From patchwork Fri Nov 10 13:33:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liviu Dudau X-Patchwork-Id: 118529 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp7941568qgn; Fri, 10 Nov 2017 05:33:25 -0800 (PST) X-Google-Smtp-Source: AGs4zMYZbx5CtFEdKI9YxH/CqQmvx2Gj7U1W1uKMQmmH/Df+CVAVLyY2URvWBkjd3arMoLZTq0j6 X-Received: by 10.98.98.132 with SMTP id w126mr400812pfb.208.1510320805333; Fri, 10 Nov 2017 05:33:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510320805; cv=none; d=google.com; s=arc-20160816; b=vmiX8cd/AvslA6Rn+SFE9UqSueQZOuxoi5CACkLwCh78EvlLPW337/I3OYTet64L5o qfNSglI0D+i4eLRANEQc0k9O//rRRXuFBXG0Zgn/C/sInTVToXVezB5lcyZFxO7U09vt 186oxd72l/uNkkA8yXlO5kegRoolUTmYa4Y2VDQkwT+FCB/ztUxc2QTR9f5o2t08Yz1t 3CTCeiNbiNz3y8gp0oZcjHTQGM2u3LIvcdiEonUgEW32mExkJ0GWm/wMQF6AWbIxtq/p q2BhNYgFpfxM52q+n4XURDy7Epp8BdedF5B38r64D2mZX/hytKj+HOPH765LHYDARhOI ukqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:cc:references:in-reply-to:message-id:date :subject:to:from:delivered-to:arc-authentication-results; bh=wQTkVAbTrUaySUMJqysg/a8qna/eZQNP+17HAlXLsOo=; b=s5x+7mUkwb1TH/s9hy7orm12BzeyZici/l5PzonIOFfHPd20wOE+yyGsgXsmH2FwIm e8BnTz8t8sBTv5sff5nVmyzwRoIP3tOJhLIp4aMk/KyIGdks/d4X6VVb0OTf5xUKP95T Iz5E1FQ72EsbH7ze6DDyim5DhkiHZI+GIG/3PYxMv6htOIiJCA1D+mMbKDcsQi/9K4fY 4349Eh2T3SD8MTKLKEn25Emr5JBX9EMENQNzSNdRIjuhgh0VUYTN4V6CIn7f+A0urwab Nu5MvKrN5O4invxPjslRJXVMazMRmwCvTiKhCevHVxPB0awPGEijA1klsM5YQpBURJKH wLhg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [131.252.210.177]) by mx.google.com with ESMTPS id l1si8851815pld.82.2017.11.10.05.33.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Nov 2017 05:33:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) client-ip=131.252.210.177; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5916F6EA61; Fri, 10 Nov 2017 13:33:24 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from cam-smtp0.cambridge.arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7C3C96EA61; Fri, 10 Nov 2017 13:33:23 +0000 (UTC) Received: from e110455-lin.cambridge.arm.com (e110455-lin.cambridge.arm.com [10.2.131.36]) by cam-smtp0.cambridge.arm.com (8.13.8/8.13.8) with ESMTP id vAADXAgT011315; Fri, 10 Nov 2017 13:33:10 GMT From: Liviu Dudau To: Laurent Pinchart Subject: [PATCH v2] drm: gem_cma_helper.c: Allow importing of contiguous scatterlists with nents > 1 Date: Fri, 10 Nov 2017 13:33:10 +0000 Message-Id: <20171110133310.1225-1-Liviu.Dudau@arm.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <2213365.Z1vsgl9bDt@avalon> References: <2213365.Z1vsgl9bDt@avalon> Cc: David Airlie , intel-gfx@lists.freedesktop.org, Liviu Dudau , LKML , DRI-devel , Mali DP Maintainers , Daniel Vetter X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" drm_gem_cma_prime_import_sg_table() will fail if the number of entries in the sg_table > 1. However, you can have a device that uses an IOMMU engine and can map a discontiguous buffer with multiple entries that have consecutive sg_dma_addresses, effectively making it contiguous. Allow for that scenario by testing the entries in the sg_table for contiguous coverage. Reviewed-by: Laurent Pinchart Signed-off-by: Liviu Dudau --- Laurent, Thanks for the review! I would like to ask for one more favour: if you are OK with this version, can you pull this patch through the drm-misc tree? Many thanks, Liviu drivers/gpu/drm/drm_gem_cma_helper.c | 22 ++++++++++++++++++++-- include/drm/drm_gem_cma_helper.h | 4 +++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/drm_gem_cma_helper.c b/drivers/gpu/drm/drm_gem_cma_helper.c index 020e7668dfaba..43b179212052d 100644 --- a/drivers/gpu/drm/drm_gem_cma_helper.c +++ b/drivers/gpu/drm/drm_gem_cma_helper.c @@ -482,8 +482,26 @@ drm_gem_cma_prime_import_sg_table(struct drm_device *dev, { struct drm_gem_cma_object *cma_obj; - if (sgt->nents != 1) - return ERR_PTR(-EINVAL); + if (sgt->nents != 1) { + /* check if the entries in the sg_table are contiguous */ + dma_addr_t next_addr = sg_dma_address(sgt->sgl); + struct scatterlist *s; + unsigned int i; + + for_each_sg(sgt->sgl, s, sgt->nents, i) { + /* + * sg_dma_address(s) is only valid for entries + * that have sg_dma_len(s) != 0 + */ + if (!sg_dma_len(s)) + continue; + + if (sg_dma_address(s) != next_addr) + return ERR_PTR(-EINVAL); + + next_addr = sg_dma_address(s) + sg_dma_len(s); + } + } /* Create a CMA GEM buffer. */ cma_obj = __drm_gem_cma_create(dev, attach->dmabuf->size); diff --git a/include/drm/drm_gem_cma_helper.h b/include/drm/drm_gem_cma_helper.h index 58a739bf15f1f..214aa85adc8d5 100644 --- a/include/drm/drm_gem_cma_helper.h +++ b/include/drm/drm_gem_cma_helper.h @@ -8,7 +8,9 @@ * struct drm_gem_cma_object - GEM object backed by CMA memory allocations * @base: base GEM object * @paddr: physical address of the backing memory - * @sgt: scatter/gather table for imported PRIME buffers + * @sgt: scatter/gather table for imported PRIME buffers. The table can have + * more than one entry but they are guaranteed to have contiguous + * DMA addresses. * @vaddr: kernel virtual address of the backing memory */ struct drm_gem_cma_object {