Date   

[PATCH v1 0/5] Add ACPI support for Kvmtool

PierreGondois
 

From: Pierre Gondois <Pierre.Gondois@arm.com>

Kvmtool dynamically generates a device tree describing the platform
to boot on. Using the patch-sets listed below, the DynamicTables
framework generates ACPI tables describing a similar platform.

This patch-set:
- adds a ConfigurationManager allowing to generate ACPI tables
for Kvmtool
- adds the acpiview command line utility to the ArmVirtPkg
- update ArmVirtPkg.ci.yaml to add new words and use the
DynamicTablesPkg

This patch sets also set the default platform description format
to ACPI instead of the device tree (c.f.: PcdForceNoAcpi is set
to FALSE).

The changes can be seen at: https://github.com/PierreARM/edk2/tree/1456_Add_ACPI_support_for_Kvmtool_v1
The results of the CI can be seen at: https://github.com/tianocore/edk2/pull/1753

This patch-set is dependent over the following patch-sets:
[PATCH v1 00/10] Various DynamicTablesPkg modifications
https://edk2.groups.io/g/devel/message/76929
and:
[PATCH v1 00/13] Create a SSDT CPU topology generator
https://edk2.groups.io/g/devel/message/76941
and:
[PATCH v1 0/7] Create a SSDT PCIe generator
https://edk2.groups.io/g/devel/message/76958
and:
[PATCH v1 00/14] Implement a FdtHwInfoParserLib
https://edk2.groups.io/g/devel/message/76967
and:
[PATCH v1 0/5] Add DynamicPlatRepoLib
https://edk2.groups.io/g/devel/message/76984

Pierre Gondois (1):
ArmVirtPkg: Add cspell exceptions

Sami Mujawar (4):
ArmVirtPkg: Add DSDT ACPI table for Kvmtool firmware
ArmVirtPkg: Add Configuration Manager for Kvmtool firmware
ArmVirtPkg: Enable ACPI support for Kvmtool
ArmVirtPkg: Enable Acpiview for ArmVirtPkg

ArmVirtPkg/ArmVirt.dsc.inc | 3 +-
ArmVirtPkg/ArmVirtKvmTool.dsc | 18 +-
ArmVirtPkg/ArmVirtKvmTool.fdf | 11 +
ArmVirtPkg/ArmVirtPkg.ci.yaml | 3 +
.../KvmtoolCfgMgrDxe/AslTables/Dsdt.asl | 19 +
.../KvmtoolCfgMgrDxe/ConfigurationManager.c | 948 ++++++++++++++++++
.../KvmtoolCfgMgrDxe/ConfigurationManager.h | 94 ++
.../ConfigurationManagerDxe.inf | 58 ++
8 files changed, 1151 insertions(+), 3 deletions(-)
create mode 100644 ArmVirtPkg/KvmtoolCfgMgrDxe/AslTables/Dsdt.asl
create mode 100644 ArmVirtPkg/KvmtoolCfgMgrDxe/ConfigurationManager.c
create mode 100644 ArmVirtPkg/KvmtoolCfgMgrDxe/ConfigurationManager.h
create mode 100644 ArmVirtPkg/KvmtoolCfgMgrDxe/ConfigurationManagerDxe.inf

--
2.17.1


[PATCH v1 5/5] DynamicTablesPkg: Add DynamicPlatRepo library

PierreGondois
 

From: Pierre Gondois <Pierre.Gondois@arm.com>

The DynamicPlatRepo library allows to handle dynamically created
CmObj. The dynamic platform repository can be in the following states:
1 - Non-initialised
2 - Transient:
Possibility to add CmObj to the platform, but not to query them.
3 - Finalised:
Possibility to query CmObj, but not to add new.

A token is allocated to each CmObj added to the dynamic platform
repository (except for reference tokens CmObj). This allows to retrieve
dynamic CmObjs among all CmObj (static CmObj for instance).

This patch add the inf file of the module and the main module
functionnalities and update the dsc file of the package.

Signed-off-by: Sami Mujawar <sami.mujawar@arm.com>
Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
---
DynamicTablesPkg/DynamicTablesPkg.dsc | 1 +
.../Include/Library/DynamicPlatRepoLib.h | 4 +-
.../DynamicPlatRepoLib/DynamicPlatRepo.c | 518 ++++++++++++++++++
.../DynamicPlatRepoInternal.h | 78 +++
.../DynamicPlatRepoLib/DynamicPlatRepoLib.inf | 33 ++
5 files changed, 633 insertions(+), 1 deletion(-)
create mode 100644 DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/DynamicPlatRepo.c
create mode 100644 DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/DynamicPlatRepoInternal.h
create mode 100644 DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/DynamicPlatRepoLib.inf

diff --git a/DynamicTablesPkg/DynamicTablesPkg.dsc b/DynamicTablesPkg/DynamicTablesPkg.dsc
index fd7345891cf1..432c958cf8b2 100644
--- a/DynamicTablesPkg/DynamicTablesPkg.dsc
+++ b/DynamicTablesPkg/DynamicTablesPkg.dsc
@@ -43,6 +43,7 @@ [Components.common]
DynamicTablesPkg/Library/Common/SsdtSerialPortFixupLib/SsdtSerialPortFixupLib.inf
DynamicTablesPkg/Library/Common/TableHelperLib/TableHelperLib.inf
DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtHwInfoParserLib.inf
+ DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/DynamicPlatRepoLib.inf

[BuildOptions]
*_*_*_CC_FLAGS = -D DISABLE_NEW_DEPRECATED_INTERFACES
diff --git a/DynamicTablesPkg/Include/Library/DynamicPlatRepoLib.h b/DynamicTablesPkg/Include/Library/DynamicPlatRepoLib.h
index 8e4665bf5c59..4a76b30399b4 100644
--- a/DynamicTablesPkg/Include/Library/DynamicPlatRepoLib.h
+++ b/DynamicTablesPkg/Include/Library/DynamicPlatRepoLib.h
@@ -13,6 +13,8 @@
#ifndef DYNAMIC_PLAT_REPO_H_
#define DYNAMIC_PLAT_REPO_H_

+#include <Protocol/ConfigurationManagerProtocol.h>
+
/** A structure describing the platform configuration
manager repository information
*/
@@ -109,4 +111,4 @@ DynamicPlatRepoShutdown (
IN DYNAMIC_PLATFORM_REPOSITORY_INFO * DynPlatRepo
);

-#endif DYNAMIC_PLAT_REPO_H_
+#endif // DYNAMIC_PLAT_REPO_H_
diff --git a/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/DynamicPlatRepo.c b/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/DynamicPlatRepo.c
new file mode 100644
index 000000000000..f26f8ad32bc8
--- /dev/null
+++ b/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/DynamicPlatRepo.c
@@ -0,0 +1,518 @@
+/** @file
+ Dynamic Platform Info Repository
+
+ Copyright (c) 2021, Arm Limited. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Glossary:
+ - Cm or CM - Configuration Manager
+ - Obj or OBJ - Object
+**/
+
+#include <Protocol/ConfigurationManagerProtocol.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/MemoryAllocationLib.h>
+
+#include "CmObjectTokenFixer.h"
+#include "DynamicPlatRepoInternal.h"
+#include "TokenGenerator.h"
+
+/** Allocate a CM_OBJ_NODE.
+
+ @param [in] CmObjDesc CmObj to wrap in a node.
+ All the fields of the CmObj (Data field included),
+ are copied.
+ @param [in] Token Token to assign to this CmObj/node.
+ @param [out] ObjNode Allocated ObjNode.
+
+ @retval EFI_SUCCESS Success.
+ @retval EFI_INVALID_PARAMETER A parameter is invalid.
+ @retval EFI_OUT_OF_RESOURCES An allocation has failed.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+AllocCmObjNode (
+ IN CONST CM_OBJ_DESCRIPTOR * CmObjDesc,
+ IN CM_OBJECT_TOKEN Token,
+ OUT CM_OBJ_NODE ** ObjNode
+ )
+{
+ CM_OBJ_NODE *Node;
+ CM_OBJ_DESCRIPTOR *Desc;
+
+ if ((CmObjDesc == NULL) || (ObjNode == NULL)) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Node = AllocateZeroPool (sizeof (CM_OBJ_NODE));
+ if (Node == NULL) {
+ ASSERT (0);
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ // Initialise the list head.
+ InitializeListHead (&Node->Link);
+ Node->Token = Token;
+ Desc = &Node->CmObjDesc;
+ Desc->ObjectId = CmObjDesc->ObjectId;
+ Desc->Size = CmObjDesc->Size;
+ Desc->Count = CmObjDesc->Count;
+
+ // Allocate and copy the CmObject Data.
+ Desc->Data = AllocateCopyPool (CmObjDesc->Size, CmObjDesc->Data);
+ if (Desc->Data == NULL) {
+ FreePool (Node);
+ ASSERT (0);
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ *ObjNode = Node;
+ return EFI_SUCCESS;
+}
+
+/** Free a CM_OBJ_NODE.
+
+ @param [in] ObjNode ObjNode to free.
+
+ @retval EFI_SUCCESS Success.
+ @retval EFI_INVALID_PARAMETER A parameter is invalid.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+FreeCmObjNode (
+ IN CM_OBJ_NODE * ObjNode
+ )
+{
+ CM_OBJ_DESCRIPTOR *Desc;
+
+ if (ObjNode == NULL) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ // Unlink Node
+ RemoveEntryList (&ObjNode->Link);
+
+ Desc = &ObjNode->CmObjDesc;
+ if (Desc->Data != NULL) {
+ FreePool (Desc->Data);
+ }
+
+ FreePool (ObjNode);
+ return EFI_SUCCESS;
+}
+
+/** Add an object to the dynamic platform repository.
+
+ @param [in] This This dynamic platform repository.
+ @param [in] CmObjDesc CmObj to add. The data is copied.
+ @param [out] Token If not NULL, token allocated to this CmObj.
+
+ @retval EFI_SUCCESS Success.
+ @retval EFI_INVALID_PARAMETER A parameter is invalid.
+ @retval EFI_OUT_OF_RESOURCES An allocation has failed.
+**/
+EFI_STATUS
+EFIAPI
+DynPlatRepoAddObject (
+ IN DYNAMIC_PLATFORM_REPOSITORY_INFO * This,
+ IN CONST CM_OBJ_DESCRIPTOR * CmObjDesc,
+ OUT CM_OBJECT_TOKEN * Token OPTIONAL
+ )
+{
+ EFI_STATUS Status;
+ CM_OBJ_NODE *ObjNode;
+ CM_OBJECT_ID ArmNamespaceObjId;
+ CM_OBJECT_TOKEN NewToken;
+
+ // The dynamic repository must be able to receive objects.
+ if ((This == NULL) ||
+ (CmObjDesc == NULL) ||
+ (This->RepoState != DynRepoTransient)) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ // Check the CmObjDesc:
+ // - only Arm objects are supported for now.
+ // - only EArmObjCmRef objects can be added as arrays.
+ ArmNamespaceObjId = GET_CM_OBJECT_ID (CmObjDesc->ObjectId);
+ if ((CmObjDesc->Size == 0) ||
+ (CmObjDesc->Count == 0) ||
+ (ArmNamespaceObjId >= EArmObjMax) ||
+ ((CmObjDesc->Count > 1) && (ArmNamespaceObjId != EArmObjCmRef)) ||
+ (GET_CM_NAMESPACE_ID (CmObjDesc->ObjectId) != EObjNameSpaceArm)) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ // Generate a token.
+ NewToken = GenerateToken ();
+
+ // Create an ObjNode.
+ Status = AllocCmObjNode (CmObjDesc, NewToken, &ObjNode);
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+
+ // Fixup self-token if necessary.
+ Status = FixupCmObjectSelfToken (&ObjNode->CmObjDesc, NewToken);
+ if (EFI_ERROR (Status)) {
+ FreeCmObjNode (ObjNode);
+ ASSERT (0);
+ return Status;
+ }
+
+ // Add to link list.
+ InsertTailList (&This->ArmCmObjList[ArmNamespaceObjId], &ObjNode->Link);
+ This->ObjectCount += 1;
+
+ if (Token != NULL) {
+ *Token = NewToken;
+ }
+ return EFI_SUCCESS;
+}
+
+/** Group lists of CmObjNode from the ArmNameSpace to one array.
+
+ @param [in] This This dynamic platform repository.
+ @param [in] ArmObjIndex Index in EARM_OBJECT_ID
+ (must be < EArmObjMax).
+
+ @retval EFI_SUCCESS Success.
+ @retval EFI_INVALID_PARAMETER A parameter is invalid.
+ @retval EFI_BUFFER_TOO_SMALL Buffer too small.
+ @retval EFI_OUT_OF_RESOURCES An allocation has failed.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+GroupCmObjNodes (
+ IN DYNAMIC_PLATFORM_REPOSITORY_INFO * This,
+ IN UINT32 ArmObjIndex
+ )
+{
+ EFI_STATUS Status;
+ UINTN Count;
+ UINTN Size;
+ UINT32 CmObjId;
+ UINT8 *GroupedData;
+ UINT8 *Data;
+ CM_OBJ_DESCRIPTOR *CmObjDesc;
+ LIST_ENTRY *ListHead;
+ LIST_ENTRY *Link;
+
+ if ((This == NULL) ||
+ (ArmObjIndex >= EArmObjMax)) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Count = 0;
+ Size = 0;
+ CmObjId = CREATE_CM_ARM_OBJECT_ID (ArmObjIndex);
+ ListHead = &This->ArmCmObjList[ArmObjIndex];
+ Link = GetFirstNode (ListHead);
+
+ // Compute the total count and size of the CmObj in the list.
+ while (Link != ListHead) {
+ CmObjDesc = &((CM_OBJ_NODE*)Link)->CmObjDesc;
+
+ if (CmObjDesc->ObjectId != CmObjId) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if ((CmObjDesc->Count != 1) && (ArmObjIndex != EArmObjCmRef)){
+ // We expect each descriptor to contain an individual object.
+ // EArmObjCmRef objects are counted as groups, so +1 as well.
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Count++;
+ Size += CmObjDesc->Size;
+
+ // Next Link
+ Link = GetNextNode (ListHead, Link);
+ } // while
+
+ if (Count == 0) {
+ // No objects found.
+ return EFI_SUCCESS;
+ }
+
+ GroupedData = AllocateZeroPool (Size);
+ if (GroupedData == NULL) {
+ ASSERT (0);
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ // Copy the Object Data and add to the TokenMapper.
+ Data = GroupedData;
+ Link = GetFirstNode (ListHead);
+ while (Link != ListHead) {
+ CmObjDesc = &((CM_OBJ_NODE*)Link)->CmObjDesc;
+ CopyMem (Data, CmObjDesc->Data, CmObjDesc->Size);
+
+ // Add the object to the Token Mapper.
+ // Note: The CmObject Data field of objects in the Token Mapper point
+ // to the memory in the GroupedData array.
+ Status = TokenMapperAddObject (
+ &This->TokenMapper,
+ ((CM_OBJ_NODE*)Link)->Token,
+ CmObjDesc->ObjectId,
+ CmObjDesc->Size,
+ Data
+ );
+ if (EFI_ERROR (Status)) {
+ FreePool (GroupedData);
+ return Status;
+ }
+
+ Data += CmObjDesc->Size;
+ Link = GetNextNode (ListHead, Link);
+ } // while
+
+ CmObjDesc = &This->ArmCmObjArray[ArmObjIndex];
+ CmObjDesc->ObjectId = CmObjId;
+ CmObjDesc->Size = Size;
+ CmObjDesc->Count = Count;
+ CmObjDesc->Data = GroupedData;
+
+ return Status;
+}
+
+/** Finalise the dynamic repository.
+
+ Finalising means:
+ - Preventing any further objects from being added.
+ - Allowing to get objects from the dynamic repository
+ (not possible before a call to this function).
+
+ @param [in] This This dynamic platform repository.
+
+ @retval EFI_SUCCESS Success.
+ @retval EFI_ALREADY_STARTED Instance already initialised.
+ @retval EFI_INVALID_PARAMETER A parameter is invalid.
+ @retval EFI_BUFFER_TOO_SMALL Buffer too small.
+ @retval EFI_OUT_OF_RESOURCES An allocation has failed.
+**/
+EFI_STATUS
+EFIAPI
+DynamicPlatRepoFinalise (
+ IN DYNAMIC_PLATFORM_REPOSITORY_INFO * This
+ )
+{
+ EFI_STATUS Status;
+ UINTN ArmObjIndex;
+
+ if ((This == NULL) ||
+ (This->RepoState != DynRepoTransient)) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ // Prevent any further objects from being added.
+ This->RepoState = DynRepoFinalized;
+
+ // Initialise the token mapper.
+ Status = TokenMapperInitialise (&This->TokenMapper, This->ObjectCount);
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+
+ // For each CM_OBJECT_ID:
+ // - Convert the list of nodes to an array
+ // (the array is wrapped in a CmObjDesc).
+ // - Add the Token/CmObj binding to the token mapper.
+ for (ArmObjIndex = 0; ArmObjIndex < EArmObjMax; ArmObjIndex++) {
+ Status = GroupCmObjNodes (This, ArmObjIndex);
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ // Free the TokenMapper.
+ // Ignore the returned Status since we already failed.
+ TokenMapperShutdown (&This->TokenMapper);
+ return Status;
+ }
+ } // for
+
+ return EFI_SUCCESS;
+}
+
+/** Get a CmObj from the dynamic repository.
+
+ @param [in] This Pointer to the Dynamic Platform Repository.
+ @param [in] CmObjectId The Configuration Manager Object ID.
+ @param [in] Token An optional token identifying the object. If
+ unused this must be CM_NULL_TOKEN.
+ @param [in, out] CmObjDesc Pointer to the Configuration Manager Object
+ descriptor describing the requested Object.
+
+ @retval EFI_SUCCESS Success.
+ @retval EFI_INVALID_PARAMETER A parameter is invalid.
+ @retval EFI_NOT_FOUND The required object information is not found.
+**/
+EFI_STATUS
+EFIAPI
+DynamicPlatRepoGetObject (
+ IN DYNAMIC_PLATFORM_REPOSITORY_INFO * This,
+ IN CM_OBJECT_ID CmObjectId,
+ IN CM_OBJECT_TOKEN Token OPTIONAL,
+ IN OUT CM_OBJ_DESCRIPTOR * CmObjDesc
+ )
+{
+ EFI_STATUS Status;
+ CM_OBJ_DESCRIPTOR *Desc;
+ CM_OBJECT_ID ArmNamespaceObjId;
+
+ if ((This == NULL) ||
+ (CmObjDesc == NULL) ||
+ (This->RepoState != DynRepoFinalized)) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ ArmNamespaceObjId = GET_CM_OBJECT_ID (CmObjectId);
+ if (ArmNamespaceObjId >= EArmObjMax) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (Token != CM_NULL_TOKEN) {
+ // Search in the Token Mapper and return the object.
+ Status = TokenMapperGetObject (
+ &This->TokenMapper,
+ Token,
+ CmObjectId,
+ CmObjDesc
+ );
+ ASSERT_EFI_ERROR (Status);
+ return Status;
+ }
+
+ if (ArmNamespaceObjId == EArmObjCmRef) {
+ // EArmObjCmRef object must be requested using a valid token.
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Desc = &This->ArmCmObjArray[ArmNamespaceObjId];
+
+ // Nothing here.
+ if (Desc->Count == 0) {
+ return EFI_NOT_FOUND;
+ } else {
+ // Return the full array.
+ CmObjDesc->ObjectId = Desc->ObjectId;
+ CmObjDesc->Size = Desc->Size;
+ CmObjDesc->Data = Desc->Data;
+ CmObjDesc->Count = Desc->Count;
+ }
+
+ return EFI_SUCCESS;
+}
+
+/** Initialize the dynamic platform repository.
+
+ @param [out] DynPlatRepo If success, contains the initialised dynamic
+ platform repository.
+
+ @retval EFI_SUCCESS Success.
+ @retval EFI_INVALID_PARAMETER A parameter is invalid.
+ @retval EFI_OUT_OF_RESOURCES An allocation has failed.
+**/
+EFI_STATUS
+EFIAPI
+DynamicPlatRepoInit (
+ OUT DYNAMIC_PLATFORM_REPOSITORY_INFO ** DynPlatRepo
+ )
+{
+ UINTN Index;
+ DYNAMIC_PLATFORM_REPOSITORY_INFO * Repo;
+
+ if (DynPlatRepo == NULL) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Repo = AllocateZeroPool (sizeof (DYNAMIC_PLATFORM_REPOSITORY_INFO));
+ if (Repo == NULL) {
+ ASSERT (0);
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ // Initialise the CmObject List.
+ for (Index = 0; Index < EArmObjMax; Index++) {
+ InitializeListHead (&Repo->ArmCmObjList[Index]);
+ }
+
+ Repo->ObjectCount = 0;
+ Repo->RepoState = DynRepoTransient;
+
+ *DynPlatRepo = Repo;
+
+ return EFI_SUCCESS;
+}
+
+/** Shutdown the dynamic platform repository.
+
+ Free all the memory allocated for the dynamic platform repository.
+
+ @param [in] DynPlatRepo The dynamic platform repository.
+
+ @retval EFI_INVALID_PARAMETER A parameter is invalid.
+ @retval EFI_SUCCESS Success.
+**/
+EFI_STATUS
+EFIAPI
+DynamicPlatRepoShutdown (
+ IN DYNAMIC_PLATFORM_REPOSITORY_INFO * DynPlatRepo
+ )
+{
+ EFI_STATUS Status;
+ UINT32 Index;
+ LIST_ENTRY * ListHead;
+ CM_OBJ_DESCRIPTOR * CmObjDesc;
+ VOID * Data;
+
+ if (DynPlatRepo == NULL) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ // Free the list of objects.
+ for (Index = 0; Index < EArmObjMax; Index++) {
+ // Free all the nodes with this object Id.
+ ListHead = &DynPlatRepo->ArmCmObjList[Index];
+ while (!IsListEmpty (ListHead)) {
+ FreeCmObjNode ((CM_OBJ_NODE*)GetFirstNode (ListHead));
+ } // while
+ } // for
+
+ // Free the arrays.
+ CmObjDesc = DynPlatRepo->ArmCmObjArray;
+ for (Index = 0; Index < EArmObjMax; Index++) {
+ Data = CmObjDesc[Index].Data;
+ if (Data != NULL) {
+ FreePool (Data);
+ }
+ } // for
+
+ // Free the TokenMapper
+ Status = TokenMapperShutdown (&DynPlatRepo->TokenMapper);
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ }
+
+ FreePool (DynPlatRepo);
+ return Status;
+}
diff --git a/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/DynamicPlatRepoInternal.h b/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/DynamicPlatRepoInternal.h
new file mode 100644
index 000000000000..d03fa2b7dcec
--- /dev/null
+++ b/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/DynamicPlatRepoInternal.h
@@ -0,0 +1,78 @@
+/** @file
+ Dynamic Platform Info Repository Internal
+
+ Copyright (c) 2021, Arm Limited. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Glossary:
+ - Cm or CM - Configuration Manager
+ - Obj or OBJ - Object
+**/
+
+#ifndef DYNAMIC_PLAT_REPO_INTERNAL_H_
+#define DYNAMIC_PLAT_REPO_INTERNAL_H_
+
+#include "TokenMapper.h"
+
+#pragma pack(1)
+
+/** CmObj node.
+
+ This is a node wrapper around the CM_OBJ_DESCRIPTOR structure.
+ It also allows to bind a token to the CM_OBJ_DESCRIPTOR.
+*/
+typedef struct CmObjectNode {
+ /// This must be the first field in this structure.
+ LIST_ENTRY Link;
+
+ /// Token associated with the CmObjDesc.
+ CM_OBJECT_TOKEN Token;
+
+ /// CmObjDesc wrapped.
+ /// Note: the CM_OBJ_DESCRIPTOR.Data field is allocated and copied.
+ CM_OBJ_DESCRIPTOR CmObjDesc;
+} CM_OBJ_NODE;
+
+/** Dynamic repository states.
+
+ The states must progress as:
+ UnInitialised -> Transient -> Finalized
+*/
+typedef enum DynRepoState {
+ DynRepoUnInitialised, ///< Un-Initialised state
+ DynRepoTransient, ///< Transient state - CmObjects can be added.
+ DynRepoFinalized, ///< Repo Locked - No further CmObjects can be added.
+ ///< Getting objects is now possible.
+ DynRepoMax ///< Max value.
+} EDYNAMIC_REPO_STATE;
+
+/** A structure describing the platform configuration
+ manager repository information
+*/
+typedef struct DynamicPlatformRepositoryInfo {
+ /// Repo state machine.
+ EDYNAMIC_REPO_STATE RepoState;
+
+ /// Count of all the objects added to the Dynamic Platform Repo
+ /// during the Transient state.
+ UINTN ObjectCount;
+
+ /// Link lists of CmObj from the ArmNameSpace
+ /// that are added in the Transient state.
+ LIST_ENTRY ArmCmObjList[EArmObjMax];
+
+ /// Structure Members used in Finalized state.
+ /// An array of CmObj Descriptors from the ArmNameSpace
+ /// This array is populated when the Repo is finalized.
+ CM_OBJ_DESCRIPTOR ArmCmObjArray[EArmObjMax];
+
+ /// A token mapper for the objects in the ArmNamespaceObjectArray
+ /// The Token mapper is populated when the Repo is finalized in
+ /// a call to DynamicPlatRepoFinalise ().
+ TOKEN_MAPPER TokenMapper;
+} DYNAMIC_PLATFORM_REPOSITORY_INFO;
+
+#pragma pack()
+
+#endif // DYNAMIC_PLAT_REPO_INTERNAL_H_
diff --git a/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/DynamicPlatRepoLib.inf b/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/DynamicPlatRepoLib.inf
new file mode 100644
index 000000000000..9a3cc87fd91d
--- /dev/null
+++ b/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/DynamicPlatRepoLib.inf
@@ -0,0 +1,33 @@
+## @file
+# Dynamic Platform Repository
+#
+# Copyright (c) 2021, Arm Limited. All rights reserved.<BR>
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+ INF_VERSION = 0x0001001B
+ BASE_NAME = DynamicPlatRepoLib
+ FILE_GUID = 836D253D-3144-4A89-9BEE-BC55AFDC814E
+ VERSION_STRING = 1.0
+ MODULE_TYPE = DXE_DRIVER
+ LIBRARY_CLASS = DynamicPlatRepoLib
+
+[Sources]
+ CmObjectTokenFixer.c
+ CmObjectTokenFixer.h
+ DynamicPlatRepo.c
+ DynamicPlatRepoInternal.h
+ TokenGenerator.c
+ TokenGenerator.h
+ TokenMapper.c
+ TokenMapper.h
+
+[Packages]
+ MdePkg/MdePkg.dec
+ DynamicTablesPkg/DynamicTablesPkg.dec
+
+[LibraryClasses]
+ AcpiHelperLib
+ BaseLib
--
2.17.1


[PATCH v1 4/5] DynamicTablesPkg: DynamicPlatRepo: Add TokenMapper

PierreGondois
 

From: Pierre Gondois <Pierre.Gondois@arm.com>

The DynamicPlatRepo library allows to handle dynamically created
CmObj. The dynamic platform repository can be in the following states:
1 - Non-initialised
2 - Transient:
Possibility to add CmObj to the platform, but not to query them.
3 - Finalised:
Possibility to query CmObj, but not to add new.

A token is allocated to each CmObj added to the dynamic platform
repository (except for reference tokens CmObj). This allows to retrieve
dynamic CmObjs among all CmObj (static CmObj for instance).

This patch add the TokenMapper files, allowing to retrieve a CmObj
from a token/CmObjId couple.

Signed-off-by: Sami Mujawar <sami.mujawar@arm.com>
Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
---
.../Common/DynamicPlatRepoLib/TokenMapper.c | 214 ++++++++++++++++++
.../Common/DynamicPlatRepoLib/TokenMapper.h | 123 ++++++++++
2 files changed, 337 insertions(+)
create mode 100644 DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/TokenMapper.c
create mode 100644 DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/TokenMapper.h

diff --git a/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/TokenMapper.c b/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/TokenMapper.c
new file mode 100644
index 000000000000..f23bc8c1c7db
--- /dev/null
+++ b/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/TokenMapper.c
@@ -0,0 +1,214 @@
+/** @file
+ Token Mapper
+
+ Copyright (c) 2021, Arm Limited. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Glossary:
+ - Cm or CM - Configuration Manager
+ - Obj or OBJ - Object
+**/
+
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Protocol/ConfigurationManagerProtocol.h>
+
+#include "TokenMapper.h"
+
+/** Add a CmObjDesc to the TokenMapper.
+
+ @param [in] TokenMapper The TokenMapper instance.
+ @param [in] Token CmObj token.
+ @param [in] ObjectId CmObj ObjectId.
+ @param [in] Size CmObj Size.
+ @param [in] Data CmObj Data.
+ This memory is referenced, not copied.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_BUFFER_TOO_SMALL Buffer too small.
+ @retval EFI_INVALID_PARAMETER A parameter is invalid.
+**/
+EFI_STATUS
+EFIAPI
+TokenMapperAddObject (
+ IN TOKEN_MAPPER *TokenMapper,
+ IN CM_OBJECT_TOKEN Token,
+ IN CM_OBJECT_ID ObjectId,
+ IN UINT32 Size,
+ IN VOID *Data
+ )
+{
+ TOKEN_MAP_DESCRIPTOR *TokenMapDesc;
+ CM_OBJ_DESCRIPTOR *CmObjDesc;
+
+ if ((TokenMapper == NULL) ||
+ (TokenMapper->TokenDescArray == NULL) ||
+ (Size == 0) ||
+ (Data == NULL)) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (TokenMapper->ItemCount >= TokenMapper->MaxTokenDescCount) {
+ ASSERT (0);
+ return EFI_BUFFER_TOO_SMALL;
+ }
+
+ TokenMapDesc = &TokenMapper->TokenDescArray[TokenMapper->ItemCount++];
+ TokenMapDesc->Token = Token;
+ CmObjDesc = &TokenMapDesc->CmObjDesc;
+ CmObjDesc->ObjectId = ObjectId;
+ CmObjDesc->Size = Size;
+
+ // Point inside the finalized array.
+ CmObjDesc->Data = Data;
+
+ // Only EArmObjCmRef CmObj can be added as arrays (more than 1 elements).
+ if ((GET_CM_NAMESPACE_ID (ObjectId) == EObjNameSpaceArm) &&
+ (GET_CM_OBJECT_ID (ObjectId) == EArmObjCmRef)) {
+ CmObjDesc->Count = Size / sizeof (CM_ARM_OBJ_REF);
+ } else {
+ CmObjDesc->Count = 1;
+ }
+
+ return EFI_SUCCESS;
+}
+
+/** Get a CmObjDesc from a ObjectId/Token couple.
+
+ The Token parameter is not optional. An existing token must be provided.
+
+ @param [in] TokenMapper The TokenMapper instance.
+ @param [in] Token Token of the CmObj to search.
+ @param [in] ObjectId Object Id of the CmObj to search.
+ @param [out] CmObjDesc CM_OBJ_DESCRIPTOR containing the CmObj searched.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_INVALID_PARAMETER A parameter is invalid.
+ @retval EFI_NOT_FOUND Not found.
+**/
+EFI_STATUS
+EFIAPI
+TokenMapperGetObject (
+ IN TOKEN_MAPPER *TokenMapper,
+ IN CM_OBJECT_TOKEN Token,
+ IN CM_OBJECT_ID ObjectId,
+ OUT CM_OBJ_DESCRIPTOR *CmObjDesc
+ )
+{
+ UINTN Index;
+ UINTN MaxCount;
+ TOKEN_MAP_DESCRIPTOR *TokenMapDesc;
+
+ // Nothing to do.
+ if ((TokenMapper != NULL) && (TokenMapper->MaxTokenDescCount == 0)) {
+ return EFI_SUCCESS;
+ }
+
+ if ((Token == CM_NULL_TOKEN) ||
+ (CmObjDesc == NULL) ||
+ (TokenMapper == NULL) ||
+ (TokenMapper->TokenDescArray == NULL)) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ TokenMapDesc = TokenMapper->TokenDescArray;
+ MaxCount = TokenMapper->MaxTokenDescCount;
+ for (Index = 0; Index < MaxCount; Index++) {
+ if ((TokenMapDesc->CmObjDesc.ObjectId == ObjectId) &&
+ (TokenMapDesc->Token == Token)) {
+ CopyMem (
+ CmObjDesc,
+ &TokenMapDesc->CmObjDesc,
+ sizeof (CM_OBJ_DESCRIPTOR)
+ );
+ return EFI_SUCCESS;
+ }
+ TokenMapDesc++;
+ } // for
+
+ DEBUG ((
+ DEBUG_INFO,
+ "INFO: Requested CmObj of type 0x%x with token 0x%x"
+ " not found in the dynamic repository\n.",
+ ObjectId,
+ Token
+ ));
+ return EFI_NOT_FOUND;
+}
+
+/** Initialise a TokenMapper.
+
+ @param [in] TokenMapper The TokenMapper to initialise.
+ @param [in] DescriptorCount Number of entries to allocate.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ALREADY_STARTED Instance already initialised.
+ @retval EFI_INVALID_PARAMETER A parameter is invalid.
+**/
+EFI_STATUS
+EFIAPI
+TokenMapperInitialise (
+ IN TOKEN_MAPPER * TokenMapper,
+ IN UINTN DescriptorCount
+ )
+{
+ if (TokenMapper == NULL) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ // Nothing to do.
+ if (DescriptorCount == 0) {
+ return EFI_SUCCESS;
+ }
+
+ if (TokenMapper->TokenDescArray != NULL) {
+ DEBUG ((DEBUG_ERROR, "ERROR: Token mapper already initialised\n."));
+ ASSERT (0);
+ return EFI_ALREADY_STARTED;
+ }
+
+ TokenMapper->TokenDescArray =
+ AllocateZeroPool (sizeof (TOKEN_MAP_DESCRIPTOR) * DescriptorCount);
+ if (TokenMapper->TokenDescArray == NULL) {
+ ASSERT (0);
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ TokenMapper->MaxTokenDescCount = DescriptorCount;
+ TokenMapper->ItemCount = 0;
+
+ return EFI_SUCCESS;
+}
+
+/** Shutdown a TokenMapper.
+
+ @param [in] TokenMapper The TokenMapper to shutdown.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_INVALID_PARAMETER A parameter is invalid.
+**/
+EFI_STATUS
+EFIAPI
+TokenMapperShutdown (
+ IN TOKEN_MAPPER * TokenMapper
+ )
+{
+ // Nothing to do.
+ if ((TokenMapper != NULL) && (TokenMapper->MaxTokenDescCount == 0)) {
+ return EFI_SUCCESS;
+ }
+
+ if ((TokenMapper == NULL) ||
+ (TokenMapper->TokenDescArray == NULL)) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ FreePool (TokenMapper->TokenDescArray);
+ return EFI_SUCCESS;
+}
diff --git a/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/TokenMapper.h b/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/TokenMapper.h
new file mode 100644
index 000000000000..377fc03dcd01
--- /dev/null
+++ b/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/TokenMapper.h
@@ -0,0 +1,123 @@
+/** @file
+ Token Mapper
+
+ Copyright (c) 2021, Arm Limited. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Glossary:
+ - Cm or CM - Configuration Manager
+ - Obj or OBJ - Object
+**/
+
+#ifndef TOKEN_MAPPER_H_
+#define TOKEN_MAPPER_H_
+
+#pragma pack(1)
+
+/** Token mapping descriptor.
+
+ Bind a token and a CmObj together.
+*/
+typedef struct TokenMapDescriptor {
+ /// Object Token.
+ CM_OBJECT_TOKEN Token;
+
+ /// CmObjectDescriptor CM_OBJ_DESCRIPTOR.Data is a reference copy
+ /// and not allocated. It points to the individual objects in the
+ /// Dynamic Plat Repo ArmNameSpaceObjectArray.
+ CM_OBJ_DESCRIPTOR CmObjDesc;
+} TOKEN_MAP_DESCRIPTOR;
+
+/** Token mapper.
+
+ Contain all the Token/CmObj couple mapping.
+**/
+typedef struct TokenMapper {
+ /// Maximum number of TOKEN_MAP_DESCRIPTOR entries in TokenDescArray.
+ UINTN MaxTokenDescCount;
+
+ /// Next TOKEN_MAP_DESCRIPTOR entry to use in TokenDescArray.
+ UINTN ItemCount;
+
+ /// Array of TOKEN_MAP_DESCRIPTOR.
+ TOKEN_MAP_DESCRIPTOR * TokenDescArray;
+} TOKEN_MAPPER;
+
+#pragma pack()
+
+/** Add a CmObjDesc to the TokenMapper.
+
+ @param [in] TokenMapper The TokenMapper instance.
+ @param [in] Token CmObj token.
+ @param [in] ObjectId CmObj ObjectId.
+ @param [in] Size CmObj Size.
+ @param [in] Data CmObj Data.
+ This memory is referenced, not copied.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_BUFFER_TOO_SMALL Buffer too small.
+ @retval EFI_INVALID_PARAMETER A parameter is invalid.
+**/
+EFI_STATUS
+EFIAPI
+TokenMapperAddObject (
+ IN TOKEN_MAPPER *TokenMapper,
+ IN CM_OBJECT_TOKEN Token,
+ IN CM_OBJECT_ID ObjectId,
+ IN UINT32 Size,
+ IN VOID *Data
+ );
+
+/** Get a CmObjDesc from a ObjectId/Token couple.
+
+ The Token parameter is not optional. An existing token must be provided.
+
+ @param [in] TokenMapper The TokenMapper instance.
+ @param [in] Token Token of the CmObj to search.
+ @param [in] ObjectId Object Id of the CmObj to search.
+ @param [out] CmObjDesc CM_OBJ_DESCRIPTOR containing the CmObj searched.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_INVALID_PARAMETER A parameter is invalid.
+ @retval EFI_NOT_FOUND Not found.
+**/
+EFI_STATUS
+EFIAPI
+TokenMapperGetObject (
+ IN TOKEN_MAPPER *TokenMapper,
+ IN CM_OBJECT_TOKEN Token,
+ IN CM_OBJECT_ID ObjectId,
+ OUT CM_OBJ_DESCRIPTOR *CmObjDesc
+ );
+
+/** Initialise a TokenMapper.
+
+ @param [in] TokenMapper The TokenMapper to initialise.
+ @param [in] DescriptorCount Number of entries to allocate.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ALREADY_STARTED Instance already initialised.
+ @retval EFI_INVALID_PARAMETER A parameter is invalid.
+**/
+EFI_STATUS
+EFIAPI
+TokenMapperInitialise (
+ IN TOKEN_MAPPER * TokenMapper,
+ IN UINTN DescriptorCount
+ );
+
+/** Shutdown a TokenMapper.
+
+ @param [in] TokenMapper The TokenMapper to shutdown.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_INVALID_PARAMETER A parameter is invalid.
+**/
+EFI_STATUS
+EFIAPI
+TokenMapperShutdown (
+ IN TOKEN_MAPPER * TokenMapper
+ );
+
+#endif // TOKEN_MAPPER_H_
--
2.17.1


[PATCH v1 3/5] DynamicTablesPkg: DynamicPlatRepo: Add TokenFixer

PierreGondois
 

From: Pierre Gondois <Pierre.Gondois@arm.com>

The DynamicPlatRepo library allows to handle dynamically created
CmObj. The dynamic platform repository can be in the following states:
1 - Non-initialised
2 - Transient:
Possibility to add CmObj to the platform, but not to query them.
3 - Finalised:
Possibility to query CmObj, but not to add new.

A token is allocated to each CmObj added to the dynamic platform
repository (except for reference tokens CmObj). This allows to retrieve
dynamic CmObjs among all CmObj (static CmObj for instance).

This patch add the TokenFixer files, allowing to update the
self-token some CmObj have.

Signed-off-by: Sami Mujawar <sami.mujawar@arm.com>
Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
---
.../DynamicPlatRepoLib/CmObjectTokenFixer.c | 164 ++++++++++++++++++
.../DynamicPlatRepoLib/CmObjectTokenFixer.h | 52 ++++++
2 files changed, 216 insertions(+)
create mode 100644 DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/CmObjectTokenFixer.c
create mode 100644 DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/CmObjectTokenFixer.h

diff --git a/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/CmObjectTokenFixer.c b/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/CmObjectTokenFixer.c
new file mode 100644
index 000000000000..74eeefccf4ce
--- /dev/null
+++ b/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/CmObjectTokenFixer.c
@@ -0,0 +1,164 @@
+/** @file
+ Configuration Manager object token fixer
+
+ Copyright (c) 2021, Arm Limited. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Glossary:
+ - Cm or CM - Configuration Manager
+ - Obj or OBJ - Object
+**/
+
+#include <Library/DebugLib.h>
+#include <Protocol/ConfigurationManagerProtocol.h>
+#include "CmObjectTokenFixer.h"
+
+/** Token fixer not implemented.
+
+ Most of the objects are not generated by this parser. Add the missing
+ functions when needed.
+
+ CmObjectToken fixer function that updates the Tokens in the CmObjects.
+
+ @param [in] CmObject Pointer to the Configuration Manager Object.
+ @param [in] Token Token to be updated in the CmObject.
+
+ @retval EFI_SUCCESS Success.
+ @retval EFI_INVALID_PARAMETER A parameter is invalid.
+ @retval EFI_UNSUPPORTED Not supported.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+TokenFixerNotImplemented (
+ IN CM_OBJ_DESCRIPTOR * CmObject,
+ IN CM_OBJECT_TOKEN Token
+ )
+{
+ ASSERT (0);
+ return EFI_UNSUPPORTED;
+}
+
+/** EArmObjItsGroup token fixer.
+
+ CmObjectToken fixer function that updates the Tokens in the CmObjects.
+
+ @param [in] CmObject Pointer to the Configuration Manager Object.
+ @param [in] Token Token to be updated in the CmObject.
+
+ @retval EFI_SUCCESS Success.
+ @retval EFI_INVALID_PARAMETER A parameter is invalid.
+ @retval EFI_UNSUPPORTED Not supported.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+TokenFixerItsGroup (
+ IN CM_OBJ_DESCRIPTOR * CmObject,
+ IN CM_OBJECT_TOKEN Token
+ )
+{
+ ASSERT (CmObject != NULL);
+ ((CM_ARM_ITS_GROUP_NODE*)CmObject)->Token = Token;
+ return EFI_SUCCESS;
+}
+
+/** TokenFixer functions table.
+
+ A CmObj having a CM_OBJECT_TOKEN field might need to have its
+ Token fixed. Each CmObj can have its Token in a specific way.
+*/
+CONST
+CM_OBJECT_TOKEN_FIXER TokenFixer[EArmObjMax] = {
+ NULL, ///< 0 - Reserved
+ NULL, ///< 1 - Boot Architecture Info
+ NULL, ///< 2 - CPU Info
+ NULL, ///< 3 - Power Management Profile Info
+ NULL, ///< 4 - GIC CPU Interface Info
+ NULL, ///< 5 - GIC Distributor Info
+ NULL, ///< 6 - GIC MSI Frame Info
+ NULL, ///< 7 - GIC Redistributor Info
+ NULL, ///< 8 - GIC ITS Info
+ NULL, ///< 9 - Serial Console Port Info
+ NULL, ///< 10 - Serial Debug Port Info
+ NULL, ///< 11 - Generic Timer Info
+ NULL, ///< 12 - Platform GT Block Info
+ NULL, ///< 13 - Generic Timer Block Frame Info
+ NULL, ///< 14 - Platform Generic Watchdog
+ NULL, ///< 15 - PCI Configuration Space Info
+ NULL, ///< 16 - Hypervisor Vendor Id
+ NULL, ///< 17 - Fixed feature flags for FADT
+ TokenFixerItsGroup, ///< 18 - ITS Group
+ TokenFixerNotImplemented, ///< 19 - Named Component
+ TokenFixerNotImplemented, ///< 20 - Root Complex
+ TokenFixerNotImplemented, ///< 21 - SMMUv1 or SMMUv2
+ TokenFixerNotImplemented, ///< 22 - SMMUv3
+ TokenFixerNotImplemented, ///< 23 - PMCG
+ NULL, ///< 24 - GIC ITS Identifier Array
+ NULL, ///< 25 - ID Mapping Array
+ NULL, ///< 26 - SMMU Interrupt Array
+ TokenFixerNotImplemented, ///< 27 - Processor Hierarchy Info
+ TokenFixerNotImplemented, ///< 28 - Cache Info
+ TokenFixerNotImplemented, ///< 29 - Processor Node ID Info
+ NULL, ///< 30 - CM Object Reference
+ NULL, ///< 31 - Memory Affinity Info
+ NULL, ///< 32 - Device Handle Acpi
+ NULL, ///< 33 - Device Handle Pci
+ NULL, ///< 34 - Generic Initiator Affinity
+ NULL, ///< 35 - Generic Serial Port Info
+ NULL, ///< 36 - CMN-600 Info
+ NULL, ///< 37 - Lpi Info
+ NULL, ///< 38 - Pci Address Map Info
+ NULL, ///< 39 - Pci Interrupt Map Info
+};
+
+/** CmObj token fixer.
+
+ Some CmObj structures have a self-token, i.e. they are storing their own
+ token value in the CmObj. Dynamically created CmObj need to have their
+ self-token assigned at some point.
+
+ @param [in] CmObjDesc Pointer to the Configuration Manager Object.
+ @param [in] Token Token to update the CmObjDesc with.
+
+ @retval EFI_SUCCESS Success.
+ @retval EFI_INVALID_PARAMETER A parameter is invalid.
+ @retval EFI_UNSUPPORTED Not supported.
+**/
+EFI_STATUS
+EFIAPI
+FixupCmObjectSelfToken (
+ IN CM_OBJ_DESCRIPTOR * CmObjDesc,
+ IN CM_OBJECT_TOKEN Token
+ )
+{
+ EFI_STATUS Status;
+ CM_OBJECT_TOKEN_FIXER TokenFixerFunc;
+ CM_OBJECT_ID ArmNamespaceObjId;
+
+ // Only support Arm objects for now.
+ if ((CmObjDesc == NULL) ||
+ (GET_CM_NAMESPACE_ID (CmObjDesc->ObjectId) != EObjNameSpaceArm)) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ ArmNamespaceObjId = GET_CM_OBJECT_ID (CmObjDesc->ObjectId);
+ if (ArmNamespaceObjId >= EArmObjMax) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ // Fixup self-token if necessary.
+ TokenFixerFunc = TokenFixer[ArmNamespaceObjId];
+ if (TokenFixerFunc != NULL) {
+ Status = TokenFixerFunc (CmObjDesc, Token);
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+ }
+
+ return EFI_SUCCESS;
+}
diff --git a/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/CmObjectTokenFixer.h b/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/CmObjectTokenFixer.h
new file mode 100644
index 000000000000..d8cc7094697f
--- /dev/null
+++ b/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/CmObjectTokenFixer.h
@@ -0,0 +1,52 @@
+/** @file
+ Configuration Manager object token fixer
+
+ Copyright (c) 2021, Arm Limited. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Glossary:
+ - Cm or CM - Configuration Manager
+ - Obj or OBJ - Object
+**/
+
+#ifndef CM_OBJECT_TOKEN_FIXER_H_
+#define CM_OBJECT_TOKEN_FIXER_H_
+
+/** CmObjectToken fixer function that updates the Tokens in the CmObjects.
+
+ @param [in] CmObject Pointer to the Configuration Manager Object.
+ @param [in] Token Token to be updated in the CmObject.
+
+ @retval EFI_SUCCESS Success.
+ @retval EFI_INVALID_PARAMETER A parameter is invalid.
+ @retval EFI_UNSUPPORTED Not supported.
+**/
+typedef
+EFI_STATUS
+(EFIAPI * CM_OBJECT_TOKEN_FIXER) (
+ IN CM_OBJ_DESCRIPTOR * CmObject,
+ IN CM_OBJECT_TOKEN Token
+ );
+
+/** CmObj token fixer.
+
+ Some CmObj structures have a self-token, i.e. they are storing their own
+ token value in the CmObj. Dynamically created CmObj need to have their
+ self-token assigned at some point.
+
+ @param [in] CmObjDesc Pointer to the Configuration Manager Object.
+ @param [in] Token Token to update the CmObjDesc with.
+
+ @retval EFI_SUCCESS Success.
+ @retval EFI_INVALID_PARAMETER A parameter is invalid.
+ @retval EFI_UNSUPPORTED Not supported.
+**/
+EFI_STATUS
+EFIAPI
+FixupCmObjectSelfToken (
+ IN CM_OBJ_DESCRIPTOR * CmObjDesc,
+ IN CM_OBJECT_TOKEN Token
+ );
+
+#endif // CM_OBJECT_TOKEN_FIXER_H_
--
2.17.1


[PATCH v1 2/5] DynamicTablesPkg: DynamicPlatRepo: Add TokenGenerator

PierreGondois
 

From: Pierre Gondois <Pierre.Gondois@arm.com>

The DynamicPlatRepo library allows to handle dynamically created
CmObj. The dynamic platform repository can be in the following states:
1 - Non-initialised
2 - Transient:
Possibility to add CmObj to the platform, but not to query them.
3 - Finalised:
Possibility to query CmObj, but not to add new.

A token is allocated to each CmObj added to the dynamic platform
repository (except for reference tokens CmObj). This allows to retrieve
dynamic CmObjs among all CmObj (static CmObj for instance).

This patch add the TokenGenerator files.

Signed-off-by: Sami Mujawar <sami.mujawar@arm.com>
Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
---
.../DynamicPlatRepoLib/TokenGenerator.c | 28 +++++++++++++++++++
.../DynamicPlatRepoLib/TokenGenerator.h | 26 +++++++++++++++++
2 files changed, 54 insertions(+)
create mode 100644 DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/TokenGenerator.c
create mode 100644 DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/TokenGenerator.h

diff --git a/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/TokenGenerator.c b/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/TokenGenerator.c
new file mode 100644
index 000000000000..637e784bd284
--- /dev/null
+++ b/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/TokenGenerator.c
@@ -0,0 +1,28 @@
+/** @file
+ Token Generator
+
+ Copyright (c) 2021, Arm Limited. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Glossary:
+ - Cm or CM - Configuration Manager
+ - Obj or OBJ - Object
+**/
+
+#include <Protocol/ConfigurationManagerProtocol.h>
+
+/** Generate a token.
+
+ @return A token.
+**/
+CM_OBJECT_TOKEN
+EFIAPI
+GenerateToken (
+ VOID
+ )
+{
+ // Start Tokens at 1 to avoid collisions with CM_NULL_TOKEN.
+ STATIC UINTN CurrentToken = 1;
+ return (CM_OBJECT_TOKEN)(CurrentToken++);
+}
diff --git a/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/TokenGenerator.h b/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/TokenGenerator.h
new file mode 100644
index 000000000000..44d32e5b41a1
--- /dev/null
+++ b/DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/TokenGenerator.h
@@ -0,0 +1,26 @@
+/** @file
+ Token Generator
+
+ Copyright (c) 2021, Arm Limited. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Glossary:
+ - Cm or CM - Configuration Manager
+ - Obj or OBJ - Object
+**/
+
+#ifndef TOKEN_GENERATOR_H_
+#define TOKEN_GENERATOR_H_
+
+/** Generate a token.
+
+ @return A token.
+**/
+CM_OBJECT_TOKEN
+EFIAPI
+GenerateToken (
+ VOID
+ );
+
+#endif // TOKEN_GENERATOR_H_
--
2.17.1


[PATCH v1 1/5] DynamicTablesPkg: Definition for DynamicPlatRepoLib interface

PierreGondois
 

From: Pierre Gondois <Pierre.Gondois@arm.com>

The DynamicPlatRepoLib library allows to handle dynamically created
CmObj. The dynamic platform repository can be in the following states:
1 - Non-initialised
2 - Transient:
Possibility to add CmObj to the platform, but not to query them.
3 - Finalised:
Possibility to query CmObj, but not to add new.

A token is allocated to each CmObj added to the dynamic platform
repository (except for reference tokens CmObj). This allows to
retrieve dynamic CmObjs among all CmObj (static CmObj for instance).

This patch defines the library interface of the DynamicPlatRepo.

Signed-off-by: Sami Mujawar <sami.mujawar@arm.com>
Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
---
DynamicTablesPkg/DynamicTablesPkg.dec | 3 +
.../Include/Library/DynamicPlatRepoLib.h | 112 ++++++++++++++++++
2 files changed, 115 insertions(+)
create mode 100644 DynamicTablesPkg/Include/Library/DynamicPlatRepoLib.h

diff --git a/DynamicTablesPkg/DynamicTablesPkg.dec b/DynamicTablesPkg/DynamicTablesPkg.dec
index 80a61dd2dbac..9b74c5a67178 100644
--- a/DynamicTablesPkg/DynamicTablesPkg.dec
+++ b/DynamicTablesPkg/DynamicTablesPkg.dec
@@ -24,6 +24,9 @@ [LibraryClasses]
## @libraryclass Defines a set of APIs for Dynamic AML generation.
AmlLib|Include/Library/AmlLib/AmlLib.h

+ ## @libraryclass Defines a set of APIs to handle dynamically created CmObj.
+ DynamicPlatRepoLib|Include/Library/DynamicPlatRepoLib.h
+
## @libraryclass Defines a set of APIs to a hardware information parser.
HwInfoParserLib|Include/Library/HwInfoParserLib.h

diff --git a/DynamicTablesPkg/Include/Library/DynamicPlatRepoLib.h b/DynamicTablesPkg/Include/Library/DynamicPlatRepoLib.h
new file mode 100644
index 000000000000..8e4665bf5c59
--- /dev/null
+++ b/DynamicTablesPkg/Include/Library/DynamicPlatRepoLib.h
@@ -0,0 +1,112 @@
+/** @file
+ Dynamic Platform Info Repository
+
+ Copyright (c) 2021, Arm Limited. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Glossary:
+ - Cm or CM - Configuration Manager
+ - Obj or OBJ - Object
+**/
+
+#ifndef DYNAMIC_PLAT_REPO_H_
+#define DYNAMIC_PLAT_REPO_H_
+
+/** A structure describing the platform configuration
+ manager repository information
+*/
+typedef VOID* DYNAMIC_PLATFORM_REPOSITORY_INFO;
+
+/** Add an object to the dynamic platform repository.
+
+ @param [in] This This dynamic platform repository.
+ @param [in] CmObjDesc CmObj to add. The data is copied.
+ @param [out] Token If not NULL, token allocated to this CmObj.
+
+ @retval EFI_SUCCESS Success.
+ @retval EFI_INVALID_PARAMETER A parameter is invalid.
+ @retval EFI_OUT_OF_RESOURCES An allocation has failed.
+**/
+EFI_STATUS
+EFIAPI
+DynPlatRepoAddObject (
+ IN DYNAMIC_PLATFORM_REPOSITORY_INFO * This,
+ IN CONST CM_OBJ_DESCRIPTOR * CmObjDesc,
+ OUT CM_OBJECT_TOKEN * Token OPTIONAL
+ );
+
+/** Finalise the dynamic repository.
+
+ Finalising means:
+ - Preventing any further objects from being added.
+ - Allowing to get objects from the dynamic repository
+ (not possible before a call to this function).
+
+ @param [in] This This dynamic platform repository.
+
+ @retval EFI_SUCCESS Success.
+ @retval EFI_ALREADY_STARTED Instance already initialised.
+ @retval EFI_INVALID_PARAMETER A parameter is invalid.
+ @retval EFI_BUFFER_TOO_SMALL Buffer too small.
+ @retval EFI_OUT_OF_RESOURCES An allocation has failed.
+**/
+EFI_STATUS
+EFIAPI
+DynamicPlatRepoFinalise (
+ IN DYNAMIC_PLATFORM_REPOSITORY_INFO * This
+ );
+
+/** Get a CmObj from the dynamic repository.
+
+ @param [in] This Pointer to the Dynamic Platform Repository.
+ @param [in] CmObjectId The Configuration Manager Object ID.
+ @param [in] Token An optional token identifying the object. If
+ unused this must be CM_NULL_TOKEN.
+ @param [in, out] CmObjDesc Pointer to the Configuration Manager Object
+ descriptor describing the requested Object.
+
+ @retval EFI_SUCCESS Success.
+ @retval EFI_INVALID_PARAMETER A parameter is invalid.
+ @retval EFI_NOT_FOUND The required object information is not found.
+**/
+EFI_STATUS
+EFIAPI
+DynamicPlatRepoGetObject (
+ IN DYNAMIC_PLATFORM_REPOSITORY_INFO * This,
+ IN CM_OBJECT_ID CmObjectId,
+ IN CM_OBJECT_TOKEN Token OPTIONAL,
+ IN OUT CM_OBJ_DESCRIPTOR * CmObjDesc
+ );
+
+/** Initialize the dynamic platform repository.
+
+ @param [out] DynPlatRepo If success, contains the initialised dynamic
+ platform repository.
+
+ @retval EFI_SUCCESS Success.
+ @retval EFI_INVALID_PARAMETER A parameter is invalid.
+ @retval EFI_OUT_OF_RESOURCES An allocation has failed.
+**/
+EFI_STATUS
+EFIAPI
+DynamicPlatRepoInit (
+ OUT DYNAMIC_PLATFORM_REPOSITORY_INFO ** DynPlatRepo
+ );
+
+/** Shutdown the dynamic platform repository.
+
+ Free all the memory allocated for the dynamic platform repository.
+
+ @param [in] DynPlatRepo The dynamic platform repository.
+
+ @retval EFI_INVALID_PARAMETER A parameter is invalid.
+ @retval EFI_SUCCESS Success.
+**/
+EFI_STATUS
+EFIAPI
+DynamicPlatRepoShutdown (
+ IN DYNAMIC_PLATFORM_REPOSITORY_INFO * DynPlatRepo
+ );
+
+#endif DYNAMIC_PLAT_REPO_H_
--
2.17.1


[PATCH v1 0/5] Add DynamicPlatRepoLib

PierreGondois
 

From: Pierre Gondois <Pierre.Gondois@arm.com>

The DynamicPlatRepoLib is library allowing to receive and then
give Configuration Manager (CM) objects.
After being initialized, a dynamic platform repository can receive
CMObjects. The library generates a token to uniquely identify the
CMObject in the repository. The dynamic platform repository must
then be 'finalized' before receiving CMObject queries.

This library is complementary to the 'static' definition of
CMObjects (i.e. as C structs). It is particularly useful when
using a HwInfoParserLib that dynamically creates CMObjects
(from a device tree for instance).

The changes can be seen at: https://github.com/PierreARM/edk2/tree/1788_Add_Dynamic_Plarform_Repository_Lib_v1
The results of the CI can be seen at: https://github.com/tianocore/edk2/pull/1752

This patch-set is dependent over the following patch-sets:
[PATCH v1 00/10] Various DynamicTablesPkg modifications
https://edk2.groups.io/g/devel/message/76929
and:
[PATCH v1 00/13] Create a SSDT CPU topology generator
https://edk2.groups.io/g/devel/message/76941
and:
[PATCH v1 0/7] Create a SSDT PCIe generator
https://edk2.groups.io/g/devel/message/76958
and:
[PATCH v1 00/14] Implement a FdtHwInfoParserLib
https://edk2.groups.io/g/devel/message/76967

Pierre Gondois (5):
DynamicTablesPkg: Definition for DynamicPlatRepoLib interface
DynamicTablesPkg: DynamicPlatRepo: Add TokenGenerator
DynamicTablesPkg: DynamicPlatRepo: Add TokenFixer
DynamicTablesPkg: DynamicPlatRepo: Add TokenMapper
DynamicTablesPkg: Add DynamicPlatRepo library

DynamicTablesPkg/DynamicTablesPkg.dec | 3 +
DynamicTablesPkg/DynamicTablesPkg.dsc | 1 +
.../Include/Library/DynamicPlatRepoLib.h | 114 ++++
.../DynamicPlatRepoLib/CmObjectTokenFixer.c | 164 ++++++
.../DynamicPlatRepoLib/CmObjectTokenFixer.h | 52 ++
.../DynamicPlatRepoLib/DynamicPlatRepo.c | 518 ++++++++++++++++++
.../DynamicPlatRepoInternal.h | 78 +++
.../DynamicPlatRepoLib/DynamicPlatRepoLib.inf | 33 ++
.../DynamicPlatRepoLib/TokenGenerator.c | 28 +
.../DynamicPlatRepoLib/TokenGenerator.h | 26 +
.../Common/DynamicPlatRepoLib/TokenMapper.c | 214 ++++++++
.../Common/DynamicPlatRepoLib/TokenMapper.h | 123 +++++
12 files changed, 1354 insertions(+)
create mode 100644 DynamicTablesPkg/Include/Library/DynamicPlatRepoLib.h
create mode 100644 DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/CmObjectTokenFixer.c
create mode 100644 DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/CmObjectTokenFixer.h
create mode 100644 DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/DynamicPlatRepo.c
create mode 100644 DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/DynamicPlatRepoInternal.h
create mode 100644 DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/DynamicPlatRepoLib.inf
create mode 100644 DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/TokenGenerator.c
create mode 100644 DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/TokenGenerator.h
create mode 100644 DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/TokenMapper.c
create mode 100644 DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/TokenMapper.h

--
2.17.1


Re: [PATCH v4 0/4] SEV Live Migration support for OVMF.

Dov Murik
 

+cc Tobin


On 22/06/2021 20:46, Ashish Kalra via groups.io wrote:
Hello Laszlo,

Please see my replies below :

On Tue, Jun 22, 2021 at 07:20:53PM +0200, Laszlo Ersek wrote:
-snip-



Anyway, where I'm particularly lost is that I (very vaguely) recall conflicting approaches from AMD and IBM on migration. Has an agreement been reached there?
Yes, these are the slow SEV live migration patches. The fast migration
support is being developed by IBM and that is a separate effort.

As this slow live migration support has now been included in KVM, we
will need the corresponding OVMF and QEMU support now.

I'll also add that the fast (guest-assisted) SEV migration we (IBM) are
working on uses some of the features of the "slow" migration. For
example, for sure, patches 1-3 in this series will be needed to keep the
record of which of the guest pages are encrypted and which are shared
(also in fast migration).

-Dov


Re: [PATCH v6 0/2] CryptoPkg/OpensslLib: Add native instruction support for X64

Yao, Jiewen
 

Hi Christopher
Thank you very much to resume this work. :-)

I have no problem to approve CryptoPkg. (I believe I already did that in last year).

But since you updated base tool. We need base tool package maintainer to approve that change.

A good practice is to split the patch from package level. Then we can let each package maintainer approve its own package.

I will be waiting for the response from base tool owner to review " BaseTools/Scripts/GccBase.lds " and give R-B.


Thank you
Yao Jiewen

-----Original Message-----
From: Christopher Zurcher <christopher.zurcher@outlook.com>
Sent: Tuesday, June 22, 2021 6:05 AM
To: devel@edk2.groups.io; gaoliming@byosoft.com.cn
Cc: Yao, Jiewen <jiewen.yao@intel.com>; Wang, Jian J <jian.j.wang@intel.com>;
Lu, XiaoyuX <xiaoyux.lu@intel.com>; Kinney, Michael D
<michael.d.kinney@intel.com>; 'Ard Biesheuvel' <ard.biesheuvel@arm.com>
Subject: RE: [edk2-devel] [PATCH v6 0/2] CryptoPkg/OpensslLib: Add native
instruction support for X64

Yes this was discussed last year, sorry for the delay in follow-up, I was changing
jobs.
The problem is that the assembly code provided by OpenSSL uses
"wrt ..imagebase" which is only supported by win64, not elf64. It was requested
at the time that I include the OpenSSL-provided .S files as a GCC tool chain
alternative.

Thanks,
Christopher Zurcher

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of gaoliming
Sent: Sunday, June 20, 2021 18:34
To: devel@edk2.groups.io; christopher.zurcher@outlook.com
Cc: 'Jiewen Yao' <jiewen.yao@intel.com>; 'Jian J Wang'
<jian.j.wang@intel.com>; 'Xiaoyu Lu' <xiaoyux.lu@intel.com>; 'Mike Kinney'
<michael.d.kinney@intel.com>; 'Ard Biesheuvel' <ard.biesheuvel@arm.com>
Subject: 回复: [edk2-devel] [PATCH v6 0/2] CryptoPkg/OpensslLib: Add native
instruction support for X64

Christopher:
Nasm should support GCC tool chain. Do you meet with the problem on nasm
version assembly code?
So, you have to add GAS assembly code. This topic may be discussed last year.
Can you give some detail for it?

Thanks
Liming
-----邮件原件-----
发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表 Christopher
Zurcher
发送时间: 2021年6月19日 10:09
收件人: devel@edk2.groups.io
抄送: Jiewen Yao <jiewen.yao@intel.com>; Jian J Wang
<jian.j.wang@intel.com>; Xiaoyu Lu <xiaoyux.lu@intel.com>; Mike Kinney
<michael.d.kinney@intel.com>; Ard Biesheuvel <ard.biesheuvel@arm.com>
主题: [edk2-devel] [PATCH v6 0/2] CryptoPkg/OpensslLib: Add native
instruction support for X64

From: Christopher Zurcher <christopher.zurcher@microsoft.com>

V6 Changes:
Add GCC-compatible version of these modifications. Supporting GCC
build
of
native OpenSSL .S files requires removal of *(COMMON) from the
/DISCARD/
section of the GCC linker script.
The VS/CLANG portion of the patch is unchanged from the
previously-approved
patchset.

V5 Changes:
Move ApiHooks.c into X64 folder
Update process_files.pl to clean architecture-specific subfolders
without
removing them
Rebased INF file to merge latest changes regarding RngLib vs.
TimerLib

V4 Changes:
Add copyright header to uefi-asm.conf
Move [Sources.X64] block to cover entire X64-specific config

V3 Changes:
Added definitions for ptrdiff_t and wchar_t to CrtLibSupport.h for
LLVM/Clang build support.
Added -UWIN32 to GCC Flags for LLVM/Clang build support.
Added missing AES GCM assembly file.

V2 Changes:
Limit scope of assembly config to SHA and AES functions.
Removed IA32 native support (reduced config was causing build
failure
and
can be added in a later patch).
Removed XMM instructions from assembly generation.
Added automatic copyright header porting for generated assembly files.

This patch adds support for building the native instruction algorithms
for the X64 architecture in OpensslLib. The process_files.pl script
was
modified
to parse the .asm file targets from the OpenSSL build config data
struct,
and
generate the necessary assembly files for the EDK2 build environment.

For the X64 variant, OpenSSL includes calls to a Windows error
handling
API,
and that function has been stubbed out in ApiHooks.c.

For all variants, a constructor is added to call the required CPUID
function
within OpenSSL to facilitate processor capability checks in the native
algorithms.

Additional native architecture variants should be simple to add by
following
the changes made for this architecture.

The OpenSSL assembly files are traditionally generated at build time
using
a
perl script. To avoid that burden on EDK2 users, these end-result
assembly files are generated during the configuration steps performed
by the
package
maintainer (through process_files.pl). The perl generator scripts
inside OpenSSL do not parse file comments as they are only meant to
create intermediate build files, so process_files.pl contains
additional hooks to preserve the copyright headers as well as clean up
tabs and line endings
to
comply with EDK2 coding standards. The resulting file headers align
with the generated .h files which are already included in the EDK2 repository.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Xiaoyu Lu <xiaoyux.lu@intel.com>
Cc: Mike Kinney <michael.d.kinney@intel.com>
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>

Christopher Zurcher (2):
CryptoPkg/OpensslLib: Add native instruction support for X64
CryptoPkg/OpensslLib: Commit the auto-generated assembly files for
X64

BaseTools/Scripts/GccBase.lds
| 1 -
CryptoPkg/CryptoPkg.ci.yaml
| 21 +-
CryptoPkg/Library/Include/CrtLibSupport.h
| 2 +
CryptoPkg/Library/Include/openssl/opensslconf.h
| 3 -
CryptoPkg/Library/OpensslLib/OpensslLib.inf
| 2 +-
CryptoPkg/Library/OpensslLib/OpensslLibConstructor.c
| 44 +
CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf
| 2 +-
CryptoPkg/Library/OpensslLib/OpensslLibX64.inf
| 653 +++
CryptoPkg/Library/OpensslLib/OpensslLibX64Gcc.inf
| 653 +++
CryptoPkg/Library/OpensslLib/UefiAsm.conf
| 30 +
CryptoPkg/Library/OpensslLib/X64/ApiHooks.c
| 22 +
CryptoPkg/Library/OpensslLib/X64/crypto/aes/aesni-mb-x86_64.nasm
| 732 +++
CryptoPkg/Library/OpensslLib/X64/crypto/aes/aesni-sha1-x86_64.nasm
| 1916 ++++++++
CryptoPkg/Library/OpensslLib/X64/crypto/aes/aesni-sha256-x86_64.nasm
| 78 +
CryptoPkg/Library/OpensslLib/X64/crypto/aes/aesni-x86_64.nasm
| 5103 ++++++++++++++++++++
CryptoPkg/Library/OpensslLib/X64/crypto/aes/vpaes-x86_64.nasm
| 1173 +++++
CryptoPkg/Library/OpensslLib/X64/crypto/modes/aesni-gcm-x86_64.nasm
| 34 +
CryptoPkg/Library/OpensslLib/X64/crypto/modes/ghash-x86_64.nasm
| 1569 ++++++
CryptoPkg/Library/OpensslLib/X64/crypto/sha/sha1-mb-x86_64.nasm
| 3137 ++++++++++++
CryptoPkg/Library/OpensslLib/X64/crypto/sha/sha1-x86_64.nasm
| 2884 +++++++++++
CryptoPkg/Library/OpensslLib/X64/crypto/sha/sha256-mb-x86_64.nasm
| 3461 +++++++++++++
CryptoPkg/Library/OpensslLib/X64/crypto/sha/sha256-x86_64.nasm
| 3313 +++++++++++++
CryptoPkg/Library/OpensslLib/X64/crypto/sha/sha512-x86_64.nasm
| 1938 ++++++++
CryptoPkg/Library/OpensslLib/X64/crypto/x86_64cpuid.nasm
| 491 ++
CryptoPkg/Library/OpensslLib/X64Gcc/crypto/aes/aesni-mb-x86_64.S
| 552 +++
CryptoPkg/Library/OpensslLib/X64Gcc/crypto/aes/aesni-sha1-x86_64.S
| 1719 +++++++
CryptoPkg/Library/OpensslLib/X64Gcc/crypto/aes/aesni-sha256-x86_64.S
|
69 +
CryptoPkg/Library/OpensslLib/X64Gcc/crypto/aes/aesni-x86_64.S
| 4484 +++++++++++++++++
CryptoPkg/Library/OpensslLib/X64Gcc/crypto/aes/vpaes-x86_64.S
| 863 ++++
CryptoPkg/Library/OpensslLib/X64Gcc/crypto/modes/aesni-gcm-x86_64.S
| 29 +
CryptoPkg/Library/OpensslLib/X64Gcc/crypto/modes/ghash-x86_64.S
| 1386 ++++++
CryptoPkg/Library/OpensslLib/X64Gcc/crypto/sha/sha1-mb-x86_64.S
| 2962 ++++++++++++
CryptoPkg/Library/OpensslLib/X64Gcc/crypto/sha/sha1-x86_64.S
| 2631 ++++++++++
CryptoPkg/Library/OpensslLib/X64Gcc/crypto/sha/sha256-mb-x86_64.S
| 3286 +++++++++++++
CryptoPkg/Library/OpensslLib/X64Gcc/crypto/sha/sha256-x86_64.S
| 3097 ++++++++++++
CryptoPkg/Library/OpensslLib/X64Gcc/crypto/sha/sha512-x86_64.S
| 1811 +++++++
CryptoPkg/Library/OpensslLib/X64Gcc/crypto/x86_64cpuid.S
| 491 ++
CryptoPkg/Library/OpensslLib/process_files.pl
| 241 +-
38 files changed, 50828 insertions(+), 55 deletions(-) create mode
100644 CryptoPkg/Library/OpensslLib/OpensslLibConstructor.c
create mode 100644 CryptoPkg/Library/OpensslLib/OpensslLibX64.inf
create mode 100644 CryptoPkg/Library/OpensslLib/OpensslLibX64Gcc.inf
create mode 100644 CryptoPkg/Library/OpensslLib/UefiAsm.conf
create mode 100644 CryptoPkg/Library/OpensslLib/X64/ApiHooks.c
create mode 100644
CryptoPkg/Library/OpensslLib/X64/crypto/aes/aesni-mb-x86_64.nasm
create mode 100644
CryptoPkg/Library/OpensslLib/X64/crypto/aes/aesni-sha1-x86_64.nasm
create mode 100644
CryptoPkg/Library/OpensslLib/X64/crypto/aes/aesni-sha256-x86_64.nasm
create mode 100644
CryptoPkg/Library/OpensslLib/X64/crypto/aes/aesni-x86_64.nasm
create mode 100644
CryptoPkg/Library/OpensslLib/X64/crypto/aes/vpaes-x86_64.nasm
create mode 100644
CryptoPkg/Library/OpensslLib/X64/crypto/modes/aesni-gcm-x86_64.nasm
create mode 100644
CryptoPkg/Library/OpensslLib/X64/crypto/modes/ghash-x86_64.nasm
create mode 100644
CryptoPkg/Library/OpensslLib/X64/crypto/sha/sha1-mb-x86_64.nasm
create mode 100644
CryptoPkg/Library/OpensslLib/X64/crypto/sha/sha1-x86_64.nasm
create mode 100644
CryptoPkg/Library/OpensslLib/X64/crypto/sha/sha256-mb-x86_64.nasm
create mode 100644
CryptoPkg/Library/OpensslLib/X64/crypto/sha/sha256-x86_64.nasm
create mode 100644
CryptoPkg/Library/OpensslLib/X64/crypto/sha/sha512-x86_64.nasm
create mode 100644
CryptoPkg/Library/OpensslLib/X64/crypto/x86_64cpuid.nasm
create mode 100644
CryptoPkg/Library/OpensslLib/X64Gcc/crypto/aes/aesni-mb-x86_64.S
create mode 100644
CryptoPkg/Library/OpensslLib/X64Gcc/crypto/aes/aesni-sha1-x86_64.S
create mode 100644
CryptoPkg/Library/OpensslLib/X64Gcc/crypto/aes/aesni-sha256-x86_64.S
create mode 100644
CryptoPkg/Library/OpensslLib/X64Gcc/crypto/aes/aesni-x86_64.S
create mode 100644
CryptoPkg/Library/OpensslLib/X64Gcc/crypto/aes/vpaes-x86_64.S
create mode 100644
CryptoPkg/Library/OpensslLib/X64Gcc/crypto/modes/aesni-gcm-x86_64.S
create mode 100644
CryptoPkg/Library/OpensslLib/X64Gcc/crypto/modes/ghash-x86_64.S
create mode 100644
CryptoPkg/Library/OpensslLib/X64Gcc/crypto/sha/sha1-mb-x86_64.S
create mode 100644
CryptoPkg/Library/OpensslLib/X64Gcc/crypto/sha/sha1-x86_64.S
create mode 100644
CryptoPkg/Library/OpensslLib/X64Gcc/crypto/sha/sha256-mb-x86_64.S
create mode 100644
CryptoPkg/Library/OpensslLib/X64Gcc/crypto/sha/sha256-x86_64.S
create mode 100644
CryptoPkg/Library/OpensslLib/X64Gcc/crypto/sha/sha512-x86_64.S
create mode 100644
CryptoPkg/Library/OpensslLib/X64Gcc/crypto/x86_64cpuid.S

--
2.32.0.windows.1










[PATCH v1 14/14] DynamicTablesPkg: Add FdtHwInfoParser library

PierreGondois
 

From: Pierre Gondois <Pierre.Gondois@arm.com>

Hardware information parser is an optional module defined
by the Dynamic Tables Framework. It can either parse an
XML, a Device Tree or a Json file containing the platform
hardware information to populate the platform information
repository.

FdtHwInfoParser library is an instance of a HwInfoParser
that parses a Device Tree and populates the Configuration
Manager Platform information repository.

FdtHwInfoParser library is aimed at providing a solution
for generating ACPI tables for Guest Partitions launched
by virtual machine managers (VMMs). One such use case is
Kvmtool where the Device Tree for the Guest is passed on
to the firmware by Kvmtool. The Configuration Manager for
Kvmtool firmware shall invoke the FdtHwInfoParser to parse
the Device Tree to populate the hardware information in
the Platform Info Repository. The Kvmtool Configuration
Manager can the process this information to generate the
required ACPI tables for the Guest VM.

This approach also scales well if the number of CPUs or
if the hardware configuration of the Guest partition is
varied.

FdtHwInfoParser thereby introduces 'Dynamic Tables for
Virtual Machines'.

Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
Signed-off-by: Sami Mujawar <sami.mujawar@arm.com>
---
DynamicTablesPkg/DynamicTablesPkg.dsc | 3 +-
.../FdtHwInfoParserLib/FdtHwInfoParser.c | 193 ++++++++++++++++++
.../FdtHwInfoParserLib/FdtHwInfoParser.h | 63 ++++++
.../FdtHwInfoParserInclude.h | 17 ++
.../FdtHwInfoParserLib/FdtHwInfoParserLib.inf | 56 +++++
5 files changed, 331 insertions(+), 1 deletion(-)
create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtHwInfoParser.c
create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtHwInfoParser.h
create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtHwInfoParserInclude.h
create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtHwInfoParserLib.inf

diff --git a/DynamicTablesPkg/DynamicTablesPkg.dsc b/DynamicTablesPkg/DynamicTablesPkg.dsc
index 46b2e667fd25..fd7345891cf1 100644
--- a/DynamicTablesPkg/DynamicTablesPkg.dsc
+++ b/DynamicTablesPkg/DynamicTablesPkg.dsc
@@ -2,7 +2,7 @@
# Dsc file for Dynamic Tables Framework.
#
# Copyright (c) 2019, Linaro Limited. All rights reserved.<BR>
-# Copyright (c) 2019 - 2020, Arm Limited. All rights reserved.<BR>
+# Copyright (c) 2019 - 2021, Arm Limited. All rights reserved.<BR>
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
@@ -42,6 +42,7 @@ [Components.common]
DynamicTablesPkg/Library/Common/AmlLib/AmlLib.inf
DynamicTablesPkg/Library/Common/SsdtSerialPortFixupLib/SsdtSerialPortFixupLib.inf
DynamicTablesPkg/Library/Common/TableHelperLib/TableHelperLib.inf
+ DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtHwInfoParserLib.inf

[BuildOptions]
*_*_*_CC_FLAGS = -D DISABLE_NEW_DEPRECATED_INTERFACES
diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtHwInfoParser.c b/DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtHwInfoParser.c
new file mode 100644
index 000000000000..ab3ac58b994e
--- /dev/null
+++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtHwInfoParser.c
@@ -0,0 +1,193 @@
+/** @file
+ Flattened Device Tree parser library for KvmTool.
+
+ Copyright (c) 2021, ARM Limited. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include "FdtHwInfoParser.h"
+#include "BootArch/ArmBootArchParser.h"
+#include "GenericTimer/ArmGenericTimerParser.h"
+#include "Gic/ArmGicDispatcher.h"
+#include "Pci/ArmPciConfigSpaceParser.h"
+#include "Serial/ArmSerialPortParser.h"
+
+/** Ordered table of parsers/dispatchers.
+
+ A parser parses a Device Tree to populate a specific CmObj type. None,
+ one or many CmObj can be created by the parser.
+ The created CmObj are then handed to the parser's caller through the
+ HW_INFO_ADD_OBJECT interface.
+ This can also be a dispatcher. I.e. a function that not parsing a
+ Device Tree but calling other parsers.
+*/
+STATIC CONST FDT_HW_INFO_PARSER_FUNC HwInfoParserTable[] = {
+ ArmBootArchInfoParser,
+ ArmGenericTimerInfoParser,
+ ArmGicDispatcher,
+ ArmPciConfigInfoParser,
+ SerialPortDispatcher
+};
+
+/** Main dispatcher: sequentially call the parsers/dispatchers
+ of the HwInfoParserTable.
+
+ A parser parses a Device Tree to populate a specific CmObj type. None,
+ one or many CmObj can be created by the parser.
+ The created CmObj are then handed to the parser's caller through the
+ HW_INFO_ADD_OBJECT interface.
+ This can also be a dispatcher. I.e. a function that not parsing a
+ Device Tree but calling other parsers.
+
+ @param [in] FdtParserHandle A handle to the parser instance.
+ @param [in] FdtBranch When searching for DT node name, restrict
+ the search to this Device Tree branch.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ABORTED An error occurred.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval EFI_NOT_FOUND Not found.
+ @retval EFI_UNSUPPORTED Unsupported.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+MainDispatcher (
+ IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle,
+ IN INT32 FdtBranch
+ )
+{
+ EFI_STATUS Status;
+ UINT32 Index;
+
+ if (fdt_check_header (FdtParserHandle->Fdt) < 0) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ for (Index = 0; Index < ARRAY_SIZE (HwInfoParserTable); Index++) {
+ Status = HwInfoParserTable[Index] (
+ FdtParserHandle,
+ FdtBranch
+ );
+ if (EFI_ERROR (Status) &&
+ (Status != EFI_NOT_FOUND)) {
+ // If EFI_NOT_FOUND, the parser didn't find information in the DT.
+ // Don't trigger an error.
+ ASSERT (0);
+ return Status;
+ }
+ } // for
+
+ return EFI_SUCCESS;
+}
+
+/** Initialise the HwInfoParser.
+
+ The HwInfoParser shall use the information provided by the HwDataSource
+ to initialise the internal state of the parser or to index the data. This
+ internal state shall be linked to the ParserHandle using an implementation
+ defined mechanism.
+
+ @param [in] HwDataSource Pointer to the blob containing the hardware
+ information. It can be a pointer to a Device
+ Tree, an XML file, etc. or any other data
+ structure defined by the HwInfoParser.
+ @param [in] Context A pointer to the caller's context.
+ @param [in] HwInfoAdd Function pointer called by the parser when
+ adding information.
+ @param [out] ParserHandle A handle to the parser instance.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+**/
+EFI_STATUS
+EFIAPI
+HwInfoParserInit (
+ IN VOID * HwDataSource,
+ IN VOID * Context,
+ IN HW_INFO_ADD_OBJECT HwInfoAdd,
+ OUT HW_INFO_PARSER_HANDLE * ParserHandle
+ )
+{
+ FDT_HW_INFO_PARSER * FdtParserHandle;
+
+ if ((ParserHandle == NULL) ||
+ (HwInfoAdd == NULL) ||
+ (HwDataSource == NULL) ||
+ (fdt_check_header (HwDataSource) < 0)) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ FdtParserHandle = AllocateZeroPool (sizeof (FDT_HW_INFO_PARSER));
+ if (FdtParserHandle == NULL) {
+ *ParserHandle = NULL;
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ // The HwDataSource is a pointer to the FDT data.
+ FdtParserHandle->Fdt = HwDataSource;
+ FdtParserHandle->Context = Context;
+ FdtParserHandle->HwInfoAdd = HwInfoAdd;
+
+ *ParserHandle = (HW_INFO_PARSER_HANDLE)FdtParserHandle;
+ return EFI_SUCCESS;
+}
+
+/** Parse the data provided by the HwDataSource.
+
+ @param [in] ParserHandle A handle to the parser instance.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval EFI_OUT_OF_RESOURCES An allocation has failed.
+**/
+EFI_STATUS
+EFIAPI
+HwInfoParse (
+ IN HW_INFO_PARSER_HANDLE ParserHandle
+ )
+{
+ EFI_STATUS Status;
+
+ if (ParserHandle == NULL) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ // Call all the parsers from the root node (-1).
+ Status = MainDispatcher (
+ (FDT_HW_INFO_PARSER_HANDLE)ParserHandle,
+ -1
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ }
+
+ return Status;
+}
+
+/** Cleanup any internal state and resources that were allocated
+ by the the HwInfoParser.
+
+ @param [in] ParserHandle A handle to the parser instance.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+**/
+EFI_STATUS
+EFIAPI
+HwInfoParserShutdown (
+ IN HW_INFO_PARSER_HANDLE ParserHandle
+)
+{
+ if (ParserHandle == NULL) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ FreePool (ParserHandle);
+
+ return EFI_SUCCESS;
+}
diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtHwInfoParser.h b/DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtHwInfoParser.h
new file mode 100644
index 000000000000..1c40fc5587c9
--- /dev/null
+++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtHwInfoParser.h
@@ -0,0 +1,63 @@
+/** @file
+ Flattened Device Tree parser definitions.
+
+ Copyright (c) 2021, ARM Limited. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef FDT_HW_INFO_PARSER_H_
+#define FDT_HW_INFO_PARSER_H_
+
+#include <FdtHwInfoParserInclude.h>
+
+#include <ConfigurationManagerObject.h>
+#include <Library/HwInfoParserLib.h>
+
+#include "FdtUtility.h"
+
+/** A structure describing the instance of the FdtHwInfoParser.
+*/
+typedef struct FdtHwInfoParser {
+ /// Pointer to the HwDataSource i.e. the
+ /// Flattened Device Tree (Fdt).
+ VOID * Fdt;
+
+ /// Pointer to the caller's context.
+ VOID * Context;
+
+ /// Function pointer called by the
+ /// parser when adding information.
+ HW_INFO_ADD_OBJECT HwInfoAdd;
+} FDT_HW_INFO_PARSER;
+
+/** A pointer type for FDT_HW_INFO_PARSER.
+*/
+typedef FDT_HW_INFO_PARSER* FDT_HW_INFO_PARSER_HANDLE;
+
+/** Function pointer to a parser function.
+
+ A parser parses a Device Tree to populate a specific CmObj type. None,
+ one or many CmObj can be created by the parser.
+ The created CmObj are then handed to the parser's caller through the
+ HW_INFO_ADD_OBJECT interface.
+ This can also be a dispatcher. I.e. a function that not parsing a
+ Device Tree but calling other parsers.
+
+ @param [in] ParserHandle Handle to the parser instance.
+ @param [in] FdtBranch When searching for DT node name, restrict
+ the search to this Device Tree branch.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ABORTED An error occurred.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval EFI_NOT_FOUND Not found.
+ @retval EFI_UNSUPPORTED Unsupported.
+**/
+typedef
+EFI_STATUS
+(EFIAPI * FDT_HW_INFO_PARSER_FUNC) (
+ IN CONST FDT_HW_INFO_PARSER_HANDLE ParserHandle,
+ IN INT32 FdtBranch
+ );
+
+#endif // FDT_HW_INFO_PARSER_H_
diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtHwInfoParserInclude.h b/DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtHwInfoParserInclude.h
new file mode 100644
index 000000000000..583f290095d9
--- /dev/null
+++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtHwInfoParserInclude.h
@@ -0,0 +1,17 @@
+/** @file
+ Include file for Fdt HwInfoParser.
+
+ Copyright (c) 2021, ARM Limited. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef FDT_HW_INFO_PARSER_INCLUDE_H_
+#define FDT_HW_INFO_PARSER_INCLUDE_H_
+
+#include <Base.h>
+#include <libfdt.h>
+#include <Library/ArmLib.h>
+#include <Library/DebugLib.h>
+#include <Library/MemoryAllocationLib.h>
+
+#endif // FDT_HW_INFO_PARSER_INCLUDE_H_
diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtHwInfoParserLib.inf b/DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtHwInfoParserLib.inf
new file mode 100644
index 000000000000..d2c171accaa5
--- /dev/null
+++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtHwInfoParserLib.inf
@@ -0,0 +1,56 @@
+## @file
+# Flattened Device Tree information parser.
+#
+# Copyright (c) 2021, ARM Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+ INF_VERSION = 0x00010019
+ BASE_NAME = FdtHwInfoParserLib
+ FILE_GUID = F174A422-BC86-41E2-9E9C-C6D6E437F4AD
+ VERSION_STRING = 1.0
+ MODULE_TYPE = DXE_DRIVER
+ LIBRARY_CLASS = HwInfoParserLib
+
+[Sources]
+ CmObjectDescUtility.c
+ CmObjectDescUtility.h
+ FdtHwInfoParserInclude.h
+ FdtHwInfoParser.c
+ FdtHwInfoParser.h
+ FdtUtility.c
+ FdtUtility.h
+ BootArch/ArmBootArchParser.c
+ BootArch/ArmBootArchParser.h
+ GenericTimer/ArmGenericTimerParser.c
+ GenericTimer/ArmGenericTimerParser.h
+ Gic/ArmGicCParser.c
+ Gic/ArmGicCParser.h
+ Gic/ArmGicDispatcher.c
+ Gic/ArmGicDispatcher.h
+ Gic/ArmGicDParser.c
+ Gic/ArmGicDParser.h
+ Gic/ArmGicItsParser.c
+ Gic/ArmGicItsParser.h
+ Gic/ArmGicMsiFrameParser.c
+ Gic/ArmGicMsiFrameParser.h
+ Gic/ArmGicRParser.c
+ Gic/ArmGicRParser.h
+ Pci/ArmPciConfigSpaceParser.c
+ Pci/ArmPciConfigSpaceParser.h
+ Serial/ArmSerialPortParser.c
+ Serial/ArmSerialPortParser.h
+
+[Packages]
+ ArmPkg/ArmPkg.dec
+ DynamicTablesPkg/DynamicTablesPkg.dec
+ EmbeddedPkg/EmbeddedPkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+ MdePkg/MdePkg.dec
+
+[LibraryClasses]
+ DebugLib
+ FdtLib
+ MemoryAllocationLib
--
2.17.1


[PATCH v1 13/14] DynamicTablesPkg: FdtHwInfoParser: Add PCI config parser

PierreGondois
 

From: Pierre Gondois <Pierre.Gondois@arm.com>

On platforms that implement PCIe, the PCIe configuration space
information must be described to a standards-based operating
system in the Memory mapped configuration space base address
Description (MCFG) table.

The PCIe information is described in the platform Device Tree,
the bindings for which can be found at:
- linux/Documentation/devicetree/bindings/pci/
host-generic-pci.yaml

The FdtHwInfoParser implements a PCI configuration space Parser
that parses the platform Device Tree to create
CM_ARM_PCI_CONFIG_SPACE_INFO objects which are encapsulated in a
Configuration Manager descriptor object and added to the platform
information repository.

The platform Configuration Manager can then utilise this
information when generating the MCFG table.

Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
Signed-off-by: Sami Mujawar <sami.mujawar@arm.com>
---
.../Pci/ArmPciConfigSpaceParser.c | 799 ++++++++++++++++++
.../Pci/ArmPciConfigSpaceParser.h | 142 ++++
2 files changed, 941 insertions(+)
create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/Pci/ArmPciConfigSpaceParser.c
create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/Pci/ArmPciConfigSpaceParser.h

diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/Pci/ArmPciConfigSpaceParser.c b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Pci/ArmPciConfigSpaceParser.c
new file mode 100644
index 000000000000..2b1b0749b903
--- /dev/null
+++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Pci/ArmPciConfigSpaceParser.c
@@ -0,0 +1,799 @@
+/** @file
+ Arm PCI Configuration Space Parser.
+
+ Copyright (c) 2021, ARM Limited. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Reference(s):
+ - linux/Documentation/devicetree/bindings/pci/host-generic-pci.yaml
+ - PCI Firmware Specification - Revision 3.0
+ - Open Firmware Recommended Practice: Interrupt Mapping, Version 0.9
+ - Devicetree Specification Release v0.3
+ - linux kernel code
+**/
+
+#include "CmObjectDescUtility.h"
+#include <Library/DebugLib.h>
+
+#include "FdtHwInfoParser.h"
+#include "Pci/ArmPciConfigSpaceParser.h"
+#include "Gic/ArmGicDispatcher.h"
+
+/** List of "compatible" property values for host PCIe bridges nodes.
+
+ Any other "compatible" value is not supported by this module.
+*/
+STATIC CONST COMPATIBILITY_STR PciCompatibleStr[] = {
+ {"pci-host-ecam-generic"}
+};
+
+/** COMPATIBILITY_INFO structure for the PCIe.
+*/
+STATIC CONST COMPATIBILITY_INFO PciCompatibleInfo = {
+ ARRAY_SIZE (PciCompatibleStr),
+ PciCompatibleStr
+};
+
+/** Get the Segment group (also called: Domain Id) of a host-pci node.
+
+ kernel/Documentation/devicetree/bindings/pci/pci.txt:
+ "It is required to either not set this property at all or set it for all
+ host bridges in the system"
+
+ The function checks the "linux,pci-domain" property of the host-pci node.
+ Either all host-pci nodes must have this property, or none of them. If the
+ property is available, read it. Otherwise dynamically assign the Ids.
+
+ @param [in] Fdt Pointer to a Flattened Device Tree (Fdt).
+ @param [in] HostPciNode Offset of a host-pci node.
+ @param [out] SegGroup Segment group assigned to the host-pci controller.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ABORTED An error occurred.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+GetPciSegGroup (
+ IN CONST VOID * Fdt,
+ IN INT32 HostPciNode,
+ OUT INT32 * SegGroup
+ )
+{
+ CONST UINT8 * Data;
+ INT32 DataSize;
+ STATIC INT32 LocalSegGroup = 0;
+
+ if ((Fdt == NULL) ||
+ (SegGroup == NULL)) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Data = fdt_getprop (Fdt, HostPciNode, "linux,pci-domain", &DataSize);
+ if ((Data == NULL) || (DataSize < 0)) {
+ // Did not find property, assign the DomainIds ourselves.
+ if (LocalSegGroup < 0) {
+ // "linux,pci-domain" property was defined for another node.
+ ASSERT (0);
+ return EFI_ABORTED;
+ }
+
+ *SegGroup = LocalSegGroup++;
+ return EFI_SUCCESS;
+ }
+
+ if ((DataSize > sizeof (UINT32)) ||
+ (LocalSegGroup > 0)) {
+ // Property on more than 1 cell or
+ // "linux,pci-domain" property was not defined for a node.
+ ASSERT (0);
+ return EFI_ABORTED;
+ }
+
+ // If one node has the "linux,pci-domain" property, then all the host-pci
+ // nodes must have it.
+ LocalSegGroup = -1;
+
+ *SegGroup = fdt32_to_cpu (*(UINT32*)Data);
+ return EFI_SUCCESS;
+}
+
+/** Parse the bus-range controlled by this host-pci node.
+
+ @param [in] Fdt Pointer to a Flattened Device Tree (Fdt).
+ @param [in] HostPciNode Offset of a host-pci node.
+ @param [in, out] PciInfo PCI_PARSER_TABLE structure storing
+ information about the current host-pci.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ABORTED An error occurred.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+PopulateBusRange (
+ IN CONST VOID * Fdt,
+ IN INT32 HostPciNode,
+ IN OUT PCI_PARSER_TABLE * PciInfo
+ )
+{
+ CONST UINT8 * Data;
+ INT32 DataSize;
+ UINT32 StartBus;
+ UINT32 EndBus;
+
+ if ((Fdt == NULL) ||
+ (PciInfo == NULL)) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Data = fdt_getprop (Fdt, HostPciNode, "bus-range", &DataSize);
+ if ((Data == NULL) || (DataSize < 0)) {
+ // No evidence this property is mandatory. Use default values.
+ StartBus = 0;
+ EndBus = 255;
+ } else if (DataSize == (2 * sizeof (UINT32))) {
+ // If available, the property is on two integers.
+ StartBus = fdt32_to_cpu (((UINT32*)Data)[0]);
+ EndBus = fdt32_to_cpu (((UINT32*)Data)[1]);
+ } else {
+ ASSERT (0);
+ return EFI_ABORTED;
+ }
+
+ PciInfo->PciConfigSpaceInfo.StartBusNumber = StartBus;
+ PciInfo->PciConfigSpaceInfo.EndBusNumber = EndBus;
+
+ return EFI_SUCCESS;
+}
+
+/** Parse the PCI address map.
+
+ The PCI address map is available in the "ranges" device-tree property.
+
+ @param [in] Fdt Pointer to a Flattened Device Tree (Fdt).
+ @param [in] HostPciNode Offset of a host-pci node.
+ @param [in] AddressCells # of cells used to encode an address on
+ the parent bus.
+ @param [in, out] PciInfo PCI_PARSER_TABLE structure storing
+ information about the current host-pci.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ABORTED An error occurred.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval EFI_OUT_OF_RESOURCES An allocation has failed.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+ParseAddressMap (
+ IN CONST VOID * Fdt,
+ IN INT32 HostPciNode,
+ IN INT32 AddressCells,
+ IN OUT PCI_PARSER_TABLE * PciInfo
+ )
+{
+ CONST UINT8 * Data;
+ INT32 DataSize;
+ UINT32 Index;
+ UINT32 Offset;
+ UINT32 AddressMapSize;
+ UINT32 Count;
+ UINT32 PciAddressAttr;
+
+ CM_ARM_PCI_ADDRESS_MAP_INFO * PciAddressMapInfo;
+ UINT32 BufferSize;
+
+ // The mapping is done on AddressMapSize bytes.
+ AddressMapSize = (PCI_ADDRESS_CELLS + AddressCells + PCI_SIZE_CELLS) *
+ sizeof (UINT32);
+
+ Data = fdt_getprop (Fdt, HostPciNode, "ranges", &DataSize);
+ if ((Data == NULL) ||
+ (DataSize < 0) ||
+ ((DataSize % AddressMapSize) != 0)) {
+ // If error or not on AddressMapSize bytes.
+ ASSERT (0);
+ return EFI_ABORTED;
+ }
+
+ Count = DataSize / AddressMapSize;
+
+ // Allocate a buffer to store each address mapping.
+ BufferSize = Count * sizeof (CM_ARM_PCI_ADDRESS_MAP_INFO);
+ PciAddressMapInfo = AllocateZeroPool (BufferSize);
+ if (PciAddressMapInfo == NULL) {
+ ASSERT (0);
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ for (Index = 0; Index < Count; Index++) {
+ Offset = Index * AddressMapSize;
+
+ // Pci address attributes
+ PciAddressAttr = fdt32_to_cpu (*(UINT32*)&Data[Offset]);
+ PciAddressMapInfo[Index].SpaceCode = READ_PCI_SS (PciAddressAttr);
+ Offset += sizeof (UINT32);
+
+ // Pci address
+ PciAddressMapInfo[Index].PciAddress =
+ fdt64_to_cpu (*(UINT64*)&Data[Offset]);
+ Offset += (PCI_ADDRESS_CELLS - 1) * sizeof (UINT32);
+
+ // Cpu address
+ if (AddressCells == 2) {
+ PciAddressMapInfo[Index].CpuAddress =
+ fdt64_to_cpu (*(UINT64*)&Data[Offset]);
+ } else {
+ PciAddressMapInfo[Index].CpuAddress =
+ fdt32_to_cpu (*(UINT32*)&Data[Offset]);
+ }
+ Offset += AddressCells * sizeof (UINT32);
+
+ // Address size
+ PciAddressMapInfo[Index].AddressSize =
+ fdt64_to_cpu (*(UINT64*)&Data[Offset]);
+ Offset += PCI_SIZE_CELLS * sizeof (UINT32);
+ } // for
+
+ PciInfo->Mapping[PciMappingTableAddress].ObjectId =
+ CREATE_CM_ARM_OBJECT_ID (EArmObjPciAddressMapInfo);
+ PciInfo->Mapping[PciMappingTableAddress].Size =
+ sizeof (CM_ARM_PCI_ADDRESS_MAP_INFO) * Count;
+ PciInfo->Mapping[PciMappingTableAddress].Data = PciAddressMapInfo;
+ PciInfo->Mapping[PciMappingTableAddress].Count = Count;
+
+ return EFI_SUCCESS;
+}
+
+/** Parse the PCI interrupt map.
+
+ The PCI interrupt map is available in the "interrupt-map"
+ and "interrupt-map-mask" device-tree properties.
+
+ Cf Devicetree Specification Release v0.3,
+ s2.4.3 Interrupt Nexus Properties
+
+ An interrupt-map must be as:
+ interrupt-map = < [child unit address] [child interrupt specifier]
+ [interrupt-parent]
+ [parent unit address] [parent interrupt specifier] >
+
+ @param [in] Fdt Pointer to a Flattened Device Tree (Fdt).
+ @param [in] HostPciNode Offset of a host-pci node.
+ @param [in, out] PciInfo PCI_PARSER_TABLE structure storing
+ information about the current host-pci.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ABORTED An error occurred.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval EFI_OUT_OF_RESOURCES An allocation has failed.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+ParseIrqMap (
+ IN CONST VOID * Fdt,
+ IN INT32 HostPciNode,
+ IN OUT PCI_PARSER_TABLE * PciInfo
+ )
+{
+ EFI_STATUS Status;
+ CONST UINT8 * Data;
+ INT32 DataSize;
+ UINT32 Index;
+ UINT32 Offset;
+
+ INT32 IntcNode;
+ INT32 IntcAddressCells;
+ INT32 IntcCells;
+
+ INT32 PciIntCells;
+ INT32 IntcPhandle;
+
+ INT32 IrqMapSize;
+ UINT32 IrqMapCount;
+ CONST UINT8 * IrqMapMask;
+ INT32 IrqMapMaskSize;
+
+ INT32 PHandleOffset;
+ UINT32 GicVersion;
+
+ UINT32 PciAddressAttr;
+
+
+ CM_ARM_PCI_INTERRUPT_MAP_INFO * PciInterruptMapInfo;
+ UINT32 BufferSize;
+
+ Data = fdt_getprop (Fdt, HostPciNode, "interrupt-map", &DataSize);
+ if ((Data == NULL) || (DataSize < 0)) {
+ // We cannot check the # for now
+ ASSERT (0);
+ return EFI_ABORTED;
+ } else if (DataSize == 0) {
+ // No device described, so no interrupt-mapping.
+ DEBUG ((
+ DEBUG_WARN,
+ "Fdt parser: No Pci device described in the device tree.\n"
+ ));
+ return EFI_SUCCESS;
+ }
+
+ // PCI interrupts are expected to be on 1 cell. Check it.
+ Status = FdtGetInterruptCellsInfo (Fdt, HostPciNode, &PciIntCells);
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+ if (PciIntCells != PCI_INTERRUPTS_CELLS) {
+ ASSERT (0);
+ return EFI_ABORTED;
+ }
+
+ IrqMapMask = fdt_getprop (
+ Fdt,
+ HostPciNode,
+ "interrupt-map-mask",
+ &IrqMapMaskSize
+ );
+ if ((IrqMapMask == NULL) ||
+ (IrqMapMaskSize !=
+ (PCI_ADDRESS_CELLS + PCI_INTERRUPTS_CELLS) * sizeof (UINT32))) {
+ ASSERT (0);
+ return EFI_ABORTED;
+ }
+
+ // Get the interrupt-controller of the first irq mapping.
+ PHandleOffset = (PCI_ADDRESS_CELLS + PciIntCells) * sizeof (UINT32);
+ if (PHandleOffset > DataSize) {
+ ASSERT (0);
+ return EFI_ABORTED;
+ }
+ IntcPhandle = fdt32_to_cpu (*(UINT32*)&Data[PHandleOffset]);
+ IntcNode = fdt_node_offset_by_phandle (Fdt, IntcPhandle);
+ if (IntcNode < 0) {
+ ASSERT (0);
+ return EFI_ABORTED;
+ }
+
+ // Only support Gic(s) for now.
+ Status = GetGicVersion (Fdt, IntcNode, &GicVersion);
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+
+ // Get the "address-cells" property of the IntcNode.
+ Status = FdtGetAddressInfo (Fdt, IntcNode, &IntcAddressCells, NULL);
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+
+ // Get the "interrupt-cells" property of the IntcNode.
+ Status = FdtGetInterruptCellsInfo (Fdt, IntcNode, &IntcCells);
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+
+ // An irq mapping is done on IrqMapSize bytes
+ // (which includes 1 cell for the PHandle).
+ IrqMapSize = (PCI_ADDRESS_CELLS + PciIntCells + 1
+ + IntcAddressCells + IntcCells) * sizeof (UINT32);
+ if ((DataSize % IrqMapSize) != 0) {
+ // The mapping is not done on IrqMapSize bytes.
+ ASSERT (0);
+ return EFI_ABORTED;
+ }
+ IrqMapCount = DataSize / IrqMapSize;
+
+ // We assume the same interrupt-controller is used for all the mappings.
+ // Check this is correct.
+ for (Index = 0; Index < IrqMapCount; Index++) {
+ if (IntcPhandle != fdt32_to_cpu (
+ *(UINT32*)&Data[(Index * IrqMapSize) + PHandleOffset])) {
+ ASSERT (0);
+ return EFI_ABORTED;
+ }
+ }
+
+ // Allocate a buffer to store each interrupt mapping.
+ IrqMapCount = DataSize / IrqMapSize;
+ BufferSize = IrqMapCount * sizeof (CM_ARM_PCI_ADDRESS_MAP_INFO);
+ PciInterruptMapInfo = AllocateZeroPool (BufferSize);
+ if (PciInterruptMapInfo == NULL) {
+ ASSERT (0);
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ for (Index = 0; Index < IrqMapCount; Index++) {
+ Offset = Index * IrqMapSize;
+
+ // Pci address attributes
+ PciAddressAttr = fdt32_to_cpu (
+ (*(UINT32*)&Data[Offset]) &
+ (*(UINT32*)&IrqMapMask[0])
+ );
+ PciInterruptMapInfo[Index].PciBus = READ_PCI_BBBBBBBB (PciAddressAttr);
+ PciInterruptMapInfo[Index].PciDevice = READ_PCI_DDDDD (PciAddressAttr);
+ Offset += PCI_ADDRESS_CELLS * sizeof (UINT32);
+
+ // Pci irq
+ PciInterruptMapInfo[Index].PciInterrupt = fdt32_to_cpu (
+ (*(UINT32*)&Data[Offset]) &
+ (*(UINT32*)&IrqMapMask[3 * sizeof (UINT32)])
+ );
+ // -1 to translate from device-tree (INTA=1) to ACPI (INTA=0) irq IDs.
+ PciInterruptMapInfo[Index].PciInterrupt -= 1;
+ Offset += PCI_INTERRUPTS_CELLS * sizeof (UINT32);
+
+ // PHandle (skip it)
+ Offset += sizeof (UINT32);
+
+ // "Parent unit address" (skip it)
+ Offset += IntcAddressCells * sizeof (UINT32);
+
+ // Interrupt controller interrupt and flags
+ PciInterruptMapInfo[Index].IntcInterrupt.Interrupt =
+ FdtGetInterruptId ((UINT32*)&Data[Offset]);
+ PciInterruptMapInfo[Index].IntcInterrupt.Flags =
+ FdtGetInterruptFlags ((UINT32*)&Data[Offset]);
+ } // for
+
+ PciInfo->Mapping[PciMappingTableInterrupt].ObjectId =
+ CREATE_CM_ARM_OBJECT_ID (EArmObjPciInterruptMapInfo);
+ PciInfo->Mapping[PciMappingTableInterrupt].Size =
+ sizeof (CM_ARM_PCI_INTERRUPT_MAP_INFO) * IrqMapCount;
+ PciInfo->Mapping[PciMappingTableInterrupt].Data = PciInterruptMapInfo;
+ PciInfo->Mapping[PciMappingTableInterrupt].Count = IrqMapCount;
+
+ return Status;
+}
+
+/** Parse a Host-pci node.
+
+ @param [in] Fdt Pointer to a Flattened Device Tree (Fdt).
+ @param [in] HostPciNode Offset of a host-pci node.
+ @param [in, out] PciInfo The CM_ARM_PCI_CONFIG_SPACE_INFO to populate.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ABORTED An error occurred.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval EFI_OUT_OF_RESOURCES An allocation has failed.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+PciNodeParser (
+ IN CONST VOID * Fdt,
+ IN INT32 HostPciNode,
+ IN OUT PCI_PARSER_TABLE * PciInfo
+ )
+{
+ EFI_STATUS Status;
+ INT32 AddressCells;
+ INT32 SizeCells;
+ CONST UINT8 * Data;
+ INT32 DataSize;
+ INT32 SegGroup;
+
+ if ((Fdt == NULL) ||
+ (PciInfo == NULL)) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ // Segment Group / DomainId
+ Status = GetPciSegGroup (Fdt, HostPciNode, &SegGroup);
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+ PciInfo->PciConfigSpaceInfo.PciSegmentGroupNumber = SegGroup;
+
+ // Bus range
+ Status = PopulateBusRange (Fdt, HostPciNode, PciInfo);
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+
+ Status = FdtGetParentAddressInfo (
+ Fdt,
+ HostPciNode,
+ &AddressCells,
+ &SizeCells
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+
+ // Only support 32/64 bits addresses.
+ if ((AddressCells < 1) ||
+ (AddressCells > 2) ||
+ (SizeCells < 1) ||
+ (SizeCells > 2)) {
+ ASSERT (0);
+ return EFI_ABORTED;
+ }
+
+ Data = fdt_getprop (Fdt, HostPciNode, "reg", &DataSize);
+ if ((Data == NULL) ||
+ (DataSize != ((AddressCells + SizeCells) * sizeof (UINT32)))) {
+ // If error or wrong size.
+ ASSERT (0);
+ return EFI_ABORTED;
+ }
+
+ // Base address
+ if (AddressCells == 2) {
+ PciInfo->PciConfigSpaceInfo.BaseAddress = fdt64_to_cpu (*(UINT64*)Data);
+ } else {
+ PciInfo->PciConfigSpaceInfo.BaseAddress = fdt32_to_cpu (*(UINT32*)Data);
+ }
+
+ // Address map
+ Status = ParseAddressMap (
+ Fdt,
+ HostPciNode,
+ AddressCells,
+ PciInfo
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+
+ // Irq map
+ Status = ParseIrqMap (
+ Fdt,
+ HostPciNode,
+ PciInfo
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ }
+
+ return Status;
+}
+
+/** Add the parsed Pci information to the Configuration Manager.
+
+ CmObj of the following types are concerned:
+ - EArmObjPciConfigSpaceInfo
+ - EArmObjPciAddressMapInfo
+ - EArmObjPciInterruptMapInfo
+
+ @param [in] FdtParserHandle A handle to the parser instance.
+ @param [in] PciTableInfo PCI_PARSER_TABLE structure containing the
+ CmObjs to add.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval EFI_OUT_OF_RESOURCES An allocation has failed.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+PciInfoAdd (
+ IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle,
+ IN PCI_PARSER_TABLE *PciTableInfo
+ )
+{
+ EFI_STATUS Status;
+ CM_ARM_PCI_CONFIG_SPACE_INFO *PciConfigSpaceInfo;
+
+ if ((FdtParserHandle == NULL) ||
+ (PciTableInfo == NULL)) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ PciConfigSpaceInfo = &PciTableInfo->PciConfigSpaceInfo;
+
+ // Add the address map space CmObj to the Configuration Manager.
+ Status = AddMultipleCmObjWithCmObjRef (
+ FdtParserHandle,
+ &PciTableInfo->Mapping[PciMappingTableAddress],
+ &PciConfigSpaceInfo->AddressMapToken
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+
+ // Add the interrupt map space CmObj to the Configuration Manager.
+ // Possible to have no device described, and thus no interrupt-mapping.
+ if (PciTableInfo->Mapping[PciMappingTableInterrupt].Count != 0) {
+ Status = AddMultipleCmObjWithCmObjRef (
+ FdtParserHandle,
+ &PciTableInfo->Mapping[PciMappingTableInterrupt],
+ &PciConfigSpaceInfo->InterruptMapToken
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+ }
+
+ // Add the configuration space CmObj to the Configuration Manager.
+ Status = AddSingleCmObj (
+ FdtParserHandle,
+ CREATE_CM_ARM_OBJECT_ID (EArmObjPciConfigSpaceInfo),
+ &PciTableInfo->PciConfigSpaceInfo,
+ sizeof (CM_ARM_PCI_CONFIG_SPACE_INFO),
+ NULL
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ }
+ return Status;
+}
+
+/** Free the CmObjDesc of the ParserTable.
+
+ @param [in] PciTableInfo PCI_PARSER_TABLE structure containing the
+ CmObjs to free.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+FreeParserTable (
+ IN PCI_PARSER_TABLE *PciTableInfo
+ )
+{
+ UINT32 Index;
+ VOID *Data;
+
+ if (PciTableInfo == NULL) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ for (Index = 0; Index < PciMappingTableMax; Index++) {
+ Data = PciTableInfo->Mapping[Index].Data;
+ if (Data != NULL) {
+ FreePool (Data);
+ }
+ }
+
+ return EFI_SUCCESS;
+}
+
+/** CM_ARM_PCI_CONFIG_SPACE_INFO parser function.
+
+ The following structure is populated:
+ typedef struct CmArmPciConfigSpaceInfo {
+ UINT64 BaseAddress; // {Populated}
+ UINT16 PciSegmentGroupNumber; // {Populated}
+ UINT8 StartBusNumber; // {Populated}
+ UINT8 EndBusNumber; // {Populated}
+ } CM_ARM_PCI_CONFIG_SPACE_INFO;
+
+ typedef struct CmArmPciAddressMapInfo {
+ UINT8 SpaceCode; // {Populated}
+ UINT64 PciAddress; // {Populated}
+ UINT64 CpuAddress; // {Populated}
+ UINT64 AddressSize; // {Populated}
+ } CM_ARM_PCI_ADDRESS_MAP_INFO;
+
+ typedef struct CmArmPciInterruptMapInfo {
+ UINT8 PciBus; // {Populated}
+ UINT8 PciDevice; // {Populated}
+ UINT8 PciInterrupt; // {Populated}
+ CM_ARM_GENERIC_INTERRUPT IntcInterrupt; // {Populated}
+ } CM_ARM_PCI_INTERRUPT_MAP_INFO;
+
+ A parser parses a Device Tree to populate a specific CmObj type. None,
+ one or many CmObj can be created by the parser.
+ The created CmObj are then handed to the parser's caller through the
+ HW_INFO_ADD_OBJECT interface.
+ This can also be a dispatcher. I.e. a function that not parsing a
+ Device Tree but calling other parsers.
+
+ @param [in] FdtParserHandle A handle to the parser instance.
+ @param [in] FdtBranch When searching for DT node name, restrict
+ the search to this Device Tree branch.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ABORTED An error occurred.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval EFI_NOT_FOUND Not found.
+ @retval EFI_UNSUPPORTED Unsupported.
+**/
+EFI_STATUS
+EFIAPI
+ArmPciConfigInfoParser (
+ IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle,
+ IN INT32 FdtBranch
+ )
+{
+ EFI_STATUS Status;
+ UINT32 Index;
+ INT32 PciNode;
+ UINT32 PciNodeCount;
+ PCI_PARSER_TABLE PciTableInfo;
+ VOID *Fdt;
+
+ if (FdtParserHandle == NULL) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Fdt = FdtParserHandle->Fdt;
+
+ // Only search host-pci devices.
+ // PCI Firmware Specification Revision 3.0, s4.1.2. "MCFG Table Description":
+ // "This table directly refers to PCI Segment Groups defined in the system
+ // via the _SEG object in the ACPI name space for the applicable host bridge
+ // device."
+ Status = FdtCountCompatNodeInBranch (
+ Fdt,
+ FdtBranch,
+ &PciCompatibleInfo,
+ &PciNodeCount
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+
+ if (PciNodeCount == 0) {
+ return EFI_NOT_FOUND;
+ }
+
+ // Parse each host-pci node in the branch.
+ PciNode = FdtBranch;
+ for (Index = 0; Index < PciNodeCount; Index++) {
+ ZeroMem (&PciTableInfo, sizeof (PCI_PARSER_TABLE));
+
+ Status = FdtGetNextCompatNodeInBranch (
+ Fdt,
+ FdtBranch,
+ &PciCompatibleInfo,
+ &PciNode
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ if (Status == EFI_NOT_FOUND) {
+ // Should have found the node.
+ Status = EFI_ABORTED;
+ }
+ return Status;
+ }
+
+ Status = PciNodeParser (Fdt, PciNode, &PciTableInfo);
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ goto error_handler;
+ }
+
+ // Add Pci information to the Configuration Manager.
+ Status = PciInfoAdd (FdtParserHandle, &PciTableInfo);
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ goto error_handler;
+ }
+
+ Status = FreeParserTable (&PciTableInfo);
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+ } // for
+
+ return Status;
+
+error_handler:
+ FreeParserTable (&PciTableInfo);
+ return Status;
+}
diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/Pci/ArmPciConfigSpaceParser.h b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Pci/ArmPciConfigSpaceParser.h
new file mode 100644
index 000000000000..b260c53a82ab
--- /dev/null
+++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Pci/ArmPciConfigSpaceParser.h
@@ -0,0 +1,142 @@
+/** @file
+ Arm PCI Configuration Space Parser.
+
+ Copyright (c) 2021, ARM Limited. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Reference(s):
+ - linux/Documentation/devicetree/bindings/pci/host-generic-pci.yaml
+ - PCI Firmware Specification - Revision 3.0
+ - Open Firmware Recommended Practice: Interrupt Mapping, Version 0.9
+ - Devicetree Specification Release v0.3
+ - linux kernel code
+**/
+
+#ifndef ARM_PCI_CONFIG_SPACE_PARSER_H_
+#define ARM_PCI_CONFIG_SPACE_PARSER_H_
+
+/** Read LEN bits at OFF offsets bits of the ADDR.
+
+ @param [in] ADDR Address to read the bits from.
+ @param [in] OFF Offset of the bits to read.
+ @param [in] LEN Number of bits to read.
+
+ @return The bits read.
+**/
+#define READ_BITS(ADDR, OFF, LEN) (((ADDR) >> (OFF)) & ((1<<(LEN))-1))
+
+/* Pci address attributes.
+*/
+/// 0 if relocatable.
+#define READ_PCI_N(ADDR) READ_BITS((ADDR), 31, 1)
+/// 1 if prefetchable.
+#define READ_PCI_P(ADDR) READ_BITS((ADDR), 30, 1)
+/// 1 if aliased.
+#define READ_PCI_T(ADDR) READ_BITS((ADDR), 29, 1)
+/** Space code.
+
+ 00: Configuration Space
+ 01: I/O Space
+ 10: 32-bit-address Memory Space
+ 11: 64-bit-address Memory Space
+*/
+#define READ_PCI_SS(ADDR) READ_BITS((ADDR), 24, 2)
+/// Bus number.
+#define READ_PCI_BBBBBBBB(ADDR) READ_BITS((ADDR), 16, 8)
+/// Device number.
+#define READ_PCI_DDDDD(ADDR) READ_BITS((ADDR), 11, 5)
+
+/** Number of device-tree cells used for PCI nodes properties.
+
+ Values are well defined, except the "#interrupt-cells" which
+ is assumed to be 1.
+*/
+#define PCI_ADDRESS_CELLS 3U
+#define PCI_SIZE_CELLS 2U
+#define PCI_INTERRUPTS_CELLS 1U
+
+/** PCI interrupt flags for device-tree.
+
+ Local Bus Specification Revision 3.0, s2.2.6., Interrupt Pins:
+ - 'Interrupts on PCI are optional and defined as "level sensitive,"
+ asserted low (negative true)'
+*/
+#define DT_PCI_IRQ_FLAGS(x) (((x) & 0xF) == BIT0)
+
+/** Indexes in the mapping table.
+*/
+typedef enum PciMappingTable {
+ PciMappingTableAddress, ///< 0 - Address mapping
+ PciMappingTableInterrupt, ///< 1 - Interrupt mapping
+ PciMappingTableMax, ///< 2 - Max
+} PCI_MAPPING_TABLE;
+
+#pragma pack(1)
+
+/** PCI parser table
+
+ Multiple address-map and interrupt map can correspond to
+ one host-pci device. This structure allows to temporarily
+ store the CmObjects created and generate tokens once
+ the whole device tree is parsed.
+*/
+typedef struct PciParserTable {
+ /// PCI Configuration Space Info
+ CM_ARM_PCI_CONFIG_SPACE_INFO PciConfigSpaceInfo;
+
+ /// Store the address mapping and interrupt mapping as CmObjDesc
+ /// before adding them to the Configuration Manager.
+ CM_OBJ_DESCRIPTOR Mapping[PciMappingTableMax];
+} PCI_PARSER_TABLE;
+
+#pragma pack()
+
+/** CM_ARM_PCI_CONFIG_SPACE_INFO parser function.
+
+ The following structure is populated:
+ typedef struct CmArmPciConfigSpaceInfo {
+ UINT64 BaseAddress; // {Populated}
+ UINT16 PciSegmentGroupNumber; // {Populated}
+ UINT8 StartBusNumber; // {Populated}
+ UINT8 EndBusNumber; // {Populated}
+ } CM_ARM_PCI_CONFIG_SPACE_INFO;
+
+ typedef struct CmArmPciAddressMapInfo {
+ UINT8 SpaceCode; // {Populated}
+ UINT64 PciAddress; // {Populated}
+ UINT64 CpuAddress; // {Populated}
+ UINT64 AddressSize; // {Populated}
+ } CM_ARM_PCI_ADDRESS_MAP_INFO;
+
+ typedef struct CmArmPciInterruptMapInfo {
+ UINT8 PciBus; // {Populated}
+ UINT8 PciDevice; // {Populated}
+ UINT8 PciInterrupt; // {Populated}
+ CM_ARM_GENERIC_INTERRUPT IntcInterrupt; // {Populated}
+ } CM_ARM_PCI_INTERRUPT_MAP_INFO;
+
+ A parser parses a Device Tree to populate a specific CmObj type. None,
+ one or many CmObj can be created by the parser.
+ The created CmObj are then handed to the parser's caller through the
+ HW_INFO_ADD_OBJECT interface.
+ This can also be a dispatcher. I.e. a function that not parsing a
+ Device Tree but calling other parsers.
+
+ @param [in] FdtParserHandle A handle to the parser instance.
+ @param [in] FdtBranch When searching for DT node name, restrict
+ the search to this Device Tree branch.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ABORTED An error occurred.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval EFI_NOT_FOUND Not found.
+ @retval EFI_UNSUPPORTED Unsupported.
+**/
+EFI_STATUS
+EFIAPI
+ArmPciConfigInfoParser (
+ IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle,
+ IN INT32 FdtBranch
+ );
+
+#endif // ARM_PCI_CONFIG_SPACE_PARSER_H_
--
2.17.1


[PATCH v1 12/14] DynamicTablesPkg: FdtHwInfoParser: Add GIC dispatcher

PierreGondois
 

From: Pierre Gondois <Pierre.Gondois@arm.com>

The GIC Dispatcher is the top-level component that is responsible
for invoking the respective parsers for GICC, GICD, GIC MSI Frame,
GIC ITS and the GICR.

Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
Signed-off-by: Sami Mujawar <sami.mujawar@arm.com>
---
.../FdtHwInfoParserLib/Gic/ArmGicDispatcher.c | 212 ++++++++++++++++++
.../FdtHwInfoParserLib/Gic/ArmGicDispatcher.h | 72 ++++++
2 files changed, 284 insertions(+)
create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicDispatcher.c
create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicDispatcher.h

diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicDispatcher.c b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicDispatcher.c
new file mode 100644
index 000000000000..3e5d7fb0cba6
--- /dev/null
+++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicDispatcher.c
@@ -0,0 +1,212 @@
+/** @file
+ Arm Gic dispatcher.
+
+ Copyright (c) 2021, ARM Limited. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Reference(s):
+ - linux/Documentation/devicetree/bindings/interrupt-controller/arm,gic.yaml
+ - linux/Documentation/devicetree/bindings/interrupt-controller/arm,gic-v3.yaml
+**/
+
+#include "FdtHwInfoParser.h"
+#include "Gic/ArmGicCParser.h"
+#include "Gic/ArmGicDispatcher.h"
+#include "Gic/ArmGicDParser.h"
+#include "Gic/ArmGicItsParser.h"
+#include "Gic/ArmGicMsiFrameParser.h"
+#include "Gic/ArmGicRParser.h"
+
+/** List of "compatible" property values for GicV2 interrupt nodes.
+
+ Any other "compatible" value is not supported by this module.
+*/
+STATIC CONST COMPATIBILITY_STR GicV2CompatibleStr[] = {
+ {"arm,cortex-a15-gic"}
+};
+
+/** COMPATIBILITY_INFO structure for the GICv2.
+*/
+CONST COMPATIBILITY_INFO GicV2CompatibleInfo = {
+ ARRAY_SIZE (GicV2CompatibleStr),
+ GicV2CompatibleStr
+};
+
+/** List of "compatible" property values for GicV3 interrupt nodes.
+
+ Any other "compatible" value is not supported by this module.
+*/
+STATIC CONST COMPATIBILITY_STR GicV3CompatibleStr[] = {
+ {"arm,gic-v3"}
+};
+
+/** COMPATIBILITY_INFO structure for the GICv3.
+*/
+CONST COMPATIBILITY_INFO GicV3CompatibleInfo = {
+ ARRAY_SIZE (GicV3CompatibleStr),
+ GicV3CompatibleStr
+};
+
+/** Get the Gic version of am interrupt-controller node.
+
+ @param [in] Fdt Pointer to a Flattened Device Tree (Fdt).
+ @param [in] IntcNode Interrupt-controller node.
+ @param [out] GicVersion If success, contains the Gic version of the
+ interrupt-controller node.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval EFI_UNSUPPORTED Unsupported.
+**/
+EFI_STATUS
+EFIAPI
+GetGicVersion (
+ IN CONST VOID * Fdt,
+ IN INT32 IntcNode,
+ OUT UINT32 * GicVersion
+ )
+{
+ if ((Fdt == NULL) ||
+ (GicVersion == NULL)) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (FdtNodeIsCompatible (Fdt, IntcNode, &GicV2CompatibleInfo)) {
+ *GicVersion = 2;
+ } else if (FdtNodeIsCompatible (Fdt, IntcNode, &GicV3CompatibleInfo)) {
+ *GicVersion = 3;
+ } else {
+ // Unsupported Gic version.
+ ASSERT (0);
+ return EFI_UNSUPPORTED;
+ }
+
+ return EFI_SUCCESS;
+}
+
+/** Gic dispatcher.
+
+ This disptacher populates the following structures:
+ - CM_ARM_GICC_INFO
+ - CM_ARM_GICD_INFO
+ - CM_ARM_GIC_MSI_FRAME_INFO
+
+ A parser parses a Device Tree to populate a specific CmObj type. None,
+ one or many CmObj can be created by the parser.
+ The created CmObj are then handed to the parser's caller through the
+ HW_INFO_ADD_OBJECT interface.
+ This can also be a dispatcher. I.e. a function that not parsing a
+ Device Tree but calling other parsers.
+
+ @param [in] FdtParserHandle A handle to the parser instance.
+ @param [in] FdtBranch When searching for DT node name, restrict
+ the search to this Device Tree branch.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ABORTED An error occurred.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval EFI_NOT_FOUND Not found.
+ @retval EFI_UNSUPPORTED Unsupported.
+**/
+EFI_STATUS
+EFIAPI
+ArmGicDispatcher (
+ IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle,
+ IN INT32 FdtBranch
+ )
+{
+ EFI_STATUS Status;
+ INT32 CpusNode;
+ INT32 IntcNode;
+ UINT32 GicVersion;
+ VOID * Fdt;
+
+ if (FdtParserHandle == NULL) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Fdt = FdtParserHandle->Fdt;
+
+ // The "cpus" node resides at the the root of the DT. Fetch it.
+ CpusNode = fdt_path_offset (Fdt, "/cpus");
+ if (CpusNode < 0) {
+ return EFI_NOT_FOUND;
+ }
+
+ // Get the interrupt-controller node associated to the "cpus" node.
+ Status = FdtGetIntcParentNode (Fdt, CpusNode, &IntcNode);
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ if (Status == EFI_NOT_FOUND) {
+ // Should have found the node.
+ Status = EFI_ABORTED;
+ }
+ return Status;
+ }
+
+ Status = GetGicVersion (Fdt, IntcNode, &GicVersion);
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+
+ // Parse the GicC information.
+ Status = ArmGicCInfoParser (FdtParserHandle, CpusNode);
+ if (EFI_ERROR (Status)) {
+ // Don't try to parse GicD and GicMsiFrame information
+ // if no GicC information is found. Return.
+ ASSERT (Status == EFI_NOT_FOUND);
+ return Status;
+ }
+
+ // Parse the GicD information of the "cpus" interrupt-controller node.
+ Status = ArmGicDInfoParser (FdtParserHandle, IntcNode);
+ if (EFI_ERROR (Status)) {
+ // EFI_NOT_FOUND is not tolerated at this point.
+ ASSERT (0);
+ return Status;
+ }
+
+ switch (GicVersion) {
+ case 4:
+ case 3:
+ {
+ // Parse the GicR information of the interrupt-controller node.
+ Status = ArmGicRInfoParser (FdtParserHandle, IntcNode);
+ if (EFI_ERROR (Status)) {
+ // EFI_NOT_FOUND is not tolerated at this point.
+ ASSERT (0);
+ return Status;
+ }
+
+ // Parse the GicIts information of the interrupt-controller node.
+ Status = ArmGicItsInfoParser (FdtParserHandle, IntcNode);
+ if (EFI_ERROR (Status) &&
+ (Status != EFI_NOT_FOUND)) {
+ ASSERT (0);
+ return Status;
+ }
+ break;
+ }
+ case 2:
+ {
+ // Parse the GicMsiFrame information.
+ Status = ArmGicMsiFrameInfoParser (FdtParserHandle, IntcNode);
+ if (EFI_ERROR (Status) &&
+ (Status != EFI_NOT_FOUND)) {
+ ASSERT (0);
+ return Status;
+ }
+ break;
+ }
+ default:
+ {
+ ASSERT (0);
+ return EFI_UNSUPPORTED;
+ }
+ }
+
+ return EFI_SUCCESS;
+}
diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicDispatcher.h b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicDispatcher.h
new file mode 100644
index 000000000000..a0671cea8a67
--- /dev/null
+++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicDispatcher.h
@@ -0,0 +1,72 @@
+/** @file
+ Arm Gic dispatcher.
+
+ Copyright (c) 2021, ARM Limited. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Reference(s):
+ - linux/Documentation/devicetree/bindings/interrupt-controller/arm,gic.yaml
+ - linux/Documentation/devicetree/bindings/interrupt-controller/arm,gic-v3.yaml
+**/
+
+#ifndef ARM_GIC_DISPATCHER_H_
+#define ARM_GIC_DISPATCHER_H_
+
+#include <FdtHwInfoParserInclude.h>
+#include "FdtUtility.h"
+
+/** COMPATIBILITY_INFO structure for the GICv2.
+*/
+extern CONST COMPATIBILITY_INFO GicV2CompatibleInfo;
+
+/** Get the Gic version of the interrupt-controller node.
+
+ @param [in] Fdt Pointer to a Flattened Device Tree (Fdt).
+ @param [in] IntcNode Interrupt-controller node.
+ @param [out] GicVersion If success, contains the Gic version of the
+ interrupt-controller node.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval EFI_UNSUPPORTED Unsupported.
+**/
+EFI_STATUS
+EFIAPI
+GetGicVersion (
+ IN CONST VOID * Fdt,
+ IN INT32 IntcNode,
+ OUT UINT32 * GicVersion
+ );
+
+/** Gic dispatcher.
+
+ This disptacher populates the following structures:
+ - CM_ARM_GICC_INFO
+ - CM_ARM_GICD_INFO
+ - CM_ARM_GIC_MSI_FRAME_INFO
+
+ A parser parses a Device Tree to populate a specific CmObj type. None,
+ one or many CmObj can be created by the parser.
+ The created CmObj are then handed to the parser's caller through the
+ HW_INFO_ADD_OBJECT interface.
+ This can also be a dispatcher. I.e. a function that not parsing a
+ Device Tree but calling other parsers.
+
+ @param [in] FdtParserHandle A handle to the parser instance.
+ @param [in] FdtBranch When searching for DT node name, restrict
+ the search to this Device Tree branch.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ABORTED An error occurred.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval EFI_NOT_FOUND Not found.
+ @retval EFI_UNSUPPORTED Unsupported.
+**/
+EFI_STATUS
+EFIAPI
+ArmGicDispatcher (
+ IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle,
+ IN INT32 FdtBranch
+ );
+
+#endif // ARM_GIC_DISPATCHER_H_
--
2.17.1


[PATCH v1 11/14] DynamicTablesPkg: FdtHwInfoParser: Add GICR parser

PierreGondois
 

From: Pierre Gondois <Pierre.Gondois@arm.com>

The GIC Redistributor (GICR) structure is part of the Multiple
APIC Description Table (MADT) that enables the discovery of
GIC Redistributor base addresses by providing the Physical Base
Address of a page range containing the GIC Redistributors. More
than one GICR Structure may be presented in the MADT. The GICR
structures should only be used when describing GIC version 3 or
higher.

The GIC Redistributor information is described in the platform
Device Tree, the bindings for which can be found at:
- linux/Documentation/devicetree/bindings/interrupt-controller/
arm,gic-v3.yaml

The FdtHwInfoParser implements a GIC Redistributor Parser that
parses the platform Device Tree to create CM_ARM_GIC_REDIST_INFO
objects which are encapsulated in a Configuration Manager
descriptor object and added to the platform information
repository.

The platform Configuration Manager can then utilise this
information when generating the MADT table.

Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
Signed-off-by: Sami Mujawar <sami.mujawar@arm.com>
---
.../FdtHwInfoParserLib/Gic/ArmGicRParser.c | 237 ++++++++++++++++++
.../FdtHwInfoParserLib/Gic/ArmGicRParser.h | 47 ++++
2 files changed, 284 insertions(+)
create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicRParser.c
create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicRParser.h

diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicRParser.c b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicRParser.c
new file mode 100644
index 000000000000..dba4667f722e
--- /dev/null
+++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicRParser.c
@@ -0,0 +1,237 @@
+/** @file
+ Arm Gic Redistributor Parser.
+
+ Copyright (c) 2021, ARM Limited. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Reference(s):
+ - linux/Documentation/devicetree/bindings/interrupt-controller/arm,gic-v3.yaml
+**/
+
+#include "CmObjectDescUtility.h"
+#include "FdtHwInfoParser.h"
+#include "Gic/ArmGicDispatcher.h"
+#include "Gic/ArmGicRParser.h"
+
+/** Parse a Gic compatible interrupt-controller node,
+ extracting GicR information.
+
+ This parser is valid for Gic v3 and higher.
+
+ @param [in] FdtParserHandle A handle to the parser instance.
+ @param [in] GicIntcNode Offset of a Gic compatible
+ interrupt-controller node.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ABORTED An error occurred.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+GicRIntcNodeParser (
+ IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle,
+ IN INT32 GicIntcNode
+ )
+{
+ EFI_STATUS Status;
+ UINT32 Index;
+ UINT32 RedistReg;
+ UINT32 RegSize;
+ INT32 AddressCells;
+ INT32 SizeCells;
+ CONST UINT8 * Data;
+ INT32 DataSize;
+ CM_ARM_GIC_REDIST_INFO GicRInfo;
+ VOID * Fdt;
+
+ if (FdtParserHandle == NULL) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Fdt = FdtParserHandle->Fdt;
+
+ Status = FdtGetParentAddressInfo (
+ Fdt,
+ GicIntcNode,
+ &AddressCells,
+ &SizeCells
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+
+ // Don't support more than 64 bits and less than 32 bits addresses.
+ if ((AddressCells < 1) ||
+ (AddressCells > 2) ||
+ (SizeCells < 1) ||
+ (SizeCells > 2)) {
+ ASSERT (0);
+ return EFI_ABORTED;
+ }
+
+ // The "#redistributor-regions" property is optional.
+ // It indicates the number of GicR.
+ Data = fdt_getprop (Fdt, GicIntcNode, "#redistributor-regions", &DataSize);
+ if ((Data != NULL) && (DataSize == sizeof (UINT32))) {
+ // If available, must be on one cell.
+ RedistReg = fdt32_to_cpu (*(UINT32*)Data);
+ } else {
+ // The DT Spec says GicR is mandatory so we will
+ // always have one.
+ RedistReg = 1;
+ }
+
+ /*
+ Ref: linux/blob/master/Documentation/devicetree/bindings/
+ interrupt-controller/arm%2Cgic-v3.yaml
+
+ reg:
+ description: |
+ Specifies base physical address(s) and size of the GIC
+ registers, in the following order:
+ - GIC Distributor interface (GICD)
+ - GIC Redistributors (GICR), one range per redistributor region
+ - GIC CPU interface (GICC)
+ - GIC Hypervisor interface (GICH)
+ - GIC Virtual CPU interface (GICV)
+ GICC, GICH and GICV are optional.
+ minItems: 2
+ maxItems: 4096
+
+ Example:
+ interrupt-controller@2c010000 {
+ compatible = "arm,gic-v3";
+ #interrupt-cells = <4>;
+ #address-cells = <1>;
+ #size-cells = <1>;
+ ranges;
+ interrupt-controller;
+ redistributor-stride = <0x0 0x40000>; // 256kB stride
+ #redistributor-regions = <2>;
+ reg = <0x2c010000 0x10000>, // GICD
+ <0x2d000000 0x800000>, // GICR 1: CPUs 0-31
+ <0x2e000000 0x800000>, // GICR 2: CPUs 32-63
+ <0x2c040000 0x2000>, // GICC
+ <0x2c060000 0x2000>, // GICH
+ <0x2c080000 0x2000>; // GICV
+ interrupts = <1 9 4>;
+ ...
+ }
+ */
+ RegSize = (AddressCells + SizeCells) * sizeof (UINT32);
+ Data = fdt_getprop (Fdt, GicIntcNode, "reg", &DataSize);
+ if ((Data == NULL) ||
+ (DataSize < 0) ||
+ ((DataSize % RegSize) != 0)) {
+ // If error or wrong size.
+ ASSERT (0);
+ return EFI_ABORTED;
+ }
+
+ Data += GET_DT_REG_ADDRESS_OFFSET (1, AddressCells, SizeCells)
+ * sizeof (UINT32);
+ for (Index = 0; Index < RedistReg; Index++) {
+ ZeroMem (&GicRInfo, sizeof (CM_ARM_GIC_REDIST_INFO));
+
+ if (AddressCells == 2) {
+ GicRInfo.DiscoveryRangeBaseAddress = fdt64_to_cpu (*(UINT64*)Data);
+ } else {
+ GicRInfo.DiscoveryRangeBaseAddress = fdt32_to_cpu (*(UINT32*)Data);
+ }
+ Data += sizeof (UINT32) * AddressCells;
+
+ if (SizeCells == 2) {
+ GicRInfo.DiscoveryRangeLength = (UINT32)fdt64_to_cpu (*(UINT64*)Data);
+ } else {
+ GicRInfo.DiscoveryRangeLength = fdt32_to_cpu (*(UINT32*)Data);
+ }
+
+ // Add the CmObj to the Configuration Manager.
+ Status = AddSingleCmObj (
+ FdtParserHandle,
+ CREATE_CM_ARM_OBJECT_ID (EArmObjGicRedistributorInfo),
+ &GicRInfo,
+ sizeof (CM_ARM_GIC_REDIST_INFO),
+ NULL
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+
+ Data += sizeof (UINT32) * SizeCells;
+ } // for
+
+ return Status;
+}
+
+/** CM_ARM_GIC_REDIST_INFO parser function.
+
+ This parser expects FdtBranch to be a Gic interrupt-controller node.
+ Gic version must be v3 or higher.
+ typedef struct CmArmGicRedistInfo {
+ UINT64 DiscoveryRangeBaseAddress; // {Populated}
+ UINT32 DiscoveryRangeLength; // {Populated}
+ } CM_ARM_GIC_REDIST_INFO;
+
+ A parser parses a Device Tree to populate a specific CmObj type. None,
+ one or many CmObj can be created by the parser.
+ The created CmObj are then handed to the parser's caller through the
+ HW_INFO_ADD_OBJECT interface.
+ This can also be a dispatcher. I.e. a function that not parsing a
+ Device Tree but calling other parsers.
+
+ @param [in] FdtParserHandle A handle to the parser instance.
+ @param [in] FdtBranch When searching for DT node name, restrict
+ the search to this Device Tree branch.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ABORTED An error occurred.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval EFI_NOT_FOUND Not found.
+ @retval EFI_UNSUPPORTED Unsupported.
+**/
+EFI_STATUS
+EFIAPI
+ArmGicRInfoParser (
+ IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle,
+ IN INT32 FdtBranch
+ )
+{
+ EFI_STATUS Status;
+ UINT32 GicVersion;
+ VOID * Fdt;
+
+ if (FdtParserHandle == NULL) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Fdt = FdtParserHandle->Fdt;
+
+ if (!FdtNodeHasProperty (Fdt, FdtBranch, "interrupt-controller")) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ // Get the Gic version of the interrupt-controller.
+ Status = GetGicVersion (Fdt, FdtBranch, &GicVersion);
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+
+ if (GicVersion < 3) {
+ ASSERT (0);
+ return EFI_UNSUPPORTED;
+ }
+
+ Status = GicRIntcNodeParser (FdtParserHandle, FdtBranch);
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ }
+ return Status;
+}
diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicRParser.h b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicRParser.h
new file mode 100644
index 000000000000..ef91c2d32cd9
--- /dev/null
+++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicRParser.h
@@ -0,0 +1,47 @@
+/** @file
+ Arm Gic Redistributor Parser.
+
+ Copyright (c) 2021, ARM Limited. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Reference(s):
+ - linux/Documentation/devicetree/bindings/interrupt-controller/arm,gic-v3.yaml
+**/
+
+#ifndef ARM_GICR_PARSER_H_
+#define ARM_GICR_PARSER_H_
+
+/** CM_ARM_GIC_REDIST_INFO parser function.
+
+ This parser expects FdtBranch to be a Gic interrupt-controller node.
+ Gic version must be v3 or higher.
+ typedef struct CmArmGicRedistInfo {
+ UINT64 DiscoveryRangeBaseAddress; // {Populated}
+ UINT32 DiscoveryRangeLength; // {Populated}
+ } CM_ARM_GIC_REDIST_INFO;
+
+ A parser parses a Device Tree to populate a specific CmObj type. None,
+ one or many CmObj can be created by the parser.
+ The created CmObj are then handed to the parser's caller through the
+ HW_INFO_ADD_OBJECT interface.
+ This can also be a dispatcher. I.e. a function that not parsing a
+ Device Tree but calling other parsers.
+
+ @param [in] FdtParserHandle A handle to the parser instance.
+ @param [in] FdtBranch When searching for DT node name, restrict
+ the search to this Device Tree branch.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ABORTED An error occurred.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval EFI_NOT_FOUND Not found.
+ @retval EFI_UNSUPPORTED Unsupported.
+**/
+EFI_STATUS
+EFIAPI
+ArmGicRInfoParser (
+ IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle,
+ IN INT32 FdtBranch
+ );
+
+#endif // ARM_GICR_PARSER_H_
--
2.17.1


[PATCH v1 10/14] DynamicTablesPkg: FdtHwInfoParser: Add ITS parser

PierreGondois
 

From: Pierre Gondois <Pierre.Gondois@arm.com>

Arm GIC v3/v4 optionally includes support for GIC Interrupt
Translation Service (ITS). The GIC ITS Structure is part of
the Multiple APIC Description Table (MADT) that describes
the GIC Interrupt Translation service to the OS.

The GIC Interrupt Translation Service information is described
in the platform Device Tree, the bindings for which can be
found at:
- linux/Documentation/devicetree/bindings/interrupt-controller/
arm,gic-v3.yaml

The FdtHwInfoParser implements a GIC ITS Parser that parses the
platform Device Tree to create CM_ARM_GIC_ITS_INFO objects which
are encapsulated in a Configuration Manager descriptor object and
added to the platform information repository.

The platform Configuration Manager can then utilise this information
when generating the MADT table.

Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
Signed-off-by: Sami Mujawar <sami.mujawar@arm.com>
---
.../FdtHwInfoParserLib/Gic/ArmGicItsParser.c | 215 ++++++++++++++++++
.../FdtHwInfoParserLib/Gic/ArmGicItsParser.h | 48 ++++
2 files changed, 263 insertions(+)
create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicItsParser.c
create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicItsParser.h

diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicItsParser.c b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicItsParser.c
new file mode 100644
index 000000000000..faaa0df1d9be
--- /dev/null
+++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicItsParser.c
@@ -0,0 +1,215 @@
+/** @file
+ Arm Gic Interrupt Translation Service Parser.
+
+ Copyright (c) 2021, ARM Limited. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Reference(s):
+ - linux/Documentation/devicetree/bindings/interrupt-controller/arm,gic-v3.yaml
+**/
+
+#include "CmObjectDescUtility.h"
+#include "FdtHwInfoParser.h"
+#include "Gic/ArmGicDispatcher.h"
+#include "Gic/ArmGicItsParser.h"
+
+/** Parse a Gic compatible interrupt-controller node,
+ extracting GicIts information.
+
+ This parser is valid for Gic v3 and higher.
+
+ @param [in] Fdt Pointer to a Flattened Device Tree (Fdt).
+ @param [in] GicIntcNode Offset of a Gic compatible
+ interrupt-controller node.
+ @param [in] GicItsId Id for the Gic ITS node.
+ @param [in] GicItsInfo The CM_ARM_GIC_ITS_INFO to populate.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ABORTED An error occurred.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+GicItsIntcNodeParser (
+ IN CONST VOID * Fdt,
+ IN INT32 GicIntcNode,
+ IN UINT32 GicItsId,
+ IN CM_ARM_GIC_ITS_INFO * GicItsInfo
+ )
+{
+ EFI_STATUS Status;
+ INT32 AddressCells;
+ CONST UINT8 * Data;
+ INT32 DataSize;
+
+ if ((Fdt == NULL) ||
+ (GicItsInfo == NULL)) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Status = FdtGetParentAddressInfo (Fdt, GicIntcNode, &AddressCells, NULL);
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+
+ // Don't support more than 64 bits and less than 32 bits addresses.
+ if ((AddressCells < 1) ||
+ (AddressCells > 2)) {
+ ASSERT (0);
+ return EFI_ABORTED;
+ }
+
+ Data = fdt_getprop (Fdt, GicIntcNode, "reg", &DataSize);
+ if ((Data == NULL) || (DataSize < (INT32)(AddressCells * sizeof (UINT32)))) {
+ // If error or not enough space.
+ ASSERT (0);
+ return EFI_ABORTED;
+ }
+
+ if (AddressCells == 2) {
+ GicItsInfo->PhysicalBaseAddress = fdt64_to_cpu (*(UINT64*)Data);
+ } else {
+ GicItsInfo->PhysicalBaseAddress = fdt32_to_cpu (*(UINT32*)Data);
+ }
+
+ // Gic Its Id
+ GicItsInfo->GicItsId = GicItsId;
+
+ // {default = 0}
+ GicItsInfo->ProximityDomain = 0;
+ return Status;
+}
+
+/** CM_ARM_GIC_ITS_INFO parser function.
+
+ This parser expects FdtBranch to be a Gic interrupt-controller node.
+ Gic version must be v3 or higher.
+ typedef struct CmArmGicItsInfo {
+ UINT32 GicItsId; // {Populated}
+ UINT64 PhysicalBaseAddress; // {Populated}
+ UINT32 ProximityDomain; // {default = 0}
+ } CM_ARM_GIC_ITS_INFO;
+
+ A parser parses a Device Tree to populate a specific CmObj type. None,
+ one or many CmObj can be created by the parser.
+ The created CmObj are then handed to the parser's caller through the
+ HW_INFO_ADD_OBJECT interface.
+ This can also be a dispatcher. I.e. a function that not parsing a
+ Device Tree but calling other parsers.
+
+ @param [in] FdtParserHandle A handle to the parser instance.
+ @param [in] FdtBranch When searching for DT node name, restrict
+ the search to this Device Tree branch.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ABORTED An error occurred.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval EFI_NOT_FOUND Not found.
+ @retval EFI_UNSUPPORTED Unsupported.
+**/
+EFI_STATUS
+EFIAPI
+ArmGicItsInfoParser (
+ IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle,
+ IN INT32 FdtBranch
+ )
+{
+ EFI_STATUS Status;
+ UINT32 GicVersion;
+ CM_ARM_GIC_ITS_INFO GicItsInfo;
+ UINT32 Index;
+ INT32 GicItsNode;
+ UINT32 GicItsNodeCount;
+ VOID * Fdt;
+
+ if (FdtParserHandle == NULL) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Fdt = FdtParserHandle->Fdt;
+
+ if (!FdtNodeHasProperty (Fdt, FdtBranch, "interrupt-controller")) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ // Get the Gic version of the interrupt-controller.
+ Status = GetGicVersion (Fdt, FdtBranch, &GicVersion);
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+
+ if (GicVersion < 3) {
+ ASSERT (0);
+ return EFI_UNSUPPORTED;
+ }
+
+ // Count the nodes with the "msi-controller" property.
+ // The interrupt-controller itself can have this property,
+ // but the first node is skipped in the search.
+ Status = FdtCountPropNodeInBranch (
+ Fdt,
+ FdtBranch,
+ "msi-controller",
+ &GicItsNodeCount
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+
+ if (GicItsNodeCount == 0) {
+ return EFI_NOT_FOUND;
+ }
+
+ GicItsNode = FdtBranch;
+ for (Index = 0; Index < GicItsNodeCount; Index++) {
+ ZeroMem (&GicItsInfo, sizeof (CM_ARM_GIC_ITS_INFO));
+
+ Status = FdtGetNextPropNodeInBranch (
+ Fdt,
+ FdtBranch,
+ "msi-controller",
+ &GicItsNode
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ if (Status == EFI_NOT_FOUND) {
+ // Should have found the node.
+ Status = EFI_ABORTED;
+ }
+ return Status;
+ }
+
+ Status = GicItsIntcNodeParser (
+ Fdt,
+ GicItsNode,
+ Index,
+ &GicItsInfo
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+
+ // Add the CmObj to the Configuration Manager.
+ Status = AddSingleCmObj (
+ FdtParserHandle,
+ CREATE_CM_ARM_OBJECT_ID (EArmObjGicItsInfo),
+ &GicItsInfo,
+ sizeof (CM_ARM_GIC_ITS_INFO),
+ NULL
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+ } // for
+
+ return Status;
+}
diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicItsParser.h b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicItsParser.h
new file mode 100644
index 000000000000..6ea498ff71c9
--- /dev/null
+++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicItsParser.h
@@ -0,0 +1,48 @@
+/** @file
+ Arm Gic Interrupt Translation Service Parser.
+
+ Copyright (c) 2021, ARM Limited. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Reference(s):
+ - linux/Documentation/devicetree/bindings/interrupt-controller/arm,gic-v3.yaml
+**/
+
+#ifndef ARM_GIC_ITS_PARSER_H_
+#define ARM_GIC_ITS_PARSER_H_
+
+/** CM_ARM_GIC_ITS_INFO parser function.
+
+ This parser expects FdtBranch to be a Gic interrupt-controller node.
+ Gic version must be v3 or higher.
+ typedef struct CmArmGicItsInfo {
+ UINT32 GicItsId; // {Populated}
+ UINT64 PhysicalBaseAddress; // {Populated}
+ UINT32 ProximityDomain; // {default = 0}
+ } CM_ARM_GIC_ITS_INFO;
+
+ A parser parses a Device Tree to populate a specific CmObj type. None,
+ one or many CmObj can be created by the parser.
+ The created CmObj are then handed to the parser's caller through the
+ HW_INFO_ADD_OBJECT interface.
+ This can also be a dispatcher. I.e. a function that not parsing a
+ Device Tree but calling other parsers.
+
+ @param [in] FdtParserHandle A handle to the parser instance.
+ @param [in] FdtBranch When searching for DT node name, restrict
+ the search to this Device Tree branch.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ABORTED An error occurred.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval EFI_NOT_FOUND Not found.
+ @retval EFI_UNSUPPORTED Unsupported.
+**/
+EFI_STATUS
+EFIAPI
+ArmGicItsInfoParser (
+ IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle,
+ IN INT32 FdtBranch
+ );
+
+#endif // ARM_GIC_ITS_PARSER_H_
--
2.17.1


[PATCH v1 09/14] DynamicTablesPkg: FdtHwInfoParser: Add MSI Frame parser

PierreGondois
 

From: Pierre Gondois <Pierre.Gondois@arm.com>

Arm GIC version 2 systems that support Message Signalled Interrupts
implement GICv2m MSI frame(s). Each GICv2m MSI frame consists of a
4k page which includes registers to generate message signalled
interrupts to an associated GIC distributor. The frame also includes
registers to discover the set of distributor lines which may be
signalled by MSIs from that frame. A system may have multiple MSI
frames, and separate frames may be defined for secure and non-secure
access.

A MSI Frame structure is part of the Multiple APIC Description Table
(MADT) and must only be used to describe non-secure MSI frames.

The MSI Frame information is described in the platform Device Tree,
the bindings for which can be found at:
- linux/Documentation/devicetree/bindings/interrupt-controller/
arm,gic.yaml
- linux/Documentation/devicetree/bindings/interrupt-controller/
arm,gic-v3.yaml

The FdtHwInfoParser implements a MSI Frame Parser that parses
the platform Device Tree to create CM_ARM_GIC_MSI_FRAME_INFO
objects which are encapsulated in a Configuration Manager
descriptor object and added to the platform information
repository.

The platform Configuration Manager can then utilise this
information when generating the MADT table.

Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
Signed-off-by: Sami Mujawar <sami.mujawar@arm.com>
---
.../Gic/ArmGicMsiFrameParser.c | 214 ++++++++++++++++++
.../Gic/ArmGicMsiFrameParser.h | 50 ++++
2 files changed, 264 insertions(+)
create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicMsiFrameParser.c
create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicMsiFrameParser.h

diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicMsiFrameParser.c b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicMsiFrameParser.c
new file mode 100644
index 000000000000..9e6715f69ce7
--- /dev/null
+++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicMsiFrameParser.c
@@ -0,0 +1,214 @@
+/** @file
+ Arm Gic Msi frame Parser.
+
+ Copyright (c) 2021, ARM Limited. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Reference(s):
+ - linux/Documentation/devicetree/bindings/interrupt-controller/arm,gic.yaml
+ - linux/Documentation/devicetree/bindings/interrupt-controller/arm,gic-v3.yaml
+**/
+
+#include "CmObjectDescUtility.h"
+#include "FdtHwInfoParser.h"
+#include "Gic/ArmGicDispatcher.h"
+#include "Gic/ArmGicMsiFrameParser.h"
+
+/** List of "compatible" property values for Msi-frame nodes.
+
+ Any other "compatible" value is not supported by this module.
+*/
+STATIC CONST COMPATIBILITY_STR MsiFrameCompatibleStr[] = {
+ {"arm,gic-v2m-frame"}
+};
+
+/** COMPATIBILITY_INFO structure for the MSI frame.
+*/
+STATIC CONST COMPATIBILITY_INFO MsiFrameCompatibleInfo = {
+ ARRAY_SIZE (MsiFrameCompatibleStr),
+ MsiFrameCompatibleStr
+};
+
+/** Parse a Msi frame node.
+
+ @param [in] Fdt Pointer to a Flattened Device Tree (Fdt).
+ @param [in] MsiFrameNode Offset of a Msi frame node.
+ @param [in] MsiFrameId Frame ID.
+ @param [out] MsiFrameInfo The CM_ARM_GIC_MSI_FRAME_INFO to populate.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ABORTED An error occurred.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+MsiFrameNodeParser (
+ IN CONST VOID * Fdt,
+ IN INT32 MsiFrameNode,
+ IN UINT32 MsiFrameId,
+ OUT CM_ARM_GIC_MSI_FRAME_INFO * MsiFrameInfo
+ )
+{
+ EFI_STATUS Status;
+ INT32 AddressCells;
+ CONST UINT8 * Data;
+ INT32 DataSize;
+
+ if ((Fdt == NULL) ||
+ (MsiFrameInfo == NULL)) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Status = FdtGetParentAddressInfo (Fdt, MsiFrameNode, &AddressCells, NULL);
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+
+ // Don't support more than 64 bits and less than 32 bits addresses.
+ if ((AddressCells < 1) ||
+ (AddressCells > 2)) {
+ ASSERT (0);
+ return EFI_ABORTED;
+ }
+
+ Data = fdt_getprop (Fdt, MsiFrameNode, "reg", &DataSize);
+ if ((Data == NULL) || (DataSize < (INT32)(AddressCells * sizeof (UINT32)))) {
+ // If error or not enough space.
+ ASSERT (0);
+ return EFI_ABORTED;
+ }
+
+ if (AddressCells == 2) {
+ MsiFrameInfo->PhysicalBaseAddress = fdt64_to_cpu (*(UINT64*)Data);
+ } else {
+ MsiFrameInfo->PhysicalBaseAddress = fdt32_to_cpu (*(UINT32*)Data);
+ }
+
+ MsiFrameInfo->GicMsiFrameId = MsiFrameId;
+
+ return EFI_SUCCESS;
+}
+
+/** CM_ARM_GIC_MSI_FRAME_INFO parser function.
+
+ The following structure is populated:
+ typedef struct CmArmGicMsiFrameInfo {
+ UINT32 GicMsiFrameId; // {Populated}
+ UINT64 PhysicalBaseAddress; // {Populated}
+ UINT32 Flags; // {default = 0}
+ UINT16 SPICount;
+ UINT16 SPIBase;
+ } CM_ARM_GIC_MSI_FRAME_INFO;
+
+ A parser parses a Device Tree to populate a specific CmObj type. None,
+ one or many CmObj can be created by the parser.
+ The created CmObj are then handed to the parser's caller through the
+ HW_INFO_ADD_OBJECT interface.
+ This can also be a dispatcher. I.e. a function that not parsing a
+ Device Tree but calling other parsers.
+
+ @param [in] FdtParserHandle A handle to the parser instance.
+ @param [in] FdtBranch When searching for DT node name, restrict
+ the search to this Device Tree branch.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ABORTED An error occurred.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval EFI_NOT_FOUND Not found.
+ @retval EFI_UNSUPPORTED Unsupported.
+**/
+EFI_STATUS
+EFIAPI
+ArmGicMsiFrameInfoParser (
+ IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle,
+ IN INT32 FdtBranch
+ )
+{
+ EFI_STATUS Status;
+ INT32 MsiFrameNode;
+ UINT32 MsiFrameNodeCount;
+
+ UINT32 Index;
+ CM_ARM_GIC_MSI_FRAME_INFO MsiFrameInfo;
+ VOID * Fdt;
+
+ if (FdtParserHandle == NULL) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Fdt = FdtParserHandle->Fdt;
+
+ // Count the number of nodes having the "interrupt-controller" property.
+ Status = FdtCountPropNodeInBranch (
+ Fdt,
+ FdtBranch,
+ "msi-controller",
+ &MsiFrameNodeCount
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+
+ if (MsiFrameNodeCount == 0) {
+ return EFI_NOT_FOUND;
+ }
+
+ // Parse each node having the "msi-controller" property.
+ MsiFrameNode = FdtBranch;
+ for (Index = 0; Index < MsiFrameNodeCount; Index++) {
+ ZeroMem (&MsiFrameInfo, sizeof (CM_ARM_GIC_MSI_FRAME_INFO));
+
+ Status = FdtGetNextPropNodeInBranch (
+ Fdt,
+ FdtBranch,
+ "msi-controller",
+ &MsiFrameNode
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ if (Status == EFI_NOT_FOUND) {
+ // Should have found the node.
+ Status = EFI_ABORTED;
+ }
+ return Status;
+ }
+
+ if (!FdtNodeIsCompatible (Fdt, MsiFrameNode, &MsiFrameCompatibleInfo)) {
+ ASSERT (0);
+ Status = EFI_UNSUPPORTED;
+ return Status;
+ }
+
+ // Parse the Msi information.
+ Status = MsiFrameNodeParser (
+ Fdt,
+ MsiFrameNode,
+ Index,
+ &MsiFrameInfo
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+
+ // Add the CmObj to the Configuration Manager.
+ Status = AddSingleCmObj (
+ FdtParserHandle,
+ CREATE_CM_ARM_OBJECT_ID (EArmObjGicMsiFrameInfo),
+ &MsiFrameInfo,
+ sizeof (CM_ARM_GIC_MSI_FRAME_INFO),
+ NULL
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+ } // for
+
+ return Status;
+}
diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicMsiFrameParser.h b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicMsiFrameParser.h
new file mode 100644
index 000000000000..40f83010a686
--- /dev/null
+++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicMsiFrameParser.h
@@ -0,0 +1,50 @@
+/** @file
+ Arm Gic Msi frame Parser.
+
+ Copyright (c) 2021, ARM Limited. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Reference(s):
+ - linux/Documentation/devicetree/bindings/interrupt-controller/arm,gic.yaml
+ - linux/Documentation/devicetree/bindings/interrupt-controller/arm,gic-v3.yaml
+**/
+
+#ifndef ARM_GIC_MSI_FRAME_PARSER_H_
+#define ARM_GIC_MSI_FRAME_PARSER_H_
+
+/** CM_ARM_GIC_MSI_FRAME_INFO parser function.
+
+ The following structure is populated:
+ typedef struct CmArmGicMsiFrameInfo {
+ UINT32 GicMsiFrameId; // {Populated}
+ UINT64 PhysicalBaseAddress; // {Populated}
+ UINT32 Flags; // {default = 0}
+ UINT16 SPICount;
+ UINT16 SPIBase;
+ } CM_ARM_GIC_MSI_FRAME_INFO;
+
+ A parser parses a Device Tree to populate a specific CmObj type. None,
+ one or many CmObj can be created by the parser.
+ The created CmObj are then handed to the parser's caller through the
+ HW_INFO_ADD_OBJECT interface.
+ This can also be a dispatcher. I.e. a function that not parsing a
+ Device Tree but calling other parsers.
+
+ @param [in] FdtParserHandle A handle to the parser instance.
+ @param [in] FdtBranch When searching for DT node name, restrict
+ the search to this Device Tree branch.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ABORTED An error occurred.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval EFI_NOT_FOUND Not found.
+ @retval EFI_UNSUPPORTED Unsupported.
+**/
+EFI_STATUS
+EFIAPI
+ArmGicMsiFrameInfoParser (
+ IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle,
+ IN INT32 FdtBranch
+ );
+
+#endif // ARM_GIC_MSI_FRAME_PARSER_H_
--
2.17.1


[PATCH v1 08/14] DynamicTablesPkg: FdtHwInfoParser: Add GICD parser

PierreGondois
 

From: Pierre Gondois <Pierre.Gondois@arm.com>

On ARM-based systems the Generic Interrupt Controller (GIC)
manages interrupts on the system. Each interrupt is identified
in the GIC by an interrupt identifier (INTID). ACPI GSIVs map
one to one to GIC INTIDs for peripheral interrupts, whether
shared (SPI) or private (PPI). The GIC distributor provides
the routing configuration for the interrupts.

The GIC Distributor (GICD) structure is part of the Multiple
APIC Description Table (MADT) that describes the GIC
distributor to the OS. The MADT table is a mandatory table
required for booting a standards-based operating system.

The GIC Distributor information is described in the platform
Device Tree, the bindings for which can be found at:
- linux/Documentation/devicetree/bindings/interrupt-controller/
arm,gic.yaml
- linux/Documentation/devicetree/bindings/interrupt-controller/
arm,gic-v3.yaml

The FdtHwInfoParser implements a GIC Distributor Parser that
parses the platform Device Tree to create CM_ARM_GICD_INFO
object which is encapsulated in a Configuration Manager
descriptor object and added to the platform information
repository.

The platform Configuration Manager can then utilise this
information when generating the MADT table.

Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
Signed-off-by: Sami Mujawar <sami.mujawar@arm.com>
---
.../FdtHwInfoParserLib/Gic/ArmGicDParser.c | 171 ++++++++++++++++++
.../FdtHwInfoParserLib/Gic/ArmGicDParser.h | 50 +++++
2 files changed, 221 insertions(+)
create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicDParser.c
create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicDParser.h

diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicDParser.c b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicDParser.c
new file mode 100644
index 000000000000..10207a667336
--- /dev/null
+++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicDParser.c
@@ -0,0 +1,171 @@
+/** @file
+ Arm Gic Distributor Parser.
+
+ Copyright (c) 2021, ARM Limited. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Reference(s):
+ - linux/Documentation/devicetree/bindings/interrupt-controller/arm,gic.yaml
+ - linux/Documentation/devicetree/bindings/interrupt-controller/arm,gic-v3.yaml
+**/
+
+#include "CmObjectDescUtility.h"
+#include "FdtHwInfoParser.h"
+#include "Gic/ArmGicDispatcher.h"
+#include "Gic/ArmGicDParser.h"
+
+/** Parse a Gic compatible interrupt-controller node,
+ extracting GicD information.
+
+ This parser is valid for Gic v2 and v3.
+
+ @param [in] Fdt Pointer to a Flattened Device Tree (Fdt).
+ @param [in] GicIntcNode Offset of a Gic compatible
+ interrupt-controller node.
+ @param [in] GicDInfo The CM_ARM_GICD_INFO to populate.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ABORTED An error occurred.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+GicDIntcNodeParser (
+ IN CONST VOID * Fdt,
+ IN INT32 GicIntcNode,
+ IN CM_ARM_GICD_INFO * GicDInfo
+ )
+{
+ EFI_STATUS Status;
+ INT32 AddressCells;
+ CONST UINT8 * Data;
+ INT32 DataSize;
+
+ if ((Fdt == NULL) ||
+ (GicDInfo == NULL)) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Status = FdtGetParentAddressInfo (Fdt, GicIntcNode, &AddressCells, NULL);
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+
+ // Don't support more than 64 bits and less than 32 bits addresses.
+ if ((AddressCells < 1) ||
+ (AddressCells > 2)) {
+ ASSERT (0);
+ return EFI_ABORTED;
+ }
+
+ Data = fdt_getprop (Fdt, GicIntcNode, "reg", &DataSize);
+ if ((Data == NULL) || (DataSize < (INT32)(AddressCells * sizeof (UINT32)))) {
+ // If error or not enough space.
+ ASSERT (0);
+ return EFI_ABORTED;
+ }
+
+ if (AddressCells == 2) {
+ GicDInfo->PhysicalBaseAddress = fdt64_to_cpu (*(UINT64*)Data);
+ } else {
+ GicDInfo->PhysicalBaseAddress = fdt32_to_cpu (*(UINT32*)Data);
+ }
+
+ return Status;
+}
+
+/** CM_ARM_GICD_INFO parser function.
+
+ This parser expects FdtBranch to be a Gic interrupt-controller node.
+ At most one CmObj is created.
+ The following structure is populated:
+ typedef struct CmArmGicDInfo {
+ UINT64 PhysicalBaseAddress; // {Populated}
+ UINT32 SystemVectorBase;
+ UINT8 GicVersion; // {Populated}
+ } CM_ARM_GICD_INFO;
+
+ A parser parses a Device Tree to populate a specific CmObj type. None,
+ one or many CmObj can be created by the parser.
+ The created CmObj are then handed to the parser's caller through the
+ HW_INFO_ADD_OBJECT interface.
+ This can also be a dispatcher. I.e. a function that not parsing a
+ Device Tree but calling other parsers.
+
+ @param [in] FdtParserHandle A handle to the parser instance.
+ @param [in] FdtBranch When searching for DT node name, restrict
+ the search to this Device Tree branch.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ABORTED An error occurred.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval EFI_NOT_FOUND Not found.
+ @retval EFI_UNSUPPORTED Unsupported.
+**/
+EFI_STATUS
+EFIAPI
+ArmGicDInfoParser (
+ IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle,
+ IN INT32 FdtBranch
+ )
+{
+ EFI_STATUS Status;
+ UINT32 GicVersion;
+ CM_ARM_GICD_INFO GicDInfo;
+ VOID * Fdt;
+
+ if (FdtParserHandle == NULL) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Fdt = FdtParserHandle->Fdt;
+
+ if (!FdtNodeHasProperty (Fdt, FdtBranch, "interrupt-controller")) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ // Get the Gic version of the interrupt-controller.
+ Status = GetGicVersion (Fdt, FdtBranch, &GicVersion);
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+
+ ZeroMem (&GicDInfo, sizeof (GicDInfo));
+ GicDInfo.GicVersion = GicVersion;
+
+ // Parse the interrupt-controller depending on its Gic version.
+ switch (GicVersion) {
+ case 2:
+ case 3:
+ {
+ // Set the Gic version, then parse the GicD information.
+ Status = GicDIntcNodeParser (Fdt, FdtBranch, &GicDInfo);
+ break;
+ }
+ default:
+ {
+ // Unsupported Gic version.
+ ASSERT (0);
+ return EFI_UNSUPPORTED;
+ }
+ }
+
+ // Add the CmObj to the Configuration Manager.
+ Status = AddSingleCmObj (
+ FdtParserHandle,
+ CREATE_CM_ARM_OBJECT_ID (EArmObjGicDInfo),
+ &GicDInfo,
+ sizeof (CM_ARM_GICD_INFO),
+ NULL
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ }
+ return Status;
+}
diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicDParser.h b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicDParser.h
new file mode 100644
index 000000000000..a274a4b43070
--- /dev/null
+++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicDParser.h
@@ -0,0 +1,50 @@
+/** @file
+ Arm Gic Distributor Parser.
+
+ Copyright (c) 2021, ARM Limited. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Reference(s):
+ - linux/Documentation/devicetree/bindings/interrupt-controller/arm,gic.yaml
+ - linux/Documentation/devicetree/bindings/interrupt-controller/arm,gic-v3.yaml
+**/
+
+#ifndef ARM_GICD_PARSER_H_
+#define ARM_GICD_PARSER_H_
+
+/** CM_ARM_GICD_INFO parser function.
+
+ This parser expects FdtBranch to be a Gic interrupt-controller node.
+ At most one CmObj is created.
+ The following structure is populated:
+ typedef struct CmArmGicDInfo {
+ UINT64 PhysicalBaseAddress; // {Populated}
+ UINT32 SystemVectorBase;
+ UINT8 GicVersion; // {Populated}
+ } CM_ARM_GICD_INFO;
+
+ A parser parses a Device Tree to populate a specific CmObj type. None,
+ one or many CmObj can be created by the parser.
+ The created CmObj are then handed to the parser's caller through the
+ HW_INFO_ADD_OBJECT interface.
+ This can also be a dispatcher. I.e. a function that not parsing a
+ Device Tree but calling other parsers.
+
+ @param [in] FdtParserHandle A handle to the parser instance.
+ @param [in] FdtBranch When searching for DT node name, restrict
+ the search to this Device Tree branch.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ABORTED An error occurred.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval EFI_NOT_FOUND Not found.
+ @retval EFI_UNSUPPORTED Unsupported.
+**/
+EFI_STATUS
+EFIAPI
+ArmGicDInfoParser (
+ IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle,
+ IN INT32 FdtBranch
+ );
+
+#endif // ARM_GICD_PARSER_H_
--
2.17.1


[PATCH v1 07/14] DynamicTablesPkg: FdtHwInfoParser: Add GICC parser

PierreGondois
 

From: Pierre Gondois <Pierre.Gondois@arm.com>

The GIC CPU Interface (GICC) structure is part of the Multiple
APIC Description Table (MADT) that describes the interrupt model
for the platform. The MADT table is a mandatory table required
for booting a standards-based operating system.

Arm requires the GIC interrupt model, in which the logical
processors are required to have a Processor Device object in
the DSDT, and must convey each processor’s GIC information to
the OS using the GICC structure.

The CPU and GIC information is described in the platform Device
Tree, the bindings for which can be found at:
- linux/Documentation/devicetree/bindings/arm/cpus.yaml
- linux/Documentation/devicetree/bindings/interrupt-controller/
arm,gic.yaml
- linux/Documentation/devicetree/bindings/interrupt-controller/
arm,gic-v3.yaml

The FdtHwInfoParser implements a GIC CPU Interface Parser that
parses the platform Device Tree to create CM_ARM_GICC_INFO
objects which are encapsulated in a Configuration Manager
descriptor object and added to the platform information
repository.

The platform Configuration Manager can then utilise this
information when generating the MADT and the SSDT CPU
information tables.

Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
Signed-off-by: Sami Mujawar <sami.mujawar@arm.com>
---
.../FdtHwInfoParserLib/Gic/ArmGicCParser.c | 762 ++++++++++++++++++
.../FdtHwInfoParserLib/Gic/ArmGicCParser.h | 67 ++
2 files changed, 829 insertions(+)
create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicCParser.c
create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicCParser.h

diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicCParser.c b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicCParser.c
new file mode 100644
index 000000000000..2163888c870e
--- /dev/null
+++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicCParser.c
@@ -0,0 +1,762 @@
+/** @file
+ Arm Gic cpu parser.
+
+ Copyright (c) 2021, ARM Limited. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Reference(s):
+ - linux/Documentation/devicetree/bindings/arm/cpus.yaml
+ - linux/Documentation/devicetree/bindings/interrupt-controller/arm,gic.yaml
+ - linux/Documentation/devicetree/bindings/interrupt-controller/arm,gic-v3.yaml
+**/
+
+#include "FdtHwInfoParser.h"
+#include "CmObjectDescUtility.h"
+#include "Gic/ArmGicCParser.h"
+#include "Gic/ArmGicDispatcher.h"
+
+/** List of "compatible" property values for CPU nodes.
+
+ Any other "compatible" value is not supported by this module.
+*/
+STATIC CONST COMPATIBILITY_STR CpuCompatibleStr[] = {
+ {"arm,arm-v7"},
+ {"arm,arm-v8"},
+ {"arm,cortex-a15"},
+ {"arm,cortex-a7"},
+ {"arm,cortex-a57"}
+};
+
+/** COMPATIBILITY_INFO structure for CPU nodes.
+*/
+STATIC CONST COMPATIBILITY_INFO CpuCompatibleInfo = {
+ ARRAY_SIZE (CpuCompatibleStr),
+ CpuCompatibleStr
+};
+
+/** Parse a "cpu" node.
+
+ @param [in] Fdt Pointer to a Flattened Device Tree (Fdt).
+ @param [in] CpuNode Offset of a cpu node.
+ @param [in] GicVersion Version of the GIC.
+ @param [in] AddressCells Number of address cells used for the reg
+ property.
+ @param [out] GicCInfo CM_ARM_GICC_INFO structure to populate.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ABORTED An error occurred.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval EFI_UNSUPPORTED Unsupported.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+CpuNodeParser (
+ IN CONST VOID * Fdt,
+ IN INT32 CpuNode,
+ IN UINT32 GicVersion,
+ IN UINT32 AddressCells,
+ OUT CM_ARM_GICC_INFO * GicCInfo
+)
+{
+ UINT32 CpuRegProp;
+ CONST VOID * Data;
+ INT32 DataSize;
+ UINT64 MpIdr;
+
+ if (GicCInfo == NULL) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Data = fdt_getprop (Fdt, CpuNode, "reg", &DataSize);
+ if ((Data == NULL) ||
+ ((DataSize != sizeof (UINT32)) &&
+ (DataSize != sizeof (UINT64)))) {
+ ASSERT (0);
+ return EFI_ABORTED;
+ }
+
+ if (AddressCells == 1) {
+ MpIdr = fdt32_to_cpu (*((UINT32*)Data));
+ } else if (AddressCells == 2) {
+ MpIdr = fdt64_to_cpu (*((UINT64*)Data));
+ } else {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ // Currently we only support 3 affinity levels.
+ if ((MpIdr & ~(ARM_CORE_AFF0 | ARM_CORE_AFF1 | ARM_CORE_AFF2)) != 0) {
+ ASSERT (0);
+ return EFI_UNSUPPORTED;
+ }
+
+ CpuRegProp = (MpIdr & (ARM_CORE_AFF0 | ARM_CORE_AFF1 | ARM_CORE_AFF2));
+
+ /* ACPI 6.3, s5.2.12.14 GIC CPU Interface (GICC) Structure:
+ GIC 's CPU Interface Number. In GICv1/v2 implementations,
+ this value matches the bit index of the associated processor
+ in the GIC distributor's GICD_ITARGETSR register. For
+ GICv3/4 implementations this field must be provided by the
+ platform, if compatibility mode is supported. If it is not supported
+ by the implementation, then this field must be zero.
+
+ Note: We do not support compatibility mode for GicV3
+ */
+ if (GicVersion == 2) {
+ GicCInfo->CPUInterfaceNumber = CpuRegProp;
+ } else {
+ GicCInfo->CPUInterfaceNumber = 0;
+ }
+
+ GicCInfo->AcpiProcessorUid = CpuRegProp;
+ GicCInfo->Flags = EFI_ACPI_6_3_GIC_ENABLED;
+ GicCInfo->MPIDR= MpIdr;
+
+ return EFI_SUCCESS;
+}
+
+/** Parse a "cpus" node and its children "cpu" nodes.
+
+ Create as many CM_ARM_GICC_INFO structures as "cpu" nodes.
+
+ @param [in] Fdt Pointer to a Flattened Device Tree (Fdt).
+ @param [in] CpusNode Offset of a cpus node.
+ @param [in] GicVersion Version of the GIC.
+ @param [out] NewGicCmObjDesc If success, CM_OBJ_DESCRIPTOR containing
+ all the created CM_ARM_GICC_INFO.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ABORTED An error occurred.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval EFI_UNSUPPORTED Unsupported.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+CpusNodeParser (
+ IN CONST VOID * Fdt,
+ IN INT32 CpusNode,
+ IN UINT32 GicVersion,
+ OUT CM_OBJ_DESCRIPTOR ** NewGicCmObjDesc
+ )
+{
+ EFI_STATUS Status;
+ INT32 CpuNode;
+ UINT32 CpuNodeCount;
+ INT32 AddressCells;
+
+ UINT32 Index;
+ CM_ARM_GICC_INFO * GicCInfoBuffer;
+ UINT32 GicCInfoBufferSize;
+
+ if (NewGicCmObjDesc == NULL) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ AddressCells = fdt_address_cells (Fdt, CpusNode);
+ if (AddressCells < 0) {
+ ASSERT (0);
+ return EFI_ABORTED;
+ }
+
+ // Count the number of "cpu" nodes under the "cpus" node.
+ Status = FdtCountNamedNodeInBranch (Fdt, CpusNode, "cpu", &CpuNodeCount);
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+
+ if (CpuNodeCount == 0) {
+ ASSERT (0);
+ return EFI_NOT_FOUND;
+ }
+
+ // Allocate memory for CpuNodeCount CM_ARM_GICC_INFO structures.
+ GicCInfoBufferSize = CpuNodeCount * sizeof (CM_ARM_GICC_INFO);
+ GicCInfoBuffer = AllocateZeroPool (GicCInfoBufferSize);
+ if (GicCInfoBuffer == NULL) {
+ ASSERT (0);
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ CpuNode = CpusNode;
+ for (Index = 0; Index < CpuNodeCount; Index++) {
+ Status = FdtGetNextNamedNodeInBranch (Fdt, CpusNode, "cpu", &CpuNode);
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ if (Status == EFI_NOT_FOUND) {
+ // Should have found the node.
+ Status = EFI_ABORTED;
+ }
+ goto exit_handler;
+ }
+
+ // Parse the "cpu" node.
+ if (!FdtNodeIsCompatible (Fdt, CpuNode, &CpuCompatibleInfo)) {
+ ASSERT (0);
+ Status = EFI_UNSUPPORTED;
+ goto exit_handler;
+ }
+
+ Status = CpuNodeParser (
+ Fdt,
+ CpuNode,
+ GicVersion,
+ AddressCells,
+ &GicCInfoBuffer[Index]
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ goto exit_handler;
+ }
+ } // for
+
+ Status = CreateCmObjDesc (
+ CREATE_CM_ARM_OBJECT_ID (EArmObjGicCInfo),
+ CpuNodeCount,
+ GicCInfoBuffer,
+ GicCInfoBufferSize,
+ NewGicCmObjDesc
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ }
+
+exit_handler:
+ FreePool (GicCInfoBuffer);
+ return Status;
+}
+
+/** Parse a Gic compatible interrupt-controller node,
+ extracting GicC information generic to Gic v2 and v3.
+
+ This function modifies a CM_OBJ_DESCRIPTOR object.
+ The following CM_ARM_GICC_INFO fields are patched:
+ - VGICMaintenanceInterrupt;
+ - Flags;
+
+ @param [in] Fdt Pointer to a Flattened Device Tree (Fdt).
+ @param [in] GicIntcNode Offset of a Gic compatible
+ interrupt-controller node.
+ @param [in, out] GicCCmObjDesc The CM_ARM_GICC_INFO to patch.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ABORTED An error occurred.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+GicCIntcNodeParser (
+ IN CONST VOID * Fdt,
+ IN INT32 GicIntcNode,
+ IN OUT CM_OBJ_DESCRIPTOR * GicCCmObjDesc
+ )
+{
+ EFI_STATUS Status;
+ INT32 IntCells;
+ CM_ARM_GICC_INFO * GicCInfo;
+
+ CONST UINT8 * Data;
+ INT32 DataSize;
+
+ if (GicCCmObjDesc == NULL) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ // Get the number of cells used to encode an interrupt.
+ Status = FdtGetInterruptCellsInfo (Fdt, GicIntcNode, &IntCells);
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+
+ // Get the GSIV maintenance interrupt.
+ // According to the DT bindings, this could be the:
+ // "Interrupt source of the parent interrupt controller on secondary GICs"
+ // but it is assumed that only one Gic is available.
+ Data = fdt_getprop (Fdt, GicIntcNode, "interrupts", &DataSize);
+ if ((Data != NULL) && (DataSize == (IntCells * sizeof (UINT32)))) {
+ GicCInfo = (CM_ARM_GICC_INFO*)GicCCmObjDesc->Data;
+ GicCInfo->VGICMaintenanceInterrupt =
+ FdtGetInterruptId ((CONST UINT32*)Data);
+ GicCInfo->Flags = DT_IRQ_IS_EDGE_TRIGGERED (
+ fdt32_to_cpu (((UINT32*)Data)[IRQ_FLAGS_OFFSET])
+ ) ?
+ EFI_ACPI_6_3_VGIC_MAINTENANCE_INTERRUPT_MODE_FLAGS :
+ 0;
+ return Status;
+ } else if (DataSize < 0) {
+ // This property is optional and was not found. Just return.
+ return Status;
+ }
+ // The property exists and its size doesn't match for one interrupt.
+ ASSERT (0);
+ return EFI_ABORTED;
+}
+
+/** Parse a Gic compatible interrupt-controller node,
+ extracting GicCv2 information.
+
+ This function modifies a CM_OBJ_DESCRIPTOR object.
+ The following CM_ARM_GICC_INFO fields are patched:
+ - PhysicalAddress;
+ - GICH;
+ - GICV;
+
+ @param [in] Fdt Pointer to a Flattened Device Tree (Fdt).
+ @param [in] Gicv2IntcNode Offset of a Gicv2 compatible
+ interrupt-controller node.
+ @param [in, out] GicCCmObjDesc The CM_ARM_GICC_INFO to patch.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ABORTED An error occurred.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+GicCv2IntcNodeParser (
+ IN CONST VOID * Fdt,
+ IN INT32 Gicv2IntcNode,
+ IN OUT CM_OBJ_DESCRIPTOR * GicCCmObjDesc
+ )
+{
+ EFI_STATUS Status;
+ UINT32 Index;
+ CM_ARM_GICC_INFO * GicCInfo;
+ INT32 AddressCells;
+ INT32 SizeCells;
+
+ CONST UINT8 * GicCValue;
+ CONST UINT8 * GicVValue;
+ CONST UINT8 * GicHValue;
+
+ CONST UINT8 * Data;
+ INT32 DataSize;
+ UINT32 RegSize;
+ UINT32 RegCount;
+
+ if (GicCCmObjDesc == NULL) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ GicCInfo = (CM_ARM_GICC_INFO*)GicCCmObjDesc->Data;
+ GicVValue = NULL;
+ GicHValue = NULL;
+
+ // Get the #address-cells and #size-cells property values.
+ Status = FdtGetParentAddressInfo (
+ Fdt,
+ Gicv2IntcNode,
+ &AddressCells,
+ &SizeCells
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+
+ // Don't support more than 64 bits and less than 32 bits addresses.
+ if ((AddressCells < 1) ||
+ (AddressCells > 2) ||
+ (SizeCells < 1) ||
+ (SizeCells > 2)) {
+ ASSERT (0);
+ return EFI_ABORTED;
+ }
+
+ RegSize = (AddressCells + SizeCells) * sizeof (UINT32);
+
+ Data = fdt_getprop (Fdt, Gicv2IntcNode, "reg", &DataSize);
+ if ((Data == NULL) ||
+ (DataSize < 0) ||
+ ((DataSize % RegSize) != 0)) {
+ // If error or wrong size.
+ ASSERT (0);
+ return EFI_ABORTED;
+ }
+
+ RegCount = DataSize/RegSize;
+
+ switch (RegCount) {
+ case 4:
+ {
+ // GicV is at index 3 in the reg property. GicV is optional.
+ GicVValue = Data + (sizeof (UINT32) *
+ GET_DT_REG_ADDRESS_OFFSET (3, AddressCells, SizeCells));
+ // fall-through.
+ }
+ case 3:
+ {
+ // GicH is at index 2 in the reg property. GicH is optional.
+ GicHValue = Data + (sizeof (UINT32) *
+ GET_DT_REG_ADDRESS_OFFSET (2, AddressCells, SizeCells));
+ // fall-through.
+ }
+ case 2:
+ {
+ // GicC is at index 1 in the reg property. GicC is mandatory.
+ GicCValue = Data + (sizeof (UINT32) *
+ GET_DT_REG_ADDRESS_OFFSET (1, AddressCells, SizeCells));
+ break;
+ }
+ default:
+ {
+ // Not enough or too much information.
+ ASSERT (0);
+ return EFI_ABORTED;
+ }
+ }
+
+ // Patch the relevant fields of the CM_ARM_GICC_INFO objects.
+ for (Index = 0; Index < GicCCmObjDesc->Count; Index++) {
+ if (AddressCells == 2) {
+ GicCInfo[Index].PhysicalBaseAddress = fdt64_to_cpu (*(UINT64*)GicCValue);
+ GicCInfo[Index].GICH = (GicHValue == NULL) ? 0 :
+ fdt64_to_cpu (*(UINT64*)GicHValue);
+ GicCInfo[Index].GICV = (GicVValue == NULL) ? 0 :
+ fdt64_to_cpu (*(UINT64*)GicVValue);
+ } else {
+ GicCInfo[Index].PhysicalBaseAddress = fdt32_to_cpu (*(UINT32*)GicCValue);
+ GicCInfo[Index].GICH = (GicHValue == NULL) ? 0 :
+ fdt32_to_cpu (*(UINT32*)GicHValue);
+ GicCInfo[Index].GICV = (GicVValue == NULL) ? 0 :
+ fdt32_to_cpu (*(UINT32*)GicVValue);
+ }
+ } // for
+
+ return EFI_SUCCESS;
+}
+
+/** Parse a Gic compatible interrupt-controller node,
+ extracting GicCv3 information.
+
+ This function modifies a CM_OBJ_DESCRIPTOR object.
+ The following CM_ARM_GICC_INFO fields are patched:
+ - PhysicalAddress;
+ - GICH;
+ - GICV;
+
+ @param [in] Fdt Pointer to a Flattened Device Tree (Fdt).
+ @param [in] Gicv3IntcNode Offset of a Gicv3 compatible
+ interrupt-controller node.
+ @param [in, out] GicCCmObjDesc The CM_ARM_GICC_INFO to patch.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ABORTED An error occurred.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+GicCv3IntcNodeParser (
+ IN CONST VOID * Fdt,
+ IN INT32 Gicv3IntcNode,
+ IN OUT CM_OBJ_DESCRIPTOR * GicCCmObjDesc
+ )
+{
+ EFI_STATUS Status;
+ UINT32 Index;
+ CM_ARM_GICC_INFO * GicCInfo;
+ INT32 AddressCells;
+ INT32 SizeCells;
+ UINT32 AdditionalRedistReg;
+
+ CONST UINT8 * GicCValue;
+ CONST UINT8 * GicVValue;
+ CONST UINT8 * GicHValue;
+
+ CONST UINT8 * Data;
+ INT32 DataSize;
+ UINT32 RegSize;
+ UINT32 RegCount;
+
+ if (GicCCmObjDesc == NULL) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ GicCInfo = (CM_ARM_GICC_INFO*)GicCCmObjDesc->Data;
+ GicCValue = NULL;
+ GicVValue = NULL;
+ GicHValue = NULL;
+
+ // Get the #address-cells and #size-cells property values.
+ Status = FdtGetParentAddressInfo (
+ Fdt,
+ Gicv3IntcNode,
+ &AddressCells,
+ &SizeCells
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+
+ // Don't support more than 64 bits and less than 32 bits addresses.
+ if ((AddressCells < 1) ||
+ (AddressCells > 2) ||
+ (SizeCells < 1) ||
+ (SizeCells > 2)) {
+ ASSERT (0);
+ return EFI_ABORTED;
+ }
+
+ // The "#redistributor-regions" property is optional.
+ Data = fdt_getprop (Fdt, Gicv3IntcNode, "#redistributor-regions", &DataSize);
+ if ((Data != NULL) && (DataSize == sizeof (UINT32))) {
+ ASSERT (fdt32_to_cpu (*(UINT32*)Data) > 1);
+ AdditionalRedistReg = fdt32_to_cpu (*(UINT32*)Data) - 1;
+ } else {
+ AdditionalRedistReg = 0;
+ }
+
+ RegSize = (AddressCells + SizeCells) * sizeof (UINT32);
+
+ /*
+ Ref: linux/blob/master/Documentation/devicetree/bindings/
+ interrupt-controller/arm%2Cgic-v3.yaml
+
+ reg:
+ description: |
+ Specifies base physical address(s) and size of the GIC
+ registers, in the following order:
+ - GIC Distributor interface (GICD)
+ - GIC Redistributors (GICR), one range per redistributor region
+ - GIC CPU interface (GICC)
+ - GIC Hypervisor interface (GICH)
+ - GIC Virtual CPU interface (GICV)
+ GICC, GICH and GICV are optional.
+ minItems: 2
+ maxItems: 4096
+ */
+ Data = fdt_getprop (Fdt, Gicv3IntcNode, "reg", &DataSize);
+ if ((Data == NULL) ||
+ (DataSize < 0) ||
+ ((DataSize % RegSize) != 0)) {
+ // If error or wrong size.
+ ASSERT (0);
+ return EFI_ABORTED;
+ }
+
+ RegCount = (DataSize / RegSize) - AdditionalRedistReg;
+
+ // The GicD and GicR info is mandatory.
+ switch (RegCount) {
+ case 5:
+ {
+ // GicV is at index 4 in the reg property. GicV is optional.
+ GicVValue = Data + (sizeof (UINT32) *
+ GET_DT_REG_ADDRESS_OFFSET (
+ 4 + AdditionalRedistReg,
+ AddressCells,
+ SizeCells
+ ));
+ // fall-through.
+ }
+ case 4:
+ {
+ // GicH is at index 3 in the reg property. GicH is optional.
+ GicHValue = Data + (sizeof (UINT32) *
+ GET_DT_REG_ADDRESS_OFFSET (
+ 3 + AdditionalRedistReg,
+ AddressCells,
+ SizeCells
+ ));
+ // fall-through.
+ }
+ case 3:
+ {
+ // GicC is at index 2 in the reg property. GicC is optional.
+ // Even though GicC is optional, it is made mandatory in this parser.
+ GicCValue = Data + (sizeof (UINT32) *
+ GET_DT_REG_ADDRESS_OFFSET (
+ 2 + AdditionalRedistReg,
+ AddressCells,
+ SizeCells
+ ));
+ // fall-through
+ }
+ case 2:
+ {
+ // GicR is discribed by the CM_ARM_GIC_REDIST_INFO object.
+ // GicD is described by the CM_ARM_GICD_INFO object.
+ break;
+ }
+ default:
+ {
+ // Not enough or too much information.
+ ASSERT (0);
+ return EFI_ABORTED;
+ }
+ }
+
+ // Patch the relevant fields of the CM_ARM_GICC_INFO objects.
+ if (AddressCells == 2) {
+ for (Index = 0; Index < GicCCmObjDesc->Count; Index++) {
+ // GicR is discribed by the CM_ARM_GIC_REDIST_INFO object.
+ GicCInfo[Index].GICRBaseAddress = 0;
+ GicCInfo[Index].PhysicalBaseAddress = (GicCValue == NULL) ? 0 :
+ fdt64_to_cpu (*(UINT64*)GicCValue);
+ GicCInfo[Index].GICH = (GicHValue == NULL) ? 0 :
+ fdt64_to_cpu (*(UINT64*)GicHValue);
+ GicCInfo[Index].GICV = (GicVValue == NULL) ? 0 :
+ fdt64_to_cpu (*(UINT64*)GicVValue);
+ }
+ } else {
+ for (Index = 0; Index < GicCCmObjDesc->Count; Index++) {
+ // GicR is discribed by the CM_ARM_GIC_REDIST_INFO object.
+ GicCInfo[Index].GICRBaseAddress = 0;
+ GicCInfo[Index].PhysicalBaseAddress = (GicCValue == NULL) ? 0 :
+ fdt32_to_cpu (*(UINT32*)GicCValue);
+ GicCInfo[Index].GICH = (GicHValue == NULL) ? 0 :
+ fdt32_to_cpu (*(UINT32*)GicHValue);
+ GicCInfo[Index].GICV = (GicVValue == NULL) ? 0 :
+ fdt32_to_cpu (*(UINT32*)GicVValue);
+ }
+ }
+
+ return EFI_SUCCESS;
+}
+
+/** CM_ARM_GICC_INFO parser function.
+
+ This parser expects FdtBranch to be the "\cpus" node node.
+ At most one CmObj is created.
+ The following structure is populated:
+ typedef struct CmArmGicCInfo {
+ UINT32 CPUInterfaceNumber; // {Populated}
+ UINT32 AcpiProcessorUid; // {Populated}
+ UINT32 Flags; // {Populated}
+ UINT32 ParkingProtocolVersion; // {default = 0}
+ UINT32 PerformanceInterruptGsiv; // {default = 0}
+ UINT64 ParkedAddress; // {default = 0}
+ UINT64 PhysicalBaseAddress; // {Populated}
+ UINT64 GICV; // {Populated}
+ UINT64 GICH; // {Populated}
+ UINT32 VGICMaintenanceInterrupt; // {Populated}
+ UINT64 GICRBaseAddress; // {default = 0}
+ UINT64 MPIDR; // {Populated}
+ UINT8 ProcessorPowerEfficiencyClass; // {default = 0}
+ UINT16 SpeOverflowInterrupt; // {default = 0}
+ UINT32 ProximityDomain; // {default = 0}
+ UINT32 ClockDomain; // {default = 0}
+ UINT32 AffinityFlags; // {default = 0}
+ } CM_ARM_GICC_INFO;
+
+ The pmu information can be found in the pmu node. There is no support
+ for now.
+
+ A parser parses a Device Tree to populate a specific CmObj type. None,
+ one or many CmObj can be created by the parser.
+ The created CmObj are then handed to the parser's caller through the
+ HW_INFO_ADD_OBJECT interface.
+ This can also be a dispatcher. I.e. a function that not parsing a
+ Device Tree but calling other parsers.
+
+ @param [in] FdtParserHandle A handle to the parser instance.
+ @param [in] FdtBranch When searching for DT node name, restrict
+ the search to this Device Tree branch.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ABORTED An error occurred.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval EFI_NOT_FOUND Not found.
+ @retval EFI_UNSUPPORTED Unsupported.
+**/
+EFI_STATUS
+EFIAPI
+ArmGicCInfoParser (
+ IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle,
+ IN INT32 FdtBranch
+ )
+{
+ EFI_STATUS Status;
+ INT32 IntcNode;
+ UINT32 GicVersion;
+ CM_OBJ_DESCRIPTOR * NewCmObjDesc;
+ VOID * Fdt;
+
+ if (FdtParserHandle == NULL) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Fdt = FdtParserHandle->Fdt;
+ NewCmObjDesc = NULL;
+
+ // The FdtBranch points to the Cpus Node.
+ // Get the interrupt-controller node associated to the "cpus" node.
+ Status = FdtGetIntcParentNode (Fdt, FdtBranch, &IntcNode);
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ if (Status == EFI_NOT_FOUND) {
+ // Should have found the node.
+ Status = EFI_ABORTED;
+ }
+ goto exit_handler;
+ }
+
+ Status = GetGicVersion (Fdt, IntcNode, &GicVersion);
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ goto exit_handler;
+ }
+
+ // Parse the "cpus" nodes and its children "cpu" nodes,
+ // and create a CM_OBJ_DESCRIPTOR.
+ Status = CpusNodeParser (Fdt, FdtBranch, GicVersion, &NewCmObjDesc);
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+
+ // Parse the interrupt-controller node according to the Gic version.
+ switch (GicVersion) {
+ case 2:
+ {
+ Status = GicCv2IntcNodeParser (Fdt, IntcNode, NewCmObjDesc);
+ break;
+ }
+ case 3:
+ {
+ Status = GicCv3IntcNodeParser (Fdt, IntcNode, NewCmObjDesc);
+ break;
+ }
+ default:
+ {
+ // Unsupported Gic version.
+ ASSERT (0);
+ Status = EFI_UNSUPPORTED;
+ }
+ }
+
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ goto exit_handler;
+ }
+
+ // Parse the Gic information common to Gic v2 and v3.
+ Status = GicCIntcNodeParser (Fdt, IntcNode, NewCmObjDesc);
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ goto exit_handler;
+ }
+
+ // Add all the CmObjs to the Configuration Manager.
+ Status = AddMultipleCmObj (FdtParserHandle, NewCmObjDesc, 0, NULL);
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ goto exit_handler;
+ }
+
+exit_handler:
+ FreeCmObjDesc (NewCmObjDesc);
+ return Status;
+}
diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicCParser.h b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicCParser.h
new file mode 100644
index 000000000000..10e6b03c541f
--- /dev/null
+++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Gic/ArmGicCParser.h
@@ -0,0 +1,67 @@
+/** @file
+ Arm Gic cpu parser.
+
+ Copyright (c) 2021, ARM Limited. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Reference(s):
+ - linux/Documentation/devicetree/bindings/interrupt-controller/arm,gic.yaml
+ - linux/Documentation/devicetree/bindings/interrupt-controller/arm,gic-v3.yaml
+**/
+
+#ifndef ARM_GICC_PARSER_H_
+#define ARM_GICC_PARSER_H_
+
+/** CM_ARM_GICC_INFO parser function.
+
+ This parser expects FdtBranch to be the "\cpus" node node.
+ At most one CmObj is created.
+ The following structure is populated:
+ typedef struct CmArmGicCInfo {
+ UINT32 CPUInterfaceNumber; // {Populated}
+ UINT32 AcpiProcessorUid; // {Populated}
+ UINT32 Flags; // {Populated}
+ UINT32 ParkingProtocolVersion; // {default = 0}
+ UINT32 PerformanceInterruptGsiv; // {default = 0}
+ UINT64 ParkedAddress; // {default = 0}
+ UINT64 PhysicalBaseAddress; // {Populated}
+ UINT64 GICV; // {Populated}
+ UINT64 GICH; // {Populated}
+ UINT32 VGICMaintenanceInterrupt; // {Populated}
+ UINT64 GICRBaseAddress; // {default = 0}
+ UINT64 MPIDR; // {Populated}
+ UINT8 ProcessorPowerEfficiencyClass; // {default = 0}
+ UINT16 SpeOverflowInterrupt; // {default = 0}
+ UINT32 ProximityDomain; // {default = 0}
+ UINT32 ClockDomain; // {default = 0}
+ UINT32 AffinityFlags; // {default = 0}
+ } CM_ARM_GICC_INFO;
+
+ The pmu information can be found in the pmu node. There is no support
+ for now.
+
+ A parser parses a Device Tree to populate a specific CmObj type. None,
+ one or many CmObj can be created by the parser.
+ The created CmObj are then handed to the parser's caller through the
+ HW_INFO_ADD_OBJECT interface.
+ This can also be a dispatcher. I.e. a function that not parsing a
+ Device Tree but calling other parsers.
+
+ @param [in] FdtParserHandle A handle to the parser instance.
+ @param [in] FdtBranch When searching for DT node name, restrict
+ the search to this Device Tree branch.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ABORTED An error occurred.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval EFI_NOT_FOUND Not found.
+ @retval EFI_UNSUPPORTED Unsupported.
+**/
+EFI_STATUS
+EFIAPI
+ArmGicCInfoParser (
+ IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle,
+ IN INT32 FdtBranch
+ );
+
+#endif // ARM_GICC_PARSER_H_
--
2.17.1


[PATCH v1 06/14] DynamicTablesPkg: FdtHwInfoParser: Add Serial port parser

PierreGondois
 

From: Pierre Gondois <Pierre.Gondois@arm.com>

The Microsoft Debug Port Table 2 (DBG2), the Serial Port Console
Redirector (SPCR) table are mandatory tables required for booting
a standards-based operating system. The DBG2 table is used by the
OS debugger while the SPCR table is used to configure the serial
terminal. Additionally, the serial ports available on a platform
for generic use also need to be described in DSDT/SSDT for an OS
to be able to use the serial ports.

The Arm Base System Architecture 1.0 specification a lists of
supported serial port hardware for Arm Platforms. This list
includes the following serial port UARTs:
- SBSA/Generic UART
- a fully 16550 compatible UART.
Along, with these the PL011 UART is the most commonly used serial
port hardware on Arm platforms.

The serial port hardware information is described in the platform
Device Tree, the bindings for which can be found at:
- linux/Documentation/devicetree/bindings/serial/serial.yaml
- linux/Documentation/devicetree/bindings/serial/8250.txt
- linux/Documentation/devicetree/bindings/serial/arm_sbsa_uart.txt
- linux/Documentation/devicetree/bindings/serial/pl011.yaml

The FdtHwInfoParser implements a Serial Port Parser that parses
the platform Device Tree to create CM_ARM_SERIAL_PORT_INFO objects
with the following IDs:
- EArmObjSerialConsolePortInfo (for use by SPCR)
- EArmObjSerialDebugPortInfo (for use by DBG2)
- EArmObjSerialPortInfo (for use as generic Serial Ports)

The Serial Port for use by SPCR is selected by parsing the Device
Tree for the '/chosen' node with the 'stdout-path' property. The
next Serial Port is selected for use as the Debug Serial Port and
the remaining serial ports are used as generic serial ports.

The CM_ARM_SERIAL_PORT_INFO objects are encapsulated in Configuration
Manager descriptor objects with the respective IDs and are added to
the platform information repository.

The platform Configuration Manager can then utilise this information
when generating the DBG2, SPCR and the SSDT serial port tables.

Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
Signed-off-by: Sami Mujawar <sami.mujawar@arm.com>
---
.../Serial/ArmSerialPortParser.c | 621 ++++++++++++++++++
.../Serial/ArmSerialPortParser.h | 47 ++
2 files changed, 668 insertions(+)
create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/Serial/ArmSerialPortParser.c
create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/Serial/ArmSerialPortParser.h

diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/Serial/ArmSerialPortParser.c b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Serial/ArmSerialPortParser.c
new file mode 100644
index 000000000000..d5db206ae93c
--- /dev/null
+++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Serial/ArmSerialPortParser.c
@@ -0,0 +1,621 @@
+/** @file
+ Arm Serial Port Parser.
+
+ Copyright (c) 2021, ARM Limited. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Reference(s):
+ - linux/Documentation/devicetree/bindings/serial/serial.yaml
+ - linux/Documentation/devicetree/bindings/serial/8250.txt
+ - linux/Documentation/devicetree/bindings/serial/arm_sbsa_uart.txt
+ - linux/Documentation/devicetree/bindings/serial/pl011.yaml
+**/
+
+#include <IndustryStandard/DebugPort2Table.h>
+
+#include "CmObjectDescUtility.h"
+#include "FdtHwInfoParser.h"
+#include "Serial/ArmSerialPortParser.h"
+
+/** List of "compatible" property values for serial port nodes.
+
+ Any other "compatible" value is not supported by this module.
+*/
+STATIC CONST COMPATIBILITY_STR SerialCompatibleStr[] = {
+ {"ns16550a"},
+ {"arm,sbsa-uart"}
+};
+
+/** COMPATIBILITY_INFO structure for the SerialCompatible.
+*/
+CONST COMPATIBILITY_INFO SerialCompatibleInfo = {
+ ARRAY_SIZE (SerialCompatibleStr),
+ SerialCompatibleStr
+};
+
+/** 16550 UART compatible strings.
+
+ Any string of this list must be part of SerialCompatible.
+*/
+STATIC CONST COMPATIBILITY_STR Serial16550CompatibleStr[] = {
+ {"ns16550a"}
+};
+
+/** COMPATIBILITY_INFO structure for the Serial16550Compatible.
+*/
+CONST COMPATIBILITY_INFO Serial16550CompatibleInfo = {
+ ARRAY_SIZE (Serial16550CompatibleStr),
+ Serial16550CompatibleStr
+};
+
+/** SBSA UART compatible strings.
+
+ Any string of this list must be part of SerialCompatible.
+*/
+STATIC CONST COMPATIBILITY_STR SerialSbsaCompatibleStr[] = {
+ {"arm,sbsa-uart"}
+};
+
+/** COMPATIBILITY_INFO structure for the SerialSbsaCompatible.
+*/
+CONST COMPATIBILITY_INFO SerialSbsaCompatibleInfo = {
+ ARRAY_SIZE (SerialSbsaCompatibleStr),
+ SerialSbsaCompatibleStr
+};
+
+/** Parse a serial port node.
+
+ @param [in] Fdt Pointer to a Flattened Device Tree (Fdt).
+ @param [in] SerialPortNode Offset of a serial-port node.
+ @param [in] SerialPortInfo The CM_ARM_SERIAL_PORT_INFO to populate.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ABORTED An error occurred.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval EFI_UNSUPPORTED Unsupported.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+SerialPortNodeParser (
+ IN CONST VOID * Fdt,
+ IN INT32 SerialPortNode,
+ IN CM_ARM_SERIAL_PORT_INFO * SerialPortInfo
+ )
+{
+ EFI_STATUS Status;
+ INT32 IntcNode;
+ CONST UINT8 * SizeValue;
+
+ INT32 AddressCells;
+ INT32 SizeCells;
+ INT32 IntCells;
+
+ CONST UINT8 * Data;
+ INT32 DataSize;
+ UINT8 AccessSize;
+
+ if ((Fdt == NULL) ||
+ (SerialPortInfo == NULL)) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Status = FdtGetParentAddressInfo (
+ Fdt,
+ SerialPortNode,
+ &AddressCells,
+ &SizeCells
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+
+ // Don't support more than 64 bits and less than 32 bits addresses.
+ if ((AddressCells < 1) ||
+ (AddressCells > 2) ||
+ (SizeCells < 1) ||
+ (SizeCells > 2)) {
+ ASSERT (0);
+ return EFI_ABORTED;
+ }
+
+ Data = fdt_getprop (Fdt, SerialPortNode, "reg", &DataSize);
+ if ((Data == NULL) ||
+ (DataSize < (INT32)(sizeof (UINT32) *
+ GET_DT_REG_ADDRESS_OFFSET (1, AddressCells, SizeCells)) - 1)) {
+ // If error or not enough space.
+ ASSERT (0);
+ return EFI_ABORTED;
+ }
+
+ if (AddressCells == 2) {
+ SerialPortInfo->BaseAddress = fdt64_to_cpu (*(UINT64*)Data);
+ } else {
+ SerialPortInfo->BaseAddress = fdt32_to_cpu (*(UINT32*)Data);
+ }
+
+ SizeValue = Data + (sizeof (UINT32) *
+ GET_DT_REG_SIZE_OFFSET (0, AddressCells, SizeCells));
+ if (SizeCells == 2) {
+ SerialPortInfo->BaseAddressLength = fdt64_to_cpu (*(UINT64*)SizeValue);
+ } else {
+ SerialPortInfo->BaseAddressLength = fdt32_to_cpu (*(UINT32*)SizeValue);
+ }
+
+ // Get the associated interrupt-controller.
+ Status= FdtGetIntcParentNode (Fdt, SerialPortNode, &IntcNode);
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ if (Status == EFI_NOT_FOUND) {
+ // Should have found the node.
+ Status = EFI_ABORTED;
+ }
+ return Status;
+ }
+
+ // Get the number of cells used to encode an interrupt.
+ Status = FdtGetInterruptCellsInfo (Fdt, IntcNode, &IntCells);
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+
+ Data = fdt_getprop (Fdt, SerialPortNode, "interrupts", &DataSize);
+ if ((Data == NULL) || (DataSize != (IntCells * sizeof (UINT32)))) {
+ // If error or not 1 interrupt.
+ ASSERT (0);
+ return EFI_ABORTED;
+ }
+
+ SerialPortInfo->Interrupt = FdtGetInterruptId ((CONST UINT32*)Data);
+
+ // Note: clock-frequency is optional for SBSA UART.
+ Data = fdt_getprop (Fdt, SerialPortNode, "clock-frequency", &DataSize);
+ if (Data != NULL) {
+ if (DataSize < sizeof (UINT32)) {
+ // If error or not enough space.
+ ASSERT (0);
+ return EFI_ABORTED;
+ } else if (fdt_node_offset_by_phandle (Fdt, fdt32_to_cpu (*Data)) >= 0) {
+ // "clock-frequency" can be a "clocks phandle to refer to the clk used".
+ // This is not supported.
+ ASSERT (0);
+ return EFI_UNSUPPORTED;
+ }
+ SerialPortInfo->Clock = fdt32_to_cpu (*(UINT32*)Data);
+ }
+
+ if (FdtNodeIsCompatible (Fdt, SerialPortNode, &Serial16550CompatibleInfo)) {
+ SerialPortInfo->PortSubtype = EFI_ACPI_DBG2_PORT_SUBTYPE_SERIAL_FULL_16550;
+
+ /* reg-io-width:
+ description: |
+ The size (in bytes) of the IO accesses that should be performed on the
+ device. There are some systems that require 32-bit accesses to the
+ UART.
+ */
+ Data = fdt_getprop (Fdt, SerialPortNode, "reg-io-width", &DataSize);
+ if (Data != NULL) {
+ if (DataSize < sizeof (UINT32)) {
+ // If error or not enough space.
+ ASSERT (0);
+ return EFI_ABORTED;
+ }
+
+ AccessSize = fdt32_to_cpu (*(UINT32*)Data);
+ if (AccessSize > EFI_ACPI_6_3_QWORD) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+ SerialPortInfo->AccessSize = AccessSize;
+ } else {
+ // 8250/16550 defaults to byte access.
+ SerialPortInfo->AccessSize = EFI_ACPI_6_3_BYTE;
+ }
+ } else if (FdtNodeIsCompatible (
+ Fdt,
+ SerialPortNode,
+ &SerialSbsaCompatibleInfo
+ )) {
+ SerialPortInfo->PortSubtype =
+ EFI_ACPI_DBG2_PORT_SUBTYPE_SERIAL_ARM_SBSA_GENERIC_UART;
+ } else {
+ ASSERT (0);
+ return EFI_UNSUPPORTED;
+ }
+
+ // Set Baudrate to 115200 by default
+ SerialPortInfo->BaudRate = 115200;
+ return EFI_SUCCESS;
+}
+
+/** Find the console serial-port node in the DT.
+
+ This function fetches the node referenced in the "stdout-path"
+ property of the "chosen" node.
+
+ @param [in] Fdt Pointer to a Flattened Device Tree (Fdt).
+ @param [out] SerialConsoleNode If success, contains the node offset
+ of the console serial-port node.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ABORTED An error occurred.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval EFI_NOT_FOUND Not found.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+GetSerialConsoleNode (
+ IN CONST VOID * Fdt,
+ OUT INT32 * SerialConsoleNode
+ )
+{
+ CONST CHAR8 * Prop;
+ INT32 PropSize;
+ CONST CHAR8 * Path;
+ INT32 PathLen;
+ INT32 ChosenNode;
+
+ if ((Fdt == NULL) ||
+ (SerialConsoleNode == NULL)) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ // The "chosen" node resides at the the root of the DT. Fetch it.
+ ChosenNode = fdt_path_offset (Fdt, "/chosen");
+ if (ChosenNode < 0) {
+ return EFI_NOT_FOUND;
+ }
+
+ Prop = fdt_getprop (Fdt, ChosenNode, "stdout-path", &PropSize);
+ if ((Prop == NULL) || (PropSize < 0)) {
+ return EFI_NOT_FOUND;
+ }
+
+ // Determine the actual path length, as a colon terminates the path.
+ Path = ScanMem8 (Prop, ':', PropSize);
+ if (Path == NULL) {
+ PathLen = (UINT32)AsciiStrLen (Prop);
+ } else {
+ PathLen = (INT32)(Path - Prop);
+ }
+
+ // Aliases cannot start with a '/', so it must be the actual path.
+ if (Prop[0] == '/') {
+ *SerialConsoleNode = fdt_path_offset_namelen (Fdt, Prop, PathLen);
+ return EFI_SUCCESS;
+ }
+
+ // Lookup the alias, as this contains the actual path.
+ Path = fdt_get_alias_namelen (Fdt, Prop, PathLen);
+ if (Path == NULL) {
+ return EFI_NOT_FOUND;
+ }
+
+ *SerialConsoleNode = fdt_path_offset (Fdt, Path);
+ return EFI_SUCCESS;
+}
+
+/** CM_ARM_SERIAL_PORT_INFO dispatcher function (for a generic serial-port).
+
+ @param [in] FdtParserHandle A handle to the parser instance.
+ @param [in] GenericSerialInfo Pointer to a serial port info list.
+ @param [in] NodeCount Count of serial ports to dispatch.
+ @param [in] SerialObjectId Serial port object ID.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ABORTED An error occurred.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval EFI_NOT_FOUND Not found.
+ @retval EFI_UNSUPPORTED Unsupported.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+ArmSerialPortInfoDispatch (
+ IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle,
+ IN CM_ARM_SERIAL_PORT_INFO * GenericSerialInfo,
+ IN INT32 NodeCount,
+ IN EARM_OBJECT_ID SerialObjectId
+)
+{
+ EFI_STATUS Status;
+ CM_OBJ_DESCRIPTOR * NewCmObjDesc;
+
+ if ((GenericSerialInfo == NULL) || (NodeCount == 0)) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if ((SerialObjectId != EArmObjSerialPortInfo) &&
+ (SerialObjectId != EArmObjSerialDebugPortInfo) &&
+ (SerialObjectId != EArmObjSerialConsolePortInfo)) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ // Dispatch the Generic Serial ports
+ Status = CreateCmObjDesc (
+ CREATE_CM_ARM_OBJECT_ID (SerialObjectId),
+ NodeCount,
+ GenericSerialInfo,
+ sizeof (CM_ARM_SERIAL_PORT_INFO) * NodeCount,
+ &NewCmObjDesc
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+
+ // Add all the CmObjs to the Configuration Manager.
+ Status = AddMultipleCmObj (FdtParserHandle, NewCmObjDesc, 0, NULL);
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ }
+
+ FreeCmObjDesc (NewCmObjDesc);
+ return Status;
+}
+
+/** CM_ARM_SERIAL_PORT_INFO parser function (for debug/console serial-port).
+
+ This parser expects FdtBranch to be the debug serial-port node.
+ At most one CmObj is created.
+ The following structure is populated:
+ typedef struct CmArmSerialPortInfo {
+ UINT64 BaseAddress; // {Populated}
+ UINT32 Interrupt; // {Populated}
+ UINT64 BaudRate; // {default}
+ UINT32 Clock; // {Populated}
+ UINT16 PortSubtype; // {Populated}
+ UINT64 BaseAddressLength // {Populated}
+ } CM_ARM_SERIAL_PORT_INFO;
+
+ A parser parses a Device Tree to populate a specific CmObj type. None,
+ one or many CmObj can be created by the parser.
+ The created CmObj are then handed to the parser's caller through the
+ HW_INFO_ADD_OBJECT interface.
+ This can also be a dispatcher. I.e. a function that not parsing a
+ Device Tree but calling other parsers.
+
+ @param [in] FdtParserHandle A handle to the parser instance.
+ @param [in] FdtBranch When searching for DT node name, restrict
+ the search to this Device Tree branch.
+ @param [in] SerialObjectId ArmNamespace Object ID for the serial port.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ABORTED An error occurred.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval EFI_NOT_FOUND Not found.
+ @retval EFI_UNSUPPORTED Unsupported.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+ArmSerialPortInfoParser (
+ IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle,
+ IN INT32 FdtBranch,
+ IN EARM_OBJECT_ID SerialObjectId
+ )
+{
+ EFI_STATUS Status;
+ CM_ARM_SERIAL_PORT_INFO SerialInfo;
+
+ if ((SerialObjectId != EArmObjSerialDebugPortInfo) &&
+ (SerialObjectId != EArmObjSerialConsolePortInfo)) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ ZeroMem (&SerialInfo, sizeof (SerialInfo));
+
+ Status = SerialPortNodeParser (
+ FdtParserHandle->Fdt,
+ FdtBranch,
+ &SerialInfo
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+
+ Status = ArmSerialPortInfoDispatch (
+ FdtParserHandle,
+ &SerialInfo,
+ 1,
+ SerialObjectId
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ }
+
+ return Status;
+}
+
+/** SerialPort dispatcher.
+
+ This disptacher populates the CM_ARM_SERIAL_PORT_INFO structure for
+ the following CM_OBJ_ID:
+ - EArmObjSerialConsolePortInfo
+ - EArmObjSerialDebugPortInfo
+ - EArmObjSerialPortInfo
+
+ A parser parses a Device Tree to populate a specific CmObj type. None,
+ one or many CmObj can be created by the parser.
+ The created CmObj are then handed to the parser's caller through the
+ HW_INFO_ADD_OBJECT interface.
+ This can also be a dispatcher. I.e. a function that not parsing a
+ Device Tree but calling other parsers.
+
+ @param [in] FdtParserHandle A handle to the parser instance.
+ @param [in] FdtBranch When searching for DT node name, restrict
+ the search to this Device Tree branch.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ABORTED An error occurred.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval EFI_NOT_FOUND Not found.
+ @retval EFI_UNSUPPORTED Unsupported.
+**/
+EFI_STATUS
+EFIAPI
+SerialPortDispatcher (
+ IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle,
+ IN INT32 FdtBranch
+ )
+{
+ EFI_STATUS Status;
+ INT32 SerialConsoleNode;
+ INT32 SerialDebugNode;
+ INT32 SerialNode;
+ UINT32 Index;
+ UINT32 SerialNodeCount;
+ UINT32 SerialNodesRemaining;
+ CM_ARM_SERIAL_PORT_INFO * GenericSerialInfo;
+ UINT32 GenericSerialIndex;
+ VOID * Fdt;
+
+ if (FdtParserHandle == NULL) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Fdt = FdtParserHandle->Fdt;
+
+ // Count the number of serial-ports.
+ Status = FdtCountCompatNodeInBranch (
+ Fdt,
+ FdtBranch,
+ &SerialCompatibleInfo,
+ &SerialNodeCount
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+
+ if (SerialNodeCount == 0) {
+ return EFI_NOT_FOUND;
+ }
+
+ // Track remaining nodes separately as SerialNodeCount
+ // is used in for loop below and reducing SerialNodeCount
+ // would result in the Generic Serial port nodes not
+ // being found if the serial console port node is among
+ // the first few serial nodes.
+ SerialNodesRemaining = SerialNodeCount;
+
+ // Identify the serial console port.
+ Status = GetSerialConsoleNode (Fdt, &SerialConsoleNode);
+ if (Status == EFI_NOT_FOUND) {
+ // No serial console.
+ SerialConsoleNode = -1;
+ } else if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ } else {
+ // Parse the console serial-port.
+ Status = ArmSerialPortInfoParser (
+ FdtParserHandle,
+ SerialConsoleNode,
+ EArmObjSerialConsolePortInfo
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+ SerialNodesRemaining--;
+ }
+
+ GenericSerialInfo = NULL;
+ if (SerialNodesRemaining > 1) {
+ // We have more than one serial port remaining.
+ // This means that the first serial port will
+ // be reserved as a debug port, and the remaining
+ // will be for general purpose use.
+ SerialNodesRemaining--;
+ GenericSerialInfo = AllocateZeroPool (
+ SerialNodesRemaining *
+ sizeof (CM_ARM_SERIAL_PORT_INFO)
+ );
+ if (GenericSerialInfo == NULL) {
+ ASSERT (0);
+ return EFI_OUT_OF_RESOURCES;
+ }
+ }
+
+ SerialNode = FdtBranch;
+ SerialDebugNode = -1;
+ GenericSerialIndex = 0;
+ for (Index = 0; Index < SerialNodeCount; Index++) {
+ // Search the next serial-port node in the branch.
+ Status = FdtGetNextCompatNodeInBranch (
+ Fdt,
+ FdtBranch,
+ &SerialCompatibleInfo,
+ &SerialNode
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ if (Status == EFI_NOT_FOUND) {
+ // Should have found the node.
+ Status = EFI_ABORTED;
+ }
+ goto exit_handler;
+ }
+
+ // Ignore the serial console node.
+ if (SerialNode == SerialConsoleNode) {
+ continue;
+ } else if (SerialDebugNode == -1) {
+ // The first serial-port node, not being the console serial-port,
+ // will be the debug serial-port.
+ SerialDebugNode = SerialNode;
+ Status = ArmSerialPortInfoParser (
+ FdtParserHandle,
+ SerialDebugNode,
+ EArmObjSerialDebugPortInfo
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ goto exit_handler;
+ }
+ } else {
+ if (GenericSerialInfo == NULL) {
+ // Should not be possible.
+ ASSERT (0);
+ Status = EFI_ABORTED;
+ goto exit_handler;
+ }
+
+ Status = SerialPortNodeParser (
+ Fdt,
+ SerialNode,
+ &GenericSerialInfo[GenericSerialIndex++]
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ goto exit_handler;
+ }
+ }
+ } // for
+
+ if (GenericSerialIndex > 0) {
+ Status = ArmSerialPortInfoDispatch (
+ FdtParserHandle,
+ GenericSerialInfo,
+ GenericSerialIndex,
+ EArmObjSerialPortInfo
+ );
+ }
+
+exit_handler:
+ if (GenericSerialInfo != NULL) {
+ FreePool (GenericSerialInfo);
+ }
+ return Status;
+}
diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/Serial/ArmSerialPortParser.h b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Serial/ArmSerialPortParser.h
new file mode 100644
index 000000000000..5e4707849e39
--- /dev/null
+++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/Serial/ArmSerialPortParser.h
@@ -0,0 +1,47 @@
+/** @file
+ Arm Serial Port Parser.
+
+ Copyright (c) 2021, ARM Limited. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Reference(s):
+ - linux/Documentation/devicetree/bindings/serial/serial.yaml
+ - linux/Documentation/devicetree/bindings/serial/8250.txt
+**/
+
+#ifndef ARM_SERIAL_PORT_PARSER_H_
+#define ARM_SERIAL_PORT_PARSER_H_
+
+/** SerialPort dispatcher.
+
+ This disptacher populates the CM_ARM_SERIAL_PORT_INFO structure for
+ the following CM_OBJ_ID:
+ - EArmObjSerialConsolePortInfo
+ - EArmObjSerialDebugPortInfo
+ - EArmObjSerialPortInfo
+
+ A parser parses a Device Tree to populate a specific CmObj type. None,
+ one or many CmObj can be created by the parser.
+ The created CmObj are then handed to the parser's caller through the
+ HW_INFO_ADD_OBJECT interface.
+ This can also be a dispatcher. I.e. a function that not parsing a
+ Device Tree but calling other parsers.
+
+ @param [in] FdtParserHandle A handle to the parser instance.
+ @param [in] FdtBranch When searching for DT node name, restrict
+ the search to this Device Tree branch.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ABORTED An error occurred.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval EFI_NOT_FOUND Not found.
+ @retval EFI_UNSUPPORTED Unsupported.
+**/
+EFI_STATUS
+EFIAPI
+SerialPortDispatcher (
+ IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle,
+ IN INT32 FdtBranch
+ );
+
+#endif // ARM_SERIAL_PORT_PARSER_H_
--
2.17.1


[PATCH v1 05/14] DynamicTablesPkg: FdtHwInfoParser: Generic Timer Parser

PierreGondois
 

From: Pierre Gondois <Pierre.Gondois@arm.com>

The Generic Timer Description Table (GTDT) is a mandatory table
required for booting a standards-based operating system. It
provides an OSPM with information about a system’s Generic Timer
configuration. The Generic Timer (GT) is a standard timer interface
implemented on ARM processor-based systems. The GTDT provides OSPM
with information about a system’s GT interrupt configurations, for
both per-processor timers, and platform (memory-mapped) timers.

The Generic Timer information is described in the platform Device
Tree. The Device Tree bindings for the Generic timers can be found
at:
- linux/Documentation/devicetree/bindings/timer/arm,arch_timer.yaml

The FdtHwInfoParser implements a Generic Timer Parser that parses
the platform Device Tree to create a CM_ARM_GENERIC_TIMER_INFO
object. The CM_ARM_GENERIC_TIMER_INFO object is encapsulated in a
Configuration Manager descriptor object and added to the platform
information repository.

The platform Configuration Manager can then utilise this information
when generating the GTDT table.

Note: The Generic Timer Parser currently does not support parsing
of memory-mapped platform timers.

Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
Signed-off-by: Sami Mujawar <sami.mujawar@arm.com>
---
.../GenericTimer/ArmGenericTimerParser.c | 254 ++++++++++++++++++
.../GenericTimer/ArmGenericTimerParser.h | 66 +++++
2 files changed, 320 insertions(+)
create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/GenericTimer/ArmGenericTimerParser.c
create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/GenericTimer/ArmGenericTimerParser.h

diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/GenericTimer/ArmGenericTimerParser.c b/DynamicTablesPkg/Library/FdtHwInfoParserLib/GenericTimer/ArmGenericTimerParser.c
new file mode 100644
index 000000000000..e7095396a5a8
--- /dev/null
+++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/GenericTimer/ArmGenericTimerParser.c
@@ -0,0 +1,254 @@
+/** @file
+ Arm generic timer parser.
+
+ Copyright (c) 2021, ARM Limited. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Reference(s):
+ - linux/Documentation/devicetree/bindings/timer/arm,arch_timer.yaml
+**/
+
+#include "FdtHwInfoParser.h"
+#include "CmObjectDescUtility.h"
+#include "GenericTimer/ArmGenericTimerParser.h"
+#include "Gic/ArmGicDispatcher.h"
+
+/** List of "compatible" property values for timer nodes.
+
+ Other "compatible" values are not supported by this module.
+*/
+STATIC CONST COMPATIBILITY_STR TimerCompatibleStr[] = {
+ {"arm,armv7-timer"},
+ {"arm,armv8-timer"}
+};
+
+/** Timer compatiblity information.
+*/
+STATIC CONST COMPATIBILITY_INFO TimerCompatibleInfo = {
+ ARRAY_SIZE (TimerCompatibleStr),
+ TimerCompatibleStr
+};
+
+/** Parse a timer node.
+
+ @param [in] Fdt Pointer to a Flattened Device Tree (Fdt).
+ @param [in] TimerNode Offset of a timer node.
+ @param [in] GenericTimerInfo The CM_ARM_BOOT_ARCH_INFO to populate.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ABORTED An error occurred.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+TimerNodeParser (
+ IN CONST VOID * Fdt,
+ IN INT32 TimerNode,
+ IN CM_ARM_GENERIC_TIMER_INFO * GenericTimerInfo
+ )
+{
+ EFI_STATUS Status;
+ CONST UINT32 * Data;
+ INT32 IntcNode;
+ UINT32 GicVersion;
+ INT32 DataSize;
+ INT32 IntCells;
+ BOOLEAN AlwaysOnTimer;
+
+ if ((Fdt == NULL) ||
+ (GenericTimerInfo == NULL)) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Data = fdt_getprop (Fdt, TimerNode, "always-on", &DataSize);
+ if ((Data == NULL) || (DataSize < 0)) {
+ AlwaysOnTimer = FALSE;
+ } else {
+ AlwaysOnTimer = TRUE;
+ }
+
+ // Get the associated interrupt-controller.
+ Status = FdtGetIntcParentNode (Fdt, TimerNode, &IntcNode);
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+
+ // Check that the interrupt-controller node is a Gic.
+ Status = GetGicVersion (Fdt, IntcNode, &GicVersion);
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+
+ // Get the number of cells used to encode an interrupt.
+ Status = FdtGetInterruptCellsInfo (Fdt, IntcNode, &IntCells);
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ if (Status == EFI_NOT_FOUND) {
+ // Should have found the node.
+ Status = EFI_ABORTED;
+ }
+ return Status;
+ }
+
+ Data = fdt_getprop (Fdt, TimerNode, "interrupts", &DataSize);
+ if ((Data == NULL) ||
+ (DataSize != (FdtMaxTimerItem * IntCells * sizeof (UINT32)))) {
+ // If error or not FdtMaxTimerItem interrupts.
+ ASSERT (0);
+ return EFI_ABORTED;
+ }
+
+ GenericTimerInfo->SecurePL1TimerGSIV =
+ FdtGetInterruptId (&Data[FdtSecureTimerIrq * IntCells]);
+ GenericTimerInfo->SecurePL1TimerFlags =
+ FdtGetInterruptFlags (&Data[FdtSecureTimerIrq * IntCells]);
+ GenericTimerInfo->NonSecurePL1TimerGSIV =
+ FdtGetInterruptId (&Data[FdtNonSecureTimerIrq * IntCells]);
+ GenericTimerInfo->NonSecurePL1TimerFlags =
+ FdtGetInterruptFlags (&Data[FdtNonSecureTimerIrq * IntCells]);
+ GenericTimerInfo->VirtualTimerGSIV =
+ FdtGetInterruptId (&Data[FdtVirtualTimerIrq * IntCells]);
+ GenericTimerInfo->VirtualTimerFlags =
+ FdtGetInterruptFlags (&Data[FdtVirtualTimerIrq * IntCells]);
+ GenericTimerInfo->NonSecurePL2TimerGSIV =
+ FdtGetInterruptId (&Data[FdtHypervisorTimerIrq * IntCells]);
+ GenericTimerInfo->NonSecurePL2TimerFlags =
+ FdtGetInterruptFlags (&Data[FdtHypervisorTimerIrq * IntCells]);
+
+ if (AlwaysOnTimer) {
+ GenericTimerInfo->SecurePL1TimerFlags |= BIT2;
+ GenericTimerInfo->NonSecurePL1TimerFlags |= BIT2;
+ GenericTimerInfo->VirtualTimerFlags |= BIT2;
+ GenericTimerInfo->NonSecurePL2TimerFlags |= BIT2;
+ }
+
+ // Setup default values
+ // The CntControlBase & CntReadBase Physical Address are optional if
+ // the system implements EL3 (Security Extensions). So, initialise
+ // these to their default value.
+ GenericTimerInfo->CounterControlBaseAddress = 0xFFFFFFFFFFFFFFFF;
+ GenericTimerInfo->CounterReadBaseAddress = 0xFFFFFFFFFFFFFFFF;
+
+ // For systems not implementing ARMv8.1 VHE, this field is 0.
+ GenericTimerInfo->VirtualPL2TimerGSIV = 0;
+ GenericTimerInfo->VirtualPL2TimerFlags = 0;
+
+ return EFI_SUCCESS;
+}
+
+/** CM_ARM_GENERIC_TIMER_INFO parser function.
+
+ The following structure is populated:
+ typedef struct CmArmGenericTimerInfo {
+ UINT64 CounterControlBaseAddress; // {default}
+ UINT64 CounterReadBaseAddress; // {default}
+ UINT32 SecurePL1TimerGSIV; // {Populated}
+ UINT32 SecurePL1TimerFlags; // {Populated}
+ UINT32 NonSecurePL1TimerGSIV; // {Populated}
+ UINT32 NonSecurePL1TimerFlags; // {Populated}
+ UINT32 VirtualTimerGSIV; // {Populated}
+ UINT32 VirtualTimerFlags; // {Populated}
+ UINT32 NonSecurePL2TimerGSIV; // {Populated}
+ UINT32 NonSecurePL2TimerFlags; // {Populated}
+ UINT32 VirtualPL2TimerGSIV; // {default}
+ UINT32 VirtualPL2TimerFlags; // {default}
+ } CM_ARM_GENERIC_TIMER_INFO;
+
+ A parser parses a Device Tree to populate a specific CmObj type. None,
+ one or many CmObj can be created by the parser.
+ The created CmObj are then handed to the parser's caller through the
+ HW_INFO_ADD_OBJECT interface.
+ This can also be a dispatcher. I.e. a function that not parsing a
+ Device Tree but calling other parsers.
+
+ @param [in] FdtParserHandle A handle to the parser instance.
+ @param [in] FdtBranch When searching for DT node name, restrict
+ the search to this Device Tree branch.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ABORTED An error occurred.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval EFI_NOT_FOUND Not found.
+ @retval EFI_UNSUPPORTED Unsupported.
+**/
+EFI_STATUS
+EFIAPI
+ArmGenericTimerInfoParser (
+ IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle,
+ IN INT32 FdtBranch
+ )
+{
+ EFI_STATUS Status;
+ UINT32 Index;
+ INT32 TimerNode;
+ UINT32 TimerNodeCount;
+ CM_ARM_GENERIC_TIMER_INFO GenericTimerInfo;
+ VOID * Fdt;
+
+ if (FdtParserHandle == NULL) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Fdt = FdtParserHandle->Fdt;
+ Status = FdtCountCompatNodeInBranch (
+ Fdt,
+ FdtBranch,
+ &TimerCompatibleInfo,
+ &TimerNodeCount
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+
+ if (TimerNodeCount == 0) {
+ return EFI_NOT_FOUND;
+ }
+
+ // Parse each timer node in the branch.
+ TimerNode = FdtBranch;
+ for (Index = 0; Index < TimerNodeCount; Index++) {
+ ZeroMem (&GenericTimerInfo, sizeof (CM_ARM_GENERIC_TIMER_INFO));
+
+ Status = FdtGetNextCompatNodeInBranch (
+ Fdt,
+ FdtBranch,
+ &TimerCompatibleInfo,
+ &TimerNode
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ if (Status == EFI_NOT_FOUND) {
+ // Should have found the node.
+ Status = EFI_ABORTED;
+ }
+ return Status;
+ }
+
+ Status = TimerNodeParser (Fdt, TimerNode, &GenericTimerInfo);
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+
+ // Add the CmObj to the Configuration Manager.
+ Status = AddSingleCmObj (
+ FdtParserHandle,
+ CREATE_CM_ARM_OBJECT_ID (EArmObjGenericTimerInfo),
+ &GenericTimerInfo,
+ sizeof (CM_ARM_GENERIC_TIMER_INFO),
+ NULL
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+ } // for
+
+ return Status;
+}
diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/GenericTimer/ArmGenericTimerParser.h b/DynamicTablesPkg/Library/FdtHwInfoParserLib/GenericTimer/ArmGenericTimerParser.h
new file mode 100644
index 000000000000..e1d294b3eea9
--- /dev/null
+++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/GenericTimer/ArmGenericTimerParser.h
@@ -0,0 +1,66 @@
+/** @file
+ Arm generic timer parser.
+
+ Copyright (c) 2021, ARM Limited. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Reference(s):
+ - linux/Documentation/devicetree/bindings/timer/arm,arch_timer.yaml
+**/
+
+#ifndef ARM_GENERIC_TIMER_PARSER_H_
+#define ARM_GENERIC_TIMER_PARSER_H_
+
+/** An enum listing the FDT interrupt items.
+*/
+typedef enum FdtTimerInterruptItems {
+ FdtSecureTimerIrq, ///< Secure timer IRQ
+ FdtNonSecureTimerIrq, ///< Non-secure timer IRQ
+ FdtVirtualTimerIrq, ///< Virtual timer IRQ
+ FdtHypervisorTimerIrq, ///< Hypervisor timer IRQ
+ FdtMaxTimerItem ///< Max timer item
+} FDT_TIMER_INTERRUPT_ITEMS;
+
+/** CM_ARM_BOOT_ARCH_INFO parser function.
+
+ The following structure is populated:
+ typedef struct CmArmGenericTimerInfo {
+ UINT64 CounterControlBaseAddress; // {default}
+ UINT64 CounterReadBaseAddress; // {default}
+ UINT32 SecurePL1TimerGSIV; // {Populated}
+ UINT32 SecurePL1TimerFlags; // {Populated}
+ UINT32 NonSecurePL1TimerGSIV; // {Populated}
+ UINT32 NonSecurePL1TimerFlags; // {Populated}
+ UINT32 VirtualTimerGSIV; // {Populated}
+ UINT32 VirtualTimerFlags; // {Populated}
+ UINT32 NonSecurePL2TimerGSIV; // {Populated}
+ UINT32 NonSecurePL2TimerFlags; // {Populated}
+ UINT32 VirtualPL2TimerGSIV; // {default}
+ UINT32 VirtualPL2TimerFlags; // {default}
+ } CM_ARM_GENERIC_TIMER_INFO;
+
+ A parser parses a Device Tree to populate a specific CmObj type. None,
+ one or many CmObj can be created by the parser.
+ The created CmObj are then handed to the parser's caller through the
+ HW_INFO_ADD_OBJECT interface.
+ This can also be a dispatcher. I.e. a function that not parsing a
+ Device Tree but calling other parsers.
+
+ @param [in] FdtParserHandle A handle to the parser instance.
+ @param [in] FdtBranch When searching for DT node name, restrict
+ the search to this Device Tree branch.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ABORTED An error occurred.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval EFI_NOT_FOUND Not found.
+ @retval EFI_UNSUPPORTED Unsupported.
+**/
+EFI_STATUS
+EFIAPI
+ArmGenericTimerInfoParser (
+ IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle,
+ IN INT32 FdtBranch
+ );
+
+#endif // ARM_GENERIC_TIMER_PARSER_H_
--
2.17.1


[PATCH v1 04/14] DynamicTablesPkg: FdtHwInfoParser: Add Boot Arch parser

PierreGondois
 

From: Pierre Gondois <Pierre.Gondois@arm.com>

The Fixed ACPI Description Table (FADT) is a mandatory table
required for booting a standards-based operating system. The
FADT table has an 'ARM Boot Architecture Flags' field that is
used by an OS at boot time to determine the code path during
boot. This field is used to specify if the platform complies
with the PSCI specification. It is also used to describe the
conduit (SMC/HVC) to be used for PSCI.

The PSCI compliance information for a platform is described
in the platform Device Tree, the bindings for which can be
found at:
- linux/Documentation/devicetree/bindings/arm/psci.yaml

The FdtHwInfoParser implements a Boot Arch Parser that parses
the platform Device Tree to create a CM_ARM_BOOT_ARCH_INFO
object. The CM_ARM_BOOT_ARCH_INFO object is encapsulated in
a Configuration Manager descriptor object and added to the
platform information repository.

The platform Configuration Manager can then utilise this
information when generating the FADT table.

Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
Signed-off-by: Sami Mujawar <sami.mujawar@arm.com>
---
.../BootArch/ArmBootArchParser.c | 161 ++++++++++++++++++
.../BootArch/ArmBootArchParser.h | 45 +++++
2 files changed, 206 insertions(+)
create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/BootArch/ArmBootArchParser.c
create mode 100644 DynamicTablesPkg/Library/FdtHwInfoParserLib/BootArch/ArmBootArchParser.h

diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/BootArch/ArmBootArchParser.c b/DynamicTablesPkg/Library/FdtHwInfoParserLib/BootArch/ArmBootArchParser.c
new file mode 100644
index 000000000000..b18970f115f2
--- /dev/null
+++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/BootArch/ArmBootArchParser.c
@@ -0,0 +1,161 @@
+/** @file
+ Arm boot architecture parser.
+
+ Copyright (c) 2021, ARM Limited. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Reference(s):
+ - linux/Documentation/devicetree/bindings/arm/psci.yaml
+**/
+
+#include "FdtHwInfoParser.h"
+#include "CmObjectDescUtility.h"
+#include "BootArch/ArmBootArchParser.h"
+
+/** List of "compatible" property values for Psci nodes.
+
+ Other "compatible" values are not supported by this module.
+*/
+STATIC CONST COMPATIBILITY_STR PsciCompatibleStr[] = {
+ {"arm,psci-0.2"},
+ {"arm,psci"}
+};
+
+/** COMPATIBILITY_INFO structure for the PsciCompatibleInfo.
+*/
+STATIC CONST COMPATIBILITY_INFO PsciCompatibleInfo = {
+ ARRAY_SIZE (PsciCompatibleStr),
+ PsciCompatibleStr
+};
+
+/** List of PSCI method strings.
+*/
+STATIC CONST CHAR8 *PsciMethod[] = {
+ "smc",
+ "hvc"
+};
+
+/** Parse a Psci node.
+
+ @param [in] Fdt Pointer to a Flattened Device Tree (Fdt).
+ @param [in] PsciNode Offset of a Psci node.
+ @param [in] BootArchInfo The CM_ARM_BOOT_ARCH_INFO to populate.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ABORTED An error occurred.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+PsciNodeParser (
+ IN CONST VOID * Fdt,
+ IN INT32 PsciNode,
+ IN CM_ARM_BOOT_ARCH_INFO * BootArchInfo
+ )
+{
+ CONST VOID * Data;
+ INT32 DataSize;
+
+ if ((Fdt == NULL) ||
+ (BootArchInfo == NULL)) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ // Default to parking protocol
+ BootArchInfo->BootArchFlags = 0;
+
+ Data = fdt_getprop (Fdt, PsciNode, "method", &DataSize);
+ if ((Data == NULL) || (DataSize < 0)) {
+ ASSERT (0);
+ return EFI_ABORTED;
+ }
+
+ // Check PSCI conduit.
+ if (AsciiStrnCmp (Data, PsciMethod[0], DataSize) == 0) {
+ BootArchInfo->BootArchFlags = EFI_ACPI_6_3_ARM_PSCI_COMPLIANT;
+
+ } else if (AsciiStrnCmp (Data, PsciMethod[1], DataSize) == 0) {
+ BootArchInfo->BootArchFlags = (EFI_ACPI_6_3_ARM_PSCI_COMPLIANT |
+ EFI_ACPI_6_3_ARM_PSCI_USE_HVC);
+ }
+
+ return EFI_SUCCESS;
+}
+
+/** CM_ARM_BOOT_ARCH_INFO parser function.
+
+ The following structure is populated:
+ typedef struct CmArmBootArchInfo {
+ UINT16 BootArchFlags; // {Populated}
+ } CM_ARM_BOOT_ARCH_INFO;
+
+ A parser parses a Device Tree to populate a specific CmObj type. None,
+ one or many CmObj can be created by the parser.
+ The created CmObj are then handed to the parser's caller through the
+ HW_INFO_ADD_OBJECT interface.
+ This can also be a dispatcher. I.e. a function that not parsing a
+ Device Tree but calling other parsers.
+
+ @param [in] FdtParserHandle A handle to the parser instance.
+ @param [in] FdtBranch When searching for DT node name, restrict
+ the search to this Device Tree branch.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ABORTED An error occurred.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval EFI_NOT_FOUND Not found.
+ @retval EFI_UNSUPPORTED Unsupported.
+**/
+EFI_STATUS
+EFIAPI
+ArmBootArchInfoParser (
+ IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle,
+ IN INT32 FdtBranch
+ )
+{
+ EFI_STATUS Status;
+ INT32 PsciNode;
+ CM_ARM_BOOT_ARCH_INFO BootArchInfo;
+
+ if (FdtParserHandle == NULL) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ ZeroMem (&BootArchInfo, sizeof (CM_ARM_BOOT_ARCH_INFO));
+
+ PsciNode = FdtBranch;
+ Status = FdtGetNextCompatNodeInBranch (
+ FdtParserHandle->Fdt,
+ FdtBranch,
+ &PsciCompatibleInfo,
+ &PsciNode
+ );
+ if (EFI_ERROR (Status)) {
+ // Error, or no node found.
+ ASSERT (Status == EFI_NOT_FOUND);
+ return Status;
+ }
+
+ // Parse the psci node.
+ Status = PsciNodeParser (FdtParserHandle->Fdt, PsciNode, &BootArchInfo);
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ return Status;
+ }
+
+ // Add the CmObj to the Configuration Manager.
+ Status = AddSingleCmObj (
+ FdtParserHandle,
+ CREATE_CM_ARM_OBJECT_ID (EArmObjBootArchInfo),
+ &BootArchInfo,
+ sizeof (CM_ARM_BOOT_ARCH_INFO),
+ NULL
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT (0);
+ }
+ return Status;
+}
diff --git a/DynamicTablesPkg/Library/FdtHwInfoParserLib/BootArch/ArmBootArchParser.h b/DynamicTablesPkg/Library/FdtHwInfoParserLib/BootArch/ArmBootArchParser.h
new file mode 100644
index 000000000000..959c65a53fb3
--- /dev/null
+++ b/DynamicTablesPkg/Library/FdtHwInfoParserLib/BootArch/ArmBootArchParser.h
@@ -0,0 +1,45 @@
+/** @file
+ Arm boot architecture parser.
+
+ Copyright (c) 2021, ARM Limited. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Reference(s):
+ - linux/Documentation/devicetree/bindings/arm/psci.yaml
+**/
+
+#ifndef ARM_BOOT_ARCH_PARSER_H_
+#define ARM_BOOT_ARCH_PARSER_H_
+
+/** CM_ARM_BOOT_ARCH_INFO parser function.
+
+ The following structure is populated:
+ typedef struct CmArmBootArchInfo {
+ UINT16 BootArchFlags; // {Populated}
+ } CM_ARM_BOOT_ARCH_INFO;
+
+ A parser parses a Device Tree to populate a specific CmObj type. None,
+ one or many CmObj can be created by the parser.
+ The created CmObj are then handed to the parser's caller through the
+ HW_INFO_ADD_OBJECT interface.
+ This can also be a dispatcher. I.e. a function that not parsing a
+ Device Tree but calling other parsers.
+
+ @param [in] FdtParserHandle A handle to the parser instance.
+ @param [in] FdtBranch When searching for DT node name, restrict
+ the search to this Device Tree branch.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_ABORTED An error occurred.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+ @retval EFI_NOT_FOUND Not found.
+ @retval EFI_UNSUPPORTED Unsupported.
+**/
+EFI_STATUS
+EFIAPI
+ArmBootArchInfoParser (
+ IN CONST FDT_HW_INFO_PARSER_HANDLE FdtParserHandle,
+ IN INT32 FdtBranch
+ );
+
+#endif // ARM_BOOT_ARCH_PARSER_H_
--
2.17.1

5401 - 5420 of 82316