Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 2 Jun 2007 17:56:52 GMT
From:      Rui Paulo <rpaulo@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 120788 for review
Message-ID:  <200706021756.l52Huq9A049371@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=120788

Change 120788 by rpaulo@rpaulo_epsilon on 2007/06/02 17:55:58

	Add locking.	

Affected files ...

.. //depot/projects/soc2007/rpaulo-macbook/dev/asmc/asmc.c#8 edit
.. //depot/projects/soc2007/rpaulo-macbook/dev/asmc/asmcvar.h#4 edit

Differences ...

==== //depot/projects/soc2007/rpaulo-macbook/dev/asmc/asmc.c#8 (text+ko) ====

@@ -23,7 +23,7 @@
  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  *
- * $P4: //depot/projects/soc2007/rpaulo-macbook/dev/asmc/asmc.c#7 $
+ * $P4: //depot/projects/soc2007/rpaulo-macbook/dev/asmc/asmc.c#8 $
  *
  */
 
@@ -46,7 +46,8 @@
 #include <sys/conf.h>
 #include <sys/kernel.h>
 #include <sys/sysctl.h>
-#include <sys/sbuf.h>
+#include <sys/lock.h>
+#include <sys/mutex.h>
 
 #include <isa/isavar.h>
 
@@ -239,6 +240,8 @@
 
 	model = asmc_match(dev);
 
+	mtx_init(&sc->sc_mtx, "asmc_mtx", NULL, MTX_SPIN);
+
 	asmc_init(dev);
 
 	sc->sc_model = model;
@@ -397,6 +400,8 @@
 	if (sc->sc_res)
 		bus_release_resource(dev, SYS_RES_IRQ, sc->sc_rid, sc->sc_res);
 
+	mtx_destroy(&sc->sc_mtx);
+
 	return 0;
 }
 
@@ -510,7 +515,10 @@
 asmc_key_read(device_t dev, const char *key, uint8_t *buf, uint8_t len)
 {
 	int i, error = 1;
+	struct asmc_softc *sc = device_get_softc(dev);
 
+	mtx_lock_spin(&sc->sc_mtx);
+
 	outb(ASMC_CMDPORT, ASMC_CMDREAD);
 	if (asmc_wait(dev, 0x0c))
 		goto out;
@@ -531,6 +539,8 @@
 
 	error = 0;
 out:
+	mtx_unlock_spin(&sc->sc_mtx);
+
 	return error;
 }
 
@@ -538,6 +548,9 @@
 asmc_key_write(device_t dev, const char *key, uint8_t *buf, uint8_t len)
 {
 	int i, error = -1;
+	struct asmc_softc *sc = device_get_softc(dev);
+
+	mtx_lock_spin(&sc->sc_mtx);
 
 	outb(ASMC_CMDPORT, ASMC_CMDWRITE);
 	if (asmc_wait(dev, 0x0c))
@@ -559,6 +572,8 @@
 
 	error = 0;
 out:
+	mtx_unlock_spin(&sc->sc_mtx);
+
 	return error;
 
 }
@@ -707,6 +722,7 @@
 	uint8_t buf[2];
 	int error;
 
+	/* no need to do locking here as asmc_key_read() already does it */ 
 	switch (key[3]) {
 	case 'X':
 	case 'Y':
@@ -740,6 +756,9 @@
 {
 	uint8_t type;
 	device_t dev = (device_t) arg;
+	struct asmc_softc *sc = device_get_softc(dev);
+
+	mtx_lock_spin(&sc->sc_mtx);	
 
 	type = inb(ASMC_INTPORT);
 
@@ -757,6 +776,8 @@
 		device_printf(dev, "%s unknown interrupt\n", __func__);
 	}
 
+	mtx_unlock_spin(&sc->sc_mtx);
+
 	return 0;
 }
 

==== //depot/projects/soc2007/rpaulo-macbook/dev/asmc/asmcvar.h#4 (text+ko) ====

@@ -23,7 +23,7 @@
  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  *
- * $P4: //depot/projects/soc2007/rpaulo-macbook/dev/asmc/asmcvar.h#3 $
+ * $P4: //depot/projects/soc2007/rpaulo-macbook/dev/asmc/asmcvar.h#4 $
  *
  */
 
@@ -49,6 +49,8 @@
 	int			sc_rid;
 	struct resource		*sc_res;
 	void			*sc_cookie;
+
+	struct mtx		sc_mtx;
 };
 
 struct asmc_model {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200706021756.l52Huq9A049371>