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