]> git.saurik.com Git - apple/xnu.git/blob - osfmk/ppc/ppc_init.c
xnu-344.21.74.tar.gz
[apple/xnu.git] / osfmk / ppc / ppc_init.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 * @OSF_COPYRIGHT@
27 */
28
29 #include <debug.h>
30 #include <mach_ldebug.h>
31 #include <mach_kdb.h>
32 #include <mach_kdp.h>
33
34 #include <kern/misc_protos.h>
35 #include <kern/thread.h>
36 #include <kern/processor.h>
37 #include <machine/machine_routines.h>
38 #include <ppc/boot.h>
39 #include <ppc/proc_reg.h>
40 #include <ppc/misc_protos.h>
41 #include <ppc/pmap.h>
42 #include <ppc/new_screen.h>
43 #include <ppc/exception.h>
44 #include <ppc/Firmware.h>
45 #include <ppc/savearea.h>
46 #include <ppc/low_trace.h>
47 #include <ppc/Diagnostics.h>
48 #include <ppc/mem.h>
49 #include <ppc/mappings.h>
50
51 #include <pexpert/pexpert.h>
52
53 extern unsigned int intstack_top_ss; /* declared in start.s */
54 extern unsigned int debstackptr; /* declared in start.s */
55 extern unsigned int debstack_top_ss; /* declared in start.s */
56
57 int pc_trace_buf[1024] = {0};
58 int pc_trace_cnt = 1024;
59
60 extern unsigned int extPatchMCK;
61 extern unsigned int extPatch32;
62 extern unsigned int hwulckPatch_isync;
63 extern unsigned int hwulckPatch_eieio;
64 extern unsigned int hwulckbPatch_isync;
65 extern unsigned int hwulckbPatch_eieio;
66 extern unsigned int mulckPatch_isync;
67 extern unsigned int mulckPatch_eieio;
68 extern unsigned int sulckPatch_isync;
69 extern unsigned int sulckPatch_eieio;
70 extern unsigned int retfsectPatch_eieio;
71 extern unsigned int retfsectPatch_isync;
72
73 int forcenap = 0;
74
75 patch_entry_t patch_table[PATCH_TABLE_SIZE] = {
76 &extPatch32, 0x60000000, PATCH_FEATURE, PatchExt32,
77 &extPatchMCK, 0x60000000, PATCH_PROCESSOR, CPU_SUBTYPE_POWERPC_970,
78 &hwulckPatch_isync, 0x60000000, PATCH_FEATURE, PatchLwsync,
79 &hwulckPatch_eieio, 0x7c2004ac, PATCH_FEATURE, PatchLwsync,
80 &hwulckbPatch_isync, 0x60000000, PATCH_FEATURE, PatchLwsync,
81 &hwulckbPatch_eieio, 0x7c2004ac, PATCH_FEATURE, PatchLwsync,
82 &mulckPatch_isync, 0x60000000, PATCH_FEATURE, PatchLwsync,
83 &mulckPatch_eieio, 0x7c2004ac, PATCH_FEATURE, PatchLwsync,
84 &sulckPatch_isync, 0x60000000, PATCH_FEATURE, PatchLwsync,
85 &sulckPatch_eieio, 0x7c2004ac, PATCH_FEATURE, PatchLwsync,
86 #if !MACH_LDEBUG
87 &retfsectPatch_isync, 0x60000000, PATCH_FEATURE, PatchLwsync,
88 &retfsectPatch_eieio, 0x7c2004ac, PATCH_FEATURE, PatchLwsync
89 #else
90 0, 0, PATCH_INVALID, 0,
91 0, 0, PATCH_INVALID, 0
92 #endif
93 };
94
95 void ppc_init(boot_args *args)
96 {
97 int i;
98 unsigned long *src,*dst;
99 char *str;
100 unsigned long addr, videoAddr;
101 unsigned int maxmem;
102 uint64_t xmaxmem;
103 unsigned int cputrace;
104 unsigned int novmx;
105 extern vm_offset_t static_memory_end;
106 mapping *mp;
107
108 /*
109 * Setup per_proc info for first cpu.
110 */
111
112 per_proc_info[0].cpu_number = 0;
113 per_proc_info[0].cpu_flags = 0;
114 per_proc_info[0].istackptr = 0; /* we're on the interrupt stack */
115 per_proc_info[0].intstack_top_ss = intstack_top_ss;
116 per_proc_info[0].debstackptr = debstackptr;
117 per_proc_info[0].debstack_top_ss = debstack_top_ss;
118 per_proc_info[0].interrupts_enabled = 0;
119 per_proc_info[0].active_kloaded = (unsigned int)
120 &active_kloaded[0];
121 set_machine_current_thread(&pageout_thread);
122 set_machine_current_act(&pageout_act);
123 pageout_thread.top_act = &pageout_act;
124 pageout_act.thread = &pageout_thread;
125 pageout_act.mact.curctx = &pageout_act.mact.facctx;
126 pageout_act.mact.facctx.facAct = &pageout_act;
127 pageout_act.mact.cioSpace = invalSpace; /* Initialize copyin/out space to invalid */
128 pageout_act.mact.preemption_count = 1;
129 per_proc_info[0].pp_preemption_count = -1;
130 per_proc_info[0].pp_simple_lock_count = 0;
131 per_proc_info[0].pp_interrupt_level = 0;
132 per_proc_info[0].active_stacks = (unsigned int)
133 &active_stacks[0];
134 per_proc_info[0].need_ast = (unsigned int)
135 &need_ast[0];
136 per_proc_info[0].FPU_owner = 0;
137 per_proc_info[0].VMX_owner = 0;
138 mp = (mapping *)per_proc_info[0].ppCIOmp;
139 mp->mpFlags = 0x01000000 | mpSpecial | 1;
140 mp->mpSpace = invalSpace;
141
142 machine_slot[0].is_cpu = TRUE;
143
144 cpu_init();
145
146 /*
147 * Setup some processor related structures to satisfy funnels.
148 * Must be done before using unparallelized device drivers.
149 */
150 processor_ptr[0] = &processor_array[0];
151 master_cpu = 0;
152 master_processor = cpu_to_processor(master_cpu);
153
154 static_memory_end = round_page_32(args->topOfKernelData);;
155
156 PE_init_platform(FALSE, args); /* Get platform expert set up */
157
158 if (!PE_parse_boot_arg("novmx", &novmx)) novmx=0; /* Special run without VMX? */
159 if(novmx) { /* Yeah, turn it off */
160 for(i = 0; i < NCPUS; i++) { /* Cycle through all potential processors */
161 per_proc_info[i].pf.Available &= ~pfAltivec; /* Turn off Altivec available */
162 }
163 __asm__ volatile("mtsprg 2,%0" : : "r" (per_proc_info[0].pf.Available)); /* Set live value */
164 }
165
166 if (!PE_parse_boot_arg("fn", &forcenap)) forcenap = 0; /* If force nap not set, make 0 */
167 else {
168 if(forcenap < 2) forcenap = forcenap + 1; /* Else set 1 for off, 2 for on */
169 else forcenap = 0; /* Clear for error case */
170 }
171
172 if (!PE_parse_boot_arg("diag", &dgWork.dgFlags)) dgWork.dgFlags=0; /* Set diagnostic flags */
173 if(dgWork.dgFlags & enaExpTrace) trcWork.traceMask = 0xFFFFFFFF; /* If tracing requested, enable it */
174
175 if(PE_parse_boot_arg("ctrc", &cputrace)) { /* See if tracing is limited to a specific cpu */
176 trcWork.traceMask = (trcWork.traceMask & 0xFFFFFFF0) | (cputrace & 0xF); /* Limit to 4 */
177 }
178
179 if(!PE_parse_boot_arg("tb", &trcWork.traceSize)) { /* See if non-default trace buffer size */
180 #if DEBUG
181 trcWork.traceSize = 32; /* Default 32 page trace table for DEBUG */
182 #else
183 trcWork.traceSize = 8; /* Default 8 page trace table for RELEASE */
184 #endif
185 }
186
187 if(trcWork.traceSize < 1) trcWork.traceSize = 1; /* Minimum size of 1 page */
188 if(trcWork.traceSize > 256) trcWork.traceSize = 256; /* Maximum size of 256 pages */
189 trcWork.traceSize = trcWork.traceSize * 4096; /* Change page count to size */
190
191 if (!PE_parse_boot_arg("maxmem", &maxmem))
192 xmaxmem=0;
193 else
194 xmaxmem = (uint64_t)maxmem * (1024 * 1024);
195
196 /*
197 * VM initialization, after this we're using page tables...
198 */
199
200 ppc_vm_init(xmaxmem, args);
201
202 PE_init_platform(TRUE, args);
203
204 machine_startup(args);
205 }
206
207 ppc_init_cpu(
208 struct per_proc_info *proc_info)
209 {
210 int i;
211
212 if(!(proc_info->next_savearea)) /* Do we have a savearea set up already? */
213 proc_info->next_savearea = (vm_offset_t)save_get_init(); /* Get a savearea */
214
215 cpu_init();
216
217 ppc_vm_cpu_init(proc_info);
218
219 ml_thrm_init(); /* Start thermal monitoring on this processor */
220
221 slave_main();
222 }