svn commit: r354296 - head/sys/dev/ichiic

Vladimir Kondratyev wulf at FreeBSD.org
Sun Nov 3 20:45:26 UTC 2019


Author: wulf
Date: Sun Nov  3 20:45:25 2019
New Revision: 354296
URL: https://svnweb.freebsd.org/changeset/base/354296

Log:
  [ig4] Reduce scope of io_lock
  
  Now io_lock is used as condition variable to synchronize active process with
  the interrupt handler. It is not used for tasks other than waiting for
  interrupt and passing parameters to and from it's handler.

Modified:
  head/sys/dev/ichiic/ig4_iic.c
  head/sys/dev/ichiic/ig4_var.h

Modified: head/sys/dev/ichiic/ig4_iic.c
==============================================================================
--- head/sys/dev/ichiic/ig4_iic.c	Sun Nov  3 20:44:16 2019	(r354295)
+++ head/sys/dev/ichiic/ig4_iic.c	Sun Nov  3 20:45:25 2019	(r354296)
@@ -188,10 +188,12 @@ wait_status(ig4iic_softc_t *sc, uint32_t status)
 		 * work, otherwise poll with the lock held.
 		 */
 		if (status & IG4_STATUS_RX_NOTEMPTY) {
+			mtx_lock(&sc->io_lock);
 			set_intr_mask(sc, IG4_INTR_STOP_DET | IG4_INTR_RX_FULL);
 			mtx_sleep(sc, &sc->io_lock, 0, "i2cwait",
 				  (hz + 99) / 100); /* sleep up to 10ms */
 			set_intr_mask(sc, 0);
+			mtx_unlock(&sc->io_lock);
 			count_us += 10000;
 		} else {
 			DELAY(25);
@@ -405,7 +407,6 @@ ig4iic_transfer(device_t dev, struct iic_msg *msgs, ui
 	}
 
 	sx_xlock(&sc->call_lock);
-	mtx_lock(&sc->io_lock);
 
 	/* Debugging - dump registers. */
 	if (ig4_dump) {
@@ -453,7 +454,6 @@ ig4iic_transfer(device_t dev, struct iic_msg *msgs, ui
 		rpstart = !stop;
 	}
 
-	mtx_unlock(&sc->io_lock);
 	sx_unlock(&sc->call_lock);
 	return (error);
 }
@@ -464,7 +464,6 @@ ig4iic_reset(device_t dev, u_char speed, u_char addr, 
 	ig4iic_softc_t *sc = device_get_softc(dev);
 
 	sx_xlock(&sc->call_lock);
-	mtx_lock(&sc->io_lock);
 
 	/* TODO handle speed configuration? */
 	if (oldaddr != NULL)
@@ -473,7 +472,6 @@ ig4iic_reset(device_t dev, u_char speed, u_char addr, 
 	if (addr == IIC_UNKNOWN)
 		sc->slave_valid = false;
 
-	mtx_unlock(&sc->io_lock);
 	sx_unlock(&sc->call_lock);
 	return (0);
 }
@@ -664,14 +662,12 @@ ig4iic_detach(ig4iic_softc_t *sc)
 		bus_teardown_intr(sc->dev, sc->intr_res, sc->intr_handle);
 
 	sx_xlock(&sc->call_lock);
-	mtx_lock(&sc->io_lock);
 
 	sc->iicbus = NULL;
 	sc->intr_handle = NULL;
 	reg_write(sc, IG4_REG_INTR_MASK, 0);
 	set_controller(sc, 0);
 
-	mtx_unlock(&sc->io_lock);
 	sx_xunlock(&sc->call_lock);
 
 	mtx_destroy(&sc->io_lock);

Modified: head/sys/dev/ichiic/ig4_var.h
==============================================================================
--- head/sys/dev/ichiic/ig4_var.h	Sun Nov  3 20:44:16 2019	(r354295)
+++ head/sys/dev/ichiic/ig4_var.h	Sun Nov  3 20:45:25 2019	(r354296)
@@ -73,8 +73,12 @@ struct ig4iic_softc {
 	 *
 	 * Functions implementing the icbus interface that interact
 	 * with the controller acquire an exclusive lock on call_lock
-	 * to prevent interleaving of calls to the interface and a lock on
-	 * io_lock right afterwards, to synchronize controller I/O activity.
+	 * to prevent interleaving of calls to the interface.
+	 *
+	 * io_lock is used as condition variable to synchronize active process
+	 * with the interrupt handler. It should not be used for tasks other
+	 * than waiting for interrupt and passing parameters to and from
+	 * it's handler.
 	 */
 	struct sx	call_lock;
 	struct mtx	io_lock;


More information about the svn-src-head mailing list