From 6bbf5ad2058db4020ae20d6aba8f5b099dadc85f Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 14 Mar 2025 22:26:42 +0100 Subject: TQ-24 && TQ-16: Add build scripts for MBCI, MBCI+Flash, and UFS. META: Along other tweaks and important ARM64 patches. Signed-off-by: Amlal El Mahrouss --- dev/Kernel/HALKit/ARM64/HalACPIFactoryInterface.cc | 3 +- dev/Kernel/HALKit/ARM64/HalDebugOutput.cc | 4 +- dev/Kernel/HALKit/ARM64/HalFlushTLB.S | 5 + dev/Kernel/HALKit/ARM64/HalKernelMain.cc | 2 + dev/Kernel/HALKit/ARM64/HalPageInternal.S | 5 - dev/Kernel/HALKit/ARM64/HalPagingMgrARM64.cc | 4 +- dev/Kernel/HALKit/ARM64/Processor.h | 2 +- .../HALKit/ARM64/Storage/MBCI+Flash+IO+Generic.cc | 119 +++++++++++++++++++++ dev/Kernel/HALKit/ARM64/Storage/MFlash+IO.cc | 119 --------------------- dev/Kernel/HALKit/ARM64/Storage/UFS+Generic.cc | 11 ++ 10 files changed, 144 insertions(+), 130 deletions(-) create mode 100644 dev/Kernel/HALKit/ARM64/HalFlushTLB.S delete mode 100644 dev/Kernel/HALKit/ARM64/HalPageInternal.S create mode 100644 dev/Kernel/HALKit/ARM64/Storage/MBCI+Flash+IO+Generic.cc delete mode 100644 dev/Kernel/HALKit/ARM64/Storage/MFlash+IO.cc create mode 100644 dev/Kernel/HALKit/ARM64/Storage/UFS+Generic.cc (limited to 'dev/Kernel/HALKit/ARM64') diff --git a/dev/Kernel/HALKit/ARM64/HalACPIFactoryInterface.cc b/dev/Kernel/HALKit/ARM64/HalACPIFactoryInterface.cc index 6dcfa9a2..8ca9ac06 100644 --- a/dev/Kernel/HALKit/ARM64/HalACPIFactoryInterface.cc +++ b/dev/Kernel/HALKit/ARM64/HalACPIFactoryInterface.cc @@ -17,9 +17,10 @@ namespace NeOS { } - Void ACPIFactoryInterface::Shutdown() + BOOL ACPIFactoryInterface::Shutdown() { apm_send_io_command(kAPMPowerCommandShutdown, 0); + return NO; } /// @brief Reboot machine in either ACPI or by triple faulting. diff --git a/dev/Kernel/HALKit/ARM64/HalDebugOutput.cc b/dev/Kernel/HALKit/ARM64/HalDebugOutput.cc index 97621e23..8d54739f 100644 --- a/dev/Kernel/HALKit/ARM64/HalDebugOutput.cc +++ b/dev/Kernel/HALKit/ARM64/HalDebugOutput.cc @@ -11,7 +11,7 @@ namespace NeOS { - EXTERN_C void ke_io_write(const Char* bytes) + EXTERN_C void ke_io_write(IDeviceObject* self, const Char* bytes) { #ifdef __DEBUG__ if (*bytes == 0) @@ -38,7 +38,7 @@ namespace NeOS TerminalDevice::~TerminalDevice() = default; - EXTERN_C void ke_io_read(const Char* bytes) + EXTERN_C void ke_io_read(IDeviceObject* self, const Char* bytes) { #ifdef __DEBUG__ SizeT index = 0; diff --git a/dev/Kernel/HALKit/ARM64/HalFlushTLB.S b/dev/Kernel/HALKit/ARM64/HalFlushTLB.S new file mode 100644 index 00000000..8fcf40ff --- /dev/null +++ b/dev/Kernel/HALKit/ARM64/HalFlushTLB.S @@ -0,0 +1,5 @@ +.text + +hal_flush_tlb: + tlbi + ret diff --git a/dev/Kernel/HALKit/ARM64/HalKernelMain.cc b/dev/Kernel/HALKit/ARM64/HalKernelMain.cc index afb1cc0e..5a6d0dc2 100644 --- a/dev/Kernel/HALKit/ARM64/HalKernelMain.cc +++ b/dev/Kernel/HALKit/ARM64/HalKernelMain.cc @@ -18,6 +18,8 @@ #include #include +#include + EXTERN_C void hal_init_platform( NeOS::HEL::BootInfoHeader* handover_hdr) { diff --git a/dev/Kernel/HALKit/ARM64/HalPageInternal.S b/dev/Kernel/HALKit/ARM64/HalPageInternal.S deleted file mode 100644 index 8fcf40ff..00000000 --- a/dev/Kernel/HALKit/ARM64/HalPageInternal.S +++ /dev/null @@ -1,5 +0,0 @@ -.text - -hal_flush_tlb: - tlbi - ret diff --git a/dev/Kernel/HALKit/ARM64/HalPagingMgrARM64.cc b/dev/Kernel/HALKit/ARM64/HalPagingMgrARM64.cc index e04b77cd..4ec45b51 100644 --- a/dev/Kernel/HALKit/ARM64/HalPagingMgrARM64.cc +++ b/dev/Kernel/HALKit/ARM64/HalPagingMgrARM64.cc @@ -45,7 +45,7 @@ namespace NeOS::HAL /// @param phys_addr point to physical address. /// @param flags the flags to put on the page. /// @return Status code of page manipulation process. - EXTERN_C Int32 mm_map_page(VoidPtr virtual_address, UInt32 flags) + EXTERN_C Int32 mm_map_page(VoidPtr virtual_address, VoidPtr physical_address, UInt32 flags) { if (!virtual_address || !flags) @@ -73,7 +73,7 @@ namespace NeOS::HAL { NE_PAGE_STORE& page_store = NE_PAGE_STORE::The(); - // Update Internal store. + // Update internal store. page_store.fInternalStore.fPde = nullptr; page_store.fInternalStore.fPte = pt_entry; diff --git a/dev/Kernel/HALKit/ARM64/Processor.h b/dev/Kernel/HALKit/ARM64/Processor.h index 4dba5a8b..e79a99c7 100644 --- a/dev/Kernel/HALKit/ARM64/Processor.h +++ b/dev/Kernel/HALKit/ARM64/Processor.h @@ -36,7 +36,7 @@ namespace NeOS::HAL /// @param phys_addr point to physical address. /// @param flags the flags to put on the page. /// @return Status code of page manip. - EXTERN_C Int32 mm_map_page(VoidPtr virt_addr, UInt32 flags); + EXTERN_C Int32 mm_map_page(VoidPtr virtual_address, VoidPtr physical_address, UInt32 flags); typedef UIntPtr Reg; typedef Register64 Register; diff --git a/dev/Kernel/HALKit/ARM64/Storage/MBCI+Flash+IO+Generic.cc b/dev/Kernel/HALKit/ARM64/Storage/MBCI+Flash+IO+Generic.cc new file mode 100644 index 00000000..3ccca867 --- /dev/null +++ b/dev/Kernel/HALKit/ARM64/Storage/MBCI+Flash+IO+Generic.cc @@ -0,0 +1,119 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal EL Mahrouss, all rights reserved. + +------------------------------------------- */ + +#ifdef NE_USE_MBCI_FLASH + +#include +#include +#include +#include + +/// @file MBCI+Flash.cc +/// @brief MBCI Flash support. + +#define MBCI_MAX_SLOTS (8U) + +namespace NeOS +{ + /// /Mount/Flash/n + constexpr auto kFlashBridgeMagic = 0x70768372; + constexpr auto kFlashBridgeRevision = 1; + + STATIC BOOL kFlashEnabled = NO; + STATIC SizeT kFlashSize[MBCI_MAX_SLOTS] = {}; + STATIC SizeT kFlashSectorSz[MBCI_MAX_SLOTS] = {}; + STATIC IMBCIHost* kFlashMetaPackets[MBCI_MAX_SLOTS] = {}; + STATIC IMBCIHost* kFlashDataPackets[MBCI_MAX_SLOTS] = {}; + + STATIC Void drv_std_io(Int32 slot, UInt64 lba, Char* buf, SizeT sector_sz, SizeT buf_sz); + + /// @brief Enable flash memory builtin. + STATIC Void drv_enable_flash(Int32 slot); + + /// @brief Disable flash memory builtin. + STATIC Void drv_disable_flash(Int32 slot); + + /// @brief get slot sector count. + /// @return slot sector count. + SizeT drv_get_sector_count(Int32 slot) + { + if (slot > MBCI_MAX_SLOTS) + return 0; + + return kFlashSectorSz[slot]; + } + + /// @brief get slot full size (in bytes). + /// @return drive slot size + SizeT drv_get_size(Int32 slot) + { + if (slot > MBCI_MAX_SLOTS) + return 0; + + return kFlashSize[slot]; + } + + /// @brief Enable flash memory at slot. + BOOL drv_enable_at(Int32 slot) + { + if (slot > MBCI_MAX_SLOTS) + return NO; + + kFlashMetaPackets[slot]->InterruptEnable = YES; + + kout << "Enabled hardware slot at: " << number(slot) << kendl; + + return YES; + } + + /// @brief Disable flash memory at slot. + BOOL drv_disable_at(Int32 slot) + { + if (slot > MBCI_MAX_SLOTS) + return NO; + + kFlashMetaPackets[slot]->InterruptEnable = NO; + + kout << "Disabled hardware slot at: " << number(slot) << kendl; + + return YES; + } + + STATIC Void drv_std_io(Int32 slot, UInt64 lba, Char* buf, SizeT sector_sz, SizeT buf_sz) + { + UInt64* packet_frame = (UInt64*)kFlashDataPackets[slot]->BaseAddressRegister; + + if (packet_frame[0] != (UInt64)kFlashBridgeMagic) + return; + + if (packet_frame[8] != (UInt64)kFlashBridgeRevision) + return; + + packet_frame[16 + 0] = lba; + packet_frame[16 + 4] = sector_sz; + packet_frame[16 + 8] = lba; + packet_frame[16 + 12] = buf_sz; + packet_frame[16 + 14] = (UIntPtr)HAL::hal_get_phys_address(buf); + + while (packet_frame[0] == lba) + ; + } + + Void drv_std_read(Int32 slot, UInt64 lba, Char* buf, SizeT sector_sz, SizeT buf_sz) + { + rt_set_memory(buf, 0, buf_sz); + + drv_std_io(slot, lba, buf, sector_sz, buf_sz); + } + + Void drv_std_write(Int32 slot, UInt64 lba, Char* buf, SizeT sector_sz, SizeT buf_sz) + { + drv_std_io(slot, lba, buf, sector_sz, buf_sz); + } + +} // namespace NeOS + +#endif // if NE_USE_MBCI_FLASH diff --git a/dev/Kernel/HALKit/ARM64/Storage/MFlash+IO.cc b/dev/Kernel/HALKit/ARM64/Storage/MFlash+IO.cc deleted file mode 100644 index 1335a9e4..00000000 --- a/dev/Kernel/HALKit/ARM64/Storage/MFlash+IO.cc +++ /dev/null @@ -1,119 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal EL Mahrouss, all rights reserved. - -------------------------------------------- */ - -#ifdef NE_USE_MBCI_FLASH - -#include -#include -#include -#include - -/// @file MFlash.cc -/// @brief MBCI Flash support. - -#define kMaxFlashSlots (8U) - -namespace NeOS -{ - /// /Mount/Flash/n - constexpr auto kFlashBridgeMagic = 0x70768372; - constexpr auto kFlashBridgeRevision = 1; - - STATIC BOOL kFlashEnabled = NO; - STATIC SizeT kFlashSize[kMaxFlashSlots] = {}; - STATIC SizeT kFlashSectorSz[kMaxFlashSlots] = {}; - STATIC IMBCIHost* kFlashMetaPackets[kMaxFlashSlots] = {}; - STATIC IMBCIHost* kFlashDataPackets[kMaxFlashSlots] = {}; - - STATIC Void drv_std_io(Int32 slot, UInt64 lba, Char* buf, SizeT sector_sz, SizeT buf_sz); - - /// @brief Enable flash memory builtin. - STATIC Void drv_enable_flash(Int32 slot); - - /// @brief Disable flash memory builtin. - STATIC Void drv_disable_flash(Int32 slot); - - /// @brief get slot sector count. - /// @return slot sector count. - SizeT drv_get_sector_count(Int32 slot) - { - if (slot > kMaxFlashSlots) - return 0; - - return kFlashSectorSz[slot]; - } - - /// @brief get slot full size (in bytes). - /// @return drive slot size - SizeT drv_get_size(Int32 slot) - { - if (slot > kMaxFlashSlots) - return 0; - - return kFlashSize[slot]; - } - - /// @brief Enable flash memory at slot. - BOOL drv_enable_at(Int32 slot) - { - if (slot > kMaxFlashSlots) - return NO; - - kFlashMetaPackets[slot]->InterruptEnable = YES; - - kout << "Enabled hardware slot at: " << number(slot) << kendl; - - return YES; - } - - /// @brief Disable flash memory at slot. - BOOL drv_disable_at(Int32 slot) - { - if (slot > kMaxFlashSlots) - return NO; - - kFlashMetaPackets[slot]->InterruptEnable = NO; - - kout << "Disabled hardware slot at: " << number(slot) << kendl; - - return YES; - } - - STATIC Void drv_std_io(Int32 slot, UInt64 lba, Char* buf, SizeT sector_sz, SizeT buf_sz) - { - UInt64* packet_frame = (UInt64*)kFlashDataPackets[slot]->BaseAddressRegister; - - if (packet_frame[0] != (UInt64)kFlashBridgeMagic) - return; - - if (packet_frame[8] != (UInt64)kFlashBridgeRevision) - return; - - packet_frame[16 + 0] = lba; - packet_frame[16 + 4] = sector_sz; - packet_frame[16 + 8] = lba; - packet_frame[16 + 12] = buf_sz; - packet_frame[16 + 14] = (UIntPtr)HAL::hal_get_phys_address(buf); - - while (packet_frame[0] == lba) - ; - } - - Void drv_std_read(Int32 slot, UInt64 lba, Char* buf, SizeT sector_sz, SizeT buf_sz) - { - rt_set_memory(buf, 0, buf_sz); - - drv_std_io(slot, lba, buf, sector_sz, buf_sz); - } - - Void drv_std_write(Int32 slot, UInt64 lba, Char* buf, SizeT sector_sz, SizeT buf_sz) - { - drv_std_io(slot, lba, buf, sector_sz, buf_sz); - } - -} // namespace NeOS - -#endif // if NE_USE_MBCI_FLASH diff --git a/dev/Kernel/HALKit/ARM64/Storage/UFS+Generic.cc b/dev/Kernel/HALKit/ARM64/Storage/UFS+Generic.cc new file mode 100644 index 00000000..20d06671 --- /dev/null +++ b/dev/Kernel/HALKit/ARM64/Storage/UFS+Generic.cc @@ -0,0 +1,11 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal EL Mahrouss, all rights reserved. + +------------------------------------------- */ + +/// @file UFS.cc +/// @brief UFS Flash Memory support. + +#define UFS_PCI_VENDOR_ID (0x01001) /* AKER */ +#define UFS_PCI_DEVICE_ID (0xAEAEA) /* AKER */ \ No newline at end of file -- cgit v1.2.3