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