Kernel: Add floating bus detection for ATA Bus

This commit is contained in:
Bananymous 2024-04-22 13:45:35 +03:00
parent 47dafe62b8
commit 195c5e92a4
1 changed files with 5 additions and 13 deletions

View File

@ -19,6 +19,11 @@ namespace Kernel
if (bus_ptr == nullptr) if (bus_ptr == nullptr)
return BAN::Error::from_errno(ENOMEM); return BAN::Error::from_errno(ENOMEM);
auto bus = BAN::RefPtr<ATABus>::adopt(bus_ptr); auto bus = BAN::RefPtr<ATABus>::adopt(bus_ptr);
if (bus->io_read(ATA_PORT_STATUS) == 0x00)
{
dprintln("Floating ATA bus on IO port 0x{H}", base);
return BAN::Error::from_errno(ENODEV);
}
bus->set_irq(irq); bus->set_irq(irq);
TRY(bus->initialize()); TRY(bus->initialize());
return bus; return bus;
@ -73,15 +78,6 @@ namespace Kernel
select_delay(); select_delay();
} }
static bool identify_all_same(BAN::Span<const uint16_t> identify_data)
{
uint16_t value = identify_data[0];
for (size_t i = 1; i < 256; i++)
if (identify_data[i] != value)
return false;
return true;
}
BAN::ErrorOr<ATABus::DeviceType> ATABus::identify(bool secondary, BAN::Span<uint16_t> buffer) BAN::ErrorOr<ATABus::DeviceType> ATABus::identify(bool secondary, BAN::Span<uint16_t> buffer)
{ {
// Try to detect whether port contains device // Try to detect whether port contains device
@ -145,10 +141,6 @@ namespace Kernel
ASSERT(buffer.size() >= 256); ASSERT(buffer.size() >= 256);
read_buffer(ATA_PORT_DATA, buffer.data(), 256); read_buffer(ATA_PORT_DATA, buffer.data(), 256);
if (identify_all_same(buffer))
return BAN::Error::from_errno(ENODEV);
return type; return type;
} }