Minuscule SATA improvements

This commit is contained in:
Thomas Oltmann 2026-05-06 20:36:31 +02:00
parent 23441cc5e5
commit e63c1f1047

View file

@ -368,7 +368,7 @@ static void ahci_irq_handler(unsigned hba_num)
}
if (pctx->dispatched_requests[i]) {
sata_free_request(pctx->dispatched_requests[i]);
}
}
pctx->dispatched_requests[i] = NULL;
}
}
@ -546,7 +546,7 @@ static void sata_init_controller(unsigned hba_num)
hba->max_slots = ((hba->hba_mem->ghc >> 8) & 0x1F) + 1; // GHC.NCS
// This could be done with bit twiddling, but there's some pitfalls and it's just not worth it.
hba->impl_slot_mask = 0;
for (int i = 0; i < hba->max_slots; i++) {
for (unsigned i = 0; i < hba->max_slots; i++) {
hba->impl_slot_mask |= 1 << i;
}
@ -726,31 +726,14 @@ bool sata_dispatch_request(unsigned drive_id, struct sata_request *req)
cmd_hdr->ctba = ctb & 0xffffffff;
cmd_hdr->ctbau = ctb >> 32;
__asm__ volatile ("" ::: "memory");
// Clear pending interrupt bits
port->is = (uint32_t)-1;
int saved_flags = int_enable();
// The below loop waits until the port is no longer busy before issuing a new command
unsigned spin = 0; // Spin lock timeout counter
while ((port->tfd & (ATA_DEV_BUSY | ATA_DEV_DRQ)) && spin < 1000000) {
spin++;
}
if (spin == 1000000) {
printf("AHCI Port %d is hung\n", port_num);
int_restore(saved_flags);
return false;
}
port->ci = 1 << slot; // Issue command
pctx->known_ci |= 1 << slot;
pctx->dispatched_requests[slot] = req;
__asm__ volatile ("" ::: "memory");
return true;
}