PerfectCacheMemory.hh revision 6154
111666Stushar@ece.gatech.edu 211666Stushar@ece.gatech.edu/* 311666Stushar@ece.gatech.edu * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 411666Stushar@ece.gatech.edu * All rights reserved. 511666Stushar@ece.gatech.edu * 611666Stushar@ece.gatech.edu * Redistribution and use in source and binary forms, with or without 711666Stushar@ece.gatech.edu * modification, are permitted provided that the following conditions are 811666Stushar@ece.gatech.edu * met: redistributions of source code must retain the above copyright 911666Stushar@ece.gatech.edu * notice, this list of conditions and the following disclaimer; 1011666Stushar@ece.gatech.edu * redistributions in binary form must reproduce the above copyright 1111666Stushar@ece.gatech.edu * notice, this list of conditions and the following disclaimer in the 1211666Stushar@ece.gatech.edu * documentation and/or other materials provided with the distribution; 1311666Stushar@ece.gatech.edu * neither the name of the copyright holders nor the names of its 1411666Stushar@ece.gatech.edu * contributors may be used to endorse or promote products derived from 1511666Stushar@ece.gatech.edu * this software without specific prior written permission. 1611666Stushar@ece.gatech.edu * 1711666Stushar@ece.gatech.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1811666Stushar@ece.gatech.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1911666Stushar@ece.gatech.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2011666Stushar@ece.gatech.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2111666Stushar@ece.gatech.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2211666Stushar@ece.gatech.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2311666Stushar@ece.gatech.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2411666Stushar@ece.gatech.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2511666Stushar@ece.gatech.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2611666Stushar@ece.gatech.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2711666Stushar@ece.gatech.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2811666Stushar@ece.gatech.edu */ 2911666Stushar@ece.gatech.edu 3011666Stushar@ece.gatech.edu/* 3111666Stushar@ece.gatech.edu * PerfectCacheMemory.h 3211666Stushar@ece.gatech.edu * 3313665Sandreas.sandberg@arm.com * Description: 3413665Sandreas.sandberg@arm.com * 3513665Sandreas.sandberg@arm.com * $Id$ 3611666Stushar@ece.gatech.edu * 3711666Stushar@ece.gatech.edu */ 3811666Stushar@ece.gatech.edu 3911666Stushar@ece.gatech.edu#ifndef PERFECTCACHEMEMORY_H 4011666Stushar@ece.gatech.edu#define PERFECTCACHEMEMORY_H 4111666Stushar@ece.gatech.edu 4211666Stushar@ece.gatech.edu#include "mem/ruby/common/Global.hh" 4311666Stushar@ece.gatech.edu#include "mem/gems_common/Map.hh" 4411666Stushar@ece.gatech.edu#include "mem/protocol/AccessPermission.hh" 4511666Stushar@ece.gatech.edu#include "mem/ruby/config/RubyConfig.hh" 4611666Stushar@ece.gatech.edu#include "mem/ruby/common/Address.hh" 4711666Stushar@ece.gatech.edu#include "mem/ruby/slicc_interface/AbstractChip.hh" 4811666Stushar@ece.gatech.edu 4911762Sjieming.yin@amd.comtemplate<class ENTRY> 5011762Sjieming.yin@amd.comclass PerfectCacheLineState { 5111666Stushar@ece.gatech.edupublic: 5211666Stushar@ece.gatech.edu PerfectCacheLineState() { m_permission = AccessPermission_NUM; } 5311666Stushar@ece.gatech.edu AccessPermission m_permission; 5411666Stushar@ece.gatech.edu ENTRY m_entry; 5511666Stushar@ece.gatech.edu}; 5611666Stushar@ece.gatech.edu 5711666Stushar@ece.gatech.edutemplate<class ENTRY> 5811666Stushar@ece.gatech.educlass PerfectCacheMemory { 5911666Stushar@ece.gatech.edupublic: 6011666Stushar@ece.gatech.edu 6111666Stushar@ece.gatech.edu // Constructors 6211762Sjieming.yin@amd.com PerfectCacheMemory(AbstractChip* chip_ptr); 6311762Sjieming.yin@amd.com 6411666Stushar@ece.gatech.edu // Destructor 6511666Stushar@ece.gatech.edu //~PerfectCacheMemory(); 6611666Stushar@ece.gatech.edu 6711666Stushar@ece.gatech.edu // Public Methods 6811666Stushar@ece.gatech.edu 6911666Stushar@ece.gatech.edu static void printConfig(ostream& out); 7011666Stushar@ece.gatech.edu 7111666Stushar@ece.gatech.edu // perform a cache access and see if we hit or not. Return true on 7211666Stushar@ece.gatech.edu // a hit. 73 bool tryCacheAccess(const CacheMsg& msg, bool& block_stc, ENTRY*& entry); 74 75 // tests to see if an address is present in the cache 76 bool isTagPresent(const Address& address) const; 77 78 // Returns true if there is: 79 // a) a tag match on this address or there is 80 // b) an Invalid line in the same cache "way" 81 bool cacheAvail(const Address& address) const; 82 83 // find an Invalid entry and sets the tag appropriate for the address 84 void allocate(const Address& address); 85 86 void deallocate(const Address& address); 87 88 // Returns with the physical address of the conflicting cache line 89 Address cacheProbe(const Address& newAddress) const; 90 91 // looks an address up in the cache 92 ENTRY& lookup(const Address& address); 93 const ENTRY& lookup(const Address& address) const; 94 95 // Get/Set permission of cache block 96 AccessPermission getPermission(const Address& address) const; 97 void changePermission(const Address& address, AccessPermission new_perm); 98 99 // Print cache contents 100 void print(ostream& out) const; 101private: 102 // Private Methods 103 104 // Private copy constructor and assignment operator 105 PerfectCacheMemory(const PerfectCacheMemory& obj); 106 PerfectCacheMemory& operator=(const PerfectCacheMemory& obj); 107 108 // Data Members (m_prefix) 109 Map<Address, PerfectCacheLineState<ENTRY> > m_map; 110 AbstractChip* m_chip_ptr; 111}; 112 113// Output operator declaration 114//ostream& operator<<(ostream& out, const PerfectCacheMemory<ENTRY>& obj); 115 116// ******************* Definitions ******************* 117 118// Output operator definition 119template<class ENTRY> 120extern inline 121ostream& operator<<(ostream& out, const PerfectCacheMemory<ENTRY>& obj) 122{ 123 obj.print(out); 124 out << flush; 125 return out; 126} 127 128 129// **************************************************************** 130 131template<class ENTRY> 132extern inline 133PerfectCacheMemory<ENTRY>::PerfectCacheMemory(AbstractChip* chip_ptr) 134{ 135 m_chip_ptr = chip_ptr; 136} 137 138// STATIC METHODS 139 140template<class ENTRY> 141extern inline 142void PerfectCacheMemory<ENTRY>::printConfig(ostream& out) 143{ 144} 145 146// PUBLIC METHODS 147 148template<class ENTRY> 149extern inline 150bool PerfectCacheMemory<ENTRY>::tryCacheAccess(const CacheMsg& msg, bool& block_stc, ENTRY*& entry) 151{ 152 ERROR_MSG("not implemented"); 153} 154 155// tests to see if an address is present in the cache 156template<class ENTRY> 157extern inline 158bool PerfectCacheMemory<ENTRY>::isTagPresent(const Address& address) const 159{ 160 return m_map.exist(line_address(address)); 161} 162 163template<class ENTRY> 164extern inline 165bool PerfectCacheMemory<ENTRY>::cacheAvail(const Address& address) const 166{ 167 return true; 168} 169 170// find an Invalid or already allocated entry and sets the tag 171// appropriate for the address 172template<class ENTRY> 173extern inline 174void PerfectCacheMemory<ENTRY>::allocate(const Address& address) 175{ 176 PerfectCacheLineState<ENTRY> line_state; 177 line_state.m_permission = AccessPermission_Busy; 178 line_state.m_entry = ENTRY(); 179 m_map.add(line_address(address), line_state); 180} 181 182// deallocate entry 183template<class ENTRY> 184extern inline 185void PerfectCacheMemory<ENTRY>::deallocate(const Address& address) 186{ 187 m_map.erase(line_address(address)); 188} 189 190// Returns with the physical address of the conflicting cache line 191template<class ENTRY> 192extern inline 193Address PerfectCacheMemory<ENTRY>::cacheProbe(const Address& newAddress) const 194{ 195 ERROR_MSG("cacheProbe called in perfect cache"); 196} 197 198// looks an address up in the cache 199template<class ENTRY> 200extern inline 201ENTRY& PerfectCacheMemory<ENTRY>::lookup(const Address& address) 202{ 203 return m_map.lookup(line_address(address)).m_entry; 204} 205 206// looks an address up in the cache 207template<class ENTRY> 208extern inline 209const ENTRY& PerfectCacheMemory<ENTRY>::lookup(const Address& address) const 210{ 211 return m_map.lookup(line_address(address)).m_entry; 212} 213 214template<class ENTRY> 215extern inline 216AccessPermission PerfectCacheMemory<ENTRY>::getPermission(const Address& address) const 217{ 218 return m_map.lookup(line_address(address)).m_permission; 219} 220 221template<class ENTRY> 222extern inline 223void PerfectCacheMemory<ENTRY>::changePermission(const Address& address, AccessPermission new_perm) 224{ 225 Address line_address = address; 226 line_address.makeLineAddress(); 227 PerfectCacheLineState<ENTRY>& line_state = m_map.lookup(line_address); 228 AccessPermission old_perm = line_state.m_permission; 229 line_state.m_permission = new_perm; 230} 231 232template<class ENTRY> 233extern inline 234void PerfectCacheMemory<ENTRY>::print(ostream& out) const 235{ 236} 237 238#endif //PERFECTCACHEMEMORY_H 239