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
33/*==========================================================================
34 * Initialize the structure of parameters passed to
35 * the kernel by the booter.
36 */
37boot_args_Legacy *bootArgsLegacy;
38boot_args_common *bootArgs;
39boot_args_107 *bootArgs107;
40/* ... */
41
42PrivateBootInfo_t *bootInfo;
43Node *gMemoryMapNode;
44
45static char platformName[64];
46
47void 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{
90Node *node;
91node = DT__FindNode("/", true);
92if (node == 0) {
93stop("Couldn't create root node");
94}
95getPlatformName(platformName);
96
97{
98int nameLen;
99nameLen = strlen(platformName) + 1;
100DT__AddProperty(node, "compatible", nameLen, platformName);
101DT__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{ \
114bootArgs##Ver = (boot_args_##Ver *)AllocateKernelMemory(sizeof(boot_args_##Ver));\
115}
116
117#define CopyCommonBootArgsHeader(Ver) \
118{ \
119bootArgs##Ver->Revision = bootArgs->Header.Revision ;\
120bootArgs##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{ \
126bcopy(bootArgs->CommandLine, bootArgs##Ver->CommandLine, BOOT_LINE_LENGTH);\
127bootArgs##Ver->MemoryMap = bootArgs->MemoryMap ;\
128bootArgs##Ver->MemoryMapSize = bootArgs->MemoryMapSize ;\
129bootArgs##Ver->MemoryMapDescriptorSize = bootArgs->MemoryMapDescriptorSize ;\
130bootArgs##Ver->MemoryMapDescriptorVersion = bootArgs->MemoryMapDescriptorVersion ;\
131bootArgs##Ver->Video = bootArgs->Video ;\
132bootArgs##Ver->deviceTreeP = bootArgs->deviceTreeP ;\
133bootArgs##Ver->deviceTreeLength = bootArgs->deviceTreeLength ;\
134bootArgs##Ver->kaddr = bootArgs->kaddr ;\
135bootArgs##Ver->ksize = bootArgs->ksize ;\
136bootArgs##Ver->efiRuntimeServicesPageStart = bootArgs->efiRuntimeServicesPageStart ;\
137bootArgs##Ver->efiRuntimeServicesPageCount = bootArgs->efiRuntimeServicesPageCount ;\
138bootArgs##Ver->efiSystemTable = bootArgs->efiSystemTable ;\
139bootArgs##Ver->efiMode = bootArgs->efiMode ;\
140bootArgs##Ver->performanceDataStart = bootArgs->performanceDataStart ;\
141bootArgs##Ver->performanceDataSize = bootArgs->performanceDataSize ;\
142bootArgs##Ver->efiRuntimeServicesVirtualPageStart = bootArgs->efiRuntimeServicesVirtualPageStart ;\
143}
144
145#define init_boot_args(Ver) \
146{ \
147AllocateKernelMemoryForBootArgs(Ver);\
148CopyCommonBootArgsHeader(Ver);\
149CopyCommonBootArgs(Ver);\
150}
151
152/* Copy boot args after kernel and record address. */
153
154void
155reserveKern107BootStruct(void)
156{
157init_boot_args(107);
158
159/* Darwin 10.7 specific boot arguments */
160bootArgs107->keyStoreDataStart = bootArgs->keyStoreDataStart ;
161bootArgs107->keyStoreDataSize = bootArgs->keyStoreDataSize ;
162bootArgs107->bootMemStart = bootArgs->bootMemStart ;
163bootArgs107->bootMemSize = bootArgs->bootMemSize ;
164bootArgs107->PhysicalMemorySize = bootArgs->PhysicalMemorySize ;
165bootArgs107->FSBFrequency = bootArgs->FSBFrequency ;
166bootArgs107->debugMode = bootArgs->debugMode;
167
168}
169
170void
171reserveKernLegacyBootStruct(void)
172{
173init_boot_args(Legacy);
174}
175
176void
177finalizeBootStruct(void)
178{
179{
180int i;
181EfiMemoryRange *memoryMap;
182MemoryRange *range;
183uint64_tsane_size = 0; /* Memory size to use for defaults calculations */
184
185int memoryMapCount = bootInfo->memoryMapCount;
186
187if (memoryMapCount == 0) {
188
189// XXX could make a two-part map here
190stop("No memory map found\n");
191}
192
193
194
195// convert memory map to boot_args memory map
196memoryMap = (EfiMemoryRange *)AllocateKernelMemory(sizeof(EfiMemoryRange) * memoryMapCount);
197if (memoryMap == NULL) {
198
199stop("Unable to allocate kernel space for the memory map\n");
200}
201bootArgs->MemoryMap = (uint32_t)memoryMap;
202bootArgs->MemoryMapSize = sizeof(EfiMemoryRange) * memoryMapCount;
203bootArgs->MemoryMapDescriptorSize = sizeof(EfiMemoryRange);
204bootArgs->MemoryMapDescriptorVersion = 0;
205
206for (i=0; i<memoryMapCount; i++, memoryMap++) {
207range = &bootInfo->memoryMap[i];
208switch(range->type) {
209case kMemoryRangeACPI:
210memoryMap->Type = kEfiACPIReclaimMemory;
211break;
212case kMemoryRangeNVS:
213memoryMap->Type = kEfiACPIMemoryNVS;
214break;
215case kMemoryRangeUsable:
216memoryMap->Type = kEfiConventionalMemory;
217break;
218case kMemoryRangeReserved:
219default:
220memoryMap->Type = kEfiReservedMemoryType;
221break;
222}
223memoryMap->PhysicalStart = range->base;
224memoryMap->VirtualStart = range->base;
225memoryMap->NumberOfPages = range->length >> I386_PGSHIFT;
226memoryMap->Attribute = 0;
227
228switch (memoryMap->Type) {
229case kEfiLoaderCode:
230case kEfiLoaderData:
231case kEfiBootServicesCode:
232case kEfiBootServicesData:
233case kEfiConventionalMemory:
234/*
235 * Consolidate usable memory types into one.
236 */
237sane_size += (uint64_t)(memoryMap->NumberOfPages << I386_PGSHIFT);
238break;
239
240case kEfiRuntimeServicesCode:
241case kEfiRuntimeServicesData:
242case kEfiACPIReclaimMemory:
243case kEfiACPIMemoryNVS:
244case 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 */
250sane_size += (uint64_t)(memoryMap->NumberOfPages << I386_PGSHIFT);
251break;
252default:
253break;
254
255}
256}
257
258if (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
262stop("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
272sane_size = (sane_size + 128 * MEG - 1) & ~((uint64_t)(128 * MEG - 1));
273bootArgs->PhysicalMemorySize = sane_size;
274bootArgs->FSBFrequency = Platform->CPU.FSBFrequency;
275
276}
277
278 // add PCI info somehow into device tree
279 // XXX
280
281{
282uint32_t size;
283void *addr;
284// Flatten device tree
285DT__FlattenDeviceTree(0, &size);
286addr = (void *)AllocateKernelMemory(size);
287if (addr == 0) {
288stop("Couldn't allocate device tree\n");
289}
290
291DT__FlattenDeviceTree((void **)&addr, &size);
292bootArgs->deviceTreeP = (uint32_t)addr;
293bootArgs->deviceTreeLength = size;
294}
295
296}
297

Archive Download this file

Revision: 1735