xref: /freebsd/share/man/man9/bus_dma.9 (revision 81ae4b8da9920ccfb697984dbb2e8751573d183a)
124503465SHiten Pandya.\" Copyright (c) 2002, 2003 Hiten M. Pandya.
224503465SHiten Pandya.\" All rights reserved.
324503465SHiten Pandya.\"
424503465SHiten Pandya.\" Redistribution and use in source and binary forms, with or without
524503465SHiten Pandya.\" modification, are permitted provided that the following conditions
624503465SHiten Pandya.\" are met:
724503465SHiten Pandya.\" 1. Redistributions of source code must retain the above copyright
824503465SHiten Pandya.\"    notice, this list of conditions, and the following disclaimer,
924503465SHiten Pandya.\"    without modification, immediately at the beginning of the file.
1024503465SHiten Pandya.\" 2. The name of the author may not be used to endorse or promote products
1124503465SHiten Pandya.\"    derived from this software without specific prior written permission.
1224503465SHiten Pandya.\"
1324503465SHiten Pandya.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1424503465SHiten Pandya.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1524503465SHiten Pandya.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1624503465SHiten Pandya.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR, CONTRIBUTORS OR THE
1724503465SHiten Pandya.\" VOICES IN HITEN PANDYA'S HEAD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1824503465SHiten Pandya.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
1924503465SHiten Pandya.\" TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
2024503465SHiten Pandya.\" PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
2124503465SHiten Pandya.\" LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
2224503465SHiten Pandya.\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
2324503465SHiten Pandya.\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2424503465SHiten Pandya.\"
2524503465SHiten Pandya.\" Copyright (c) 1996, 1997, 1998, 2001 The NetBSD Foundation, Inc.
2624503465SHiten Pandya.\" All rights reserved.
2724503465SHiten Pandya.\"
2824503465SHiten Pandya.\" This code is derived from software contributed to The NetBSD Foundation
2924503465SHiten Pandya.\" by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
3024503465SHiten Pandya.\" NASA Ames Research Center.
3124503465SHiten Pandya.\"
3224503465SHiten Pandya.\" Redistribution and use in source and binary forms, with or without
3324503465SHiten Pandya.\" modification, are permitted provided that the following conditions
3424503465SHiten Pandya.\" are met:
3524503465SHiten Pandya.\" 1. Redistributions of source code must retain the above copyright
3624503465SHiten Pandya.\"    notice, this list of conditions and the following disclaimer.
3724503465SHiten Pandya.\" 2. Redistributions in binary form must reproduce the above copyright
3824503465SHiten Pandya.\"    notice, this list of conditions and the following disclaimer in the
3924503465SHiten Pandya.\"    documentation and/or other materials provided with the distribution.
4024503465SHiten Pandya.\" 3. All advertising materials mentioning features or use of this software
4124503465SHiten Pandya.\"    must display the following acknowledgment:
4224503465SHiten Pandya.\" 	This product includes software developed by the NetBSD
4324503465SHiten Pandya.\" 	Foundation, Inc. and its contributors.
4424503465SHiten Pandya.\" 4. Neither the name of The NetBSD Foundation nor the names of its
4524503465SHiten Pandya.\"    contributors may be used to endorse or promote products derived
4624503465SHiten Pandya.\"    from this software without specific prior written permission.
4724503465SHiten Pandya.\"
4824503465SHiten Pandya.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
4924503465SHiten Pandya.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
5024503465SHiten Pandya.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
5124503465SHiten Pandya.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
5224503465SHiten Pandya.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
5324503465SHiten Pandya.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
5424503465SHiten Pandya.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
5524503465SHiten Pandya.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
5624503465SHiten Pandya.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
5724503465SHiten Pandya.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
5824503465SHiten Pandya.\" POSSIBILITY OF SUCH DAMAGE.
5924503465SHiten Pandya.\"
6024503465SHiten Pandya.\" $FreeBSD$
6124503465SHiten Pandya.\" $NetBSD: bus_dma.9,v 1.25 2002/10/14 13:43:16 wiz Exp $
6224503465SHiten Pandya.\"
6307bf564cSRuslan Ermilov.Dd August 31, 2006
6424503465SHiten Pandya.Dt BUS_DMA 9
6524503465SHiten Pandya.Os
6624503465SHiten Pandya.Sh NAME
6724503465SHiten Pandya.Nm bus_dma ,
6824503465SHiten Pandya.Nm bus_dma_tag_create ,
6924503465SHiten Pandya.Nm bus_dma_tag_destroy ,
7024503465SHiten Pandya.Nm bus_dmamap_create ,
7124503465SHiten Pandya.Nm bus_dmamap_destroy ,
7224503465SHiten Pandya.Nm bus_dmamap_load ,
7324503465SHiten Pandya.Nm bus_dmamap_load_mbuf ,
74824f4edfSScott Long.Nm bus_dmamap_load_mbuf_sg ,
7524503465SHiten Pandya.Nm bus_dmamap_load_uio ,
7624503465SHiten Pandya.Nm bus_dmamap_unload ,
7724503465SHiten Pandya.Nm bus_dmamap_sync ,
7824503465SHiten Pandya.Nm bus_dmamem_alloc ,
79a1bd700aSHiten Pandya.Nm bus_dmamem_free
8024503465SHiten Pandya.Nd Bus and Machine Independent DMA Mapping Interface
8124503465SHiten Pandya.Sh SYNOPSIS
8224503465SHiten Pandya.In machine/bus.h
8324503465SHiten Pandya.Ft int
8424503465SHiten Pandya.Fn bus_dma_tag_create "bus_dma_tag_t parent" "bus_size_t alignment" \
8524503465SHiten Pandya"bus_size_t boundary" "bus_addr_t lowaddr" "bus_addr_t highaddr" \
8624503465SHiten Pandya"bus_dma_filter_t *filtfunc" "void *filtfuncarg" "bus_size_t maxsize" \
870e5f9b7dSScott Long"int nsegments" "bus_size_t maxsegsz" "int flags" "bus_dma_lock_t *lockfunc" \
880e5f9b7dSScott Long"void *lockfuncarg" "bus_dma_tag_t *dmat"
8924503465SHiten Pandya.Ft int
9024503465SHiten Pandya.Fn bus_dma_tag_destroy "bus_dma_tag_t dmat"
9124503465SHiten Pandya.Ft int
9224503465SHiten Pandya.Fn bus_dmamap_create "bus_dma_tag_t dmat" "int flags" "bus_dmamap_t *mapp"
9324503465SHiten Pandya.Ft int
9424503465SHiten Pandya.Fn bus_dmamap_destroy "bus_dma_tag_t dmat" "bus_dmamap_t map"
9524503465SHiten Pandya.Ft int
9624503465SHiten Pandya.Fn bus_dmamap_load "bus_dma_tag_t dmat" "bus_dmamap_t map" "void *buf" \
9724503465SHiten Pandya"bus_size_t buflen" "bus_dmamap_callback_t *callback" "void *callback_arg" \
9824503465SHiten Pandya"int flags"
9924503465SHiten Pandya.Ft int
10024503465SHiten Pandya.Fn bus_dmamap_load_mbuf "bus_dma_tag_t dmat" "bus_dmamap_t map" \
10124503465SHiten Pandya"struct mbuf *mbuf" "bus_dmamap_callback2_t *callback" "void *callback_arg" \
10224503465SHiten Pandya"int flags"
10324503465SHiten Pandya.Ft int
104824f4edfSScott Long.Fn bus_dmamap_load_mbuf_sg "bus_dma_tag_t dmat" "bus_dmamap_t map" \
105824f4edfSScott Long"struct mbuf *mbuf" "bus_dma_segment_t *segs" "int *nsegs" "int flags"
106824f4edfSScott Long.Ft int
10724503465SHiten Pandya.Fn bus_dmamap_load_uio "bus_dma_tag_t dmat" "bus_dmamap_t map" \
10824503465SHiten Pandya"struct uio *uio" "bus_dmamap_callback2_t *callback" "void *callback_arg" \
10924503465SHiten Pandya"int flags"
11024503465SHiten Pandya.Ft void
11124503465SHiten Pandya.Fn bus_dmamap_unload "bus_dma_tag_t dmat" "bus_dmamap_t map"
11224503465SHiten Pandya.Ft void
11324503465SHiten Pandya.Fn bus_dmamap_sync "bus_dma_tag_t dmat" "bus_dmamap_t map" \
11424503465SHiten Pandya"op"
115cbfef69cSWarner Losh.Ft int
116cbfef69cSWarner Losh.Fn bus_dmamem_alloc "bus_dma_tag_t dmat" "void **vaddr" \
117cbfef69cSWarner Losh"int flags" "bus_dmamap_t *mapp"
11824503465SHiten Pandya.Ft void
11924503465SHiten Pandya.Fn bus_dmamem_free "bus_dma_tag_t dmat" "void *vaddr" \
12024503465SHiten Pandya"bus_dmamap_t map"
12124503465SHiten Pandya.Sh DESCRIPTION
12224503465SHiten PandyaDirect Memory Access (DMA) is a method of transferring data
12324503465SHiten Pandyawithout involving the CPU, thus providing higher performance.
12424503465SHiten PandyaA DMA transaction can be achieved between device to memory,
12524503465SHiten Pandyadevice to device, or memory to memory.
12624503465SHiten Pandya.Pp
12724503465SHiten PandyaThe
12824503465SHiten Pandya.Nm
12924503465SHiten PandyaAPI is a bus, device, and machine-independent (MI) interface to
13024503465SHiten PandyaDMA mechanisms.
13124503465SHiten PandyaIt provides the client with flexibility and simplicity by
13224503465SHiten Pandyaabstracting machine dependent issues like setting up
13324503465SHiten PandyaDMA mappings, handling cache issues, bus specific features
13424503465SHiten Pandyaand limitations.
13524503465SHiten Pandya.Sh STRUCTURES AND TYPES
13681ae4b8dSRuslan Ermilov.Bl -tag -width indent
13724503465SHiten Pandya.It Vt bus_dma_tag_t
13824503465SHiten PandyaA machine-dependent (MD) opaque type that describes the
13924503465SHiten Pandyacharacteristics of DMA transactions.
14024503465SHiten PandyaDMA tags are organized into a hierarchy, with each child
14124503465SHiten Pandyatag inheriting the restrictions of its parent.
14224503465SHiten PandyaThis allows all devices along the path of DMA transactions
14324503465SHiten Pandyato contribute to the constraints of those transactions.
14424503465SHiten Pandya.It Vt bus_dma_filter_t
14524503465SHiten PandyaClient specified address filter having the format:
14681ae4b8dSRuslan Ermilov.Bl -tag -width indent
14724503465SHiten Pandya.It Ft int
14824503465SHiten Pandya.Fn "client_filter" "void *filtarg" "bus_addr_t testaddr"
14924503465SHiten Pandya.El
15081ae4b8dSRuslan Ermilov.Pp
15124503465SHiten PandyaAddress filters can be specified during tag creation to allow
15259892d33SRuslan Ermilovfor devices whose DMA address restrictions cannot be specified
15324503465SHiten Pandyaby a single window.
15424503465SHiten PandyaThe
15524503465SHiten Pandya.Fa filtarg
15624503465SHiten Pandyais client specified during tag creation to be passed to all
15724503465SHiten Pandyainvocations of the callback.
15824503465SHiten PandyaThe
15924503465SHiten Pandya.Fa testaddr
16024503465SHiten Pandyaargument contains a potential starting address of a DMA mapping.
16124503465SHiten PandyaThe filter function operates on the set of addresses from
16224503465SHiten Pandya.Fa testaddr
16324503465SHiten Pandyato
16424503465SHiten Pandya.Ql trunc_page(testaddr) + PAGE_SIZE - 1 ,
16524503465SHiten Pandyainclusive.
16624503465SHiten PandyaThe filter function should return zero for any mapping in this range
16724503465SHiten Pandyathat can be accommodated by the device and non-zero otherwise.
16824503465SHiten Pandya.It Vt bus_dma_segment_t
16924503465SHiten PandyaA machine-dependent type that describes individual
17024503465SHiten PandyaDMA segments.
17124503465SHiten Pandya.Bd -literal
17224503465SHiten Pandya	bus_addr_t	ds_addr;
17324503465SHiten Pandya	bus_size_t	ds_len;
17424503465SHiten Pandya.Ed
17581ae4b8dSRuslan Ermilov.Pp
17624503465SHiten PandyaThe
17724503465SHiten Pandya.Fa ds_addr
17824503465SHiten Pandyafield contains the device visible address of the DMA segment, and
17924503465SHiten Pandya.Fa ds_len
18024503465SHiten Pandyacontains the length of the DMA segment.
18124503465SHiten PandyaAlthough the DMA segments returned by a mapping call will adhere to
18224503465SHiten Pandyaall restrictions necessary for a successful DMA operation, some conversion
1835203edcdSRuslan Ermilov(e.g.\& a conversion from host byte order to the device's byte order) is
18424503465SHiten Pandyaalmost always required when presenting segment information to the device.
18524503465SHiten Pandya.It Vt bus_dmamap_t
18624503465SHiten PandyaA machine-dependent opaque type describing an individual mapping.
18771bb1f9bSScott LongOne map is used for each memory allocation that will be loaded.
18871bb1f9bSScott LongMaps can be reused once they have been unloaded.
18971bb1f9bSScott LongMultiple maps can be associated with one DMA tag.
19081ae4b8dSRuslan ErmilovWhile the value of the map may evaluate to
19181ae4b8dSRuslan Ermilov.Dv NULL
19281ae4b8dSRuslan Ermilovon some platforms under certain conditions,
19381ae4b8dSRuslan Ermilovit should never be assumed that it will be
19481ae4b8dSRuslan Ermilov.Dv NULL
19581ae4b8dSRuslan Ermilovin all cases.
19624503465SHiten Pandya.It Vt bus_dmamap_callback_t
19724503465SHiten PandyaClient specified callback for receiving mapping information resulting from
19824503465SHiten Pandyathe load of a
19924503465SHiten Pandya.Vt bus_dmamap_t
20024503465SHiten Pandyavia
20124503465SHiten Pandya.Fn bus_dmamap_load .
20224503465SHiten PandyaCallbacks are of the format:
20381ae4b8dSRuslan Ermilov.Bl -tag -width indent
20424503465SHiten Pandya.It Ft void
20524503465SHiten Pandya.Fn "client_callback" "void *callback_arg" "bus_dma_segment_t *segs" \
20624503465SHiten Pandya"int nseg" "int error"
20724503465SHiten Pandya.El
20881ae4b8dSRuslan Ermilov.Pp
20924503465SHiten PandyaThe
21024503465SHiten Pandya.Fa callback_arg
21124503465SHiten Pandyais the callback argument passed to dmamap load functions.
21224503465SHiten PandyaThe
21324503465SHiten Pandya.Fa segs
21424503465SHiten Pandyaand
21524503465SHiten Pandya.Fa nseg
21624503465SHiten Pandyaparameters describe an array of
21724503465SHiten Pandya.Vt bus_dma_segment_t
21824503465SHiten Pandyastructures that represent the mapping.
21924503465SHiten PandyaThis array is only valid within the scope of the callback function.
22024503465SHiten PandyaThe success or failure of the mapping is indicated by the
22124503465SHiten Pandya.Fa error
22224503465SHiten Pandyaparameter.
22324503465SHiten PandyaMore information on the use of callbacks can be found in the
22424503465SHiten Pandyadescription of the individual dmamap load functions.
22524503465SHiten Pandya.It Vt bus_dmamap_callback2_t
22624503465SHiten PandyaClient specified callback for receiving mapping information resulting from
22724503465SHiten Pandyathe load of a
22824503465SHiten Pandya.Vt bus_dmamap_t
22924503465SHiten Pandyavia
23024503465SHiten Pandya.Fn bus_dmamap_load_uio
23124503465SHiten Pandyaor
23224503465SHiten Pandya.Fn bus_dmamap_load_mbuf .
23381ae4b8dSRuslan Ermilov.Pp
23424503465SHiten PandyaCallback2s are of the format:
23581ae4b8dSRuslan Ermilov.Bl -tag -width indent
23624503465SHiten Pandya.It Ft void
23724503465SHiten Pandya.Fn "client_callback2" "void *callback_arg" "bus_dma_segment_t *segs" \
23824503465SHiten Pandya"int nseg" "bus_size_t mapsize" "int error"
23924503465SHiten Pandya.El
24081ae4b8dSRuslan Ermilov.Pp
24124503465SHiten PandyaCallback2's behavior is the same as
24224503465SHiten Pandya.Vt bus_dmamap_callback_t
24324503465SHiten Pandyawith the addition that the length of the data mapped is provided via
24424503465SHiten Pandya.Fa mapsize .
24524503465SHiten Pandya.It Vt bus_dmasync_op_t
24624503465SHiten PandyaMemory synchronization operation specifier.
24736a142c4SRuslan ErmilovBus DMA requires explicit synchronization of memory with its device
24824503465SHiten Pandyavisible mapping in order to guarantee memory coherency.
24924503465SHiten PandyaThe
25024503465SHiten Pandya.Vt bus_dmasync_op_t
25124503465SHiten Pandyaallows the type of DMA operation that will be or has been performed
25224503465SHiten Pandyato be communicated to the system so that the correct coherency measures
25324503465SHiten Pandyaare taken.
2541cb112abSScott LongThe operations are represented as bitfield flags that can be combined together,
2551cb112abSScott Longthough it only makes sense to combine PRE flags or POST flags, not both.
2561cb112abSScott LongSee the
257e8c9966dSJohn-Mark Gurney.Fn bus_dmamap_sync
2581cb112abSScott Longdescription below for more details on how to use these operations.
2596f3d2701SScott Long.Pp
2606f3d2701SScott LongAll operations specified below are performed from the host memory point of view,
2616f3d2701SScott Longwhere a read implies data coming from the device to the host memory, and a write
2626f3d2701SScott Longimplies data going from the host memory to the device.
26307bf564cSRuslan ErmilovAlternatively, the operations can be thought of in terms of driver operations,
264a79d1e83SScott Longwhere reading a network packet or storage sector corresponds to a read operation
265a79d1e83SScott Longin
266a79d1e83SScott Long.Nm .
26707bf564cSRuslan Ermilov.Bl -tag -width ".Dv BUS_DMASYNC_POSTWRITE"
26824503465SHiten Pandya.It Dv BUS_DMASYNC_PREREAD
2696f3d2701SScott LongPerform any synchronization required prior to an update of host memory by the
27007bf564cSRuslan Ermilovdevice.
27124503465SHiten Pandya.It Dv BUS_DMASYNC_PREWRITE
2726f3d2701SScott LongPerform any synchronization required after an update of host memory by the CPU
27307bf564cSRuslan Ermilovand prior to device access to host memory.
27424503465SHiten Pandya.It Dv BUS_DMASYNC_POSTREAD
27507bf564cSRuslan ErmilovPerform any synchronization required after an update of host memory by the
27607bf564cSRuslan Ermilovdevice and prior to CPU access to host memory.
27724503465SHiten Pandya.It Dv BUS_DMASYNC_POSTWRITE
27807bf564cSRuslan ErmilovPerform any synchronization required after the device access to host memory.
27924503465SHiten Pandya.El
2800e5f9b7dSScott Long.It Vt bus_dma_lock_t
281c7d3a65dSHiten PandyaClient specified lock/mutex manipulation method.
282c7d3a65dSHiten PandyaThis will be called from
2830e5f9b7dSScott Longwithin busdma whenever a client lock needs to be manipulated.
2844d855643SWarner LoshIn its current form, the function will be called immediately before
2854d855643SWarner Loshthe callback for a dma load operation that has been deferred with
2864d855643SWarner Losh.Dv BUS_DMA_LOCK
2874d855643SWarner Loshand immediately after with
2884d855643SWarner Losh.Dv BUS_DMA_UNLOCK .
2894d855643SWarner LoshIf the load operation does not need to be deferred, then it
2904d855643SWarner Loshwill not be called since the function loading the map should
2914d855643SWarner Loshbe holding the appropriate locks.
2920e5f9b7dSScott LongThis method is of the format:
29381ae4b8dSRuslan Ermilov.Bl -tag -width indent
2940e5f9b7dSScott Long.It Ft void
2950e5f9b7dSScott Long.Fn "lockfunc" "void *lockfunc_arg" "bus_dma_lock_op_t op"
29624503465SHiten Pandya.El
29781ae4b8dSRuslan Ermilov.Pp
2980e5f9b7dSScott LongTwo
2990e5f9b7dSScott Long.Vt lockfunc
3000e5f9b7dSScott Longimplementations are provided for convenience.
3010e5f9b7dSScott Long.Fn busdma_lock_mutex
3020e5f9b7dSScott Longperforms standard mutex operations on the sleep mutex provided via the
3030e5f9b7dSScott Long.Fa lockfuncarg .
3040e5f9b7dSScott Longpassed into
3050e5f9b7dSScott Long.Fn bus_dma_tag_create .
3060e5f9b7dSScott Long.Fn dflt_lock
307c7d3a65dSHiten Pandyawill generate a system panic if it is called.
308c7d3a65dSHiten PandyaIt is substituted into the tag when
3090e5f9b7dSScott Long.Fa lockfunc
31081ae4b8dSRuslan Ermilovis passed as
31181ae4b8dSRuslan Ermilov.Dv NULL
31281ae4b8dSRuslan Ermilovto
3130e5f9b7dSScott Long.Fn bus_dma_tag_create .
3140e5f9b7dSScott Long.It Vt bus_dma_lock_op_t
3150e5f9b7dSScott LongOperations to be performed by the client-specified
3160e5f9b7dSScott Long.Fn lockfunc .
31781ae4b8dSRuslan Ermilov.Bl -tag -width ".Dv BUS_DMA_UNLOCK"
3180e5f9b7dSScott Long.It Dv BUS_DMA_LOCK
3192988974bSMike PritchardAcquires and/or locks the client locking primitive.
3200e5f9b7dSScott Long.It Dv BUS_DMA_UNLOCK
3210e5f9b7dSScott LongReleases and/or unlocks the client locking primitive.
3220e5f9b7dSScott Long.El
3230e5f9b7dSScott Long.El
32424503465SHiten Pandya.Sh FUNCTIONS
32581ae4b8dSRuslan Ermilov.Bl -tag -width indent
32624503465SHiten Pandya.It Fn bus_dma_tag_create "parent" "alignment" "boundary" "lowaddr" \
32724503465SHiten Pandya"highaddr" "*filtfunc" "*filtfuncarg" "maxsize" "nsegments" "maxsegsz" \
3289b5c4b66SScott Long"flags" "lockfunc" "lockfuncarg" "*dmat"
32924503465SHiten PandyaAllocates a device specific DMA tag, and initializes it according to
33024503465SHiten Pandyathe arguments provided:
33181ae4b8dSRuslan Ermilov.Bl -tag -width ".Fa filtfuncarg"
33224503465SHiten Pandya.It Fa parent
33324503465SHiten PandyaIndicates restrictions between the parent bridge, CPU memory, and the
33424503465SHiten Pandyadevice.
335d1c32d02SJohn-Mark GurneyEach device must use a master parent tag by calling
336d1c32d02SJohn-Mark Gurney.Fn bus_get_dma_tag .
33724503465SHiten Pandya.It Fa alignment
33824503465SHiten PandyaAlignment constraint, in bytes, of any mappings created using this tag.
33924503465SHiten PandyaThe alignment must be a power of 2.
34024503465SHiten PandyaHardware that can DMA starting at any address would specify
34124503465SHiten Pandya.Em 1
34224503465SHiten Pandyafor byte alignment.
34324503465SHiten PandyaHardware requiring DMA transfers to start on a multiple of 4K
34424503465SHiten Pandyawould specify
34524503465SHiten Pandya.Em 4096 .
34624503465SHiten Pandya.It Fa boundary
34724503465SHiten PandyaBoundary constraint, in bytes, of the target DMA memory region.
34824503465SHiten PandyaThe boundary indicates the set of addresses, all multiples of the
34924503465SHiten Pandyaboundary argument, that cannot be crossed by a single
35024503465SHiten Pandya.Vt bus_dma_segment_t .
3512d4071acSChristian BruefferThe boundary must be a power of 2 and must be no smaller than the
352ab0b83b5SScott Longmaximum segment size.
35324503465SHiten Pandya.Ql 0
35424503465SHiten Pandyaindicates that there are no boundary restrictions.
35581ae4b8dSRuslan Ermilov.It Fa lowaddr , highaddr
35624503465SHiten PandyaBounds of the window of bus address space that
35724503465SHiten Pandya.Em cannot
35824503465SHiten Pandyabe directly accessed by the device.
3592d4071acSChristian BruefferThe window contains all addresses greater than lowaddr and
36024503465SHiten Pandyaless than or equal to highaddr.
36124503465SHiten PandyaFor example, a device incapable of DMA above 4GB, would specify
36224503465SHiten Pandyaa highaddr of
36324503465SHiten Pandya.Dv BUS_SPACE_MAXADDR
36424503465SHiten Pandyaand a lowaddr of
36524503465SHiten Pandya.Dv BUS_SPACE_MAXADDR_32BIT .
36624503465SHiten PandyaSimilarly a device that can only dma to addresses bellow 16MB would
36724503465SHiten Pandyaspecify a highaddr of
36824503465SHiten Pandya.Dv BUS_SPACE_MAXADDR
36924503465SHiten Pandyaand a lowaddr of
37024503465SHiten Pandya.Dv BUS_SPACE_MAXADDR_24BIT .
37124503465SHiten PandyaSome implementations requires that some region of device visible
37224503465SHiten Pandyaaddress space, overlapping available host memory, be outside the
37324503465SHiten Pandyawindow.
37424503465SHiten PandyaThis area of
37524503465SHiten Pandya.Ql safe memory
37624503465SHiten Pandyais used to bounce requests that would otherwise conflict with
37724503465SHiten Pandyathe exclusion window.
37824503465SHiten Pandya.It Fa filtfunc
37981ae4b8dSRuslan ErmilovOptional filter function (may be
38081ae4b8dSRuslan Ermilov.Dv NULL )
38181ae4b8dSRuslan Ermilovto be called for any attempt to
38224503465SHiten Pandyamap memory into the window described by
38324503465SHiten Pandya.Fa lowaddr
38424503465SHiten Pandyaand
38524503465SHiten Pandya.Fa highaddr .
38624503465SHiten PandyaA filter function is only required when the single window described
38724503465SHiten Pandyaby
38824503465SHiten Pandya.Fa lowaddr
38924503465SHiten Pandyaand
39024503465SHiten Pandya.Fa highaddr
39124503465SHiten Pandyacannot adequately describe the constraints of the device.
39224503465SHiten PandyaThe filter function will be called for every machine page
39324503465SHiten Pandyathat overlaps the exclusion window.
39424503465SHiten Pandya.It Fa filtfuncarg
39524503465SHiten PandyaArgument passed to all calls to the filter function for this tag.
39681ae4b8dSRuslan ErmilovMay be
39781ae4b8dSRuslan Ermilov.Dv NULL .
39824503465SHiten Pandya.It Fa maxsize
39924503465SHiten PandyaMaximum size, in bytes, of the sum of all segment lengths in a given
40024503465SHiten PandyaDMA mapping associated with this tag.
40124503465SHiten Pandya.It Fa nsegments
40224503465SHiten PandyaNumber of discontinuities (scatter/gather segments) allowed
40324503465SHiten Pandyain a DMA mapped region.
40424503465SHiten PandyaIf there is no restriction,
40524503465SHiten Pandya.Dv BUS_SPACE_UNRESTRICTED
40624503465SHiten Pandyamay be specified.
407094dc7e3SJohn-Mark Gurney.It Fa maxsegsz
408094dc7e3SJohn-Mark GurneyMaximum size, in bytes, of a segment in any DMA mapped region associated
409094dc7e3SJohn-Mark Gurneywith
410094dc7e3SJohn-Mark Gurney.Fa dmat .
41124503465SHiten Pandya.It Fa flags
41224503465SHiten PandyaAre as follows:
41381ae4b8dSRuslan Ermilov.Bl -tag -width ".Dv BUS_DMA_ALLOCNOW"
41424503465SHiten Pandya.It Dv BUS_DMA_ALLOCNOW
4150f3a0078SScott LongPre-allocate enough resources to handle at least one map load operation on
41671bb1f9bSScott Longthis tag.
41724503465SHiten PandyaIf sufficient resources are not available,
41824503465SHiten Pandya.Er ENOMEM
41924503465SHiten Pandyais returned.
42071bb1f9bSScott LongThis should not be used for tags that only describe buffers that will be
42171bb1f9bSScott Longallocated with
42271bb1f9bSScott Long.Fn bus_dmamem_alloc .
42371bb1f9bSScott LongAlso, due to resource sharing with other tags, this flag does not guarantee
42471bb1f9bSScott Longthat resources will be allocated or reserved exclusively for this tag.
42571bb1f9bSScott LongIt should be treated only as a minor optimization.
42624503465SHiten Pandya.El
4279b5c4b66SScott Long.It Fa lockfunc
42881ae4b8dSRuslan ErmilovOptional lock manipulation function (may be
42981ae4b8dSRuslan Ermilov.Dv NULL )
43081ae4b8dSRuslan Ermilovto be called when busdma
431c7d3a65dSHiten Pandyaneeds to manipulate a lock on behalf of the client.
43281ae4b8dSRuslan ErmilovIf
43381ae4b8dSRuslan Ermilov.Dv NULL
43481ae4b8dSRuslan Ermilovis specified,
4359b5c4b66SScott Long.Fn dflt_lock
4369b5c4b66SScott Longis used.
4379b5c4b66SScott Long.It Fa lockfuncarg
4389b5c4b66SScott LongOptional argument to be passed to the function specified by
4399b5c4b66SScott Long.Fa lockfunc .
44024503465SHiten Pandya.It Fa dmat
44124503465SHiten PandyaPointer to a bus_dma_tag_t where the resulting DMA tag will
44224503465SHiten Pandyabe stored.
44324503465SHiten Pandya.El
44424503465SHiten Pandya.Pp
44524503465SHiten PandyaReturns
44624503465SHiten Pandya.Er ENOMEM
44724503465SHiten Pandyaif sufficient memory is not available for tag creation
44824503465SHiten Pandyaor allocating mapping resources.
44924503465SHiten Pandya.It Fn bus_dma_tag_destroy "dmat"
45024503465SHiten PandyaDeallocate the DMA tag
45124503465SHiten Pandya.Fa dmat
45224503465SHiten Pandyathat was created by
45324503465SHiten Pandya.Fn bus_dma_tag_create .
45424503465SHiten Pandya.Pp
45524503465SHiten PandyaReturns
45624503465SHiten Pandya.Er EBUSY
45724503465SHiten Pandyaif any DMA maps remain associated with
45824503465SHiten Pandya.Fa dmat
45924503465SHiten Pandyaor
46024503465SHiten Pandya.Ql 0
46124503465SHiten Pandyaon success.
46224503465SHiten Pandya.It Fn bus_dmamap_create "dmat" "flags" "*mapp"
46324503465SHiten PandyaAllocates and initializes a DMA map.
46424503465SHiten PandyaArguments are as follows:
46581ae4b8dSRuslan Ermilov.Bl -tag -width ".Fa nsegments"
46624503465SHiten Pandya.It Fa dmat
46724503465SHiten PandyaDMA tag.
46824503465SHiten Pandya.It Fa flags
46924503465SHiten PandyaThe value of this argument is currently undefined and should be
47024503465SHiten Pandyaspecified as
47124503465SHiten Pandya.Ql 0 .
47224503465SHiten Pandya.It Fa mapp
47324503465SHiten PandyaPointer to a
47424503465SHiten Pandya.Vt bus_dmamap_t
47524503465SHiten Pandyawhere the resulting DMA map will be stored.
47624503465SHiten Pandya.El
47724503465SHiten Pandya.Pp
47824503465SHiten PandyaReturns
47924503465SHiten Pandya.Er ENOMEM
48024503465SHiten Pandyaif sufficient memory is not available for creating the
48124503465SHiten Pandyamap or allocating mapping resources.
48224503465SHiten Pandya.It Fn bus_dmamap_destroy "dmat" "map"
48324503465SHiten PandyaFrees all resources associated with a given DMA map.
48424503465SHiten PandyaArguments are as follows:
48581ae4b8dSRuslan Ermilov.Bl -tag -width ".Fa dmat"
48624503465SHiten Pandya.It Fa dmat
48724503465SHiten PandyaDMA tag used to allocate
48824503465SHiten Pandya.Fa map .
48924503465SHiten Pandya.It Fa map
49024503465SHiten PandyaThe DMA map to destroy.
49124503465SHiten Pandya.El
49224503465SHiten Pandya.Pp
49324503465SHiten PandyaReturns
49424503465SHiten Pandya.Er EBUSY
49524503465SHiten Pandyaif a mapping is still active for
49624503465SHiten Pandya.Fa map .
49795929b66SWarner Losh.It Fn bus_dmamap_load "dmat" "map" "buf" "buflen" "*callback" \
49895929b66SWarner Losh"callback_arg" "flags"
49924503465SHiten PandyaCreates a mapping in device visible address space of
50024503465SHiten Pandya.Fa buflen
50124503465SHiten Pandyabytes of
50224503465SHiten Pandya.Fa buf ,
50324503465SHiten Pandyaassociated with the DMA map
50424503465SHiten Pandya.Fa map .
50571bb1f9bSScott LongThis call will always return immediately and will not block for any reason.
50624503465SHiten PandyaArguments are as follows:
50781ae4b8dSRuslan Ermilov.Bl -tag -width ".Fa buflen"
50824503465SHiten Pandya.It Fa dmat
50924503465SHiten PandyaDMA tag used to allocate
51024503465SHiten Pandya.Fa map .
51124503465SHiten Pandya.It Fa map
51224503465SHiten PandyaA DMA map without a currently active mapping.
51324503465SHiten Pandya.It Fa buf
51424503465SHiten PandyaA kernel virtual address pointer to a contiguous (in KVA) buffer, to be
51524503465SHiten Pandyamapped into device visible address space.
51624503465SHiten Pandya.It Fa buflen
51724503465SHiten PandyaThe size of the buffer.
51824503465SHiten Pandya.It Fa callback Fa callback_arg
51924503465SHiten PandyaThe callback function, and its argument.
52071bb1f9bSScott LongThis function is called once sufficient mapping resources are available for
52171bb1f9bSScott Longthe DMA operation.
52271bb1f9bSScott LongIf resources are temporarily unavailable, this function will be deferred until
52371bb1f9bSScott Longlater, but the load operation will still return immediately to the caller.
52471bb1f9bSScott LongThus, callers should not assume that the callback will be called before the
52571bb1f9bSScott Longload returns, and code should be structured appropriately to handle this.
52671bb1f9bSScott LongSee below for specific flags and error codes that control this behavior.
52724503465SHiten Pandya.It Fa flags
52871bb1f9bSScott LongAre as follows:
52981ae4b8dSRuslan Ermilov.Bl -tag -width ".Dv BUS_DMA_NOWAIT"
53081ae4b8dSRuslan Ermilov.It Dv BUS_DMA_NOWAIT
53171bb1f9bSScott LongThe load should not be deferred in case of insufficient mapping resources,
53271bb1f9bSScott Longand instead should return immediately with an appropriate error.
53371bb1f9bSScott Long.El
53424503465SHiten Pandya.El
53524503465SHiten Pandya.Pp
53624503465SHiten PandyaReturn values to the caller are as follows:
53781ae4b8dSRuslan Ermilov.Bl -tag -width ".Er EINPROGRESS"
53824503465SHiten Pandya.It 0
53924503465SHiten PandyaThe callback has been called and completed.
54024503465SHiten PandyaThe status of the mapping has been delivered to the callback.
54124503465SHiten Pandya.It Er EINPROGRESS
54224503465SHiten PandyaThe mapping has been deferred for lack of resources.
54324503465SHiten PandyaThe callback will be called as soon as resources are available.
54424503465SHiten PandyaCallbacks are serviced in FIFO order.
5450f3a0078SScott LongTo ensure that ordering is guaranteed, all subsequent load requests will also
5460f3a0078SScott Longbe deferred until all callbacks have been processed.
54771bb1f9bSScott Long.It Er ENOMEM
54871bb1f9bSScott LongThe load request has failed due to insufficient resources, and the caller
54971bb1f9bSScott Longspecifically used the
55081ae4b8dSRuslan Ermilov.Dv BUS_DMA_NOWAIT
55171bb1f9bSScott Longflag.
55224503465SHiten Pandya.It Er EINVAL
55324503465SHiten PandyaThe load request was invalid.
55471bb1f9bSScott LongThe callback has been called and has been provided the same error.
55524503465SHiten PandyaThis error value may indicate that
55624503465SHiten Pandya.Fa dmat ,
55724503465SHiten Pandya.Fa map ,
55824503465SHiten Pandya.Fa buf ,
55924503465SHiten Pandyaor
56024503465SHiten Pandya.Fa callback
56124503465SHiten Pandyawere invalid, or
56271bb1f9bSScott Long.Fa buflen
56324503465SHiten Pandyawas larger than the
56424503465SHiten Pandya.Fa maxsize
56524503465SHiten Pandyaargument used to create the dma tag
56624503465SHiten Pandya.Fa dmat .
56724503465SHiten Pandya.El
56824503465SHiten Pandya.Pp
56924503465SHiten PandyaWhen the callback is called, it is presented with an error value
57024503465SHiten Pandyaindicating the disposition of the mapping.
57124503465SHiten PandyaError may be one of the following:
57281ae4b8dSRuslan Ermilov.Bl -tag -width ".Er EINPROGRESS"
57324503465SHiten Pandya.It 0
57424503465SHiten PandyaThe mapping was successful and the
57524503465SHiten Pandya.Fa dm_segs
57624503465SHiten Pandyacallback argument contains an array of
57724503465SHiten Pandya.Vt bus_dma_segment_t
57824503465SHiten Pandyaelements describing the mapping.
57924503465SHiten PandyaThis array is only valid during the scope of the callback function.
58024503465SHiten Pandya.It Er EFBIG
58124503465SHiten PandyaA mapping could not be achieved within the segment constraints provided
58224503465SHiten Pandyain the tag even though the requested allocation size was less than maxsize.
58324503465SHiten Pandya.El
58424503465SHiten Pandya.It Fn bus_dmamap_load_mbuf "dmat" "map" "mbuf" "callback2" "callback_arg" \
58524503465SHiten Pandya"flags"
58624503465SHiten PandyaThis is a variation of
58724503465SHiten Pandya.Fn bus_dmamap_load
58824503465SHiten Pandyawhich maps mbuf chains
58924503465SHiten Pandyafor DMA transfers.
59024503465SHiten PandyaA
59124503465SHiten Pandya.Vt bus_size_t
59224503465SHiten Pandyaargument is also passed to the callback routine, which
59324503465SHiten Pandyacontains the mbuf chain's packet header length.
59471bb1f9bSScott LongThe
59581ae4b8dSRuslan Ermilov.Dv BUS_DMA_NOWAIT
59671bb1f9bSScott Longflag is implied, thus no callback deferral will happen.
59724503465SHiten Pandya.Pp
59824503465SHiten PandyaMbuf chains are assumed to be in kernel virtual address space.
59924503465SHiten Pandya.Pp
60071bb1f9bSScott LongBeside the error values listed for
60171bb1f9bSScott Long.Fn bus_dmamap_load ,
60224503465SHiten Pandya.Er EINVAL
60371bb1f9bSScott Longwill be returned if the size of the mbuf chain exceeds the maximum limit of the
60424503465SHiten PandyaDMA tag.
605824f4edfSScott Long.It Fn bus_dmamap_load_mbuf_sg "dmat" "map" "mbuf" "segs" "nsegs" "flags"
606824f4edfSScott LongThis is just like
607824f4edfSScott Long.Fn bus_dmamap_load_mbuf
6084f068961SRuslan Ermilovexcept that it returns immediately without calling a callback function.
6094f068961SRuslan ErmilovIt is provided for efficiency.
610824f4edfSScott LongThe scatter/gather segment array
611824f4edfSScott Long.Va segs
612824f4edfSScott Longis provided by the caller and filled in directly by the function.
613824f4edfSScott LongThe
614824f4edfSScott Long.Va nsegs
615824f4edfSScott Longargument is returned with the number of segments filled in.
616824f4edfSScott LongReturns the same errors as
617824f4edfSScott Long.Fn bus_dmamap_load_mbuf .
61824503465SHiten Pandya.It Fn bus_dmamap_load_uio "dmat" "map" "uio" "callback2" "callback_arg" "flags"
61924503465SHiten PandyaThis is a variation of
62024503465SHiten Pandya.Fn bus_dmamap_load
62124503465SHiten Pandyawhich maps buffers pointed to by
62224503465SHiten Pandya.Fa uio
62324503465SHiten Pandyafor DMA transfers.
62424503465SHiten PandyaA
62524503465SHiten Pandya.Vt bus_size_t
62624503465SHiten Pandyaargument is also passed to the callback routine, which contains the size of
62724503465SHiten Pandya.Fa uio ,
62824503465SHiten Pandyai.e.
62924503465SHiten Pandya.Fa uio->uio_resid .
63071bb1f9bSScott LongThe
63181ae4b8dSRuslan Ermilov.Dv BUS_DMA_NOWAIT
63271bb1f9bSScott Longflag is implied, thus no callback deferral will happen.
63371bb1f9bSScott LongReturns the same errors as
63471bb1f9bSScott Long.Fn bus_dmamap_load .
63524503465SHiten Pandya.Pp
63624503465SHiten PandyaIf
63724503465SHiten Pandya.Fa uio->uio_segflg
63824503465SHiten Pandyais
63924503465SHiten Pandya.Dv UIO_USERSPACE ,
64024503465SHiten Pandyathen it is assumed that the buffer,
64124503465SHiten Pandya.Fa uio
64224503465SHiten Pandyais in
64324503465SHiten Pandya.Fa "uio->uio_td->td_proc" Ns 's
64424503465SHiten Pandyaaddress space.
64524503465SHiten PandyaUser space memory must be in-core and wired prior to attempting a map
64624503465SHiten Pandyaload operation.
647490ec740SWarner LoshPages may be locked using
648490ec740SWarner Losh.Xr vslock 9 .
64924503465SHiten Pandya.It Fn bus_dmamap_unload "dmat" "map"
65024503465SHiten PandyaUnloads a DMA map.
65124503465SHiten PandyaArguments are as follows:
65281ae4b8dSRuslan Ermilov.Bl -tag -width ".Fa dmam"
65324503465SHiten Pandya.It Fa dmat
65424503465SHiten PandyaDMA tag used to allocate
65524503465SHiten Pandya.Fa map .
65624503465SHiten Pandya.It Fa map
65724503465SHiten PandyaThe DMA map that is to be unloaded.
65824503465SHiten Pandya.El
65924503465SHiten Pandya.Pp
66024503465SHiten Pandya.Fn bus_dmamap_unload
66124503465SHiten Pandyawill not perform any implicit synchronization of DMA buffers.
66224503465SHiten PandyaThis must be done explicitly by a call to
66324503465SHiten Pandya.Fn bus_dmamap_sync
66424503465SHiten Pandyaprior to unloading the map.
66524503465SHiten Pandya.It Fn bus_dmamap_sync "dmat" "map" "op"
66624503465SHiten PandyaPerforms synchronization of a device visible mapping with the CPU visible
66724503465SHiten Pandyamemory referenced by that mapping.
66824503465SHiten PandyaArguments are as follows:
66981ae4b8dSRuslan Ermilov.Bl -tag -width ".Fa dmat"
67024503465SHiten Pandya.It Fa dmat
67124503465SHiten PandyaDMA tag used to allocate
67224503465SHiten Pandya.Fa map .
67324503465SHiten Pandya.It Fa map
67424503465SHiten PandyaThe DMA mapping to be synchronized.
67524503465SHiten Pandya.It Fa op
67624503465SHiten PandyaType of synchronization operation to perform.
67724503465SHiten PandyaSee the definition of
67824503465SHiten Pandya.Vt bus_dmasync_op_t
67924503465SHiten Pandyafor a description of the acceptable values for
68024503465SHiten Pandya.Fa op .
68124503465SHiten Pandya.El
68224503465SHiten Pandya.Pp
68307bf564cSRuslan ErmilovThe
68424503465SHiten Pandya.Fn bus_dmamap_sync
68507bf564cSRuslan Ermilovfunction
68607bf564cSRuslan Ermilovis the method used to ensure that CPU's and device's direct
68707bf564cSRuslan Ermilovmemory access (DMA) to shared
68824503465SHiten Pandyamemory is coherent.
68924503465SHiten PandyaFor example, the CPU might be used to set up the contents of a buffer
69007bf564cSRuslan Ermilovthat is to be made available to a device.
69124503465SHiten PandyaTo ensure that the data are visible via the device's mapping of that
69207bf564cSRuslan Ermilovmemory, the buffer must be loaded and a DMA sync operation of
6936f56dcd4SJohn-Mark Gurney.Dv BUS_DMASYNC_PREWRITE
69424503465SHiten Pandyamust be performed.
69507bf564cSRuslan ErmilovIf later CPU modifies this buffer again, another
69607bf564cSRuslan Ermilov.Dv BUS_DMASYNC_PREWRITE
69707bf564cSRuslan Ermilovsync operation must be performed before an additional
69807bf564cSRuslan Ermilovaccess to this memory by a device.
69907bf564cSRuslan ErmilovConversely, a device updates the memory that is to be read by a CPU.
70007bf564cSRuslan ErmilovIn this case, the buffer must be loaded, and a DMA sync operation of
7016f56dcd4SJohn-Mark Gurney.Dv BUS_DMASYNC_PREREAD
70224503465SHiten Pandyamust be performed.
70307bf564cSRuslan ErmilovThe CPU will only be able to see the results of this memory update
70407bf564cSRuslan Ermilovonce the DMA operation has completed and a
7056f56dcd4SJohn-Mark Gurney.Dv BUS_DMASYNC_POSTREAD
70607bf564cSRuslan Ermilovsync operation has been performed.
70724503465SHiten Pandya.Pp
70807bf564cSRuslan ErmilovIf read and write operations are not preceded and followed by the
70924503465SHiten Pandyaappropriate synchronization operations, behavior is undefined.
7106f3d2701SScott Long.It Fn bus_dmamem_alloc "dmat" "**vaddr" "flags" "*mapp"
71124503465SHiten PandyaAllocates memory that is mapped into KVA at the address returned
71224503465SHiten Pandyain
71324503465SHiten Pandya.Fa vaddr
71424503465SHiten Pandyathat is permanently loaded into the newly created
71524503465SHiten Pandya.Vt bus_dmamap_t
71624503465SHiten Pandyareturned via
71724503465SHiten Pandya.Fa mapp .
71824503465SHiten PandyaArguments are as follows:
71981ae4b8dSRuslan Ermilov.Bl -tag -width ".Fa alignment"
72024503465SHiten Pandya.It Fa dmat
72124503465SHiten PandyaDMA tag describing the constraints of the DMA mapping.
72224503465SHiten Pandya.It Fa vaddr
72324503465SHiten PandyaPointer to a pointer that will hold the returned KVA mapping of
72424503465SHiten Pandyathe allocated region.
72524503465SHiten Pandya.It Fa flags
72624503465SHiten PandyaFlags are defined as follows:
72781ae4b8dSRuslan Ermilov.Bl -tag -width ".Dv BUS_DMA_NOWAIT"
72824503465SHiten Pandya.It Dv BUS_DMA_WAITOK
72924503465SHiten PandyaThe routine can safely wait (sleep) for resources.
73024503465SHiten Pandya.It Dv BUS_DMA_NOWAIT
73124503465SHiten PandyaThe routine is not allowed to wait for resources.
73224503465SHiten PandyaIf resources are not available,
73324503465SHiten Pandya.Dv ENOMEM
73424503465SHiten Pandyais returned.
73524503465SHiten Pandya.It Dv BUS_DMA_COHERENT
73624503465SHiten PandyaAttempt to map this memory such that cache sync operations are
73724503465SHiten Pandyaas cheap as possible.
73824503465SHiten PandyaThis flag is typically set on memory that will be accessed by both
73924503465SHiten Pandyaa CPU and a DMA engine, frequently.
74024503465SHiten PandyaUse of this flag does not remove the requirement of using
74124503465SHiten Pandyabus_dmamap_sync, but it may reduce the cost of performing
74224503465SHiten Pandyathese operations.
74381ae4b8dSRuslan ErmilovThe
74481ae4b8dSRuslan Ermilov.Dv BUS_DMA_COHERENT
74581ae4b8dSRuslan Ermilovflag is currently implemented on sparc64 and arm.
74682d227dcSMaxime Henrion.It Dv BUS_DMA_ZERO
74782d227dcSMaxime HenrionCauses the allocated memory to be set to all zeros.
74824503465SHiten Pandya.El
74924503465SHiten Pandya.It Fa mapp
7506f3d2701SScott LongPointer to a
7516f3d2701SScott Long.Vt bus_dmamap_t
7526f3d2701SScott Longwhere the resulting DMA map will be stored.
75324503465SHiten Pandya.El
75424503465SHiten Pandya.Pp
75524503465SHiten PandyaThe size of memory to be allocated is
75624503465SHiten Pandya.Fa maxsize
75724503465SHiten Pandyaas specified in
75824503465SHiten Pandya.Fa dmat .
75924503465SHiten Pandya.Pp
76024503465SHiten PandyaThe current implementation of
76124503465SHiten Pandya.Fn bus_dmamem_alloc
76224503465SHiten Pandyawill allocate all requests as a single segment.
76324503465SHiten Pandya.Pp
7646f3d2701SScott LongAn initial load operation is required to obtain the bus address of the allocated
7656f3d2701SScott Longmemory, and an unload operation is required before freeing the memory, as
7666f3d2701SScott Longdescribed below in
7676f3d2701SScott Long.Fn bus_dmamem_free .
7686f3d2701SScott LongMaps are automatically handled by this function and should not be explicitly
7696f3d2701SScott Longallocated or destroyed.
7706f3d2701SScott Long.Pp
7716f3d2701SScott LongAlthough an explicit load is not required for each access to the memory
77224503465SHiten Pandyareferenced by the returned map, the synchronization requirements
77324503465SHiten Pandyaas described in the
77424503465SHiten Pandya.Fn bus_dmamap_sync
7756f3d2701SScott Longsection still apply and should be used to achieve portability on architecutures
7766f3d2701SScott Longwithout coherent buses.
77724503465SHiten Pandya.Pp
77824503465SHiten PandyaReturns
77924503465SHiten Pandya.Er ENOMEM
78024503465SHiten Pandyaif sufficient memory is not available for completing
78124503465SHiten Pandyathe operation.
78224503465SHiten Pandya.It Fn bus_dmamem_free "dmat" "*vaddr" "map"
78324503465SHiten PandyaFrees memory previously allocated by
78424503465SHiten Pandya.Fn bus_dmamem_alloc .
78524503465SHiten PandyaAny mappings
78624503465SHiten Pandyawill be invalidated.
78724503465SHiten PandyaArguments are as follows:
78881ae4b8dSRuslan Ermilov.Bl -tag -width ".Fa vaddr"
78924503465SHiten Pandya.It Fa dmat
79024503465SHiten PandyaDMA tag.
79124503465SHiten Pandya.It Fa vaddr
79224503465SHiten PandyaKernel virtual address of the memory.
79324503465SHiten Pandya.It Fa map
79424503465SHiten PandyaDMA map to be invalidated.
79524503465SHiten Pandya.El
79624503465SHiten Pandya.El
79724503465SHiten Pandya.Sh RETURN VALUES
79824503465SHiten PandyaBehavior is undefined if invalid arguments are passed to
79924503465SHiten Pandyaany of the above functions.
80024503465SHiten PandyaIf sufficient resources cannot be allocated for a given
80124503465SHiten Pandyatransaction,
80224503465SHiten Pandya.Er ENOMEM
80324503465SHiten Pandyais returned.
80424503465SHiten PandyaAll
80524503465SHiten Pandyaroutines that are not of type,
80624503465SHiten Pandya.Vt void ,
80724503465SHiten Pandyawill return 0 on success or an error
80824503465SHiten Pandyacode, as discussed above.
80924503465SHiten Pandya.Pp
81024503465SHiten PandyaAll
81124503465SHiten Pandya.Vt void
81224503465SHiten Pandyaroutines will succeed if provided with valid arguments.
8134905491fSScott Long.Sh LOCKING
8144905491fSScott LongTwo locking protocols are used by
8154905491fSScott Long.Nm .
8164905491fSScott LongThe first is a private global lock that is used to synchronize access to the
8174905491fSScott Longbounce buffer pool on the architectures that make use of them.
8184905491fSScott LongThis lock is strictly a leaf lock that is only used internally to
8194905491fSScott Long.Nm
8204905491fSScott Longand is not exposed to clients of the API.
8214905491fSScott Long.Pp
8224905491fSScott LongThe second protocol involves protecting various resources stored in the tag.
8234905491fSScott LongSince almost all
8244905491fSScott Long.Nm
8254905491fSScott Longoperations are done through requests from the driver that created the tag,
8264905491fSScott Longthe most efficient way to protect the tag resources is through the lock that
8274905491fSScott Longthe driver uses.
8284905491fSScott LongIn cases where
8294905491fSScott Long.Nm
8304905491fSScott Longacts on its own without being called by the driver, the lock primitive
8314905491fSScott Longspecified in the tag is acquired and released automatically.
8324905491fSScott LongAn example of this is when the
8334905491fSScott Long.Fn bus_dmamap_load
834b1cc1020SGiorgos Keramidascallback function is called from a deferred context instead of the driver
8354905491fSScott Longcontext.
8364905491fSScott LongThis means that certain
8374905491fSScott Long.Nm
83881ae4b8dSRuslan Ermilovfunctions must always be called with the same lock held that is specified in the
83981ae4b8dSRuslan Ermilovtag.
84081ae4b8dSRuslan ErmilovThese functions include:
8414905491fSScott Long.Pp
84281ae4b8dSRuslan Ermilov.Bl -item -offset indent -compact
84381ae4b8dSRuslan Ermilov.It
84481ae4b8dSRuslan Ermilov.Fn bus_dmamap_load
84581ae4b8dSRuslan Ermilov.It
84681ae4b8dSRuslan Ermilov.Fn bus_dmamap_load_uio
84781ae4b8dSRuslan Ermilov.It
84881ae4b8dSRuslan Ermilov.Fn bus_dmamap_load_mbuf
84981ae4b8dSRuslan Ermilov.It
85081ae4b8dSRuslan Ermilov.Fn bus_dmamap_load_mbuf_sg
85181ae4b8dSRuslan Ermilov.It
85281ae4b8dSRuslan Ermilov.Fn bus_dmamap_unload
85381ae4b8dSRuslan Ermilov.It
85481ae4b8dSRuslan Ermilov.Fn bus_dmamap_sync
8554905491fSScott Long.El
8564905491fSScott Long.Pp
8574905491fSScott LongThere is one exception to this rule.
8584905491fSScott LongIt is common practice to call some of these functions during driver start-up
8594905491fSScott Longwithout any locks held.
8604905491fSScott LongSo long as there is a guarantee of no possible concurrent use of the tag by
8614905491fSScott Longdifferent threads during this operation, it is safe to not hold a lock for
8624905491fSScott Longthese functions.
8634905491fSScott Long.Pp
8644905491fSScott LongCertain
8654905491fSScott Long.Nm
8664905491fSScott Longoperations should not be called with the driver lock held, either because
8674905491fSScott Longthey are already protected by an internal lock, or because they might sleep
86881ae4b8dSRuslan Ermilovdue to memory or resource allocation.
86981ae4b8dSRuslan ErmilovThe following functions must not be
8704905491fSScott Longcalled with any non-sleepable locks held:
8714905491fSScott Long.Pp
87281ae4b8dSRuslan Ermilov.Bl -item -offset indent -compact
87381ae4b8dSRuslan Ermilov.It
87481ae4b8dSRuslan Ermilov.Fn bus_dma_tag_create
87581ae4b8dSRuslan Ermilov.It
87681ae4b8dSRuslan Ermilov.Fn bus_dmamap_create
87781ae4b8dSRuslan Ermilov.It
87881ae4b8dSRuslan Ermilov.Fn bus_dmamem_alloc
8794905491fSScott Long.El
8804905491fSScott Long.Pp
8814905491fSScott LongAll other functions do not have a locking protocol and can thus be
8824905491fSScott Longcalled with or without and system or driver locks held.
88324503465SHiten Pandya.Sh SEE ALSO
88424503465SHiten Pandya.Xr devclass 9 ,
88524503465SHiten Pandya.Xr device 9 ,
88624503465SHiten Pandya.Xr driver 9 ,
887490ec740SWarner Losh.Xr rman 9 ,
888490ec740SWarner Losh.Xr vslock 9
88924503465SHiten Pandya.Pp
89024503465SHiten Pandya.Rs
89124503465SHiten Pandya.%A "Jason R. Thorpe"
89224503465SHiten Pandya.%T "A Machine-Independent DMA Framework for NetBSD"
89324503465SHiten Pandya.%J "Proceedings of the Summer 1998 USENIX Technical Conference"
89424503465SHiten Pandya.%Q "USENIX Association"
89524503465SHiten Pandya.%D "June 1998"
89624503465SHiten Pandya.Re
89724503465SHiten Pandya.Sh HISTORY
89824503465SHiten PandyaThe
89924503465SHiten Pandya.Nm
90024503465SHiten Pandyainterface first appeared in
90124503465SHiten Pandya.Nx 1.3 .
90224503465SHiten Pandya.Pp
90324503465SHiten PandyaThe
90424503465SHiten Pandya.Nm
90524503465SHiten PandyaAPI was adopted from
90624503465SHiten Pandya.Nx
90724503465SHiten Pandyafor use in the CAM SCSI subsystem.
90824503465SHiten PandyaThe alterations to the original API were aimed to remove the need for
90924503465SHiten Pandyaa
91024503465SHiten Pandya.Vt bus_dma_segment_t
91124503465SHiten Pandyaarray stored in each
91224503465SHiten Pandya.Vt bus_dmamap_t
91324503465SHiten Pandyawhile allowing callers to queue up on scarce resources.
91424503465SHiten Pandya.Sh AUTHORS
91524503465SHiten PandyaThe
91624503465SHiten Pandya.Nm
917b9b855ddSMaxime Henrioninterface was designed and implemented by
918b9b855ddSMaxime Henrion.An Jason R. Thorpe
919b9b855ddSMaxime Henrionof the Numerical Aerospace Simulation Facility, NASA Ames Research Center.
92024503465SHiten PandyaAdditional input on the
92124503465SHiten Pandya.Nm
922b9b855ddSMaxime Henriondesign was provided by
923b9b855ddSMaxime Henrion.An -nosplit
924b9b855ddSMaxime Henrion.An Chris Demetriou ,
925b9b855ddSMaxime Henrion.An Charles Hannum ,
926b9b855ddSMaxime Henrion.An Ross Harvey ,
927b9b855ddSMaxime Henrion.An Matthew Jacob ,
928b9b855ddSMaxime Henrion.An Jonathan Stone ,
929b9b855ddSMaxime Henrionand
930b9b855ddSMaxime Henrion.An Matt Thomas .
93124503465SHiten Pandya.Pp
93224503465SHiten PandyaThe
93324503465SHiten Pandya.Nm
93424503465SHiten Pandyainterface in
93524503465SHiten Pandya.Fx
936b9b855ddSMaxime Henrionbenefits from the contributions of
937b9b855ddSMaxime Henrion.An Justin T. Gibbs ,
938b9b855ddSMaxime Henrion.An Peter Wemm ,
939b9b855ddSMaxime Henrion.An Doug Rabson ,
940b9b855ddSMaxime Henrion.An Matthew N. Dodd ,
941b9b855ddSMaxime Henrion.An Sam Leffler ,
942b9b855ddSMaxime Henrion.An Maxime Henrion ,
943b9b855ddSMaxime Henrion.An Jake Burkholder ,
944b9b855ddSMaxime Henrion.An Takahashi Yoshihiro ,
945b9b855ddSMaxime Henrion.An Scott Long
946b9b855ddSMaxime Henrionand many others.
94724503465SHiten Pandya.Pp
948b9b855ddSMaxime HenrionThis manual page was written by
949b9b855ddSMaxime Henrion.An Hiten M. Pandya
950b9b855ddSMaxime Henrionand
951b9b855ddSMaxime Henrion.An Justin T. Gibbs .
952