1 | /** @file
|
---|
2 | Arm Ffa library code for PEI Driver
|
---|
3 |
|
---|
4 | Copyright (c) 2024, Arm Limited. All rights reserved.<BR>
|
---|
5 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
6 |
|
---|
7 | @par Glossary:
|
---|
8 | - FF-A - Firmware Framework for Arm A-profile
|
---|
9 |
|
---|
10 | @par Reference(s):
|
---|
11 | - Arm Firmware Framework for Arm A-Profile [https://developer.arm.com/documentation/den0077/latest]
|
---|
12 |
|
---|
13 | **/
|
---|
14 |
|
---|
15 | #include <Uefi.h>
|
---|
16 | #include <PiPei.h>
|
---|
17 | #include <Pi/PiPeiCis.h>
|
---|
18 | #include <Pi/PiMultiPhase.h>
|
---|
19 |
|
---|
20 | #include <Library/ArmLib.h>
|
---|
21 | #include <Library/ArmSmcLib.h>
|
---|
22 | #include <Library/ArmFfaLib.h>
|
---|
23 | #include <Library/BaseLib.h>
|
---|
24 | #include <Library/BaseMemoryLib.h>
|
---|
25 | #include <Library/DebugLib.h>
|
---|
26 | #include <Library/HobLib.h>
|
---|
27 | #include <Library/MemoryAllocationLib.h>
|
---|
28 | #include <Library/PcdLib.h>
|
---|
29 |
|
---|
30 | #include <IndustryStandard/ArmFfaSvc.h>
|
---|
31 |
|
---|
32 | #include "ArmFfaCommon.h"
|
---|
33 | #include "ArmFfaRxTxMap.h"
|
---|
34 |
|
---|
35 | /**
|
---|
36 | ArmFfaLib Constructor.
|
---|
37 |
|
---|
38 | @param [in] FileHandle File Handle
|
---|
39 | @param [in] PeiServices Pei Service Table
|
---|
40 |
|
---|
41 | @retval EFI_SUCCESS Success
|
---|
42 | @retval Others Error
|
---|
43 |
|
---|
44 | **/
|
---|
45 | EFI_STATUS
|
---|
46 | EFIAPI
|
---|
47 | ArmFfaPeiLibConstructor (
|
---|
48 | IN EFI_PEI_FILE_HANDLE FileHandle,
|
---|
49 | IN CONST EFI_PEI_SERVICES **PeiServices
|
---|
50 | )
|
---|
51 | {
|
---|
52 | EFI_STATUS Status;
|
---|
53 | EFI_HOB_GUID_TYPE *RxTxBufferHob;
|
---|
54 | ARM_FFA_RX_TX_BUFFER_INFO *BufferInfo;
|
---|
55 |
|
---|
56 | Status = ArmFfaLibCommonInit ();
|
---|
57 | if (EFI_ERROR (Status)) {
|
---|
58 | if (Status == EFI_UNSUPPORTED) {
|
---|
59 | /*
|
---|
60 | * EFI_UNSUPPORTED return from ArmFfaLibCommonInit() means
|
---|
61 | * FF-A interface doesn't support.
|
---|
62 | * However, It doesn't make failure of loading driver/library instance
|
---|
63 | * (i.e) ArmPkg's MmCommunication Dxe/PEI Driver uses as well as SpmMm.
|
---|
64 | * So If FF-A is not supported the the MmCommunication Dxe/PEI falls
|
---|
65 | * back to SpmMm.
|
---|
66 | * For this case, return EFI_SUCCESS.
|
---|
67 |
|
---|
68 | */
|
---|
69 | return EFI_SUCCESS;
|
---|
70 | }
|
---|
71 |
|
---|
72 | return Status;
|
---|
73 | }
|
---|
74 |
|
---|
75 | RxTxBufferHob = GetFirstGuidHob (&gArmFfaRxTxBufferInfoGuid);
|
---|
76 | if (RxTxBufferHob == NULL) {
|
---|
77 | Status = ArmFfaLibRxTxMap ();
|
---|
78 | if (EFI_ERROR (Status)) {
|
---|
79 | return Status;
|
---|
80 | }
|
---|
81 |
|
---|
82 | BufferInfo = BuildGuidHob (
|
---|
83 | &gArmFfaRxTxBufferInfoGuid,
|
---|
84 | sizeof (ARM_FFA_RX_TX_BUFFER_INFO)
|
---|
85 | );
|
---|
86 | if (BufferInfo == NULL) {
|
---|
87 | ArmFfaLibRxTxUnmap ();
|
---|
88 | return EFI_OUT_OF_RESOURCES;
|
---|
89 | }
|
---|
90 |
|
---|
91 | BufferInfo->TxBufferAddr = (VOID *)(UINTN)PcdGet64 (PcdFfaTxBuffer);
|
---|
92 | BufferInfo->TxBufferSize = PcdGet64 (PcdFfaTxRxPageCount) * EFI_PAGE_SIZE;
|
---|
93 | BufferInfo->RxBufferAddr = (VOID *)(UINTN)PcdGet64 (PcdFfaRxBuffer);
|
---|
94 | BufferInfo->RxBufferSize = PcdGet64 (PcdFfaTxRxPageCount) * EFI_PAGE_SIZE;
|
---|
95 | }
|
---|
96 |
|
---|
97 | return EFI_SUCCESS;
|
---|
98 | }
|
---|