sglist.h revision 345039
1193260Sjhb/*- 2193260Sjhb * Copyright (c) 2008 Yahoo!, Inc. 3193260Sjhb * All rights reserved. 4193260Sjhb * Written by: John Baldwin <jhb@FreeBSD.org> 5193260Sjhb * 6193260Sjhb * Redistribution and use in source and binary forms, with or without 7193260Sjhb * modification, are permitted provided that the following conditions 8193260Sjhb * are met: 9193260Sjhb * 1. Redistributions of source code must retain the above copyright 10193260Sjhb * notice, this list of conditions and the following disclaimer. 11193260Sjhb * 2. Redistributions in binary form must reproduce the above copyright 12193260Sjhb * notice, this list of conditions and the following disclaimer in the 13193260Sjhb * documentation and/or other materials provided with the distribution. 14193260Sjhb * 3. Neither the name of the author nor the names of any co-contributors 15193260Sjhb * may be used to endorse or promote products derived from this software 16193260Sjhb * without specific prior written permission. 17193260Sjhb * 18193260Sjhb * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19193260Sjhb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20193260Sjhb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21193260Sjhb * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22193260Sjhb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23193260Sjhb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24193260Sjhb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25193260Sjhb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26193260Sjhb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27193260Sjhb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28193260Sjhb * SUCH DAMAGE. 29193260Sjhb * 30193260Sjhb * $FreeBSD: stable/11/sys/sys/sglist.h 345039 2019-03-11 22:48:51Z jhb $ 31193260Sjhb */ 32193260Sjhb 33193260Sjhb/* 34193260Sjhb * A scatter/gather list describes a group of physical address ranges. 35193260Sjhb * Each physical address range consists of a starting address and a 36193260Sjhb * length. 37193260Sjhb */ 38193260Sjhb 39193260Sjhb#ifndef __SGLIST_H__ 40193260Sjhb#define __SGLIST_H__ 41193260Sjhb 42193260Sjhb#include <sys/refcount.h> 43193260Sjhb 44193260Sjhbstruct sglist_seg { 45193260Sjhb vm_paddr_t ss_paddr; 46193260Sjhb size_t ss_len; 47193260Sjhb}; 48193260Sjhb 49193260Sjhbstruct sglist { 50193260Sjhb struct sglist_seg *sg_segs; 51193260Sjhb int sg_refs; 52193260Sjhb u_short sg_nseg; 53193260Sjhb u_short sg_maxseg; 54193260Sjhb}; 55193260Sjhb 56260581Sbryanvstruct bio; 57193260Sjhbstruct mbuf; 58193260Sjhbstruct uio; 59193260Sjhb 60193260Sjhbstatic __inline void 61193260Sjhbsglist_init(struct sglist *sg, u_short maxsegs, struct sglist_seg *segs) 62193260Sjhb{ 63193260Sjhb 64193260Sjhb sg->sg_segs = segs; 65193260Sjhb sg->sg_nseg = 0; 66193260Sjhb sg->sg_maxseg = maxsegs; 67193260Sjhb refcount_init(&sg->sg_refs, 1); 68193260Sjhb} 69193260Sjhb 70193260Sjhbstatic __inline void 71193260Sjhbsglist_reset(struct sglist *sg) 72193260Sjhb{ 73193260Sjhb 74193260Sjhb sg->sg_nseg = 0; 75193260Sjhb} 76193260Sjhb 77193260Sjhbstatic __inline struct sglist * 78193260Sjhbsglist_hold(struct sglist *sg) 79193260Sjhb{ 80193260Sjhb 81193260Sjhb refcount_acquire(&sg->sg_refs); 82193260Sjhb return (sg); 83193260Sjhb} 84193260Sjhb 85193260Sjhbstruct sglist *sglist_alloc(int nsegs, int mflags); 86193260Sjhbint sglist_append(struct sglist *sg, void *buf, size_t len); 87260581Sbryanvint sglist_append_bio(struct sglist *sg, struct bio *bp); 88193260Sjhbint sglist_append_mbuf(struct sglist *sg, struct mbuf *m0); 89193260Sjhbint sglist_append_phys(struct sglist *sg, vm_paddr_t paddr, 90193260Sjhb size_t len); 91345039Sjhbint sglist_append_sglist(struct sglist *sg, struct sglist *source, 92345039Sjhb size_t offset, size_t length); 93193260Sjhbint sglist_append_uio(struct sglist *sg, struct uio *uio); 94193260Sjhbint sglist_append_user(struct sglist *sg, void *buf, size_t len, 95193260Sjhb struct thread *td); 96300337Sjhbint sglist_append_vmpages(struct sglist *sg, vm_page_t *m, size_t pgoff, 97300337Sjhb size_t len); 98193260Sjhbstruct sglist *sglist_build(void *buf, size_t len, int mflags); 99193260Sjhbstruct sglist *sglist_clone(struct sglist *sg, int mflags); 100196404Sjhbint sglist_consume_uio(struct sglist *sg, struct uio *uio, size_t resid); 101193260Sjhbint sglist_count(void *buf, size_t len); 102300337Sjhbint sglist_count_vmpages(vm_page_t *m, size_t pgoff, size_t len); 103193260Sjhbvoid sglist_free(struct sglist *sg); 104193260Sjhbint sglist_join(struct sglist *first, struct sglist *second); 105193260Sjhbsize_t sglist_length(struct sglist *sg); 106193260Sjhbint sglist_slice(struct sglist *original, struct sglist **slice, 107193260Sjhb size_t offset, size_t length, int mflags); 108193260Sjhbint sglist_split(struct sglist *original, struct sglist **head, 109193260Sjhb size_t length, int mflags); 110193260Sjhb 111193260Sjhb#endif /* !__SGLIST_H__ */ 112