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.
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/memory_control.hh"
45 #include "cpu/intr_control.hh"
46 #include "sim/builder.hh"
47 #include "sim/system.hh"
50 //Should this be AlphaISA?
51 using namespace TheISA
;
53 TsunamiCChip::TsunamiCChip(const string
&name
, Tsunami
*t
, Addr a
,
54 MemoryController
*mmu
, HierParams
*hier
,
55 Bus
* pio_bus
, Tick pio_latency
)
56 : PioDevice(name
, t
), addr(a
), tsunami(t
)
58 mmu
->add_child(this, RangeSize(addr
, size
));
61 pioInterface
= newPioInterface(name
+ ".pio", hier
, pio_bus
, this,
62 &TsunamiCChip::cacheAccess
);
63 pioInterface
->addAddrRange(RangeSize(addr
, size
));
64 pioLatency
= pio_latency
* pio_bus
->clockRate
;
71 for (int x
= 0; x
< Tsunami::Max_CPUs
; x
++)
77 //Put back pointer in tsunami
78 tsunami
->cchip
= this;
82 TsunamiCChip::read(MemReqPtr
&req
, uint8_t *data
)
84 DPRINTF(Tsunami
, "read va=%#x size=%d\n", req
->vaddr
, req
->size
);
86 Addr regnum
= (req
->paddr
- (addr
& EV5::PAddrImplMask
)) >> 6;
87 Addr daddr
= (req
->paddr
- (addr
& EV5::PAddrImplMask
));
89 ExecContext
*xc
= req
->xc
;
93 case sizeof(uint64_t):
94 if (daddr
& TSDEV_CC_BDIMS
)
96 *(uint64_t*)data
= dim
[(daddr
>> 4) & 0x3F];
100 if (daddr
& TSDEV_CC_BDIRS
)
102 *(uint64_t*)data
= dir
[(daddr
>> 4) & 0x3F];
108 *(uint64_t*)data
= 0x0;
111 panic("TSDEV_CC_MTR not implemeted\n");
114 *(uint64_t*)data
= (ipint
<< 8) & 0xF |
122 *(uint64_t*)data
= 0;
125 *(uint64_t*)data
= dim
[0];
128 *(uint64_t*)data
= dim
[1];
131 *(uint64_t*)data
= dim
[2];
134 *(uint64_t*)data
= dim
[3];
137 *(uint64_t*)data
= dir
[0];
140 *(uint64_t*)data
= dir
[1];
143 *(uint64_t*)data
= dir
[2];
146 *(uint64_t*)data
= dir
[3];
149 *(uint64_t*)data
= drir
;
152 panic("TSDEV_CC_PRBEN not implemented\n");
158 panic("TSDEV_CC_IICx not implemented\n");
164 panic("TSDEV_CC_MPRx not implemented\n");
167 *(uint64_t*)data
= ipint
;
170 *(uint64_t*)data
= itint
;
173 panic("default in cchip read reached, accessing 0x%x\n");
177 case sizeof(uint32_t):
178 if (regnum
== TSDEV_CC_DRIR
) {
179 warn("accessing DRIR with 32 bit read, "
180 "hopefully your just reading this for timing");
181 *(uint32_t*)data
= drir
;
183 panic("invalid access size(?) for tsunami register!\n");
185 case sizeof(uint16_t):
186 case sizeof(uint8_t):
188 panic("invalid access size(?) for tsunami register!\n");
190 DPRINTFN("Tsunami CChip ERROR: read regnum=%#x size=%d\n", regnum
, req
->size
);
196 TsunamiCChip::write(MemReqPtr
&req
, const uint8_t *data
)
198 DPRINTF(Tsunami
, "write - va=%#x value=%#x size=%d \n",
199 req
->vaddr
, *(uint64_t*)data
, req
->size
);
201 Addr daddr
= (req
->paddr
- (addr
& EV5::PAddrImplMask
));
202 Addr regnum
= (req
->paddr
- (addr
& EV5::PAddrImplMask
)) >> 6;
204 bool supportedWrite
= false;
208 case sizeof(uint64_t):
209 if (daddr
& TSDEV_CC_BDIMS
)
211 int number
= (daddr
>> 4) & 0x3F;
217 olddim
= dim
[number
];
218 olddir
= dir
[number
];
219 dim
[number
] = *(uint64_t*)data
;
220 dir
[number
] = dim
[number
] & drir
;
221 for(int x
= 0; x
< Tsunami::Max_CPUs
; x
++)
223 bitvector
= ULL(1) << x
;
224 // Figure out which bits have changed
225 if ((dim
[number
] & bitvector
) != (olddim
& bitvector
))
227 // The bit is now set and it wasn't before (set)
228 if((dim
[number
] & bitvector
) && (dir
[number
] & bitvector
))
230 tsunami
->intrctrl
->post(number
, TheISA::INTLEVEL_IRQ1
, x
);
231 DPRINTF(Tsunami
, "dim write resulting in posting dir"
232 " interrupt to cpu %d\n", number
);
234 else if ((olddir
& bitvector
) &&
235 !(dir
[number
] & bitvector
))
237 // The bit was set and now its now clear and
238 // we were interrupting on that bit before
239 tsunami
->intrctrl
->clear(number
, TheISA::INTLEVEL_IRQ1
, x
);
240 DPRINTF(Tsunami
, "dim write resulting in clear"
241 " dir interrupt to cpu %d\n", number
);
253 panic("TSDEV_CC_CSR write\n");
256 panic("TSDEV_CC_MTR write not implemented\n");
260 ipreq
= (*(uint64_t*)data
>> 12) & 0xF;
261 //If it is bit 12-15, this is an IPI post
264 supportedWrite
= true;
267 //If it is bit 8-11, this is an IPI clear
269 ipintr
= (*(uint64_t*)data
>> 8) & 0xF;
272 supportedWrite
= true;
275 //If it is the 4-7th bit, clear the RTC interrupt
277 itintr
= (*(uint64_t*)data
>> 4) & 0xF;
280 supportedWrite
= true;
284 if (*(uint64_t*)data
& 0x10000000)
285 supportedWrite
= true;
288 panic("TSDEV_CC_MISC write not implemented\n");
295 panic("TSDEV_CC_AARx write not implemeted\n");
302 if(regnum
== TSDEV_CC_DIM0
)
304 else if(regnum
== TSDEV_CC_DIM1
)
306 else if(regnum
== TSDEV_CC_DIM2
)
315 olddim
= dim
[number
];
316 olddir
= dir
[number
];
317 dim
[number
] = *(uint64_t*)data
;
318 dir
[number
] = dim
[number
] & drir
;
319 for(int x
= 0; x
< 64; x
++)
321 bitvector
= ULL(1) << x
;
322 // Figure out which bits have changed
323 if ((dim
[number
] & bitvector
) != (olddim
& bitvector
))
325 // The bit is now set and it wasn't before (set)
326 if((dim
[number
] & bitvector
) && (dir
[number
] & bitvector
))
328 tsunami
->intrctrl
->post(number
, TheISA::INTLEVEL_IRQ1
, x
);
329 DPRINTF(Tsunami
, "posting dir interrupt to cpu 0\n");
331 else if ((olddir
& bitvector
) &&
332 !(dir
[number
] & bitvector
))
334 // The bit was set and now its now clear and
335 // we were interrupting on that bit before
336 tsunami
->intrctrl
->clear(number
, TheISA::INTLEVEL_IRQ1
, x
);
337 DPRINTF(Tsunami
, "dim write resulting in clear"
338 " dir interrupt to cpu %d\n",
351 panic("TSDEV_CC_DIR write not implemented\n");
353 panic("TSDEV_CC_DRIR write not implemented\n");
355 panic("TSDEV_CC_PRBEN write not implemented\n");
360 panic("TSDEV_CC_IICx write not implemented\n");
365 panic("TSDEV_CC_MPRx write not implemented\n");
367 clearIPI(*(uint64_t*)data
);
370 clearITI(*(uint64_t*)data
);
373 reqIPI(*(uint64_t*)data
);
376 panic("default in cchip read reached, accessing 0x%x\n");
380 case sizeof(uint32_t):
381 case sizeof(uint16_t):
382 case sizeof(uint8_t):
384 panic("invalid access size(?) for tsunami register!\n");
387 DPRINTFN("Tsunami ERROR: write daddr=%#x size=%d\n", daddr
, req
->size
);
393 TsunamiCChip::clearIPI(uint64_t ipintr
)
395 int numcpus
= tsunami
->intrctrl
->cpu
->system
->execContexts
.size();
396 assert(numcpus
<= Tsunami::Max_CPUs
);
399 for (int cpunum
=0; cpunum
< numcpus
; cpunum
++) {
400 // Check each cpu bit
401 uint64_t cpumask
= ULL(1) << cpunum
;
402 if (ipintr
& cpumask
) {
403 // Check if there is a pending ipi
404 if (ipint
& cpumask
) {
406 tsunami
->intrctrl
->clear(cpunum
, TheISA::INTLEVEL_IRQ3
, 0);
407 DPRINTF(IPI
, "clear IPI IPI cpu=%d\n", cpunum
);
410 warn("clear IPI for CPU=%d, but NO IPI\n", cpunum
);
415 panic("Big IPI Clear, but not processors indicated\n");
419 TsunamiCChip::clearITI(uint64_t itintr
)
421 int numcpus
= tsunami
->intrctrl
->cpu
->system
->execContexts
.size();
422 assert(numcpus
<= Tsunami::Max_CPUs
);
425 for (int i
=0; i
< numcpus
; i
++) {
426 uint64_t cpumask
= ULL(1) << i
;
427 if (itintr
& cpumask
& itint
) {
428 tsunami
->intrctrl
->clear(i
, TheISA::INTLEVEL_IRQ2
, 0);
430 DPRINTF(Tsunami
, "clearing rtc interrupt to cpu=%d\n", i
);
435 panic("Big ITI Clear, but not processors indicated\n");
439 TsunamiCChip::reqIPI(uint64_t ipreq
)
441 int numcpus
= tsunami
->intrctrl
->cpu
->system
->execContexts
.size();
442 assert(numcpus
<= Tsunami::Max_CPUs
);
445 for (int cpunum
=0; cpunum
< numcpus
; cpunum
++) {
446 // Check each cpu bit
447 uint64_t cpumask
= ULL(1) << cpunum
;
448 if (ipreq
& cpumask
) {
449 // Check if there is already an ipi (bits 8:11)
450 if (!(ipint
& cpumask
)) {
452 tsunami
->intrctrl
->post(cpunum
, TheISA::INTLEVEL_IRQ3
, 0);
453 DPRINTF(IPI
, "send IPI cpu=%d\n", cpunum
);
456 warn("post IPI for CPU=%d, but IPI already\n", cpunum
);
461 panic("Big IPI Request, but not processors indicated\n");
466 TsunamiCChip::postRTC()
468 int size
= tsunami
->intrctrl
->cpu
->system
->execContexts
.size();
469 assert(size
<= Tsunami::Max_CPUs
);
471 for (int i
= 0; i
< size
; i
++) {
472 uint64_t cpumask
= ULL(1) << i
;
473 if (!(cpumask
& itint
)) {
475 tsunami
->intrctrl
->post(i
, TheISA::INTLEVEL_IRQ2
, 0);
476 DPRINTF(Tsunami
, "Posting RTC interrupt to cpu=%d", i
);
483 TsunamiCChip::postDRIR(uint32_t interrupt
)
485 uint64_t bitvector
= ULL(1) << interrupt
;
486 uint64_t size
= tsunami
->intrctrl
->cpu
->system
->execContexts
.size();
487 assert(size
<= Tsunami::Max_CPUs
);
490 for(int i
=0; i
< size
; i
++) {
491 dir
[i
] = dim
[i
] & drir
;
492 if (dim
[i
] & bitvector
) {
493 tsunami
->intrctrl
->post(i
, TheISA::INTLEVEL_IRQ1
, interrupt
);
494 DPRINTF(Tsunami
, "posting dir interrupt to cpu %d,"
495 "interrupt %d\n",i
, interrupt
);
501 TsunamiCChip::clearDRIR(uint32_t interrupt
)
503 uint64_t bitvector
= ULL(1) << interrupt
;
504 uint64_t size
= tsunami
->intrctrl
->cpu
->system
->execContexts
.size();
505 assert(size
<= Tsunami::Max_CPUs
);
507 if (drir
& bitvector
)
510 for(int i
=0; i
< size
; i
++) {
511 if (dir
[i
] & bitvector
) {
512 tsunami
->intrctrl
->clear(i
, TheISA::INTLEVEL_IRQ1
, interrupt
);
513 DPRINTF(Tsunami
, "clearing dir interrupt to cpu %d,"
514 "interrupt %d\n",i
, interrupt
);
517 dir
[i
] = dim
[i
] & drir
;
521 DPRINTF(Tsunami
, "Spurrious clear? interrupt %d\n", interrupt
);
525 TsunamiCChip::cacheAccess(MemReqPtr
&req
)
527 return curTick
+ pioLatency
;
532 TsunamiCChip::serialize(std::ostream
&os
)
534 SERIALIZE_ARRAY(dim
, Tsunami::Max_CPUs
);
535 SERIALIZE_ARRAY(dir
, Tsunami::Max_CPUs
);
536 SERIALIZE_SCALAR(ipint
);
537 SERIALIZE_SCALAR(itint
);
538 SERIALIZE_SCALAR(drir
);
542 TsunamiCChip::unserialize(Checkpoint
*cp
, const std::string
§ion
)
544 UNSERIALIZE_ARRAY(dim
, Tsunami::Max_CPUs
);
545 UNSERIALIZE_ARRAY(dir
, Tsunami::Max_CPUs
);
546 UNSERIALIZE_SCALAR(ipint
);
547 UNSERIALIZE_SCALAR(itint
);
548 UNSERIALIZE_SCALAR(drir
);
551 BEGIN_DECLARE_SIM_OBJECT_PARAMS(TsunamiCChip
)
553 SimObjectParam
<Tsunami
*> tsunami
;
554 SimObjectParam
<MemoryController
*> mmu
;
556 SimObjectParam
<Bus
*> pio_bus
;
557 Param
<Tick
> pio_latency
;
558 SimObjectParam
<HierParams
*> hier
;
560 END_DECLARE_SIM_OBJECT_PARAMS(TsunamiCChip
)
562 BEGIN_INIT_SIM_OBJECT_PARAMS(TsunamiCChip
)
564 INIT_PARAM(tsunami
, "Tsunami"),
565 INIT_PARAM(mmu
, "Memory Controller"),
566 INIT_PARAM(addr
, "Device Address"),
567 INIT_PARAM_DFLT(pio_bus
, "The IO Bus to attach to", NULL
),
568 INIT_PARAM_DFLT(pio_latency
, "Programmed IO latency in bus cycles", 1),
569 INIT_PARAM_DFLT(hier
, "Hierarchy global variables", &defaultHierParams
)
571 END_INIT_SIM_OBJECT_PARAMS(TsunamiCChip
)
573 CREATE_SIM_OBJECT(TsunamiCChip
)
575 return new TsunamiCChip(getInstanceName(), tsunami
, addr
, mmu
, hier
,
576 pio_bus
, pio_latency
);
579 REGISTER_SIM_OBJECT("TsunamiCChip", TsunamiCChip
)