sglist.h revision 193260
1184588Sdfr/*- 2197583Sjamie * Copyright (c) 2008 Yahoo!, Inc. 3197583Sjamie * All rights reserved. 4184588Sdfr * Written by: John Baldwin <jhb@FreeBSD.org> 5184588Sdfr * 6184588Sdfr * Redistribution and use in source and binary forms, with or without 7184588Sdfr * modification, are permitted provided that the following conditions 8184588Sdfr * are met: 9184588Sdfr * 1. Redistributions of source code must retain the above copyright 10184588Sdfr * notice, this list of conditions and the following disclaimer. 11184588Sdfr * 2. Redistributions in binary form must reproduce the above copyright 12184588Sdfr * notice, this list of conditions and the following disclaimer in the 13184588Sdfr * documentation and/or other materials provided with the distribution. 14197583Sjamie * 3. Neither the name of the author nor the names of any co-contributors 15184588Sdfr * may be used to endorse or promote products derived from this software 16184588Sdfr * without specific prior written permission. 17197583Sjamie * 18184588Sdfr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19184588Sdfr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20184588Sdfr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21184588Sdfr * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22184588Sdfr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23184588Sdfr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24184588Sdfr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25184588Sdfr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26197583Sjamie * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27197583Sjamie * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28197583Sjamie * SUCH DAMAGE. 29197583Sjamie * 30197583Sjamie * $FreeBSD: head/sys/sys/sglist.h 193260 2009-06-01 20:35:39Z jhb $ 31184588Sdfr */ 32197583Sjamie 33197583Sjamie/* 34197583Sjamie * A scatter/gather list describes a group of physical address ranges. 35197583Sjamie * Each physical address range consists of a starting address and a 36197583Sjamie * length. 37197583Sjamie */ 38197583Sjamie 39197583Sjamie#ifndef __SGLIST_H__ 40197583Sjamie#define __SGLIST_H__ 41197583Sjamie 42197583Sjamie#include <sys/refcount.h> 43197583Sjamie 44197583Sjamiestruct sglist_seg { 45197583Sjamie vm_paddr_t ss_paddr; 46197583Sjamie size_t ss_len; 47197583Sjamie}; 48197583Sjamie 49197583Sjamiestruct sglist { 50197583Sjamie struct sglist_seg *sg_segs; 51197583Sjamie int sg_refs; 52197583Sjamie u_short sg_nseg; 53197583Sjamie u_short sg_maxseg; 54197583Sjamie}; 55197583Sjamie 56197583Sjamiestruct mbuf; 57197583Sjamiestruct uio; 58197583Sjamie 59197583Sjamiestatic __inline void 60197583Sjamiesglist_init(struct sglist *sg, u_short maxsegs, struct sglist_seg *segs) 61197583Sjamie{ 62197583Sjamie 63184588Sdfr sg->sg_segs = segs; 64184588Sdfr sg->sg_nseg = 0; 65184588Sdfr sg->sg_maxseg = maxsegs; 66184588Sdfr refcount_init(&sg->sg_refs, 1); 67197583Sjamie} 68194239Srmacklem 69184588Sdfrstatic __inline void 70197583Sjamiesglist_reset(struct sglist *sg) 71184588Sdfr{ 72184588Sdfr 73184588Sdfr sg->sg_nseg = 0; 74184588Sdfr} 75197583Sjamie 76197583Sjamiestatic __inline struct sglist * 77197583Sjamiesglist_hold(struct sglist *sg) 78184588Sdfr{ 79197583Sjamie 80197583Sjamie refcount_acquire(&sg->sg_refs); 81184588Sdfr return (sg); 82197583Sjamie} 83184588Sdfr 84197583Sjamiestruct sglist *sglist_alloc(int nsegs, int mflags); 85197583Sjamieint sglist_append(struct sglist *sg, void *buf, size_t len); 86197583Sjamieint sglist_append_mbuf(struct sglist *sg, struct mbuf *m0); 87197583Sjamieint sglist_append_phys(struct sglist *sg, vm_paddr_t paddr, 88197583Sjamie size_t len); 89184588Sdfrint sglist_append_uio(struct sglist *sg, struct uio *uio); 90197583Sjamieint sglist_append_user(struct sglist *sg, void *buf, size_t len, 91197583Sjamie struct thread *td); 92197583Sjamiestruct sglist *sglist_build(void *buf, size_t len, int mflags); 93197583Sjamiestruct sglist *sglist_clone(struct sglist *sg, int mflags); 94184588Sdfrint sglist_consume_uio(struct sglist *sg, struct uio *uio, int resid); 95184588Sdfrint sglist_count(void *buf, size_t len); 96197583Sjamievoid sglist_free(struct sglist *sg); 97197583Sjamieint sglist_join(struct sglist *first, struct sglist *second); 98197583Sjamiesize_t sglist_length(struct sglist *sg); 99197583Sjamieint sglist_slice(struct sglist *original, struct sglist **slice, 100197583Sjamie size_t offset, size_t length, int mflags); 101197583Sjamieint sglist_split(struct sglist *original, struct sglist **head, 102197583Sjamie size_t length, int mflags); 103201145Santoine 104197583Sjamie#endif /* !__SGLIST_H__ */ 105197583Sjamie