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

Archive Download this file

Revision: 1887