2 .\" Copyright (c) 2009 Advanced Computing Technologies LLC
3 .\" Written by: John H. Baldwin <jhb@FreeBSD.org>
4 .\" All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
15 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 .Nm sglist_append_mbuf ,
37 .Nm sglist_append_phys ,
38 .Nm sglist_append_uio ,
39 .Nm sglist_append_user ,
42 .Nm sglist_consume_uio ,
52 .Nd manage a scatter/gather list of physical memory addresses
57 .Fn sglist_alloc "int nsegs" "int mflags"
59 .Fn sglist_append "struct sglist *sg" "void *buf" "size_t len"
61 .Fn sglist_append_mbuf "struct sglist *sg" "struct mbuf *m"
63 .Fn sglist_append_phys "struct sglist *sg" "vm_paddr_t paddr" "size_t len"
65 .Fn sglist_append_uio "struct sglist *sg" "struct uio *uio"
67 .Fn sglist_append_user "struct sglist *sg" "void *buf" "size_t len" "struct thread *td"
69 .Fn sglist_build "void *buf" "size_t len" "int mflags"
71 .Fn sglist_clone "struct sglist *sg" "int mflags"
73 .Fn sglist_consume_uio "struct sglist *sg" "struct uio *uio" "size_t resid"
75 .Fn sglist_count "void *buf" "size_t len"
77 .Fn sglist_free "struct sglist *sg"
79 .Fn sglist_hold "struct sglist *sg"
81 .Fn sglist_init "struct sglist *sg" "int maxsegs" "struct sglist_seg *segs"
83 .Fn sglist_join "struct sglist *first" "struct sglist *second"
85 .Fn sglist_length "struct sglist *sg"
87 .Fn sglist_reset "struct sglist *sg"
89 .Fn sglist_slice "struct sglist *original" "struct sglist **slice" "size_t offset" "size_t length" "int mflags"
91 .Fn sglist_split "struct sglist *original" "struct sglist **head" "size_t length" "int mflags"
95 API manages physical address ranges.
96 Each list contains one or more elements.
97 Each element contains a starting physical address and a length.
98 Scatter/gather lists are read-only while they are shared.
99 If one wishes to alter an existing scatter/gather list and does not hold the
100 sole reference to the list,
101 then one should create a new list instead of modifying the existing list.
103 Each scatter/gather list object contains a reference count.
104 New lists are created with a single reference.
105 New references are obtained by calling
107 and are released by calling
109 .Ss Allocating and Initializing Lists
112 object consists of a header structure and a variable-length array of
113 scatter/gather list elements.
116 function allocates a new list that contains a header and
118 scatter/gather list elements.
121 argument can be set to either
128 function returns the number of scatter/gather list elements needed to describe
129 the physical address ranges mapped by a single kernel virtual address range.
130 The kernel virtual address range starts at
138 function allocates a new scatter/gather list object that describes the physical
139 address ranges mapped by a single kernel virtual address range.
140 The kernel virtual address range starts at
147 argument can be set to either
154 function returns a copy of an exising scatter/gather list object
158 argument can be set to either
162 This can be used to obtain a private copy of a scatter/gather list before
167 function initializes a scatter/gather list header.
168 The header is pointed to by
170 and is initialized to manage an array of
172 scatter/gather list elements pointed to by
174 This can be used to initialize a scatter/gather list header whose storage
177 In that case, the caller should not call
179 to release its own reference and is responsible for ensuring all other
180 references to the list are dropped before it releases the storage for
184 .Ss Constructing Scatter/Gather Lists
187 API provides several routines for building a scatter/gather list to describe
191 family of routines can be used to append the physical address ranges described
192 by an object to the end of a scatter/gather list.
193 All of these routines return 0 on success or an error on failure.
194 If a request to append an address range to a scatter/gather list fails,
195 the scatter/gather list will remain unchanged.
199 function appends the physical address ranges described by a single kernel
200 virtual address range to the scatter/gather list
202 The kernel virtual address range starts at
209 .Nm sglist_append_mbuf
210 function appends the physical address ranges described by an entire mbuf
213 to the scatter/gather list
217 .Nm sglist_append_phys
218 function appends a single physical address range to the scatter/gather list
220 The physical address range starts at
227 .Nm sglist_append_uio
228 function appends the physical address ranges described by a
230 object to the scatter/gather list
232 Note that it is the caller's responsibility to ensure that the pages backing
233 the I/O request are wired for the lifetime of
235 Note also that this routine does not modify
239 .Nm sglist_append_user
240 function appends the physical address ranges described by a single user
241 virtual address range to the scatter/gather list
243 The user virtual address range is relative to the address space of the thread
250 Note that it is the caller's responsibility to ensure that the pages backing
251 the user buffer are wired for the lifetime of
255 .Nm sglist_consume_uio
256 function is a variation of
257 .Nm sglist_append_uio .
259 .Nm sglist_append_uio ,
260 it appends the physical address ranges described by
262 to the scatter/gather list
265 .Nm sglist_append_uio ,
267 .Nm sglist_consume_uio
268 modifies the I/O request to indicate that the appended address ranges have
269 been processed similar to calling
271 This routine will only append ranges that describe up to
273 total bytes in length.
274 If the available segments in the scatter/gather list are exhausted before
279 structure will be updated to reflect the actual number of bytes processed,
281 .Nm sglist_consume_io
282 will return zero to indicate success.
283 In effect, this function will perform partial reads or writes.
284 The caller can compare the
288 before and after calling
289 .Nm sglist_consume_uio
290 to determine the actual number of bytes processed.
291 .Ss Manipulating Scatter/Gather Lists
294 function appends physical address ranges from the scatter/gather list
301 It returns zero on success or an error on failure.
305 function splits an existing scatter/gather list into two lists.
308 bytes described by the list
310 are moved to a new list
314 describes a total address range that is smaller than
317 then all of the address ranges will be moved to the new list at
321 will be an empty list.
322 The caller may supply an existing scatter/gather list in
324 If so, the list must be empty.
325 Otherwise, the caller may set
329 in which case a new scatter/gather list will be allocated.
338 list is modified by this call, it must be a private list with no other
342 function returns zero on success or an error on failure.
346 function generates a new scatter/gather list from a sub-range of an existing
349 The sub-range to extract is specified by the
354 The new scatter/gather list is stored in
360 the caller may either provide an empty scatter/gather list,
367 will allocate a new list subject to
374 and does not require it to be a private list.
377 function returns zero on success or an error on failure.
378 .Ss Miscellaneous Routines
381 function clears the scatter/gather list
383 so that it no longer maps any address ranges.
384 This can allow reuse of a single scatter/gather list object for multiple
389 function returns the total length of the physical address ranges described
390 by the scatter/gather list
398 functions return a new scatter/gather list on success or
404 family of functions and the
405 .Nm sglist_consume_uio ,
410 functions return zero on success or an error on failure.
414 function returns a count of scatter/gather list elements.
418 function returns a count of address space described by a scatter/gather list
423 functions return the following errors on failure:
426 The scatter/gather list has zero segments.
428 There are not enough available segments in the scatter/gather list to append
429 the specified physical address ranges.
433 .Nm sglist_consume_uio
434 function returns the following error on failure:
437 The scatter/gather list has zero segments.
442 function returns the following error on failure:
445 There are not enough available segments in the scatter/gather list
447 to append the physical address ranges from
453 function returns the following errors on failure:
458 scatter/gather list does not describe enough address space to cover the
461 The caller-supplied scatter/gather list in
465 An attempt to allocate a new scatter/gather list with
471 There are not enough available segments in the caller-supplied scatter/gather
474 to describe the requested physical address ranges.
479 function returns the following errors on failure:
484 scatter/gather list has more than one reference.
486 The caller-supplied scatter/gather list in
490 An attempt to allocate a new scatter/gather list with
496 There are not enough available segments in the caller-supplied scatter/gather
499 to describe the requested physical address ranges.
506 This API was first introduced in