Thomas Gleixner | 3b20eb2 | 2019-05-29 16:57:35 -0700 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 2 | /* |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 3 | * Copyright (c) 2009, Microsoft Corporation. |
| 4 | * |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 5 | * Authors: |
| 6 | * Haiyang Zhang <haiyangz@microsoft.com> |
| 7 | * Hank Janssen <hjanssen@microsoft.com> |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 8 | * K. Y. Srinivasan <kys@microsoft.com> |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 9 | */ |
Hank Janssen | 0a46618 | 2011-03-29 13:58:47 -0700 | [diff] [blame] | 10 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 11 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 12 | #include <linux/init.h> |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/device.h> |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 15 | #include <linux/interrupt.h> |
| 16 | #include <linux/sysctl.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 17 | #include <linux/slab.h> |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 18 | #include <linux/acpi.h> |
Haiyang Zhang | 8b5d6d3 | 2010-05-28 23:22:44 +0000 | [diff] [blame] | 19 | #include <linux/completion.h> |
Greg Kroah-Hartman | 46a9719 | 2011-10-04 12:29:52 -0700 | [diff] [blame] | 20 | #include <linux/hyperv.h> |
K. Y. Srinivasan | b020950 | 2012-12-01 06:46:54 -0800 | [diff] [blame] | 21 | #include <linux/kernel_stat.h> |
K. Y. Srinivasan | 4061ed9 | 2015-01-09 23:54:32 -0800 | [diff] [blame] | 22 | #include <linux/clockchips.h> |
Vitaly Kuznetsov | e513229 | 2015-02-27 11:25:51 -0800 | [diff] [blame] | 23 | #include <linux/cpu.h> |
Ingo Molnar | 68db0cf | 2017-02-08 18:51:37 +0100 | [diff] [blame] | 24 | #include <linux/sched/task_stack.h> |
| 25 | |
K. Y. Srinivasan | 302a3c0 | 2013-02-17 11:30:44 -0800 | [diff] [blame] | 26 | #include <asm/mshyperv.h> |
Nick Meier | 96c1d05 | 2015-02-28 11:39:01 -0800 | [diff] [blame] | 27 | #include <linux/notifier.h> |
| 28 | #include <linux/ptrace.h> |
Jake Oshins | 3546448 | 2015-08-05 00:52:37 -0700 | [diff] [blame] | 29 | #include <linux/screen_info.h> |
Vitaly Kuznetsov | 510f7ae | 2015-08-01 16:08:10 -0700 | [diff] [blame] | 30 | #include <linux/kdebug.h> |
Jake Oshins | 6d146ae | 2016-04-05 10:22:55 -0700 | [diff] [blame] | 31 | #include <linux/efi.h> |
Stephan Mueller | 4b44f2d | 2016-05-02 02:14:34 -0400 | [diff] [blame] | 32 | #include <linux/random.h> |
K. Y. Srinivasan | 0f2a661 | 2011-05-12 19:34:28 -0700 | [diff] [blame] | 33 | #include "hyperv_vmbus.h" |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 34 | |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 35 | struct vmbus_dynid { |
| 36 | struct list_head node; |
| 37 | struct hv_vmbus_device_id id; |
| 38 | }; |
| 39 | |
K. Y. Srinivasan | 607c1a1 | 2011-06-06 15:49:39 -0700 | [diff] [blame] | 40 | static struct acpi_device *hv_acpi_dev; |
K. Y. Srinivasan | 1168ac2 | 2011-03-15 15:03:32 -0700 | [diff] [blame] | 41 | |
K. Y. Srinivasan | 71a6655 | 2011-04-29 13:45:04 -0700 | [diff] [blame] | 42 | static struct completion probe_event; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 43 | |
Vitaly Kuznetsov | 76d36ab | 2016-12-07 14:53:11 -0800 | [diff] [blame] | 44 | static int hyperv_cpuhp_online; |
Nick Meier | 96c1d05 | 2015-02-28 11:39:01 -0800 | [diff] [blame] | 45 | |
Sunil Muthuswamy | 81b18bc | 2018-07-08 02:56:51 +0000 | [diff] [blame] | 46 | static void *hv_panic_page; |
| 47 | |
Vitaly Kuznetsov | 510f7ae | 2015-08-01 16:08:10 -0700 | [diff] [blame] | 48 | static int hyperv_panic_event(struct notifier_block *nb, unsigned long val, |
| 49 | void *args) |
| 50 | { |
| 51 | struct pt_regs *regs; |
| 52 | |
| 53 | regs = current_pt_regs(); |
| 54 | |
K. Y. Srinivasan | 7ed4325 | 2017-10-29 11:33:41 -0700 | [diff] [blame] | 55 | hyperv_report_panic(regs, val); |
Nick Meier | 96c1d05 | 2015-02-28 11:39:01 -0800 | [diff] [blame] | 56 | return NOTIFY_DONE; |
| 57 | } |
| 58 | |
Vitaly Kuznetsov | 510f7ae | 2015-08-01 16:08:10 -0700 | [diff] [blame] | 59 | static int hyperv_die_event(struct notifier_block *nb, unsigned long val, |
| 60 | void *args) |
| 61 | { |
| 62 | struct die_args *die = (struct die_args *)args; |
| 63 | struct pt_regs *regs = die->regs; |
| 64 | |
K. Y. Srinivasan | 7ed4325 | 2017-10-29 11:33:41 -0700 | [diff] [blame] | 65 | hyperv_report_panic(regs, val); |
Vitaly Kuznetsov | 510f7ae | 2015-08-01 16:08:10 -0700 | [diff] [blame] | 66 | return NOTIFY_DONE; |
| 67 | } |
| 68 | |
| 69 | static struct notifier_block hyperv_die_block = { |
| 70 | .notifier_call = hyperv_die_event, |
| 71 | }; |
Nick Meier | 96c1d05 | 2015-02-28 11:39:01 -0800 | [diff] [blame] | 72 | static struct notifier_block hyperv_panic_block = { |
| 73 | .notifier_call = hyperv_panic_event, |
| 74 | }; |
| 75 | |
Jake Oshins | 6d146ae | 2016-04-05 10:22:55 -0700 | [diff] [blame] | 76 | static const char *fb_mmio_name = "fb_range"; |
| 77 | static struct resource *fb_mmio; |
Stephen Hemminger | e2e8084 | 2016-09-07 05:39:33 -0700 | [diff] [blame] | 78 | static struct resource *hyperv_mmio; |
| 79 | static DEFINE_SEMAPHORE(hyperv_mmio_lock); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 80 | |
K. Y. Srinivasan | cf6a2ea | 2011-12-01 09:59:34 -0800 | [diff] [blame] | 81 | static int vmbus_exists(void) |
| 82 | { |
| 83 | if (hv_acpi_dev == NULL) |
| 84 | return -ENODEV; |
| 85 | |
| 86 | return 0; |
| 87 | } |
| 88 | |
Olaf Hering | fd776ba | 2011-09-02 18:25:56 +0200 | [diff] [blame] | 89 | #define VMBUS_ALIAS_LEN ((sizeof((struct hv_vmbus_device_id *)0)->guid) * 2) |
| 90 | static void print_alias_name(struct hv_device *hv_dev, char *alias_name) |
| 91 | { |
| 92 | int i; |
| 93 | for (i = 0; i < VMBUS_ALIAS_LEN; i += 2) |
| 94 | sprintf(&alias_name[i], "%02x", hv_dev->dev_type.b[i/2]); |
| 95 | } |
| 96 | |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 97 | static u8 channel_monitor_group(const struct vmbus_channel *channel) |
Greg Kroah-Hartman | 76c52bb | 2013-09-13 11:32:56 -0700 | [diff] [blame] | 98 | { |
| 99 | return (u8)channel->offermsg.monitorid / 32; |
| 100 | } |
| 101 | |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 102 | static u8 channel_monitor_offset(const struct vmbus_channel *channel) |
Greg Kroah-Hartman | 76c52bb | 2013-09-13 11:32:56 -0700 | [diff] [blame] | 103 | { |
| 104 | return (u8)channel->offermsg.monitorid % 32; |
| 105 | } |
| 106 | |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 107 | static u32 channel_pending(const struct vmbus_channel *channel, |
| 108 | const struct hv_monitor_page *monitor_page) |
Greg Kroah-Hartman | 76c52bb | 2013-09-13 11:32:56 -0700 | [diff] [blame] | 109 | { |
| 110 | u8 monitor_group = channel_monitor_group(channel); |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 111 | |
Greg Kroah-Hartman | 76c52bb | 2013-09-13 11:32:56 -0700 | [diff] [blame] | 112 | return monitor_page->trigger_group[monitor_group].pending; |
| 113 | } |
| 114 | |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 115 | static u32 channel_latency(const struct vmbus_channel *channel, |
| 116 | const struct hv_monitor_page *monitor_page) |
Greg Kroah-Hartman | 1cee272 | 2013-09-13 11:32:57 -0700 | [diff] [blame] | 117 | { |
| 118 | u8 monitor_group = channel_monitor_group(channel); |
| 119 | u8 monitor_offset = channel_monitor_offset(channel); |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 120 | |
Greg Kroah-Hartman | 1cee272 | 2013-09-13 11:32:57 -0700 | [diff] [blame] | 121 | return monitor_page->latency[monitor_group][monitor_offset]; |
| 122 | } |
| 123 | |
Greg Kroah-Hartman | 4947c74 | 2013-09-13 11:32:58 -0700 | [diff] [blame] | 124 | static u32 channel_conn_id(struct vmbus_channel *channel, |
| 125 | struct hv_monitor_page *monitor_page) |
| 126 | { |
| 127 | u8 monitor_group = channel_monitor_group(channel); |
| 128 | u8 monitor_offset = channel_monitor_offset(channel); |
| 129 | return monitor_page->parameter[monitor_group][monitor_offset].connectionid.u.id; |
| 130 | } |
| 131 | |
Greg Kroah-Hartman | 03f3a91 | 2013-09-13 11:32:49 -0700 | [diff] [blame] | 132 | static ssize_t id_show(struct device *dev, struct device_attribute *dev_attr, |
| 133 | char *buf) |
| 134 | { |
| 135 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 136 | |
| 137 | if (!hv_dev->channel) |
| 138 | return -ENODEV; |
| 139 | return sprintf(buf, "%d\n", hv_dev->channel->offermsg.child_relid); |
| 140 | } |
| 141 | static DEVICE_ATTR_RO(id); |
| 142 | |
Greg Kroah-Hartman | a8fb5f3 | 2013-09-13 11:32:50 -0700 | [diff] [blame] | 143 | static ssize_t state_show(struct device *dev, struct device_attribute *dev_attr, |
| 144 | char *buf) |
| 145 | { |
| 146 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 147 | |
| 148 | if (!hv_dev->channel) |
| 149 | return -ENODEV; |
| 150 | return sprintf(buf, "%d\n", hv_dev->channel->state); |
| 151 | } |
| 152 | static DEVICE_ATTR_RO(state); |
| 153 | |
Greg Kroah-Hartman | 5ffd00e | 2013-09-13 11:32:51 -0700 | [diff] [blame] | 154 | static ssize_t monitor_id_show(struct device *dev, |
| 155 | struct device_attribute *dev_attr, char *buf) |
| 156 | { |
| 157 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 158 | |
| 159 | if (!hv_dev->channel) |
| 160 | return -ENODEV; |
| 161 | return sprintf(buf, "%d\n", hv_dev->channel->offermsg.monitorid); |
| 162 | } |
| 163 | static DEVICE_ATTR_RO(monitor_id); |
| 164 | |
Greg Kroah-Hartman | 68234c0 | 2013-09-13 11:32:53 -0700 | [diff] [blame] | 165 | static ssize_t class_id_show(struct device *dev, |
| 166 | struct device_attribute *dev_attr, char *buf) |
| 167 | { |
| 168 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 169 | |
| 170 | if (!hv_dev->channel) |
| 171 | return -ENODEV; |
| 172 | return sprintf(buf, "{%pUl}\n", |
| 173 | hv_dev->channel->offermsg.offer.if_type.b); |
| 174 | } |
| 175 | static DEVICE_ATTR_RO(class_id); |
| 176 | |
Greg Kroah-Hartman | 7c55e1d | 2013-09-13 11:32:54 -0700 | [diff] [blame] | 177 | static ssize_t device_id_show(struct device *dev, |
| 178 | struct device_attribute *dev_attr, char *buf) |
| 179 | { |
| 180 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 181 | |
| 182 | if (!hv_dev->channel) |
| 183 | return -ENODEV; |
| 184 | return sprintf(buf, "{%pUl}\n", |
| 185 | hv_dev->channel->offermsg.offer.if_instance.b); |
| 186 | } |
| 187 | static DEVICE_ATTR_RO(device_id); |
| 188 | |
Greg Kroah-Hartman | 647fa37 | 2013-09-13 11:32:52 -0700 | [diff] [blame] | 189 | static ssize_t modalias_show(struct device *dev, |
| 190 | struct device_attribute *dev_attr, char *buf) |
| 191 | { |
| 192 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 193 | char alias_name[VMBUS_ALIAS_LEN + 1]; |
| 194 | |
| 195 | print_alias_name(hv_dev, alias_name); |
| 196 | return sprintf(buf, "vmbus:%s\n", alias_name); |
| 197 | } |
| 198 | static DEVICE_ATTR_RO(modalias); |
| 199 | |
Stephen Hemminger | 7ceb1c3 | 2018-07-28 21:58:48 +0000 | [diff] [blame] | 200 | #ifdef CONFIG_NUMA |
| 201 | static ssize_t numa_node_show(struct device *dev, |
| 202 | struct device_attribute *attr, char *buf) |
| 203 | { |
| 204 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 205 | |
| 206 | if (!hv_dev->channel) |
| 207 | return -ENODEV; |
| 208 | |
| 209 | return sprintf(buf, "%d\n", hv_dev->channel->numa_node); |
| 210 | } |
| 211 | static DEVICE_ATTR_RO(numa_node); |
| 212 | #endif |
| 213 | |
Greg Kroah-Hartman | 76c52bb | 2013-09-13 11:32:56 -0700 | [diff] [blame] | 214 | static ssize_t server_monitor_pending_show(struct device *dev, |
| 215 | struct device_attribute *dev_attr, |
| 216 | char *buf) |
| 217 | { |
| 218 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 219 | |
| 220 | if (!hv_dev->channel) |
| 221 | return -ENODEV; |
| 222 | return sprintf(buf, "%d\n", |
| 223 | channel_pending(hv_dev->channel, |
Kimberly Brown | fd8e3c3 | 2019-02-19 00:38:06 -0500 | [diff] [blame] | 224 | vmbus_connection.monitor_pages[0])); |
Greg Kroah-Hartman | 76c52bb | 2013-09-13 11:32:56 -0700 | [diff] [blame] | 225 | } |
| 226 | static DEVICE_ATTR_RO(server_monitor_pending); |
| 227 | |
| 228 | static ssize_t client_monitor_pending_show(struct device *dev, |
| 229 | struct device_attribute *dev_attr, |
| 230 | char *buf) |
| 231 | { |
| 232 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 233 | |
| 234 | if (!hv_dev->channel) |
| 235 | return -ENODEV; |
| 236 | return sprintf(buf, "%d\n", |
| 237 | channel_pending(hv_dev->channel, |
| 238 | vmbus_connection.monitor_pages[1])); |
| 239 | } |
| 240 | static DEVICE_ATTR_RO(client_monitor_pending); |
Greg Kroah-Hartman | 68234c0 | 2013-09-13 11:32:53 -0700 | [diff] [blame] | 241 | |
Greg Kroah-Hartman | 1cee272 | 2013-09-13 11:32:57 -0700 | [diff] [blame] | 242 | static ssize_t server_monitor_latency_show(struct device *dev, |
| 243 | struct device_attribute *dev_attr, |
| 244 | char *buf) |
| 245 | { |
| 246 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 247 | |
| 248 | if (!hv_dev->channel) |
| 249 | return -ENODEV; |
| 250 | return sprintf(buf, "%d\n", |
| 251 | channel_latency(hv_dev->channel, |
| 252 | vmbus_connection.monitor_pages[0])); |
| 253 | } |
| 254 | static DEVICE_ATTR_RO(server_monitor_latency); |
| 255 | |
| 256 | static ssize_t client_monitor_latency_show(struct device *dev, |
| 257 | struct device_attribute *dev_attr, |
| 258 | char *buf) |
| 259 | { |
| 260 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 261 | |
| 262 | if (!hv_dev->channel) |
| 263 | return -ENODEV; |
| 264 | return sprintf(buf, "%d\n", |
| 265 | channel_latency(hv_dev->channel, |
| 266 | vmbus_connection.monitor_pages[1])); |
| 267 | } |
| 268 | static DEVICE_ATTR_RO(client_monitor_latency); |
| 269 | |
Greg Kroah-Hartman | 4947c74 | 2013-09-13 11:32:58 -0700 | [diff] [blame] | 270 | static ssize_t server_monitor_conn_id_show(struct device *dev, |
| 271 | struct device_attribute *dev_attr, |
| 272 | char *buf) |
| 273 | { |
| 274 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 275 | |
| 276 | if (!hv_dev->channel) |
| 277 | return -ENODEV; |
| 278 | return sprintf(buf, "%d\n", |
| 279 | channel_conn_id(hv_dev->channel, |
| 280 | vmbus_connection.monitor_pages[0])); |
| 281 | } |
| 282 | static DEVICE_ATTR_RO(server_monitor_conn_id); |
| 283 | |
| 284 | static ssize_t client_monitor_conn_id_show(struct device *dev, |
| 285 | struct device_attribute *dev_attr, |
| 286 | char *buf) |
| 287 | { |
| 288 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 289 | |
| 290 | if (!hv_dev->channel) |
| 291 | return -ENODEV; |
| 292 | return sprintf(buf, "%d\n", |
| 293 | channel_conn_id(hv_dev->channel, |
| 294 | vmbus_connection.monitor_pages[1])); |
| 295 | } |
| 296 | static DEVICE_ATTR_RO(client_monitor_conn_id); |
| 297 | |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 298 | static ssize_t out_intr_mask_show(struct device *dev, |
| 299 | struct device_attribute *dev_attr, char *buf) |
| 300 | { |
| 301 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 302 | struct hv_ring_buffer_debug_info outbound; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 303 | int ret; |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 304 | |
| 305 | if (!hv_dev->channel) |
| 306 | return -ENODEV; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 307 | |
| 308 | ret = hv_ringbuffer_get_debuginfo(&hv_dev->channel->outbound, |
| 309 | &outbound); |
| 310 | if (ret < 0) |
| 311 | return ret; |
| 312 | |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 313 | return sprintf(buf, "%d\n", outbound.current_interrupt_mask); |
| 314 | } |
| 315 | static DEVICE_ATTR_RO(out_intr_mask); |
| 316 | |
| 317 | static ssize_t out_read_index_show(struct device *dev, |
| 318 | struct device_attribute *dev_attr, char *buf) |
| 319 | { |
| 320 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 321 | struct hv_ring_buffer_debug_info outbound; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 322 | int ret; |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 323 | |
| 324 | if (!hv_dev->channel) |
| 325 | return -ENODEV; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 326 | |
| 327 | ret = hv_ringbuffer_get_debuginfo(&hv_dev->channel->outbound, |
| 328 | &outbound); |
| 329 | if (ret < 0) |
| 330 | return ret; |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 331 | return sprintf(buf, "%d\n", outbound.current_read_index); |
| 332 | } |
| 333 | static DEVICE_ATTR_RO(out_read_index); |
| 334 | |
| 335 | static ssize_t out_write_index_show(struct device *dev, |
| 336 | struct device_attribute *dev_attr, |
| 337 | char *buf) |
| 338 | { |
| 339 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 340 | struct hv_ring_buffer_debug_info outbound; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 341 | int ret; |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 342 | |
| 343 | if (!hv_dev->channel) |
| 344 | return -ENODEV; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 345 | |
| 346 | ret = hv_ringbuffer_get_debuginfo(&hv_dev->channel->outbound, |
| 347 | &outbound); |
| 348 | if (ret < 0) |
| 349 | return ret; |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 350 | return sprintf(buf, "%d\n", outbound.current_write_index); |
| 351 | } |
| 352 | static DEVICE_ATTR_RO(out_write_index); |
| 353 | |
| 354 | static ssize_t out_read_bytes_avail_show(struct device *dev, |
| 355 | struct device_attribute *dev_attr, |
| 356 | char *buf) |
| 357 | { |
| 358 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 359 | struct hv_ring_buffer_debug_info outbound; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 360 | int ret; |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 361 | |
| 362 | if (!hv_dev->channel) |
| 363 | return -ENODEV; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 364 | |
| 365 | ret = hv_ringbuffer_get_debuginfo(&hv_dev->channel->outbound, |
| 366 | &outbound); |
| 367 | if (ret < 0) |
| 368 | return ret; |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 369 | return sprintf(buf, "%d\n", outbound.bytes_avail_toread); |
| 370 | } |
| 371 | static DEVICE_ATTR_RO(out_read_bytes_avail); |
| 372 | |
| 373 | static ssize_t out_write_bytes_avail_show(struct device *dev, |
| 374 | struct device_attribute *dev_attr, |
| 375 | char *buf) |
| 376 | { |
| 377 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 378 | struct hv_ring_buffer_debug_info outbound; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 379 | int ret; |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 380 | |
| 381 | if (!hv_dev->channel) |
| 382 | return -ENODEV; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 383 | |
| 384 | ret = hv_ringbuffer_get_debuginfo(&hv_dev->channel->outbound, |
| 385 | &outbound); |
| 386 | if (ret < 0) |
| 387 | return ret; |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 388 | return sprintf(buf, "%d\n", outbound.bytes_avail_towrite); |
| 389 | } |
| 390 | static DEVICE_ATTR_RO(out_write_bytes_avail); |
| 391 | |
| 392 | static ssize_t in_intr_mask_show(struct device *dev, |
| 393 | struct device_attribute *dev_attr, char *buf) |
| 394 | { |
| 395 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 396 | struct hv_ring_buffer_debug_info inbound; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 397 | int ret; |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 398 | |
| 399 | if (!hv_dev->channel) |
| 400 | return -ENODEV; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 401 | |
| 402 | ret = hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound); |
| 403 | if (ret < 0) |
| 404 | return ret; |
| 405 | |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 406 | return sprintf(buf, "%d\n", inbound.current_interrupt_mask); |
| 407 | } |
| 408 | static DEVICE_ATTR_RO(in_intr_mask); |
| 409 | |
| 410 | static ssize_t in_read_index_show(struct device *dev, |
| 411 | struct device_attribute *dev_attr, char *buf) |
| 412 | { |
| 413 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 414 | struct hv_ring_buffer_debug_info inbound; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 415 | int ret; |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 416 | |
| 417 | if (!hv_dev->channel) |
| 418 | return -ENODEV; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 419 | |
| 420 | ret = hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound); |
| 421 | if (ret < 0) |
| 422 | return ret; |
| 423 | |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 424 | return sprintf(buf, "%d\n", inbound.current_read_index); |
| 425 | } |
| 426 | static DEVICE_ATTR_RO(in_read_index); |
| 427 | |
| 428 | static ssize_t in_write_index_show(struct device *dev, |
| 429 | struct device_attribute *dev_attr, char *buf) |
| 430 | { |
| 431 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 432 | struct hv_ring_buffer_debug_info inbound; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 433 | int ret; |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 434 | |
| 435 | if (!hv_dev->channel) |
| 436 | return -ENODEV; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 437 | |
| 438 | ret = hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound); |
| 439 | if (ret < 0) |
| 440 | return ret; |
| 441 | |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 442 | return sprintf(buf, "%d\n", inbound.current_write_index); |
| 443 | } |
| 444 | static DEVICE_ATTR_RO(in_write_index); |
| 445 | |
| 446 | static ssize_t in_read_bytes_avail_show(struct device *dev, |
| 447 | struct device_attribute *dev_attr, |
| 448 | char *buf) |
| 449 | { |
| 450 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 451 | struct hv_ring_buffer_debug_info inbound; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 452 | int ret; |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 453 | |
| 454 | if (!hv_dev->channel) |
| 455 | return -ENODEV; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 456 | |
| 457 | ret = hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound); |
| 458 | if (ret < 0) |
| 459 | return ret; |
| 460 | |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 461 | return sprintf(buf, "%d\n", inbound.bytes_avail_toread); |
| 462 | } |
| 463 | static DEVICE_ATTR_RO(in_read_bytes_avail); |
| 464 | |
| 465 | static ssize_t in_write_bytes_avail_show(struct device *dev, |
| 466 | struct device_attribute *dev_attr, |
| 467 | char *buf) |
| 468 | { |
| 469 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 470 | struct hv_ring_buffer_debug_info inbound; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 471 | int ret; |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 472 | |
| 473 | if (!hv_dev->channel) |
| 474 | return -ENODEV; |
Dexuan Cui | ba50bf1 | 2018-12-17 20:16:09 +0000 | [diff] [blame] | 475 | |
| 476 | ret = hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound); |
| 477 | if (ret < 0) |
| 478 | return ret; |
| 479 | |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 480 | return sprintf(buf, "%d\n", inbound.bytes_avail_towrite); |
| 481 | } |
| 482 | static DEVICE_ATTR_RO(in_write_bytes_avail); |
| 483 | |
Dexuan Cui | 042ab03 | 2015-08-05 00:52:43 -0700 | [diff] [blame] | 484 | static ssize_t channel_vp_mapping_show(struct device *dev, |
| 485 | struct device_attribute *dev_attr, |
| 486 | char *buf) |
| 487 | { |
| 488 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 489 | struct vmbus_channel *channel = hv_dev->channel, *cur_sc; |
| 490 | unsigned long flags; |
| 491 | int buf_size = PAGE_SIZE, n_written, tot_written; |
| 492 | struct list_head *cur; |
| 493 | |
| 494 | if (!channel) |
| 495 | return -ENODEV; |
| 496 | |
| 497 | tot_written = snprintf(buf, buf_size, "%u:%u\n", |
| 498 | channel->offermsg.child_relid, channel->target_cpu); |
| 499 | |
| 500 | spin_lock_irqsave(&channel->lock, flags); |
| 501 | |
| 502 | list_for_each(cur, &channel->sc_list) { |
| 503 | if (tot_written >= buf_size - 1) |
| 504 | break; |
| 505 | |
| 506 | cur_sc = list_entry(cur, struct vmbus_channel, sc_list); |
| 507 | n_written = scnprintf(buf + tot_written, |
| 508 | buf_size - tot_written, |
| 509 | "%u:%u\n", |
| 510 | cur_sc->offermsg.child_relid, |
| 511 | cur_sc->target_cpu); |
| 512 | tot_written += n_written; |
| 513 | } |
| 514 | |
| 515 | spin_unlock_irqrestore(&channel->lock, flags); |
| 516 | |
| 517 | return tot_written; |
| 518 | } |
| 519 | static DEVICE_ATTR_RO(channel_vp_mapping); |
| 520 | |
K. Y. Srinivasan | 7047f17 | 2015-12-25 20:00:30 -0800 | [diff] [blame] | 521 | static ssize_t vendor_show(struct device *dev, |
| 522 | struct device_attribute *dev_attr, |
| 523 | char *buf) |
| 524 | { |
| 525 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 526 | return sprintf(buf, "0x%x\n", hv_dev->vendor_id); |
| 527 | } |
| 528 | static DEVICE_ATTR_RO(vendor); |
| 529 | |
| 530 | static ssize_t device_show(struct device *dev, |
| 531 | struct device_attribute *dev_attr, |
| 532 | char *buf) |
| 533 | { |
| 534 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 535 | return sprintf(buf, "0x%x\n", hv_dev->device_id); |
| 536 | } |
| 537 | static DEVICE_ATTR_RO(device); |
| 538 | |
Stephen Hemminger | d765edb | 2018-08-10 23:06:08 +0000 | [diff] [blame] | 539 | static ssize_t driver_override_store(struct device *dev, |
| 540 | struct device_attribute *attr, |
| 541 | const char *buf, size_t count) |
| 542 | { |
| 543 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 544 | char *driver_override, *old, *cp; |
| 545 | |
| 546 | /* We need to keep extra room for a newline */ |
| 547 | if (count >= (PAGE_SIZE - 1)) |
| 548 | return -EINVAL; |
| 549 | |
| 550 | driver_override = kstrndup(buf, count, GFP_KERNEL); |
| 551 | if (!driver_override) |
| 552 | return -ENOMEM; |
| 553 | |
| 554 | cp = strchr(driver_override, '\n'); |
| 555 | if (cp) |
| 556 | *cp = '\0'; |
| 557 | |
| 558 | device_lock(dev); |
| 559 | old = hv_dev->driver_override; |
| 560 | if (strlen(driver_override)) { |
| 561 | hv_dev->driver_override = driver_override; |
| 562 | } else { |
| 563 | kfree(driver_override); |
| 564 | hv_dev->driver_override = NULL; |
| 565 | } |
| 566 | device_unlock(dev); |
| 567 | |
| 568 | kfree(old); |
| 569 | |
| 570 | return count; |
| 571 | } |
| 572 | |
| 573 | static ssize_t driver_override_show(struct device *dev, |
| 574 | struct device_attribute *attr, char *buf) |
| 575 | { |
| 576 | struct hv_device *hv_dev = device_to_hv_device(dev); |
| 577 | ssize_t len; |
| 578 | |
| 579 | device_lock(dev); |
| 580 | len = snprintf(buf, PAGE_SIZE, "%s\n", hv_dev->driver_override); |
| 581 | device_unlock(dev); |
| 582 | |
| 583 | return len; |
| 584 | } |
| 585 | static DEVICE_ATTR_RW(driver_override); |
| 586 | |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 587 | /* Set up per device attributes in /sys/bus/vmbus/devices/<bus device> */ |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 588 | static struct attribute *vmbus_dev_attrs[] = { |
Greg Kroah-Hartman | 03f3a91 | 2013-09-13 11:32:49 -0700 | [diff] [blame] | 589 | &dev_attr_id.attr, |
Greg Kroah-Hartman | a8fb5f3 | 2013-09-13 11:32:50 -0700 | [diff] [blame] | 590 | &dev_attr_state.attr, |
Greg Kroah-Hartman | 5ffd00e | 2013-09-13 11:32:51 -0700 | [diff] [blame] | 591 | &dev_attr_monitor_id.attr, |
Greg Kroah-Hartman | 68234c0 | 2013-09-13 11:32:53 -0700 | [diff] [blame] | 592 | &dev_attr_class_id.attr, |
Greg Kroah-Hartman | 7c55e1d | 2013-09-13 11:32:54 -0700 | [diff] [blame] | 593 | &dev_attr_device_id.attr, |
Greg Kroah-Hartman | 647fa37 | 2013-09-13 11:32:52 -0700 | [diff] [blame] | 594 | &dev_attr_modalias.attr, |
Stephen Hemminger | 7ceb1c3 | 2018-07-28 21:58:48 +0000 | [diff] [blame] | 595 | #ifdef CONFIG_NUMA |
| 596 | &dev_attr_numa_node.attr, |
| 597 | #endif |
Greg Kroah-Hartman | 76c52bb | 2013-09-13 11:32:56 -0700 | [diff] [blame] | 598 | &dev_attr_server_monitor_pending.attr, |
| 599 | &dev_attr_client_monitor_pending.attr, |
Greg Kroah-Hartman | 1cee272 | 2013-09-13 11:32:57 -0700 | [diff] [blame] | 600 | &dev_attr_server_monitor_latency.attr, |
| 601 | &dev_attr_client_monitor_latency.attr, |
Greg Kroah-Hartman | 4947c74 | 2013-09-13 11:32:58 -0700 | [diff] [blame] | 602 | &dev_attr_server_monitor_conn_id.attr, |
| 603 | &dev_attr_client_monitor_conn_id.attr, |
Greg Kroah-Hartman | 98f4c65 | 2013-09-13 11:33:01 -0700 | [diff] [blame] | 604 | &dev_attr_out_intr_mask.attr, |
| 605 | &dev_attr_out_read_index.attr, |
| 606 | &dev_attr_out_write_index.attr, |
| 607 | &dev_attr_out_read_bytes_avail.attr, |
| 608 | &dev_attr_out_write_bytes_avail.attr, |
| 609 | &dev_attr_in_intr_mask.attr, |
| 610 | &dev_attr_in_read_index.attr, |
| 611 | &dev_attr_in_write_index.attr, |
| 612 | &dev_attr_in_read_bytes_avail.attr, |
| 613 | &dev_attr_in_write_bytes_avail.attr, |
Dexuan Cui | 042ab03 | 2015-08-05 00:52:43 -0700 | [diff] [blame] | 614 | &dev_attr_channel_vp_mapping.attr, |
K. Y. Srinivasan | 7047f17 | 2015-12-25 20:00:30 -0800 | [diff] [blame] | 615 | &dev_attr_vendor.attr, |
| 616 | &dev_attr_device.attr, |
Stephen Hemminger | d765edb | 2018-08-10 23:06:08 +0000 | [diff] [blame] | 617 | &dev_attr_driver_override.attr, |
Greg Kroah-Hartman | 03f3a91 | 2013-09-13 11:32:49 -0700 | [diff] [blame] | 618 | NULL, |
| 619 | }; |
Kimberly Brown | 46fc154 | 2019-03-19 00:04:01 -0400 | [diff] [blame] | 620 | |
| 621 | /* |
| 622 | * Device-level attribute_group callback function. Returns the permission for |
| 623 | * each attribute, and returns 0 if an attribute is not visible. |
| 624 | */ |
| 625 | static umode_t vmbus_dev_attr_is_visible(struct kobject *kobj, |
| 626 | struct attribute *attr, int idx) |
| 627 | { |
| 628 | struct device *dev = kobj_to_dev(kobj); |
| 629 | const struct hv_device *hv_dev = device_to_hv_device(dev); |
| 630 | |
| 631 | /* Hide the monitor attributes if the monitor mechanism is not used. */ |
| 632 | if (!hv_dev->channel->offermsg.monitor_allocated && |
| 633 | (attr == &dev_attr_monitor_id.attr || |
| 634 | attr == &dev_attr_server_monitor_pending.attr || |
| 635 | attr == &dev_attr_client_monitor_pending.attr || |
| 636 | attr == &dev_attr_server_monitor_latency.attr || |
| 637 | attr == &dev_attr_client_monitor_latency.attr || |
| 638 | attr == &dev_attr_server_monitor_conn_id.attr || |
| 639 | attr == &dev_attr_client_monitor_conn_id.attr)) |
| 640 | return 0; |
| 641 | |
| 642 | return attr->mode; |
| 643 | } |
| 644 | |
| 645 | static const struct attribute_group vmbus_dev_group = { |
| 646 | .attrs = vmbus_dev_attrs, |
| 647 | .is_visible = vmbus_dev_attr_is_visible |
| 648 | }; |
| 649 | __ATTRIBUTE_GROUPS(vmbus_dev); |
Greg Kroah-Hartman | 03f3a91 | 2013-09-13 11:32:49 -0700 | [diff] [blame] | 650 | |
K. Y. Srinivasan | adde248 | 2011-03-15 15:03:37 -0700 | [diff] [blame] | 651 | /* |
| 652 | * vmbus_uevent - add uevent for our device |
| 653 | * |
| 654 | * This routine is invoked when a device is added or removed on the vmbus to |
| 655 | * generate a uevent to udev in the userspace. The udev will then look at its |
| 656 | * rule and the uevent generated here to load the appropriate driver |
K. Y. Srinivasan | 0ddda66 | 2011-08-25 09:48:38 -0700 | [diff] [blame] | 657 | * |
| 658 | * The alias string will be of the form vmbus:guid where guid is the string |
| 659 | * representation of the device guid (each byte of the guid will be |
| 660 | * represented with two hex characters. |
K. Y. Srinivasan | adde248 | 2011-03-15 15:03:37 -0700 | [diff] [blame] | 661 | */ |
| 662 | static int vmbus_uevent(struct device *device, struct kobj_uevent_env *env) |
| 663 | { |
| 664 | struct hv_device *dev = device_to_hv_device(device); |
Olaf Hering | fd776ba | 2011-09-02 18:25:56 +0200 | [diff] [blame] | 665 | int ret; |
| 666 | char alias_name[VMBUS_ALIAS_LEN + 1]; |
K. Y. Srinivasan | adde248 | 2011-03-15 15:03:37 -0700 | [diff] [blame] | 667 | |
Olaf Hering | fd776ba | 2011-09-02 18:25:56 +0200 | [diff] [blame] | 668 | print_alias_name(dev, alias_name); |
K. Y. Srinivasan | 0ddda66 | 2011-08-25 09:48:38 -0700 | [diff] [blame] | 669 | ret = add_uevent_var(env, "MODALIAS=vmbus:%s", alias_name); |
| 670 | return ret; |
K. Y. Srinivasan | adde248 | 2011-03-15 15:03:37 -0700 | [diff] [blame] | 671 | } |
| 672 | |
Stephen Hemminger | d765edb | 2018-08-10 23:06:08 +0000 | [diff] [blame] | 673 | static const struct hv_vmbus_device_id * |
Andy Shevchenko | 593db80 | 2019-01-10 16:25:32 +0200 | [diff] [blame] | 674 | hv_vmbus_dev_match(const struct hv_vmbus_device_id *id, const guid_t *guid) |
Stephen Hemminger | d765edb | 2018-08-10 23:06:08 +0000 | [diff] [blame] | 675 | { |
| 676 | if (id == NULL) |
| 677 | return NULL; /* empty device table */ |
| 678 | |
Andy Shevchenko | 593db80 | 2019-01-10 16:25:32 +0200 | [diff] [blame] | 679 | for (; !guid_is_null(&id->guid); id++) |
| 680 | if (guid_equal(&id->guid, guid)) |
Stephen Hemminger | d765edb | 2018-08-10 23:06:08 +0000 | [diff] [blame] | 681 | return id; |
| 682 | |
| 683 | return NULL; |
| 684 | } |
| 685 | |
| 686 | static const struct hv_vmbus_device_id * |
Andy Shevchenko | 593db80 | 2019-01-10 16:25:32 +0200 | [diff] [blame] | 687 | hv_vmbus_dynid_match(struct hv_driver *drv, const guid_t *guid) |
K. Y. Srinivasan | 3037a7b | 2011-09-13 10:59:37 -0700 | [diff] [blame] | 688 | { |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 689 | const struct hv_vmbus_device_id *id = NULL; |
| 690 | struct vmbus_dynid *dynid; |
| 691 | |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 692 | spin_lock(&drv->dynids.lock); |
| 693 | list_for_each_entry(dynid, &drv->dynids.list, node) { |
Andy Shevchenko | 593db80 | 2019-01-10 16:25:32 +0200 | [diff] [blame] | 694 | if (guid_equal(&dynid->id.guid, guid)) { |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 695 | id = &dynid->id; |
| 696 | break; |
| 697 | } |
| 698 | } |
| 699 | spin_unlock(&drv->dynids.lock); |
| 700 | |
Stephen Hemminger | d765edb | 2018-08-10 23:06:08 +0000 | [diff] [blame] | 701 | return id; |
| 702 | } |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 703 | |
Andy Shevchenko | 593db80 | 2019-01-10 16:25:32 +0200 | [diff] [blame] | 704 | static const struct hv_vmbus_device_id vmbus_device_null; |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 705 | |
Stephen Hemminger | d765edb | 2018-08-10 23:06:08 +0000 | [diff] [blame] | 706 | /* |
| 707 | * Return a matching hv_vmbus_device_id pointer. |
| 708 | * If there is no match, return NULL. |
| 709 | */ |
| 710 | static const struct hv_vmbus_device_id *hv_vmbus_get_id(struct hv_driver *drv, |
| 711 | struct hv_device *dev) |
| 712 | { |
Andy Shevchenko | 593db80 | 2019-01-10 16:25:32 +0200 | [diff] [blame] | 713 | const guid_t *guid = &dev->dev_type; |
Stephen Hemminger | d765edb | 2018-08-10 23:06:08 +0000 | [diff] [blame] | 714 | const struct hv_vmbus_device_id *id; |
K. Y. Srinivasan | 3037a7b | 2011-09-13 10:59:37 -0700 | [diff] [blame] | 715 | |
Stephen Hemminger | d765edb | 2018-08-10 23:06:08 +0000 | [diff] [blame] | 716 | /* When driver_override is set, only bind to the matching driver */ |
| 717 | if (dev->driver_override && strcmp(dev->driver_override, drv->name)) |
| 718 | return NULL; |
| 719 | |
| 720 | /* Look at the dynamic ids first, before the static ones */ |
| 721 | id = hv_vmbus_dynid_match(drv, guid); |
| 722 | if (!id) |
| 723 | id = hv_vmbus_dev_match(drv->id_table, guid); |
| 724 | |
| 725 | /* driver_override will always match, send a dummy id */ |
| 726 | if (!id && dev->driver_override) |
| 727 | id = &vmbus_device_null; |
| 728 | |
| 729 | return id; |
K. Y. Srinivasan | 3037a7b | 2011-09-13 10:59:37 -0700 | [diff] [blame] | 730 | } |
| 731 | |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 732 | /* vmbus_add_dynid - add a new device ID to this driver and re-probe devices */ |
Andy Shevchenko | 593db80 | 2019-01-10 16:25:32 +0200 | [diff] [blame] | 733 | static int vmbus_add_dynid(struct hv_driver *drv, guid_t *guid) |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 734 | { |
| 735 | struct vmbus_dynid *dynid; |
| 736 | |
| 737 | dynid = kzalloc(sizeof(*dynid), GFP_KERNEL); |
| 738 | if (!dynid) |
| 739 | return -ENOMEM; |
| 740 | |
| 741 | dynid->id.guid = *guid; |
| 742 | |
| 743 | spin_lock(&drv->dynids.lock); |
| 744 | list_add_tail(&dynid->node, &drv->dynids.list); |
| 745 | spin_unlock(&drv->dynids.lock); |
| 746 | |
| 747 | return driver_attach(&drv->driver); |
| 748 | } |
| 749 | |
| 750 | static void vmbus_free_dynids(struct hv_driver *drv) |
| 751 | { |
| 752 | struct vmbus_dynid *dynid, *n; |
| 753 | |
| 754 | spin_lock(&drv->dynids.lock); |
| 755 | list_for_each_entry_safe(dynid, n, &drv->dynids.list, node) { |
| 756 | list_del(&dynid->node); |
| 757 | kfree(dynid); |
| 758 | } |
| 759 | spin_unlock(&drv->dynids.lock); |
| 760 | } |
| 761 | |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 762 | /* |
| 763 | * store_new_id - sysfs frontend to vmbus_add_dynid() |
| 764 | * |
| 765 | * Allow GUIDs to be added to an existing driver via sysfs. |
| 766 | */ |
| 767 | static ssize_t new_id_store(struct device_driver *driver, const char *buf, |
| 768 | size_t count) |
| 769 | { |
| 770 | struct hv_driver *drv = drv_to_hv_drv(driver); |
Andy Shevchenko | 593db80 | 2019-01-10 16:25:32 +0200 | [diff] [blame] | 771 | guid_t guid; |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 772 | ssize_t retval; |
| 773 | |
Andy Shevchenko | 593db80 | 2019-01-10 16:25:32 +0200 | [diff] [blame] | 774 | retval = guid_parse(buf, &guid); |
Andy Shevchenko | 3110010 | 2017-05-18 10:46:06 -0700 | [diff] [blame] | 775 | if (retval) |
| 776 | return retval; |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 777 | |
Stephen Hemminger | d765edb | 2018-08-10 23:06:08 +0000 | [diff] [blame] | 778 | if (hv_vmbus_dynid_match(drv, &guid)) |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 779 | return -EEXIST; |
| 780 | |
| 781 | retval = vmbus_add_dynid(drv, &guid); |
| 782 | if (retval) |
| 783 | return retval; |
| 784 | return count; |
| 785 | } |
| 786 | static DRIVER_ATTR_WO(new_id); |
| 787 | |
| 788 | /* |
| 789 | * store_remove_id - remove a PCI device ID from this driver |
| 790 | * |
| 791 | * Removes a dynamic pci device ID to this driver. |
| 792 | */ |
| 793 | static ssize_t remove_id_store(struct device_driver *driver, const char *buf, |
| 794 | size_t count) |
| 795 | { |
| 796 | struct hv_driver *drv = drv_to_hv_drv(driver); |
| 797 | struct vmbus_dynid *dynid, *n; |
Andy Shevchenko | 593db80 | 2019-01-10 16:25:32 +0200 | [diff] [blame] | 798 | guid_t guid; |
Andy Shevchenko | 3110010 | 2017-05-18 10:46:06 -0700 | [diff] [blame] | 799 | ssize_t retval; |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 800 | |
Andy Shevchenko | 593db80 | 2019-01-10 16:25:32 +0200 | [diff] [blame] | 801 | retval = guid_parse(buf, &guid); |
Andy Shevchenko | 3110010 | 2017-05-18 10:46:06 -0700 | [diff] [blame] | 802 | if (retval) |
| 803 | return retval; |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 804 | |
Andy Shevchenko | 3110010 | 2017-05-18 10:46:06 -0700 | [diff] [blame] | 805 | retval = -ENODEV; |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 806 | spin_lock(&drv->dynids.lock); |
| 807 | list_for_each_entry_safe(dynid, n, &drv->dynids.list, node) { |
| 808 | struct hv_vmbus_device_id *id = &dynid->id; |
| 809 | |
Andy Shevchenko | 593db80 | 2019-01-10 16:25:32 +0200 | [diff] [blame] | 810 | if (guid_equal(&id->guid, &guid)) { |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 811 | list_del(&dynid->node); |
| 812 | kfree(dynid); |
| 813 | retval = count; |
| 814 | break; |
| 815 | } |
| 816 | } |
| 817 | spin_unlock(&drv->dynids.lock); |
| 818 | |
| 819 | return retval; |
| 820 | } |
| 821 | static DRIVER_ATTR_WO(remove_id); |
| 822 | |
| 823 | static struct attribute *vmbus_drv_attrs[] = { |
| 824 | &driver_attr_new_id.attr, |
| 825 | &driver_attr_remove_id.attr, |
| 826 | NULL, |
| 827 | }; |
| 828 | ATTRIBUTE_GROUPS(vmbus_drv); |
K. Y. Srinivasan | 3037a7b | 2011-09-13 10:59:37 -0700 | [diff] [blame] | 829 | |
K. Y. Srinivasan | b7fc147 | 2011-03-15 15:03:38 -0700 | [diff] [blame] | 830 | |
| 831 | /* |
| 832 | * vmbus_match - Attempt to match the specified device to the specified driver |
| 833 | */ |
| 834 | static int vmbus_match(struct device *device, struct device_driver *driver) |
| 835 | { |
K. Y. Srinivasan | b7fc147 | 2011-03-15 15:03:38 -0700 | [diff] [blame] | 836 | struct hv_driver *drv = drv_to_hv_drv(driver); |
K. Y. Srinivasan | e8e2704 | 2011-06-06 15:50:04 -0700 | [diff] [blame] | 837 | struct hv_device *hv_dev = device_to_hv_device(device); |
K. Y. Srinivasan | b7fc147 | 2011-03-15 15:03:38 -0700 | [diff] [blame] | 838 | |
Dexuan Cui | 8981da3 | 2016-01-27 22:29:41 -0800 | [diff] [blame] | 839 | /* The hv_sock driver handles all hv_sock offers. */ |
| 840 | if (is_hvsock_channel(hv_dev->channel)) |
| 841 | return drv->hvsock; |
| 842 | |
Stephen Hemminger | d765edb | 2018-08-10 23:06:08 +0000 | [diff] [blame] | 843 | if (hv_vmbus_get_id(drv, hv_dev)) |
K. Y. Srinivasan | 3037a7b | 2011-09-13 10:59:37 -0700 | [diff] [blame] | 844 | return 1; |
K. Y. Srinivasan | de632a2b | 2011-04-26 09:20:24 -0700 | [diff] [blame] | 845 | |
K. Y. Srinivasan | 5841a82 | 2011-08-25 09:48:39 -0700 | [diff] [blame] | 846 | return 0; |
K. Y. Srinivasan | b7fc147 | 2011-03-15 15:03:38 -0700 | [diff] [blame] | 847 | } |
| 848 | |
K. Y. Srinivasan | f1f0d67 | 2011-03-15 15:03:39 -0700 | [diff] [blame] | 849 | /* |
| 850 | * vmbus_probe - Add the new vmbus's child device |
| 851 | */ |
| 852 | static int vmbus_probe(struct device *child_device) |
| 853 | { |
| 854 | int ret = 0; |
| 855 | struct hv_driver *drv = |
| 856 | drv_to_hv_drv(child_device->driver); |
K. Y. Srinivasan | 9efd21e | 2011-04-29 13:45:10 -0700 | [diff] [blame] | 857 | struct hv_device *dev = device_to_hv_device(child_device); |
K. Y. Srinivasan | 8494689 | 2011-09-13 10:59:38 -0700 | [diff] [blame] | 858 | const struct hv_vmbus_device_id *dev_id; |
K. Y. Srinivasan | f1f0d67 | 2011-03-15 15:03:39 -0700 | [diff] [blame] | 859 | |
Stephen Hemminger | d765edb | 2018-08-10 23:06:08 +0000 | [diff] [blame] | 860 | dev_id = hv_vmbus_get_id(drv, dev); |
K. Y. Srinivasan | 9efd21e | 2011-04-29 13:45:10 -0700 | [diff] [blame] | 861 | if (drv->probe) { |
K. Y. Srinivasan | 8494689 | 2011-09-13 10:59:38 -0700 | [diff] [blame] | 862 | ret = drv->probe(dev, dev_id); |
K. Y. Srinivasan | b14a7b3 | 2011-04-29 13:45:03 -0700 | [diff] [blame] | 863 | if (ret != 0) |
Hank Janssen | 0a46618 | 2011-03-29 13:58:47 -0700 | [diff] [blame] | 864 | pr_err("probe failed for device %s (%d)\n", |
| 865 | dev_name(child_device), ret); |
K. Y. Srinivasan | f1f0d67 | 2011-03-15 15:03:39 -0700 | [diff] [blame] | 866 | |
K. Y. Srinivasan | f1f0d67 | 2011-03-15 15:03:39 -0700 | [diff] [blame] | 867 | } else { |
Hank Janssen | 0a46618 | 2011-03-29 13:58:47 -0700 | [diff] [blame] | 868 | pr_err("probe not set for driver %s\n", |
| 869 | dev_name(child_device)); |
K. Y. Srinivasan | 6de925b | 2011-06-06 15:50:07 -0700 | [diff] [blame] | 870 | ret = -ENODEV; |
K. Y. Srinivasan | f1f0d67 | 2011-03-15 15:03:39 -0700 | [diff] [blame] | 871 | } |
| 872 | return ret; |
| 873 | } |
| 874 | |
K. Y. Srinivasan | c5dce3d | 2011-03-15 15:03:40 -0700 | [diff] [blame] | 875 | /* |
| 876 | * vmbus_remove - Remove a vmbus device |
| 877 | */ |
| 878 | static int vmbus_remove(struct device *child_device) |
| 879 | { |
K. Y. Srinivasan | d15a030 | 2015-02-28 11:18:16 -0800 | [diff] [blame] | 880 | struct hv_driver *drv; |
K. Y. Srinivasan | 415b023 | 2011-04-29 13:45:12 -0700 | [diff] [blame] | 881 | struct hv_device *dev = device_to_hv_device(child_device); |
K. Y. Srinivasan | c5dce3d | 2011-03-15 15:03:40 -0700 | [diff] [blame] | 882 | |
K. Y. Srinivasan | d15a030 | 2015-02-28 11:18:16 -0800 | [diff] [blame] | 883 | if (child_device->driver) { |
| 884 | drv = drv_to_hv_drv(child_device->driver); |
| 885 | if (drv->remove) |
| 886 | drv->remove(dev); |
K. Y. Srinivasan | d15a030 | 2015-02-28 11:18:16 -0800 | [diff] [blame] | 887 | } |
K. Y. Srinivasan | c5dce3d | 2011-03-15 15:03:40 -0700 | [diff] [blame] | 888 | |
| 889 | return 0; |
| 890 | } |
| 891 | |
K. Y. Srinivasan | eb1bb25 | 2011-03-15 15:03:41 -0700 | [diff] [blame] | 892 | |
| 893 | /* |
| 894 | * vmbus_shutdown - Shutdown a vmbus device |
| 895 | */ |
| 896 | static void vmbus_shutdown(struct device *child_device) |
| 897 | { |
| 898 | struct hv_driver *drv; |
K. Y. Srinivasan | ca6887f | 2011-04-29 13:45:14 -0700 | [diff] [blame] | 899 | struct hv_device *dev = device_to_hv_device(child_device); |
K. Y. Srinivasan | eb1bb25 | 2011-03-15 15:03:41 -0700 | [diff] [blame] | 900 | |
| 901 | |
| 902 | /* The device may not be attached yet */ |
| 903 | if (!child_device->driver) |
| 904 | return; |
| 905 | |
| 906 | drv = drv_to_hv_drv(child_device->driver); |
| 907 | |
K. Y. Srinivasan | ca6887f | 2011-04-29 13:45:14 -0700 | [diff] [blame] | 908 | if (drv->shutdown) |
| 909 | drv->shutdown(dev); |
K. Y. Srinivasan | eb1bb25 | 2011-03-15 15:03:41 -0700 | [diff] [blame] | 910 | } |
| 911 | |
K. Y. Srinivasan | 086e7a5 | 2011-03-15 15:03:42 -0700 | [diff] [blame] | 912 | |
| 913 | /* |
| 914 | * vmbus_device_release - Final callback release of the vmbus child device |
| 915 | */ |
| 916 | static void vmbus_device_release(struct device *device) |
| 917 | { |
K. Y. Srinivasan | e8e2704 | 2011-06-06 15:50:04 -0700 | [diff] [blame] | 918 | struct hv_device *hv_dev = device_to_hv_device(device); |
Dexuan Cui | 34c6801 | 2015-12-14 16:01:49 -0800 | [diff] [blame] | 919 | struct vmbus_channel *channel = hv_dev->channel; |
K. Y. Srinivasan | 086e7a5 | 2011-03-15 15:03:42 -0700 | [diff] [blame] | 920 | |
K. Y. Srinivasan | 54a66265 | 2017-04-30 16:21:18 -0700 | [diff] [blame] | 921 | mutex_lock(&vmbus_connection.channel_mutex); |
Stephen Hemminger | 800b932 | 2018-09-14 09:10:15 -0700 | [diff] [blame] | 922 | hv_process_channel_removal(channel); |
K. Y. Srinivasan | 54a66265 | 2017-04-30 16:21:18 -0700 | [diff] [blame] | 923 | mutex_unlock(&vmbus_connection.channel_mutex); |
K. Y. Srinivasan | e8e2704 | 2011-06-06 15:50:04 -0700 | [diff] [blame] | 924 | kfree(hv_dev); |
K. Y. Srinivasan | 086e7a5 | 2011-03-15 15:03:42 -0700 | [diff] [blame] | 925 | } |
| 926 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 927 | /* The one and only one */ |
K. Y. Srinivasan | 9adcac5 | 2011-04-29 13:45:08 -0700 | [diff] [blame] | 928 | static struct bus_type hv_bus = { |
| 929 | .name = "vmbus", |
| 930 | .match = vmbus_match, |
| 931 | .shutdown = vmbus_shutdown, |
| 932 | .remove = vmbus_remove, |
| 933 | .probe = vmbus_probe, |
| 934 | .uevent = vmbus_uevent, |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 935 | .dev_groups = vmbus_dev_groups, |
| 936 | .drv_groups = vmbus_drv_groups, |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 937 | }; |
| 938 | |
Timo Teräs | bf6506f | 2010-12-15 20:48:08 +0200 | [diff] [blame] | 939 | struct onmessage_work_context { |
| 940 | struct work_struct work; |
| 941 | struct hv_message msg; |
| 942 | }; |
| 943 | |
| 944 | static void vmbus_onmessage_work(struct work_struct *work) |
| 945 | { |
| 946 | struct onmessage_work_context *ctx; |
| 947 | |
Vitaly Kuznetsov | 09a1962 | 2015-02-27 11:25:54 -0800 | [diff] [blame] | 948 | /* Do not process messages if we're in DISCONNECTED state */ |
| 949 | if (vmbus_connection.conn_state == DISCONNECTED) |
| 950 | return; |
| 951 | |
Timo Teräs | bf6506f | 2010-12-15 20:48:08 +0200 | [diff] [blame] | 952 | ctx = container_of(work, struct onmessage_work_context, |
| 953 | work); |
| 954 | vmbus_onmessage(&ctx->msg); |
| 955 | kfree(ctx); |
| 956 | } |
| 957 | |
Stephen Hemminger | 37cdd99 | 2017-02-11 23:02:19 -0700 | [diff] [blame] | 958 | static void hv_process_timer_expiration(struct hv_message *msg, |
| 959 | struct hv_per_cpu_context *hv_cpu) |
K. Y. Srinivasan | 4061ed9 | 2015-01-09 23:54:32 -0800 | [diff] [blame] | 960 | { |
Stephen Hemminger | 37cdd99 | 2017-02-11 23:02:19 -0700 | [diff] [blame] | 961 | struct clock_event_device *dev = hv_cpu->clk_evt; |
K. Y. Srinivasan | 4061ed9 | 2015-01-09 23:54:32 -0800 | [diff] [blame] | 962 | |
| 963 | if (dev->event_handler) |
| 964 | dev->event_handler(dev); |
| 965 | |
Vitaly Kuznetsov | cd95aad | 2016-04-30 19:21:34 -0700 | [diff] [blame] | 966 | vmbus_signal_eom(msg, HVMSG_TIMER_EXPIRED); |
K. Y. Srinivasan | 4061ed9 | 2015-01-09 23:54:32 -0800 | [diff] [blame] | 967 | } |
| 968 | |
K. Y. Srinivasan | d81274a | 2016-02-26 15:13:21 -0800 | [diff] [blame] | 969 | void vmbus_on_msg_dpc(unsigned long data) |
Greg Kroah-Hartman | 36199a9 | 2010-12-02 11:59:22 -0800 | [diff] [blame] | 970 | { |
Stephen Hemminger | 37cdd99 | 2017-02-11 23:02:19 -0700 | [diff] [blame] | 971 | struct hv_per_cpu_context *hv_cpu = (void *)data; |
| 972 | void *page_addr = hv_cpu->synic_message_page; |
Greg Kroah-Hartman | 36199a9 | 2010-12-02 11:59:22 -0800 | [diff] [blame] | 973 | struct hv_message *msg = (struct hv_message *)page_addr + |
| 974 | VMBUS_MESSAGE_SINT; |
Dexuan Cui | 652594c | 2015-03-27 09:10:08 -0700 | [diff] [blame] | 975 | struct vmbus_channel_message_header *hdr; |
Stephen Hemminger | e6242fa | 2017-03-04 18:27:16 -0700 | [diff] [blame] | 976 | const struct vmbus_channel_message_table_entry *entry; |
Timo Teräs | bf6506f | 2010-12-15 20:48:08 +0200 | [diff] [blame] | 977 | struct onmessage_work_context *ctx; |
Vitaly Kuznetsov | cd95aad | 2016-04-30 19:21:34 -0700 | [diff] [blame] | 978 | u32 message_type = msg->header.message_type; |
Greg Kroah-Hartman | 36199a9 | 2010-12-02 11:59:22 -0800 | [diff] [blame] | 979 | |
Vitaly Kuznetsov | cd95aad | 2016-04-30 19:21:34 -0700 | [diff] [blame] | 980 | if (message_type == HVMSG_NONE) |
Vitaly Kuznetsov | 7be3e16 | 2016-02-26 15:13:15 -0800 | [diff] [blame] | 981 | /* no msg */ |
| 982 | return; |
Dexuan Cui | 652594c | 2015-03-27 09:10:08 -0700 | [diff] [blame] | 983 | |
Vitaly Kuznetsov | 7be3e16 | 2016-02-26 15:13:15 -0800 | [diff] [blame] | 984 | hdr = (struct vmbus_channel_message_header *)msg->u.payload; |
Dexuan Cui | 652594c | 2015-03-27 09:10:08 -0700 | [diff] [blame] | 985 | |
Vitaly Kuznetsov | c9fe0f8 | 2017-10-29 12:21:00 -0700 | [diff] [blame] | 986 | trace_vmbus_on_msg_dpc(hdr); |
| 987 | |
Vitaly Kuznetsov | 7be3e16 | 2016-02-26 15:13:15 -0800 | [diff] [blame] | 988 | if (hdr->msgtype >= CHANNELMSG_COUNT) { |
| 989 | WARN_ONCE(1, "unknown msgtype=%d\n", hdr->msgtype); |
| 990 | goto msg_handled; |
| 991 | } |
Dexuan Cui | 652594c | 2015-03-27 09:10:08 -0700 | [diff] [blame] | 992 | |
Vitaly Kuznetsov | 7be3e16 | 2016-02-26 15:13:15 -0800 | [diff] [blame] | 993 | entry = &channel_message_table[hdr->msgtype]; |
| 994 | if (entry->handler_type == VMHT_BLOCKING) { |
| 995 | ctx = kmalloc(sizeof(*ctx), GFP_ATOMIC); |
| 996 | if (ctx == NULL) |
| 997 | return; |
Dexuan Cui | 652594c | 2015-03-27 09:10:08 -0700 | [diff] [blame] | 998 | |
Vitaly Kuznetsov | 7be3e16 | 2016-02-26 15:13:15 -0800 | [diff] [blame] | 999 | INIT_WORK(&ctx->work, vmbus_onmessage_work); |
| 1000 | memcpy(&ctx->msg, msg, sizeof(*msg)); |
Greg Kroah-Hartman | 36199a9 | 2010-12-02 11:59:22 -0800 | [diff] [blame] | 1001 | |
K. Y. Srinivasan | 54a66265 | 2017-04-30 16:21:18 -0700 | [diff] [blame] | 1002 | /* |
| 1003 | * The host can generate a rescind message while we |
| 1004 | * may still be handling the original offer. We deal with |
| 1005 | * this condition by ensuring the processing is done on the |
| 1006 | * same CPU. |
| 1007 | */ |
| 1008 | switch (hdr->msgtype) { |
| 1009 | case CHANNELMSG_RESCIND_CHANNELOFFER: |
| 1010 | /* |
| 1011 | * If we are handling the rescind message; |
| 1012 | * schedule the work on the global work queue. |
| 1013 | */ |
| 1014 | schedule_work_on(vmbus_connection.connect_cpu, |
| 1015 | &ctx->work); |
| 1016 | break; |
| 1017 | |
| 1018 | case CHANNELMSG_OFFERCHANNEL: |
| 1019 | atomic_inc(&vmbus_connection.offer_in_progress); |
| 1020 | queue_work_on(vmbus_connection.connect_cpu, |
| 1021 | vmbus_connection.work_queue, |
| 1022 | &ctx->work); |
| 1023 | break; |
| 1024 | |
| 1025 | default: |
| 1026 | queue_work(vmbus_connection.work_queue, &ctx->work); |
| 1027 | } |
Vitaly Kuznetsov | 7be3e16 | 2016-02-26 15:13:15 -0800 | [diff] [blame] | 1028 | } else |
| 1029 | entry->message_handler(hdr); |
Dexuan Cui | 652594c | 2015-03-27 09:10:08 -0700 | [diff] [blame] | 1030 | |
| 1031 | msg_handled: |
Vitaly Kuznetsov | cd95aad | 2016-04-30 19:21:34 -0700 | [diff] [blame] | 1032 | vmbus_signal_eom(msg, message_type); |
Greg Kroah-Hartman | 36199a9 | 2010-12-02 11:59:22 -0800 | [diff] [blame] | 1033 | } |
| 1034 | |
Stephen Hemminger | 631e63a | 2017-02-11 23:02:20 -0700 | [diff] [blame] | 1035 | |
| 1036 | /* |
Stephen Hemminger | b71e328 | 2017-02-11 23:02:21 -0700 | [diff] [blame] | 1037 | * Direct callback for channels using other deferred processing |
| 1038 | */ |
| 1039 | static void vmbus_channel_isr(struct vmbus_channel *channel) |
| 1040 | { |
| 1041 | void (*callback_fn)(void *); |
| 1042 | |
| 1043 | callback_fn = READ_ONCE(channel->onchannel_callback); |
| 1044 | if (likely(callback_fn != NULL)) |
| 1045 | (*callback_fn)(channel->channel_callback_context); |
| 1046 | } |
| 1047 | |
| 1048 | /* |
Stephen Hemminger | 631e63a | 2017-02-11 23:02:20 -0700 | [diff] [blame] | 1049 | * Schedule all channels with events pending |
| 1050 | */ |
| 1051 | static void vmbus_chan_sched(struct hv_per_cpu_context *hv_cpu) |
| 1052 | { |
| 1053 | unsigned long *recv_int_page; |
| 1054 | u32 maxbits, relid; |
| 1055 | |
| 1056 | if (vmbus_proto_version < VERSION_WIN8) { |
| 1057 | maxbits = MAX_NUM_CHANNELS_SUPPORTED; |
| 1058 | recv_int_page = vmbus_connection.recv_int_page; |
| 1059 | } else { |
| 1060 | /* |
| 1061 | * When the host is win8 and beyond, the event page |
| 1062 | * can be directly checked to get the id of the channel |
| 1063 | * that has the interrupt pending. |
| 1064 | */ |
| 1065 | void *page_addr = hv_cpu->synic_event_page; |
| 1066 | union hv_synic_event_flags *event |
| 1067 | = (union hv_synic_event_flags *)page_addr + |
| 1068 | VMBUS_MESSAGE_SINT; |
| 1069 | |
| 1070 | maxbits = HV_EVENT_FLAGS_COUNT; |
| 1071 | recv_int_page = event->flags; |
| 1072 | } |
| 1073 | |
| 1074 | if (unlikely(!recv_int_page)) |
| 1075 | return; |
| 1076 | |
| 1077 | for_each_set_bit(relid, recv_int_page, maxbits) { |
| 1078 | struct vmbus_channel *channel; |
| 1079 | |
| 1080 | if (!sync_test_and_clear_bit(relid, recv_int_page)) |
| 1081 | continue; |
| 1082 | |
| 1083 | /* Special case - vmbus channel protocol msg */ |
| 1084 | if (relid == 0) |
| 1085 | continue; |
| 1086 | |
Stephen Hemminger | 8200f20 | 2017-03-04 18:13:57 -0700 | [diff] [blame] | 1087 | rcu_read_lock(); |
| 1088 | |
Stephen Hemminger | 631e63a | 2017-02-11 23:02:20 -0700 | [diff] [blame] | 1089 | /* Find channel based on relid */ |
Stephen Hemminger | 8200f20 | 2017-03-04 18:13:57 -0700 | [diff] [blame] | 1090 | list_for_each_entry_rcu(channel, &hv_cpu->chan_list, percpu_list) { |
Stephen Hemminger | b71e328 | 2017-02-11 23:02:21 -0700 | [diff] [blame] | 1091 | if (channel->offermsg.child_relid != relid) |
| 1092 | continue; |
| 1093 | |
K. Y. Srinivasan | 6f3d791 | 2017-08-11 10:03:59 -0700 | [diff] [blame] | 1094 | if (channel->rescind) |
| 1095 | continue; |
| 1096 | |
Vitaly Kuznetsov | 991f8f1 | 2017-10-29 12:21:16 -0700 | [diff] [blame] | 1097 | trace_vmbus_chan_sched(channel); |
| 1098 | |
Stephen Hemminger | 6981fbf | 2017-10-29 11:33:40 -0700 | [diff] [blame] | 1099 | ++channel->interrupts; |
| 1100 | |
Stephen Hemminger | b71e328 | 2017-02-11 23:02:21 -0700 | [diff] [blame] | 1101 | switch (channel->callback_mode) { |
| 1102 | case HV_CALL_ISR: |
| 1103 | vmbus_channel_isr(channel); |
Stephen Hemminger | 631e63a | 2017-02-11 23:02:20 -0700 | [diff] [blame] | 1104 | break; |
Stephen Hemminger | b71e328 | 2017-02-11 23:02:21 -0700 | [diff] [blame] | 1105 | |
| 1106 | case HV_CALL_BATCHED: |
| 1107 | hv_begin_read(&channel->inbound); |
| 1108 | /* fallthrough */ |
| 1109 | case HV_CALL_DIRECT: |
| 1110 | tasklet_schedule(&channel->callback_event); |
Stephen Hemminger | 631e63a | 2017-02-11 23:02:20 -0700 | [diff] [blame] | 1111 | } |
| 1112 | } |
Stephen Hemminger | 8200f20 | 2017-03-04 18:13:57 -0700 | [diff] [blame] | 1113 | |
| 1114 | rcu_read_unlock(); |
Stephen Hemminger | 631e63a | 2017-02-11 23:02:20 -0700 | [diff] [blame] | 1115 | } |
| 1116 | } |
| 1117 | |
Thomas Gleixner | 76d388c | 2014-03-05 13:42:14 +0100 | [diff] [blame] | 1118 | static void vmbus_isr(void) |
Greg Kroah-Hartman | 36199a9 | 2010-12-02 11:59:22 -0800 | [diff] [blame] | 1119 | { |
Stephen Hemminger | 37cdd99 | 2017-02-11 23:02:19 -0700 | [diff] [blame] | 1120 | struct hv_per_cpu_context *hv_cpu |
| 1121 | = this_cpu_ptr(hv_context.cpu_context); |
| 1122 | void *page_addr = hv_cpu->synic_event_page; |
Greg Kroah-Hartman | 36199a9 | 2010-12-02 11:59:22 -0800 | [diff] [blame] | 1123 | struct hv_message *msg; |
| 1124 | union hv_synic_event_flags *event; |
K. Y. Srinivasan | ae4636e | 2011-08-27 11:31:35 -0700 | [diff] [blame] | 1125 | bool handled = false; |
Greg Kroah-Hartman | 36199a9 | 2010-12-02 11:59:22 -0800 | [diff] [blame] | 1126 | |
Stephen Hemminger | 37cdd99 | 2017-02-11 23:02:19 -0700 | [diff] [blame] | 1127 | if (unlikely(page_addr == NULL)) |
Thomas Gleixner | 76d388c | 2014-03-05 13:42:14 +0100 | [diff] [blame] | 1128 | return; |
K. Y. Srinivasan | 5ab0595 | 2012-12-01 06:46:55 -0800 | [diff] [blame] | 1129 | |
| 1130 | event = (union hv_synic_event_flags *)page_addr + |
| 1131 | VMBUS_MESSAGE_SINT; |
K. Y. Srinivasan | 7341d90 | 2011-08-31 14:35:56 -0700 | [diff] [blame] | 1132 | /* |
| 1133 | * Check for events before checking for messages. This is the order |
| 1134 | * in which events and messages are checked in Windows guests on |
| 1135 | * Hyper-V, and the Windows team suggested we do the same. |
| 1136 | */ |
Greg Kroah-Hartman | 36199a9 | 2010-12-02 11:59:22 -0800 | [diff] [blame] | 1137 | |
K. Y. Srinivasan | 6552ecd7 | 2012-12-01 06:46:49 -0800 | [diff] [blame] | 1138 | if ((vmbus_proto_version == VERSION_WS2008) || |
| 1139 | (vmbus_proto_version == VERSION_WIN7)) { |
Greg Kroah-Hartman | 36199a9 | 2010-12-02 11:59:22 -0800 | [diff] [blame] | 1140 | |
K. Y. Srinivasan | 6552ecd7 | 2012-12-01 06:46:49 -0800 | [diff] [blame] | 1141 | /* Since we are a child, we only need to check bit 0 */ |
Stephen Hemminger | 5c1bec6 | 2017-02-05 17:20:31 -0700 | [diff] [blame] | 1142 | if (sync_test_and_clear_bit(0, event->flags)) |
K. Y. Srinivasan | 6552ecd7 | 2012-12-01 06:46:49 -0800 | [diff] [blame] | 1143 | handled = true; |
K. Y. Srinivasan | 6552ecd7 | 2012-12-01 06:46:49 -0800 | [diff] [blame] | 1144 | } else { |
| 1145 | /* |
| 1146 | * Our host is win8 or above. The signaling mechanism |
| 1147 | * has changed and we can directly look at the event page. |
| 1148 | * If bit n is set then we have an interrup on the channel |
| 1149 | * whose id is n. |
| 1150 | */ |
K. Y. Srinivasan | ae4636e | 2011-08-27 11:31:35 -0700 | [diff] [blame] | 1151 | handled = true; |
K. Y. Srinivasan | 793be9c | 2011-03-15 15:03:43 -0700 | [diff] [blame] | 1152 | } |
K. Y. Srinivasan | ae4636e | 2011-08-27 11:31:35 -0700 | [diff] [blame] | 1153 | |
K. Y. Srinivasan | 6552ecd7 | 2012-12-01 06:46:49 -0800 | [diff] [blame] | 1154 | if (handled) |
Stephen Hemminger | 631e63a | 2017-02-11 23:02:20 -0700 | [diff] [blame] | 1155 | vmbus_chan_sched(hv_cpu); |
K. Y. Srinivasan | 6552ecd7 | 2012-12-01 06:46:49 -0800 | [diff] [blame] | 1156 | |
Stephen Hemminger | 37cdd99 | 2017-02-11 23:02:19 -0700 | [diff] [blame] | 1157 | page_addr = hv_cpu->synic_message_page; |
K. Y. Srinivasan | 7341d90 | 2011-08-31 14:35:56 -0700 | [diff] [blame] | 1158 | msg = (struct hv_message *)page_addr + VMBUS_MESSAGE_SINT; |
| 1159 | |
| 1160 | /* Check if there are actual msgs to be processed */ |
K. Y. Srinivasan | 4061ed9 | 2015-01-09 23:54:32 -0800 | [diff] [blame] | 1161 | if (msg->header.message_type != HVMSG_NONE) { |
| 1162 | if (msg->header.message_type == HVMSG_TIMER_EXPIRED) |
Stephen Hemminger | 37cdd99 | 2017-02-11 23:02:19 -0700 | [diff] [blame] | 1163 | hv_process_timer_expiration(msg, hv_cpu); |
K. Y. Srinivasan | 4061ed9 | 2015-01-09 23:54:32 -0800 | [diff] [blame] | 1164 | else |
Stephen Hemminger | 37cdd99 | 2017-02-11 23:02:19 -0700 | [diff] [blame] | 1165 | tasklet_schedule(&hv_cpu->msg_dpc); |
K. Y. Srinivasan | 4061ed9 | 2015-01-09 23:54:32 -0800 | [diff] [blame] | 1166 | } |
Stephan Mueller | 4b44f2d | 2016-05-02 02:14:34 -0400 | [diff] [blame] | 1167 | |
| 1168 | add_interrupt_randomness(HYPERVISOR_CALLBACK_VECTOR, 0); |
K. Y. Srinivasan | 793be9c | 2011-03-15 15:03:43 -0700 | [diff] [blame] | 1169 | } |
| 1170 | |
Sunil Muthuswamy | 81b18bc | 2018-07-08 02:56:51 +0000 | [diff] [blame] | 1171 | /* |
| 1172 | * Boolean to control whether to report panic messages over Hyper-V. |
| 1173 | * |
| 1174 | * It can be set via /proc/sys/kernel/hyperv/record_panic_msg |
| 1175 | */ |
| 1176 | static int sysctl_record_panic_msg = 1; |
| 1177 | |
| 1178 | /* |
| 1179 | * Callback from kmsg_dump. Grab as much as possible from the end of the kmsg |
| 1180 | * buffer and call into Hyper-V to transfer the data. |
| 1181 | */ |
| 1182 | static void hv_kmsg_dump(struct kmsg_dumper *dumper, |
| 1183 | enum kmsg_dump_reason reason) |
| 1184 | { |
| 1185 | size_t bytes_written; |
| 1186 | phys_addr_t panic_pa; |
| 1187 | |
| 1188 | /* We are only interested in panics. */ |
| 1189 | if ((reason != KMSG_DUMP_PANIC) || (!sysctl_record_panic_msg)) |
| 1190 | return; |
| 1191 | |
| 1192 | panic_pa = virt_to_phys(hv_panic_page); |
| 1193 | |
| 1194 | /* |
| 1195 | * Write dump contents to the page. No need to synchronize; panic should |
| 1196 | * be single-threaded. |
| 1197 | */ |
Sunil Muthuswamy | ddcaf3c | 2018-07-28 21:58:45 +0000 | [diff] [blame] | 1198 | kmsg_dump_get_buffer(dumper, true, hv_panic_page, PAGE_SIZE, |
| 1199 | &bytes_written); |
| 1200 | if (bytes_written) |
| 1201 | hyperv_report_panic_msg(panic_pa, bytes_written); |
Sunil Muthuswamy | 81b18bc | 2018-07-08 02:56:51 +0000 | [diff] [blame] | 1202 | } |
| 1203 | |
| 1204 | static struct kmsg_dumper hv_kmsg_dumper = { |
| 1205 | .dump = hv_kmsg_dump, |
| 1206 | }; |
| 1207 | |
| 1208 | static struct ctl_table_header *hv_ctl_table_hdr; |
| 1209 | static int zero; |
| 1210 | static int one = 1; |
| 1211 | |
| 1212 | /* |
| 1213 | * sysctl option to allow the user to control whether kmsg data should be |
| 1214 | * reported to Hyper-V on panic. |
| 1215 | */ |
| 1216 | static struct ctl_table hv_ctl_table[] = { |
| 1217 | { |
| 1218 | .procname = "hyperv_record_panic_msg", |
| 1219 | .data = &sysctl_record_panic_msg, |
| 1220 | .maxlen = sizeof(int), |
| 1221 | .mode = 0644, |
| 1222 | .proc_handler = proc_dointvec_minmax, |
| 1223 | .extra1 = &zero, |
| 1224 | .extra2 = &one |
| 1225 | }, |
| 1226 | {} |
| 1227 | }; |
| 1228 | |
| 1229 | static struct ctl_table hv_root_table[] = { |
| 1230 | { |
| 1231 | .procname = "kernel", |
| 1232 | .mode = 0555, |
| 1233 | .child = hv_ctl_table |
| 1234 | }, |
| 1235 | {} |
| 1236 | }; |
Vitaly Kuznetsov | e513229 | 2015-02-27 11:25:51 -0800 | [diff] [blame] | 1237 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 1238 | /* |
Greg Kroah-Hartman | 90c9960 | 2009-09-02 07:11:14 -0700 | [diff] [blame] | 1239 | * vmbus_bus_init -Main vmbus driver initialization routine. |
| 1240 | * |
| 1241 | * Here, we |
Lars Lindley | 0686e4f | 2010-03-11 23:51:23 +0100 | [diff] [blame] | 1242 | * - initialize the vmbus driver context |
Lars Lindley | 0686e4f | 2010-03-11 23:51:23 +0100 | [diff] [blame] | 1243 | * - invoke the vmbus hv main init routine |
Lars Lindley | 0686e4f | 2010-03-11 23:51:23 +0100 | [diff] [blame] | 1244 | * - retrieve the channel offers |
Greg Kroah-Hartman | 90c9960 | 2009-09-02 07:11:14 -0700 | [diff] [blame] | 1245 | */ |
K. Y. Srinivasan | efc2672 | 2015-12-14 16:01:46 -0800 | [diff] [blame] | 1246 | static int vmbus_bus_init(void) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1247 | { |
Greg Kroah-Hartman | 90c9960 | 2009-09-02 07:11:14 -0700 | [diff] [blame] | 1248 | int ret; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1249 | |
Greg Kroah-Hartman | 6d26e38fa2 | 2010-12-02 12:08:08 -0800 | [diff] [blame] | 1250 | /* Hypervisor initialization...setup hypercall page..etc */ |
| 1251 | ret = hv_init(); |
Greg Kroah-Hartman | 90c9960 | 2009-09-02 07:11:14 -0700 | [diff] [blame] | 1252 | if (ret != 0) { |
Hank Janssen | 0a46618 | 2011-03-29 13:58:47 -0700 | [diff] [blame] | 1253 | pr_err("Unable to initialize the hypervisor - 0x%x\n", ret); |
K. Y. Srinivasan | d6c1c5d | 2011-06-06 15:50:08 -0700 | [diff] [blame] | 1254 | return ret; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1255 | } |
| 1256 | |
K. Y. Srinivasan | 9adcac5 | 2011-04-29 13:45:08 -0700 | [diff] [blame] | 1257 | ret = bus_register(&hv_bus); |
K. Y. Srinivasan | d6c1c5d | 2011-06-06 15:50:08 -0700 | [diff] [blame] | 1258 | if (ret) |
Vitaly Kuznetsov | d6f3609 | 2017-01-28 12:37:14 -0700 | [diff] [blame] | 1259 | return ret; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1260 | |
Thomas Gleixner | 76d388c | 2014-03-05 13:42:14 +0100 | [diff] [blame] | 1261 | hv_setup_vmbus_irq(vmbus_isr); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1262 | |
Jason Wang | 2608fb6 | 2013-06-19 11:28:10 +0800 | [diff] [blame] | 1263 | ret = hv_synic_alloc(); |
| 1264 | if (ret) |
| 1265 | goto err_alloc; |
K. Y. Srinivasan | 800b690 | 2011-03-15 15:03:33 -0700 | [diff] [blame] | 1266 | /* |
K. Y. Srinivasan | 302a3c0 | 2013-02-17 11:30:44 -0800 | [diff] [blame] | 1267 | * Initialize the per-cpu interrupt state and |
K. Y. Srinivasan | 800b690 | 2011-03-15 15:03:33 -0700 | [diff] [blame] | 1268 | * connect to the host. |
| 1269 | */ |
Michael Kelley | 4a5f3cd | 2017-12-22 11:19:02 -0700 | [diff] [blame] | 1270 | ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "hyperv/vmbus:online", |
Vitaly Kuznetsov | 76d36ab | 2016-12-07 14:53:11 -0800 | [diff] [blame] | 1271 | hv_synic_init, hv_synic_cleanup); |
| 1272 | if (ret < 0) |
| 1273 | goto err_alloc; |
| 1274 | hyperv_cpuhp_online = ret; |
| 1275 | |
K. Y. Srinivasan | 800b690 | 2011-03-15 15:03:33 -0700 | [diff] [blame] | 1276 | ret = vmbus_connect(); |
K. Y. Srinivasan | 8b9987e9 | 2011-08-31 14:35:55 -0700 | [diff] [blame] | 1277 | if (ret) |
Andrey Smetanin | 17efbee | 2015-12-14 16:01:38 -0800 | [diff] [blame] | 1278 | goto err_connect; |
K. Y. Srinivasan | 800b690 | 2011-03-15 15:03:33 -0700 | [diff] [blame] | 1279 | |
Nick Meier | 96c1d05 | 2015-02-28 11:39:01 -0800 | [diff] [blame] | 1280 | /* |
| 1281 | * Only register if the crash MSRs are available |
| 1282 | */ |
Denis V. Lunev | cc2dd40 | 2015-08-01 16:08:20 -0700 | [diff] [blame] | 1283 | if (ms_hyperv.misc_features & HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE) { |
Sunil Muthuswamy | 81b18bc | 2018-07-08 02:56:51 +0000 | [diff] [blame] | 1284 | u64 hyperv_crash_ctl; |
| 1285 | /* |
| 1286 | * Sysctl registration is not fatal, since by default |
| 1287 | * reporting is enabled. |
| 1288 | */ |
| 1289 | hv_ctl_table_hdr = register_sysctl_table(hv_root_table); |
| 1290 | if (!hv_ctl_table_hdr) |
| 1291 | pr_err("Hyper-V: sysctl table register error"); |
| 1292 | |
| 1293 | /* |
| 1294 | * Register for panic kmsg callback only if the right |
| 1295 | * capability is supported by the hypervisor. |
| 1296 | */ |
Sunil Muthuswamy | 9d9c965 | 2018-07-28 21:58:47 +0000 | [diff] [blame] | 1297 | hv_get_crash_ctl(hyperv_crash_ctl); |
Sunil Muthuswamy | 81b18bc | 2018-07-08 02:56:51 +0000 | [diff] [blame] | 1298 | if (hyperv_crash_ctl & HV_CRASH_CTL_CRASH_NOTIFY_MSG) { |
| 1299 | hv_panic_page = (void *)get_zeroed_page(GFP_KERNEL); |
| 1300 | if (hv_panic_page) { |
| 1301 | ret = kmsg_dump_register(&hv_kmsg_dumper); |
| 1302 | if (ret) |
| 1303 | pr_err("Hyper-V: kmsg dump register " |
| 1304 | "error 0x%x\n", ret); |
| 1305 | } else |
| 1306 | pr_err("Hyper-V: panic message page memory " |
| 1307 | "allocation failed"); |
| 1308 | } |
| 1309 | |
Vitaly Kuznetsov | 510f7ae | 2015-08-01 16:08:10 -0700 | [diff] [blame] | 1310 | register_die_notifier(&hyperv_die_block); |
Nick Meier | 96c1d05 | 2015-02-28 11:39:01 -0800 | [diff] [blame] | 1311 | atomic_notifier_chain_register(&panic_notifier_list, |
| 1312 | &hyperv_panic_block); |
| 1313 | } |
| 1314 | |
Greg Kroah-Hartman | 2d6e882 | 2010-12-02 08:50:58 -0800 | [diff] [blame] | 1315 | vmbus_request_offers(); |
Haiyang Zhang | 8b5d6d3 | 2010-05-28 23:22:44 +0000 | [diff] [blame] | 1316 | |
K. Y. Srinivasan | d6c1c5d | 2011-06-06 15:50:08 -0700 | [diff] [blame] | 1317 | return 0; |
K. Y. Srinivasan | 8b9987e9 | 2011-08-31 14:35:55 -0700 | [diff] [blame] | 1318 | |
Andrey Smetanin | 17efbee | 2015-12-14 16:01:38 -0800 | [diff] [blame] | 1319 | err_connect: |
Vitaly Kuznetsov | 76d36ab | 2016-12-07 14:53:11 -0800 | [diff] [blame] | 1320 | cpuhp_remove_state(hyperv_cpuhp_online); |
Jason Wang | 2608fb6 | 2013-06-19 11:28:10 +0800 | [diff] [blame] | 1321 | err_alloc: |
| 1322 | hv_synic_free(); |
Thomas Gleixner | 76d388c | 2014-03-05 13:42:14 +0100 | [diff] [blame] | 1323 | hv_remove_vmbus_irq(); |
K. Y. Srinivasan | 8b9987e9 | 2011-08-31 14:35:55 -0700 | [diff] [blame] | 1324 | |
K. Y. Srinivasan | 8b9987e9 | 2011-08-31 14:35:55 -0700 | [diff] [blame] | 1325 | bus_unregister(&hv_bus); |
Sunil Muthuswamy | 81b18bc | 2018-07-08 02:56:51 +0000 | [diff] [blame] | 1326 | free_page((unsigned long)hv_panic_page); |
Sunil Muthuswamy | 8afc06d | 2018-07-28 21:58:46 +0000 | [diff] [blame] | 1327 | unregister_sysctl_table(hv_ctl_table_hdr); |
| 1328 | hv_ctl_table_hdr = NULL; |
K. Y. Srinivasan | 8b9987e9 | 2011-08-31 14:35:55 -0700 | [diff] [blame] | 1329 | return ret; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1330 | } |
| 1331 | |
Greg Kroah-Hartman | 90c9960 | 2009-09-02 07:11:14 -0700 | [diff] [blame] | 1332 | /** |
Jake Oshins | 3546448 | 2015-08-05 00:52:37 -0700 | [diff] [blame] | 1333 | * __vmbus_child_driver_register() - Register a vmbus's driver |
| 1334 | * @hv_driver: Pointer to driver structure you want to register |
Greg Kroah-Hartman | 768fa21 | 2011-08-25 15:07:32 -0700 | [diff] [blame] | 1335 | * @owner: owner module of the drv |
| 1336 | * @mod_name: module name string |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 1337 | * |
| 1338 | * Registers the given driver with Linux through the 'driver_register()' call |
Greg Kroah-Hartman | 768fa21 | 2011-08-25 15:07:32 -0700 | [diff] [blame] | 1339 | * and sets up the hyper-v vmbus handling for this driver. |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 1340 | * It will return the state of the 'driver_register()' call. |
| 1341 | * |
Greg Kroah-Hartman | 90c9960 | 2009-09-02 07:11:14 -0700 | [diff] [blame] | 1342 | */ |
Greg Kroah-Hartman | 768fa21 | 2011-08-25 15:07:32 -0700 | [diff] [blame] | 1343 | int __vmbus_driver_register(struct hv_driver *hv_driver, struct module *owner, const char *mod_name) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1344 | { |
Bill Pemberton | 5d48a1c | 2009-07-27 16:47:36 -0400 | [diff] [blame] | 1345 | int ret; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1346 | |
Greg Kroah-Hartman | 768fa21 | 2011-08-25 15:07:32 -0700 | [diff] [blame] | 1347 | pr_info("registering driver %s\n", hv_driver->name); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1348 | |
K. Y. Srinivasan | cf6a2ea | 2011-12-01 09:59:34 -0800 | [diff] [blame] | 1349 | ret = vmbus_exists(); |
| 1350 | if (ret < 0) |
| 1351 | return ret; |
| 1352 | |
Greg Kroah-Hartman | 768fa21 | 2011-08-25 15:07:32 -0700 | [diff] [blame] | 1353 | hv_driver->driver.name = hv_driver->name; |
| 1354 | hv_driver->driver.owner = owner; |
| 1355 | hv_driver->driver.mod_name = mod_name; |
| 1356 | hv_driver->driver.bus = &hv_bus; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1357 | |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 1358 | spin_lock_init(&hv_driver->dynids.lock); |
| 1359 | INIT_LIST_HEAD(&hv_driver->dynids.list); |
| 1360 | |
Greg Kroah-Hartman | 768fa21 | 2011-08-25 15:07:32 -0700 | [diff] [blame] | 1361 | ret = driver_register(&hv_driver->driver); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1362 | |
Bill Pemberton | 5d48a1c | 2009-07-27 16:47:36 -0400 | [diff] [blame] | 1363 | return ret; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1364 | } |
Greg Kroah-Hartman | 768fa21 | 2011-08-25 15:07:32 -0700 | [diff] [blame] | 1365 | EXPORT_SYMBOL_GPL(__vmbus_driver_register); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1366 | |
Greg Kroah-Hartman | 90c9960 | 2009-09-02 07:11:14 -0700 | [diff] [blame] | 1367 | /** |
Greg Kroah-Hartman | 768fa21 | 2011-08-25 15:07:32 -0700 | [diff] [blame] | 1368 | * vmbus_driver_unregister() - Unregister a vmbus's driver |
Jake Oshins | 3546448 | 2015-08-05 00:52:37 -0700 | [diff] [blame] | 1369 | * @hv_driver: Pointer to driver structure you want to |
| 1370 | * un-register |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 1371 | * |
Greg Kroah-Hartman | 768fa21 | 2011-08-25 15:07:32 -0700 | [diff] [blame] | 1372 | * Un-register the given driver that was previous registered with a call to |
| 1373 | * vmbus_driver_register() |
Greg Kroah-Hartman | 90c9960 | 2009-09-02 07:11:14 -0700 | [diff] [blame] | 1374 | */ |
Greg Kroah-Hartman | 768fa21 | 2011-08-25 15:07:32 -0700 | [diff] [blame] | 1375 | void vmbus_driver_unregister(struct hv_driver *hv_driver) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1376 | { |
Greg Kroah-Hartman | 768fa21 | 2011-08-25 15:07:32 -0700 | [diff] [blame] | 1377 | pr_info("unregistering driver %s\n", hv_driver->name); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1378 | |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 1379 | if (!vmbus_exists()) { |
K. Y. Srinivasan | 8f257a1 | 2011-12-27 13:49:37 -0800 | [diff] [blame] | 1380 | driver_unregister(&hv_driver->driver); |
Stephen Hemminger | fc76936 | 2016-12-03 12:34:39 -0800 | [diff] [blame] | 1381 | vmbus_free_dynids(hv_driver); |
| 1382 | } |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1383 | } |
Greg Kroah-Hartman | 768fa21 | 2011-08-25 15:07:32 -0700 | [diff] [blame] | 1384 | EXPORT_SYMBOL_GPL(vmbus_driver_unregister); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1385 | |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1386 | |
| 1387 | /* |
| 1388 | * Called when last reference to channel is gone. |
| 1389 | */ |
| 1390 | static void vmbus_chan_release(struct kobject *kobj) |
| 1391 | { |
| 1392 | struct vmbus_channel *channel |
| 1393 | = container_of(kobj, struct vmbus_channel, kobj); |
| 1394 | |
| 1395 | kfree_rcu(channel, rcu); |
| 1396 | } |
| 1397 | |
| 1398 | struct vmbus_chan_attribute { |
| 1399 | struct attribute attr; |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1400 | ssize_t (*show)(struct vmbus_channel *chan, char *buf); |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1401 | ssize_t (*store)(struct vmbus_channel *chan, |
| 1402 | const char *buf, size_t count); |
| 1403 | }; |
| 1404 | #define VMBUS_CHAN_ATTR(_name, _mode, _show, _store) \ |
| 1405 | struct vmbus_chan_attribute chan_attr_##_name \ |
| 1406 | = __ATTR(_name, _mode, _show, _store) |
| 1407 | #define VMBUS_CHAN_ATTR_RW(_name) \ |
| 1408 | struct vmbus_chan_attribute chan_attr_##_name = __ATTR_RW(_name) |
| 1409 | #define VMBUS_CHAN_ATTR_RO(_name) \ |
| 1410 | struct vmbus_chan_attribute chan_attr_##_name = __ATTR_RO(_name) |
| 1411 | #define VMBUS_CHAN_ATTR_WO(_name) \ |
| 1412 | struct vmbus_chan_attribute chan_attr_##_name = __ATTR_WO(_name) |
| 1413 | |
| 1414 | static ssize_t vmbus_chan_attr_show(struct kobject *kobj, |
| 1415 | struct attribute *attr, char *buf) |
| 1416 | { |
| 1417 | const struct vmbus_chan_attribute *attribute |
| 1418 | = container_of(attr, struct vmbus_chan_attribute, attr); |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1419 | struct vmbus_channel *chan |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1420 | = container_of(kobj, struct vmbus_channel, kobj); |
| 1421 | |
| 1422 | if (!attribute->show) |
| 1423 | return -EIO; |
| 1424 | |
| 1425 | return attribute->show(chan, buf); |
| 1426 | } |
| 1427 | |
| 1428 | static const struct sysfs_ops vmbus_chan_sysfs_ops = { |
| 1429 | .show = vmbus_chan_attr_show, |
| 1430 | }; |
| 1431 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1432 | static ssize_t out_mask_show(struct vmbus_channel *channel, char *buf) |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1433 | { |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1434 | struct hv_ring_buffer_info *rbi = &channel->outbound; |
| 1435 | ssize_t ret; |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1436 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1437 | mutex_lock(&rbi->ring_buffer_mutex); |
| 1438 | if (!rbi->ring_buffer) { |
| 1439 | mutex_unlock(&rbi->ring_buffer_mutex); |
Kimberly Brown | fcedbb2 | 2019-03-14 16:05:00 -0400 | [diff] [blame] | 1440 | return -EINVAL; |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1441 | } |
Kimberly Brown | fcedbb2 | 2019-03-14 16:05:00 -0400 | [diff] [blame] | 1442 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1443 | ret = sprintf(buf, "%u\n", rbi->ring_buffer->interrupt_mask); |
| 1444 | mutex_unlock(&rbi->ring_buffer_mutex); |
| 1445 | return ret; |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1446 | } |
Stephen Hemminger | 875c362 | 2018-01-04 14:13:25 -0800 | [diff] [blame] | 1447 | static VMBUS_CHAN_ATTR_RO(out_mask); |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1448 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1449 | static ssize_t in_mask_show(struct vmbus_channel *channel, char *buf) |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1450 | { |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1451 | struct hv_ring_buffer_info *rbi = &channel->inbound; |
| 1452 | ssize_t ret; |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1453 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1454 | mutex_lock(&rbi->ring_buffer_mutex); |
| 1455 | if (!rbi->ring_buffer) { |
| 1456 | mutex_unlock(&rbi->ring_buffer_mutex); |
Kimberly Brown | fcedbb2 | 2019-03-14 16:05:00 -0400 | [diff] [blame] | 1457 | return -EINVAL; |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1458 | } |
Kimberly Brown | fcedbb2 | 2019-03-14 16:05:00 -0400 | [diff] [blame] | 1459 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1460 | ret = sprintf(buf, "%u\n", rbi->ring_buffer->interrupt_mask); |
| 1461 | mutex_unlock(&rbi->ring_buffer_mutex); |
| 1462 | return ret; |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1463 | } |
Stephen Hemminger | 875c362 | 2018-01-04 14:13:25 -0800 | [diff] [blame] | 1464 | static VMBUS_CHAN_ATTR_RO(in_mask); |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1465 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1466 | static ssize_t read_avail_show(struct vmbus_channel *channel, char *buf) |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1467 | { |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1468 | struct hv_ring_buffer_info *rbi = &channel->inbound; |
| 1469 | ssize_t ret; |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1470 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1471 | mutex_lock(&rbi->ring_buffer_mutex); |
| 1472 | if (!rbi->ring_buffer) { |
| 1473 | mutex_unlock(&rbi->ring_buffer_mutex); |
Kimberly Brown | fcedbb2 | 2019-03-14 16:05:00 -0400 | [diff] [blame] | 1474 | return -EINVAL; |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1475 | } |
Kimberly Brown | fcedbb2 | 2019-03-14 16:05:00 -0400 | [diff] [blame] | 1476 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1477 | ret = sprintf(buf, "%u\n", hv_get_bytes_to_read(rbi)); |
| 1478 | mutex_unlock(&rbi->ring_buffer_mutex); |
| 1479 | return ret; |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1480 | } |
Stephen Hemminger | 875c362 | 2018-01-04 14:13:25 -0800 | [diff] [blame] | 1481 | static VMBUS_CHAN_ATTR_RO(read_avail); |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1482 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1483 | static ssize_t write_avail_show(struct vmbus_channel *channel, char *buf) |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1484 | { |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1485 | struct hv_ring_buffer_info *rbi = &channel->outbound; |
| 1486 | ssize_t ret; |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1487 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1488 | mutex_lock(&rbi->ring_buffer_mutex); |
| 1489 | if (!rbi->ring_buffer) { |
| 1490 | mutex_unlock(&rbi->ring_buffer_mutex); |
Kimberly Brown | fcedbb2 | 2019-03-14 16:05:00 -0400 | [diff] [blame] | 1491 | return -EINVAL; |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1492 | } |
Kimberly Brown | fcedbb2 | 2019-03-14 16:05:00 -0400 | [diff] [blame] | 1493 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1494 | ret = sprintf(buf, "%u\n", hv_get_bytes_to_write(rbi)); |
| 1495 | mutex_unlock(&rbi->ring_buffer_mutex); |
| 1496 | return ret; |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1497 | } |
Stephen Hemminger | 875c362 | 2018-01-04 14:13:25 -0800 | [diff] [blame] | 1498 | static VMBUS_CHAN_ATTR_RO(write_avail); |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1499 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1500 | static ssize_t show_target_cpu(struct vmbus_channel *channel, char *buf) |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1501 | { |
| 1502 | return sprintf(buf, "%u\n", channel->target_cpu); |
| 1503 | } |
Stephen Hemminger | 875c362 | 2018-01-04 14:13:25 -0800 | [diff] [blame] | 1504 | static VMBUS_CHAN_ATTR(cpu, S_IRUGO, show_target_cpu, NULL); |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1505 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1506 | static ssize_t channel_pending_show(struct vmbus_channel *channel, |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1507 | char *buf) |
| 1508 | { |
| 1509 | return sprintf(buf, "%d\n", |
| 1510 | channel_pending(channel, |
| 1511 | vmbus_connection.monitor_pages[1])); |
| 1512 | } |
Stephen Hemminger | 875c362 | 2018-01-04 14:13:25 -0800 | [diff] [blame] | 1513 | static VMBUS_CHAN_ATTR(pending, S_IRUGO, channel_pending_show, NULL); |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1514 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1515 | static ssize_t channel_latency_show(struct vmbus_channel *channel, |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1516 | char *buf) |
| 1517 | { |
| 1518 | return sprintf(buf, "%d\n", |
| 1519 | channel_latency(channel, |
| 1520 | vmbus_connection.monitor_pages[1])); |
| 1521 | } |
Stephen Hemminger | 875c362 | 2018-01-04 14:13:25 -0800 | [diff] [blame] | 1522 | static VMBUS_CHAN_ATTR(latency, S_IRUGO, channel_latency_show, NULL); |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1523 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1524 | static ssize_t channel_interrupts_show(struct vmbus_channel *channel, char *buf) |
Stephen Hemminger | 6981fbf | 2017-10-29 11:33:40 -0700 | [diff] [blame] | 1525 | { |
| 1526 | return sprintf(buf, "%llu\n", channel->interrupts); |
| 1527 | } |
Stephen Hemminger | 875c362 | 2018-01-04 14:13:25 -0800 | [diff] [blame] | 1528 | static VMBUS_CHAN_ATTR(interrupts, S_IRUGO, channel_interrupts_show, NULL); |
Stephen Hemminger | 6981fbf | 2017-10-29 11:33:40 -0700 | [diff] [blame] | 1529 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1530 | static ssize_t channel_events_show(struct vmbus_channel *channel, char *buf) |
Stephen Hemminger | 6981fbf | 2017-10-29 11:33:40 -0700 | [diff] [blame] | 1531 | { |
| 1532 | return sprintf(buf, "%llu\n", channel->sig_events); |
| 1533 | } |
Stephen Hemminger | 875c362 | 2018-01-04 14:13:25 -0800 | [diff] [blame] | 1534 | static VMBUS_CHAN_ATTR(events, S_IRUGO, channel_events_show, NULL); |
Stephen Hemminger | 6981fbf | 2017-10-29 11:33:40 -0700 | [diff] [blame] | 1535 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1536 | static ssize_t channel_intr_in_full_show(struct vmbus_channel *channel, |
Kimberly Brown | 396ae57 | 2019-02-04 02:13:09 -0500 | [diff] [blame] | 1537 | char *buf) |
| 1538 | { |
| 1539 | return sprintf(buf, "%llu\n", |
| 1540 | (unsigned long long)channel->intr_in_full); |
| 1541 | } |
| 1542 | static VMBUS_CHAN_ATTR(intr_in_full, 0444, channel_intr_in_full_show, NULL); |
| 1543 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1544 | static ssize_t channel_intr_out_empty_show(struct vmbus_channel *channel, |
Kimberly Brown | 396ae57 | 2019-02-04 02:13:09 -0500 | [diff] [blame] | 1545 | char *buf) |
| 1546 | { |
| 1547 | return sprintf(buf, "%llu\n", |
| 1548 | (unsigned long long)channel->intr_out_empty); |
| 1549 | } |
| 1550 | static VMBUS_CHAN_ATTR(intr_out_empty, 0444, channel_intr_out_empty_show, NULL); |
| 1551 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1552 | static ssize_t channel_out_full_first_show(struct vmbus_channel *channel, |
Kimberly Brown | 396ae57 | 2019-02-04 02:13:09 -0500 | [diff] [blame] | 1553 | char *buf) |
| 1554 | { |
| 1555 | return sprintf(buf, "%llu\n", |
| 1556 | (unsigned long long)channel->out_full_first); |
| 1557 | } |
| 1558 | static VMBUS_CHAN_ATTR(out_full_first, 0444, channel_out_full_first_show, NULL); |
| 1559 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1560 | static ssize_t channel_out_full_total_show(struct vmbus_channel *channel, |
Kimberly Brown | 396ae57 | 2019-02-04 02:13:09 -0500 | [diff] [blame] | 1561 | char *buf) |
| 1562 | { |
| 1563 | return sprintf(buf, "%llu\n", |
| 1564 | (unsigned long long)channel->out_full_total); |
| 1565 | } |
| 1566 | static VMBUS_CHAN_ATTR(out_full_total, 0444, channel_out_full_total_show, NULL); |
| 1567 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1568 | static ssize_t subchannel_monitor_id_show(struct vmbus_channel *channel, |
Stephen Hemminger | f0fa297 | 2018-01-09 10:29:06 -0800 | [diff] [blame] | 1569 | char *buf) |
| 1570 | { |
| 1571 | return sprintf(buf, "%u\n", channel->offermsg.monitorid); |
| 1572 | } |
| 1573 | static VMBUS_CHAN_ATTR(monitor_id, S_IRUGO, subchannel_monitor_id_show, NULL); |
| 1574 | |
Kimberly Brown | 14948e3 | 2019-03-14 16:05:15 -0400 | [diff] [blame] | 1575 | static ssize_t subchannel_id_show(struct vmbus_channel *channel, |
Stephen Hemminger | f0fa297 | 2018-01-09 10:29:06 -0800 | [diff] [blame] | 1576 | char *buf) |
| 1577 | { |
| 1578 | return sprintf(buf, "%u\n", |
| 1579 | channel->offermsg.offer.sub_channel_index); |
| 1580 | } |
| 1581 | static VMBUS_CHAN_ATTR_RO(subchannel_id); |
| 1582 | |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1583 | static struct attribute *vmbus_chan_attrs[] = { |
| 1584 | &chan_attr_out_mask.attr, |
| 1585 | &chan_attr_in_mask.attr, |
| 1586 | &chan_attr_read_avail.attr, |
| 1587 | &chan_attr_write_avail.attr, |
| 1588 | &chan_attr_cpu.attr, |
| 1589 | &chan_attr_pending.attr, |
| 1590 | &chan_attr_latency.attr, |
Stephen Hemminger | 6981fbf | 2017-10-29 11:33:40 -0700 | [diff] [blame] | 1591 | &chan_attr_interrupts.attr, |
| 1592 | &chan_attr_events.attr, |
Kimberly Brown | 396ae57 | 2019-02-04 02:13:09 -0500 | [diff] [blame] | 1593 | &chan_attr_intr_in_full.attr, |
| 1594 | &chan_attr_intr_out_empty.attr, |
| 1595 | &chan_attr_out_full_first.attr, |
| 1596 | &chan_attr_out_full_total.attr, |
Stephen Hemminger | f0fa297 | 2018-01-09 10:29:06 -0800 | [diff] [blame] | 1597 | &chan_attr_monitor_id.attr, |
| 1598 | &chan_attr_subchannel_id.attr, |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1599 | NULL |
| 1600 | }; |
| 1601 | |
Kimberly Brown | 46fc154 | 2019-03-19 00:04:01 -0400 | [diff] [blame] | 1602 | /* |
| 1603 | * Channel-level attribute_group callback function. Returns the permission for |
| 1604 | * each attribute, and returns 0 if an attribute is not visible. |
| 1605 | */ |
| 1606 | static umode_t vmbus_chan_attr_is_visible(struct kobject *kobj, |
| 1607 | struct attribute *attr, int idx) |
| 1608 | { |
| 1609 | const struct vmbus_channel *channel = |
| 1610 | container_of(kobj, struct vmbus_channel, kobj); |
| 1611 | |
| 1612 | /* Hide the monitor attributes if the monitor mechanism is not used. */ |
| 1613 | if (!channel->offermsg.monitor_allocated && |
| 1614 | (attr == &chan_attr_pending.attr || |
| 1615 | attr == &chan_attr_latency.attr || |
| 1616 | attr == &chan_attr_monitor_id.attr)) |
| 1617 | return 0; |
| 1618 | |
| 1619 | return attr->mode; |
| 1620 | } |
| 1621 | |
| 1622 | static struct attribute_group vmbus_chan_group = { |
| 1623 | .attrs = vmbus_chan_attrs, |
| 1624 | .is_visible = vmbus_chan_attr_is_visible |
| 1625 | }; |
| 1626 | |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1627 | static struct kobj_type vmbus_chan_ktype = { |
| 1628 | .sysfs_ops = &vmbus_chan_sysfs_ops, |
| 1629 | .release = vmbus_chan_release, |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1630 | }; |
| 1631 | |
| 1632 | /* |
| 1633 | * vmbus_add_channel_kobj - setup a sub-directory under device/channels |
| 1634 | */ |
| 1635 | int vmbus_add_channel_kobj(struct hv_device *dev, struct vmbus_channel *channel) |
| 1636 | { |
Kimberly Brown | 46fc154 | 2019-03-19 00:04:01 -0400 | [diff] [blame] | 1637 | const struct device *device = &dev->device; |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1638 | struct kobject *kobj = &channel->kobj; |
| 1639 | u32 relid = channel->offermsg.child_relid; |
| 1640 | int ret; |
| 1641 | |
| 1642 | kobj->kset = dev->channels_kset; |
| 1643 | ret = kobject_init_and_add(kobj, &vmbus_chan_ktype, NULL, |
| 1644 | "%u", relid); |
| 1645 | if (ret) |
| 1646 | return ret; |
| 1647 | |
Kimberly Brown | 46fc154 | 2019-03-19 00:04:01 -0400 | [diff] [blame] | 1648 | ret = sysfs_create_group(kobj, &vmbus_chan_group); |
| 1649 | |
| 1650 | if (ret) { |
| 1651 | /* |
| 1652 | * The calling functions' error handling paths will cleanup the |
| 1653 | * empty channel directory. |
| 1654 | */ |
| 1655 | dev_err(device, "Unable to set up channel sysfs files\n"); |
| 1656 | return ret; |
| 1657 | } |
| 1658 | |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1659 | kobject_uevent(kobj, KOBJ_ADD); |
| 1660 | |
| 1661 | return 0; |
| 1662 | } |
| 1663 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 1664 | /* |
Kimberly Brown | 46fc154 | 2019-03-19 00:04:01 -0400 | [diff] [blame] | 1665 | * vmbus_remove_channel_attr_group - remove the channel's attribute group |
| 1666 | */ |
| 1667 | void vmbus_remove_channel_attr_group(struct vmbus_channel *channel) |
| 1668 | { |
| 1669 | sysfs_remove_group(&channel->kobj, &vmbus_chan_group); |
| 1670 | } |
| 1671 | |
| 1672 | /* |
K. Y. Srinivasan | f2c7301 | 2011-09-08 07:24:12 -0700 | [diff] [blame] | 1673 | * vmbus_device_create - Creates and registers a new child device |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 1674 | * on the vmbus. |
Greg Kroah-Hartman | 90c9960 | 2009-09-02 07:11:14 -0700 | [diff] [blame] | 1675 | */ |
Andy Shevchenko | 593db80 | 2019-01-10 16:25:32 +0200 | [diff] [blame] | 1676 | struct hv_device *vmbus_device_create(const guid_t *type, |
| 1677 | const guid_t *instance, |
stephen hemminger | 1b9d48f | 2014-06-03 08:38:15 -0700 | [diff] [blame] | 1678 | struct vmbus_channel *channel) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1679 | { |
Nicolas Palix | 3d3b551 | 2009-07-28 17:32:53 +0200 | [diff] [blame] | 1680 | struct hv_device *child_device_obj; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1681 | |
K. Y. Srinivasan | 6bad88da | 2011-03-07 13:35:48 -0800 | [diff] [blame] | 1682 | child_device_obj = kzalloc(sizeof(struct hv_device), GFP_KERNEL); |
| 1683 | if (!child_device_obj) { |
Hank Janssen | 0a46618 | 2011-03-29 13:58:47 -0700 | [diff] [blame] | 1684 | pr_err("Unable to allocate device object for child device\n"); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1685 | return NULL; |
| 1686 | } |
| 1687 | |
Greg Kroah-Hartman | cae5b84 | 2010-10-21 09:05:27 -0700 | [diff] [blame] | 1688 | child_device_obj->channel = channel; |
Andy Shevchenko | 593db80 | 2019-01-10 16:25:32 +0200 | [diff] [blame] | 1689 | guid_copy(&child_device_obj->dev_type, type); |
| 1690 | guid_copy(&child_device_obj->dev_instance, instance); |
K. Y. Srinivasan | 7047f17 | 2015-12-25 20:00:30 -0800 | [diff] [blame] | 1691 | child_device_obj->vendor_id = 0x1414; /* MSFT vendor ID */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1692 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1693 | return child_device_obj; |
| 1694 | } |
| 1695 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 1696 | /* |
K. Y. Srinivasan | 22794281 | 2011-09-08 07:24:13 -0700 | [diff] [blame] | 1697 | * vmbus_device_register - Register the child device |
Greg Kroah-Hartman | 90c9960 | 2009-09-02 07:11:14 -0700 | [diff] [blame] | 1698 | */ |
K. Y. Srinivasan | 22794281 | 2011-09-08 07:24:13 -0700 | [diff] [blame] | 1699 | int vmbus_device_register(struct hv_device *child_device_obj) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1700 | { |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1701 | struct kobject *kobj = &child_device_obj->device.kobj; |
| 1702 | int ret; |
K. Y. Srinivasan | 6bad88da | 2011-03-07 13:35:48 -0800 | [diff] [blame] | 1703 | |
Stephen Hemminger | f6b2db0 | 2016-11-01 00:01:59 -0700 | [diff] [blame] | 1704 | dev_set_name(&child_device_obj->device, "%pUl", |
Vitaly Kuznetsov | b294809 | 2016-09-16 09:01:17 -0700 | [diff] [blame] | 1705 | child_device_obj->channel->offermsg.offer.if_instance.b); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1706 | |
K. Y. Srinivasan | 0bce28b | 2011-08-27 11:31:39 -0700 | [diff] [blame] | 1707 | child_device_obj->device.bus = &hv_bus; |
K. Y. Srinivasan | 607c1a1 | 2011-06-06 15:49:39 -0700 | [diff] [blame] | 1708 | child_device_obj->device.parent = &hv_acpi_dev->dev; |
K. Y. Srinivasan | 6bad88da | 2011-03-07 13:35:48 -0800 | [diff] [blame] | 1709 | child_device_obj->device.release = vmbus_device_release; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1710 | |
Greg Kroah-Hartman | 90c9960 | 2009-09-02 07:11:14 -0700 | [diff] [blame] | 1711 | /* |
| 1712 | * Register with the LDM. This will kick off the driver/device |
| 1713 | * binding...which will eventually call vmbus_match() and vmbus_probe() |
| 1714 | */ |
K. Y. Srinivasan | 6bad88da | 2011-03-07 13:35:48 -0800 | [diff] [blame] | 1715 | ret = device_register(&child_device_obj->device); |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1716 | if (ret) { |
Hank Janssen | 0a46618 | 2011-03-29 13:58:47 -0700 | [diff] [blame] | 1717 | pr_err("Unable to register child device\n"); |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1718 | return ret; |
| 1719 | } |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1720 | |
Stephen Hemminger | c2e5df6 | 2017-09-21 20:58:49 -0700 | [diff] [blame] | 1721 | child_device_obj->channels_kset = kset_create_and_add("channels", |
| 1722 | NULL, kobj); |
| 1723 | if (!child_device_obj->channels_kset) { |
| 1724 | ret = -ENOMEM; |
| 1725 | goto err_dev_unregister; |
| 1726 | } |
| 1727 | |
| 1728 | ret = vmbus_add_channel_kobj(child_device_obj, |
| 1729 | child_device_obj->channel); |
| 1730 | if (ret) { |
| 1731 | pr_err("Unable to register primary channeln"); |
| 1732 | goto err_kset_unregister; |
| 1733 | } |
| 1734 | |
| 1735 | return 0; |
| 1736 | |
| 1737 | err_kset_unregister: |
| 1738 | kset_unregister(child_device_obj->channels_kset); |
| 1739 | |
| 1740 | err_dev_unregister: |
| 1741 | device_unregister(&child_device_obj->device); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1742 | return ret; |
| 1743 | } |
| 1744 | |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 1745 | /* |
K. Y. Srinivasan | 696453b | 2011-09-08 07:24:14 -0700 | [diff] [blame] | 1746 | * vmbus_device_unregister - Remove the specified child device |
Hank Janssen | 3e18951 | 2010-03-04 22:11:00 +0000 | [diff] [blame] | 1747 | * from the vmbus. |
Greg Kroah-Hartman | 90c9960 | 2009-09-02 07:11:14 -0700 | [diff] [blame] | 1748 | */ |
K. Y. Srinivasan | 696453b | 2011-09-08 07:24:14 -0700 | [diff] [blame] | 1749 | void vmbus_device_unregister(struct hv_device *device_obj) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1750 | { |
Fernando Soto | 8467236 | 2013-06-14 23:13:35 +0000 | [diff] [blame] | 1751 | pr_debug("child device %s unregistered\n", |
| 1752 | dev_name(&device_obj->device)); |
| 1753 | |
Dexuan Cui | 869b556 | 2017-11-14 06:53:32 -0700 | [diff] [blame] | 1754 | kset_unregister(device_obj->channels_kset); |
| 1755 | |
Greg Kroah-Hartman | 90c9960 | 2009-09-02 07:11:14 -0700 | [diff] [blame] | 1756 | /* |
| 1757 | * Kick off the process of unregistering the device. |
| 1758 | * This will call vmbus_remove() and eventually vmbus_device_release() |
| 1759 | */ |
K. Y. Srinivasan | 6bad88da | 2011-03-07 13:35:48 -0800 | [diff] [blame] | 1760 | device_unregister(&device_obj->device); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1761 | } |
| 1762 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1763 | |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 1764 | /* |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 1765 | * VMBUS is an acpi enumerated device. Get the information we |
K. Y. Srinivasan | 90f3453 | 2014-01-29 18:14:39 -0800 | [diff] [blame] | 1766 | * need from DSDT. |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 1767 | */ |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 1768 | #define VTPM_BASE_ADDRESS 0xfed40000 |
K. Y. Srinivasan | 90f3453 | 2014-01-29 18:14:39 -0800 | [diff] [blame] | 1769 | static acpi_status vmbus_walk_resources(struct acpi_resource *res, void *ctx) |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 1770 | { |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 1771 | resource_size_t start = 0; |
| 1772 | resource_size_t end = 0; |
| 1773 | struct resource *new_res; |
| 1774 | struct resource **old_res = &hyperv_mmio; |
| 1775 | struct resource **prev_res = NULL; |
| 1776 | |
K. Y. Srinivasan | 90f3453 | 2014-01-29 18:14:39 -0800 | [diff] [blame] | 1777 | switch (res->type) { |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 1778 | |
| 1779 | /* |
| 1780 | * "Address" descriptors are for bus windows. Ignore |
| 1781 | * "memory" descriptors, which are for registers on |
| 1782 | * devices. |
| 1783 | */ |
| 1784 | case ACPI_RESOURCE_TYPE_ADDRESS32: |
| 1785 | start = res->data.address32.address.minimum; |
| 1786 | end = res->data.address32.address.maximum; |
Gerd Hoffmann | 4eb923f | 2014-02-24 14:17:08 +0100 | [diff] [blame] | 1787 | break; |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 1788 | |
K. Y. Srinivasan | 90f3453 | 2014-01-29 18:14:39 -0800 | [diff] [blame] | 1789 | case ACPI_RESOURCE_TYPE_ADDRESS64: |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 1790 | start = res->data.address64.address.minimum; |
| 1791 | end = res->data.address64.address.maximum; |
Gerd Hoffmann | 4eb923f | 2014-02-24 14:17:08 +0100 | [diff] [blame] | 1792 | break; |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 1793 | |
| 1794 | default: |
| 1795 | /* Unused resource type */ |
| 1796 | return AE_OK; |
| 1797 | |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 1798 | } |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 1799 | /* |
| 1800 | * Ignore ranges that are below 1MB, as they're not |
| 1801 | * necessary or useful here. |
| 1802 | */ |
| 1803 | if (end < 0x100000) |
| 1804 | return AE_OK; |
| 1805 | |
| 1806 | new_res = kzalloc(sizeof(*new_res), GFP_ATOMIC); |
| 1807 | if (!new_res) |
| 1808 | return AE_NO_MEMORY; |
| 1809 | |
| 1810 | /* If this range overlaps the virtual TPM, truncate it. */ |
| 1811 | if (end > VTPM_BASE_ADDRESS && start < VTPM_BASE_ADDRESS) |
| 1812 | end = VTPM_BASE_ADDRESS; |
| 1813 | |
| 1814 | new_res->name = "hyperv mmio"; |
| 1815 | new_res->flags = IORESOURCE_MEM; |
| 1816 | new_res->start = start; |
| 1817 | new_res->end = end; |
| 1818 | |
Jake Oshins | 40f26f3 | 2015-12-14 16:01:52 -0800 | [diff] [blame] | 1819 | /* |
Jake Oshins | 40f26f3 | 2015-12-14 16:01:52 -0800 | [diff] [blame] | 1820 | * If two ranges are adjacent, merge them. |
| 1821 | */ |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 1822 | do { |
| 1823 | if (!*old_res) { |
| 1824 | *old_res = new_res; |
| 1825 | break; |
| 1826 | } |
| 1827 | |
Jake Oshins | 40f26f3 | 2015-12-14 16:01:52 -0800 | [diff] [blame] | 1828 | if (((*old_res)->end + 1) == new_res->start) { |
| 1829 | (*old_res)->end = new_res->end; |
| 1830 | kfree(new_res); |
| 1831 | break; |
| 1832 | } |
| 1833 | |
| 1834 | if ((*old_res)->start == new_res->end + 1) { |
| 1835 | (*old_res)->start = new_res->start; |
| 1836 | kfree(new_res); |
| 1837 | break; |
| 1838 | } |
| 1839 | |
Jake Oshins | 23a0683 | 2016-04-05 10:22:53 -0700 | [diff] [blame] | 1840 | if ((*old_res)->start > new_res->end) { |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 1841 | new_res->sibling = *old_res; |
| 1842 | if (prev_res) |
| 1843 | (*prev_res)->sibling = new_res; |
| 1844 | *old_res = new_res; |
| 1845 | break; |
| 1846 | } |
| 1847 | |
| 1848 | prev_res = old_res; |
| 1849 | old_res = &(*old_res)->sibling; |
| 1850 | |
| 1851 | } while (1); |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 1852 | |
| 1853 | return AE_OK; |
| 1854 | } |
| 1855 | |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 1856 | static int vmbus_acpi_remove(struct acpi_device *device) |
| 1857 | { |
| 1858 | struct resource *cur_res; |
| 1859 | struct resource *next_res; |
| 1860 | |
| 1861 | if (hyperv_mmio) { |
Jake Oshins | 6d146ae | 2016-04-05 10:22:55 -0700 | [diff] [blame] | 1862 | if (fb_mmio) { |
| 1863 | __release_region(hyperv_mmio, fb_mmio->start, |
| 1864 | resource_size(fb_mmio)); |
| 1865 | fb_mmio = NULL; |
| 1866 | } |
| 1867 | |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 1868 | for (cur_res = hyperv_mmio; cur_res; cur_res = next_res) { |
| 1869 | next_res = cur_res->sibling; |
| 1870 | kfree(cur_res); |
| 1871 | } |
| 1872 | } |
| 1873 | |
| 1874 | return 0; |
| 1875 | } |
| 1876 | |
Jake Oshins | 6d146ae | 2016-04-05 10:22:55 -0700 | [diff] [blame] | 1877 | static void vmbus_reserve_fb(void) |
| 1878 | { |
| 1879 | int size; |
| 1880 | /* |
| 1881 | * Make a claim for the frame buffer in the resource tree under the |
| 1882 | * first node, which will be the one below 4GB. The length seems to |
| 1883 | * be underreported, particularly in a Generation 1 VM. So start out |
| 1884 | * reserving a larger area and make it smaller until it succeeds. |
| 1885 | */ |
| 1886 | |
| 1887 | if (screen_info.lfb_base) { |
| 1888 | if (efi_enabled(EFI_BOOT)) |
| 1889 | size = max_t(__u32, screen_info.lfb_size, 0x800000); |
| 1890 | else |
| 1891 | size = max_t(__u32, screen_info.lfb_size, 0x4000000); |
| 1892 | |
| 1893 | for (; !fb_mmio && (size >= 0x100000); size >>= 1) { |
| 1894 | fb_mmio = __request_region(hyperv_mmio, |
| 1895 | screen_info.lfb_base, size, |
| 1896 | fb_mmio_name, 0); |
| 1897 | } |
| 1898 | } |
| 1899 | } |
| 1900 | |
Jake Oshins | 3546448 | 2015-08-05 00:52:37 -0700 | [diff] [blame] | 1901 | /** |
| 1902 | * vmbus_allocate_mmio() - Pick a memory-mapped I/O range. |
| 1903 | * @new: If successful, supplied a pointer to the |
| 1904 | * allocated MMIO space. |
| 1905 | * @device_obj: Identifies the caller |
| 1906 | * @min: Minimum guest physical address of the |
| 1907 | * allocation |
| 1908 | * @max: Maximum guest physical address |
| 1909 | * @size: Size of the range to be allocated |
| 1910 | * @align: Alignment of the range to be allocated |
| 1911 | * @fb_overlap_ok: Whether this allocation can be allowed |
| 1912 | * to overlap the video frame buffer. |
| 1913 | * |
| 1914 | * This function walks the resources granted to VMBus by the |
| 1915 | * _CRS object in the ACPI namespace underneath the parent |
| 1916 | * "bridge" whether that's a root PCI bus in the Generation 1 |
| 1917 | * case or a Module Device in the Generation 2 case. It then |
| 1918 | * attempts to allocate from the global MMIO pool in a way that |
| 1919 | * matches the constraints supplied in these parameters and by |
| 1920 | * that _CRS. |
| 1921 | * |
| 1922 | * Return: 0 on success, -errno on failure |
| 1923 | */ |
| 1924 | int vmbus_allocate_mmio(struct resource **new, struct hv_device *device_obj, |
| 1925 | resource_size_t min, resource_size_t max, |
| 1926 | resource_size_t size, resource_size_t align, |
| 1927 | bool fb_overlap_ok) |
| 1928 | { |
Jake Oshins | be000f9 | 2016-04-05 10:22:54 -0700 | [diff] [blame] | 1929 | struct resource *iter, *shadow; |
Jake Oshins | ea37a6b | 2016-04-05 10:22:56 -0700 | [diff] [blame] | 1930 | resource_size_t range_min, range_max, start; |
Jake Oshins | 3546448 | 2015-08-05 00:52:37 -0700 | [diff] [blame] | 1931 | const char *dev_n = dev_name(&device_obj->device); |
Jake Oshins | ea37a6b | 2016-04-05 10:22:56 -0700 | [diff] [blame] | 1932 | int retval; |
Jake Oshins | e16dad6 | 2016-04-05 10:22:50 -0700 | [diff] [blame] | 1933 | |
| 1934 | retval = -ENXIO; |
| 1935 | down(&hyperv_mmio_lock); |
Jake Oshins | 3546448 | 2015-08-05 00:52:37 -0700 | [diff] [blame] | 1936 | |
Jake Oshins | ea37a6b | 2016-04-05 10:22:56 -0700 | [diff] [blame] | 1937 | /* |
| 1938 | * If overlaps with frame buffers are allowed, then first attempt to |
| 1939 | * make the allocation from within the reserved region. Because it |
| 1940 | * is already reserved, no shadow allocation is necessary. |
| 1941 | */ |
| 1942 | if (fb_overlap_ok && fb_mmio && !(min > fb_mmio->end) && |
| 1943 | !(max < fb_mmio->start)) { |
| 1944 | |
| 1945 | range_min = fb_mmio->start; |
| 1946 | range_max = fb_mmio->end; |
| 1947 | start = (range_min + align - 1) & ~(align - 1); |
| 1948 | for (; start + size - 1 <= range_max; start += align) { |
| 1949 | *new = request_mem_region_exclusive(start, size, dev_n); |
| 1950 | if (*new) { |
| 1951 | retval = 0; |
| 1952 | goto exit; |
| 1953 | } |
| 1954 | } |
| 1955 | } |
| 1956 | |
Jake Oshins | 3546448 | 2015-08-05 00:52:37 -0700 | [diff] [blame] | 1957 | for (iter = hyperv_mmio; iter; iter = iter->sibling) { |
| 1958 | if ((iter->start >= max) || (iter->end <= min)) |
| 1959 | continue; |
| 1960 | |
| 1961 | range_min = iter->start; |
| 1962 | range_max = iter->end; |
Jake Oshins | ea37a6b | 2016-04-05 10:22:56 -0700 | [diff] [blame] | 1963 | start = (range_min + align - 1) & ~(align - 1); |
| 1964 | for (; start + size - 1 <= range_max; start += align) { |
| 1965 | shadow = __request_region(iter, start, size, NULL, |
| 1966 | IORESOURCE_BUSY); |
| 1967 | if (!shadow) |
| 1968 | continue; |
Jake Oshins | 3546448 | 2015-08-05 00:52:37 -0700 | [diff] [blame] | 1969 | |
Jake Oshins | ea37a6b | 2016-04-05 10:22:56 -0700 | [diff] [blame] | 1970 | *new = request_mem_region_exclusive(start, size, dev_n); |
| 1971 | if (*new) { |
| 1972 | shadow->name = (char *)*new; |
| 1973 | retval = 0; |
| 1974 | goto exit; |
Jake Oshins | 3546448 | 2015-08-05 00:52:37 -0700 | [diff] [blame] | 1975 | } |
| 1976 | |
Jake Oshins | ea37a6b | 2016-04-05 10:22:56 -0700 | [diff] [blame] | 1977 | __release_region(iter, start, size); |
Jake Oshins | 3546448 | 2015-08-05 00:52:37 -0700 | [diff] [blame] | 1978 | } |
| 1979 | } |
| 1980 | |
Jake Oshins | e16dad6 | 2016-04-05 10:22:50 -0700 | [diff] [blame] | 1981 | exit: |
| 1982 | up(&hyperv_mmio_lock); |
| 1983 | return retval; |
Jake Oshins | 3546448 | 2015-08-05 00:52:37 -0700 | [diff] [blame] | 1984 | } |
| 1985 | EXPORT_SYMBOL_GPL(vmbus_allocate_mmio); |
| 1986 | |
Jake Oshins | 619848b | 2015-12-14 16:01:39 -0800 | [diff] [blame] | 1987 | /** |
Jake Oshins | 97fb77dc | 2016-04-05 10:22:51 -0700 | [diff] [blame] | 1988 | * vmbus_free_mmio() - Free a memory-mapped I/O range. |
| 1989 | * @start: Base address of region to release. |
| 1990 | * @size: Size of the range to be allocated |
| 1991 | * |
| 1992 | * This function releases anything requested by |
| 1993 | * vmbus_mmio_allocate(). |
| 1994 | */ |
| 1995 | void vmbus_free_mmio(resource_size_t start, resource_size_t size) |
| 1996 | { |
Jake Oshins | be000f9 | 2016-04-05 10:22:54 -0700 | [diff] [blame] | 1997 | struct resource *iter; |
| 1998 | |
| 1999 | down(&hyperv_mmio_lock); |
| 2000 | for (iter = hyperv_mmio; iter; iter = iter->sibling) { |
| 2001 | if ((iter->start >= start + size) || (iter->end <= start)) |
| 2002 | continue; |
| 2003 | |
| 2004 | __release_region(iter, start, size); |
| 2005 | } |
Jake Oshins | 97fb77dc | 2016-04-05 10:22:51 -0700 | [diff] [blame] | 2006 | release_mem_region(start, size); |
Jake Oshins | be000f9 | 2016-04-05 10:22:54 -0700 | [diff] [blame] | 2007 | up(&hyperv_mmio_lock); |
Jake Oshins | 97fb77dc | 2016-04-05 10:22:51 -0700 | [diff] [blame] | 2008 | |
| 2009 | } |
| 2010 | EXPORT_SYMBOL_GPL(vmbus_free_mmio); |
| 2011 | |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 2012 | static int vmbus_acpi_add(struct acpi_device *device) |
| 2013 | { |
| 2014 | acpi_status result; |
K. Y. Srinivasan | 90f3453 | 2014-01-29 18:14:39 -0800 | [diff] [blame] | 2015 | int ret_val = -ENODEV; |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 2016 | struct acpi_device *ancestor; |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 2017 | |
K. Y. Srinivasan | 607c1a1 | 2011-06-06 15:49:39 -0700 | [diff] [blame] | 2018 | hv_acpi_dev = device; |
| 2019 | |
K. Y. Srinivasan | 0a4425b | 2011-08-27 11:31:38 -0700 | [diff] [blame] | 2020 | result = acpi_walk_resources(device->handle, METHOD_NAME__CRS, |
K. Y. Srinivasan | 90f3453 | 2014-01-29 18:14:39 -0800 | [diff] [blame] | 2021 | vmbus_walk_resources, NULL); |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 2022 | |
K. Y. Srinivasan | 90f3453 | 2014-01-29 18:14:39 -0800 | [diff] [blame] | 2023 | if (ACPI_FAILURE(result)) |
| 2024 | goto acpi_walk_err; |
| 2025 | /* |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 2026 | * Some ancestor of the vmbus acpi device (Gen1 or Gen2 |
| 2027 | * firmware) is the VMOD that has the mmio ranges. Get that. |
K. Y. Srinivasan | 90f3453 | 2014-01-29 18:14:39 -0800 | [diff] [blame] | 2028 | */ |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 2029 | for (ancestor = device->parent; ancestor; ancestor = ancestor->parent) { |
| 2030 | result = acpi_walk_resources(ancestor->handle, METHOD_NAME__CRS, |
| 2031 | vmbus_walk_resources, NULL); |
K. Y. Srinivasan | 90f3453 | 2014-01-29 18:14:39 -0800 | [diff] [blame] | 2032 | |
| 2033 | if (ACPI_FAILURE(result)) |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 2034 | continue; |
Jake Oshins | 6d146ae | 2016-04-05 10:22:55 -0700 | [diff] [blame] | 2035 | if (hyperv_mmio) { |
| 2036 | vmbus_reserve_fb(); |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 2037 | break; |
Jake Oshins | 6d146ae | 2016-04-05 10:22:55 -0700 | [diff] [blame] | 2038 | } |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 2039 | } |
K. Y. Srinivasan | 90f3453 | 2014-01-29 18:14:39 -0800 | [diff] [blame] | 2040 | ret_val = 0; |
| 2041 | |
| 2042 | acpi_walk_err: |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 2043 | complete(&probe_event); |
Jake Oshins | 7f163a6 | 2015-08-05 00:52:36 -0700 | [diff] [blame] | 2044 | if (ret_val) |
| 2045 | vmbus_acpi_remove(device); |
K. Y. Srinivasan | 90f3453 | 2014-01-29 18:14:39 -0800 | [diff] [blame] | 2046 | return ret_val; |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 2047 | } |
| 2048 | |
| 2049 | static const struct acpi_device_id vmbus_acpi_device_ids[] = { |
| 2050 | {"VMBUS", 0}, |
K. Y. Srinivasan | 9d7b18d | 2011-06-06 15:49:42 -0700 | [diff] [blame] | 2051 | {"VMBus", 0}, |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 2052 | {"", 0}, |
| 2053 | }; |
| 2054 | MODULE_DEVICE_TABLE(acpi, vmbus_acpi_device_ids); |
| 2055 | |
| 2056 | static struct acpi_driver vmbus_acpi_driver = { |
| 2057 | .name = "vmbus", |
| 2058 | .ids = vmbus_acpi_device_ids, |
| 2059 | .ops = { |
| 2060 | .add = vmbus_acpi_add, |
Vitaly Kuznetsov | e4ecb41 | 2015-04-22 21:31:28 -0700 | [diff] [blame] | 2061 | .remove = vmbus_acpi_remove, |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 2062 | }, |
| 2063 | }; |
| 2064 | |
Vitaly Kuznetsov | 2517281 | 2015-08-01 16:08:07 -0700 | [diff] [blame] | 2065 | static void hv_kexec_handler(void) |
| 2066 | { |
Vitaly Kuznetsov | 2517281 | 2015-08-01 16:08:07 -0700 | [diff] [blame] | 2067 | hv_synic_clockevents_cleanup(); |
Vitaly Kuznetsov | 75ff3a8 | 2016-02-26 15:13:16 -0800 | [diff] [blame] | 2068 | vmbus_initiate_unload(false); |
Vitaly Kuznetsov | 523b940 | 2016-12-07 14:53:12 -0800 | [diff] [blame] | 2069 | vmbus_connection.conn_state = DISCONNECTED; |
| 2070 | /* Make sure conn_state is set as hv_synic_cleanup checks for it */ |
| 2071 | mb(); |
Vitaly Kuznetsov | 76d36ab | 2016-12-07 14:53:11 -0800 | [diff] [blame] | 2072 | cpuhp_remove_state(hyperv_cpuhp_online); |
Vitaly Kuznetsov | d6f3609 | 2017-01-28 12:37:14 -0700 | [diff] [blame] | 2073 | hyperv_cleanup(); |
Vitaly Kuznetsov | 2517281 | 2015-08-01 16:08:07 -0700 | [diff] [blame] | 2074 | }; |
| 2075 | |
Vitaly Kuznetsov | b4370df | 2015-08-01 16:08:09 -0700 | [diff] [blame] | 2076 | static void hv_crash_handler(struct pt_regs *regs) |
| 2077 | { |
Vitaly Kuznetsov | 75ff3a8 | 2016-02-26 15:13:16 -0800 | [diff] [blame] | 2078 | vmbus_initiate_unload(true); |
Vitaly Kuznetsov | b4370df | 2015-08-01 16:08:09 -0700 | [diff] [blame] | 2079 | /* |
| 2080 | * In crash handler we can't schedule synic cleanup for all CPUs, |
| 2081 | * doing the cleanup for current CPU only. This should be sufficient |
| 2082 | * for kdump. |
| 2083 | */ |
Vitaly Kuznetsov | 523b940 | 2016-12-07 14:53:12 -0800 | [diff] [blame] | 2084 | vmbus_connection.conn_state = DISCONNECTED; |
Vitaly Kuznetsov | 76d36ab | 2016-12-07 14:53:11 -0800 | [diff] [blame] | 2085 | hv_synic_cleanup(smp_processor_id()); |
Vitaly Kuznetsov | d6f3609 | 2017-01-28 12:37:14 -0700 | [diff] [blame] | 2086 | hyperv_cleanup(); |
Vitaly Kuznetsov | b4370df | 2015-08-01 16:08:09 -0700 | [diff] [blame] | 2087 | }; |
| 2088 | |
K. Y. Srinivasan | 607c1a1 | 2011-06-06 15:49:39 -0700 | [diff] [blame] | 2089 | static int __init hv_acpi_init(void) |
K. Y. Srinivasan | 1168ac2 | 2011-03-15 15:03:32 -0700 | [diff] [blame] | 2090 | { |
K. Y. Srinivasan | 2dda95f | 2011-07-15 13:38:56 -0700 | [diff] [blame] | 2091 | int ret, t; |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 2092 | |
Michael Kelley | 4a5f3cd | 2017-12-22 11:19:02 -0700 | [diff] [blame] | 2093 | if (!hv_is_hyperv_initialized()) |
Jason Wang | 0592969 | 2012-08-17 18:52:43 +0800 | [diff] [blame] | 2094 | return -ENODEV; |
| 2095 | |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 2096 | init_completion(&probe_event); |
| 2097 | |
| 2098 | /* |
K. Y. Srinivasan | efc2672 | 2015-12-14 16:01:46 -0800 | [diff] [blame] | 2099 | * Get ACPI resources first. |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 2100 | */ |
K. Y. Srinivasan | 0246604 | 2011-06-06 15:49:40 -0700 | [diff] [blame] | 2101 | ret = acpi_bus_register_driver(&vmbus_acpi_driver); |
| 2102 | |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 2103 | if (ret) |
| 2104 | return ret; |
| 2105 | |
K. Y. Srinivasan | 2dda95f | 2011-07-15 13:38:56 -0700 | [diff] [blame] | 2106 | t = wait_for_completion_timeout(&probe_event, 5*HZ); |
| 2107 | if (t == 0) { |
| 2108 | ret = -ETIMEDOUT; |
| 2109 | goto cleanup; |
| 2110 | } |
K. Y. Srinivasan | b0069f4 | 2011-04-29 13:45:15 -0700 | [diff] [blame] | 2111 | |
K. Y. Srinivasan | efc2672 | 2015-12-14 16:01:46 -0800 | [diff] [blame] | 2112 | ret = vmbus_bus_init(); |
K. Y. Srinivasan | 91fd799 | 2011-06-16 13:16:38 -0700 | [diff] [blame] | 2113 | if (ret) |
K. Y. Srinivasan | 2dda95f | 2011-07-15 13:38:56 -0700 | [diff] [blame] | 2114 | goto cleanup; |
| 2115 | |
Vitaly Kuznetsov | 2517281 | 2015-08-01 16:08:07 -0700 | [diff] [blame] | 2116 | hv_setup_kexec_handler(hv_kexec_handler); |
Vitaly Kuznetsov | b4370df | 2015-08-01 16:08:09 -0700 | [diff] [blame] | 2117 | hv_setup_crash_handler(hv_crash_handler); |
Vitaly Kuznetsov | 2517281 | 2015-08-01 16:08:07 -0700 | [diff] [blame] | 2118 | |
K. Y. Srinivasan | 2dda95f | 2011-07-15 13:38:56 -0700 | [diff] [blame] | 2119 | return 0; |
| 2120 | |
| 2121 | cleanup: |
| 2122 | acpi_bus_unregister_driver(&vmbus_acpi_driver); |
K. Y. Srinivasan | cf6a2ea | 2011-12-01 09:59:34 -0800 | [diff] [blame] | 2123 | hv_acpi_dev = NULL; |
K. Y. Srinivasan | 91fd799 | 2011-06-16 13:16:38 -0700 | [diff] [blame] | 2124 | return ret; |
K. Y. Srinivasan | 1168ac2 | 2011-03-15 15:03:32 -0700 | [diff] [blame] | 2125 | } |
| 2126 | |
K. Y. Srinivasan | 93e5bd0 | 2011-12-12 09:29:17 -0800 | [diff] [blame] | 2127 | static void __exit vmbus_exit(void) |
| 2128 | { |
Vitaly Kuznetsov | e72e7ac | 2015-02-27 11:25:55 -0800 | [diff] [blame] | 2129 | int cpu; |
| 2130 | |
Vitaly Kuznetsov | 2517281 | 2015-08-01 16:08:07 -0700 | [diff] [blame] | 2131 | hv_remove_kexec_handler(); |
Vitaly Kuznetsov | b4370df | 2015-08-01 16:08:09 -0700 | [diff] [blame] | 2132 | hv_remove_crash_handler(); |
Vitaly Kuznetsov | 09a1962 | 2015-02-27 11:25:54 -0800 | [diff] [blame] | 2133 | vmbus_connection.conn_state = DISCONNECTED; |
Vitaly Kuznetsov | e086748 | 2015-02-27 11:25:57 -0800 | [diff] [blame] | 2134 | hv_synic_clockevents_cleanup(); |
K. Y. Srinivasan | 2db84ef | 2015-04-22 21:31:32 -0700 | [diff] [blame] | 2135 | vmbus_disconnect(); |
Thomas Gleixner | 76d388c | 2014-03-05 13:42:14 +0100 | [diff] [blame] | 2136 | hv_remove_vmbus_irq(); |
Stephen Hemminger | 37cdd99 | 2017-02-11 23:02:19 -0700 | [diff] [blame] | 2137 | for_each_online_cpu(cpu) { |
| 2138 | struct hv_per_cpu_context *hv_cpu |
| 2139 | = per_cpu_ptr(hv_context.cpu_context, cpu); |
| 2140 | |
| 2141 | tasklet_kill(&hv_cpu->msg_dpc); |
| 2142 | } |
K. Y. Srinivasan | 93e5bd0 | 2011-12-12 09:29:17 -0800 | [diff] [blame] | 2143 | vmbus_free_channels(); |
Stephen Hemminger | 37cdd99 | 2017-02-11 23:02:19 -0700 | [diff] [blame] | 2144 | |
Denis V. Lunev | cc2dd40 | 2015-08-01 16:08:20 -0700 | [diff] [blame] | 2145 | if (ms_hyperv.misc_features & HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE) { |
Sunil Muthuswamy | 81b18bc | 2018-07-08 02:56:51 +0000 | [diff] [blame] | 2146 | kmsg_dump_unregister(&hv_kmsg_dumper); |
Vitaly Kuznetsov | 510f7ae | 2015-08-01 16:08:10 -0700 | [diff] [blame] | 2147 | unregister_die_notifier(&hyperv_die_block); |
Vitaly Kuznetsov | 096c605 | 2015-04-22 21:31:29 -0700 | [diff] [blame] | 2148 | atomic_notifier_chain_unregister(&panic_notifier_list, |
| 2149 | &hyperv_panic_block); |
| 2150 | } |
Sunil Muthuswamy | 81b18bc | 2018-07-08 02:56:51 +0000 | [diff] [blame] | 2151 | |
| 2152 | free_page((unsigned long)hv_panic_page); |
Sunil Muthuswamy | 8afc06d | 2018-07-28 21:58:46 +0000 | [diff] [blame] | 2153 | unregister_sysctl_table(hv_ctl_table_hdr); |
| 2154 | hv_ctl_table_hdr = NULL; |
K. Y. Srinivasan | 93e5bd0 | 2011-12-12 09:29:17 -0800 | [diff] [blame] | 2155 | bus_unregister(&hv_bus); |
Stephen Hemminger | 37cdd99 | 2017-02-11 23:02:19 -0700 | [diff] [blame] | 2156 | |
Vitaly Kuznetsov | 76d36ab | 2016-12-07 14:53:11 -0800 | [diff] [blame] | 2157 | cpuhp_remove_state(hyperv_cpuhp_online); |
Vitaly Kuznetsov | 06210b4 | 2015-08-01 16:08:05 -0700 | [diff] [blame] | 2158 | hv_synic_free(); |
K. Y. Srinivasan | 93e5bd0 | 2011-12-12 09:29:17 -0800 | [diff] [blame] | 2159 | acpi_bus_unregister_driver(&vmbus_acpi_driver); |
| 2160 | } |
| 2161 | |
K. Y. Srinivasan | 1168ac2 | 2011-03-15 15:03:32 -0700 | [diff] [blame] | 2162 | |
Greg Kroah-Hartman | 90c9960 | 2009-09-02 07:11:14 -0700 | [diff] [blame] | 2163 | MODULE_LICENSE("GPL"); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 2164 | |
K. Y. Srinivasan | 43d4e11 | 2011-10-24 11:28:12 -0700 | [diff] [blame] | 2165 | subsys_initcall(hv_acpi_init); |
K. Y. Srinivasan | 93e5bd0 | 2011-12-12 09:29:17 -0800 | [diff] [blame] | 2166 | module_exit(vmbus_exit); |