9 #include <linux/export.h>
10 #include <linux/slab.h>
27 #ifdef CONFIG_DEBUG_SG
76 #ifndef ARCH_HAS_SG_CHAIN
86 #ifdef CONFIG_DEBUG_SG
106 memset(sgl, 0,
sizeof(*sgl) * nents);
107 #ifdef CONFIG_DEBUG_SG
110 for (i = 0; i < nents; i++)
114 sg_mark_end(&sgl[nents - 1]);
128 sg_set_buf(sg, buf, buflen);
155 static void sg_kfree(
struct scatterlist *
sg,
unsigned int nents)
187 unsigned int sg_size;
195 if (alloc_size > max_ents) {
197 alloc_size = max_ents;
198 sg_size = alloc_size - 1;
200 sg_size = alloc_size;
205 free_fn(sgl, alloc_size);
244 unsigned int max_ents,
gfp_t gfp_mask,
250 #ifndef ARCH_HAS_SG_CHAIN
254 memset(table, 0,
sizeof(*table));
259 unsigned int sg_size, alloc_size =
left;
261 if (alloc_size > max_ents) {
262 alloc_size = max_ents;
263 sg_size = alloc_size - 1;
265 sg_size = alloc_size;
269 sg = alloc_fn(alloc_size, gfp_mask);
291 sg_chain(prv, max_ents, sg);
299 sg_mark_end(&sg[sg_size - 1]);
324 gfp_mask, sg_kmalloc);
353 struct page **
pages,
unsigned int n_pages,
359 unsigned int cur_page;
365 for (i = 1; i < n_pages; ++
i)
376 unsigned long chunk_size;
380 for (j = cur_page + 1; j < n_pages; ++
j)
386 sg_set_page(s, pages[cur_page],
min(size, chunk_size), offset);
409 unsigned int nents,
unsigned int flags)
440 unsigned int off,
len;
498 flush_kernel_dcache_page(miter->
page);
526 static size_t sg_copy_buffer(
struct scatterlist *
sgl,
unsigned int nents,
546 len =
min(miter.length, buflen - offset);
549 memcpy(buf + offset, miter.addr, len);
551 memcpy(miter.addr, buf + offset, len);
573 void *buf,
size_t buflen)
575 return sg_copy_buffer(sgl, nents, buf, buflen, 0);
590 void *buf,
size_t buflen)
592 return sg_copy_buffer(sgl, nents, buf, buflen, 1);