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 *bootArgs;
39PrivateBootInfo_t *bootInfo;
40Node *gMemoryMapNode;
41
42static char platformName[64];
43
44void 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{
87Node *node;
88node = DT__FindNode("/", true);
89if (node == 0) {
90stop("Couldn't create root node");
91}
92getPlatformName(platformName);
93
94{
95int nameLen;
96nameLen = strlen(platformName) + 1;
97DT__AddProperty(node, "compatible", nameLen, platformName);
98DT__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
112void
113reserveKernBootStruct(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
122void
123reserveKernLegacyBootStruct(void)
124{
125 bootArgsLegacy = (boot_args_legacy *)AllocateKernelMemory(sizeof(boot_args_legacy));
126
127bootArgsLegacy->Revision = bootArgs->Revision ;
128bootArgsLegacy->Version = bootArgs->Version ;
129bcopy(bootArgs->CommandLine, bootArgsLegacy->CommandLine, BOOT_LINE_LENGTH);
130bootArgsLegacy->MemoryMap = bootArgs->MemoryMap ;
131bootArgsLegacy->MemoryMapSize = bootArgs->MemoryMapSize ;
132bootArgsLegacy->MemoryMapDescriptorSize = bootArgs->MemoryMapDescriptorSize ;
133bootArgsLegacy->MemoryMapDescriptorVersion = bootArgs->MemoryMapDescriptorVersion ;
134bootArgsLegacy->Video = bootArgs->Video ;
135bootArgsLegacy->deviceTreeP = bootArgs->deviceTreeP ;
136bootArgsLegacy->deviceTreeLength = bootArgs->deviceTreeLength ;
137bootArgsLegacy->kaddr = bootArgs->kaddr ;
138bootArgsLegacy->ksize = bootArgs->ksize ;
139bootArgsLegacy->efiRuntimeServicesPageStart = bootArgs->efiRuntimeServicesPageStart ;
140bootArgsLegacy->efiRuntimeServicesPageCount = bootArgs->efiRuntimeServicesPageCount ;
141bootArgsLegacy->efiSystemTable = bootArgs->efiSystemTable ;
142bootArgsLegacy->efiMode = bootArgs->efiMode ;
143bootArgsLegacy->performanceDataStart = bootArgs->performanceDataStart ;
144bootArgsLegacy->performanceDataSize = bootArgs->performanceDataSize ;
145bootArgsLegacy->efiRuntimeServicesVirtualPageStart = bootArgs->efiRuntimeServicesVirtualPageStart ;
146
147
148}
149
150void
151finalizeBootStruct(void)
152{
153{
154int i;
155EfiMemoryRange *memoryMap;
156MemoryRange *range;
157uint64_tsane_size = 0; /* Memory size to use for defaults calculations */
158
159int memoryMapCount = bootInfo->memoryMapCount;
160
161if (memoryMapCount == 0) {
162
163// XXX could make a two-part map here
164stop("No memory map found\n");
165}
166
167
168
169// convert memory map to boot_args memory map
170memoryMap = (EfiMemoryRange *)AllocateKernelMemory(sizeof(EfiMemoryRange) * memoryMapCount);
171if (memoryMap == NULL) {
172
173stop("Unable to allocate kernel space for the memory map\n");
174}
175bootArgs->MemoryMap = (uint32_t)memoryMap;
176bootArgs->MemoryMapSize = sizeof(EfiMemoryRange) * memoryMapCount;
177bootArgs->MemoryMapDescriptorSize = sizeof(EfiMemoryRange);
178bootArgs->MemoryMapDescriptorVersion = 0;
179
180for (i=0; i<memoryMapCount; i++, memoryMap++) {
181range = &bootInfo->memoryMap[i];
182switch(range->type) {
183case kMemoryRangeACPI:
184memoryMap->Type = kEfiACPIReclaimMemory;
185break;
186case kMemoryRangeNVS:
187memoryMap->Type = kEfiACPIMemoryNVS;
188break;
189case kMemoryRangeUsable:
190memoryMap->Type = kEfiConventionalMemory;
191break;
192case kMemoryRangeReserved:
193default:
194memoryMap->Type = kEfiReservedMemoryType;
195break;
196}
197memoryMap->PhysicalStart = range->base;
198memoryMap->VirtualStart = range->base;
199memoryMap->NumberOfPages = range->length >> I386_PGSHIFT;
200memoryMap->Attribute = 0;
201
202switch (memoryMap->Type) {
203case kEfiLoaderCode:
204case kEfiLoaderData:
205case kEfiBootServicesCode:
206case kEfiBootServicesData:
207case kEfiConventionalMemory:
208/*
209 * Consolidate usable memory types into one.
210 */
211sane_size += (uint64_t)(memoryMap->NumberOfPages << I386_PGSHIFT);
212break;
213
214case kEfiRuntimeServicesCode:
215case kEfiRuntimeServicesData:
216case kEfiACPIReclaimMemory:
217case kEfiACPIMemoryNVS:
218case 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 */
224sane_size += (uint64_t)(memoryMap->NumberOfPages << I386_PGSHIFT);
225break;
226default:
227break;
228
229}
230}
231
232if (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
236stop("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
246sane_size = (sane_size + 128 * MEG - 1) & ~((uint64_t)(128 * MEG - 1));
247bootArgs->PhysicalMemorySize = sane_size;
248bootArgs->FSBFrequency = Platform->CPU.FSBFrequency;
249
250}
251
252 // add PCI info somehow into device tree
253 // XXX
254
255{
256uint32_t size;
257void *addr;
258// Flatten device tree
259DT__FlattenDeviceTree(0, &size);
260addr = (void *)AllocateKernelMemory(size);
261if (addr == 0) {
262stop("Couldn't allocate device tree\n");
263}
264
265DT__FlattenDeviceTree((void **)&addr, &size);
266bootArgs->deviceTreeP = (uint32_t)addr;
267bootArgs->deviceTreeLength = size;
268}
269
270
271
272}
273

Archive Download this file

Revision: 1468