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