PCI: Allow initialization to be deferred.

This is for platforms where information from parsed ACPI namespace
is necessary to fully configure PCI subsystem.

Change-Id: I8bdcfab6b99cbe7fdbc902b9fc13b44133325961
Reviewed-on: https://review.haiku-os.org/c/haiku/+/5273
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: Adrien Destugues <pulkomandy@pulkomandy.tk>
This commit is contained in:
milek7 2022-04-06 20:47:38 +02:00 committed by Adrien Destugues
parent 62298adc03
commit 26a39bed4a
3 changed files with 35 additions and 7 deletions

View File

@ -473,14 +473,20 @@ pcirefresh(int argc, char **argv)
// #pragma mark bus manager init/uninit // #pragma mark bus manager init/uninit
static bool sInitDone;
status_t status_t
pci_init(void) pci_init_deferred(void)
{ {
gPCI = new PCI; if (sInitDone)
return B_OK;
// pci_controller_init may setup things needed by pci_io_init like mmio addresses status_t ret = pci_controller_init();
if (pci_controller_init() != B_OK) { if (ret == B_DEV_NOT_READY)
return ret;
if (ret != B_OK) {
TRACE(("PCI: pci_controller_init failed\n")); TRACE(("PCI: pci_controller_init failed\n"));
return B_ERROR; return B_ERROR;
} }
@ -510,13 +516,36 @@ pci_init(void)
add_debugger_command("pcistatus", &pcistatus, "dump and clear pci device status registers"); add_debugger_command("pcistatus", &pcistatus, "dump and clear pci device status registers");
add_debugger_command("pcirefresh", &pcirefresh, "refresh and print all pci_info"); add_debugger_command("pcirefresh", &pcirefresh, "refresh and print all pci_info");
sInitDone = true;
return B_OK; return B_OK;
} }
status_t
pci_init(void)
{
gPCI = new PCI;
status_t ret = pci_init_deferred();
if (ret == B_DEV_NOT_READY) {
TRACE(("PCI: init deferred\n"));
return B_OK;
}
return ret;
}
void void
pci_uninit(void) pci_uninit(void)
{ {
delete gPCI;
if (!sInitDone)
return;
sInitDone = false;
remove_debugger_command("outw", &write_io); remove_debugger_command("outw", &write_io);
remove_debugger_command("out32", &write_io); remove_debugger_command("out32", &write_io);
remove_debugger_command("outs", &write_io); remove_debugger_command("outs", &write_io);
@ -533,8 +562,6 @@ pci_uninit(void)
remove_debugger_command("pcistatus", &pcistatus); remove_debugger_command("pcistatus", &pcistatus);
remove_debugger_command("pcirefresh", &pcirefresh); remove_debugger_command("pcirefresh", &pcirefresh);
delete gPCI;
} }

View File

@ -196,6 +196,7 @@ extern "C" {
#endif #endif
status_t pci_init(void); status_t pci_init(void);
status_t pci_init_deferred(void);
void pci_uninit(void); void pci_uninit(void);
long pci_get_nth_pci_info(long index, pci_info *outInfo); long pci_get_nth_pci_info(long index, pci_info *outInfo);

View File

@ -130,7 +130,7 @@ pci_root_init(device_node* node, void** _cookie)
if (res < B_OK) if (res < B_OK)
return res; return res;
return B_OK; return pci_init_deferred();
} }