}
port->drive.type = DTYPE_AHCI;
+ port->drive.cntl_id = pnr;
port->drive.removable = (buffer[0] & 0x80) ? 1 : 0;
- port->drive.desc = malloc_tmp(MAXDESCSIZE);
- if (!port->drive.desc) {
- warn_noalloc();
- return NULL;
- }
if (!port->atapi) {
// found disk (ata)
adjsize >>= 10;
adjprefix = 'G';
}
- snprintf(port->drive.desc, MAXDESCSIZE
- , "AHCI/%d: %s ATA-%d Hard-Disk (%u %ciBytes)"
- , port->pnr
- , ata_extract_model(model, MAXMODEL, buffer)
- , ata_extract_version(buffer)
- , (u32)adjsize, adjprefix);
-
- // Setup disk geometry translation.
- setup_translation(&port->drive);
+ char *desc = znprintf(MAXDESCSIZE
+ , "AHCI/%d: %s ATA-%d Hard-Disk (%u %ciBytes)"
+ , port->pnr
+ , ata_extract_model(model, MAXMODEL, buffer)
+ , ata_extract_version(buffer)
+ , (u32)adjsize, adjprefix);
+ dprintf(1, "%s\n", desc);
+
// Register with bcv system.
- add_bcv_internal(&port->drive);
+ boot_add_hd(&port->drive, desc, -1);
} else {
// found cdrom (atapi)
port->drive.blksize = CDROM_SECTOR_SIZE;
port->drive.sectors = (u64)-1;
u8 iscd = ((buffer[0] >> 8) & 0x1f) == 0x05;
- snprintf(port->drive.desc, MAXDESCSIZE, "AHCI/%d: %s ATAPI-%d %s"
- , port->pnr
- , ata_extract_model(model, MAXMODEL, buffer)
- , ata_extract_version(buffer)
- , (iscd ? "DVD/CD" : "Device"));
+ char *desc = znprintf(MAXDESCSIZE
+ , "DVD/CD [AHCI/%d: %s ATAPI-%d %s]"
+ , port->pnr
+ , ata_extract_model(model, MAXMODEL, buffer)
+ , ata_extract_version(buffer)
+ , (iscd ? "DVD/CD" : "Device"));
+ dprintf(1, "%s\n", desc);
// fill cdidmap
if (iscd)
- map_cd_drive(&port->drive);
+ boot_add_cd(&port->drive, desc, -1);
}
- dprintf(1, "%s\n", port->drive.desc);
return port;
ahci_init(void)
{
// Scan PCI bus for ATA adapters
- int bdf, max;
- foreachpci(bdf, max) {
- if (pci_config_readw(bdf, PCI_CLASS_DEVICE) != PCI_CLASS_STORAGE_SATA)
+ struct pci_device *pci;
+ foreachpci(pci) {
+ if (pci->class != PCI_CLASS_STORAGE_SATA)
continue;
- if (pci_config_readb(bdf, PCI_CLASS_PROG) != 1 /* AHCI rev 1 */)
+ if (pci->prog_if != 1 /* AHCI rev 1 */)
continue;
- ahci_init_controller(bdf);
+ ahci_init_controller(pci->bdf);
}
}