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
;
109 * Setup per_proc info for first cpu.
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)
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)
134 per_proc_info
[0].need_ast
= (unsigned int)
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
;
142 machine_slot
[0].is_cpu
= TRUE
;
147 * Setup some processor related structures to satisfy funnels.
148 * Must be done before using unparallelized device drivers.
150 processor_ptr
[0] = &processor_array
[0];
152 master_processor
= cpu_to_processor(master_cpu
);
154 static_memory_end
= round_page_32(args
->topOfKernelData
);;
156 PE_init_platform(FALSE
, args
); /* Get platform expert set up */
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 */
163 __asm__
volatile("mtsprg 2,%0" : : "r" (per_proc_info
[0].pf
.Available
)); /* Set live value */
166 if (!PE_parse_boot_arg("fn", &forcenap
)) forcenap
= 0; /* If force nap not set, make 0 */
168 if(forcenap
< 2) forcenap
= forcenap
+ 1; /* Else set 1 for off, 2 for on */
169 else forcenap
= 0; /* Clear for error case */
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 */
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 */
179 if(!PE_parse_boot_arg("tb", &trcWork
.traceSize
)) { /* See if non-default trace buffer size */
181 trcWork
.traceSize
= 32; /* Default 32 page trace table for DEBUG */
183 trcWork
.traceSize
= 8; /* Default 8 page trace table for RELEASE */
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 */
191 if (!PE_parse_boot_arg("maxmem", &maxmem
))
194 xmaxmem
= (uint64_t)maxmem
* (1024 * 1024);
197 * VM initialization, after this we're using page tables...
200 ppc_vm_init(xmaxmem
, args
);
202 PE_init_platform(TRUE
, args
);
204 machine_startup(args
);
208 struct per_proc_info
*proc_info
)
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 */
217 ppc_vm_cpu_init(proc_info
);
219 ml_thrm_init(); /* Start thermal monitoring on this processor */