From 3b547d7c3ff7d40672c49c58d43eeea9f09423a4 Mon Sep 17 00:00:00 2001 From: jhb Date: Mon, 4 Aug 2008 21:03:06 +0000 Subject: 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. --- sys/dev/iicbus/iicbus.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'sys/dev/iicbus/iicbus.h') diff --git a/sys/dev/iicbus/iicbus.h b/sys/dev/iicbus/iicbus.h index 55f3b93..0698d5c 100644 --- a/sys/dev/iicbus/iicbus.h +++ b/sys/dev/iicbus/iicbus.h @@ -29,6 +29,9 @@ #ifndef __IICBUS_H #define __IICBUS_H +#include +#include + #define IICBUS_IVAR(d) (struct iicbus_ivar *) device_get_ivars(d) #define IICBUS_SOFTC(d) (struct iicbus_softc *) device_get_softc(d) @@ -38,6 +41,7 @@ struct iicbus_softc device_t owner; /* iicbus owner device structure */ u_char started; /* address of the 'started' slave * 0 if no start condition succeeded */ + struct mtx lock; }; struct iicbus_ivar @@ -50,15 +54,14 @@ enum { }; #define IICBUS_ACCESSOR(A, B, T) \ -__inline static int \ -iicbus_get_ ## A(device_t dev, T *t) \ -{ \ - return BUS_READ_IVAR(device_get_parent(dev), dev, \ - IICBUS_IVAR_ ## B, (uintptr_t *) t); \ -} + __BUS_ACCESSOR(iicbus, A, IICBUS, B, T) IICBUS_ACCESSOR(addr, ADDR, uint32_t) +#define IICBUS_LOCK(sc) mtx_lock(&(sc)->lock) +#define IICBUS_UNLOCK(sc) mtx_unlock(&(sc)->lock) +#define IICBUS_ASSERT_LOCKED(sc) mtx_assert(&(sc)->lock, MA_OWNED) + extern int iicbus_generic_intr(device_t dev, int event, char *buf); extern driver_t iicbus_driver; -- cgit v1.1