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 *bootArgs;␊ |
39 | PrivateBootInfo_t *bootInfo;␊ |
40 | Node *gMemoryMapNode;␊ |
41 | ␊ |
42 | static char platformName[64];␊ |
43 | ␊ |
44 | void initKernBootStruct( void )␊ |
45 | { ␊ |
46 | static int init_done = 0;␊ |
47 | ␊ |
48 | if ( !init_done )␊ |
49 | {␉␉␉␊ |
50 | bootArgs = (boot_args *)malloc(sizeof(boot_args));␊ |
51 | bootInfo = (PrivateBootInfo_t *)malloc(sizeof(PrivateBootInfo_t));␊ |
52 | if (bootArgs == 0 || bootInfo == 0)␊ |
53 | stop("Couldn't allocate boot info\n");␊ |
54 | ␊ |
55 | bzero(bootArgs, sizeof(boot_args));␊ |
56 | bzero(bootInfo, sizeof(PrivateBootInfo_t));␊ |
57 | ␊ |
58 | // Get system memory map. Also update the size of the␊ |
59 | // conventional/extended memory for backwards compatibility.␊ |
60 | ␉␉␊ |
61 | ␉␉␉␊ |
62 | bootInfo->memoryMapCount =␊ |
63 | getMemoryMap( bootInfo->memoryMap, kMemoryMapCountMax,␊ |
64 | (unsigned long *) &bootInfo->convmem,␊ |
65 | (unsigned long *) &bootInfo->extmem );␊ |
66 | ␉␉␊ |
67 | ␉␉␊ |
68 | ␊ |
69 | if ( bootInfo->memoryMapCount == 0 )␊ |
70 | {␊ |
71 | // BIOS did not provide a memory map, systems with␊ |
72 | // discontiguous memory or unusual memory hole locations␊ |
73 | // may have problems.␊ |
74 | ␊ |
75 | bootInfo->convmem = getConventionalMemorySize();␊ |
76 | bootInfo->extmem = getExtendedMemorySize();␉␉␉␊ |
77 | ␉␉␉␊ |
78 | }␊ |
79 | #if 0␉␉␊ |
80 | bootInfo->configEnd = bootInfo->config;␊ |
81 | #endif␊ |
82 | bootArgs->Video.v_display = VGA_TEXT_MODE;␊ |
83 | ␊ |
84 | DT__Initialize();␊ |
85 | ␊ |
86 | ␉␉{␊ |
87 | ␉␉␉Node *node;␊ |
88 | ␉␉␉node = DT__FindNode("/", true);␊ |
89 | ␉␉␉if (node == 0) {␊ |
90 | ␉␉␉␉stop("Couldn't create root node");␊ |
91 | ␉␉␉}␊ |
92 | ␉␉␉getPlatformName(platformName);␊ |
93 | ␉␉␉␊ |
94 | ␉␉␉{␊ |
95 | ␉␉␉␉int nameLen;␊ |
96 | ␉␉␉␉nameLen = strlen(platformName) + 1;␊ |
97 | ␉␉␉␉DT__AddProperty(node, "compatible", nameLen, platformName);␊ |
98 | ␉␉␉␉DT__AddProperty(node, "model", nameLen, platformName);␊ |
99 | ␉␉␉} ␊ |
100 | ␉␉}␉␉ ␊ |
101 | ␊ |
102 | gMemoryMapNode = DT__FindNode("/chosen/memory-map", true);␊ |
103 | ␊ |
104 | init_done = 1;␊ |
105 | }␊ |
106 | ␊ |
107 | }␊ |
108 | ␊ |
109 | ␊ |
110 | /* Copy boot args after kernel and record address. */␊ |
111 | ␊ |
112 | void␊ |
113 | reserveKernBootStruct(void)␊ |
114 | {␊ |
115 | void *oldAddr = bootArgs;␉␊ |
116 | ␉␊ |
117 | bootArgs = (boot_args *)AllocateKernelMemory(sizeof(boot_args));␊ |
118 | bcopy(oldAddr, bootArgs, sizeof(boot_args));␊ |
119 | ␉␉␊ |
120 | }␊ |
121 | ␊ |
122 | void␊ |
123 | reserveKernLegacyBootStruct(void)␊ |
124 | { ␊ |
125 | bootArgsLegacy = (boot_args_legacy *)AllocateKernelMemory(sizeof(boot_args_legacy));␊ |
126 | ␊ |
127 | ␉bootArgsLegacy->Revision = bootArgs->Revision ;␊ |
128 | ␉bootArgsLegacy->Version = bootArgs->Version ;␊ |
129 | ␉bcopy(bootArgs->CommandLine, bootArgsLegacy->CommandLine, BOOT_LINE_LENGTH);␊ |
130 | ␉bootArgsLegacy->MemoryMap = bootArgs->MemoryMap ;␊ |
131 | ␉bootArgsLegacy->MemoryMapSize = bootArgs->MemoryMapSize ;␊ |
132 | ␉bootArgsLegacy->MemoryMapDescriptorSize = bootArgs->MemoryMapDescriptorSize ;␊ |
133 | ␉bootArgsLegacy->MemoryMapDescriptorVersion = bootArgs->MemoryMapDescriptorVersion ;␊ |
134 | ␉bootArgsLegacy->Video = bootArgs->Video ;␊ |
135 | ␉bootArgsLegacy->deviceTreeP = bootArgs->deviceTreeP ;␊ |
136 | ␉bootArgsLegacy->deviceTreeLength = bootArgs->deviceTreeLength ;␊ |
137 | ␉bootArgsLegacy->kaddr = bootArgs->kaddr ;␊ |
138 | ␉bootArgsLegacy->ksize = bootArgs->ksize ;␊ |
139 | ␉bootArgsLegacy->efiRuntimeServicesPageStart = bootArgs->efiRuntimeServicesPageStart ;␊ |
140 | ␉bootArgsLegacy->efiRuntimeServicesPageCount = bootArgs->efiRuntimeServicesPageCount ;␊ |
141 | ␉bootArgsLegacy->efiSystemTable = bootArgs->efiSystemTable ;␊ |
142 | ␉bootArgsLegacy->efiMode = bootArgs->efiMode ;␊ |
143 | ␉bootArgsLegacy->performanceDataStart = bootArgs->performanceDataStart ;␊ |
144 | ␉bootArgsLegacy->performanceDataSize = bootArgs->performanceDataSize ;␊ |
145 | ␉bootArgsLegacy->efiRuntimeServicesVirtualPageStart = bootArgs->efiRuntimeServicesVirtualPageStart ;␊ |
146 | ␊ |
147 | ␉␊ |
148 | }␊ |
149 | ␊ |
150 | void␊ |
151 | finalizeBootStruct(void)␊ |
152 | { ␊ |
153 | ␉{␊ |
154 | ␉␉int i;␊ |
155 | ␉␉EfiMemoryRange *memoryMap;␊ |
156 | ␉␉MemoryRange *range;␊ |
157 | ␉␉uint64_t␉sane_size = 0; /* Memory size to use for defaults calculations */␊ |
158 | ␉␉␊ |
159 | ␉␉int memoryMapCount = bootInfo->memoryMapCount;␊ |
160 | ␉␉␊ |
161 | ␉␉if (memoryMapCount == 0) {␊ |
162 | ␉␉␉␊ |
163 | ␉␉␉// XXX could make a two-part map here␊ |
164 | ␉␉␉stop("No memory map found\n");␊ |
165 | ␉␉}␊ |
166 | ␉␉␊ |
167 | ␉␉␊ |
168 | ␉␉␊ |
169 | ␉␉// convert memory map to boot_args memory map␊ |
170 | ␉␉memoryMap = (EfiMemoryRange *)AllocateKernelMemory(sizeof(EfiMemoryRange) * memoryMapCount);␊ |
171 | ␉␉if (memoryMap == NULL) {␊ |
172 | ␉␉␉␊ |
173 | ␉␉␉stop("Unable to allocate kernel space for the memory map\n");␊ |
174 | ␉␉}␊ |
175 | ␉␉bootArgs->MemoryMap = (uint32_t)memoryMap;␊ |
176 | ␉␉bootArgs->MemoryMapSize = sizeof(EfiMemoryRange) * memoryMapCount;␊ |
177 | ␉␉bootArgs->MemoryMapDescriptorSize = sizeof(EfiMemoryRange);␊ |
178 | ␉␉bootArgs->MemoryMapDescriptorVersion = 0;␊ |
179 | ␉␉␊ |
180 | ␉␉for (i=0; i<memoryMapCount; i++, memoryMap++) {␊ |
181 | ␉␉␉range = &bootInfo->memoryMap[i];␊ |
182 | ␉␉␉switch(range->type) {␊ |
183 | ␉␉␉␉case kMemoryRangeACPI:␊ |
184 | ␉␉␉␉␉memoryMap->Type = kEfiACPIReclaimMemory;␊ |
185 | ␉␉␉␉␉break;␊ |
186 | ␉␉␉␉case kMemoryRangeNVS:␊ |
187 | ␉␉␉␉␉memoryMap->Type = kEfiACPIMemoryNVS;␊ |
188 | ␉␉␉␉␉break;␊ |
189 | ␉␉␉␉case kMemoryRangeUsable:␊ |
190 | ␉␉␉␉␉memoryMap->Type = kEfiConventionalMemory;␊ |
191 | ␉␉␉␉␉break;␊ |
192 | ␉␉␉␉case kMemoryRangeReserved:␊ |
193 | ␉␉␉␉default:␊ |
194 | ␉␉␉␉␉memoryMap->Type = kEfiReservedMemoryType;␊ |
195 | ␉␉␉␉␉break;␊ |
196 | ␉␉␉}␊ |
197 | ␉␉␉memoryMap->PhysicalStart = range->base;␊ |
198 | ␉␉␉memoryMap->VirtualStart = range->base;␊ |
199 | ␉␉␉memoryMap->NumberOfPages = range->length >> I386_PGSHIFT;␊ |
200 | ␉␉␉memoryMap->Attribute = 0;␊ |
201 | ␉␉␉␊ |
202 | ␉␉␉switch (memoryMap->Type) {␊ |
203 | ␉␉␉␉case kEfiLoaderCode:␊ |
204 | ␉␉␉␉case kEfiLoaderData:␊ |
205 | ␉␉␉␉case kEfiBootServicesCode:␊ |
206 | ␉␉␉␉case kEfiBootServicesData:␊ |
207 | ␉␉␉␉case kEfiConventionalMemory:␊ |
208 | ␉␉␉␉␉/*␊ |
209 | ␉␉␉␉␉ * Consolidate usable memory types into one.␊ |
210 | ␉␉␉␉␉ */␊ |
211 | ␉␉␉␉␉sane_size += (uint64_t)(memoryMap->NumberOfPages << I386_PGSHIFT);␊ |
212 | ␉␉␉␉␉break;␊ |
213 | ␉␉␉␉␉␊ |
214 | ␉␉␉␉case kEfiRuntimeServicesCode:␊ |
215 | ␉␉␉␉case kEfiRuntimeServicesData:␊ |
216 | ␉␉␉␉case kEfiACPIReclaimMemory:␊ |
217 | ␉␉␉␉case kEfiACPIMemoryNVS:␊ |
218 | ␉␉␉␉case kEfiPalCode:␊ |
219 | ␉␉␉␉␉/*␊ |
220 | ␉␉␉␉␉ * sane_size should reflect the total amount of physical ram␊ |
221 | ␉␉␉␉␉ * in the system, not just the amount that is available for␊ |
222 | ␉␉␉␉␉ * the OS to use␊ |
223 | ␉␉␉␉␉ */␊ |
224 | ␉␉␉␉␉sane_size += (uint64_t)(memoryMap->NumberOfPages << I386_PGSHIFT);␊ |
225 | ␉␉␉␉␉break;␊ |
226 | ␉␉␉␉default:␊ |
227 | ␉␉␉␉␉break;␊ |
228 | ␉␉␉␉␉␊ |
229 | ␉␉␉}␊ |
230 | ␉␉}␊ |
231 | ␉␉␊ |
232 | ␉␉if (sane_size == 0) {␊ |
233 | ␉␉␉␊ |
234 | ␉␉␉// I Guess that if sane_size == 0 we've got a big problem here, ␊ |
235 | ␉␉␉// and it means that the memory map was not converted properly␊ |
236 | ␉␉␉stop("Unable to convert memory map into proper format\n");␊ |
237 | ␉␉}␊ |
238 | ␉␉␊ |
239 | #define MEG␉␉(1024*1024)␊ |
240 | ␉␉␊ |
241 | ␉␉/*␊ |
242 | ␉␉ * For user visible memory size, round up to 128 Mb - accounting for the various stolen memory␊ |
243 | ␉␉ * not reported by EFI.␊ |
244 | ␉␉ */␊ |
245 | ␉␉␊ |
246 | ␉␉sane_size = (sane_size + 128 * MEG - 1) & ~((uint64_t)(128 * MEG - 1));␊ |
247 | ␉␉bootArgs->PhysicalMemorySize = sane_size;␊ |
248 | ␉␉bootArgs->FSBFrequency = Platform->CPU.FSBFrequency;␊ |
249 | ␉␊ |
250 | ␉}␊ |
251 | ␉␊ |
252 | // add PCI info somehow into device tree␊ |
253 | // XXX␊ |
254 | ␉␉␊ |
255 | ␉{␊ |
256 | ␉␉uint32_t size;␊ |
257 | ␉␉void *addr;␊ |
258 | ␉␉// Flatten device tree␊ |
259 | ␉␉DT__FlattenDeviceTree(0, &size);␊ |
260 | ␉␉addr = (void *)AllocateKernelMemory(size);␊ |
261 | ␉␉if (addr == 0) {␊ |
262 | ␉␉␉stop("Couldn't allocate device tree\n");␊ |
263 | ␉␉}␊ |
264 | ␉␉␊ |
265 | ␉␉DT__FlattenDeviceTree((void **)&addr, &size);␊ |
266 | ␉␉bootArgs->deviceTreeP = (uint32_t)addr;␊ |
267 | ␉␉bootArgs->deviceTreeLength = size;␊ |
268 | ␉}␊ |
269 | ␊ |
270 | ␊ |
271 | ␊ |
272 | }␊ |
273 | |