PCI: Add power sequencing driver for PCI slots
Subsystems (2)
v3 cover PCI: Add power sequencing driver for PCI slots
Now with tests! This took longer than I thought it would...
Changes in v3:
- Use a parallel structure for emulation
- Add PCI bridge emulation
- Add a test
Changes in v2:
- Return early if there's no PERST GPIO
- Only mdelay if we need to
- Use CONFIG_IS_ENABLED to set .probe directly
Sean Anderson (3):
PCI: sandbox: Use a parallel structure for emulation
PCI: sandbox: Add PCI bridge emulation
PCI: Add power sequencing driver for PCI slots
arch/sandbox/dts/sandbox.dtsi | 16 ++- arch/sandbox/dts/test.dts | 132 +++++++++++++---- arch/sandbox/include/asm/test.h | 1 + configs/sandbox64_defconfig | 2 + configs/sandbox_defconfig | 2 + doc/develop/driver-model/pci-info.rst | 59 ++------ drivers/misc/p2sb_emul.c | 7 +- drivers/misc/swap_case.c | 7 +- drivers/pci/Kconfig | 8 ++ drivers/pci/Makefile | 2 +- drivers/pci/pci-emul-uclass.c | 82 ++++++++--- drivers/pci/pci-uclass.c | 65 +++++++++ drivers/pci/pci_sandbox.c | 94 +++--------- drivers/pci/pci_sandbox_bridge.c | 192 +++++++++++++++++++++++++ include/pci.h | 5 +- test/dm/pci.c | 199 ++++++++++++++++++++++++++ 16 files changed, 694 insertions(+), 179 deletions(-) create mode 100644 drivers/pci/pci_sandbox_bridge.c
Signature · 4 lines
2.35.1.1320.gc452695387.dirty base-commit: 141be72e2a9d43aa4e3d1a6a6e0ab8f9eb8784c6 branch: pci_pwrseq
PATCH v3 1/3 PCI: sandbox: Use a parallel structure for emulation
Currently, sandbox associates PCI emulators with PCI devices on a per-device level. To create this association, the PCI bus needs an ofnode for each device to include the appropriate phandle, or sandbox,dev-info can be used to automatically create PCI devices. In the latter case, the emulator is bound to the PCI device itself! This prevents testing any U-Boot PCI driver, and also precludes bridges without device tree nodes (as non-zero busses cannot be specified with sandbox,dev-info).
Instead of extending sandbox,dev-info, switch to a more-natural approach where PCI emulators form a parallel tree exactly matching the PCI hierarchy to emulate. To do the lookup, we walk up the PCI tree until we get to the root port, look up the emulator, and retrace our steps down the emulator tree.
As it's no longer necessary to have device tree nodes just to link to the appropriate emulator, remove the superfluous ones. 01:10.0 and 02:1f.0 are left in because they are required by dm_test_pci_drvdata and dm_test_pci_mixed, respectively.
---
Changes in v3:
- New
arch/sandbox/dts/sandbox.dtsi | 16 +++-- arch/sandbox/dts/test.dts | 85 +++++++++++++++++------- doc/develop/driver-model/pci-info.rst | 59 +++++------------ drivers/misc/p2sb_emul.c | 7 +- drivers/misc/swap_case.c | 7 +- drivers/pci/pci-emul-uclass.c | 82 +++++++++++++++++------ drivers/pci/pci_sandbox.c | 94 +++++---------------------- include/pci.h | 5 +- 8 files changed, 179 insertions(+), 176 deletions(-)
arch/sandbox/dts/sandbox.dtsi +11 -5
@@ -202,10 +202,11 @@ }; pci@0 { + sandbox,emul = <&pci0_emul>; + pci@1e,0 { compatible = "sandbox,pmc"; reg = <0xf000 0 0 0 0>; - sandbox,emul = <&pmc_emul>; gpe0-dwx-mask = <0xf>; gpe0-dwx-shift-base = <4>; gpe0-dw = <6 7 9>;
@@ -216,17 +217,22 @@ pci@1f,0 { compatible = "pci-generic"; reg = <0xf800 0 0 0 0>; - sandbox,emul = <&swap_case_emul>; }; }; - emul { + pci0_emul: emul { + #address-cells = <1>; + #size-cells = <0>; compatible = "sandbox,pci-emul-parent"; - pmc_emul: emul@1e,0 { + + emul@1e,0 { compatible = "sandbox,pmc-emul"; + reg = <0xf0>; }; - swap_case_emul: emul@1f,0 { + + emul@1f,0 { compatible = "sandbox,swap-case"; + reg = <0xf8>; }; };
arch/sandbox/dts/test.dts +61 -24
156 lines not on this page · raw message
doc/develop/driver-model/pci-info.rst +15 -44
72 lines not on this page · raw message
drivers/misc/p2sb_emul.c +6 -1
@@ -264,9 +264,14 @@ U_BOOT_DRIVER(sandbox_p2sb_emul_emul) = { .plat_auto = sizeof(struct p2sb_emul_plat), }; +U_BOOT_DRIVER (sandbox_p2sb_emul) = { + .name ="sandbox_p2sb_emul" , + .id =UCLASS_MISC , +}; +static struct pci_device_id sandbox_p2sb_emul_supported[] = { {PCI_VDEVICE (SANDBOX ,SANDBOX_PCI_PMC_EMUL_ID ) }, {}, }; -U_BOOT_PCI_DEVICE (sandbox_p2sb_emul_emul, sandbox_p2sb_emul_supported); +U_BOOT_PCI_DEVICE (sandbox_p2sb_emul, sandbox_p2sb_emul_supported);
drivers/misc/swap_case.c +6 -1
@@ -406,10 +406,15 @@ U_BOOT_DRIVER(sandbox_swap_case_emul) = { .plat_auto = sizeof(struct swap_case_plat), }; +U_BOOT_DRIVER (sandbox_swap_case) = { + .name ="sandbox_swap_case" , + .id =UCLASS_MISC , +}; +static struct pci_device_id sandbox_swap_case_supported[] = { {PCI_VDEVICE (SANDBOX ,SANDBOX_PCI_SWAP_CASE_EMUL_ID ),SWAP_CASE_DRV_DATA }, {}, }; -U_BOOT_PCI_DEVICE (sandbox_swap_case_emul, sandbox_swap_case_supported); +U_BOOT_PCI_DEVICE (sandbox_swap_case, sandbox_swap_case_supported);
drivers/pci/pci-emul-uclass.c +61 -21
117 lines not on this page · raw message
drivers/pci/pci_sandbox.c +17 -77
133 lines not on this page · raw message
include/pci.h +2 -3
@@ -1630,12 +1630,11 @@ struct dm_pci_emul_ops {* * @bus: PCI bus to search * @find_devfn: PCI device and function address (PCI_DEVFN()) -* @containerp: Returns container device if found * @emulp: Returns emulated device if found * Return: 0 if found, -ENODEV if not found */ -int sandbox_pci_get_emul (const struct udevice *bus,pci_dev_t find_devfn, -struct udevice **containerp,struct udevice **emulp); +int sandbox_pci_get_emul (struct udevice *bus,pci_dev_t find_devfn, +struct udevice **emulp);/** * sandbox_pci_get_client() - Find the client for an emulation device
Signature · 1 line
2.35.1.1320.gc452695387.dirty
Re: [PATCH v3 1/3] PCI: sandbox: Use a parallel structure for emulation
Hi Sean,
Quoted 26 lines · Sean Anderson
Currently, sandbox associates PCI emulators with PCI devices on a per-device level. To create this association, the PCI bus needs an ofnode for each device to include the appropriate phandle, or sandbox,dev-info can be used to automatically create PCI devices. In the latter case, the emulator is bound to the PCI device itself! This prevents testing any U-Boot PCI driver, and also precludes bridges without device tree nodes (as non-zero busses cannot be specified with sandbox,dev-info).
Instead of extending sandbox,dev-info, switch to a more-natural approach where PCI emulators form a parallel tree exactly matching the PCI hierarchy to emulate. To do the lookup, we walk up the PCI tree until we get to the root port, look up the emulator, and retrace our steps down the emulator tree.
As it's no longer necessary to have device tree nodes just to link to the appropriate emulator, remove the superfluous ones. 01:10.0 and 02:1f.0 are left in because they are required by
dm_test_pci_drvdataanddm_test_pci_mixed, respectively.Signed-off-by Sean Anderson <[email protected]>---
Changes in v3:
- New
Quoted 9 lines
arch/sandbox/dts/sandbox.dtsi | 16 +++-- arch/sandbox/dts/test.dts | 85 +++++++++++++++++------- doc/develop/driver-model/pci-info.rst | 59 +++++------------ drivers/misc/p2sb_emul.c | 7 +- drivers/misc/swap_case.c | 7 +- drivers/pci/pci-emul-uclass.c | 82 +++++++++++++++++------ drivers/pci/pci_sandbox.c | 94 +++++---------------------- include/pci.h | 5 +- 8 files changed, 179 insertions(+), 176 deletions(-)
Thank you for taking this on.
PATCH v3 2/3 PCI: sandbox: Add PCI bridge emulation
In reply to Sean AndersonAdd a PCI bridge emulation device. Although real bridges need to be configured in order to forward requests, this happens automatically for now (see arch/sandbox/lib/pci_io.c). So just record the window registers and check them in a test to make sure pci_auto is sane.
As each bridge consume at least 4k I/O registers, increase the root port's I/O space so we have some left for other devices.
---
Changes in v3:
- New
arch/sandbox/dts/test.dts | 35 +++++- arch/sandbox/include/asm/test.h | 1 + drivers/pci/Makefile | 2 +- drivers/pci/pci_sandbox_bridge.c | 192 +++++++++++++++++++++++++++++++ test/dm/pci.c | 142 +++++++++++++++++++++++ 5 files changed, 370 insertions(+), 2 deletions(-) create mode 100644 drivers/pci/pci_sandbox_bridge.c
arch/sandbox/dts/test.dts +34 -1
@@ -1279,7 +1279,7 @@ #address-cells = <3>; #size-cells = <2>; ranges = <0x02000000 0 0x10000000 0x10000000 0 0x2000000 - 0x01000000 0 0x20000000 0x20000000 0 0x2000>; + 0x01000000 0 0x20000000 0x20000000 0 0x20000>; iommu-map = <0x0010 &iommu 0 1>; iommu-map-mask = <0xfffffff8>; sandbox,emul = <&pci_emul0>;
@@ -1301,6 +1301,15 @@ }; }; + pci@4,0 { + #address-cells = <3>; + #size-cells = <2>; + device_type = "pci"; + compatible = "pciclass,0604"; + reg = <0x00002000 0 0 0 0>; + ranges; + }; + pci@1e,0 { compatible = "sandbox,pmc"; reg = <0xf000 0 0 0 0>;
@@ -1340,6 +1349,30 @@ reg = <0x10>; }; + emul@3,0 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "sandbox,pci-bridge"; + reg = <0x18>; + + emul@0,0 { + compatible = "sandbox,swap-case"; + reg = <0x00>; + }; + }; + + emul@4,0 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "sandbox,pci-bridge"; + reg = <0x20>; + + emul@0,0 { + compatible = "sandbox,swap-case"; + reg = <0x00>; + }; + }; + emul@1e,0 { compatible = "sandbox,pmc-emul"; reg = <0xf0>;
arch/sandbox/include/asm/test.h +1 -0
@@ -19,6 +19,7 @@ struct unit_test_state;#define SANDBOX_PCI_SWAP_CASE_EMUL_ID 0x5678#define SANDBOX_PCI_PMC_EMUL_ID 0x5677#define SANDBOX_PCI_P2SB_EMUL_ID 0x5676 +#define SANDBOX_PCI_BRIDGE_EMUL_ID 0x5662#define SANDBOX_PCI_CLASS_CODE (PCI_CLASS_COMMUNICATION_SERIAL >> 8)#define SANDBOX_PCI_CLASS_SUB_CODE (PCI_CLASS_COMMUNICATION_SERIAL & 0xff)
drivers/pci/Makefile +1 -1
@@ -7,7 +7,7 @@ obj-$(CONFIG_VIDEO) += pci_rom.o obj-$(CONFIG_PCI) += pci-uclass.o pci_auto.o obj-$(CONFIG_DM_PCI_COMPAT) += pci_compat.o obj-$(CONFIG_PCI_SANDBOX) += pci_sandbox.o -obj-$(CONFIG_SANDBOX) += pci-emul-uclass.o +obj-$(CONFIG_SANDBOX) += pci-emul-uclass.o pci_sandbox_bridge.o obj-$(CONFIG_X86) += pci_x86.o pci_rom.o obj-$(CONFIG_PCI) += pci_auto_common.o pci_common.o
drivers/pci/pci_sandbox_bridge.c new file +192 -0
192 lines not on this page · raw message
test/dm/pci.c +142 -0
151 lines not on this page · raw message
Signature · 1 line
2.35.1.1320.gc452695387.dirty
Re: [PATCH v3 2/3] PCI: sandbox: Add PCI bridge emulation
Quoted 15 lines · Sean Anderson
Add a PCI bridge emulation device. Although real bridges need to be configured in order to forward requests, this happens automatically for now (see
arch/sandbox/lib/pci_io.c). So just record the window registers and check them in a test to make surepci_autois sane.As each bridge consume at least 4k I/O registers, increase the root port's I/O space so we have some left for other devices.
Signed-off-by Sean Anderson <[email protected]>---
Changes in v3:
- New
Quoted 7 lines
arch/sandbox/dts/test.dts | 35 +++++- arch/sandbox/include/asm/test.h | 1 + drivers/pci/Makefile | 2 +- drivers/pci/pci_sandbox_bridge.c | 192 +++++++++++++++++++++++++++++++ test/dm/pci.c | 142 +++++++++++++++++++++++ 5 files changed, 370 insertions(+), 2 deletions(-) create mode 100644 drivers/pci/pci_sandbox_bridge.c
PATCH v3 3/3 PCI: Add power sequencing driver for PCI slots
In reply to Sean AndersonExtend the PCI bridge driver to enable resources associated with PCI slots like clocks, power rails, and resets. This is modeled off of the PCI power control subsystem in Linux. The traditional compatible for PCI slots in U-Boot is pci-bridge, but Linux uses the more-systematic pciclass,0604 so add that as an option.
Add a test to make sure the clock/gpio get enabled and that we skip some of the delays when PERST is already asserted.
---
Changes in v3:
- Add a test
Changes in v2:
- Return early if there's no PERST GPIO
- Only mdelay if we need to
- Use CONFIG_IS_ENABLED to set .probe directly
arch/sandbox/dts/test.dts | 12 ++++++- configs/sandbox64_defconfig | 2 ++ configs/sandbox_defconfig | 2 ++ drivers/pci/Kconfig | 8 +++++ drivers/pci/pci-uclass.c | 65 +++++++++++++++++++++++++++++++++++++ test/dm/pci.c | 57 ++++++++++++++++++++++++++++++++ 6 files changed, 145 insertions(+), 1 deletion(-)
arch/sandbox/dts/test.dts +11 -1
@@ -632,6 +632,13 @@ clocks = <&clk_fixed>; }; + pci_refclk: clk-gpio { + compatible = "gpio-gate-clock"; + #clock-cells = <0>; + clocks = <&clk_fixed>; + enable-gpios = <&gpio_a 26>; + }; + osc { compatible = "fixed-clock"; #clock-cells = <0>;
@@ -822,7 +829,7 @@ gpio-controller; #gpio-cells = <1>; gpio-bank-name = "a"; - sandbox,gpio-count = <25>; + sandbox,gpio-count = <27>; gpio-line-names = "", "eth1-reset", "rtc-irq"; hog_input_active_low { gpio-hog;
@@ -1308,6 +1315,9 @@ compatible = "pciclass,0604"; reg = <0x00002000 0 0 0 0>; ranges; + + clocks = <&pci_refclk>; + reset-gpios = <&gpio_a 25>; }; pci@1e,0 {
configs/sandbox64_defconfig +2 -0
@@ -139,6 +139,7 @@ CONFIG_BUTTON_ADC=y CONFIG_BUTTON_GPIO=y CONFIG_CLK=y CONFIG_CLK_COMPOSITE_CCF=y +CONFIG_CLK_GPIO=y CONFIG_CLK_K210=y CONFIG_CLK_K210_SET_RATE=y CONFIG_SANDBOX_CLK_CCF=y
@@ -201,6 +202,7 @@ CONFIG_SPI_FLASH_WINBOND=y CONFIG_NVMXIP_QSPI=y CONFIG_NVME_PCI=y CONFIG_PCI_REGION_MULTI_ENTRY=y +CONFIG_PCI_PWRCTRL_SLOT=y CONFIG_PCI_SANDBOX=y CONFIG_PHY=y CONFIG_PHY_SANDBOX=y
configs/sandbox_defconfig +2 -0
@@ -191,6 +191,7 @@ CONFIG_BUTTON_ADC=y CONFIG_BUTTON_GPIO=y CONFIG_CLK=y CONFIG_CLK_COMPOSITE_CCF=y +CONFIG_CLK_GPIO=y CONFIG_CLK_K210=y CONFIG_CLK_K210_SET_RATE=y CONFIG_SANDBOX_CLK_CCF=y
@@ -279,6 +280,7 @@ CONFIG_MULTIPLEXER=y CONFIG_MUX_MMIO=y CONFIG_NVME_PCI=y CONFIG_PCI_REGION_MULTI_ENTRY=y +CONFIG_PCI_PWRCTRL_SLOT=y CONFIG_PCI_FTPCI100=y CONFIG_PCI_SANDBOX=y CONFIG_PHY=y
drivers/pci/Kconfig +8 -0
@@ -100,6 +100,14 @@ config PCI_ENHANCED_ALLOCATION Enable support for Enhanced Allocation which can be used by supported devices in place of traditional BARS for allocation of resources. +config PCI_PWRCTRL_SLOT + bool "PCI slot power control" + help + This is a generic driver that controls the power state of different + PCI slots. The clocks and resets for the PCI slots are expected to be + defined in the devicetree node of the PCI bridge. Say N if your PCI + busses don't have software-controlled clocks or power rails. + config PCI_ARID bool "Enable Alternate Routing-ID support for PCI" help
drivers/pci/pci-uclass.c +65 -0
90 lines not on this page · raw message
test/dm/pci.c +57 -0
150 lines not on this page · raw message
Signature · 1 line
2.35.1.1320.gc452695387.dirty
Quoted 21 lines · Sean Anderson
Extend the PCI bridge driver to enable resources associated with PCI slots like clocks, power rails, and resets. This is modeled off of the PCI power control subsystem in Linux. The traditional compatible for PCI slots in U-Boot is pci-bridge, but Linux uses the more-systematic pciclass,0604 so add that as an option.
Add a test to make sure the clock/gpio get enabled and that we skip some of the delays when PERST is already asserted.
Signed-off-by Sean Anderson <[email protected]>---
Changes in v3:
- Add a testChanges in v2:
- Return early if there's no PERST GPIO
- Only mdelay if we need to
- UseCONFIG_IS_ENABLEDto set .probe directly
Quoted 7 lines
arch/sandbox/dts/test.dts | 12 ++++++- configs/sandbox64_defconfig | 2 ++ configs/sandbox_defconfig | 2 ++ drivers/pci/Kconfig | 8 +++++ drivers/pci/pci-uclass.c | 65 +++++++++++++++++++++++++++++++++++++ test/dm/pci.c | 57 ++++++++++++++++++++++++++++++++ 6 files changed, 145 insertions(+), 1 deletion(-)
At some point we should have a static inline to skip delays on sandbox, e.g. arch_skip_delays() like we have arch_reset_for_test() - that would avoid the #include and the #ifdef
Quoted 279 lines
arch/sandbox/dts/test.dts +11
-1@@ -632,6 +632,13 @@ clocks = <&clk_fixed>; }; + pci_refclk: clk-gpio { + compatible = "gpio-gate-clock"; + #clock-cells = <0>; + clocks = <&clk_fixed>; + enable-gpios = <&gpio_a 26>; + }; + osc { compatible = "fixed-clock"; #clock-cells = <0>;@@ -822,7 +829,7 @@ gpio-controller; #gpio-cells = <1>; gpio-bank-name = "a"; - sandbox,gpio-count = <25>; + sandbox,gpio-count = <27>; gpio-line-names = "", "eth1-reset", "rtc-irq"; hog_input_active_low { gpio-hog;@@ -1308,6 +1315,9 @@ compatible = "pciclass,0604"; reg = <0x00002000 0 0 0 0>; ranges; + + clocks = <&pci_refclk>; + reset-gpios = <&gpio_a 25>; }; pci@1e,0 {configs/sandbox64_defconfig +2
-0@@ -139,6 +139,7 @@ CONFIG_BUTTON_ADC=y CONFIG_BUTTON_GPIO=y CONFIG_CLK=y CONFIG_CLK_COMPOSITE_CCF=y +CONFIG_CLK_GPIO=y CONFIG_CLK_K210=y CONFIG_CLK_K210_SET_RATE=y CONFIG_SANDBOX_CLK_CCF=y@@ -201,6 +202,7 @@ CONFIG_SPI_FLASH_WINBOND=y CONFIG_NVMXIP_QSPI=y CONFIG_NVME_PCI=y CONFIG_PCI_REGION_MULTI_ENTRY=y +CONFIG_PCI_PWRCTRL_SLOT=y CONFIG_PCI_SANDBOX=y CONFIG_PHY=y CONFIG_PHY_SANDBOX=yconfigs/sandbox_defconfig +2
-0@@ -191,6 +191,7 @@ CONFIG_BUTTON_ADC=y CONFIG_BUTTON_GPIO=y CONFIG_CLK=y CONFIG_CLK_COMPOSITE_CCF=y +CONFIG_CLK_GPIO=y CONFIG_CLK_K210=y CONFIG_CLK_K210_SET_RATE=y CONFIG_SANDBOX_CLK_CCF=y@@ -279,6 +280,7 @@ CONFIG_MULTIPLEXER=y CONFIG_MUX_MMIO=y CONFIG_NVME_PCI=y CONFIG_PCI_REGION_MULTI_ENTRY=y +CONFIG_PCI_PWRCTRL_SLOT=y CONFIG_PCI_FTPCI100=y CONFIG_PCI_SANDBOX=y CONFIG_PHY=ydrivers/pci/Kconfig +8
-0@@ -100,6 +100,14 @@ config PCI_ENHANCED_ALLOCATION Enable support for Enhanced Allocation which can be used by supported devices in place of traditional BARS for allocation of resources. +config PCI_PWRCTRL_SLOT + bool "PCI slot power control" + help + This is a generic driver that controls the power state of different + PCI slots. The clocks and resets for the PCI slots are expected to be + defined in the devicetree node of the PCI bridge. Say N if your PCI + busses don't have software-controlled clocks or power rails. + config PCI_ARID bool "Enable Alternate Routing-ID support for PCI" helpdrivers/pci/pci-uclass.c +65
-0@@ -6,6 +6,7 @@#define LOG_CATEGORY UCLASS_PCI +#include <clk.h> #include <dm.h> #include <errno.h> #include <init.h> @@ -14,6 +15,7 @@#include <pci.h> #include <spl.h> #include <asm/global_data.h> +#include <asm/gpio.h> #include <asm/io.h> #include <dm/device-internal.h> #include <dm/lists.h> @@ -1893,13 +1895,76 @@ static const struct dm_pci_ops pci_bridge_ops = {static const struct udevice_id pci_bridge_ids[] = { { .compatible ="pci-bridge" }, + { .compatible ="pciclass,0604" }, { } }; +#ifdef CONFIG_SANDBOX +#include <asm/state.h> +#endif + +static int __maybe_unused pci_bridge_probe (struct udevice *dev) +{ +struct clk clk; +struct gpio_desc perst; +unsigned long delay =0 ; +int ret; + +if (!clk_get_by_index (dev,0 , &clk)) { +int ret =clk_enable (&clk); + +if (ret) +return log_msg_ret ("clk" , ret); + +/* Delay for T_PERST-CLK (100 us for all slot types) */ +udelay (100 ); + } + +if (gpio_request_by_name (dev,"reset-gpios" ,0 , &perst,0 )) +return 0 ; + +/* +* If PERST is inactive, the following call to dm_gpio_clrset_flags +* will be the first time we assert it and we will need to delay for +* T_PERST. +*/ +if (dm_gpio_get_value (&perst) !=1 ) + delay =100 ; + + ret =dm_gpio_clrset_flags (&perst,GPIOD_MASK_DIR , +GPIOD_IS_OUT |GPIOD_IS_OUT_ACTIVE ); +if (ret) +return log_msg_ret ("set" , ret); + +#ifdef CONFIG_SANDBOX + if (!state_get_skip_delays()) +#endif + if (delay) + mdelay(delay); + + ret = dm_gpio_set_value(&perst, 0); + if (ret) + return log_msg_ret("clr", ret); + + /* + * PCIe section 6.6.1: + * > ... software must wait a minimum of 100 ms before sending a + * > Configuration Request to the device immediately below that Port. + */ +#ifdef CONFIG_SANDBOX + if (!state_get_skip_delays()) +#endif + mdelay(100); + + return 0; +} + U_BOOT_DRIVER(pci_bridge_drv) = { .name = "pci_bridge_drv", .id = UCLASS_PCI, .of_match = pci_bridge_ids, + .probe = CONFIG_IS_ENABLED(PCI_PWRCTRL_SLOT, + (pci_bridge_probe), NULL), .ops = &pci_bridge_ops, };test/dm/pci.c +10
-0@@ -5,6 +5,7 @@#include <dm.h> #include <dm/device_compat.h> +#include <asm/gpio.h> #include <asm/io.h> #include <asm/test.h> #include <dm/test.h> @@ -16,6 +17,7 @@ static int dm_test_pci_base(struct unit_test_state *uts) {struct udevice *bus; +test_set_skip_delays (true);ut_assertok (uclass_get_device (UCLASS_PCI ,0 , &bus));return 0 ;@@ -30,6 +32,7 @@ static int dm_test_pci_busdev(struct unit_test_state *uts)u16 vendor, device;/* Test bus#0 and its devices */ +test_set_skip_delays (true);ut_assertok (uclass_get_device_by_seq (UCLASS_PCI ,0 , &bus));ut_assertok (dm_pci_bus_find_bdf (PCI_BDF (0 ,0x00 ,0 ), &swap));@@ -65,6 +68,7 @@ static int dm_test_pci_swapcase(struct unit_test_state *uts)char *ptr;/* Check that asking for the device 0 automatically fires up PCI */ +test_set_skip_delays (true);ut_assertok (dm_pci_bus_find_bdf (PCI_BDF (0 ,0x00 ,0 ), &swap));/* First test I/O */ @@ -116,6 +120,7 @@ static int dm_test_pci_drvdata(struct unit_test_state *uts)struct udevice *bus, *swap;/* Check that asking for the device automatically fires up PCI */ +test_set_skip_delays (true);ut_assertok (uclass_get_device_by_seq (UCLASS_PCI ,1 , &bus));ut_assertok (dm_pci_bus_find_bdf (PCI_BDF (1 ,0x08 ,0 ), &swap));@@ -141,6 +146,7 @@ static int dm_test_pci_mixed(struct unit_test_state *uts)ulong io_addr, mem_addr;char *ptr; +test_set_skip_delays (true);ut_assertok (uclass_get_device_by_seq (UCLASS_PCI ,2 , &bus));/* Test the dynamic device */ @@ -201,6 +207,7 @@ static int dm_test_pci_cap(struct unit_test_state *uts)struct udevice *bus, *swap;int cap; +test_set_skip_delays (true);ut_assertok (uclass_get_device_by_seq (UCLASS_PCI ,0 , &bus));ut_assertok (dm_pci_bus_find_bdf (PCI_BDF (0 ,0x1f ,0 ), &swap));@@ -258,6 +265,7 @@ static int dm_test_pci_ea(struct unit_test_state *uts)* use emulated device mapping function, we're not using real physical * addresses in this test */ +test_set_skip_delays (true);sandbox_set_enable_pci_map (true);ut_assertok (uclass_get_device_by_seq (UCLASS_PCI ,0 , &bus));@@ -303,6 +311,7 @@ static int dm_test_pci_addr_flat(struct unit_test_state *uts)ulong io_addr, mem_addr;fdt_addr_t size; +test_set_skip_delays (true);ut_assertok (dm_pci_bus_find_bdf (PCI_BDF (0 ,0x1f ,0 ), &swap1f)); io_addr =dm_pci_read_bar32 (swap1f,0 );ut_asserteq (io_addr,dev_read_addr_pci (swap1f, &size));@@ -334,6 +343,7 @@ static int dm_test_pci_addr_live(struct unit_test_state *uts)struct udevice *swap1f, *swap1;fdt_size_t size; +test_set_skip_delays (true);ut_assertok (dm_pci_bus_find_bdf (PCI_BDF (0 ,0x1f ,0 ), &swap1f));ut_asserteq_64 (FDT_ADDR_T_NONE ,dev_read_addr_pci (swap1f, &size));ut_asserteq (0 , size);
test/dm/pci.c static int dm_test_pci_on_bus(struct unit_test_state *uts) · line 366
Quoted 6 lines
test/dm/pci.c +1
-0@@ -351,6 +361,7 @@ static int dm_test_pci_on_bus(struct unit_test_state *uts) {struct udevice *dev; +test_set_skip_delays (true);ut_assertok (dm_pci_bus_find_bdf (PCI_BDF (0 ,0x1f ,0 ), &dev));ut_asserteq (true,device_is_on_pci_bus (dev));
ut_assert(device_is_on_pci_bus(dev));
test/dm/pci.c static int dm_test_pci_on_bus(struct unit_test_state *uts) · line 367
Quoted 1 line
test/dm/pci.c +0
-0ut_asserteq (false,device_is_on_pci_bus (dev_get_parent (dev)));
ut_assert(!...)
Quoted 42 lines
test/dm/pci.c +10
-0@@ -374,6 +385,7 @@ static int dm_test_pci_region_multi(struct unit_test_state *uts)ulong mem_addr;/* Test memory BAR1 on bus#1 */ +test_set_skip_delays (true);ut_assertok (dm_pci_bus_find_bdf (PCI_BDF (1 ,0x08 ,0 ), &dev)); mem_addr =dm_pci_read_bar32 (dev,1 );ut_asserteq (mem_addr,0x30000000 );@@ -393,6 +405,7 @@ static int dm_test_pci_bus_to_phys(struct unit_test_state *uts)struct udevice *dev;phys_addr_t phys_addr; +test_set_skip_delays (true);ut_assertok (dm_pci_bus_find_bdf (PCI_BDF (1 ,0x08 ,0 ), &dev));/* Before any of the ranges. */ @@ -446,6 +459,7 @@ static int dm_test_pci_phys_to_bus(struct unit_test_state *uts)struct udevice *dev;pci_addr_t pci_addr; +test_set_skip_delays (true);ut_assertok (dm_pci_bus_find_bdf (PCI_BDF (1 ,0x08 ,0 ), &dev));/* Before any of the ranges. */ @@ -620,6 +634,7 @@ static int dm_test_pci_bridge_windows(struct unit_test_state *uts) {struct udevice *bus; +test_set_skip_delays (true);ut_assertok (dm_pci_bus_find_bdf (PCI_BDF (0 ,0x03 ,0 ), &bus));if (_dm_test_pci_bridge_windows (uts, bus))return CMD_RET_FAILURE ;@@ -628,3 +643,45 @@ static int dm_test_pci_bridge_windows(struct unit_test_state *uts)return _dm_test_pci_bridge_windows (uts, bus); }DM_TEST (dm_test_pci_bridge_windows,UTF_SCAN_PDATA |UTF_SCAN_FDT ); + +#if IS_ENABLED (CONFIG_PCI_PWRCTRL_SLOT ) +/* GPIO 25 is PERST; GPIO 26 is REFCLK enable */ +static int dm_test_pci_pwrseq_cold (struct unit_test_state *uts) +{ +struct udevice *bus, *gpio;
test/dm/pci.c static int dm_test_pci_bridge_windows(struct unit_test_state *uts) · line 661
Quoted 10 lines
test/dm/pci.c +10
-0+unsigned long start, end; + +ut_assertok (uclass_get_device (UCLASS_GPIO ,1 , &gpio)); +ut_assertok (sandbox_gpio_set_value (gpio,25 ,1 )); + + start =timer_get_us (); +ut_assertok (dm_pci_bus_find_bdf (PCI_BDF (0 ,0x04 ,0 ), &bus)); + end =timer_get_us (); +ut_assert (end - start >100000 ); +ut_assert (end - start <200000 );
We do have get_timer_us() so another option is:
start = get_timer_us(0);ut_assert(get_timer_us(start) > 100000);
Quoted 27 lines
test/dm/pci.c +26
-1+ +ut_asserteq (0 ,sandbox_gpio_get_value (gpio,25 )); +ut_asserteq (1 ,sandbox_gpio_get_value (gpio,26 )); + +return 0 ; +} +DM_TEST (dm_test_pci_pwrseq_cold,UTF_SCAN_PDATA |UTF_SCAN_FDT ); + +static int dm_test_pci_pwrseq_warm (struct unit_test_state *uts) +{ +struct udevice *bus, *gpio; +unsigned long start; + +ut_assertok (uclass_get_device (UCLASS_GPIO ,1 , &gpio)); + + start =timer_get_us (); +ut_assertok (dm_pci_bus_find_bdf (PCI_BDF (0 ,0x04 ,0 ), &bus)); +ut_assert (timer_get_us () - start >200000 ); + +ut_asserteq (0 ,sandbox_gpio_get_value (gpio,25 )); +ut_asserteq (1 ,sandbox_gpio_get_value (gpio,26 )); + +return 0 ; +} +DM_TEST (dm_test_pci_pwrseq_warm,UTF_SCAN_PDATA |UTF_SCAN_FDT ); +#endif --
Quoted 2 lines
2.35.1.1320.gc452695387.dirty
Regards,
Simon