1/* 2 * Copyright (c) 2015, University of Kaiserslautern 3 * Copyright (c) 2016, Dresden University of Technology (TU Dresden) 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are 8 * met: 9 * 10 * 1. Redistributions of source code must retain the above copyright notice, 11 * this list of conditions and the following disclaimer. 12 * 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * 3. Neither the name of the copyright holder nor the names of its 18 * contributors may be used to endorse or promote products derived from 19 * this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 25 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 * 33 * Authors: Matthias Jung 34 * Christian Menard 35 */ 36 37#ifndef PAYLOAD_EVENT_H_ 38#define PAYLOAD_EVENT_H_ 39 40// TLM includes 41#include <tlm.h> 42 43// gem5 includes 44#include <sim/eventq.hh> 45 46namespace Gem5SystemC { 47/** 48 * A 'Fake Payload Event Queue', similar to the TLM PEQs. This helps the 49 * transactors to schedule events in gem5. 50 */ 51template <typename OWNER> 52class PayloadEvent : public Event 53{ 54 public: 55 OWNER& port; 56 const std::string eventName; 57 void (OWNER::*handler)(PayloadEvent<OWNER>* pe, 58 tlm::tlm_generic_payload& trans, 59 const tlm::tlm_phase& phase); 60 61 protected: 62 tlm::tlm_generic_payload* t; 63 tlm::tlm_phase p; 64 65 void process() { (port.*handler)(this, *t, p); } 66 67 public: 68 const std::string name() const { return eventName; } 69 70 PayloadEvent(OWNER& port_, 71 void (OWNER::*handler_)(PayloadEvent<OWNER>* pe, 72 tlm::tlm_generic_payload& trans, 73 const tlm::tlm_phase& phase), 74 const std::string& event_name) 75 : port(port_) 76 , eventName(event_name) 77 , handler(handler_) 78 { 79 } 80 81 /// Schedule an event into gem5 82 void notify(tlm::tlm_generic_payload& trans, const tlm::tlm_phase& phase, 83 const sc_core::sc_time& delay) 84 { 85 assert(!scheduled()); 86 87 t = &trans; 88 p = phase; 89 90 /** 91 * Get time from SystemC as this will always be more up to date 92 * than gem5's 93 */ 94 Tick nextEventTick = sc_core::sc_time_stamp().value() + delay.value(); 95 96 port.owner.wakeupEventQueue(nextEventTick); 97 port.owner.schedule(this, nextEventTick); 98 } 99}; 100} 101 102#endif 103