2 * Copyright (c) 2007 MIPS Technologies, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * Authors: Korey Sewell
32 #ifndef __CPU_INORDER_CACHE_UNIT_HH__
33 #define __CPU_INORDER_CACHE_UNIT_HH__
39 #include "arch/predecoder.hh"
40 #include "arch/tlb.hh"
41 #include "config/the_isa.hh"
42 #include "cpu/inorder/inorder_dyn_inst.hh"
43 #include "cpu/inorder/pipeline_traits.hh"
44 #include "cpu/inorder/resource.hh"
45 #include "mem/packet.hh"
46 #include "mem/packet_access.hh"
47 #include "mem/port.hh"
48 #include "params/InOrderCPU.hh"
49 #include "sim/sim_object.hh"
52 typedef CacheRequest* CacheReqPtr;
55 typedef CacheReqPacket* CacheReqPktPtr;
57 class CacheUnit : public Resource
60 typedef ThePipeline::DynInstPtr DynInstPtr;
63 CacheUnit(std::string res_name, int res_id, int res_width,
64 int res_latency, InOrderCPU *_cpu, ThePipeline::Params *params);
78 CompleteSecondSplitRead
82 /** CachePort class for the Cache Unit. Handles doing the
83 * communication with the cache/memory.
85 class CachePort : public Port
88 /** Pointer to cache port unit */
89 CacheUnit *cachePortUnit;
92 /** Default constructor. */
93 CachePort(CacheUnit *_cachePortUnit)
94 : Port(_cachePortUnit->name() + "-cache-port",
95 (MemObject*)_cachePortUnit->cpu),
96 cachePortUnit(_cachePortUnit)
102 /** Atomic version of receive. Panics. */
103 virtual Tick recvAtomic(PacketPtr pkt);
105 /** Functional version of receive. Panics. */
106 virtual void recvFunctional(PacketPtr pkt);
108 /** Receives status change. Other than range changing, panics. */
109 virtual void recvStatusChange(Status status);
111 /** Returns the address ranges of this device. */
112 virtual void getDeviceAddressRanges(AddrRangeList &resp,
113 AddrRangeList &snoop)
114 { resp.clear(); snoop.clear(); }
116 /** Timing version of receive. Handles setting fetch to the
117 * proper status to start fetching. */
118 virtual bool recvTiming(PacketPtr pkt);
120 /** Handles doing a retry of a failed fetch. */
121 virtual void recvRetry();
126 virtual ResourceRequest* getRequest(DynInstPtr _inst, int stage_num,
127 int res_idx, int slot_num,
130 ResReqPtr findRequest(DynInstPtr inst);
131 ResReqPtr findSplitRequest(DynInstPtr inst, int idx);
133 void requestAgain(DynInstPtr inst, bool &try_request);
135 int getSlot(DynInstPtr inst);
137 void freeSlot(int slot_num);
139 /** Execute the function of this resource. The Default is action
140 * is to do nothing. More specific models will derive from this
141 * class and define their own execute function.
143 void execute(int slot_num);
145 void squash(DynInstPtr inst, int stage_num,
146 InstSeqNum squash_seq_num, ThreadID tid);
148 void squashDueToMemStall(DynInstPtr inst, int stage_num,
149 InstSeqNum squash_seq_num, ThreadID tid);
151 /** Processes cache completion event. */
152 void processCacheCompletion(PacketPtr pkt);
156 /** Align a PC to the start of an I-cache block. */
157 Addr cacheBlockAlignPC(Addr addr)
159 return (addr & ~(cacheBlkMask));
162 /** Returns a specific port. */
163 Port *getPort(const std::string &if_name, int idx);
166 Fault read(DynInstPtr inst, Addr addr, T &data, unsigned flags);
169 Fault write(DynInstPtr inst, T data, Addr addr, unsigned flags,
172 Fault doTLBAccess(DynInstPtr inst, CacheReqPtr cache_req, int acc_size,
173 int flags, TheISA::TLB::Mode tlb_mode);
175 /** Read/Write on behalf of an instruction.
176 * curResSlot needs to be a valid value in instruction.
178 Fault doCacheAccess(DynInstPtr inst, uint64_t *write_result=NULL, CacheReqPtr split_req=NULL);
180 void prefetch(DynInstPtr inst);
182 void writeHint(DynInstPtr inst);
184 uint64_t getMemData(Packet *packet);
187 /** Cache interface. */
188 CachePort *cachePort;
190 bool cachePortBlocked;
192 std::vector<Addr> addrList[ThePipeline::MaxThreads];
194 std::map<Addr, InstSeqNum> addrMap[ThePipeline::MaxThreads];
201 /** Align a PC to the start of the Cache block. */
202 Addr cacheBlockAlign(Addr addr)
204 return (addr & ~(cacheBlkMask));
207 /** The mem line being fetched. */
208 uint8_t *fetchData[ThePipeline::MaxThreads];
210 /** @TODO: Move functionaly of fetching more than
211 one instruction to 'fetch unit'*/
212 /** The Addr of the cacheline that has been loaded. */
213 //Addr cacheBlockAddr[ThePipeline::MaxThreads];
214 //unsigned fetchOffset[ThePipeline::MaxThreads];
216 TheISA::Predecoder predecoder;
218 bool tlbBlocked[ThePipeline::MaxThreads];
225 class CacheUnitEvent : public ResourceEvent {
227 const std::string name() const
229 return "CacheUnitEvent";
233 /** Constructs a resource event. */
235 virtual ~CacheUnitEvent() {}
237 /** Processes a resource event. */
238 virtual void process();
241 class CacheRequest : public ResourceRequest
244 CacheRequest(CacheUnit *cres, DynInstPtr inst, int stage_num, int res_idx,
245 int slot_num, unsigned cmd, int req_size,
246 MemCmd::Command pkt_cmd, unsigned flags, int cpu_id, int idx)
247 : ResourceRequest(cres, inst, stage_num, res_idx, slot_num, cmd),
248 pktCmd(pkt_cmd), memReq(NULL), reqData(NULL), dataPkt(NULL),
249 retryPkt(NULL), memAccComplete(false), memAccPending(false),
250 tlbStall(false), splitAccess(false), splitAccessNum(-1),
251 split2ndAccess(false), instIdx(idx)
255 virtual ~CacheRequest()
257 if (reqData && !splitAccess) {
262 virtual PacketDataPtr getData()
266 setMemAccCompleted(bool completed = true)
268 memAccComplete = completed;
273 return split2ndAccess;
276 bool isMemAccComplete() { return memAccComplete; }
278 void setMemAccPending(bool pending = true) { memAccPending = pending; }
279 bool isMemAccPending() { return memAccPending; }
281 //Make this data private/protected!
282 MemCmd::Command pktCmd;
284 PacketDataPtr reqData;
299 class CacheReqPacket : public Packet
302 CacheReqPacket(CacheRequest *_req,
303 Command _cmd, short _dest, int _idx = 0)
304 : Packet(_req->memReq, _cmd, _dest), cacheReq(_req), instIdx(_idx)
309 CacheRequest *cacheReq;
314 #endif //__CPU_CACHE_UNIT_HH__