From d00b7f603c5fc8ad53b75772b6ba7e4b590fcc51 Mon Sep 17 00:00:00 2001 From: miod Date: Sun, 14 Apr 2024 19:08:09 +0000 Subject: [PATCH] Turn sp_tlb_flush_{ctx,pte} into function pointers, and pick one out of three flavours: pre-usIII, usIII, and sun4v. This allows us to get rid of the HORRID_III_HACK define in locore and switch pre-usIII systems to the older, slightly simpler, code for these routines. ok claudio@ kettenis@ --- sys/arch/sparc64/include/pte.h | 14 ++-- sys/arch/sparc64/sparc64/autoconf.c | 33 ++++---- sys/arch/sparc64/sparc64/ipifuncs.c | 10 +-- sys/arch/sparc64/sparc64/locore.s | 114 ++++++++++++++++------------ 4 files changed, 93 insertions(+), 78 deletions(-) diff --git a/sys/arch/sparc64/include/pte.h b/sys/arch/sparc64/include/pte.h index 07c862dcbae..bc45272563f 100644 --- a/sys/arch/sparc64/include/pte.h +++ b/sys/arch/sparc64/include/pte.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pte.h,v 1.16 2024/03/29 21:06:14 miod Exp $ */ +/* $OpenBSD: pte.h,v 1.17 2024/04/14 19:08:09 miod Exp $ */ /* $NetBSD: pte.h,v 1.7 2001/07/31 06:55:46 eeh Exp $ */ /* @@ -89,17 +89,17 @@ struct sun4u_tte { typedef struct sun4u_tte pte_t; /* Assembly routine to flush a mapping */ -extern void sp_tlb_flush_pte(vaddr_t addr, int ctx); -extern void sp_tlb_flush_ctx(int ctx); +extern void (*sp_tlb_flush_pte)(vaddr_t, uint64_t); +extern void (*sp_tlb_flush_ctx)(uint64_t); #if defined(MULTIPROCESSOR) -void smp_tlb_flush_pte(vaddr_t, int); -void smp_tlb_flush_ctx(int); +void smp_tlb_flush_pte(vaddr_t, uint64_t); +void smp_tlb_flush_ctx(uint64_t); #define tlb_flush_pte(va,ctx) smp_tlb_flush_pte(va, ctx) #define tlb_flush_ctx(ctx) smp_tlb_flush_ctx(ctx) #else -#define tlb_flush_pte(va,ctx) sp_tlb_flush_pte(va, ctx) -#define tlb_flush_ctx(ctx) sp_tlb_flush_ctx(ctx) +#define tlb_flush_pte(va,ctx) (*sp_tlb_flush_pte)(va, ctx) +#define tlb_flush_ctx(ctx) (*sp_tlb_flush_ctx)(ctx) #endif #endif /* _LOCORE */ diff --git a/sys/arch/sparc64/sparc64/autoconf.c b/sys/arch/sparc64/sparc64/autoconf.c index 0909be5fb7d..cd08a83cdbe 100644 --- a/sys/arch/sparc64/sparc64/autoconf.c +++ b/sys/arch/sparc64/sparc64/autoconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: autoconf.c,v 1.148 2024/04/08 19:59:28 miod Exp $ */ +/* $OpenBSD: autoconf.c,v 1.149 2024/04/14 19:08:09 miod Exp $ */ /* $NetBSD: autoconf.c,v 1.51 2001/07/24 19:32:11 eeh Exp $ */ /* @@ -170,6 +170,16 @@ void sun4v_interrupt_init(void); void sun4v_sdio_init(void); #endif +extern void us_tlb_flush_pte(vaddr_t, uint64_t); +extern void us3_tlb_flush_pte(vaddr_t, uint64_t); +extern void sun4v_tlb_flush_pte(vaddr_t, uint64_t); +extern void us_tlb_flush_ctx(uint64_t); +extern void us3_tlb_flush_ctx(uint64_t); +extern void sun4v_tlb_flush_ctx(uint64_t); + +void (*sp_tlb_flush_pte)(vaddr_t, uint64_t) = us_tlb_flush_pte; +void (*sp_tlb_flush_ctx)(uint64_t) = us_tlb_flush_ctx; + #ifdef DEBUG #define ACDB_BOOTDEV 0x1 #define ACDB_PROBE 0x2 @@ -342,6 +352,8 @@ bootstrap(int nctx) } cacheinfo.c_dcache_flush_page = us3_dcache_flush_page; + sp_tlb_flush_pte = us3_tlb_flush_pte; + sp_tlb_flush_ctx = us3_tlb_flush_ctx; } if ((impl >= IMPL_ZEUS && impl <= IMPL_JUPITER) || CPU_ISSUN4V) { @@ -375,22 +387,6 @@ bootstrap(int nctx) #ifdef SUN4V if (CPU_ISSUN4V) { - u_int32_t insn; - int32_t disp; - - disp = (vaddr_t)hv_mmu_demap_page - (vaddr_t)sp_tlb_flush_pte; - insn = 0x10800000 | disp >> 2; /* ba hv_mmu_demap_page */ - ((u_int32_t *)sp_tlb_flush_pte)[0] = insn; - insn = 0x94102003; /* mov MAP_ITLB|MAP_DTLB, %o2 */ - ((u_int32_t *)sp_tlb_flush_pte)[1] = insn; - - disp = (vaddr_t)hv_mmu_demap_ctx - (vaddr_t)sp_tlb_flush_ctx; - insn = 0x10800000 | disp >> 2; /* ba hv_mmu_demap_ctx */ - ((u_int32_t *)sp_tlb_flush_ctx)[0] = insn; - insn = 0x92102003; /* mov MAP_ITLB|MAP_DTLB, %o1 */ - ((u_int32_t *)sp_tlb_flush_ctx)[1] = insn; - - { struct sun4v_patch { u_int32_t addr; u_int32_t insn; @@ -413,8 +409,9 @@ bootstrap(int nctx) flush((void *)(vaddr_t)p->addr); } #endif - } + sp_tlb_flush_pte = sun4v_tlb_flush_pte; + sp_tlb_flush_ctx = sun4v_tlb_flush_ctx; } #endif diff --git a/sys/arch/sparc64/sparc64/ipifuncs.c b/sys/arch/sparc64/sparc64/ipifuncs.c index 2edd45a756b..b53a4e6e8fe 100644 --- a/sys/arch/sparc64/sparc64/ipifuncs.c +++ b/sys/arch/sparc64/sparc64/ipifuncs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ipifuncs.c,v 1.21 2024/04/11 18:58:44 miod Exp $ */ +/* $OpenBSD: ipifuncs.c,v 1.22 2024/04/14 19:08:09 miod Exp $ */ /* $NetBSD: ipifuncs.c,v 1.8 2006/10/07 18:11:36 rjs Exp $ */ /*- @@ -211,9 +211,9 @@ sun4v_broadcast_ipi(void (*func)(void), u_int64_t arg0, u_int64_t arg1) } void -smp_tlb_flush_pte(vaddr_t va, int ctx) +smp_tlb_flush_pte(vaddr_t va, uint64_t ctx) { - sp_tlb_flush_pte(va, ctx); + (*sp_tlb_flush_pte)(va, ctx); if (db_active) return; @@ -225,9 +225,9 @@ smp_tlb_flush_pte(vaddr_t va, int ctx) } void -smp_tlb_flush_ctx(int ctx) +smp_tlb_flush_ctx(uint64_t ctx) { - sp_tlb_flush_ctx(ctx); + (*sp_tlb_flush_ctx)(ctx); if (db_active) return; diff --git a/sys/arch/sparc64/sparc64/locore.s b/sys/arch/sparc64/sparc64/locore.s index 1ff66746066..76f50f60127 100644 --- a/sys/arch/sparc64/sparc64/locore.s +++ b/sys/arch/sparc64/sparc64/locore.s @@ -1,4 +1,4 @@ -/* $OpenBSD: locore.s,v 1.222 2024/04/08 20:09:18 miod Exp $ */ +/* $OpenBSD: locore.s,v 1.223 2024/04/14 19:08:09 miod Exp $ */ /* $NetBSD: locore.s,v 1.137 2001/08/13 06:10:10 jdolecek Exp $ */ /* @@ -56,8 +56,6 @@ * @(#)locore.s 8.4 (Berkeley) 12/10/93 */ -#define HORRID_III_HACK - .register %g2, .register %g3, @@ -410,9 +408,10 @@ cold: .endm .macro KCLEANWIN - clr %l0 #ifdef DEBUG set 0xbadbeef, %l0 ! DEBUG +#else + clr %l0 #endif /* DEBUG */ mov %l0, %l1; mov %l0, %l2 ! 024-027 = clean window trap rdpr %cleanwin, %o7 ! This handler is in-lined and cannot fault @@ -1118,12 +1117,6 @@ trapbase_sun4v: * Finally, we may now call C code. * * This macro will destroy %g5-%g7. %g0-%g4 remain unchanged. - * - * In order to properly handle nested traps without lossage, alternate - * global %g6 is used as a kernel stack pointer. It is set to the last - * allocated stack pointer (trapframe) and the old value is stored in - * tf_kstack. It is restored when returning from a trap. It is cleared - * on entering user mode. */ /* @@ -2042,8 +2035,8 @@ text_error: #ifdef SUN4V /* - * Perform an inline pseg_get(), to retrieve the pte associated to the given - * virtual address. + * Perform an inline pseg_get(), to retrieve the address of the PTE associated + * to the given virtual address. * On entry: %g3 = va (won't be modified), %g6 = context * Registers used: %g4,%g5, %g6 * Branches to the "failure" label if translation invalid, otherwise ends @@ -2676,7 +2669,19 @@ sun4v_texttrap: nop NOTREACHED -#endif + .align 8 +NENTRY(sun4v_tlb_flush_pte) + ba hv_mmu_demap_page + mov MAP_ITLB|MAP_DTLB, %o2 +END(sun4v_tlb_flush_pte) + + .align 8 +NENTRY(sun4v_tlb_flush_ctx) + ba hv_mmu_demap_ctx + mov MAP_ITLB|MAP_DTLB, %o1 +END(sun4v_tlb_flush_ctx) + +#endif /* SUN4V */ /* * We're here because we took an alignment fault in NUCLEUS context. @@ -3964,8 +3969,28 @@ END(openfirmware) * */ .align 8 -NENTRY(sp_tlb_flush_pte) -#ifdef HORRID_III_HACK +NENTRY(us_tlb_flush_pte) + mov CTX_SECONDARY, %o2 + andn %o0, 0xfff, %g2 ! drop unused va bits + ldxa [%o2] ASI_DMMU, %g1 ! Save secondary context + sethi %hi(KERNBASE), %o4 + membar #LoadStore + stxa %o1, [%o2] ASI_DMMU ! Insert context to demap + membar #Sync + or %g2, DEMAP_PAGE_SECONDARY, %g2 ! Demap page from secondary context only + stxa %g0, [%g2] ASI_DMMU_DEMAP ! Do the demap + stxa %g0, [%g2] ASI_IMMU_DEMAP ! to both TLBs + membar #Sync ! No real reason for this XXXX + flush %o4 + stxa %g1, [%o2] ASI_DMMU ! Restore asi + membar #Sync ! No real reason for this XXXX + flush %o4 + retl + nop +END(us_tlb_flush_pte) + + .align 8 +NENTRY(us3_tlb_flush_pte) rdpr %pstate, %o5 andn %o5, PSTATE_IE, %o4 wrpr %o4, %pstate ! disable interrupts @@ -3983,31 +4008,18 @@ NENTRY(sp_tlb_flush_pte) stxa %o1, [%o2] ASI_DMMU ! Insert context to demap membar #Sync or %g2, DEMAP_PAGE_PRIMARY, %g2 ! Demap page from primary context only -#else - mov CTX_SECONDARY, %o2 - andn %o0, 0xfff, %g2 ! drop unused va bits - ldxa [%o2] ASI_DMMU, %g1 ! Save secondary context - sethi %hi(KERNBASE), %o4 - membar #LoadStore - stxa %o1, [%o2] ASI_DMMU ! Insert context to demap - membar #Sync - or %g2, DEMAP_PAGE_SECONDARY, %g2 ! Demap page from secondary context only -#endif - stxa %g2, [%g2] ASI_DMMU_DEMAP ! Do the demap - membar #Sync - stxa %g2, [%g2] ASI_IMMU_DEMAP ! to both TLBs + stxa %g0, [%g2] ASI_DMMU_DEMAP ! Do the demap + stxa %g0, [%g2] ASI_IMMU_DEMAP ! to both TLBs membar #Sync ! No real reason for this XXXX flush %o4 stxa %g1, [%o2] ASI_DMMU ! Restore asi membar #Sync ! No real reason for this XXXX flush %o4 -#ifdef HORRID_III_HACK wrpr %g0, %o3, %tl ! Restore traplevel wrpr %o5, %pstate ! Restore interrupts -#endif retl nop -END(sp_tlb_flush_pte) +END(us_tlb_flush_pte) /* * tlb_flush_ctx(int ctx) @@ -4016,8 +4028,26 @@ END(sp_tlb_flush_pte) * */ .align 8 -NENTRY(sp_tlb_flush_ctx) -#ifdef HORRID_III_HACK +NENTRY(us_tlb_flush_ctx) + mov CTX_SECONDARY, %o2 + sethi %hi(KERNBASE), %o4 + ldxa [%o2] ASI_DMMU, %g1 ! Save secondary context + membar #LoadStore + stxa %o0, [%o2] ASI_DMMU ! Insert context to demap + membar #Sync + set DEMAP_CTX_SECONDARY, %g2 ! Demap context from secondary context only + stxa %g0, [%g2] ASI_DMMU_DEMAP ! Do the demap + stxa %g0, [%g2] ASI_IMMU_DEMAP ! Do the demap + membar #Sync + stxa %g1, [%o2] ASI_DMMU ! Restore secondary asi + membar #Sync ! No real reason for this XXXX + flush %o4 + retl + nop +END(us_tlb_flush_ctx) + + .align 8 +NENTRY(us3_tlb_flush_ctx) rdpr %pstate, %o5 andn %o5, PSTATE_IE, %o4 wrpr %o4, %pstate ! disable interrupts @@ -4034,29 +4064,17 @@ NENTRY(sp_tlb_flush_ctx) stxa %o0, [%o2] ASI_DMMU ! Insert context to demap membar #Sync set DEMAP_CTX_PRIMARY, %g2 ! Demap context from primary context only -#else - mov CTX_SECONDARY, %o2 - sethi %hi(KERNBASE), %o4 - ldxa [%o2] ASI_DMMU, %g1 ! Save secondary context - membar #LoadStore - stxa %o0, [%o2] ASI_DMMU ! Insert context to demap - membar #Sync - set DEMAP_CTX_SECONDARY, %g2 ! Demap context from secondary context only -#endif - stxa %g2, [%g2] ASI_DMMU_DEMAP ! Do the demap - membar #Sync ! No real reason for this XXXX - stxa %g2, [%g2] ASI_IMMU_DEMAP ! Do the demap + stxa %g0, [%g2] ASI_DMMU_DEMAP ! Do the demap + stxa %g0, [%g2] ASI_IMMU_DEMAP ! Do the demap membar #Sync stxa %g1, [%o2] ASI_DMMU ! Restore secondary asi membar #Sync ! No real reason for this XXXX flush %o4 -#ifdef HORRID_III_HACK wrpr %g0, %o3, %tl ! Restore traplevel wrpr %o5, %pstate ! Restore interrupts -#endif retl nop -END(sp_tlb_flush_ctx) +END(us3_tlb_flush_ctx) /* * dcache_flush_page(paddr_t pa) -- 2.20.1