blob: 526b06a5caae958ede01ef276f0d52dcc23b8e38 [file] [log] [blame]
oliviermartin1e57a462013-01-25 11:28:06 +00001/** @file
2
3 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
Olivier Martin4e57d6d2014-02-05 12:53:09 +00004 Copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.<BR>
oliviermartin1e57a462013-01-25 11:28:06 +00005
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
10
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.
13
14**/
15
16#ifndef __ARM_LIB__
17#define __ARM_LIB__
18
19#include <Uefi/UefiBaseType.h>
20
Harry Liebel25402f52013-07-18 18:07:46 +000021#ifdef MDE_CPU_ARM
22 #ifdef ARM_CPU_ARMv6
23 #include <Chipset/ARM1176JZ-S.h>
24 #else
25 #include <Chipset/ArmV7.h>
26 #endif
27#elif defined(MDE_CPU_AARCH64)
28 #include <Chipset/AArch64.h>
oliviermartin1e57a462013-01-25 11:28:06 +000029#else
Harry Liebel25402f52013-07-18 18:07:46 +000030 #error "Unknown chipset."
oliviermartin1e57a462013-01-25 11:28:06 +000031#endif
32
33typedef enum {
34 ARM_CACHE_TYPE_WRITE_BACK,
35 ARM_CACHE_TYPE_UNKNOWN
36} ARM_CACHE_TYPE;
37
38typedef enum {
39 ARM_CACHE_ARCHITECTURE_UNIFIED,
40 ARM_CACHE_ARCHITECTURE_SEPARATE,
41 ARM_CACHE_ARCHITECTURE_UNKNOWN
42} ARM_CACHE_ARCHITECTURE;
43
44typedef struct {
45 ARM_CACHE_TYPE Type;
46 ARM_CACHE_ARCHITECTURE Architecture;
47 BOOLEAN DataCachePresent;
48 UINTN DataCacheSize;
49 UINTN DataCacheAssociativity;
50 UINTN DataCacheLineLength;
51 BOOLEAN InstructionCachePresent;
52 UINTN InstructionCacheSize;
53 UINTN InstructionCacheAssociativity;
54 UINTN InstructionCacheLineLength;
55} ARM_CACHE_INFO;
56
57/**
58 * The UEFI firmware must not use the ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_* attributes.
59 *
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.
62 */
63typedef enum {
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;
73
74#define IS_ARM_MEMORY_REGION_ATTRIBUTES_SECURE(attr) ((UINT32)(attr) & 1)
75
76typedef struct {
77 EFI_PHYSICAL_ADDRESS PhysicalBase;
78 EFI_VIRTUAL_ADDRESS VirtualBase;
Olivier Martinc357fd62014-01-10 11:27:31 +000079 UINT64 Length;
oliviermartin1e57a462013-01-25 11:28:06 +000080 ARM_MEMORY_REGION_ATTRIBUTES Attributes;
81} ARM_MEMORY_REGION_DESCRIPTOR;
82
83typedef VOID (*CACHE_OPERATION)(VOID);
84typedef VOID (*LINE_OPERATION)(UINTN);
85
86//
87// ARM Processor Mode
88//
89typedef enum {
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
99} ARM_PROCESSOR_MODE;
100
101//
102// ARM Cpu IDs
103//
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)
110
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)
117
118//
119// ARM MP Core IDs
120//
oliviermartin1e57a462013-01-25 11:28:06 +0000121#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)
oliviermartine3595652013-05-12 23:56:35 +0000125#define GET_MPID(ClusterId, CoreId) (((ClusterId) << 8) | (CoreId))
oliviermartin1e57a462013-01-25 11:28:06 +0000126#define PRIMARY_CORE_ID (PcdGet32(PcdArmPrimaryCore) & ARM_CORE_MASK)
127
128ARM_CACHE_TYPE
129EFIAPI
130ArmCacheType (
131 VOID
132 );
133
134ARM_CACHE_ARCHITECTURE
135EFIAPI
136ArmCacheArchitecture (
137 VOID
138 );
139
140VOID
141EFIAPI
142ArmCacheInformation (
143 OUT ARM_CACHE_INFO *CacheInfo
144 );
145
146BOOLEAN
147EFIAPI
148ArmDataCachePresent (
149 VOID
150 );
Ronald Cron3402aac2014-08-19 13:29:52 +0000151
oliviermartin1e57a462013-01-25 11:28:06 +0000152UINTN
153EFIAPI
154ArmDataCacheSize (
155 VOID
156 );
Ronald Cron3402aac2014-08-19 13:29:52 +0000157
oliviermartin1e57a462013-01-25 11:28:06 +0000158UINTN
159EFIAPI
160ArmDataCacheAssociativity (
161 VOID
162 );
Ronald Cron3402aac2014-08-19 13:29:52 +0000163
oliviermartin1e57a462013-01-25 11:28:06 +0000164UINTN
165EFIAPI
166ArmDataCacheLineLength (
167 VOID
168 );
Ronald Cron3402aac2014-08-19 13:29:52 +0000169
oliviermartin1e57a462013-01-25 11:28:06 +0000170BOOLEAN
171EFIAPI
172ArmInstructionCachePresent (
173 VOID
174 );
Ronald Cron3402aac2014-08-19 13:29:52 +0000175
oliviermartin1e57a462013-01-25 11:28:06 +0000176UINTN
177EFIAPI
178ArmInstructionCacheSize (
179 VOID
180 );
Ronald Cron3402aac2014-08-19 13:29:52 +0000181
oliviermartin1e57a462013-01-25 11:28:06 +0000182UINTN
183EFIAPI
184ArmInstructionCacheAssociativity (
185 VOID
186 );
Ronald Cron3402aac2014-08-19 13:29:52 +0000187
oliviermartin1e57a462013-01-25 11:28:06 +0000188UINTN
189EFIAPI
190ArmInstructionCacheLineLength (
191 VOID
192 );
Olivier Martin168d7242013-11-28 21:37:36 +0000193
194UINTN
195EFIAPI
196ArmIsArchTimerImplemented (
197 VOID
198 );
199
200UINTN
201EFIAPI
202ArmReadIdPfr0 (
203 VOID
204 );
205
206UINTN
207EFIAPI
208ArmReadIdPfr1 (
209 VOID
210 );
211
Olivier Martin64751722014-03-24 15:26:22 +0000212UINTN
oliviermartin1e57a462013-01-25 11:28:06 +0000213EFIAPI
Olivier Martin64751722014-03-24 15:26:22 +0000214ArmCacheInfo (
oliviermartin1e57a462013-01-25 11:28:06 +0000215 VOID
216 );
217
218BOOLEAN
219EFIAPI
220ArmIsMpCore (
221 VOID
222 );
223
224VOID
225EFIAPI
226ArmInvalidateDataCache (
227 VOID
228 );
229
230
231VOID
232EFIAPI
233ArmCleanInvalidateDataCache (
234 VOID
235 );
236
237VOID
238EFIAPI
239ArmCleanDataCache (
240 VOID
241 );
242
243VOID
244EFIAPI
245ArmCleanDataCacheToPoU (
246 VOID
247 );
248
249VOID
250EFIAPI
251ArmInvalidateInstructionCache (
252 VOID
253 );
254
255VOID
256EFIAPI
257ArmInvalidateDataCacheEntryByMVA (
258 IN UINTN Address
259 );
260
261VOID
262EFIAPI
263ArmCleanDataCacheEntryByMVA (
264 IN UINTN Address
265 );
266
267VOID
268EFIAPI
269ArmCleanInvalidateDataCacheEntryByMVA (
270 IN UINTN Address
271 );
272
273VOID
274EFIAPI
Olivier Martin0ff0e412014-03-01 10:57:09 +0000275ArmInvalidateDataCacheEntryBySetWay (
276 IN UINTN SetWayFormat
277 );
278
279VOID
280EFIAPI
281ArmCleanDataCacheEntryBySetWay (
282 IN UINTN SetWayFormat
283 );
284
285VOID
286EFIAPI
287ArmCleanInvalidateDataCacheEntryBySetWay (
288 IN UINTN SetWayFormat
289 );
290
291VOID
292EFIAPI
oliviermartin1e57a462013-01-25 11:28:06 +0000293ArmEnableDataCache (
294 VOID
295 );
296
297VOID
298EFIAPI
299ArmDisableDataCache (
300 VOID
301 );
302
303VOID
304EFIAPI
305ArmEnableInstructionCache (
306 VOID
307 );
308
309VOID
310EFIAPI
311ArmDisableInstructionCache (
312 VOID
313 );
Ronald Cron3402aac2014-08-19 13:29:52 +0000314
oliviermartin1e57a462013-01-25 11:28:06 +0000315VOID
316EFIAPI
317ArmEnableMmu (
318 VOID
319 );
320
321VOID
322EFIAPI
323ArmDisableMmu (
324 VOID
325 );
326
327VOID
328EFIAPI
Olivier Martin0ff0e412014-03-01 10:57:09 +0000329ArmEnableCachesAndMmu (
330 VOID
331 );
332
333VOID
334EFIAPI
oliviermartin1e57a462013-01-25 11:28:06 +0000335ArmDisableCachesAndMmu (
336 VOID
337 );
338
339VOID
340EFIAPI
oliviermartin1e57a462013-01-25 11:28:06 +0000341ArmEnableInterrupts (
342 VOID
343 );
344
345UINTN
346EFIAPI
347ArmDisableInterrupts (
348 VOID
349 );
oliviermartin47585ed2013-01-25 11:52:14 +0000350
oliviermartin1e57a462013-01-25 11:28:06 +0000351BOOLEAN
352EFIAPI
353ArmGetInterruptState (
354 VOID
355 );
356
Olivier Martin0ff0e412014-03-01 10:57:09 +0000357VOID
358EFIAPI
359ArmEnableAsynchronousAbort (
360 VOID
361 );
362
oliviermartin47585ed2013-01-25 11:52:14 +0000363UINTN
364EFIAPI
Olivier Martin0ff0e412014-03-01 10:57:09 +0000365ArmDisableAsynchronousAbort (
oliviermartin47585ed2013-01-25 11:52:14 +0000366 VOID
367 );
368
369VOID
370EFIAPI
371ArmEnableIrq (
372 VOID
373 );
374
Olivier Martin0ff0e412014-03-01 10:57:09 +0000375UINTN
376EFIAPI
377ArmDisableIrq (
378 VOID
379 );
380
oliviermartin1e57a462013-01-25 11:28:06 +0000381VOID
382EFIAPI
383ArmEnableFiq (
384 VOID
385 );
386
387UINTN
388EFIAPI
389ArmDisableFiq (
390 VOID
391 );
Ronald Cron3402aac2014-08-19 13:29:52 +0000392
oliviermartin1e57a462013-01-25 11:28:06 +0000393BOOLEAN
394EFIAPI
395ArmGetFiqState (
396 VOID
397 );
398
Olivier Martin8dd618d2014-10-27 15:38:55 +0000399/**
400 * Invalidate Data and Instruction TLBs
401 */
oliviermartin1e57a462013-01-25 11:28:06 +0000402VOID
403EFIAPI
404ArmInvalidateTlb (
405 VOID
406 );
Ronald Cron3402aac2014-08-19 13:29:52 +0000407
oliviermartin1e57a462013-01-25 11:28:06 +0000408VOID
409EFIAPI
410ArmUpdateTranslationTableEntry (
411 IN VOID *TranslationTableEntry,
412 IN VOID *Mva
413 );
Ronald Cron3402aac2014-08-19 13:29:52 +0000414
oliviermartin1e57a462013-01-25 11:28:06 +0000415VOID
416EFIAPI
417ArmSetDomainAccessControl (
418 IN UINT32 Domain
419 );
420
421VOID
422EFIAPI
423ArmSetTTBR0 (
424 IN VOID *TranslationTableBase
425 );
426
427VOID *
428EFIAPI
429ArmGetTTBR0BaseAddress (
430 VOID
431 );
432
Olivier Martin6f050ad2013-06-27 18:16:06 +0000433RETURN_STATUS
oliviermartin1e57a462013-01-25 11:28:06 +0000434EFIAPI
435ArmConfigureMmu (
436 IN ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable,
Olivier Martin6f050ad2013-06-27 18:16:06 +0000437 OUT VOID **TranslationTableBase OPTIONAL,
oliviermartin1e57a462013-01-25 11:28:06 +0000438 OUT UINTN *TranslationTableSize OPTIONAL
439 );
Ronald Cron3402aac2014-08-19 13:29:52 +0000440
oliviermartin1e57a462013-01-25 11:28:06 +0000441BOOLEAN
442EFIAPI
443ArmMmuEnabled (
444 VOID
445 );
Ronald Cron3402aac2014-08-19 13:29:52 +0000446
oliviermartin1e57a462013-01-25 11:28:06 +0000447VOID
448EFIAPI
oliviermartin1e57a462013-01-25 11:28:06 +0000449ArmEnableBranchPrediction (
450 VOID
451 );
452
453VOID
454EFIAPI
455ArmDisableBranchPrediction (
456 VOID
457 );
458
459VOID
460EFIAPI
461ArmSetLowVectors (
462 VOID
463 );
464
465VOID
466EFIAPI
467ArmSetHighVectors (
468 VOID
469 );
470
471VOID
472EFIAPI
Olivier Martin0ff0e412014-03-01 10:57:09 +0000473ArmDrainWriteBuffer (
474 VOID
475 );
476
477VOID
478EFIAPI
oliviermartin1e57a462013-01-25 11:28:06 +0000479ArmDataMemoryBarrier (
480 VOID
481 );
Ronald Cron3402aac2014-08-19 13:29:52 +0000482
oliviermartin1e57a462013-01-25 11:28:06 +0000483VOID
484EFIAPI
485ArmDataSyncronizationBarrier (
486 VOID
487 );
Ronald Cron3402aac2014-08-19 13:29:52 +0000488
oliviermartin1e57a462013-01-25 11:28:06 +0000489VOID
490EFIAPI
491ArmInstructionSynchronizationBarrier (
492 VOID
493 );
494
495VOID
496EFIAPI
497ArmWriteVBar (
Olivier Martin4e57d6d2014-02-05 12:53:09 +0000498 IN UINTN VectorBase
oliviermartin1e57a462013-01-25 11:28:06 +0000499 );
500
Olivier Martin4e57d6d2014-02-05 12:53:09 +0000501UINTN
oliviermartin1e57a462013-01-25 11:28:06 +0000502EFIAPI
503ArmReadVBar (
504 VOID
505 );
506
507VOID
508EFIAPI
509ArmWriteAuxCr (
510 IN UINT32 Bit
511 );
512
513UINT32
514EFIAPI
515ArmReadAuxCr (
516 VOID
517 );
518
519VOID
520EFIAPI
521ArmSetAuxCrBit (
522 IN UINT32 Bits
523 );
524
525VOID
526EFIAPI
527ArmUnsetAuxCrBit (
528 IN UINT32 Bits
529 );
530
531VOID
532EFIAPI
533ArmCallSEV (
534 VOID
535 );
536
537VOID
538EFIAPI
539ArmCallWFE (
540 VOID
541 );
542
543VOID
544EFIAPI
545ArmCallWFI (
Harry Liebel25402f52013-07-18 18:07:46 +0000546
oliviermartin1e57a462013-01-25 11:28:06 +0000547 VOID
548 );
549
550UINTN
551EFIAPI
552ArmReadMpidr (
553 VOID
554 );
555
Olivier Martin9401d6f2014-02-12 15:14:41 +0000556UINTN
557EFIAPI
558ArmReadMidr (
559 VOID
560 );
561
oliviermartin1e57a462013-01-25 11:28:06 +0000562UINT32
563EFIAPI
564ArmReadCpacr (
565 VOID
566 );
567
568VOID
569EFIAPI
570ArmWriteCpacr (
571 IN UINT32 Access
572 );
573
574VOID
575EFIAPI
576ArmEnableVFP (
577 VOID
578 );
579
Olivier Martin46d4d752014-07-29 14:10:45 +0000580/**
581 Get the Secure Configuration Register value
582
583 @return Value read from the Secure Configuration Register
584
585**/
oliviermartin1e57a462013-01-25 11:28:06 +0000586UINT32
587EFIAPI
oliviermartin1e57a462013-01-25 11:28:06 +0000588ArmReadScr (
589 VOID
590 );
591
Olivier Martin46d4d752014-07-29 14:10:45 +0000592/**
593 Set the Secure Configuration Register
594
595 @param Value Value to write to the Secure Configuration Register
596
597**/
oliviermartin1e57a462013-01-25 11:28:06 +0000598VOID
599EFIAPI
600ArmWriteScr (
Olivier Martin46d4d752014-07-29 14:10:45 +0000601 IN UINT32 Value
oliviermartin1e57a462013-01-25 11:28:06 +0000602 );
603
604UINT32
605EFIAPI
606ArmReadMVBar (
607 VOID
608 );
609
610VOID
611EFIAPI
612ArmWriteMVBar (
613 IN UINT32 VectorMonitorBase
614 );
615
616UINT32
617EFIAPI
618ArmReadSctlr (
619 VOID
620 );
621
oliviermartin5ea2c2d2013-03-12 00:59:46 +0000622UINTN
623EFIAPI
624ArmReadHVBar (
625 VOID
626 );
627
628VOID
629EFIAPI
630ArmWriteHVBar (
631 IN UINTN HypModeVectorBase
632 );
633
Olivier Martin52d44f72014-03-26 19:31:01 +0000634
635//
636// Helper functions for accessing CPU ACTLR
637//
638
639UINTN
640EFIAPI
641ArmReadCpuActlr (
642 VOID
643 );
644
645VOID
646EFIAPI
647ArmWriteCpuActlr (
648 IN UINTN Val
649 );
650
651VOID
652EFIAPI
653ArmSetCpuActlrBit (
654 IN UINTN Bits
655 );
656
657VOID
658EFIAPI
659ArmUnsetCpuActlrBit (
660 IN UINTN Bits
661 );
662
oliviermartin1e57a462013-01-25 11:28:06 +0000663#endif // __ARM_LIB__