2 * Copyright (c) 2018 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
40 #ifndef __MEM_QOS_POLICY_HH__
41 #define __MEM_QOS_POLICY_HH__
43 #include "base/trace.hh"
44 #include "debug/QOS.hh"
45 #include "mem/qos/mem_ctrl.hh"
46 #include "mem/packet.hh"
47 #include "sim/system.hh"
52 * QoS Policy base class
54 * QoS Policy base class: all QoS policies derive from this class to
55 * implement specific QoS scheduling algorithms
58 class Policy : public SimObject
61 using Params = QoSPolicyParams;
62 Policy(const Params* p);
66 virtual void regStats() override {};
68 virtual void init() override {};
71 * Setting a pointer to the Memory Controller implementing
74 void setMemCtrl(MemCtrl* mem) { memCtrl = mem; };
77 * Builds a MasterID/value pair given a master input.
78 * This will be lookuped in the system list of masters in order
79 * to retrieve the associated MasterID.
80 * In case the master name/object cannot be resolved, the pairing
83 * @param master Master to lookup in the system
84 * @param value Value to be associated with the MasterID
85 * @return A MasterID/Value pair.
87 template <typename M, typename T>
88 std::pair<MasterID, T> pair(M master, T value);
91 * Schedules data - must be defined by derived class
93 * @param mId master id to schedule
94 * @param data data to schedule
95 * @return QoS priority value
97 virtual uint8_t schedule(const MasterID mId, const uint64_t data) = 0;
100 * Schedules a packet. Non virtual interface for the scheduling
101 * method requiring a master ID.
103 * @param pkt pointer to packet to schedule
104 * @return QoS priority value
106 uint8_t schedule(const PacketPtr pkt);
109 /** Pointer to parent memory controller implementing the policy */
113 template <typename M, typename T>
114 std::pair<MasterID, T>
115 Policy::pair(M master, T value)
117 auto id = memCtrl->system()->lookupMasterId(master);
119 panic_if(id == Request::invldMasterId,
120 "Unable to find master %s\n", master);
123 "Master %s [id %d] associated with QoS data %d\n",
126 return std::pair<MasterID, T>(id, value);
131 #endif /* __MEM_QOS_POLICY_HH__ */