Clean up MD pollution of bus_dma.h:
--Remove special-case handling of sparc64 bus_dmamap* functions. Replace with a more generic mechanism that allows MD busdma implementations to generate inline mapping functions by defining WANT_INLINE_DMAMAP in <machine/bus_dma.h>. This is currently useful for sparc64, x86, and arm64, which all implement non-load dmamap operations as simple wrappers around map objects which may be bus- or device-specific. --Remove NULL-checked bus_dmamap macros. Implement the equivalent NULL checks in the inlined x86 implementation. For non-x86 platforms, these checks are a minor pessimization as those platforms do not currently allow NULL maps. NULL maps were originally allowed on arm64, which appears to have been the motivation behind adding arm[64]-specific barriers to bus_dma.h, but that support was removed in r299463. --Simplify the internal interface used by the bus_dmamap_load* variants and move it to bus_dma_internal.h --Fix some drivers that directly include sys/bus_dma.h despite the recommendations of bus_dma(9) Reviewed by: kib (previous revision), marius Differential Revision: https://reviews.freebsd.org/D10729
This commit is contained in:
parent
31bb357d50
commit
d1caaa9300
@ -29,6 +29,6 @@
|
||||
#ifndef _AMD64_BUS_DMA_H_
|
||||
#define _AMD64_BUS_DMA_H_
|
||||
|
||||
#include <sys/bus_dma.h>
|
||||
#include <x86/bus_dma.h>
|
||||
|
||||
#endif /* _AMD64_BUS_DMA_H_ */
|
||||
|
@ -1008,7 +1008,7 @@ _bus_dmamap_load_phys(bus_dma_tag_t dmat, bus_dmamap_t map, vm_paddr_t buf,
|
||||
* Did we fit?
|
||||
*/
|
||||
if (buflen != 0) {
|
||||
_bus_dmamap_unload(dmat, map);
|
||||
bus_dmamap_unload(dmat, map);
|
||||
return (EFBIG); /* XXX better return value here? */
|
||||
}
|
||||
return (0);
|
||||
@ -1129,14 +1129,14 @@ _bus_dmamap_load_buffer(bus_dma_tag_t dmat, bus_dmamap_t map, void *buf,
|
||||
* Did we fit?
|
||||
*/
|
||||
if (buflen != 0) {
|
||||
_bus_dmamap_unload(dmat, map);
|
||||
bus_dmamap_unload(dmat, map);
|
||||
return (EFBIG); /* XXX better return value here? */
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
__bus_dmamap_waitok(bus_dma_tag_t dmat, bus_dmamap_t map, struct memdesc *mem,
|
||||
_bus_dmamap_waitok(bus_dma_tag_t dmat, bus_dmamap_t map, struct memdesc *mem,
|
||||
bus_dmamap_callback_t *callback, void *callback_arg)
|
||||
{
|
||||
|
||||
@ -1161,7 +1161,7 @@ _bus_dmamap_complete(bus_dma_tag_t dmat, bus_dmamap_t map,
|
||||
* Release the mapping held by map.
|
||||
*/
|
||||
void
|
||||
_bus_dmamap_unload(bus_dma_tag_t dmat, bus_dmamap_t map)
|
||||
bus_dmamap_unload(bus_dma_tag_t dmat, bus_dmamap_t map)
|
||||
{
|
||||
struct bounce_page *bpage;
|
||||
struct bounce_zone *bz;
|
||||
@ -1334,7 +1334,7 @@ _bus_dmamap_sync_bp(bus_dma_tag_t dmat, bus_dmamap_t map, bus_dmasync_op_t op)
|
||||
}
|
||||
|
||||
void
|
||||
_bus_dmamap_sync(bus_dma_tag_t dmat, bus_dmamap_t map, bus_dmasync_op_t op)
|
||||
bus_dmamap_sync(bus_dma_tag_t dmat, bus_dmamap_t map, bus_dmasync_op_t op)
|
||||
{
|
||||
struct sync_list *sl, *end;
|
||||
int bufaligned;
|
||||
|
@ -1070,7 +1070,7 @@ _bus_dmamap_load_phys(bus_dma_tag_t dmat, bus_dmamap_t map, vm_paddr_t buf,
|
||||
* Did we fit?
|
||||
*/
|
||||
if (buflen != 0) {
|
||||
_bus_dmamap_unload(dmat, map);
|
||||
bus_dmamap_unload(dmat, map);
|
||||
return (EFBIG); /* XXX better return value here? */
|
||||
}
|
||||
return (0);
|
||||
@ -1195,14 +1195,14 @@ _bus_dmamap_load_buffer(bus_dma_tag_t dmat, bus_dmamap_t map, void *buf,
|
||||
* Did we fit?
|
||||
*/
|
||||
if (buflen != 0) {
|
||||
_bus_dmamap_unload(dmat, map);
|
||||
bus_dmamap_unload(dmat, map);
|
||||
return (EFBIG); /* XXX better return value here? */
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
__bus_dmamap_waitok(bus_dma_tag_t dmat, bus_dmamap_t map, struct memdesc *mem,
|
||||
_bus_dmamap_waitok(bus_dma_tag_t dmat, bus_dmamap_t map, struct memdesc *mem,
|
||||
bus_dmamap_callback_t *callback, void *callback_arg)
|
||||
{
|
||||
|
||||
@ -1226,7 +1226,7 @@ _bus_dmamap_complete(bus_dma_tag_t dmat, bus_dmamap_t map,
|
||||
* Release the mapping held by map.
|
||||
*/
|
||||
void
|
||||
_bus_dmamap_unload(bus_dma_tag_t dmat, bus_dmamap_t map)
|
||||
bus_dmamap_unload(bus_dma_tag_t dmat, bus_dmamap_t map)
|
||||
{
|
||||
struct bounce_page *bpage;
|
||||
struct bounce_zone *bz;
|
||||
@ -1326,7 +1326,7 @@ dma_dcache_sync(struct sync_list *sl, bus_dmasync_op_t op)
|
||||
}
|
||||
|
||||
void
|
||||
_bus_dmamap_sync(bus_dma_tag_t dmat, bus_dmamap_t map, bus_dmasync_op_t op)
|
||||
bus_dmamap_sync(bus_dma_tag_t dmat, bus_dmamap_t map, bus_dmasync_op_t op)
|
||||
{
|
||||
struct bounce_page *bpage;
|
||||
struct sync_list *sl, *end;
|
||||
|
@ -67,6 +67,7 @@
|
||||
#define _ARM_BUS_DMA_H
|
||||
|
||||
#include <sys/bus_dma.h>
|
||||
#include <sys/bus_dma_internal.h>
|
||||
|
||||
/* Bus Space DMA macros */
|
||||
|
||||
|
@ -223,133 +223,3 @@ bus_dma_tag_destroy(bus_dma_tag_t dmat)
|
||||
return (tc->impl->tag_destroy(dmat));
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate a handle for mapping from kva/uva/physical
|
||||
* address space into bus device space.
|
||||
*/
|
||||
int
|
||||
bus_dmamap_create(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp)
|
||||
{
|
||||
struct bus_dma_tag_common *tc;
|
||||
|
||||
tc = (struct bus_dma_tag_common *)dmat;
|
||||
return (tc->impl->map_create(dmat, flags, mapp));
|
||||
}
|
||||
|
||||
/*
|
||||
* Destroy a handle for mapping from kva/uva/physical
|
||||
* address space into bus device space.
|
||||
*/
|
||||
int
|
||||
bus_dmamap_destroy(bus_dma_tag_t dmat, bus_dmamap_t map)
|
||||
{
|
||||
struct bus_dma_tag_common *tc;
|
||||
|
||||
tc = (struct bus_dma_tag_common *)dmat;
|
||||
return (tc->impl->map_destroy(dmat, map));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Allocate a piece of memory that can be efficiently mapped into
|
||||
* bus device space based on the constraints listed in the dma tag.
|
||||
* 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)
|
||||
{
|
||||
struct bus_dma_tag_common *tc;
|
||||
|
||||
tc = (struct bus_dma_tag_common *)dmat;
|
||||
return (tc->impl->mem_alloc(dmat, vaddr, flags, mapp));
|
||||
}
|
||||
|
||||
/*
|
||||
* 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)
|
||||
{
|
||||
struct bus_dma_tag_common *tc;
|
||||
|
||||
tc = (struct bus_dma_tag_common *)dmat;
|
||||
tc->impl->mem_free(dmat, vaddr, map);
|
||||
}
|
||||
|
||||
int
|
||||
_bus_dmamap_load_phys(bus_dma_tag_t dmat, bus_dmamap_t map, vm_paddr_t buf,
|
||||
bus_size_t buflen, int flags, bus_dma_segment_t *segs, int *segp)
|
||||
{
|
||||
struct bus_dma_tag_common *tc;
|
||||
|
||||
tc = (struct bus_dma_tag_common *)dmat;
|
||||
return (tc->impl->load_phys(dmat, map, buf, buflen, flags, segs,
|
||||
segp));
|
||||
}
|
||||
|
||||
int
|
||||
_bus_dmamap_load_ma(bus_dma_tag_t dmat, bus_dmamap_t map, struct vm_page **ma,
|
||||
bus_size_t tlen, int ma_offs, int flags, bus_dma_segment_t *segs,
|
||||
int *segp)
|
||||
{
|
||||
struct bus_dma_tag_common *tc;
|
||||
|
||||
tc = (struct bus_dma_tag_common *)dmat;
|
||||
return (tc->impl->load_ma(dmat, map, ma, tlen, ma_offs, flags,
|
||||
segs, segp));
|
||||
}
|
||||
|
||||
int
|
||||
_bus_dmamap_load_buffer(bus_dma_tag_t dmat, bus_dmamap_t map, void *buf,
|
||||
bus_size_t buflen, pmap_t pmap, int flags, bus_dma_segment_t *segs,
|
||||
int *segp)
|
||||
{
|
||||
struct bus_dma_tag_common *tc;
|
||||
|
||||
tc = (struct bus_dma_tag_common *)dmat;
|
||||
return (tc->impl->load_buffer(dmat, map, buf, buflen, pmap, flags, segs,
|
||||
segp));
|
||||
}
|
||||
|
||||
void
|
||||
__bus_dmamap_waitok(bus_dma_tag_t dmat, bus_dmamap_t map,
|
||||
struct memdesc *mem, bus_dmamap_callback_t *callback, void *callback_arg)
|
||||
{
|
||||
struct bus_dma_tag_common *tc;
|
||||
|
||||
tc = (struct bus_dma_tag_common *)dmat;
|
||||
tc->impl->map_waitok(dmat, map, mem, callback, callback_arg);
|
||||
}
|
||||
|
||||
bus_dma_segment_t *
|
||||
_bus_dmamap_complete(bus_dma_tag_t dmat, bus_dmamap_t map,
|
||||
bus_dma_segment_t *segs, int nsegs, int error)
|
||||
{
|
||||
struct bus_dma_tag_common *tc;
|
||||
|
||||
tc = (struct bus_dma_tag_common *)dmat;
|
||||
return (tc->impl->map_complete(dmat, map, segs, nsegs, error));
|
||||
}
|
||||
|
||||
/*
|
||||
* Release the mapping held by map.
|
||||
*/
|
||||
void
|
||||
_bus_dmamap_unload(bus_dma_tag_t dmat, bus_dmamap_t map)
|
||||
{
|
||||
struct bus_dma_tag_common *tc;
|
||||
|
||||
tc = (struct bus_dma_tag_common *)dmat;
|
||||
tc->impl->map_unload(dmat, map);
|
||||
}
|
||||
|
||||
void
|
||||
_bus_dmamap_sync(bus_dma_tag_t dmat, bus_dmamap_t map, bus_dmasync_op_t op)
|
||||
{
|
||||
struct bus_dma_tag_common *tc;
|
||||
|
||||
tc = (struct bus_dma_tag_common *)dmat;
|
||||
tc->impl->map_sync(dmat, map, op);
|
||||
}
|
||||
|
@ -3,6 +3,139 @@
|
||||
#ifndef _MACHINE_BUS_DMA_H_
|
||||
#define _MACHINE_BUS_DMA_H_
|
||||
|
||||
#define WANT_INLINE_DMAMAP
|
||||
#include <sys/bus_dma.h>
|
||||
|
||||
#include <machine/bus_dma_impl.h>
|
||||
|
||||
/*
|
||||
* Allocate a handle for mapping from kva/uva/physical
|
||||
* address space into bus device space.
|
||||
*/
|
||||
static inline int
|
||||
bus_dmamap_create(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp)
|
||||
{
|
||||
struct bus_dma_tag_common *tc;
|
||||
|
||||
tc = (struct bus_dma_tag_common *)dmat;
|
||||
return (tc->impl->map_create(dmat, flags, mapp));
|
||||
}
|
||||
|
||||
/*
|
||||
* Destroy a handle for mapping from kva/uva/physical
|
||||
* address space into bus device space.
|
||||
*/
|
||||
static inline int
|
||||
bus_dmamap_destroy(bus_dma_tag_t dmat, bus_dmamap_t map)
|
||||
{
|
||||
struct bus_dma_tag_common *tc;
|
||||
|
||||
tc = (struct bus_dma_tag_common *)dmat;
|
||||
return (tc->impl->map_destroy(dmat, map));
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate a piece of memory that can be efficiently mapped into
|
||||
* bus device space based on the constraints listed in the dma tag.
|
||||
* A dmamap to for use with dmamap_load is also allocated.
|
||||
*/
|
||||
static inline int
|
||||
bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
|
||||
bus_dmamap_t *mapp)
|
||||
{
|
||||
struct bus_dma_tag_common *tc;
|
||||
|
||||
tc = (struct bus_dma_tag_common *)dmat;
|
||||
return (tc->impl->mem_alloc(dmat, vaddr, flags, mapp));
|
||||
}
|
||||
|
||||
/*
|
||||
* Free a piece of memory and it's allociated dmamap, that was allocated
|
||||
* via bus_dmamem_alloc. Make the same choice for free/contigfree.
|
||||
*/
|
||||
static inline void
|
||||
bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map)
|
||||
{
|
||||
struct bus_dma_tag_common *tc;
|
||||
|
||||
tc = (struct bus_dma_tag_common *)dmat;
|
||||
tc->impl->mem_free(dmat, vaddr, map);
|
||||
}
|
||||
|
||||
/*
|
||||
* Release the mapping held by map.
|
||||
*/
|
||||
static inline void
|
||||
bus_dmamap_unload(bus_dma_tag_t dmat, bus_dmamap_t map)
|
||||
{
|
||||
struct bus_dma_tag_common *tc;
|
||||
|
||||
tc = (struct bus_dma_tag_common *)dmat;
|
||||
tc->impl->map_unload(dmat, map);
|
||||
}
|
||||
|
||||
static inline void
|
||||
bus_dmamap_sync(bus_dma_tag_t dmat, bus_dmamap_t map, bus_dmasync_op_t op)
|
||||
{
|
||||
struct bus_dma_tag_common *tc;
|
||||
|
||||
tc = (struct bus_dma_tag_common *)dmat;
|
||||
tc->impl->map_sync(dmat, map, op);
|
||||
}
|
||||
|
||||
static inline int
|
||||
_bus_dmamap_load_phys(bus_dma_tag_t dmat, bus_dmamap_t map, vm_paddr_t buf,
|
||||
bus_size_t buflen, int flags, bus_dma_segment_t *segs, int *segp)
|
||||
{
|
||||
struct bus_dma_tag_common *tc;
|
||||
|
||||
tc = (struct bus_dma_tag_common *)dmat;
|
||||
return (tc->impl->load_phys(dmat, map, buf, buflen, flags, segs,
|
||||
segp));
|
||||
}
|
||||
|
||||
static inline int
|
||||
_bus_dmamap_load_ma(bus_dma_tag_t dmat, bus_dmamap_t map, struct vm_page **ma,
|
||||
bus_size_t tlen, int ma_offs, int flags, bus_dma_segment_t *segs,
|
||||
int *segp)
|
||||
{
|
||||
struct bus_dma_tag_common *tc;
|
||||
|
||||
tc = (struct bus_dma_tag_common *)dmat;
|
||||
return (tc->impl->load_ma(dmat, map, ma, tlen, ma_offs, flags,
|
||||
segs, segp));
|
||||
}
|
||||
|
||||
static inline int
|
||||
_bus_dmamap_load_buffer(bus_dma_tag_t dmat, bus_dmamap_t map, void *buf,
|
||||
bus_size_t buflen, struct pmap *pmap, int flags, bus_dma_segment_t *segs,
|
||||
int *segp)
|
||||
{
|
||||
struct bus_dma_tag_common *tc;
|
||||
|
||||
tc = (struct bus_dma_tag_common *)dmat;
|
||||
return (tc->impl->load_buffer(dmat, map, buf, buflen, pmap, flags, segs,
|
||||
segp));
|
||||
}
|
||||
|
||||
static inline void
|
||||
_bus_dmamap_waitok(bus_dma_tag_t dmat, bus_dmamap_t map,
|
||||
struct memdesc *mem, bus_dmamap_callback_t *callback, void *callback_arg)
|
||||
{
|
||||
struct bus_dma_tag_common *tc;
|
||||
|
||||
tc = (struct bus_dma_tag_common *)dmat;
|
||||
tc->impl->map_waitok(dmat, map, mem, callback, callback_arg);
|
||||
}
|
||||
|
||||
static inline bus_dma_segment_t *
|
||||
_bus_dmamap_complete(bus_dma_tag_t dmat, bus_dmamap_t map,
|
||||
bus_dma_segment_t *segs, int nsegs, int error)
|
||||
{
|
||||
struct bus_dma_tag_common *tc;
|
||||
|
||||
tc = (struct bus_dma_tag_common *)dmat;
|
||||
return (tc->impl->map_complete(dmat, map, segs, nsegs, error));
|
||||
}
|
||||
|
||||
#endif /* !_MACHINE_BUS_DMA_H_ */
|
||||
|
@ -70,7 +70,7 @@ struct bus_dma_impl {
|
||||
vm_paddr_t buf, bus_size_t buflen, int flags,
|
||||
bus_dma_segment_t *segs, int *segp);
|
||||
int (*load_buffer)(bus_dma_tag_t dmat, bus_dmamap_t map,
|
||||
void *buf, bus_size_t buflen, pmap_t pmap, int flags,
|
||||
void *buf, bus_size_t buflen, struct pmap *pmap, int flags,
|
||||
bus_dma_segment_t *segs, int *segp);
|
||||
void (*map_waitok)(bus_dma_tag_t dmat, bus_dmamap_t map,
|
||||
struct memdesc *mem, bus_dmamap_callback_t *callback,
|
||||
|
@ -55,7 +55,6 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/rman.h>
|
||||
|
||||
#include <machine/bus.h>
|
||||
#include <sys/bus_dma.h>
|
||||
#include <machine/resource.h>
|
||||
|
||||
#include <dev/pci/pcireg.h>
|
||||
|
@ -56,7 +56,6 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/rman.h>
|
||||
|
||||
#include <machine/bus.h>
|
||||
#include <sys/bus_dma.h>
|
||||
#include <machine/resource.h>
|
||||
|
||||
#include <dev/pci/pcireg.h>
|
||||
|
@ -32,13 +32,13 @@ __FBSDID("$FreeBSD$");
|
||||
#ifndef _BNXT_H
|
||||
#define _BNXT_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/bus.h>
|
||||
#include <sys/bus_dma.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/taskqueue.h>
|
||||
|
||||
#include <machine/bus.h>
|
||||
|
||||
#include <net/ethernet.h>
|
||||
#include <net/if.h>
|
||||
#include <net/if_var.h>
|
||||
|
@ -54,7 +54,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
#include <machine/bus.h>
|
||||
#include <machine/resource.h>
|
||||
|
||||
#include <sys/bus_dma.h>
|
||||
#include <dev/pci/pcireg.h>
|
||||
#include <dev/pci/pcivar.h>
|
||||
|
||||
|
@ -41,7 +41,6 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/conf.h>
|
||||
#include <machine/bus.h>
|
||||
#include <machine/resource.h>
|
||||
#include <sys/bus_dma.h>
|
||||
#include <sys/ktr.h>
|
||||
#include <sys/rman.h>
|
||||
#include <sys/ioccom.h>
|
||||
|
@ -41,7 +41,6 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/conf.h>
|
||||
#include <machine/bus.h>
|
||||
#include <machine/resource.h>
|
||||
#include <sys/bus_dma.h>
|
||||
#include <sys/rman.h>
|
||||
#include <sys/queue.h>
|
||||
#include <sys/sysctl.h>
|
||||
|
@ -39,7 +39,6 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/conf.h>
|
||||
#include <machine/bus.h>
|
||||
#include <machine/resource.h>
|
||||
#include <sys/bus_dma.h>
|
||||
#include <sys/rman.h>
|
||||
#include <sys/ioccom.h>
|
||||
#include <sys/mbuf.h>
|
||||
|
@ -40,7 +40,6 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/conf.h>
|
||||
#include <machine/bus.h>
|
||||
#include <machine/resource.h>
|
||||
#include <sys/bus_dma.h>
|
||||
#include <sys/rman.h>
|
||||
#include <sys/ioccom.h>
|
||||
#include <sys/mbuf.h>
|
||||
|
@ -41,7 +41,6 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/conf.h>
|
||||
#include <machine/bus.h>
|
||||
#include <machine/resource.h>
|
||||
#include <sys/bus_dma.h>
|
||||
#include <sys/rman.h>
|
||||
#include <sys/ioccom.h>
|
||||
#include <sys/mbuf.h>
|
||||
|
@ -40,7 +40,6 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/conf.h>
|
||||
#include <machine/bus.h>
|
||||
#include <machine/resource.h>
|
||||
#include <sys/bus_dma.h>
|
||||
#include <sys/rman.h>
|
||||
#include <sys/ioccom.h>
|
||||
#include <sys/mbuf.h>
|
||||
|
@ -40,7 +40,6 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/conf.h>
|
||||
#include <machine/bus.h>
|
||||
#include <machine/resource.h>
|
||||
#include <sys/bus_dma.h>
|
||||
#include <sys/rman.h>
|
||||
#include <sys/ioccom.h>
|
||||
#include <sys/mbuf.h>
|
||||
|
@ -40,7 +40,6 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/conf.h>
|
||||
#include <machine/bus.h>
|
||||
#include <machine/resource.h>
|
||||
#include <sys/bus_dma.h>
|
||||
#include <sys/rman.h>
|
||||
#include <sys/ioccom.h>
|
||||
#include <sys/mbuf.h>
|
||||
|
@ -40,7 +40,6 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/conf.h>
|
||||
#include <machine/bus.h>
|
||||
#include <machine/resource.h>
|
||||
#include <sys/bus_dma.h>
|
||||
#include <sys/rman.h>
|
||||
#include <sys/ioccom.h>
|
||||
#include <sys/mbuf.h>
|
||||
|
@ -40,7 +40,6 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/conf.h>
|
||||
#include <machine/bus.h>
|
||||
#include <machine/resource.h>
|
||||
#include <sys/bus_dma.h>
|
||||
#include <sys/rman.h>
|
||||
#include <sys/ioccom.h>
|
||||
#include <sys/mbuf.h>
|
||||
|
@ -40,7 +40,6 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/conf.h>
|
||||
#include <machine/bus.h>
|
||||
#include <machine/resource.h>
|
||||
#include <sys/bus_dma.h>
|
||||
#include <sys/rman.h>
|
||||
#include <sys/ioccom.h>
|
||||
#include <sys/mbuf.h>
|
||||
|
@ -40,7 +40,6 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/conf.h>
|
||||
#include <machine/bus.h>
|
||||
#include <machine/resource.h>
|
||||
#include <sys/bus_dma.h>
|
||||
#include <sys/rman.h>
|
||||
#include <sys/ioccom.h>
|
||||
#include <sys/mbuf.h>
|
||||
|
@ -62,7 +62,6 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/sglist.h>
|
||||
#include <sys/eventhandler.h>
|
||||
#include <machine/bus.h>
|
||||
#include <sys/bus_dma.h>
|
||||
|
||||
#include <cam/cam.h>
|
||||
#include <cam/cam_ccb.h>
|
||||
|
@ -67,7 +67,6 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/conf.h>
|
||||
#include <sys/eventhandler.h>
|
||||
#include <sys/rman.h>
|
||||
#include <sys/bus_dma.h>
|
||||
#include <sys/bio.h>
|
||||
#include <sys/ioccom.h>
|
||||
#include <sys/uio.h>
|
||||
|
@ -39,7 +39,6 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/conf.h>
|
||||
#include <sys/eventhandler.h>
|
||||
#include <sys/rman.h>
|
||||
#include <sys/bus_dma.h>
|
||||
#include <sys/bio.h>
|
||||
#include <sys/ioccom.h>
|
||||
#include <sys/uio.h>
|
||||
|
@ -37,7 +37,6 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/bus.h>
|
||||
#include <sys/bus_dma.h>
|
||||
#include <sys/endian.h>
|
||||
#include <sys/mbuf.h>
|
||||
#include <sys/kernel.h>
|
||||
|
@ -45,7 +45,6 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/sx.h>
|
||||
#include <sys/bus_dma.h>
|
||||
|
||||
#include <machine/bus.h>
|
||||
|
||||
|
@ -49,7 +49,6 @@ __FBSDID("$FreeBSD$");
|
||||
#include <machine/resource.h>
|
||||
#include <machine/intr_machdep.h>
|
||||
#include <machine/vmparam.h>
|
||||
#include <sys/bus_dma.h>
|
||||
|
||||
#include <xen/xen-os.h>
|
||||
#include <xen/hypervisor.h>
|
||||
|
@ -29,6 +29,6 @@
|
||||
#ifndef _I386_BUS_DMA_H_
|
||||
#define _I386_BUS_DMA_H_
|
||||
|
||||
#include <sys/bus_dma.h>
|
||||
#include <x86/bus_dma.h>
|
||||
|
||||
#endif /* _I386_BUS_DMA_H_ */
|
||||
|
@ -30,5 +30,6 @@
|
||||
#define _MIPS_BUS_DMA_H_
|
||||
|
||||
#include <sys/bus_dma.h>
|
||||
#include <sys/bus_dma_internal.h>
|
||||
|
||||
#endif /* _MIPS_BUS_DMA_H_ */
|
||||
|
@ -930,7 +930,7 @@ _bus_dmamap_load_phys(bus_dma_tag_t dmat, bus_dmamap_t map,
|
||||
* Did we fit?
|
||||
*/
|
||||
if (buflen != 0) {
|
||||
_bus_dmamap_unload(dmat, map);
|
||||
bus_dmamap_unload(dmat, map);
|
||||
return (EFBIG); /* XXX better return value here? */
|
||||
}
|
||||
return (0);
|
||||
@ -1028,14 +1028,14 @@ _bus_dmamap_load_buffer(bus_dma_tag_t dmat, bus_dmamap_t map, void *buf,
|
||||
* Did we fit?
|
||||
*/
|
||||
if (buflen != 0) {
|
||||
_bus_dmamap_unload(dmat, map);
|
||||
bus_dmamap_unload(dmat, map);
|
||||
error = EFBIG; /* XXX better return value here? */
|
||||
}
|
||||
return (error);
|
||||
}
|
||||
|
||||
void
|
||||
__bus_dmamap_waitok(bus_dma_tag_t dmat, bus_dmamap_t map,
|
||||
_bus_dmamap_waitok(bus_dma_tag_t dmat, bus_dmamap_t map,
|
||||
struct memdesc *mem, bus_dmamap_callback_t *callback, void *callback_arg)
|
||||
{
|
||||
|
||||
@ -1060,7 +1060,7 @@ _bus_dmamap_complete(bus_dma_tag_t dmat, bus_dmamap_t map,
|
||||
* Release the mapping held by map.
|
||||
*/
|
||||
void
|
||||
_bus_dmamap_unload(bus_dma_tag_t dmat, bus_dmamap_t map)
|
||||
bus_dmamap_unload(bus_dma_tag_t dmat, bus_dmamap_t map)
|
||||
{
|
||||
struct bounce_page *bpage;
|
||||
|
||||
@ -1233,7 +1233,7 @@ _bus_dmamap_sync_bp(bus_dma_tag_t dmat, bus_dmamap_t map, bus_dmasync_op_t op)
|
||||
}
|
||||
|
||||
void
|
||||
_bus_dmamap_sync(bus_dma_tag_t dmat, bus_dmamap_t map, bus_dmasync_op_t op)
|
||||
bus_dmamap_sync(bus_dma_tag_t dmat, bus_dmamap_t map, bus_dmasync_op_t op)
|
||||
{
|
||||
struct sync_list *sl, *end;
|
||||
int aligned;
|
||||
|
@ -33,7 +33,6 @@
|
||||
#include <sys/bus.h>
|
||||
#include <sys/cpuset.h>
|
||||
#include <machine/bus.h>
|
||||
#include <sys/bus_dma.h>
|
||||
#include <sys/nv.h>
|
||||
#include <sys/gtaskqueue.h>
|
||||
|
||||
|
@ -29,6 +29,7 @@
|
||||
#define _POWERPC_BUS_DMA_H_
|
||||
|
||||
#include <sys/bus_dma.h>
|
||||
#include <sys/bus_dma_internal.h>
|
||||
|
||||
struct device;
|
||||
|
||||
|
@ -841,7 +841,7 @@ _bus_dmamap_load_buffer(bus_dma_tag_t dmat,
|
||||
}
|
||||
|
||||
void
|
||||
__bus_dmamap_waitok(bus_dma_tag_t dmat, bus_dmamap_t map,
|
||||
_bus_dmamap_waitok(bus_dma_tag_t dmat, bus_dmamap_t map,
|
||||
struct memdesc *mem, bus_dmamap_callback_t *callback,
|
||||
void *callback_arg)
|
||||
{
|
||||
@ -879,7 +879,7 @@ _bus_dmamap_complete(bus_dma_tag_t dmat, bus_dmamap_t map,
|
||||
* Release the mapping held by map.
|
||||
*/
|
||||
void
|
||||
_bus_dmamap_unload(bus_dma_tag_t dmat, bus_dmamap_t map)
|
||||
bus_dmamap_unload(bus_dma_tag_t dmat, bus_dmamap_t map)
|
||||
{
|
||||
struct bounce_page *bpage;
|
||||
|
||||
@ -895,7 +895,7 @@ _bus_dmamap_unload(bus_dma_tag_t dmat, bus_dmamap_t map)
|
||||
}
|
||||
|
||||
void
|
||||
_bus_dmamap_sync(bus_dma_tag_t dmat, bus_dmamap_t map, bus_dmasync_op_t op)
|
||||
bus_dmamap_sync(bus_dma_tag_t dmat, bus_dmamap_t map, bus_dmasync_op_t op)
|
||||
{
|
||||
struct bounce_page *bpage;
|
||||
vm_offset_t datavaddr, tempvaddr;
|
||||
|
@ -4,5 +4,6 @@
|
||||
#define _MACHINE_BUS_DMA_H_
|
||||
|
||||
#include <sys/bus_dma.h>
|
||||
#include <sys/bus_dma_internal.h>
|
||||
|
||||
#endif /* !_MACHINE_BUS_DMA_H_ */
|
||||
|
@ -69,7 +69,7 @@ _bus_dmamap_load_buffer(bus_dma_tag_t dmat, bus_dmamap_t map, void *buf,
|
||||
}
|
||||
|
||||
void
|
||||
__bus_dmamap_waitok(bus_dma_tag_t dmat, bus_dmamap_t map,
|
||||
_bus_dmamap_waitok(bus_dma_tag_t dmat, bus_dmamap_t map,
|
||||
struct memdesc *mem, bus_dmamap_callback_t *callback, void *callback_arg)
|
||||
{
|
||||
|
||||
@ -88,14 +88,14 @@ _bus_dmamap_complete(bus_dma_tag_t dmat, bus_dmamap_t map,
|
||||
* Release the mapping held by map.
|
||||
*/
|
||||
void
|
||||
_bus_dmamap_unload(bus_dma_tag_t dmat, bus_dmamap_t map)
|
||||
bus_dmamap_unload(bus_dma_tag_t dmat, bus_dmamap_t map)
|
||||
{
|
||||
|
||||
panic("busdma");
|
||||
}
|
||||
|
||||
void
|
||||
_bus_dmamap_sync(bus_dma_tag_t dmat, bus_dmamap_t map, bus_dmasync_op_t op)
|
||||
bus_dmamap_sync(bus_dma_tag_t dmat, bus_dmamap_t map, bus_dmasync_op_t op)
|
||||
{
|
||||
|
||||
panic("busdma");
|
||||
|
@ -68,6 +68,7 @@
|
||||
#ifndef _SPARC64_BUS_DMA_H
|
||||
#define _SPARC64_BUS_DMA_H
|
||||
|
||||
#define WANT_INLINE_DMAMAP
|
||||
#include <sys/bus_dma.h>
|
||||
|
||||
/* DMA support */
|
||||
@ -124,29 +125,95 @@ struct bus_dma_tag {
|
||||
struct bus_dma_methods *dt_mt;
|
||||
};
|
||||
|
||||
#define bus_dmamap_create(t, f, p) \
|
||||
((t)->dt_mt->dm_dmamap_create((t), (f), (p)))
|
||||
#define bus_dmamap_destroy(t, p) \
|
||||
((t)->dt_mt->dm_dmamap_destroy((t), (p)))
|
||||
#define _bus_dmamap_load_phys(t, m, b, l, f, s, sp) \
|
||||
((t)->dt_mt->dm_dmamap_load_phys((t), (m), (b), (l), \
|
||||
(f), (s), (sp)))
|
||||
#define _bus_dmamap_load_buffer(t, m, b, l, p, f, s, sp) \
|
||||
((t)->dt_mt->dm_dmamap_load_buffer((t), (m), (b), (l), (p), \
|
||||
(f), (s), (sp)))
|
||||
#define _bus_dmamap_waitok(t, m, mem, c, ca) \
|
||||
((t)->dt_mt->dm_dmamap_waitok((t), (m), (mem), (c), (ca)))
|
||||
#define _bus_dmamap_complete(t, m, s, n, e) \
|
||||
((t)->dt_mt->dm_dmamap_complete((t), (m), (s), (n), (e)))
|
||||
#define bus_dmamap_unload(t, p) \
|
||||
((t)->dt_mt->dm_dmamap_unload((t), (p)))
|
||||
#define bus_dmamap_sync(t, m, op) \
|
||||
((t)->dt_mt->dm_dmamap_sync((t), (m), (op)))
|
||||
#define bus_dmamem_alloc(t, v, f, m) \
|
||||
((t)->dt_mt->dm_dmamem_alloc((t), (v), (f), (m)))
|
||||
#define bus_dmamem_free(t, v, m) \
|
||||
((t)->dt_mt->dm_dmamem_free((t), (v), (m)))
|
||||
#define _bus_dmamap_load_ma(t, m, a, tt, o, f, s, p) \
|
||||
bus_dmamap_load_ma_triv((t), (m), (a), (tt), (o), (f), (s), (p))
|
||||
static inline int
|
||||
bus_dmamap_create(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp)
|
||||
{
|
||||
|
||||
return (dmat->dt_mt->dm_dmamap_create(dmat, flags, mapp));
|
||||
}
|
||||
|
||||
static inline int
|
||||
bus_dmamap_destroy(bus_dma_tag_t dmat, bus_dmamap_t map)
|
||||
{
|
||||
|
||||
return (dmat->dt_mt->dm_dmamap_destroy(dmat, map));
|
||||
}
|
||||
|
||||
static inline void
|
||||
bus_dmamap_sync(bus_dma_tag_t dmat, bus_dmamap_t map, bus_dmasync_op_t op)
|
||||
{
|
||||
|
||||
dmat->dt_mt->dm_dmamap_sync(dmat, map, op);
|
||||
}
|
||||
|
||||
static inline void
|
||||
bus_dmamap_unload(bus_dma_tag_t dmat, bus_dmamap_t map)
|
||||
{
|
||||
|
||||
dmat->dt_mt->dm_dmamap_unload(dmat, map);
|
||||
}
|
||||
|
||||
static inline int
|
||||
bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags, bus_dmamap_t *mapp)
|
||||
{
|
||||
|
||||
return (dmat->dt_mt->dm_dmamem_alloc(dmat, vaddr, flags, mapp));
|
||||
}
|
||||
|
||||
static inline void
|
||||
bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map)
|
||||
{
|
||||
|
||||
dmat->dt_mt->dm_dmamem_free(dmat, vaddr, map);
|
||||
}
|
||||
|
||||
static inline bus_dma_segment_t*
|
||||
_bus_dmamap_complete(bus_dma_tag_t dmat, bus_dmamap_t map,
|
||||
bus_dma_segment_t *segs, int nsegs, int error)
|
||||
{
|
||||
|
||||
return (dmat->dt_mt->dm_dmamap_complete(dmat, map, segs,
|
||||
nsegs, error));
|
||||
}
|
||||
|
||||
static inline int
|
||||
_bus_dmamap_load_buffer(bus_dma_tag_t dmat, bus_dmamap_t map,
|
||||
void *buf, bus_size_t buflen, struct pmap *pmap,
|
||||
int flags, bus_dma_segment_t *segs, int *segp)
|
||||
{
|
||||
|
||||
return (dmat->dt_mt->dm_dmamap_load_buffer(dmat, map, buf, buflen,
|
||||
pmap, flags, segs, segp));
|
||||
}
|
||||
|
||||
static inline int
|
||||
_bus_dmamap_load_ma(bus_dma_tag_t dmat, bus_dmamap_t map,
|
||||
struct vm_page **ma, bus_size_t tlen, int ma_offs,
|
||||
int flags, bus_dma_segment_t *segs, int *segp)
|
||||
{
|
||||
|
||||
return (bus_dmamap_load_ma_triv(dmat, map, ma, tlen, ma_offs, flags,
|
||||
segs, segp));
|
||||
}
|
||||
|
||||
static inline int
|
||||
_bus_dmamap_load_phys(bus_dma_tag_t dmat, bus_dmamap_t map,
|
||||
vm_paddr_t paddr, bus_size_t buflen,
|
||||
int flags, bus_dma_segment_t *segs, int *segp)
|
||||
{
|
||||
|
||||
return (dmat->dt_mt->dm_dmamap_load_phys(dmat, map, paddr, buflen,
|
||||
flags, segs, segp));
|
||||
}
|
||||
|
||||
static inline void
|
||||
_bus_dmamap_waitok(bus_dma_tag_t dmat, bus_dmamap_t map,
|
||||
struct memdesc *mem, bus_dmamap_callback_t *callback,
|
||||
void *callback_arg)
|
||||
{
|
||||
|
||||
return (dmat->dt_mt->dm_dmamap_waitok(dmat, map, mem, callback,
|
||||
callback_arg));
|
||||
}
|
||||
|
||||
#endif /* !_SPARC64_BUS_DMA_H_ */
|
||||
|
@ -248,105 +248,49 @@ int bus_dmamap_load_ma_triv(bus_dma_tag_t dmat, bus_dmamap_t map,
|
||||
struct vm_page **ma, bus_size_t tlen, int ma_offs, int flags,
|
||||
bus_dma_segment_t *segs, int *segp);
|
||||
|
||||
/*
|
||||
* XXX sparc64 uses the same interface, but a much different implementation.
|
||||
* <machine/bus_dma.h> for the sparc64 arch contains the equivalent
|
||||
* declarations.
|
||||
*/
|
||||
#if !defined(__sparc64__)
|
||||
#ifdef WANT_INLINE_DMAMAP
|
||||
#define BUS_DMAMAP_OP static inline
|
||||
#else
|
||||
#define BUS_DMAMAP_OP
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Allocate a handle for mapping from kva/uva/physical
|
||||
* address space into bus device space.
|
||||
*/
|
||||
int bus_dmamap_create(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp);
|
||||
BUS_DMAMAP_OP int bus_dmamap_create(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp);
|
||||
|
||||
/*
|
||||
* Destroy a handle for mapping from kva/uva/physical
|
||||
* address space into bus device space.
|
||||
*/
|
||||
int bus_dmamap_destroy(bus_dma_tag_t dmat, bus_dmamap_t map);
|
||||
BUS_DMAMAP_OP int bus_dmamap_destroy(bus_dma_tag_t dmat, bus_dmamap_t map);
|
||||
|
||||
/*
|
||||
* Allocate a piece of memory that can be efficiently mapped into
|
||||
* bus device space based on the constraints listed in the dma tag.
|
||||
* 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_OP int bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
|
||||
bus_dmamap_t *mapp);
|
||||
|
||||
/*
|
||||
* Free a piece of memory and its allocated dmamap, that was allocated
|
||||
* via bus_dmamem_alloc.
|
||||
*/
|
||||
void bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map);
|
||||
BUS_DMAMAP_OP void bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map);
|
||||
|
||||
/*
|
||||
* Perform a synchronization operation on the given map. If the map
|
||||
* is NULL we have a fully IO-coherent system. On every ARM architecture
|
||||
* there must be a memory barrier placed to ensure that all data
|
||||
* accesses are visible before going any further.
|
||||
* is NULL we have a fully IO-coherent system.
|
||||
*/
|
||||
void _bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_dmasync_op_t);
|
||||
#if defined(__arm__)
|
||||
#define __BUS_DMAMAP_SYNC_DEFAULT mb()
|
||||
#elif defined(__aarch64__)
|
||||
#define __BUS_DMAMAP_SYNC_DEFAULT dmb(sy)
|
||||
#else
|
||||
#define __BUS_DMAMAP_SYNC_DEFAULT do {} while (0)
|
||||
#endif
|
||||
#define bus_dmamap_sync(dmat, dmamap, op) \
|
||||
do { \
|
||||
if ((dmamap) != NULL) \
|
||||
_bus_dmamap_sync(dmat, dmamap, op); \
|
||||
else \
|
||||
__BUS_DMAMAP_SYNC_DEFAULT; \
|
||||
} while (0)
|
||||
BUS_DMAMAP_OP void bus_dmamap_sync(bus_dma_tag_t dmat, bus_dmamap_t dmamap, bus_dmasync_op_t op);
|
||||
|
||||
/*
|
||||
* Release the mapping held by map.
|
||||
*/
|
||||
void _bus_dmamap_unload(bus_dma_tag_t dmat, bus_dmamap_t map);
|
||||
#define bus_dmamap_unload(dmat, dmamap) \
|
||||
do { \
|
||||
if ((dmamap) != NULL) \
|
||||
_bus_dmamap_unload(dmat, dmamap); \
|
||||
} while (0)
|
||||
BUS_DMAMAP_OP void bus_dmamap_unload(bus_dma_tag_t dmat, bus_dmamap_t dmamap);
|
||||
|
||||
/*
|
||||
* The following functions define the interface between the MD and MI
|
||||
* busdma layers. These are not intended for consumption by driver
|
||||
* software.
|
||||
*/
|
||||
void __bus_dmamap_waitok(bus_dma_tag_t dmat, bus_dmamap_t map,
|
||||
struct memdesc *mem,
|
||||
bus_dmamap_callback_t *callback,
|
||||
void *callback_arg);
|
||||
|
||||
#define _bus_dmamap_waitok(dmat, map, mem, callback, callback_arg) \
|
||||
do { \
|
||||
if ((map) != NULL) \
|
||||
__bus_dmamap_waitok(dmat, map, mem, callback, \
|
||||
callback_arg); \
|
||||
} while (0);
|
||||
|
||||
int _bus_dmamap_load_buffer(bus_dma_tag_t dmat, bus_dmamap_t map,
|
||||
void *buf, bus_size_t buflen, struct pmap *pmap,
|
||||
int flags, bus_dma_segment_t *segs, int *segp);
|
||||
|
||||
int _bus_dmamap_load_phys(bus_dma_tag_t dmat, bus_dmamap_t map,
|
||||
vm_paddr_t paddr, bus_size_t buflen,
|
||||
int flags, bus_dma_segment_t *segs, int *segp);
|
||||
|
||||
int _bus_dmamap_load_ma(bus_dma_tag_t dmat, bus_dmamap_t map,
|
||||
struct vm_page **ma, bus_size_t tlen, int ma_offs, int flags,
|
||||
bus_dma_segment_t *segs, int *segp);
|
||||
|
||||
bus_dma_segment_t *_bus_dmamap_complete(bus_dma_tag_t dmat,
|
||||
bus_dmamap_t map,
|
||||
bus_dma_segment_t *segs,
|
||||
int nsegs, int error);
|
||||
|
||||
#endif /* __sparc64__ */
|
||||
#undef BUS_DMAMAP_OP
|
||||
|
||||
#endif /* _BUS_DMA_H_ */
|
||||
|
59
sys/sys/bus_dma_internal.h
Normal file
59
sys/sys/bus_dma_internal.h
Normal file
@ -0,0 +1,59 @@
|
||||
/*-
|
||||
* Copyright (c) 2017 Jason A. Harmening.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _BUS_DMA_INTERNAL_H_
|
||||
#define _BUS_DMA_INTERNAL_H_
|
||||
|
||||
/*
|
||||
* The following functions define the interface between the MD and MI
|
||||
* busdma layers. These are not intended for consumption by driver
|
||||
* software.
|
||||
*/
|
||||
|
||||
bus_dma_segment_t *_bus_dmamap_complete(bus_dma_tag_t dmat,
|
||||
bus_dmamap_t map, bus_dma_segment_t *segs,
|
||||
int nsegs, int error);
|
||||
|
||||
int _bus_dmamap_load_buffer(bus_dma_tag_t dmat, bus_dmamap_t map,
|
||||
void *buf, bus_size_t buflen, struct pmap *pmap,
|
||||
int flags, bus_dma_segment_t *segs, int *segp);
|
||||
|
||||
int _bus_dmamap_load_ma(bus_dma_tag_t dmat, bus_dmamap_t map,
|
||||
struct vm_page **ma, bus_size_t tlen, int ma_offs,
|
||||
int flags, bus_dma_segment_t *segs, int *segp);
|
||||
|
||||
int _bus_dmamap_load_phys(bus_dma_tag_t dmat, bus_dmamap_t map,
|
||||
vm_paddr_t paddr, bus_size_t buflen,
|
||||
int flags, bus_dma_segment_t *segs, int *segp);
|
||||
|
||||
void _bus_dmamap_waitok(bus_dma_tag_t dmat, bus_dmamap_t map,
|
||||
struct memdesc *mem, bus_dmamap_callback_t *callback,
|
||||
void *callback_arg);
|
||||
|
||||
#endif /* !_BUS_DMA_INTERNAL_H_ */
|
||||
|
183
sys/x86/include/bus_dma.h
Normal file
183
sys/x86/include/bus_dma.h
Normal file
@ -0,0 +1,183 @@
|
||||
/*-
|
||||
* Copyright (c) 2017 Jason A. Harmening.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _X86_BUS_DMA_H_
|
||||
#define _X86_BUS_DMA_H_
|
||||
|
||||
#define WANT_INLINE_DMAMAP
|
||||
#include <sys/bus_dma.h>
|
||||
#include <sys/_null.h>
|
||||
|
||||
#include <x86/busdma_impl.h>
|
||||
|
||||
/*
|
||||
* Allocate a handle for mapping from kva/uva/physical
|
||||
* address space into bus device space.
|
||||
*/
|
||||
static inline int
|
||||
bus_dmamap_create(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp)
|
||||
{
|
||||
struct bus_dma_tag_common *tc;
|
||||
|
||||
tc = (struct bus_dma_tag_common *)dmat;
|
||||
return (tc->impl->map_create(dmat, flags, mapp));
|
||||
}
|
||||
|
||||
/*
|
||||
* Destroy a handle for mapping from kva/uva/physical
|
||||
* address space into bus device space.
|
||||
*/
|
||||
static inline int
|
||||
bus_dmamap_destroy(bus_dma_tag_t dmat, bus_dmamap_t map)
|
||||
{
|
||||
struct bus_dma_tag_common *tc;
|
||||
|
||||
tc = (struct bus_dma_tag_common *)dmat;
|
||||
return (tc->impl->map_destroy(dmat, map));
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate a piece of memory that can be efficiently mapped into
|
||||
* bus device space based on the constraints lited in the dma tag.
|
||||
* A dmamap to for use with dmamap_load is also allocated.
|
||||
*/
|
||||
static inline int
|
||||
bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
|
||||
bus_dmamap_t *mapp)
|
||||
{
|
||||
struct bus_dma_tag_common *tc;
|
||||
|
||||
tc = (struct bus_dma_tag_common *)dmat;
|
||||
return (tc->impl->mem_alloc(dmat, vaddr, flags, mapp));
|
||||
}
|
||||
|
||||
/*
|
||||
* Free a piece of memory and it's allociated dmamap, that was allocated
|
||||
* via bus_dmamem_alloc. Make the same choice for free/contigfree.
|
||||
*/
|
||||
static inline void
|
||||
bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map)
|
||||
{
|
||||
struct bus_dma_tag_common *tc;
|
||||
|
||||
tc = (struct bus_dma_tag_common *)dmat;
|
||||
tc->impl->mem_free(dmat, vaddr, map);
|
||||
}
|
||||
|
||||
/*
|
||||
* Release the mapping held by map.
|
||||
*/
|
||||
static inline void
|
||||
bus_dmamap_unload(bus_dma_tag_t dmat, bus_dmamap_t map)
|
||||
{
|
||||
struct bus_dma_tag_common *tc;
|
||||
|
||||
if (map != NULL) {
|
||||
tc = (struct bus_dma_tag_common *)dmat;
|
||||
tc->impl->map_unload(dmat, map);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void
|
||||
bus_dmamap_sync(bus_dma_tag_t dmat, bus_dmamap_t map, bus_dmasync_op_t op)
|
||||
{
|
||||
struct bus_dma_tag_common *tc;
|
||||
|
||||
if (map != NULL) {
|
||||
tc = (struct bus_dma_tag_common *)dmat;
|
||||
tc->impl->map_sync(dmat, map, op);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Utility function to load a physical buffer. segp contains
|
||||
* the starting segment on entrace, and the ending segment on exit.
|
||||
*/
|
||||
static inline int
|
||||
_bus_dmamap_load_phys(bus_dma_tag_t dmat, bus_dmamap_t map, vm_paddr_t buf,
|
||||
bus_size_t buflen, int flags, bus_dma_segment_t *segs, int *segp)
|
||||
{
|
||||
struct bus_dma_tag_common *tc;
|
||||
|
||||
tc = (struct bus_dma_tag_common *)dmat;
|
||||
return (tc->impl->load_phys(dmat, map, buf, buflen, flags, segs,
|
||||
segp));
|
||||
}
|
||||
|
||||
static inline int
|
||||
_bus_dmamap_load_ma(bus_dma_tag_t dmat, bus_dmamap_t map, struct vm_page **ma,
|
||||
bus_size_t tlen, int ma_offs, int flags, bus_dma_segment_t *segs,
|
||||
int *segp)
|
||||
{
|
||||
struct bus_dma_tag_common *tc;
|
||||
|
||||
tc = (struct bus_dma_tag_common *)dmat;
|
||||
return (tc->impl->load_ma(dmat, map, ma, tlen, ma_offs, flags,
|
||||
segs, segp));
|
||||
}
|
||||
|
||||
/*
|
||||
* Utility function to load a linear buffer. segp contains
|
||||
* the starting segment on entrace, and the ending segment on exit.
|
||||
*/
|
||||
static inline int
|
||||
_bus_dmamap_load_buffer(bus_dma_tag_t dmat, bus_dmamap_t map, void *buf,
|
||||
bus_size_t buflen, struct pmap *pmap, int flags, bus_dma_segment_t *segs,
|
||||
int *segp)
|
||||
{
|
||||
struct bus_dma_tag_common *tc;
|
||||
|
||||
tc = (struct bus_dma_tag_common *)dmat;
|
||||
return (tc->impl->load_buffer(dmat, map, buf, buflen, pmap, flags, segs,
|
||||
segp));
|
||||
}
|
||||
|
||||
static inline void
|
||||
_bus_dmamap_waitok(bus_dma_tag_t dmat, bus_dmamap_t map,
|
||||
struct memdesc *mem, bus_dmamap_callback_t *callback, void *callback_arg)
|
||||
{
|
||||
struct bus_dma_tag_common *tc;
|
||||
|
||||
if (map != NULL) {
|
||||
tc = (struct bus_dma_tag_common *)dmat;
|
||||
tc->impl->map_waitok(dmat, map, mem, callback, callback_arg);
|
||||
}
|
||||
}
|
||||
|
||||
static inline bus_dma_segment_t *
|
||||
_bus_dmamap_complete(bus_dma_tag_t dmat, bus_dmamap_t map,
|
||||
bus_dma_segment_t *segs, int nsegs, int error)
|
||||
{
|
||||
struct bus_dma_tag_common *tc;
|
||||
|
||||
tc = (struct bus_dma_tag_common *)dmat;
|
||||
return (tc->impl->map_complete(dmat, map, segs, nsegs, error));
|
||||
}
|
||||
|
||||
#endif /* !_X86_BUS_DMA_H_ */
|
||||
|
@ -70,7 +70,7 @@ struct bus_dma_impl {
|
||||
vm_paddr_t buf, bus_size_t buflen, int flags,
|
||||
bus_dma_segment_t *segs, int *segp);
|
||||
int (*load_buffer)(bus_dma_tag_t dmat, bus_dmamap_t map,
|
||||
void *buf, bus_size_t buflen, pmap_t pmap, int flags,
|
||||
void *buf, bus_size_t buflen, struct pmap *pmap, int flags,
|
||||
bus_dma_segment_t *segs, int *segp);
|
||||
void (*map_waitok)(bus_dma_tag_t dmat, bus_dmamap_t map,
|
||||
struct memdesc *mem, bus_dmamap_callback_t *callback,
|
||||
|
@ -361,6 +361,8 @@ dmar_bus_dmamap_create(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp)
|
||||
struct bus_dma_tag_dmar *tag;
|
||||
struct bus_dmamap_dmar *map;
|
||||
|
||||
WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL, "%s", __func__);
|
||||
|
||||
tag = (struct bus_dma_tag_dmar *)dmat;
|
||||
map = malloc(sizeof(*map), M_DMAR_DMAMAP, M_NOWAIT | M_ZERO);
|
||||
if (map == NULL) {
|
||||
|
@ -262,6 +262,8 @@ bounce_bus_dmamap_create(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp)
|
||||
struct bounce_zone *bz;
|
||||
int error, maxpages, pages;
|
||||
|
||||
WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL, "%s", __func__);
|
||||
|
||||
error = 0;
|
||||
|
||||
if (dmat->segments == NULL) {
|
||||
@ -371,6 +373,8 @@ bounce_bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
|
||||
vm_memattr_t attr;
|
||||
int mflags;
|
||||
|
||||
WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL, "%s", __func__);
|
||||
|
||||
if (flags & BUS_DMA_NOWAIT)
|
||||
mflags = M_NOWAIT;
|
||||
else
|
||||
|
@ -221,145 +221,3 @@ bus_dma_tag_destroy(bus_dma_tag_t dmat)
|
||||
return (tc->impl->tag_destroy(dmat));
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate a handle for mapping from kva/uva/physical
|
||||
* address space into bus device space.
|
||||
*/
|
||||
int
|
||||
bus_dmamap_create(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp)
|
||||
{
|
||||
struct bus_dma_tag_common *tc;
|
||||
|
||||
WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL, "%s", __func__);
|
||||
|
||||
tc = (struct bus_dma_tag_common *)dmat;
|
||||
return (tc->impl->map_create(dmat, flags, mapp));
|
||||
}
|
||||
|
||||
/*
|
||||
* Destroy a handle for mapping from kva/uva/physical
|
||||
* address space into bus device space.
|
||||
*/
|
||||
int
|
||||
bus_dmamap_destroy(bus_dma_tag_t dmat, bus_dmamap_t map)
|
||||
{
|
||||
struct bus_dma_tag_common *tc;
|
||||
|
||||
tc = (struct bus_dma_tag_common *)dmat;
|
||||
return (tc->impl->map_destroy(dmat, map));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Allocate a piece of memory that can be efficiently mapped into
|
||||
* 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(bus_dma_tag_t dmat, void** vaddr, int flags,
|
||||
bus_dmamap_t *mapp)
|
||||
{
|
||||
struct bus_dma_tag_common *tc;
|
||||
|
||||
WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL, "%s", __func__);
|
||||
|
||||
tc = (struct bus_dma_tag_common *)dmat;
|
||||
return (tc->impl->mem_alloc(dmat, vaddr, flags, mapp));
|
||||
}
|
||||
|
||||
/*
|
||||
* 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)
|
||||
{
|
||||
struct bus_dma_tag_common *tc;
|
||||
|
||||
tc = (struct bus_dma_tag_common *)dmat;
|
||||
tc->impl->mem_free(dmat, vaddr, map);
|
||||
}
|
||||
|
||||
/*
|
||||
* Utility function to load a physical buffer. segp contains
|
||||
* the starting segment on entrace, and the ending segment on exit.
|
||||
*/
|
||||
int
|
||||
_bus_dmamap_load_phys(bus_dma_tag_t dmat, bus_dmamap_t map, vm_paddr_t buf,
|
||||
bus_size_t buflen, int flags, bus_dma_segment_t *segs, int *segp)
|
||||
{
|
||||
struct bus_dma_tag_common *tc;
|
||||
|
||||
tc = (struct bus_dma_tag_common *)dmat;
|
||||
return (tc->impl->load_phys(dmat, map, buf, buflen, flags, segs,
|
||||
segp));
|
||||
}
|
||||
|
||||
int
|
||||
_bus_dmamap_load_ma(bus_dma_tag_t dmat, bus_dmamap_t map, struct vm_page **ma,
|
||||
bus_size_t tlen, int ma_offs, int flags, bus_dma_segment_t *segs,
|
||||
int *segp)
|
||||
{
|
||||
struct bus_dma_tag_common *tc;
|
||||
|
||||
tc = (struct bus_dma_tag_common *)dmat;
|
||||
return (tc->impl->load_ma(dmat, map, ma, tlen, ma_offs, flags,
|
||||
segs, segp));
|
||||
}
|
||||
|
||||
/*
|
||||
* Utility function to load a linear buffer. segp contains
|
||||
* the starting segment on entrace, and the ending segment on exit.
|
||||
*/
|
||||
int
|
||||
_bus_dmamap_load_buffer(bus_dma_tag_t dmat, bus_dmamap_t map, void *buf,
|
||||
bus_size_t buflen, pmap_t pmap, int flags, bus_dma_segment_t *segs,
|
||||
int *segp)
|
||||
{
|
||||
struct bus_dma_tag_common *tc;
|
||||
|
||||
tc = (struct bus_dma_tag_common *)dmat;
|
||||
return (tc->impl->load_buffer(dmat, map, buf, buflen, pmap, flags, segs,
|
||||
segp));
|
||||
}
|
||||
|
||||
void
|
||||
__bus_dmamap_waitok(bus_dma_tag_t dmat, bus_dmamap_t map,
|
||||
struct memdesc *mem, bus_dmamap_callback_t *callback, void *callback_arg)
|
||||
{
|
||||
struct bus_dma_tag_common *tc;
|
||||
|
||||
tc = (struct bus_dma_tag_common *)dmat;
|
||||
tc->impl->map_waitok(dmat, map, mem, callback, callback_arg);
|
||||
}
|
||||
|
||||
bus_dma_segment_t *
|
||||
_bus_dmamap_complete(bus_dma_tag_t dmat, bus_dmamap_t map,
|
||||
bus_dma_segment_t *segs, int nsegs, int error)
|
||||
{
|
||||
struct bus_dma_tag_common *tc;
|
||||
|
||||
tc = (struct bus_dma_tag_common *)dmat;
|
||||
return (tc->impl->map_complete(dmat, map, segs, nsegs, error));
|
||||
}
|
||||
|
||||
/*
|
||||
* Release the mapping held by map.
|
||||
*/
|
||||
void
|
||||
_bus_dmamap_unload(bus_dma_tag_t dmat, bus_dmamap_t map)
|
||||
{
|
||||
struct bus_dma_tag_common *tc;
|
||||
|
||||
tc = (struct bus_dma_tag_common *)dmat;
|
||||
tc->impl->map_unload(dmat, map);
|
||||
}
|
||||
|
||||
void
|
||||
_bus_dmamap_sync(bus_dma_tag_t dmat, bus_dmamap_t map, bus_dmasync_op_t op)
|
||||
{
|
||||
struct bus_dma_tag_common *tc;
|
||||
|
||||
tc = (struct bus_dma_tag_common *)dmat;
|
||||
tc->impl->map_sync(dmat, map, op);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user