vtophys.cc revision 12749:223c83ed9979
111988Sandreas.sandberg@arm.com/* 28840Sandreas.hansson@arm.com * Copyright (c) 2010, 2012-2013 ARM Limited 38840Sandreas.hansson@arm.com * All rights reserved 48840Sandreas.hansson@arm.com * 58840Sandreas.hansson@arm.com * The license below extends only to copyright in the software and shall 68840Sandreas.hansson@arm.com * not be construed as granting a license to any other intellectual 78840Sandreas.hansson@arm.com * property including but not limited to intellectual property relating 88840Sandreas.hansson@arm.com * to a hardware implementation of the functionality of the software 98840Sandreas.hansson@arm.com * licensed hereunder. You may use the software subject to the license 108840Sandreas.hansson@arm.com * terms below provided that you ensure that this notice is replicated 118840Sandreas.hansson@arm.com * unmodified and in its entirety in all distributions of the software, 128840Sandreas.hansson@arm.com * modified or unmodified, in source code or in binary form. 132740SN/A * 149983Sstever@gmail.com * Copyright (c) 2002-2005 The Regents of The University of Michigan 159983Sstever@gmail.com * Copyright (c) 2007-2008 The Florida State University 161046SN/A * All rights reserved. 171046SN/A * 181046SN/A * Redistribution and use in source and binary forms, with or without 191046SN/A * modification, are permitted provided that the following conditions are 201046SN/A * met: redistributions of source code must retain the above copyright 211046SN/A * notice, this list of conditions and the following disclaimer; 221046SN/A * redistributions in binary form must reproduce the above copyright 231046SN/A * notice, this list of conditions and the following disclaimer in the 241046SN/A * documentation and/or other materials provided with the distribution; 251046SN/A * neither the name of the copyright holders nor the names of its 261046SN/A * contributors may be used to endorse or promote products derived from 271046SN/A * this software without specific prior written permission. 281046SN/A * 291046SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 301046SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 311046SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 321046SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 331046SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 341046SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 351046SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 361046SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 371046SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 381046SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 391046SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 402665SN/A * 412665SN/A * Authors: Ali Saidi 422665SN/A * Nathan Binkert 438840Sandreas.hansson@arm.com * Stephen Hines 4411988Sandreas.sandberg@arm.com */ 451046SN/A 465766Snate@binkert.org#include "arch/arm/vtophys.hh" 478331Ssteve.reinhardt@amd.com 4811988Sandreas.sandberg@arm.com#include <string> 4911988Sandreas.sandberg@arm.com 501438SN/A#include "arch/arm/faults.hh" 514762Snate@binkert.org#include "arch/arm/table_walker.hh" 526654Snate@binkert.org#include "arch/arm/tlb.hh" 5311988Sandreas.sandberg@arm.com#include "base/chunk_generator.hh" 543102Sstever@eecs.umich.edu#include "base/trace.hh" 553102Sstever@eecs.umich.edu#include "cpu/thread_context.hh" 563102Sstever@eecs.umich.edu#include "mem/fs_translating_port_proxy.hh" 573102Sstever@eecs.umich.edu 586654Snate@binkert.orgusing namespace std; 593102Sstever@eecs.umich.eduusing namespace ArmISA; 603102Sstever@eecs.umich.edu 617528Ssteve.reinhardt@amd.comAddr 628839Sandreas.hansson@arm.comArmISA::vtophys(Addr vaddr) 633102Sstever@eecs.umich.edu{ 646654Snate@binkert.org fatal("VTOPHYS: Can't convert vaddr to paddr on ARM without a thread context"); 656654Snate@binkert.org} 66679SN/A 67679SN/Astatic std::pair<bool, Addr> 68679SN/Atry_translate(ThreadContext *tc, Addr addr) 69679SN/A{ 70679SN/A Fault fault; 71679SN/A // Set up a functional memory Request to pass to the TLB 721692SN/A // to get it to translate the vaddr to a paddr 73679SN/A auto req = std::make_shared<Request>(0, addr, 64, 0x40, -1, 0, 0); 74679SN/A ArmISA::TLB *tlb; 75679SN/A 76679SN/A // Check the TLBs for a translation 77679SN/A // It's possible that there is a valid translation in the tlb 78679SN/A // that is no loger valid in the page table in memory 79679SN/A // so we need to check here first 80679SN/A // 81679SN/A // Calling translateFunctional invokes a table-walk if required 82679SN/A // so we should always succeed 83679SN/A tlb = static_cast<ArmISA::TLB*>(tc->getDTBPtr()); 84679SN/A fault = tlb->translateFunctional(req, tc, BaseTLB::Read, TLB::NormalTran); 85679SN/A if (fault == NoFault) 86679SN/A return std::make_pair(true, req->getPaddr()); 871692SN/A 88679SN/A tlb = static_cast<ArmISA::TLB*>(tc->getITBPtr()); 89679SN/A fault = tlb->translateFunctional(req, tc, BaseTLB::Read, TLB::NormalTran); 90679SN/A if (fault == NoFault) 91679SN/A return std::make_pair(true, req->getPaddr()); 92679SN/A 93679SN/A return std::make_pair(false, 0); 94679SN/A} 95679SN/A 96679SN/AAddr 97679SN/AArmISA::vtophys(ThreadContext *tc, Addr addr) 98679SN/A{ 99679SN/A const std::pair<bool, Addr> translation(try_translate(tc, addr)); 100679SN/A 101679SN/A if (translation.first) 102679SN/A return translation.second; 1032740SN/A else 104679SN/A panic("Table walkers support functional accesses. We should never get here\n"); 105679SN/A} 106679SN/A 1074762Snate@binkert.orgbool 1084762Snate@binkert.orgArmISA::virtvalid(ThreadContext *tc, Addr vaddr) 1094762Snate@binkert.org{ 1102738SN/A const std::pair<bool, Addr> translation(try_translate(tc, vaddr)); 1112738SN/A 1122738SN/A return translation.first; 1139338SAndreas.Sandberg@arm.com} 1149338SAndreas.Sandberg@arm.com 1159338SAndreas.Sandberg@arm.com 1167673Snate@binkert.org