gem5  v20.1.0.0
intdev.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012 ARM Limited
3  * All rights reserved
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Copyright (c) 2008 The Regents of The University of Michigan
15  * All rights reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions are
19  * met: redistributions of source code must retain the above copyright
20  * notice, this list of conditions and the following disclaimer;
21  * redistributions in binary form must reproduce the above copyright
22  * notice, this list of conditions and the following disclaimer in the
23  * documentation and/or other materials provided with the distribution;
24  * neither the name of the copyright holders nor the names of its
25  * contributors may be used to endorse or promote products derived from
26  * this software without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  */
40 
41 #ifndef __DEV_X86_INTDEV_HH__
42 #define __DEV_X86_INTDEV_HH__
43 
44 #include <cassert>
45 #include <functional>
46 #include <string>
47 
48 #include "base/cast.hh"
49 #include "mem/tport.hh"
50 #include "sim/sim_object.hh"
51 
52 namespace X86ISA
53 {
54 
55 template <class Device>
57 {
58  Device * device;
59 
60  public:
61  IntResponsePort(const std::string& _name, SimObject* _parent,
62  Device* dev) :
63  SimpleTimingPort(_name, _parent), device(dev)
64  {
65  }
66 
68  getAddrRanges() const
69  {
70  return device->getIntAddrRange();
71  }
72 
73  Tick
75  {
77  "%s received unexpected command %s from %s.\n",
78  name(), pkt->cmd.toString(), getPeer());
79  pkt->headerDelay = pkt->payloadDelay = 0;
80  return device->recvMessage(pkt);
81  }
82 };
83 
84 template<class T>
87 {
88  RequestPtr req = std::make_shared<Request>(
90  PacketPtr pkt = new Packet(req, MemCmd::WriteReq);
91  pkt->allocate();
92  pkt->setRaw<T>(payload);
93  return pkt;
94 }
95 
96 template <class Device>
98 {
99  private:
102 
103  Device* device;
105 
106  typedef std::function<void(PacketPtr)> OnCompletionFunc;
108  {
110  OnCompletion(OnCompletionFunc _func) : func(_func) {}
111  };
112  // If nothing extra needs to happen, just clean up the packet.
113  static void defaultOnCompletion(PacketPtr pkt) { delete pkt; }
114 
115  public:
116  IntRequestPort(const std::string& _name, SimObject* _parent,
117  Device* dev, Tick _latency) :
118  QueuedRequestPort(_name, _parent, reqQueue, snoopRespQueue),
119  reqQueue(*_parent, *this), snoopRespQueue(*_parent, *this),
120  device(dev), latency(_latency)
121  {
122  }
123 
124  bool
125  recvTimingResp(PacketPtr pkt) override
126  {
127  assert(pkt->isResponse());
128  auto *oc = safe_cast<OnCompletion *>(pkt->popSenderState());
129  oc->func(pkt);
130  delete oc;
131  return true;
132  }
133 
134  void
135  sendMessage(PacketPtr pkt, bool timing,
137  {
138  if (timing) {
139  pkt->pushSenderState(new OnCompletion(func));
140  schedTimingReq(pkt, curTick() + latency);
141  // The target handles cleaning up the packet in timing mode.
142  } else {
143  // ignore the latency involved in the atomic transaction
144  sendAtomic(pkt);
145  func(pkt);
146  }
147  }
148 };
149 
150 } // namespace X86ISA
151 
152 #endif //__DEV_X86_INTDEV_HH__
Request::intRequestorId
@ intRequestorId
This requestor id is used for message signaled interrupts.
Definition: request.hh:250
X86ISA::IntResponsePort::IntResponsePort
IntResponsePort(const std::string &_name, SimObject *_parent, Device *dev)
Definition: intdev.hh:61
SnoopRespPacketQueue
Definition: packet_queue.hh:258
X86ISA::IntRequestPort::OnCompletion::func
OnCompletionFunc func
Definition: intdev.hh:109
X86ISA::IntRequestPort::snoopRespQueue
SnoopRespPacketQueue snoopRespQueue
Definition: intdev.hh:101
Packet::isResponse
bool isResponse() const
Definition: packet.hh:560
Packet::payloadDelay
uint32_t payloadDelay
The extra pipelining delay from seeing the packet until the end of payload is transmitted by the comp...
Definition: packet.hh:412
Packet::setRaw
void setRaw(T v)
Set the value in the data pointer to v without byte swapping.
Definition: packet_access.hh:58
X86ISA::IntRequestPort::OnCompletionFunc
std::function< void(PacketPtr)> OnCompletionFunc
Definition: intdev.hh:106
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:63
cast.hh
RequestPtr
std::shared_ptr< Request > RequestPtr
Definition: request.hh:82
X86ISA::IntRequestPort::sendMessage
void sendMessage(PacketPtr pkt, bool timing, OnCompletionFunc func=defaultOnCompletion)
Definition: intdev.hh:135
Packet::headerDelay
uint32_t headerDelay
The extra delay from seeing the packet until the header is transmitted.
Definition: packet.hh:394
QueuedRequestPort::schedTimingReq
void schedTimingReq(PacketPtr pkt, Tick when)
Schedule the sending of a timing request.
Definition: qport.hh:146
MemCmd::WriteReq
@ WriteReq
Definition: packet.hh:85
X86ISA::IntRequestPort::IntRequestPort
IntRequestPort(const std::string &_name, SimObject *_parent, Device *dev, Tick _latency)
Definition: intdev.hh:116
Packet::SenderState
A virtual base opaque structure used to hold state associated with the packet (e.g....
Definition: packet.hh:431
MemCmd::toString
const std::string & toString() const
Return the string to a cmd given by idx.
Definition: packet.hh:239
sim_object.hh
QueuedRequestPort
The QueuedRequestPort combines two queues, a request queue and a snoop response queue,...
Definition: qport.hh:106
X86ISA::IntResponsePort::recvAtomic
Tick recvAtomic(PacketPtr pkt)
Receive an atomic request packet from the peer.
Definition: intdev.hh:74
X86ISA::IntRequestPort
Definition: intdev.hh:97
Request::UNCACHEABLE
@ UNCACHEABLE
The request is to an uncacheable address.
Definition: request.hh:114
X86ISA::IntResponsePort::getAddrRanges
AddrRangeList getAddrRanges() const
Get a list of the non-overlapping address ranges the owner is responsible for.
Definition: intdev.hh:68
X86ISA
This is exposed globally, independent of the ISA.
Definition: acpi.hh:55
ProbePoints::Packet
ProbePointArg< PacketInfo > Packet
Packet probe point.
Definition: mem.hh:103
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
Port::name
const std::string name() const
Return port name (for DPRINTF).
Definition: port.hh:106
X86ISA::IntRequestPort::device
Device * device
Definition: intdev.hh:103
X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:79
Packet::cmd
MemCmd cmd
The command field of the packet.
Definition: packet.hh:335
panic_if
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:197
Packet::pushSenderState
void pushSenderState(SenderState *sender_state)
Push a new sender state to the packet and make the current sender state the predecessor of the new on...
Definition: packet.cc:332
SimpleTimingPort
The simple timing port uses a queued port to implement recvFunctional and recvTimingReq through recvA...
Definition: tport.hh:59
X86ISA::IntResponsePort
Definition: intdev.hh:56
X86ISA::IntRequestPort::reqQueue
ReqPacketQueue reqQueue
Definition: intdev.hh:100
tport.hh
X86ISA::IntResponsePort::device
Device * device
Definition: intdev.hh:58
Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:257
Packet::popSenderState
SenderState * popSenderState()
Pop the top of the state stack and return a pointer to it.
Definition: packet.cc:340
X86ISA::IntRequestPort::defaultOnCompletion
static void defaultOnCompletion(PacketPtr pkt)
Definition: intdev.hh:113
Port::getPeer
Port & getPeer()
Return a reference to this port's peer.
Definition: port.hh:103
RequestPort::sendAtomic
Tick sendAtomic(PacketPtr pkt)
Send an atomic request packet, where the data is moved and the state is updated in zero time,...
Definition: port.hh:461
std::list< AddrRange >
X86ISA::IntRequestPort::OnCompletion
Definition: intdev.hh:107
X86ISA::IntRequestPort::recvTimingResp
bool recvTimingResp(PacketPtr pkt) override
Receive a timing response from the peer.
Definition: intdev.hh:125
Packet::allocate
void allocate()
Allocate memory for the packet.
Definition: packet.hh:1299
X86ISA::IntRequestPort::OnCompletion::OnCompletion
OnCompletion(OnCompletionFunc _func)
Definition: intdev.hh:110
X86ISA::buildIntPacket
PacketPtr buildIntPacket(Addr addr, T payload)
Definition: intdev.hh:86
ReqPacketQueue
Definition: packet_queue.hh:222
X86ISA::IntRequestPort::latency
Tick latency
Definition: intdev.hh:104
curTick
Tick curTick()
The current simulated tick.
Definition: core.hh:45
SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:92

Generated on Wed Sep 30 2020 14:02:12 for gem5 by doxygen 1.8.17