--- //depot/yahoo/ybsd_6/src/sys/dev/bktr/bktr_i2c.c 2005/06/04 00:22:47 +++ //depot/jhb/ipmi/sys/dev/bktr/bktr_i2c.c 2006/08/30 11:22:28 @@ -119,7 +119,7 @@ return (error); } -int bti2c_smb_callback(device_t dev, int index, caddr_t *data) +int bti2c_smb_callback(device_t dev, int index, void *data) { struct bktr_softc *bktr_sc = (struct bktr_softc *)device_get_softc(dev); struct bktr_i2c_softc *sc = &bktr_sc->i2c_sc; @@ -338,4 +338,6 @@ return (0); } +DRIVER_MODULE(smbus, bktr, smbus_driver, smbus_devclass, 0, 0); + #endif /* defined(BKTR_USE_FREEBSD_SMBUS) */ --- //depot/yahoo/ybsd_6/src/sys/dev/ichsmb/ichsmb.c 2005/08/22 20:35:35 +++ //depot/jhb/ipmi/sys/dev/ichsmb/ichsmb.c 2006/08/30 11:30:06 @@ -51,6 +51,7 @@ #include #include #include +#include #include #include #include @@ -136,7 +137,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; @@ -403,7 +404,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 +412,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) + if (*count < 1 || *count > 32) return (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 +424,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 @@ -674,14 +677,17 @@ } } -int ichsmb_detach(device_t dev) +int +ichsmb_detach(device_t dev) { const sc_p sc = device_get_softc(dev); - mtx_destroy(&sc->mutex); bus_generic_detach(dev); 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); --- //depot/yahoo/ybsd_6/src/sys/dev/iicbus/iicsmb.c 2004/12/23 17:57:00 +++ //depot/jhb/ipmi/sys/dev/iicbus/iicsmb.c 2006/08/30 11:22:28 @@ -83,7 +83,7 @@ static void iicsmb_identify(driver_t *driver, device_t parent); static void iicsmb_intr(device_t dev, int event, char *buf); -static int iicsmb_callback(device_t dev, int index, caddr_t data); +static int iicsmb_callback(device_t dev, int index, void *data); static int iicsmb_quick(device_t dev, u_char slave, int how); static int iicsmb_sendb(device_t dev, u_char slave, char byte); static int iicsmb_recvb(device_t dev, u_char slave, char *byte); @@ -93,7 +93,7 @@ static int iicsmb_readw(device_t dev, u_char slave, char cmd, short *word); static int iicsmb_pcall(device_t dev, u_char slave, char cmd, short sdata, short *rdata); static int iicsmb_bwrite(device_t dev, u_char slave, char cmd, u_char count, char *buf); -static int iicsmb_bread(device_t dev, u_char slave, char cmd, u_char count, char *buf); +static int iicsmb_bread(device_t dev, u_char slave, char cmd, u_char *count, char *buf); static devclass_t iicsmb_devclass; @@ -249,7 +249,7 @@ } static int -iicsmb_callback(device_t dev, int index, caddr_t data) +iicsmb_callback(device_t dev, int index, void *data) { device_t parent = device_get_parent(dev); int error = 0; @@ -484,7 +484,7 @@ } static int -iicsmb_bread(device_t dev, u_char slave, char cmd, u_char count, char *buf) +iicsmb_bread(device_t dev, u_char slave, char cmd, u_char *count, char *buf) { device_t parent = device_get_parent(dev); int error, sent, read; @@ -498,9 +498,10 @@ if ((error = iicbus_repeated_start(parent, slave | LSB, IICBUS_TIMEOUT))) goto error; - if ((error = iicbus_read(parent, buf, (int)count, &read, + if ((error = iicbus_read(parent, buf, (int)*count, &read, IIC_LAST_READ, IICBUS_TIMEOUT))) goto error; + *count = read; error: iicbus_stop(parent); @@ -508,6 +509,7 @@ } DRIVER_MODULE(iicsmb, iicbus, iicsmb_driver, iicsmb_devclass, 0, 0); +DRIVER_MODULE(smbus, iicsmb, smbus_driver, smbus_devclass, 0, 0); MODULE_DEPEND(iicsmb, iicbus, IICBUS_MINVER, IICBUS_PREFVER, IICBUS_MAXVER); MODULE_DEPEND(iicsmb, smbus, SMBUS_MINVER, SMBUS_PREFVER, SMBUS_MAXVER); MODULE_VERSION(iicsmb, 1); --- //depot/yahoo/ybsd_6/src/sys/dev/smbus/smb.c 2006/02/01 21:28:07 +++ //depot/jhb/ipmi/sys/dev/smbus/smb.c 2006/08/25 09:57:17 @@ -55,6 +55,7 @@ #define IIC_DEVICE(unit) \ (devclass_get_device(smb_devclass, (unit))) +static void smb_identify(driver_t *driver, device_t parent); static int smb_probe(device_t); static int smb_attach(device_t); static int smb_detach(device_t); @@ -63,6 +64,7 @@ static device_method_t smb_methods[] = { /* device interface */ + DEVMETHOD(device_identify, smb_identify), DEVMETHOD(device_probe, smb_probe), DEVMETHOD(device_attach, smb_attach), DEVMETHOD(device_detach, smb_detach), @@ -92,6 +94,14 @@ .d_name = "smb", }; +static void +smb_identify(driver_t *driver, device_t parent) +{ + + if (device_find_child(parent, "smb", -1) == NULL) + BUS_ADD_CHILD(parent, 0, "smb", -1); +} + static int smb_probe(device_t dev) { @@ -171,6 +181,7 @@ device_t smbdev = IIC_DEVICE(minor(dev)); int error; short w; + u_char count; char c; if (sc == NULL) @@ -261,13 +272,13 @@ case SMB_BREAD: if (s->count && s->data.byte_ptr) { - if (s->count > SMB_MAXBLOCKSIZE) - s->count = SMB_MAXBLOCKSIZE; + count = min(s->count, SMB_MAXBLOCKSIZE); error = smbus_error(smbus_bread(parent, s->slave, - s->cmd, s->count, buf)); + s->cmd, &count, buf)); if (error) break; - error = copyout(buf, s->data.byte_ptr, s->count); + /* XXX: We don't return the actual count. */ + error = copyout(buf, s->data.byte_ptr, count); } break; --- //depot/yahoo/ybsd_6/src/sys/dev/smbus/smbconf.c 2004/12/23 17:57:00 +++ //depot/jhb/ipmi/sys/dev/smbus/smbconf.c 2006/08/30 11:30:06 @@ -30,7 +30,9 @@ __FBSDID("$FreeBSD: src/sys/dev/smbus/smbconf.c,v 1.13 2003/08/24 18:03:44 obrien Exp $"); #include #include +#include #include +#include #include #include @@ -43,13 +45,13 @@ void smbus_intr(device_t bus, u_char devaddr, char low, char high, int error) { - struct smbus_softc *sc = (struct smbus_softc *)device_get_softc(bus); + struct smbus_softc *sc = device_get_softc(bus); /* call owner's intr routine */ + mtx_lock(&sc->lock); if (sc->owner) SMBUS_INTR(sc->owner, devaddr, low, high, error); - - return; + mtx_unlock(&sc->lock); } /* @@ -65,17 +67,16 @@ if (smb_error == SMB_ENOERR) return (0); - if (smb_error & (SMB_ENOTSUPP)) { + if (smb_error & (SMB_ENOTSUPP)) error = ENODEV; - } else if (smb_error & (SMB_ENOACK)) { + else if (smb_error & (SMB_ENOACK)) error = ENXIO; - } else if (smb_error & (SMB_ETIMEOUT)) { + else if (smb_error & (SMB_ETIMEOUT)) error = EWOULDBLOCK; - } else if (smb_error & (SMB_EBUSY)) { + else if (smb_error & (SMB_EBUSY)) error = EBUSY; - } else { + else error = EINVAL; - } return (error); } @@ -86,16 +87,16 @@ int error; switch (how) { - case (SMB_WAIT | SMB_INTR): - error = tsleep(sc, SMBPRI|PCATCH, "smbreq", 0); + case SMB_WAIT | SMB_INTR: + error = msleep(sc, &sc->lock, SMBPRI|PCATCH, "smbreq", 0); break; - case (SMB_WAIT | SMB_NOINTR): - error = tsleep(sc, SMBPRI, "smbreq", 0); + case SMB_WAIT | SMB_NOINTR: + error = msleep(sc, &sc->lock, SMBPRI, "smbreq", 0); break; default: - return (EWOULDBLOCK); + error = EWOULDBLOCK; break; } @@ -112,35 +113,38 @@ int smbus_request_bus(device_t bus, device_t dev, int how) { - struct smbus_softc *sc = (struct smbus_softc *)device_get_softc(bus); - int s, error = 0; + struct smbus_softc *sc = device_get_softc(bus); + device_t parent; + int error; /* first, ask the underlying layers if the request is ok */ + parent = device_get_parent(bus); + mtx_lock(&sc->lock); do { - error = SMBUS_CALLBACK(device_get_parent(bus), - SMB_REQUEST_BUS, (caddr_t)&how); + mtx_unlock(&sc->lock); + error = SMBUS_CALLBACK(parent, SMB_REQUEST_BUS, &how); + mtx_lock(&sc->lock); + if (error) error = smbus_poll(sc, how); } while (error == EWOULDBLOCK); - while (!error) { - s = splhigh(); - if (sc->owner && sc->owner != dev) { - splx(s); - + while (error == 0) { + if (sc->owner && sc->owner != dev) error = smbus_poll(sc, how); - } else { + else { sc->owner = dev; - - splx(s); - return (0); + break; } /* free any allocated resource */ - if (error) - SMBUS_CALLBACK(device_get_parent(bus), SMB_RELEASE_BUS, - (caddr_t)&how); + if (error) { + mtx_unlock(&sc->lock); + SMBUS_CALLBACK(parent, SMB_RELEASE_BUS, &how); + return (error); + } } + mtx_unlock(&sc->lock); return (error); } @@ -153,8 +157,8 @@ int smbus_release_bus(device_t bus, device_t dev) { - struct smbus_softc *sc = (struct smbus_softc *)device_get_softc(bus); - int s, error; + struct smbus_softc *sc = device_get_softc(bus); + int error; /* first, ask the underlying layers if the release is ok */ error = SMBUS_CALLBACK(device_get_parent(bus), SMB_RELEASE_BUS, NULL); @@ -162,17 +166,15 @@ if (error) return (error); - s = splhigh(); - if (sc->owner != dev) { - splx(s); - return (EACCES); - } + mtx_lock(&sc->lock); + if (sc->owner == dev) { + sc->owner = NULL; - sc->owner = 0; - splx(s); + /* wakeup waiting processes */ + wakeup(sc); + } else + error = EACCES; + mtx_unlock(&sc->lock); - /* wakeup waiting processes */ - wakeup(sc); - - return (0); + return (error); } --- //depot/yahoo/ybsd_6/src/sys/dev/smbus/smbconf.h 2004/12/23 17:57:00 +++ //depot/jhb/ipmi/sys/dev/smbus/smbconf.h 2006/08/30 10:55:48 @@ -69,16 +69,19 @@ /* * ivars codes */ -#define SMBUS_IVAR_ADDR 0x1 /* I2C address of the device */ +#define SMBUS_IVAR_ADDR 0x1 /* slave address of the device */ + +int smbus_request_bus(device_t, device_t, int); +int smbus_release_bus(device_t, device_t); +device_t smbus_alloc_bus(device_t); +int smbus_error(int error); -extern int smbus_request_bus(device_t, device_t, int); -extern int smbus_release_bus(device_t, device_t); -extern device_t smbus_alloc_bus(device_t); -extern int smbus_error(int error); +void smbus_intr(device_t, u_char, char low, char high, int error); -extern void smbus_intr(device_t, u_char, char low, char high, int error); +u_char smbus_get_addr(device_t); -extern u_char smbus_get_addr(device_t); +extern driver_t smbus_driver; +extern devclass_t smbus_devclass; #define smbus_quick(bus,slave,how) \ (SMBUS_QUICK(device_get_parent(bus), slave, how)) --- //depot/yahoo/ybsd_6/src/sys/dev/smbus/smbus.c 2006/08/24 10:57:46 +++ //depot/jhb/ipmi/sys/dev/smbus/smbus.c 2006/08/30 11:30:06 @@ -30,32 +30,30 @@ __FBSDID("$FreeBSD: src/sys/dev/smbus/smbus.c,v 1.18.10.2 2006/08/17 11:01:25 ru Exp $"); #include #include -#include +#include #include +#include #include #include #include /* - * Autoconfiguration and support routines for the Philips serial I2C bus + * Autoconfiguration and support routines for System Management bus */ -#define DEVTOSMBUS(dev) ((struct smbus_device*)device_get_ivars(dev)) - -static devclass_t smbus_devclass; - /* * Device methods */ static int smbus_probe(device_t); static int smbus_attach(device_t); +static int smbus_detach(device_t); static device_method_t smbus_methods[] = { /* device interface */ DEVMETHOD(device_probe, smbus_probe), DEVMETHOD(device_attach, smbus_attach), - DEVMETHOD(device_detach, bus_generic_detach), + DEVMETHOD(device_detach, smbus_detach), /* bus interface */ DEVMETHOD(bus_print_child, bus_generic_print_child), @@ -63,12 +61,14 @@ { 0, 0 } }; -static driver_t smbus_driver = { +driver_t smbus_driver = { "smbus", smbus_methods, sizeof(struct smbus_softc), }; +devclass_t smbus_devclass; + /* * At 'probe' time, we add all the devices which we know about to the * bus. The generic attach routine will probe and attach them if they @@ -77,6 +77,7 @@ static int smbus_probe(device_t dev) { + device_set_desc(dev, "System Management Bus"); return (0); @@ -85,25 +86,29 @@ static int smbus_attach(device_t dev) { - device_add_child(dev, NULL, -1); + struct smbus_softc *sc = device_get_softc(dev); + + mtx_init(&sc->lock, device_get_nameunit(dev), "smbus", MTX_DEF); + bus_generic_probe(dev); bus_generic_attach(dev); return (0); } +static int +smbus_detach(device_t dev) +{ + struct smbus_softc *sc = device_get_softc(dev); + + bus_generic_detach(dev); + mtx_destroy(&sc->lock); + + return (0); +} + void smbus_generic_intr(device_t dev, u_char devaddr, char low, char high) { - return; } -DRIVER_MODULE(smbus, iicsmb, smbus_driver, smbus_devclass, 0, 0); -DRIVER_MODULE(smbus, bktr, smbus_driver, smbus_devclass, 0, 0); -DRIVER_MODULE(smbus, intsmb, smbus_driver, smbus_devclass, 0, 0); -DRIVER_MODULE(smbus, alpm, smbus_driver, smbus_devclass, 0, 0); -DRIVER_MODULE(smbus, ichsmb, smbus_driver, smbus_devclass, 0, 0); -DRIVER_MODULE(smbus, amdpm, smbus_driver, smbus_devclass, 0, 0); -DRIVER_MODULE(smbus, amdsmb, smbus_driver, smbus_devclass, 0, 0); -DRIVER_MODULE(smbus, nfsmb, smbus_driver, smbus_devclass, 0, 0); -DRIVER_MODULE(smbus, viapropm, smbus_driver, smbus_devclass, 0, 0); MODULE_VERSION(smbus, SMBUS_MODVER); --- //depot/yahoo/ybsd_6/src/sys/dev/smbus/smbus.h 2006/02/01 21:28:07 +++ //depot/jhb/ipmi/sys/dev/smbus/smbus.h 2006/08/30 10:55:48 @@ -30,10 +30,10 @@ #define __SMBUS_H struct smbus_softc { - device_t owner; /* smbus owner device structure */ + struct mtx lock; }; -extern void smbus_generic_intr(device_t dev, u_char devaddr, char low, char high); +void smbus_generic_intr(device_t dev, u_char devaddr, char low, char high); #endif --- //depot/yahoo/ybsd_6/src/sys/dev/smbus/smbus_if.m 2005/01/25 16:45:15 +++ //depot/jhb/ipmi/sys/dev/smbus/smbus_if.m 2006/08/30 10:55:48 @@ -47,7 +47,7 @@ METHOD int callback { device_t dev; int index; - caddr_t data; + void *data; }; # @@ -146,6 +146,6 @@ device_t dev; u_char slave; char cmd; - u_char count; + u_char *count; char *buf; }; --- //depot/yahoo/ybsd_6/src/sys/kern/bus_if.m 2006/08/24 10:57:46 +++ //depot/jhb/ipmi/sys/kern/bus_if.m 2006/08/25 10:08:08 @@ -194,7 +194,7 @@ int _order; const char *_name; int _unit; -}; +} DEFAULT bus_generic_add_child; /** * @brief Allocate a system resource --- //depot/yahoo/ybsd_6/src/sys/kern/subr_bus.c 2006/08/24 10:57:46 +++ //depot/jhb/ipmi/sys/kern/subr_bus.c 2006/08/25 10:08:08 @@ -2829,6 +2829,13 @@ } } +device_t +bus_generic_add_child(device_t dev, int order, const char *name, int unit) +{ + + return (device_add_child_ordered(dev, order, name, unit)); +} + /** * @brief Helper function for implementing DEVICE_PROBE() * --- //depot/yahoo/ybsd_6/src/sys/pci/alpm.c 2005/06/04 00:22:47 +++ //depot/jhb/ipmi/sys/pci/alpm.c 2006/08/30 11:22:28 @@ -259,7 +259,7 @@ } static int -alpm_callback(device_t dev, int index, caddr_t *data) +alpm_callback(device_t dev, int index, void *data) { int error = 0; @@ -525,82 +525,76 @@ alpm_bwrite(device_t dev, u_char slave, char cmd, u_char count, char *buf) { struct alpm_softc *sc = (struct alpm_softc *)device_get_softc(dev); - u_char remain, len, i; - int error = SMB_ENOERR; + u_char i; + int error; + if (count < 1 || count > 32) + return (EINVAL); alpm_clear(sc); if(!alpm_idle(sc)) return (SMB_EBUSY); - remain = count; - while (remain) { - len = min(remain, 32); - - ALPM_SMBOUTB(sc, SMBHADDR, slave & ~LSB); + ALPM_SMBOUTB(sc, SMBHADDR, slave & ~LSB); - /* set the cmd and reset the - * 32-byte long internal buffer */ - ALPM_SMBOUTB(sc, SMBCMD, SMBWRBLOCK | SMB_BLK_CLR); + /* set the cmd and reset the + * 32-byte long internal buffer */ + ALPM_SMBOUTB(sc, SMBCMD, SMBWRBLOCK | SMB_BLK_CLR); - ALPM_SMBOUTB(sc, SMBHDATA, len); + ALPM_SMBOUTB(sc, SMBHDATA, count); - /* fill the 32-byte internal buffer */ - for (i=0; i 32) + return (EINVAL); alpm_clear(sc); if (!alpm_idle(sc)) return (SMB_EBUSY); - remain = count; - while (remain) { - ALPM_SMBOUTB(sc, SMBHADDR, slave | LSB); + ALPM_SMBOUTB(sc, SMBHADDR, slave | LSB); - /* set the cmd and reset the - * 32-byte long internal buffer */ - ALPM_SMBOUTB(sc, SMBCMD, SMBWRBLOCK | SMB_BLK_CLR); + /* set the cmd and reset the + * 32-byte long internal buffer */ + ALPM_SMBOUTB(sc, SMBCMD, SMBWRBLOCK | SMB_BLK_CLR); - ALPM_SMBOUTB(sc, SMBHCMD, cmd); - ALPM_SMBOUTB(sc, SMBSTART, 0xff); + ALPM_SMBOUTB(sc, SMBHCMD, cmd); + ALPM_SMBOUTB(sc, SMBSTART, 0xff); - if ((error = alpm_wait(sc)) != SMB_ENOERR) + if ((error = alpm_wait(sc)) != SMB_ENOERR) goto error; - len = ALPM_SMBINB(sc, SMBHDATA); + len = ALPM_SMBINB(sc, SMBHDATA); - /* read the 32-byte internal buffer */ - for (i=0; i 32) + return (EINVAL); amdpm_clear(sc); if(!amdpm_idle(sc)) return (SMB_EBUSY); - remain = count; - while (remain) { - len = min(remain, 32); - - AMDPM_SMBOUTW(sc, AMDSMB_HSTADDR, slave & ~LSB); + AMDPM_SMBOUTW(sc, AMDSMB_HSTADDR, slave & ~LSB); - /* - * Do we have to reset the internal 32-byte buffer? - * Can't see how to do this from the data sheet. - */ + /* + * Do we have to reset the internal 32-byte buffer? + * Can't see how to do this from the data sheet. + */ + AMDPM_SMBOUTW(sc, AMDSMB_HSTDATA, count); - AMDPM_SMBOUTW(sc, AMDSMB_HSTDATA, len); + /* Fill the 32-byte internal buffer */ + for (i = 0; i < count; i++) { + AMDPM_SMBOUTB(sc, AMDSMB_HSTDFIFO, buf[i]); + DELAY(2); + } + AMDPM_SMBOUTB(sc, AMDSMB_HSTCMD, cmd); + l = AMDPM_SMBINW(sc, AMDSMB_GLOBAL_ENABLE); + AMDPM_SMBOUTW(sc, AMDSMB_GLOBAL_ENABLE, + (l & 0xfff8) | AMDSMB_GE_CYC_BLOCK | AMDSMB_GE_HOST_STC); - /* Fill the 32-byte internal buffer */ - for (i=0; i 32) + return (EINVAL); amdpm_clear(sc); if (!amdpm_idle(sc)) return (SMB_EBUSY); - remain = count; - while (remain) { - AMDPM_SMBOUTW(sc, AMDSMB_HSTADDR, slave | LSB); + AMDPM_SMBOUTW(sc, AMDSMB_HSTADDR, slave | LSB); - AMDPM_SMBOUTB(sc, AMDSMB_HSTCMD, cmd); + AMDPM_SMBOUTB(sc, AMDSMB_HSTCMD, cmd); - l = AMDPM_SMBINW(sc, AMDSMB_GLOBAL_ENABLE); - AMDPM_SMBOUTW(sc, AMDSMB_GLOBAL_ENABLE, (l & 0xfff8) | AMDSMB_GE_CYC_BLOCK | AMDSMB_GE_HOST_STC); + l = AMDPM_SMBINW(sc, AMDSMB_GLOBAL_ENABLE); + AMDPM_SMBOUTW(sc, AMDSMB_GLOBAL_ENABLE, + (l & 0xfff8) | AMDSMB_GE_CYC_BLOCK | AMDSMB_GE_HOST_STC); - if ((error = amdpm_wait(sc)) != SMB_ENOERR) - goto error; + if ((error = amdpm_wait(sc)) != SMB_ENOERR) + goto error; - len = AMDPM_SMBINW(sc, AMDSMB_HSTDATA); + len = AMDPM_SMBINW(sc, AMDSMB_HSTDATA); - /* Read the 32-byte internal buffer */ - for (i=0; i 32) + return (EINVAL); amdsmb_ec_write(sc, SMB_CMD, cmd); - amdsmb_ec_write(sc, SMB_BCNT, len); - for (i = 0; i < len; i++) + amdsmb_ec_write(sc, SMB_BCNT, count); + for (i = 0; i < count; i++) amdsmb_ec_write(sc, SMB_DATA + i, buf[i]); amdsmb_ec_write(sc, SMB_ADDR, slave); amdsmb_ec_write(sc, SMB_PRTCL, SMB_PRTCL_WRITE | SMB_PRTCL_BLOCK_DATA); @@ -464,10 +465,10 @@ } static int -amdsmb_bread(device_t dev, u_char slave, char cmd, u_char count, char *buf) +amdsmb_bread(device_t dev, u_char slave, char cmd, u_char *count, char *buf) { struct amdsmb_softc *sc = (struct amdsmb_softc *)device_get_softc(dev); - u_char len, i; + u_char data, len, i; int error; amdsmb_ec_write(sc, SMB_CMD, cmd); @@ -476,13 +477,16 @@ if ((error = amdsmb_wait(sc)) == SMB_ENOERR) { amdsmb_ec_read(sc, SMB_BCNT, &len); - len = min(len, 32); - for (i = 0; i < len; i++) - amdsmb_ec_read(sc, SMB_DATA + i, buf + i); + for (i = 0; i < len; i++) { + amdsmb_ec_read(sc, SMB_DATA + i, &data); + if (i < *count) + buf[i] = data; + } + *count = len; } AMDSMB_DEBUG(printf("amdsmb: READBLK to 0x%x, count=0x%x, cmd=0x%x, " - "error=0x%x", slave, count, cmd, error)); + "error=0x%x", slave, *count, cmd, error)); return (error); } @@ -517,6 +521,7 @@ }; DRIVER_MODULE(amdsmb, pci, amdsmb_driver, amdsmb_devclass, 0, 0); +DRIVER_MODULE(smbus, amdsmb, smbus_driver, smbus_devclass, 0, 0); MODULE_DEPEND(amdsmb, pci, 1, 1, 1); MODULE_DEPEND(amdsmb, smbus, SMBUS_MINVER, SMBUS_PREFVER, SMBUS_MAXVER); --- //depot/yahoo/ybsd_6/src/sys/pci/intpm.c 2005/06/04 00:22:47 +++ //depot/jhb/ipmi/sys/pci/intpm.c 2006/08/30 11:22:28 @@ -71,7 +71,7 @@ static int intsmb_intr(device_t dev); static int intsmb_slvintr(device_t dev); static void intsmb_alrintr(device_t dev); -static int intsmb_callback(device_t dev, int index, caddr_t data); +static int intsmb_callback(device_t dev, int index, void *data); static int intsmb_quick(device_t dev, u_char slave, int how); static int intsmb_sendb(device_t dev, u_char slave, char byte); static int intsmb_recvb(device_t dev, u_char slave, char *byte); @@ -81,7 +81,7 @@ static int intsmb_readw(device_t dev, u_char slave, char cmd, short *word); static int intsmb_pcall(device_t dev, u_char slave, char cmd, short sdata, short *rdata); static int intsmb_bwrite(device_t dev, u_char slave, char cmd, u_char count, char *buf); -static int intsmb_bread(device_t dev, u_char slave, char cmd, u_char count, char *buf); +static int intsmb_bread(device_t dev, u_char slave, char cmd, u_char *count, char *buf); static void intsmb_start(device_t dev,u_char cmd,int nointr); static int intsmb_stop(device_t dev); static int intsmb_stop_poll(device_t dev); @@ -175,7 +175,7 @@ } static int -intsmb_callback(device_t dev, int index, caddr_t data) +intsmb_callback(device_t dev, int index, void *data) { int error = 0; intrmask_t s; @@ -603,12 +603,13 @@ } static int -intsmb_bread(device_t dev, u_char slave, char cmd, u_char count, char *buf) +intsmb_bread(device_t dev, u_char slave, char cmd, u_char *count, char *buf) { int error,i; + u_char data, nread; struct intsmb_softc *sc = (struct intsmb_softc *)device_get_softc(dev); error=intsmb_free(dev); - if(count>SMBBLOCKTRANS_MAX||count==0) + if(*count>SMBBLOCKTRANS_MAX||*count==0) error=EINVAL; if(!error){ /*Reset internal array index*/ @@ -616,19 +617,21 @@ bus_space_write_1(sc->st,sc->sh,PIIX4_SMBHSTADD,slave|LSB); bus_space_write_1(sc->st,sc->sh,PIIX4_SMBHSTCMD,cmd); - bus_space_write_1(sc->st,sc->sh,PIIX4_SMBHSTDAT0,count); + bus_space_write_1(sc->st,sc->sh,PIIX4_SMBHSTDAT0,*count); intsmb_start(dev,PIIX4_SMBHSTCNT_PROT_BLOCK,0); error=intsmb_stop(dev); if(!error){ - bzero(buf,count);/*Is it needed?*/ - count= bus_space_read_1(sc->st,sc->sh, + nread= bus_space_read_1(sc->st,sc->sh, PIIX4_SMBHSTDAT0); - if(count!=0&&count<=SMBBLOCKTRANS_MAX){ - for(i=0;ist, + if(nread!=0&&nread<=SMBBLOCKTRANS_MAX){ + for(i=0;ist, sc->sh, PIIX4_SMBBLKDAT); + if (i < *count) + buf[i] = data; } + *count = nread; } else{ error=EIO; @@ -739,6 +742,7 @@ } } DRIVER_MODULE(intpm, pci , intpm_pci_driver, intpm_devclass, 0, 0); +DRIVER_MODULE(smbus, intsmb, smbus_driver, smbus_devclass, 0, 0); MODULE_DEPEND(intpm, smbus, SMBUS_MINVER, SMBUS_PREFVER, SMBUS_MAXVER); MODULE_VERSION(intpm, 1); --- //depot/yahoo/ybsd_6/src/sys/pci/nfsmb.c 2006/08/24 10:57:46 +++ //depot/jhb/ipmi/sys/pci/nfsmb.c 2006/08/30 11:22:28 @@ -243,7 +243,7 @@ } static int -nfsmb_callback(device_t dev, int index, caddr_t *data) +nfsmb_callback(device_t dev, int index, void *data) { int error = 0; @@ -447,13 +447,14 @@ nfsmb_bwrite(device_t dev, u_char slave, char cmd, u_char count, char *buf) { struct nfsmb_softc *sc = (struct nfsmb_softc *)device_get_softc(dev); - u_char len, i; + u_char i; int error; - len = min(count, 32); + if (count < 1 || count > 32) + return (EINVAL); NFSMB_SMBOUTB(sc, SMB_CMD, cmd); - NFSMB_SMBOUTB(sc, SMB_BCNT, len); - for (i = 0; i < len; i++) + NFSMB_SMBOUTB(sc, SMB_BCNT, count); + for (i = 0; i < count; i++) NFSMB_SMBOUTB(sc, SMB_DATA + i, buf[i]); NFSMB_SMBOUTB(sc, SMB_ADDR, slave); NFSMB_SMBOUTB(sc, SMB_PRTCL, SMB_PRTCL_WRITE | SMB_PRTCL_BLOCK_DATA); @@ -466,24 +467,29 @@ } static int -nfsmb_bread(device_t dev, u_char slave, char cmd, u_char count, char *buf) +nfsmb_bread(device_t dev, u_char slave, char cmd, u_char *count, char *buf) { struct nfsmb_softc *sc = (struct nfsmb_softc *)device_get_softc(dev); - u_char len, i; + u_char data, len, i; int error; + if (*count < 1 || *count > 32) + return (EINVAL); NFSMB_SMBOUTB(sc, SMB_CMD, cmd); NFSMB_SMBOUTB(sc, SMB_ADDR, slave); NFSMB_SMBOUTB(sc, SMB_PRTCL, SMB_PRTCL_READ | SMB_PRTCL_BLOCK_DATA); if ((error = nfsmb_wait(sc)) == SMB_ENOERR) { len = NFSMB_SMBINB(sc, SMB_BCNT); - len = min(len, 32); - for (i = 0; i < len; i++) - buf[i] = NFSMB_SMBINB(sc, SMB_DATA + i); + for (i = 0; i < len; i++) { + data = NFSMB_SMBINB(sc, SMB_DATA + i); + if (i < *count) + buf[i] = data; + } + *count = len; } - NFSMB_DEBUG(printf("nfsmb: READBLK to 0x%x, count=0x%x, cmd=0x%x, error=0x%x", slave, count, cmd, error)); + NFSMB_DEBUG(printf("nfsmb: READBLK to 0x%x, count=0x%x, cmd=0x%x, error=0x%x", slave, *count, cmd, error)); return (error); } @@ -546,6 +552,7 @@ DRIVER_MODULE(nfsmb, pci, nfsmb_driver, nfsmb_devclass, 0, 0); DRIVER_MODULE(nfsmb, nfsmb, nfsmbsub_driver, nfsmb_devclass, 0, 0); +DRIVER_MODULE(smbus, nfsmb, smbus_driver, smbus_devclass, 0, 0); MODULE_DEPEND(nfsmb, pci, 1, 1, 1); MODULE_DEPEND(nfsmb, smbus, SMBUS_MINVER, SMBUS_PREFVER, SMBUS_MAXVER); --- //depot/yahoo/ybsd_6/src/sys/pci/viapm.c 2005/11/08 23:06:59 +++ //depot/jhb/ipmi/sys/pci/viapm.c 2006/08/30 10:55:48 @@ -809,37 +809,31 @@ viasmb_bwrite(device_t dev, u_char slave, char cmd, u_char count, char *buf) { struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev); - u_char remain, len, i; - int error = SMB_ENOERR; + u_char i; + int error; + + if (count < 1 || count > 32) + return (EINVAL); viapm_clear(viapm); if (viapm_busy(viapm)) return (EBUSY); - remain = count; - while (remain) { - len = min(remain, 32); + VIAPM_OUTB(SMBHADDR, slave & ~LSB); + VIAPM_OUTB(SMBHCMD, cmd); + VIAPM_OUTB(SMBHDATA0, count); + i = VIAPM_INB(SMBHCTRL); - VIAPM_OUTB(SMBHADDR, slave & ~LSB); - VIAPM_OUTB(SMBHCMD, cmd); - VIAPM_OUTB(SMBHDATA0, len); - i = VIAPM_INB(SMBHCTRL); + /* fill the 32-byte internal buffer */ + for (i = 0; i < count; i++) { + VIAPM_OUTB(SMBHBLOCK, buf[i]); + DELAY(2); + } + VIAPM_OUTB(SMBHCMD, cmd); + VIAPM_OUTB(SMBHCTRL, SMBHCTRL_START | SMBHCTRL_BLOCK); - /* fill the 32-byte internal buffer */ - for (i=0; i 32) + return (EINVAL); viapm_clear(viapm); if (viapm_busy(viapm)) return (EBUSY); - remain = count; - while (remain) { - VIAPM_OUTB(SMBHADDR, slave | LSB); - VIAPM_OUTB(SMBHCMD, cmd); - VIAPM_OUTB(SMBHCTRL, SMBHCTRL_START | SMBHCTRL_BLOCK); + VIAPM_OUTB(SMBHADDR, slave | LSB); + VIAPM_OUTB(SMBHCMD, cmd); + VIAPM_OUTB(SMBHCTRL, SMBHCTRL_START | SMBHCTRL_BLOCK); - if ((error = viapm_wait(viapm)) != SMB_ENOERR) - goto error; + if ((error = viapm_wait(viapm)) != SMB_ENOERR) + goto error; - len = VIAPM_INB(SMBHDATA0); - i = VIAPM_INB(SMBHCTRL); /* reset counter */ + len = VIAPM_INB(SMBHDATA0); + i = VIAPM_INB(SMBHCTRL); /* reset counter */ - len = min(len, remain); + /* read the 32-byte internal buffer */ + for (i = 0; i < len; i++) { + data = VIAPM_INB(SMBHBLOCK); + if (i < *count) + buf[i] = data; + DELAY(2); + } + *count = len; - /* read the 32-byte internal buffer */ - for (i=0; i