aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2024-06-03 20:36:18 -0400
committerIan Moffett <ian@osmora.org>2024-06-03 20:36:18 -0400
commit214eadc62b5578f76c98a38a28f8b3d80ac4d6ad (patch)
tree9e104caa48a12511d11a0833afb8005f1fb65e0d
parent46b556a8c7fdbfaa9a11306dea197b2d7363e97c (diff)
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 <ian@osmora.org>
-rw-r--r--sys/dev/ic/ahci.c13
-rw-r--r--sys/dev/pci/pci.c22
-rw-r--r--sys/include/dev/pci/pci.h2
3 files changed, 22 insertions, 15 deletions
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 <dev/pci/pci.h>
#include <dev/ic/ahciregs.h>
#include <dev/ic/ahcivar.h>
+#include <machine/bus.h>
#include <vm/vm.h>
#include <string.h>
@@ -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);
diff --git a/sys/dev/pci/pci.c b/sys/dev/pci/pci.c
index 3be61d9..9a8eae4 100644
--- a/sys/dev/pci/pci.c
+++ b/sys/dev/pci/pci.c
@@ -205,21 +205,21 @@ pci_get_barreg(struct pci_device *dev, uint8_t bar)
}
/*
- * Map a PCI(e) BAR into kernel memory.
+ * Get size length of memory region that a PCI(e) BAR
+ * covers. A returned value of zero is invalid and indicates
+ * an error.
*
- * @dev: Device of BAR to map.
- * @bar: BAR number to map.
- * @vap: Resulting virtual address.
+ * @dev: Device of BAR to get.
+ * @bar: BAR number.
*/
-int
-pci_map_bar(struct pci_device *dev, uint8_t bar, void **vap)
+uint32_t
+pci_bar_size(struct pci_device *dev, uint8_t bar)
{
uint8_t bar_reg = pci_get_barreg(dev, bar);
- uintptr_t tmp;
- uint32_t size;
+ uint32_t tmp, size;
if (bar_reg == 0) {
- return -EINVAL;
+ return 0;
}
/*
@@ -235,9 +235,7 @@ pci_map_bar(struct pci_device *dev, uint8_t bar, void **vap)
/* Now we need to restore the previous value */
pci_writel(dev, bar_reg, tmp);
-
- /* Now do the actual mapping work */
- return bus_map(dev->bar[bar], size, 0, vap);
+ return size;
}
/*
diff --git a/sys/include/dev/pci/pci.h b/sys/include/dev/pci/pci.h
index dbbd7ce..d6edf3b 100644
--- a/sys/include/dev/pci/pci.h
+++ b/sys/include/dev/pci/pci.h
@@ -75,9 +75,9 @@ struct pci_device {
int pci_init(void);
uint32_t pci_readl(struct pci_device *dev, uint32_t offset);
+uint32_t pci_bar_size(struct pci_device *dev, uint8_t bar);
void pci_writel(struct pci_device *dev, uint32_t offset, uint32_t val);
void pci_set_cmdreg(struct pci_device *dev, uint16_t bits);
-int pci_map_bar(struct pci_device *dev, uint8_t bar, void **vap);
struct pci_device *pci_get_device(struct pci_lookup lookup, uint16_t lookup_type);
#endif /* !_DEV_PCI_H_ */