2006-08-30 15:37:39 +04:00
|
|
|
.\" $NetBSD: bus_dma.9,v 1.37 2006/08/30 11:37:39 jnemeth Exp $
|
1997-08-12 03:40:33 +04:00
|
|
|
.\"
|
2006-01-29 05:26:27 +03:00
|
|
|
.\" Copyright (c) 1996, 1997, 1998, 2001, 2005, 2006 The NetBSD Foundation, Inc.
|
1997-08-12 03:40:33 +04:00
|
|
|
.\" All rights reserved.
|
2001-06-21 15:59:00 +04:00
|
|
|
.\"
|
1997-08-12 03:40:33 +04:00
|
|
|
.\" This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
.\" by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
|
|
|
|
.\" NASA Ames Research Center.
|
2001-06-21 15:59:00 +04:00
|
|
|
.\"
|
1997-08-12 03:40:33 +04:00
|
|
|
.\" 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.
|
|
|
|
.\" 3. All advertising materials mentioning features or use of this software
|
1997-08-12 17:21:52 +04:00
|
|
|
.\" must display the following acknowledgment:
|
1997-08-12 03:40:33 +04:00
|
|
|
.\" This product includes software developed by the NetBSD
|
|
|
|
.\" Foundation, Inc. and its contributors.
|
|
|
|
.\" 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
.\" contributors may be used to endorse or promote products derived
|
|
|
|
.\" from this software without specific prior written permission.
|
2001-06-21 15:59:00 +04:00
|
|
|
.\"
|
1997-08-12 03:40:33 +04:00
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
|
1997-08-12 11:09:31 +04:00
|
|
|
.\"
|
2006-08-30 15:37:39 +04:00
|
|
|
.Dd August 30, 2006
|
1997-08-13 19:24:58 +04:00
|
|
|
.Dt BUS_DMA 9
|
1999-03-16 03:40:46 +03:00
|
|
|
.Os
|
1997-08-12 03:40:33 +04:00
|
|
|
.Sh NAME
|
1997-11-11 13:06:37 +03:00
|
|
|
.Nm bus_dma ,
|
|
|
|
.Nm bus_dmamap_create ,
|
|
|
|
.Nm bus_dmamap_destroy ,
|
|
|
|
.Nm bus_dmamap_load ,
|
|
|
|
.Nm bus_dmamap_load_mbuf ,
|
|
|
|
.Nm bus_dmamap_load_uio ,
|
|
|
|
.Nm bus_dmamap_load_raw ,
|
|
|
|
.Nm bus_dmamap_unload ,
|
|
|
|
.Nm bus_dmamap_sync ,
|
|
|
|
.Nm bus_dmamem_alloc ,
|
|
|
|
.Nm bus_dmamem_free ,
|
|
|
|
.Nm bus_dmamem_map ,
|
|
|
|
.Nm bus_dmamem_unmap ,
|
|
|
|
.Nm bus_dmamem_mmap
|
1997-08-12 03:40:33 +04:00
|
|
|
.Nd Bus and Machine Independent DMA Mapping Interface
|
|
|
|
.Sh SYNOPSIS
|
2003-04-16 17:34:34 +04:00
|
|
|
.In machine/bus.h
|
1997-08-12 03:40:33 +04:00
|
|
|
.Ft int
|
|
|
|
.Fn bus_dmamap_create "bus_dma_tag_t tag" "bus_size_t size" "int nsegments" \
|
|
|
|
"bus_size_t maxsegsz" "bus_size_t boundary" "int flags" "bus_dmamap_t *dmamp"
|
|
|
|
.Ft void
|
|
|
|
.Fn bus_dmamap_destroy "bus_dma_tag_t tag" "bus_dmamap_t dmam"
|
|
|
|
.Ft int
|
|
|
|
.Fn bus_dmamap_load "bus_dma_tag_t tag" "bus_dmamap_t dmam" "void *buf" \
|
2005-12-20 22:53:14 +03:00
|
|
|
"bus_size_t buflen" "struct lwp *l" "int flags"
|
1997-08-12 03:40:33 +04:00
|
|
|
.Ft int
|
|
|
|
.Fn bus_dmamap_load_mbuf "bus_dma_tag_t tag" "bus_dmamap_t dmam" \
|
|
|
|
"struct mbuf *chain" "int flags"
|
|
|
|
.Ft int
|
|
|
|
.Fn bus_dmamap_load_uio "bus_dma_tag_t tag" "bus_dmamap_t dmam" \
|
|
|
|
"struct uio *uio" "int flags"
|
|
|
|
.Ft int
|
|
|
|
.Fn bus_dmamap_load_raw "bus_dma_tag_t tag" "bus_dmamap_t dmam" \
|
|
|
|
"bus_dma_segment_t *segs" "int nsegs" "bus_size_t size" "int flags"
|
|
|
|
.Ft void
|
|
|
|
.Fn bus_dmamap_unload "bus_dma_tag_t tag" "bus_dmamap_t dmam"
|
|
|
|
.Ft void
|
|
|
|
.Fn bus_dmamap_sync "bus_dma_tag_t tag" "bus_dmamap_t dmam" \
|
1998-02-04 09:42:53 +03:00
|
|
|
"bus_addr_t offset" "bus_size_t len" "int ops"
|
1997-08-12 03:40:33 +04:00
|
|
|
.Ft int
|
|
|
|
.Fn bus_dmamem_alloc "bus_dma_tag_t tag" "bus_size_t size" \
|
|
|
|
"bus_size_t alignment" "bus_size_t boundary" "bus_dma_segment_t *segs" \
|
|
|
|
"int nsegs" "int *rsegs" "int flags"
|
|
|
|
.Ft void
|
|
|
|
.Fn bus_dmamem_free "bus_dma_tag_t tag" "bus_dma_segment_t *segs" "int nsegs"
|
1997-08-12 11:31:42 +04:00
|
|
|
.Ft int
|
|
|
|
.Fn bus_dmamem_map "bus_dma_tag_t tag" "bus_dma_segment_t *segs" "int nsegs" \
|
|
|
|
"size_t size" "caddr_t *kvap" "int flags"
|
1997-08-12 03:40:33 +04:00
|
|
|
.Ft void
|
|
|
|
.Fn bus_dmamem_unmap "bus_dma_tag_t tag" "caddr_t kva" "size_t size"
|
2001-09-03 04:37:54 +04:00
|
|
|
.Ft paddr_t
|
1997-08-12 03:40:33 +04:00
|
|
|
.Fn bus_dmamem_mmap "bus_dma_tag_t tag" "bus_dma_segment_t *segs" \
|
2001-09-03 04:29:35 +04:00
|
|
|
"int nsegs" "off_t off" "int prot" "int flags"
|
1997-08-12 03:40:33 +04:00
|
|
|
.Sh DESCRIPTION
|
|
|
|
Provide a bus- and machine-independent "DMA mapping interface."
|
|
|
|
.Sh NOTES
|
|
|
|
All data structures, function prototypes, and macros will be defined
|
1997-08-12 11:09:31 +04:00
|
|
|
by the port-specific header
|
2003-06-30 16:10:40 +04:00
|
|
|
.Aq Pa machine/bus.h .
|
1997-08-12 11:09:31 +04:00
|
|
|
Note that this document
|
1997-08-12 03:40:33 +04:00
|
|
|
assumes the existence of types already defined by the current "bus.h"
|
|
|
|
interface.
|
|
|
|
.Pp
|
|
|
|
Unless otherwise noted, all function calls in this interface may be
|
1997-08-12 11:09:31 +04:00
|
|
|
defined as
|
|
|
|
.Xr cpp 1
|
|
|
|
macros.
|
1997-08-12 03:40:33 +04:00
|
|
|
.Sh DATA TYPES
|
|
|
|
Individual implementations may name these structures whatever they
|
|
|
|
wish, providing that the external representations are:
|
|
|
|
.Bl -tag -width compact
|
|
|
|
.It Fa bus_dma_tag_t
|
|
|
|
A machine-dependent opaque type describing the implementation of
|
|
|
|
DMA for a given bus.
|
|
|
|
.It Fa bus_dma_segment_t
|
|
|
|
A structure with at least the following members:
|
|
|
|
.Bd -literal
|
|
|
|
bus_addr_t ds_addr;
|
|
|
|
bus_size_t ds_len;
|
|
|
|
.Ed
|
|
|
|
.sp
|
|
|
|
The structure may have machine-dependent members and arbitrary layout.
|
1997-08-12 11:09:31 +04:00
|
|
|
The values in
|
|
|
|
.Fa ds_addr
|
|
|
|
and
|
|
|
|
.Fa ds_len
|
|
|
|
are suitable for programming into
|
1997-08-12 03:40:33 +04:00
|
|
|
DMA controller address and length registers.
|
|
|
|
.It Fa bus_dmamap_t
|
|
|
|
A pointer to a structure with at least the following members:
|
|
|
|
.Bd -literal
|
2005-03-10 00:22:59 +03:00
|
|
|
bus_size_t dm_maxsegsz;
|
1998-02-04 09:42:53 +03:00
|
|
|
bus_size_t dm_mapsize;
|
|
|
|
int dm_nsegs;
|
1997-08-12 03:40:33 +04:00
|
|
|
bus_dma_segment_t *dm_segs;
|
|
|
|
.Ed
|
|
|
|
.sp
|
|
|
|
The structure may have machine-dependent members and arbitrary layout.
|
1997-08-12 11:09:31 +04:00
|
|
|
The
|
2005-03-10 00:22:59 +03:00
|
|
|
.Fa dm_maxsegsz
|
|
|
|
member indicates the maximum number of bytes that may be transferred by
|
|
|
|
any given DMA segment.
|
|
|
|
The
|
1998-02-04 09:42:53 +03:00
|
|
|
.Fa dm_mapsize
|
2002-10-14 17:43:14 +04:00
|
|
|
member indicates the size of the mapping.
|
|
|
|
A value of 0 indicates the mapping is invalid.
|
1998-02-04 09:42:53 +03:00
|
|
|
The
|
1997-08-12 11:09:31 +04:00
|
|
|
.Fa dm_segs
|
|
|
|
member may be an array of segments or a pointer to an
|
2002-10-14 17:43:14 +04:00
|
|
|
array of segments.
|
|
|
|
The
|
1997-08-12 11:09:31 +04:00
|
|
|
.Fa dm_nsegs
|
|
|
|
member indicates the number of segments in
|
|
|
|
.Fa dm_segs .
|
1997-08-12 03:40:33 +04:00
|
|
|
.El
|
|
|
|
.Sh FUNCTIONS
|
|
|
|
.Bl -tag -width compact
|
1997-08-13 19:24:58 +04:00
|
|
|
.It Fn bus_dmamap_create "tag" "size" "nsegments" "maxsegsz" "boundary" "flags" "dmamp"
|
1997-08-12 11:09:31 +04:00
|
|
|
Allocates a DMA handle and initializes it according to the parameters
|
1999-03-07 01:09:29 +03:00
|
|
|
provided.
|
|
|
|
Arguments are as follows:
|
1997-08-12 11:09:31 +04:00
|
|
|
.Bl -tag -width nsegments -compact
|
1997-08-12 03:40:33 +04:00
|
|
|
.It Fa tag
|
|
|
|
This is the bus_dma_tag_t passed down from the parent driver via
|
2002-02-13 11:17:26 +03:00
|
|
|
.Fa \*[Lt]bus\*[Gt]_attach_args .
|
1997-08-12 03:40:33 +04:00
|
|
|
.It Fa size
|
|
|
|
This is the maximum DMA transfer that can be mapped by the handle.
|
|
|
|
.It Fa nsegments
|
|
|
|
Number of segments the device can support in a single DMA transaction.
|
|
|
|
This may be the number of scatter-gather descriptors supported by the
|
|
|
|
device.
|
|
|
|
.It Fa maxsegsz
|
1997-08-12 11:09:31 +04:00
|
|
|
The maximum number of bytes that may be transferred by any given DMA
|
2005-03-10 00:22:59 +03:00
|
|
|
segment and will be assigned to the
|
|
|
|
.Fa dm_maxsegsz
|
|
|
|
member.
|
1997-08-12 03:40:33 +04:00
|
|
|
.It Fa boundary
|
|
|
|
Some DMA controllers are not able to transfer data that crosses a
|
2002-10-14 17:43:14 +04:00
|
|
|
particular boundary.
|
|
|
|
This argument allows this boundary to be specified.
|
|
|
|
The boundary lines begin at 0, and occur every
|
1997-08-12 11:09:31 +04:00
|
|
|
.Fa boundary
|
2002-10-14 17:43:14 +04:00
|
|
|
bytes.
|
|
|
|
Mappings may begin on a boundary line but may not end on or
|
|
|
|
cross a boundary line.
|
|
|
|
If no boundary condition needs to be observed, a
|
1997-08-12 11:09:31 +04:00
|
|
|
.Fa boundary
|
|
|
|
argument of 0 should be used.
|
1997-08-12 03:40:33 +04:00
|
|
|
.It Fa flags
|
|
|
|
Flags are defined as follows:
|
|
|
|
.Bl -tag -width BUS_DMA_ALLOCNOW -compact
|
|
|
|
.It Dv BUS_DMA_WAITOK
|
1997-08-12 11:09:31 +04:00
|
|
|
It is safe to wait (sleep) for resources during this call.
|
1997-08-12 03:40:33 +04:00
|
|
|
.It Dv BUS_DMA_NOWAIT
|
|
|
|
It is not safe to wait (sleep) for resources during this call.
|
|
|
|
.It Dv BUS_DMA_ALLOCNOW
|
2002-10-14 17:43:14 +04:00
|
|
|
Perform any resource allocation this handle may need now.
|
|
|
|
If this is not specified, the allocation may be deferred to
|
1997-08-12 03:40:33 +04:00
|
|
|
.Fn bus_dmamap_load .
|
|
|
|
If this flag is specified,
|
|
|
|
.Fn bus_dmamap_load
|
|
|
|
will not block on resource
|
|
|
|
allocation.
|
|
|
|
.It Dv BUS_DMA_BUS[1-4]
|
|
|
|
These flags are placeholders, and may be used by busses to provide
|
|
|
|
bus-dependent functionality.
|
|
|
|
.El
|
|
|
|
.It Fa dmamp
|
2002-10-14 17:43:14 +04:00
|
|
|
This is a pointer to a bus_dmamap_t.
|
|
|
|
A DMA map will be allocated and pointed to by
|
1997-08-12 11:09:31 +04:00
|
|
|
.Fa dmamp
|
1997-08-12 17:21:52 +04:00
|
|
|
upon successful completion of this routine.
|
1997-08-12 03:40:33 +04:00
|
|
|
.El
|
1997-08-12 11:09:31 +04:00
|
|
|
.Pp
|
1997-08-12 03:40:33 +04:00
|
|
|
Behavior is not defined if invalid arguments are passed to
|
|
|
|
.Fn bus_dmamap_create .
|
|
|
|
.Pp
|
1997-08-12 11:09:31 +04:00
|
|
|
Returns 0 on success, or an error code to indicate mode of failure.
|
1997-08-13 19:24:58 +04:00
|
|
|
.It Fn bus_dmamap_destroy "tag" "dmam"
|
2002-10-14 17:43:14 +04:00
|
|
|
Frees all resources associated with a given DMA handle.
|
|
|
|
Arguments are as follows:
|
1997-08-12 03:40:33 +04:00
|
|
|
.Bl -tag -width dmam -compact
|
|
|
|
.It Fa tag
|
|
|
|
This is the bus_dma_tag_t passed down from the parent driver via
|
2002-02-13 11:17:26 +03:00
|
|
|
.Fa \*[Lt]bus\*[Gt]_attach_args .
|
1997-08-12 03:40:33 +04:00
|
|
|
.It Fa dmam
|
1997-08-12 11:09:31 +04:00
|
|
|
The DMA handle to destroy.
|
1997-08-12 03:40:33 +04:00
|
|
|
.El
|
|
|
|
.Pp
|
1997-08-12 11:09:31 +04:00
|
|
|
In the event that the DMA handle contains a valid mapping,
|
2001-06-21 15:59:00 +04:00
|
|
|
the mapping will be unloaded via the same mechanism used by
|
1997-08-12 03:40:33 +04:00
|
|
|
.Fn bus_dmamap_unload .
|
|
|
|
.Pp
|
1997-08-12 11:09:31 +04:00
|
|
|
Behavior is not defined if invalid arguments are passed to
|
1997-08-12 03:40:33 +04:00
|
|
|
.Fn bus_dmamap_destroy .
|
|
|
|
.Pp
|
|
|
|
If given valid arguments,
|
|
|
|
.Fn bus_dmamap_destroy
|
1997-08-12 17:21:52 +04:00
|
|
|
always succeeds.
|
2006-08-30 15:37:39 +04:00
|
|
|
.It Fn bus_dmamap_load "tag" "dmam" "buf" "buflen" "l" "flags"
|
2002-10-14 17:43:14 +04:00
|
|
|
Loads a DMA handle with mappings for a DMA transfer.
|
|
|
|
It assumes that all pages involved in a DMA transfer are wired.
|
1999-03-07 01:09:29 +03:00
|
|
|
Arguments are as follows:
|
1997-08-12 03:40:33 +04:00
|
|
|
.Bl -tag -width buflen -compact
|
|
|
|
.It Fa tag
|
|
|
|
This is the bus_dma_tag_t passed down from the parent driver via
|
2002-02-13 11:17:26 +03:00
|
|
|
.Fa \*[Lt]bus\*[Gt]_attach_args .
|
1997-08-12 03:40:33 +04:00
|
|
|
.It Fa dmam
|
1997-08-12 11:09:31 +04:00
|
|
|
The DMA handle with which to map the transfer.
|
1997-08-12 03:40:33 +04:00
|
|
|
.It Fa buf
|
|
|
|
The buffer to be used for the DMA transfer.
|
|
|
|
.It Fa buflen
|
|
|
|
The size of the buffer.
|
2006-01-29 05:26:27 +03:00
|
|
|
.It Fa l
|
2002-10-14 17:43:14 +04:00
|
|
|
Used to indicate the address space in which the buffer is located.
|
|
|
|
If
|
1997-08-12 11:09:31 +04:00
|
|
|
.Dv NULL ,
|
2002-10-14 17:43:14 +04:00
|
|
|
the buffer is assumed to be in kernel space.
|
2006-01-29 05:26:27 +03:00
|
|
|
Otherwise, the buffer is assumed to be in lwp
|
2006-02-04 23:19:21 +03:00
|
|
|
.Fa l Ap s
|
1997-08-12 11:09:31 +04:00
|
|
|
address space.
|
1997-08-12 03:40:33 +04:00
|
|
|
.It Fa flags
|
|
|
|
are defined as follows:
|
2001-03-08 01:23:45 +03:00
|
|
|
.Bl -tag -width "BUS_DMA_STREAMING" -compact
|
1997-08-12 03:40:33 +04:00
|
|
|
.It Dv BUS_DMA_WAITOK
|
|
|
|
It is safe to wait (sleep) for resources during this call.
|
|
|
|
.It Dv BUS_DMA_NOWAIT
|
|
|
|
It is not safe to wait (sleep) for resources during this call.
|
2001-03-08 01:23:45 +03:00
|
|
|
.It Dv BUS_DMA_STREAMING
|
|
|
|
By default, the
|
|
|
|
.Nm
|
|
|
|
API assumes that there is coherency between memory and the device
|
2002-10-14 17:43:14 +04:00
|
|
|
performing the DMA transaction.
|
|
|
|
Some platforms, however, have special hardware, such as an
|
2001-03-08 01:23:45 +03:00
|
|
|
.Dq I/O cache ,
|
|
|
|
which may improve performance
|
|
|
|
of some types of DMA transactions, but which break the assumption
|
|
|
|
that there is coherency between memory and the device performing
|
|
|
|
the DMA transaction.
|
|
|
|
This flag allows the use of this special hardware, provided that
|
|
|
|
the device is doing sequential, unidirectional transfers which
|
2001-06-21 15:59:00 +04:00
|
|
|
conform to certain alignment and size constraints defined by the
|
2002-10-14 17:43:14 +04:00
|
|
|
platform.
|
|
|
|
If the platform does not support the feature, or if the buffer being
|
|
|
|
loaded into the DMA map does not conform to the constraints required
|
|
|
|
for use of the feature, then this flag will be silently ignored.
|
|
|
|
Also refer to the use of this flag with the
|
2001-03-08 01:23:45 +03:00
|
|
|
.Fn bus_dmamem_alloc
|
|
|
|
function.
|
2001-07-19 19:32:06 +04:00
|
|
|
.It Dv BUS_DMA_READ
|
|
|
|
This is a hint to the machine-dependent back-end that indicates the
|
|
|
|
mapping will be used only for a
|
2002-02-13 11:17:26 +03:00
|
|
|
.Em "device -\*[Gt] memory"
|
2002-10-14 17:43:14 +04:00
|
|
|
transaction.
|
|
|
|
The back-end may perform optimizations based on this information.
|
2001-07-19 19:32:06 +04:00
|
|
|
.It Dv BUS_DMA_WRITE
|
|
|
|
This is a hint to the machine-dependent back-end that indicates the
|
|
|
|
mapping will be used only for a
|
2002-02-13 11:17:26 +03:00
|
|
|
.Em "memory -\*[Gt] device"
|
2002-10-14 17:43:14 +04:00
|
|
|
transaction.
|
|
|
|
The back-end may perform optimizations based on this information.
|
1997-08-12 03:40:33 +04:00
|
|
|
.It Dv BUS_DMA_BUS[1-4]
|
|
|
|
These flags are placeholders, and may be used by busses to
|
|
|
|
provide bus-dependent functionality.
|
|
|
|
.El
|
|
|
|
.El
|
|
|
|
.Pp
|
1997-08-12 11:09:31 +04:00
|
|
|
As noted above, if a DMA handle is created with
|
1997-08-12 03:40:33 +04:00
|
|
|
.Dv BUS_DMA_ALLOCNOW ,
|
|
|
|
.Fn bus_dmamap_load
|
|
|
|
will never block.
|
|
|
|
.Pp
|
2001-06-21 15:59:00 +04:00
|
|
|
If a call to
|
1997-08-12 03:40:33 +04:00
|
|
|
.Fn bus_dmamap_load
|
|
|
|
fails, the mapping in
|
2002-10-14 17:43:14 +04:00
|
|
|
the DMA handle will be invalid.
|
|
|
|
It is the responsibility of the caller to clean up any inconsistent
|
|
|
|
device state resulting from incomplete iteration through the uio.
|
1997-08-12 03:40:33 +04:00
|
|
|
.Pp
|
|
|
|
Behavior is not defined if invalid arguments are passed to
|
|
|
|
.Fn bus_dmamap_load .
|
|
|
|
.Pp
|
1997-08-12 11:09:31 +04:00
|
|
|
Returns 0 on success, or an error code to indicate mode of failure.
|
1997-08-13 19:24:58 +04:00
|
|
|
.It Fn bus_dmamap_load_mbuf "tag" "dmam" "chain" "flags"
|
2001-06-21 15:59:00 +04:00
|
|
|
This is a variation of
|
1997-08-12 03:40:33 +04:00
|
|
|
.Fn bus_dmamap_load
|
|
|
|
which maps mbuf chains
|
2002-10-14 17:43:14 +04:00
|
|
|
for DMA transfers.
|
|
|
|
Mbuf chains are assumed to be in kernel virtual address space.
|
1997-08-13 19:24:58 +04:00
|
|
|
.It Fn bus_dmamap_load_uio "tag" "dmam" "uio" "flags"
|
1997-08-12 03:40:33 +04:00
|
|
|
This is a variation of
|
|
|
|
.Fn bus_dmamap_load
|
1997-08-12 11:09:31 +04:00
|
|
|
which maps buffers pointed to by
|
|
|
|
.Fa uio
|
2002-10-14 17:43:14 +04:00
|
|
|
for DMA transfers.
|
|
|
|
The value of
|
2002-02-13 11:17:26 +03:00
|
|
|
.Fa "uio-\*[Gt]uio_segflg"
|
1997-08-12 11:09:31 +04:00
|
|
|
will
|
1997-08-12 03:40:33 +04:00
|
|
|
determine if the buffers are in user or kernel virtual address space.
|
|
|
|
If the buffers are in user address space, the buffers are assumed to be
|
1997-08-12 11:09:31 +04:00
|
|
|
in
|
2006-02-04 23:19:21 +03:00
|
|
|
.Fa "uio-\*[Gt]uio_procp" Ap s
|
1997-08-12 11:09:31 +04:00
|
|
|
address space.
|
1997-08-13 19:24:58 +04:00
|
|
|
.It Fn bus_dmamap_load_raw "tag" "dmam" "segs" "nsegs" "size" "flags"
|
1997-08-12 03:40:33 +04:00
|
|
|
This is a variation of
|
|
|
|
.Fn bus_dmamap_load
|
|
|
|
which maps buffers
|
|
|
|
allocated by
|
|
|
|
.Fn bus_dmamem_alloc
|
2002-10-14 17:43:14 +04:00
|
|
|
(see below).
|
|
|
|
The
|
1997-08-12 11:09:31 +04:00
|
|
|
.Fa segs
|
1997-08-12 03:40:33 +04:00
|
|
|
argument is an array of bus_dma_segment_t's filled in
|
|
|
|
by
|
|
|
|
.Fn bus_dmamem_alloc .
|
1997-08-12 11:09:31 +04:00
|
|
|
The
|
|
|
|
.Fa nsegs
|
2002-10-14 17:43:14 +04:00
|
|
|
argument is the number of segments in the array.
|
|
|
|
The
|
1997-08-12 11:09:31 +04:00
|
|
|
.Fa size
|
|
|
|
argument is the size of the DMA transfer.
|
1997-08-13 19:24:58 +04:00
|
|
|
.It Fn bus_dmamap_unload "tag" "dmam"
|
2002-10-14 17:43:14 +04:00
|
|
|
Deletes the mappings for a given DMA handle.
|
|
|
|
Arguments are as follows:
|
1997-08-12 03:40:33 +04:00
|
|
|
.Bl -tag -width dmam -compact
|
|
|
|
.It Fa tag
|
|
|
|
This is the bus_dma_tag_t passed down from the parent driver via
|
2002-02-13 11:17:26 +03:00
|
|
|
.Fa \*[Lt]bus\*[Gt]_attach_args .
|
1997-08-12 03:40:33 +04:00
|
|
|
.It Fa dmam
|
1997-08-12 11:09:31 +04:00
|
|
|
The DMA handle containing the mappings which are to be deleted.
|
1997-08-12 03:40:33 +04:00
|
|
|
.El
|
|
|
|
.Pp
|
1997-08-12 11:09:31 +04:00
|
|
|
If the DMA handle was created with
|
1997-08-12 03:40:33 +04:00
|
|
|
.Dv BUS_DMA_ALLOCNOW ,
|
|
|
|
.Fn bus_dmamap_unload
|
|
|
|
will not free the corresponding
|
|
|
|
resources which were allocated by
|
|
|
|
.Fn bus_dmamap_create .
|
|
|
|
This is to ensure that
|
|
|
|
.Fn bus_dmamap_load
|
|
|
|
will never block
|
|
|
|
on resources if the handle was created with
|
|
|
|
.Dv BUS_DMA_ALLOCNOW .
|
|
|
|
.Pp
|
2002-06-12 19:23:34 +04:00
|
|
|
.Fn bus_dmamap_unload
|
2002-10-14 17:43:14 +04:00
|
|
|
will not perform any implicit synchronization of DMA buffers.
|
|
|
|
This must be done explicitly by
|
2002-06-12 19:23:34 +04:00
|
|
|
.Fn bus_dmamap_sync .
|
|
|
|
.Pp
|
2005-03-10 00:22:59 +03:00
|
|
|
.Fn bus_dmamap_unload
|
|
|
|
will restore the
|
|
|
|
.Fa dm_maxsegsz
|
|
|
|
member to its initial value assigned by
|
|
|
|
.Fn bus_dmamap_create .
|
|
|
|
.Pp
|
1997-08-12 03:40:33 +04:00
|
|
|
Behavior is not defined if invalid arguments are passed to
|
|
|
|
.Fn bus_dmamap_unload .
|
|
|
|
.Pp
|
|
|
|
If given valid arguments,
|
|
|
|
.Fn bus_dmamap_unload
|
1997-08-12 17:21:52 +04:00
|
|
|
always succeeds.
|
1998-02-04 09:42:53 +03:00
|
|
|
.It Fn bus_dmamap_sync "tag" "dmam" "offset" "len" "ops"
|
1997-08-12 03:40:33 +04:00
|
|
|
Performs pre- and post-DMA operation cache and/or buffer synchronization.
|
|
|
|
Arguments are as follows:
|
1998-02-04 09:42:53 +03:00
|
|
|
.Bl -tag -width offset -compact
|
1997-08-12 03:40:33 +04:00
|
|
|
.It Fa tag
|
|
|
|
This is the bus_dma_tag_t passed down from the parent driver via
|
2002-02-13 11:17:26 +03:00
|
|
|
.Fa \*[Lt]bus\*[Gt]_attach_args .
|
1997-08-12 03:40:33 +04:00
|
|
|
.It Fa dmam
|
|
|
|
The DMA mapping to be synchronized.
|
1998-02-04 09:42:53 +03:00
|
|
|
.It Fa offset
|
|
|
|
The offset into the DMA mapping to synchronize.
|
|
|
|
.It Fa len
|
|
|
|
The length of the mapping from
|
|
|
|
.Fa offset
|
|
|
|
to synchronize.
|
|
|
|
.It Fa ops
|
2002-10-14 17:43:14 +04:00
|
|
|
One or more synchronization operation to perform.
|
|
|
|
The following DMA synchronization operations are defined:
|
1997-08-12 03:40:33 +04:00
|
|
|
.Bl -tag -width BUS_DMASYNC_POSTWRITE -compact
|
|
|
|
.It Dv BUS_DMASYNC_PREREAD
|
|
|
|
Perform any pre-read DMA cache and/or bounce operations.
|
|
|
|
.It Dv BUS_DMASYNC_POSTREAD
|
|
|
|
Perform any post-read DMA cache and/or bounce operations.
|
|
|
|
.It Dv BUS_DMASYNC_PREWRITE
|
|
|
|
Perform any pre-write DMA cache and/or bounce operations.
|
|
|
|
.It Dv BUS_DMASYNC_POSTWRITE
|
|
|
|
Perform any post-write DMA cache and/or bounce operations.
|
|
|
|
.El
|
1998-02-04 09:42:53 +03:00
|
|
|
.Pp
|
|
|
|
More than one operation may performed in a given synchronization call.
|
|
|
|
Mixing of
|
|
|
|
.Em PRE
|
|
|
|
and
|
|
|
|
.Em POST
|
|
|
|
operations is not allowed, and behavior is undefined if this is attempted.
|
1997-08-12 03:40:33 +04:00
|
|
|
.El
|
|
|
|
.Pp
|
1998-02-04 09:42:53 +03:00
|
|
|
Synchronization operations are expressed from the perspective of
|
2002-10-14 17:43:14 +04:00
|
|
|
the host RAM, e.g., a
|
2002-02-13 11:17:26 +03:00
|
|
|
.Em "device -\*[Gt] memory"
|
1998-02-04 09:42:53 +03:00
|
|
|
operation is a
|
|
|
|
.Em READ
|
|
|
|
and a
|
2002-02-13 11:17:26 +03:00
|
|
|
.Em "memory -\*[Gt] device"
|
1998-02-04 09:42:53 +03:00
|
|
|
operation is a
|
|
|
|
.Em WRITE .
|
|
|
|
.Pp
|
2000-04-19 11:57:50 +04:00
|
|
|
.Fn bus_dmamap_sync
|
1998-02-04 09:42:53 +03:00
|
|
|
may consult state kept within the DMA map to determine if the memory
|
2002-10-14 17:43:14 +04:00
|
|
|
is mapped in a DMA coherent fashion.
|
|
|
|
If so,
|
1998-02-04 09:42:53 +03:00
|
|
|
.Fn bus_dmamap_sync
|
|
|
|
may elect to skip certain expensive operations, such as flushing
|
2002-10-14 17:43:14 +04:00
|
|
|
of the data cache.
|
|
|
|
See
|
1998-02-04 09:42:53 +03:00
|
|
|
.Fn bus_dmamem_map
|
|
|
|
for more information on this subject.
|
|
|
|
.Pp
|
2003-02-11 10:02:26 +03:00
|
|
|
On platforms which implement a weak memory access ordering model,
|
1998-02-04 09:42:53 +03:00
|
|
|
.Fn bus_dmamap_sync
|
2004-04-23 06:58:27 +04:00
|
|
|
will always cause the appropriate memory barriers to be issued.
|
1998-02-04 09:42:53 +03:00
|
|
|
.Pp
|
2002-06-12 19:23:34 +04:00
|
|
|
This function exists to ensure that the host and the device have
|
|
|
|
a consistent view of a range of DMA memory, before and after
|
|
|
|
a DMA operation.
|
1997-08-12 03:40:33 +04:00
|
|
|
.Pp
|
2002-06-12 19:23:34 +04:00
|
|
|
An example of using
|
2003-02-16 19:06:19 +03:00
|
|
|
.Fn bus_dmamap_sync ,
|
2002-06-12 19:27:55 +04:00
|
|
|
involving multiple read-write use of a single mapping
|
2002-06-12 19:23:34 +04:00
|
|
|
might look like this:
|
1997-08-12 03:40:33 +04:00
|
|
|
.Bd -literal
|
|
|
|
bus_dmamap_load(...);
|
|
|
|
|
|
|
|
while (not done) {
|
|
|
|
/* invalidate soon-to-be-stale cache blocks */
|
|
|
|
bus_dmamap_sync(..., BUS_DMASYNC_PREREAD);
|
|
|
|
|
|
|
|
[ do read DMA ]
|
|
|
|
|
|
|
|
/* copy from bounce */
|
|
|
|
bus_dmamap_sync(..., BUS_DMASYNC_POSTREAD);
|
|
|
|
|
|
|
|
/* read data now in driver-provided buffer */
|
|
|
|
|
|
|
|
[ computation ]
|
|
|
|
|
|
|
|
/* data to be written now in driver-provided buffer */
|
|
|
|
|
|
|
|
/* flush write buffers and writeback, copy to bounce */
|
|
|
|
bus_dmamap_sync(..., BUS_DMASYNC_PREWRITE);
|
|
|
|
|
|
|
|
[ do write DMA ]
|
|
|
|
|
|
|
|
/* probably a no-op, but provided for consistency */
|
|
|
|
bus_dmamap_sync(..., BUS_DMASYNC_POSTWRITE);
|
|
|
|
}
|
|
|
|
|
|
|
|
bus_dmamap_unload(...);
|
|
|
|
.Ed
|
|
|
|
.Pp
|
2002-06-12 19:23:34 +04:00
|
|
|
This function
|
|
|
|
.Em must
|
|
|
|
be called to synchronize DMA buffers before and after a DMA operation.
|
|
|
|
Other
|
|
|
|
.Nm
|
|
|
|
functions can
|
|
|
|
.Em not
|
|
|
|
be relied on to do this synchronization implicitly.
|
1997-08-12 11:09:31 +04:00
|
|
|
If DMA read and write operations are not preceded and followed by the
|
1997-08-12 17:21:52 +04:00
|
|
|
appropriate synchronization operations, behavior is undefined.
|
1997-08-12 03:40:33 +04:00
|
|
|
.Pp
|
|
|
|
Behavior is not defined if invalid arguments are passed to
|
|
|
|
.Fn bus_dmamap_sync .
|
|
|
|
.Pp
|
|
|
|
If given valid arguments,
|
|
|
|
.Fn bus_dmamap_sync
|
|
|
|
always succeeds.
|
1997-08-13 19:24:58 +04:00
|
|
|
.\" XXX: This does not work with all the arguments.
|
|
|
|
.It Fn bus_dmamem_alloc "tag" "size" "alignment" "boundary" "segs" "..."
|
1997-08-12 03:40:33 +04:00
|
|
|
Allocates memory that is "DMA safe" for the bus corresponding to the
|
2000-05-02 03:12:20 +04:00
|
|
|
given tag.
|
|
|
|
.Pp
|
|
|
|
The mapping of this memory is machine-dependent (or
|
1997-08-12 11:09:31 +04:00
|
|
|
"opaque"); machine-independent code is not to assume that the
|
1997-08-12 03:40:33 +04:00
|
|
|
addresses returned are valid in kernel virtual address space, or that
|
2002-10-14 17:43:14 +04:00
|
|
|
the addresses returned are system physical addresses.
|
|
|
|
The address value returned as part of
|
2000-05-02 03:12:20 +04:00
|
|
|
.Fa segs
|
2002-10-14 17:43:14 +04:00
|
|
|
can thus not be used to program DMA controller address registers.
|
|
|
|
Only the values in the
|
2000-05-02 03:12:20 +04:00
|
|
|
.Fa dm_segs
|
2001-06-21 15:59:00 +04:00
|
|
|
array of a successfully loaded DMA map (using
|
2002-10-14 17:43:14 +04:00
|
|
|
.Fn bus_dmamap_load )
|
|
|
|
can be used for this purpose.
|
1997-08-12 03:40:33 +04:00
|
|
|
.Pp
|
2002-10-14 17:43:14 +04:00
|
|
|
Allocations will always be rounded to the hardware page size.
|
|
|
|
Callers may wish to take advantage of this, and cluster allocation of small
|
1999-03-07 01:09:29 +03:00
|
|
|
data structures.
|
|
|
|
Arguments are as follows:
|
1997-08-12 03:40:33 +04:00
|
|
|
.Bl -tag -width alignment -compact
|
|
|
|
.It Fa tag
|
2003-02-16 19:06:19 +03:00
|
|
|
This is the bus_dma_tag_t passed down from the parent driver via
|
2002-02-13 11:17:26 +03:00
|
|
|
.Fa \*[Lt]bus\*[Gt]_attach_args .
|
1997-08-12 03:40:33 +04:00
|
|
|
.It Fa size
|
|
|
|
The amount of memory to allocate.
|
|
|
|
.It Fa alignment
|
2002-10-14 17:43:14 +04:00
|
|
|
Each segment in the allocated memory will be aligned to this value.
|
|
|
|
If the alignment is less than a hardware page size, it will be rounded up
|
|
|
|
to the hardware page size.
|
|
|
|
This value must be a power of two.
|
1997-08-12 03:40:33 +04:00
|
|
|
.It Fa boundary
|
|
|
|
Each segment in the allocated memory must not cross this boundary
|
2002-10-14 17:43:14 +04:00
|
|
|
(relative to zero).
|
|
|
|
This value must be a power of two.
|
|
|
|
A boundary value less than the size of the allocation is invalid.
|
1997-08-12 03:40:33 +04:00
|
|
|
.It Fa segs
|
|
|
|
An array of bus_dma_segment_t's, filled in as memory is allocated,
|
|
|
|
representing the opaque addresses of the memory chunks.
|
|
|
|
.It Fa nsegs
|
1997-08-12 11:09:31 +04:00
|
|
|
Specifies the number of segments in
|
|
|
|
.Fa segs ,
|
|
|
|
and this is the maximum number
|
|
|
|
of segments that the allocated memory may contain.
|
1997-08-12 03:40:33 +04:00
|
|
|
.It Fa rsegs
|
1997-08-12 11:09:31 +04:00
|
|
|
Used to return the actual number of segments the memory contains.
|
1997-08-12 03:40:33 +04:00
|
|
|
.It Fa flags
|
|
|
|
Flags are defined as follows:
|
2001-03-08 01:23:45 +03:00
|
|
|
.Bl -tag -width BUS_DMA_STREAMING -compact
|
1997-08-12 03:40:33 +04:00
|
|
|
.It Dv BUS_DMA_WAITOK
|
|
|
|
It is safe to wait (sleep) for resources during this call.
|
|
|
|
.It Dv BUS_DMA_NOWAIT
|
|
|
|
It is not safe to wait (sleep) for resources during this call.
|
2001-03-08 01:23:45 +03:00
|
|
|
.It Dv BUS_DMA_STREAMING
|
2001-06-21 15:59:00 +04:00
|
|
|
Adjusts, if necessary, the size, alignment, and boundary constrains
|
2001-03-08 01:23:45 +03:00
|
|
|
to conform to the platform-dependent requirements for the use of the
|
|
|
|
.Dv BUS_DMA_STREAMING
|
|
|
|
flag with the
|
|
|
|
.Fn bus_dmamap_load
|
2002-10-14 17:43:14 +04:00
|
|
|
function.
|
|
|
|
If the platform does not support the
|
2001-03-08 01:23:45 +03:00
|
|
|
.Dv BUS_DMA_STREAMING
|
|
|
|
feature, or if the size, alignment, and boundary constraints
|
|
|
|
would already satisfy the platform's requirements, this flag
|
2002-10-14 17:43:14 +04:00
|
|
|
is silently ignored.
|
|
|
|
The
|
2001-03-08 01:23:45 +03:00
|
|
|
.Dv BUS_DMA_STREAMING
|
|
|
|
flag will never relax the constraints specified in the call.
|
1997-08-12 03:40:33 +04:00
|
|
|
.It Dv BUS_DMA_BUS[1-4]
|
|
|
|
These flags are placeholders, and may be used by busses to provide
|
|
|
|
bus-dependent functionality.
|
|
|
|
.El
|
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
All pages allocated by
|
|
|
|
.Fn bus_dmamem_alloc
|
|
|
|
will be wired down
|
|
|
|
until they are freed by
|
|
|
|
.Fn bus_dmamem_free .
|
|
|
|
.Pp
|
|
|
|
Behavior is undefined if invalid arguments are passed to
|
|
|
|
.Fn bus_dmamem_alloc .
|
|
|
|
.Pp
|
1997-08-12 11:09:31 +04:00
|
|
|
Returns 0 on success, or an error code indicating mode of failure.
|
1997-08-13 19:24:58 +04:00
|
|
|
.It Fn bus_dmamem_free "tag" "segs" "nsegs"
|
2001-06-21 15:59:00 +04:00
|
|
|
Frees memory previously allocated by
|
1997-08-12 03:40:33 +04:00
|
|
|
.Fn bus_dmamem_alloc .
|
|
|
|
Any mappings
|
2002-10-14 17:43:14 +04:00
|
|
|
will be invalidated.
|
|
|
|
Arguments are as follows:
|
1997-08-12 03:40:33 +04:00
|
|
|
.Bl -tag -width nsegs -compact
|
|
|
|
.It Fa tag
|
|
|
|
This is the bus_dma_tag_t passed down from the parent driver via
|
2002-02-13 11:17:26 +03:00
|
|
|
.Fa \*[Lt]bus\*[Gt]_attach_args .
|
1997-08-12 03:40:33 +04:00
|
|
|
.It Fa segs
|
|
|
|
The array of bus_dma_segment_t's filled in by
|
|
|
|
.Fn bus_dmamem_alloc .
|
|
|
|
.It Fa nsegs
|
1997-08-12 11:09:31 +04:00
|
|
|
The number of segments in
|
|
|
|
.Fa segs .
|
1997-08-12 03:40:33 +04:00
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
Behavior is undefined if invalid arguments are passed to
|
|
|
|
.Fn bus_dmamem_free .
|
|
|
|
.Pp
|
2001-06-21 15:59:00 +04:00
|
|
|
If given valid arguments,
|
1997-08-12 03:40:33 +04:00
|
|
|
.Fn bus_dmamem_free
|
|
|
|
always succeeds.
|
1997-08-13 19:24:58 +04:00
|
|
|
.It Fn bus_dmamem_map "tag" "segs" "nsegs" "size" "kvap" "flags"
|
1997-08-12 03:40:33 +04:00
|
|
|
Maps memory allocated with
|
|
|
|
.Fn bus_dmamem_alloc
|
2002-10-14 17:43:14 +04:00
|
|
|
into kernel virtual address space.
|
|
|
|
Arguments are as follows:
|
1997-08-12 03:40:33 +04:00
|
|
|
.Bl -tag -width flags -compact
|
|
|
|
.It Fa tag
|
|
|
|
This is the bus_dma_tag_t passed down from the parent driver via
|
2002-02-13 11:17:26 +03:00
|
|
|
.Fa \*[Lt]bus\*[Gt]_attach_args .
|
1997-08-12 03:40:33 +04:00
|
|
|
.It Fa segs
|
|
|
|
The array of bus_dma_segment_t's filled in by
|
|
|
|
.Fn bus_dmamem_alloc ,
|
|
|
|
representing the memory regions to map.
|
|
|
|
.It Fa nsegs
|
1997-08-12 11:09:31 +04:00
|
|
|
The number of segments in
|
|
|
|
.Fa segs .
|
1997-08-12 03:40:33 +04:00
|
|
|
.It Fa size
|
|
|
|
The size of the mapping.
|
|
|
|
.It Fa kvap
|
1997-08-12 17:21:52 +04:00
|
|
|
Filled in to specify the kernel virtual address where the memory is mapped.
|
1997-08-12 03:40:33 +04:00
|
|
|
.It Fa flags
|
|
|
|
Flags are defined as follows:
|
1998-02-04 09:42:53 +03:00
|
|
|
.Bl -tag -width BUS_DMA_COHERENT -compact
|
1997-08-12 03:40:33 +04:00
|
|
|
.It Dv BUS_DMA_WAITOK
|
|
|
|
It is safe to wait (sleep) for resources during this call.
|
|
|
|
.It Dv BUS_DMA_NOWAIT
|
|
|
|
It is not safe to wait (sleep) for resources during this call.
|
|
|
|
.It Dv BUS_DMA_BUS[1-4]
|
|
|
|
These flags are placeholders, and may be used by busses to provide
|
|
|
|
bus-dependent functionality.
|
1998-02-04 09:42:53 +03:00
|
|
|
.It Dv BUS_DMA_COHERENT
|
|
|
|
This flag is a
|
|
|
|
.Em hint
|
2002-10-14 17:43:14 +04:00
|
|
|
to machine-dependent code.
|
|
|
|
If possible, map the memory in such a way as it will be DMA coherent.
|
|
|
|
This may include mapping the pages into uncached address space or
|
|
|
|
setting the cache-inhibit bits in page table entries.
|
|
|
|
If DMA coherent mappings are impossible, this flag is silently ignored.
|
1998-02-04 09:42:53 +03:00
|
|
|
.Pp
|
|
|
|
Later, when this memory is loaded into a DMA map, machine-dependent code
|
|
|
|
will take whatever steps are necessary to determine if the memory was
|
2002-10-14 17:43:14 +04:00
|
|
|
mapped in a DMA coherent fashion.
|
|
|
|
This may include checking if the kernel virtual address lies within
|
|
|
|
uncached address space or if the cache-inhibit bits are set in page
|
|
|
|
table entries.
|
|
|
|
If it is determined that the mapping is DMA coherent, state may be
|
|
|
|
placed into the DMA map for use by later calls to
|
1998-02-04 09:42:53 +03:00
|
|
|
.Fn bus_dmamap_sync .
|
2001-03-08 01:23:45 +03:00
|
|
|
.Pp
|
|
|
|
Note that a device driver must not rely on
|
|
|
|
.Dv BUS_DMA_COHERENT
|
2002-10-14 17:43:14 +04:00
|
|
|
for correct operation.
|
|
|
|
All calls to
|
2001-03-08 01:23:45 +03:00
|
|
|
.Fn bus_dmamap_sync
|
2002-10-14 17:43:14 +04:00
|
|
|
must still be made.
|
|
|
|
This flag is provided only as an optimization hint to machine-dependent code.
|
2001-03-08 01:23:45 +03:00
|
|
|
.Pp
|
|
|
|
Also note that this flag only applies to coherency between the CPU
|
2002-10-14 17:43:14 +04:00
|
|
|
and memory.
|
|
|
|
Coherency between memory and the device is controlled with a different flag.
|
|
|
|
See the description of the
|
2001-03-08 01:23:45 +03:00
|
|
|
.Fn bus_dmamap_load
|
|
|
|
function.
|
2003-01-28 04:07:51 +03:00
|
|
|
.It Dv BUS_DMA_NOCACHE
|
|
|
|
This flag is a
|
|
|
|
.Em hint
|
|
|
|
to machine-dependent code.
|
2003-02-16 19:06:19 +03:00
|
|
|
If possible, map the uncached memory.
|
2003-01-28 04:07:51 +03:00
|
|
|
This flag may be useful in the case that the memory cache causes unexpected
|
|
|
|
behavior of the device.
|
1997-08-12 03:40:33 +04:00
|
|
|
.El
|
|
|
|
.El
|
|
|
|
.Pp
|
1997-08-12 11:31:42 +04:00
|
|
|
Behavior is undefined if invalid arguments are passed to
|
1997-08-12 03:40:33 +04:00
|
|
|
.Fn bus_dmamem_map .
|
|
|
|
.Pp
|
1997-08-12 11:09:31 +04:00
|
|
|
Returns 0 on success, or an error code indicating mode of failure.
|
1997-08-13 19:24:58 +04:00
|
|
|
.It Fn bus_dmamem_unmap "tag" "kva" "size"
|
1997-08-12 03:40:33 +04:00
|
|
|
Unmaps memory previously mapped with
|
|
|
|
.Fn bus_dmamem_map ,
|
|
|
|
freeing the
|
2002-10-14 17:43:14 +04:00
|
|
|
kernel virtual address space used by the mapping.
|
|
|
|
The arguments are as follows:
|
1997-08-12 03:40:33 +04:00
|
|
|
.Bl -tag -width size -compact
|
|
|
|
.It Fa tag
|
|
|
|
This is the bus_dma_tag_t passed down from the parent driver via
|
2002-02-13 11:17:26 +03:00
|
|
|
.Fa \*[Lt]bus\*[Gt]_attach_args .
|
1997-08-12 03:40:33 +04:00
|
|
|
.It Fa kva
|
|
|
|
The kernel virtual address of the mapped memory.
|
|
|
|
.It Fa size
|
|
|
|
The size of the mapping.
|
|
|
|
.El
|
|
|
|
.Pp
|
1997-08-12 11:31:42 +04:00
|
|
|
Behavior is undefined if invalid arguments are passed to
|
1997-08-12 03:40:33 +04:00
|
|
|
.Fn bus_dmamem_unmap .
|
|
|
|
.Pp
|
2001-06-21 15:59:00 +04:00
|
|
|
If given valid arguments,
|
1997-08-12 03:40:33 +04:00
|
|
|
.Fn bus_dmamem_unmap
|
|
|
|
always succeeds.
|
1997-08-13 19:24:58 +04:00
|
|
|
.It Fn bus_dmamem_mmap "tag" "segs" "nsegs" "off" "prot" "flags"
|
1997-08-12 03:40:33 +04:00
|
|
|
Provides support for user
|
2006-02-04 23:19:21 +03:00
|
|
|
.Xr mmap 2 Ap ing
|
2002-10-14 17:43:14 +04:00
|
|
|
of DMA-safe memory.
|
|
|
|
This function is to be called by a device driver's (*d_mmap)() entry
|
|
|
|
point, which is called by the device pager for each page to be mapped.
|
|
|
|
The arguments are as follows:
|
1997-08-12 03:40:33 +04:00
|
|
|
.Bl -tag -width nsegs -compact
|
|
|
|
.It Fa tag
|
1997-08-12 11:09:31 +04:00
|
|
|
This is the bus_dma_tag_t passed down from the parent driver via
|
2002-02-13 11:17:26 +03:00
|
|
|
.Fa \*[Lt]bus\*[Gt]_attach_args .
|
1997-08-12 03:40:33 +04:00
|
|
|
.It Fa segs
|
1997-08-12 11:09:31 +04:00
|
|
|
The array of bus_dma_segment_t's filled in by
|
1997-08-12 03:40:33 +04:00
|
|
|
.Fn bus_dmamem_alloc ,
|
1997-08-12 11:09:31 +04:00
|
|
|
representing the memory to be
|
2006-02-04 23:19:21 +03:00
|
|
|
.Xr mmap 2 Ap ed .
|
1997-08-12 03:40:33 +04:00
|
|
|
.It Fa nsegs
|
1997-08-12 11:09:31 +04:00
|
|
|
The number of elements in the
|
|
|
|
.Fa segs
|
|
|
|
array.
|
1997-08-12 03:40:33 +04:00
|
|
|
.It Fa off
|
|
|
|
The offset of the page in DMA memory which is to be mapped.
|
|
|
|
.It Fa prot
|
|
|
|
The protection codes for the mapping.
|
|
|
|
.It Fa flags
|
|
|
|
Flags are defined as follows:
|
1998-02-04 09:42:53 +03:00
|
|
|
.Bl -tag -width BUS_DMA_COHERENT -compact
|
1997-08-12 03:40:33 +04:00
|
|
|
.It Dv BUS_DMA_WAITOK
|
|
|
|
It is safe to wait (sleep) for resources during this call.
|
|
|
|
.It Dv BUS_DMA_NOWAIT
|
|
|
|
It is not safe to wait (sleep) for resources during this call.
|
|
|
|
.It Dv BUS_DMA_BUS[1-4]
|
|
|
|
These flags are placeholders, and may be used by busses to provide
|
|
|
|
bus-dependent functionality.
|
1998-02-04 09:42:53 +03:00
|
|
|
.It Dv BUS_DMA_COHERENT
|
|
|
|
See
|
|
|
|
.Fn bus_dmamem_map
|
|
|
|
above for a description of this flag.
|
2003-01-28 04:07:51 +03:00
|
|
|
.It Dv BUS_DMA_NOCACHE
|
|
|
|
See
|
|
|
|
.Fn bus_dmamem_map
|
|
|
|
above for a description of this flag.
|
1997-08-12 03:40:33 +04:00
|
|
|
.El
|
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
Behavior is undefined if invalid arguments are passed
|
|
|
|
to
|
|
|
|
.Fn bus_dmamem_mmap .
|
|
|
|
.Pp
|
2002-10-14 17:43:14 +04:00
|
|
|
Returns -1 to indicate failure.
|
|
|
|
Otherwise, returns an opaque value to be interpreted by the device pager.
|
1999-02-26 02:29:33 +03:00
|
|
|
.El
|
1997-08-13 21:39:19 +04:00
|
|
|
.Sh SEE ALSO
|
|
|
|
.Xr bus_space 9
|
2004-11-05 15:38:09 +03:00
|
|
|
.Rs
|
|
|
|
.%A Jason Thorpe
|
|
|
|
.%T "A Machine-Independent DMA Framework for NetBSD"
|
|
|
|
.%J "Proceedings of the FREENIX track: 1998 USENIX Annual Technical Conference"
|
|
|
|
.%P pp. 1-12
|
|
|
|
.%D 1998
|
|
|
|
.Re
|
2001-12-26 04:02:01 +03:00
|
|
|
.Sh HISTORY
|
|
|
|
The
|
|
|
|
.Nm
|
|
|
|
interface appeared in
|
|
|
|
.Nx 1.3 .
|
2001-09-11 03:32:29 +04:00
|
|
|
.Sh AUTHORS
|
1998-02-04 09:42:53 +03:00
|
|
|
The
|
|
|
|
.Nm
|
|
|
|
interface was designed and implemented by Jason R. Thorpe of the
|
|
|
|
Numerical Aerospace Simulation Facility, NASA Ames Research Center.
|
|
|
|
Additional input on the
|
|
|
|
.Nm
|
|
|
|
design was provided by Chris Demetriou, Charles Hannum, Ross Harvey,
|
|
|
|
Matthew Jacob, Jonathan Stone, and Matt Thomas.
|