VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/ArmPkg/Include/Library/ArmLib.h@ 105670

Last change on this file since 105670 was 105670, checked in by vboxsync, 6 months ago

Devices/EFI/FirmwareNew: Merge edk2-stable-202405 and make it build on aarch64, bugref:4643

  • Property svn:eol-style set to native
File size: 10.9 KB
Line 
1/** @file
2
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 - 2021, NUVIA Inc. All rights reserved.<BR>
6
7 SPDX-License-Identifier: BSD-2-Clause-Patent
8
9**/
10
11#ifndef ARM_LIB_H_
12#define ARM_LIB_H_
13
14#include <Uefi/UefiBaseType.h>
15
16#ifdef MDE_CPU_ARM
17 #include <Chipset/ArmV7.h>
18#elif defined (MDE_CPU_AARCH64)
19 #include <Chipset/AArch64.h>
20#else
21 #error "Unknown chipset."
22#endif
23
24#define EFI_MEMORY_CACHETYPE_MASK (EFI_MEMORY_UC | EFI_MEMORY_WC | \
25 EFI_MEMORY_WT | EFI_MEMORY_WB | \
26 EFI_MEMORY_UCE)
27
28typedef enum {
29 ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED = 0,
30 ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK,
31
32 // On some platforms, memory mapped flash region is designed as not supporting
33 // shareable attribute, so WRITE_BACK_NONSHAREABLE is added for such special
34 // need.
35 // Do NOT use below two attributes if you are not sure.
36 ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK_NONSHAREABLE,
37
38 // Special region types for memory that must be mapped with read-only or
39 // non-execute permissions from the very start, e.g., to support the use
40 // of the WXN virtual memory control.
41 ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK_RO,
42 ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK_XP,
43
44 ARM_MEMORY_REGION_ATTRIBUTE_WRITE_THROUGH,
45 ARM_MEMORY_REGION_ATTRIBUTE_DEVICE,
46} ARM_MEMORY_REGION_ATTRIBUTES;
47
48typedef struct {
49 EFI_PHYSICAL_ADDRESS PhysicalBase;
50 EFI_VIRTUAL_ADDRESS VirtualBase;
51 UINT64 Length;
52 ARM_MEMORY_REGION_ATTRIBUTES Attributes;
53} ARM_MEMORY_REGION_DESCRIPTOR;
54
55typedef VOID (*CACHE_OPERATION)(
56 VOID
57 );
58typedef VOID (*LINE_OPERATION)(
59 UINTN
60 );
61
62//
63// ARM Processor Mode
64//
65typedef enum {
66 ARM_PROCESSOR_MODE_USER = 0x10,
67 ARM_PROCESSOR_MODE_FIQ = 0x11,
68 ARM_PROCESSOR_MODE_IRQ = 0x12,
69 ARM_PROCESSOR_MODE_SUPERVISOR = 0x13,
70 ARM_PROCESSOR_MODE_ABORT = 0x17,
71 ARM_PROCESSOR_MODE_HYP = 0x1A,
72 ARM_PROCESSOR_MODE_UNDEFINED = 0x1B,
73 ARM_PROCESSOR_MODE_SYSTEM = 0x1F,
74 ARM_PROCESSOR_MODE_MASK = 0x1F
75} ARM_PROCESSOR_MODE;
76
77//
78// ARM Cpu IDs
79//
80#define ARM_CPU_IMPLEMENTER_MASK (0xFFU << 24)
81#define ARM_CPU_IMPLEMENTER_ARMLTD (0x41U << 24)
82#define ARM_CPU_IMPLEMENTER_DEC (0x44U << 24)
83#define ARM_CPU_IMPLEMENTER_MOT (0x4DU << 24)
84#define ARM_CPU_IMPLEMENTER_QUALCOMM (0x51U << 24)
85#define ARM_CPU_IMPLEMENTER_MARVELL (0x56U << 24)
86
87#define ARM_CPU_PRIMARY_PART_MASK (0xFFF << 4)
88#define ARM_CPU_PRIMARY_PART_CORTEXA5 (0xC05 << 4)
89#define ARM_CPU_PRIMARY_PART_CORTEXA7 (0xC07 << 4)
90#define ARM_CPU_PRIMARY_PART_CORTEXA8 (0xC08 << 4)
91#define ARM_CPU_PRIMARY_PART_CORTEXA9 (0xC09 << 4)
92#define ARM_CPU_PRIMARY_PART_CORTEXA15 (0xC0F << 4)
93
94//
95// ARM MP Core IDs
96//
97#define ARM_CORE_AFF0 0xFF
98#define ARM_CORE_AFF1 (0xFF << 8)
99#define ARM_CORE_AFF2 (0xFF << 16)
100#define ARM_CORE_AFF3 (0xFFULL << 32)
101
102#define ARM_CORE_MASK ARM_CORE_AFF0
103#define ARM_CLUSTER_MASK ARM_CORE_AFF1
104#define GET_CORE_ID(MpId) ((MpId) & ARM_CORE_MASK)
105#define GET_CLUSTER_ID(MpId) (((MpId) & ARM_CLUSTER_MASK) >> 8)
106#define GET_MPID(ClusterId, CoreId) (((ClusterId) << 8) | (CoreId))
107#define GET_MPIDR_AFF0(MpId) ((MpId) & ARM_CORE_AFF0)
108#define GET_MPIDR_AFF1(MpId) (((MpId) & ARM_CORE_AFF1) >> 8)
109#define GET_MPIDR_AFF2(MpId) (((MpId) & ARM_CORE_AFF2) >> 16)
110#define GET_MPIDR_AFF3(MpId) (((MpId) & ARM_CORE_AFF3) >> 32)
111#define GET_MPIDR_AFFINITY_BITS(MpId) ((MpId) & 0xFF00FFFFFF)
112#define PRIMARY_CORE_ID (PcdGet32(PcdArmPrimaryCore) & ARM_CORE_MASK)
113#define MPIDR_MT_BIT BIT24
114
115/** Reads the CCSIDR register for the specified cache.
116
117 @param CSSELR The CSSELR cache selection register value.
118
119 @return The contents of the CCSIDR_EL1 register for the specified cache, when in AARCH64 mode.
120 Returns the contents of the CCSIDR register in AARCH32 mode.
121**/
122UINTN
123ReadCCSIDR (
124 IN UINT32 CSSELR
125 );
126
127/** Reads the CCSIDR2 for the specified cache.
128
129 @param CSSELR The CSSELR cache selection register value
130
131 @return The contents of the CCSIDR2 register for the specified cache.
132**/
133UINT32
134ReadCCSIDR2 (
135 IN UINT32 CSSELR
136 );
137
138/** Reads the Cache Level ID (CLIDR) register.
139
140 @return The contents of the CLIDR_EL1 register.
141**/
142UINT32
143ReadCLIDR (
144 VOID
145 );
146
147UINTN
148EFIAPI
149ArmDataCacheLineLength (
150 VOID
151 );
152
153UINTN
154EFIAPI
155ArmInstructionCacheLineLength (
156 VOID
157 );
158
159UINTN
160EFIAPI
161ArmCacheWritebackGranule (
162 VOID
163 );
164
165UINTN
166EFIAPI
167ArmIsArchTimerImplemented (
168 VOID
169 );
170
171UINTN
172EFIAPI
173ArmCacheInfo (
174 VOID
175 );
176
177BOOLEAN
178EFIAPI
179ArmIsMpCore (
180 VOID
181 );
182
183VOID
184EFIAPI
185ArmInvalidateDataCache (
186 VOID
187 );
188
189VOID
190EFIAPI
191ArmCleanInvalidateDataCache (
192 VOID
193 );
194
195VOID
196EFIAPI
197ArmCleanDataCache (
198 VOID
199 );
200
201VOID
202EFIAPI
203ArmInvalidateInstructionCache (
204 VOID
205 );
206
207VOID
208EFIAPI
209ArmInvalidateDataCacheEntryByMVA (
210 IN UINTN Address
211 );
212
213VOID
214EFIAPI
215ArmCleanDataCacheEntryToPoUByMVA (
216 IN UINTN Address
217 );
218
219VOID
220EFIAPI
221ArmInvalidateInstructionCacheEntryToPoUByMVA (
222 IN UINTN Address
223 );
224
225VOID
226EFIAPI
227ArmCleanDataCacheEntryByMVA (
228 IN UINTN Address
229 );
230
231VOID
232EFIAPI
233ArmCleanInvalidateDataCacheEntryByMVA (
234 IN UINTN Address
235 );
236
237VOID
238EFIAPI
239ArmEnableDataCache (
240 VOID
241 );
242
243VOID
244EFIAPI
245ArmDisableDataCache (
246 VOID
247 );
248
249VOID
250EFIAPI
251ArmEnableInstructionCache (
252 VOID
253 );
254
255VOID
256EFIAPI
257ArmDisableInstructionCache (
258 VOID
259 );
260
261VOID
262EFIAPI
263ArmEnableMmu (
264 VOID
265 );
266
267VOID
268EFIAPI
269ArmDisableMmu (
270 VOID
271 );
272
273VOID
274EFIAPI
275ArmEnableCachesAndMmu (
276 VOID
277 );
278
279VOID
280EFIAPI
281ArmDisableCachesAndMmu (
282 VOID
283 );
284
285VOID
286EFIAPI
287ArmEnableInterrupts (
288 VOID
289 );
290
291UINTN
292EFIAPI
293ArmDisableInterrupts (
294 VOID
295 );
296
297BOOLEAN
298EFIAPI
299ArmGetInterruptState (
300 VOID
301 );
302
303VOID
304EFIAPI
305ArmEnableAsynchronousAbort (
306 VOID
307 );
308
309UINTN
310EFIAPI
311ArmDisableAsynchronousAbort (
312 VOID
313 );
314
315VOID
316EFIAPI
317ArmEnableIrq (
318 VOID
319 );
320
321UINTN
322EFIAPI
323ArmDisableIrq (
324 VOID
325 );
326
327VOID
328EFIAPI
329ArmEnableFiq (
330 VOID
331 );
332
333UINTN
334EFIAPI
335ArmDisableFiq (
336 VOID
337 );
338
339BOOLEAN
340EFIAPI
341ArmGetFiqState (
342 VOID
343 );
344
345/**
346 * Invalidate Data and Instruction TLBs
347 */
348VOID
349EFIAPI
350ArmInvalidateTlb (
351 VOID
352 );
353
354VOID
355EFIAPI
356ArmUpdateTranslationTableEntry (
357 IN VOID *TranslationTableEntry,
358 IN VOID *Mva
359 );
360
361VOID
362EFIAPI
363ArmSetDomainAccessControl (
364 IN UINT32 Domain
365 );
366
367VOID
368EFIAPI
369ArmSetTTBR0 (
370 IN VOID *TranslationTableBase
371 );
372
373VOID
374EFIAPI
375ArmSetTTBCR (
376 IN UINT32 Bits
377 );
378
379VOID *
380EFIAPI
381ArmGetTTBR0BaseAddress (
382 VOID
383 );
384
385BOOLEAN
386EFIAPI
387ArmMmuEnabled (
388 VOID
389 );
390
391VOID
392EFIAPI
393ArmEnableBranchPrediction (
394 VOID
395 );
396
397VOID
398EFIAPI
399ArmDisableBranchPrediction (
400 VOID
401 );
402
403VOID
404EFIAPI
405ArmSetLowVectors (
406 VOID
407 );
408
409VOID
410EFIAPI
411ArmSetHighVectors (
412 VOID
413 );
414
415VOID
416EFIAPI
417ArmDataMemoryBarrier (
418 VOID
419 );
420
421VOID
422EFIAPI
423ArmDataSynchronizationBarrier (
424 VOID
425 );
426
427VOID
428EFIAPI
429ArmInstructionSynchronizationBarrier (
430 VOID
431 );
432
433VOID
434EFIAPI
435ArmWriteVBar (
436 IN UINTN VectorBase
437 );
438
439UINTN
440EFIAPI
441ArmReadVBar (
442 VOID
443 );
444
445VOID
446EFIAPI
447ArmWriteAuxCr (
448 IN UINT32 Bit
449 );
450
451UINT32
452EFIAPI
453ArmReadAuxCr (
454 VOID
455 );
456
457VOID
458EFIAPI
459ArmSetAuxCrBit (
460 IN UINT32 Bits
461 );
462
463VOID
464EFIAPI
465ArmUnsetAuxCrBit (
466 IN UINT32 Bits
467 );
468
469VOID
470EFIAPI
471ArmCallSEV (
472 VOID
473 );
474
475VOID
476EFIAPI
477ArmCallWFE (
478 VOID
479 );
480
481VOID
482EFIAPI
483ArmCallWFI (
484
485 VOID
486 );
487
488UINTN
489EFIAPI
490ArmReadMpidr (
491 VOID
492 );
493
494UINTN
495EFIAPI
496ArmReadMidr (
497 VOID
498 );
499
500UINT32
501EFIAPI
502ArmReadCpacr (
503 VOID
504 );
505
506VOID
507EFIAPI
508ArmWriteCpacr (
509 IN UINT32 Access
510 );
511
512VOID
513EFIAPI
514ArmEnableVFP (
515 VOID
516 );
517
518/**
519 Get the Secure Configuration Register value
520
521 @return Value read from the Secure Configuration Register
522
523**/
524UINT32
525EFIAPI
526ArmReadScr (
527 VOID
528 );
529
530/**
531 Set the Secure Configuration Register
532
533 @param Value Value to write to the Secure Configuration Register
534
535**/
536VOID
537EFIAPI
538ArmWriteScr (
539 IN UINT32 Value
540 );
541
542UINT32
543EFIAPI
544ArmReadMVBar (
545 VOID
546 );
547
548VOID
549EFIAPI
550ArmWriteMVBar (
551 IN UINT32 VectorMonitorBase
552 );
553
554UINT32
555EFIAPI
556ArmReadSctlr (
557 VOID
558 );
559
560VOID
561EFIAPI
562ArmWriteSctlr (
563 IN UINT32 Value
564 );
565
566UINTN
567EFIAPI
568ArmReadHVBar (
569 VOID
570 );
571
572VOID
573EFIAPI
574ArmWriteHVBar (
575 IN UINTN HypModeVectorBase
576 );
577
578//
579// Helper functions for accessing CPU ACTLR
580//
581
582UINTN
583EFIAPI
584ArmReadCpuActlr (
585 VOID
586 );
587
588VOID
589EFIAPI
590ArmWriteCpuActlr (
591 IN UINTN Val
592 );
593
594VOID
595EFIAPI
596ArmSetCpuActlrBit (
597 IN UINTN Bits
598 );
599
600VOID
601EFIAPI
602ArmUnsetCpuActlrBit (
603 IN UINTN Bits
604 );
605
606//
607// Accessors for the architected generic timer registers
608//
609
610#define ARM_ARCH_TIMER_ENABLE (1 << 0)
611#define ARM_ARCH_TIMER_IMASK (1 << 1)
612#define ARM_ARCH_TIMER_ISTATUS (1 << 2)
613
614UINTN
615EFIAPI
616ArmReadCntFrq (
617 VOID
618 );
619
620VOID
621EFIAPI
622ArmWriteCntFrq (
623 UINTN FreqInHz
624 );
625
626UINT64
627EFIAPI
628ArmReadCntPct (
629 VOID
630 );
631
632UINTN
633EFIAPI
634ArmReadCntkCtl (
635 VOID
636 );
637
638VOID
639EFIAPI
640ArmWriteCntkCtl (
641 UINTN Val
642 );
643
644UINTN
645EFIAPI
646ArmReadCntpTval (
647 VOID
648 );
649
650VOID
651EFIAPI
652ArmWriteCntpTval (
653 UINTN Val
654 );
655
656UINTN
657EFIAPI
658ArmReadCntpCtl (
659 VOID
660 );
661
662VOID
663EFIAPI
664ArmWriteCntpCtl (
665 UINTN Val
666 );
667
668UINTN
669EFIAPI
670ArmReadCntvTval (
671 VOID
672 );
673
674VOID
675EFIAPI
676ArmWriteCntvTval (
677 UINTN Val
678 );
679
680UINTN
681EFIAPI
682ArmReadCntvCtl (
683 VOID
684 );
685
686VOID
687EFIAPI
688ArmWriteCntvCtl (
689 UINTN Val
690 );
691
692UINT64
693EFIAPI
694ArmReadCntvCt (
695 VOID
696 );
697
698UINT64
699EFIAPI
700ArmReadCntpCval (
701 VOID
702 );
703
704VOID
705EFIAPI
706ArmWriteCntpCval (
707 UINT64 Val
708 );
709
710UINT64
711EFIAPI
712ArmReadCntvCval (
713 VOID
714 );
715
716VOID
717EFIAPI
718ArmWriteCntvCval (
719 UINT64 Val
720 );
721
722UINT64
723EFIAPI
724ArmReadCntvOff (
725 VOID
726 );
727
728VOID
729EFIAPI
730ArmWriteCntvOff (
731 UINT64 Val
732 );
733
734UINTN
735EFIAPI
736ArmGetPhysicalAddressBits (
737 VOID
738 );
739
740///
741/// ID Register Helper functions
742///
743
744/**
745 Check whether the CPU supports the GIC system register interface (any version)
746
747 @return Whether GIC System Register Interface is supported
748
749**/
750BOOLEAN
751EFIAPI
752ArmHasGicSystemRegisters (
753 VOID
754 );
755
756/** Checks if CCIDX is implemented.
757
758 @retval TRUE CCIDX is implemented.
759 @retval FALSE CCIDX is not implemented.
760**/
761BOOLEAN
762EFIAPI
763ArmHasCcidx (
764 VOID
765 );
766
767#ifdef MDE_CPU_AARCH64
768///
769/// AArch64-only ID Register Helper functions
770///
771
772/**
773 Checks whether the CPU implements the Virtualization Host Extensions.
774
775 @retval TRUE FEAT_VHE is implemented.
776 @retval FALSE FEAT_VHE is not mplemented.
777**/
778BOOLEAN
779EFIAPI
780ArmHasVhe (
781 VOID
782 );
783
784/**
785 Checks whether the CPU implements the Trace Buffer Extension.
786
787 @retval TRUE FEAT_TRBE is implemented.
788 @retval FALSE FEAT_TRBE is not mplemented.
789**/
790BOOLEAN
791EFIAPI
792ArmHasTrbe (
793 VOID
794 );
795
796/**
797 Checks whether the CPU implements the Embedded Trace Extension.
798
799 @retval TRUE FEAT_ETE is implemented.
800 @retval FALSE FEAT_ETE is not mplemented.
801**/
802BOOLEAN
803EFIAPI
804ArmHasEte (
805 VOID
806 );
807
808#endif // MDE_CPU_AARCH64
809
810#ifdef MDE_CPU_ARM
811///
812/// AArch32-only ID Register Helper functions
813///
814
815/**
816 Check whether the CPU supports the Security extensions
817
818 @return Whether the Security extensions are implemented
819
820**/
821BOOLEAN
822EFIAPI
823ArmHasSecurityExtensions (
824 VOID
825 );
826
827#endif // MDE_CPU_ARM
828
829#endif // ARM_LIB_H_
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette