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("Unable to convert memory map into proper format\n");
160 }
161
162 // convert memory map to boot_args memory map
163 memoryMap = (EfiMemoryRange *)AllocateKernelMemory(sizeof(EfiMemoryRange) * memoryMapCount);
164 bootArgs->MemoryMap = (uint32_t)memoryMap;
165 bootArgs->MemoryMapSize = sizeof(EfiMemoryRange) * memoryMapCount;
166 bootArgs->MemoryMapDescriptorSize = sizeof(EfiMemoryRange);
167 bootArgs->MemoryMapDescriptorVersion = 0;
168
169 for (i=0; i<memoryMapCount; i++, memoryMap++) {
170 range = &bootInfo->memoryMap[i];
171 switch(range->type) {
172case kMemoryRangeACPI:
173memoryMap->Type = kEfiACPIReclaimMemory;
174break;
175case kMemoryRangeNVS:
176memoryMap->Type = kEfiACPIMemoryNVS;
177break;
178case kMemoryRangeUsable:
179memoryMap->Type = kEfiConventionalMemory;
180break;
181case kMemoryRangeReserved:
182default:
183memoryMap->Type = kEfiReservedMemoryType;
184break;
185 }
186 memoryMap->PhysicalStart = range->base;
187 memoryMap->VirtualStart = range->base;
188 memoryMap->NumberOfPages = range->length >> I386_PGSHIFT;
189 memoryMap->Attribute = 0;
190
191switch (memoryMap->Type) {
192case kEfiLoaderCode:
193case kEfiLoaderData:
194case kEfiBootServicesCode:
195case kEfiBootServicesData:
196case kEfiConventionalMemory:
197 /*
198 * Consolidate usable memory types into one.
199 */
200 sane_size += (uint64_t)(memoryMap->NumberOfPages << I386_PGSHIFT);
201break;
202
203case kEfiRuntimeServicesCode:
204case kEfiRuntimeServicesData:
205case kEfiACPIReclaimMemory:
206case kEfiACPIMemoryNVS:
207case kEfiPalCode:
208/*
209 * sane_size should reflect the total amount of physical ram
210 * in the system, not just the amount that is available for
211 * the OS to use
212 */
213 sane_size += (uint64_t)(memoryMap->NumberOfPages << I386_PGSHIFT);
214break;
215
216}
217 }
218
219
220#define MEG(1024*1024)
221
222/*
223 * For user visible memory size, round up to 128 Mb - accounting for the various stolen memory
224 * not reported by EFI.
225 */
226
227sane_size = (sane_size + 128 * MEG - 1) & ~((uint64_t)(128 * MEG - 1));
228bootArgs->PhysicalMemorySize = sane_size;
229bootArgs->FSBFrequency = Platform->CPU.FSBFrequency;
230
231// copy bootFile into device tree
232 // XXX
233
234 // add PCI info somehow into device tree
235 // XXX
236
237 // Flatten device tree
238 DT__FlattenDeviceTree(0, &size);
239 addr = (void *)AllocateKernelMemory(size);
240 if (addr == 0) {
241 stop("Couldn't allocate device tree\n");
242 }
243
244 DT__FlattenDeviceTree((void **)&addr, &size);
245 bootArgs->deviceTreeP = (uint32_t)addr;
246 bootArgs->deviceTreeLength = size;
247}
248

Archive Download this file

Revision: 789