14997Sgblack@eecs.umich.edu/*
25268Sksewell@umich.edu * Copyright (c) 2001-2005 The Regents of The University of Michigan
35222Sksewell@umich.edu * Copyright (c) 2007 MIPS Technologies, Inc.
44997Sgblack@eecs.umich.edu * All rights reserved.
54997Sgblack@eecs.umich.edu *
64997Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without
74997Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are
84997Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright
94997Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer;
104997Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright
114997Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the
124997Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution;
134997Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its
144997Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from
154997Sgblack@eecs.umich.edu * this software without specific prior written permission.
164997Sgblack@eecs.umich.edu *
174997Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
184997Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
194997Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
204997Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
214997Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
224997Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
234997Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
244997Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
254997Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
264997Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
274997Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
284997Sgblack@eecs.umich.edu *
295268Sksewell@umich.edu * Authors: Nathan Binkert
305268Sksewell@umich.edu *          Steve Reinhardt
315268Sksewell@umich.edu *          Jaidev Patwardhan
325268Sksewell@umich.edu *          Korey Sewell
334997Sgblack@eecs.umich.edu */
344997Sgblack@eecs.umich.edu
354997Sgblack@eecs.umich.edu#ifndef __ARCH_MIPS_TLB_HH__
364997Sgblack@eecs.umich.edu#define __ARCH_MIPS_TLB_HH__
374997Sgblack@eecs.umich.edu
385222Sksewell@umich.edu#include <map>
395222Sksewell@umich.edu
4010687SAndreas.Sandberg@ARM.com#include "arch/generic/tlb.hh"
415222Sksewell@umich.edu#include "arch/mips/isa_traits.hh"
428229Snate@binkert.org#include "arch/mips/pagetable.hh"
435222Sksewell@umich.edu#include "arch/mips/utility.hh"
445222Sksewell@umich.edu#include "arch/mips/vtophys.hh"
455222Sksewell@umich.edu#include "base/statistics.hh"
465222Sksewell@umich.edu#include "mem/request.hh"
476022Sgblack@eecs.umich.edu#include "params/MipsTLB.hh"
488229Snate@binkert.org#include "sim/sim_object.hh"
494997Sgblack@eecs.umich.edu
505222Sksewell@umich.educlass ThreadContext;
515222Sksewell@umich.edu
525222Sksewell@umich.edu/* MIPS does not distinguish between a DTLB and an ITLB -> unified TLB
535222Sksewell@umich.edu   However, to maintain compatibility with other architectures, we'll
545222Sksewell@umich.edu   simply create an ITLB and DTLB that will point to the real TLB */
555222Sksewell@umich.edunamespace MipsISA {
565222Sksewell@umich.edu
575358Sgblack@eecs.umich.educlass TLB : public BaseTLB
585222Sksewell@umich.edu{
595222Sksewell@umich.edu  protected:
605222Sksewell@umich.edu    typedef std::multimap<Addr, int> PageTable;
615543Ssaidi@eecs.umich.edu    PageTable lookupTable;      // Quick lookup into page table
625222Sksewell@umich.edu
635543Ssaidi@eecs.umich.edu    MipsISA::PTE *table;        // the Page Table
645543Ssaidi@eecs.umich.edu    int size;                   // TLB Size
655543Ssaidi@eecs.umich.edu    int nlu;                    // not last used entry (for replacement)
665222Sksewell@umich.edu
675222Sksewell@umich.edu    void nextnlu() { if (++nlu >= size) nlu = 0; }
685222Sksewell@umich.edu    MipsISA::PTE *lookup(Addr vpn, uint8_t asn) const;
695222Sksewell@umich.edu
705999Snate@binkert.org    mutable Stats::Scalar read_hits;
715999Snate@binkert.org    mutable Stats::Scalar read_misses;
725999Snate@binkert.org    mutable Stats::Scalar read_acv;
735999Snate@binkert.org    mutable Stats::Scalar read_accesses;
745999Snate@binkert.org    mutable Stats::Scalar write_hits;
755999Snate@binkert.org    mutable Stats::Scalar write_misses;
765999Snate@binkert.org    mutable Stats::Scalar write_acv;
775999Snate@binkert.org    mutable Stats::Scalar write_accesses;
785222Sksewell@umich.edu    Stats::Formula hits;
795222Sksewell@umich.edu    Stats::Formula misses;
805222Sksewell@umich.edu    Stats::Formula accesses;
815222Sksewell@umich.edu
825222Sksewell@umich.edu  public:
835222Sksewell@umich.edu    typedef MipsTLBParams Params;
845222Sksewell@umich.edu    TLB(const Params *p);
855222Sksewell@umich.edu
865222Sksewell@umich.edu    int probeEntry(Addr vpn,uint8_t) const;
875222Sksewell@umich.edu    MipsISA::PTE *getEntry(unsigned) const;
885222Sksewell@umich.edu    virtual ~TLB();
8910194SGeoffrey.Blake@arm.com
9011347Sandreas.hansson@arm.com    void takeOverFrom(BaseTLB *otlb) override {}
9110194SGeoffrey.Blake@arm.com
925222Sksewell@umich.edu    int smallPages;
935222Sksewell@umich.edu    int getsize() const { return size; }
945222Sksewell@umich.edu
955222Sksewell@umich.edu    MipsISA::PTE &index(bool advance = true);
965222Sksewell@umich.edu    void insert(Addr vaddr, MipsISA::PTE &pte);
975222Sksewell@umich.edu    void insertAt(MipsISA::PTE &pte, unsigned Index, int _smallPages);
9811347Sandreas.hansson@arm.com    void flushAll() override;
9911347Sandreas.hansson@arm.com    void demapPage(Addr vaddr, uint64_t asn) override
1005358Sgblack@eecs.umich.edu    {
1015358Sgblack@eecs.umich.edu        panic("demapPage unimplemented.\n");
1025358Sgblack@eecs.umich.edu    }
1035222Sksewell@umich.edu
1045222Sksewell@umich.edu    // static helper functions... really
1055222Sksewell@umich.edu    static bool validVirtualAddress(Addr vaddr);
1065222Sksewell@umich.edu
10712749Sgiacomo.travaglini@arm.com    static Fault checkCacheability(const RequestPtr &req);
1085222Sksewell@umich.edu
1095222Sksewell@umich.edu    // Checkpointing
11011168Sandreas.hansson@arm.com    void serialize(CheckpointOut &cp) const override;
11111168Sandreas.hansson@arm.com    void unserialize(CheckpointIn &cp) override;
1125222Sksewell@umich.edu
11311347Sandreas.hansson@arm.com    void regStats() override;
1145222Sksewell@umich.edu
11512406Sgabeblack@google.com    Fault translateAtomic(
11612749Sgiacomo.travaglini@arm.com            const RequestPtr &req, ThreadContext *tc, Mode mode) override;
11712406Sgabeblack@google.com    void translateTiming(
11812749Sgiacomo.travaglini@arm.com            const RequestPtr &req, ThreadContext *tc,
11912406Sgabeblack@google.com            Translation *translation, Mode mode) override;
12012406Sgabeblack@google.com    Fault finalizePhysical(
12112749Sgiacomo.travaglini@arm.com            const RequestPtr &req,
12212749Sgiacomo.travaglini@arm.com            ThreadContext *tc, Mode mode) const override;
1238888Sgeoffrey.blake@arm.com
1246022Sgblack@eecs.umich.edu  private:
12512749Sgiacomo.travaglini@arm.com    Fault translateInst(const RequestPtr &req, ThreadContext *tc);
12612749Sgiacomo.travaglini@arm.com    Fault translateData(const RequestPtr &req, ThreadContext *tc, bool write);
1275222Sksewell@umich.edu};
1285222Sksewell@umich.edu
1295222Sksewell@umich.edu}
1305222Sksewell@umich.edu
1315222Sksewell@umich.edu
1325222Sksewell@umich.edu
1335222Sksewell@umich.edu#endif // __MIPS_MEMORY_HH__
134