melissa jost has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/53036 )

Change subject: dev: Added new LupIO-PIC device
......................................................................

dev: Added new LupIO-PIC device

This device is a virtual programmable interrupt controller, and it
manages interrupt requests from up to 32 sources.  It is implemented
as a BasicPioDevice.

The following are the specifications regarding the LupIO-PIC:
https://gitlab.com/luplab/lupio/lupio-specs/-/blob/main/lupio-pic.md
Change-Id: I9ccdb607789f62cc89bdd7392d8e59c8e5c24797
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/53036
Maintainer: Bobby Bruce <bbr...@ucdavis.edu>
Tested-by: kokoro <noreply+kok...@google.com>
Reviewed-by: Jason Lowe-Power <power...@gmail.com>
---
A src/dev/lupio/lupio_pic.cc
A src/dev/lupio/lupio_pic.hh
A src/dev/lupio/LupioPIC.py
M src/dev/lupio/SConscript
4 files changed, 328 insertions(+), 1 deletion(-)

Approvals:
  Jason Lowe-Power: Looks good to me, approved
  Bobby Bruce: Looks good to me, approved
  kokoro: Regressions pass




diff --git a/src/dev/lupio/LupioPIC.py b/src/dev/lupio/LupioPIC.py
new file mode 100644
index 0000000..992501b
--- /dev/null
+++ b/src/dev/lupio/LupioPIC.py
@@ -0,0 +1,38 @@
+# Copyright (c) 2021 The Regents of the University of California
+# 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.
+
+from m5.objects.Device import BasicPioDevice
+from m5.params import Param
+
+class LupioPIC(BasicPioDevice):
+
+    type = 'LupioPIC'
+    cxx_class='gem5::LupioPIC'
+    cxx_header = 'dev/lupio/lupio_pic.hh'
+    pio_size = Param.Addr(0x1000, "PIO Size")
+    n_src = Param.Int("Number of interrupt sources")
+    num_threads = Param.Int("Number of threads")
+    int_type = Param.Int("Type of interrupt")
diff --git a/src/dev/lupio/SConscript b/src/dev/lupio/SConscript
index 1eb0187..93600236 100644
--- a/src/dev/lupio/SConscript
+++ b/src/dev/lupio/SConscript
@@ -27,19 +27,22 @@
 Import('*')

 SimObject('LupioBLK.py', tags='riscv isa')
+SimObject('LupioPIC.py', tags='riscv isa')
 SimObject('LupioRNG.py', tags='riscv isa')
 SimObject('LupioRTC.py', tags='riscv isa')
 SimObject('LupioTMR.py', tags='riscv isa')
 SimObject('LupioTTY.py', tags='riscv isa')

 DebugFlag('LupioBLK')
+DebugFlag('LupioPIC')
 DebugFlag('LupioRNG')
 DebugFlag('LupioRTC')
 DebugFlag('LupioTMR')
 DebugFlag('LupioTTY')

 Source('lupio_blk.cc', tags='riscv isa')
+Source('lupio_pic.cc', tags='riscv isa')
 Source('lupio_rng.cc', tags='riscv isa')
 Source('lupio_rtc.cc', tags='riscv isa')
 Source('lupio_tmr.cc', tags='riscv isa')
-Source('lupio_tty.cc', tags='riscv isa')
\ No newline at end of file
+Source('lupio_tty.cc', tags='riscv isa')
diff --git a/src/dev/lupio/lupio_pic.cc b/src/dev/lupio/lupio_pic.cc
new file mode 100644
index 0000000..010a5d8
--- /dev/null
+++ b/src/dev/lupio/lupio_pic.cc
@@ -0,0 +1,165 @@
+/*
+ * Copyright (c) 2021 The Regents of the University of California
+ * 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.
+ */
+
+#include "dev/lupio/lupio_pic.hh"
+
+#include "cpu/base.hh"
+#include "debug/LupioPIC.hh"
+#include "mem/packet_access.hh"
+#include "params/LupioPIC.hh"
+#include "sim/system.hh"
+
+#define LUPIO_PIC_NSRC      32
+
+namespace gem5
+{
+
+LupioPIC::LupioPIC(const Params &params) :
+    BasicPioDevice(params, params.pio_size),
+    system(params.system),
+    nSrc(params.n_src),
+    nThread(params.num_threads),
+    intType(params.int_type)
+{
+    DPRINTF(LupioPIC, "LupioPIC initalized\n");
+}
+
+void
+LupioPIC::lupioPicUpdateIRQ()
+{
+    if (nThread > 1 ) {
+        panic("This device currently does not have SMP support\n");
+    }
+
+    auto tc = system->threads[0];
+    if (pending & mask) {
+        tc->getCpuPtr()->postInterrupt(tc->threadId(), intType, 0);
+    } else {
+        tc->getCpuPtr()->clearInterrupt(tc->threadId(), intType, 0);
+    }
+}
+
+void
+LupioPIC::post(int src_id)
+{
+    gem5_assert(src_id < nSrc && src_id >= 0);
+
+    uint32_t irq_mask = 1UL << src_id;
+    pending |= irq_mask;
+    lupioPicUpdateIRQ();
+}
+
+void
+LupioPIC::clear(int src_id)
+{
+    gem5_assert(src_id < nSrc && src_id >= 0);
+
+    uint32_t irq_mask = 1UL << src_id;
+    pending &= ~irq_mask;
+    lupioPicUpdateIRQ();
+}
+
+uint64_t
+LupioPIC::lupioPicRead(uint8_t addr)
+{
+    uint32_t r = 0;
+
+    switch (addr >> 2) {
+        case LUPIO_PIC_PRIO:
+            // Value will be 32 if there is no unmasked pending IRQ
+            r = ctz32(pending & mask);
+            DPRINTF(LupioPIC, "Read PIC_PRIO: %d\n", r);
+            break;
+        case LUPIO_PIC_MASK:
+            r = mask;
+            DPRINTF(LupioPIC, "Read PIC_MASK: %d\n", r);
+            break;
+        case LUPIO_PIC_PEND:
+                       r = pending;
+            DPRINTF(LupioPIC, "Read PIC_PEND: %d\n", r);
+            break;
+
+        default:
+ panic("Unexpected read to the LupioPIC device at address %#llx!",
+                    addr);
+            break;
+    }
+    return r;
+}
+
+void
+LupioPIC::lupioPicWrite(uint8_t addr, uint64_t val64)
+{
+    uint32_t val = val64;
+
+    switch (addr >> 2) {
+        case LUPIO_PIC_MASK:
+            mask = val;
+            DPRINTF(LupioPIC, "Write PIC_MASK: %d\n", mask);
+            lupioPicUpdateIRQ();
+            break;
+
+        default:
+ panic("Unexpected write to the LupioPIC device at address %#llx!",
+                    addr);
+            break;
+    }
+}
+
+Tick
+LupioPIC::read(PacketPtr pkt)
+{
+    Addr pic_addr = pkt->getAddr() - pioAddr;
+
+    DPRINTF(LupioPIC,
+        "Read request - addr: %#x, size: %#x\n", pic_addr, pkt->getSize());
+
+    uint64_t read_val = lupioPicRead(pic_addr);
+    DPRINTF(LupioPIC, "Packet Read: %#x\n", read_val);
+    pkt->setUintX(read_val, byteOrder);
+    pkt->makeResponse();
+
+    return pioDelay;
+}
+
+Tick
+LupioPIC::write(PacketPtr pkt)
+{
+    Addr pic_addr = pkt->getAddr() - pioAddr;
+
+    DPRINTF(LupioPIC, "Write register %#x value %#x\n", pic_addr,
+            pkt->getUintX(byteOrder));
+
+    lupioPicWrite(pic_addr, pkt->getUintX(byteOrder));
+ DPRINTF(LupioPIC, "Packet Write Value: %d\n", pkt->getUintX(byteOrder));
+
+    pkt->makeResponse();
+
+    return pioDelay;
+}
+} // namespace gem5
diff --git a/src/dev/lupio/lupio_pic.hh b/src/dev/lupio/lupio_pic.hh
new file mode 100644
index 0000000..2ed1d17
--- /dev/null
+++ b/src/dev/lupio/lupio_pic.hh
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 2021 The Regents of the University of California
+ * 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.
+ */
+
+#ifndef __DEV_LUPIO_LUPIO_PIC_HH__
+#define __DEV_LUPIO_LUPIO_PIC_HH__
+
+#include "arch/riscv/interrupts.hh"
+#include "dev/io_device.hh"
+#include "dev/platform.hh"
+#include "params/LupioPIC.hh"
+#include "sim/system.hh"
+
+namespace gem5
+{
+
+/**
+ * LupioPIC:
+ * A programmable interrupt controller virtual device that can
+ *  manage input IRQs coming from up to 32 sources
+ */
+
+class LupioPIC : public BasicPioDevice
+{
+  protected:
+    System *system;
+    int nSrc;
+    int nThread;
+    // Type of interrupt
+    int intType;
+
+    const ByteOrder byteOrder = ByteOrder::little;
+
+  // Register map
+  private:
+    enum
+    {
+        LUPIO_PIC_PRIO,
+        LUPIO_PIC_MASK,
+        LUPIO_PIC_PEND,
+
+        // Max offset
+        LUPIO_PIC_MAX,
+    };
+
+    uint32_t pending = 0;
+    uint32_t mask = 0;
+
+  protected:
+    /**
+ * Function to return information about interrupt requests to the LupIO-PIC
+     */
+    uint64_t lupioPicRead(const uint8_t addr);
+    /**
+     * Function to update interrupt requests
+     */
+    void lupioPicWrite(const uint8_t addr, uint64_t val64);
+    /**
+     * Function to post and clear interrupts
+     **/
+    void lupioPicUpdateIRQ();
+
+  public:
+    PARAMS(LupioPIC);
+    LupioPIC(const Params &params);
+
+    void post(int src_id);
+    void clear(int src_id);
+    /**
+     * Implement BasicPioDevice virtual functions
+     */
+    Tick read(PacketPtr pkt) override;
+    Tick write(PacketPtr pkt) override;
+};
+
+} // namespace gem5
+
+#endif // __DEV_LUPIO_LUPIO_PIC_HH_

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

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I9ccdb607789f62cc89bdd7392d8e59c8e5c24797
Gerrit-Change-Number: 53036
Gerrit-PatchSet: 11
Gerrit-Owner: melissa jost <melissakj...@gmail.com>
Gerrit-Reviewer: Bobby Bruce <bbr...@ucdavis.edu>
Gerrit-Reviewer: Gabe Black <gabe.bl...@gmail.com>
Gerrit-Reviewer: Jason Lowe-Power <power...@gmail.com>
Gerrit-Reviewer: kokoro <noreply+kok...@google.com>
Gerrit-Reviewer: melissa jost <melissakj...@gmail.com>
Gerrit-CC: Laura Hinman <llhin...@ucdavis.edu>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to