2 * Copyright (c) 2004 The Regents of The University of Michigan
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.
30 * Emulation of the Tsunami CChip CSRs
37 #include "base/trace.hh"
38 #include "dev/tsunami_cchip.hh"
39 #include "dev/tsunamireg.h"
40 #include "dev/tsunami.hh"
41 #include "mem/bus/bus.hh"
42 #include "mem/bus/pio_interface.hh"
43 #include "mem/bus/pio_interface_impl.hh"
44 #include "mem/functional_mem/memory_control.hh"
45 #include "cpu/intr_control.hh"
46 #include "sim/builder.hh"
47 #include "sim/system.hh"
51 TsunamiCChip::TsunamiCChip(const string
&name
, Tsunami
*t
, Addr a
,
52 MemoryController
*mmu
, HierParams
*hier
, Bus
* bus
,
54 : PioDevice(name
), addr(a
), tsunami(t
)
56 mmu
->add_child(this, RangeSize(addr
, size
));
58 for(int i
=0; i
< Tsunami::Max_CPUs
; i
++) {
61 dirInterrupting
[i
] = false;
62 ipiInterrupting
[i
] = false;
63 RTCInterrupting
[i
] = false;
67 pioInterface
= newPioInterface(name
, hier
, bus
, this,
68 &TsunamiCChip::cacheAccess
);
69 pioInterface
->addAddrRange(RangeSize(addr
, size
));
70 pioLatency
= pio_latency
* bus
->clockRatio
;
76 //Put back pointer in tsunami
77 tsunami
->cchip
= this;
81 TsunamiCChip::read(MemReqPtr
&req
, uint8_t *data
)
83 DPRINTF(Tsunami
, "read va=%#x size=%d\n",
84 req
->vaddr
, req
->size
);
86 Addr daddr
= (req
->paddr
- (addr
& EV5::PAddrImplMask
)) >> 6;
87 ExecContext
*xc
= req
->xc
;
91 case sizeof(uint64_t):
94 *(uint64_t*)data
= 0x0;
97 panic("TSDEV_CC_MTR not implemeted\n");
100 *(uint64_t*)data
= misc
| (xc
->cpu_id
& 0x3);
106 *(uint64_t*)data
= 0;
109 *(uint64_t*)data
= dim
[0];
112 *(uint64_t*)data
= dim
[1];
115 *(uint64_t*)data
= dim
[2];
118 *(uint64_t*)data
= dim
[3];
121 *(uint64_t*)data
= dir
[0];
124 *(uint64_t*)data
= dir
[1];
127 *(uint64_t*)data
= dir
[2];
130 *(uint64_t*)data
= dir
[3];
133 *(uint64_t*)data
= drir
;
136 panic("TSDEV_CC_PRBEN not implemented\n");
142 panic("TSDEV_CC_IICx not implemented\n");
148 panic("TSDEV_CC_MPRx not implemented\n");
151 panic("default in cchip read reached, accessing 0x%x\n");
155 case sizeof(uint32_t):
156 case sizeof(uint16_t):
157 case sizeof(uint8_t):
159 panic("invalid access size(?) for tsunami register!\n");
161 DPRINTFN("Tsunami CChip ERROR: read daddr=%#x size=%d\n", daddr
, req
->size
);
167 TsunamiCChip::write(MemReqPtr
&req
, const uint8_t *data
)
169 DPRINTF(Tsunami
, "write - va=%#x value=%#x size=%d \n",
170 req
->vaddr
, *(uint64_t*)data
, req
->size
);
172 Addr daddr
= (req
->paddr
- (addr
& EV5::PAddrImplMask
)) >> 6;
174 bool supportedWrite
= false;
175 uint64_t size
= tsunami
->intrctrl
->cpu
->system
->execContexts
.size();
179 case sizeof(uint64_t):
182 panic("TSDEV_CC_CSR write\n");
185 panic("TSDEV_CC_MTR write not implemented\n");
189 ipreq
= (*(uint64_t*)data
>> 12) & 0xF;
190 //If it is bit 12-15, this is an IPI post
192 for (int cpunum
=0; cpunum
< Tsunami::Max_CPUs
; cpunum
++) {
193 // Check each cpu bit
194 if (ipreq
& (1 << cpunum
)) {
195 // Check if there is already an ipi (bits 8:11)
196 if (!(misc
& (0x100 << cpunum
))) {
197 misc
|= (0x100 << cpunum
);
198 tsunami
->intrctrl
->post(cpunum
,
199 TheISA::INTLEVEL_IRQ3
, 0);
200 DPRINTF(IPI
, "send IPI cpu=%d from=%d\n",
201 cpunum
, req
->cpu_num
);
205 supportedWrite
= true;
208 //If it is bit 8-11, this is an IPI clear
210 ipintr
= (*(uint64_t*)data
>> 8) & 0xF;
212 for (int cpunum
=0; cpunum
< Tsunami::Max_CPUs
; cpunum
++) {
213 // Check each cpu bit
214 if (ipintr
& (1 << cpunum
)) {
215 // Check if there is a pending ipi (bits 8:11)
216 if (misc
& (0x100 << cpunum
)) {
217 misc
&= ~(0x100 << cpunum
);
218 tsunami
->intrctrl
->clear(cpunum
,
219 TheISA::INTLEVEL_IRQ3
, 0);
220 DPRINTF(IPI
, "clear IPI IPI cpu=%d from=%d\n",
221 cpunum
, req
->cpu_num
);
225 supportedWrite
= true;
230 //If it is the 4-7th bit, clear the RTC interrupt
232 if ((itintr
= (*(uint64_t*) data
) & (0xf<<4))) {
233 //Clear the bits in ITINTR
235 for (int i
=0; i
< size
; i
++) {
236 if ((itintr
& (1 << (i
+4))) && RTCInterrupting
[i
]) {
237 tsunami
->intrctrl
->clear(i
, TheISA::INTLEVEL_IRQ2
, 0);
238 RTCInterrupting
[i
] = false;
239 DPRINTF(Tsunami
, "clearing rtc interrupt to cpu=%d\n", i
);
242 supportedWrite
= true;
246 if (*(uint64_t*)data
& 0x10000000)
247 supportedWrite
= true;
250 panic("TSDEV_CC_MISC write not implemented\n");
257 panic("TSDEV_CC_AARx write not implemeted\n");
264 if(daddr
== TSDEV_CC_DIM0
)
266 else if(daddr
== TSDEV_CC_DIM1
)
268 else if(daddr
== TSDEV_CC_DIM2
)
277 olddim
= dim
[number
];
278 olddir
= dir
[number
];
279 dim
[number
] = *(uint64_t*)data
;
280 dir
[number
] = dim
[number
] & drir
;
281 for(int x
= 0; x
< 64; x
++)
283 bitvector
= (uint64_t)1 << x
;
284 // Figure out which bits have changed
285 if ((dim
[number
] & bitvector
) != (olddim
& bitvector
))
287 // The bit is now set and it wasn't before (set)
288 if((dim
[number
] & bitvector
) && (dir
[number
] & bitvector
))
290 tsunami
->intrctrl
->post(number
, TheISA::INTLEVEL_IRQ1
, x
);
291 DPRINTF(Tsunami
, "posting dir interrupt to cpu 0\n");
293 else if ((olddir
& bitvector
) &&
294 !(dir
[number
] & bitvector
))
296 // The bit was set and now its now clear and
297 // we were interrupting on that bit before
298 tsunami
->intrctrl
->clear(number
, TheISA::INTLEVEL_IRQ1
, x
);
299 DPRINTF(Tsunami
, "dim write resulting in clear"
300 "dir interrupt to cpu 0\n");
312 panic("TSDEV_CC_DIR write not implemented\n");
314 panic("TSDEV_CC_DRIR write not implemented\n");
316 panic("TSDEV_CC_PRBEN write not implemented\n");
321 panic("TSDEV_CC_IICx write not implemented\n");
326 panic("TSDEV_CC_MPRx write not implemented\n");
328 panic("default in cchip read reached, accessing 0x%x\n");
332 case sizeof(uint32_t):
333 case sizeof(uint16_t):
334 case sizeof(uint8_t):
336 panic("invalid access size(?) for tsunami register!\n");
339 DPRINTFN("Tsunami ERROR: write daddr=%#x size=%d\n", daddr
, req
->size
);
345 TsunamiCChip::postRTC()
347 int size
= tsunami
->intrctrl
->cpu
->system
->execContexts
.size();
349 for (int i
= 0; i
< size
; i
++) {
350 if (!RTCInterrupting
[i
]) {
352 RTCInterrupting
[i
] = true;
353 tsunami
->intrctrl
->post(i
, TheISA::INTLEVEL_IRQ2
, 0);
354 DPRINTF(Tsunami
, "Posting RTC interrupt to cpu=%d", i
);
361 TsunamiCChip::postDRIR(uint32_t interrupt
)
363 uint64_t bitvector
= (uint64_t)0x1 << interrupt
;
365 uint64_t size
= tsunami
->intrctrl
->cpu
->system
->execContexts
.size();
366 for(int i
=0; i
< size
; i
++) {
367 dir
[i
] = dim
[i
] & drir
;
368 if (dim
[i
] & bitvector
) {
369 tsunami
->intrctrl
->post(i
, TheISA::INTLEVEL_IRQ1
, interrupt
);
370 DPRINTF(Tsunami
, "posting dir interrupt to cpu %d,"
371 "interrupt %d\n",i
, interrupt
);
377 TsunamiCChip::clearDRIR(uint32_t interrupt
)
379 uint64_t bitvector
= (uint64_t)0x1 << interrupt
;
380 uint64_t size
= tsunami
->intrctrl
->cpu
->system
->execContexts
.size();
381 if (drir
& bitvector
)
384 for(int i
=0; i
< size
; i
++) {
385 if (dir
[i
] & bitvector
) {
386 tsunami
->intrctrl
->clear(i
, TheISA::INTLEVEL_IRQ1
, interrupt
);
387 DPRINTF(Tsunami
, "clearing dir interrupt to cpu %d,"
388 "interrupt %d\n",i
, interrupt
);
391 dir
[i
] = dim
[i
] & drir
;
395 DPRINTF(Tsunami
, "Spurrious clear? interrupt %d\n", interrupt
);
399 TsunamiCChip::cacheAccess(MemReqPtr
&req
)
401 return curTick
+ pioLatency
;
406 TsunamiCChip::serialize(std::ostream
&os
)
408 SERIALIZE_ARRAY(dim
, Tsunami::Max_CPUs
);
409 SERIALIZE_ARRAY(dir
, Tsunami::Max_CPUs
);
410 SERIALIZE_ARRAY(dirInterrupting
, Tsunami::Max_CPUs
);
411 SERIALIZE_ARRAY(ipiInterrupting
, Tsunami::Max_CPUs
);
412 SERIALIZE_SCALAR(drir
);
413 SERIALIZE_SCALAR(misc
);
414 SERIALIZE_ARRAY(RTCInterrupting
, Tsunami::Max_CPUs
);
418 TsunamiCChip::unserialize(Checkpoint
*cp
, const std::string
§ion
)
420 UNSERIALIZE_ARRAY(dim
, Tsunami::Max_CPUs
);
421 UNSERIALIZE_ARRAY(dir
, Tsunami::Max_CPUs
);
422 UNSERIALIZE_ARRAY(dirInterrupting
, Tsunami::Max_CPUs
);
423 UNSERIALIZE_ARRAY(ipiInterrupting
, Tsunami::Max_CPUs
);
424 UNSERIALIZE_SCALAR(drir
);
425 UNSERIALIZE_SCALAR(misc
);
426 UNSERIALIZE_ARRAY(RTCInterrupting
, Tsunami::Max_CPUs
);
429 BEGIN_DECLARE_SIM_OBJECT_PARAMS(TsunamiCChip
)
431 SimObjectParam
<Tsunami
*> tsunami
;
432 SimObjectParam
<MemoryController
*> mmu
;
434 SimObjectParam
<Bus
*> io_bus
;
435 Param
<Tick
> pio_latency
;
436 SimObjectParam
<HierParams
*> hier
;
438 END_DECLARE_SIM_OBJECT_PARAMS(TsunamiCChip
)
440 BEGIN_INIT_SIM_OBJECT_PARAMS(TsunamiCChip
)
442 INIT_PARAM(tsunami
, "Tsunami"),
443 INIT_PARAM(mmu
, "Memory Controller"),
444 INIT_PARAM(addr
, "Device Address"),
445 INIT_PARAM_DFLT(io_bus
, "The IO Bus to attach to", NULL
),
446 INIT_PARAM_DFLT(pio_latency
, "Programmed IO latency in bus cycles", 1),
447 INIT_PARAM_DFLT(hier
, "Hierarchy global variables", &defaultHierParams
)
449 END_INIT_SIM_OBJECT_PARAMS(TsunamiCChip
)
451 CREATE_SIM_OBJECT(TsunamiCChip
)
453 return new TsunamiCChip(getInstanceName(), tsunami
, addr
, mmu
, hier
,
454 io_bus
, pio_latency
);
457 REGISTER_SIM_OBJECT("TsunamiCChip", TsunamiCChip
)