3 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
4 Copyright (c) 2011 - 2012, ARM Ltd. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 #include <Uefi/UefiBaseType.h>
23 #include <Chipset/ARM1176JZ-S.h>
25 #include <Chipset/ArmV7.h>
27 #elif defined(MDE_CPU_AARCH64)
28 #include <Chipset/AArch64.h>
30 #error "Unknown chipset."
34 ARM_CACHE_TYPE_WRITE_BACK
,
35 ARM_CACHE_TYPE_UNKNOWN
39 ARM_CACHE_ARCHITECTURE_UNIFIED
,
40 ARM_CACHE_ARCHITECTURE_SEPARATE
,
41 ARM_CACHE_ARCHITECTURE_UNKNOWN
42 } ARM_CACHE_ARCHITECTURE
;
46 ARM_CACHE_ARCHITECTURE Architecture
;
47 BOOLEAN DataCachePresent
;
49 UINTN DataCacheAssociativity
;
50 UINTN DataCacheLineLength
;
51 BOOLEAN InstructionCachePresent
;
52 UINTN InstructionCacheSize
;
53 UINTN InstructionCacheAssociativity
;
54 UINTN InstructionCacheLineLength
;
58 * The UEFI firmware must not use the ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_* attributes.
60 * The Non Secure memory attribute (ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_*) should only
61 * be used in Secure World to distinguished Secure to Non-Secure memory.
64 ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED
= 0,
65 ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_UNCACHED_UNBUFFERED
,
66 ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK
,
67 ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_BACK
,
68 ARM_MEMORY_REGION_ATTRIBUTE_WRITE_THROUGH
,
69 ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_THROUGH
,
70 ARM_MEMORY_REGION_ATTRIBUTE_DEVICE
,
71 ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_DEVICE
72 } ARM_MEMORY_REGION_ATTRIBUTES
;
74 #define IS_ARM_MEMORY_REGION_ATTRIBUTES_SECURE(attr) ((UINT32)(attr) & 1)
77 EFI_PHYSICAL_ADDRESS PhysicalBase
;
78 EFI_VIRTUAL_ADDRESS VirtualBase
;
80 ARM_MEMORY_REGION_ATTRIBUTES Attributes
;
81 } ARM_MEMORY_REGION_DESCRIPTOR
;
83 typedef VOID (*CACHE_OPERATION
)(VOID
);
84 typedef VOID (*LINE_OPERATION
)(UINTN
);
90 ARM_PROCESSOR_MODE_USER
= 0x10,
91 ARM_PROCESSOR_MODE_FIQ
= 0x11,
92 ARM_PROCESSOR_MODE_IRQ
= 0x12,
93 ARM_PROCESSOR_MODE_SUPERVISOR
= 0x13,
94 ARM_PROCESSOR_MODE_ABORT
= 0x17,
95 ARM_PROCESSOR_MODE_HYP
= 0x1A,
96 ARM_PROCESSOR_MODE_UNDEFINED
= 0x1B,
97 ARM_PROCESSOR_MODE_SYSTEM
= 0x1F,
98 ARM_PROCESSOR_MODE_MASK
= 0x1F
104 #define ARM_CPU_IMPLEMENTER_MASK (0xFFU << 24)
105 #define ARM_CPU_IMPLEMENTER_ARMLTD (0x41U << 24)
106 #define ARM_CPU_IMPLEMENTER_DEC (0x44U << 24)
107 #define ARM_CPU_IMPLEMENTER_MOT (0x4DU << 24)
108 #define ARM_CPU_IMPLEMENTER_QUALCOMM (0x51U << 24)
109 #define ARM_CPU_IMPLEMENTER_MARVELL (0x56U << 24)
111 #define ARM_CPU_PRIMARY_PART_MASK (0xFFF << 4)
112 #define ARM_CPU_PRIMARY_PART_CORTEXA5 (0xC05 << 4)
113 #define ARM_CPU_PRIMARY_PART_CORTEXA7 (0xC07 << 4)
114 #define ARM_CPU_PRIMARY_PART_CORTEXA8 (0xC08 << 4)
115 #define ARM_CPU_PRIMARY_PART_CORTEXA9 (0xC09 << 4)
116 #define ARM_CPU_PRIMARY_PART_CORTEXA15 (0xC0F << 4)
121 #define ARM_CORE_MASK 0xFF
122 #define ARM_CLUSTER_MASK (0xFF << 8)
123 #define GET_CORE_ID(MpId) ((MpId) & ARM_CORE_MASK)
124 #define GET_CLUSTER_ID(MpId) (((MpId) & ARM_CLUSTER_MASK) >> 8)
125 #define GET_MPID(ClusterId, CoreId) (((ClusterId) << 8) | (CoreId))
126 // Get the position of the core for the Stack Offset (4 Core per Cluster)
127 // Position = (ClusterId * 4) + CoreId
128 #define GET_CORE_POS(MpId) ((((MpId) & ARM_CLUSTER_MASK) >> 6) + ((MpId) & ARM_CORE_MASK))
129 #define PRIMARY_CORE_ID (PcdGet32(PcdArmPrimaryCore) & ARM_CORE_MASK)
137 ARM_CACHE_ARCHITECTURE
139 ArmCacheArchitecture (
145 ArmCacheInformation (
146 OUT ARM_CACHE_INFO
*CacheInfo
151 ArmDataCachePresent (
163 ArmDataCacheAssociativity (
169 ArmDataCacheLineLength (
175 ArmInstructionCachePresent (
181 ArmInstructionCacheSize (
187 ArmInstructionCacheAssociativity (
193 ArmInstructionCacheLineLength (
217 ArmInvalidateDataCache (
224 ArmCleanInvalidateDataCache (
236 ArmCleanDataCacheToPoU (
242 ArmInvalidateInstructionCache (
248 ArmInvalidateDataCacheEntryByMVA (
254 ArmCleanDataCacheEntryByMVA (
260 ArmCleanInvalidateDataCacheEntryByMVA (
272 ArmDisableDataCache (
278 ArmEnableInstructionCache (
284 ArmDisableInstructionCache (
302 ArmDisableCachesAndMmu (
308 ArmInvalidateInstructionAndDataTlb (
314 ArmEnableInterrupts (
320 ArmDisableInterrupts (
326 ArmGetInterruptState (
368 ArmUpdateTranslationTableEntry (
369 IN VOID
*TranslationTableEntry
,
375 ArmSetDomainAccessControl (
382 IN VOID
*TranslationTableBase
387 ArmGetTTBR0BaseAddress (
394 IN ARM_MEMORY_REGION_DESCRIPTOR
*MemoryTable
,
395 OUT VOID
**TranslationTableBase OPTIONAL
,
396 OUT UINTN
*TranslationTableSize OPTIONAL
407 ArmSwitchProcessorMode (
408 IN ARM_PROCESSOR_MODE Mode
419 ArmEnableBranchPrediction (
425 ArmDisableBranchPrediction (
443 ArmDataMemoryBarrier (
449 ArmDataSyncronizationBarrier (
455 ArmInstructionSynchronizationBarrier (
547 IN UINT32 SetWayFormat
559 IN UINT32 VectorMonitorBase
577 IN UINTN HypModeVectorBase
580 #endif // __ARM_LIB__