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

Archive Download this file

Revision: 2118