win-pvdrivers

view common/include/xen_windows.h @ 398:e7292fd9e55a

Fixup xenpci for mingw build with DBG enabled.

add FUNCTION_EXIT_STATUS macro
run unix2dos to fix line endings
update mingw makefiles
use FUNCTION_* macros in xenpci
author Andy Grover <andy.grover@oracle.com>
date Thu Jul 17 10:33:40 2008 -0700 (2008-07-17)
parents 7259dad4e96c
children b9028997f48b
line source
1 #if !defined(_XEN_WINDOWS_H_)
2 #define _XEN_WINDOWS_H_
4 #pragma warning( disable : 4201 ) // nonstandard extension used : nameless struct/union
5 #pragma warning( disable : 4214 ) // nonstandard extension used : bit field types other than int
7 #define __XEN_INTERFACE_VERSION__ 0x00030205
8 #if defined(_AMD64_)
9 #define __x86_64__
10 #elif defined(_IA64_)
11 #define __ia64__
12 #elif defined(__MINGW32__)
13 /* __i386__ already defined */
14 #elif defined(_X86_)
15 #define __i386__
16 #else
17 #error Unknown architecture
18 #endif
20 #ifdef __MINGW32__
21 typedef signed char int8_t;
22 typedef unsigned char uint8_t;
23 typedef signed short int16_t;
24 typedef unsigned short uint16_t;
25 typedef signed int int32_t;
26 typedef unsigned int uint32_t;
27 typedef unsigned long long uint64_t;
28 #else
29 typedef INT8 int8_t;
30 typedef UINT8 uint8_t;
31 typedef INT16 int16_t;
32 typedef UINT16 uint16_t;
33 typedef INT32 int32_t;
34 typedef UINT32 uint32_t;
35 typedef UINT64 uint64_t;
36 #endif
38 #include <xen.h>
40 #define _PAGE_PRESENT 0x001UL
41 #define _PAGE_RW 0x002UL
42 #define _PAGE_USER 0x004UL
43 #define _PAGE_PWT 0x008UL
44 #define _PAGE_PCD 0x010UL
45 #define _PAGE_ACCESSED 0x020UL
46 #define _PAGE_DIRTY 0x040UL
47 #define _PAGE_PAT 0x080UL
48 #define _PAGE_PSE 0x080UL
49 #define _PAGE_GLOBAL 0x100UL
51 #define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED)
53 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
55 typedef unsigned long xenbus_transaction_t;
57 #define XBT_NIL ((xenbus_transaction_t)0)
59 #define SPLITSTRING_POOL_TAG (ULONG) 'SSPT'
61 #define wmb() KeMemoryBarrier()
62 #define mb() KeMemoryBarrier()
64 #define FUNCTION_ENTER() KdPrint((__DRIVER_NAME " --> %s\n", __FUNCTION__))
65 #define FUNCTION_EXIT() KdPrint((__DRIVER_NAME " <-- %s\n", __FUNCTION__))
66 #define FUNCTION_EXIT_STATUS(_status) KdPrint((__DRIVER_NAME " <-- %s, status = %08x\n", __FUNCTION__, _status))
67 #define FUNCTION_ERROR_EXIT() KdPrint((__DRIVER_NAME " <-- %s (error path)\n", __FUNCTION__))
68 #define FUNCTION_CALLED() KdPrint((__DRIVER_NAME " %s called (line %d)\n", __FUNCTION__, __LINE__))
69 #ifdef __MINGW32__
70 #define FUNCTION_MSG(_x) _FUNCTION_MSG _x
71 #define _FUNCTION_MSG(format, args...) KdPrint((__DRIVER_NAME " %s called: " format, __FUNCTION__, ##args))
72 #else
73 #define FUNCTION_MSG(_x) { \
74 KdPrint((__DRIVER_NAME " %s called: ", __FUNCTION__)); \
75 KdPrint(_x); \
76 }
77 #endif
79 static __inline char **
80 SplitString(char *String, char Split, int MaxParts, int *Count)
81 {
82 char **RetVal;
83 char *first;
84 char *last;
86 //KdPrint((__DRIVER_NAME " a\n"));
88 *Count = 0;
90 RetVal = ExAllocatePoolWithTag(NonPagedPool, (MaxParts + 1) * sizeof(char *), SPLITSTRING_POOL_TAG);
91 last = String;
92 do
93 {
94 if (*Count == MaxParts)
95 break;
96 //KdPrint((__DRIVER_NAME " b - count = %d\n", *Count));
97 first = last;
98 for (last = first; *last != '\0' && *last != Split; last++);
99 RetVal[*Count] = ExAllocatePoolWithTag(NonPagedPool, last - first + 1, SPLITSTRING_POOL_TAG);
100 //KdPrint((__DRIVER_NAME " c - count = %d\n", *Count));
101 strncpy(RetVal[*Count], first, last - first);
102 RetVal[*Count][last - first] = 0;
103 //KdPrint((__DRIVER_NAME " d - count = %d\n", *Count));
104 (*Count)++;
105 //KdPrint((__DRIVER_NAME " e - count = %d\n", *Count));
106 if (*last == Split)
107 last++;
108 } while (*last != 0);
109 //KdPrint((__DRIVER_NAME " f - count = %d\n", *Count));
110 RetVal[*Count] = NULL;
111 return RetVal;
112 }
114 static __inline VOID
115 FreeSplitString(char **Bits, int Count)
116 {
117 int i;
119 for (i = 0; i < Count; i++)
120 ExFreePoolWithTag(Bits[i], SPLITSTRING_POOL_TAG);
121 ExFreePoolWithTag(Bits, SPLITSTRING_POOL_TAG);
122 }
124 #define ALLOCATE_PAGES_POOL_TAG (ULONG) 'APPT'
126 static PMDL
127 AllocatePagesExtra(int Pages, int ExtraSize)
128 {
129 PMDL Mdl;
130 PVOID Buf;
132 Buf = ExAllocatePoolWithTag(NonPagedPool, Pages * PAGE_SIZE, ALLOCATE_PAGES_POOL_TAG);
133 if (Buf == NULL)
134 {
135 KdPrint((__DRIVER_NAME " AllocatePages Failed at ExAllocatePoolWithTag\n"));
136 return NULL;
137 }
138 // KdPrint((__DRIVER_NAME " --- AllocatePages IRQL = %d, Buf = %p\n", KeGetCurrentIrql(), Buf));
139 Mdl = ExAllocatePoolWithTag(NonPagedPool, MmSizeOfMdl(Buf, Pages * PAGE_SIZE) + ExtraSize, ALLOCATE_PAGES_POOL_TAG);
140 //Mdl = IoAllocateMdl(Buf, Pages * PAGE_SIZE, FALSE, FALSE, NULL);
141 if (Mdl == NULL)
142 {
143 // free the memory here
144 KdPrint((__DRIVER_NAME " AllocatePages Failed at IoAllocateMdl\n"));
145 return NULL;
146 }
148 MmInitializeMdl(Mdl, Buf, Pages * PAGE_SIZE);
149 MmBuildMdlForNonPagedPool(Mdl);
151 return Mdl;
152 }
154 static __inline PMDL
155 AllocatePages(int Pages)
156 {
157 return AllocatePagesExtra(Pages, 0);
158 }
160 static __inline PMDL
161 AllocatePage()
162 {
163 return AllocatePagesExtra(1, 0);
164 }
166 static __inline PMDL
167 AllocateUncachedPage()
168 {
169 PMDL mdl;
170 PVOID buf;
172 buf = MmAllocateNonCachedMemory(PAGE_SIZE);
173 mdl = IoAllocateMdl(buf, PAGE_SIZE, FALSE, FALSE, NULL);
174 MmBuildMdlForNonPagedPool(mdl);
176 return mdl;
177 }
179 static __inline VOID
180 FreeUncachedPage(PMDL mdl)
181 {
182 PVOID buf = MmGetMdlVirtualAddress(mdl);
184 IoFreeMdl(mdl);
185 MmFreeNonCachedMemory(buf, PAGE_SIZE);
186 }
188 static __inline VOID
189 FreePages(PMDL Mdl)
190 {
191 PVOID Buf = MmGetMdlVirtualAddress(Mdl);
192 // KdPrint((__DRIVER_NAME " --- FreePages IRQL = %d, Buf = %p\n", KeGetCurrentIrql(), Buf));
193 // IoFreeMdl(Mdl);
194 ExFreePoolWithTag(Mdl, ALLOCATE_PAGES_POOL_TAG);
195 ExFreePoolWithTag(Buf, ALLOCATE_PAGES_POOL_TAG);
196 }
198 #endif