From 574d2cf63006cabbf9db4a80c55a407b5b33a700 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Thu, 7 Oct 2021 21:59:22 +0200 Subject: ATA: detect device type --- src/kernel/arch/i386/ata.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'src/kernel') diff --git a/src/kernel/arch/i386/ata.c b/src/kernel/arch/i386/ata.c index e33b5af..4bc4293 100644 --- a/src/kernel/arch/i386/ata.c +++ b/src/kernel/arch/i386/ata.c @@ -5,6 +5,11 @@ #include static struct { + enum { + DEV_UNKNOWN, + DEV_PATA, + DEV_PATAPI, + } type; uint32_t sectors; } ata_drives[4]; @@ -47,11 +52,19 @@ static bool ata_identify(int drive) { if (v == 0) return false; // nonexistent drive while (port_in8(iobase + STATUS) & 0x80); - /* check for uncomformant devices, quit early */ - if (port_in8(iobase + LBAmid) || port_in8(iobase + LBAhi)) { - // TODO atapi - return true; + /* detect device type */ + switch (port_in8(iobase + LBAmid)) { + case 0: + ata_drives[drive].type = DEV_PATA; + break; + case 0x14: + ata_drives[drive].type = DEV_PATAPI; + return true; + default: + ata_drives[drive].type = DEV_UNKNOWN; + return false; } + /* pool until bit 3 (DRQ) or 0 (ERR) is set */ while (!((v = port_in8(iobase + STATUS) & 0x9))); if (v & 1) return false; /* ERR was set, bail */ -- cgit v1.2.3