From patchwork Mon Oct 21 21:45:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring \(Arm\)" X-Patchwork-Id: 177136 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp3977339ill; Mon, 21 Oct 2019 14:45:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqxpKC417MW5lpVhpO8mUMqwZIDOySW6PlKg5+gxX5B4xOkRgnfNCSxifQfW7UXNDXkp3P7F X-Received: by 2002:a17:902:8a8c:: with SMTP id p12mr168384plo.208.1571694359394; Mon, 21 Oct 2019 14:45:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571694359; cv=none; d=google.com; s=arc-20160816; b=P3HEXzF3vfhVLDI9n3LsRB4C6v2z8KrJTwrxo/hYDTBWOt//0U7d/R1zUXr7vgtg1S l8XqCCuSwO8pHfylom8PsoaYFCQ2gPptIscO9GYoB3hxIb/KGRN0f3K8moWWpDNSGIgX 9DJ0I5xeBPASNmyowgF7gfk9HsUu8n68TMsqaHg23BTKCN0/1pioQ4UCnlAmF0lkrA3S 7GpiukynX/dShulcCRs3ReR6rHHD6DYbP7hb12g8slKN7oRjUApOeO0gspAmLY0NdXIY POVQonmRWeRrKzhb7mH3AQiKn+2hX8ePeP5sx+OxEA05WGtCxSm0csCaDscXII1TiKnR XvAQ== 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=uFqhk0MGGR2tpu6JhceDkXTwBCSx75tnUJ0voN0cok0=; b=eIooFY+IrlPMM377oN+oE7n8e3K/VKr7wIT+d5IPt19Gpufmclm9I6Vb1nWiyw6Jep TwiiK8kAgOQpGJw7OnguTIr7c2Hf/Yp3HcyRD7iMC9SW0uFYDEhPhb8q5refzGkqLyVG KzpXiI8QUvg7PhjqpN77dcUVuVQM7tH11kT6f1Q6uHISnjnxAGsyvIVCn+0KkCbG8McA XrdbJKn++wU4FqCwC4KMA7S89RJuhCKZVydtgrFSqH+Sq7dUJFHceOS+w9KhYdFPBTUG kj/pxWqAVBqUtD2pIkZ4WoWXJMd/Ma84b9j3BM7QN6aeA35QL6ShWq+xWqRYW0304yMu HYQg== 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 30si15980397plf.333.2019.10.21.14.45.59 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 21 Oct 2019 14:45:59 -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 35C5F6E279; Mon, 21 Oct 2019 21:45:58 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-oi1-f193.google.com (mail-oi1-f193.google.com [209.85.167.193]) by gabe.freedesktop.org (Postfix) with ESMTPS id 83FBF6E277 for ; Mon, 21 Oct 2019 21:45:56 +0000 (UTC) Received: by mail-oi1-f193.google.com with SMTP id w144so12420267oia.6 for ; Mon, 21 Oct 2019 14:45:56 -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=nG1jrqiVrLvARMweYNsyPG+j+EFZbDQxRJlgrVpfL4I=; b=tkzu+x32IjRhPjMpr/KbDQMA8Tq45LavPJwpewimcGNI1bYJSWQ96BEJ08p+9cMxvl WRAEuoivZppL4j0KhOqfghgxB+ONUlR8JUkyHbNb8vTH2dRjn44Q0VK8bMnhNIfcDfYN 4AUts7/tTJLkZOuW7Uoea4NVFw5p6+HKiUgeX3RG/+/XVyiHcUiXSp9euqZPgU81tJTM oXNfYfNeirL09kp7QSwUHOF9bhsws+7+IJ23Kxi/72xu62TeL6HrwxVWYBEBJK1+hnsx LidrPZtB371dCkm/40qW4cy+uQ9BT6PdRZlSyULS+T3VhZAlKMOOyqhx8OXXZH2hCKUZ 8Hjg== X-Gm-Message-State: APjAAAVxfNgDRjYHTpKtCG6HZtl1k9r/3btv2cD7pvKY1KQDaO8qui7X 2V0RoRzvdcOCgV3XknJ+j6hdvXY= X-Received: by 2002:aca:40b:: with SMTP id 11mr191900oie.59.1571694355381; Mon, 21 Oct 2019 14:45:55 -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.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2019 14:45:54 -0700 (PDT) From: Rob Herring To: dri-devel@lists.freedesktop.org Subject: [PATCH 1/6] drm/kirin: Use DRM_GEM_CMA_VMAP_DRIVER_OPS Date: Mon, 21 Oct 2019 16:45:45 -0500 Message-Id: <20191021214550.1461-2-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 , 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-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" drm_gem_cma_dumb_create_internal() is not supposed to be used for .dumb_create directly. drm_gem_cma_dumb_create() should be used instead. If we do that, we might as well convert over to using DRM_GEM_CMA_VMAP_DRIVER_OPS instead. Cc: Xinliang Liu Cc: Rongrong Zou Cc: Xinwei Kong Cc: Chen Feng Cc: David Airlie Cc: Daniel Vetter Signed-off-by: Rob Herring --- drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c index 73cd28a6ea07..490537a1d035 100644 --- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c +++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c @@ -941,16 +941,7 @@ DEFINE_DRM_GEM_CMA_FOPS(ade_fops); static struct drm_driver ade_driver = { .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_ATOMIC, .fops = &ade_fops, - .gem_free_object_unlocked = drm_gem_cma_free_object, - .gem_vm_ops = &drm_gem_cma_vm_ops, - .dumb_create = drm_gem_cma_dumb_create_internal, - .prime_handle_to_fd = drm_gem_prime_handle_to_fd, - .prime_fd_to_handle = drm_gem_prime_fd_to_handle, - .gem_prime_get_sg_table = drm_gem_cma_prime_get_sg_table, - .gem_prime_import_sg_table = drm_gem_cma_prime_import_sg_table, - .gem_prime_vmap = drm_gem_cma_prime_vmap, - .gem_prime_vunmap = drm_gem_cma_prime_vunmap, - .gem_prime_mmap = drm_gem_cma_prime_mmap, + DRM_GEM_CMA_VMAP_DRIVER_OPS, .name = "kirin", .desc = "Hisilicon Kirin620 SoC DRM Driver", From patchwork Mon Oct 21 21:45:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring \(Arm\)" X-Patchwork-Id: 177137 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp3977389ill; Mon, 21 Oct 2019 14:46:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqwq94guj34u18inYBlyrx8k0Hv+lRAMTi7rzubk5e+2jeIiffrJl+YDi8uxnoaDi+YwhjO+ X-Received: by 2002:a63:9dc2:: with SMTP id i185mr37474pgd.294.1571694362288; Mon, 21 Oct 2019 14:46:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571694362; cv=none; d=google.com; s=arc-20160816; b=z/gcnpngfXd+GLwGKjHgLCwQzcxYlvz8jNWEA/KHwit9831jG+NEHcEPfZqsX0/DSP nlupQHdvc3o1ykgdwmlQjOyhVuhalbuGCeRypNsCWaNXHouZqeV+XQDTkCZ36rVUtfwb +JKFNyizHiCtpX10uDu77Za3zcxhSkkBkq0rsWgRXoAl8rcMrSbGjS80fnoSDgWfkRHo L66EBViHW99Uz0gTmX8Io/o/r04Go2lynmKLsGzzPcEJ5o77vNFEqCKofI75VScUk9eF DF/ec1Q12Y+ERkh+DSWHUJYozTFJT688JwpYvrjKtmQmKQ7ck1xgDGPOLy/cZiRPO8P6 MVGA== 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=z3yf036dc7pMKCJhbQtaWCt/MaTaH0GWftJtVG49uY0=; b=Vj1VbNCIWYv4Kn7shARv9daP9pjVXXkG0kqfqLrXmtndS9LrzQ2dvInfi7oZkAorhj GooGxF8z+yJeZ/kNp31AUmB5bVUMody7IRE+okSjmSSdsGsz78OBLC+ZSBAwU94YzP9q n9/C5CYS6vWt+S0Of8qXHgCPxV5d8phh49CgTujb4ha/tBhKPFKBiAVGynzCdMqoWv1+ TQ9f4BOLFlcROj1CyanYtlae38su0y2MKk8eQgm493sAhxTCQtkDZMEQzLfkxggFInwX HAF+QZ7pyLtsn8CCp2+IyWOvAH4b3Om0fbgblZjeC2kTvkkCTx4DXkAkKbdfRpvOMNmz uVLg== 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 y3si14998528pgr.85.2019.10.21.14.46.02 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 21 Oct 2019 14:46:02 -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 5FFE46E277; Mon, 21 Oct 2019 21:46:01 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-oi1-f193.google.com (mail-oi1-f193.google.com [209.85.167.193]) by gabe.freedesktop.org (Postfix) with ESMTPS id 300076E277 for ; Mon, 21 Oct 2019 21:45:58 +0000 (UTC) Received: by mail-oi1-f193.google.com with SMTP id g81so12402661oib.8 for ; Mon, 21 Oct 2019 14:45:58 -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=TsrtW/3IwxExUlY3NAEem6qIu9cq5ThxwAPMPnLEB1M=; b=KbcvqwPovIyI+sJBE3BeF7+xLfC1MV+hOpmlDAQuKHvSN/AnxtXzqq6x5BybGztEud j1m+ksI6gjEgwwP+S23aqMZpBsd94aEv0wvwBRps8uD753iZW2RaHc0+DP+jc2nB/Viv TfGx75LLeC2prlWqv0u0WzHItAmslmJwWoL9Z4PdFpBLwnUrn0MgYnQ4P12hcmPMBeZx i1aNfm5P7T9WjSxW8MeU55RD5Zx4v8lFAKN1PQWeylnbAO0duiw7ThXRRIEmmt8/LGON ROw/Z3LPLOYKeGc6MO9OuhLrGMCuf13oEYUjaylwvr7xotrj6A8YpNiPRL3vHnQR9fbm SbQg== X-Gm-Message-State: APjAAAX+As3CG9tG8WeG3fJM+rZ+T2CrbAPM7gpXN2qq87z9qSPokJO1 k5A1e4m5mLnUWw1y5X/Cxl3rn4Y= X-Received: by 2002:a54:4182:: with SMTP id 2mr188880oiy.148.1571694357143; Mon, 21 Oct 2019 14:45:57 -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.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2019 14:45:56 -0700 (PDT) From: Rob Herring To: dri-devel@lists.freedesktop.org Subject: [PATCH 2/6] drm: Introduce DRM_MODE_DUMB_KERNEL_MAP flag Date: Mon, 21 Oct 2019 16:45:46 -0500 Message-Id: <20191021214550.1461-3-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 , 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-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" Introduce a new flag, DRM_MODE_DUMB_KERNEL_MAP, for struct drm_mode_create_dumb. This flag is for internal kernel use to indicate if dumb buffer allocation needs a kernel mapping. This is needed only for CMA where creating a kernel mapping or not has to be decided at allocation time because creating a mapping on demand (with vmap()) is not guaranteed to work. Several drivers are using CMA, but not the CMA helpers because they distinguish between kernel and userspace allocations to create a kernel mapping or not. Update the callers of drm_mode_dumb_create() to set drm_mode_dumb_create.flags to appropriate defaults. Currently, flags can be set to anything by userspace, but is unused within the kernel. Let's force flags to zero (no kernel mapping) for userspace callers by default. For in kernel clients, set DRM_MODE_DUMB_KERNEL_MAP by default. Drivers can override this as needed. Cc: David Airlie Cc: Daniel Vetter Cc: Maarten Lankhorst Cc: Maxime Ripard Cc: Sean Paul Signed-off-by: Rob Herring --- drivers/gpu/drm/drm_client.c | 1 + drivers/gpu/drm/drm_dumb_buffers.c | 5 ++++- include/uapi/drm/drm_mode.h | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_client.c b/drivers/gpu/drm/drm_client.c index d9a2e3695525..dbfc8061b392 100644 --- a/drivers/gpu/drm/drm_client.c +++ b/drivers/gpu/drm/drm_client.c @@ -264,6 +264,7 @@ drm_client_buffer_create(struct drm_client_dev *client, u32 width, u32 height, u dumb_args.width = width; dumb_args.height = height; dumb_args.bpp = info->cpp[0] * 8; + dumb_args.flags = DRM_MODE_DUMB_KERNEL_MAP; ret = drm_mode_create_dumb(dev, &dumb_args, client->file); if (ret) goto err_delete; diff --git a/drivers/gpu/drm/drm_dumb_buffers.c b/drivers/gpu/drm/drm_dumb_buffers.c index d18a740fe0f1..74a13f14c173 100644 --- a/drivers/gpu/drm/drm_dumb_buffers.c +++ b/drivers/gpu/drm/drm_dumb_buffers.c @@ -97,7 +97,10 @@ int drm_mode_create_dumb(struct drm_device *dev, int drm_mode_create_dumb_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv) { - return drm_mode_create_dumb(dev, data, file_priv); + struct drm_mode_create_dumb *args = data; + + args->flags = 0; + return drm_mode_create_dumb(dev, args, file_priv); } /** diff --git a/include/uapi/drm/drm_mode.h b/include/uapi/drm/drm_mode.h index 735c8cfdaaa1..02712f46b94c 100644 --- a/include/uapi/drm/drm_mode.h +++ b/include/uapi/drm/drm_mode.h @@ -796,6 +796,8 @@ struct drm_mode_crtc_page_flip_target { __u64 user_data; }; +#define DRM_MODE_DUMB_KERNEL_MAP (1<<0) /* For internal kernel use */ + /* create a dumb scanout buffer */ struct drm_mode_create_dumb { __u32 height; From patchwork Mon Oct 21 21:45:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring \(Arm\)" X-Patchwork-Id: 177138 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp3977471ill; Mon, 21 Oct 2019 14:46:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqzJs5Mde5d8bQSjRv+OAlzVxEmDEyFWYBFDhNOTs2AGSq4ZQoq9kjozvp8MxuFmMQsIQq9z X-Received: by 2002:a17:902:724b:: with SMTP id c11mr146735pll.155.1571694366538; Mon, 21 Oct 2019 14:46:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571694366; cv=none; d=google.com; s=arc-20160816; b=K0VjJ68kPsoS+DDESASfeUbvzD36p9YujO1RBfgShxuKdQuhVDS3dGkSy0v7NJMC0s Sr7bwWJoUG7Q1+OgqkkI74RTb1iFVwlQjVOwDgVgdy3/kxxpD7T4+UsbAQFnpN9IJtJK druJpbf8KLoVj2sUOC6bA0vJ4NBWgv/nP5Kl29rMjaR5zBGAv2wTEp9EtZLP4jhJWTpa PXPg4dN7zR9nNMUGF20DzYrYMIniVOpPpyTfOhsu85m4pK7Zx7jpMZY6rgvyZwgsD2zh J64dBZn8zCbALk2fbrIQM9+Wpve2eUNxYZlVJqiJ3zZYVbAxD1Gb/E7s47dyK557lhPv Ig7A== 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=dPv8kF+DtUC4ScI2MYAES/8tVjpxSYQ47iNDSWOde0Q=; b=tDFqscdTGMNz85F0b01B6exDBFWB7aPb3bgZFRJlEH8lEv6quO+MqJa77f6BQcOexF X1f9zegltoofGHoim0hJFOsHRlgRQLJCLrFANPwK89+P5OdiL30sHu07xnFqn4gxyuI2 FJ4g995VwhE7OHpoyiMQAoD2erOad/Ax7UjjvvkU2fWJXyr//a3Oe29B2Ya9GQySS4YK vnz2SJNpPKtd+cg3UwRox8+OcdtH/xz0t1yFNdmJM4XCkd4VcCkT6Wps4iI54mC/R1LR iza2FD2A7Dky8yPr6weZNtybl8Tyqcmd27U4ZwRbmYeptsiXaljwcqZvTAuOBXJm0RjB UP2w== 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 a1si16069081pgw.544.2019.10.21.14.46.06 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 21 Oct 2019 14:46:06 -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 6D93C6E27A; Mon, 21 Oct 2019 21:46:05 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-oi1-f194.google.com (mail-oi1-f194.google.com [209.85.167.194]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9C9D26E277 for ; Mon, 21 Oct 2019 21:46:00 +0000 (UTC) Received: by mail-oi1-f194.google.com with SMTP id 83so12446205oii.1 for ; Mon, 21 Oct 2019 14:46:00 -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=dtmBYecTmxMYIL93VEKcTUybHl02f54X+UyJdNEnFs0=; b=fYet3nMNJj3F52K1ylvGd7+Lcgb9y8lKqSE8Zp+SQhZN9lqbFFkzblBxNmyVVabNLF jQNejhBIBF/bhPypb467IYPRQXqBdY+tJr9R118OIzPRShWuHnPwEx6ZHM0+zDNB3Clc GW2Xm8SUsnUQ9+V0KguV2MjhTN/gC+29axRqYnftnHRNl69gGA1SimRUHJeJjousSJJQ p7wRQMr2FtpaU+c+fvyaM0UPeDd0iOtcreAAwrQh7w9qHoIrpUCALV9z8qwwRFuxERQf Qohrpz7HoepMnhfrYxT0jGCzJe4RSQ9fzV+sKBtkNRxpkGZFuCVoNivE/If6cFXG+GY+ Myvw== X-Gm-Message-State: APjAAAWndQRK5P57hCw44s4zVVsSFELtxX5rfJfoPjXRlqxeBn8LUeO9 dfnvGJZ4ZBggMYBg1Aywx21CMaU= X-Received: by 2002:aca:bd08:: with SMTP id n8mr193003oif.107.1571694359449; Mon, 21 Oct 2019 14:45:59 -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.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2019 14:45:58 -0700 (PDT) From: Rob Herring To: dri-devel@lists.freedesktop.org Subject: [PATCH 3/6] drm/cma-helper: Use the dma_*_attr API variant Date: Mon, 21 Oct 2019 16:45:47 -0500 Message-Id: <20191021214550.1461-4-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 , 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-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" In preparation to allow DRM CMA users to adjust the DMA_ATTR_* flags, convert the CMA helper code to use the dma_*_attr APIs instead of the dma_*_wc variants. Only the DMA_ATTR_WRITE_COMBINE and DMA_ATTR_NO_WARN attributes are set in this commit, so there's no functional change. Cc: Maarten Lankhorst Cc: Maxime Ripard Cc: Sean Paul Cc: David Airlie Cc: Daniel Vetter Signed-off-by: Rob Herring Reviewed-by: Laurent Pinchart --- drivers/gpu/drm/drm_gem_cma_helper.c | 20 ++++++++++++-------- include/drm/drm_gem_cma_helper.h | 1 + 2 files changed, 13 insertions(+), 8 deletions(-) -- 2.20.1 diff --git a/drivers/gpu/drm/drm_gem_cma_helper.c b/drivers/gpu/drm/drm_gem_cma_helper.c index 12e98fb28229..4cebfe01e6ea 100644 --- a/drivers/gpu/drm/drm_gem_cma_helper.c +++ b/drivers/gpu/drm/drm_gem_cma_helper.c @@ -70,6 +70,7 @@ __drm_gem_cma_create(struct drm_device *drm, size_t size) goto error; } + cma_obj->dma_attrs |= DMA_ATTR_NO_WARN | DMA_ATTR_WRITE_COMBINE; return cma_obj; error: @@ -102,8 +103,9 @@ struct drm_gem_cma_object *drm_gem_cma_create(struct drm_device *drm, if (IS_ERR(cma_obj)) return cma_obj; - cma_obj->vaddr = dma_alloc_wc(drm->dev, size, &cma_obj->paddr, - GFP_KERNEL | __GFP_NOWARN); + cma_obj->vaddr = dma_alloc_attrs(drm->dev, size, &cma_obj->paddr, + GFP_KERNEL | __GFP_NOWARN, + cma_obj->dma_attrs); if (!cma_obj->vaddr) { dev_dbg(drm->dev, "failed to allocate buffer with size %zu\n", size); @@ -184,8 +186,9 @@ void drm_gem_cma_free_object(struct drm_gem_object *gem_obj) dma_buf_vunmap(gem_obj->import_attach->dmabuf, cma_obj->vaddr); drm_prime_gem_destroy(gem_obj, cma_obj->sgt); } else if (cma_obj->vaddr) { - dma_free_wc(gem_obj->dev->dev, cma_obj->base.size, - cma_obj->vaddr, cma_obj->paddr); + dma_free_attrs(gem_obj->dev->dev, cma_obj->base.size, + cma_obj->vaddr, cma_obj->paddr, + cma_obj->dma_attrs); } drm_gem_object_release(gem_obj); @@ -279,8 +282,9 @@ static int drm_gem_cma_mmap_obj(struct drm_gem_cma_object *cma_obj, vma->vm_flags &= ~VM_PFNMAP; vma->vm_pgoff = 0; - ret = dma_mmap_wc(cma_obj->base.dev->dev, vma, cma_obj->vaddr, - cma_obj->paddr, vma->vm_end - vma->vm_start); + ret = dma_mmap_attrs(cma_obj->base.dev->dev, vma, cma_obj->vaddr, + cma_obj->paddr, vma->vm_end - vma->vm_start, + cma_obj->dma_attrs); if (ret) drm_gem_vm_close(vma); @@ -434,8 +438,8 @@ struct sg_table *drm_gem_cma_prime_get_sg_table(struct drm_gem_object *obj) if (!sgt) return ERR_PTR(-ENOMEM); - ret = dma_get_sgtable(obj->dev->dev, sgt, cma_obj->vaddr, - cma_obj->paddr, obj->size); + ret = dma_get_sgtable_attrs(obj->dev->dev, sgt, cma_obj->vaddr, + cma_obj->paddr, obj->size, cma_obj->dma_attrs); if (ret < 0) goto out; diff --git a/include/drm/drm_gem_cma_helper.h b/include/drm/drm_gem_cma_helper.h index 947ac95eb24a..d042213c3595 100644 --- a/include/drm/drm_gem_cma_helper.h +++ b/include/drm/drm_gem_cma_helper.h @@ -24,6 +24,7 @@ struct drm_gem_cma_object { /* For objects with DMA memory allocated by GEM CMA */ void *vaddr; + unsigned long dma_attrs; }; #define to_drm_gem_cma_obj(gem_obj) \ 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); } From patchwork Mon Oct 21 21:45:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring \(Arm\)" X-Patchwork-Id: 177139 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp3977489ill; Mon, 21 Oct 2019 14:46:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqzvnAizz672o2ZO3o+bcbZYjOV5nzMBBjEFgZ4UKUTEWmKbb72TXqPkiRArnwzWsLA1kUYN X-Received: by 2002:a62:1c07:: with SMTP id c7mr277739pfc.48.1571694368747; Mon, 21 Oct 2019 14:46:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571694368; cv=none; d=google.com; s=arc-20160816; b=lXYpDZQlO29KbATcHEivhj6x81T0xdEvXWXSnj1MrvgsLE3ZnYF6T4C4waWqHwxT3A 1FS3s45uzRJ+o6iH9l47GvB4I1jwZW7g9PV7p0A4xle9oaDBiYa9wLEiz7gChaBGvk3j Ke0RS+MiUrkH4OnqUT+MpD/xuzAItzCQ9fAQJLt+jkNChADMmgS63ZZmGUpncHmIMeXz D0K2rSNUnDYexzjEpBh53qeqPE38bnNqbsuocHIVwjOLhXgPbmIxnntlgiUMuMV4CK4b rywBR3qNLdnlpe0EZpWBuc2kteOJEEvZFwzKjDp7RVjaoZ3GmqpuwQb9uMKC0K6Qc4D5 2cNw== 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=D7gJqZ/mrPS4vrWvdaKIiOeQoB104VAJoWVhjSQ6l4M=; b=v6106GTO1s1yiJ+LRIzIPI2CBRWUITTkU3KEqBEElMW/+VcH35p4388J4Lxhkh4/3v KiZoiZbMMBcWR6/u71NO4sOzJBuhB2MSjSM4I0y9xTX1ZtJbBWP2EBNv0RnaV6AgRy85 ad2zBSJo4XWw1GlCFY9oLRA8HtqLOnihOA3seVcJt4dTUwZyrYUESH0yLHIFEmsy4Xj6 SMHy9/GIUFk2EQ55wE7Yu2tEeKR2ArQ8nNel0s9pMCCXFDhqPbibJY/45fHq7B/ErYR0 aALeFaL3BNTAe3X2W28NZYfeoqwj9bS61bB8PXq/Hx3cOpB7t1pp37of7Ub2vWYiCzrh bP0w== 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 p26si16981086pgd.348.2019.10.21.14.46.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 21 Oct 2019 14:46:08 -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 A1D546E27C; Mon, 21 Oct 2019 21:46:05 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ot1-f67.google.com (mail-ot1-f67.google.com [209.85.210.67]) by gabe.freedesktop.org (Postfix) with ESMTPS id 526CA6E27A for ; Mon, 21 Oct 2019 21:46:04 +0000 (UTC) Received: by mail-ot1-f67.google.com with SMTP id s22so12367749otr.6 for ; Mon, 21 Oct 2019 14:46:04 -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=QQDw9NPftsDM5OhHs6ZNOxGtsrxVPosqKf8720sJxbM=; b=hEmvBS/AXI7bW1V52I0wmZyiGn3H7S4hYf0Iugtg2DUcAB9GchiYZhhzYgg2R5ayuZ JUnlcH10unKuDngSO/hf2Ht8T5Lh+3K1UChOPj+I0hPBFJy86bQf+dBRwIoGBjVFZGpB IL8qOkHyfONVcDMkv3NQMKuqsL8Jt6bI50TyxaCyJAy97oS+cGjKk/zJZgxFszuvb79d F5zYqZcI2DlQB/v2zNYv5iADL1bobg4C6S7KeXwe/V8Ed/KKVGA96dLdCRQw8OHSDQ6U kkbAtdv4vfXzrxefDN9gSms/GP7Nk02KrcE/PgzB8V1ggKaxuLJ2vwWMlG5N3NtVT4D4 lPbQ== X-Gm-Message-State: APjAAAXo03Glde0q63G/Otnzw3wtL/vA9NtpqD8rW9+I9iE2cWia94Qk VFhximEv1lrQ5J5VC1A10cFW63w= X-Received: by 2002:a9d:344a:: with SMTP id v68mr55638otb.85.1571694363240; Mon, 21 Oct 2019 14:46:03 -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.46.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2019 14:46:02 -0700 (PDT) From: Rob Herring To: dri-devel@lists.freedesktop.org Subject: [PATCH 5/6] drm/mediatek: Convert to use CMA helpers Date: Mon, 21 Oct 2019 16:45:49 -0500 Message-Id: <20191021214550.1461-6-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 , 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-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" The only reason the Mediatek driver doesn't use the CMA helpers is it sets DMA_ATTR_NO_KERNEL_MAPPING and does a vmap() on demand. Using vmap() is not even guaranteed to work as DMA buffers may not have a struct page. Now that the CMA helpers support setting DMA_ATTR_NO_KERNEL_MAPPING as needed or not, convert Mediatek driver to use CMA helpers. Cc: CK Hu Cc: Philipp Zabel Cc: David Airlie Cc: Daniel Vetter Cc: Matthias Brugger Cc: linux-arm-kernel@lists.infradead.org Cc: linux-mediatek@lists.infradead.org Signed-off-by: Rob Herring --- drivers/gpu/drm/mediatek/Makefile | 1 - drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 2 +- drivers/gpu/drm/mediatek/mtk_drm_drv.c | 28 +-- drivers/gpu/drm/mediatek/mtk_drm_fb.c | 1 - drivers/gpu/drm/mediatek/mtk_drm_gem.c | 289 ----------------------- drivers/gpu/drm/mediatek/mtk_drm_gem.h | 51 ---- drivers/gpu/drm/mediatek/mtk_drm_plane.c | 7 +- 7 files changed, 15 insertions(+), 364 deletions(-) delete mode 100644 drivers/gpu/drm/mediatek/mtk_drm_gem.c delete mode 100644 drivers/gpu/drm/mediatek/mtk_drm_gem.h diff --git a/drivers/gpu/drm/mediatek/Makefile b/drivers/gpu/drm/mediatek/Makefile index 82ae49c64221..50a50e86738f 100644 --- a/drivers/gpu/drm/mediatek/Makefile +++ b/drivers/gpu/drm/mediatek/Makefile @@ -8,7 +8,6 @@ mediatek-drm-y := mtk_disp_color.o \ mtk_drm_ddp_comp.o \ mtk_drm_drv.o \ mtk_drm_fb.o \ - mtk_drm_gem.o \ mtk_drm_plane.o \ mtk_dsi.o \ mtk_mipi_tx.o \ diff --git a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c index 34a731755791..638d57e8ac12 100644 --- a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c +++ b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c @@ -11,6 +11,7 @@ #include #include +#include #include #include @@ -18,7 +19,6 @@ #include "mtk_drm_crtc.h" #include "mtk_drm_ddp.h" #include "mtk_drm_ddp_comp.h" -#include "mtk_drm_gem.h" #include "mtk_drm_plane.h" /** diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.c b/drivers/gpu/drm/mediatek/mtk_drm_drv.c index 352b81a7a670..36f32507e5fb 100644 --- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c +++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c @@ -28,7 +28,6 @@ #include "mtk_drm_ddp_comp.h" #include "mtk_drm_drv.h" #include "mtk_drm_fb.h" -#include "mtk_drm_gem.h" #define DRIVER_NAME "mediatek" #define DRIVER_DESC "Mediatek SoC DRM" @@ -335,16 +334,14 @@ static void mtk_drm_kms_deinit(struct drm_device *drm) drm_mode_config_cleanup(drm); } -static const struct file_operations mtk_drm_fops = { - .owner = THIS_MODULE, - .open = drm_open, - .release = drm_release, - .unlocked_ioctl = drm_ioctl, - .mmap = mtk_drm_gem_mmap, - .poll = drm_poll, - .read = drm_read, - .compat_ioctl = drm_compat_ioctl, -}; +DEFINE_DRM_GEM_CMA_FOPS(mtk_drm_fops); + +static int mtk_drm_gem_dumb_create(struct drm_file *file_priv, + struct drm_device *dev, + struct drm_mode_create_dumb *args) +{ + return drm_gem_cma_dumb_create_internal(file_priv, dev, args); +} /* * We need to override this because the device used to import the memory is @@ -361,18 +358,15 @@ struct drm_gem_object *mtk_drm_gem_prime_import(struct drm_device *dev, static struct drm_driver mtk_drm_driver = { .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_ATOMIC, - .gem_free_object_unlocked = mtk_drm_gem_free_object, .gem_vm_ops = &drm_gem_cma_vm_ops, + .gem_create_object = drm_cma_gem_create_object_default_funcs, .dumb_create = mtk_drm_gem_dumb_create, .prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle, .gem_prime_import = mtk_drm_gem_prime_import, - .gem_prime_get_sg_table = mtk_gem_prime_get_sg_table, - .gem_prime_import_sg_table = mtk_gem_prime_import_sg_table, - .gem_prime_mmap = mtk_drm_gem_mmap_buf, - .gem_prime_vmap = mtk_drm_gem_prime_vmap, - .gem_prime_vunmap = mtk_drm_gem_prime_vunmap, + .gem_prime_import_sg_table = drm_gem_cma_prime_import_sg_table_vmap, + .gem_prime_mmap = drm_gem_prime_mmap, .fops = &mtk_drm_fops, .name = DRIVER_NAME, diff --git a/drivers/gpu/drm/mediatek/mtk_drm_fb.c b/drivers/gpu/drm/mediatek/mtk_drm_fb.c index 3f230a28a2dc..596b4d5ed002 100644 --- a/drivers/gpu/drm/mediatek/mtk_drm_fb.c +++ b/drivers/gpu/drm/mediatek/mtk_drm_fb.c @@ -14,7 +14,6 @@ #include "mtk_drm_drv.h" #include "mtk_drm_fb.h" -#include "mtk_drm_gem.h" static const struct drm_framebuffer_funcs mtk_drm_fb_funcs = { .create_handle = drm_gem_fb_create_handle, diff --git a/drivers/gpu/drm/mediatek/mtk_drm_gem.c b/drivers/gpu/drm/mediatek/mtk_drm_gem.c deleted file mode 100644 index ca672f1d140d..000000000000 --- a/drivers/gpu/drm/mediatek/mtk_drm_gem.c +++ /dev/null @@ -1,289 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (c) 2015 MediaTek Inc. - */ - -#include - -#include -#include -#include -#include - -#include "mtk_drm_drv.h" -#include "mtk_drm_gem.h" - -static struct mtk_drm_gem_obj *mtk_drm_gem_init(struct drm_device *dev, - unsigned long size) -{ - struct mtk_drm_gem_obj *mtk_gem_obj; - int ret; - - size = round_up(size, PAGE_SIZE); - - mtk_gem_obj = kzalloc(sizeof(*mtk_gem_obj), GFP_KERNEL); - if (!mtk_gem_obj) - return ERR_PTR(-ENOMEM); - - ret = drm_gem_object_init(dev, &mtk_gem_obj->base, size); - if (ret < 0) { - DRM_ERROR("failed to initialize gem object\n"); - kfree(mtk_gem_obj); - return ERR_PTR(ret); - } - - return mtk_gem_obj; -} - -struct mtk_drm_gem_obj *mtk_drm_gem_create(struct drm_device *dev, - size_t size, bool alloc_kmap) -{ - struct mtk_drm_private *priv = dev->dev_private; - struct mtk_drm_gem_obj *mtk_gem; - struct drm_gem_object *obj; - int ret; - - mtk_gem = mtk_drm_gem_init(dev, size); - if (IS_ERR(mtk_gem)) - return ERR_CAST(mtk_gem); - - obj = &mtk_gem->base; - - mtk_gem->dma_attrs = DMA_ATTR_WRITE_COMBINE; - - if (!alloc_kmap) - mtk_gem->dma_attrs |= DMA_ATTR_NO_KERNEL_MAPPING; - - mtk_gem->cookie = dma_alloc_attrs(priv->dma_dev, obj->size, - &mtk_gem->dma_addr, GFP_KERNEL, - mtk_gem->dma_attrs); - if (!mtk_gem->cookie) { - DRM_ERROR("failed to allocate %zx byte dma buffer", obj->size); - ret = -ENOMEM; - goto err_gem_free; - } - - if (alloc_kmap) - mtk_gem->kvaddr = mtk_gem->cookie; - - DRM_DEBUG_DRIVER("cookie = %p dma_addr = %pad size = %zu\n", - mtk_gem->cookie, &mtk_gem->dma_addr, - size); - - return mtk_gem; - -err_gem_free: - drm_gem_object_release(obj); - kfree(mtk_gem); - return ERR_PTR(ret); -} - -void mtk_drm_gem_free_object(struct drm_gem_object *obj) -{ - struct mtk_drm_gem_obj *mtk_gem = to_mtk_gem_obj(obj); - struct mtk_drm_private *priv = obj->dev->dev_private; - - if (mtk_gem->sg) - drm_prime_gem_destroy(obj, mtk_gem->sg); - else - dma_free_attrs(priv->dma_dev, obj->size, mtk_gem->cookie, - mtk_gem->dma_addr, mtk_gem->dma_attrs); - - /* release file pointer to gem object. */ - drm_gem_object_release(obj); - - kfree(mtk_gem); -} - -int mtk_drm_gem_dumb_create(struct drm_file *file_priv, struct drm_device *dev, - struct drm_mode_create_dumb *args) -{ - struct mtk_drm_gem_obj *mtk_gem; - int ret; - - args->pitch = DIV_ROUND_UP(args->width * args->bpp, 8); - args->size = args->pitch * args->height; - - mtk_gem = mtk_drm_gem_create(dev, args->size, false); - if (IS_ERR(mtk_gem)) - return PTR_ERR(mtk_gem); - - /* - * allocate a id of idr table where the obj is registered - * and handle has the id what user can see. - */ - ret = drm_gem_handle_create(file_priv, &mtk_gem->base, &args->handle); - if (ret) - goto err_handle_create; - - /* drop reference from allocate - handle holds it now. */ - drm_gem_object_put_unlocked(&mtk_gem->base); - - return 0; - -err_handle_create: - mtk_drm_gem_free_object(&mtk_gem->base); - return ret; -} - -static int mtk_drm_gem_object_mmap(struct drm_gem_object *obj, - struct vm_area_struct *vma) - -{ - int ret; - struct mtk_drm_gem_obj *mtk_gem = to_mtk_gem_obj(obj); - struct mtk_drm_private *priv = obj->dev->dev_private; - - /* - * dma_alloc_attrs() allocated a struct page table for mtk_gem, so clear - * VM_PFNMAP flag that was set by drm_gem_mmap_obj()/drm_gem_mmap(). - */ - vma->vm_flags &= ~VM_PFNMAP; - - ret = dma_mmap_attrs(priv->dma_dev, vma, mtk_gem->cookie, - mtk_gem->dma_addr, obj->size, mtk_gem->dma_attrs); - if (ret) - drm_gem_vm_close(vma); - - return ret; -} - -int mtk_drm_gem_mmap_buf(struct drm_gem_object *obj, struct vm_area_struct *vma) -{ - int ret; - - ret = drm_gem_mmap_obj(obj, obj->size, vma); - if (ret) - return ret; - - return mtk_drm_gem_object_mmap(obj, vma); -} - -int mtk_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma) -{ - struct drm_gem_object *obj; - int ret; - - ret = drm_gem_mmap(filp, vma); - if (ret) - return ret; - - obj = vma->vm_private_data; - - /* - * Set vm_pgoff (used as a fake buffer offset by DRM) to 0 and map the - * whole buffer from the start. - */ - vma->vm_pgoff = 0; - - return mtk_drm_gem_object_mmap(obj, vma); -} - -/* - * Allocate a sg_table for this GEM object. - * Note: Both the table's contents, and the sg_table itself must be freed by - * the caller. - * Returns a pointer to the newly allocated sg_table, or an ERR_PTR() error. - */ -struct sg_table *mtk_gem_prime_get_sg_table(struct drm_gem_object *obj) -{ - struct mtk_drm_gem_obj *mtk_gem = to_mtk_gem_obj(obj); - struct mtk_drm_private *priv = obj->dev->dev_private; - struct sg_table *sgt; - int ret; - - sgt = kzalloc(sizeof(*sgt), GFP_KERNEL); - if (!sgt) - return ERR_PTR(-ENOMEM); - - ret = dma_get_sgtable_attrs(priv->dma_dev, sgt, mtk_gem->cookie, - mtk_gem->dma_addr, obj->size, - mtk_gem->dma_attrs); - if (ret) { - DRM_ERROR("failed to allocate sgt, %d\n", ret); - kfree(sgt); - return ERR_PTR(ret); - } - - return sgt; -} - -struct drm_gem_object *mtk_gem_prime_import_sg_table(struct drm_device *dev, - struct dma_buf_attachment *attach, struct sg_table *sg) -{ - struct mtk_drm_gem_obj *mtk_gem; - int ret; - struct scatterlist *s; - unsigned int i; - dma_addr_t expected; - - mtk_gem = mtk_drm_gem_init(dev, attach->dmabuf->size); - - if (IS_ERR(mtk_gem)) - return ERR_CAST(mtk_gem); - - expected = sg_dma_address(sg->sgl); - for_each_sg(sg->sgl, s, sg->nents, i) { - if (sg_dma_address(s) != expected) { - DRM_ERROR("sg_table is not contiguous"); - ret = -EINVAL; - goto err_gem_free; - } - expected = sg_dma_address(s) + sg_dma_len(s); - } - - mtk_gem->dma_addr = sg_dma_address(sg->sgl); - mtk_gem->sg = sg; - - return &mtk_gem->base; - -err_gem_free: - kfree(mtk_gem); - return ERR_PTR(ret); -} - -void *mtk_drm_gem_prime_vmap(struct drm_gem_object *obj) -{ - struct mtk_drm_gem_obj *mtk_gem = to_mtk_gem_obj(obj); - struct sg_table *sgt; - struct sg_page_iter iter; - unsigned int npages; - unsigned int i = 0; - - if (mtk_gem->kvaddr) - return mtk_gem->kvaddr; - - sgt = mtk_gem_prime_get_sg_table(obj); - if (IS_ERR(sgt)) - return NULL; - - npages = obj->size >> PAGE_SHIFT; - mtk_gem->pages = kcalloc(npages, sizeof(*mtk_gem->pages), GFP_KERNEL); - if (!mtk_gem->pages) - goto out; - - for_each_sg_page(sgt->sgl, &iter, sgt->orig_nents, 0) { - mtk_gem->pages[i++] = sg_page_iter_page(&iter); - if (i > npages) - break; - } - mtk_gem->kvaddr = vmap(mtk_gem->pages, npages, VM_MAP, - pgprot_writecombine(PAGE_KERNEL)); - -out: - kfree((void *)sgt); - - return mtk_gem->kvaddr; -} - -void mtk_drm_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr) -{ - struct mtk_drm_gem_obj *mtk_gem = to_mtk_gem_obj(obj); - - if (!mtk_gem->pages) - return; - - vunmap(vaddr); - mtk_gem->kvaddr = 0; - kfree((void *)mtk_gem->pages); -} diff --git a/drivers/gpu/drm/mediatek/mtk_drm_gem.h b/drivers/gpu/drm/mediatek/mtk_drm_gem.h deleted file mode 100644 index ff9f976d9807..000000000000 --- a/drivers/gpu/drm/mediatek/mtk_drm_gem.h +++ /dev/null @@ -1,51 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (c) 2015 MediaTek Inc. - */ - -#ifndef _MTK_DRM_GEM_H_ -#define _MTK_DRM_GEM_H_ - -#include - -/* - * mtk drm buffer structure. - * - * @base: a gem object. - * - a new handle to this gem object would be created - * by drm_gem_handle_create(). - * @cookie: the return value of dma_alloc_attrs(), keep it for dma_free_attrs() - * @kvaddr: kernel virtual address of gem buffer. - * @dma_addr: dma address of gem buffer. - * @dma_attrs: dma attributes of gem buffer. - * - * P.S. this object would be transferred to user as kms_bo.handle so - * user can access the buffer through kms_bo.handle. - */ -struct mtk_drm_gem_obj { - struct drm_gem_object base; - void *cookie; - void *kvaddr; - dma_addr_t dma_addr; - unsigned long dma_attrs; - struct sg_table *sg; - struct page **pages; -}; - -#define to_mtk_gem_obj(x) container_of(x, struct mtk_drm_gem_obj, base) - -void mtk_drm_gem_free_object(struct drm_gem_object *gem); -struct mtk_drm_gem_obj *mtk_drm_gem_create(struct drm_device *dev, size_t size, - bool alloc_kmap); -int mtk_drm_gem_dumb_create(struct drm_file *file_priv, struct drm_device *dev, - struct drm_mode_create_dumb *args); -int mtk_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma); -int mtk_drm_gem_mmap_buf(struct drm_gem_object *obj, - struct vm_area_struct *vma); -struct sg_table *mtk_gem_prime_get_sg_table(struct drm_gem_object *obj); -struct drm_gem_object *mtk_gem_prime_import_sg_table(struct drm_device *dev, - struct dma_buf_attachment *attach, struct sg_table *sg); -void *mtk_drm_gem_prime_vmap(struct drm_gem_object *obj); -void mtk_drm_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr); - -#endif diff --git a/drivers/gpu/drm/mediatek/mtk_drm_plane.c b/drivers/gpu/drm/mediatek/mtk_drm_plane.c index 584a9ecadce6..8f256602f075 100644 --- a/drivers/gpu/drm/mediatek/mtk_drm_plane.c +++ b/drivers/gpu/drm/mediatek/mtk_drm_plane.c @@ -8,13 +8,14 @@ #include #include #include +#include +#include #include #include "mtk_drm_crtc.h" #include "mtk_drm_ddp_comp.h" #include "mtk_drm_drv.h" #include "mtk_drm_fb.h" -#include "mtk_drm_gem.h" #include "mtk_drm_plane.h" static const u32 formats[] = { @@ -108,7 +109,6 @@ static void mtk_plane_atomic_update(struct drm_plane *plane, struct drm_crtc *crtc = plane->state->crtc; struct drm_framebuffer *fb = plane->state->fb; struct drm_gem_object *gem; - struct mtk_drm_gem_obj *mtk_gem; unsigned int pitch, format; dma_addr_t addr; @@ -116,8 +116,7 @@ static void mtk_plane_atomic_update(struct drm_plane *plane, return; gem = fb->obj[0]; - mtk_gem = to_mtk_gem_obj(gem); - addr = mtk_gem->dma_addr; + addr = to_drm_gem_cma_obj(gem)->paddr; pitch = fb->pitches[0]; format = fb->format->format; From patchwork Mon Oct 21 21:45:50 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: 177141 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp3977556ill; Mon, 21 Oct 2019 14:46:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqwasXsDRdzYCSJ0iSVLXvqS4CmaO7zDBHkgJ6VCL+bEaRwTfKph/bZUpdhP/OWUXRPFD62f X-Received: by 2002:a17:90a:a882:: with SMTP id h2mr341181pjq.1.1571694373586; Mon, 21 Oct 2019 14:46:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571694373; cv=none; d=google.com; s=arc-20160816; b=M4JvDZW3Qg704c+DkNnayLTN+ootkhQNJgPDT2AbuFEB7Mag9O6U3xgfbQvRN/Pm7X s+qt04h+RA65QzbBZr1fBTPMC0WSc+ZOCtP201V3I4uMYPw961q8yGwvMNFvqyvtdp2Q dpjw2Q7WJBQj5OmWfw+wDAxWyHOd+Kng1w3Ch5ikKjDQXuwHy22ru/O38skhm+W6IFea gZSMp3/82Mw4RXAqCJGvObSecwFkt9GER08QYOJS66tFbw+Ppns2lYVuvZY0/AZ4pjHA hnHp4dkuzjJhayMVVqecHJ8Znvaaq8uRXEoUKQCdF+vG+hYZZg5bMAycehpyKhNyDeBU ZmQw== 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=wQByQ6j6e/o1qhQU/2TbfG2JSHgAAt5UrGmkw59RxJQ=; b=xyx5TPAhgpQu5mccoDW03KkY7P3O2H/gSlnAFtaS+OZ58fgK8+ogbfsFdU7ZruK949 aR/s0vwJWC6PVFfDdgD4iN90ClWi79DreDw0cVC9dBlFQXR0suUukS88rE1tJS/YwYZP LwJvAnbTUr21ANWB4wBu+oFEM48jAONo4W2owpDCEJK2Owc7K7zjsnPRaxbCar+M+tWw f8RIvmNi0b9T494gT6eE6XEVbeaPBuHKbXRrDq72A2F12qJpCBFQKYkAy8bJIK/gfXtT q1ZS1Loed8kaCIwkZk9AmaQ/8l7XiX4PpViyHevXVG4fNAkyhRCjiVY7eChqojF697mq 74Nw== 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 r24si17550617pfh.2.2019.10.21.14.46.13 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 21 Oct 2019 14:46:13 -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 3A3DF6E286; Mon, 21 Oct 2019 21:46:11 +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 696656E283 for ; Mon, 21 Oct 2019 21:46:06 +0000 (UTC) Received: by mail-ot1-f66.google.com with SMTP id o44so12373258ota.10 for ; Mon, 21 Oct 2019 14:46:06 -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=PYPtBAV4HvBXyxpYafYBRi+ornFWpusKrf/ucuegk3I=; b=Ufvr7jOomjZxgjP6+zZsh+ZOSQVp6zdS/LwX+smRhpqCnu3scFQiiPKrGkK7ZsB1om b/0zVMpwHFtGKCj84HM34Bm1FxCNhzit0LZtbn8fAuX1KRiuX1j8sNKgIyg0yFTvAZrj 5lftzNVFynwikeBoK+IsyYQm67QN4iOrlcZxXVcfUrml5J7WwqrguSGtOMKfgUQUasRI JzTrSI09LbKag9KgiM8rRdY5EC6ReRVbxVxYDs5FBWoowZoMx/nZHdl2GYenyzapEyJW kT9kG4VEUDYPcYgH4VB4f+yDaxxZ9mdMOKwF3HLhhdceRAAg6wDpeUwqFG7dUkzve1Wb eblQ== X-Gm-Message-State: APjAAAVd1oyY+hr5u0oRkgRw+dC/IS/LnEx1lk/z14NKYf/IB/gqYiwc YtR7HmeDlGKUB9Ofs+gYCc2w+QY= X-Received: by 2002:a9d:6f07:: with SMTP id n7mr89656otq.8.1571694365138; Mon, 21 Oct 2019 14:46:05 -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.46.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2019 14:46:04 -0700 (PDT) From: Rob Herring To: dri-devel@lists.freedesktop.org Subject: [PATCH 6/6] drm/rockchip: Convert to use generic fbdev emulation Date: Mon, 21 Oct 2019 16:45:50 -0500 Message-Id: <20191021214550.1461-7-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 , 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-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" Now that we have the DRM_MODE_DUMB_KERNEL_MAP flag to indicate whether or not a kernel mapping is required, the Rockchip driver can be converted to using the generic fbdev emulation. This patch makes full use of the generic fbdev emulation by using its drm_client callbacks. This means that drm_mode_config_funcs->output_poll_changed and drm_driver->lastclose are now handled by the emulation code. Additionally fbdev unregister happens automatically on drm_dev_unregister(). The drm_fbdev_generic_setup() call is put after drm_dev_register() in the driver. This is done to highlight the fact that fbdev emulation is an internal client that makes use of the driver, it is not part of the driver as such. If fbdev setup fails, an error is printed, but the driver succeeds probing. Cc: Noralf Trønnes Cc: Sandy Huang Cc: "Heiko Stübner" Cc: David Airlie Cc: Daniel Vetter Cc: linux-arm-kernel@lists.infradead.org Cc: linux-rockchip@lists.infradead.org Signed-off-by: Rob Herring --- drivers/gpu/drm/rockchip/Makefile | 1 - drivers/gpu/drm/rockchip/rockchip_drm_drv.c | 10 +- drivers/gpu/drm/rockchip/rockchip_drm_drv.h | 2 - drivers/gpu/drm/rockchip/rockchip_drm_fb.c | 14 -- drivers/gpu/drm/rockchip/rockchip_drm_fb.h | 6 - drivers/gpu/drm/rockchip/rockchip_drm_fbdev.c | 170 ------------------ drivers/gpu/drm/rockchip/rockchip_drm_fbdev.h | 24 --- drivers/gpu/drm/rockchip/rockchip_drm_gem.c | 5 +- drivers/gpu/drm/rockchip/rockchip_drm_gem.h | 4 - 9 files changed, 6 insertions(+), 230 deletions(-) delete mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_fbdev.c delete mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_fbdev.h diff --git a/drivers/gpu/drm/rockchip/Makefile b/drivers/gpu/drm/rockchip/Makefile index 17a9e7eb2130..1a56f696558c 100644 --- a/drivers/gpu/drm/rockchip/Makefile +++ b/drivers/gpu/drm/rockchip/Makefile @@ -5,7 +5,6 @@ rockchipdrm-y := rockchip_drm_drv.o rockchip_drm_fb.o \ rockchip_drm_gem.o rockchip_drm_vop.o rockchip_vop_reg.o -rockchipdrm-$(CONFIG_DRM_FBDEV_EMULATION) += rockchip_drm_fbdev.o rockchipdrm-$(CONFIG_ROCKCHIP_ANALOGIX_DP) += analogix_dp-rockchip.o rockchipdrm-$(CONFIG_ROCKCHIP_CDN_DP) += cdn-dp-core.o cdn-dp-reg.o diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c index 20ecb1508a22..95a489c481d5 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c @@ -25,7 +25,6 @@ #include "rockchip_drm_drv.h" #include "rockchip_drm_fb.h" -#include "rockchip_drm_fbdev.h" #include "rockchip_drm_gem.h" #define DRIVER_NAME "rockchip" @@ -156,10 +155,6 @@ static int rockchip_drm_bind(struct device *dev) */ drm_dev->irq_enabled = true; - ret = rockchip_drm_fbdev_init(drm_dev); - if (ret) - goto err_unbind_all; - /* init kms poll for handling hpd */ drm_kms_helper_poll_init(drm_dev); @@ -167,10 +162,11 @@ static int rockchip_drm_bind(struct device *dev) if (ret) goto err_kms_helper_poll_fini; + drm_fbdev_generic_setup(drm_dev, 32); + return 0; err_kms_helper_poll_fini: drm_kms_helper_poll_fini(drm_dev); - rockchip_drm_fbdev_fini(drm_dev); err_unbind_all: component_unbind_all(dev, drm_dev); err_mode_config_cleanup: @@ -189,7 +185,6 @@ static void rockchip_drm_unbind(struct device *dev) drm_dev_unregister(drm_dev); - rockchip_drm_fbdev_fini(drm_dev); drm_kms_helper_poll_fini(drm_dev); drm_atomic_helper_shutdown(drm_dev); @@ -215,7 +210,6 @@ static const struct file_operations rockchip_drm_driver_fops = { static struct drm_driver rockchip_drm_driver = { .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_ATOMIC, - .lastclose = drm_fb_helper_lastclose, .gem_vm_ops = &drm_gem_cma_vm_ops, .gem_free_object_unlocked = rockchip_gem_free_object, .dumb_create = rockchip_gem_dumb_create, diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_drv.h b/drivers/gpu/drm/rockchip/rockchip_drm_drv.h index c5b06048124e..397d6582aabe 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_drv.h +++ b/drivers/gpu/drm/rockchip/rockchip_drm_drv.h @@ -42,8 +42,6 @@ struct rockchip_crtc_state { * @mm_lock: protect drm_mm on multi-threads. */ struct rockchip_drm_private { - struct drm_fb_helper fbdev_helper; - struct drm_gem_object *fbdev_bo; struct iommu_domain *domain; struct mutex mm_lock; struct drm_mm mm; diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_fb.c b/drivers/gpu/drm/rockchip/rockchip_drm_fb.c index ca01234c037c..2c01074b0d3c 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_fb.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_fb.c @@ -116,20 +116,6 @@ static const struct drm_mode_config_funcs rockchip_drm_mode_config_funcs = { .atomic_commit = drm_atomic_helper_commit, }; -struct drm_framebuffer * -rockchip_drm_framebuffer_init(struct drm_device *dev, - const struct drm_mode_fb_cmd2 *mode_cmd, - struct drm_gem_object *obj) -{ - struct drm_framebuffer *fb; - - fb = rockchip_fb_alloc(dev, mode_cmd, &obj, 1); - if (IS_ERR(fb)) - return ERR_CAST(fb); - - return fb; -} - void rockchip_drm_mode_config_init(struct drm_device *dev) { dev->mode_config.min_width = 0; diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_fb.h b/drivers/gpu/drm/rockchip/rockchip_drm_fb.h index 1a696521096d..bae4e079dfb1 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_fb.h +++ b/drivers/gpu/drm/rockchip/rockchip_drm_fb.h @@ -7,11 +7,5 @@ #ifndef _ROCKCHIP_DRM_FB_H #define _ROCKCHIP_DRM_FB_H -struct drm_framebuffer * -rockchip_drm_framebuffer_init(struct drm_device *dev, - const struct drm_mode_fb_cmd2 *mode_cmd, - struct drm_gem_object *obj); -void rockchip_drm_framebuffer_fini(struct drm_framebuffer *fb); - void rockchip_drm_mode_config_init(struct drm_device *dev); #endif /* _ROCKCHIP_DRM_FB_H */ diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_fbdev.c b/drivers/gpu/drm/rockchip/rockchip_drm_fbdev.c deleted file mode 100644 index 02be6c5ff857..000000000000 --- a/drivers/gpu/drm/rockchip/rockchip_drm_fbdev.c +++ /dev/null @@ -1,170 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) Fuzhou Rockchip Electronics Co.Ltd - * Author:Mark Yao - */ - -#include -#include -#include -#include - -#include "rockchip_drm_drv.h" -#include "rockchip_drm_gem.h" -#include "rockchip_drm_fb.h" -#include "rockchip_drm_fbdev.h" - -#define PREFERRED_BPP 32 -#define to_drm_private(x) \ - container_of(x, struct rockchip_drm_private, fbdev_helper) - -static int rockchip_fbdev_mmap(struct fb_info *info, - struct vm_area_struct *vma) -{ - struct drm_fb_helper *helper = info->par; - struct rockchip_drm_private *private = to_drm_private(helper); - - return rockchip_gem_mmap_buf(private->fbdev_bo, vma); -} - -static struct fb_ops rockchip_drm_fbdev_ops = { - .owner = THIS_MODULE, - DRM_FB_HELPER_DEFAULT_OPS, - .fb_mmap = rockchip_fbdev_mmap, - .fb_fillrect = drm_fb_helper_cfb_fillrect, - .fb_copyarea = drm_fb_helper_cfb_copyarea, - .fb_imageblit = drm_fb_helper_cfb_imageblit, -}; - -static int rockchip_drm_fbdev_create(struct drm_fb_helper *helper, - struct drm_fb_helper_surface_size *sizes) -{ - struct rockchip_drm_private *private = to_drm_private(helper); - struct drm_mode_fb_cmd2 mode_cmd = { 0 }; - struct drm_device *dev = helper->dev; - struct rockchip_gem_object *rk_obj; - struct drm_framebuffer *fb; - unsigned int bytes_per_pixel; - unsigned long offset; - struct fb_info *fbi; - size_t size; - int ret; - - bytes_per_pixel = DIV_ROUND_UP(sizes->surface_bpp, 8); - - mode_cmd.width = sizes->surface_width; - mode_cmd.height = sizes->surface_height; - mode_cmd.pitches[0] = sizes->surface_width * bytes_per_pixel; - mode_cmd.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp, - sizes->surface_depth); - - size = mode_cmd.pitches[0] * mode_cmd.height; - - rk_obj = rockchip_gem_create_object(dev, size, true); - if (IS_ERR(rk_obj)) - return -ENOMEM; - - private->fbdev_bo = &rk_obj->base; - - fbi = drm_fb_helper_alloc_fbi(helper); - if (IS_ERR(fbi)) { - DRM_DEV_ERROR(dev->dev, "Failed to create framebuffer info.\n"); - ret = PTR_ERR(fbi); - goto out; - } - - helper->fb = rockchip_drm_framebuffer_init(dev, &mode_cmd, - private->fbdev_bo); - if (IS_ERR(helper->fb)) { - DRM_DEV_ERROR(dev->dev, - "Failed to allocate DRM framebuffer.\n"); - ret = PTR_ERR(helper->fb); - goto out; - } - - fbi->fbops = &rockchip_drm_fbdev_ops; - - fb = helper->fb; - drm_fb_helper_fill_info(fbi, helper, sizes); - - offset = fbi->var.xoffset * bytes_per_pixel; - offset += fbi->var.yoffset * fb->pitches[0]; - - dev->mode_config.fb_base = 0; - fbi->screen_base = rk_obj->kvaddr + offset; - fbi->screen_size = rk_obj->base.size; - fbi->fix.smem_len = rk_obj->base.size; - - DRM_DEBUG_KMS("FB [%dx%d]-%d kvaddr=%p offset=%ld size=%zu\n", - fb->width, fb->height, fb->format->depth, - rk_obj->kvaddr, - offset, size); - - return 0; - -out: - rockchip_gem_free_object(&rk_obj->base); - return ret; -} - -static const struct drm_fb_helper_funcs rockchip_drm_fb_helper_funcs = { - .fb_probe = rockchip_drm_fbdev_create, -}; - -int rockchip_drm_fbdev_init(struct drm_device *dev) -{ - struct rockchip_drm_private *private = dev->dev_private; - struct drm_fb_helper *helper; - int ret; - - if (!dev->mode_config.num_crtc || !dev->mode_config.num_connector) - return -EINVAL; - - helper = &private->fbdev_helper; - - drm_fb_helper_prepare(dev, helper, &rockchip_drm_fb_helper_funcs); - - ret = drm_fb_helper_init(dev, helper, ROCKCHIP_MAX_CONNECTOR); - if (ret < 0) { - DRM_DEV_ERROR(dev->dev, - "Failed to initialize drm fb helper - %d.\n", - ret); - return ret; - } - - ret = drm_fb_helper_single_add_all_connectors(helper); - if (ret < 0) { - DRM_DEV_ERROR(dev->dev, - "Failed to add connectors - %d.\n", ret); - goto err_drm_fb_helper_fini; - } - - ret = drm_fb_helper_initial_config(helper, PREFERRED_BPP); - if (ret < 0) { - DRM_DEV_ERROR(dev->dev, - "Failed to set initial hw config - %d.\n", - ret); - goto err_drm_fb_helper_fini; - } - - return 0; - -err_drm_fb_helper_fini: - drm_fb_helper_fini(helper); - return ret; -} - -void rockchip_drm_fbdev_fini(struct drm_device *dev) -{ - struct rockchip_drm_private *private = dev->dev_private; - struct drm_fb_helper *helper; - - helper = &private->fbdev_helper; - - drm_fb_helper_unregister_fbi(helper); - - if (helper->fb) - drm_framebuffer_put(helper->fb); - - drm_fb_helper_fini(helper); -} diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_fbdev.h b/drivers/gpu/drm/rockchip/rockchip_drm_fbdev.h deleted file mode 100644 index 5fb7ac2371a8..000000000000 --- a/drivers/gpu/drm/rockchip/rockchip_drm_fbdev.h +++ /dev/null @@ -1,24 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) Fuzhou Rockchip Electronics Co.Ltd - * Author:Mark Yao - */ - -#ifndef _ROCKCHIP_DRM_FBDEV_H -#define _ROCKCHIP_DRM_FBDEV_H - -#ifdef CONFIG_DRM_FBDEV_EMULATION -int rockchip_drm_fbdev_init(struct drm_device *dev); -void rockchip_drm_fbdev_fini(struct drm_device *dev); -#else -static inline int rockchip_drm_fbdev_init(struct drm_device *dev) -{ - return 0; -} - -static inline void rockchip_drm_fbdev_fini(struct drm_device *dev) -{ -} -#endif - -#endif /* _ROCKCHIP_DRM_FBDEV_H */ diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_gem.c b/drivers/gpu/drm/rockchip/rockchip_drm_gem.c index f09b9a035376..0562d7e30af5 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_gem.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_gem.c @@ -370,13 +370,14 @@ void rockchip_gem_free_object(struct drm_gem_object *obj) static struct rockchip_gem_object * rockchip_gem_create_with_handle(struct drm_file *file_priv, struct drm_device *drm, unsigned int size, + bool alloc_kmap, unsigned int *handle) { struct rockchip_gem_object *rk_obj; struct drm_gem_object *obj; int ret; - rk_obj = rockchip_gem_create_object(drm, size, false); + rk_obj = rockchip_gem_create_object(drm, size, alloc_kmap); if (IS_ERR(rk_obj)) return ERR_CAST(rk_obj); @@ -414,6 +415,7 @@ int rockchip_gem_dumb_create(struct drm_file *file_priv, { struct rockchip_gem_object *rk_obj; int min_pitch = DIV_ROUND_UP(args->width * args->bpp, 8); + bool alloc_kmap = args->flags & DRM_MODE_DUMB_KERNEL_MAP; /* * align to 64 bytes since Mali requires it. @@ -423,6 +425,7 @@ int rockchip_gem_dumb_create(struct drm_file *file_priv, args->size = args->pitch * args->height; rk_obj = rockchip_gem_create_with_handle(file_priv, dev, args->size, + alloc_kmap, &args->handle); return PTR_ERR_OR_ZERO(rk_obj); diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_gem.h b/drivers/gpu/drm/rockchip/rockchip_drm_gem.h index 7ffc541bea07..3a2e7065ab13 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_gem.h +++ b/drivers/gpu/drm/rockchip/rockchip_drm_gem.h @@ -41,10 +41,6 @@ int rockchip_gem_mmap(struct file *filp, struct vm_area_struct *vma); int rockchip_gem_mmap_buf(struct drm_gem_object *obj, struct vm_area_struct *vma); -struct rockchip_gem_object * - rockchip_gem_create_object(struct drm_device *drm, unsigned int size, - bool alloc_kmap); - void rockchip_gem_free_object(struct drm_gem_object *obj); int rockchip_gem_dumb_create(struct drm_file *file_priv,