win-pvdrivers

view xenpci/xenpci.h @ 497:312a41f82b8f

Updated to support the proposed patches to qemu from Steven Smith on ~20081216
author James Harper <james.harper@bendigoit.com.au>
date Fri Dec 19 22:08:17 2008 +1100 (2008-12-19)
parents a6e3f76419c3
children cb0b2da68686
line source
1 /*
2 PV Drivers for Windows Xen HVM Domains
3 Copyright (C) 2007 James Harper
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
20 #if !defined(_XENPCI_H_)
21 #define _XENPCI_H_
23 #define __attribute__(arg) /* empty */
24 #define EISCONN 127
26 #include <ntifs.h>
27 #include <ntddk.h>
29 #ifdef __MINGW32__
30 #include "../mingw/mingw_extras.h"
31 #else
32 #define DDKAPI
33 #include <wdm.h>
34 //#include <wdf.h>
35 #include <initguid.h>
36 #include <wdmguid.h>
37 #include <errno.h>
38 #define NTSTRSAFE_LIB
39 #include <ntstrsafe.h>
40 #endif
42 #define __DRIVER_NAME "XenPCI"
44 #include <xen_windows.h>
45 #include <memory.h>
46 #include <grant_table.h>
47 #include <event_channel.h>
48 #include <hvm/params.h>
49 #include <hvm/hvm_op.h>
50 #include <sched.h>
51 #include <io/xenbus.h>
53 #include <xen_public.h>
55 //{C828ABE9-14CA-4445-BAA6-82C2376C6518}
56 DEFINE_GUID( GUID_XENPCI_DEVCLASS, 0xC828ABE9, 0x14CA, 0x4445, 0xBA, 0xA6, 0x82, 0xC2, 0x37, 0x6C, 0x65, 0x18);
58 #define XENPCI_POOL_TAG (ULONG) 'XenP'
60 #define NR_RESERVED_ENTRIES 8
61 #define NR_GRANT_FRAMES 32
62 #define NR_GRANT_ENTRIES (NR_GRANT_FRAMES * PAGE_SIZE / sizeof(grant_entry_t))
64 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
66 #define EVT_ACTION_TYPE_EMPTY 0
67 #define EVT_ACTION_TYPE_NORMAL 1
68 #define EVT_ACTION_TYPE_DPC 2
69 #define EVT_ACTION_TYPE_IRQ 3
70 #define EVT_ACTION_TYPE_SUSPEND 4
72 #define XEN_PV_PRODUCT_NUMBER 0x0002
73 #define XEN_PV_PRODUCT_BUILD 0x00000001
75 extern ULONG qemu_filtered;
76 extern ULONG qemu_protocol_version;
78 typedef struct _ev_action_t {
79 PKSERVICE_ROUTINE ServiceRoutine;
80 PVOID ServiceContext;
81 CHAR description[128];
82 ULONG type; /* EVT_ACTION_TYPE_* */
83 KDPC Dpc;
84 ULONG vector;
85 ULONG count;
86 PVOID xpdd;
87 } ev_action_t;
89 typedef struct _XENBUS_WATCH_RING
90 {
91 char Path[128];
92 char Token[10];
93 } XENBUS_WATCH_RING;
95 typedef struct _XENBUS_REQ_INFO
96 {
97 int In_Use:1;
98 KEVENT WaitEvent;
99 void *Reply;
100 } XENBUS_REQ_INFO;
102 typedef struct _XENBUS_WATCH_ENTRY {
103 char Path[128];
104 PXENBUS_WATCH_CALLBACK ServiceRoutine;
105 PVOID ServiceContext;
106 int Count;
107 int Active;
108 //int RemovePending;
109 //int Running;
110 //KEVENT CompleteEvent;
111 } XENBUS_WATCH_ENTRY, *PXENBUS_WATCH_ENTRY;
113 #define NR_EVENTS 1024
114 #define WATCH_RING_SIZE 128
115 #define NR_XB_REQS 32
116 #define MAX_WATCH_ENTRIES 128
118 #define CHILD_STATE_EMPTY 0
119 #define CHILD_STATE_DELETED 1
120 #define CHILD_STATE_ADDED 2
122 // TODO: tidy up & organize this struct
124 typedef enum {
125 Unknown = 0,
126 NotStarted,
127 Started,
128 StopPending,
129 Stopped,
130 RemovePending,
131 SurpriseRemovePending,
132 Removed
133 } DEVICE_PNP_STATE;
135 typedef struct
136 {
137 PDEVICE_OBJECT fdo;
138 PDEVICE_OBJECT pdo;
139 PDEVICE_OBJECT lower_do;
141 DEVICE_PNP_STATE current_pnp_state;
142 DEVICE_PNP_STATE previous_pnp_state;
143 DEVICE_POWER_STATE device_power_state;
144 SYSTEM_POWER_STATE system_power_state;
146 ULONG device_usage_paging;
147 ULONG device_usage_dump;
148 ULONG device_usage_hibernation;
149 } XENPCI_COMMON, *PXENPCI_COMMON;
151 static __inline void INIT_PNP_STATE(PXENPCI_COMMON common)
152 {
153 common->current_pnp_state = NotStarted;
154 common->previous_pnp_state = NotStarted;
155 }
157 static __inline void SET_PNP_STATE(PXENPCI_COMMON common, DEVICE_PNP_STATE state)
158 {
159 common->previous_pnp_state = common->current_pnp_state;
160 common->current_pnp_state = state;
161 }
163 static __inline void REVERT_PNP_STATE(PXENPCI_COMMON common)
164 {
165 common->current_pnp_state = common->previous_pnp_state;
166 }
168 #define SHUTDOWN_RING_SIZE 128
170 #define SUSPEND_STATE_NONE 0 /* no suspend in progress */
171 #define SUSPEND_STATE_SCHEDULED 1 /* suspend scheduled */
172 #define SUSPEND_STATE_HIGH_IRQL 2 /* all processors are at high IRQL and spinning */
173 #define SUSPEND_STATE_RESUMING 3 /* we are the other side of the suspend and things are starting to get back to normal */
175 typedef struct {
176 XENPCI_COMMON common;
178 BOOLEAN XenBus_ShuttingDown;
180 PKINTERRUPT interrupt;
181 ULONG irq_number;
182 ULONG irq_vector;
183 KIRQL irq_level;
184 KINTERRUPT_MODE irq_mode;
185 KAFFINITY irq_affinity;
187 PHYSICAL_ADDRESS shared_info_area_unmapped;
188 shared_info_t *shared_info_area;
189 xen_ulong_t evtchn_pending_pvt[sizeof(xen_ulong_t) * 8];
190 xen_ulong_t evtchn_pending_suspend[sizeof(xen_ulong_t) * 8];
191 evtchn_port_t pdo_event_channel;
192 BOOLEAN interrupts_masked;
194 PHYSICAL_ADDRESS platform_mmio_addr;
195 ULONG platform_mmio_orig_len;
196 ULONG platform_mmio_len;
197 ULONG platform_mmio_alloc;
198 USHORT platform_mmio_flags;
200 ULONG platform_ioport_addr;
201 ULONG platform_ioport_len;
203 char *hypercall_stubs;
205 evtchn_port_t xen_store_evtchn;
207 grant_entry_t *gnttab_table;
208 PHYSICAL_ADDRESS gnttab_table_physical;
209 grant_ref_t *gnttab_list;
210 int gnttab_list_free;
211 /* this is the maximum number of grant frames we have memory allocated for */
212 /* after a resume it may not be the actual number of grant frames we have though */
213 ULONG max_grant_frames;
215 ev_action_t ev_actions[NR_EVENTS];
216 // unsigned long bound_ports[NR_EVENTS/(8*sizeof(unsigned long))];
218 PKTHREAD XenBus_ReadThread;
219 KEVENT XenBus_ReadThreadEvent;
220 PKTHREAD XenBus_WatchThread;
221 KEVENT XenBus_WatchThreadEvent;
223 KSPIN_LOCK xenbus_id_lock;
224 KEVENT xenbus_id_event;
226 XENBUS_WATCH_RING XenBus_WatchRing[WATCH_RING_SIZE];
227 int XenBus_WatchRingReadIndex;
228 int XenBus_WatchRingWriteIndex;
230 struct xenstore_domain_interface *xen_store_interface;
232 XENBUS_REQ_INFO req_info[NR_XB_REQS];
233 int nr_live_reqs;
234 XENBUS_WATCH_ENTRY XenBus_WatchEntries[MAX_WATCH_ENTRIES];
236 FAST_MUTEX watch_mutex;
237 FAST_MUTEX xenbus_mutex;
238 KSPIN_LOCK grant_lock;
240 //KGUARDED_MUTEX WatchHandlerMutex;
242 LIST_ENTRY child_list;
244 int suspend_state;
246 UNICODE_STRING interface_name;
247 BOOLEAN interface_open;
249 KSPIN_LOCK shutdown_ring_lock;
250 CHAR shutdown_ring[SHUTDOWN_RING_SIZE];
251 ULONG shutdown_prod;
252 ULONG shutdown_cons;
253 ULONG shutdown_start; /* the start of the most recent message on the ring */
254 PIRP shutdown_irp;
256 BOOLEAN log_interrupts;
257 } XENPCI_DEVICE_DATA, *PXENPCI_DEVICE_DATA;
259 typedef struct {
260 XENPCI_COMMON common;
261 PDEVICE_OBJECT bus_pdo;
262 PDEVICE_OBJECT bus_fdo;
263 BOOLEAN reported_missing;
264 char path[128];
265 char device[128];
266 ULONG index;
267 ULONG irq_number;
268 ULONG irq_vector;
269 KIRQL irq_level;
270 char backend_path[128];
271 //PVOID xenbus_request;
272 KEVENT backend_state_event;
273 ULONG backend_state;
274 PHYSICAL_ADDRESS config_page_phys;
275 ULONG config_page_length;
276 PUCHAR requested_resources_start;
277 PUCHAR requested_resources_ptr;
278 PUCHAR assigned_resources_start;
279 PUCHAR assigned_resources_ptr;
280 XENPCI_DEVICE_STATE device_state;
281 BOOLEAN restart_on_resume;
282 } XENPCI_PDO_DEVICE_DATA, *PXENPCI_PDO_DEVICE_DATA;
284 typedef struct
285 {
286 LIST_ENTRY entry;
287 int state;
288 PXENPCI_PDO_DEVICE_DATA context;
289 } XEN_CHILD, *PXEN_CHILD;
291 #include "hypercall.h"
293 #define XBT_NIL ((xenbus_transaction_t)0)
295 #if 0
296 static __inline VOID
297 XenPci_FreeMem(PVOID Ptr)
298 {
299 ExFreePoolWithTag(Ptr, XENPCI_POOL_TAG);
300 }
301 #endif
303 NTSTATUS
304 hvm_get_stubs(PXENPCI_DEVICE_DATA xpdd);
305 NTSTATUS
306 hvm_free_stubs(PXENPCI_DEVICE_DATA xpdd);
308 NTSTATUS
309 XenPci_Power_Fdo(PDEVICE_OBJECT device_object, PIRP irp);
310 NTSTATUS
311 XenPci_Dummy_Fdo(PDEVICE_OBJECT device_object, PIRP irp);
312 NTSTATUS
313 XenPci_Pnp_Fdo(PDEVICE_OBJECT device_object, PIRP irp);
314 NTSTATUS
315 XenPci_Irp_Create_Fdo(PDEVICE_OBJECT device_object, PIRP irp);
316 NTSTATUS
317 XenPci_Irp_Close_Fdo(PDEVICE_OBJECT device_object, PIRP irp);
318 NTSTATUS
319 XenPci_Irp_Read_Fdo(PDEVICE_OBJECT device_object, PIRP irp);
320 NTSTATUS
321 XenPci_Irp_Cleanup_Fdo(PDEVICE_OBJECT device_object, PIRP irp);
322 NTSTATUS
323 XenPci_SystemControl_Fdo(PDEVICE_OBJECT device_object, PIRP irp);
325 NTSTATUS
326 XenPci_Power_Pdo(PDEVICE_OBJECT device_object, PIRP irp);
327 //NTSTATUS
328 //XenPci_Dummy_Pdo(PDEVICE_OBJECT device_object, PIRP irp);
329 NTSTATUS
330 XenPci_Pnp_Pdo(PDEVICE_OBJECT device_object, PIRP irp);
331 NTSTATUS
332 XenPci_Irp_Create_Pdo(PDEVICE_OBJECT device_object, PIRP irp);
333 NTSTATUS
334 XenPci_Irp_Close_Pdo(PDEVICE_OBJECT device_object, PIRP irp);
335 NTSTATUS
336 XenPci_Irp_Read_Pdo(PDEVICE_OBJECT device_object, PIRP irp);
337 NTSTATUS
338 XenPci_Irp_Cleanup_Pdo(PDEVICE_OBJECT device_object, PIRP irp);
339 NTSTATUS
340 XenPci_SystemControl_Pdo(PDEVICE_OBJECT device_object, PIRP irp);
342 NTSTATUS
343 XenPci_Pdo_Suspend(PDEVICE_OBJECT device_object);
344 NTSTATUS
345 XenPci_Pdo_Resume(PDEVICE_OBJECT device_object);
347 VOID
348 XenPci_DumpPdoConfig(PDEVICE_OBJECT device_object);
350 char *
351 XenBus_Read(PVOID Context, xenbus_transaction_t xbt, const char *path, char **value);
352 char *
353 XenBus_Write(PVOID Context, xenbus_transaction_t xbt, const char *path, const char *value);
354 char *
355 XenBus_Printf(PVOID Context, xenbus_transaction_t xbt, const char *path, const char *fmt, ...);
356 char *
357 XenBus_StartTransaction(PVOID Context, xenbus_transaction_t *xbt);
358 char *
359 XenBus_EndTransaction(PVOID Context, xenbus_transaction_t t, int abort, int *retry);
360 char *
361 XenBus_List(PVOID Context, xenbus_transaction_t xbt, const char *prefix, char ***contents);
362 char *
363 XenBus_AddWatch(PVOID Context, xenbus_transaction_t xbt, const char *Path, PXENBUS_WATCH_CALLBACK ServiceRoutine, PVOID ServiceContext);
364 char *
365 XenBus_RemWatch(PVOID Context, xenbus_transaction_t xbt, const char *Path, PXENBUS_WATCH_CALLBACK ServiceRoutine, PVOID ServiceContext);
366 //VOID
367 //XenBus_ThreadProc(PVOID StartContext);
368 NTSTATUS
369 XenBus_Init(PXENPCI_DEVICE_DATA xpdd);
370 NTSTATUS
371 XenBus_Close(PXENPCI_DEVICE_DATA xpdd);
372 NTSTATUS
373 XenBus_Start(PXENPCI_DEVICE_DATA xpdd);
374 NTSTATUS
375 XenBus_Stop(PXENPCI_DEVICE_DATA xpdd);
376 NTSTATUS
377 XenBus_Suspend(PXENPCI_DEVICE_DATA xpdd);
378 NTSTATUS
379 XenBus_Resume(PXENPCI_DEVICE_DATA xpdd);
380 NTSTATUS
381 XenBus_StopThreads(PXENPCI_DEVICE_DATA xpdd);
383 PHYSICAL_ADDRESS
384 XenPci_AllocMMIO(PXENPCI_DEVICE_DATA xpdd, ULONG len);
386 NTSTATUS
387 EvtChn_Init(PXENPCI_DEVICE_DATA xpdd);
388 NTSTATUS
389 EvtChn_ConnectInterrupt(PXENPCI_DEVICE_DATA xpdd);
390 NTSTATUS
391 EvtChn_Shutdown(PXENPCI_DEVICE_DATA xpdd);
393 NTSTATUS
394 EvtChn_Mask(PVOID Context, evtchn_port_t Port);
395 NTSTATUS
396 EvtChn_Unmask(PVOID Context, evtchn_port_t Port);
397 NTSTATUS
398 EvtChn_Bind(PVOID Context, evtchn_port_t Port, PKSERVICE_ROUTINE ServiceRoutine, PVOID ServiceContext);
399 NTSTATUS
400 EvtChn_BindDpc(PVOID Context, evtchn_port_t Port, PKSERVICE_ROUTINE ServiceRoutine, PVOID ServiceContext);
401 NTSTATUS
402 EvtChn_BindIrq(PVOID Context, evtchn_port_t Port, ULONG vector, PCHAR description);
403 evtchn_port_t
404 EvtChn_AllocIpi(PVOID context, ULONG vcpu);
405 NTSTATUS
406 EvtChn_Unbind(PVOID Context, evtchn_port_t Port);
407 NTSTATUS
408 EvtChn_Notify(PVOID Context, evtchn_port_t Port);
409 VOID
410 EvtChn_Close(PVOID Context, evtchn_port_t Port);
411 evtchn_port_t
412 EvtChn_AllocUnbound(PVOID Context, domid_t Domain);
413 BOOLEAN
414 EvtChn_AckEvent(PVOID context, evtchn_port_t port);
416 VOID
417 GntTbl_Init(PXENPCI_DEVICE_DATA xpdd);
418 VOID
419 GntTbl_InitMap(PXENPCI_DEVICE_DATA xpdd);
420 grant_ref_t
421 GntTbl_GrantAccess(PVOID Context, domid_t domid, uint32_t, int readonly, grant_ref_t ref);
422 BOOLEAN
423 GntTbl_EndAccess(PVOID Context, grant_ref_t ref, BOOLEAN keepref);
424 VOID
425 GntTbl_PutRef(PVOID Context, grant_ref_t ref);
426 grant_ref_t
427 GntTbl_GetRef(PVOID Context);
428 int
429 GntTbl_Map(PVOID Context, unsigned int start_idx, unsigned int end_idx);
430 #endif