win-pvdrivers

view common/include/xen_windows.h @ 1099:27bd2a5a4704

License change from GPL to BSD
author James Harper <james.harper@bendigoit.com.au>
date Thu Mar 13 13:38:31 2014 +1100 (2014-03-13)
parents ebf4d299224b
children 99ce7ae22363
line source
1 #if !defined(_XEN_WINDOWS_H_)
2 #define _XEN_WINDOWS_H_
4 #include <ntverp.h>
6 #include "ejbpv_version.h"
8 #pragma warning( disable : 4201 ) // nonstandard extension used : nameless struct/union
9 #pragma warning( disable : 4214 ) // nonstandard extension used : bit field types other than int
10 #pragma warning( disable : 4505 ) // 'XenDbgPrint' : unreferenced local function has been removed
12 #define __XEN_INTERFACE_VERSION__ 0x00030205
13 #if defined(_AMD64_)
14 #define __x86_64__
15 #elif defined(_IA64_)
16 #define __ia64__
17 #elif defined(_X86_)
18 #define __i386__
19 #else
20 #error Unknown architecture
21 #endif
23 typedef INT8 int8_t;
24 typedef UINT8 uint8_t;
25 typedef INT16 int16_t;
26 typedef UINT16 uint16_t;
27 typedef INT32 int32_t;
28 typedef UINT32 uint32_t;
29 typedef UINT64 uint64_t;
31 #include <xen.h>
32 #include <grant_table.h>
33 #include <event_channel.h>
34 #include <xen_guids.h>
36 #define _PAGE_PRESENT 0x001UL
37 #define _PAGE_RW 0x002UL
38 #define _PAGE_USER 0x004UL
39 #define _PAGE_PWT 0x008UL
40 #define _PAGE_PCD 0x010UL
41 #define _PAGE_ACCESSED 0x020UL
42 #define _PAGE_DIRTY 0x040UL
43 #define _PAGE_PAT 0x080UL
44 #define _PAGE_PSE 0x080UL
45 #define _PAGE_GLOBAL 0x100UL
47 #define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED)
49 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
51 typedef unsigned long xenbus_transaction_t;
53 #define XBT_NIL ((xenbus_transaction_t)0)
55 #define SPLITSTRING_POOL_TAG (ULONG) 'SSPT'
57 #define wmb() KeMemoryBarrier()
58 #define mb() KeMemoryBarrier()
60 static __inline char **
61 SplitString(char *String, char Split, int MaxParts, int *Count) {
62 char **RetVal;
63 char *first;
64 char *last;
66 *Count = 0;
68 RetVal = (char **)ExAllocatePoolWithTag(NonPagedPool, (MaxParts + 1) * sizeof(char *), SPLITSTRING_POOL_TAG);
69 last = String;
70 do {
71 if (*Count == MaxParts)
72 break;
73 first = last;
74 for (last = first; *last != '\0' && *last != Split; last++);
75 RetVal[*Count] = (char *)ExAllocatePoolWithTag(NonPagedPool, last - first + 1, SPLITSTRING_POOL_TAG);
76 RtlStringCbCopyNA(RetVal[*Count], last - first + 1, first, last - first);
77 RetVal[*Count][last - first] = 0;
78 (*Count)++;
79 if (*last == Split)
80 last++;
81 } while (*last != 0);
82 RetVal[*Count] = NULL;
83 return RetVal;
84 }
86 static __inline VOID
87 FreeSplitString(char **Bits, int Count) {
88 int i;
90 for (i = 0; i < Count; i++)
91 ExFreePoolWithTag(Bits[i], SPLITSTRING_POOL_TAG);
92 ExFreePoolWithTag(Bits, SPLITSTRING_POOL_TAG);
93 }
95 #define ALLOCATE_PAGES_POOL_TAG (ULONG) 'APPT'
97 static PMDL
98 AllocatePagesExtra(int Pages, int ExtraSize)
99 {
100 PMDL Mdl;
101 PVOID Buf;
103 Buf = ExAllocatePoolWithTag(NonPagedPool, Pages * PAGE_SIZE, ALLOCATE_PAGES_POOL_TAG);
104 if (Buf == NULL) {
105 KdPrint((__DRIVER_NAME " AllocatePages Failed at ExAllocatePoolWithTag\n"));
106 return NULL;
107 }
108 Mdl = (PMDL)ExAllocatePoolWithTag(NonPagedPool, MmSizeOfMdl(Buf, Pages * PAGE_SIZE) + ExtraSize, ALLOCATE_PAGES_POOL_TAG);
109 if (Mdl == NULL) {
110 ExFreePoolWithTag(Buf, ALLOCATE_PAGES_POOL_TAG);
111 KdPrint((__DRIVER_NAME " AllocatePages Failed at IoAllocateMdl\n"));
112 return NULL;
113 }
115 MmInitializeMdl(Mdl, Buf, Pages * PAGE_SIZE);
116 MmBuildMdlForNonPagedPool(Mdl);
118 return Mdl;
119 }
121 static __inline PMDL
122 AllocatePages(int Pages) {
123 return AllocatePagesExtra(Pages, 0);
124 }
126 static __inline PMDL
127 AllocatePage() {
128 return AllocatePagesExtra(1, 0);
129 }
131 static __inline PMDL
132 AllocateUncachedPage() {
133 PMDL mdl;
134 PVOID buf;
136 buf = MmAllocateNonCachedMemory(PAGE_SIZE);
137 mdl = IoAllocateMdl(buf, PAGE_SIZE, FALSE, FALSE, NULL);
138 MmBuildMdlForNonPagedPool(mdl);
140 return mdl;
141 }
143 static __inline VOID
144 FreeUncachedPage(PMDL mdl) {
145 PVOID buf = MmGetMdlVirtualAddress(mdl);
147 IoFreeMdl(mdl);
148 MmFreeNonCachedMemory(buf, PAGE_SIZE);
149 }
151 static __inline VOID
152 FreePages(PMDL Mdl) {
153 PVOID Buf = MmGetMdlVirtualAddress(Mdl);
154 ExFreePoolWithTag(Mdl, ALLOCATE_PAGES_POOL_TAG);
155 ExFreePoolWithTag(Buf, ALLOCATE_PAGES_POOL_TAG);
156 }
158 #define XEN_IOPORT_BASE 0x10
160 /*
161 define these as pointers so that the READ_PORT* functions complain if
162 the wrong width is used with the wrong defined port
163 */
165 #define XEN_IOPORT_MAGIC ((PUSHORT)UlongToPtr(XEN_IOPORT_BASE + 0))
166 #define XEN_IOPORT_LOG ((PUCHAR)UlongToPtr(XEN_IOPORT_BASE + 2))
167 #define XEN_IOPORT_VERSION ((PUCHAR)UlongToPtr(XEN_IOPORT_BASE + 2))
168 #define XEN_IOPORT_PRODUCT ((PUSHORT)UlongToPtr(XEN_IOPORT_BASE + 2))
169 #define XEN_IOPORT_BUILD ((PULONG)UlongToPtr(XEN_IOPORT_BASE + 0))
170 #define XEN_IOPORT_DEVICE_MASK ((PUSHORT)UlongToPtr(XEN_IOPORT_BASE + 0))
172 #define QEMU_UNPLUG_ALL_IDE_DISKS 1
173 #define QEMU_UNPLUG_ALL_NICS 2
174 #define QEMU_UNPLUG_AUX_IDE_DISKS 4
176 #if DBG
177 #define FUNCTION_ENTER() XnDebugPrint(__DRIVER_NAME " --> %s\n", __FUNCTION__)
178 #define FUNCTION_EXIT() XnDebugPrint(__DRIVER_NAME " <-- %s\n", __FUNCTION__)
179 #define FUNCTION_EXIT_STATUS(_status) XnDebugPrint(__DRIVER_NAME " <-- %s, status = %08x\n", __FUNCTION__, _status)
180 #define FUNCTION_MSG(...) XnDebugPrint(__DRIVER_NAME " " __VA_ARGS__)
181 #else
182 #define FUNCTION_ENTER()
183 #define FUNCTION_EXIT()
184 #define FUNCTION_EXIT_STATUS(_status)
185 #define FUNCTION_MSG(...)
186 #endif
188 #define INVALID_GRANT_REF 0xFFFFFFFF
190 #define XN_BASE_FRONTEND 1 /* path is relative to frontend device */
191 #define XN_BASE_BACKEND 2 /* path is relative to backend device */
192 #define XN_BASE_GLOBAL 3 /* path is relative to root of xenstore */
194 #define XN_DEVICE_CALLBACK_BACKEND_STATE 1 /* backend state change callback */
195 #define XN_DEVICE_CALLBACK_SUSPEND 2
196 #define XN_DEVICE_CALLBACK_RESUME 3
198 typedef PVOID XN_HANDLE;
200 typedef VOID
201 (*PXN_WATCH_CALLBACK)(PVOID context, char *path);
203 typedef VOID
204 (*PXN_EVENT_CALLBACK)(PVOID context);
206 typedef VOID
207 (*PXN_DEVICE_CALLBACK)(PVOID context, ULONG callback_type, PVOID value);
209 ULONG
210 XnGetVersion();
212 XN_HANDLE
213 XnOpenDevice(PDEVICE_OBJECT pdo, PXN_DEVICE_CALLBACK callback, PVOID context);
215 VOID
216 XnCloseDevice(XN_HANDLE handle);
218 #define XN_VALUE_TYPE_QEMU_HIDE_FLAGS 1
219 #define XN_VALUE_TYPE_QEMU_FILTER 2 /* true if qemu devices hidden by device filter, not by qemu */
221 VOID
222 XnGetValue(XN_HANDLE handle, ULONG value_type, PVOID value);
224 NTSTATUS
225 XnReadInt32(XN_HANDLE handle, ULONG base, PCHAR path, ULONG *value);
227 NTSTATUS
228 XnWriteInt32(XN_HANDLE handle, ULONG base, PCHAR path, ULONG value);
230 NTSTATUS
231 XnReadInt64(XN_HANDLE handle, ULONG base, PCHAR path, ULONGLONG *value);
233 NTSTATUS
234 XnWriteInt64(XN_HANDLE handle, ULONG base, PCHAR path, ULONGLONG value);
236 NTSTATUS
237 XnReadString(XN_HANDLE handle, ULONG base, PCHAR path, PCHAR *value);
239 NTSTATUS
240 XnWriteString(XN_HANDLE handle, ULONG base, PCHAR path, PCHAR value);
242 NTSTATUS
243 XnFreeString(XN_HANDLE handle, PCHAR string);
245 NTSTATUS
246 XnNotify(XN_HANDLE handle, evtchn_port_t port);
248 grant_ref_t
249 XnGrantAccess(XN_HANDLE handle, uint32_t frame, int readonly, grant_ref_t ref, ULONG tag);
251 BOOLEAN
252 XnEndAccess(XN_HANDLE handle, grant_ref_t ref, BOOLEAN keepref, ULONG tag);
254 grant_ref_t
255 XnAllocateGrant(XN_HANDLE handle, ULONG tag);
257 VOID
258 XnFreeGrant(XN_HANDLE handle, grant_ref_t ref, ULONG tag);
260 NTSTATUS
261 XnBindEvent(XN_HANDLE handle, evtchn_port_t *port, PXN_EVENT_CALLBACK callback, PVOID context);
263 NTSTATUS
264 XnUnbindEvent(XN_HANDLE handle, evtchn_port_t port);
266 ULONG
267 XnTmemOp(struct tmem_op *tmem_op);
269 #ifndef XENPCI_POOL_TAG
270 #define XENPCI_POOL_TAG (ULONG) 'XenP'
271 #endif
273 static __inline VOID
274 XnFreeMem(XN_HANDLE handle, PVOID Ptr) {
275 UNREFERENCED_PARAMETER(handle);
276 ExFreePoolWithTag(Ptr, XENPCI_POOL_TAG);
277 }
279 PVOID
280 XnGetHypercallStubs();
282 VOID
283 XnSetHypercallStubs(PVOID _hypercall_stubs);
285 NTSTATUS
286 XnDebugPrint(PCHAR format, ...);
288 VOID
289 XnPrintDump();
291 #if DBG
292 #define XN_ASSERT(expr) \
293 if (!(expr)) { \
294 XnDebugPrint("ASSERT(%s) %s:%d\n", #expr, __FILE__, __LINE__); \
295 ASSERT(expr); \
296 }
297 #else
298 #define XN_ASSERT(expr)
299 #endif
301 #endif