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 <dev/smbus/smbconf.h>
43 #include <dev/smbus/smbus.h>
44 #include <dev/smbus/smb.h>
51 #include <dev/ipmi/ipmivars.h>
54 static void ipmi_smbus_identify(driver_t *driver, device_t parent);
55 static int ipmi_smbus_probe(device_t dev);
56 static int ipmi_smbus_attach(device_t dev);
59 ipmi_smbus_identify(driver_t *driver, device_t parent)
61 struct ipmi_get_info info;
63 if (ipmi_smbios_identify(&info) && info.iface_type == SSIF_MODE &&
64 device_find_child(parent, "ipmi", -1) == NULL)
65 BUS_ADD_CHILD(parent, 0, "ipmi", -1);
69 ipmi_smbus_probe(device_t dev)
72 device_set_desc(dev, "IPMI System Interface");
73 return (BUS_PROBE_DEFAULT);
77 ipmi_smbus_attach(device_t dev)
79 struct ipmi_softc *sc = device_get_softc(dev);
80 struct ipmi_get_info info;
83 /* This should never fail. */
84 if (!ipmi_smbios_identify(&info))
87 if (info.iface_type != SSIF_MODE) {
88 device_printf(dev, "No SSIF IPMI interface found\n");
96 sc->ipmi_irq_res = bus_alloc_resource(dev, SYS_RES_IRQ,
97 &sc->ipmi_irq_rid, info.irq, info.irq, 1,
98 RF_SHAREABLE | RF_ACTIVE);
101 device_printf(dev, "SSIF mode found at address 0x%llx on %s\n",
102 (long long)info.address, device_get_name(device_get_parent(dev)));
103 error = ipmi_ssif_attach(sc, device_get_parent(dev), info.address);
107 error = ipmi_attach(dev);
113 ipmi_release_resources(dev);
117 static device_method_t ipmi_methods[] = {
118 /* Device interface */
119 DEVMETHOD(device_identify, ipmi_smbus_identify),
120 DEVMETHOD(device_probe, ipmi_smbus_probe),
121 DEVMETHOD(device_attach, ipmi_smbus_attach),
122 DEVMETHOD(device_detach, ipmi_detach),
126 static driver_t ipmi_smbus_driver = {
129 sizeof(struct ipmi_softc)
132 DRIVER_MODULE(ipmi_smbus, smbus, ipmi_smbus_driver, ipmi_devclass, 0, 0);
133 MODULE_DEPEND(ipmi_smbus, smbus, SMBUS_MINVER, SMBUS_PREFVER, SMBUS_MAXVER);