tlb.hh revision 3836
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"
373569Sgblack@eecs.umich.edu#include "mem/request.hh"
383468Sgblack@eecs.umich.edu#include "sim/faults.hh"
393569Sgblack@eecs.umich.edu#include "sim/sim_object.hh"
403468Sgblack@eecs.umich.edu
413468Sgblack@eecs.umich.educlass ThreadContext;
423806Ssaidi@eecs.umich.educlass Packet;
433468Sgblack@eecs.umich.edu
443468Sgblack@eecs.umich.edunamespace SparcISA
453468Sgblack@eecs.umich.edu{
463603Ssaidi@eecs.umich.edu
473804Ssaidi@eecs.umich.educlass TLB : public SimObject
483804Ssaidi@eecs.umich.edu{
493804Ssaidi@eecs.umich.edu  protected:
503804Ssaidi@eecs.umich.edu    TlbMap lookupTable;;
513804Ssaidi@eecs.umich.edu    typedef TlbMap::iterator MapIter;
523804Ssaidi@eecs.umich.edu
533804Ssaidi@eecs.umich.edu    TlbEntry *tlb;
543804Ssaidi@eecs.umich.edu
553804Ssaidi@eecs.umich.edu    int size;
563804Ssaidi@eecs.umich.edu    int usedEntries;
573804Ssaidi@eecs.umich.edu
583836Ssaidi@eecs.umich.edu    uint64_t cacheState;
593836Ssaidi@eecs.umich.edu    bool cacheValid;
603836Ssaidi@eecs.umich.edu
613804Ssaidi@eecs.umich.edu    enum FaultTypes {
623804Ssaidi@eecs.umich.edu        OtherFault = 0,
633804Ssaidi@eecs.umich.edu        PrivViolation = 0x1,
643804Ssaidi@eecs.umich.edu        SideEffect = 0x2,
653804Ssaidi@eecs.umich.edu        AtomicToIo = 0x4,
663804Ssaidi@eecs.umich.edu        IllegalAsi = 0x8,
673804Ssaidi@eecs.umich.edu        LoadFromNfo = 0x10,
683804Ssaidi@eecs.umich.edu        VaOutOfRange = 0x20,
693804Ssaidi@eecs.umich.edu        VaOutOfRangeJmp = 0x40
703468Sgblack@eecs.umich.edu    };
713468Sgblack@eecs.umich.edu
723804Ssaidi@eecs.umich.edu    enum ContextType {
733804Ssaidi@eecs.umich.edu        Primary = 0,
743804Ssaidi@eecs.umich.edu        Secondary = 1,
753804Ssaidi@eecs.umich.edu        Nucleus = 2
763468Sgblack@eecs.umich.edu    };
773468Sgblack@eecs.umich.edu
783804Ssaidi@eecs.umich.edu
793804Ssaidi@eecs.umich.edu    /** lookup an entry in the TLB based on the partition id, and real bit if
803804Ssaidi@eecs.umich.edu     * real is true or the partition id, and context id if real is false.
813804Ssaidi@eecs.umich.edu     * @param va the virtual address not shifted (e.g. bottom 13 bits are 0)
823804Ssaidi@eecs.umich.edu     * @param paritition_id partition this entry is for
833804Ssaidi@eecs.umich.edu     * @param real is this a real->phys or virt->phys translation
843804Ssaidi@eecs.umich.edu     * @param context_id if this is virt->phys what context
853804Ssaidi@eecs.umich.edu     * @return A pointer to a tlb entry
863804Ssaidi@eecs.umich.edu     */
873804Ssaidi@eecs.umich.edu    TlbEntry *lookup(Addr va, int partition_id, bool real, int context_id = 0);
883804Ssaidi@eecs.umich.edu
893804Ssaidi@eecs.umich.edu    /** Insert a PTE into the TLB. */
903804Ssaidi@eecs.umich.edu    void insert(Addr vpn, int partition_id, int context_id, bool real,
913826Ssaidi@eecs.umich.edu            const PageTableEntry& PTE, int entry = -1);
923804Ssaidi@eecs.umich.edu
933804Ssaidi@eecs.umich.edu    /** Given an entry id, read that tlb entries' tag. */
943804Ssaidi@eecs.umich.edu    uint64_t TagRead(int entry);
953804Ssaidi@eecs.umich.edu
963804Ssaidi@eecs.umich.edu    /** Give an entry id, read that tlb entries' tte */
973804Ssaidi@eecs.umich.edu    uint64_t TteRead(int entry);
983804Ssaidi@eecs.umich.edu
993804Ssaidi@eecs.umich.edu    /** Remove all entries from the TLB */
1003804Ssaidi@eecs.umich.edu    void invalidateAll();
1013804Ssaidi@eecs.umich.edu
1023804Ssaidi@eecs.umich.edu    /** Remove all non-locked entries from the tlb that match partition id. */
1033804Ssaidi@eecs.umich.edu    void demapAll(int partition_id);
1043804Ssaidi@eecs.umich.edu
1053804Ssaidi@eecs.umich.edu    /** Remove all entries that match a given context/partition id. */
1063804Ssaidi@eecs.umich.edu    void demapContext(int partition_id, int context_id);
1073804Ssaidi@eecs.umich.edu
1083804Ssaidi@eecs.umich.edu    /** Remve all entries that match a certain partition id, (contextid), and
1093804Ssaidi@eecs.umich.edu     * va). */
1103804Ssaidi@eecs.umich.edu    void demapPage(Addr va, int partition_id, bool real, int context_id);
1113804Ssaidi@eecs.umich.edu
1123804Ssaidi@eecs.umich.edu    /** Checks if the virtual address provided is a valid one. */
1133804Ssaidi@eecs.umich.edu    bool validVirtualAddress(Addr va, bool am);
1143804Ssaidi@eecs.umich.edu
1153804Ssaidi@eecs.umich.edu    void writeSfsr(ThreadContext *tc, int reg, bool write, ContextType ct,
1163804Ssaidi@eecs.umich.edu            bool se, FaultTypes ft, int asi);
1173804Ssaidi@eecs.umich.edu
1183804Ssaidi@eecs.umich.edu    void TLB::clearUsedBits();
1193804Ssaidi@eecs.umich.edu
1203804Ssaidi@eecs.umich.edu
1213826Ssaidi@eecs.umich.edu    void writeTagAccess(ThreadContext *tc, int reg, Addr va, int context);
1223826Ssaidi@eecs.umich.edu
1233804Ssaidi@eecs.umich.edu  public:
1243804Ssaidi@eecs.umich.edu    TLB(const std::string &name, int size);
1253804Ssaidi@eecs.umich.edu
1263826Ssaidi@eecs.umich.edu    void dumpAll();
1273826Ssaidi@eecs.umich.edu
1283804Ssaidi@eecs.umich.edu    // Checkpointing
1293804Ssaidi@eecs.umich.edu    virtual void serialize(std::ostream &os);
1303804Ssaidi@eecs.umich.edu    virtual void unserialize(Checkpoint *cp, const std::string &section);
1313804Ssaidi@eecs.umich.edu};
1323804Ssaidi@eecs.umich.edu
1333804Ssaidi@eecs.umich.educlass ITB : public TLB
1343804Ssaidi@eecs.umich.edu{
1353804Ssaidi@eecs.umich.edu  public:
1363804Ssaidi@eecs.umich.edu    ITB(const std::string &name, int size) : TLB(name, size)
1373468Sgblack@eecs.umich.edu    {
1383836Ssaidi@eecs.umich.edu        cacheEntry = NULL;
1393804Ssaidi@eecs.umich.edu    }
1403569Sgblack@eecs.umich.edu
1413804Ssaidi@eecs.umich.edu    Fault translate(RequestPtr &req, ThreadContext *tc);
1423804Ssaidi@eecs.umich.edu  private:
1433804Ssaidi@eecs.umich.edu    void writeSfsr(ThreadContext *tc, bool write, ContextType ct,
1443804Ssaidi@eecs.umich.edu            bool se, FaultTypes ft, int asi);
1453826Ssaidi@eecs.umich.edu    void writeTagAccess(ThreadContext *tc, Addr va, int context);
1463836Ssaidi@eecs.umich.edu    TlbEntry *cacheEntry;
1473826Ssaidi@eecs.umich.edu    friend class DTB;
1483804Ssaidi@eecs.umich.edu};
1493804Ssaidi@eecs.umich.edu
1503804Ssaidi@eecs.umich.educlass DTB : public TLB
1513804Ssaidi@eecs.umich.edu{
1523804Ssaidi@eecs.umich.edu  public:
1533804Ssaidi@eecs.umich.edu    DTB(const std::string &name, int size) : TLB(name, size)
1543804Ssaidi@eecs.umich.edu    {
1553836Ssaidi@eecs.umich.edu        cacheEntry[0] = NULL;
1563836Ssaidi@eecs.umich.edu        cacheEntry[1] = NULL;
1573804Ssaidi@eecs.umich.edu    }
1583804Ssaidi@eecs.umich.edu
1593804Ssaidi@eecs.umich.edu    Fault translate(RequestPtr &req, ThreadContext *tc, bool write);
1603806Ssaidi@eecs.umich.edu    Tick doMmuRegRead(ThreadContext *tc, Packet *pkt);
1613806Ssaidi@eecs.umich.edu    Tick doMmuRegWrite(ThreadContext *tc, Packet *pkt);
1623804Ssaidi@eecs.umich.edu
1633804Ssaidi@eecs.umich.edu  private:
1643804Ssaidi@eecs.umich.edu    void writeSfr(ThreadContext *tc, Addr a, bool write, ContextType ct,
1653804Ssaidi@eecs.umich.edu            bool se, FaultTypes ft, int asi);
1663826Ssaidi@eecs.umich.edu    void writeTagAccess(ThreadContext *tc, Addr va, int context);
1673826Ssaidi@eecs.umich.edu
1683836Ssaidi@eecs.umich.edu    TlbEntry *cacheEntry[2];
1693836Ssaidi@eecs.umich.edu    ASI cacheAsi[2];
1703804Ssaidi@eecs.umich.edu};
1713804Ssaidi@eecs.umich.edu
1723468Sgblack@eecs.umich.edu}
1732650Ssaidi@eecs.umich.edu
1742650Ssaidi@eecs.umich.edu#endif // __ARCH_SPARC_TLB_HH__
175