tlb.hh revision 12334
112855Sgabeblack@google.com/* 212855Sgabeblack@google.com * Copyright (c) 2006 The Regents of The University of Michigan 312855Sgabeblack@google.com * All rights reserved. 412855Sgabeblack@google.com * 512855Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 612855Sgabeblack@google.com * modification, are permitted provided that the following conditions are 712855Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 812855Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 912855Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 1012855Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1112855Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1212855Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1312855Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1412855Sgabeblack@google.com * this software without specific prior written permission. 1512855Sgabeblack@google.com * 1612855Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1712855Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1812855Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1912855Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2012855Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2112855Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2212855Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2312855Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2412855Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2512855Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2612855Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2712855Sgabeblack@google.com * 2812855Sgabeblack@google.com * Authors: Ali Saidi 2912855Sgabeblack@google.com */ 3012855Sgabeblack@google.com 3112855Sgabeblack@google.com#ifndef __ARCH_SPARC_TLB_HH__ 3212855Sgabeblack@google.com#define __ARCH_SPARC_TLB_HH__ 3312855Sgabeblack@google.com 3412855Sgabeblack@google.com#include "arch/generic/tlb.hh" 3512855Sgabeblack@google.com#include "arch/sparc/asi.hh" 3612855Sgabeblack@google.com#include "arch/sparc/tlb_map.hh" 3712855Sgabeblack@google.com#include "base/logging.hh" 3812855Sgabeblack@google.com#include "mem/request.hh" 3912855Sgabeblack@google.com#include "params/SparcTLB.hh" 4012855Sgabeblack@google.com 4112855Sgabeblack@google.comclass ThreadContext; 4212855Sgabeblack@google.comclass Packet; 4312855Sgabeblack@google.com 4412855Sgabeblack@google.comnamespace SparcISA 4512855Sgabeblack@google.com{ 4612855Sgabeblack@google.com 4712855Sgabeblack@google.comclass TLB : public BaseTLB 4812855Sgabeblack@google.com{ 4912855Sgabeblack@google.com // These faults need to be able to populate the tlb in SE mode. 5012855Sgabeblack@google.com friend class FastInstructionAccessMMUMiss; 5112855Sgabeblack@google.com friend class FastDataAccessMMUMiss; 5212855Sgabeblack@google.com 5312855Sgabeblack@google.com // TLB state 5412855Sgabeblack@google.com protected: 5512855Sgabeblack@google.com // Only used when this is the data TLB. 5612855Sgabeblack@google.com uint64_t sfar; 5712855Sgabeblack@google.com uint64_t c0_tsb_ps0; 5812855Sgabeblack@google.com uint64_t c0_tsb_ps1; 5912855Sgabeblack@google.com uint64_t c0_config; 6012855Sgabeblack@google.com uint64_t cx_tsb_ps0; 6112855Sgabeblack@google.com uint64_t cx_tsb_ps1; 6212855Sgabeblack@google.com uint64_t cx_config; 6312855Sgabeblack@google.com uint64_t sfsr; 6412855Sgabeblack@google.com uint64_t tag_access; 6512855Sgabeblack@google.com 6612855Sgabeblack@google.com protected: 6712855Sgabeblack@google.com TlbMap lookupTable;; 6812855Sgabeblack@google.com typedef TlbMap::iterator MapIter; 6912855Sgabeblack@google.com 7012855Sgabeblack@google.com TlbEntry *tlb; 71 72 int size; 73 int usedEntries; 74 int lastReplaced; 75 76 uint64_t cacheState; 77 bool cacheValid; 78 79 std::list<TlbEntry*> freeList; 80 81 enum FaultTypes { 82 OtherFault = 0, 83 PrivViolation = 0x1, 84 SideEffect = 0x2, 85 AtomicToIo = 0x4, 86 IllegalAsi = 0x8, 87 LoadFromNfo = 0x10, 88 VaOutOfRange = 0x20, 89 VaOutOfRangeJmp = 0x40 90 }; 91 92 enum ContextType { 93 Primary = 0, 94 Secondary = 1, 95 Nucleus = 2 96 }; 97 98 enum TsbPageSize { 99 Ps0, 100 Ps1 101 }; 102 public: 103 /** lookup an entry in the TLB based on the partition id, and real bit if 104 * real is true or the partition id, and context id if real is false. 105 * @param va the virtual address not shifted (e.g. bottom 13 bits are 0) 106 * @param paritition_id partition this entry is for 107 * @param real is this a real->phys or virt->phys translation 108 * @param context_id if this is virt->phys what context 109 * @param update_used should ew update the used bits in the 110 * entries on not useful if we are trying to do a va->pa without 111 * mucking with any state for a debug read for example. 112 * @return A pointer to a tlb entry 113 */ 114 TlbEntry *lookup(Addr va, int partition_id, bool real, int context_id = 0, 115 bool update_used = true); 116 117 /** Remove all entries from the TLB */ 118 void flushAll() override; 119 120 protected: 121 /** Insert a PTE into the TLB. */ 122 void insert(Addr vpn, int partition_id, int context_id, bool real, 123 const PageTableEntry& PTE, int entry = -1); 124 125 /** Given an entry id, read that tlb entries' tag. */ 126 uint64_t TagRead(int entry); 127 128 /** Remove all non-locked entries from the tlb that match partition id. */ 129 void demapAll(int partition_id); 130 131 /** Remove all entries that match a given context/partition id. */ 132 void demapContext(int partition_id, int context_id); 133 134 /** Remve all entries that match a certain partition id, (contextid), and 135 * va). */ 136 void demapPage(Addr va, int partition_id, bool real, int context_id); 137 138 /** Checks if the virtual address provided is a valid one. */ 139 bool validVirtualAddress(Addr va, bool am); 140 141 void writeSfsr(bool write, ContextType ct, 142 bool se, FaultTypes ft, int asi); 143 144 void clearUsedBits(); 145 146 147 void writeTagAccess(Addr va, int context); 148 149 Fault translateInst(RequestPtr req, ThreadContext *tc); 150 Fault translateData(RequestPtr req, ThreadContext *tc, bool write); 151 152 public: 153 typedef SparcTLBParams Params; 154 TLB(const Params *p); 155 156 void takeOverFrom(BaseTLB *otlb) override {} 157 158 void 159 demapPage(Addr vaddr, uint64_t asn) override 160 { 161 panic("demapPage(Addr) is not implemented.\n"); 162 } 163 164 void dumpAll(); 165 166 Fault translateAtomic(RequestPtr req, ThreadContext *tc, Mode mode); 167 void translateTiming(RequestPtr req, ThreadContext *tc, 168 Translation *translation, Mode mode); 169 /** Stub function for compilation support with CheckerCPU. SPARC ISA 170 * does not support the Checker model at the moment 171 */ 172 Fault translateFunctional(RequestPtr req, ThreadContext *tc, Mode mode); 173 Fault finalizePhysical(RequestPtr req, ThreadContext *tc, Mode mode) const; 174 Cycles doMmuRegRead(ThreadContext *tc, Packet *pkt); 175 Cycles doMmuRegWrite(ThreadContext *tc, Packet *pkt); 176 void GetTsbPtr(ThreadContext *tc, Addr addr, int ctx, Addr *ptrs); 177 178 // Checkpointing 179 void serialize(CheckpointOut &cp) const override; 180 void unserialize(CheckpointIn &cp) override; 181 182 /** Give an entry id, read that tlb entries' tte */ 183 uint64_t TteRead(int entry); 184 185 private: 186 void writeSfsr(Addr a, bool write, ContextType ct, 187 bool se, FaultTypes ft, int asi); 188 189 uint64_t MakeTsbPtr(TsbPageSize ps, uint64_t tag_access, uint64_t c0_tsb, 190 uint64_t c0_config, uint64_t cX_tsb, uint64_t cX_config); 191 192 193 TlbEntry *cacheEntry[2]; 194 ASI cacheAsi[2]; 195}; 196 197} 198 199#endif // __ARCH_SPARC_TLB_HH__ 200