From cbfd279a1410e11d734edc99509a3e0c02dc6fcc Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 3 Jan 2025 09:58:24 +0100 Subject: Worked on the AARCH64 HAL for TQ's boards, Add new spec in /doc/ Signed-off-by: Amlal El Mahrouss --- dev/Kernel/HALKit/ARM64/.gitkeep | 0 dev/Kernel/HALKit/ARM64/APM/.gitkeep | 0 dev/Kernel/HALKit/ARM64/APM/APM+IO.cc | 37 ++++++++++ dev/Kernel/HALKit/ARM64/APM/APM.cc | 37 ---------- dev/Kernel/HALKit/ARM64/HalAP.cc | 40 ----------- dev/Kernel/HALKit/ARM64/HalApplicationProcessor.cc | 40 +++++++++++ dev/Kernel/HALKit/ARM64/MBCI/.keepme | 0 dev/Kernel/HALKit/ARM64/MBCI/MBCI.cc | 7 ++ dev/Kernel/HALKit/ARM64/Storage/HalMFlash.cc | 67 ----------------- dev/Kernel/HALKit/ARM64/Storage/MFlash+IO.cc | 84 ++++++++++++++++++++++ dev/Mod/MBCI/MBCI.h | 20 +----- dev/Mod/MFlash/MFlash.h | 12 ++-- dev/Mod/NVME/NVME.h | 11 +-- 13 files changed, 183 insertions(+), 172 deletions(-) delete mode 100644 dev/Kernel/HALKit/ARM64/.gitkeep delete mode 100644 dev/Kernel/HALKit/ARM64/APM/.gitkeep create mode 100644 dev/Kernel/HALKit/ARM64/APM/APM+IO.cc delete mode 100644 dev/Kernel/HALKit/ARM64/APM/APM.cc delete mode 100644 dev/Kernel/HALKit/ARM64/HalAP.cc create mode 100644 dev/Kernel/HALKit/ARM64/HalApplicationProcessor.cc delete mode 100644 dev/Kernel/HALKit/ARM64/MBCI/.keepme create mode 100644 dev/Kernel/HALKit/ARM64/MBCI/MBCI.cc delete mode 100644 dev/Kernel/HALKit/ARM64/Storage/HalMFlash.cc create mode 100644 dev/Kernel/HALKit/ARM64/Storage/MFlash+IO.cc (limited to 'dev') diff --git a/dev/Kernel/HALKit/ARM64/.gitkeep b/dev/Kernel/HALKit/ARM64/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/dev/Kernel/HALKit/ARM64/APM/.gitkeep b/dev/Kernel/HALKit/ARM64/APM/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/dev/Kernel/HALKit/ARM64/APM/APM+IO.cc b/dev/Kernel/HALKit/ARM64/APM/APM+IO.cc new file mode 100644 index 00000000..d9b2512d --- /dev/null +++ b/dev/Kernel/HALKit/ARM64/APM/APM+IO.cc @@ -0,0 +1,37 @@ +/* ------------------------------------------- + + Copyright (C) 2024, Theater Quality Corp, all rights reserved. + +------------------------------------------- */ + +#include +#include + +using namespace Kernel; + +/// @brief Send APM command to it's space. +/// @param base_dma the IO base port. +/// @param cmd the command. +/// @return status code. +EXTERN_C Int32 apm_send_io_command(UInt16 cmd, APMPowerCmd value) +{ + switch (cmd) + { + case kAPMPowerCommandReboot: { + asm volatile( + "ldr x0, =0x84000004\n" + "svc #0\n"); + + return kErrorSuccess; + } + case kAPMPowerCommandShutdown: { + asm volatile( + "ldr x0, =0x84000008\n" + "svc #0\n"); + + return kErrorSuccess; + } + default: + return kErrorInvalidData; + } +} diff --git a/dev/Kernel/HALKit/ARM64/APM/APM.cc b/dev/Kernel/HALKit/ARM64/APM/APM.cc deleted file mode 100644 index 51ac14f3..00000000 --- a/dev/Kernel/HALKit/ARM64/APM/APM.cc +++ /dev/null @@ -1,37 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024, Theater Quality Corp, all rights reserved. - -------------------------------------------- */ - -#include -#include - -using namespace Kernel; - -/// @brief Send a APM command into it's own IO space. -/// @param base_dma the IO base port. -/// @param cmd the command. -/// @return status code. -EXTERN_C Int32 apm_send_io_command(UInt16 cmd, APMPowerCmd value) -{ - switch (cmd) - { - case kAPMPowerCommandReboot: { - asm volatile( - "ldr x0, =0x84000009\n" - "hvc #0\n"); - - return kErrorSuccess; - } - case kAPMPowerCommandShutdown: { - asm volatile( - "ldr x0, =0x84000008\n" - "hvc #0\n"); - - return kErrorSuccess; - } - default: - return kErrorInvalidData; - } -} diff --git a/dev/Kernel/HALKit/ARM64/HalAP.cc b/dev/Kernel/HALKit/ARM64/HalAP.cc deleted file mode 100644 index c74a83d0..00000000 --- a/dev/Kernel/HALKit/ARM64/HalAP.cc +++ /dev/null @@ -1,40 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024, Theater Quality Corp, all rights reserved. - -------------------------------------------- */ - -#include -#include -#include - -using namespace Kernel; - -namespace Kernel::Detail -{ - STATIC void mp_hang_fn(void) - { - while (YES) - ; - } -} // namespace Kernel::Detail - -/// @brief wakes up thread. -/// wakes up thread from hang. -void mp_wakeup_thread(HAL::StackFramePtr stack) -{ - if (!stack) - return; - - hal_set_pc_to_hart(reinterpret_cast(stack->R15), reinterpret_cast(stack->BP)); -} - -/// @brief makes thread sleep. -/// hooks and hangs thread to prevent code from executing. -void mp_hang_thread(HAL::StackFramePtr stack) -{ - if (!stack) - return; - - hal_set_pc_to_hart(reinterpret_cast(stack->R15), reinterpret_cast(Kernel::Detail::mp_hang_fn)); -} diff --git a/dev/Kernel/HALKit/ARM64/HalApplicationProcessor.cc b/dev/Kernel/HALKit/ARM64/HalApplicationProcessor.cc new file mode 100644 index 00000000..fa62cf20 --- /dev/null +++ b/dev/Kernel/HALKit/ARM64/HalApplicationProcessor.cc @@ -0,0 +1,40 @@ +/* ------------------------------------------- + + Copyright (C) 2024, Theater Quality Corp, all rights reserved. + +------------------------------------------- */ + +#include +#include +#include + +using namespace Kernel; + +namespace Kernel::Detail +{ + STATIC void mp_hang_fn(void) + { + while (YES) + ; + } +} // namespace Kernel::Detail + +/// @brief wakes up thread from it's hang state. +/// wakes up thread from hang. +Void mp_wakeup_thread(HAL::StackFramePtr stack) +{ + if (!stack) + return; + + hal_set_pc_to_hart(reinterpret_cast(stack->R15), reinterpret_cast(stack->BP)); +} + +/// @brief makes thread go to hang state. +/// hooks and hangs thread to prevent code from executing. +Void mp_hang_thread(HAL::StackFramePtr stack) +{ + if (!stack) + return; + + hal_set_pc_to_hart(reinterpret_cast(stack->R15), reinterpret_cast(Kernel::Detail::mp_hang_fn)); +} diff --git a/dev/Kernel/HALKit/ARM64/MBCI/.keepme b/dev/Kernel/HALKit/ARM64/MBCI/.keepme deleted file mode 100644 index e69de29b..00000000 diff --git a/dev/Kernel/HALKit/ARM64/MBCI/MBCI.cc b/dev/Kernel/HALKit/ARM64/MBCI/MBCI.cc new file mode 100644 index 00000000..e16845da --- /dev/null +++ b/dev/Kernel/HALKit/ARM64/MBCI/MBCI.cc @@ -0,0 +1,7 @@ +/* ------------------------------------------- + + Copyright (C) 2025, Theater Quality Corp, all rights reserved. + +------------------------------------------- */ + +#include \ No newline at end of file diff --git a/dev/Kernel/HALKit/ARM64/Storage/HalMFlash.cc b/dev/Kernel/HALKit/ARM64/Storage/HalMFlash.cc deleted file mode 100644 index 2a764101..00000000 --- a/dev/Kernel/HALKit/ARM64/Storage/HalMFlash.cc +++ /dev/null @@ -1,67 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024, Theater Quality Corp, all rights reserved. - -------------------------------------------- */ - -#ifdef ZKA_USE_MBCI_FLASH - -#include -#include -#include - -/// @file HalMFlash.cc -/// @brief MBCI Flash builtin. - -#define kMaxFlash (4U) - -namespace Kernel -{ - /// /Mount/Flash/n - constexpr auto kFlashBridgeMagic = "FLSH"; - constexpr auto kFlashBridgeRevision = 1; - - STATIC CONST Boolean kFlashEnabled = No; - STATIC SizeT kFlashSize[kMaxFlash] = {}; - STATIC SizeT kFlashSectorSz[kMaxFlash] = {}; - - /// @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 sector count. - /// @return drive sector count. - SizeT drv_get_sector_count(Int32 slot) - { - if (slot > kMaxFlash) - return 0; - - return kFlashSectorSz[slot]; - } - - /// @brief get device size. - /// @return drive size - SizeT drv_get_size(Int32 slot) - { - if (slot > kMaxFlash) - return 0; - - return kFlashSize[slot]; - } - - /// @brief Enable flash memory at slot. - STATIC Void drv_enable_flash(Int32 arg) - { - kcout << "Enabled FLSH hardware.\r"; - } - - /// @brief Disable flash memory at slot. - STATIC Void drv_disable_flash(Int32 arg) - { - kcout << "Disabled FLSH hardware.\r"; - } -} // namespace Kernel - -#endif // if ZKA_USE_MBCI_FLASH (Bridge) diff --git a/dev/Kernel/HALKit/ARM64/Storage/MFlash+IO.cc b/dev/Kernel/HALKit/ARM64/Storage/MFlash+IO.cc new file mode 100644 index 00000000..2d556b96 --- /dev/null +++ b/dev/Kernel/HALKit/ARM64/Storage/MFlash+IO.cc @@ -0,0 +1,84 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Theater Quality Corp, all rights reserved. + +------------------------------------------- */ + +#ifdef ZKA_USE_MBCI_FLASH + +#include +#include +#include +#include + +/// @file MFlash.cc +/// @brief MBCI Flash support. + +#define kMaxFlashSlots (8U) + +namespace Kernel +{ + /// /Mount/Flash/n + constexpr auto kFlashBridgeMagic = "FLSH"; + constexpr auto kFlashBridgeRevision = 1; + + STATIC BOOL kFlashEnabled = NO; + STATIC SizeT kFlashSize[kMaxFlashSlots] = {}; + STATIC SizeT kFlashSectorSz[kMaxFlashSlots] = {}; + STATIC IMBCIHost* kFlashMetaPackets[kMaxFlashSlots] = {}; + STATIC IMBCIHost* kFlashDataPackets[kMaxFlashSlots] = {}; + + /// @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; + + kcout << "Enabled hardware slot at: " << number(slot) << endl; + + return YES; + } + + /// @brief Disable flash memory at slot. + BOOL drv_disable_at(Int32 slot) + { + if (slot > kMaxFlashSlots) + return NO; + + kFlashMetaPackets[slot]->InterruptEnable = NO; + + kcout << "Disabled hardware slot at: " << number(slot) << endl; + + return YES; + } +} // namespace Kernel + +#endif // if ZKA_USE_MBCI_FLASH diff --git a/dev/Mod/MBCI/MBCI.h b/dev/Mod/MBCI/MBCI.h index dae14298..562953d4 100644 --- a/dev/Mod/MBCI/MBCI.h +++ b/dev/Mod/MBCI/MBCI.h @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright (C) 2024, Theater Quality Corp, all rights reserved. + Copyright (C) 2024-2025, Theater Quality Corp, all rights reserved. ------------------------------------------- */ @@ -26,20 +26,6 @@ namespace Kernel { struct IMBCIHost; - struct IMBCIHostPacketFrame; - - /// @brief MBCI Packet frame header - struct PACKED IMBCIHostPacketFrame final - { - UInt32 Magic; - UInt32 HostId; - UInt32 Flags; - UInt32 VendorId; - UInt32 DeviceId; - UInt32 DeviceSpeed; - Bool Acknowledge; - Char Zero[kMBCIZeroSz]; - }; enum { @@ -49,7 +35,7 @@ namespace Kernel kMBCISpeedDeviceCount, }; - /// @brief MBCI Host Interface header. + /// @brief MBCI Host header. struct PACKED IMBCIHost final { UInt32 Magic; @@ -92,7 +78,7 @@ namespace Kernel }; /// @brief An AuthKey is a context used to decrpy data from an MBCI packet. - typedef UInt64 MBCIAuthyKeyType; + typedef UInt64 MBCIAuthKeyType; } // namespace Kernel #endif // ifndef _INC_MODULE_MBCI_H_ diff --git a/dev/Mod/MFlash/MFlash.h b/dev/Mod/MFlash/MFlash.h index 5942353a..33e56a2b 100644 --- a/dev/Mod/MFlash/MFlash.h +++ b/dev/Mod/MFlash/MFlash.h @@ -10,12 +10,12 @@ #include -/// @brief get sector count. -/// @return drive sector count. -Kernel::SizeT drv_get_sector_count(); +Kernel::SizeT drv_get_sector_count(Kernel::Int32 slot); -/// @brief get device size. -/// @return drive size -Kernel::SizeT drv_get_size(); +Kernel::SizeT drv_get_size(Kernel::Int32 slot); + +Kernel::Void drv_enable_at(Kernel::Int32 slot); + +Kernel::Void drv_disable_at(Kernel::Int32 slot); #endif // ifdef ZKA_USE_MBCI_FLASH diff --git a/dev/Mod/NVME/NVME.h b/dev/Mod/NVME/NVME.h index 6d327bd7..73ca0d7e 100644 --- a/dev/Mod/NVME/NVME.h +++ b/dev/Mod/NVME/NVME.h @@ -5,7 +5,7 @@ Revision History: ??/??/24: Added file (amlel) - 23 Jul 24: Update filename to Defines.h and using ALIGN_NVME for NVME structs. (amlel) + 23 Jul 24: Update filename to Defines.h and using ZKA_ALIGN_NVME for NVME structs. (amlel) ------------------------------------------- */ @@ -14,13 +14,14 @@ #include -/// TODO: checklist in: https://wiki.osdev.org/NVMe +/// @file NVME.h +/// @brief NVME driver. -#define ALIGN_NVME ATTRIBUTE(aligned(sizeof(Kernel::UInt32))) +#define ZKA_ALIGN_NVME ATTRIBUTE(aligned(sizeof(Kernel::UInt32))) namespace Kernel { - struct ALIGN_NVME HAL_NVME_BAR_0 final + struct ZKA_ALIGN_NVME HAL_NVME_BAR_0 final { UInt32 fCapabilities; UInt32 fVersion; @@ -33,7 +34,7 @@ namespace Kernel UInt32 fAdminCompletionQueue; }; - struct ALIGN_NVME HAL_NVME_QUEUE final + struct ZKA_ALIGN_NVME HAL_NVME_QUEUE final { UInt32 fOpcode; UInt32 fNSID; -- cgit v1.2.3