2 * Copyright (c) 2006 IronPort Systems Inc. <ambrisko@ironport.com>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/param.h>
31 #include <sys/systm.h>
33 #include <sys/condvar.h>
34 #include <sys/eventhandler.h>
35 #include <sys/kernel.h>
36 #include <sys/module.h>
38 #include <sys/selinfo.h>
40 #include <dev/pci/pcireg.h>
41 #include <dev/pci/pcivar.h>
46 #include <dev/ipmi/ipmivars.h>
49 static int ipmi_pci_probe(device_t dev);
50 static int ipmi_pci_attach(device_t dev);
52 static struct ipmi_ident
57 } ipmi_identifiers[] = {
58 {0x1028, 0x000d, "Dell PE2650 SMIC interface"},
63 ipmi_pci_match(uint16_t vendor, uint16_t device)
67 for (m = ipmi_identifiers; m->vendor != 0; m++)
68 if (m->vendor == vendor && m->device == device)
74 ipmi_pci_probe(device_t dev)
81 desc = ipmi_pci_match(pci_get_vendor(dev), pci_get_device(dev));
83 device_set_desc(dev, desc);
84 return (BUS_PROBE_DEFAULT);
91 ipmi_pci_attach(device_t dev)
93 struct ipmi_softc *sc = device_get_softc(dev);
94 struct ipmi_get_info info;
98 /* Look for an IPMI entry in the SMBIOS table. */
99 if (!ipmi_smbios_identify(&info))
104 switch (info.iface_type) {
112 device_printf(dev, "BT mode is unsupported\n");
115 device_printf(dev, "No IPMI interface found\n");
119 device_printf(dev, "%s mode found at %s 0x%jx alignment 0x%x on %s\n",
120 mode, info.io_mode ? "io" : "mem",
121 (uintmax_t)info.address, info.offset,
122 device_get_name(device_get_parent(dev)));
124 type = SYS_RES_IOPORT;
126 type = SYS_RES_MEMORY;
128 sc->ipmi_io_rid = PCIR_BAR(0);
129 sc->ipmi_io_res[0] = bus_alloc_resource_any(dev, type,
130 &sc->ipmi_io_rid, RF_ACTIVE);
131 sc->ipmi_io_type = type;
132 sc->ipmi_io_spacing = info.offset;
134 if (sc->ipmi_io_res[0] == NULL) {
135 device_printf(dev, "couldn't configure pci io res\n");
139 sc->ipmi_irq_rid = 0;
140 sc->ipmi_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ,
141 &sc->ipmi_irq_rid, RF_SHAREABLE | RF_ACTIVE);
143 switch (info.iface_type) {
145 error = ipmi_kcs_attach(sc);
150 error = ipmi_smic_attach(sc);
155 error = ipmi_attach(dev);
161 ipmi_release_resources(dev);
165 static device_method_t ipmi_methods[] = {
166 /* Device interface */
167 DEVMETHOD(device_probe, ipmi_pci_probe),
168 DEVMETHOD(device_attach, ipmi_pci_attach),
169 DEVMETHOD(device_detach, ipmi_detach),
173 static driver_t ipmi_pci_driver = {
176 sizeof(struct ipmi_softc)
179 DRIVER_MODULE(ipmi_pci, pci, ipmi_pci_driver, ipmi_devclass, 0, 0);
181 /* Native IPMI on PCI driver. */
184 ipmi2_pci_probe(device_t dev)
187 if (pci_get_class(dev) == PCIC_SERIALBUS &&
188 pci_get_subclass(dev) == PCIS_SERIALBUS_IPMI) {
189 device_set_desc(dev, "IPMI System Interface");
190 return (BUS_PROBE_GENERIC);
197 ipmi2_pci_attach(device_t dev)
199 struct ipmi_softc *sc;
200 int error, iface, type;
202 sc = device_get_softc(dev);
205 /* Interface is determined by progif. */
206 switch (pci_get_progif(dev)) {
207 case PCIP_SERIALBUS_IPMI_SMIC:
210 case PCIP_SERIALBUS_IPMI_KCS:
213 case PCIP_SERIALBUS_IPMI_BT:
215 device_printf(dev, "BT interface unsupported\n");
218 device_printf(dev, "Unsupported interface: %d\n",
219 pci_get_progif(dev));
223 /* Check the BAR to determine our resource type. */
224 sc->ipmi_io_rid = PCIR_BAR(0);
225 if (PCI_BAR_IO(pci_read_config(dev, PCIR_BAR(0), 4)))
226 type = SYS_RES_IOPORT;
228 type = SYS_RES_MEMORY;
229 sc->ipmi_io_type = type;
230 sc->ipmi_io_spacing = 1;
231 sc->ipmi_io_res[0] = bus_alloc_resource_any(dev, type,
232 &sc->ipmi_io_rid, RF_ACTIVE);
233 if (sc->ipmi_io_res[0] == NULL) {
234 device_printf(dev, "couldn't map ports/memory\n");
238 sc->ipmi_irq_rid = 0;
239 sc->ipmi_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ,
240 &sc->ipmi_irq_rid, RF_SHAREABLE | RF_ACTIVE);
244 device_printf(dev, "using KSC interface\n");
247 * We have to examine the resource directly to determine the
250 if (!ipmi_kcs_probe_align(sc)) {
251 device_printf(dev, "Unable to determine alignment\n");
256 error = ipmi_kcs_attach(sc);
261 device_printf(dev, "using SMIC interface\n");
263 error = ipmi_smic_attach(sc);
268 error = ipmi_attach(dev);
274 ipmi_release_resources(dev);
278 static device_method_t ipmi2_methods[] = {
279 /* Device interface */
280 DEVMETHOD(device_probe, ipmi2_pci_probe),
281 DEVMETHOD(device_attach, ipmi2_pci_attach),
282 DEVMETHOD(device_detach, ipmi_detach),
286 static driver_t ipmi2_pci_driver = {
289 sizeof(struct ipmi_softc)
292 DRIVER_MODULE(ipmi2_pci, pci, ipmi2_pci_driver, ipmi_devclass, 0, 0);