1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
|
'\" te
.\" Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
.\" 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.
.\" 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.
.\" 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]
.TH DDI_DMA_ADDR_BIND_HANDLE 9F "Jan 18, 2020"
.SH NAME
ddi_dma_addr_bind_handle \- binds an address to a DMA handle
.SH SYNOPSIS
.nf
#include <sys/ddi.h>
#include <sys/sunddi.h>
\fBint\fR \fBddi_dma_addr_bind_handle\fR(\fBddi_dma_handle_t\fR \fIhandle\fR, \fBstruct as *\fR\fIas\fR,
\fBcaddr_t\fR \fIaddr\fR, \fBsize_t\fR \fIlen\fR, \fBuint_t\fR \fIflags\fR, \fBint (*\fR\fIcallback\fR) (caddr_t) ,
\fBcaddr_t\fR \fIarg\fR, \fBddi_dma_cookie_t *\fR\fIcookiep\fR, \fBuint_t *\fR\fIccountp\fR);
.fi
.SH INTERFACE LEVEL
illumos DDI specific (illumos DDI).
.SH PARAMETERS
.ne 2
.na
\fB\fIhandle\fR \fR
.ad
.RS 13n
The \fBDMA\fR handle previously allocated by a call to
\fBddi_dma_alloc_handle\fR(9F).
.RE
.sp
.ne 2
.na
\fB\fIas\fR \fR
.ad
.RS 13n
A pointer to an address space structure. This parameter should be set to
\fINULL\fR, which implies kernel address space.
.RE
.sp
.ne 2
.na
\fB\fIaddr\fR \fR
.ad
.RS 13n
Virtual address of the memory object.
.RE
.sp
.ne 2
.na
\fB\fIlen\fR \fR
.ad
.RS 13n
Length of the memory object in bytes.
.RE
.sp
.ne 2
.na
\fB\fIflags\fR \fR
.ad
.RS 13n
Valid flags include:
.sp
.ne 2
.na
\fB\fBDDI_DMA_WRITE\fR \fR
.ad
.RS 23n
Transfer direction is from memory to I/O.
.RE
.sp
.ne 2
.na
\fB\fBDDI_DMA_READ\fR \fR
.ad
.RS 23n
Transfer direction is from I/O to memory.
.RE
.sp
.ne 2
.na
\fB\fBDDI_DMA_RDWR\fR \fR
.ad
.RS 23n
Both read and write.
.RE
.sp
.ne 2
.na
\fB\fBDDI_DMA_REDZONE\fR \fR
.ad
.RS 23n
Establish an \fBMMU\fR redzone at end of the object.
.RE
.sp
.ne 2
.na
\fB\fBDDI_DMA_PARTIAL\fR \fR
.ad
.RS 23n
Partial resource allocation.
.RE
.sp
.ne 2
.na
\fB\fBDDI_DMA_CONSISTENT\fR \fR
.ad
.RS 23n
Nonsequential, random, and small block transfers.
.RE
.sp
.ne 2
.na
\fB\fBDDI_DMA_STREAMING\fR \fR
.ad
.RS 23n
Sequential, unidirectional, block-sized, and block-aligned transfers.
.RE
.RE
.sp
.ne 2
.na
\fB\fIcallback\fR \fR
.ad
.RS 13n
The address of a function to call back later if resources are not currently
available. The following special function addresses may also be used.
.sp
.ne 2
.na
\fB\fBDDI_DMA_SLEEP\fR \fR
.ad
.RS 21n
Wait until resources are available.
.RE
.sp
.ne 2
.na
\fB\fBDDI_DMA_DONTWAIT\fR \fR
.ad
.RS 21n
Do not wait until resources are available and do not schedule a callback.
.RE
.RE
.sp
.ne 2
.na
\fB\fIarg\fR \fR
.ad
.RS 13n
Argument to be passed to the callback function, \fIcallback\fR, if such a
function is specified.
.RE
.sp
.ne 2
.na
\fB\fIcookiep\fR \fR
.ad
.RS 13n
A pointer to the first \fBddi_dma_cookie\fR(9S) structure. This should
be left as \fBNULL\fR in new callers.
.RE
.sp
.ne 2
.na
\fB\fIccountp\fR \fR
.ad
.RS 13n
Upon a successful return, \fIccountp\fR points to a value representing the
number of cookies for this \fBDMA\fR object. This can
be left as \fBNULL\fR in new callers. The cookie count can be obtained
by calling \fBddi_dma_ncookies\fR(9F).
.RE
.SH DESCRIPTION
\fBddi_dma_addr_bind_handle()\fR allocates \fBDMA\fR resources for a memory
object such that a device can perform \fBDMA\fR to or from the object.
\fBDMA\fR resources are allocated considering the device's \fBDMA\fR attributes
as expressed by \fBddi_dma_attr\fR(9S) (see \fBddi_dma_alloc_handle\fR(9F)).
.sp
.LP
\fBddi_dma_addr_bind_handle()\fR allocates and associates a number of
\fBDMA\fR cookies with \fIhandle\fR. To get the total number of
cookies, callers should use the \fBddi_dma_ncookies\fR(9F) function. To
get all of the cookies, callers should use the
\fBddi_dma_cookie_iter\fR(9F) or \fBddi_dma_cookie_get\fR(9F) functions.
Callers should pass \fBNULL\fR for \fIcookiep\fR and \fIccountp\fR.
These values are required if using the deprecated
\fBddi_dma_nextcookie\fR(9F) interface, in which case \fIcookiep\fR is
filled in with the first \fBddi_dma_cookie\fR(9S) structure.
.sp
.LP
When a \fBDMA\fR transfer completes, the driver frees up system \fBDMA\fR
resources by calling \fBddi_dma_unbind_handle\fR(9F).
.sp
.LP
The \fIflags\fR argument contains information for mapping routines.
.sp
.ne 2
.na
\fB\fBDDI_DMA_WRITE\fR, \fBDDI_DMA_READ\fR, \fBDDI_DMA_RDWR\fR\fR
.ad
.sp .6
.RS 4n
These flags describe the intended direction of the \fBDMA\fR transfer.
.RE
.sp
.ne 2
.na
\fB\fBDDI_DMA_STREAMING\fR \fR
.ad
.sp .6
.RS 4n
This flag should be set if the device is doing sequential, unidirectional,
block-sized, and block-aligned transfers to or from memory. The alignment and
padding constraints specified by the \fBminxfer\fR and \fBburstsizes\fR fields
in the \fBDMA\fR attribute structure, \fBddi_dma_attr\fR(9S) (see
\fBddi_dma_alloc_handle\fR(9F)) is used to allocate the most effective hardware
support for large transfers.
.RE
.sp
.ne 2
.na
\fB\fBDDI_DMA_CONSISTENT\fR \fR
.ad
.sp .6
.RS 4n
This flag should be set if the device accesses memory randomly, or if
synchronization steps using \fBddi_dma_sync\fR(9F) need to be as efficient as
possible. I/O parameter blocks used for communication between a device and a
driver should be allocated using \fBDDI_DMA_CONSISTENT\fR.
.RE
.sp
.ne 2
.na
\fB\fBDDI_DMA_REDZONE\fR \fR
.ad
.sp .6
.RS 4n
If this flag is set, the system attempts to establish a protected red zone
after the object. The \fBDMA\fR resource allocation functions do not guarantee
the success of this request as some implementations may not have the hardware
ability to support a red zone.
.RE
.sp
.ne 2
.na
\fB\fBDDI_DMA_PARTIAL\fR \fR
.ad
.sp .6
.RS 4n
Setting this flag indicates the caller can accept resources for part of the
object. That is, if the size of the object exceeds the resources available,
only resources for a portion of the object are allocated. The system indicates
this condition by returning status \fBDDI_DMA_PARTIAL_MAP\fR. At a later point,
the caller can use \fBddi_dma_getwin\fR(9F) to change the valid portion of the
object for which resources are allocated. If resources were allocated for only
part of the object, \fBddi_dma_addr_bind_handle()\fR returns resources for the
first \fBDMA\fRwindow. Even when \fBDDI_DMA_PARTIAL\fR is set, the system may
decide to allocate resources for the entire object (less overhead) in which
case \fBDDI_DMA_MAPPED\fR is returned.
.RE
.sp
.LP
The callback function \fIcallback\fR indicates how a caller wants to handle the
possibility of resources not being available. If \fIcallback\fR is set to
\fBDDI_DMA_DONTWAIT\fR, the caller does not care if the allocation fails, and
can handle an allocation failure appropriately. If \fIcallback\fR is set to
\fBDDI_DMA_SLEEP\fR, the caller wishes to have the allocation routines wait for
resources to become available. If any other value is set and a \fBDMA\fR
resource allocation fails, this value is assumed to be the address of a
function to be called when resources become available. When the specified
function is called, \fIarg\fR is passed to it as an argument. The specified
callback function must return either \fBDDI_DMA_CALLBACK_RUNOUT\fR or
\fBDDI_DMA_CALLBACK_DONE\fR. \fBDDI_DMA_CALLBACK_RUNOUT\fR indicates that the
callback function attempted to allocate \fBDMA\fR resources but failed. In
this case, the callback function is put back on a list to be called again
later. \fBDDI_DMA_CALLBACK_DONE\fR indicates that either the allocation of
\fBDMA\fR resources was successful or the driver no longer wishes to retry.
.sp
.LP
The callback function is called in interrupt context. Therefore, only system
functions accessible from interrupt context are be available. The callback
function must take whatever steps are necessary to protect its critical
resources, data structures, queues, and so on.
.SH RETURN VALUES
\fBddi_dma_addr_bind_handle()\fR returns:
.sp
.ne 2
.na
\fB\fBDDI_DMA_MAPPED\fR \fR
.ad
.RS 24n
Successfully allocated resources for the entire object.
.RE
.sp
.ne 2
.na
\fB\fBDDI_DMA_PARTIAL_MAP\fR \fR
.ad
.RS 24n
Successfully allocated resources for a part of the object. This is acceptable
when partial transfers are permitted by setting the \fBDDI_DMA_PARTIAL\fR flag
in \fIflags\fR.
.RE
.sp
.ne 2
.na
\fB\fBDDI_DMA_INUSE\fR \fR
.ad
.RS 24n
Another I/O transaction is using the \fBDMA\fR handle.
.RE
.sp
.ne 2
.na
\fB\fBDDI_DMA_NORESOURCES\fR \fR
.ad
.RS 24n
No resources are available at the present time.
.RE
.sp
.ne 2
.na
\fB\fBDDI_DMA_NOMAPPING\fR \fR
.ad
.RS 24n
The object cannot be reached by the device requesting the resources.
.RE
.sp
.ne 2
.na
\fB\fBDDI_DMA_TOOBIG\fR \fR
.ad
.RS 24n
The object is too big. A request of this size can never be satisfied on this
particular system. The maximum size varies depending on machine and
configuration.
.RE
.SH CONTEXT
\fBddi_dma_addr_bind_handle()\fR can be called from user, kernel, or interrupt
context, except when \fIcallback\fR is set to \fBDDI_DMA_SLEEP\fR, in which
case it can only be called from user or kernel context.
.SH SEE ALSO
.BR ddi_dma_alloc_handle (9F),
.BR ddi_dma_cookie_get (9F),
.BR ddi_dma_cookie_iter (9F),
.BR ddi_dma_free_handle (9F),
.BR ddi_dma_getwin (9F),
.BR ddi_dma_mem_alloc (9F),
.BR ddi_dma_mem_free (9F),
.BR ddi_dma_ncookies (9F),
.BR ddi_dma_sync (9F),
.BR ddi_dma_unbind_handle (9F),
.BR ddi_umem_iosetup (9F),
.BR ddi_dma_attr (9S),
.BR ddi_dma_cookie (9S)
.sp
.LP
\fIWriting Device Drivers\fR
.SH NOTES
If the driver permits partial mapping with the \fBDDI_DMA_PARTIAL\fR flag, the
number of cookies in each window may exceed the size of the device's
scatter/gather list as specified in the \fBdma_attr_sgllen\fR field in the
\fBddi_dma_attr\fR(9S) structure. In this case, each set of cookies comprising
a \fBDMA\fR window will satisfy the \fBDMA\fR attributes as described in the
\fBddi_dma_attr\fR(9S) structure in all aspects. The driver should set up its
\fBDMA\fR engine and perform one transfer for each set of cookies sufficient
for its scatter/gather list, up to the number of cookies for this window,
before advancing to the next window using \fBddi_dma_getwin\fR(9F).
|