pci: add a helper to detect 32 bit BARs Not sure if the AHCI driver actually needed this or if it was just cruft. This commit cleans up PCI a little, in that no one refers to the mmio_base or size fields directly. Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
diff --git a/kern/arch/x86/pci.c b/kern/arch/x86/pci.c index ecbebee..a00d4ae 100644 --- a/kern/arch/x86/pci.c +++ b/kern/arch/x86/pci.c
@@ -678,6 +678,13 @@ return 0; } +bool pci_bar_is_mem32(struct pci_device *pdev, int bir) +{ + if (bir >= pdev->nr_bars) + return false; + return pci_is_membar32(pdev->bar[bir].raw_bar); +} + uint32_t pci_get_membar_sz(struct pci_device *pcidev, int bir) { if (bir >= pcidev->nr_bars)
diff --git a/kern/arch/x86/pci.h b/kern/arch/x86/pci.h index 6df42ff..88bdd00 100644 --- a/kern/arch/x86/pci.h +++ b/kern/arch/x86/pci.h
@@ -255,6 +255,7 @@ struct pci_device *pci_match_tbdf(int tbdf); uintptr_t pci_get_membar(struct pci_device *pcidev, int bir); uintptr_t pci_get_iobar(struct pci_device *pcidev, int bir); +bool pci_bar_is_mem32(struct pci_device *pdev, int bar); uint32_t pci_get_membar_sz(struct pci_device *pcidev, int bir); uint16_t pci_get_vendor(struct pci_device *pcidev); uint16_t pci_get_device(struct pci_device *pcidev);
diff --git a/kern/drivers/dev/sdiahci.c b/kern/drivers/dev/sdiahci.c index b8e07c3..ce57b4b 100644 --- a/kern/drivers/dev/sdiahci.c +++ b/kern/drivers/dev/sdiahci.c
@@ -2242,10 +2242,13 @@ continue; printd("ahci: %s: ven_id=0x%04x, dev_id=0x%04x, didtype=%d\n", __func__, p->ven_id, p->dev_id, type); - /* TODO: hokey - can this not handle a 64 bit BAR, but the - * device might provide one? Or it just hokey code? */ - if (p->bar[Abar].mmio_base32 == 0) + /* Not sure if this check matters, or if it was code cruft. + * Why wouldn't a 64 bit BAR work? */ + if (!pci_bar_is_mem32(p, Abar)) { + printk("ahci: bar %d was not 'mem32' - aborting\n", + Abar); continue; + } if (niactlr == NCtlr) { printk("ahci: iapnp: %s: too many controllers\n", tname[type]);