Path: blob/master/arch/powerpc/platforms/ps3/htab.c
10818 views
/*1* PS3 pagetable management routines.2*3* Copyright (C) 2006 Sony Computer Entertainment Inc.4* Copyright 2006, 2007 Sony Corporation5*6* This program is free software; you can redistribute it and/or modify7* it under the terms of the GNU General Public License as published by8* the Free Software Foundation; version 2 of the License.9*10* This program is distributed in the hope that it will be useful,11* but WITHOUT ANY WARRANTY; without even the implied warranty of12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13* GNU General Public License for more details.14*15* You should have received a copy of the GNU General Public License16* along with this program; if not, write to the Free Software17* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA18*/1920#include <linux/kernel.h>21#include <linux/memblock.h>2223#include <asm/machdep.h>24#include <asm/prom.h>25#include <asm/udbg.h>26#include <asm/lv1call.h>27#include <asm/ps3fb.h>2829#include "platform.h"3031/**32* enum lpar_vas_id - id of LPAR virtual address space.33* @lpar_vas_id_current: Current selected virtual address space34*35* Identify the target LPAR address space.36*/3738enum ps3_lpar_vas_id {39PS3_LPAR_VAS_ID_CURRENT = 0,40};414243static DEFINE_SPINLOCK(ps3_htab_lock);4445static long ps3_hpte_insert(unsigned long hpte_group, unsigned long va,46unsigned long pa, unsigned long rflags, unsigned long vflags,47int psize, int ssize)48{49int result;50u64 hpte_v, hpte_r;51u64 inserted_index;52u64 evicted_v, evicted_r;53u64 hpte_v_array[4], hpte_rs;54unsigned long flags;55long ret = -1;5657/*58* lv1_insert_htab_entry() will search for victim59* entry in both primary and secondary pte group60*/61vflags &= ~HPTE_V_SECONDARY;6263hpte_v = hpte_encode_v(va, psize, ssize) | vflags | HPTE_V_VALID;64hpte_r = hpte_encode_r(ps3_mm_phys_to_lpar(pa), psize) | rflags;6566spin_lock_irqsave(&ps3_htab_lock, flags);6768/* talk hvc to replace entries BOLTED == 0 */69result = lv1_insert_htab_entry(PS3_LPAR_VAS_ID_CURRENT, hpte_group,70hpte_v, hpte_r,71HPTE_V_BOLTED, 0,72&inserted_index,73&evicted_v, &evicted_r);7475if (result) {76/* all entries bolted !*/77pr_info("%s:result=%d va=%lx pa=%lx ix=%lx v=%llx r=%llx\n",78__func__, result, va, pa, hpte_group, hpte_v, hpte_r);79BUG();80}8182/*83* see if the entry is inserted into secondary pteg84*/85result = lv1_read_htab_entries(PS3_LPAR_VAS_ID_CURRENT,86inserted_index & ~0x3UL,87&hpte_v_array[0], &hpte_v_array[1],88&hpte_v_array[2], &hpte_v_array[3],89&hpte_rs);90BUG_ON(result);9192if (hpte_v_array[inserted_index % 4] & HPTE_V_SECONDARY)93ret = (inserted_index & 7) | (1 << 3);94else95ret = inserted_index & 7;9697spin_unlock_irqrestore(&ps3_htab_lock, flags);9899return ret;100}101102static long ps3_hpte_remove(unsigned long hpte_group)103{104panic("ps3_hpte_remove() not implemented");105return 0;106}107108static long ps3_hpte_updatepp(unsigned long slot, unsigned long newpp,109unsigned long va, int psize, int ssize, int local)110{111int result;112u64 hpte_v, want_v, hpte_rs;113u64 hpte_v_array[4];114unsigned long flags;115long ret;116117want_v = hpte_encode_v(va, psize, ssize);118119spin_lock_irqsave(&ps3_htab_lock, flags);120121result = lv1_read_htab_entries(PS3_LPAR_VAS_ID_CURRENT, slot & ~0x3UL,122&hpte_v_array[0], &hpte_v_array[1],123&hpte_v_array[2], &hpte_v_array[3],124&hpte_rs);125126if (result) {127pr_info("%s: res=%d read va=%lx slot=%lx psize=%d\n",128__func__, result, va, slot, psize);129BUG();130}131132hpte_v = hpte_v_array[slot % 4];133134/*135* As lv1_read_htab_entries() does not give us the RPN, we can136* not synthesize the new hpte_r value here, and therefore can137* not update the hpte with lv1_insert_htab_entry(), so we138* instead invalidate it and ask the caller to update it via139* ps3_hpte_insert() by returning a -1 value.140*/141if (!HPTE_V_COMPARE(hpte_v, want_v) || !(hpte_v & HPTE_V_VALID)) {142/* not found */143ret = -1;144} else {145/* entry found, just invalidate it */146result = lv1_write_htab_entry(PS3_LPAR_VAS_ID_CURRENT,147slot, 0, 0);148ret = -1;149}150151spin_unlock_irqrestore(&ps3_htab_lock, flags);152return ret;153}154155static void ps3_hpte_updateboltedpp(unsigned long newpp, unsigned long ea,156int psize, int ssize)157{158panic("ps3_hpte_updateboltedpp() not implemented");159}160161static void ps3_hpte_invalidate(unsigned long slot, unsigned long va,162int psize, int ssize, int local)163{164unsigned long flags;165int result;166167spin_lock_irqsave(&ps3_htab_lock, flags);168169result = lv1_write_htab_entry(PS3_LPAR_VAS_ID_CURRENT, slot, 0, 0);170171if (result) {172pr_info("%s: res=%d va=%lx slot=%lx psize=%d\n",173__func__, result, va, slot, psize);174BUG();175}176177spin_unlock_irqrestore(&ps3_htab_lock, flags);178}179180static void ps3_hpte_clear(void)181{182unsigned long hpte_count = (1UL << ppc64_pft_size) >> 4;183u64 i;184185for (i = 0; i < hpte_count; i++)186lv1_write_htab_entry(PS3_LPAR_VAS_ID_CURRENT, i, 0, 0);187188ps3_mm_shutdown();189ps3_mm_vas_destroy();190}191192void __init ps3_hpte_init(unsigned long htab_size)193{194ppc_md.hpte_invalidate = ps3_hpte_invalidate;195ppc_md.hpte_updatepp = ps3_hpte_updatepp;196ppc_md.hpte_updateboltedpp = ps3_hpte_updateboltedpp;197ppc_md.hpte_insert = ps3_hpte_insert;198ppc_md.hpte_remove = ps3_hpte_remove;199ppc_md.hpte_clear_all = ps3_hpte_clear;200201ppc64_pft_size = __ilog2(htab_size);202}203204205206