xen_mainbus.c revision 1.6 1 /* $NetBSD: xen_mainbus.c,v 1.6 2019/02/14 08:18:26 cherry Exp $ */
2 /* NetBSD: mainbus.c,v 1.19 2017/05/23 08:54:39 nonaka Exp */
3 /* NetBSD: mainbus.c,v 1.53 2003/10/27 14:11:47 junyoung Exp */
4
5 /*
6 * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following 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 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Christopher G. Demetriou
19 * for the NetBSD Project.
20 * 4. The name of the author may not be used to endorse or promote products
21 * derived from this software without specific prior written permission
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35 #include <sys/cdefs.h>
36 __KERNEL_RCSID(0, "$NetBSD: xen_mainbus.c,v 1.6 2019/02/14 08:18:26 cherry Exp $");
37
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/device.h>
41
42 #include <sys/bus.h>
43
44 #include "hypervisor.h"
45 #include "pci.h"
46
47 #include "opt_xen.h"
48 #include "opt_mpbios.h"
49 #include "opt_pcifixup.h"
50
51 #include "acpica.h"
52 #include "ioapic.h"
53
54 #include "ipmi.h"
55
56 #include <machine/cpuvar.h>
57 #include <machine/i82093var.h>
58
59 #include <xen/xen.h>
60 #include <xen/hypervisor.h>
61
62 #if NIPMI > 0
63 #include <x86/ipmivar.h>
64 #endif
65
66 #if NPCI > 0
67 #include <dev/pci/pcivar.h>
68 #if NACPICA > 0
69 #include <dev/acpi/acpivar.h>
70 #include <xen/mpacpi.h>
71 #endif /* NACPICA > 0 */
72 #ifdef MPBIOS
73 #include <machine/mpbiosvar.h>
74 #endif /* MPBIOS */
75 #ifdef PCI_BUS_FIXUP
76 #include <arch/x86/pci/pci_bus_fixup.h>
77 #ifdef PCI_ADDR_FIXUP
78 #include <arch/x86/pci/pci_addr_fixup.h>
79 #endif
80 #endif
81
82 #if defined(XENPV) && (defined(MPBIOS) || NACPICA > 0)
83 struct mp_bus *mp_busses;
84 int mp_nbus;
85 struct mp_intr_map *mp_intrs;
86 int mp_nintr;
87
88 int mp_isa_bus = -1; /* XXX */
89 int mp_eisa_bus = -1; /* XXX */
90
91 #ifdef MPVERBOSE
92 int mp_verbose = 1;
93 #else /* MPVERBOSE */
94 int mp_verbose = 0;
95 #endif /* MPVERBOSE */
96 #endif /* defined(MPBIOS) || NACPICA > 0 */
97 #endif /* NPCI > 0 */
98
99 extern bool acpi_present;
100 extern bool mpacpi_active;
101
102 int xen_mainbus_match(device_t, cfdata_t, void *);
103 void xen_mainbus_attach(device_t, device_t, void *);
104 int xen_mainbus_print(void *, const char *);
105
106 union xen_mainbus_attach_args {
107 const char *mba_busname; /* first elem of all */
108 struct cpu_attach_args mba_caa;
109 #if NHYPERVISOR > 0
110 struct hypervisor_attach_args mba_haa;
111 #endif
112 #if NIPMI > 0
113 struct ipmi_attach_args mba_ipmi;
114 #endif
115 };
116
117 /*
118 * Probe for the mainbus; always succeeds.
119 */
120 int
121 xen_mainbus_match(device_t parent, cfdata_t match, void *aux)
122 {
123
124 return 1;
125 }
126
127 /*
128 * Attach the mainbus.
129 */
130 void
131 xen_mainbus_attach(device_t parent, device_t self, void *aux)
132 {
133 #if NIPMI > 0 || NHYPERVISOR > 0
134 union xen_mainbus_attach_args mba;
135 #endif
136
137 #if NIPMI > 0
138 memset(&mba.mba_ipmi, 0, sizeof(mba.mba_ipmi));
139 mba.mba_ipmi.iaa_iot = x86_bus_space_io;
140 mba.mba_ipmi.iaa_memt = x86_bus_space_mem;
141 if (ipmi_probe(&mba.mba_ipmi))
142 config_found_ia(self, "ipmibus", &mba.mba_ipmi, 0);
143 #endif
144
145 #if NHYPERVISOR > 0
146 mba.mba_haa.haa_busname = "hypervisor";
147 config_found_ia(self, "hypervisorbus", &mba.mba_haa, xen_mainbus_print);
148 #endif
149
150 /* save/restore for Xen */
151 if (!pmf_device_register(self, NULL, NULL))
152 aprint_error_dev(self, "couldn't establish power handler\n");
153 }
154
155 int
156 xen_mainbus_print(void *aux, const char *pnp)
157 {
158 union xen_mainbus_attach_args *mba = aux;
159
160 if (pnp)
161 aprint_normal("%s at %s", mba->mba_busname, pnp);
162 return UNCONF;
163 }
164