Staging: hv: vmbus: VMBUS is an ACPI enumerated device, get rid of the PCI signature
[deliverable/linux.git] / drivers / staging / hv / vmbus_drv.c
CommitLineData
3e7ee490 1/*
3e7ee490
HJ
2 * Copyright (c) 2009, Microsoft Corporation.
3 *
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.
7 *
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.
12 *
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.
16 *
17 * Authors:
18 * Haiyang Zhang <haiyangz@microsoft.com>
19 * Hank Janssen <hjanssen@microsoft.com>
b0069f43 20 * K. Y. Srinivasan <kys@microsoft.com>
52e5c1ce 21 *
3e7ee490 22 */
0a46618d
HJ
23#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
24
3e7ee490
HJ
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>
c22090fa 31#include <linux/dmi.h>
5a0e3ad6 32#include <linux/slab.h>
b0069f43
S
33#include <linux/acpi.h>
34#include <acpi/acpi_bus.h>
8b5d6d3b 35#include <linux/completion.h>
3f335ea2
S
36
37#include "hyperv.h"
0f2a6619 38#include "hyperv_vmbus.h"
3e7ee490 39
3e7ee490 40
607c1a11 41static struct acpi_device *hv_acpi_dev;
1168ac22 42
59c0e4f0 43static struct tasklet_struct msg_dpc;
66d9229c 44static struct tasklet_struct event_dpc;
59c0e4f0 45
98db4335
S
46unsigned int vmbus_loglevel = (ALL_MODULES << 16 | INFO_LVL);
47EXPORT_SYMBOL(vmbus_loglevel);
48 /* (ALL_MODULES << 16 | DEBUG_LVL_ENTEREXIT); */
49 /* (((VMBUS | VMBUS_DRV)<<16) | DEBUG_LVL_ENTEREXIT); */
50
71a6655d 51static struct completion probe_event;
b0069f43 52static int irq;
98db4335
S
53
54static void get_channel_info(struct hv_device *device,
55 struct hv_device_info *info)
56{
57 struct vmbus_channel_debug_info debug_info;
58
59 if (!device->channel)
60 return;
61
62 vmbus_get_debug_info(device->channel, &debug_info);
63
64 info->chn_id = debug_info.relid;
65 info->chn_state = debug_info.state;
66 memcpy(&info->chn_type, &debug_info.interfacetype,
67 sizeof(struct hv_guid));
68 memcpy(&info->chn_instance, &debug_info.interface_instance,
69 sizeof(struct hv_guid));
70
71 info->monitor_id = debug_info.monitorid;
72
73 info->server_monitor_pending = debug_info.servermonitor_pending;
74 info->server_monitor_latency = debug_info.servermonitor_latency;
75 info->server_monitor_conn_id = debug_info.servermonitor_connectionid;
76
77 info->client_monitor_pending = debug_info.clientmonitor_pending;
78 info->client_monitor_latency = debug_info.clientmonitor_latency;
79 info->client_monitor_conn_id = debug_info.clientmonitor_connectionid;
80
81 info->inbound.int_mask = debug_info.inbound.current_interrupt_mask;
82 info->inbound.read_idx = debug_info.inbound.current_read_index;
83 info->inbound.write_idx = debug_info.inbound.current_write_index;
84 info->inbound.bytes_avail_toread =
85 debug_info.inbound.bytes_avail_toread;
86 info->inbound.bytes_avail_towrite =
87 debug_info.inbound.bytes_avail_towrite;
3e7ee490 88
98db4335
S
89 info->outbound.int_mask =
90 debug_info.outbound.current_interrupt_mask;
91 info->outbound.read_idx = debug_info.outbound.current_read_index;
92 info->outbound.write_idx = debug_info.outbound.current_write_index;
93 info->outbound.bytes_avail_toread =
94 debug_info.outbound.bytes_avail_toread;
95 info->outbound.bytes_avail_towrite =
96 debug_info.outbound.bytes_avail_towrite;
97}
3e7ee490 98
98db4335
S
99/*
100 * vmbus_show_device_attr - Show the device attribute in sysfs.
101 *
102 * This is invoked when user does a
103 * "cat /sys/bus/vmbus/devices/<busdevice>/<attr name>"
104 */
90c9960e
GKH
105static ssize_t vmbus_show_device_attr(struct device *dev,
106 struct device_attribute *dev_attr,
98db4335
S
107 char *buf)
108{
e8e27047 109 struct hv_device *hv_dev = device_to_hv_device(dev);
98db4335 110 struct hv_device_info device_info;
3e7ee490 111
98db4335 112 memset(&device_info, 0, sizeof(struct hv_device_info));
3e7ee490 113
e8e27047 114 get_channel_info(hv_dev, &device_info);
3e7ee490 115
98db4335
S
116 if (!strcmp(dev_attr->attr.name, "class_id")) {
117 return sprintf(buf, "{%02x%02x%02x%02x-%02x%02x-%02x%02x-"
118 "%02x%02x%02x%02x%02x%02x%02x%02x}\n",
119 device_info.chn_type.data[3],
120 device_info.chn_type.data[2],
121 device_info.chn_type.data[1],
122 device_info.chn_type.data[0],
123 device_info.chn_type.data[5],
124 device_info.chn_type.data[4],
125 device_info.chn_type.data[7],
126 device_info.chn_type.data[6],
127 device_info.chn_type.data[8],
128 device_info.chn_type.data[9],
129 device_info.chn_type.data[10],
130 device_info.chn_type.data[11],
131 device_info.chn_type.data[12],
132 device_info.chn_type.data[13],
133 device_info.chn_type.data[14],
134 device_info.chn_type.data[15]);
135 } else if (!strcmp(dev_attr->attr.name, "device_id")) {
136 return sprintf(buf, "{%02x%02x%02x%02x-%02x%02x-%02x%02x-"
137 "%02x%02x%02x%02x%02x%02x%02x%02x}\n",
138 device_info.chn_instance.data[3],
139 device_info.chn_instance.data[2],
140 device_info.chn_instance.data[1],
141 device_info.chn_instance.data[0],
142 device_info.chn_instance.data[5],
143 device_info.chn_instance.data[4],
144 device_info.chn_instance.data[7],
145 device_info.chn_instance.data[6],
146 device_info.chn_instance.data[8],
147 device_info.chn_instance.data[9],
148 device_info.chn_instance.data[10],
149 device_info.chn_instance.data[11],
150 device_info.chn_instance.data[12],
151 device_info.chn_instance.data[13],
152 device_info.chn_instance.data[14],
153 device_info.chn_instance.data[15]);
154 } else if (!strcmp(dev_attr->attr.name, "state")) {
155 return sprintf(buf, "%d\n", device_info.chn_state);
156 } else if (!strcmp(dev_attr->attr.name, "id")) {
157 return sprintf(buf, "%d\n", device_info.chn_id);
158 } else if (!strcmp(dev_attr->attr.name, "out_intr_mask")) {
159 return sprintf(buf, "%d\n", device_info.outbound.int_mask);
160 } else if (!strcmp(dev_attr->attr.name, "out_read_index")) {
161 return sprintf(buf, "%d\n", device_info.outbound.read_idx);
162 } else if (!strcmp(dev_attr->attr.name, "out_write_index")) {
163 return sprintf(buf, "%d\n", device_info.outbound.write_idx);
164 } else if (!strcmp(dev_attr->attr.name, "out_read_bytes_avail")) {
165 return sprintf(buf, "%d\n",
166 device_info.outbound.bytes_avail_toread);
167 } else if (!strcmp(dev_attr->attr.name, "out_write_bytes_avail")) {
168 return sprintf(buf, "%d\n",
169 device_info.outbound.bytes_avail_towrite);
170 } else if (!strcmp(dev_attr->attr.name, "in_intr_mask")) {
171 return sprintf(buf, "%d\n", device_info.inbound.int_mask);
172 } else if (!strcmp(dev_attr->attr.name, "in_read_index")) {
173 return sprintf(buf, "%d\n", device_info.inbound.read_idx);
174 } else if (!strcmp(dev_attr->attr.name, "in_write_index")) {
175 return sprintf(buf, "%d\n", device_info.inbound.write_idx);
176 } else if (!strcmp(dev_attr->attr.name, "in_read_bytes_avail")) {
177 return sprintf(buf, "%d\n",
178 device_info.inbound.bytes_avail_toread);
179 } else if (!strcmp(dev_attr->attr.name, "in_write_bytes_avail")) {
180 return sprintf(buf, "%d\n",
181 device_info.inbound.bytes_avail_towrite);
182 } else if (!strcmp(dev_attr->attr.name, "monitor_id")) {
183 return sprintf(buf, "%d\n", device_info.monitor_id);
184 } else if (!strcmp(dev_attr->attr.name, "server_monitor_pending")) {
185 return sprintf(buf, "%d\n", device_info.server_monitor_pending);
186 } else if (!strcmp(dev_attr->attr.name, "server_monitor_latency")) {
187 return sprintf(buf, "%d\n", device_info.server_monitor_latency);
188 } else if (!strcmp(dev_attr->attr.name, "server_monitor_conn_id")) {
189 return sprintf(buf, "%d\n",
190 device_info.server_monitor_conn_id);
191 } else if (!strcmp(dev_attr->attr.name, "client_monitor_pending")) {
192 return sprintf(buf, "%d\n", device_info.client_monitor_pending);
193 } else if (!strcmp(dev_attr->attr.name, "client_monitor_latency")) {
194 return sprintf(buf, "%d\n", device_info.client_monitor_latency);
195 } else if (!strcmp(dev_attr->attr.name, "client_monitor_conn_id")) {
196 return sprintf(buf, "%d\n",
197 device_info.client_monitor_conn_id);
198 } else {
199 return 0;
200 }
201}
3e7ee490 202
454f18a9 203/* Set up per device attributes in /sys/bus/vmbus/devices/<bus device> */
3e7ee490
HJ
204static struct device_attribute vmbus_device_attrs[] = {
205 __ATTR(id, S_IRUGO, vmbus_show_device_attr, NULL),
206 __ATTR(state, S_IRUGO, vmbus_show_device_attr, NULL),
207 __ATTR(class_id, S_IRUGO, vmbus_show_device_attr, NULL),
208 __ATTR(device_id, S_IRUGO, vmbus_show_device_attr, NULL),
209 __ATTR(monitor_id, S_IRUGO, vmbus_show_device_attr, NULL),
210
211 __ATTR(server_monitor_pending, S_IRUGO, vmbus_show_device_attr, NULL),
212 __ATTR(server_monitor_latency, S_IRUGO, vmbus_show_device_attr, NULL),
213 __ATTR(server_monitor_conn_id, S_IRUGO, vmbus_show_device_attr, NULL),
214
215 __ATTR(client_monitor_pending, S_IRUGO, vmbus_show_device_attr, NULL),
216 __ATTR(client_monitor_latency, S_IRUGO, vmbus_show_device_attr, NULL),
217 __ATTR(client_monitor_conn_id, S_IRUGO, vmbus_show_device_attr, NULL),
218
219 __ATTR(out_intr_mask, S_IRUGO, vmbus_show_device_attr, NULL),
220 __ATTR(out_read_index, S_IRUGO, vmbus_show_device_attr, NULL),
221 __ATTR(out_write_index, S_IRUGO, vmbus_show_device_attr, NULL),
222 __ATTR(out_read_bytes_avail, S_IRUGO, vmbus_show_device_attr, NULL),
223 __ATTR(out_write_bytes_avail, S_IRUGO, vmbus_show_device_attr, NULL),
224
225 __ATTR(in_intr_mask, S_IRUGO, vmbus_show_device_attr, NULL),
226 __ATTR(in_read_index, S_IRUGO, vmbus_show_device_attr, NULL),
227 __ATTR(in_write_index, S_IRUGO, vmbus_show_device_attr, NULL),
228 __ATTR(in_read_bytes_avail, S_IRUGO, vmbus_show_device_attr, NULL),
229 __ATTR(in_write_bytes_avail, S_IRUGO, vmbus_show_device_attr, NULL),
230 __ATTR_NULL
231};
3e7ee490 232
793be9c7 233
adde2487
S
234/*
235 * vmbus_uevent - add uevent for our device
236 *
237 * This routine is invoked when a device is added or removed on the vmbus to
238 * generate a uevent to udev in the userspace. The udev will then look at its
239 * rule and the uevent generated here to load the appropriate driver
240 */
241static int vmbus_uevent(struct device *device, struct kobj_uevent_env *env)
242{
243 struct hv_device *dev = device_to_hv_device(device);
244 int ret;
245
adde2487
S
246 ret = add_uevent_var(env, "VMBUS_DEVICE_CLASS_GUID={"
247 "%02x%02x%02x%02x-%02x%02x-%02x%02x-"
248 "%02x%02x%02x%02x%02x%02x%02x%02x}",
249 dev->dev_type.data[3],
250 dev->dev_type.data[2],
251 dev->dev_type.data[1],
252 dev->dev_type.data[0],
253 dev->dev_type.data[5],
254 dev->dev_type.data[4],
255 dev->dev_type.data[7],
256 dev->dev_type.data[6],
257 dev->dev_type.data[8],
258 dev->dev_type.data[9],
259 dev->dev_type.data[10],
260 dev->dev_type.data[11],
261 dev->dev_type.data[12],
262 dev->dev_type.data[13],
263 dev->dev_type.data[14],
264 dev->dev_type.data[15]);
265
266 if (ret)
267 return ret;
268
269 ret = add_uevent_var(env, "VMBUS_DEVICE_DEVICE_GUID={"
270 "%02x%02x%02x%02x-%02x%02x-%02x%02x-"
271 "%02x%02x%02x%02x%02x%02x%02x%02x}",
272 dev->dev_instance.data[3],
273 dev->dev_instance.data[2],
274 dev->dev_instance.data[1],
275 dev->dev_instance.data[0],
276 dev->dev_instance.data[5],
277 dev->dev_instance.data[4],
278 dev->dev_instance.data[7],
279 dev->dev_instance.data[6],
280 dev->dev_instance.data[8],
281 dev->dev_instance.data[9],
282 dev->dev_instance.data[10],
283 dev->dev_instance.data[11],
284 dev->dev_instance.data[12],
285 dev->dev_instance.data[13],
286 dev->dev_instance.data[14],
287 dev->dev_instance.data[15]);
288 if (ret)
289 return ret;
290
291 return 0;
292}
293
b7fc147b
S
294
295/*
296 * vmbus_match - Attempt to match the specified device to the specified driver
297 */
298static int vmbus_match(struct device *device, struct device_driver *driver)
299{
300 int match = 0;
301 struct hv_driver *drv = drv_to_hv_drv(driver);
e8e27047 302 struct hv_device *hv_dev = device_to_hv_device(device);
b7fc147b
S
303
304 /* We found our driver ? */
e8e27047 305 if (memcmp(&hv_dev->dev_type, &drv->dev_type,
de632a2b 306 sizeof(struct hv_guid)) == 0)
b7fc147b 307 match = 1;
de632a2b 308
b7fc147b
S
309 return match;
310}
311
f1f0d67b
S
312/*
313 * vmbus_probe - Add the new vmbus's child device
314 */
315static int vmbus_probe(struct device *child_device)
316{
317 int ret = 0;
318 struct hv_driver *drv =
319 drv_to_hv_drv(child_device->driver);
9efd21e1 320 struct hv_device *dev = device_to_hv_device(child_device);
f1f0d67b 321
9efd21e1
S
322 if (drv->probe) {
323 ret = drv->probe(dev);
b14a7b30 324 if (ret != 0)
0a46618d
HJ
325 pr_err("probe failed for device %s (%d)\n",
326 dev_name(child_device), ret);
f1f0d67b 327
f1f0d67b 328 } else {
0a46618d
HJ
329 pr_err("probe not set for driver %s\n",
330 dev_name(child_device));
6de925b1 331 ret = -ENODEV;
f1f0d67b
S
332 }
333 return ret;
334}
335
c5dce3db
S
336/*
337 * vmbus_remove - Remove a vmbus device
338 */
339static int vmbus_remove(struct device *child_device)
340{
341 int ret;
342 struct hv_driver *drv;
343
415b023a 344 struct hv_device *dev = device_to_hv_device(child_device);
c5dce3db
S
345
346 if (child_device->driver) {
347 drv = drv_to_hv_drv(child_device->driver);
348
415b023a
S
349 if (drv->remove) {
350 ret = drv->remove(dev);
c5dce3db 351 } else {
0a46618d
HJ
352 pr_err("remove not set for driver %s\n",
353 dev_name(child_device));
6de925b1 354 ret = -ENODEV;
c5dce3db
S
355 }
356 }
357
358 return 0;
359}
360
eb1bb259
S
361
362/*
363 * vmbus_shutdown - Shutdown a vmbus device
364 */
365static void vmbus_shutdown(struct device *child_device)
366{
367 struct hv_driver *drv;
ca6887fb 368 struct hv_device *dev = device_to_hv_device(child_device);
eb1bb259
S
369
370
371 /* The device may not be attached yet */
372 if (!child_device->driver)
373 return;
374
375 drv = drv_to_hv_drv(child_device->driver);
376
ca6887fb
S
377 if (drv->shutdown)
378 drv->shutdown(dev);
eb1bb259
S
379
380 return;
381}
382
086e7a56
S
383
384/*
385 * vmbus_device_release - Final callback release of the vmbus child device
386 */
387static void vmbus_device_release(struct device *device)
388{
e8e27047 389 struct hv_device *hv_dev = device_to_hv_device(device);
086e7a56 390
e8e27047 391 kfree(hv_dev);
086e7a56
S
392
393}
394
454f18a9 395/* The one and only one */
9adcac5c
S
396static struct bus_type hv_bus = {
397 .name = "vmbus",
398 .match = vmbus_match,
399 .shutdown = vmbus_shutdown,
400 .remove = vmbus_remove,
401 .probe = vmbus_probe,
402 .uevent = vmbus_uevent,
403 .dev_attrs = vmbus_device_attrs,
3e7ee490
HJ
404};
405
adf874cb 406static const char *driver_name = "hyperv";
36199a99 407
36199a99 408
bf6506f6
TT
409struct onmessage_work_context {
410 struct work_struct work;
411 struct hv_message msg;
412};
413
414static void vmbus_onmessage_work(struct work_struct *work)
415{
416 struct onmessage_work_context *ctx;
417
418 ctx = container_of(work, struct onmessage_work_context,
419 work);
420 vmbus_onmessage(&ctx->msg);
421 kfree(ctx);
422}
423
36199a99
GKH
424/*
425 * vmbus_on_msg_dpc - DPC routine to handle messages from the hypervisior
426 */
62c1059d 427static void vmbus_on_msg_dpc(unsigned long data)
36199a99
GKH
428{
429 int cpu = smp_processor_id();
430 void *page_addr = hv_context.synic_message_page[cpu];
431 struct hv_message *msg = (struct hv_message *)page_addr +
432 VMBUS_MESSAGE_SINT;
bf6506f6 433 struct onmessage_work_context *ctx;
36199a99
GKH
434
435 while (1) {
436 if (msg->header.message_type == HVMSG_NONE) {
437 /* no msg */
438 break;
439 } else {
bf6506f6
TT
440 ctx = kmalloc(sizeof(*ctx), GFP_ATOMIC);
441 if (ctx == NULL)
36199a99 442 continue;
bf6506f6
TT
443 INIT_WORK(&ctx->work, vmbus_onmessage_work);
444 memcpy(&ctx->msg, msg, sizeof(*msg));
da9fcb72 445 queue_work(vmbus_connection.work_queue, &ctx->work);
36199a99
GKH
446 }
447
448 msg->header.message_type = HVMSG_NONE;
449
450 /*
451 * Make sure the write to MessageType (ie set to
452 * HVMSG_NONE) happens before we read the
453 * MessagePending and EOMing. Otherwise, the EOMing
454 * will not deliver any more messages since there is
455 * no empty slot
456 */
e826f1d5 457 smp_mb();
36199a99
GKH
458
459 if (msg->header.message_flags.msg_pending) {
460 /*
461 * This will cause message queue rescan to
462 * possibly deliver another msg from the
463 * hypervisor
464 */
465 wrmsrl(HV_X64_MSR_EOM, 0);
466 }
467 }
468}
469
36199a99
GKH
470/*
471 * vmbus_on_isr - ISR routine
472 */
480ae58d 473static int vmbus_on_isr(void)
36199a99
GKH
474{
475 int ret = 0;
476 int cpu = smp_processor_id();
477 void *page_addr;
478 struct hv_message *msg;
479 union hv_synic_event_flags *event;
480
481 page_addr = hv_context.synic_message_page[cpu];
482 msg = (struct hv_message *)page_addr + VMBUS_MESSAGE_SINT;
483
484 /* Check if there are actual msgs to be process */
98e08702 485 if (msg->header.message_type != HVMSG_NONE)
36199a99 486 ret |= 0x1;
36199a99 487
36199a99
GKH
488 page_addr = hv_context.synic_event_page[cpu];
489 event = (union hv_synic_event_flags *)page_addr + VMBUS_MESSAGE_SINT;
490
491 /* Since we are a child, we only need to check bit 0 */
32235b07 492 if (sync_test_and_clear_bit(0, (unsigned long *) &event->flags32[0]))
36199a99 493 ret |= 0x2;
36199a99
GKH
494
495 return ret;
496}
497
793be9c7
S
498
499static irqreturn_t vmbus_isr(int irq, void *dev_id)
500{
501 int ret;
502
503 ret = vmbus_on_isr();
504
505 /* Schedules a dpc if necessary */
506 if (ret > 0) {
507 if (test_bit(0, (unsigned long *)&ret))
59c0e4f0 508 tasklet_schedule(&msg_dpc);
793be9c7
S
509
510 if (test_bit(1, (unsigned long *)&ret))
66d9229c 511 tasklet_schedule(&event_dpc);
793be9c7
S
512
513 return IRQ_HANDLED;
514 } else {
515 return IRQ_NONE;
516 }
517}
518
3e189519 519/*
90c9960e
GKH
520 * vmbus_bus_init -Main vmbus driver initialization routine.
521 *
522 * Here, we
0686e4f4 523 * - initialize the vmbus driver context
0686e4f4
LL
524 * - invoke the vmbus hv main init routine
525 * - get the irq resource
0686e4f4 526 * - retrieve the channel offers
90c9960e 527 */
9aaa995e 528static int vmbus_bus_init(int irq)
3e7ee490 529{
90c9960e
GKH
530 int ret;
531 unsigned int vector;
3e7ee490 532
6d26e38f
GKH
533 /* Hypervisor initialization...setup hypercall page..etc */
534 ret = hv_init();
90c9960e 535 if (ret != 0) {
0a46618d 536 pr_err("Unable to initialize the hypervisor - 0x%x\n", ret);
d6c1c5de 537 return ret;
3e7ee490
HJ
538 }
539
454f18a9 540 /* Initialize the bus context */
59c0e4f0 541 tasklet_init(&msg_dpc, vmbus_on_msg_dpc, 0);
66d9229c 542 tasklet_init(&event_dpc, vmbus_on_event, 0);
3e7ee490 543
a6e4d8e3 544 /* Now, register the bus with LDM */
9adcac5c 545 ret = bus_register(&hv_bus);
d6c1c5de
S
546 if (ret)
547 return ret;
3e7ee490 548
454f18a9 549 /* Get the interrupt resource */
3d2de267 550 ret = request_irq(irq, vmbus_isr, IRQF_SAMPLE_RANDOM,
607c1a11 551 driver_name, hv_acpi_dev);
3e7ee490 552
90c9960e 553 if (ret != 0) {
0a46618d 554 pr_err("Unable to request IRQ %d\n",
9aaa995e 555 irq);
3e7ee490 556
9adcac5c 557 bus_unregister(&hv_bus);
3e7ee490 558
d6c1c5de 559 return ret;
3e7ee490 560 }
3e7ee490 561
9aaa995e 562 vector = IRQ0_VECTOR + irq;
3e7ee490 563
800b6902
S
564 /*
565 * Notify the hypervisor of our irq and
566 * connect to the host.
567 */
568 on_each_cpu(hv_synic_init, (void *)&vector, 1);
569 ret = vmbus_connect();
90c9960e 570 if (ret) {
607c1a11 571 free_irq(irq, hv_acpi_dev);
9adcac5c 572 bus_unregister(&hv_bus);
d6c1c5de 573 return ret;
5d48a1c2
BP
574 }
575
800b6902 576
2d6e882b 577 vmbus_request_offers();
8b5d6d3b 578
d6c1c5de 579 return 0;
3e7ee490
HJ
580}
581
90c9960e 582/**
3e189519 583 * vmbus_child_driver_register() - Register a vmbus's child driver
c643269d 584 * @drv: Pointer to driver structure you want to register
3e189519 585 *
3e189519
HJ
586 *
587 * Registers the given driver with Linux through the 'driver_register()' call
588 * And sets up the hyper-v vmbus handling for this driver.
589 * It will return the state of the 'driver_register()' call.
590 *
591 * Mainly used by Hyper-V drivers.
90c9960e 592 */
c643269d 593int vmbus_child_driver_register(struct device_driver *drv)
3e7ee490 594{
5d48a1c2 595 int ret;
3e7ee490 596
0a46618d 597 pr_info("child driver registering - name %s\n", drv->name);
3e7ee490 598
454f18a9 599 /* The child driver on this vmbus */
9adcac5c 600 drv->bus = &hv_bus;
3e7ee490 601
c643269d 602 ret = driver_register(drv);
3e7ee490 603
2d6e882b 604 vmbus_request_offers();
3e7ee490 605
5d48a1c2 606 return ret;
3e7ee490 607}
3e7ee490
HJ
608EXPORT_SYMBOL(vmbus_child_driver_register);
609
90c9960e 610/**
3e189519 611 * vmbus_child_driver_unregister() - Unregister a vmbus's child driver
06de23f7 612 * @drv: Pointer to driver structure you want to un-register
3e189519 613 *
3e189519
HJ
614 *
615 * Un-register the given driver with Linux through the 'driver_unregister()'
616 * call. And ungegisters the driver from the Hyper-V vmbus handler.
617 *
618 * Mainly used by Hyper-V drivers.
90c9960e 619 */
06de23f7 620void vmbus_child_driver_unregister(struct device_driver *drv)
3e7ee490 621{
0a46618d 622 pr_info("child driver unregistering - name %s\n", drv->name);
3e7ee490 623
06de23f7 624 driver_unregister(drv);
3e7ee490 625
3e7ee490 626}
3e7ee490
HJ
627EXPORT_SYMBOL(vmbus_child_driver_unregister);
628
3e189519
HJ
629/*
630 * vmbus_child_device_create - Creates and registers a new child device
631 * on the vmbus.
90c9960e 632 */
89733aa9
GKH
633struct hv_device *vmbus_child_device_create(struct hv_guid *type,
634 struct hv_guid *instance,
635 struct vmbus_channel *channel)
3e7ee490 636{
3d3b5518 637 struct hv_device *child_device_obj;
3e7ee490 638
454f18a9 639 /* Allocate the new child device */
6bad88da
S
640 child_device_obj = kzalloc(sizeof(struct hv_device), GFP_KERNEL);
641 if (!child_device_obj) {
0a46618d 642 pr_err("Unable to allocate device object for child device\n");
3e7ee490
HJ
643 return NULL;
644 }
645
cae5b843 646 child_device_obj->channel = channel;
ca623ad3
HZ
647 memcpy(&child_device_obj->dev_type, type, sizeof(struct hv_guid));
648 memcpy(&child_device_obj->dev_instance, instance,
90c9960e 649 sizeof(struct hv_guid));
3e7ee490 650
3e7ee490 651
3e7ee490
HJ
652 return child_device_obj;
653}
654
3e189519 655/*
e13a0b5a 656 * vmbus_child_device_register - Register the child device
90c9960e 657 */
3ca07cb0 658int vmbus_child_device_register(struct hv_device *child_device_obj)
3e7ee490 659{
90c9960e 660 int ret = 0;
6bad88da 661
f4888417 662 static atomic_t device_num = ATOMIC_INIT(0);
3e7ee490 663
1bb40a25 664 /* Set the device name. Otherwise, device_register() will fail. */
6bad88da 665 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
90c9960e 666 atomic_inc_return(&device_num));
3e7ee490 667
454f18a9 668 /* The new device belongs to this bus */
9adcac5c 669 child_device_obj->device.bus = &hv_bus; /* device->dev.bus; */
607c1a11 670 child_device_obj->device.parent = &hv_acpi_dev->dev;
6bad88da 671 child_device_obj->device.release = vmbus_device_release;
3e7ee490 672
90c9960e
GKH
673 /*
674 * Register with the LDM. This will kick off the driver/device
675 * binding...which will eventually call vmbus_match() and vmbus_probe()
676 */
6bad88da 677 ret = device_register(&child_device_obj->device);
3e7ee490 678
3e7ee490 679 if (ret)
0a46618d 680 pr_err("Unable to register child device\n");
3e7ee490 681 else
0a46618d
HJ
682 pr_info("child device %s registered\n",
683 dev_name(&child_device_obj->device));
3e7ee490 684
3e7ee490
HJ
685 return ret;
686}
687
3e189519
HJ
688/*
689 * vmbus_child_device_unregister - Remove the specified child device
690 * from the vmbus.
90c9960e 691 */
9d8bd71a 692void vmbus_child_device_unregister(struct hv_device *device_obj)
3e7ee490 693{
90c9960e
GKH
694 /*
695 * Kick off the process of unregistering the device.
696 * This will call vmbus_remove() and eventually vmbus_device_release()
697 */
6bad88da 698 device_unregister(&device_obj->device);
3e7ee490 699
0a46618d
HJ
700 pr_info("child device %s unregistered\n",
701 dev_name(&device_obj->device));
3e7ee490
HJ
702}
703
3e7ee490 704
b0069f43
S
705/*
706 * VMBUS is an acpi enumerated device. Get the the IRQ information
707 * from DSDT.
708 */
709
710static acpi_status vmbus_walk_resources(struct acpi_resource *res, void *irq)
711{
712
713 if (res->type == ACPI_RESOURCE_TYPE_IRQ) {
714 struct acpi_resource_irq *irqp;
715 irqp = &res->data.irq;
716
717 *((unsigned int *)irq) = irqp->interrupts[0];
718 }
719
720 return AE_OK;
721}
722
723static int vmbus_acpi_add(struct acpi_device *device)
724{
725 acpi_status result;
726
607c1a11
S
727 hv_acpi_dev = device;
728
b0069f43
S
729 result =
730 acpi_walk_resources(device->handle, METHOD_NAME__CRS,
731 vmbus_walk_resources, &irq);
732
733 if (ACPI_FAILURE(result)) {
734 complete(&probe_event);
735 return -ENODEV;
736 }
737 complete(&probe_event);
738 return 0;
739}
740
741static const struct acpi_device_id vmbus_acpi_device_ids[] = {
742 {"VMBUS", 0},
9d7b18d1 743 {"VMBus", 0},
b0069f43
S
744 {"", 0},
745};
746MODULE_DEVICE_TABLE(acpi, vmbus_acpi_device_ids);
747
748static struct acpi_driver vmbus_acpi_driver = {
749 .name = "vmbus",
750 .ids = vmbus_acpi_device_ids,
751 .ops = {
752 .add = vmbus_acpi_add,
753 },
754};
755
607c1a11 756static int __init hv_acpi_init(void)
1168ac22 757{
2dda95f8 758 int ret, t;
b0069f43
S
759
760 init_completion(&probe_event);
761
762 /*
763 * Get irq resources first.
764 */
765
0246604c
S
766 ret = acpi_bus_register_driver(&vmbus_acpi_driver);
767
b0069f43
S
768 if (ret)
769 return ret;
770
2dda95f8
S
771 t = wait_for_completion_timeout(&probe_event, 5*HZ);
772 if (t == 0) {
773 ret = -ETIMEDOUT;
774 goto cleanup;
775 }
b0069f43
S
776
777 if (irq <= 0) {
2dda95f8
S
778 ret = -ENODEV;
779 goto cleanup;
b0069f43
S
780 }
781
91fd799e
S
782 ret = vmbus_bus_init(irq);
783 if (ret)
2dda95f8
S
784 goto cleanup;
785
786 return 0;
787
788cleanup:
789 acpi_bus_unregister_driver(&vmbus_acpi_driver);
91fd799e 790 return ret;
1168ac22
S
791}
792
1168ac22 793
90c9960e 794MODULE_LICENSE("GPL");
26c14cc1 795MODULE_VERSION(HV_DRV_VERSION);
13399cba 796module_param(vmbus_loglevel, int, S_IRUGO|S_IWUSR);
3e7ee490 797
607c1a11 798module_init(hv_acpi_init);
This page took 0.280035 seconds and 5 git commands to generate.