]>
Commit | Line | Data |
---|---|---|
2cb7cef9 BS |
1 | From bee20ea87b3e6f246b387f707983a0ef47c8a15b Mon Sep 17 00:00:00 2001 |
2 | From: Hank Janssen <hjanssen@microsoft.com> | |
3 | Date: Mon, 13 Jul 2009 15:19:28 -0700 | |
4 | Subject: Staging: hv: add the Hyper-V driver header files | |
5 | ||
6 | From: Hank Janssen <hjanssen@microsoft.com> | |
7 | ||
8 | These are the header files for the different Linux Hyper-V drivers to | |
9 | use. | |
10 | ||
11 | Signed-off-by: Hank Janssen <hjanssen@microsoft.com> | |
12 | Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com> | |
13 | Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> | |
14 | --- | |
15 | drivers/staging/hv/include/NetVscApi.h | 145 +++++++++++++++++ | |
16 | drivers/staging/hv/include/StorVscApi.h | 137 ++++++++++++++++ | |
17 | drivers/staging/hv/include/VmbusApi.h | 262 +++++++++++++++++++++++++++++++ | |
18 | drivers/staging/hv/include/logging.h | 134 ++++++++++++++++ | |
19 | drivers/staging/hv/include/osd.h | 263 ++++++++++++++++++++++++++++++++ | |
20 | drivers/staging/hv/include/vmbus.h | 111 +++++++++++++ | |
21 | 6 files changed, 1052 insertions(+) | |
22 | create mode 100644 drivers/staging/hv/include/NetVscApi.h | |
23 | create mode 100644 drivers/staging/hv/include/StorVscApi.h | |
24 | create mode 100644 drivers/staging/hv/include/VmbusApi.h | |
25 | create mode 100644 drivers/staging/hv/include/logging.h | |
26 | create mode 100644 drivers/staging/hv/include/osd.h | |
27 | create mode 100644 drivers/staging/hv/include/vmbus.h | |
28 | ||
29 | --- /dev/null | |
30 | +++ b/drivers/staging/hv/include/logging.h | |
31 | @@ -0,0 +1,134 @@ | |
32 | +/* | |
33 | + * | |
34 | + * Copyright (c) 2009, Microsoft Corporation. | |
35 | + * | |
36 | + * This program is free software; you can redistribute it and/or modify it | |
37 | + * under the terms and conditions of the GNU General Public License, | |
38 | + * version 2, as published by the Free Software Foundation. | |
39 | + * | |
40 | + * This program is distributed in the hope it will be useful, but WITHOUT | |
41 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
42 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
43 | + * more details. | |
44 | + * | |
45 | + * You should have received a copy of the GNU General Public License along with | |
46 | + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple | |
47 | + * Place - Suite 330, Boston, MA 02111-1307 USA. | |
48 | + * | |
49 | + * Authors: | |
50 | + * Haiyang Zhang <haiyangz@microsoft.com> | |
51 | + * Hank Janssen <hjanssen@microsoft.com> | |
52 | + * | |
53 | + */ | |
54 | + | |
55 | + | |
56 | +#ifndef _LOGGING_H_ | |
57 | +#define _LOGGING_H_ | |
58 | + | |
59 | +//#include <linux/init.h> | |
60 | +//#include <linux/module.h> | |
61 | + | |
62 | +#include "osd.h" | |
63 | + | |
64 | +#define VMBUS 0x0001 | |
65 | +#define STORVSC 0x0002 | |
66 | +#define NETVSC 0x0004 | |
67 | +#define INPUTVSC 0x0008 | |
68 | +#define BLKVSC 0x0010 | |
69 | +#define VMBUS_DRV 0x0100 | |
70 | +#define STORVSC_DRV 0x0200 | |
71 | +#define NETVSC_DRV 0x0400 | |
72 | +#define INPUTVSC_DRV 0x0800 | |
73 | +#define BLKVSC_DRV 0x1000 | |
74 | + | |
75 | +#define ALL_MODULES (VMBUS |\ | |
76 | + STORVSC |\ | |
77 | + NETVSC |\ | |
78 | + INPUTVSC |\ | |
79 | + BLKVSC |\ | |
80 | + VMBUS_DRV |\ | |
81 | + STORVSC_DRV |\ | |
82 | + NETVSC_DRV |\ | |
83 | + INPUTVSC_DRV|\ | |
84 | + BLKVSC_DRV) | |
85 | + | |
86 | +// Logging Level | |
87 | +#define CRITICAL_LVL 2 | |
88 | +#define ERROR_LVL 3 | |
89 | +#define WARNING_LVL 4 | |
90 | +#define INFO_LVL 6 | |
91 | +#define DEBUG_LVL 7 | |
92 | +#define DEBUG_LVL_ENTEREXIT 8 | |
93 | +#define DEBUG_RING_LVL 9 | |
94 | + | |
95 | +extern unsigned int vmbus_loglevel; | |
96 | + | |
97 | +#define ASSERT(expr) \ | |
98 | + if (!(expr)) { \ | |
99 | + LogMsg("<%d>Assertion failed! %s,%s,%s,line=%d\n", CRITICAL_LVL, #expr,__FILE__,__FUNCTION__,__LINE__); \ | |
100 | + __asm__ __volatile__("int3"); \ | |
101 | + } | |
102 | + | |
103 | +#define DPRINT(mod, lvl, fmt, args...) do {\ | |
104 | + if (mod & (HIWORD(vmbus_loglevel))) \ | |
105 | + (lvl <= LOWORD(vmbus_loglevel))?(LogMsg("<%d>" #mod": %s() " fmt "\n", DEBUG_LVL, __FUNCTION__, ## args)):(0);\ | |
106 | + } while (0) | |
107 | + | |
108 | +#define DPRINT_DBG(mod, fmt, args...) do {\ | |
109 | + if (mod & (HIWORD(vmbus_loglevel))) \ | |
110 | + (DEBUG_LVL <= LOWORD(vmbus_loglevel))?(LogMsg("<%d>" #mod": %s() " fmt "\n", DEBUG_LVL, __FUNCTION__, ## args)):(0);\ | |
111 | + } while (0) | |
112 | + | |
113 | +#define DPRINT_INFO(mod, fmt, args...) do {\ | |
114 | + if (mod & (HIWORD(vmbus_loglevel))) \ | |
115 | + (INFO_LVL <= LOWORD(vmbus_loglevel))?(LogMsg("<%d>" #mod": " fmt "\n", INFO_LVL, ## args)):(0);\ | |
116 | + } while (0) | |
117 | + | |
118 | +#define DPRINT_WARN(mod, fmt, args...) do {\ | |
119 | + if (mod & (HIWORD(vmbus_loglevel))) \ | |
120 | + (WARNING_LVL <= LOWORD(vmbus_loglevel))?(LogMsg("<%d>" #mod": WARNING! " fmt "\n", WARNING_LVL, ## args)):(0);\ | |
121 | + } while (0) | |
122 | + | |
123 | +#define DPRINT_ERR(mod, fmt, args...) do {\ | |
124 | + if (mod & (HIWORD(vmbus_loglevel))) \ | |
125 | + (ERROR_LVL <= LOWORD(vmbus_loglevel))?(LogMsg("<%d>" #mod": %s() ERROR!! " fmt "\n", ERROR_LVL, __FUNCTION__, ## args)):(0);\ | |
126 | + } while (0) | |
127 | + | |
128 | +#ifdef DEBUG | |
129 | +#define DPRINT_ENTER(mod) do {\ | |
130 | + if (mod & (HIWORD(vmbus_loglevel))) \ | |
131 | + (DEBUG_LVL_ENTEREXIT <= LOWORD(vmbus_loglevel))?(LogMsg("<%d>" "["#mod"]: %s() enter\n", DEBUG_LVL, __FUNCTION__)):(0);\ | |
132 | + } while (0) | |
133 | + | |
134 | +#define DPRINT_EXIT(mod) do {\ | |
135 | + if (mod & (HIWORD(vmbus_loglevel))) \ | |
136 | + (DEBUG_LVL_ENTEREXIT <= LOWORD(vmbus_loglevel))?(LogMsg("<%d>" "["#mod"]: %s() exit\n", DEBUG_LVL, __FUNCTION__)):(0);\ | |
137 | + } while (0) | |
138 | +#else | |
139 | +#define DPRINT_ENTER(mod) | |
140 | +#define DPRINT_EXIT(mod) | |
141 | +#endif | |
142 | + | |
143 | +static inline void PrintBytes(const unsigned char* bytes, int len) | |
144 | +{ | |
145 | + int i=0; | |
146 | + | |
147 | + LogMsg("\n<< "); | |
148 | + for (i=0; i< len; i++) | |
149 | + { | |
150 | + LogMsg("0x%x ", bytes[i]); | |
151 | + } | |
152 | + LogMsg(">>\n"); | |
153 | +} | |
154 | + | |
155 | +// | |
156 | +// Inline | |
157 | +// | |
158 | +//static inline void GuidToStr(const GUID g, char *str) | |
159 | +//{ | |
160 | +// sprintf(str, "{%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}", | |
161 | +// g[3], g[2], g[1], g[0], g[5], g[4], g[7], g[6], g[8], g[9], g[10], g[11], g[12], g[13], g[14], g[15]); | |
162 | +// | |
163 | +//} | |
164 | + | |
165 | +#endif //_LOGGING_H_ | |
166 | --- /dev/null | |
167 | +++ b/drivers/staging/hv/include/NetVscApi.h | |
168 | @@ -0,0 +1,145 @@ | |
169 | +/* | |
170 | + * | |
171 | + * Copyright (c) 2009, Microsoft Corporation. | |
172 | + * | |
173 | + * This program is free software; you can redistribute it and/or modify it | |
174 | + * under the terms and conditions of the GNU General Public License, | |
175 | + * version 2, as published by the Free Software Foundation. | |
176 | + * | |
177 | + * This program is distributed in the hope it will be useful, but WITHOUT | |
178 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
179 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
180 | + * more details. | |
181 | + * | |
182 | + * You should have received a copy of the GNU General Public License along with | |
183 | + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple | |
184 | + * Place - Suite 330, Boston, MA 02111-1307 USA. | |
185 | + * | |
186 | + * Authors: | |
187 | + * Haiyang Zhang <haiyangz@microsoft.com> | |
188 | + * Hank Janssen <hjanssen@microsoft.com> | |
189 | + * | |
190 | + */ | |
191 | + | |
192 | + | |
193 | +#ifndef _NETVSC_API_H_ | |
194 | +#define _NETVSC_API_H_ | |
195 | + | |
196 | +#include "VmbusApi.h" | |
197 | + | |
198 | +// | |
199 | +// Defines | |
200 | +// | |
201 | +#define NETVSC_DEVICE_RING_BUFFER_SIZE 64*PAGE_SIZE | |
202 | + | |
203 | +#define HW_MACADDR_LEN 6 | |
204 | + | |
205 | +// | |
206 | +// Fwd declaration | |
207 | +// | |
208 | +typedef struct _NETVSC_PACKET *PNETVSC_PACKET; | |
209 | + | |
210 | + | |
211 | +// | |
212 | +// Data types | |
213 | +// | |
214 | + | |
215 | +typedef int (*PFN_ON_OPEN)(DEVICE_OBJECT *Device); | |
216 | +typedef int (*PFN_ON_CLOSE)(DEVICE_OBJECT *Device); | |
217 | + | |
218 | +typedef void (*PFN_QUERY_LINKSTATUS)(DEVICE_OBJECT *Device); | |
219 | +typedef int (*PFN_ON_SEND)(DEVICE_OBJECT *dev, PNETVSC_PACKET packet); | |
220 | +typedef void (*PFN_ON_SENDRECVCOMPLETION)(PVOID Context); | |
221 | + | |
222 | +typedef int (*PFN_ON_RECVCALLBACK)(DEVICE_OBJECT *dev, PNETVSC_PACKET packet); | |
223 | +typedef void (*PFN_ON_LINKSTATUS_CHANGED)(DEVICE_OBJECT *dev, UINT32 Status); | |
224 | + | |
225 | +// Represent the xfer page packet which contains 1 or more netvsc packet | |
226 | +typedef struct _XFERPAGE_PACKET { | |
227 | + DLIST_ENTRY ListEntry; | |
228 | + | |
229 | + // # of netvsc packets this xfer packet contains | |
230 | + UINT32 Count; | |
231 | +} XFERPAGE_PACKET; | |
232 | + | |
233 | + | |
234 | +// The number of pages which are enough to cover jumbo frame buffer. | |
235 | +#define NETVSC_PACKET_MAXPAGE 4 | |
236 | + | |
237 | +// Represent netvsc packet which contains 1 RNDIS and 1 ethernet frame within the RNDIS | |
238 | +typedef struct _NETVSC_PACKET { | |
239 | + // Bookkeeping stuff | |
240 | + DLIST_ENTRY ListEntry; | |
241 | + | |
242 | + DEVICE_OBJECT *Device; | |
243 | + BOOL IsDataPacket; | |
244 | + | |
245 | + // Valid only for receives when we break a xfer page packet into multiple netvsc packets | |
246 | + XFERPAGE_PACKET *XferPagePacket; | |
247 | + | |
248 | + union { | |
249 | + struct{ | |
250 | + UINT64 ReceiveCompletionTid; | |
251 | + PVOID ReceiveCompletionContext; | |
252 | + PFN_ON_SENDRECVCOMPLETION OnReceiveCompletion; | |
253 | + } Recv; | |
254 | + struct{ | |
255 | + UINT64 SendCompletionTid; | |
256 | + PVOID SendCompletionContext; | |
257 | + PFN_ON_SENDRECVCOMPLETION OnSendCompletion; | |
258 | + } Send; | |
259 | + } Completion; | |
260 | + | |
261 | + // This points to the memory after PageBuffers | |
262 | + PVOID Extension; | |
263 | + | |
264 | + UINT32 TotalDataBufferLength; | |
265 | + // Points to the send/receive buffer where the ethernet frame is | |
266 | + UINT32 PageBufferCount; | |
267 | + PAGE_BUFFER PageBuffers[NETVSC_PACKET_MAXPAGE]; | |
268 | + | |
269 | +} NETVSC_PACKET; | |
270 | + | |
271 | + | |
272 | +// Represents the net vsc driver | |
273 | +typedef struct _NETVSC_DRIVER_OBJECT { | |
274 | + DRIVER_OBJECT Base; // Must be the first field | |
275 | + | |
276 | + UINT32 RingBufferSize; | |
277 | + UINT32 RequestExtSize; | |
278 | + | |
279 | + // Additional num of page buffers to allocate | |
280 | + UINT32 AdditionalRequestPageBufferCount; | |
281 | + | |
282 | + // This is set by the caller to allow us to callback when we receive a packet | |
283 | + // from the "wire" | |
284 | + PFN_ON_RECVCALLBACK OnReceiveCallback; | |
285 | + | |
286 | + PFN_ON_LINKSTATUS_CHANGED OnLinkStatusChanged; | |
287 | + | |
288 | + // Specific to this driver | |
289 | + PFN_ON_OPEN OnOpen; | |
290 | + PFN_ON_CLOSE OnClose; | |
291 | + PFN_ON_SEND OnSend; | |
292 | + //PFN_ON_RECVCOMPLETION OnReceiveCompletion; | |
293 | + | |
294 | + //PFN_QUERY_LINKSTATUS QueryLinkStatus; | |
295 | + | |
296 | + void* Context; | |
297 | +} NETVSC_DRIVER_OBJECT; | |
298 | + | |
299 | + | |
300 | +typedef struct _NETVSC_DEVICE_INFO { | |
301 | + UCHAR MacAddr[6]; | |
302 | + BOOL LinkState; // 0 - link up, 1 - link down | |
303 | +} NETVSC_DEVICE_INFO; | |
304 | + | |
305 | +// | |
306 | +// Interface | |
307 | +// | |
308 | +int | |
309 | +NetVscInitialize( | |
310 | + DRIVER_OBJECT* drv | |
311 | + ); | |
312 | + | |
313 | +#endif // _NETVSC_API_H_ | |
314 | --- /dev/null | |
315 | +++ b/drivers/staging/hv/include/osd.h | |
316 | @@ -0,0 +1,263 @@ | |
317 | +/* | |
318 | + * | |
319 | + * Copyright (c) 2009, Microsoft Corporation. | |
320 | + * | |
321 | + * This program is free software; you can redistribute it and/or modify it | |
322 | + * under the terms and conditions of the GNU General Public License, | |
323 | + * version 2, as published by the Free Software Foundation. | |
324 | + * | |
325 | + * This program is distributed in the hope it will be useful, but WITHOUT | |
326 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
327 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
328 | + * more details. | |
329 | + * | |
330 | + * You should have received a copy of the GNU General Public License along with | |
331 | + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple | |
332 | + * Place - Suite 330, Boston, MA 02111-1307 USA. | |
333 | + * | |
334 | + * Authors: | |
335 | + * Haiyang Zhang <haiyangz@microsoft.com> | |
336 | + * Hank Janssen <hjanssen@microsoft.com> | |
337 | + * | |
338 | + */ | |
339 | + | |
340 | + | |
341 | +#ifndef _OSD_H_ | |
342 | +#define _OSD_H_ | |
343 | + | |
344 | +// | |
345 | +// Defines | |
346 | +// | |
347 | + | |
348 | +#ifndef PAGE_SIZE | |
349 | +#define PAGE_SIZE 0x1000 | |
350 | +#endif | |
351 | + | |
352 | +#ifndef PAGE_SHIFT | |
353 | +#define PAGE_SHIFT 12 | |
354 | +#endif | |
355 | + | |
356 | +#ifndef memcpy | |
357 | +#define memcpy __builtin_memcpy | |
358 | +#endif | |
359 | + | |
360 | +#ifndef memset | |
361 | +#define memset __builtin_memset | |
362 | +#endif | |
363 | + | |
364 | +#ifndef memcmp | |
365 | +#define memcmp __builtin_memcmp | |
366 | +#endif | |
367 | + | |
368 | +#ifndef strcpy | |
369 | +#define strcpy __builtin_strcpy | |
370 | +#endif | |
371 | + | |
372 | +// | |
373 | +//#ifndef sprintf | |
374 | +//#define sprintf __builtin_sprintf | |
375 | +//#endif | |
376 | + | |
377 | +#define STRUCT_PACKED __attribute__((__packed__)) | |
378 | +#define STRUCT_ALIGNED(x) __attribute__((__aligned__(x))) | |
379 | + | |
380 | +#define UNUSED_VAR(v) v __attribute__((__unused__)) | |
381 | + | |
382 | +#define ALIGN_UP(value, align) ( ((value) & (align-1))? ( ((value) + (align-1)) & ~(align-1) ): (value) ) | |
383 | +#define ALIGN_DOWN(value, align) ( (value) & ~(align-1) ) | |
384 | +#define NUM_PAGES_SPANNED(addr, len) ( (ALIGN_UP(addr+len, PAGE_SIZE) - ALIGN_DOWN(addr, PAGE_SIZE)) >> PAGE_SHIFT ) | |
385 | + | |
386 | +#define MIN(a, b) ((a) < (b)? (a): (b)) | |
387 | +#define MAX(a, b) ((a) > (b)? (a): (b)) | |
388 | + | |
389 | +#define LOWORD(dw) ((unsigned short) (dw)) | |
390 | +#define HIWORD(dw) ((unsigned short) (((unsigned int) (dw) >> 16) & 0xFFFF)) | |
391 | + | |
392 | +#define FIELD_OFFSET(t, f) ((unsigned int)(unsigned long)&(((t *)0)->f)) | |
393 | + | |
394 | +#ifdef FALSE | |
395 | +#undef FALSE | |
396 | +#endif | |
397 | +#define FALSE 0 | |
398 | + | |
399 | +#ifdef TRUE | |
400 | +#undef TRUE | |
401 | +#endif | |
402 | +#define TRUE 1 | |
403 | + | |
404 | +#ifndef NULL | |
405 | +#define NULL (void *)0 | |
406 | +#endif | |
407 | + | |
408 | +typedef struct _DLIST_ENTRY { | |
409 | + struct _DLIST_ENTRY *Flink; | |
410 | + struct _DLIST_ENTRY *Blink; | |
411 | +} DLIST_ENTRY; | |
412 | + | |
413 | +// | |
414 | +// unsigned types | |
415 | +// | |
416 | +typedef unsigned char UINT8; | |
417 | +typedef unsigned short UINT16; | |
418 | +typedef unsigned int UINT32; | |
419 | +#ifdef __x86_64__ | |
420 | +typedef unsigned long UINT64; | |
421 | +#else | |
422 | +typedef unsigned long long UINT64; | |
423 | +#endif | |
424 | + | |
425 | +typedef unsigned long long ULONGLONG; | |
426 | +typedef unsigned int ULONG; | |
427 | +typedef unsigned short USHORT; | |
428 | +typedef unsigned char UCHAR; | |
429 | + | |
430 | +// | |
431 | +// signed types | |
432 | +// | |
433 | +typedef char INT8; | |
434 | +typedef short INT16; | |
435 | +typedef int INT32; | |
436 | +#ifdef __x86_64__ | |
437 | +typedef long INT64; | |
438 | +#else | |
439 | +typedef long long INT64; | |
440 | +#endif | |
441 | + | |
442 | +typedef int LONG; | |
443 | +typedef char CHAR; | |
444 | +typedef long long LONGLONG; | |
445 | + | |
446 | +// | |
447 | +// Other types | |
448 | +// | |
449 | +typedef unsigned long SIZE_T; | |
450 | +typedef void VOID; | |
451 | +//typedef unsigned char GUID[16]; | |
452 | +typedef void* PVOID; | |
453 | +typedef unsigned char BOOL; | |
454 | +typedef unsigned char BOOLEAN; | |
455 | +typedef void* HANDLE; | |
456 | +typedef UINT32 DWORD; | |
457 | +typedef char* PCHAR; | |
458 | +typedef unsigned char BYTE; | |
459 | + | |
460 | +typedef unsigned long ULONG_PTR; | |
461 | + | |
462 | +typedef struct { | |
463 | + unsigned char Data[16]; | |
464 | +} GUID; | |
465 | + | |
466 | +typedef void (*PFN_WORKITEM_CALLBACK)(void* context); | |
467 | +typedef void (*PFN_TIMER_CALLBACK)(void* context); | |
468 | + | |
469 | + | |
470 | +#ifdef __x86_64__ | |
471 | + | |
472 | +#define RDMSR(reg, v) { \ | |
473 | + UINT32 h, l; \ | |
474 | + __asm__ __volatile__("rdmsr" \ | |
475 | + : "=a" (l), "=d" (h) \ | |
476 | + : "c" (reg)); \ | |
477 | + v = (((UINT64)h) << 32) | l; \ | |
478 | +} | |
479 | + | |
480 | +#define WRMSR(reg, v) { \ | |
481 | + UINT32 h, l; \ | |
482 | + l = (UINT32)(((UINT64)(v)) & 0xFFFFFFFF); \ | |
483 | + h = (UINT32)((((UINT64)(v)) >> 32) & 0xFFFFFFFF); \ | |
484 | + __asm__ __volatile__("wrmsr" \ | |
485 | + : /* no outputs */ \ | |
486 | + : "c" (reg), "a" (l), "d" (h)); \ | |
487 | +} | |
488 | + | |
489 | +#else | |
490 | + | |
491 | +#define RDMSR(reg, v) \ | |
492 | + __asm__ __volatile__("rdmsr" \ | |
493 | + : "=A" (v) \ | |
494 | + : "c" (reg)) | |
495 | + | |
496 | +#define WRMSR(reg, v) \ | |
497 | + __asm__ __volatile__("wrmsr" \ | |
498 | + : /* no outputs */ \ | |
499 | + : "c" (reg), "A" ((UINT64)v)) | |
500 | + | |
501 | +#endif | |
502 | + | |
503 | + | |
504 | +static inline void do_cpuid(unsigned int op, unsigned int *eax, unsigned int *ebx, unsigned int *ecx, unsigned int *edx) | |
505 | +{ | |
506 | + __asm__ __volatile__("cpuid" : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx) : "0" (op), "c" (ecx)); | |
507 | +} | |
508 | + | |
509 | +// | |
510 | +// Osd routines | |
511 | +// | |
512 | +extern void LogMsg(const char *fmt, ...); | |
513 | + | |
514 | +extern void BitSet(unsigned int* addr, int value); | |
515 | +extern void BitClear(unsigned int* addr, int value); | |
516 | +extern int BitTest(unsigned int* addr, int value); | |
517 | +extern int BitTestAndClear(unsigned int* addr, int value); | |
518 | +extern int BitTestAndSet(unsigned int* addr, int value); | |
519 | + | |
520 | +extern int InterlockedIncrement(int *val); | |
521 | +extern int InterlockedDecrement(int *val); | |
522 | +extern int InterlockedCompareExchange(int *val, int new, int curr); | |
523 | + | |
524 | +extern void Sleep(unsigned long usecs); | |
525 | + | |
526 | +extern void* VirtualAllocExec(unsigned int size); | |
527 | +extern void VirtualFree(void* VirtAddr); | |
528 | + | |
529 | +extern void* PageAlloc(unsigned int count); | |
530 | +extern void PageFree(void* page, unsigned int count); | |
531 | + | |
532 | +extern void* MemMapIO(unsigned long phys, unsigned long size); | |
533 | +extern void MemUnmapIO(void* virt); | |
534 | + | |
535 | +extern void* MemAlloc(unsigned int size); | |
536 | +extern void* MemAllocZeroed(unsigned int size); | |
537 | +extern void* MemAllocAtomic(unsigned int size); | |
538 | +extern void MemFree(void* buf); | |
539 | +extern void MemoryFence(VOID); | |
540 | + | |
541 | +extern HANDLE TimerCreate(PFN_TIMER_CALLBACK pfnTimerCB, void* context); | |
542 | +extern void TimerClose(HANDLE hTimer); | |
543 | +extern int TimerStop(HANDLE hTimer); | |
544 | +extern void TimerStart(HANDLE hTimer, UINT32 expirationInUs); | |
545 | +extern SIZE_T GetTickCount(void); | |
546 | + | |
547 | +extern HANDLE WaitEventCreate(void); | |
548 | +extern void WaitEventClose(HANDLE hWait); | |
549 | +extern void WaitEventSet(HANDLE hWait); | |
550 | +extern int WaitEventWait(HANDLE hWait); | |
551 | + | |
552 | +// If >0, hWait got signaled. If ==0, timeout. If < 0, error | |
553 | +extern int WaitEventWaitEx(HANDLE hWait, UINT32 TimeoutInMs); | |
554 | + | |
555 | +extern HANDLE SpinlockCreate(void); | |
556 | +extern void SpinlockClose(HANDLE hSpin); | |
557 | +extern void SpinlockAcquire(HANDLE hSpin); | |
558 | +extern void SpinlockRelease(HANDLE hSpin); | |
559 | + | |
560 | + | |
561 | +#define GetVirtualAddress Physical2LogicalAddr | |
562 | +void* Physical2LogicalAddr(ULONG_PTR PhysAddr); | |
563 | + | |
564 | +#define GetPhysicalAddress Logical2PhysicalAddr | |
565 | +ULONG_PTR Logical2PhysicalAddr(PVOID LogicalAddr); | |
566 | + | |
567 | +ULONG_PTR Virtual2Physical(PVOID VirtAddr); | |
568 | + | |
569 | +void* PageMapVirtualAddress(unsigned long Pfn); | |
570 | +void PageUnmapVirtualAddress(void* VirtAddr); | |
571 | + | |
572 | + | |
573 | +extern HANDLE WorkQueueCreate(char* name); | |
574 | +extern void WorkQueueClose(HANDLE hWorkQueue); | |
575 | +extern int WorkQueueQueueWorkItem(HANDLE hWorkQueue, PFN_WORKITEM_CALLBACK workItem, void* context); | |
576 | + | |
577 | +extern void QueueWorkItem(PFN_WORKITEM_CALLBACK workItem, void* context); | |
578 | + | |
579 | +#endif // _OSD_H_ | |
580 | --- /dev/null | |
581 | +++ b/drivers/staging/hv/include/StorVscApi.h | |
582 | @@ -0,0 +1,137 @@ | |
583 | +/* | |
584 | + * | |
585 | + * Copyright (c) 2009, Microsoft Corporation. | |
586 | + * | |
587 | + * This program is free software; you can redistribute it and/or modify it | |
588 | + * under the terms and conditions of the GNU General Public License, | |
589 | + * version 2, as published by the Free Software Foundation. | |
590 | + * | |
591 | + * This program is distributed in the hope it will be useful, but WITHOUT | |
592 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
593 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
594 | + * more details. | |
595 | + * | |
596 | + * You should have received a copy of the GNU General Public License along with | |
597 | + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple | |
598 | + * Place - Suite 330, Boston, MA 02111-1307 USA. | |
599 | + * | |
600 | + * Authors: | |
601 | + * Haiyang Zhang <haiyangz@microsoft.com> | |
602 | + * Hank Janssen <hjanssen@microsoft.com> | |
603 | + * | |
604 | + */ | |
605 | + | |
606 | + | |
607 | +#ifndef _STORVSC_API_H_ | |
608 | +#define _STORVSC_API_H_ | |
609 | + | |
610 | +#include "VmbusApi.h" | |
611 | + | |
612 | +// | |
613 | +// Defines | |
614 | +// | |
615 | + | |
616 | +#define STORVSC_RING_BUFFER_SIZE 10*PAGE_SIZE | |
617 | +#define BLKVSC_RING_BUFFER_SIZE 20*PAGE_SIZE | |
618 | + | |
619 | +#define STORVSC_MAX_IO_REQUESTS 64 | |
620 | + | |
621 | +// In Hyper-V, each port/path/target maps to 1 scsi host adapter. | |
622 | +// In reality, the path/target is not used (ie always set to 0) so | |
623 | +// our scsi host adapter essentially has 1 bus with 1 target that contains | |
624 | +// up to 256 luns. | |
625 | + | |
626 | +#define STORVSC_MAX_LUNS_PER_TARGET 64 | |
627 | +#define STORVSC_MAX_TARGETS 1 | |
628 | +#define STORVSC_MAX_CHANNELS 1 | |
629 | + | |
630 | + | |
631 | +// Fwd decl | |
632 | +// | |
633 | +//struct VMBUS_CHANNEL; | |
634 | +typedef struct _STORVSC_REQUEST* PSTORVSC_REQUEST; | |
635 | + | |
636 | +// | |
637 | +// Data types | |
638 | +// | |
639 | +typedef int (*PFN_ON_IO_REQUEST)(PDEVICE_OBJECT Device, PSTORVSC_REQUEST Request); | |
640 | +typedef void (*PFN_ON_IO_REQUEST_COMPLTN)(PSTORVSC_REQUEST Request); | |
641 | + | |
642 | +typedef int (*PFN_ON_HOST_RESET)(PDEVICE_OBJECT Device); | |
643 | +typedef void (*PFN_ON_HOST_RESCAN)(PDEVICE_OBJECT Device); | |
644 | + | |
645 | + | |
646 | +// Matches Windows-end | |
647 | +typedef enum _STORVSC_REQUEST_TYPE{ | |
648 | + WRITE_TYPE, | |
649 | + READ_TYPE, | |
650 | + UNKNOWN_TYPE, | |
651 | +} STORVSC_REQUEST_TYPE; | |
652 | + | |
653 | + | |
654 | +typedef struct _STORVSC_REQUEST { | |
655 | + STORVSC_REQUEST_TYPE Type; | |
656 | + UINT32 Host; | |
657 | + UINT32 Bus; | |
658 | + UINT32 TargetId; | |
659 | + UINT32 LunId; | |
660 | + UINT8* Cdb; | |
661 | + UINT32 CdbLen; | |
662 | + UINT32 Status; | |
663 | + UINT32 BytesXfer; | |
664 | + | |
665 | + UCHAR* SenseBuffer; | |
666 | + UINT32 SenseBufferSize; | |
667 | + | |
668 | + PVOID Context; | |
669 | + | |
670 | + PFN_ON_IO_REQUEST_COMPLTN OnIOCompletion; | |
671 | + | |
672 | + // This points to the memory after DataBuffer | |
673 | + PVOID Extension; | |
674 | + | |
675 | + MULTIPAGE_BUFFER DataBuffer; | |
676 | +} STORVSC_REQUEST; | |
677 | + | |
678 | + | |
679 | +// Represents the block vsc driver | |
680 | +typedef struct _STORVSC_DRIVER_OBJECT { | |
681 | + DRIVER_OBJECT Base; // Must be the first field | |
682 | + | |
683 | + // Set by caller (in bytes) | |
684 | + UINT32 RingBufferSize; | |
685 | + | |
686 | + // Allocate this much private extension for each I/O request | |
687 | + UINT32 RequestExtSize; | |
688 | + | |
689 | + // Maximum # of requests in flight per channel/device | |
690 | + UINT32 MaxOutstandingRequestsPerChannel; | |
691 | + | |
692 | + // Set by the caller to allow us to re-enumerate the bus on the host | |
693 | + PFN_ON_HOST_RESCAN OnHostRescan; | |
694 | + | |
695 | + // Specific to this driver | |
696 | + PFN_ON_IO_REQUEST OnIORequest; | |
697 | + PFN_ON_HOST_RESET OnHostReset; | |
698 | + | |
699 | +} STORVSC_DRIVER_OBJECT; | |
700 | + | |
701 | +typedef struct _STORVSC_DEVICE_INFO { | |
702 | + ULONG PortNumber; | |
703 | + UCHAR PathId; | |
704 | + UCHAR TargetId; | |
705 | +} STORVSC_DEVICE_INFO; | |
706 | + | |
707 | +// | |
708 | +// Interface | |
709 | +// | |
710 | +int | |
711 | +StorVscInitialize( | |
712 | + DRIVER_OBJECT *Driver | |
713 | + ); | |
714 | + | |
715 | +int | |
716 | +BlkVscInitialize( | |
717 | + DRIVER_OBJECT *Driver | |
718 | + ); | |
719 | +#endif // _STORVSC_API_H_ | |
720 | --- /dev/null | |
721 | +++ b/drivers/staging/hv/include/VmbusApi.h | |
722 | @@ -0,0 +1,262 @@ | |
723 | +/* | |
724 | + * | |
725 | + * Copyright (c) 2009, Microsoft Corporation. | |
726 | + * | |
727 | + * This program is free software; you can redistribute it and/or modify it | |
728 | + * under the terms and conditions of the GNU General Public License, | |
729 | + * version 2, as published by the Free Software Foundation. | |
730 | + * | |
731 | + * This program is distributed in the hope it will be useful, but WITHOUT | |
732 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
733 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
734 | + * more details. | |
735 | + * | |
736 | + * You should have received a copy of the GNU General Public License along with | |
737 | + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple | |
738 | + * Place - Suite 330, Boston, MA 02111-1307 USA. | |
739 | + * | |
740 | + * Authors: | |
741 | + * Haiyang Zhang <haiyangz@microsoft.com> | |
742 | + * Hank Janssen <hjanssen@microsoft.com> | |
743 | + * | |
744 | + */ | |
745 | + | |
746 | + | |
747 | +#ifndef _VMBUS_API_H_ | |
748 | +#define _VMBUS_API_H_ | |
749 | + | |
750 | +#include "osd.h" | |
751 | + | |
752 | +// | |
753 | +// Defines | |
754 | +// | |
755 | + | |
756 | +#define MAX_PAGE_BUFFER_COUNT 16 | |
757 | +#define MAX_MULTIPAGE_BUFFER_COUNT 32 // 128K | |
758 | + | |
759 | + | |
760 | +// | |
761 | +// Fwd declarations | |
762 | +// | |
763 | +typedef struct _DRIVER_OBJECT *PDRIVER_OBJECT; | |
764 | +typedef struct _DEVICE_OBJECT *PDEVICE_OBJECT; | |
765 | + | |
766 | +// | |
767 | +// Data types | |
768 | +// | |
769 | + | |
770 | +#pragma pack(push,1) | |
771 | + | |
772 | +// Single-page buffer | |
773 | +typedef struct _PAGE_BUFFER { | |
774 | + UINT32 Length; | |
775 | + UINT32 Offset; | |
776 | + UINT64 Pfn; | |
777 | +} PAGE_BUFFER; | |
778 | + | |
779 | +// Multiple-page buffer | |
780 | +typedef struct _MULTIPAGE_BUFFER { | |
781 | + // Length and Offset determines the # of pfns in the array | |
782 | + UINT32 Length; | |
783 | + UINT32 Offset; | |
784 | + UINT64 PfnArray[MAX_MULTIPAGE_BUFFER_COUNT]; | |
785 | +}MULTIPAGE_BUFFER; | |
786 | + | |
787 | +//0x18 includes the proprietary packet header | |
788 | +#define MAX_PAGE_BUFFER_PACKET (0x18 + (sizeof(PAGE_BUFFER) * MAX_PAGE_BUFFER_COUNT)) | |
789 | +#define MAX_MULTIPAGE_BUFFER_PACKET (0x18 + sizeof(MULTIPAGE_BUFFER)) | |
790 | + | |
791 | + | |
792 | +#pragma pack(pop) | |
793 | + | |
794 | +// All drivers | |
795 | +typedef int (*PFN_ON_DEVICEADD)(PDEVICE_OBJECT Device, void* AdditionalInfo); | |
796 | +typedef int (*PFN_ON_DEVICEREMOVE)(PDEVICE_OBJECT Device); | |
797 | +typedef char** (*PFN_ON_GETDEVICEIDS)(void); | |
798 | +typedef void (*PFN_ON_CLEANUP)(PDRIVER_OBJECT Driver); | |
799 | + | |
800 | +// Vmbus extensions | |
801 | +//typedef int (*PFN_ON_MATCH)(PDEVICE_OBJECT dev, PDRIVER_OBJECT drv); | |
802 | +//typedef int (*PFN_ON_PROBE)(PDEVICE_OBJECT dev); | |
803 | +typedef int (*PFN_ON_ISR)(PDRIVER_OBJECT drv); | |
804 | +typedef void (*PFN_ON_DPC)(PDRIVER_OBJECT drv); | |
805 | +typedef void (*PFN_GET_CHANNEL_OFFERS)(void); | |
806 | + | |
807 | +typedef PDEVICE_OBJECT (*PFN_ON_CHILDDEVICE_CREATE)(GUID DeviceType, GUID DeviceInstance, void *Context); | |
808 | +typedef void (*PFN_ON_CHILDDEVICE_DESTROY)(PDEVICE_OBJECT Device); | |
809 | +typedef int (*PFN_ON_CHILDDEVICE_ADD)(PDEVICE_OBJECT RootDevice, PDEVICE_OBJECT ChildDevice); | |
810 | +typedef void (*PFN_ON_CHILDDEVICE_REMOVE)(PDEVICE_OBJECT Device); | |
811 | + | |
812 | +// Vmbus channel interface | |
813 | +typedef void (*VMBUS_CHANNEL_CALLBACK)(PVOID context); | |
814 | + | |
815 | +typedef int (*VMBUS_CHANNEL_OPEN)( | |
816 | + PDEVICE_OBJECT Device, | |
817 | + UINT32 SendBufferSize, | |
818 | + UINT32 RecvRingBufferSize, | |
819 | + PVOID UserData, | |
820 | + UINT32 UserDataLen, | |
821 | + VMBUS_CHANNEL_CALLBACK ChannelCallback, | |
822 | + PVOID Context | |
823 | + ); | |
824 | + | |
825 | +typedef void (*VMBUS_CHANNEL_CLOSE)( | |
826 | + PDEVICE_OBJECT Device | |
827 | + ); | |
828 | + | |
829 | +typedef int (*VMBUS_CHANNEL_SEND_PACKET)( | |
830 | + PDEVICE_OBJECT Device, | |
831 | + const PVOID Buffer, | |
832 | + UINT32 BufferLen, | |
833 | + UINT64 RequestId, | |
834 | + UINT32 Type, | |
835 | + UINT32 Flags | |
836 | +); | |
837 | + | |
838 | +typedef int (*VMBUS_CHANNEL_SEND_PACKET_PAGEBUFFER)( | |
839 | + PDEVICE_OBJECT Device, | |
840 | + PAGE_BUFFER PageBuffers[], | |
841 | + UINT32 PageCount, | |
842 | + PVOID Buffer, | |
843 | + UINT32 BufferLen, | |
844 | + UINT64 RequestId | |
845 | + ); | |
846 | + | |
847 | +typedef int (*VMBUS_CHANNEL_SEND_PACKET_MULTIPAGEBUFFER)( | |
848 | + PDEVICE_OBJECT Device, | |
849 | + MULTIPAGE_BUFFER *MultiPageBuffer, | |
850 | + PVOID Buffer, | |
851 | + UINT32 BufferLen, | |
852 | + UINT64 RequestId | |
853 | +); | |
854 | + | |
855 | +typedef int (*VMBUS_CHANNEL_RECV_PACKET)( | |
856 | + PDEVICE_OBJECT Device, | |
857 | + PVOID Buffer, | |
858 | + UINT32 BufferLen, | |
859 | + UINT32* BufferActualLen, | |
860 | + UINT64* RequestId | |
861 | + ); | |
862 | + | |
863 | +typedef int (*VMBUS_CHANNEL_RECV_PACKET_PAW)( | |
864 | + PDEVICE_OBJECT Device, | |
865 | + PVOID Buffer, | |
866 | + UINT32 BufferLen, | |
867 | + UINT32* BufferActualLen, | |
868 | + UINT64* RequestId | |
869 | + ); | |
870 | + | |
871 | +typedef int (*VMBUS_CHANNEL_ESTABLISH_GPADL)( | |
872 | + PDEVICE_OBJECT Device, | |
873 | + PVOID Buffer, // from kmalloc() | |
874 | + UINT32 BufferLen, // page-size multiple | |
875 | + UINT32* GpadlHandle | |
876 | + ); | |
877 | + | |
878 | +typedef int (*VMBUS_CHANNEL_TEARDOWN_GPADL)( | |
879 | + PDEVICE_OBJECT Device, | |
880 | + UINT32 GpadlHandle | |
881 | + ); | |
882 | + | |
883 | + | |
884 | +typedef struct _PORT_INFO { | |
885 | + UINT32 InterruptMask; | |
886 | + UINT32 ReadIndex; | |
887 | + UINT32 WriteIndex; | |
888 | + UINT32 BytesAvailToRead; | |
889 | + UINT32 BytesAvailToWrite; | |
890 | +} PORT_INFO; | |
891 | + | |
892 | + | |
893 | +typedef struct _DEVICE_INFO { | |
894 | + UINT32 ChannelId; | |
895 | + UINT32 ChannelState; | |
896 | + GUID ChannelType; | |
897 | + GUID ChannelInstance; | |
898 | + | |
899 | + UINT32 MonitorId; | |
900 | + UINT32 ServerMonitorPending; | |
901 | + UINT32 ServerMonitorLatency; | |
902 | + UINT32 ServerMonitorConnectionId; | |
903 | + UINT32 ClientMonitorPending; | |
904 | + UINT32 ClientMonitorLatency; | |
905 | + UINT32 ClientMonitorConnectionId; | |
906 | + | |
907 | + PORT_INFO Inbound; | |
908 | + PORT_INFO Outbound; | |
909 | +} DEVICE_INFO; | |
910 | + | |
911 | +typedef void (*VMBUS_GET_CHANNEL_INFO)(PDEVICE_OBJECT Device, DEVICE_INFO* DeviceInfo); | |
912 | + | |
913 | +typedef struct _VMBUS_CHANNEL_INTERFACE { | |
914 | + VMBUS_CHANNEL_OPEN Open; | |
915 | + VMBUS_CHANNEL_CLOSE Close; | |
916 | + VMBUS_CHANNEL_SEND_PACKET SendPacket; | |
917 | + VMBUS_CHANNEL_SEND_PACKET_PAGEBUFFER SendPacketPageBuffer; | |
918 | + VMBUS_CHANNEL_SEND_PACKET_MULTIPAGEBUFFER SendPacketMultiPageBuffer; | |
919 | + VMBUS_CHANNEL_RECV_PACKET RecvPacket; | |
920 | + VMBUS_CHANNEL_RECV_PACKET_PAW RecvPacketRaw; | |
921 | + VMBUS_CHANNEL_ESTABLISH_GPADL EstablishGpadl; | |
922 | + VMBUS_CHANNEL_TEARDOWN_GPADL TeardownGpadl; | |
923 | + VMBUS_GET_CHANNEL_INFO GetInfo; | |
924 | +} VMBUS_CHANNEL_INTERFACE; | |
925 | + | |
926 | +typedef void (*VMBUS_GET_CHANNEL_INTERFACE)(VMBUS_CHANNEL_INTERFACE *Interface); | |
927 | + | |
928 | +// Base driver object | |
929 | +typedef struct _DRIVER_OBJECT { | |
930 | + const char* name; | |
931 | + GUID deviceType; // the device type supported by this driver | |
932 | + | |
933 | + PFN_ON_DEVICEADD OnDeviceAdd; | |
934 | + PFN_ON_DEVICEREMOVE OnDeviceRemove; | |
935 | + PFN_ON_GETDEVICEIDS OnGetDeviceIds; // device ids supported by this driver | |
936 | + PFN_ON_CLEANUP OnCleanup; | |
937 | + | |
938 | + VMBUS_CHANNEL_INTERFACE VmbusChannelInterface; | |
939 | +} DRIVER_OBJECT; | |
940 | + | |
941 | + | |
942 | +// Base device object | |
943 | +typedef struct _DEVICE_OBJECT { | |
944 | + DRIVER_OBJECT* Driver; // the driver for this device | |
945 | + char name[64]; | |
946 | + GUID deviceType; // the device type id of this device | |
947 | + GUID deviceInstance; // the device instance id of this device | |
948 | + void* context; | |
949 | + void* Extension; // Device extension; | |
950 | +} DEVICE_OBJECT; | |
951 | + | |
952 | + | |
953 | +// Vmbus driver object | |
954 | +typedef struct _VMBUS_DRIVER_OBJECT { | |
955 | + DRIVER_OBJECT Base; // !! Must be the 1st field !! | |
956 | + | |
957 | + // Set by the caller | |
958 | + PFN_ON_CHILDDEVICE_CREATE OnChildDeviceCreate; | |
959 | + PFN_ON_CHILDDEVICE_DESTROY OnChildDeviceDestroy; | |
960 | + PFN_ON_CHILDDEVICE_ADD OnChildDeviceAdd; | |
961 | + PFN_ON_CHILDDEVICE_REMOVE OnChildDeviceRemove; | |
962 | + | |
963 | + // Set by the callee | |
964 | + //PFN_ON_MATCH OnMatch; | |
965 | + //PFN_ON_PROBE OnProbe; | |
966 | + PFN_ON_ISR OnIsr; | |
967 | + PFN_ON_DPC OnMsgDpc; | |
968 | + PFN_ON_DPC OnEventDpc; | |
969 | + PFN_GET_CHANNEL_OFFERS GetChannelOffers; | |
970 | + | |
971 | + VMBUS_GET_CHANNEL_INTERFACE GetChannelInterface; | |
972 | + VMBUS_GET_CHANNEL_INFO GetChannelInfo; | |
973 | +} VMBUS_DRIVER_OBJECT; | |
974 | + | |
975 | + | |
976 | +// | |
977 | +// Interface | |
978 | +// | |
979 | +int | |
980 | +VmbusInitialize( | |
981 | + DRIVER_OBJECT* drv | |
982 | + ); | |
983 | + | |
984 | +#endif // _VMBUS_API_H_ | |
985 | --- /dev/null | |
986 | +++ b/drivers/staging/hv/include/vmbus.h | |
987 | @@ -0,0 +1,111 @@ | |
988 | +/* | |
989 | + * | |
990 | + * Copyright (c) 2009, Microsoft Corporation. | |
991 | + * | |
992 | + * This program is free software; you can redistribute it and/or modify it | |
993 | + * under the terms and conditions of the GNU General Public License, | |
994 | + * version 2, as published by the Free Software Foundation. | |
995 | + * | |
996 | + * This program is distributed in the hope it will be useful, but WITHOUT | |
997 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
998 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
999 | + * more details. | |
1000 | + * | |
1001 | + * You should have received a copy of the GNU General Public License along with | |
1002 | + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple | |
1003 | + * Place - Suite 330, Boston, MA 02111-1307 USA. | |
1004 | + * | |
1005 | + * Authors: | |
1006 | + * Haiyang Zhang <haiyangz@microsoft.com> | |
1007 | + * Hank Janssen <hjanssen@microsoft.com> | |
1008 | + * | |
1009 | + */ | |
1010 | + | |
1011 | + | |
1012 | +#ifndef _VMBUS_H_ | |
1013 | +#define _VMBUS_H_ | |
1014 | + | |
1015 | +#include <linux/device.h> | |
1016 | + | |
1017 | +#include "VmbusApi.h" | |
1018 | + | |
1019 | +// | |
1020 | +// Data types | |
1021 | +// | |
1022 | + | |
1023 | +typedef int (*PFN_DRIVERINITIALIZE)(DRIVER_OBJECT *drv); | |
1024 | +typedef int (*PFN_DRIVEREXIT)(DRIVER_OBJECT *drv); | |
1025 | + | |
1026 | +struct driver_context { | |
1027 | + GUID class_id; | |
1028 | + | |
1029 | + struct device_driver driver; | |
1030 | + | |
1031 | + // Use these methods instead of the struct device_driver so 2.6 kernel stops complaining | |
1032 | + int (*probe)(struct device *); | |
1033 | + int (*remove)(struct device *); | |
1034 | + void (*shutdown)(struct device *); | |
1035 | +}; | |
1036 | + | |
1037 | +struct device_context { | |
1038 | + struct work_struct probe_failed_work_item; | |
1039 | + GUID class_id; | |
1040 | + GUID device_id; | |
1041 | + int probe_error; | |
1042 | + struct device device; | |
1043 | + DEVICE_OBJECT device_obj; | |
1044 | +}; | |
1045 | + | |
1046 | + | |
1047 | +// | |
1048 | +// Global | |
1049 | +// | |
1050 | + | |
1051 | +// | |
1052 | +// Inlines | |
1053 | +// | |
1054 | +static inline struct device_context *to_device_context(DEVICE_OBJECT *device_obj) | |
1055 | +{ | |
1056 | + return container_of(device_obj, struct device_context, device_obj); | |
1057 | +} | |
1058 | + | |
1059 | +static inline struct device_context *device_to_device_context(struct device *device) | |
1060 | +{ | |
1061 | + return container_of(device, struct device_context, device); | |
1062 | +} | |
1063 | + | |
1064 | +static inline struct driver_context *driver_to_driver_context(struct device_driver *driver) | |
1065 | +{ | |
1066 | + return container_of(driver, struct driver_context, driver); | |
1067 | +} | |
1068 | + | |
1069 | +#if defined(KERNEL_2_6_5) | |
1070 | +static inline void* kzalloc(int size, int flags) | |
1071 | +{ | |
1072 | + void *p; | |
1073 | + p = kmalloc(size, flags); | |
1074 | + if (p) memset(p, 0, size); | |
1075 | + | |
1076 | + return p; | |
1077 | +} | |
1078 | +#endif // KERNEL_2_6_5 | |
1079 | + | |
1080 | +// | |
1081 | +// Vmbus interface | |
1082 | +// | |
1083 | +void | |
1084 | +vmbus_child_driver_register( | |
1085 | + struct driver_context* driver_ctx | |
1086 | + ); | |
1087 | + | |
1088 | +void | |
1089 | +vmbus_child_driver_unregister( | |
1090 | + struct driver_context *driver_ctx | |
1091 | + ); | |
1092 | + | |
1093 | +void | |
1094 | +vmbus_get_interface( | |
1095 | + VMBUS_CHANNEL_INTERFACE *interface | |
1096 | + ); | |
1097 | + | |
1098 | +#endif // _VMBUS_H_ |