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