]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c
MFC 297142,297143,297176,297177,297178,297221
[FreeBSD/stable/10.git] / sys / dev / hyperv / vmbus / hv_vmbus_drv_freebsd.c
1 /*-
2  * Copyright (c) 2009-2012 Microsoft Corp.
3  * Copyright (c) 2012 NetApp Inc.
4  * Copyright (c) 2012 Citrix Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice unmodified, this list of conditions, and the following
12  *    disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28
29 /*
30  * VM Bus Driver Implementation
31  */
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
34
35 #include <sys/param.h>
36 #include <sys/bus.h>
37 #include <sys/kernel.h>
38 #include <sys/lock.h>
39 #include <sys/malloc.h>
40 #include <sys/module.h>
41 #include <sys/proc.h>
42 #include <sys/sysctl.h>
43 #include <sys/syslog.h>
44 #include <sys/systm.h>
45 #include <sys/rtprio.h>
46 #include <sys/interrupt.h>
47 #include <sys/sx.h>
48 #include <sys/taskqueue.h>
49 #include <sys/mutex.h>
50 #include <sys/smp.h>
51
52 #include <machine/resource.h>
53 #include <sys/rman.h>
54
55 #include <machine/stdarg.h>
56 #include <machine/intr_machdep.h>
57 #include <machine/md_var.h>
58 #include <machine/segments.h>
59 #include <sys/pcpu.h>
60 #include <machine/apicvar.h>
61
62 #include <dev/hyperv/include/hyperv.h>
63 #include "hv_vmbus_priv.h"
64
65 #include <contrib/dev/acpica/include/acpi.h>
66 #include "acpi_if.h"
67
68 static device_t vmbus_devp;
69 static int vmbus_inited;
70 static hv_setup_args setup_args; /* only CPU 0 supported at this time */
71
72 static char *vmbus_ids[] = { "VMBUS", NULL };
73
74 /**
75  * @brief Software interrupt thread routine to handle channel messages from
76  * the hypervisor.
77  */
78 static void
79 vmbus_msg_swintr(void *arg, int pending __unused)
80 {
81         int                     cpu;
82         void*                   page_addr;
83         hv_vmbus_channel_msg_header      *hdr;
84         hv_vmbus_channel_msg_table_entry *entry;
85         hv_vmbus_channel_msg_type msg_type;
86         hv_vmbus_message*       msg;
87
88         cpu = (int)(long)arg;
89         KASSERT(cpu <= mp_maxid, ("VMBUS: vmbus_msg_swintr: "
90             "cpu out of range!"));
91
92         page_addr = hv_vmbus_g_context.syn_ic_msg_page[cpu];
93         msg = (hv_vmbus_message*) page_addr + HV_VMBUS_MESSAGE_SINT;
94
95         for (;;) {
96                 if (msg->header.message_type == HV_MESSAGE_TYPE_NONE)
97                         break; /* no message */
98
99                 hdr = (hv_vmbus_channel_msg_header *)msg->u.payload;
100                 msg_type = hdr->message_type;
101
102                 if (msg_type >= HV_CHANNEL_MESSAGE_COUNT) {
103                         printf("VMBUS: unknown message type = %d\n", msg_type);
104                         goto handled;
105                 }
106
107                 entry = &g_channel_message_table[msg_type];
108
109                 if (entry->messageHandler)
110                         entry->messageHandler(hdr);
111 handled:
112             msg->header.message_type = HV_MESSAGE_TYPE_NONE;
113
114             /*
115              * Make sure the write to message_type (ie set to
116              * HV_MESSAGE_TYPE_NONE) happens before we read the
117              * message_pending and EOMing. Otherwise, the EOMing will
118              * not deliver any more messages
119              * since there is no empty slot
120              *
121              * NOTE:
122              * mb() is used here, since atomic_thread_fence_seq_cst()
123              * will become compler fence on UP kernel.
124              */
125             mb();
126
127             if (msg->header.message_flags.u.message_pending) {
128                         /*
129                          * This will cause message queue rescan to possibly
130                          * deliver another msg from the hypervisor
131                          */
132                         wrmsr(HV_X64_MSR_EOM, 0);
133             }
134         }
135 }
136
137 /**
138  * @brief Interrupt filter routine for VMBUS.
139  *
140  * The purpose of this routine is to determine the type of VMBUS protocol
141  * message to process - an event or a channel message.
142  */
143 static inline int
144 hv_vmbus_isr(struct trapframe *frame)
145 {
146         int                             cpu;
147         hv_vmbus_message*               msg;
148         hv_vmbus_synic_event_flags*     event;
149         void*                           page_addr;
150
151         cpu = PCPU_GET(cpuid);
152
153         /*
154          * The Windows team has advised that we check for events
155          * before checking for messages. This is the way they do it
156          * in Windows when running as a guest in Hyper-V
157          */
158
159         page_addr = hv_vmbus_g_context.syn_ic_event_page[cpu];
160         event = (hv_vmbus_synic_event_flags*)
161                     page_addr + HV_VMBUS_MESSAGE_SINT;
162
163         if ((hv_vmbus_protocal_version == HV_VMBUS_VERSION_WS2008) ||
164             (hv_vmbus_protocal_version == HV_VMBUS_VERSION_WIN7)) {
165                 /* Since we are a child, we only need to check bit 0 */
166                 if (synch_test_and_clear_bit(0, &event->flags32[0])) {
167                         hv_vmbus_on_events(cpu);
168                 }
169         } else {
170                 /*
171                  * On host with Win8 or above, we can directly look at
172                  * the event page. If bit n is set, we have an interrupt 
173                  * on the channel with id n.
174                  * Directly schedule the event software interrupt on
175                  * current cpu.
176                  */
177                 hv_vmbus_on_events(cpu);
178         }
179
180         /* Check if there are actual msgs to be process */
181         page_addr = hv_vmbus_g_context.syn_ic_msg_page[cpu];
182         msg = (hv_vmbus_message*) page_addr + HV_VMBUS_TIMER_SINT;
183
184         /* we call eventtimer process the message */
185         if (msg->header.message_type == HV_MESSAGE_TIMER_EXPIRED) {
186                 msg->header.message_type = HV_MESSAGE_TYPE_NONE;
187
188                 /* call intrrupt handler of event timer */
189                 hv_et_intr(frame);
190
191                 /*
192                  * Make sure the write to message_type (ie set to
193                  * HV_MESSAGE_TYPE_NONE) happens before we read the
194                  * message_pending and EOMing. Otherwise, the EOMing will
195                  * not deliver any more messages
196                  * since there is no empty slot
197                  *
198                  * NOTE:
199                  * mb() is used here, since atomic_thread_fence_seq_cst()
200                  * will become compler fence on UP kernel.
201                  */
202                 mb();
203
204                 if (msg->header.message_flags.u.message_pending) {
205                         /*
206                          * This will cause message queue rescan to possibly
207                          * deliver another msg from the hypervisor
208                          */
209                         wrmsr(HV_X64_MSR_EOM, 0);
210                 }
211         }
212
213         msg = (hv_vmbus_message*) page_addr + HV_VMBUS_MESSAGE_SINT;
214         if (msg->header.message_type != HV_MESSAGE_TYPE_NONE) {
215                 taskqueue_enqueue(hv_vmbus_g_context.hv_msg_tq[cpu],
216                     &hv_vmbus_g_context.hv_msg_task[cpu]);
217         }
218
219         return (FILTER_HANDLED);
220 }
221
222 u_long *hv_vmbus_intr_cpu[MAXCPU];
223
224 void
225 hv_vector_handler(struct trapframe *trap_frame)
226 {
227         int cpu;
228
229         /*
230          * Disable preemption.
231          */
232         critical_enter();
233
234         /*
235          * Do a little interrupt counting.
236          */
237         cpu = PCPU_GET(cpuid);
238         (*hv_vmbus_intr_cpu[cpu])++;
239
240         hv_vmbus_isr(trap_frame);
241
242         /*
243          * Enable preemption.
244          */
245         critical_exit();
246 }
247
248 static int
249 vmbus_read_ivar(
250         device_t        dev,
251         device_t        child,
252         int             index,
253         uintptr_t*      result)
254 {
255         struct hv_device *child_dev_ctx = device_get_ivars(child);
256
257         switch (index) {
258
259         case HV_VMBUS_IVAR_TYPE:
260                 *result = (uintptr_t) &child_dev_ctx->class_id;
261                 return (0);
262         case HV_VMBUS_IVAR_INSTANCE:
263                 *result = (uintptr_t) &child_dev_ctx->device_id;
264                 return (0);
265         case HV_VMBUS_IVAR_DEVCTX:
266                 *result = (uintptr_t) child_dev_ctx;
267                 return (0);
268         case HV_VMBUS_IVAR_NODE:
269                 *result = (uintptr_t) child_dev_ctx->device;
270                 return (0);
271         }
272         return (ENOENT);
273 }
274
275 static int
276 vmbus_write_ivar(
277         device_t        dev,
278         device_t        child,
279         int             index,
280         uintptr_t       value)
281 {
282         switch (index) {
283
284         case HV_VMBUS_IVAR_TYPE:
285         case HV_VMBUS_IVAR_INSTANCE:
286         case HV_VMBUS_IVAR_DEVCTX:
287         case HV_VMBUS_IVAR_NODE:
288                 /* read-only */
289                 return (EINVAL);
290         }
291         return (ENOENT);
292 }
293
294 static int
295 vmbus_child_pnpinfo_str(device_t dev, device_t child, char *buf, size_t buflen)
296 {
297         char guidbuf[40];
298         struct hv_device *dev_ctx = device_get_ivars(child);
299
300         strlcat(buf, "classid=", buflen);
301         snprintf_hv_guid(guidbuf, sizeof(guidbuf), &dev_ctx->class_id);
302         strlcat(buf, guidbuf, buflen);
303
304         strlcat(buf, " deviceid=", buflen);
305         snprintf_hv_guid(guidbuf, sizeof(guidbuf), &dev_ctx->device_id);
306         strlcat(buf, guidbuf, buflen);
307
308         return (0);
309 }
310
311 struct hv_device*
312 hv_vmbus_child_device_create(
313         hv_guid         type,
314         hv_guid         instance,
315         hv_vmbus_channel*       channel)
316 {
317         hv_device* child_dev;
318
319         /*
320          * Allocate the new child device
321          */
322         child_dev = malloc(sizeof(hv_device), M_DEVBUF,
323                         M_WAITOK |  M_ZERO);
324
325         child_dev->channel = channel;
326         memcpy(&child_dev->class_id, &type, sizeof(hv_guid));
327         memcpy(&child_dev->device_id, &instance, sizeof(hv_guid));
328
329         return (child_dev);
330 }
331
332 int
333 snprintf_hv_guid(char *buf, size_t sz, const hv_guid *guid)
334 {
335         int cnt;
336         const unsigned char *d = guid->data;
337
338         cnt = snprintf(buf, sz,
339                 "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
340                 d[3], d[2], d[1], d[0], d[5], d[4], d[7], d[6],
341                 d[8], d[9], d[10], d[11], d[12], d[13], d[14], d[15]);
342         return (cnt);
343 }
344
345 int
346 hv_vmbus_child_device_register(struct hv_device *child_dev)
347 {
348         device_t child;
349         int ret = 0;
350
351         if (bootverbose) {
352                 char name[40];
353                 snprintf_hv_guid(name, sizeof(name), &child_dev->class_id);
354                 printf("VMBUS: Class ID: %s\n", name);
355         }
356
357         child = device_add_child(vmbus_devp, NULL, -1);
358         child_dev->device = child;
359         device_set_ivars(child, child_dev);
360
361         mtx_lock(&Giant);
362         ret = device_probe_and_attach(child);
363         mtx_unlock(&Giant);
364
365         return (0);
366 }
367
368 int
369 hv_vmbus_child_device_unregister(struct hv_device *child_dev)
370 {
371         int ret = 0;
372         /*
373          * XXXKYS: Ensure that this is the opposite of
374          * device_add_child()
375          */
376         mtx_lock(&Giant);
377         ret = device_delete_child(vmbus_devp, child_dev->device);
378         mtx_unlock(&Giant);
379         return(ret);
380 }
381
382 static int
383 vmbus_probe(device_t dev) {
384         if (ACPI_ID_PROBE(device_get_parent(dev), dev, vmbus_ids) == NULL ||
385             device_get_unit(dev) != 0)
386                 return (ENXIO);
387
388         device_set_desc(dev, "Vmbus Devices");
389
390         return (BUS_PROBE_DEFAULT);
391 }
392
393 #ifdef HYPERV
394 extern inthand_t IDTVEC(rsvd), IDTVEC(hv_vmbus_callback);
395
396 /**
397  * @brief Find a free IDT slot and setup the interrupt handler.
398  */
399 static int
400 vmbus_vector_alloc(void)
401 {
402         int vector;
403         uintptr_t func;
404         struct gate_descriptor *ip;
405
406         /*
407          * Search backwards form the highest IDT vector available for use
408          * as vmbus channel callback vector. We install 'hv_vmbus_callback'
409          * handler at that vector and use it to interrupt vcpus.
410          */
411         vector = APIC_SPURIOUS_INT;
412         while (--vector >= APIC_IPI_INTS) {
413                 ip = &idt[vector];
414                 func = ((long)ip->gd_hioffset << 16 | ip->gd_looffset);
415                 if (func == (uintptr_t)&IDTVEC(rsvd)) {
416 #ifdef __i386__
417                         setidt(vector , IDTVEC(hv_vmbus_callback), SDT_SYS386IGT,
418                             SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
419 #else
420                         setidt(vector , IDTVEC(hv_vmbus_callback), SDT_SYSIGT,
421                             SEL_KPL, 0);
422 #endif
423
424                         return (vector);
425                 }
426         }
427         return (0);
428 }
429
430 /**
431  * @brief Restore the IDT slot to rsvd.
432  */
433 static void
434 vmbus_vector_free(int vector)
435 {
436         uintptr_t func;
437         struct gate_descriptor *ip;
438
439         if (vector == 0)
440                 return;
441
442         KASSERT(vector >= APIC_IPI_INTS && vector < APIC_SPURIOUS_INT,
443             ("invalid vector %d", vector));
444
445         ip = &idt[vector];
446         func = ((long)ip->gd_hioffset << 16 | ip->gd_looffset);
447         KASSERT(func == (uintptr_t)&IDTVEC(hv_vmbus_callback),
448             ("invalid vector %d", vector));
449
450         setidt(vector, IDTVEC(rsvd), SDT_SYSIGT, SEL_KPL, 0);
451 }
452
453 #else /* HYPERV */
454
455 static int
456 vmbus_vector_alloc(void)
457 {
458         return(0);
459 }
460
461 static void
462 vmbus_vector_free(int vector)
463 {
464 }
465
466 #endif /* HYPERV */
467
468 static void
469 vmbus_cpuset_setthread_task(void *xmask, int pending __unused)
470 {
471         cpuset_t *mask = xmask;
472         int error;
473
474         error = cpuset_setthread(curthread->td_tid, mask);
475         if (error) {
476                 panic("curthread=%ju: can't pin; error=%d",
477                     (uintmax_t)curthread->td_tid, error);
478         }
479 }
480
481 /**
482  * @brief Main vmbus driver initialization routine.
483  *
484  * Here, we
485  * - initialize the vmbus driver context
486  * - setup various driver entry points
487  * - invoke the vmbus hv main init routine
488  * - get the irq resource
489  * - invoke the vmbus to add the vmbus root device
490  * - setup the vmbus root device
491  * - retrieve the channel offers
492  */
493 static int
494 vmbus_bus_init(void)
495 {
496         int i, j, n, ret;
497         char buf[MAXCOMLEN + 1];
498         cpuset_t cpu_mask;
499
500         if (vmbus_inited)
501                 return (0);
502
503         vmbus_inited = 1;
504
505         ret = hv_vmbus_init();
506
507         if (ret) {
508                 if(bootverbose)
509                         printf("Error VMBUS: Hypervisor Initialization Failed!\n");
510                 return (ret);
511         }
512
513         /*
514          * Find a free IDT slot for vmbus callback.
515          */
516         hv_vmbus_g_context.hv_cb_vector = vmbus_vector_alloc();
517
518         if (hv_vmbus_g_context.hv_cb_vector == 0) {
519                 if(bootverbose)
520                         printf("Error VMBUS: Cannot find free IDT slot for "
521                             "vmbus callback!\n");
522                 goto cleanup;
523         }
524
525         if(bootverbose)
526                 printf("VMBUS: vmbus callback vector %d\n",
527                     hv_vmbus_g_context.hv_cb_vector);
528
529         /*
530          * Notify the hypervisor of our vector.
531          */
532         setup_args.vector = hv_vmbus_g_context.hv_cb_vector;
533
534         CPU_FOREACH(j) {
535                 snprintf(buf, sizeof(buf), "cpu%d:hyperv", j);
536                 intrcnt_add(buf, &hv_vmbus_intr_cpu[j]);
537
538                 for (i = 0; i < 2; i++)
539                         setup_args.page_buffers[2 * j + i] = NULL;
540         }
541
542         /*
543          * Per cpu setup.
544          */
545         CPU_FOREACH(j) {
546                 struct task cpuset_task;
547
548                 /*
549                  * Setup taskqueue to handle events
550                  */
551                 hv_vmbus_g_context.hv_event_queue[j] = taskqueue_create_fast("hyperv event", M_WAITOK,
552                         taskqueue_thread_enqueue, &hv_vmbus_g_context.hv_event_queue[j]);
553                 taskqueue_start_threads(&hv_vmbus_g_context.hv_event_queue[j], 1, PI_NET,
554                         "hvevent%d", j);
555
556                 CPU_SETOF(j, &cpu_mask);
557                 TASK_INIT(&cpuset_task, 0, vmbus_cpuset_setthread_task, &cpu_mask);
558                 taskqueue_enqueue(hv_vmbus_g_context.hv_event_queue[j], &cpuset_task);
559                 taskqueue_drain(hv_vmbus_g_context.hv_event_queue[j], &cpuset_task);
560
561                 /*
562                  * Setup per-cpu tasks and taskqueues to handle msg.
563                  */
564                 hv_vmbus_g_context.hv_msg_tq[j] = taskqueue_create_fast(
565                     "hyperv msg", M_WAITOK, taskqueue_thread_enqueue,
566                     &hv_vmbus_g_context.hv_msg_tq[j]);
567                 taskqueue_start_threads(&hv_vmbus_g_context.hv_msg_tq[j], 1, PI_NET,
568                     "hvmsg%d", j);
569                 TASK_INIT(&hv_vmbus_g_context.hv_msg_task[j], 0,
570                     vmbus_msg_swintr, (void *)(long)j);
571
572                 CPU_SETOF(j, &cpu_mask);
573                 TASK_INIT(&cpuset_task, 0, vmbus_cpuset_setthread_task, &cpu_mask);
574                 taskqueue_enqueue(hv_vmbus_g_context.hv_msg_tq[j], &cpuset_task);
575                 taskqueue_drain(hv_vmbus_g_context.hv_msg_tq[j], &cpuset_task);
576
577                 /*
578                  * Prepare the per cpu msg and event pages to be called on each cpu.
579                  */
580                 for(i = 0; i < 2; i++) {
581                         setup_args.page_buffers[2 * j + i] =
582                                 malloc(PAGE_SIZE, M_DEVBUF, M_WAITOK | M_ZERO);
583                 }
584         }
585
586         if (bootverbose)
587                 printf("VMBUS: Calling smp_rendezvous, smp_started = %d\n",
588                     smp_started);
589
590         smp_rendezvous(NULL, hv_vmbus_synic_init, NULL, &setup_args);
591
592         /*
593          * Connect to VMBus in the root partition
594          */
595         ret = hv_vmbus_connect();
596
597         if (ret != 0)
598                 goto cleanup1;
599
600         hv_vmbus_request_channel_offers();
601         return (ret);
602
603         cleanup1:
604         /*
605          * Free pages alloc'ed
606          */
607         for (n = 0; n < 2 * MAXCPU; n++)
608                 if (setup_args.page_buffers[n] != NULL)
609                         free(setup_args.page_buffers[n], M_DEVBUF);
610
611         /*
612          * remove swi and vmbus callback vector;
613          */
614         CPU_FOREACH(j) {
615                 if (hv_vmbus_g_context.hv_event_queue[j] != NULL) {
616                         taskqueue_free(hv_vmbus_g_context.hv_event_queue[j]);
617                         hv_vmbus_g_context.hv_event_queue[j] = NULL;
618                 }
619         }
620
621         vmbus_vector_free(hv_vmbus_g_context.hv_cb_vector);
622
623         cleanup:
624         hv_vmbus_cleanup();
625
626         return (ret);
627 }
628
629 static int
630 vmbus_attach(device_t dev)
631 {
632         if(bootverbose)
633                 device_printf(dev, "VMBUS: attach dev: %p\n", dev);
634         vmbus_devp = dev;
635
636         /* 
637          * If the system has already booted and thread
638          * scheduling is possible indicated by the global
639          * cold set to zero, we just call the driver
640          * initialization directly.
641          */
642         if (!cold)
643                 vmbus_bus_init();
644
645         return (0);
646 }
647
648 static void
649 vmbus_init(void)
650 {
651         if (vm_guest != VM_GUEST_HV)
652                 return;
653
654         /* 
655          * If the system has already booted and thread
656          * scheduling is possible, as indicated by the
657          * global cold set to zero, we just call the driver
658          * initialization directly.
659          */
660         if (!cold) 
661                 vmbus_bus_init();
662 }
663
664 static void
665 vmbus_bus_exit(void)
666 {
667         int i;
668
669         hv_vmbus_release_unattached_channels();
670         hv_vmbus_disconnect();
671
672         smp_rendezvous(NULL, hv_vmbus_synic_cleanup, NULL, NULL);
673
674         for(i = 0; i < 2 * MAXCPU; i++) {
675                 if (setup_args.page_buffers[i] != 0)
676                         free(setup_args.page_buffers[i], M_DEVBUF);
677         }
678
679         hv_vmbus_cleanup();
680
681         /* remove swi */
682         CPU_FOREACH(i) {
683                 if (hv_vmbus_g_context.hv_event_queue[i] != NULL) {
684                         taskqueue_free(hv_vmbus_g_context.hv_event_queue[i]);
685                         hv_vmbus_g_context.hv_event_queue[i] = NULL;
686                 }
687         }
688
689         vmbus_vector_free(hv_vmbus_g_context.hv_cb_vector);
690
691         return;
692 }
693
694 static void
695 vmbus_exit(void)
696 {
697         vmbus_bus_exit();
698 }
699
700 static int
701 vmbus_detach(device_t dev)
702 {
703         vmbus_exit();
704         return (0);
705 }
706
707 static void
708 vmbus_mod_load(void)
709 {
710         if(bootverbose)
711                 printf("VMBUS: load\n");
712 }
713
714 static void
715 vmbus_mod_unload(void)
716 {
717         if(bootverbose)
718                 printf("VMBUS: unload\n");
719 }
720
721 static int
722 vmbus_modevent(module_t mod, int what, void *arg)
723 {
724         switch (what) {
725
726         case MOD_LOAD:
727                 vmbus_mod_load();
728                 break;
729         case MOD_UNLOAD:
730                 vmbus_mod_unload();
731                 break;
732         }
733
734         return (0);
735 }
736
737 static device_method_t vmbus_methods[] = {
738         /** Device interface */
739         DEVMETHOD(device_probe, vmbus_probe),
740         DEVMETHOD(device_attach, vmbus_attach),
741         DEVMETHOD(device_detach, vmbus_detach),
742         DEVMETHOD(device_shutdown, bus_generic_shutdown),
743         DEVMETHOD(device_suspend, bus_generic_suspend),
744         DEVMETHOD(device_resume, bus_generic_resume),
745
746         /** Bus interface */
747         DEVMETHOD(bus_add_child, bus_generic_add_child),
748         DEVMETHOD(bus_print_child, bus_generic_print_child),
749         DEVMETHOD(bus_read_ivar, vmbus_read_ivar),
750         DEVMETHOD(bus_write_ivar, vmbus_write_ivar),
751         DEVMETHOD(bus_child_pnpinfo_str, vmbus_child_pnpinfo_str),
752
753         { 0, 0 } };
754
755 static char driver_name[] = "vmbus";
756 static driver_t vmbus_driver = { driver_name, vmbus_methods,0, };
757
758
759 devclass_t vmbus_devclass;
760
761 DRIVER_MODULE(vmbus, acpi, vmbus_driver, vmbus_devclass, vmbus_modevent, 0);
762 MODULE_DEPEND(vmbus, acpi, 1, 1, 1);
763 MODULE_VERSION(vmbus, 1);
764
765 /* We want to be started after SMP is initialized */
766 SYSINIT(vmb_init, SI_SUB_SMP + 1, SI_ORDER_FIRST, vmbus_init, NULL);
767