dev: Delete the authors list from files in src/dev.
[gem5.git] / src / dev / x86 / intdev.hh
index b01d36e37f3f9016cbf9461940f0110213761822..a40a1d4f54623422134053e3eb11c2514a172ef8 100644 (file)
@@ -1,4 +1,16 @@
 /*
+ * Copyright (c) 2012 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.
+ *
  * Copyright (c) 2008 The Regents of The University of Michigan
  * All rights reserved.
  *
  * 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 __DEV_X86_INTDEV_HH__
 #define __DEV_X86_INTDEV_HH__
 
 #include <cassert>
+#include <functional>
 #include <string>
 
-#include "arch/x86/x86_traits.hh"
-#include "arch/x86/intmessage.hh"
-#include "mem/mem_object.hh"
-#include "mem/mport.hh"
+#include "mem/tport.hh"
 #include "sim/sim_object.hh"
-#include "params/X86IntSourcePin.hh"
-#include "params/X86IntSinkPin.hh"
-#include "params/X86IntLine.hh"
-
-#include <list>
 
-namespace X86ISA {
-
-typedef std::list<int> ApicList;
-
-class IntDev
+namespace X86ISA
 {
-  protected:
-    class IntPort : public MessagePort
-    {
-        IntDev * device;
-        Tick latency;
-        Addr intAddr;
-      public:
-        IntPort(const std::string &_name, MemObject * _parent,
-                IntDev *dev, Tick _latency) :
-            MessagePort(_name, _parent), device(dev), latency(_latency)
-        {
-        }
-
-        void getDeviceAddressRanges(AddrRangeList &resp, bool &snoop)
-        {
-            snoop = false;
-            device->getIntAddrRange(resp);
-        }
-
-        Tick recvMessage(PacketPtr pkt)
-        {
-            return device->recvMessage(pkt);
-        }
-
-        Tick recvResponse(PacketPtr pkt)
-        {
-            return device->recvResponse(pkt);
-        }
-
-        // This is x86 focused, so if this class becomes generic, this would
-        // need to be moved into a subclass.
-        void sendMessage(ApicList apics,
-                TriggerIntMessage message, bool timing);
-
-        void recvStatusChange(Status status)
-        {
-            if (status == RangeChange) {
-                sendStatusChange(Port::RangeChange);
-            }
-        }
-
-    };
 
-    IntPort * intPort;
+template <class Device>
+class IntSlavePort : public SimpleTimingPort
+{
+    Device * device;
 
   public:
-    IntDev(MemObject * parent, Tick latency = 0)
-    {
-        if (parent != NULL) {
-            intPort = new IntPort(parent->name() + ".int_port",
-                    parent, this, latency);
-        } else {
-            intPort = NULL;
-        }
-    }
-
-    virtual ~IntDev()
-    {}
-
-    virtual void
-    signalInterrupt(int line)
-    {
-        panic("signalInterrupt not implemented.\n");
-    }
-
-    virtual void
-    raiseInterruptPin(int number)
+    IntSlavePort(const std::string& _name, SimObject* _parent,
+                 Device* dev) :
+        SimpleTimingPort(_name, _parent), device(dev)
     {
-        panic("raiseInterruptPin not implemented.\n");
     }
 
-    virtual void
-    lowerInterruptPin(int number)
+    AddrRangeList
+    getAddrRanges() const
     {
-        panic("lowerInterruptPin not implemented.\n");
+        return device->getIntAddrRange();
     }
 
-    virtual Tick
-    recvMessage(PacketPtr pkt)
+    Tick
+    recvAtomic(PacketPtr pkt)
     {
-        panic("recvMessage not implemented.\n");
-        return 0;
-    }
-
-    virtual Tick
-    recvResponse(PacketPtr pkt)
-    {
-        delete pkt->req;
-        delete pkt;
-        return 0;
-    }
-
-    virtual void
-    getIntAddrRange(AddrRangeList &range_list)
-    {
-        panic("intAddrRange not implemented.\n");
+        panic_if(pkt->cmd != MemCmd::WriteReq,
+                "%s received unexpected command %s from %s.\n",
+                name(), pkt->cmd.toString(), getPeer());
+        pkt->headerDelay = pkt->payloadDelay = 0;
+        return device->recvMessage(pkt);
     }
 };
 
-class IntSinkPin : public SimObject
+template<class T>
+PacketPtr
+buildIntPacket(Addr addr, T payload)
 {
-  public:
-    IntDev * device;
-    int number;
-
-    typedef X86IntSinkPinParams Params;
-
-    const Params *
-    params() const
-    {
-        return dynamic_cast<const Params *>(_params);
-    }
+    RequestPtr req = std::make_shared<Request>(
+        addr, sizeof(T), Request::UNCACHEABLE, Request::intMasterId);
+    PacketPtr pkt = new Packet(req, MemCmd::WriteReq);
+    pkt->allocate();
+    pkt->setRaw<T>(payload);
+    return pkt;
+}
+
+template <class Device>
+class IntMasterPort : public QueuedMasterPort
+{
+  private:
+    ReqPacketQueue reqQueue;
+    SnoopRespPacketQueue snoopRespQueue;
 
-    IntSinkPin(Params *p) : SimObject(p),
-            device(dynamic_cast<IntDev *>(p->device)), number(p->number)
-    {
-        assert(device);
-    }
-};
+    Device* device;
+    Tick latency;
 
-class IntSourcePin : public SimObject
-{
-  protected:
-    std::vector<IntSinkPin *> sinks;
+    typedef std::function<void(PacketPtr)> OnCompletionFunc;
+    OnCompletionFunc onCompletion = nullptr;
+    // If nothing extra needs to happen, just clean up the packet.
+    static void defaultOnCompletion(PacketPtr pkt) { delete pkt; }
 
   public:
-    typedef X86IntSourcePinParams Params;
-
-    const Params *
-    params() const
+    IntMasterPort(const std::string& _name, SimObject* _parent,
+                  Device* dev, Tick _latency) :
+        QueuedMasterPort(_name, _parent, reqQueue, snoopRespQueue),
+        reqQueue(*_parent, *this), snoopRespQueue(*_parent, *this),
+        device(dev), latency(_latency)
     {
-        return dynamic_cast<const Params *>(_params);
     }
 
-    void
-    addSink(IntSinkPin *sink)
+    bool
+    recvTimingResp(PacketPtr pkt) override
     {
-        sinks.push_back(sink);
+        assert(pkt->isResponse());
+        onCompletion(pkt);
+        onCompletion = nullptr;
+        return true;
     }
 
     void
-    raise()
+    sendMessage(PacketPtr pkt, bool timing,
+            OnCompletionFunc func=defaultOnCompletion)
     {
-        for (int i = 0; i < sinks.size(); i++) {
-            const IntSinkPin &pin = *sinks[i];
-            pin.device->raiseInterruptPin(pin.number);
-        }
-    }
-    
-    void
-    lower()
-    {
-        for (int i = 0; i < sinks.size(); i++) {
-            const IntSinkPin &pin = *sinks[i];
-            pin.device->lowerInterruptPin(pin.number);
+        if (timing) {
+            onCompletion = func;
+            schedTimingReq(pkt, curTick() + latency);
+            // The target handles cleaning up the packet in timing mode.
+        } else {
+            // ignore the latency involved in the atomic transaction
+            sendAtomic(pkt);
+            func(pkt);
         }
     }
-
-    IntSourcePin(Params *p) : SimObject(p)
-    {}
-};
-
-class IntLine : public SimObject
-{
-  protected:
-    IntSourcePin *source;
-    IntSinkPin *sink;
-
-  public:
-    typedef X86IntLineParams Params;
-
-    const Params *
-    params() const
-    {
-        return dynamic_cast<const Params *>(_params);
-    }
-
-    IntLine(Params *p) : SimObject(p), source(p->source), sink(p->sink)
-    {
-        source->addSink(sink);
-    }
 };
 
 } // namespace X86ISA