From 561ad1494cad32243fa256af8acb755466ef12a7 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Sun, 21 Sep 2025 14:12:27 -0400 Subject: kern: ahci: Scan for implemented ports with PI reg Signed-off-by: Ian Moffett --- src/sys/io/ic/ahci.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'src/sys/io/ic/ahci.c') diff --git a/src/sys/io/ic/ahci.c b/src/sys/io/ic/ahci.c index 825306d..9f96a00 100644 --- a/src/sys/io/ic/ahci.c +++ b/src/sys/io/ic/ahci.c @@ -143,6 +143,27 @@ ahci_hba_reset(struct ahci_hba *hba) return 0; } +/* + * Initialize the ports of an HBA + */ +static int +ahci_init_ports(struct ahci_hba *hba) +{ + volatile struct hba_memspace *io = hba->io; + uint32_t pi, nbits; + + pi = hba->pi; + for (int i = 0; i < hba->nport; ++i) { + if (!ISSET(pi, BIT(i))) { + continue; + } + + dtrace("port %d implemented\n", i); + } + + return 0; +} + /* * Put the HBA as well as its devices in an initialized * state so that they may be used for operation. @@ -151,9 +172,14 @@ static int ahci_hba_init(struct ahci_hba *hba) { volatile struct hba_memspace *io = hba->io; - uint32_t ghc; + uint32_t ghc, cap; int error; + /* Yoink from firmware before reset */ + cap = mmio_read32(&io->cap); + hba->pi = mmio_read32(&io->pi); + hba->nport = AHCI_CAP_NP(cap) + 1; + /* * We cannot be so certain what state the BIOS or whatever * firmware left the host controller in, therefore the HBA @@ -173,7 +199,7 @@ ahci_hba_init(struct ahci_hba *hba) ghc = mmio_read32(&io->ghc); ghc |= AHCI_GHC_AE; mmio_write32(&io->ghc, ghc); - return 0; + return ahci_init_ports(hba); } /* -- cgit v1.2.3