From 4012f363f2d0e01549aff0c76ab1ee00a52b985b Mon Sep 17 00:00:00 2001 From: Nicolas Souchu Date: Sun, 14 Feb 1999 14:36:45 +0000 Subject: [PATCH] Return approriate errors to userland. --- sys/dev/smbus/smb.c | 39 +++++++++++++++++++++------------------ sys/dev/smbus/smbconf.c | 30 +++++++++++++++++++++++++++++- sys/dev/smbus/smbconf.h | 3 ++- 3 files changed, 52 insertions(+), 20 deletions(-) diff --git a/sys/dev/smbus/smb.c b/sys/dev/smbus/smb.c index a26f3fa3b6a6..cfb6f0ead0b2 100644 --- a/sys/dev/smbus/smb.c +++ b/sys/dev/smbus/smb.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: smb.c,v 1.6 1999/01/14 22:55:03 nsouch Exp $ + * $Id: smb.c,v 1.7 1999/02/13 17:57:19 nsouch Exp $ * */ #include @@ -160,7 +160,7 @@ smbwrite(dev_t dev, struct uio * uio, int ioflag) { /* not supported */ - return (EINVAL); + return (ENODEV); } static int @@ -168,7 +168,7 @@ smbread(dev_t dev, struct uio * uio, int ioflag) { /* not supported */ - return (EINVAL); + return (ENODEV); } static int @@ -191,56 +191,59 @@ smbioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct proc *p) switch (cmd) { case SMB_QUICK_WRITE: - error=smbus_quick(parent, s->slave, SMB_QWRITE); + error = smbus_error(smbus_quick(parent, s->slave, SMB_QWRITE)); break; case SMB_QUICK_READ: - error=smbus_quick(parent, s->slave, SMB_QREAD); + error = smbus_error(smbus_quick(parent, s->slave, SMB_QREAD)); break; case SMB_SENDB: - error=smbus_sendb(parent, s->slave, s->cmd); + error = smbus_error(smbus_sendb(parent, s->slave, s->cmd)); break; case SMB_RECVB: - error=smbus_recvb(parent, s->slave, &s->cmd); + error = smbus_error(smbus_recvb(parent, s->slave, &s->cmd)); break; case SMB_WRITEB: - error=smbus_writeb(parent, s->slave, s->cmd, s->data.byte); + error = smbus_error(smbus_writeb(parent, s->slave, s->cmd, + s->data.byte)); break; case SMB_WRITEW: - error=smbus_writew(parent, s->slave, s->cmd, s->data.word); + error = smbus_error(smbus_writew(parent, s->slave, + s->cmd, s->data.word)); break; case SMB_READB: if (s->data.byte_ptr) - error=smbus_readb(parent, s->slave, s->cmd, - s->data.byte_ptr); + error = smbus_error(smbus_readb(parent, s->slave, + s->cmd, s->data.byte_ptr)); break; case SMB_READW: if (s->data.word_ptr) - error=smbus_readw(parent, s->slave, s->cmd, s->data.word_ptr); + error = smbus_error(smbus_readw(parent, s->slave, + s->cmd, s->data.word_ptr)); break; case SMB_PCALL: if (s->data.process.rdata) - error=smbus_pcall(parent, s->slave, s->cmd, - s->data.process.sdata, s->data.process.rdata); + error = smbus_error(smbus_pcall(parent, s->slave, s->cmd, + s->data.process.sdata, s->data.process.rdata)); break; case SMB_BWRITE: if (s->count && s->data.byte_ptr) - error=smbus_bwrite(parent, s->slave, s->cmd, s->count, - s->data.byte_ptr); + error = smbus_error(smbus_bwrite(parent, s->slave, + s->cmd, s->count, s->data.byte_ptr)); break; case SMB_BREAD: if (s->count && s->data.byte_ptr) - error=smbus_bread(parent, s->slave, s->cmd, s->count, - s->data.byte_ptr); + error = smbus_error(smbus_bread(parent, s->slave, + s->cmd, s->count, s->data.byte_ptr)); break; default: diff --git a/sys/dev/smbus/smbconf.c b/sys/dev/smbus/smbconf.c index 1e7d8c4a90a9..59c105c325c7 100644 --- a/sys/dev/smbus/smbconf.c +++ b/sys/dev/smbus/smbconf.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: smbconf.c,v 1.4 1999/01/09 18:08:23 nsouch Exp $ + * $Id: smbconf.c,v 1.5 1999/02/13 17:57:19 nsouch Exp $ * */ #include @@ -52,6 +52,34 @@ smbus_intr(device_t bus, u_char devaddr, char low, char high, int error) return; } +/* + * smbus_error() + * + * Converts an smbus error to a unix error. + */ +int +smbus_error(int smb_error) +{ + int error = 0; + + if (smb_error == SMB_ENOERR) + return (0); + + if (smb_error & (SMB_ENOTSUPP)) { + error = ENODEV; + } else if (smb_error & (SMB_ENOACK)) { + error = ENXIO; + } else if (smb_error & (SMB_ETIMEOUT)) { + error = EWOULDBLOCK; + } else if (smb_error & (SMB_EBUSY)) { + error = EBUSY; + } else { + error = EINVAL; + } + + return (error); +} + /* * smbus_alloc_bus() * diff --git a/sys/dev/smbus/smbconf.h b/sys/dev/smbus/smbconf.h index c5fca8503498..c260de4f8625 100644 --- a/sys/dev/smbus/smbconf.h +++ b/sys/dev/smbus/smbconf.h @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: smbconf.h,v 1.3 1999/01/27 19:58:53 dillon Exp $ + * $Id: smbconf.h,v 1.4 1999/02/13 17:57:19 nsouch Exp $ */ #ifndef __SMBONF_H #define __SMBONF_H @@ -74,6 +74,7 @@ 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); extern void smbus_intr(device_t, u_char, char low, char high, int error);