ofwgencfg_machdep.c revision 1.17 1 1.17 dsl /* $NetBSD: ofwgencfg_machdep.c,v 1.17 2009/03/14 15:36:02 dsl 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.17 dsl __KERNEL_RCSID(0, "$NetBSD: ofwgencfg_machdep.c,v 1.17 2009/03/14 15:36:02 dsl 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.11 matt #include <machine/irqhandler.h>
67 1.9 bjh21 #include <arm/arm32/machdep.h>
68 1.1 thorpej #include <arm/undefined.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.16 dsl extern void data_abort_handler(trapframe_t *frame);
89 1.16 dsl extern void prefetch_abort_handler(trapframe_t *frame);
90 1.16 dsl extern void undefinedinstruction_bounce(trapframe_t *frame);
91 1.16 dsl int ofbus_match(struct device *, struct cfdata *, void *);
92 1.16 dsl void ofbus_attach(struct device *, struct device *, void *);
93 1.1 thorpej
94 1.1 thorpej /* Local routines */
95 1.16 dsl static void process_kernel_args(void);
96 1.1 thorpej
97 1.1 thorpej /*
98 1.1 thorpej * Exported variables
99 1.1 thorpej */
100 1.1 thorpej BootConfig bootconfig;
101 1.1 thorpej char *boot_args = NULL;
102 1.1 thorpej char *boot_file = NULL;
103 1.1 thorpej #ifndef PMAP_STATIC_L1S
104 1.1 thorpej int max_processes = 64; /* Default number */
105 1.1 thorpej #endif /* !PMAP_STATIC_L1S */
106 1.1 thorpej
107 1.1 thorpej int ofw_handleticks = 0; /* set to TRUE by cpu_initclocks */
108 1.1 thorpej
109 1.4 thorpej CFATTACH_DECL(ofbus_root, sizeof(struct device),
110 1.4 thorpej ofbus_match, ofbus_attach, NULL, NULL);
111 1.1 thorpej
112 1.1 thorpej /**************************************************************/
113 1.1 thorpej
114 1.1 thorpej
115 1.1 thorpej /*
116 1.1 thorpej * void boot(int howto, char *bootstr)
117 1.1 thorpej *
118 1.1 thorpej * Reboots the system, in event of:
119 1.1 thorpej * - reboot system call
120 1.1 thorpej * - panic
121 1.1 thorpej */
122 1.1 thorpej
123 1.1 thorpej void
124 1.17 dsl cpu_reboot(int howto, 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.10 bjh21 * u_int 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.10 bjh21 u_int
150 1.10 bjh21 initarm(void *cookie)
151 1.1 thorpej {
152 1.10 bjh21 ofw_handle_t ofw_handle = cookie;
153 1.10 bjh21
154 1.1 thorpej set_cpufuncs();
155 1.1 thorpej
156 1.1 thorpej /* XXX - set this somewhere else? -JJK */
157 1.1 thorpej boothowto = 0;
158 1.1 thorpej
159 1.1 thorpej /* Init the OFW interface. */
160 1.1 thorpej /* MUST do this before invoking any OFW client services! */
161 1.1 thorpej ofw_init(ofw_handle);
162 1.1 thorpej
163 1.1 thorpej /* Initialize the console (which will call into OFW). */
164 1.1 thorpej /* This will allow us to see panic messages and other printf output. */
165 1.1 thorpej consinit();
166 1.1 thorpej
167 1.1 thorpej /* Get boot info and process it. */
168 1.1 thorpej ofw_getbootinfo(&boot_file, &boot_args);
169 1.1 thorpej process_kernel_args();
170 1.1 thorpej
171 1.1 thorpej /* Configure memory. */
172 1.1 thorpej ofw_configmem();
173 1.1 thorpej
174 1.1 thorpej /*
175 1.1 thorpej * Set-up stacks.
176 1.1 thorpej * OFW has control of the interrupt frame.
177 1.1 thorpej * The kernel stack for SVC mode will be updated on return from
178 1.1 thorpej * this routine. All we need to do is prepare for abort-handling
179 1.1 thorpej * and undefined exceptions.
180 1.1 thorpej */
181 1.5 thorpej set_stackptr(PSR_UND32_MODE, undstack.pv_va + PAGE_SIZE);
182 1.5 thorpej set_stackptr(PSR_ABT32_MODE, abtstack.pv_va + PAGE_SIZE);
183 1.1 thorpej
184 1.1 thorpej /* Set-up exception handlers.
185 1.1 thorpej * Take control of selected vectors from OFW.
186 1.1 thorpej * We take: undefined, swi, pre-fetch abort, data abort, addrexc
187 1.1 thorpej * OFW retains: reset, irq, fiq
188 1.1 thorpej */
189 1.2 thorpej arm32_vector_init(ARM_VECTORS_LOW,
190 1.2 thorpej ARM_VEC_ALL & ~(ARM_VEC_RESET|ARM_VEC_IRQ|ARM_VEC_FIQ));
191 1.1 thorpej
192 1.1 thorpej data_abort_handler_address = (u_int)data_abort_handler;
193 1.1 thorpej prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
194 1.1 thorpej undefined_handler_address =
195 1.1 thorpej (u_int)undefinedinstruction_bounce; /* why is this needed? -JJK */
196 1.1 thorpej
197 1.1 thorpej /* Initialise the undefined instruction handlers. */
198 1.1 thorpej undefined_init();
199 1.1 thorpej
200 1.1 thorpej /* Set-up the IRQ system. */
201 1.1 thorpej irq_init();
202 1.1 thorpej
203 1.6 ragge #ifdef DDB
204 1.6 ragge db_machine_init();
205 1.1 thorpej if (boothowto & RB_KDB)
206 1.1 thorpej Debugger();
207 1.1 thorpej #endif
208 1.1 thorpej
209 1.1 thorpej /* Return the new stackbase. */
210 1.1 thorpej return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
211 1.1 thorpej }
212 1.1 thorpej
213 1.1 thorpej
214 1.1 thorpej /*
215 1.1 thorpej * Set various globals based on contents of boot_args
216 1.1 thorpej *
217 1.1 thorpej * Note that this routine must NOT trash boot_args, as
218 1.1 thorpej * it is scanned by later routines.
219 1.1 thorpej *
220 1.1 thorpej * There ought to be a routine in machdep.c that does
221 1.1 thorpej * the generic bits of this. -JJK
222 1.1 thorpej */
223 1.1 thorpej static void
224 1.1 thorpej process_kernel_args(void)
225 1.1 thorpej {
226 1.1 thorpej /* Process all the generic ARM boot options */
227 1.1 thorpej parse_mi_bootargs(boot_args);
228 1.1 thorpej
229 1.1 thorpej /* Check for ofwgencfg-specific args here. */
230 1.1 thorpej }
231 1.1 thorpej
232 1.1 thorpej
233 1.1 thorpej /*
234 1.1 thorpej * Walk the OFW device tree and configure found devices.
235 1.1 thorpej *
236 1.1 thorpej * Move this into common OFW module? -JJK
237 1.1 thorpej */
238 1.1 thorpej void
239 1.1 thorpej ofrootfound(void)
240 1.1 thorpej {
241 1.1 thorpej int node;
242 1.1 thorpej struct ofbus_attach_args aa;
243 1.1 thorpej
244 1.1 thorpej if (!(node = OF_peer(0)))
245 1.1 thorpej panic("No OFW root");
246 1.1 thorpej aa.oba_busname = "ofw";
247 1.1 thorpej aa.oba_phandle = node;
248 1.1 thorpej if (!config_rootfound("ofbus", &aa))
249 1.1 thorpej panic("ofw root ofbus not configured");
250 1.1 thorpej }
251