diff mbox series

[U-Boot,1/4,v3] pci: Add pci_get_devfn() to extract devfn from the fdt_pci_addr

Message ID 20190125105245.12624-1-sr@denx.de
State Accepted
Commit b52142004fbdfd6db0091ba7ae33c91e3b459034
Delegated to: Stefan Roese
Headers show
Series [U-Boot,1/4,v3] pci: Add pci_get_devfn() to extract devfn from the fdt_pci_addr | expand

Commit Message

Stefan Roese Jan. 25, 2019, 10:52 a.m. UTC
This function will be used by the Marvell Armada XP/38x PCIe driver,
which is moved to DM right now. So let's extract the functionality
from pci_uclass_child_post_bind() to make it available.

Signed-off-by: Stefan Roese <sr@denx.de>
Cc: Simon Glass <sjg@chromium.org>
Cc: Bin Meng <bmeng.cn@gmail.com>
---
v3:
- New patch, replaces "[PATCH] core: ofnode: Add ofnode_pci_get_devfn()"

 drivers/pci/pci-uclass.c | 28 +++++++++++++++++++---------
 include/pci.h            | 10 ++++++++++
 2 files changed, 29 insertions(+), 9 deletions(-)

Comments

Simon Glass Jan. 31, 2019, 10:04 a.m. UTC | #1
On Fri, 25 Jan 2019 at 03:52, Stefan Roese <sr@denx.de> wrote:
>
> This function will be used by the Marvell Armada XP/38x PCIe driver,
> which is moved to DM right now. So let's extract the functionality
> from pci_uclass_child_post_bind() to make it available.
>
> Signed-off-by: Stefan Roese <sr@denx.de>
> Cc: Simon Glass <sjg@chromium.org>
> Cc: Bin Meng <bmeng.cn@gmail.com>
> ---
> v3:
> - New patch, replaces "[PATCH] core: ofnode: Add ofnode_pci_get_devfn()"
>
>  drivers/pci/pci-uclass.c | 28 +++++++++++++++++++---------
>  include/pci.h            | 10 ++++++++++
>  2 files changed, 29 insertions(+), 9 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>
Bin Meng Jan. 31, 2019, 2:38 p.m. UTC | #2
On Fri, Jan 25, 2019 at 6:52 PM Stefan Roese <sr@denx.de> wrote:
>
> This function will be used by the Marvell Armada XP/38x PCIe driver,
> which is moved to DM right now. So let's extract the functionality
> from pci_uclass_child_post_bind() to make it available.
>
> Signed-off-by: Stefan Roese <sr@denx.de>
> Cc: Simon Glass <sjg@chromium.org>
> Cc: Bin Meng <bmeng.cn@gmail.com>
> ---
> v3:
> - New patch, replaces "[PATCH] core: ofnode: Add ofnode_pci_get_devfn()"
>
>  drivers/pci/pci-uclass.c | 28 +++++++++++++++++++---------
>  include/pci.h            | 10 ++++++++++
>  2 files changed, 29 insertions(+), 9 deletions(-)
>

Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Stefan Roese Feb. 5, 2019, 1:26 p.m. UTC | #3
On 31.01.19 11:04, Simon Glass wrote:
> On Fri, 25 Jan 2019 at 03:52, Stefan Roese <sr@denx.de> wrote:
>>
>> This function will be used by the Marvell Armada XP/38x PCIe driver,
>> which is moved to DM right now. So let's extract the functionality
>> from pci_uclass_child_post_bind() to make it available.
>>
>> Signed-off-by: Stefan Roese <sr@denx.de>
>> Cc: Simon Glass <sjg@chromium.org>
>> Cc: Bin Meng <bmeng.cn@gmail.com>
>> ---
>> v3:
>> - New patch, replaces "[PATCH] core: ofnode: Add ofnode_pci_get_devfn()"
>>
>>   drivers/pci/pci-uclass.c | 28 +++++++++++++++++++---------
>>   include/pci.h            | 10 ++++++++++
>>   2 files changed, 29 insertions(+), 9 deletions(-)
> 
> Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot-marvell/master

Thanks,
Stefan
diff mbox series

Patch

diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c
index 2cf55cb743..47f3cc9107 100644
--- a/drivers/pci/pci-uclass.c
+++ b/drivers/pci/pci-uclass.c
@@ -1007,10 +1007,25 @@  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;
-	struct fdt_pci_addr addr;
 	int ret;
 
 	if (!dev_of_valid(dev))
@@ -1022,14 +1037,9 @@  static int pci_uclass_child_post_bind(struct udevice *dev)
 	ofnode_read_pci_vendev(dev_ofnode(dev), &pplat->vendor, &pplat->device);
 
 	/* 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;
-	} else {
-		pplat->devfn = addr.phys_hi & 0xff00;
-	}
+	pplat->devfn = pci_get_devfn(dev);
+	if (ret < 0)
+		return ret;
 
 	return 0;
 }
diff --git a/include/pci.h b/include/pci.h
index 785d7d28b7..041f8e3747 100644
--- a/include/pci.h
+++ b/include/pci.h
@@ -1560,6 +1560,16 @@  struct dm_pci_emul_ops {
 int sandbox_pci_get_emul(struct udevice *bus, pci_dev_t find_devfn,
 			 struct udevice **containerp, struct udevice **emulp);
 
+/**
+ * pci_get_devfn() - Extract the devfn from fdt_pci_addr of the device
+ *
+ * Get devfn from fdt_pci_addr of the specifified 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 */
 
 /**