From 0973627785f3b2387bb5c4bb13c634b74348e1b1 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Fri, 9 May 2025 22:45:06 -0400 Subject: kernel: ahci: Add command list helpers Signed-off-by: Ian Moffett --- sys/dev/ic/ahci.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'sys/dev') diff --git a/sys/dev/ic/ahci.c b/sys/dev/ic/ahci.c index 3142193..3078ec3 100644 --- a/sys/dev/ic/ahci.c +++ b/sys/dev/ic/ahci.c @@ -87,6 +87,42 @@ ahci_poll_reg(volatile uint32_t *reg, uint32_t bits, bool pollset) return 0; } +/* + * Allocate a command slot for a port on + * the HBA. + */ +static int +ahci_alloc_cmdslot(struct ahci_hba *hba, struct hba_port *port) +{ + uint32_t slotlist; + + slotlist = port->ci | port->sact; + slotlist = mmio_read32(&port->ci); + slotlist |= mmio_read32(&port->sact); + + for (int i = 0; i < hba->nslots; ++i) { + if (!ISSET(slotlist, i)) { + return i; + } + } + + return -EAGAIN; +} + +/* + * Get the command list base. + */ +static paddr_t +ahci_cmdbase(struct hba_port *port) +{ + paddr_t basel, baseh, base; + + basel = mmio_read32(&port->clb); + baseh = mmio_read32(&port->clbu); + base = COMBINE32(baseh, basel); + return base; +} + static int ahci_hba_reset(struct ahci_hba *hba) { -- cgit v1.2.3