2010-08-23 18:18:40 +02:00
|
|
|
/*
|
2016-05-06 16:52:34 +02:00
|
|
|
* Copyright (c) 2010, 2013, 2015-2016 ARM Limited
|
2010-08-23 18:18:40 +02:00
|
|
|
* All rights reserved
|
|
|
|
*
|
|
|
|
* The license below extends only to copyright in the software and shall
|
|
|
|
* not be construed as granting a license to any other intellectual
|
|
|
|
* property including but not limited to intellectual property relating
|
|
|
|
* to a hardware implementation of the functionality of the software
|
|
|
|
* licensed hereunder. You may use the software subject to the license
|
|
|
|
* terms below provided that you ensure that this notice is replicated
|
|
|
|
* unmodified and in its entirety in all distributions of the software,
|
|
|
|
* modified or unmodified, in source code or in binary form.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2005 The Regents of The University of Michigan
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met: redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer;
|
|
|
|
* redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution;
|
|
|
|
* neither the name of the copyright holders nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived from
|
|
|
|
* this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* Authors: Ali Saidi
|
2010-10-01 23:04:00 +02:00
|
|
|
* Prakash Ramrakhyani
|
2010-08-23 18:18:40 +02:00
|
|
|
*/
|
|
|
|
|
2016-11-09 21:27:37 +01:00
|
|
|
#include "dev/arm/gic_pl390.hh"
|
|
|
|
|
2010-08-23 18:18:40 +02:00
|
|
|
#include "base/trace.hh"
|
2011-04-21 03:45:03 +02:00
|
|
|
#include "debug/Checkpoint.hh"
|
|
|
|
#include "debug/GIC.hh"
|
2011-05-05 03:38:27 +02:00
|
|
|
#include "debug/IPI.hh"
|
2011-09-30 09:28:33 +02:00
|
|
|
#include "debug/Interrupt.hh"
|
2010-08-23 18:18:40 +02:00
|
|
|
#include "dev/terminal.hh"
|
|
|
|
#include "mem/packet.hh"
|
|
|
|
#include "mem/packet_access.hh"
|
|
|
|
|
2016-08-02 14:35:45 +02:00
|
|
|
const AddrRange Pl390::GICD_ISENABLER (0x100, 0x17f);
|
|
|
|
const AddrRange Pl390::GICD_ICENABLER (0x180, 0x1ff);
|
|
|
|
const AddrRange Pl390::GICD_ISPENDR (0x200, 0x27f);
|
|
|
|
const AddrRange Pl390::GICD_ICPENDR (0x280, 0x2ff);
|
|
|
|
const AddrRange Pl390::GICD_ISACTIVER (0x300, 0x37f);
|
|
|
|
const AddrRange Pl390::GICD_ICACTIVER (0x380, 0x3ff);
|
|
|
|
const AddrRange Pl390::GICD_IPRIORITYR(0x400, 0x7ff);
|
|
|
|
const AddrRange Pl390::GICD_ITARGETSR (0x800, 0xbff);
|
|
|
|
const AddrRange Pl390::GICD_ICFGR (0xc00, 0xcff);
|
|
|
|
|
2012-10-25 15:05:24 +02:00
|
|
|
Pl390::Pl390(const Params *p)
|
|
|
|
: BaseGic(p), distAddr(p->dist_addr),
|
2011-10-04 11:26:03 +02:00
|
|
|
cpuAddr(p->cpu_addr), distPioDelay(p->dist_pio_delay),
|
|
|
|
cpuPioDelay(p->cpu_pio_delay), intLatency(p->int_latency),
|
2016-08-02 14:35:45 +02:00
|
|
|
enabled(false), haveGem5Extensions(p->gem5_extensions),
|
|
|
|
itLines(p->it_lines),
|
|
|
|
intEnabled {}, pendingInt {}, activeInt {},
|
|
|
|
intPriority {}, cpuTarget {}, intConfig {},
|
|
|
|
cpuSgiPending {}, cpuSgiActive {},
|
|
|
|
cpuSgiPendingExt {}, cpuSgiActiveExt {},
|
|
|
|
cpuPpiPending {}, cpuPpiActive {},
|
|
|
|
irqEnable(false)
|
2010-08-23 18:18:40 +02:00
|
|
|
{
|
2011-05-05 03:38:27 +02:00
|
|
|
for (int x = 0; x < CPU_MAX; x++) {
|
2015-11-11 11:18:38 +01:00
|
|
|
iccrpr[x] = 0xff;
|
2010-08-23 18:18:40 +02:00
|
|
|
cpuEnabled[x] = false;
|
2011-05-05 03:38:27 +02:00
|
|
|
cpuPriority[x] = 0xff;
|
2010-08-23 18:18:40 +02:00
|
|
|
cpuBpr[x] = 0;
|
2010-10-01 23:04:00 +02:00
|
|
|
// Initialize cpu highest int
|
|
|
|
cpuHighestInt[x] = SPURIOUS_INT;
|
2011-05-05 03:38:27 +02:00
|
|
|
postIntEvent[x] = new PostIntEvent(x, p->platform);
|
2010-08-23 18:18:40 +02:00
|
|
|
}
|
2011-05-05 03:38:27 +02:00
|
|
|
DPRINTF(Interrupt, "cpuEnabled[0]=%d cpuEnabled[1]=%d\n", cpuEnabled[0],
|
|
|
|
cpuEnabled[1]);
|
2010-08-23 18:18:40 +02:00
|
|
|
|
2015-09-18 17:49:28 +02:00
|
|
|
gem5ExtensionsEnabled = false;
|
2010-08-23 18:18:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Tick
|
2012-10-25 15:05:24 +02:00
|
|
|
Pl390::read(PacketPtr pkt)
|
2010-08-23 18:18:40 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
Addr addr = pkt->getAddr();
|
|
|
|
|
|
|
|
if (addr >= distAddr && addr < distAddr + DIST_SIZE)
|
|
|
|
return readDistributor(pkt);
|
|
|
|
else if (addr >= cpuAddr && addr < cpuAddr + CPU_SIZE)
|
|
|
|
return readCpu(pkt);
|
|
|
|
else
|
|
|
|
panic("Read to unknown address %#x\n", pkt->getAddr());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Tick
|
2012-10-25 15:05:24 +02:00
|
|
|
Pl390::write(PacketPtr pkt)
|
2010-08-23 18:18:40 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
Addr addr = pkt->getAddr();
|
|
|
|
|
|
|
|
if (addr >= distAddr && addr < distAddr + DIST_SIZE)
|
|
|
|
return writeDistributor(pkt);
|
|
|
|
else if (addr >= cpuAddr && addr < cpuAddr + CPU_SIZE)
|
|
|
|
return writeCpu(pkt);
|
|
|
|
else
|
|
|
|
panic("Write to unknown address %#x\n", pkt->getAddr());
|
|
|
|
}
|
|
|
|
|
|
|
|
Tick
|
2012-10-25 15:05:24 +02:00
|
|
|
Pl390::readDistributor(PacketPtr pkt)
|
2010-08-23 18:18:40 +02:00
|
|
|
{
|
|
|
|
Addr daddr = pkt->getAddr() - distAddr;
|
|
|
|
|
2016-08-02 14:35:47 +02:00
|
|
|
ContextID ctx = pkt->req->contextId();
|
2011-08-19 22:08:05 +02:00
|
|
|
|
2011-05-05 03:38:27 +02:00
|
|
|
DPRINTF(GIC, "gic distributor read register %#x\n", daddr);
|
2010-08-23 18:18:40 +02:00
|
|
|
|
2016-08-02 14:35:45 +02:00
|
|
|
if (GICD_ISENABLER.contains(daddr)) {
|
|
|
|
uint32_t ix = (daddr - GICD_ISENABLER.start()) >> 2;
|
|
|
|
assert(ix < 32);
|
2016-08-02 14:35:47 +02:00
|
|
|
pkt->set<uint32_t>(getIntEnabled(ctx, ix));
|
2016-08-02 14:35:45 +02:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GICD_ICENABLER.contains(daddr)) {
|
|
|
|
uint32_t ix = (daddr - GICD_ICENABLER.start()) >> 2;
|
|
|
|
assert(ix < 32);
|
2016-08-02 14:35:47 +02:00
|
|
|
pkt->set<uint32_t>(getIntEnabled(ctx, ix));
|
2010-08-23 18:18:40 +02:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2016-08-02 14:35:45 +02:00
|
|
|
if (GICD_ISPENDR.contains(daddr)) {
|
|
|
|
uint32_t ix = (daddr - GICD_ISPENDR.start()) >> 2;
|
|
|
|
assert(ix < 32);
|
2016-08-02 14:35:47 +02:00
|
|
|
pkt->set<uint32_t>(getPendingInt(ctx, ix));
|
2010-08-23 18:18:40 +02:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2016-08-02 14:35:45 +02:00
|
|
|
if (GICD_ICPENDR.contains(daddr)) {
|
|
|
|
uint32_t ix = (daddr - GICD_ICPENDR.start()) >> 2;
|
|
|
|
assert(ix < 32);
|
2016-08-02 14:35:47 +02:00
|
|
|
pkt->set<uint32_t>(getPendingInt(ctx, ix));
|
2010-08-23 18:18:40 +02:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2016-08-02 14:35:45 +02:00
|
|
|
if (GICD_ISACTIVER.contains(daddr)) {
|
|
|
|
uint32_t ix = (daddr - GICD_ISACTIVER.start()) >> 2;
|
|
|
|
assert(ix < 32);
|
2016-08-02 14:35:47 +02:00
|
|
|
pkt->set<uint32_t>(getPendingInt(ctx, ix));
|
2010-08-23 18:18:40 +02:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2016-08-02 14:35:45 +02:00
|
|
|
if (GICD_ICACTIVER.contains(daddr)) {
|
|
|
|
uint32_t ix = (daddr - GICD_ICACTIVER.start()) >> 2;
|
|
|
|
assert(ix < 32);
|
2016-08-02 14:35:47 +02:00
|
|
|
pkt->set<uint32_t>(getPendingInt(ctx, ix));
|
2010-08-23 18:18:40 +02:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2016-08-02 14:35:45 +02:00
|
|
|
if (GICD_IPRIORITYR.contains(daddr)) {
|
|
|
|
Addr int_num = daddr - GICD_IPRIORITYR.start();
|
2011-05-05 03:38:27 +02:00
|
|
|
assert(int_num < INT_LINES_MAX);
|
2010-10-01 23:04:00 +02:00
|
|
|
DPRINTF(Interrupt, "Reading interrupt priority at int# %#x \n",int_num);
|
2011-08-19 22:08:05 +02:00
|
|
|
|
|
|
|
switch (pkt->getSize()) {
|
2010-10-01 23:04:00 +02:00
|
|
|
case 1:
|
2016-08-02 14:35:47 +02:00
|
|
|
pkt->set<uint8_t>(getIntPriority(ctx, int_num));
|
2010-10-01 23:04:00 +02:00
|
|
|
break;
|
|
|
|
case 2:
|
2012-06-05 07:23:08 +02:00
|
|
|
assert((int_num + 1) < INT_LINES_MAX);
|
2016-08-02 14:35:47 +02:00
|
|
|
pkt->set<uint16_t>(getIntPriority(ctx, int_num) |
|
|
|
|
getIntPriority(ctx, int_num+1) << 8);
|
2010-10-01 23:04:00 +02:00
|
|
|
break;
|
|
|
|
case 4:
|
2012-06-05 07:23:08 +02:00
|
|
|
assert((int_num + 3) < INT_LINES_MAX);
|
2016-08-02 14:35:47 +02:00
|
|
|
pkt->set<uint32_t>(getIntPriority(ctx, int_num) |
|
|
|
|
getIntPriority(ctx, int_num+1) << 8 |
|
|
|
|
getIntPriority(ctx, int_num+2) << 16 |
|
|
|
|
getIntPriority(ctx, int_num+3) << 24);
|
2010-10-01 23:04:00 +02:00
|
|
|
break;
|
|
|
|
default:
|
2011-05-05 03:38:27 +02:00
|
|
|
panic("Invalid size while reading priority regs in GIC: %d\n",
|
|
|
|
pkt->getSize());
|
2010-10-01 23:04:00 +02:00
|
|
|
}
|
2010-08-23 18:18:40 +02:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2016-08-02 14:35:45 +02:00
|
|
|
if (GICD_ITARGETSR.contains(daddr)) {
|
|
|
|
Addr int_num = daddr - GICD_ITARGETSR.start();
|
2011-05-05 03:38:27 +02:00
|
|
|
DPRINTF(GIC, "Reading processor target register for int# %#x \n",
|
|
|
|
int_num);
|
|
|
|
assert(int_num < INT_LINES_MAX);
|
2010-08-23 18:18:40 +02:00
|
|
|
|
2011-05-05 03:38:27 +02:00
|
|
|
// First 31 interrupts only target single processor (SGI)
|
2010-08-23 18:18:40 +02:00
|
|
|
if (int_num > 31) {
|
2011-05-05 03:38:27 +02:00
|
|
|
if (pkt->getSize() == 1) {
|
|
|
|
pkt->set<uint8_t>(cpuTarget[int_num]);
|
|
|
|
} else {
|
|
|
|
assert(pkt->getSize() == 4);
|
|
|
|
int_num = mbits(int_num, 31, 2);
|
|
|
|
pkt->set<uint32_t>(cpuTarget[int_num] |
|
|
|
|
cpuTarget[int_num+1] << 8 |
|
|
|
|
cpuTarget[int_num+2] << 16 |
|
|
|
|
cpuTarget[int_num+3] << 24) ;
|
|
|
|
}
|
2010-08-23 18:18:40 +02:00
|
|
|
} else {
|
2016-08-02 14:35:47 +02:00
|
|
|
assert(ctx < sys->numRunningContexts());
|
2015-09-18 17:49:28 +02:00
|
|
|
uint32_t ctx_mask;
|
|
|
|
if (gem5ExtensionsEnabled) {
|
2016-08-02 14:35:47 +02:00
|
|
|
ctx_mask = ctx;
|
2015-09-18 17:49:28 +02:00
|
|
|
} else {
|
2013-10-17 17:20:45 +02:00
|
|
|
// convert the CPU id number into a bit mask
|
2016-08-02 14:35:47 +02:00
|
|
|
ctx_mask = power(2, ctx);
|
2015-09-18 17:49:28 +02:00
|
|
|
}
|
2013-10-17 17:20:45 +02:00
|
|
|
// replicate the 8-bit mask 4 times in a 32-bit word
|
|
|
|
ctx_mask |= ctx_mask << 8;
|
|
|
|
ctx_mask |= ctx_mask << 16;
|
|
|
|
pkt->set<uint32_t>(ctx_mask);
|
2010-08-23 18:18:40 +02:00
|
|
|
}
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2016-08-02 14:35:45 +02:00
|
|
|
if (GICD_ICFGR.contains(daddr)) {
|
|
|
|
uint32_t ix = (daddr - GICD_ICFGR.start()) >> 2;
|
|
|
|
assert(ix < 64);
|
|
|
|
/** @todo software generated interrupts and PPIs
|
|
|
|
* can't be configured in some ways */
|
|
|
|
pkt->set<uint32_t>(intConfig[ix]);
|
2010-08-23 18:18:40 +02:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(daddr) {
|
2016-05-06 16:52:34 +02:00
|
|
|
case GICD_CTLR:
|
2010-08-23 18:18:40 +02:00
|
|
|
pkt->set<uint32_t>(enabled);
|
|
|
|
break;
|
2016-05-26 12:56:24 +02:00
|
|
|
case GICD_TYPER: {
|
2015-09-18 17:49:28 +02:00
|
|
|
/* The 0x100 is a made-up flag to show that gem5 extensions
|
|
|
|
* are available,
|
2016-08-02 14:35:45 +02:00
|
|
|
* write 0x200 to this register to enable it. */
|
2016-05-26 12:56:24 +02:00
|
|
|
uint32_t tmp = ((sys->numRunningContexts() - 1) << 5) |
|
|
|
|
(itLines/INT_BITS_MAX -1) |
|
|
|
|
(haveGem5Extensions ? 0x100 : 0x0);
|
2010-08-23 18:18:40 +02:00
|
|
|
pkt->set<uint32_t>(tmp);
|
2016-05-26 12:56:24 +02:00
|
|
|
} break;
|
2010-08-23 18:18:40 +02:00
|
|
|
default:
|
|
|
|
panic("Tried to read Gic distributor at offset %#x\n", daddr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
done:
|
|
|
|
pkt->makeAtomicResponse();
|
|
|
|
return distPioDelay;
|
|
|
|
}
|
|
|
|
|
|
|
|
Tick
|
2012-10-25 15:05:24 +02:00
|
|
|
Pl390::readCpu(PacketPtr pkt)
|
2010-08-23 18:18:40 +02:00
|
|
|
{
|
|
|
|
Addr daddr = pkt->getAddr() - cpuAddr;
|
|
|
|
|
2011-05-05 03:38:27 +02:00
|
|
|
assert(pkt->req->hasContextId());
|
2016-08-02 14:35:47 +02:00
|
|
|
ContextID ctx = pkt->req->contextId();
|
|
|
|
assert(ctx < sys->numRunningContexts());
|
2011-05-05 03:38:27 +02:00
|
|
|
|
|
|
|
DPRINTF(GIC, "gic cpu read register %#x cpu context: %d\n", daddr,
|
2016-08-02 14:35:47 +02:00
|
|
|
ctx);
|
2010-08-23 18:18:40 +02:00
|
|
|
|
|
|
|
switch(daddr) {
|
2016-05-06 16:52:34 +02:00
|
|
|
case GICC_IIDR:
|
2015-04-30 05:35:23 +02:00
|
|
|
pkt->set<uint32_t>(0);
|
|
|
|
break;
|
2016-05-06 16:52:34 +02:00
|
|
|
case GICC_CTLR:
|
2016-08-02 14:35:47 +02:00
|
|
|
pkt->set<uint32_t>(cpuEnabled[ctx]);
|
2010-08-23 18:18:40 +02:00
|
|
|
break;
|
2016-05-06 16:52:34 +02:00
|
|
|
case GICC_PMR:
|
2016-08-02 14:35:47 +02:00
|
|
|
pkt->set<uint32_t>(cpuPriority[ctx]);
|
2010-08-23 18:18:40 +02:00
|
|
|
break;
|
2016-05-06 16:52:34 +02:00
|
|
|
case GICC_BPR:
|
2016-08-02 14:35:47 +02:00
|
|
|
pkt->set<uint32_t>(cpuBpr[ctx]);
|
2010-08-23 18:18:40 +02:00
|
|
|
break;
|
2016-05-06 16:52:34 +02:00
|
|
|
case GICC_IAR:
|
2016-08-02 14:35:47 +02:00
|
|
|
if (enabled && cpuEnabled[ctx]) {
|
|
|
|
int active_int = cpuHighestInt[ctx];
|
2011-05-05 03:38:27 +02:00
|
|
|
IAR iar = 0;
|
|
|
|
iar.ack_id = active_int;
|
|
|
|
iar.cpu_id = 0;
|
|
|
|
if (active_int < SGI_MAX) {
|
|
|
|
// this is a software interrupt from another CPU
|
2015-09-18 17:49:28 +02:00
|
|
|
if (!gem5ExtensionsEnabled) {
|
|
|
|
panic_if(!cpuSgiPending[active_int],
|
|
|
|
"Interrupt %d active but no CPU generated it?\n",
|
2011-05-05 03:38:27 +02:00
|
|
|
active_int);
|
2015-09-18 17:49:28 +02:00
|
|
|
for (int x = 0; x < sys->numRunningContexts(); x++) {
|
|
|
|
// See which CPU generated the interrupt
|
|
|
|
uint8_t cpugen =
|
|
|
|
bits(cpuSgiPending[active_int], 7 + 8 * x, 8 * x);
|
2016-08-02 14:35:47 +02:00
|
|
|
if (cpugen & (1 << ctx)) {
|
2015-09-18 17:49:28 +02:00
|
|
|
iar.cpu_id = x;
|
|
|
|
break;
|
|
|
|
}
|
2011-05-05 03:38:27 +02:00
|
|
|
}
|
2016-08-02 14:35:47 +02:00
|
|
|
uint64_t sgi_num = ULL(1) << (ctx + 8 * iar.cpu_id);
|
2015-09-18 17:49:28 +02:00
|
|
|
cpuSgiActive[iar.ack_id] |= sgi_num;
|
|
|
|
cpuSgiPending[iar.ack_id] &= ~sgi_num;
|
|
|
|
} else {
|
|
|
|
uint64_t sgi_num = ULL(1) << iar.ack_id;
|
2016-08-02 14:35:47 +02:00
|
|
|
cpuSgiActiveExt[ctx] |= sgi_num;
|
|
|
|
cpuSgiPendingExt[ctx] &= ~sgi_num;
|
2011-05-05 03:38:27 +02:00
|
|
|
}
|
2011-08-19 22:08:05 +02:00
|
|
|
} else if (active_int < (SGI_MAX + PPI_MAX) ) {
|
2016-08-02 14:35:47 +02:00
|
|
|
uint32_t int_num = 1 << (cpuHighestInt[ctx] - SGI_MAX);
|
|
|
|
cpuPpiActive[ctx] |= int_num;
|
2011-08-19 22:08:05 +02:00
|
|
|
updateRunPri();
|
2016-08-02 14:35:47 +02:00
|
|
|
cpuPpiPending[ctx] &= ~int_num;
|
2011-08-19 22:08:05 +02:00
|
|
|
|
2011-05-05 03:38:27 +02:00
|
|
|
} else {
|
2016-08-02 14:35:47 +02:00
|
|
|
uint32_t int_num = 1 << intNumToBit(cpuHighestInt[ctx]);
|
|
|
|
getActiveInt(ctx, intNumToWord(cpuHighestInt[ctx])) |= int_num;
|
2011-05-05 03:38:27 +02:00
|
|
|
updateRunPri();
|
2016-08-02 14:35:47 +02:00
|
|
|
getPendingInt(ctx, intNumToWord(cpuHighestInt[ctx]))
|
2016-08-02 14:35:45 +02:00
|
|
|
&= ~int_num;
|
2011-05-05 03:38:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DPRINTF(Interrupt,"CPU %d reading IAR.id=%d IAR.cpu=%d, iar=0x%x\n",
|
2016-08-02 14:35:47 +02:00
|
|
|
ctx, iar.ack_id, iar.cpu_id, iar);
|
|
|
|
cpuHighestInt[ctx] = SPURIOUS_INT;
|
2010-10-01 23:04:00 +02:00
|
|
|
updateIntState(-1);
|
2011-05-05 03:38:27 +02:00
|
|
|
pkt->set<uint32_t>(iar);
|
2016-08-02 14:35:47 +02:00
|
|
|
platform->intrctrl->clear(ctx, ArmISA::INT_IRQ, 0);
|
2010-10-01 23:04:00 +02:00
|
|
|
} else {
|
|
|
|
pkt->set<uint32_t>(SPURIOUS_INT);
|
|
|
|
}
|
|
|
|
|
2010-08-23 18:18:40 +02:00
|
|
|
break;
|
2016-05-06 16:52:34 +02:00
|
|
|
case GICC_RPR:
|
2010-10-01 23:04:00 +02:00
|
|
|
pkt->set<uint32_t>(iccrpr[0]);
|
2010-08-23 18:18:40 +02:00
|
|
|
break;
|
2016-05-06 16:52:34 +02:00
|
|
|
case GICC_HPPIR:
|
2010-08-23 18:18:40 +02:00
|
|
|
pkt->set<uint32_t>(0);
|
|
|
|
panic("Need to implement HPIR");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
panic("Tried to read Gic cpu at offset %#x\n", daddr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pkt->makeAtomicResponse();
|
|
|
|
return cpuPioDelay;
|
|
|
|
}
|
|
|
|
|
|
|
|
Tick
|
2012-10-25 15:05:24 +02:00
|
|
|
Pl390::writeDistributor(PacketPtr pkt)
|
2010-08-23 18:18:40 +02:00
|
|
|
{
|
|
|
|
Addr daddr = pkt->getAddr() - distAddr;
|
|
|
|
|
2011-05-05 03:38:27 +02:00
|
|
|
assert(pkt->req->hasContextId());
|
2016-08-02 14:35:47 +02:00
|
|
|
ContextID ctx = pkt->req->contextId();
|
2011-05-05 03:38:27 +02:00
|
|
|
|
2014-09-03 13:42:27 +02:00
|
|
|
uint32_t pkt_data M5_VAR_USED;
|
|
|
|
switch (pkt->getSize())
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
pkt_data = pkt->get<uint8_t>();
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
pkt_data = pkt->get<uint16_t>();
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
pkt_data = pkt->get<uint32_t>();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
panic("Invalid size when writing to priority regs in Gic: %d\n",
|
|
|
|
pkt->getSize());
|
|
|
|
}
|
|
|
|
|
2011-05-05 03:38:27 +02:00
|
|
|
DPRINTF(GIC, "gic distributor write register %#x size %#x value %#x \n",
|
2014-09-03 13:42:27 +02:00
|
|
|
daddr, pkt->getSize(), pkt_data);
|
2010-08-23 18:18:40 +02:00
|
|
|
|
2016-08-02 14:35:45 +02:00
|
|
|
if (GICD_ISENABLER.contains(daddr)) {
|
|
|
|
uint32_t ix = (daddr - GICD_ISENABLER.start()) >> 2;
|
|
|
|
assert(ix < 32);
|
2016-08-02 14:35:47 +02:00
|
|
|
getIntEnabled(ctx, ix) |= pkt->get<uint32_t>();
|
2010-08-23 18:18:40 +02:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2016-08-02 14:35:45 +02:00
|
|
|
if (GICD_ICENABLER.contains(daddr)) {
|
|
|
|
uint32_t ix = (daddr - GICD_ICENABLER.start()) >> 2;
|
|
|
|
assert(ix < 32);
|
2016-08-02 14:35:47 +02:00
|
|
|
getIntEnabled(ctx, ix) &= ~pkt->get<uint32_t>();
|
2010-08-23 18:18:40 +02:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2016-08-02 14:35:45 +02:00
|
|
|
if (GICD_ISPENDR.contains(daddr)) {
|
|
|
|
uint32_t ix = (daddr - GICD_ISPENDR.start()) >> 2;
|
|
|
|
auto mask = pkt->get<uint32_t>();
|
|
|
|
if (ix == 0) mask &= SGI_MASK; // Don't allow SGIs to be changed
|
2016-08-02 14:35:47 +02:00
|
|
|
getPendingInt(ctx, ix) |= mask;
|
2016-08-02 14:35:45 +02:00
|
|
|
updateIntState(ix);
|
2010-08-23 18:18:40 +02:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2016-08-02 14:35:45 +02:00
|
|
|
if (GICD_ICPENDR.contains(daddr)) {
|
|
|
|
uint32_t ix = (daddr - GICD_ICPENDR.start()) >> 2;
|
|
|
|
auto mask = pkt->get<uint32_t>();
|
|
|
|
if (ix == 0) mask &= SGI_MASK; // Don't allow SGIs to be changed
|
2016-08-02 14:35:47 +02:00
|
|
|
getPendingInt(ctx, ix) &= ~mask;
|
2016-08-02 14:35:45 +02:00
|
|
|
updateIntState(ix);
|
2010-08-23 18:18:40 +02:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2016-08-02 14:35:45 +02:00
|
|
|
if (GICD_ISACTIVER.contains(daddr)) {
|
|
|
|
uint32_t ix = (daddr - GICD_ISACTIVER.start()) >> 2;
|
2016-08-02 14:35:47 +02:00
|
|
|
getActiveInt(ctx, ix) |= pkt->get<uint32_t>();
|
2016-08-02 14:35:45 +02:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GICD_ICACTIVER.contains(daddr)) {
|
|
|
|
uint32_t ix = (daddr - GICD_ICACTIVER.start()) >> 2;
|
2016-08-02 14:35:47 +02:00
|
|
|
getActiveInt(ctx, ix) &= ~pkt->get<uint32_t>();
|
2016-08-02 14:35:45 +02:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GICD_IPRIORITYR.contains(daddr)) {
|
|
|
|
Addr int_num = daddr - GICD_IPRIORITYR.start();
|
2011-05-05 03:38:27 +02:00
|
|
|
switch(pkt->getSize()) {
|
2010-10-01 23:04:00 +02:00
|
|
|
case 1:
|
2016-08-02 14:35:47 +02:00
|
|
|
getIntPriority(ctx, int_num) = pkt->get<uint8_t>();
|
2010-10-01 23:04:00 +02:00
|
|
|
break;
|
2016-08-02 14:35:45 +02:00
|
|
|
case 2: {
|
|
|
|
auto tmp16 = pkt->get<uint16_t>();
|
2016-08-02 14:35:47 +02:00
|
|
|
getIntPriority(ctx, int_num) = bits(tmp16, 7, 0);
|
|
|
|
getIntPriority(ctx, int_num + 1) = bits(tmp16, 15, 8);
|
2010-10-01 23:04:00 +02:00
|
|
|
break;
|
2016-08-02 14:35:45 +02:00
|
|
|
}
|
|
|
|
case 4: {
|
|
|
|
auto tmp32 = pkt->get<uint32_t>();
|
2016-08-02 14:35:47 +02:00
|
|
|
getIntPriority(ctx, int_num) = bits(tmp32, 7, 0);
|
|
|
|
getIntPriority(ctx, int_num + 1) = bits(tmp32, 15, 8);
|
|
|
|
getIntPriority(ctx, int_num + 2) = bits(tmp32, 23, 16);
|
|
|
|
getIntPriority(ctx, int_num + 3) = bits(tmp32, 31, 24);
|
2010-10-01 23:04:00 +02:00
|
|
|
break;
|
2016-08-02 14:35:45 +02:00
|
|
|
}
|
2010-10-01 23:04:00 +02:00
|
|
|
default:
|
2011-05-05 03:38:27 +02:00
|
|
|
panic("Invalid size when writing to priority regs in Gic: %d\n",
|
|
|
|
pkt->getSize());
|
2010-10-01 23:04:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
updateIntState(-1);
|
|
|
|
updateRunPri();
|
2010-08-23 18:18:40 +02:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2016-08-02 14:35:45 +02:00
|
|
|
if (GICD_ITARGETSR.contains(daddr)) {
|
|
|
|
Addr int_num = daddr - GICD_ITARGETSR.start();
|
2010-08-23 18:18:40 +02:00
|
|
|
// First 31 interrupts only target single processor
|
2011-05-05 03:38:27 +02:00
|
|
|
if (int_num >= SGI_MAX) {
|
|
|
|
if (pkt->getSize() == 1) {
|
|
|
|
uint8_t tmp = pkt->get<uint8_t>();
|
|
|
|
cpuTarget[int_num] = tmp & 0xff;
|
|
|
|
} else {
|
|
|
|
assert (pkt->getSize() == 4);
|
|
|
|
int_num = mbits(int_num, 31, 2);
|
|
|
|
uint32_t tmp = pkt->get<uint32_t>();
|
|
|
|
cpuTarget[int_num] = bits(tmp, 7, 0);
|
|
|
|
cpuTarget[int_num+1] = bits(tmp, 15, 8);
|
|
|
|
cpuTarget[int_num+2] = bits(tmp, 23, 16);
|
|
|
|
cpuTarget[int_num+3] = bits(tmp, 31, 24);
|
|
|
|
}
|
2016-08-02 14:35:45 +02:00
|
|
|
updateIntState(int_num >> 2);
|
2010-08-23 18:18:40 +02:00
|
|
|
}
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2016-08-02 14:35:45 +02:00
|
|
|
if (GICD_ICFGR.contains(daddr)) {
|
|
|
|
uint32_t ix = (daddr - GICD_ICFGR.start()) >> 2;
|
|
|
|
assert(ix < INT_BITS_MAX*2);
|
|
|
|
intConfig[ix] = pkt->get<uint32_t>();
|
2011-05-05 03:38:27 +02:00
|
|
|
if (pkt->get<uint32_t>() & NN_CONFIG_MASK)
|
|
|
|
warn("GIC N:N mode selected and not supported at this time\n");
|
2010-08-23 18:18:40 +02:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(daddr) {
|
2016-05-06 16:52:34 +02:00
|
|
|
case GICD_CTLR:
|
2010-08-23 18:18:40 +02:00
|
|
|
enabled = pkt->get<uint32_t>();
|
2010-10-01 23:04:00 +02:00
|
|
|
DPRINTF(Interrupt, "Distributor enable flag set to = %d\n", enabled);
|
2010-08-23 18:18:40 +02:00
|
|
|
break;
|
2016-05-06 16:52:34 +02:00
|
|
|
case GICD_TYPER:
|
2015-09-18 17:49:28 +02:00
|
|
|
/* 0x200 is a made-up flag to enable gem5 extension functionality.
|
|
|
|
* This reg is not normally written.
|
|
|
|
*/
|
2016-05-26 12:56:24 +02:00
|
|
|
gem5ExtensionsEnabled = (
|
|
|
|
(pkt->get<uint32_t>() & 0x200) && haveGem5Extensions);
|
|
|
|
DPRINTF(GIC, "gem5 extensions %s\n",
|
|
|
|
gem5ExtensionsEnabled ? "enabled" : "disabled");
|
2015-09-18 17:49:28 +02:00
|
|
|
break;
|
2016-05-06 16:52:34 +02:00
|
|
|
case GICD_SGIR:
|
2016-08-02 14:35:47 +02:00
|
|
|
softInt(ctx, pkt->get<uint32_t>());
|
2010-08-23 18:18:40 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
panic("Tried to write Gic distributor at offset %#x\n", daddr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
pkt->makeAtomicResponse();
|
|
|
|
return distPioDelay;
|
|
|
|
}
|
|
|
|
|
|
|
|
Tick
|
2012-10-25 15:05:24 +02:00
|
|
|
Pl390::writeCpu(PacketPtr pkt)
|
2010-08-23 18:18:40 +02:00
|
|
|
{
|
|
|
|
Addr daddr = pkt->getAddr() - cpuAddr;
|
|
|
|
|
2011-05-05 03:38:27 +02:00
|
|
|
assert(pkt->req->hasContextId());
|
2016-08-02 14:35:47 +02:00
|
|
|
ContextID ctx = pkt->req->contextId();
|
2011-05-05 03:38:27 +02:00
|
|
|
IAR iar;
|
|
|
|
|
|
|
|
DPRINTF(GIC, "gic cpu write register cpu:%d %#x val: %#x\n",
|
2016-08-02 14:35:47 +02:00
|
|
|
ctx, daddr, pkt->get<uint32_t>());
|
2010-08-23 18:18:40 +02:00
|
|
|
|
|
|
|
switch(daddr) {
|
2016-05-06 16:52:34 +02:00
|
|
|
case GICC_CTLR:
|
2016-08-02 14:35:47 +02:00
|
|
|
cpuEnabled[ctx] = pkt->get<uint32_t>();
|
2010-08-23 18:18:40 +02:00
|
|
|
break;
|
2016-05-06 16:52:34 +02:00
|
|
|
case GICC_PMR:
|
2016-08-02 14:35:47 +02:00
|
|
|
cpuPriority[ctx] = pkt->get<uint32_t>();
|
2010-08-23 18:18:40 +02:00
|
|
|
break;
|
2016-05-06 16:52:34 +02:00
|
|
|
case GICC_BPR:
|
2016-08-02 14:35:47 +02:00
|
|
|
cpuBpr[ctx] = pkt->get<uint32_t>();
|
2010-08-23 18:18:40 +02:00
|
|
|
break;
|
2016-05-06 16:52:34 +02:00
|
|
|
case GICC_EOIR:
|
2011-05-05 03:38:27 +02:00
|
|
|
iar = pkt->get<uint32_t>();
|
|
|
|
if (iar.ack_id < SGI_MAX) {
|
2017-02-14 22:09:18 +01:00
|
|
|
// Clear out the bit that corresponds to the cleared int
|
2016-08-02 14:35:47 +02:00
|
|
|
uint64_t clr_int = ULL(1) << (ctx + 8 * iar.cpu_id);
|
2015-09-18 17:49:28 +02:00
|
|
|
if (!(cpuSgiActive[iar.ack_id] & clr_int) &&
|
2016-08-02 14:35:47 +02:00
|
|
|
!(cpuSgiActiveExt[ctx] & (1 << iar.ack_id)))
|
2011-05-05 03:38:27 +02:00
|
|
|
panic("Done handling a SGI that isn't active?\n");
|
2015-09-18 17:49:28 +02:00
|
|
|
if (gem5ExtensionsEnabled)
|
2016-08-02 14:35:47 +02:00
|
|
|
cpuSgiActiveExt[ctx] &= ~(1 << iar.ack_id);
|
2015-09-18 17:49:28 +02:00
|
|
|
else
|
|
|
|
cpuSgiActive[iar.ack_id] &= ~clr_int;
|
2011-08-19 22:08:05 +02:00
|
|
|
} else if (iar.ack_id < (SGI_MAX + PPI_MAX) ) {
|
|
|
|
uint32_t int_num = 1 << (iar.ack_id - SGI_MAX);
|
2016-08-02 14:35:47 +02:00
|
|
|
if (!(cpuPpiActive[ctx] & int_num))
|
2015-09-18 17:49:28 +02:00
|
|
|
panic("CPU %d Done handling a PPI interrupt "
|
2016-08-02 14:35:47 +02:00
|
|
|
"that isn't active?\n", ctx);
|
|
|
|
cpuPpiActive[ctx] &= ~int_num;
|
2011-05-05 03:38:27 +02:00
|
|
|
} else {
|
|
|
|
uint32_t int_num = 1 << intNumToBit(iar.ack_id);
|
2016-08-02 14:35:47 +02:00
|
|
|
if (!(getActiveInt(ctx, intNumToWord(iar.ack_id)) & int_num))
|
2015-04-30 05:35:23 +02:00
|
|
|
warn("Done handling interrupt that isn't active: %d\n",
|
|
|
|
intNumToBit(iar.ack_id));
|
2016-08-02 14:35:47 +02:00
|
|
|
getActiveInt(ctx, intNumToWord(iar.ack_id)) &= ~int_num;
|
2011-05-05 03:38:27 +02:00
|
|
|
}
|
2010-10-01 23:04:00 +02:00
|
|
|
updateRunPri();
|
2011-05-05 03:38:27 +02:00
|
|
|
DPRINTF(Interrupt, "CPU %d done handling intr IAR = %d from cpu %d\n",
|
2016-08-02 14:35:47 +02:00
|
|
|
ctx, iar.ack_id, iar.cpu_id);
|
2010-08-23 18:18:40 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
panic("Tried to write Gic cpu at offset %#x\n", daddr);
|
|
|
|
break;
|
|
|
|
}
|
2016-08-02 14:35:47 +02:00
|
|
|
if (cpuEnabled[ctx]) updateIntState(-1);
|
2010-08-23 18:18:40 +02:00
|
|
|
pkt->makeAtomicResponse();
|
|
|
|
return cpuPioDelay;
|
|
|
|
}
|
|
|
|
|
2016-08-02 14:35:45 +02:00
|
|
|
Pl390::BankedRegs&
|
2016-08-02 14:35:47 +02:00
|
|
|
Pl390::getBankedRegs(ContextID ctx) {
|
|
|
|
if (bankedRegs.size() <= ctx)
|
|
|
|
bankedRegs.resize(ctx + 1);
|
2016-08-02 14:35:45 +02:00
|
|
|
|
2016-08-02 14:35:47 +02:00
|
|
|
if (!bankedRegs[ctx])
|
|
|
|
bankedRegs[ctx] = new BankedRegs;
|
|
|
|
return *bankedRegs[ctx];
|
2016-08-02 14:35:45 +02:00
|
|
|
}
|
|
|
|
|
2010-08-23 18:18:40 +02:00
|
|
|
void
|
2016-08-02 14:35:47 +02:00
|
|
|
Pl390::softInt(ContextID ctx, SWI swi)
|
2010-08-23 18:18:40 +02:00
|
|
|
{
|
2015-09-18 17:49:28 +02:00
|
|
|
if (gem5ExtensionsEnabled) {
|
|
|
|
switch (swi.list_type) {
|
|
|
|
case 0: {
|
|
|
|
// interrupt cpus specified
|
|
|
|
int dest = swi.cpu_list;
|
|
|
|
DPRINTF(IPI, "Generating softIRQ from CPU %d for CPU %d\n",
|
2016-08-02 14:35:47 +02:00
|
|
|
ctx, dest);
|
2015-09-18 17:49:28 +02:00
|
|
|
if (cpuEnabled[dest]) {
|
|
|
|
cpuSgiPendingExt[dest] |= (1 << swi.sgi_id);
|
|
|
|
DPRINTF(IPI, "SGI[%d]=%#x\n", dest,
|
|
|
|
cpuSgiPendingExt[dest]);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case 1: {
|
|
|
|
// interrupt all
|
|
|
|
for (int i = 0; i < sys->numContexts(); i++) {
|
|
|
|
DPRINTF(IPI, "Processing CPU %d\n", i);
|
|
|
|
if (!cpuEnabled[i])
|
|
|
|
continue;
|
|
|
|
cpuSgiPendingExt[i] |= 1 << swi.sgi_id;
|
|
|
|
DPRINTF(IPI, "SGI[%d]=%#x\n", swi.sgi_id,
|
|
|
|
cpuSgiPendingExt[i]);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case 2: {
|
|
|
|
// Interrupt requesting cpu only
|
|
|
|
DPRINTF(IPI, "Generating softIRQ from CPU %d for CPU %d\n",
|
2016-08-02 14:35:47 +02:00
|
|
|
ctx, ctx);
|
|
|
|
if (cpuEnabled[ctx]) {
|
|
|
|
cpuSgiPendingExt[ctx] |= (1 << swi.sgi_id);
|
|
|
|
DPRINTF(IPI, "SGI[%d]=%#x\n", ctx,
|
|
|
|
cpuSgiPendingExt[ctx]);
|
2015-09-18 17:49:28 +02:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (swi.list_type) {
|
|
|
|
case 1:
|
|
|
|
// interrupt all
|
|
|
|
uint8_t cpu_list;
|
|
|
|
cpu_list = 0;
|
|
|
|
for (int x = 0; x < sys->numContexts(); x++)
|
|
|
|
cpu_list |= cpuEnabled[x] ? 1 << x : 0;
|
|
|
|
swi.cpu_list = cpu_list;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
// interrupt requesting cpu only
|
2016-08-02 14:35:47 +02:00
|
|
|
swi.cpu_list = 1 << ctx;
|
2015-09-18 17:49:28 +02:00
|
|
|
break;
|
|
|
|
// else interrupt cpus specified
|
|
|
|
}
|
2011-05-05 03:38:27 +02:00
|
|
|
|
2016-08-02 14:35:47 +02:00
|
|
|
DPRINTF(IPI, "Generating softIRQ from CPU %d for %#x\n", ctx,
|
2015-09-18 17:49:28 +02:00
|
|
|
swi.cpu_list);
|
|
|
|
for (int i = 0; i < sys->numContexts(); i++) {
|
|
|
|
DPRINTF(IPI, "Processing CPU %d\n", i);
|
|
|
|
if (!cpuEnabled[i])
|
|
|
|
continue;
|
|
|
|
if (swi.cpu_list & (1 << i))
|
2016-08-02 14:35:47 +02:00
|
|
|
cpuSgiPending[swi.sgi_id] |= (1 << i) << (8 * ctx);
|
2015-09-18 17:49:28 +02:00
|
|
|
DPRINTF(IPI, "SGI[%d]=%#x\n", swi.sgi_id,
|
|
|
|
cpuSgiPending[swi.sgi_id]);
|
|
|
|
}
|
2011-05-05 03:38:27 +02:00
|
|
|
}
|
|
|
|
updateIntState(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
2012-10-25 15:05:24 +02:00
|
|
|
Pl390::genSwiMask(int cpu)
|
2011-05-05 03:38:27 +02:00
|
|
|
{
|
2015-09-18 17:49:28 +02:00
|
|
|
if (cpu > sys->numContexts())
|
2011-05-05 03:38:27 +02:00
|
|
|
panic("Invalid CPU ID\n");
|
|
|
|
return ULL(0x0101010101010101) << cpu;
|
2010-08-23 18:18:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-10-25 15:05:24 +02:00
|
|
|
Pl390::updateIntState(int hint)
|
2010-08-23 18:18:40 +02:00
|
|
|
{
|
2015-09-18 17:49:28 +02:00
|
|
|
for (int cpu = 0; cpu < sys->numContexts(); cpu++) {
|
2011-05-05 03:38:27 +02:00
|
|
|
if (!cpuEnabled[cpu])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/*@todo use hint to do less work. */
|
|
|
|
int highest_int = SPURIOUS_INT;
|
2016-05-06 16:52:34 +02:00
|
|
|
// Priorities below that set in GICC_PMR can be ignored
|
2011-05-05 03:38:27 +02:00
|
|
|
uint8_t highest_pri = cpuPriority[cpu];
|
|
|
|
|
|
|
|
// Check SGIs
|
|
|
|
for (int swi = 0; swi < SGI_MAX; swi++) {
|
2015-09-18 17:49:28 +02:00
|
|
|
if (!cpuSgiPending[swi] && !cpuSgiPendingExt[cpu])
|
2011-05-05 03:38:27 +02:00
|
|
|
continue;
|
2015-09-18 17:49:28 +02:00
|
|
|
if ((cpuSgiPending[swi] & genSwiMask(cpu)) ||
|
|
|
|
(cpuSgiPendingExt[cpu] & (1 << swi)))
|
2016-08-02 14:35:45 +02:00
|
|
|
if (highest_pri > getIntPriority(cpu, swi)) {
|
|
|
|
highest_pri = getIntPriority(cpu, swi);
|
2011-05-05 03:38:27 +02:00
|
|
|
highest_int = swi;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-19 22:08:05 +02:00
|
|
|
// Check PPIs
|
|
|
|
if (cpuPpiPending[cpu]) {
|
|
|
|
for (int ppi = 0; ppi < PPI_MAX; ppi++) {
|
|
|
|
if (cpuPpiPending[cpu] & (1 << ppi))
|
2016-08-02 14:35:45 +02:00
|
|
|
if (highest_pri > getIntPriority(cpu, SGI_MAX + ppi)) {
|
|
|
|
highest_pri = getIntPriority(cpu, SGI_MAX + ppi);
|
2011-08-19 22:08:05 +02:00
|
|
|
highest_int = SGI_MAX + ppi;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-05 03:38:27 +02:00
|
|
|
bool mp_sys = sys->numRunningContexts() > 1;
|
|
|
|
// Check other ints
|
2011-08-19 22:08:05 +02:00
|
|
|
for (int x = 0; x < (itLines/INT_BITS_MAX); x++) {
|
2016-08-02 14:35:45 +02:00
|
|
|
if (getIntEnabled(cpu, x) & getPendingInt(cpu, x)) {
|
2011-05-05 03:38:27 +02:00
|
|
|
for (int y = 0; y < INT_BITS_MAX; y++) {
|
|
|
|
uint32_t int_nm = x * INT_BITS_MAX + y;
|
|
|
|
DPRINTF(GIC, "Checking for interrupt# %d \n",int_nm);
|
|
|
|
/* Set current pending int as highest int for current cpu
|
2016-08-02 14:35:45 +02:00
|
|
|
if the interrupt's priority higher than current priority
|
2017-02-14 22:09:18 +01:00
|
|
|
and if current cpu is the target (for mp configs only)
|
2011-05-05 03:38:27 +02:00
|
|
|
*/
|
2016-08-02 14:35:45 +02:00
|
|
|
if ((bits(getIntEnabled(cpu, x), y)
|
|
|
|
&bits(getPendingInt(cpu, x), y)) &&
|
|
|
|
(getIntPriority(cpu, int_nm) < highest_pri))
|
|
|
|
if ((!mp_sys) ||
|
|
|
|
(gem5ExtensionsEnabled
|
|
|
|
? (cpuTarget[int_nm] == cpu)
|
|
|
|
: (cpuTarget[int_nm] & (1 << cpu)))) {
|
|
|
|
highest_pri = getIntPriority(cpu, int_nm);
|
2011-05-05 03:38:27 +02:00
|
|
|
highest_int = int_nm;
|
|
|
|
}
|
|
|
|
}
|
2010-08-23 18:18:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-05 03:38:27 +02:00
|
|
|
cpuHighestInt[cpu] = highest_int;
|
2010-08-23 18:18:40 +02:00
|
|
|
|
2011-05-05 03:38:27 +02:00
|
|
|
if (highest_int == SPURIOUS_INT)
|
|
|
|
continue;
|
2010-08-23 18:18:40 +02:00
|
|
|
|
2011-05-05 03:38:27 +02:00
|
|
|
/* @todo make this work for more than one cpu, need to handle 1:N, N:N
|
|
|
|
* models */
|
|
|
|
if (enabled && cpuEnabled[cpu] && (highest_pri < cpuPriority[cpu]) &&
|
2016-08-02 14:35:45 +02:00
|
|
|
!(getActiveInt(cpu, intNumToWord(highest_int))
|
|
|
|
& (1 << intNumToBit(highest_int)))) {
|
2010-08-23 18:18:40 +02:00
|
|
|
|
2011-05-05 03:38:27 +02:00
|
|
|
DPRINTF(Interrupt, "Posting interrupt %d to cpu%d\n", highest_int,
|
|
|
|
cpu);
|
|
|
|
postInt(cpu, curTick() + intLatency);
|
|
|
|
}
|
2010-08-23 18:18:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-01 23:04:00 +02:00
|
|
|
void
|
2012-10-25 15:05:24 +02:00
|
|
|
Pl390::updateRunPri()
|
2010-10-01 23:04:00 +02:00
|
|
|
{
|
2015-09-18 17:49:28 +02:00
|
|
|
for (int cpu = 0; cpu < sys->numContexts(); cpu++) {
|
2011-08-19 22:08:05 +02:00
|
|
|
if (!cpuEnabled[cpu])
|
|
|
|
continue;
|
2011-05-05 03:38:27 +02:00
|
|
|
uint8_t maxPriority = 0xff;
|
2016-08-02 14:35:45 +02:00
|
|
|
for (int i = 0; i < itLines; i++) {
|
2011-05-05 03:38:27 +02:00
|
|
|
if (i < SGI_MAX) {
|
2015-09-18 17:49:28 +02:00
|
|
|
if (((cpuSgiActive[i] & genSwiMask(cpu)) ||
|
|
|
|
(cpuSgiActiveExt[cpu] & (1 << i))) &&
|
2016-08-02 14:35:45 +02:00
|
|
|
(getIntPriority(cpu, i) < maxPriority))
|
|
|
|
maxPriority = getIntPriority(cpu, i);
|
2011-08-19 22:08:05 +02:00
|
|
|
} else if (i < (SGI_MAX + PPI_MAX)) {
|
|
|
|
if ((cpuPpiActive[cpu] & ( 1 << (i - SGI_MAX))) &&
|
2016-08-02 14:35:45 +02:00
|
|
|
(getIntPriority(cpu, i) < maxPriority))
|
|
|
|
maxPriority = getIntPriority(cpu, i);
|
2011-08-19 22:08:05 +02:00
|
|
|
|
2011-05-05 03:38:27 +02:00
|
|
|
} else {
|
2016-08-02 14:35:45 +02:00
|
|
|
if (getActiveInt(cpu, intNumToWord(i))
|
|
|
|
& (1 << intNumToBit(i)))
|
|
|
|
if (getIntPriority(cpu, i) < maxPriority)
|
|
|
|
maxPriority = getIntPriority(cpu, i);
|
2011-05-05 03:38:27 +02:00
|
|
|
}
|
2010-10-01 23:04:00 +02:00
|
|
|
}
|
2011-05-05 03:38:27 +02:00
|
|
|
iccrpr[cpu] = maxPriority;
|
2010-10-01 23:04:00 +02:00
|
|
|
}
|
|
|
|
}
|
2011-05-05 03:38:27 +02:00
|
|
|
|
2010-08-23 18:18:40 +02:00
|
|
|
void
|
2012-10-25 15:05:24 +02:00
|
|
|
Pl390::sendInt(uint32_t num)
|
2010-08-23 18:18:40 +02:00
|
|
|
{
|
2017-02-14 22:09:18 +01:00
|
|
|
DPRINTF(Interrupt, "Received Interrupt number %d, cpuTarget %#x: \n",
|
2011-05-05 03:38:27 +02:00
|
|
|
num, cpuTarget[num]);
|
2015-09-18 17:49:28 +02:00
|
|
|
if ((cpuTarget[num] & (cpuTarget[num] - 1)) && !gem5ExtensionsEnabled)
|
2011-05-05 03:38:27 +02:00
|
|
|
panic("Multiple targets for peripheral interrupts is not supported\n");
|
2016-08-02 14:35:45 +02:00
|
|
|
panic_if(num < SGI_MAX + PPI_MAX,
|
|
|
|
"sentInt() must only be used for interrupts 32 and higher");
|
|
|
|
getPendingInt(cpuTarget[num], intNumToWord(num)) |= 1 << intNumToBit(num);
|
2010-08-23 18:18:40 +02:00
|
|
|
updateIntState(intNumToWord(num));
|
|
|
|
}
|
|
|
|
|
2011-08-19 22:08:05 +02:00
|
|
|
void
|
2012-10-25 15:05:24 +02:00
|
|
|
Pl390::sendPPInt(uint32_t num, uint32_t cpu)
|
2011-08-19 22:08:05 +02:00
|
|
|
{
|
2013-10-17 17:20:45 +02:00
|
|
|
DPRINTF(Interrupt, "Received PPI %d, cpuTarget %#x: \n",
|
2011-08-19 22:08:05 +02:00
|
|
|
num, cpu);
|
2011-08-19 22:08:05 +02:00
|
|
|
cpuPpiPending[cpu] |= 1 << (num - SGI_MAX);
|
|
|
|
updateIntState(intNumToWord(num));
|
|
|
|
}
|
|
|
|
|
2010-08-23 18:18:40 +02:00
|
|
|
void
|
2012-10-25 15:05:24 +02:00
|
|
|
Pl390::clearInt(uint32_t number)
|
2010-08-23 18:18:40 +02:00
|
|
|
{
|
|
|
|
/* @todo assume edge triggered only at the moment. Nothing to do. */
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:20:45 +02:00
|
|
|
void
|
|
|
|
Pl390::clearPPInt(uint32_t num, uint32_t cpu)
|
|
|
|
{
|
|
|
|
DPRINTF(Interrupt, "Clearing PPI %d, cpuTarget %#x: \n",
|
|
|
|
num, cpu);
|
|
|
|
cpuPpiPending[cpu] &= ~(1 << (num - SGI_MAX));
|
|
|
|
updateIntState(intNumToWord(num));
|
|
|
|
}
|
|
|
|
|
2011-05-05 03:38:27 +02:00
|
|
|
void
|
2012-10-25 15:05:24 +02:00
|
|
|
Pl390::postInt(uint32_t cpu, Tick when)
|
2011-05-05 03:38:27 +02:00
|
|
|
{
|
|
|
|
if (!(postIntEvent[cpu]->scheduled()))
|
|
|
|
eventq->schedule(postIntEvent[cpu], when);
|
|
|
|
}
|
|
|
|
|
2012-01-17 19:55:09 +01:00
|
|
|
AddrRangeList
|
2012-10-25 15:05:24 +02:00
|
|
|
Pl390::getAddrRanges() const
|
2010-08-23 18:18:40 +02:00
|
|
|
{
|
2012-01-17 19:55:09 +01:00
|
|
|
AddrRangeList ranges;
|
|
|
|
ranges.push_back(RangeSize(distAddr, DIST_SIZE));
|
|
|
|
ranges.push_back(RangeSize(cpuAddr, CPU_SIZE));
|
|
|
|
return ranges;
|
2010-08-23 18:18:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2015-07-07 10:51:03 +02:00
|
|
|
Pl390::serialize(CheckpointOut &cp) const
|
2010-08-23 18:18:40 +02:00
|
|
|
{
|
2010-11-08 20:58:25 +01:00
|
|
|
DPRINTF(Checkpoint, "Serializing Arm GIC\n");
|
|
|
|
|
|
|
|
SERIALIZE_SCALAR(distAddr);
|
|
|
|
SERIALIZE_SCALAR(cpuAddr);
|
|
|
|
SERIALIZE_SCALAR(distPioDelay);
|
|
|
|
SERIALIZE_SCALAR(cpuPioDelay);
|
|
|
|
SERIALIZE_SCALAR(enabled);
|
|
|
|
SERIALIZE_SCALAR(itLines);
|
2016-08-02 14:35:45 +02:00
|
|
|
SERIALIZE_ARRAY(intEnabled, INT_BITS_MAX-1);
|
|
|
|
SERIALIZE_ARRAY(pendingInt, INT_BITS_MAX-1);
|
|
|
|
SERIALIZE_ARRAY(activeInt, INT_BITS_MAX-1);
|
2011-05-05 03:38:27 +02:00
|
|
|
SERIALIZE_ARRAY(iccrpr, CPU_MAX);
|
2016-08-02 14:35:45 +02:00
|
|
|
SERIALIZE_ARRAY(intPriority, GLOBAL_INT_LINES);
|
|
|
|
SERIALIZE_ARRAY(cpuTarget, GLOBAL_INT_LINES);
|
2011-05-05 03:38:27 +02:00
|
|
|
SERIALIZE_ARRAY(intConfig, INT_BITS_MAX * 2);
|
|
|
|
SERIALIZE_ARRAY(cpuEnabled, CPU_MAX);
|
|
|
|
SERIALIZE_ARRAY(cpuPriority, CPU_MAX);
|
|
|
|
SERIALIZE_ARRAY(cpuBpr, CPU_MAX);
|
|
|
|
SERIALIZE_ARRAY(cpuHighestInt, CPU_MAX);
|
|
|
|
SERIALIZE_ARRAY(cpuSgiActive, SGI_MAX);
|
|
|
|
SERIALIZE_ARRAY(cpuSgiPending, SGI_MAX);
|
2015-09-18 17:49:28 +02:00
|
|
|
SERIALIZE_ARRAY(cpuSgiActiveExt, CPU_MAX);
|
|
|
|
SERIALIZE_ARRAY(cpuSgiPendingExt, CPU_MAX);
|
2011-08-19 22:08:05 +02:00
|
|
|
SERIALIZE_ARRAY(cpuPpiActive, CPU_MAX);
|
|
|
|
SERIALIZE_ARRAY(cpuPpiPending, CPU_MAX);
|
2010-11-08 20:58:25 +01:00
|
|
|
SERIALIZE_SCALAR(irqEnable);
|
2011-05-05 03:38:27 +02:00
|
|
|
Tick interrupt_time[CPU_MAX];
|
|
|
|
for (uint32_t cpu = 0; cpu < CPU_MAX; cpu++) {
|
|
|
|
interrupt_time[cpu] = 0;
|
|
|
|
if (postIntEvent[cpu]->scheduled()) {
|
|
|
|
interrupt_time[cpu] = postIntEvent[cpu]->when();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SERIALIZE_ARRAY(interrupt_time, CPU_MAX);
|
2015-09-18 17:49:28 +02:00
|
|
|
SERIALIZE_SCALAR(gem5ExtensionsEnabled);
|
2016-08-02 14:35:45 +02:00
|
|
|
|
|
|
|
for (uint32_t i=0; i < bankedRegs.size(); ++i) {
|
|
|
|
if (!bankedRegs[i])
|
|
|
|
continue;
|
|
|
|
bankedRegs[i]->serializeSection(cp, csprintf("bankedRegs%i", i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Pl390::BankedRegs::serialize(CheckpointOut &cp) const
|
|
|
|
{
|
|
|
|
SERIALIZE_SCALAR(intEnabled);
|
|
|
|
SERIALIZE_SCALAR(pendingInt);
|
|
|
|
SERIALIZE_SCALAR(activeInt);
|
|
|
|
SERIALIZE_ARRAY(intPriority, SGI_MAX + PPI_MAX);
|
|
|
|
SERIALIZE_ARRAY(cpuTarget, SGI_MAX + PPI_MAX);
|
2010-08-23 18:18:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-07-07 10:51:03 +02:00
|
|
|
Pl390::unserialize(CheckpointIn &cp)
|
2010-08-23 18:18:40 +02:00
|
|
|
{
|
2010-11-08 20:58:25 +01:00
|
|
|
DPRINTF(Checkpoint, "Unserializing Arm GIC\n");
|
|
|
|
|
|
|
|
UNSERIALIZE_SCALAR(distAddr);
|
|
|
|
UNSERIALIZE_SCALAR(cpuAddr);
|
|
|
|
UNSERIALIZE_SCALAR(distPioDelay);
|
|
|
|
UNSERIALIZE_SCALAR(cpuPioDelay);
|
|
|
|
UNSERIALIZE_SCALAR(enabled);
|
|
|
|
UNSERIALIZE_SCALAR(itLines);
|
2016-08-02 14:35:45 +02:00
|
|
|
UNSERIALIZE_ARRAY(intEnabled, INT_BITS_MAX-1);
|
|
|
|
UNSERIALIZE_ARRAY(pendingInt, INT_BITS_MAX-1);
|
|
|
|
UNSERIALIZE_ARRAY(activeInt, INT_BITS_MAX-1);
|
2011-05-05 03:38:27 +02:00
|
|
|
UNSERIALIZE_ARRAY(iccrpr, CPU_MAX);
|
2016-08-02 14:35:45 +02:00
|
|
|
UNSERIALIZE_ARRAY(intPriority, GLOBAL_INT_LINES);
|
|
|
|
UNSERIALIZE_ARRAY(cpuTarget, GLOBAL_INT_LINES);
|
2011-05-05 03:38:27 +02:00
|
|
|
UNSERIALIZE_ARRAY(intConfig, INT_BITS_MAX * 2);
|
|
|
|
UNSERIALIZE_ARRAY(cpuEnabled, CPU_MAX);
|
|
|
|
UNSERIALIZE_ARRAY(cpuPriority, CPU_MAX);
|
|
|
|
UNSERIALIZE_ARRAY(cpuBpr, CPU_MAX);
|
|
|
|
UNSERIALIZE_ARRAY(cpuHighestInt, CPU_MAX);
|
|
|
|
UNSERIALIZE_ARRAY(cpuSgiActive, SGI_MAX);
|
|
|
|
UNSERIALIZE_ARRAY(cpuSgiPending, SGI_MAX);
|
2015-09-18 17:49:28 +02:00
|
|
|
UNSERIALIZE_ARRAY(cpuSgiActiveExt, CPU_MAX);
|
|
|
|
UNSERIALIZE_ARRAY(cpuSgiPendingExt, CPU_MAX);
|
2011-08-19 22:08:05 +02:00
|
|
|
UNSERIALIZE_ARRAY(cpuPpiActive, CPU_MAX);
|
|
|
|
UNSERIALIZE_ARRAY(cpuPpiPending, CPU_MAX);
|
2010-11-08 20:58:25 +01:00
|
|
|
UNSERIALIZE_SCALAR(irqEnable);
|
2011-05-05 03:38:27 +02:00
|
|
|
|
|
|
|
Tick interrupt_time[CPU_MAX];
|
|
|
|
UNSERIALIZE_ARRAY(interrupt_time, CPU_MAX);
|
|
|
|
|
|
|
|
for (uint32_t cpu = 0; cpu < CPU_MAX; cpu++) {
|
|
|
|
if (interrupt_time[cpu])
|
|
|
|
schedule(postIntEvent[cpu], interrupt_time[cpu]);
|
|
|
|
}
|
2015-09-18 17:49:28 +02:00
|
|
|
if (!UNSERIALIZE_OPT_SCALAR(gem5ExtensionsEnabled))
|
|
|
|
gem5ExtensionsEnabled = false;
|
2016-08-02 14:35:45 +02:00
|
|
|
|
|
|
|
for (uint32_t i=0; i < CPU_MAX; ++i) {
|
|
|
|
ScopedCheckpointSection sec(cp, csprintf("bankedRegs%i", i));
|
|
|
|
if (cp.sectionExists(Serializable::currentSection())) {
|
|
|
|
getBankedRegs(i).unserialize(cp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Pl390::BankedRegs::unserialize(CheckpointIn &cp)
|
|
|
|
{
|
|
|
|
UNSERIALIZE_SCALAR(intEnabled);
|
|
|
|
UNSERIALIZE_SCALAR(pendingInt);
|
|
|
|
UNSERIALIZE_SCALAR(activeInt);
|
|
|
|
UNSERIALIZE_ARRAY(intPriority, SGI_MAX + PPI_MAX);
|
|
|
|
UNSERIALIZE_ARRAY(cpuTarget, SGI_MAX + PPI_MAX);
|
2010-08-23 18:18:40 +02:00
|
|
|
}
|
|
|
|
|
2012-10-25 15:05:24 +02:00
|
|
|
Pl390 *
|
|
|
|
Pl390Params::create()
|
2010-08-23 18:18:40 +02:00
|
|
|
{
|
2012-10-25 15:05:24 +02:00
|
|
|
return new Pl390(this);
|
2010-08-23 18:18:40 +02:00
|
|
|
}
|
2010-10-01 23:04:00 +02:00
|
|
|
|
|
|
|
/* Functions for debugging and testing */
|
|
|
|
void
|
2016-08-02 14:35:45 +02:00
|
|
|
Pl390::driveSPI(uint32_t spiVect)
|
2010-10-01 23:04:00 +02:00
|
|
|
{
|
|
|
|
DPRINTF(GIC, "Received SPI Vector:%x Enable: %d\n", spiVect, irqEnable);
|
2016-08-02 14:35:45 +02:00
|
|
|
getPendingInt(0, 1) |= spiVect;
|
2011-05-05 03:38:27 +02:00
|
|
|
if (irqEnable && enabled) {
|
2010-10-01 23:04:00 +02:00
|
|
|
updateIntState(-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-10-25 15:05:24 +02:00
|
|
|
Pl390::driveIrqEn( bool state)
|
2010-10-01 23:04:00 +02:00
|
|
|
{
|
|
|
|
irqEnable = state;
|
2011-05-05 03:38:27 +02:00
|
|
|
DPRINTF(GIC, " Enabling Irq\n");
|
|
|
|
updateIntState(-1);
|
2010-10-01 23:04:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-10-25 15:05:24 +02:00
|
|
|
Pl390::driveLegIRQ(bool state)
|
2010-10-01 23:04:00 +02:00
|
|
|
{
|
2011-05-05 03:38:27 +02:00
|
|
|
if (irqEnable && !(!enabled && cpuEnabled[0])) {
|
|
|
|
if (state) {
|
2010-10-01 23:04:00 +02:00
|
|
|
DPRINTF(GIC, "Driving Legacy Irq\n");
|
|
|
|
platform->intrctrl->post(0, ArmISA::INT_IRQ, 0);
|
|
|
|
}
|
|
|
|
else platform->intrctrl->clear(0, ArmISA::INT_IRQ, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-10-25 15:05:24 +02:00
|
|
|
Pl390::driveLegFIQ(bool state)
|
2010-10-01 23:04:00 +02:00
|
|
|
{
|
|
|
|
if (state)
|
|
|
|
platform->intrctrl->post(0, ArmISA::INT_FIQ, 0);
|
|
|
|
else platform->intrctrl->clear(0, ArmISA::INT_FIQ, 0);
|
|
|
|
}
|