]>
Commit | Line | Data |
---|---|---|
a6caee65 | 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 | |
15 | #include <PiPei.h>\r | |
16 | \r | |
0787bc61 | 17 | #include <Library/ArmLib.h>\r |
55a0d64b | 18 | #include <Library/ArmGicLib.h>\r |
a6caee65 | 19 | #include <Library/DebugLib.h>\r |
20 | #include <Library/PcdLib.h>\r | |
21 | #include <Library/PrintLib.h>\r | |
22 | #include <Library/SerialPortLib.h>\r | |
a6caee65 | 23 | \r |
0787bc61 | 24 | #include <Chipset/ArmV7.h> |
a6caee65 | 25 | \r |
26 | // When the firmware is built as not Standalone, the secondary cores need to wait the firmware\r | |
27 | // entirely written into DRAM. It is the firmware from DRAM which will wake up the secondary cores.\r | |
28 | VOID\r | |
29 | NonSecureWaitForFirmware (\r | |
30 | VOID\r | |
31 | )\r | |
32 | {\r | |
33 | VOID (*secondary_start)(VOID);\r | |
34 | \r | |
35 | // The secondary cores will execute the firmware once wake from WFI.\r | |
36 | secondary_start = (VOID (*)())PcdGet32(PcdNormalFvBaseAddress);\r | |
37 | \r | |
38 | ArmCallWFI();\r | |
39 | \r | |
40 | // Acknowledge the interrupt and send End of Interrupt signal.\r | |
0787bc61 | 41 | ArmGicAcknowledgeSgiFrom (PcdGet32(PcdGicInterruptInterfaceBase), PRIMARY_CORE_ID);\r |
a6caee65 | 42 | \r |
43 | // Jump to secondary core entry point.\r | |
44 | secondary_start ();\r | |
45 | \r | |
46 | // PEI Core should always load and never return\r | |
47 | ASSERT (FALSE);\r | |
48 | }\r | |
49 | \r | |
50 | /**\r | |
51 | Call before jumping to Normal World\r | |
52 | \r | |
53 | This function allows the firmware platform to do extra actions before\r | |
54 | jumping to the Normal World\r | |
55 | \r | |
56 | **/\r | |
57 | VOID\r | |
58 | ArmPlatformSecExtraAction (\r | |
0787bc61 | 59 | IN UINTN MpId,\r |
a6caee65 | 60 | OUT UINTN* JumpAddress\r |
61 | )\r | |
62 | {\r | |
63 | CHAR8 Buffer[100];\r | |
64 | UINTN CharCount;\r | |
65 | \r | |
66 | if (FeaturePcdGet (PcdStandalone) == FALSE) {\r | |
0787bc61 | 67 | if (IS_PRIMARY_CORE(MpId)) {\r |
a6caee65 | 68 | UINTN* StartAddress = (UINTN*)PcdGet32(PcdNormalFvBaseAddress);\r |
69 | \r | |
70 | // Patch the DRAM to make an infinite loop at the start address\r | |
71 | *StartAddress = 0xEAFFFFFE; // opcode for while(1)\r | |
72 | \r | |
73 | CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Waiting for firmware at 0x%08X ...\n\r",StartAddress);\r | |
74 | SerialPortWrite ((UINT8 *) Buffer, CharCount);\r | |
75 | \r | |
76 | *JumpAddress = PcdGet32(PcdNormalFvBaseAddress);\r | |
77 | } else {\r | |
78 | // When the primary core is stopped by the hardware debugger to copy the firmware\r | |
79 | // into DRAM. The secondary cores are still running. As soon as the first bytes of\r | |
80 | // the firmware are written into DRAM, the secondary cores will start to execute the\r | |
81 | // code even if the firmware is not entirely written into the memory.\r | |
82 | // That's why the secondary cores need to be parked in WFI and wake up once the\r | |
83 | // firmware is ready.\r | |
84 | \r | |
85 | *JumpAddress = (UINTN)NonSecureWaitForFirmware;\r | |
86 | }\r | |
87 | } else if (FeaturePcdGet (PcdSystemMemoryInitializeInSec)) {\r | |
0787bc61 | 88 | if (IS_PRIMARY_CORE(MpId)) {\r |
a6caee65 | 89 | // Signal the secondary cores they can jump to PEI phase\r |
55a0d64b | 90 | ArmGicSendSgiTo (PcdGet32(PcdGicDistributorBase), ARM_GIC_ICDSGIR_FILTER_EVERYONEELSE, 0x0E);\r |
a6caee65 | 91 | \r |
92 | // To enter into Non Secure state, we need to make a return from exception\r | |
93 | *JumpAddress = PcdGet32(PcdNormalFvBaseAddress);\r | |
94 | } else {\r | |
95 | // We wait for the primary core to finish to initialize the System Memory. Otherwise the secondary\r | |
96 | // cores would make crash the system by setting their stacks in DRAM before the primary core has not\r | |
97 | // finished to initialize the system memory.\r | |
98 | *JumpAddress = (UINTN)NonSecureWaitForFirmware;\r | |
99 | }\r | |
100 | } else {\r | |
101 | *JumpAddress = PcdGet32(PcdNormalFvBaseAddress);\r | |
102 | }\r | |
103 | }\r |