From owner-svn-src-head@FreeBSD.ORG Sat Dec 13 18:49:01 2008 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id DDC651065672; Sat, 13 Dec 2008 18:49:01 +0000 (UTC) (envelope-from nwhitehorn@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id CB4C88FC13; Sat, 13 Dec 2008 18:49:01 +0000 (UTC) (envelope-from nwhitehorn@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mBDIn1ta036836; Sat, 13 Dec 2008 18:49:01 GMT (envelope-from nwhitehorn@svn.freebsd.org) Received: (from nwhitehorn@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mBDIn1NV036834; Sat, 13 Dec 2008 18:49:01 GMT (envelope-from nwhitehorn@svn.freebsd.org) Message-Id: <200812131849.mBDIn1NV036834@svn.freebsd.org> From: Nathan Whitehorn Date: Sat, 13 Dec 2008 18:49:01 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r186046 - head/sys/powerpc/powermac X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 13 Dec 2008 18:49:02 -0000 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_ */