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