Home | History | Annotate | Line # | Download | only in virtex
machdep.c revision 1.25.2.1
      1  1.25.2.1   thorpej /*	$NetBSD: machdep.c,v 1.25.2.1 2021/04/03 22:28:25 thorpej Exp $ */
      2       1.1     freza 
      3       1.1     freza /*
      4       1.1     freza  * Copyright (c) 2006 Jachym Holecek
      5       1.1     freza  * All rights reserved.
      6       1.1     freza  *
      7       1.1     freza  * Written for DFC Design, s.r.o.
      8       1.1     freza  *
      9       1.1     freza  * Redistribution and use in source and binary forms, with or without
     10       1.1     freza  * modification, are permitted provided that the following conditions
     11       1.1     freza  * are met:
     12       1.1     freza  *
     13       1.1     freza  * 1. Redistributions of source code must retain the above copyright
     14       1.1     freza  *    notice, this list of conditions and the following disclaimer.
     15       1.1     freza  *
     16       1.1     freza  * 2. Redistributions in binary form must reproduce the above copyright
     17       1.1     freza  *    notice, this list of conditions and the following disclaimer in the
     18       1.1     freza  *    documentation and/or other materials provided with the distribution.
     19       1.1     freza  *
     20       1.1     freza  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21       1.1     freza  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22       1.1     freza  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23       1.1     freza  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24       1.1     freza  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25       1.1     freza  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26       1.1     freza  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27       1.1     freza  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28       1.1     freza  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29       1.1     freza  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30       1.1     freza  */
     31       1.1     freza 
     32       1.1     freza /*
     33       1.1     freza  * Based on Walnut and Explora.
     34       1.1     freza  */
     35       1.1     freza 
     36       1.1     freza #include <sys/cdefs.h>
     37  1.25.2.1   thorpej __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.25.2.1 2021/04/03 22:28:25 thorpej Exp $");
     38       1.1     freza 
     39       1.1     freza #include "opt_compat_netbsd.h"
     40       1.1     freza #include "opt_ddb.h"
     41       1.1     freza #include "opt_virtex.h"
     42       1.5   garbled #include "opt_kgdb.h"
     43       1.1     freza 
     44       1.1     freza #include <sys/param.h>
     45      1.19      matt #include <sys/boot_flag.h>
     46       1.1     freza #include <sys/buf.h>
     47      1.19      matt #include <sys/bus.h>
     48      1.19      matt #include <sys/device.h>
     49       1.1     freza #include <sys/exec.h>
     50       1.1     freza #include <sys/malloc.h>
     51       1.1     freza #include <sys/mbuf.h>
     52      1.19      matt #include <sys/module.h>
     53       1.1     freza #include <sys/mount.h>
     54       1.1     freza #include <sys/msgbuf.h>
     55      1.19      matt #include <sys/kernel.h>
     56      1.19      matt #include <sys/ksyms.h>
     57       1.1     freza #include <sys/proc.h>
     58       1.1     freza #include <sys/reboot.h>
     59       1.1     freza #include <sys/syscallargs.h>
     60       1.1     freza #include <sys/syslog.h>
     61       1.1     freza #include <sys/systm.h>
     62       1.1     freza 
     63       1.1     freza #include <uvm/uvm_extern.h>
     64       1.1     freza 
     65       1.1     freza #include <dev/cons.h>
     66       1.1     freza 
     67       1.1     freza #include <machine/powerpc.h>
     68      1.19      matt 
     69      1.19      matt #include <powerpc/trap.h>
     70      1.19      matt #include <powerpc/pcb.h>
     71       1.1     freza 
     72       1.1     freza #include <powerpc/spr.h>
     73      1.14      matt #include <powerpc/ibm4xx/spr.h>
     74       1.1     freza 
     75      1.18      matt #include <powerpc/ibm4xx/cpu.h>
     76      1.18      matt 
     77       1.1     freza #include <evbppc/virtex/dcr.h>
     78       1.1     freza #include <evbppc/virtex/virtex.h>
     79       1.1     freza 
     80       1.1     freza #include "ksyms.h"
     81       1.1     freza 
     82       1.1     freza #if defined(DDB)
     83      1.19      matt #include <powerpc/db_machdep.h>
     84       1.1     freza #include <ddb/db_extern.h>
     85       1.1     freza #endif
     86       1.1     freza 
     87       1.5   garbled #if defined(KGDB)
     88       1.5   garbled #include <sys/kgdb.h>
     89       1.5   garbled #endif
     90       1.1     freza 
     91      1.20      matt void initppc(vaddr_t, vaddr_t);
     92       1.1     freza 
     93       1.1     freza /* BSS segment start & end. */
     94       1.1     freza extern char 		edata[], end[];
     95       1.1     freza 
     96       1.1     freza /* One region holds all memory, the other is terminator expected by 405 pmap. */
     97       1.1     freza #define MEMREGIONS 	2
     98       1.1     freza struct mem_region 	physmemr[MEMREGIONS];
     99       1.1     freza struct mem_region 	availmemr[MEMREGIONS];
    100       1.1     freza 
    101       1.1     freza /* Maximum TLB page size. */
    102       1.1     freza #define TLB_PG_SIZE 	(16*1024*1024)
    103       1.1     freza 
    104       1.1     freza void
    105      1.20      matt initppc(vaddr_t startkernel, vaddr_t endkernel)
    106       1.1     freza {
    107      1.20      matt 	paddr_t			addr, memsize;
    108       1.1     freza 
    109       1.1     freza         /* Initialize cache info for memcpy, memset, etc. */
    110       1.1     freza         cpu_probe_cache();
    111       1.1     freza 
    112       1.1     freza 	memset(physmemr, 0, sizeof(physmemr)); 		/* [1].size = 0 */
    113       1.1     freza 	memset(availmemr, 0, sizeof(availmemr)); 	/* [1].size = 0 */
    114       1.1     freza 
    115       1.1     freza 	memsize = (PHYSMEM * 1024 * 1024) & ~PGOFSET;
    116       1.1     freza 
    117       1.1     freza 	physmemr[0].start 	= 0;
    118       1.1     freza 	physmemr[0].size 	= memsize;
    119       1.1     freza 
    120       1.1     freza 	availmemr[0].start 	= startkernel;
    121       1.1     freza 	availmemr[0].size 	= memsize - availmemr[0].start;
    122       1.1     freza 
    123       1.1     freza 	/* Map kernel memory linearly. */
    124       1.1     freza 	for (addr = 0; addr < endkernel; addr += TLB_PG_SIZE)
    125       1.1     freza 		ppc4xx_tlb_reserve(addr, addr, TLB_PG_SIZE, TLB_EX);
    126       1.1     freza 
    127       1.1     freza 	/* Give design-specific code a hint for reserved mappings. */
    128       1.1     freza 	virtex_machdep_init(roundup(memsize, TLB_PG_SIZE), TLB_PG_SIZE,
    129       1.1     freza 	    physmemr, availmemr);
    130       1.1     freza 
    131      1.20      matt 	ibm4xx_init(startkernel, endkernel, pic_ext_intr);
    132       1.1     freza 
    133       1.1     freza #ifdef DDB
    134       1.1     freza 	if (boothowto & RB_KDB)
    135       1.1     freza 		Debugger();
    136       1.1     freza #endif
    137      1.22      maxv 
    138       1.5   garbled #ifdef KGDB
    139       1.5   garbled 	/*
    140       1.5   garbled 	 * Now trap to KGDB
    141       1.5   garbled 	 */
    142       1.5   garbled 	kgdb_connect(1);
    143       1.5   garbled #endif /* KGDB */
    144      1.16       mrg 
    145      1.16       mrg 	/*
    146      1.16       mrg 	 * Look for the ibm4xx modules in the right place.
    147      1.16       mrg 	 */
    148      1.16       mrg 	module_machine = module_machine_ibm4xx;
    149       1.1     freza }
    150       1.1     freza 
    151       1.1     freza /*
    152       1.1     freza  * Machine dependent startup code.
    153       1.1     freza  */
    154       1.1     freza 
    155       1.1     freza void
    156       1.1     freza cpu_startup(void)
    157       1.1     freza {
    158       1.1     freza 	/* For use by propdb. */
    159       1.1     freza 	static u_int 	memsize = PHYSMEM * 1024 * 1024;
    160       1.1     freza 	static u_int 	cpuspeed = CPUFREQ * 1000 * 1000;
    161       1.1     freza 	prop_number_t 	pn;
    162       1.1     freza 
    163       1.1     freza 	vaddr_t 	minaddr, maxaddr;
    164       1.1     freza 	char 		pbuf[9];
    165       1.1     freza 
    166       1.1     freza 	curcpu()->ci_khz = cpuspeed / 1000;
    167       1.1     freza 
    168       1.1     freza 	/* Initialize error message buffer. */
    169       1.4  christos 	initmsgbuf((void *)msgbuf, round_page(MSGBUFSIZE));
    170       1.1     freza 
    171       1.1     freza 	printf("%s%s", copyright, version);
    172       1.1     freza 
    173       1.1     freza 	format_bytes(pbuf, sizeof(pbuf), ctob(physmem));
    174       1.1     freza 	printf("total memory = %s\n", pbuf);
    175       1.1     freza 
    176       1.1     freza 	minaddr = 0;
    177       1.1     freza 	/*
    178       1.1     freza 	 * Allocate a submap for physio
    179       1.1     freza 	 */
    180       1.1     freza 	phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
    181       1.3   thorpej 				 VM_PHYS_SIZE, 0, false, NULL);
    182       1.1     freza 
    183       1.1     freza 	/*
    184       1.1     freza 	 * No need to allocate an mbuf cluster submap.  Mbuf clusters
    185       1.1     freza 	 * are allocated via the pool allocator, and we use direct-mapped
    186       1.1     freza 	 * pool pages.
    187       1.1     freza 	 */
    188       1.1     freza 
    189      1.25        ad 	format_bytes(pbuf, sizeof(pbuf), ptoa(uvm_availmem(false)));
    190       1.1     freza 	printf("avail memory = %s\n", pbuf);
    191       1.1     freza 
    192       1.1     freza 	/*
    193       1.1     freza 	 * Set up the board properties database.
    194       1.1     freza 	 */
    195       1.1     freza 	board_info_init();
    196       1.1     freza 
    197       1.1     freza 	pn = prop_number_create_integer(memsize);
    198       1.1     freza 	KASSERT(pn != NULL);
    199       1.3   thorpej 	if (prop_dictionary_set(board_properties, "mem-size", pn) == false)
    200       1.1     freza 		panic("setting mem-size");
    201       1.1     freza 	prop_object_release(pn);
    202       1.1     freza 
    203       1.1     freza 	pn = prop_number_create_integer(cpuspeed);
    204       1.1     freza 	KASSERT(pn != NULL);
    205       1.1     freza 	if (prop_dictionary_set(board_properties, "processor-frequency",
    206       1.3   thorpej 	    pn) == false)
    207       1.1     freza 		panic("setting processor-frequency");
    208       1.1     freza 	prop_object_release(pn);
    209       1.1     freza 
    210       1.1     freza 	/*
    211       1.1     freza 	 * Now that we have VM, malloc()s are OK in bus_space.
    212       1.1     freza 	 */
    213       1.1     freza 	bus_space_mallocok();
    214       1.1     freza 	fake_mapiodev = 0;
    215       1.1     freza }
    216       1.1     freza 
    217       1.1     freza /* Hook used by 405 pmap module. */
    218       1.1     freza void
    219       1.1     freza mem_regions(struct mem_region **mem, struct mem_region **avail)
    220       1.1     freza {
    221       1.1     freza 	*mem 	= physmemr;
    222       1.1     freza 	*avail 	= availmemr;
    223       1.1     freza }
    224