summaryrefslogtreecommitdiffhomepage
path: root/dev/Kernel/HALKit/AMD64/Storage/PIO.cc
diff options
context:
space:
mode:
authorAmlal <amlal.elmahrouss@icloud.com>2025-02-17 08:52:03 +0100
committerAmlal <amlal.elmahrouss@icloud.com>2025-02-17 08:52:03 +0100
commit8abfbf50f6f0cca4184cfb602a68027f99d500ca (patch)
tree61337db2be7ca95c3e5e894fcb478fbf5c7f38c8 /dev/Kernel/HALKit/AMD64/Storage/PIO.cc
parent5e6b090e8caafe81d58b92198579fd006fb7b6a3 (diff)
Storage: Improve PIO and SATA drivers.
Signed-off-by: Amlal <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/Kernel/HALKit/AMD64/Storage/PIO.cc')
-rw-r--r--dev/Kernel/HALKit/AMD64/Storage/PIO.cc50
1 files changed, 20 insertions, 30 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?