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, Range
<Addr
>(addr
, 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(addr
, addr
+ size
- 1);
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
& PA_IMPL_MASK
)) >> 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
& PA_IMPL_MASK
)) >> 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");
188 //If it is the 4-7th bit, clear the RTC interrupt
190 if ((itintr
= (*(uint64_t*) data
) & (0xf<<4))) {
191 //Clear the bits in ITINTR
193 for (int i
=0; i
< size
; i
++) {
194 if ((itintr
& (1 << (i
+4))) && RTCInterrupting
[i
]) {
195 tsunami
->intrctrl
->clear(i
, TheISA::INTLEVEL_IRQ2
, 0);
196 RTCInterrupting
[i
] = false;
197 DPRINTF(Tsunami
, "clearing rtc interrupt to cpu=%d\n", i
);
200 supportedWrite
= true;
202 //If it is 12th-15th bit, IPI sent to Processor 1
204 if ((ipreq
= (*(uint64_t*) data
) & (0xf << 12))) {
205 //Set the bits in IPINTR
206 misc
|= (ipreq
>> 4);
207 for (int i
=0; i
< size
; i
++) {
208 if ((ipreq
& (1 << (i
+ 12)))) {
209 if (!ipiInterrupting
[i
])
210 tsunami
->intrctrl
->post(i
, TheISA::INTLEVEL_IRQ3
, 0);
211 ipiInterrupting
[i
]++;
212 DPRINTF(IPI
, "send cpu=%d pending=%d from=%d\n", i
,
213 ipiInterrupting
[i
], req
->cpu_num
);
216 supportedWrite
= true;
218 //If it is bits 8-11, then clearing IPI's
220 if ((ipintr
= (*(uint64_t*) data
) & (0xf << 8))) {
221 //Clear the bits in IPINTR
223 for (int i
=0; i
< size
; i
++) {
224 if ((ipintr
& (1 << (i
+ 8))) && ipiInterrupting
[i
]) {
225 if (!(--ipiInterrupting
[i
]))
226 tsunami
->intrctrl
->clear(i
, TheISA::INTLEVEL_IRQ3
, 0);
227 DPRINTF(IPI
, "clearing cpu=%d pending=%d from=%d\n", i
,
228 ipiInterrupting
[i
] + 1, req
->cpu_num
);
231 supportedWrite
= true;
235 if (*(uint64_t*)data
& 0x10000000)
236 supportedWrite
= true;
238 if(!supportedWrite
) panic("TSDEV_CC_MISC write not implemented\n");
244 panic("TSDEV_CC_AARx write not implemeted\n");
251 if(daddr
== TSDEV_CC_DIM0
)
253 else if(daddr
== TSDEV_CC_DIM1
)
255 else if(daddr
== TSDEV_CC_DIM2
)
264 olddim
= dim
[number
];
265 olddir
= dir
[number
];
266 dim
[number
] = *(uint64_t*)data
;
267 dir
[number
] = dim
[number
] & drir
;
268 for(int x
= 0; x
< 64; x
++)
270 bitvector
= (uint64_t)1 << x
;
271 // Figure out which bits have changed
272 if ((dim
[number
] & bitvector
) != (olddim
& bitvector
))
274 // The bit is now set and it wasn't before (set)
275 if((dim
[number
] & bitvector
) && (dir
[number
] & bitvector
))
277 tsunami
->intrctrl
->post(number
, TheISA::INTLEVEL_IRQ1
, x
);
278 DPRINTF(Tsunami
, "posting dir interrupt to cpu 0\n");
280 else if ((olddir
& bitvector
) &&
281 !(dir
[number
] & bitvector
))
283 // The bit was set and now its now clear and
284 // we were interrupting on that bit before
285 tsunami
->intrctrl
->clear(number
, TheISA::INTLEVEL_IRQ1
, x
);
286 DPRINTF(Tsunami
, "dim write resulting in clear"
287 "dir interrupt to cpu 0\n");
299 panic("TSDEV_CC_DIR write not implemented\n");
301 panic("TSDEV_CC_DRIR write not implemented\n");
303 panic("TSDEV_CC_PRBEN write not implemented\n");
308 panic("TSDEV_CC_IICx write not implemented\n");
313 panic("TSDEV_CC_MPRx write not implemented\n");
315 panic("default in cchip read reached, accessing 0x%x\n");
319 case sizeof(uint32_t):
320 case sizeof(uint16_t):
321 case sizeof(uint8_t):
323 panic("invalid access size(?) for tsunami register!\n");
326 DPRINTFN("Tsunami ERROR: write daddr=%#x size=%d\n", daddr
, req
->size
);
332 TsunamiCChip::postRTC()
334 int size
= tsunami
->intrctrl
->cpu
->system
->execContexts
.size();
336 for (int i
= 0; i
< size
; i
++) {
337 if (!RTCInterrupting
[i
]) {
339 RTCInterrupting
[i
] = true;
340 tsunami
->intrctrl
->post(i
, TheISA::INTLEVEL_IRQ2
, 0);
341 DPRINTF(Tsunami
, "Posting RTC interrupt to cpu=%d", i
);
348 TsunamiCChip::postDRIR(uint32_t interrupt
)
350 uint64_t bitvector
= (uint64_t)0x1 << interrupt
;
352 uint64_t size
= tsunami
->intrctrl
->cpu
->system
->execContexts
.size();
353 for(int i
=0; i
< size
; i
++) {
354 dir
[i
] = dim
[i
] & drir
;
355 if (dim
[i
] & bitvector
) {
356 tsunami
->intrctrl
->post(i
, TheISA::INTLEVEL_IRQ1
, interrupt
);
357 DPRINTF(Tsunami
, "posting dir interrupt to cpu %d,"
358 "interrupt %d\n",i
, interrupt
);
364 TsunamiCChip::clearDRIR(uint32_t interrupt
)
366 uint64_t bitvector
= (uint64_t)0x1 << interrupt
;
367 uint64_t size
= tsunami
->intrctrl
->cpu
->system
->execContexts
.size();
368 if (drir
& bitvector
)
371 for(int i
=0; i
< size
; i
++) {
372 if (dir
[i
] & bitvector
) {
373 tsunami
->intrctrl
->clear(i
, TheISA::INTLEVEL_IRQ1
, interrupt
);
374 DPRINTF(Tsunami
, "clearing dir interrupt to cpu %d,"
375 "interrupt %d\n",i
, interrupt
);
378 dir
[i
] = dim
[i
] & drir
;
382 DPRINTF(Tsunami
, "Spurrious clear? interrupt %d\n", interrupt
);
386 TsunamiCChip::cacheAccess(MemReqPtr
&req
)
388 return curTick
+ pioLatency
;
393 TsunamiCChip::serialize(std::ostream
&os
)
395 SERIALIZE_ARRAY(dim
, Tsunami::Max_CPUs
);
396 SERIALIZE_ARRAY(dir
, Tsunami::Max_CPUs
);
397 SERIALIZE_ARRAY(dirInterrupting
, Tsunami::Max_CPUs
);
398 SERIALIZE_ARRAY(ipiInterrupting
, Tsunami::Max_CPUs
);
399 SERIALIZE_SCALAR(drir
);
400 SERIALIZE_SCALAR(misc
);
401 SERIALIZE_ARRAY(RTCInterrupting
, Tsunami::Max_CPUs
);
405 TsunamiCChip::unserialize(Checkpoint
*cp
, const std::string
§ion
)
407 UNSERIALIZE_ARRAY(dim
, Tsunami::Max_CPUs
);
408 UNSERIALIZE_ARRAY(dir
, Tsunami::Max_CPUs
);
409 UNSERIALIZE_ARRAY(dirInterrupting
, Tsunami::Max_CPUs
);
410 UNSERIALIZE_ARRAY(ipiInterrupting
, Tsunami::Max_CPUs
);
411 UNSERIALIZE_SCALAR(drir
);
412 UNSERIALIZE_SCALAR(misc
);
413 UNSERIALIZE_ARRAY(RTCInterrupting
, Tsunami::Max_CPUs
);
416 BEGIN_DECLARE_SIM_OBJECT_PARAMS(TsunamiCChip
)
418 SimObjectParam
<Tsunami
*> tsunami
;
419 SimObjectParam
<MemoryController
*> mmu
;
421 SimObjectParam
<Bus
*> io_bus
;
422 Param
<Tick
> pio_latency
;
423 SimObjectParam
<HierParams
*> hier
;
425 END_DECLARE_SIM_OBJECT_PARAMS(TsunamiCChip
)
427 BEGIN_INIT_SIM_OBJECT_PARAMS(TsunamiCChip
)
429 INIT_PARAM(tsunami
, "Tsunami"),
430 INIT_PARAM(mmu
, "Memory Controller"),
431 INIT_PARAM(addr
, "Device Address"),
432 INIT_PARAM_DFLT(io_bus
, "The IO Bus to attach to", NULL
),
433 INIT_PARAM_DFLT(pio_latency
, "Programmed IO latency in bus cycles", 1),
434 INIT_PARAM_DFLT(hier
, "Hierarchy global variables", &defaultHierParams
)
436 END_INIT_SIM_OBJECT_PARAMS(TsunamiCChip
)
438 CREATE_SIM_OBJECT(TsunamiCChip
)
440 return new TsunamiCChip(getInstanceName(), tsunami
, addr
, mmu
, hier
,
441 io_bus
, pio_latency
);
444 REGISTER_SIM_OBJECT("TsunamiCChip", TsunamiCChip
)