[Midnightbsd-cvs] src: dev/ichsmb: sync with freebsd 7
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Sun Nov 30 14:50:30 EST 2008
Log Message:
-----------
sync with freebsd 7
Modified Files:
--------------
src/sys/dev/ichsmb:
ichsmb.c (r1.1.1.1 -> r1.2)
ichsmb_pci.c (r1.2 -> r1.3)
-------------- next part --------------
Index: ichsmb.c
===================================================================
RCS file: /home/cvs/src/sys/dev/ichsmb/ichsmb.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/ichsmb/ichsmb.c -L sys/dev/ichsmb/ichsmb.c -u -r1.1.1.1 -r1.2
--- sys/dev/ichsmb/ichsmb.c
+++ sys/dev/ichsmb/ichsmb.c
@@ -36,7 +36,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/ichsmb/ichsmb.c,v 1.13.2.1 2005/08/19 18:38:55 brian Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/ichsmb/ichsmb.c,v 1.18 2007/02/23 12:18:43 piso Exp $");
/*
* Support for the SMBus controller logical device which is part of the
@@ -51,6 +51,7 @@
#include <sys/kernel.h>
#include <sys/errno.h>
#include <sys/lock.h>
+#include <sys/module.h>
#include <sys/mutex.h>
#include <sys/syslog.h>
#include <sys/bus.h>
@@ -70,7 +71,7 @@
#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
@@ -109,26 +110,38 @@
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,
+ NULL, 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);
}
/********************************************************************
@@ -136,7 +149,7 @@
********************************************************************/
int
-ichsmb_callback(device_t dev, int index, caddr_t data)
+ichsmb_callback(device_t dev, int index, void *data)
{
int smb_error = 0;
@@ -381,7 +394,7 @@
KASSERT(sc->ich_cmd == -1,
("%s: ich_cmd=%d\n", __func__ , sc->ich_cmd));
if (count < 1 || count > 32)
- return (EINVAL);
+ return (SMB_EINVAL);
bcopy(buf, sc->block_data, count);
sc->block_count = count;
sc->block_index = 1;
@@ -403,7 +416,7 @@
}
int
-ichsmb_bread(device_t dev, u_char slave, char cmd, u_char count, char *buf)
+ichsmb_bread(device_t dev, u_char slave, char cmd, u_char *count, char *buf)
{
const sc_p sc = device_get_softc(dev);
int smb_error;
@@ -411,10 +424,10 @@
DBG("slave=0x%02x cmd=0x%02x count=%d\n", slave, (u_char)cmd, count);
KASSERT(sc->ich_cmd == -1,
("%s: ich_cmd=%d\n", __func__ , sc->ich_cmd));
- if (count < 1 || count > 32)
- return (EINVAL);
+ if (*count < 1 || *count > 32)
+ return (SMB_EINVAL);
bzero(sc->block_data, sizeof(sc->block_data));
- sc->block_count = count;
+ sc->block_count = 0;
sc->block_index = 0;
sc->block_write = 0;
@@ -423,11 +436,13 @@
bus_space_write_1(sc->io_bst, sc->io_bsh, ICH_XMIT_SLVA,
(slave << 1) | ICH_XMIT_SLVA_READ);
bus_space_write_1(sc->io_bst, sc->io_bsh, ICH_HST_CMD, cmd);
- bus_space_write_1(sc->io_bst, sc->io_bsh, ICH_D0, count); /* XXX? */
+ bus_space_write_1(sc->io_bst, sc->io_bsh, ICH_D0, *count); /* XXX? */
bus_space_write_1(sc->io_bst, sc->io_bsh, ICH_HST_CNT,
ICH_HST_CNT_START | ICH_HST_CNT_INTREN | sc->ich_cmd);
- if ((smb_error = ichsmb_wait(sc)) == SMB_ENOERR)
- bcopy(sc->block_data, buf, sc->block_count);
+ if ((smb_error = ichsmb_wait(sc)) == SMB_ENOERR) {
+ bcopy(sc->block_data, buf, min(sc->block_count, *count));
+ *count = sc->block_count;
+ }
mtx_unlock(&sc->mutex);
DBG("smb_error=%d\n", smb_error);
#if ICHSMB_DEBUG
@@ -515,8 +530,8 @@
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;
@@ -526,12 +541,10 @@
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");
}
}
}
@@ -606,8 +619,7 @@
/* 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));
}
}
@@ -625,20 +637,14 @@
KASSERT(sc->ich_cmd != -1,
("%s: ich_cmd=%d\n", __func__ , sc->ich_cmd));
mtx_assert(&sc->mutex, MA_OWNED);
-sleep:
- error = msleep(sc, &sc->mutex, PZERO | PCATCH, "ichsmb", hz / 4);
+ error = msleep(sc, &sc->mutex, PZERO, "ichsmb", hz / 4);
DBG("msleep -> %d\n", error);
switch (error) {
- case ERESTART:
- if (sc->ich_cmd != -1)
- goto sleep;
- /* FALLTHROUGH */
case 0:
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;
@@ -674,14 +680,20 @@
}
}
-int ichsmb_detach(device_t dev)
+int
+ichsmb_detach(device_t dev)
{
const sc_p sc = device_get_softc(dev);
+ int error;
- mtx_destroy(&sc->mutex);
- bus_generic_detach(dev);
+ error = bus_generic_detach(dev);
+ if (error)
+ return (error);
device_delete_child(dev, sc->smb);
ichsmb_release_resources(sc);
+ mtx_destroy(&sc->mutex);
return 0;
}
+
+DRIVER_MODULE(smbus, ichsmb, smbus_driver, smbus_devclass, 0, 0);
Index: ichsmb_pci.c
===================================================================
RCS file: /home/cvs/src/sys/dev/ichsmb/ichsmb_pci.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -L sys/dev/ichsmb/ichsmb_pci.c -L sys/dev/ichsmb/ichsmb_pci.c -u -r1.2 -r1.3
--- sys/dev/ichsmb/ichsmb_pci.c
+++ sys/dev/ichsmb/ichsmb_pci.c
@@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/ichsmb/ichsmb_pci.c,v 1.16.2.1 2005/08/19 18:38:55 brian Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/ichsmb/ichsmb_pci.c,v 1.19.2.1 2007/12/02 08:42:15 remko Exp $");
/*
* Support for the SMBus controller logical device which is part of the
@@ -73,6 +73,8 @@
#define ID_82801CA 0x24838086
#define ID_82801DC 0x24C38086
#define ID_82801EB 0x24D38086
+#define ID_82801FB 0x266A8086
+#define ID_82801GB 0x27da8086
#define ID_6300ESB 0x25a48086
#define ID_631xESB 0x269b8086
@@ -144,11 +146,17 @@
case ID_82801EB:
device_set_desc(dev, "Intel 82801EB (ICH5) SMBus controller");
break;
+ case ID_82801FB:
+ device_set_desc(dev, "Intel 82801FB (ICH6) SMBus controller");
+ break;
+ case ID_82801GB:
+ device_set_desc(dev, "Intel 82801GB (ICH7) SMBus controller");
+ break;
case ID_6300ESB:
device_set_desc(dev, "Intel 6300ESB (ICH) SMBus controller");
break;
case ID_631xESB:
- device_set_desc(dev, "Intel 631xESB/6321ESB (ESB2 SMBus controller");
+ device_set_desc(dev, "Intel 631xESB/6321ESB (ESB2) SMBus controller");
break;
default:
if (pci_get_class(dev) == PCIC_SERIALBUS
@@ -168,7 +176,6 @@
ichsmb_pci_attach(device_t dev)
{
const sc_p sc = device_get_softc(dev);
- u_int32_t cmd;
int error;
/* Initialize private state */
@@ -184,7 +191,7 @@
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;
}
@@ -196,27 +203,7 @@
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;
}
@@ -225,7 +212,10 @@
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 */
More information about the Midnightbsd-cvs
mailing list