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