diff options
author | phk <phk@FreeBSD.org> | 2004-09-15 12:09:50 +0000 |
---|---|---|
committer | phk <phk@FreeBSD.org> | 2004-09-15 12:09:50 +0000 |
commit | 1795816cf766cbe770384eb50bb559e0d9fba2a6 (patch) | |
tree | 56e89a43c4b2e1186b0edeeb3e43382456e0543e | |
parent | fe0362c5d20c4b60c70d896778b722b144ded3ed (diff) | |
download | FreeBSD-src-1795816cf766cbe770384eb50bb559e0d9fba2a6.zip FreeBSD-src-1795816cf766cbe770384eb50bb559e0d9fba2a6.tar.gz |
Add new a function isa_dma_init() which returns an errno when it fails
and which takes a M_WAITOK/M_NOWAIT flag argument.
Add compatibility isa_dmainit() macro which whines loudly if
isa_dma_init() fails.
Problem uncovered by: tegge
-rw-r--r-- | sys/alpha/isa/isa_dma.c | 18 | ||||
-rw-r--r-- | sys/amd64/isa/isa_dma.c | 24 | ||||
-rw-r--r-- | sys/i386/isa/isa_dma.c | 24 | ||||
-rw-r--r-- | sys/ia64/isa/isa_dma.c | 17 | ||||
-rw-r--r-- | sys/isa/isavar.h | 8 | ||||
-rw-r--r-- | sys/pc98/cbus/cbus_dma.c | 26 | ||||
-rw-r--r-- | sys/pc98/pc98/isa_dma.c | 26 | ||||
-rw-r--r-- | sys/vm/vm_page.c | 2 |
8 files changed, 70 insertions, 75 deletions
diff --git a/sys/alpha/isa/isa_dma.c b/sys/alpha/isa/isa_dma.c index 0c01fc5..91ca8bb 100644 --- a/sys/alpha/isa/isa_dma.c +++ b/sys/alpha/isa/isa_dma.c @@ -93,10 +93,8 @@ static int dmapageport[8] = { 0x87, 0x83, 0x81, 0x82, 0x8f, 0x8b, 0x89, 0x8a }; /* * Setup a DMA channel's bounce buffer. */ -void -isa_dmainit(chan, bouncebufsize) - int chan; - u_int bouncebufsize; +int +isa_dma_init(int chan, u_int bouncebufsize, int flag __unused) { static int initted = 0; bus_addr_t boundary = chan >= 4 ? 0x20000 : 0x10000; @@ -114,10 +112,10 @@ isa_dmainit(chan, bouncebufsize) #ifdef DIAGNOSTIC if (chan & ~VALID_DMA_MASK) - panic("isa_dmainit: channel out of range"); + panic("isa_dma_init: channel out of range"); if (dma_tag[chan] || dma_map[chan]) - panic("isa_dmainit: impossible request"); + panic("isa_dma_init: impossible request"); #endif if (bus_dma_tag_create(/*parent*/NULL, @@ -132,13 +130,13 @@ isa_dmainit(chan, bouncebufsize) /*lockfunc*/busdma_lock_mutex, /*lockarg*/&Giant, &dma_tag[chan]) != 0) { - panic("isa_dmainit: unable to create dma tag\n"); + panic("isa_dma_init: unable to create dma tag\n"); } if (bus_dmamap_create(dma_tag[chan], 0, &dma_map[chan])) { - panic("isa_dmainit: unable to create dma map\n"); + panic("isa_dma_init: unable to create dma map\n"); } - + return (0); } /* @@ -349,7 +347,7 @@ isa_dmastart(int flags, caddr_t addr, u_int nbytes, int chan) #endif if (!dma_tag || !dma_map[chan]) - panic("isa_dmastart: called without isa_dmainit"); + panic("isa_dmastart: called without isa_dma_init"); dma_busy |= (1 << chan); diff --git a/sys/amd64/isa/isa_dma.c b/sys/amd64/isa/isa_dma.c index 2017158..9bd5d01 100644 --- a/sys/amd64/isa/isa_dma.c +++ b/sys/amd64/isa/isa_dma.c @@ -96,15 +96,13 @@ static int dmapageport[8] = { 0x87, 0x83, 0x81, 0x82, 0x8f, 0x8b, 0x89, 0x8a }; /* * Setup a DMA channel's bounce buffer. */ -void -isa_dmainit(chan, bouncebufsize) - int chan; - u_int bouncebufsize; +int +isa_dma_init(int chan, u_int bouncebufsize, int flag) { void *buf; /* - * If a DMA channel is shared, both drivers have to call isa_dmainit + * If a DMA channel is shared, both drivers have to call isa_dma_init * since they don't know that the other driver will do it. * Just return if we're already set up good. * XXX: this only works if they agree on the bouncebuf size. This @@ -112,30 +110,30 @@ isa_dmainit(chan, bouncebufsize) * XXX: the same driver. */ if (dma_bouncebuf[chan] != NULL) - return; + return (0); #ifdef DIAGNOSTIC if (chan & ~VALID_DMA_MASK) - panic("isa_dmainit: channel out of range"); + panic("isa_dma_init: channel out of range"); #endif dma_bouncebufsize[chan] = bouncebufsize; /* Try malloc() first. It works better if it works. */ - buf = malloc(bouncebufsize, M_DEVBUF, M_NOWAIT); + buf = malloc(bouncebufsize, M_DEVBUF, flag); if (buf != NULL) { if (isa_dmarangecheck(buf, bouncebufsize, chan) == 0) { dma_bouncebuf[chan] = buf; - return; + return (0); } free(buf, M_DEVBUF); } - buf = contigmalloc(bouncebufsize, M_DEVBUF, M_NOWAIT, 0ul, 0xfffffful, + buf = contigmalloc(bouncebufsize, M_DEVBUF, flag, 0ul, 0xfffffful, 1ul, chan & 4 ? 0x20000ul : 0x10000ul); if (buf == NULL) - printf("isa_dmainit(%d, %d) failed\n", chan, bouncebufsize); - else - dma_bouncebuf[chan] = buf; + return (ENOMEM); + dma_bouncebuf[chan] = buf; + return (0); } /* diff --git a/sys/i386/isa/isa_dma.c b/sys/i386/isa/isa_dma.c index 23dc07d..1739871 100644 --- a/sys/i386/isa/isa_dma.c +++ b/sys/i386/isa/isa_dma.c @@ -94,15 +94,13 @@ static int dmapageport[8] = { 0x87, 0x83, 0x81, 0x82, 0x8f, 0x8b, 0x89, 0x8a }; /* * Setup a DMA channel's bounce buffer. */ -void -isa_dmainit(chan, bouncebufsize) - int chan; - u_int bouncebufsize; +int +isa_dma_init(int chan, u_int bouncebufsize, int flag) { void *buf; /* - * If a DMA channel is shared, both drivers have to call isa_dmainit + * If a DMA channel is shared, both drivers have to call isa_dma_init * since they don't know that the other driver will do it. * Just return if we're already set up good. * XXX: this only works if they agree on the bouncebuf size. This @@ -110,30 +108,30 @@ isa_dmainit(chan, bouncebufsize) * XXX: the same driver. */ if (dma_bouncebuf[chan] != NULL) - return; + return (0); #ifdef DIAGNOSTIC if (chan & ~VALID_DMA_MASK) - panic("isa_dmainit: channel out of range"); + panic("isa_dma_init: channel out of range"); #endif dma_bouncebufsize[chan] = bouncebufsize; /* Try malloc() first. It works better if it works. */ - buf = malloc(bouncebufsize, M_DEVBUF, M_NOWAIT); + buf = malloc(bouncebufsize, M_DEVBUF, flag); if (buf != NULL) { if (isa_dmarangecheck(buf, bouncebufsize, chan) == 0) { dma_bouncebuf[chan] = buf; - return; + return (0); } free(buf, M_DEVBUF); } - buf = contigmalloc(bouncebufsize, M_DEVBUF, M_NOWAIT, 0ul, 0xfffffful, + buf = contigmalloc(bouncebufsize, M_DEVBUF, flag, 0ul, 0xfffffful, 1ul, chan & 4 ? 0x20000ul : 0x10000ul); if (buf == NULL) - printf("isa_dmainit(%d, %d) failed\n", chan, bouncebufsize); - else - dma_bouncebuf[chan] = buf; + return (ENOMEM); + dma_bouncebuf[chan] = buf; + return (0); } /* diff --git a/sys/ia64/isa/isa_dma.c b/sys/ia64/isa/isa_dma.c index cd7fd69..08ead75 100644 --- a/sys/ia64/isa/isa_dma.c +++ b/sys/ia64/isa/isa_dma.c @@ -91,10 +91,8 @@ static int dmapageport[8] = { 0x87, 0x83, 0x81, 0x82, 0x8f, 0x8b, 0x89, 0x8a }; /* * Setup a DMA channel's bounce buffer. */ -void -isa_dmainit(chan, bouncebufsize) - int chan; - u_int bouncebufsize; +int +isa_dma_init(int chan, u_int bouncebufsize, int flag __unused) { static int initted = 0; bus_addr_t boundary = chan >= 4 ? 0x20000 : 0x10000; @@ -112,10 +110,10 @@ isa_dmainit(chan, bouncebufsize) #ifdef DIAGNOSTIC if (chan & ~VALID_DMA_MASK) - panic("isa_dmainit: channel out of range"); + panic("isa_dma_init: channel out of range"); if (dma_tag[chan] || dma_map[chan]) - panic("isa_dmainit: impossible request"); + panic("isa_dma_init: impossible request"); #endif if (bus_dma_tag_create(/*parent*/NULL, @@ -130,13 +128,14 @@ isa_dmainit(chan, bouncebufsize) /*lockfunc*/busdma_lock_mutex, /*lockarg*/&Giant, &dma_tag[chan]) != 0) { - panic("isa_dmainit: unable to create dma tag\n"); + panic("isa_dma_init: unable to create dma tag\n"); } if (bus_dmamap_create(dma_tag[chan], 0, &dma_map[chan])) { - panic("isa_dmainit: unable to create dma map\n"); + panic("isa_dma_init: unable to create dma map\n"); } + return (0); } /* @@ -351,7 +350,7 @@ isa_dmastart(int flags, caddr_t addr, u_int nbytes, int chan) #endif if (!dma_tag || !dma_map[chan]) - panic("isa_dmastart: called without isa_dmainit"); + panic("isa_dmastart: called without isa_dma_init"); dma_busy |= (1 << chan); diff --git a/sys/isa/isavar.h b/sys/isa/isavar.h index 5a7621e..811a721 100644 --- a/sys/isa/isavar.h +++ b/sys/isa/isavar.h @@ -160,13 +160,19 @@ extern void isa_probe_children(device_t dev); extern void isa_dmacascade(int chan); extern void isa_dmadone(int flags, caddr_t addr, int nbytes, int chan); -extern void isa_dmainit(int chan, u_int bouncebufsize); +extern int isa_dma_init(int chan, u_int bouncebufsize, int flag); extern void isa_dmastart(int flags, caddr_t addr, u_int nbytes, int chan); extern int isa_dma_acquire(int chan); extern void isa_dma_release(int chan); extern int isa_dmastatus(int chan); extern int isa_dmastop(int chan); +#define isa_dmainit(chan, size) do { \ + if (isa_dma_init(chan, size, M_NOWAIT)) \ + printf("WARNING: isa_dma_init(%d, %ju) failed\n", \ + (int)(chan), (uintmax_t)(size)); \ + } while (0) + int isab_attach(device_t dev); #ifdef PC98 diff --git a/sys/pc98/cbus/cbus_dma.c b/sys/pc98/cbus/cbus_dma.c index e9d4604..25f52f9 100644 --- a/sys/pc98/cbus/cbus_dma.c +++ b/sys/pc98/cbus/cbus_dma.c @@ -123,16 +123,14 @@ static int dmapageport[8] = { 0x87, 0x83, 0x81, 0x82, 0x8f, 0x8b, 0x89, 0x8a }; /* * Setup a DMA channel's bounce buffer. */ -void -isa_dmainit(chan, bouncebufsize) - int chan; - u_int bouncebufsize; +int +isa_dma_init(int chan, u_int bouncebufsize, int flag) { void *buf; #ifndef PC98 /* - * If a DMA channel is shared, both drivers have to call isa_dmainit + * If a DMA channel is shared, both drivers have to call isa_dma_init * since they don't know that the other driver will do it. * Just return if we're already set up good. * XXX: this only works if they agree on the bouncebuf size. This @@ -140,35 +138,35 @@ isa_dmainit(chan, bouncebufsize) * XXX: the same driver. */ if (dma_bouncebuf[chan] != NULL) - return; + return (0); #endif #ifdef DIAGNOSTIC if (chan & ~VALID_DMA_MASK) - panic("isa_dmainit: channel out of range"); + panic("isa_dma_init: channel out of range"); #ifdef PC98 if (dma_bouncebuf[chan] != NULL) - panic("isa_dmainit: impossible request"); + panic("isa_dma_init: impossible request"); #endif #endif dma_bouncebufsize[chan] = bouncebufsize; /* Try malloc() first. It works better if it works. */ - buf = malloc(bouncebufsize, M_DEVBUF, M_NOWAIT); + buf = malloc(bouncebufsize, M_DEVBUF, flag); if (buf != NULL) { if (isa_dmarangecheck(buf, bouncebufsize, chan) == 0) { dma_bouncebuf[chan] = buf; - return; + return (0); } free(buf, M_DEVBUF); } - buf = contigmalloc(bouncebufsize, M_DEVBUF, M_NOWAIT, 0ul, 0xfffffful, + buf = contigmalloc(bouncebufsize, M_DEVBUF, flag, 0ul, 0xfffffful, 1ul, chan & 4 ? 0x20000ul : 0x10000ul); if (buf == NULL) - printf("isa_dmainit(%d, %d) failed\n", chan, bouncebufsize); - else - dma_bouncebuf[chan] = buf; + return (ENOMEM); + dma_bouncebuf[chan] = buf; + return (0); } /* diff --git a/sys/pc98/pc98/isa_dma.c b/sys/pc98/pc98/isa_dma.c index e9d4604..25f52f9 100644 --- a/sys/pc98/pc98/isa_dma.c +++ b/sys/pc98/pc98/isa_dma.c @@ -123,16 +123,14 @@ static int dmapageport[8] = { 0x87, 0x83, 0x81, 0x82, 0x8f, 0x8b, 0x89, 0x8a }; /* * Setup a DMA channel's bounce buffer. */ -void -isa_dmainit(chan, bouncebufsize) - int chan; - u_int bouncebufsize; +int +isa_dma_init(int chan, u_int bouncebufsize, int flag) { void *buf; #ifndef PC98 /* - * If a DMA channel is shared, both drivers have to call isa_dmainit + * If a DMA channel is shared, both drivers have to call isa_dma_init * since they don't know that the other driver will do it. * Just return if we're already set up good. * XXX: this only works if they agree on the bouncebuf size. This @@ -140,35 +138,35 @@ isa_dmainit(chan, bouncebufsize) * XXX: the same driver. */ if (dma_bouncebuf[chan] != NULL) - return; + return (0); #endif #ifdef DIAGNOSTIC if (chan & ~VALID_DMA_MASK) - panic("isa_dmainit: channel out of range"); + panic("isa_dma_init: channel out of range"); #ifdef PC98 if (dma_bouncebuf[chan] != NULL) - panic("isa_dmainit: impossible request"); + panic("isa_dma_init: impossible request"); #endif #endif dma_bouncebufsize[chan] = bouncebufsize; /* Try malloc() first. It works better if it works. */ - buf = malloc(bouncebufsize, M_DEVBUF, M_NOWAIT); + buf = malloc(bouncebufsize, M_DEVBUF, flag); if (buf != NULL) { if (isa_dmarangecheck(buf, bouncebufsize, chan) == 0) { dma_bouncebuf[chan] = buf; - return; + return (0); } free(buf, M_DEVBUF); } - buf = contigmalloc(bouncebufsize, M_DEVBUF, M_NOWAIT, 0ul, 0xfffffful, + buf = contigmalloc(bouncebufsize, M_DEVBUF, flag, 0ul, 0xfffffful, 1ul, chan & 4 ? 0x20000ul : 0x10000ul); if (buf == NULL) - printf("isa_dmainit(%d, %d) failed\n", chan, bouncebufsize); - else - dma_bouncebuf[chan] = buf; + return (ENOMEM); + dma_bouncebuf[chan] = buf; + return (0); } /* diff --git a/sys/vm/vm_page.c b/sys/vm/vm_page.c index e9adf50..91683a6 100644 --- a/sys/vm/vm_page.c +++ b/sys/vm/vm_page.c @@ -263,7 +263,7 @@ vm_page_startup(vm_offset_t vaddr) * Construct the free queue(s) in descending order (by physical * address) so that the first 16MB of physical memory is allocated * last rather than first. On large-memory machines, this avoids - * the exhaustion of low physical memory before isa_dmainit has run. + * the exhaustion of low physical memory before isa_dma_init has run. */ cnt.v_page_count = 0; cnt.v_free_count = 0; |