win-pvdrivers

view common/include/xen_public.h @ 314:a55d72ac422f

updates to the whole xenconfig thing to allow xennet to dynamically config. Almost there.
Created some bat files to do the signing.
author James Harper <james.harper@bendigoit.com.au>
date Tue Jun 17 10:35:26 2008 +1000 (2008-06-17)
parents 60372bd2582d
children eabe51317e3a
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(_XEN_PUBLIC_H_)
21 #define _XEN_PUBLIC_H_
23 #include <grant_table.h>
24 #include <event_channel.h>
25 #include <xen_guids.h>
26 //{5C568AC5-9DDF-4FA5-A94A-39D67077819C}
27 DEFINE_GUID(GUID_XEN_IFACE, 0x5C568AC5, 0x9DDF, 0x4FA5, 0xA9, 0x4A, 0x39, 0xD6, 0x70, 0x77, 0x81, 0x9C);
29 typedef PHYSICAL_ADDRESS
30 (*PXEN_ALLOCMMIO)(PVOID Context, ULONG Length);
32 typedef void
33 (*PXEN_FREEMEM)(PVOID Ptr);
35 typedef NTSTATUS
36 (*PXEN_EVTCHN_BIND)(PVOID Context, evtchn_port_t Port, PKSERVICE_ROUTINE ServiceRoutine, PVOID ServiceContext);
38 typedef NTSTATUS
39 (*PXEN_EVTCHN_UNBIND)(PVOID Context, evtchn_port_t Port);
41 typedef NTSTATUS
42 (*PXEN_EVTCHN_MASK)(PVOID Context, evtchn_port_t Port);
44 typedef NTSTATUS
45 (*PXEN_EVTCHN_UNMASK)(PVOID Context, evtchn_port_t Port);
47 typedef NTSTATUS
48 (*PXEN_EVTCHN_NOTIFY)(PVOID Context, evtchn_port_t Port);
50 typedef evtchn_port_t
51 (*PXEN_EVTCHN_ALLOCUNBOUND)(PVOID Context, domid_t Domain);
53 typedef grant_ref_t
54 (*PXEN_GNTTBL_GRANTACCESS)(PVOID Context, domid_t domid, uint32_t frame, int readonly, grant_ref_t ref);
56 typedef BOOLEAN
57 (*PXEN_GNTTBL_ENDACCESS)(PVOID Context, grant_ref_t ref, BOOLEAN keepref);
59 typedef VOID
60 (*PXEN_GNTTBL_PUTREF)(PVOID Context, grant_ref_t ref);
62 typedef grant_ref_t
63 (*PXEN_GNTTBL_GETREF)(PVOID Context);
66 typedef VOID
67 (*PXENBUS_WATCH_CALLBACK)(char *Path, PVOID ServiceContext);
69 typedef char *
70 (*PXEN_XENBUS_READ)(PVOID Context, xenbus_transaction_t xbt, const char *path, char **value);
72 typedef char *
73 (*PXEN_XENBUS_WRITE)(PVOID Context, xenbus_transaction_t xbt, const char *path, const char *value);
75 typedef char *
76 (*PXEN_XENBUS_PRINTF)(PVOID Context, xenbus_transaction_t xbt, const char *path, const char *fmt, ...);
78 typedef char *
79 (*PXEN_XENBUS_STARTTRANSACTION)(PVOID Context, xenbus_transaction_t *xbt);
81 typedef char *
82 (*PXEN_XENBUS_ENDTRANSACTION)(PVOID Context, xenbus_transaction_t t, int abort, int *retry);
84 typedef char *
85 (*PXEN_XENBUS_LIST)(PVOID Context, xenbus_transaction_t xbt, const char *prefix, char ***contents);
87 typedef char *
88 (*PXEN_XENBUS_ADDWATCH)(PVOID Context, xenbus_transaction_t xbt, const char *Path, PXENBUS_WATCH_CALLBACK ServiceRoutine, PVOID ServiceContext);
90 typedef char *
91 (*PXEN_XENBUS_REMWATCH)(PVOID Context, xenbus_transaction_t xbt, const char *Path, PXENBUS_WATCH_CALLBACK ServiceRoutine, PVOID ServiceContext);
93 typedef NTSTATUS
94 (*PXEN_XENPCI_XEN_CONFIG_DEVICE)(PVOID Context);
96 typedef NTSTATUS
97 (*PXEN_XENPCI_XEN_SHUTDOWN_DEVICE)(PVOID Context);
99 #define XEN_DATA_MAGIC 0x12345678
101 typedef struct {
102 ULONG magic;
103 USHORT length;
105 PVOID context;
106 PXEN_EVTCHN_BIND EvtChn_Bind;
107 PXEN_EVTCHN_BIND EvtChn_BindDpc;
108 PXEN_EVTCHN_UNBIND EvtChn_Unbind;
109 PXEN_EVTCHN_MASK EvtChn_Mask;
110 PXEN_EVTCHN_UNMASK EvtChn_Unmask;
111 PXEN_EVTCHN_NOTIFY EvtChn_Notify;
112 PXEN_GNTTBL_GETREF GntTbl_GetRef;
113 PXEN_GNTTBL_PUTREF GntTbl_PutRef;
114 PXEN_GNTTBL_GRANTACCESS GntTbl_GrantAccess;
115 PXEN_GNTTBL_ENDACCESS GntTbl_EndAccess;
116 PXEN_XENPCI_XEN_CONFIG_DEVICE XenPci_XenConfigDevice;
117 PXEN_XENPCI_XEN_SHUTDOWN_DEVICE XenPci_XenShutdownDevice;
118 } XENPCI_VECTORS, *PXENPCI_VECTORS;
121 #define XEN_INIT_TYPE_END 0
122 #define XEN_INIT_TYPE_WRITE_STRING 1
123 #define XEN_INIT_TYPE_RING 2
124 #define XEN_INIT_TYPE_EVENT_CHANNEL 3
125 #define XEN_INIT_TYPE_EVENT_CHANNEL_IRQ 4
126 #define XEN_INIT_TYPE_READ_STRING_FRONT 5
127 #define XEN_INIT_TYPE_READ_STRING_BACK 6
128 #define XEN_INIT_TYPE_VECTORS 7
129 #define XEN_INIT_TYPE_GRANT_ENTRIES 8
130 //#define XEN_INIT_TYPE_COPY_PTR 9
131 #define XEN_INIT_TYPE_RUN 10
133 static __inline VOID
134 __ADD_XEN_INIT_UCHAR(PUCHAR *ptr, UCHAR val)
135 {
136 KdPrint((__DRIVER_NAME " ADD_XEN_INIT_UCHAR *ptr = %p, val = %d\n", *ptr, val));
137 *(PUCHAR)(*ptr) = val;
138 *ptr += sizeof(UCHAR);
139 }
141 static __inline VOID
142 __ADD_XEN_INIT_USHORT(PUCHAR *ptr, USHORT val)
143 {
144 KdPrint((__DRIVER_NAME " ADD_XEN_INIT_USHORT *ptr = %p, val = %d\n", *ptr, val));
145 *(PUSHORT)(*ptr) = val;
146 *ptr += sizeof(USHORT);
147 }
149 static __inline VOID
150 __ADD_XEN_INIT_ULONG(PUCHAR *ptr, ULONG val)
151 {
152 KdPrint((__DRIVER_NAME " ADD_XEN_INIT_ULONG *ptr = %p, val = %d\n", *ptr, val));
153 *(PULONG)(*ptr) = val;
154 *ptr += sizeof(ULONG);
155 }
157 static __inline VOID
158 __ADD_XEN_INIT_PTR(PUCHAR *ptr, PVOID val)
159 {
160 KdPrint((__DRIVER_NAME " ADD_XEN_INIT_PTR *ptr = %p, val = %p\n", *ptr, val));
161 *(PVOID *)(*ptr) = val;
162 *ptr += sizeof(PVOID);
163 }
165 static __inline VOID
166 __ADD_XEN_INIT_STRING(PUCHAR *ptr, PCHAR val)
167 {
168 KdPrint((__DRIVER_NAME " ADD_XEN_INIT_STRING *ptr = %p, val = %s\n", *ptr, val));
169 RtlStringCbCopyA((PCHAR)*ptr, PAGE_SIZE - (PtrToUlong(*ptr) & (PAGE_SIZE - 1)), val);
170 *ptr += strlen(val) + 1;
171 }
173 static __inline UCHAR
174 __GET_XEN_INIT_UCHAR(PUCHAR *ptr)
175 {
176 UCHAR retval;
177 retval = **ptr;
178 KdPrint((__DRIVER_NAME " GET_XEN_INIT_UCHAR *ptr = %p, retval = %d\n", *ptr, retval));
179 *ptr += sizeof(UCHAR);
180 return retval;
181 }
183 static __inline USHORT
184 __GET_XEN_INIT_USHORT(PUCHAR *ptr)
185 {
186 USHORT retval;
187 retval = *(PUSHORT)*ptr;
188 KdPrint((__DRIVER_NAME " GET_XEN_INIT_USHORT *ptr = %p, retval = %d\n", *ptr, retval));
189 *ptr += sizeof(USHORT);
190 return retval;
191 }
193 static __inline ULONG
194 __GET_XEN_INIT_ULONG(PUCHAR *ptr)
195 {
196 ULONG retval;
197 retval = *(PLONG)*ptr;
198 KdPrint((__DRIVER_NAME " GET_XEN_INIT_ULONG *ptr = %p, retval = %d\n", *ptr, retval));
199 *ptr += sizeof(ULONG);
200 return retval;
201 }
203 static __inline PCHAR
204 __GET_XEN_INIT_STRING(PUCHAR *ptr)
205 {
206 PCHAR retval;
207 retval = (PCHAR)*ptr;
208 KdPrint((__DRIVER_NAME " GET_XEN_INIT_STRING *ptr = %p, retval = %s\n", *ptr, retval));
209 *ptr += strlen((PCHAR)*ptr) + 1;
210 return retval;
211 }
213 static __inline PVOID
214 __GET_XEN_INIT_PTR(PUCHAR *ptr)
215 {
216 PVOID retval;
217 retval = *(PVOID *)(*ptr);
218 KdPrint((__DRIVER_NAME " GET_XEN_INIT_PTR *ptr = %p, retval = %p\n", *ptr, retval));
219 *ptr += sizeof(PVOID);
220 return retval;
221 }
223 static __inline VOID
224 ADD_XEN_INIT_REQ(PUCHAR *ptr, UCHAR type, PVOID p1, PVOID p2)
225 {
226 __ADD_XEN_INIT_UCHAR(ptr, type);
227 switch (type)
228 {
229 case XEN_INIT_TYPE_END:
230 case XEN_INIT_TYPE_VECTORS:
231 case XEN_INIT_TYPE_RUN:
232 break;
233 case XEN_INIT_TYPE_WRITE_STRING:
234 __ADD_XEN_INIT_STRING(ptr, p1);
235 __ADD_XEN_INIT_STRING(ptr, p2);
236 break;
237 case XEN_INIT_TYPE_RING:
238 case XEN_INIT_TYPE_EVENT_CHANNEL:
239 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
240 case XEN_INIT_TYPE_READ_STRING_FRONT:
241 case XEN_INIT_TYPE_READ_STRING_BACK:
242 __ADD_XEN_INIT_STRING(ptr, p1);
243 break;
244 case XEN_INIT_TYPE_GRANT_ENTRIES:
245 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p2));
246 break;
247 // case XEN_INIT_TYPE_COPY_PTR:
248 // __ADD_XEN_INIT_STRING(ptr, p1);
249 // __ADD_XEN_INIT_PTR(ptr, p2);
250 }
251 }
253 static __inline UCHAR
254 GET_XEN_INIT_REQ(PUCHAR *ptr, PVOID *p1, PVOID *p2)
255 {
256 UCHAR retval;
258 retval = __GET_XEN_INIT_UCHAR(ptr);
259 switch (retval)
260 {
261 case XEN_INIT_TYPE_END:
262 case XEN_INIT_TYPE_VECTORS:
263 case XEN_INIT_TYPE_RUN:
264 *p1 = NULL;
265 *p2 = NULL;
266 break;
267 case XEN_INIT_TYPE_WRITE_STRING:
268 *p1 = __GET_XEN_INIT_STRING(ptr);
269 *p2 = __GET_XEN_INIT_STRING(ptr);
270 break;
271 case XEN_INIT_TYPE_RING:
272 case XEN_INIT_TYPE_EVENT_CHANNEL:
273 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
274 case XEN_INIT_TYPE_READ_STRING_FRONT:
275 case XEN_INIT_TYPE_READ_STRING_BACK:
276 *p1 = __GET_XEN_INIT_STRING(ptr);
277 *p2 = NULL;
278 break;
279 case XEN_INIT_TYPE_GRANT_ENTRIES:
280 *p2 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
281 break;
282 // case XEN_INIT_TYPE_COPY_PTR:
283 // *p1 = __GET_XEN_INIT_STRING(ptr);
284 // *p2 = __GET_XEN_INIT_PTR(ptr);
285 }
286 return retval;
287 }
289 static __inline VOID
290 ADD_XEN_INIT_RSP(PUCHAR *ptr, UCHAR type, PVOID p1, PVOID p2)
291 {
292 __ADD_XEN_INIT_UCHAR(ptr, type);
293 switch (type)
294 {
295 case XEN_INIT_TYPE_END:
296 case XEN_INIT_TYPE_WRITE_STRING: /* this shouldn't happen */
297 case XEN_INIT_TYPE_RUN:
298 break;
299 case XEN_INIT_TYPE_RING:
300 __ADD_XEN_INIT_STRING(ptr, p1);
301 __ADD_XEN_INIT_PTR(ptr, p2);
302 break;
303 case XEN_INIT_TYPE_EVENT_CHANNEL:
304 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
305 __ADD_XEN_INIT_STRING(ptr, p1);
306 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p2));
307 break;
308 case XEN_INIT_TYPE_READ_STRING_FRONT:
309 case XEN_INIT_TYPE_READ_STRING_BACK:
310 __ADD_XEN_INIT_STRING(ptr, p1);
311 __ADD_XEN_INIT_STRING(ptr, p2);
312 break;
313 case XEN_INIT_TYPE_VECTORS:
314 //__ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p1));
315 memcpy(*ptr, p2, sizeof(XENPCI_VECTORS));
316 *ptr += sizeof(XENPCI_VECTORS);
317 break;
318 case XEN_INIT_TYPE_GRANT_ENTRIES:
319 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p1));
320 memcpy(*ptr, p2, PtrToUlong(p1) * sizeof(grant_entry_t));
321 *ptr += PtrToUlong(p1) * sizeof(grant_entry_t);
322 break;
323 // case XEN_INIT_TYPE_COPY_PTR:
324 // __ADD_XEN_INIT_STRING(ptr, p1);
325 // __ADD_XEN_INIT_PTR(ptr, p2);
326 // break;
327 }
328 }
330 static __inline UCHAR
331 GET_XEN_INIT_RSP(PUCHAR *ptr, PVOID *p1, PVOID *p2)
332 {
333 UCHAR retval;
335 retval = __GET_XEN_INIT_UCHAR(ptr);
336 switch (retval)
337 {
338 case XEN_INIT_TYPE_END:
339 case XEN_INIT_TYPE_RUN:
340 *p1 = NULL;
341 *p2 = NULL;
342 break;
343 case XEN_INIT_TYPE_WRITE_STRING:
344 // this shouldn't happen - no response here
345 break;
346 case XEN_INIT_TYPE_RING:
347 *p1 = __GET_XEN_INIT_STRING(ptr);
348 *p2 = __GET_XEN_INIT_PTR(ptr);
349 break;
350 case XEN_INIT_TYPE_EVENT_CHANNEL:
351 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
352 *p1 = __GET_XEN_INIT_STRING(ptr);
353 *p2 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
354 break;
355 case XEN_INIT_TYPE_READ_STRING_FRONT:
356 *p1 = __GET_XEN_INIT_STRING(ptr);
357 *p2 = __GET_XEN_INIT_STRING(ptr);
358 break;
359 case XEN_INIT_TYPE_READ_STRING_BACK:
360 *p1 = __GET_XEN_INIT_STRING(ptr);
361 *p2 = __GET_XEN_INIT_STRING(ptr);
362 break;
363 case XEN_INIT_TYPE_VECTORS:
364 *p1 = NULL;
365 *p2 = *ptr;
366 *ptr += ((PXENPCI_VECTORS)*p2)->length;
367 break;
368 case XEN_INIT_TYPE_GRANT_ENTRIES:
369 *p1 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
370 *p2 = *ptr;
371 *ptr += PtrToUlong(*p1) * sizeof(grant_ref_t);
372 break;
373 // case XEN_INIT_TYPE_COPY_PTR:
374 // *p1 = __GET_XEN_INIT_STRING(ptr);
375 // *p2 = __GET_XEN_INIT_PTR(ptr);
376 }
377 return retval;
378 }
380 #endif