From patchwork Tue Oct 15 11:33:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 11190163 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 214FD912 for ; Tue, 15 Oct 2019 11:33:27 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 093BD218DE for ; Tue, 15 Oct 2019 11:33:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 093BD218DE Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 053AC6E2C8; Tue, 15 Oct 2019 11:33:24 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by gabe.freedesktop.org (Postfix) with ESMTPS id E18626E7AD for ; Tue, 15 Oct 2019 11:33:21 +0000 (UTC) Received: by mail-wr1-x443.google.com with SMTP id z9so23401958wrl.11 for ; Tue, 15 Oct 2019 04:33:21 -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=qDD2ziTUH4iVa0dzLE+0MqtrcwtEloFCQjzGa/0salE=; b=M7IoFQVEiLz60BgmndaHx2lqAlRzWQljhSmoUw0wjg70RlQ6BFU2Y19WL4m2SUX+xu sqfZN7/Mbiv+ss2g5GstcIvJF62SFB/XwmUpw/qy5j3pEF4wxWNbRCVV8pGMSRovjiF8 aYq+yLK/l7iUoBPqo7snsFqkJY+v9Ld7S66dytUpTc5J1fMLh2hjVoreRnnd1/TN3LzP OOrV3xgoVXoVvqMSD1Jd20/4+pV4HWUEDYNx1kz3cKJZrpwv86BQbAizc3yirM60euai voQMgNGTKKwvJk27pcgFcgxs7wWOty7mkCH+czNri6i61+wsxCbbhTQRf9DNTsZzzR0n FsQQ== X-Gm-Message-State: APjAAAUMUmbDkpc1cxEQ8bZUmpMxCOuTsJg6BWmCIkzYZ50viWqfTiZQ Jf4Uq0TTbtHSKhl04QMM0sCL0e6HOCscqA== X-Google-Smtp-Source: APXvYqzvHDrAswuxfaKhLlsc6gVx/1CV0JI9RaDviWLgIieIrtHFyZ5gMV1lLmSdngWnO/oDbDSaIA== X-Received: by 2002:a5d:50c9:: with SMTP id f9mr28942541wrt.36.1571139200081; Tue, 15 Oct 2019 04:33:20 -0700 (PDT) Received: from bender.baylibre.local (lmontsouris-657-1-212-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.gmail.com with ESMTPSA id 63sm32395096wri.25.2019.10.15.04.33.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Oct 2019 04:33:19 -0700 (PDT) From: Neil Armstrong To: dri-devel@lists.freedesktop.org Subject: [PATCH 1/3] drm/meson: add RDMA register bits defines Date: Tue, 15 Oct 2019 13:33:15 +0200 Message-Id: <20191015113317.8870-2-narmstrong@baylibre.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20191015113317.8870-1-narmstrong@baylibre.com> References: <20191015113317.8870-1-narmstrong@baylibre.com> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qDD2ziTUH4iVa0dzLE+0MqtrcwtEloFCQjzGa/0salE=; b=UKUn63uYSPaK29ydxiYmSknSs81jDHNuTMRX1J5rZqWRKtzQRtgYKONVZBUv4gEPso 5GeJinkiduOh0IbwrGej/wJPrKKqCP0ASaiobuINL9/sQoCl4eBw1LHdGEZ+qgUqdIhL is6wfVj2XvWrXp9TvdGXppR4eGhs3YvjUht8aBRq8xi4UWX+88iPKhcyVYgNWHU4ZGg0 utp8lrJFUvERfqO7bMuSCegmjZCKVbEmA0HFyJmDKkZLVPcpXycMW3Qx/Q/XRA/+Xcu3 OL2BJHCuipRRgJZnImMjaXbO9cYA4zwpBcAzc2cFSAxp1QChHTL9iIJ5wi2ZjOQrNG+J lHUA== 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: khilman@baylibre.com, linux-amlogic@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Neil Armstrong Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The Amlogic VPU embeds a "Register DMA" that can write a sequence of registers on the VPU AHB bus, either manually or triggered by an internal IRQ event like VSYNC or a line input counter. This adds the register defines. Signed-off-by: Neil Armstrong --- drivers/gpu/drm/meson/meson_registers.h | 48 +++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/drivers/gpu/drm/meson/meson_registers.h b/drivers/gpu/drm/meson/meson_registers.h index 547bee04b46e..8ea00546cd4e 100644 --- a/drivers/gpu/drm/meson/meson_registers.h +++ b/drivers/gpu/drm/meson/meson_registers.h @@ -1211,11 +1211,59 @@ #define RDMA_AHB_START_ADDR_7 0x110e #define RDMA_AHB_END_ADDR_7 0x110f #define RDMA_ACCESS_AUTO 0x1110 +#define RDMA_ACCESS_TRIGGER_CHAN3 GENMASK(31, 24) +#define RDMA_ACCESS_TRIGGER_CHAN2 GENMASK(23, 16) +#define RDMA_ACCESS_TRIGGER_CHAN1 GENMASK(15, 8) +#define RDMA_ACCESS_TRIGGER_STOP 0 +#define RDMA_ACCESS_TRIGGER_VSYNC 1 +#define RDMA_ACCESS_TRIGGER_LINE 32 +#define RDMA_ACCESS_RW_FLAG_CHAN3 BIT(7) +#define RDMA_ACCESS_RW_FLAG_CHAN2 BIT(6) +#define RDMA_ACCESS_RW_FLAG_CHAN1 BIT(5) +#define RDMA_ACCESS_ADDR_INC_CHAN3 BIT(3) +#define RDMA_ACCESS_ADDR_INC_CHAN2 BIT(2) +#define RDMA_ACCESS_ADDR_INC_CHAN1 BIT(1) #define RDMA_ACCESS_AUTO2 0x1111 +#define RDMA_ACCESS_RW_FLAG_CHAN7 BIT(7) +#define RDMA_ACCESS_RW_FLAG_CHAN6 BIT(6) +#define RDMA_ACCESS_RW_FLAG_CHAN5 BIT(5) +#define RDMA_ACCESS_RW_FLAG_CHAN4 BIT(4) +#define RDMA_ACCESS_ADDR_INC_CHAN7 BIT(3) +#define RDMA_ACCESS_ADDR_INC_CHAN6 BIT(2) +#define RDMA_ACCESS_ADDR_INC_CHAN5 BIT(1) +#define RDMA_ACCESS_ADDR_INC_CHAN4 BIT(0) #define RDMA_ACCESS_AUTO3 0x1112 +#define RDMA_ACCESS_TRIGGER_CHAN7 GENMASK(31, 24) +#define RDMA_ACCESS_TRIGGER_CHAN6 GENMASK(23, 16) +#define RDMA_ACCESS_TRIGGER_CHAN5 GENMASK(15, 8) +#define RDMA_ACCESS_TRIGGER_CHAN4 GENMASK(7, 0) #define RDMA_ACCESS_MAN 0x1113 +#define RDMA_ACCESS_MAN_RW_FLAG BIT(2) +#define RDMA_ACCESS_MAN_ADDR_INC BIT(1) +#define RDMA_ACCESS_MAN_START BIT(0) #define RDMA_CTRL 0x1114 +#define RDMA_IRQ_CLEAR_CHAN7 BIT(31) +#define RDMA_IRQ_CLEAR_CHAN6 BIT(30) +#define RDMA_IRQ_CLEAR_CHAN5 BIT(29) +#define RDMA_IRQ_CLEAR_CHAN4 BIT(28) +#define RDMA_IRQ_CLEAR_CHAN3 BIT(27) +#define RDMA_IRQ_CLEAR_CHAN2 BIT(26) +#define RDMA_IRQ_CLEAR_CHAN1 BIT(25) +#define RDMA_IRQ_CLEAR_CHAN_MAN BIT(24) +#define RDMA_DEFAULT_CONFIG (BIT(7) | BIT(6)) +#define RDMA_CTRL_AHB_WR_BURST GENMASK(5, 4) +#define RDMA_CTRL_AHB_RD_BURST GENMASK(3, 2) +#define RDMA_CTRL_SW_RESET BIT(1) +#define RDMA_CTRL_FREE_CLK_EN BIT(0) #define RDMA_STATUS 0x1115 +#define RDMA_IRQ_STAT_CHAN7 BIT(31) +#define RDMA_IRQ_STAT_CHAN6 BIT(30) +#define RDMA_IRQ_STAT_CHAN5 BIT(29) +#define RDMA_IRQ_STAT_CHAN4 BIT(28) +#define RDMA_IRQ_STAT_CHAN3 BIT(27) +#define RDMA_IRQ_STAT_CHAN2 BIT(26) +#define RDMA_IRQ_STAT_CHAN1 BIT(25) +#define RDMA_IRQ_STAT_CHAN_MAN BIT(24) #define RDMA_STATUS2 0x1116 #define RDMA_STATUS3 0x1117 #define L_GAMMA_CNTL_PORT 0x1400 From patchwork Tue Oct 15 11:33:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 11190165 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 A86A2912 for ; Tue, 15 Oct 2019 11:33:29 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 9095521848 for ; Tue, 15 Oct 2019 11:33:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9095521848 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C481C6E7AD; Tue, 15 Oct 2019 11:33:25 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by gabe.freedesktop.org (Postfix) with ESMTPS id E676D6E2C8 for ; Tue, 15 Oct 2019 11:33:22 +0000 (UTC) Received: by mail-wr1-x441.google.com with SMTP id p14so23408788wro.4 for ; Tue, 15 Oct 2019 04:33:22 -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=XD8DbPS/ne8UaQDhNONqYd7ghmzPvUyX1U8dT7qrutE=; b=RgAqpXUQ5V0tpv7LRPhzgYy13+S+iBd+pD4fDcYrPeU08W/j0Ivz8KQ/SDiY68AuIz OUVQTb6JRFyylqAmoImGrSLB5hGAw2yqr1RBCmPvWrtTRoLMe0DfVXkEKKSEbluao63K yFCuRHtr9BBAQ7ZtDZaVfTU/OUK0DCsBPWQO17XqV4zfvNp2pROKD+LOw7SVIZ/mf+yg UJhTE7cjisceWtAWlB4GidAsr7i4cGNsQHRhxrR46B260NhTDVMrfAT+Yo26z/XtitgJ koD4RYVrmgi4ijqkSdcuz1oW46yNHDQH6SSkNGiZM2pJe8tZNfkQxVXiFBOEDG5Bm/WC UJ6g== X-Gm-Message-State: APjAAAXh/LviMhXIZaN8OGtInzKQtjUngteCbpiikDA4P7Sm4tWkAKFM IaURqWkVfEPNSe4Tl9zfpGQsW+I+h4g0tg== X-Google-Smtp-Source: APXvYqz3/ywYvl/yxSTgmzwEzMwNVIMbEibD2CeaLA2BdzUCSeyNo38qIG9VG3Gn1s8EEwD5aZnjkQ== X-Received: by 2002:adf:cc8e:: with SMTP id p14mr32243806wrj.301.1571139200760; Tue, 15 Oct 2019 04:33:20 -0700 (PDT) Received: from bender.baylibre.local (lmontsouris-657-1-212-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.gmail.com with ESMTPSA id 63sm32395096wri.25.2019.10.15.04.33.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Oct 2019 04:33:20 -0700 (PDT) From: Neil Armstrong To: dri-devel@lists.freedesktop.org Subject: [PATCH 2/3] drm/meson: add RDMA module driver Date: Tue, 15 Oct 2019 13:33:16 +0200 Message-Id: <20191015113317.8870-3-narmstrong@baylibre.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20191015113317.8870-1-narmstrong@baylibre.com> References: <20191015113317.8870-1-narmstrong@baylibre.com> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XD8DbPS/ne8UaQDhNONqYd7ghmzPvUyX1U8dT7qrutE=; b=sTOUlTSqbfOR8WzwLDXV6yG6Z9aZKsrcpdiNzhvasyfpICO2KPmjYjQnkWJomOYXzq 7dqF8grMJWWWcJrG/5DxoUy0RBqLVuzfaXcS1BQOIiWiKJjiCg0/rchM5UENSbKvn52K AVnz3oInfGvkKF9AKiy8Qn62DNx2SalFP6Cb+WDHqYVJU3AibtkJdlgXdpn/AshicxLG dygpvlVEXSReT/2G2u+gQvzBRMbGq2t2LD0vtHCTz5R6HNU3zuGNV7GO2M7MtzPU0pL5 UOL7GghYHRrt/JxjWWy4xTsuRmWWbaWByAFX/m1HnzAZID2aeYKCPdDh++kyFNrijqmD 7x3w== 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: khilman@baylibre.com, linux-amlogic@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Neil Armstrong Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The VPU embeds a "Register DMA" that can write a sequence of registers on the VPU AHB bus, either manually or triggered by an internal IRQ event like VSYNC or a line input counter. The initial implementation handles a single channel (over 8), triggered by the VSYNC irq and does not handle the RDMA irq. The RDMA will be usefull to reset and program the AFBC decoder unit on each vsync without involving the interrupt handler that can be masked for a long period of time, producing display glitches. Signed-off-by: Neil Armstrong --- drivers/gpu/drm/meson/Makefile | 2 +- drivers/gpu/drm/meson/meson_drv.c | 14 +++- drivers/gpu/drm/meson/meson_drv.h | 6 ++ drivers/gpu/drm/meson/meson_rdma.c | 123 +++++++++++++++++++++++++++++ drivers/gpu/drm/meson/meson_rdma.h | 20 +++++ 5 files changed, 161 insertions(+), 4 deletions(-) create mode 100644 drivers/gpu/drm/meson/meson_rdma.c create mode 100644 drivers/gpu/drm/meson/meson_rdma.h diff --git a/drivers/gpu/drm/meson/Makefile b/drivers/gpu/drm/meson/Makefile index b1fa055aaed3..9e36f0c7b816 100644 --- a/drivers/gpu/drm/meson/Makefile +++ b/drivers/gpu/drm/meson/Makefile @@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only meson-drm-y := meson_drv.o meson_plane.o meson_crtc.o meson_venc_cvbs.o meson-drm-y += meson_viu.o meson_vpp.o meson_venc.o meson_vclk.o meson_overlay.o -meson-drm-y += meson_osd_afbcd.o +meson-drm-y += meson_osd_afbcd.o meson_rdma.o obj-$(CONFIG_DRM_MESON) += meson-drm.o obj-$(CONFIG_DRM_MESON_DW_HDMI) += meson_dw_hdmi.o diff --git a/drivers/gpu/drm/meson/meson_drv.c b/drivers/gpu/drm/meson/meson_drv.c index 0f31e70bb94f..2200d8b5252e 100644 --- a/drivers/gpu/drm/meson/meson_drv.c +++ b/drivers/gpu/drm/meson/meson_drv.c @@ -33,6 +33,7 @@ #include "meson_venc_cvbs.h" #include "meson_viu.h" #include "meson_vpp.h" +#include "meson_rdma.h" #define DRIVER_NAME "meson" #define DRIVER_DESC "Amlogic Meson DRM driver" @@ -295,8 +296,11 @@ static int meson_drv_bind_master(struct device *dev, bool has_components) meson_venc_init(priv); meson_vpp_init(priv); meson_viu_init(priv); - if (priv->afbcd.ops) - priv->afbcd.ops->init(priv); + if (priv->afbcd.ops) { + ret = priv->afbcd.ops->init(priv); + if (ret) + return ret; + } /* Encoder Initialization */ @@ -367,12 +371,16 @@ static void meson_drv_unbind(struct device *dev) meson_canvas_free(priv->canvas, priv->canvas_id_vd1_2); } + if (priv->afbcd.ops) { + priv->afbcd.ops->reset(priv); + meson_rdma_free(priv); + } + drm_dev_unregister(drm); drm_irq_uninstall(drm); drm_kms_helper_poll_fini(drm); drm_mode_config_cleanup(drm); drm_dev_put(drm); - } static const struct component_master_ops meson_drv_master_ops = { diff --git a/drivers/gpu/drm/meson/meson_drv.h b/drivers/gpu/drm/meson/meson_drv.h index de25349be8aa..9995d74c5ded 100644 --- a/drivers/gpu/drm/meson/meson_drv.h +++ b/drivers/gpu/drm/meson/meson_drv.h @@ -139,6 +139,12 @@ struct meson_drm { u64 modifier; u32 format; } afbcd; + + struct { + dma_addr_t addr_phys; + uint32_t *addr; + unsigned int offset; + } rdma; }; static inline int meson_vpu_is_compatible(struct meson_drm *priv, diff --git a/drivers/gpu/drm/meson/meson_rdma.c b/drivers/gpu/drm/meson/meson_rdma.c new file mode 100644 index 000000000000..13fd9b173439 --- /dev/null +++ b/drivers/gpu/drm/meson/meson_rdma.c @@ -0,0 +1,123 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2019 BayLibre, SAS + * Author: Neil Armstrong + */ + +#include +#include + +#include "meson_drv.h" +#include "meson_registers.h" +#include "meson_rdma.h" + +/* + * The VPU embeds a "Register DMA" that can write a sequence of registers + * on the VPU AHB bus, either manually or triggered by an internal IRQ + * event like VSYNC or a line input counter. + * The initial implementation handles a single channel (over 8), triggered + * by the VSYNC irq and does not handle the RDMA irq. + */ + +int meson_rdma_init(struct meson_drm *priv) +{ + /* Allocate a PAGE buffer */ + priv->rdma.addr = dma_alloc_coherent(priv->dev, SZ_4K, + &priv->rdma.addr_phys, + GFP_KERNEL); + if (!priv->rdma.addr) + return -ENOMEM; + + priv->rdma.offset = 0; + + writel_relaxed(RDMA_CTRL_SW_RESET, + priv->io_base + _REG(RDMA_CTRL)); + writel_relaxed(RDMA_DEFAULT_CONFIG | + FIELD_PREP(RDMA_CTRL_AHB_WR_BURST, 3) | + FIELD_PREP(RDMA_CTRL_AHB_RD_BURST, 0), + priv->io_base + _REG(RDMA_CTRL)); + + return 0; +} + +void meson_rdma_free(struct meson_drm *priv) +{ + if (!priv->rdma.addr && !priv->rdma.addr_phys) + return; + + meson_rdma_stop(priv); + + dma_free_coherent(priv->dev, SZ_4K, + priv->rdma.addr, priv->rdma.addr_phys); + + priv->rdma.addr = NULL; + priv->rdma.addr_phys = (dma_addr_t)NULL; +} + +void meson_rdma_setup(struct meson_drm *priv) +{ + /* Channel 1: Write Flag, No Address Increment */ + writel_bits_relaxed(RDMA_ACCESS_RW_FLAG_CHAN1 | + RDMA_ACCESS_ADDR_INC_CHAN1, + RDMA_ACCESS_RW_FLAG_CHAN1, + priv->io_base + _REG(RDMA_ACCESS_AUTO)); +} + +void meson_rdma_stop(struct meson_drm *priv) +{ + writel_bits_relaxed(RDMA_IRQ_CLEAR_CHAN1, + RDMA_IRQ_CLEAR_CHAN1, + priv->io_base + _REG(RDMA_CTRL)); + + /* Stop Channel 1 */ + writel_bits_relaxed(RDMA_ACCESS_TRIGGER_CHAN1, + FIELD_PREP(RDMA_ACCESS_ADDR_INC_CHAN1, + RDMA_ACCESS_TRIGGER_STOP), + priv->io_base + _REG(RDMA_ACCESS_AUTO)); +} + +static void meson_rdma_writel(struct meson_drm *priv, uint32_t val, + uint32_t reg) +{ + if (priv->rdma.offset == SZ_4K) { + dev_warn_once(priv->dev, "%s: overflow\n", __func__); + return; + } + + priv->rdma.addr[priv->rdma.offset++] = reg; + priv->rdma.addr[priv->rdma.offset++] = val; +} + +/* + * This will add the register to the RDMA buffer and write it to the + * hardware at the same time. + * When meson_rdma_flush is called, the RDMA will replay the register + * writes in order. + */ +void meson_rdma_writel_sync(struct meson_drm *priv, uint32_t val, uint32_t reg) +{ + meson_rdma_writel(priv, val, reg); + + writel_relaxed(val, priv->io_base + _REG(reg)); +} + +void meson_rdma_flush(struct meson_drm *priv) +{ + meson_rdma_stop(priv); + + /* Start of Channel 1 register writes buffer */ + writel(priv->rdma.addr_phys, + priv->io_base + _REG(RDMA_AHB_START_ADDR_1)); + + /* Last byte on Channel 1 register writes buffer */ + writel(priv->rdma.addr_phys + (priv->rdma.offset * 8) - 1, + priv->io_base + _REG(RDMA_AHB_END_ADDR_1)); + + /* Trigger Channel 1 on VSYNC event */ + writel_bits_relaxed(RDMA_ACCESS_TRIGGER_CHAN1, + FIELD_PREP(RDMA_ACCESS_TRIGGER_CHAN1, + RDMA_ACCESS_TRIGGER_VSYNC), + priv->io_base + _REG(RDMA_ACCESS_AUTO)); + + priv->rdma.offset = 0; +} diff --git a/drivers/gpu/drm/meson/meson_rdma.h b/drivers/gpu/drm/meson/meson_rdma.h new file mode 100644 index 000000000000..84c882f97d28 --- /dev/null +++ b/drivers/gpu/drm/meson/meson_rdma.h @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (C) 2019 BayLibre, SAS + * Author: Neil Armstrong + */ + +#ifndef __MESON_RDMA_H +#define __MESON_RDMA_H + +#include "meson_drv.h" + +int meson_rdma_init(struct meson_drm *priv); +void meson_rdma_free(struct meson_drm *priv); +void meson_rdma_setup(struct meson_drm *priv); +void meson_rdma_stop(struct meson_drm *priv); + +void meson_rdma_writel_sync(struct meson_drm *priv, uint32_t val, uint32_t reg); +void meson_rdma_flush(struct meson_drm *priv); + +#endif /* __MESON_RDMA_H */ From patchwork Tue Oct 15 11:33:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 11190171 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 8D28D912 for ; Tue, 15 Oct 2019 11:33:33 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 75C9621848 for ; Tue, 15 Oct 2019 11:33:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 75C9621848 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 220696E7AF; Tue, 15 Oct 2019 11:33:28 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6A3786E7AD for ; Tue, 15 Oct 2019 11:33:23 +0000 (UTC) Received: by mail-wm1-x344.google.com with SMTP id m18so19909333wmc.1 for ; Tue, 15 Oct 2019 04:33:23 -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=KGLJVsNqev2Pu0SrD3On1A2o4/VJ1lpv7UIRH8Pz9IM=; b=FzwObAaOKTuzLT7ZND+mkPItrXySfxN5E5yyGzufg56jeuoTljSjoLIJOVHVVM6R/E FxTX5aHKLeys2/MIJhwto13DUTL8dHJ8ReHVFqLbnwTn6K+xxDBb3HKazw9evuZvAmLb pn8XSRM/r/p3tsiPOk30oGlL7poXd0EbAEpL5SIU+jpBpA00nMQ5ZFdD5KJDp/8Sc74e swqkOzT2gMSOPuBGBK1VVE0zjRLErMAx9MTYmtwHEUJyqBoPWepKelrkGH4DSWCIXEeC 1BMw76o2bKKc3wXLMacbN6+kDFBxCTL2/eaLCT/HUHIcpWY59JdSsq0qCCXoC0RCbv5U +BMQ== X-Gm-Message-State: APjAAAUvZli4vUUMzAy0Kd7YErFzX1djvyoOKqAZyCfWhoOmYacd1K01 5hWTnj1/ygfINfHyimfrQJQWRhpk8OZa2A== X-Google-Smtp-Source: APXvYqzZdAXaUpGAPplnWQNtzhFSJwWdMt0J26CbY0jWOEEM95qMYh3DeBdhVnwqT9/M00AH/gVeTQ== X-Received: by 2002:a7b:ce12:: with SMTP id m18mr18640193wmc.108.1571139201527; Tue, 15 Oct 2019 04:33:21 -0700 (PDT) Received: from bender.baylibre.local (lmontsouris-657-1-212-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.gmail.com with ESMTPSA id 63sm32395096wri.25.2019.10.15.04.33.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Oct 2019 04:33:21 -0700 (PDT) From: Neil Armstrong To: dri-devel@lists.freedesktop.org Subject: [PATCH 3/3] drm/meson: use RDMA to reconfigure AFBC on vsync Date: Tue, 15 Oct 2019 13:33:17 +0200 Message-Id: <20191015113317.8870-4-narmstrong@baylibre.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20191015113317.8870-1-narmstrong@baylibre.com> References: <20191015113317.8870-1-narmstrong@baylibre.com> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KGLJVsNqev2Pu0SrD3On1A2o4/VJ1lpv7UIRH8Pz9IM=; b=l5IXnpYGo3Y6+5Ol9NmoMngdaTzKCwQ1j6TfH4/PaDlVfRX0bKuSvifFb4BCW2dnJn C/Vw0/attmUWpVUPr7UGHwndNl4jgHWjquQ0NZq4DtuxqJT0khDV+sjIeZRHQVPUbpsX j8QCKdzuEL9w9pijBhzfAVm46CEKGO9k2YT3hMKEdnfd7LmvRaGKubWu9BZjWCx9lMtQ LhKOIH1JcgKdAQN1jNLAkU16iHE98x0DT2B/wYafaTaRNrJFBnrlOsj2JTwIpFKagYu8 ZyMp0qQrGsEkp3IvoPpo8EwlxhLdUWornqgjGUmi4UBLdbBRKjg0U9FUsMOLH5qBv7sm K3gg== 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: khilman@baylibre.com, linux-amlogic@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Neil Armstrong Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The VPU embeds a "Register DMA" that can write a sequence of registers on the VPU AHB bus, either manually or triggered by an internal IRQ event like VSYNC or a line input counter. The RDMA is used here to reset and program the AFBC decoder unit on each vsync without involving the interrupt handler that can be masked for a long period of time, producing display glitches. For this we use the meson_rdma_writel_sync() which adds the register write tuple (VPU register offset and register value) to the RDMA buffer and write the value to the HW. When enabled, the RDMA is enabled to rewritte the same sequence at the next VSYNC event, until a new buffer is committed to the OSD plane. The the Amlogic G12A is switched to RDMA, the Amlogic GXM Decoder doesn't need a reset/reprogram at each vsync. Signed-off-by: Neil Armstrong --- drivers/gpu/drm/meson/meson_crtc.c | 27 ++----- drivers/gpu/drm/meson/meson_osd_afbcd.c | 100 ++++++++++++++---------- 2 files changed, 64 insertions(+), 63 deletions(-) diff --git a/drivers/gpu/drm/meson/meson_crtc.c b/drivers/gpu/drm/meson/meson_crtc.c index d28efd0dbf11..8e0cf03e45eb 100644 --- a/drivers/gpu/drm/meson/meson_crtc.c +++ b/drivers/gpu/drm/meson/meson_crtc.c @@ -23,6 +23,7 @@ #include "meson_registers.h" #include "meson_venc.h" #include "meson_viu.h" +#include "meson_rdma.h" #include "meson_vpp.h" #include "meson_osd_afbcd.h" @@ -39,8 +40,6 @@ struct meson_crtc { void (*enable_osd1_afbc)(struct meson_drm *priv); void (*disable_osd1_afbc)(struct meson_drm *priv); unsigned int viu_offset; - bool vsync_forced; - bool vsync_disabled; }; #define to_meson_crtc(x) container_of(x, struct meson_crtc, base) @@ -51,7 +50,6 @@ static int meson_crtc_enable_vblank(struct drm_crtc *crtc) struct meson_crtc *meson_crtc = to_meson_crtc(crtc); struct meson_drm *priv = meson_crtc->priv; - meson_crtc->vsync_disabled = false; meson_venc_enable_vsync(priv); return 0; @@ -62,10 +60,7 @@ static void meson_crtc_disable_vblank(struct drm_crtc *crtc) struct meson_crtc *meson_crtc = to_meson_crtc(crtc); struct meson_drm *priv = meson_crtc->priv; - if (!meson_crtc->vsync_forced) { - meson_crtc->vsync_disabled = true; - meson_venc_disable_vsync(priv); - } + meson_venc_disable_vsync(priv); } static const struct drm_crtc_funcs meson_crtc_funcs = { @@ -368,10 +363,11 @@ void meson_crtc_irq(struct meson_drm *priv) if (meson_crtc->enable_osd1) meson_crtc->enable_osd1(priv); - if (priv->viu.osd1_afbcd) - meson_crtc->vsync_forced = true; - else - meson_crtc->vsync_forced = false; + if (priv->viu.osd1_afbcd) { + priv->afbcd.ops->reset(priv); + priv->afbcd.ops->setup(priv); + priv->afbcd.ops->enable(priv); + } priv->viu.osd1_commit = false; } @@ -595,15 +591,6 @@ void meson_crtc_irq(struct meson_drm *priv) priv->viu.vd1_commit = false; } - if (meson_crtc->vsync_forced && priv->viu.osd1_afbcd) { - priv->afbcd.ops->reset(priv); - priv->afbcd.ops->setup(priv); - priv->afbcd.ops->enable(priv); - } - - if (meson_crtc->vsync_disabled) - return; - drm_crtc_handle_vblank(priv->crtc); spin_lock_irqsave(&priv->drm->event_lock, flags); diff --git a/drivers/gpu/drm/meson/meson_osd_afbcd.c b/drivers/gpu/drm/meson/meson_osd_afbcd.c index aae4341bedaf..6d97bb4be3ca 100644 --- a/drivers/gpu/drm/meson/meson_osd_afbcd.c +++ b/drivers/gpu/drm/meson/meson_osd_afbcd.c @@ -12,6 +12,7 @@ #include "meson_drv.h" #include "meson_registers.h" #include "meson_viu.h" +#include "meson_rdma.h" #include "meson_osd_afbcd.h" /* @@ -270,6 +271,14 @@ static bool meson_g12a_afbcd_supported_fmt(u64 modifier, uint32_t format) static int meson_g12a_afbcd_init(struct meson_drm *priv) { + int ret; + + ret = meson_rdma_init(priv); + if (ret) + return ret; + + meson_rdma_setup(priv); + /* Handle AFBC Decoder reset manually */ writel_bits_relaxed(MALI_AFBCD_MANUAL_RESET, MALI_AFBCD_MANUAL_RESET, priv->io_base + _REG(MALI_AFBCD_TOP_CTRL)); @@ -279,27 +288,32 @@ static int meson_g12a_afbcd_init(struct meson_drm *priv) static int meson_g12a_afbcd_reset(struct meson_drm *priv) { - writel_relaxed(VIU_SW_RESET_G12A_AFBC_ARB | - VIU_SW_RESET_G12A_OSD1_AFBCD, - priv->io_base + _REG(VIU_SW_RESET)); - writel_relaxed(0, priv->io_base + _REG(VIU_SW_RESET)); + meson_rdma_stop(priv); + + meson_rdma_writel_sync(priv, VIU_SW_RESET_G12A_AFBC_ARB | + VIU_SW_RESET_G12A_OSD1_AFBCD, + VIU_SW_RESET); + meson_rdma_writel_sync(priv, 0, VIU_SW_RESET); return 0; } static int meson_g12a_afbcd_enable(struct meson_drm *priv) { - writel_relaxed(VPU_MAFBC_IRQ_SURFACES_COMPLETED | - VPU_MAFBC_IRQ_CONFIGURATION_SWAPPED | - VPU_MAFBC_IRQ_DECODE_ERROR | - VPU_MAFBC_IRQ_DETILING_ERROR, - priv->io_base + _REG(VPU_MAFBC_IRQ_MASK)); + meson_rdma_writel_sync(priv, VPU_MAFBC_IRQ_SURFACES_COMPLETED | + VPU_MAFBC_IRQ_CONFIGURATION_SWAPPED | + VPU_MAFBC_IRQ_DECODE_ERROR | + VPU_MAFBC_IRQ_DETILING_ERROR, + VPU_MAFBC_IRQ_MASK); - writel_bits_relaxed(VPU_MAFBC_S0_ENABLE, VPU_MAFBC_S0_ENABLE, - priv->io_base + _REG(VPU_MAFBC_SURFACE_CFG)); + meson_rdma_writel_sync(priv, VPU_MAFBC_S0_ENABLE, + VPU_MAFBC_SURFACE_CFG); + + meson_rdma_writel_sync(priv, VPU_MAFBC_DIRECT_SWAP, + VPU_MAFBC_COMMAND); - writel_relaxed(VPU_MAFBC_DIRECT_SWAP, - priv->io_base + _REG(VPU_MAFBC_COMMAND)); + /* This will enable the RDMA replaying the register writes on vsync */ + meson_rdma_flush(priv); return 0; } @@ -330,36 +344,36 @@ static int meson_g12a_afbcd_setup(struct meson_drm *priv) AFBC_FORMAT_MOD_BLOCK_SIZE_32x8) format |= FIELD_PREP(VPU_MAFBC_SUPER_BLOCK_ASPECT, 1); - writel_relaxed(format, - priv->io_base + _REG(VPU_MAFBC_FORMAT_SPECIFIER_S0)); - - writel_relaxed(priv->viu.osd1_addr, - priv->io_base + _REG(VPU_MAFBC_HEADER_BUF_ADDR_LOW_S0)); - writel_relaxed(0, - priv->io_base + _REG(VPU_MAFBC_HEADER_BUF_ADDR_HIGH_S0)); - - writel_relaxed(priv->viu.osd1_width, - priv->io_base + _REG(VPU_MAFBC_BUFFER_WIDTH_S0)); - writel_relaxed(ALIGN(priv->viu.osd1_height, 32), - priv->io_base + _REG(VPU_MAFBC_BUFFER_HEIGHT_S0)); - - writel_relaxed(0, - priv->io_base + _REG(VPU_MAFBC_BOUNDING_BOX_X_START_S0)); - writel_relaxed(priv->viu.osd1_width - 1, - priv->io_base + _REG(VPU_MAFBC_BOUNDING_BOX_X_END_S0)); - writel_relaxed(0, - priv->io_base + _REG(VPU_MAFBC_BOUNDING_BOX_Y_START_S0)); - writel_relaxed(priv->viu.osd1_height - 1, - priv->io_base + _REG(VPU_MAFBC_BOUNDING_BOX_Y_END_S0)); - - writel_relaxed(MESON_G12A_AFBCD_OUT_ADDR, - priv->io_base + _REG(VPU_MAFBC_OUTPUT_BUF_ADDR_LOW_S0)); - writel_relaxed(0, - priv->io_base + _REG(VPU_MAFBC_OUTPUT_BUF_ADDR_HIGH_S0)); - - writel_relaxed(priv->viu.osd1_width * - (meson_g12a_afbcd_bpp(priv->afbcd.format) / 8), - priv->io_base + _REG(VPU_MAFBC_OUTPUT_BUF_STRIDE_S0)); + meson_rdma_writel_sync(priv, format, + VPU_MAFBC_FORMAT_SPECIFIER_S0); + + meson_rdma_writel_sync(priv, priv->viu.osd1_addr, + VPU_MAFBC_HEADER_BUF_ADDR_LOW_S0); + meson_rdma_writel_sync(priv, 0, + VPU_MAFBC_HEADER_BUF_ADDR_HIGH_S0); + + meson_rdma_writel_sync(priv, priv->viu.osd1_width, + VPU_MAFBC_BUFFER_WIDTH_S0); + meson_rdma_writel_sync(priv, ALIGN(priv->viu.osd1_height, 32), + VPU_MAFBC_BUFFER_HEIGHT_S0); + + meson_rdma_writel_sync(priv, 0, + VPU_MAFBC_BOUNDING_BOX_X_START_S0); + meson_rdma_writel_sync(priv, priv->viu.osd1_width - 1, + VPU_MAFBC_BOUNDING_BOX_X_END_S0); + meson_rdma_writel_sync(priv, 0, + VPU_MAFBC_BOUNDING_BOX_Y_START_S0); + meson_rdma_writel_sync(priv, priv->viu.osd1_height - 1, + VPU_MAFBC_BOUNDING_BOX_Y_END_S0); + + meson_rdma_writel_sync(priv, MESON_G12A_AFBCD_OUT_ADDR, + VPU_MAFBC_OUTPUT_BUF_ADDR_LOW_S0); + meson_rdma_writel_sync(priv, 0, + VPU_MAFBC_OUTPUT_BUF_ADDR_HIGH_S0); + + meson_rdma_writel_sync(priv, priv->viu.osd1_width * + (meson_g12a_afbcd_bpp(priv->afbcd.format) / 8), + VPU_MAFBC_OUTPUT_BUF_STRIDE_S0); return 0; }