From a0e00b993a4dd19c212e6be6358b78c3ee0ea615 Mon Sep 17 00:00:00 2001 From: p-szafonimateusz Date: Mon, 11 Mar 2024 17:15:05 +0100 Subject: [PATCH] intel64: register PCI controller early but postpone PCI drivers init Some of PCI drivers require OS interfaces that can't be executed in the INIT context. In that case we have to postpone PCI drivers probing and call it for example in board initialization logic. Signed-off-by: p-szafonimateusz --- arch/Kconfig | 1 + arch/x86_64/src/common/x86_64_initialize.c | 6 ++++++ boards/x86_64/intel64/qemu-intel64/src/qemu_bringup.c | 11 +++++++---- drivers/drivers_initialize.c | 2 +- drivers/pci/Kconfig | 8 ++++++++ 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/arch/Kconfig b/arch/Kconfig index 1ad53bf349..43475fea6a 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -138,6 +138,7 @@ config ARCH_X86_64 select ARCH_HAVE_TESTSET select ARCH_HAVE_INTERRUPTSTACK select ARCH_HAVE_CUSTOMOPT + select PCI_LATE_DRIVERS_REGISTER if PCI select LIBC_ARCH_ELF_64BIT if LIBC_ARCH_ELF select ARCH_TOOLCHAIN_GNU ---help--- diff --git a/arch/x86_64/src/common/x86_64_initialize.c b/arch/x86_64/src/common/x86_64_initialize.c index ca289b46ac..412c8c7a16 100644 --- a/arch/x86_64/src/common/x86_64_initialize.c +++ b/arch/x86_64/src/common/x86_64_initialize.c @@ -145,6 +145,12 @@ void up_initialize(void) x86_64_netinitialize(); #endif + /* Initialize the PCI bus */ + +#ifdef CONFIG_PCI + x86_64_pci_init(); +#endif + /* Initialize USB -- device and/or host */ x86_64_usbinitialize(); diff --git a/boards/x86_64/intel64/qemu-intel64/src/qemu_bringup.c b/boards/x86_64/intel64/qemu-intel64/src/qemu_bringup.c index 8a39c3c2ab..4c8b60da5a 100644 --- a/boards/x86_64/intel64/qemu-intel64/src/qemu_bringup.c +++ b/boards/x86_64/intel64/qemu-intel64/src/qemu_bringup.c @@ -36,7 +36,10 @@ # include #endif -#include "x86_64_internal.h" +#ifdef CONFIG_PCI +# include +#endif + #include "qemu_intel64.h" /**************************************************************************** @@ -68,10 +71,10 @@ int qemu_bringup(void) int ret = OK; - /* Initialize the PCI bus */ - #ifdef CONFIG_PCI - x86_64_pci_init(); + /* Register the PCI bus drivers */ + + pci_register_drivers(); #endif #ifdef CONFIG_FS_PROCFS diff --git a/drivers/drivers_initialize.c b/drivers/drivers_initialize.c index 702fdd0069..b38a5ecf39 100644 --- a/drivers/drivers_initialize.c +++ b/drivers/drivers_initialize.c @@ -254,7 +254,7 @@ void drivers_initialize(void) mtd_loop_register(); #endif -#ifdef CONFIG_PCI +#if defined(CONFIG_PCI) && !defined(CONFIG_PCI_LATE_DRIVERS_REGISTER) pci_register_drivers(); #endif diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig index 8722e164ca..f85217c7a5 100644 --- a/drivers/pci/Kconfig +++ b/drivers/pci/Kconfig @@ -12,6 +12,14 @@ menuconfig PCI if PCI +config PCI_LATE_DRIVERS_REGISTER + bool + default n + ---help--- + This option disables PCI driver registration in drivers_initialize(). + Care must be taken to call pci_register_drivers() in later code, most likely + as board specific code. + config PCI_MSIX bool "PCI MSI-X support" default n