2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
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
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.
23 * @APPLE_LICENSE_HEADER_END@
30 #include <mach_ldebug.h>
34 #include <kern/misc_protos.h>
35 #include <kern/thread.h>
36 #include <kern/processor.h>
37 #include <machine/machine_routines.h>
39 #include <ppc/proc_reg.h>
40 #include <ppc/misc_protos.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>
49 #include <ppc/mappings.h>
51 #include <pexpert/pexpert.h>
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 */
57 int pc_trace_buf
[1024] = {0};
58 int pc_trace_cnt
= 1024;
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
;
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
,
87 &retfsectPatch_isync
, 0x60000000, PATCH_FEATURE
, PatchLwsync
,
88 &retfsectPatch_eieio
, 0x7c2004ac, PATCH_FEATURE
, PatchLwsync
90 0, 0, PATCH_INVALID
, 0,
91 0, 0, PATCH_INVALID
, 0
95 void ppc_init(boot_args
*args
)
98 unsigned long *src
,*dst
;
100 unsigned long addr
, videoAddr
;
103 unsigned int cputrace
;
105 extern vm_offset_t static_memory_end
;
110 * Setup per_proc info for first cpu.
113 per_proc_info
[0].cpu_number
= 0;
114 per_proc_info
[0].cpu_flags
= 0;
115 per_proc_info
[0].istackptr
= 0; /* we're on the interrupt stack */
116 per_proc_info
[0].intstack_top_ss
= intstack_top_ss
;
117 per_proc_info
[0].debstackptr
= debstackptr
;
118 per_proc_info
[0].debstack_top_ss
= debstack_top_ss
;
119 per_proc_info
[0].interrupts_enabled
= 0;
120 per_proc_info
[0].pp_preemption_count
= -1;
121 per_proc_info
[0].pp_simple_lock_count
= 0;
122 per_proc_info
[0].pp_interrupt_level
= 0;
123 per_proc_info
[0].need_ast
= (unsigned int)&need_ast
[0];
124 per_proc_info
[0].FPU_owner
= 0;
125 per_proc_info
[0].VMX_owner
= 0;
126 mp
= (mapping
*)per_proc_info
[0].ppCIOmp
;
127 mp
->mpFlags
= 0x01000000 | mpSpecial
| 1;
128 mp
->mpSpace
= invalSpace
;
130 machine_slot
[0].is_cpu
= TRUE
;
134 thread
= current_act();
135 thread
->mact
.curctx
= &thread
->mact
.facctx
;
136 thread
->mact
.facctx
.facAct
= thread
;
137 thread
->mact
.cioSpace
= invalSpace
; /* Initialize copyin/out space to invalid */
138 thread
->mact
.preemption_count
= 1;
143 * Setup some processor related structures to satisfy funnels.
144 * Must be done before using unparallelized device drivers.
146 processor_ptr
[0] = &processor_array
[0];
148 master_processor
= cpu_to_processor(master_cpu
);
150 static_memory_end
= round_page_32(args
->topOfKernelData
);;
152 PE_init_platform(FALSE
, args
); /* Get platform expert set up */
154 if (!PE_parse_boot_arg("novmx", &novmx
)) novmx
=0; /* Special run without VMX? */
155 if(novmx
) { /* Yeah, turn it off */
156 for(i
= 0; i
< NCPUS
; i
++) { /* Cycle through all potential processors */
157 per_proc_info
[i
].pf
.Available
&= ~pfAltivec
; /* Turn off Altivec available */
159 __asm__
volatile("mtsprg 2,%0" : : "r" (per_proc_info
[0].pf
.Available
)); /* Set live value */
162 if (!PE_parse_boot_arg("fn", &forcenap
)) forcenap
= 0; /* If force nap not set, make 0 */
164 if(forcenap
< 2) forcenap
= forcenap
+ 1; /* Else set 1 for off, 2 for on */
165 else forcenap
= 0; /* Clear for error case */
168 if (!PE_parse_boot_arg("diag", &dgWork
.dgFlags
)) dgWork
.dgFlags
=0; /* Set diagnostic flags */
169 if(dgWork
.dgFlags
& enaExpTrace
) trcWork
.traceMask
= 0xFFFFFFFF; /* If tracing requested, enable it */
171 if(PE_parse_boot_arg("ctrc", &cputrace
)) { /* See if tracing is limited to a specific cpu */
172 trcWork
.traceMask
= (trcWork
.traceMask
& 0xFFFFFFF0) | (cputrace
& 0xF); /* Limit to 4 */
175 if(!PE_parse_boot_arg("tb", &trcWork
.traceSize
)) { /* See if non-default trace buffer size */
177 trcWork
.traceSize
= 32; /* Default 32 page trace table for DEBUG */
179 trcWork
.traceSize
= 8; /* Default 8 page trace table for RELEASE */
183 if(trcWork
.traceSize
< 1) trcWork
.traceSize
= 1; /* Minimum size of 1 page */
184 if(trcWork
.traceSize
> 256) trcWork
.traceSize
= 256; /* Maximum size of 256 pages */
185 trcWork
.traceSize
= trcWork
.traceSize
* 4096; /* Change page count to size */
187 if (!PE_parse_boot_arg("maxmem", &maxmem
))
190 xmaxmem
= (uint64_t)maxmem
* (1024 * 1024);
193 * VM initialization, after this we're using page tables...
196 ppc_vm_init(xmaxmem
, args
);
198 PE_init_platform(TRUE
, args
);
200 machine_startup(args
);
204 struct per_proc_info
*proc_info
)
208 proc_info
->cpu_flags
&= ~SleepState
;
210 if(!(proc_info
->next_savearea
)) /* Do we have a savearea set up already? */
211 proc_info
->next_savearea
= (uint64_t)save_get_init(); /* Get a savearea */
215 ppc_vm_cpu_init(proc_info
);
217 ml_thrm_init(); /* Start thermal monitoring on this processor */