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