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

Archive Download this file

Revision: 1972