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

Archive Download this file

Revision: 1840