]>
Commit | Line | Data |
---|---|---|
a36d531f MC |
1 | /** @file\r |
2 | *\r | |
3 | * Copyright (c) 2011-2013, ARM Limited. All rights reserved.\r | |
4 | * Copyright (c) 2014, Linaro Limited. All rights reserved.\r | |
5 | * Copyright (c) 2014, Red Hat, Inc.\r | |
6 | *\r | |
7 | *\r | |
8 | * This program and the accompanying materials\r | |
9 | * are licensed and made available under the terms and conditions of the BSD License\r | |
10 | * which accompanies this distribution. The full text of the license may be found at\r | |
11 | * http://opensource.org/licenses/bsd-license.php\r | |
12 | *\r | |
13 | * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
14 | * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
15 | *\r | |
16 | **/\r | |
17 | \r | |
18 | #include <Library/IoLib.h>\r | |
19 | #include <Library/ArmPlatformLib.h>\r | |
20 | #include <Library/DebugLib.h>\r | |
21 | #include <Library/PcdLib.h>\r | |
22 | #include <ArmPlatform.h>\r | |
23 | #include <libfdt.h>\r | |
24 | #include <Pi/PiBootMode.h>\r | |
25 | #include <Uefi/UefiBaseType.h>\r | |
26 | #include <Uefi/UefiMultiPhase.h>\r | |
a36d531f MC |
27 | \r |
28 | /**\r | |
29 | Return the current Boot Mode\r | |
30 | \r | |
31 | This function returns the boot reason on the platform\r | |
32 | \r | |
33 | @return Return the current Boot Mode of the platform\r | |
34 | \r | |
35 | **/\r | |
36 | EFI_BOOT_MODE\r | |
37 | ArmPlatformGetBootMode (\r | |
38 | VOID\r | |
39 | )\r | |
40 | {\r | |
41 | return BOOT_WITH_FULL_CONFIGURATION;\r | |
42 | }\r | |
43 | \r | |
44 | /**\r | |
45 | This function is called by PrePeiCore, in the SEC phase.\r | |
46 | **/\r | |
47 | RETURN_STATUS\r | |
48 | ArmPlatformInitialize (\r | |
49 | IN UINTN MpId\r | |
50 | )\r | |
51 | {\r | |
52 | //\r | |
53 | // We are relying on ArmPlatformInitializeSystemMemory () being called from\r | |
54 | // InitializeMemory (), which only occurs if the following feature is disabled\r | |
55 | //\r | |
56 | ASSERT (!FeaturePcdGet (PcdSystemMemoryInitializeInSec));\r | |
57 | return RETURN_SUCCESS;\r | |
58 | }\r | |
59 | \r | |
60 | /**\r | |
61 | Initialize the system (or sometimes called permanent) memory\r | |
62 | \r | |
63 | This memory is generally represented by the DRAM.\r | |
64 | \r | |
65 | This function is called from InitializeMemory() in MemoryInitPeim, in the PEI\r | |
66 | phase.\r | |
67 | **/\r | |
68 | VOID\r | |
69 | ArmPlatformInitializeSystemMemory (\r | |
70 | VOID\r | |
71 | )\r | |
72 | {\r | |
a9f63d69 LE |
73 | VOID *DeviceTreeBase;\r |
74 | INT32 Node, Prev;\r | |
75 | UINT64 NewBase, CurBase;\r | |
76 | UINT64 NewSize, CurSize;\r | |
77 | CONST CHAR8 *Type;\r | |
78 | INT32 Len;\r | |
79 | CONST UINT64 *RegProp;\r | |
80 | RETURN_STATUS PcdStatus;\r | |
a36d531f MC |
81 | \r |
82 | NewBase = 0;\r | |
83 | NewSize = 0;\r | |
84 | \r | |
ada518b7 | 85 | DeviceTreeBase = (VOID *)(UINTN)PcdGet64 (PcdDeviceTreeInitialBaseAddress);\r |
a36d531f MC |
86 | ASSERT (DeviceTreeBase != NULL);\r |
87 | \r | |
88 | //\r | |
89 | // Make sure we have a valid device tree blob\r | |
90 | //\r | |
91 | ASSERT (fdt_check_header (DeviceTreeBase) == 0);\r | |
92 | \r | |
93 | //\r | |
45f9bb91 | 94 | // Look for the lowest memory node\r |
a36d531f | 95 | //\r |
337d450e | 96 | for (Prev = 0;; Prev = Node) {\r |
a36d531f MC |
97 | Node = fdt_next_node (DeviceTreeBase, Prev, NULL);\r |
98 | if (Node < 0) {\r | |
99 | break;\r | |
100 | }\r | |
101 | \r | |
102 | //\r | |
103 | // Check for memory node\r | |
104 | //\r | |
105 | Type = fdt_getprop (DeviceTreeBase, Node, "device_type", &Len);\r | |
106 | if (Type && AsciiStrnCmp (Type, "memory", Len) == 0) {\r | |
107 | //\r | |
108 | // Get the 'reg' property of this node. For now, we will assume\r | |
109 | // two 8 byte quantities for base and size, respectively.\r | |
110 | //\r | |
111 | RegProp = fdt_getprop (DeviceTreeBase, Node, "reg", &Len);\r | |
112 | if (RegProp != 0 && Len == (2 * sizeof (UINT64))) {\r | |
113 | \r | |
45f9bb91 SZ |
114 | CurBase = fdt64_to_cpu (ReadUnaligned64 (RegProp));\r |
115 | CurSize = fdt64_to_cpu (ReadUnaligned64 (RegProp + 1));\r | |
a36d531f MC |
116 | \r |
117 | DEBUG ((EFI_D_INFO, "%a: System RAM @ 0x%lx - 0x%lx\n",\r | |
45f9bb91 SZ |
118 | __FUNCTION__, CurBase, CurBase + CurSize - 1));\r |
119 | \r | |
120 | if (NewBase > CurBase || NewBase == 0) {\r | |
121 | NewBase = CurBase;\r | |
122 | NewSize = CurSize;\r | |
123 | }\r | |
a36d531f MC |
124 | } else {\r |
125 | DEBUG ((EFI_D_ERROR, "%a: Failed to parse FDT memory node\n",\r | |
126 | __FUNCTION__));\r | |
127 | }\r | |
a36d531f MC |
128 | }\r |
129 | }\r | |
130 | \r | |
45f9bb91 SZ |
131 | //\r |
132 | // Make sure the start of DRAM matches our expectation\r | |
133 | //\r | |
134 | ASSERT (FixedPcdGet64 (PcdSystemMemoryBase) == NewBase);\r | |
a9f63d69 LE |
135 | PcdStatus = PcdSet64S (PcdSystemMemorySize, NewSize);\r |
136 | ASSERT_RETURN_ERROR (PcdStatus);\r | |
45f9bb91 | 137 | \r |
a36d531f MC |
138 | //\r |
139 | // We need to make sure that the machine we are running on has at least\r | |
140 | // 128 MB of memory configured, and is currently executing this binary from\r | |
141 | // NOR flash. This prevents a device tree image in DRAM from getting\r | |
142 | // clobbered when our caller installs permanent PEI RAM, before we have a\r | |
143 | // chance of marking its location as reserved or copy it to a freshly\r | |
144 | // allocated block in the permanent PEI RAM in the platform PEIM.\r | |
145 | //\r | |
146 | ASSERT (NewSize >= SIZE_128MB);\r | |
147 | ASSERT (\r | |
bb5420bb | 148 | (((UINT64)PcdGet64 (PcdFdBaseAddress) +\r |
a36d531f | 149 | (UINT64)PcdGet32 (PcdFdSize)) <= NewBase) ||\r |
bb5420bb | 150 | ((UINT64)PcdGet64 (PcdFdBaseAddress) >= (NewBase + NewSize)));\r |
a36d531f MC |
151 | }\r |
152 | \r | |
153 | VOID\r | |
154 | ArmPlatformGetPlatformPpiList (\r | |
155 | OUT UINTN *PpiListSize,\r | |
156 | OUT EFI_PEI_PPI_DESCRIPTOR **PpiList\r | |
157 | )\r | |
158 | {\r | |
159 | *PpiListSize = 0;\r | |
160 | *PpiList = NULL;\r | |
161 | }\r |