From patchwork Thu Mar 22 13:42:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Ujfalusi X-Patchwork-Id: 132279 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp862782ljb; Thu, 22 Mar 2018 06:42:12 -0700 (PDT) X-Google-Smtp-Source: AG47ELu6qWctInwb98vd7DkawImdfbXPMieF4VZ7YmRKfpVr2xOyo0RFgN0WLsy1GfQET72HIZLH X-Received: by 2002:a17:902:822:: with SMTP id 31-v6mr24638731plk.362.1521726132508; Thu, 22 Mar 2018 06:42:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521726132; cv=none; d=google.com; s=arc-20160816; b=gdZhT208Fh9hENjVNYndcMa9Hx3zwXUiEUKu4cXBVoAOLbv0RqHw0qQVYYHhwEHegu +HinW+rB4yvnvexbsNHSw8lQBvVIXLb0zshgBBNpSIIk8KmODZpliPtUv/GTequ6Gj0V qT81TSL4sCZJf05uAt7ifGxzm+un5JRyE2wg9oyeIHtP3Qz1ezb0ie/85ENnNJGo/cdR xjeCTqR3U7JCqhOiT2R7+8zLZqd+NtwUbPWOfVNvXs4AJPtctHHP+vvLo1K+quAhNWc+ QI9D+T90RL5TffRp14xcVi8h/QEI8xH3ej1qVHD4//bfdnMnEMoQwHnnA+dybVWSHj3F jVzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=Jn/YzEY4oAiT5VngTKH9ujuuzT8bE9kyYJ30PaQgTmI=; b=mDMkgLY+AuSElx+umhzLRao3r1mxCkaYGW8Uyw9FPml+UQs8HhgvaYBzg2G/Gs7BM1 vOSYZ6k0PPP58M3tE3n2PHKtd6GLlUaX1peFNmGah9XeSLhSK08RID5TrXlXtQd6Iah0 hCppRSI4K/wt7kuzHMbsZZTqLAhfREXhHmSBnxRXHZl3v4toUFmomtdgZLArQd6DwUoP UjKZGQPmWfcnZnX9lf7pZMP0aqW61wEiNXaNNczQF8WoyoNkQgVNE1XTg9DEfVpyjqUK y1HaCPMaSlEjP8qnihPVfwRfkpeoqQT7D9Z+hyIkZEaXEfR5mUV7VIHEBEjyvGpjV+nL +gBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@ti.com header.s=ti-com-17Q1 header.b=l6OAOxdw; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n69si4903855pfg.28.2018.03.22.06.42.12; Thu, 22 Mar 2018 06:42:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@ti.com header.s=ti-com-17Q1 header.b=l6OAOxdw; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754861AbeCVNmL (ORCPT + 6 others); Thu, 22 Mar 2018 09:42:11 -0400 Received: from lelnx194.ext.ti.com ([198.47.27.80]:31241 "EHLO lelnx194.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754779AbeCVNmK (ORCPT ); Thu, 22 Mar 2018 09:42:10 -0400 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by lelnx194.ext.ti.com (8.15.1/8.15.1) with ESMTP id w2MDg6Nq022466; Thu, 22 Mar 2018 08:42:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ti.com; s=ti-com-17Q1; t=1521726126; bh=ESrMPpd0+PXQEw/BTRMZppAgJvbJalS67m99l/8FM28=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=l6OAOxdwjdge8XimVoHril5sTonhBbwfyCLtB2hGRGmRga7+mXCgJLzJyYircjFJb Fq3YwzwvCDX9+WdGjEyQ7XaAjOXHFCn3u7cY+BP3tm5tjGNtSqj7Gg9GkGCLjCZ2sP jjnuHfC/zIXL0AixwKZ8+oCkOdGGuXGkpWy+BTqg= Received: from DFLE104.ent.ti.com (dfle104.ent.ti.com [10.64.6.25]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id w2MDg6Qj007608; Thu, 22 Mar 2018 08:42:06 -0500 Received: from DFLE107.ent.ti.com (10.64.6.28) by DFLE104.ent.ti.com (10.64.6.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1261.35; Thu, 22 Mar 2018 08:42:05 -0500 Received: from dflp33.itg.ti.com (10.64.6.16) by DFLE107.ent.ti.com (10.64.6.28) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1261.35 via Frontend Transport; Thu, 22 Mar 2018 08:42:05 -0500 Received: from feketebors.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id w2MDfxRa010212; Thu, 22 Mar 2018 08:42:04 -0500 From: Peter Ujfalusi To: , CC: , , , Subject: [PATCH v2 2/2] drm/omap: partial workaround for DRA7xx DMM errata i878 Date: Thu, 22 Mar 2018 15:42:06 +0200 Message-ID: <20180322134206.22857-3-peter.ujfalusi@ti.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180322134206.22857-1-peter.ujfalusi@ti.com> References: <20180322134206.22857-1-peter.ujfalusi@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Tomi Valkeinen Errata i878 says that MPU should not be used to access RAM and DMM at the same time. As it's not possible to prevent MPU accessing RAM, we need to access DMM via a proxy. This patch changes DMM driver to access DMM registers via sDMA. Instead of doing a normal readl/writel call to read/write a register, we use sDMA to copy 4 bytes from/to the DMM registers. This patch provides only a partial workaround for i878, as not only DMM register reads/writes are affected, but also accesses to the DMM mapped buffers (framebuffers, usually). Signed-off-by: Tomi Valkeinen --- drivers/gpu/drm/omapdrm/omap_dmm_priv.h | 8 ++ drivers/gpu/drm/omapdrm/omap_dmm_tiler.c | 153 ++++++++++++++++++++++++++++++- 2 files changed, 159 insertions(+), 2 deletions(-) -- Peter Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Signed-off-by: Peter Ujfalusi diff --git a/drivers/gpu/drm/omapdrm/omap_dmm_priv.h b/drivers/gpu/drm/omapdrm/omap_dmm_priv.h index c2785cc98dc9..9ce9d1d7039a 100644 --- a/drivers/gpu/drm/omapdrm/omap_dmm_priv.h +++ b/drivers/gpu/drm/omapdrm/omap_dmm_priv.h @@ -155,10 +155,12 @@ struct refill_engine { struct dmm_platform_data { u32 cpu_cache_flags; + bool errata_i878_wa; }; struct dmm { struct device *dev; + dma_addr_t phys_base; void __iomem *base; int irq; @@ -189,6 +191,12 @@ struct dmm { struct list_head alloc_head; const struct dmm_platform_data *plat_data; + + bool dmm_workaround; + spinlock_t wa_lock; + u32 *wa_dma_data; + dma_addr_t wa_dma_handle; + struct dma_chan *wa_dma_chan; }; #endif diff --git a/drivers/gpu/drm/omapdrm/omap_dmm_tiler.c b/drivers/gpu/drm/omapdrm/omap_dmm_tiler.c index e84871e74615..27c67bc36203 100644 --- a/drivers/gpu/drm/omapdrm/omap_dmm_tiler.c +++ b/drivers/gpu/drm/omapdrm/omap_dmm_tiler.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -79,14 +80,138 @@ static const u32 reg[][4] = { DMM_PAT_DESCR__2, DMM_PAT_DESCR__3}, }; +static int dmm_dma_copy(struct dmm *dmm, dma_addr_t src, dma_addr_t dst) +{ + struct dma_device *dma_dev = dmm->wa_dma_chan->device; + struct dma_async_tx_descriptor *tx; + enum dma_status status; + dma_cookie_t cookie; + + tx = dma_dev->device_prep_dma_memcpy(dmm->wa_dma_chan, dst, src, 4, 0); + if (!tx) { + dev_err(dmm->dev, "Failed to prepare DMA memcpy\n"); + return -EIO; + } + + cookie = tx->tx_submit(tx); + if (dma_submit_error(cookie)) { + dev_err(dmm->dev, "Failed to do DMA tx_submit\n"); + return -EIO; + } + + dma_async_issue_pending(dmm->wa_dma_chan); + status = dma_sync_wait(dmm->wa_dma_chan, cookie); + if (status != DMA_COMPLETE) + dev_err(dmm->dev, "i878 wa DMA copy failure\n"); + + dmaengine_terminate_all(dmm->wa_dma_chan); + return 0; +} + +static u32 dmm_read_wa(struct dmm *dmm, u32 reg) +{ + dma_addr_t src, dst; + int r; + + src = dmm->phys_base + reg; + dst = dmm->wa_dma_handle; + + r = dmm_dma_copy(dmm, src, dst); + if (r) { + dev_err(dmm->dev, "sDMA read transfer timeout\n"); + return readl(dmm->base + reg); + } + + /* + * As per i878 workaround, the DMA is used to access the DMM registers. + * Make sure that the readl is not moved by the compiler or the CPU + * earlier than the DMA finished writing the value to memory. + */ + rmb(); + return readl(dmm->wa_dma_data); +} + +static void dmm_write_wa(struct dmm *dmm, u32 val, u32 reg) +{ + dma_addr_t src, dst; + int r; + + writel(val, dmm->wa_dma_data); + /* + * As per i878 workaround, the DMA is used to access the DMM registers. + * Make sure that the writel is not moved by the compiler or the CPU, so + * the data will be in place before we start the DMA to do the actual + * register write. + */ + wmb(); + + src = dmm->wa_dma_handle; + dst = dmm->phys_base + reg; + + r = dmm_dma_copy(dmm, src, dst); + if (r) { + dev_err(dmm->dev, "sDMA write transfer timeout\n"); + writel(val, dmm->base + reg); + } +} + static u32 dmm_read(struct dmm *dmm, u32 reg) { - return readl(dmm->base + reg); + if (dmm->dmm_workaround) { + u32 v; + unsigned long flags; + + spin_lock_irqsave(&dmm->wa_lock, flags); + v = dmm_read_wa(dmm, reg); + spin_unlock_irqrestore(&dmm->wa_lock, flags); + + return v; + } else { + return readl(dmm->base + reg); + } } static void dmm_write(struct dmm *dmm, u32 val, u32 reg) { - writel(val, dmm->base + reg); + if (dmm->dmm_workaround) { + unsigned long flags; + + spin_lock_irqsave(&dmm->wa_lock, flags); + dmm_write_wa(dmm, val, reg); + spin_unlock_irqrestore(&dmm->wa_lock, flags); + } else { + writel(val, dmm->base + reg); + } +} + +static int dmm_workaround_init(struct dmm *dmm) +{ + dma_cap_mask_t mask; + + spin_lock_init(&dmm->wa_lock); + + dmm->wa_dma_data = dma_alloc_coherent(dmm->dev, sizeof(u32), + &dmm->wa_dma_handle, GFP_KERNEL); + if (!dmm->wa_dma_data) + return -ENOMEM; + + dma_cap_zero(mask); + dma_cap_set(DMA_MEMCPY, mask); + + dmm->wa_dma_chan = dma_request_channel(mask, NULL, NULL); + if (!dmm->wa_dma_chan) { + dma_free_coherent(dmm->dev, 4, dmm->wa_dma_data, dmm->wa_dma_handle); + return -ENODEV; + } + + return 0; +} + +static void dmm_workaround_uninit(struct dmm *dmm) +{ + dma_release_channel(dmm->wa_dma_chan); + + dma_free_coherent(dmm->dev, 4, dmm->wa_dma_data, dmm->wa_dma_handle); } /* simple allocator to grab next 16 byte aligned memory from txn */ @@ -632,6 +757,9 @@ static int omap_dmm_remove(struct platform_device *dev) if (omap_dmm->dummy_page) __free_page(omap_dmm->dummy_page); + if (omap_dmm->dmm_workaround) + dmm_workaround_uninit(omap_dmm); + if (omap_dmm->irq > 0) free_irq(omap_dmm->irq, omap_dmm); @@ -680,6 +808,7 @@ static int omap_dmm_probe(struct platform_device *dev) goto fail; } + omap_dmm->phys_base = mem->start; omap_dmm->base = ioremap(mem->start, SZ_2K); if (!omap_dmm->base) { @@ -695,6 +824,17 @@ static int omap_dmm_probe(struct platform_device *dev) omap_dmm->dev = &dev->dev; + if (omap_dmm->plat_data->errata_i878_wa) { + if (!dmm_workaround_init(omap_dmm)) { + omap_dmm->dmm_workaround = true; + dev_info(&dev->dev, + "workaround for errata i878 in use\n"); + } else { + dev_warn(&dev->dev, + "failed to initialize work-around for i878\n"); + } + } + hwinfo = dmm_read(omap_dmm, DMM_PAT_HWINFO); omap_dmm->num_engines = (hwinfo >> 24) & 0x1F; omap_dmm->num_lut = (hwinfo >> 16) & 0x1F; @@ -1058,6 +1198,11 @@ static const struct dmm_platform_data dmm_omap5_platform_data = { .cpu_cache_flags = OMAP_BO_UNCACHED, }; +static const struct dmm_platform_data dmm_dra7_platform_data = { + .cpu_cache_flags = OMAP_BO_UNCACHED, + .errata_i878_wa = true, +}; + static const struct of_device_id dmm_of_match[] = { { .compatible = "ti,omap4-dmm", @@ -1067,6 +1212,10 @@ static const struct of_device_id dmm_of_match[] = { .compatible = "ti,omap5-dmm", .data = &dmm_omap5_platform_data, }, + { + .compatible = "ti,dra7-dmm", + .data = &dmm_dra7_platform_data, + }, {}, }; #endif