From 2537751fa7352577f6c7b48de59c0a1f553bec4e Mon Sep 17 00:00:00 2001 From: Maxim Poliakovski Date: Thu, 8 Dec 2022 08:04:09 +0100 Subject: [PATCH] Clean up ATA interface. --- devices/common/ata/atabasedevice.cpp | 12 ++++++------ devices/common/ata/atadefs.h | 12 ++++++++---- devices/common/ata/idechannel.cpp | 2 ++ 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/devices/common/ata/atabasedevice.cpp b/devices/common/ata/atabasedevice.cpp index 8180949..e096db6 100644 --- a/devices/common/ata/atabasedevice.cpp +++ b/devices/common/ata/atabasedevice.cpp @@ -28,9 +28,7 @@ along with this program. If not, see . #include -#define sector_size 512 - -using namespace std; +using namespace ata_interface; AtaBaseDevice::AtaBaseDevice(const std::string name) { @@ -46,16 +44,18 @@ void AtaBaseDevice::device_reset() this->r_sect_count = 1; this->r_sect_num = 1; + this->r_dev_ctrl = 0; // set ATA protocol signature this->r_cylinder_lo = 0; this->r_cylinder_hi = 0; + this->r_dev_head = 0; // TODO: ATAPI devices shouldn't change this reg! this->r_status = IDE_Status::DRDY | IDE_Status::DSC; } uint16_t AtaBaseDevice::read(const uint8_t reg_addr) { switch (reg_addr) { - case IDE_Reg::IDE_DATA: + case IDE_Reg::DATA: LOG_F(WARNING, "Retrieving data from %s", this->name.c_str()); return 0xFFFFU; case IDE_Reg::ERROR: @@ -83,7 +83,7 @@ uint16_t AtaBaseDevice::read(const uint8_t reg_addr) { void AtaBaseDevice::write(const uint8_t reg_addr, const uint16_t value) { switch (reg_addr) { - case IDE_Reg::IDE_DATA: + case IDE_Reg::DATA: LOG_F(WARNING, "Pushing data to %s", this->name.c_str()); break; case IDE_Reg::FEATURES: @@ -106,7 +106,7 @@ void AtaBaseDevice::write(const uint8_t reg_addr, const uint16_t value) { break; case IDE_Reg::COMMAND: this->r_command = value; - if (is_selected()) { + if (is_selected() || this->r_command == IDE_Cmd::DIAGNOSTICS) { perform_command(); } break; diff --git a/devices/common/ata/atadefs.h b/devices/common/ata/atadefs.h index c452652..2529fd8 100644 --- a/devices/common/ata/atadefs.h +++ b/devices/common/ata/atadefs.h @@ -26,9 +26,11 @@ along with this program. If not, see . #include -/** IDE register offsets. */ +namespace ata_interface { + +/** ATA register offsets. */ enum IDE_Reg : int { - IDE_DATA = 0x0, + DATA = 0x0, ERROR = 0x1, // error (read) FEATURES = 0x1, // features (write) SEC_COUNT = 0x2, // sector count @@ -67,9 +69,9 @@ enum IDE_Error : int { BBK = 0x80 }; -/** Heath IDE commands. */ +/** ATA commands. */ enum IDE_Cmd : int { - IDE_NOP = 0x00, + NOP = 0x00, RESET_ATAPI = 0x08, RECALIBRATE = 0x10, READ_SECTOR = 0x20, @@ -83,6 +85,8 @@ enum IDE_Cmd : int { WRITE_DMA = 0xCA, }; +}; // namespace ata_interface + /** Interface for ATA devices. */ class AtaInterface { public: diff --git a/devices/common/ata/idechannel.cpp b/devices/common/ata/idechannel.cpp index 8a554ea..9743568 100644 --- a/devices/common/ata/idechannel.cpp +++ b/devices/common/ata/idechannel.cpp @@ -35,6 +35,8 @@ along with this program. If not, see . #include #include +using namespace ata_interface; + IdeChannel::IdeChannel(const std::string name) { this->set_name(name);