xref: /illumos-gate/usr/src/uts/common/xen/io/xpv_autoconfig.c (revision e86372a01d2d16a5dd4a64e144ed978ba17fe7dd)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #include <sys/types.h>
28 #include <sys/hypervisor.h>
29 #include <sys/sunndi.h>
30 #include <sys/sunddi.h>
31 #include <sys/ddi_subrdefs.h>
32 #include <sys/bootconf.h>
33 #include <sys/psw.h>
34 #include <sys/modctl.h>
35 #include <sys/errno.h>
36 #include <sys/reboot.h>
37 #include <sys/hypervisor.h>
38 #include <xen/sys/xenbus_comms.h>
39 #include <xen/sys/xenbus_impl.h>
40 #include <xen/sys/xendev.h>
41 
42 extern int xen_boot_debug;
43 
44 /*
45  * Internal structures and functions
46  */
47 int xendev_nounload = 0;
48 void xendev_enumerate(int);
49 
50 /*
51  * Interface routines
52  */
53 
54 static struct modlmisc modlmisc = {
55 	&mod_miscops, "virtual device probe"
56 };
57 
58 static struct modlinkage modlinkage = {
59 	MODREV_1, (void *)&modlmisc, NULL
60 };
61 
62 int
63 _init(void)
64 {
65 	int	err;
66 
67 	if ((err = mod_install(&modlinkage)) != 0)
68 		return (err);
69 
70 	impl_bus_add_probe(xendev_enumerate);
71 	return (0);
72 }
73 
74 int
75 _fini(void)
76 {
77 	int	err;
78 
79 	if (xendev_nounload)
80 		return (EBUSY);
81 
82 	if ((err = mod_remove(&modlinkage)) != 0)
83 		return (err);
84 
85 	impl_bus_delete_probe(xendev_enumerate);
86 	return (0);
87 }
88 
89 int
90 _info(struct modinfo *modinfop)
91 {
92 	return (mod_info(&modlinkage, modinfop));
93 }
94 
95 
96 /*
97  * This functions is invoked twice, first time with reprogram=0 to
98  * set up the xpvd portion of the device tree. The second time is
99  * ignored.
100  */
101 void
102 xendev_enumerate(int reprogram)
103 {
104 	dev_info_t *dip;
105 
106 	if (reprogram != 0)
107 		return;
108 
109 	ndi_devi_alloc_sleep(ddi_root_node(), "xpvd",
110 	    (pnode_t)DEVI_SID_NODEID, &dip);
111 
112 	(void) ndi_devi_bind_driver(dip, 0);
113 
114 	/*
115 	 * Too early to enumerate split device drivers in domU
116 	 * since we need to create taskq thread during enumeration.
117 	 * So, we only enumerate softdevs and console here.
118 	 */
119 	xendev_enum_all(dip, B_TRUE);
120 }
121