]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/PrePeiCore/MainMPCore.c
ArmPkg: Create MpCoreInfo PPI and HOB to describe CPU Cores on a MPCore platform
[mirror_edk2.git] / ArmPlatformPkg / PrePeiCore / MainMPCore.c
CommitLineData
1d5d0ae9 1/** @file\r
2*\r
3* Copyright (c) 2011, ARM Limited. All rights reserved.\r
4*\r
5* This program and the accompanying materials\r
6* are licensed and made available under the terms and conditions of the BSD License\r
7* which accompanies this distribution. The full text of the license may be found at\r
8* http://opensource.org/licenses/bsd-license.php\r
9*\r
10* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12*\r
13**/\r
14\r
55a0d64b 15#include <Library/ArmGicLib.h>\r
44788bae 16\r
17#include <Ppi/ArmMpCoreInfo.h>\r
18\r
1d5d0ae9 19#include <Chipset/ArmV7.h>\r
1d5d0ae9 20\r
f598bf12 21#include "PrePeiCore.h"\r
22\r
1d5d0ae9 23/*\r
24 * This is the main function for secondary cores. They loop around until a non Null value is written to\r
25 * SYS_FLAGS register.The SYS_FLAGS register is platform specific.\r
26 * Note:The secondary cores, while executing secondary_main, assumes that:\r
27 * : SGI 0 is configured as Non-secure interrupt\r
28 * : Priority Mask is configured to allow SGI 0\r
29 * : Interrupt Distributor and CPU interfaces are enabled\r
30 *\r
31 */\r
32VOID\r
33EFIAPI\r
f598bf12 34SecondaryMain (\r
0787bc61 35 IN UINTN MpId\r
f598bf12 36 )\r
1d5d0ae9 37{\r
44788bae 38 EFI_STATUS Status;\r
39 UINTN PpiListSize;\r
40 UINTN PpiListCount;\r
41 EFI_PEI_PPI_DESCRIPTOR *PpiList;\r
42 ARM_MP_CORE_INFO_PPI *ArmMpCoreInfoPpi;\r
43 UINTN Index;\r
44 UINTN ArmCoreCount;\r
45 ARM_CORE_INFO *ArmCoreInfoTable;\r
46 UINT32 ClusterId;\r
47 UINT32 CoreId;\r
48 VOID (*SecondaryStart)(VOID);\r
49 UINTN SecondaryEntryAddr;\r
50\r
51 ClusterId = GET_CLUSTER_ID(MpId);\r
52 CoreId = GET_CORE_ID(MpId);\r
53\r
54 // Get the gArmMpCoreInfoPpiGuid\r
55 PpiListSize = 0;\r
56 ArmPlatformGetPlatformPpiList (&PpiListSize, &PpiList);\r
57 PpiListCount = PpiListSize / sizeof(EFI_PEI_PPI_DESCRIPTOR);\r
58 for (Index = 0; Index < PpiListCount; Index++, PpiList++) {\r
59 if (CompareGuid (PpiList->Guid, &gArmMpCoreInfoPpiGuid) == TRUE) {\r
60 break;\r
61 }\r
62 }\r
63\r
64 // On MP Core Platform we must implement the ARM MP Core Info PPI\r
65 ASSERT (Index != PpiListCount);\r
66\r
67 ArmMpCoreInfoPpi = PpiList->Ppi;\r
68 ArmCoreCount = 0;\r
69 Status = ArmMpCoreInfoPpi->GetMpCoreInfo (&ArmCoreCount, &ArmCoreInfoTable);\r
70 ASSERT_EFI_ERROR (Status);\r
71\r
72 // Find the core in the ArmCoreTable\r
73 for (Index = 0; Index < ArmCoreCount; Index++) {\r
74 if ((ArmCoreInfoTable[Index].ClusterId == ClusterId) && (ArmCoreInfoTable[Index].CoreId == CoreId)) {\r
75 break;\r
76 }\r
77 }\r
78\r
79 // The ARM Core Info Table must define every core\r
80 ASSERT (Index != ArmCoreCount);\r
1d5d0ae9 81\r
f598bf12 82 // Clear Secondary cores MailBox\r
44788bae 83 MmioWrite32 (ArmCoreInfoTable[Index].MailboxClearAddress, ArmCoreInfoTable[Index].MailboxClearValue);\r
1d5d0ae9 84\r
44788bae 85 SecondaryEntryAddr = 0;\r
86 while (SecondaryEntryAddr = MmioRead32 (ArmCoreInfoTable[Index].MailboxGetAddress), SecondaryEntryAddr == 0) {\r
87 ArmCallWFI ();\r
f598bf12 88 // Acknowledge the interrupt and send End of Interrupt signal.\r
0787bc61 89 ArmGicAcknowledgeSgiFrom (PcdGet32(PcdGicInterruptInterfaceBase), PRIMARY_CORE_ID);\r
f598bf12 90 }\r
1d5d0ae9 91\r
f598bf12 92 // Jump to secondary core entry point.\r
44788bae 93 SecondaryStart = (VOID (*)())SecondaryEntryAddr;\r
94 SecondaryStart();\r
1d5d0ae9 95\r
f598bf12 96 // The secondaries shouldn't reach here\r
97 ASSERT(FALSE);\r
1d5d0ae9 98}\r
99\r
f598bf12 100VOID\r
101EFIAPI\r
102PrimaryMain (\r
1d5d0ae9 103 IN EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint\r
104 )\r
105{\r
f598bf12 106 EFI_SEC_PEI_HAND_OFF SecCoreData;\r
77de7e53 107 UINTN PpiListSize;\r
108 EFI_PEI_PPI_DESCRIPTOR *PpiList;\r
109 UINTN TemporaryRamBase;\r
110 UINTN TemporaryRamSize;\r
111\r
112 CreatePpiList (&PpiListSize, &PpiList);\r
1d5d0ae9 113\r
55a0d64b 114 // Enable the GIC Distributor\r
115 ArmGicEnableDistributor(PcdGet32(PcdGicDistributorBase));\r
1d5d0ae9 116\r
f598bf12 117 // If ArmVe has not been built as Standalone then we need to wake up the secondary cores\r
55a0d64b 118 if (FeaturePcdGet (PcdSendSgiToBringUpSecondaryCores)) {\r
f598bf12 119 // Sending SGI to all the Secondary CPU interfaces\r
55a0d64b 120 ArmGicSendSgiTo (PcdGet32(PcdGicDistributorBase), ARM_GIC_ICDSGIR_FILTER_EVERYONEELSE, 0x0E);\r
f598bf12 121 }\r
1d5d0ae9 122\r
77de7e53 123 // Adjust the Temporary Ram as the new Ppi List (Common + Platform Ppi Lists) is created at\r
124 // the base of the primary core stack\r
125 PpiListSize = ALIGN_VALUE(PpiListSize, 0x4);\r
126 TemporaryRamBase = (UINTN)PcdGet32 (PcdCPUCoresStackBase) + PpiListSize;\r
127 TemporaryRamSize = (UINTN)PcdGet32 (PcdCPUCorePrimaryStackSize) - PpiListSize;\r
128\r
f598bf12 129 //\r
130 // Bind this information into the SEC hand-off state\r
131 // Note: this must be in sync with the stuff in the asm file\r
132 // Note also: HOBs (pei temp ram) MUST be above stack\r
133 //\r
134 SecCoreData.DataSize = sizeof(EFI_SEC_PEI_HAND_OFF);\r
f92b93c9 135 SecCoreData.BootFirmwareVolumeBase = (VOID *)(UINTN)PcdGet32 (PcdFvBaseAddress);\r
136 SecCoreData.BootFirmwareVolumeSize = PcdGet32 (PcdFvSize);\r
77de7e53 137 SecCoreData.TemporaryRamBase = (VOID *)TemporaryRamBase; // We run on the primary core (and so we use the first stack)\r
138 SecCoreData.TemporaryRamSize = TemporaryRamSize;\r
139 SecCoreData.PeiTemporaryRamBase = SecCoreData.TemporaryRamBase;\r
f598bf12 140 SecCoreData.PeiTemporaryRamSize = SecCoreData.TemporaryRamSize / 2;\r
93d451c6 141 SecCoreData.StackBase = (VOID *)((UINTN)(SecCoreData.TemporaryRamBase) + (SecCoreData.TemporaryRamSize/2));\r
142 SecCoreData.StackSize = SecCoreData.TemporaryRamSize / 2;\r
1d5d0ae9 143\r
f598bf12 144 // Jump to PEI core entry point\r
77de7e53 145 (PeiCoreEntryPoint)(&SecCoreData, PpiList);\r
1d5d0ae9 146}\r