3 * Copyright (c) 2009, Microsoft Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16 * Place - Suite 330, Boston, MA 02111-1307 USA.
19 * Haiyang Zhang <haiyangz@microsoft.com>
20 * Hank Janssen <hjanssen@microsoft.com>
28 #define MAX_PAGE_BUFFER_COUNT 16
29 #define MAX_MULTIPAGE_BUFFER_COUNT 32 /* 128K */
33 /* Single-page buffer */
34 typedef struct _PAGE_BUFFER {
40 /* Multiple-page buffer */
41 typedef struct _MULTIPAGE_BUFFER {
42 /* Length and Offset determines the # of pfns in the array */
45 u64 PfnArray[MAX_MULTIPAGE_BUFFER_COUNT];
48 /* 0x18 includes the proprietary packet header */
49 #define MAX_PAGE_BUFFER_PACKET (0x18 + \
50 (sizeof(PAGE_BUFFER) * \
51 MAX_PAGE_BUFFER_COUNT))
52 #define MAX_MULTIPAGE_BUFFER_PACKET (0x18 + sizeof(MULTIPAGE_BUFFER))
61 typedef int (*PFN_ON_DEVICEADD)(struct hv_device *Device,
62 void *AdditionalInfo);
63 typedef int (*PFN_ON_DEVICEREMOVE)(struct hv_device *Device);
64 typedef char** (*PFN_ON_GETDEVICEIDS)(void);
65 typedef void (*PFN_ON_CLEANUP)(struct hv_driver *Driver);
67 /* Vmbus extensions */
68 typedef int (*PFN_ON_ISR)(struct hv_driver *drv);
69 typedef void (*PFN_ON_DPC)(struct hv_driver *drv);
70 typedef void (*PFN_GET_CHANNEL_OFFERS)(void);
72 typedef struct hv_device *(*PFN_ON_CHILDDEVICE_CREATE)
73 (struct hv_guid *DeviceType,
74 struct hv_guid *DeviceInstance,
76 typedef void (*PFN_ON_CHILDDEVICE_DESTROY)(struct hv_device *Device);
77 typedef int (*PFN_ON_CHILDDEVICE_ADD)(struct hv_device *RootDevice,
78 struct hv_device *ChildDevice);
79 typedef void (*PFN_ON_CHILDDEVICE_REMOVE)(struct hv_device *Device);
81 /* Vmbus channel interface */
82 typedef void (*VMBUS_CHANNEL_CALLBACK)(void *context);
83 typedef int (*VMBUS_CHANNEL_OPEN)(struct hv_device *Device, u32 SendBufferSize,
84 u32 RecvRingBufferSize,
87 VMBUS_CHANNEL_CALLBACK ChannelCallback,
89 typedef void (*VMBUS_CHANNEL_CLOSE)(struct hv_device *Device);
90 typedef int (*VMBUS_CHANNEL_SEND_PACKET)(struct hv_device *Device,
96 typedef int (*VMBUS_CHANNEL_SEND_PACKET_PAGEBUFFER)(struct hv_device *Device,
97 PAGE_BUFFER PageBuffers[],
102 typedef int(*VMBUS_CHANNEL_SEND_PACKET_MULTIPAGEBUFFER)
103 (struct hv_device *Device,
104 MULTIPAGE_BUFFER *MultiPageBuffer,
108 typedef int (*VMBUS_CHANNEL_RECV_PACKET)(struct hv_device *Device,
111 u32 *BufferActualLen,
113 typedef int(*VMBUS_CHANNEL_RECV_PACKET_PAW)(struct hv_device *Device,
116 u32 *BufferActualLen,
118 typedef int (*VMBUS_CHANNEL_ESTABLISH_GPADL)(struct hv_device *Device,
122 typedef int (*VMBUS_CHANNEL_TEARDOWN_GPADL)(struct hv_device *Device,
126 typedef struct _PORT_INFO {
130 u32 BytesAvailToRead;
131 u32 BytesAvailToWrite;
134 typedef struct _DEVICE_INFO {
137 struct hv_guid ChannelType;
138 struct hv_guid ChannelInstance;
141 u32 ServerMonitorPending;
142 u32 ServerMonitorLatency;
143 u32 ServerMonitorConnectionId;
144 u32 ClientMonitorPending;
145 u32 ClientMonitorLatency;
146 u32 ClientMonitorConnectionId;
152 typedef void (*VMBUS_GET_CHANNEL_INFO)(struct hv_device *Device,
153 DEVICE_INFO *DeviceInfo);
155 typedef struct _VMBUS_CHANNEL_INTERFACE {
156 VMBUS_CHANNEL_OPEN Open;
157 VMBUS_CHANNEL_CLOSE Close;
158 VMBUS_CHANNEL_SEND_PACKET SendPacket;
159 VMBUS_CHANNEL_SEND_PACKET_PAGEBUFFER SendPacketPageBuffer;
160 VMBUS_CHANNEL_SEND_PACKET_MULTIPAGEBUFFER SendPacketMultiPageBuffer;
161 VMBUS_CHANNEL_RECV_PACKET RecvPacket;
162 VMBUS_CHANNEL_RECV_PACKET_PAW RecvPacketRaw;
163 VMBUS_CHANNEL_ESTABLISH_GPADL EstablishGpadl;
164 VMBUS_CHANNEL_TEARDOWN_GPADL TeardownGpadl;
165 VMBUS_GET_CHANNEL_INFO GetInfo;
166 } VMBUS_CHANNEL_INTERFACE;
168 typedef void (*VMBUS_GET_CHANNEL_INTERFACE)(VMBUS_CHANNEL_INTERFACE *Interface);
170 /* Base driver object */
174 /* the device type supported by this driver */
175 struct hv_guid deviceType;
177 PFN_ON_DEVICEADD OnDeviceAdd;
178 PFN_ON_DEVICEREMOVE OnDeviceRemove;
180 /* device ids supported by this driver */
181 PFN_ON_GETDEVICEIDS OnGetDeviceIds;
182 PFN_ON_CLEANUP OnCleanup;
184 VMBUS_CHANNEL_INTERFACE VmbusChannelInterface;
187 /* Base device object */
189 /* the driver for this device */
190 struct hv_driver *Driver;
194 /* the device type id of this device */
195 struct hv_guid deviceType;
197 /* the device instance id of this device */
198 struct hv_guid deviceInstance;
202 /* Device extension; */
206 /* Vmbus driver object */
207 typedef struct _VMBUS_DRIVER_OBJECT {
208 /* !! Must be the 1st field !! */
209 /* FIXME if ^, then someone is doing somthing stupid */
210 struct hv_driver Base;
212 /* Set by the caller */
213 PFN_ON_CHILDDEVICE_CREATE OnChildDeviceCreate;
214 PFN_ON_CHILDDEVICE_DESTROY OnChildDeviceDestroy;
215 PFN_ON_CHILDDEVICE_ADD OnChildDeviceAdd;
216 PFN_ON_CHILDDEVICE_REMOVE OnChildDeviceRemove;
218 /* Set by the callee */
221 PFN_ON_DPC OnEventDpc;
222 PFN_GET_CHANNEL_OFFERS GetChannelOffers;
224 VMBUS_GET_CHANNEL_INTERFACE GetChannelInterface;
225 VMBUS_GET_CHANNEL_INFO GetChannelInfo;
226 } VMBUS_DRIVER_OBJECT;
228 int VmbusInitialize(struct hv_driver *drv);
230 #endif /* _VMBUS_API_H_ */