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 <machine/pci_cfgreg.h>
41 #include <dev/pci/pcireg.h>
43 #include <isa/isavar.h>
50 #include <dev/ipmi/ipmivars.h>
54 ipmi_isa_identify(driver_t *driver, device_t parent)
56 struct ipmi_get_info info;
59 if (ipmi_smbios_identify(&info) && info.iface_type != SSIF_MODE &&
60 device_find_child(parent, "ipmi", -1) == NULL) {
62 * XXX: Hack alert. On some broken systems, the IPMI
63 * interface is described via SMBIOS, but the actual
64 * IO resource is in a PCI device BAR, so we have to let
65 * the PCI device attach ipmi instead. In that case don't
66 * create an isa ipmi device. For now we hardcode the list
67 * of bus, device, function tuples.
69 devid = pci_cfgregread(0, 4, 2, PCIR_DEVVENDOR, 4);
70 if (devid != 0xffffffff &&
71 ipmi_pci_match(devid & 0xffff, devid >> 16) != NULL)
73 BUS_ADD_CHILD(parent, 0, "ipmi", -1);
78 ipmi_isa_probe(device_t dev)
82 * Give other drivers precedence. Unfortunately, this doesn't
83 * work if we have an SMBIOS table that duplicates a PCI device
84 * that's later on the bus than the PCI-ISA bridge.
89 /* Skip any PNP devices. */
90 if (isa_get_logicalid(dev) != 0)
93 device_set_desc(dev, "IPMI System Interface");
94 return (BUS_PROBE_DEFAULT);
98 ipmi_hint_identify(device_t dev, struct ipmi_get_info *info)
100 const char *mode, *name;
103 /* We require at least a "mode" hint. */
104 name = device_get_name(dev);
105 unit = device_get_unit(dev);
106 if (resource_string_value(name, unit, "mode", &mode) != 0)
109 /* Set the mode and default I/O resources for each mode. */
110 bzero(info, sizeof(struct ipmi_get_info));
111 if (strcasecmp(mode, "KCS") == 0) {
112 info->iface_type = KCS_MODE;
113 info->address = 0xca2;
116 } else if (strcasecmp(mode, "SMIC") == 0) {
117 info->iface_type = SMIC_MODE;
118 info->address = 0xca9;
121 } else if (strcasecmp(mode, "BT") == 0) {
122 info->iface_type = BT_MODE;
123 info->address = 0xe4;
127 device_printf(dev, "Invalid mode %s\n", mode);
132 * Kill any resources that isahint.c might have setup for us
133 * since it will conflict with how we do resources.
135 for (i = 0; i < 2; i++) {
136 bus_delete_resource(dev, SYS_RES_MEMORY, i);
137 bus_delete_resource(dev, SYS_RES_IOPORT, i);
140 /* Allow the I/O address to be overriden via hints. */
141 if (resource_int_value(name, unit, "port", &val) == 0 && val != 0) {
144 } else if (resource_int_value(name, unit, "maddr", &val) == 0 &&
150 /* Allow the spacing to be overriden. */
151 if (resource_int_value(name, unit, "spacing", &val) == 0) {
163 device_printf(dev, "Invalid register spacing\n");
171 ipmi_isa_attach(device_t dev)
173 struct ipmi_softc *sc = device_get_softc(dev);
174 struct ipmi_get_info info;
176 int count, error, i, type;
179 * Pull info out of the SMBIOS table. If that doesn't work, use
180 * hints to enumerate a device.
182 if (!ipmi_smbios_identify(&info) &&
183 !ipmi_hint_identify(dev, &info))
186 switch (info.iface_type) {
196 device_printf(dev, "BT mode is unsupported\n");
204 device_printf(dev, "%s mode found at %s 0x%jx alignment 0x%x on %s\n",
205 mode, info.io_mode ? "io" : "mem",
206 (uintmax_t)info.address, info.offset,
207 device_get_name(device_get_parent(dev)));
209 type = SYS_RES_IOPORT;
211 type = SYS_RES_MEMORY;
213 sc->ipmi_io_type = type;
214 sc->ipmi_io_spacing = info.offset;
215 if (info.offset == 1) {
217 sc->ipmi_io_res[0] = bus_alloc_resource(dev, type,
218 &sc->ipmi_io_rid, info.address, info.address + count - 1,
220 if (sc->ipmi_io_res[0] == NULL) {
221 device_printf(dev, "couldn't configure I/O resource\n");
225 for (i = 0; i < count; i++) {
227 sc->ipmi_io_res[i] = bus_alloc_resource(dev, type,
228 &sc->ipmi_io_rid, info.address + i * info.offset,
229 info.address + i * info.offset, 1, RF_ACTIVE);
230 if (sc->ipmi_io_res[i] == NULL) {
232 "couldn't configure I/O resource\n");
242 sc->ipmi_irq_rid = 0;
243 sc->ipmi_irq_res = bus_alloc_resource(dev, SYS_RES_IRQ,
244 &sc->ipmi_irq_rid, info.irq, info.irq, 1,
245 RF_SHAREABLE | RF_ACTIVE);
248 switch (info.iface_type) {
250 error = ipmi_kcs_attach(sc);
255 error = ipmi_smic_attach(sc);
261 error = ipmi_attach(dev);
267 ipmi_release_resources(dev);
271 static device_method_t ipmi_methods[] = {
272 /* Device interface */
273 DEVMETHOD(device_identify, ipmi_isa_identify),
274 DEVMETHOD(device_probe, ipmi_isa_probe),
275 DEVMETHOD(device_attach, ipmi_isa_attach),
276 DEVMETHOD(device_detach, ipmi_detach),
280 static driver_t ipmi_isa_driver = {
283 sizeof(struct ipmi_softc),
286 DRIVER_MODULE(ipmi_isa, isa, ipmi_isa_driver, ipmi_devclass, 0, 0);