From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4982BC433FE for ; Wed, 24 Nov 2021 17:01:40 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4A32A8370D; Wed, 24 Nov 2021 18:01:27 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="XMyyA4Ud"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 47E8E8321B; Wed, 24 Nov 2021 18:00:58 +0100 (CET) Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 239C783605 for ; Wed, 24 Nov 2021 18:00:47 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=pali@kernel.org Received: by mail.kernel.org (Postfix) with ESMTPSA id 91E5560FE3; Wed, 24 Nov 2021 17:00:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637773245; bh=4cOorBbMj5IkvQ0C5LUb6jcpvGnv/gnbdl9w+3iZWno=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XMyyA4UdXEAsII118L9FClMm5izQySXgrGbFgoUCBeWp1QLk0oGzhSCePfoMRtyZQ /P9uAT39qd7wVSqiktmBgMpV47bH2g4qzwZowhlfqrOVUYjLbfVnRJ4Cha89+vmZLS 9P8aUZ0j4EtTI2jZKO+L3Igh+LzLNj+z5VezQ9F6mUmjaBWeABQpftM86EN92cLFxu 0mH6+o0XRfaItfz2eV8P7vllUw8PaiDteGw0vVC9som5sKJVk6X6feNfc53mVITRW8 fsNkc/DK5VRWfDFeWMPotWxrcOSv9n4cmK9WQua6ThrbMdoqbGjLYXsW+m7dTPJMwS FIhghSTy2loig== Received: by pali.im (Postfix) id 558E556D; Wed, 24 Nov 2021 18:00:45 +0100 (CET) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Stefan Roese , Simon Glass , Bin Meng Cc: u-boot@lists.denx.de Subject: [PATCH u-boot-next 4/4] pci: pci_octeontx: Use PCIE_ECAM_OFFSET() macro Date: Wed, 24 Nov 2021 18:00:33 +0100 Message-Id: <20211124170033.4137-5-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211124170033.4137-1-pali@kernel.org> References: <20211124170033.4137-1-pali@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.37 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean Replace custom driver macros by PCIE_ECAM_OFFSET() macro from pci.h Signed-off-by: Pali Rohár --- drivers/pci/pci_octeontx.c | 61 +++++++++++++------------------------- 1 file changed, 20 insertions(+), 41 deletions(-) diff --git a/drivers/pci/pci_octeontx.c b/drivers/pci/pci_octeontx.c index 46855c5cd3a3..875cf7f7115d 100644 --- a/drivers/pci/pci_octeontx.c +++ b/drivers/pci/pci_octeontx.c @@ -49,25 +49,6 @@ struct octeontx_pci { struct resource bus; }; -static uintptr_t octeontx_cfg_addr(struct octeontx_pci *pcie, - int bus_offs, int shift_offs, - pci_dev_t bdf, uint offset) -{ - u32 bus, dev, func; - uintptr_t address; - - bus = PCI_BUS(bdf) + bus_offs; - dev = PCI_DEV(bdf); - func = PCI_FUNC(bdf); - - address = (bus << (20 + shift_offs)) | - (dev << (15 + shift_offs)) | - (func << (12 + shift_offs)) | offset; - address += pcie->cfg.start; - - return address; -} - static ulong readl_size(uintptr_t addr, enum pci_size_t size) { ulong val; @@ -123,9 +104,9 @@ static int octeontx_ecam_read_config(const struct udevice *bus, pci_dev_t bdf, struct pci_controller *hose = dev_get_uclass_priv(bus); uintptr_t address; - address = octeontx_cfg_addr(pcie, pcie->bus.start - hose->first_busno, - 0, bdf, offset); - *valuep = readl_size(address, size); + address = PCIE_ECAM_OFFSET(PCI_BUS(bdf) + pcie->bus.start - hose->first_busno, + PCI_DEV(bdf), PCI_FUNC(bdf), offset); + *valuep = readl_size(pcie->cfg.start + address, size); debug("%02x.%02x.%02x: u%d %x -> %lx\n", PCI_BUS(bdf), PCI_DEV(bdf), PCI_FUNC(bdf), size, offset, *valuep); @@ -141,9 +122,9 @@ static int octeontx_ecam_write_config(struct udevice *bus, pci_dev_t bdf, struct pci_controller *hose = dev_get_uclass_priv(bus); uintptr_t address; - address = octeontx_cfg_addr(pcie, pcie->bus.start - hose->first_busno, - 0, bdf, offset); - writel_size(address, size, value); + address = PCIE_ECAM_OFFSET(PCI_BUS(bdf) + pcie->bus.start - hose->first_busno, + PCI_DEV(bdf), PCI_FUNC(bdf), offset); + writel_size(pcie->cfg.start + address, size, value); debug("%02x.%02x.%02x: u%d %x <- %lx\n", PCI_BUS(bdf), PCI_DEV(bdf), PCI_FUNC(bdf), size, offset, value); @@ -162,17 +143,16 @@ static int octeontx_pem_read_config(const struct udevice *bus, pci_dev_t bdf, u8 pri_bus = pcie->bus.start + 1 - hose->first_busno; u32 bus_offs = (pri_bus << 16) | (pri_bus << 8) | (pri_bus << 0); - address = octeontx_cfg_addr(pcie, 1 - hose->first_busno, 4, - bdf, 0); - *valuep = pci_conv_32_to_size(~0UL, offset, size); if (octeontx_bdf_invalid(bdf)) return -EPERM; - *valuep = readl_size(address + offset, size); + address = PCIE_ECAM_OFFSET(PCI_BUS(bdf) + 1 - hose->first_busno, + PCI_DEV(bdf), PCI_FUNC(bdf), 0) << 4; + *valuep = readl_size(pcie->cfg.start + address + offset, size); - hdrtype = readb(address + PCI_HEADER_TYPE); + hdrtype = readb(pcie->cfg.start + address + PCI_HEADER_TYPE); if (hdrtype == PCI_HEADER_TYPE_BRIDGE && offset >= PCI_PRIMARY_BUS && offset <= PCI_SUBORDINATE_BUS && @@ -193,9 +173,10 @@ static int octeontx_pem_write_config(struct udevice *bus, pci_dev_t bdf, u8 pri_bus = pcie->bus.start + 1 - hose->first_busno; u32 bus_offs = (pri_bus << 16) | (pri_bus << 8) | (pri_bus << 0); - address = octeontx_cfg_addr(pcie, 1 - hose->first_busno, 4, bdf, 0); + address = PCIE_ECAM_OFFSET(PCI_BUS(bdf) + 1 - hose->first_busno, + PCI_DEV(bdf), PCI_FUNC(bdf), 0) << 4; - hdrtype = readb(address + PCI_HEADER_TYPE); + hdrtype = readb(pcie->cfg.start + address + PCI_HEADER_TYPE); if (hdrtype == PCI_HEADER_TYPE_BRIDGE && offset >= PCI_PRIMARY_BUS && offset <= PCI_SUBORDINATE_BUS && @@ -205,7 +186,7 @@ static int octeontx_pem_write_config(struct udevice *bus, pci_dev_t bdf, if (octeontx_bdf_invalid(bdf)) return -EPERM; - writel_size(address + offset, size, value); + writel_size(pcie->cfg.start + address + offset, size, value); debug("%02x.%02x.%02x: u%d %x (%lx) <- %lx\n", PCI_BUS(bdf), PCI_DEV(bdf), PCI_FUNC(bdf), size, offset, @@ -222,15 +203,14 @@ static int octeontx2_pem_read_config(const struct udevice *bus, pci_dev_t bdf, struct pci_controller *hose = dev_get_uclass_priv(bus); uintptr_t address; - address = octeontx_cfg_addr(pcie, 1 - hose->first_busno, 0, - bdf, 0); - *valuep = pci_conv_32_to_size(~0UL, offset, size); if (octeontx_bdf_invalid(bdf)) return -EPERM; - *valuep = readl_size(address + offset, size); + address = PCIE_ECAM_OFFSET(PCI_BUS(bdf) + 1 - hose->first_busno, + PCI_DEV(bdf), PCI_FUNC(bdf), offset); + *valuep = readl_size(pcie->cfg.start + address, size); debug("%02x.%02x.%02x: u%d %x (%lx) -> %lx\n", PCI_BUS(bdf), PCI_DEV(bdf), PCI_FUNC(bdf), size, offset, @@ -247,13 +227,12 @@ static int octeontx2_pem_write_config(struct udevice *bus, pci_dev_t bdf, struct pci_controller *hose = dev_get_uclass_priv(bus); uintptr_t address; - address = octeontx_cfg_addr(pcie, 1 - hose->first_busno, 0, - bdf, 0); - if (octeontx_bdf_invalid(bdf)) return -EPERM; - writel_size(address + offset, size, value); + address = PCIE_ECAM_OFFSET(PCI_BUS(bdf) + 1 - hose->first_busno, + PCI_DEV(bdf), PCI_FUNC(bdf), offset); + writel_size(pcie->cfg.start + address, size, value); debug("%02x.%02x.%02x: u%d %x (%lx) <- %lx\n", PCI_BUS(bdf), PCI_DEV(bdf), PCI_FUNC(bdf), size, offset, -- 2.20.1