ofwgencfg_machdep.c revision 1.6 1 /* $NetBSD: ofwgencfg_machdep.c,v 1.6 2003/04/26 11:05:08 ragge Exp $ */
2
3 /*
4 * Copyright 1997
5 * Digital Equipment Corporation. All rights reserved.
6 *
7 * This software is furnished under license and may be used and
8 * copied only in accordance with the following terms and conditions.
9 * Subject to these conditions, you may download, copy, install,
10 * use, modify and distribute this software in source and/or binary
11 * form. No title or ownership is transferred hereby.
12 *
13 * 1) Any source code used, modified or distributed must reproduce
14 * and retain this copyright notice and list of conditions as
15 * they appear in the source file.
16 *
17 * 2) No right is granted to use any trade name, trademark, or logo of
18 * Digital Equipment Corporation. Neither the "Digital Equipment
19 * Corporation" name nor any trademark or logo of Digital Equipment
20 * Corporation may be used to endorse or promote products derived
21 * from this software without the prior written permission of
22 * Digital Equipment Corporation.
23 *
24 * 3) This software is provided "AS-IS" and any express or implied
25 * warranties, including but not limited to, any implied warranties
26 * of merchantability, fitness for a particular purpose, or
27 * non-infringement are disclaimed. In no event shall DIGITAL be
28 * liable for any damages whatsoever, and in particular, DIGITAL
29 * shall not be liable for special, indirect, consequential, or
30 * incidental damages or damages for lost profits, loss of
31 * revenue or loss of use, whether such damages arise in contract,
32 * negligence, tort, under statute, in equity, at law or otherwise,
33 * even if advised of the possibility of such damage.
34 */
35
36 /*
37 * Kernel setup for the OFW Generic Configuration
38 */
39
40 #include "opt_ddb.h"
41
42 #include <sys/types.h>
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/reboot.h>
46 #include <sys/proc.h>
47 #include <sys/kernel.h>
48 #include <sys/exec.h>
49 #include <sys/ksyms.h>
50
51 #include <uvm/uvm_extern.h>
52
53 #include <dev/cons.h>
54
55 #include <machine/db_machdep.h>
56 #include <ddb/db_sym.h>
57 #include <ddb/db_extern.h>
58
59 #include <machine/frame.h>
60 #include <machine/bootconfig.h>
61 #include <machine/cpu.h>
62 #include <machine/intr.h>
63 #include <arm/undefined.h>
64
65 #include "opt_ipkdb.h"
66
67 #include <dev/ofw/openfirm.h>
68 #include <machine/ofw.h>
69
70 #include "ksyms.h"
71
72 /*
73 * Imported variables
74 */
75 extern pv_addr_t undstack;
76 extern pv_addr_t abtstack;
77 extern pv_addr_t kernelstack;
78 extern u_int data_abort_handler_address;
79 extern u_int prefetch_abort_handler_address;
80 extern u_int undefined_handler_address;
81
82 /*
83 * Imported routines
84 */
85 extern void parse_mi_bootargs __P((char *args));
86 extern void data_abort_handler __P((trapframe_t *frame));
87 extern void prefetch_abort_handler __P((trapframe_t *frame));
88 extern void undefinedinstruction_bounce __P((trapframe_t *frame));
89 int ofbus_match __P((struct device *, struct cfdata *, void *));
90 void ofbus_attach __P((struct device *, struct device *, void *));
91
92 /* Local routines */
93 static void process_kernel_args __P((void));
94
95 /*
96 * Exported variables
97 */
98 BootConfig bootconfig;
99 char *boot_args = NULL;
100 char *boot_file = NULL;
101 #ifndef PMAP_STATIC_L1S
102 int max_processes = 64; /* Default number */
103 #endif /* !PMAP_STATIC_L1S */
104
105 int ofw_handleticks = 0; /* set to TRUE by cpu_initclocks */
106
107 CFATTACH_DECL(ofbus_root, sizeof(struct device),
108 ofbus_match, ofbus_attach, NULL, NULL);
109
110 /**************************************************************/
111
112
113 /*
114 * void boot(int howto, char *bootstr)
115 *
116 * Reboots the system, in event of:
117 * - reboot system call
118 * - panic
119 */
120
121 void
122 cpu_reboot(howto, bootstr)
123 int howto;
124 char *bootstr;
125 {
126 /* Just call OFW common routine. */
127 ofw_boot(howto, bootstr);
128
129 OF_boot("not reached -- stupid compiler");
130 }
131
132
133 /*
134 * vaddr_t initarm(ofw_handle_t handle)
135 *
136 * Initial entry point on startup for a GENERIC OFW
137 * system. Called with MMU on, running in the OFW
138 * client environment.
139 *
140 * Major tasks are:
141 * - read the bootargs out of OFW;
142 * - take over memory management from OFW;
143 * - set-up the stacks
144 * - set-up the exception handlers
145 *
146 * Return the new stackptr (va) for the SVC frame.
147 *
148 */
149 vaddr_t
150 initarm(ofw_handle)
151 ofw_handle_t ofw_handle;
152 {
153 set_cpufuncs();
154
155 /* XXX - set this somewhere else? -JJK */
156 boothowto = 0;
157
158 /* Init the OFW interface. */
159 /* MUST do this before invoking any OFW client services! */
160 ofw_init(ofw_handle);
161
162 /* Initialize the console (which will call into OFW). */
163 /* This will allow us to see panic messages and other printf output. */
164 consinit();
165
166 /* Get boot info and process it. */
167 ofw_getbootinfo(&boot_file, &boot_args);
168 process_kernel_args();
169
170 /* Configure memory. */
171 ofw_configmem();
172
173 /*
174 * Set-up stacks.
175 * OFW has control of the interrupt frame.
176 * The kernel stack for SVC mode will be updated on return from
177 * this routine. All we need to do is prepare for abort-handling
178 * and undefined exceptions.
179 */
180 set_stackptr(PSR_UND32_MODE, undstack.pv_va + PAGE_SIZE);
181 set_stackptr(PSR_ABT32_MODE, abtstack.pv_va + PAGE_SIZE);
182
183 /* Set-up exception handlers.
184 * Take control of selected vectors from OFW.
185 * We take: undefined, swi, pre-fetch abort, data abort, addrexc
186 * OFW retains: reset, irq, fiq
187 */
188 arm32_vector_init(ARM_VECTORS_LOW,
189 ARM_VEC_ALL & ~(ARM_VEC_RESET|ARM_VEC_IRQ|ARM_VEC_FIQ));
190
191 data_abort_handler_address = (u_int)data_abort_handler;
192 prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
193 undefined_handler_address =
194 (u_int)undefinedinstruction_bounce; /* why is this needed? -JJK */
195
196 /* Initialise the undefined instruction handlers. */
197 undefined_init();
198
199 /* Set-up the IRQ system. */
200 irq_init();
201
202 #if NKSYMS || defined(DDB) || defined(LKM)
203 #ifdef __ELF__
204 ksyms_init(0, NULL, NULL); /* XXX */
205 #else
206 {
207 struct exec *kernexec = (struct exec *)KERNEL_TEXT_BASE;
208 extern int end;
209 extern char *esym;
210
211 ksyms_init(kernexec->a_syms, &end, esym);
212 }
213 #endif /* __ELF__ */
214 #endif
215
216 #ifdef DDB
217 db_machine_init();
218 if (boothowto & RB_KDB)
219 Debugger();
220 #endif
221
222 /* Return the new stackbase. */
223 return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
224 }
225
226
227 /*
228 * Set various globals based on contents of boot_args
229 *
230 * Note that this routine must NOT trash boot_args, as
231 * it is scanned by later routines.
232 *
233 * There ought to be a routine in machdep.c that does
234 * the generic bits of this. -JJK
235 */
236 static void
237 process_kernel_args(void)
238 {
239 /* Process all the generic ARM boot options */
240 parse_mi_bootargs(boot_args);
241
242 /* Check for ofwgencfg-specific args here. */
243 }
244
245
246 /*
247 * Walk the OFW device tree and configure found devices.
248 *
249 * Move this into common OFW module? -JJK
250 */
251 void
252 ofrootfound(void)
253 {
254 int node;
255 struct ofbus_attach_args aa;
256
257 if (!(node = OF_peer(0)))
258 panic("No OFW root");
259 aa.oba_busname = "ofw";
260 aa.oba_phandle = node;
261 if (!config_rootfound("ofbus", &aa))
262 panic("ofw root ofbus not configured");
263 }
264