ofwgencfg_machdep.c revision 1.10 1 /* $NetBSD: ofwgencfg_machdep.c,v 1.10 2006/10/26 22:49:36 bjh21 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 <sys/cdefs.h>
41 __KERNEL_RCSID(0, "$NetBSD: ofwgencfg_machdep.c,v 1.10 2006/10/26 22:49:36 bjh21 Exp $");
42
43 #include "opt_ddb.h"
44
45 #include <sys/types.h>
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/reboot.h>
49 #include <sys/proc.h>
50 #include <sys/kernel.h>
51 #include <sys/exec.h>
52 #include <sys/ksyms.h>
53
54 #include <uvm/uvm_extern.h>
55
56 #include <dev/cons.h>
57
58 #include <machine/db_machdep.h>
59 #include <ddb/db_sym.h>
60 #include <ddb/db_extern.h>
61
62 #include <machine/frame.h>
63 #include <machine/bootconfig.h>
64 #include <machine/cpu.h>
65 #include <machine/intr.h>
66 #include <arm/arm32/machdep.h>
67 #include <arm/undefined.h>
68
69 #include "opt_ipkdb.h"
70
71 #include <dev/ofw/openfirm.h>
72 #include <machine/ofw.h>
73
74 #include "ksyms.h"
75
76 /*
77 * Imported variables
78 */
79 extern pv_addr_t undstack;
80 extern pv_addr_t abtstack;
81 extern pv_addr_t kernelstack;
82 extern u_int data_abort_handler_address;
83 extern u_int prefetch_abort_handler_address;
84 extern u_int undefined_handler_address;
85
86 /*
87 * Imported routines
88 */
89 extern void data_abort_handler __P((trapframe_t *frame));
90 extern void prefetch_abort_handler __P((trapframe_t *frame));
91 extern void undefinedinstruction_bounce __P((trapframe_t *frame));
92 int ofbus_match __P((struct device *, struct cfdata *, void *));
93 void ofbus_attach __P((struct device *, struct device *, void *));
94
95 /* Local routines */
96 static void process_kernel_args __P((void));
97
98 /*
99 * Exported variables
100 */
101 BootConfig bootconfig;
102 char *boot_args = NULL;
103 char *boot_file = NULL;
104 #ifndef PMAP_STATIC_L1S
105 int max_processes = 64; /* Default number */
106 #endif /* !PMAP_STATIC_L1S */
107
108 int ofw_handleticks = 0; /* set to TRUE by cpu_initclocks */
109
110 CFATTACH_DECL(ofbus_root, sizeof(struct device),
111 ofbus_match, ofbus_attach, NULL, NULL);
112
113 /**************************************************************/
114
115
116 /*
117 * void boot(int howto, char *bootstr)
118 *
119 * Reboots the system, in event of:
120 * - reboot system call
121 * - panic
122 */
123
124 void
125 cpu_reboot(howto, bootstr)
126 int howto;
127 char *bootstr;
128 {
129 /* Just call OFW common routine. */
130 ofw_boot(howto, bootstr);
131
132 OF_boot("not reached -- stupid compiler");
133 }
134
135
136 /*
137 * u_int initarm(ofw_handle_t handle)
138 *
139 * Initial entry point on startup for a GENERIC OFW
140 * system. Called with MMU on, running in the OFW
141 * client environment.
142 *
143 * Major tasks are:
144 * - read the bootargs out of OFW;
145 * - take over memory management from OFW;
146 * - set-up the stacks
147 * - set-up the exception handlers
148 *
149 * Return the new stackptr (va) for the SVC frame.
150 *
151 */
152 u_int
153 initarm(void *cookie)
154 {
155 ofw_handle_t ofw_handle = cookie;
156
157 set_cpufuncs();
158
159 /* XXX - set this somewhere else? -JJK */
160 boothowto = 0;
161
162 /* Init the OFW interface. */
163 /* MUST do this before invoking any OFW client services! */
164 ofw_init(ofw_handle);
165
166 /* Initialize the console (which will call into OFW). */
167 /* This will allow us to see panic messages and other printf output. */
168 consinit();
169
170 /* Get boot info and process it. */
171 ofw_getbootinfo(&boot_file, &boot_args);
172 process_kernel_args();
173
174 /* Configure memory. */
175 ofw_configmem();
176
177 /*
178 * Set-up stacks.
179 * OFW has control of the interrupt frame.
180 * The kernel stack for SVC mode will be updated on return from
181 * this routine. All we need to do is prepare for abort-handling
182 * and undefined exceptions.
183 */
184 set_stackptr(PSR_UND32_MODE, undstack.pv_va + PAGE_SIZE);
185 set_stackptr(PSR_ABT32_MODE, abtstack.pv_va + PAGE_SIZE);
186
187 /* Set-up exception handlers.
188 * Take control of selected vectors from OFW.
189 * We take: undefined, swi, pre-fetch abort, data abort, addrexc
190 * OFW retains: reset, irq, fiq
191 */
192 arm32_vector_init(ARM_VECTORS_LOW,
193 ARM_VEC_ALL & ~(ARM_VEC_RESET|ARM_VEC_IRQ|ARM_VEC_FIQ));
194
195 data_abort_handler_address = (u_int)data_abort_handler;
196 prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
197 undefined_handler_address =
198 (u_int)undefinedinstruction_bounce; /* why is this needed? -JJK */
199
200 /* Initialise the undefined instruction handlers. */
201 undefined_init();
202
203 /* Set-up the IRQ system. */
204 irq_init();
205
206 #if NKSYMS || defined(DDB) || defined(LKM)
207 #ifdef __ELF__
208 ksyms_init(0, NULL, NULL); /* XXX */
209 #else
210 {
211 struct exec *kernexec = (struct exec *)KERNEL_TEXT_BASE;
212 extern int end;
213 extern char *esym;
214
215 ksyms_init(kernexec->a_syms, &end, esym);
216 }
217 #endif /* __ELF__ */
218 #endif
219
220 #ifdef DDB
221 db_machine_init();
222 if (boothowto & RB_KDB)
223 Debugger();
224 #endif
225
226 /* Return the new stackbase. */
227 return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
228 }
229
230
231 /*
232 * Set various globals based on contents of boot_args
233 *
234 * Note that this routine must NOT trash boot_args, as
235 * it is scanned by later routines.
236 *
237 * There ought to be a routine in machdep.c that does
238 * the generic bits of this. -JJK
239 */
240 static void
241 process_kernel_args(void)
242 {
243 /* Process all the generic ARM boot options */
244 parse_mi_bootargs(boot_args);
245
246 /* Check for ofwgencfg-specific args here. */
247 }
248
249
250 /*
251 * Walk the OFW device tree and configure found devices.
252 *
253 * Move this into common OFW module? -JJK
254 */
255 void
256 ofrootfound(void)
257 {
258 int node;
259 struct ofbus_attach_args aa;
260
261 if (!(node = OF_peer(0)))
262 panic("No OFW root");
263 aa.oba_busname = "ofw";
264 aa.oba_phandle = node;
265 if (!config_rootfound("ofbus", &aa))
266 panic("ofw root ofbus not configured");
267 }
268