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

Archive Download this file

Revision: HEAD