tlb.hh revision 12749
16019Shines@cs.fsu.edu/*
211577SDylan.Johnson@ARM.com * Copyright (c) 2010-2013, 2016 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) 2001-2005 The Regents of The University of Michigan
156019Shines@cs.fsu.edu * All rights reserved.
166019Shines@cs.fsu.edu *
176019Shines@cs.fsu.edu * Redistribution and use in source and binary forms, with or without
186019Shines@cs.fsu.edu * modification, are permitted provided that the following conditions are
196019Shines@cs.fsu.edu * met: redistributions of source code must retain the above copyright
206019Shines@cs.fsu.edu * notice, this list of conditions and the following disclaimer;
216019Shines@cs.fsu.edu * redistributions in binary form must reproduce the above copyright
226019Shines@cs.fsu.edu * notice, this list of conditions and the following disclaimer in the
236019Shines@cs.fsu.edu * documentation and/or other materials provided with the distribution;
246019Shines@cs.fsu.edu * neither the name of the copyright holders nor the names of its
256019Shines@cs.fsu.edu * contributors may be used to endorse or promote products derived from
266019Shines@cs.fsu.edu * this software without specific prior written permission.
276019Shines@cs.fsu.edu *
286019Shines@cs.fsu.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
296019Shines@cs.fsu.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
306019Shines@cs.fsu.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
316019Shines@cs.fsu.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
326019Shines@cs.fsu.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
336019Shines@cs.fsu.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
346019Shines@cs.fsu.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
356019Shines@cs.fsu.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
366019Shines@cs.fsu.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
376019Shines@cs.fsu.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
386019Shines@cs.fsu.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
396019Shines@cs.fsu.edu *
407399SAli.Saidi@ARM.com * Authors: Ali Saidi
416019Shines@cs.fsu.edu */
426019Shines@cs.fsu.edu
436019Shines@cs.fsu.edu#ifndef __ARCH_ARM_TLB_HH__
446019Shines@cs.fsu.edu#define __ARCH_ARM_TLB_HH__
456019Shines@cs.fsu.edu
466019Shines@cs.fsu.edu
476019Shines@cs.fsu.edu#include "arch/arm/isa_traits.hh"
488229Snate@binkert.org#include "arch/arm/pagetable.hh"
496019Shines@cs.fsu.edu#include "arch/arm/utility.hh"
506019Shines@cs.fsu.edu#include "arch/arm/vtophys.hh"
5110687SAndreas.Sandberg@ARM.com#include "arch/generic/tlb.hh"
526019Shines@cs.fsu.edu#include "base/statistics.hh"
536019Shines@cs.fsu.edu#include "mem/request.hh"
546116Snate@binkert.org#include "params/ArmTLB.hh"
5510463SAndreas.Sandberg@ARM.com#include "sim/probe/pmu.hh"
566019Shines@cs.fsu.edu
576019Shines@cs.fsu.educlass ThreadContext;
586019Shines@cs.fsu.edu
596019Shines@cs.fsu.edunamespace ArmISA {
606019Shines@cs.fsu.edu
617404SAli.Saidi@ARM.comclass TableWalker;
6210037SARM gem5 Developersclass Stage2LookUp;
6310037SARM gem5 Developersclass Stage2MMU;
6411395Sandreas.sandberg@arm.comclass TLB;
6511395Sandreas.sandberg@arm.com
6611395Sandreas.sandberg@arm.comclass TlbTestInterface
6711395Sandreas.sandberg@arm.com{
6811395Sandreas.sandberg@arm.com  public:
6911395Sandreas.sandberg@arm.com    TlbTestInterface() {}
7011395Sandreas.sandberg@arm.com    virtual ~TlbTestInterface() {}
7111395Sandreas.sandberg@arm.com
7211395Sandreas.sandberg@arm.com    /**
7311395Sandreas.sandberg@arm.com     * Check if a TLB translation should be forced to fail.
7411395Sandreas.sandberg@arm.com     *
7511395Sandreas.sandberg@arm.com     * @param req Request requiring a translation.
7611395Sandreas.sandberg@arm.com     * @param is_priv Access from a privileged mode (i.e., not EL0)
7711395Sandreas.sandberg@arm.com     * @param mode Access type
7811395Sandreas.sandberg@arm.com     * @param domain Domain type
7911395Sandreas.sandberg@arm.com     */
8012749Sgiacomo.travaglini@arm.com    virtual Fault translationCheck(const RequestPtr &req, bool is_priv,
8111395Sandreas.sandberg@arm.com                                   BaseTLB::Mode mode,
8211395Sandreas.sandberg@arm.com                                   TlbEntry::DomainType domain) = 0;
8311395Sandreas.sandberg@arm.com
8411395Sandreas.sandberg@arm.com    /**
8511395Sandreas.sandberg@arm.com     * Check if a page table walker access should be forced to fail.
8611395Sandreas.sandberg@arm.com     *
8711395Sandreas.sandberg@arm.com     * @param pa Physical address the walker is accessing
8811395Sandreas.sandberg@arm.com     * @param size Walker access size
8911395Sandreas.sandberg@arm.com     * @param va Virtual address that initiated the walk
9011395Sandreas.sandberg@arm.com     * @param is_secure Access from secure state
9111395Sandreas.sandberg@arm.com     * @param is_priv Access from a privileged mode (i.e., not EL0)
9211395Sandreas.sandberg@arm.com     * @param mode Access type
9311395Sandreas.sandberg@arm.com     * @param domain Domain type
9411395Sandreas.sandberg@arm.com     * @param lookup_level Page table walker level
9511395Sandreas.sandberg@arm.com     */
9611395Sandreas.sandberg@arm.com    virtual Fault walkCheck(Addr pa, Addr size, Addr va, bool is_secure,
9711395Sandreas.sandberg@arm.com                            Addr is_priv, BaseTLB::Mode mode,
9811395Sandreas.sandberg@arm.com                            TlbEntry::DomainType domain,
9911395Sandreas.sandberg@arm.com                            LookupLevel lookup_level) = 0;
10011395Sandreas.sandberg@arm.com};
1017404SAli.Saidi@ARM.com
1026019Shines@cs.fsu.educlass TLB : public BaseTLB
1036019Shines@cs.fsu.edu{
1047294Sgblack@eecs.umich.edu  public:
1057294Sgblack@eecs.umich.edu    enum ArmFlags {
10610037SARM gem5 Developers        AlignmentMask = 0x7,
1077294Sgblack@eecs.umich.edu
1087294Sgblack@eecs.umich.edu        AlignByte = 0x0,
1097294Sgblack@eecs.umich.edu        AlignHalfWord = 0x1,
11010037SARM gem5 Developers        AlignWord = 0x2,
11110037SARM gem5 Developers        AlignDoubleWord = 0x3,
11210037SARM gem5 Developers        AlignQuadWord = 0x4,
11310037SARM gem5 Developers        AlignOctWord = 0x5,
1147294Sgblack@eecs.umich.edu
11510037SARM gem5 Developers        AllowUnaligned = 0x8,
1167404SAli.Saidi@ARM.com        // Priv code operating as if it wasn't
11710037SARM gem5 Developers        UserMode = 0x10,
1187294Sgblack@eecs.umich.edu        // Because zero otherwise looks like a valid setting and may be used
1197294Sgblack@eecs.umich.edu        // accidentally, this bit must be non-zero to show it was used on
1207294Sgblack@eecs.umich.edu        // purpose.
12110037SARM gem5 Developers        MustBeOne = 0x40
12210037SARM gem5 Developers    };
12310037SARM gem5 Developers
12410037SARM gem5 Developers    enum ArmTranslationType {
12510037SARM gem5 Developers        NormalTran = 0,
12610037SARM gem5 Developers        S1CTran = 0x1,
12710037SARM gem5 Developers        HypMode = 0x2,
12810037SARM gem5 Developers        // Secure code operating as if it wasn't (required by some Address
12910037SARM gem5 Developers        // Translate operations)
13011577SDylan.Johnson@ARM.com        S1S2NsTran = 0x4,
13111577SDylan.Johnson@ARM.com        // Address translation instructions (eg AT S1E0R_Xt) need to be handled
13211577SDylan.Johnson@ARM.com        // in special ways during translation because they could need to act
13311577SDylan.Johnson@ARM.com        // like a different EL than the current EL. The following flags are
13411577SDylan.Johnson@ARM.com        // for these instructions
13511577SDylan.Johnson@ARM.com        S1E0Tran = 0x8,
13611577SDylan.Johnson@ARM.com        S1E1Tran = 0x10,
13711577SDylan.Johnson@ARM.com        S1E2Tran = 0x20,
13811577SDylan.Johnson@ARM.com        S1E3Tran = 0x40,
13911577SDylan.Johnson@ARM.com        S12E0Tran = 0x80,
14011577SDylan.Johnson@ARM.com        S12E1Tran = 0x100
1417294Sgblack@eecs.umich.edu    };
14212735Sandreas.sandberg@arm.com
14312735Sandreas.sandberg@arm.com    /**
14412735Sandreas.sandberg@arm.com     * Determine the EL to use for the purpose of a translation given
14512735Sandreas.sandberg@arm.com     * a specific translation type. If the translation type doesn't
14612735Sandreas.sandberg@arm.com     * specify an EL, we use the current EL.
14712735Sandreas.sandberg@arm.com     */
14812735Sandreas.sandberg@arm.com    static ExceptionLevel tranTypeEL(CPSR cpsr, ArmTranslationType type);
14912735Sandreas.sandberg@arm.com
1506019Shines@cs.fsu.edu  protected:
15110037SARM gem5 Developers    TlbEntry* table;     // the Page Table
15210037SARM gem5 Developers    int size;            // TLB Size
15310037SARM gem5 Developers    bool isStage2;       // Indicates this TLB is part of the second stage MMU
15410037SARM gem5 Developers    bool stage2Req;      // Indicates whether a stage 2 lookup is also required
15510037SARM gem5 Developers    uint64_t _attr;      // Memory attributes for last accessed TLB entry
15610037SARM gem5 Developers    bool directToStage2; // Indicates whether all translation requests should
15710037SARM gem5 Developers                         // be routed directly to the stage 2 TLB
1587436Sdam.sunwoo@arm.com
1597404SAli.Saidi@ARM.com    TableWalker *tableWalker;
16010037SARM gem5 Developers    TLB *stage2Tlb;
16110037SARM gem5 Developers    Stage2MMU *stage2Mmu;
1626019Shines@cs.fsu.edu
16311395Sandreas.sandberg@arm.com    TlbTestInterface *test;
16411395Sandreas.sandberg@arm.com
1657399SAli.Saidi@ARM.com    // Access Stats
1667734SAli.Saidi@ARM.com    mutable Stats::Scalar instHits;
1677734SAli.Saidi@ARM.com    mutable Stats::Scalar instMisses;
1687734SAli.Saidi@ARM.com    mutable Stats::Scalar readHits;
1697734SAli.Saidi@ARM.com    mutable Stats::Scalar readMisses;
1707734SAli.Saidi@ARM.com    mutable Stats::Scalar writeHits;
1717734SAli.Saidi@ARM.com    mutable Stats::Scalar writeMisses;
1727734SAli.Saidi@ARM.com    mutable Stats::Scalar inserts;
1737734SAli.Saidi@ARM.com    mutable Stats::Scalar flushTlb;
1747734SAli.Saidi@ARM.com    mutable Stats::Scalar flushTlbMva;
1757734SAli.Saidi@ARM.com    mutable Stats::Scalar flushTlbMvaAsid;
1767734SAli.Saidi@ARM.com    mutable Stats::Scalar flushTlbAsid;
1777734SAli.Saidi@ARM.com    mutable Stats::Scalar flushedEntries;
1787734SAli.Saidi@ARM.com    mutable Stats::Scalar alignFaults;
1797734SAli.Saidi@ARM.com    mutable Stats::Scalar prefetchFaults;
1807734SAli.Saidi@ARM.com    mutable Stats::Scalar domainFaults;
1817734SAli.Saidi@ARM.com    mutable Stats::Scalar permsFaults;
1827734SAli.Saidi@ARM.com
1837734SAli.Saidi@ARM.com    Stats::Formula readAccesses;
1847734SAli.Saidi@ARM.com    Stats::Formula writeAccesses;
1857734SAli.Saidi@ARM.com    Stats::Formula instAccesses;
1866019Shines@cs.fsu.edu    Stats::Formula hits;
1876019Shines@cs.fsu.edu    Stats::Formula misses;
1886019Shines@cs.fsu.edu    Stats::Formula accesses;
1896019Shines@cs.fsu.edu
19010463SAndreas.Sandberg@ARM.com    /** PMU probe for TLB refills */
19110463SAndreas.Sandberg@ARM.com    ProbePoints::PMUUPtr ppRefills;
19210463SAndreas.Sandberg@ARM.com
1937697SAli.Saidi@ARM.com    int rangeMRU; //On lookup, only move entries ahead when outside rangeMRU
1947404SAli.Saidi@ARM.com
1956019Shines@cs.fsu.edu  public:
19610037SARM gem5 Developers    TLB(const ArmTLBParams *p);
19710037SARM gem5 Developers    TLB(const Params *p, int _size, TableWalker *_walker);
1986019Shines@cs.fsu.edu
1999535Smrinmoy.ghosh@arm.com    /** Lookup an entry in the TLB
2009535Smrinmoy.ghosh@arm.com     * @param vpn virtual address
2019535Smrinmoy.ghosh@arm.com     * @param asn context id/address space id to use
20210037SARM gem5 Developers     * @param vmid The virtual machine ID used for stage 2 translation
20310037SARM gem5 Developers     * @param secure if the lookup is secure
20410037SARM gem5 Developers     * @param hyp if the lookup is done from hyp mode
2059535Smrinmoy.ghosh@arm.com     * @param functional if the lookup should modify state
20610037SARM gem5 Developers     * @param ignore_asn if on lookup asn should be ignored
20710037SARM gem5 Developers     * @return pointer to TLB entry if it exists
2089535Smrinmoy.ghosh@arm.com     */
20910037SARM gem5 Developers    TlbEntry *lookup(Addr vpn, uint16_t asn, uint8_t vmid, bool hyp,
21010037SARM gem5 Developers                     bool secure, bool functional,
21110037SARM gem5 Developers                     bool ignore_asn, uint8_t target_el);
2129535Smrinmoy.ghosh@arm.com
2136019Shines@cs.fsu.edu    virtual ~TLB();
21410037SARM gem5 Developers
21511169Sandreas.hansson@arm.com    void takeOverFrom(BaseTLB *otlb) override;
21610194SGeoffrey.Blake@arm.com
21710037SARM gem5 Developers    /// setup all the back pointers
21811169Sandreas.hansson@arm.com    void init() override;
21910037SARM gem5 Developers
22011395Sandreas.sandberg@arm.com    void setTestInterface(SimObject *ti);
22111395Sandreas.sandberg@arm.com
22210717Sandreas.hansson@arm.com    TableWalker *getTableWalker() { return tableWalker; }
22310717Sandreas.hansson@arm.com
22410717Sandreas.hansson@arm.com    void setMMU(Stage2MMU *m, MasterID master_id);
22510037SARM gem5 Developers
2266019Shines@cs.fsu.edu    int getsize() const { return size; }
2276019Shines@cs.fsu.edu
2287404SAli.Saidi@ARM.com    void insert(Addr vaddr, TlbEntry &pte);
2297404SAli.Saidi@ARM.com
23012749Sgiacomo.travaglini@arm.com    Fault getTE(TlbEntry **te, const RequestPtr &req,
23112749Sgiacomo.travaglini@arm.com                ThreadContext *tc, Mode mode,
23210037SARM gem5 Developers                Translation *translation, bool timing, bool functional,
23310037SARM gem5 Developers                bool is_secure, ArmTranslationType tranType);
23410037SARM gem5 Developers
23512749Sgiacomo.travaglini@arm.com    Fault getResultTe(TlbEntry **te, const RequestPtr &req,
23612749Sgiacomo.travaglini@arm.com                      ThreadContext *tc, Mode mode,
23712749Sgiacomo.travaglini@arm.com                      Translation *translation, bool timing,
23810037SARM gem5 Developers                      bool functional, TlbEntry *mergeTe);
23910037SARM gem5 Developers
24012749Sgiacomo.travaglini@arm.com    Fault checkPermissions(TlbEntry *te, const RequestPtr &req, Mode mode);
24112749Sgiacomo.travaglini@arm.com    Fault checkPermissions64(TlbEntry *te, const RequestPtr &req, Mode mode,
24210037SARM gem5 Developers                             ThreadContext *tc);
24310037SARM gem5 Developers
24410037SARM gem5 Developers
24510037SARM gem5 Developers    /** Reset the entire TLB
24610037SARM gem5 Developers     * @param secure_lookup if the operation affects the secure world
24710037SARM gem5 Developers     */
24810037SARM gem5 Developers    void flushAllSecurity(bool secure_lookup, uint8_t target_el,
24910037SARM gem5 Developers                          bool ignore_el = false);
25010037SARM gem5 Developers
25110037SARM gem5 Developers    /** Remove all entries in the non secure world, depending on whether they
25210037SARM gem5 Developers     *  were allocated in hyp mode or not
25310037SARM gem5 Developers     * @param hyp if the opperation affects hyp mode
25410037SARM gem5 Developers     */
25510037SARM gem5 Developers    void flushAllNs(bool hyp, uint8_t target_el, bool ignore_el = false);
25610037SARM gem5 Developers
25710037SARM gem5 Developers
25810037SARM gem5 Developers    /** Reset the entire TLB. Used for CPU switching to prevent stale
25910037SARM gem5 Developers     * translations after multiple switches
26010037SARM gem5 Developers     */
26111169Sandreas.hansson@arm.com    void flushAll() override
26210037SARM gem5 Developers    {
26310037SARM gem5 Developers        flushAllSecurity(false, 0, true);
26410037SARM gem5 Developers        flushAllSecurity(true, 0, true);
26510037SARM gem5 Developers    }
2667404SAli.Saidi@ARM.com
2677404SAli.Saidi@ARM.com    /** Remove any entries that match both a va and asn
2687404SAli.Saidi@ARM.com     * @param mva virtual address to flush
2697404SAli.Saidi@ARM.com     * @param asn contextid/asn to flush on match
27010037SARM gem5 Developers     * @param secure_lookup if the operation affects the secure world
2717404SAli.Saidi@ARM.com     */
27210037SARM gem5 Developers    void flushMvaAsid(Addr mva, uint64_t asn, bool secure_lookup,
27310037SARM gem5 Developers                      uint8_t target_el);
2747404SAli.Saidi@ARM.com
2757404SAli.Saidi@ARM.com    /** Remove any entries that match the asn
2767404SAli.Saidi@ARM.com     * @param asn contextid/asn to flush on match
27710037SARM gem5 Developers     * @param secure_lookup if the operation affects the secure world
2787404SAli.Saidi@ARM.com     */
27910037SARM gem5 Developers    void flushAsid(uint64_t asn, bool secure_lookup, uint8_t target_el);
2807404SAli.Saidi@ARM.com
2817404SAli.Saidi@ARM.com    /** Remove all entries that match the va regardless of asn
2827404SAli.Saidi@ARM.com     * @param mva address to flush from cache
28310037SARM gem5 Developers     * @param secure_lookup if the operation affects the secure world
28410037SARM gem5 Developers     * @param hyp if the operation affects hyp mode
2857404SAli.Saidi@ARM.com     */
28610037SARM gem5 Developers    void flushMva(Addr mva, bool secure_lookup, bool hyp, uint8_t target_el);
2877404SAli.Saidi@ARM.com
28811584SDylan.Johnson@ARM.com    /**
28911584SDylan.Johnson@ARM.com     * Invalidate all entries in the stage 2 TLB that match the given ipa
29011584SDylan.Johnson@ARM.com     * and the current VMID
29111584SDylan.Johnson@ARM.com     * @param ipa the address to invalidate
29211584SDylan.Johnson@ARM.com     * @param secure_lookup if the operation affects the secure world
29311584SDylan.Johnson@ARM.com     * @param hyp if the operation affects hyp mode
29411584SDylan.Johnson@ARM.com     */
29511584SDylan.Johnson@ARM.com    void flushIpaVmid(Addr ipa, bool secure_lookup, bool hyp, uint8_t target_el);
29611584SDylan.Johnson@ARM.com
29712749Sgiacomo.travaglini@arm.com    Fault trickBoxCheck(const RequestPtr &req, Mode mode,
29812749Sgiacomo.travaglini@arm.com                        TlbEntry::DomainType domain);
29912749Sgiacomo.travaglini@arm.com
30012749Sgiacomo.travaglini@arm.com    Fault walkTrickBoxCheck(Addr pa, bool is_secure, Addr va, Addr sz,
30112749Sgiacomo.travaglini@arm.com                            bool is_exec, bool is_write,
30212749Sgiacomo.travaglini@arm.com                            TlbEntry::DomainType domain,
30312749Sgiacomo.travaglini@arm.com                            LookupLevel lookup_level);
30411584SDylan.Johnson@ARM.com
30510037SARM gem5 Developers    void printTlb() const;
3067404SAli.Saidi@ARM.com
30711169Sandreas.hansson@arm.com    void demapPage(Addr vaddr, uint64_t asn) override
3086019Shines@cs.fsu.edu    {
30910037SARM gem5 Developers        // needed for x86 only
31010037SARM gem5 Developers        panic("demapPage() is not implemented.\n");
3116019Shines@cs.fsu.edu    }
3126019Shines@cs.fsu.edu
3137694SAli.Saidi@ARM.com    /**
3147694SAli.Saidi@ARM.com     * Do a functional lookup on the TLB (for debugging)
3157694SAli.Saidi@ARM.com     * and don't modify any internal state
3167694SAli.Saidi@ARM.com     * @param tc thread context to get the context id from
3177694SAli.Saidi@ARM.com     * @param vaddr virtual address to translate
3187694SAli.Saidi@ARM.com     * @param pa returned physical address
3197694SAli.Saidi@ARM.com     * @return if the translation was successful
3207694SAli.Saidi@ARM.com     */
3217694SAli.Saidi@ARM.com    bool translateFunctional(ThreadContext *tc, Addr vaddr, Addr &paddr);
3227694SAli.Saidi@ARM.com
3238733Sgeoffrey.blake@arm.com    /**
3248733Sgeoffrey.blake@arm.com     * Do a functional lookup on the TLB (for checker cpu) that
3258733Sgeoffrey.blake@arm.com     * behaves like a normal lookup without modifying any page table state.
3268733Sgeoffrey.blake@arm.com     */
32712749Sgiacomo.travaglini@arm.com    Fault translateFunctional(const RequestPtr &req, ThreadContext *tc,
32812749Sgiacomo.travaglini@arm.com            Mode mode, ArmTranslationType tranType);
32912419Sgabeblack@google.com    Fault
33012749Sgiacomo.travaglini@arm.com    translateFunctional(const RequestPtr &req,
33112749Sgiacomo.travaglini@arm.com                        ThreadContext *tc, Mode mode) override
33212419Sgabeblack@google.com    {
33312419Sgabeblack@google.com        return translateFunctional(req, tc, mode, NormalTran);
33412419Sgabeblack@google.com    }
3358733Sgeoffrey.blake@arm.com
3367436Sdam.sunwoo@arm.com    /** Accessor functions for memory attributes for last accessed TLB entry
3377436Sdam.sunwoo@arm.com     */
3387436Sdam.sunwoo@arm.com    void
33910037SARM gem5 Developers    setAttr(uint64_t attr)
3407436Sdam.sunwoo@arm.com    {
3417436Sdam.sunwoo@arm.com        _attr = attr;
3427436Sdam.sunwoo@arm.com    }
34310037SARM gem5 Developers
34410037SARM gem5 Developers    uint64_t
3457436Sdam.sunwoo@arm.com    getAttr() const
3467436Sdam.sunwoo@arm.com    {
3477436Sdam.sunwoo@arm.com        return _attr;
3487436Sdam.sunwoo@arm.com    }
3497436Sdam.sunwoo@arm.com
35012749Sgiacomo.travaglini@arm.com    Fault translateFs(const RequestPtr &req, ThreadContext *tc, Mode mode,
3518733Sgeoffrey.blake@arm.com            Translation *translation, bool &delay,
35210037SARM gem5 Developers            bool timing, ArmTranslationType tranType, bool functional = false);
35312749Sgiacomo.travaglini@arm.com    Fault translateSe(const RequestPtr &req, ThreadContext *tc, Mode mode,
3547404SAli.Saidi@ARM.com            Translation *translation, bool &delay, bool timing);
35512749Sgiacomo.travaglini@arm.com    Fault translateAtomic(const RequestPtr &req, ThreadContext *tc, Mode mode,
35612406Sgabeblack@google.com            ArmTranslationType tranType);
35712406Sgabeblack@google.com    Fault
35812749Sgiacomo.travaglini@arm.com    translateAtomic(const RequestPtr &req,
35912749Sgiacomo.travaglini@arm.com                    ThreadContext *tc, Mode mode) override
36012406Sgabeblack@google.com    {
36112406Sgabeblack@google.com        return translateAtomic(req, tc, mode, NormalTran);
36212406Sgabeblack@google.com    }
36312406Sgabeblack@google.com    void translateTiming(
36412749Sgiacomo.travaglini@arm.com            const RequestPtr &req, ThreadContext *tc,
36510037SARM gem5 Developers            Translation *translation, Mode mode,
36612406Sgabeblack@google.com            ArmTranslationType tranType);
36712406Sgabeblack@google.com    void
36812749Sgiacomo.travaglini@arm.com    translateTiming(const RequestPtr &req, ThreadContext *tc,
36912406Sgabeblack@google.com                    Translation *translation, Mode mode) override
37012406Sgabeblack@google.com    {
37112406Sgabeblack@google.com        translateTiming(req, tc, translation, mode, NormalTran);
37212406Sgabeblack@google.com    }
37312749Sgiacomo.travaglini@arm.com    Fault translateComplete(const RequestPtr &req, ThreadContext *tc,
37410037SARM gem5 Developers            Translation *translation, Mode mode, ArmTranslationType tranType,
37510037SARM gem5 Developers            bool callFromS2);
37612406Sgabeblack@google.com    Fault finalizePhysical(
37712749Sgiacomo.travaglini@arm.com            const RequestPtr &req,
37812749Sgiacomo.travaglini@arm.com            ThreadContext *tc, Mode mode) const override;
3796116Snate@binkert.org
38011168Sandreas.hansson@arm.com    void drainResume() override;
3819439SAndreas.Sandberg@ARM.com
3826019Shines@cs.fsu.edu    // Checkpointing
38311168Sandreas.hansson@arm.com    void serialize(CheckpointOut &cp) const override;
38411168Sandreas.hansson@arm.com    void unserialize(CheckpointIn &cp) override;
3856019Shines@cs.fsu.edu
38611169Sandreas.hansson@arm.com    void regStats() override;
3877749SAli.Saidi@ARM.com
38811168Sandreas.hansson@arm.com    void regProbePoints() override;
38910463SAndreas.Sandberg@ARM.com
3908922Swilliam.wang@arm.com    /**
3918922Swilliam.wang@arm.com     * Get the table walker master port. This is used for migrating
3928922Swilliam.wang@arm.com     * port connections during a CPU takeOverFrom() call. For
3938922Swilliam.wang@arm.com     * architectures that do not have a table walker, NULL is
3948922Swilliam.wang@arm.com     * returned, hence the use of a pointer rather than a
3958922Swilliam.wang@arm.com     * reference. For ARM this method will always return a valid port
3968922Swilliam.wang@arm.com     * pointer.
3978922Swilliam.wang@arm.com     *
3988922Swilliam.wang@arm.com     * @return A pointer to the walker master port
3998922Swilliam.wang@arm.com     */
40011169Sandreas.hansson@arm.com    BaseMasterPort* getMasterPort() override;
4017781SAli.Saidi@ARM.com
4027749SAli.Saidi@ARM.com    // Caching misc register values here.
4037749SAli.Saidi@ARM.com    // Writing to misc registers needs to invalidate them.
4047749SAli.Saidi@ARM.com    // translateFunctional/translateSe/translateFs checks if they are
4057749SAli.Saidi@ARM.com    // invalid and call updateMiscReg if necessary.
4067749SAli.Saidi@ARM.comprotected:
40710854SNathanael.Premillieu@arm.com    CPSR cpsr;
40810037SARM gem5 Developers    bool aarch64;
40910037SARM gem5 Developers    ExceptionLevel aarch64EL;
4107749SAli.Saidi@ARM.com    SCTLR sctlr;
41110037SARM gem5 Developers    SCR scr;
4127749SAli.Saidi@ARM.com    bool isPriv;
41310037SARM gem5 Developers    bool isSecure;
41410037SARM gem5 Developers    bool isHyp;
41510037SARM gem5 Developers    TTBCR ttbcr;
41610037SARM gem5 Developers    uint16_t asid;
41710037SARM gem5 Developers    uint8_t vmid;
4187749SAli.Saidi@ARM.com    PRRR prrr;
4197749SAli.Saidi@ARM.com    NMRR nmrr;
42010037SARM gem5 Developers    HCR hcr;
4217749SAli.Saidi@ARM.com    uint32_t dacr;
4227749SAli.Saidi@ARM.com    bool miscRegValid;
42311152Smitch.hayenga@arm.com    ContextID miscRegContext;
42410037SARM gem5 Developers    ArmTranslationType curTranType;
42510037SARM gem5 Developers
42610037SARM gem5 Developers    // Cached copies of system-level properties
42710037SARM gem5 Developers    bool haveLPAE;
42810037SARM gem5 Developers    bool haveVirtualization;
42910037SARM gem5 Developers    bool haveLargeAsid64;
43010037SARM gem5 Developers
43112005Sandreas.sandberg@arm.com    AddrRange m5opRange;
43212005Sandreas.sandberg@arm.com
43310037SARM gem5 Developers    void updateMiscReg(ThreadContext *tc,
43410037SARM gem5 Developers                       ArmTranslationType tranType = NormalTran);
43510037SARM gem5 Developers
4367749SAli.Saidi@ARM.compublic:
4378299Schander.sudanthi@arm.com    const Params *
4388299Schander.sudanthi@arm.com    params() const
4398299Schander.sudanthi@arm.com    {
4408299Schander.sudanthi@arm.com        return dynamic_cast<const Params *>(_params);
4418299Schander.sudanthi@arm.com    }
4427749SAli.Saidi@ARM.com    inline void invalidateMiscReg() { miscRegValid = false; }
44310037SARM gem5 Developers
44410037SARM gem5 Developersprivate:
44510037SARM gem5 Developers    /** Remove any entries that match both a va and asn
44610037SARM gem5 Developers     * @param mva virtual address to flush
44710037SARM gem5 Developers     * @param asn contextid/asn to flush on match
44810037SARM gem5 Developers     * @param secure_lookup if the operation affects the secure world
44910037SARM gem5 Developers     * @param hyp if the operation affects hyp mode
45010037SARM gem5 Developers     * @param ignore_asn if the flush should ignore the asn
45110037SARM gem5 Developers     */
45210037SARM gem5 Developers    void _flushMva(Addr mva, uint64_t asn, bool secure_lookup,
45310037SARM gem5 Developers                   bool hyp, bool ignore_asn, uint8_t target_el);
45410037SARM gem5 Developers
45510037SARM gem5 Developers    bool checkELMatch(uint8_t target_el, uint8_t tentry_el, bool ignore_el);
45611395Sandreas.sandberg@arm.com
45711395Sandreas.sandberg@arm.com  public: /* Testing */
45812749Sgiacomo.travaglini@arm.com    Fault testTranslation(const RequestPtr &req, Mode mode,
45911395Sandreas.sandberg@arm.com                          TlbEntry::DomainType domain);
46011395Sandreas.sandberg@arm.com    Fault testWalk(Addr pa, Addr size, Addr va, bool is_secure, Mode mode,
46111395Sandreas.sandberg@arm.com                   TlbEntry::DomainType domain,
46211395Sandreas.sandberg@arm.com                   LookupLevel lookup_level);
4636019Shines@cs.fsu.edu};
4646019Shines@cs.fsu.edu
46512605Sgiacomo.travaglini@arm.comtemplate<typename T>
46612605Sgiacomo.travaglini@arm.comTLB *
46712605Sgiacomo.travaglini@arm.comgetITBPtr(T *tc)
46812605Sgiacomo.travaglini@arm.com{
46912605Sgiacomo.travaglini@arm.com    auto tlb = static_cast<TLB *>(tc->getITBPtr());
47012605Sgiacomo.travaglini@arm.com    assert(tlb);
47112605Sgiacomo.travaglini@arm.com    return tlb;
47212605Sgiacomo.travaglini@arm.com}
47312605Sgiacomo.travaglini@arm.com
47412605Sgiacomo.travaglini@arm.comtemplate<typename T>
47512605Sgiacomo.travaglini@arm.comTLB *
47612605Sgiacomo.travaglini@arm.comgetDTBPtr(T *tc)
47712605Sgiacomo.travaglini@arm.com{
47812605Sgiacomo.travaglini@arm.com    auto tlb = static_cast<TLB *>(tc->getDTBPtr());
47912605Sgiacomo.travaglini@arm.com    assert(tlb);
48012605Sgiacomo.travaglini@arm.com    return tlb;
48112605Sgiacomo.travaglini@arm.com}
48212605Sgiacomo.travaglini@arm.com
4837811Ssteve.reinhardt@amd.com} // namespace ArmISA
4846019Shines@cs.fsu.edu
4856019Shines@cs.fsu.edu#endif // __ARCH_ARM_TLB_HH__
486