Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp4654261ima; Mon, 4 Feb 2019 22:08:24 -0800 (PST) X-Google-Smtp-Source: AHgI3IbFqexaOG+ldrSXrjE7LaGXzIywPw4Ug4LTqA0xmcPnqvFWaxiMKV0hUI2+7LJGfBKDFJFV X-Received: by 2002:a63:e247:: with SMTP id y7mr2957129pgj.84.1549346904760; Mon, 04 Feb 2019 22:08:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549346904; cv=none; d=google.com; s=arc-20160816; b=Vrnpnl9uR99j4dYGegtIrgHYwo2Oxa79IdU5FzOdAX1MhLL+oVAUs/whuRN3QBzj1t CYmJ1g2cAju7dxVc7qv/mDaGwZCS4o0ev9o/3pZl2myiV2s0U8r22vdEGqOQaAdb75N/ whqNalOy1pLgy6OIfkPc8JzN8TUl7oQU9Y4m+96QW6MQUBuOuGPXAPHvjxSSMCnlGrmm uBhgMKr3Z2rKJGVCy+Q70D5AQUx+z+cLuKjtQzmYG/cj3B+uottW6Pt9sl9OCmgLmIvw 3+nEFUj+BWyP/hSThX2MVWPgT3/gaoj0/iSV7zlwS5nZ2cWmayQ9vjxY+L1wOsDzZSfM EO3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=1X7N/dVorY1n8o81SeDGrzaKlbKZ1oT9Ljxn+D684ws=; b=kAb15l5ROu1K4qkJDP8I9mxz1NBOFcywvYQ1Y4c0zfKbWceMV6TgGDwVIHMoLc+dEA AVLvTCxPrbLSkVF7AJ1kRY3yM3WyNQ6pvNDj9M3af2zEK7UETCY13PAmDMiDHuAfosVb Fp5TlxCTaJagEPlB9//pL1pVDH3GBoWdLeECNhO2K/whhlgIRyg4iSRyLZNXgCKLdemb rxFpfzlHap2xWK0Z8dn9Zwx5v0YtlXmeK313LKjsS//DpJ8nF4rIquRdxni0sXK2u0UO Facc53sQHKvvnEnrizoFgNRXH1q8zhZeMBvudA1bbum+bPCHa1h2GOVJrgVLLnDhoKNB PDaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mobiveil.co.in header.s=google header.b=jumluG8r; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u7si405915pgg.357.2019.02.04.22.08.08; Mon, 04 Feb 2019 22:08:24 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@mobiveil.co.in header.s=google header.b=jumluG8r; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727460AbfBEGHi (ORCPT + 99 others); Tue, 5 Feb 2019 01:07:38 -0500 Received: from mail-wr1-f54.google.com ([209.85.221.54]:38696 "EHLO mail-wr1-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727276AbfBEGHh (ORCPT ); Tue, 5 Feb 2019 01:07:37 -0500 Received: by mail-wr1-f54.google.com with SMTP id v13so2288426wrw.5 for ; Mon, 04 Feb 2019 22:07:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mobiveil.co.in; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=1X7N/dVorY1n8o81SeDGrzaKlbKZ1oT9Ljxn+D684ws=; b=jumluG8r5o7eqoHVTBNXM7Z+nNa3LZuGQCTHMO01skLXnrTLcrRBGBPAtx88LvgE6F GiPEQHi8dL/1FgSrJ7OTeYohrHuhvJl9tu2ZSF5U0lFuBlcNcH2YveeKRPYW9y12G/a0 DbYgjwSbSH44ln9wfgDpp8716HSHKAEEio5pY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=1X7N/dVorY1n8o81SeDGrzaKlbKZ1oT9Ljxn+D684ws=; b=a5ejQ6+tgt3dc7W7jPFEZ7qZd+KulMJMxGvfosrjLBcpeGad0WnfpFTSohS2IRPnJk MyF3eCIHpm9ZfxQ581KQTtYs+yT+j//hVUgawHbgoZGI+tROa0zcDqugCbwYPT/4eTXy CKarDWmXYAYq8FWzKKJupciEard8OrsKEr8hWbis/2H0tydXgzEo2oyhCUXAV5MM3aMW YaqL/3WES+OL39MpGw8l6KO6zGB4gSOHeI31RHzsFYLR4gWGhsymRGe+B5EcU+CIW/lw mmoevceejHcrKcpsAFYcNeV1UG+J57TFb6DG038Lv2O3x6LiSJBAFTYAEd9Nz2PSeovo q8Uw== X-Gm-Message-State: AHQUAuY5IExztyf2ZCRP9XzWYRq3O/CnmO8vdeP9prj6PMfdCY41gHYY vvWPon7pRcmhOnkgias+N5azxmFAVAR7tlD6W2W836Pc5eH33w== X-Received: by 2002:a5d:4ec7:: with SMTP id s7mr2206258wrv.14.1549346854954; Mon, 04 Feb 2019 22:07:34 -0800 (PST) MIME-Version: 1.0 References: <20190129080926.36773-1-Zhiqiang.Hou@nxp.com> <20190129080926.36773-10-Zhiqiang.Hou@nxp.com> In-Reply-To: <20190129080926.36773-10-Zhiqiang.Hou@nxp.com> From: Subrahmanya Lingappa Date: Tue, 5 Feb 2019 11:40:08 +0530 Message-ID: Subject: Re: [PATCHv3 09/27] PCI: mobiveil: correct inbound/outbound window setup routines To: "Z.q. Hou" Cc: "linux-pci@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "devicetree@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "bhelgaas@google.com" , "robh+dt@kernel.org" , "mark.rutland@arm.com" , "shawnguo@kernel.org" , Leo Li , "lorenzo.pieralisi@arm.com" , "catalin.marinas@arm.com" , "will.deacon@arm.com" , Mingkai Hu , "M.h. Lian" , Xiaowei Bao Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ZQ, please correct the tab spacing of the macro definitions, otherwise its OK. Reviewed-by: Subrahmanya Lingappa On Tue, Jan 29, 2019 at 1:39 PM Z.q. Hou wrote: > > From: Hou Zhiqiang > > Outbound window routine: > - Removed unused var definition and register read operations. > - Added the upper 32-bit cpu address setup of the window. > - Instead of blindly write, only change the fields specified. > - Masked the lower bits of window size in case override the > control bits. > - Check if the passing window number is available, instead of > the total number of the initialized windows. > > Inbound window routine: > - Added parameter 'u64 cpu_addr' to specify the cpu address > of the window instead of using 'pci_addr'. > - Changed 'int pci_addr' to 'u64 pci_addr', and added setup > of the upper 32-bit pci address of the window. > - Moved the PCIe PIO master enablement to mobiveil_host_init(). > - Instead of blindly write, only change the fields specified. > - Masked the lower bits of window size in case override the > control bits. > - Check if the passing window number is available, instead of > the total number of the initialized windows. > - And added the statistic of initialized inbound windows. > > Fixes: 9af6bcb11e12 ("PCI: mobiveil: Add Mobiveil PCIe Host > Bridge IP driver") > Signed-off-by: Hou Zhiqiang > Reviewed-by: Minghuan Lian > --- > V3: > - No change > > drivers/pci/controller/pcie-mobiveil.c | 70 +++++++++++++++----------- > 1 file changed, 42 insertions(+), 28 deletions(-) > > diff --git a/drivers/pci/controller/pcie-mobiveil.c b/drivers/pci/controller/pcie-mobiveil.c > index e88afc792a5c..4ba458474e42 100644 > --- a/drivers/pci/controller/pcie-mobiveil.c > +++ b/drivers/pci/controller/pcie-mobiveil.c > @@ -65,9 +65,13 @@ > #define PAB_AXI_AMAP_CTRL(win) PAB_REG_ADDR(0x0ba0, win) > #define WIN_ENABLE_SHIFT 0 > #define WIN_TYPE_SHIFT 1 > +#define WIN_TYPE_MASK 0x3 > +#define WIN_SIZE_SHIFT 10 > +#define WIN_SIZE_MASK 0x3fffff > > #define PAB_EXT_AXI_AMAP_SIZE(win) PAB_EXT_REG_ADDR(0xbaf0, win) > > +#define PAB_EXT_AXI_AMAP_AXI_WIN(win) PAB_EXT_REG_ADDR(0x80a0, win) > #define PAB_AXI_AMAP_AXI_WIN(win) PAB_REG_ADDR(0x0ba4, win) > #define AXI_WINDOW_ALIGN_MASK 3 > > @@ -82,8 +86,10 @@ > #define PAB_PEX_AMAP_CTRL(win) PAB_REG_ADDR(0x4ba0, win) > #define AMAP_CTRL_EN_SHIFT 0 > #define AMAP_CTRL_TYPE_SHIFT 1 > +#define AMAP_CTRL_TYPE_MASK 3 > > #define PAB_EXT_PEX_AMAP_SIZEN(win) PAB_EXT_REG_ADDR(0xbef0, win) > +#define PAB_EXT_PEX_AMAP_AXI_WIN(win) PAB_EXT_REG_ADDR(0xb4a0, win) > #define PAB_PEX_AMAP_AXI_WIN(win) PAB_REG_ADDR(0x4ba4, win) > #define PAB_PEX_AMAP_PEX_WIN_L(win) PAB_REG_ADDR(0x4ba8, win) > #define PAB_PEX_AMAP_PEX_WIN_H(win) PAB_REG_ADDR(0x4bac, win) > @@ -455,49 +461,51 @@ static int mobiveil_pcie_parse_dt(struct mobiveil_pcie *pcie) > } > > static void program_ib_windows(struct mobiveil_pcie *pcie, int win_num, > - int pci_addr, u32 type, u64 size) > + u64 cpu_addr, u64 pci_addr, u32 type, u64 size) > { > - int pio_ctrl_val; > - int amap_ctrl_dw; > + u32 value; > u64 size64 = ~(size - 1); > > - if ((pcie->ib_wins_configured + 1) > pcie->ppio_wins) { > + if (win_num >= pcie->ppio_wins) { > dev_err(&pcie->pdev->dev, > "ERROR: max inbound windows reached !\n"); > return; > } > > - pio_ctrl_val = csr_readl(pcie, PAB_PEX_PIO_CTRL); > - pio_ctrl_val |= 1 << PIO_ENABLE_SHIFT; > - csr_writel(pcie, pio_ctrl_val, PAB_PEX_PIO_CTRL); > - > - amap_ctrl_dw = csr_readl(pcie, PAB_PEX_AMAP_CTRL(win_num)); > - amap_ctrl_dw |= (type << AMAP_CTRL_TYPE_SHIFT) | > - (1 << AMAP_CTRL_EN_SHIFT) | > - lower_32_bits(size64); > - csr_writel(pcie, amap_ctrl_dw, PAB_PEX_AMAP_CTRL(win_num)); > + value = csr_readl(pcie, PAB_PEX_AMAP_CTRL(win_num)); > + value &= ~(AMAP_CTRL_TYPE_MASK << AMAP_CTRL_TYPE_SHIFT | > + WIN_SIZE_MASK << WIN_SIZE_SHIFT); > + value |= (type << AMAP_CTRL_TYPE_SHIFT) | (1 << AMAP_CTRL_EN_SHIFT) | > + (lower_32_bits(size64) & WIN_SIZE_MASK << WIN_SIZE_SHIFT); > + csr_writel(pcie, value, PAB_PEX_AMAP_CTRL(win_num)); > > csr_writel(pcie, upper_32_bits(size64), > PAB_EXT_PEX_AMAP_SIZEN(win_num)); > > - csr_writel(pcie, pci_addr, PAB_PEX_AMAP_AXI_WIN(win_num)); > + csr_writel(pcie, lower_32_bits(cpu_addr), > + PAB_PEX_AMAP_AXI_WIN(win_num)); > + csr_writel(pcie, upper_32_bits(cpu_addr), > + PAB_EXT_PEX_AMAP_AXI_WIN(win_num)); > + > + csr_writel(pcie, lower_32_bits(pci_addr), > + PAB_PEX_AMAP_PEX_WIN_L(win_num)); > + csr_writel(pcie, upper_32_bits(pci_addr), > + PAB_PEX_AMAP_PEX_WIN_H(win_num)); > > - csr_writel(pcie, pci_addr, PAB_PEX_AMAP_PEX_WIN_L(win_num)); > - csr_writel(pcie, 0, PAB_PEX_AMAP_PEX_WIN_H(win_num)); > + pcie->ib_wins_configured++; > } > > /* > * routine to program the outbound windows > */ > static void program_ob_windows(struct mobiveil_pcie *pcie, int win_num, > - u64 cpu_addr, u64 pci_addr, > - u32 config_io_bit, u64 size) > + u64 cpu_addr, u64 pci_addr, u32 type, u64 size) > { > > - u32 value, type; > + u32 value; > u64 size64 = ~(size - 1); > > - if ((pcie->ob_wins_configured + 1) > pcie->apio_wins) { > + if (win_num >= pcie->apio_wins) { > dev_err(&pcie->pdev->dev, > "ERROR: max outbound windows reached !\n"); > return; > @@ -507,10 +515,12 @@ static void program_ob_windows(struct mobiveil_pcie *pcie, int win_num, > * program Enable Bit to 1, Type Bit to (00) base 2, AXI Window Size Bit > * to 4 KB in PAB_AXI_AMAP_CTRL register > */ > - type = config_io_bit; > value = csr_readl(pcie, PAB_AXI_AMAP_CTRL(win_num)); > - csr_writel(pcie, 1 << WIN_ENABLE_SHIFT | type << WIN_TYPE_SHIFT | > - lower_32_bits(size64), PAB_AXI_AMAP_CTRL(win_num)); > + value &= ~(WIN_TYPE_MASK << WIN_TYPE_SHIFT | > + WIN_SIZE_MASK << WIN_SIZE_SHIFT); > + value |= 1 << WIN_ENABLE_SHIFT | type << WIN_TYPE_SHIFT | > + (lower_32_bits(size64) & WIN_SIZE_MASK << WIN_SIZE_SHIFT); > + csr_writel(pcie, value, PAB_AXI_AMAP_CTRL(win_num)); > > csr_writel(pcie, upper_32_bits(size64), PAB_EXT_AXI_AMAP_SIZE(win_num)); > > @@ -518,11 +528,10 @@ static void program_ob_windows(struct mobiveil_pcie *pcie, int win_num, > * program AXI window base with appropriate value in > * PAB_AXI_AMAP_AXI_WIN0 register > */ > - value = csr_readl(pcie, PAB_AXI_AMAP_AXI_WIN(win_num)); > - csr_writel(pcie, cpu_addr & (~AXI_WINDOW_ALIGN_MASK), > + csr_writel(pcie, lower_32_bits(cpu_addr) & (~AXI_WINDOW_ALIGN_MASK), > PAB_AXI_AMAP_AXI_WIN(win_num)); > - > - value = csr_readl(pcie, PAB_AXI_AMAP_PEX_WIN_H(win_num)); > + csr_writel(pcie, upper_32_bits(cpu_addr), > + PAB_EXT_AXI_AMAP_AXI_WIN(win_num)); > > csr_writel(pcie, lower_32_bits(pci_addr), > PAB_AXI_AMAP_PEX_WIN_L(win_num)); > @@ -604,6 +613,11 @@ static int mobiveil_host_init(struct mobiveil_pcie *pcie) > value |= APIO_EN_MASK; > csr_writel(pcie, value, PAB_AXI_PIO_CTRL); > > + /* Enable PCIe PIO master */ > + value = csr_readl(pcie, PAB_PEX_PIO_CTRL); > + value |= 1 << PIO_ENABLE_SHIFT; > + csr_writel(pcie, value, PAB_PEX_PIO_CTRL); > + > /* > * we'll program one outbound window for config reads and > * another default inbound window for all the upstream traffic > @@ -616,7 +630,7 @@ static int mobiveil_host_init(struct mobiveil_pcie *pcie) > CFG_WINDOW_TYPE, resource_size(pcie->ob_io_res)); > > /* memory inbound translation window */ > - program_ib_windows(pcie, WIN_NUM_0, 0, MEM_WINDOW_TYPE, IB_WIN_SIZE); > + program_ib_windows(pcie, WIN_NUM_0, 0, 0, MEM_WINDOW_TYPE, IB_WIN_SIZE); > > /* Get the I/O and memory ranges from DT */ > resource_list_for_each_entry(win, &pcie->resources) { > -- > 2.17.1 >