Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 13 Dec 2008 18:49:01 +0000 (UTC)
From:      Nathan Whitehorn <nwhitehorn@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r186046 - head/sys/powerpc/powermac
Message-ID:  <200812131849.mBDIn1NV036834@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: nwhitehorn
Date: Sat Dec 13 18:49:01 2008
New Revision: 186046
URL: http://svn.freebsd.org/changeset/base/186046

Log:
  Use a static free packet queue instead of using malloc() to allocate new ADB packets.
  This fixes some locking problems.

Modified:
  head/sys/powerpc/powermac/cuda.c
  head/sys/powerpc/powermac/cudavar.h

Modified: head/sys/powerpc/powermac/cuda.c
==============================================================================
--- head/sys/powerpc/powermac/cuda.c	Sat Dec 13 18:33:22 2008	(r186045)
+++ head/sys/powerpc/powermac/cuda.c	Sat Dec 13 18:49:01 2008	(r186046)
@@ -104,8 +104,6 @@ static devclass_t cuda_devclass;
 DRIVER_MODULE(cuda, macio, cuda_driver, cuda_devclass, 0, 0);
 DRIVER_MODULE(adb, cuda, adb_driver, adb_devclass, 0, 0);
 
-MALLOC_DEFINE(M_CUDA, "cuda", "CUDA packet queue");
-
 static void cuda_intr(void *arg);
 static uint8_t cuda_read_reg(struct cuda_softc *sc, u_int offset);
 static void cuda_write_reg(struct cuda_softc *sc, u_int offset, uint8_t value);
@@ -178,6 +176,10 @@ cuda_attach(device_t dev)
 
 	STAILQ_INIT(&sc->sc_inq);
 	STAILQ_INIT(&sc->sc_outq);
+	STAILQ_INIT(&sc->sc_freeq);
+
+	for (i = 0; i < CUDA_MAXPACKETS; i++)
+		STAILQ_INSERT_TAIL(&sc->sc_freeq, &sc->sc_pkts[i], pkt_q);
 
 	/* Init CUDA */
 
@@ -348,11 +350,17 @@ cuda_send(void *cookie, int poll, int le
 
 	mtx_lock(&sc->sc_mutex);
 
-	pkt = malloc(sizeof(struct cuda_packet), M_CUDA, M_WAITOK);
+	pkt = STAILQ_FIRST(&sc->sc_freeq);
+	if (pkt == NULL) {
+		mtx_unlock(&sc->sc_mutex);
+		return (-1);
+	}
+
 	pkt->len = length - 1;
 	pkt->type = msg[0];
 	memcpy(pkt->data, &msg[1], pkt->len);
 
+	STAILQ_REMOVE_HEAD(&sc->sc_freeq, pkt_q);
 	STAILQ_INSERT_TAIL(&sc->sc_outq, pkt, pkt_q);
 
 	/*
@@ -389,8 +397,8 @@ cuda_send_outbound(struct cuda_softc *sc
 	memcpy(sc->sc_out, &pkt->type, pkt->len + 1);
 	sc->sc_sent = 0;
 
-	free(pkt, M_CUDA);
 	STAILQ_REMOVE_HEAD(&sc->sc_outq, pkt_q);
+	STAILQ_INSERT_TAIL(&sc->sc_freeq, pkt, pkt_q);
 
 	sc->sc_waiting = 1;
 
@@ -455,9 +463,9 @@ cuda_send_inbound(struct cuda_softc *sc)
 			break;
 		}
 
-		free(pkt,M_CUDA);
-
 		mtx_lock(&sc->sc_mutex);
+
+		STAILQ_INSERT_TAIL(&sc->sc_freeq, pkt, pkt_q);
 	}
 
 	mtx_unlock(&sc->sc_mutex);
@@ -559,18 +567,22 @@ switch_start:
 			cuda_idle(sc);
 
 			/* Queue up the packet */
-			pkt = malloc(sizeof(struct cuda_packet), M_CUDA, 
-			    M_WAITOK);
+			pkt = STAILQ_FIRST(&sc->sc_freeq);
+			if (pkt != NULL) {
+				/* If we have a free packet, process it */
+
+				pkt->len = sc->sc_received - 2;
+				pkt->type = sc->sc_in[1];
+				memcpy(pkt->data, &sc->sc_in[2], pkt->len);
 
-			pkt->len = sc->sc_received - 2;
-			pkt->type = sc->sc_in[1];
-			memcpy(pkt->data, &sc->sc_in[2], pkt->len);
+				STAILQ_REMOVE_HEAD(&sc->sc_freeq, pkt_q);
+				STAILQ_INSERT_TAIL(&sc->sc_inq, pkt, pkt_q);
 
-			STAILQ_INSERT_TAIL(&sc->sc_inq, pkt, pkt_q);
+				process_inbound = 1;
+			}
 
 			sc->sc_state = CUDA_IDLE;
 			sc->sc_received = 0;
-			process_inbound = 1;
 
 			/*
 			 * If there is something waiting to be sent out,

Modified: head/sys/powerpc/powermac/cudavar.h
==============================================================================
--- head/sys/powerpc/powermac/cudavar.h	Sat Dec 13 18:33:22 2008	(r186045)
+++ head/sys/powerpc/powermac/cudavar.h	Sat Dec 13 18:49:01 2008	(r186046)
@@ -35,6 +35,7 @@
 #define	_POWERPC_CUDAVAR_H_
 
 #define CUDA_DEVSTR	"Apple CUDA I/O Controller"
+#define	CUDA_MAXPACKETS	10
 
 /* Cuda addresses */
 #define CUDA_ADB	0
@@ -99,8 +100,10 @@ struct cuda_softc {
 	int		sc_out_length;
 	int		sc_received;
 
+	struct cuda_packet sc_pkts[CUDA_MAXPACKETS];
 	struct cuda_pktq sc_inq;
 	struct cuda_pktq sc_outq;
+	struct cuda_pktq sc_freeq;
 };
 
 #endif /* _POWERPC_CUDAVAR_H_ */



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