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