2009-10-15 21:14:42 +00:00
|
|
|
/*-
|
2009-10-29 15:55:25 +00:00
|
|
|
* Copyright (c) 2006-2009 RMI Corporation
|
2009-10-15 21:14:42 +00:00
|
|
|
* Copyright (c) 2002-2004 Juli Mallett <jmallett@FreeBSD.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*/
|
2009-11-05 18:14:25 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2009-12-21 11:29:30 +00:00
|
|
|
#include "opt_ddb.h"
|
|
|
|
|
2009-10-15 21:14:42 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/rtprio.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/interrupt.h>
|
|
|
|
#include <sys/limits.h>
|
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/mutex.h>
|
|
|
|
#include <sys/random.h>
|
|
|
|
|
2009-10-29 21:14:10 +00:00
|
|
|
#include <sys/cons.h> /* cinit() */
|
2009-12-21 11:29:30 +00:00
|
|
|
#include <sys/kdb.h>
|
2009-10-15 21:14:42 +00:00
|
|
|
#include <sys/reboot.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <sys/smp.h>
|
|
|
|
#include <sys/timetc.h>
|
|
|
|
|
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/vm_page.h>
|
|
|
|
|
|
|
|
#include <machine/cpu.h>
|
|
|
|
#include <machine/cpufunc.h>
|
|
|
|
#include <machine/cpuinfo.h>
|
|
|
|
#include <machine/cpuregs.h>
|
|
|
|
#include <machine/frame.h>
|
|
|
|
#include <machine/hwfunc.h>
|
|
|
|
#include <machine/md_var.h>
|
|
|
|
#include <machine/asm.h>
|
|
|
|
#include <machine/pmap.h>
|
|
|
|
#include <machine/trap.h>
|
|
|
|
#include <machine/clock.h>
|
|
|
|
#include <machine/fls64.h>
|
|
|
|
#include <machine/intr_machdep.h>
|
|
|
|
#include <machine/smp.h>
|
|
|
|
|
2009-10-29 15:55:25 +00:00
|
|
|
#include <mips/rmi/iomap.h>
|
|
|
|
#include <mips/rmi/msgring.h>
|
|
|
|
#include <mips/rmi/interrupt.h>
|
|
|
|
#include <mips/rmi/pic.h>
|
2010-08-25 08:48:54 +00:00
|
|
|
#include <mips/rmi/board.h>
|
2010-08-30 13:05:21 +00:00
|
|
|
#include <mips/rmi/rmi_mips_exts.h>
|
|
|
|
#include <mips/rmi/rmi_boot_info.h>
|
2009-10-15 21:14:42 +00:00
|
|
|
|
2010-05-16 19:43:48 +00:00
|
|
|
void mpwait(void);
|
2009-10-15 21:14:42 +00:00
|
|
|
unsigned long xlr_io_base = (unsigned long)(DEFAULT_XLR_IO_BASE);
|
|
|
|
|
2009-10-29 21:14:10 +00:00
|
|
|
/* 4KB static data aread to keep a copy of the bootload env until
|
2009-10-15 21:14:42 +00:00
|
|
|
the dynamic kenv is setup */
|
|
|
|
char boot1_env[4096];
|
2009-11-05 18:14:25 +00:00
|
|
|
int rmi_spin_mutex_safe=0;
|
2010-08-25 08:48:54 +00:00
|
|
|
struct mtx xlr_pic_lock;
|
|
|
|
|
2009-10-15 21:14:42 +00:00
|
|
|
/*
|
|
|
|
* Parameters from boot loader
|
|
|
|
*/
|
2009-10-29 21:14:10 +00:00
|
|
|
struct boot1_info xlr_boot1_info;
|
|
|
|
int xlr_run_mode;
|
|
|
|
int xlr_argc;
|
2010-07-15 16:39:17 +00:00
|
|
|
int32_t *xlr_argv, *xlr_envp;
|
2009-10-29 21:14:10 +00:00
|
|
|
uint64_t cpu_mask_info;
|
|
|
|
uint32_t xlr_online_cpumask;
|
|
|
|
uint32_t xlr_core_cpu_mask = 0x1; /* Core 0 thread 0 is always there */
|
2009-10-15 21:14:42 +00:00
|
|
|
|
2010-05-21 05:34:19 +00:00
|
|
|
int xlr_shtlb_enabled;
|
|
|
|
int xlr_ncores;
|
|
|
|
int xlr_threads_per_core;
|
|
|
|
uint32_t xlr_hw_thread_mask;
|
|
|
|
int xlr_cpuid_to_hwtid[MAXCPU];
|
|
|
|
int xlr_hwtid_to_cpuid[MAXCPU];
|
2009-10-15 21:14:42 +00:00
|
|
|
|
2009-10-29 21:14:10 +00:00
|
|
|
static void
|
2010-05-21 05:34:19 +00:00
|
|
|
xlr_setup_mmu_split(void)
|
2009-10-15 21:14:42 +00:00
|
|
|
{
|
2010-09-09 17:45:48 +00:00
|
|
|
uint64_t mmu_setup;
|
2010-05-21 05:34:19 +00:00
|
|
|
int val = 0;
|
|
|
|
|
|
|
|
if (xlr_threads_per_core == 4 && xlr_shtlb_enabled == 0)
|
|
|
|
return; /* no change from boot setup */
|
|
|
|
|
|
|
|
switch (xlr_threads_per_core) {
|
|
|
|
case 1:
|
|
|
|
val = 0; break;
|
|
|
|
case 2:
|
|
|
|
val = 2; break;
|
|
|
|
case 4:
|
|
|
|
val = 3; break;
|
2009-10-15 21:14:42 +00:00
|
|
|
}
|
2010-05-21 05:34:19 +00:00
|
|
|
|
2010-09-09 17:45:48 +00:00
|
|
|
mmu_setup = read_xlr_ctrl_register(4, 0);
|
2009-10-15 21:14:42 +00:00
|
|
|
mmu_setup = mmu_setup & ~0x06;
|
2010-05-21 05:34:19 +00:00
|
|
|
mmu_setup |= (val << 1);
|
2009-10-15 21:14:42 +00:00
|
|
|
|
|
|
|
/* turn on global mode */
|
2010-05-21 05:34:19 +00:00
|
|
|
if (xlr_shtlb_enabled)
|
|
|
|
mmu_setup |= 0x01;
|
2009-10-15 21:14:42 +00:00
|
|
|
|
2010-09-09 17:45:48 +00:00
|
|
|
write_xlr_ctrl_register(4, 0, mmu_setup);
|
2009-10-15 21:14:42 +00:00
|
|
|
}
|
2009-10-29 21:14:10 +00:00
|
|
|
|
2010-05-21 05:34:19 +00:00
|
|
|
static void
|
|
|
|
xlr_parse_mmu_options(void)
|
2009-10-15 21:14:42 +00:00
|
|
|
{
|
2010-05-21 05:34:19 +00:00
|
|
|
#ifdef notyet
|
|
|
|
char *hw_env, *start, *end;
|
|
|
|
#endif
|
|
|
|
uint32_t cpu_map;
|
|
|
|
uint8_t core0_thr_mask, core_thr_mask;
|
|
|
|
int i, j, k;
|
|
|
|
|
|
|
|
/* First check for the shared TLB setup */
|
|
|
|
xlr_shtlb_enabled = 0;
|
|
|
|
#ifdef notyet
|
|
|
|
/*
|
|
|
|
* We don't support sharing TLB per core - TODO
|
|
|
|
*/
|
|
|
|
xlr_shtlb_enabled = 0;
|
|
|
|
if ((hw_env = getenv("xlr.shtlb")) != NULL) {
|
|
|
|
start = hw_env;
|
|
|
|
tmp = strtoul(start, &end, 0);
|
|
|
|
if (start != end)
|
|
|
|
xlr_shtlb_enabled = (tmp != 0);
|
|
|
|
else
|
|
|
|
printf("Bad value for xlr.shtlb [%s]\n", hw_env);
|
|
|
|
freeenv(hw_env);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
* XLR supports splitting the 64 TLB entries across one, two or four
|
|
|
|
* threads (split mode). XLR also allows the 64 TLB entries to be shared
|
|
|
|
* across all threads in the core using a global flag (shared TLB mode).
|
|
|
|
* We will support 1/2/4 threads in split mode or shared mode.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
xlr_ncores = 1;
|
|
|
|
cpu_map = xlr_boot1_info.cpu_online_map;
|
2010-10-20 09:41:36 +00:00
|
|
|
|
|
|
|
#ifndef SMP /* Uniprocessor! */
|
|
|
|
if (cpu_map != 0x1) {
|
|
|
|
printf("WARNING: Starting uniprocessor kernel on cpumask [0x%lx]!\n"
|
|
|
|
"WARNING: Other CPUs will be unused.\n", (u_long)cpu_map);
|
|
|
|
cpu_map = 0x1;
|
|
|
|
}
|
|
|
|
#endif
|
2010-05-21 05:34:19 +00:00
|
|
|
core0_thr_mask = cpu_map & 0xf;
|
|
|
|
switch (core0_thr_mask) {
|
|
|
|
case 1:
|
|
|
|
xlr_threads_per_core = 1; break;
|
|
|
|
case 3:
|
|
|
|
xlr_threads_per_core = 2; break;
|
|
|
|
case 0xf:
|
|
|
|
xlr_threads_per_core = 4; break;
|
|
|
|
default:
|
|
|
|
goto unsupp;
|
|
|
|
}
|
2009-10-15 21:14:42 +00:00
|
|
|
|
2010-05-21 05:34:19 +00:00
|
|
|
/* Verify other cores CPU masks */
|
|
|
|
for (i = 1; i < XLR_MAX_CORES; i++) {
|
|
|
|
core_thr_mask = (cpu_map >> (i*4)) & 0xf;
|
|
|
|
if (core_thr_mask) {
|
|
|
|
if (core_thr_mask != core0_thr_mask)
|
|
|
|
goto unsupp;
|
|
|
|
xlr_ncores++;
|
2009-10-15 21:14:42 +00:00
|
|
|
}
|
|
|
|
}
|
2010-10-20 09:41:36 +00:00
|
|
|
xlr_hw_thread_mask = cpu_map;
|
2009-10-15 21:14:42 +00:00
|
|
|
|
2010-05-21 05:34:19 +00:00
|
|
|
/* setup hardware processor id to cpu id mapping */
|
|
|
|
for (i = 0; i< MAXCPU; i++)
|
|
|
|
xlr_cpuid_to_hwtid[i] =
|
|
|
|
xlr_hwtid_to_cpuid [i] = -1;
|
|
|
|
for (i = 0, k = 0; i < XLR_MAX_CORES; i++) {
|
|
|
|
if (((cpu_map >> (i*4)) & 0xf) == 0)
|
|
|
|
continue;
|
|
|
|
for (j = 0; j < xlr_threads_per_core; j++) {
|
|
|
|
xlr_cpuid_to_hwtid[k] = i*4 + j;
|
|
|
|
xlr_hwtid_to_cpuid[i*4 + j] = k;
|
|
|
|
k++;
|
2009-10-15 21:14:42 +00:00
|
|
|
}
|
|
|
|
}
|
2010-05-21 05:34:19 +00:00
|
|
|
|
|
|
|
/* setup for the startup core */
|
|
|
|
xlr_setup_mmu_split();
|
2009-10-15 21:14:42 +00:00
|
|
|
return;
|
|
|
|
|
2010-05-21 05:34:19 +00:00
|
|
|
unsupp:
|
|
|
|
printf("ERROR : Unsupported CPU mask [use 1,2 or 4 threads per core].\n"
|
|
|
|
"\tcore0 thread mask [%lx], boot cpu mask [%lx]\n"
|
|
|
|
"\tUsing default, 16 TLB entries per CPU, split mode\n",
|
|
|
|
(u_long)core0_thr_mask, (u_long)cpu_map);
|
|
|
|
panic("Invalid CPU mask - halting.\n");
|
2009-10-15 21:14:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-10-29 21:14:10 +00:00
|
|
|
static void
|
|
|
|
xlr_set_boot_flags(void)
|
2009-10-15 21:14:42 +00:00
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
|
2010-05-21 05:34:19 +00:00
|
|
|
p = getenv("bootflags");
|
|
|
|
if (p == NULL)
|
|
|
|
p = getenv("boot_flags"); /* old style */
|
|
|
|
if (p == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (; p && *p != '\0'; p++) {
|
2009-10-29 21:14:10 +00:00
|
|
|
switch (*p) {
|
2009-10-15 21:14:42 +00:00
|
|
|
case 'd':
|
|
|
|
case 'D':
|
|
|
|
boothowto |= RB_KDB;
|
|
|
|
break;
|
|
|
|
case 'g':
|
|
|
|
case 'G':
|
|
|
|
boothowto |= RB_GDB;
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
case 'V':
|
|
|
|
boothowto |= RB_VERBOSE;
|
|
|
|
break;
|
|
|
|
|
2009-10-29 21:14:10 +00:00
|
|
|
case 's': /* single-user (default, supported for sanity) */
|
2009-10-15 21:14:42 +00:00
|
|
|
case 'S':
|
|
|
|
boothowto |= RB_SINGLE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
printf("Unrecognized boot flag '%c'.\n", *p);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-21 05:34:19 +00:00
|
|
|
freeenv(p);
|
2009-10-15 21:14:42 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-10-29 21:14:10 +00:00
|
|
|
extern uint32_t _end;
|
2009-10-29 15:55:25 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
mips_init(void)
|
|
|
|
{
|
|
|
|
init_param1();
|
|
|
|
init_param2(physmem);
|
|
|
|
|
|
|
|
mips_cpu_init();
|
2010-09-01 17:35:31 +00:00
|
|
|
cpuinfo.cache_coherent_dma = TRUE;
|
2009-10-29 15:55:25 +00:00
|
|
|
pmap_bootstrap();
|
|
|
|
#ifdef DDB
|
|
|
|
kdb_init();
|
|
|
|
if (boothowto & RB_KDB) {
|
2009-12-21 11:29:30 +00:00
|
|
|
kdb_enter("Boot flags requested debugger", NULL);
|
2009-10-29 15:55:25 +00:00
|
|
|
}
|
|
|
|
#endif
|
2010-01-26 05:10:10 +00:00
|
|
|
mips_proc0_init();
|
|
|
|
mutex_init();
|
2009-10-29 15:55:25 +00:00
|
|
|
}
|
|
|
|
|
2010-08-25 13:37:55 +00:00
|
|
|
u_int
|
|
|
|
platform_get_timecount(struct timecounter *tc __unused)
|
|
|
|
{
|
|
|
|
|
|
|
|
return (0xffffffffU - pic_timer_count32(PIC_CLOCK_TIMER));
|
|
|
|
}
|
|
|
|
|
2010-08-25 08:48:54 +00:00
|
|
|
static void
|
|
|
|
xlr_pic_init(void)
|
|
|
|
{
|
2010-08-25 13:37:55 +00:00
|
|
|
struct timecounter pic_timecounter = {
|
|
|
|
platform_get_timecount, /* get_timecount */
|
|
|
|
0, /* no poll_pps */
|
|
|
|
~0U, /* counter_mask */
|
|
|
|
PIC_TIMER_HZ, /* frequency */
|
|
|
|
"XLRPIC", /* name */
|
|
|
|
2000, /* quality (adjusted in code) */
|
|
|
|
};
|
2010-08-25 08:48:54 +00:00
|
|
|
xlr_reg_t *mmio = xlr_io_mmio(XLR_IO_PIC_OFFSET);
|
2010-09-06 06:18:49 +00:00
|
|
|
int i, irq;
|
2010-08-25 08:48:54 +00:00
|
|
|
|
2010-09-01 17:35:31 +00:00
|
|
|
write_c0_eimr64(0ULL);
|
2010-08-25 08:48:54 +00:00
|
|
|
mtx_init(&xlr_pic_lock, "pic", NULL, MTX_SPIN);
|
|
|
|
xlr_write_reg(mmio, PIC_CTRL, 0);
|
2010-08-25 13:37:55 +00:00
|
|
|
|
|
|
|
/* Initialize all IRT entries */
|
2010-08-25 08:48:54 +00:00
|
|
|
for (i = 0; i < PIC_NUM_IRTS; i++) {
|
2010-08-25 12:10:20 +00:00
|
|
|
irq = PIC_INTR_TO_IRQ(i);
|
2010-08-25 08:48:54 +00:00
|
|
|
|
|
|
|
/*
|
2010-09-06 06:18:49 +00:00
|
|
|
* Disable all IRTs. Set defaults (local scheduling, high
|
|
|
|
* polarity, level * triggered, and CPU irq)
|
2010-08-25 08:48:54 +00:00
|
|
|
*/
|
2010-09-06 06:18:49 +00:00
|
|
|
xlr_write_reg(mmio, PIC_IRT_1(i), (1 << 30) | (1 << 6) | irq);
|
|
|
|
/* Bind all PIC irqs to cpu 0 */
|
|
|
|
xlr_write_reg(mmio, PIC_IRT_0(i), 0x01);
|
2010-08-25 08:48:54 +00:00
|
|
|
}
|
2010-08-25 13:37:55 +00:00
|
|
|
|
|
|
|
/* Setup timer 7 of PIC as a timestamp, no interrupts */
|
|
|
|
pic_init_timer(PIC_CLOCK_TIMER);
|
|
|
|
pic_set_timer(PIC_CLOCK_TIMER, ~UINT64_C(0));
|
|
|
|
platform_timecounter = &pic_timecounter;
|
2010-08-25 08:48:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
xlr_mem_init(void)
|
|
|
|
{
|
|
|
|
struct xlr_boot1_mem_map *boot_map;
|
|
|
|
vm_size_t physsz = 0;
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
/* get physical memory info from boot loader */
|
|
|
|
boot_map = (struct xlr_boot1_mem_map *)
|
|
|
|
(unsigned long)xlr_boot1_info.psb_mem_map;
|
|
|
|
for (i = 0, j = 0; i < boot_map->num_entries; i++, j += 2) {
|
|
|
|
if (boot_map->physmem_map[i].type == BOOT1_MEM_RAM) {
|
|
|
|
if (j == 14) {
|
|
|
|
printf("*** ERROR *** memory map too large ***\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (j == 0) {
|
|
|
|
/* TODO FIXME */
|
|
|
|
/* start after kernel end */
|
|
|
|
phys_avail[0] = (vm_paddr_t)
|
|
|
|
MIPS_KSEG0_TO_PHYS(&_end) + 0x20000;
|
|
|
|
/* boot loader start */
|
|
|
|
/* HACK to Use bootloaders memory region */
|
|
|
|
/* TODO FIXME */
|
|
|
|
if (boot_map->physmem_map[0].size == 0x0c000000) {
|
|
|
|
boot_map->physmem_map[0].size = 0x0ff00000;
|
|
|
|
}
|
|
|
|
phys_avail[1] = boot_map->physmem_map[0].addr +
|
|
|
|
boot_map->physmem_map[0].size;
|
|
|
|
printf("First segment: addr:%p -> %p \n",
|
|
|
|
(void *)phys_avail[0],
|
|
|
|
(void *)phys_avail[1]);
|
|
|
|
|
2010-12-09 07:47:40 +00:00
|
|
|
dump_avail[0] = phys_avail[0];
|
|
|
|
dump_avail[1] = phys_avail[1];
|
2010-12-09 07:01:03 +00:00
|
|
|
|
2010-08-25 08:48:54 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Can't use this code yet, because most of the fixed allocations happen from
|
|
|
|
* the biggest physical area. If we have more than 512M memory the kernel will try
|
|
|
|
* to map from the second are which is not in KSEG0 and not mapped
|
|
|
|
*/
|
|
|
|
phys_avail[j] = (vm_paddr_t)
|
|
|
|
boot_map->physmem_map[i].addr;
|
|
|
|
phys_avail[j + 1] = phys_avail[j] +
|
|
|
|
boot_map->physmem_map[i].size;
|
|
|
|
if (phys_avail[j + 1] < phys_avail[j] ) {
|
|
|
|
/* Houston we have an issue. Memory is
|
|
|
|
* larger than possible. Its probably in
|
|
|
|
* 64 bit > 4Gig and we are in 32 bit mode.
|
|
|
|
*/
|
|
|
|
phys_avail[j + 1] = 0xfffff000;
|
|
|
|
printf("boot map size was %jx\n",
|
|
|
|
(intmax_t)boot_map->physmem_map[i].size);
|
|
|
|
boot_map->physmem_map[i].size = phys_avail[j + 1]
|
|
|
|
- phys_avail[j];
|
|
|
|
printf("reduced to %jx\n",
|
|
|
|
(intmax_t)boot_map->physmem_map[i].size);
|
|
|
|
}
|
|
|
|
printf("Next segment : addr:%p -> %p \n",
|
|
|
|
(void *)phys_avail[j],
|
|
|
|
(void *)phys_avail[j+1]);
|
|
|
|
}
|
2010-12-09 07:01:03 +00:00
|
|
|
|
2010-12-09 07:47:40 +00:00
|
|
|
dump_avail[j] = phys_avail[j];
|
|
|
|
dump_avail[j+1] = phys_avail[j+1];
|
2010-12-09 07:01:03 +00:00
|
|
|
|
2010-08-25 08:48:54 +00:00
|
|
|
physsz += boot_map->physmem_map[i].size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME XLR TODO */
|
|
|
|
phys_avail[j] = phys_avail[j + 1] = 0;
|
|
|
|
realmem = physmem = btoc(physsz);
|
|
|
|
}
|
|
|
|
|
2009-10-15 21:14:42 +00:00
|
|
|
void
|
2009-10-29 15:55:25 +00:00
|
|
|
platform_start(__register_t a0 __unused,
|
2009-10-29 21:14:10 +00:00
|
|
|
__register_t a1 __unused,
|
|
|
|
__register_t a2 __unused,
|
|
|
|
__register_t a3 __unused)
|
2009-10-15 21:14:42 +00:00
|
|
|
{
|
2010-08-25 08:48:54 +00:00
|
|
|
int i;
|
2009-10-15 21:14:42 +00:00
|
|
|
#ifdef SMP
|
|
|
|
uint32_t tmp;
|
2009-10-29 21:14:10 +00:00
|
|
|
void (*wakeup) (void *, void *, unsigned int);
|
2009-10-15 21:14:42 +00:00
|
|
|
#endif
|
2010-08-25 08:48:54 +00:00
|
|
|
|
2009-10-15 21:14:42 +00:00
|
|
|
/* XXX FIXME the code below is not 64 bit clean */
|
|
|
|
/* Save boot loader and other stuff from scratch regs */
|
2010-07-08 15:05:23 +00:00
|
|
|
xlr_boot1_info = *(struct boot1_info *)(intptr_t)(int)read_c0_register32(MIPS_COP_0_OSSCRATCH, 0);
|
2009-10-29 21:14:10 +00:00
|
|
|
cpu_mask_info = read_c0_register64(MIPS_COP_0_OSSCRATCH, 1);
|
2009-10-15 21:14:42 +00:00
|
|
|
xlr_online_cpumask = read_c0_register32(MIPS_COP_0_OSSCRATCH, 2);
|
|
|
|
xlr_run_mode = read_c0_register32(MIPS_COP_0_OSSCRATCH, 3);
|
|
|
|
xlr_argc = read_c0_register32(MIPS_COP_0_OSSCRATCH, 4);
|
2010-07-15 16:39:17 +00:00
|
|
|
/*
|
|
|
|
* argv and envp are passed in array of 32bit pointers
|
|
|
|
*/
|
|
|
|
xlr_argv = (int32_t *)(intptr_t)(int)read_c0_register32(MIPS_COP_0_OSSCRATCH, 5);
|
|
|
|
xlr_envp = (int32_t *)(intptr_t)(int)read_c0_register32(MIPS_COP_0_OSSCRATCH, 6);
|
2009-10-15 21:14:42 +00:00
|
|
|
|
|
|
|
/* TODO: Verify the magic number here */
|
2009-10-29 21:14:10 +00:00
|
|
|
/* FIXMELATER: xlr_boot1_info.magic_number */
|
2009-10-15 21:14:42 +00:00
|
|
|
|
2010-05-21 05:34:19 +00:00
|
|
|
/* Initialize pcpu stuff */
|
|
|
|
mips_pcpu0_init();
|
|
|
|
|
2009-10-15 21:14:42 +00:00
|
|
|
/* initialize console so that we have printf */
|
2009-10-29 21:14:10 +00:00
|
|
|
boothowto |= (RB_SERIAL | RB_MULTIPLE); /* Use multiple consoles */
|
|
|
|
|
2009-10-15 21:14:42 +00:00
|
|
|
/* clockrate used by delay, so initialize it here */
|
2009-10-29 21:14:10 +00:00
|
|
|
cpu_clock = xlr_boot1_info.cpu_frequency / 1000000;
|
2009-10-29 15:55:25 +00:00
|
|
|
|
2009-10-29 21:14:10 +00:00
|
|
|
/*
|
|
|
|
* Note the time counter on CPU0 runs not at system clock speed, but
|
|
|
|
* at PIC time counter speed (which is returned by
|
|
|
|
* platform_get_frequency(). Thus we do not use
|
|
|
|
* xlr_boot1_info.cpu_frequency here.
|
2009-10-29 15:55:25 +00:00
|
|
|
*/
|
2010-07-27 09:22:41 +00:00
|
|
|
mips_timer_early_init(xlr_boot1_info.cpu_frequency);
|
2009-11-05 18:14:25 +00:00
|
|
|
|
|
|
|
/* Init console please */
|
2009-10-15 21:14:42 +00:00
|
|
|
cninit();
|
2009-10-28 21:36:46 +00:00
|
|
|
init_static_kenv(boot1_env, sizeof(boot1_env));
|
2009-10-29 21:14:10 +00:00
|
|
|
printf("Environment (from %d args):\n", xlr_argc - 1);
|
2009-10-15 21:14:42 +00:00
|
|
|
if (xlr_argc == 1)
|
|
|
|
printf("\tNone\n");
|
2009-10-29 21:14:10 +00:00
|
|
|
for (i = 1; i < xlr_argc; i++) {
|
2010-07-15 16:39:17 +00:00
|
|
|
char *n, *arg;
|
2009-10-28 21:36:46 +00:00
|
|
|
|
2010-07-15 16:39:17 +00:00
|
|
|
arg = (char *)(intptr_t)xlr_argv[i];
|
|
|
|
printf("\t%s\n", arg);
|
|
|
|
n = strsep(&arg, "=");
|
|
|
|
if (arg == NULL)
|
2009-10-28 21:36:46 +00:00
|
|
|
setenv(n, "1");
|
|
|
|
else
|
2010-07-15 16:39:17 +00:00
|
|
|
setenv(n, arg);
|
2009-10-15 21:14:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
xlr_set_boot_flags();
|
2010-05-21 05:34:19 +00:00
|
|
|
xlr_parse_mmu_options();
|
2009-10-15 21:14:42 +00:00
|
|
|
|
2010-08-25 08:48:54 +00:00
|
|
|
xlr_mem_init();
|
2009-10-15 21:14:42 +00:00
|
|
|
/* Set up hz, among others. */
|
|
|
|
mips_init();
|
|
|
|
|
|
|
|
#ifdef SMP
|
2009-10-29 21:14:10 +00:00
|
|
|
/*
|
|
|
|
* If thread 0 of any core is not available then mark whole core as
|
|
|
|
* not available
|
|
|
|
*/
|
2009-10-15 21:14:42 +00:00
|
|
|
tmp = xlr_boot1_info.cpu_online_map;
|
2009-10-29 21:14:10 +00:00
|
|
|
for (i = 4; i < MAXCPU; i += 4) {
|
|
|
|
if ((tmp & (0xf << i)) && !(tmp & (0x1 << i))) {
|
|
|
|
/*
|
2010-05-21 05:34:19 +00:00
|
|
|
* Oops.. thread 0 is not available. Disable whole
|
2009-10-29 21:14:10 +00:00
|
|
|
* core
|
|
|
|
*/
|
|
|
|
tmp = tmp & ~(0xf << i);
|
2009-10-15 21:14:42 +00:00
|
|
|
printf("WARNING: Core %d is disabled because thread 0"
|
2009-10-29 21:14:10 +00:00
|
|
|
" of this core is not enabled.\n", i / 4);
|
2009-10-15 21:14:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
xlr_boot1_info.cpu_online_map = tmp;
|
|
|
|
|
|
|
|
/* Wakeup Other cpus, and put them in bsd park code. */
|
2009-10-29 21:14:10 +00:00
|
|
|
wakeup = ((void (*) (void *, void *, unsigned int))
|
|
|
|
(unsigned long)(xlr_boot1_info.wakeup));
|
2010-08-11 19:56:09 +00:00
|
|
|
printf("Waking up CPUs 0x%jx.\n",
|
|
|
|
(intmax_t)xlr_boot1_info.cpu_online_map & ~(0x1U));
|
2009-10-29 21:14:10 +00:00
|
|
|
if (xlr_boot1_info.cpu_online_map & ~(0x1U))
|
2010-05-16 19:43:48 +00:00
|
|
|
wakeup(mpwait, 0,
|
2009-10-29 21:14:10 +00:00
|
|
|
(unsigned int)xlr_boot1_info.cpu_online_map);
|
2009-10-15 21:14:42 +00:00
|
|
|
#endif
|
|
|
|
|
2009-10-29 21:14:10 +00:00
|
|
|
/* xlr specific post initialization */
|
2010-08-25 08:48:54 +00:00
|
|
|
/* initialize other on chip stuff */
|
|
|
|
xlr_board_info_setup();
|
|
|
|
xlr_msgring_config();
|
|
|
|
xlr_pic_init();
|
|
|
|
xlr_msgring_cpu_init();
|
|
|
|
|
2010-07-27 09:22:41 +00:00
|
|
|
mips_timer_init_params(xlr_boot1_info.cpu_frequency, 0);
|
2010-08-25 08:48:54 +00:00
|
|
|
|
2009-11-06 12:52:51 +00:00
|
|
|
printf("Platform specific startup now completes\n");
|
2009-10-15 21:14:42 +00:00
|
|
|
}
|
|
|
|
|
2010-05-21 05:34:19 +00:00
|
|
|
void
|
|
|
|
platform_cpu_init()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-10-15 21:14:42 +00:00
|
|
|
void
|
|
|
|
platform_identify(void)
|
|
|
|
{
|
2010-08-25 08:48:54 +00:00
|
|
|
|
2009-10-29 21:14:10 +00:00
|
|
|
printf("Board [%d:%d], processor 0x%08x\n", (int)xlr_boot1_info.board_major_version,
|
|
|
|
(int)xlr_boot1_info.board_minor_version, mips_rd_prid());
|
2009-10-15 21:14:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX Maybe return the state of the watchdog in enter, and pass it to
|
|
|
|
* exit? Like spl().
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
platform_trap_enter(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-05-21 05:34:19 +00:00
|
|
|
void
|
|
|
|
platform_reset(void)
|
|
|
|
{
|
|
|
|
xlr_reg_t *mmio = xlr_io_mmio(XLR_IO_GPIO_OFFSET);
|
|
|
|
|
|
|
|
/* write 1 to GPIO software reset register */
|
|
|
|
xlr_write_reg(mmio, 8, 1);
|
|
|
|
}
|
|
|
|
|
2009-10-15 21:14:42 +00:00
|
|
|
void
|
|
|
|
platform_trap_exit(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-05-16 19:43:48 +00:00
|
|
|
#ifdef SMP
|
|
|
|
int xlr_ap_release[MAXCPU];
|
2009-10-15 21:14:42 +00:00
|
|
|
|
2010-05-21 05:34:19 +00:00
|
|
|
int
|
|
|
|
platform_start_ap(int cpuid)
|
2009-10-15 21:14:42 +00:00
|
|
|
{
|
2010-05-21 05:34:19 +00:00
|
|
|
int hwid = xlr_cpuid_to_hwtid[cpuid];
|
|
|
|
|
|
|
|
if (xlr_boot1_info.cpu_online_map & (1<<hwid)) {
|
|
|
|
/*
|
|
|
|
* other cpus are enabled by the boot loader and they will be
|
|
|
|
* already looping in mpwait, release them
|
|
|
|
*/
|
|
|
|
atomic_store_rel_int(&xlr_ap_release[hwid], 1);
|
|
|
|
return (0);
|
|
|
|
} else
|
|
|
|
return (-1);
|
2009-10-15 21:14:42 +00:00
|
|
|
}
|
2009-10-29 21:14:10 +00:00
|
|
|
|
2010-05-21 05:34:19 +00:00
|
|
|
void
|
|
|
|
platform_init_ap(int cpuid)
|
2009-10-15 21:14:42 +00:00
|
|
|
{
|
2010-05-16 19:43:48 +00:00
|
|
|
uint32_t stat;
|
2009-10-15 21:14:42 +00:00
|
|
|
|
2010-05-21 05:34:19 +00:00
|
|
|
/* The first thread has to setup the core MMU split */
|
|
|
|
if (xlr_thr_id() == 0)
|
|
|
|
xlr_setup_mmu_split();
|
|
|
|
|
2010-05-16 19:43:48 +00:00
|
|
|
/* Setup interrupts for secondary CPUs here */
|
|
|
|
stat = mips_rd_status();
|
2010-05-18 04:02:34 +00:00
|
|
|
KASSERT((stat & MIPS_SR_INT_IE) == 0,
|
|
|
|
("Interrupts enabled in %s!", __func__));
|
2010-05-16 19:43:48 +00:00
|
|
|
stat |= MIPS_SR_COP_2_BIT | MIPS_SR_COP_0_BIT;
|
|
|
|
mips_wr_status(stat);
|
|
|
|
|
2010-09-01 17:35:31 +00:00
|
|
|
write_c0_eimr64(0ULL);
|
2010-08-27 19:53:57 +00:00
|
|
|
xlr_enable_irq(IRQ_IPI);
|
|
|
|
xlr_enable_irq(IRQ_TIMER);
|
2010-05-16 19:43:48 +00:00
|
|
|
if (xlr_thr_id() == 0) {
|
|
|
|
xlr_msgring_cpu_init();
|
2010-08-27 19:53:57 +00:00
|
|
|
xlr_enable_irq(IRQ_MSGRING);
|
2010-05-16 19:43:48 +00:00
|
|
|
}
|
2009-10-15 21:14:42 +00:00
|
|
|
|
2010-05-16 19:43:48 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-10-15 21:14:42 +00:00
|
|
|
|
2010-05-21 05:34:19 +00:00
|
|
|
int
|
|
|
|
platform_ipi_intrnum(void)
|
2010-05-16 19:43:48 +00:00
|
|
|
{
|
2010-08-25 08:48:54 +00:00
|
|
|
|
2010-05-21 05:34:19 +00:00
|
|
|
return (IRQ_IPI);
|
2010-05-16 19:43:48 +00:00
|
|
|
}
|
2009-10-15 21:14:42 +00:00
|
|
|
|
2010-05-21 05:34:19 +00:00
|
|
|
void
|
|
|
|
platform_ipi_send(int cpuid)
|
2010-05-16 19:43:48 +00:00
|
|
|
{
|
2010-08-25 08:48:54 +00:00
|
|
|
|
2010-08-25 11:49:48 +00:00
|
|
|
pic_send_ipi(xlr_cpuid_to_hwtid[cpuid], platform_ipi_intrnum());
|
2010-05-16 19:43:48 +00:00
|
|
|
}
|
2009-10-15 21:14:42 +00:00
|
|
|
|
2010-05-21 05:34:19 +00:00
|
|
|
void
|
|
|
|
platform_ipi_clear(void)
|
2010-05-16 19:43:48 +00:00
|
|
|
{
|
2009-10-15 21:14:42 +00:00
|
|
|
}
|
2010-05-16 19:43:48 +00:00
|
|
|
|
2010-05-21 05:34:19 +00:00
|
|
|
int
|
|
|
|
platform_processor_id(void)
|
2009-10-15 21:14:42 +00:00
|
|
|
{
|
2010-08-25 08:48:54 +00:00
|
|
|
|
2010-05-21 05:34:19 +00:00
|
|
|
return (xlr_hwtid_to_cpuid[xlr_cpu_id()]);
|
2009-10-15 21:14:42 +00:00
|
|
|
}
|
2010-05-16 19:43:48 +00:00
|
|
|
|
2010-05-21 05:34:19 +00:00
|
|
|
int
|
|
|
|
platform_num_processors(void)
|
2010-05-16 19:43:48 +00:00
|
|
|
{
|
2010-08-25 08:48:54 +00:00
|
|
|
|
2010-05-21 05:34:19 +00:00
|
|
|
return (xlr_ncores * xlr_threads_per_core);
|
2010-05-16 19:43:48 +00:00
|
|
|
}
|
2010-05-18 04:02:34 +00:00
|
|
|
|
|
|
|
struct cpu_group *
|
|
|
|
platform_smp_topo()
|
|
|
|
{
|
2010-08-25 08:48:54 +00:00
|
|
|
|
2010-05-21 05:34:19 +00:00
|
|
|
return (smp_topo_2level(CG_SHARE_L2, xlr_ncores, CG_SHARE_L1,
|
|
|
|
xlr_threads_per_core, CG_FLAG_THREAD));
|
2010-05-18 04:02:34 +00:00
|
|
|
}
|
2010-05-16 19:43:48 +00:00
|
|
|
#endif
|