1 | ␊ |
2 | /*␊ |
3 | * Copyright 2007 David F. Elliott.␉ All rights reserved.␊ |
4 | */␊ |
5 | ␊ |
6 | /*␊ |
7 | * Copyright 2010,2011 Cadet-petit Armel <armelcadetpetit@gmail.com>. All rights reserved.␊ |
8 | */␊ |
9 | ␊ |
10 | #include "libsaio.h"␊ |
11 | #include "bootstruct.h"␊ |
12 | #include "efi.h"␊ |
13 | #include "acpi.h"␊ |
14 | #include "fake_efi.h"␊ |
15 | #include "efi_tables.h"␊ |
16 | #include "platform.h"␊ |
17 | #include "device_inject.h"␊ |
18 | #include "convert.h"␊ |
19 | #include "pci.h"␊ |
20 | #include "sl.h"␊ |
21 | #include "modules.h"␊ |
22 | #include "vers.h"␊ |
23 | #include "smp-imps.h"␊ |
24 | ␊ |
25 | #ifndef DEBUG_EFI␊ |
26 | #define DEBUG_EFI 0␊ |
27 | #endif␊ |
28 | ␊ |
29 | #if DEBUG_EFI␊ |
30 | #define DBG(x...)␉printf(x)␊ |
31 | #else␊ |
32 | #define DBG(x...)␊ |
33 | #endif␊ |
34 | /*␊ |
35 | * Modern Darwin kernels require some amount of EFI because Apple machines all␊ |
36 | * have EFI. Modifying the kernel source to not require EFI is of course␊ |
37 | * possible but would have to be maintained as a separate patch because it is␊ |
38 | * unlikely that Apple wishes to add legacy support to their kernel.␊ |
39 | *␊ |
40 | * As you can see from the Apple-supplied code in bootstruct.c, it seems that␊ |
41 | * the intention was clearly to modify this booter to provide EFI-like structures␊ |
42 | * to the kernel rather than modifying the kernel to handle non-EFI stuff.␉ This␊ |
43 | * makes a lot of sense from an engineering point of view as it means the kernel␊ |
44 | * for the as yet unreleased EFI-only Macs could still be booted by the non-EFI␊ |
45 | * DTK systems so long as the kernel checked to ensure the boot tables were␊ |
46 | * filled in appropriately.␉ Modern xnu requires a system table and a runtime␊ |
47 | * services table and performs no checks whatsoever to ensure the pointers to␊ |
48 | * these tables are non-NULL.␉Therefore, any modern xnu kernel will page fault␊ |
49 | * early on in the boot process if the system table pointer is zero.␊ |
50 | *␊ |
51 | * Even before that happens, the tsc_init function in modern xnu requires the FSB␊ |
52 | * Frequency to be a property in the /efi/platform node of the device tree or else␊ |
53 | * it panics the bootstrap process very early on.␊ |
54 | *␊ |
55 | * As of this writing, the current implementation found here is good enough␊ |
56 | * to make the currently available xnu kernel boot without modification on a␊ |
57 | * system with an appropriate processor. With a minor source modification to␊ |
58 | * the tsc_init function to remove the explicit check for Core or Core 2␊ |
59 | * processors the kernel can be made to boot on other processors so long as␊ |
60 | * the code can be executed by the processor and the machine contains the␊ |
61 | * necessary hardware.␊ |
62 | */␊ |
63 | static inline char * mallocStringForGuid(EFI_GUID const *pGuid);␊ |
64 | static VOID EFI_ST_FIX_CRC32(void);␊ |
65 | static EFI_STATUS setupAcpiNoMod();␊ |
66 | static EFI_CHAR16* getSmbiosChar16(const char * key, size_t* len);␊ |
67 | static EFI_CHAR8* getSmbiosUUID();␊ |
68 | static int8_t *getSystemID();␊ |
69 | static VOID setupSystemType();␊ |
70 | static VOID setupEfiDeviceTree(void);␊ |
71 | static VOID setup_Smbios();␊ |
72 | static VOID setup_machine_signature();␊ |
73 | static VOID setupEfiConfigurationTable();␊ |
74 | ␊ |
75 | /*==========================================================================␊ |
76 | * Utility function to make a device tree string from an EFI_GUID␊ |
77 | */␊ |
78 | ␊ |
79 | static inline char * mallocStringForGuid(EFI_GUID const *pGuid)␊ |
80 | {␊ |
81 | ␉char *string = malloc(37);␊ |
82 | ␉efi_guid_unparse_upper(pGuid, string);␊ |
83 | ␉return string;␊ |
84 | }␊ |
85 | ␊ |
86 | /*==========================================================================␊ |
87 | * Function to map 32 bit physical address to 64 bit virtual address␊ |
88 | */␊ |
89 | ␊ |
90 | #define ptov64(addr) (uint64_t)((uint64_t)addr | 0xFFFFFF8000000000ULL)␊ |
91 | ␊ |
92 | /*==========================================================================␊ |
93 | * Fake EFI implementation␊ |
94 | */␊ |
95 | ␊ |
96 | static EFI_CHAR16 const FIRMWARE_VENDOR[] = {'A','p','p','l','e', 0}; ␊ |
97 | ␊ |
98 | /* Info About the current Firmware */␊ |
99 | #define FIRMWARE_MAINTENER "cparm, armelcadetpetit@gmail.com" ␊ |
100 | static EFI_CHAR16 const FIRMWARE_NAME[] = {'C','u','p','e','r','t','i','n','o', 0}; ␊ |
101 | static EFI_UINT32 const FIRMWARE_REVISION = 0x00010800; //1.8␊ |
102 | static EFI_UINT32 const DEVICE_SUPPORTED = 0x00000001;␊ |
103 | ␊ |
104 | /* Default platform system_id (fix by IntVar) */␊ |
105 | static EFI_CHAR8 const SYSTEM_ID[] = "0123456789ABCDEF"; //random value gen by uuidgen␊ |
106 | ␊ |
107 | /* Just a ret instruction */␊ |
108 | static uint8_t const VOIDRET_INSTRUCTIONS[] = {0xc3};␊ |
109 | ␊ |
110 | /* movl $0x80000003,%eax; ret */␊ |
111 | static uint8_t const UNSUPPORTEDRET_INSTRUCTIONS[] = {0xb8, 0x03, 0x00, 0x00, 0x80, 0xc3};␊ |
112 | ␊ |
113 | EFI_SYSTEM_TABLE_32 *gST32 = NULL;␊ |
114 | EFI_SYSTEM_TABLE_64 *gST64 = NULL;␊ |
115 | Node *gEfiConfigurationTableNode = NULL;␊ |
116 | ␊ |
117 | /* From Foundation/Efi/Guid/Smbios/SmBios.h */␊ |
118 | /* Modified to wrap Data4 array init with {} */␊ |
119 | #define EFI_SMBIOS_TABLE_GUID {0xeb9d2d31, 0x2d88, 0x11d3, {0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d}}␊ |
120 | ␊ |
121 | #define EFI_ACPI_TABLE_GUID \␊ |
122 | { \␊ |
123 | 0xeb9d2d30, 0x2d88, 0x11d3, { 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d } \␊ |
124 | }␊ |
125 | ␊ |
126 | #define EFI_ACPI_20_TABLE_GUID \␊ |
127 | { \␊ |
128 | 0x8868e871, 0xe4f1, 0x11d3, { 0xbc, 0x22, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } \␊ |
129 | }␊ |
130 | ␊ |
131 | #define EFI_MPS_TABLE_GUID \␊ |
132 | { \␊ |
133 | 0xeb9d2d2f,0x2d88,0x11d3,{0x9a,0x16,0x0,0x90,0x27,0x3f,0xc1,0x4d} \␊ |
134 | }␊ |
135 | /* From Foundation/Efi/Guid/Smbios/SmBios.c */␊ |
136 | EFI_GUID const␉gEfiSmbiosTableGuid = EFI_SMBIOS_TABLE_GUID;␊ |
137 | ␊ |
138 | EFI_GUID gEfiAcpiTableGuid = EFI_ACPI_TABLE_GUID;␊ |
139 | EFI_GUID gEfiAcpi20TableGuid = EFI_ACPI_20_TABLE_GUID;␊ |
140 | EFI_GUID gEfiMpsTableGuid = EFI_MPS_TABLE_GUID;␊ |
141 | ␊ |
142 | EFI_UINT32 gNumTables32 = 0;␊ |
143 | EFI_UINT64 gNumTables64 = 0;␊ |
144 | EFI_CONFIGURATION_TABLE_32 gEfiConfigurationTable32[MAX_CONFIGURATION_TABLE_ENTRIES];␊ |
145 | EFI_CONFIGURATION_TABLE_64 gEfiConfigurationTable64[MAX_CONFIGURATION_TABLE_ENTRIES];␊ |
146 | extern EFI_STATUS addConfigurationTable(EFI_GUID const *pGuid, void *table, char const *alias)␊ |
147 | {␊ |
148 | ␉EFI_UINTN i = 0;␊ |
149 | ␉␊ |
150 | if (pGuid == NULL || table == NULL)␊ |
151 | ␉␉return EFI_INVALID_PARAMETER;␊ |
152 | ␊ |
153 | ␉//Azi: as is, cpu's with em64t will use EFI64 on pre 10.6 systems,␊ |
154 | ␉// wich seems to cause no problem. In case it does, force i386 arch.␊ |
155 | ␉if (archCpuType == CPU_TYPE_I386)␊ |
156 | ␉{␊ |
157 | ␉␉i = gNumTables32;␊ |
158 | ␉}␊ |
159 | ␉else␊ |
160 | ␉{␊ |
161 | ␉␉i = (EFI_UINTN)gNumTables64;␊ |
162 | ␉}␊ |
163 | ␉␊ |
164 | ␉// We only do adds, not modifications and deletes like InstallConfigurationTable␊ |
165 | ␉if (i >= MAX_CONFIGURATION_TABLE_ENTRIES)␊ |
166 | ␉{␊ |
167 | ␊ |
168 | ␉␉␊ |
169 | printf("Ran out of space for configuration tables (max = %d). Please, increase the reserved size in the code.\n", (int)MAX_CONFIGURATION_TABLE_ENTRIES);␊ |
170 | return EFI_ABORTED;␊ |
171 | } ␊ |
172 | ␊ |
173 | if (archCpuType == CPU_TYPE_I386)␊ |
174 | ␉{ ␊ |
175 | ␊ |
176 | gEfiConfigurationTable32[i].VendorGuid = *pGuid;␊ |
177 | gEfiConfigurationTable32[i].VendorTable = (EFI_PTR32)table;␊ |
178 | ␊ |
179 | ␉␉gNumTables32++;␊ |
180 | ␉}␊ |
181 | ␉else␊ |
182 | ␉{ ␊ |
183 | gEfiConfigurationTable64[i].VendorGuid = *pGuid;␊ |
184 | gEfiConfigurationTable64[i].VendorTable = (EFI_PTR32)table;␊ |
185 | ␉␉gNumTables64++ ;␊ |
186 | ␉} ␊ |
187 | ␉␊ |
188 | Node *tableNode = DT__AddChild(gEfiConfigurationTableNode, mallocStringForGuid(pGuid));␊ |
189 | ␊ |
190 | // Use the pointer to the GUID we just stuffed into the system table␊ |
191 | DT__AddProperty(tableNode, "guid", sizeof(EFI_GUID), (void*)pGuid);␊ |
192 | ␊ |
193 | // The "table" property is the 32-bit (in our implementation) physical address of the table␊ |
194 | DT__AddProperty(tableNode, "table", sizeof(void*) * 2, table);␊ |
195 | ␊ |
196 | // Assume the alias pointer is a global or static piece of data␊ |
197 | if (alias != NULL)␊ |
198 | DT__AddProperty(tableNode, "alias", strlen(alias)+1, (char*)alias);␊ |
199 | ␊ |
200 | return EFI_SUCCESS;␊ |
201 | ␉␊ |
202 | }␊ |
203 | ␊ |
204 | static VOID EFI_ST_FIX_CRC32(void)␊ |
205 | {␊ |
206 | ␉if (archCpuType == CPU_TYPE_I386)␊ |
207 | ␉{␊ |
208 | ␉␉gST32->Hdr.CRC32 = 0;␊ |
209 | ␉␉gST32->Hdr.CRC32 = crc32(0L, gST32, gST32->Hdr.HeaderSize);␊ |
210 | ␉}␊ |
211 | ␉else␊ |
212 | ␉{␊ |
213 | ␉␉gST64->Hdr.CRC32 = 0;␊ |
214 | ␉␉gST64->Hdr.CRC32 = crc32(0L, gST64, gST64->Hdr.HeaderSize);␊ |
215 | ␉}␊ |
216 | }␊ |
217 | ␊ |
218 | void finalizeEFIConfigTable(void )␊ |
219 | { ␊ |
220 | if (archCpuType == CPU_TYPE_I386)␊ |
221 | ␉{␊ |
222 | ␉␉EFI_SYSTEM_TABLE_32 *efiSystemTable = gST32; ␊ |
223 | ␊ |
224 | efiSystemTable->NumberOfTableEntries = gNumTables32; ␊ |
225 | efiSystemTable->ConfigurationTable = (EFI_PTR32)gEfiConfigurationTable32;␊ |
226 | ␊ |
227 | ␉}␊ |
228 | ␉else␊ |
229 | ␉{␊ |
230 | ␉␉EFI_SYSTEM_TABLE_64 *efiSystemTable = gST64; ␊ |
231 | ␊ |
232 | efiSystemTable->NumberOfTableEntries = gNumTables64; ␊ |
233 | efiSystemTable->ConfigurationTable = ptov64((EFI_PTR32)gEfiConfigurationTable64); ␊ |
234 | ␊ |
235 | ␉}␊ |
236 | EFI_ST_FIX_CRC32();␊ |
237 | ␊ |
238 | #if DEBUG_EFI␊ |
239 | EFI_UINTN i;␊ |
240 | EFI_UINTN num = 0;␊ |
241 | uint32_t table ;␊ |
242 | EFI_GUID Guid;␊ |
243 | ␊ |
244 | if (archCpuType == CPU_TYPE_I386)␊ |
245 | ␉{␊ |
246 | ␉␉num = gST32->NumberOfTableEntries; ␊ |
247 | ␊ |
248 | ␉}␊ |
249 | ␉else␊ |
250 | ␉{␊ |
251 | ␉␉num = (EFI_UINTN)gST64->NumberOfTableEntries; ␊ |
252 | ␊ |
253 | ␉}␊ |
254 | ␉msglog("EFI Configuration table :\n");␊ |
255 | for (i=0; i<num; i++)␊ |
256 | ␉{␊ |
257 | if (archCpuType == CPU_TYPE_I386)␊ |
258 | {␊ |
259 | table = gEfiConfigurationTable32[i].VendorTable;␊ |
260 | Guid = gEfiConfigurationTable32[i].VendorGuid;␊ |
261 | ␊ |
262 | }␊ |
263 | else␊ |
264 | {␊ |
265 | table = gEfiConfigurationTable64[i].VendorTable;␊ |
266 | Guid = gEfiConfigurationTable64[i].VendorGuid;␊ |
267 | ␊ |
268 | }␊ |
269 | char id[5];␊ |
270 | bzero(id,sizeof(id)); ␊ |
271 | if (memcmp(&Guid, &gEfiSmbiosTableGuid, sizeof(EFI_GUID)) == 0)␊ |
272 | ␉␉{␊ |
273 | sprintf(id, "%s", "_SM_");␊ |
274 | }␊ |
275 | ␉␉else if (memcmp(&Guid, &gEfiAcpiTableGuid, sizeof(EFI_GUID)) == 0)␊ |
276 | ␉␉{␊ |
277 | sprintf(id, "%s", "RSD1");␊ |
278 | }␊ |
279 | ␉␉else if (memcmp(&Guid, &gEfiAcpi20TableGuid, sizeof(EFI_GUID)) == 0)␊ |
280 | ␉␉{␊ |
281 | sprintf(id, "%s", "RSD2");␊ |
282 | }␊ |
283 | ␉␉else if (memcmp(&Guid, &gEfiMpsTableGuid, sizeof(EFI_GUID)) == 0)␊ |
284 | ␉␉{␊ |
285 | sprintf(id, "%s", "_MP_");␊ |
286 | } ␊ |
287 | ␉␉␊ |
288 | msglog("table [%d]:%s , 32Bit addr : 0x%x\n",i,id,table);␊ |
289 | ␊ |
290 | }␊ |
291 | msglog("\n");␊ |
292 | #endif␊ |
293 | ␊ |
294 | }␊ |
295 | ␊ |
296 | /*␊ |
297 | * What we do here is simply allocate a fake EFI system table and a fake EFI␊ |
298 | * runtime services table.␊ |
299 | *␊ |
300 | * Because we build against modern headers with kBootArgsRevision 4 we␊ |
301 | * also take care to set efiMode = 32.␊ |
302 | */␊ |
303 | ␊ |
304 | ␊ |
305 | #define pto(mode, addr) (mode == 64) ? ptov64((EFI_PTR32)addr) : (EFI_PTR32)addr␊ |
306 | ␊ |
307 | #define setupEfiTables(mode) \␊ |
308 | { \␊ |
309 | struct fake_efi_pages \␊ |
310 | {\␊ |
311 | /* We use the fake_efi_pages struct so that we only need to do one kernel␊ |
312 | * memory allocation for all needed EFI data. Otherwise, small allocations␊ |
313 | * like the FIRMWARE_VENDOR string would take up an entire page.␊ |
314 | * NOTE WELL: Do NOT assume this struct has any particular layout within itself.␊ |
315 | * It is absolutely not intended to be publicly exposed anywhere␊ |
316 | * We say pages (plural) although right now we are well within the 1 page size␊ |
317 | * and probably will stay that way.␊ |
318 | */\␊ |
319 | EFI_SYSTEM_TABLE_##mode efiSystemTable;\␊ |
320 | EFI_RUNTIME_SERVICES_##mode efiRuntimeServices;\␊ |
321 | EFI_CONFIGURATION_TABLE_##mode efiConfigurationTable[MAX_CONFIGURATION_TABLE_ENTRIES];\␊ |
322 | EFI_CHAR16 firmwareVendor[sizeof(FIRMWARE_VENDOR)/sizeof(EFI_CHAR16)];\␊ |
323 | uint8_t voidret_instructions[sizeof(VOIDRET_INSTRUCTIONS)/sizeof(uint8_t)];\␊ |
324 | uint8_t unsupportedret_instructions[sizeof(UNSUPPORTEDRET_INSTRUCTIONS)/sizeof(uint8_t)];\␊ |
325 | };\␊ |
326 | struct fake_efi_pages *fakeEfiPages = (struct fake_efi_pages*)AllocateKernelMemory(sizeof(struct fake_efi_pages));\␊ |
327 | /* Zero out all the tables in case fields are added later*/\␊ |
328 | bzero(fakeEfiPages, sizeof(struct fake_efi_pages));\␊ |
329 | /*--------------------------------------------------------------------␊ |
330 | * Initialize some machine code that will return EFI_UNSUPPORTED for␊ |
331 | * functions returning int and simply return for void functions.*/\␊ |
332 | memcpy(fakeEfiPages->voidret_instructions, VOIDRET_INSTRUCTIONS, sizeof(VOIDRET_INSTRUCTIONS));\␊ |
333 | memcpy(fakeEfiPages->unsupportedret_instructions, UNSUPPORTEDRET_INSTRUCTIONS, sizeof(UNSUPPORTEDRET_INSTRUCTIONS));\␊ |
334 | /*--------------------------------------------------------------------␊ |
335 | * System table*/\␊ |
336 | EFI_SYSTEM_TABLE_##mode *efiSystemTable = gST##mode = &fakeEfiPages->efiSystemTable;\␊ |
337 | efiSystemTable->Hdr.Signature = EFI_SYSTEM_TABLE_SIGNATURE;\␊ |
338 | efiSystemTable->Hdr.Revision = EFI_SYSTEM_TABLE_REVISION;\␊ |
339 | efiSystemTable->Hdr.HeaderSize = sizeof(EFI_SYSTEM_TABLE_##mode);\␊ |
340 | efiSystemTable->Hdr.CRC32 = 0;/*Initialize to zero and then do CRC32*/ \␊ |
341 | efiSystemTable->Hdr.Reserved = 0;\␊ |
342 | efiSystemTable->FirmwareVendor = pto(mode, &fakeEfiPages->firmwareVendor);\␊ |
343 | memcpy(fakeEfiPages->firmwareVendor, FIRMWARE_VENDOR, sizeof(FIRMWARE_VENDOR));\␊ |
344 | efiSystemTable->FirmwareRevision = FIRMWARE_REVISION;\␊ |
345 | /* XXX: We may need to have basic implementations of ConIn/ConOut/StdErr␊ |
346 | * The EFI spec states that all handles are invalid after boot services have been␊ |
347 | * exited so we can probably get by with leaving the handles as zero.␊ |
348 | */\␊ |
349 | efiSystemTable->ConsoleInHandle = 0;\␊ |
350 | efiSystemTable->ConIn = 0;\␊ |
351 | efiSystemTable->ConsoleOutHandle = 0;\␊ |
352 | efiSystemTable->ConOut = 0;\␊ |
353 | efiSystemTable->StandardErrorHandle = 0;\␊ |
354 | efiSystemTable->StdErr = 0;\␊ |
355 | efiSystemTable->RuntimeServices = pto(mode,&fakeEfiPages->efiRuntimeServices) ;\␊ |
356 | /* According to the EFI spec, BootServices aren't valid after the␊ |
357 | * boot process is exited so we can probably do without it.␊ |
358 | * Apple didn't provide a definition for it in pexpert/i386/efi.h␊ |
359 | * so I'm guessing they don't use it.␊ |
360 | */\␊ |
361 | efiSystemTable->BootServices = 0;\␊ |
362 | efiSystemTable->NumberOfTableEntries = 0;\␊ |
363 | efiSystemTable->ConfigurationTable = pto(mode,fakeEfiPages->efiConfigurationTable);\␊ |
364 | /* We're done. Now CRC32 the thing so the kernel will accept it.␊ |
365 | * Must be initialized to zero before CRC32, done above.␊ |
366 | */\␊ |
367 | gST##mode->Hdr.CRC32 = crc32(0L, gST##mode, gST##mode->Hdr.HeaderSize);\␊ |
368 | /*--------------------------------------------------------------------␊ |
369 | * Runtime services*/\␊ |
370 | EFI_RUNTIME_SERVICES_##mode *efiRuntimeServices = &fakeEfiPages->efiRuntimeServices;\␊ |
371 | efiRuntimeServices->Hdr.Signature = EFI_RUNTIME_SERVICES_SIGNATURE;\␊ |
372 | efiRuntimeServices->Hdr.Revision = EFI_RUNTIME_SERVICES_REVISION;\␊ |
373 | efiRuntimeServices->Hdr.HeaderSize = sizeof(EFI_RUNTIME_SERVICES_##mode);\␊ |
374 | efiRuntimeServices->Hdr.CRC32 = 0;\␊ |
375 | efiRuntimeServices->Hdr.Reserved = 0;\␊ |
376 | /* There are a number of function pointers in the efiRuntimeServices table.␊ |
377 | * These are the Foundation (e.g. core) services and are expected to be present on␊ |
378 | * all EFI-compliant machines.␉Some kernel extensions (notably AppleEFIRuntime)␊ |
379 | * will call these without checking to see if they are null.␊ |
380 | *␊ |
381 | * We don't really feel like doing an EFI implementation in the bootloader␊ |
382 | * but it is nice if we can at least prevent a complete crash by␊ |
383 | * at least providing some sort of implementation until one can be provided␊ |
384 | * nicely in a kext.␊ |
385 | */\␊ |
386 | void (*voidret_fp)() = (void*)fakeEfiPages->voidret_instructions;\␊ |
387 | void (*unsupportedret_fp)() = (void*)fakeEfiPages->unsupportedret_instructions;\␊ |
388 | efiRuntimeServices->GetTime = pto(mode,unsupportedret_fp);\␊ |
389 | efiRuntimeServices->SetTime = pto(mode,unsupportedret_fp);\␊ |
390 | efiRuntimeServices->GetWakeupTime = pto(mode,unsupportedret_fp);\␊ |
391 | efiRuntimeServices->SetWakeupTime = pto(mode,unsupportedret_fp);\␊ |
392 | efiRuntimeServices->SetVirtualAddressMap = pto(mode,unsupportedret_fp);\␊ |
393 | efiRuntimeServices->ConvertPointer = pto(mode,unsupportedret_fp);\␊ |
394 | efiRuntimeServices->GetVariable = pto(mode,unsupportedret_fp);\␊ |
395 | efiRuntimeServices->GetNextVariableName = pto(mode,unsupportedret_fp);\␊ |
396 | efiRuntimeServices->SetVariable = pto(mode,unsupportedret_fp);\␊ |
397 | efiRuntimeServices->GetNextHighMonotonicCount = pto(mode,unsupportedret_fp);\␊ |
398 | efiRuntimeServices->ResetSystem = pto(mode,voidret_fp);\␊ |
399 | /*We're done.␉Now CRC32 the thing so the kernel will accept it*/\␊ |
400 | efiRuntimeServices->Hdr.CRC32 = crc32(0L, efiRuntimeServices, efiRuntimeServices->Hdr.HeaderSize);\␊ |
401 | /*--------------------------------------------------------------------␊ |
402 | * Finish filling in the rest of the boot args that we need.*/\␊ |
403 | bootArgs->efiSystemTable = (uint32_t)efiSystemTable;\␊ |
404 | bootArgs->efiMode = kBootArgsEfiMode##mode;\␊ |
405 | /* The bootArgs structure as a whole is bzero'd so we don't need to fill in␊ |
406 | * things like efiRuntimeServices* and what not.␊ |
407 | *␊ |
408 | * In fact, the only code that seems to use that is the hibernate code so it␊ |
409 | * knows not to save the pages.␉ It even checks to make sure its nonzero.␊ |
410 | */\␊ |
411 | }␊ |
412 | ␊ |
413 | /*␊ |
414 | * In addition to the EFI tables there is also the EFI device tree node.␊ |
415 | * In particular, we need /efi/platform to have an FSBFrequency key. Without it,␊ |
416 | * the tsc_init function will panic very early on in kernel startup, before␊ |
417 | * the console is available.␊ |
418 | */␊ |
419 | ␊ |
420 | /*==========================================================================␊ |
421 | * FSB Frequency detection␊ |
422 | */␊ |
423 | ␊ |
424 | /* These should be const but DT__AddProperty takes char* */␊ |
425 | #if UNUSED␊ |
426 | static const char const TSC_Frequency_prop[] = "TSCFrequency";␊ |
427 | static const char const CPU_Frequency_prop[] = "CPUFrequency";␊ |
428 | #endif␊ |
429 | static const char const FSB_Frequency_prop[] = "FSBFrequency";␊ |
430 | ␊ |
431 | /*==========================================================================␊ |
432 | * SMBIOS␊ |
433 | */␊ |
434 | ␊ |
435 | static uint64_t smbios_p;␊ |
436 | ␊ |
437 | void Register_Smbios_Efi(void* smbios)␊ |
438 | {␊ |
439 | smbios_p = ((uint64_t)((uint32_t)smbios));␉␊ |
440 | }␊ |
441 | ␊ |
442 | /*==========================================================================␊ |
443 | * ACPI ␊ |
444 | */␊ |
445 | ␊ |
446 | static uint64_t local_rsd_p;␊ |
447 | static ACPI_TABLES acpi_tables;␊ |
448 | static uint64_t kFSBFrequency;␊ |
449 | static uint32_t␉␉kHardware_signature;␊ |
450 | static uint8_t␉␉kType;␊ |
451 | static uint32_t␉␉kAdler32;␊ |
452 | ␊ |
453 | EFI_STATUS Register_Acpi_Efi(void* rsd_p, unsigned char rev )␊ |
454 | {␊ |
455 | ␉EFI_STATUS Status = EFI_UNSUPPORTED;␊ |
456 | ␉local_rsd_p = ((U64)((U32)rsd_p));␊ |
457 | ␊ |
458 | ␉if (local_rsd_p) {␊ |
459 | ␉␉if (rev == 2)␊ |
460 | ␉␉{␊ |
461 | ␉␉␉Status = addConfigurationTable(&gEfiAcpi20TableGuid, &local_rsd_p, "ACPI_20");␊ |
462 | ␉␉}␊ |
463 | ␉␉else␊ |
464 | ␉␉{␊ |
465 | ␉␉␉Status = addConfigurationTable(&gEfiAcpiTableGuid, &local_rsd_p, "ACPI");␉␉␉␊ |
466 | ␉␉}␊ |
467 | ␉}␉␉␊ |
468 | ␉␊ |
469 | ␉return Status;␉␊ |
470 | }␊ |
471 | ␊ |
472 | /* Setup ACPI without any patch. */␊ |
473 | static EFI_STATUS setupAcpiNoMod()␊ |
474 | { ␉␊ |
475 | ␉EFI_STATUS ret = EFI_UNSUPPORTED;␊ |
476 | ␉␊ |
477 | ACPI_TABLE_RSDP* rsdp = (ACPI_TABLE_RSDP*)((uint32_t)local_rsd_p);␊ |
478 | if(rsdp->Revision > 0 && (GetChecksum(rsdp, sizeof(ACPI_TABLE_RSDP)) == 0))␊ |
479 | ␉{␊ |
480 | ␉␉ret = addConfigurationTable(&gEfiAcpi20TableGuid, &local_rsd_p, "ACPI_20");␉␉ ␊ |
481 | ␉}␊ |
482 | ␉else␊ |
483 | ␉{␊ |
484 | ␉␉ret = addConfigurationTable(&gEfiAcpiTableGuid, &local_rsd_p, "ACPI");␉␉␊ |
485 | ␉}␊ |
486 | ␉␊ |
487 | ␉return ret;␊ |
488 | }␊ |
489 | ␊ |
490 | EFI_STATUS setup_acpi (void)␊ |
491 | {␉␊ |
492 | ␉EFI_STATUS ret = EFI_UNSUPPORTED;␉␊ |
493 | ␉␊ |
494 | ␉do {␊ |
495 | if (!FindAcpiTables(&acpi_tables))␊ |
496 | {␊ |
497 | printf("Failed to detect ACPI tables.\n");␊ |
498 | ret = EFI_NOT_FOUND;␊ |
499 | break;␊ |
500 | }␊ |
501 | ␊ |
502 | local_rsd_p = ((uint64_t)((uint32_t)acpi_tables.RsdPointer));␊ |
503 | ␊ |
504 | {␊ |
505 | ACPI_TABLE_FADT *FacpPointer = (acpi_tables.FacpPointer64 != (void*)0ul) ? (ACPI_TABLE_FADT *)acpi_tables.FacpPointer64 : (ACPI_TABLE_FADT *)acpi_tables.FacpPointer;␊ |
506 | ␊ |
507 | uint8_t type = FacpPointer->PreferredProfile;␊ |
508 | if (type <= MaxSupportedPMProfile) ␊ |
509 | safe_set_env(envType,type);␊ |
510 | } ␊ |
511 | ␊ |
512 | ret = setupAcpiNoMod();␊ |
513 | ␉␉␊ |
514 | ␉} while (0);␉␊ |
515 | ␉␊ |
516 | ␉return ret;␉␊ |
517 | ␉␊ |
518 | }␊ |
519 | ␊ |
520 | /*==========================================================================␊ |
521 | * Fake EFI implementation␊ |
522 | */␊ |
523 | ␊ |
524 | /* These should be const but DT__AddProperty takes char* */␊ |
525 | static const char const FIRMWARE_REVISION_PROP[] = "firmware-revision";␊ |
526 | static const char const FIRMWARE_ABI_PROP[] = "firmware-abi";␊ |
527 | static const char const FIRMWARE_VENDOR_PROP[] = "firmware-vendor";␊ |
528 | static const char const FIRMWARE_NAME_PROP[] = "firmware-name";␊ |
529 | static const char const FIRMWARE_DATE_PROP[] = "firmware-date";␊ |
530 | static const char const FIRMWARE_DEV_PROP[] = "firmware-maintener";␊ |
531 | static const char const FIRMWARE_PUBLISH_PROP[] = "firmware-publisher";␊ |
532 | ␊ |
533 | ␊ |
534 | static const char const FIRMWARE_ABI_32_PROP_VALUE[] = "EFI32";␊ |
535 | static const char const FIRMWARE_ABI_64_PROP_VALUE[] = "EFI64";␊ |
536 | static const char const SYSTEM_ID_PROP[] = "system-id";␊ |
537 | static const char const SYSTEM_SERIAL_PROP[] = "SystemSerialNumber";␊ |
538 | static const char const SYSTEM_TYPE_PROP[] = "system-type";␊ |
539 | static const char const MODEL_PROP[] = "Model";␊ |
540 | static const char const MOTHERBOARD_NAME_PROP[] = "motherboard-name";␊ |
541 | ␊ |
542 | ␊ |
543 | /*␊ |
544 | * Get an smbios option string option to convert to EFI_CHAR16 string␊ |
545 | */␊ |
546 | ␊ |
547 | static EFI_CHAR16* getSmbiosChar16(const char * key, size_t* len)␊ |
548 | {␊ |
549 | ␉if (!GetgPlatformName() && strcmp(key, "SMproductname") == 0)␊ |
550 | ␉␉readSMBIOS(thePlatformName);␊ |
551 | ␉␊ |
552 | ␉const char␉*PlatformName = GetgPlatformName() ;␊ |
553 | ␉␊ |
554 | ␉const char␉*src = (strcmp(key, "SMproductname") == 0) ? PlatformName : getStringForKey(key, DEFAULT_SMBIOS_CONFIG);␊ |
555 | ␉␊ |
556 | ␉EFI_CHAR16*␉ dst = 0;␉␊ |
557 | ␉␊ |
558 | ␉if (!key || !(*key) || !src) return 0;␊ |
559 | ␉␊ |
560 | ␉*len = strlen(src);␊ |
561 | ␉dst = (EFI_CHAR16*) malloc( ((*len)+1) * 2 );␊ |
562 | ␉{␊ |
563 | ␉␉size_t␉␉ i = 0;␊ |
564 | ␉␉for (; i < (*len); i++)␉ dst[i] = src[i];␊ |
565 | ␉}␊ |
566 | ␉dst[(*len)] = '\0';␊ |
567 | ␉*len = ((*len)+1)*2; // return the CHAR16 bufsize in cluding zero terminated CHAR16␊ |
568 | ␉return dst;␊ |
569 | }␊ |
570 | ␊ |
571 | /*␊ |
572 | * Get the SystemID from the bios dmi info␊ |
573 | */␊ |
574 | ␊ |
575 | static EFI_CHAR8* getSmbiosUUID()␊ |
576 | {␊ |
577 | ␉static EFI_CHAR8␉␉ uuid[UUID_LEN];␊ |
578 | ␉int␉␉␉␉␉␉ i, isZero, isOnes;␊ |
579 | ␉SMBByte␉␉␉␉␉*p;␉␉␊ |
580 | ␉␊ |
581 | p = (SMBByte*)(uint32_t)get_env(envUUID);␊ |
582 | ␊ |
583 | if ( p == NULL )␊ |
584 | ␉{␊ |
585 | DBG("No patched UUID found, fallback to original UUID (if exist) \n");␊ |
586 | ␉␉␊ |
587 | readSMBIOS(theUUID);␉␉␊ |
588 | p = (SMBByte*)(uint32_t)get_env(envUUID);␊ |
589 | ␊ |
590 | }␊ |
591 | ␊ |
592 | ␉for (i=0, isZero=1, isOnes=1; i<UUID_LEN; i++)␊ |
593 | ␉{␊ |
594 | ␉␉if (p[i] != 0x00) isZero = 0;␊ |
595 | ␉␉if (p[i] != 0xff) isOnes = 0;␊ |
596 | ␉}␊ |
597 | ␉␊ |
598 | ␉if (isZero || isOnes) // empty or setable means: no uuid present␊ |
599 | ␉{␊ |
600 | ␉␉verbose("No UUID present in SMBIOS System Information Table\n");␊ |
601 | ␉␉return 0;␊ |
602 | ␉} ␊ |
603 | #if DEBUG_EFI␊ |
604 | ␉else␊ |
605 | ␉␉verbose("Found UUID in SMBIOS System Information Table\n");␊ |
606 | #endif␊ |
607 | ␉␊ |
608 | ␉memcpy(uuid, p, UUID_LEN);␊ |
609 | ␉return uuid;␊ |
610 | }␊ |
611 | ␊ |
612 | /*␊ |
613 | * return a binary UUID value from the overriden SystemID and SMUUID if found, ␊ |
614 | * or from the bios if not, or from a fixed value if no bios value is found ␊ |
615 | */␊ |
616 | ␊ |
617 | static int8_t *getSystemID()␊ |
618 | {␊ |
619 | static int8_t␉␉␉␉sysid[16];␊ |
620 | ␉// unable to determine UUID for host. Error: 35 fix␊ |
621 | ␉// Rek: new SMsystemid option conforming to smbios notation standards, this option should␊ |
622 | ␉// belong to smbios config only ...␊ |
623 | ␉EFI_CHAR8*␉ret = getUUIDFromString(getStringForKey(kSystemID, DEFAULT_BOOT_CONFIG));␊ |
624 | ␉␊ |
625 | ␉if (!ret) // try bios dmi info UUID extraction␉␊ |
626 | ␉␉ret = getSmbiosUUID();␊ |
627 | ␉␊ |
628 | ␉if (!ret)␊ |
629 | ␉{␊ |
630 | ␉␉// no bios dmi UUID available, set a fixed value for system-id␊ |
631 | ␉␉ret=getUUIDFromString((const char*) SYSTEM_ID);␊ |
632 | ␉␉verbose("Customizing SystemID with : %s\n", getStringFromUUID(ret)); // apply a nice formatting to the displayed output␊ |
633 | ␉}␊ |
634 | ␉else␉␊ |
635 | ␉{␊ |
636 | ␉␉const char *mac = getStringFromUUID(ret);␊ |
637 | ␉␉verbose("MAC address : %c%c:%c%c:%c%c:%c%c:%c%c:%c%c\n",mac[24],mac[25],mac[26],mac[27],mac[28],mac[29]␊ |
638 | ␉␉␉␉,mac[30],mac[31],mac[32],mac[33],mac[34],mac[35]);␉␉ ␊ |
639 | ␉␉␊ |
640 | ␉}␊ |
641 | ␉␊ |
642 | ␉if (ret)␊ |
643 | ␉{ ␊ |
644 | ␉␉memcpy(sysid, ret, UUID_LEN);␊ |
645 | set_env_copy(envSysId, sysid, sizeof(sysid));␊ |
646 | ␉}␊ |
647 | ␉␊ |
648 | ␉return sysid;␊ |
649 | }␊ |
650 | ␊ |
651 | /*␊ |
652 | * Must be called AFTER setup Acpi because we need to take care of correct␊ |
653 | * facp content to reflect in ioregs␊ |
654 | */␊ |
655 | ␊ |
656 | static VOID setupSystemType()␊ |
657 | {␊ |
658 | ␉Node *node = DT__FindNode("/", false);␊ |
659 | ␉if (node == 0) stop("Couldn't get root node");␊ |
660 | ␉// we need to write this property after facp parsing␊ |
661 | ␉// Export system-type only if it has been overrriden by the SystemType option␊ |
662 | kType = get_env(envType);␊ |
663 | ␉DT__AddProperty(node, SYSTEM_TYPE_PROP, sizeof(uint8_t), &kType);␊ |
664 | }␊ |
665 | ␊ |
666 | struct boot_progress_element {␊ |
667 | ␉unsigned int␉width;␊ |
668 | ␉unsigned int␉height;␊ |
669 | ␉int␉␉␉yOffset;␊ |
670 | ␉unsigned int␉res[5];␊ |
671 | ␉unsigned char␉data[0];␊ |
672 | };␊ |
673 | typedef struct boot_progress_element boot_progress_element;␊ |
674 | ␊ |
675 | static VOID setupEfiDeviceTree(void)␊ |
676 | {␉␊ |
677 | ␉Node␉␉*node;␊ |
678 | ␉␊ |
679 | ␉node = DT__FindNode("/", false);␊ |
680 | ␉␊ |
681 | ␉if (node == 0) stop("Couldn't get root node");␊ |
682 | ␉␊ |
683 | ␉{␊ |
684 | ␉␉long size;␊ |
685 | ␉␉{␊ |
686 | #include "appleClut8.h"␊ |
687 | ␉␉␉size = sizeof(appleClut8);␊ |
688 | ␉␉␉long clut = AllocateKernelMemory(size);␊ |
689 | ␉␉␉bcopy(&appleClut8, (void*)clut, size);␊ |
690 | #if UNUSED␊ |
691 | ␉␉␉AllocateMemoryRange( "BootCLUT", clut, size,-1);␊ |
692 | ␉␉␉␊ |
693 | #else␊ |
694 | ␉␉␉AllocateMemoryRange( "BootCLUT", clut, size);␊ |
695 | ␉␉␉␊ |
696 | #endif␊ |
697 | ␉␉}␊ |
698 | ␉␉␊ |
699 | ␉␉{␊ |
700 | #include "failedboot.h"␉␊ |
701 | ␉␉␉size = 32 + kFailedBootWidth * kFailedBootHeight;␊ |
702 | ␉␉␉long bootPict = AllocateKernelMemory(size);␊ |
703 | #if UNUSED␊ |
704 | ␉␉␉AllocateMemoryRange( "Pict-FailedBoot", bootPict, size,-1); ␊ |
705 | #else␊ |
706 | ␉␉␉AllocateMemoryRange( "Pict-FailedBoot", bootPict, size); ␊ |
707 | #endif␊ |
708 | ␉␉␉((boot_progress_element *)bootPict)->width = kFailedBootWidth;␊ |
709 | ␉␉␉((boot_progress_element *)bootPict)->height = kFailedBootHeight;␊ |
710 | ␉␉␉((boot_progress_element *)bootPict)->yOffset = kFailedBootOffset;␉␊ |
711 | ␉␉␉if (gBootVolume->OSVersion[3] == '8') ␊ |
712 | {␊ |
713 | ((boot_progress_element *)bootPict)->res[0] = size - 32; ␊ |
714 | }␊ |
715 | ␉␉␉bcopy((char *)gFailedBootPict, (char *)(bootPict + 32), size - 32);␊ |
716 | ␉␉}␊ |
717 | ␉}␊ |
718 | ␉␊ |
719 | ␉//Fix an error with the Lion's (DP2+) installer␉␊ |
720 | ␉if (execute_hook("getboardproductPatched", NULL, NULL, NULL, NULL, NULL, NULL) != EFI_SUCCESS)␊ |
721 | ␉{␊ |
722 | ␉␉Setgboardproduct(getStringForKey("SMboardproduct", DEFAULT_SMBIOS_CONFIG));␊ |
723 | ␉␉␊ |
724 | ␉␉if (!Getgboardproduct()) readSMBIOS(theProducBoard);␊ |
725 | ␉␉␊ |
726 | ␉}␊ |
727 | ␉if (Getgboardproduct())␊ |
728 | ␉{␊ |
729 | ␉␉DT__AddProperty(node, "board-id", strlen(Getgboardproduct())+1, Getgboardproduct());␊ |
730 | ␉}␊ |
731 | ␉␊ |
732 | ␉{␊ |
733 | ␉␉Node *chosenNode = DT__FindNode("/chosen", true);␊ |
734 | ␉␉if (chosenNode)␊ |
735 | ␉␉{␉␉␉␊ |
736 | ␉␉␉DT__AddProperty(chosenNode, "boot-args", strlen(bootArgs->CommandLine)+1, (EFI_CHAR16*)bootArgs->CommandLine);␊ |
737 | ␉␉␉␊ |
738 | ␉␉␉// "boot-uuid" MAIN GOAL IS SYMPLY TO BOOT FROM THE UUID SET IN THE DT AND DECREASE BOOT TIME, SEE IOKitBSDInit.cpp␊ |
739 | ␉␉␉// additionally this value can be used by third-party apps or osx components (ex: pre-10.7 kextcache, ...)␊ |
740 | ␉␉␉if (bootInfo->uuidStr[0]) ␉␉␉␊ |
741 | ␉␉␉␉DT__AddProperty(chosenNode, kBootUUIDKey, strlen(bootInfo->uuidStr)+1, bootInfo->uuidStr);␊ |
742 | ␉␉␉␊ |
743 | ␉␉␉if (GetgRootDevice())␊ |
744 | ␉␉␉{␊ |
745 | ␉␉␉␉␊ |
746 | ␉␉␉␉DT__AddProperty(chosenNode, "boot-device-path", strlen(GetgRootDevice())+1, GetgRootDevice());␉␉␉␊ |
747 | ␉␉␉␉␊ |
748 | ␉␉␉}␉␉␉␊ |
749 | #ifdef rootpath␊ |
750 | ␉␉␉else␊ |
751 | ␉␉␉␉if (gRootPath[0])␊ |
752 | ␉␉␉␉{␊ |
753 | ␉␉␉␉␉␊ |
754 | ␉␉␉␉␉DT__AddProperty(chosenNode, "rootpath", strlen(gRootPath)+1, gRootPath);␉␉␉␊ |
755 | ␉␉␉␉␉␊ |
756 | ␉␉␉␉} ␊ |
757 | ␊ |
758 | #endif␊ |
759 | ␉␉␉␊ |
760 | ␉␉␉// "boot-file" is not used by kextcache if there is no "boot-device-path" or if there is a valid "rootpath" ,␊ |
761 | ␉␉␉// but i let it by default since it may be used by another service␊ |
762 | ␉␉␉DT__AddProperty(chosenNode, "boot-file", strlen(bootInfo->bootFile)+1, (EFI_CHAR16*)bootInfo->bootFile);␉␉␉␊ |
763 | ␉␉␉␊ |
764 | ␉␉␉if ((kAdler32 = (uint32_t)get_env(envAdler32))) ␊ |
765 | ␉␉␉␉DT__AddProperty(chosenNode, "boot-kernelcache-adler32", sizeof(unsigned long), &kAdler32);␊ |
766 | ␉␉␉␊ |
767 | ␉␉}␊ |
768 | ␉}␉␊ |
769 | ␉␊ |
770 | ␉// We could also just do DT__FindNode("/efi/platform", true)␊ |
771 | ␉// But I think eventually we want to fill stuff in the efi node␊ |
772 | ␉// too so we might as well create it so we have a pointer for it too.␊ |
773 | ␉Node *efiNode = DT__AddChild(node, "efi");␊ |
774 | ␉␊ |
775 | ␉{␊ |
776 | ␉␉// Set up the /efi/runtime-services table node similar to the way a child node of configuration-table␊ |
777 | ␉␉// is set up. That is, name and table properties␊ |
778 | ␉␉Node *runtimeServicesNode = DT__AddChild(efiNode, "runtime-services");␉␉␊ |
779 | ␉␉Node *kernelCompatibilityNode = 0; // ??? not sure that it should be used like that (because it's maybe the kernel capability and not the cpu capability)␊ |
780 | ␉␉␊ |
781 | ␉␉if (gBootVolume->OSVersion[3] > '6')␊ |
782 | ␉␉{␊ |
783 | ␉␉␉kernelCompatibilityNode = DT__AddChild(efiNode, "kernel-compatibility");␉␊ |
784 | ␉␉␉DT__AddProperty(kernelCompatibilityNode, "i386", sizeof(uint32_t), (EFI_UINT32*)&DEVICE_SUPPORTED);␊ |
785 | ␉␉}␊ |
786 | ␉␉␊ |
787 | ␉␉if (archCpuType == CPU_TYPE_I386)␊ |
788 | ␉␉{␊ |
789 | ␉␉␉// The value of the table property is the 32-bit physical address for the RuntimeServices table.␊ |
790 | ␉␉␉// Since the EFI system table already has a pointer to it, we simply use the address of that pointer␊ |
791 | ␉␉␉// for the pointer to the property data. Warning.. DT finalization calls free on that but we're not␊ |
792 | ␉␉␉// the only thing to use a non-malloc'd pointer for something in the DT␊ |
793 | ␉␉␉␊ |
794 | ␉␉␉DT__AddProperty(runtimeServicesNode, "table", sizeof(uint64_t), &gST32->RuntimeServices);␊ |
795 | ␉␉␉DT__AddProperty(efiNode, FIRMWARE_ABI_PROP, sizeof(FIRMWARE_ABI_32_PROP_VALUE), (char*)FIRMWARE_ABI_32_PROP_VALUE);␊ |
796 | ␉␉}␊ |
797 | ␉␉else␊ |
798 | ␉␉{␊ |
799 | ␉␉␉if (kernelCompatibilityNode) ␊ |
800 | ␉␉␉␉DT__AddProperty(kernelCompatibilityNode, "x86_64", sizeof(uint32_t), (EFI_UINT32*)&DEVICE_SUPPORTED);␊ |
801 | ␉␉␉␊ |
802 | ␉␉␉DT__AddProperty(runtimeServicesNode, "table", sizeof(uint64_t), &gST64->RuntimeServices);␊ |
803 | ␉␉␉DT__AddProperty(efiNode, FIRMWARE_ABI_PROP, sizeof(FIRMWARE_ABI_64_PROP_VALUE), (char*)FIRMWARE_ABI_64_PROP_VALUE);␊ |
804 | ␉␉}␊ |
805 | ␉}␊ |
806 | ␉␊ |
807 | ␉DT__AddProperty(efiNode, FIRMWARE_REVISION_PROP, sizeof(FIRMWARE_REVISION), (EFI_UINT32*)&FIRMWARE_REVISION);␊ |
808 | ␉DT__AddProperty(efiNode, FIRMWARE_VENDOR_PROP, sizeof(FIRMWARE_VENDOR), (EFI_CHAR16*)FIRMWARE_VENDOR);␊ |
809 | ␉DT__AddProperty(efiNode, FIRMWARE_NAME_PROP, sizeof(FIRMWARE_NAME), (EFI_CHAR16*)FIRMWARE_NAME);␊ |
810 | ␉DT__AddProperty(efiNode, FIRMWARE_DATE_PROP, strlen(I386BOOT_BUILDDATE)+1, I386BOOT_BUILDDATE);␉␊ |
811 | ␉DT__AddProperty(efiNode, FIRMWARE_DEV_PROP, strlen(FIRMWARE_MAINTENER)+1, FIRMWARE_MAINTENER);␊ |
812 | ␉DT__AddProperty(efiNode, FIRMWARE_PUBLISH_PROP, strlen(FIRMWARE_PUBLISHER)+1, FIRMWARE_PUBLISHER);␊ |
813 | ␉␊ |
814 | ␉{␊ |
815 | ␉␉// Export it for amlsgn support␊ |
816 | ␉␉char * DefaultPlatform = readDefaultPlatformName();␊ |
817 | ␉␉if (DefaultPlatform)␊ |
818 | ␉␉{␊ |
819 | ␉␉␉DT__AddProperty(efiNode, MOTHERBOARD_NAME_PROP, strlen(DefaultPlatform)+1, DefaultPlatform);␊ |
820 | ␉␉}␊ |
821 | ␉␉␊ |
822 | ␉}␊ |
823 | ␉␊ |
824 | ␉// Set up the /efi/configuration-table node which will eventually have several child nodes for␊ |
825 | ␉// all of the configuration tables needed by various kernel extensions.␊ |
826 | ␉gEfiConfigurationTableNode = DT__AddChild(efiNode, "configuration-table");␊ |
827 | ␉␊ |
828 | ␉{␊ |
829 | ␉␉EFI_CHAR16 *serial = 0, *productname = 0;␊ |
830 | int8_t␉␉␉␉*sysid = 0;␊ |
831 | ␉␉size_t␉␉ len = 0;␊ |
832 | ␉␉␊ |
833 | ␉␉// Now fill in the /efi/platform Node␊ |
834 | ␉␉Node *efiPlatformNode = DT__AddChild(efiNode, "platform");␊ |
835 | ␉␉␊ |
836 | ␉␉DT__AddProperty(efiPlatformNode, "DevicePathsSupported", sizeof(uint32_t), (EFI_UINT32*)&DEVICE_SUPPORTED);␊ |
837 | ␉␉␊ |
838 | ␉␉// NOTE WELL: If you do add FSB Frequency detection, make sure to store␊ |
839 | ␉␉// the value in the fsbFrequency global and not an malloc'd pointer␊ |
840 | ␉␉// because the DT_AddProperty function does not copy its args.␊ |
841 | ␉␉␊ |
842 | kFSBFrequency = get_env(envFSBFreq);␊ |
843 | ␉␉if (kFSBFrequency != 0)␊ |
844 | ␉␉␉DT__AddProperty(efiPlatformNode, FSB_Frequency_prop, sizeof(uint64_t), &kFSBFrequency);␉␉␊ |
845 | ␉␉␊ |
846 | #if UNUSED␊ |
847 | ␉␉// Export TSC and CPU frequencies for use by the kernel or KEXTs␊ |
848 | ␉␉Platform.CPU.TSCFrequency = get_env(envTSCFreq);␊ |
849 | if (Platform.CPU.TSCFrequency != 0)␊ |
850 | ␉␉␉DT__AddProperty(efiPlatformNode, TSC_Frequency_prop, sizeof(uint64_t), &Platform.CPU.TSCFrequency);␊ |
851 | ␉␉␊ |
852 | Platform.CPU.CPUFrequency = get_env(envCPUFreq);␊ |
853 | ␉␉if (Platform.CPU.CPUFrequency != 0)␊ |
854 | ␉␉␉DT__AddProperty(efiPlatformNode, CPU_Frequency_prop, sizeof(uint64_t), &Platform.CPU.CPUFrequency);␊ |
855 | #endif␊ |
856 | ␉␉␊ |
857 | ␉␉// Export system-id. Can be disabled with SystemId=No in com.apple.Boot.plist␉␉␊ |
858 | ␉␉if ((sysid = getSystemID()))␊ |
859 | ␉␉␉DT__AddProperty(efiPlatformNode, SYSTEM_ID_PROP, UUID_LEN, (EFI_UINT32*) sysid);␊ |
860 | ␉␉␊ |
861 | ␉␉// Export SystemSerialNumber if present␊ |
862 | ␉␉if ((serial=getSmbiosChar16("SMserial", &len)))␊ |
863 | ␉␉␉DT__AddProperty(efiPlatformNode, SYSTEM_SERIAL_PROP, len, serial);␊ |
864 | ␉␉␊ |
865 | ␉␉// Export Model if present␊ |
866 | ␉␉if ((productname=getSmbiosChar16("SMproductname", &len)))␊ |
867 | ␉␉␉DT__AddProperty(efiPlatformNode, MODEL_PROP, len, productname);␊ |
868 | ␉}␉␉␊ |
869 | ␉␊ |
870 | ␉// Fill /efi/device-properties node.␉␉␉␊ |
871 | ␉setupDeviceProperties(efiNode);␊ |
872 | }␊ |
873 | ␊ |
874 | /*␊ |
875 | * Load the smbios.plist override config file if any␊ |
876 | */␊ |
877 | ␊ |
878 | void setupSmbiosConfigFile(const char *filename)␊ |
879 | {␉␊ |
880 | ␉static bool readSmbConfigFile = true;␊ |
881 | ␉␊ |
882 | ␉if (readSmbConfigFile == true)␊ |
883 | ␉{␊ |
884 | ␉␉char␉␉dirSpecSMBIOS[128] = "";␊ |
885 | ␉␉const char *override_pathname = NULL;␊ |
886 | ␉␉int␉␉␉len = 0, err = 0;␊ |
887 | ␉␉␊ |
888 | ␉␉// Take in account user overriding␊ |
889 | ␉␉if (getValueForKey("SMBIOS", &override_pathname, &len, DEFAULT_BOOT_CONFIG) && len > 0)␊ |
890 | ␉␉{␊ |
891 | ␉␉␉// Specify a path to a file, e.g. SMBIOS=/Extra/macProXY.plist␊ |
892 | ␉␉␉sprintf(dirSpecSMBIOS, override_pathname);␊ |
893 | ␉␉␉err = loadConfigFile(dirSpecSMBIOS, DEFAULT_SMBIOS_CONFIG);␊ |
894 | ␉␉}␊ |
895 | ␉␉else␊ |
896 | ␉␉{␊ |
897 | ␉␉␉// Check selected volume's Extra.␊ |
898 | ␉␉␉sprintf(dirSpecSMBIOS, "/Extra/%s", filename);␊ |
899 | ␉␉␉if ((err = loadConfigFile(dirSpecSMBIOS, DEFAULT_SMBIOS_CONFIG)))␊ |
900 | ␉␉␉{␊ |
901 | ␉␉␉␉// Check booter volume/rdbt Extra.␊ |
902 | ␉␉␉␉sprintf(dirSpecSMBIOS, "bt(0,0)/Extra/%s", filename);␊ |
903 | ␉␉␉␉err = loadConfigFile(dirSpecSMBIOS, DEFAULT_SMBIOS_CONFIG);␊ |
904 | ␉␉␉}␊ |
905 | ␉␉}␊ |
906 | ␉␉␊ |
907 | ␉␉if (err)␊ |
908 | ␉␉{␊ |
909 | ␉␉␉verbose("No SMBIOS config file found.\n");␊ |
910 | ␉␉}␊ |
911 | ␉␉readSmbConfigFile = false;␊ |
912 | ␉}␊ |
913 | }␊ |
914 | ␊ |
915 | static VOID setup_Smbios()␊ |
916 | {␉␉␉␊ |
917 | ␉if (execute_hook("getSmbiosPatched",NULL, NULL, NULL, NULL, NULL, NULL) != EFI_SUCCESS)␊ |
918 | ␉{␊ |
919 | ␉␉DBG("Using the original SMBIOS !!\n");␉␊ |
920 | struct SMBEntryPoint *smbios_o = getSmbiosOriginal();␉␊ |
921 | smbios_p = ((uint64_t)((uint32_t)smbios_o)); ␊ |
922 | ␉}␉␊ |
923 | }␊ |
924 | ␊ |
925 | static VOID setup_machine_signature()␊ |
926 | {␊ |
927 | ␉Node *chosenNode = DT__FindNode("/chosen", false);␊ |
928 | ␉if (chosenNode)␊ |
929 | ␉{␊ |
930 | ␉␉if (get_env(envHardwareSignature) == 0xFFFFFFFF)␊ |
931 | ␉␉{␉␉␉␊ |
932 | ␉␉␉do {␊ |
933 | ␉␉␉␉if (!local_rsd_p)␊ |
934 | ␉␉␉␉{␉␉␉␊ |
935 | ␉␉␉␉␉if (!FindAcpiTables(&acpi_tables)){␊ |
936 | ␉␉␉␉␉␉printf("Failed to detect ACPI tables.\n");␊ |
937 | ␉␉␉␉␉␉break;␊ |
938 | ␉␉␉␉␉}␊ |
939 | ␉␉␉␉␉␊ |
940 | ␉␉␉␉␉local_rsd_p = ((uint64_t)((uint32_t)acpi_tables.RsdPointer));␊ |
941 | ␉␉␉␉}␊ |
942 | ␉␉␉␉␊ |
943 | ␉␉␉␉ACPI_TABLE_FACS *FacsPointer = (acpi_tables.FacsPointer64 != (void*)0ul) ? (ACPI_TABLE_FACS *)acpi_tables.FacsPointer64:(ACPI_TABLE_FACS *)acpi_tables.FacsPointer;␉␉␉␉␊ |
944 | ␊ |
945 | safe_set_env(envHardwareSignature , FacsPointer->HardwareSignature);␊ |
946 | ␉␉␉␉␊ |
947 | ␉␉␉} while (0); ␉␊ |
948 | ␉␉␉␊ |
949 | ␉␉␉// Verify that we have a valid hardware signature␊ |
950 | ␉␉␉if (get_env(envHardwareSignature) == 0xFFFFFFFF) ␊ |
951 | ␉␉␉{␊ |
952 | ␉␉␉␉verbose("Warning: hardware_signature is invalid, defaulting to 0 \n"); ␊ |
953 | safe_set_env(envHardwareSignature , 0);␊ |
954 | ␉␉␉}␊ |
955 | ␉␉}␊ |
956 | ␉␉␊ |
957 | kHardware_signature = get_env(envHardwareSignature); ␊ |
958 | ␉␉DT__AddProperty(chosenNode, "machine-signature", sizeof(uint32_t), &kHardware_signature);␊ |
959 | ␉}␊ |
960 | ␉␊ |
961 | }␊ |
962 | ␊ |
963 | /*␊ |
964 | * Installs all the needed configuration table entries␊ |
965 | */␊ |
966 | ␊ |
967 | static VOID setupEfiConfigurationTable()␊ |
968 | {␊ |
969 | if (smbios_p)␊ |
970 | addConfigurationTable(&gEfiSmbiosTableGuid, &smbios_p, NULL);␊ |
971 | ␉␊ |
972 | ␉if (get_env(envVendor) == CPUID_VENDOR_INTEL )␊ |
973 | ␉{␊ |
974 | ␉␉int num_cpus;␊ |
975 | ␉␉␊ |
976 | ␉␉void *mps_p = imps_probe(&num_cpus);␊ |
977 | ␉␉␊ |
978 | ␉␉if (mps_p)␊ |
979 | ␉␉{␊ |
980 | ␉␉␉uint64_t mps = ((uint64_t)((uint32_t)mps_p)); ␊ |
981 | ␉␉␉␊ |
982 | ␉␉␉addConfigurationTable(&gEfiMpsTableGuid, &mps, NULL);␊ |
983 | ␉␉}␊ |
984 | ␉␉␊ |
985 | #if DEBUG_EFI␊ |
986 | if (num_cpus != get_env(envNoCores))␊ |
987 | {␊ |
988 | printf("Warning: SMP nb of core (%d) mismatch with the value found in cpu.c (%d) \n",num_cpus,get_env(envNoCores)); ␊ |
989 | } ␊ |
990 | #endif ␊ |
991 | ␉}␉␊ |
992 | ␉␊ |
993 | ␉// PM_Model␊ |
994 | ␉if (get_env(envIsServer))␊ |
995 | {␊ |
996 | safe_set_env(envType , Workstation);␊ |
997 | ␉}␊ |
998 | ␉else if (get_env(envIsMobile))//Slice␊ |
999 | ␉{␉␊ |
1000 | safe_set_env(envType , Mobile);␊ |
1001 | ␉} ␊ |
1002 | ␉else␊ |
1003 | ␉{␊ |
1004 | safe_set_env(envType , Desktop);␊ |
1005 | ␉}␊ |
1006 | ␉␊ |
1007 | ␉// Invalidate the platform hardware signature (this needs to be verified with acpica, but i guess that 0xFFFFFFFF is an invalid signature) ␉␊ |
1008 | safe_set_env(envHardwareSignature , 0xFFFFFFFF);␊ |
1009 | ␉␊ |
1010 | ␉// Setup ACPI (based on the mackerintel's patch)␊ |
1011 | ␉(VOID)setup_acpi();␊ |
1012 | ␉␊ |
1013 | ␉setup_machine_signature();␊ |
1014 | ␉␊ |
1015 | ␉// We now have to write the system-type in ioregs: we cannot do it before in setupDeviceTree()␊ |
1016 | ␉// because we need to take care of facp original content, if it is correct.␊ |
1017 | ␉setupSystemType();␊ |
1018 | ␉␊ |
1019 | ␉// We've obviously changed the count.. so fix up the CRC32␉␊ |
1020 | EFI_ST_FIX_CRC32();␊ |
1021 | }␊ |
1022 | ␊ |
1023 | /*␊ |
1024 | * Entrypoint from boot.c␊ |
1025 | */␊ |
1026 | ␊ |
1027 | void setupFakeEfi(void)␊ |
1028 | {␊ |
1029 | ␉// Collect PCI info &| Generate device prop string␊ |
1030 | ␉setup_pci_devs(root_pci_dev);␊ |
1031 | ␉␊ |
1032 | ␉// load smbios.plist file if any␊ |
1033 | ␉setupSmbiosConfigFile("SMBIOS.plist");␊ |
1034 | ␉setup_Smbios();␊ |
1035 | ␉␊ |
1036 | ␉// Initialize the base table␊ |
1037 | ␉if (archCpuType == CPU_TYPE_I386)␊ |
1038 | ␉{␊ |
1039 | ␉␉setupEfiTables(32); ␊ |
1040 | ␉}␊ |
1041 | ␉else␊ |
1042 | ␉{␊ |
1043 | ␉␉setupEfiTables(64); ␊ |
1044 | ␉}␊ |
1045 | ␉␊ |
1046 | ␉// Initialize the device tree␊ |
1047 | ␉setupEfiDeviceTree();␊ |
1048 | ␉␊ |
1049 | ␉// Add configuration table entries to both the services table and the device tree␊ |
1050 | ␉setupEfiConfigurationTable();␉␉␊ |
1051 | ␉␊ |
1052 | } |