win-pvdrivers

view xenpci/xenpci.h @ 198:c5f21187ef46

Working on suspend/resume. Suspend works (well... you get a checkpoint file), but resume fails.
author James Harper <james.harper@bendigoit.com.au>
date Thu Feb 28 09:06:35 2008 +1100 (2008-02-28)
parents 8609c27c4893
children d841932ba7ae
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 <ntddk.h>
27 #include <wdm.h>
28 #include <wdf.h>
29 #include <initguid.h>
30 #include <wdmguid.h>
31 #include <errno.h>
33 #define NTSTRSAFE_LIB
34 #include <ntstrsafe.h>
36 #define __DRIVER_NAME "XenPCI"
38 #include <xen_windows.h>
39 #include <memory.h>
40 #include <grant_table.h>
41 #include <event_channel.h>
42 #include <hvm/params.h>
43 #include <hvm/hvm_op.h>
44 #include <sched.h>
46 #include <xen_public.h>
48 //{C828ABE9-14CA-4445-BAA6-82C2376C6518}
49 DEFINE_GUID( GUID_XENPCI_DEVCLASS, 0xC828ABE9, 0x14CA, 0x4445, 0xBA, 0xA6, 0x82, 0xC2, 0x37, 0x6C, 0x65, 0x18);
51 #define XENPCI_POOL_TAG (ULONG) 'XenP'
52 //#define XENPCI_FDO_INSTANCE_SIGNATURE (ULONG) 'XENP'
54 #define NR_RESERVED_ENTRIES 8
55 #define NR_GRANT_FRAMES 4
56 #define NR_GRANT_ENTRIES (NR_GRANT_FRAMES * PAGE_SIZE / sizeof(grant_entry_t))
58 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
60 typedef struct _ev_action_t {
61 PKSERVICE_ROUTINE ServiceRoutine;
62 PVOID ServiceContext;
63 BOOLEAN DpcFlag;
64 WDFDPC Dpc;
65 ULONG Count;
66 } ev_action_t;
68 typedef struct {
69 ev_action_t *Action;
70 } EVTCHN_DEVICE_DATA, *PEVTCHN_DEVICE_DATA;
71 WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(EVTCHN_DEVICE_DATA, GetEvtChnDeviceData);
73 typedef struct _XENBUS_WATCH_RING
74 {
75 char Path[128];
76 char Token[10];
77 } XENBUS_WATCH_RING;
79 typedef struct _XENBUS_REQ_INFO
80 {
81 int In_Use:1;
82 KEVENT WaitEvent;
83 void *Reply;
84 } XENBUS_REQ_INFO;
86 typedef struct _XENBUS_WATCH_ENTRY {
87 char Path[128];
88 PXENBUS_WATCH_CALLBACK ServiceRoutine;
89 PVOID ServiceContext;
90 int Count;
91 int Active;
92 int RemovePending;
93 int Running;
94 KEVENT CompleteEvent;
95 } XENBUS_WATCH_ENTRY, *PXENBUS_WATCH_ENTRY;
97 #define NR_EVENTS 1024
98 #define WATCH_RING_SIZE 128
99 #define NR_XB_REQS 32
100 #define MAX_WATCH_ENTRIES 128
102 // TODO: tidy up & organize this struct
103 typedef struct {
105 WDFDEVICE Device;
106 BOOLEAN XenBus_ShuttingDown;
108 WDFINTERRUPT XenInterrupt;
109 ULONG irqNumber;
111 shared_info_t *shared_info_area;
113 PHYSICAL_ADDRESS platform_mmio_addr;
114 ULONG platform_mmio_orig_len;
115 ULONG platform_mmio_len;
116 ULONG platform_mmio_alloc;
118 char *hypercall_stubs;
120 evtchn_port_t xen_store_evtchn;
122 grant_entry_t *gnttab_table;
123 PHYSICAL_ADDRESS gnttab_table_physical;
124 grant_ref_t gnttab_list[NR_GRANT_ENTRIES];
126 ev_action_t ev_actions[NR_EVENTS];
127 unsigned long bound_ports[NR_EVENTS/(8*sizeof(unsigned long))];
129 HANDLE XenBus_ReadThreadHandle;
130 KEVENT XenBus_ReadThreadEvent;
131 HANDLE XenBus_WatchThreadHandle;
132 KEVENT XenBus_WatchThreadEvent;
134 XENBUS_WATCH_RING XenBus_WatchRing[WATCH_RING_SIZE];
135 int XenBus_WatchRingReadIndex;
136 int XenBus_WatchRingWriteIndex;
138 struct xenstore_domain_interface *xen_store_interface;
140 XENBUS_REQ_INFO req_info[NR_XB_REQS];
141 int nr_live_reqs;
142 XENBUS_WATCH_ENTRY XenBus_WatchEntries[MAX_WATCH_ENTRIES];
144 KSPIN_LOCK WatchLock;
145 KSPIN_LOCK grant_lock;
147 KGUARDED_MUTEX WatchHandlerMutex;
149 int suspending;
150 } XENPCI_DEVICE_DATA, *PXENPCI_DEVICE_DATA;
152 WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(XENPCI_DEVICE_DATA, GetDeviceData);
154 #if defined(_X86_)
155 #include "hypercall_x86.h"
156 #else
157 #if defined(_AMD64_)
158 #include "hypercall_amd64.h"
159 #endif
160 #endif
162 typedef unsigned long xenbus_transaction_t;
163 typedef uint32_t XENSTORE_RING_IDX;
165 #define XBT_NIL ((xenbus_transaction_t)0)
167 char *
168 XenBus_Read(PVOID Context, xenbus_transaction_t xbt, const char *path, char **value);
169 char *
170 XenBus_Write(PVOID Context, xenbus_transaction_t xbt, const char *path, const char *value);
171 char *
172 XenBus_Printf(PVOID Context, xenbus_transaction_t xbt, const char *path, const char *fmt, ...);
173 char *
174 XenBus_StartTransaction(PVOID Context, xenbus_transaction_t *xbt);
175 char *
176 XenBus_EndTransaction(PVOID Context, xenbus_transaction_t t, int abort, int *retry);
177 char *
178 XenBus_List(PVOID Context, xenbus_transaction_t xbt, const char *prefix, char ***contents);
179 NTSTATUS
180 XenBus_Init(WDFDEVICE Device);
181 NTSTATUS
182 XenBus_Close(WDFDEVICE Device);
183 NTSTATUS
184 XenBus_Start(WDFDEVICE Device);
185 NTSTATUS
186 XenBus_Stop(WDFDEVICE Device);
187 char *
188 XenBus_AddWatch(PVOID Context, xenbus_transaction_t xbt, const char *Path, PXENBUS_WATCH_CALLBACK ServiceRoutine, PVOID ServiceContext);
189 char *
190 XenBus_RemWatch(PVOID Context, xenbus_transaction_t xbt, const char *Path, PXENBUS_WATCH_CALLBACK ServiceRoutine, PVOID ServiceContext);
191 VOID
192 XenBus_ThreadProc(PVOID StartContext);
194 PHYSICAL_ADDRESS
195 XenPCI_AllocMMIO(WDFDEVICE Device, ULONG len);
197 NTSTATUS
198 EvtChn_Init(WDFDEVICE Device);
199 BOOLEAN
200 EvtChn_Interrupt(WDFINTERRUPT Interrupt, ULONG MessageID);
201 VOID
202 EvtChn_InterruptDpc(WDFINTERRUPT Interrupt, WDFOBJECT AssociatedObject);
203 NTSTATUS
204 EvtChn_Mask(PVOID Context, evtchn_port_t Port);
205 NTSTATUS
206 EvtChn_Unmask(PVOID Context, evtchn_port_t Port);
207 NTSTATUS
208 EvtChn_Bind(PVOID Context, evtchn_port_t Port, PKSERVICE_ROUTINE ServiceRoutine, PVOID ServiceContext);
209 NTSTATUS
210 EvtChn_BindDpc(PVOID Context, evtchn_port_t Port, PKSERVICE_ROUTINE ServiceRoutine, PVOID ServiceContext);
211 NTSTATUS
212 EvtChn_Unbind(PVOID Context, evtchn_port_t Port);
213 NTSTATUS
214 EvtChn_Notify(PVOID Context, evtchn_port_t Port);
215 evtchn_port_t
216 EvtChn_AllocUnbound(PVOID Context, domid_t Domain);
217 evtchn_port_t
218 EvtChn_GetXenStorePort(WDFDEVICE Device);
219 PVOID
220 EvtChn_GetXenStoreRingAddr(WDFDEVICE Device);
222 VOID
223 GntTbl_Init(WDFDEVICE Device);
224 grant_ref_t
225 GntTbl_GrantAccess(WDFDEVICE Device, domid_t domid, uint32_t, int readonly);
226 BOOLEAN
227 GntTbl_EndAccess(WDFDEVICE Device, grant_ref_t ref);
229 #endif