diff options
| author | Amlal <amlal@nekernel.org> | 2025-05-09 20:22:01 +0200 |
|---|---|---|
| committer | Amlal <amlal@nekernel.org> | 2025-05-09 20:23:52 +0200 |
| commit | 1391fa1bdc1cfe864596d3120bda12590131bc62 (patch) | |
| tree | 103f36459712cd3af1af8d603404684ce41718b4 /dev/kernel/HALKit/AMD64 | |
| parent | 902bafa5dc8c3ac5fcbf13a5af73e016e9c64685 (diff) | |
dev(kernel, tooling): better code quality inside the codebase and more checks inside the kernel, and cli.
also:
- make use _NeMain for the mk_fwrk tool.
Signed-off-by: Amlal <amlal@nekernel.org>
Diffstat (limited to 'dev/kernel/HALKit/AMD64')
| -rw-r--r-- | dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc index 2b7aec14..ad4f9eeb 100644 --- a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc +++ b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc @@ -160,10 +160,12 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz UInt16 timeout = 0; + constexpr static UInt16 kTimeout = 0x7000; + while (slot == ~0UL) { kout << "No free command slot found, AHCI disk is busy!\r"; - if (timeout > 0x1000) { + if (timeout > kTimeout) { err_global_get() = kErrorDisk; return; } @@ -183,6 +185,8 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz volatile HbaCmdTbl* command_table = (volatile HbaCmdTbl*) (((UInt64) command_header->Ctbau << 32) | command_header->Ctba); + MUST_PASS(command_table); + rt_set_memory((VoidPtr) command_table, 0, sizeof(HbaCmdTbl)); VoidPtr ptr = rtl_dma_alloc(size_buffer, kib_cast(4)); @@ -195,7 +199,7 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz rtl_dma_flush(ptr, size_buffer); - // Build the PRDT + // Build the PRD table. SizeT bytes_remaining = size_buffer; SizeT prdt_index = 0; UIntPtr buffer_phys = (UIntPtr) ptr; @@ -216,11 +220,13 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz ++prdt_index; } + // Mark the last PRD entry, for the FIS to process the table. command_table->Prdt[prdt_index - 1].Ie = YES; if (bytes_remaining > 0) { kout << "Warning: AHCI PRDT overflow, cannot map full buffer.\r"; err_global_get() = kErrorDisk; + rtl_dma_free(size_buffer); return; } |
