00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef SIM_MEMORY_CACHE_CACHE_TYPES_H
00033 #define SIM_MEMORY_CACHE_CACHE_TYPES_H
00034
00035 #include "Sim/Op/OpArray/OpArray.h"
00036 #include "Sim/Pipeline/PipelineNodeIF.h"
00037 #include "Sim/Memory/AddrHasher.h"
00038
00039 namespace Onikiri
00040 {
00041 class Cache;
00042
00043 struct CacheLineValue
00044 {
00045
00046 };
00047
00048 typedef
00049 AdrHasher
00050 CacheHasher;
00051
00052 typedef
00053 std::pair<Addr, CacheLineValue>
00054 CachePair;
00055
00056 typedef
00057 shttl::setassoc_table<
00058 CachePair,
00059 CacheHasher,
00060 shttl::lru_list< Addr, u8 >
00061 >
00062 CacheTable;
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 typedef
00081 CacheTable::line_type
00082 CacheLine;
00083
00084 typedef
00085 CacheTable::iterator
00086 CacheTableIterator;
00087
00088 typedef
00089 CacheTable::const_iterator
00090 CacheTableConstIterator;
00091
00092
00093 struct CacheAccess : public MemAccess
00094 {
00095
00096 enum OperationType
00097 {
00098 OT_READ,
00099 OT_WRITE,
00100 OT_WRITE_BACK,
00101 OT_READ_FOR_WRITE_ALLOCATE,
00102 OT_PREFETCH
00103 };
00104 OperationType type;
00105 OpIterator op;
00106 CacheLineValue lineValue;
00107
00108 CacheAccess(
00109 const MemAccess& newMem = MemAccess(),
00110 OpIterator op = OpIterator(),
00111 OperationType newType = OT_READ,
00112 CacheLineValue newLineValue = CacheLineValue()
00113 ) :
00114 MemAccess( newMem ),
00115 type ( newType ),
00116 op ( op ),
00117 lineValue( newLineValue )
00118 {
00119 }
00120
00121 bool IsWirte() const
00122 {
00123 return type == OT_WRITE || type == OT_WRITE_BACK;
00124 }
00125 };
00126
00127
00128
00129 struct CacheAccessResult
00130 {
00131 int latency;
00132 enum State
00133 {
00134 ST_HIT,
00135 ST_PENDING_HIT,
00136 ST_MISS,
00137 ST_NOT_ACCESSED
00138 };
00139 State state;
00140 Cache* cache;
00141
00142
00143
00144 CacheTableIterator line;
00145
00146 CacheAccessResult(
00147 int newLatency = -1,
00148 State newState = ST_NOT_ACCESSED,
00149 Cache* newCache = NULL,
00150 CacheTableIterator newLine = CacheTableIterator()
00151 ) :
00152 latency( newLatency ),
00153 state ( newState ),
00154 cache ( newCache ),
00155 line ( newLine )
00156 {
00157 }
00158 };
00159
00160 enum CacheAccessEventType
00161 {
00162
00163
00164 CAET_FILL_FROM_NEXT_CACHE_FINISHED,
00165 CAET_FILL_FROM_MAL_FINISHED,
00166
00167
00168 CAET_WRITE_ALLOCATE_FINISHED,
00169 CAET_WRITE_ACCESS_FINISHED,
00170 CAET_READ_ACCESS_FINISHED
00171 };
00172
00173 struct CacheAccessNotificationParam
00174 {
00175 CacheAccessEventType type;
00176 CacheAccessResult result;
00177
00178 CacheAccessNotificationParam(
00179 const CacheAccessEventType newType = CAET_FILL_FROM_NEXT_CACHE_FINISHED,
00180 const CacheAccessResult& newResult = CacheAccessResult()
00181 ) :
00182 type( newType ),
00183 result( newResult )
00184 {
00185 }
00186 };
00187
00188 class CacheAccessNotifieeIF
00189 {
00190 public:
00191 virtual ~CacheAccessNotifieeIF(){};
00192
00193
00194 virtual void AccessFinished(
00195 const CacheAccess& access,
00196 const CacheAccessNotificationParam ¶m
00197 ) = 0;
00198 };
00199
00200
00201 struct CacheHookParam
00202 {
00203 const CacheAccess* access;
00204 const Addr* address;
00205 const CacheTable* table;
00206 CacheAccessNotifieeIF* notifiee;
00207 CacheAccessResult result;
00208 CacheTableConstIterator line;
00209 bool replaced;
00210 CacheHookParam() :
00211 access ( NULL ),
00212 address ( NULL ),
00213 table ( NULL ),
00214 notifiee( NULL ),
00215 replaced( false )
00216 {
00217 }
00218 };
00219
00220 };
00221
00222 #endif // __CACHEIF_H__
00223