2 * Copyright (c) 2004-2005 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.
33 * Emulation of the Tsunami CChip CSRs
40 #include "arch/alpha/ev5.hh"
41 #include "base/trace.hh"
42 #include "config/the_isa.hh"
43 #include "cpu/intr_control.hh"
44 #include "cpu/thread_context.hh"
45 #include "debug/IPI.hh"
46 #include "debug/Tsunami.hh"
47 #include "dev/alpha/tsunami.hh"
48 #include "dev/alpha/tsunami_cchip.hh"
49 #include "dev/alpha/tsunamireg.h"
50 #include "mem/packet.hh"
51 #include "mem/packet_access.hh"
52 #include "mem/port.hh"
53 #include "params/TsunamiCChip.hh"
54 #include "sim/system.hh"
56 //Should this be AlphaISA?
57 using namespace TheISA
;
59 TsunamiCChip::TsunamiCChip(const Params
*p
)
60 : BasicPioDevice(p
), tsunami(p
->tsunami
)
68 for (int x
= 0; x
< Tsunami::Max_CPUs
; x
++)
74 //Put back pointer in tsunami
75 tsunami
->cchip
= this;
79 TsunamiCChip::read(PacketPtr pkt
)
81 DPRINTF(Tsunami
, "read va=%#x size=%d\n", pkt
->getAddr(), pkt
->getSize());
83 assert(pkt
->getAddr() >= pioAddr
&& pkt
->getAddr() < pioAddr
+ pioSize
);
85 Addr regnum
= (pkt
->getAddr() - pioAddr
) >> 6;
86 Addr daddr
= (pkt
->getAddr() - pioAddr
);
89 switch (pkt
->getSize()) {
91 case sizeof(uint64_t):
92 pkt
->set
<uint64_t>(0);
94 if (daddr
& TSDEV_CC_BDIMS
)
96 pkt
->set(dim
[(daddr
>> 4) & 0x3F]);
100 if (daddr
& TSDEV_CC_BDIRS
)
102 pkt
->set(dir
[(daddr
>> 4) & 0x3F]);
111 panic("TSDEV_CC_MTR not implemeted\n");
114 pkt
->set(((ipint
<< 8) & 0xF) | ((itint
<< 4) & 0xF) |
115 (pkt
->req
->contextId() & 0x3));
116 // currently, FS cannot handle MT so contextId and
117 // cpuId are effectively the same, don't know if it will
118 // matter if FS becomes MT enabled. I suspect no because
119 // we are currently able to boot up to 64 procs anyway
120 // which would render the CPUID of this register useless
157 panic("TSDEV_CC_PRBEN not implemented\n");
163 panic("TSDEV_CC_IICx not implemented\n");
169 panic("TSDEV_CC_MPRx not implemented\n");
178 panic("default in cchip read reached, accessing 0x%x\n");
182 case sizeof(uint32_t):
183 case sizeof(uint16_t):
184 case sizeof(uint8_t):
186 panic("invalid access size(?) for tsunami register!\n");
188 DPRINTF(Tsunami
, "Tsunami CChip: read regnum=%#x size=%d data=%lld\n",
189 regnum
, pkt
->getSize(), pkt
->get
<uint64_t>());
191 pkt
->makeAtomicResponse();
196 TsunamiCChip::write(PacketPtr pkt
)
198 assert(pkt
->getAddr() >= pioAddr
&& pkt
->getAddr() < pioAddr
+ pioSize
);
199 Addr daddr
= pkt
->getAddr() - pioAddr
;
200 Addr regnum
= (pkt
->getAddr() - pioAddr
) >> 6 ;
203 assert(pkt
->getSize() == sizeof(uint64_t));
205 DPRINTF(Tsunami
, "write - addr=%#x value=%#x\n", pkt
->getAddr(), pkt
->get
<uint64_t>());
207 bool supportedWrite
= false;
210 if (daddr
& TSDEV_CC_BDIMS
)
212 int number
= (daddr
>> 4) & 0x3F;
218 olddim
= dim
[number
];
219 olddir
= dir
[number
];
220 dim
[number
] = pkt
->get
<uint64_t>();
221 dir
[number
] = dim
[number
] & drir
;
222 for(int x
= 0; x
< Tsunami::Max_CPUs
; x
++)
224 bitvector
= ULL(1) << x
;
225 // Figure out which bits have changed
226 if ((dim
[number
] & bitvector
) != (olddim
& bitvector
))
228 // The bit is now set and it wasn't before (set)
229 if((dim
[number
] & bitvector
) && (dir
[number
] & bitvector
))
231 tsunami
->intrctrl
->post(number
, TheISA::INTLEVEL_IRQ1
, x
);
232 DPRINTF(Tsunami
, "dim write resulting in posting dir"
233 " interrupt to cpu %d\n", number
);
235 else if ((olddir
& bitvector
) &&
236 !(dir
[number
] & bitvector
))
238 // The bit was set and now its now clear and
239 // we were interrupting on that bit before
240 tsunami
->intrctrl
->clear(number
, TheISA::INTLEVEL_IRQ1
, x
);
241 DPRINTF(Tsunami
, "dim write resulting in clear"
242 " dir interrupt to cpu %d\n", number
);
252 panic("TSDEV_CC_CSR write\n");
254 panic("TSDEV_CC_MTR write not implemented\n");
257 ipreq
= (pkt
->get
<uint64_t>() >> 12) & 0xF;
258 //If it is bit 12-15, this is an IPI post
261 supportedWrite
= true;
264 //If it is bit 8-11, this is an IPI clear
266 ipintr
= (pkt
->get
<uint64_t>() >> 8) & 0xF;
269 supportedWrite
= true;
272 //If it is the 4-7th bit, clear the RTC interrupt
274 itintr
= (pkt
->get
<uint64_t>() >> 4) & 0xF;
277 supportedWrite
= true;
281 if (pkt
->get
<uint64_t>() & 0x10000000)
282 supportedWrite
= true;
285 panic("TSDEV_CC_MISC write not implemented\n");
292 panic("TSDEV_CC_AARx write not implemeted\n");
298 if(regnum
== TSDEV_CC_DIM0
)
300 else if(regnum
== TSDEV_CC_DIM1
)
302 else if(regnum
== TSDEV_CC_DIM2
)
311 olddim
= dim
[number
];
312 olddir
= dir
[number
];
313 dim
[number
] = pkt
->get
<uint64_t>();
314 dir
[number
] = dim
[number
] & drir
;
315 for(int x
= 0; x
< 64; x
++)
317 bitvector
= ULL(1) << x
;
318 // Figure out which bits have changed
319 if ((dim
[number
] & bitvector
) != (olddim
& bitvector
))
321 // The bit is now set and it wasn't before (set)
322 if((dim
[number
] & bitvector
) && (dir
[number
] & bitvector
))
324 tsunami
->intrctrl
->post(number
, TheISA::INTLEVEL_IRQ1
, x
);
325 DPRINTF(Tsunami
, "posting dir interrupt to cpu 0\n");
327 else if ((olddir
& bitvector
) &&
328 !(dir
[number
] & bitvector
))
330 // The bit was set and now its now clear and
331 // we were interrupting on that bit before
332 tsunami
->intrctrl
->clear(number
, TheISA::INTLEVEL_IRQ1
, x
);
333 DPRINTF(Tsunami
, "dim write resulting in clear"
334 " dir interrupt to cpu %d\n",
347 panic("TSDEV_CC_DIR write not implemented\n");
349 panic("TSDEV_CC_DRIR write not implemented\n");
351 panic("TSDEV_CC_PRBEN write not implemented\n");
356 panic("TSDEV_CC_IICx write not implemented\n");
361 panic("TSDEV_CC_MPRx write not implemented\n");
363 clearIPI(pkt
->get
<uint64_t>());
366 clearITI(pkt
->get
<uint64_t>());
369 reqIPI(pkt
->get
<uint64_t>());
372 panic("default in cchip read reached, accessing 0x%x\n");
374 } // not BIG_TSUNAMI write
375 pkt
->makeAtomicResponse();
380 TsunamiCChip::clearIPI(uint64_t ipintr
)
382 int numcpus
= sys
->threadContexts
.size();
383 assert(numcpus
<= Tsunami::Max_CPUs
);
386 for (int cpunum
=0; cpunum
< numcpus
; cpunum
++) {
387 // Check each cpu bit
388 uint64_t cpumask
= ULL(1) << cpunum
;
389 if (ipintr
& cpumask
) {
390 // Check if there is a pending ipi
391 if (ipint
& cpumask
) {
393 tsunami
->intrctrl
->clear(cpunum
, TheISA::INTLEVEL_IRQ3
, 0);
394 DPRINTF(IPI
, "clear IPI IPI cpu=%d\n", cpunum
);
397 warn("clear IPI for CPU=%d, but NO IPI\n", cpunum
);
402 panic("Big IPI Clear, but not processors indicated\n");
406 TsunamiCChip::clearITI(uint64_t itintr
)
408 int numcpus
= sys
->threadContexts
.size();
409 assert(numcpus
<= Tsunami::Max_CPUs
);
412 for (int i
=0; i
< numcpus
; i
++) {
413 uint64_t cpumask
= ULL(1) << i
;
414 if (itintr
& cpumask
& itint
) {
415 tsunami
->intrctrl
->clear(i
, TheISA::INTLEVEL_IRQ2
, 0);
417 DPRINTF(Tsunami
, "clearing rtc interrupt to cpu=%d\n", i
);
422 panic("Big ITI Clear, but not processors indicated\n");
426 TsunamiCChip::reqIPI(uint64_t ipreq
)
428 int numcpus
= sys
->threadContexts
.size();
429 assert(numcpus
<= Tsunami::Max_CPUs
);
432 for (int cpunum
=0; cpunum
< numcpus
; cpunum
++) {
433 // Check each cpu bit
434 uint64_t cpumask
= ULL(1) << cpunum
;
435 if (ipreq
& cpumask
) {
436 // Check if there is already an ipi (bits 8:11)
437 if (!(ipint
& cpumask
)) {
439 tsunami
->intrctrl
->post(cpunum
, TheISA::INTLEVEL_IRQ3
, 0);
440 DPRINTF(IPI
, "send IPI cpu=%d\n", cpunum
);
443 warn("post IPI for CPU=%d, but IPI already\n", cpunum
);
448 panic("Big IPI Request, but not processors indicated\n");
453 TsunamiCChip::postRTC()
455 int size
= sys
->threadContexts
.size();
456 assert(size
<= Tsunami::Max_CPUs
);
458 for (int i
= 0; i
< size
; i
++) {
459 uint64_t cpumask
= ULL(1) << i
;
460 if (!(cpumask
& itint
)) {
462 tsunami
->intrctrl
->post(i
, TheISA::INTLEVEL_IRQ2
, 0);
463 DPRINTF(Tsunami
, "Posting RTC interrupt to cpu=%d\n", i
);
470 TsunamiCChip::postDRIR(uint32_t interrupt
)
472 uint64_t bitvector
= ULL(1) << interrupt
;
473 uint64_t size
= sys
->threadContexts
.size();
474 assert(size
<= Tsunami::Max_CPUs
);
477 for(int i
=0; i
< size
; i
++) {
478 dir
[i
] = dim
[i
] & drir
;
479 if (dim
[i
] & bitvector
) {
480 tsunami
->intrctrl
->post(i
, TheISA::INTLEVEL_IRQ1
, interrupt
);
481 DPRINTF(Tsunami
, "posting dir interrupt to cpu %d,"
482 "interrupt %d\n",i
, interrupt
);
488 TsunamiCChip::clearDRIR(uint32_t interrupt
)
490 uint64_t bitvector
= ULL(1) << interrupt
;
491 uint64_t size
= sys
->threadContexts
.size();
492 assert(size
<= Tsunami::Max_CPUs
);
494 if (drir
& bitvector
)
497 for(int i
=0; i
< size
; i
++) {
498 if (dir
[i
] & bitvector
) {
499 tsunami
->intrctrl
->clear(i
, TheISA::INTLEVEL_IRQ1
, interrupt
);
500 DPRINTF(Tsunami
, "clearing dir interrupt to cpu %d,"
501 "interrupt %d\n",i
, interrupt
);
504 dir
[i
] = dim
[i
] & drir
;
508 DPRINTF(Tsunami
, "Spurrious clear? interrupt %d\n", interrupt
);
513 TsunamiCChip::serialize(std::ostream
&os
)
515 SERIALIZE_ARRAY(dim
, Tsunami::Max_CPUs
);
516 SERIALIZE_ARRAY(dir
, Tsunami::Max_CPUs
);
517 SERIALIZE_SCALAR(ipint
);
518 SERIALIZE_SCALAR(itint
);
519 SERIALIZE_SCALAR(drir
);
523 TsunamiCChip::unserialize(Checkpoint
*cp
, const std::string
§ion
)
525 UNSERIALIZE_ARRAY(dim
, Tsunami::Max_CPUs
);
526 UNSERIALIZE_ARRAY(dir
, Tsunami::Max_CPUs
);
527 UNSERIALIZE_SCALAR(ipint
);
528 UNSERIALIZE_SCALAR(itint
);
529 UNSERIALIZE_SCALAR(drir
);
533 TsunamiCChipParams::create()
535 return new TsunamiCChip(this);