#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.31 2023/12/20 14:18:37 thorpej Exp $");
#include "opt_compat_netbsd.h"
#include "opt_ddb.h"
#include "opt_virtex.h"
#include "opt_kgdb.h"
#include <sys/param.h>
#include <sys/boot_flag.h>
#include <sys/buf.h>
#include <sys/bus.h>
#include <sys/device.h>
#include <sys/exec.h>
#include <sys/mbuf.h>
#include <sys/module.h>
#include <sys/mount.h>
#include <sys/msgbuf.h>
#include <sys/kernel.h>
#include <sys/ksyms.h>
#include <sys/proc.h>
#include <sys/reboot.h>
#include <sys/syscallargs.h>
#include <sys/syslog.h>
#include <sys/systm.h>
#include <uvm/uvm_extern.h>
#include <dev/cons.h>
#include <machine/powerpc.h>
#include <powerpc/trap.h>
#include <powerpc/pcb.h>
#include <powerpc/spr.h>
#include <powerpc/ibm4xx/spr.h>
#include <powerpc/ibm4xx/cpu.h>
#include <evbppc/virtex/dcr.h>
#include <evbppc/virtex/virtex.h>
#include "ksyms.h"
#if defined(DDB)
#include <powerpc/db_machdep.h>
#include <ddb/db_extern.h>
#endif
#if defined(KGDB)
#include <sys/kgdb.h>
#endif
void initppc(vaddr_t, vaddr_t);
extern char edata[], end[];
#define MEMREGIONS 2
struct mem_region physmemr[MEMREGIONS];
struct mem_region availmemr[MEMREGIONS];
#define TLB_PG_SIZE (16*1024*1024)
void
initppc(vaddr_t startkernel, vaddr_t endkernel)
{
paddr_t addr, memsize;
cpu_probe_cache();
memset(physmemr, 0, sizeof(physmemr));
memset(availmemr, 0, sizeof(availmemr));
memsize = (PHYSMEM * 1024 * 1024) & ~PGOFSET;
physmemr[0].start = 0;
physmemr[0].size = memsize;
availmemr[0].start = startkernel;
availmemr[0].size = memsize - availmemr[0].start;
for (addr = 0; addr < endkernel; addr += TLB_PG_SIZE)
ppc4xx_tlb_reserve(addr, addr, TLB_PG_SIZE, TLB_EX);
virtex_machdep_init(roundup(memsize, TLB_PG_SIZE), TLB_PG_SIZE,
physmemr, availmemr);
ibm4xx_init(startkernel, endkernel, pic_ext_intr);
#ifdef DDB
if (boothowto & RB_KDB)
Debugger();
#endif
#ifdef KGDB
kgdb_connect(1);
#endif
}
void
cpu_startup(void)
{
static u_int memsize = PHYSMEM * 1024 * 1024;
static u_int cpuspeed = CPUFREQ * 1000 * 1000;
prop_number_t pn;
vaddr_t minaddr, maxaddr;
char pbuf[9];
curcpu()->ci_khz = cpuspeed / 1000;
initmsgbuf((void *)msgbuf, round_page(MSGBUFSIZE));
printf("%s%s", copyright, version);
format_bytes(pbuf, sizeof(pbuf), ctob(physmem));
printf("total memory = %s\n", pbuf);
minaddr = 0;
phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
VM_PHYS_SIZE, 0, false, NULL);
format_bytes(pbuf, sizeof(pbuf), ptoa(uvm_availmem(false)));
printf("avail memory = %s\n", pbuf);
board_info_init();
pn = prop_number_create_integer(memsize);
KASSERT(pn != NULL);
if (prop_dictionary_set(board_properties, "mem-size", pn) == false)
panic("setting mem-size");
prop_object_release(pn);
pn = prop_number_create_integer(cpuspeed);
KASSERT(pn != NULL);
if (prop_dictionary_set(board_properties, "processor-frequency",
pn) == false)
panic("setting processor-frequency");
prop_object_release(pn);
bus_space_mallocok();
fake_mapiodev = 0;
}
void
mem_regions(struct mem_region **mem, struct mem_region **avail)
{
*mem = physmemr;
*avail = availmemr;
}