From 214eadc62b5578f76c98a38a28f8b3d80ac4d6ad Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Mon, 3 Jun 2024 20:36:18 -0400 Subject: kernel: pci: Require mapping BAR using bus_map() This commit gets rid of pci_map_bar() as some devices have their base address spanning mulitple BARs. This change also exposes PCI bar size logic through pci_bar_size() Signed-off-by: Ian Moffett --- sys/dev/ic/ahci.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'sys/dev/ic') diff --git a/sys/dev/ic/ahci.c b/sys/dev/ic/ahci.c index 3ff13cf..257fd00 100644 --- a/sys/dev/ic/ahci.c +++ b/sys/dev/ic/ahci.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include @@ -724,6 +725,7 @@ ahci_init(void) { int status; uint16_t cmdreg_bits; + uint32_t bar_size; struct ahci_hba hba = {0}; struct pci_lookup ahci_lookup = { .pci_class = 0x01, @@ -749,8 +751,15 @@ ahci_init(void) return -1; } - if ((status = pci_map_bar(dev, 5, (void *)&hba.abar)) != 0) { - return status; + if ((bar_size = pci_bar_size(dev, 5)) == 0) { + pr_error("Failed to fetch BAR size\n"); + return -1; + } + + status = bus_map(dev->bar[5], bar_size, 0, (void *)&hba.abar); + if (status != 0) { + pr_error("Failed to map BAR into higher half\n"); + return -1; } pr_trace("AHCI HBA memspace @ 0x%p\n", hba.abar); -- cgit v1.2.3