summaryrefslogtreecommitdiffstats
path: root/sys/dev/ppbus/pcfclock.c
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2009-01-21 23:10:06 +0000
committerjhb <jhb@FreeBSD.org>2009-01-21 23:10:06 +0000
commit879505d4df9b978295c6bf69566f83157938bb81 (patch)
tree3630bd635674ccc163c264b6c7fe5990b52be744 /sys/dev/ppbus/pcfclock.c
parentd41b901b60d3c5cbda874071b1e5ab50fc8b4e03 (diff)
downloadFreeBSD-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/pcfclock.c')
-rw-r--r--sys/dev/ppbus/pcfclock.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/sys/dev/ppbus/pcfclock.c b/sys/dev/ppbus/pcfclock.c
index a969a84..e59a891 100644
--- a/sys/dev/ppbus/pcfclock.c
+++ b/sys/dev/ppbus/pcfclock.c
@@ -54,7 +54,6 @@ __FBSDID("$FreeBSD$");
struct pcfclock_data {
device_t dev;
struct cdev *cdev;
- int count;
};
static devclass_t pcfclock_devclass;
@@ -65,7 +64,6 @@ static d_read_t pcfclock_read;
static struct cdevsw pcfclock_cdevsw = {
.d_version = D_VERSION,
- .d_flags = D_NEEDGIANT,
.d_open = pcfclock_open,
.d_close = pcfclock_close,
.d_read = pcfclock_read,
@@ -159,13 +157,11 @@ pcfclock_open(struct cdev *dev, int flag, int fms, struct thread *td)
if (!sc)
return (ENXIO);
- if ((res = ppb_request_bus(ppbus, pcfclockdev,
- (flag & O_NONBLOCK) ? PPB_DONTWAIT : PPB_WAIT)))
- return (res);
-
- sc->count++;
-
- return (0);
+ ppb_lock(ppbus);
+ res = ppb_request_bus(ppbus, pcfclockdev,
+ (flag & O_NONBLOCK) ? PPB_DONTWAIT : PPB_WAIT);
+ ppb_unlock(ppbus);
+ return (res);
}
static int
@@ -175,9 +171,9 @@ pcfclock_close(struct cdev *dev, int flags, int fmt, struct thread *td)
device_t pcfclockdev = sc->dev;
device_t ppbus = device_get_parent(pcfclockdev);
- sc->count--;
- if (sc->count == 0)
- ppb_release_bus(ppbus, pcfclockdev);
+ ppb_lock(ppbus);
+ ppb_release_bus(ppbus, pcfclockdev);
+ ppb_unlock(ppbus);
return (0);
}
@@ -240,7 +236,7 @@ pcfclock_read_data(struct cdev *dev, char *buf, ssize_t bits)
waitfor = 100;
for (i = 0; i <= bits; i++) {
/* wait for clock, maximum (waitfor*100) usec */
- while(!CLOCK_OK && --waitfor > 0)
+ while (!CLOCK_OK && --waitfor > 0)
DELAY(100);
/* timed out? */
@@ -297,13 +293,17 @@ static int
pcfclock_read(struct cdev *dev, struct uio *uio, int ioflag)
{
struct pcfclock_data *sc = dev->si_drv1;
+ device_t ppbus;
char buf[18];
int error = 0;
if (uio->uio_resid < 18)
return (ERANGE);
+ ppbus = device_get_parent(sc->dev);
+ ppb_lock(ppbus);
error = pcfclock_read_dev(dev, buf, PCFCLOCK_MAX_RETRIES);
+ ppb_unlock(ppbus);
if (error) {
device_printf(sc->dev, "no PCF found\n");
OpenPOWER on IntegriCloud