blob: b0d08f980de13babb46a9c2f73539a7204e9b3be [file] [log] [blame]
Hank Janssen3e7ee492009-07-13 16:02:34 -07001/*
Hank Janssen3e7ee492009-07-13 16:02:34 -07002 * 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>
K. Y. Srinivasanb0069f42011-04-29 13:45:15 -070020 * K. Y. Srinivasan <kys@microsoft.com>
K. Y. Srinivasan52e5c1c2011-03-15 15:03:34 -070021 *
Hank Janssen3e7ee492009-07-13 16:02:34 -070022 */
Hank Janssen0a466182011-03-29 13:58:47 -070023#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
24
Hank Janssen3e7ee492009-07-13 16:02:34 -070025#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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090031#include <linux/slab.h>
K. Y. Srinivasanb0069f42011-04-29 13:45:15 -070032#include <linux/acpi.h>
33#include <acpi/acpi_bus.h>
Haiyang Zhang8b5d6d32010-05-28 23:22:44 +000034#include <linux/completion.h>
Greg Kroah-Hartman46a97192011-10-04 12:29:52 -070035#include <linux/hyperv.h>
K. Y. Srinivasan3f335ea2011-05-12 19:34:15 -070036
K. Y. Srinivasan0f2a6612011-05-12 19:34:28 -070037#include "hyperv_vmbus.h"
Hank Janssen3e7ee492009-07-13 16:02:34 -070038
Hank Janssen3e7ee492009-07-13 16:02:34 -070039
K. Y. Srinivasan607c1a12011-06-06 15:49:39 -070040static struct acpi_device *hv_acpi_dev;
K. Y. Srinivasan1168ac22011-03-15 15:03:32 -070041
K. Y. Srinivasan59c0e4f2011-04-29 13:45:06 -070042static struct tasklet_struct msg_dpc;
K. Y. Srinivasan66d92292011-04-29 13:45:07 -070043static struct tasklet_struct event_dpc;
K. Y. Srinivasan59c0e4f2011-04-29 13:45:06 -070044
Greg Kroah-Hartman90c99602009-09-02 07:11:14 -070045unsigned int vmbus_loglevel = (ALL_MODULES << 16 | INFO_LVL);
Hank Janssen3e7ee492009-07-13 16:02:34 -070046EXPORT_SYMBOL(vmbus_loglevel);
47
K. Y. Srinivasan71a66552011-04-29 13:45:04 -070048static struct completion probe_event;
K. Y. Srinivasanb0069f42011-04-29 13:45:15 -070049static int irq;
Hank Janssen3e7ee492009-07-13 16:02:34 -070050
K. Y. Srinivasan98db4332011-03-15 15:03:44 -070051static void get_channel_info(struct hv_device *device,
52 struct hv_device_info *info)
53{
54 struct vmbus_channel_debug_info debug_info;
55
56 if (!device->channel)
57 return;
58
59 vmbus_get_debug_info(device->channel, &debug_info);
60
61 info->chn_id = debug_info.relid;
62 info->chn_state = debug_info.state;
63 memcpy(&info->chn_type, &debug_info.interfacetype,
K. Y. Srinivasan358d2ee2011-08-25 09:48:28 -070064 sizeof(uuid_le));
K. Y. Srinivasan98db4332011-03-15 15:03:44 -070065 memcpy(&info->chn_instance, &debug_info.interface_instance,
K. Y. Srinivasan358d2ee2011-08-25 09:48:28 -070066 sizeof(uuid_le));
K. Y. Srinivasan98db4332011-03-15 15:03:44 -070067
68 info->monitor_id = debug_info.monitorid;
69
70 info->server_monitor_pending = debug_info.servermonitor_pending;
71 info->server_monitor_latency = debug_info.servermonitor_latency;
72 info->server_monitor_conn_id = debug_info.servermonitor_connectionid;
73
74 info->client_monitor_pending = debug_info.clientmonitor_pending;
75 info->client_monitor_latency = debug_info.clientmonitor_latency;
76 info->client_monitor_conn_id = debug_info.clientmonitor_connectionid;
77
78 info->inbound.int_mask = debug_info.inbound.current_interrupt_mask;
79 info->inbound.read_idx = debug_info.inbound.current_read_index;
80 info->inbound.write_idx = debug_info.inbound.current_write_index;
81 info->inbound.bytes_avail_toread =
82 debug_info.inbound.bytes_avail_toread;
83 info->inbound.bytes_avail_towrite =
84 debug_info.inbound.bytes_avail_towrite;
85
86 info->outbound.int_mask =
87 debug_info.outbound.current_interrupt_mask;
88 info->outbound.read_idx = debug_info.outbound.current_read_index;
89 info->outbound.write_idx = debug_info.outbound.current_write_index;
90 info->outbound.bytes_avail_toread =
91 debug_info.outbound.bytes_avail_toread;
92 info->outbound.bytes_avail_towrite =
93 debug_info.outbound.bytes_avail_towrite;
94}
95
Olaf Heringfd776ba2011-09-02 18:25:56 +020096#define VMBUS_ALIAS_LEN ((sizeof((struct hv_vmbus_device_id *)0)->guid) * 2)
97static void print_alias_name(struct hv_device *hv_dev, char *alias_name)
98{
99 int i;
100 for (i = 0; i < VMBUS_ALIAS_LEN; i += 2)
101 sprintf(&alias_name[i], "%02x", hv_dev->dev_type.b[i/2]);
102}
103
K. Y. Srinivasan98db4332011-03-15 15:03:44 -0700104/*
105 * vmbus_show_device_attr - Show the device attribute in sysfs.
106 *
107 * This is invoked when user does a
108 * "cat /sys/bus/vmbus/devices/<busdevice>/<attr name>"
109 */
110static ssize_t vmbus_show_device_attr(struct device *dev,
111 struct device_attribute *dev_attr,
112 char *buf)
113{
K. Y. Srinivasane8e27042011-06-06 15:50:04 -0700114 struct hv_device *hv_dev = device_to_hv_device(dev);
K. Y. Srinivasan7bb52382011-09-13 10:59:52 -0700115 struct hv_device_info *device_info;
Olaf Heringfd776ba2011-09-02 18:25:56 +0200116 char alias_name[VMBUS_ALIAS_LEN + 1];
K. Y. Srinivasan7bb52382011-09-13 10:59:52 -0700117 int ret = 0;
K. Y. Srinivasan98db4332011-03-15 15:03:44 -0700118
K. Y. Srinivasan7bb52382011-09-13 10:59:52 -0700119 device_info = kzalloc(sizeof(struct hv_device_info), GFP_KERNEL);
120 if (!device_info)
121 return ret;
K. Y. Srinivasan98db4332011-03-15 15:03:44 -0700122
K. Y. Srinivasan7bb52382011-09-13 10:59:52 -0700123 get_channel_info(hv_dev, device_info);
K. Y. Srinivasan98db4332011-03-15 15:03:44 -0700124
125 if (!strcmp(dev_attr->attr.name, "class_id")) {
K. Y. Srinivasan7bb52382011-09-13 10:59:52 -0700126 ret = sprintf(buf, "{%02x%02x%02x%02x-%02x%02x-%02x%02x-"
K. Y. Srinivasan98db4332011-03-15 15:03:44 -0700127 "%02x%02x%02x%02x%02x%02x%02x%02x}\n",
K. Y. Srinivasan7bb52382011-09-13 10:59:52 -0700128 device_info->chn_type.b[3],
129 device_info->chn_type.b[2],
130 device_info->chn_type.b[1],
131 device_info->chn_type.b[0],
132 device_info->chn_type.b[5],
133 device_info->chn_type.b[4],
134 device_info->chn_type.b[7],
135 device_info->chn_type.b[6],
136 device_info->chn_type.b[8],
137 device_info->chn_type.b[9],
138 device_info->chn_type.b[10],
139 device_info->chn_type.b[11],
140 device_info->chn_type.b[12],
141 device_info->chn_type.b[13],
142 device_info->chn_type.b[14],
143 device_info->chn_type.b[15]);
K. Y. Srinivasan98db4332011-03-15 15:03:44 -0700144 } else if (!strcmp(dev_attr->attr.name, "device_id")) {
K. Y. Srinivasan7bb52382011-09-13 10:59:52 -0700145 ret = sprintf(buf, "{%02x%02x%02x%02x-%02x%02x-%02x%02x-"
K. Y. Srinivasan98db4332011-03-15 15:03:44 -0700146 "%02x%02x%02x%02x%02x%02x%02x%02x}\n",
K. Y. Srinivasan7bb52382011-09-13 10:59:52 -0700147 device_info->chn_instance.b[3],
148 device_info->chn_instance.b[2],
149 device_info->chn_instance.b[1],
150 device_info->chn_instance.b[0],
151 device_info->chn_instance.b[5],
152 device_info->chn_instance.b[4],
153 device_info->chn_instance.b[7],
154 device_info->chn_instance.b[6],
155 device_info->chn_instance.b[8],
156 device_info->chn_instance.b[9],
157 device_info->chn_instance.b[10],
158 device_info->chn_instance.b[11],
159 device_info->chn_instance.b[12],
160 device_info->chn_instance.b[13],
161 device_info->chn_instance.b[14],
162 device_info->chn_instance.b[15]);
Olaf Heringfd776ba2011-09-02 18:25:56 +0200163 } else if (!strcmp(dev_attr->attr.name, "modalias")) {
164 print_alias_name(hv_dev, alias_name);
K. Y. Srinivasan7bb52382011-09-13 10:59:52 -0700165 ret = sprintf(buf, "vmbus:%s\n", alias_name);
K. Y. Srinivasan98db4332011-03-15 15:03:44 -0700166 } else if (!strcmp(dev_attr->attr.name, "state")) {
K. Y. Srinivasan7bb52382011-09-13 10:59:52 -0700167 ret = sprintf(buf, "%d\n", device_info->chn_state);
K. Y. Srinivasan98db4332011-03-15 15:03:44 -0700168 } else if (!strcmp(dev_attr->attr.name, "id")) {
K. Y. Srinivasan7bb52382011-09-13 10:59:52 -0700169 ret = sprintf(buf, "%d\n", device_info->chn_id);
K. Y. Srinivasan98db4332011-03-15 15:03:44 -0700170 } else if (!strcmp(dev_attr->attr.name, "out_intr_mask")) {
K. Y. Srinivasan7bb52382011-09-13 10:59:52 -0700171 ret = sprintf(buf, "%d\n", device_info->outbound.int_mask);
K. Y. Srinivasan98db4332011-03-15 15:03:44 -0700172 } else if (!strcmp(dev_attr->attr.name, "out_read_index")) {
K. Y. Srinivasan7bb52382011-09-13 10:59:52 -0700173 ret = sprintf(buf, "%d\n", device_info->outbound.read_idx);
K. Y. Srinivasan98db4332011-03-15 15:03:44 -0700174 } else if (!strcmp(dev_attr->attr.name, "out_write_index")) {
K. Y. Srinivasan7bb52382011-09-13 10:59:52 -0700175 ret = sprintf(buf, "%d\n", device_info->outbound.write_idx);
K. Y. Srinivasan98db4332011-03-15 15:03:44 -0700176 } else if (!strcmp(dev_attr->attr.name, "out_read_bytes_avail")) {
K. Y. Srinivasan7bb52382011-09-13 10:59:52 -0700177 ret = sprintf(buf, "%d\n",
178 device_info->outbound.bytes_avail_toread);
K. Y. Srinivasan98db4332011-03-15 15:03:44 -0700179 } else if (!strcmp(dev_attr->attr.name, "out_write_bytes_avail")) {
K. Y. Srinivasan7bb52382011-09-13 10:59:52 -0700180 ret = sprintf(buf, "%d\n",
181 device_info->outbound.bytes_avail_towrite);
K. Y. Srinivasan98db4332011-03-15 15:03:44 -0700182 } else if (!strcmp(dev_attr->attr.name, "in_intr_mask")) {
K. Y. Srinivasan7bb52382011-09-13 10:59:52 -0700183 ret = sprintf(buf, "%d\n", device_info->inbound.int_mask);
K. Y. Srinivasan98db4332011-03-15 15:03:44 -0700184 } else if (!strcmp(dev_attr->attr.name, "in_read_index")) {
K. Y. Srinivasan7bb52382011-09-13 10:59:52 -0700185 ret = sprintf(buf, "%d\n", device_info->inbound.read_idx);
K. Y. Srinivasan98db4332011-03-15 15:03:44 -0700186 } else if (!strcmp(dev_attr->attr.name, "in_write_index")) {
K. Y. Srinivasan7bb52382011-09-13 10:59:52 -0700187 ret = sprintf(buf, "%d\n", device_info->inbound.write_idx);
K. Y. Srinivasan98db4332011-03-15 15:03:44 -0700188 } else if (!strcmp(dev_attr->attr.name, "in_read_bytes_avail")) {
K. Y. Srinivasan7bb52382011-09-13 10:59:52 -0700189 ret = sprintf(buf, "%d\n",
190 device_info->inbound.bytes_avail_toread);
K. Y. Srinivasan98db4332011-03-15 15:03:44 -0700191 } else if (!strcmp(dev_attr->attr.name, "in_write_bytes_avail")) {
K. Y. Srinivasan7bb52382011-09-13 10:59:52 -0700192 ret = sprintf(buf, "%d\n",
193 device_info->inbound.bytes_avail_towrite);
K. Y. Srinivasan98db4332011-03-15 15:03:44 -0700194 } else if (!strcmp(dev_attr->attr.name, "monitor_id")) {
K. Y. Srinivasan7bb52382011-09-13 10:59:52 -0700195 ret = sprintf(buf, "%d\n", device_info->monitor_id);
K. Y. Srinivasan98db4332011-03-15 15:03:44 -0700196 } else if (!strcmp(dev_attr->attr.name, "server_monitor_pending")) {
K. Y. Srinivasan7bb52382011-09-13 10:59:52 -0700197 ret = sprintf(buf, "%d\n", device_info->server_monitor_pending);
K. Y. Srinivasan98db4332011-03-15 15:03:44 -0700198 } else if (!strcmp(dev_attr->attr.name, "server_monitor_latency")) {
K. Y. Srinivasan7bb52382011-09-13 10:59:52 -0700199 ret = sprintf(buf, "%d\n", device_info->server_monitor_latency);
K. Y. Srinivasan98db4332011-03-15 15:03:44 -0700200 } else if (!strcmp(dev_attr->attr.name, "server_monitor_conn_id")) {
K. Y. Srinivasan7bb52382011-09-13 10:59:52 -0700201 ret = sprintf(buf, "%d\n",
202 device_info->server_monitor_conn_id);
K. Y. Srinivasan98db4332011-03-15 15:03:44 -0700203 } else if (!strcmp(dev_attr->attr.name, "client_monitor_pending")) {
K. Y. Srinivasan7bb52382011-09-13 10:59:52 -0700204 ret = sprintf(buf, "%d\n", device_info->client_monitor_pending);
K. Y. Srinivasan98db4332011-03-15 15:03:44 -0700205 } else if (!strcmp(dev_attr->attr.name, "client_monitor_latency")) {
K. Y. Srinivasan7bb52382011-09-13 10:59:52 -0700206 ret = sprintf(buf, "%d\n", device_info->client_monitor_latency);
K. Y. Srinivasan98db4332011-03-15 15:03:44 -0700207 } else if (!strcmp(dev_attr->attr.name, "client_monitor_conn_id")) {
K. Y. Srinivasan7bb52382011-09-13 10:59:52 -0700208 ret = sprintf(buf, "%d\n",
209 device_info->client_monitor_conn_id);
K. Y. Srinivasan98db4332011-03-15 15:03:44 -0700210 }
K. Y. Srinivasan7bb52382011-09-13 10:59:52 -0700211
212 kfree(device_info);
213 return ret;
K. Y. Srinivasan98db4332011-03-15 15:03:44 -0700214}
215
Bill Pemberton454f18a2009-07-27 16:47:24 -0400216/* Set up per device attributes in /sys/bus/vmbus/devices/<bus device> */
Hank Janssen3e7ee492009-07-13 16:02:34 -0700217static struct device_attribute vmbus_device_attrs[] = {
218 __ATTR(id, S_IRUGO, vmbus_show_device_attr, NULL),
219 __ATTR(state, S_IRUGO, vmbus_show_device_attr, NULL),
220 __ATTR(class_id, S_IRUGO, vmbus_show_device_attr, NULL),
221 __ATTR(device_id, S_IRUGO, vmbus_show_device_attr, NULL),
222 __ATTR(monitor_id, S_IRUGO, vmbus_show_device_attr, NULL),
Olaf Heringfd776ba2011-09-02 18:25:56 +0200223 __ATTR(modalias, S_IRUGO, vmbus_show_device_attr, NULL),
Hank Janssen3e7ee492009-07-13 16:02:34 -0700224
225 __ATTR(server_monitor_pending, S_IRUGO, vmbus_show_device_attr, NULL),
226 __ATTR(server_monitor_latency, S_IRUGO, vmbus_show_device_attr, NULL),
227 __ATTR(server_monitor_conn_id, S_IRUGO, vmbus_show_device_attr, NULL),
228
229 __ATTR(client_monitor_pending, S_IRUGO, vmbus_show_device_attr, NULL),
230 __ATTR(client_monitor_latency, S_IRUGO, vmbus_show_device_attr, NULL),
231 __ATTR(client_monitor_conn_id, S_IRUGO, vmbus_show_device_attr, NULL),
232
233 __ATTR(out_intr_mask, S_IRUGO, vmbus_show_device_attr, NULL),
234 __ATTR(out_read_index, S_IRUGO, vmbus_show_device_attr, NULL),
235 __ATTR(out_write_index, S_IRUGO, vmbus_show_device_attr, NULL),
236 __ATTR(out_read_bytes_avail, S_IRUGO, vmbus_show_device_attr, NULL),
237 __ATTR(out_write_bytes_avail, S_IRUGO, vmbus_show_device_attr, NULL),
238
239 __ATTR(in_intr_mask, S_IRUGO, vmbus_show_device_attr, NULL),
240 __ATTR(in_read_index, S_IRUGO, vmbus_show_device_attr, NULL),
241 __ATTR(in_write_index, S_IRUGO, vmbus_show_device_attr, NULL),
242 __ATTR(in_read_bytes_avail, S_IRUGO, vmbus_show_device_attr, NULL),
243 __ATTR(in_write_bytes_avail, S_IRUGO, vmbus_show_device_attr, NULL),
244 __ATTR_NULL
245};
Hank Janssen3e7ee492009-07-13 16:02:34 -0700246
K. Y. Srinivasan793be9c2011-03-15 15:03:43 -0700247
K. Y. Srinivasanadde2482011-03-15 15:03:37 -0700248/*
249 * vmbus_uevent - add uevent for our device
250 *
251 * This routine is invoked when a device is added or removed on the vmbus to
252 * generate a uevent to udev in the userspace. The udev will then look at its
253 * rule and the uevent generated here to load the appropriate driver
K. Y. Srinivasan0ddda662011-08-25 09:48:38 -0700254 *
255 * The alias string will be of the form vmbus:guid where guid is the string
256 * representation of the device guid (each byte of the guid will be
257 * represented with two hex characters.
K. Y. Srinivasanadde2482011-03-15 15:03:37 -0700258 */
259static int vmbus_uevent(struct device *device, struct kobj_uevent_env *env)
260{
261 struct hv_device *dev = device_to_hv_device(device);
Olaf Heringfd776ba2011-09-02 18:25:56 +0200262 int ret;
263 char alias_name[VMBUS_ALIAS_LEN + 1];
K. Y. Srinivasanadde2482011-03-15 15:03:37 -0700264
Olaf Heringfd776ba2011-09-02 18:25:56 +0200265 print_alias_name(dev, alias_name);
K. Y. Srinivasan0ddda662011-08-25 09:48:38 -0700266 ret = add_uevent_var(env, "MODALIAS=vmbus:%s", alias_name);
267 return ret;
K. Y. Srinivasanadde2482011-03-15 15:03:37 -0700268}
269
K. Y. Srinivasan5841a822011-08-25 09:48:39 -0700270static uuid_le null_guid;
271
272static inline bool is_null_guid(const __u8 *guid)
273{
274 if (memcmp(guid, &null_guid, sizeof(uuid_le)))
275 return false;
276 return true;
277}
278
K. Y. Srinivasan3037a7b2011-09-13 10:59:37 -0700279/*
280 * Return a matching hv_vmbus_device_id pointer.
281 * If there is no match, return NULL.
282 */
283static const struct hv_vmbus_device_id *hv_vmbus_get_id(
284 const struct hv_vmbus_device_id *id,
285 __u8 *guid)
286{
287 for (; !is_null_guid(id->guid); id++)
288 if (!memcmp(&id->guid, guid, sizeof(uuid_le)))
289 return id;
290
291 return NULL;
292}
293
294
K. Y. Srinivasanb7fc1472011-03-15 15:03:38 -0700295
296/*
297 * vmbus_match - Attempt to match the specified device to the specified driver
298 */
299static int vmbus_match(struct device *device, struct device_driver *driver)
300{
K. Y. Srinivasanb7fc1472011-03-15 15:03:38 -0700301 struct hv_driver *drv = drv_to_hv_drv(driver);
K. Y. Srinivasane8e27042011-06-06 15:50:04 -0700302 struct hv_device *hv_dev = device_to_hv_device(device);
K. Y. Srinivasanb7fc1472011-03-15 15:03:38 -0700303
K. Y. Srinivasan3037a7b2011-09-13 10:59:37 -0700304 if (hv_vmbus_get_id(drv->id_table, hv_dev->dev_type.b))
305 return 1;
K. Y. Srinivasande632a22011-04-26 09:20:24 -0700306
K. Y. Srinivasan5841a822011-08-25 09:48:39 -0700307 return 0;
K. Y. Srinivasanb7fc1472011-03-15 15:03:38 -0700308}
309
K. Y. Srinivasanf1f0d672011-03-15 15:03:39 -0700310/*
311 * vmbus_probe - Add the new vmbus's child device
312 */
313static int vmbus_probe(struct device *child_device)
314{
315 int ret = 0;
316 struct hv_driver *drv =
317 drv_to_hv_drv(child_device->driver);
K. Y. Srinivasan9efd21e2011-04-29 13:45:10 -0700318 struct hv_device *dev = device_to_hv_device(child_device);
K. Y. Srinivasan84946892011-09-13 10:59:38 -0700319 const struct hv_vmbus_device_id *dev_id;
K. Y. Srinivasanf1f0d672011-03-15 15:03:39 -0700320
K. Y. Srinivasan84946892011-09-13 10:59:38 -0700321 dev_id = hv_vmbus_get_id(drv->id_table, dev->dev_type.b);
K. Y. Srinivasan9efd21e2011-04-29 13:45:10 -0700322 if (drv->probe) {
K. Y. Srinivasan84946892011-09-13 10:59:38 -0700323 ret = drv->probe(dev, dev_id);
K. Y. Srinivasanb14a7b32011-04-29 13:45:03 -0700324 if (ret != 0)
Hank Janssen0a466182011-03-29 13:58:47 -0700325 pr_err("probe failed for device %s (%d)\n",
326 dev_name(child_device), ret);
K. Y. Srinivasanf1f0d672011-03-15 15:03:39 -0700327
K. Y. Srinivasanf1f0d672011-03-15 15:03:39 -0700328 } else {
Hank Janssen0a466182011-03-29 13:58:47 -0700329 pr_err("probe not set for driver %s\n",
330 dev_name(child_device));
K. Y. Srinivasan6de925b2011-06-06 15:50:07 -0700331 ret = -ENODEV;
K. Y. Srinivasanf1f0d672011-03-15 15:03:39 -0700332 }
333 return ret;
334}
335
K. Y. Srinivasanc5dce3d2011-03-15 15:03:40 -0700336/*
337 * vmbus_remove - Remove a vmbus device
338 */
339static int vmbus_remove(struct device *child_device)
340{
K. Y. Srinivasand4372172011-09-13 10:59:44 -0700341 struct hv_driver *drv = drv_to_hv_drv(child_device->driver);
K. Y. Srinivasan415b0232011-04-29 13:45:12 -0700342 struct hv_device *dev = device_to_hv_device(child_device);
K. Y. Srinivasanc5dce3d2011-03-15 15:03:40 -0700343
K. Y. Srinivasand4372172011-09-13 10:59:44 -0700344 if (drv->remove)
345 drv->remove(dev);
346 else
347 pr_err("remove not set for driver %s\n",
348 dev_name(child_device));
K. Y. Srinivasanc5dce3d2011-03-15 15:03:40 -0700349
350 return 0;
351}
352
K. Y. Srinivasaneb1bb252011-03-15 15:03:41 -0700353
354/*
355 * vmbus_shutdown - Shutdown a vmbus device
356 */
357static void vmbus_shutdown(struct device *child_device)
358{
359 struct hv_driver *drv;
K. Y. Srinivasanca6887f2011-04-29 13:45:14 -0700360 struct hv_device *dev = device_to_hv_device(child_device);
K. Y. Srinivasaneb1bb252011-03-15 15:03:41 -0700361
362
363 /* The device may not be attached yet */
364 if (!child_device->driver)
365 return;
366
367 drv = drv_to_hv_drv(child_device->driver);
368
K. Y. Srinivasanca6887f2011-04-29 13:45:14 -0700369 if (drv->shutdown)
370 drv->shutdown(dev);
K. Y. Srinivasaneb1bb252011-03-15 15:03:41 -0700371
372 return;
373}
374
K. Y. Srinivasan086e7a52011-03-15 15:03:42 -0700375
376/*
377 * vmbus_device_release - Final callback release of the vmbus child device
378 */
379static void vmbus_device_release(struct device *device)
380{
K. Y. Srinivasane8e27042011-06-06 15:50:04 -0700381 struct hv_device *hv_dev = device_to_hv_device(device);
K. Y. Srinivasan086e7a52011-03-15 15:03:42 -0700382
K. Y. Srinivasane8e27042011-06-06 15:50:04 -0700383 kfree(hv_dev);
K. Y. Srinivasan086e7a52011-03-15 15:03:42 -0700384
385}
386
Bill Pemberton454f18a2009-07-27 16:47:24 -0400387/* The one and only one */
K. Y. Srinivasan9adcac52011-04-29 13:45:08 -0700388static struct bus_type hv_bus = {
389 .name = "vmbus",
390 .match = vmbus_match,
391 .shutdown = vmbus_shutdown,
392 .remove = vmbus_remove,
393 .probe = vmbus_probe,
394 .uevent = vmbus_uevent,
395 .dev_attrs = vmbus_device_attrs,
Hank Janssen3e7ee492009-07-13 16:02:34 -0700396};
397
Haiyang Zhangadf874c2011-01-26 12:12:09 -0800398static const char *driver_name = "hyperv";
Greg Kroah-Hartman36199a92010-12-02 11:59:22 -0800399
Greg Kroah-Hartman36199a92010-12-02 11:59:22 -0800400
Timo Teräsbf6506f2010-12-15 20:48:08 +0200401struct onmessage_work_context {
402 struct work_struct work;
403 struct hv_message msg;
404};
405
406static void vmbus_onmessage_work(struct work_struct *work)
407{
408 struct onmessage_work_context *ctx;
409
410 ctx = container_of(work, struct onmessage_work_context,
411 work);
412 vmbus_onmessage(&ctx->msg);
413 kfree(ctx);
414}
415
K. Y. Srinivasan62c10592011-03-10 14:04:53 -0800416static void vmbus_on_msg_dpc(unsigned long data)
Greg Kroah-Hartman36199a92010-12-02 11:59:22 -0800417{
418 int cpu = smp_processor_id();
419 void *page_addr = hv_context.synic_message_page[cpu];
420 struct hv_message *msg = (struct hv_message *)page_addr +
421 VMBUS_MESSAGE_SINT;
Timo Teräsbf6506f2010-12-15 20:48:08 +0200422 struct onmessage_work_context *ctx;
Greg Kroah-Hartman36199a92010-12-02 11:59:22 -0800423
424 while (1) {
425 if (msg->header.message_type == HVMSG_NONE) {
426 /* no msg */
427 break;
428 } else {
Timo Teräsbf6506f2010-12-15 20:48:08 +0200429 ctx = kmalloc(sizeof(*ctx), GFP_ATOMIC);
430 if (ctx == NULL)
Greg Kroah-Hartman36199a92010-12-02 11:59:22 -0800431 continue;
Timo Teräsbf6506f2010-12-15 20:48:08 +0200432 INIT_WORK(&ctx->work, vmbus_onmessage_work);
433 memcpy(&ctx->msg, msg, sizeof(*msg));
Haiyang Zhangda9fcb72011-01-26 12:12:14 -0800434 queue_work(vmbus_connection.work_queue, &ctx->work);
Greg Kroah-Hartman36199a92010-12-02 11:59:22 -0800435 }
436
437 msg->header.message_type = HVMSG_NONE;
438
439 /*
440 * Make sure the write to MessageType (ie set to
441 * HVMSG_NONE) happens before we read the
442 * MessagePending and EOMing. Otherwise, the EOMing
443 * will not deliver any more messages since there is
444 * no empty slot
445 */
K. Y. Srinivasane826f1d2011-06-06 15:50:03 -0700446 smp_mb();
Greg Kroah-Hartman36199a92010-12-02 11:59:22 -0800447
448 if (msg->header.message_flags.msg_pending) {
449 /*
450 * This will cause message queue rescan to
451 * possibly deliver another msg from the
452 * hypervisor
453 */
454 wrmsrl(HV_X64_MSR_EOM, 0);
455 }
456 }
457}
458
K. Y. Srinivasanae4636e2011-08-27 11:31:35 -0700459static irqreturn_t vmbus_isr(int irq, void *dev_id)
Greg Kroah-Hartman36199a92010-12-02 11:59:22 -0800460{
Greg Kroah-Hartman36199a92010-12-02 11:59:22 -0800461 int cpu = smp_processor_id();
462 void *page_addr;
463 struct hv_message *msg;
464 union hv_synic_event_flags *event;
K. Y. Srinivasanae4636e2011-08-27 11:31:35 -0700465 bool handled = false;
Greg Kroah-Hartman36199a92010-12-02 11:59:22 -0800466
K. Y. Srinivasan7341d902011-08-31 14:35:56 -0700467 /*
468 * Check for events before checking for messages. This is the order
469 * in which events and messages are checked in Windows guests on
470 * Hyper-V, and the Windows team suggested we do the same.
471 */
Greg Kroah-Hartman36199a92010-12-02 11:59:22 -0800472
Greg Kroah-Hartman36199a92010-12-02 11:59:22 -0800473 page_addr = hv_context.synic_event_page[cpu];
474 event = (union hv_synic_event_flags *)page_addr + VMBUS_MESSAGE_SINT;
475
476 /* Since we are a child, we only need to check bit 0 */
K. Y. Srinivasanae4636e2011-08-27 11:31:35 -0700477 if (sync_test_and_clear_bit(0, (unsigned long *) &event->flags32[0])) {
478 handled = true;
479 tasklet_schedule(&event_dpc);
K. Y. Srinivasan793be9c2011-03-15 15:03:43 -0700480 }
K. Y. Srinivasanae4636e2011-08-27 11:31:35 -0700481
K. Y. Srinivasan7341d902011-08-31 14:35:56 -0700482 page_addr = hv_context.synic_message_page[cpu];
483 msg = (struct hv_message *)page_addr + VMBUS_MESSAGE_SINT;
484
485 /* Check if there are actual msgs to be processed */
486 if (msg->header.message_type != HVMSG_NONE) {
487 handled = true;
488 tasklet_schedule(&msg_dpc);
489 }
490
K. Y. Srinivasanae4636e2011-08-27 11:31:35 -0700491 if (handled)
492 return IRQ_HANDLED;
493 else
494 return IRQ_NONE;
K. Y. Srinivasan793be9c2011-03-15 15:03:43 -0700495}
496
Hank Janssen3e189512010-03-04 22:11:00 +0000497/*
Greg Kroah-Hartman90c99602009-09-02 07:11:14 -0700498 * vmbus_bus_init -Main vmbus driver initialization routine.
499 *
500 * Here, we
Lars Lindley0686e4f2010-03-11 23:51:23 +0100501 * - initialize the vmbus driver context
Lars Lindley0686e4f2010-03-11 23:51:23 +0100502 * - invoke the vmbus hv main init routine
503 * - get the irq resource
Lars Lindley0686e4f2010-03-11 23:51:23 +0100504 * - retrieve the channel offers
Greg Kroah-Hartman90c99602009-09-02 07:11:14 -0700505 */
K. Y. Srinivasan9aaa9952011-06-06 15:49:37 -0700506static int vmbus_bus_init(int irq)
Hank Janssen3e7ee492009-07-13 16:02:34 -0700507{
Greg Kroah-Hartman90c99602009-09-02 07:11:14 -0700508 int ret;
509 unsigned int vector;
Hank Janssen3e7ee492009-07-13 16:02:34 -0700510
Greg Kroah-Hartman6d26e382010-12-02 12:08:08 -0800511 /* Hypervisor initialization...setup hypercall page..etc */
512 ret = hv_init();
Greg Kroah-Hartman90c99602009-09-02 07:11:14 -0700513 if (ret != 0) {
Hank Janssen0a466182011-03-29 13:58:47 -0700514 pr_err("Unable to initialize the hypervisor - 0x%x\n", ret);
K. Y. Srinivasand6c1c5d2011-06-06 15:50:08 -0700515 return ret;
Hank Janssen3e7ee492009-07-13 16:02:34 -0700516 }
517
K. Y. Srinivasan59c0e4f2011-04-29 13:45:06 -0700518 tasklet_init(&msg_dpc, vmbus_on_msg_dpc, 0);
K. Y. Srinivasan66d92292011-04-29 13:45:07 -0700519 tasklet_init(&event_dpc, vmbus_on_event, 0);
Hank Janssen3e7ee492009-07-13 16:02:34 -0700520
K. Y. Srinivasan9adcac52011-04-29 13:45:08 -0700521 ret = bus_register(&hv_bus);
K. Y. Srinivasand6c1c5d2011-06-06 15:50:08 -0700522 if (ret)
K. Y. Srinivasan8b9987e2011-08-31 14:35:55 -0700523 goto err_cleanup;
Hank Janssen3e7ee492009-07-13 16:02:34 -0700524
K. Y. Srinivasan3d2de262011-06-06 15:49:38 -0700525 ret = request_irq(irq, vmbus_isr, IRQF_SAMPLE_RANDOM,
K. Y. Srinivasan607c1a12011-06-06 15:49:39 -0700526 driver_name, hv_acpi_dev);
Hank Janssen3e7ee492009-07-13 16:02:34 -0700527
Greg Kroah-Hartman90c99602009-09-02 07:11:14 -0700528 if (ret != 0) {
Hank Janssen0a466182011-03-29 13:58:47 -0700529 pr_err("Unable to request IRQ %d\n",
K. Y. Srinivasan9aaa9952011-06-06 15:49:37 -0700530 irq);
K. Y. Srinivasan8b9987e2011-08-31 14:35:55 -0700531 goto err_unregister;
Hank Janssen3e7ee492009-07-13 16:02:34 -0700532 }
Hank Janssen3e7ee492009-07-13 16:02:34 -0700533
K. Y. Srinivasan9aaa9952011-06-06 15:49:37 -0700534 vector = IRQ0_VECTOR + irq;
Hank Janssen3e7ee492009-07-13 16:02:34 -0700535
K. Y. Srinivasan800b6902011-03-15 15:03:33 -0700536 /*
537 * Notify the hypervisor of our irq and
538 * connect to the host.
539 */
540 on_each_cpu(hv_synic_init, (void *)&vector, 1);
541 ret = vmbus_connect();
K. Y. Srinivasan8b9987e2011-08-31 14:35:55 -0700542 if (ret)
543 goto err_irq;
K. Y. Srinivasan800b6902011-03-15 15:03:33 -0700544
Greg Kroah-Hartman2d6e8822010-12-02 08:50:58 -0800545 vmbus_request_offers();
Haiyang Zhang8b5d6d32010-05-28 23:22:44 +0000546
K. Y. Srinivasand6c1c5d2011-06-06 15:50:08 -0700547 return 0;
K. Y. Srinivasan8b9987e2011-08-31 14:35:55 -0700548
549err_irq:
550 free_irq(irq, hv_acpi_dev);
551
552err_unregister:
553 bus_unregister(&hv_bus);
554
555err_cleanup:
556 hv_cleanup();
557
558 return ret;
Hank Janssen3e7ee492009-07-13 16:02:34 -0700559}
560
Greg Kroah-Hartman90c99602009-09-02 07:11:14 -0700561/**
Greg Kroah-Hartman768fa212011-08-25 15:07:32 -0700562 * __vmbus_child_driver_register - Register a vmbus's driver
563 * @drv: Pointer to driver structure you want to register
564 * @owner: owner module of the drv
565 * @mod_name: module name string
Hank Janssen3e189512010-03-04 22:11:00 +0000566 *
567 * Registers the given driver with Linux through the 'driver_register()' call
Greg Kroah-Hartman768fa212011-08-25 15:07:32 -0700568 * and sets up the hyper-v vmbus handling for this driver.
Hank Janssen3e189512010-03-04 22:11:00 +0000569 * It will return the state of the 'driver_register()' call.
570 *
Greg Kroah-Hartman90c99602009-09-02 07:11:14 -0700571 */
Greg Kroah-Hartman768fa212011-08-25 15:07:32 -0700572int __vmbus_driver_register(struct hv_driver *hv_driver, struct module *owner, const char *mod_name)
Hank Janssen3e7ee492009-07-13 16:02:34 -0700573{
Bill Pemberton5d48a1c2009-07-27 16:47:36 -0400574 int ret;
Hank Janssen3e7ee492009-07-13 16:02:34 -0700575
Greg Kroah-Hartman768fa212011-08-25 15:07:32 -0700576 pr_info("registering driver %s\n", hv_driver->name);
Hank Janssen3e7ee492009-07-13 16:02:34 -0700577
Greg Kroah-Hartman768fa212011-08-25 15:07:32 -0700578 hv_driver->driver.name = hv_driver->name;
579 hv_driver->driver.owner = owner;
580 hv_driver->driver.mod_name = mod_name;
581 hv_driver->driver.bus = &hv_bus;
Hank Janssen3e7ee492009-07-13 16:02:34 -0700582
Greg Kroah-Hartman768fa212011-08-25 15:07:32 -0700583 ret = driver_register(&hv_driver->driver);
Hank Janssen3e7ee492009-07-13 16:02:34 -0700584
Greg Kroah-Hartman2d6e8822010-12-02 08:50:58 -0800585 vmbus_request_offers();
Hank Janssen3e7ee492009-07-13 16:02:34 -0700586
Bill Pemberton5d48a1c2009-07-27 16:47:36 -0400587 return ret;
Hank Janssen3e7ee492009-07-13 16:02:34 -0700588}
Greg Kroah-Hartman768fa212011-08-25 15:07:32 -0700589EXPORT_SYMBOL_GPL(__vmbus_driver_register);
Hank Janssen3e7ee492009-07-13 16:02:34 -0700590
Greg Kroah-Hartman90c99602009-09-02 07:11:14 -0700591/**
Greg Kroah-Hartman768fa212011-08-25 15:07:32 -0700592 * vmbus_driver_unregister() - Unregister a vmbus's driver
593 * @drv: Pointer to driver structure you want to un-register
Hank Janssen3e189512010-03-04 22:11:00 +0000594 *
Greg Kroah-Hartman768fa212011-08-25 15:07:32 -0700595 * Un-register the given driver that was previous registered with a call to
596 * vmbus_driver_register()
Greg Kroah-Hartman90c99602009-09-02 07:11:14 -0700597 */
Greg Kroah-Hartman768fa212011-08-25 15:07:32 -0700598void vmbus_driver_unregister(struct hv_driver *hv_driver)
Hank Janssen3e7ee492009-07-13 16:02:34 -0700599{
Greg Kroah-Hartman768fa212011-08-25 15:07:32 -0700600 pr_info("unregistering driver %s\n", hv_driver->name);
Hank Janssen3e7ee492009-07-13 16:02:34 -0700601
Greg Kroah-Hartman768fa212011-08-25 15:07:32 -0700602 driver_unregister(&hv_driver->driver);
Hank Janssen3e7ee492009-07-13 16:02:34 -0700603
Hank Janssen3e7ee492009-07-13 16:02:34 -0700604}
Greg Kroah-Hartman768fa212011-08-25 15:07:32 -0700605EXPORT_SYMBOL_GPL(vmbus_driver_unregister);
Hank Janssen3e7ee492009-07-13 16:02:34 -0700606
Hank Janssen3e189512010-03-04 22:11:00 +0000607/*
K. Y. Srinivasanf2c73012011-09-08 07:24:12 -0700608 * vmbus_device_create - Creates and registers a new child device
Hank Janssen3e189512010-03-04 22:11:00 +0000609 * on the vmbus.
Greg Kroah-Hartman90c99602009-09-02 07:11:14 -0700610 */
K. Y. Srinivasanf2c73012011-09-08 07:24:12 -0700611struct hv_device *vmbus_device_create(uuid_le *type,
K. Y. Srinivasan358d2ee2011-08-25 09:48:28 -0700612 uuid_le *instance,
Greg Kroah-Hartman89733aa2010-12-02 08:22:41 -0800613 struct vmbus_channel *channel)
Hank Janssen3e7ee492009-07-13 16:02:34 -0700614{
Nicolas Palix3d3b5512009-07-28 17:32:53 +0200615 struct hv_device *child_device_obj;
Hank Janssen3e7ee492009-07-13 16:02:34 -0700616
K. Y. Srinivasan6bad88d2011-03-07 13:35:48 -0800617 child_device_obj = kzalloc(sizeof(struct hv_device), GFP_KERNEL);
618 if (!child_device_obj) {
Hank Janssen0a466182011-03-29 13:58:47 -0700619 pr_err("Unable to allocate device object for child device\n");
Hank Janssen3e7ee492009-07-13 16:02:34 -0700620 return NULL;
621 }
622
Greg Kroah-Hartmancae5b842010-10-21 09:05:27 -0700623 child_device_obj->channel = channel;
K. Y. Srinivasan358d2ee2011-08-25 09:48:28 -0700624 memcpy(&child_device_obj->dev_type, type, sizeof(uuid_le));
Haiyang Zhangca623ad2011-01-26 12:12:11 -0800625 memcpy(&child_device_obj->dev_instance, instance,
K. Y. Srinivasan358d2ee2011-08-25 09:48:28 -0700626 sizeof(uuid_le));
Hank Janssen3e7ee492009-07-13 16:02:34 -0700627
Hank Janssen3e7ee492009-07-13 16:02:34 -0700628
Hank Janssen3e7ee492009-07-13 16:02:34 -0700629 return child_device_obj;
630}
631
Hank Janssen3e189512010-03-04 22:11:00 +0000632/*
K. Y. Srinivasan22794282011-09-08 07:24:13 -0700633 * vmbus_device_register - Register the child device
Greg Kroah-Hartman90c99602009-09-02 07:11:14 -0700634 */
K. Y. Srinivasan22794282011-09-08 07:24:13 -0700635int vmbus_device_register(struct hv_device *child_device_obj)
Hank Janssen3e7ee492009-07-13 16:02:34 -0700636{
Greg Kroah-Hartman90c99602009-09-02 07:11:14 -0700637 int ret = 0;
K. Y. Srinivasan6bad88d2011-03-07 13:35:48 -0800638
Bill Pembertonf4888412009-07-29 17:00:12 -0400639 static atomic_t device_num = ATOMIC_INIT(0);
Hank Janssen3e7ee492009-07-13 16:02:34 -0700640
K. Y. Srinivasan6bad88d2011-03-07 13:35:48 -0800641 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
Greg Kroah-Hartman90c99602009-09-02 07:11:14 -0700642 atomic_inc_return(&device_num));
Hank Janssen3e7ee492009-07-13 16:02:34 -0700643
K. Y. Srinivasan0bce28b2011-08-27 11:31:39 -0700644 child_device_obj->device.bus = &hv_bus;
K. Y. Srinivasan607c1a12011-06-06 15:49:39 -0700645 child_device_obj->device.parent = &hv_acpi_dev->dev;
K. Y. Srinivasan6bad88d2011-03-07 13:35:48 -0800646 child_device_obj->device.release = vmbus_device_release;
Hank Janssen3e7ee492009-07-13 16:02:34 -0700647
Greg Kroah-Hartman90c99602009-09-02 07:11:14 -0700648 /*
649 * Register with the LDM. This will kick off the driver/device
650 * binding...which will eventually call vmbus_match() and vmbus_probe()
651 */
K. Y. Srinivasan6bad88d2011-03-07 13:35:48 -0800652 ret = device_register(&child_device_obj->device);
Hank Janssen3e7ee492009-07-13 16:02:34 -0700653
Hank Janssen3e7ee492009-07-13 16:02:34 -0700654 if (ret)
Hank Janssen0a466182011-03-29 13:58:47 -0700655 pr_err("Unable to register child device\n");
Hank Janssen3e7ee492009-07-13 16:02:34 -0700656 else
Hank Janssen0a466182011-03-29 13:58:47 -0700657 pr_info("child device %s registered\n",
658 dev_name(&child_device_obj->device));
Hank Janssen3e7ee492009-07-13 16:02:34 -0700659
Hank Janssen3e7ee492009-07-13 16:02:34 -0700660 return ret;
661}
662
Hank Janssen3e189512010-03-04 22:11:00 +0000663/*
K. Y. Srinivasan696453b2011-09-08 07:24:14 -0700664 * vmbus_device_unregister - Remove the specified child device
Hank Janssen3e189512010-03-04 22:11:00 +0000665 * from the vmbus.
Greg Kroah-Hartman90c99602009-09-02 07:11:14 -0700666 */
K. Y. Srinivasan696453b2011-09-08 07:24:14 -0700667void vmbus_device_unregister(struct hv_device *device_obj)
Hank Janssen3e7ee492009-07-13 16:02:34 -0700668{
Greg Kroah-Hartman90c99602009-09-02 07:11:14 -0700669 /*
670 * Kick off the process of unregistering the device.
671 * This will call vmbus_remove() and eventually vmbus_device_release()
672 */
K. Y. Srinivasan6bad88d2011-03-07 13:35:48 -0800673 device_unregister(&device_obj->device);
Hank Janssen3e7ee492009-07-13 16:02:34 -0700674
Hank Janssen0a466182011-03-29 13:58:47 -0700675 pr_info("child device %s unregistered\n",
676 dev_name(&device_obj->device));
Hank Janssen3e7ee492009-07-13 16:02:34 -0700677}
678
Hank Janssen3e7ee492009-07-13 16:02:34 -0700679
K. Y. Srinivasanb0069f42011-04-29 13:45:15 -0700680/*
681 * VMBUS is an acpi enumerated device. Get the the IRQ information
682 * from DSDT.
683 */
684
685static acpi_status vmbus_walk_resources(struct acpi_resource *res, void *irq)
686{
687
688 if (res->type == ACPI_RESOURCE_TYPE_IRQ) {
689 struct acpi_resource_irq *irqp;
690 irqp = &res->data.irq;
691
692 *((unsigned int *)irq) = irqp->interrupts[0];
693 }
694
695 return AE_OK;
696}
697
698static int vmbus_acpi_add(struct acpi_device *device)
699{
700 acpi_status result;
701
K. Y. Srinivasan607c1a12011-06-06 15:49:39 -0700702 hv_acpi_dev = device;
703
K. Y. Srinivasan0a4425b2011-08-27 11:31:38 -0700704 result = acpi_walk_resources(device->handle, METHOD_NAME__CRS,
705 vmbus_walk_resources, &irq);
K. Y. Srinivasanb0069f42011-04-29 13:45:15 -0700706
707 if (ACPI_FAILURE(result)) {
708 complete(&probe_event);
709 return -ENODEV;
710 }
711 complete(&probe_event);
712 return 0;
713}
714
715static const struct acpi_device_id vmbus_acpi_device_ids[] = {
716 {"VMBUS", 0},
K. Y. Srinivasan9d7b18d2011-06-06 15:49:42 -0700717 {"VMBus", 0},
K. Y. Srinivasanb0069f42011-04-29 13:45:15 -0700718 {"", 0},
719};
720MODULE_DEVICE_TABLE(acpi, vmbus_acpi_device_ids);
721
722static struct acpi_driver vmbus_acpi_driver = {
723 .name = "vmbus",
724 .ids = vmbus_acpi_device_ids,
725 .ops = {
726 .add = vmbus_acpi_add,
727 },
728};
729
K. Y. Srinivasan607c1a12011-06-06 15:49:39 -0700730static int __init hv_acpi_init(void)
K. Y. Srinivasan1168ac22011-03-15 15:03:32 -0700731{
K. Y. Srinivasan2dda95f2011-07-15 13:38:56 -0700732 int ret, t;
K. Y. Srinivasanb0069f42011-04-29 13:45:15 -0700733
734 init_completion(&probe_event);
735
736 /*
737 * Get irq resources first.
738 */
739
K. Y. Srinivasan02466042011-06-06 15:49:40 -0700740 ret = acpi_bus_register_driver(&vmbus_acpi_driver);
741
K. Y. Srinivasanb0069f42011-04-29 13:45:15 -0700742 if (ret)
743 return ret;
744
K. Y. Srinivasan2dda95f2011-07-15 13:38:56 -0700745 t = wait_for_completion_timeout(&probe_event, 5*HZ);
746 if (t == 0) {
747 ret = -ETIMEDOUT;
748 goto cleanup;
749 }
K. Y. Srinivasanb0069f42011-04-29 13:45:15 -0700750
751 if (irq <= 0) {
K. Y. Srinivasan2dda95f2011-07-15 13:38:56 -0700752 ret = -ENODEV;
753 goto cleanup;
K. Y. Srinivasanb0069f42011-04-29 13:45:15 -0700754 }
755
K. Y. Srinivasan91fd7992011-06-16 13:16:38 -0700756 ret = vmbus_bus_init(irq);
757 if (ret)
K. Y. Srinivasan2dda95f2011-07-15 13:38:56 -0700758 goto cleanup;
759
760 return 0;
761
762cleanup:
763 acpi_bus_unregister_driver(&vmbus_acpi_driver);
K. Y. Srinivasan91fd7992011-06-16 13:16:38 -0700764 return ret;
K. Y. Srinivasan1168ac22011-03-15 15:03:32 -0700765}
766
K. Y. Srinivasan1168ac22011-03-15 15:03:32 -0700767
Greg Kroah-Hartman90c99602009-09-02 07:11:14 -0700768MODULE_LICENSE("GPL");
Hank Janssen26c14cc2010-02-11 23:02:42 +0000769MODULE_VERSION(HV_DRV_VERSION);
Olaf Hering13399cb2011-04-16 18:50:42 +0200770module_param(vmbus_loglevel, int, S_IRUGO|S_IWUSR);
Hank Janssen3e7ee492009-07-13 16:02:34 -0700771
K. Y. Srinivasan607c1a12011-06-06 15:49:39 -0700772module_init(hv_acpi_init);