diff --git a/sys/dev/ipmi/ipmi_isa.c b/sys/dev/ipmi/ipmi_isa.c index 2831b53e4586..cdff305b07ec 100644 --- a/sys/dev/ipmi/ipmi_isa.c +++ b/sys/dev/ipmi/ipmi_isa.c @@ -1,289 +1,288 @@ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2006 IronPort Systems Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include #ifdef LOCAL_MODULE #include #include #else #include #include #endif static void ipmi_isa_identify(driver_t *driver, device_t parent) { struct ipmi_get_info info; uint32_t devid; if (ipmi_smbios_identify(&info) && info.iface_type != SSIF_MODE && device_find_child(parent, "ipmi", -1) == NULL) { /* * XXX: Hack alert. On some broken systems, the IPMI * interface is described via SMBIOS, but the actual * IO resource is in a PCI device BAR, so we have to let * the PCI device attach ipmi instead. In that case don't * create an isa ipmi device. For now we hardcode the list * of bus, device, function tuples. */ devid = pci_cfgregread(0, 4, 2, PCIR_DEVVENDOR, 4); if (devid != 0xffffffff && ipmi_pci_match(devid & 0xffff, devid >> 16) != NULL) return; BUS_ADD_CHILD(parent, 0, "ipmi", -1); } } static int ipmi_isa_probe(device_t dev) { /* * Give other drivers precedence. Unfortunately, this doesn't * work if we have an SMBIOS table that duplicates a PCI device * that's later on the bus than the PCI-ISA bridge. */ if (ipmi_attached) return (ENXIO); /* Skip any PNP devices. */ if (isa_get_logicalid(dev) != 0) return (ENXIO); device_set_desc(dev, "IPMI System Interface"); return (BUS_PROBE_DEFAULT); } static int ipmi_hint_identify(device_t dev, struct ipmi_get_info *info) { const char *mode, *name; int i, unit, val; /* We require at least a "mode" hint. */ name = device_get_name(dev); unit = device_get_unit(dev); if (resource_string_value(name, unit, "mode", &mode) != 0) return (0); /* Set the mode and default I/O resources for each mode. */ bzero(info, sizeof(struct ipmi_get_info)); if (strcasecmp(mode, "KCS") == 0) { info->iface_type = KCS_MODE; info->address = 0xca2; info->io_mode = 1; info->offset = 1; } else if (strcasecmp(mode, "SMIC") == 0) { info->iface_type = SMIC_MODE; info->address = 0xca9; info->io_mode = 1; info->offset = 1; } else if (strcasecmp(mode, "BT") == 0) { info->iface_type = BT_MODE; info->address = 0xe4; info->io_mode = 1; info->offset = 1; } else { device_printf(dev, "Invalid mode %s\n", mode); return (0); } /* * Kill any resources that isahint.c might have setup for us * since it will conflict with how we do resources. */ for (i = 0; i < 2; i++) { bus_delete_resource(dev, SYS_RES_MEMORY, i); bus_delete_resource(dev, SYS_RES_IOPORT, i); } /* Allow the I/O address to be overriden via hints. */ if (resource_int_value(name, unit, "port", &val) == 0 && val != 0) { info->address = val; info->io_mode = 1; } else if (resource_int_value(name, unit, "maddr", &val) == 0 && val != 0) { info->address = val; info->io_mode = 0; } /* Allow the spacing to be overriden. */ if (resource_int_value(name, unit, "spacing", &val) == 0) { switch (val) { case 8: info->offset = 1; break; case 16: info->offset = 2; break; case 32: info->offset = 4; break; default: device_printf(dev, "Invalid register spacing\n"); return (0); } } return (1); } static int ipmi_isa_attach(device_t dev) { struct ipmi_softc *sc = device_get_softc(dev); struct ipmi_get_info info; const char *mode; int count, error, i, type; /* * Pull info out of the SMBIOS table. If that doesn't work, use * hints to enumerate a device. */ if (!ipmi_smbios_identify(&info) && !ipmi_hint_identify(dev, &info)) return (ENXIO); switch (info.iface_type) { case KCS_MODE: count = 2; mode = "KCS"; break; case SMIC_MODE: count = 3; mode = "SMIC"; break; case BT_MODE: device_printf(dev, "BT mode is unsupported\n"); return (ENXIO); default: return (ENXIO); } error = 0; sc->ipmi_dev = dev; device_printf(dev, "%s mode found at %s 0x%jx alignment 0x%x on %s\n", mode, info.io_mode ? "io" : "mem", (uintmax_t)info.address, info.offset, device_get_name(device_get_parent(dev))); if (info.io_mode) type = SYS_RES_IOPORT; else type = SYS_RES_MEMORY; sc->ipmi_io_type = type; sc->ipmi_io_spacing = info.offset; if (info.offset == 1) { sc->ipmi_io_rid = 0; sc->ipmi_io_res[0] = bus_alloc_resource(dev, type, &sc->ipmi_io_rid, info.address, info.address + count - 1, count, RF_ACTIVE); if (sc->ipmi_io_res[0] == NULL) { device_printf(dev, "couldn't configure I/O resource\n"); return (ENXIO); } } else { for (i = 0; i < count; i++) { sc->ipmi_io_rid = i; sc->ipmi_io_res[i] = bus_alloc_resource(dev, type, &sc->ipmi_io_rid, info.address + i * info.offset, info.address + i * info.offset, 1, RF_ACTIVE); if (sc->ipmi_io_res[i] == NULL) { device_printf(dev, "couldn't configure I/O resource\n"); error = ENXIO; sc->ipmi_io_rid = 0; goto bad; } } sc->ipmi_io_rid = 0; } if (info.irq != 0) { sc->ipmi_irq_rid = 0; sc->ipmi_irq_res = bus_alloc_resource(dev, SYS_RES_IRQ, &sc->ipmi_irq_rid, info.irq, info.irq, 1, RF_SHAREABLE | RF_ACTIVE); } switch (info.iface_type) { case KCS_MODE: error = ipmi_kcs_attach(sc); if (error) goto bad; break; case SMIC_MODE: error = ipmi_smic_attach(sc); if (error) goto bad; break; } error = ipmi_attach(dev); if (error) goto bad; return (0); bad: ipmi_release_resources(dev); return (error); } static device_method_t ipmi_methods[] = { /* Device interface */ DEVMETHOD(device_identify, ipmi_isa_identify), DEVMETHOD(device_probe, ipmi_isa_probe), DEVMETHOD(device_attach, ipmi_isa_attach), DEVMETHOD(device_detach, ipmi_detach), { 0, 0 } }; static driver_t ipmi_isa_driver = { "ipmi", ipmi_methods, sizeof(struct ipmi_softc), }; DRIVER_MODULE(ipmi_isa, isa, ipmi_isa_driver, ipmi_devclass, 0, 0); -MODULE_DEPEND(ipmi_isa, smbios, 1, 1, 1); diff --git a/sys/dev/ipmi/ipmi_pci.c b/sys/dev/ipmi/ipmi_pci.c index 1697a4c31c2a..d4598f9db873 100644 --- a/sys/dev/ipmi/ipmi_pci.c +++ b/sys/dev/ipmi/ipmi_pci.c @@ -1,295 +1,294 @@ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2006 IronPort Systems Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #ifdef LOCAL_MODULE #include #else #include #endif static int ipmi_pci_probe(device_t dev); static int ipmi_pci_attach(device_t dev); static struct ipmi_ident { u_int16_t vendor; u_int16_t device; char *desc; } ipmi_identifiers[] = { {0x1028, 0x000d, "Dell PE2650 SMIC interface"}, {0, 0, 0} }; const char * ipmi_pci_match(uint16_t vendor, uint16_t device) { struct ipmi_ident *m; for (m = ipmi_identifiers; m->vendor != 0; m++) if (m->vendor == vendor && m->device == device) return (m->desc); return (NULL); } static int ipmi_pci_probe(device_t dev) { const char *desc; if (ipmi_attached) return (ENXIO); desc = ipmi_pci_match(pci_get_vendor(dev), pci_get_device(dev)); if (desc != NULL) { device_set_desc(dev, desc); return (BUS_PROBE_DEFAULT); } return (ENXIO); } static int ipmi_pci_attach(device_t dev) { struct ipmi_softc *sc = device_get_softc(dev); struct ipmi_get_info info; const char *mode; int error, type; /* Look for an IPMI entry in the SMBIOS table. */ if (!ipmi_smbios_identify(&info)) return (ENXIO); sc->ipmi_dev = dev; switch (info.iface_type) { case KCS_MODE: mode = "KCS"; break; case SMIC_MODE: mode = "SMIC"; break; case BT_MODE: device_printf(dev, "BT mode is unsupported\n"); return (ENXIO); default: device_printf(dev, "No IPMI interface found\n"); return (ENXIO); } device_printf(dev, "%s mode found at %s 0x%jx alignment 0x%x on %s\n", mode, info.io_mode ? "io" : "mem", (uintmax_t)info.address, info.offset, device_get_name(device_get_parent(dev))); if (info.io_mode) type = SYS_RES_IOPORT; else type = SYS_RES_MEMORY; sc->ipmi_io_rid = PCIR_BAR(0); sc->ipmi_io_res[0] = bus_alloc_resource_any(dev, type, &sc->ipmi_io_rid, RF_ACTIVE); sc->ipmi_io_type = type; sc->ipmi_io_spacing = info.offset; if (sc->ipmi_io_res[0] == NULL) { device_printf(dev, "couldn't configure pci io res\n"); return (ENXIO); } sc->ipmi_irq_rid = 0; sc->ipmi_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->ipmi_irq_rid, RF_SHAREABLE | RF_ACTIVE); switch (info.iface_type) { case KCS_MODE: error = ipmi_kcs_attach(sc); if (error) goto bad; break; case SMIC_MODE: error = ipmi_smic_attach(sc); if (error) goto bad; break; } error = ipmi_attach(dev); if (error) goto bad; return (0); bad: ipmi_release_resources(dev); return (error); } static device_method_t ipmi_methods[] = { /* Device interface */ DEVMETHOD(device_probe, ipmi_pci_probe), DEVMETHOD(device_attach, ipmi_pci_attach), DEVMETHOD(device_detach, ipmi_detach), { 0, 0 } }; static driver_t ipmi_pci_driver = { "ipmi", ipmi_methods, sizeof(struct ipmi_softc) }; DRIVER_MODULE(ipmi_pci, pci, ipmi_pci_driver, ipmi_devclass, 0, 0); -MODULE_DEPEND(ipmi_pci, smbios, 1, 1, 1); /* Native IPMI on PCI driver. */ static int ipmi2_pci_probe(device_t dev) { if (pci_get_class(dev) == PCIC_SERIALBUS && pci_get_subclass(dev) == PCIS_SERIALBUS_IPMI) { device_set_desc(dev, "IPMI System Interface"); return (BUS_PROBE_GENERIC); } return (ENXIO); } static int ipmi2_pci_attach(device_t dev) { struct ipmi_softc *sc; int error, iface, type; sc = device_get_softc(dev); sc->ipmi_dev = dev; /* Interface is determined by progif. */ switch (pci_get_progif(dev)) { case PCIP_SERIALBUS_IPMI_SMIC: iface = SMIC_MODE; break; case PCIP_SERIALBUS_IPMI_KCS: iface = KCS_MODE; break; case PCIP_SERIALBUS_IPMI_BT: iface = BT_MODE; device_printf(dev, "BT interface unsupported\n"); return (ENXIO); default: device_printf(dev, "Unsupported interface: %d\n", pci_get_progif(dev)); return (ENXIO); } /* Check the BAR to determine our resource type. */ sc->ipmi_io_rid = PCIR_BAR(0); if (PCI_BAR_IO(pci_read_config(dev, PCIR_BAR(0), 4))) type = SYS_RES_IOPORT; else type = SYS_RES_MEMORY; sc->ipmi_io_type = type; sc->ipmi_io_spacing = 1; sc->ipmi_io_res[0] = bus_alloc_resource_any(dev, type, &sc->ipmi_io_rid, RF_ACTIVE); if (sc->ipmi_io_res[0] == NULL) { device_printf(dev, "couldn't map ports/memory\n"); return (ENXIO); } sc->ipmi_irq_rid = 0; sc->ipmi_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->ipmi_irq_rid, RF_SHAREABLE | RF_ACTIVE); switch (iface) { case KCS_MODE: device_printf(dev, "using KSC interface\n"); /* * We have to examine the resource directly to determine the * alignment. */ if (!ipmi_kcs_probe_align(sc)) { device_printf(dev, "Unable to determine alignment\n"); error = ENXIO; goto bad; } error = ipmi_kcs_attach(sc); if (error) goto bad; break; case SMIC_MODE: device_printf(dev, "using SMIC interface\n"); error = ipmi_smic_attach(sc); if (error) goto bad; break; } error = ipmi_attach(dev); if (error) goto bad; return (0); bad: ipmi_release_resources(dev); return (error); } static device_method_t ipmi2_methods[] = { /* Device interface */ DEVMETHOD(device_probe, ipmi2_pci_probe), DEVMETHOD(device_attach, ipmi2_pci_attach), DEVMETHOD(device_detach, ipmi_detach), { 0, 0 } }; static driver_t ipmi2_pci_driver = { "ipmi", ipmi2_methods, sizeof(struct ipmi_softc) }; DRIVER_MODULE(ipmi2_pci, pci, ipmi2_pci_driver, ipmi_devclass, 0, 0); diff --git a/sys/dev/ipmi/ipmi_smbios.c b/sys/dev/ipmi/ipmi_smbios.c index 735f404eec5f..308a3b076ef7 100644 --- a/sys/dev/ipmi/ipmi_smbios.c +++ b/sys/dev/ipmi/ipmi_smbios.c @@ -1,255 +1,269 @@ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2006 IronPort Systems Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #if defined(__amd64__) || defined(__i386__) #include #endif #include #ifdef LOCAL_MODULE #include #include #else #include #include #endif struct ipmi_entry { uint8_t type; uint8_t length; uint16_t handle; uint8_t interface_type; uint8_t spec_revision; uint8_t i2c_slave_address; uint8_t NV_storage_device_address; uint64_t base_address; uint8_t base_address_modifier; uint8_t interrupt_number; }; /* Fields in the base_address field of an IPMI entry. */ #define IPMI_BAR_MODE(ba) ((ba) & 0x0000000000000001) #define IPMI_BAR_ADDR(ba) ((ba) & 0xfffffffffffffffe) /* Fields in the base_address_modifier field of an IPMI entry. */ #define IPMI_BAM_IRQ_TRIGGER 0x01 #define IPMI_BAM_IRQ_POLARITY 0x02 #define IPMI_BAM_IRQ_VALID 0x08 #define IPMI_BAM_ADDR_LSB(bam) (((bam) & 0x10) >> 4) #define IPMI_BAM_REG_SPACING(bam) (((bam) & 0xc0) >> 6) #define SPACING_8 0x0 #define SPACING_32 0x1 #define SPACING_16 0x2 typedef void (*smbios_callback_t)(struct smbios_structure_header *, void *); static struct ipmi_get_info ipmi_info; static int ipmi_probed; static struct mtx ipmi_info_mtx; MTX_SYSINIT(ipmi_info, &ipmi_info_mtx, "ipmi info", MTX_DEF); static void ipmi_smbios_probe(struct ipmi_get_info *); static int smbios_cksum(struct smbios_eps *); -static void smbios_walk_table(uint8_t *, vm_size_t, smbios_callback_t, +static void smbios_walk_table(uint8_t *, int, smbios_callback_t, void *); static void smbios_ipmi_info(struct smbios_structure_header *, void *); static void smbios_ipmi_info(struct smbios_structure_header *h, void *arg) { struct ipmi_get_info *info; struct ipmi_entry *s; if (h->type != 38 || h->length < offsetof(struct ipmi_entry, interrupt_number)) return; s = (struct ipmi_entry *)h; info = arg; bzero(info, sizeof(struct ipmi_get_info)); switch (s->interface_type) { case KCS_MODE: case SMIC_MODE: info->address = IPMI_BAR_ADDR(s->base_address) | IPMI_BAM_ADDR_LSB(s->base_address_modifier); info->io_mode = IPMI_BAR_MODE(s->base_address); switch (IPMI_BAM_REG_SPACING(s->base_address_modifier)) { case SPACING_8: info->offset = 1; break; case SPACING_32: info->offset = 4; break; case SPACING_16: info->offset = 2; break; default: printf("SMBIOS: Invalid register spacing\n"); return; } break; case SSIF_MODE: if ((s->base_address & 0xffffffffffffff00) != 0) { printf("SMBIOS: Invalid SSIF SMBus address, using BMC I2C slave address instead\n"); info->address = s->i2c_slave_address; break; } info->address = IPMI_BAR_ADDR(s->base_address); break; default: return; } if (s->length > offsetof(struct ipmi_entry, interrupt_number)) { if (s->interrupt_number > 15) printf("SMBIOS: Non-ISA IRQ %d for IPMI\n", s->interrupt_number); else info->irq = s->interrupt_number; } info->iface_type = s->interface_type; } static void -smbios_walk_table(uint8_t *table, vm_size_t size, smbios_callback_t cb, void *arg) +smbios_walk_table(uint8_t *p, int entries, smbios_callback_t cb, void *arg) { struct smbios_structure_header *s; - uint8_t *p; - for (p = table; p < table + size;) { + while (entries--) { s = (struct smbios_structure_header *)p; cb(s, arg); /* * Look for a double-nul after the end of the * formatted area of this structure. */ p += s->length; - while (!(p[0] == 0 && p[1] == 0)) { + while (!(p[0] == 0 && p[1] == 0)) p++; - if (p >= table + size) - return; - } /* * Skip over the double-nul to the start of the next * structure. */ p += 2; } } /* * Walk the SMBIOS table looking for an IPMI (type 38) entry. If we find * one, return the parsed data in the passed in ipmi_get_info structure and * return true. If we don't find one, return false. */ static void ipmi_smbios_probe(struct ipmi_get_info *info) { + struct smbios_eps *header; void *table; - vm_paddr_t table_paddr; - vm_size_t table_size; - int err; + u_int32_t addr; bzero(info, sizeof(struct ipmi_get_info)); - err = smbios_get_structure_table(&table_paddr, &table_size); - if (err != 0) + /* Find the SMBIOS table header. */ + addr = bios_sigsearch(SMBIOS_START, SMBIOS_SIG, SMBIOS_LEN, + SMBIOS_STEP, SMBIOS_OFF); + if (addr == 0) return; - table = pmap_mapbios(table_paddr, table_size); + /* + * Map the header. We first map a fixed size to get the actual + * length and then map it a second time with the actual length so + * we can verify the checksum. + */ + header = pmap_mapbios(addr, sizeof(struct smbios_eps)); + table = pmap_mapbios(addr, header->length); + pmap_unmapbios((vm_offset_t)header, sizeof(struct smbios_eps)); + header = table; + if (smbios_cksum(header) != 0) { + pmap_unmapbios((vm_offset_t)header, header->length); + return; + } - smbios_walk_table(table, table_size, smbios_ipmi_info, info); + /* Now map the actual table and walk it looking for an IPMI entry. */ + table = pmap_mapbios(header->structure_table_address, + header->structure_table_length); + smbios_walk_table(table, header->number_structures, smbios_ipmi_info, + info); /* Unmap everything. */ - pmap_unmapbios((vm_offset_t)table, table_size); + pmap_unmapbios((vm_offset_t)table, header->structure_table_length); + pmap_unmapbios((vm_offset_t)header, header->length); } /* * Return the SMBIOS IPMI table entry info to the caller. If we haven't * searched the IPMI table yet, search it. Otherwise, return a cached * copy of the data. */ int ipmi_smbios_identify(struct ipmi_get_info *info) { mtx_lock(&ipmi_info_mtx); switch (ipmi_probed) { case 0: /* Need to probe the SMBIOS table. */ ipmi_probed++; mtx_unlock(&ipmi_info_mtx); ipmi_smbios_probe(&ipmi_info); mtx_lock(&ipmi_info_mtx); ipmi_probed++; wakeup(&ipmi_info); break; case 1: /* Another thread is currently probing the table, so wait. */ while (ipmi_probed == 1) msleep(&ipmi_info, &ipmi_info_mtx, 0, "ipmi info", 0); break; default: /* The cached data is available. */ break; } bcopy(&ipmi_info, info, sizeof(ipmi_info)); mtx_unlock(&ipmi_info_mtx); return (info->iface_type != 0); } static int smbios_cksum(struct smbios_eps *e) { u_int8_t *ptr; u_int8_t cksum; int i; ptr = (u_int8_t *)e; cksum = 0; for (i = 0; i < e->length; i++) { cksum += ptr[i]; } return (cksum); } diff --git a/sys/dev/ipmi/ipmi_smbus.c b/sys/dev/ipmi/ipmi_smbus.c index bc7377e5aee8..212248f0217e 100644 --- a/sys/dev/ipmi/ipmi_smbus.c +++ b/sys/dev/ipmi/ipmi_smbus.c @@ -1,134 +1,133 @@ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2006 IronPort Systems Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include #include "smbus_if.h" #ifdef LOCAL_MODULE #include #else #include #endif static void ipmi_smbus_identify(driver_t *driver, device_t parent); static int ipmi_smbus_probe(device_t dev); static int ipmi_smbus_attach(device_t dev); static void ipmi_smbus_identify(driver_t *driver, device_t parent) { struct ipmi_get_info info; if (ipmi_smbios_identify(&info) && info.iface_type == SSIF_MODE && device_find_child(parent, "ipmi", -1) == NULL) BUS_ADD_CHILD(parent, 0, "ipmi", -1); } static int ipmi_smbus_probe(device_t dev) { device_set_desc(dev, "IPMI System Interface"); return (BUS_PROBE_DEFAULT); } static int ipmi_smbus_attach(device_t dev) { struct ipmi_softc *sc = device_get_softc(dev); struct ipmi_get_info info; int error; /* This should never fail. */ if (!ipmi_smbios_identify(&info)) return (ENXIO); if (info.iface_type != SSIF_MODE) { device_printf(dev, "No SSIF IPMI interface found\n"); return (ENXIO); } sc->ipmi_dev = dev; if (info.irq != 0) { sc->ipmi_irq_rid = 0; sc->ipmi_irq_res = bus_alloc_resource(dev, SYS_RES_IRQ, &sc->ipmi_irq_rid, info.irq, info.irq, 1, RF_SHAREABLE | RF_ACTIVE); } device_printf(dev, "SSIF mode found at address 0x%llx on %s\n", (long long)info.address, device_get_name(device_get_parent(dev))); error = ipmi_ssif_attach(sc, device_get_parent(dev), info.address); if (error) goto bad; error = ipmi_attach(dev); if (error) goto bad; return (0); bad: ipmi_release_resources(dev); return (error); } static device_method_t ipmi_methods[] = { /* Device interface */ DEVMETHOD(device_identify, ipmi_smbus_identify), DEVMETHOD(device_probe, ipmi_smbus_probe), DEVMETHOD(device_attach, ipmi_smbus_attach), DEVMETHOD(device_detach, ipmi_detach), { 0, 0 } }; static driver_t ipmi_smbus_driver = { "ipmi", ipmi_methods, sizeof(struct ipmi_softc) }; DRIVER_MODULE(ipmi_smbus, smbus, ipmi_smbus_driver, ipmi_devclass, 0, 0); MODULE_DEPEND(ipmi_smbus, smbus, SMBUS_MINVER, SMBUS_PREFVER, SMBUS_MAXVER); -MODULE_DEPEND(ipmi_smbus, smbios, 1, 1, 1); diff --git a/sys/dev/smbios/smbios.c b/sys/dev/smbios/smbios.c index 00c7e2c98d2a..10589ed8d49d 100644 --- a/sys/dev/smbios/smbios.c +++ b/sys/dev/smbios/smbios.c @@ -1,282 +1,261 @@ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2003 Matthew N. Dodd * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include #include #include #if defined(__amd64__) || defined(__i386__) #include #endif #include -static struct smbios_softc *smbios; - /* * System Management BIOS Reference Specification, v2.4 Final * http://www.dmtf.org/standards/published_documents/DSP0134.pdf */ struct smbios_softc { device_t dev; struct resource * res; int rid; struct smbios_eps * eps; }; #define RES2EPS(res) ((struct smbios_eps *)rman_get_virtual(res)) static devclass_t smbios_devclass; static void smbios_identify (driver_t *, device_t); static int smbios_probe (device_t); static int smbios_attach (device_t); static int smbios_detach (device_t); static int smbios_modevent (module_t, int, void *); static int smbios_cksum (struct smbios_eps *); static void smbios_identify (driver_t *driver, device_t parent) { struct smbios_eps *eps; device_t child; vm_paddr_t addr; int length; int rid; if (!device_is_alive(parent)) return; #if defined(__amd64__) || defined(__i386__) addr = bios_sigsearch(SMBIOS_START, SMBIOS_SIG, SMBIOS_LEN, SMBIOS_STEP, SMBIOS_OFF); #else addr = 0; #endif if (addr != 0) { eps = pmap_mapbios(addr, 0x1f); rid = 0; length = eps->length; if (length != 0x1f) { u_int8_t major, minor; major = eps->major_version; minor = eps->minor_version; /* SMBIOS v2.1 implementation might use 0x1e. */ if (length == 0x1e && major == 2 && minor == 1) length = 0x1f; else return; } child = BUS_ADD_CHILD(parent, 5, "smbios", -1); device_set_driver(child, driver); bus_set_resource(child, SYS_RES_MEMORY, rid, addr, length); device_set_desc(child, "System Management BIOS"); pmap_unmapbios((vm_offset_t)eps, 0x1f); } return; } static int smbios_probe (device_t dev) { struct resource *res; int rid; int error; error = 0; rid = 0; res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); if (res == NULL) { device_printf(dev, "Unable to allocate memory resource.\n"); error = ENOMEM; goto bad; } if (smbios_cksum(RES2EPS(res))) { device_printf(dev, "SMBIOS checksum failed.\n"); error = ENXIO; goto bad; } bad: if (res) bus_release_resource(dev, SYS_RES_MEMORY, rid, res); return (error); } static int smbios_attach (device_t dev) { struct smbios_softc *sc; int error; sc = device_get_softc(dev); error = 0; sc->dev = dev; sc->rid = 0; sc->res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->rid, RF_ACTIVE); if (sc->res == NULL) { device_printf(dev, "Unable to allocate memory resource.\n"); error = ENOMEM; goto bad; } sc->eps = RES2EPS(sc->res); device_printf(dev, "Version: %u.%u", sc->eps->major_version, sc->eps->minor_version); if (bcd2bin(sc->eps->BCD_revision)) printf(", BCD Revision: %u.%u", bcd2bin(sc->eps->BCD_revision >> 4), bcd2bin(sc->eps->BCD_revision & 0x0f)); printf("\n"); - smbios = sc; return (0); bad: if (sc->res) bus_release_resource(dev, SYS_RES_MEMORY, sc->rid, sc->res); return (error); } static int smbios_detach (device_t dev) { struct smbios_softc *sc; - smbios = NULL; sc = device_get_softc(dev); if (sc->res) bus_release_resource(dev, SYS_RES_MEMORY, sc->rid, sc->res); return (0); } -int -smbios_get_structure_table(vm_paddr_t *table, vm_size_t *size) -{ - - if (smbios == NULL) - return (ENXIO); - if (smbios->eps_64bit) { - *table = smbios->eps3->structure_table_address; - *size = smbios->eps3->structure_table_max_size; - } else { - *table = smbios->eps->structure_table_address; - *size = smbios->eps->structure_table_length; - } - return (0); -} - - static int smbios_modevent (mod, what, arg) module_t mod; int what; void * arg; { device_t * devs; int count; int i; switch (what) { case MOD_LOAD: break; case MOD_UNLOAD: devclass_get_devices(smbios_devclass, &devs, &count); for (i = 0; i < count; i++) { device_delete_child(device_get_parent(devs[i]), devs[i]); } free(devs, M_TEMP); break; default: break; } return (0); } static device_method_t smbios_methods[] = { /* Device interface */ DEVMETHOD(device_identify, smbios_identify), DEVMETHOD(device_probe, smbios_probe), DEVMETHOD(device_attach, smbios_attach), DEVMETHOD(device_detach, smbios_detach), { 0, 0 } }; static driver_t smbios_driver = { "smbios", smbios_methods, sizeof(struct smbios_softc), }; DRIVER_MODULE(smbios, nexus, smbios_driver, smbios_devclass, smbios_modevent, 0); MODULE_VERSION(smbios, 1); static int smbios_cksum (struct smbios_eps *e) { u_int8_t *ptr; u_int8_t cksum; int i; ptr = (u_int8_t *)e; cksum = 0; for (i = 0; i < e->length; i++) { cksum += ptr[i]; } return (cksum); } diff --git a/sys/dev/smbios/smbios.h b/sys/dev/smbios/smbios.h index 554b882f1da4..6503cdb73c4c 100644 --- a/sys/dev/smbios/smbios.h +++ b/sys/dev/smbios/smbios.h @@ -1,69 +1,67 @@ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 1997 Michael Smith * Copyright (c) 1998 Jonathan Lemon * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #ifndef _SMBIOS_H_ #define _SMBIOS_H_ -int smbios_get_structure_table(vm_paddr_t *table, vm_size_t *size); - /* * System Management BIOS */ #define SMBIOS_START 0xf0000 #define SMBIOS_STEP 0x10 #define SMBIOS_OFF 0 #define SMBIOS_LEN 4 #define SMBIOS_SIG "_SM_" struct smbios_eps { uint8_t anchor_string[4]; /* '_SM_' */ uint8_t checksum; uint8_t length; uint8_t major_version; uint8_t minor_version; uint16_t maximum_structure_size; uint8_t entry_point_revision; uint8_t formatted_area[5]; uint8_t intermediate_anchor_string[5]; /* '_DMI_' */ uint8_t intermediate_checksum; uint16_t structure_table_length; uint32_t structure_table_address; uint16_t number_structures; uint8_t BCD_revision; }; struct smbios_structure_header { uint8_t type; uint8_t length; uint16_t handle; }; #endif /* _SMBIOS_H_ */