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