From mboxrd@z Thu Jan 1 00:00:00 1970 From: Simon Glass Date: Sun, 20 Oct 2019 21:31:42 -0600 Subject: [U-Boot] [PATCH v3 009/108] dm: pci: Move pci_get_devfn() into a common file In-Reply-To: <20191021033322.217715-2-sjg@chromium.org> References: <20191021033322.217715-2-sjg@chromium.org> Message-ID: <20191021033322.217715-10-sjg@chromium.org> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Early in boot it is necessary to decode the PCI device/function values for particular peripherals in the device tree or of-platdata. This is needed in TPL where CONFIG_PCI is not defined. To handle this, move pci_get_devfn() into a file that is built even when CONFIG_PCI is not defined. Signed-off-by: Simon Glass --- Changes in v3: - Move the function to a common file instead of duplicating it - Update device type to pci_dev_t Changes in v2: None arch/x86/include/asm/pci.h | 11 +++++++++++ drivers/core/util.c | 20 ++++++++++++++++++++ drivers/pci/pci-uclass.c | 16 ---------------- include/dm/pci.h | 21 +++++++++++++++++++++ include/pci.h | 12 ++---------- 5 files changed, 54 insertions(+), 26 deletions(-) create mode 100644 include/dm/pci.h diff --git a/arch/x86/include/asm/pci.h b/arch/x86/include/asm/pci.h index 2a720735728..66f1515cefa 100644 --- a/arch/x86/include/asm/pci.h +++ b/arch/x86/include/asm/pci.h @@ -60,6 +60,17 @@ int pci_x86_write_config(pci_dev_t bdf, uint offset, ulong value, int pci_x86_clrset_config(pci_dev_t bdf, uint offset, ulong clr, ulong set, enum pci_size_t size); +/** + * pci_x86_ofplat_get_devfn() - Get the PCI dev/fn from ofplat reg data + * + * @reg: reg value from dt-platdata.c array (first member) + * @return device/function for that device + */ +static inline pci_dev_t pci_x86_ofplat_get_devfn(u32 reg) +{ + return reg & 0xff00; +} + /** * Assign IRQ number to a PCI device * diff --git a/drivers/core/util.c b/drivers/core/util.c index 7dc1a2af028..69f83755f05 100644 --- a/drivers/core/util.c +++ b/drivers/core/util.c @@ -4,7 +4,9 @@ */ #include +#include #include +#include #include #include #include @@ -58,3 +60,21 @@ bool dm_ofnode_pre_reloc(ofnode node) #endif } #endif + +#if !CONFIG_IS_ENABLED(OF_PLATDATA) +int pci_get_devfn(struct udevice *dev) +{ + struct fdt_pci_addr addr; + int ret; + + /* Extract the devfn from fdt_pci_addr */ + ret = ofnode_read_pci_addr(dev_ofnode(dev), FDT_PCI_SPACE_CONFIG, + "reg", &addr); + if (ret) { + if (ret != -ENOENT) + return -EINVAL; + } + + return addr.phys_hi & 0xff00; +} +#endif diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c index e77445cea33..95d36d91564 100644 --- a/drivers/pci/pci-uclass.c +++ b/drivers/pci/pci-uclass.c @@ -1013,22 +1013,6 @@ static int pci_uclass_post_probe(struct udevice *bus) return 0; } -int pci_get_devfn(struct udevice *dev) -{ - struct fdt_pci_addr addr; - int ret; - - /* Extract the devfn from fdt_pci_addr */ - ret = ofnode_read_pci_addr(dev_ofnode(dev), FDT_PCI_SPACE_CONFIG, - "reg", &addr); - if (ret) { - if (ret != -ENOENT) - return -EINVAL; - } - - return addr.phys_hi & 0xff00; -} - static int pci_uclass_child_post_bind(struct udevice *dev) { struct pci_child_platdata *pplat; diff --git a/include/dm/pci.h b/include/dm/pci.h new file mode 100644 index 00000000000..6147696d825 --- /dev/null +++ b/include/dm/pci.h @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (c) 2019 Google, Inc + */ + +#ifndef __DM_PCI_H +#define __DM_PCI_H + +struct udevice; + +/** + * pci_get_devfn() - Extract the devfn from fdt_pci_addr of the device + * + * Get devfn from fdt_pci_addr of the specified device + * + * @dev: PCI device + * @return devfn in bits 15...8 if found, -ENODEV if not found + */ +int pci_get_devfn(struct udevice *dev); + +#endif diff --git a/include/pci.h b/include/pci.h index ff59ac0e695..083f4ee2e90 100644 --- a/include/pci.h +++ b/include/pci.h @@ -482,6 +482,8 @@ #ifndef __ASSEMBLY__ +#include + #ifdef CONFIG_SYS_PCI_64BIT typedef u64 pci_addr_t; typedef u64 pci_size_t; @@ -1612,16 +1614,6 @@ int sandbox_pci_get_emul(struct udevice *bus, pci_dev_t find_devfn, */ int sandbox_pci_get_client(struct udevice *emul, struct udevice **devp); -/** - * pci_get_devfn() - Extract the devfn from fdt_pci_addr of the device - * - * Get devfn from fdt_pci_addr of the specified device - * - * @dev: PCI device - * @return devfn in bits 15...8 if found, -ENODEV if not found - */ -int pci_get_devfn(struct udevice *dev); - #endif /* CONFIG_DM_PCI */ /** -- 2.23.0.866.gb869b98d4c-goog