summaryrefslogtreecommitdiffstats
path: root/DynamicTablesPkg/Library/Acpi/Arm/AcpiPcctLibArm/PcctGenerator.c
blob: 183d8cd221bbda85f38be019b1bfb3e7de0be6e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
/** @file
  PCCT Table Generator

  Copyright (c) 2022, Arm Limited. All rights reserved.<BR>
  SPDX-License-Identifier: BSD-2-Clause-Patent

  @par Reference(s):
  - ACPI 6.4 Specification - January 2021
    s14 PLATFORM COMMUNICATIONS CHANNEL (PCC)

**/

#include <Library/AcpiLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Protocol/AcpiTable.h>

// Module specific include files.
#include <AcpiTableGenerator.h>
#include <ConfigurationManagerObject.h>
#include <ConfigurationManagerHelper.h>
#include <Library/TableHelperLib.h>
#include <Protocol/ConfigurationManagerProtocol.h>
#include "PcctGenerator.h"

/** ARM standard PCCT Generator

Requirements:
  The following Configuration Manager Object(s) are required by
  this Generator:
  - EArchCommonObjPccSubspaceType0Info
  - EArchCommonObjPccSubspaceType1Info
  - EArmObjPccSubspaceType2Info
  - EArmObjPccSubspaceType3Info
  - EArmObjPccSubspaceType4Info
  - EArmObjPccSubspaceType5Info
*/

/** This macro expands to a function that retrieves the PCC
    Subspace of Type 0 Information from the Configuration Manager.
*/
GET_OBJECT_LIST (
  EObjNameSpaceArchCommon,
  EArchCommonObjPccSubspaceType0Info,
  CM_ARCH_COMMON_PCC_SUBSPACE_TYPE0_INFO
  );

/** This macro expands to a function that retrieves the PCC
    Subspace of Type 1 Information from the Configuration Manager.
*/
GET_OBJECT_LIST (
  EObjNameSpaceArchCommon,
  EArchCommonObjPccSubspaceType1Info,
  CM_ARCH_COMMON_PCC_SUBSPACE_TYPE1_INFO
  );

/** This macro expands to a function that retrieves the PCC
    Subspace of Type 2 Information from the Configuration Manager.
*/
GET_OBJECT_LIST (
  EObjNameSpaceArm,
  EArmObjPccSubspaceType2Info,
  CM_ARM_PCC_SUBSPACE_TYPE2_INFO
  );

/** This macro expands to a function that retrieves the PCC
    Subspace of Type 3 Information from the Configuration Manager.
*/
GET_OBJECT_LIST (
  EObjNameSpaceArm,
  EArmObjPccSubspaceType3Info,
  CM_ARM_PCC_SUBSPACE_TYPE3_INFO
  );

/** This macro expands to a function that retrieves the PCC
    Subspace of Type 4 Information from the Configuration Manager.
*/
GET_OBJECT_LIST (
  EObjNameSpaceArm,
  EArmObjPccSubspaceType4Info,
  CM_ARM_PCC_SUBSPACE_TYPE4_INFO
  );

/** This macro expands to a function that retrieves the PCC
    Subspace of Type 5 Information from the Configuration Manager.
*/
GET_OBJECT_LIST (
  EObjNameSpaceArm,
  EArmObjPccSubspaceType5Info,
  CM_ARM_PCC_SUBSPACE_TYPE5_INFO
  );

/** The Platform is capable of generating an interrupt
    to indicate completion of a command.

  Cf: s14.1.1 Platform Communications Channel Global Flags
  Platform Interrupt flag
  and s14.1.6 Extended PCC subspaces (types 3 and 4)
    If a responder subspace is included in the PCCT,
    then the global Platform Interrupt flag must be set to 1

  Set this variable and populate the PCCT flag accordingly if either:
   - One of the PCCT Subspace uses interrupts.
   - A PCC Subspace of type 4 is used.
*/
STATIC BOOLEAN  mHasPlatformInterrupt;

/** Initialize the MappingTable.

  @param [in] MappingTable  The mapping table structure.
  @param [in] Count         Number of entries to allocate in the
                            MappingTable.

  @retval EFI_SUCCESS            Success.
  @retval EFI_INVALID_PARAMETER  Invalid parameter.
  @retval EFI_OUT_OF_RESOURCES   Failed to allocate memory.
**/
STATIC
EFI_STATUS
EFIAPI
MappingTableInitialize (
  IN  MAPPING_TABLE  *MappingTable,
  IN  UINT32         Count
  )
{
  VOID  **Table;

  if ((MappingTable == NULL)  ||
      (Count == 0))
  {
    ASSERT (0);
    return EFI_INVALID_PARAMETER;
  }

  Table = AllocateZeroPool (sizeof (*Table) * Count);
  if (Table == NULL) {
    ASSERT (0);
    return EFI_OUT_OF_RESOURCES;
  }

  MappingTable->Table    = Table;
  MappingTable->MaxIndex = Count;

  return EFI_SUCCESS;
}

/** Free the MappingTable.

  @param [in, out]  MappingTable  The mapping table structure.
**/
STATIC
VOID
EFIAPI
MappingTableFree (
  IN  OUT MAPPING_TABLE  *MappingTable
  )
{
  ASSERT (MappingTable != NULL);
  ASSERT (MappingTable->Table != NULL);

  if (MappingTable->Table != NULL) {
    FreePool (MappingTable->Table);
  }
}

/** Add a new entry for PccSubspace at Index.

  @param [in] MappingTable      The mapping table structure.
  @param [in] PccSubspace       A pointer to
                                CM_[ARM|ARCH_COMMON]_PCC_SUBSPACE_TYPE[X]_INFO.
  @param [in] Index             Index at which PccSubspace must be added.
                                This is the Subspace Id.

  @retval EFI_SUCCESS            Success.
  @retval EFI_BUFFER_TOO_SMALL   Buffer too small.
  @retval EFI_INVALID_PARAMETER  Invalid parameter.
**/
STATIC
EFI_STATUS
EFIAPI
MappingTableAdd (
  IN  MAPPING_TABLE  *MappingTable,
  IN  VOID           *PccSubspace,
  IN  UINT32         Index
  )
{
  if ((MappingTable == NULL)        ||
      (MappingTable->Table == NULL) ||
      (PccSubspace == NULL))
  {
    ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER);
    return EFI_INVALID_PARAMETER;
  }

  if ((Index >= MappingTable->MaxIndex) ||
      (MappingTable->Table[Index] != 0))
  {
    ASSERT_EFI_ERROR (EFI_BUFFER_TOO_SMALL);
    return EFI_BUFFER_TOO_SMALL;
  }

  // Just map the Pcc Subspace in the Table.
  MappingTable->Table[Index] = PccSubspace;
  return EFI_SUCCESS;
}

/** Parse the CmPccArray objects and add them to the MappingTable.

  @param [in] MappingTable     The mapping table structure.
  @param [in] CmPccArray       Pointer to an array of
                               CM_[ARM|ARCH_COMMON]_PCC_SUBSPACE_TYPE[X]_INFO.
  @param [in] CmPccCount       Count of objects in CmPccArray.

  @retval EFI_SUCCESS            Success.
  @retval EFI_BUFFER_TOO_SMALL   Buffer too small.
  @retval EFI_INVALID_PARAMETER  Invalid parameter.
**/
STATIC
EFI_STATUS
EFIAPI
MapPccSubspaceId (
  IN  MAPPING_TABLE  *MappingTable,
  IN  VOID           *CmPccArray,
  IN  UINT32         CmPccCount
  )
{
  EFI_STATUS                 Status;
  UINT8                      *PccBuffer;
  UINT32                     Index;
  UINT32                     CmObjSize;
  PCC_SUBSPACE_GENERIC_INFO  *GenericPcc;

  if (CmPccCount == 0) {
    return EFI_SUCCESS;
  }

  if ((CmPccArray == NULL) || (MappingTable == NULL)) {
    ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER);
    return EFI_INVALID_PARAMETER;
  }

  GenericPcc = (PCC_SUBSPACE_GENERIC_INFO *)CmPccArray;

  switch (GenericPcc->Type) {
    case EFI_ACPI_6_4_PCCT_SUBSPACE_TYPE_GENERIC:
      CmObjSize = sizeof (CM_ARCH_COMMON_PCC_SUBSPACE_TYPE0_INFO);
      break;

    case EFI_ACPI_6_4_PCCT_SUBSPACE_TYPE_1_HW_REDUCED_COMMUNICATIONS:
      CmObjSize = sizeof (CM_ARCH_COMMON_PCC_SUBSPACE_TYPE1_INFO);
      break;

    case EFI_ACPI_6_4_PCCT_SUBSPACE_TYPE_2_HW_REDUCED_COMMUNICATIONS:
      CmObjSize = sizeof (CM_ARM_PCC_SUBSPACE_TYPE2_INFO);
      break;

    case EFI_ACPI_6_4_PCCT_SUBSPACE_TYPE_3_EXTENDED_PCC:
      CmObjSize = sizeof (CM_ARM_PCC_SUBSPACE_TYPE3_INFO);
      break;

    case EFI_ACPI_6_4_PCCT_SUBSPACE_TYPE_4_EXTENDED_PCC:
      CmObjSize = sizeof (CM_ARM_PCC_SUBSPACE_TYPE4_INFO);
      break;

    case EFI_ACPI_6_4_PCCT_SUBSPACE_TYPE_5_HW_REGISTERS_COMMUNICATIONS:
      CmObjSize = sizeof (CM_ARM_PCC_SUBSPACE_TYPE5_INFO);
      break;

    default:
      ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER);
      return EFI_INVALID_PARAMETER;
  }

  PccBuffer = (UINT8 *)CmPccArray;

  // Map the Pcc channel to their Subspace Id.
  for (Index = 0; Index < CmPccCount; Index++) {
    GenericPcc = (PCC_SUBSPACE_GENERIC_INFO *)PccBuffer;

    Status = MappingTableAdd (
               MappingTable,
               PccBuffer,
               GenericPcc->SubspaceId
               );
    if (EFI_ERROR (Status)) {
      ASSERT_EFI_ERROR (Status);
      return Status;
    }

    PccBuffer += CmObjSize;
  }

  return EFI_SUCCESS;
}

/** Add one PCCT Subspace structure of Type 0 (Generic).

  @param [in]  PccCmObj   Pointer to a CmObj PCCT Subspace info structure.
  @param [in]  PccAcpi    Pointer to the ACPI PCCT Subspace structure to populate.

  @retval EFI_SUCCESS           Table generated successfully.
  @retval EFI_INVALID_PARAMETER A parameter is invalid.
**/
STATIC
EFI_STATUS
EFIAPI
AddSubspaceStructType0 (
  IN  CM_ARCH_COMMON_PCC_SUBSPACE_TYPE0_INFO  *PccCmObj,
  IN  EFI_ACPI_6_4_PCCT_SUBSPACE_GENERIC      *PccAcpi
  )
{
  PCC_MAILBOX_REGISTER_INFO         *Doorbell;
  PCC_SUBSPACE_CHANNEL_TIMING_INFO  *ChannelTiming;

  if ((PccCmObj == NULL) ||
      (PccCmObj->Type != EFI_ACPI_6_4_PCCT_SUBSPACE_TYPE_GENERIC)  ||
      (PccAcpi == NULL))
  {
    ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER);
    return EFI_INVALID_PARAMETER;
  }

  Doorbell      = &PccCmObj->DoorbellReg;
  ChannelTiming = &PccCmObj->ChannelTiming;

  PccAcpi->Type                    = PccCmObj->Type;
  PccAcpi->Length                  = sizeof (EFI_ACPI_6_4_PCCT_SUBSPACE_GENERIC);
  *(UINT32 *)&PccAcpi->Reserved[0] = EFI_ACPI_RESERVED_DWORD;
  *(UINT16 *)&PccAcpi->Reserved[4] = EFI_ACPI_RESERVED_WORD;
  PccAcpi->BaseAddress             = PccCmObj->BaseAddress;
  PccAcpi->AddressLength           = PccCmObj->AddressLength;

  CopyMem (
    &PccAcpi->DoorbellRegister,
    &Doorbell->Register,
    sizeof (EFI_ACPI_6_4_GENERIC_ADDRESS_STRUCTURE)
    );
  PccAcpi->DoorbellPreserve = Doorbell->PreserveMask;
  PccAcpi->DoorbellWrite    = Doorbell->WriteMask;

  PccAcpi->NominalLatency               = ChannelTiming->NominalLatency;
  PccAcpi->MaximumPeriodicAccessRate    = ChannelTiming->MaxPeriodicAccessRate;
  PccAcpi->MinimumRequestTurnaroundTime = ChannelTiming->MinRequestTurnaroundTime;

  return EFI_SUCCESS;
}

/** Add one PCCT subspace structure of Type 1 (HW-Reduced).

  @param [in]  PccCmObj   Pointer to a CmObj PCCT Subspace info structure.
  @param [in]  PccAcpi    Pointer to the ACPI PCCT Subspace structure to populate.

  @retval EFI_SUCCESS           Table generated successfully.
  @retval EFI_INVALID_PARAMETER A parameter is invalid.
**/
STATIC
EFI_STATUS
EFIAPI
AddSubspaceStructType1 (
  IN  CM_ARCH_COMMON_PCC_SUBSPACE_TYPE1_INFO                  *PccCmObj,
  IN  EFI_ACPI_6_4_PCCT_SUBSPACE_1_HW_REDUCED_COMMUNICATIONS  *PccAcpi
  )
{
  CM_ARCH_COMMON_PCC_SUBSPACE_TYPE0_INFO  *GenericPccCmObj;
  PCC_MAILBOX_REGISTER_INFO               *Doorbell;
  PCC_SUBSPACE_CHANNEL_TIMING_INFO        *ChannelTiming;

  GenericPccCmObj = (CM_ARCH_COMMON_PCC_SUBSPACE_TYPE0_INFO *)PccCmObj;

  if ((PccCmObj == NULL) ||
      (GenericPccCmObj->Type != EFI_ACPI_6_4_PCCT_SUBSPACE_TYPE_1_HW_REDUCED_COMMUNICATIONS)  ||
      (PccAcpi == NULL))
  {
    ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER);
    return EFI_INVALID_PARAMETER;
  }

  Doorbell      = &GenericPccCmObj->DoorbellReg;
  ChannelTiming = &GenericPccCmObj->ChannelTiming;

  PccAcpi->Type                   = GenericPccCmObj->Type;
  PccAcpi->Length                 = sizeof (EFI_ACPI_6_4_PCCT_SUBSPACE_1_HW_REDUCED_COMMUNICATIONS);
  PccAcpi->PlatformInterrupt      = PccCmObj->PlatIrq.Interrupt;
  PccAcpi->PlatformInterruptFlags = PccCmObj->PlatIrq.Flags;
  PccAcpi->Reserved               = EFI_ACPI_RESERVED_BYTE;
  PccAcpi->BaseAddress            = GenericPccCmObj->BaseAddress;
  PccAcpi->AddressLength          = GenericPccCmObj->AddressLength;

  CopyMem (
    &PccAcpi->DoorbellRegister,
    &Doorbell->Register,
    sizeof (EFI_ACPI_6_4_GENERIC_ADDRESS_STRUCTURE)
    );
  PccAcpi->DoorbellPreserve = Doorbell->PreserveMask;
  PccAcpi->DoorbellWrite    = Doorbell->WriteMask;

  PccAcpi->NominalLatency               = ChannelTiming->NominalLatency;
  PccAcpi->MaximumPeriodicAccessRate    = ChannelTiming->MaxPeriodicAccessRate;
  PccAcpi->MinimumRequestTurnaroundTime = ChannelTiming->MinRequestTurnaroundTime;

  if ((PccCmObj->PlatIrq.Interrupt != 0)) {
    mHasPlatformInterrupt = TRUE;
  }

  return EFI_SUCCESS;
}

/** Add one PCCT subspace structure of Type 2 (HW-Reduced).

  @param [in]  PccCmObj   Pointer to a CmObj PCCT Subspace info structure.
  @param [in]  PccAcpi    Pointer to the ACPI PCCT Subspace structure to populate.

  @retval EFI_SUCCESS           Table generated successfully.
  @retval EFI_INVALID_PARAMETER A parameter is invalid.
**/
STATIC
EFI_STATUS
EFIAPI
AddSubspaceStructType2 (
  IN  CM_ARM_PCC_SUBSPACE_TYPE2_INFO                          *PccCmObj,
  IN  EFI_ACPI_6_4_PCCT_SUBSPACE_2_HW_REDUCED_COMMUNICATIONS  *PccAcpi
  )
{
  CM_ARCH_COMMON_PCC_SUBSPACE_TYPE0_INFO  *GenericPccCmObj;
  PCC_MAILBOX_REGISTER_INFO               *Doorbell;
  PCC_MAILBOX_REGISTER_INFO               *PlatIrqAck;
  PCC_SUBSPACE_CHANNEL_TIMING_INFO        *ChannelTiming;

  GenericPccCmObj = (CM_ARCH_COMMON_PCC_SUBSPACE_TYPE0_INFO *)PccCmObj;

  if ((PccCmObj == NULL) ||
      (GenericPccCmObj->Type != EFI_ACPI_6_4_PCCT_SUBSPACE_TYPE_2_HW_REDUCED_COMMUNICATIONS)  ||
      (PccAcpi == NULL))
  {
    ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER);
    return EFI_INVALID_PARAMETER;
  }

  Doorbell      = &GenericPccCmObj->DoorbellReg;
  PlatIrqAck    = &PccCmObj->PlatIrqAckReg;
  ChannelTiming = &GenericPccCmObj->ChannelTiming;

  PccAcpi->Type                   = GenericPccCmObj->Type;
  PccAcpi->Length                 = sizeof (EFI_ACPI_6_4_PCCT_SUBSPACE_2_HW_REDUCED_COMMUNICATIONS);
  PccAcpi->PlatformInterrupt      = PccCmObj->PlatIrq.Interrupt;
  PccAcpi->PlatformInterruptFlags = PccCmObj->PlatIrq.Flags;
  PccAcpi->BaseAddress            = GenericPccCmObj->BaseAddress;
  PccAcpi->Reserved               = EFI_ACPI_RESERVED_BYTE;
  PccAcpi->BaseAddress            = GenericPccCmObj->BaseAddress;
  PccAcpi->AddressLength          = GenericPccCmObj->AddressLength;

  CopyMem (
    &PccAcpi->DoorbellRegister,
    &Doorbell->Register,
    sizeof (EFI_ACPI_6_4_GENERIC_ADDRESS_STRUCTURE)
    );
  PccAcpi->DoorbellPreserve = Doorbell->PreserveMask;
  PccAcpi->DoorbellWrite    = Doorbell->WriteMask;

  PccAcpi->NominalLatency               = ChannelTiming->NominalLatency;
  PccAcpi->MaximumPeriodicAccessRate    = ChannelTiming->MaxPeriodicAccessRate;
  PccAcpi->MinimumRequestTurnaroundTime = ChannelTiming->MinRequestTurnaroundTime;

  CopyMem (
    &PccAcpi->PlatformInterruptAckRegister,
    &PlatIrqAck->Register,
    sizeof (EFI_ACPI_6_4_GENERIC_ADDRESS_STRUCTURE)
    );
  PccAcpi->PlatformInterruptAckPreserve = PlatIrqAck->PreserveMask;
  PccAcpi->PlatformInterruptAckWrite    = PlatIrqAck->WriteMask;

  if ((PccCmObj->PlatIrq.Interrupt != 0)) {
    mHasPlatformInterrupt = TRUE;
  }

  return EFI_SUCCESS;
}

/** Add one PCCT subspace structure of Type 3 or 4 (Extended).

  @param [in]  PccCmObj   Pointer to a CmObj PCCT Subspace info structure.
  @param [in]  PccAcpi    Pointer to the ACPI PCCT Subspace structure to populate.

  @retval EFI_SUCCESS           Table generated successfully.
  @retval EFI_INVALID_PARAMETER A parameter is invalid.
**/
STATIC
EFI_STATUS
EFIAPI
AddSubspaceStructType34 (
  IN  CM_ARM_PCC_SUBSPACE_TYPE3_INFO             *PccCmObj,
  IN  EFI_ACPI_6_4_PCCT_SUBSPACE_3_EXTENDED_PCC  *PccAcpi
  )
{
  CM_ARCH_COMMON_PCC_SUBSPACE_TYPE0_INFO  *GenericPccCmObj;
  PCC_MAILBOX_REGISTER_INFO               *Doorbell;
  PCC_MAILBOX_REGISTER_INFO               *PlatIrqAck;
  PCC_MAILBOX_REGISTER_INFO               *CmdCompleteCheck;
  PCC_MAILBOX_REGISTER_INFO               *CmdCompleteUpdate;
  PCC_MAILBOX_REGISTER_INFO               *ErrorStatus;
  PCC_SUBSPACE_CHANNEL_TIMING_INFO        *ChannelTiming;

  GenericPccCmObj = (CM_ARCH_COMMON_PCC_SUBSPACE_TYPE0_INFO *)PccCmObj;

  if ((PccCmObj == NULL) ||
      ((GenericPccCmObj->Type != EFI_ACPI_6_4_PCCT_SUBSPACE_TYPE_3_EXTENDED_PCC) &&
       (GenericPccCmObj->Type != EFI_ACPI_6_4_PCCT_SUBSPACE_TYPE_4_EXTENDED_PCC)) ||
      (PccAcpi == NULL))
  {
    ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER);
    return EFI_INVALID_PARAMETER;
  }

  Doorbell          = &GenericPccCmObj->DoorbellReg;
  PlatIrqAck        = &PccCmObj->PlatIrqAckReg;
  CmdCompleteCheck  = &PccCmObj->CmdCompleteCheckReg;
  CmdCompleteUpdate = &PccCmObj->CmdCompleteUpdateReg;
  ErrorStatus       = &PccCmObj->ErrorStatusReg;
  ChannelTiming     = &GenericPccCmObj->ChannelTiming;

  PccAcpi->Type                   = GenericPccCmObj->Type;
  PccAcpi->Length                 = sizeof (EFI_ACPI_6_4_PCCT_SUBSPACE_3_EXTENDED_PCC);
  PccAcpi->PlatformInterrupt      = PccCmObj->PlatIrq.Interrupt;
  PccAcpi->PlatformInterruptFlags = PccCmObj->PlatIrq.Flags;
  PccAcpi->Reserved               = EFI_ACPI_RESERVED_BYTE;
  PccAcpi->BaseAddress            = GenericPccCmObj->BaseAddress;
  PccAcpi->AddressLength          = GenericPccCmObj->AddressLength;

  CopyMem (
    &PccAcpi->DoorbellRegister,
    &Doorbell->Register,
    sizeof (EFI_ACPI_6_4_GENERIC_ADDRESS_STRUCTURE)
    );
  PccAcpi->DoorbellPreserve = Doorbell->PreserveMask;
  PccAcpi->DoorbellWrite    = Doorbell->WriteMask;

  PccAcpi->NominalLatency               = ChannelTiming->NominalLatency;
  PccAcpi->MaximumPeriodicAccessRate    = ChannelTiming->MaxPeriodicAccessRate;
  PccAcpi->MinimumRequestTurnaroundTime = ChannelTiming->MinRequestTurnaroundTime;

  CopyMem (
    &PccAcpi->PlatformInterruptAckRegister,
    &PlatIrqAck->Register,
    sizeof (EFI_ACPI_6_4_GENERIC_ADDRESS_STRUCTURE)
    );
  PccAcpi->PlatformInterruptAckPreserve = PlatIrqAck->PreserveMask;
  PccAcpi->PlatformInterruptAckSet      = PlatIrqAck->WriteMask;

  PccAcpi->Reserved1[0] = EFI_ACPI_RESERVED_BYTE;
  PccAcpi->Reserved1[1] = EFI_ACPI_RESERVED_BYTE;
  PccAcpi->Reserved1[1] = EFI_ACPI_RESERVED_BYTE;
  PccAcpi->Reserved1[3] = EFI_ACPI_RESERVED_BYTE;
  PccAcpi->Reserved1[4] = EFI_ACPI_RESERVED_BYTE;
  PccAcpi->Reserved1[5] = EFI_ACPI_RESERVED_BYTE;
  PccAcpi->Reserved1[6] = EFI_ACPI_RESERVED_BYTE;
  PccAcpi->Reserved1[7] = EFI_ACPI_RESERVED_BYTE;

  CopyMem (
    &PccAcpi->CommandCompleteCheckRegister,
    &CmdCompleteCheck->Register,
    sizeof (EFI_ACPI_6_4_GENERIC_ADDRESS_STRUCTURE)
    );
  PccAcpi->CommandCompleteCheckMask = CmdCompleteCheck->PreserveMask;
  // No Write mask.

  CopyMem (
    &PccAcpi->CommandCompleteUpdateRegister,
    &CmdCompleteUpdate->Register,
    sizeof (EFI_ACPI_6_4_GENERIC_ADDRESS_STRUCTURE)
    );
  PccAcpi->CommandCompleteUpdatePreserve = CmdCompleteUpdate->PreserveMask;
  PccAcpi->CommandCompleteUpdateSet      = CmdCompleteUpdate->WriteMask;

  CopyMem (
    &PccAcpi->ErrorStatusRegister,
    &ErrorStatus->Register,
    sizeof (EFI_ACPI_6_4_GENERIC_ADDRESS_STRUCTURE)
    );
  PccAcpi->ErrorStatusMask = ErrorStatus->PreserveMask;
  // No Write mask.

  if (GenericPccCmObj->Type == EFI_ACPI_6_4_PCCT_SUBSPACE_TYPE_4_EXTENDED_PCC) {
    mHasPlatformInterrupt = TRUE;
  } else if ((PccCmObj->PlatIrq.Interrupt != 0)) {
    mHasPlatformInterrupt = TRUE;
  }

  return EFI_SUCCESS;
}

/** Add one PCCT subspace structure of Type 5 (HW-Registers).

  @param [in]  PccCmObj   Pointer to a CmObj PCCT Subspace info structure.
  @param [in]  PccAcpi    Pointer to the ACPI PCCT Subspace structure to populate.

  @retval EFI_SUCCESS           Table generated successfully.
  @retval EFI_INVALID_PARAMETER A parameter is invalid.
**/
STATIC
EFI_STATUS
EFIAPI
AddSubspaceStructType5 (
  IN  CM_ARM_PCC_SUBSPACE_TYPE5_INFO                            *PccCmObj,
  IN  EFI_ACPI_6_4_PCCT_SUBSPACE_5_HW_REGISTERS_COMMUNICATIONS  *PccAcpi
  )
{
  CM_ARCH_COMMON_PCC_SUBSPACE_TYPE0_INFO  *GenericPccCmObj;
  PCC_MAILBOX_REGISTER_INFO               *Doorbell;
  PCC_MAILBOX_REGISTER_INFO               *CmdCompleteCheck;
  PCC_MAILBOX_REGISTER_INFO               *ErrorStatus;
  PCC_SUBSPACE_CHANNEL_TIMING_INFO        *ChannelTiming;

  GenericPccCmObj = (CM_ARCH_COMMON_PCC_SUBSPACE_TYPE0_INFO *)PccCmObj;

  if ((PccCmObj == NULL) ||
      (GenericPccCmObj->Type != EFI_ACPI_6_4_PCCT_SUBSPACE_TYPE_5_HW_REGISTERS_COMMUNICATIONS)  ||
      (PccAcpi == NULL))
  {
    ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER);
    return EFI_INVALID_PARAMETER;
  }

  Doorbell         = &GenericPccCmObj->DoorbellReg;
  CmdCompleteCheck = &PccCmObj->CmdCompleteCheckReg;
  ErrorStatus      = &PccCmObj->ErrorStatusReg;
  ChannelTiming    = &GenericPccCmObj->ChannelTiming;

  PccAcpi->Type                    = GenericPccCmObj->Type;
  PccAcpi->Length                  = sizeof (EFI_ACPI_6_4_PCCT_SUBSPACE_5_HW_REGISTERS_COMMUNICATIONS);
  PccAcpi->Version                 = PccCmObj->Version;
  PccAcpi->BaseAddress             = GenericPccCmObj->BaseAddress;
  PccAcpi->SharedMemoryRangeLength = GenericPccCmObj->AddressLength;

  CopyMem (
    &PccAcpi->DoorbellRegister,
    &Doorbell->Register,
    sizeof (EFI_ACPI_6_4_GENERIC_ADDRESS_STRUCTURE)
    );
  PccAcpi->DoorbellPreserve = Doorbell->PreserveMask;
  PccAcpi->DoorbellWrite    = Doorbell->WriteMask;

  CopyMem (
    &PccAcpi->CommandCompleteCheckRegister,
    &CmdCompleteCheck->Register,
    sizeof (EFI_ACPI_6_4_GENERIC_ADDRESS_STRUCTURE)
    );
  PccAcpi->CommandCompleteCheckMask = CmdCompleteCheck->PreserveMask;
  // No Write mask.

  CopyMem (
    &PccAcpi->ErrorStatusRegister,
    &ErrorStatus->Register,
    sizeof (EFI_ACPI_6_4_GENERIC_ADDRESS_STRUCTURE)
    );
  PccAcpi->ErrorStatusMask = ErrorStatus->PreserveMask;
  // No Write mask.

  PccAcpi->NominalLatency = ChannelTiming->NominalLatency;
  // No MaximumPeriodicAccessRate.
  PccAcpi->MinimumRequestTurnaroundTime = ChannelTiming->MinRequestTurnaroundTime;

  return EFI_SUCCESS;
}

/** Populate the PCCT table using the MappingTable.

  @param [in] MappingTable  The mapping table structure.
  @param [in] Pcc           Pointer to an array of Pcc Subpace structures.
  @param [in] Size          Size of the Pcc array.

  @retval EFI_SUCCESS           Table generated successfully.
  @retval EFI_BUFFER_TOO_SMALL  Buffer too small.
  @retval EFI_INVALID_PARAMETER A parameter is invalid.
**/
STATIC
EFI_STATUS
EFIAPI
PopulatePcctTable (
  IN  MAPPING_TABLE  *MappingTable,
  IN  VOID           *Pcc,
  IN  UINT32         Size
  )
{
  EFI_STATUS  Status;
  UINT8       *PccBuffer;
  UINT32      CmObjSize;
  UINT32      Index;
  UINT32      MaxIndex;
  VOID        **Table;
  VOID        *CurrentPccSubspace;

  ASSERT (MappingTable != NULL);
  ASSERT (MappingTable->Table != NULL);

  PccBuffer = Pcc;
  MaxIndex  = MappingTable->MaxIndex;
  Table     = MappingTable->Table;

  for (Index = 0; Index < MaxIndex; Index++) {
    CurrentPccSubspace = Table[Index];
    if (CurrentPccSubspace == NULL) {
      ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER);
      return EFI_INVALID_PARAMETER;
    }

    switch (((PCC_SUBSPACE_GENERIC_INFO *)CurrentPccSubspace)->Type) {
      case EFI_ACPI_6_4_PCCT_SUBSPACE_TYPE_GENERIC:
        Status = AddSubspaceStructType0 (
                   (CM_ARCH_COMMON_PCC_SUBSPACE_TYPE0_INFO *)CurrentPccSubspace,
                   (EFI_ACPI_6_4_PCCT_SUBSPACE_GENERIC *)PccBuffer
                   );

        CmObjSize = sizeof (EFI_ACPI_6_4_PCCT_SUBSPACE_GENERIC);
        break;

      case EFI_ACPI_6_4_PCCT_SUBSPACE_TYPE_1_HW_REDUCED_COMMUNICATIONS:
        Status = AddSubspaceStructType1 (
                   (CM_ARCH_COMMON_PCC_SUBSPACE_TYPE1_INFO *)CurrentPccSubspace,
                   (EFI_ACPI_6_4_PCCT_SUBSPACE_1_HW_REDUCED_COMMUNICATIONS *)PccBuffer
                   );

        CmObjSize = sizeof (EFI_ACPI_6_4_PCCT_SUBSPACE_1_HW_REDUCED_COMMUNICATIONS);
        break;

      case EFI_ACPI_6_4_PCCT_SUBSPACE_TYPE_2_HW_REDUCED_COMMUNICATIONS:
        Status = AddSubspaceStructType2 (
                   (CM_ARM_PCC_SUBSPACE_TYPE2_INFO *)CurrentPccSubspace,
                   (EFI_ACPI_6_4_PCCT_SUBSPACE_2_HW_REDUCED_COMMUNICATIONS *)PccBuffer
                   );

        CmObjSize = sizeof (EFI_ACPI_6_4_PCCT_SUBSPACE_2_HW_REDUCED_COMMUNICATIONS);
        break;

      case EFI_ACPI_6_4_PCCT_SUBSPACE_TYPE_3_EXTENDED_PCC:
        Status = AddSubspaceStructType34 (
                   (CM_ARM_PCC_SUBSPACE_TYPE3_INFO *)CurrentPccSubspace,
                   (EFI_ACPI_6_4_PCCT_SUBSPACE_3_EXTENDED_PCC *)PccBuffer
                   );

        CmObjSize = sizeof (EFI_ACPI_6_4_PCCT_SUBSPACE_3_EXTENDED_PCC);
        break;

      case EFI_ACPI_6_4_PCCT_SUBSPACE_TYPE_4_EXTENDED_PCC:
        Status = AddSubspaceStructType34 (
                   (CM_ARM_PCC_SUBSPACE_TYPE4_INFO *)CurrentPccSubspace,
                   (EFI_ACPI_6_4_PCCT_SUBSPACE_4_EXTENDED_PCC *)PccBuffer
                   );

        CmObjSize = sizeof (EFI_ACPI_6_4_PCCT_SUBSPACE_4_EXTENDED_PCC);
        break;

      case EFI_ACPI_6_4_PCCT_SUBSPACE_TYPE_5_HW_REGISTERS_COMMUNICATIONS:
        Status = AddSubspaceStructType5 (
                   (CM_ARM_PCC_SUBSPACE_TYPE5_INFO *)CurrentPccSubspace,
                   (EFI_ACPI_6_4_PCCT_SUBSPACE_5_HW_REGISTERS_COMMUNICATIONS *)PccBuffer
                   );

        CmObjSize = sizeof (EFI_ACPI_6_4_PCCT_SUBSPACE_5_HW_REGISTERS_COMMUNICATIONS);
        break;

      default:
        ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER);
        return EFI_INVALID_PARAMETER;
    } // switch

    if (EFI_ERROR (Status)) {
      ASSERT_EFI_ERROR (Status);
      return Status;
    }

    if (Size < CmObjSize) {
      ASSERT_EFI_ERROR (EFI_BUFFER_TOO_SMALL);
      return EFI_BUFFER_TOO_SMALL;
    }

    PccBuffer += CmObjSize;
    Size      -= CmObjSize;
  } // for

  return EFI_SUCCESS;
}

/** Construct the PCCT ACPI table.

  Called by the Dynamic Table Manager, this function invokes the
  Configuration Manager protocol interface to get the required hardware
  information for generating the ACPI table.

  If this function allocates any resources then they must be freed
  in the FreeXXXXTableResources function.

  @param [in]  This           Pointer to the table generator.
  @param [in]  AcpiTableInfo  Pointer to the ACPI Table Info.
  @param [in]  CfgMgrProtocol Pointer to the Configuration Manager
                              Protocol Interface.
  @param [out] Table          Pointer to the constructed ACPI Table.

  @retval EFI_SUCCESS           Table generated successfully.
  @retval EFI_INVALID_PARAMETER A parameter is invalid.
  @retval EFI_NOT_FOUND         The required object was not found.
  @retval EFI_BAD_BUFFER_SIZE   The size returned by the Configuration
                                Manager is less than the Object size for the
                                requested object.
  @retval EFI_BUFFER_TOO_SMALL   Buffer too small.
  @retval EFI_OUT_OF_RESOURCES  Memory allocation failed.
**/
STATIC
EFI_STATUS
EFIAPI
BuildPcctTable (
  IN  CONST ACPI_TABLE_GENERATOR                  *CONST  This,
  IN  CONST CM_STD_OBJ_ACPI_TABLE_INFO            *CONST  AcpiTableInfo,
  IN  CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL  *CONST  CfgMgrProtocol,
  OUT       EFI_ACPI_DESCRIPTION_HEADER          **CONST  Table
  )
{
  EFI_STATUS                                                Status;
  ACPI_PCCT_GENERATOR                                       *Generator;
  UINT32                                                    TableSize;
  EFI_ACPI_6_4_PLATFORM_COMMUNICATION_CHANNEL_TABLE_HEADER  *Pcct;
  UINT8                                                     *Buffer;

  MAPPING_TABLE  *MappingTable;
  UINT32         MappingTableCount;

  CM_ARCH_COMMON_PCC_SUBSPACE_TYPE0_INFO  *PccType0;
  UINT32                                  PccType0Count;
  CM_ARCH_COMMON_PCC_SUBSPACE_TYPE1_INFO  *PccType1;
  UINT32                                  PccType1Count;
  CM_ARM_PCC_SUBSPACE_TYPE2_INFO          *PccType2;
  UINT32                                  PccType2Count;
  CM_ARM_PCC_SUBSPACE_TYPE3_INFO          *PccType3;
  UINT32                                  PccType3Count;
  CM_ARM_PCC_SUBSPACE_TYPE4_INFO          *PccType4;
  UINT32                                  PccType4Count;
  CM_ARM_PCC_SUBSPACE_TYPE5_INFO          *PccType5;
  UINT32                                  PccType5Count;

  ASSERT (This != NULL);
  ASSERT (AcpiTableInfo != NULL);
  ASSERT (CfgMgrProtocol != NULL);
  ASSERT (Table != NULL);
  ASSERT (AcpiTableInfo->TableGeneratorId == This->GeneratorID);
  ASSERT (AcpiTableInfo->AcpiTableSignature == This->AcpiTableSignature);

  if ((AcpiTableInfo->AcpiTableRevision < This->MinAcpiTableRevision) ||
      (AcpiTableInfo->AcpiTableRevision > This->AcpiTableRevision))
  {
    DEBUG ((
      DEBUG_ERROR,
      "ERROR: PCCT: Requested table revision = %d, is not supported."
      "Supported table revision: Minimum = %d, Maximum = %d\n",
      AcpiTableInfo->AcpiTableRevision,
      This->MinAcpiTableRevision,
      This->AcpiTableRevision
      ));
    ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER);
    return EFI_INVALID_PARAMETER;
  }

  Generator    = (ACPI_PCCT_GENERATOR *)This;
  MappingTable = &Generator->MappingTable;
  *Table       = NULL;

  // First get all the Pcc Subpace CmObj of type X.

  Status = GetEArchCommonObjPccSubspaceType0Info (
             CfgMgrProtocol,
             CM_NULL_TOKEN,
             &PccType0,
             &PccType0Count
             );
  if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) {
    ASSERT_EFI_ERROR (Status);
    goto error_handler;
  }

  Status = GetEArchCommonObjPccSubspaceType1Info (
             CfgMgrProtocol,
             CM_NULL_TOKEN,
             &PccType1,
             &PccType1Count
             );
  if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) {
    ASSERT_EFI_ERROR (Status);
    goto error_handler;
  }

  Status = GetEArmObjPccSubspaceType2Info (
             CfgMgrProtocol,
             CM_NULL_TOKEN,
             &PccType2,
             &PccType2Count
             );
  if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) {
    ASSERT_EFI_ERROR (Status);
    goto error_handler;
  }

  Status = GetEArmObjPccSubspaceType3Info (
             CfgMgrProtocol,
             CM_NULL_TOKEN,
             &PccType3,
             &PccType3Count
             );
  if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) {
    ASSERT_EFI_ERROR (Status);
    goto error_handler;
  }

  Status = GetEArmObjPccSubspaceType4Info (
             CfgMgrProtocol,
             CM_NULL_TOKEN,
             &PccType4,
             &PccType4Count
             );
  if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) {
    ASSERT_EFI_ERROR (Status);
    goto error_handler;
  }

  Status = GetEArmObjPccSubspaceType5Info (
             CfgMgrProtocol,
             CM_NULL_TOKEN,
             &PccType5,
             &PccType5Count
             );
  if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) {
    ASSERT_EFI_ERROR (Status);
    goto error_handler;
  }

  // Count the number of Pcc Subspaces.
  MappingTableCount  = PccType0Count;
  MappingTableCount += PccType1Count;
  MappingTableCount += PccType2Count;
  MappingTableCount += PccType3Count;
  MappingTableCount += PccType4Count;
  MappingTableCount += PccType5Count;

  Status = MappingTableInitialize (MappingTable, MappingTableCount);
  if (EFI_ERROR (Status)) {
    ASSERT_EFI_ERROR (Status);
    goto error_handler;
  }

  // Map the Subspace Ids for all types.

  Status = MapPccSubspaceId (MappingTable, PccType0, PccType0Count);
  if (EFI_ERROR (Status)) {
    ASSERT_EFI_ERROR (Status);
    goto error_handler;
  }

  Status = MapPccSubspaceId (MappingTable, PccType1, PccType1Count);
  if (EFI_ERROR (Status)) {
    ASSERT_EFI_ERROR (Status);
    goto error_handler;
  }

  Status = MapPccSubspaceId (MappingTable, PccType2, PccType2Count);
  if (EFI_ERROR (Status)) {
    ASSERT_EFI_ERROR (Status);
    goto error_handler;
  }

  Status = MapPccSubspaceId (MappingTable, PccType3, PccType3Count);
  if (EFI_ERROR (Status)) {
    ASSERT_EFI_ERROR (Status);
    goto error_handler;
  }

  Status = MapPccSubspaceId (MappingTable, PccType4, PccType4Count);
  if (EFI_ERROR (Status)) {
    ASSERT_EFI_ERROR (Status);
    goto error_handler;
  }

  Status = MapPccSubspaceId (MappingTable, PccType5, PccType5Count);
  if (EFI_ERROR (Status)) {
    ASSERT_EFI_ERROR (Status);
    goto error_handler;
  }

  // Compute the size of the PCCT table.
  TableSize  = sizeof (EFI_ACPI_6_4_PLATFORM_COMMUNICATION_CHANNEL_TABLE_HEADER);
  TableSize += PccType0Count * sizeof (EFI_ACPI_6_4_PCCT_SUBSPACE_GENERIC);
  TableSize += PccType1Count * sizeof (EFI_ACPI_6_4_PCCT_SUBSPACE_1_HW_REDUCED_COMMUNICATIONS);
  TableSize += PccType2Count * sizeof (EFI_ACPI_6_4_PCCT_SUBSPACE_2_HW_REDUCED_COMMUNICATIONS);
  TableSize += PccType3Count * sizeof (EFI_ACPI_6_4_PCCT_SUBSPACE_3_EXTENDED_PCC);
  TableSize += PccType4Count * sizeof (EFI_ACPI_6_4_PCCT_SUBSPACE_4_EXTENDED_PCC);
  TableSize += PccType5Count * sizeof (EFI_ACPI_6_4_PCCT_SUBSPACE_5_HW_REGISTERS_COMMUNICATIONS);

  // Allocate a Buffer for the PCCT table.
  *Table = (EFI_ACPI_DESCRIPTION_HEADER *)AllocateZeroPool (TableSize);
  if (*Table == NULL) {
    Status = EFI_OUT_OF_RESOURCES;
    ASSERT_EFI_ERROR (Status);
    goto error_handler;
  }

  Pcct = (EFI_ACPI_6_4_PLATFORM_COMMUNICATION_CHANNEL_TABLE_HEADER *)*Table;

  Status = AddAcpiHeader (
             CfgMgrProtocol,
             This,
             &Pcct->Header,
             AcpiTableInfo,
             TableSize
             );
  if (EFI_ERROR (Status)) {
    DEBUG ((
      DEBUG_ERROR,
      "ERROR: PCCT: Failed to add ACPI header. Status = %r\n",
      Status
      ));
    ASSERT_EFI_ERROR (Status);
    goto error_handler;
  }

  Buffer     = (UINT8 *)Pcct;
  Buffer    += sizeof (EFI_ACPI_6_4_PLATFORM_COMMUNICATION_CHANNEL_TABLE_HEADER);
  TableSize -= sizeof (EFI_ACPI_6_4_PLATFORM_COMMUNICATION_CHANNEL_TABLE_HEADER);

  // Populate the PCCT table by following the Subspace Id mapping.
  Status = PopulatePcctTable (MappingTable, Buffer, TableSize);
  if (EFI_ERROR (Status)) {
    ASSERT_EFI_ERROR (Status);
    goto error_handler;
  }

  // Setup the Reserved fields once mHasPlatformInterrupt hase been populated.
  Pcct->Flags    = mHasPlatformInterrupt;
  Pcct->Reserved = EFI_ACPI_RESERVED_QWORD;

  MappingTableFree (MappingTable);

  return Status;

error_handler:
  DEBUG ((
    DEBUG_ERROR,
    "ERROR: PCCT: Failed to install table. Status = %r\n",
    Status
    ));

  if (*Table != NULL) {
    FreePool (*Table);
    *Table = NULL;
  }

  MappingTableFree (MappingTable);

  return Status;
}

/** Free any resources allocated for constructing the PCCT.

  @param [in]      This           Pointer to the table generator.
  @param [in]      AcpiTableInfo  Pointer to the ACPI Table Info.
  @param [in]      CfgMgrProtocol Pointer to the Configuration Manager
                                  Protocol Interface.
  @param [in, out] Table          Pointer to the ACPI Table.

  @retval EFI_SUCCESS           The resources were freed successfully.
  @retval EFI_INVALID_PARAMETER The table pointer is NULL or invalid.
**/
STATIC
EFI_STATUS
FreePcctTableResources (
  IN      CONST ACPI_TABLE_GENERATOR                  *CONST  This,
  IN      CONST CM_STD_OBJ_ACPI_TABLE_INFO            *CONST  AcpiTableInfo,
  IN      CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL  *CONST  CfgMgrProtocol,
  IN OUT        EFI_ACPI_DESCRIPTION_HEADER          **CONST  Table
  )
{
  ASSERT (This != NULL);
  ASSERT (AcpiTableInfo != NULL);
  ASSERT (CfgMgrProtocol != NULL);
  ASSERT (AcpiTableInfo->TableGeneratorId == This->GeneratorID);
  ASSERT (AcpiTableInfo->AcpiTableSignature == This->AcpiTableSignature);

  if ((Table == NULL) || (*Table == NULL)) {
    DEBUG ((DEBUG_ERROR, "ERROR: PCCT: Invalid Table Pointer\n"));
    ASSERT ((Table != NULL) && (*Table != NULL));
    return EFI_INVALID_PARAMETER;
  }

  FreePool (*Table);
  *Table = NULL;
  return EFI_SUCCESS;
}

/** This macro defines the PCCT Table Generator revision.
*/
#define PCCT_GENERATOR_REVISION  CREATE_REVISION (1, 0)

/** The interface for the PCCT Table Generator.
*/
STATIC
ACPI_PCCT_GENERATOR  PcctGenerator = {
  // ACPI table generator header
  {
    // Generator ID
    CREATE_STD_ACPI_TABLE_GEN_ID (EStdAcpiTableIdPcct),
    // Generator Description
    L"ACPI.STD.PCCT.GENERATOR",
    // ACPI Table Signature
    EFI_ACPI_6_4_PLATFORM_COMMUNICATIONS_CHANNEL_TABLE_SIGNATURE,
    // ACPI Table Revision supported by this Generator
    EFI_ACPI_6_4_PLATFORM_COMMUNICATION_CHANNEL_TABLE_REVISION,
    // Minimum ACPI Table Revision supported by this Generator
    EFI_ACPI_6_4_PLATFORM_COMMUNICATION_CHANNEL_TABLE_REVISION,
    // Creator ID
    TABLE_GENERATOR_CREATOR_ID_ARM,
    // Creator Revision
    PCCT_GENERATOR_REVISION,
    // Build Table function
    BuildPcctTable,
    // Free Resource function
    FreePcctTableResources,
    // Extended build function not needed
    NULL,
    // Extended build function not implemented by the generator.
    // Hence extended free resource function is not required.
    NULL
  },

  // Private fields are defined from here.

  // Mapping Table
  {
    // Table
    NULL,
    // MaxIndex
    0,
  },
};

/** Register the Generator with the ACPI Table Factory.

  @param [in]  ImageHandle  The handle to the image.
  @param [in]  SystemTable  Pointer to the System Table.

  @retval EFI_SUCCESS           The Generator is registered.
  @retval EFI_INVALID_PARAMETER A parameter is invalid.
  @retval EFI_ALREADY_STARTED   The Generator for the Table ID
                                is already registered.
**/
EFI_STATUS
EFIAPI
AcpiPcctLibConstructor (
  IN  EFI_HANDLE        ImageHandle,
  IN  EFI_SYSTEM_TABLE  *SystemTable
  )
{
  EFI_STATUS  Status;

  Status = RegisterAcpiTableGenerator (&PcctGenerator.Header);
  DEBUG ((DEBUG_INFO, "PCCT: Register Generator. Status = %r\n", Status));
  ASSERT_EFI_ERROR (Status);
  return Status;
}

/** Deregister the Generator from the ACPI Table Factory.

  @param [in]  ImageHandle  The handle to the image.
  @param [in]  SystemTable  Pointer to the System Table.

  @retval EFI_SUCCESS           The Generator is deregistered.
  @retval EFI_INVALID_PARAMETER A parameter is invalid.
  @retval EFI_NOT_FOUND         The Generator is not registered.
**/
EFI_STATUS
EFIAPI
AcpiPcctLibDestructor (
  IN  EFI_HANDLE        ImageHandle,
  IN  EFI_SYSTEM_TABLE  *SystemTable
  )
{
  EFI_STATUS  Status;

  Status = DeregisterAcpiTableGenerator (&PcctGenerator.Header);
  DEBUG ((DEBUG_INFO, "PCCT: Deregister Generator. Status = %r\n", Status));
  ASSERT_EFI_ERROR (Status);
  return Status;
}