Staging: hv: remove more printk() warnings
[linux-2.6/mini2440.git] / drivers / staging / hv / Vmbus.c
blob825c2f2d3e09885ec8d5b8e4f46488522b53a6a3
1 /*
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
12 * more details.
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.
18 * Authors:
19 * Haiyang Zhang <haiyangz@microsoft.com>
20 * Hank Janssen <hjanssen@microsoft.com>
24 #include <linux/kernel.h>
25 #include <linux/mm.h>
26 #include "include/logging.h"
27 #include "VersionInfo.h"
28 #include "VmbusPrivate.h"
31 /* Globals */
33 static const char* gDriverName="vmbus";
35 /* Windows vmbus does not defined this.
36 * We defined this to be consistent with other devices
38 /* {c5295816-f63a-4d5f-8d1a-4daf999ca185} */
39 static const GUID gVmbusDeviceType={
40 .Data = {0x16, 0x58, 0x29, 0xc5, 0x3a, 0xf6, 0x5f, 0x4d, 0x8d, 0x1a, 0x4d, 0xaf, 0x99, 0x9c, 0xa1, 0x85}
43 /* {ac3760fc-9adf-40aa-9427-a70ed6de95c5} */
44 static const GUID gVmbusDeviceId={
45 .Data = {0xfc, 0x60, 0x37, 0xac, 0xdf, 0x9a, 0xaa, 0x40, 0x94, 0x27, 0xa7, 0x0e, 0xd6, 0xde, 0x95, 0xc5}
48 static DRIVER_OBJECT* gDriver; /* vmbus driver object */
49 static struct hv_device* gDevice; /* vmbus root device */
53 /* Internal routines */
56 static void
57 VmbusGetChannelInterface(
58 VMBUS_CHANNEL_INTERFACE *Interface
61 static void
62 VmbusGetChannelInfo(
63 struct hv_device *DeviceObject,
64 DEVICE_INFO *DeviceInfo
67 static void
68 VmbusGetChannelOffers(
69 void
72 static int
73 VmbusOnDeviceAdd(
74 struct hv_device *Device,
75 void *AdditionalInfo
78 static int
79 VmbusOnDeviceRemove(
80 struct hv_device *dev
83 static void
84 VmbusOnCleanup(
85 DRIVER_OBJECT* drv
88 static int
89 VmbusOnISR(
90 DRIVER_OBJECT* drv
93 static void
94 VmbusOnMsgDPC(
95 DRIVER_OBJECT* drv
98 static void
99 VmbusOnEventDPC(
100 DRIVER_OBJECT* drv
103 /*++;
105 Name:
106 VmbusInitialize()
108 Description:
109 Main entry point
111 --*/
113 VmbusInitialize(
114 DRIVER_OBJECT* drv
117 VMBUS_DRIVER_OBJECT* driver = (VMBUS_DRIVER_OBJECT*)drv;
118 int ret=0;
120 DPRINT_ENTER(VMBUS);
122 DPRINT_INFO(VMBUS, "+++++++ Build Date=%s %s +++++++", VersionDate, VersionTime);
123 DPRINT_INFO(VMBUS, "+++++++ Build Description=%s +++++++", VersionDesc);
125 DPRINT_INFO(VMBUS, "+++++++ Vmbus supported version = %d +++++++", VMBUS_REVISION_NUMBER);
126 DPRINT_INFO(VMBUS, "+++++++ Vmbus using SINT %d +++++++", VMBUS_MESSAGE_SINT);
128 DPRINT_DBG(VMBUS, "sizeof(VMBUS_CHANNEL_PACKET_PAGE_BUFFER)=%d, sizeof(VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER)=%d",
129 sizeof(struct VMBUS_CHANNEL_PACKET_PAGE_BUFFER), sizeof(struct VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER));
131 drv->name = gDriverName;
132 memcpy(&drv->deviceType, &gVmbusDeviceType, sizeof(GUID));
134 /* Setup dispatch table */
135 driver->Base.OnDeviceAdd = VmbusOnDeviceAdd;
136 driver->Base.OnDeviceRemove = VmbusOnDeviceRemove;
137 driver->Base.OnCleanup = VmbusOnCleanup;
138 driver->OnIsr = VmbusOnISR;
139 driver->OnMsgDpc = VmbusOnMsgDPC;
140 driver->OnEventDpc = VmbusOnEventDPC;
141 driver->GetChannelOffers = VmbusGetChannelOffers;
142 driver->GetChannelInterface = VmbusGetChannelInterface;
143 driver->GetChannelInfo = VmbusGetChannelInfo;
145 /* Hypervisor initialization...setup hypercall page..etc */
146 ret = HvInit();
147 if (ret != 0)
149 DPRINT_ERR(VMBUS, "Unable to initialize the hypervisor - 0x%x", ret);
152 gDriver = drv;
154 DPRINT_EXIT(VMBUS);
156 return ret;
160 /*++;
162 Name:
163 VmbusGetChannelOffers()
165 Description:
166 Retrieve the channel offers from the parent partition
168 --*/
170 static void
171 VmbusGetChannelOffers(void)
173 DPRINT_ENTER(VMBUS);
174 VmbusChannelRequestOffers();
175 DPRINT_EXIT(VMBUS);
179 /*++;
181 Name:
182 VmbusGetChannelInterface()
184 Description:
185 Get the channel interface
187 --*/
188 static void
189 VmbusGetChannelInterface(
190 VMBUS_CHANNEL_INTERFACE *Interface
193 GetChannelInterface(Interface);
197 /*++;
199 Name:
200 VmbusGetChannelInterface()
202 Description:
203 Get the device info for the specified device object
205 --*/
206 static void
207 VmbusGetChannelInfo(
208 struct hv_device *DeviceObject,
209 DEVICE_INFO *DeviceInfo
212 GetChannelInfo(DeviceObject, DeviceInfo);
217 /*++
219 Name:
220 VmbusCreateChildDevice()
222 Description:
223 Creates the child device on the bus that represents the channel offer
225 --*/
227 struct hv_device*
228 VmbusChildDeviceCreate(
229 GUID DeviceType,
230 GUID DeviceInstance,
231 void *Context)
233 VMBUS_DRIVER_OBJECT* vmbusDriver = (VMBUS_DRIVER_OBJECT*)gDriver;
235 return vmbusDriver->OnChildDeviceCreate(
236 DeviceType,
237 DeviceInstance,
238 Context);
242 /*++
244 Name:
245 VmbusChildDeviceAdd()
247 Description:
248 Registers the child device with the vmbus
250 --*/
252 VmbusChildDeviceAdd(
253 struct hv_device *ChildDevice)
255 VMBUS_DRIVER_OBJECT* vmbusDriver = (VMBUS_DRIVER_OBJECT*)gDriver;
257 return vmbusDriver->OnChildDeviceAdd(gDevice, ChildDevice);
261 /*++
263 Name:
264 VmbusChildDeviceRemove()
266 Description:
267 Unregisters the child device from the vmbus
269 --*/
270 void
271 VmbusChildDeviceRemove(
272 struct hv_device *ChildDevice)
274 VMBUS_DRIVER_OBJECT* vmbusDriver = (VMBUS_DRIVER_OBJECT*)gDriver;
276 vmbusDriver->OnChildDeviceRemove(ChildDevice);
279 /*++
281 Name:
282 VmbusChildDeviceDestroy()
284 Description:
285 Release the child device from the vmbus
287 --*/
289 /* **************
290 void
291 VmbusChildDeviceDestroy(
292 struct hv_device *ChildDevice
295 VMBUS_DRIVER_OBJECT* vmbusDriver = (VMBUS_DRIVER_OBJECT*)gDriver;
297 vmbusDriver->OnChildDeviceDestroy(ChildDevice);
299 ************* */
301 /*++
303 Name:
304 VmbusOnDeviceAdd()
306 Description:
307 Callback when the root bus device is added
309 --*/
310 static int
311 VmbusOnDeviceAdd(
312 struct hv_device *dev,
313 void *AdditionalInfo
316 u32 *irqvector = (u32*) AdditionalInfo;
317 int ret=0;
319 DPRINT_ENTER(VMBUS);
321 gDevice = dev;
323 memcpy(&gDevice->deviceType, &gVmbusDeviceType, sizeof(GUID));
324 memcpy(&gDevice->deviceInstance, &gVmbusDeviceId, sizeof(GUID));
326 /* strcpy(dev->name, "vmbus"); */
327 /* SynIC setup... */
328 ret = HvSynicInit(*irqvector);
330 /* Connect to VMBus in the root partition */
331 ret = VmbusConnect();
333 /* VmbusSendEvent(device->localPortId+1); */
334 DPRINT_EXIT(VMBUS);
336 return ret;
340 /*++
342 Name:
343 VmbusOnDeviceRemove()
345 Description:
346 Callback when the root bus device is removed
348 --*/
349 int VmbusOnDeviceRemove(
350 struct hv_device *dev
353 int ret=0;
355 DPRINT_ENTER(VMBUS);
357 VmbusChannelReleaseUnattachedChannels();
359 VmbusDisconnect();
361 HvSynicCleanup();
363 DPRINT_EXIT(VMBUS);
365 return ret;
369 /*++
371 Name:
372 VmbusOnCleanup()
374 Description:
375 Perform any cleanup when the driver is removed
377 --*/
378 void
379 VmbusOnCleanup(
380 DRIVER_OBJECT* drv
383 /* VMBUS_DRIVER_OBJECT* driver = (VMBUS_DRIVER_OBJECT*)drv; */
385 DPRINT_ENTER(VMBUS);
387 HvCleanup();
389 DPRINT_EXIT(VMBUS);
393 /*++
395 Name:
396 VmbusOnMsgDPC()
398 Description:
399 DPC routine to handle messages from the hypervisior
401 --*/
402 void
403 VmbusOnMsgDPC(
404 DRIVER_OBJECT* drv
407 void *page_addr = gHvContext.synICMessagePage[0];
409 HV_MESSAGE* msg = (HV_MESSAGE*)page_addr + VMBUS_MESSAGE_SINT;
410 HV_MESSAGE *copied;
411 while (1)
413 if (msg->Header.MessageType == HvMessageTypeNone) /* no msg */
415 break;
417 else
419 copied = kmalloc(sizeof(HV_MESSAGE), GFP_ATOMIC);
420 if (copied == NULL)
422 continue;
425 memcpy(copied, msg, sizeof(HV_MESSAGE));
426 WorkQueueQueueWorkItem(gVmbusConnection.WorkQueue, VmbusOnChannelMessage, (void*)copied);
429 msg->Header.MessageType = HvMessageTypeNone;
432 * Make sure the write to MessageType (ie set to
433 * HvMessageTypeNone) happens before we read the
434 * MessagePending and EOMing. Otherwise, the EOMing
435 * will not deliver any more messages since there is
436 * no empty slot
438 mb();
440 if (msg->Header.MessageFlags.MessagePending)
443 * This will cause message queue rescan to
444 * possibly deliver another msg from the
445 * hypervisor
447 WriteMsr(HV_X64_MSR_EOM, 0);
452 /*++
454 Name:
455 VmbusOnEventDPC()
457 Description:
458 DPC routine to handle events from the hypervisior
460 --*/
461 void
462 VmbusOnEventDPC(
463 DRIVER_OBJECT* drv
466 /* TODO: Process any events */
467 VmbusOnEvents();
471 /*++
473 Name:
474 VmbusOnISR()
476 Description:
477 ISR routine
479 --*/
481 VmbusOnISR(
482 DRIVER_OBJECT* drv
485 /* VMBUS_DRIVER_OBJECT* driver = (VMBUS_DRIVER_OBJECT*)drv; */
487 int ret=0;
488 /* struct page* page; */
489 void *page_addr;
490 HV_MESSAGE* msg;
491 HV_SYNIC_EVENT_FLAGS* event;
493 /* page = SynICMessagePage[0]; */
494 /* page_addr = page_address(page); */
495 page_addr = gHvContext.synICMessagePage[0];
496 msg = (HV_MESSAGE*)page_addr + VMBUS_MESSAGE_SINT;
498 DPRINT_ENTER(VMBUS);
500 /* Check if there are actual msgs to be process */
501 if (msg->Header.MessageType != HvMessageTypeNone)
503 DPRINT_DBG(VMBUS, "received msg type %d size %d", msg->Header.MessageType, msg->Header.PayloadSize);
504 ret |= 0x1;
507 /* TODO: Check if there are events to be process */
508 page_addr = gHvContext.synICEventPage[0];
509 event = (HV_SYNIC_EVENT_FLAGS*)page_addr + VMBUS_MESSAGE_SINT;
511 /* Since we are a child, we only need to check bit 0 */
512 if (BitTestAndClear(&event->Flags32[0], 0))
514 DPRINT_DBG(VMBUS, "received event %d", event->Flags32[0]);
515 ret |= 0x2;
518 DPRINT_EXIT(VMBUS);
519 return ret;
522 /* eof */