gma500: begin the config based split
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / staging / hv / vmbus_drv.c
blobbe158be28ee3ee20bc1c97ae1cf50d263f6b5c46
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>
20 * K. Y. Srinivasan <kys@microsoft.com>
23 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
25 #include <linux/init.h>
26 #include <linux/module.h>
27 #include <linux/device.h>
28 #include <linux/irq.h>
29 #include <linux/interrupt.h>
30 #include <linux/sysctl.h>
31 #include <linux/pci.h>
32 #include <linux/dmi.h>
33 #include <linux/slab.h>
34 #include <linux/acpi.h>
35 #include <acpi/acpi_bus.h>
36 #include <linux/completion.h>
38 #include "hyperv.h"
39 #include "hyperv_vmbus.h"
42 static struct acpi_device *hv_acpi_dev;
44 static struct tasklet_struct msg_dpc;
45 static struct tasklet_struct event_dpc;
47 unsigned int vmbus_loglevel = (ALL_MODULES << 16 | INFO_LVL);
48 EXPORT_SYMBOL(vmbus_loglevel);
49 /* (ALL_MODULES << 16 | DEBUG_LVL_ENTEREXIT); */
50 /* (((VMBUS | VMBUS_DRV)<<16) | DEBUG_LVL_ENTEREXIT); */
52 static struct completion probe_event;
53 static int irq;
55 static void get_channel_info(struct hv_device *device,
56 struct hv_device_info *info)
58 struct vmbus_channel_debug_info debug_info;
60 if (!device->channel)
61 return;
63 vmbus_get_debug_info(device->channel, &debug_info);
65 info->chn_id = debug_info.relid;
66 info->chn_state = debug_info.state;
67 memcpy(&info->chn_type, &debug_info.interfacetype,
68 sizeof(struct hv_guid));
69 memcpy(&info->chn_instance, &debug_info.interface_instance,
70 sizeof(struct hv_guid));
72 info->monitor_id = debug_info.monitorid;
74 info->server_monitor_pending = debug_info.servermonitor_pending;
75 info->server_monitor_latency = debug_info.servermonitor_latency;
76 info->server_monitor_conn_id = debug_info.servermonitor_connectionid;
78 info->client_monitor_pending = debug_info.clientmonitor_pending;
79 info->client_monitor_latency = debug_info.clientmonitor_latency;
80 info->client_monitor_conn_id = debug_info.clientmonitor_connectionid;
82 info->inbound.int_mask = debug_info.inbound.current_interrupt_mask;
83 info->inbound.read_idx = debug_info.inbound.current_read_index;
84 info->inbound.write_idx = debug_info.inbound.current_write_index;
85 info->inbound.bytes_avail_toread =
86 debug_info.inbound.bytes_avail_toread;
87 info->inbound.bytes_avail_towrite =
88 debug_info.inbound.bytes_avail_towrite;
90 info->outbound.int_mask =
91 debug_info.outbound.current_interrupt_mask;
92 info->outbound.read_idx = debug_info.outbound.current_read_index;
93 info->outbound.write_idx = debug_info.outbound.current_write_index;
94 info->outbound.bytes_avail_toread =
95 debug_info.outbound.bytes_avail_toread;
96 info->outbound.bytes_avail_towrite =
97 debug_info.outbound.bytes_avail_towrite;
101 * vmbus_show_device_attr - Show the device attribute in sysfs.
103 * This is invoked when user does a
104 * "cat /sys/bus/vmbus/devices/<busdevice>/<attr name>"
106 static ssize_t vmbus_show_device_attr(struct device *dev,
107 struct device_attribute *dev_attr,
108 char *buf)
110 struct hv_device *hv_dev = device_to_hv_device(dev);
111 struct hv_device_info device_info;
113 memset(&device_info, 0, sizeof(struct hv_device_info));
115 get_channel_info(hv_dev, &device_info);
117 if (!strcmp(dev_attr->attr.name, "class_id")) {
118 return sprintf(buf, "{%02x%02x%02x%02x-%02x%02x-%02x%02x-"
119 "%02x%02x%02x%02x%02x%02x%02x%02x}\n",
120 device_info.chn_type.data[3],
121 device_info.chn_type.data[2],
122 device_info.chn_type.data[1],
123 device_info.chn_type.data[0],
124 device_info.chn_type.data[5],
125 device_info.chn_type.data[4],
126 device_info.chn_type.data[7],
127 device_info.chn_type.data[6],
128 device_info.chn_type.data[8],
129 device_info.chn_type.data[9],
130 device_info.chn_type.data[10],
131 device_info.chn_type.data[11],
132 device_info.chn_type.data[12],
133 device_info.chn_type.data[13],
134 device_info.chn_type.data[14],
135 device_info.chn_type.data[15]);
136 } else if (!strcmp(dev_attr->attr.name, "device_id")) {
137 return sprintf(buf, "{%02x%02x%02x%02x-%02x%02x-%02x%02x-"
138 "%02x%02x%02x%02x%02x%02x%02x%02x}\n",
139 device_info.chn_instance.data[3],
140 device_info.chn_instance.data[2],
141 device_info.chn_instance.data[1],
142 device_info.chn_instance.data[0],
143 device_info.chn_instance.data[5],
144 device_info.chn_instance.data[4],
145 device_info.chn_instance.data[7],
146 device_info.chn_instance.data[6],
147 device_info.chn_instance.data[8],
148 device_info.chn_instance.data[9],
149 device_info.chn_instance.data[10],
150 device_info.chn_instance.data[11],
151 device_info.chn_instance.data[12],
152 device_info.chn_instance.data[13],
153 device_info.chn_instance.data[14],
154 device_info.chn_instance.data[15]);
155 } else if (!strcmp(dev_attr->attr.name, "state")) {
156 return sprintf(buf, "%d\n", device_info.chn_state);
157 } else if (!strcmp(dev_attr->attr.name, "id")) {
158 return sprintf(buf, "%d\n", device_info.chn_id);
159 } else if (!strcmp(dev_attr->attr.name, "out_intr_mask")) {
160 return sprintf(buf, "%d\n", device_info.outbound.int_mask);
161 } else if (!strcmp(dev_attr->attr.name, "out_read_index")) {
162 return sprintf(buf, "%d\n", device_info.outbound.read_idx);
163 } else if (!strcmp(dev_attr->attr.name, "out_write_index")) {
164 return sprintf(buf, "%d\n", device_info.outbound.write_idx);
165 } else if (!strcmp(dev_attr->attr.name, "out_read_bytes_avail")) {
166 return sprintf(buf, "%d\n",
167 device_info.outbound.bytes_avail_toread);
168 } else if (!strcmp(dev_attr->attr.name, "out_write_bytes_avail")) {
169 return sprintf(buf, "%d\n",
170 device_info.outbound.bytes_avail_towrite);
171 } else if (!strcmp(dev_attr->attr.name, "in_intr_mask")) {
172 return sprintf(buf, "%d\n", device_info.inbound.int_mask);
173 } else if (!strcmp(dev_attr->attr.name, "in_read_index")) {
174 return sprintf(buf, "%d\n", device_info.inbound.read_idx);
175 } else if (!strcmp(dev_attr->attr.name, "in_write_index")) {
176 return sprintf(buf, "%d\n", device_info.inbound.write_idx);
177 } else if (!strcmp(dev_attr->attr.name, "in_read_bytes_avail")) {
178 return sprintf(buf, "%d\n",
179 device_info.inbound.bytes_avail_toread);
180 } else if (!strcmp(dev_attr->attr.name, "in_write_bytes_avail")) {
181 return sprintf(buf, "%d\n",
182 device_info.inbound.bytes_avail_towrite);
183 } else if (!strcmp(dev_attr->attr.name, "monitor_id")) {
184 return sprintf(buf, "%d\n", device_info.monitor_id);
185 } else if (!strcmp(dev_attr->attr.name, "server_monitor_pending")) {
186 return sprintf(buf, "%d\n", device_info.server_monitor_pending);
187 } else if (!strcmp(dev_attr->attr.name, "server_monitor_latency")) {
188 return sprintf(buf, "%d\n", device_info.server_monitor_latency);
189 } else if (!strcmp(dev_attr->attr.name, "server_monitor_conn_id")) {
190 return sprintf(buf, "%d\n",
191 device_info.server_monitor_conn_id);
192 } else if (!strcmp(dev_attr->attr.name, "client_monitor_pending")) {
193 return sprintf(buf, "%d\n", device_info.client_monitor_pending);
194 } else if (!strcmp(dev_attr->attr.name, "client_monitor_latency")) {
195 return sprintf(buf, "%d\n", device_info.client_monitor_latency);
196 } else if (!strcmp(dev_attr->attr.name, "client_monitor_conn_id")) {
197 return sprintf(buf, "%d\n",
198 device_info.client_monitor_conn_id);
199 } else {
200 return 0;
204 /* Set up per device attributes in /sys/bus/vmbus/devices/<bus device> */
205 static struct device_attribute vmbus_device_attrs[] = {
206 __ATTR(id, S_IRUGO, vmbus_show_device_attr, NULL),
207 __ATTR(state, S_IRUGO, vmbus_show_device_attr, NULL),
208 __ATTR(class_id, S_IRUGO, vmbus_show_device_attr, NULL),
209 __ATTR(device_id, S_IRUGO, vmbus_show_device_attr, NULL),
210 __ATTR(monitor_id, S_IRUGO, vmbus_show_device_attr, NULL),
212 __ATTR(server_monitor_pending, S_IRUGO, vmbus_show_device_attr, NULL),
213 __ATTR(server_monitor_latency, S_IRUGO, vmbus_show_device_attr, NULL),
214 __ATTR(server_monitor_conn_id, S_IRUGO, vmbus_show_device_attr, NULL),
216 __ATTR(client_monitor_pending, S_IRUGO, vmbus_show_device_attr, NULL),
217 __ATTR(client_monitor_latency, S_IRUGO, vmbus_show_device_attr, NULL),
218 __ATTR(client_monitor_conn_id, S_IRUGO, vmbus_show_device_attr, NULL),
220 __ATTR(out_intr_mask, S_IRUGO, vmbus_show_device_attr, NULL),
221 __ATTR(out_read_index, S_IRUGO, vmbus_show_device_attr, NULL),
222 __ATTR(out_write_index, S_IRUGO, vmbus_show_device_attr, NULL),
223 __ATTR(out_read_bytes_avail, S_IRUGO, vmbus_show_device_attr, NULL),
224 __ATTR(out_write_bytes_avail, S_IRUGO, vmbus_show_device_attr, NULL),
226 __ATTR(in_intr_mask, S_IRUGO, vmbus_show_device_attr, NULL),
227 __ATTR(in_read_index, S_IRUGO, vmbus_show_device_attr, NULL),
228 __ATTR(in_write_index, S_IRUGO, vmbus_show_device_attr, NULL),
229 __ATTR(in_read_bytes_avail, S_IRUGO, vmbus_show_device_attr, NULL),
230 __ATTR(in_write_bytes_avail, S_IRUGO, vmbus_show_device_attr, NULL),
231 __ATTR_NULL
236 * vmbus_uevent - add uevent for our device
238 * This routine is invoked when a device is added or removed on the vmbus to
239 * generate a uevent to udev in the userspace. The udev will then look at its
240 * rule and the uevent generated here to load the appropriate driver
242 static int vmbus_uevent(struct device *device, struct kobj_uevent_env *env)
244 struct hv_device *dev = device_to_hv_device(device);
245 int ret;
247 ret = add_uevent_var(env, "VMBUS_DEVICE_CLASS_GUID={"
248 "%02x%02x%02x%02x-%02x%02x-%02x%02x-"
249 "%02x%02x%02x%02x%02x%02x%02x%02x}",
250 dev->dev_type.data[3],
251 dev->dev_type.data[2],
252 dev->dev_type.data[1],
253 dev->dev_type.data[0],
254 dev->dev_type.data[5],
255 dev->dev_type.data[4],
256 dev->dev_type.data[7],
257 dev->dev_type.data[6],
258 dev->dev_type.data[8],
259 dev->dev_type.data[9],
260 dev->dev_type.data[10],
261 dev->dev_type.data[11],
262 dev->dev_type.data[12],
263 dev->dev_type.data[13],
264 dev->dev_type.data[14],
265 dev->dev_type.data[15]);
267 if (ret)
268 return ret;
270 ret = add_uevent_var(env, "VMBUS_DEVICE_DEVICE_GUID={"
271 "%02x%02x%02x%02x-%02x%02x-%02x%02x-"
272 "%02x%02x%02x%02x%02x%02x%02x%02x}",
273 dev->dev_instance.data[3],
274 dev->dev_instance.data[2],
275 dev->dev_instance.data[1],
276 dev->dev_instance.data[0],
277 dev->dev_instance.data[5],
278 dev->dev_instance.data[4],
279 dev->dev_instance.data[7],
280 dev->dev_instance.data[6],
281 dev->dev_instance.data[8],
282 dev->dev_instance.data[9],
283 dev->dev_instance.data[10],
284 dev->dev_instance.data[11],
285 dev->dev_instance.data[12],
286 dev->dev_instance.data[13],
287 dev->dev_instance.data[14],
288 dev->dev_instance.data[15]);
289 if (ret)
290 return ret;
292 return 0;
297 * vmbus_match - Attempt to match the specified device to the specified driver
299 static int vmbus_match(struct device *device, struct device_driver *driver)
301 int match = 0;
302 struct hv_driver *drv = drv_to_hv_drv(driver);
303 struct hv_device *hv_dev = device_to_hv_device(device);
305 /* We found our driver ? */
306 if (memcmp(&hv_dev->dev_type, &drv->dev_type,
307 sizeof(struct hv_guid)) == 0)
308 match = 1;
310 return match;
314 * vmbus_probe - Add the new vmbus's child device
316 static int vmbus_probe(struct device *child_device)
318 int ret = 0;
319 struct hv_driver *drv =
320 drv_to_hv_drv(child_device->driver);
321 struct hv_device *dev = device_to_hv_device(child_device);
323 if (drv->probe) {
324 ret = drv->probe(dev);
325 if (ret != 0)
326 pr_err("probe failed for device %s (%d)\n",
327 dev_name(child_device), ret);
329 } else {
330 pr_err("probe not set for driver %s\n",
331 dev_name(child_device));
332 ret = -ENODEV;
334 return ret;
338 * vmbus_remove - Remove a vmbus device
340 static int vmbus_remove(struct device *child_device)
342 int ret;
343 struct hv_driver *drv;
345 struct hv_device *dev = device_to_hv_device(child_device);
347 if (child_device->driver) {
348 drv = drv_to_hv_drv(child_device->driver);
350 if (drv->remove) {
351 ret = drv->remove(dev);
352 } else {
353 pr_err("remove not set for driver %s\n",
354 dev_name(child_device));
355 ret = -ENODEV;
359 return 0;
364 * vmbus_shutdown - Shutdown a vmbus device
366 static void vmbus_shutdown(struct device *child_device)
368 struct hv_driver *drv;
369 struct hv_device *dev = device_to_hv_device(child_device);
372 /* The device may not be attached yet */
373 if (!child_device->driver)
374 return;
376 drv = drv_to_hv_drv(child_device->driver);
378 if (drv->shutdown)
379 drv->shutdown(dev);
381 return;
386 * vmbus_device_release - Final callback release of the vmbus child device
388 static void vmbus_device_release(struct device *device)
390 struct hv_device *hv_dev = device_to_hv_device(device);
392 kfree(hv_dev);
396 /* The one and only one */
397 static struct bus_type hv_bus = {
398 .name = "vmbus",
399 .match = vmbus_match,
400 .shutdown = vmbus_shutdown,
401 .remove = vmbus_remove,
402 .probe = vmbus_probe,
403 .uevent = vmbus_uevent,
404 .dev_attrs = vmbus_device_attrs,
407 static const char *driver_name = "hyperv";
410 struct onmessage_work_context {
411 struct work_struct work;
412 struct hv_message msg;
415 static void vmbus_onmessage_work(struct work_struct *work)
417 struct onmessage_work_context *ctx;
419 ctx = container_of(work, struct onmessage_work_context,
420 work);
421 vmbus_onmessage(&ctx->msg);
422 kfree(ctx);
426 * vmbus_on_msg_dpc - DPC routine to handle messages from the hypervisior
428 static void vmbus_on_msg_dpc(unsigned long data)
430 int cpu = smp_processor_id();
431 void *page_addr = hv_context.synic_message_page[cpu];
432 struct hv_message *msg = (struct hv_message *)page_addr +
433 VMBUS_MESSAGE_SINT;
434 struct onmessage_work_context *ctx;
436 while (1) {
437 if (msg->header.message_type == HVMSG_NONE) {
438 /* no msg */
439 break;
440 } else {
441 ctx = kmalloc(sizeof(*ctx), GFP_ATOMIC);
442 if (ctx == NULL)
443 continue;
444 INIT_WORK(&ctx->work, vmbus_onmessage_work);
445 memcpy(&ctx->msg, msg, sizeof(*msg));
446 queue_work(vmbus_connection.work_queue, &ctx->work);
449 msg->header.message_type = HVMSG_NONE;
452 * Make sure the write to MessageType (ie set to
453 * HVMSG_NONE) happens before we read the
454 * MessagePending and EOMing. Otherwise, the EOMing
455 * will not deliver any more messages since there is
456 * no empty slot
458 smp_mb();
460 if (msg->header.message_flags.msg_pending) {
462 * This will cause message queue rescan to
463 * possibly deliver another msg from the
464 * hypervisor
466 wrmsrl(HV_X64_MSR_EOM, 0);
472 * vmbus_on_isr - ISR routine
474 static int vmbus_on_isr(void)
476 int ret = 0;
477 int cpu = smp_processor_id();
478 void *page_addr;
479 struct hv_message *msg;
480 union hv_synic_event_flags *event;
482 page_addr = hv_context.synic_message_page[cpu];
483 msg = (struct hv_message *)page_addr + VMBUS_MESSAGE_SINT;
485 /* Check if there are actual msgs to be process */
486 if (msg->header.message_type != HVMSG_NONE)
487 ret |= 0x1;
489 page_addr = hv_context.synic_event_page[cpu];
490 event = (union hv_synic_event_flags *)page_addr + VMBUS_MESSAGE_SINT;
492 /* Since we are a child, we only need to check bit 0 */
493 if (sync_test_and_clear_bit(0, (unsigned long *) &event->flags32[0]))
494 ret |= 0x2;
496 return ret;
500 static irqreturn_t vmbus_isr(int irq, void *dev_id)
502 int ret;
504 ret = vmbus_on_isr();
506 /* Schedules a dpc if necessary */
507 if (ret > 0) {
508 if (test_bit(0, (unsigned long *)&ret))
509 tasklet_schedule(&msg_dpc);
511 if (test_bit(1, (unsigned long *)&ret))
512 tasklet_schedule(&event_dpc);
514 return IRQ_HANDLED;
515 } else {
516 return IRQ_NONE;
521 * vmbus_bus_init -Main vmbus driver initialization routine.
523 * Here, we
524 * - initialize the vmbus driver context
525 * - invoke the vmbus hv main init routine
526 * - get the irq resource
527 * - retrieve the channel offers
529 static int vmbus_bus_init(int irq)
531 int ret;
532 unsigned int vector;
534 /* Hypervisor initialization...setup hypercall page..etc */
535 ret = hv_init();
536 if (ret != 0) {
537 pr_err("Unable to initialize the hypervisor - 0x%x\n", ret);
538 return ret;
541 /* Initialize the bus context */
542 tasklet_init(&msg_dpc, vmbus_on_msg_dpc, 0);
543 tasklet_init(&event_dpc, vmbus_on_event, 0);
545 /* Now, register the bus with LDM */
546 ret = bus_register(&hv_bus);
547 if (ret)
548 return ret;
550 /* Get the interrupt resource */
551 ret = request_irq(irq, vmbus_isr, IRQF_SAMPLE_RANDOM,
552 driver_name, hv_acpi_dev);
554 if (ret != 0) {
555 pr_err("Unable to request IRQ %d\n",
556 irq);
558 bus_unregister(&hv_bus);
560 return ret;
563 vector = IRQ0_VECTOR + irq;
566 * Notify the hypervisor of our irq and
567 * connect to the host.
569 on_each_cpu(hv_synic_init, (void *)&vector, 1);
570 ret = vmbus_connect();
571 if (ret) {
572 free_irq(irq, hv_acpi_dev);
573 bus_unregister(&hv_bus);
574 return ret;
578 vmbus_request_offers();
580 return 0;
584 * vmbus_child_driver_register() - Register a vmbus's child driver
585 * @drv: Pointer to driver structure you want to register
588 * Registers the given driver with Linux through the 'driver_register()' call
589 * And sets up the hyper-v vmbus handling for this driver.
590 * It will return the state of the 'driver_register()' call.
592 * Mainly used by Hyper-V drivers.
594 int vmbus_child_driver_register(struct device_driver *drv)
596 int ret;
598 pr_info("child driver registering - name %s\n", drv->name);
600 /* The child driver on this vmbus */
601 drv->bus = &hv_bus;
603 ret = driver_register(drv);
605 vmbus_request_offers();
607 return ret;
609 EXPORT_SYMBOL(vmbus_child_driver_register);
612 * vmbus_child_driver_unregister() - Unregister a vmbus's child driver
613 * @drv: Pointer to driver structure you want to un-register
616 * Un-register the given driver with Linux through the 'driver_unregister()'
617 * call. And ungegisters the driver from the Hyper-V vmbus handler.
619 * Mainly used by Hyper-V drivers.
621 void vmbus_child_driver_unregister(struct device_driver *drv)
623 pr_info("child driver unregistering - name %s\n", drv->name);
625 driver_unregister(drv);
628 EXPORT_SYMBOL(vmbus_child_driver_unregister);
631 * vmbus_child_device_create - Creates and registers a new child device
632 * on the vmbus.
634 struct hv_device *vmbus_child_device_create(struct hv_guid *type,
635 struct hv_guid *instance,
636 struct vmbus_channel *channel)
638 struct hv_device *child_device_obj;
640 /* Allocate the new child device */
641 child_device_obj = kzalloc(sizeof(struct hv_device), GFP_KERNEL);
642 if (!child_device_obj) {
643 pr_err("Unable to allocate device object for child device\n");
644 return NULL;
647 child_device_obj->channel = channel;
648 memcpy(&child_device_obj->dev_type, type, sizeof(struct hv_guid));
649 memcpy(&child_device_obj->dev_instance, instance,
650 sizeof(struct hv_guid));
653 return child_device_obj;
657 * vmbus_child_device_register - Register the child device
659 int vmbus_child_device_register(struct hv_device *child_device_obj)
661 int ret = 0;
663 static atomic_t device_num = ATOMIC_INIT(0);
665 /* Set the device name. Otherwise, device_register() will fail. */
666 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
667 atomic_inc_return(&device_num));
669 /* The new device belongs to this bus */
670 child_device_obj->device.bus = &hv_bus; /* device->dev.bus; */
671 child_device_obj->device.parent = &hv_acpi_dev->dev;
672 child_device_obj->device.release = vmbus_device_release;
675 * Register with the LDM. This will kick off the driver/device
676 * binding...which will eventually call vmbus_match() and vmbus_probe()
678 ret = device_register(&child_device_obj->device);
680 if (ret)
681 pr_err("Unable to register child device\n");
682 else
683 pr_info("child device %s registered\n",
684 dev_name(&child_device_obj->device));
686 return ret;
690 * vmbus_child_device_unregister - Remove the specified child device
691 * from the vmbus.
693 void vmbus_child_device_unregister(struct hv_device *device_obj)
696 * Kick off the process of unregistering the device.
697 * This will call vmbus_remove() and eventually vmbus_device_release()
699 device_unregister(&device_obj->device);
701 pr_info("child device %s unregistered\n",
702 dev_name(&device_obj->device));
707 * VMBUS is an acpi enumerated device. Get the the IRQ information
708 * from DSDT.
711 static acpi_status vmbus_walk_resources(struct acpi_resource *res, void *irq)
714 if (res->type == ACPI_RESOURCE_TYPE_IRQ) {
715 struct acpi_resource_irq *irqp;
716 irqp = &res->data.irq;
718 *((unsigned int *)irq) = irqp->interrupts[0];
721 return AE_OK;
724 static int vmbus_acpi_add(struct acpi_device *device)
726 acpi_status result;
728 hv_acpi_dev = device;
730 result =
731 acpi_walk_resources(device->handle, METHOD_NAME__CRS,
732 vmbus_walk_resources, &irq);
734 if (ACPI_FAILURE(result)) {
735 complete(&probe_event);
736 return -ENODEV;
738 complete(&probe_event);
739 return 0;
742 static const struct acpi_device_id vmbus_acpi_device_ids[] = {
743 {"VMBUS", 0},
744 {"VMBus", 0},
745 {"", 0},
747 MODULE_DEVICE_TABLE(acpi, vmbus_acpi_device_ids);
749 static struct acpi_driver vmbus_acpi_driver = {
750 .name = "vmbus",
751 .ids = vmbus_acpi_device_ids,
752 .ops = {
753 .add = vmbus_acpi_add,
758 * We use a PCI table to determine if we should autoload this driver This is
759 * needed by distro tools to determine if the hyperv drivers should be
760 * installed and/or configured. We don't do anything else with the table, but
761 * it needs to be present.
763 static const struct pci_device_id microsoft_hv_pci_table[] = {
764 { PCI_DEVICE(0x1414, 0x5353) }, /* VGA compatible controller */
765 { 0 }
767 MODULE_DEVICE_TABLE(pci, microsoft_hv_pci_table);
769 static int __init hv_acpi_init(void)
771 int ret;
773 init_completion(&probe_event);
776 * Get irq resources first.
779 ret = acpi_bus_register_driver(&vmbus_acpi_driver);
781 if (ret)
782 return ret;
784 wait_for_completion(&probe_event);
786 if (irq <= 0) {
787 acpi_bus_unregister_driver(&vmbus_acpi_driver);
788 return -ENODEV;
791 return vmbus_bus_init(irq);
795 MODULE_LICENSE("GPL");
796 MODULE_VERSION(HV_DRV_VERSION);
797 module_param(vmbus_loglevel, int, S_IRUGO|S_IWUSR);
799 module_init(hv_acpi_init);