2 .\" Copyright (c) 2002 Sun Microsystems, Inc. All Rights Reserved.
3 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
4 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
5 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6 .TH DDI_DMA_BUF_BIND_HANDLE 9F "Jul 27, 1996"
8 ddi_dma_buf_bind_handle \- binds a system buffer to a DMA handle
13 #include <sys/sunddi.h>
17 \fBint\fR \fBddi_dma_buf_bind_handle\fR(\fBddi_dma_handle_t\fR \fIhandle\fR, \fBstruct buf *\fR\fIbp\fR,
18 \fBuint_t\fR \fIflags\fR, \fBint (*\fR\fIcallback\fR)(caddr_t), \fBcaddr_t\fR
19 \fIarg\fR, \fBddi_dma_cookie_t *\fR\fIcookiep\fR, \fBuint_t *\fR\fIccountp\fR);
25 Solaris DDI specific (Solaris DDI).
33 The \fBDMA\fR handle previously allocated by a call to
34 \fBddi_dma_alloc_handle\fR(9F).
43 A pointer to a system buffer structure (see \fBbuf\fR(9S)).
56 \fB\fBDDI_DMA_WRITE\fR\fR
59 Transfer direction is from memory to I/O
65 \fB\fBDDI_DMA_READ\fR\fR
68 Transfer direction is from I/O to memory
74 \fB\fBDDI_DMA_RDWR\fR\fR
83 \fB\fBDDI_DMA_REDZONE\fR\fR
86 Establish an \fBMMU\fR redzone at end of the object.
92 \fB\fBDDI_DMA_PARTIAL\fR\fR
95 Partial resource allocation
101 \fB\fBDDI_DMA_CONSISTENT\fR\fR
104 Nonsequential, random, and small block transfers.
110 \fB\fBDDI_DMA_STREAMING\fR\fR
113 Sequential, unidirectional, block-sized, and block-aligned transfers.
124 The address of a function to call back later if resources are not available
125 now. The following special function addresses may also be used.
129 \fB\fBDDI_DMA_SLEEP\fR\fR
132 Wait until resources are available.
138 \fB\fBDDI_DMA_DONTWAIT\fR\fR
141 Do not wait until resources are available and do not schedule a callback.
152 Argument to be passed to the callback function, \fIcallback\fR, if such a
153 function is specified.
162 A pointer to the first \fBddi_dma_cookie\fR(9S) structure.
171 Upon a successful return, \fIccountp\fR points to a value representing the
172 number of cookies for this \fBDMA\fR object.
178 \fBddi_dma_buf_bind_handle()\fR allocates \fBDMA\fR resources for a system
179 buffer such that a device can perform \fBDMA\fR to or from the buffer.
180 \fBDMA\fR resources are allocated considering the device's \fBDMA\fR attributes
181 as expressed by \fBddi_dma_attr\fR(9S) (see \fBddi_dma_alloc_handle\fR(9F)).
184 \fBddi_dma_buf_bind_handle()\fR fills in the first \fBDMA\fR cookie pointed to
185 by \fIcookiep\fR with the appropriate address, length, and bus type.
186 \fB*\fR\fIccountp\fR is set to the number of \fBDMA\fR cookies representing
187 this \fBDMA\fR object. Subsequent \fBDMA\fR cookies must be retrieved by
188 calling \fBddi_dma_nextcookie\fR(9F) \fB*\fR\fIcountp\fR-1 times.
191 When a \fBDMA\fR transfer completes, the driver should free up system \fBDMA\fR
192 resources by calling \fBddi_dma_unbind_handle\fR(9F).
195 The \fIflags\fR argument contains information for mapping routines.
199 \fB\fBDDI_DMA_WRITE\fR, \fBDDI_DMA_READ\fR, \fBDDI_DMA_RDWR\fR\fR
203 These flags describe the intended direction of the \fBDMA\fR transfer.
209 \fB\fBDDI_DMA_STREAMING\fR \fR
213 This flag should be set if the device is doing sequential, unidirectional,
214 block-sized, and block-aligned transfers to or from memory. The alignment and
215 padding constraints specified by the \fBminxfer\fR and \fBburstsizes\fR fields
216 in the \fBDMA\fR attribute structure, \fBddi_dma_attr\fR(9S) (see
217 \fBddi_dma_alloc_handle\fR(9F)) is used to allocate the most effective hardware
218 support for large transfers.
224 \fB\fBDDI_DMA_CONSISTENT\fR \fR
228 This flag should be set if the device accesses memory randomly, or if
229 synchronization steps using \fBddi_dma_sync\fR(9F) need to be as efficient as
230 possible. I/O parameter blocks used for communication between a device and a
231 driver should be allocated using \fBDDI_DMA_CONSISTENT\fR.
237 \fB\fBDDI_DMA_REDZONE\fR \fR
241 If this flag is set, the system attempts to establish a protected red zone
242 after the object. The \fBDMA\fR resource allocation functions do not guarantee
243 the success of this request as some implementations may not have the hardware
244 ability to support a red zone.
250 \fB\fBDDI_DMA_PARTIAL\fR \fR
254 Setting this flag indicates the caller can accept resources for part of the
255 object. That is, if the size of the object exceeds the resources available,
256 only resources for a portion of the object are allocated. The system indicates
257 this condition returning status \fBDDI_DMA_PARTIAL_MAP\fR. At a later point,
258 the caller can use \fBddi_dma_getwin\fR(9F) to change the valid portion of the
259 object for which resources are allocated. If resources were allocated for only
260 part of the object, \fBddi_dma_addr_bind_handle()\fR returns resources for the
261 first \fBDMA\fR window. Even when \fBDDI_DMA_PARTIAL\fR is set, the system may
262 decide to allocate resources for the entire object (less overhead) in which
263 case \fBDDI_DMA_MAPPED\fR is returned.
268 The callback function, \fIcallback\fR, indicates how a caller wants to handle
269 the possibility of resources not being available. If \fIcallback\fR is set to
270 \fBDDI_DMA_DONTWAIT\fR, the caller does not care if the allocation fails, and
271 can handle an allocation failure appropriately. If \fIcallback\fR is set to
272 \fBDDI_DMA_SLEEP\fR, the caller wishes to have the allocation routines wait for
273 resources to become available. If any other value is set, and a \fBDMA\fR
274 resource allocation fails, this value is assumed to be the address of a
275 function to call at a later time when resources may become available. When the
276 specified function is called, it is passed \fIarg\fR as an argument. The
277 specified callback function must return either \fBDDI_DMA_CALLBACK_RUNOUT\fR or
278 \fBDDI_DMA_CALLBACK_DONE\fR. \fBDDI_DMA_CALLBACK_RUNOUT\fR indicates that the
279 callback function attempted to allocate \fBDMA\fR resources but failed to do
280 so. In this case the callback function is put back on a list to be called again
281 later. \fBDDI_DMA_CALLBACK_DONE\fR indicates either a successful allocation of
282 \fBDMA\fR resources or that the driver no longer wishes to retry.
285 The callback function is called in interrupt context. Therefore, only system
286 functions accessible from interrupt context are be available. The callback
287 function must take whatever steps necessary to protect its critical resources,
288 data structures, queues, etc.
292 \fBddi_dma_buf_bind_handle()\fR returns:
296 \fB\fBDDI_DMA_MAPPED\fR\fR
299 Successfully allocated resources for the entire object.
305 \fB\fBDDI_DMA_PARTIAL_MAP\fR\fR
308 Successfully allocated resources for a part of the object. This is acceptable
309 when partial transfers are permitted by setting the \fBDDI_DMA_PARTIAL\fR flag
316 \fB\fBDDI_DMA_INUSE\fR\fR
319 Another I/O transaction is using the \fBDMA\fR handle.
325 \fB\fBDDI_DMA_NORESOURCES\fR\fR
328 No resources are available at the present time.
334 \fB\fBDDI_DMA_NOMAPPING\fR\fR
337 The object cannot be reached by the device requesting the resources.
343 \fB\fBDDI_DMA_TOOBIG\fR\fR
346 The object is too big. A request of this size can never be satisfied on this
347 particular system. The maximum size varies depending on machine and
354 \fBddi_dma_buf_bind_handle()\fR can be called from user, kernel, or interrupt
355 context, except when \fIcallback\fR is set to \fBDDI_DMA_SLEEP\fR, in which
356 case it can be called from user or kernel context only.
360 \fBddi_dma_addr_bind_handle\fR(9F), \fBddi_dma_alloc_handle\fR(9F),
361 \fBddi_dma_free_handle\fR(9F), \fBddi_dma_getwin\fR(9F),
362 \fBddi_dma_nextcookie\fR(9F), \fBddi_dma_sync\fR(9F),
363 \fBddi_dma_unbind_handle\fR(9F), \fBbuf\fR(9S), \fBddi_dma_attr\fR(9S),
364 \fBddi_dma_cookie\fR(9S)
367 \fIWriting Device Drivers\fR
371 If the driver permits partial mapping with the \fBDDI_DMA_PARTIAL\fR flag, the
372 number of cookies in each window may exceed the size of the device's
373 scatter/gather list as specified in the \fBdma_attr_sgllen\fR field in the
374 \fBddi_dma_attr\fR(9S) structure. In this case, each set of cookies comprising
375 a \fBDMA\fR window will satisfy the \fBDMA\fR attributes as described in the
376 \fBddi_dma_attr\fR(9S) structure in all aspects. The driver should set up its
377 \fBDMA\fR engine and perform one transfer for each set of cookies sufficient
378 for its scatter/gather list, up to the number of cookies for this window,
379 before advancing to the next window using \fBddi_dma_getwin\fR(9F).