From 8415f755f1d25c350d9570172d2ed0470e8a35a2 Mon Sep 17 00:00:00 2001 From: Brandon Bergren Date: Fri, 19 Jun 2020 18:40:39 +0000 Subject: [PATCH] [PowerPC] Fix booke64 qemu infinite loop in L2 cache enable Since qemu does not implement the L2 cache, we get stuck forever waiting for a bit to be set when trying to invalidate it. To prevent that, we should bail out if the L2 cache is missing. One easy way to check this is L2CFG0 == 0 (since L2CSIZE always has at least one bit set in a valid implementation) (tested on qemu, rb800, and x5000) Reviewed by: jhibbits Sponsored by: Tag1 Consulting, Inc. Differential Revision: https://reviews.freebsd.org/D25225 --- sys/powerpc/booke/machdep_e500.c | 12 +++++++++++- sys/powerpc/include/spr.h | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/sys/powerpc/booke/machdep_e500.c b/sys/powerpc/booke/machdep_e500.c index c76a0cc822bb..0e4ac3943e2b 100644 --- a/sys/powerpc/booke/machdep_e500.c +++ b/sys/powerpc/booke/machdep_e500.c @@ -91,7 +91,17 @@ booke_enable_l2_cache(void) if ((((mfpvr() >> 16) & 0xFFFF) == FSL_E500mc) || (((mfpvr() >> 16) & 0xFFFF) == FSL_E5500)) { csr = mfspr(SPR_L2CSR0); - if ((csr & L2CSR0_L2E) == 0) { + /* + * Don't actually attempt to manipulate the L2 cache if + * L2CFG0 is zero. + * + * Any chip with a working L2 cache will have a nonzero + * L2CFG0, as it will have a nonzero L2CSIZE field. + * + * This fixes waiting forever for cache enable in qemu, + * which does not implement the L2 cache. + */ + if (mfspr(SPR_L2CFG0) != 0 && (csr & L2CSR0_L2E) == 0) { l2cache_inval(); l2cache_enable(); } diff --git a/sys/powerpc/include/spr.h b/sys/powerpc/include/spr.h index 6da97e743338..9ee165285d18 100644 --- a/sys/powerpc/include/spr.h +++ b/sys/powerpc/include/spr.h @@ -887,6 +887,7 @@ #define L1CSR1_ICFI 0x00000002 /* Instruction Cache Flash Invalidate */ #define L1CSR1_ICE 0x00000001 /* Instruction Cache Enable */ +#define SPR_L2CFG0 0x207 /* ..8 L2 Configuration Register 0 */ #define SPR_L2CSR0 0x3F9 /* ..8 L2 Cache Control and Status Register 0 */ #define L2CSR0_L2E 0x80000000 /* L2 Cache Enable */ #define L2CSR0_L2PE 0x40000000 /* L2 Cache Parity Enable */