The branch main has been updated by jhb:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=762f1c7c6cded9242956c2c35c772dff9b5d155b

commit 762f1c7c6cded9242956c2c35c772dff9b5d155b
Author:     John Baldwin <[email protected]>
AuthorDate: 2025-10-06 17:56:47 +0000
Commit:     John Baldwin <[email protected]>
CommitDate: 2025-10-06 17:56:47 +0000

    ahci: Use pci_msix_*_bar instead of reading config registers directly
    
    Reported by:    avg
    Reviewed by:    avg, imp
    Differential Revision:  https://reviews.freebsd.org/D52888
---
 sys/dev/ahci/ahci_pci.c | 38 +++-----------------------------------
 1 file changed, 3 insertions(+), 35 deletions(-)

diff --git a/sys/dev/ahci/ahci_pci.c b/sys/dev/ahci/ahci_pci.c
index 82f56fc0d19e..80547d178cd6 100644
--- a/sys/dev/ahci/ahci_pci.c
+++ b/sys/dev/ahci/ahci_pci.c
@@ -466,28 +466,6 @@ ahci_ata_probe(device_t dev)
        return (BUS_PROBE_DEFAULT);
 }
 
-static int
-ahci_pci_read_msix_bars(device_t dev, uint8_t *table_bar, uint8_t *pba_bar)
-{
-       int cap_offset = 0, ret;
-       uint32_t val;
-
-       if ((table_bar == NULL) || (pba_bar == NULL))
-               return (EINVAL);
-
-       ret = pci_find_cap(dev, PCIY_MSIX, &cap_offset);
-       if (ret != 0)
-               return (EINVAL);
-
-       val = pci_read_config(dev, cap_offset + PCIR_MSIX_TABLE, 4);
-       *table_bar = PCIR_BAR(val & PCIM_MSIX_BIR_MASK);
-
-       val = pci_read_config(dev, cap_offset + PCIR_MSIX_PBA, 4);
-       *pba_bar = PCIR_BAR(val & PCIM_MSIX_BIR_MASK);
-
-       return (0);
-}
-
 static int
 ahci_pci_attach(device_t dev)
 {
@@ -496,7 +474,6 @@ ahci_pci_attach(device_t dev)
        uint32_t devid = pci_get_devid(dev);
        uint8_t revid = pci_get_revid(dev);
        int msi_count, msix_count;
-       uint8_t table_bar = 0, pba_bar = 0;
        uint32_t caps, pi;
 
        msi_count = pci_msi_count(dev);
@@ -584,20 +561,11 @@ ahci_pci_attach(device_t dev)
        if (ctlr->quirks & AHCI_Q_NOMSIX)
                msix_count = 0;
 
-       /* Read MSI-x BAR IDs if supported */
-       if (msix_count > 0) {
-               error = ahci_pci_read_msix_bars(dev, &table_bar, &pba_bar);
-               if (error == 0) {
-                       ctlr->r_msix_tab_rid = table_bar;
-                       ctlr->r_msix_pba_rid = pba_bar;
-               } else {
-                       /* Failed to read BARs, disable MSI-x */
-                       msix_count = 0;
-               }
-       }
-
        /* Allocate resources for MSI-x table and PBA */
        if (msix_count > 0) {
+               ctlr->r_msix_tab_rid = pci_msix_table_bar(dev);
+               ctlr->r_msix_pba_rid = pci_msix_pba_bar(dev);
+
                /*
                 * Allocate new MSI-x table only if not
                 * allocated before.

Reply via email to