2 * Copyright (c) 2018-2020 ARM Limited
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.
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions are
16 * met: redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer;
18 * redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution;
21 * neither the name of the copyright holders nor the names of its
22 * contributors may be used to endorse or promote products derived from
23 * this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 * Author: Matteo Andreozzi
41 #ifndef __MEM_QOS_MEM_SINK_HH__
42 #define __MEM_QOS_MEM_SINK_HH__
44 #include "mem/abstract_mem.hh"
45 #include "mem/qos/mem_ctrl.hh"
46 #include "mem/qport.hh"
47 #include "params/QoSMemSinkCtrl.hh"
49 class QoSMemSinkInterfaceParams;
50 class QoSMemSinkInterface;
57 * The QoS Memory Sink is a lightweight memory controller with QoS
58 * support. It is meant to provide a QoS aware simple memory system
59 * without the need of using a complex DRAM memory controller
61 class MemSinkCtrl : public MemCtrl
65 * The Request packets are store in a multiple dequeue structure,
66 * based on their QoS priority
68 using PacketQueue = std::deque<PacketPtr>;
71 class MemoryPort : public QueuedSlavePort
74 /** reference to parent memory object */
77 /** Outgoing packet responses queue */
78 RespPacketQueue queue;
85 * @param m reference to ProfileGen parent object
87 MemoryPort(const std::string&, MemSinkCtrl&);
91 * Receive a Packet in Atomic mode
93 * @param pkt pointer to memory packet
94 * @return packet access latency in ticks
96 Tick recvAtomic(PacketPtr pkt);
99 * Receive a Packet in Functional mode
101 * @param pkt pointer to memory packet
103 void recvFunctional(PacketPtr pkt);
106 * Receive a Packet in Timing mode
108 * @param pkt pointer to memory packet
109 * @return true if the request was accepted
111 bool recvTimingReq(PacketPtr pkt);
114 * Gets the configured address ranges for this port
115 * @return the configured address ranges for this port
117 AddrRangeList getAddrRanges() const;
123 * QoS Memory Sink Constructor
125 * @param p QoS Memory Sink configuration parameters
127 MemSinkCtrl(const QoSMemSinkCtrlParams*);
129 virtual ~MemSinkCtrl();
132 * Checks and return the Drain state of this SimObject
133 * @return current Drain state
135 DrainState drain() override;
138 * Getter method to access this memory's slave port
140 * @param if_name interface name
141 * @param idx port ID number
142 * @return reference to this memory's slave port
144 Port &getPort(const std::string &if_name, PortID=InvalidPortID) override;
147 * Initializes this object
149 void init() override;
152 /** Memory between requests latency (ticks) */
153 const Tick requestLatency;
155 /** Memory response latency (ticks) */
156 const Tick responseLatency;
158 /** Memory packet size in bytes */
159 const uint64_t memoryPacketSize;
161 /** Read request packets queue buffer size in #packets */
162 const uint64_t readBufferSize;
164 /** Write request packets queue buffer size in #packets */
165 const uint64_t writeBufferSize;
167 /** Memory slave port */
171 * Create pointer to interface of actual media
173 QoSMemSinkInterface* const interface;
175 /** Read request pending */
178 /** Write request pending */
181 /** Next request service time */
184 /** Count the number of read retries */
185 Stats::Scalar numReadRetries;
187 /** Count the number of write retries */
188 Stats::Scalar numWriteRetries;
191 * QoS-aware (per priority) incoming read requests packets queue
193 std::vector<PacketQueue> readQueue;
196 * QoS-aware (per priority) incoming read requests packets queue
198 std::vector<PacketQueue> writeQueue;
201 * Processes the next Request event according to configured
204 void processNextReqEvent();
206 /** Event wrapper to schedule next request handler function */
209 &MemSinkCtrl::processNextReqEvent> nextReqEvent;
212 * Check if the read queue has room for more entries
214 * @param packets The number of entries needed in the read queue
215 * @return true if read queue is full, false otherwise
217 inline bool readQueueFull(const uint64_t packets) const;
220 * Check if the write queue has room for more entries
222 * @param packets The number of entries needed in the write queue
223 * @return true if write queue is full, false otherwise
225 inline bool writeQueueFull(const uint64_t packets) const;
228 * Receive a Packet in Atomic mode
230 * @param pkt pointer to memory packet
231 * @return packet access latency in ticks
233 Tick recvAtomic(PacketPtr pkt);
236 * Receive a Packet in Functional mode
238 * @param pkt pointer to memory packet
240 void recvFunctional(PacketPtr pkt);
243 * Receive a Packet in Timing mode
245 * @param pkt pointer to memory packet
246 * @return true if the request was accepted
248 bool recvTimingReq(PacketPtr pkt);
250 /** Registers statistics */
251 void regStats() override;
256 class QoSMemSinkInterface : public AbstractMemory
259 /** Setting a pointer to the interface */
260 void setMemCtrl(QoS::MemSinkCtrl* _ctrl) { ctrl = _ctrl; };
262 /** Pointer to the controller */
263 QoS::MemSinkCtrl* ctrl;
265 QoSMemSinkInterface(const QoSMemSinkInterfaceParams* _p);
269 #endif /* __MEM_QOS_MEM_SINK_HH__ */