diff options
| author | Amlal <amlal@nekernel.org> | 2025-04-27 17:30:36 +0200 |
|---|---|---|
| committer | Amlal <amlal@nekernel.org> | 2025-04-27 17:30:36 +0200 |
| commit | cb2f383f45dda8d1cdcef0b87fe4c70243659701 (patch) | |
| tree | f109c3c44fa3f142d34f8ca61cfa69672e556614 /dev/kernel/HALKit | |
| parent | 14d5ee9e0cfededddfceec73d5dfa8a2fcda6c5d (diff) | |
dev, kernel: AHCI, HeFS filesystem, SysChk, and BootSATA improvements.
what?
- AHCI now writes to disk, forgot to do it.
- Codebase's architecutre has been used to reuse the Generic+AHCI driver in SysChk for AHCI. (tradeoff is 256K in size instead of 36K)
- DriveMgr now detects EPM.
- And HeFS is still being worked on.
Signed-off-by: Amlal <amlal@nekernel.org>
Diffstat (limited to 'dev/kernel/HALKit')
| -rw-r--r-- | dev/kernel/HALKit/AMD64/HalDescriptorLoader.cc | 38 | ||||
| -rw-r--r-- | dev/kernel/HALKit/AMD64/HalKernelMain.cc | 4 | ||||
| -rw-r--r-- | dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc | 45 | ||||
| -rw-r--r-- | dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc | 13 |
4 files changed, 59 insertions, 41 deletions
diff --git a/dev/kernel/HALKit/AMD64/HalDescriptorLoader.cc b/dev/kernel/HALKit/AMD64/HalDescriptorLoader.cc index e6d57be2..2fb6ad4c 100644 --- a/dev/kernel/HALKit/AMD64/HalDescriptorLoader.cc +++ b/dev/kernel/HALKit/AMD64/HalDescriptorLoader.cc @@ -15,26 +15,20 @@ namespace Detail { STATIC ::Kernel::Detail::AMD64::InterruptDescriptorAMD64 kInterruptVectorTable[kKernelIdtSize] = {}; -#if 0 - STATIC void hal_set_irq_mask(UInt8 irql) [[maybe_unused]] - { - UInt16 port; - UInt8 value; - - if (irql < 8) - { - port = kPICData; - } - else - { - port = kPIC2Data; - irql -= 8; - } - - value = rt_in8(port) | (1 << irql); - rt_out8(port, value); - } -#endif // make gcc shut up + STATIC ATTRIBUTE(unused) void hal_set_irq_mask(UInt8 irql) [[maybe_unused]] { + UInt16 port; + UInt8 value; + + if (irql < 8) { + port = kPICData; + } else { + port = kPIC2Data; + irql -= 8; + } + + value = rt_in8(port) | (1 << irql); + rt_out8(port, value); + } STATIC void hal_clear_irq_mask(UInt8 irql) [[maybe_unused]] { UInt16 port; @@ -70,7 +64,9 @@ namespace Detail { /// @param gdt /// @return Void GDTLoader::Load(Register64& gdt) { +#ifndef __NE_MODULAR_KERNEL_COMPONENTS__ hal_load_gdt(gdt); +#endif // __NE_MODULAR_KERNEL_COMPONENTS__ } Void IDTLoader::Load(Register64& idt) { @@ -98,7 +94,9 @@ Void IDTLoader::Load(Register64& idt) { Detail::hal_enable_pit(kPITTickForScheduler); +#ifndef __NE_MODULAR_KERNEL_COMPONENTS__ hal_load_idt(idt); +#endif // __NE_MODULAR_KERNEL_COMPONENTS__ rt_sti(); } diff --git a/dev/kernel/HALKit/AMD64/HalKernelMain.cc b/dev/kernel/HALKit/AMD64/HalKernelMain.cc index 8f4b55cb..5a826a9d 100644 --- a/dev/kernel/HALKit/AMD64/HalKernelMain.cc +++ b/dev/kernel/HALKit/AMD64/HalKernelMain.cc @@ -17,6 +17,7 @@ #include <modules/ACPI/ACPIFactoryInterface.h> #include <modules/CoreGfx/TextGfx.h> +#ifndef __NE_MODULAR_KERNEL_COMPONENTS__ EXTERN_C Kernel::VoidPtr kInterruptVectorTable[]; STATIC Kernel::Void hal_pre_init_scheduler() noexcept { @@ -105,7 +106,9 @@ EXTERN_C Int32 hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) { EXTERN_C Kernel::Void hal_real_init(Kernel::Void) noexcept { hal_pre_init_scheduler(); +#if defined(__FSKIT_INCLUDES_HEFS__) Kernel::HeFS::fs_init_hefs(); +#endif Kernel::HAL::mp_init_cores(kHandoverHeader->f_HardwareTables.f_VendorPtr); @@ -141,3 +144,4 @@ EXTERN_C Kernel::Void hal_real_init(Kernel::Void) noexcept { ++team_index; } } +#endif // ifndef __NE_MODULAR_KERNEL_COMPONENTS__
\ No newline at end of file diff --git a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc index fd138513..1591fa56 100644 --- a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc +++ b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc @@ -55,11 +55,11 @@ using namespace Kernel; STATIC PCI::Device kSATADev; STATIC HbaMemRef kSATAHba; -STATIC Lba kSATASectorCount = 0UL; -STATIC UInt16 kSATAIndex = 0U; -STATIC Char kCurrentDiskModel[50] = {"GENERIC SATA"}; -STATIC UInt16 kSATAPortsImplemented = 0U; -STATIC ALIGN(4096) UInt8 kIdentifyData[kAHCISectorSize] = {0}; +STATIC Lba kSATASectorCount = 0UL; +STATIC UInt16 kSATAIndex = 0U; +STATIC Char kCurrentDiskModel[50] = {"GENERIC SATA"}; +STATIC UInt16 kSATAPortsImplemented = 0U; +STATIC ALIGN(kib_cast(4)) UInt8 kIdentifyData[kAHCISectorSize] = {0}; template <BOOL Write, BOOL CommandOrCTRL, BOOL Identify> STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz, @@ -153,6 +153,10 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz VoidPtr ptr = Kernel::rtl_dma_alloc(size_buffer, 4096); + if (Write) { + Kernel::rt_copy_memory(buffer, ptr, size_buffer); + } + // Build the PRDT SizeT bytes_remaining = size_buffer; SizeT prdt_index = 0; @@ -160,8 +164,8 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz while (bytes_remaining > 0 && prdt_index < 8) { SizeT chunk_size = bytes_remaining; - if (chunk_size > 8 * 1024) // AHCI recommends ~8 KiB per PRDT - chunk_size = 8 * 1024; + + if (chunk_size > kib_cast(32)) chunk_size = kib_cast(32); command_table->Prdt[prdt_index].Dba = (UInt32) (buffer_phys & 0xFFFFFFFF); command_table->Prdt[prdt_index].Dbau = (UInt32) (buffer_phys >> 32); @@ -170,12 +174,16 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz buffer_phys += chunk_size; bytes_remaining -= chunk_size; + ++prdt_index; } + 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; + return; } @@ -197,9 +205,10 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz h2d_fis->Lba4 = (lba >> 32) & 0xFF; h2d_fis->Lba5 = (lba >> 40) & 0xFF; + h2d_fis->Device = 0; + if (Identify) { - h2d_fis->Device = 0; // DO NOT set LBAMODE flag - h2d_fis->CountLow = 1; // IDENTIFY always transfers 1 sector + h2d_fis->CountLow = 1; h2d_fis->CountHigh = 0; } else { h2d_fis->Device = kSATALBAMode; @@ -220,12 +229,15 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz if (kSATAHba->Is & kHBAErrTaskFile) { kout << "AHCI Task File Error during I/O.\r"; - + rtl_dma_free(size_buffer); err_global_get() = kErrorDiskIsCorrupted; return; } else { + rtl_dma_flush(ptr, size_buffer); rt_copy_memory(ptr, buffer, size_buffer); + rtl_dma_flush(ptr, size_buffer); + rtl_dma_free(size_buffer); err_global_get() = kErrorSuccess; @@ -289,11 +301,11 @@ STATIC Bool drv_init_command_structures_ahci() { UIntPtr clb_phys = HAL::hal_get_phys_address(clb_mem); - kSATAHba->Ports[kSATAIndex].Clb = (UInt32)(clb_phys & 0xFFFFFFFF); - kSATAHba->Ports[kSATAIndex].Clbu = (UInt32)(clb_phys >> 32); + kSATAHba->Ports[kSATAIndex].Clb = (UInt32) (clb_phys & 0xFFFFFFFF); + kSATAHba->Ports[kSATAIndex].Clbu = (UInt32) (clb_phys >> 32); // Clear it - rt_set_memory(clb_mem, 0, 4096); + rt_set_memory(clb_mem, 0, kib_cast(4)); // For each command slot (up to 32) volatile HbaCmdHeader* header = (volatile HbaCmdHeader*) clb_mem; @@ -302,15 +314,15 @@ STATIC Bool drv_init_command_structures_ahci() { // Allocate 4KiB for Command Table VoidPtr ct_mem = Kernel::rtl_dma_alloc(4096, 128); if (!ct_mem) { - kout << "Failed to allocate CTB memory for slot " << hex_number(i); + (Void)(kout << "Failed to allocate CTB memory for slot " << hex_number(i)); kout << "!\r"; return NO; } UIntPtr ct_phys = HAL::hal_get_phys_address(ct_mem); - header[i].Ctba = (UInt32)(ct_phys & 0xFFFFFFFF); - header[i].Ctbau = (UInt32)(ct_phys >> 32); + header[i].Ctba = (UInt32) (ct_phys & 0xFFFFFFFF); + header[i].Ctbau = (UInt32) (ct_phys >> 32); // Clear the command table rt_set_memory((VoidPtr) ct_mem, 0, 4096); @@ -319,7 +331,6 @@ STATIC Bool drv_init_command_structures_ahci() { return YES; } - /// @brief Initializes an AHCI disk. /// @param pi the amount of ports that have been detected. /// @param atapi reference value, tells whether we should detect ATAPI instead of SATA. diff --git a/dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc index a7361778..ca3e9ee4 100644 --- a/dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc +++ b/dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc @@ -28,11 +28,11 @@ using namespace Kernel::HAL; /// BUGS: 0 -STATIC Boolean kATADetected = false; -STATIC Int32 kATADeviceType = kATADeviceCount; -STATIC UInt16 kATAIdentifyData[kATADataLen] = {0}; +STATIC Boolean kATADetected = false; +STATIC Int32 kATADeviceType ATTRIBUTE(unused) = kATADeviceCount; +STATIC UInt16 kATAIdentifyData[kATADataLen] = {0}; STATIC Kernel::PCI::Device kATADevice; -STATIC Char kATADiskModel[50] = {"GENERIC DMA"}; +STATIC Char kATADiskModel[50] ATTRIBUTE(unused) = {"GENERIC DMA"}; Boolean drv_std_wait_io(UInt16 IO) { for (int i = 0; i < 400; i++) rt_in8(IO + ATA_REG_STATUS); @@ -60,6 +60,11 @@ Void drv_std_select(UInt16 Bus) { } Boolean drv_std_init(UInt16 Bus, UInt8 Drive, UInt16& OutBus, UInt8& OutMaster) { + NE_UNUSED(Bus); + NE_UNUSED(Drive); + NE_UNUSED(OutBus); + NE_UNUSED(OutMaster); + PCI::Iterator iterator(Types::PciDeviceKind::MassStorageController); for (SizeT device_index = 0; device_index < NE_BUS_COUNT; ++device_index) { |
