4 Copyright (c) 2019, ARM Limited. All rights reserved.
5 SPDX-License-Identifier: BSD-2-Clause-Patent
8 - ACPI 6.3 Specification, January 2019
11 - Cm or CM - Configuration Manager
15 #include <Library/AcpiLib.h>
16 #include <Library/BaseLib.h>
17 #include <Library/DebugLib.h>
18 #include <Library/MemoryAllocationLib.h>
19 #include <Protocol/AcpiTable.h>
21 // Module specific include files.
22 #include <AcpiTableGenerator.h>
23 #include <ConfigurationManagerObject.h>
24 #include <ConfigurationManagerHelper.h>
25 #include <Library/TableHelperLib.h>
26 #include <Protocol/ConfigurationManagerProtocol.h>
28 #include "PpttGenerator.h"
31 ARM standard PPTT Generator
34 The following Configuration Manager Object(s) are used by this Generator:
35 - EArmObjProcHierarchyInfo (REQUIRED)
37 - EArmObjProcNodeIdInfo
39 - EArmObjGicCInfo (REQUIRED)
43 This macro expands to a function that retrieves the Processor Hierarchy
44 information from the Configuration Manager.
48 EArmObjProcHierarchyInfo
,
49 CM_ARM_PROC_HIERARCHY_INFO
53 This macro expands to a function that retrieves the cache information
54 from the Configuration Manager.
63 This macro expands to a function that retrieves the ID information for
64 Processor Hierarchy Nodes from the Configuration Manager.
68 EArmObjProcNodeIdInfo
,
69 CM_ARM_PROC_NODE_ID_INFO
73 This macro expands to a function that retrieves the cross-CM-object-
74 reference information from the Configuration Manager.
83 This macro expands to a function that retrieves the GIC CPU interface
84 information from the Configuration Manager.
93 Returns the size of the PPTT Processor Hierarchy Node (Type 0) given a
94 Processor Hierarchy Info CM object.
96 @param [in] Node Pointer to Processor Hierarchy Info CM object which
97 represents the Processor Hierarchy Node to be generated.
99 @retval Size of the Processor Hierarchy Node in bytes.
103 GetProcHierarchyNodeSize (
104 IN CONST CM_ARM_PROC_HIERARCHY_INFO
* Node
107 ASSERT (Node
!= NULL
);
109 // <size of Processor Hierarchy Node> + <size of Private Resources array>
110 return sizeof (EFI_ACPI_6_3_PPTT_STRUCTURE_PROCESSOR
) +
111 (Node
->NoOfPrivateResources
* sizeof (UINT32
));
115 This macro expands to a function that retrieves the amount of memory required
116 to store the Processor Hierarchy Nodes (Type 0) and updates the Node Indexer.
118 GET_SIZE_OF_PPTT_STRUCTS (
120 GetProcHierarchyNodeSize (NodesToIndex
),
121 CM_ARM_PROC_HIERARCHY_INFO
125 This macro expands to a function that retrieves the amount of memory required
126 to store the Cache Type Structures (Type 1) and updates the Node Indexer.
128 GET_SIZE_OF_PPTT_STRUCTS (
130 sizeof (EFI_ACPI_6_3_PPTT_STRUCTURE_CACHE
),
134 /** This macro expands to a function that retrieves the amount of memory
135 required to store the ID Structures (Type 2) and updates the Node Indexer.
137 GET_SIZE_OF_PPTT_STRUCTS (
139 sizeof (EFI_ACPI_6_3_PPTT_STRUCTURE_ID
),
140 CM_ARM_PROC_NODE_ID_INFO
144 Search the Node Indexer and return the indexed PPTT node with the given
147 @param [in] NodeIndexer Pointer to the Node Indexer array.
148 @param [in] NodeCount Number of elements in Node Indexer.
149 @param [in] SearchToken Token used for Node Indexer lookup.
150 @param [out] IndexedNodeFound Pointer to the Node Indexer array element
151 with the given Token.
153 @retval EFI_SUCCESS Success.
154 @retval EFI_NOT_FOUND No element with a matching token was
155 found in the Node Indexer array.
159 GetPpttNodeReferencedByToken (
160 IN PPTT_NODE_INDEXER
* NodeIndexer
,
162 IN CONST CM_OBJECT_TOKEN SearchToken
,
163 OUT PPTT_NODE_INDEXER
** IndexedNodeFound
168 ASSERT (NodeIndexer
!= NULL
);
172 "PPTT: Node Indexer: SearchToken = %p\n",
176 while (NodeCount
-- != 0) {
179 "PPTT: Node Indexer: NodeIndexer->Token = %p. Offset = %d\n",
184 if (NodeIndexer
->Token
== SearchToken
) {
185 *IndexedNodeFound
= NodeIndexer
;
186 Status
= EFI_SUCCESS
;
189 "PPTT: Node Indexer: Token = %p. Found, Status = %r\n",
198 Status
= EFI_NOT_FOUND
;
201 "PPTT: Node Indexer: SearchToken = %p. Status = %r\n",
210 Detect cycles in the processor and cache topology graph represented in
213 @param [in] Generator Pointer to the PPTT Generator.
215 @retval EFI_SUCCESS There are no cyclic references in the graph.
216 @retval EFI_INVALID_PARAMETER Processor or cache references form a cycle.
220 DetectCyclesInTopology (
221 IN CONST ACPI_PPTT_GENERATOR
* CONST Generator
225 PPTT_NODE_INDEXER
* Iterator
;
226 PPTT_NODE_INDEXER
* CycleDetector
;
227 UINT32 NodesRemaining
;
229 ASSERT (Generator
!= NULL
);
231 Iterator
= Generator
->NodeIndexer
;
232 NodesRemaining
= Generator
->ProcTopologyStructCount
;
234 while (NodesRemaining
!= 0) {
237 "INFO: PPTT: Cycle detection for element with index %d\n",
238 Generator
->ProcTopologyStructCount
- NodesRemaining
241 CycleDetector
= Iterator
;
243 // Walk the topology tree
244 while (CycleDetector
->TopologyParent
!= NULL
) {
247 "INFO: PPTT: %p -> %p\n",
248 CycleDetector
->Token
,
249 CycleDetector
->TopologyParent
->Token
252 // Check if we have already visited this node
253 if (CycleDetector
->CycleDetectionStamp
== NodesRemaining
) {
254 Status
= EFI_INVALID_PARAMETER
;
257 "ERROR: PPTT: Cycle in processor and cache topology detected for " \
258 "a chain of references originating from a node with: Token = %p " \
266 // Stamp the visited node
267 CycleDetector
->CycleDetectionStamp
= NodesRemaining
;
268 CycleDetector
= CycleDetector
->TopologyParent
;
269 } // Continue topology tree walk
273 } // Next Node Indexer
279 Update the array of private resources for a given Processor Hierarchy Node.
281 @param [in] Generator Pointer to the PPTT Generator.
282 @param [in] CfgMgrProtocol Pointer to the Configuration Manager
284 @param [in] PrivResArray Pointer to the array of private resources.
285 @param [in] PrivResCount Number of private resources.
286 @param [in] PrivResArrayToken Reference Token for the CM_ARM_OBJ_REF
287 array describing node's private resources.
289 @retval EFI_SUCCESS Array updated successfully.
290 @retval EFI_INVALID_PARAMETER A parameter is invalid.
291 @retval EFI_NOT_FOUND A private resource was not found.
295 AddPrivateResources (
296 IN CONST ACPI_PPTT_GENERATOR
* CONST Generator
,
297 IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL
* CONST CfgMgrProtocol
,
298 IN UINT32
* PrivResArray
,
299 IN UINT32 PrivResCount
,
300 IN CONST CM_OBJECT_TOKEN PrivResArrayToken
304 CM_ARM_OBJ_REF
* CmObjRefs
;
305 UINT32 CmObjRefCount
;
306 PPTT_NODE_INDEXER
* PpttNodeFound
;
309 (Generator
!= NULL
) &&
310 (CfgMgrProtocol
!= NULL
) &&
311 (PrivResArray
!= NULL
) &&
315 // Validate input arguments
316 if (PrivResArrayToken
== CM_NULL_TOKEN
) {
317 Status
= EFI_INVALID_PARAMETER
;
320 "ERROR: PPTT: The number of private resources is %d while " \
321 "PrivResToken = CM_NULL_TOKEN. Status = %r\n",
329 // Get the CM Object References
330 Status
= GetEArmObjCmRef (
336 if (EFI_ERROR (Status
)) {
339 "ERROR: PPTT: Failed to get CM Object References. " \
340 "PrivResToken = %p. Status = %r\n",
347 if (CmObjRefCount
!= PrivResCount
) {
348 Status
= EFI_INVALID_PARAMETER
;
351 "ERROR: PPTT: The number of CM Object References retrieved and the " \
352 "number of private resources don't match. CmObjRefCount = %d. " \
353 "PrivResourceCount = %d. PrivResToken = %p. Status = %r\n",
362 while (PrivResCount
-- != 0) {
363 if (CmObjRefs
->ReferenceToken
== CM_NULL_TOKEN
) {
364 Status
= EFI_INVALID_PARAMETER
;
367 "ERROR: PPTT: CM_NULL_TOKEN provided as reference token for a " \
368 "private resource. Status = %r\n",
374 // The Node indexer has the Processor hierarchy nodes at the begining
375 // followed by the cache structs and Id structs. Therefore we can
376 // skip the Processor hierarchy nodes in the node indexer search.
377 Status
= GetPpttNodeReferencedByToken (
378 Generator
->CacheStructIndexedList
,
379 (Generator
->ProcTopologyStructCount
-
380 Generator
->ProcHierarchyNodeCount
),
381 CmObjRefs
->ReferenceToken
,
384 if (EFI_ERROR (Status
)) {
387 "ERROR: PPTT: Failed to get a private resource with Token = %p from " \
388 "Node Indexer. Status = %r\n",
389 CmObjRefs
->ReferenceToken
,
395 // Update the offset of the private resources in the Processor
396 // Hierarchy Node structure
397 *(PrivResArray
++) = PpttNodeFound
->Offset
;
405 Function to test if two indexed Processor Hierarchy Info objects map to the
406 same GIC CPU Interface Info object.
408 This is a callback function that can be invoked by FindDuplicateValue ().
410 @param [in] Object1 Pointer to the first indexed Processor Hierarchy
412 @param [in] Object2 Pointer to the second indexed Processor Hierarchy
414 @param [in] Index1 Index of Object1 to be displayed for debugging
416 @param [in] Index2 Index of Object2 to be displayed for debugging
419 @retval TRUE Object1 and Object2 have the same GicCToken.
420 @retval FALSE Object1 and Object2 have different GicCTokens.
425 IN CONST VOID
* Object1
,
426 IN CONST VOID
* Object2
,
431 PPTT_NODE_INDEXER
* IndexedObject1
;
432 PPTT_NODE_INDEXER
* IndexedObject2
;
433 CM_ARM_PROC_HIERARCHY_INFO
* ProcNode1
;
434 CM_ARM_PROC_HIERARCHY_INFO
* ProcNode2
;
441 IndexedObject1
= (PPTT_NODE_INDEXER
*)Object1
;
442 IndexedObject2
= (PPTT_NODE_INDEXER
*)Object2
;
443 ProcNode1
= (CM_ARM_PROC_HIERARCHY_INFO
*)IndexedObject1
->Object
;
444 ProcNode2
= (CM_ARM_PROC_HIERARCHY_INFO
*)IndexedObject2
->Object
;
446 if (IS_ACPI_PROC_ID_VALID (ProcNode1
) &&
447 IS_ACPI_PROC_ID_VALID (ProcNode2
) &&
448 (ProcNode1
->GicCToken
!= CM_NULL_TOKEN
) &&
449 (ProcNode2
->GicCToken
!= CM_NULL_TOKEN
) &&
450 (ProcNode1
->GicCToken
== ProcNode2
->GicCToken
)) {
453 "ERROR: PPTT: Two Processor Hierarchy Info objects (%d and %d) map to " \
454 "the same GICC Info object. ACPI Processor IDs are not unique. " \
457 IndexedObject1
->Token
,
468 Update the Processor Hierarchy Node (Type 0) information.
470 This function populates the Processor Hierarchy Nodes with information from
471 the Configuration Manager and adds this information to the PPTT table.
473 @param [in] Generator Pointer to the PPTT Generator.
474 @param [in] CfgMgrProtocol Pointer to the Configuration Manager
476 @param [in] Pptt Pointer to PPTT table structure.
477 @param [in] NodesStartOffset Offset from the start of PPTT table to the
478 start of Processor Hierarchy Nodes.
480 @retval EFI_SUCCESS Node updated successfully.
481 @retval EFI_INVALID_PARAMETER A parameter is invalid.
482 @retval EFI_NOT_FOUND The required object was not found.
486 AddProcHierarchyNodes (
487 IN CONST ACPI_PPTT_GENERATOR
* CONST Generator
,
488 IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL
* CONST CfgMgrProtocol
,
489 IN CONST EFI_ACPI_6_3_PROCESSOR_PROPERTIES_TOPOLOGY_TABLE_HEADER
* Pptt
,
490 IN CONST UINT32 NodesStartOffset
494 EFI_ACPI_6_3_PPTT_STRUCTURE_PROCESSOR
* ProcStruct
;
495 UINT32
* PrivateResources
;
496 BOOLEAN IsGicCTokenDuplicated
;
498 CM_ARM_GICC_INFO
* GicCInfoList
;
499 UINT32 GicCInfoCount
;
500 UINT32 UniqueGicCRefCount
;
502 PPTT_NODE_INDEXER
* PpttNodeFound
;
503 CM_ARM_PROC_HIERARCHY_INFO
* ProcInfoNode
;
505 PPTT_NODE_INDEXER
* ProcNodeIterator
;
509 (Generator
!= NULL
) &&
510 (CfgMgrProtocol
!= NULL
) &&
514 ProcStruct
= (EFI_ACPI_6_3_PPTT_STRUCTURE_PROCESSOR
*)((UINT8
*)Pptt
+
517 ProcNodeIterator
= Generator
->ProcHierarchyNodeIndexedList
;
518 NodeCount
= Generator
->ProcHierarchyNodeCount
;
520 // Check if every GICC Object is referenced by onlu one Proc Node
521 IsGicCTokenDuplicated
= FindDuplicateValue (
524 sizeof (PPTT_NODE_INDEXER
),
527 // Duplicate GIC CPU Interface Token was found so two PPTT Processor Hierarchy
528 // Nodes map to the same MADT GICC structure
529 if (IsGicCTokenDuplicated
) {
530 return EFI_INVALID_PARAMETER
;
533 UniqueGicCRefCount
= 0;
535 while (NodeCount
-- != 0) {
536 ProcInfoNode
= (CM_ARM_PROC_HIERARCHY_INFO
*)ProcNodeIterator
->Object
;
538 // Check if the private resource count is within the size limit
539 // imposed on the Processor Hierarchy node by the specification.
540 // Note: The length field is 8 bit wide while the number of private
541 // resource field is 32 bit wide.
542 if ((sizeof (EFI_ACPI_6_3_PPTT_STRUCTURE_PROCESSOR
) +
543 (ProcInfoNode
->NoOfPrivateResources
* sizeof (UINT32
))) > MAX_UINT8
) {
544 Status
= EFI_INVALID_PARAMETER
;
547 "ERROR: PPTT: Too many private resources. Count = %d. " \
548 "Maximum supported Processor Node size exceeded. " \
549 "Token = %p. Status = %r\n",
550 ProcInfoNode
->NoOfPrivateResources
,
551 ProcInfoNode
->ParentToken
,
557 // Populate the node header
558 ProcStruct
->Type
= EFI_ACPI_6_3_PPTT_TYPE_PROCESSOR
;
559 ProcStruct
->Length
= GetProcHierarchyNodeSize (ProcInfoNode
);
560 ProcStruct
->Reserved
[0] = EFI_ACPI_RESERVED_BYTE
;
561 ProcStruct
->Reserved
[1] = EFI_ACPI_RESERVED_BYTE
;
563 // Populate the flags
564 ProcStruct
->Flags
.PhysicalPackage
= ProcInfoNode
->Flags
& BIT0
;
565 ProcStruct
->Flags
.AcpiProcessorIdValid
= (ProcInfoNode
->Flags
& BIT1
) >> 1;
566 ProcStruct
->Flags
.ProcessorIsAThread
= (ProcInfoNode
->Flags
& BIT2
) >> 2;
567 ProcStruct
->Flags
.NodeIsALeaf
= (ProcInfoNode
->Flags
& BIT3
) >> 3;
568 ProcStruct
->Flags
.IdenticalImplementation
=
569 (ProcInfoNode
->Flags
& BIT4
) >> 4;
570 ProcStruct
->Flags
.Reserved
= 0;
572 // Populate the parent reference
573 if (ProcInfoNode
->ParentToken
== CM_NULL_TOKEN
) {
574 ProcStruct
->Parent
= 0;
576 Status
= GetPpttNodeReferencedByToken (
577 Generator
->ProcHierarchyNodeIndexedList
,
578 Generator
->ProcHierarchyNodeCount
,
579 ProcInfoNode
->ParentToken
,
582 if (EFI_ERROR (Status
)) {
585 "ERROR: PPTT: Failed to get parent processor hierarchy node " \
586 "reference. Token = %p, Status = %r\n",
587 ProcInfoNode
->ParentToken
,
594 // Test if the reference is to a 'leaf' node
595 if (IS_PROC_NODE_LEAF (
596 ((CM_ARM_PROC_HIERARCHY_INFO
*)PpttNodeFound
->Object
))) {
597 Status
= EFI_INVALID_PARAMETER
;
600 "ERROR: PPTT: Reference to a leaf Processor Hierarchy Node. " \
601 "ParentToken = %p. ChildToken = %p. Status = %r\n",
602 ProcInfoNode
->ParentToken
,
609 // Update Proc Structure with the offset of the parent node
610 ProcStruct
->Parent
= PpttNodeFound
->Offset
;
612 // Store the reference for the parent node in the Node Indexer
613 // so that this can be used later for cycle detection
614 ProcNodeIterator
->TopologyParent
= PpttNodeFound
;
617 // Populate ACPI Processor ID
618 if (!IS_ACPI_PROC_ID_VALID (ProcInfoNode
)) {
619 // Default invalid ACPI Processor ID to 0
620 ProcStruct
->AcpiProcessorId
= 0;
621 } else if (ProcInfoNode
->GicCToken
== CM_NULL_TOKEN
) {
622 Status
= EFI_INVALID_PARAMETER
;
625 "ERROR: PPTT: The 'ACPI Processor ID valid' flag is set but no GICC " \
626 "structure token was provided. GicCToken = %p. RequestorToken = %p. " \
628 ProcInfoNode
->GicCToken
,
634 Status
= GetEArmObjGicCInfo (
636 ProcInfoNode
->GicCToken
,
640 if (EFI_ERROR (Status
)) {
643 "ERROR: PPTT: Failed to get GICC structure. ACPI Processor ID " \
644 "can't be populated. GicCToken = %p. RequestorToken = %p. " \
646 ProcInfoNode
->GicCToken
,
653 if (GicCInfoCount
!= 1) {
654 Status
= EFI_INVALID_PARAMETER
;
657 "ERROR: PPTT: Failed to find a unique GICC structure. " \
658 "ACPI Processor ID can't be populated. " \
659 "GICC Structure Count = %d. GicCToken = %p. RequestorToken = %p " \
662 ProcInfoNode
->GicCToken
,
669 // Update the ACPI Processor Id
670 ProcStruct
->AcpiProcessorId
= GicCInfoList
->AcpiProcessorUid
;
672 // Increment the reference count for the number of
673 // Unique GICC objects that were retrieved.
674 UniqueGicCRefCount
++;
677 ProcStruct
->NumberOfPrivateResources
= ProcInfoNode
->NoOfPrivateResources
;
678 PrivateResources
= (UINT32
*)((UINT8
*)ProcStruct
+
679 sizeof (EFI_ACPI_6_3_PPTT_STRUCTURE_PROCESSOR
));
681 if (ProcStruct
->NumberOfPrivateResources
!= 0) {
682 // Populate the private resources array
683 Status
= AddPrivateResources (
687 ProcStruct
->NumberOfPrivateResources
,
688 ProcInfoNode
->PrivateResourcesArrayToken
690 if (EFI_ERROR (Status
)) {
693 "ERROR: PPTT: Failed to populate the private resources array. " \
701 // Next Processor Hierarchy Node
702 ProcStruct
= (EFI_ACPI_6_3_PPTT_STRUCTURE_PROCESSOR
*)((UINT8
*)ProcStruct
+
705 } // Processor Hierarchy Node
707 // Knowing the total number of GICC references made and that all GICC Token
708 // references are unique, we can test if no GICC instances have been left out.
709 Status
= GetEArmObjGicCInfo (
715 if (EFI_ERROR (Status
)) {
718 "ERROR: PPTT: Failed to get GICC Info. Status = %r\n",
724 // MADT - PPTT cross validation
725 // This checks that one and only one GICC structure is referenced by a
726 // Processor Hierarchy Node in the PPTT.
727 // Since we have already checked that the GICC objects referenced by the
728 // Proc Nodes are unique, the UniqueGicCRefCount cannot be greater than
729 // the total number of GICC objects in the platform.
730 if (GicCInfoCount
> UniqueGicCRefCount
) {
731 Status
= EFI_INVALID_PARAMETER
;
734 "ERROR: PPTT: %d GICC structure(s) exposed by MADT don't have " \
735 "a corresponding Processor Hierarchy Node. Status = %r\n",
736 GicCInfoCount
- UniqueGicCRefCount
,
745 Update the Cache Type Structure (Type 1) information.
747 This function populates the Cache Type Structures with information from
748 the Configuration Manager and adds this information to the PPTT table.
750 @param [in] Generator Pointer to the PPTT Generator.
751 @param [in] CfgMgrProtocol Pointer to the Configuration Manager
753 @param [in] Pptt Pointer to PPTT table structure.
754 @param [in] NodesStartOffset Offset from the start of PPTT table to the
755 start of Cache Type Structures.
757 @retval EFI_SUCCESS Structures updated successfully.
758 @retval EFI_INVALID_PARAMETER A parameter is invalid.
759 @retval EFI_NOT_FOUND A required object was not found.
763 AddCacheTypeStructures (
764 IN CONST ACPI_PPTT_GENERATOR
* CONST Generator
,
765 IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL
* CONST CfgMgrProtocol
,
766 IN CONST EFI_ACPI_6_3_PROCESSOR_PROPERTIES_TOPOLOGY_TABLE_HEADER
* Pptt
,
767 IN CONST UINT32 NodesStartOffset
771 EFI_ACPI_6_3_PPTT_STRUCTURE_CACHE
* CacheStruct
;
772 PPTT_NODE_INDEXER
* PpttNodeFound
;
773 CM_ARM_CACHE_INFO
* CacheInfoNode
;
774 PPTT_NODE_INDEXER
* CacheNodeIterator
;
778 (Generator
!= NULL
) &&
779 (CfgMgrProtocol
!= NULL
) &&
783 CacheStruct
= (EFI_ACPI_6_3_PPTT_STRUCTURE_CACHE
*)((UINT8
*)Pptt
+
786 CacheNodeIterator
= Generator
->CacheStructIndexedList
;
787 NodeCount
= Generator
->CacheStructCount
;
789 while (NodeCount
-- != 0) {
790 CacheInfoNode
= (CM_ARM_CACHE_INFO
*)CacheNodeIterator
->Object
;
792 // Populate the node header
793 CacheStruct
->Type
= EFI_ACPI_6_3_PPTT_TYPE_CACHE
;
794 CacheStruct
->Length
= sizeof (EFI_ACPI_6_3_PPTT_STRUCTURE_CACHE
);
795 CacheStruct
->Reserved
[0] = EFI_ACPI_RESERVED_BYTE
;
796 CacheStruct
->Reserved
[1] = EFI_ACPI_RESERVED_BYTE
;
798 // "On Arm-based systems, all cache properties must be provided in the
799 // table." (ACPI 6.3, Section 5.2.29.2)
800 CacheStruct
->Flags
.SizePropertyValid
= 1;
801 CacheStruct
->Flags
.NumberOfSetsValid
= 1;
802 CacheStruct
->Flags
.AssociativityValid
= 1;
803 CacheStruct
->Flags
.AllocationTypeValid
= 1;
804 CacheStruct
->Flags
.CacheTypeValid
= 1;
805 CacheStruct
->Flags
.WritePolicyValid
= 1;
806 CacheStruct
->Flags
.LineSizeValid
= 1;
807 CacheStruct
->Flags
.Reserved
= 0;
809 // Populate the reference to the next level of cache
810 if (CacheInfoNode
->NextLevelOfCacheToken
== CM_NULL_TOKEN
) {
811 CacheStruct
->NextLevelOfCache
= 0;
813 Status
= GetPpttNodeReferencedByToken (
814 Generator
->CacheStructIndexedList
,
815 Generator
->CacheStructCount
,
816 CacheInfoNode
->NextLevelOfCacheToken
,
819 if (EFI_ERROR (Status
)) {
822 "ERROR: PPTT: Failed to get the reference to the Next Level of " \
823 "Cache. NextLevelOfCacheToken = %p. RequestorToken = %p. " \
825 CacheInfoNode
->NextLevelOfCacheToken
,
826 CacheInfoNode
->Token
,
832 // Update Cache Structure with the offset for the next level of cache
833 CacheStruct
->NextLevelOfCache
= PpttNodeFound
->Offset
;
835 // Store the next level of cache information in the Node Indexer
836 // so that this can be used later for cycle detection
837 CacheNodeIterator
->TopologyParent
= PpttNodeFound
;
840 CacheStruct
->Size
= CacheInfoNode
->Size
;
842 // Validate and populate the 'Number of sets' field
843 if (CacheInfoNode
->NumberOfSets
> PPTT_ARM_CCIDX_CACHE_NUMBER_OF_SETS_MAX
) {
844 Status
= EFI_INVALID_PARAMETER
;
847 "ERROR: PPTT: When ARMv8.3-CCIDX is implemented the maximum number " \
848 "of sets can be %d. NumberOfSets = %d. Status = %r\n",
849 PPTT_ARM_CCIDX_CACHE_NUMBER_OF_SETS_MAX
,
850 CacheInfoNode
->NumberOfSets
,
856 if (CacheInfoNode
->NumberOfSets
> PPTT_ARM_CACHE_NUMBER_OF_SETS_MAX
) {
859 "INFO: PPTT: When ARMv8.3-CCIDX is not implemented the maximum " \
860 "number of sets can be %d. NumberOfSets = %d\n",
861 PPTT_ARM_CACHE_NUMBER_OF_SETS_MAX
,
862 CacheInfoNode
->NumberOfSets
866 CacheStruct
->NumberOfSets
= CacheInfoNode
->NumberOfSets
;
868 // Validate Associativity field based on maximum associativity
869 // supported by ACPI Cache type structure.
870 if (CacheInfoNode
->Associativity
> MAX_UINT8
) {
871 Status
= EFI_INVALID_PARAMETER
;
874 "ERROR: PPTT: The maximum associativity supported by ACPI " \
875 "Cache type structure is %d. Associativity = %d, Status = %r\n",
877 CacheInfoNode
->Associativity
,
883 // Validate the Associativity field based on the architecture specification
884 // The architecture supports much larger associativity values than the
885 // current ACPI specification.
886 // These checks will be needed in the future when the ACPI specification
887 // is extended. Disabling this code for now.
889 if (CacheInfoNode
->Associativity
> PPTT_ARM_CCIDX_CACHE_ASSOCIATIVITY_MAX
) {
890 Status
= EFI_INVALID_PARAMETER
;
893 "ERROR: PPTT: When ARMv8.3-CCIDX is implemented the maximum cache " \
894 "associativity can be %d. Associativity = %d. Status = %r\n",
895 PPTT_ARM_CCIDX_CACHE_ASSOCIATIVITY_MAX
,
896 CacheInfoNode
->Associativity
,
902 if (CacheInfoNode
->Associativity
> PPTT_ARM_CACHE_ASSOCIATIVITY_MAX
) {
905 "INFO: PPTT: When ARMv8.3-CCIDX is not implemented the maximum " \
906 "cache associativity can be %d. Associativity = %d\n",
907 PPTT_ARM_CACHE_ASSOCIATIVITY_MAX
,
908 CacheInfoNode
->Associativity
913 // Note a typecast is needed as the maximum associativity
914 // supported by ACPI Cache type structure is MAX_UINT8.
915 CacheStruct
->Associativity
= (UINT8
)CacheInfoNode
->Associativity
;
917 // Populate cache attributes
918 CacheStruct
->Attributes
.AllocationType
=
919 CacheInfoNode
->Attributes
& (BIT0
| BIT1
);
920 CacheStruct
->Attributes
.CacheType
=
921 (CacheInfoNode
->Attributes
& (BIT2
| BIT3
)) >> 2;
922 CacheStruct
->Attributes
.WritePolicy
=
923 (CacheInfoNode
->Attributes
& BIT4
) >> 4;
924 CacheStruct
->Attributes
.Reserved
= 0;
926 // Validate and populate cache line size
927 if ((CacheInfoNode
->LineSize
< PPTT_ARM_CACHE_LINE_SIZE_MIN
) ||
928 (CacheInfoNode
->LineSize
> PPTT_ARM_CACHE_LINE_SIZE_MAX
)) {
930 Status
= EFI_INVALID_PARAMETER
;
933 "ERROR: PPTT: The cache line size must be between %d and %d bytes " \
934 "on ARM Platforms. LineSize = %d. Status = %r\n" ,
935 PPTT_ARM_CACHE_LINE_SIZE_MIN
,
936 PPTT_ARM_CACHE_LINE_SIZE_MAX
,
937 CacheInfoNode
->LineSize
,
943 if ((CacheInfoNode
->LineSize
& (CacheInfoNode
->LineSize
- 1)) != 0) {
944 Status
= EFI_INVALID_PARAMETER
;
947 "ERROR: PPTT: The cache line size is not a power of 2. " \
948 "LineSize = %d. Status = %r\n" ,
949 CacheInfoNode
->LineSize
,
955 CacheStruct
->LineSize
= CacheInfoNode
->LineSize
;
957 // Next Cache Type Structure
958 CacheStruct
= (EFI_ACPI_6_3_PPTT_STRUCTURE_CACHE
*)((UINT8
*)CacheStruct
+
959 CacheStruct
->Length
);
961 } // Cache Type Structure
967 Update the ID Type Structure (Type 2) information.
969 This function populates the ID Type Structures with information from
970 the Configuration Manager and and adds this information to the PPTT table.
972 @param [in] Generator Pointer to the PPTT Generator.
973 @param [in] CfgMgrProtocol Pointer to the Configuration Manager
975 @param [in] Pptt Pointer to PPTT table structure.
976 @param [in] NodesStartOffset Offset from the start of PPTT table to the
977 start of ID Type Structures.
979 @retval EFI_SUCCESS Structures updated successfully.
980 @retval EFI_INVALID_PARAMETER A parameter is invalid.
981 @retval EFI_NOT_FOUND A required object was not found.
985 AddIdTypeStructures (
986 IN CONST ACPI_PPTT_GENERATOR
* CONST Generator
,
987 IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL
* CONST CfgMgrProtocol
,
988 IN CONST EFI_ACPI_6_3_PROCESSOR_PROPERTIES_TOPOLOGY_TABLE_HEADER
* Pptt
,
989 IN CONST UINT32 NodesStartOffset
992 EFI_ACPI_6_3_PPTT_STRUCTURE_ID
* IdStruct
;
993 CM_ARM_PROC_NODE_ID_INFO
* ProcIdInfoNode
;
994 PPTT_NODE_INDEXER
* IdStructIterator
;
999 (Generator
!= NULL
) &&
1000 (CfgMgrProtocol
!= NULL
) &&
1004 IdStruct
= (EFI_ACPI_6_3_PPTT_STRUCTURE_ID
*)((UINT8
*)Pptt
+ NodesStartOffset
);
1006 IdStructIterator
= Generator
->IdStructIndexedList
;
1007 NodeCount
= Generator
->IdStructCount
;
1008 while (NodeCount
-- != 0) {
1009 ProcIdInfoNode
= (CM_ARM_PROC_NODE_ID_INFO
*)IdStructIterator
->Object
;
1011 // Populate the node
1012 IdStruct
->Type
= EFI_ACPI_6_3_PPTT_TYPE_ID
;
1013 IdStruct
->Length
= sizeof (EFI_ACPI_6_3_PPTT_STRUCTURE_ID
);
1014 IdStruct
->Reserved
[0] = EFI_ACPI_RESERVED_BYTE
;
1015 IdStruct
->Reserved
[1] = EFI_ACPI_RESERVED_BYTE
;
1016 IdStruct
->VendorId
= ProcIdInfoNode
->VendorId
;
1017 IdStruct
->Level1Id
= ProcIdInfoNode
->Level1Id
;
1018 IdStruct
->Level2Id
= ProcIdInfoNode
->Level2Id
;
1019 IdStruct
->MajorRev
= ProcIdInfoNode
->MajorRev
;
1020 IdStruct
->MinorRev
= ProcIdInfoNode
->MinorRev
;
1021 IdStruct
->SpinRev
= ProcIdInfoNode
->SpinRev
;
1023 // Next ID Type Structure
1024 IdStruct
= (EFI_ACPI_6_3_PPTT_STRUCTURE_ID
*)((UINT8
*)IdStruct
+
1027 } // ID Type Structure
1033 Construct the PPTT ACPI table.
1035 This function invokes the Configuration Manager protocol interface
1036 to get the required hardware information for generating the ACPI
1039 If this function allocates any resources then they must be freed
1040 in the FreeXXXXTableResources function.
1042 @param [in] This Pointer to the table generator.
1043 @param [in] AcpiTableInfo Pointer to the ACPI table generator to be used.
1044 @param [in] CfgMgrProtocol Pointer to the Configuration Manager
1046 @param [out] Table Pointer to the constructed ACPI Table.
1048 @retval EFI_SUCCESS Table generated successfully.
1049 @retval EFI_INVALID_PARAMETER A parameter is invalid.
1050 @retval EFI_NOT_FOUND The required object was not found.
1051 @retval EFI_BAD_BUFFER_SIZE The size returned by the Configuration
1052 Manager is less than the Object size for
1053 the requested object.
1059 IN CONST ACPI_TABLE_GENERATOR
* CONST This
,
1060 IN CONST CM_STD_OBJ_ACPI_TABLE_INFO
* CONST AcpiTableInfo
,
1061 IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL
* CONST CfgMgrProtocol
,
1062 OUT EFI_ACPI_DESCRIPTION_HEADER
** CONST Table
1067 UINT32 ProcTopologyStructCount
;
1069 UINT32 ProcHierarchyNodeOffset
;
1070 UINT32 CacheStructOffset
;
1071 UINT32 IdStructOffset
;
1073 CM_ARM_PROC_HIERARCHY_INFO
* ProcHierarchyNodeList
;
1074 CM_ARM_CACHE_INFO
* CacheStructList
;
1075 CM_ARM_PROC_NODE_ID_INFO
* IdStructList
;
1077 ACPI_PPTT_GENERATOR
* Generator
;
1079 // Pointer to the Node Indexer array
1080 PPTT_NODE_INDEXER
* NodeIndexer
;
1082 EFI_ACPI_6_3_PROCESSOR_PROPERTIES_TOPOLOGY_TABLE_HEADER
* Pptt
;
1086 (AcpiTableInfo
!= NULL
) &&
1087 (CfgMgrProtocol
!= NULL
) &&
1089 (AcpiTableInfo
->TableGeneratorId
== This
->GeneratorID
) &&
1090 (AcpiTableInfo
->AcpiTableSignature
== This
->AcpiTableSignature
)
1093 if ((AcpiTableInfo
->AcpiTableRevision
< This
->MinAcpiTableRevision
) ||
1094 (AcpiTableInfo
->AcpiTableRevision
> This
->AcpiTableRevision
)) {
1097 "ERROR: PPTT: Requested table revision = %d is not supported. "
1098 "Supported table revisions: Minimum = %d. Maximum = %d\n",
1099 AcpiTableInfo
->AcpiTableRevision
,
1100 This
->MinAcpiTableRevision
,
1101 This
->AcpiTableRevision
1103 return EFI_INVALID_PARAMETER
;
1106 Generator
= (ACPI_PPTT_GENERATOR
*)This
;
1109 // Get the processor hierarchy info and update the processor topology
1110 // structure count with Processor Hierarchy Nodes (Type 0)
1111 Status
= GetEArmObjProcHierarchyInfo (
1114 &ProcHierarchyNodeList
,
1115 &Generator
->ProcHierarchyNodeCount
1117 if (EFI_ERROR (Status
)) {
1120 "ERROR: PPTT: Failed to get processor hierarchy info. Status = %r\n",
1126 ProcTopologyStructCount
= Generator
->ProcHierarchyNodeCount
;
1128 // Get the cache info and update the processor topology structure count with
1129 // Cache Type Structures (Type 1)
1130 Status
= GetEArmObjCacheInfo (
1134 &Generator
->CacheStructCount
1136 if (EFI_ERROR (Status
) && (Status
!= EFI_NOT_FOUND
)) {
1139 "ERROR: PPTT: Failed to get cache info. Status = %r\n",
1145 ProcTopologyStructCount
+= Generator
->CacheStructCount
;
1147 // Get the processor hierarchy node ID info and update the processor topology
1148 // structure count with ID Structures (Type 2)
1149 Status
= GetEArmObjProcNodeIdInfo (
1153 &Generator
->IdStructCount
1155 if (EFI_ERROR (Status
) && (Status
!= EFI_NOT_FOUND
)) {
1158 "ERROR: PPTT: Failed to get processor hierarchy node ID info. " \
1165 ProcTopologyStructCount
+= Generator
->IdStructCount
;
1167 // Allocate Node Indexer array
1168 NodeIndexer
= (PPTT_NODE_INDEXER
*)AllocateZeroPool (
1169 sizeof (PPTT_NODE_INDEXER
) *
1170 ProcTopologyStructCount
1172 if (NodeIndexer
== NULL
) {
1173 Status
= EFI_OUT_OF_RESOURCES
;
1176 "ERROR: PPTT: Failed to allocate memory for Node Indexer. Status = %r\n ",
1182 DEBUG ((DEBUG_INFO
, "INFO: NodeIndexer = %p\n", NodeIndexer
));
1183 Generator
->ProcTopologyStructCount
= ProcTopologyStructCount
;
1184 Generator
->NodeIndexer
= NodeIndexer
;
1186 // Calculate the size of the PPTT table
1187 TableSize
= sizeof (EFI_ACPI_6_3_PROCESSOR_PROPERTIES_TOPOLOGY_TABLE_HEADER
);
1189 // Include the size of Processor Hierarchy Nodes and index them
1190 if (Generator
->ProcHierarchyNodeCount
!= 0) {
1191 ProcHierarchyNodeOffset
= TableSize
;
1192 Generator
->ProcHierarchyNodeIndexedList
= NodeIndexer
;
1193 TableSize
+= GetSizeofProcHierarchyNodes (
1194 ProcHierarchyNodeOffset
,
1195 ProcHierarchyNodeList
,
1196 Generator
->ProcHierarchyNodeCount
,
1201 // Include the size of Cache Type Structures and index them
1202 if (Generator
->CacheStructCount
!= 0) {
1203 CacheStructOffset
= TableSize
;
1204 Generator
->CacheStructIndexedList
= NodeIndexer
;
1205 TableSize
+= GetSizeofCacheTypeStructs (
1208 Generator
->CacheStructCount
,
1213 // Include the size of ID Type Structures and index them
1214 if (Generator
->IdStructCount
!= 0) {
1215 IdStructOffset
= TableSize
;
1216 Generator
->IdStructIndexedList
= NodeIndexer
;
1217 TableSize
+= GetSizeofIdStructs (
1220 Generator
->IdStructCount
,
1228 " ProcTopologyStructCount = %d\n" \
1229 " TableSize = %d\n",
1230 ProcTopologyStructCount
,
1236 " ProcHierarchyNodeCount = %d\n" \
1237 " ProcHierarchyNodeOffset = 0x%x\n" \
1238 " ProcHierarchyNodeIndexedList = 0x%p\n",
1239 Generator
->ProcHierarchyNodeCount
,
1240 ProcHierarchyNodeOffset
,
1241 Generator
->ProcHierarchyNodeIndexedList
1246 " CacheStructCount = %d\n" \
1247 " CacheStructOffset = 0x%x\n" \
1248 " CacheStructIndexedList = 0x%p\n",
1249 Generator
->CacheStructCount
,
1251 Generator
->CacheStructIndexedList
1256 " IdStructCount = %d\n" \
1257 " IdStructOffset = 0x%x\n" \
1258 " IdStructIndexedList = 0x%p\n",
1259 Generator
->IdStructCount
,
1261 Generator
->IdStructIndexedList
1264 // Allocate the Buffer for the PPTT table
1265 *Table
= (EFI_ACPI_DESCRIPTION_HEADER
*)AllocateZeroPool (TableSize
);
1266 if (*Table
== NULL
) {
1267 Status
= EFI_OUT_OF_RESOURCES
;
1270 "ERROR: PPTT: Failed to allocate memory for PPTT Table. " \
1271 "Size = %d. Status = %r\n",
1278 Pptt
= (EFI_ACPI_6_3_PROCESSOR_PROPERTIES_TOPOLOGY_TABLE_HEADER
*)*Table
;
1282 "PPTT: Pptt = 0x%p. TableSize = 0x%x\n",
1288 Status
= AddAcpiHeader (
1295 if (EFI_ERROR (Status
)) {
1298 "ERROR: PPTT: Failed to add ACPI header. Status = %r\n",
1304 // Add Processor Hierarchy Nodes (Type 0) to the generated table
1305 if (Generator
->ProcHierarchyNodeCount
!= 0) {
1306 Status
= AddProcHierarchyNodes (
1310 ProcHierarchyNodeOffset
1312 if (EFI_ERROR (Status
)) {
1315 "ERROR: PPTT: Failed to add Processor Hierarchy Nodes. Status = %r\n",
1322 // Add Cache Type Structures (Type 1) to the generated table
1323 if (Generator
->CacheStructCount
!= 0) {
1324 Status
= AddCacheTypeStructures (
1330 if (EFI_ERROR (Status
)) {
1333 "ERROR: PPTT: Failed to add Cache Type Structures. Status = %r\n",
1340 // Add ID Type Structures (Type 2) to the generated table
1341 if (Generator
->IdStructCount
!= 0) {
1342 Status
= AddIdTypeStructures (
1348 if (EFI_ERROR (Status
)) {
1351 "ERROR: PPTT: Failed to add ID Type Structures. Status = %r\n",
1358 // Validate CM object cross-references in PPTT
1359 Status
= DetectCyclesInTopology (Generator
);
1360 if (EFI_ERROR (Status
)) {
1363 "ERROR: PPTT: Invalid processor and cache topology. Status = %r\n",
1372 if (Generator
->NodeIndexer
!= NULL
) {
1373 FreePool (Generator
->NodeIndexer
);
1374 Generator
->NodeIndexer
= NULL
;
1377 if (*Table
!= NULL
) {
1386 Free any resources allocated for constructing the PPTT
1388 @param [in] This Pointer to the table generator.
1389 @param [in] AcpiTableInfo Pointer to the ACPI Table Info.
1390 @param [in] CfgMgrProtocol Pointer to the Configuration Manager
1392 @param [in, out] Table Pointer to the ACPI Table.
1394 @retval EFI_SUCCESS The resources were freed successfully.
1395 @retval EFI_INVALID_PARAMETER The table pointer is NULL or invalid.
1399 FreePpttTableResources (
1400 IN CONST ACPI_TABLE_GENERATOR
* CONST This
,
1401 IN CONST CM_STD_OBJ_ACPI_TABLE_INFO
* CONST AcpiTableInfo
,
1402 IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL
* CONST CfgMgrProtocol
,
1403 IN OUT EFI_ACPI_DESCRIPTION_HEADER
** CONST Table
1406 ACPI_PPTT_GENERATOR
* Generator
;
1410 (AcpiTableInfo
!= NULL
) &&
1411 (CfgMgrProtocol
!= NULL
) &&
1412 (AcpiTableInfo
->TableGeneratorId
== This
->GeneratorID
) &&
1413 (AcpiTableInfo
->AcpiTableSignature
== This
->AcpiTableSignature
)
1416 Generator
= (ACPI_PPTT_GENERATOR
*)This
;
1418 // Free any memory allocated by the generator
1419 if (Generator
->NodeIndexer
!= NULL
) {
1420 FreePool (Generator
->NodeIndexer
);
1421 Generator
->NodeIndexer
= NULL
;
1424 if ((Table
== NULL
) || (*Table
== NULL
)) {
1425 DEBUG ((DEBUG_ERROR
, "ERROR: PPTT: Invalid Table Pointer\n"));
1430 return EFI_INVALID_PARAMETER
;
1438 /** The PPTT Table Generator revision.
1440 #define PPTT_GENERATOR_REVISION CREATE_REVISION (1, 0)
1442 /** The interface for the PPTT Table Generator.
1445 ACPI_PPTT_GENERATOR PpttGenerator
= {
1446 // ACPI table generator header
1449 CREATE_STD_ACPI_TABLE_GEN_ID (EStdAcpiTableIdPptt
),
1450 // Generator Description
1451 L
"ACPI.STD.PPTT.GENERATOR",
1452 // ACPI Table Signature
1453 EFI_ACPI_6_3_PROCESSOR_PROPERTIES_TOPOLOGY_TABLE_STRUCTURE_SIGNATURE
,
1454 // ACPI Table Revision supported by this Generator
1455 EFI_ACPI_6_3_PROCESSOR_PROPERTIES_TOPOLOGY_TABLE_REVISION
,
1456 // Minimum supported ACPI Table Revision
1457 EFI_ACPI_6_3_PROCESSOR_PROPERTIES_TOPOLOGY_TABLE_REVISION
,
1459 TABLE_GENERATOR_CREATOR_ID_ARM
,
1461 PPTT_GENERATOR_REVISION
,
1462 // Build Table function
1464 // Free Resource function
1465 FreePpttTableResources
,
1466 // Extended build function not needed
1468 // Extended build function not implemented by the generator.
1469 // Hence extended free resource function is not required.
1473 // PPTT Generator private data
1475 // Processor topology node count
1477 // Pointer to PPTT Node Indexer
1482 Register the Generator with the ACPI Table Factory.
1484 @param [in] ImageHandle The handle to the image.
1485 @param [in] SystemTable Pointer to the System Table.
1487 @retval EFI_SUCCESS The Generator is registered.
1488 @retval EFI_INVALID_PARAMETER A parameter is invalid.
1489 @retval EFI_ALREADY_STARTED The Generator for the Table ID
1490 is already registered.
1494 AcpiPpttLibConstructor (
1495 IN EFI_HANDLE ImageHandle
,
1496 IN EFI_SYSTEM_TABLE
* SystemTable
1500 Status
= RegisterAcpiTableGenerator (&PpttGenerator
.Header
);
1501 DEBUG ((DEBUG_INFO
, "PPTT: Register Generator. Status = %r\n", Status
));
1502 ASSERT_EFI_ERROR (Status
);
1507 Deregister the Generator from the ACPI Table Factory.
1509 @param [in] ImageHandle The handle to the image.
1510 @param [in] SystemTable Pointer to the System Table.
1512 @retval EFI_SUCCESS The Generator is deregistered.
1513 @retval EFI_INVALID_PARAMETER A parameter is invalid.
1514 @retval EFI_NOT_FOUND The Generator is not registered.
1518 AcpiPpttLibDestructor (
1519 IN EFI_HANDLE ImageHandle
,
1520 IN EFI_SYSTEM_TABLE
* SystemTable
1524 Status
= DeregisterAcpiTableGenerator (&PpttGenerator
.Header
);
1525 DEBUG ((DEBUG_INFO
, "PPTT: Deregister Generator. Status = %r\n", Status
));
1526 ASSERT_EFI_ERROR (Status
);