diff options
Diffstat (limited to 'dev/kernel/HALKit')
| -rw-r--r-- | dev/kernel/HALKit/AMD64/HalInterruptAPI.asm | 1 | ||||
| -rw-r--r-- | dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc | 46 |
2 files changed, 29 insertions, 18 deletions
diff --git a/dev/kernel/HALKit/AMD64/HalInterruptAPI.asm b/dev/kernel/HALKit/AMD64/HalInterruptAPI.asm index 77f1d9a1..cc34b99f 100644 --- a/dev/kernel/HALKit/AMD64/HalInterruptAPI.asm +++ b/dev/kernel/HALKit/AMD64/HalInterruptAPI.asm @@ -98,7 +98,6 @@ __NE_INT_3: out 0x20, al push rcx - mov rcx, rsp call idt_handle_generic pop rcx diff --git a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc index 8bb7170d..3336e20e 100644 --- a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc +++ b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc @@ -67,6 +67,22 @@ STATIC Int32 drv_find_cmd_slot_ahci(HbaPort* port) noexcept; STATIC Void drv_compute_disk_ahci() noexcept; +namespace AHCI::Detail +{ + template <typename RetType> + RetType* ahci_align_address(RetType* address, Int32 alignement) + { + if (!address) + return nullptr; + + UIntPtr addr = (UIntPtr)address; + + UIntPtr aligned_addr = (addr + alignement - 1) & ~alignement - 1; + + return (RetType*)aligned_addr; + } +} // namespace AHCI::Detail + STATIC Void drv_compute_disk_ahci() noexcept { kSATASectorCount = 0UL; @@ -75,7 +91,7 @@ STATIC Void drv_compute_disk_ahci() noexcept const UInt16 kSzIdent = 256; /// Push it to the stack - UInt16* identify_data ATTRIBUTE(aligned(4096)) = new UInt16[kSzIdent]; + UInt16* identify_data ATTRIBUTE(aligned(kib_cast(1))) = AHCI::Detail::ahci_align_address<UInt16>(new UInt16[kSzIdent], kib_cast(1)); /// Send AHCI command for identification. drv_std_input_output_ahci<NO, YES, YES>(0, (UInt8*)identify_data, kAHCISectorSize, kSzIdent); @@ -166,7 +182,7 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz for (UInt16 i = 0; i < prdt_count; ++i) { - UInt32 chunk = (bytes_remaining > kMaxPRDSize) ? kMaxPRDSize : bytes_remaining; + UInt32 chunk = bytes_remaining / prdt_count; if (chunk == 0) break; @@ -277,8 +293,8 @@ STATIC BOOL ahci_enable_and_probe() // Relocate Command List Base. - auto const addr = mm_new_heap(kib_cast(64), YES, NO, 0); - auto kAHCIBaseAddress = (UIntPtr)addr; + VoidPtr const kAHCIBasePtr = AHCI::Detail::ahci_align_address<Void>(mm_new_heap(kib_cast(64), YES, NO, 0), kib_cast(1)); + UIntPtr const kAHCIBaseAddress = reinterpret_cast<UIntPtr>(kAHCIBasePtr); port->Clb = kAHCIBaseAddress + (kSATAIndex << 10); port->Clbu = 0; @@ -288,7 +304,7 @@ STATIC BOOL ahci_enable_and_probe() // Relocate Frame Info Structure now. - port->Fb = kAHCIBaseAddress + (kSATAPortCnt << 10) + (kSATAIndex << 10); + port->Fb = (UInt32)(UIntPtr)(UIntPtr*)AHCI::Detail::ahci_align_address<UInt32>((UInt32*)(kAHCIBaseAddress + (kSATAPortCnt << 10) + (kSATAIndex << 10)), kib_cast(1)); port->Fbu = 0; // clean it. @@ -299,18 +315,12 @@ STATIC BOOL ahci_enable_and_probe() for (Int32 i = 0; i < kSATAPortCnt; i++) { cmd_hdr[i].Prdtl = 8; - cmd_hdr[i].Ctba = kAHCIBaseAddress + (40 << 10) + (kSATAPortCnt << 10) + (kSATAIndex << 10); + cmd_hdr[i].Ctba = (UInt32)(UIntPtr)(UIntPtr*)AHCI::Detail::ahci_align_address<UInt32>((UInt32*)(kAHCIBaseAddress + (40 << 10) + (kSATAPortCnt << 10) + (kSATAIndex << 10)), kib_cast(1)); cmd_hdr[i].Ctbau = 0; rt_set_memory(reinterpret_cast<VoidPtr>(cmd_hdr[i].Ctba), 0, 256); } - for (UIntPtr offset = 0; offset < kib_cast(64); offset += kib_cast(1)) - { - VoidPtr addr = reinterpret_cast<VoidPtr>(kAHCIBaseAddress + offset); - HAL::mm_map_page(addr, addr, HAL::kMMFlagsWr); - } - // Now we are ready. kSATAHba->Ports[kSATAIndex].Cmd |= kHBAPxCmdFre; @@ -357,10 +367,10 @@ STATIC Bool drv_std_init_ahci(UInt16& pi, BOOL& atapi) pi = ports_implemented; const UInt16 kSATAMaxPortsImplemented = ports_implemented; - const UInt32 kSATASignature = kSATASig; - const UInt32 kSATAPISignature = kSATAPISig; - const UInt8 kSATAPresent = 0x03; - const UInt8 kSATAIPMActive = 0x01; + const UInt32 kSATASignature = kSATASig; + const UInt32 kSATAPISignature = kSATAPISig; + const UInt8 kSATAPresent = 0x03; + const UInt8 kSATAIPMActive = 0x01; if (kSATAMaxPortsImplemented < 1) continue; @@ -399,6 +409,8 @@ success_hba_fetch: return YES; } + + return NO; } /// @brief Checks if an AHCI device is detected. @@ -411,7 +423,7 @@ Bool drv_std_detected_ahci() // ================================================================================================ // -// This applies only if we compile with AHCI as a default disk driver. +/// @note This applies only if we compile with AHCI as a default disk driver. // // ================================================================================================ |
