112966SMatteo.Andreozzi@arm.com/*
212966SMatteo.Andreozzi@arm.com * Copyright (c) 2018 ARM Limited
312966SMatteo.Andreozzi@arm.com * All rights reserved
412966SMatteo.Andreozzi@arm.com *
512966SMatteo.Andreozzi@arm.com * The license below extends only to copyright in the software and shall
612966SMatteo.Andreozzi@arm.com * not be construed as granting a license to any other intellectual
712966SMatteo.Andreozzi@arm.com * property including but not limited to intellectual property relating
812966SMatteo.Andreozzi@arm.com * to a hardware implementation of the functionality of the software
912966SMatteo.Andreozzi@arm.com * licensed hereunder.  You may use the software subject to the license
1012966SMatteo.Andreozzi@arm.com * terms below provided that you ensure that this notice is replicated
1112966SMatteo.Andreozzi@arm.com * unmodified and in its entirety in all distributions of the software,
1212966SMatteo.Andreozzi@arm.com * modified or unmodified, in source code or in binary form.
1312966SMatteo.Andreozzi@arm.com *
1412966SMatteo.Andreozzi@arm.com * Redistribution and use in source and binary forms, with or without
1512966SMatteo.Andreozzi@arm.com * modification, are permitted provided that the following conditions are
1612966SMatteo.Andreozzi@arm.com * met: redistributions of source code must retain the above copyright
1712966SMatteo.Andreozzi@arm.com * notice, this list of conditions and the following disclaimer;
1812966SMatteo.Andreozzi@arm.com * redistributions in binary form must reproduce the above copyright
1912966SMatteo.Andreozzi@arm.com * notice, this list of conditions and the following disclaimer in the
2012966SMatteo.Andreozzi@arm.com * documentation and/or other materials provided with the distribution;
2112966SMatteo.Andreozzi@arm.com * neither the name of the copyright holders nor the names of its
2212966SMatteo.Andreozzi@arm.com * contributors may be used to endorse or promote products derived from
2312966SMatteo.Andreozzi@arm.com * this software without specific prior written permission.
2412966SMatteo.Andreozzi@arm.com *
2512966SMatteo.Andreozzi@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2612966SMatteo.Andreozzi@arm.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2712966SMatteo.Andreozzi@arm.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2812966SMatteo.Andreozzi@arm.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2912966SMatteo.Andreozzi@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3012966SMatteo.Andreozzi@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3112966SMatteo.Andreozzi@arm.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3212966SMatteo.Andreozzi@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3312966SMatteo.Andreozzi@arm.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3412966SMatteo.Andreozzi@arm.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3512966SMatteo.Andreozzi@arm.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3612966SMatteo.Andreozzi@arm.com *
3712966SMatteo.Andreozzi@arm.com * Author: Matteo Andreozzi
3812966SMatteo.Andreozzi@arm.com */
3912966SMatteo.Andreozzi@arm.com
4012966SMatteo.Andreozzi@arm.com#ifndef __MEM_QOS_POLICY_HH__
4112966SMatteo.Andreozzi@arm.com#define __MEM_QOS_POLICY_HH__
4212966SMatteo.Andreozzi@arm.com
4312966SMatteo.Andreozzi@arm.com#include "base/trace.hh"
4412966SMatteo.Andreozzi@arm.com#include "debug/QOS.hh"
4512966SMatteo.Andreozzi@arm.com#include "mem/qos/mem_ctrl.hh"
4612966SMatteo.Andreozzi@arm.com#include "mem/packet.hh"
4712966SMatteo.Andreozzi@arm.com#include "sim/system.hh"
4812966SMatteo.Andreozzi@arm.com
4912966SMatteo.Andreozzi@arm.comnamespace QoS {
5012966SMatteo.Andreozzi@arm.com
5112966SMatteo.Andreozzi@arm.com/**
5212966SMatteo.Andreozzi@arm.com * QoS Policy base class
5312966SMatteo.Andreozzi@arm.com *
5412966SMatteo.Andreozzi@arm.com * QoS Policy base class: all QoS policies derive from this class to
5512966SMatteo.Andreozzi@arm.com * implement specific QoS scheduling algorithms
5612966SMatteo.Andreozzi@arm.com *
5712966SMatteo.Andreozzi@arm.com */
5812966SMatteo.Andreozzi@arm.comclass Policy : public SimObject
5912966SMatteo.Andreozzi@arm.com{
6012966SMatteo.Andreozzi@arm.com  public:
6112966SMatteo.Andreozzi@arm.com    using Params = QoSPolicyParams;
6212966SMatteo.Andreozzi@arm.com    Policy(const Params* p);
6312966SMatteo.Andreozzi@arm.com
6412966SMatteo.Andreozzi@arm.com    virtual ~Policy();
6512966SMatteo.Andreozzi@arm.com
6612966SMatteo.Andreozzi@arm.com    virtual void regStats() override {};
6712966SMatteo.Andreozzi@arm.com
6812966SMatteo.Andreozzi@arm.com    virtual void init() override {};
6912966SMatteo.Andreozzi@arm.com
7012966SMatteo.Andreozzi@arm.com    /**
7112966SMatteo.Andreozzi@arm.com     * Setting a pointer to the Memory Controller implementing
7212966SMatteo.Andreozzi@arm.com     * the policy.
7312966SMatteo.Andreozzi@arm.com     */
7412966SMatteo.Andreozzi@arm.com    void setMemCtrl(MemCtrl* mem) { memCtrl = mem; };
7512966SMatteo.Andreozzi@arm.com
7612966SMatteo.Andreozzi@arm.com    /**
7712966SMatteo.Andreozzi@arm.com     * Builds a MasterID/value pair given a master input.
7812966SMatteo.Andreozzi@arm.com     * This will be lookuped in the system list of masters in order
7912966SMatteo.Andreozzi@arm.com     * to retrieve the associated MasterID.
8012966SMatteo.Andreozzi@arm.com     * In case the master name/object cannot be resolved, the pairing
8112966SMatteo.Andreozzi@arm.com     * method will panic.
8212966SMatteo.Andreozzi@arm.com     *
8312966SMatteo.Andreozzi@arm.com     * @param master Master to lookup in the system
8412966SMatteo.Andreozzi@arm.com     * @param value Value to be associated with the MasterID
8512966SMatteo.Andreozzi@arm.com     * @return A MasterID/Value pair.
8612966SMatteo.Andreozzi@arm.com     */
8712966SMatteo.Andreozzi@arm.com    template <typename M, typename T>
8812966SMatteo.Andreozzi@arm.com    std::pair<MasterID, T> pair(M master, T value);
8912966SMatteo.Andreozzi@arm.com
9012966SMatteo.Andreozzi@arm.com    /**
9112966SMatteo.Andreozzi@arm.com     * Schedules data - must be defined by derived class
9212966SMatteo.Andreozzi@arm.com     *
9312966SMatteo.Andreozzi@arm.com     * @param mId master id to schedule
9412966SMatteo.Andreozzi@arm.com     * @param data data to schedule
9512966SMatteo.Andreozzi@arm.com     * @return QoS priority value
9612966SMatteo.Andreozzi@arm.com     */
9712966SMatteo.Andreozzi@arm.com    virtual uint8_t schedule(const MasterID mId, const uint64_t data) = 0;
9812966SMatteo.Andreozzi@arm.com
9912966SMatteo.Andreozzi@arm.com    /**
10012966SMatteo.Andreozzi@arm.com     * Schedules a packet. Non virtual interface for the scheduling
10112966SMatteo.Andreozzi@arm.com     * method requiring a master ID.
10212966SMatteo.Andreozzi@arm.com     *
10312966SMatteo.Andreozzi@arm.com     * @param pkt pointer to packet to schedule
10412966SMatteo.Andreozzi@arm.com     * @return QoS priority value
10512966SMatteo.Andreozzi@arm.com     */
10612966SMatteo.Andreozzi@arm.com    uint8_t schedule(const PacketPtr pkt);
10712966SMatteo.Andreozzi@arm.com
10812966SMatteo.Andreozzi@arm.com  protected:
10912966SMatteo.Andreozzi@arm.com    /** Pointer to parent memory controller implementing the policy */
11012966SMatteo.Andreozzi@arm.com    MemCtrl* memCtrl;
11112966SMatteo.Andreozzi@arm.com};
11212966SMatteo.Andreozzi@arm.com
11312966SMatteo.Andreozzi@arm.comtemplate <typename M, typename T>
11412966SMatteo.Andreozzi@arm.comstd::pair<MasterID, T>
11512966SMatteo.Andreozzi@arm.comPolicy::pair(M master, T value)
11612966SMatteo.Andreozzi@arm.com{
11712966SMatteo.Andreozzi@arm.com    auto id = memCtrl->system()->lookupMasterId(master);
11812966SMatteo.Andreozzi@arm.com
11912966SMatteo.Andreozzi@arm.com    panic_if(id == Request::invldMasterId,
12012966SMatteo.Andreozzi@arm.com             "Unable to find master %s\n", master);
12112966SMatteo.Andreozzi@arm.com
12212966SMatteo.Andreozzi@arm.com    DPRINTF(QOS,
12312966SMatteo.Andreozzi@arm.com            "Master %s [id %d] associated with QoS data %d\n",
12412966SMatteo.Andreozzi@arm.com            master, id, value);
12512966SMatteo.Andreozzi@arm.com
12612966SMatteo.Andreozzi@arm.com    return std::pair<MasterID, T>(id, value);
12712966SMatteo.Andreozzi@arm.com}
12812966SMatteo.Andreozzi@arm.com
12912966SMatteo.Andreozzi@arm.com} // namespace QoS
13012966SMatteo.Andreozzi@arm.com
13112966SMatteo.Andreozzi@arm.com#endif /* __MEM_QOS_POLICY_HH__ */
132