win-pvdrivers

view common/include/xen_windows.h @ 1024:53d89db72d24

Update debugprint macros
author James Harper <james.harper@bendigoit.com.au>
date Tue Feb 19 15:13:22 2013 +1100 (2013-02-19)
parents 2cbbfed14af4
children e0944ce4ea98
line source
1 #if !defined(_XEN_WINDOWS_H_)
2 #define _XEN_WINDOWS_H_
4 #include "gplpv_version.h"
6 #include <ntverp.h>
7 #pragma warning( disable : 4201 ) // nonstandard extension used : nameless struct/union
8 #pragma warning( disable : 4214 ) // nonstandard extension used : bit field types other than int
9 #pragma warning( disable : 4505 ) // 'XenDbgPrint' : unreferenced local function has been removed
11 #define __XEN_INTERFACE_VERSION__ 0x00030205
12 #if defined(_AMD64_)
13 #define __x86_64__
14 #elif defined(_IA64_)
15 #define __ia64__
16 #elif defined(_X86_)
17 #define __i386__
18 #else
19 #error Unknown architecture
20 #endif
22 typedef INT8 int8_t;
23 typedef UINT8 uint8_t;
24 typedef INT16 int16_t;
25 typedef UINT16 uint16_t;
26 typedef INT32 int32_t;
27 typedef UINT32 uint32_t;
28 typedef UINT64 uint64_t;
30 #include <xen.h>
31 #include <grant_table.h>
32 #include <event_channel.h>
33 #include <xen_guids.h>
35 #define _PAGE_PRESENT 0x001UL
36 #define _PAGE_RW 0x002UL
37 #define _PAGE_USER 0x004UL
38 #define _PAGE_PWT 0x008UL
39 #define _PAGE_PCD 0x010UL
40 #define _PAGE_ACCESSED 0x020UL
41 #define _PAGE_DIRTY 0x040UL
42 #define _PAGE_PAT 0x080UL
43 #define _PAGE_PSE 0x080UL
44 #define _PAGE_GLOBAL 0x100UL
46 #define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED)
48 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
50 typedef unsigned long xenbus_transaction_t;
52 #define XBT_NIL ((xenbus_transaction_t)0)
54 #define SPLITSTRING_POOL_TAG (ULONG) 'SSPT'
56 #define wmb() KeMemoryBarrier()
57 #define mb() KeMemoryBarrier()
59 static __inline char **
60 SplitString(char *String, char Split, int MaxParts, int *Count) {
61 char **RetVal;
62 char *first;
63 char *last;
65 *Count = 0;
67 RetVal = (char **)ExAllocatePoolWithTag(NonPagedPool, (MaxParts + 1) * sizeof(char *), SPLITSTRING_POOL_TAG);
68 last = String;
69 do {
70 if (*Count == MaxParts)
71 break;
72 first = last;
73 for (last = first; *last != '\0' && *last != Split; last++);
74 RetVal[*Count] = (char *)ExAllocatePoolWithTag(NonPagedPool, last - first + 1, SPLITSTRING_POOL_TAG);
75 RtlStringCbCopyNA(RetVal[*Count], last - first + 1, first, last - first);
76 RetVal[*Count][last - first] = 0;
77 (*Count)++;
78 if (*last == Split)
79 last++;
80 } while (*last != 0);
81 RetVal[*Count] = NULL;
82 return RetVal;
83 }
85 static __inline VOID
86 FreeSplitString(char **Bits, int Count) {
87 int i;
89 for (i = 0; i < Count; i++)
90 ExFreePoolWithTag(Bits[i], SPLITSTRING_POOL_TAG);
91 ExFreePoolWithTag(Bits, SPLITSTRING_POOL_TAG);
92 }
94 #define ALLOCATE_PAGES_POOL_TAG (ULONG) 'APPT'
96 static PMDL
97 AllocatePagesExtra(int Pages, int ExtraSize)
98 {
99 PMDL Mdl;
100 PVOID Buf;
102 Buf = ExAllocatePoolWithTag(NonPagedPool, Pages * PAGE_SIZE, ALLOCATE_PAGES_POOL_TAG);
103 if (Buf == NULL) {
104 KdPrint((__DRIVER_NAME " AllocatePages Failed at ExAllocatePoolWithTag\n"));
105 return NULL;
106 }
107 Mdl = (PMDL)ExAllocatePoolWithTag(NonPagedPool, MmSizeOfMdl(Buf, Pages * PAGE_SIZE) + ExtraSize, ALLOCATE_PAGES_POOL_TAG);
108 if (Mdl == NULL) {
109 ExFreePoolWithTag(Buf, ALLOCATE_PAGES_POOL_TAG);
110 KdPrint((__DRIVER_NAME " AllocatePages Failed at IoAllocateMdl\n"));
111 return NULL;
112 }
114 MmInitializeMdl(Mdl, Buf, Pages * PAGE_SIZE);
115 MmBuildMdlForNonPagedPool(Mdl);
117 return Mdl;
118 }
120 static __inline PMDL
121 AllocatePages(int Pages) {
122 return AllocatePagesExtra(Pages, 0);
123 }
125 static __inline PMDL
126 AllocatePage() {
127 return AllocatePagesExtra(1, 0);
128 }
130 static __inline PMDL
131 AllocateUncachedPage() {
132 PMDL mdl;
133 PVOID buf;
135 buf = MmAllocateNonCachedMemory(PAGE_SIZE);
136 mdl = IoAllocateMdl(buf, PAGE_SIZE, FALSE, FALSE, NULL);
137 MmBuildMdlForNonPagedPool(mdl);
139 return mdl;
140 }
142 static __inline VOID
143 FreeUncachedPage(PMDL mdl) {
144 PVOID buf = MmGetMdlVirtualAddress(mdl);
146 IoFreeMdl(mdl);
147 MmFreeNonCachedMemory(buf, PAGE_SIZE);
148 }
150 static __inline VOID
151 FreePages(PMDL Mdl) {
152 PVOID Buf = MmGetMdlVirtualAddress(Mdl);
153 ExFreePoolWithTag(Mdl, ALLOCATE_PAGES_POOL_TAG);
154 ExFreePoolWithTag(Buf, ALLOCATE_PAGES_POOL_TAG);
155 }
157 #define XEN_IOPORT_BASE 0x10
159 /*
160 define these as pointers so that the READ_PORT* functions complain if
161 the wrong width is used with the wrong defined port
162 */
164 #define XEN_IOPORT_MAGIC ((PUSHORT)UlongToPtr(XEN_IOPORT_BASE + 0))
165 #define XEN_IOPORT_LOG ((PUCHAR)UlongToPtr(XEN_IOPORT_BASE + 2))
166 #define XEN_IOPORT_VERSION ((PUCHAR)UlongToPtr(XEN_IOPORT_BASE + 2))
167 #define XEN_IOPORT_PRODUCT ((PUSHORT)UlongToPtr(XEN_IOPORT_BASE + 2))
168 #define XEN_IOPORT_BUILD ((PULONG)UlongToPtr(XEN_IOPORT_BASE + 0))
169 #define XEN_IOPORT_DEVICE_MASK ((PUSHORT)UlongToPtr(XEN_IOPORT_BASE + 0))
171 #define QEMU_UNPLUG_ALL_IDE_DISKS 1
172 #define QEMU_UNPLUG_ALL_NICS 2
173 #define QEMU_UNPLUG_AUX_IDE_DISKS 4
175 #define FUNCTION_ENTER() XnDebugPrint(__DRIVER_NAME " --> %s\n", __FUNCTION__)
176 #define FUNCTION_EXIT() XnDebugPrint(__DRIVER_NAME " <-- %s\n", __FUNCTION__)
177 #define FUNCTION_EXIT_STATUS(_status) XnDebugPrint(__DRIVER_NAME " <-- %s, status = %08x\n", __FUNCTION__, _status)
178 #define FUNCTION_MSG(...) XnDebugPrint(__DRIVER_NAME " " __VA_ARGS__)
180 #define INVALID_GRANT_REF 0xFFFFFFFF
182 #define XN_BASE_FRONTEND 1 /* path is relative to frontend device */
183 #define XN_BASE_BACKEND 2 /* path is relative to backend device */
184 #define XN_BASE_GLOBAL 3 /* path is relative to root of xenstore */
186 #define XN_DEVICE_CALLBACK_BACKEND_STATE 1 /* backend state change callback */
187 #define XN_DEVICE_CALLBACK_SUSPEND 2
188 #define XN_DEVICE_CALLBACK_RESUME 3
190 typedef PVOID XN_HANDLE;
192 typedef VOID
193 (*PXN_WATCH_CALLBACK)(PVOID context, char *path);
195 typedef VOID
196 (*PXN_EVENT_CALLBACK)(PVOID context);
198 typedef VOID
199 (*PXN_DEVICE_CALLBACK)(PVOID context, ULONG callback_type, PVOID value);
201 ULONG
202 XnGetVersion();
204 XN_HANDLE
205 XnOpenDevice(PDEVICE_OBJECT pdo, PXN_DEVICE_CALLBACK callback, PVOID context);
207 VOID
208 XnCloseDevice(XN_HANDLE handle);
210 #define XN_VALUE_TYPE_QEMU_HIDE_FLAGS 1
211 #define XN_VALUE_TYPE_QEMU_FILTER 2 /* true if qemu devices hidden by device filter, not by qemu */
213 VOID
214 XnGetValue(XN_HANDLE handle, ULONG value_type, PVOID value);
216 NTSTATUS
217 XnReadInt32(XN_HANDLE handle, ULONG base, PCHAR path, ULONG *value);
219 NTSTATUS
220 XnWriteInt32(XN_HANDLE handle, ULONG base, PCHAR path, ULONG value);
222 NTSTATUS
223 XnReadInt64(XN_HANDLE handle, ULONG base, PCHAR path, ULONGLONG *value);
225 NTSTATUS
226 XnWriteInt64(XN_HANDLE handle, ULONG base, PCHAR path, ULONGLONG value);
228 NTSTATUS
229 XnReadString(XN_HANDLE handle, ULONG base, PCHAR path, PCHAR *value);
231 NTSTATUS
232 XnWriteString(XN_HANDLE handle, ULONG base, PCHAR path, PCHAR value);
234 NTSTATUS
235 XnFreeString(XN_HANDLE handle, PCHAR string);
237 NTSTATUS
238 XnNotify(XN_HANDLE handle, evtchn_port_t port);
240 grant_ref_t
241 XnGrantAccess(XN_HANDLE handle, uint32_t frame, int readonly, grant_ref_t ref, ULONG tag);
243 BOOLEAN
244 XnEndAccess(XN_HANDLE handle, grant_ref_t ref, BOOLEAN keepref, ULONG tag);
246 grant_ref_t
247 XnAllocateGrant(XN_HANDLE handle, ULONG tag);
249 VOID
250 XnFreeGrant(XN_HANDLE handle, grant_ref_t ref, ULONG tag);
252 NTSTATUS
253 XnBindEvent(XN_HANDLE handle, evtchn_port_t *port, PXN_EVENT_CALLBACK callback, PVOID context);
255 NTSTATUS
256 XnUnbindEvent(XN_HANDLE handle, evtchn_port_t port);
258 #ifndef XENPCI_POOL_TAG
259 #define XENPCI_POOL_TAG (ULONG) 'XenP'
260 #endif
262 static __inline VOID
263 XnFreeMem(XN_HANDLE handle, PVOID Ptr) {
264 UNREFERENCED_PARAMETER(handle);
265 ExFreePoolWithTag(Ptr, XENPCI_POOL_TAG);
266 }
269 //VOID
270 //XnDumpModeHookDebugPrint();
273 NTSTATUS
274 XnDebugPrint(PCHAR format, ...);
276 VOID
277 XnPrintDump();
279 #if DBG
280 #define XN_ASSERT(expr) \
281 if (!(expr)) { \
282 XnDebugPrint("ASSERT(%s) %s:%d\n", #expr, __FILE__, __LINE__); \
283 ASSERT(expr); \
284 }
285 #else
286 #define XN_ASSERT(expr)
287 #endif
289 #endif