summaryrefslogtreecommitdiffstats
path: root/sys/dev/iicbus/iicbus.c
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2008-08-04 21:03:06 +0000
committerjhb <jhb@FreeBSD.org>2008-08-04 21:03:06 +0000
commit3b547d7c3ff7d40672c49c58d43eeea9f09423a4 (patch)
tree08e4c4501b42622c7e3145bc5fd24fe0b8042ee7 /sys/dev/iicbus/iicbus.c
parent9b394a3293bfa4397c24c6649034b411994dbb72 (diff)
downloadFreeBSD-src-3b547d7c3ff7d40672c49c58d43eeea9f09423a4.zip
FreeBSD-src-3b547d7c3ff7d40672c49c58d43eeea9f09423a4.tar.gz
Add locking to the core iicbus(4) drivers:
- Add an sx lock to the iic(4) driver to serialize open(), close(), read(), and write and to protect sc_addr and sc_count in the softc. - Use cdev->si_drv1 instead of using the minor number of the cdev to lookup the softc via newbus in iic(4). - Store the device_t in the softc to avoid a similar detour via minor numbers in iic(4). - Only add at most one instance of iic(4) and iicsmb(4) to each iicbus(4) instance, and do it in the child driver. - Add a mutex to the iicbus(4) softc to synchronize the request/release bus stuff. - Use __BUS_ACCESSOR() for IICBUS_ACCESSOR() instead of rolling our own. - Add a mutex to the iicsmb(4) softc to protect softc state updated in the interrupt handler. - Remove Giant from all the smbus methods in iicsmb(4) now that all the iicbus(4) backend is locked.
Diffstat (limited to 'sys/dev/iicbus/iicbus.c')
-rw-r--r--sys/dev/iicbus/iicbus.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/sys/dev/iicbus/iicbus.c b/sys/dev/iicbus/iicbus.c
index 8594b8d..de64874 100644
--- a/sys/dev/iicbus/iicbus.c
+++ b/sys/dev/iicbus/iicbus.c
@@ -34,8 +34,10 @@ __FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
+#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/module.h>
+#include <sys/mutex.h>
#include <sys/bus.h>
#include <dev/iicbus/iiconf.h>
@@ -90,6 +92,7 @@ iicbus_attach(device_t dev)
struct iicbus_softc *sc = IICBUS_SOFTC(dev);
sc->dev = dev;
+ mtx_init(&sc->lock, "iicbus", NULL, MTX_DEF);
iicbus_reset(dev, IIC_FASTEST, 0, NULL);
/* device probing is meaningless since the bus is supposed to be
@@ -108,13 +111,8 @@ iicbus_attach(device_t dev)
}
printf("\n");
#endif
- /* Always attach the iicsmb children */
- BUS_ADD_CHILD(dev, 0, "iicsmb", -1);
- /* attach any known device */
- BUS_ADD_CHILD(dev, 0, "iic", -1);
- /* Attach the wired devices via hints */
+ bus_generic_probe(dev);
bus_enumerate_hinted_children(dev);
- /* Now probe and attach them */
bus_generic_attach(dev);
return (0);
}
@@ -122,9 +120,11 @@ iicbus_attach(device_t dev)
static int
iicbus_detach(device_t dev)
{
+ struct iicbus_softc *sc = IICBUS_SOFTC(dev);
iicbus_reset(dev, IIC_FASTEST, 0, NULL);
bus_generic_detach(dev);
+ mtx_destroy(&sc->lock);
return (0);
}
@@ -265,6 +265,4 @@ driver_t iicbus_driver = {
devclass_t iicbus_devclass;
-DRIVER_MODULE(iicbus, envctrl, iicbus_driver, iicbus_devclass, 0, 0);
-DRIVER_MODULE(iicbus, iicbb, iicbus_driver, iicbus_devclass, 0, 0);
MODULE_VERSION(iicbus, IICBUS_MODVER);
OpenPOWER on IntegriCloud