23 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
26 #include <linux/module.h>
27 #include <linux/device.h>
30 #include <linux/sysctl.h>
31 #include <linux/slab.h>
37 #include <asm/hypervisor.h>
41 static struct acpi_device *hv_acpi_dev;
66 static int vmbus_exists(
void)
68 if (hv_acpi_dev ==
NULL)
75 static void get_channel_info(
struct hv_device *
device,
105 info->
inbound.bytes_avail_toread =
107 info->
inbound.bytes_avail_towrite =
116 info->
outbound.bytes_avail_towrite =
120 #define VMBUS_ALIAS_LEN ((sizeof((struct hv_vmbus_device_id *)0)->guid) * 2)
121 static void print_alias_name(
struct hv_device *hv_dev,
char *alias_name)
125 sprintf(&alias_name[i],
"%02x", hv_dev->dev_type.b[i/2]);
134 static ssize_t vmbus_show_device_attr(
struct device *
dev,
138 struct hv_device *hv_dev = device_to_hv_device(dev);
147 get_channel_info(hv_dev, device_info);
149 if (!
strcmp(dev_attr->
attr.name,
"class_id")) {
151 }
else if (!
strcmp(dev_attr->
attr.name,
"device_id")) {
153 }
else if (!
strcmp(dev_attr->
attr.name,
"modalias")) {
154 print_alias_name(hv_dev, alias_name);
155 ret =
sprintf(buf,
"vmbus:%s\n", alias_name);
156 }
else if (!
strcmp(dev_attr->
attr.name,
"state")) {
158 }
else if (!
strcmp(dev_attr->
attr.name,
"id")) {
160 }
else if (!
strcmp(dev_attr->
attr.name,
"out_intr_mask")) {
162 }
else if (!
strcmp(dev_attr->
attr.name,
"out_read_index")) {
164 }
else if (!
strcmp(dev_attr->
attr.name,
"out_write_index")) {
166 }
else if (!
strcmp(dev_attr->
attr.name,
"out_read_bytes_avail")) {
168 device_info->
outbound.bytes_avail_toread);
169 }
else if (!
strcmp(dev_attr->
attr.name,
"out_write_bytes_avail")) {
171 device_info->
outbound.bytes_avail_towrite);
172 }
else if (!
strcmp(dev_attr->
attr.name,
"in_intr_mask")) {
174 }
else if (!
strcmp(dev_attr->
attr.name,
"in_read_index")) {
176 }
else if (!
strcmp(dev_attr->
attr.name,
"in_write_index")) {
178 }
else if (!
strcmp(dev_attr->
attr.name,
"in_read_bytes_avail")) {
180 device_info->
inbound.bytes_avail_toread);
181 }
else if (!
strcmp(dev_attr->
attr.name,
"in_write_bytes_avail")) {
183 device_info->
inbound.bytes_avail_towrite);
184 }
else if (!
strcmp(dev_attr->
attr.name,
"monitor_id")) {
186 }
else if (!
strcmp(dev_attr->
attr.name,
"server_monitor_pending")) {
188 }
else if (!
strcmp(dev_attr->
attr.name,
"server_monitor_latency")) {
190 }
else if (!
strcmp(dev_attr->
attr.name,
"server_monitor_conn_id")) {
193 }
else if (!
strcmp(dev_attr->
attr.name,
"client_monitor_pending")) {
195 }
else if (!
strcmp(dev_attr->
attr.name,
"client_monitor_latency")) {
197 }
else if (!
strcmp(dev_attr->
attr.name,
"client_monitor_conn_id")) {
251 struct hv_device *dev = device_to_hv_device(device);
255 print_alias_name(dev, alias_name);
262 static inline bool is_null_guid(
const __u8 *guid)
277 for (; !is_null_guid(id->
guid);
id++)
291 struct hv_driver *drv = drv_to_hv_drv(driver);
292 struct hv_device *hv_dev = device_to_hv_device(device);
294 if (hv_vmbus_get_id(drv->id_table, hv_dev->dev_type.b))
303 static int vmbus_probe(
struct device *child_device)
306 struct hv_driver *drv =
307 drv_to_hv_drv(child_device->
driver);
308 struct hv_device *dev = device_to_hv_device(child_device);
311 dev_id = hv_vmbus_get_id(drv->id_table, dev->dev_type.b);
313 ret = drv->probe(dev, dev_id);
315 pr_err(
"probe failed for device %s (%d)\n",
316 dev_name(child_device), ret);
319 pr_err(
"probe not set for driver %s\n",
320 dev_name(child_device));
329 static int vmbus_remove(
struct device *child_device)
331 struct hv_driver *drv = drv_to_hv_drv(child_device->
driver);
332 struct hv_device *dev = device_to_hv_device(child_device);
337 pr_err(
"remove not set for driver %s\n",
338 dev_name(child_device));
347 static void vmbus_shutdown(
struct device *child_device)
349 struct hv_driver *drv;
350 struct hv_device *dev = device_to_hv_device(child_device);
354 if (!child_device->
driver)
357 drv = drv_to_hv_drv(child_device->
driver);
369 static void vmbus_device_release(
struct device *device)
371 struct hv_device *hv_dev = device_to_hv_device(device);
380 .match = vmbus_match,
381 .shutdown = vmbus_shutdown,
382 .remove = vmbus_remove,
383 .probe = vmbus_probe,
384 .uevent = vmbus_uevent,
385 .dev_attrs = vmbus_device_attrs,
406 static void vmbus_on_msg_dpc(
unsigned long data)
438 if (msg->
header.message_flags.msg_pending) {
449 static irqreturn_t vmbus_isr(
int irq,
void *dev_id)
455 bool handled =
false;
469 tasklet_schedule(&event_dpc);
478 tasklet_schedule(&msg_dpc);
496 static int vmbus_bus_init(
int irq)
504 pr_err(
"Unable to initialize the hypervisor - 0x%x\n", ret);
515 ret =
request_irq(irq, vmbus_isr, 0, driver_name, hv_acpi_dev);
518 pr_err(
"Unable to request IRQ %d\n",
565 pr_info(
"registering driver %s\n", hv_driver->name);
567 ret = vmbus_exists();
571 hv_driver->driver.name = hv_driver->name;
572 hv_driver->driver.owner =
owner;
573 hv_driver->driver.mod_name = mod_name;
574 hv_driver->driver.bus = &hv_bus;
593 pr_info(
"unregistering driver %s\n", hv_driver->name);
608 struct hv_device *child_device_obj;
610 child_device_obj = kzalloc(
sizeof(
struct hv_device),
GFP_KERNEL);
611 if (!child_device_obj) {
612 pr_err(
"Unable to allocate device object for child device\n");
616 child_device_obj->channel =
channel;
618 memcpy(&child_device_obj->dev_instance, instance,
622 return child_device_obj;
637 child_device_obj->device.bus = &hv_bus;
638 child_device_obj->device.parent = &hv_acpi_dev->dev;
639 child_device_obj->device.release = vmbus_device_release;
648 pr_err(
"Unable to register child device\n");
650 pr_info(
"child device %s registered\n",
651 dev_name(&child_device_obj->device));
668 pr_info(
"child device %s unregistered\n",
669 dev_name(&device_obj->device));
691 static int vmbus_acpi_add(
struct acpi_device *device)
695 hv_acpi_dev = device;
698 vmbus_walk_resources, &irq);
715 static struct acpi_driver vmbus_acpi_driver = {
717 .ids = vmbus_acpi_device_ids,
719 .add = vmbus_acpi_add,
723 static int __init hv_acpi_init(
void)
730 init_completion(&probe_event);
752 ret = vmbus_bus_init(irq);
764 static void __exit vmbus_exit(
void)