1 | /*␊ |
2 | * Copyright (c) 1999-2003 Apple Computer, Inc. All rights reserved.␊ |
3 | *␊ |
4 | * @APPLE_LICENSE_HEADER_START@␊ |
5 | * ␊ |
6 | * Portions Copyright (c) 1999-2003 Apple Computer, Inc. All Rights␊ |
7 | * Reserved. This file contains Original Code and/or Modifications of␊ |
8 | * Original Code as defined in and that are subject to the Apple Public␊ |
9 | * Source License Version 2.0 (the "License"). You may not use this file␊ |
10 | * except in compliance with the License. Please obtain a copy of the␊ |
11 | * License at http://www.apple.com/publicsource and read it before using␊ |
12 | * this file.␊ |
13 | * ␊ |
14 | * The Original Code and all software distributed under the License are␊ |
15 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER␊ |
16 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,␊ |
17 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,␊ |
18 | * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the␊ |
19 | * License for the specific language governing rights and limitations␊ |
20 | * under the License.␊ |
21 | * ␊ |
22 | * @APPLE_LICENSE_HEADER_END@␊ |
23 | */␊ |
24 | /*␊ |
25 | * Copyright 1993 NeXT, Inc.␊ |
26 | * All rights reserved.␊ |
27 | */␊ |
28 | ␊ |
29 | #include "libsaio.h"␊ |
30 | #include "bootstruct.h"␊ |
31 | #include "platform.h"␊ |
32 | ␊ |
33 | /*==========================================================================␊ |
34 | * Initialize the structure of parameters passed to␊ |
35 | * the kernel by the booter.␊ |
36 | */␊ |
37 | boot_args_Legacy *bootArgsLegacy;␊ |
38 | boot_args_common *bootArgs;␊ |
39 | boot_args_107 *bootArgs107;␊ |
40 | /* ... */␊ |
41 | ␊ |
42 | PrivateBootInfo_t *bootInfo;␊ |
43 | Node *gMemoryMapNode;␊ |
44 | ␊ |
45 | static char platformName[64];␊ |
46 | ␊ |
47 | void initKernBootStruct( void )␊ |
48 | { ␊ |
49 | static int init_done = 0;␊ |
50 | ␊ |
51 | if ( !init_done )␊ |
52 | {␉␉␉␊ |
53 | bootArgs = (boot_args_common *)malloc(sizeof(boot_args_common));␊ |
54 | bootInfo = (PrivateBootInfo_t *)malloc(sizeof(PrivateBootInfo_t));␊ |
55 | if (bootArgs == 0 || bootInfo == 0)␊ |
56 | stop("Couldn't allocate boot info\n");␊ |
57 | ␊ |
58 | bzero(bootArgs, sizeof(boot_args_common));␊ |
59 | bzero(bootInfo, sizeof(PrivateBootInfo_t));␊ |
60 | ␊ |
61 | // Get system memory map. Also update the size of the␊ |
62 | // conventional/extended memory for backwards compatibility.␊ |
63 | ␉␉␊ |
64 | ␉␉␉␊ |
65 | bootInfo->memoryMapCount =␊ |
66 | getMemoryMap( bootInfo->memoryMap, kMemoryMapCountMax,␊ |
67 | (unsigned long *) &bootInfo->convmem,␊ |
68 | (unsigned long *) &bootInfo->extmem );␊ |
69 | ␉␉␊ |
70 | ␉␉␊ |
71 | ␊ |
72 | if ( bootInfo->memoryMapCount == 0 )␊ |
73 | {␊ |
74 | // BIOS did not provide a memory map, systems with␊ |
75 | // discontiguous memory or unusual memory hole locations␊ |
76 | // may have problems.␊ |
77 | ␊ |
78 | bootInfo->convmem = getConventionalMemorySize();␊ |
79 | bootInfo->extmem = getExtendedMemorySize();␉␉␉␊ |
80 | ␉␉␉␊ |
81 | }␊ |
82 | #if 0␉␉␊ |
83 | bootInfo->configEnd = bootInfo->config;␊ |
84 | #endif␊ |
85 | bootArgs->Video.v_display = VGA_TEXT_MODE;␊ |
86 | ␊ |
87 | DT__Initialize();␊ |
88 | ␊ |
89 | ␉␉{␊ |
90 | ␉␉␉Node *node;␊ |
91 | ␉␉␉node = DT__FindNode("/", true);␊ |
92 | ␉␉␉if (node == 0) {␊ |
93 | ␉␉␉␉stop("Couldn't create root node");␊ |
94 | ␉␉␉}␊ |
95 | ␉␉␉getPlatformName(platformName);␊ |
96 | ␉␉␉␊ |
97 | ␉␉␉{␊ |
98 | ␉␉␉␉int nameLen;␊ |
99 | ␉␉␉␉nameLen = strlen(platformName) + 1;␊ |
100 | ␉␉␉␉DT__AddProperty(node, "compatible", nameLen, platformName);␊ |
101 | ␉␉␉␉DT__AddProperty(node, "model", nameLen, platformName);␊ |
102 | ␉␉␉} ␊ |
103 | ␉␉}␉␉ ␊ |
104 | ␊ |
105 | gMemoryMapNode = DT__FindNode("/chosen/memory-map", true);␊ |
106 | ␊ |
107 | init_done = 1;␊ |
108 | }␊ |
109 | ␊ |
110 | }␊ |
111 | ␊ |
112 | #define AllocateKernelMemoryForBootArgs(Ver) \␊ |
113 | { \␊ |
114 | ␉bootArgs##Ver = (boot_args_##Ver *)AllocateKernelMemory(sizeof(boot_args_##Ver));\␊ |
115 | }␊ |
116 | ␊ |
117 | #define CopyCommonBootArgsHeader(Ver) \␊ |
118 | { \␊ |
119 | ␉bootArgs##Ver->Revision = bootArgs->Header.Revision ;\␊ |
120 | ␉bootArgs##Ver->Version = bootArgs->Header.Version ;\␊ |
121 | }␊ |
122 | ␊ |
123 | // For 10.6, 10.5 and 10.4 please use :Legacy:, for 10.7 use :107:␊ |
124 | #define CopyCommonBootArgs(Ver) \␊ |
125 | { \␊ |
126 | ␉bcopy(bootArgs->CommandLine, bootArgs##Ver->CommandLine, BOOT_LINE_LENGTH);\␊ |
127 | ␉bootArgs##Ver->MemoryMap = bootArgs->MemoryMap ;\␊ |
128 | ␉bootArgs##Ver->MemoryMapSize = bootArgs->MemoryMapSize ;\␊ |
129 | ␉bootArgs##Ver->MemoryMapDescriptorSize = bootArgs->MemoryMapDescriptorSize ;\␊ |
130 | ␉bootArgs##Ver->MemoryMapDescriptorVersion = bootArgs->MemoryMapDescriptorVersion ;\␊ |
131 | ␉bootArgs##Ver->Video = bootArgs->Video ;\␊ |
132 | ␉bootArgs##Ver->deviceTreeP = bootArgs->deviceTreeP ;\␊ |
133 | ␉bootArgs##Ver->deviceTreeLength = bootArgs->deviceTreeLength ;\␊ |
134 | ␉bootArgs##Ver->kaddr = bootArgs->kaddr ;\␊ |
135 | ␉bootArgs##Ver->ksize = bootArgs->ksize ;\␊ |
136 | ␉bootArgs##Ver->efiRuntimeServicesPageStart = bootArgs->efiRuntimeServicesPageStart ;\␊ |
137 | ␉bootArgs##Ver->efiRuntimeServicesPageCount = bootArgs->efiRuntimeServicesPageCount ;\␊ |
138 | ␉bootArgs##Ver->efiSystemTable = bootArgs->efiSystemTable ;\␊ |
139 | ␉bootArgs##Ver->efiMode = bootArgs->efiMode ;\␊ |
140 | ␉bootArgs##Ver->performanceDataStart = bootArgs->performanceDataStart ;\␊ |
141 | ␉bootArgs##Ver->performanceDataSize = bootArgs->performanceDataSize ;\␊ |
142 | ␉bootArgs##Ver->efiRuntimeServicesVirtualPageStart = bootArgs->efiRuntimeServicesVirtualPageStart ;\␊ |
143 | }␊ |
144 | ␊ |
145 | #define init_boot_args(Ver) \␊ |
146 | { \␊ |
147 | ␉AllocateKernelMemoryForBootArgs(Ver);\␊ |
148 | ␉CopyCommonBootArgsHeader(Ver);\␊ |
149 | ␉CopyCommonBootArgs(Ver);\␊ |
150 | }␊ |
151 | ␊ |
152 | /* Copy boot args after kernel and record address. */␊ |
153 | ␊ |
154 | void␊ |
155 | reserveKern107BootStruct(void)␊ |
156 | {␉␊ |
157 | ␉init_boot_args(107);␊ |
158 | ␉␊ |
159 | ␉/* Darwin 10.7 specific boot arguments */␊ |
160 | ␉bootArgs107->keyStoreDataStart = bootArgs->keyStoreDataStart ;␊ |
161 | ␉bootArgs107->keyStoreDataSize = bootArgs->keyStoreDataSize ;␊ |
162 | ␉bootArgs107->bootMemStart = bootArgs->bootMemStart ;␊ |
163 | ␉bootArgs107->bootMemSize = bootArgs->bootMemSize ;␊ |
164 | ␉bootArgs107->PhysicalMemorySize = bootArgs->PhysicalMemorySize ;␊ |
165 | ␉bootArgs107->FSBFrequency = bootArgs->FSBFrequency ;␉␊ |
166 | ␉bootArgs107->debugMode = bootArgs->debugMode; ␊ |
167 | ␊ |
168 | }␊ |
169 | ␊ |
170 | void␊ |
171 | reserveKernLegacyBootStruct(void)␊ |
172 | {␊ |
173 | ␉init_boot_args(Legacy);␊ |
174 | }␊ |
175 | ␊ |
176 | void␊ |
177 | finalizeBootStruct(void)␊ |
178 | { ␊ |
179 | ␉{␊ |
180 | ␉␉int i;␊ |
181 | ␉␉EfiMemoryRange *memoryMap;␊ |
182 | ␉␉MemoryRange *range;␊ |
183 | ␉␉uint64_t␉sane_size = 0; /* Memory size to use for defaults calculations */␊ |
184 | ␉␉␊ |
185 | ␉␉int memoryMapCount = bootInfo->memoryMapCount;␊ |
186 | ␉␉␊ |
187 | ␉␉if (memoryMapCount == 0) {␊ |
188 | ␉␉␉␊ |
189 | ␉␉␉// XXX could make a two-part map here␊ |
190 | ␉␉␉stop("No memory map found\n");␊ |
191 | ␉␉}␊ |
192 | ␉␉␊ |
193 | ␉␉␊ |
194 | ␉␉␊ |
195 | ␉␉// convert memory map to boot_args memory map␊ |
196 | ␉␉memoryMap = (EfiMemoryRange *)AllocateKernelMemory(sizeof(EfiMemoryRange) * memoryMapCount);␊ |
197 | ␉␉if (memoryMap == NULL) {␊ |
198 | ␉␉␉␊ |
199 | ␉␉␉stop("Unable to allocate kernel space for the memory map\n");␊ |
200 | ␉␉}␊ |
201 | ␉␉bootArgs->MemoryMap = (uint32_t)memoryMap;␊ |
202 | ␉␉bootArgs->MemoryMapSize = sizeof(EfiMemoryRange) * memoryMapCount;␊ |
203 | ␉␉bootArgs->MemoryMapDescriptorSize = sizeof(EfiMemoryRange);␊ |
204 | ␉␉bootArgs->MemoryMapDescriptorVersion = 0;␊ |
205 | ␉␉␊ |
206 | ␉␉for (i=0; i<memoryMapCount; i++, memoryMap++) {␊ |
207 | ␉␉␉range = &bootInfo->memoryMap[i];␊ |
208 | ␉␉␉switch(range->type) {␊ |
209 | ␉␉␉␉case kMemoryRangeACPI:␊ |
210 | ␉␉␉␉␉memoryMap->Type = kEfiACPIReclaimMemory;␊ |
211 | ␉␉␉␉␉break;␊ |
212 | ␉␉␉␉case kMemoryRangeNVS:␊ |
213 | ␉␉␉␉␉memoryMap->Type = kEfiACPIMemoryNVS;␊ |
214 | ␉␉␉␉␉break;␊ |
215 | ␉␉␉␉case kMemoryRangeUsable:␊ |
216 | ␉␉␉␉␉memoryMap->Type = kEfiConventionalMemory;␊ |
217 | ␉␉␉␉␉break;␊ |
218 | ␉␉␉␉case kMemoryRangeReserved:␊ |
219 | ␉␉␉␉default:␊ |
220 | ␉␉␉␉␉memoryMap->Type = kEfiReservedMemoryType;␊ |
221 | ␉␉␉␉␉break;␊ |
222 | ␉␉␉}␊ |
223 | ␉␉␉memoryMap->PhysicalStart = range->base;␊ |
224 | ␉␉␉memoryMap->VirtualStart = range->base;␊ |
225 | ␉␉␉memoryMap->NumberOfPages = range->length >> I386_PGSHIFT;␊ |
226 | ␉␉␉memoryMap->Attribute = 0;␊ |
227 | ␉␉␉␊ |
228 | ␉␉␉switch (memoryMap->Type) {␊ |
229 | ␉␉␉␉case kEfiLoaderCode:␊ |
230 | ␉␉␉␉case kEfiLoaderData:␊ |
231 | ␉␉␉␉case kEfiBootServicesCode:␊ |
232 | ␉␉␉␉case kEfiBootServicesData:␊ |
233 | ␉␉␉␉case kEfiConventionalMemory:␊ |
234 | ␉␉␉␉␉/*␊ |
235 | ␉␉␉␉␉ * Consolidate usable memory types into one.␊ |
236 | ␉␉␉␉␉ */␊ |
237 | ␉␉␉␉␉sane_size += (uint64_t)(memoryMap->NumberOfPages << I386_PGSHIFT);␊ |
238 | ␉␉␉␉␉break;␊ |
239 | ␉␉␉␉␉␊ |
240 | ␉␉␉␉case kEfiRuntimeServicesCode:␊ |
241 | ␉␉␉␉case kEfiRuntimeServicesData:␊ |
242 | ␉␉␉␉case kEfiACPIReclaimMemory:␊ |
243 | ␉␉␉␉case kEfiACPIMemoryNVS:␊ |
244 | ␉␉␉␉case kEfiPalCode:␊ |
245 | ␉␉␉␉␉/*␊ |
246 | ␉␉␉␉␉ * sane_size should reflect the total amount of physical ram␊ |
247 | ␉␉␉␉␉ * in the system, not just the amount that is available for␊ |
248 | ␉␉␉␉␉ * the OS to use␊ |
249 | ␉␉␉␉␉ */␊ |
250 | ␉␉␉␉␉sane_size += (uint64_t)(memoryMap->NumberOfPages << I386_PGSHIFT);␊ |
251 | ␉␉␉␉␉break;␊ |
252 | ␉␉␉␉default:␊ |
253 | ␉␉␉␉␉break;␊ |
254 | ␉␉␉␉␉␊ |
255 | ␉␉␉}␊ |
256 | ␉␉}␊ |
257 | ␉␉␊ |
258 | ␉␉if (sane_size == 0) {␊ |
259 | ␉␉␉␊ |
260 | ␉␉␉// I Guess that if sane_size == 0 we've got a big problem here, ␊ |
261 | ␉␉␉// and it means that the memory map was not converted properly␊ |
262 | ␉␉␉stop("Unable to convert memory map into proper format\n");␊ |
263 | ␉␉}␊ |
264 | ␉␉␊ |
265 | #define MEG␉␉(1024*1024)␊ |
266 | ␉␉␊ |
267 | ␉␉/*␊ |
268 | ␉␉ * For user visible memory size, round up to 128 Mb - accounting for the various stolen memory␊ |
269 | ␉␉ * not reported by EFI.␊ |
270 | ␉␉ */␊ |
271 | ␉␉␊ |
272 | ␉␉sane_size = (sane_size + 128 * MEG - 1) & ~((uint64_t)(128 * MEG - 1));␊ |
273 | ␉␉bootArgs->PhysicalMemorySize = sane_size;␊ |
274 | ␉␉bootArgs->FSBFrequency = Platform->CPU.FSBFrequency;␊ |
275 | ␉␊ |
276 | ␉}␊ |
277 | ␉␊ |
278 | // add PCI info somehow into device tree␊ |
279 | // XXX␊ |
280 | ␉␉␊ |
281 | ␉{␊ |
282 | ␉␉uint32_t size;␊ |
283 | ␉␉void *addr;␊ |
284 | ␉␉// Flatten device tree␊ |
285 | ␉␉DT__FlattenDeviceTree(0, &size);␊ |
286 | ␉␉addr = (void *)AllocateKernelMemory(size);␊ |
287 | ␉␉if (addr == 0) {␊ |
288 | ␉␉␉stop("Couldn't allocate device tree\n");␊ |
289 | ␉␉}␊ |
290 | ␉␉␊ |
291 | ␉␉DT__FlattenDeviceTree((void **)&addr, &size);␊ |
292 | ␉␉bootArgs->deviceTreeP = (uint32_t)addr;␊ |
293 | ␉␉bootArgs->deviceTreeLength = size;␊ |
294 | ␉} ␊ |
295 | ␊ |
296 | }␊ |
297 | |