]> git.proxmox.com Git - mirror_edk2.git/blob - DynamicTablesPkg/Library/Acpi/Arm/AcpiPpttLibArm/PpttGenerator.c
DynamicTablesPkg: Add dynamic PPTT table generation support
[mirror_edk2.git] / DynamicTablesPkg / Library / Acpi / Arm / AcpiPpttLibArm / PpttGenerator.c
1 /** @file
2 PPTT Table Generator
3
4 Copyright (c) 2019, ARM Limited. All rights reserved.
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 @par Reference(s):
8 - ACPI 6.3 Specification, January 2019
9
10 @par Glossary:
11 - Cm or CM - Configuration Manager
12 - Obj or OBJ - Object
13 **/
14
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>
20
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>
27
28 #include "PpttGenerator.h"
29
30 /**
31 ARM standard PPTT Generator
32
33 Requirements:
34 The following Configuration Manager Object(s) are used by this Generator:
35 - EArmObjProcHierarchyInfo (REQUIRED)
36 - EArmObjCacheInfo
37 - EArmObjProcNodeIdInfo
38 - EArmObjCmRef
39 - EArmObjGicCInfo (REQUIRED)
40 */
41
42 /**
43 This macro expands to a function that retrieves the Processor Hierarchy
44 information from the Configuration Manager.
45 */
46 GET_OBJECT_LIST (
47 EObjNameSpaceArm,
48 EArmObjProcHierarchyInfo,
49 CM_ARM_PROC_HIERARCHY_INFO
50 );
51
52 /**
53 This macro expands to a function that retrieves the cache information
54 from the Configuration Manager.
55 */
56 GET_OBJECT_LIST (
57 EObjNameSpaceArm,
58 EArmObjCacheInfo,
59 CM_ARM_CACHE_INFO
60 );
61
62 /**
63 This macro expands to a function that retrieves the ID information for
64 Processor Hierarchy Nodes from the Configuration Manager.
65 */
66 GET_OBJECT_LIST (
67 EObjNameSpaceArm,
68 EArmObjProcNodeIdInfo,
69 CM_ARM_PROC_NODE_ID_INFO
70 );
71
72 /**
73 This macro expands to a function that retrieves the cross-CM-object-
74 reference information from the Configuration Manager.
75 */
76 GET_OBJECT_LIST (
77 EObjNameSpaceArm,
78 EArmObjCmRef,
79 CM_ARM_OBJ_REF
80 );
81
82 /**
83 This macro expands to a function that retrieves the GIC CPU interface
84 information from the Configuration Manager.
85 */
86 GET_OBJECT_LIST (
87 EObjNameSpaceArm,
88 EArmObjGicCInfo,
89 CM_ARM_GICC_INFO
90 );
91
92 /**
93 Returns the size of the PPTT Processor Hierarchy Node (Type 0) given a
94 Processor Hierarchy Info CM object.
95
96 @param [in] Node Pointer to Processor Hierarchy Info CM object which
97 represents the Processor Hierarchy Node to be generated.
98
99 @retval Size of the Processor Hierarchy Node in bytes.
100 **/
101 STATIC
102 UINT32
103 GetProcHierarchyNodeSize (
104 IN CONST CM_ARM_PROC_HIERARCHY_INFO * Node
105 )
106 {
107 ASSERT (Node != NULL);
108
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));
112 }
113
114 /**
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.
117 */
118 GET_SIZE_OF_PPTT_STRUCTS (
119 ProcHierarchyNodes,
120 GetProcHierarchyNodeSize (NodesToIndex),
121 CM_ARM_PROC_HIERARCHY_INFO
122 );
123
124 /**
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.
127 */
128 GET_SIZE_OF_PPTT_STRUCTS (
129 CacheTypeStructs,
130 sizeof (EFI_ACPI_6_3_PPTT_STRUCTURE_CACHE),
131 CM_ARM_CACHE_INFO
132 );
133
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.
136 */
137 GET_SIZE_OF_PPTT_STRUCTS (
138 IdStructs,
139 sizeof (EFI_ACPI_6_3_PPTT_STRUCTURE_ID),
140 CM_ARM_PROC_NODE_ID_INFO
141 );
142
143 /**
144 Search the Node Indexer and return the indexed PPTT node with the given
145 Token.
146
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.
152
153 @retval EFI_SUCCESS Success.
154 @retval EFI_NOT_FOUND No element with a matching token was
155 found in the Node Indexer array.
156 **/
157 STATIC
158 EFI_STATUS
159 GetPpttNodeReferencedByToken (
160 IN PPTT_NODE_INDEXER * NodeIndexer,
161 IN UINT32 NodeCount,
162 IN CONST CM_OBJECT_TOKEN SearchToken,
163 OUT PPTT_NODE_INDEXER ** IndexedNodeFound
164 )
165 {
166 EFI_STATUS Status;
167
168 ASSERT (NodeIndexer != NULL);
169
170 DEBUG ((
171 DEBUG_INFO,
172 "PPTT: Node Indexer: SearchToken = %p\n",
173 SearchToken
174 ));
175
176 while (NodeCount-- != 0) {
177 DEBUG ((
178 DEBUG_INFO,
179 "PPTT: Node Indexer: NodeIndexer->Token = %p. Offset = %d\n",
180 NodeIndexer->Token,
181 NodeIndexer->Offset
182 ));
183
184 if (NodeIndexer->Token == SearchToken) {
185 *IndexedNodeFound = NodeIndexer;
186 Status = EFI_SUCCESS;
187 DEBUG ((
188 DEBUG_INFO,
189 "PPTT: Node Indexer: Token = %p. Found, Status = %r\n",
190 SearchToken,
191 Status
192 ));
193 return Status;
194 }
195 NodeIndexer++;
196 }
197
198 Status = EFI_NOT_FOUND;
199 DEBUG ((
200 DEBUG_ERROR,
201 "PPTT: Node Indexer: SearchToken = %p. Status = %r\n",
202 SearchToken,
203 Status
204 ));
205
206 return Status;
207 }
208
209 /**
210 Detect cycles in the processor and cache topology graph represented in
211 the PPTT table.
212
213 @param [in] Generator Pointer to the PPTT Generator.
214
215 @retval EFI_SUCCESS There are no cyclic references in the graph.
216 @retval EFI_INVALID_PARAMETER Processor or cache references form a cycle.
217 **/
218 STATIC
219 EFI_STATUS
220 DetectCyclesInTopology (
221 IN CONST ACPI_PPTT_GENERATOR * CONST Generator
222 )
223 {
224 EFI_STATUS Status;
225 PPTT_NODE_INDEXER * Iterator;
226 PPTT_NODE_INDEXER * CycleDetector;
227 UINT32 NodesRemaining;
228
229 ASSERT (Generator != NULL);
230
231 Iterator = Generator->NodeIndexer;
232 NodesRemaining = Generator->ProcTopologyStructCount;
233
234 while (NodesRemaining != 0) {
235 DEBUG ((
236 DEBUG_INFO,
237 "INFO: PPTT: Cycle detection for element with index %d\n",
238 Generator->ProcTopologyStructCount - NodesRemaining
239 ));
240
241 CycleDetector = Iterator;
242
243 // Walk the topology tree
244 while (CycleDetector->TopologyParent != NULL) {
245 DEBUG ((
246 DEBUG_INFO,
247 "INFO: PPTT: %p -> %p\n",
248 CycleDetector->Token,
249 CycleDetector->TopologyParent->Token
250 ));
251
252 // Check if we have already visited this node
253 if (CycleDetector->CycleDetectionStamp == NodesRemaining) {
254 Status = EFI_INVALID_PARAMETER;
255 DEBUG ((
256 DEBUG_ERROR,
257 "ERROR: PPTT: Cycle in processor and cache topology detected for " \
258 "a chain of references originating from a node with: Token = %p " \
259 "Status = %r\n",
260 Iterator->Token,
261 Status
262 ));
263 return Status;
264 }
265
266 // Stamp the visited node
267 CycleDetector->CycleDetectionStamp = NodesRemaining;
268 CycleDetector = CycleDetector->TopologyParent;
269 } // Continue topology tree walk
270
271 Iterator++;
272 NodesRemaining--;
273 } // Next Node Indexer
274
275 return EFI_SUCCESS;
276 }
277
278 /**
279 Update the array of private resources for a given Processor Hierarchy Node.
280
281 @param [in] Generator Pointer to the PPTT Generator.
282 @param [in] CfgMgrProtocol Pointer to the Configuration Manager
283 Protocol Interface.
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.
288
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.
292 **/
293 STATIC
294 EFI_STATUS
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
301 )
302 {
303 EFI_STATUS Status;
304 CM_ARM_OBJ_REF * CmObjRefs;
305 UINT32 CmObjRefCount;
306 PPTT_NODE_INDEXER * PpttNodeFound;
307
308 ASSERT (
309 (Generator != NULL) &&
310 (CfgMgrProtocol != NULL) &&
311 (PrivResArray != NULL) &&
312 (PrivResCount != 0)
313 );
314
315 // Validate input arguments
316 if (PrivResArrayToken == CM_NULL_TOKEN) {
317 Status = EFI_INVALID_PARAMETER;
318 DEBUG ((
319 DEBUG_ERROR,
320 "ERROR: PPTT: The number of private resources is %d while " \
321 "PrivResToken = CM_NULL_TOKEN. Status = %r\n",
322 PrivResCount,
323 Status
324 ));
325 return Status;
326 }
327
328 CmObjRefCount = 0;
329 // Get the CM Object References
330 Status = GetEArmObjCmRef (
331 CfgMgrProtocol,
332 PrivResArrayToken,
333 &CmObjRefs,
334 &CmObjRefCount
335 );
336 if (EFI_ERROR (Status)) {
337 DEBUG ((
338 DEBUG_ERROR,
339 "ERROR: PPTT: Failed to get CM Object References. " \
340 "PrivResToken = %p. Status = %r\n",
341 PrivResArrayToken,
342 Status
343 ));
344 return Status;
345 }
346
347 if (CmObjRefCount != PrivResCount) {
348 Status = EFI_INVALID_PARAMETER;
349 DEBUG ((
350 DEBUG_ERROR,
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",
354 CmObjRefCount,
355 PrivResCount,
356 PrivResArrayToken,
357 Status
358 ));
359 return Status;
360 }
361
362 while (PrivResCount-- != 0) {
363 if (CmObjRefs->ReferenceToken == CM_NULL_TOKEN) {
364 Status = EFI_INVALID_PARAMETER;
365 DEBUG ((
366 DEBUG_ERROR,
367 "ERROR: PPTT: CM_NULL_TOKEN provided as reference token for a " \
368 "private resource. Status = %r\n",
369 Status
370 ));
371 return Status;
372 }
373
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,
382 &PpttNodeFound
383 );
384 if (EFI_ERROR (Status)) {
385 DEBUG ((
386 DEBUG_ERROR,
387 "ERROR: PPTT: Failed to get a private resource with Token = %p from " \
388 "Node Indexer. Status = %r\n",
389 CmObjRefs->ReferenceToken,
390 Status
391 ));
392 return Status;
393 }
394
395 // Update the offset of the private resources in the Processor
396 // Hierarchy Node structure
397 *(PrivResArray++) = PpttNodeFound->Offset;
398 CmObjRefs++;
399 }
400
401 return EFI_SUCCESS;
402 }
403
404 /**
405 Function to test if two indexed Processor Hierarchy Info objects map to the
406 same GIC CPU Interface Info object.
407
408 This is a callback function that can be invoked by FindDuplicateValue ().
409
410 @param [in] Object1 Pointer to the first indexed Processor Hierarchy
411 Info object.
412 @param [in] Object2 Pointer to the second indexed Processor Hierarchy
413 Info object.
414 @param [in] Index1 Index of Object1 to be displayed for debugging
415 purposes.
416 @param [in] Index2 Index of Object2 to be displayed for debugging
417 purposes.
418
419 @retval TRUE Object1 and Object2 have the same GicCToken.
420 @retval FALSE Object1 and Object2 have different GicCTokens.
421 **/
422 BOOLEAN
423 EFIAPI
424 IsGicCTokenEqual (
425 IN CONST VOID * Object1,
426 IN CONST VOID * Object2,
427 IN UINTN Index1,
428 IN UINTN Index2
429 )
430 {
431 PPTT_NODE_INDEXER * IndexedObject1;
432 PPTT_NODE_INDEXER * IndexedObject2;
433 CM_ARM_PROC_HIERARCHY_INFO * ProcNode1;
434 CM_ARM_PROC_HIERARCHY_INFO * ProcNode2;
435
436 ASSERT (
437 (Object1 != NULL) &&
438 (Object2 != NULL)
439 );
440
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;
445
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)) {
451 DEBUG ((
452 DEBUG_ERROR,
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. " \
455 "GicCToken = %p.\n",
456 Index1,
457 IndexedObject1->Token,
458 Index2,
459 ProcNode1->GicCToken
460 ));
461 return TRUE;
462 }
463
464 return FALSE;
465 }
466
467 /**
468 Update the Processor Hierarchy Node (Type 0) information.
469
470 This function populates the Processor Hierarchy Nodes with information from
471 the Configuration Manager and adds this information to the PPTT table.
472
473 @param [in] Generator Pointer to the PPTT Generator.
474 @param [in] CfgMgrProtocol Pointer to the Configuration Manager
475 Protocol Interface.
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.
479
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.
483 **/
484 STATIC
485 EFI_STATUS
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
491 )
492 {
493 EFI_STATUS Status;
494 EFI_ACPI_6_3_PPTT_STRUCTURE_PROCESSOR * ProcStruct;
495 UINT32 * PrivateResources;
496 BOOLEAN IsGicCTokenDuplicated;
497
498 CM_ARM_GICC_INFO * GicCInfoList;
499 UINT32 GicCInfoCount;
500 UINT32 UniqueGicCRefCount;
501
502 PPTT_NODE_INDEXER * PpttNodeFound;
503 CM_ARM_PROC_HIERARCHY_INFO * ProcInfoNode;
504
505 PPTT_NODE_INDEXER * ProcNodeIterator;
506 UINT32 NodeCount;
507
508 ASSERT (
509 (Generator != NULL) &&
510 (CfgMgrProtocol != NULL) &&
511 (Pptt != NULL)
512 );
513
514 ProcStruct = (EFI_ACPI_6_3_PPTT_STRUCTURE_PROCESSOR*)((UINT8*)Pptt +
515 NodesStartOffset);
516
517 ProcNodeIterator = Generator->ProcHierarchyNodeIndexedList;
518 NodeCount = Generator->ProcHierarchyNodeCount;
519
520 // Check if every GICC Object is referenced by onlu one Proc Node
521 IsGicCTokenDuplicated = FindDuplicateValue (
522 ProcNodeIterator,
523 NodeCount,
524 sizeof (PPTT_NODE_INDEXER),
525 IsGicCTokenEqual
526 );
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;
531 }
532
533 UniqueGicCRefCount = 0;
534
535 while (NodeCount-- != 0) {
536 ProcInfoNode = (CM_ARM_PROC_HIERARCHY_INFO*)ProcNodeIterator->Object;
537
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;
545 DEBUG ((
546 DEBUG_ERROR,
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,
552 Status
553 ));
554 return Status;
555 }
556
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;
562
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;
571
572 // Populate the parent reference
573 if (ProcInfoNode->ParentToken == CM_NULL_TOKEN) {
574 ProcStruct->Parent = 0;
575 } else {
576 Status = GetPpttNodeReferencedByToken (
577 Generator->ProcHierarchyNodeIndexedList,
578 Generator->ProcHierarchyNodeCount,
579 ProcInfoNode->ParentToken,
580 &PpttNodeFound
581 );
582 if (EFI_ERROR (Status)) {
583 DEBUG ((
584 DEBUG_ERROR,
585 "ERROR: PPTT: Failed to get parent processor hierarchy node " \
586 "reference. Token = %p, Status = %r\n",
587 ProcInfoNode->ParentToken,
588 ProcInfoNode->Token,
589 Status
590 ));
591 return Status;
592 }
593
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;
598 DEBUG ((
599 DEBUG_ERROR,
600 "ERROR: PPTT: Reference to a leaf Processor Hierarchy Node. " \
601 "ParentToken = %p. ChildToken = %p. Status = %r\n",
602 ProcInfoNode->ParentToken,
603 ProcInfoNode->Token,
604 Status
605 ));
606 return Status;
607 }
608
609 // Update Proc Structure with the offset of the parent node
610 ProcStruct->Parent = PpttNodeFound->Offset;
611
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;
615 }
616
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;
623 DEBUG ((
624 DEBUG_ERROR,
625 "ERROR: PPTT: The 'ACPI Processor ID valid' flag is set but no GICC " \
626 "structure token was provided. GicCToken = %p. RequestorToken = %p. " \
627 "Status = %r\n",
628 ProcInfoNode->GicCToken,
629 ProcInfoNode->Token,
630 Status
631 ));
632 return Status;
633 } else {
634 Status = GetEArmObjGicCInfo (
635 CfgMgrProtocol,
636 ProcInfoNode->GicCToken,
637 &GicCInfoList,
638 &GicCInfoCount
639 );
640 if (EFI_ERROR (Status)) {
641 DEBUG ((
642 DEBUG_ERROR,
643 "ERROR: PPTT: Failed to get GICC structure. ACPI Processor ID " \
644 "can't be populated. GicCToken = %p. RequestorToken = %p. " \
645 "Status = %r\n",
646 ProcInfoNode->GicCToken,
647 ProcInfoNode->Token,
648 Status
649 ));
650 return Status;
651 }
652
653 if (GicCInfoCount != 1) {
654 Status = EFI_INVALID_PARAMETER;
655 DEBUG ((
656 DEBUG_ERROR,
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 " \
660 "Status = %r\n",
661 GicCInfoCount,
662 ProcInfoNode->GicCToken,
663 ProcInfoNode->Token,
664 Status
665 ));
666 return Status;
667 }
668
669 // Update the ACPI Processor Id
670 ProcStruct->AcpiProcessorId = GicCInfoList->AcpiProcessorUid;
671
672 // Increment the reference count for the number of
673 // Unique GICC objects that were retrieved.
674 UniqueGicCRefCount++;
675 }
676
677 ProcStruct->NumberOfPrivateResources = ProcInfoNode->NoOfPrivateResources;
678 PrivateResources = (UINT32*)((UINT8*)ProcStruct +
679 sizeof (EFI_ACPI_6_3_PPTT_STRUCTURE_PROCESSOR));
680
681 if (ProcStruct->NumberOfPrivateResources != 0) {
682 // Populate the private resources array
683 Status = AddPrivateResources (
684 Generator,
685 CfgMgrProtocol,
686 PrivateResources,
687 ProcStruct->NumberOfPrivateResources,
688 ProcInfoNode->PrivateResourcesArrayToken
689 );
690 if (EFI_ERROR (Status)) {
691 DEBUG ((
692 DEBUG_ERROR,
693 "ERROR: PPTT: Failed to populate the private resources array. " \
694 "Status = %r\n",
695 Status
696 ));
697 return Status;
698 }
699 }
700
701 // Next Processor Hierarchy Node
702 ProcStruct = (EFI_ACPI_6_3_PPTT_STRUCTURE_PROCESSOR*)((UINT8*)ProcStruct +
703 ProcStruct->Length);
704 ProcNodeIterator++;
705 } // Processor Hierarchy Node
706
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 (
710 CfgMgrProtocol,
711 CM_NULL_TOKEN,
712 &GicCInfoList,
713 &GicCInfoCount
714 );
715 if (EFI_ERROR (Status)) {
716 DEBUG ((
717 DEBUG_ERROR,
718 "ERROR: PPTT: Failed to get GICC Info. Status = %r\n",
719 Status
720 ));
721 return Status;
722 }
723
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;
732 DEBUG ((
733 DEBUG_ERROR,
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,
737 Status
738 ));
739 }
740
741 return Status;
742 }
743
744 /**
745 Update the Cache Type Structure (Type 1) information.
746
747 This function populates the Cache Type Structures with information from
748 the Configuration Manager and adds this information to the PPTT table.
749
750 @param [in] Generator Pointer to the PPTT Generator.
751 @param [in] CfgMgrProtocol Pointer to the Configuration Manager
752 Protocol Interface.
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.
756
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.
760 **/
761 STATIC
762 EFI_STATUS
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
768 )
769 {
770 EFI_STATUS Status;
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;
775 UINT32 NodeCount;
776
777 ASSERT (
778 (Generator != NULL) &&
779 (CfgMgrProtocol != NULL) &&
780 (Pptt != NULL)
781 );
782
783 CacheStruct = (EFI_ACPI_6_3_PPTT_STRUCTURE_CACHE*)((UINT8*)Pptt +
784 NodesStartOffset);
785
786 CacheNodeIterator = Generator->CacheStructIndexedList;
787 NodeCount = Generator->CacheStructCount;
788
789 while (NodeCount-- != 0) {
790 CacheInfoNode = (CM_ARM_CACHE_INFO*)CacheNodeIterator->Object;
791
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;
797
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;
808
809 // Populate the reference to the next level of cache
810 if (CacheInfoNode->NextLevelOfCacheToken == CM_NULL_TOKEN) {
811 CacheStruct->NextLevelOfCache = 0;
812 } else {
813 Status = GetPpttNodeReferencedByToken (
814 Generator->CacheStructIndexedList,
815 Generator->CacheStructCount,
816 CacheInfoNode->NextLevelOfCacheToken,
817 &PpttNodeFound
818 );
819 if (EFI_ERROR (Status)) {
820 DEBUG ((
821 DEBUG_ERROR,
822 "ERROR: PPTT: Failed to get the reference to the Next Level of " \
823 "Cache. NextLevelOfCacheToken = %p. RequestorToken = %p. " \
824 "Status = %r\n",
825 CacheInfoNode->NextLevelOfCacheToken,
826 CacheInfoNode->Token,
827 Status
828 ));
829 return Status;
830 }
831
832 // Update Cache Structure with the offset for the next level of cache
833 CacheStruct->NextLevelOfCache = PpttNodeFound->Offset;
834
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;
838 }
839
840 CacheStruct->Size = CacheInfoNode->Size;
841
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;
845 DEBUG ((
846 DEBUG_ERROR,
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,
851 Status
852 ));
853 return Status;
854 }
855
856 if (CacheInfoNode->NumberOfSets > PPTT_ARM_CACHE_NUMBER_OF_SETS_MAX) {
857 DEBUG ((
858 DEBUG_INFO,
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
863 ));
864 }
865
866 CacheStruct->NumberOfSets = CacheInfoNode->NumberOfSets;
867
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;
872 DEBUG ((
873 DEBUG_ERROR,
874 "ERROR: PPTT: The maximum associativity supported by ACPI " \
875 "Cache type structure is %d. Associativity = %d, Status = %r\n",
876 MAX_UINT8,
877 CacheInfoNode->Associativity,
878 Status
879 ));
880 return Status;
881 }
882
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.
888 #if 0
889 if (CacheInfoNode->Associativity > PPTT_ARM_CCIDX_CACHE_ASSOCIATIVITY_MAX) {
890 Status = EFI_INVALID_PARAMETER;
891 DEBUG ((
892 DEBUG_ERROR,
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,
897 Status
898 ));
899 return Status;
900 }
901
902 if (CacheInfoNode->Associativity > PPTT_ARM_CACHE_ASSOCIATIVITY_MAX) {
903 DEBUG ((
904 DEBUG_INFO,
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
909 ));
910 }
911 #endif
912
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;
916
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;
925
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)) {
929
930 Status = EFI_INVALID_PARAMETER;
931 DEBUG ((
932 DEBUG_ERROR,
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,
938 Status
939 ));
940 return Status;
941 }
942
943 if ((CacheInfoNode->LineSize & (CacheInfoNode->LineSize - 1)) != 0) {
944 Status = EFI_INVALID_PARAMETER;
945 DEBUG ((
946 DEBUG_ERROR,
947 "ERROR: PPTT: The cache line size is not a power of 2. " \
948 "LineSize = %d. Status = %r\n" ,
949 CacheInfoNode->LineSize,
950 Status
951 ));
952 return Status;
953 }
954
955 CacheStruct->LineSize = CacheInfoNode->LineSize;
956
957 // Next Cache Type Structure
958 CacheStruct = (EFI_ACPI_6_3_PPTT_STRUCTURE_CACHE*)((UINT8*)CacheStruct +
959 CacheStruct->Length);
960 CacheNodeIterator++;
961 } // Cache Type Structure
962
963 return EFI_SUCCESS;
964 }
965
966 /**
967 Update the ID Type Structure (Type 2) information.
968
969 This function populates the ID Type Structures with information from
970 the Configuration Manager and and adds this information to the PPTT table.
971
972 @param [in] Generator Pointer to the PPTT Generator.
973 @param [in] CfgMgrProtocol Pointer to the Configuration Manager
974 Protocol Interface.
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.
978
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.
982 **/
983 STATIC
984 EFI_STATUS
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
990 )
991 {
992 EFI_ACPI_6_3_PPTT_STRUCTURE_ID * IdStruct;
993 CM_ARM_PROC_NODE_ID_INFO * ProcIdInfoNode;
994 PPTT_NODE_INDEXER * IdStructIterator;
995 UINT32 NodeCount;
996
997
998 ASSERT (
999 (Generator != NULL) &&
1000 (CfgMgrProtocol != NULL) &&
1001 (Pptt != NULL)
1002 );
1003
1004 IdStruct = (EFI_ACPI_6_3_PPTT_STRUCTURE_ID*)((UINT8*)Pptt + NodesStartOffset);
1005
1006 IdStructIterator = Generator->IdStructIndexedList;
1007 NodeCount = Generator->IdStructCount;
1008 while (NodeCount-- != 0) {
1009 ProcIdInfoNode = (CM_ARM_PROC_NODE_ID_INFO*)IdStructIterator->Object;
1010
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;
1022
1023 // Next ID Type Structure
1024 IdStruct = (EFI_ACPI_6_3_PPTT_STRUCTURE_ID*)((UINT8*)IdStruct +
1025 IdStruct->Length);
1026 IdStructIterator++;
1027 } // ID Type Structure
1028
1029 return EFI_SUCCESS;
1030 }
1031
1032 /**
1033 Construct the PPTT ACPI table.
1034
1035 This function invokes the Configuration Manager protocol interface
1036 to get the required hardware information for generating the ACPI
1037 table.
1038
1039 If this function allocates any resources then they must be freed
1040 in the FreeXXXXTableResources function.
1041
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
1045 Protocol Interface.
1046 @param [out] Table Pointer to the constructed ACPI Table.
1047
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.
1054 **/
1055 STATIC
1056 EFI_STATUS
1057 EFIAPI
1058 BuildPpttTable (
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
1063 )
1064 {
1065 EFI_STATUS Status;
1066 UINT32 TableSize;
1067 UINT32 ProcTopologyStructCount;
1068
1069 UINT32 ProcHierarchyNodeOffset;
1070 UINT32 CacheStructOffset;
1071 UINT32 IdStructOffset;
1072
1073 CM_ARM_PROC_HIERARCHY_INFO * ProcHierarchyNodeList;
1074 CM_ARM_CACHE_INFO * CacheStructList;
1075 CM_ARM_PROC_NODE_ID_INFO * IdStructList;
1076
1077 ACPI_PPTT_GENERATOR * Generator;
1078
1079 // Pointer to the Node Indexer array
1080 PPTT_NODE_INDEXER * NodeIndexer;
1081
1082 EFI_ACPI_6_3_PROCESSOR_PROPERTIES_TOPOLOGY_TABLE_HEADER * Pptt;
1083
1084 ASSERT (
1085 (This != NULL) &&
1086 (AcpiTableInfo != NULL) &&
1087 (CfgMgrProtocol != NULL) &&
1088 (Table != NULL) &&
1089 (AcpiTableInfo->TableGeneratorId == This->GeneratorID) &&
1090 (AcpiTableInfo->AcpiTableSignature == This->AcpiTableSignature)
1091 );
1092
1093 if ((AcpiTableInfo->AcpiTableRevision < This->MinAcpiTableRevision) ||
1094 (AcpiTableInfo->AcpiTableRevision > This->AcpiTableRevision)) {
1095 DEBUG ((
1096 DEBUG_ERROR,
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
1102 ));
1103 return EFI_INVALID_PARAMETER;
1104 }
1105
1106 Generator = (ACPI_PPTT_GENERATOR*)This;
1107 *Table = NULL;
1108
1109 // Get the processor hierarchy info and update the processor topology
1110 // structure count with Processor Hierarchy Nodes (Type 0)
1111 Status = GetEArmObjProcHierarchyInfo (
1112 CfgMgrProtocol,
1113 CM_NULL_TOKEN,
1114 &ProcHierarchyNodeList,
1115 &Generator->ProcHierarchyNodeCount
1116 );
1117 if (EFI_ERROR (Status)) {
1118 DEBUG ((
1119 DEBUG_ERROR,
1120 "ERROR: PPTT: Failed to get processor hierarchy info. Status = %r\n",
1121 Status
1122 ));
1123 goto error_handler;
1124 }
1125
1126 ProcTopologyStructCount = Generator->ProcHierarchyNodeCount;
1127
1128 // Get the cache info and update the processor topology structure count with
1129 // Cache Type Structures (Type 1)
1130 Status = GetEArmObjCacheInfo (
1131 CfgMgrProtocol,
1132 CM_NULL_TOKEN,
1133 &CacheStructList,
1134 &Generator->CacheStructCount
1135 );
1136 if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) {
1137 DEBUG ((
1138 DEBUG_ERROR,
1139 "ERROR: PPTT: Failed to get cache info. Status = %r\n",
1140 Status
1141 ));
1142 goto error_handler;
1143 }
1144
1145 ProcTopologyStructCount += Generator->CacheStructCount;
1146
1147 // Get the processor hierarchy node ID info and update the processor topology
1148 // structure count with ID Structures (Type 2)
1149 Status = GetEArmObjProcNodeIdInfo (
1150 CfgMgrProtocol,
1151 CM_NULL_TOKEN,
1152 &IdStructList,
1153 &Generator->IdStructCount
1154 );
1155 if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) {
1156 DEBUG ((
1157 DEBUG_ERROR,
1158 "ERROR: PPTT: Failed to get processor hierarchy node ID info. " \
1159 "Status = %r\n",
1160 Status
1161 ));
1162 goto error_handler;
1163 }
1164
1165 ProcTopologyStructCount += Generator->IdStructCount;
1166
1167 // Allocate Node Indexer array
1168 NodeIndexer = (PPTT_NODE_INDEXER*)AllocateZeroPool (
1169 sizeof (PPTT_NODE_INDEXER) *
1170 ProcTopologyStructCount
1171 );
1172 if (NodeIndexer == NULL) {
1173 Status = EFI_OUT_OF_RESOURCES;
1174 DEBUG ((
1175 DEBUG_ERROR,
1176 "ERROR: PPTT: Failed to allocate memory for Node Indexer. Status = %r\n ",
1177 Status
1178 ));
1179 goto error_handler;
1180 }
1181
1182 DEBUG ((DEBUG_INFO, "INFO: NodeIndexer = %p\n", NodeIndexer));
1183 Generator->ProcTopologyStructCount = ProcTopologyStructCount;
1184 Generator->NodeIndexer = NodeIndexer;
1185
1186 // Calculate the size of the PPTT table
1187 TableSize = sizeof (EFI_ACPI_6_3_PROCESSOR_PROPERTIES_TOPOLOGY_TABLE_HEADER);
1188
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,
1197 &NodeIndexer
1198 );
1199 }
1200
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 (
1206 CacheStructOffset,
1207 CacheStructList,
1208 Generator->CacheStructCount,
1209 &NodeIndexer
1210 );
1211 }
1212
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 (
1218 IdStructOffset,
1219 IdStructList,
1220 Generator->IdStructCount,
1221 &NodeIndexer
1222 );
1223 }
1224
1225 DEBUG ((
1226 DEBUG_INFO,
1227 "INFO: PPTT:\n" \
1228 " ProcTopologyStructCount = %d\n" \
1229 " TableSize = %d\n",
1230 ProcTopologyStructCount,
1231 TableSize
1232 ));
1233
1234 DEBUG ((
1235 DEBUG_INFO,
1236 " ProcHierarchyNodeCount = %d\n" \
1237 " ProcHierarchyNodeOffset = 0x%x\n" \
1238 " ProcHierarchyNodeIndexedList = 0x%p\n",
1239 Generator->ProcHierarchyNodeCount,
1240 ProcHierarchyNodeOffset,
1241 Generator->ProcHierarchyNodeIndexedList
1242 ));
1243
1244 DEBUG ((
1245 DEBUG_INFO,
1246 " CacheStructCount = %d\n" \
1247 " CacheStructOffset = 0x%x\n" \
1248 " CacheStructIndexedList = 0x%p\n",
1249 Generator->CacheStructCount,
1250 CacheStructOffset,
1251 Generator->CacheStructIndexedList
1252 ));
1253
1254 DEBUG ((
1255 DEBUG_INFO,
1256 " IdStructCount = %d\n" \
1257 " IdStructOffset = 0x%x\n" \
1258 " IdStructIndexedList = 0x%p\n",
1259 Generator->IdStructCount,
1260 IdStructOffset,
1261 Generator->IdStructIndexedList
1262 ));
1263
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;
1268 DEBUG ((
1269 DEBUG_ERROR,
1270 "ERROR: PPTT: Failed to allocate memory for PPTT Table. " \
1271 "Size = %d. Status = %r\n",
1272 TableSize,
1273 Status
1274 ));
1275 goto error_handler;
1276 }
1277
1278 Pptt = (EFI_ACPI_6_3_PROCESSOR_PROPERTIES_TOPOLOGY_TABLE_HEADER*)*Table;
1279
1280 DEBUG ((
1281 DEBUG_INFO,
1282 "PPTT: Pptt = 0x%p. TableSize = 0x%x\n",
1283 Pptt,
1284 TableSize
1285 ));
1286
1287 // Add ACPI header
1288 Status = AddAcpiHeader (
1289 CfgMgrProtocol,
1290 This,
1291 &Pptt->Header,
1292 AcpiTableInfo,
1293 TableSize
1294 );
1295 if (EFI_ERROR (Status)) {
1296 DEBUG ((
1297 DEBUG_ERROR,
1298 "ERROR: PPTT: Failed to add ACPI header. Status = %r\n",
1299 Status
1300 ));
1301 goto error_handler;
1302 }
1303
1304 // Add Processor Hierarchy Nodes (Type 0) to the generated table
1305 if (Generator->ProcHierarchyNodeCount != 0) {
1306 Status = AddProcHierarchyNodes (
1307 Generator,
1308 CfgMgrProtocol,
1309 Pptt,
1310 ProcHierarchyNodeOffset
1311 );
1312 if (EFI_ERROR (Status)) {
1313 DEBUG ((
1314 DEBUG_ERROR,
1315 "ERROR: PPTT: Failed to add Processor Hierarchy Nodes. Status = %r\n",
1316 Status
1317 ));
1318 goto error_handler;
1319 }
1320 }
1321
1322 // Add Cache Type Structures (Type 1) to the generated table
1323 if (Generator->CacheStructCount != 0) {
1324 Status = AddCacheTypeStructures (
1325 Generator,
1326 CfgMgrProtocol,
1327 Pptt,
1328 CacheStructOffset
1329 );
1330 if (EFI_ERROR (Status)) {
1331 DEBUG ((
1332 DEBUG_ERROR,
1333 "ERROR: PPTT: Failed to add Cache Type Structures. Status = %r\n",
1334 Status
1335 ));
1336 goto error_handler;
1337 }
1338 }
1339
1340 // Add ID Type Structures (Type 2) to the generated table
1341 if (Generator->IdStructCount != 0) {
1342 Status = AddIdTypeStructures (
1343 Generator,
1344 CfgMgrProtocol,
1345 Pptt,
1346 IdStructOffset
1347 );
1348 if (EFI_ERROR (Status)) {
1349 DEBUG ((
1350 DEBUG_ERROR,
1351 "ERROR: PPTT: Failed to add ID Type Structures. Status = %r\n",
1352 Status
1353 ));
1354 goto error_handler;
1355 }
1356 }
1357
1358 // Validate CM object cross-references in PPTT
1359 Status = DetectCyclesInTopology (Generator);
1360 if (EFI_ERROR (Status)) {
1361 DEBUG ((
1362 DEBUG_ERROR,
1363 "ERROR: PPTT: Invalid processor and cache topology. Status = %r\n",
1364 Status
1365 ));
1366 goto error_handler;
1367 }
1368
1369 return Status;
1370
1371 error_handler:
1372 if (Generator->NodeIndexer != NULL) {
1373 FreePool (Generator->NodeIndexer);
1374 Generator->NodeIndexer = NULL;
1375 }
1376
1377 if (*Table != NULL) {
1378 FreePool (*Table);
1379 *Table = NULL;
1380 }
1381
1382 return Status;
1383 }
1384
1385 /**
1386 Free any resources allocated for constructing the PPTT
1387
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
1391 Protocol Interface.
1392 @param [in, out] Table Pointer to the ACPI Table.
1393
1394 @retval EFI_SUCCESS The resources were freed successfully.
1395 @retval EFI_INVALID_PARAMETER The table pointer is NULL or invalid.
1396 **/
1397 STATIC
1398 EFI_STATUS
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
1404 )
1405 {
1406 ACPI_PPTT_GENERATOR * Generator;
1407
1408 ASSERT (
1409 (This != NULL) &&
1410 (AcpiTableInfo != NULL) &&
1411 (CfgMgrProtocol != NULL) &&
1412 (AcpiTableInfo->TableGeneratorId == This->GeneratorID) &&
1413 (AcpiTableInfo->AcpiTableSignature == This->AcpiTableSignature)
1414 );
1415
1416 Generator = (ACPI_PPTT_GENERATOR*)This;
1417
1418 // Free any memory allocated by the generator
1419 if (Generator->NodeIndexer != NULL) {
1420 FreePool (Generator->NodeIndexer);
1421 Generator->NodeIndexer = NULL;
1422 }
1423
1424 if ((Table == NULL) || (*Table == NULL)) {
1425 DEBUG ((DEBUG_ERROR, "ERROR: PPTT: Invalid Table Pointer\n"));
1426 ASSERT (
1427 (Table != NULL) &&
1428 (*Table != NULL)
1429 );
1430 return EFI_INVALID_PARAMETER;
1431 }
1432
1433 FreePool (*Table);
1434 *Table = NULL;
1435 return EFI_SUCCESS;
1436 }
1437
1438 /** The PPTT Table Generator revision.
1439 */
1440 #define PPTT_GENERATOR_REVISION CREATE_REVISION (1, 0)
1441
1442 /** The interface for the PPTT Table Generator.
1443 */
1444 STATIC
1445 ACPI_PPTT_GENERATOR PpttGenerator = {
1446 // ACPI table generator header
1447 {
1448 // Generator ID
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,
1458 // Creator ID
1459 TABLE_GENERATOR_CREATOR_ID_ARM,
1460 // Creator Revision
1461 PPTT_GENERATOR_REVISION,
1462 // Build Table function
1463 BuildPpttTable,
1464 // Free Resource function
1465 FreePpttTableResources,
1466 // Extended build function not needed
1467 NULL,
1468 // Extended build function not implemented by the generator.
1469 // Hence extended free resource function is not required.
1470 NULL
1471 },
1472
1473 // PPTT Generator private data
1474
1475 // Processor topology node count
1476 0,
1477 // Pointer to PPTT Node Indexer
1478 NULL
1479 };
1480
1481 /**
1482 Register the Generator with the ACPI Table Factory.
1483
1484 @param [in] ImageHandle The handle to the image.
1485 @param [in] SystemTable Pointer to the System Table.
1486
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.
1491 **/
1492 EFI_STATUS
1493 EFIAPI
1494 AcpiPpttLibConstructor (
1495 IN CONST EFI_HANDLE ImageHandle,
1496 IN EFI_SYSTEM_TABLE * CONST SystemTable
1497 )
1498 {
1499 EFI_STATUS Status;
1500 Status = RegisterAcpiTableGenerator (&PpttGenerator.Header);
1501 DEBUG ((DEBUG_INFO, "PPTT: Register Generator. Status = %r\n", Status));
1502 ASSERT_EFI_ERROR (Status);
1503 return Status;
1504 }
1505
1506 /**
1507 Deregister the Generator from the ACPI Table Factory.
1508
1509 @param [in] ImageHandle The handle to the image.
1510 @param [in] SystemTable Pointer to the System Table.
1511
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.
1515 **/
1516 EFI_STATUS
1517 EFIAPI
1518 AcpiPpttLibDestructor (
1519 IN CONST EFI_HANDLE ImageHandle,
1520 IN EFI_SYSTEM_TABLE * CONST SystemTable
1521 )
1522 {
1523 EFI_STATUS Status;
1524 Status = DeregisterAcpiTableGenerator (&PpttGenerator.Header);
1525 DEBUG ((DEBUG_INFO, "PPTT: Deregister Generator. Status = %r\n", Status));
1526 ASSERT_EFI_ERROR (Status);
1527 return Status;
1528 }