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

Archive Download this file

Revision: 1977