113820Sgabeblack@google.com/*
213820Sgabeblack@google.com * Copyright (c) 2015, University of Kaiserslautern
313820Sgabeblack@google.com * Copyright (c) 2016, Dresden University of Technology (TU Dresden)
413820Sgabeblack@google.com * All rights reserved.
513820Sgabeblack@google.com *
613820Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
713820Sgabeblack@google.com * modification, are permitted provided that the following conditions are
813820Sgabeblack@google.com * met:
913820Sgabeblack@google.com *
1013820Sgabeblack@google.com * 1. Redistributions of source code must retain the above copyright notice,
1113820Sgabeblack@google.com *    this list of conditions and the following disclaimer.
1213820Sgabeblack@google.com *
1313820Sgabeblack@google.com * 2. Redistributions in binary form must reproduce the above copyright
1413820Sgabeblack@google.com *    notice, this list of conditions and the following disclaimer in the
1513820Sgabeblack@google.com *    documentation and/or other materials provided with the distribution.
1613820Sgabeblack@google.com *
1713820Sgabeblack@google.com * 3. Neither the name of the copyright holder nor the names of its
1813820Sgabeblack@google.com *    contributors may be used to endorse or promote products derived from
1913820Sgabeblack@google.com *    this software without specific prior written permission.
2013820Sgabeblack@google.com *
2113820Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2213820Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2313820Sgabeblack@google.com * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2413820Sgabeblack@google.com * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
2513820Sgabeblack@google.com * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
2613820Sgabeblack@google.com * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
2713820Sgabeblack@google.com * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
2813820Sgabeblack@google.com * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
2913820Sgabeblack@google.com * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
3013820Sgabeblack@google.com * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
3113820Sgabeblack@google.com * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3213820Sgabeblack@google.com *
3313820Sgabeblack@google.com * Authors: Matthias Jung
3413820Sgabeblack@google.com *          Christian Menard
3513820Sgabeblack@google.com */
3613820Sgabeblack@google.com
3713820Sgabeblack@google.com#ifndef PAYLOAD_EVENT_H_
3813820Sgabeblack@google.com#define PAYLOAD_EVENT_H_
3913820Sgabeblack@google.com
4013820Sgabeblack@google.com// TLM includes
4113820Sgabeblack@google.com#include <tlm.h>
4213820Sgabeblack@google.com
4313820Sgabeblack@google.com// gem5 includes
4413820Sgabeblack@google.com#include <sim/eventq.hh>
4513820Sgabeblack@google.com
4613820Sgabeblack@google.comnamespace Gem5SystemC {
4713820Sgabeblack@google.com/**
4813820Sgabeblack@google.com * A 'Fake Payload Event Queue', similar to the TLM PEQs. This helps the
4913820Sgabeblack@google.com * transactors to schedule events in gem5.
5013820Sgabeblack@google.com */
5113820Sgabeblack@google.comtemplate <typename OWNER>
5213820Sgabeblack@google.comclass PayloadEvent : public Event
5313820Sgabeblack@google.com{
5413820Sgabeblack@google.com  public:
5513820Sgabeblack@google.com    OWNER& port;
5613820Sgabeblack@google.com    const std::string eventName;
5713820Sgabeblack@google.com    void (OWNER::*handler)(PayloadEvent<OWNER>* pe,
5813820Sgabeblack@google.com                           tlm::tlm_generic_payload& trans,
5913820Sgabeblack@google.com                           const tlm::tlm_phase& phase);
6013820Sgabeblack@google.com
6113820Sgabeblack@google.com  protected:
6213820Sgabeblack@google.com    tlm::tlm_generic_payload* t;
6313820Sgabeblack@google.com    tlm::tlm_phase p;
6413820Sgabeblack@google.com
6513820Sgabeblack@google.com    void process() { (port.*handler)(this, *t, p); }
6613820Sgabeblack@google.com
6713820Sgabeblack@google.com  public:
6813820Sgabeblack@google.com    const std::string name() const { return eventName; }
6913820Sgabeblack@google.com
7013820Sgabeblack@google.com    PayloadEvent(OWNER& port_,
7113820Sgabeblack@google.com                 void (OWNER::*handler_)(PayloadEvent<OWNER>* pe,
7213820Sgabeblack@google.com                                         tlm::tlm_generic_payload& trans,
7313820Sgabeblack@google.com                                         const tlm::tlm_phase& phase),
7413820Sgabeblack@google.com                 const std::string& event_name)
7513820Sgabeblack@google.com      : port(port_)
7613820Sgabeblack@google.com      , eventName(event_name)
7713820Sgabeblack@google.com      , handler(handler_)
7813820Sgabeblack@google.com    {
7913820Sgabeblack@google.com    }
8013820Sgabeblack@google.com
8113820Sgabeblack@google.com    /// Schedule an event into gem5
8213820Sgabeblack@google.com    void notify(tlm::tlm_generic_payload& trans, const tlm::tlm_phase& phase,
8313820Sgabeblack@google.com                const sc_core::sc_time& delay)
8413820Sgabeblack@google.com    {
8513820Sgabeblack@google.com        assert(!scheduled());
8613820Sgabeblack@google.com
8713820Sgabeblack@google.com        t = &trans;
8813820Sgabeblack@google.com        p = phase;
8913820Sgabeblack@google.com
9013820Sgabeblack@google.com        /**
9113820Sgabeblack@google.com         * Get time from SystemC as this will always be more up to date
9213820Sgabeblack@google.com         * than gem5's
9313820Sgabeblack@google.com         */
9413820Sgabeblack@google.com        Tick nextEventTick = sc_core::sc_time_stamp().value() + delay.value();
9513820Sgabeblack@google.com
9613820Sgabeblack@google.com        port.owner.wakeupEventQueue(nextEventTick);
9713820Sgabeblack@google.com        port.owner.schedule(this, nextEventTick);
9813820Sgabeblack@google.com    }
9913820Sgabeblack@google.com};
10013820Sgabeblack@google.com}
10113820Sgabeblack@google.com
10213820Sgabeblack@google.com#endif
103