Module Name: src
Committed By: tsutsui
Date: Sat May 9 03:22:20 UTC 2009
Modified Files:
src/sys/arch/ews4800mips/sbd: if_iee_sbdio.c
src/sys/arch/hp700/gsc: if_iee_gsc.c
src/sys/dev/ic: i82596.c i82596var.h
Log Message:
Move allocation of DMA shared memory with bus_dma(9) ops
from MD attachments to MI iee_attach().
Tested on HP9000 735/125. Compile test only on ews4800mips.
XXX: more strict bus_dmamap_sync(9) calls are required in various places.
To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/ews4800mips/sbd/if_iee_sbdio.c
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/hp700/gsc/if_iee_gsc.c
cvs rdiff -u -r1.20 -r1.21 src/sys/dev/ic/i82596.c
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/ic/i82596var.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/ews4800mips/sbd/if_iee_sbdio.c
diff -u src/sys/arch/ews4800mips/sbd/if_iee_sbdio.c:1.7 src/sys/arch/ews4800mips/sbd/if_iee_sbdio.c:1.8
--- src/sys/arch/ews4800mips/sbd/if_iee_sbdio.c:1.7 Sat May 9 02:18:48 2009
+++ src/sys/arch/ews4800mips/sbd/if_iee_sbdio.c Sat May 9 03:22:20 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: if_iee_sbdio.c,v 1.7 2009/05/09 02:18:48 tsutsui Exp $ */
+/* $NetBSD: if_iee_sbdio.c,v 1.8 2009/05/09 03:22:20 tsutsui Exp $ */
/*
* Copyright (c) 2003 Jochen Kunz.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_iee_sbdio.c,v 1.7 2009/05/09 02:18:48 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_iee_sbdio.c,v 1.8 2009/05/09 03:22:20 tsutsui Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -85,7 +85,6 @@
struct sbdio_attach_args *sa = aux;
uint8_t eaddr[ETHER_ADDR_LEN];
int media[2];
- int rsegs;
sc->sc_dev = self;
sc_ssc->sc_port =
@@ -98,44 +97,8 @@
sc->sc_dmat = sa->sa_dmat;
- if (bus_dmamem_alloc(sc->sc_dmat, IEE_SHMEM_MAX, PAGE_SIZE, 0,
- &sc->sc_dma_segs, 1, &rsegs, BUS_DMA_NOWAIT) != 0) {
- aprint_error(": can't allocate %d bytes of DMA memory\n",
- (int)IEE_SHMEM_MAX);
- return;
- }
-
- if (bus_dmamem_map(sc->sc_dmat, &sc->sc_dma_segs, rsegs, IEE_SHMEM_MAX,
- (void **)sc->sc_shmem_addr,
- BUS_DMA_NOWAIT | BUS_DMA_COHERENT) != 0) {
- aprint_error(": can't map DMA memory\n");
- bus_dmamem_free(sc->sc_dmat, &sc->sc_dma_segs, rsegs);
- return;
- }
-
- if (bus_dmamap_create(sc->sc_dmat, IEE_SHMEM_MAX, rsegs,
- IEE_SHMEM_MAX, 0, BUS_DMA_NOWAIT, &sc->sc_shmem_map) != 0) {
- aprint_error(": can't create DMA map\n");
- bus_dmamem_unmap(sc->sc_dmat, sc->sc_shmem_addr, IEE_SHMEM_MAX);
- bus_dmamem_free(sc->sc_dmat, &sc->sc_dma_segs, rsegs);
- return;
- }
-
- if (bus_dmamap_load(sc->sc_dmat, sc->sc_shmem_map, sc->sc_shmem_addr,
- IEE_SHMEM_MAX, NULL, BUS_DMA_NOWAIT) != 0) {
- aprint_error(": can't load DMA map\n");
- bus_dmamap_destroy(sc->sc_dmat, sc->sc_shmem_map);
- bus_dmamem_unmap(sc->sc_dmat, sc->sc_shmem_addr, IEE_SHMEM_MAX);
- bus_dmamem_free(sc->sc_dmat, &sc->sc_dma_segs, rsegs);
- return;
- }
- memset(sc->sc_shmem_addr, 0, IEE_SHMEM_MAX);
-
- bus_dmamap_sync(sc->sc_dmat, sc->sc_shmem_map, 0, IEE_SHMEM_MAX,
- BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
-
/* Setup SYSBUS byte. TR2 specific? -uch */
- SC_SCP->scp_sysbus = IEE_SYSBUS_BE | IEE_SYSBUS_INT |
+ sc->sc_sysbus = IEE_SYSBUS_BE | IEE_SYSBUS_INT |
IEE_SYSBUS_LIEAR | IEE_SYSBUS_STD;
sc->sc_iee_reset = iee_sbdio_reset;
Index: src/sys/arch/hp700/gsc/if_iee_gsc.c
diff -u src/sys/arch/hp700/gsc/if_iee_gsc.c:1.11 src/sys/arch/hp700/gsc/if_iee_gsc.c:1.12
--- src/sys/arch/hp700/gsc/if_iee_gsc.c:1.11 Sat May 9 02:29:29 2009
+++ src/sys/arch/hp700/gsc/if_iee_gsc.c Sat May 9 03:22:20 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: if_iee_gsc.c,v 1.11 2009/05/09 02:29:29 tsutsui Exp $ */
+/* $NetBSD: if_iee_gsc.c,v 1.12 2009/05/09 03:22:20 tsutsui Exp $ */
/*
* Copyright (c) 2003 Jochen Kunz.
@@ -34,7 +34,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_iee_gsc.c,v 1.11 2009/05/09 02:29:29 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_iee_gsc.c,v 1.12 2009/05/09 03:22:20 tsutsui Exp $");
/* autoconfig and device stuff */
#include <sys/param.h>
@@ -214,7 +214,6 @@
struct gsc_attach_args *ga = aux;
enum hppa_cpu_type cpu_type;
int media[2];
- int rsegs;
sc->sc_dev = self;
@@ -241,34 +240,6 @@
}
sc->sc_dmat = ga->ga_dmatag;
- if (bus_dmamem_alloc(sc->sc_dmat, IEE_SHMEM_MAX, PAGE_SIZE, 0,
- &sc->sc_dma_segs, 1, &rsegs, BUS_DMA_NOWAIT) != 0) {
- aprint_error(": iee_gsc_attach: can't allocate %d bytes of "
- "DMA memory\n", (int)IEE_SHMEM_MAX);
- return;
- }
- if (bus_dmamem_map(sc->sc_dmat, &sc->sc_dma_segs, rsegs, IEE_SHMEM_MAX,
- (void **)&sc->sc_shmem_addr, BUS_DMA_NOWAIT) != 0) {
- aprint_error(": iee_gsc_attach: can't map DMA memory\n");
- bus_dmamem_free(sc->sc_dmat, &sc->sc_dma_segs, rsegs);
- return;
- }
- if (bus_dmamap_create(sc->sc_dmat, IEE_SHMEM_MAX, rsegs,
- IEE_SHMEM_MAX, 0, BUS_DMA_NOWAIT, &sc->sc_shmem_map) != 0) {
- aprint_error(": iee_gsc_attach: can't create DMA map\n");
- bus_dmamem_unmap(sc->sc_dmat, sc->sc_shmem_addr, IEE_SHMEM_MAX);
- bus_dmamem_free(sc->sc_dmat, &sc->sc_dma_segs, rsegs);
- return;
- }
- if (bus_dmamap_load(sc->sc_dmat, sc->sc_shmem_map, sc->sc_shmem_addr,
- IEE_SHMEM_MAX, NULL, BUS_DMA_NOWAIT) != 0) {
- aprint_error(": iee_gsc_attach: can't load DMA map\n");
- bus_dmamap_destroy(sc->sc_dmat, sc->sc_shmem_map);
- bus_dmamem_unmap(sc->sc_dmat, sc->sc_shmem_addr, IEE_SHMEM_MAX);
- bus_dmamem_free(sc->sc_dmat, &sc->sc_dma_segs, rsegs);
- return;
- }
- memset(sc->sc_shmem_addr, 0, IEE_SHMEM_MAX);
/* Setup SYSBUS byte. */
if (ga->ga_type.iodc_sv_model == HPPA_FIO_LAN) {
@@ -281,11 +252,11 @@
* 715/50, 735/99: Rev A1? (per PR port-hp700/35531)
* 735/125: Rev C
*/
- SC_SCP->scp_sysbus = IEE_SYSBUS_INT |
+ sc->sc_sysbus = IEE_SYSBUS_INT |
IEE_SYSBUS_TRG | IEE_SYSBUS_LIEAR | IEE_SYSBUS_STD;
sc->sc_flags = IEE_NEED_SWAP | IEE_REV_A;
} else {
- SC_SCP->scp_sysbus = IEE_SYSBUS_BE | IEE_SYSBUS_INT |
+ sc->sc_sysbus = IEE_SYSBUS_BE | IEE_SYSBUS_INT |
IEE_SYSBUS_TRG | IEE_SYSBUS_LIEAR | IEE_SYSBUS_STD;
sc->sc_flags = IEE_NEED_SWAP;
}
@@ -311,10 +282,6 @@
iee_detach(sc, flags);
bus_space_unmap(sc_gsc->sc_iot, sc_gsc->sc_ioh, IEE_GSC_IO_SZ);
- bus_dmamap_unload(sc->sc_dmat, sc->sc_shmem_map);
- bus_dmamap_destroy(sc->sc_dmat, sc->sc_shmem_map);
- bus_dmamem_unmap(sc->sc_dmat, sc->sc_shmem_addr, IEE_SHMEM_MAX);
- bus_dmamem_free(sc->sc_dmat, &sc->sc_dma_segs, 1);
/* There is no hp700_intr_disestablish()! */
return 0;
}
Index: src/sys/dev/ic/i82596.c
diff -u src/sys/dev/ic/i82596.c:1.20 src/sys/dev/ic/i82596.c:1.21
--- src/sys/dev/ic/i82596.c:1.20 Tue May 5 15:47:35 2009
+++ src/sys/dev/ic/i82596.c Sat May 9 03:22:20 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: i82596.c,v 1.20 2009/05/05 15:47:35 tsutsui Exp $ */
+/* $NetBSD: i82596.c,v 1.21 2009/05/09 03:22:20 tsutsui Exp $ */
/*
* Copyright (c) 2003 Jochen Kunz.
@@ -43,7 +43,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: i82596.c,v 1.20 2009/05/05 15:47:35 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i82596.c,v 1.21 2009/05/09 03:22:20 tsutsui Exp $");
/* autoconfig and device stuff */
#include <sys/param.h>
@@ -156,12 +156,13 @@
* sc->sc_cl_align MUST BE INITIALIZED BEFORE THE FOLLOWING MACROS ARE USED:
* SC_* IEE_*_SZ IEE_*_OFF IEE_SHMEM_MAX (shell style glob(3) pattern)
*
- * The MD frontend has to allocate a piece of DMA memory at least of
- * IEE_SHMEM_MAX bytes size. All communication with the chip is done via
- * this shared memory. If possible map this memory non-cachable on
- * archs with non DMA I/O coherent caches. The base of the memory needs
- * to be aligned to an even address if sc->sc_cl_align == 1 and aligned
- * to a cache line if sc->sc_cl_align != 1.
+ * The MD frontend also has to set sc->sc_cl_align and sc->sc_sysbus
+ * to allocate and setup shared DMA memory in MI iee_attach().
+ * All communication with the chip is done via this shared memory.
+ * This memory is mapped with BUS_DMA_COHERENT so it will be uncached
+ * if possible for archs with non DMA I/O coherent caches.
+ * The base of the memory needs to be aligned to an even address
+ * if sc->sc_cl_align == 1 and aligned to a cache line if sc->sc_cl_align != 1.
*
* An interrupt with iee_intr() as handler must be established.
*
@@ -530,9 +531,44 @@
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
int n;
+ KASSERT(sc->sc_cl_align > 0);
+
+ /* allocate memory for shared DMA descriptors */
+ if (bus_dmamem_alloc(sc->sc_dmat, IEE_SHMEM_MAX, PAGE_SIZE, 0,
+ &sc->sc_dma_segs, 1, &sc->sc_dma_rsegs, BUS_DMA_NOWAIT) != 0) {
+ aprint_error(": iee_gsc_attach: can't allocate %d bytes of "
+ "DMA memory\n", (int)IEE_SHMEM_MAX);
+ return;
+ }
+ if (bus_dmamem_map(sc->sc_dmat, &sc->sc_dma_segs, sc->sc_dma_rsegs,
+ IEE_SHMEM_MAX, (void **)&sc->sc_shmem_addr,
+ BUS_DMA_COHERENT | BUS_DMA_NOWAIT) != 0) {
+ aprint_error(": iee_gsc_attach: can't map DMA memory\n");
+ bus_dmamem_free(sc->sc_dmat, &sc->sc_dma_segs,
+ sc->sc_dma_rsegs);
+ return;
+ }
+ if (bus_dmamap_create(sc->sc_dmat, IEE_SHMEM_MAX, sc->sc_dma_rsegs,
+ IEE_SHMEM_MAX, 0, BUS_DMA_NOWAIT, &sc->sc_shmem_map) != 0) {
+ aprint_error(": iee_gsc_attach: can't create DMA map\n");
+ bus_dmamem_unmap(sc->sc_dmat, sc->sc_shmem_addr, IEE_SHMEM_MAX); bus_dmamem_free(sc->sc_dmat, &sc->sc_dma_segs,
+ sc->sc_dma_rsegs);
+ return;
+ }
+ if (bus_dmamap_load(sc->sc_dmat, sc->sc_shmem_map, sc->sc_shmem_addr,
+ IEE_SHMEM_MAX, NULL, BUS_DMA_NOWAIT) != 0) {
+ aprint_error(": iee_gsc_attach: can't load DMA map\n");
+ bus_dmamap_destroy(sc->sc_dmat, sc->sc_shmem_map);
+ bus_dmamem_unmap(sc->sc_dmat, sc->sc_shmem_addr, IEE_SHMEM_MAX); bus_dmamem_free(sc->sc_dmat, &sc->sc_dma_segs,
+ sc->sc_dma_rsegs);
+ return;
+ }
+ memset(sc->sc_shmem_addr, 0, IEE_SHMEM_MAX);
+
/* Set pointer to Intermediate System Configuration Pointer. */
/* Phys. addr. in big endian order. (Big endian as defined by Intel.) */
SC_SCP->scp_iscp_addr = IEE_SWAP32(IEE_PHYS_SHMEM(IEE_ISCP_OFF));
+ SC_SCP->scp_sysbus = sc->sc_sysbus;
/* Set pointer to System Control Block. */
/* Phys. addr. in big endian order. (Big endian as defined by Intel.) */
SC_ISCP->iscp_scb_addr = IEE_SWAP32(IEE_PHYS_SHMEM(IEE_SCB_OFF));
@@ -541,6 +577,9 @@
/* Set pointer to Command Block. (physical address) */
SC_SCB->scb_cmd_blk_addr = IEE_SWAPA32(IEE_PHYS_SHMEM(IEE_CB_OFF));
+ bus_dmamap_sync(sc->sc_dmat, sc->sc_shmem_map, 0, IEE_SHMEM_MAX,
+ BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
+
ifmedia_init(&sc->sc_ifmedia, 0, iee_mediachange, iee_mediastatus);
if (media != NULL) {
for (n = 0 ; n < nmedia ; n++)
@@ -591,6 +630,10 @@
iee_stop(ifp, 1);
ether_ifdetach(ifp);
if_detach(ifp);
+ bus_dmamap_unload(sc->sc_dmat, sc->sc_shmem_map);
+ bus_dmamap_destroy(sc->sc_dmat, sc->sc_shmem_map);
+ bus_dmamem_unmap(sc->sc_dmat, sc->sc_shmem_addr, IEE_SHMEM_MAX);
+ bus_dmamem_free(sc->sc_dmat, &sc->sc_dma_segs, sc->sc_dma_rsegs);
}
Index: src/sys/dev/ic/i82596var.h
diff -u src/sys/dev/ic/i82596var.h:1.11 src/sys/dev/ic/i82596var.h:1.12
--- src/sys/dev/ic/i82596var.h:1.11 Tue May 5 15:47:35 2009
+++ src/sys/dev/ic/i82596var.h Sat May 9 03:22:20 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: i82596var.h,v 1.11 2009/05/05 15:47:35 tsutsui Exp $ */
+/* $NetBSD: i82596var.h,v 1.12 2009/05/09 03:22:20 tsutsui Exp $ */
/*
* Copyright (c) 2003 Jochen Kunz.
@@ -156,6 +156,7 @@
bus_dma_tag_t sc_dmat;
bus_dmamap_t sc_shmem_map;
bus_dma_segment_t sc_dma_segs;
+ int sc_dma_rsegs;
bus_dmamap_t sc_rx_map[IEE_NRFD];
bus_dmamap_t sc_tx_map[IEE_NCB];
struct mbuf *sc_rx_mbuf[IEE_NRFD];
@@ -167,6 +168,7 @@
uint8_t sc_cf[14];
int sc_flags;
int sc_cl_align;
+ uint32_t sc_sysbus;
uint32_t sc_crc_err;
uint32_t sc_align_err;
uint32_t sc_resource_err;