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
6 From: Hank Janssen <hjanssen@microsoft.com>
8 These are the header files for the different Linux Hyper-V drivers to
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>
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
30 +++ b/drivers/staging/hv/include/logging.h
34 + * Copyright (c) 2009, Microsoft Corporation.
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.
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
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.
50 + * Haiyang Zhang <haiyangz@microsoft.com>
51 + * Hank Janssen <hjanssen@microsoft.com>
59 +//#include <linux/init.h>
60 +//#include <linux/module.h>
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
75 +#define ALL_MODULES (VMBUS |\
87 +#define CRITICAL_LVL 2
89 +#define WARNING_LVL 4
92 +#define DEBUG_LVL_ENTEREXIT 8
93 +#define DEBUG_RING_LVL 9
95 +extern unsigned int vmbus_loglevel;
97 +#define ASSERT(expr) \
99 + LogMsg("<%d>Assertion failed! %s,%s,%s,line=%d\n", CRITICAL_LVL, #expr,__FILE__,__FUNCTION__,__LINE__); \
100 + __asm__ __volatile__("int3"); \
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);\
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);\
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);\
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);\
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);\
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);\
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);\
139 +#define DPRINT_ENTER(mod)
140 +#define DPRINT_EXIT(mod)
143 +static inline void PrintBytes(const unsigned char* bytes, int len)
148 + for (i=0; i< len; i++)
150 + LogMsg("0x%x ", bytes[i]);
158 +//static inline void GuidToStr(const GUID g, char *str)
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]);
165 +#endif //_LOGGING_H_
167 +++ b/drivers/staging/hv/include/NetVscApi.h
171 + * Copyright (c) 2009, Microsoft Corporation.
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.
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
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.
187 + * Haiyang Zhang <haiyangz@microsoft.com>
188 + * Hank Janssen <hjanssen@microsoft.com>
193 +#ifndef _NETVSC_API_H_
194 +#define _NETVSC_API_H_
196 +#include "VmbusApi.h"
201 +#define NETVSC_DEVICE_RING_BUFFER_SIZE 64*PAGE_SIZE
203 +#define HW_MACADDR_LEN 6
208 +typedef struct _NETVSC_PACKET *PNETVSC_PACKET;
215 +typedef int (*PFN_ON_OPEN)(DEVICE_OBJECT *Device);
216 +typedef int (*PFN_ON_CLOSE)(DEVICE_OBJECT *Device);
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);
222 +typedef int (*PFN_ON_RECVCALLBACK)(DEVICE_OBJECT *dev, PNETVSC_PACKET packet);
223 +typedef void (*PFN_ON_LINKSTATUS_CHANGED)(DEVICE_OBJECT *dev, UINT32 Status);
225 +// Represent the xfer page packet which contains 1 or more netvsc packet
226 +typedef struct _XFERPAGE_PACKET {
227 + DLIST_ENTRY ListEntry;
229 + // # of netvsc packets this xfer packet contains
234 +// The number of pages which are enough to cover jumbo frame buffer.
235 +#define NETVSC_PACKET_MAXPAGE 4
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;
242 + DEVICE_OBJECT *Device;
245 + // Valid only for receives when we break a xfer page packet into multiple netvsc packets
246 + XFERPAGE_PACKET *XferPagePacket;
250 + UINT64 ReceiveCompletionTid;
251 + PVOID ReceiveCompletionContext;
252 + PFN_ON_SENDRECVCOMPLETION OnReceiveCompletion;
255 + UINT64 SendCompletionTid;
256 + PVOID SendCompletionContext;
257 + PFN_ON_SENDRECVCOMPLETION OnSendCompletion;
261 + // This points to the memory after PageBuffers
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];
272 +// Represents the net vsc driver
273 +typedef struct _NETVSC_DRIVER_OBJECT {
274 + DRIVER_OBJECT Base; // Must be the first field
276 + UINT32 RingBufferSize;
277 + UINT32 RequestExtSize;
279 + // Additional num of page buffers to allocate
280 + UINT32 AdditionalRequestPageBufferCount;
282 + // This is set by the caller to allow us to callback when we receive a packet
284 + PFN_ON_RECVCALLBACK OnReceiveCallback;
286 + PFN_ON_LINKSTATUS_CHANGED OnLinkStatusChanged;
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;
294 + //PFN_QUERY_LINKSTATUS QueryLinkStatus;
297 +} NETVSC_DRIVER_OBJECT;
300 +typedef struct _NETVSC_DEVICE_INFO {
302 + BOOL LinkState; // 0 - link up, 1 - link down
303 +} NETVSC_DEVICE_INFO;
313 +#endif // _NETVSC_API_H_
315 +++ b/drivers/staging/hv/include/osd.h
319 + * Copyright (c) 2009, Microsoft Corporation.
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.
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
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.
335 + * Haiyang Zhang <haiyangz@microsoft.com>
336 + * Hank Janssen <hjanssen@microsoft.com>
349 +#define PAGE_SIZE 0x1000
353 +#define PAGE_SHIFT 12
357 +#define memcpy __builtin_memcpy
361 +#define memset __builtin_memset
365 +#define memcmp __builtin_memcmp
369 +#define strcpy __builtin_strcpy
374 +//#define sprintf __builtin_sprintf
377 +#define STRUCT_PACKED __attribute__((__packed__))
378 +#define STRUCT_ALIGNED(x) __attribute__((__aligned__(x)))
380 +#define UNUSED_VAR(v) v __attribute__((__unused__))
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 )
386 +#define MIN(a, b) ((a) < (b)? (a): (b))
387 +#define MAX(a, b) ((a) > (b)? (a): (b))
389 +#define LOWORD(dw) ((unsigned short) (dw))
390 +#define HIWORD(dw) ((unsigned short) (((unsigned int) (dw) >> 16) & 0xFFFF))
392 +#define FIELD_OFFSET(t, f) ((unsigned int)(unsigned long)&(((t *)0)->f))
405 +#define NULL (void *)0
408 +typedef struct _DLIST_ENTRY {
409 + struct _DLIST_ENTRY *Flink;
410 + struct _DLIST_ENTRY *Blink;
416 +typedef unsigned char UINT8;
417 +typedef unsigned short UINT16;
418 +typedef unsigned int UINT32;
420 +typedef unsigned long UINT64;
422 +typedef unsigned long long UINT64;
425 +typedef unsigned long long ULONGLONG;
426 +typedef unsigned int ULONG;
427 +typedef unsigned short USHORT;
428 +typedef unsigned char UCHAR;
434 +typedef short INT16;
439 +typedef long long INT64;
444 +typedef long long LONGLONG;
449 +typedef unsigned long SIZE_T;
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;
460 +typedef unsigned long ULONG_PTR;
463 + unsigned char Data[16];
466 +typedef void (*PFN_WORKITEM_CALLBACK)(void* context);
467 +typedef void (*PFN_TIMER_CALLBACK)(void* context);
472 +#define RDMSR(reg, v) { \
474 + __asm__ __volatile__("rdmsr" \
475 + : "=a" (l), "=d" (h) \
477 + v = (((UINT64)h) << 32) | l; \
480 +#define WRMSR(reg, v) { \
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)); \
491 +#define RDMSR(reg, v) \
492 + __asm__ __volatile__("rdmsr" \
496 +#define WRMSR(reg, v) \
497 + __asm__ __volatile__("wrmsr" \
498 + : /* no outputs */ \
499 + : "c" (reg), "A" ((UINT64)v))
504 +static inline void do_cpuid(unsigned int op, unsigned int *eax, unsigned int *ebx, unsigned int *ecx, unsigned int *edx)
506 + __asm__ __volatile__("cpuid" : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx) : "0" (op), "c" (ecx));
512 +extern void LogMsg(const char *fmt, ...);
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);
520 +extern int InterlockedIncrement(int *val);
521 +extern int InterlockedDecrement(int *val);
522 +extern int InterlockedCompareExchange(int *val, int new, int curr);
524 +extern void Sleep(unsigned long usecs);
526 +extern void* VirtualAllocExec(unsigned int size);
527 +extern void VirtualFree(void* VirtAddr);
529 +extern void* PageAlloc(unsigned int count);
530 +extern void PageFree(void* page, unsigned int count);
532 +extern void* MemMapIO(unsigned long phys, unsigned long size);
533 +extern void MemUnmapIO(void* virt);
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);
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);
547 +extern HANDLE WaitEventCreate(void);
548 +extern void WaitEventClose(HANDLE hWait);
549 +extern void WaitEventSet(HANDLE hWait);
550 +extern int WaitEventWait(HANDLE hWait);
552 +// If >0, hWait got signaled. If ==0, timeout. If < 0, error
553 +extern int WaitEventWaitEx(HANDLE hWait, UINT32 TimeoutInMs);
555 +extern HANDLE SpinlockCreate(void);
556 +extern void SpinlockClose(HANDLE hSpin);
557 +extern void SpinlockAcquire(HANDLE hSpin);
558 +extern void SpinlockRelease(HANDLE hSpin);
561 +#define GetVirtualAddress Physical2LogicalAddr
562 +void* Physical2LogicalAddr(ULONG_PTR PhysAddr);
564 +#define GetPhysicalAddress Logical2PhysicalAddr
565 +ULONG_PTR Logical2PhysicalAddr(PVOID LogicalAddr);
567 +ULONG_PTR Virtual2Physical(PVOID VirtAddr);
569 +void* PageMapVirtualAddress(unsigned long Pfn);
570 +void PageUnmapVirtualAddress(void* VirtAddr);
573 +extern HANDLE WorkQueueCreate(char* name);
574 +extern void WorkQueueClose(HANDLE hWorkQueue);
575 +extern int WorkQueueQueueWorkItem(HANDLE hWorkQueue, PFN_WORKITEM_CALLBACK workItem, void* context);
577 +extern void QueueWorkItem(PFN_WORKITEM_CALLBACK workItem, void* context);
581 +++ b/drivers/staging/hv/include/StorVscApi.h
585 + * Copyright (c) 2009, Microsoft Corporation.
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.
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
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.
601 + * Haiyang Zhang <haiyangz@microsoft.com>
602 + * Hank Janssen <hjanssen@microsoft.com>
607 +#ifndef _STORVSC_API_H_
608 +#define _STORVSC_API_H_
610 +#include "VmbusApi.h"
616 +#define STORVSC_RING_BUFFER_SIZE 10*PAGE_SIZE
617 +#define BLKVSC_RING_BUFFER_SIZE 20*PAGE_SIZE
619 +#define STORVSC_MAX_IO_REQUESTS 64
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
626 +#define STORVSC_MAX_LUNS_PER_TARGET 64
627 +#define STORVSC_MAX_TARGETS 1
628 +#define STORVSC_MAX_CHANNELS 1
633 +//struct VMBUS_CHANNEL;
634 +typedef struct _STORVSC_REQUEST* PSTORVSC_REQUEST;
639 +typedef int (*PFN_ON_IO_REQUEST)(PDEVICE_OBJECT Device, PSTORVSC_REQUEST Request);
640 +typedef void (*PFN_ON_IO_REQUEST_COMPLTN)(PSTORVSC_REQUEST Request);
642 +typedef int (*PFN_ON_HOST_RESET)(PDEVICE_OBJECT Device);
643 +typedef void (*PFN_ON_HOST_RESCAN)(PDEVICE_OBJECT Device);
646 +// Matches Windows-end
647 +typedef enum _STORVSC_REQUEST_TYPE{
651 +} STORVSC_REQUEST_TYPE;
654 +typedef struct _STORVSC_REQUEST {
655 + STORVSC_REQUEST_TYPE Type;
665 + UCHAR* SenseBuffer;
666 + UINT32 SenseBufferSize;
670 + PFN_ON_IO_REQUEST_COMPLTN OnIOCompletion;
672 + // This points to the memory after DataBuffer
675 + MULTIPAGE_BUFFER DataBuffer;
679 +// Represents the block vsc driver
680 +typedef struct _STORVSC_DRIVER_OBJECT {
681 + DRIVER_OBJECT Base; // Must be the first field
683 + // Set by caller (in bytes)
684 + UINT32 RingBufferSize;
686 + // Allocate this much private extension for each I/O request
687 + UINT32 RequestExtSize;
689 + // Maximum # of requests in flight per channel/device
690 + UINT32 MaxOutstandingRequestsPerChannel;
692 + // Set by the caller to allow us to re-enumerate the bus on the host
693 + PFN_ON_HOST_RESCAN OnHostRescan;
695 + // Specific to this driver
696 + PFN_ON_IO_REQUEST OnIORequest;
697 + PFN_ON_HOST_RESET OnHostReset;
699 +} STORVSC_DRIVER_OBJECT;
701 +typedef struct _STORVSC_DEVICE_INFO {
705 +} STORVSC_DEVICE_INFO;
712 + DRIVER_OBJECT *Driver
717 + DRIVER_OBJECT *Driver
719 +#endif // _STORVSC_API_H_
721 +++ b/drivers/staging/hv/include/VmbusApi.h
725 + * Copyright (c) 2009, Microsoft Corporation.
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.
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
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.
741 + * Haiyang Zhang <haiyangz@microsoft.com>
742 + * Hank Janssen <hjanssen@microsoft.com>
747 +#ifndef _VMBUS_API_H_
748 +#define _VMBUS_API_H_
756 +#define MAX_PAGE_BUFFER_COUNT 16
757 +#define MAX_MULTIPAGE_BUFFER_COUNT 32 // 128K
763 +typedef struct _DRIVER_OBJECT *PDRIVER_OBJECT;
764 +typedef struct _DEVICE_OBJECT *PDEVICE_OBJECT;
770 +#pragma pack(push,1)
772 +// Single-page buffer
773 +typedef struct _PAGE_BUFFER {
779 +// Multiple-page buffer
780 +typedef struct _MULTIPAGE_BUFFER {
781 + // Length and Offset determines the # of pfns in the array
784 + UINT64 PfnArray[MAX_MULTIPAGE_BUFFER_COUNT];
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))
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);
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);
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);
812 +// Vmbus channel interface
813 +typedef void (*VMBUS_CHANNEL_CALLBACK)(PVOID context);
815 +typedef int (*VMBUS_CHANNEL_OPEN)(
816 + PDEVICE_OBJECT Device,
817 + UINT32 SendBufferSize,
818 + UINT32 RecvRingBufferSize,
820 + UINT32 UserDataLen,
821 + VMBUS_CHANNEL_CALLBACK ChannelCallback,
825 +typedef void (*VMBUS_CHANNEL_CLOSE)(
826 + PDEVICE_OBJECT Device
829 +typedef int (*VMBUS_CHANNEL_SEND_PACKET)(
830 + PDEVICE_OBJECT Device,
831 + const PVOID Buffer,
838 +typedef int (*VMBUS_CHANNEL_SEND_PACKET_PAGEBUFFER)(
839 + PDEVICE_OBJECT Device,
840 + PAGE_BUFFER PageBuffers[],
847 +typedef int (*VMBUS_CHANNEL_SEND_PACKET_MULTIPAGEBUFFER)(
848 + PDEVICE_OBJECT Device,
849 + MULTIPAGE_BUFFER *MultiPageBuffer,
855 +typedef int (*VMBUS_CHANNEL_RECV_PACKET)(
856 + PDEVICE_OBJECT Device,
859 + UINT32* BufferActualLen,
863 +typedef int (*VMBUS_CHANNEL_RECV_PACKET_PAW)(
864 + PDEVICE_OBJECT Device,
867 + UINT32* BufferActualLen,
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
878 +typedef int (*VMBUS_CHANNEL_TEARDOWN_GPADL)(
879 + PDEVICE_OBJECT Device,
884 +typedef struct _PORT_INFO {
885 + UINT32 InterruptMask;
888 + UINT32 BytesAvailToRead;
889 + UINT32 BytesAvailToWrite;
893 +typedef struct _DEVICE_INFO {
895 + UINT32 ChannelState;
897 + GUID ChannelInstance;
900 + UINT32 ServerMonitorPending;
901 + UINT32 ServerMonitorLatency;
902 + UINT32 ServerMonitorConnectionId;
903 + UINT32 ClientMonitorPending;
904 + UINT32 ClientMonitorLatency;
905 + UINT32 ClientMonitorConnectionId;
908 + PORT_INFO Outbound;
911 +typedef void (*VMBUS_GET_CHANNEL_INFO)(PDEVICE_OBJECT Device, DEVICE_INFO* DeviceInfo);
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;
926 +typedef void (*VMBUS_GET_CHANNEL_INTERFACE)(VMBUS_CHANNEL_INTERFACE *Interface);
928 +// Base driver object
929 +typedef struct _DRIVER_OBJECT {
931 + GUID deviceType; // the device type supported by this driver
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;
938 + VMBUS_CHANNEL_INTERFACE VmbusChannelInterface;
942 +// Base device object
943 +typedef struct _DEVICE_OBJECT {
944 + DRIVER_OBJECT* Driver; // the driver for this device
946 + GUID deviceType; // the device type id of this device
947 + GUID deviceInstance; // the device instance id of this device
949 + void* Extension; // Device extension;
953 +// Vmbus driver object
954 +typedef struct _VMBUS_DRIVER_OBJECT {
955 + DRIVER_OBJECT Base; // !! Must be the 1st field !!
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;
963 + // Set by the callee
964 + //PFN_ON_MATCH OnMatch;
965 + //PFN_ON_PROBE OnProbe;
967 + PFN_ON_DPC OnMsgDpc;
968 + PFN_ON_DPC OnEventDpc;
969 + PFN_GET_CHANNEL_OFFERS GetChannelOffers;
971 + VMBUS_GET_CHANNEL_INTERFACE GetChannelInterface;
972 + VMBUS_GET_CHANNEL_INFO GetChannelInfo;
973 +} VMBUS_DRIVER_OBJECT;
984 +#endif // _VMBUS_API_H_
986 +++ b/drivers/staging/hv/include/vmbus.h
990 + * Copyright (c) 2009, Microsoft Corporation.
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.
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
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.
1006 + * Haiyang Zhang <haiyangz@microsoft.com>
1007 + * Hank Janssen <hjanssen@microsoft.com>
1015 +#include <linux/device.h>
1017 +#include "VmbusApi.h"
1023 +typedef int (*PFN_DRIVERINITIALIZE)(DRIVER_OBJECT *drv);
1024 +typedef int (*PFN_DRIVEREXIT)(DRIVER_OBJECT *drv);
1026 +struct driver_context {
1029 + struct device_driver driver;
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 *);
1037 +struct device_context {
1038 + struct work_struct probe_failed_work_item;
1042 + struct device device;
1043 + DEVICE_OBJECT device_obj;
1054 +static inline struct device_context *to_device_context(DEVICE_OBJECT *device_obj)
1056 + return container_of(device_obj, struct device_context, device_obj);
1059 +static inline struct device_context *device_to_device_context(struct device *device)
1061 + return container_of(device, struct device_context, device);
1064 +static inline struct driver_context *driver_to_driver_context(struct device_driver *driver)
1066 + return container_of(driver, struct driver_context, driver);
1069 +#if defined(KERNEL_2_6_5)
1070 +static inline void* kzalloc(int size, int flags)
1073 + p = kmalloc(size, flags);
1074 + if (p) memset(p, 0, size);
1078 +#endif // KERNEL_2_6_5
1084 +vmbus_child_driver_register(
1085 + struct driver_context* driver_ctx
1089 +vmbus_child_driver_unregister(
1090 + struct driver_context *driver_ctx
1094 +vmbus_get_interface(
1095 + VMBUS_CHANNEL_INTERFACE *interface
1098 +#endif // _VMBUS_H_