From patchwork Mon Oct 21 21:45:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Rob Herring (Arm)" X-Patchwork-Id: 11203081 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F2F3B913 for ; Mon, 21 Oct 2019 21:48:04 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CDE8E20659 for ; Mon, 21 Oct 2019 21:48:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="amTv1+0d" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CDE8E20659 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=1grdORgba+yxxlwoKabpmys72n+Smfr//0HsHpxNwJ4=; b=amTv1+0dpE6ZWa RbHdZ/aOcNjpUR9PU0IWE7mznNZQq+xgyjGMflY+pa5FBURwtOi+sj6TePtwmF0zfAZfHwfE6rdvi kAYgmrKFQDPdwjjpbGezq9JitnmvZ4mZ8lsjS3nFDviDILqDg0AKf7tka78q1hUGYmgXc4yxNMWw2 5WMf2dY1TEB0/D4jUdze/rhO89nbnaFGdS9i6tMzZ6GdAZL7D3T21IORKSGH1548yZIMScruiJKFe cUZYU1HQ1qLHvXEtzs+3p46xMDX4DC+KpfRxcdItdA5kvAZyOMEjN4igaaL+BMkHSPmMLEQ75K28i hoVsznmD3ojYCHL5dwXQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iMfX0-0002Pk-6K; Mon, 21 Oct 2019 21:48:02 +0000 Received: from mail-ot1-f66.google.com ([209.85.210.66]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iMfV4-0000HV-Fv; Mon, 21 Oct 2019 21:46:05 +0000 Received: by mail-ot1-f66.google.com with SMTP id c7so1602260otm.3; Mon, 21 Oct 2019 14:46:02 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=v85itWVb55sjk1S2/4vfjQdYVBkEeNhYbZwroc8bhoE=; b=uIEiTwG4Q7c59PocTtnhRKONA17NdISaISmR4179+Wi9ccqDlA6WdiQ9zMPmqBCpk0 +OLNgwHPEfHtPAQnySzuZ/Fds7nj0vWGX1OzSSU9hznoGtbnHUVC7t2iDHVFPkBttbB9 aW8Dgp5ukxmLE7Mm8Q4CYT0VjM87KuoiDocbx1SmqOXBfZMEXKY1tlJIRcSLEDzKGaA9 Jvyd0VQlr5bX8NY3yKiVLi2JWDC4IGpaR6ZTr61AHjHNfK5A07LKhlPwP9VpCztLatl4 pImO25MdHYPU7ZSdTGSMRHqte/zEGFyUaCiqoJdt+DX35CgjGAjCiIbFokztYSoWQBwg uzhA== X-Gm-Message-State: APjAAAUs9xaumcqxBTZWSUDSQViMgOg4TtHn7Wn8r0weIEIQYCDWQ8LT w7QEitRNDtI9OCw+CqDRLA== X-Google-Smtp-Source: APXvYqzkNxCqlFqsK5HBa4boCVhpMxwfWAj66hdD/5mch5qmynl4RhUugcgkNWf4J602suw2X3Zo7Q== X-Received: by 2002:a9d:5c0e:: with SMTP id o14mr57383otk.79.1571694361346; Mon, 21 Oct 2019 14:46:01 -0700 (PDT) Received: from xps15.herring.priv (24-155-109-49.dyn.grandenetworks.net. [24.155.109.49]) by smtp.googlemail.com with ESMTPSA id u130sm4122676oib.56.2019.10.21.14.45.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2019 14:46:00 -0700 (PDT) From: Rob Herring To: dri-devel@lists.freedesktop.org Subject: [PATCH 4/6] drm/cma-helper: Support DRM_MODE_DUMB_KERNEL_MAP flag Date: Mon, 21 Oct 2019 16:45:48 -0500 Message-Id: <20191021214550.1461-5-robh@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191021214550.1461-1-robh@kernel.org> References: <20191021214550.1461-1-robh@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191021_144602_850663_3BC32AC6 X-CRM114-Status: GOOD ( 16.72 ) X-Spam-Score: 0.7 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [209.85.210.66 listed in list.dnswl.org] 0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [209.85.210.66 listed in wl.mailspike.net] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (robherring2[at]gmail.com) 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit (robherring2[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record 0.2 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level mail domains are different 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders 0.2 FREEMAIL_FORGED_FROMDOMAIN 2nd level domains in From and EnvelopeFrom freemail headers are different X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Heiko_St=C3=BCbner?= , Neil Armstrong , David Airlie , Liviu Dudau , Sandy Huang , Laurent Pinchart , Benjamin Gaignard , linux-amlogic@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, Yannick Fertre , Kevin Hilman , Xinwei Kong , Xinliang Liu , linux-rockchip@lists.infradead.org, Chen-Yu Tsai , =?utf-8?q?Noralf_Tr=C3=B8nnes?= , "James \(Qian\) Wang" , CK Hu , Philipp Zabel , Alexandre Torgue , Chen Feng , Maarten Lankhorst , linux-renesas-soc@vger.kernel.org, Maxime Ripard , linux-mediatek@lists.infradead.org, Matthias Brugger , Daniel Vetter , Sean Paul , linux-arm-kernel@lists.infradead.org, Philippe Cornu , Vincent Abriou , Kieran Bingham , Maxime Coquelin , Rongrong Zou , Brian Starkey Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org Add support in CMA helpers to handle callers specifying DRM_MODE_DUMB_KERNEL_MAP flag. Existing behavior is maintained with this change. drm_gem_cma_dumb_create() always creates a kernel mapping as before. drm_gem_cma_dumb_create_internal() lets the caller set the flags as desired. Therefore, update all the existing callers of drm_gem_cma_dumb_create_internal() to also set the DRM_MODE_DUMB_KERNEL_MAP flag. Cc: Maarten Lankhorst Cc: Maxime Ripard Cc: Sean Paul Cc: David Airlie Cc: Daniel Vetter Cc: "James (Qian) Wang" Cc: Liviu Dudau Cc: Brian Starkey Cc: Neil Armstrong Cc: Kevin Hilman Cc: Laurent Pinchart Cc: Kieran Bingham Cc: Sandy Huang Cc: "Heiko Stübner" Cc: Yannick Fertre Cc: Philippe Cornu Cc: Benjamin Gaignard Cc: Vincent Abriou Cc: Maxime Coquelin Cc: Alexandre Torgue Cc: Chen-Yu Tsai Cc: linux-amlogic@lists.infradead.org Cc: linux-arm-kernel@lists.infradead.org Cc: linux-renesas-soc@vger.kernel.org Cc: linux-rockchip@lists.infradead.org Cc: linux-stm32@st-md-mailman.stormreply.com Signed-off-by: Rob Herring Reviewed-by: James Qian Wang (Arm Technology China) Reviewed-by: Neil Armstrong # for drm_gem_cma_helper and meson drm driver Reviewed-by: Laurent Pinchart --- .../gpu/drm/arm/display/komeda/komeda_kms.c | 1 + drivers/gpu/drm/arm/malidp_drv.c | 1 + drivers/gpu/drm/drm_gem_cma_helper.c | 48 +++++++++++-------- drivers/gpu/drm/meson/meson_drv.c | 1 + drivers/gpu/drm/rcar-du/rcar_du_kms.c | 1 + drivers/gpu/drm/rockchip/rockchip_drm_gem.c | 1 + drivers/gpu/drm/stm/drv.c | 1 + drivers/gpu/drm/sun4i/sun4i_drv.c | 1 + 8 files changed, 36 insertions(+), 19 deletions(-) diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_kms.c b/drivers/gpu/drm/arm/display/komeda/komeda_kms.c index d49772de93e0..7cf0dc4cbfc1 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_kms.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_kms.c @@ -31,6 +31,7 @@ static int komeda_gem_cma_dumb_create(struct drm_file *file, u32 pitch = DIV_ROUND_UP(args->width * args->bpp, 8); args->pitch = ALIGN(pitch, mdev->chip.bus_width); + args->flags = DRM_MODE_DUMB_KERNEL_MAP; return drm_gem_cma_dumb_create_internal(file, dev, args); } diff --git a/drivers/gpu/drm/arm/malidp_drv.c b/drivers/gpu/drm/arm/malidp_drv.c index 8a76315aaa0f..aeb1a779ecc1 100644 --- a/drivers/gpu/drm/arm/malidp_drv.c +++ b/drivers/gpu/drm/arm/malidp_drv.c @@ -465,6 +465,7 @@ static int malidp_dumb_create(struct drm_file *file_priv, u8 alignment = malidp_hw_get_pitch_align(malidp->dev, 1); args->pitch = ALIGN(DIV_ROUND_UP(args->width * args->bpp, 8), alignment); + args->flags = DRM_MODE_DUMB_KERNEL_MAP; return drm_gem_cma_dumb_create_internal(file_priv, drm, args); } diff --git a/drivers/gpu/drm/drm_gem_cma_helper.c b/drivers/gpu/drm/drm_gem_cma_helper.c index 4cebfe01e6ea..f91e9e8adeaf 100644 --- a/drivers/gpu/drm/drm_gem_cma_helper.c +++ b/drivers/gpu/drm/drm_gem_cma_helper.c @@ -78,21 +78,8 @@ __drm_gem_cma_create(struct drm_device *drm, size_t size) return ERR_PTR(ret); } -/** - * drm_gem_cma_create - allocate an object with the given size - * @drm: DRM device - * @size: size of the object to allocate - * - * This function creates a CMA GEM object and allocates a contiguous chunk of - * memory as backing store. The backing memory has the writecombine attribute - * set. - * - * Returns: - * A struct drm_gem_cma_object * on success or an ERR_PTR()-encoded negative - * error code on failure. - */ -struct drm_gem_cma_object *drm_gem_cma_create(struct drm_device *drm, - size_t size) +static struct drm_gem_cma_object * +drm_gem_cma_create_flags(struct drm_device *drm, size_t size, u32 flags) { struct drm_gem_cma_object *cma_obj; int ret; @@ -103,6 +90,9 @@ struct drm_gem_cma_object *drm_gem_cma_create(struct drm_device *drm, if (IS_ERR(cma_obj)) return cma_obj; + if (!(flags & DRM_MODE_DUMB_KERNEL_MAP)) + cma_obj->dma_attrs |= DMA_ATTR_NO_KERNEL_MAPPING; + cma_obj->vaddr = dma_alloc_attrs(drm->dev, size, &cma_obj->paddr, GFP_KERNEL | __GFP_NOWARN, cma_obj->dma_attrs); @@ -119,6 +109,25 @@ struct drm_gem_cma_object *drm_gem_cma_create(struct drm_device *drm, drm_gem_object_put_unlocked(&cma_obj->base); return ERR_PTR(ret); } + +/** + * drm_gem_cma_create - allocate an object with the given size + * @drm: DRM device + * @size: size of the object to allocate + * + * This function creates a CMA GEM object and allocates a contiguous chunk of + * memory as backing store. The backing memory has the writecombine attribute + * set. + * + * Returns: + * A struct drm_gem_cma_object * on success or an ERR_PTR()-encoded negative + * error code on failure. + */ +struct drm_gem_cma_object *drm_gem_cma_create(struct drm_device *drm, + size_t size) +{ + return drm_gem_cma_create_flags(drm, size, DRM_MODE_DUMB_KERNEL_MAP); +} EXPORT_SYMBOL_GPL(drm_gem_cma_create); /** @@ -139,14 +148,14 @@ EXPORT_SYMBOL_GPL(drm_gem_cma_create); */ static struct drm_gem_cma_object * drm_gem_cma_create_with_handle(struct drm_file *file_priv, - struct drm_device *drm, size_t size, + struct drm_device *drm, size_t size, u32 flags, uint32_t *handle) { struct drm_gem_cma_object *cma_obj; struct drm_gem_object *gem_obj; int ret; - cma_obj = drm_gem_cma_create(drm, size); + cma_obj = drm_gem_cma_create_flags(drm, size, flags); if (IS_ERR(cma_obj)) return cma_obj; @@ -225,7 +234,7 @@ int drm_gem_cma_dumb_create_internal(struct drm_file *file_priv, args->size = args->pitch * args->height; cma_obj = drm_gem_cma_create_with_handle(file_priv, drm, args->size, - &args->handle); + args->flags, &args->handle); return PTR_ERR_OR_ZERO(cma_obj); } EXPORT_SYMBOL_GPL(drm_gem_cma_dumb_create_internal); @@ -256,9 +265,10 @@ int drm_gem_cma_dumb_create(struct drm_file *file_priv, args->pitch = DIV_ROUND_UP(args->width * args->bpp, 8); args->size = args->pitch * args->height; + args->flags = DRM_MODE_DUMB_KERNEL_MAP; cma_obj = drm_gem_cma_create_with_handle(file_priv, drm, args->size, - &args->handle); + args->flags, &args->handle); return PTR_ERR_OR_ZERO(cma_obj); } EXPORT_SYMBOL_GPL(drm_gem_cma_dumb_create); diff --git a/drivers/gpu/drm/meson/meson_drv.c b/drivers/gpu/drm/meson/meson_drv.c index 397c33182f4f..1593518dcbe4 100644 --- a/drivers/gpu/drm/meson/meson_drv.c +++ b/drivers/gpu/drm/meson/meson_drv.c @@ -81,6 +81,7 @@ static int meson_dumb_create(struct drm_file *file, struct drm_device *dev, */ args->pitch = ALIGN(DIV_ROUND_UP(args->width * args->bpp, 8), SZ_64); args->size = PAGE_ALIGN(args->pitch * args->height); + args->flags = DRM_MODE_DUMB_KERNEL_MAP; return drm_gem_cma_dumb_create_internal(file, dev, args); } diff --git a/drivers/gpu/drm/rcar-du/rcar_du_kms.c b/drivers/gpu/drm/rcar-du/rcar_du_kms.c index 2dc9caee8767..c9b1f298ce7e 100644 --- a/drivers/gpu/drm/rcar-du/rcar_du_kms.c +++ b/drivers/gpu/drm/rcar-du/rcar_du_kms.c @@ -299,6 +299,7 @@ int rcar_du_dumb_create(struct drm_file *file, struct drm_device *dev, align = 16 * args->bpp / 8; args->pitch = roundup(min_pitch, align); + args->flags = DRM_MODE_DUMB_KERNEL_MAP; return drm_gem_cma_dumb_create_internal(file, dev, args); } diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_gem.c b/drivers/gpu/drm/rockchip/rockchip_drm_gem.c index 7582d0e6a60a..f09b9a035376 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_gem.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_gem.c @@ -419,6 +419,7 @@ int rockchip_gem_dumb_create(struct drm_file *file_priv, * align to 64 bytes since Mali requires it. */ args->pitch = ALIGN(min_pitch, 64); + args->flags = DRM_MODE_DUMB_KERNEL_MAP; args->size = args->pitch * args->height; rk_obj = rockchip_gem_create_with_handle(file_priv, dev, args->size, diff --git a/drivers/gpu/drm/stm/drv.c b/drivers/gpu/drm/stm/drv.c index 5a9f9aca8bc2..0f76a4ac95b3 100644 --- a/drivers/gpu/drm/stm/drv.c +++ b/drivers/gpu/drm/stm/drv.c @@ -47,6 +47,7 @@ static int stm_gem_cma_dumb_create(struct drm_file *file, */ args->pitch = roundup(min_pitch, 128); args->height = roundup(args->height, 4); + args->flags = DRM_MODE_DUMB_KERNEL_MAP; return drm_gem_cma_dumb_create_internal(file, dev, args); } diff --git a/drivers/gpu/drm/sun4i/sun4i_drv.c b/drivers/gpu/drm/sun4i/sun4i_drv.c index a5757b11b730..f653a5d1e2d6 100644 --- a/drivers/gpu/drm/sun4i/sun4i_drv.c +++ b/drivers/gpu/drm/sun4i/sun4i_drv.c @@ -34,6 +34,7 @@ static int drm_sun4i_gem_dumb_create(struct drm_file *file_priv, { /* The hardware only allows even pitches for YUV buffers. */ args->pitch = ALIGN(DIV_ROUND_UP(args->width * args->bpp, 8), 2); + args->flags = DRM_MODE_DUMB_KERNEL_MAP; return drm_gem_cma_dumb_create_internal(file_priv, drm, args); }