19cca02b8SHiten Pandya.\" 29cca02b8SHiten Pandya.\" Copyright (c) 2002, 2003, 2004 The DragonFly Project. All rights reserved. 39cca02b8SHiten Pandya.\" 49cca02b8SHiten Pandya.\" This code is derived from software contributed to The DragonFly Project 59cca02b8SHiten Pandya.\" by Hiten Pandya <hmp@backplane.com>. 617a12593SHiten Pandya.\" 717a12593SHiten Pandya.\" Redistribution and use in source and binary forms, with or without 817a12593SHiten Pandya.\" modification, are permitted provided that the following conditions 917a12593SHiten Pandya.\" are met: 1017a12593SHiten Pandya.\" 119cca02b8SHiten Pandya.\" 1. Redistributions of source code must retain the above copyright 129cca02b8SHiten Pandya.\" notice, this list of conditions and the following disclaimer. 139cca02b8SHiten Pandya.\" 2. Redistributions in binary form must reproduce the above copyright 149cca02b8SHiten Pandya.\" notice, this list of conditions and the following disclaimer in 159cca02b8SHiten Pandya.\" the documentation and/or other materials provided with the 169cca02b8SHiten Pandya.\" distribution. 179cca02b8SHiten Pandya.\" 3. Neither the name of The DragonFly Project nor the names of its 189cca02b8SHiten Pandya.\" contributors may be used to endorse or promote products derived 199cca02b8SHiten Pandya.\" from this software without specific, prior written permission. 209cca02b8SHiten Pandya.\" 219cca02b8SHiten Pandya.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 229cca02b8SHiten Pandya.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 239cca02b8SHiten Pandya.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 249cca02b8SHiten Pandya.\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 259cca02b8SHiten Pandya.\" COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 269cca02b8SHiten Pandya.\" INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, 279cca02b8SHiten Pandya.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 289cca02b8SHiten Pandya.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 299cca02b8SHiten Pandya.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 309cca02b8SHiten Pandya.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 319cca02b8SHiten Pandya.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 329cca02b8SHiten Pandya.\" SUCH DAMAGE. 3317a12593SHiten Pandya.\" 3417a12593SHiten Pandya.\" Copyright (c) 1996, 1997, 1998, 2001 The NetBSD Foundation, Inc. 3517a12593SHiten Pandya.\" All rights reserved. 3617a12593SHiten Pandya.\" 3717a12593SHiten Pandya.\" This code is derived from software contributed to The NetBSD Foundation 3817a12593SHiten Pandya.\" by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 3917a12593SHiten Pandya.\" NASA Ames Research Center. 4017a12593SHiten Pandya.\" 4117a12593SHiten Pandya.\" Redistribution and use in source and binary forms, with or without 4217a12593SHiten Pandya.\" modification, are permitted provided that the following conditions 4317a12593SHiten Pandya.\" are met: 4417a12593SHiten Pandya.\" 1. Redistributions of source code must retain the above copyright 4517a12593SHiten Pandya.\" notice, this list of conditions and the following disclaimer. 4617a12593SHiten Pandya.\" 2. Redistributions in binary form must reproduce the above copyright 4717a12593SHiten Pandya.\" notice, this list of conditions and the following disclaimer in the 4817a12593SHiten Pandya.\" documentation and/or other materials provided with the distribution. 4917a12593SHiten Pandya.\" 3. All advertising materials mentioning features or use of this software 5017a12593SHiten Pandya.\" must display the following acknowledgment: 5117a12593SHiten Pandya.\" This product includes software developed by the NetBSD 5217a12593SHiten Pandya.\" Foundation, Inc. and its contributors. 5317a12593SHiten Pandya.\" 4. Neither the name of The NetBSD Foundation nor the names of its 5417a12593SHiten Pandya.\" contributors may be used to endorse or promote products derived 5517a12593SHiten Pandya.\" from this software without specific prior written permission. 5617a12593SHiten Pandya.\" 5717a12593SHiten Pandya.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 5817a12593SHiten Pandya.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 5917a12593SHiten Pandya.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 6017a12593SHiten Pandya.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 6117a12593SHiten Pandya.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 6217a12593SHiten Pandya.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 6317a12593SHiten Pandya.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 6417a12593SHiten Pandya.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 6517a12593SHiten Pandya.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 6617a12593SHiten Pandya.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 6717a12593SHiten Pandya.\" POSSIBILITY OF SUCH DAMAGE. 6817a12593SHiten Pandya.\" 6917a12593SHiten Pandya.\" $FreeBSD: /repoman/r/ncvs/src/share/man/man9/bus_dma.9,v 1.7 2003/07/27 14:05:29 mux Exp $ 7017a12593SHiten Pandya.\" $NetBSD: bus_dma.9,v 1.25 2002/10/14 13:43:16 wiz Exp $ 7117a12593SHiten Pandya.\" 72*030b0c8cSMichael Neumann.Dd December 09, 2023 7317a12593SHiten Pandya.Dt BUS_DMA 9 7417a12593SHiten Pandya.Os 7517a12593SHiten Pandya.Sh NAME 7617a12593SHiten Pandya.Nm bus_dma , 7717a12593SHiten Pandya.Nm bus_dma_tag_create , 7817a12593SHiten Pandya.Nm bus_dma_tag_destroy , 7917a12593SHiten Pandya.Nm bus_dmamap_create , 8017a12593SHiten Pandya.Nm bus_dmamap_destroy , 8117a12593SHiten Pandya.Nm bus_dmamap_load , 82537b9048SSascha Wildner.Nm bus_dmamap_load_ccb , 8317a12593SHiten Pandya.Nm bus_dmamap_load_mbuf , 847c7d835fSSepherosa Ziehau.Nm bus_dmamap_load_mbuf_segment , 857c7d835fSSepherosa Ziehau.Nm bus_dmamap_load_mbuf_defrag , 8617a12593SHiten Pandya.Nm bus_dmamap_load_uio , 8717a12593SHiten Pandya.Nm bus_dmamap_unload , 8817a12593SHiten Pandya.Nm bus_dmamap_sync , 8917a12593SHiten Pandya.Nm bus_dmamem_alloc , 907c7d835fSSepherosa Ziehau.Nm bus_dmamem_coherent , 917c7d835fSSepherosa Ziehau.Nm bus_dmamem_coherent_any , 921efd0e72SHiten Pandya.Nm bus_dmamem_free 9317a12593SHiten Pandya.Nd Bus and Machine Independent DMA Mapping Interface 9417a12593SHiten Pandya.Sh SYNOPSIS 953f6e2311SSascha Wildner.In sys/bus.h 9617a12593SHiten Pandya.Ft int 9717a12593SHiten Pandya.Fn bus_dma_tag_create "bus_dma_tag_t parent" "bus_size_t alignment" \ 9817a12593SHiten Pandya"bus_size_t boundary" "bus_addr_t lowaddr" "bus_addr_t highaddr" \ 99*030b0c8cSMichael Neumann"bus_size_t maxsize" "int nsegments" "bus_size_t maxsegsz" \ 100*030b0c8cSMichael Neumann"int flags" "bus_dma_tag_t *dmat" 10117a12593SHiten Pandya.Ft int 10217a12593SHiten Pandya.Fn bus_dma_tag_destroy "bus_dma_tag_t dmat" 10317a12593SHiten Pandya.Ft int 10417a12593SHiten Pandya.Fn bus_dmamap_create "bus_dma_tag_t dmat" "int flags" "bus_dmamap_t *mapp" 10517a12593SHiten Pandya.Ft int 10617a12593SHiten Pandya.Fn bus_dmamap_destroy "bus_dma_tag_t dmat" "bus_dmamap_t map" 10717a12593SHiten Pandya.Ft int 10817a12593SHiten Pandya.Fn bus_dmamap_load "bus_dma_tag_t dmat" "bus_dmamap_t map" "void *buf" \ 10917a12593SHiten Pandya"bus_size_t buflen" "bus_dmamap_callback_t *callback" "void *callback_arg" \ 11017a12593SHiten Pandya"int flags" 11117a12593SHiten Pandya.Ft int 112537b9048SSascha Wildner.Fn bus_dmamap_load_ccb "bus_dma_tag_t dmat" "bus_dmamap_t map" \ 113537b9048SSascha Wildner"union ccb *ccb" "bus_dmamap_callback_t *callback" "void *callback_arg" \ 114537b9048SSascha Wildner"int flags" 115537b9048SSascha Wildner.Ft int 11617a12593SHiten Pandya.Fn bus_dmamap_load_mbuf "bus_dma_tag_t dmat" "bus_dmamap_t map" \ 11717a12593SHiten Pandya"struct mbuf *mbuf" "bus_dmamap_callback2_t *callback" "void *callback_arg" \ 11817a12593SHiten Pandya"int flags" 11917a12593SHiten Pandya.Ft int 1207c7d835fSSepherosa Ziehau.Fn bus_dmamap_load_mbuf_segment "bus_dma_tag_t dmat" "bus_dmamap_t map" \ 1217c7d835fSSepherosa Ziehau"struct mbuf *mbuf" "bus_dma_segment_t *segs" "int maxsegs" "int *nsegs" \ 1227c7d835fSSepherosa Ziehau"int flags" 1237c7d835fSSepherosa Ziehau.Ft int 1247c7d835fSSepherosa Ziehau.Fn bus_dmamap_load_mbuf_defrag "bus_dma_tag_t dmat" "bus_dmamap_t map" \ 1257c7d835fSSepherosa Ziehau"struct mbuf **mbuf" "bus_dma_segment_t *segs" "int maxsegs" "int *nsegs" \ 1267c7d835fSSepherosa Ziehau"int flags" 1277c7d835fSSepherosa Ziehau.Ft int 12817a12593SHiten Pandya.Fn bus_dmamap_load_uio "bus_dma_tag_t dmat" "bus_dmamap_t map" \ 12917a12593SHiten Pandya"struct uio *uio" "bus_dmamap_callback2_t *callback" "void *callback_arg" \ 13017a12593SHiten Pandya"int flags" 13117a12593SHiten Pandya.Ft int 13217a12593SHiten Pandya.Fn bus_dmamem_alloc "bus_dma_tag_t dmat" "void **vaddr" \ 13317a12593SHiten Pandya"int flags" "bus_dmamap_t *mapp" 1347c7d835fSSepherosa Ziehau.Ft int 1357c7d835fSSepherosa Ziehau.Fn bus_dmamem_coherent "bus_dma_tag_t parent" "bus_size_t alignment" \ 1367c7d835fSSepherosa Ziehau"bus_size_t boundary" "bus_addr_t lowaddr" "bus_addr_t highaddr" \ 1377c7d835fSSepherosa Ziehau"bus_size_t maxsize" "int flags" "bus_dmamem_t *dmem" 1387c7d835fSSepherosa Ziehau.Ft void * 1397c7d835fSSepherosa Ziehau.Fn bus_dmamem_coherent_any "bus_dma_tag_t parent" "bus_size_t alignment" \ 1407c7d835fSSepherosa Ziehau"bus_size_t maxsize" "int flags" "bus_dma_tag_t *dtag" "bus_dmamap_t *dmap" \ 1417c7d835fSSepherosa Ziehau"bus_addr_t *busaddr" 14217a12593SHiten Pandya.Ft void 14317a12593SHiten Pandya.Fn bus_dmamap_unload "bus_dma_tag_t dmat" "bus_dmamap_t map" 14417a12593SHiten Pandya.Ft void 14517a12593SHiten Pandya.Fn bus_dmamap_sync "bus_dma_tag_t dmat" "bus_dmamap_t map" \ 14677db1ba9SSascha Wildner"bus_dmasync_op_t op" 14717a12593SHiten Pandya.Ft void 14817a12593SHiten Pandya.Fn bus_dmamem_free "bus_dma_tag_t dmat" "void *vaddr" \ 14917a12593SHiten Pandya"bus_dmamap_t map" 15017a12593SHiten Pandya.Sh DESCRIPTION 15117a12593SHiten PandyaDirect Memory Access (DMA) is a method of transferring data 15217a12593SHiten Pandyawithout involving the CPU, thus providing higher performance. 15317a12593SHiten PandyaA DMA transaction can be achieved between device to memory, 15417a12593SHiten Pandyadevice to device, or memory to memory. 15517a12593SHiten Pandya.Pp 15617a12593SHiten PandyaThe 15717a12593SHiten Pandya.Nm 15817a12593SHiten PandyaAPI is a bus, device, and machine-independent (MI) interface to 15917a12593SHiten PandyaDMA mechanisms. 16017a12593SHiten PandyaIt provides the client with flexibility and simplicity by 16117a12593SHiten Pandyaabstracting machine dependent issues like setting up 16217a12593SHiten PandyaDMA mappings, handling cache issues, bus specific features 16317a12593SHiten Pandyaand limitations. 16417a12593SHiten Pandya.Sh STRUCTURES AND TYPES 16517a12593SHiten Pandya.Bl -tag -width compact 16617a12593SHiten Pandya.It Vt bus_dma_tag_t 16717a12593SHiten PandyaA machine-dependent (MD) opaque type that describes the 16817a12593SHiten Pandyacharacteristics of DMA transactions. 16917a12593SHiten PandyaDMA tags are organized into a hierarchy, with each child 17017a12593SHiten Pandyatag inheriting the restrictions of its parent. 17117a12593SHiten PandyaThis allows all devices along the path of DMA transactions 17217a12593SHiten Pandyato contribute to the constraints of those transactions. 17317a12593SHiten Pandya.It Vt bus_dma_segment_t 17417a12593SHiten PandyaA machine-dependent type that describes individual 17517a12593SHiten PandyaDMA segments. 17617a12593SHiten Pandya.Bd -literal 17717a12593SHiten Pandya bus_addr_t ds_addr; 17817a12593SHiten Pandya bus_size_t ds_len; 17917a12593SHiten Pandya.Ed 18017a12593SHiten Pandya.sp 18117a12593SHiten PandyaThe 18217a12593SHiten Pandya.Fa ds_addr 18317a12593SHiten Pandyafield contains the device visible address of the DMA segment, and 18417a12593SHiten Pandya.Fa ds_len 18517a12593SHiten Pandyacontains the length of the DMA segment. 18617a12593SHiten PandyaAlthough the DMA segments returned by a mapping call will adhere to 18717a12593SHiten Pandyaall restrictions necessary for a successful DMA operation, some conversion 18817a12593SHiten Pandya(e.g. a conversion from host byte order to the device's byte order) is 18917a12593SHiten Pandyaalmost always required when presenting segment information to the device. 19017a12593SHiten Pandya.It Vt bus_dmamap_t 19117a12593SHiten PandyaA machine-dependent opaque type describing an individual mapping. 19217a12593SHiten PandyaMultiple DMA maps can be associated with one DMA tag. 1937c7d835fSSepherosa Ziehau.It Vt bus_dmamem_t 1947c7d835fSSepherosa ZiehauA machine-dependent type that describes DMA memory created by 1957c7d835fSSepherosa Ziehau.Fn bus_dmamem_coherent . 1967c7d835fSSepherosa Ziehau.Bd -literal 1977c7d835fSSepherosa Ziehau bus_dma_tag_t dmem_tag; 1987c7d835fSSepherosa Ziehau bus_dmamap_t dmem_map; 1997c7d835fSSepherosa Ziehau void *dmem_addr; 2007c7d835fSSepherosa Ziehau bus_addr_t dmem_busaddr; 2017c7d835fSSepherosa Ziehau.Ed 2027c7d835fSSepherosa Ziehau.sp 2037c7d835fSSepherosa ZiehauThe 2047c7d835fSSepherosa Ziehau.Fa dmem_tag 2057c7d835fSSepherosa Ziehaufield contains the DMA tag of the DMA memory and 2067c7d835fSSepherosa Ziehau.Fa dmem_map 2077c7d835fSSepherosa Ziehaufield contains the DMA map of the DMA memory. 2087c7d835fSSepherosa ZiehauThe 2097c7d835fSSepherosa Ziehau.Fa dmem_addr 2107c7d835fSSepherosa Ziehaufield points to the allocated DMA memory in kernel virtual address space. 2117c7d835fSSepherosa ZiehauThe 2127c7d835fSSepherosa Ziehau.Fa dmem_busaddr 2137c7d835fSSepherosa Ziehaufield contains the device visible address of the DMA memory. 21417a12593SHiten Pandya.It Vt bus_dmamap_callback_t 21517a12593SHiten PandyaClient specified callback for receiving mapping information resulting from 21617a12593SHiten Pandyathe load of a 21717a12593SHiten Pandya.Vt bus_dmamap_t 21817a12593SHiten Pandyavia 219537b9048SSascha Wildner.Fn bus_dmamap_load 220537b9048SSascha Wildneror 221537b9048SSascha Wildner.Fn bus_dmamap_load_ccb . 22217a12593SHiten PandyaCallbacks are of the format: 22317a12593SHiten Pandya.Bl -tag -width compact 22417a12593SHiten Pandya.It Ft void 22517a12593SHiten Pandya.Fn "client_callback" "void *callback_arg" "bus_dma_segment_t *segs" \ 22617a12593SHiten Pandya"int nseg" "int error" 22717a12593SHiten Pandya.El 22817a12593SHiten Pandya.sp 22917a12593SHiten PandyaThe 23017a12593SHiten Pandya.Fa callback_arg 23117a12593SHiten Pandyais the callback argument passed to dmamap load functions. 23217a12593SHiten PandyaThe 23317a12593SHiten Pandya.Fa segs 23417a12593SHiten Pandyaand 23517a12593SHiten Pandya.Fa nseg 23617a12593SHiten Pandyaparameters describe an array of 23717a12593SHiten Pandya.Vt bus_dma_segment_t 23817a12593SHiten Pandyastructures that represent the mapping. 23917a12593SHiten PandyaThis array is only valid within the scope of the callback function. 24017a12593SHiten PandyaThe success or failure of the mapping is indicated by the 24117a12593SHiten Pandya.Fa error 24217a12593SHiten Pandyaparameter. 24317a12593SHiten PandyaMore information on the use of callbacks can be found in the 24417a12593SHiten Pandyadescription of the individual dmamap load functions. 24517a12593SHiten Pandya.It Vt bus_dmamap_callback2_t 24617a12593SHiten PandyaClient specified callback for receiving mapping information resulting from 24717a12593SHiten Pandyathe load of a 24817a12593SHiten Pandya.Vt bus_dmamap_t 24917a12593SHiten Pandyavia 25017a12593SHiten Pandya.Fn bus_dmamap_load_uio 25117a12593SHiten Pandyaor 25217a12593SHiten Pandya.Fn bus_dmamap_load_mbuf . 25317a12593SHiten Pandya.sp 25417a12593SHiten PandyaCallback2s are of the format: 25517a12593SHiten Pandya.Bl -tag -width compact 25617a12593SHiten Pandya.It Ft void 25717a12593SHiten Pandya.Fn "client_callback2" "void *callback_arg" "bus_dma_segment_t *segs" \ 25817a12593SHiten Pandya"int nseg" "bus_size_t mapsize" "int error" 25917a12593SHiten Pandya.El 26017a12593SHiten Pandya.sp 26117a12593SHiten PandyaCallback2's behavior is the same as 26217a12593SHiten Pandya.Vt bus_dmamap_callback_t 26317a12593SHiten Pandyawith the addition that the length of the data mapped is provided via 26417a12593SHiten Pandya.Fa mapsize . 26517a12593SHiten Pandya.It Vt bus_dmasync_op_t 26617a12593SHiten PandyaMemory synchronization operation specifier. 267a42bad2dSSascha WildnerBus DMA requires explicit synchronization of memory with its device 26817a12593SHiten Pandyavisible mapping in order to guarantee memory coherency. 26917a12593SHiten PandyaThe 27017a12593SHiten Pandya.Vt bus_dmasync_op_t 27117a12593SHiten Pandyaallows the type of DMA operation that will be or has been performed 27217a12593SHiten Pandyato be communicated to the system so that the correct coherency measures 27317a12593SHiten Pandyaare taken. 27417a12593SHiten PandyaAll operations specified below are performed from the DMA engine's 27517a12593SHiten Pandyapoint of view: 27617a12593SHiten Pandya.Bl -tag -width BUS_DMASYNC_POSTWRITE 27717a12593SHiten Pandya.It Dv BUS_DMASYNC_PREREAD 27817a12593SHiten PandyaPerform any synchronization required after an update of memory by the CPU 27917a12593SHiten Pandyabut prior to DMA read operations. 28017a12593SHiten Pandya.It Dv BUS_DMASYNC_PREWRITE 28117a12593SHiten PandyaPerform any synchronization required after an update of memory by the CPU 28217a12593SHiten Pandyabut prior to DMA write operations. 28317a12593SHiten Pandya.It Dv BUS_DMASYNC_POSTREAD 28417a12593SHiten PandyaPerform any synchronization required after DMA read operations, but prior 28517a12593SHiten Pandyato CPU access of the memory. 28617a12593SHiten Pandya.It Dv BUS_DMASYNC_POSTWRITE 28717a12593SHiten PandyaPerform any synchronization required after DMA write operations, but prior 28817a12593SHiten Pandyato CPU access of the memory. 28917a12593SHiten Pandya.El 29017a12593SHiten Pandya.El 29117a12593SHiten Pandya.sp 29217a12593SHiten Pandya.Sh FUNCTIONS 29317a12593SHiten Pandya.Bl -tag -width compact 29417a12593SHiten Pandya.It Fn bus_dma_tag_create "parent" "alignment" "boundary" "lowaddr" \ 295*030b0c8cSMichael Neumann"highaddr" "maxsize" "nsegments" "maxsegsz" "flags" "*dmat" 29617a12593SHiten PandyaAllocates a device specific DMA tag, and initializes it according to 29717a12593SHiten Pandyathe arguments provided: 298*030b0c8cSMichael Neumann.Bl -tag -width alignment -compact 29917a12593SHiten Pandya.It Fa parent 30017a12593SHiten PandyaIndicates restrictions between the parent bridge, CPU memory, and the 30117a12593SHiten Pandyadevice. 30217a12593SHiten PandyaMay be NULL, if no DMA restrictions are to be inherited. 30317a12593SHiten Pandya.It Fa alignment 30417a12593SHiten PandyaAlignment constraint, in bytes, of any mappings created using this tag. 30517a12593SHiten PandyaThe alignment must be a power of 2. 30617a12593SHiten PandyaHardware that can DMA starting at any address would specify 30717a12593SHiten Pandya.Em 1 30817a12593SHiten Pandyafor byte alignment. 30917a12593SHiten PandyaHardware requiring DMA transfers to start on a multiple of 4K 31017a12593SHiten Pandyawould specify 31117a12593SHiten Pandya.Em 4096 . 31217a12593SHiten Pandya.It Fa boundary 31317a12593SHiten PandyaBoundary constraint, in bytes, of the target DMA memory region. 31417a12593SHiten PandyaThe boundary indicates the set of addresses, all multiples of the 31517a12593SHiten Pandyaboundary argument, that cannot be crossed by a single 31617a12593SHiten Pandya.Vt bus_dma_segment_t . 31717a12593SHiten PandyaThe boundary must be either a power of 2 or 0. 31817a12593SHiten Pandya.Ql 0 31917a12593SHiten Pandyaindicates that there are no boundary restrictions. 32017a12593SHiten Pandya.It Fa lowaddr 32117a12593SHiten Pandya.It Fa highaddr 32217a12593SHiten PandyaBounds of the window of bus address space that 32317a12593SHiten Pandya.Em cannot 32417a12593SHiten Pandyabe directly accessed by the device. 32517a12593SHiten PandyaThe window contains all address greater than lowaddr and 32617a12593SHiten Pandyaless than or equal to highaddr. 32717a12593SHiten PandyaFor example, a device incapable of DMA above 4GB, would specify 32817a12593SHiten Pandyaa highaddr of 32917a12593SHiten Pandya.Dv BUS_SPACE_MAXADDR 33017a12593SHiten Pandyaand a lowaddr of 33117a12593SHiten Pandya.Dv BUS_SPACE_MAXADDR_32BIT . 3329a32a03aSSascha WildnerSimilarly a device that can only dma to addresses below 16MB would 33317a12593SHiten Pandyaspecify a highaddr of 33417a12593SHiten Pandya.Dv BUS_SPACE_MAXADDR 33517a12593SHiten Pandyaand a lowaddr of 33617a12593SHiten Pandya.Dv BUS_SPACE_MAXADDR_24BIT . 33717a12593SHiten PandyaSome implementations requires that some region of device visible 33817a12593SHiten Pandyaaddress space, overlapping available host memory, be outside the 33917a12593SHiten Pandyawindow. 34017a12593SHiten PandyaThis area of 34117a12593SHiten Pandya.Ql safe memory 34217a12593SHiten Pandyais used to bounce requests that would otherwise conflict with 34317a12593SHiten Pandyathe exclusion window. 34417a12593SHiten Pandya.It Fa maxsize 34517a12593SHiten PandyaMaximum size, in bytes, of the sum of all segment lengths in a given 34617a12593SHiten PandyaDMA mapping associated with this tag. 34717a12593SHiten Pandya.It Fa nsegments 34817a12593SHiten PandyaNumber of discontinuities (scatter/gather segments) allowed 34917a12593SHiten Pandyain a DMA mapped region. 35017a12593SHiten PandyaIf there is no restriction, 35117a12593SHiten Pandya.Dv BUS_SPACE_UNRESTRICTED 3521db4124bSSepherosa Ziehaumay be specified for the tag intended to be used as the parent. 3531db4124bSSepherosa Ziehau.Dv BUS_SPACE_UNRESTRICTED 3541db4124bSSepherosa Ziehaumust not be specified for the tags 3551db4124bSSepherosa Ziehauwhich will be used to create maps. 3561db4124bSSepherosa ZiehauFor tags which will be used to create maps, 357cf37dc20SSascha Wildnerthis argument must be less than 16384 on x86_64. 35817a12593SHiten Pandya.It Fa maxsegsz 35917a12593SHiten PandyaMaximum size, in bytes, of a segment in any DMA mapped region associated 36017a12593SHiten Pandyawith 36117a12593SHiten Pandya.Fa dmat . 36217a12593SHiten Pandya.It Fa flags 36317a12593SHiten PandyaAre as follows: 3649549a449SSascha Wildner.Bl -tag -width ".Dv BUS_DMA_PRIVBZONE" -compact 36517a12593SHiten Pandya.It Dv BUS_DMA_ALLOCNOW 3667c7d835fSSepherosa ZiehauAllocate the minimum resources necessary to guarantee that all map load 3677c7d835fSSepherosa Ziehauoperations associated with this tag may not block. 36817a12593SHiten PandyaIf sufficient resources are not available, 36917a12593SHiten Pandya.Er ENOMEM 37017a12593SHiten Pandyais returned. 3717c7d835fSSepherosa Ziehau.It Dv BUS_DMA_WAITOK 3727c7d835fSSepherosa ZiehauIndicates that it is OK to wait for resources. 3737c7d835fSSepherosa ZiehauHowever, 3747c7d835fSSepherosa Ziehauunlike 3757c7d835fSSepherosa Ziehau.Xr kmalloc 9 , 376d662f93cSSascha Wildnerit is not guaranteed that the resource allocation will succeed. 3777c7d835fSSepherosa ZiehauThis flag is the default one, 3787c7d835fSSepherosa Ziehauif 3797c7d835fSSepherosa Ziehau.Dv BUS_DMA_NOWAIT 3807c7d835fSSepherosa Ziehauis not supplied. 3817c7d835fSSepherosa Ziehau.It Dv BUS_DMA_NOWAIT 3827c7d835fSSepherosa ZiehauIf the resource allocation request cannot be immediately fulfilled, 3837c7d835fSSepherosa Ziehau.Er ENOMEM 3847c7d835fSSepherosa Ziehauis returned. 3857c7d835fSSepherosa Ziehau.It Dv BUS_DMA_ONEBPAGE 3867c7d835fSSepherosa ZiehauAllocte one bounce page at most, 3877c7d835fSSepherosa Ziehaueven if the 3887c7d835fSSepherosa Ziehau.Fa maxsize 3897c7d835fSSepherosa Ziehauindicates that multiple bounce pages are needed. 3907c7d835fSSepherosa Ziehau.It Dv BUS_DMA_ALIGNED 3917c7d835fSSepherosa ZiehauIndicates that all memory to be loaded into the DMA maps associated 3927c7d835fSSepherosa Ziehauwith this DMA tag is properly aligned according to 3937c7d835fSSepherosa Ziehau.Fa alignment 3947c7d835fSSepherosa Ziehauconstraint. 3957c7d835fSSepherosa ZiehauNo resources, 3967c7d835fSSepherosa Ziehaue.g. bounce pages, 3977c7d835fSSepherosa Ziehauwill be allocated due to the 3987c7d835fSSepherosa Ziehau.Fa alignment 3997c7d835fSSepherosa Ziehauconstraint. 4007c7d835fSSepherosa ZiehauIf unaligned memory was loaded into the DMA maps associated with this DMA tag, 4017c7d835fSSepherosa Ziehausystem will panic. 4029549a449SSascha Wildner.It Dv BUS_DMA_PRIVBZONE 4039549a449SSascha WildnerUses a private bounce zone instead of a shared one. 4049549a449SSascha WildnerA private bounce zone will vanish if the DMA tag is destroyed. 4059549a449SSascha Wildner.It Dv BUS_DMA_ALLOCALL 4069549a449SSascha WildnerAllocate all required resources (mainly the bounce buffer). 4079549a449SSascha WildnerIf any allocation fails, 4089549a449SSascha Wildner.Fn bus_dma_tag_create 4099549a449SSascha Wildnerfails. 4109549a449SSascha Wildner.It Dv BUS_DMA_PROTECTED 4119549a449SSascha WildnerAll of the functions called with the DMA tag are already protected by the 4129549a449SSascha Wildnercaller, so the 4139549a449SSascha Wildner.Nm 4149549a449SSascha Wildnercode need not protect the internal data structures. 41517a12593SHiten Pandya.El 41617a12593SHiten Pandya.It Fa dmat 41717a12593SHiten PandyaPointer to a bus_dma_tag_t where the resulting DMA tag will 41817a12593SHiten Pandyabe stored. 41917a12593SHiten Pandya.El 42017a12593SHiten Pandya.Pp 42117a12593SHiten PandyaReturns 42217a12593SHiten Pandya.Er ENOMEM 42317a12593SHiten Pandyaif sufficient memory is not available for tag creation 42417a12593SHiten Pandyaor allocating mapping resources. 42517a12593SHiten Pandya.It Fn bus_dma_tag_destroy "dmat" 42617a12593SHiten PandyaDeallocate the DMA tag 42717a12593SHiten Pandya.Fa dmat 42817a12593SHiten Pandyathat was created by 42917a12593SHiten Pandya.Fn bus_dma_tag_create . 43017a12593SHiten Pandya.Pp 43117a12593SHiten PandyaReturns 43217a12593SHiten Pandya.Er EBUSY 43317a12593SHiten Pandyaif any DMA maps remain associated with 43417a12593SHiten Pandya.Fa dmat 43517a12593SHiten Pandyaor 43617a12593SHiten Pandya.Ql 0 43717a12593SHiten Pandyaon success. 43817a12593SHiten Pandya.It Fn bus_dmamap_create "dmat" "flags" "*mapp" 43917a12593SHiten PandyaAllocates and initializes a DMA map. 44017a12593SHiten PandyaArguments are as follows: 44117a12593SHiten Pandya.Bl -tag -width nsegments -compact 44217a12593SHiten Pandya.It Fa dmat 44317a12593SHiten PandyaDMA tag. 44417a12593SHiten Pandya.It Fa flags 4457c7d835fSSepherosa ZiehauAre as follows: 446f54c32e1SSascha Wildner.Bl -tag -width ".Dv BUS_DMA_ONEBPAGE" -compact 4477c7d835fSSepherosa Ziehau.It Dv BUS_DMA_WAITOK 4487c7d835fSSepherosa ZiehauIndicates that it is OK to wait for resources. 4497c7d835fSSepherosa ZiehauHowever, 4507c7d835fSSepherosa Ziehauunlike 4517c7d835fSSepherosa Ziehau.Xr kmalloc 9 , 452d662f93cSSascha Wildnerit is not guaranteed that the resource allocation will succeed. 4537c7d835fSSepherosa ZiehauThis flag is the default one, 4547c7d835fSSepherosa Ziehauif 4557c7d835fSSepherosa Ziehau.Dv BUS_DMA_NOWAIT 4567c7d835fSSepherosa Ziehauis not supplied. 4577c7d835fSSepherosa Ziehau.It Dv BUS_DMA_NOWAIT 4587c7d835fSSepherosa ZiehauIf the resource allocation request cannot be immediately fulfilled, 4597c7d835fSSepherosa Ziehau.Er ENOMEM 4607c7d835fSSepherosa Ziehauis returned. 4617c7d835fSSepherosa Ziehau.It Dv BUS_DMA_ONEBPAGE 4627c7d835fSSepherosa ZiehauAllocte one bounce page at most, 4637c7d835fSSepherosa Ziehaueven if the 4647c7d835fSSepherosa Ziehau.Fa maxsize 4657c7d835fSSepherosa Ziehauused to create the 4667c7d835fSSepherosa Ziehau.Fa dmat 4677c7d835fSSepherosa Ziehauindicates that multiple bounce pages are needed. 4687c7d835fSSepherosa Ziehau.El 46917a12593SHiten Pandya.It Fa mapp 47017a12593SHiten PandyaPointer to a 47117a12593SHiten Pandya.Vt bus_dmamap_t 47217a12593SHiten Pandyawhere the resulting DMA map will be stored. 47317a12593SHiten Pandya.El 47417a12593SHiten Pandya.Pp 47517a12593SHiten PandyaReturns 47617a12593SHiten Pandya.Er ENOMEM 47717a12593SHiten Pandyaif sufficient memory is not available for creating the 47817a12593SHiten Pandyamap or allocating mapping resources. 47917a12593SHiten Pandya.It Fn bus_dmamap_destroy "dmat" "map" 48017a12593SHiten PandyaFrees all resources associated with a given DMA map. 48117a12593SHiten PandyaArguments are as follows: 48217a12593SHiten Pandya.Bl -tag -width dmat -compact 48317a12593SHiten Pandya.It Fa dmat 48417a12593SHiten PandyaDMA tag used to allocate 48517a12593SHiten Pandya.Fa map . 48617a12593SHiten Pandya.It Fa map 48717a12593SHiten PandyaThe DMA map to destroy. 48817a12593SHiten Pandya.El 48917a12593SHiten Pandya.Pp 49017a12593SHiten PandyaReturns 49117a12593SHiten Pandya.Er EBUSY 49217a12593SHiten Pandyaif a mapping is still active for 49317a12593SHiten Pandya.Fa map . 49417a12593SHiten Pandya.It Fn bus_dmamap_load "dmat" "map" "buf" "buflen" "*callback" "..." 49517a12593SHiten PandyaCreates a mapping in device visible address space of 49617a12593SHiten Pandya.Fa buflen 49717a12593SHiten Pandyabytes of 49817a12593SHiten Pandya.Fa buf , 49917a12593SHiten Pandyaassociated with the DMA map 50017a12593SHiten Pandya.Fa map . 50117a12593SHiten PandyaArguments are as follows: 50217a12593SHiten Pandya.Bl -tag -width buflen -compact 50317a12593SHiten Pandya.It Fa dmat 50417a12593SHiten PandyaDMA tag used to allocate 50517a12593SHiten Pandya.Fa map . 50617a12593SHiten Pandya.It Fa map 50717a12593SHiten PandyaA DMA map without a currently active mapping. 50817a12593SHiten Pandya.It Fa buf 50917a12593SHiten PandyaA kernel virtual address pointer to a contiguous (in KVA) buffer, to be 51017a12593SHiten Pandyamapped into device visible address space. 51117a12593SHiten Pandya.It Fa buflen 51217a12593SHiten PandyaThe size of the buffer. 51317a12593SHiten Pandya.It Fa callback Fa callback_arg 51417a12593SHiten PandyaThe callback function, and its argument. 51517a12593SHiten Pandya.It Fa flags 51617a12593SHiten PandyaThe value of this argument is currently undefined, and should be 51717a12593SHiten Pandyaspecified as 51817a12593SHiten Pandya.Ql 0 . 51917a12593SHiten Pandya.El 52017a12593SHiten Pandya.Pp 52117a12593SHiten PandyaReturn values to the caller are as follows: 522585a94afSSascha Wildner.Bl -tag -width ".Er EINPROGRESS" -compact 52317a12593SHiten Pandya.It 0 52417a12593SHiten PandyaThe callback has been called and completed. 52517a12593SHiten PandyaThe status of the mapping has been delivered to the callback. 52617a12593SHiten Pandya.It Er EINPROGRESS 52717a12593SHiten PandyaThe mapping has been deferred for lack of resources. 52817a12593SHiten PandyaThe callback will be called as soon as resources are available. 52917a12593SHiten PandyaCallbacks are serviced in FIFO order. 53017a12593SHiten PandyaDMA maps created from DMA tags that are allocated with 53117a12593SHiten Pandyathe 53217a12593SHiten Pandya.Dv BUS_DMA_ALLOCNOW 53317a12593SHiten Pandyaflag will never return this status for a load operation. 53417a12593SHiten Pandya.It Er EINVAL 53517a12593SHiten PandyaThe load request was invalid. 53617a12593SHiten PandyaThe callback has not, and will not be called. 53717a12593SHiten PandyaThis error value may indicate that 53817a12593SHiten Pandya.Fa dmat , 53917a12593SHiten Pandya.Fa map , 54017a12593SHiten Pandya.Fa buf , 54117a12593SHiten Pandyaor 54217a12593SHiten Pandya.Fa callback 54317a12593SHiten Pandyawere invalid, or 54417a12593SHiten Pandya.Fa buslen 54517a12593SHiten Pandyawas larger than the 54617a12593SHiten Pandya.Fa maxsize 54717a12593SHiten Pandyaargument used to create the dma tag 54817a12593SHiten Pandya.Fa dmat . 54917a12593SHiten Pandya.El 55017a12593SHiten Pandya.Pp 55117a12593SHiten PandyaWhen the callback is called, it is presented with an error value 55217a12593SHiten Pandyaindicating the disposition of the mapping. 55317a12593SHiten PandyaError may be one of the following: 554585a94afSSascha Wildner.Bl -tag -width ".Er EINPROGRESS" -compact 55517a12593SHiten Pandya.It 0 55617a12593SHiten PandyaThe mapping was successful and the 55717a12593SHiten Pandya.Fa dm_segs 55817a12593SHiten Pandyacallback argument contains an array of 55917a12593SHiten Pandya.Vt bus_dma_segment_t 56017a12593SHiten Pandyaelements describing the mapping. 56117a12593SHiten PandyaThis array is only valid during the scope of the callback function. 56217a12593SHiten Pandya.It Er EFBIG 56317a12593SHiten PandyaA mapping could not be achieved within the segment constraints provided 56417a12593SHiten Pandyain the tag even though the requested allocation size was less than maxsize. 56517a12593SHiten Pandya.El 566537b9048SSascha Wildner.It Fn bus_dmamap_load_ccb "dmat" "map" "ccb" "callback" "callback_arg" "flags" 567537b9048SSascha WildnerThis is a variation of 568537b9048SSascha Wildner.Fn bus_dmamap_load 569537b9048SSascha Wildnerwhich maps data pointed to by 570537b9048SSascha Wildner.Fa ccb 571537b9048SSascha Wildnerfor DMA transfers. 57217a12593SHiten Pandya.It Fn bus_dmamap_load_mbuf "dmat" "map" "mbuf" "callback2" "callback_arg" \ 57317a12593SHiten Pandya"flags" 57417a12593SHiten PandyaThis is a variation of 57517a12593SHiten Pandya.Fn bus_dmamap_load 57617a12593SHiten Pandyawhich maps mbuf chains 57717a12593SHiten Pandyafor DMA transfers. 57817a12593SHiten PandyaA 57917a12593SHiten Pandya.Vt bus_size_t 58017a12593SHiten Pandyaargument is also passed to the callback routine, which 58117a12593SHiten Pandyacontains the mbuf chain's packet header length. 58217a12593SHiten Pandya.Pp 58317a12593SHiten PandyaMbuf chains are assumed to be in kernel virtual address space. 58417a12593SHiten Pandya.Pp 58517a12593SHiten PandyaReturns 58617a12593SHiten Pandya.Er EINVAL 58717a12593SHiten Pandyaif the size of the mbuf chain exceeds the maximum limit of the 58817a12593SHiten PandyaDMA tag. 5897c7d835fSSepherosa Ziehau.It Fn bus_dmamap_load_mbuf_segment "dmat" "map" "mbuf" "*segs" "maxsegs" \ 5907c7d835fSSepherosa Ziehau"*nsegs" "flags" 5917c7d835fSSepherosa ZiehauIt is like 5927c7d835fSSepherosa Ziehau.Fn bus_dmamap_load_mbuf 5937c7d835fSSepherosa Ziehauwithout callback. 5947c7d835fSSepherosa ZiehauSegmentation information are saved in the 5957c7d835fSSepherosa Ziehau.Fa segs 5967c7d835fSSepherosa Ziehauand 5977c7d835fSSepherosa Ziehau.Fa nsegs 5987c7d835fSSepherosa Ziehauif the loading is successful. 5997c7d835fSSepherosa ZiehauThe 6007c7d835fSSepherosa Ziehau.Fa maxsegs , 6017c7d835fSSepherosa Ziehauwhich indicates the number of elements in the 6027c7d835fSSepherosa Ziehau.Fa segs , 60325140569SImre Vadászmust be set by the caller and must be at least 1 and at most equal the 6047c7d835fSSepherosa Ziehau.Fa nsegments 6057c7d835fSSepherosa Ziehauused to create the 6067c7d835fSSepherosa Ziehau.Fa dmat . 6077c7d835fSSepherosa ZiehauThe 6087c7d835fSSepherosa Ziehau.Fa flags 6097c7d835fSSepherosa Ziehaumust have 6107c7d835fSSepherosa Ziehau.Dv BUS_DMA_NOWAIT 6117c7d835fSSepherosa Ziehauturned on. 6127c7d835fSSepherosa Ziehau.Pp 6137c7d835fSSepherosa ZiehauThis function will not block. 6147c7d835fSSepherosa ZiehauWhen system is short of DMA resources, 6157c7d835fSSepherosa Ziehauthis function will return 6167c7d835fSSepherosa Ziehau.Er ENOMEM , 6177c7d835fSSepherosa Ziehauinstead of 6187c7d835fSSepherosa Ziehau.Er EINPROGRESS . 6197c7d835fSSepherosa Ziehau.It Fn bus_dmamap_load_mbuf_defrag "dmat" "map" "*mbuf" "*segs" "maxsegs" \ 6207c7d835fSSepherosa Ziehau"*nsegs" "flags" 6217c7d835fSSepherosa ZiehauThis function is like 6227c7d835fSSepherosa Ziehau.Fn bus_dmamap_load_mbuf_segment , 6237c7d835fSSepherosa Ziehaubut it will call 6247c7d835fSSepherosa Ziehau.Fn m_defrag 6257c7d835fSSepherosa Ziehauon the 6267c7d835fSSepherosa Ziehau.Fa *mbuf 6277c7d835fSSepherosa Ziehauand try reloading, 6287c7d835fSSepherosa Ziehauif low level code indicates too many fragments in the 6297c7d835fSSepherosa Ziehau.Fa *mbuf ; 6307c7d835fSSepherosa Ziehauthe 6317c7d835fSSepherosa Ziehau.Fa mbuf 6327c7d835fSSepherosa Ziehauwill be updated under this situation. 6337c7d835fSSepherosa ZiehauHowever, 6347c7d835fSSepherosa Ziehau.Fa *mbuf 6357c7d835fSSepherosa Ziehauwould not be freed by this function, 6367c7d835fSSepherosa Ziehaueven if 6377c7d835fSSepherosa Ziehau.Fn m_defrag 6387c7d835fSSepherosa Ziehaufailed. 6397c7d835fSSepherosa Ziehau.Pp 6407c7d835fSSepherosa ZiehauReturn 6417c7d835fSSepherosa Ziehau.Er ENOBUFS , 6427c7d835fSSepherosa Ziehauif the calling of 6437c7d835fSSepherosa Ziehau.Fn m_defrag 6447c7d835fSSepherosa Ziehaufailed. 64517a12593SHiten Pandya.It Fn bus_dmamap_load_uio "dmat" "map" "uio" "callback2" "callback_arg" "flags" 64617a12593SHiten PandyaThis is a variation of 64717a12593SHiten Pandya.Fn bus_dmamap_load 64817a12593SHiten Pandyawhich maps buffers pointed to by 64917a12593SHiten Pandya.Fa uio 65017a12593SHiten Pandyafor DMA transfers. 65117a12593SHiten PandyaA 65217a12593SHiten Pandya.Vt bus_size_t 65317a12593SHiten Pandyaargument is also passed to the callback routine, which contains the size of 65417a12593SHiten Pandya.Fa uio , 65517a12593SHiten Pandyai.e. 65617a12593SHiten Pandya.Fa uio->uio_resid . 65717a12593SHiten Pandya.Pp 65817a12593SHiten PandyaIf 65917a12593SHiten Pandya.Fa uio->uio_segflg 66017a12593SHiten Pandyais 66117a12593SHiten Pandya.Dv UIO_USERSPACE , 66217a12593SHiten Pandyathen it is assumed that the buffer, 66317a12593SHiten Pandya.Fa uio 66417a12593SHiten Pandyais in 66517a12593SHiten Pandya.Fa "uio->uio_td->td_proc" Ns 's 66617a12593SHiten Pandyaaddress space. 66717a12593SHiten PandyaUser space memory must be in-core and wired prior to attempting a map 66817a12593SHiten Pandyaload operation. 66917a12593SHiten Pandya.It Fn bus_dmamap_unload "dmat" "map" 67017a12593SHiten PandyaUnloads a DMA map. 67117a12593SHiten PandyaArguments are as follows: 67217a12593SHiten Pandya.Bl -tag -width dmam -compact 67317a12593SHiten Pandya.It Fa dmat 67417a12593SHiten PandyaDMA tag used to allocate 67517a12593SHiten Pandya.Fa map . 67617a12593SHiten Pandya.It Fa map 67717a12593SHiten PandyaThe DMA map that is to be unloaded. 67817a12593SHiten Pandya.El 67917a12593SHiten Pandya.Pp 68017a12593SHiten Pandya.Fn bus_dmamap_unload 68117a12593SHiten Pandyawill not perform any implicit synchronization of DMA buffers. 68217a12593SHiten PandyaThis must be done explicitly by a call to 68317a12593SHiten Pandya.Fn bus_dmamap_sync 68417a12593SHiten Pandyaprior to unloading the map. 68517a12593SHiten Pandya.It Fn bus_dmamap_sync "dmat" "map" "op" 68617a12593SHiten PandyaPerforms synchronization of a device visible mapping with the CPU visible 68717a12593SHiten Pandyamemory referenced by that mapping. 68817a12593SHiten PandyaArguments are as follows: 68917a12593SHiten Pandya.Bl -tag -width dmat -compact 69017a12593SHiten Pandya.It Fa dmat 69117a12593SHiten PandyaDMA tag used to allocate 69217a12593SHiten Pandya.Fa map . 69317a12593SHiten Pandya.It Fa map 69417a12593SHiten PandyaThe DMA mapping to be synchronized. 69517a12593SHiten Pandya.It Fa op 69617a12593SHiten PandyaType of synchronization operation to perform. 69717a12593SHiten PandyaSee the definition of 69817a12593SHiten Pandya.Vt bus_dmasync_op_t 69917a12593SHiten Pandyafor a description of the acceptable values for 70017a12593SHiten Pandya.Fa op . 70117a12593SHiten Pandya.El 70217a12593SHiten Pandya.Pp 70317a12593SHiten Pandya.Fn bus_dmamap_sync 70417a12593SHiten Pandyais the method used to ensure that CPU and device DMA access to shared 70517a12593SHiten Pandyamemory is coherent. 70617a12593SHiten PandyaFor example, the CPU might be used to setup the contents of a buffer 70717a12593SHiten Pandyathat is to be DMA'ed into a device. 70817a12593SHiten PandyaTo ensure that the data are visible via the device's mapping of that 70917a12593SHiten Pandyamemory, the buffer must be loaded and a dma sync operation of 71017a12593SHiten Pandya.Dv BUS_DMASYNC_PREREAD 71117a12593SHiten Pandyamust be performed. 71217a12593SHiten PandyaAdditional sync operations must be performed after every CPU write 71317a12593SHiten Pandyato this memory if additional DMA reads are to be performed. 71417a12593SHiten PandyaConversely, for the DMA write case, the buffer must be loaded, 71517a12593SHiten Pandyaand a dma sync operation of 71617a12593SHiten Pandya.Dv BUS_DMASYNC_PREWRITE 71717a12593SHiten Pandyamust be performed. 71817a12593SHiten PandyaThe CPU will only be able to see the results of this DMA write 71917a12593SHiten Pandyaonce the DMA has completed and a 72017a12593SHiten Pandya.Dv BUS_DMASYNC_POSTWRITE 72117a12593SHiten Pandyaoperation has been performed. 72217a12593SHiten Pandya.Pp 72317a12593SHiten PandyaIf DMA read and write operations are not preceded and followed by the 72417a12593SHiten Pandyaappropriate synchronization operations, behavior is undefined. 72517a12593SHiten Pandya.It Fn bus_dmamem_alloc "dmat" "**vaddr" "flags" "mapp" 72617a12593SHiten PandyaAllocates memory that is mapped into KVA at the address returned 72717a12593SHiten Pandyain 72817a12593SHiten Pandya.Fa vaddr 72917a12593SHiten Pandyathat is permanently loaded into the newly created 73017a12593SHiten Pandya.Vt bus_dmamap_t 73117a12593SHiten Pandyareturned via 73217a12593SHiten Pandya.Fa mapp . 73317a12593SHiten PandyaArguments are as follows: 73417a12593SHiten Pandya.Bl -tag -width alignment -compact 73517a12593SHiten Pandya.It Fa dmat 73617a12593SHiten PandyaDMA tag describing the constraints of the DMA mapping. 73717a12593SHiten Pandya.It Fa vaddr 73817a12593SHiten PandyaPointer to a pointer that will hold the returned KVA mapping of 73917a12593SHiten Pandyathe allocated region. 74017a12593SHiten Pandya.It Fa flags 74117a12593SHiten PandyaFlags are defined as follows: 74250f35324SSascha Wildner.Bl -tag -width ".Dv BUS_DMA_COHERENT" -compact 74317a12593SHiten Pandya.It Dv BUS_DMA_WAITOK 74417a12593SHiten PandyaThe routine can safely wait (sleep) for resources. 74517a12593SHiten Pandya.It Dv BUS_DMA_NOWAIT 74617a12593SHiten PandyaThe routine is not allowed to wait for resources. 74717a12593SHiten PandyaIf resources are not available, 7484a865848SSascha Wildner.Er ENOMEM 74917a12593SHiten Pandyais returned. 75017a12593SHiten Pandya.It Dv BUS_DMA_COHERENT 75117a12593SHiten PandyaAttempt to map this memory such that cache sync operations are 75217a12593SHiten Pandyaas cheap as possible. 75317a12593SHiten PandyaThis flag is typically set on memory that will be accessed by both 75417a12593SHiten Pandyaa CPU and a DMA engine, frequently. 75517a12593SHiten PandyaUse of this flag does not remove the requirement of using 75617a12593SHiten Pandyabus_dmamap_sync, but it may reduce the cost of performing 75717a12593SHiten Pandyathese operations. 75817a12593SHiten Pandya.It Dv BUS_DMA_ZERO 75917a12593SHiten PandyaCauses the allocated memory to be set to all zeros. 760fe8980dcSImre Vadász.It Dv BUS_DMA_NOCACHE 761fe8980dcSImre VadászThe allocated memory will not be cached in the processor caches. 762fe8980dcSImre VadászAll memory accesses appear on the bus and are executed 763fe8980dcSImre Vadászwithout reordering. 764fe8980dcSImre VadászOn x86_64, the 765fe8980dcSImre Vadász.Dv BUS_DMA_NOCACHE 766fe8980dcSImre Vadászflag results in the 767fe8980dcSImre VadászStrong Uncacheable PAT to be set for the allocated virtual address range. 76817a12593SHiten Pandya.El 76917a12593SHiten Pandya.It Fa mapp 77017a12593SHiten PandyaPointer to storage for the returned DMA map. 77117a12593SHiten Pandya.El 77217a12593SHiten Pandya.Pp 77317a12593SHiten PandyaThe size of memory to be allocated is 77417a12593SHiten Pandya.Fa maxsize 77517a12593SHiten Pandyaas specified in 77617a12593SHiten Pandya.Fa dmat . 77717a12593SHiten Pandya.Pp 77817a12593SHiten PandyaThe current implementation of 77917a12593SHiten Pandya.Fn bus_dmamem_alloc 78017a12593SHiten Pandyawill allocate all requests as a single segment. 78117a12593SHiten Pandya.Pp 78217a12593SHiten PandyaAlthough no explicit loading is required to access the memory 78317a12593SHiten Pandyareferenced by the returned map, the synchronization requirements 78417a12593SHiten Pandyaas described in the 78517a12593SHiten Pandya.Fn bus_dmamap_sync 78617a12593SHiten Pandyasection still apply. 78717a12593SHiten Pandya.Pp 78817a12593SHiten PandyaReturns 78917a12593SHiten Pandya.Er ENOMEM 79017a12593SHiten Pandyaif sufficient memory is not available for completing 79117a12593SHiten Pandyathe operation. 7927c7d835fSSepherosa Ziehau.It Fn bus_dmamem_coherent "parent" "alignment" "boundary" "lowaddr" \ 7937c7d835fSSepherosa Ziehau"highaddr" "maxsize" "flags" "*dmem" 7947c7d835fSSepherosa ZiehauThis is a convenient function to create one segment of DMA memory. 7957c7d835fSSepherosa ZiehauIt combines following 796265a1428SSascha Wildner.Nm 7977c7d835fSSepherosa Ziehaufunction calls: 7987c7d835fSSepherosa Ziehau.Bd -literal 7997c7d835fSSepherosa Ziehau bus_dma_tag_create(..., dtag); 8007c7d835fSSepherosa Ziehau bus_dmamem_alloc(*dtag, vaddr, ..., dmap); 8017c7d835fSSepherosa Ziehau bus_dmamap_load(*dtag, *dmap, *vaddr, ..., \\ 8027c7d835fSSepherosa Ziehau callback, busaddr, ...); 8037c7d835fSSepherosa Ziehau.Ed 8047c7d835fSSepherosa Ziehau.sp 8057c7d835fSSepherosa ZiehauThe final results of the above function calls are: 8067c7d835fSSepherosa ZiehauDMA tag, 8077c7d835fSSepherosa ZiehauDMA map, 8087c7d835fSSepherosa ZiehauDMA memory's kernel virtual address and 8097c7d835fSSepherosa Ziehauits device visible address. 8107c7d835fSSepherosa Ziehau.Fn bus_dmamem_coherent 8117c7d835fSSepherosa Ziehausaves the results in 8127c7d835fSSepherosa Ziehau.Fa *dmem . 8137c7d835fSSepherosa Ziehau.Pp 8147c7d835fSSepherosa ZiehauThe 8157c7d835fSSepherosa Ziehau.Fa parent , 8167c7d835fSSepherosa Ziehau.Fa alignment , 8177c7d835fSSepherosa Ziehau.Fa boundary , 8187c7d835fSSepherosa Ziehau.Fa lowaddr 8197c7d835fSSepherosa Ziehauand 8207c7d835fSSepherosa Ziehau.Fa highaddr 8217c7d835fSSepherosa Ziehauwill be passed to 8227c7d835fSSepherosa Ziehau.Fn bus_dma_tag_create 8237c7d835fSSepherosa Ziehauas they are. 8247c7d835fSSepherosa ZiehauThe 8257c7d835fSSepherosa Ziehau.Fa maxsize 8267c7d835fSSepherosa Ziehauwill be passed to 8277c7d835fSSepherosa Ziehau.Fn bus_dma_tag_create 8287c7d835fSSepherosa Ziehauas its 8297c7d835fSSepherosa Ziehau.Fa maxsize 8307c7d835fSSepherosa Ziehauand 8317c7d835fSSepherosa Ziehau.Fa maxsegsz 8327c7d835fSSepherosa Ziehauand 8337c7d835fSSepherosa Ziehau.Ql 1 8347c7d835fSSepherosa Ziehauwill be passed to 8357c7d835fSSepherosa Ziehau.Fn bus_dma_tag_create 8367c7d835fSSepherosa Ziehauas its 8377c7d835fSSepherosa Ziehau.Fa nsegments . 8387c7d835fSSepherosa ZiehauWhen 8397c7d835fSSepherosa Ziehau.Fn bus_dmamem_alloc 8407c7d835fSSepherosa Ziehauis called, 8417c7d835fSSepherosa Ziehau.Fa flags 8427c7d835fSSepherosa Ziehauwill be first or'ed with 8437c7d835fSSepherosa Ziehau.Dv BUS_DMA_COHERENT 8447c7d835fSSepherosa Ziehauthen passed to it. 8457c7d835fSSepherosa ZiehauThe final results of the above three functions, 8467c7d835fSSepherosa Ziehaui.e. DMA tag, 8477c7d835fSSepherosa ZiehauDMA map, 8487c7d835fSSepherosa ZiehauDMA memory's kernel virtual address and 8497c7d835fSSepherosa Ziehauits device visible address, 8507c7d835fSSepherosa Ziehauare saved in 8517c7d835fSSepherosa Ziehau.Fa *dmem . 8527c7d835fSSepherosa ZiehauIf any of the three functions failed, 8537c7d835fSSepherosa Ziehauthis function will return the error code and the 8547c7d835fSSepherosa Ziehau.Fa *dmem 8557c7d835fSSepherosa Ziehaushould not be used. 8567c7d835fSSepherosa Ziehau.It Fn bus_dmamem_coherent_any "parent" "alignment" "maxsize" "flags" \ 8577c7d835fSSepherosa Ziehau"*dtag" "*dmap" "*busaddr" 8587c7d835fSSepherosa ZiehauThis function is a simplified version of 8597c7d835fSSepherosa Ziehau.Fn bus_dmamem_coherent 8607c7d835fSSepherosa Ziehauwith 8617c7d835fSSepherosa Ziehauits 8627c7d835fSSepherosa Ziehau.Fa boundary 8637c7d835fSSepherosa Ziehauset to 8647c7d835fSSepherosa Ziehau.Ql 0 , 8657c7d835fSSepherosa Ziehau.Fa lowaddr 8667c7d835fSSepherosa Ziehauset to 8677c7d835fSSepherosa Ziehau.Dv BUS_SPACE_MAXADDR 8687c7d835fSSepherosa Ziehauand 8697c7d835fSSepherosa Ziehau.Fa highaddr 8707c7d835fSSepherosa Ziehauset to 8717c7d835fSSepherosa Ziehau.Dv BUS_SPACE_MAXADDR . 8727c7d835fSSepherosa ZiehauThe 8737c7d835fSSepherosa Ziehau.Fa parent 8747c7d835fSSepherosa Ziehauusually should not be NULL. 8757c7d835fSSepherosa Ziehau.Pp 8767c7d835fSSepherosa ZiehauReturn the DMA memory's kernel virtual address. 8777c7d835fSSepherosa ZiehauThe DMA tag, DMA map and device visible address are returned in 8787c7d835fSSepherosa Ziehau.Fa *dtag , 8797c7d835fSSepherosa Ziehau.Fa *dmap , 8807c7d835fSSepherosa Ziehauand 8817c7d835fSSepherosa Ziehau.Fa *busaddr . 8827c7d835fSSepherosa ZiehauIf this function failed, 8837c7d835fSSepherosa ZiehauNULL will be returned; 8847c7d835fSSepherosa Ziehau.Fa *dtag , 8857c7d835fSSepherosa Ziehau.Fa *dmap , 8867c7d835fSSepherosa Ziehauand 8877c7d835fSSepherosa Ziehau.Fa *busaddr 8887c7d835fSSepherosa Ziehauare left unchanged. 88917a12593SHiten Pandya.It Fn bus_dmamem_free "dmat" "*vaddr" "map" 89017a12593SHiten PandyaFrees memory previously allocated by 89117a12593SHiten Pandya.Fn bus_dmamem_alloc . 89217a12593SHiten PandyaAny mappings 89317a12593SHiten Pandyawill be invalidated. 89417a12593SHiten PandyaArguments are as follows: 89517a12593SHiten Pandya.Bl -tag -width vaddr -compact 89617a12593SHiten Pandya.It Fa dmat 89717a12593SHiten PandyaDMA tag. 89817a12593SHiten Pandya.It Fa vaddr 89917a12593SHiten PandyaKernel virtual address of the memory. 90017a12593SHiten Pandya.It Fa map 90117a12593SHiten PandyaDMA map to be invalidated. 90217a12593SHiten Pandya.El 90317a12593SHiten Pandya.El 90417a12593SHiten Pandya.Sh RETURN VALUES 90517a12593SHiten PandyaBehavior is undefined if invalid arguments are passed to 90617a12593SHiten Pandyaany of the above functions. 90717a12593SHiten PandyaIf sufficient resources cannot be allocated for a given 90817a12593SHiten Pandyatransaction, 90917a12593SHiten Pandya.Er ENOMEM 91017a12593SHiten Pandyais returned. 91117a12593SHiten PandyaAll 91217a12593SHiten Pandyaroutines that are not of type, 91317a12593SHiten Pandya.Vt void , 91417a12593SHiten Pandyawill return 0 on success or an error 91517a12593SHiten Pandyacode, as discussed above. 91617a12593SHiten Pandya.Pp 91717a12593SHiten PandyaAll 91817a12593SHiten Pandya.Vt void 91917a12593SHiten Pandyaroutines will succeed if provided with valid arguments. 92017a12593SHiten Pandya.Sh SEE ALSO 92117a12593SHiten Pandya.Xr devclass 9 , 92217a12593SHiten Pandya.Xr device 9 , 92317a12593SHiten Pandya.Xr driver 9 , 92417a12593SHiten Pandya.Xr rman 9 92517a12593SHiten Pandya.Rs 92617a12593SHiten Pandya.%A "Jason R. Thorpe" 92717a12593SHiten Pandya.%T "A Machine-Independent DMA Framework for NetBSD" 92817a12593SHiten Pandya.%J "Proceedings of the Summer 1998 USENIX Technical Conference" 92917a12593SHiten Pandya.%Q "USENIX Association" 93017a12593SHiten Pandya.%D "June 1998" 93117a12593SHiten Pandya.Re 93217a12593SHiten Pandya.Sh HISTORY 93317a12593SHiten PandyaThe 93417a12593SHiten Pandya.Nm 93517a12593SHiten Pandyainterface first appeared in 93617a12593SHiten Pandya.Nx 1.3 . 93717a12593SHiten Pandya.Pp 93817a12593SHiten PandyaThe 93917a12593SHiten Pandya.Nm 94017a12593SHiten PandyaAPI was adopted from 94117a12593SHiten Pandya.Nx 94217a12593SHiten Pandyafor use in the CAM SCSI subsystem. 94317a12593SHiten PandyaThe alterations to the original API were aimed to remove the need for 94417a12593SHiten Pandyaa 94517a12593SHiten Pandya.Vt bus_dma_segment_t 94617a12593SHiten Pandyaarray stored in each 94717a12593SHiten Pandya.Vt bus_dmamap_t 94817a12593SHiten Pandyawhile allowing callers to queue up on scarce resources. 94917a12593SHiten Pandya.Sh AUTHORS 95017a12593SHiten PandyaThe 95117a12593SHiten Pandya.Nm 95217a12593SHiten Pandyainterface was designed and implemented by 95317a12593SHiten Pandya.An Jason R. Thorpe 95417a12593SHiten Pandyaof the Numerical Aerospace Simulation Facility, NASA Ames Research Center. 95517a12593SHiten PandyaAdditional input on the 95617a12593SHiten Pandya.Nm 95717a12593SHiten Pandyadesign was provided by 95817a12593SHiten Pandya.An -nosplit 95917a12593SHiten Pandya.An Chris Demetriou , 96017a12593SHiten Pandya.An Charles Hannum , 96117a12593SHiten Pandya.An Ross Harvey , 96217a12593SHiten Pandya.An Matthew Jacob , 96317a12593SHiten Pandya.An Jonathan Stone , 96417a12593SHiten Pandyaand 96517a12593SHiten Pandya.An Matt Thomas . 96617a12593SHiten Pandya.Pp 96717a12593SHiten PandyaThis manual page was written by 96817a12593SHiten Pandya.An Hiten Pandya 96917a12593SHiten Pandyaand 97017a12593SHiten Pandya.An Justin T. Gibbs . 971