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