Lines Matching full:sg
63 #define SGLIST_SAVE(sg, sgsave) do { \ argument
64 (sgsave).sg_nseg = (sg)->sg_nseg; \
66 (sgsave).ss_len = (sg)->sg_segs[(sgsave).sg_nseg - 1].ss_len; \
71 #define SGLIST_RESTORE(sg, sgsave) do { \ argument
72 (sg)->sg_nseg = (sgsave).sg_nseg; \
74 (sg)->sg_segs[(sgsave).sg_nseg - 1].ss_len = (sgsave).ss_len; \
78 * Append a single (paddr, len) to a sglist. sg is the list and ss is
83 _sglist_append_range(struct sglist *sg, struct sglist_seg **ssp, in _sglist_append_range() argument
92 if (sg->sg_nseg == sg->sg_maxseg) in _sglist_append_range()
97 sg->sg_nseg++; in _sglist_append_range()
108 _sglist_append_buf(struct sglist *sg, void *buf, size_t len, pmap_t pmap, in _sglist_append_buf() argument
130 if (sg->sg_nseg == 0) { in _sglist_append_buf()
131 ss = sg->sg_segs; in _sglist_append_buf()
134 sg->sg_nseg = 1; in _sglist_append_buf()
136 ss = &sg->sg_segs[sg->sg_nseg - 1]; in _sglist_append_buf()
137 error = _sglist_append_range(sg, &ss, paddr, seglen); in _sglist_append_buf()
152 error = _sglist_append_range(sg, &ss, paddr, seglen); in _sglist_append_buf()
283 struct sglist *sg; in sglist_alloc() local
285 sg = malloc(sizeof(struct sglist) + nsegs * sizeof(struct sglist_seg), in sglist_alloc()
287 if (sg == NULL) in sglist_alloc()
289 sglist_init(sg, nsegs, (struct sglist_seg *)(sg + 1)); in sglist_alloc()
290 return (sg); in sglist_alloc()
297 sglist_free(struct sglist *sg) in sglist_free() argument
300 if (sg == NULL) in sglist_free()
303 if (refcount_release(&sg->sg_refs)) in sglist_free()
304 free(sg, M_SGLIST); in sglist_free()
313 sglist_append(struct sglist *sg, void *buf, size_t len) in sglist_append() argument
318 if (sg->sg_maxseg == 0) in sglist_append()
320 SGLIST_SAVE(sg, save); in sglist_append()
321 error = _sglist_append_buf(sg, buf, len, NULL, NULL); in sglist_append()
323 SGLIST_RESTORE(sg, save); in sglist_append()
334 sglist_append_bio(struct sglist *sg, struct bio *bp) in sglist_append_bio() argument
339 error = sglist_append(sg, bp->bio_data, bp->bio_bcount); in sglist_append_bio()
341 error = sglist_append_vmpages(sg, bp->bio_ma, in sglist_append_bio()
351 sglist_append_phys(struct sglist *sg, vm_paddr_t paddr, size_t len) in sglist_append_phys() argument
357 if (sg->sg_maxseg == 0) in sglist_append_phys()
362 if (sg->sg_nseg == 0) { in sglist_append_phys()
363 sg->sg_segs[0].ss_paddr = paddr; in sglist_append_phys()
364 sg->sg_segs[0].ss_len = len; in sglist_append_phys()
365 sg->sg_nseg = 1; in sglist_append_phys()
368 ss = &sg->sg_segs[sg->sg_nseg - 1]; in sglist_append_phys()
369 SGLIST_SAVE(sg, save); in sglist_append_phys()
370 error = _sglist_append_range(sg, &ss, paddr, len); in sglist_append_phys()
372 SGLIST_RESTORE(sg, save); in sglist_append_phys()
381 sglist_append_mbuf_epg(struct sglist *sg, struct mbuf *m, size_t off, in sglist_append_mbuf_epg() argument
400 error = sglist_append(sg, in sglist_append_mbuf_epg()
418 error = sglist_append_phys(sg, paddr, seglen); in sglist_append_mbuf_epg()
424 error = sglist_append(sg, in sglist_append_mbuf_epg()
438 sglist_append_mbuf(struct sglist *sg, struct mbuf *m0) in sglist_append_mbuf() argument
444 if (sg->sg_maxseg == 0) in sglist_append_mbuf()
448 SGLIST_SAVE(sg, save); in sglist_append_mbuf()
452 error = sglist_append_mbuf_epg(sg, m, in sglist_append_mbuf()
455 error = sglist_append(sg, m->m_data, in sglist_append_mbuf()
458 SGLIST_RESTORE(sg, save); in sglist_append_mbuf()
472 sglist_append_single_mbuf(struct sglist *sg, struct mbuf *m) in sglist_append_single_mbuf() argument
475 return (sglist_append_mbuf_epg(sg, m, in sglist_append_single_mbuf()
478 return (sglist_append(sg, m->m_data, m->m_len)); in sglist_append_single_mbuf()
487 sglist_append_vmpages(struct sglist *sg, vm_page_t *m, size_t pgoff, in sglist_append_vmpages() argument
496 if (sg->sg_maxseg == 0) in sglist_append_vmpages()
501 SGLIST_SAVE(sg, save); in sglist_append_vmpages()
503 if (sg->sg_nseg == 0) { in sglist_append_vmpages()
505 sg->sg_segs[0].ss_paddr = VM_PAGE_TO_PHYS(m[0]) + pgoff; in sglist_append_vmpages()
506 sg->sg_segs[0].ss_len = seglen; in sglist_append_vmpages()
507 sg->sg_nseg = 1; in sglist_append_vmpages()
512 ss = &sg->sg_segs[sg->sg_nseg - 1]; in sglist_append_vmpages()
516 error = _sglist_append_range(sg, &ss, paddr, seglen); in sglist_append_vmpages()
518 SGLIST_RESTORE(sg, save); in sglist_append_vmpages()
532 sglist_append_user(struct sglist *sg, void *buf, size_t len, struct thread *td) in sglist_append_user() argument
537 if (sg->sg_maxseg == 0) in sglist_append_user()
539 SGLIST_SAVE(sg, save); in sglist_append_user()
540 error = _sglist_append_buf(sg, buf, len, in sglist_append_user()
543 SGLIST_RESTORE(sg, save); in sglist_append_user()
549 * the scatter/gather list 'sg'. If there are insufficient segments,
553 sglist_append_sglist(struct sglist *sg, struct sglist *source, size_t offset, in sglist_append_sglist() argument
561 if (sg->sg_maxseg == 0 || length == 0) in sglist_append_sglist()
563 SGLIST_SAVE(sg, save); in sglist_append_sglist()
565 ss = &sg->sg_segs[sg->sg_nseg - 1]; in sglist_append_sglist()
574 error = _sglist_append_range(sg, &ss, in sglist_append_sglist()
586 SGLIST_RESTORE(sg, save); in sglist_append_sglist()
596 sglist_append_uio(struct sglist *sg, struct uio *uio) in sglist_append_uio() argument
604 if (sg->sg_maxseg == 0) in sglist_append_uio()
618 SGLIST_SAVE(sg, save); in sglist_append_uio()
626 error = _sglist_append_buf(sg, iov[i].iov_base, minlen, in sglist_append_uio()
629 SGLIST_RESTORE(sg, save); in sglist_append_uio()
644 sglist_consume_uio(struct sglist *sg, struct uio *uio, size_t resid) in sglist_consume_uio() argument
651 if (sg->sg_maxseg == 0) in sglist_consume_uio()
677 error = _sglist_append_buf(sg, iov->iov_base, len, pmap, &done); in sglist_consume_uio()
696 struct sglist *sg; in sglist_build() local
703 sg = sglist_alloc(nsegs, mflags); in sglist_build()
704 if (sg == NULL) in sglist_build()
706 if (sglist_append(sg, buf, len) != 0) { in sglist_build()
707 sglist_free(sg); in sglist_build()
710 return (sg); in sglist_build()
717 sglist_clone(struct sglist *sg, int mflags) in sglist_clone() argument
721 if (sg == NULL) in sglist_clone()
723 new = sglist_alloc(sg->sg_maxseg, mflags); in sglist_clone()
726 new->sg_nseg = sg->sg_nseg; in sglist_clone()
727 bcopy(sg->sg_segs, new->sg_segs, sizeof(struct sglist_seg) * in sglist_clone()
728 sg->sg_nseg); in sglist_clone()
737 sglist_length(struct sglist *sg) in sglist_length() argument
743 for (i = 0; i < sg->sg_nseg; i++) in sglist_length()
744 space += sg->sg_segs[i].ss_len; in sglist_length()
769 struct sglist *sg; in sglist_split() local
800 sg = sglist_alloc(count, mflags); in sglist_split()
801 if (sg == NULL) in sglist_split()
803 *head = sg; in sglist_split()
805 sg = *head; in sglist_split()
806 if (sg->sg_maxseg < count) in sglist_split()
808 if (sg->sg_nseg != 0) in sglist_split()
812 /* Copy 'count' entries to 'sg' from 'original'. */ in sglist_split()
813 bcopy(original->sg_segs, sg->sg_segs, count * in sglist_split()
815 sg->sg_nseg = count; in sglist_split()
819 * 'sg' and the new first entry in 'original'. We also in sglist_split()
825 sg->sg_segs[count].ss_len -= split; in sglist_split()
827 sg->sg_segs[count].ss_paddr + split; in sglist_split()
900 struct sglist *sg; in sglist_slice() local
950 sg = sglist_alloc(count, mflags); in sglist_slice()
951 if (sg == NULL) in sglist_slice()
953 *slice = sg; in sglist_slice()
955 sg = *slice; in sglist_slice()
956 if (sg->sg_maxseg < count) in sglist_slice()
958 if (sg->sg_nseg != 0) in sglist_slice()
964 * 'fseg' to 'sg'. in sglist_slice()
966 bcopy(original->sg_segs + fseg, sg->sg_segs, in sglist_slice()
968 sg->sg_nseg = count; in sglist_slice()
972 sg->sg_segs[0].ss_paddr += foffs; in sglist_slice()
973 sg->sg_segs[0].ss_len -= foffs; in sglist_slice()
975 (long)sg->sg_segs[0].ss_paddr, sg->sg_segs[0].ss_len); in sglist_slice()
978 sg->sg_segs[count - 1].ss_len -= loffs; in sglist_slice()
980 sg->sg_segs[count - 1].ss_len); in sglist_slice()