* 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 "mem/tport.hh"
template <class Device>
class IntMasterPort : public QueuedMasterPort
{
+ private:
ReqPacketQueue reqQueue;
SnoopRespPacketQueue snoopRespQueue;
Device* device;
Tick latency;
+ 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:
IntMasterPort(const std::string& _name, SimObject* _parent,
Device* dev, Tick _latency) :
bool
recvTimingResp(PacketPtr pkt) override
{
- return device->recvResponse(pkt);
+ assert(pkt->isResponse());
+ onCompletion(pkt);
+ onCompletion = nullptr;
+ return true;
}
void
- sendMessage(PacketPtr pkt, bool timing)
+ sendMessage(PacketPtr pkt, bool timing,
+ OnCompletionFunc func=defaultOnCompletion)
{
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);
- assert(pkt->isResponse());
- // also ignore the latency in handling the response
- device->recvResponse(pkt);
+ func(pkt);
}
}
};