diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2025-01-04 22:34:34 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2025-01-04 22:35:29 +0100 |
| commit | 188550e4f26c77e33dcc2a83c4775d17e47dcb39 (patch) | |
| tree | 7d46b2f9424943d543f1028881602ee6713ce8b1 /dev/Kernel/HALKit | |
| parent | ede8280f2ad6cbb9152d4d55164912c32dfbeb97 (diff) | |
META: Day end bump.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/Kernel/HALKit')
| -rw-r--r-- | dev/Kernel/HALKit/AMD64/Storage/ATA-PIO.cc | 2 | ||||
| -rw-r--r-- | dev/Kernel/HALKit/AMD64/Storage/SATA-DMA.cc | 67 |
2 files changed, 27 insertions, 42 deletions
diff --git a/dev/Kernel/HALKit/AMD64/Storage/ATA-PIO.cc b/dev/Kernel/HALKit/AMD64/Storage/ATA-PIO.cc index b9da351a..ea8840eb 100644 --- a/dev/Kernel/HALKit/AMD64/Storage/ATA-PIO.cc +++ b/dev/Kernel/HALKit/AMD64/Storage/ATA-PIO.cc @@ -121,7 +121,7 @@ Void drv_std_read(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT SectorSz 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); diff --git a/dev/Kernel/HALKit/AMD64/Storage/SATA-DMA.cc b/dev/Kernel/HALKit/AMD64/Storage/SATA-DMA.cc index a3c1474d..5d3acd16 100644 --- a/dev/Kernel/HALKit/AMD64/Storage/SATA-DMA.cc +++ b/dev/Kernel/HALKit/AMD64/Storage/SATA-DMA.cc @@ -15,6 +15,7 @@ * */ +#include "NewKit/Defines.h" #include <KernelKit/UserProcessScheduler.h> #include <KernelKit/LPC.h> @@ -166,65 +167,53 @@ Kernel::Boolean drv_std_detected(Kernel::Void) Kernel::Void drv_std_write(Kernel::UInt64 lba, Kernel::Char* buffer, Kernel::SizeT sector_cnt, Kernel::SizeT size_buffer) { + lba /= sector_cnt; + drv_std_input_output<YES, YES, NO>(lba, (Kernel::UInt8*)buffer, sector_cnt, size_buffer); } Kernel::Void drv_std_read(Kernel::UInt64 lba, Kernel::Char* buffer, Kernel::SizeT sector_cnt, Kernel::SizeT size_buffer) { + lba /= sector_cnt; + drv_std_input_output<NO, YES, NO>(lba, (Kernel::UInt8*)buffer, sector_cnt, size_buffer); } template <BOOL Write, BOOL CommandOrCTRL, BOOL Identify> static Kernel::Void drv_std_input_output(Kernel::UInt64 lba, Kernel::UInt8* buffer, Kernel::SizeT sector_cnt, Kernel::SizeT size_buffer) { - Kernel::SizeT port = 0; - Kernel::UInt32 slots = (kAhciPort->Sact | kAhciPort->Ci); - - for (; port < slots; ++port) - { - if ((slots & 1) == 0) - break; - - slots >>= 1; - } + volatile HbaCmdHeader* command_header = *(HbaCmdHeader**)&kAhciPort->Clb; - if (slots == 0) - return; - - Kernel::UInt32* command_list = new Kernel::UInt32[kib_cast(1)]; - Kernel::UInt32* command_table = new Kernel::UInt32[kib_cast(4)]; - - Kernel::rt_set_memory(command_list, 0, kib_cast(1)); - Kernel::rt_set_memory(command_table, 0, kib_cast(4)); + command_header->Cfl = sizeof(FisRegH2D) / sizeof(Kernel::UInt32); - auto command_table_deref = *(Kernel::UInt32*)&command_table; + command_header->Write = Write; + command_header->Prdtl = (Kernel::UInt16)((size_buffer - 1) >> 4) + 1; - command_table[0] = *(Kernel::UInt32*)&buffer; + HbaCmdTbl* command_table = (HbaCmdTbl*)(command_header->Ctba); - command_list[0] = command_table_deref; - command_list[1] = size_buffer; + command_table->PrdtEntries[0].Dba = *(Kernel::UInt32*)&buffer; + command_table->PrdtEntries[0].Dbc = size_buffer; + command_table->PrdtEntries[0].InterruptBit = 1; - volatile Kernel::UInt32* command_header = (Kernel::UInt32*)kAhciPort + 0x10; + FisRegH2D* h2d_fis = (FisRegH2D*)(&command_table->Cfis); - auto command_list_deref = *(Kernel::UInt32*)&command_list; + h2d_fis->Command = Write ? kAHCICmdWriteDmaEx : kAHCICmdReadDmaEx; + h2d_fis->FisType = kFISTypeRegH2D; + h2d_fis->CmdOrCtrl = CommandOrCTRL; - command_header[0] = 5 | 0 | (Write ? kAHCICmdWriteDma : kAHCICmdReadDma) | 0 | 00000000 | 1 | 00000000000; - command_header[0] = command_header[0] | (lba & __UINT32_MAX__); - - command_header[1] = command_list_deref; + h2d_fis->Lba0 = lba & 0xFF; + h2d_fis->Lba1 = lba >> 8; + h2d_fis->Lba2 = lba >> 16; - Kernel::UInt32* fis = command_list; + h2d_fis->Device = 1 << 6; - fis[0] = kFISTypeRegH2D; - fis[1] = CommandOrCTRL; + h2d_fis->Lba3 = lba >> 24; + h2d_fis->Lba4 = lba >> 32; + h2d_fis->Lba5 = lba >> 40; - fis[2] = Identify ? kAHCICmdIdentify : kAHCICmdReadDmaEx; + h2d_fis->CountLow = sector_cnt & 0xFF; + h2d_fis->CountHigh = (sector_cnt >> 8) & 0xFF; - if (Write) - fis[2] = kAHCICmdWriteDmaEx; - - // 5. Issue the command - // Write command issue bit kAhciPort->Ci |= (1 << 0); // Command Issue while (kAhciPort->Ci & (1 << 0)) @@ -251,10 +240,6 @@ static Kernel::Void drv_std_input_output(Kernel::UInt64 lba, Kernel::UInt8* buff return; } - - delete[] command_table; - - command_table = nullptr; } /*** |
