summaryrefslogtreecommitdiffhomepage
path: root/dev/kernel/HALKit/AMD64/Storage
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-08-16 19:56:21 +0200
committerGitHub <noreply@github.com>2025-08-16 19:56:21 +0200
commit1a32b9307357ac0fc9095e853b2b6d94f9fe62bb (patch)
treef41f723659c8926e38182fbe062746d821ab487e /dev/kernel/HALKit/AMD64/Storage
parenteb9df5eea339812513c25a8d3b2eeb03c633e7ac (diff)
parentb301047903b79560dce69085fc271a653a1eb4b6 (diff)
Merge pull request #55 from nekernel-org/dev
v0.0.4
Diffstat (limited to 'dev/kernel/HALKit/AMD64/Storage')
-rw-r--r--dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc23
-rw-r--r--dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc10
-rw-r--r--dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc13
3 files changed, 21 insertions, 25 deletions
diff --git a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc
index cd41480a..3363e809 100644
--- a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc
+++ b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc
@@ -136,7 +136,7 @@ template <BOOL Write, BOOL CommandOrCTRL, BOOL Identify>
STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz,
SizeT size_buffer) noexcept {
if (sector_sz == 0) {
- kout << "Invalid sector size.\r";
+ kout << "ahci: Invalid sector size.\r";
err_global_get() = kErrorDisk;
return;
}
@@ -144,7 +144,7 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz
lba /= sector_sz;
if (!buffer || size_buffer == 0) {
- kout << "Invalid buffer for AHCI I/O.\r";
+ kout << "ahci: Invalid buffer for AHCI I/O.\r";
err_global_get() = kErrorDisk;
return;
}
@@ -157,7 +157,7 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz
while (slot == ~0UL) {
if (timeout > kTimeout) {
- kout << "No free command slot found, AHCI disk is busy!\r";
+ kout << "ahci: No free command slot found, AHCI disk is busy!\r";
err_global_get() = kErrorDisk;
return;
@@ -217,7 +217,7 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz
command_table->Prdt[prdt_index - 1].Ie = YES;
if (bytes_remaining > 0) {
- kout << "Warning: AHCI PRDT overflow, cannot map full buffer.\r";
+ kout << "ahci: AHCI PRDT overflow, cannot map full buffer.\r";
err_global_get() = kErrorDisk;
rtl_dma_free(size_buffer);
@@ -262,7 +262,7 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz
while (YES) {
if (timeout > kTimeout) {
- kout << "Disk hangup!\r";
+ kout << "ahci: disk-hangup, corrupted-disk.\r";
err_global_get() = kErrorDiskIsCorrupted;
rtl_dma_free(size_buffer);
@@ -277,7 +277,7 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz
rtl_dma_flush(ptr, size_buffer);
if (kSATAHba->Is & kSATAErrTaskFile) {
- kout << "AHCI Task File Error during I/O.\r";
+ kout << "ahci: Task File Error during I/O.\r";
rtl_dma_free(size_buffer);
err_global_get() = kErrorDiskIsCorrupted;
@@ -293,9 +293,8 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz
if ((kSATAHba->Ports[kSATAIndex].Tfd & (kSATASRBsy | kSATASRDrq)) == 0) {
goto ahci_io_end;
} else {
- kout << "Warning: Disk still busy after command completion!\r";
- while (kSATAHba->Ports[kSATAIndex].Tfd & (kSATASRBsy | kSATASRDrq))
- ;
+ kout << "ahci: Disk still busy after command completion!\r";
+ while (kSATAHba->Ports[kSATAIndex].Tfd & (kSATASRBsy | kSATASRDrq));
}
ahci_io_end:
@@ -308,13 +307,15 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz
@brief Gets the number of sectors inside the drive.
@return Sector size in bytes.
*/
-STATIC ATTRIBUTE(unused) SizeT drv_get_sector_count_ahci() {
+STATIC ATTRIBUTE(unused)
+SizeT drv_get_sector_count_ahci() {
return kSATASectorCount;
}
/// @brief Get the drive size.
/// @return Disk size in bytes.
-STATIC ATTRIBUTE(unused) SizeT drv_get_size_ahci() {
+STATIC ATTRIBUTE(unused)
+SizeT drv_get_size_ahci() {
return drv_std_get_sector_count() * kAHCISectorSize;
}
diff --git a/dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc
index 39efb7d3..4688203f 100644
--- a/dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc
+++ b/dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc
@@ -105,7 +105,7 @@ Void drv_std_read(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT SectorSz
rt_out8(IO + ATA_REG_SEC_COUNT0, ((Size + SectorSz - 1) / SectorSz));
- rt_out8(IO + ATA_REG_LBA0, (Lba) &0xFF);
+ rt_out8(IO + ATA_REG_LBA0, (Lba) & 0xFF);
rt_out8(IO + ATA_REG_LBA1, (Lba) >> 8);
rt_out8(IO + ATA_REG_LBA2, (Lba) >> 16);
rt_out8(IO + ATA_REG_LBA3, (Lba) >> 24);
@@ -123,8 +123,7 @@ Void drv_std_read(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT SectorSz
rt_out8(kATADevice.Bar(0x20) + 0x00, 0x09); // Start DMA engine
- while (rt_in8(kATADevice.Bar(0x20) + ATA_REG_STATUS) & 0x01)
- ;
+ while (rt_in8(kATADevice.Bar(0x20) + ATA_REG_STATUS) & 0x01);
rt_out8(kATADevice.Bar(0x20) + 0x00, 0x00); // Stop DMA engine
@@ -147,7 +146,7 @@ Void drv_std_write(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT SectorS
rt_out8(IO + ATA_REG_SEC_COUNT0, ((Size + (SectorSz - 1)) / SectorSz));
- rt_out8(IO + ATA_REG_LBA0, (Lba) &0xFF);
+ rt_out8(IO + ATA_REG_LBA0, (Lba) & 0xFF);
rt_out8(IO + ATA_REG_LBA1, (Lba) >> 8);
rt_out8(IO + ATA_REG_LBA2, (Lba) >> 16);
rt_out8(IO + ATA_REG_LBA3, (Lba) >> 24);
@@ -163,8 +162,7 @@ Void drv_std_write(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT SectorS
rt_out8(IO + 0x00, 0x09); // Start DMA engine
- while (rt_in8(kATADevice.Bar(0x20) + ATA_REG_STATUS) & 0x01)
- ;
+ while (rt_in8(kATADevice.Bar(0x20) + ATA_REG_STATUS) & 0x01);
rt_out8(kATADevice.Bar(0x20) + 0x00, 0x00); // Stop DMA engine
diff --git a/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc
index 6fccbdfa..9c5b3931 100644
--- a/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc
+++ b/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc
@@ -83,8 +83,7 @@ ATAInit_Retry:
rt_out8(OutBus + ATA_REG_COMMAND, ATA_CMD_IDENTIFY);
- while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ))
- ;
+ while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ));
/// fetch serial info
/// model, speed, number of sectors...
@@ -117,15 +116,14 @@ Void drv_pio_std_read(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT Sect
rt_out8(IO + ATA_REG_SEC_COUNT0, ((Size + SectorSz) / SectorSz));
- rt_out8(IO + ATA_REG_LBA0, (Lba) &0xFF);
+ rt_out8(IO + ATA_REG_LBA0, (Lba) & 0xFF);
rt_out8(IO + ATA_REG_LBA1, (Lba) >> 8);
rt_out8(IO + ATA_REG_LBA2, (Lba) >> 16);
rt_out8(IO + ATA_REG_LBA3, (Lba) >> 24);
rt_out8(IO + ATA_REG_COMMAND, ATA_CMD_READ_PIO);
- while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ))
- ;
+ while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ));
for (SizeT IndexOff = 0; IndexOff < Size; IndexOff += 2) {
drv_pio_std_wait_io(IO);
@@ -149,15 +147,14 @@ Void drv_pio_std_write(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT Sec
rt_out8(IO + ATA_REG_SEC_COUNT0, ((Size + SectorSz) / SectorSz));
- rt_out8(IO + ATA_REG_LBA0, (Lba) &0xFF);
+ rt_out8(IO + ATA_REG_LBA0, (Lba) & 0xFF);
rt_out8(IO + ATA_REG_LBA1, (Lba) >> 8);
rt_out8(IO + ATA_REG_LBA2, (Lba) >> 16);
rt_out8(IO + ATA_REG_LBA3, (Lba) >> 24);
rt_out8(IO + ATA_REG_COMMAND, ATA_CMD_WRITE_PIO);
- while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ))
- ;
+ while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ));
for (SizeT IndexOff = 0; IndexOff < Size; IndexOff += 2) {
drv_pio_std_wait_io(IO);