3 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
4 Copyright (c) 2011 - 2016, ARM Ltd. All rights reserved.<BR>
5 Copyright (c) 2020, NUVIA Inc. All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
14 #include <Uefi/UefiBaseType.h>
17 #include <Chipset/ArmV7.h>
18 #elif defined(MDE_CPU_AARCH64)
19 #include <Chipset/AArch64.h>
21 #error "Unknown chipset."
24 #define EFI_MEMORY_CACHETYPE_MASK (EFI_MEMORY_UC | EFI_MEMORY_WC | \
25 EFI_MEMORY_WT | EFI_MEMORY_WB | \
29 * The UEFI firmware must not use the ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_* attributes.
31 * The Non Secure memory attribute (ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_*) should only
32 * be used in Secure World to distinguished Secure to Non-Secure memory.
35 ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED
= 0,
36 ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_UNCACHED_UNBUFFERED
,
37 ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK
,
38 ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_BACK
,
40 // On some platforms, memory mapped flash region is designed as not supporting
41 // shareable attribute, so WRITE_BACK_NONSHAREABLE is added for such special
43 // Do NOT use below two attributes if you are not sure.
44 ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK_NONSHAREABLE
,
45 ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_BACK_NONSHAREABLE
,
47 ARM_MEMORY_REGION_ATTRIBUTE_WRITE_THROUGH
,
48 ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_THROUGH
,
49 ARM_MEMORY_REGION_ATTRIBUTE_DEVICE
,
50 ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_DEVICE
51 } ARM_MEMORY_REGION_ATTRIBUTES
;
53 #define IS_ARM_MEMORY_REGION_ATTRIBUTES_SECURE(attr) ((UINT32)(attr) & 1)
56 EFI_PHYSICAL_ADDRESS PhysicalBase
;
57 EFI_VIRTUAL_ADDRESS VirtualBase
;
59 ARM_MEMORY_REGION_ATTRIBUTES Attributes
;
60 } ARM_MEMORY_REGION_DESCRIPTOR
;
62 typedef VOID (*CACHE_OPERATION
)(VOID
);
63 typedef VOID (*LINE_OPERATION
)(UINTN
);
69 ARM_PROCESSOR_MODE_USER
= 0x10,
70 ARM_PROCESSOR_MODE_FIQ
= 0x11,
71 ARM_PROCESSOR_MODE_IRQ
= 0x12,
72 ARM_PROCESSOR_MODE_SUPERVISOR
= 0x13,
73 ARM_PROCESSOR_MODE_ABORT
= 0x17,
74 ARM_PROCESSOR_MODE_HYP
= 0x1A,
75 ARM_PROCESSOR_MODE_UNDEFINED
= 0x1B,
76 ARM_PROCESSOR_MODE_SYSTEM
= 0x1F,
77 ARM_PROCESSOR_MODE_MASK
= 0x1F
83 #define ARM_CPU_IMPLEMENTER_MASK (0xFFU << 24)
84 #define ARM_CPU_IMPLEMENTER_ARMLTD (0x41U << 24)
85 #define ARM_CPU_IMPLEMENTER_DEC (0x44U << 24)
86 #define ARM_CPU_IMPLEMENTER_MOT (0x4DU << 24)
87 #define ARM_CPU_IMPLEMENTER_QUALCOMM (0x51U << 24)
88 #define ARM_CPU_IMPLEMENTER_MARVELL (0x56U << 24)
90 #define ARM_CPU_PRIMARY_PART_MASK (0xFFF << 4)
91 #define ARM_CPU_PRIMARY_PART_CORTEXA5 (0xC05 << 4)
92 #define ARM_CPU_PRIMARY_PART_CORTEXA7 (0xC07 << 4)
93 #define ARM_CPU_PRIMARY_PART_CORTEXA8 (0xC08 << 4)
94 #define ARM_CPU_PRIMARY_PART_CORTEXA9 (0xC09 << 4)
95 #define ARM_CPU_PRIMARY_PART_CORTEXA15 (0xC0F << 4)
100 #define ARM_CORE_AFF0 0xFF
101 #define ARM_CORE_AFF1 (0xFF << 8)
102 #define ARM_CORE_AFF2 (0xFF << 16)
103 #define ARM_CORE_AFF3 (0xFFULL << 32)
105 #define ARM_CORE_MASK ARM_CORE_AFF0
106 #define ARM_CLUSTER_MASK ARM_CORE_AFF1
107 #define GET_CORE_ID(MpId) ((MpId) & ARM_CORE_MASK)
108 #define GET_CLUSTER_ID(MpId) (((MpId) & ARM_CLUSTER_MASK) >> 8)
109 #define GET_MPID(ClusterId, CoreId) (((ClusterId) << 8) | (CoreId))
110 #define PRIMARY_CORE_ID (PcdGet32(PcdArmPrimaryCore) & ARM_CORE_MASK)
114 ArmDataCacheLineLength (
120 ArmInstructionCacheLineLength (
126 ArmCacheWritebackGranule (
132 ArmIsArchTimerImplemented (
150 ArmInvalidateDataCache (
157 ArmCleanInvalidateDataCache (
169 ArmInvalidateInstructionCache (
175 ArmInvalidateDataCacheEntryByMVA (
181 ArmCleanDataCacheEntryToPoUByMVA (
187 ArmInvalidateInstructionCacheEntryToPoUByMVA (
193 ArmCleanDataCacheEntryByMVA (
199 ArmCleanInvalidateDataCacheEntryByMVA (
211 ArmDisableDataCache (
217 ArmEnableInstructionCache (
223 ArmDisableInstructionCache (
241 ArmEnableCachesAndMmu (
247 ArmDisableCachesAndMmu (
253 ArmEnableInterrupts (
259 ArmDisableInterrupts (
265 ArmGetInterruptState (
271 ArmEnableAsynchronousAbort (
277 ArmDisableAsynchronousAbort (
312 * Invalidate Data and Instruction TLBs
322 ArmUpdateTranslationTableEntry (
323 IN VOID
*TranslationTableEntry
,
329 ArmSetDomainAccessControl (
336 IN VOID
*TranslationTableBase
347 ArmGetTTBR0BaseAddress (
359 ArmEnableBranchPrediction (
365 ArmDisableBranchPrediction (
383 ArmDataMemoryBarrier (
389 ArmDataSynchronizationBarrier (
395 ArmInstructionSynchronizationBarrier (
485 Get the Secure Configuration Register value
487 @return Value read from the Secure Configuration Register
497 Set the Secure Configuration Register
499 @param Value Value to write to the Secure Configuration Register
517 IN UINT32 VectorMonitorBase
541 IN UINTN HypModeVectorBase
546 // Helper functions for accessing CPU ACTLR
569 ArmUnsetCpuActlrBit (
574 // Accessors for the architected generic timer registers
577 #define ARM_ARCH_TIMER_ENABLE (1 << 0)
578 #define ARM_ARCH_TIMER_IMASK (1 << 1)
579 #define ARM_ARCH_TIMER_ISTATUS (1 << 2)
703 ArmGetPhysicalAddressBits (
709 /// ID Register Helper functions
713 Check whether the CPU supports the GIC system register interface (any version)
715 @return Whether GIC System Register Interface is supported
720 ArmHasGicSystemRegisters (
726 /// AArch32-only ID Register Helper functions
729 Check whether the CPU supports the Security extensions
731 @return Whether the Security extensions are implemented
736 ArmHasSecurityExtensions (
739 #endif // MDE_CPU_ARM
741 #endif // __ARM_LIB__