112047Schristian.menard@tu-dresden.de/*
212047Schristian.menard@tu-dresden.de * Copyright (c) 2015, University of Kaiserslautern
312047Schristian.menard@tu-dresden.de * Copyright (c) 2016, Dresden University of Technology (TU Dresden)
412047Schristian.menard@tu-dresden.de * All rights reserved.
512047Schristian.menard@tu-dresden.de *
612047Schristian.menard@tu-dresden.de * Redistribution and use in source and binary forms, with or without
712047Schristian.menard@tu-dresden.de * modification, are permitted provided that the following conditions are
812047Schristian.menard@tu-dresden.de * met:
912047Schristian.menard@tu-dresden.de *
1012047Schristian.menard@tu-dresden.de * 1. Redistributions of source code must retain the above copyright notice,
1112047Schristian.menard@tu-dresden.de *    this list of conditions and the following disclaimer.
1212047Schristian.menard@tu-dresden.de *
1312047Schristian.menard@tu-dresden.de * 2. Redistributions in binary form must reproduce the above copyright
1412047Schristian.menard@tu-dresden.de *    notice, this list of conditions and the following disclaimer in the
1512047Schristian.menard@tu-dresden.de *    documentation and/or other materials provided with the distribution.
1612047Schristian.menard@tu-dresden.de *
1712047Schristian.menard@tu-dresden.de * 3. Neither the name of the copyright holder nor the names of its
1812047Schristian.menard@tu-dresden.de *    contributors may be used to endorse or promote products derived from
1912047Schristian.menard@tu-dresden.de *    this software without specific prior written permission.
2012047Schristian.menard@tu-dresden.de *
2112047Schristian.menard@tu-dresden.de * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2212047Schristian.menard@tu-dresden.de * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2312047Schristian.menard@tu-dresden.de * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2412047Schristian.menard@tu-dresden.de * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
2512047Schristian.menard@tu-dresden.de * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
2612047Schristian.menard@tu-dresden.de * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
2712047Schristian.menard@tu-dresden.de * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
2812047Schristian.menard@tu-dresden.de * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
2912047Schristian.menard@tu-dresden.de * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
3012047Schristian.menard@tu-dresden.de * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
3112047Schristian.menard@tu-dresden.de * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3212047Schristian.menard@tu-dresden.de *
3312047Schristian.menard@tu-dresden.de * Authors: Matthias Jung
3412047Schristian.menard@tu-dresden.de *          Christian Menard
3512047Schristian.menard@tu-dresden.de */
3612047Schristian.menard@tu-dresden.de
3712047Schristian.menard@tu-dresden.de#ifndef PAYLOAD_EVENT_H_
3812047Schristian.menard@tu-dresden.de#define PAYLOAD_EVENT_H_
3912047Schristian.menard@tu-dresden.de
4012047Schristian.menard@tu-dresden.de// TLM includes
4112047Schristian.menard@tu-dresden.de#include <tlm.h>
4212047Schristian.menard@tu-dresden.de
4312047Schristian.menard@tu-dresden.de// gem5 includes
4412047Schristian.menard@tu-dresden.de#include <sim/eventq.hh>
4512047Schristian.menard@tu-dresden.de
4612047Schristian.menard@tu-dresden.denamespace Gem5SystemC {
4712047Schristian.menard@tu-dresden.de/**
4812047Schristian.menard@tu-dresden.de * A 'Fake Payload Event Queue', similar to the TLM PEQs. This helps the
4912047Schristian.menard@tu-dresden.de * transactors to schedule events in gem5.
5012047Schristian.menard@tu-dresden.de */
5112047Schristian.menard@tu-dresden.detemplate <typename OWNER>
5212047Schristian.menard@tu-dresden.declass PayloadEvent : public Event
5312047Schristian.menard@tu-dresden.de{
5412047Schristian.menard@tu-dresden.de  public:
5512047Schristian.menard@tu-dresden.de    OWNER& port;
5612047Schristian.menard@tu-dresden.de    const std::string eventName;
5712047Schristian.menard@tu-dresden.de    void (OWNER::*handler)(PayloadEvent<OWNER>* pe,
5812047Schristian.menard@tu-dresden.de                           tlm::tlm_generic_payload& trans,
5912047Schristian.menard@tu-dresden.de                           const tlm::tlm_phase& phase);
6012047Schristian.menard@tu-dresden.de
6112047Schristian.menard@tu-dresden.de  protected:
6212047Schristian.menard@tu-dresden.de    tlm::tlm_generic_payload* t;
6312047Schristian.menard@tu-dresden.de    tlm::tlm_phase p;
6412047Schristian.menard@tu-dresden.de
6512047Schristian.menard@tu-dresden.de    void process() { (port.*handler)(this, *t, p); }
6612047Schristian.menard@tu-dresden.de
6712047Schristian.menard@tu-dresden.de  public:
6812047Schristian.menard@tu-dresden.de    const std::string name() const { return eventName; }
6912047Schristian.menard@tu-dresden.de
7012047Schristian.menard@tu-dresden.de    PayloadEvent(OWNER& port_,
7112047Schristian.menard@tu-dresden.de                 void (OWNER::*handler_)(PayloadEvent<OWNER>* pe,
7212047Schristian.menard@tu-dresden.de                                         tlm::tlm_generic_payload& trans,
7312047Schristian.menard@tu-dresden.de                                         const tlm::tlm_phase& phase),
7412047Schristian.menard@tu-dresden.de                 const std::string& event_name)
7512047Schristian.menard@tu-dresden.de      : port(port_)
7612047Schristian.menard@tu-dresden.de      , eventName(event_name)
7712047Schristian.menard@tu-dresden.de      , handler(handler_)
7812047Schristian.menard@tu-dresden.de    {
7912047Schristian.menard@tu-dresden.de    }
8012047Schristian.menard@tu-dresden.de
8112047Schristian.menard@tu-dresden.de    /// Schedule an event into gem5
8212047Schristian.menard@tu-dresden.de    void notify(tlm::tlm_generic_payload& trans, const tlm::tlm_phase& phase,
8312047Schristian.menard@tu-dresden.de                const sc_core::sc_time& delay)
8412047Schristian.menard@tu-dresden.de    {
8512047Schristian.menard@tu-dresden.de        assert(!scheduled());
8612047Schristian.menard@tu-dresden.de
8712047Schristian.menard@tu-dresden.de        t = &trans;
8812047Schristian.menard@tu-dresden.de        p = phase;
8912047Schristian.menard@tu-dresden.de
9012047Schristian.menard@tu-dresden.de        /**
9112047Schristian.menard@tu-dresden.de         * Get time from SystemC as this will always be more up to date
9212047Schristian.menard@tu-dresden.de         * than gem5's
9312047Schristian.menard@tu-dresden.de         */
9412047Schristian.menard@tu-dresden.de        Tick nextEventTick = sc_core::sc_time_stamp().value() + delay.value();
9512047Schristian.menard@tu-dresden.de
9612047Schristian.menard@tu-dresden.de        port.owner.wakeupEventQueue(nextEventTick);
9712047Schristian.menard@tu-dresden.de        port.owner.schedule(this, nextEventTick);
9812047Schristian.menard@tu-dresden.de    }
9912047Schristian.menard@tu-dresden.de};
10012047Schristian.menard@tu-dresden.de}
10112047Schristian.menard@tu-dresden.de
10212047Schristian.menard@tu-dresden.de#endif
103