writeback: split writeback_inodes_wb
[linux-2.6/next.git] / drivers / staging / hv / vmbus.c
blob007543bdb4100b31d8dba170217a5f46939ef491
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 <linux/slab.h>
25 #include "osd.h"
26 #include "logging.h"
27 #include "version_info.h"
28 #include "vmbus_private.h"
30 static const char *gDriverName = "vmbus";
33 * Windows vmbus does not defined this.
34 * We defined this to be consistent with other devices
36 /* {c5295816-f63a-4d5f-8d1a-4daf999ca185} */
37 static const struct hv_guid gVmbusDeviceType = {
38 .data = {
39 0x16, 0x58, 0x29, 0xc5, 0x3a, 0xf6, 0x5f, 0x4d,
40 0x8d, 0x1a, 0x4d, 0xaf, 0x99, 0x9c, 0xa1, 0x85
44 /* {ac3760fc-9adf-40aa-9427-a70ed6de95c5} */
45 static const struct hv_guid gVmbusDeviceId = {
46 .data = {
47 0xfc, 0x60, 0x37, 0xac, 0xdf, 0x9a, 0xaa, 0x40,
48 0x94, 0x27, 0xa7, 0x0e, 0xd6, 0xde, 0x95, 0xc5
52 static struct hv_driver *gDriver; /* vmbus driver object */
53 static struct hv_device *gDevice; /* vmbus root device */
56 * VmbusGetChannelOffers - Retrieve the channel offers from the parent partition
58 static void VmbusGetChannelOffers(void)
60 DPRINT_ENTER(VMBUS);
61 VmbusChannelRequestOffers();
62 DPRINT_EXIT(VMBUS);
66 * VmbusGetChannelInterface - Get the channel interface
68 static void VmbusGetChannelInterface(struct vmbus_channel_interface *Interface)
70 GetChannelInterface(Interface);
74 * VmbusGetChannelInfo - Get the device info for the specified device object
76 static void VmbusGetChannelInfo(struct hv_device *DeviceObject,
77 struct hv_device_info *DeviceInfo)
79 GetChannelInfo(DeviceObject, DeviceInfo);
83 * VmbusCreateChildDevice - Creates the child device on the bus that represents the channel offer
85 struct hv_device *VmbusChildDeviceCreate(struct hv_guid *DeviceType,
86 struct hv_guid *DeviceInstance,
87 void *Context)
89 struct vmbus_driver *vmbusDriver = (struct vmbus_driver *)gDriver;
91 return vmbusDriver->OnChildDeviceCreate(DeviceType, DeviceInstance,
92 Context);
96 * VmbusChildDeviceAdd - Registers the child device with the vmbus
98 int VmbusChildDeviceAdd(struct hv_device *ChildDevice)
100 struct vmbus_driver *vmbusDriver = (struct vmbus_driver *)gDriver;
102 return vmbusDriver->OnChildDeviceAdd(gDevice, ChildDevice);
106 * VmbusChildDeviceRemove Unregisters the child device from the vmbus
108 void VmbusChildDeviceRemove(struct hv_device *ChildDevice)
110 struct vmbus_driver *vmbusDriver = (struct vmbus_driver *)gDriver;
112 vmbusDriver->OnChildDeviceRemove(ChildDevice);
116 * VmbusOnDeviceAdd - Callback when the root bus device is added
118 static int VmbusOnDeviceAdd(struct hv_device *dev, void *AdditionalInfo)
120 u32 *irqvector = AdditionalInfo;
121 int ret;
123 DPRINT_ENTER(VMBUS);
125 gDevice = dev;
127 memcpy(&gDevice->deviceType, &gVmbusDeviceType, sizeof(struct hv_guid));
128 memcpy(&gDevice->deviceInstance, &gVmbusDeviceId,
129 sizeof(struct hv_guid));
131 /* strcpy(dev->name, "vmbus"); */
132 /* SynIC setup... */
133 on_each_cpu(HvSynicInit, (void *)irqvector, 1);
135 /* Connect to VMBus in the root partition */
136 ret = VmbusConnect();
138 /* VmbusSendEvent(device->localPortId+1); */
139 DPRINT_EXIT(VMBUS);
141 return ret;
145 * VmbusOnDeviceRemove - Callback when the root bus device is removed
147 static int VmbusOnDeviceRemove(struct hv_device *dev)
149 int ret = 0;
151 DPRINT_ENTER(VMBUS);
152 VmbusChannelReleaseUnattachedChannels();
153 VmbusDisconnect();
154 on_each_cpu(HvSynicCleanup, NULL, 1);
155 DPRINT_EXIT(VMBUS);
157 return ret;
161 * VmbusOnCleanup - Perform any cleanup when the driver is removed
163 static void VmbusOnCleanup(struct hv_driver *drv)
165 /* struct vmbus_driver *driver = (struct vmbus_driver *)drv; */
167 DPRINT_ENTER(VMBUS);
168 HvCleanup();
169 DPRINT_EXIT(VMBUS);
173 * VmbusOnMsgDPC - DPC routine to handle messages from the hypervisior
175 static void VmbusOnMsgDPC(struct hv_driver *drv)
177 int cpu = smp_processor_id();
178 void *page_addr = gHvContext.synICMessagePage[cpu];
179 struct hv_message *msg = (struct hv_message *)page_addr +
180 VMBUS_MESSAGE_SINT;
181 struct hv_message *copied;
183 while (1) {
184 if (msg->Header.MessageType == HvMessageTypeNone) {
185 /* no msg */
186 break;
187 } else {
188 copied = kmemdup(msg, sizeof(*copied), GFP_ATOMIC);
189 if (copied == NULL)
190 continue;
192 osd_schedule_callback(gVmbusConnection.WorkQueue,
193 VmbusOnChannelMessage,
194 (void *)copied);
197 msg->Header.MessageType = HvMessageTypeNone;
200 * Make sure the write to MessageType (ie set to
201 * HvMessageTypeNone) happens before we read the
202 * MessagePending and EOMing. Otherwise, the EOMing
203 * will not deliver any more messages since there is
204 * no empty slot
206 mb();
208 if (msg->Header.MessageFlags.MessagePending) {
210 * This will cause message queue rescan to
211 * possibly deliver another msg from the
212 * hypervisor
214 wrmsrl(HV_X64_MSR_EOM, 0);
220 * VmbusOnEventDPC - DPC routine to handle events from the hypervisior
222 static void VmbusOnEventDPC(struct hv_driver *drv)
224 /* TODO: Process any events */
225 VmbusOnEvents();
229 * VmbusOnISR - ISR routine
231 static int VmbusOnISR(struct hv_driver *drv)
233 int ret = 0;
234 int cpu = smp_processor_id();
235 void *page_addr;
236 struct hv_message *msg;
237 union hv_synic_event_flags *event;
239 page_addr = gHvContext.synICMessagePage[cpu];
240 msg = (struct hv_message *)page_addr + VMBUS_MESSAGE_SINT;
242 DPRINT_ENTER(VMBUS);
244 /* Check if there are actual msgs to be process */
245 if (msg->Header.MessageType != HvMessageTypeNone) {
246 DPRINT_DBG(VMBUS, "received msg type %d size %d",
247 msg->Header.MessageType,
248 msg->Header.PayloadSize);
249 ret |= 0x1;
252 /* TODO: Check if there are events to be process */
253 page_addr = gHvContext.synICEventPage[cpu];
254 event = (union hv_synic_event_flags *)page_addr + VMBUS_MESSAGE_SINT;
256 /* Since we are a child, we only need to check bit 0 */
257 if (test_and_clear_bit(0, (unsigned long *) &event->Flags32[0])) {
258 DPRINT_DBG(VMBUS, "received event %d", event->Flags32[0]);
259 ret |= 0x2;
262 DPRINT_EXIT(VMBUS);
263 return ret;
267 * VmbusInitialize - Main entry point
269 int VmbusInitialize(struct hv_driver *drv)
271 struct vmbus_driver *driver = (struct vmbus_driver *)drv;
272 int ret;
274 DPRINT_ENTER(VMBUS);
276 DPRINT_INFO(VMBUS, "+++++++ HV Driver version = %s +++++++",
277 HV_DRV_VERSION);
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;