1843e1988Sjohnlev /*
2843e1988Sjohnlev * CDDL HEADER START
3843e1988Sjohnlev *
4843e1988Sjohnlev * The contents of this file are subject to the terms of the
5843e1988Sjohnlev * Common Development and Distribution License (the "License").
6843e1988Sjohnlev * You may not use this file except in compliance with the License.
7843e1988Sjohnlev *
8843e1988Sjohnlev * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9843e1988Sjohnlev * or http://www.opensolaris.org/os/licensing.
10843e1988Sjohnlev * See the License for the specific language governing permissions
11843e1988Sjohnlev * and limitations under the License.
12843e1988Sjohnlev *
13843e1988Sjohnlev * When distributing Covered Code, include this CDDL HEADER in each
14843e1988Sjohnlev * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15843e1988Sjohnlev * If applicable, add the following below this CDDL HEADER, with the
16843e1988Sjohnlev * fields enclosed by brackets "[]" replaced with your own identifying
17843e1988Sjohnlev * information: Portions Copyright [yyyy] [name of copyright owner]
18843e1988Sjohnlev *
19843e1988Sjohnlev * CDDL HEADER END
20843e1988Sjohnlev */
21843e1988Sjohnlev
22843e1988Sjohnlev /*
23*39b361b2SRichard Bean * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24843e1988Sjohnlev * Use is subject to license terms.
25843e1988Sjohnlev */
26843e1988Sjohnlev
27843e1988Sjohnlev #include <sys/types.h>
28843e1988Sjohnlev #include <sys/hypervisor.h>
29843e1988Sjohnlev #include <sys/sunndi.h>
30843e1988Sjohnlev #include <sys/sunddi.h>
31843e1988Sjohnlev #include <sys/ddi_subrdefs.h>
32843e1988Sjohnlev #include <sys/bootconf.h>
33843e1988Sjohnlev #include <sys/psw.h>
34843e1988Sjohnlev #include <sys/modctl.h>
35843e1988Sjohnlev #include <sys/errno.h>
36843e1988Sjohnlev #include <sys/reboot.h>
37843e1988Sjohnlev #include <sys/hypervisor.h>
38843e1988Sjohnlev #include <xen/sys/xenbus_comms.h>
39843e1988Sjohnlev #include <xen/sys/xenbus_impl.h>
40843e1988Sjohnlev #include <xen/sys/xendev.h>
41843e1988Sjohnlev
42843e1988Sjohnlev extern int xen_boot_debug;
43843e1988Sjohnlev
44843e1988Sjohnlev /*
45843e1988Sjohnlev * Internal structures and functions
46843e1988Sjohnlev */
47843e1988Sjohnlev int xendev_nounload = 0;
48843e1988Sjohnlev void xendev_enumerate(int);
49843e1988Sjohnlev
50843e1988Sjohnlev /*
51843e1988Sjohnlev * Interface routines
52843e1988Sjohnlev */
53843e1988Sjohnlev
54843e1988Sjohnlev static struct modlmisc modlmisc = {
55*39b361b2SRichard Bean &mod_miscops, "virtual device probe"
56843e1988Sjohnlev };
57843e1988Sjohnlev
58843e1988Sjohnlev static struct modlinkage modlinkage = {
59843e1988Sjohnlev MODREV_1, (void *)&modlmisc, NULL
60843e1988Sjohnlev };
61843e1988Sjohnlev
62843e1988Sjohnlev int
_init(void)63843e1988Sjohnlev _init(void)
64843e1988Sjohnlev {
65843e1988Sjohnlev int err;
66843e1988Sjohnlev
67843e1988Sjohnlev if ((err = mod_install(&modlinkage)) != 0)
68843e1988Sjohnlev return (err);
69843e1988Sjohnlev
70843e1988Sjohnlev impl_bus_add_probe(xendev_enumerate);
71843e1988Sjohnlev return (0);
72843e1988Sjohnlev }
73843e1988Sjohnlev
74843e1988Sjohnlev int
_fini(void)75843e1988Sjohnlev _fini(void)
76843e1988Sjohnlev {
77843e1988Sjohnlev int err;
78843e1988Sjohnlev
79843e1988Sjohnlev if (xendev_nounload)
80843e1988Sjohnlev return (EBUSY);
81843e1988Sjohnlev
82843e1988Sjohnlev if ((err = mod_remove(&modlinkage)) != 0)
83843e1988Sjohnlev return (err);
84843e1988Sjohnlev
85843e1988Sjohnlev impl_bus_delete_probe(xendev_enumerate);
86843e1988Sjohnlev return (0);
87843e1988Sjohnlev }
88843e1988Sjohnlev
89843e1988Sjohnlev int
_info(struct modinfo * modinfop)90843e1988Sjohnlev _info(struct modinfo *modinfop)
91843e1988Sjohnlev {
92843e1988Sjohnlev return (mod_info(&modlinkage, modinfop));
93843e1988Sjohnlev }
94843e1988Sjohnlev
95843e1988Sjohnlev
96843e1988Sjohnlev /*
97843e1988Sjohnlev * This functions is invoked twice, first time with reprogram=0 to
98843e1988Sjohnlev * set up the xpvd portion of the device tree. The second time is
99843e1988Sjohnlev * ignored.
100843e1988Sjohnlev */
101843e1988Sjohnlev void
xendev_enumerate(int reprogram)102843e1988Sjohnlev xendev_enumerate(int reprogram)
103843e1988Sjohnlev {
104843e1988Sjohnlev dev_info_t *dip;
105843e1988Sjohnlev
106843e1988Sjohnlev if (reprogram != 0)
107843e1988Sjohnlev return;
108843e1988Sjohnlev
109843e1988Sjohnlev ndi_devi_alloc_sleep(ddi_root_node(), "xpvd",
110843e1988Sjohnlev (pnode_t)DEVI_SID_NODEID, &dip);
111843e1988Sjohnlev
112843e1988Sjohnlev (void) ndi_devi_bind_driver(dip, 0);
113843e1988Sjohnlev
114843e1988Sjohnlev /*
115843e1988Sjohnlev * Too early to enumerate split device drivers in domU
116843e1988Sjohnlev * since we need to create taskq thread during enumeration.
117843e1988Sjohnlev * So, we only enumerate softdevs and console here.
118843e1988Sjohnlev */
119843e1988Sjohnlev xendev_enum_all(dip, B_TRUE);
120843e1988Sjohnlev }
121