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
)
53 : PioDevice(name
), addr(a
), tsunami(t
)
55 mmu
->add_child(this, Range
<Addr
>(addr
, addr
+ size
));
57 for(int i
=0; i
< Tsunami::Max_CPUs
; i
++) {
60 dirInterrupting
[i
] = false;
61 ipiInterrupting
[i
] = false;
62 RTCInterrupting
[i
] = false;
66 pioInterface
= newPioInterface(name
, hier
, bus
, this,
67 &TsunamiCChip::cacheAccess
);
68 pioInterface
->addAddrRange(addr
, addr
+ size
- 1);
74 //Put back pointer in tsunami
75 tsunami
->cchip
= this;
79 TsunamiCChip::read(MemReqPtr
&req
, uint8_t *data
)
81 DPRINTF(Tsunami
, "read va=%#x size=%d\n",
82 req
->vaddr
, req
->size
);
84 Addr daddr
= (req
->paddr
- (addr
& PA_IMPL_MASK
)) >> 6;
85 ExecContext
*xc
= req
->xc
;
89 case sizeof(uint64_t):
92 *(uint64_t*)data
= 0x0;
95 panic("TSDEV_CC_MTR not implemeted\n");
98 *(uint64_t*)data
= misc
| (xc
->cpu_id
& 0x3);
104 *(uint64_t*)data
= 0;
107 *(uint64_t*)data
= dim
[0];
110 *(uint64_t*)data
= dim
[1];
113 *(uint64_t*)data
= dim
[2];
116 *(uint64_t*)data
= dim
[3];
119 *(uint64_t*)data
= dir
[0];
122 *(uint64_t*)data
= dir
[1];
125 *(uint64_t*)data
= dir
[2];
128 *(uint64_t*)data
= dir
[3];
131 *(uint64_t*)data
= drir
;
134 panic("TSDEV_CC_PRBEN not implemented\n");
140 panic("TSDEV_CC_IICx not implemented\n");
146 panic("TSDEV_CC_MPRx not implemented\n");
149 panic("default in cchip read reached, accessing 0x%x\n");
153 case sizeof(uint32_t):
154 case sizeof(uint16_t):
155 case sizeof(uint8_t):
157 panic("invalid access size(?) for tsunami register!\n");
159 DPRINTFN("Tsunami CChip ERROR: read daddr=%#x size=%d\n", daddr
, req
->size
);
165 TsunamiCChip::write(MemReqPtr
&req
, const uint8_t *data
)
167 DPRINTF(Tsunami
, "write - va=%#x value=%#x size=%d \n",
168 req
->vaddr
, *(uint64_t*)data
, req
->size
);
170 Addr daddr
= (req
->paddr
- (addr
& PA_IMPL_MASK
)) >> 6;
172 bool supportedWrite
= false;
173 uint64_t size
= tsunami
->intrctrl
->cpu
->system
->execContexts
.size();
177 case sizeof(uint64_t):
180 panic("TSDEV_CC_CSR write\n");
183 panic("TSDEV_CC_MTR write not implemented\n");
186 //If it is the 4-7th bit, clear the RTC interrupt
188 if ((itintr
= (*(uint64_t*) data
) & (0xf<<4))) {
189 //Clear the bits in ITINTR
191 for (int i
=0; i
< size
; i
++) {
192 if ((itintr
& (1 << (i
+4))) && RTCInterrupting
[i
]) {
193 tsunami
->intrctrl
->clear(i
, TheISA::INTLEVEL_IRQ2
, 0);
194 RTCInterrupting
[i
] = false;
195 DPRINTF(Tsunami
, "clearing rtc interrupt to cpu=%d\n", i
);
198 supportedWrite
= true;
200 //If it is 12th-15th bit, IPI sent to Processor 1
202 if ((ipreq
= (*(uint64_t*) data
) & (0xf << 12))) {
203 //Set the bits in IPINTR
204 misc
|= (ipreq
>> 4);
205 for (int i
=0; i
< size
; i
++) {
206 if ((ipreq
& (1 << (i
+ 12)))) {
207 if (!ipiInterrupting
[i
])
208 tsunami
->intrctrl
->post(i
, TheISA::INTLEVEL_IRQ3
, 0);
209 ipiInterrupting
[i
]++;
210 DPRINTF(IPI
, "send cpu=%d pending=%d from=%d\n", i
,
211 ipiInterrupting
[i
], req
->cpu_num
);
214 supportedWrite
= true;
216 //If it is bits 8-11, then clearing IPI's
218 if ((ipintr
= (*(uint64_t*) data
) & (0xf << 8))) {
219 //Clear the bits in IPINTR
221 for (int i
=0; i
< size
; i
++) {
222 if ((ipintr
& (1 << (i
+ 8))) && ipiInterrupting
[i
]) {
223 if (!(--ipiInterrupting
[i
]))
224 tsunami
->intrctrl
->clear(i
, TheISA::INTLEVEL_IRQ3
, 0);
225 DPRINTF(IPI
, "clearing cpu=%d pending=%d from=%d\n", i
,
226 ipiInterrupting
[i
] + 1, req
->cpu_num
);
229 supportedWrite
= true;
233 if (*(uint64_t*)data
& 0x10000000)
234 supportedWrite
= true;
236 if(!supportedWrite
) panic("TSDEV_CC_MISC write not implemented\n");
242 panic("TSDEV_CC_AARx write not implemeted\n");
249 if(daddr
== TSDEV_CC_DIM0
)
251 else if(daddr
== TSDEV_CC_DIM1
)
253 else if(daddr
== TSDEV_CC_DIM2
)
262 olddim
= dim
[number
];
263 olddir
= dir
[number
];
264 dim
[number
] = *(uint64_t*)data
;
265 dir
[number
] = dim
[number
] & drir
;
266 for(int x
= 0; x
< 64; x
++)
268 bitvector
= (uint64_t)1 << x
;
269 // Figure out which bits have changed
270 if ((dim
[number
] & bitvector
) != (olddim
& bitvector
))
272 // The bit is now set and it wasn't before (set)
273 if((dim
[number
] & bitvector
) && (dir
[number
] & bitvector
))
275 tsunami
->intrctrl
->post(number
, TheISA::INTLEVEL_IRQ1
, x
);
276 DPRINTF(Tsunami
, "posting dir interrupt to cpu 0\n");
278 else if ((olddir
& bitvector
) &&
279 !(dir
[number
] & bitvector
))
281 // The bit was set and now its now clear and
282 // we were interrupting on that bit before
283 tsunami
->intrctrl
->clear(number
, TheISA::INTLEVEL_IRQ1
, x
);
284 DPRINTF(Tsunami
, "dim write resulting in clear"
285 "dir interrupt to cpu 0\n");
297 panic("TSDEV_CC_DIR write not implemented\n");
299 panic("TSDEV_CC_DRIR write not implemented\n");
301 panic("TSDEV_CC_PRBEN write not implemented\n");
306 panic("TSDEV_CC_IICx write not implemented\n");
311 panic("TSDEV_CC_MPRx write not implemented\n");
313 panic("default in cchip read reached, accessing 0x%x\n");
317 case sizeof(uint32_t):
318 case sizeof(uint16_t):
319 case sizeof(uint8_t):
321 panic("invalid access size(?) for tsunami register!\n");
324 DPRINTFN("Tsunami ERROR: write daddr=%#x size=%d\n", daddr
, req
->size
);
330 TsunamiCChip::postRTC()
332 int size
= tsunami
->intrctrl
->cpu
->system
->execContexts
.size();
334 for (int i
= 0; i
< size
; i
++) {
335 if (!RTCInterrupting
[i
]) {
337 RTCInterrupting
[i
] = true;
338 tsunami
->intrctrl
->post(i
, TheISA::INTLEVEL_IRQ2
, 0);
339 DPRINTF(Tsunami
, "Posting RTC interrupt to cpu=%d", i
);
346 TsunamiCChip::postDRIR(uint32_t interrupt
)
348 uint64_t bitvector
= (uint64_t)0x1 << interrupt
;
350 uint64_t size
= tsunami
->intrctrl
->cpu
->system
->execContexts
.size();
351 for(int i
=0; i
< size
; i
++) {
352 dir
[i
] = dim
[i
] & drir
;
353 if (dim
[i
] & bitvector
) {
354 tsunami
->intrctrl
->post(i
, TheISA::INTLEVEL_IRQ1
, interrupt
);
355 DPRINTF(Tsunami
, "posting dir interrupt to cpu %d,"
356 "interrupt %d\n",i
, interrupt
);
362 TsunamiCChip::clearDRIR(uint32_t interrupt
)
364 uint64_t bitvector
= (uint64_t)0x1 << interrupt
;
365 uint64_t size
= tsunami
->intrctrl
->cpu
->system
->execContexts
.size();
366 if (drir
& bitvector
)
369 for(int i
=0; i
< size
; i
++) {
370 if (dir
[i
] & bitvector
) {
371 tsunami
->intrctrl
->clear(i
, TheISA::INTLEVEL_IRQ1
, interrupt
);
372 DPRINTF(Tsunami
, "clearing dir interrupt to cpu %d,"
373 "interrupt %d\n",i
, interrupt
);
376 dir
[i
] = dim
[i
] & drir
;
380 DPRINTF(Tsunami
, "Spurrious clear? interrupt %d\n", interrupt
);
384 TsunamiCChip::cacheAccess(MemReqPtr
&req
)
386 return curTick
+ 1000;
391 TsunamiCChip::serialize(std::ostream
&os
)
393 SERIALIZE_ARRAY(dim
, Tsunami::Max_CPUs
);
394 SERIALIZE_ARRAY(dir
, Tsunami::Max_CPUs
);
395 SERIALIZE_ARRAY(dirInterrupting
, Tsunami::Max_CPUs
);
396 SERIALIZE_ARRAY(ipiInterrupting
, Tsunami::Max_CPUs
);
397 SERIALIZE_SCALAR(drir
);
398 SERIALIZE_SCALAR(misc
);
399 SERIALIZE_ARRAY(RTCInterrupting
, Tsunami::Max_CPUs
);
403 TsunamiCChip::unserialize(Checkpoint
*cp
, const std::string
§ion
)
405 UNSERIALIZE_ARRAY(dim
, Tsunami::Max_CPUs
);
406 UNSERIALIZE_ARRAY(dir
, Tsunami::Max_CPUs
);
407 UNSERIALIZE_ARRAY(dirInterrupting
, Tsunami::Max_CPUs
);
408 UNSERIALIZE_ARRAY(ipiInterrupting
, Tsunami::Max_CPUs
);
409 UNSERIALIZE_SCALAR(drir
);
410 UNSERIALIZE_SCALAR(misc
);
411 UNSERIALIZE_ARRAY(RTCInterrupting
, Tsunami::Max_CPUs
);
414 BEGIN_DECLARE_SIM_OBJECT_PARAMS(TsunamiCChip
)
416 SimObjectParam
<Tsunami
*> tsunami
;
417 SimObjectParam
<MemoryController
*> mmu
;
419 SimObjectParam
<Bus
*> io_bus
;
420 SimObjectParam
<HierParams
*> hier
;
422 END_DECLARE_SIM_OBJECT_PARAMS(TsunamiCChip
)
424 BEGIN_INIT_SIM_OBJECT_PARAMS(TsunamiCChip
)
426 INIT_PARAM(tsunami
, "Tsunami"),
427 INIT_PARAM(mmu
, "Memory Controller"),
428 INIT_PARAM(addr
, "Device Address"),
429 INIT_PARAM_DFLT(io_bus
, "The IO Bus to attach to", NULL
),
430 INIT_PARAM_DFLT(hier
, "Hierarchy global variables", &defaultHierParams
)
432 END_INIT_SIM_OBJECT_PARAMS(TsunamiCChip
)
434 CREATE_SIM_OBJECT(TsunamiCChip
)
436 return new TsunamiCChip(getInstanceName(), tsunami
, addr
, mmu
, hier
, io_bus
);
439 REGISTER_SIM_OBJECT("TsunamiCChip", TsunamiCChip
)