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
26 * $FreeBSD: head/sys/dev/ipmi/ipmi_isa.c 253813 2013-07-30 18:54:24Z sbruno $
29 #include <sys/param.h>
30 #include <sys/systm.h>
32 #include <sys/condvar.h>
33 #include <sys/eventhandler.h>
34 #include <sys/kernel.h>
35 #include <sys/module.h>
39 #include <bus/pci/pci_cfgreg.h>
40 #include <bus/pci/pcireg.h>
42 #include <bus/isa/isavar.h>
49 #include <dev/misc/ipmi/ipmivars.h>
53 ipmi_isa_identify(driver_t *driver, device_t parent)
55 struct ipmi_get_info info;
58 if (ipmi_smbios_identify(&info) && info.iface_type != SSIF_MODE &&
59 device_find_child(parent, "ipmi", -1) == NULL) {
61 * XXX: Hack alert. On some broken systems, the IPMI
62 * interface is described via SMBIOS, but the actual
63 * IO resource is in a PCI device BAR, so we have to let
64 * the PCI device attach ipmi instead. In that case don't
65 * create an isa ipmi device. For now we hardcode the list
66 * of bus, device, function tuples.
68 devid = pci_cfgregread(0, 4, 2, PCIR_DEVVENDOR, 4);
69 if (devid != 0xffffffff &&
70 ipmi_pci_match(devid & 0xffff, devid >> 16) != NULL)
72 BUS_ADD_CHILD(parent, parent, 0, "ipmi", -1);
77 ipmi_isa_probe(device_t dev)
81 * Give other drivers precedence. Unfortunately, this doesn't
82 * work if we have an SMBIOS table that duplicates a PCI device
83 * that's later on the bus than the PCI-ISA bridge.
88 /* Skip any PNP devices. */
89 if (isa_get_logicalid(dev) != 0)
92 device_set_desc(dev, "IPMI System Interface");
93 return (BUS_PROBE_DEFAULT);
97 ipmi_hint_identify(device_t dev, struct ipmi_get_info *info)
99 const char *mode, *name;
102 /* We require at least a "mode" hint. */
103 name = device_get_name(dev);
104 unit = device_get_unit(dev);
105 if (resource_string_value(name, unit, "mode", &mode) != 0)
108 /* Set the mode and default I/O resources for each mode. */
109 bzero(info, sizeof(struct ipmi_get_info));
110 if (strcasecmp(mode, "KCS") == 0) {
111 info->iface_type = KCS_MODE;
112 info->address = 0xca2;
115 } else if (strcasecmp(mode, "SMIC") == 0) {
116 info->iface_type = SMIC_MODE;
117 info->address = 0xca9;
120 } else if (strcasecmp(mode, "BT") == 0) {
121 info->iface_type = BT_MODE;
122 info->address = 0xe4;
126 device_printf(dev, "Invalid mode %s\n", mode);
131 * Kill any resources that isahint.c might have setup for us
132 * since it will conflict with how we do resources.
134 for (i = 0; i < 2; i++) {
135 bus_delete_resource(dev, SYS_RES_MEMORY, i);
136 bus_delete_resource(dev, SYS_RES_IOPORT, i);
139 /* Allow the I/O address to be overridden via hints. */
140 if (resource_int_value(name, unit, "port", &val) == 0 && val != 0) {
143 } else if (resource_int_value(name, unit, "maddr", &val) == 0 &&
149 /* Allow the spacing to be overridden. */
150 if (resource_int_value(name, unit, "spacing", &val) == 0) {
162 device_printf(dev, "Invalid register spacing\n");
170 ipmi_isa_attach(device_t dev)
172 struct ipmi_softc *sc = device_get_softc(dev);
173 struct ipmi_get_info info;
175 int count, error, i, type;
178 * Pull info out of the SMBIOS table. If that doesn't work, use
179 * hints to enumerate a device.
181 if (!ipmi_smbios_identify(&info) &&
182 !ipmi_hint_identify(dev, &info))
185 switch (info.iface_type) {
195 device_printf(dev, "BT mode is unsupported\n");
203 device_printf(dev, "%s mode found at %s 0x%jx alignment 0x%x on %s\n",
204 mode, info.io_mode ? "io" : "mem",
205 (uintmax_t)info.address, info.offset,
206 device_get_name(device_get_parent(dev)));
208 type = SYS_RES_IOPORT;
210 type = SYS_RES_MEMORY;
212 sc->ipmi_io_type = type;
213 sc->ipmi_io_spacing = info.offset;
214 if (info.offset == 1) {
216 sc->ipmi_io_res[0] = bus_alloc_resource(dev, type,
217 &sc->ipmi_io_rid, info.address, info.address + count - 1,
219 if (sc->ipmi_io_res[0] == NULL) {
220 device_printf(dev, "couldn't configure I/O resource\n");
224 for (i = 0; i < count; i++) {
226 sc->ipmi_io_res[i] = bus_alloc_resource(dev, type,
227 &sc->ipmi_io_rid, info.address + i * info.offset,
228 info.address + i * info.offset, 1, RF_ACTIVE);
229 if (sc->ipmi_io_res[i] == NULL) {
231 "couldn't configure I/O resource\n");
241 sc->ipmi_irq_rid = 0;
242 sc->ipmi_irq_res = bus_alloc_resource(dev, SYS_RES_IRQ,
243 &sc->ipmi_irq_rid, info.irq, info.irq, 1,
244 RF_SHAREABLE | RF_ACTIVE);
247 switch (info.iface_type) {
249 error = ipmi_kcs_attach(sc);
254 error = ipmi_smic_attach(sc);
260 error = ipmi_attach(dev);
266 ipmi_release_resources(dev);
270 static device_method_t ipmi_methods[] = {
271 /* Device interface */
272 DEVMETHOD(device_identify, ipmi_isa_identify),
273 DEVMETHOD(device_probe, ipmi_isa_probe),
274 DEVMETHOD(device_attach, ipmi_isa_attach),
275 DEVMETHOD(device_detach, ipmi_detach),
279 static driver_t ipmi_isa_driver = {
282 sizeof(struct ipmi_softc),
285 DRIVER_MODULE(ipmi_isa, isa, ipmi_isa_driver, ipmi_devclass, NULL, NULL);