]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | *\r | |
3 | * Copyright (c) 2011-2014, 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 | |
15 | #include <Library/ArmGicLib.h>\r | |
16 | \r | |
17 | #include <Ppi/ArmMpCoreInfo.h>\r | |
18 | \r | |
19 | #include "PrePeiCore.h"\r | |
20 | \r | |
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 | |
30 | VOID\r | |
31 | EFIAPI\r | |
32 | SecondaryMain (\r | |
33 | IN UINTN MpId\r | |
34 | )\r | |
35 | {\r | |
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 | UINTN AcknowledgeInterrupt;\r | |
49 | UINTN InterruptId;\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 | |
81 | \r | |
82 | // Clear Secondary cores MailBox\r | |
83 | MmioWrite32 (ArmCoreInfoTable[Index].MailboxClearAddress, ArmCoreInfoTable[Index].MailboxClearValue);\r | |
84 | \r | |
85 | do {\r | |
86 | ArmCallWFI ();\r | |
87 | \r | |
88 | // Read the Mailbox\r | |
89 | SecondaryEntryAddr = MmioRead32 (ArmCoreInfoTable[Index].MailboxGetAddress);\r | |
90 | \r | |
91 | // Acknowledge the interrupt and send End of Interrupt signal.\r | |
92 | AcknowledgeInterrupt = ArmGicAcknowledgeInterrupt (PcdGet64 (PcdGicInterruptInterfaceBase), &InterruptId);\r | |
93 | // Check if it is a valid interrupt ID\r | |
94 | if (InterruptId < ArmGicGetMaxNumInterrupts (PcdGet64 (PcdGicDistributorBase))) {\r | |
95 | // Got a valid SGI number hence signal End of Interrupt\r | |
96 | ArmGicEndOfInterrupt (PcdGet64 (PcdGicInterruptInterfaceBase), AcknowledgeInterrupt);\r | |
97 | }\r | |
98 | } while (SecondaryEntryAddr == 0);\r | |
99 | \r | |
100 | // Jump to secondary core entry point.\r | |
101 | SecondaryStart = (VOID (*)())SecondaryEntryAddr;\r | |
102 | SecondaryStart();\r | |
103 | \r | |
104 | // The secondaries shouldn't reach here\r | |
105 | ASSERT(FALSE);\r | |
106 | }\r | |
107 | \r | |
108 | VOID\r | |
109 | EFIAPI\r | |
110 | PrimaryMain (\r | |
111 | IN EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint\r | |
112 | )\r | |
113 | {\r | |
114 | EFI_SEC_PEI_HAND_OFF SecCoreData;\r | |
115 | UINTN PpiListSize;\r | |
116 | EFI_PEI_PPI_DESCRIPTOR *PpiList;\r | |
117 | UINTN TemporaryRamBase;\r | |
118 | UINTN TemporaryRamSize;\r | |
119 | \r | |
120 | CreatePpiList (&PpiListSize, &PpiList);\r | |
121 | \r | |
122 | // Enable the GIC Distributor\r | |
123 | ArmGicEnableDistributor (PcdGet64(PcdGicDistributorBase));\r | |
124 | \r | |
125 | // If ArmVe has not been built as Standalone then we need to wake up the secondary cores\r | |
126 | if (FeaturePcdGet (PcdSendSgiToBringUpSecondaryCores)) {\r | |
127 | // Sending SGI to all the Secondary CPU interfaces\r | |
128 | ArmGicSendSgiTo (PcdGet64(PcdGicDistributorBase), ARM_GIC_ICDSGIR_FILTER_EVERYONEELSE, 0x0E, PcdGet32 (PcdGicSgiIntId));\r | |
129 | }\r | |
130 | \r | |
131 | // Adjust the Temporary Ram as the new Ppi List (Common + Platform Ppi Lists) is created at\r | |
132 | // the base of the primary core stack\r | |
133 | PpiListSize = ALIGN_VALUE(PpiListSize, CPU_STACK_ALIGNMENT);\r | |
134 | TemporaryRamBase = (UINTN)PcdGet64 (PcdCPUCoresStackBase) + PpiListSize;\r | |
135 | TemporaryRamSize = (UINTN)PcdGet32 (PcdCPUCorePrimaryStackSize) - PpiListSize;\r | |
136 | \r | |
137 | //\r | |
138 | // Bind this information into the SEC hand-off state\r | |
139 | // Note: this must be in sync with the stuff in the asm file\r | |
140 | // Note also: HOBs (pei temp ram) MUST be above stack\r | |
141 | //\r | |
142 | SecCoreData.DataSize = sizeof(EFI_SEC_PEI_HAND_OFF);\r | |
143 | SecCoreData.BootFirmwareVolumeBase = (VOID *)(UINTN)PcdGet64 (PcdFvBaseAddress);\r | |
144 | SecCoreData.BootFirmwareVolumeSize = PcdGet32 (PcdFvSize);\r | |
145 | SecCoreData.TemporaryRamBase = (VOID *)TemporaryRamBase; // We run on the primary core (and so we use the first stack)\r | |
146 | SecCoreData.TemporaryRamSize = TemporaryRamSize;\r | |
147 | SecCoreData.PeiTemporaryRamBase = SecCoreData.TemporaryRamBase;\r | |
148 | SecCoreData.PeiTemporaryRamSize = ALIGN_VALUE (SecCoreData.TemporaryRamSize / 2, CPU_STACK_ALIGNMENT);\r | |
149 | SecCoreData.StackBase = (VOID *)((UINTN)SecCoreData.TemporaryRamBase + SecCoreData.PeiTemporaryRamSize);\r | |
150 | SecCoreData.StackSize = (TemporaryRamBase + TemporaryRamSize) - (UINTN)SecCoreData.StackBase;\r | |
151 | \r | |
152 | // Jump to PEI core entry point\r | |
153 | PeiCoreEntryPoint (&SecCoreData, PpiList);\r | |
154 | }\r |