tlb.hh revision 5555
12650Ssaidi@eecs.umich.edu/*
22650Ssaidi@eecs.umich.edu * Copyright (c) 2006 The Regents of The University of Michigan
32650Ssaidi@eecs.umich.edu * All rights reserved.
42650Ssaidi@eecs.umich.edu *
52650Ssaidi@eecs.umich.edu * Redistribution and use in source and binary forms, with or without
62650Ssaidi@eecs.umich.edu * modification, are permitted provided that the following conditions are
72650Ssaidi@eecs.umich.edu * met: redistributions of source code must retain the above copyright
82650Ssaidi@eecs.umich.edu * notice, this list of conditions and the following disclaimer;
92650Ssaidi@eecs.umich.edu * redistributions in binary form must reproduce the above copyright
102650Ssaidi@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the
112650Ssaidi@eecs.umich.edu * documentation and/or other materials provided with the distribution;
122650Ssaidi@eecs.umich.edu * neither the name of the copyright holders nor the names of its
132650Ssaidi@eecs.umich.edu * contributors may be used to endorse or promote products derived from
142650Ssaidi@eecs.umich.edu * this software without specific prior written permission.
152650Ssaidi@eecs.umich.edu *
162650Ssaidi@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172650Ssaidi@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182650Ssaidi@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192650Ssaidi@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202650Ssaidi@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212650Ssaidi@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222650Ssaidi@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232650Ssaidi@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242650Ssaidi@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252650Ssaidi@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262650Ssaidi@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272650Ssaidi@eecs.umich.edu *
282650Ssaidi@eecs.umich.edu * Authors: Ali Saidi
292650Ssaidi@eecs.umich.edu */
302650Ssaidi@eecs.umich.edu
312650Ssaidi@eecs.umich.edu#ifndef __ARCH_SPARC_TLB_HH__
322650Ssaidi@eecs.umich.edu#define __ARCH_SPARC_TLB_HH__
332650Ssaidi@eecs.umich.edu
343836Ssaidi@eecs.umich.edu#include "arch/sparc/asi.hh"
353804Ssaidi@eecs.umich.edu#include "arch/sparc/tlb_map.hh"
363602Sgblack@eecs.umich.edu#include "base/misc.hh"
374997Sgblack@eecs.umich.edu#include "config/full_system.hh"
383569Sgblack@eecs.umich.edu#include "mem/request.hh"
395034Smilesck@eecs.umich.edu#include "params/SparcDTB.hh"
405034Smilesck@eecs.umich.edu#include "params/SparcITB.hh"
413468Sgblack@eecs.umich.edu#include "sim/faults.hh"
425358Sgblack@eecs.umich.edu#include "sim/tlb.hh"
433468Sgblack@eecs.umich.edu
443468Sgblack@eecs.umich.educlass ThreadContext;
453806Ssaidi@eecs.umich.educlass Packet;
463468Sgblack@eecs.umich.edu
473468Sgblack@eecs.umich.edunamespace SparcISA
483468Sgblack@eecs.umich.edu{
493603Ssaidi@eecs.umich.edu
505358Sgblack@eecs.umich.educlass TLB : public BaseTLB
513804Ssaidi@eecs.umich.edu{
524997Sgblack@eecs.umich.edu#if !FULL_SYSTEM
534997Sgblack@eecs.umich.edu    //These faults need to be able to populate the tlb in SE mode.
544997Sgblack@eecs.umich.edu    friend class FastInstructionAccessMMUMiss;
554997Sgblack@eecs.umich.edu    friend class FastDataAccessMMUMiss;
564997Sgblack@eecs.umich.edu#endif
574997Sgblack@eecs.umich.edu
584990Sgblack@eecs.umich.edu    //TLB state
594990Sgblack@eecs.umich.edu  protected:
604990Sgblack@eecs.umich.edu    uint64_t c0_tsb_ps0;
614990Sgblack@eecs.umich.edu    uint64_t c0_tsb_ps1;
624990Sgblack@eecs.umich.edu    uint64_t c0_config;
634990Sgblack@eecs.umich.edu    uint64_t cx_tsb_ps0;
644990Sgblack@eecs.umich.edu    uint64_t cx_tsb_ps1;
654990Sgblack@eecs.umich.edu    uint64_t cx_config;
664990Sgblack@eecs.umich.edu    uint64_t sfsr;
674990Sgblack@eecs.umich.edu    uint64_t tag_access;
684990Sgblack@eecs.umich.edu
693804Ssaidi@eecs.umich.edu  protected:
703804Ssaidi@eecs.umich.edu    TlbMap lookupTable;;
713804Ssaidi@eecs.umich.edu    typedef TlbMap::iterator MapIter;
723804Ssaidi@eecs.umich.edu
733804Ssaidi@eecs.umich.edu    TlbEntry *tlb;
743804Ssaidi@eecs.umich.edu
753804Ssaidi@eecs.umich.edu    int size;
763804Ssaidi@eecs.umich.edu    int usedEntries;
773881Ssaidi@eecs.umich.edu    int lastReplaced;
783804Ssaidi@eecs.umich.edu
793836Ssaidi@eecs.umich.edu    uint64_t cacheState;
803836Ssaidi@eecs.umich.edu    bool cacheValid;
813836Ssaidi@eecs.umich.edu
823881Ssaidi@eecs.umich.edu    std::list<TlbEntry*> freeList;
833881Ssaidi@eecs.umich.edu
843804Ssaidi@eecs.umich.edu    enum FaultTypes {
853804Ssaidi@eecs.umich.edu        OtherFault = 0,
863804Ssaidi@eecs.umich.edu        PrivViolation = 0x1,
873804Ssaidi@eecs.umich.edu        SideEffect = 0x2,
883804Ssaidi@eecs.umich.edu        AtomicToIo = 0x4,
893804Ssaidi@eecs.umich.edu        IllegalAsi = 0x8,
903804Ssaidi@eecs.umich.edu        LoadFromNfo = 0x10,
913804Ssaidi@eecs.umich.edu        VaOutOfRange = 0x20,
923804Ssaidi@eecs.umich.edu        VaOutOfRangeJmp = 0x40
933468Sgblack@eecs.umich.edu    };
943468Sgblack@eecs.umich.edu
953804Ssaidi@eecs.umich.edu    enum ContextType {
963804Ssaidi@eecs.umich.edu        Primary = 0,
973804Ssaidi@eecs.umich.edu        Secondary = 1,
983804Ssaidi@eecs.umich.edu        Nucleus = 2
993468Sgblack@eecs.umich.edu    };
1003468Sgblack@eecs.umich.edu
1014070Ssaidi@eecs.umich.edu    enum TsbPageSize {
1024070Ssaidi@eecs.umich.edu        Ps0,
1034070Ssaidi@eecs.umich.edu        Ps1
1044070Ssaidi@eecs.umich.edu    };
1054070Ssaidi@eecs.umich.edu  public:
1063804Ssaidi@eecs.umich.edu    /** lookup an entry in the TLB based on the partition id, and real bit if
1073804Ssaidi@eecs.umich.edu     * real is true or the partition id, and context id if real is false.
1083804Ssaidi@eecs.umich.edu     * @param va the virtual address not shifted (e.g. bottom 13 bits are 0)
1093804Ssaidi@eecs.umich.edu     * @param paritition_id partition this entry is for
1103804Ssaidi@eecs.umich.edu     * @param real is this a real->phys or virt->phys translation
1113804Ssaidi@eecs.umich.edu     * @param context_id if this is virt->phys what context
1125555Snate@binkert.org     * @param update_used should ew update the used bits in the
1135555Snate@binkert.org     * entries on not useful if we are trying to do a va->pa without
1145555Snate@binkert.org     * mucking with any state for a debug read for example.
1153804Ssaidi@eecs.umich.edu     * @return A pointer to a tlb entry
1163804Ssaidi@eecs.umich.edu     */
1174070Ssaidi@eecs.umich.edu    TlbEntry *lookup(Addr va, int partition_id, bool real, int context_id = 0,
1184070Ssaidi@eecs.umich.edu            bool update_used = true);
1194070Ssaidi@eecs.umich.edu  protected:
1203804Ssaidi@eecs.umich.edu    /** Insert a PTE into the TLB. */
1213804Ssaidi@eecs.umich.edu    void insert(Addr vpn, int partition_id, int context_id, bool real,
1223826Ssaidi@eecs.umich.edu            const PageTableEntry& PTE, int entry = -1);
1233804Ssaidi@eecs.umich.edu
1243804Ssaidi@eecs.umich.edu    /** Given an entry id, read that tlb entries' tag. */
1253804Ssaidi@eecs.umich.edu    uint64_t TagRead(int entry);
1263804Ssaidi@eecs.umich.edu
1273804Ssaidi@eecs.umich.edu    /** Remove all entries from the TLB */
1283804Ssaidi@eecs.umich.edu    void invalidateAll();
1293804Ssaidi@eecs.umich.edu
1303804Ssaidi@eecs.umich.edu    /** Remove all non-locked entries from the tlb that match partition id. */
1313804Ssaidi@eecs.umich.edu    void demapAll(int partition_id);
1323804Ssaidi@eecs.umich.edu
1333804Ssaidi@eecs.umich.edu    /** Remove all entries that match a given context/partition id. */
1343804Ssaidi@eecs.umich.edu    void demapContext(int partition_id, int context_id);
1353804Ssaidi@eecs.umich.edu
1363804Ssaidi@eecs.umich.edu    /** Remve all entries that match a certain partition id, (contextid), and
1373804Ssaidi@eecs.umich.edu     * va). */
1383804Ssaidi@eecs.umich.edu    void demapPage(Addr va, int partition_id, bool real, int context_id);
1393804Ssaidi@eecs.umich.edu
1403804Ssaidi@eecs.umich.edu    /** Checks if the virtual address provided is a valid one. */
1413804Ssaidi@eecs.umich.edu    bool validVirtualAddress(Addr va, bool am);
1423804Ssaidi@eecs.umich.edu
1434990Sgblack@eecs.umich.edu    void writeSfsr(bool write, ContextType ct,
1443804Ssaidi@eecs.umich.edu            bool se, FaultTypes ft, int asi);
1453804Ssaidi@eecs.umich.edu
1463834Sgblack@eecs.umich.edu    void clearUsedBits();
1473804Ssaidi@eecs.umich.edu
1483804Ssaidi@eecs.umich.edu
1494990Sgblack@eecs.umich.edu    void writeTagAccess(Addr va, int context);
1503826Ssaidi@eecs.umich.edu
1513804Ssaidi@eecs.umich.edu  public:
1525034Smilesck@eecs.umich.edu    typedef SparcTLBParams Params;
1535034Smilesck@eecs.umich.edu    TLB(const Params *p);
1543804Ssaidi@eecs.umich.edu
1555358Sgblack@eecs.umich.edu    void demapPage(Addr vaddr, uint64_t asn)
1565358Sgblack@eecs.umich.edu    {
1575358Sgblack@eecs.umich.edu        panic("demapPage(Addr) is not implemented.\n");
1585358Sgblack@eecs.umich.edu    }
1595358Sgblack@eecs.umich.edu
1603826Ssaidi@eecs.umich.edu    void dumpAll();
1613826Ssaidi@eecs.umich.edu
1623804Ssaidi@eecs.umich.edu    // Checkpointing
1633804Ssaidi@eecs.umich.edu    virtual void serialize(std::ostream &os);
1643804Ssaidi@eecs.umich.edu    virtual void unserialize(Checkpoint *cp, const std::string &section);
1653881Ssaidi@eecs.umich.edu
1663881Ssaidi@eecs.umich.edu    /** Give an entry id, read that tlb entries' tte */
1673881Ssaidi@eecs.umich.edu    uint64_t TteRead(int entry);
1683881Ssaidi@eecs.umich.edu
1693804Ssaidi@eecs.umich.edu};
1703804Ssaidi@eecs.umich.edu
1713804Ssaidi@eecs.umich.educlass ITB : public TLB
1723804Ssaidi@eecs.umich.edu{
1733804Ssaidi@eecs.umich.edu  public:
1745034Smilesck@eecs.umich.edu    typedef SparcITBParams Params;
1755034Smilesck@eecs.umich.edu    ITB(const Params *p) : TLB(p)
1763468Sgblack@eecs.umich.edu    {
1773836Ssaidi@eecs.umich.edu        cacheEntry = NULL;
1783804Ssaidi@eecs.umich.edu    }
1793569Sgblack@eecs.umich.edu
1803804Ssaidi@eecs.umich.edu    Fault translate(RequestPtr &req, ThreadContext *tc);
1813804Ssaidi@eecs.umich.edu  private:
1824990Sgblack@eecs.umich.edu    void writeSfsr(bool write, ContextType ct,
1833804Ssaidi@eecs.umich.edu            bool se, FaultTypes ft, int asi);
1843836Ssaidi@eecs.umich.edu    TlbEntry *cacheEntry;
1853826Ssaidi@eecs.umich.edu    friend class DTB;
1863804Ssaidi@eecs.umich.edu};
1873804Ssaidi@eecs.umich.edu
1883804Ssaidi@eecs.umich.educlass DTB : public TLB
1893804Ssaidi@eecs.umich.edu{
1904990Sgblack@eecs.umich.edu    //DTLB specific state
1914990Sgblack@eecs.umich.edu  protected:
1924990Sgblack@eecs.umich.edu    uint64_t sfar;
1933804Ssaidi@eecs.umich.edu  public:
1945034Smilesck@eecs.umich.edu    typedef SparcDTBParams Params;
1955034Smilesck@eecs.umich.edu    DTB(const Params *p) : TLB(p)
1963804Ssaidi@eecs.umich.edu    {
1974990Sgblack@eecs.umich.edu        sfar = 0;
1983836Ssaidi@eecs.umich.edu        cacheEntry[0] = NULL;
1993836Ssaidi@eecs.umich.edu        cacheEntry[1] = NULL;
2003804Ssaidi@eecs.umich.edu    }
2013804Ssaidi@eecs.umich.edu
2023804Ssaidi@eecs.umich.edu    Fault translate(RequestPtr &req, ThreadContext *tc, bool write);
2034997Sgblack@eecs.umich.edu#if FULL_SYSTEM
2043806Ssaidi@eecs.umich.edu    Tick doMmuRegRead(ThreadContext *tc, Packet *pkt);
2053806Ssaidi@eecs.umich.edu    Tick doMmuRegWrite(ThreadContext *tc, Packet *pkt);
2064997Sgblack@eecs.umich.edu#endif
2074070Ssaidi@eecs.umich.edu    void GetTsbPtr(ThreadContext *tc, Addr addr, int ctx, Addr *ptrs);
2083804Ssaidi@eecs.umich.edu
2094990Sgblack@eecs.umich.edu    // Checkpointing
2104990Sgblack@eecs.umich.edu    virtual void serialize(std::ostream &os);
2114990Sgblack@eecs.umich.edu    virtual void unserialize(Checkpoint *cp, const std::string &section);
2124990Sgblack@eecs.umich.edu
2133804Ssaidi@eecs.umich.edu  private:
2144990Sgblack@eecs.umich.edu    void writeSfsr(Addr a, bool write, ContextType ct,
2153804Ssaidi@eecs.umich.edu            bool se, FaultTypes ft, int asi);
2163826Ssaidi@eecs.umich.edu
2174070Ssaidi@eecs.umich.edu    uint64_t MakeTsbPtr(TsbPageSize ps, uint64_t tag_access, uint64_t c0_tsb,
2184070Ssaidi@eecs.umich.edu        uint64_t c0_config, uint64_t cX_tsb, uint64_t cX_config);
2194070Ssaidi@eecs.umich.edu
2204070Ssaidi@eecs.umich.edu
2213836Ssaidi@eecs.umich.edu    TlbEntry *cacheEntry[2];
2223836Ssaidi@eecs.umich.edu    ASI cacheAsi[2];
2233804Ssaidi@eecs.umich.edu};
2243804Ssaidi@eecs.umich.edu
2253468Sgblack@eecs.umich.edu}
2262650Ssaidi@eecs.umich.edu
2272650Ssaidi@eecs.umich.edu#endif // __ARCH_SPARC_TLB_HH__
228