summaryrefslogtreecommitdiffstats
path: root/ArmPkg/Drivers/CpuDxe/CpuMpCore.c
blob: d16ae3979207966e716054bf3f3c675775ba257c (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
/** @file
*
*  Copyright (c) 2011-2014, ARM Limited. All rights reserved.
*
*  SPDX-License-Identifier: BSD-2-Clause-Patent
*
**/

#include <Library/UefiBootServicesTableLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/HobLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>

#include <Guid/ArmMpCoreInfo.h>

ARM_PROCESSOR_TABLE mArmProcessorTableTemplate = {
  {
    EFI_ARM_PROCESSOR_TABLE_SIGNATURE,
    0,
    EFI_ARM_PROCESSOR_TABLE_REVISION,
    EFI_ARM_PROCESSOR_TABLE_OEM_ID,
    EFI_ARM_PROCESSOR_TABLE_OEM_TABLE_ID,
    EFI_ARM_PROCESSOR_TABLE_OEM_REVISION,
    EFI_ARM_PROCESSOR_TABLE_CREATOR_ID,
    EFI_ARM_PROCESSOR_TABLE_CREATOR_REVISION,
    { 0 },
    0
  },   //ARM Processor table header
  0,   // Number of entries in ARM processor Table
  NULL // ARM Processor Table
};

/** Publish ARM Processor Data table in UEFI SYSTEM Table.
 * @param:  HobStart               Pointer to the beginning of the HOB List from PEI.
 *
 * Description : This function iterates through HOB list and finds ARM processor Table Entry HOB.
 *               If  the ARM processor Table Entry HOB is found, the HOB data is copied to run-time memory
 *               and a pointer is assigned to it in ARM processor table. Then the ARM processor table is
 *               installed in EFI configuration table.
**/
VOID
EFIAPI
PublishArmProcessorTable (
  VOID
  )
{
  EFI_PEI_HOB_POINTERS    Hob;

  Hob.Raw = GetHobList ();

  // Iterate through the HOBs and find if there is ARM PROCESSOR ENTRY HOB
  for (; !END_OF_HOB_LIST(Hob); Hob.Raw = GET_NEXT_HOB(Hob)) {
    // Check for Correct HOB type
    if ((GET_HOB_TYPE (Hob)) == EFI_HOB_TYPE_GUID_EXTENSION) {
      // Check for correct GUID type
      if (CompareGuid(&(Hob.Guid->Name), &gArmMpCoreInfoGuid)) {
        ARM_PROCESSOR_TABLE     *ArmProcessorTable;
        EFI_STATUS              Status;

        // Allocate Runtime memory for ARM processor table
        ArmProcessorTable = (ARM_PROCESSOR_TABLE*)AllocateRuntimePool(sizeof(ARM_PROCESSOR_TABLE));

        // Check if the memory allocation is successful or not
        ASSERT(NULL != ArmProcessorTable);

        // Set ARM processor table to default values
        CopyMem(ArmProcessorTable,&mArmProcessorTableTemplate,sizeof(ARM_PROCESSOR_TABLE));

        // Fill in Length fields of ARM processor table
        ArmProcessorTable->Header.Length = sizeof(ARM_PROCESSOR_TABLE);
        ArmProcessorTable->Header.DataLen = GET_GUID_HOB_DATA_SIZE(Hob);

        // Fill in Identifier(ARM processor table GUID)
        ArmProcessorTable->Header.Identifier = gArmMpCoreInfoGuid;

        // Set Number of ARM core entries in the Table
        ArmProcessorTable->NumberOfEntries = GET_GUID_HOB_DATA_SIZE(Hob)/sizeof(ARM_CORE_INFO);

        // Allocate runtime memory for ARM processor Table entries
        ArmProcessorTable->ArmCpus = (ARM_CORE_INFO*)AllocateRuntimePool (
           ArmProcessorTable->NumberOfEntries * sizeof(ARM_CORE_INFO));

        // Check if the memory allocation is successful or not
        ASSERT(NULL != ArmProcessorTable->ArmCpus);

        // Copy ARM Processor Table data from HOB list to newly allocated memory
        CopyMem(ArmProcessorTable->ArmCpus,GET_GUID_HOB_DATA(Hob), ArmProcessorTable->Header.DataLen);

        // Install the ARM Processor table into EFI system configuration table
        Status = gBS->InstallConfigurationTable (&gArmMpCoreInfoGuid, ArmProcessorTable);

        ASSERT_EFI_ERROR (Status);
      }
    }
  }
}