vtophys.cc revision 7694
16019Shines@cs.fsu.edu/* 27399SAli.Saidi@ARM.com * Copyright (c) 2010 ARM Limited 37399SAli.Saidi@ARM.com * All rights reserved 47399SAli.Saidi@ARM.com * 57399SAli.Saidi@ARM.com * The license below extends only to copyright in the software and shall 67399SAli.Saidi@ARM.com * not be construed as granting a license to any other intellectual 77399SAli.Saidi@ARM.com * property including but not limited to intellectual property relating 87399SAli.Saidi@ARM.com * to a hardware implementation of the functionality of the software 97399SAli.Saidi@ARM.com * licensed hereunder. You may use the software subject to the license 107399SAli.Saidi@ARM.com * terms below provided that you ensure that this notice is replicated 117399SAli.Saidi@ARM.com * unmodified and in its entirety in all distributions of the software, 127399SAli.Saidi@ARM.com * modified or unmodified, in source code or in binary form. 137399SAli.Saidi@ARM.com * 146019Shines@cs.fsu.edu * Copyright (c) 2002-2005 The Regents of The University of Michigan 156019Shines@cs.fsu.edu * Copyright (c) 2007-2008 The Florida State University 166019Shines@cs.fsu.edu * All rights reserved. 176019Shines@cs.fsu.edu * 186019Shines@cs.fsu.edu * Redistribution and use in source and binary forms, with or without 196019Shines@cs.fsu.edu * modification, are permitted provided that the following conditions are 206019Shines@cs.fsu.edu * met: redistributions of source code must retain the above copyright 216019Shines@cs.fsu.edu * notice, this list of conditions and the following disclaimer; 226019Shines@cs.fsu.edu * redistributions in binary form must reproduce the above copyright 236019Shines@cs.fsu.edu * notice, this list of conditions and the following disclaimer in the 246019Shines@cs.fsu.edu * documentation and/or other materials provided with the distribution; 256019Shines@cs.fsu.edu * neither the name of the copyright holders nor the names of its 266019Shines@cs.fsu.edu * contributors may be used to endorse or promote products derived from 276019Shines@cs.fsu.edu * this software without specific prior written permission. 286019Shines@cs.fsu.edu * 296019Shines@cs.fsu.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 306019Shines@cs.fsu.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 316019Shines@cs.fsu.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 326019Shines@cs.fsu.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 336019Shines@cs.fsu.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 346019Shines@cs.fsu.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 356019Shines@cs.fsu.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 366019Shines@cs.fsu.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 376019Shines@cs.fsu.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 386019Shines@cs.fsu.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 396019Shines@cs.fsu.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 407399SAli.Saidi@ARM.com * 416019Shines@cs.fsu.edu * Authors: Ali Saidi 426019Shines@cs.fsu.edu * Nathan Binkert 436019Shines@cs.fsu.edu * Stephen Hines 446019Shines@cs.fsu.edu */ 456019Shines@cs.fsu.edu 466019Shines@cs.fsu.edu#include <string> 476019Shines@cs.fsu.edu 486019Shines@cs.fsu.edu#include "arch/arm/table_walker.hh" 496019Shines@cs.fsu.edu#include "arch/arm/tlb.hh" 506019Shines@cs.fsu.edu#include "arch/arm/vtophys.hh" 516019Shines@cs.fsu.edu#include "base/chunk_generator.hh" 526019Shines@cs.fsu.edu#include "base/trace.hh" 536019Shines@cs.fsu.edu#include "cpu/thread_context.hh" 546116Snate@binkert.org#include "mem/vport.hh" 557678Sgblack@eecs.umich.edu 566019Shines@cs.fsu.eduusing namespace std; 576019Shines@cs.fsu.eduusing namespace ArmISA; 586019Shines@cs.fsu.edu 596019Shines@cs.fsu.eduAddr 606019Shines@cs.fsu.eduArmISA::vtophys(Addr vaddr) 616019Shines@cs.fsu.edu{ 627404SAli.Saidi@ARM.com fatal("VTOPHYS: Can't convert vaddr to paddr on ARM without a thread context"); 637404SAli.Saidi@ARM.com} 646019Shines@cs.fsu.edu 656019Shines@cs.fsu.eduAddr 667294Sgblack@eecs.umich.eduArmISA::vtophys(ThreadContext *tc, Addr addr) 677294Sgblack@eecs.umich.edu{ 687639Sgblack@eecs.umich.edu SCTLR sctlr = tc->readMiscReg(MISCREG_SCTLR); 697294Sgblack@eecs.umich.edu if (!sctlr.m) { 707294Sgblack@eecs.umich.edu // Translation is currently disabled PA == VA 717294Sgblack@eecs.umich.edu return addr; 727294Sgblack@eecs.umich.edu } 737294Sgblack@eecs.umich.edu bool success; 747639Sgblack@eecs.umich.edu Addr pa; 757639Sgblack@eecs.umich.edu ArmISA::TLB *tlb; 767294Sgblack@eecs.umich.edu 777639Sgblack@eecs.umich.edu // Check the TLBs far a translation 787404SAli.Saidi@ARM.com // It's possible that there is a validy translation in the tlb 797639Sgblack@eecs.umich.edu // that is no loger valid in the page table in memory 807294Sgblack@eecs.umich.edu // so we need to check here first 817294Sgblack@eecs.umich.edu tlb = static_cast<ArmISA::TLB*>(tc->getDTBPtr()); 827294Sgblack@eecs.umich.edu success = tlb->translateFunctional(tc, addr, pa); 837639Sgblack@eecs.umich.edu if (success) 847294Sgblack@eecs.umich.edu return pa; 856019Shines@cs.fsu.edu 866019Shines@cs.fsu.edu tlb = static_cast<ArmISA::TLB*>(tc->getITBPtr()); 877404SAli.Saidi@ARM.com success = tlb->translateFunctional(tc, addr, pa); 886019Shines@cs.fsu.edu if (success) 897406SAli.Saidi@ARM.com return pa; 907436Sdam.sunwoo@arm.com 917436Sdam.sunwoo@arm.com // We've failed everything, so we need to do a 927406SAli.Saidi@ARM.com // hardware tlb walk without messing with any 937404SAli.Saidi@ARM.com // state 947406SAli.Saidi@ARM.com 956019Shines@cs.fsu.edu uint32_t N = tc->readMiscReg(MISCREG_TTBCR); 967694SAli.Saidi@ARM.com Addr ttbr; 977694SAli.Saidi@ARM.com if (N == 0 || !mbits(addr, 31, 32-N)) { 987694SAli.Saidi@ARM.com ttbr = tc->readMiscReg(MISCREG_TTBR0); 997694SAli.Saidi@ARM.com } else { 1007694SAli.Saidi@ARM.com ttbr = tc->readMiscReg(MISCREG_TTBR1); 1017694SAli.Saidi@ARM.com N = 0; 1027694SAli.Saidi@ARM.com } 1036019Shines@cs.fsu.edu 1047399SAli.Saidi@ARM.com FunctionalPort *port = tc->getPhysPort(); 1057734SAli.Saidi@ARM.com Addr l1desc_addr = mbits(ttbr, 31, 14-N) | (bits(addr,31-N,20) << 2); 1067734SAli.Saidi@ARM.com 1077734SAli.Saidi@ARM.com TableWalker::L1Descriptor l1desc; 1087734SAli.Saidi@ARM.com l1desc.data = port->read<uint32_t>(l1desc_addr); 1097734SAli.Saidi@ARM.com if (l1desc.type() == TableWalker::L1Descriptor::Ignore || 1107734SAli.Saidi@ARM.com l1desc.type() == TableWalker::L1Descriptor::Reserved) { 1117734SAli.Saidi@ARM.com warn("Unable to translate virtual address: %#x\n", addr); 1127734SAli.Saidi@ARM.com return -1; 1137734SAli.Saidi@ARM.com } 1147734SAli.Saidi@ARM.com if (l1desc.type() == TableWalker::L1Descriptor::Section) 1157734SAli.Saidi@ARM.com return l1desc.paddr(addr); 1167734SAli.Saidi@ARM.com 1177734SAli.Saidi@ARM.com // Didn't find it at the first level, try againt 1187734SAli.Saidi@ARM.com Addr l2desc_addr = l1desc.l2Addr() | (bits(addr, 19, 12) << 2); 1197734SAli.Saidi@ARM.com TableWalker::L2Descriptor l2desc; 1207734SAli.Saidi@ARM.com l2desc.data = port->read<uint32_t>(l2desc_addr); 1217734SAli.Saidi@ARM.com 1227734SAli.Saidi@ARM.com if (l2desc.invalid()) { 1237734SAli.Saidi@ARM.com warn("Unable to translate virtual address: %#x\n", addr); 1247734SAli.Saidi@ARM.com return -1; 1256019Shines@cs.fsu.edu } 1266019Shines@cs.fsu.edu 1276019Shines@cs.fsu.edu return l2desc.paddr(addr); 1286019Shines@cs.fsu.edu} 1297697SAli.Saidi@ARM.com 1307404SAli.Saidi@ARM.combool 1316019Shines@cs.fsu.eduArmISA::virtvalid(ThreadContext *tc, Addr vaddr) 1326019Shines@cs.fsu.edu{ 1336019Shines@cs.fsu.edu if (vtophys(tc, vaddr) != -1) 1346019Shines@cs.fsu.edu return true; 1356019Shines@cs.fsu.edu return false; 1366019Shines@cs.fsu.edu} 1376019Shines@cs.fsu.edu 1387404SAli.Saidi@ARM.com 1397404SAli.Saidi@ARM.com