/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2011-2012 Semihalf.4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND16* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE17* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE18* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE19* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL20* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS21* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)22* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT23* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY24* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF25* SUCH DAMAGE.26*/2728#include <sys/cdefs.h>2930#include <sys/types.h>31#include <sys/param.h>32#include <sys/proc.h>33#include <sys/reboot.h>3435#include <vm/vm.h>36#include <vm/pmap.h>3738#include <machine/machdep.h>3940#include <dev/fdt/fdt_common.h>4142#include <powerpc/mpc85xx/mpc85xx.h>4344extern void dcache_enable(void);45extern void dcache_inval(void);46extern void icache_enable(void);47extern void icache_inval(void);48extern void l2cache_enable(void);49extern void l2cache_inval(void);50extern void bpred_enable(void);5152void53booke_enable_l1_cache(void)54{55uint32_t csr;5657/* Enable D-cache if applicable */58csr = mfspr(SPR_L1CSR0);59if ((csr & L1CSR0_DCE) == 0) {60dcache_inval();61dcache_enable();62}6364csr = mfspr(SPR_L1CSR0);65if ((boothowto & RB_VERBOSE) != 0 || (csr & L1CSR0_DCE) == 0)66printf("L1 D-cache %sabled\n",67(csr & L1CSR0_DCE) ? "en" : "dis");6869/* Enable L1 I-cache if applicable. */70csr = mfspr(SPR_L1CSR1);71if ((csr & L1CSR1_ICE) == 0) {72icache_inval();73icache_enable();74}7576csr = mfspr(SPR_L1CSR1);77if ((boothowto & RB_VERBOSE) != 0 || (csr & L1CSR1_ICE) == 0)78printf("L1 I-cache %sabled\n",79(csr & L1CSR1_ICE) ? "en" : "dis");80}8182void83booke_enable_l2_cache(void)84{85uint32_t csr;8687/* Enable L2 cache on E500mc */88if ((((mfpvr() >> 16) & 0xFFFF) == FSL_E500mc) ||89(((mfpvr() >> 16) & 0xFFFF) == FSL_E5500)) {90csr = mfspr(SPR_L2CSR0);91/*92* Don't actually attempt to manipulate the L2 cache if93* L2CFG0 is zero.94*95* Any chip with a working L2 cache will have a nonzero96* L2CFG0, as it will have a nonzero L2CSIZE field.97*98* This fixes waiting forever for cache enable in qemu,99* which does not implement the L2 cache.100*/101if (mfspr(SPR_L2CFG0) != 0 && (csr & L2CSR0_L2E) == 0) {102l2cache_inval();103l2cache_enable();104}105106csr = mfspr(SPR_L2CSR0);107if ((boothowto & RB_VERBOSE) != 0 || (csr & L2CSR0_L2E) == 0)108printf("L2 cache %sabled\n",109(csr & L2CSR0_L2E) ? "en" : "dis");110}111}112113void114booke_enable_bpred(void)115{116uint32_t csr;117118bpred_enable();119csr = mfspr(SPR_BUCSR);120if ((boothowto & RB_VERBOSE) != 0 || (csr & BUCSR_BPEN) == 0)121printf("Branch Predictor %sabled\n",122(csr & BUCSR_BPEN) ? "en" : "dis");123}124125void126booke_disable_l2_cache(void)127{128}129130/* Return 0 on handled success, otherwise signal number. */131int132cpu_machine_check(struct thread *td, struct trapframe *frame, int *ucode)133{134135*ucode = BUS_OBJERR;136return (SIGBUS);137}138139140