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

Archive Download this file

Revision: 1119