Home | History | Annotate | Line # | Download | only in oea
      1  1.13  thorpej /* $NetBSD: prep_machdep.c,v 1.13 2021/02/27 01:31:23 thorpej Exp $ */
      2   1.2  garbled 
      3   1.2  garbled /*-
      4   1.2  garbled  * Copyright (c) 2007 The NetBSD Foundation, Inc.
      5   1.2  garbled  * All rights reserved.
      6   1.2  garbled  *
      7   1.2  garbled  * This code is derived from software contributed to The NetBSD Foundation
      8   1.2  garbled  * by Tim Rightnour
      9   1.2  garbled  *
     10   1.2  garbled  * Redistribution and use in source and binary forms, with or without
     11   1.2  garbled  * modification, are permitted provided that the following conditions
     12   1.2  garbled  * are met:
     13   1.2  garbled  * 1. Redistributions of source code must retain the above copyright
     14   1.2  garbled  *    notice, this list of conditions and the following disclaimer.
     15   1.2  garbled  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.2  garbled  *    notice, this list of conditions and the following disclaimer in the
     17   1.2  garbled  *    documentation and/or other materials provided with the distribution.
     18   1.2  garbled  *
     19   1.2  garbled  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.2  garbled  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.2  garbled  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.2  garbled  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.2  garbled  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.2  garbled  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.2  garbled  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.2  garbled  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.2  garbled  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.2  garbled  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.2  garbled  * POSSIBILITY OF SUCH DAMAGE.
     30   1.2  garbled  */
     31   1.2  garbled 
     32   1.2  garbled /*
     33   1.2  garbled  * This is a set of general routines that most PReP-similar machines have
     34   1.2  garbled  * in common.  Machines that use these routines do not have to be fully
     35   1.2  garbled  * PReP compliant, the only requirement is that they use a PReP memory map.
     36   1.2  garbled  * IE, io at 0x80000000 and mem at 0xc0000000.
     37   1.2  garbled  */
     38   1.2  garbled 
     39   1.2  garbled #include <sys/cdefs.h>
     40  1.13  thorpej __KERNEL_RCSID(0, "$NetBSD: prep_machdep.c,v 1.13 2021/02/27 01:31:23 thorpej Exp $");
     41   1.6      apb 
     42  1.12      rin #include "ksyms.h"
     43  1.12      rin 
     44  1.12      rin #ifdef _KERNEL_OPT
     45  1.12      rin #include "opt_ddb.h"
     46   1.6      apb #include "opt_modular.h"
     47  1.12      rin #endif
     48   1.2  garbled 
     49   1.2  garbled #include <sys/param.h>
     50   1.2  garbled #include <sys/extent.h>
     51   1.2  garbled #include <sys/kernel.h>
     52   1.2  garbled #include <sys/reboot.h>
     53   1.2  garbled #include <sys/ksyms.h>
     54   1.2  garbled 
     55   1.2  garbled #include <uvm/uvm_extern.h>
     56   1.2  garbled #include <machine/powerpc.h>
     57   1.7   dyoung #include <sys/bus.h>
     58   1.2  garbled #include <machine/pmap.h>
     59   1.2  garbled #include <powerpc/oea/bat.h>
     60   1.2  garbled 
     61   1.2  garbled #ifdef DDB
     62   1.2  garbled #include <machine/db_machdep.h>
     63   1.2  garbled #include <ddb/db_extern.h>
     64   1.2  garbled #endif
     65   1.2  garbled 
     66   1.4       ad #if NKSYMS || defined(DDB) || defined(MODULAR)
     67   1.2  garbled extern void *endsym, *startsym;
     68   1.2  garbled #endif
     69   1.2  garbled extern struct mem_region physmemr[2], availmemr[2];
     70   1.2  garbled 
     71   1.2  garbled struct powerpc_bus_space prep_io_space_tag = {
     72   1.2  garbled 	.pbs_flags = _BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_IO_TYPE,
     73   1.2  garbled 	.pbs_offset = PREP_BUS_SPACE_IO,
     74   1.2  garbled 	.pbs_base = 0x00000000,
     75   1.2  garbled 	.pbs_limit = PREP_PHYS_SIZE_IO,
     76   1.2  garbled };
     77   1.2  garbled 
     78   1.2  garbled struct powerpc_bus_space genppc_isa_io_space_tag = {
     79   1.2  garbled 	.pbs_flags = _BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_IO_TYPE,
     80   1.2  garbled 	.pbs_offset = PREP_BUS_SPACE_IO,
     81   1.2  garbled 	.pbs_base = 0x00000000,
     82   1.2  garbled 	.pbs_limit = PREP_ISA_SIZE_IO,
     83   1.2  garbled };
     84   1.2  garbled 
     85   1.2  garbled struct powerpc_bus_space prep_mem_space_tag = {
     86   1.2  garbled 	.pbs_flags = _BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_MEM_TYPE,
     87   1.2  garbled 	.pbs_offset = PREP_BUS_SPACE_MEM,
     88   1.2  garbled 	.pbs_base = 0x00000000,
     89   1.2  garbled 	.pbs_limit = PREP_PHYS_SIZE_MEM,
     90   1.2  garbled };
     91   1.2  garbled 
     92   1.2  garbled struct powerpc_bus_space genppc_isa_mem_space_tag = {
     93   1.2  garbled 	.pbs_flags = _BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_MEM_TYPE,
     94   1.2  garbled 	.pbs_offset = PREP_BUS_SPACE_MEM,
     95   1.2  garbled 	.pbs_base = 0x00000000,
     96   1.2  garbled 	.pbs_limit = PREP_ISA_SIZE_MEM,
     97   1.2  garbled };
     98   1.2  garbled 
     99   1.2  garbled static char ex_storage[2][EXTENT_FIXED_STORAGE_SIZE(8)]
    100   1.2  garbled 	__attribute__((aligned(8)));
    101   1.2  garbled 
    102   1.2  garbled void
    103   1.2  garbled prep_bus_space_init(void)
    104   1.2  garbled {
    105   1.2  garbled 	int error;
    106   1.2  garbled 
    107   1.2  garbled 	error = bus_space_init(&prep_io_space_tag, "ioport",
    108   1.2  garbled 	    ex_storage[0], sizeof(ex_storage[0]));
    109   1.2  garbled 	if (error)
    110   1.2  garbled 		panic("prep_bus_space_init: can't init io tag");
    111   1.2  garbled 
    112   1.2  garbled 	error = extent_alloc_region(prep_io_space_tag.pbs_extent,
    113   1.2  garbled 	    PREP_PHYS_RESVD_START_IO, PREP_PHYS_RESVD_SIZE_IO, EX_NOWAIT);
    114   1.2  garbled 	if (error)
    115   1.2  garbled 		panic("prep_bus_space_init: can't block out reserved I/O"
    116   1.2  garbled 		    " space 0x10000-0x7fffff: error=%d", error);
    117   1.2  garbled 
    118   1.2  garbled 	error = bus_space_init(&prep_mem_space_tag, "iomem",
    119   1.2  garbled 	    ex_storage[1], sizeof(ex_storage[1]));
    120   1.2  garbled 	if (error)
    121   1.2  garbled 		panic("prep_bus_space_init: can't init mem tag");
    122   1.2  garbled 
    123   1.2  garbled 	genppc_isa_io_space_tag.pbs_extent = prep_io_space_tag.pbs_extent;
    124   1.2  garbled 	error = bus_space_init(&genppc_isa_io_space_tag, "isa-ioport", NULL, 0);	if (error)
    125   1.2  garbled 		panic("prep_bus_space_init: can't init isa io tag");
    126   1.2  garbled 
    127   1.2  garbled 	genppc_isa_mem_space_tag.pbs_extent = prep_mem_space_tag.pbs_extent;
    128   1.2  garbled 	error = bus_space_init(&genppc_isa_mem_space_tag, "isa-iomem", NULL, 0);
    129   1.2  garbled 	if (error)
    130   1.2  garbled 		panic("prep_bus_space_init: can't init isa mem tag");
    131   1.2  garbled }
    132   1.2  garbled 
    133   1.2  garbled /*
    134   1.2  garbled  * just a few calls used in initppc() all in one place so everything gets
    135   1.2  garbled  * done the same across the ports
    136   1.2  garbled  */
    137   1.2  garbled 
    138   1.2  garbled void
    139  1.13  thorpej prep_initppc(u_long startkernel, u_long endkernel, u_int args, paddr_t pa, ...)
    140   1.2  garbled {
    141  1.13  thorpej 	va_list ap;
    142   1.2  garbled 
    143   1.2  garbled 	/*
    144  1.13  thorpej 	 * Set up fixed BAT registers.  We map the PReP IO and MEM
    145  1.13  thorpej 	 * space, plus any additional regions the platform wants.
    146   1.2  garbled 	 */
    147   1.2  garbled 	oea_batinit(
    148   1.2  garbled 	    PREP_BUS_SPACE_MEM, BAT_BL_256M,
    149   1.2  garbled 	    PREP_BUS_SPACE_IO,  BAT_BL_256M,
    150   1.2  garbled 	    0);
    151   1.2  garbled 
    152  1.13  thorpej 	va_start(ap, pa);
    153  1.13  thorpej 	while (pa != 0) {
    154  1.13  thorpej 		register_t len = va_arg(ap, register_t);
    155  1.13  thorpej 		oea_iobat_add(pa, len);
    156  1.13  thorpej 		pa = va_arg(ap, paddr_t);
    157  1.13  thorpej 	}
    158  1.13  thorpej 	va_end(ap);
    159  1.13  thorpej 
    160   1.2  garbled 	/* Install vectors and interrupt handler. */
    161   1.2  garbled 	oea_init(NULL);
    162   1.2  garbled 
    163   1.2  garbled 	/* Initialize bus_space. */
    164   1.2  garbled 	prep_bus_space_init();
    165   1.2  garbled 
    166   1.2  garbled 	/* Initialize the console asap. */
    167   1.2  garbled 	consinit();
    168   1.2  garbled 
    169   1.2  garbled 	/* Set the page size */
    170  1.11   cherry 	uvm_md_init();
    171   1.2  garbled 
    172   1.2  garbled 	/* Initialize pmap module */
    173   1.2  garbled 	pmap_bootstrap(startkernel, endkernel);
    174   1.2  garbled 
    175   1.4       ad #if NKSYMS || defined(DDB) || defined(MODULAR)
    176   1.5   martin 	ksyms_addsyms_elf((int)((u_long)endsym - (u_long)startsym), startsym, endsym);
    177   1.2  garbled #endif
    178   1.2  garbled 
    179   1.2  garbled #ifdef DDB
    180   1.2  garbled 	boothowto = args;
    181   1.2  garbled 	if (boothowto & RB_KDB)
    182   1.2  garbled 		Debugger();
    183   1.2  garbled #endif
    184   1.2  garbled }
    185   1.2  garbled 
    186   1.2  garbled void
    187   1.2  garbled mem_regions(struct mem_region **mem, struct mem_region **avail)
    188   1.2  garbled {
    189   1.2  garbled 
    190   1.2  garbled 	*mem = physmemr;
    191   1.2  garbled 	*avail = availmemr;
    192   1.2  garbled }
    193