1b36cfff7SJohn Baldwin.\" 2179fa75eSJohn Baldwin.\" Copyright (c) 2009 Hudson River Trading LLC 3b36cfff7SJohn Baldwin.\" Written by: John H. Baldwin <jhb@FreeBSD.org> 4b36cfff7SJohn Baldwin.\" All rights reserved. 5b36cfff7SJohn Baldwin.\" 6b36cfff7SJohn Baldwin.\" Redistribution and use in source and binary forms, with or without 7b36cfff7SJohn Baldwin.\" modification, are permitted provided that the following conditions 8b36cfff7SJohn Baldwin.\" are met: 9b36cfff7SJohn Baldwin.\" 1. Redistributions of source code must retain the above copyright 10b36cfff7SJohn Baldwin.\" notice, this list of conditions and the following disclaimer. 11b36cfff7SJohn Baldwin.\" 2. Redistributions in binary form must reproduce the above copyright 12b36cfff7SJohn Baldwin.\" notice, this list of conditions and the following disclaimer in the 13b36cfff7SJohn Baldwin.\" documentation and/or other materials provided with the distribution. 14b36cfff7SJohn Baldwin.\" 15b36cfff7SJohn Baldwin.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16b36cfff7SJohn Baldwin.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17b36cfff7SJohn Baldwin.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18b36cfff7SJohn Baldwin.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19b36cfff7SJohn Baldwin.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20b36cfff7SJohn Baldwin.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21b36cfff7SJohn Baldwin.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22b36cfff7SJohn Baldwin.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23b36cfff7SJohn Baldwin.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24b36cfff7SJohn Baldwin.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25b36cfff7SJohn Baldwin.\" SUCH DAMAGE. 26b36cfff7SJohn Baldwin.\" 276663f8a2SJohn Baldwin.Dd May 25, 2021 28b36cfff7SJohn Baldwin.Dt SGLIST 9 29b36cfff7SJohn Baldwin.Os 30b36cfff7SJohn Baldwin.Sh NAME 31b36cfff7SJohn Baldwin.Nm sglist , 32b36cfff7SJohn Baldwin.Nm sglist_alloc , 33b36cfff7SJohn Baldwin.Nm sglist_append , 34fb6c2518SBryan Venteicher.Nm sglist_append_bio , 35b36cfff7SJohn Baldwin.Nm sglist_append_mbuf , 3649b6b60eSGleb Smirnoff.Nm sglist_append_mbuf_epg , 37b36cfff7SJohn Baldwin.Nm sglist_append_phys , 3800f6cd3fSJohn Baldwin.Nm sglist_append_sglist , 396663f8a2SJohn Baldwin.Nm sglist_append_single_mbuf , 40b36cfff7SJohn Baldwin.Nm sglist_append_uio , 41b36cfff7SJohn Baldwin.Nm sglist_append_user , 4220fee109SJohn Baldwin.Nm sglist_append_vmpages , 43b36cfff7SJohn Baldwin.Nm sglist_build , 44b36cfff7SJohn Baldwin.Nm sglist_clone , 45b36cfff7SJohn Baldwin.Nm sglist_consume_uio , 46b36cfff7SJohn Baldwin.Nm sglist_count , 4749b6b60eSGleb Smirnoff.Nm sglist_count_mbuf_epg , 4820fee109SJohn Baldwin.Nm sglist_count_vmpages , 49b36cfff7SJohn Baldwin.Nm sglist_free , 50b36cfff7SJohn Baldwin.Nm sglist_hold , 51b36cfff7SJohn Baldwin.Nm sglist_init , 52b36cfff7SJohn Baldwin.Nm sglist_join , 53b36cfff7SJohn Baldwin.Nm sglist_length , 54b36cfff7SJohn Baldwin.Nm sglist_reset , 55b36cfff7SJohn Baldwin.Nm sglist_slice , 56b36cfff7SJohn Baldwin.Nm sglist_split 57b36cfff7SJohn Baldwin.Nd manage a scatter/gather list of physical memory addresses 58b36cfff7SJohn Baldwin.Sh SYNOPSIS 59b36cfff7SJohn Baldwin.In sys/types.h 60b36cfff7SJohn Baldwin.In sys/sglist.h 61b36cfff7SJohn Baldwin.Ft struct sglist * 62b36cfff7SJohn Baldwin.Fn sglist_alloc "int nsegs" "int mflags" 63b36cfff7SJohn Baldwin.Ft int 64b36cfff7SJohn Baldwin.Fn sglist_append "struct sglist *sg" "void *buf" "size_t len" 65b36cfff7SJohn Baldwin.Ft int 66fb6c2518SBryan Venteicher.Fn sglist_append_bio "struct sglist *sg" "struct bio *bp" 67fb6c2518SBryan Venteicher.Ft int 6849b6b60eSGleb Smirnoff.Fn sglist_append_mbuf_epg "struct sglist *sg" "struct mbuf *m" "size_t offset" "size_t len" 6982334850SJohn Baldwin.Ft int 70b36cfff7SJohn Baldwin.Fn sglist_append_mbuf "struct sglist *sg" "struct mbuf *m" 71b36cfff7SJohn Baldwin.Ft int 72b36cfff7SJohn Baldwin.Fn sglist_append_phys "struct sglist *sg" "vm_paddr_t paddr" "size_t len" 73b36cfff7SJohn Baldwin.Ft int 7400f6cd3fSJohn Baldwin.Fn sglist_append_sglist "struct sglist *sg" "struct sglist *source" "size_t offset" "size_t len" 7500f6cd3fSJohn Baldwin.Ft int 766663f8a2SJohn Baldwin.Fn sglist_append_single_mbuf "struct sglist *sg" "struct mbuf *m" 776663f8a2SJohn Baldwin.Ft int 78b36cfff7SJohn Baldwin.Fn sglist_append_uio "struct sglist *sg" "struct uio *uio" 79b36cfff7SJohn Baldwin.Ft int 80b36cfff7SJohn Baldwin.Fn sglist_append_user "struct sglist *sg" "void *buf" "size_t len" "struct thread *td" 8120fee109SJohn Baldwin.Ft int 8220fee109SJohn Baldwin.Fn sglist_append_vmpages "struct sglist *sg" "vm_page_t *m" "size_t pgoff" "size_t len" 83b36cfff7SJohn Baldwin.Ft struct sglist * 84b36cfff7SJohn Baldwin.Fn sglist_build "void *buf" "size_t len" "int mflags" 85b36cfff7SJohn Baldwin.Ft struct sglist * 86b36cfff7SJohn Baldwin.Fn sglist_clone "struct sglist *sg" "int mflags" 87b36cfff7SJohn Baldwin.Ft int 880cef25aeSJohn Baldwin.Fn sglist_consume_uio "struct sglist *sg" "struct uio *uio" "size_t resid" 89b36cfff7SJohn Baldwin.Ft int 90b36cfff7SJohn Baldwin.Fn sglist_count "void *buf" "size_t len" 9120fee109SJohn Baldwin.Ft int 9249b6b60eSGleb Smirnoff.Fn sglist_count_mbuf_epg "struct mbuf *m" "size_t offset" "size_t len" 9382334850SJohn Baldwin.Ft int 9420fee109SJohn Baldwin.Fn sglist_count_vmpages "vm_page_t *m" "size_t pgoff" "size_t len" 95b36cfff7SJohn Baldwin.Ft void 96b36cfff7SJohn Baldwin.Fn sglist_free "struct sglist *sg" 97b36cfff7SJohn Baldwin.Ft struct sglist * 98b36cfff7SJohn Baldwin.Fn sglist_hold "struct sglist *sg" 99b36cfff7SJohn Baldwin.Ft void 100b36cfff7SJohn Baldwin.Fn sglist_init "struct sglist *sg" "int maxsegs" "struct sglist_seg *segs" 101b36cfff7SJohn Baldwin.Ft int 102b36cfff7SJohn Baldwin.Fn sglist_join "struct sglist *first" "struct sglist *second" 103b36cfff7SJohn Baldwin.Ft size_t 104b36cfff7SJohn Baldwin.Fn sglist_length "struct sglist *sg" 105b36cfff7SJohn Baldwin.Ft void 106b36cfff7SJohn Baldwin.Fn sglist_reset "struct sglist *sg" 107b36cfff7SJohn Baldwin.Ft int 108b36cfff7SJohn Baldwin.Fn sglist_slice "struct sglist *original" "struct sglist **slice" "size_t offset" "size_t length" "int mflags" 109b36cfff7SJohn Baldwin.Ft int 110b36cfff7SJohn Baldwin.Fn sglist_split "struct sglist *original" "struct sglist **head" "size_t length" "int mflags" 111b36cfff7SJohn Baldwin.Sh DESCRIPTION 112b36cfff7SJohn BaldwinThe 113b36cfff7SJohn Baldwin.Nm 114b36cfff7SJohn BaldwinAPI manages physical address ranges. 115b36cfff7SJohn BaldwinEach list contains one or more elements. 116b36cfff7SJohn BaldwinEach element contains a starting physical address and a length. 117b36cfff7SJohn BaldwinScatter/gather lists are read-only while they are shared. 118b36cfff7SJohn BaldwinIf one wishes to alter an existing scatter/gather list and does not hold the 119b36cfff7SJohn Baldwinsole reference to the list, 120b36cfff7SJohn Baldwinthen one should create a new list instead of modifying the existing list. 121b36cfff7SJohn Baldwin.Pp 122b36cfff7SJohn BaldwinEach scatter/gather list object contains a reference count. 123b36cfff7SJohn BaldwinNew lists are created with a single reference. 124b36cfff7SJohn BaldwinNew references are obtained by calling 125b36cfff7SJohn Baldwin.Nm sglist_hold 126b36cfff7SJohn Baldwinand are released by calling 127b36cfff7SJohn Baldwin.Nm sglist_free . 128b36cfff7SJohn Baldwin.Ss Allocating and Initializing Lists 129b36cfff7SJohn BaldwinEach 130b36cfff7SJohn Baldwin.Nm 131b36cfff7SJohn Baldwinobject consists of a header structure and a variable-length array of 132b36cfff7SJohn Baldwinscatter/gather list elements. 133b36cfff7SJohn BaldwinThe 134b36cfff7SJohn Baldwin.Nm sglist_alloc 135b36cfff7SJohn Baldwinfunction allocates a new list that contains a header and 136b36cfff7SJohn Baldwin.Fa nsegs 137b36cfff7SJohn Baldwinscatter/gather list elements. 138b36cfff7SJohn BaldwinThe 139b36cfff7SJohn Baldwin.Fa mflags 140b36cfff7SJohn Baldwinargument can be set to either 141b36cfff7SJohn Baldwin.Dv M_NOWAIT 142b36cfff7SJohn Baldwinor 143b36cfff7SJohn Baldwin.Dv M_WAITOK . 144b36cfff7SJohn Baldwin.Pp 145b36cfff7SJohn BaldwinThe 146b36cfff7SJohn Baldwin.Nm sglist_count 147b36cfff7SJohn Baldwinfunction returns the number of scatter/gather list elements needed to describe 148b36cfff7SJohn Baldwinthe physical address ranges mapped by a single kernel virtual address range. 149b36cfff7SJohn BaldwinThe kernel virtual address range starts at 150b36cfff7SJohn Baldwin.Fa buf 151b36cfff7SJohn Baldwinand is 152b36cfff7SJohn Baldwin.Fa len 153b36cfff7SJohn Baldwinbytes long. 154b36cfff7SJohn Baldwin.Pp 155b36cfff7SJohn BaldwinThe 15649b6b60eSGleb Smirnoff.Nm sglist_count_mbuf_epg 15782334850SJohn Baldwinfunction returns the number of scatter/gather list elements needed to describe 15849b6b60eSGleb Smirnoffthe external multipage mbuf buffer 15949b6b60eSGleb Smirnoff.Fa m . 16082334850SJohn BaldwinThe ranges start at an offset of 16182334850SJohn Baldwin.Fa offset 16282334850SJohn Baldwinrelative to the start of the buffer and is 16382334850SJohn Baldwin.Fa len 16482334850SJohn Baldwinbytes long. 16582334850SJohn Baldwin.Pp 16682334850SJohn BaldwinThe 16720fee109SJohn Baldwin.Nm sglist_count_vmpages 16820fee109SJohn Baldwinfunction returns the number of scatter/gather list elements needed to describe 16920fee109SJohn Baldwinthe physical address ranges of a buffer backed by an array of virtual memory 17020fee109SJohn Baldwinpages 17120fee109SJohn Baldwin.Fa m . 17220fee109SJohn BaldwinThe buffer starts at an offset of 17320fee109SJohn Baldwin.Fa pgoff 17420fee109SJohn Baldwinbytes relative to the first page and is 17520fee109SJohn Baldwin.Fa len 17620fee109SJohn Baldwinbytes long. 17720fee109SJohn Baldwin.Pp 17820fee109SJohn BaldwinThe 179b36cfff7SJohn Baldwin.Nm sglist_build 180b36cfff7SJohn Baldwinfunction allocates a new scatter/gather list object that describes the physical 181b36cfff7SJohn Baldwinaddress ranges mapped by a single kernel virtual address range. 182b36cfff7SJohn BaldwinThe kernel virtual address range starts at 183b36cfff7SJohn Baldwin.Fa buf 184b36cfff7SJohn Baldwinand is 185b36cfff7SJohn Baldwin.Fa len 186b36cfff7SJohn Baldwinbytes long. 187b36cfff7SJohn BaldwinThe 188b36cfff7SJohn Baldwin.Fa mflags 189b36cfff7SJohn Baldwinargument can be set to either 190b36cfff7SJohn Baldwin.Dv M_NOWAIT 191b36cfff7SJohn Baldwinor 192b36cfff7SJohn Baldwin.Dv M_WAITOK . 193b36cfff7SJohn Baldwin.Pp 194b36cfff7SJohn BaldwinThe 195b36cfff7SJohn Baldwin.Nm sglist_clone 1969ba47352SJoel Dahlfunction returns a copy of an existing scatter/gather list object 197b36cfff7SJohn Baldwin.Fa sg . 198b36cfff7SJohn BaldwinThe 199b36cfff7SJohn Baldwin.Fa mflags 200b36cfff7SJohn Baldwinargument can be set to either 201b36cfff7SJohn Baldwin.Dv M_NOWAIT 202b36cfff7SJohn Baldwinor 203b36cfff7SJohn Baldwin.Dv M_WAITOK . 204b36cfff7SJohn BaldwinThis can be used to obtain a private copy of a scatter/gather list before 205b36cfff7SJohn Baldwinmodifying it. 206b36cfff7SJohn Baldwin.Pp 207b36cfff7SJohn BaldwinThe 208b36cfff7SJohn Baldwin.Nm sglist_init 209b36cfff7SJohn Baldwinfunction initializes a scatter/gather list header. 210b36cfff7SJohn BaldwinThe header is pointed to by 211b36cfff7SJohn Baldwin.Fa sg 212b36cfff7SJohn Baldwinand is initialized to manage an array of 213b36cfff7SJohn Baldwin.Fa maxsegs 214b36cfff7SJohn Baldwinscatter/gather list elements pointed to by 215b36cfff7SJohn Baldwin.Fa segs . 216b36cfff7SJohn BaldwinThis can be used to initialize a scatter/gather list header whose storage 217b36cfff7SJohn Baldwinis not provided by 218b36cfff7SJohn Baldwin.Nm sglist_alloc . 219b36cfff7SJohn BaldwinIn that case, the caller should not call 220b36cfff7SJohn Baldwin.Nm sglist_free 221b36cfff7SJohn Baldwinto release its own reference and is responsible for ensuring all other 222b36cfff7SJohn Baldwinreferences to the list are dropped before it releases the storage for 223b36cfff7SJohn Baldwin.Fa sg 224b36cfff7SJohn Baldwinand 225b36cfff7SJohn Baldwin.Fa segs . 226b36cfff7SJohn Baldwin.Ss Constructing Scatter/Gather Lists 227b36cfff7SJohn BaldwinThe 228b36cfff7SJohn Baldwin.Nm 229b36cfff7SJohn BaldwinAPI provides several routines for building a scatter/gather list to describe 230b36cfff7SJohn Baldwinone or more objects. 231b36cfff7SJohn BaldwinSpecifically, the 232b36cfff7SJohn Baldwin.Nm sglist_append 233b36cfff7SJohn Baldwinfamily of routines can be used to append the physical address ranges described 234b36cfff7SJohn Baldwinby an object to the end of a scatter/gather list. 235b36cfff7SJohn BaldwinAll of these routines return 0 on success or an error on failure. 236eb5a1e8fSJohn BaldwinIf a request to append an address range to a scatter/gather list fails, 237eb5a1e8fSJohn Baldwinthe scatter/gather list will remain unchanged. 238b36cfff7SJohn Baldwin.Pp 239b36cfff7SJohn BaldwinThe 240b36cfff7SJohn Baldwin.Nm sglist_append 241b36cfff7SJohn Baldwinfunction appends the physical address ranges described by a single kernel 242b36cfff7SJohn Baldwinvirtual address range to the scatter/gather list 243b36cfff7SJohn Baldwin.Fa sg . 244b36cfff7SJohn BaldwinThe kernel virtual address range starts at 245b36cfff7SJohn Baldwin.Fa buf 246b36cfff7SJohn Baldwinand is 247b36cfff7SJohn Baldwin.Fa len 248b36cfff7SJohn Baldwinbytes long. 249b36cfff7SJohn Baldwin.Pp 250b36cfff7SJohn BaldwinThe 251fb6c2518SBryan Venteicher.Nm sglist_append_bio 252fb6c2518SBryan Venteicherfunction appends the physical address ranges described by a single bio 253fb6c2518SBryan Venteicher.Fa bp 254fb6c2518SBryan Venteicherto the scatter/gather list 255fb6c2518SBryan Venteicher.Fa sg . 256fb6c2518SBryan Venteicher.Pp 257fb6c2518SBryan VenteicherThe 25849b6b60eSGleb Smirnoff.Nm sglist_append_mbuf_epg 25949b6b60eSGleb Smirnofffunction appends the physical address ranges described by the 26049b6b60eSGleb Smirnoffexternal multipage 26149b6b60eSGleb Smirnoff.Xr mbuf 9 26249b6b60eSGleb Smirnoffbuffer 26382334850SJohn Baldwin.Fa ext_pgs 26482334850SJohn Baldwinto the scatter/gather list 26582334850SJohn Baldwin.Fa sg . 26682334850SJohn BaldwinThe physical address ranges start at offset 26782334850SJohn Baldwin.Fa offset 26882334850SJohn Baldwinwithin 26982334850SJohn Baldwin.Fa ext_pgs 27082334850SJohn Baldwinand continue for 27182334850SJohn Baldwin.Fa len 27282334850SJohn Baldwinbytes. 27382334850SJohn BaldwinNote that unlike 27482334850SJohn Baldwin.Nm sglist_append_mbuf , 27549b6b60eSGleb Smirnoff.Nm sglist_append_mbuf_epg 27682334850SJohn Baldwinonly adds ranges for a single mbuf, 27782334850SJohn Baldwinnot an entire mbuf chain. 27882334850SJohn Baldwin.Pp 27982334850SJohn BaldwinThe 280b36cfff7SJohn Baldwin.Nm sglist_append_mbuf 281b36cfff7SJohn Baldwinfunction appends the physical address ranges described by an entire mbuf 282b36cfff7SJohn Baldwinchain 283b36cfff7SJohn Baldwin.Fa m 284b36cfff7SJohn Baldwinto the scatter/gather list 285b36cfff7SJohn Baldwin.Fa sg . 286b36cfff7SJohn Baldwin.Pp 287b36cfff7SJohn BaldwinThe 288*fd3d1367SDanilo Egea Gondolfo.Nm sglist_append_single_mbuf 2896663f8a2SJohn Baldwinfunction appends the physical address ranges described by a single mbuf 2906663f8a2SJohn Baldwin.Fa m 2916663f8a2SJohn Baldwinto the scatter/gather list 2926663f8a2SJohn Baldwin.Fa sg . 2936663f8a2SJohn Baldwin.Pp 2946663f8a2SJohn BaldwinThe 295b36cfff7SJohn Baldwin.Nm sglist_append_phys 296b36cfff7SJohn Baldwinfunction appends a single physical address range to the scatter/gather list 297b36cfff7SJohn Baldwin.Fa sg . 298b36cfff7SJohn BaldwinThe physical address range starts at 299b36cfff7SJohn Baldwin.Fa paddr 300b36cfff7SJohn Baldwinand is 301b36cfff7SJohn Baldwin.Fa len 302b36cfff7SJohn Baldwinbytes long. 303b36cfff7SJohn Baldwin.Pp 304b36cfff7SJohn BaldwinThe 30500f6cd3fSJohn Baldwin.Nm sglist_append_sglist 30600f6cd3fSJohn Baldwinfunction appends physical address ranges described by the scatter/gather list 30700f6cd3fSJohn Baldwin.Fa source 30800f6cd3fSJohn Baldwinto the scatter/gather list 30900f6cd3fSJohn Baldwin.Fa sg . 31000f6cd3fSJohn BaldwinThe physical address ranges start at offset 31100f6cd3fSJohn Baldwin.Fa offset 31200f6cd3fSJohn Baldwinwithin 31300f6cd3fSJohn Baldwin.Fa source 31400f6cd3fSJohn Baldwinand continue for 31500f6cd3fSJohn Baldwin.Fa len 31600f6cd3fSJohn Baldwinbytes. 31700f6cd3fSJohn Baldwin.Pp 31800f6cd3fSJohn BaldwinThe 319b36cfff7SJohn Baldwin.Nm sglist_append_uio 320b36cfff7SJohn Baldwinfunction appends the physical address ranges described by a 321b36cfff7SJohn Baldwin.Xr uio 9 322b36cfff7SJohn Baldwinobject to the scatter/gather list 323b36cfff7SJohn Baldwin.Fa sg . 324b36cfff7SJohn BaldwinNote that it is the caller's responsibility to ensure that the pages backing 325b36cfff7SJohn Baldwinthe I/O request are wired for the lifetime of 326b36cfff7SJohn Baldwin.Fa sg . 327b36cfff7SJohn BaldwinNote also that this routine does not modify 328b36cfff7SJohn Baldwin.Fa uio . 329b36cfff7SJohn Baldwin.Pp 330b36cfff7SJohn BaldwinThe 331b36cfff7SJohn Baldwin.Nm sglist_append_user 332b36cfff7SJohn Baldwinfunction appends the physical address ranges described by a single user 333b36cfff7SJohn Baldwinvirtual address range to the scatter/gather list 334b36cfff7SJohn Baldwin.Fa sg . 335b36cfff7SJohn BaldwinThe user virtual address range is relative to the address space of the thread 336b36cfff7SJohn Baldwin.Fa td . 337b36cfff7SJohn BaldwinIt starts at 338b36cfff7SJohn Baldwin.Fa buf 339b36cfff7SJohn Baldwinand is 340b36cfff7SJohn Baldwin.Fa len 341b36cfff7SJohn Baldwinbytes long. 342b36cfff7SJohn BaldwinNote that it is the caller's responsibility to ensure that the pages backing 343b36cfff7SJohn Baldwinthe user buffer are wired for the lifetime of 344b36cfff7SJohn Baldwin.Fa sg . 345b36cfff7SJohn Baldwin.Pp 346b36cfff7SJohn BaldwinThe 34720fee109SJohn Baldwin.Nm sglist_append_vmpages 34820fee109SJohn Baldwinfunction appends the physical address ranges of a buffer backed by an array 34920fee109SJohn Baldwinof virtual memory pages 35020fee109SJohn Baldwin.Fa m . 35120fee109SJohn BaldwinThe buffer starts at an offset of 35220fee109SJohn Baldwin.Fa pgoff 35320fee109SJohn Baldwinbytes relative to the first page and is 35420fee109SJohn Baldwin.Fa len 35520fee109SJohn Baldwinbytes long. 35620fee109SJohn Baldwin.Pp 35720fee109SJohn BaldwinThe 358b36cfff7SJohn Baldwin.Nm sglist_consume_uio 359b36cfff7SJohn Baldwinfunction is a variation of 360b36cfff7SJohn Baldwin.Nm sglist_append_uio . 361b36cfff7SJohn BaldwinAs with 362b36cfff7SJohn Baldwin.Nm sglist_append_uio , 363b36cfff7SJohn Baldwinit appends the physical address ranges described by 364b36cfff7SJohn Baldwin.Fa uio 365b36cfff7SJohn Baldwinto the scatter/gather list 366b36cfff7SJohn Baldwin.Fa sg . 367b36cfff7SJohn BaldwinUnlike 368b36cfff7SJohn Baldwin.Nm sglist_append_uio , 369b36cfff7SJohn Baldwinhowever, 370b36cfff7SJohn Baldwin.Nm sglist_consume_uio 371b36cfff7SJohn Baldwinmodifies the I/O request to indicate that the appended address ranges have 372b36cfff7SJohn Baldwinbeen processed similar to calling 373b36cfff7SJohn Baldwin.Xr uiomove 9 . 374b36cfff7SJohn BaldwinThis routine will only append ranges that describe up to 375b36cfff7SJohn Baldwin.Fa resid 376b36cfff7SJohn Baldwintotal bytes in length. 377b36cfff7SJohn BaldwinIf the available segments in the scatter/gather list are exhausted before 378b36cfff7SJohn Baldwin.Fa resid 379b36cfff7SJohn Baldwinbytes are processed, 380b36cfff7SJohn Baldwinthen the 381b36cfff7SJohn Baldwin.Fa uio 382b36cfff7SJohn Baldwinstructure will be updated to reflect the actual number of bytes processed, 383b36cfff7SJohn Baldwinand 384b36cfff7SJohn Baldwin.Nm sglist_consume_io 385b36cfff7SJohn Baldwinwill return zero to indicate success. 386b36cfff7SJohn BaldwinIn effect, this function will perform partial reads or writes. 387b36cfff7SJohn BaldwinThe caller can compare the 388b36cfff7SJohn Baldwin.Fa uio_resid 389b36cfff7SJohn Baldwinmember of 390b36cfff7SJohn Baldwin.Fa uio 391b36cfff7SJohn Baldwinbefore and after calling 392b36cfff7SJohn Baldwin.Nm sglist_consume_uio 393b36cfff7SJohn Baldwinto determine the actual number of bytes processed. 394b36cfff7SJohn Baldwin.Ss Manipulating Scatter/Gather Lists 395b36cfff7SJohn BaldwinThe 396b36cfff7SJohn Baldwin.Nm sglist_join 397b36cfff7SJohn Baldwinfunction appends physical address ranges from the scatter/gather list 398b36cfff7SJohn Baldwin.Fa second 399b36cfff7SJohn Baldwinonto 400b36cfff7SJohn Baldwin.Fa first 401b36cfff7SJohn Baldwinand then resets 402b36cfff7SJohn Baldwin.Fa second 403b36cfff7SJohn Baldwinto an empty list. 404b36cfff7SJohn BaldwinIt returns zero on success or an error on failure. 405b36cfff7SJohn Baldwin.Pp 406b36cfff7SJohn BaldwinThe 407b36cfff7SJohn Baldwin.Nm sglist_split 408b36cfff7SJohn Baldwinfunction splits an existing scatter/gather list into two lists. 409b36cfff7SJohn BaldwinThe first 410b36cfff7SJohn Baldwin.Fa length 411b36cfff7SJohn Baldwinbytes described by the list 412b36cfff7SJohn Baldwin.Fa original 413b36cfff7SJohn Baldwinare moved to a new list 414b36cfff7SJohn Baldwin.Fa *head . 415b36cfff7SJohn BaldwinIf 416b36cfff7SJohn Baldwin.Fa original 417b36cfff7SJohn Baldwindescribes a total address range that is smaller than 418b36cfff7SJohn Baldwin.Fa length 419b36cfff7SJohn Baldwinbytes, 420b36cfff7SJohn Baldwinthen all of the address ranges will be moved to the new list at 421b36cfff7SJohn Baldwin.Fa *head 422b36cfff7SJohn Baldwinand 423b36cfff7SJohn Baldwin.Fa original 424b36cfff7SJohn Baldwinwill be an empty list. 425b36cfff7SJohn BaldwinThe caller may supply an existing scatter/gather list in 426b36cfff7SJohn Baldwin.Fa *head . 427b36cfff7SJohn BaldwinIf so, the list must be empty. 428b36cfff7SJohn BaldwinOtherwise, the caller may set 429b36cfff7SJohn Baldwin.Fa *head 430b36cfff7SJohn Baldwinto 431b36cfff7SJohn Baldwin.Dv NULL 432b36cfff7SJohn Baldwinin which case a new scatter/gather list will be allocated. 433b36cfff7SJohn BaldwinIn that case, 434b36cfff7SJohn Baldwin.Fa mflags 435b36cfff7SJohn Baldwinmay be set to either 436b36cfff7SJohn Baldwin.Dv M_NOWAIT 437b36cfff7SJohn Baldwinor 438b36cfff7SJohn Baldwin.Dv M_WAITOK . 439b36cfff7SJohn BaldwinNote that since the 440b36cfff7SJohn Baldwin.Fa original 441b36cfff7SJohn Baldwinlist is modified by this call, it must be a private list with no other 442b36cfff7SJohn Baldwinreferences. 443b36cfff7SJohn BaldwinThe 444b36cfff7SJohn Baldwin.Nm sglist_split 445b36cfff7SJohn Baldwinfunction returns zero on success or an error on failure. 446b36cfff7SJohn Baldwin.Pp 447b36cfff7SJohn BaldwinThe 448b36cfff7SJohn Baldwin.Nm sglist_slice 449b36cfff7SJohn Baldwinfunction generates a new scatter/gather list from a sub-range of an existing 450b36cfff7SJohn Baldwinscatter/gather list 451b36cfff7SJohn Baldwin.Fa original . 452b36cfff7SJohn BaldwinThe sub-range to extract is specified by the 453b36cfff7SJohn Baldwin.Fa offset 454b36cfff7SJohn Baldwinand 455b36cfff7SJohn Baldwin.Fa length 456b36cfff7SJohn Baldwinparameters. 457b36cfff7SJohn BaldwinThe new scatter/gather list is stored in 458b36cfff7SJohn Baldwin.Fa *slice . 459b36cfff7SJohn BaldwinAs with 460b36cfff7SJohn Baldwin.Fa head 461b36cfff7SJohn Baldwinfor 462b36cfff7SJohn Baldwin.Nm sglist_join , 463b36cfff7SJohn Baldwinthe caller may either provide an empty scatter/gather list, 464b36cfff7SJohn Baldwinor it may set 465b36cfff7SJohn Baldwin.Fa *slice 466b36cfff7SJohn Baldwinto 467b36cfff7SJohn Baldwin.Dv NULL 468b36cfff7SJohn Baldwinin which case 469b36cfff7SJohn Baldwin.Nm sglist_slice 470b36cfff7SJohn Baldwinwill allocate a new list subject to 471b36cfff7SJohn Baldwin.Fa mflags . 472b36cfff7SJohn BaldwinUnlike 473b36cfff7SJohn Baldwin.Nm sglist_split , 474b36cfff7SJohn Baldwin.Nm sglist_slice 475b36cfff7SJohn Baldwindoes not modify 476b36cfff7SJohn Baldwin.Fa original 477b36cfff7SJohn Baldwinand does not require it to be a private list. 478b36cfff7SJohn BaldwinThe 479b36cfff7SJohn Baldwin.Nm sglist_split 480b36cfff7SJohn Baldwinfunction returns zero on success or an error on failure. 481b36cfff7SJohn Baldwin.Ss Miscellaneous Routines 482b36cfff7SJohn BaldwinThe 483b36cfff7SJohn Baldwin.Nm sglist_reset 484b36cfff7SJohn Baldwinfunction clears the scatter/gather list 485b36cfff7SJohn Baldwin.Fa sg 486b36cfff7SJohn Baldwinso that it no longer maps any address ranges. 487b36cfff7SJohn BaldwinThis can allow reuse of a single scatter/gather list object for multiple 488b36cfff7SJohn Baldwinrequests. 489b36cfff7SJohn Baldwin.Pp 490b36cfff7SJohn BaldwinThe 491b36cfff7SJohn Baldwin.Nm sglist_length 492b36cfff7SJohn Baldwinfunction returns the total length of the physical address ranges described 493b36cfff7SJohn Baldwinby the scatter/gather list 494b36cfff7SJohn Baldwin.Fa sg . 495b36cfff7SJohn Baldwin.Sh RETURN VALUES 496b36cfff7SJohn BaldwinThe 497b36cfff7SJohn Baldwin.Nm sglist_alloc , 498b36cfff7SJohn Baldwin.Nm sglist_build , 499b36cfff7SJohn Baldwinand 500b36cfff7SJohn Baldwin.Nm sglist_clone 501b36cfff7SJohn Baldwinfunctions return a new scatter/gather list on success or 502b36cfff7SJohn Baldwin.Dv NULL 503b36cfff7SJohn Baldwinon failure. 504b36cfff7SJohn Baldwin.Pp 505b36cfff7SJohn BaldwinThe 506b36cfff7SJohn Baldwin.Nm sglist_append 507b36cfff7SJohn Baldwinfamily of functions and the 508b36cfff7SJohn Baldwin.Nm sglist_consume_uio , 509b36cfff7SJohn Baldwin.Nm sglist_join , 510b36cfff7SJohn Baldwin.Nm sglist_slice , 511b36cfff7SJohn Baldwinand 512b36cfff7SJohn Baldwin.Nm sglist_split 513b36cfff7SJohn Baldwinfunctions return zero on success or an error on failure. 514b36cfff7SJohn Baldwin.Pp 515b36cfff7SJohn BaldwinThe 516b36cfff7SJohn Baldwin.Nm sglist_count 51782334850SJohn Baldwinfamily of 51820fee109SJohn Baldwinfunctions return a count of scatter/gather list elements. 519b36cfff7SJohn Baldwin.Pp 520b36cfff7SJohn BaldwinThe 521b36cfff7SJohn Baldwin.Nm sglist_length 522b36cfff7SJohn Baldwinfunction returns a count of address space described by a scatter/gather list 523b36cfff7SJohn Baldwinin bytes. 524b36cfff7SJohn Baldwin.Sh ERRORS 525b36cfff7SJohn BaldwinThe 526b36cfff7SJohn Baldwin.Nm sglist_append 527b36cfff7SJohn Baldwinfunctions return the following errors on failure: 528b36cfff7SJohn Baldwin.Bl -tag -width Er 529b36cfff7SJohn Baldwin.It Bq Er EINVAL 530b36cfff7SJohn BaldwinThe scatter/gather list has zero segments. 531b36cfff7SJohn Baldwin.It Bq Er EFBIG 532b36cfff7SJohn BaldwinThere are not enough available segments in the scatter/gather list to append 533b36cfff7SJohn Baldwinthe specified physical address ranges. 534b36cfff7SJohn Baldwin.El 535b36cfff7SJohn Baldwin.Pp 536b36cfff7SJohn BaldwinThe 537b36cfff7SJohn Baldwin.Nm sglist_consume_uio 538b36cfff7SJohn Baldwinfunction returns the following error on failure: 539b36cfff7SJohn Baldwin.Bl -tag -width Er 540b36cfff7SJohn Baldwin.It Bq Er EINVAL 541b36cfff7SJohn BaldwinThe scatter/gather list has zero segments. 542b36cfff7SJohn Baldwin.El 543b36cfff7SJohn Baldwin.Pp 544b36cfff7SJohn BaldwinThe 545b36cfff7SJohn Baldwin.Nm sglist_join 546b36cfff7SJohn Baldwinfunction returns the following error on failure: 547b36cfff7SJohn Baldwin.Bl -tag -width Er 548b36cfff7SJohn Baldwin.It Bq Er EFBIG 549b36cfff7SJohn BaldwinThere are not enough available segments in the scatter/gather list 550b36cfff7SJohn Baldwin.Fa first 551b36cfff7SJohn Baldwinto append the physical address ranges from 552b36cfff7SJohn Baldwin.Fa second . 553b36cfff7SJohn Baldwin.El 554eb5a1e8fSJohn Baldwin.Pp 555b36cfff7SJohn BaldwinThe 556b36cfff7SJohn Baldwin.Nm sglist_slice 557b36cfff7SJohn Baldwinfunction returns the following errors on failure: 558b36cfff7SJohn Baldwin.Bl -tag -width Er 559b36cfff7SJohn Baldwin.It Bq Er EINVAL 560b36cfff7SJohn BaldwinThe 561b36cfff7SJohn Baldwin.Fa original 562b36cfff7SJohn Baldwinscatter/gather list does not describe enough address space to cover the 563b36cfff7SJohn Baldwinrequested sub-range. 564b36cfff7SJohn Baldwin.It Bq Er EINVAL 565b36cfff7SJohn BaldwinThe caller-supplied scatter/gather list in 566b36cfff7SJohn Baldwin.Fa *slice 567b36cfff7SJohn Baldwinis not empty. 568b36cfff7SJohn Baldwin.It Bq Er ENOMEM 569b36cfff7SJohn BaldwinAn attempt to allocate a new scatter/gather list with 570b36cfff7SJohn Baldwin.Dv M_NOWAIT 571b36cfff7SJohn Baldwinset in 572b36cfff7SJohn Baldwin.Fa mflags 573b36cfff7SJohn Baldwinfailed. 574b36cfff7SJohn Baldwin.It Bq Er EFBIG 575b36cfff7SJohn BaldwinThere are not enough available segments in the caller-supplied scatter/gather 576b36cfff7SJohn Baldwinlist in 577b36cfff7SJohn Baldwin.Fa *slice 578b36cfff7SJohn Baldwinto describe the requested physical address ranges. 579b36cfff7SJohn Baldwin.El 580eb5a1e8fSJohn Baldwin.Pp 581b36cfff7SJohn BaldwinThe 582b36cfff7SJohn Baldwin.Nm sglist_split 583b36cfff7SJohn Baldwinfunction returns the following errors on failure: 584b36cfff7SJohn Baldwin.Bl -tag -width Er 585b36cfff7SJohn Baldwin.It Bq Er EDOOFUS 586b36cfff7SJohn BaldwinThe 587b36cfff7SJohn Baldwin.Fa original 588b36cfff7SJohn Baldwinscatter/gather list has more than one reference. 589b36cfff7SJohn Baldwin.It Bq Er EINVAL 590b36cfff7SJohn BaldwinThe caller-supplied scatter/gather list in 591b36cfff7SJohn Baldwin.Fa *head 592b36cfff7SJohn Baldwinis not empty. 593b36cfff7SJohn Baldwin.It Bq Er ENOMEM 594b36cfff7SJohn BaldwinAn attempt to allocate a new scatter/gather list with 595b36cfff7SJohn Baldwin.Dv M_NOWAIT 596b36cfff7SJohn Baldwinset in 597b36cfff7SJohn Baldwin.Fa mflags 598b36cfff7SJohn Baldwinfailed. 599b36cfff7SJohn Baldwin.It Bq Er EFBIG 600b36cfff7SJohn BaldwinThere are not enough available segments in the caller-supplied scatter/gather 601b36cfff7SJohn Baldwinlist in 602b36cfff7SJohn Baldwin.Fa *head 603b36cfff7SJohn Baldwinto describe the requested physical address ranges. 604b36cfff7SJohn Baldwin.El 605b36cfff7SJohn Baldwin.Sh SEE ALSO 606fb6c2518SBryan Venteicher.Xr g_bio 9 , 607b36cfff7SJohn Baldwin.Xr malloc 9 , 608b36cfff7SJohn Baldwin.Xr mbuf 9 , 609b36cfff7SJohn Baldwin.Xr uio 9 610b36cfff7SJohn Baldwin.Sh HISTORY 611b36cfff7SJohn BaldwinThis API was first introduced in 612b36cfff7SJohn Baldwin.Fx 8.0 . 613