Detect ATA driver via PCI

This commit is contained in:
2025-11-18 23:28:45 +01:00
parent 88f9d0e3d4
commit ecfe1a7eae
8 changed files with 58 additions and 68 deletions

44
kernel/pci/ide.c Normal file
View File

@ -0,0 +1,44 @@
#include <stdint.h>
#include <stddef.h>
#include "pci/pci.h"
#include "pci/ide.h"
#include "storedev/atasd.h"
#include "storedev/storedev.h"
#include "util/util.h"
#include "kprintf.h"
#define ATA_MASTER 0x00
#define ATA_SLAVE 0x01
#define ATA_PROBE(STRING, IOBASE, CTRLBASE, S_OR_M) \
ps = ata_probesize_bytes((IOBASE), (CTRLBASE), (S_OR_M)); \
if (ps > 0) { \
AtaSdInitExtra extra = { \
.devno = (S_OR_M), \
.capacity = ps, \
.iobase = (IOBASE), \
.ctrlbase = (CTRLBASE), \
}; \
storedev_create(STOREDEV_ATASD, (STRING), (void *)&extra); \
}
void pci_ide_init(PciDevInfo *devinfo) {
LOG("pci", "init ATA drive\n");
uint16_t iobase, ctrlbase;
uint64_t ps;
if (!(devinfo->progintf & 0x1)) {
iobase = 0x1F0;
ctrlbase = 0x3F6;
}
ATA_PROBE("atasd0m", iobase, ctrlbase, ATA_MASTER)
ATA_PROBE("atasd0s", iobase, ctrlbase, ATA_SLAVE)
if (!(devinfo->progintf & 0x4)) {
iobase = 0x170;
ctrlbase = 0x376;
}
ATA_PROBE("atasd1m", iobase, ctrlbase, ATA_MASTER)
ATA_PROBE("atasd1s", iobase, ctrlbase, ATA_SLAVE)
}