vtophys.cc revision 8232
12650Ssaidi@eecs.umich.edu/* 22650Ssaidi@eecs.umich.edu * Copyright (c) 2002-2005 The Regents of The University of Michigan 32650Ssaidi@eecs.umich.edu * All rights reserved. 42650Ssaidi@eecs.umich.edu * 52650Ssaidi@eecs.umich.edu * Redistribution and use in source and binary forms, with or without 62650Ssaidi@eecs.umich.edu * modification, are permitted provided that the following conditions are 72650Ssaidi@eecs.umich.edu * met: redistributions of source code must retain the above copyright 82650Ssaidi@eecs.umich.edu * notice, this list of conditions and the following disclaimer; 92650Ssaidi@eecs.umich.edu * redistributions in binary form must reproduce the above copyright 102650Ssaidi@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the 112650Ssaidi@eecs.umich.edu * documentation and/or other materials provided with the distribution; 122650Ssaidi@eecs.umich.edu * neither the name of the copyright holders nor the names of its 132650Ssaidi@eecs.umich.edu * contributors may be used to endorse or promote products derived from 142650Ssaidi@eecs.umich.edu * this software without specific prior written permission. 152650Ssaidi@eecs.umich.edu * 162650Ssaidi@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172650Ssaidi@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182650Ssaidi@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192650Ssaidi@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202650Ssaidi@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212650Ssaidi@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222650Ssaidi@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232650Ssaidi@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242650Ssaidi@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252650Ssaidi@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262650Ssaidi@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 284070Ssaidi@eecs.umich.edu * Authors: Ali Saidi 292650Ssaidi@eecs.umich.edu */ 302650Ssaidi@eecs.umich.edu 312650Ssaidi@eecs.umich.edu#include <string> 322650Ssaidi@eecs.umich.edu 338229Snate@binkert.org#include "arch/sparc/tlb.hh" 343529Sgblack@eecs.umich.edu#include "arch/sparc/vtophys.hh" 358229Snate@binkert.org#include "base/chunk_generator.hh" 364070Ssaidi@eecs.umich.edu#include "base/compiler.hh" 372650Ssaidi@eecs.umich.edu#include "base/trace.hh" 382680Sktlim@umich.edu#include "cpu/thread_context.hh" 398232Snate@binkert.org#include "debug/VtoPhys.hh" 402650Ssaidi@eecs.umich.edu#include "mem/vport.hh" 412650Ssaidi@eecs.umich.edu 422650Ssaidi@eecs.umich.eduusing namespace std; 432650Ssaidi@eecs.umich.edu 445560Snate@binkert.orgnamespace SparcISA { 455560Snate@binkert.org 465560Snate@binkert.orgAddr 475560Snate@binkert.orgvtophys(Addr vaddr) 482650Ssaidi@eecs.umich.edu{ 495560Snate@binkert.org // In SPARC it's almost always impossible to turn a VA->PA w/o a 505560Snate@binkert.org // context The only times we can kinda do it are if we have a 515560Snate@binkert.org // SegKPM mapping and can find the real address in the tlb or we 525560Snate@binkert.org // have a physical adddress already (beacuse we are looking at the 535560Snate@binkert.org // hypervisor) Either case is rare, so we'll just panic. 544070Ssaidi@eecs.umich.edu 555560Snate@binkert.org panic("vtophys() without context on SPARC largly worthless\n"); 565560Snate@binkert.org M5_DUMMY_RETURN; 575560Snate@binkert.org} 585560Snate@binkert.org 595560Snate@binkert.orgAddr 605560Snate@binkert.orgvtophys(ThreadContext *tc, Addr addr) 615560Snate@binkert.org{ 625560Snate@binkert.org // Here we have many options and are really implementing something like 635560Snate@binkert.org // a fill handler to find the address since there isn't a multilevel 645560Snate@binkert.org // table for us to walk around. 655560Snate@binkert.org // 665560Snate@binkert.org // 1. We are currently hyperpriv, return the address unmodified 675560Snate@binkert.org // 2. The mmu is off return(ra->pa) 685560Snate@binkert.org // 3. We are currently priv, use ctx0* tsbs to find the page 695560Snate@binkert.org // 4. We are not priv, use ctxN0* tsbs to find the page 705560Snate@binkert.org // For all accesses we check the tlbs first since it's possible that 715560Snate@binkert.org // long standing pages (e.g. locked kernel mappings) won't be in the tsb 725560Snate@binkert.org uint64_t tlbdata = tc->readMiscRegNoEffect(MISCREG_TLB_DATA); 735560Snate@binkert.org 745560Snate@binkert.org bool hpriv = bits(tlbdata,0,0); 757741Sgblack@eecs.umich.edu // bool priv = bits(tlbdata,2,2); 765560Snate@binkert.org bool addr_mask = bits(tlbdata,3,3); 775560Snate@binkert.org bool data_real = !bits(tlbdata,5,5); 785560Snate@binkert.org bool inst_real = !bits(tlbdata,4,4); 795560Snate@binkert.org bool ctx_zero = bits(tlbdata,18,16) > 0; 805560Snate@binkert.org int part_id = bits(tlbdata,15,8); 815560Snate@binkert.org int pri_context = bits(tlbdata,47,32); 827741Sgblack@eecs.umich.edu // int sec_context = bits(tlbdata,63,48); 835560Snate@binkert.org 845560Snate@binkert.org FunctionalPort *mem = tc->getPhysPort(); 856022Sgblack@eecs.umich.edu TLB* itb = tc->getITBPtr(); 866022Sgblack@eecs.umich.edu TLB* dtb = tc->getDTBPtr(); 875560Snate@binkert.org TlbEntry* tbe; 885560Snate@binkert.org PageTableEntry pte; 895560Snate@binkert.org Addr tsbs[4]; 905560Snate@binkert.org Addr va_tag; 915560Snate@binkert.org TteTag ttetag; 925560Snate@binkert.org 935560Snate@binkert.org if (hpriv) 945560Snate@binkert.org return addr; 955560Snate@binkert.org 965560Snate@binkert.org if (addr_mask) 975560Snate@binkert.org addr = addr & VAddrAMask; 985560Snate@binkert.org 995560Snate@binkert.org tbe = dtb->lookup(addr, part_id, data_real, ctx_zero ? 0 : pri_context , 1005560Snate@binkert.org false); 1015560Snate@binkert.org if (tbe) 1025560Snate@binkert.org goto foundtbe; 1035560Snate@binkert.org 1045560Snate@binkert.org tbe = itb->lookup(addr, part_id, inst_real, ctx_zero ? 0 : pri_context, 1055560Snate@binkert.org false); 1065560Snate@binkert.org if (tbe) 1075560Snate@binkert.org goto foundtbe; 1085560Snate@binkert.org 1095560Snate@binkert.org // We didn't find it in the tlbs, so lets look at the TSBs 1105560Snate@binkert.org dtb->GetTsbPtr(tc, addr, ctx_zero ? 0 : pri_context, tsbs); 1115560Snate@binkert.org va_tag = bits(addr, 63, 22); 1125560Snate@binkert.org for (int x = 0; x < 4; x++) { 1135560Snate@binkert.org ttetag = betoh(mem->read<uint64_t>(tsbs[x])); 1145560Snate@binkert.org if (ttetag.valid() && ttetag.va() == va_tag) { 1155560Snate@binkert.org uint64_t entry = mem->read<uint64_t>(tsbs[x]) + sizeof(uint64_t); 1165560Snate@binkert.org // I think it's sun4v at least! 1175560Snate@binkert.org pte.populate(betoh(entry), PageTableEntry::sun4v); 1185560Snate@binkert.org DPRINTF(VtoPhys, "Virtual(%#x)->Physical(%#x) found in TTE\n", 1195560Snate@binkert.org addr, pte.translate(addr)); 1205560Snate@binkert.org goto foundpte; 1215560Snate@binkert.org } 1222650Ssaidi@eecs.umich.edu } 1235560Snate@binkert.org panic("couldn't translate %#x\n", addr); 1242650Ssaidi@eecs.umich.edu 1255560Snate@binkert.org foundtbe: 1265560Snate@binkert.org pte = tbe->pte; 1275560Snate@binkert.org DPRINTF(VtoPhys, "Virtual(%#x)->Physical(%#x) found in TLB\n", addr, 1285560Snate@binkert.org pte.translate(addr)); 1295560Snate@binkert.org foundpte: 1305560Snate@binkert.org return pte.translate(addr); 1315560Snate@binkert.org} 1322650Ssaidi@eecs.umich.edu 1337811Ssteve.reinhardt@amd.com} // namespace SparcISA 134