Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  *  PS3 pagetable management routines.
0004  *
0005  *  Copyright (C) 2006 Sony Computer Entertainment Inc.
0006  *  Copyright 2006, 2007 Sony Corporation
0007  */
0008 
0009 #include <linux/kernel.h>
0010 #include <linux/memblock.h>
0011 
0012 #include <asm/machdep.h>
0013 #include <asm/udbg.h>
0014 #include <asm/lv1call.h>
0015 #include <asm/ps3fb.h>
0016 
0017 #define PS3_VERBOSE_RESULT
0018 #include "platform.h"
0019 
0020 /**
0021  * enum lpar_vas_id - id of LPAR virtual address space.
0022  * @lpar_vas_id_current: Current selected virtual address space
0023  *
0024  * Identify the target LPAR address space.
0025  */
0026 
0027 enum ps3_lpar_vas_id {
0028     PS3_LPAR_VAS_ID_CURRENT = 0,
0029 };
0030 
0031 
0032 static DEFINE_SPINLOCK(ps3_htab_lock);
0033 
0034 static long ps3_hpte_insert(unsigned long hpte_group, unsigned long vpn,
0035     unsigned long pa, unsigned long rflags, unsigned long vflags,
0036     int psize, int apsize, int ssize)
0037 {
0038     int result;
0039     u64 hpte_v, hpte_r;
0040     u64 inserted_index;
0041     u64 evicted_v, evicted_r;
0042     u64 hpte_v_array[4], hpte_rs;
0043     unsigned long flags;
0044     long ret = -1;
0045 
0046     /*
0047      * lv1_insert_htab_entry() will search for victim
0048      * entry in both primary and secondary pte group
0049      */
0050     vflags &= ~HPTE_V_SECONDARY;
0051 
0052     hpte_v = hpte_encode_v(vpn, psize, apsize, ssize) | vflags | HPTE_V_VALID;
0053     hpte_r = hpte_encode_r(ps3_mm_phys_to_lpar(pa), psize, apsize) | rflags;
0054 
0055     spin_lock_irqsave(&ps3_htab_lock, flags);
0056 
0057     /* talk hvc to replace entries BOLTED == 0 */
0058     result = lv1_insert_htab_entry(PS3_LPAR_VAS_ID_CURRENT, hpte_group,
0059                        hpte_v, hpte_r,
0060                        HPTE_V_BOLTED, 0,
0061                        &inserted_index,
0062                        &evicted_v, &evicted_r);
0063 
0064     if (result) {
0065         /* all entries bolted !*/
0066         pr_info("%s:result=%s vpn=%lx pa=%lx ix=%lx v=%llx r=%llx\n",
0067             __func__, ps3_result(result), vpn, pa, hpte_group,
0068             hpte_v, hpte_r);
0069         BUG();
0070     }
0071 
0072     /*
0073      * see if the entry is inserted into secondary pteg
0074      */
0075     result = lv1_read_htab_entries(PS3_LPAR_VAS_ID_CURRENT,
0076                        inserted_index & ~0x3UL,
0077                        &hpte_v_array[0], &hpte_v_array[1],
0078                        &hpte_v_array[2], &hpte_v_array[3],
0079                        &hpte_rs);
0080     BUG_ON(result);
0081 
0082     if (hpte_v_array[inserted_index % 4] & HPTE_V_SECONDARY)
0083         ret = (inserted_index & 7) | (1 << 3);
0084     else
0085         ret = inserted_index & 7;
0086 
0087     spin_unlock_irqrestore(&ps3_htab_lock, flags);
0088 
0089     return ret;
0090 }
0091 
0092 static long ps3_hpte_remove(unsigned long hpte_group)
0093 {
0094     panic("ps3_hpte_remove() not implemented");
0095     return 0;
0096 }
0097 
0098 static long ps3_hpte_updatepp(unsigned long slot, unsigned long newpp,
0099                   unsigned long vpn, int psize, int apsize,
0100                   int ssize, unsigned long inv_flags)
0101 {
0102     int result;
0103     u64 hpte_v, want_v, hpte_rs;
0104     u64 hpte_v_array[4];
0105     unsigned long flags;
0106     long ret;
0107 
0108     want_v = hpte_encode_avpn(vpn, psize, ssize);
0109 
0110     spin_lock_irqsave(&ps3_htab_lock, flags);
0111 
0112     result = lv1_read_htab_entries(PS3_LPAR_VAS_ID_CURRENT, slot & ~0x3UL,
0113                        &hpte_v_array[0], &hpte_v_array[1],
0114                        &hpte_v_array[2], &hpte_v_array[3],
0115                        &hpte_rs);
0116 
0117     if (result) {
0118         pr_info("%s: result=%s read vpn=%lx slot=%lx psize=%d\n",
0119             __func__, ps3_result(result), vpn, slot, psize);
0120         BUG();
0121     }
0122 
0123     hpte_v = hpte_v_array[slot % 4];
0124 
0125     /*
0126      * As lv1_read_htab_entries() does not give us the RPN, we can
0127      * not synthesize the new hpte_r value here, and therefore can
0128      * not update the hpte with lv1_insert_htab_entry(), so we
0129      * instead invalidate it and ask the caller to update it via
0130      * ps3_hpte_insert() by returning a -1 value.
0131      */
0132     if (!HPTE_V_COMPARE(hpte_v, want_v) || !(hpte_v & HPTE_V_VALID)) {
0133         /* not found */
0134         ret = -1;
0135     } else {
0136         /* entry found, just invalidate it */
0137         result = lv1_write_htab_entry(PS3_LPAR_VAS_ID_CURRENT,
0138                           slot, 0, 0);
0139         ret = -1;
0140     }
0141 
0142     spin_unlock_irqrestore(&ps3_htab_lock, flags);
0143     return ret;
0144 }
0145 
0146 static void ps3_hpte_updateboltedpp(unsigned long newpp, unsigned long ea,
0147     int psize, int ssize)
0148 {
0149     panic("ps3_hpte_updateboltedpp() not implemented");
0150 }
0151 
0152 static void ps3_hpte_invalidate(unsigned long slot, unsigned long vpn,
0153                 int psize, int apsize, int ssize, int local)
0154 {
0155     unsigned long flags;
0156     int result;
0157 
0158     spin_lock_irqsave(&ps3_htab_lock, flags);
0159 
0160     result = lv1_write_htab_entry(PS3_LPAR_VAS_ID_CURRENT, slot, 0, 0);
0161 
0162     if (result) {
0163         pr_info("%s: result=%s vpn=%lx slot=%lx psize=%d\n",
0164             __func__, ps3_result(result), vpn, slot, psize);
0165         BUG();
0166     }
0167 
0168     spin_unlock_irqrestore(&ps3_htab_lock, flags);
0169 }
0170 
0171 /* Called during kexec sequence with MMU off */
0172 static notrace void ps3_hpte_clear(void)
0173 {
0174     unsigned long hpte_count = (1UL << ppc64_pft_size) >> 4;
0175     u64 i;
0176 
0177     for (i = 0; i < hpte_count; i++)
0178         lv1_write_htab_entry(PS3_LPAR_VAS_ID_CURRENT, i, 0, 0);
0179 
0180     ps3_mm_shutdown();
0181     ps3_mm_vas_destroy();
0182 }
0183 
0184 void __init ps3_hpte_init(unsigned long htab_size)
0185 {
0186     mmu_hash_ops.hpte_invalidate = ps3_hpte_invalidate;
0187     mmu_hash_ops.hpte_updatepp = ps3_hpte_updatepp;
0188     mmu_hash_ops.hpte_updateboltedpp = ps3_hpte_updateboltedpp;
0189     mmu_hash_ops.hpte_insert = ps3_hpte_insert;
0190     mmu_hash_ops.hpte_remove = ps3_hpte_remove;
0191     mmu_hash_ops.hpte_clear_all = ps3_hpte_clear;
0192 
0193     ppc64_pft_size = __ilog2(htab_size);
0194 }
0195