tlb.hh revision 11577
12810SN/A/* 29614Srene.dejong@arm.com * Copyright (c) 2010-2013, 2016 ARM Limited 38856Sandreas.hansson@arm.com * All rights reserved 48856Sandreas.hansson@arm.com * 58856Sandreas.hansson@arm.com * The license below extends only to copyright in the software and shall 68856Sandreas.hansson@arm.com * not be construed as granting a license to any other intellectual 78856Sandreas.hansson@arm.com * property including but not limited to intellectual property relating 88856Sandreas.hansson@arm.com * to a hardware implementation of the functionality of the software 98856Sandreas.hansson@arm.com * licensed hereunder. You may use the software subject to the license 108856Sandreas.hansson@arm.com * terms below provided that you ensure that this notice is replicated 118856Sandreas.hansson@arm.com * unmodified and in its entirety in all distributions of the software, 128856Sandreas.hansson@arm.com * modified or unmodified, in source code or in binary form. 138856Sandreas.hansson@arm.com * 142810SN/A * Copyright (c) 2001-2005 The Regents of The University of Michigan 152810SN/A * All rights reserved. 162810SN/A * 172810SN/A * Redistribution and use in source and binary forms, with or without 182810SN/A * modification, are permitted provided that the following conditions are 192810SN/A * met: redistributions of source code must retain the above copyright 202810SN/A * notice, this list of conditions and the following disclaimer; 212810SN/A * redistributions in binary form must reproduce the above copyright 222810SN/A * notice, this list of conditions and the following disclaimer in the 232810SN/A * documentation and/or other materials provided with the distribution; 242810SN/A * neither the name of the copyright holders nor the names of its 252810SN/A * contributors may be used to endorse or promote products derived from 262810SN/A * this software without specific prior written permission. 272810SN/A * 282810SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 292810SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 302810SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 312810SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 322810SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 332810SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 342810SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 352810SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 362810SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 372810SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 382810SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 392810SN/A * 402810SN/A * Authors: Ali Saidi 412810SN/A */ 422810SN/A 432810SN/A#ifndef __ARCH_ARM_TLB_HH__ 442810SN/A#define __ARCH_ARM_TLB_HH__ 452810SN/A 462810SN/A 472810SN/A#include "arch/arm/isa_traits.hh" 488232Snate@binkert.org#include "arch/arm/pagetable.hh" 499152Satgutier@umich.edu#include "arch/arm/utility.hh" 509795Sandreas.hansson@arm.com#include "arch/arm/vtophys.hh" 519795Sandreas.hansson@arm.com#include "arch/generic/tlb.hh" 5210263Satgutier@umich.edu#include "base/statistics.hh" 535338Sstever@gmail.com#include "mem/request.hh" 549795Sandreas.hansson@arm.com#include "params/ArmTLB.hh" 555338Sstever@gmail.com#include "sim/probe/pmu.hh" 568786Sgblack@eecs.umich.edu 572810SN/Aclass ThreadContext; 582810SN/A 592810SN/Anamespace ArmISA { 608856Sandreas.hansson@arm.com 618856Sandreas.hansson@arm.comclass TableWalker; 628856Sandreas.hansson@arm.comclass Stage2LookUp; 638922Swilliam.wang@arm.comclass Stage2MMU; 648914Sandreas.hansson@arm.comclass TLB; 658856Sandreas.hansson@arm.com 668856Sandreas.hansson@arm.comclass TlbTestInterface 674475SN/A{ 685034SN/A public: 695034SN/A TlbTestInterface() {} 7010360Sandreas.hansson@arm.com virtual ~TlbTestInterface() {} 7110622Smitch.hayenga@arm.com 7210622Smitch.hayenga@arm.com /** 734628SN/A * Check if a TLB translation should be forced to fail. 749814Sandreas.hansson@arm.com * 759263Smrinmoy.ghosh@arm.com * @param req Request requiring a translation. 769263Smrinmoy.ghosh@arm.com * @param is_priv Access from a privileged mode (i.e., not EL0) 775034SN/A * @param mode Access type 786122SSteve.Reinhardt@amd.com * @param domain Domain type 798134SAli.Saidi@ARM.com */ 804626SN/A virtual Fault translationCheck(RequestPtr req, bool is_priv, 8110360Sandreas.hansson@arm.com BaseTLB::Mode mode, 824626SN/A TlbEntry::DomainType domain) = 0; 835034SN/A 848883SAli.Saidi@ARM.com /** 858833Sdam.sunwoo@arm.com * Check if a page table walker access should be forced to fail. 864458SN/A * 872810SN/A * @param pa Physical address the walker is accessing 882810SN/A * @param size Walker access size 893013SN/A * @param va Virtual address that initiated the walk 908856Sandreas.hansson@arm.com * @param is_secure Access from secure state 912810SN/A * @param is_priv Access from a privileged mode (i.e., not EL0) 923013SN/A * @param mode Access type 938856Sandreas.hansson@arm.com * @param domain Domain type 942810SN/A * @param lookup_level Page table walker level 959614Srene.dejong@arm.com */ 969614Srene.dejong@arm.com virtual Fault walkCheck(Addr pa, Addr size, Addr va, bool is_secure, 979614Srene.dejong@arm.com Addr is_priv, BaseTLB::Mode mode, 9810345SCurtis.Dunham@arm.com TlbEntry::DomainType domain, 9910345SCurtis.Dunham@arm.com LookupLevel lookup_level) = 0; 10010345SCurtis.Dunham@arm.com}; 1019614Srene.dejong@arm.com 1022810SN/Aclass TLB : public BaseTLB 1032810SN/A{ 1042810SN/A public: 1058856Sandreas.hansson@arm.com enum ArmFlags { 1062810SN/A AlignmentMask = 0x7, 1073013SN/A 1088856Sandreas.hansson@arm.com AlignByte = 0x0, 1093013SN/A AlignHalfWord = 0x1, 1108856Sandreas.hansson@arm.com AlignWord = 0x2, 1114666SN/A AlignDoubleWord = 0x3, 1128922Swilliam.wang@arm.com AlignQuadWord = 0x4, 1132897SN/A AlignOctWord = 0x5, 1142810SN/A 1152810SN/A AllowUnaligned = 0x8, 11610344Sandreas.hansson@arm.com // Priv code operating as if it wasn't 11710344Sandreas.hansson@arm.com UserMode = 0x10, 11810344Sandreas.hansson@arm.com // Because zero otherwise looks like a valid setting and may be used 11910344Sandreas.hansson@arm.com // accidentally, this bit must be non-zero to show it was used on 12010344Sandreas.hansson@arm.com // purpose. 12110344Sandreas.hansson@arm.com MustBeOne = 0x40 12210344Sandreas.hansson@arm.com }; 12310344Sandreas.hansson@arm.com 12410344Sandreas.hansson@arm.com enum ArmTranslationType { 1252844SN/A NormalTran = 0, 1262810SN/A S1CTran = 0x1, 1272858SN/A HypMode = 0x2, 1282858SN/A // Secure code operating as if it wasn't (required by some Address 1298856Sandreas.hansson@arm.com // Translate operations) 1308922Swilliam.wang@arm.com S1S2NsTran = 0x4, 1318711Sandreas.hansson@arm.com // Address translation instructions (eg AT S1E0R_Xt) need to be handled 1322858SN/A // in special ways during translation because they could need to act 1332858SN/A // like a different EL than the current EL. The following flags are 1349294Sandreas.hansson@arm.com // for these instructions 1359294Sandreas.hansson@arm.com S1E0Tran = 0x8, 1368922Swilliam.wang@arm.com S1E1Tran = 0x10, 1378922Swilliam.wang@arm.com S1E2Tran = 0x20, 1388922Swilliam.wang@arm.com S1E3Tran = 0x40, 1398922Swilliam.wang@arm.com S12E0Tran = 0x80, 1408922Swilliam.wang@arm.com S12E1Tran = 0x100 1418922Swilliam.wang@arm.com }; 1428922Swilliam.wang@arm.com protected: 1438922Swilliam.wang@arm.com TlbEntry* table; // the Page Table 1449294Sandreas.hansson@arm.com int size; // TLB Size 1459294Sandreas.hansson@arm.com bool isStage2; // Indicates this TLB is part of the second stage MMU 1468922Swilliam.wang@arm.com bool stage2Req; // Indicates whether a stage 2 lookup is also required 1478922Swilliam.wang@arm.com uint64_t _attr; // Memory attributes for last accessed TLB entry 1488922Swilliam.wang@arm.com bool directToStage2; // Indicates whether all translation requests should 1498922Swilliam.wang@arm.com // be routed directly to the stage 2 TLB 1508922Swilliam.wang@arm.com 1518922Swilliam.wang@arm.com TableWalker *tableWalker; 1528922Swilliam.wang@arm.com TLB *stage2Tlb; 1534628SN/A Stage2MMU *stage2Mmu; 1542858SN/A 1552810SN/A TlbTestInterface *test; 1562810SN/A 1572810SN/A // Access Stats 1582810SN/A mutable Stats::Scalar instHits; 1592810SN/A mutable Stats::Scalar instMisses; 1604022SN/A mutable Stats::Scalar readHits; 1614022SN/A mutable Stats::Scalar readMisses; 1624022SN/A mutable Stats::Scalar writeHits; 1632810SN/A mutable Stats::Scalar writeMisses; 1642810SN/A mutable Stats::Scalar inserts; 1658833Sdam.sunwoo@arm.com mutable Stats::Scalar flushTlb; 1662810SN/A mutable Stats::Scalar flushTlbMva; 1672810SN/A mutable Stats::Scalar flushTlbMvaAsid; 1682810SN/A mutable Stats::Scalar flushTlbAsid; 1692810SN/A mutable Stats::Scalar flushedEntries; 1708833Sdam.sunwoo@arm.com mutable Stats::Scalar alignFaults; 1718833Sdam.sunwoo@arm.com mutable Stats::Scalar prefetchFaults; 1728833Sdam.sunwoo@arm.com mutable Stats::Scalar domainFaults; 1732810SN/A mutable Stats::Scalar permsFaults; 1742810SN/A 1754871SN/A Stats::Formula readAccesses; 1764871SN/A Stats::Formula writeAccesses; 1774871SN/A Stats::Formula instAccesses; 1784871SN/A Stats::Formula hits; 1794871SN/A Stats::Formula misses; 1804871SN/A Stats::Formula accesses; 1814871SN/A 1824871SN/A /** PMU probe for TLB refills */ 1834871SN/A ProbePoints::PMUUPtr ppRefills; 1844871SN/A 1852810SN/A int rangeMRU; //On lookup, only move entries ahead when outside rangeMRU 1862810SN/A 1872810SN/A public: 1888833Sdam.sunwoo@arm.com TLB(const ArmTLBParams *p); 1892810SN/A TLB(const Params *p, int _size, TableWalker *_walker); 1904871SN/A 1918833Sdam.sunwoo@arm.com /** Lookup an entry in the TLB 1928833Sdam.sunwoo@arm.com * @param vpn virtual address 1938833Sdam.sunwoo@arm.com * @param asn context id/address space id to use 1942810SN/A * @param vmid The virtual machine ID used for stage 2 translation 1952810SN/A * @param secure if the lookup is secure 1962810SN/A * @param hyp if the lookup is done from hyp mode 1972810SN/A * @param functional if the lookup should modify state 1988833Sdam.sunwoo@arm.com * @param ignore_asn if on lookup asn should be ignored 1992810SN/A * @return pointer to TLB entry if it exists 2004871SN/A */ 2018833Sdam.sunwoo@arm.com TlbEntry *lookup(Addr vpn, uint16_t asn, uint8_t vmid, bool hyp, 2028833Sdam.sunwoo@arm.com bool secure, bool functional, 2038833Sdam.sunwoo@arm.com bool ignore_asn, uint8_t target_el); 2042810SN/A 2052810SN/A virtual ~TLB(); 2064022SN/A 2074022SN/A void takeOverFrom(BaseTLB *otlb) override; 2084022SN/A 2092810SN/A /// setup all the back pointers 2102810SN/A void init() override; 2118833Sdam.sunwoo@arm.com 2122810SN/A void setTestInterface(SimObject *ti); 2132810SN/A 2142810SN/A TableWalker *getTableWalker() { return tableWalker; } 2152810SN/A 2168833Sdam.sunwoo@arm.com void setMMU(Stage2MMU *m, MasterID master_id); 2178833Sdam.sunwoo@arm.com 2188833Sdam.sunwoo@arm.com int getsize() const { return size; } 2192810SN/A 2202810SN/A void insert(Addr vaddr, TlbEntry &pte); 2212810SN/A 2222810SN/A Fault getTE(TlbEntry **te, RequestPtr req, ThreadContext *tc, Mode mode, 2232810SN/A Translation *translation, bool timing, bool functional, 2248833Sdam.sunwoo@arm.com bool is_secure, ArmTranslationType tranType); 2252810SN/A 2264871SN/A Fault getResultTe(TlbEntry **te, RequestPtr req, ThreadContext *tc, 2278833Sdam.sunwoo@arm.com Mode mode, Translation *translation, bool timing, 2288833Sdam.sunwoo@arm.com bool functional, TlbEntry *mergeTe); 2298833Sdam.sunwoo@arm.com 2302810SN/A Fault checkPermissions(TlbEntry *te, RequestPtr req, Mode mode); 2312810SN/A Fault checkPermissions64(TlbEntry *te, RequestPtr req, Mode mode, 2322810SN/A ThreadContext *tc); 2332810SN/A 2348833Sdam.sunwoo@arm.com 2352810SN/A /** Reset the entire TLB 2364871SN/A * @param secure_lookup if the operation affects the secure world 2378833Sdam.sunwoo@arm.com */ 2388833Sdam.sunwoo@arm.com void flushAllSecurity(bool secure_lookup, uint8_t target_el, 2398833Sdam.sunwoo@arm.com bool ignore_el = false); 2402810SN/A 2412810SN/A /** Remove all entries in the non secure world, depending on whether they 2424022SN/A * were allocated in hyp mode or not 2434022SN/A * @param hyp if the opperation affects hyp mode 2444022SN/A */ 2452810SN/A void flushAllNs(bool hyp, uint8_t target_el, bool ignore_el = false); 2462810SN/A 2478833Sdam.sunwoo@arm.com 2482810SN/A /** Reset the entire TLB. Used for CPU switching to prevent stale 2492810SN/A * translations after multiple switches 2502810SN/A */ 2512810SN/A void flushAll() override 2528833Sdam.sunwoo@arm.com { 2538833Sdam.sunwoo@arm.com flushAllSecurity(false, 0, true); 2548833Sdam.sunwoo@arm.com flushAllSecurity(true, 0, true); 2552810SN/A } 2562810SN/A 2572810SN/A /** Remove any entries that match both a va and asn 2582810SN/A * @param mva virtual address to flush 2592810SN/A * @param asn contextid/asn to flush on match 2608833Sdam.sunwoo@arm.com * @param secure_lookup if the operation affects the secure world 2612810SN/A */ 2624871SN/A void flushMvaAsid(Addr mva, uint64_t asn, bool secure_lookup, 2638833Sdam.sunwoo@arm.com uint8_t target_el); 2648833Sdam.sunwoo@arm.com 2658833Sdam.sunwoo@arm.com /** Remove any entries that match the asn 2662810SN/A * @param asn contextid/asn to flush on match 2672810SN/A * @param secure_lookup if the operation affects the secure world 2682810SN/A */ 2692810SN/A void flushAsid(uint64_t asn, bool secure_lookup, uint8_t target_el); 2708833Sdam.sunwoo@arm.com 2712810SN/A /** Remove all entries that match the va regardless of asn 2724871SN/A * @param mva address to flush from cache 2738833Sdam.sunwoo@arm.com * @param secure_lookup if the operation affects the secure world 2748833Sdam.sunwoo@arm.com * @param hyp if the operation affects hyp mode 2758833Sdam.sunwoo@arm.com */ 2762810SN/A void flushMva(Addr mva, bool secure_lookup, bool hyp, uint8_t target_el); 2772810SN/A 2784022SN/A void printTlb() const; 2794022SN/A 2804022SN/A void demapPage(Addr vaddr, uint64_t asn) override 2812810SN/A { 2822810SN/A // needed for x86 only 2832810SN/A panic("demapPage() is not implemented.\n"); 2842810SN/A } 2852810SN/A 2862810SN/A /** 2878833Sdam.sunwoo@arm.com * Do a functional lookup on the TLB (for debugging) 2882810SN/A * and don't modify any internal state 2898833Sdam.sunwoo@arm.com * @param tc thread context to get the context id from 2908833Sdam.sunwoo@arm.com * @param vaddr virtual address to translate 2918833Sdam.sunwoo@arm.com * @param pa returned physical address 2922810SN/A * @return if the translation was successful 2932810SN/A */ 2942810SN/A bool translateFunctional(ThreadContext *tc, Addr vaddr, Addr &paddr); 2952810SN/A 2962810SN/A /** 2978833Sdam.sunwoo@arm.com * Do a functional lookup on the TLB (for checker cpu) that 2982810SN/A * behaves like a normal lookup without modifying any page table state. 2992810SN/A */ 3008833Sdam.sunwoo@arm.com Fault translateFunctional(RequestPtr req, ThreadContext *tc, Mode mode, 3018833Sdam.sunwoo@arm.com ArmTranslationType tranType = NormalTran); 3028833Sdam.sunwoo@arm.com 3032810SN/A /** Accessor functions for memory attributes for last accessed TLB entry 3042810SN/A */ 3052810SN/A void 3062810SN/A setAttr(uint64_t attr) 3078833Sdam.sunwoo@arm.com { 3082810SN/A _attr = attr; 3092810SN/A } 3108833Sdam.sunwoo@arm.com 3118833Sdam.sunwoo@arm.com uint64_t 3128833Sdam.sunwoo@arm.com getAttr() const 3132810SN/A { 3142810SN/A return _attr; 3154022SN/A } 3164022SN/A 3174022SN/A Fault translateFs(RequestPtr req, ThreadContext *tc, Mode mode, 3182810SN/A Translation *translation, bool &delay, 3192810SN/A bool timing, ArmTranslationType tranType, bool functional = false); 3202810SN/A Fault translateSe(RequestPtr req, ThreadContext *tc, Mode mode, 3212810SN/A Translation *translation, bool &delay, bool timing); 3222810SN/A Fault translateAtomic(RequestPtr req, ThreadContext *tc, Mode mode, 3232810SN/A ArmTranslationType tranType = NormalTran); 3248833Sdam.sunwoo@arm.com Fault translateTiming(RequestPtr req, ThreadContext *tc, 3252810SN/A Translation *translation, Mode mode, 3268833Sdam.sunwoo@arm.com ArmTranslationType tranType = NormalTran); 3278833Sdam.sunwoo@arm.com Fault translateComplete(RequestPtr req, ThreadContext *tc, 3288833Sdam.sunwoo@arm.com Translation *translation, Mode mode, ArmTranslationType tranType, 3292810SN/A bool callFromS2); 3302810SN/A Fault finalizePhysical(RequestPtr req, ThreadContext *tc, Mode mode) const; 3312810SN/A 3322810SN/A void drainResume() override; 3332810SN/A 3348833Sdam.sunwoo@arm.com // Checkpointing 3352810SN/A void serialize(CheckpointOut &cp) const override; 3362810SN/A void unserialize(CheckpointIn &cp) override; 3378833Sdam.sunwoo@arm.com 3388833Sdam.sunwoo@arm.com void regStats() override; 3398833Sdam.sunwoo@arm.com 3402810SN/A void regProbePoints() override; 3412810SN/A 3422810SN/A /** 3432810SN/A * Get the table walker master port. This is used for migrating 3448833Sdam.sunwoo@arm.com * port connections during a CPU takeOverFrom() call. For 3452810SN/A * architectures that do not have a table walker, NULL is 3462810SN/A * returned, hence the use of a pointer rather than a 3478833Sdam.sunwoo@arm.com * reference. For ARM this method will always return a valid port 3488833Sdam.sunwoo@arm.com * pointer. 3498833Sdam.sunwoo@arm.com * 3502810SN/A * @return A pointer to the walker master port 3512810SN/A */ 3524022SN/A BaseMasterPort* getMasterPort() override; 3534022SN/A 3544022SN/A // Caching misc register values here. 3552810SN/A // Writing to misc registers needs to invalidate them. 3562810SN/A // translateFunctional/translateSe/translateFs checks if they are 3572810SN/A // invalid and call updateMiscReg if necessary. 3582810SN/Aprotected: 3592810SN/A CPSR cpsr; 3602810SN/A bool aarch64; 3612810SN/A ExceptionLevel aarch64EL; 3622810SN/A SCTLR sctlr; 3638833Sdam.sunwoo@arm.com SCR scr; 3648833Sdam.sunwoo@arm.com bool isPriv; 3658833Sdam.sunwoo@arm.com bool isSecure; 3668833Sdam.sunwoo@arm.com bool isHyp; 3672810SN/A TTBCR ttbcr; 3682810SN/A uint16_t asid; 3692810SN/A uint8_t vmid; 3702810SN/A PRRR prrr; 3712810SN/A NMRR nmrr; 3728833Sdam.sunwoo@arm.com HCR hcr; 3732810SN/A uint32_t dacr; 3742810SN/A bool miscRegValid; 3758833Sdam.sunwoo@arm.com ContextID miscRegContext; 3768833Sdam.sunwoo@arm.com ArmTranslationType curTranType; 3778833Sdam.sunwoo@arm.com 3782810SN/A // Cached copies of system-level properties 3792810SN/A bool haveLPAE; 3802810SN/A bool haveVirtualization; 3812810SN/A bool haveLargeAsid64; 3828833Sdam.sunwoo@arm.com 3832810SN/A void updateMiscReg(ThreadContext *tc, 3842810SN/A ArmTranslationType tranType = NormalTran); 3858833Sdam.sunwoo@arm.com 3868833Sdam.sunwoo@arm.compublic: 3878833Sdam.sunwoo@arm.com const Params * 3882810SN/A params() const 3892810SN/A { 3902810SN/A return dynamic_cast<const Params *>(_params); 3912810SN/A } 3922810SN/A inline void invalidateMiscReg() { miscRegValid = false; } 3932810SN/A 3942810SN/Aprivate: 3952810SN/A /** Remove any entries that match both a va and asn 3962810SN/A * @param mva virtual address to flush 3972810SN/A * @param asn contextid/asn to flush on match 3982810SN/A * @param secure_lookup if the operation affects the secure world 3992810SN/A * @param hyp if the operation affects hyp mode 4002810SN/A * @param ignore_asn if the flush should ignore the asn 4012810SN/A */ 4022810SN/A void _flushMva(Addr mva, uint64_t asn, bool secure_lookup, 4032810SN/A bool hyp, bool ignore_asn, uint8_t target_el); 4042810SN/A 4052810SN/A bool checkELMatch(uint8_t target_el, uint8_t tentry_el, bool ignore_el); 4062810SN/A 4072810SN/A public: /* Testing */ 4082810SN/A Fault testTranslation(RequestPtr req, Mode mode, 4092810SN/A TlbEntry::DomainType domain); 4102810SN/A Fault testWalk(Addr pa, Addr size, Addr va, bool is_secure, Mode mode, 4112810SN/A TlbEntry::DomainType domain, 4122810SN/A LookupLevel lookup_level); 4132810SN/A}; 4142810SN/A 4152810SN/A} // namespace ArmISA 4162810SN/A 4172810SN/A#endif // __ARCH_ARM_TLB_HH__ 4182810SN/A