scatterlist: add sg_alloc_table_from_pages function
Subsystems (2)
PATCH v4 1/1 scatterlist: add sg_alloc_table_from_pages function
This patch adds a new constructor for an sg table. The table is constructed from an array of struct pages. All contiguous chunks of the pages are merged into a single sg nodes. A user may provide an offset and a size of a buffer if the buffer is not page-aligned.
The function is dedicated for DMABUF exporters which often perform conversion from an page array to a scatterlist. Moreover the scatterlist should be squashed in order to save memory and to speed-up the process of DMA mapping using dma_map_sg.
The code is based on the patch 'v4l: vb2-dma-contig: add support for scatterlist in userptr mode' and hints from Laurent Pinchart.
---
v4:
- fix typos
- add Changelog
v3:
- use PFNs instead of page pointers to check contiguity
v2:
- rename sg_table_alloc_by_pages to sg_table_alloc_from_pages
- add some comments about error value
v1:
- initial version
--- include/linux/scatterlist.h | 4 +++ lib/scatterlist.c | 64 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+)
include/linux/scatterlist.h +4 -0
@@ -214,6 +214,10 @@ void sg_free_table(struct sg_table *);int __sg_alloc_table (struct sg_table *,unsigned int ,unsigned int ,gfp_t ,sg_alloc_fn *);int sg_alloc_table (struct sg_table *,unsigned int ,gfp_t ); +int sg_alloc_table_from_pages (struct sg_table *sgt, +struct page **pages,unsigned int n_pages, +unsigned long offset,unsigned long size, +gfp_t gfp_mask);size_t sg_copy_from_buffer (struct scatterlist *sgl,unsigned int nents,void *buf,size_t buflen);
lib/scatterlist.c +64 -0
70 lines not on this page · raw message
Signature · 1 line
1.7.9.5