blob: 92b1874b3eb390a9cc29942b22861700bb6c363d [file] [log] [blame]
Thomas Gleixner3b20eb22019-05-29 16:57:35 -07001// SPDX-License-Identifier: GPL-2.0-only
Hank Janssen3e7ee492009-07-13 16:02:34 -07002/*
Hank Janssen3e7ee492009-07-13 16:02:34 -07003 * Copyright (c) 2009, Microsoft Corporation.
4 *
Hank Janssen3e7ee492009-07-13 16:02:34 -07005 * Authors:
6 * Haiyang Zhang <haiyangz@microsoft.com>
7 * Hank Janssen <hjanssen@microsoft.com>
K. Y. Srinivasanb0069f42011-04-29 13:45:15 -07008 * K. Y. Srinivasan <kys@microsoft.com>
Hank Janssen3e7ee492009-07-13 16:02:34 -07009 */
Hank Janssen0a466182011-03-29 13:58:47 -070010#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
11
Hank Janssen3e7ee492009-07-13 16:02:34 -070012#include <linux/init.h>
13#include <linux/module.h>
14#include <linux/device.h>
Hank Janssen3e7ee492009-07-13 16:02:34 -070015#include <linux/interrupt.h>
16#include <linux/sysctl.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090017#include <linux/slab.h>
K. Y. Srinivasanb0069f42011-04-29 13:45:15 -070018#include <linux/acpi.h>
Haiyang Zhang8b5d6d32010-05-28 23:22:44 +000019#include <linux/completion.h>
Greg Kroah-Hartman46a97192011-10-04 12:29:52 -070020#include <linux/hyperv.h>
K. Y. Srinivasanb0209502012-12-01 06:46:54 -080021#include <linux/kernel_stat.h>
K. Y. Srinivasan4061ed92015-01-09 23:54:32 -080022#include <linux/clockchips.h>
Vitaly Kuznetsove5132292015-02-27 11:25:51 -080023#include <linux/cpu.h>
Ingo Molnar68db0cf2017-02-08 18:51:37 +010024#include <linux/sched/task_stack.h>
25
K. Y. Srinivasan302a3c02013-02-17 11:30:44 -080026#include <asm/mshyperv.h>
Nick Meier96c1d052015-02-28 11:39:01 -080027#include <linux/notifier.h>
28#include <linux/ptrace.h>
Jake Oshins35464482015-08-05 00:52:37 -070029#include <linux/screen_info.h>
Vitaly Kuznetsov510f7ae2015-08-01 16:08:10 -070030#include <linux/kdebug.h>
Jake Oshins6d146ae2016-04-05 10:22:55 -070031#include <linux/efi.h>
Stephan Mueller4b44f2d2016-05-02 02:14:34 -040032#include <linux/random.h>
K. Y. Srinivasan0f2a6612011-05-12 19:34:28 -070033#include "hyperv_vmbus.h"
Hank Janssen3e7ee492009-07-13 16:02:34 -070034
Stephen Hemmingerfc769362016-12-03 12:34:39 -080035struct vmbus_dynid {
36 struct list_head node;
37 struct hv_vmbus_device_id id;
38};
39
K. Y. Srinivasan607c1a12011-06-06 15:49:39 -070040static struct acpi_device *hv_acpi_dev;
K. Y. Srinivasan1168ac22011-03-15 15:03:32 -070041
K. Y. Srinivasan71a66552011-04-29 13:45:04 -070042static struct completion probe_event;
Hank Janssen3e7ee492009-07-13 16:02:34 -070043
Vitaly Kuznetsov76d36ab2016-12-07 14:53:11 -080044static int hyperv_cpuhp_online;
Nick Meier96c1d052015-02-28 11:39:01 -080045
Sunil Muthuswamy81b18bc2018-07-08 02:56:51 +000046static void *hv_panic_page;
47
Vitaly Kuznetsov510f7ae2015-08-01 16:08:10 -070048static 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. Srinivasan7ed43252017-10-29 11:33:41 -070055 hyperv_report_panic(regs, val);
Nick Meier96c1d052015-02-28 11:39:01 -080056 return NOTIFY_DONE;
57}
58
Vitaly Kuznetsov510f7ae2015-08-01 16:08:10 -070059static 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. Srinivasan7ed43252017-10-29 11:33:41 -070065 hyperv_report_panic(regs, val);
Vitaly Kuznetsov510f7ae2015-08-01 16:08:10 -070066 return NOTIFY_DONE;
67}
68
69static struct notifier_block hyperv_die_block = {
70 .notifier_call = hyperv_die_event,
71};
Nick Meier96c1d052015-02-28 11:39:01 -080072static struct notifier_block hyperv_panic_block = {
73 .notifier_call = hyperv_panic_event,
74};
75
Jake Oshins6d146ae2016-04-05 10:22:55 -070076static const char *fb_mmio_name = "fb_range";
77static struct resource *fb_mmio;
Stephen Hemmingere2e80842016-09-07 05:39:33 -070078static struct resource *hyperv_mmio;
79static DEFINE_SEMAPHORE(hyperv_mmio_lock);
Hank Janssen3e7ee492009-07-13 16:02:34 -070080
K. Y. Srinivasancf6a2ea2011-12-01 09:59:34 -080081static int vmbus_exists(void)
82{
83 if (hv_acpi_dev == NULL)
84 return -ENODEV;
85
86 return 0;
87}
88
Olaf Heringfd776ba2011-09-02 18:25:56 +020089#define VMBUS_ALIAS_LEN ((sizeof((struct hv_vmbus_device_id *)0)->guid) * 2)
90static 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 Hemmingerc2e5df62017-09-21 20:58:49 -070097static u8 channel_monitor_group(const struct vmbus_channel *channel)
Greg Kroah-Hartman76c52bb2013-09-13 11:32:56 -070098{
99 return (u8)channel->offermsg.monitorid / 32;
100}
101
Stephen Hemmingerc2e5df62017-09-21 20:58:49 -0700102static u8 channel_monitor_offset(const struct vmbus_channel *channel)
Greg Kroah-Hartman76c52bb2013-09-13 11:32:56 -0700103{
104 return (u8)channel->offermsg.monitorid % 32;
105}
106
Stephen Hemmingerc2e5df62017-09-21 20:58:49 -0700107static u32 channel_pending(const struct vmbus_channel *channel,
108 const struct hv_monitor_page *monitor_page)
Greg Kroah-Hartman76c52bb2013-09-13 11:32:56 -0700109{
110 u8 monitor_group = channel_monitor_group(channel);
Stephen Hemmingerc2e5df62017-09-21 20:58:49 -0700111
Greg Kroah-Hartman76c52bb2013-09-13 11:32:56 -0700112 return monitor_page->trigger_group[monitor_group].pending;
113}
114
Stephen Hemmingerc2e5df62017-09-21 20:58:49 -0700115static u32 channel_latency(const struct vmbus_channel *channel,
116 const struct hv_monitor_page *monitor_page)
Greg Kroah-Hartman1cee2722013-09-13 11:32:57 -0700117{
118 u8 monitor_group = channel_monitor_group(channel);
119 u8 monitor_offset = channel_monitor_offset(channel);
Stephen Hemmingerc2e5df62017-09-21 20:58:49 -0700120
Greg Kroah-Hartman1cee2722013-09-13 11:32:57 -0700121 return monitor_page->latency[monitor_group][monitor_offset];
122}
123
Greg Kroah-Hartman4947c742013-09-13 11:32:58 -0700124static 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-Hartman03f3a912013-09-13 11:32:49 -0700132static 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}
141static DEVICE_ATTR_RO(id);
142
Greg Kroah-Hartmana8fb5f32013-09-13 11:32:50 -0700143static 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}
152static DEVICE_ATTR_RO(state);
153
Greg Kroah-Hartman5ffd00e2013-09-13 11:32:51 -0700154static 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}
163static DEVICE_ATTR_RO(monitor_id);
164
Greg Kroah-Hartman68234c02013-09-13 11:32:53 -0700165static 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}
175static DEVICE_ATTR_RO(class_id);
176
Greg Kroah-Hartman7c55e1d2013-09-13 11:32:54 -0700177static 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}
187static DEVICE_ATTR_RO(device_id);
188
Greg Kroah-Hartman647fa372013-09-13 11:32:52 -0700189static 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}
198static DEVICE_ATTR_RO(modalias);
199
Stephen Hemminger7ceb1c32018-07-28 21:58:48 +0000200#ifdef CONFIG_NUMA
201static 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}
211static DEVICE_ATTR_RO(numa_node);
212#endif
213
Greg Kroah-Hartman76c52bb2013-09-13 11:32:56 -0700214static 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 Brownfd8e3c32019-02-19 00:38:06 -0500224 vmbus_connection.monitor_pages[0]));
Greg Kroah-Hartman76c52bb2013-09-13 11:32:56 -0700225}
226static DEVICE_ATTR_RO(server_monitor_pending);
227
228static 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}
240static DEVICE_ATTR_RO(client_monitor_pending);
Greg Kroah-Hartman68234c02013-09-13 11:32:53 -0700241
Greg Kroah-Hartman1cee2722013-09-13 11:32:57 -0700242static 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}
254static DEVICE_ATTR_RO(server_monitor_latency);
255
256static 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}
268static DEVICE_ATTR_RO(client_monitor_latency);
269
Greg Kroah-Hartman4947c742013-09-13 11:32:58 -0700270static 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}
282static DEVICE_ATTR_RO(server_monitor_conn_id);
283
284static 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}
296static DEVICE_ATTR_RO(client_monitor_conn_id);
297
Greg Kroah-Hartman98f4c652013-09-13 11:33:01 -0700298static 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 Cuiba50bf12018-12-17 20:16:09 +0000303 int ret;
Greg Kroah-Hartman98f4c652013-09-13 11:33:01 -0700304
305 if (!hv_dev->channel)
306 return -ENODEV;
Dexuan Cuiba50bf12018-12-17 20:16:09 +0000307
308 ret = hv_ringbuffer_get_debuginfo(&hv_dev->channel->outbound,
309 &outbound);
310 if (ret < 0)
311 return ret;
312
Greg Kroah-Hartman98f4c652013-09-13 11:33:01 -0700313 return sprintf(buf, "%d\n", outbound.current_interrupt_mask);
314}
315static DEVICE_ATTR_RO(out_intr_mask);
316
317static 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 Cuiba50bf12018-12-17 20:16:09 +0000322 int ret;
Greg Kroah-Hartman98f4c652013-09-13 11:33:01 -0700323
324 if (!hv_dev->channel)
325 return -ENODEV;
Dexuan Cuiba50bf12018-12-17 20:16:09 +0000326
327 ret = hv_ringbuffer_get_debuginfo(&hv_dev->channel->outbound,
328 &outbound);
329 if (ret < 0)
330 return ret;
Greg Kroah-Hartman98f4c652013-09-13 11:33:01 -0700331 return sprintf(buf, "%d\n", outbound.current_read_index);
332}
333static DEVICE_ATTR_RO(out_read_index);
334
335static 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 Cuiba50bf12018-12-17 20:16:09 +0000341 int ret;
Greg Kroah-Hartman98f4c652013-09-13 11:33:01 -0700342
343 if (!hv_dev->channel)
344 return -ENODEV;
Dexuan Cuiba50bf12018-12-17 20:16:09 +0000345
346 ret = hv_ringbuffer_get_debuginfo(&hv_dev->channel->outbound,
347 &outbound);
348 if (ret < 0)
349 return ret;
Greg Kroah-Hartman98f4c652013-09-13 11:33:01 -0700350 return sprintf(buf, "%d\n", outbound.current_write_index);
351}
352static DEVICE_ATTR_RO(out_write_index);
353
354static 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 Cuiba50bf12018-12-17 20:16:09 +0000360 int ret;
Greg Kroah-Hartman98f4c652013-09-13 11:33:01 -0700361
362 if (!hv_dev->channel)
363 return -ENODEV;
Dexuan Cuiba50bf12018-12-17 20:16:09 +0000364
365 ret = hv_ringbuffer_get_debuginfo(&hv_dev->channel->outbound,
366 &outbound);
367 if (ret < 0)
368 return ret;
Greg Kroah-Hartman98f4c652013-09-13 11:33:01 -0700369 return sprintf(buf, "%d\n", outbound.bytes_avail_toread);
370}
371static DEVICE_ATTR_RO(out_read_bytes_avail);
372
373static 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 Cuiba50bf12018-12-17 20:16:09 +0000379 int ret;
Greg Kroah-Hartman98f4c652013-09-13 11:33:01 -0700380
381 if (!hv_dev->channel)
382 return -ENODEV;
Dexuan Cuiba50bf12018-12-17 20:16:09 +0000383
384 ret = hv_ringbuffer_get_debuginfo(&hv_dev->channel->outbound,
385 &outbound);
386 if (ret < 0)
387 return ret;
Greg Kroah-Hartman98f4c652013-09-13 11:33:01 -0700388 return sprintf(buf, "%d\n", outbound.bytes_avail_towrite);
389}
390static DEVICE_ATTR_RO(out_write_bytes_avail);
391
392static 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 Cuiba50bf12018-12-17 20:16:09 +0000397 int ret;
Greg Kroah-Hartman98f4c652013-09-13 11:33:01 -0700398
399 if (!hv_dev->channel)
400 return -ENODEV;
Dexuan Cuiba50bf12018-12-17 20:16:09 +0000401
402 ret = hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound);
403 if (ret < 0)
404 return ret;
405
Greg Kroah-Hartman98f4c652013-09-13 11:33:01 -0700406 return sprintf(buf, "%d\n", inbound.current_interrupt_mask);
407}
408static DEVICE_ATTR_RO(in_intr_mask);
409
410static 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 Cuiba50bf12018-12-17 20:16:09 +0000415 int ret;
Greg Kroah-Hartman98f4c652013-09-13 11:33:01 -0700416
417 if (!hv_dev->channel)
418 return -ENODEV;
Dexuan Cuiba50bf12018-12-17 20:16:09 +0000419
420 ret = hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound);
421 if (ret < 0)
422 return ret;
423
Greg Kroah-Hartman98f4c652013-09-13 11:33:01 -0700424 return sprintf(buf, "%d\n", inbound.current_read_index);
425}
426static DEVICE_ATTR_RO(in_read_index);
427
428static 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 Cuiba50bf12018-12-17 20:16:09 +0000433 int ret;
Greg Kroah-Hartman98f4c652013-09-13 11:33:01 -0700434
435 if (!hv_dev->channel)
436 return -ENODEV;
Dexuan Cuiba50bf12018-12-17 20:16:09 +0000437
438 ret = hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound);
439 if (ret < 0)
440 return ret;
441
Greg Kroah-Hartman98f4c652013-09-13 11:33:01 -0700442 return sprintf(buf, "%d\n", inbound.current_write_index);
443}
444static DEVICE_ATTR_RO(in_write_index);
445
446static 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 Cuiba50bf12018-12-17 20:16:09 +0000452 int ret;
Greg Kroah-Hartman98f4c652013-09-13 11:33:01 -0700453
454 if (!hv_dev->channel)
455 return -ENODEV;
Dexuan Cuiba50bf12018-12-17 20:16:09 +0000456
457 ret = hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound);
458 if (ret < 0)
459 return ret;
460
Greg Kroah-Hartman98f4c652013-09-13 11:33:01 -0700461 return sprintf(buf, "%d\n", inbound.bytes_avail_toread);
462}
463static DEVICE_ATTR_RO(in_read_bytes_avail);
464
465static 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 Cuiba50bf12018-12-17 20:16:09 +0000471 int ret;
Greg Kroah-Hartman98f4c652013-09-13 11:33:01 -0700472
473 if (!hv_dev->channel)
474 return -ENODEV;
Dexuan Cuiba50bf12018-12-17 20:16:09 +0000475
476 ret = hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound);
477 if (ret < 0)
478 return ret;
479
Greg Kroah-Hartman98f4c652013-09-13 11:33:01 -0700480 return sprintf(buf, "%d\n", inbound.bytes_avail_towrite);
481}
482static DEVICE_ATTR_RO(in_write_bytes_avail);
483
Dexuan Cui042ab032015-08-05 00:52:43 -0700484static 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}
519static DEVICE_ATTR_RO(channel_vp_mapping);
520
K. Y. Srinivasan7047f172015-12-25 20:00:30 -0800521static 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}
528static DEVICE_ATTR_RO(vendor);
529
530static 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}
537static DEVICE_ATTR_RO(device);
538
Stephen Hemmingerd765edb2018-08-10 23:06:08 +0000539static 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
573static 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}
585static DEVICE_ATTR_RW(driver_override);
586
Greg Kroah-Hartman98f4c652013-09-13 11:33:01 -0700587/* Set up per device attributes in /sys/bus/vmbus/devices/<bus device> */
Stephen Hemmingerfc769362016-12-03 12:34:39 -0800588static struct attribute *vmbus_dev_attrs[] = {
Greg Kroah-Hartman03f3a912013-09-13 11:32:49 -0700589 &dev_attr_id.attr,
Greg Kroah-Hartmana8fb5f32013-09-13 11:32:50 -0700590 &dev_attr_state.attr,
Greg Kroah-Hartman5ffd00e2013-09-13 11:32:51 -0700591 &dev_attr_monitor_id.attr,
Greg Kroah-Hartman68234c02013-09-13 11:32:53 -0700592 &dev_attr_class_id.attr,
Greg Kroah-Hartman7c55e1d2013-09-13 11:32:54 -0700593 &dev_attr_device_id.attr,
Greg Kroah-Hartman647fa372013-09-13 11:32:52 -0700594 &dev_attr_modalias.attr,
Stephen Hemminger7ceb1c32018-07-28 21:58:48 +0000595#ifdef CONFIG_NUMA
596 &dev_attr_numa_node.attr,
597#endif
Greg Kroah-Hartman76c52bb2013-09-13 11:32:56 -0700598 &dev_attr_server_monitor_pending.attr,
599 &dev_attr_client_monitor_pending.attr,
Greg Kroah-Hartman1cee2722013-09-13 11:32:57 -0700600 &dev_attr_server_monitor_latency.attr,
601 &dev_attr_client_monitor_latency.attr,
Greg Kroah-Hartman4947c742013-09-13 11:32:58 -0700602 &dev_attr_server_monitor_conn_id.attr,
603 &dev_attr_client_monitor_conn_id.attr,
Greg Kroah-Hartman98f4c652013-09-13 11:33:01 -0700604 &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 Cui042ab032015-08-05 00:52:43 -0700614 &dev_attr_channel_vp_mapping.attr,
K. Y. Srinivasan7047f172015-12-25 20:00:30 -0800615 &dev_attr_vendor.attr,
616 &dev_attr_device.attr,
Stephen Hemmingerd765edb2018-08-10 23:06:08 +0000617 &dev_attr_driver_override.attr,
Greg Kroah-Hartman03f3a912013-09-13 11:32:49 -0700618 NULL,
619};
Kimberly Brown46fc1542019-03-19 00:04:01 -0400620
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 */
625static 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
645static 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-Hartman03f3a912013-09-13 11:32:49 -0700650
K. Y. Srinivasanadde2482011-03-15 15:03:37 -0700651/*
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. Srinivasan0ddda662011-08-25 09:48:38 -0700657 *
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. Srinivasanadde2482011-03-15 15:03:37 -0700661 */
662static int vmbus_uevent(struct device *device, struct kobj_uevent_env *env)
663{
664 struct hv_device *dev = device_to_hv_device(device);
Olaf Heringfd776ba2011-09-02 18:25:56 +0200665 int ret;
666 char alias_name[VMBUS_ALIAS_LEN + 1];
K. Y. Srinivasanadde2482011-03-15 15:03:37 -0700667
Olaf Heringfd776ba2011-09-02 18:25:56 +0200668 print_alias_name(dev, alias_name);
K. Y. Srinivasan0ddda662011-08-25 09:48:38 -0700669 ret = add_uevent_var(env, "MODALIAS=vmbus:%s", alias_name);
670 return ret;
K. Y. Srinivasanadde2482011-03-15 15:03:37 -0700671}
672
Stephen Hemmingerd765edb2018-08-10 23:06:08 +0000673static const struct hv_vmbus_device_id *
Andy Shevchenko593db802019-01-10 16:25:32 +0200674hv_vmbus_dev_match(const struct hv_vmbus_device_id *id, const guid_t *guid)
Stephen Hemmingerd765edb2018-08-10 23:06:08 +0000675{
676 if (id == NULL)
677 return NULL; /* empty device table */
678
Andy Shevchenko593db802019-01-10 16:25:32 +0200679 for (; !guid_is_null(&id->guid); id++)
680 if (guid_equal(&id->guid, guid))
Stephen Hemmingerd765edb2018-08-10 23:06:08 +0000681 return id;
682
683 return NULL;
684}
685
686static const struct hv_vmbus_device_id *
Andy Shevchenko593db802019-01-10 16:25:32 +0200687hv_vmbus_dynid_match(struct hv_driver *drv, const guid_t *guid)
K. Y. Srinivasan3037a7b2011-09-13 10:59:37 -0700688{
Stephen Hemmingerfc769362016-12-03 12:34:39 -0800689 const struct hv_vmbus_device_id *id = NULL;
690 struct vmbus_dynid *dynid;
691
Stephen Hemmingerfc769362016-12-03 12:34:39 -0800692 spin_lock(&drv->dynids.lock);
693 list_for_each_entry(dynid, &drv->dynids.list, node) {
Andy Shevchenko593db802019-01-10 16:25:32 +0200694 if (guid_equal(&dynid->id.guid, guid)) {
Stephen Hemmingerfc769362016-12-03 12:34:39 -0800695 id = &dynid->id;
696 break;
697 }
698 }
699 spin_unlock(&drv->dynids.lock);
700
Stephen Hemmingerd765edb2018-08-10 23:06:08 +0000701 return id;
702}
Stephen Hemmingerfc769362016-12-03 12:34:39 -0800703
Andy Shevchenko593db802019-01-10 16:25:32 +0200704static const struct hv_vmbus_device_id vmbus_device_null;
Stephen Hemmingerfc769362016-12-03 12:34:39 -0800705
Stephen Hemmingerd765edb2018-08-10 23:06:08 +0000706/*
707 * Return a matching hv_vmbus_device_id pointer.
708 * If there is no match, return NULL.
709 */
710static const struct hv_vmbus_device_id *hv_vmbus_get_id(struct hv_driver *drv,
711 struct hv_device *dev)
712{
Andy Shevchenko593db802019-01-10 16:25:32 +0200713 const guid_t *guid = &dev->dev_type;
Stephen Hemmingerd765edb2018-08-10 23:06:08 +0000714 const struct hv_vmbus_device_id *id;
K. Y. Srinivasan3037a7b2011-09-13 10:59:37 -0700715
Stephen Hemmingerd765edb2018-08-10 23:06:08 +0000716 /* 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. Srinivasan3037a7b2011-09-13 10:59:37 -0700730}
731
Stephen Hemmingerfc769362016-12-03 12:34:39 -0800732/* vmbus_add_dynid - add a new device ID to this driver and re-probe devices */
Andy Shevchenko593db802019-01-10 16:25:32 +0200733static int vmbus_add_dynid(struct hv_driver *drv, guid_t *guid)
Stephen Hemmingerfc769362016-12-03 12:34:39 -0800734{
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
750static 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 Hemmingerfc769362016-12-03 12:34:39 -0800762/*
763 * store_new_id - sysfs frontend to vmbus_add_dynid()
764 *
765 * Allow GUIDs to be added to an existing driver via sysfs.
766 */
767static 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 Shevchenko593db802019-01-10 16:25:32 +0200771 guid_t guid;
Stephen Hemmingerfc769362016-12-03 12:34:39 -0800772 ssize_t retval;
773
Andy Shevchenko593db802019-01-10 16:25:32 +0200774 retval = guid_parse(buf, &guid);
Andy Shevchenko31100102017-05-18 10:46:06 -0700775 if (retval)
776 return retval;
Stephen Hemmingerfc769362016-12-03 12:34:39 -0800777
Stephen Hemmingerd765edb2018-08-10 23:06:08 +0000778 if (hv_vmbus_dynid_match(drv, &guid))
Stephen Hemmingerfc769362016-12-03 12:34:39 -0800779 return -EEXIST;
780
781 retval = vmbus_add_dynid(drv, &guid);
782 if (retval)
783 return retval;
784 return count;
785}
786static 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 */
793static 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 Shevchenko593db802019-01-10 16:25:32 +0200798 guid_t guid;
Andy Shevchenko31100102017-05-18 10:46:06 -0700799 ssize_t retval;
Stephen Hemmingerfc769362016-12-03 12:34:39 -0800800
Andy Shevchenko593db802019-01-10 16:25:32 +0200801 retval = guid_parse(buf, &guid);
Andy Shevchenko31100102017-05-18 10:46:06 -0700802 if (retval)
803 return retval;
Stephen Hemmingerfc769362016-12-03 12:34:39 -0800804
Andy Shevchenko31100102017-05-18 10:46:06 -0700805 retval = -ENODEV;
Stephen Hemmingerfc769362016-12-03 12:34:39 -0800806 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 Shevchenko593db802019-01-10 16:25:32 +0200810 if (guid_equal(&id->guid, &guid)) {
Stephen Hemmingerfc769362016-12-03 12:34:39 -0800811 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}
821static DRIVER_ATTR_WO(remove_id);
822
823static struct attribute *vmbus_drv_attrs[] = {
824 &driver_attr_new_id.attr,
825 &driver_attr_remove_id.attr,
826 NULL,
827};
828ATTRIBUTE_GROUPS(vmbus_drv);
K. Y. Srinivasan3037a7b2011-09-13 10:59:37 -0700829
K. Y. Srinivasanb7fc1472011-03-15 15:03:38 -0700830
831/*
832 * vmbus_match - Attempt to match the specified device to the specified driver
833 */
834static int vmbus_match(struct device *device, struct device_driver *driver)
835{
K. Y. Srinivasanb7fc1472011-03-15 15:03:38 -0700836 struct hv_driver *drv = drv_to_hv_drv(driver);
K. Y. Srinivasane8e27042011-06-06 15:50:04 -0700837 struct hv_device *hv_dev = device_to_hv_device(device);
K. Y. Srinivasanb7fc1472011-03-15 15:03:38 -0700838
Dexuan Cui8981da32016-01-27 22:29:41 -0800839 /* The hv_sock driver handles all hv_sock offers. */
840 if (is_hvsock_channel(hv_dev->channel))
841 return drv->hvsock;
842
Stephen Hemmingerd765edb2018-08-10 23:06:08 +0000843 if (hv_vmbus_get_id(drv, hv_dev))
K. Y. Srinivasan3037a7b2011-09-13 10:59:37 -0700844 return 1;
K. Y. Srinivasande632a2b2011-04-26 09:20:24 -0700845
K. Y. Srinivasan5841a822011-08-25 09:48:39 -0700846 return 0;
K. Y. Srinivasanb7fc1472011-03-15 15:03:38 -0700847}
848
K. Y. Srinivasanf1f0d672011-03-15 15:03:39 -0700849/*
850 * vmbus_probe - Add the new vmbus's child device
851 */
852static 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. Srinivasan9efd21e2011-04-29 13:45:10 -0700857 struct hv_device *dev = device_to_hv_device(child_device);
K. Y. Srinivasan84946892011-09-13 10:59:38 -0700858 const struct hv_vmbus_device_id *dev_id;
K. Y. Srinivasanf1f0d672011-03-15 15:03:39 -0700859
Stephen Hemmingerd765edb2018-08-10 23:06:08 +0000860 dev_id = hv_vmbus_get_id(drv, dev);
K. Y. Srinivasan9efd21e2011-04-29 13:45:10 -0700861 if (drv->probe) {
K. Y. Srinivasan84946892011-09-13 10:59:38 -0700862 ret = drv->probe(dev, dev_id);
K. Y. Srinivasanb14a7b32011-04-29 13:45:03 -0700863 if (ret != 0)
Hank Janssen0a466182011-03-29 13:58:47 -0700864 pr_err("probe failed for device %s (%d)\n",
865 dev_name(child_device), ret);
K. Y. Srinivasanf1f0d672011-03-15 15:03:39 -0700866
K. Y. Srinivasanf1f0d672011-03-15 15:03:39 -0700867 } else {
Hank Janssen0a466182011-03-29 13:58:47 -0700868 pr_err("probe not set for driver %s\n",
869 dev_name(child_device));
K. Y. Srinivasan6de925b2011-06-06 15:50:07 -0700870 ret = -ENODEV;
K. Y. Srinivasanf1f0d672011-03-15 15:03:39 -0700871 }
872 return ret;
873}
874
K. Y. Srinivasanc5dce3d2011-03-15 15:03:40 -0700875/*
876 * vmbus_remove - Remove a vmbus device
877 */
878static int vmbus_remove(struct device *child_device)
879{
K. Y. Srinivasand15a0302015-02-28 11:18:16 -0800880 struct hv_driver *drv;
K. Y. Srinivasan415b0232011-04-29 13:45:12 -0700881 struct hv_device *dev = device_to_hv_device(child_device);
K. Y. Srinivasanc5dce3d2011-03-15 15:03:40 -0700882
K. Y. Srinivasand15a0302015-02-28 11:18:16 -0800883 if (child_device->driver) {
884 drv = drv_to_hv_drv(child_device->driver);
885 if (drv->remove)
886 drv->remove(dev);
K. Y. Srinivasand15a0302015-02-28 11:18:16 -0800887 }
K. Y. Srinivasanc5dce3d2011-03-15 15:03:40 -0700888
889 return 0;
890}
891
K. Y. Srinivasaneb1bb252011-03-15 15:03:41 -0700892
893/*
894 * vmbus_shutdown - Shutdown a vmbus device
895 */
896static void vmbus_shutdown(struct device *child_device)
897{
898 struct hv_driver *drv;
K. Y. Srinivasanca6887f2011-04-29 13:45:14 -0700899 struct hv_device *dev = device_to_hv_device(child_device);
K. Y. Srinivasaneb1bb252011-03-15 15:03:41 -0700900
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. Srinivasanca6887f2011-04-29 13:45:14 -0700908 if (drv->shutdown)
909 drv->shutdown(dev);
K. Y. Srinivasaneb1bb252011-03-15 15:03:41 -0700910}
911
K. Y. Srinivasan086e7a52011-03-15 15:03:42 -0700912
913/*
914 * vmbus_device_release - Final callback release of the vmbus child device
915 */
916static void vmbus_device_release(struct device *device)
917{
K. Y. Srinivasane8e27042011-06-06 15:50:04 -0700918 struct hv_device *hv_dev = device_to_hv_device(device);
Dexuan Cui34c68012015-12-14 16:01:49 -0800919 struct vmbus_channel *channel = hv_dev->channel;
K. Y. Srinivasan086e7a52011-03-15 15:03:42 -0700920
K. Y. Srinivasan54a662652017-04-30 16:21:18 -0700921 mutex_lock(&vmbus_connection.channel_mutex);
Stephen Hemminger800b9322018-09-14 09:10:15 -0700922 hv_process_channel_removal(channel);
K. Y. Srinivasan54a662652017-04-30 16:21:18 -0700923 mutex_unlock(&vmbus_connection.channel_mutex);
K. Y. Srinivasane8e27042011-06-06 15:50:04 -0700924 kfree(hv_dev);
K. Y. Srinivasan086e7a52011-03-15 15:03:42 -0700925}
926
Bill Pemberton454f18a2009-07-27 16:47:24 -0400927/* The one and only one */
K. Y. Srinivasan9adcac52011-04-29 13:45:08 -0700928static 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 Hemmingerfc769362016-12-03 12:34:39 -0800935 .dev_groups = vmbus_dev_groups,
936 .drv_groups = vmbus_drv_groups,
Hank Janssen3e7ee492009-07-13 16:02:34 -0700937};
938
Timo Teräsbf6506f2010-12-15 20:48:08 +0200939struct onmessage_work_context {
940 struct work_struct work;
941 struct hv_message msg;
942};
943
944static void vmbus_onmessage_work(struct work_struct *work)
945{
946 struct onmessage_work_context *ctx;
947
Vitaly Kuznetsov09a19622015-02-27 11:25:54 -0800948 /* Do not process messages if we're in DISCONNECTED state */
949 if (vmbus_connection.conn_state == DISCONNECTED)
950 return;
951
Timo Teräsbf6506f2010-12-15 20:48:08 +0200952 ctx = container_of(work, struct onmessage_work_context,
953 work);
954 vmbus_onmessage(&ctx->msg);
955 kfree(ctx);
956}
957
Stephen Hemminger37cdd992017-02-11 23:02:19 -0700958static void hv_process_timer_expiration(struct hv_message *msg,
959 struct hv_per_cpu_context *hv_cpu)
K. Y. Srinivasan4061ed92015-01-09 23:54:32 -0800960{
Stephen Hemminger37cdd992017-02-11 23:02:19 -0700961 struct clock_event_device *dev = hv_cpu->clk_evt;
K. Y. Srinivasan4061ed92015-01-09 23:54:32 -0800962
963 if (dev->event_handler)
964 dev->event_handler(dev);
965
Vitaly Kuznetsovcd95aad2016-04-30 19:21:34 -0700966 vmbus_signal_eom(msg, HVMSG_TIMER_EXPIRED);
K. Y. Srinivasan4061ed92015-01-09 23:54:32 -0800967}
968
K. Y. Srinivasand81274a2016-02-26 15:13:21 -0800969void vmbus_on_msg_dpc(unsigned long data)
Greg Kroah-Hartman36199a92010-12-02 11:59:22 -0800970{
Stephen Hemminger37cdd992017-02-11 23:02:19 -0700971 struct hv_per_cpu_context *hv_cpu = (void *)data;
972 void *page_addr = hv_cpu->synic_message_page;
Greg Kroah-Hartman36199a92010-12-02 11:59:22 -0800973 struct hv_message *msg = (struct hv_message *)page_addr +
974 VMBUS_MESSAGE_SINT;
Dexuan Cui652594c2015-03-27 09:10:08 -0700975 struct vmbus_channel_message_header *hdr;
Stephen Hemmingere6242fa2017-03-04 18:27:16 -0700976 const struct vmbus_channel_message_table_entry *entry;
Timo Teräsbf6506f2010-12-15 20:48:08 +0200977 struct onmessage_work_context *ctx;
Vitaly Kuznetsovcd95aad2016-04-30 19:21:34 -0700978 u32 message_type = msg->header.message_type;
Greg Kroah-Hartman36199a92010-12-02 11:59:22 -0800979
Vitaly Kuznetsovcd95aad2016-04-30 19:21:34 -0700980 if (message_type == HVMSG_NONE)
Vitaly Kuznetsov7be3e162016-02-26 15:13:15 -0800981 /* no msg */
982 return;
Dexuan Cui652594c2015-03-27 09:10:08 -0700983
Vitaly Kuznetsov7be3e162016-02-26 15:13:15 -0800984 hdr = (struct vmbus_channel_message_header *)msg->u.payload;
Dexuan Cui652594c2015-03-27 09:10:08 -0700985
Vitaly Kuznetsovc9fe0f82017-10-29 12:21:00 -0700986 trace_vmbus_on_msg_dpc(hdr);
987
Vitaly Kuznetsov7be3e162016-02-26 15:13:15 -0800988 if (hdr->msgtype >= CHANNELMSG_COUNT) {
989 WARN_ONCE(1, "unknown msgtype=%d\n", hdr->msgtype);
990 goto msg_handled;
991 }
Dexuan Cui652594c2015-03-27 09:10:08 -0700992
Vitaly Kuznetsov7be3e162016-02-26 15:13:15 -0800993 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 Cui652594c2015-03-27 09:10:08 -0700998
Vitaly Kuznetsov7be3e162016-02-26 15:13:15 -0800999 INIT_WORK(&ctx->work, vmbus_onmessage_work);
1000 memcpy(&ctx->msg, msg, sizeof(*msg));
Greg Kroah-Hartman36199a92010-12-02 11:59:22 -08001001
K. Y. Srinivasan54a662652017-04-30 16:21:18 -07001002 /*
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 Kuznetsov7be3e162016-02-26 15:13:15 -08001028 } else
1029 entry->message_handler(hdr);
Dexuan Cui652594c2015-03-27 09:10:08 -07001030
1031msg_handled:
Vitaly Kuznetsovcd95aad2016-04-30 19:21:34 -07001032 vmbus_signal_eom(msg, message_type);
Greg Kroah-Hartman36199a92010-12-02 11:59:22 -08001033}
1034
Stephen Hemminger631e63a2017-02-11 23:02:20 -07001035
1036/*
Stephen Hemmingerb71e3282017-02-11 23:02:21 -07001037 * Direct callback for channels using other deferred processing
1038 */
1039static 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 Hemminger631e63a2017-02-11 23:02:20 -07001049 * Schedule all channels with events pending
1050 */
1051static 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 Hemminger8200f202017-03-04 18:13:57 -07001087 rcu_read_lock();
1088
Stephen Hemminger631e63a2017-02-11 23:02:20 -07001089 /* Find channel based on relid */
Stephen Hemminger8200f202017-03-04 18:13:57 -07001090 list_for_each_entry_rcu(channel, &hv_cpu->chan_list, percpu_list) {
Stephen Hemmingerb71e3282017-02-11 23:02:21 -07001091 if (channel->offermsg.child_relid != relid)
1092 continue;
1093
K. Y. Srinivasan6f3d7912017-08-11 10:03:59 -07001094 if (channel->rescind)
1095 continue;
1096
Vitaly Kuznetsov991f8f12017-10-29 12:21:16 -07001097 trace_vmbus_chan_sched(channel);
1098
Stephen Hemminger6981fbf2017-10-29 11:33:40 -07001099 ++channel->interrupts;
1100
Stephen Hemmingerb71e3282017-02-11 23:02:21 -07001101 switch (channel->callback_mode) {
1102 case HV_CALL_ISR:
1103 vmbus_channel_isr(channel);
Stephen Hemminger631e63a2017-02-11 23:02:20 -07001104 break;
Stephen Hemmingerb71e3282017-02-11 23:02:21 -07001105
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 Hemminger631e63a2017-02-11 23:02:20 -07001111 }
1112 }
Stephen Hemminger8200f202017-03-04 18:13:57 -07001113
1114 rcu_read_unlock();
Stephen Hemminger631e63a2017-02-11 23:02:20 -07001115 }
1116}
1117
Thomas Gleixner76d388c2014-03-05 13:42:14 +01001118static void vmbus_isr(void)
Greg Kroah-Hartman36199a92010-12-02 11:59:22 -08001119{
Stephen Hemminger37cdd992017-02-11 23:02:19 -07001120 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-Hartman36199a92010-12-02 11:59:22 -08001123 struct hv_message *msg;
1124 union hv_synic_event_flags *event;
K. Y. Srinivasanae4636e2011-08-27 11:31:35 -07001125 bool handled = false;
Greg Kroah-Hartman36199a92010-12-02 11:59:22 -08001126
Stephen Hemminger37cdd992017-02-11 23:02:19 -07001127 if (unlikely(page_addr == NULL))
Thomas Gleixner76d388c2014-03-05 13:42:14 +01001128 return;
K. Y. Srinivasan5ab05952012-12-01 06:46:55 -08001129
1130 event = (union hv_synic_event_flags *)page_addr +
1131 VMBUS_MESSAGE_SINT;
K. Y. Srinivasan7341d902011-08-31 14:35:56 -07001132 /*
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-Hartman36199a92010-12-02 11:59:22 -08001137
K. Y. Srinivasan6552ecd72012-12-01 06:46:49 -08001138 if ((vmbus_proto_version == VERSION_WS2008) ||
1139 (vmbus_proto_version == VERSION_WIN7)) {
Greg Kroah-Hartman36199a92010-12-02 11:59:22 -08001140
K. Y. Srinivasan6552ecd72012-12-01 06:46:49 -08001141 /* Since we are a child, we only need to check bit 0 */
Stephen Hemminger5c1bec62017-02-05 17:20:31 -07001142 if (sync_test_and_clear_bit(0, event->flags))
K. Y. Srinivasan6552ecd72012-12-01 06:46:49 -08001143 handled = true;
K. Y. Srinivasan6552ecd72012-12-01 06:46:49 -08001144 } 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. Srinivasanae4636e2011-08-27 11:31:35 -07001151 handled = true;
K. Y. Srinivasan793be9c2011-03-15 15:03:43 -07001152 }
K. Y. Srinivasanae4636e2011-08-27 11:31:35 -07001153
K. Y. Srinivasan6552ecd72012-12-01 06:46:49 -08001154 if (handled)
Stephen Hemminger631e63a2017-02-11 23:02:20 -07001155 vmbus_chan_sched(hv_cpu);
K. Y. Srinivasan6552ecd72012-12-01 06:46:49 -08001156
Stephen Hemminger37cdd992017-02-11 23:02:19 -07001157 page_addr = hv_cpu->synic_message_page;
K. Y. Srinivasan7341d902011-08-31 14:35:56 -07001158 msg = (struct hv_message *)page_addr + VMBUS_MESSAGE_SINT;
1159
1160 /* Check if there are actual msgs to be processed */
K. Y. Srinivasan4061ed92015-01-09 23:54:32 -08001161 if (msg->header.message_type != HVMSG_NONE) {
1162 if (msg->header.message_type == HVMSG_TIMER_EXPIRED)
Stephen Hemminger37cdd992017-02-11 23:02:19 -07001163 hv_process_timer_expiration(msg, hv_cpu);
K. Y. Srinivasan4061ed92015-01-09 23:54:32 -08001164 else
Stephen Hemminger37cdd992017-02-11 23:02:19 -07001165 tasklet_schedule(&hv_cpu->msg_dpc);
K. Y. Srinivasan4061ed92015-01-09 23:54:32 -08001166 }
Stephan Mueller4b44f2d2016-05-02 02:14:34 -04001167
1168 add_interrupt_randomness(HYPERVISOR_CALLBACK_VECTOR, 0);
K. Y. Srinivasan793be9c2011-03-15 15:03:43 -07001169}
1170
Sunil Muthuswamy81b18bc2018-07-08 02:56:51 +00001171/*
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 */
1176static 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 */
1182static 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 Muthuswamyddcaf3c2018-07-28 21:58:45 +00001198 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 Muthuswamy81b18bc2018-07-08 02:56:51 +00001202}
1203
1204static struct kmsg_dumper hv_kmsg_dumper = {
1205 .dump = hv_kmsg_dump,
1206};
1207
1208static struct ctl_table_header *hv_ctl_table_hdr;
1209static int zero;
1210static 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 */
1216static 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
1229static struct ctl_table hv_root_table[] = {
1230 {
1231 .procname = "kernel",
1232 .mode = 0555,
1233 .child = hv_ctl_table
1234 },
1235 {}
1236};
Vitaly Kuznetsove5132292015-02-27 11:25:51 -08001237
Hank Janssen3e189512010-03-04 22:11:00 +00001238/*
Greg Kroah-Hartman90c99602009-09-02 07:11:14 -07001239 * vmbus_bus_init -Main vmbus driver initialization routine.
1240 *
1241 * Here, we
Lars Lindley0686e4f2010-03-11 23:51:23 +01001242 * - initialize the vmbus driver context
Lars Lindley0686e4f2010-03-11 23:51:23 +01001243 * - invoke the vmbus hv main init routine
Lars Lindley0686e4f2010-03-11 23:51:23 +01001244 * - retrieve the channel offers
Greg Kroah-Hartman90c99602009-09-02 07:11:14 -07001245 */
K. Y. Srinivasanefc26722015-12-14 16:01:46 -08001246static int vmbus_bus_init(void)
Hank Janssen3e7ee492009-07-13 16:02:34 -07001247{
Greg Kroah-Hartman90c99602009-09-02 07:11:14 -07001248 int ret;
Hank Janssen3e7ee492009-07-13 16:02:34 -07001249
Greg Kroah-Hartman6d26e38fa22010-12-02 12:08:08 -08001250 /* Hypervisor initialization...setup hypercall page..etc */
1251 ret = hv_init();
Greg Kroah-Hartman90c99602009-09-02 07:11:14 -07001252 if (ret != 0) {
Hank Janssen0a466182011-03-29 13:58:47 -07001253 pr_err("Unable to initialize the hypervisor - 0x%x\n", ret);
K. Y. Srinivasand6c1c5d2011-06-06 15:50:08 -07001254 return ret;
Hank Janssen3e7ee492009-07-13 16:02:34 -07001255 }
1256
K. Y. Srinivasan9adcac52011-04-29 13:45:08 -07001257 ret = bus_register(&hv_bus);
K. Y. Srinivasand6c1c5d2011-06-06 15:50:08 -07001258 if (ret)
Vitaly Kuznetsovd6f36092017-01-28 12:37:14 -07001259 return ret;
Hank Janssen3e7ee492009-07-13 16:02:34 -07001260
Thomas Gleixner76d388c2014-03-05 13:42:14 +01001261 hv_setup_vmbus_irq(vmbus_isr);
Hank Janssen3e7ee492009-07-13 16:02:34 -07001262
Jason Wang2608fb62013-06-19 11:28:10 +08001263 ret = hv_synic_alloc();
1264 if (ret)
1265 goto err_alloc;
K. Y. Srinivasan800b6902011-03-15 15:03:33 -07001266 /*
K. Y. Srinivasan302a3c02013-02-17 11:30:44 -08001267 * Initialize the per-cpu interrupt state and
K. Y. Srinivasan800b6902011-03-15 15:03:33 -07001268 * connect to the host.
1269 */
Michael Kelley4a5f3cd2017-12-22 11:19:02 -07001270 ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "hyperv/vmbus:online",
Vitaly Kuznetsov76d36ab2016-12-07 14:53:11 -08001271 hv_synic_init, hv_synic_cleanup);
1272 if (ret < 0)
1273 goto err_alloc;
1274 hyperv_cpuhp_online = ret;
1275
K. Y. Srinivasan800b6902011-03-15 15:03:33 -07001276 ret = vmbus_connect();
K. Y. Srinivasan8b9987e92011-08-31 14:35:55 -07001277 if (ret)
Andrey Smetanin17efbee2015-12-14 16:01:38 -08001278 goto err_connect;
K. Y. Srinivasan800b6902011-03-15 15:03:33 -07001279
Nick Meier96c1d052015-02-28 11:39:01 -08001280 /*
1281 * Only register if the crash MSRs are available
1282 */
Denis V. Lunevcc2dd402015-08-01 16:08:20 -07001283 if (ms_hyperv.misc_features & HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE) {
Sunil Muthuswamy81b18bc2018-07-08 02:56:51 +00001284 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 Muthuswamy9d9c9652018-07-28 21:58:47 +00001297 hv_get_crash_ctl(hyperv_crash_ctl);
Sunil Muthuswamy81b18bc2018-07-08 02:56:51 +00001298 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 Kuznetsov510f7ae2015-08-01 16:08:10 -07001310 register_die_notifier(&hyperv_die_block);
Nick Meier96c1d052015-02-28 11:39:01 -08001311 atomic_notifier_chain_register(&panic_notifier_list,
1312 &hyperv_panic_block);
1313 }
1314
Greg Kroah-Hartman2d6e8822010-12-02 08:50:58 -08001315 vmbus_request_offers();
Haiyang Zhang8b5d6d32010-05-28 23:22:44 +00001316
K. Y. Srinivasand6c1c5d2011-06-06 15:50:08 -07001317 return 0;
K. Y. Srinivasan8b9987e92011-08-31 14:35:55 -07001318
Andrey Smetanin17efbee2015-12-14 16:01:38 -08001319err_connect:
Vitaly Kuznetsov76d36ab2016-12-07 14:53:11 -08001320 cpuhp_remove_state(hyperv_cpuhp_online);
Jason Wang2608fb62013-06-19 11:28:10 +08001321err_alloc:
1322 hv_synic_free();
Thomas Gleixner76d388c2014-03-05 13:42:14 +01001323 hv_remove_vmbus_irq();
K. Y. Srinivasan8b9987e92011-08-31 14:35:55 -07001324
K. Y. Srinivasan8b9987e92011-08-31 14:35:55 -07001325 bus_unregister(&hv_bus);
Sunil Muthuswamy81b18bc2018-07-08 02:56:51 +00001326 free_page((unsigned long)hv_panic_page);
Sunil Muthuswamy8afc06d2018-07-28 21:58:46 +00001327 unregister_sysctl_table(hv_ctl_table_hdr);
1328 hv_ctl_table_hdr = NULL;
K. Y. Srinivasan8b9987e92011-08-31 14:35:55 -07001329 return ret;
Hank Janssen3e7ee492009-07-13 16:02:34 -07001330}
1331
Greg Kroah-Hartman90c99602009-09-02 07:11:14 -07001332/**
Jake Oshins35464482015-08-05 00:52:37 -07001333 * __vmbus_child_driver_register() - Register a vmbus's driver
1334 * @hv_driver: Pointer to driver structure you want to register
Greg Kroah-Hartman768fa212011-08-25 15:07:32 -07001335 * @owner: owner module of the drv
1336 * @mod_name: module name string
Hank Janssen3e189512010-03-04 22:11:00 +00001337 *
1338 * Registers the given driver with Linux through the 'driver_register()' call
Greg Kroah-Hartman768fa212011-08-25 15:07:32 -07001339 * and sets up the hyper-v vmbus handling for this driver.
Hank Janssen3e189512010-03-04 22:11:00 +00001340 * It will return the state of the 'driver_register()' call.
1341 *
Greg Kroah-Hartman90c99602009-09-02 07:11:14 -07001342 */
Greg Kroah-Hartman768fa212011-08-25 15:07:32 -07001343int __vmbus_driver_register(struct hv_driver *hv_driver, struct module *owner, const char *mod_name)
Hank Janssen3e7ee492009-07-13 16:02:34 -07001344{
Bill Pemberton5d48a1c2009-07-27 16:47:36 -04001345 int ret;
Hank Janssen3e7ee492009-07-13 16:02:34 -07001346
Greg Kroah-Hartman768fa212011-08-25 15:07:32 -07001347 pr_info("registering driver %s\n", hv_driver->name);
Hank Janssen3e7ee492009-07-13 16:02:34 -07001348
K. Y. Srinivasancf6a2ea2011-12-01 09:59:34 -08001349 ret = vmbus_exists();
1350 if (ret < 0)
1351 return ret;
1352
Greg Kroah-Hartman768fa212011-08-25 15:07:32 -07001353 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 Janssen3e7ee492009-07-13 16:02:34 -07001357
Stephen Hemmingerfc769362016-12-03 12:34:39 -08001358 spin_lock_init(&hv_driver->dynids.lock);
1359 INIT_LIST_HEAD(&hv_driver->dynids.list);
1360
Greg Kroah-Hartman768fa212011-08-25 15:07:32 -07001361 ret = driver_register(&hv_driver->driver);
Hank Janssen3e7ee492009-07-13 16:02:34 -07001362
Bill Pemberton5d48a1c2009-07-27 16:47:36 -04001363 return ret;
Hank Janssen3e7ee492009-07-13 16:02:34 -07001364}
Greg Kroah-Hartman768fa212011-08-25 15:07:32 -07001365EXPORT_SYMBOL_GPL(__vmbus_driver_register);
Hank Janssen3e7ee492009-07-13 16:02:34 -07001366
Greg Kroah-Hartman90c99602009-09-02 07:11:14 -07001367/**
Greg Kroah-Hartman768fa212011-08-25 15:07:32 -07001368 * vmbus_driver_unregister() - Unregister a vmbus's driver
Jake Oshins35464482015-08-05 00:52:37 -07001369 * @hv_driver: Pointer to driver structure you want to
1370 * un-register
Hank Janssen3e189512010-03-04 22:11:00 +00001371 *
Greg Kroah-Hartman768fa212011-08-25 15:07:32 -07001372 * Un-register the given driver that was previous registered with a call to
1373 * vmbus_driver_register()
Greg Kroah-Hartman90c99602009-09-02 07:11:14 -07001374 */
Greg Kroah-Hartman768fa212011-08-25 15:07:32 -07001375void vmbus_driver_unregister(struct hv_driver *hv_driver)
Hank Janssen3e7ee492009-07-13 16:02:34 -07001376{
Greg Kroah-Hartman768fa212011-08-25 15:07:32 -07001377 pr_info("unregistering driver %s\n", hv_driver->name);
Hank Janssen3e7ee492009-07-13 16:02:34 -07001378
Stephen Hemmingerfc769362016-12-03 12:34:39 -08001379 if (!vmbus_exists()) {
K. Y. Srinivasan8f257a12011-12-27 13:49:37 -08001380 driver_unregister(&hv_driver->driver);
Stephen Hemmingerfc769362016-12-03 12:34:39 -08001381 vmbus_free_dynids(hv_driver);
1382 }
Hank Janssen3e7ee492009-07-13 16:02:34 -07001383}
Greg Kroah-Hartman768fa212011-08-25 15:07:32 -07001384EXPORT_SYMBOL_GPL(vmbus_driver_unregister);
Hank Janssen3e7ee492009-07-13 16:02:34 -07001385
Stephen Hemmingerc2e5df62017-09-21 20:58:49 -07001386
1387/*
1388 * Called when last reference to channel is gone.
1389 */
1390static 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
1398struct vmbus_chan_attribute {
1399 struct attribute attr;
Kimberly Brown14948e32019-03-14 16:05:15 -04001400 ssize_t (*show)(struct vmbus_channel *chan, char *buf);
Stephen Hemmingerc2e5df62017-09-21 20:58:49 -07001401 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
1414static 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 Brown14948e32019-03-14 16:05:15 -04001419 struct vmbus_channel *chan
Stephen Hemmingerc2e5df62017-09-21 20:58:49 -07001420 = container_of(kobj, struct vmbus_channel, kobj);
1421
1422 if (!attribute->show)
1423 return -EIO;
1424
1425 return attribute->show(chan, buf);
1426}
1427
1428static const struct sysfs_ops vmbus_chan_sysfs_ops = {
1429 .show = vmbus_chan_attr_show,
1430};
1431
Kimberly Brown14948e32019-03-14 16:05:15 -04001432static ssize_t out_mask_show(struct vmbus_channel *channel, char *buf)
Stephen Hemmingerc2e5df62017-09-21 20:58:49 -07001433{
Kimberly Brown14948e32019-03-14 16:05:15 -04001434 struct hv_ring_buffer_info *rbi = &channel->outbound;
1435 ssize_t ret;
Stephen Hemmingerc2e5df62017-09-21 20:58:49 -07001436
Kimberly Brown14948e32019-03-14 16:05:15 -04001437 mutex_lock(&rbi->ring_buffer_mutex);
1438 if (!rbi->ring_buffer) {
1439 mutex_unlock(&rbi->ring_buffer_mutex);
Kimberly Brownfcedbb22019-03-14 16:05:00 -04001440 return -EINVAL;
Kimberly Brown14948e32019-03-14 16:05:15 -04001441 }
Kimberly Brownfcedbb22019-03-14 16:05:00 -04001442
Kimberly Brown14948e32019-03-14 16:05:15 -04001443 ret = sprintf(buf, "%u\n", rbi->ring_buffer->interrupt_mask);
1444 mutex_unlock(&rbi->ring_buffer_mutex);
1445 return ret;
Stephen Hemmingerc2e5df62017-09-21 20:58:49 -07001446}
Stephen Hemminger875c3622018-01-04 14:13:25 -08001447static VMBUS_CHAN_ATTR_RO(out_mask);
Stephen Hemmingerc2e5df62017-09-21 20:58:49 -07001448
Kimberly Brown14948e32019-03-14 16:05:15 -04001449static ssize_t in_mask_show(struct vmbus_channel *channel, char *buf)
Stephen Hemmingerc2e5df62017-09-21 20:58:49 -07001450{
Kimberly Brown14948e32019-03-14 16:05:15 -04001451 struct hv_ring_buffer_info *rbi = &channel->inbound;
1452 ssize_t ret;
Stephen Hemmingerc2e5df62017-09-21 20:58:49 -07001453
Kimberly Brown14948e32019-03-14 16:05:15 -04001454 mutex_lock(&rbi->ring_buffer_mutex);
1455 if (!rbi->ring_buffer) {
1456 mutex_unlock(&rbi->ring_buffer_mutex);
Kimberly Brownfcedbb22019-03-14 16:05:00 -04001457 return -EINVAL;
Kimberly Brown14948e32019-03-14 16:05:15 -04001458 }
Kimberly Brownfcedbb22019-03-14 16:05:00 -04001459
Kimberly Brown14948e32019-03-14 16:05:15 -04001460 ret = sprintf(buf, "%u\n", rbi->ring_buffer->interrupt_mask);
1461 mutex_unlock(&rbi->ring_buffer_mutex);
1462 return ret;
Stephen Hemmingerc2e5df62017-09-21 20:58:49 -07001463}
Stephen Hemminger875c3622018-01-04 14:13:25 -08001464static VMBUS_CHAN_ATTR_RO(in_mask);
Stephen Hemmingerc2e5df62017-09-21 20:58:49 -07001465
Kimberly Brown14948e32019-03-14 16:05:15 -04001466static ssize_t read_avail_show(struct vmbus_channel *channel, char *buf)
Stephen Hemmingerc2e5df62017-09-21 20:58:49 -07001467{
Kimberly Brown14948e32019-03-14 16:05:15 -04001468 struct hv_ring_buffer_info *rbi = &channel->inbound;
1469 ssize_t ret;
Stephen Hemmingerc2e5df62017-09-21 20:58:49 -07001470
Kimberly Brown14948e32019-03-14 16:05:15 -04001471 mutex_lock(&rbi->ring_buffer_mutex);
1472 if (!rbi->ring_buffer) {
1473 mutex_unlock(&rbi->ring_buffer_mutex);
Kimberly Brownfcedbb22019-03-14 16:05:00 -04001474 return -EINVAL;
Kimberly Brown14948e32019-03-14 16:05:15 -04001475 }
Kimberly Brownfcedbb22019-03-14 16:05:00 -04001476
Kimberly Brown14948e32019-03-14 16:05:15 -04001477 ret = sprintf(buf, "%u\n", hv_get_bytes_to_read(rbi));
1478 mutex_unlock(&rbi->ring_buffer_mutex);
1479 return ret;
Stephen Hemmingerc2e5df62017-09-21 20:58:49 -07001480}
Stephen Hemminger875c3622018-01-04 14:13:25 -08001481static VMBUS_CHAN_ATTR_RO(read_avail);
Stephen Hemmingerc2e5df62017-09-21 20:58:49 -07001482
Kimberly Brown14948e32019-03-14 16:05:15 -04001483static ssize_t write_avail_show(struct vmbus_channel *channel, char *buf)
Stephen Hemmingerc2e5df62017-09-21 20:58:49 -07001484{
Kimberly Brown14948e32019-03-14 16:05:15 -04001485 struct hv_ring_buffer_info *rbi = &channel->outbound;
1486 ssize_t ret;
Stephen Hemmingerc2e5df62017-09-21 20:58:49 -07001487
Kimberly Brown14948e32019-03-14 16:05:15 -04001488 mutex_lock(&rbi->ring_buffer_mutex);
1489 if (!rbi->ring_buffer) {
1490 mutex_unlock(&rbi->ring_buffer_mutex);
Kimberly Brownfcedbb22019-03-14 16:05:00 -04001491 return -EINVAL;
Kimberly Brown14948e32019-03-14 16:05:15 -04001492 }
Kimberly Brownfcedbb22019-03-14 16:05:00 -04001493
Kimberly Brown14948e32019-03-14 16:05:15 -04001494 ret = sprintf(buf, "%u\n", hv_get_bytes_to_write(rbi));
1495 mutex_unlock(&rbi->ring_buffer_mutex);
1496 return ret;
Stephen Hemmingerc2e5df62017-09-21 20:58:49 -07001497}
Stephen Hemminger875c3622018-01-04 14:13:25 -08001498static VMBUS_CHAN_ATTR_RO(write_avail);
Stephen Hemmingerc2e5df62017-09-21 20:58:49 -07001499
Kimberly Brown14948e32019-03-14 16:05:15 -04001500static ssize_t show_target_cpu(struct vmbus_channel *channel, char *buf)
Stephen Hemmingerc2e5df62017-09-21 20:58:49 -07001501{
1502 return sprintf(buf, "%u\n", channel->target_cpu);
1503}
Stephen Hemminger875c3622018-01-04 14:13:25 -08001504static VMBUS_CHAN_ATTR(cpu, S_IRUGO, show_target_cpu, NULL);
Stephen Hemmingerc2e5df62017-09-21 20:58:49 -07001505
Kimberly Brown14948e32019-03-14 16:05:15 -04001506static ssize_t channel_pending_show(struct vmbus_channel *channel,
Stephen Hemmingerc2e5df62017-09-21 20:58:49 -07001507 char *buf)
1508{
1509 return sprintf(buf, "%d\n",
1510 channel_pending(channel,
1511 vmbus_connection.monitor_pages[1]));
1512}
Stephen Hemminger875c3622018-01-04 14:13:25 -08001513static VMBUS_CHAN_ATTR(pending, S_IRUGO, channel_pending_show, NULL);
Stephen Hemmingerc2e5df62017-09-21 20:58:49 -07001514
Kimberly Brown14948e32019-03-14 16:05:15 -04001515static ssize_t channel_latency_show(struct vmbus_channel *channel,
Stephen Hemmingerc2e5df62017-09-21 20:58:49 -07001516 char *buf)
1517{
1518 return sprintf(buf, "%d\n",
1519 channel_latency(channel,
1520 vmbus_connection.monitor_pages[1]));
1521}
Stephen Hemminger875c3622018-01-04 14:13:25 -08001522static VMBUS_CHAN_ATTR(latency, S_IRUGO, channel_latency_show, NULL);
Stephen Hemmingerc2e5df62017-09-21 20:58:49 -07001523
Kimberly Brown14948e32019-03-14 16:05:15 -04001524static ssize_t channel_interrupts_show(struct vmbus_channel *channel, char *buf)
Stephen Hemminger6981fbf2017-10-29 11:33:40 -07001525{
1526 return sprintf(buf, "%llu\n", channel->interrupts);
1527}
Stephen Hemminger875c3622018-01-04 14:13:25 -08001528static VMBUS_CHAN_ATTR(interrupts, S_IRUGO, channel_interrupts_show, NULL);
Stephen Hemminger6981fbf2017-10-29 11:33:40 -07001529
Kimberly Brown14948e32019-03-14 16:05:15 -04001530static ssize_t channel_events_show(struct vmbus_channel *channel, char *buf)
Stephen Hemminger6981fbf2017-10-29 11:33:40 -07001531{
1532 return sprintf(buf, "%llu\n", channel->sig_events);
1533}
Stephen Hemminger875c3622018-01-04 14:13:25 -08001534static VMBUS_CHAN_ATTR(events, S_IRUGO, channel_events_show, NULL);
Stephen Hemminger6981fbf2017-10-29 11:33:40 -07001535
Kimberly Brown14948e32019-03-14 16:05:15 -04001536static ssize_t channel_intr_in_full_show(struct vmbus_channel *channel,
Kimberly Brown396ae572019-02-04 02:13:09 -05001537 char *buf)
1538{
1539 return sprintf(buf, "%llu\n",
1540 (unsigned long long)channel->intr_in_full);
1541}
1542static VMBUS_CHAN_ATTR(intr_in_full, 0444, channel_intr_in_full_show, NULL);
1543
Kimberly Brown14948e32019-03-14 16:05:15 -04001544static ssize_t channel_intr_out_empty_show(struct vmbus_channel *channel,
Kimberly Brown396ae572019-02-04 02:13:09 -05001545 char *buf)
1546{
1547 return sprintf(buf, "%llu\n",
1548 (unsigned long long)channel->intr_out_empty);
1549}
1550static VMBUS_CHAN_ATTR(intr_out_empty, 0444, channel_intr_out_empty_show, NULL);
1551
Kimberly Brown14948e32019-03-14 16:05:15 -04001552static ssize_t channel_out_full_first_show(struct vmbus_channel *channel,
Kimberly Brown396ae572019-02-04 02:13:09 -05001553 char *buf)
1554{
1555 return sprintf(buf, "%llu\n",
1556 (unsigned long long)channel->out_full_first);
1557}
1558static VMBUS_CHAN_ATTR(out_full_first, 0444, channel_out_full_first_show, NULL);
1559
Kimberly Brown14948e32019-03-14 16:05:15 -04001560static ssize_t channel_out_full_total_show(struct vmbus_channel *channel,
Kimberly Brown396ae572019-02-04 02:13:09 -05001561 char *buf)
1562{
1563 return sprintf(buf, "%llu\n",
1564 (unsigned long long)channel->out_full_total);
1565}
1566static VMBUS_CHAN_ATTR(out_full_total, 0444, channel_out_full_total_show, NULL);
1567
Kimberly Brown14948e32019-03-14 16:05:15 -04001568static ssize_t subchannel_monitor_id_show(struct vmbus_channel *channel,
Stephen Hemmingerf0fa2972018-01-09 10:29:06 -08001569 char *buf)
1570{
1571 return sprintf(buf, "%u\n", channel->offermsg.monitorid);
1572}
1573static VMBUS_CHAN_ATTR(monitor_id, S_IRUGO, subchannel_monitor_id_show, NULL);
1574
Kimberly Brown14948e32019-03-14 16:05:15 -04001575static ssize_t subchannel_id_show(struct vmbus_channel *channel,
Stephen Hemmingerf0fa2972018-01-09 10:29:06 -08001576 char *buf)
1577{
1578 return sprintf(buf, "%u\n",
1579 channel->offermsg.offer.sub_channel_index);
1580}
1581static VMBUS_CHAN_ATTR_RO(subchannel_id);
1582
Stephen Hemmingerc2e5df62017-09-21 20:58:49 -07001583static 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 Hemminger6981fbf2017-10-29 11:33:40 -07001591 &chan_attr_interrupts.attr,
1592 &chan_attr_events.attr,
Kimberly Brown396ae572019-02-04 02:13:09 -05001593 &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 Hemmingerf0fa2972018-01-09 10:29:06 -08001597 &chan_attr_monitor_id.attr,
1598 &chan_attr_subchannel_id.attr,
Stephen Hemmingerc2e5df62017-09-21 20:58:49 -07001599 NULL
1600};
1601
Kimberly Brown46fc1542019-03-19 00:04:01 -04001602/*
1603 * Channel-level attribute_group callback function. Returns the permission for
1604 * each attribute, and returns 0 if an attribute is not visible.
1605 */
1606static 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
1622static struct attribute_group vmbus_chan_group = {
1623 .attrs = vmbus_chan_attrs,
1624 .is_visible = vmbus_chan_attr_is_visible
1625};
1626
Stephen Hemmingerc2e5df62017-09-21 20:58:49 -07001627static struct kobj_type vmbus_chan_ktype = {
1628 .sysfs_ops = &vmbus_chan_sysfs_ops,
1629 .release = vmbus_chan_release,
Stephen Hemmingerc2e5df62017-09-21 20:58:49 -07001630};
1631
1632/*
1633 * vmbus_add_channel_kobj - setup a sub-directory under device/channels
1634 */
1635int vmbus_add_channel_kobj(struct hv_device *dev, struct vmbus_channel *channel)
1636{
Kimberly Brown46fc1542019-03-19 00:04:01 -04001637 const struct device *device = &dev->device;
Stephen Hemmingerc2e5df62017-09-21 20:58:49 -07001638 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 Brown46fc1542019-03-19 00:04:01 -04001648 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 Hemmingerc2e5df62017-09-21 20:58:49 -07001659 kobject_uevent(kobj, KOBJ_ADD);
1660
1661 return 0;
1662}
1663
Hank Janssen3e189512010-03-04 22:11:00 +00001664/*
Kimberly Brown46fc1542019-03-19 00:04:01 -04001665 * vmbus_remove_channel_attr_group - remove the channel's attribute group
1666 */
1667void vmbus_remove_channel_attr_group(struct vmbus_channel *channel)
1668{
1669 sysfs_remove_group(&channel->kobj, &vmbus_chan_group);
1670}
1671
1672/*
K. Y. Srinivasanf2c73012011-09-08 07:24:12 -07001673 * vmbus_device_create - Creates and registers a new child device
Hank Janssen3e189512010-03-04 22:11:00 +00001674 * on the vmbus.
Greg Kroah-Hartman90c99602009-09-02 07:11:14 -07001675 */
Andy Shevchenko593db802019-01-10 16:25:32 +02001676struct hv_device *vmbus_device_create(const guid_t *type,
1677 const guid_t *instance,
stephen hemminger1b9d48f2014-06-03 08:38:15 -07001678 struct vmbus_channel *channel)
Hank Janssen3e7ee492009-07-13 16:02:34 -07001679{
Nicolas Palix3d3b5512009-07-28 17:32:53 +02001680 struct hv_device *child_device_obj;
Hank Janssen3e7ee492009-07-13 16:02:34 -07001681
K. Y. Srinivasan6bad88da2011-03-07 13:35:48 -08001682 child_device_obj = kzalloc(sizeof(struct hv_device), GFP_KERNEL);
1683 if (!child_device_obj) {
Hank Janssen0a466182011-03-29 13:58:47 -07001684 pr_err("Unable to allocate device object for child device\n");
Hank Janssen3e7ee492009-07-13 16:02:34 -07001685 return NULL;
1686 }
1687
Greg Kroah-Hartmancae5b842010-10-21 09:05:27 -07001688 child_device_obj->channel = channel;
Andy Shevchenko593db802019-01-10 16:25:32 +02001689 guid_copy(&child_device_obj->dev_type, type);
1690 guid_copy(&child_device_obj->dev_instance, instance);
K. Y. Srinivasan7047f172015-12-25 20:00:30 -08001691 child_device_obj->vendor_id = 0x1414; /* MSFT vendor ID */
Hank Janssen3e7ee492009-07-13 16:02:34 -07001692
Hank Janssen3e7ee492009-07-13 16:02:34 -07001693 return child_device_obj;
1694}
1695
Hank Janssen3e189512010-03-04 22:11:00 +00001696/*
K. Y. Srinivasan227942812011-09-08 07:24:13 -07001697 * vmbus_device_register - Register the child device
Greg Kroah-Hartman90c99602009-09-02 07:11:14 -07001698 */
K. Y. Srinivasan227942812011-09-08 07:24:13 -07001699int vmbus_device_register(struct hv_device *child_device_obj)
Hank Janssen3e7ee492009-07-13 16:02:34 -07001700{
Stephen Hemmingerc2e5df62017-09-21 20:58:49 -07001701 struct kobject *kobj = &child_device_obj->device.kobj;
1702 int ret;
K. Y. Srinivasan6bad88da2011-03-07 13:35:48 -08001703
Stephen Hemmingerf6b2db02016-11-01 00:01:59 -07001704 dev_set_name(&child_device_obj->device, "%pUl",
Vitaly Kuznetsovb2948092016-09-16 09:01:17 -07001705 child_device_obj->channel->offermsg.offer.if_instance.b);
Hank Janssen3e7ee492009-07-13 16:02:34 -07001706
K. Y. Srinivasan0bce28b2011-08-27 11:31:39 -07001707 child_device_obj->device.bus = &hv_bus;
K. Y. Srinivasan607c1a12011-06-06 15:49:39 -07001708 child_device_obj->device.parent = &hv_acpi_dev->dev;
K. Y. Srinivasan6bad88da2011-03-07 13:35:48 -08001709 child_device_obj->device.release = vmbus_device_release;
Hank Janssen3e7ee492009-07-13 16:02:34 -07001710
Greg Kroah-Hartman90c99602009-09-02 07:11:14 -07001711 /*
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. Srinivasan6bad88da2011-03-07 13:35:48 -08001715 ret = device_register(&child_device_obj->device);
Stephen Hemmingerc2e5df62017-09-21 20:58:49 -07001716 if (ret) {
Hank Janssen0a466182011-03-29 13:58:47 -07001717 pr_err("Unable to register child device\n");
Stephen Hemmingerc2e5df62017-09-21 20:58:49 -07001718 return ret;
1719 }
Hank Janssen3e7ee492009-07-13 16:02:34 -07001720
Stephen Hemmingerc2e5df62017-09-21 20:58:49 -07001721 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
1737err_kset_unregister:
1738 kset_unregister(child_device_obj->channels_kset);
1739
1740err_dev_unregister:
1741 device_unregister(&child_device_obj->device);
Hank Janssen3e7ee492009-07-13 16:02:34 -07001742 return ret;
1743}
1744
Hank Janssen3e189512010-03-04 22:11:00 +00001745/*
K. Y. Srinivasan696453b2011-09-08 07:24:14 -07001746 * vmbus_device_unregister - Remove the specified child device
Hank Janssen3e189512010-03-04 22:11:00 +00001747 * from the vmbus.
Greg Kroah-Hartman90c99602009-09-02 07:11:14 -07001748 */
K. Y. Srinivasan696453b2011-09-08 07:24:14 -07001749void vmbus_device_unregister(struct hv_device *device_obj)
Hank Janssen3e7ee492009-07-13 16:02:34 -07001750{
Fernando Soto84672362013-06-14 23:13:35 +00001751 pr_debug("child device %s unregistered\n",
1752 dev_name(&device_obj->device));
1753
Dexuan Cui869b5562017-11-14 06:53:32 -07001754 kset_unregister(device_obj->channels_kset);
1755
Greg Kroah-Hartman90c99602009-09-02 07:11:14 -07001756 /*
1757 * Kick off the process of unregistering the device.
1758 * This will call vmbus_remove() and eventually vmbus_device_release()
1759 */
K. Y. Srinivasan6bad88da2011-03-07 13:35:48 -08001760 device_unregister(&device_obj->device);
Hank Janssen3e7ee492009-07-13 16:02:34 -07001761}
1762
Hank Janssen3e7ee492009-07-13 16:02:34 -07001763
K. Y. Srinivasanb0069f42011-04-29 13:45:15 -07001764/*
Jake Oshins7f163a62015-08-05 00:52:36 -07001765 * VMBUS is an acpi enumerated device. Get the information we
K. Y. Srinivasan90f34532014-01-29 18:14:39 -08001766 * need from DSDT.
K. Y. Srinivasanb0069f42011-04-29 13:45:15 -07001767 */
Jake Oshins7f163a62015-08-05 00:52:36 -07001768#define VTPM_BASE_ADDRESS 0xfed40000
K. Y. Srinivasan90f34532014-01-29 18:14:39 -08001769static acpi_status vmbus_walk_resources(struct acpi_resource *res, void *ctx)
K. Y. Srinivasanb0069f42011-04-29 13:45:15 -07001770{
Jake Oshins7f163a62015-08-05 00:52:36 -07001771 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. Srinivasan90f34532014-01-29 18:14:39 -08001777 switch (res->type) {
Jake Oshins7f163a62015-08-05 00:52:36 -07001778
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 Hoffmann4eb923f2014-02-24 14:17:08 +01001787 break;
K. Y. Srinivasanb0069f42011-04-29 13:45:15 -07001788
K. Y. Srinivasan90f34532014-01-29 18:14:39 -08001789 case ACPI_RESOURCE_TYPE_ADDRESS64:
Jake Oshins7f163a62015-08-05 00:52:36 -07001790 start = res->data.address64.address.minimum;
1791 end = res->data.address64.address.maximum;
Gerd Hoffmann4eb923f2014-02-24 14:17:08 +01001792 break;
Jake Oshins7f163a62015-08-05 00:52:36 -07001793
1794 default:
1795 /* Unused resource type */
1796 return AE_OK;
1797
K. Y. Srinivasanb0069f42011-04-29 13:45:15 -07001798 }
Jake Oshins7f163a62015-08-05 00:52:36 -07001799 /*
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 Oshins40f26f32015-12-14 16:01:52 -08001819 /*
Jake Oshins40f26f32015-12-14 16:01:52 -08001820 * If two ranges are adjacent, merge them.
1821 */
Jake Oshins7f163a62015-08-05 00:52:36 -07001822 do {
1823 if (!*old_res) {
1824 *old_res = new_res;
1825 break;
1826 }
1827
Jake Oshins40f26f32015-12-14 16:01:52 -08001828 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 Oshins23a06832016-04-05 10:22:53 -07001840 if ((*old_res)->start > new_res->end) {
Jake Oshins7f163a62015-08-05 00:52:36 -07001841 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. Srinivasanb0069f42011-04-29 13:45:15 -07001852
1853 return AE_OK;
1854}
1855
Jake Oshins7f163a62015-08-05 00:52:36 -07001856static 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 Oshins6d146ae2016-04-05 10:22:55 -07001862 if (fb_mmio) {
1863 __release_region(hyperv_mmio, fb_mmio->start,
1864 resource_size(fb_mmio));
1865 fb_mmio = NULL;
1866 }
1867
Jake Oshins7f163a62015-08-05 00:52:36 -07001868 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 Oshins6d146ae2016-04-05 10:22:55 -07001877static 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 Oshins35464482015-08-05 00:52:37 -07001901/**
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 */
1924int 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 Oshinsbe000f92016-04-05 10:22:54 -07001929 struct resource *iter, *shadow;
Jake Oshinsea37a6b2016-04-05 10:22:56 -07001930 resource_size_t range_min, range_max, start;
Jake Oshins35464482015-08-05 00:52:37 -07001931 const char *dev_n = dev_name(&device_obj->device);
Jake Oshinsea37a6b2016-04-05 10:22:56 -07001932 int retval;
Jake Oshinse16dad62016-04-05 10:22:50 -07001933
1934 retval = -ENXIO;
1935 down(&hyperv_mmio_lock);
Jake Oshins35464482015-08-05 00:52:37 -07001936
Jake Oshinsea37a6b2016-04-05 10:22:56 -07001937 /*
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 Oshins35464482015-08-05 00:52:37 -07001957 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 Oshinsea37a6b2016-04-05 10:22:56 -07001963 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 Oshins35464482015-08-05 00:52:37 -07001969
Jake Oshinsea37a6b2016-04-05 10:22:56 -07001970 *new = request_mem_region_exclusive(start, size, dev_n);
1971 if (*new) {
1972 shadow->name = (char *)*new;
1973 retval = 0;
1974 goto exit;
Jake Oshins35464482015-08-05 00:52:37 -07001975 }
1976
Jake Oshinsea37a6b2016-04-05 10:22:56 -07001977 __release_region(iter, start, size);
Jake Oshins35464482015-08-05 00:52:37 -07001978 }
1979 }
1980
Jake Oshinse16dad62016-04-05 10:22:50 -07001981exit:
1982 up(&hyperv_mmio_lock);
1983 return retval;
Jake Oshins35464482015-08-05 00:52:37 -07001984}
1985EXPORT_SYMBOL_GPL(vmbus_allocate_mmio);
1986
Jake Oshins619848b2015-12-14 16:01:39 -08001987/**
Jake Oshins97fb77dc2016-04-05 10:22:51 -07001988 * 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 */
1995void vmbus_free_mmio(resource_size_t start, resource_size_t size)
1996{
Jake Oshinsbe000f92016-04-05 10:22:54 -07001997 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 Oshins97fb77dc2016-04-05 10:22:51 -07002006 release_mem_region(start, size);
Jake Oshinsbe000f92016-04-05 10:22:54 -07002007 up(&hyperv_mmio_lock);
Jake Oshins97fb77dc2016-04-05 10:22:51 -07002008
2009}
2010EXPORT_SYMBOL_GPL(vmbus_free_mmio);
2011
K. Y. Srinivasanb0069f42011-04-29 13:45:15 -07002012static int vmbus_acpi_add(struct acpi_device *device)
2013{
2014 acpi_status result;
K. Y. Srinivasan90f34532014-01-29 18:14:39 -08002015 int ret_val = -ENODEV;
Jake Oshins7f163a62015-08-05 00:52:36 -07002016 struct acpi_device *ancestor;
K. Y. Srinivasanb0069f42011-04-29 13:45:15 -07002017
K. Y. Srinivasan607c1a12011-06-06 15:49:39 -07002018 hv_acpi_dev = device;
2019
K. Y. Srinivasan0a4425b2011-08-27 11:31:38 -07002020 result = acpi_walk_resources(device->handle, METHOD_NAME__CRS,
K. Y. Srinivasan90f34532014-01-29 18:14:39 -08002021 vmbus_walk_resources, NULL);
K. Y. Srinivasanb0069f42011-04-29 13:45:15 -07002022
K. Y. Srinivasan90f34532014-01-29 18:14:39 -08002023 if (ACPI_FAILURE(result))
2024 goto acpi_walk_err;
2025 /*
Jake Oshins7f163a62015-08-05 00:52:36 -07002026 * Some ancestor of the vmbus acpi device (Gen1 or Gen2
2027 * firmware) is the VMOD that has the mmio ranges. Get that.
K. Y. Srinivasan90f34532014-01-29 18:14:39 -08002028 */
Jake Oshins7f163a62015-08-05 00:52:36 -07002029 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. Srinivasan90f34532014-01-29 18:14:39 -08002032
2033 if (ACPI_FAILURE(result))
Jake Oshins7f163a62015-08-05 00:52:36 -07002034 continue;
Jake Oshins6d146ae2016-04-05 10:22:55 -07002035 if (hyperv_mmio) {
2036 vmbus_reserve_fb();
Jake Oshins7f163a62015-08-05 00:52:36 -07002037 break;
Jake Oshins6d146ae2016-04-05 10:22:55 -07002038 }
K. Y. Srinivasanb0069f42011-04-29 13:45:15 -07002039 }
K. Y. Srinivasan90f34532014-01-29 18:14:39 -08002040 ret_val = 0;
2041
2042acpi_walk_err:
K. Y. Srinivasanb0069f42011-04-29 13:45:15 -07002043 complete(&probe_event);
Jake Oshins7f163a62015-08-05 00:52:36 -07002044 if (ret_val)
2045 vmbus_acpi_remove(device);
K. Y. Srinivasan90f34532014-01-29 18:14:39 -08002046 return ret_val;
K. Y. Srinivasanb0069f42011-04-29 13:45:15 -07002047}
2048
2049static const struct acpi_device_id vmbus_acpi_device_ids[] = {
2050 {"VMBUS", 0},
K. Y. Srinivasan9d7b18d2011-06-06 15:49:42 -07002051 {"VMBus", 0},
K. Y. Srinivasanb0069f42011-04-29 13:45:15 -07002052 {"", 0},
2053};
2054MODULE_DEVICE_TABLE(acpi, vmbus_acpi_device_ids);
2055
2056static struct acpi_driver vmbus_acpi_driver = {
2057 .name = "vmbus",
2058 .ids = vmbus_acpi_device_ids,
2059 .ops = {
2060 .add = vmbus_acpi_add,
Vitaly Kuznetsove4ecb412015-04-22 21:31:28 -07002061 .remove = vmbus_acpi_remove,
K. Y. Srinivasanb0069f42011-04-29 13:45:15 -07002062 },
2063};
2064
Vitaly Kuznetsov25172812015-08-01 16:08:07 -07002065static void hv_kexec_handler(void)
2066{
Vitaly Kuznetsov25172812015-08-01 16:08:07 -07002067 hv_synic_clockevents_cleanup();
Vitaly Kuznetsov75ff3a82016-02-26 15:13:16 -08002068 vmbus_initiate_unload(false);
Vitaly Kuznetsov523b9402016-12-07 14:53:12 -08002069 vmbus_connection.conn_state = DISCONNECTED;
2070 /* Make sure conn_state is set as hv_synic_cleanup checks for it */
2071 mb();
Vitaly Kuznetsov76d36ab2016-12-07 14:53:11 -08002072 cpuhp_remove_state(hyperv_cpuhp_online);
Vitaly Kuznetsovd6f36092017-01-28 12:37:14 -07002073 hyperv_cleanup();
Vitaly Kuznetsov25172812015-08-01 16:08:07 -07002074};
2075
Vitaly Kuznetsovb4370df2015-08-01 16:08:09 -07002076static void hv_crash_handler(struct pt_regs *regs)
2077{
Vitaly Kuznetsov75ff3a82016-02-26 15:13:16 -08002078 vmbus_initiate_unload(true);
Vitaly Kuznetsovb4370df2015-08-01 16:08:09 -07002079 /*
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 Kuznetsov523b9402016-12-07 14:53:12 -08002084 vmbus_connection.conn_state = DISCONNECTED;
Vitaly Kuznetsov76d36ab2016-12-07 14:53:11 -08002085 hv_synic_cleanup(smp_processor_id());
Vitaly Kuznetsovd6f36092017-01-28 12:37:14 -07002086 hyperv_cleanup();
Vitaly Kuznetsovb4370df2015-08-01 16:08:09 -07002087};
2088
K. Y. Srinivasan607c1a12011-06-06 15:49:39 -07002089static int __init hv_acpi_init(void)
K. Y. Srinivasan1168ac22011-03-15 15:03:32 -07002090{
K. Y. Srinivasan2dda95f2011-07-15 13:38:56 -07002091 int ret, t;
K. Y. Srinivasanb0069f42011-04-29 13:45:15 -07002092
Michael Kelley4a5f3cd2017-12-22 11:19:02 -07002093 if (!hv_is_hyperv_initialized())
Jason Wang05929692012-08-17 18:52:43 +08002094 return -ENODEV;
2095
K. Y. Srinivasanb0069f42011-04-29 13:45:15 -07002096 init_completion(&probe_event);
2097
2098 /*
K. Y. Srinivasanefc26722015-12-14 16:01:46 -08002099 * Get ACPI resources first.
K. Y. Srinivasanb0069f42011-04-29 13:45:15 -07002100 */
K. Y. Srinivasan02466042011-06-06 15:49:40 -07002101 ret = acpi_bus_register_driver(&vmbus_acpi_driver);
2102
K. Y. Srinivasanb0069f42011-04-29 13:45:15 -07002103 if (ret)
2104 return ret;
2105
K. Y. Srinivasan2dda95f2011-07-15 13:38:56 -07002106 t = wait_for_completion_timeout(&probe_event, 5*HZ);
2107 if (t == 0) {
2108 ret = -ETIMEDOUT;
2109 goto cleanup;
2110 }
K. Y. Srinivasanb0069f42011-04-29 13:45:15 -07002111
K. Y. Srinivasanefc26722015-12-14 16:01:46 -08002112 ret = vmbus_bus_init();
K. Y. Srinivasan91fd7992011-06-16 13:16:38 -07002113 if (ret)
K. Y. Srinivasan2dda95f2011-07-15 13:38:56 -07002114 goto cleanup;
2115
Vitaly Kuznetsov25172812015-08-01 16:08:07 -07002116 hv_setup_kexec_handler(hv_kexec_handler);
Vitaly Kuznetsovb4370df2015-08-01 16:08:09 -07002117 hv_setup_crash_handler(hv_crash_handler);
Vitaly Kuznetsov25172812015-08-01 16:08:07 -07002118
K. Y. Srinivasan2dda95f2011-07-15 13:38:56 -07002119 return 0;
2120
2121cleanup:
2122 acpi_bus_unregister_driver(&vmbus_acpi_driver);
K. Y. Srinivasancf6a2ea2011-12-01 09:59:34 -08002123 hv_acpi_dev = NULL;
K. Y. Srinivasan91fd7992011-06-16 13:16:38 -07002124 return ret;
K. Y. Srinivasan1168ac22011-03-15 15:03:32 -07002125}
2126
K. Y. Srinivasan93e5bd02011-12-12 09:29:17 -08002127static void __exit vmbus_exit(void)
2128{
Vitaly Kuznetsove72e7ac2015-02-27 11:25:55 -08002129 int cpu;
2130
Vitaly Kuznetsov25172812015-08-01 16:08:07 -07002131 hv_remove_kexec_handler();
Vitaly Kuznetsovb4370df2015-08-01 16:08:09 -07002132 hv_remove_crash_handler();
Vitaly Kuznetsov09a19622015-02-27 11:25:54 -08002133 vmbus_connection.conn_state = DISCONNECTED;
Vitaly Kuznetsove0867482015-02-27 11:25:57 -08002134 hv_synic_clockevents_cleanup();
K. Y. Srinivasan2db84ef2015-04-22 21:31:32 -07002135 vmbus_disconnect();
Thomas Gleixner76d388c2014-03-05 13:42:14 +01002136 hv_remove_vmbus_irq();
Stephen Hemminger37cdd992017-02-11 23:02:19 -07002137 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. Srinivasan93e5bd02011-12-12 09:29:17 -08002143 vmbus_free_channels();
Stephen Hemminger37cdd992017-02-11 23:02:19 -07002144
Denis V. Lunevcc2dd402015-08-01 16:08:20 -07002145 if (ms_hyperv.misc_features & HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE) {
Sunil Muthuswamy81b18bc2018-07-08 02:56:51 +00002146 kmsg_dump_unregister(&hv_kmsg_dumper);
Vitaly Kuznetsov510f7ae2015-08-01 16:08:10 -07002147 unregister_die_notifier(&hyperv_die_block);
Vitaly Kuznetsov096c6052015-04-22 21:31:29 -07002148 atomic_notifier_chain_unregister(&panic_notifier_list,
2149 &hyperv_panic_block);
2150 }
Sunil Muthuswamy81b18bc2018-07-08 02:56:51 +00002151
2152 free_page((unsigned long)hv_panic_page);
Sunil Muthuswamy8afc06d2018-07-28 21:58:46 +00002153 unregister_sysctl_table(hv_ctl_table_hdr);
2154 hv_ctl_table_hdr = NULL;
K. Y. Srinivasan93e5bd02011-12-12 09:29:17 -08002155 bus_unregister(&hv_bus);
Stephen Hemminger37cdd992017-02-11 23:02:19 -07002156
Vitaly Kuznetsov76d36ab2016-12-07 14:53:11 -08002157 cpuhp_remove_state(hyperv_cpuhp_online);
Vitaly Kuznetsov06210b42015-08-01 16:08:05 -07002158 hv_synic_free();
K. Y. Srinivasan93e5bd02011-12-12 09:29:17 -08002159 acpi_bus_unregister_driver(&vmbus_acpi_driver);
2160}
2161
K. Y. Srinivasan1168ac22011-03-15 15:03:32 -07002162
Greg Kroah-Hartman90c99602009-09-02 07:11:14 -07002163MODULE_LICENSE("GPL");
Hank Janssen3e7ee492009-07-13 16:02:34 -07002164
K. Y. Srinivasan43d4e112011-10-24 11:28:12 -07002165subsys_initcall(hv_acpi_init);
K. Y. Srinivasan93e5bd02011-12-12 09:29:17 -08002166module_exit(vmbus_exit);