ahci: enumerate ahci bus

This commit is contained in:
Michael Shaw 2023-05-06 20:48:23 -04:00
commit 970b34de9a
3 changed files with 61 additions and 12 deletions

View file

@ -1,4 +1,5 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#include "stdio.h"
#include <kernel/mem.h>
#include <kernel/irq.h>
@ -11,6 +12,46 @@ static void ahci_irq_handler()
{
}
static int ahci_port_type(hbaport_t *port)
{
uint32_t ssts = port->ssts;
uint8_t det = ssts & 0x0F;
if (det != HBA_PORT_DET_PRESENT)
return AHCI_DEV_NULL;
switch (port->sig) {
case SATA_SIG_ATAPI:
return AHCI_DEV_SATAPI;
case SATA_SIG_SEMB:
return AHCI_DEV_SEMB;
case SATA_SIG_PM:
return AHCI_DEV_PM;
default:
return AHCI_DEV_SATA;
}
}
static void ahci_probe_ports(hbamem_t *abar)
{
uint32_t pi = abar->pi;
for (int i = 0; i < 32; i++) {
if (pi & 1) {
uint32_t type = ahci_port_type(&abar->ports[i]);
if (type == AHCI_DEV_SATA) {
printf(LOG_INFO "SATA drive found at port %d\n", i);
} else if (type == AHCI_DEV_SATAPI) {
printf(LOG_INFO "SATAPI drive found at port %d\n", i);
} else if (type == AHCI_DEV_SEMB) {
printf(LOG_INFO "SEMB drive found at port %d\n", i);
} else if (type == AHCI_DEV_PM) {
printf(LOG_INFO "PM drive found at port %d\n", i);
}
}
pi >>= 1;
}
}
void ahci_init()
{
struct pci_device *dev = pci_find_device(0x01, 0x06);
@ -26,6 +67,8 @@ void ahci_init()
return;
}
ahci_probe_ports(abar);
/* setup device irq number */
uint16_t irq = irq_highest_free();
uint32_t tmp = pci_config_read_long(dev->bus, dev->slot, 0, 0x3C);

View file

@ -56,7 +56,6 @@ static void pci_scan_bus(uint8_t bus)
pci_devices[pci_device_count].subclass = subclass;
pci_devices[pci_device_count].bar0 = pci_config_read_long(bus, slot, 0, 0x10);
pci_devices[pci_device_count].bar1 = pci_config_read_long(bus, slot, 0, 0x14);
uint8_t header_type = (pci_config_read_long(bus, slot, 0, 0xC) >> 24) & 0xFF;
@ -64,11 +63,8 @@ static void pci_scan_bus(uint8_t bus)
if (header_type == 0) {
pci_devices[pci_device_count].bar2 = pci_config_read_long(bus, slot, 0, 0x18);
pci_devices[pci_device_count].bar3 = pci_config_read_long(bus, slot, 0, 0x1C);
pci_devices[pci_device_count].bar4 = pci_config_read_long(bus, slot, 0, 0x20);
pci_devices[pci_device_count].bar5 = pci_config_read_long(bus, slot, 0, 0x24);
}