Make DPRINTFs depend on busdma_debug variable (off by default).

Move mixed PRE/POST check in _bus_dmamap_sync under DIAGNOSTIC.
Use __func__ to print function name and wrap long DPRINTF lines
to reduce visual clutter.
This commit is contained in:
uwe 2008-05-03 22:07:07 +00:00
parent b6a04a1973
commit 4b4321601b
1 changed files with 74 additions and 44 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: bus_dma.c,v 1.2 2007/03/04 06:00:03 christos Exp $ */
/* $NetBSD: bus_dma.c,v 1.3 2008/05/03 22:07:07 uwe Exp $ */
/*
* Copyright (c) 2005 NONAKA Kimihiro
@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.2 2007/03/04 06:00:03 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.3 2008/05/03 22:07:07 uwe Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -44,7 +44,8 @@ __KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.2 2007/03/04 06:00:03 christos Exp $")
#include <machine/bus.h>
#if defined(DEBUG) && defined(BUSDMA_DEBUG)
#define DPRINTF(a) printf a
int busdma_debug = 0;
#define DPRINTF(a) if (busdma_debug) printf a
#else
#define DPRINTF(a)
#endif
@ -80,7 +81,9 @@ _bus_dmamap_create(bus_dma_tag_t t, bus_size_t size, int nsegments,
size_t mapsize;
int error;
DPRINTF(("bus_dmamap_create: t = %p, size = %ld, nsegments = %d, maxsegsz = %ld, boundary = %ld, flags = %x\n", t, size, nsegments, maxsegsz, boundary, flags));
DPRINTF(("%s: t = %p, size = %ld, nsegments = %d, maxsegsz = %ld,"
" boundary = %ld, flags = %x\n",
__func__, t, size, nsegments, maxsegsz, boundary, flags));
/*
* Allocate and initialize the DMA map. The end of the map
@ -101,7 +104,7 @@ _bus_dmamap_create(bus_dma_tag_t t, bus_size_t size, int nsegments,
(flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK)) == NULL)
return (ENOMEM);
DPRINTF(("bus_dmamap_create: dmamp = %p\n", mapstore));
DPRINTF(("%s: dmamp = %p\n", __func__, mapstore));
memset(mapstore, 0, mapsize);
map = (bus_dmamap_t)mapstore;
@ -126,7 +129,7 @@ void
_bus_dmamap_destroy(bus_dma_tag_t t, bus_dmamap_t map)
{
DPRINTF(("bus_dmamap_destroy: t = %p, map = %p\n", t, map));
DPRINTF(("%s: t = %p, map = %p\n", __func__, t, map));
free(map, M_DMAMAP);
}
@ -145,8 +148,11 @@ _bus_dmamap_load_paddr(bus_dma_tag_t t, bus_dmamap_t map,
nseg = *segp;
lastaddr = *lastaddrp;
DPRINTF(("_bus_dmamap_load_paddr: t = %p, map = %p, paddr = 0x%08lx, vaddr = 0x%08lx, size = %d\n", t, map, paddr, vaddr, size));
DPRINTF(("_bus_dmamap_load_paddr: nseg = %d, bmask = 0x%08lx, lastaddr = 0x%08lx\n", nseg, bmask, lastaddr));
DPRINTF(("%s: t = %p, map = %p, paddr = 0x%08lx,"
" vaddr = 0x%08lx, size = %d\n",
__func__, t, map, paddr, vaddr, size));
DPRINTF(("%s: nseg = %d, bmask = 0x%08lx, lastaddr = 0x%08lx\n",
__func__, nseg, bmask, lastaddr));
do {
sgsize = size;
@ -162,7 +168,7 @@ _bus_dmamap_load_paddr(bus_dma_tag_t t, bus_dmamap_t map,
sgsize = (baddr - paddr);
}
DPRINTF(("_bus_dmamap_load_paddr: sgsize = %d\n", sgsize));
DPRINTF(("%s: sgsize = %d\n", __func__, sgsize));
/*
* Insert chunk into a segment, coalescing with
@ -170,7 +176,7 @@ _bus_dmamap_load_paddr(bus_dma_tag_t t, bus_dmamap_t map,
*/
if (first) {
/* first segment */
DPRINTF(("_bus_dmamap_load_paddr: first\n"));
DPRINTF(("%s: first\n", __func__));
segs[nseg].ds_addr = SH3_PHYS_TO_P2SEG(paddr);
segs[nseg].ds_len = sgsize;
segs[nseg]._ds_vaddr = vaddr;
@ -181,14 +187,14 @@ _bus_dmamap_load_paddr(bus_dma_tag_t t, bus_dmamap_t map,
&& (map->_dm_boundary == 0 ||
(segs[nseg].ds_addr & bmask) == (paddr & bmask))) {
/* coalesce */
DPRINTF(("_bus_dmamap_load_paddr: coalesce\n"));
DPRINTF(("%s: coalesce\n", __func__));
segs[nseg].ds_len += sgsize;
} else {
if (++nseg >= map->_dm_segcnt) {
break;
}
/* new segment */
DPRINTF(("_bus_dmamap_load_paddr: new\n"));
DPRINTF(("%s: new\n", __func__));
segs[nseg].ds_addr = SH3_PHYS_TO_P2SEG(paddr);
segs[nseg].ds_len = sgsize;
segs[nseg]._ds_vaddr = vaddr;
@ -199,10 +205,13 @@ _bus_dmamap_load_paddr(bus_dma_tag_t t, bus_dmamap_t map,
paddr += sgsize;
vaddr += sgsize;
size -= sgsize;
DPRINTF(("_bus_dmamap_load_paddr: lastaddr = 0x%08lx, paddr = 0x%08lx, vaddr = 0x%08lx, size = %d\n", lastaddr, paddr, vaddr, size));
DPRINTF(("%s: lastaddr = 0x%08lx, paddr = 0x%08lx,"
" vaddr = 0x%08lx, size = %d\n",
__func__, lastaddr, paddr, vaddr, size));
} while (size > 0);
DPRINTF(("_bus_dmamap_load_paddr: nseg = %d\n", nseg));
DPRINTF(("%s: nseg = %d\n", __func__, nseg));
*segp = nseg;
*lastaddrp = lastaddr;
@ -234,7 +243,9 @@ _bus_bus_dmamap_load_buffer(bus_dma_tag_t t, bus_dmamap_t map, void *buf,
int first;
int error;
DPRINTF(("_bus_dmamap_load_buffer: t = %p, map = %p, buf = %p, buflen = %ld, p = %p, flags = %x\n", t, map, buf, buflen, p, flags));
DPRINTF(("%s: t = %p, map = %p, buf = %p, buflen = %ld,"
" p = %p, flags = %x\n",
__func__, t, map, buf, buflen, p, flags));
if (p != NULL)
pmap = p->p_vmspace->vm_map.pmap;
@ -284,7 +295,9 @@ _bus_dmamap_load(bus_dma_tag_t t, bus_dmamap_t map, void *buf,
int first;
int error;
DPRINTF(("bus_dmamap_load: t = %p, map = %p, buf = %p, buflen = %ld, p = %p, flags = %x\n", t, map, buf, buflen, p, flags));
DPRINTF(("%s: t = %p, map = %p, buf = %p, buflen = %ld,"
" p = %p, flags = %x\n",
__func__, t, map, buf, buflen, p, flags));
/*
* Make sure on error condition we return "no valid mappings."
@ -302,7 +315,7 @@ _bus_dmamap_load(bus_dma_tag_t t, bus_dmamap_t map, void *buf,
bus_size_t sgsize;
bus_size_t len = buflen;
DPRINTF(("bus_dmamap_load: P[12]SEG (0x%08lx)\n", addr));
DPRINTF(("%s: P[12]SEG (0x%08lx)\n", __func__, addr));
seg = 0;
first = 1;
@ -352,7 +365,8 @@ _bus_dmamap_load_mbuf(bus_dma_tag_t t, bus_dmamap_t map, struct mbuf *m0,
int first;
int error;
DPRINTF(("bus_dmamap_load_mbuf: t = %p, map = %p, m0 = %p, flags = %x\n", t, map, m0, flags));
DPRINTF(("%s: t = %p, map = %p, m0 = %p, flags = %x\n",
__func__, t, map, m0, flags));
/*
* Make sure on error condition we return "no valid mappings."
@ -427,7 +441,7 @@ void
_bus_dmamap_unload(bus_dma_tag_t t, bus_dmamap_t map)
{
DPRINTF(("bus_dmamap_unload: t = %p, map = %p\n", t, map));
DPRINTF(("%s: t = %p, map = %p\n", __func__, t, map));
map->dm_nsegs = 0;
map->dm_mapsize = 0;
@ -444,16 +458,14 @@ _bus_dmamap_sync(bus_dma_tag_t t, bus_dmamap_t map, bus_addr_t offset,
bus_addr_t addr, naddr;
int i;
DPRINTF(("bus_dmamap_sync: t = %p, map = %p, offset = %ld, len = %ld, ops = %x\n", t, map, offset, len, ops));
DPRINTF(("%s: t = %p, map = %p, offset = %ld, len = %ld, ops = %x\n",
__func__, t, map, offset, len, ops));
/*
* Mixing PRE and POST operations is not allowed.
*/
#ifdef DIAGNOSTIC
if ((ops & (BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE)) != 0 &&
(ops & (BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE)) != 0)
panic("_bus_dmamap_sync: mix PRE and POST");
#ifdef DIAGNOSTIC
if (offset >= map->dm_mapsize)
panic("_bus_dmamap_sync: bad offset");
if ((offset + len) > map->dm_mapsize)
@ -462,7 +474,7 @@ _bus_dmamap_sync(bus_dma_tag_t t, bus_dmamap_t map, bus_addr_t offset,
if (!sh_cache_enable_dcache) {
/* Nothing to do */
DPRINTF(("bus_dmamap_sync: disabled D-Cache\n"));
DPRINTF(("%s: disabled D-Cache\n", __func__));
return;
}
@ -486,15 +498,16 @@ _bus_dmamap_sync(bus_dma_tag_t t, bus_dmamap_t map, bus_addr_t offset,
if ((naddr >= SH3_P2SEG_BASE)
&& (naddr + minlen <= SH3_P2SEG_END)) {
DPRINTF(("bus_dmamap_sync: P2SEG (0x%08lx)\n", naddr));
DPRINTF(("%s: P2SEG (0x%08lx)\n", __func__, naddr));
offset = 0;
len -= minlen;
continue;
}
DPRINTF(("bus_dmamap_sync: flushing segment %d "
"(0x%lx+%lx, 0x%lx+0x%lx) (remain = %ld)\n",
i, addr, offset, addr, offset + minlen - 1, len));
DPRINTF(("%s: flushing segment %d "
"(0x%lx+%lx, 0x%lx+0x%lx) (remain = %ld)\n",
__func__, i,
addr, offset, addr, offset + minlen - 1, len));
switch (ops) {
case BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE:
@ -534,8 +547,12 @@ _bus_dmamem_alloc(bus_dma_tag_t t, bus_size_t size, bus_size_t alignment,
struct vm_page *m;
int curseg, error;
DPRINTF(("bus_dmamem_alloc: t = %p, size = %ld, alignment = %ld, boundary = %ld, segs = %p, nsegs = %d, rsegs = %p, flags = %x\n", t, size, alignment, boundary, segs, nsegs, rsegs, flags));
DPRINTF(("bus_dmamem_alloc: avail_start = 0x%08lx, avail_end = 0x%08lx\n", avail_start, avail_end));
DPRINTF(("%s: t = %p, size = %ld, alignment = %ld, boundary = %ld,"
" segs = %p, nsegs = %d, rsegs = %p, flags = %x\n",
__func__, t, size, alignment, boundary,
segs, nsegs, rsegs, flags));
DPRINTF(("%s: avail_start = 0x%08lx, avail_end = 0x%08lx\n",
__func__, avail_start, avail_end));
/* Always round the size. */
size = round_page(size);
@ -557,15 +574,17 @@ _bus_dmamem_alloc(bus_dma_tag_t t, bus_size_t size, bus_size_t alignment,
lastaddr = segs[curseg].ds_addr = VM_PAGE_TO_PHYS(m);
segs[curseg].ds_len = PAGE_SIZE;
DPRINTF(("bus_dmamem_alloc: m = %p, lastaddr = 0x%08lx\n",m,lastaddr));
DPRINTF(("%s: m = %p, lastaddr = 0x%08lx\n", __func__, m, lastaddr));
while ((m = TAILQ_NEXT(m, pageq)) != NULL) {
curaddr = VM_PAGE_TO_PHYS(m);
DPRINTF(("bus_dmamem_alloc: m = %p, curaddr = 0x%08lx, lastaddr = 0x%08lx\n", m, curaddr, lastaddr));
DPRINTF(("%s: m = %p, curaddr = 0x%08lx, lastaddr = 0x%08lx\n",
__func__, m, curaddr, lastaddr));
if (curaddr == (lastaddr + PAGE_SIZE)) {
segs[curseg].ds_len += PAGE_SIZE;
} else {
DPRINTF(("bus_dmamem_alloc: new segment\n"));
DPRINTF(("%s: new segment\n", __func__));
curseg++;
segs[curseg].ds_addr = curaddr;
segs[curseg].ds_len = PAGE_SIZE;
@ -575,7 +594,7 @@ _bus_dmamem_alloc(bus_dma_tag_t t, bus_size_t size, bus_size_t alignment,
*rsegs = curseg + 1;
DPRINTF(("bus_dmamem_alloc: curseg = %d, *rsegs = %d\n",curseg,*rsegs));
DPRINTF(("%s: curseg = %d, *rsegs = %d\n", __func__, curseg, *rsegs));
return (0);
}
@ -592,19 +611,23 @@ _bus_dmamem_free(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs)
struct pglist mlist;
int curseg;
DPRINTF(("bus_dmamem_free: t = %p, segs = %p, nsegs = %d\n", t, segs, nsegs));
DPRINTF(("%s: t = %p, segs = %p, nsegs = %d\n",
__func__, t, segs, nsegs));
/*
* Build a list of pages to free back to the VM system.
*/
TAILQ_INIT(&mlist);
for (curseg = 0; curseg < nsegs; curseg++) {
DPRINTF(("bus_dmamem_free: segs[%d]: ds_addr = 0x%08lx, ds_len = %ld\n", curseg, segs[curseg].ds_addr, segs[curseg].ds_len));
DPRINTF(("%s: segs[%d]: ds_addr = 0x%08lx, ds_len = %ld\n",
__func__, curseg,
segs[curseg].ds_addr, segs[curseg].ds_len));
for (addr = segs[curseg].ds_addr;
addr < (segs[curseg].ds_addr + segs[curseg].ds_len);
addr += PAGE_SIZE) {
m = PHYS_TO_VM_PAGE(addr);
DPRINTF(("bus_dmamem_free: m = %p\n", m));
DPRINTF(("%s: m = %p\n", __func__, m));
TAILQ_INSERT_TAIL(&mlist, m, pageq);
}
}
@ -622,9 +645,11 @@ _bus_dmamem_map(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs,
bus_addr_t addr;
int curseg;
DPRINTF(("bus_dmamem_map: t = %p, segs = %p, nsegs = %d, size = %d, kvap = %p, flags = %x\n", t, segs, nsegs, size, kvap, flags));
DPRINTF(("%s: t = %p, segs = %p, nsegs = %d, size = %d,"
" kvap = %p, flags = %x\n",
__func__, t, segs, nsegs, size, kvap, flags));
/*
/*
* If we're only mapping 1 segment, use P2SEG, to avoid
* TLB thrashing.
*/
@ -634,7 +659,8 @@ _bus_dmamem_map(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs,
} else {
*kvap = (void *)SH3_PHYS_TO_P1SEG(segs[0].ds_addr);
}
DPRINTF(("bus_dmamem_map: addr = 0x%08lx, kva = %p\n", segs[0].ds_addr, *kvap));
DPRINTF(("%s: addr = 0x%08lx, kva = %p\n",
__func__, segs[0].ds_addr, *kvap));
return 0;
}
@ -647,7 +673,10 @@ _bus_dmamem_map(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs,
*kvap = (void *)va;
for (curseg = 0; curseg < nsegs; curseg++) {
DPRINTF(("bus_dmamem_map: segs[%d]: ds_addr = 0x%08lx, ds_len = %ld\n", curseg, segs[curseg].ds_addr, segs[curseg].ds_len));
DPRINTF(("%s: segs[%d]: ds_addr = 0x%08lx, ds_len = %ld\n",
__func__, curseg,
segs[curseg].ds_addr, segs[curseg].ds_len));
for (addr = segs[curseg].ds_addr;
addr < segs[curseg].ds_addr + segs[curseg].ds_len;
addr += PAGE_SIZE, va += PAGE_SIZE, size -= PAGE_SIZE) {
@ -666,14 +695,15 @@ void
_bus_dmamem_unmap(bus_dma_tag_t t, void *kva, size_t size)
{
DPRINTF(("bus_dmamem_unmap: t = %p, kva = %p, size = %d\n", t, kva, size));
DPRINTF(("%s: t = %p, kva = %p, size = %d\n",
__func__, t, kva, size));
#ifdef DIAGNOSTIC
if ((u_long)kva & PAGE_MASK)
panic("_bus_dmamem_unmap");
#endif
/*
/*
* Nothing to do if we mapped it with P[12]SEG.
*/
if ((kva >= (void *)SH3_P1SEG_BASE)