#include <sys/cdefs.h>
#include <sys/types.h>
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/eventhandler.h>
#include <sys/proc.h>
#include <sys/reboot.h>
#include <sys/smp.h>
#include <vm/vm.h>
#include <vm/pmap.h>
#include <machine/machdep.h>
#include <dev/fdt/fdt_common.h>
#include <powerpc/mpc85xx/mpc85xx.h>
extern void dcache_enable(void);
extern void dcache_inval(void);
extern void icache_enable(void);
extern void icache_inval(void);
extern void l2cache_enable(void);
extern void l2cache_inval(void);
extern void bpred_enable(void);
void
booke_enable_l1_cache(void)
{
uint32_t csr;
csr = mfspr(SPR_L1CSR0);
if ((csr & L1CSR0_DCE) == 0) {
dcache_inval();
dcache_enable();
}
csr = mfspr(SPR_L1CSR0);
if ((boothowto & RB_VERBOSE) != 0 || (csr & L1CSR0_DCE) == 0)
printf("L1 D-cache %sabled\n",
(csr & L1CSR0_DCE) ? "en" : "dis");
csr = mfspr(SPR_L1CSR1);
if ((csr & L1CSR1_ICE) == 0) {
icache_inval();
icache_enable();
}
csr = mfspr(SPR_L1CSR1);
if ((boothowto & RB_VERBOSE) != 0 || (csr & L1CSR1_ICE) == 0)
printf("L1 I-cache %sabled\n",
(csr & L1CSR1_ICE) ? "en" : "dis");
}
void
booke_enable_l2_cache(void)
{
uint32_t csr;
if ((((mfpvr() >> 16) & 0xFFFF) == FSL_E500mc) ||
(((mfpvr() >> 16) & 0xFFFF) == FSL_E5500)) {
csr = mfspr(SPR_L2CSR0);
if (mfspr(SPR_L2CFG0) != 0 && (csr & L2CSR0_L2E) == 0) {
l2cache_inval();
l2cache_enable();
}
csr = mfspr(SPR_L2CSR0);
if ((boothowto & RB_VERBOSE) != 0 || (csr & L2CSR0_L2E) == 0)
printf("L2 cache %sabled\n",
(csr & L2CSR0_L2E) ? "en" : "dis");
}
}
void
booke_enable_bpred(void)
{
uint32_t csr;
bpred_enable();
csr = mfspr(SPR_BUCSR);
if ((boothowto & RB_VERBOSE) != 0 || (csr & BUCSR_BPEN) == 0)
printf("Branch Predictor %sabled\n",
(csr & BUCSR_BPEN) ? "en" : "dis");
}
void
booke_disable_l2_cache(void)
{
}
int
cpu_machine_check(struct thread *td, struct trapframe *frame, int *ucode)
{
*ucode = BUS_OBJERR;
return (SIGBUS);
}
static void
booke_watchdog_cpu(void *arg)
{
uint32_t tcr;
int bitno = (uintptr_t)arg;
mtspr(SPR_TSR, TSR_ENW | TSR_WIS);
tcr = mfspr(SPR_TCR);
tcr &= ~(TCR_WP_MASK | TCR_WPEXT_MASK);
tcr |= TCR_MAKE_WP(bitno);
tcr |= TCR_WRC_CHIP | TCR_WIE;
mtspr(SPR_TCR, tcr);
}
static void
booke_watchdog_fn(void *priv, sbintime_t sbt, sbintime_t *esbt, int *err)
{
struct cpuref cpuref;
uintptr_t tb_bit;
uint64_t freq, tb, ticks;
if (sbt == 0) {
*err = EOPNOTSUPP;
return;
}
cpuref.cr_hwref = 0;
cpuref.cr_cpuid = 0;
freq = platform_timebase_freq(&cpuref);
ticks = 1000000000 / freq;
ticks = sbttons(sbt) / ticks;
tb = mftb() & ((1 << flsll(ticks)) - 1);
tb += ticks;
tb_bit = 64 - flsll(tb);
smp_rendezvous(NULL, booke_watchdog_cpu, NULL, (void *)tb_bit);
*err = 0;
}
static void
booke_watchdog_register(void *arg)
{
printf("Registering booke watchdog timer\n");
EVENTHANDLER_REGISTER(watchdog_sbt_list, booke_watchdog_fn, NULL, 0);
}
SYSINIT(booke_watchdog, SI_SUB_LAST, SI_ORDER_ANY, booke_watchdog_register, NULL);