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: 177140 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp3977517ill; Mon, 21 Oct 2019 14:46:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqx8k1ofuQWQe0nRcAl19jt+CcCtzTEpwLWg2D7VHdiHdQOZZ8mGUgbkAdDBCGeCrnGM4ZFl X-Received: by 2002:a17:90a:dd43:: with SMTP id u3mr350580pjv.130.1571694371320; Mon, 21 Oct 2019 14:46:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571694371; cv=none; d=google.com; s=arc-20160816; b=TOMSP9x44Xwz5q8ssbhogWQPVFfDkTF+X8gZr9X1sCje71ydGFYqMzHc/wDlM6S/Fx hf4Jj3AmxlNcUekKwYqFCUAEjpyOOJbwPFPo46I9LIa0FySl3aN26JzfljI63P2gPlVw 9z9giRr4NWPqfkCtUDRc2a26OoVqpPzpgDAU8fIyA9Phv0mlLhh/aUIb7/s/VXHV6h4v 9ZdCmM2fP5dVxMb8MFXrcqMQJd00HvsxaK3JmuNTzb+Req56Miv9Nc9BgcHq/5BQwCkU 9hzAsBcjONRM5ZrMoFQnbYhbaoo6Erpz9QR4/sZ4KZtyKFyGMpznvf+QnPXNoz+iJYK/ QVew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mime-version:references:in-reply-to:message-id:date :subject:to:from:delivered-to; bh=knGoCjIW4ieTNE6S9yXSU4ln2e4JBawqOQz1ktOUPGA=; b=MpHdy+eDn4eRDV6sAjwTraR1jFwh49mmHtz9yAS1wmwq+XuYmLXxwEAI9ShiVPnGKp Sr59zbOFo1nPJ7/8ys/3eX0G1idMsc+nlAgnKpsf6u62gofnrbCSxW6taFFeTfb0FKQO EDTbIYHApWRmP8cw30/B+dHGJFbhJxgIbTg2F4sxt4wNT1no7GyhRw8v953Hf152kMzd BTttbc5aI2uFqMfOt3kKQcLptoEDdhueD9uMHBjE25v4HCJDC4kTd7aLFvHfqDtIw/gC ORzbsdCfrcSWAw1N8X4QtyGYgLbvMVK0fD+ul7ADZtRL+Chb3D9zjq4U+LFCDWQMs1Dq IrKA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [131.252.210.177]) by mx.google.com with ESMTPS id u5si16677666pgc.297.2019.10.21.14.46.11 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 21 Oct 2019 14:46:11 -0700 (PDT) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 51F4E6E283; Mon, 21 Oct 2019 21:46:10 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ot1-f66.google.com (mail-ot1-f66.google.com [209.85.210.66]) by gabe.freedesktop.org (Postfix) with ESMTPS id 85B716E27A for ; Mon, 21 Oct 2019 21:46:02 +0000 (UTC) Received: by mail-ot1-f66.google.com with SMTP id 53so767930otv.4 for ; 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=JoOVl9cdvAjOSRgzOWc6FyHFp6/BiQuehzzSLrSpBtEH0yjC+u9PB9+S7MlK39vrIH 2p9o3RZoSU+oDx/hReQY4dA9DAF8QYwqsTTk0g530kPejR24UfySHoJfRo+qMNH+xzh2 MfDZfwVK86bl4cWfHYyRq21MVTDuU14GJAfbPllEYAAZuupCDSJp9FAHIcnSiA4so744 q/q09CgPelIXAmBC+6OuohcNOVLbedBHbNfC/uWkdIkVATXA5LokAslXo7UW5qthvb60 TMtBZCy+BeQgxXrq6hetaTxEUDxHpO0uJF7Ons4JRPIm+hC1gxeYc6h/Kp2TI5ZXdVhV /fkQ== X-Gm-Message-State: APjAAAWc8+ueCU2q097JDoxoST+zPvyE5P0PBhMd7bifcVNDl4JwClFW d1Kr0SGNsbYkvYZwltkA68jDmWw= 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-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Neil Armstrong , David Airlie , Liviu Dudau , Laurent Pinchart , 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 , Kieran Bingham , "James \(Qian\) Wang" , Alexandre Torgue , Chen Feng , linux-renesas-soc@vger.kernel.org, linux-mediatek@lists.infradead.org, Matthias Brugger , Sean Paul , linux-arm-kernel@lists.infradead.org, Philippe Cornu , Vincent Abriou , Maxime Coquelin , Rongrong Zou Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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); }