[ARM] pxa: update defconfig for Verdex Pro
[linux-2.6/verdex.git] / drivers / staging / hv / Vmbus.c
bloba4dd06f6d459bf39496c55ea9d4ca606e7c6bcf7
1 /*
2 * Copyright (c) 2009, Microsoft Corporation.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15 * Place - Suite 330, Boston, MA 02111-1307 USA.
17 * Authors:
18 * Haiyang Zhang <haiyangz@microsoft.com>
19 * Hank Janssen <hjanssen@microsoft.com>
22 #include <linux/kernel.h>
23 #include <linux/mm.h>
24 #include "osd.h"
25 #include "logging.h"
26 #include "VersionInfo.h"
27 #include "VmbusPrivate.h"
29 static const char *gDriverName = "vmbus";
32 * Windows vmbus does not defined this.
33 * We defined this to be consistent with other devices
35 /* {c5295816-f63a-4d5f-8d1a-4daf999ca185} */
36 static const struct hv_guid gVmbusDeviceType = {
37 .data = {
38 0x16, 0x58, 0x29, 0xc5, 0x3a, 0xf6, 0x5f, 0x4d,
39 0x8d, 0x1a, 0x4d, 0xaf, 0x99, 0x9c, 0xa1, 0x85
43 /* {ac3760fc-9adf-40aa-9427-a70ed6de95c5} */
44 static const struct hv_guid gVmbusDeviceId = {
45 .data = {
46 0xfc, 0x60, 0x37, 0xac, 0xdf, 0x9a, 0xaa, 0x40,
47 0x94, 0x27, 0xa7, 0x0e, 0xd6, 0xde, 0x95, 0xc5
51 static struct hv_driver *gDriver; /* vmbus driver object */
52 static struct hv_device *gDevice; /* vmbus root device */
54 /**
55 * VmbusGetChannelOffers - Retrieve the channel offers from the parent partition
57 static void VmbusGetChannelOffers(void)
59 DPRINT_ENTER(VMBUS);
60 VmbusChannelRequestOffers();
61 DPRINT_EXIT(VMBUS);
64 /**
65 * VmbusGetChannelInterface - Get the channel interface
67 static void VmbusGetChannelInterface(struct vmbus_channel_interface *Interface)
69 GetChannelInterface(Interface);
72 /**
73 * VmbusGetChannelInfo - Get the device info for the specified device object
75 static void VmbusGetChannelInfo(struct hv_device *DeviceObject,
76 struct hv_device_info *DeviceInfo)
78 GetChannelInfo(DeviceObject, DeviceInfo);
81 /**
82 * VmbusCreateChildDevice - Creates the child device on the bus that represents the channel offer
84 struct hv_device *VmbusChildDeviceCreate(struct hv_guid *DeviceType,
85 struct hv_guid *DeviceInstance,
86 void *Context)
88 struct vmbus_driver *vmbusDriver = (struct vmbus_driver *)gDriver;
90 return vmbusDriver->OnChildDeviceCreate(DeviceType, DeviceInstance,
91 Context);
94 /**
95 * VmbusChildDeviceAdd - Registers the child device with the vmbus
97 int VmbusChildDeviceAdd(struct hv_device *ChildDevice)
99 struct vmbus_driver *vmbusDriver = (struct vmbus_driver *)gDriver;
101 return vmbusDriver->OnChildDeviceAdd(gDevice, ChildDevice);
105 * VmbusChildDeviceRemove Unregisters the child device from the vmbus
107 void VmbusChildDeviceRemove(struct hv_device *ChildDevice)
109 struct vmbus_driver *vmbusDriver = (struct vmbus_driver *)gDriver;
111 vmbusDriver->OnChildDeviceRemove(ChildDevice);
115 * VmbusOnDeviceAdd - Callback when the root bus device is added
117 static int VmbusOnDeviceAdd(struct hv_device *dev, void *AdditionalInfo)
119 u32 *irqvector = AdditionalInfo;
120 int ret;
122 DPRINT_ENTER(VMBUS);
124 gDevice = dev;
126 memcpy(&gDevice->deviceType, &gVmbusDeviceType, sizeof(struct hv_guid));
127 memcpy(&gDevice->deviceInstance, &gVmbusDeviceId,
128 sizeof(struct hv_guid));
130 /* strcpy(dev->name, "vmbus"); */
131 /* SynIC setup... */
132 ret = HvSynicInit(*irqvector);
134 /* Connect to VMBus in the root partition */
135 ret = VmbusConnect();
137 /* VmbusSendEvent(device->localPortId+1); */
138 DPRINT_EXIT(VMBUS);
140 return ret;
144 * VmbusOnDeviceRemove - Callback when the root bus device is removed
146 static int VmbusOnDeviceRemove(struct hv_device *dev)
148 int ret = 0;
150 DPRINT_ENTER(VMBUS);
151 VmbusChannelReleaseUnattachedChannels();
152 VmbusDisconnect();
153 HvSynicCleanup();
154 DPRINT_EXIT(VMBUS);
156 return ret;
160 * VmbusOnCleanup - Perform any cleanup when the driver is removed
162 static void VmbusOnCleanup(struct hv_driver *drv)
164 /* struct vmbus_driver *driver = (struct vmbus_driver *)drv; */
166 DPRINT_ENTER(VMBUS);
167 HvCleanup();
168 DPRINT_EXIT(VMBUS);
172 * VmbusOnMsgDPC - DPC routine to handle messages from the hypervisior
174 static void VmbusOnMsgDPC(struct hv_driver *drv)
176 void *page_addr = gHvContext.synICMessagePage[0];
177 struct hv_message *msg = (struct hv_message *)page_addr +
178 VMBUS_MESSAGE_SINT;
179 struct hv_message *copied;
181 while (1) {
182 if (msg->Header.MessageType == HvMessageTypeNone) {
183 /* no msg */
184 break;
185 } else {
186 copied = kmalloc(sizeof(*copied), GFP_ATOMIC);
187 if (copied == NULL)
188 continue;
190 memcpy(copied, msg, sizeof(*copied));
191 osd_schedule_callback(gVmbusConnection.WorkQueue,
192 VmbusOnChannelMessage,
193 (void *)copied);
196 msg->Header.MessageType = HvMessageTypeNone;
199 * Make sure the write to MessageType (ie set to
200 * HvMessageTypeNone) happens before we read the
201 * MessagePending and EOMing. Otherwise, the EOMing
202 * will not deliver any more messages since there is
203 * no empty slot
205 mb();
207 if (msg->Header.MessageFlags.MessagePending) {
209 * This will cause message queue rescan to
210 * possibly deliver another msg from the
211 * hypervisor
213 wrmsrl(HV_X64_MSR_EOM, 0);
219 * VmbusOnEventDPC - DPC routine to handle events from the hypervisior
221 static void VmbusOnEventDPC(struct hv_driver *drv)
223 /* TODO: Process any events */
224 VmbusOnEvents();
228 * VmbusOnISR - ISR routine
230 static int VmbusOnISR(struct hv_driver *drv)
232 int ret = 0;
233 void *page_addr;
234 struct hv_message *msg;
235 union hv_synic_event_flags *event;
237 page_addr = gHvContext.synICMessagePage[0];
238 msg = (struct hv_message *)page_addr + VMBUS_MESSAGE_SINT;
240 DPRINT_ENTER(VMBUS);
242 /* Check if there are actual msgs to be process */
243 if (msg->Header.MessageType != HvMessageTypeNone) {
244 DPRINT_DBG(VMBUS, "received msg type %d size %d",
245 msg->Header.MessageType,
246 msg->Header.PayloadSize);
247 ret |= 0x1;
250 /* TODO: Check if there are events to be process */
251 page_addr = gHvContext.synICEventPage[0];
252 event = (union hv_synic_event_flags *)page_addr + VMBUS_MESSAGE_SINT;
254 /* Since we are a child, we only need to check bit 0 */
255 if (test_and_clear_bit(0, (unsigned long *) &event->Flags32[0])) {
256 DPRINT_DBG(VMBUS, "received event %d", event->Flags32[0]);
257 ret |= 0x2;
260 DPRINT_EXIT(VMBUS);
261 return ret;
265 * VmbusInitialize - Main entry point
267 int VmbusInitialize(struct hv_driver *drv)
269 struct vmbus_driver *driver = (struct vmbus_driver *)drv;
270 int ret;
272 DPRINT_ENTER(VMBUS);
274 DPRINT_INFO(VMBUS, "+++++++ Build Date=%s %s +++++++",
275 VersionDate, VersionTime);
276 DPRINT_INFO(VMBUS, "+++++++ Build Description=%s +++++++",
277 VersionDesc);
278 DPRINT_INFO(VMBUS, "+++++++ Vmbus supported version = %d +++++++",
279 VMBUS_REVISION_NUMBER);
280 DPRINT_INFO(VMBUS, "+++++++ Vmbus using SINT %d +++++++",
281 VMBUS_MESSAGE_SINT);
282 DPRINT_DBG(VMBUS, "sizeof(VMBUS_CHANNEL_PACKET_PAGE_BUFFER)=%zd, "
283 "sizeof(VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER)=%zd",
284 sizeof(struct VMBUS_CHANNEL_PACKET_PAGE_BUFFER),
285 sizeof(struct VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER));
287 drv->name = gDriverName;
288 memcpy(&drv->deviceType, &gVmbusDeviceType, sizeof(struct hv_guid));
290 /* Setup dispatch table */
291 driver->Base.OnDeviceAdd = VmbusOnDeviceAdd;
292 driver->Base.OnDeviceRemove = VmbusOnDeviceRemove;
293 driver->Base.OnCleanup = VmbusOnCleanup;
294 driver->OnIsr = VmbusOnISR;
295 driver->OnMsgDpc = VmbusOnMsgDPC;
296 driver->OnEventDpc = VmbusOnEventDPC;
297 driver->GetChannelOffers = VmbusGetChannelOffers;
298 driver->GetChannelInterface = VmbusGetChannelInterface;
299 driver->GetChannelInfo = VmbusGetChannelInfo;
301 /* Hypervisor initialization...setup hypercall page..etc */
302 ret = HvInit();
303 if (ret != 0)
304 DPRINT_ERR(VMBUS, "Unable to initialize the hypervisor - 0x%x",
305 ret);
306 gDriver = drv;
308 DPRINT_EXIT(VMBUS);
310 return ret;