19827Sakash.bagdia@arm.com/*
29827Sakash.bagdia@arm.com * Copyright (c) 2012 ARM Limited
39827Sakash.bagdia@arm.com * All rights reserved
49827Sakash.bagdia@arm.com *
59827Sakash.bagdia@arm.com * The license below extends only to copyright in the software and shall
69827Sakash.bagdia@arm.com * not be construed as granting a license to any other intellectual
79827Sakash.bagdia@arm.com * property including but not limited to intellectual property relating
89827Sakash.bagdia@arm.com * to a hardware implementation of the functionality of the software
99827Sakash.bagdia@arm.com * licensed hereunder.  You may use the software subject to the license
109827Sakash.bagdia@arm.com * terms below provided that you ensure that this notice is replicated
119827Sakash.bagdia@arm.com * unmodified and in its entirety in all distributions of the software,
129827Sakash.bagdia@arm.com * modified or unmodified, in source code or in binary form.
139827Sakash.bagdia@arm.com *
149827Sakash.bagdia@arm.com * Redistribution and use in source and binary forms, with or without
159827Sakash.bagdia@arm.com * modification, are permitted provided that the following conditions are
169827Sakash.bagdia@arm.com * met: redistributions of source code must retain the above copyright
179827Sakash.bagdia@arm.com * notice, this list of conditions and the following disclaimer;
189827Sakash.bagdia@arm.com * redistributions in binary form must reproduce the above copyright
199827Sakash.bagdia@arm.com * notice, this list of conditions and the following disclaimer in the
209827Sakash.bagdia@arm.com * documentation and/or other materials provided with the distribution;
219827Sakash.bagdia@arm.com * neither the name of the copyright holders nor the names of its
229827Sakash.bagdia@arm.com * contributors may be used to endorse or promote products derived from
239827Sakash.bagdia@arm.com * this software without specific prior written permission.
249827Sakash.bagdia@arm.com *
259827Sakash.bagdia@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
269827Sakash.bagdia@arm.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
279827Sakash.bagdia@arm.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
289827Sakash.bagdia@arm.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
299827Sakash.bagdia@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
309827Sakash.bagdia@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
319827Sakash.bagdia@arm.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
329827Sakash.bagdia@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
339827Sakash.bagdia@arm.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
349827Sakash.bagdia@arm.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
359827Sakash.bagdia@arm.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
369827Sakash.bagdia@arm.com *
379827Sakash.bagdia@arm.com * Authors: Vasileios Spiliopoulos
389827Sakash.bagdia@arm.com *          Akash Bagdia
399827Sakash.bagdia@arm.com */
409827Sakash.bagdia@arm.com
419827Sakash.bagdia@arm.com#ifndef __SIM_VOLTAGE_DOMAIN_HH__
429827Sakash.bagdia@arm.com#define __SIM_VOLTAGE_DOMAIN_HH__
439827Sakash.bagdia@arm.com
4410249Sstephan.diestelhorst@arm.com#include <vector>
4510249Sstephan.diestelhorst@arm.com
469827Sakash.bagdia@arm.com#include "base/statistics.hh"
479827Sakash.bagdia@arm.com#include "params/VoltageDomain.hh"
4810249Sstephan.diestelhorst@arm.com#include "sim/clock_domain.hh"
499827Sakash.bagdia@arm.com#include "sim/sim_object.hh"
509827Sakash.bagdia@arm.com
519827Sakash.bagdia@arm.com/**
529827Sakash.bagdia@arm.com * A VoltageDomain is used to group clock domains that operate under
539827Sakash.bagdia@arm.com * the same voltage. The class provides methods for setting and
549827Sakash.bagdia@arm.com * getting the voltage.
559827Sakash.bagdia@arm.com */
569827Sakash.bagdia@arm.comclass VoltageDomain : public SimObject
579827Sakash.bagdia@arm.com{
5810249Sstephan.diestelhorst@arm.com  public:
599827Sakash.bagdia@arm.com
6010249Sstephan.diestelhorst@arm.com    typedef VoltageDomainParams Params;
6110249Sstephan.diestelhorst@arm.com    VoltageDomain(const Params *p);
629827Sakash.bagdia@arm.com
6310395Sstephan.diestelhorst@arm.com    typedef SrcClockDomain::PerfLevel PerfLevel;
6410395Sstephan.diestelhorst@arm.com
659827Sakash.bagdia@arm.com    /**
6610249Sstephan.diestelhorst@arm.com     * Get the current voltage.
6710249Sstephan.diestelhorst@arm.com     *
6810249Sstephan.diestelhorst@arm.com     * @return Voltage of the domain
699827Sakash.bagdia@arm.com     */
7010249Sstephan.diestelhorst@arm.com    double voltage() const { return voltageOpPoints[_perfLevel]; }
7110249Sstephan.diestelhorst@arm.com
7210395Sstephan.diestelhorst@arm.com    /**
7310395Sstephan.diestelhorst@arm.com     * Get the voltage at specified performance level.
7410395Sstephan.diestelhorst@arm.com     *
7510395Sstephan.diestelhorst@arm.com     * @param perf_level Performance level for which the voltage is requested
7610395Sstephan.diestelhorst@arm.com     * @return Voltage of the domain at specified performance level
7710395Sstephan.diestelhorst@arm.com     */
7810395Sstephan.diestelhorst@arm.com    double voltage(PerfLevel perf_level) const
7910395Sstephan.diestelhorst@arm.com    {
8010398Sstephan.diestelhorst@arm.com        chatty_assert(perf_level < numVoltages(), "VoltageDomain %s "\
8110398Sstephan.diestelhorst@arm.com                      "request for voltage perf level %u is outside "\
8210398Sstephan.diestelhorst@arm.com                      "of numVoltages %u", name(), perf_level,
8310398Sstephan.diestelhorst@arm.com                      numVoltages());
8410395Sstephan.diestelhorst@arm.com        return voltageOpPoints[perf_level];
8510395Sstephan.diestelhorst@arm.com    }
8610395Sstephan.diestelhorst@arm.com
8710249Sstephan.diestelhorst@arm.com    uint32_t numVoltages() const { return (uint32_t)voltageOpPoints.size(); }
8810249Sstephan.diestelhorst@arm.com
8910249Sstephan.diestelhorst@arm.com    /**
9010249Sstephan.diestelhorst@arm.com     * Set the voltage point of the domain.
9110249Sstephan.diestelhorst@arm.com     * @param Voltage value to be set
9210249Sstephan.diestelhorst@arm.com     */
9310249Sstephan.diestelhorst@arm.com    void perfLevel(PerfLevel perf_level);
9410249Sstephan.diestelhorst@arm.com
9510249Sstephan.diestelhorst@arm.com    /**
9610249Sstephan.diestelhorst@arm.com     * Get the voltage point of the domain.
9710249Sstephan.diestelhorst@arm.com     * @param Voltage value to be set
9810249Sstephan.diestelhorst@arm.com     */
9910249Sstephan.diestelhorst@arm.com    PerfLevel perfLevel() const { return _perfLevel; }
10010249Sstephan.diestelhorst@arm.com
10110249Sstephan.diestelhorst@arm.com    /**
10210249Sstephan.diestelhorst@arm.com     * Register a SrcClockDomain with this voltage domain.
10310249Sstephan.diestelhorst@arm.com     * @param src_clock_domain The SrcClockDomain to register.
10410249Sstephan.diestelhorst@arm.com     */
10510249Sstephan.diestelhorst@arm.com    void registerSrcClockDom(SrcClockDomain *src_clock_dom) {
10610249Sstephan.diestelhorst@arm.com        assert(src_clock_dom->voltageDomain() == this);
10710249Sstephan.diestelhorst@arm.com        srcClockChildren.push_back(src_clock_dom);
10810249Sstephan.diestelhorst@arm.com    }
10910249Sstephan.diestelhorst@arm.com
11010249Sstephan.diestelhorst@arm.com    /**
11110249Sstephan.diestelhorst@arm.com     * Startup has all SrcClockDomains registered with this voltage domain, so
11210249Sstephan.diestelhorst@arm.com     * try to make sure that all perf level requests from them are met.
11310249Sstephan.diestelhorst@arm.com     */
11411169Sandreas.hansson@arm.com    void startup() override;
11510249Sstephan.diestelhorst@arm.com
11610249Sstephan.diestelhorst@arm.com    /**
11710249Sstephan.diestelhorst@arm.com     * Recomputes the highest (fastest, i.e., numerically lowest) requested
11810249Sstephan.diestelhorst@arm.com     * performance level of all associated clock domains, and updates the
11910249Sstephan.diestelhorst@arm.com     * performance level of this voltage domain to match.  This means that for
12010249Sstephan.diestelhorst@arm.com     * two connected clock domains, one fast and one slow, the voltage domain
12110249Sstephan.diestelhorst@arm.com     * will provide the voltage associated with the fast DVFS operation point.
12210249Sstephan.diestelhorst@arm.com     * Must be called whenever a clock domain decides to swtich its performance
12310249Sstephan.diestelhorst@arm.com     * level.
12410249Sstephan.diestelhorst@arm.com     *
12510249Sstephan.diestelhorst@arm.com     * @return True, if the voltage was actually changed.
12610249Sstephan.diestelhorst@arm.com     */
12710249Sstephan.diestelhorst@arm.com    bool sanitiseVoltages();
12810249Sstephan.diestelhorst@arm.com
12911169Sandreas.hansson@arm.com    void regStats() override;
13010249Sstephan.diestelhorst@arm.com
13111168Sandreas.hansson@arm.com    void serialize(CheckpointOut &cp) const override;
13211168Sandreas.hansson@arm.com    void unserialize(CheckpointIn &cp) override;
13310905Sandreas.sandberg@arm.com
13410249Sstephan.diestelhorst@arm.com  private:
13510249Sstephan.diestelhorst@arm.com    typedef std::vector<double> Voltages;
13610249Sstephan.diestelhorst@arm.com    /**
13710249Sstephan.diestelhorst@arm.com     * List of possible minimum voltage at each of the frequency operational
13810249Sstephan.diestelhorst@arm.com     * points, should be in descending order and same size as freqOpPoints.
13910249Sstephan.diestelhorst@arm.com     * An empty list corresponds to default voltage specified for the voltage
14010249Sstephan.diestelhorst@arm.com     * domain its clock domain belongs. The same voltage is applied for each
14110249Sstephan.diestelhorst@arm.com     * freqOpPoints, overall implying NO DVS
14210249Sstephan.diestelhorst@arm.com     */
14310249Sstephan.diestelhorst@arm.com    const Voltages voltageOpPoints;
14410249Sstephan.diestelhorst@arm.com    PerfLevel _perfLevel;
1459827Sakash.bagdia@arm.com
14610022SAndreas.Hansson@ARM.com    /**
14710022SAndreas.Hansson@ARM.com     * Stat for reporting voltage of the domain
14810022SAndreas.Hansson@ARM.com     */
14910022SAndreas.Hansson@ARM.com    Stats::Value currentVoltage;
15010022SAndreas.Hansson@ARM.com
1519827Sakash.bagdia@arm.com    /**
15210249Sstephan.diestelhorst@arm.com     * List of associated SrcClockDomains that are connected to this voltage
15310249Sstephan.diestelhorst@arm.com     * domain.
1549827Sakash.bagdia@arm.com     */
15510249Sstephan.diestelhorst@arm.com    typedef std::vector<SrcClockDomain *> SrcClockChildren;
15610249Sstephan.diestelhorst@arm.com    SrcClockChildren srcClockChildren;
1579827Sakash.bagdia@arm.com};
1589827Sakash.bagdia@arm.com
1599827Sakash.bagdia@arm.com#endif
160