Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp909397ybl; Tue, 13 Aug 2019 04:38:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqxIYMb4g19HKT1AEGOOVD5vsfpzMh4bfheG1fh3haRedC7t6SCoYlVFVz+CHT152V+bmKZw X-Received: by 2002:a17:90a:b894:: with SMTP id o20mr1825738pjr.41.1565696291151; Tue, 13 Aug 2019 04:38:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565696291; cv=none; d=google.com; s=arc-20160816; b=oHueNK4Js3a3v6u8OnePVGy9lPCbyNn2jVqps43bvW14CTMWaZyVnBg4NqsXts7aNs yFoNJNhz4qNfBWHA0jbbW3KtH/8PpjzycMyBzgA0xVexwMyoBzzwUFzlWCZYRXodeOKx p0FIFcsTdVvZbotoON8bBixNaP/zOBTnG6zZwhhck5WRXsJ4jsw1JyK1RkriLW6c7I2c dhxVBqmQ7+A5304w5XVPaxtDXuRej0GY1JOvR1zG6RXhBDMD2dWSMHxj0bl/0wa0+aga twWGTAsO/VIAMeyxoerdpnCgVe3+Y3c4XSRI9BdzQr8AyKuHRQg0rxcvPAU1OppY+IIO 5KVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:dkim-signature:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from; bh=HYwlfLcFQpyTxdQf+kXiXwYkoFOdgqZeO1FMon6LMig=; b=R68lRKSA53+77mIFntI6egnKDQTY+vzyf12KVKFoz+Ux6Awpb0Sb+smtdyB0u6aTzb MoalvL4SwemNRtR0zyicKhE8nDvptPDY4209Q/Y9H1wtcfPNOo9MiNbUHBTSecxTmx8O lrzkIDF0VHRORWySW6uZCCnbOGz0h5q5wkPF+3jqDcdX8YgEhjsFy8mfS+l/VEOeinfd r9b7zAcmzVIUk4N9p8dcFHDx8SoUc7+1VjU6VuIlSe4vlLHxRZzgZPMcGaQgUwAqH99A 6BtILBiqPWn4TL4tH2766JKw5ql9/pUUorIOeA2LZxc9m+QW1CIrXHPCcSD/LzzEtiMz CgdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=bQi8o85H; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g4si833912pjt.70.2019.08.13.04.37.54; Tue, 13 Aug 2019 04:38:11 -0700 (PDT) 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=@nvidia.com header.s=n1 header.b=bQi8o85H; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727621AbfHMLhB (ORCPT + 99 others); Tue, 13 Aug 2019 07:37:01 -0400 Received: from hqemgate15.nvidia.com ([216.228.121.64]:13594 "EHLO hqemgate15.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727531AbfHMLg7 (ORCPT ); Tue, 13 Aug 2019 07:36:59 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqemgate15.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Tue, 13 Aug 2019 04:37:09 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Tue, 13 Aug 2019 04:36:58 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Tue, 13 Aug 2019 04:36:58 -0700 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL104.nvidia.com (172.18.146.11) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 13 Aug 2019 11:36:58 +0000 Received: from hqnvemgw01.nvidia.com (172.20.150.20) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Tue, 13 Aug 2019 11:36:58 +0000 Received: from vidyas-desktop.nvidia.com (Not Verified[10.24.37.38]) by hqnvemgw01.nvidia.com with Trustwave SEG (v7,5,8,10121) id ; Tue, 13 Aug 2019 04:36:57 -0700 From: Vidya Sagar To: , , , , , , , , , , CC: , , , , , , , , , , Subject: [PATCH V16 03/13] PCI: dwc: Perform dbi regs write lock towards the end Date: Tue, 13 Aug 2019 17:06:17 +0530 Message-ID: <20190813113627.27251-4-vidyas@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190813113627.27251-1-vidyas@nvidia.com> References: <20190813113627.27251-1-vidyas@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 Content-Type: text/plain DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1565696229; bh=HYwlfLcFQpyTxdQf+kXiXwYkoFOdgqZeO1FMon6LMig=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=bQi8o85HyYNr3x1ewSj07f5WJ8sQ85BP0zts0IxklBvcyjK+ijpdq/6eAzIdTQbca QzFF8Oxqq1qzg2blv8VbtZAdKATcg/n1a35IhQ+F+NR0uM2tahwC1Y1Yj3HfqTwmpR wtOsUI13B9XqDRRzgRxxLTthMAXX2iY4X81niIUQiwV38LhvBdskkPH2aG4z6fnDy7 NA6n912ykBRq4moj5mIotxUdMalc4V4YqEwShtp73X/5wSZsaRU4uwK+MPsxTZIyBI sn8i1qcOe95HYTWmk/TMaIW7bDDNNSTIbM/uPuT+ch2DJORqYX7XbX4wgZqyk0shqE txoCFT1CCN6AA== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some of DesignWare core's DBI registers (a.k.a configuration space registers) are write-protected with a lock without enabling which they are read-only by default. These write-protected registers are implementation specific. Tegra194's BAR-0 register which is at offset 0x10 in the configuration space is an example. Current implementation in dw_pcie_setup_rc() API attempts to unlock those write-protected registers whenever they are updated and lock them back again for writing. This patch attempts to unlock all such write-protected registers for writing in the beginning of the API once and lock them back again towards the end to avoid bloating the API with multiple unlock/lock sequences for all those write-protected registers. Signed-off-by: Vidya Sagar Reviewed-by: Thierry Reding Acked-by: Jingoo Han --- V16: * None V15: * None V14: * None V13: * None V12: * Modified commit message to make it explicit that write-protected registers are implementation specific. V11: * None V10: * None V9: * None V8: * None V7: * None V6: * Moved write enable to the beginning of the API and write disable to the end V5: * None V4: * None V3: * None V2: * None drivers/pci/controller/dwc/pcie-designware-host.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c index f93252d0da5b..d3156446ff27 100644 --- a/drivers/pci/controller/dwc/pcie-designware-host.c +++ b/drivers/pci/controller/dwc/pcie-designware-host.c @@ -628,6 +628,12 @@ void dw_pcie_setup_rc(struct pcie_port *pp) u32 val, ctrl, num_ctrls; struct dw_pcie *pci = to_dw_pcie_from_pp(pp); + /* + * Enable DBI read-only registers for writing/updating configuration. + * Write permission gets disabled towards the end of this function. + */ + dw_pcie_dbi_ro_wr_en(pci); + dw_pcie_setup(pci); if (!pp->ops->msi_host_init) { @@ -650,12 +656,10 @@ void dw_pcie_setup_rc(struct pcie_port *pp) dw_pcie_writel_dbi(pci, PCI_BASE_ADDRESS_1, 0x00000000); /* Setup interrupt pins */ - dw_pcie_dbi_ro_wr_en(pci); val = dw_pcie_readl_dbi(pci, PCI_INTERRUPT_LINE); val &= 0xffff00ff; val |= 0x00000100; dw_pcie_writel_dbi(pci, PCI_INTERRUPT_LINE, val); - dw_pcie_dbi_ro_wr_dis(pci); /* Setup bus numbers */ val = dw_pcie_readl_dbi(pci, PCI_PRIMARY_BUS); @@ -687,15 +691,13 @@ void dw_pcie_setup_rc(struct pcie_port *pp) dw_pcie_wr_own_conf(pp, PCI_BASE_ADDRESS_0, 4, 0); - /* Enable write permission for the DBI read-only register */ - dw_pcie_dbi_ro_wr_en(pci); /* Program correct class for RC */ dw_pcie_wr_own_conf(pp, PCI_CLASS_DEVICE, 2, PCI_CLASS_BRIDGE_PCI); - /* Better disable write permission right after the update */ - dw_pcie_dbi_ro_wr_dis(pci); dw_pcie_rd_own_conf(pp, PCIE_LINK_WIDTH_SPEED_CONTROL, 4, &val); val |= PORT_LOGIC_SPEED_CHANGE; dw_pcie_wr_own_conf(pp, PCIE_LINK_WIDTH_SPEED_CONTROL, 4, val); + + dw_pcie_dbi_ro_wr_dis(pci); } EXPORT_SYMBOL_GPL(dw_pcie_setup_rc); -- 2.17.1