ipmi_acpi.c revision 267654
1194955Strasz/*- 2194955Strasz * Copyright (c) 2006 IronPort Systems Inc. <ambrisko@ironport.com> 3194955Strasz * All rights reserved. 4194955Strasz * 5194955Strasz * Redistribution and use in source and binary forms, with or without 6194955Strasz * modification, are permitted provided that the following conditions 7194955Strasz * are met: 8194955Strasz * 1. Redistributions of source code must retain the above copyright 9194955Strasz * notice, this list of conditions and the following disclaimer. 10194955Strasz * 2. Redistributions in binary form must reproduce the above copyright 11194955Strasz * notice, this list of conditions and the following disclaimer in the 12194955Strasz * documentation and/or other materials provided with the distribution. 13194955Strasz * 14194955Strasz * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15194955Strasz * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16194955Strasz * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17204725Sjoel * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18204725Sjoel * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19204725Sjoel * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20204725Sjoel * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21204725Sjoel * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22204725Sjoel * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23204725Sjoel * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24204725Sjoel * SUCH DAMAGE. 25194955Strasz */ 26194955Strasz 27194955Strasz#include <sys/cdefs.h> 28194956Strasz__FBSDID("$FreeBSD: releng/9.3/sys/dev/ipmi/ipmi_acpi.c 193530 2009-06-05 18:44:36Z jkim $"); 29194955Strasz 30194955Strasz#include <sys/param.h> 31194955Strasz#include <sys/systm.h> 32194955Strasz#include <sys/bus.h> 33194955Strasz#include <sys/condvar.h> 34194955Strasz#include <sys/kernel.h> 35194955Strasz#include <sys/module.h> 36194955Strasz#include <sys/rman.h> 37194955Strasz#include <sys/selinfo.h> 38194955Strasz 39194955Strasz#include <contrib/dev/acpica/include/acpi.h> 40194955Strasz 41194955Strasz#include <dev/acpica/acpivar.h> 42194955Strasz 43194955Strasz/* Hooks for the ACPI CA debugging infrastructure */ 44194955Strasz#define _COMPONENT ACPI_BUTTON 45194955StraszACPI_MODULE_NAME("IPMI") 46194955Strasz 47194955Strasz#ifdef LOCAL_MODULE 48194955Strasz#include <ipmi.h> 49194955Strasz#include <ipmivars.h> 50194955Strasz#else 51194955Strasz#include <sys/ipmi.h> 52194955Strasz#include <dev/ipmi/ipmivars.h> 53194955Strasz#endif 54194955Strasz 55194955Straszstatic int ipmi_acpi_probe(device_t); 56194955Straszstatic int ipmi_acpi_attach(device_t); 57194955Strasz 58194955Straszint 59194955Straszipmi_acpi_probe(device_t dev) 60194955Strasz{ 61194955Strasz static char *ipmi_ids[] = {"IPI0001", NULL}; 62194955Strasz 63194955Strasz if (ipmi_attached) 64194955Strasz return (EBUSY); 65194955Strasz 66194955Strasz if (acpi_disabled("ipmi") || 67194955Strasz ACPI_ID_PROBE(device_get_parent(dev), dev, ipmi_ids) == NULL) 68194955Strasz return (ENXIO); 69194955Strasz 70194955Strasz device_set_desc(dev, "IPMI System Interface"); 71194955Strasz 72194955Strasz return (0); 73194955Strasz} 74194955Strasz 75194955Straszstatic int 76194955Straszipmi_acpi_attach(device_t dev) 77194955Strasz{ 78194955Strasz ACPI_HANDLE devh; 79194955Strasz const char *mode; 80194955Strasz struct ipmi_get_info info; 81194955Strasz struct ipmi_softc *sc = device_get_softc(dev); 82194955Strasz int count, error, flags, i, type; 83194955Strasz int interface_type = 0, interface_version = 0; 84194955Strasz 85194955Strasz error = 0; 86194955Strasz devh = acpi_get_handle(dev); 87 if (ACPI_FAILURE(acpi_GetInteger(devh, "_IFT", &interface_type))) 88 return (ENXIO); 89 90 if (ACPI_FAILURE(acpi_GetInteger(devh, "_SRV", &interface_version))) 91 return (ENXIO); 92 93 switch (interface_type) { 94 case KCS_MODE: 95 count = 2; 96 mode = "KCS"; 97 break; 98 case SMIC_MODE: 99 count = 3; 100 mode = "SMIC"; 101 break; 102 case BT_MODE: 103 device_printf(dev, "BT interface not supported\n"); 104 return (ENXIO); 105 case SSIF_MODE: 106 if (ACPI_FAILURE(acpi_GetInteger(devh, "_ADR", &flags))) 107 return (ENXIO); 108 info.address = flags; 109 device_printf(dev, "SSIF interface not supported on ACPI\n"); 110 return (0); 111 default: 112 return (ENXIO); 113 } 114 115 if (bus_get_resource(dev, SYS_RES_IOPORT, 0, NULL, NULL) == 0) 116 type = SYS_RES_IOPORT; 117 else if (bus_get_resource(dev, SYS_RES_MEMORY, 0, NULL, NULL) == 0) 118 type = SYS_RES_MEMORY; 119 else { 120 device_printf(dev, "unknown resource type\n"); 121 return (ENXIO); 122 } 123 124 sc->ipmi_io_rid = 0; 125 sc->ipmi_io_res[0] = bus_alloc_resource_any(dev, type, 126 &sc->ipmi_io_rid, RF_ACTIVE); 127 sc->ipmi_io_type = type; 128 sc->ipmi_io_spacing = 1; 129 if (sc->ipmi_io_res[0] == NULL) { 130 device_printf(dev, "couldn't configure I/O resource\n"); 131 return (ENXIO); 132 } 133 134 /* If we have multiple resources, allocate up to MAX_RES. */ 135 for (i = 1; i < MAX_RES; i++) { 136 sc->ipmi_io_rid = i; 137 sc->ipmi_io_res[i] = bus_alloc_resource_any(dev, type, 138 &sc->ipmi_io_rid, RF_ACTIVE); 139 if (sc->ipmi_io_res[i] == NULL) 140 break; 141 } 142 sc->ipmi_io_rid = 0; 143 144 /* If we have multiple resources, make sure we have enough of them. */ 145 if (sc->ipmi_io_res[1] != NULL && sc->ipmi_io_res[count - 1] == NULL) { 146 device_printf(dev, "too few I/O resources\n"); 147 error = ENXIO; 148 goto bad; 149 } 150 151 device_printf(dev, "%s mode found at %s 0x%jx on %s\n", 152 mode, type == SYS_RES_IOPORT ? "io" : "mem", 153 (uintmax_t)rman_get_start(sc->ipmi_io_res[0]), 154 device_get_name(device_get_parent(dev))); 155 156 sc->ipmi_dev = dev; 157 158 /* 159 * Setup an interrupt if we have an interrupt resource. We 160 * don't support GPE interrupts via _GPE yet. 161 */ 162 sc->ipmi_irq_rid = 0; 163 sc->ipmi_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, 164 &sc->ipmi_irq_rid, RF_SHAREABLE | RF_ACTIVE); 165 166 /* Warn if _GPE exists. */ 167 if (ACPI_SUCCESS(AcpiEvaluateObject(devh, "_GPE", NULL, NULL))) 168 device_printf(dev, "_GPE support not implemented\n"); 169 170 /* 171 * We assume an alignment of 1 byte as currently the IPMI spec 172 * doesn't provide any way to determine the alignment via ACPI. 173 */ 174 switch (interface_type) { 175 case KCS_MODE: 176 error = ipmi_kcs_attach(sc); 177 if (error) 178 goto bad; 179 break; 180 case SMIC_MODE: 181 error = ipmi_smic_attach(sc); 182 if (error) 183 goto bad; 184 break; 185 } 186 error = ipmi_attach(dev); 187 if (error) 188 goto bad; 189 190 return (0); 191bad: 192 ipmi_release_resources(dev); 193 return (error); 194} 195 196static device_method_t ipmi_methods[] = { 197 /* Device interface */ 198 DEVMETHOD(device_probe, ipmi_acpi_probe), 199 DEVMETHOD(device_attach, ipmi_acpi_attach), 200 DEVMETHOD(device_detach, ipmi_detach), 201 { 0, 0 } 202}; 203 204static driver_t ipmi_acpi_driver = { 205 "ipmi", 206 ipmi_methods, 207 sizeof(struct ipmi_softc), 208}; 209 210DRIVER_MODULE(ipmi_acpi, acpi, ipmi_acpi_driver, ipmi_devclass, 0, 0); 211MODULE_DEPEND(ipmi_acpi, acpi, 1, 1, 1); 212