blob: b874b29c672a21aba6a6d37afc00be7f58e6fbbb [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// 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)
130
131ARM_CACHE_TYPE
132EFIAPI
133ArmCacheType (
134 VOID
135 );
136
137ARM_CACHE_ARCHITECTURE
138EFIAPI
139ArmCacheArchitecture (
140 VOID
141 );
142
143VOID
144EFIAPI
145ArmCacheInformation (
146 OUT ARM_CACHE_INFO *CacheInfo
147 );
148
149BOOLEAN
150EFIAPI
151ArmDataCachePresent (
152 VOID
153 );
154
155UINTN
156EFIAPI
157ArmDataCacheSize (
158 VOID
159 );
160
161UINTN
162EFIAPI
163ArmDataCacheAssociativity (
164 VOID
165 );
166
167UINTN
168EFIAPI
169ArmDataCacheLineLength (
170 VOID
171 );
172
173BOOLEAN
174EFIAPI
175ArmInstructionCachePresent (
176 VOID
177 );
178
179UINTN
180EFIAPI
181ArmInstructionCacheSize (
182 VOID
183 );
184
185UINTN
186EFIAPI
187ArmInstructionCacheAssociativity (
188 VOID
189 );
190
191UINTN
192EFIAPI
193ArmInstructionCacheLineLength (
194 VOID
195 );
Olivier Martin168d7242013-11-28 21:37:36 +0000196
197UINTN
198EFIAPI
199ArmIsArchTimerImplemented (
200 VOID
201 );
202
203UINTN
204EFIAPI
205ArmReadIdPfr0 (
206 VOID
207 );
208
209UINTN
210EFIAPI
211ArmReadIdPfr1 (
212 VOID
213 );
214
oliviermartin1e57a462013-01-25 11:28:06 +0000215UINT32
216EFIAPI
217Cp15IdCode (
218 VOID
219 );
220
221UINT32
222EFIAPI
223Cp15CacheInfo (
224 VOID
225 );
226
227BOOLEAN
228EFIAPI
229ArmIsMpCore (
230 VOID
231 );
232
233VOID
234EFIAPI
235ArmInvalidateDataCache (
236 VOID
237 );
238
239
240VOID
241EFIAPI
242ArmCleanInvalidateDataCache (
243 VOID
244 );
245
246VOID
247EFIAPI
248ArmCleanDataCache (
249 VOID
250 );
251
252VOID
253EFIAPI
254ArmCleanDataCacheToPoU (
255 VOID
256 );
257
258VOID
259EFIAPI
260ArmInvalidateInstructionCache (
261 VOID
262 );
263
264VOID
265EFIAPI
266ArmInvalidateDataCacheEntryByMVA (
267 IN UINTN Address
268 );
269
270VOID
271EFIAPI
272ArmCleanDataCacheEntryByMVA (
273 IN UINTN Address
274 );
275
276VOID
277EFIAPI
278ArmCleanInvalidateDataCacheEntryByMVA (
279 IN UINTN Address
280 );
281
282VOID
283EFIAPI
284ArmEnableDataCache (
285 VOID
286 );
287
288VOID
289EFIAPI
290ArmDisableDataCache (
291 VOID
292 );
293
294VOID
295EFIAPI
296ArmEnableInstructionCache (
297 VOID
298 );
299
300VOID
301EFIAPI
302ArmDisableInstructionCache (
303 VOID
304 );
305
306VOID
307EFIAPI
308ArmEnableMmu (
309 VOID
310 );
311
312VOID
313EFIAPI
314ArmDisableMmu (
315 VOID
316 );
317
318VOID
319EFIAPI
320ArmDisableCachesAndMmu (
321 VOID
322 );
323
324VOID
325EFIAPI
326ArmInvalidateInstructionAndDataTlb (
327 VOID
328 );
329
330VOID
331EFIAPI
332ArmEnableInterrupts (
333 VOID
334 );
335
336UINTN
337EFIAPI
338ArmDisableInterrupts (
339 VOID
340 );
oliviermartin47585ed2013-01-25 11:52:14 +0000341
oliviermartin1e57a462013-01-25 11:28:06 +0000342BOOLEAN
343EFIAPI
344ArmGetInterruptState (
345 VOID
346 );
347
oliviermartin47585ed2013-01-25 11:52:14 +0000348UINTN
349EFIAPI
350ArmDisableIrq (
351 VOID
352 );
353
354VOID
355EFIAPI
356ArmEnableIrq (
357 VOID
358 );
359
oliviermartin1e57a462013-01-25 11:28:06 +0000360VOID
361EFIAPI
362ArmEnableFiq (
363 VOID
364 );
365
366UINTN
367EFIAPI
368ArmDisableFiq (
369 VOID
370 );
371
372BOOLEAN
373EFIAPI
374ArmGetFiqState (
375 VOID
376 );
377
378VOID
379EFIAPI
380ArmInvalidateTlb (
381 VOID
382 );
383
384VOID
385EFIAPI
386ArmUpdateTranslationTableEntry (
387 IN VOID *TranslationTableEntry,
388 IN VOID *Mva
389 );
390
391VOID
392EFIAPI
393ArmSetDomainAccessControl (
394 IN UINT32 Domain
395 );
396
397VOID
398EFIAPI
399ArmSetTTBR0 (
400 IN VOID *TranslationTableBase
401 );
402
403VOID *
404EFIAPI
405ArmGetTTBR0BaseAddress (
406 VOID
407 );
408
Olivier Martin6f050ad2013-06-27 18:16:06 +0000409RETURN_STATUS
oliviermartin1e57a462013-01-25 11:28:06 +0000410EFIAPI
411ArmConfigureMmu (
412 IN ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable,
Olivier Martin6f050ad2013-06-27 18:16:06 +0000413 OUT VOID **TranslationTableBase OPTIONAL,
oliviermartin1e57a462013-01-25 11:28:06 +0000414 OUT UINTN *TranslationTableSize OPTIONAL
415 );
416
417BOOLEAN
418EFIAPI
419ArmMmuEnabled (
420 VOID
421 );
422
423VOID
424EFIAPI
425ArmSwitchProcessorMode (
426 IN ARM_PROCESSOR_MODE Mode
427 );
428
429ARM_PROCESSOR_MODE
430EFIAPI
431ArmProcessorMode (
432 VOID
433 );
434
435VOID
436EFIAPI
437ArmEnableBranchPrediction (
438 VOID
439 );
440
441VOID
442EFIAPI
443ArmDisableBranchPrediction (
444 VOID
445 );
446
447VOID
448EFIAPI
449ArmSetLowVectors (
450 VOID
451 );
452
453VOID
454EFIAPI
455ArmSetHighVectors (
456 VOID
457 );
458
459VOID
460EFIAPI
461ArmDataMemoryBarrier (
462 VOID
463 );
464
465VOID
466EFIAPI
467ArmDataSyncronizationBarrier (
468 VOID
469 );
470
471VOID
472EFIAPI
473ArmInstructionSynchronizationBarrier (
474 VOID
475 );
476
477VOID
478EFIAPI
479ArmWriteVBar (
Olivier Martin4e57d6d2014-02-05 12:53:09 +0000480 IN UINTN VectorBase
oliviermartin1e57a462013-01-25 11:28:06 +0000481 );
482
Olivier Martin4e57d6d2014-02-05 12:53:09 +0000483UINTN
oliviermartin1e57a462013-01-25 11:28:06 +0000484EFIAPI
485ArmReadVBar (
486 VOID
487 );
488
489VOID
490EFIAPI
491ArmWriteAuxCr (
492 IN UINT32 Bit
493 );
494
495UINT32
496EFIAPI
497ArmReadAuxCr (
498 VOID
499 );
500
501VOID
502EFIAPI
503ArmSetAuxCrBit (
504 IN UINT32 Bits
505 );
506
507VOID
508EFIAPI
509ArmUnsetAuxCrBit (
510 IN UINT32 Bits
511 );
512
513VOID
514EFIAPI
515ArmCallSEV (
516 VOID
517 );
518
519VOID
520EFIAPI
521ArmCallWFE (
522 VOID
523 );
524
525VOID
526EFIAPI
527ArmCallWFI (
Harry Liebel25402f52013-07-18 18:07:46 +0000528
oliviermartin1e57a462013-01-25 11:28:06 +0000529 VOID
530 );
531
532UINTN
533EFIAPI
534ArmReadMpidr (
535 VOID
536 );
537
538UINT32
539EFIAPI
540ArmReadCpacr (
541 VOID
542 );
543
544VOID
545EFIAPI
546ArmWriteCpacr (
547 IN UINT32 Access
548 );
549
550VOID
551EFIAPI
552ArmEnableVFP (
553 VOID
554 );
555
556UINT32
557EFIAPI
oliviermartin1e57a462013-01-25 11:28:06 +0000558ArmReadScr (
559 VOID
560 );
561
562VOID
563EFIAPI
564ArmWriteScr (
565 IN UINT32 SetWayFormat
566 );
567
568UINT32
569EFIAPI
570ArmReadMVBar (
571 VOID
572 );
573
574VOID
575EFIAPI
576ArmWriteMVBar (
577 IN UINT32 VectorMonitorBase
578 );
579
580UINT32
581EFIAPI
582ArmReadSctlr (
583 VOID
584 );
585
oliviermartin5ea2c2d2013-03-12 00:59:46 +0000586UINTN
587EFIAPI
588ArmReadHVBar (
589 VOID
590 );
591
592VOID
593EFIAPI
594ArmWriteHVBar (
595 IN UINTN HypModeVectorBase
596 );
597
oliviermartin1e57a462013-01-25 11:28:06 +0000598#endif // __ARM_LIB__