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{
157 //bootArgs107 = (boot_args_107 *)AllocateKernelMemory(sizeof(boot_args_107));
158
159/* Common Darwin boot arguments */
160/*
161bootArgs107->Revision = bootArgs->Header.Revision ;
162bootArgs107->Version = bootArgs->Header.Version ;
163bcopy(bootArgs->CommandLine, bootArgs107->CommandLine, BOOT_LINE_LENGTH);
164bootArgs107->MemoryMap = bootArgs->MemoryMap ;
165bootArgs107->MemoryMapSize = bootArgs->MemoryMapSize ;
166bootArgs107->MemoryMapDescriptorSize = bootArgs->MemoryMapDescriptorSize ;
167bootArgs107->MemoryMapDescriptorVersion = bootArgs->MemoryMapDescriptorVersion ;
168bootArgs107->Video = bootArgs->Video ;
169bootArgs107->deviceTreeP = bootArgs->deviceTreeP ;
170bootArgs107->deviceTreeLength = bootArgs->deviceTreeLength ;
171bootArgs107->kaddr = bootArgs->kaddr ;
172bootArgs107->ksize = bootArgs->ksize ;
173bootArgs107->efiRuntimeServicesPageStart = bootArgs->efiRuntimeServicesPageStart ;
174bootArgs107->efiRuntimeServicesPageCount = bootArgs->efiRuntimeServicesPageCount ;
175bootArgs107->efiSystemTable = bootArgs->efiSystemTable ;
176bootArgs107->efiMode = bootArgs->efiMode ;
177bootArgs107->performanceDataStart = bootArgs->performanceDataStart ;
178bootArgs107->performanceDataSize = bootArgs->performanceDataSize ;
179bootArgs107->efiRuntimeServicesVirtualPageStart = bootArgs->efiRuntimeServicesVirtualPageStart ;
180*/
181
182init_boot_args(107);
183
184/* Darwin 10.7 specific boot arguments */
185bootArgs107->keyStoreDataStart = bootArgs->keyStoreDataStart ;
186bootArgs107->keyStoreDataSize = bootArgs->keyStoreDataSize ;
187bootArgs107->bootMemStart = bootArgs->bootMemStart ;
188bootArgs107->bootMemSize = bootArgs->bootMemSize ;
189bootArgs107->PhysicalMemorySize = bootArgs->PhysicalMemorySize ;
190bootArgs107->FSBFrequency = bootArgs->FSBFrequency ;
191bootArgs107->debugMode = bootArgs->debugMode;
192
193}
194
195void
196reserveKernLegacyBootStruct(void)
197{
198 //bootArgsLegacy = (boot_args_legacy *)AllocateKernelMemory(sizeof(boot_args_legacy));
199 /*
200bootArgsLegacy->Revision = bootArgs->Header.Revision ;
201bootArgsLegacy->Version = bootArgs->Header.Version ;
202bcopy(bootArgs->CommandLine, bootArgsLegacy->CommandLine, BOOT_LINE_LENGTH);
203bootArgsLegacy->MemoryMap = bootArgs->MemoryMap ;
204bootArgsLegacy->MemoryMapSize = bootArgs->MemoryMapSize ;
205bootArgsLegacy->MemoryMapDescriptorSize = bootArgs->MemoryMapDescriptorSize ;
206bootArgsLegacy->MemoryMapDescriptorVersion = bootArgs->MemoryMapDescriptorVersion ;
207bootArgsLegacy->Video = bootArgs->Video ;
208bootArgsLegacy->deviceTreeP = bootArgs->deviceTreeP ;
209bootArgsLegacy->deviceTreeLength = bootArgs->deviceTreeLength ;
210bootArgsLegacy->kaddr = bootArgs->kaddr ;
211bootArgsLegacy->ksize = bootArgs->ksize ;
212bootArgsLegacy->efiRuntimeServicesPageStart = bootArgs->efiRuntimeServicesPageStart ;
213bootArgsLegacy->efiRuntimeServicesPageCount = bootArgs->efiRuntimeServicesPageCount ;
214bootArgsLegacy->efiSystemTable = bootArgs->efiSystemTable ;
215bootArgsLegacy->efiMode = bootArgs->efiMode ;
216bootArgsLegacy->performanceDataStart = bootArgs->performanceDataStart ;
217bootArgsLegacy->performanceDataSize = bootArgs->performanceDataSize ;
218bootArgsLegacy->efiRuntimeServicesVirtualPageStart = bootArgs->efiRuntimeServicesVirtualPageStart ;
219*/
220
221init_boot_args(Legacy);
222}
223
224void
225finalizeBootStruct(void)
226{
227{
228int i;
229EfiMemoryRange *memoryMap;
230MemoryRange *range;
231uint64_tsane_size = 0; /* Memory size to use for defaults calculations */
232
233int memoryMapCount = bootInfo->memoryMapCount;
234
235if (memoryMapCount == 0) {
236
237// XXX could make a two-part map here
238stop("No memory map found\n");
239}
240
241
242
243// convert memory map to boot_args memory map
244memoryMap = (EfiMemoryRange *)AllocateKernelMemory(sizeof(EfiMemoryRange) * memoryMapCount);
245if (memoryMap == NULL) {
246
247stop("Unable to allocate kernel space for the memory map\n");
248}
249bootArgs->MemoryMap = (uint32_t)memoryMap;
250bootArgs->MemoryMapSize = sizeof(EfiMemoryRange) * memoryMapCount;
251bootArgs->MemoryMapDescriptorSize = sizeof(EfiMemoryRange);
252bootArgs->MemoryMapDescriptorVersion = 0;
253
254for (i=0; i<memoryMapCount; i++, memoryMap++) {
255range = &bootInfo->memoryMap[i];
256switch(range->type) {
257case kMemoryRangeACPI:
258memoryMap->Type = kEfiACPIReclaimMemory;
259break;
260case kMemoryRangeNVS:
261memoryMap->Type = kEfiACPIMemoryNVS;
262break;
263case kMemoryRangeUsable:
264memoryMap->Type = kEfiConventionalMemory;
265break;
266case kMemoryRangeReserved:
267default:
268memoryMap->Type = kEfiReservedMemoryType;
269break;
270}
271memoryMap->PhysicalStart = range->base;
272memoryMap->VirtualStart = range->base;
273memoryMap->NumberOfPages = range->length >> I386_PGSHIFT;
274memoryMap->Attribute = 0;
275
276switch (memoryMap->Type) {
277case kEfiLoaderCode:
278case kEfiLoaderData:
279case kEfiBootServicesCode:
280case kEfiBootServicesData:
281case kEfiConventionalMemory:
282/*
283 * Consolidate usable memory types into one.
284 */
285sane_size += (uint64_t)(memoryMap->NumberOfPages << I386_PGSHIFT);
286break;
287
288case kEfiRuntimeServicesCode:
289case kEfiRuntimeServicesData:
290case kEfiACPIReclaimMemory:
291case kEfiACPIMemoryNVS:
292case kEfiPalCode:
293/*
294 * sane_size should reflect the total amount of physical ram
295 * in the system, not just the amount that is available for
296 * the OS to use
297 */
298sane_size += (uint64_t)(memoryMap->NumberOfPages << I386_PGSHIFT);
299break;
300default:
301break;
302
303}
304}
305
306if (sane_size == 0) {
307
308// I Guess that if sane_size == 0 we've got a big problem here,
309// and it means that the memory map was not converted properly
310stop("Unable to convert memory map into proper format\n");
311}
312
313#define MEG(1024*1024)
314
315/*
316 * For user visible memory size, round up to 128 Mb - accounting for the various stolen memory
317 * not reported by EFI.
318 */
319
320sane_size = (sane_size + 128 * MEG - 1) & ~((uint64_t)(128 * MEG - 1));
321bootArgs->PhysicalMemorySize = sane_size;
322bootArgs->FSBFrequency = Platform->CPU.FSBFrequency;
323
324}
325
326 // add PCI info somehow into device tree
327 // XXX
328
329{
330uint32_t size;
331void *addr;
332// Flatten device tree
333DT__FlattenDeviceTree(0, &size);
334addr = (void *)AllocateKernelMemory(size);
335if (addr == 0) {
336stop("Couldn't allocate device tree\n");
337}
338
339DT__FlattenDeviceTree((void **)&addr, &size);
340bootArgs->deviceTreeP = (uint32_t)addr;
341bootArgs->deviceTreeLength = size;
342}
343
344}
345

Archive Download this file

Revision: 1724