summaryrefslogtreecommitdiffstats
path: root/sys/dev/iicbus/iicbus.h
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.h
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.h')
-rw-r--r--sys/dev/iicbus/iicbus.h15
1 files changed, 9 insertions, 6 deletions
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 <sys/_lock.h>
+#include <sys/_mutex.h>
+
#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;
OpenPOWER on IntegriCloud