summaryrefslogtreecommitdiffstats
path: root/sys/dev/ichsmb
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2007-01-11 19:56:24 +0000
committerjhb <jhb@FreeBSD.org>2007-01-11 19:56:24 +0000
commitafb4cfc54730fc4d0a2e88684ce0e206183e1e12 (patch)
tree939162cf86e1bf400a9cd9525a74dde0f62ddc2a /sys/dev/ichsmb
parent13d4be4423daeef02c737b4e4cc24cbb9b9b46b1 (diff)
downloadFreeBSD-src-afb4cfc54730fc4d0a2e88684ce0e206183e1e12.zip
FreeBSD-src-afb4cfc54730fc4d0a2e88684ce0e206183e1e12.tar.gz
Various updates to most of the smbus(4) drivers:
- Use printf() and device_printf() instead of log() in ichsmb(4). - Create the mutex sooner during ichsmb(4) attach. - Attach the interrupt handler later during ichsmb(4) attach to avoid races. - Don't try to set PCIM_CMD_PORTEN in ichsmb(4) attach as the PCI bus driver does this already. - Add locking to alpm(4), amdpm(4), amdsmb(4), intsmb(4), nfsmb(4), and viapm(4). - Axe ALPM_SMBIO_BASE_ADDR, it's not really safe to write arbitrary values into BARs, and the PCI bus layer will allocate resources now if needed. - Merge intpm(4) and intsmb(4) into just intsmb(4). Previously, intpm(4) attached to the PCI device and created an intsmb(4) child. Now, intsmb(4) just attaches to PCI directly. - Change several intsmb functions to take a softc instead of a device_t to make things simpler.
Diffstat (limited to 'sys/dev/ichsmb')
-rw-r--r--sys/dev/ichsmb/ichsmb.c50
-rw-r--r--sys/dev/ichsmb/ichsmb_pci.c30
2 files changed, 35 insertions, 45 deletions
diff --git a/sys/dev/ichsmb/ichsmb.c b/sys/dev/ichsmb/ichsmb.c
index 18aa32b..a12f287 100644
--- a/sys/dev/ichsmb/ichsmb.c
+++ b/sys/dev/ichsmb/ichsmb.c
@@ -71,7 +71,7 @@ __FBSDID("$FreeBSD$");
#define ICHSMB_DEBUG 0
#if ICHSMB_DEBUG != 0 && defined(__CC_SUPPORTS___FUNC__)
#define DBG(fmt, args...) \
- do { log(LOG_DEBUG, "%s: " fmt, __func__ , ## args); } while (0)
+ do { printf("%s: " fmt, __func__ , ## args); } while (0)
#else
#define DBG(fmt, args...) do { } while (0)
#endif
@@ -110,26 +110,38 @@ ichsmb_attach(device_t dev)
const sc_p sc = device_get_softc(dev);
int error;
+ /* Create mutex */
+ mtx_init(&sc->mutex, device_get_nameunit(dev), "ichsmb", MTX_DEF);
+
/* Add child: an instance of the "smbus" device */
if ((sc->smb = device_add_child(dev, DRIVER_SMBUS, -1)) == NULL) {
- log(LOG_ERR, "%s: no \"%s\" child found\n",
- device_get_nameunit(dev), DRIVER_SMBUS);
- return (ENXIO);
+ device_printf(dev, "no \"%s\" child found\n", DRIVER_SMBUS);
+ error = ENXIO;
+ goto fail;
}
/* Clear interrupt conditions */
bus_space_write_1(sc->io_bst, sc->io_bsh, ICH_HST_STA, 0xff);
- /* Add "smbus" child */
+ /* Set up interrupt handler */
+ error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_MISC,
+ ichsmb_device_intr, sc, &sc->irq_handle);
+ if (error != 0) {
+ device_printf(dev, "can't setup irq\n");
+ goto fail;
+ }
+
+ /* Attach "smbus" child */
if ((error = bus_generic_attach(dev)) != 0) {
- log(LOG_ERR, "%s: failed to attach child: %d\n",
- device_get_nameunit(dev), error);
- return (ENXIO);
+ device_printf(dev, "failed to attach child: %d\n", error);
+ goto fail;
}
- /* Create mutex */
- mtx_init(&sc->mutex, device_get_nameunit(dev), "ichsmb", MTX_DEF);
return (0);
+
+fail:
+ mtx_destroy(&sc->mutex);
+ return (error);
}
/********************************************************************
@@ -518,8 +530,8 @@ ichsmb_device_intr(void *cookie)
ok_bits |= ichsmb_state_irqs[cmd_index];
}
if ((status & ~ok_bits) != 0) {
- log(LOG_ERR, "%s: irq 0x%02x during %d\n",
- device_get_nameunit(dev), status, cmd_index);
+ device_printf(dev, "irq 0x%02x during %d\n", status,
+ cmd_index);
bus_space_write_1(sc->io_bst, sc->io_bsh,
ICH_HST_STA, (status & ~ok_bits));
continue;
@@ -529,12 +541,10 @@ ichsmb_device_intr(void *cookie)
if (status & ICH_HST_STA_SMBALERT_STS) {
static int smbalert_count = 16;
if (smbalert_count > 0) {
- log(LOG_WARNING, "%s: SMBALERT# rec'd\n",
- device_get_nameunit(dev));
+ device_printf(dev, "SMBALERT# rec'd\n");
if (--smbalert_count == 0) {
- log(LOG_WARNING,
- "%s: not logging anymore\n",
- device_get_nameunit(dev));
+ device_printf(dev,
+ "not logging anymore\n");
}
}
}
@@ -609,8 +619,7 @@ finished:
/* Too many loops? */
if (count == maxloops) {
- log(LOG_ERR, "%s: interrupt loop, status=0x%02x\n",
- device_get_nameunit(dev),
+ device_printf(dev, "interrupt loop, status=0x%02x\n",
bus_space_read_1(sc->io_bst, sc->io_bsh, ICH_HST_STA));
}
}
@@ -635,8 +644,7 @@ ichsmb_wait(sc_p sc)
smb_error = sc->smb_error;
break;
case EWOULDBLOCK:
- log(LOG_ERR, "%s: device timeout, status=0x%02x\n",
- device_get_nameunit(dev),
+ device_printf(dev, "device timeout, status=0x%02x\n",
bus_space_read_1(sc->io_bst, sc->io_bsh, ICH_HST_STA));
sc->ich_cmd = -1;
smb_error = SMB_ETIMEOUT;
diff --git a/sys/dev/ichsmb/ichsmb_pci.c b/sys/dev/ichsmb/ichsmb_pci.c
index 54c3b97..336c01c 100644
--- a/sys/dev/ichsmb/ichsmb_pci.c
+++ b/sys/dev/ichsmb/ichsmb_pci.c
@@ -164,7 +164,6 @@ static int
ichsmb_pci_attach(device_t dev)
{
const sc_p sc = device_get_softc(dev);
- u_int32_t cmd;
int error;
/* Initialize private state */
@@ -180,7 +179,7 @@ ichsmb_pci_attach(device_t dev)
sc->io_res = bus_alloc_resource(dev, SYS_RES_IOPORT,
&sc->io_rid, 0, ~0, 32, RF_ACTIVE);
if (sc->io_res == NULL) {
- log(LOG_ERR, "%s: can't map I/O\n", device_get_nameunit(dev));
+ device_printf(dev, "can't map I/O\n");
error = ENXIO;
goto fail;
}
@@ -192,27 +191,7 @@ ichsmb_pci_attach(device_t dev)
sc->irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ,
&sc->irq_rid, RF_ACTIVE | RF_SHAREABLE);
if (sc->irq_res == NULL) {
- log(LOG_ERR, "%s: can't get IRQ\n", device_get_nameunit(dev));
- error = ENXIO;
- goto fail;
- }
-
- /* Set up interrupt handler */
- error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_MISC,
- ichsmb_device_intr, sc, &sc->irq_handle);
- if (error != 0) {
- log(LOG_ERR, "%s: can't setup irq\n", device_get_nameunit(dev));
- goto fail;
- }
-
- /* Enable I/O mapping */
- cmd = pci_read_config(dev, PCIR_COMMAND, 4);
- cmd |= PCIM_CMD_PORTEN;
- pci_write_config(dev, PCIR_COMMAND, cmd, 4);
- cmd = pci_read_config(dev, PCIR_COMMAND, 4);
- if ((cmd & PCIM_CMD_PORTEN) == 0) {
- log(LOG_ERR, "%s: can't enable memory map\n",
- device_get_nameunit(dev));
+ device_printf(dev, "can't get IRQ\n");
error = ENXIO;
goto fail;
}
@@ -221,7 +200,10 @@ ichsmb_pci_attach(device_t dev)
pci_write_config(dev, ICH_HOSTC, ICH_HOSTC_HST_EN, 1);
/* Done */
- return (ichsmb_attach(dev));
+ error = ichsmb_attach(dev);
+ if (error)
+ goto fail;
+ return (0);
fail:
/* Attach failed, release resources */
OpenPOWER on IntegriCloud