physical.cc (2738:5d7a31c7fa29) physical.cc (2914:2c524dc023d2)
1/*
2 * Copyright (c) 2001-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
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;

--- 12 unchanged lines hidden (view full) ---

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.
27 *
28 * Authors: Ron Dreslinski
1/*
2 * Copyright (c) 2001-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
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;

--- 12 unchanged lines hidden (view full) ---

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.
27 *
28 * Authors: Ron Dreslinski
29 * Ali Saidi
29 */
30
31#include <sys/types.h>
32#include <sys/mman.h>
33#include <errno.h>
34#include <fcntl.h>
35#include <unistd.h>
36#include <zlib.h>

--- 10 unchanged lines hidden (view full) ---

47#include "sim/builder.hh"
48#include "sim/eventq.hh"
49#include "arch/isa_traits.hh"
50
51
52using namespace std;
53using namespace TheISA;
54
30 */
31
32#include <sys/types.h>
33#include <sys/mman.h>
34#include <errno.h>
35#include <fcntl.h>
36#include <unistd.h>
37#include <zlib.h>

--- 10 unchanged lines hidden (view full) ---

48#include "sim/builder.hh"
49#include "sim/eventq.hh"
50#include "arch/isa_traits.hh"
51
52
53using namespace std;
54using namespace TheISA;
55
55PhysicalMemory::MemResponseEvent::MemResponseEvent(Packet *pkt, MemoryPort* _m)
56 : Event(&mainEventQueue, CPU_Tick_Pri), pkt(pkt), memoryPort(_m)
57{
58
56
59 this->setFlags(AutoDelete);
60}
61
62void
63PhysicalMemory::MemResponseEvent::process()
64{
65 memoryPort->sendTiming(pkt);
66}
67
68const char *
69PhysicalMemory::MemResponseEvent::description()
70{
71 return "Physical Memory Timing Access respnse event";
72}
73
74PhysicalMemory::PhysicalMemory(const string &n, Tick latency)
75 : MemObject(n),base_addr(0), pmem_addr(NULL), port(NULL), lat(latency)
76{
77 // Hardcoded to 128 MB for now.
78 pmem_size = 1 << 27;
79
80 if (pmem_size % TheISA::PageBytes != 0)
81 panic("Memory Size not divisible by page size\n");

--- 37 unchanged lines hidden (view full) ---

119
120int
121PhysicalMemory::deviceBlockSize()
122{
123 //Can accept anysize request
124 return 0;
125}
126
57PhysicalMemory::PhysicalMemory(const string &n, Tick latency)
58 : MemObject(n),base_addr(0), pmem_addr(NULL), port(NULL), lat(latency)
59{
60 // Hardcoded to 128 MB for now.
61 pmem_size = 1 << 27;
62
63 if (pmem_size % TheISA::PageBytes != 0)
64 panic("Memory Size not divisible by page size\n");

--- 37 unchanged lines hidden (view full) ---

102
103int
104PhysicalMemory::deviceBlockSize()
105{
106 //Can accept anysize request
107 return 0;
108}
109
127bool
128PhysicalMemory::doTimingAccess (Packet *pkt, MemoryPort* memoryPort)
129{
130 doFunctionalAccess(pkt);
131
110
132 // turn packet around to go back to requester
133 pkt->makeTimingResponse();
134 MemResponseEvent* response = new MemResponseEvent(pkt, memoryPort);
135 response->schedule(curTick + lat);
136
137 return true;
138}
139
140Tick
111Tick
141PhysicalMemory::doAtomicAccess(Packet *pkt)
142{
143 doFunctionalAccess(pkt);
144 return lat;
145}
146
147void
148PhysicalMemory::doFunctionalAccess(Packet *pkt)
149{
150 assert(pkt->getAddr() + pkt->getSize() < pmem_size);
151
152 switch (pkt->cmd) {
153 case Packet::ReadReq:
154 memcpy(pkt->getPtr<uint8_t>(),
155 pmem_addr + pkt->getAddr() - base_addr,

--- 9 unchanged lines hidden (view full) ---

165 pkt->req->setScResult(1);
166 }
167 break;
168 default:
169 panic("unimplemented");
170 }
171
172 pkt->result = Packet::Success;
112PhysicalMemory::doFunctionalAccess(Packet *pkt)
113{
114 assert(pkt->getAddr() + pkt->getSize() < pmem_size);
115
116 switch (pkt->cmd) {
117 case Packet::ReadReq:
118 memcpy(pkt->getPtr<uint8_t>(),
119 pmem_addr + pkt->getAddr() - base_addr,

--- 9 unchanged lines hidden (view full) ---

129 pkt->req->setScResult(1);
130 }
131 break;
132 default:
133 panic("unimplemented");
134 }
135
136 pkt->result = Packet::Success;
137 return lat;
173}
174
175Port *
176PhysicalMemory::getPort(const std::string &if_name, int idx)
177{
178 if (if_name == "port" && idx == -1) {
179 if (port != NULL)
180 panic("PhysicalMemory::getPort: additional port requested to memory!");

--- 9 unchanged lines hidden (view full) ---

190
191void
192PhysicalMemory::recvStatusChange(Port::Status status)
193{
194}
195
196PhysicalMemory::MemoryPort::MemoryPort(const std::string &_name,
197 PhysicalMemory *_memory)
138}
139
140Port *
141PhysicalMemory::getPort(const std::string &if_name, int idx)
142{
143 if (if_name == "port" && idx == -1) {
144 if (port != NULL)
145 panic("PhysicalMemory::getPort: additional port requested to memory!");

--- 9 unchanged lines hidden (view full) ---

155
156void
157PhysicalMemory::recvStatusChange(Port::Status status)
158{
159}
160
161PhysicalMemory::MemoryPort::MemoryPort(const std::string &_name,
162 PhysicalMemory *_memory)
198 : Port(_name), memory(_memory)
163 : SimpleTimingPort(_name), memory(_memory)
199{ }
200
201void
202PhysicalMemory::MemoryPort::recvStatusChange(Port::Status status)
203{
204 memory->recvStatusChange(status);
205}
206

--- 16 unchanged lines hidden (view full) ---

223PhysicalMemory::MemoryPort::deviceBlockSize()
224{
225 return memory->deviceBlockSize();
226}
227
228bool
229PhysicalMemory::MemoryPort::recvTiming(Packet *pkt)
230{
164{ }
165
166void
167PhysicalMemory::MemoryPort::recvStatusChange(Port::Status status)
168{
169 memory->recvStatusChange(status);
170}
171

--- 16 unchanged lines hidden (view full) ---

188PhysicalMemory::MemoryPort::deviceBlockSize()
189{
190 return memory->deviceBlockSize();
191}
192
193bool
194PhysicalMemory::MemoryPort::recvTiming(Packet *pkt)
195{
231 return memory->doTimingAccess(pkt, this);
196 assert(pkt->result != Packet::Nacked);
197
198 Tick latency = memory->doFunctionalAccess(pkt);
199
200 pkt->makeTimingResponse();
201 sendTiming(pkt, latency);
202
203 return true;
232}
233
234Tick
235PhysicalMemory::MemoryPort::recvAtomic(Packet *pkt)
236{
204}
205
206Tick
207PhysicalMemory::MemoryPort::recvAtomic(Packet *pkt)
208{
237 return memory->doAtomicAccess(pkt);
209 return memory->doFunctionalAccess(pkt);
238}
239
240void
241PhysicalMemory::MemoryPort::recvFunctional(Packet *pkt)
242{
243 memory->doFunctionalAccess(pkt);
244}
245
210}
211
212void
213PhysicalMemory::MemoryPort::recvFunctional(Packet *pkt)
214{
215 memory->doFunctionalAccess(pkt);
216}
217
218unsigned int
219PhysicalMemory::drain(Event *de)
220{
221 int count = port->drain(de);
222 if (count)
223 changeState(Draining);
224 else
225 changeState(Drained);
226 return count;
227}
246
228
247
248void
249PhysicalMemory::serialize(ostream &os)
250{
251 gzFile compressedMem;
252 string filename = name() + ".physmem";
253
254 SERIALIZE_SCALAR(pmem_size);
255 SERIALIZE_SCALAR(filename);

--- 123 unchanged lines hidden ---
229void
230PhysicalMemory::serialize(ostream &os)
231{
232 gzFile compressedMem;
233 string filename = name() + ".physmem";
234
235 SERIALIZE_SCALAR(pmem_size);
236 SERIALIZE_SCALAR(filename);

--- 123 unchanged lines hidden ---