vtophys.cc revision 10037
16019Shines@cs.fsu.edu/*
210037SARM gem5 Developers * Copyright (c) 2010, 2012-2013 ARM Limited
37694SAli.Saidi@ARM.com * All rights reserved
47694SAli.Saidi@ARM.com *
57694SAli.Saidi@ARM.com * The license below extends only to copyright in the software and shall
67694SAli.Saidi@ARM.com * not be construed as granting a license to any other intellectual
77694SAli.Saidi@ARM.com * property including but not limited to intellectual property relating
87694SAli.Saidi@ARM.com * to a hardware implementation of the functionality of the software
97694SAli.Saidi@ARM.com * licensed hereunder.  You may use the software subject to the license
107694SAli.Saidi@ARM.com * terms below provided that you ensure that this notice is replicated
117694SAli.Saidi@ARM.com * unmodified and in its entirety in all distributions of the software,
127694SAli.Saidi@ARM.com * modified or unmodified, in source code or in binary form.
137694SAli.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.
406019Shines@cs.fsu.edu *
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
4810037SARM gem5 Developers#include "arch/arm/faults.hh"
497694SAli.Saidi@ARM.com#include "arch/arm/table_walker.hh"
507694SAli.Saidi@ARM.com#include "arch/arm/tlb.hh"
516019Shines@cs.fsu.edu#include "arch/arm/vtophys.hh"
526019Shines@cs.fsu.edu#include "base/chunk_generator.hh"
536019Shines@cs.fsu.edu#include "base/trace.hh"
546019Shines@cs.fsu.edu#include "cpu/thread_context.hh"
558706Sandreas.hansson@arm.com#include "mem/fs_translating_port_proxy.hh"
566019Shines@cs.fsu.edu
576019Shines@cs.fsu.eduusing namespace std;
586019Shines@cs.fsu.eduusing namespace ArmISA;
596019Shines@cs.fsu.edu
606019Shines@cs.fsu.eduAddr
616019Shines@cs.fsu.eduArmISA::vtophys(Addr vaddr)
626019Shines@cs.fsu.edu{
637694SAli.Saidi@ARM.com    fatal("VTOPHYS: Can't convert vaddr to paddr on ARM without a thread context");
646019Shines@cs.fsu.edu}
656019Shines@cs.fsu.edu
666019Shines@cs.fsu.eduAddr
676019Shines@cs.fsu.eduArmISA::vtophys(ThreadContext *tc, Addr addr)
686019Shines@cs.fsu.edu{
6910037SARM gem5 Developers    Fault fault;
7010037SARM gem5 Developers    // Set up a functional memory Request to pass to the TLB
7110037SARM gem5 Developers    // to get it to translate the vaddr to a paddr
7210037SARM gem5 Developers    Request req(0, addr, 64, 0x40, -1, 0, 0, 0);
737694SAli.Saidi@ARM.com    ArmISA::TLB *tlb;
747694SAli.Saidi@ARM.com
7510037SARM gem5 Developers    // Check the TLBs for a translation
7610037SARM gem5 Developers    // It's possible that there is a valid translation in the tlb
777694SAli.Saidi@ARM.com    // that is no loger valid in the page table in memory
787694SAli.Saidi@ARM.com    // so we need to check here first
7910037SARM gem5 Developers    //
8010037SARM gem5 Developers    // Calling translateFunctional invokes a table-walk if required
8110037SARM gem5 Developers    // so we should always succeed
827694SAli.Saidi@ARM.com    tlb = static_cast<ArmISA::TLB*>(tc->getDTBPtr());
8310037SARM gem5 Developers    fault = tlb->translateFunctional(&req, tc, BaseTLB::Read, TLB::NormalTran);
8410037SARM gem5 Developers    if (fault == NoFault)
8510037SARM gem5 Developers        return req.getPaddr();
867694SAli.Saidi@ARM.com
877694SAli.Saidi@ARM.com    tlb = static_cast<ArmISA::TLB*>(tc->getITBPtr());
8810037SARM gem5 Developers    fault = tlb->translateFunctional(&req, tc, BaseTLB::Read, TLB::NormalTran);
8910037SARM gem5 Developers    if (fault == NoFault)
9010037SARM gem5 Developers        return req.getPaddr();
917694SAli.Saidi@ARM.com
9210037SARM gem5 Developers    panic("Table walkers support functional accesses. We should never get here\n");
936019Shines@cs.fsu.edu}
946019Shines@cs.fsu.edu
957694SAli.Saidi@ARM.combool
967694SAli.Saidi@ARM.comArmISA::virtvalid(ThreadContext *tc, Addr vaddr)
977694SAli.Saidi@ARM.com{
987694SAli.Saidi@ARM.com    if (vtophys(tc, vaddr) != -1)
997694SAli.Saidi@ARM.com        return true;
1007694SAli.Saidi@ARM.com    return false;
1017694SAli.Saidi@ARM.com}
1027694SAli.Saidi@ARM.com
1037694SAli.Saidi@ARM.com
104