Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1697824
| Path | csiph.com!news.redatomik.org!aioe.org!bofh.it!news.nic.it!robomod |
|---|---|
| From | Tvrtko Ursulin <tursulin@ursulin.net> |
| Newsgroups | linux.kernel |
| Subject | [PATCH 3/4] lib/scatterlist: Introduce and export __sg_alloc_table_from_pages |
| Date | Thu, 27 Jul 2017 11:10:02 +0200 |
| Message-ID | <u7MXU-4d2-19@gated-at.bofh.it> (permalink) |
| References | <u7MXU-4d2-11@gated-at.bofh.it> |
| Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=ursulin-net.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=GLti4BIVtm0Trs2h9+c72fw8Qud9RqjqeHU+sFbxr5I=; b=V5T1WhKXA8ARl+BLqhophvBw1sXa08fecSP+PRSymns3iD+8+jPsaFXAEaP4u9KBwa WeiOuuVU+zzkqD66ClF/egUThRS/dJ1zJxjXJmlTW8qJnMlzPsu+hGIuVNZlbtzT3VnH K9hJLyozYHAzqutSwxNLxw6453hek2SZ8JzoM2fnM5dwvlxjAJKzsHskPJuO36hXtZga eKzxsOs0fdp62oMfvtlLljHtfiOmOUdwFO+MdWRF4OUItvkb4KuAZfU1/uzBnKAokbBX v8yO2cQoToMCugWh+FOrMt7/collrQlNeumKh1p6xyO6BaMA8ccNHafM+qrWhzINAepT VSuQ== |
| X-Google-Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=GLti4BIVtm0Trs2h9+c72fw8Qud9RqjqeHU+sFbxr5I=; b=NPulVJ3tKGq9DDHYZthlkR4pKyO+t4bKN7jjxz8acspsKQOHhSvJvSDDofX6Dq/p4w oIODwV9xrsU/gG2XxFUvQDaNJztK05Mnfk6+VotcEbEvwhdXYkpUirbj/Xkvxu30oaZw r4WB+iJDB9iIXvxwxIngkPdbgu0tcuWBhcBvieu1r+suPKxl7HCB+x1nIDHiYTKJddbN pCkq9oGTR/6Lw+Gei99V3Ust/rYdKpjkqRReisS9yxbOo47YI+q/ejIhyDZ7T9b76fvw t6zdjY/a/9RA4dnGwnkctDUypZ4YAt40SN3aETacdbCbnOOL0CKFR5ZW6LzfR7HtRBGj I2Qw== |
| X-Gm-Message-State | AIVw111bxKITWyTR5YAK2w7kDxZn8P9ngl+3WAxUXIrikmYSDo5jwH+b 5I99NOh8WDAtyZOA |
| X-Received | by 10.223.136.178 with SMTP id f47mr3383387wrf.250.1501146313817; Thu, 27 Jul 2017 02:05:13 -0700 (PDT) |
| X-Google-Original-From | Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com> |
| X-Mailer | git-send-email 2.9.4 |
| Sender | robomod@news.nic.it |
| List-ID | <linux-kernel.vger.kernel.org> |
| X-Mailing-List | linux-kernel@vger.kernel.org |
| Approved | robomod@news.nic.it |
| Lines | 138 |
| Organization | linux.* mail to news gateway |
| X-Original-Cc | Ben Widawsky <benjamin.widawsky@intel.com>, Jason Ekstrand <jason@jlekstrand.net>, Tvrtko Ursulin <tvrtko.ursulin@intel.com>, Masahiro Yamada <yamada.masahiro@socionext.com>, linux-kernel@vger.kernel.org, Chris Wilson <chris@chris-wilson.co.uk>, Joonas Lahtinen <joonas.lahtinen@linux.intel.com> |
| X-Original-Date | Thu, 27 Jul 2017 10:05:03 +0100 |
| X-Original-Message-ID | <20170727090504.15812-4-tvrtko.ursulin@linux.intel.com> |
| X-Original-References | <20170727090504.15812-1-tvrtko.ursulin@linux.intel.com> |
| X-Original-Sender | linux-kernel-owner@vger.kernel.org |
| Xref | csiph.com linux.kernel:1697824 |
Show key headers only | View raw
From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Drivers like i915 benefit from being able to control the maxium
size of the sg coallesced segment while building the scatter-
gather list.
Introduce and export the __sg_alloc_table_from_pages function
which will allow it that control.
v2: Reorder parameters. (Chris Wilson)
v3: Fix incomplete reordering in v2.
v4: max_segment needs to be page aligned.
v5: Rebase.
v6: Rebase.
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: linux-kernel@vger.kernel.org
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk> (v2)
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
---
include/linux/scatterlist.h | 11 +++++----
lib/scatterlist.c | 58 +++++++++++++++++++++++++++++++++++----------
2 files changed, 52 insertions(+), 17 deletions(-)
diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
index 6dd2ddbc6230..874b50c232de 100644
--- a/include/linux/scatterlist.h
+++ b/include/linux/scatterlist.h
@@ -267,10 +267,13 @@ void sg_free_table(struct sg_table *);
int __sg_alloc_table(struct sg_table *, unsigned int, unsigned int,
struct scatterlist *, 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 int offset, unsigned long size,
- gfp_t gfp_mask);
+int __sg_alloc_table_from_pages(struct sg_table *sgt, struct page **pages,
+ unsigned int n_pages, unsigned int offset,
+ unsigned long size, unsigned int max_segment,
+ gfp_t gfp_mask);
+int sg_alloc_table_from_pages(struct sg_table *sgt, struct page **pages,
+ unsigned int n_pages, unsigned int offset,
+ unsigned long size, gfp_t gfp_mask);
size_t sg_copy_buffer(struct scatterlist *sgl, unsigned int nents, void *buf,
size_t buflen, off_t skip, bool to_buffer);
diff --git a/lib/scatterlist.c b/lib/scatterlist.c
index 7b2e74da2c44..1a5900f9a057 100644
--- a/lib/scatterlist.c
+++ b/lib/scatterlist.c
@@ -370,14 +370,15 @@ int sg_alloc_table(struct sg_table *table, unsigned int nents, gfp_t gfp_mask)
EXPORT_SYMBOL(sg_alloc_table);
/**
- * sg_alloc_table_from_pages - Allocate and initialize an sg table from
- * an array of pages
- * @sgt: The sg table header to use
- * @pages: Pointer to an array of page pointers
- * @n_pages: Number of pages in the pages array
- * @offset: Offset from start of the first page to the start of a buffer
- * @size: Number of valid bytes in the buffer (after offset)
- * @gfp_mask: GFP allocation mask
+ * __sg_alloc_table_from_pages - Allocate and initialize an sg table from
+ * an array of pages
+ * @sgt: The sg table header to use
+ * @pages: Pointer to an array of page pointers
+ * @n_pages: Number of pages in the pages array
+ * @offset: Offset from start of the first page to the start of a buffer
+ * @size: Number of valid bytes in the buffer (after offset)
+ * @max_segment: Maximum size of a scatterlist node in bytes (page aligned)
+ * @gfp_mask: GFP allocation mask
*
* Description:
* Allocate and initialize an sg table from a list of pages. Contiguous
@@ -389,16 +390,18 @@ EXPORT_SYMBOL(sg_alloc_table);
* Returns:
* 0 on success, negative error on failure
*/
-int sg_alloc_table_from_pages(struct sg_table *sgt,
- struct page **pages, unsigned int n_pages,
- unsigned int offset, unsigned long size,
- gfp_t gfp_mask)
+int __sg_alloc_table_from_pages(struct sg_table *sgt, struct page **pages,
+ unsigned int n_pages, unsigned int offset,
+ unsigned long size, unsigned int max_segment,
+ gfp_t gfp_mask)
{
- const unsigned int max_segment = SCATTERLIST_MAX_SEGMENT;
unsigned int chunks, cur_page, seg_len, i;
int ret;
struct scatterlist *s;
+ if (WARN_ON(!max_segment || offset_in_page(max_segment)))
+ return -EINVAL;
+
/* compute number of contiguous chunks */
chunks = 1;
seg_len = 0;
@@ -440,6 +443,35 @@ int sg_alloc_table_from_pages(struct sg_table *sgt,
return 0;
}
+EXPORT_SYMBOL(__sg_alloc_table_from_pages);
+
+/**
+ * sg_alloc_table_from_pages - Allocate and initialize an sg table from
+ * an array of pages
+ * @sgt: The sg table header to use
+ * @pages: Pointer to an array of page pointers
+ * @n_pages: Number of pages in the pages array
+ * @offset: Offset from start of the first page to the start of a buffer
+ * @size: Number of valid bytes in the buffer (after offset)
+ * @gfp_mask: GFP allocation mask
+ *
+ * Description:
+ * Allocate and initialize an sg table from a list of pages. Contiguous
+ * ranges of the pages are squashed into a single scatterlist node. A user
+ * may provide an offset at a start and a size of valid data in a buffer
+ * specified by the page array. The returned sg table is released by
+ * sg_free_table.
+ *
+ * Returns:
+ * 0 on success, negative error on failure
+ */
+int sg_alloc_table_from_pages(struct sg_table *sgt, struct page **pages,
+ unsigned int n_pages, unsigned int offset,
+ unsigned long size, gfp_t gfp_mask)
+{
+ return __sg_alloc_table_from_pages(sgt, pages, n_pages, offset, size,
+ SCATTERLIST_MAX_SEGMENT, gfp_mask);
+}
EXPORT_SYMBOL(sg_alloc_table_from_pages);
void __sg_page_iter_start(struct sg_page_iter *piter,
--
2.9.4
Back to linux.kernel | Previous | Next — Next in thread | Find similar | Unroll thread
[PATCH 3/4] lib/scatterlist: Introduce and export __sg_alloc_table_from_pages Tvrtko Ursulin <tursulin@ursulin.net> - 2017-07-27 11:10 +0200 Re: [PATCH 3/4] lib/scatterlist: Introduce and export __sg_alloc_table_from_pages Chris Wilson <chris@chris-wilson.co.uk> - 2017-07-28 13:10 +0200
csiph-web