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 Malta CChip CSRs
40 #include "arch/mips/mips_core_specific.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 "dev/mips/malta.hh"
46 #include "dev/mips/malta_cchip.hh"
47 #include "dev/mips/maltareg.h"
48 #include "mem/packet.hh"
49 #include "mem/packet_access.hh"
50 #include "mem/port.hh"
51 #include "params/MaltaCChip.hh"
52 #include "sim/system.hh"
55 using namespace TheISA
;
57 MaltaCChip::MaltaCChip(Params
*p
)
58 : BasicPioDevice(p
), malta(p
->malta
)
60 warn("MaltaCCHIP::MaltaCChip() not implemented.");
63 //Put back pointer in malta
69 MaltaCChip::read(PacketPtr pkt
)
71 panic("MaltaCCHIP::read() not implemented.");
74 DPRINTF(Malta, "read va=%#x size=%d\n", pkt->getAddr(), pkt->getSize());
76 assert(pkt->result == Packet::Unknown);
77 assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize);
79 Addr regnum = (pkt->getAddr() - pioAddr) >> 6;
80 Addr daddr = (pkt->getAddr() - pioAddr);
83 switch (pkt->getSize()) {
85 case sizeof(uint64_t):
86 if (daddr & TSDEV_CC_BDIMS)
88 pkt->set(dim[(daddr >> 4) & 0x3F]);
92 if (daddr & TSDEV_CC_BDIRS)
94 pkt->set(dir[(daddr >> 4) & 0x3F]);
103 panic("TSDEV_CC_MTR not implemeted\n");
106 pkt->set((ipint << 8) & 0xF | (itint << 4) & 0xF |
107 (pkt->req->contextId() & 0x3));
143 panic("TSDEV_CC_PRBEN not implemented\n");
149 panic("TSDEV_CC_IICx not implemented\n");
155 panic("TSDEV_CC_MPRx not implemented\n");
164 panic("default in cchip read reached, accessing 0x%x\n");
168 case sizeof(uint32_t):
169 case sizeof(uint16_t):
170 case sizeof(uint8_t):
172 panic("invalid access size(?) for malta register!\n");
174 DPRINTF(Malta, "Malta CChip: read regnum=%#x size=%d data=%lld\n",
175 regnum, pkt->getSize(), pkt->get<uint64_t>());
177 pkt->result = Packet::Success;
183 MaltaCChip::write(PacketPtr pkt
)
185 panic("MaltaCCHIP::write() not implemented.");
188 assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize);
189 Addr daddr = pkt->getAddr() - pioAddr;
190 Addr regnum = (pkt->getAddr() - pioAddr) >> 6 ;
193 assert(pkt->getSize() == sizeof(uint64_t));
195 DPRINTF(Malta, "write - addr=%#x value=%#x\n", pkt->getAddr(), pkt->get<uint64_t>());
197 bool supportedWrite = false;
200 if (daddr & TSDEV_CC_BDIMS)
202 int number = (daddr >> 4) & 0x3F;
208 olddim = dim[number];
209 olddir = dir[number];
210 dim[number] = pkt->get<uint64_t>();
211 dir[number] = dim[number] & drir;
212 for(int x = 0; x < Malta::Max_CPUs; x++)
214 bitvector = ULL(1) << x;
215 // Figure out which bits have changed
216 if ((dim[number] & bitvector) != (olddim & bitvector))
218 // The bit is now set and it wasn't before (set)
219 if((dim[number] & bitvector) && (dir[number] & bitvector))
221 malta->intrctrl->post(number, TheISA::INTLEVEL_IRQ1, x);
222 DPRINTF(Malta, "dim write resulting in posting dir"
223 " interrupt to cpu %d\n", number);
225 else if ((olddir & bitvector) &&
226 !(dir[number] & bitvector))
228 // The bit was set and now its now clear and
229 // we were interrupting on that bit before
230 malta->intrctrl->clear(number, TheISA::INTLEVEL_IRQ1, x);
231 DPRINTF(Malta, "dim write resulting in clear"
232 " dir interrupt to cpu %d\n", number);
242 panic("TSDEV_CC_CSR write\n");
244 panic("TSDEV_CC_MTR write not implemented\n");
247 ipreq = (pkt->get<uint64_t>() >> 12) & 0xF;
248 //If it is bit 12-15, this is an IPI post
251 supportedWrite = true;
254 //If it is bit 8-11, this is an IPI clear
256 ipintr = (pkt->get<uint64_t>() >> 8) & 0xF;
259 supportedWrite = true;
262 //If it is the 4-7th bit, clear the RTC interrupt
264 itintr = (pkt->get<uint64_t>() >> 4) & 0xF;
267 supportedWrite = true;
271 if (pkt->get<uint64_t>() & 0x10000000)
272 supportedWrite = true;
275 panic("TSDEV_CC_MISC write not implemented\n");
282 panic("TSDEV_CC_AARx write not implemeted\n");
288 if(regnum == TSDEV_CC_DIM0)
290 else if(regnum == TSDEV_CC_DIM1)
292 else if(regnum == TSDEV_CC_DIM2)
301 olddim = dim[number];
302 olddir = dir[number];
303 dim[number] = pkt->get<uint64_t>();
304 dir[number] = dim[number] & drir;
305 for(int x = 0; x < 64; x++)
307 bitvector = ULL(1) << x;
308 // Figure out which bits have changed
309 if ((dim[number] & bitvector) != (olddim & bitvector))
311 // The bit is now set and it wasn't before (set)
312 if((dim[number] & bitvector) && (dir[number] & bitvector))
314 malta->intrctrl->post(number, TheISA::INTLEVEL_IRQ1, x);
315 DPRINTF(Malta, "posting dir interrupt to cpu 0\n");
317 else if ((olddir & bitvector) &&
318 !(dir[number] & bitvector))
320 // The bit was set and now its now clear and
321 // we were interrupting on that bit before
322 malta->intrctrl->clear(number, TheISA::INTLEVEL_IRQ1, x);
323 DPRINTF(Malta, "dim write resulting in clear"
324 " dir interrupt to cpu %d\n",
337 panic("TSDEV_CC_DIR write not implemented\n");
339 panic("TSDEV_CC_DRIR write not implemented\n");
341 panic("TSDEV_CC_PRBEN write not implemented\n");
346 panic("TSDEV_CC_IICx write not implemented\n");
351 panic("TSDEV_CC_MPRx write not implemented\n");
353 clearIPI(pkt->get<uint64_t>());
356 clearITI(pkt->get<uint64_t>());
359 reqIPI(pkt->get<uint64_t>());
362 panic("default in cchip read reached, accessing 0x%x\n");
364 } // not BIG_TSUNAMI write
365 pkt->result = Packet::Success;
371 MaltaCChip::clearIPI(uint64_t ipintr
)
373 panic("MaltaCCHIP::clear() not implemented.");
375 int numcpus = malta->intrctrl->cpu->system->threadContexts.size();
376 assert(numcpus <= Malta::Max_CPUs);
379 for (int cpunum=0; cpunum < numcpus; cpunum++) {
380 // Check each cpu bit
381 uint64_t cpumask = ULL(1) << cpunum;
382 if (ipintr & cpumask) {
383 // Check if there is a pending ipi
384 if (ipint & cpumask) {
386 malta->intrctrl->clear(cpunum, TheISA::INTLEVEL_IRQ3, 0);
387 DPRINTF(IPI, "clear IPI IPI cpu=%d\n", cpunum);
390 warn("clear IPI for CPU=%d, but NO IPI\n", cpunum);
395 panic("Big IPI Clear, but not processors indicated\n");
400 MaltaCChip::clearITI(uint64_t itintr
)
402 panic("MaltaCCHIP::clearITI() not implemented.");
404 int numcpus = malta->intrctrl->cpu->system->threadContexts.size();
405 assert(numcpus <= Malta::Max_CPUs);
408 for (int i=0; i < numcpus; i++) {
409 uint64_t cpumask = ULL(1) << i;
410 if (itintr & cpumask & itint) {
411 malta->intrctrl->clear(i, TheISA::INTLEVEL_IRQ2, 0);
413 DPRINTF(Malta, "clearing rtc interrupt to cpu=%d\n", i);
418 panic("Big ITI Clear, but not processors indicated\n");
423 MaltaCChip::reqIPI(uint64_t ipreq
)
425 panic("MaltaCCHIP::reqIPI() not implemented.");
428 int numcpus = malta->intrctrl->cpu->system->threadContexts.size();
429 assert(numcpus <= Malta::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 malta->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");
455 MaltaCChip::postRTC()
457 panic("MaltaCCHIP::postRTC() not implemented.");
460 int size = malta->intrctrl->cpu->system->threadContexts.size();
461 assert(size <= Malta::Max_CPUs);
463 for (int i = 0; i < size; i++) {
464 uint64_t cpumask = ULL(1) << i;
465 if (!(cpumask & itint)) {
467 malta->intrctrl->post(i, TheISA::INTLEVEL_IRQ2, 0);
468 DPRINTF(Malta, "Posting RTC interrupt to cpu=%d", i);
476 MaltaCChip::postIntr(uint32_t interrupt
)
478 uint64_t size
= sys
->threadContexts
.size();
479 assert(size
<= Malta::Max_CPUs
);
481 for(int i
=0; i
< size
; i
++) {
482 //Note: Malta does not use index, but this was added to use the pre-existing implementation
483 malta
->intrctrl
->post(i
, interrupt
, 0);
484 DPRINTF(Malta
, "posting interrupt to cpu %d,"
485 "interrupt %d\n",i
, interrupt
);
491 MaltaCChip::clearIntr(uint32_t interrupt
)
493 uint64_t size
= sys
->threadContexts
.size();
494 assert(size
<= Malta::Max_CPUs
);
496 for(int i
=0; i
< size
; i
++) {
497 //Note: Malta does not use index, but this was added to use the pre-existing implementation
498 malta
->intrctrl
->clear(i
, interrupt
, 0);
499 DPRINTF(Malta
, "clearing interrupt to cpu %d,"
500 "interrupt %d\n",i
, interrupt
);
506 MaltaCChip::serialize(std::ostream
&os
)
508 // SERIALIZE_ARRAY(dim, Malta::Max_CPUs);
509 //SERIALIZE_ARRAY(dir, Malta::Max_CPUs);
510 //SERIALIZE_SCALAR(ipint);
511 //SERIALIZE_SCALAR(itint);
512 //SERIALIZE_SCALAR(drir);
516 MaltaCChip::unserialize(Checkpoint
*cp
, const std::string
§ion
)
518 //UNSERIALIZE_ARRAY(dim, Malta::Max_CPUs);
519 //UNSERIALIZE_ARRAY(dir, Malta::Max_CPUs);
520 //UNSERIALIZE_SCALAR(ipint);
521 //UNSERIALIZE_SCALAR(itint);
522 //UNSERIALIZE_SCALAR(drir);
526 MaltaCChipParams::create()
528 return new MaltaCChip(this);