Commit Graph

1241 Commits

Author SHA1 Message Date
Ard Biesheuvel 2d2642f483 ArmPkg/ArmGicDxe: Use EOImode 0x0 on GICv3
When re-entering EDK2 from a high level OS such as Linux, the GICv3 may
be configured to use split priority drop and deactivate (EOImode == 1),
whereas EDK2's GICv3 driver assumes the default setting of EOImode == 0.

So clear the EOImode bit explicitly when taking control of the GIC.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
2025-01-17 18:37:27 +00:00
Ard Biesheuvel 81e2cd329e ArmPkg/ArmGic: Rename directory to ArmGicDxe
Now that ArmPkg/Drivers/ArmGic no longer carries a combination of
libraries and DXE drivers, rename the directory to the more idiomatic
ArmPkg/Drivers/ArmGicDxe

Continuous-integration-options: PatchCheck.ignore-multi-package

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
2025-01-17 18:37:27 +00:00
Ard Biesheuvel 9d1a9b426e ArmPkg/ArmGic: Implement GICv3+ version of GIC driver
Most platforms do not require the flexibility of the ordinary GIC
driver, which supports both GICv2 and GICv3+, and decides at runtime
which version to use.

So expose a GICv3+ version, which only supports a GICv3 or newer.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
2025-01-17 18:37:27 +00:00
Ard Biesheuvel 86119ff79e ArmPkg/ArmGic: Implement GICv2-only version of GIC driver
Most platforms do not require the flexibility of the ordinary GIC
driver, which supports both GICv2 and GICv3+, and decides at runtime
which version to use.

So expose a GICv2 only version, which only supports a GICv2.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
2025-01-17 18:37:27 +00:00
Ard Biesheuvel 0bb40c79be ArmPkg: Retire ArmGicLib implementations
Retire all implementations of the ArmGicLib library class, which are no
longer used. For now, retain the library header and library class
declaration: the header file only contains pre-processor defines derived
from the GIC architecture spec, and so this code should probably move
into MdePkg at a later moment.

Continuous-integration-options: PatchCheck.ignore-multi-package

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
2025-01-17 18:37:27 +00:00
Ard Biesheuvel c9e38d1afb ArmPkg/ArmGic: Incorporate v3 code from ArmGicLib
Move the remaining code in ArmGicLib into ArmGicDxe, its only user, and
drop the dependency on ArmGicLib. Note that ArmGicDxe has an undeclared
dependency on ArmLib, so declare that instead.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
2025-01-17 18:37:27 +00:00
Ard Biesheuvel eaa60a6b10 ArmPkg/ArmGic: Retire ArmGicArchLib
ArmGicArchLib is no longer use so remove all remaining references and
implementations.

Continuous-integration-options: PatchCheck.ignore-multi-package

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
2025-01-17 18:37:27 +00:00
Ard Biesheuvel 9bf20991b4 ArmPkg/ArmGic: Move some GIC defines into ArmGicLib.h
Before getting rid of ArmGicArchLib entirely, preserve some GIC
architecture related preprocessor defines by moving them into
ArmGicLib.h instead.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
2025-01-17 18:37:27 +00:00
Ard Biesheuvel 8edd5fd6d3 ArmPkg/ArmGic: Move GICv3 sysreg check into ArmGicDxe
ArmGicArchLib implements a check on the accessibility of the GIC system
register interface, which is a prerequisite for using the GIC in v3
mode. It might be possible to use GICv2 compatibility mode on poorly
configured platforms where the GIC is v3 capable but not accessible, but
in most cases, the GIC is driven in its native mode.

This check is now only carried out in a single place, and there is not
really any reason to keep this in a separate library. Even though
ArmVirtPkg implements its own version, the basic check (and enablement
of the sysreg interface) is still needed.

So move this check into the DXE driver itself, and drop the dependency
on ArmGicArchLib. This allows it to be retired in a subsequent patch.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
2025-01-17 18:37:27 +00:00
Ard Biesheuvel 84eed1ef2a ArmPkg/ArmGic: Move GICv2 specific EOI/ACK routines into v2 driver
ArmGicDxe is the only remaining user of ArmGicLib, and so there is no
need for the abstraction, which is drawn at an arbitrary boundary
anyway. So remove the remaining V2 specific code into the DXE driver.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
2025-01-17 18:37:27 +00:00
Ard Biesheuvel 337a99af10 ArmPkg/ArmGic: Move remaining shared code into ArmGicDxe
Move the remaining ArmGicLib code that is shared between the v2 and v3
GIC DXE drivers into ArmGicCommonDxe.c

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
2025-01-17 18:37:27 +00:00
Ard Biesheuvel 298d8c436a ArmPkg/ArmGic: Drop declarations for non-existent functions
Drop some ArmGicLib declarations that don't actually exist in the code.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
2025-01-17 18:37:27 +00:00
Ard Biesheuvel 2ab362f313 ArmPkg/ArmGic: Disentangle ArmGicEnableDistributor () versions
Split ArmGicEnableDistributor () into GICv2 and v3 specific versions,
and move them into their single respective callers, so that the original
can be dropped from ArmGicLib altogether.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
2025-01-17 18:37:27 +00:00
Ard Biesheuvel 4e874fcf09 ArmPkg/ArmGic: Disentangle v2 and v3 versions of IRQ en/disable APIs
ArmGicLib is agnostic about the difference between v2 and v3, but its
APIs are only called from code that is either v2-specific or
v3-specific. That makes the generic interface kind of pointless, and we
can just merge this code into the callers.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
2025-01-17 18:37:27 +00:00
Ard Biesheuvel a4928a0cfc ArmPkg/ArmGic: Remove ArmGicEndOfInterrupt () API
ArmGicEndOfInterrupt () is never used: the v2 and v3 versions of the
driver call respective specific versions directly, and so this API can
be removed.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
2025-01-17 18:37:27 +00:00
Ard Biesheuvel aad4dd9aac ArmPkg/ArmGic: Remove ArmGicSendSgiTo () API
ArmGicSendSgiTo () is never used, and is fundamentally tied to multi-CPU
operation which is no longer supported. So drop the implementation.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
2025-01-17 18:37:27 +00:00
Ard Biesheuvel ec5bb8f953 ArmPkg/ArmGic: drop ArmGicEnableInterruptInterface from ArmGicLib
The ArmGicLib API exposes ArmGicEnableInterruptInterface () and
ArmGicDisableInterruptInterface (), but only the former is actually
used, and only from the GICv2 driver. So drop the API entirely, and
invoke the v2 version of the underlying interface directly.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
2025-01-17 18:37:27 +00:00
Ard Biesheuvel 555bbc6643 ArmPkg/ArmGic: Drop GICv2 legacy support
Support for GICv2 legacy mode was introduced to accommodate secure world
firmware that was lagging behind in terms of development, and was
running the GIC in v2 mode on the secure side for lack of a GICv3
driver.

As per the GIC architecture, the non-secure world can only run the GIC
in v3 mode if the secure world does so too.

At this point, there is no longer a need to for this fallback: GICv2
support it still needed for platforms such as Raspberry Pi 4 that do not
implement GICv3 at all. But on platforms that do implement it, falling
back to GICv2 is unnecessary.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
2025-01-17 18:37:27 +00:00
Levi Yun f0c87b9ef4 StandaloneMmPkg: move core entry point lib and cpu driver to ArmPkg
StandaloneMmCpu driver is only used for Arm architecture and
StandaloneMmCoreEntryPointLib for Arm has specific implementation with
StandaloneMmCpu driver.

Move StandaloneMmCpu Driver and StandaloneMmCoreEntryPointLib for Arm
to ArmPkg.

Continuous-integration-options: PatchCheck.ignore-multi-package
Signed-off-by: Levi Yun <yeoreum.yun@arm.com>
2025-01-17 14:55:42 +00:00
levi.yun 6975494655 ArmPkg: Add StandaloneMm stack size Pcd
StandaloneMm Arm uses stack allocated in data section.
This patch adds Pcd which specify the stack size of StandaloneMm.

Signed-off-by: levi.yun <yeoreum.yun@arm.com>
2025-01-17 14:55:42 +00:00
levi.yun 1bebc97b81 ArmPkg/MmCommunication: add helper function converting smc return
Add helper function converting smc return value to efi status.

Signed-off-by: Levi Yun <yeoreum.yun@arm.com>
2025-01-17 14:55:42 +00:00
levi.yun 8f3c157e04 AmrPkg/MmCommunication: move Mmcommunicate.h to common include
MmCommunication.h is used in MmCommunicationDxe/Pei both.
Move this header file to common include.

Signed-off-by: Levi Yun <yeoreum.yun@arm.com>
2025-01-17 14:55:42 +00:00
Levi Yun 73b2831879 ArmPkg/MmCommunicationPei: Mmcommunication via FF-A
Support Mmcommunication protocol via FF-A with StandaloneMm.
For this, FF-A v1.2 is required.

Signed-off-by: Levi Yun <yeoreum.yun@arm.com>
2025-01-17 14:55:42 +00:00
Levi Yun 9f9a3de9e4 ArmPkg/MmCommunicationDxe: Mmcommunication via FF-A
Support Mmcommunication protocol via FF-A with StandaloneMm.

Signed-off-by: Levi Yun <yeoreum.yun@arm.com>
2025-01-17 14:55:42 +00:00
Levi Yun 4ca452cf91 ArmPkg/Library: Update StandaloneMmuLib with FF-A v1.2 with page granulirty
The StandaloneMm implementation for Arm sets up the stack in
the early startup code using the data section reserved in the
assembly code.

When TF-A loads the StandaloneMM binary in the DRAM it maps
the entire StandaloneMM memory region as Read Only.

Therefore, the initial startup assembly code updates the mem
permissions of the stack region to Read Write.

However, when the StandaloneMmCore is loaded the function
UpdateMmFoundationPeCoffPermissions() starts applying the
memory permissions based on the PE COFF sections as below:

A. If the section is not executable, it first removes the
executable permission of the section by calling TextUpdate().
TextUpdate() is the StandaloneMM MMU library function
ArmSetMemoryRegionNoExec().

B. It then checks if the section is writable, and if it is
it calls ReadWriteUpdater(), which invokes the StandaloneMM
MMU library function ArmClearMemoryRegionReadOnly() to make
the section writable.

However, this results in the stack being made read-only
between A and B. To understand this please see the following
flow.

1. TF-A sets the entire StandaloneMM region as Read Only.
2. The stack is reserved in the data section by the early
   assembly entry point code.
    +--------------------+   <--- Start of Data Section
    |                    |
    |  Data Section      |
    |                    |
    | +----------------+ |   <--- Stack region
    | |   Stack        | |
    | +----------------+ |
    |                    |
    +--------------------+

3. The StanaloneMM early entry point code updates the
   attributes of the stack to Read Write.
4. When UpdateMmFoundationPeCoffPermissions() sets the
   permission of the data section to remove the Execute
   attribute, it calls ArmSetMemoryRegionNoExec().
5. The ArmSetMemoryRegionNoExec() implementation gets the
   attributes of the first granule which is at the start
   of the data section, then clears the execute permission
   and applies the attribute for the entire data section.
6. Since TF-A has mapped the entire section as read only
   the first granule of the data section is read only and
   therefore the stack region attributes are changed to
   Read Only no execute.
7. Since the stack is read only after point A any updates
   to the stack result in an exception.

To resolve this issue with update the library with FF-A v1.2,
get/set memory permission per page unit.

Links: https://developer.arm.com/documentation/den0140/latest/ [0]
Signed-off-by: Levi Yun <yeoreum.yun@arm.com>
2025-01-17 14:55:42 +00:00
Levi Yun 401699c326 ArmPkg: Add ArmFfaLib used in StandaloneMm
Add ArmFfaLib used in StandaloneMmCore/StandaloneMm Driver.

Continuous-integration-options: PatchCheck.ignore-multi-package
Signed-off-by: Levi Yun <yeoreum.yun@arm.com>
2025-01-17 14:55:42 +00:00
Levi Yun 166c3b2eb7 ArmPkg: Add ArmFfaLib used in PEIM
Add ArmFfaLib used in PEIM.

Signed-off-by: Levi Yun <yeoreum.yun@arm.com>
2025-01-17 14:55:42 +00:00
Levi Yun 5d1b38dd07 ArmPkg: Add ArmFfaLib used in Dxe driver
Add ArmFfaLib used in Dxe driver

Signed-off-by: Levi Yun <yeoreum.yun@arm.com>
2025-01-17 14:55:42 +00:00
Levi Yun 18948c4a6a ArmPkg: Add ArmFfaLib.h
Add ArmFfaLib.h which defines interfaces correspond to FF-A ABIs.

Signed-off-by: Levi Yun <yeoreum.yun@arm.com>
2025-01-17 14:55:42 +00:00
Levi Yun 30ecebe015 ArmPkg: Remove PcdFfaEnabled
PcdFfaEnabled is no more used because ArmFfaLib could find whether FF-A
is supported dynamically.

This patch removes usage of PcdFfaEnabled.

Continuous-integration-options: PatchCheck.ignore-multi-package
Signed-off-by: Levi Yun <yeoreum.yun@arm.com>
2025-01-17 14:55:42 +00:00
Levi Yun 843f4fd60d ArmPkg: Add FF-A related dynamic Pcd and Guid
To communicate with spmc or spmd, UEFI needs to map the Rx/Tx buffer
(which is a global resource in a partition)
by getting the required information from the partition descriptor.

for this, Define ArmFfaLib related Pcd and Guid.

Pcd:
  - PcdFfaLibConduitSmc
      conudit to use ArmFfaLib.

  - PcdFfaTxBufeer
      address of Tx buffer.

  - PcdFfaRxBuffer:
      address of Rx buffer.

  - PcdTxRxPageCount:
      specify buffer size with EFI_PAGE_SIZE unit.

  - PcdFfaExitBootEventRegistered:
      check exit boot event registered to unmap rx/tx buffer.

Guid:
   - gArmFfaRxTxBufferInfoGuid:
       This is used in Hob to get Rx/Tx buffer information to pass
       Rx/Tx buffer information via HobList if Rx/Tx Buffer mapped in
       PEI phase.

Signed-off-by: Levi Yun <yeoreum.yun@arm.com>
2025-01-17 14:55:42 +00:00
Levi Yun 79875fdde0 ArmPkg: Add FF-A partition information header
Partition descriptor is used to get partition information via
FFA_PARTITION_INFO_GET or FFA_PARTITION_INFO_GET_REGS FF-A ABI.

Adds defines for partition descriptor and some macros used to call above
ABIs.

Signed-off-by: Levi Yun <yeoreum.yun@arm.com>
2025-01-17 14:55:42 +00:00
Levi Yun d1d690f363 ArmPkg/IndustryStandard: Introduce ArmFfaBootInfo.h
ArmFfaBootInfo.h contains boot information used in FF-A [0].
This boot information will be used to
initalize firmware (i.e) StandaloneMm.

Links: https://developer.arm.com/documentation/den0077/latest/ [0]

Signed-off-by: Levi Yun <yeoreum.yun@arm.com>
2025-01-17 14:55:42 +00:00
Levi Yun 173af697dd ArmPkg/IndustryStandard: Update ArmFfaSvc.h
Update ArmFfaSvc.h defines & macros with FF-A v1.2 [0] and
FF-A Memory Mangement Protocol [1].

This also changes naming convention used in it.

Link: https://developer.arm.com/documentation/den0077/latest/ [0]
Link: https://developer.arm.com/documentation/den0140/latest/ [1]

Signed-off-by: Levi Yun <yeoreum.yun@arm.com>
2025-01-17 14:55:42 +00:00
levi.yun 54e394b4a2 ArmPkg/StandaloneMmMmuLib: Introduce a SPM_MM status helper fucntion
Introduce a new helper function SpmMmStatusToEfiStatus() to convert
the SPM_MM status values to EFI_STATUS values.

Signed-off-by: Levi yun <yeoreum.yun@arm.com>
2025-01-17 14:55:42 +00:00
levi.yun c56856f068 ArmPkg/IndustryStandard: Change naming convention in ArmMmSvc.h
Change naming convention in ArmMmSvc.h with

  MM to SPM_MM

This would make it clear to discern ABI protocol used to communicate
with secure partition.

Continuous-integration-options: PatchCheck.ignore-multi-package
Signed-off-by: Levi Yun <yeoreum.yun@arm.com>
2025-01-17 14:55:42 +00:00
levi.yun fbeab84945 ArmPkg/Library: Introduce ArmTransferListLib
ArmTransferList is used to pass boot information according to
firmware handoff protocol specification [0].

When initializing StandaloneMm, it gets boot information from
the PHIT HOB in the TransferList.

[0] https://github.com/FirmwareHandoff/firmware_handoff

Signed-off-by: Levi Yun <yeoreum.yun@arm.com>
2025-01-17 14:55:42 +00:00
Mike Maslenkin aaf0846fa2 ArmPkg: remove ArmGicAcknowledgeInterrupt function.
A compiler warning was detected that 'IntId' could be used uninitialized
in the `else` branch.
Since there are no consumers of this function, it was decided to remove
this function completely.

Signed-off-by: Mike Maslenkin <mike.maslenkin@gmail.com>
2025-01-12 15:52:05 +00:00
Ashish Singhal c52dddf1eb ArmPkg: Update Generic Watchdog PCD Type
Do not use the PCDs as only fixed when there is an option
to use them as dynamic that can be set per SKU.

Signed-off-by: Ashish Singhal <ashishsingha@nvidia.com>
2024-12-23 12:07:43 +00:00
Kun Qin 25ce25ecce ArmPkg: DefaultExceptionHandlerLib: Update function input bitwidth
The current DescribeExceptionSyndrome is taking ESR as 32bit value.
However, ESR should be a 64 bit value. This change updates the function
to intake a 64bit value.

Cc: Leif Lindholm <quic_llindhol@quicinc.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Sami Mujawar <sami.mujawar@arm.com>

Signed-off-by: Kun Qin <kun.qin@microsoft.com>
2024-12-11 18:21:29 +00:00
Kun Qin e8b7d7a238 ArmPkg: ArmExceptionLib: Fixing exception vector and type casting
The current VectorBase is taking value from a 64bit PCD into a UINTN
value, which could have truncated value for 32bit system.

In addition, the comparison between UINTN and INTN could lead to
undesired comparison outcome or compiler complaints.

This change updates all of them to be UINT64 based operation.

Cc: Leif Lindholm <quic_llindhol@quicinc.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Sami Mujawar <sami.mujawar@arm.com>

Signed-off-by: Kun Qin <kun.qin@microsoft.com>
2024-12-11 18:21:29 +00:00
Kun Qin b689c387e2 ArmPkg: ArmLib: Update function to match header file
Update function implementation to match interface definition. The return
should be bound to 0xffff0000, which is guaranteed to be a UINT32.

Cc: Leif Lindholm <quic_llindhol@quicinc.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Sami Mujawar <sami.mujawar@arm.com>

Signed-off-by: Kun Qin <kun.qin@microsoft.com>
2024-12-11 18:21:29 +00:00
Kun Qin 9d0f3dd35d ArmPkg: ArmArchTimerLib: Update operations to be 64 bit wide
The existing operation in ArmArchTimerLib is operating on UINT32 or
UINT64 based on the target system. This casting game originates from the
fact that timer frequency is UINTN type.

This change will simply promote all operations to UINT64 based, which
will remove the casting and conditional #if in the code for better
portability and readability.

Cc: Leif Lindholm <quic_llindhol@quicinc.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Sami Mujawar <sami.mujawar@arm.com>

Signed-off-by: Kun Qin <kun.qin@microsoft.com>
2024-12-11 18:21:29 +00:00
Kun Qin 77d32b1796 ArmPkg: TimerDxe: Use 64bit operation for timer ticks
The current implementation operates on 64bit value with implicit value
truncation.

This change updates the involved frequencies to use 64 bit based
operations.

Cc: Leif Lindholm <quic_llindhol@quicinc.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Sami Mujawar <sami.mujawar@arm.com>

Signed-off-by: Kun Qin <kun.qin@microsoft.com>
2024-12-11 18:21:29 +00:00
Kun Qin 957fcbe7a3 ArmPkg: ArmGic: Cast CpuTarget to UINT32 for legacy GIC
The current code path supporting `PcdArmGicV3WithV2Legacy` will read 32
bit CPU target and try to program ARM_GIC_ICDIPTR. However, all these
operations are 32bit wide.

This change casts the CpuTarget variable to be UINT32 before calling
MMIO read.

Cc: Leif Lindholm <quic_llindhol@quicinc.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Sami Mujawar <sami.mujawar@arm.com>

Signed-off-by: Kun Qin <kun.qin@microsoft.com>
2024-12-11 18:21:29 +00:00
Pierre Gondois bf32c2d61f ArmPkg/SemihostFs: StrSize() cannot return 0
StrSize() account the terminating NULL character and cannot return 0.
Replace StrSize() StrLen().

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4859
Reported-by: Tormod Volden <debian.tormod@gmail.com>
Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
2024-11-27 15:57:08 +00:00
Ard Biesheuvel f60a839480 ArmPkg/ArmMmuLib: Add support for EL2&0 translation regime
With VHE enabled, EL2 uses the EL2&0 translation regime, which is
compatible with the EL1&0 translation regime when it comes to the TCR
configuration register and the page table descriptor.

Given that some CPUs may have VHE force enabled when executing at EL2,
the MMU code needs to be able to deal with this even if it doesn't
enable VHE itself.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
2024-11-26 23:53:16 +00:00
Ard Biesheuvel e80b17d21a ArmPkg/ArmMmuLib: Ignore EL3 in RELEASE code
Remove the code path for execution at EL3, which just dumps an error.
None of the other code is remotely suitable for execution at EL3, and so
just ASSERT()'ing here is sufficient, and simplifies future changes
related to VHE.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
2024-11-26 23:53:16 +00:00
Ard Biesheuvel 31ff325228 ArmPkg/ArmLib: Use VHE alternatives for timer system registers
When VHE is enabled, some pre-existing timer system register specifiers
are redirected to the HYP timer. To access the conventional timer,
special aliases have to be used that end in _EL02.

These aliases are not understood by Clang's internal assembler, so use
the generic mnemonics instead.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
2024-11-26 23:53:16 +00:00
Ard Biesheuvel 31ea376b58 ArmPkg: Remove ArmSoftFloatLib implementation
Drop the softfloat library implementation now that it is no longer used.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
2024-11-26 22:00:36 +00:00