1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 06:47:34 +00:00

Kernel/Storage: Rewrite IDE disk detection and disk access

This replaces the current disk detection and disk access code with
code based on https://wiki.osdev.org/IDE

This allows the system to boot on VirtualBox with serial debugging
enabled and VMWare Player.

I believe there were several issues with the current code:
- It didn't utilise the last 8 bits of the LBA in 24-bit mode.
- {read,write}_sectors_with_dma was not setting the obsolete bits,
  which according to OSdev wiki aren't used but should be set.
- The PIO and DMA methods were using slightly different copy
  and pasted access code, which is now put into a single
  function called "ata_access"
- PIO mode doesn't work. This doesn't fix that and should
  be looked into in the future.
- The detection code was not checking for ATA/ATAPI.
- The detection code accidentally had cyls/heads/spt as 8-bit,
  when they're 16-bit.
- The capabilities of the device were not considered. This is now
  brought in and is currently used to check if the device supports
  LBA. If not, use CHS.
This commit is contained in:
Luke 2021-01-29 19:37:40 +00:00 committed by Andreas Kling
parent f9b1a9e60c
commit 40de84ba67
4 changed files with 240 additions and 172 deletions

View file

@ -117,21 +117,37 @@ private:
//^ IRQHandler
virtual void handle_irq(const RegisterState&) override;
enum class LBAMode : u8 {
None, // CHS
TwentyEightBit,
FortyEightBit,
};
enum class Direction : u8 {
Read,
Write,
};
void initialize(bool force_pio);
void detect_disks();
String channel_type_string() const;
void start_request(AsyncBlockDeviceRequest&, bool, bool);
void try_disambiguate_error();
void wait_until_not_busy();
void start_request(AsyncBlockDeviceRequest&, bool, bool, u16);
void complete_current_request(AsyncDeviceRequest::RequestResult);
void ata_read_sectors_with_dma(bool);
void ata_read_sectors(bool);
void ata_access(Direction, bool, u32, u8, u16, bool);
void ata_read_sectors_with_dma(bool, u16);
void ata_read_sectors(bool, u16);
bool ata_do_read_sector();
void ata_write_sectors_with_dma(bool);
void ata_write_sectors(bool);
void ata_write_sectors_with_dma(bool, u16);
void ata_write_sectors(bool, u16);
void ata_do_write_sector();
// Data members
u8 m_channel_number { 0 }; // Channel number. 0 = master, 1 = slave
ChannelType m_channel_type { ChannelType::Primary };
volatile u8 m_device_error { 0 };