From patchwork Fri Nov 11 12:35:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 9422961 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 9AC51601C0 for ; Fri, 11 Nov 2016 12:35:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D21129A98 for ; Fri, 11 Nov 2016 12:35:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8197F29A97; Fri, 11 Nov 2016 12:35:56 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F262E29A97 for ; Fri, 11 Nov 2016 12:35:55 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CBE3B6E8DB; Fri, 11 Nov 2016 12:35:54 +0000 (UTC) X-Original-To: Intel-gfx@lists.freedesktop.org Delivered-To: Intel-gfx@lists.freedesktop.org Received: from mail-wm0-x241.google.com (mail-wm0-x241.google.com [IPv6:2a00:1450:400c:c09::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id 378396E8DD for ; Fri, 11 Nov 2016 12:35:53 +0000 (UTC) Received: by mail-wm0-x241.google.com with SMTP id u144so9165332wmu.0 for ; Fri, 11 Nov 2016 04:35:53 -0800 (PST) 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=GL/dyDdjNcWEtfFjLegz8JK9z23yr6lfKmTDFPDGCBo=; b=idnhFgTVG/c+JaLGiVR3CKeMXRjFRFeaoX12fPJ3QRl3qE9fEl3onn7zdQ5mLfFK3j 08jF7d34cP+rnerExgpojVT8kRncZrg9qg4LNeT3PdLzVuvvnAyUNga9fOnFEAB60JVs mYBER4evIYkW+GoEgXY87iqXrmYtJPIOwFxMwzjIQZJdUORcLel5A4kPOQ7VL2ManFZY /0frK8sBuEJjVkC6iLVURcCsS47fHFhL7FgHziSmHntgoCCxqoCwf+HtzD60FoyAm4od MxHNy6i1ZMYDh4WHsPxgNP1SjY3CRYBCerHm6wTNgWJHpJqEg69yqWbTIV/Gd+4pGEyS pVRQ== 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=GL/dyDdjNcWEtfFjLegz8JK9z23yr6lfKmTDFPDGCBo=; b=E9OoMrRZ1cCJG8Z3cT9uI7OgA9f335BYJAogyjXVd4sf+Fyn1tDvP4Hfdtqaf5YWeE Zx5MirnAp6yzt32eELS424v8Y/ptGUia3sibchdKCJxH3UC1ihrbC5TDlA5mG9EN5Tll AMU9duW1JVNvsliRgiqBqIz3bqxan4Q8+rdbgvg6hyRoazibBimOclzBR3o0POLR+BdP R8i0uMAwhPe+8ztt/XnCOr/LGIMQW36RmJbsEMj3SBoNzDwccGfDebR1GguvWDclNviy V1sgfFTJSbIO+X5Llcy2DlYrzye6CMJyMgkX8momA3X/7JCx69hcEfuBq5uomLkjLLXJ 99dQ== X-Gm-Message-State: ABUngvdNBGnZ9tHZmutkiLqV7CAt5HCWh36QHw6M7eqB22MNt2BJNd3i0cYnkuoF6oIOPw== X-Received: by 10.28.21.21 with SMTP id 21mr11670479wmv.132.1478867751650; Fri, 11 Nov 2016 04:35:51 -0800 (PST) Received: from t460p.intel ([2a02:c7d:9bd6:b000:f37e:1e07:a7d8:46cd]) by smtp.gmail.com with ESMTPSA id d85sm18695217wmd.17.2016.11.11.04.35.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Nov 2016 04:35:50 -0800 (PST) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org Date: Fri, 11 Nov 2016 12:35:44 +0000 Message-Id: <1478867744-24383-1-git-send-email-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <20161111102431.GS9300@nuc-i3427.alporthouse.com> References: <20161111102431.GS9300@nuc-i3427.alporthouse.com> Cc: Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [Intel-gfx] [PATCH v2 3/4] lib/scatterlist: Introduce and export __sg_alloc_table_from_pages X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" 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. v2: Reorder parameters. (Chris Wilson) Signed-off-by: Tvrtko Ursulin Cc: Masahiro Yamada Cc: linux-kernel@vger.kernel.org Cc: Chris Wilson --- 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..16b740afeed2 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, 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 de15f369b317..8ee1ece81626 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 single scatterlist node in bytes + * @gfp_mask: GFP allocation mask * * 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, unsigned int max_segment, + gfp_t gfp_mask) { - const unsigned int max_segment = UINT_MAX; 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, UINT_MAX); +} EXPORT_SYMBOL(sg_alloc_table_from_pages); void __sg_page_iter_start(struct sg_page_iter *piter,