diff options
author | jhb <jhb@FreeBSD.org> | 2009-01-21 23:10:06 +0000 |
---|---|---|
committer | jhb <jhb@FreeBSD.org> | 2009-01-21 23:10:06 +0000 |
commit | 879505d4df9b978295c6bf69566f83157938bb81 (patch) | |
tree | 3630bd635674ccc163c264b6c7fe5990b52be744 /sys/dev/ppbus/lpbb.c | |
parent | d41b901b60d3c5cbda874071b1e5ab50fc8b4e03 (diff) | |
download | FreeBSD-src-879505d4df9b978295c6bf69566f83157938bb81.zip FreeBSD-src-879505d4df9b978295c6bf69566f83157938bb81.tar.gz |
Add locking to ppc and ppbus and mark the whole lot MPSAFE:
- To avoid having a bunch of locks that end up always getting acquired as
a group, give each ppc(4) device a mutex which it shares with all the
child devices including ppbus(4), lpt(4), plip(4), etc. This mutex
is then used for all the locking.
- Rework the interrupt handling stuff yet again. Now ppbus drivers setup
their interrupt handler during attach and tear it down during detach
like most other drivers. ppbus(4) only invokes the interrupt handler
of the device that currently owns the bus (if any) when an interrupt
occurs, however. Also, interrupt handlers in general now accept their
softc pointers as their argument rather than the device_t. Another
feature of the ppbus interrupt handlers is that they are called with
the parent ppc device's lock already held. This minimizes the number
of lock operations during an interrupt.
- Mark plip(4), lpt(4), pcfclock(4), ppi(4), vpo(4) MPSAFE.
- lpbb(4) uses the ppc lock instead of Giant.
- Other plip(4) changes:
- Add a mutex to protect the global tables in plip(4) and free them on
module unload.
- Add a detach routine.
- Split out the init/stop code from the ioctl routine into separate
functions.
- Other lpt(4) changes:
- Use device_printf().
- Use a dedicated callout for the lptout timer.
- Allocate the I/O buffers at attach and detach rather than during
open and close as this simplifies the locking at the cost of
1024+32 bytes when the driver is attached.
- Other ppi(4) changes:
- Use an sx lock to serialize open and close.
- Remove unused HADBUS flag.
- Add a detach routine.
- Use a malloc'd buffer for each read and write to avoid races with
concurrent read/write.
- Other pps(4) changes:
- Use a callout rather than a callout handle with timeout().
- Conform to the new ppbus requirements (regular mutex, non-filter
interrupt handler). pps(4) is probably going to have to become a
standalone driver that doesn't use ppbus(4) to satisfy it's
requirements for low latency as a result.
- Use an sx lock to serialize open and close.
- Other vpo(4) changes:
- Use the parent ppc device's lock to create the CAM sim instead of
Giant.
- Other ppc(4) changes:
- Fix ppc_isa's detach method to detach instead of calling attach.
Tested by: no one :-(
Diffstat (limited to 'sys/dev/ppbus/lpbb.c')
-rw-r--r-- | sys/dev/ppbus/lpbb.c | 59 |
1 files changed, 36 insertions, 23 deletions
diff --git a/sys/dev/ppbus/lpbb.c b/sys/dev/ppbus/lpbb.c index 87ce6c7..872db24 100644 --- a/sys/dev/ppbus/lpbb.c +++ b/sys/dev/ppbus/lpbb.c @@ -103,16 +103,16 @@ lpbb_callback(device_t dev, int index, caddr_t *data) case IIC_REQUEST_BUS: /* request the ppbus */ how = *(int *)data; - mtx_lock(&Giant); + ppb_lock(ppbus); error = ppb_request_bus(ppbus, dev, how); - mtx_unlock(&Giant); + ppb_unlock(ppbus); break; case IIC_RELEASE_BUS: /* release the ppbus */ - mtx_lock(&Giant); + ppb_lock(ppbus); error = ppb_release_bus(ppbus, dev); - mtx_unlock(&Giant); + ppb_unlock(ppbus); break; default: @@ -129,25 +129,38 @@ lpbb_callback(device_t dev, int index, caddr_t *data) #define ALIM 0x20 #define I2CKEY 0x50 +/* Reset bus by setting SDA first and then SCL. */ +static void +lpbb_reset_bus(device_t dev) +{ + device_t ppbus = device_get_parent(dev); + + ppb_assert_locked(ppbus); + ppb_wdtr(ppbus, (u_char)~SDA_out); + ppb_wctr(ppbus, (u_char)(ppb_rctr(ppbus) | SCL_out)); +} + static int lpbb_getscl(device_t dev) { + device_t ppbus = device_get_parent(dev); int rval; - mtx_lock(&Giant); - rval = ((ppb_rstr(device_get_parent(dev)) & SCL_in) == SCL_in); - mtx_unlock(&Giant); + ppb_lock(ppbus); + rval = ((ppb_rstr(ppbus) & SCL_in) == SCL_in); + ppb_unlock(ppbus); return (rval); } static int lpbb_getsda(device_t dev) { + device_t ppbus = device_get_parent(dev); int rval; - mtx_lock(&Giant); - rval = ((ppb_rstr(device_get_parent(dev)) & SDA_in) == SDA_in); - mtx_unlock(&Giant); + ppb_lock(ppbus); + rval = ((ppb_rstr(ppbus) & SDA_in) == SDA_in); + ppb_unlock(ppbus); return (rval); } @@ -156,12 +169,12 @@ lpbb_setsda(device_t dev, char val) { device_t ppbus = device_get_parent(dev); - mtx_lock(&Giant); + ppb_lock(ppbus); if (val == 0) ppb_wdtr(ppbus, (u_char)SDA_out); else ppb_wdtr(ppbus, (u_char)~SDA_out); - mtx_unlock(&Giant); + ppb_unlock(ppbus); } static void @@ -169,12 +182,12 @@ lpbb_setscl(device_t dev, unsigned char val) { device_t ppbus = device_get_parent(dev); - mtx_lock(&Giant); + ppb_lock(ppbus); if (val == 0) ppb_wctr(ppbus, (u_char)(ppb_rctr(ppbus) & ~SCL_out)); else ppb_wctr(ppbus, (u_char)(ppb_rctr(ppbus) | SCL_out)); - mtx_unlock(&Giant); + ppb_unlock(ppbus); } static int @@ -182,23 +195,24 @@ lpbb_detect(device_t dev) { device_t ppbus = device_get_parent(dev); + ppb_lock(ppbus); if (ppb_request_bus(ppbus, dev, PPB_DONTWAIT)) { + ppb_unlock(ppbus); device_printf(dev, "can't allocate ppbus\n"); return (0); } - /* reset bus */ - lpbb_setsda(dev, 1); - lpbb_setscl(dev, 1); + lpbb_reset_bus(dev); if ((ppb_rstr(ppbus) & I2CKEY) || ((ppb_rstr(ppbus) & ALIM) != ALIM)) { - ppb_release_bus(ppbus, dev); + ppb_unlock(ppbus); return (0); } ppb_release_bus(ppbus, dev); + ppb_unlock(ppbus); return (1); } @@ -208,18 +222,17 @@ lpbb_reset(device_t dev, u_char speed, u_char addr, u_char * oldaddr) { device_t ppbus = device_get_parent(dev); - mtx_lock(&Giant); + ppb_lock(ppbus); if (ppb_request_bus(ppbus, dev, PPB_DONTWAIT)) { + ppb_unlock(ppbus); device_printf(dev, "can't allocate ppbus\n"); return (0); } - /* reset bus */ - lpbb_setsda(dev, 1); - lpbb_setscl(dev, 1); + lpbb_reset_bus(dev); ppb_release_bus(ppbus, dev); - mtx_unlock(&Giant); + ppb_unlock(ppbus); return (IIC_ENOADDR); } |