diff options
| author | Amlal <amlal.elmahrouss@icloud.com> | 2025-02-17 08:52:03 +0100 |
|---|---|---|
| committer | Amlal <amlal.elmahrouss@icloud.com> | 2025-02-17 08:52:03 +0100 |
| commit | 8abfbf50f6f0cca4184cfb602a68027f99d500ca (patch) | |
| tree | 61337db2be7ca95c3e5e894fcb478fbf5c7f38c8 /dev/Kernel/HALKit/AMD64 | |
| parent | 5e6b090e8caafe81d58b92198579fd006fb7b6a3 (diff) | |
Storage: Improve PIO and SATA drivers.
Signed-off-by: Amlal <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/Kernel/HALKit/AMD64')
| -rw-r--r-- | dev/Kernel/HALKit/AMD64/Storage/PIO.cc | 50 | ||||
| -rw-r--r-- | dev/Kernel/HALKit/AMD64/Storage/SATA.cc | 8 |
2 files changed, 24 insertions, 34 deletions
diff --git a/dev/Kernel/HALKit/AMD64/Storage/PIO.cc b/dev/Kernel/HALKit/AMD64/Storage/PIO.cc index 73a2690d..4965b932 100644 --- a/dev/Kernel/HALKit/AMD64/Storage/PIO.cc +++ b/dev/Kernel/HALKit/AMD64/Storage/PIO.cc @@ -25,7 +25,7 @@ using namespace Kernel::HAL; /// bugs: 0 -#define kATADataLen 256 +#define kATADataLen 512 STATIC Boolean kATADetected = false; STATIC Int32 kATADeviceType = kATADeviceCount; @@ -38,18 +38,18 @@ Boolean drv_std_wait_io(UInt16 IO) rt_in8(IO + ATA_REG_STATUS); ATAWaitForIO_Retry: - auto statRdy = rt_in8(IO + ATA_REG_STATUS); + auto stat_rdy = rt_in8(IO + ATA_REG_STATUS); - if ((statRdy & ATA_SR_BSY)) + if ((stat_rdy & ATA_SR_BSY)) goto ATAWaitForIO_Retry; ATAWaitForIO_Retry2: - statRdy = rt_in8(IO + ATA_REG_STATUS); + stat_rdy = rt_in8(IO + ATA_REG_STATUS); - if (statRdy & ATA_SR_ERR) + if (stat_rdy & ATA_SR_ERR) return false; - if (!(statRdy & ATA_SR_DRDY)) + if (!(stat_rdy & ATA_SR_DRDY)) goto ATAWaitForIO_Retry2; return true; @@ -74,43 +74,41 @@ Boolean drv_std_init(UInt16 Bus, UInt8 Drive, UInt16& OutBus, UInt8& OutMaster) // identify until it's good. ATAInit_Retry: - auto statRdy = rt_in8(IO + ATA_REG_STATUS); + auto stat_rdy = rt_in8(IO + ATA_REG_STATUS); - if (statRdy & ATA_SR_ERR) + if (stat_rdy & ATA_SR_ERR) { return false; } - if ((statRdy & ATA_SR_BSY)) + if ((stat_rdy & ATA_SR_BSY)) goto ATAInit_Retry; - rt_out8(IO + ATA_REG_COMMAND, ATA_CMD_IDENTIFY); + OutBus = (Bus == ATA_PRIMARY_IO) ? ATA_PRIMARY_IO : ATA_SECONDARY_IO; + OutMaster = (Bus == ATA_PRIMARY_IO) ? ATA_MASTER : ATA_SLAVE; - /// fetch serial info - /// model, speed, number of sectors... + rt_out8(OutBus + ATA_REG_COMMAND, ATA_CMD_IDENTIFY); drv_std_wait_io(IO); + + /// fetch serial info + /// model, speed, number of sectors... for (SizeT i = 0ul; i < kATADataLen; ++i) { - drv_std_wait_io(IO); - kATAData[i] = Kernel::HAL::rt_in16(IO + ATA_REG_DATA); - drv_std_wait_io(IO); + kATAData[i] = Kernel::HAL::rt_in16(OutBus + ATA_REG_DATA); } - - for (SizeT i = 0; i < 40; i += 2) + + for (Kernel::Int32 i = 0; i < 20; i++) { - kCurrentDiskModel[i] = kATAData[54 + i] >> 8; - kCurrentDiskModel[i + 1] = kATAData[54 + i] & 0xFF; + kCurrentDiskModel[i * 2] = kATAData[27 + i] >> 8; + kCurrentDiskModel[i * 2 + 1] = kATAData[27 + i + 1] & 0xFF; } kCurrentDiskModel[40] = '\0'; kout << "Drive Model: " << kCurrentDiskModel << endl; - OutBus = (Bus == ATA_PRIMARY_IO) ? ATA_PRIMARY_IO : ATA_SECONDARY_IO; - OutMaster = (Bus == ATA_PRIMARY_IO) ? ATA_MASTER : ATA_SLAVE; - return true; } @@ -134,13 +132,10 @@ Void drv_std_read(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT SectorSz rt_out8(IO + ATA_REG_COMMAND, ATA_CMD_READ_PIO); - drv_std_wait_io(IO); - for (SizeT IndexOff = 0; IndexOff < Size; ++IndexOff) { drv_std_wait_io(IO); Buf[IndexOff] = Kernel::HAL::rt_in16(IO + ATA_REG_DATA); - drv_std_wait_io(IO); } } @@ -164,16 +159,11 @@ Void drv_std_write(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT SectorS rt_out8(IO + ATA_REG_COMMAND, ATA_CMD_WRITE_PIO); - drv_std_wait_io(IO); - for (SizeT IndexOff = 0; IndexOff < Size; ++IndexOff) { drv_std_wait_io(IO); rt_out16(IO + ATA_REG_DATA, Buf[IndexOff]); - drv_std_wait_io(IO); } - - drv_std_wait_io(IO); } /// @brief is ATA detected? diff --git a/dev/Kernel/HALKit/AMD64/Storage/SATA.cc b/dev/Kernel/HALKit/AMD64/Storage/SATA.cc index 70fd5cb4..f0d99d31 100644 --- a/dev/Kernel/HALKit/AMD64/Storage/SATA.cc +++ b/dev/Kernel/HALKit/AMD64/Storage/SATA.cc @@ -65,14 +65,14 @@ static Kernel::Void drvi_calculate_disk_geometry() noexcept Kernel::UInt8* identify_data = new Kernel::UInt8[512]; - drvi_std_input_output<NO, YES, YES>(0, identify_data, 0, 512); + drvi_std_input_output<NO, NO, YES>(0, identify_data, 0, 512); kCurrentDiskSectorCount = (identify_data[61] << 16) | identify_data[60]; for (Kernel::Int32 i = 0; i < 20; i++) { kCurrentDiskModel[i * 2] = identify_data[27 + i] >> 8; - kCurrentDiskModel[i * 2 + 1] = identify_data[27 + i] & 0xFF; + kCurrentDiskModel[i * 2 + 1] = identify_data[27 + i + 1] & 0xFF; } kCurrentDiskModel[40] = '\0'; @@ -208,7 +208,7 @@ static Kernel::Void drvi_std_input_output(Kernel::UInt64 lba, Kernel::UInt8* buf command_table->Prdt[0].Dbau = (((Kernel::UInt64)phys_dma_buf >> 32)); command_table->Prdt[0].Dba = ((Kernel::UInt32)(Kernel::UInt64)phys_dma_buf); command_table->Prdt[0].Dbc = ((size_buffer)-1); - command_table->Prdt[0].Ie = 0; + command_table->Prdt[0].Ie = 1; FisRegH2D* h2d_fis = (FisRegH2D*)((Kernel::UInt64)&command_table->Cfis); @@ -236,7 +236,7 @@ static Kernel::Void drvi_std_input_output(Kernel::UInt64 lba, Kernel::UInt8* buf if (kSATA->Is & kHBAErrTaskFile) Kernel::ke_panic(RUNTIME_CHECK_BAD_BEHAVIOR, "AHCI Read disk failure, faulty component."); - kSATA->Ports[kSATAPortIdx].Ie = 0; + kSATA->Ports[kSATAPortIdx].Ie = 1; kSATA->Ports[kSATAPortIdx].Cmd = kHBAPxCmdFR | kHBAPxCmdST; kSATA->Ports[kSATAPortIdx].Ci = (1 << slot); |
