// Read system registerUINT64ArmReadSctlrEl1(VOID){UINT64Value;asmvolatile("mrs %0, sctlr_el1":"=r"(Value));returnValue;}// Write system registerVOIDArmWriteVbarEl1(INUINT64VectorBase){asmvolatile("msr vbar_el1, %0"::"r"(VectorBase));asmvolatile("isb");}// EDK2 library functions (ArmLib)#include<Library/ArmLib.h>UINT64Sctlr=ArmReadSctlr();ArmWriteVbar(VectorBase);ArmDisableInterrupts();ArmEnableInterrupts();ArmDisableCachesAndMmu();ArmEnableDataCache();ArmEnableInstructionCache();ArmEnableMmu();ArmInvalidateTlb();
PSCI (Power State Coordination Interface)
Function IDs
Function
SMC32 ID
SMC64 ID
Description
PSCI_VERSION
0x84000000
-
Get PSCI version
CPU_SUSPEND
0x84000001
0xC4000001
Suspend CPU
CPU_OFF
0x84000002
-
Turn off CPU
CPU_ON
0x84000003
0xC4000003
Turn on CPU
AFFINITY_INFO
0x84000004
0xC4000004
Get CPU state
MIGRATE
0x84000005
0xC4000005
Migrate trusted OS
SYSTEM_OFF
0x84000008
-
System shutdown
SYSTEM_RESET
0x84000009
-
System reset
SYSTEM_RESET2
0x84000012
0xC4000012
Reset with type
FEATURES
0x8400000A
-
Query features
CPU_FREEZE
0x8400000B
-
Freeze CPU
CPU_DEFAULT_SUSPEND
0x8400000C
0xC400000C
Default suspend
SYSTEM_SUSPEND
0x8400000E
0xC400000E
System suspend
PSCI_STAT_RESIDENCY
0x84000010
0xC4000010
Stat residency
PSCI_STAT_COUNT
0x84000011
0xC4000011
Stat count
Return Values
Value
Meaning
0 (PSCI_SUCCESS)
Success
-1 (PSCI_E_NOT_SUPPORTED)
Not supported
-2 (PSCI_E_INVALID_PARAMS)
Invalid parameters
-3 (PSCI_E_DENIED)
Denied
-4 (PSCI_E_ALREADY_ON)
Already on
-5 (PSCI_E_ON_PENDING)
On pending
-6 (PSCI_E_INTERN_FAIL)
Internal failure
-7 (PSCI_E_NOT_PRESENT)
Not present
-8 (PSCI_E_DISABLED)
Disabled
-9 (PSCI_E_INVALID_ADDRESS)
Invalid address
PSCI Usage Examples
#include<IndustryStandard/ArmStdSmc.h>
#include<Library/ArmSmcLib.h>// Call PSCI via SMCARM_SMC_ARGSSmcArgs;// Get PSCI versionSmcArgs.Arg0=ARM_SMC_ID_PSCI_VERSION;ArmCallSmc(&SmcArgs);UINT32Version=SmcArgs.Arg0;// 0x00010001 = v1.1// CPU_ON - Start secondary CPUSmcArgs.Arg0=ARM_SMC_ID_PSCI_CPU_ON_AARCH64;SmcArgs.Arg1=TargetMpidr;// Target CPU MPIDRSmcArgs.Arg2=EntryPoint;// Entry point addressSmcArgs.Arg3=ContextId;// Context (passed to CPU)ArmCallSmc(&SmcArgs);if(SmcArgs.Arg0!=PSCI_SUCCESS){// Handle error}// System resetSmcArgs.Arg0=ARM_SMC_ID_PSCI_SYSTEM_RESET;ArmCallSmc(&SmcArgs);// Does not return
GIC (Generic Interrupt Controller)
GIC Registers
Distributor (GICD)
Register
Offset
Description
GICD_CTLR
0x0000
Distributor Control
GICD_TYPER
0x0004
Interrupt Controller Type
GICD_IIDR
0x0008
Implementer Identification
GICD_IGROUPRn
0x0080
Interrupt Group (GICv2)
GICD_ISENABLERn
0x0100
Interrupt Set-Enable
GICD_ICENABLERn
0x0180
Interrupt Clear-Enable
GICD_ISPENDRn
0x0200
Interrupt Set-Pending
GICD_ICPENDRn
0x0280
Interrupt Clear-Pending
GICD_IPRIORITYRn
0x0400
Interrupt Priority
GICD_ITARGETSRn
0x0800
Interrupt Targets (GICv2)
GICD_ICFGRn
0x0C00
Interrupt Configuration
GICD_IROUTERn
0x6100
Interrupt Routing (GICv3)
Redistributor (GICR) - GICv3+
Register
Offset
Description
GICR_CTLR
0x0000
Redistributor Control
GICR_TYPER
0x0008
Redistributor Type
GICR_WAKER
0x0014
Redistributor Wake
GICR_IGROUPR0
0x10080
SGI/PPI Group
GICR_ISENABLER0
0x10100
SGI/PPI Set-Enable
GICR_ICENABLER0
0x10180
SGI/PPI Clear-Enable
CPU Interface (GICC/ICC)
Register
Description
ICC_PMR_EL1
Priority Mask
ICC_BPR1_EL1
Binary Point
ICC_IAR1_EL1
Interrupt Acknowledge
ICC_EOIR1_EL1
End of Interrupt
ICC_CTLR_EL1
CPU Interface Control
ICC_SRE_EL1
System Register Enable
ICC_IGRPEN1_EL1
Group 1 Enable
Interrupt Types
Type
Range
Description
SGI
0-15
Software Generated Interrupts
PPI
16-31
Private Peripheral Interrupts
SPI
32-1019
Shared Peripheral Interrupts
LPI
8192+
Locality-specific (GICv3)
GIC Configuration Example
#include<Library/ArmGicLib.h>// Initialize GICVOIDInitializeGic(INUINT64GicdBase,INUINT64GicrBase// GICv3 only){// Enable distributorMmioWrite32(GicdBase+GICD_CTLR,GICD_CTLR_ARE_S|GICD_CTLR_ARE_NS|GICD_CTLR_ENABLE_GRP1_NS);// For each SPI (32+)for(UINT32IntId=32;IntId<MaxIntId;IntId++){// Set priorityMmioWrite8(GicdBase+GICD_IPRIORITYR+IntId,0xA0);// Route to this CPU (GICv3)MmioWrite64(GicdBase+GICD_IROUTER+IntId*8,ArmReadMpidr()&0xFFFFFF);// Enable interruptMmioWrite32(GicdBase+GICD_ISENABLER+(IntId/32)*4,1<<(IntId%32));}// Enable CPU interface (GICv3 system registers)ArmGicV3SetPriorityMask(0xFF);ArmGicV3SetBinaryPointer(0);ArmGicV3EnableInterruptInterface();}// Handle interruptVOIDHandleInterrupt(VOID){UINT32IntId=ArmGicV3AcknowledgeInterrupt();if(IntId<1020){// Handle the interruptProcessInterrupt(IntId);// Signal end of interruptArmGicV3EndOfInterrupt(IntId);}}
ARM ACPI Tables
Required Tables for ARM
Table
Description
Key Contents
RSDP
Root System Description Pointer
XSDT address
XSDT
Extended System Description Table
Pointers to other tables
FADT
Fixed ACPI Description Table
PSCI info, hardware model
MADT
Multiple APIC Description Table
GIC structures
GTDT
Generic Timer Description Table
Timer info
DSDT
Differentiated System Description
Device tree in AML
DBG2
Debug Port Table 2
Debug console
SPCR
Serial Port Console Redirection
Serial console
PPTT
Processor Properties Topology
Cache hierarchy
IORT
IO Remapping Table
SMMU mappings
MCFG
PCI Express Config
ECAM base
MADT GIC Structures
// GIC Distributortypedefstruct{UINT8Type;// 12UINT8Length;// 24UINT16Reserved1;UINT32GicId;UINT64PhysicalBaseAddress;UINT32SystemVectorBase;UINT8GicVersion;// 3 for GICv3UINT8Reserved2[3];}EFI_ACPI_6_3_GICD_STRUCTURE;// GIC CPU Interfacetypedefstruct{UINT8Type;// 11UINT8Length;// 80UINT16Reserved;UINT32CpuInterfaceNumber;UINT32AcpiProcessorUid;UINT32Flags;UINT32ParkingProtocolVersion;UINT32PerformanceInterruptGsiv;UINT64ParkedAddress;UINT64PhysicalBaseAddress;// GICCUINT64GICV;UINT64GICH;UINT32VGICMaintenanceInterrupt;UINT64GICRBaseAddress;// GICv3UINT64MPIDR;UINT8ProcessorPowerEfficiencyClass;UINT8Reserved2;UINT16SpeOverflowInterrupt;}EFI_ACPI_6_3_GIC_STRUCTURE;// GIC Redistributor (GICv3)typedefstruct{UINT8Type;// 14UINT8Length;// 16UINT16Reserved;UINT64DiscoveryRangeBaseAddress;UINT32DiscoveryRangeLength;}EFI_ACPI_6_3_GICR_STRUCTURE;// GIC ITS (GICv3)typedefstruct{UINT8Type;// 15UINT8Length;// 20UINT16Reserved1;UINT32GicItsId;UINT64PhysicalBaseAddress;UINT32Reserved2;}EFI_ACPI_6_3_GIC_ITS_STRUCTURE;