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