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