From patchwork Fri Oct 21 14:11:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 9389323 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A42CF607F0 for ; Fri, 21 Oct 2016 14:13:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 958BD2A236 for ; Fri, 21 Oct 2016 14:13:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 89EF22A239; Fri, 21 Oct 2016 14:13:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 071682A23B for ; Fri, 21 Oct 2016 14:13:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934400AbcJUOMq (ORCPT ); Fri, 21 Oct 2016 10:12:46 -0400 Received: from mail-lf0-f68.google.com ([209.85.215.68]:36162 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933737AbcJUOLm (ORCPT ); Fri, 21 Oct 2016 10:11:42 -0400 Received: by mail-lf0-f68.google.com with SMTP id b75so6115854lfg.3 for ; Fri, 21 Oct 2016 07:11:41 -0700 (PDT) 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=734vPnPYpKtoxhqqxsabu/mwDPSMN2xZNxjQSE1Xgbg=; b=B6gWXI1WFnexR4PXsvANGuFUBDQr1Eo2zHQYq2DBM0pgK/GQLWHvFBNueKsIhezEkh Z9k5WXRofdRLurBu6ff4M+IqGY802thN9IXmozGJbuYHkl3geEN/+3nq1n8Uiz8WkwIr qTBztmKBQgW++b8iu7EzNBcWZBwB5d3wud98s4Kkw9ewa1uQ9JkWhS/Zr5raW5oTxXbG mt2DESmyIN3gF1YxtQzi9cuNnRLaBV4lSB52s7KdLWUg/+VtM9dB9jYHVs+ZUZhXM+L5 FJbBHkHr3lklB9qsGMVLf2SrzPmLiPkQrEOPtiUWU09cR89pRWwoYLk2BpGu9W7HyoWQ s4yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=734vPnPYpKtoxhqqxsabu/mwDPSMN2xZNxjQSE1Xgbg=; b=jCm6/p+xXnCcIEh8hLhaVBaDnwlzPB2Vtz/7qLZQd9a3GY/jtxrZb7NoSISuMGpfKw 3krF7xrGd4fkRMV6ZLoVp+BhvYgPoP1gt6UMnL9LA0AuwcpygUerHhk02WHBSfVuX4SI 7O8fk4wfdmH9fhTSaCMCe8/nv6Lt6FTwYhqXN9v3yci26w6+/VcfEag/BLN9VvjLwJo1 CYWvjP9v+0DS4OruGZrnRO97CEp4FbzP0eEhNPkbFdWxneqMocois3oipRD9QBkh137E 44hFHXUwbuLGN3J9ng351jyOdZQSWsTpeobRblx7K+k4db2FwXXllEeQZ4xML8y6nU3D ej3w== X-Gm-Message-State: AA6/9RlRaf3ADlDbgbRN1zbJz8wow3VKgKCny8KfWUv0CYCR06/Ex9/qRZm/OZvnIg608Q== X-Received: by 10.28.61.215 with SMTP id k206mr3096055wma.128.1477059100843; Fri, 21 Oct 2016 07:11:40 -0700 (PDT) Received: from e31.Home ([2a02:c7d:9b6d:e300:916a:6cab:ac67:71c2]) by smtp.gmail.com with ESMTPSA id ya1sm3114013wjb.23.2016.10.21.07.11.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Oct 2016 07:11:40 -0700 (PDT) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Chris Wilson , Tvrtko Ursulin , Masahiro Yamada Subject: [PATCH 3/5] lib/scatterlist: Introduce and export __sg_alloc_table_from_pages Date: Fri, 21 Oct 2016 15:11:21 +0100 Message-Id: <1477059083-3500-4-git-send-email-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1477059083-3500-1-git-send-email-tvrtko.ursulin@linux.intel.com> References: <1477059083-3500-1-git-send-email-tvrtko.ursulin@linux.intel.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Tvrtko Ursulin 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. Signed-off-by: Tvrtko Ursulin Cc: Masahiro Yamada Cc: linux-kernel@vger.kernel.org --- include/linux/scatterlist.h | 11 +++++---- lib/scatterlist.c | 55 ++++++++++++++++++++++++++++++++++----------- 2 files changed, 49 insertions(+), 17 deletions(-) diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h index c981bee1a3ae..29591dbb20fd 100644 --- a/include/linux/scatterlist.h +++ b/include/linux/scatterlist.h @@ -261,10 +261,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, gfp_t gfp_mask, + unsigned int max_segment); +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 d928fa04aee3..0378c5fd7caa 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) + * @gfp_mask: GFP allocation mask + * @max_segment: Maximum size of a single scatterlist node in bytes * * Description: * Allocate and initialize an sg table from a list of pages. Contiguous @@ -389,12 +390,11 @@ 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, gfp_t gfp_mask, + unsigned int max_segment) { - const unsigned int max_segment = ~0; unsigned int seg_len, chunks; unsigned int i; unsigned int cur_page; @@ -444,6 +444,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, gfp_mask, ~0); +} EXPORT_SYMBOL(sg_alloc_table_from_pages); void __sg_page_iter_start(struct sg_page_iter *piter,