From patchwork Wed Nov 1 14:14:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liviu Dudau X-Patchwork-Id: 117719 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp938911qgn; Wed, 1 Nov 2017 07:14:33 -0700 (PDT) X-Google-Smtp-Source: ABhQp+S5UvMBGLbhIEObmEk4Ko0YAyO9GiaA4bJpcy4s9auak++Jim5DWTyApuLeHP1m3cCUtc9O X-Received: by 10.98.214.215 with SMTP id a84mr7000204pfl.27.1509545673281; Wed, 01 Nov 2017 07:14:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509545673; cv=none; d=google.com; s=arc-20160816; b=ZsT8VHkEa/kSTeg/UQlbCSt45IhvLvLAGYiaeiZeLXF2HTTpR3wyyq5UlObnlzl5Su Rg60N4MjeXUmFgAQJhczYMMusp4DrtRuT7uP7mbtVi6uCSHS4B80fudYu+KN/tAG9kEd f8sXdPsSiZHd810XHBY6aWMq8ZvYwpFRw7zbO6fecV9rzEA3f8P/tmqQVoXaTewwgtWI R81n0+a98jeffeLcYXmcHn8wdqOYG1Ar9vAMDBLyvaRMPXRKaCbQFZ6/mYkFJEn798kj D8MyLVi8u1ywEuTFOMbtaqKLBN7mvVuYpcMb7Q1NIFCZK1ajdnDVaxUtkEWHKLtsqYkk IG6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=qK5tbtisyWpP5ZyfwMouDa/9m4DB1pJElaxqZbMcGHU=; b=prmJlrHdNCUeFexmNedJqIj3VMhX7N77XeqVc9mtlW1BbIxa/Hhi8TqcfZB7b6Q4sa R7ZKSE7F/6zFzACboUgRUlXzNsVCZqxdpwutrm93JOL9l9Yc5dJC/gHWuhCBjlTPQGEQ S+VAQKt5KhhM/zEJ1sikXbrTggHmoYjQ5ycEPpRs6vREEelL7saa1+sRMyDae92CQe0z fGoPwyov9bI1gmr3PQcHh2fkEO2i/jOh146iRGBML425+qa7enuWudBwalPicCD9ifTV ikkrIy37ICQwcvzp/h3D7IY5lllLguhRio6AcTKbxSAhD5lnCNY4RjPZHYB7yLbfTEtz WRZA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a5si1116785pgc.127.2017.11.01.07.14.33; Wed, 01 Nov 2017 07:14:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754702AbdKAOOc (ORCPT + 26 others); Wed, 1 Nov 2017 10:14:32 -0400 Received: from fw-tnat.cambridge.arm.com ([217.140.96.140]:12530 "EHLO cam-smtp0.cambridge.arm.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754625AbdKAOOa (ORCPT ); Wed, 1 Nov 2017 10:14:30 -0400 Received: from e110455-lin.cambridge.arm.com (e110455-lin.cambridge.arm.com [10.2.131.60]) by cam-smtp0.cambridge.arm.com (8.13.8/8.13.8) with ESMTP id vA1EEJsE005409; Wed, 1 Nov 2017 14:14:20 GMT From: Liviu Dudau To: Brian Starkey Cc: Mali DP Maintainers , Daniel Vetter , David Airlie , DRI-devel , LKML , Jani Nikula , Sean Paul , Liviu Dudau Subject: [PATCH] drm: gem_cma_helper.c: Allow importing of contiguous scatterlists with nents > 1 Date: Wed, 1 Nov 2017 14:14:19 +0000 Message-Id: <20171101141419.3180-1-Liviu.Dudau@arm.com> X-Mailer: git-send-email 2.14.3 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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: Brian Starkey Signed-off-by: Liviu Dudau --- Hi, This patch is the only change I need in order to be able to use existing IOMMU domain infrastructure with the Mali DP driver. I have tested the patch and I know it works correctly for my setup, but I would like to get some comments on whether I am on the right path or if CMA really wants to see an sg_table with only one entry. Best regards, Liviu drivers/gpu/drm/drm_gem_cma_helper.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) -- 2.14.3 Reviewed-by: Laurent Pinchart 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);