Andreas Sandberg has uploaded this change for review. ( https://gem5-review.googlesource.com/10806

Change subject: dev: Add a generic interrupt simulation library
......................................................................

dev: Add a generic interrupt simulation library

Add a generic interrupt simulation library which can set, clear, and
mask interrupts. The idea is that such functions are common across
several blocks and can be re-used using a robust library.

Change-Id: Ibbb573f7cdc8225302e3784679ae8b648c554ece
Reviewed-by: Andreas Sandberg <[email protected]>
Signed-off-by: Andreas Sandberg <[email protected]>
---
M src/dev/SConscript
A src/dev/irqcontrol.hh
A src/dev/irqcontroltest.cc
3 files changed, 214 insertions(+), 0 deletions(-)



diff --git a/src/dev/SConscript b/src/dev/SConscript
index 79ad50b..150f740 100644
--- a/src/dev/SConscript
+++ b/src/dev/SConscript
@@ -55,6 +55,7 @@
 GTest('registertest',
         'register_util_test.cc','../base/trace.cc','../base/debug.cc',
         '../base/match.cc','../base/str.cc')
+GTest('irqcontroltest','irqcontroltest.cc')

 DebugFlag('Intel8254Timer')
 DebugFlag('MC146818')
diff --git a/src/dev/irqcontrol.hh b/src/dev/irqcontrol.hh
new file mode 100644
index 0000000..0c5401c
--- /dev/null
+++ b/src/dev/irqcontrol.hh
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 2018 ARM Limited
+ * 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.
+ *
+ * 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: Rohit Kurup
+ */
+
+#ifndef __DEV_IRQCONTROL_HH__
+#define __DEV_IRQCONTROL_HH__
+
+#include <functional>
+
+/** @file
+ * A generic interrupt controller
+ *
+ * The IrqControl can set/clear/mask interrupts. They can be mapped to
+ * set, clear, and mask registers in the block by calling irqSetWr,
+ * irqClrWr, irqMaskWr from register callbacks.  A parent module can
+ * assign target callbacks sendInt and clearInt where for example IRQ
+ * can be sent to an interrupt controller.  For cases, where some bits
+ * are reserved hwMsk can be set to zero.
+ */
+template<typename DataType>
+class IrqControl
+{
+    DataType irqMsk;
+    DataType irqStat;
+    DataType hwMsk;
+
+    bool irqOut;
+
+    std::function<void()> sendInt;
+    std::function<void()> clearInt;
+
+    IrqControl() = delete;
+    IrqControl(IrqControl &) = delete;
+
+    void
+    updateIRQ()
+    {
+        bool newIrq = getMskStat() ? true : false;
+        if (newIrq == irqOut)
+            return;
+
+        irqOut = newIrq;
+        if (newIrq) {
+            sendInt();
+        } else {
+            clearInt();
+        }
+    }
+
+  public :
+    IrqControl(DataType msk, std::function<void()> sendfn,
+               std::function<void()> clrfn)
+ : irqMsk(0), irqStat(0), hwMsk(msk), irqOut(false), sendInt(sendfn),
+          clearInt(clrfn)
+    {
+    }
+
+    void irqSet(DataType val)
+    {
+        val &= hwMsk;
+        irqStat = irqStat | val;
+        updateIRQ();
+    }
+
+    void irqClr(DataType val)
+    {
+        val &= hwMsk;
+        irqStat = irqStat & ~val;
+        updateIRQ();
+    }
+
+    void irqMask(DataType val)
+    {
+        irqMsk = val & hwMsk;
+        updateIRQ();
+    }
+
+    DataType getRawStat()
+    {
+        return irqStat;
+    }
+
+    DataType getMskStat()
+    {
+        return irqStat & irqMsk;
+    }
+};
+
+#endif // __DEV_IRQCONTROL_HH__
diff --git a/src/dev/irqcontroltest.cc b/src/dev/irqcontroltest.cc
new file mode 100644
index 0000000..b7cfa12
--- /dev/null
+++ b/src/dev/irqcontroltest.cc
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2018 ARM Limited
+ * 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.
+ *
+ * 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: Rohit Kurup
+ */
+
+#include <gtest/gtest.h>
+
+#include "dev/irqcontrol.hh"
+
+class IrqTest
+{
+    bool irq;
+
+  public :
+    IrqControl<uint32_t> simplecontroller;
+
+    void setirq() { irq = true; }
+
+    void clrirq() { irq = false; }
+
+    IrqTest()
+        : irq(false), simplecontroller(0xFFFFFFFF,
+                                       [this]() { this->setirq(); },
+                                       [this]() { this->clrirq(); })
+    {
+    }
+
+    bool getirq() { return irq; }
+
+};
+
+TEST(IrqControlTest, BasicTest)
+{
+    IrqTest testmod;
+    testmod.simplecontroller.irqMask(0x1111);
+    testmod.simplecontroller.irqSet(0x2222);
+    EXPECT_EQ(testmod.getirq(), false);
+
+    testmod.simplecontroller.irqMask(0x2222);
+    EXPECT_EQ(testmod.getirq(), true);
+
+    testmod.simplecontroller.irqMask(0x1111);
+    EXPECT_EQ(testmod.getirq(), false);
+    EXPECT_EQ(testmod.simplecontroller.getRawStat(), 0x2222);
+
+    testmod.simplecontroller.irqClr(0x2222);
+    EXPECT_EQ(testmod.simplecontroller.getRawStat(), 0x0);
+
+    testmod.simplecontroller.irqSet(0x1111);
+    EXPECT_EQ(testmod.getirq(), true);
+
+    testmod.simplecontroller.irqClr(0x1111);
+    EXPECT_EQ(testmod.getirq(), false);
+}
+

--
To view, visit https://gem5-review.googlesource.com/10806
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: Ibbb573f7cdc8225302e3784679ae8b648c554ece
Gerrit-Change-Number: 10806
Gerrit-PatchSet: 1
Gerrit-Owner: Andreas Sandberg <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to