Chameleon

Chameleon Svn Source Tree

Root/branches/cparm/i386/libsaio/bootstruct.c

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
33boot_args_common *bootArgs = NULL;
34
35
36/*==========================================================================
37 * structure of parameters passed to
38 * the kernel by the booter.
39 */
40boot_args_Legacy *bootArgsLegacy = NULL;
41boot_args_107 *bootArgs107 = NULL;
42boot_args_108 *bootArgs108 = NULL;
43/* ... */
44
45PrivateBootInfo_t *bootInfo = NULL;
46Node *gMemoryMapNode = NULL;
47
48static char platformName[64];
49static MemoryRange memoryMap[kMemoryMapCountMax];
50
51void initKernBootStruct( void )
52{
53 static int init_done = 0;
54
55 if ( !init_done )
56 {
57int convmem; // conventional memory
58int extmem; // extended memory
59
60unsigned long memoryMapCount = 0;
61
62 bootArgs = (boot_args_common *)malloc(sizeof(boot_args_common));
63 bootInfo = (PrivateBootInfo_t *)malloc(sizeof(PrivateBootInfo_t));
64 if (bootArgs == NULL || bootInfo == NULL)
65 stop("Couldn't allocate boot info\n");
66 else
67 {
68 bzero(bootArgs, sizeof(boot_args_common));
69 bzero(bootInfo, sizeof(PrivateBootInfo_t));
70
71 // Get system memory map. Also update the size of the
72 // conventional/extended memory for backwards compatibility.
73
74
75 memoryMapCount =
76 getMemoryMap( memoryMap, kMemoryMapCountMax,
77 (unsigned long *) &convmem,
78 (unsigned long *) &extmem );
79
80
81
82 if ( memoryMapCount == 0 )
83 {
84 // BIOS did not provide a memory map, systems with
85 // discontiguous memory or unusual memory hole locations
86 // may have problems.
87
88 convmem = getConventionalMemorySize();
89 extmem = getExtendedMemorySize();
90
91 }
92
93 bootArgs->Video.v_display = VGA_TEXT_MODE;
94
95 DT__Initialize();
96
97 {
98 Node *node;
99 node = DT__FindNode("/", true);
100 if (node == 0) {
101 stop("Couldn't create root node");
102 }
103 getPlatformName(platformName);
104
105 {
106 int nameLen;
107 nameLen = strlen(platformName) + 1;
108 DT__AddProperty(node, "compatible", nameLen, platformName);
109 DT__AddProperty(node, "model", nameLen, platformName);
110 }
111 }
112
113 gMemoryMapNode = DT__FindNode("/chosen/memory-map", true);
114
115 set_env(envConvMem, convmem);
116 set_env(envExtMem, extmem);
117 set_env(envMemoryMap, (uint32_t)memoryMap);
118 set_env(envMemoryMapCnt, memoryMapCount);
119
120
121 init_done = 1;
122 }
123
124 }
125
126}
127
128/* boot args getters/setters. */
129
130void setBootArgsVideoMode(int mode)
131{
132 bootArgs->Video.v_display = mode;
133}
134uint32_t getVideoMode(void)
135{
136 return bootArgs->Video.v_display;
137}
138void setBootArgsVideoStruct(Boot_Video*Video)
139{
140 bootArgs->Video.v_display = Video->v_display;
141 bootArgs->Video.v_width = Video->v_width;
142 bootArgs->Video.v_height = Video->v_height;
143 bootArgs->Video.v_depth = Video->v_depth;
144 bootArgs->Video.v_rowBytes = Video->v_rowBytes;
145 bootArgs->Video.v_baseAddr = Video->v_baseAddr;
146 return;
147}
148boot_args_common * getBootArgs(void)
149{
150 return bootArgs;
151}
152
153#define AllocateKernelMemoryForBootArgs(Ver) \
154{ \
155bootArgs##Ver = (boot_args_##Ver *)AllocateKernelMemory(sizeof(boot_args_##Ver));\
156}
157
158#define CopyCommonBootArgsHeader(Ver) \
159{ \
160bootArgs##Ver->Revision = bootArgs->Header.Revision ;\
161bootArgs##Ver->Version = bootArgs->Header.Version ;\
162}
163
164// For 10.6, 10.5 and 10.4 please use :Legacy:, for 10.7 use :107:, for 10.8 use :108:
165#define CopyCommonBootArgs(Ver) \
166{ \
167bcopy(bootArgs->CommandLine, bootArgs##Ver->CommandLine, BOOT_LINE_LENGTH);\
168bootArgs##Ver->MemoryMap = bootArgs->MemoryMap ;\
169bootArgs##Ver->MemoryMapSize = bootArgs->MemoryMapSize ;\
170bootArgs##Ver->MemoryMapDescriptorSize = bootArgs->MemoryMapDescriptorSize ;\
171bootArgs##Ver->MemoryMapDescriptorVersion = bootArgs->MemoryMapDescriptorVersion ;\
172bootArgs##Ver->Video = bootArgs->Video ;\
173bootArgs##Ver->deviceTreeP = bootArgs->deviceTreeP ;\
174bootArgs##Ver->deviceTreeLength = bootArgs->deviceTreeLength ;\
175bootArgs##Ver->kaddr = bootArgs->kaddr ;\
176bootArgs##Ver->ksize = bootArgs->ksize ;\
177bootArgs##Ver->efiRuntimeServicesPageStart = bootArgs->efiRuntimeServicesPageStart ;\
178bootArgs##Ver->efiRuntimeServicesPageCount = bootArgs->efiRuntimeServicesPageCount ;\
179bootArgs##Ver->efiSystemTable = bootArgs->efiSystemTable ;\
180bootArgs##Ver->efiMode = bootArgs->efiMode ;\
181bootArgs##Ver->performanceDataStart = bootArgs->performanceDataStart ;\
182bootArgs##Ver->performanceDataSize = bootArgs->performanceDataSize ;\
183bootArgs##Ver->efiRuntimeServicesVirtualPageStart = bootArgs->efiRuntimeServicesVirtualPageStart ;\
184}
185
186/*
187 * Darwin 10.7+ specific boot arguments
188 *
189 * for 10.7 use :107:, for 10.8 use :108:
190 */
191#define Copy107plusBootArgs(Ver) \
192{ \
193bootArgs##Ver->keyStoreDataStart = bootArgs->keyStoreDataStart ;\
194bootArgs##Ver->keyStoreDataSize = bootArgs->keyStoreDataSize ;\
195bootArgs##Ver->bootMemStart = bootArgs->bootMemStart ;\
196bootArgs##Ver->bootMemSize = bootArgs->bootMemSize ;\
197bootArgs##Ver->PhysicalMemorySize = bootArgs->PhysicalMemorySize ;\
198bootArgs##Ver->FSBFrequency = bootArgs->FSBFrequency ;\
199bootArgs##Ver->debugMode = bootArgs->debugMode ;\
200}
201
202#define init_boot_args(Ver) \
203{ \
204AllocateKernelMemoryForBootArgs(Ver);\
205CopyCommonBootArgsHeader(Ver);\
206CopyCommonBootArgs(Ver);\
207}
208
209/* Copy boot args after kernel and record address. */
210
211void
212reserveKern107BootStruct(void)
213{
214init_boot_args(107);
215Copy107plusBootArgs(107);
216}
217
218void
219reserveKern108BootStruct(void)
220{
221init_boot_args(108);
222Copy107plusBootArgs(108);
223
224/* Darwin 10.8 specific boot arguments */
225}
226
227void
228reserveKernLegacyBootStruct(void)
229{
230init_boot_args(Legacy);
231}
232
233void
234finalizeBootStruct(void)
235{
236{
237int i;
238EfiMemoryRange *kMemoryMap = NULL;
239MemoryRange *range = NULL;
240
241uint64_tsane_size = 0; /* Memory size to use for defaults calculations */
242
243int memoryMapCount = (int)get_env(envMemoryMapCnt);
244
245if (memoryMapCount == 0) {
246
247// XXX could make a two-part map here
248stop("No memory map found\n");
249}
250
251
252
253// convert memory map to boot_args memory map
254kMemoryMap = (EfiMemoryRange *)AllocateKernelMemory(sizeof(EfiMemoryRange) * memoryMapCount);
255if (kMemoryMap == NULL) {
256
257stop("Unable to allocate kernel space for the memory map\n");
258 return;
259}
260bootArgs->MemoryMap = (uint32_t)kMemoryMap;
261bootArgs->MemoryMapSize = sizeof(EfiMemoryRange) * memoryMapCount;
262bootArgs->MemoryMapDescriptorSize = sizeof(EfiMemoryRange);
263bootArgs->MemoryMapDescriptorVersion = 0;
264
265for (i=0; i<memoryMapCount; i++, kMemoryMap++) {
266range = &memoryMap[i];
267 if (!range || !kMemoryMap) {
268 stop("Error while computing kernel memory map\n");
269 return;
270 }
271switch(range->type) {
272case kMemoryRangeACPI:
273kMemoryMap->Type = kEfiACPIReclaimMemory;
274break;
275case kMemoryRangeNVS:
276kMemoryMap->Type = kEfiACPIMemoryNVS;
277break;
278case kMemoryRangeUsable:
279kMemoryMap->Type = kEfiConventionalMemory;
280break;
281case kMemoryRangeReserved:
282default:
283kMemoryMap->Type = kEfiReservedMemoryType;
284break;
285}
286kMemoryMap->PhysicalStart = range->base;
287kMemoryMap->VirtualStart = range->base;
288kMemoryMap->NumberOfPages = range->length >> I386_PGSHIFT;
289kMemoryMap->Attribute = 0;
290
291switch (kMemoryMap->Type) {
292case kEfiLoaderCode:
293case kEfiLoaderData:
294case kEfiBootServicesCode:
295case kEfiBootServicesData:
296case kEfiConventionalMemory:
297/*
298 * Consolidate usable memory types into one.
299 */
300sane_size += (uint64_t)(kMemoryMap->NumberOfPages << I386_PGSHIFT);
301break;
302
303case kEfiRuntimeServicesCode:
304case kEfiRuntimeServicesData:
305case kEfiACPIReclaimMemory:
306case kEfiACPIMemoryNVS:
307case kEfiPalCode:
308/*
309 * sane_size should reflect the total amount of physical ram
310 * in the system, not just the amount that is available for
311 * the OS to use
312 */
313sane_size += (uint64_t)(kMemoryMap->NumberOfPages << I386_PGSHIFT);
314break;
315default:
316break;
317
318}
319}
320
321if (sane_size == 0) {
322
323// I Guess that if sane_size == 0 we've got a big problem here,
324// and it means that the memory map was not converted properly
325stop("Unable to convert memory map into proper format\n");
326}
327
328#define MEG(1024*1024)
329
330/*
331 * For user visible memory size, round up to 128 Mb - accounting for the various stolen memory
332 * not reported by EFI.
333 */
334
335sane_size = (sane_size + 128 * MEG - 1) & ~((uint64_t)(128 * MEG - 1));
336bootArgs->PhysicalMemorySize = sane_size;
337bootArgs->FSBFrequency = get_env(envFSBFreq);
338
339}
340
341
342{
343uint32_t size;
344void *addr;
345// Flatten device tree
346DT__FlattenDeviceTree(0, &size);
347addr = (void *)AllocateKernelMemory(size);
348if (addr == 0) {
349stop("Couldn't allocate device tree\n");
350}
351
352DT__FlattenDeviceTree((void **)&addr, &size);
353bootArgs->deviceTreeP = (uint32_t)addr;
354bootArgs->deviceTreeLength = size;
355}
356
357}
358

Archive Download this file

Revision: 1899