diff options
author | nsouch <nsouch@FreeBSD.org> | 1999-02-14 14:36:45 +0000 |
---|---|---|
committer | nsouch <nsouch@FreeBSD.org> | 1999-02-14 14:36:45 +0000 |
commit | c30e87e63a89b1265197a2373650e258bde477cb (patch) | |
tree | 9dec0e73166f7d2f4228b06248993048dc3e0467 | |
parent | fe07f4870451301093bcd9d4d6049f9482f65331 (diff) | |
download | FreeBSD-src-c30e87e63a89b1265197a2373650e258bde477cb.zip FreeBSD-src-c30e87e63a89b1265197a2373650e258bde477cb.tar.gz |
Return approriate errors to userland.
-rw-r--r-- | sys/dev/smbus/smb.c | 39 | ||||
-rw-r--r-- | sys/dev/smbus/smbconf.c | 30 | ||||
-rw-r--r-- | 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 a26f3fa..cfb6f0e 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 <sys/param.h> @@ -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 1e7d8c4..59c105c 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 <sys/param.h> @@ -53,6 +53,34 @@ smbus_intr(device_t bus, u_char devaddr, char low, char high, int error) } /* + * 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() * * Allocate a new bus connected to the given parent device diff --git a/sys/dev/smbus/smbconf.h b/sys/dev/smbus/smbconf.h index c5fca85..c260de4 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); |