fastmodel: Pull out and simplify the interrupt mechanism in the GIC.
authorGabe Black <gabeblack@google.com>
Wed, 28 Aug 2019 00:20:30 +0000 (17:20 -0700)
committerGabe Black <gabeblack@google.com>
Tue, 1 Oct 2019 22:08:49 +0000 (22:08 +0000)
This change pulls out the SPI and PPI command structures and replaces
them with a custom protocol which can deliver a SPI or PPI without
having to bundle their parameters into a structure.

Change-Id: I8f15c8b3182bd6560bf5ef0345b0bc64173def85
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/21042
Reviewed-by: Giacomo Travaglini <giacomo.travaglini@arm.com>
Maintainer: Giacomo Travaglini <giacomo.travaglini@arm.com>
Tested-by: kokoro <noreply+kokoro@google.com>
src/arch/arm/fastmodel/GIC/GIC.lisa
src/arch/arm/fastmodel/GIC/GIC.sgproj
src/arch/arm/fastmodel/GIC/SConscript
src/arch/arm/fastmodel/GIC/commands.hh [deleted file]
src/arch/arm/fastmodel/GIC/gic.cc
src/arch/arm/fastmodel/GIC/gic.hh
src/arch/arm/fastmodel/protocol/SConscript
src/arch/arm/fastmodel/protocol/SignalInterruptProtocol.lisa [new file with mode: 0644]
src/arch/arm/fastmodel/protocol/signal_interrupt.hh [new file with mode: 0644]

index b15c9ef5ed7c2acf20bfff4b5a42c55c6bed4995..bb1e5649cdfc87d91f48264f6bd41de2f8944a02 100644 (file)
  *          Chun-Chen TK Hsu
  */
 
-protocol AMBAPVPPICommand
-{
-    properties
-    {
-        sc_master_port_class_name =
-            "amba_pv::signal_master_port<FastModel::PPICommand>";
-        sc_slave_base_class_name =
-            "amba_pv::signal_slave_base<FastModel::PPICommand>";
-        sc_slave_export_class_name =
-            "amba_pv::signal_slave_export<FastModel::PPICommand>";
-    }
-
-    includes
-    {
-        #include <amba_pv.h>
-        #include "arch/arm/fastmodel/GIC/commands.hh"
-    }
-
-    slave behavior set_state(
-            int export_id, const FastModel::PPICommand &value);
-}
-
-protocol AMBAPVSPICommand
-{
-    properties
-    {
-        sc_master_port_class_name =
-            "amba_pv::signal_master_port<FastModel::SPICommand>";
-        sc_slave_base_class_name =
-            "amba_pv::signal_slave_base<FastModel::SPICommand>";
-        sc_slave_export_class_name =
-            "amba_pv::signal_slave_export<FastModel::SPICommand>";
-    }
-
-    includes
-    {
-        #include <amba_pv.h>
-        #include "arch/arm/fastmodel/GIC/commands.hh"
-    }
-
-    slave behavior set_state(
-            int export_id, const FastModel::SPICommand &value);
-}
-
 component GIC
 {
     composition
@@ -410,13 +366,12 @@ component GIC
     #define setPPI(C) \
           case C: ppi_##C[num].setValue(state); \
           break
-    slave port<AMBAPVPPICommand> ppi_command
+    slave port<SignalInterrupt> signal_interrupt
     {
-        behavior set_state(int export_id, const FastModel::PPICommand &value)
+        behavior ppi(uint8_t cpu, uint32_t num, bool state_val)
         {
-            sg::Signal::State state = value.state();
-            uint32_t num = value.num();
-            uint8_t cpu = value.cpu();
+            sg::Signal::State state =
+                state_val ? sg::Signal::Set : sg::Signal::Clear;
 
             switch (cpu) {
               setPPI(0); setPPI(1); setPPI(2); setPPI(3); setPPI(4);
@@ -475,7 +430,15 @@ component GIC
                 sc_assert(false);
             }
         }
+
+        behavior spi(uint32_t num, bool state_val)
+        {
+            sg::Signal::State state =
+                state_val ? sg::Signal::Set : sg::Signal::Clear;
+            spi[num].setValue(state);
+        }
     }
+
     // CPU-side connections
     slave port<AMBAPVSignal> cnthpirq;
     slave port<AMBAPVSignal> cnthvirq;
@@ -487,14 +450,6 @@ component GIC
     slave port<AMBAPVSignal> pmuirq;
     slave port<AMBAPVSignal> vcpumntirq;
 
-    slave port<AMBAPVSPICommand> spi_command
-    {
-        behavior set_state(int export_id, const FastModel::SPICommand &value)
-        {
-            spi[value.num()].setValue(value.state());
-        }
-    }
-
     internal slave port<Signal> spi[988];
 
     internal slave port<Signal> ppi_0[16];
index 2213bff1ab384ccc71268a3a92ef434727c702b2..c01670587645ebbdd6985e2e99959f24f27217e1 100644 (file)
@@ -21,5 +21,6 @@ files
 {
     path = "GIC.lisa";
     path = "${PVLIB_HOME}/etc/sglib.sgrepo";
+    path = "../protocol/SignalInterruptProtocol.lisa";
 }
 }
index c52304d2d7c62ce606dac2568adf72861f82a5bb..be5cbbded254413c3ded6de3078ae80e304d79f0 100644 (file)
@@ -30,7 +30,10 @@ Import('*')
 if not env['USE_ARM_FASTMODEL'] or env['TARGET_ISA'] != 'arm':
     Return()
 
-ArmFastModelComponent(File('GIC.sgproj'), File('commands.hh'),
-                      File('GIC.lisa')).prepare_env(env)
+protocol_dir = Dir('..').Dir('protocol')
+
+ArmFastModelComponent(File('GIC.sgproj'), File('GIC.lisa'),
+                      protocol_dir.File('SignalInterruptProtocol.lisa')
+                      ).prepare_env(env)
 SimObject('FastModelGIC.py')
 Source('gic.cc')
diff --git a/src/arch/arm/fastmodel/GIC/commands.hh b/src/arch/arm/fastmodel/GIC/commands.hh
deleted file mode 100644 (file)
index 70f69c8..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright 2019 Google, Inc.
- *
- * 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: Gabe Black
- */
-
-#ifndef __ARCH_ARM_FASTMODEL_GIC_COMMANDS_HH__
-#define __ARCH_ARM_FASTMODEL_GIC_COMMANDS_HH__
-
-#include <cstdint>
-
-#include "base/logging.hh"
-#include "sg/SGSignal.h"
-
-namespace FastModel
-{
-
-class PPICommand
-{
-  private:
-    uint8_t _cpu;
-    uint32_t _num;
-    sg::Signal::State _state;
-
-  public:
-    PPICommand(uint8_t c, uint32_t n, bool set) :
-        _cpu(c), _num(n), _state(set ? sg::Signal::Set : sg::Signal::Clear)
-    {
-        panic_if(_cpu > 255, "PPICommand CPU out of bounds");
-        panic_if(_num > 15, "PPICommand number out of bounds");
-    }
-
-    PPICommand() : PPICommand(0, 0, false) {}
-
-    uint8_t cpu() const { return _cpu; }
-    uint32_t num() const { return _num; }
-    sg::Signal::State state() const { return _state; }
-};
-
-class SPICommand
-{
-  private:
-    uint32_t _num;
-    sg::Signal::State _state;
-
-  public:
-    SPICommand(uint32_t n, bool set) :
-        _num(n), _state(set ? sg::Signal::Set : sg::Signal::Clear)
-    {
-        panic_if(_num > 987, "SPICommand number out of bounds");
-    }
-
-    SPICommand() : SPICommand(0, false) {}
-
-    uint32_t num() const { return _num; }
-    sg::Signal::State state() const { return _state; }
-};
-
-} // namespace FastModel
-
-#endif // __ARCH_ARM_FASTMODEL_GIC_COMMANDS_HH__
index 2041e41868bdafeca4ced3172996036edaf4a4a9..cd332c62b8c21727d8426893f2aca21c46203c22 100644 (file)
@@ -48,8 +48,7 @@ SCGIC::SCGIC(const SCFastModelGICParams &params,
     pmuirqWrapper(pmuirq, params.name + ".pmuirq", -1),
     vcpumntirqWrapper(vcpumntirq, params.name + ".vcpumntirq", -1)
 {
-    ppiCommand.bind(ppi_command);
-    spiCommand.bind(spi_command);
+    signalInterrupt.bind(signal_interrupt);
 
     set_parameter("gic.enabled", params.enabled);
     set_parameter("gic.has-gicv3", params.has_gicv3);
@@ -315,25 +314,25 @@ GIC::getPort(const std::string &if_name, PortID idx)
 void
 GIC::sendInt(uint32_t num)
 {
-    scGIC->spiCommand.set_state(0, SPICommand(num - 32, true));
+    scGIC->signalInterrupt->spi(num - 32, true);
 }
 
 void
 GIC::clearInt(uint32_t num)
 {
-    scGIC->spiCommand.set_state(0, SPICommand(num - 32, false));
+    scGIC->signalInterrupt->spi(num - 32, false);
 }
 
 void
 GIC::sendPPInt(uint32_t num, uint32_t cpu)
 {
-    scGIC->ppiCommand.set_state(0, PPICommand(cpu, num, true));
+    scGIC->signalInterrupt->ppi(cpu, num, true);
 }
 
 void
 GIC::clearPPInt(uint32_t num, uint32_t cpu)
 {
-    scGIC->ppiCommand.set_state(0, PPICommand(cpu, num, false));
+    scGIC->signalInterrupt->ppi(cpu, num, false);
 }
 
 } // namespace FastModel
index 7910686cd0145ba6cfe6fda96e05caefdd919178..b5d37c42d0a708572ba7d563ec264c9e9c85c9cc 100644 (file)
@@ -30,7 +30,8 @@
 #ifndef __ARCH_ARM_FASTMODEL_GIC_GIC_HH__
 #define __ARCH_ARM_FASTMODEL_GIC_GIC_HH__
 
-#include "arch/arm/fastmodel/GIC/commands.hh"
+#include <amba_pv.h>
+
 #include "arch/arm/fastmodel/amba_ports.hh"
 #include "dev/arm/base_gic.hh"
 #include "params/FastModelGIC.hh"
@@ -57,8 +58,7 @@ class SCGIC : public scx_evs_GIC
   public:
     SCGIC(const SCFastModelGICParams &params, sc_core::sc_module_name _name);
 
-    amba_pv::signal_master_port<PPICommand> ppiCommand;
-    amba_pv::signal_master_port<SPICommand> spiCommand;
+    SignalInterruptInitiatorSocket signalInterrupt;
 
     sc_gem5::ScInterfaceWrapper<IFACE_TYPE(cnthpirq)> cnthpirqWrapper;
     sc_gem5::ScInterfaceWrapper<IFACE_TYPE(cnthvirq)> cnthvirqWrapper;
index b0171f136cea5e551556032448f39f552577a424..f82e04c2a5ff60d1495b893ce1bd295461f183e4 100644 (file)
@@ -27,3 +27,5 @@
 
 Depends('ExportedClockRateControlProtocol.lisa',
         'exported_clock_rate_control.hh')
+Depends('SignalInterruptProtocol.lisa',
+        'signal_interrupt.hh')
diff --git a/src/arch/arm/fastmodel/protocol/SignalInterruptProtocol.lisa b/src/arch/arm/fastmodel/protocol/SignalInterruptProtocol.lisa
new file mode 100644 (file)
index 0000000..d8b9a61
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2019 Google Inc.
+ *
+ * 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: Gabe Black
+ */
+
+protocol SignalInterrupt
+{
+    includes
+    {
+        #include "arch/arm/fastmodel/protocol/signal_interrupt.hh"
+    }
+    properties
+    {
+        description = "Signal an interrupt from gem5.";
+        version = "1.0";
+        dso_safe = 0;
+        sc_slave_base_class_name = "SignalInterruptSlaveBase";
+        sc_slave_socket_class_name = "SignalInterruptTargetSocket";
+    }
+
+    slave behavior ppi(uint8_t cpu, uint32_t num, bool state);
+    slave behavior spi(uint32_t num, bool state);
+}
diff --git a/src/arch/arm/fastmodel/protocol/signal_interrupt.hh b/src/arch/arm/fastmodel/protocol/signal_interrupt.hh
new file mode 100644 (file)
index 0000000..4cf0471
--- /dev/null
@@ -0,0 +1,121 @@
+/*
+ * Copyright 2019 Google, Inc.
+ *
+ * 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: Gabe Black
+ */
+
+#ifndef __ARCH_ARM_FASTMODEL_PROTOCOL_SIGNAL_INTERRUPT_HH__
+#define __ARCH_ARM_FASTMODEL_PROTOCOL_SIGNAL_INTERRUPT_HH__
+
+#include <string>
+#include <systemc>
+#include <tlm>
+
+struct SignalInterruptDummyProtocolType {};
+
+class SignalInterruptFwIf : public virtual sc_core::sc_interface
+{
+  public:
+    virtual ~SignalInterruptFwIf() {}
+    virtual void ppi(uint8_t cpu, uint32_t num, bool state) = 0;
+    virtual void spi(uint32_t num, bool state) = 0;
+};
+
+class SignalInterruptBwIf : public virtual sc_core::sc_interface
+{
+  public:
+    virtual ~SignalInterruptBwIf() {}
+};
+
+class SignalInterruptSlaveBase : public SignalInterruptFwIf
+{
+  public:
+    SignalInterruptSlaveBase(const std::string &name) {}
+};
+
+class SignalInterruptInitiatorSocket :
+    public tlm::tlm_base_initiator_socket<64, SignalInterruptFwIf,
+                                          SignalInterruptBwIf>
+{
+  private:
+    SignalInterruptBwIf dummyBwIf;
+
+  public:
+    typedef tlm::tlm_base_initiator_socket<64, SignalInterruptFwIf,
+                                           SignalInterruptBwIf> Base;
+
+    using Base::bind;
+    using Base::operator();
+
+    SignalInterruptInitiatorSocket() : Base()
+    {
+        get_base_export().bind(dummyBwIf);
+    }
+    SignalInterruptInitiatorSocket(const char *name) : Base(name)
+    {
+        get_base_export().bind(dummyBwIf);
+    }
+
+    const char *
+    kind() const override
+    {
+        return "SignalInterruptInitiatorSocket";
+    }
+
+    std::type_index
+    get_protocol_types() const override
+    {
+        return typeid(SignalInterruptDummyProtocolType);
+    }
+};
+
+class SignalInterruptTargetSocket :
+    public tlm::tlm_base_target_socket<64, SignalInterruptFwIf,
+                                       SignalInterruptBwIf>
+{
+  public:
+    typedef tlm::tlm_base_target_socket<64, SignalInterruptFwIf,
+                                        SignalInterruptBwIf> Base;
+
+    using Base::bind;
+    using Base::operator();
+
+    using Base::Base;
+
+    const char *
+    kind() const override
+    {
+        return "SignalInterruptInitiatorSocket";
+    }
+
+    std::type_index
+    get_protocol_types() const override
+    {
+        return typeid(SignalInterruptDummyProtocolType);
+    }
+};
+
+#endif // __ARCH_ARM_FASTMODEL_PROTOCOL_SIGNAL_INTERRUPT_HH__