[V9,5/5] of: unittest: Add pci_dt_testdrv pci driver
Commit Message
pci_dt_testdrv is bound to QEMU PCI Test Device. It reads
overlay_pci_node fdt fragment and apply it to Test Device. Then it
calls of_platform_default_populate() to populate the platform
devices.
Signed-off-by: Lizhi Hou <lizhi.hou@amd.com>
---
drivers/of/unittest-data/Makefile | 3 +-
.../of/unittest-data/overlay_pci_node.dtso | 22 ++
drivers/of/unittest.c | 188 ++++++++++++++++++
drivers/pci/quirks.c | 1 +
4 files changed, 213 insertions(+), 1 deletion(-)
create mode 100644 drivers/of/unittest-data/overlay_pci_node.dtso
Comments
Hi all,
On Wed, 21 Jun 2023 10:34:09 -0700
Lizhi Hou <lizhi.hou@amd.com> wrote:
> pci_dt_testdrv is bound to QEMU PCI Test Device. It reads
> overlay_pci_node fdt fragment and apply it to Test Device. Then it
> calls of_platform_default_populate() to populate the platform
> devices.
>
> Signed-off-by: Lizhi Hou <lizhi.hou@amd.com>
> ---
> drivers/of/unittest-data/Makefile | 3 +-
> .../of/unittest-data/overlay_pci_node.dtso | 22 ++
> drivers/of/unittest.c | 188 ++++++++++++++++++
> drivers/pci/quirks.c | 1 +
> 4 files changed, 213 insertions(+), 1 deletion(-)
> create mode 100644 drivers/of/unittest-data/overlay_pci_node.dtso
Did the test under QEMU with the instructions that Lizhi provided at
https://github.com/houlz0507/xoclv2/blob/pci-dt-0329/pci-dt-patch-0329/README
The unittest results were:
--- 8< ---
[ 1.107378] ### dt-test ### pass of_unittest_lifecycle():3273
[ 1.110068] ### dt-test ### pass of_unittest_pci_node():3909
[ 1.110401] ### dt-test ### pass unittest_pci_probe():3840
[ 1.110618] ### dt-test ### pass of_unittest_pci_node():3914
[ 1.110759] ### dt-test ### pass of_unittest_pci_node_verify():3870
[ 1.110894] ### dt-test ### pass of_unittest_pci_node_verify():3877
[ 1.110985] ### dt-test ### pass of_unittest_pci_node_verify():3884
[ 1.111088] ### dt-test ### pass of_unittest_pci_node():3926
[ 1.111171] ### dt-test ### pass of_unittest_pci_node():3927
[ 1.112056] ### dt-test ### pass of_unittest_pci_node_verify():3870
[ 1.112201] ### dt-test ### pass of_unittest_pci_node_verify():3890
[ 1.112326] ### dt-test ### pass of_unittest_pci_node_verify():3892
[ 1.112489] ### dt-test ### pass of_unittest_check_tree_linkage():271
--- 8< ---
Based on the test provided, no failure detected.
Tested-by: Herve Codina <herve.codina@bootlin.com>
Further more, I dumped the dt (PCI related nodes) available on the target.
If someone needs to look at it:
--- 8< ---
# cat /tmp/dt.dts
/dts-v1/;
/ {
#address-cells = <0x02>;
#size-cells = <0x02>;
interrupt-parent = <0x8002>;
compatible = "linux,dummy-virt";
name = [00];
[...]
pcie@10000000 {
#address-cells = <0x03>;
dma-coherent;
bus-range = <0x00 0xff>;
interrupt-map = <0x00 0x00 0x00 0x01 0x8002 0x00 0x00 0x00 0x03 0x04 0x00 0x00 0x00 0x02 0x8002 0x00 0x00 0x00 0x04 0x04 0x00 0x00 0x00 0x03 0x8002 0x00 0x00 0x00 0x05 0x04 0x00 0x00 0x00 0x04 0x8002 0x00 0x00 0x00 0x06 0x04 0x800 0x00 0x00 0x01 0x8002 0x00 0x00 0x00 0x04 0x04 0x800 0x00 0x00 0x02 0x8002 0x00 0x00 0x00 0x05 0x04 0x800 0x00 0x00 0x03 0x8002 0x00 0x00 0x00 0x06 0x04 0x800 0x00 0x00 0x04 0x8002 0x00 0x00 0x00 0x03 0x04 0x1000 0x00 0x00 0x01 0x8002 0x00 0x00 0x00 0x05 0x04 0x1000 0x00 0x00 0x02 0x8002 0x00 0x00 0x00 0x06 0x04 0x1000 0x00 0x00 0x03 0x8002 0x00 0x00 0x00 0x03 0x04 0x1000 0x00 0x00 0x04 0x8002 0x00 0x00 0x00 0x04 0x04 0x1800 0x00 0x00 0x01 0x8002 0x00 0x00 0x00 0x06 0x04 0x1800 0x00 0x00 0x02 0x8002 0x00 0x00 0x00 0x03 0x04 0x1800 0x00 0x00 0x03 0x8002 0x00 0x00 0x00 0x04 0x04 0x1800 0x00 0x00 0x04 0x8002 0x00 0x00 0x00 0x05 0x04>;
#size-cells = <0x02>;
device_type = "pci";
interrupt-map-mask = <0x1800 0x00 0x00 0x07>;
compatible = "pci-host-ecam-generic";
ranges = <0x1000000 0x00 0x00 0x00 0x3eff0000 0x00 0x10000 0x2000000 0x00 0x10000000 0x00 0x10000000 0x00 0x2eff0000 0x3000000 0x80 0x00 0x80 0x00 0x80 0x00>;
#interrupt-cells = <0x01>;
reg = <0x40 0x10000000 0x00 0x10000000>;
linux,pci-domain = <0x00>;
msi-parent = <0x8003>;
name = "pcie";
pci@3,0 {
#address-cells = <0x03>;
#size-cells = <0x02>;
device_type = "pci";
compatible = "pci1b36,c\0pciclass,060400\0pciclass,0604";
ranges = <0x81001800 0x00 0x1000 0x81001800 0x00 0x1000 0x00 0x2000 0x82001800 0x00 0x10000000 0x82001800 0x00 0x10000000 0x00 0x200000 0xc3001800 0x80 0x00 0xc3001800 0x80 0x00 0x00 0x200000>;
reg = <0x1800 0xffff6d76 0xc2b23600 0xffff6d76 0x3fbf63a0>;
pci@0,0 {
#address-cells = <0x03>;
#size-cells = <0x02>;
device_type = "pci";
compatible = "pci104c,8232\0pciclass,060400\0pciclass,0604";
ranges = <0x81010000 0x00 0x1000 0x81010000 0x00 0x1000 0x00 0x1000 0x82010000 0x00 0x10000000 0x82010000 0x00 0x10000000 0x00 0x200000 0xc3010000 0x80 0x00 0xc3010000 0x80 0x00 0x00 0x200000>;
reg = <0x10000 0xffff6d76 0xc2b32580 0xffff6d76 0xc2b1f000>;
pci@0,0 {
#address-cells = <0x03>;
#size-cells = <0x02>;
device_type = "pci";
compatible = "pci104c,8233\0pciclass,060400\0pciclass,0604";
ranges = <0x81020000 0x00 0x1000 0x81020000 0x00 0x1000 0x00 0x1000 0x82020000 0x00 0x10000000 0x82020000 0x00 0x10000000 0x00 0x200000 0xc3020000 0x80 0x00 0xc3020000 0x80 0x00 0x00 0x200000>;
reg = <0x20000 0xffff6d76 0xc2b3f880 0xffff6d76 0xc2b30400>;
dev@0,0 {
#address-cells = <0x03>;
#size-cells = <0x02>;
compatible = "pci1b36,5\0pciclass,00ff00\0pciclass,00ff";
ranges = <0x00 0x00 0x00 0x82030000 0x00 0x10000000 0x00 0x1000 0x01 0x00 0x00 0x81030000 0x00 0x1000 0x00 0x100>;
reg = <0x30000 0xffff6d76 0xc2b42800 0xffff6d76 0xc2b30800>;
};
};
};
};
pci@3,1 {
#address-cells = <0x03>;
#size-cells = <0x02>;
device_type = "pci";
compatible = "pci1b36,c\0pciclass,060400\0pciclass,0604";
ranges = <0x81001900 0x00 0x3000 0x81001900 0x00 0x3000 0x00 0x1000 0x82001900 0x00 0x10200000 0x82001900 0x00 0x10200000 0x00 0x200000 0xc3001900 0x80 0x200000 0xc3001900 0x80 0x200000 0x00 0x200000>;
reg = <0x1900 0xffff6d76 0xc2b29280 0xffff6d76 0x3fbf63a0>;
};
pci@4,0 {
#address-cells = <0x03>;
#size-cells = <0x02>;
device_type = "pci";
compatible = "pci8086,244e\0pciclass,060401\0pciclass,0604";
ranges = <0x82002000 0x00 0x10400000 0x82002000 0x00 0x10400000 0x00 0x100000>;
reg = <0x2000 0xffff6d76 0xc2b32d80 0xffff6d76 0x3fbf63a0>;
pci@0,0 {
#address-cells = <0x03>;
#size-cells = <0x02>;
device_type = "pci";
compatible = "pci1b36,1\0pciclass,060400\0pciclass,0604";
ranges;
reg = <0x50000 0xffff6d76 0xc2b49780 0xffff6d76 0xc2b30100>;
};
};
};
[...]
};
--- 8< ---
Best regards,
Hervé
On Thu, Jun 22, 2023 at 4:27 AM Herve Codina <herve.codina@bootlin.com> wrote:
>
> Hi all,
>
> On Wed, 21 Jun 2023 10:34:09 -0700
> Lizhi Hou <lizhi.hou@amd.com> wrote:
>
> > pci_dt_testdrv is bound to QEMU PCI Test Device. It reads
> > overlay_pci_node fdt fragment and apply it to Test Device. Then it
> > calls of_platform_default_populate() to populate the platform
> > devices.
> >
> > Signed-off-by: Lizhi Hou <lizhi.hou@amd.com>
> > ---
> > drivers/of/unittest-data/Makefile | 3 +-
> > .../of/unittest-data/overlay_pci_node.dtso | 22 ++
> > drivers/of/unittest.c | 188 ++++++++++++++++++
> > drivers/pci/quirks.c | 1 +
> > 4 files changed, 213 insertions(+), 1 deletion(-)
> > create mode 100644 drivers/of/unittest-data/overlay_pci_node.dtso
>
> Did the test under QEMU with the instructions that Lizhi provided at
> https://github.com/houlz0507/xoclv2/blob/pci-dt-0329/pci-dt-patch-0329/README
Instructions need to be in the tree, not living somewhere else. Don't
need the full QEMU setup, but just stating 'add "-device pci-testdev"'
somewhere. Probably in the test failure messages would be the most
helpful location.
>
> The unittest results were:
> --- 8< ---
> [ 1.107378] ### dt-test ### pass of_unittest_lifecycle():3273
> [ 1.110068] ### dt-test ### pass of_unittest_pci_node():3909
> [ 1.110401] ### dt-test ### pass unittest_pci_probe():3840
> [ 1.110618] ### dt-test ### pass of_unittest_pci_node():3914
> [ 1.110759] ### dt-test ### pass of_unittest_pci_node_verify():3870
> [ 1.110894] ### dt-test ### pass of_unittest_pci_node_verify():3877
> [ 1.110985] ### dt-test ### pass of_unittest_pci_node_verify():3884
> [ 1.111088] ### dt-test ### pass of_unittest_pci_node():3926
> [ 1.111171] ### dt-test ### pass of_unittest_pci_node():3927
> [ 1.112056] ### dt-test ### pass of_unittest_pci_node_verify():3870
> [ 1.112201] ### dt-test ### pass of_unittest_pci_node_verify():3890
> [ 1.112326] ### dt-test ### pass of_unittest_pci_node_verify():3892
> [ 1.112489] ### dt-test ### pass of_unittest_check_tree_linkage():271
> --- 8< ---
>
> Based on the test provided, no failure detected.
>
> Tested-by: Herve Codina <herve.codina@bootlin.com>
>
> Further more, I dumped the dt (PCI related nodes) available on the target.
> If someone needs to look at it:
Thanks!
> --- 8< ---
> # cat /tmp/dt.dts
> /dts-v1/;
>
> / {
> #address-cells = <0x02>;
> #size-cells = <0x02>;
> interrupt-parent = <0x8002>;
> compatible = "linux,dummy-virt";
> name = [00];
> [...]
> pcie@10000000 {
> #address-cells = <0x03>;
> dma-coherent;
> bus-range = <0x00 0xff>;
> interrupt-map = <0x00 0x00 0x00 0x01 0x8002 0x00 0x00 0x00 0x03 0x04 0x00 0x00 0x00 0x02 0x8002 0x00 0x00 0x00 0x04 0x04 0x00 0x00 0x00 0x03 0x8002 0x00 0x00 0x00 0x05 0x04 0x00 0x00 0x00 0x04 0x8002 0x00 0x00 0x00 0x06 0x04 0x800 0x00 0x00 0x01 0x8002 0x00 0x00 0x00 0x04 0x04 0x800 0x00 0x00 0x02 0x8002 0x00 0x00 0x00 0x05 0x04 0x800 0x00 0x00 0x03 0x8002 0x00 0x00 0x00 0x06 0x04 0x800 0x00 0x00 0x04 0x8002 0x00 0x00 0x00 0x03 0x04 0x1000 0x00 0x00 0x01 0x8002 0x00 0x00 0x00 0x05 0x04 0x1000 0x00 0x00 0x02 0x8002 0x00 0x00 0x00 0x06 0x04 0x1000 0x00 0x00 0x03 0x8002 0x00 0x00 0x00 0x03 0x04 0x1000 0x00 0x00 0x04 0x8002 0x00 0x00 0x00 0x04 0x04 0x1800 0x00 0x00 0x01 0x8002 0x00 0x00 0x00 0x06 0x04 0x1800 0x00 0x00 0x02 0x8002 0x00 0x00 0x00 0x03 0x04 0x1800 0x00 0x00 0x03 0x8002 0x00 0x00 0x00 0x04 0x04 0x1800 0x00 0x00 0x04 0x8002 0x00 0x00 0x00 0x05 0x04>;
> #size-cells = <0x02>;
> device_type = "pci";
> interrupt-map-mask = <0x1800 0x00 0x00 0x07>;
> compatible = "pci-host-ecam-generic";
> ranges = <0x1000000 0x00 0x00 0x00 0x3eff0000 0x00 0x10000 0x2000000 0x00 0x10000000 0x00 0x10000000 0x00 0x2eff0000 0x3000000 0x80 0x00 0x80 0x00 0x80 0x00>;
> #interrupt-cells = <0x01>;
> reg = <0x40 0x10000000 0x00 0x10000000>;
> linux,pci-domain = <0x00>;
> msi-parent = <0x8003>;
> name = "pcie";
>
> pci@3,0 {
> #address-cells = <0x03>;
> #size-cells = <0x02>;
> device_type = "pci";
> compatible = "pci1b36,c\0pciclass,060400\0pciclass,0604";
> ranges = <0x81001800 0x00 0x1000 0x81001800 0x00 0x1000 0x00 0x2000 0x82001800 0x00 0x10000000 0x82001800 0x00 0x10000000 0x00 0x200000 0xc3001800 0x80 0x00 0xc3001800 0x80 0x00 0x00 0x200000>;
> reg = <0x1800 0xffff6d76 0xc2b23600 0xffff6d76 0x3fbf63a0>;
Something looks wrong with the values here. I found this running it thru dtc.
<stdout>: Warning (pci_device_reg): /pcie@10000000/pci@3,0:reg: PCI
reg config space address cells 2 and 3 must be 0
Rob
On 6/26/23 09:51, Rob Herring wrote:
> On Thu, Jun 22, 2023 at 4:27 AM Herve Codina <herve.codina@bootlin.com> wrote:
>> Hi all,
>>
>> On Wed, 21 Jun 2023 10:34:09 -0700
>> Lizhi Hou <lizhi.hou@amd.com> wrote:
>>
>>> pci_dt_testdrv is bound to QEMU PCI Test Device. It reads
>>> overlay_pci_node fdt fragment and apply it to Test Device. Then it
>>> calls of_platform_default_populate() to populate the platform
>>> devices.
>>>
>>> Signed-off-by: Lizhi Hou <lizhi.hou@amd.com>
>>> ---
>>> drivers/of/unittest-data/Makefile | 3 +-
>>> .../of/unittest-data/overlay_pci_node.dtso | 22 ++
>>> drivers/of/unittest.c | 188 ++++++++++++++++++
>>> drivers/pci/quirks.c | 1 +
>>> 4 files changed, 213 insertions(+), 1 deletion(-)
>>> create mode 100644 drivers/of/unittest-data/overlay_pci_node.dtso
>> Did the test under QEMU with the instructions that Lizhi provided at
>> https://github.com/houlz0507/xoclv2/blob/pci-dt-0329/pci-dt-patch-0329/README
> Instructions need to be in the tree, not living somewhere else. Don't
> need the full QEMU setup, but just stating 'add "-device pci-testdev"'
> somewhere. Probably in the test failure messages would be the most
> helpful location.
Sure. I will add this to the test failure message.
>
>> The unittest results were:
>> --- 8< ---
>> [ 1.107378] ### dt-test ### pass of_unittest_lifecycle():3273
>> [ 1.110068] ### dt-test ### pass of_unittest_pci_node():3909
>> [ 1.110401] ### dt-test ### pass unittest_pci_probe():3840
>> [ 1.110618] ### dt-test ### pass of_unittest_pci_node():3914
>> [ 1.110759] ### dt-test ### pass of_unittest_pci_node_verify():3870
>> [ 1.110894] ### dt-test ### pass of_unittest_pci_node_verify():3877
>> [ 1.110985] ### dt-test ### pass of_unittest_pci_node_verify():3884
>> [ 1.111088] ### dt-test ### pass of_unittest_pci_node():3926
>> [ 1.111171] ### dt-test ### pass of_unittest_pci_node():3927
>> [ 1.112056] ### dt-test ### pass of_unittest_pci_node_verify():3870
>> [ 1.112201] ### dt-test ### pass of_unittest_pci_node_verify():3890
>> [ 1.112326] ### dt-test ### pass of_unittest_pci_node_verify():3892
>> [ 1.112489] ### dt-test ### pass of_unittest_check_tree_linkage():271
>> --- 8< ---
>>
>> Based on the test provided, no failure detected.
>>
>> Tested-by: Herve Codina <herve.codina@bootlin.com>
>>
>> Further more, I dumped the dt (PCI related nodes) available on the target.
>> If someone needs to look at it:
> Thanks!
>
>> --- 8< ---
>> # cat /tmp/dt.dts
>> /dts-v1/;
>>
>> / {
>> #address-cells = <0x02>;
>> #size-cells = <0x02>;
>> interrupt-parent = <0x8002>;
>> compatible = "linux,dummy-virt";
>> name = [00];
>> [...]
>> pcie@10000000 {
>> #address-cells = <0x03>;
>> dma-coherent;
>> bus-range = <0x00 0xff>;
>> interrupt-map = <0x00 0x00 0x00 0x01 0x8002 0x00 0x00 0x00 0x03 0x04 0x00 0x00 0x00 0x02 0x8002 0x00 0x00 0x00 0x04 0x04 0x00 0x00 0x00 0x03 0x8002 0x00 0x00 0x00 0x05 0x04 0x00 0x00 0x00 0x04 0x8002 0x00 0x00 0x00 0x06 0x04 0x800 0x00 0x00 0x01 0x8002 0x00 0x00 0x00 0x04 0x04 0x800 0x00 0x00 0x02 0x8002 0x00 0x00 0x00 0x05 0x04 0x800 0x00 0x00 0x03 0x8002 0x00 0x00 0x00 0x06 0x04 0x800 0x00 0x00 0x04 0x8002 0x00 0x00 0x00 0x03 0x04 0x1000 0x00 0x00 0x01 0x8002 0x00 0x00 0x00 0x05 0x04 0x1000 0x00 0x00 0x02 0x8002 0x00 0x00 0x00 0x06 0x04 0x1000 0x00 0x00 0x03 0x8002 0x00 0x00 0x00 0x03 0x04 0x1000 0x00 0x00 0x04 0x8002 0x00 0x00 0x00 0x04 0x04 0x1800 0x00 0x00 0x01 0x8002 0x00 0x00 0x00 0x06 0x04 0x1800 0x00 0x00 0x02 0x8002 0x00 0x00 0x00 0x03 0x04 0x1800 0x00 0x00 0x03 0x8002 0x00 0x00 0x00 0x04 0x04 0x1800 0x00 0x00 0x04 0x8002 0x00 0x00 0x00 0x05 0x04>;
>> #size-cells = <0x02>;
>> device_type = "pci";
>> interrupt-map-mask = <0x1800 0x00 0x00 0x07>;
>> compatible = "pci-host-ecam-generic";
>> ranges = <0x1000000 0x00 0x00 0x00 0x3eff0000 0x00 0x10000 0x2000000 0x00 0x10000000 0x00 0x10000000 0x00 0x2eff0000 0x3000000 0x80 0x00 0x80 0x00 0x80 0x00>;
>> #interrupt-cells = <0x01>;
>> reg = <0x40 0x10000000 0x00 0x10000000>;
>> linux,pci-domain = <0x00>;
>> msi-parent = <0x8003>;
>> name = "pcie";
>>
>> pci@3,0 {
>> #address-cells = <0x03>;
>> #size-cells = <0x02>;
>> device_type = "pci";
>> compatible = "pci1b36,c\0pciclass,060400\0pciclass,0604";
>> ranges = <0x81001800 0x00 0x1000 0x81001800 0x00 0x1000 0x00 0x2000 0x82001800 0x00 0x10000000 0x82001800 0x00 0x10000000 0x00 0x200000 0xc3001800 0x80 0x00 0xc3001800 0x80 0x00 0x00 0x200000>;
>> reg = <0x1800 0xffff6d76 0xc2b23600 0xffff6d76 0x3fbf63a0>;
> Something looks wrong with the values here. I found this running it thru dtc.
>
> <stdout>: Warning (pci_device_reg): /pcie@10000000/pci@3,0:reg: PCI
> reg config space address cells 2 and 3 must be 0
I will fix this. Thanks.
Lizhi
>
> Rob
@@ -32,7 +32,8 @@ obj-$(CONFIG_OF_OVERLAY) += overlay.dtbo.o \
overlay_gpio_02b.dtbo.o \
overlay_gpio_03.dtbo.o \
overlay_gpio_04a.dtbo.o \
- overlay_gpio_04b.dtbo.o
+ overlay_gpio_04b.dtbo.o \
+ overlay_pci_node.dtbo.o
# enable creation of __symbols__ node
DTC_FLAGS_overlay += -@
new file mode 100644
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: GPL-2.0
+/dts-v1/;
+/ {
+ fragment@0 {
+ target-path="";
+ __overlay__ {
+ #address-cells = <3>;
+ #size-cells = <2>;
+ pci-ep-bus@0 {
+ compatible = "simple-bus";
+ #address-cells = <1>;
+ #size-cells = <1>;
+ ranges = <0x0 0x0 0x0 0x0 0x1000>;
+ reg = <0 0 0 0 0>;
+ unittest-pci@100 {
+ compatible = "unittest-pci";
+ reg = <0x100 0x200>;
+ };
+ };
+ };
+ };
+};
@@ -22,6 +22,7 @@
#include <linux/slab.h>
#include <linux/device.h>
#include <linux/platform_device.h>
+#include <linux/pci.h>
#include <linux/kernel.h>
#include <linux/i2c.h>
@@ -3352,6 +3353,7 @@ OVERLAY_INFO_EXTERN(overlay_gpio_02b);
OVERLAY_INFO_EXTERN(overlay_gpio_03);
OVERLAY_INFO_EXTERN(overlay_gpio_04a);
OVERLAY_INFO_EXTERN(overlay_gpio_04b);
+OVERLAY_INFO_EXTERN(overlay_pci_node);
OVERLAY_INFO_EXTERN(overlay_bad_add_dup_node);
OVERLAY_INFO_EXTERN(overlay_bad_add_dup_prop);
OVERLAY_INFO_EXTERN(overlay_bad_phandle);
@@ -3387,6 +3389,7 @@ static struct overlay_info overlays[] = {
OVERLAY_INFO(overlay_gpio_03, 0),
OVERLAY_INFO(overlay_gpio_04a, 0),
OVERLAY_INFO(overlay_gpio_04b, 0),
+ OVERLAY_INFO(overlay_pci_node, 0),
OVERLAY_INFO(overlay_bad_add_dup_node, -EINVAL),
OVERLAY_INFO(overlay_bad_add_dup_prop, -EINVAL),
OVERLAY_INFO(overlay_bad_phandle, -EINVAL),
@@ -3757,6 +3760,190 @@ static inline __init void of_unittest_overlay_high_level(void) {}
#endif
+#ifdef CONFIG_PCI_DYNAMIC_OF_NODES
+
+int of_unittest_pci_dev_num;
+int of_unittest_pci_child_num;
+
+/*
+ * PCI device tree node test driver
+ */
+static const struct pci_device_id testdrv_pci_ids[] = {
+ { PCI_DEVICE(PCI_VENDOR_ID_REDHAT, 0x5), }, /* PCI_VENDOR_ID_REDHAT */
+ { 0, }
+};
+
+static int testdrv_probe(struct pci_dev *pdev, const struct pci_device_id *id)
+{
+ struct overlay_info *info;
+ struct device_node *dn;
+ int ret, ovcs_id;
+ u32 size;
+
+ dn = pdev->dev.of_node;
+ if (!dn) {
+ dev_err(&pdev->dev, "does not find bus endpoint");
+ return -EINVAL;
+ }
+
+ for (info = overlays; info && info->name; info++) {
+ if (!strcmp(info->name, "overlay_pci_node"))
+ break;
+ }
+ if (!info || !info->name) {
+ dev_err(&pdev->dev, "no overlay data for overlay_pci_node");
+ return -ENODEV;
+ }
+
+ size = info->dtbo_end - info->dtbo_begin;
+ ret = of_overlay_fdt_apply(info->dtbo_begin, size, &ovcs_id, dn);
+ of_node_put(dn);
+ if (ret)
+ return ret;
+
+ of_platform_default_populate(dn, NULL, &pdev->dev);
+ pci_set_drvdata(pdev, (void *)(uintptr_t)ovcs_id);
+
+ return 0;
+}
+
+static void testdrv_remove(struct pci_dev *pdev)
+{
+ int ovcs_id = (int)(uintptr_t)pci_get_drvdata(pdev);
+
+ of_platform_depopulate(&pdev->dev);
+ of_overlay_remove(&ovcs_id);
+}
+
+static struct pci_driver testdrv_driver = {
+ .name = "pci_dt_testdrv",
+ .id_table = testdrv_pci_ids,
+ .probe = testdrv_probe,
+ .remove = testdrv_remove,
+};
+
+static int unittest_pci_probe(struct platform_device *pdev)
+{
+ struct resource *res;
+ struct device *dev;
+ u64 exp_addr;
+
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ if (!res)
+ return -ENODEV;
+
+ dev = &pdev->dev;
+ while (dev && !dev_is_pci(dev))
+ dev = dev->parent;
+ if (!dev) {
+ pr_err("unable to find parent device\n");
+ return -ENODEV;
+ }
+
+ exp_addr = pci_resource_start(to_pci_dev(dev), 0) + 0x100;
+ unittest(res->start == exp_addr, "Incorrect translated address %llx, expected %llx\n",
+ (u64)res->start, exp_addr);
+
+ of_unittest_pci_child_num++;
+
+ return 0;
+}
+
+static const struct of_device_id unittest_pci_of_match[] = {
+ { .compatible = "unittest-pci" },
+ { }
+};
+
+static struct platform_driver unittest_pci_driver = {
+ .probe = unittest_pci_probe,
+ .driver = {
+ .name = "unittest-pci",
+ .of_match_table = unittest_pci_of_match,
+ },
+};
+
+static int of_unittest_pci_node_verify(struct pci_dev *pdev, bool add)
+{
+ struct device_node *pnp, *np = NULL;
+ struct device *child_dev;
+ char *path = NULL;
+ const __be32 *reg;
+ int rc = 0;
+
+ pnp = pdev->dev.of_node;
+ unittest(pnp, "Failed creating PCI dt node\n");
+ if (!pnp)
+ return -ENODEV;
+
+ if (add) {
+ path = kasprintf(GFP_KERNEL, "%pOF/pci-ep-bus@0/unittest-pci@100", pnp);
+ np = of_find_node_by_path(path);
+ unittest(np, "Failed to get unittest-pci node under PCI node\n");
+ if (!np) {
+ rc = -ENODEV;
+ goto failed;
+ }
+
+ reg = of_get_property(np, "reg", NULL);
+ unittest(reg, "Failed to get reg property\n");
+ if (!reg)
+ rc = -ENODEV;
+ } else {
+ path = kasprintf(GFP_KERNEL, "%pOF/pci-ep-bus@0", pnp);
+ np = of_find_node_by_path(path);
+ unittest(!np, "Child device tree node is not removed\n");
+ child_dev = device_find_any_child(&pdev->dev);
+ unittest(!child_dev, "Child device is not removed\n");
+ }
+
+failed:
+ kfree(path);
+ if (np)
+ of_node_put(np);
+
+ return rc;
+}
+
+static void __init of_unittest_pci_node(void)
+{
+ struct pci_dev *pdev = NULL;
+ int rc;
+
+ rc = pci_register_driver(&testdrv_driver);
+ unittest(!rc, "Failed to register pci test driver; rc = %d\n", rc);
+ if (rc)
+ return;
+
+ rc = platform_driver_register(&unittest_pci_driver);
+ if (unittest(!rc, "Failed to register unittest pci driver\n")) {
+ pci_unregister_driver(&testdrv_driver);
+ return;
+ }
+
+ while ((pdev = pci_get_device(PCI_VENDOR_ID_REDHAT, 0x5, pdev)) != NULL) {
+ of_unittest_pci_node_verify(pdev, true);
+ of_unittest_pci_dev_num++;
+ }
+ if (pdev)
+ pci_dev_put(pdev);
+
+ unittest(of_unittest_pci_dev_num, "No test PCI device been found\n");
+ unittest(of_unittest_pci_dev_num == of_unittest_pci_child_num,
+ "Child device number %d is not expected %d", of_unittest_pci_child_num,
+ of_unittest_pci_dev_num);
+
+ platform_driver_unregister(&unittest_pci_driver);
+ pci_unregister_driver(&testdrv_driver);
+
+ while ((pdev = pci_get_device(PCI_VENDOR_ID_REDHAT, 0x5, pdev)) != NULL)
+ of_unittest_pci_node_verify(pdev, false);
+ if (pdev)
+ pci_dev_put(pdev);
+}
+#else
+static void __init of_unittest_pci_node(void) { }
+#endif
+
static int __init of_unittest(void)
{
struct device_node *np;
@@ -3807,6 +3994,7 @@ static int __init of_unittest(void)
of_unittest_platform_populate();
of_unittest_overlay();
of_unittest_lifecycle();
+ of_unittest_pci_node();
/* Double check linkage after removing testcase data */
of_unittest_check_tree_linkage();
@@ -6052,3 +6052,4 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a31, dpc_log_size);
*/
DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_XILINX, 0x5020, of_pci_make_dev_node);
DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_XILINX, 0x5021, of_pci_make_dev_node);
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_REDHAT, 0x0005, of_pci_make_dev_node);