diff options
author | jhb <jhb@FreeBSD.org> | 2006-09-11 20:52:41 +0000 |
---|---|---|
committer | jhb <jhb@FreeBSD.org> | 2006-09-11 20:52:41 +0000 |
commit | 375fa0aa41b95aca6b081230c5f17725b9dcc893 (patch) | |
tree | 724ede4fc106e1f96720180f84383d44d174e12d /sys/pci/viapm.c | |
parent | 35312a59c3883c9be486aa033b2e5d025e9ab07c (diff) | |
download | FreeBSD-src-375fa0aa41b95aca6b081230c5f17725b9dcc893.zip FreeBSD-src-375fa0aa41b95aca6b081230c5f17725b9dcc893.tar.gz |
Minor overhaul of SMBus support:
- Change smbus_callback() to pass a void * rather than caddr_t.
- Change smbus_bread() to pass a pointer to the count and have it be an
in/out parameter. The input is the size of the buffer (same as before),
but on return it will contain the actual amount of data read back from
the bus. Note that this value may be larger than the input value. It
is up to the caller to treat this as an error if desired.
- Change the SMB_BREAD ioctl to write out the updated struct smbcmd which
will contain the actual number of bytes read in the 'count' field. To
preserve the previous ABI, the old ioctl value is mapped to SMB_OLD_BREAD
which doesn't copy the updated smbcmd back out to userland. I doubt anyone
actually used the old BREAD anyway as it was rediculous to do a bulk-read
but not tell the using program how much data was actually read.
- Make the smbus driver and devclass public in the smbus module and
push all the DRIVER_MODULE()'s for attaching the smbus driver to
various foosmb drivers out into the foosmb modules. This makes all
the foosmb logic centralized and allows new foosmb modules to be
self-contained w/o having to hack smbus.c everytime a new smbus driver
is added.
- Add a new SMB_EINVAL error bit and use it in place of EINVAL to return
an error for bad arguments (such as invalid counts for bread and bwrite).
- Map SMB bus error bits to EIO in smbus_error().
- Make the smbus driver call bus_generic_probe() and require child drivers
such as smb(4) to create device_t's via identify routines. Previously,
smbus just created one anonymous device during attach, and if you had
multiple drivers that could attach it was just random chance as to which
driver got to probe for the sole device_t first.
- Add a mutex to the smbus(4) softc and use it in place of dummy splhigh()
to protect the 'owner' field and perform necessary synchronization for
smbus_request_bus() and smbus_release_bus().
- Change the bread() and bwrite() methods of alpm(4), amdpm(4), and
viapm(4) to only perform a single transaction and not try to use a
loop of multiple transactions for a large request. The framing and
commands to use for a large transaction depend on the upper-layer
protocol (such as SSIF for IPMI over SMBus) from what I can tell, and the
smb(4) driver never allowed bulk read/writes of more than 32-bytes
anyway. The other smb drivers only performed single transactions.
- Fix buffer overflows in the bread() methods of ichsmb(4), alpm(4),
amdpm(4), amdsmb(4), intpm(4), and nfsmb(4).
- Use SMB_xxx errors in viapm(4).
- Destroy ichsmb(4)'s mutex after bus_generic_detach() to avoid problems
from child devices making smb upcalls that would use the mutex during
their detach methods.
MFC after: 1 week
Reviewed by: jmg (mostly)
Diffstat (limited to 'sys/pci/viapm.c')
-rw-r--r-- | sys/pci/viapm.c | 103 |
1 files changed, 49 insertions, 54 deletions
diff --git a/sys/pci/viapm.c b/sys/pci/viapm.c index 0bddb22..a26703e 100644 --- a/sys/pci/viapm.c +++ b/sys/pci/viapm.c @@ -640,7 +640,7 @@ viasmb_quick(device_t dev, u_char slave, int how) viapm_clear(viapm); if (viapm_busy(viapm)) - return (EBUSY); + return (SMB_EBUSY); switch (how) { case SMB_QWRITE: @@ -670,7 +670,7 @@ viasmb_sendb(device_t dev, u_char slave, char byte) viapm_clear(viapm); if (viapm_busy(viapm)) - return (EBUSY); + return (SMB_EBUSY); VIAPM_OUTB(SMBHADDR, slave & ~ LSB); VIAPM_OUTB(SMBHCMD, byte); @@ -692,7 +692,7 @@ viasmb_recvb(device_t dev, u_char slave, char *byte) viapm_clear(viapm); if (viapm_busy(viapm)) - return (EBUSY); + return (SMB_EBUSY); VIAPM_OUTB(SMBHADDR, slave | LSB); @@ -714,7 +714,7 @@ viasmb_writeb(device_t dev, u_char slave, char cmd, char byte) viapm_clear(viapm); if (viapm_busy(viapm)) - return (EBUSY); + return (SMB_EBUSY); VIAPM_OUTB(SMBHADDR, slave & ~ LSB); VIAPM_OUTB(SMBHCMD, cmd); @@ -737,7 +737,7 @@ viasmb_readb(device_t dev, u_char slave, char cmd, char *byte) viapm_clear(viapm); if (viapm_busy(viapm)) - return (EBUSY); + return (SMB_EBUSY); VIAPM_OUTB(SMBHADDR, slave | LSB); VIAPM_OUTB(SMBHCMD, cmd); @@ -760,7 +760,7 @@ viasmb_writew(device_t dev, u_char slave, char cmd, short word) viapm_clear(viapm); if (viapm_busy(viapm)) - return (EBUSY); + return (SMB_EBUSY); VIAPM_OUTB(SMBHADDR, slave & ~ LSB); VIAPM_OUTB(SMBHCMD, cmd); @@ -785,7 +785,7 @@ viasmb_readw(device_t dev, u_char slave, char cmd, short *word) viapm_clear(viapm); if (viapm_busy(viapm)) - return (EBUSY); + return (SMB_EBUSY); VIAPM_OUTB(SMBHADDR, slave | LSB); VIAPM_OUTB(SMBHCMD, cmd); @@ -808,37 +808,31 @@ static int 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 (SMB_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, len); - i = VIAPM_INB(SMBHCTRL); - - /* fill the 32-byte internal buffer */ - for (i=0; i<len; i++) { - VIAPM_OUTB(SMBHBLOCK, buf[count-remain+i]); - DELAY(2); - } - VIAPM_OUTB(SMBHCMD, cmd); - VIAPM_OUTB(SMBHCTRL, SMBHCTRL_START | SMBHCTRL_BLOCK); + return (SMB_EBUSY); - if ((error = viapm_wait(viapm)) != SMB_ENOERR) - goto error; + VIAPM_OUTB(SMBHADDR, slave & ~LSB); + VIAPM_OUTB(SMBHCMD, cmd); + VIAPM_OUTB(SMBHDATA0, count); + i = VIAPM_INB(SMBHCTRL); - remain -= len; + /* 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); + + error = viapm_wait(viapm); -error: VIAPM_DEBUG(printf("viapm: WRITEBLK to 0x%x, count=0x%x, cmd=0x%x, error=0x%x", slave, count, cmd, error)); return (error); @@ -846,40 +840,40 @@ error: } static int -viasmb_bread(device_t dev, u_char slave, char cmd, u_char count, char *buf) +viasmb_bread(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 data, len, i; + int error; + + if (*count < 1 || *count > 32) + return (SMB_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); - - if ((error = viapm_wait(viapm)) != SMB_ENOERR) - goto error; + return (SMB_EBUSY); - len = VIAPM_INB(SMBHDATA0); - i = VIAPM_INB(SMBHCTRL); /* reset counter */ + VIAPM_OUTB(SMBHADDR, slave | LSB); + VIAPM_OUTB(SMBHCMD, cmd); + VIAPM_OUTB(SMBHCTRL, SMBHCTRL_START | SMBHCTRL_BLOCK); - len = min(len, remain); + if ((error = viapm_wait(viapm)) != SMB_ENOERR) + goto error; - /* read the 32-byte internal buffer */ - for (i=0; i<len; i++) { - buf[count-remain+i] = VIAPM_INB(SMBHBLOCK); - DELAY(2); - } + len = VIAPM_INB(SMBHDATA0); + i = VIAPM_INB(SMBHCTRL); /* reset counter */ - remain -= len; + /* 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; + error: - VIAPM_DEBUG(printf("viapm: READBLK to 0x%x, count=0x%x, cmd=0x%x, error=0x%x", slave, count, cmd, error)); + VIAPM_DEBUG(printf("viapm: READBLK to 0x%x, count=0x%x, cmd=0x%x, error=0x%x", slave, *count, cmd, error)); return (error); } @@ -954,6 +948,7 @@ static driver_t viapropm_driver = { DRIVER_MODULE(viapm, pci, viapm_driver, viapm_devclass, 0, 0); DRIVER_MODULE(viapropm, pci, viapropm_driver, viapropm_devclass, 0, 0); +DRIVER_MODULE(smbus, viapropm, smbus_driver, smbus_devclass, 0, 0); MODULE_DEPEND(viapm, pci, 1, 1, 1); MODULE_DEPEND(viapropm, pci, 1, 1, 1); |