1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-12 09:58:36 +00:00

Implement bus_dmamem_alloc_size() and bus_dmamem_free_size() as

counterparts to bus_dmamem_alloc() and bus_dmamem_free().  This allows
the caller to specify the size of the allocation instead of it defaulting
to the max_size field of the busdma tag.

This is intended to aid in converting drivers to busdma.  Lots of
hardware cannot understand scatter/gather lists, which forces the
driver to copy the i/o buffers to a single contiguous region
before sending it to the hardware.  Without these new methods, this
would require a new busdma tag for each operation, or a complex
internal allocator/cache for each driver.

Allocations greater than PAGE_SIZE are rounded up to the next
PAGE_SIZE by contigmalloc(), so this is not suitable for multiple
static allocations that would be better served by a single
fixed-length subdivided allocation.

Reviewed by:	jake (sparc64)
This commit is contained in:
Scott Long 2003-01-29 07:25:27 +00:00
parent 9db58771e0
commit 5193a34646
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=110030
13 changed files with 250 additions and 41 deletions

View File

@ -350,14 +350,18 @@ bus_dmamap_destroy(bus_dma_tag_t dmat, bus_dmamap_t map)
* A dmamap to for use with dmamap_load is also allocated.
*/
int
bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
bus_dmamap_t *mapp)
bus_dmamem_alloc_size(bus_dma_tag_t dmat, void** vaddr, int flags,
bus_dmamap_t *mapp, bus_size_t size)
{
if (size > dmat->maxsize)
return (ENOMEM);
/* If we succeed, no mapping/bouncing will be required */
*mapp = &nobounce_dmamap;
if ((dmat->maxsize <= PAGE_SIZE) && dmat->lowaddr >= ptoa(Maxmem)) {
*vaddr = malloc(dmat->maxsize, M_DEVBUF,
if ((size <= PAGE_SIZE) && dmat->lowaddr >= ptoa(Maxmem)) {
*vaddr = malloc(size, M_DEVBUF,
(flags & BUS_DMA_NOWAIT) ? M_NOWAIT : 0);
} else {
/*
@ -365,7 +369,7 @@ bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
* and handles multi-seg allocations. Nobody is doing
* multi-seg allocations yet though.
*/
*vaddr = contigmalloc(dmat->maxsize, M_DEVBUF,
*vaddr = contigmalloc(size, M_DEVBUF,
(flags & BUS_DMA_NOWAIT) ? M_NOWAIT : 0,
0ul, dmat->lowaddr, dmat->alignment? dmat->alignment : 1ul,
dmat->boundary);
@ -375,12 +379,20 @@ bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
return (0);
}
int
bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
bus_dmamap_t *mapp)
{
return (bus_dmamem_alloc_size(dmat, vaddr, flags, mapp, dmat->maxsize));
}
/*
* Free a piece of memory and it's allociated dmamap, that was allocated
* via bus_dmamem_alloc.
*/
void
bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map)
bus_dmamem_free_size(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map,
bus_size_t size)
{
/*
* dmamem does not need to be bounced, so the map should be
@ -388,10 +400,16 @@ bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map)
*/
if (map != &nobounce_dmamap)
panic("bus_dmamem_free: Invalid map freed\n");
if ((dmat->maxsize <= PAGE_SIZE) && dmat->lowaddr >= ptoa(Maxmem))
if ((size <= PAGE_SIZE) && dmat->lowaddr >= ptoa(Maxmem))
free(vaddr, M_DEVBUF);
else
contigfree(vaddr, dmat->maxsize, M_DEVBUF);
contigfree(vaddr, size, M_DEVBUF);
}
void
bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map)
{
bus_dmamem_free_size(dmat, vaddr, map, dmat->maxsize);
}
#define BUS_DMAMAP_NSEGS ((BUS_SPACE_MAXSIZE / PAGE_SIZE) + 1)

View File

@ -571,6 +571,9 @@ int bus_dmamap_destroy(bus_dma_tag_t dmat, bus_dmamap_t map);
* bus device space based on the constraints lited in the dma tag.
* A dmamap to for use with dmamap_load is also allocated.
*/
int bus_dmamem_alloc_size(bus_dma_tag_t dmat, void** vaddr, int flags,
bus_dmamap_t *mapp, bus_size_t size);
int bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
bus_dmamap_t *mapp);
@ -578,6 +581,9 @@ int bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
* Free a piece of memory and it's allociated dmamap, that was allocated
* via bus_dmamem_alloc.
*/
void bus_dmamem_free_size(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map,
bus_size_t size);
void bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map);
/*

View File

@ -331,14 +331,18 @@ bus_dmamap_destroy(bus_dma_tag_t dmat, bus_dmamap_t map)
* A dmamap to for use with dmamap_load is also allocated.
*/
int
bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
bus_dmamap_t *mapp)
bus_dmamem_alloc_size(bus_dma_tag_t dmat, void** vaddr, int flags,
bus_dmamap_t *mapp, bus_size_t size)
{
if (size > dmat->maxsize)
return (ENOMEM);
/* If we succeed, no mapping/bouncing will be required */
*mapp = NULL;
if ((dmat->maxsize <= PAGE_SIZE) && dmat->lowaddr >= ptoa(Maxmem)) {
*vaddr = malloc(dmat->maxsize, M_DEVBUF,
if ((size <= PAGE_SIZE) && dmat->lowaddr >= ptoa(Maxmem)) {
*vaddr = malloc(size, M_DEVBUF,
(flags & BUS_DMA_NOWAIT) ? M_NOWAIT : 0);
} else {
/*
@ -346,7 +350,7 @@ bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
* and handles multi-seg allocations. Nobody is doing
* multi-seg allocations yet though.
*/
*vaddr = contigmalloc(dmat->maxsize, M_DEVBUF,
*vaddr = contigmalloc(size, M_DEVBUF,
(flags & BUS_DMA_NOWAIT) ? M_NOWAIT : 0,
0ul, dmat->lowaddr, dmat->alignment? dmat->alignment : 1ul,
dmat->boundary);
@ -356,12 +360,20 @@ bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
return (0);
}
int
bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
bus_dmamap_t *mapp)
{
return (bus_dmamem_alloc_size(dmat, vaddr, flags, mapp, dmat->maxsize));
}
/*
* Free a piece of memory and it's allociated dmamap, that was allocated
* via bus_dmamem_alloc. Make the same choice for free/contigfree.
*/
void
bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map)
bus_dmamem_free_size(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map,
bus_size_t size)
{
/*
* dmamem does not need to be bounced, so the map should be
@ -369,10 +381,16 @@ bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map)
*/
if (map != NULL)
panic("bus_dmamem_free: Invalid map freed\n");
if ((dmat->maxsize <= PAGE_SIZE) && dmat->lowaddr >= ptoa(Maxmem))
if ((size <= PAGE_SIZE) && dmat->lowaddr >= ptoa(Maxmem))
free(vaddr, M_DEVBUF);
else
contigfree(vaddr, dmat->maxsize, M_DEVBUF);
contigfree(vaddr, size, M_DEVBUF);
}
void
bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map)
{
bus_dmamem_free_size(dmat, vaddr, map, dmat->maxsize);
}
#define BUS_DMAMAP_NSEGS ((BUS_SPACE_MAXSIZE / PAGE_SIZE) + 1)

View File

@ -180,6 +180,9 @@ int bus_dmamap_destroy(bus_dma_tag_t dmat, bus_dmamap_t map);
* bus device space based on the constraints lited in the dma tag.
* A dmamap to for use with dmamap_load is also allocated.
*/
int bus_dmamem_alloc_size(bus_dma_tag_t dmat, void** vaddr, int flags,
bus_dmamap_t *mapp, bus_size_t size);
int bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
bus_dmamap_t *mapp);
@ -187,6 +190,9 @@ int bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
* Free a piece of memory and it's allociated dmamap, that was allocated
* via bus_dmamem_alloc.
*/
void bus_dmamem_free_size(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map,
bus_size_t size);
void bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map);
/*

View File

@ -331,14 +331,18 @@ bus_dmamap_destroy(bus_dma_tag_t dmat, bus_dmamap_t map)
* A dmamap to for use with dmamap_load is also allocated.
*/
int
bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
bus_dmamap_t *mapp)
bus_dmamem_alloc_size(bus_dma_tag_t dmat, void** vaddr, int flags,
bus_dmamap_t *mapp, bus_size_t size)
{
if (size > dmat->maxsize)
return (ENOMEM);
/* If we succeed, no mapping/bouncing will be required */
*mapp = NULL;
if ((dmat->maxsize <= PAGE_SIZE) && dmat->lowaddr >= ptoa(Maxmem)) {
*vaddr = malloc(dmat->maxsize, M_DEVBUF,
if ((size <= PAGE_SIZE) && dmat->lowaddr >= ptoa(Maxmem)) {
*vaddr = malloc(size, M_DEVBUF,
(flags & BUS_DMA_NOWAIT) ? M_NOWAIT : 0);
} else {
/*
@ -346,7 +350,7 @@ bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
* and handles multi-seg allocations. Nobody is doing
* multi-seg allocations yet though.
*/
*vaddr = contigmalloc(dmat->maxsize, M_DEVBUF,
*vaddr = contigmalloc(size, M_DEVBUF,
(flags & BUS_DMA_NOWAIT) ? M_NOWAIT : 0,
0ul, dmat->lowaddr, dmat->alignment? dmat->alignment : 1ul,
dmat->boundary);
@ -356,12 +360,20 @@ bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
return (0);
}
int
bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
bus_dmamap_t *mapp)
{
return (bus_dmamem_alloc_size(dmat, vaddr, flags, mapp, dmat->maxsize));
}
/*
* Free a piece of memory and it's allociated dmamap, that was allocated
* via bus_dmamem_alloc. Make the same choice for free/contigfree.
*/
void
bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map)
bus_dmamem_free_size(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map,
bus_size_t size)
{
/*
* dmamem does not need to be bounced, so the map should be
@ -369,10 +381,16 @@ bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map)
*/
if (map != NULL)
panic("bus_dmamem_free: Invalid map freed\n");
if ((dmat->maxsize <= PAGE_SIZE) && dmat->lowaddr >= ptoa(Maxmem))
if ((size <= PAGE_SIZE) && dmat->lowaddr >= ptoa(Maxmem))
free(vaddr, M_DEVBUF);
else
contigfree(vaddr, dmat->maxsize, M_DEVBUF);
contigfree(vaddr, size, M_DEVBUF);
}
void
bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map)
{
bus_dmamem_free_size(dmat, vaddr, map, dmat->maxsize);
}
#define BUS_DMAMAP_NSEGS ((BUS_SPACE_MAXSIZE / PAGE_SIZE) + 1)

View File

@ -180,6 +180,9 @@ int bus_dmamap_destroy(bus_dma_tag_t dmat, bus_dmamap_t map);
* bus device space based on the constraints lited in the dma tag.
* A dmamap to for use with dmamap_load is also allocated.
*/
int bus_dmamem_alloc_size(bus_dma_tag_t dmat, void** vaddr, int flags,
bus_dmamap_t *mapp, bus_size_t size);
int bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
bus_dmamap_t *mapp);
@ -187,6 +190,9 @@ int bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
* Free a piece of memory and it's allociated dmamap, that was allocated
* via bus_dmamem_alloc.
*/
void bus_dmamem_free_size(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map,
bus_size_t size);
void bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map);
/*

View File

@ -971,8 +971,12 @@ struct bus_dma_tag {
/*
* DMA memory utility functions.
*/
int (*dt_dmamem_alloc_size)(bus_dma_tag_t, bus_dma_tag_t, void **,
int, bus_dmamap_t *, bus_size_t size);
int (*dt_dmamem_alloc)(bus_dma_tag_t, bus_dma_tag_t, void **, int,
bus_dmamap_t *);
void (*dt_dmamem_free_size)(bus_dma_tag_t, bus_dma_tag_t, void *,
bus_dmamap_t, bus_size_t size);
void (*dt_dmamem_free)(bus_dma_tag_t, bus_dma_tag_t, void *,
bus_dmamap_t);
};
@ -1083,6 +1087,19 @@ sparc64_dmamap_sync(bus_dma_tag_t pt, bus_dma_tag_t dt, bus_dmamap_t m,
#define bus_dmamap_sync(t, m, op) \
sparc64_dmamap_sync((t), (t), (m), (op))
static __inline int
sparc64_dmamem_alloc_size(bus_dma_tag_t pt, bus_dma_tag_t dt, void **v, int f,
bus_dmamap_t *m, bus_size_t s)
{
bus_dma_tag_t lt;
for (lt = pt; lt->dmamem_alloc == NULL; lt = lt->parent)
;
return ((*lt->dmamem_alloc_size)(lt, dt, v, f, m, s));
}
#define bus_dmamem_alloc_size(t, v, f, m, s) \
sparc64_dmamem_alloc_size((t), (t), (v), (f), (m), (s))
static __inline int
sparc64_dmamem_alloc(bus_dma_tag_t pt, bus_dma_tag_t dt, void **v, int f,
bus_dmamap_t *m)
@ -1096,6 +1113,19 @@ sparc64_dmamem_alloc(bus_dma_tag_t pt, bus_dma_tag_t dt, void **v, int f,
#define bus_dmamem_alloc(t, v, f, m) \
sparc64_dmamem_alloc((t), (t), (v), (f), (m))
static __inline void
sparc64_dmamem_free_size(bus_dma_tag_t pt, bus_dma_tag_t dt, void *v,
bus_dmamap_t m, bus_size_t s)
{
bus_dma_tag_t lt;
for (lt = pt; lt->dmamem_free == NULL; lt = lt->parent)
;
(*lt->dmamem_free_size)(lt, dt, v, m, s);
}
#define bus_dmamem_free_size(t, v, m, s) \
sparc64_dmamem_free_size((t), (t), (v), (m), (s))
static __inline void
sparc64_dmamem_free(bus_dma_tag_t pt, bus_dma_tag_t dt, void *v,
bus_dmamap_t m)

View File

@ -95,8 +95,12 @@ void iommu_dvmamap_unload(bus_dma_tag_t, bus_dma_tag_t, struct iommu_state *,
bus_dmamap_t);
void iommu_dvmamap_sync(bus_dma_tag_t, bus_dma_tag_t, struct iommu_state *,
bus_dmamap_t, bus_dmasync_op_t);
int iommu_dvmamem_alloc_size(bus_dma_tag_t, bus_dma_tag_t, struct iommu_state *,
void **, int, bus_dmamap_t *, bus_size_t size);
int iommu_dvmamem_alloc(bus_dma_tag_t, bus_dma_tag_t, struct iommu_state *,
void **, int, bus_dmamap_t *);
void iommu_dvmamem_free_size(bus_dma_tag_t, bus_dma_tag_t, struct iommu_state *,
void *, bus_dmamap_t, bus_size_t size);
void iommu_dvmamem_free(bus_dma_tag_t, bus_dma_tag_t, struct iommu_state *,
void *, bus_dmamap_t);

View File

@ -113,8 +113,12 @@ static int psycho_dmamap_load_uio(bus_dma_tag_t, bus_dma_tag_t, bus_dmamap_t,
static void psycho_dmamap_unload(bus_dma_tag_t, bus_dma_tag_t, bus_dmamap_t);
static void psycho_dmamap_sync(bus_dma_tag_t, bus_dma_tag_t, bus_dmamap_t,
bus_dmasync_op_t);
static int psycho_dmamem_alloc_size(bus_dma_tag_t, bus_dma_tag_t, void **, int,
bus_dmamap_t *, bus_size_t size);
static int psycho_dmamem_alloc(bus_dma_tag_t, bus_dma_tag_t, void **, int,
bus_dmamap_t *);
static void psycho_dmamem_free_size(bus_dma_tag_t, bus_dma_tag_t, void *,
bus_dmamap_t, bus_size_t size);
static void psycho_dmamem_free(bus_dma_tag_t, bus_dma_tag_t, void *,
bus_dmamap_t);
@ -497,7 +501,9 @@ psycho_attach(device_t dev)
sc->sc_dmat->dt_dmamap_load_uio = psycho_dmamap_load_uio;
sc->sc_dmat->dt_dmamap_unload = psycho_dmamap_unload;
sc->sc_dmat->dt_dmamap_sync = psycho_dmamap_sync;
sc->sc_dmat->dt_dmamem_alloc_size = psycho_dmamem_alloc_size;
sc->sc_dmat->dt_dmamem_alloc = psycho_dmamem_alloc;
sc->sc_dmat->dt_dmamem_free_size = psycho_dmamem_free_size;
sc->sc_dmat->dt_dmamem_free = psycho_dmamem_free;
/* XXX: register as root dma tag (kluge). */
sparc64_root_dma_tag = sc->sc_dmat;
@ -1313,6 +1319,17 @@ psycho_alloc_bus_tag(struct psycho_softc *sc, int type)
/*
* hooks into the iommu dvma calls.
*/
static int
psycho_dmamem_alloc_size(bus_dma_tag_t pdmat, bus_dma_tag_t ddmat, void **vaddr,
int flags, bus_dmamap_t *mapp, bus_size_t size)
{
struct psycho_softc *sc;
sc = (struct psycho_softc *)pdmat->cookie;
return (iommu_dvmamem_alloc_size(pdmat, ddmat, sc->sc_is, vaddr, flags,
mapp, size));
}
static int
psycho_dmamem_alloc(bus_dma_tag_t pdmat, bus_dma_tag_t ddmat, void **vaddr,
int flags, bus_dmamap_t *mapp)
@ -1324,6 +1341,16 @@ psycho_dmamem_alloc(bus_dma_tag_t pdmat, bus_dma_tag_t ddmat, void **vaddr,
mapp));
}
static void
psycho_dmamem_free_size(bus_dma_tag_t pdmat, bus_dma_tag_t ddmat, void *vaddr,
bus_dmamap_t map, bus_size_t size)
{
struct psycho_softc *sc;
sc = (struct psycho_softc *)pdmat->cookie;
iommu_dvmamem_free_size(pdmat, ddmat, sc->sc_is, vaddr, map, size);
}
static void
psycho_dmamem_free(bus_dma_tag_t pdmat, bus_dma_tag_t ddmat, void *vaddr,
bus_dmamap_t map)

View File

@ -244,8 +244,12 @@ static int sbus_dmamap_load_uio(bus_dma_tag_t, bus_dma_tag_t, bus_dmamap_t,
static void sbus_dmamap_unload(bus_dma_tag_t, bus_dma_tag_t, bus_dmamap_t);
static void sbus_dmamap_sync(bus_dma_tag_t, bus_dma_tag_t, bus_dmamap_t,
bus_dmasync_op_t);
static int sbus_dmamem_alloc_size(bus_dma_tag_t, bus_dma_tag_t, void **, int,
bus_dmamap_t *, bus_size_t size);
static int sbus_dmamem_alloc(bus_dma_tag_t, bus_dma_tag_t, void **, int,
bus_dmamap_t *);
static void sbus_dmamem_free_size(bus_dma_tag_t, bus_dma_tag_t, void *,
bus_dmamap_t, bus_size_t);
static void sbus_dmamem_free(bus_dma_tag_t, bus_dma_tag_t, void *,
bus_dmamap_t);
@ -349,7 +353,9 @@ sbus_probe(device_t dev)
sc->sc_cdmatag->dt_dmamap_load_uio = sbus_dmamap_load_uio;
sc->sc_cdmatag->dt_dmamap_unload = sbus_dmamap_unload;
sc->sc_cdmatag->dt_dmamap_sync = sbus_dmamap_sync;
sc->sc_cdmatag->dt_dmamem_alloc_size = sbus_dmamem_alloc_size;
sc->sc_cdmatag->dt_dmamem_alloc = sbus_dmamem_alloc;
sc->sc_cdmatag->dt_dmamem_free_size = sbus_dmamem_free_size;
sc->sc_cdmatag->dt_dmamem_free = sbus_dmamem_free;
/* XXX: register as root dma tag (kluge). */
sparc64_root_dma_tag = sc->sc_cdmatag;
@ -987,6 +993,16 @@ sbus_dmamap_sync(bus_dma_tag_t pdmat, bus_dma_tag_t ddmat, bus_dmamap_t map,
iommu_dvmamap_sync(pdmat, ddmat, &sc->sc_is, map, op);
}
static int
sbus_dmamem_alloc_size(bus_dma_tag_t pdmat, bus_dma_tag_t ddmat, void **vaddr,
int flags, bus_dmamap_t *mapp, bus_size_t size)
{
struct sbus_softc *sc = (struct sbus_softc *)pdmat->cookie;
return (iommu_dvmamem_alloc_size(pdmat, ddmat, &sc->sc_is, vaddr, flags,
mapp, size));
}
static int
sbus_dmamem_alloc(bus_dma_tag_t pdmat, bus_dma_tag_t ddmat, void **vaddr,
int flags, bus_dmamap_t *mapp)
@ -997,6 +1013,15 @@ sbus_dmamem_alloc(bus_dma_tag_t pdmat, bus_dma_tag_t ddmat, void **vaddr,
mapp));
}
static void
sbus_dmamem_free_size(bus_dma_tag_t pdmat, bus_dma_tag_t ddmat, void *vaddr,
bus_dmamap_t map, bus_size_t size)
{
struct sbus_softc *sc = (struct sbus_softc *)pdmat->cookie;
iommu_dvmamem_free_size(pdmat, ddmat, &sc->sc_is, vaddr, map, size);
}
static void
sbus_dmamem_free(bus_dma_tag_t pdmat, bus_dma_tag_t ddmat, void *vaddr,
bus_dmamap_t map)

View File

@ -168,8 +168,12 @@ static int nexus_dmamap_load_uio(bus_dma_tag_t, bus_dma_tag_t, bus_dmamap_t,
static void nexus_dmamap_unload(bus_dma_tag_t, bus_dma_tag_t, bus_dmamap_t);
static void nexus_dmamap_sync(bus_dma_tag_t, bus_dma_tag_t, bus_dmamap_t,
bus_dmasync_op_t);
static int nexus_dmamem_alloc_size(bus_dma_tag_t, bus_dma_tag_t, void **, int,
bus_dmamap_t *, u_long size);
static int nexus_dmamem_alloc(bus_dma_tag_t, bus_dma_tag_t, void **, int,
bus_dmamap_t *);
static void nexus_dmamem_free_size(bus_dma_tag_t, bus_dma_tag_t, void *,
bus_dmamap_t, u_long size);
static void nexus_dmamem_free(bus_dma_tag_t, bus_dma_tag_t, void *,
bus_dmamap_t);
@ -222,7 +226,9 @@ bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t alignment,
newtag->dt_dmamap_load_uio = NULL;
newtag->dt_dmamap_unload = NULL;
newtag->dt_dmamap_sync = NULL;
newtag->dt_dmamem_alloc_size = NULL;
newtag->dt_dmamem_alloc = NULL;
newtag->dt_dmamem_free_size = NULL;
newtag->dt_dmamem_free = NULL;
/* Take into account any restrictions imposed by our parent tag */
@ -604,12 +610,15 @@ sparc64_dmamem_free_map(bus_dma_tag_t dmat, bus_dmamap_t map)
* by bus-specific DMA memory allocation functions.
*/
static int
nexus_dmamem_alloc(bus_dma_tag_t pdmat, bus_dma_tag_t ddmat, void **vaddr,
int flags, bus_dmamap_t *mapp)
nexus_dmamem_alloc_size(bus_dma_tag_t pdmat, bus_dma_tag_t ddmat, void **vaddr,
int flags, bus_dmamap_t *mapp, bus_size_t size)
{
if ((ddmat->dt_maxsize <= PAGE_SIZE)) {
*vaddr = malloc(ddmat->dt_maxsize, M_DEVBUF,
if (size > ddmat->dt_maxsize)
return (ENOMEM);
if ((size <= PAGE_SIZE)) {
*vaddr = malloc(size, M_DEVBUF,
(flags & BUS_DMA_NOWAIT) ? M_NOWAIT : 0);
} else {
/*
@ -617,7 +626,7 @@ nexus_dmamem_alloc(bus_dma_tag_t pdmat, bus_dma_tag_t ddmat, void **vaddr,
* and handles multi-seg allocations. Nobody is doing multi-seg
* allocations yet though.
*/
*vaddr = contigmalloc(ddmat->dt_maxsize, M_DEVBUF,
*vaddr = contigmalloc(size, M_DEVBUF,
(flags & BUS_DMA_NOWAIT) ? M_NOWAIT : 0,
0ul, ddmat->dt_lowaddr,
ddmat->dt_alignment ? ddmat->dt_alignment : 1UL,
@ -630,20 +639,35 @@ nexus_dmamem_alloc(bus_dma_tag_t pdmat, bus_dma_tag_t ddmat, void **vaddr,
return (0);
}
static int
nexus_dmamem_alloc(bus_dma_tag_t pdmat, bus_dma_tag_t ddmat, void **vaddr,
int flags, bus_dmamap_t *mapp)
{
return (sparc64_dmamem_alloc_size(pdmat, ddmat, vaddr, flags, mapp,
ddmat->maxsize));
}
/*
* Common function for freeing DMA-safe memory. May be called by
* bus-specific DMA memory free functions.
*/
static void
nexus_dmamem_free(bus_dma_tag_t pdmat, bus_dma_tag_t ddmat, void *vaddr,
bus_dmamap_t map)
nexus_dmamem_free_size(bus_dma_tag_t pdmat, bus_dma_tag_t ddmat, void *vaddr,
bus_dmamap_t map, bus_size_t size)
{
sparc64_dmamem_free_map(ddmat, map);
if ((ddmat->dt_maxsize <= PAGE_SIZE))
if ((size <= PAGE_SIZE))
free(vaddr, M_DEVBUF);
else
contigfree(vaddr, ddmat->dt_maxsize, M_DEVBUF);
contigfree(vaddr, size, M_DEVBUF);
}
static void
nexus_dmamem_free(bus_dma_tag_t pdmat, bus_dma_tag_t ddmat, void *vaddr,
bus_dmamap_t map)
{
sparc64_dmamem_free_size(pdmat, ddmat, vaddr, map, ddmat->dt_maxsize);
}
struct bus_dma_tag nexus_dmatag = {
@ -669,7 +693,9 @@ struct bus_dma_tag nexus_dmatag = {
nexus_dmamap_unload,
nexus_dmamap_sync,
nexus_dmamem_alloc_size,
nexus_dmamem_alloc,
nexus_dmamem_free_size,
nexus_dmamem_free,
};

View File

@ -668,18 +668,22 @@ iommu_dvma_vallocseg(bus_dma_tag_t dt, struct iommu_state *is, bus_dmamap_t map,
}
int
iommu_dvmamem_alloc(bus_dma_tag_t pt, bus_dma_tag_t dt, struct iommu_state *is,
void **vaddr, int flags, bus_dmamap_t *mapp)
iommu_dvmamem_alloc_size(bus_dma_tag_t pt, bus_dma_tag_t dt,
struct iommu_state *is, void **vaddr, int flags, bus_dmamap_t *mapp,
bus_size_t size)
{
int error;
if (size > dt->maxsize)
return (ENOMEM);
/*
* XXX: This will break for 32 bit transfers on machines with more than
* 16G (1 << 34 bytes) of memory.
*/
if ((error = sparc64_dmamem_alloc_map(dt, mapp)) != 0)
return (error);
if ((*vaddr = malloc(dt->dt_maxsize, M_IOMMU,
if ((*vaddr = malloc(size, M_IOMMU,
(flags & BUS_DMA_NOWAIT) ? M_NOWAIT : 0)) == NULL) {
error = ENOMEM;
sparc64_dmamem_free_map(dt, *mapp);
@ -690,18 +694,33 @@ iommu_dvmamem_alloc(bus_dma_tag_t pt, bus_dma_tag_t dt, struct iommu_state *is,
* Try to preallocate DVMA space. If this fails, it is retried at load
* time.
*/
iommu_dvma_valloc(dt, is, *mapp, IOMMU_SIZE_ROUNDUP(dt->dt_maxsize));
iommu_dvma_valloc(dt, is, *mapp, IOMMU_SIZE_ROUNDUP(size));
return (0);
}
int
iommu_dvmamem_alloc(bus_dma_tag_t pt, bus_dma_tag_t dt, struct iommu_state *is,
void **vaddr, int flags, bus_dmamap_t *mapp)
{
return (iommu_dvmamem_alloc_size(pt, dt, is, vaddr, flags, mapp,
dt->maxsize));
}
void
iommu_dvmamem_free_size(bus_dma_tag_t pt, bus_dma_tag_t dt,
struct iommu_state *is, void *vaddr, bus_dmamap_t map, bus_size_t size)
{
iommu_dvma_vfree(is, map);
sparc64_dmamem_free_map(dt, map);
free(vaddr, M_IOMMU);
}
void
iommu_dvmamem_free(bus_dma_tag_t pt, bus_dma_tag_t dt, struct iommu_state *is,
void *vaddr, bus_dmamap_t map)
{
iommu_dvma_vfree(is, map);
sparc64_dmamem_free_map(dt, map);
free(vaddr, M_IOMMU);
iommu_dvmamem_free_size(pt, dt, is, vaddr, map, dt->maxsize);
}
int

View File

@ -180,6 +180,9 @@ int bus_dmamap_destroy(bus_dma_tag_t dmat, bus_dmamap_t map);
* bus device space based on the constraints lited in the dma tag.
* A dmamap to for use with dmamap_load is also allocated.
*/
int bus_dmamem_alloc_size(bus_dma_tag_t dmat, void** vaddr, int flags,
bus_dmamap_t *mapp, bus_size_t size);
int bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
bus_dmamap_t *mapp);
@ -187,6 +190,9 @@ int bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
* Free a piece of memory and it's allociated dmamap, that was allocated
* via bus_dmamem_alloc.
*/
void bus_dmamem_free_size(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map,
bus_size_t size);
void bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map);
/*