diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2019-09-24 11:05:03 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2019-11-13 10:47:04 +0100 |
commit | a5ddb0ea69f21c16b7697a935d7a0c16bb3cffcf (patch) | |
tree | db091fb0f7d091804482156c9f3f55879ac93d5b /freebsd/sys/dev/iicbus/iiconf.c | |
parent | test/syscalls01: Fix sporadic test failures (diff) | |
download | rtems-libbsd-a5ddb0ea69f21c16b7697a935d7a0c16bb3cffcf.tar.bz2 |
Update to FreeBSD head 2019-09-24
Git mirror commit 6b0307a0a5184339393f555d5d424190d8a8277a.
Diffstat (limited to 'freebsd/sys/dev/iicbus/iiconf.c')
-rw-r--r-- | freebsd/sys/dev/iicbus/iiconf.c | 55 |
1 files changed, 47 insertions, 8 deletions
diff --git a/freebsd/sys/dev/iicbus/iiconf.c b/freebsd/sys/dev/iicbus/iiconf.c index afdce118..c4926852 100644 --- a/freebsd/sys/dev/iicbus/iiconf.c +++ b/freebsd/sys/dev/iicbus/iiconf.c @@ -44,6 +44,18 @@ __FBSDID("$FreeBSD$"); #include <rtems/bsd/local/iicbus_if.h> /* + * Encode a system errno value into the IIC_Exxxxx space by setting the + * IIC_ERRNO marker bit, so that iic2errno() can turn it back into a plain + * system errno value later. This lets controller- and bus-layer code get + * important system errno values (such as EINTR/ERESTART) back to the caller. + */ +int +errno2iic(int error) +{ + return ((error == 0) ? 0 : error | IIC_ERRNO); +} + +/* * Translate IIC_Exxxxx status values to vaguely-equivelent errno values. */ int @@ -61,7 +73,22 @@ iic2errno(int iic_status) case IIC_ENOTSUPP: return (EOPNOTSUPP); case IIC_ENOADDR: return (EADDRNOTAVAIL); case IIC_ERESOURCE: return (ENOMEM); - default: return (EIO); + default: + /* + * If the high bit is set, that means it's a system errno value + * that was encoded into the IIC_Exxxxxx space by setting the + * IIC_ERRNO marker bit. If lots of high-order bits are set, + * then it's one of the negative pseudo-errors such as ERESTART + * and we return it as-is. Otherwise it's a plain "small + * positive integer" errno, so just remove the IIC_ERRNO marker + * bit. If it's some unknown number without the high bit set, + * there isn't much we can do except call it an I/O error. + */ + if ((iic_status & IIC_ERRNO) == 0) + return (EIO); + if ((iic_status & 0xFFFF0000) != 0) + return (iic_status); + return (iic_status & ~IIC_ERRNO); } } @@ -99,7 +126,7 @@ iicbus_poll(struct iicbus_softc *sc, int how) return (IIC_EBUSBSY); } - return (error); + return (errno2iic(error)); } /* @@ -130,6 +157,18 @@ iicbus_request_bus(device_t bus, device_t dev, int how) ++sc->owncount; if (sc->owner == NULL) { sc->owner = dev; + /* + * Mark the device busy while it owns the bus, to + * prevent detaching the device, bus, or hardware + * controller, until ownership is relinquished. If the + * device is doing IO from its probe method before + * attaching, it cannot be busied; mark the bus busy. + */ + if (device_get_state(dev) < DS_ATTACHING) + sc->busydev = bus; + else + sc->busydev = dev; + device_busy(sc->busydev); /* * Drop the lock around the call to the bus driver, it * should be allowed to sleep in the IIC_WAIT case. @@ -146,6 +185,7 @@ iicbus_request_bus(device_t bus, device_t dev, int how) sc->owner = NULL; sc->owncount = 0; wakeup_one(sc); + device_unbusy(sc->busydev); } } } @@ -179,6 +219,7 @@ iicbus_release_bus(device_t bus, device_t dev) IICBUS_LOCK(sc); sc->owner = NULL; wakeup_one(sc); + device_unbusy(sc->busydev); } IICBUS_UNLOCK(sc); return (0); @@ -422,7 +463,7 @@ iicbus_transfer_gen(device_t dev, struct iic_msg *msgs, uint32_t nmsgs) { int i, error, lenread, lenwrote, nkid, rpstart, addr; device_t *children, bus; - bool nostop, started; + bool started; if ((error = device_get_children(dev, &children, &nkid)) != 0) return (IIC_ERESOURCE); @@ -433,7 +474,6 @@ iicbus_transfer_gen(device_t dev, struct iic_msg *msgs, uint32_t nmsgs) bus = children[0]; rpstart = 0; free(children, M_TEMP); - nostop = iicbus_get_nostop(dev); started = false; for (i = 0, error = 0; i < nmsgs && error == 0; i++) { addr = msgs[i].slave; @@ -461,12 +501,11 @@ iicbus_transfer_gen(device_t dev, struct iic_msg *msgs, uint32_t nmsgs) if (error != 0) break; - if ((msgs[i].flags & IIC_M_NOSTOP) != 0 || - (nostop && i + 1 < nmsgs)) { - rpstart = 1; /* Next message gets repeated start */ - } else { + if (!(msgs[i].flags & IIC_M_NOSTOP)) { rpstart = 0; iicbus_stop(bus); + } else { + rpstart = 1; /* Next message gets repeated start */ } } if (error != 0 && started) |