2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
35 #include <mach_ldebug.h>
39 #include <kern/misc_protos.h>
40 #include <kern/thread.h>
41 #include <kern/processor.h>
42 #include <kern/startup.h>
43 #include <machine/machine_routines.h>
45 #include <ppc/proc_reg.h>
46 #include <ppc/misc_protos.h>
48 #include <ppc/new_screen.h>
49 #include <ppc/exception.h>
51 #include <ppc/Firmware.h>
52 #include <ppc/savearea.h>
53 #include <ppc/low_trace.h>
54 #include <ppc/Diagnostics.h>
55 #include <ppc/cpu_internal.h>
57 #include <ppc/mappings.h>
58 #include <ppc/locks.h>
60 #include <ppc/rtclock.h>
62 #include <pexpert/pexpert.h>
64 extern unsigned int mckFlags
;
65 extern vm_offset_t intstack
;
66 extern vm_offset_t debstack
;
68 int pc_trace_buf
[1024] = {0};
69 int pc_trace_cnt
= 1024;
71 extern unsigned int extPatchMCK
;
72 extern unsigned int extPatch32
;
73 extern unsigned int hwulckPatch_isync
;
74 extern unsigned int hwulckPatch_eieio
;
75 extern unsigned int hwulckbPatch_isync
;
76 extern unsigned int hwulckbPatch_eieio
;
77 extern unsigned int mulckPatch_isync
;
78 extern unsigned int mulckPatch_eieio
;
79 extern unsigned int mulckePatch_isync
;
80 extern unsigned int mulckePatch_eieio
;
81 extern unsigned int sulckPatch_isync
;
82 extern unsigned int sulckPatch_eieio
;
83 extern unsigned int rwlesPatch_isync
;
84 extern unsigned int rwlesPatch_eieio
;
85 extern unsigned int rwldPatch_isync
;
86 extern unsigned int rwldPatch_eieio
;
87 extern unsigned int retfsectPatch_eieio
;
88 extern unsigned int retfsectPatch_isync
;
89 extern unsigned int bcopy_nop_if_32bit
;
90 extern unsigned int bcopy_nc_nop_if_32bit
;
91 extern unsigned int memcpy_nop_if_32bit
;
92 extern unsigned int xsum_nop_if_32bit
;
93 extern unsigned int uft_nop_if_32bit
;
94 extern unsigned int uft_uaw_nop_if_32bit
;
95 extern unsigned int uft_cuttrace
;
98 int wcte
= 0; /* Non-cache gather timer disabled */
100 patch_entry_t patch_table
[] = {
101 {&extPatch32
, 0x60000000, PATCH_FEATURE
, PatchExt32
},
102 {&extPatchMCK
, 0x60000000, PATCH_PROCESSOR
, CPU_SUBTYPE_POWERPC_970
},
103 {&hwulckPatch_isync
, 0x60000000, PATCH_FEATURE
, PatchLwsync
},
104 {&hwulckPatch_eieio
, 0x7c2004ac, PATCH_FEATURE
, PatchLwsync
},
105 {&hwulckbPatch_isync
, 0x60000000, PATCH_FEATURE
, PatchLwsync
},
106 {&hwulckbPatch_eieio
, 0x7c2004ac, PATCH_FEATURE
, PatchLwsync
},
107 {&mulckPatch_isync
, 0x60000000, PATCH_FEATURE
, PatchLwsync
},
108 {&mulckPatch_eieio
, 0x7c2004ac, PATCH_FEATURE
, PatchLwsync
},
109 {&mulckePatch_isync
, 0x60000000, PATCH_FEATURE
, PatchLwsync
},
110 {&mulckePatch_eieio
, 0x7c2004ac, PATCH_FEATURE
, PatchLwsync
},
111 {&sulckPatch_isync
, 0x60000000, PATCH_FEATURE
, PatchLwsync
},
112 {&sulckPatch_eieio
, 0x7c2004ac, PATCH_FEATURE
, PatchLwsync
},
113 {&rwlesPatch_isync
, 0x60000000, PATCH_FEATURE
, PatchLwsync
},
114 {&rwlesPatch_eieio
, 0x7c2004ac, PATCH_FEATURE
, PatchLwsync
},
115 {&rwldPatch_isync
, 0x60000000, PATCH_FEATURE
, PatchLwsync
},
116 {&rwldPatch_eieio
, 0x7c2004ac, PATCH_FEATURE
, PatchLwsync
},
117 {&bcopy_nop_if_32bit
, 0x60000000, PATCH_FEATURE
, PatchExt32
},
118 {&bcopy_nc_nop_if_32bit
,0x60000000, PATCH_FEATURE
, PatchExt32
},
119 {&memcpy_nop_if_32bit
, 0x60000000, PATCH_FEATURE
, PatchExt32
},
121 {&retfsectPatch_isync
, 0x60000000, PATCH_FEATURE
, PatchLwsync
},
122 {&retfsectPatch_eieio
, 0x7c2004ac, PATCH_FEATURE
, PatchLwsync
},
124 {&xsum_nop_if_32bit
, 0x60000000, PATCH_FEATURE
, PatchExt32
},
125 {&uft_nop_if_32bit
, 0x60000000, PATCH_FEATURE
, PatchExt32
},
126 {&uft_uaw_nop_if_32bit
, 0x60000000, PATCH_FEATURE
, PatchExt32
},
127 {&uft_cuttrace
, 0x60000000, PATCH_FEATURE
, PatchExt32
},
128 {NULL
, 0x00000000, PATCH_END_OF_TABLE
, 0}
139 struct per_proc_info
*proc_info
);
152 unsigned int cputrace
;
154 unsigned int mcksoft
;
162 * Setup per_proc info for first cpu.
165 BootProcInfo
.cpu_number
= 0;
166 BootProcInfo
.cpu_flags
= 0;
167 BootProcInfo
.istackptr
= 0; /* we're on the interrupt stack */
168 BootProcInfo
.intstack_top_ss
= (vm_offset_t
)&intstack
+ INTSTACK_SIZE
- FM_SIZE
;
169 BootProcInfo
.debstack_top_ss
= (vm_offset_t
)&debstack
+ KERNEL_STACK_SIZE
- FM_SIZE
;
170 BootProcInfo
.debstackptr
= BootProcInfo
.debstack_top_ss
;
171 BootProcInfo
.interrupts_enabled
= 0;
172 BootProcInfo
.pending_ast
= AST_NONE
;
173 BootProcInfo
.FPU_owner
= 0;
174 BootProcInfo
.VMX_owner
= 0;
175 BootProcInfo
.pp_cbfr
= console_per_proc_alloc(TRUE
);
176 BootProcInfo
.rtcPop
= EndOfAllTime
;
177 BootProcInfo
.pp2ndPage
= (addr64_t
)&BootProcInfo
; /* Initial physical address of the second page */
179 BootProcInfo
.pms
.pmsStamp
= 0; /* Dummy transition time */
180 BootProcInfo
.pms
.pmsPop
= EndOfAllTime
; /* Set the pop way into the future */
182 BootProcInfo
.pms
.pmsState
= pmsParked
; /* Park the power stepper */
183 BootProcInfo
.pms
.pmsCSetCmd
= pmsCInit
; /* Set dummy initial hardware state */
185 mp
= (mapping_t
*)BootProcInfo
.ppUMWmp
;
186 mp
->mpFlags
= 0x01000000 | mpLinkage
| mpPerm
| 1;
187 mp
->mpSpace
= invalSpace
;
189 pmsInit(); /* Initialize the stepper */
193 thread
= current_thread();
194 thread
->machine
.curctx
= &thread
->machine
.facctx
;
195 thread
->machine
.facctx
.facAct
= thread
;
196 thread
->machine
.umwSpace
= invalSpace
; /* Initialize user memory window space to invalid */
197 thread
->machine
.preemption_count
= 1;
203 processor_bootstrap();
205 timer_switch((uint32_t)mach_absolute_time(), &thread
->system_timer
);
207 static_memory_end
= round_page(args
->topOfKernelData
);;
209 PE_init_platform(FALSE
, args
); /* Get platform expert set up */
211 if (!PE_parse_boot_arg("novmx", &novmx
)) novmx
=0; /* Special run without VMX? */
212 if(novmx
) { /* Yeah, turn it off */
213 BootProcInfo
.pf
.Available
&= ~pfAltivec
; /* Turn off Altivec available */
214 __asm__
volatile("mtsprg 2,%0" : : "r" (BootProcInfo
.pf
.Available
)); /* Set live value */
217 if (!PE_parse_boot_arg("fn", &forcenap
)) forcenap
= 0; /* If force nap not set, make 0 */
219 if(forcenap
< 2) forcenap
= forcenap
+ 1; /* Else set 1 for off, 2 for on */
220 else forcenap
= 0; /* Clear for error case */
223 if (!PE_parse_boot_arg("pmsx", &pmsExperimental
)) pmsExperimental
= 0; /* Check if we should start in experimental power management stepper mode */
224 if (!PE_parse_boot_arg("lcks", &LcksOpts
)) LcksOpts
= 0; /* Set lcks options */
225 if (!PE_parse_boot_arg("diag", &dgWork
.dgFlags
)) dgWork
.dgFlags
= 0; /* Set diagnostic flags */
226 if(dgWork
.dgFlags
& enaExpTrace
) trcWork
.traceMask
= 0xFFFFFFFF; /* If tracing requested, enable it */
228 if(PE_parse_boot_arg("ctrc", &cputrace
)) { /* See if tracing is limited to a specific cpu */
229 trcWork
.traceMask
= (trcWork
.traceMask
& 0xFFFFFFF0) | (cputrace
& 0xF); /* Limit to 4 */
232 if(!PE_parse_boot_arg("tb", &trcWork
.traceSize
)) { /* See if non-default trace buffer size */
234 trcWork
.traceSize
= 32; /* Default 32 page trace table for DEBUG */
236 trcWork
.traceSize
= 8; /* Default 8 page trace table for RELEASE */
240 if(trcWork
.traceSize
< 1) trcWork
.traceSize
= 1; /* Minimum size of 1 page */
241 if(trcWork
.traceSize
> 256) trcWork
.traceSize
= 256; /* Maximum size of 256 pages */
242 trcWork
.traceSize
= trcWork
.traceSize
* 4096; /* Change page count to size */
244 if (!PE_parse_boot_arg("maxmem", &maxmem
))
247 xmaxmem
= (uint64_t)maxmem
* (1024 * 1024);
249 if (!PE_parse_boot_arg("wcte", &wcte
)) wcte
= 0; /* If write combine timer enable not supplied, make 1 */
250 else wcte
= (wcte
!= 0); /* Force to 0 or 1 */
252 if (!PE_parse_boot_arg("mcklog", &mckFlags
)) mckFlags
= 0; /* If machine check flags not specified, clear */
253 else if(mckFlags
> 1) mckFlags
= 0; /* If bogus, clear */
255 if (!PE_parse_boot_arg("ht_shift", &hash_table_shift
)) /* should we use a non-default hash table size? */
256 hash_table_shift
= 0; /* no, use default size */
259 * VM initialization, after this we're using page tables...
262 ppc_vm_init(xmaxmem
, args
);
264 if(BootProcInfo
.pf
.Available
& pf64Bit
) { /* Are we on a 64-bit machine */
267 (void)ml_scom_read(GUSModeReg
<< 8, &scdata
); /* Get GUS mode register */
268 scdata
= scdata
| GUSMstgttoff
; /* Disable the NCU store gather timer */
269 (void)ml_scom_write(GUSModeReg
<< 8, scdata
); /* Get GUS mode register */
272 if(PE_parse_boot_arg("mcksoft", &mcksoft
)) { /* Have they supplied "machine check software recovery? */
273 newhid
= BootProcInfo
.pf
.pfHID5
; /* Get the old HID5 */
275 newhid
&= 0xFFFFFFFFFFFFDFFFULL
; /* Clear the old one */
276 newhid
|= (mcksoft
& 1) << 13; /* Set new value to enable machine check recovery */
277 BootProcInfo
.pf
.pfHID5
= newhid
; /* Set the new one */
278 hid5set64(newhid
); /* Set the hid for this processir */
283 machine_startup(args
);
287 * Routine: ppc_init_cpu
292 struct per_proc_info
*proc_info
)
296 proc_info
->cpu_flags
&= ~SleepState
;
298 if((BootProcInfo
.pf
.Available
& pf64Bit
) && !wcte
) { /* Should we disable the store gather timer? */
299 (void)ml_scom_read(GUSModeReg
<< 8, &scdata
); /* Get GUS mode register */
300 scdata
= scdata
| GUSMstgttoff
; /* Disable the NCU store gather timer */
301 (void)ml_scom_write(GUSModeReg
<< 8, scdata
); /* Get GUS mode register */