2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2006 IronPort Systems Inc. <ambrisko@ironport.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
33 #include <sys/systm.h>
35 #include <sys/condvar.h>
36 #include <sys/eventhandler.h>
37 #include <sys/kernel.h>
38 #include <sys/module.h>
40 #include <sys/selinfo.h>
42 #include <machine/pci_cfgreg.h>
43 #include <dev/pci/pcireg.h>
45 #include <isa/isavar.h>
52 #include <dev/ipmi/ipmivars.h>
56 ipmi_isa_identify(driver_t *driver, device_t parent)
58 struct ipmi_get_info info;
61 if (ipmi_smbios_identify(&info) && info.iface_type != SSIF_MODE &&
62 device_find_child(parent, "ipmi", -1) == NULL) {
64 * XXX: Hack alert. On some broken systems, the IPMI
65 * interface is described via SMBIOS, but the actual
66 * IO resource is in a PCI device BAR, so we have to let
67 * the PCI device attach ipmi instead. In that case don't
68 * create an isa ipmi device. For now we hardcode the list
69 * of bus, device, function tuples.
71 devid = pci_cfgregread(0, 4, 2, PCIR_DEVVENDOR, 4);
72 if (devid != 0xffffffff &&
73 ipmi_pci_match(devid & 0xffff, devid >> 16) != NULL)
75 BUS_ADD_CHILD(parent, 0, "ipmi", -1);
80 ipmi_isa_probe(device_t dev)
84 * Give other drivers precedence. Unfortunately, this doesn't
85 * work if we have an SMBIOS table that duplicates a PCI device
86 * that's later on the bus than the PCI-ISA bridge.
91 /* Skip any PNP devices. */
92 if (isa_get_logicalid(dev) != 0)
95 device_set_desc(dev, "IPMI System Interface");
96 return (BUS_PROBE_DEFAULT);
100 ipmi_hint_identify(device_t dev, struct ipmi_get_info *info)
102 const char *mode, *name;
105 /* We require at least a "mode" hint. */
106 name = device_get_name(dev);
107 unit = device_get_unit(dev);
108 if (resource_string_value(name, unit, "mode", &mode) != 0)
111 /* Set the mode and default I/O resources for each mode. */
112 bzero(info, sizeof(struct ipmi_get_info));
113 if (strcasecmp(mode, "KCS") == 0) {
114 info->iface_type = KCS_MODE;
115 info->address = 0xca2;
118 } else if (strcasecmp(mode, "SMIC") == 0) {
119 info->iface_type = SMIC_MODE;
120 info->address = 0xca9;
123 } else if (strcasecmp(mode, "BT") == 0) {
124 info->iface_type = BT_MODE;
125 info->address = 0xe4;
129 device_printf(dev, "Invalid mode %s\n", mode);
134 * Kill any resources that isahint.c might have setup for us
135 * since it will conflict with how we do resources.
137 for (i = 0; i < 2; i++) {
138 bus_delete_resource(dev, SYS_RES_MEMORY, i);
139 bus_delete_resource(dev, SYS_RES_IOPORT, i);
142 /* Allow the I/O address to be overriden via hints. */
143 if (resource_int_value(name, unit, "port", &val) == 0 && val != 0) {
146 } else if (resource_int_value(name, unit, "maddr", &val) == 0 &&
152 /* Allow the spacing to be overriden. */
153 if (resource_int_value(name, unit, "spacing", &val) == 0) {
165 device_printf(dev, "Invalid register spacing\n");
173 ipmi_isa_attach(device_t dev)
175 struct ipmi_softc *sc = device_get_softc(dev);
176 struct ipmi_get_info info;
178 int count, error, i, type;
181 * Pull info out of the SMBIOS table. If that doesn't work, use
182 * hints to enumerate a device.
184 if (!ipmi_smbios_identify(&info) &&
185 !ipmi_hint_identify(dev, &info))
188 switch (info.iface_type) {
198 device_printf(dev, "BT mode is unsupported\n");
206 device_printf(dev, "%s mode found at %s 0x%jx alignment 0x%x on %s\n",
207 mode, info.io_mode ? "io" : "mem",
208 (uintmax_t)info.address, info.offset,
209 device_get_name(device_get_parent(dev)));
211 type = SYS_RES_IOPORT;
213 type = SYS_RES_MEMORY;
215 sc->ipmi_io_type = type;
216 sc->ipmi_io_spacing = info.offset;
217 if (info.offset == 1) {
219 sc->ipmi_io_res[0] = bus_alloc_resource(dev, type,
220 &sc->ipmi_io_rid, info.address, info.address + count - 1,
222 if (sc->ipmi_io_res[0] == NULL) {
223 device_printf(dev, "couldn't configure I/O resource\n");
227 for (i = 0; i < count; i++) {
229 sc->ipmi_io_res[i] = bus_alloc_resource(dev, type,
230 &sc->ipmi_io_rid, info.address + i * info.offset,
231 info.address + i * info.offset, 1, RF_ACTIVE);
232 if (sc->ipmi_io_res[i] == NULL) {
234 "couldn't configure I/O resource\n");
244 sc->ipmi_irq_rid = 0;
245 sc->ipmi_irq_res = bus_alloc_resource(dev, SYS_RES_IRQ,
246 &sc->ipmi_irq_rid, info.irq, info.irq, 1,
247 RF_SHAREABLE | RF_ACTIVE);
250 switch (info.iface_type) {
252 error = ipmi_kcs_attach(sc);
257 error = ipmi_smic_attach(sc);
263 error = ipmi_attach(dev);
269 ipmi_release_resources(dev);
273 static device_method_t ipmi_methods[] = {
274 /* Device interface */
275 DEVMETHOD(device_identify, ipmi_isa_identify),
276 DEVMETHOD(device_probe, ipmi_isa_probe),
277 DEVMETHOD(device_attach, ipmi_isa_attach),
278 DEVMETHOD(device_detach, ipmi_detach),
282 static driver_t ipmi_isa_driver = {
285 sizeof(struct ipmi_softc),
288 DRIVER_MODULE(ipmi_isa, isa, ipmi_isa_driver, ipmi_devclass, 0, 0);