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