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