Thu Mar 11 04:43:47 2021 UTC ()
Tidy up initialization of the kernel SRs just a bit.


(thorpej)
diff -r1.102 -r1.103 src/sys/arch/powerpc/oea/pmap.c

cvs diff -r1.102 -r1.103 src/sys/arch/powerpc/oea/pmap.c (expand / switch to unified diff)

--- src/sys/arch/powerpc/oea/pmap.c 2021/03/10 18:29:07 1.102
+++ src/sys/arch/powerpc/oea/pmap.c 2021/03/11 04:43:47 1.103
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: pmap.c,v 1.102 2021/03/10 18:29:07 thorpej Exp $ */ 1/* $NetBSD: pmap.c,v 1.103 2021/03/11 04:43:47 thorpej Exp $ */
2/*- 2/*-
3 * Copyright (c) 2001 The NetBSD Foundation, Inc. 3 * Copyright (c) 2001 The NetBSD Foundation, Inc.
4 * All rights reserved. 4 * All rights reserved.
5 * 5 *
6 * This code is derived from software contributed to The NetBSD Foundation 6 * This code is derived from software contributed to The NetBSD Foundation
7 * by Matt Thomas <matt@3am-software.com> of Allegro Networks, Inc. 7 * by Matt Thomas <matt@3am-software.com> of Allegro Networks, Inc.
8 * 8 *
9 * Support for PPC64 Bridge mode added by Sanjay Lal <sanjayl@kymasys.com> 9 * Support for PPC64 Bridge mode added by Sanjay Lal <sanjayl@kymasys.com>
10 * of Kyma Systems LLC. 10 * of Kyma Systems LLC.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions 13 * modification, are permitted provided that the following conditions
14 * are met: 14 * are met:
@@ -53,27 +53,27 @@ @@ -53,27 +53,27 @@
53 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR 53 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
54 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 54 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
55 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 55 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
56 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 56 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
57 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 57 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
58 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 58 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
59 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 59 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
60 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 60 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
61 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 61 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
62 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 62 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63 */ 63 */
64 64
65#include <sys/cdefs.h> 65#include <sys/cdefs.h>
66__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.102 2021/03/10 18:29:07 thorpej Exp $"); 66__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.103 2021/03/11 04:43:47 thorpej Exp $");
67 67
68#define PMAP_NOOPNAMES 68#define PMAP_NOOPNAMES
69 69
70#ifdef _KERNEL_OPT 70#ifdef _KERNEL_OPT
71#include "opt_altivec.h" 71#include "opt_altivec.h"
72#include "opt_multiprocessor.h" 72#include "opt_multiprocessor.h"
73#include "opt_pmap.h" 73#include "opt_pmap.h"
74#include "opt_ppcarch.h" 74#include "opt_ppcarch.h"
75#endif 75#endif
76 76
77#include <sys/param.h> 77#include <sys/param.h>
78#include <sys/proc.h> 78#include <sys/proc.h>
79#include <sys/pool.h> 79#include <sys/pool.h>
@@ -3368,53 +3368,49 @@ pmap_bootstrap1(paddr_t kernelstart, pad @@ -3368,53 +3368,49 @@ pmap_bootstrap1(paddr_t kernelstart, pad
3368 } 3368 }
3369 } 3369 }
3370 3370
3371 /* 3371 /*
3372 * Make sure kernel vsid is allocated as well as VSID 0. 3372 * Make sure kernel vsid is allocated as well as VSID 0.
3373 */ 3373 */
3374 pmap_vsid_bitmap[(KERNEL_VSIDBITS & (NPMAPS-1)) / VSID_NBPW] 3374 pmap_vsid_bitmap[(KERNEL_VSIDBITS & (NPMAPS-1)) / VSID_NBPW]
3375 |= 1 << (KERNEL_VSIDBITS % VSID_NBPW); 3375 |= 1 << (KERNEL_VSIDBITS % VSID_NBPW);
3376 pmap_vsid_bitmap[(PHYSMAP_VSIDBITS & (NPMAPS-1)) / VSID_NBPW] 3376 pmap_vsid_bitmap[(PHYSMAP_VSIDBITS & (NPMAPS-1)) / VSID_NBPW]
3377 |= 1 << (PHYSMAP_VSIDBITS % VSID_NBPW); 3377 |= 1 << (PHYSMAP_VSIDBITS % VSID_NBPW);
3378 pmap_vsid_bitmap[0] |= 1; 3378 pmap_vsid_bitmap[0] |= 1;
3379 3379
3380 /* 3380 /*
3381 * Initialize kernel pmap and hardware. 3381 * Initialize kernel pmap.
3382 */ 3382 */
3383 3383#if defined(PMAP_OEA) || defined(PMAP_OEA64_BRIDGE)
3384/* PMAP_OEA64_BRIDGE does support these instructions */ 
3385#if defined (PMAP_OEA) || defined (PMAP_OEA64_BRIDGE) 
3386 for (i = 0; i < 16; i++) { 3384 for (i = 0; i < 16; i++) {
3387#if defined(PPC_OEA601) 
3388 /* XXX wedges for segment register 0xf , so set later */ 
3389 if ((iosrtable[i] & SR601_T) && ((MFPVR() >> 16) == MPC601)) 
3390 continue; 
3391#endif 
3392 pmap_kernel()->pm_sr[i] = KERNELN_SEGMENT(i)|SR_PRKEY; 3385 pmap_kernel()->pm_sr[i] = KERNELN_SEGMENT(i)|SR_PRKEY;
3393 } 3386 }
3394 pmap_kernel()->pm_vsid = KERNEL_VSIDBITS; 3387 pmap_kernel()->pm_vsid = KERNEL_VSIDBITS;
3395 3388
3396 pmap_kernel()->pm_sr[KERNEL_SR] = KERNEL_SEGMENT|SR_SUKEY|SR_PRKEY; 3389 pmap_kernel()->pm_sr[KERNEL_SR] = KERNEL_SEGMENT|SR_SUKEY|SR_PRKEY;
3397#ifdef KERNEL2_SR 3390#ifdef KERNEL2_SR
3398 pmap_kernel()->pm_sr[KERNEL2_SR] = KERNEL2_SEGMENT|SR_SUKEY|SR_PRKEY; 3391 pmap_kernel()->pm_sr[KERNEL2_SR] = KERNEL2_SEGMENT|SR_SUKEY|SR_PRKEY;
3399#endif 3392#endif
3400#endif /* PMAP_OEA || PMAP_OEA64_BRIDGE */ 3393#endif /* PMAP_OEA || PMAP_OEA64_BRIDGE */
3401#if defined (PMAP_OEA) 3394
3402 for (i = 0; i < 16; i++) { 3395#if defined(PMAP_OEA) && defined(PPC_OEA601)
3403 if (iosrtable[i] & SR601_T) { 3396 if ((MFPVR() >> 16) == MPC601)) {
3404 pmap_kernel()->pm_sr[i] = iosrtable[i]; 3397 for (i = 0; i < 16; i++) {
 3398 if (iosrtable[i] & SR601_T) {
 3399 pmap_kernel()->pm_sr[i] = iosrtable[i];
 3400 }
3405 } 3401 }
3406 } 3402 }
3407#endif 3403#endif /* PMAP_OEA && PPC_OEA601 */
3408 3404
3409#ifdef ALTIVEC 3405#ifdef ALTIVEC
3410 pmap_use_altivec = cpu_altivec; 3406 pmap_use_altivec = cpu_altivec;
3411#endif 3407#endif
3412 3408
3413#ifdef DEBUG 3409#ifdef DEBUG
3414 if (pmapdebug & PMAPDEBUG_BOOT) { 3410 if (pmapdebug & PMAPDEBUG_BOOT) {
3415 u_int cnt; 3411 u_int cnt;
3416 uvm_physseg_t bank; 3412 uvm_physseg_t bank;
3417 char pbuf[9]; 3413 char pbuf[9];
3418 for (cnt = 0, bank = uvm_physseg_get_first(); 3414 for (cnt = 0, bank = uvm_physseg_get_first();
3419 uvm_physseg_valid_p(bank); 3415 uvm_physseg_valid_p(bank);
3420 bank = uvm_physseg_get_next(bank)) { 3416 bank = uvm_physseg_get_next(bank)) {
@@ -3490,63 +3486,58 @@ pmap_bootstrap1(paddr_t kernelstart, pad @@ -3490,63 +3486,58 @@ pmap_bootstrap1(paddr_t kernelstart, pad
3490 ptegidx = va_to_pteg(pm, va); 3486 ptegidx = va_to_pteg(pm, va);
3491 if (va < 0x3000) 3487 if (va < 0x3000)
3492 pmap_pte_create(&pt, pm, va, pa | PTE_M|PTE_BR); 3488 pmap_pte_create(&pt, pm, va, pa | PTE_M|PTE_BR);
3493 else 3489 else
3494 pmap_pte_create(&pt, pm, va, pa | PTE_M|PTE_BW); 3490 pmap_pte_create(&pt, pm, va, pa | PTE_M|PTE_BW);
3495 pmap_pte_insert(ptegidx, &pt); 3491 pmap_pte_insert(ptegidx, &pt);
3496 } 3492 }
3497 for (va = kernelend, pa = kernelend; va < SEGMENT_LENGTH; 3493 for (va = kernelend, pa = kernelend; va < SEGMENT_LENGTH;
3498 pa += PAGE_SIZE, va += PAGE_SIZE) { 3494 pa += PAGE_SIZE, va += PAGE_SIZE) {
3499 ptegidx = va_to_pteg(pm, va); 3495 ptegidx = va_to_pteg(pm, va);
3500 pmap_pte_create(&pt, pm, va, pa | PTE_M|PTE_BW); 3496 pmap_pte_create(&pt, pm, va, pa | PTE_M|PTE_BW);
3501 pmap_pte_insert(ptegidx, &pt); 3497 pmap_pte_insert(ptegidx, &pt);
3502 } 3498 }
3503#endif 3499#endif /* PMAP_NEED_FULL_MAPKERNEL */
3504 } 3500 }
3505#endif 3501#endif /* PMAP_NEED_MAPKERNEL */
3506} 3502}
3507 3503
3508/* 3504/*
3509 * Using the data structures prepared in pmap_bootstrap1(), program 3505 * Using the data structures prepared in pmap_bootstrap1(), program
3510 * the MMU hardware. 3506 * the MMU hardware.
3511 */ 3507 */
3512void 3508void
3513pmap_bootstrap2(void) 3509pmap_bootstrap2(void)
3514{ 3510{
3515/* PMAP_OEA64_BRIDGE does support these instructions */ 3511#if defined(PMAP_OEA) || defined(PMAP_OEA64_BRIDGE)
3516#if defined (PMAP_OEA) || defined (PMAP_OEA64_BRIDGE) 
3517 for (int i = 0; i < 16; i++) { 3512 for (int i = 0; i < 16; i++) {
3518#if defined(PPC_OEA601) 
3519 /* XXX wedges for segment register 0xf , so set later */ 
3520 if ((iosrtable[i] & SR601_T) && ((MFPVR() >> 16) == MPC601)) 
3521 continue; 
3522#endif /* PPC_OEA601 */ 
3523 __asm volatile("mtsrin %0,%1" 3513 __asm volatile("mtsrin %0,%1"
3524 :: "r"(pmap_kernel()->pm_sr[i]), 3514 :: "r"(pmap_kernel()->pm_sr[i]),
3525 "r"(i << ADDR_SR_SHFT)); 3515 "r"(i << ADDR_SR_SHFT));
3526 } 3516 }
3527#endif /* PMAP_OEA || PMAP_OEA64_BRIDGE */ 3517#endif /* PMAP_OEA || PMAP_OEA64_BRIDGE */
3528#if defined (PMAP_OEA) 3518
 3519#if defined(PMAP_OEA)
3529 __asm volatile("sync; mtsdr1 %0; isync" 3520 __asm volatile("sync; mtsdr1 %0; isync"
3530 :: "r"((uintptr_t)pmap_pteg_table | (pmap_pteg_mask >> 10))); 3521 :: "r"((uintptr_t)pmap_pteg_table | (pmap_pteg_mask >> 10)));
3531#elif defined (PMAP_OEA64) || defined (PMAP_OEA64_BRIDGE) 3522#elif defined(PMAP_OEA64) || defined(PMAP_OEA64_BRIDGE)
3532 __asm __volatile("sync; mtsdr1 %0; isync" 3523 __asm __volatile("sync; mtsdr1 %0; isync"
3533 :: "r"((uintptr_t)pmap_pteg_table | 3524 :: "r"((uintptr_t)pmap_pteg_table |
3534 (32 - __builtin_clz(pmap_pteg_mask >> 11)))); 3525 (32 - __builtin_clz(pmap_pteg_mask >> 11))));
3535#endif 3526#endif
3536 tlbia(); 3527 tlbia();
3537 3528
3538#if defined(PMAPDEBUG) 3529#if defined(PMAPDEBUG)
3539 if ( pmapdebug ) 3530 if (pmapdebug)
3540 pmap_print_mmuregs(); 3531 pmap_print_mmuregs();
3541#endif 3532#endif
3542} 3533}
3543 3534
3544/* 3535/*
3545 * This is not part of the defined PMAP interface and is specific to the 3536 * This is not part of the defined PMAP interface and is specific to the
3546 * PowerPC architecture. This is called during initppc, before the system 3537 * PowerPC architecture. This is called during initppc, before the system
3547 * is really initialized. 3538 * is really initialized.
3548 */ 3539 */
3549void 3540void
3550pmap_bootstrap(paddr_t kernelstart, paddr_t kernelend) 3541pmap_bootstrap(paddr_t kernelstart, paddr_t kernelend)
3551{ 3542{
3552 pmap_bootstrap1(kernelstart, kernelend); 3543 pmap_bootstrap1(kernelstart, kernelend);