energy_ctrl.hh revision 11168
12124SN/A/* 22124SN/A * Copyright (c) 2012-2014 ARM Limited 35268Sksewell@umich.edu * All rights reserved 45268Sksewell@umich.edu * 55268Sksewell@umich.edu * The license below extends only to copyright in the software and shall 65268Sksewell@umich.edu * not be construed as granting a license to any other intellectual 75268Sksewell@umich.edu * property including but not limited to intellectual property relating 85268Sksewell@umich.edu * to a hardware implementation of the functionality of the software 95268Sksewell@umich.edu * licensed hereunder. You may use the software subject to the license 105268Sksewell@umich.edu * terms below provided that you ensure that this notice is replicated 115268Sksewell@umich.edu * unmodified and in its entirety in all distributions of the software, 125268Sksewell@umich.edu * modified or unmodified, in source code or in binary form. 135268Sksewell@umich.edu * 145268Sksewell@umich.edu * Redistribution and use in source and binary forms, with or without 155268Sksewell@umich.edu * modification, are permitted provided that the following conditions are 165268Sksewell@umich.edu * met: redistributions of source code must retain the above copyright 175268Sksewell@umich.edu * notice, this list of conditions and the following disclaimer; 185268Sksewell@umich.edu * redistributions in binary form must reproduce the above copyright 195268Sksewell@umich.edu * notice, this list of conditions and the following disclaimer in the 205268Sksewell@umich.edu * documentation and/or other materials provided with the distribution; 215268Sksewell@umich.edu * neither the name of the copyright holders nor the names of its 225268Sksewell@umich.edu * contributors may be used to endorse or promote products derived from 235268Sksewell@umich.edu * this software without specific prior written permission. 245268Sksewell@umich.edu * 255268Sksewell@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 265268Sksewell@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 275268Sksewell@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 285268Sksewell@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 295268Sksewell@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 305268Sksewell@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 312022SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 322649Ssaidi@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 332649Ssaidi@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 342706Sksewell@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 352649Ssaidi@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 362649Ssaidi@eecs.umich.edu * 372022SN/A * Authors: Vasileios Spiliopoulos 382124SN/A * Akash Bagdia 392124SN/A * Stephan Diestelhorst 402124SN/A */ 412124SN/A 422124SN/A/** 432124SN/A * @file 442124SN/A * The energy controller is a device being used to manage power and energy 455736Snate@binkert.org * related control operations within the system. It provides the necessary 462239SN/A * software interface to the kernel. The kernel will require gem5 specific 472124SN/A * drivers to access this device. 482124SN/A * 492124SN/A * Tasks handled by the controller are: 502124SN/A * a) Dynamic voltage and frequency scaling control operations 516207Sksewell@umich.edu * 522124SN/A * Note that the registers defined do not resemble any specific controller 532742Sksewell@umich.edu * device in real hardware. They are currently design to accomodate the gem5 542022SN/A * system requirements. 552124SN/A */ 562022SN/A 5712616Sgabeblack@google.com#ifndef __DEV_ARM_ENERGY_CTRL_HH__ 5812616Sgabeblack@google.com#define __DEV_ARM_ENERGY_CTRL_HH__ 592124SN/A 602124SN/A#include "dev/io_device.hh" 612742Sksewell@umich.edu#include "params/EnergyCtrl.hh" 622742Sksewell@umich.edu 632742Sksewell@umich.educlass DVFSHandler; 642742Sksewell@umich.edu 652742Sksewell@umich.educlass EnergyCtrl : public BasicPioDevice 662742Sksewell@umich.edu{ 672742Sksewell@umich.edu public: 682742Sksewell@umich.edu /** 696207Sksewell@umich.edu * Discovery flows: 706207Sksewell@umich.edu * ---------------- 712742Sksewell@umich.edu * * get basic DVFS handler information 722742Sksewell@umich.edu * read(DVFS_HANDLER_STATUS) 732742Sksewell@umich.edu * read(DVFS_HANDLER_TRANS_LATENCY) 7412616Sgabeblack@google.com * 7512616Sgabeblack@google.com * * get the number of domain IDs 762742Sksewell@umich.edu * read(DVFS_NUM_DOMAINS) -> domains 772022SN/A * 782022SN/A * * query the driver to get the IDs for all i in domains 792124SN/A * write(DVFS_DOMAINID_AT_INDEX <- i) 802022SN/A * read(DOMAIN_ID) -> domainID_i 812124SN/A * 822124SN/A * * for each domainID i get voltage / frequency pairs 832124SN/A * write(DOMAIN_ID <- domainID_i) 842742Sksewell@umich.edu * read(NUM_OF_PERF_LEVELS) -> levels_i 852239SN/A * * for each l in levels_i 862124SN/A * write(PERF_LEVEL_TO_READ <- l) 872124SN/A * read(FREQ_AT_PERF_LEVEL) -> freq_l_i 882742Sksewell@umich.edu * read(VOLT_AT_PERF_LEVEL) -> volt_l_i 892742Sksewell@umich.edu * 902742Sksewell@umich.edu * 912742Sksewell@umich.edu * Setting a specific performance level (V/F combination) 922742Sksewell@umich.edu * ------------------------------------------------------ 932742Sksewell@umich.edu * * get performance for domain_ID i 942742Sksewell@umich.edu * write(DOMAIN_ID <- i) 952742Sksewell@umich.edu * read(PERF_LEVEL) -> perf_level_i 964661Sksewell@umich.edu * 974661Sksewell@umich.edu * * set performance for domain_ID i 984661Sksewell@umich.edu * write(DOMAIN_ID <- i) 999554Sandreas.hansson@arm.com * write(PERF_LEVEL <- perf_level_i) 10012234Sgabeblack@google.com * * wait for DVFS transition completion 1019554Sandreas.hansson@arm.com * while (!read(PERF_LEVEL_ACK)); 1029554Sandreas.hansson@arm.com */ 1039554Sandreas.hansson@arm.com 1044661Sksewell@umich.edu enum Registers { 1054661Sksewell@umich.edu DVFS_HANDLER_STATUS = 0, 1064661Sksewell@umich.edu DVFS_NUM_DOMAINS, 1074661Sksewell@umich.edu DVFS_DOMAINID_AT_INDEX, 10812234Sgabeblack@google.com DVFS_HANDLER_TRANS_LATENCY, 1094661Sksewell@umich.edu DOMAIN_ID, 1104661Sksewell@umich.edu PERF_LEVEL, 1115222Sksewell@umich.edu PERF_LEVEL_ACK, 1124661Sksewell@umich.edu NUM_OF_PERF_LEVELS, 1134661Sksewell@umich.edu PERF_LEVEL_TO_READ, 1145222Sksewell@umich.edu FREQ_AT_PERF_LEVEL, 1154661Sksewell@umich.edu VOLT_AT_PERF_LEVEL, 1164661Sksewell@umich.edu PIO_NUM_FIELDS 1175222Sksewell@umich.edu }; 1184661Sksewell@umich.edu 1194661Sksewell@umich.edu typedef EnergyCtrlParams Params; 1205222Sksewell@umich.edu EnergyCtrl(const Params *p); 1214661Sksewell@umich.edu 1224661Sksewell@umich.edu /** 1234661Sksewell@umich.edu * Read command sent to the device 1244661Sksewell@umich.edu * @param pkt Packet describing this request 1254661Sksewell@umich.edu * @return number of ticks it took to complete 1264661Sksewell@umich.edu */ 1274661Sksewell@umich.edu virtual Tick read(PacketPtr pkt); 1284661Sksewell@umich.edu /** 1294661Sksewell@umich.edu * Write command sent to the device 1304661Sksewell@umich.edu * @param pkt Packet describing this request 1314661Sksewell@umich.edu * @return number of ticks it took to complete 1322022SN/A */ 1332022SN/A virtual Tick write(PacketPtr pkt); 1342124SN/A 1352124SN/A void serialize(CheckpointOut &cp) const override; 1362124SN/A void unserialize(CheckpointIn &cp) override; 1372124SN/A 1382124SN/A void startup(); 1392124SN/A void init(); 1402124SN/A 1412124SN/A private: 1422124SN/A DVFSHandler *dvfsHandler; 1434661Sksewell@umich.edu 1442124SN/A /** 14512616Sgabeblack@google.com * Cluster ID (DOMAIN_ID) R/W register, programmed to ID of the domain for 14612616Sgabeblack@google.com * which the set/get performance level command can be issued 14712616Sgabeblack@google.com */ 14812616Sgabeblack@google.com uint32_t domainID; 1492124SN/A 1502022SN/A /** 1512022SN/A * Index for getting the domain ID from the domain ID list available with 1522124SN/A * the DVFS handler 1536207Sksewell@umich.edu */ 15410184SCurtis.Dunham@arm.com uint32_t domainIDIndexToRead; 1556207Sksewell@umich.edu 1562124SN/A /** 1573953Sstever@eecs.umich.edu * Acknowledgment (PERF_LEVEL_ACK) RO register, software polls this 1582124SN/A * register to read back the status of the last programmed change in the 1593953Sstever@eecs.umich.edu * domain ID and/or the performance level. Valid values are: 1602124SN/A * '0' - Ack is not OK yet 1612124SN/A * '1' - Ack is OK 16212234Sgabeblack@google.com * It is a read destructive register with a read of '1' resets the ack to 1632124SN/A * '0'. 1642124SN/A */ 1652124SN/A uint32_t perfLevelAck; 1662132SN/A 1672124SN/A uint32_t perfLevelToRead; 1685222Sksewell@umich.edu 1695222Sksewell@umich.edu static uint32_t ticksTokHz(Tick period) { 1705222Sksewell@umich.edu return (uint32_t)(SimClock::Int::ms / period); 1715222Sksewell@umich.edu } 1725222Sksewell@umich.edu 1735222Sksewell@umich.edu static uint32_t toMicroVolt(double voltage) { 1745222Sksewell@umich.edu return (uint32_t)(voltage * 1000000); 1752124SN/A } 1762124SN/A 1772124SN/A /** 1782124SN/A * Update the acknowledgment that is read back by the software to confirm 1792124SN/A * newly requested performance level has been set. 1808442Sgblack@eecs.umich.edu */ 1812124SN/A void updatePLAck() { 1822124SN/A perfLevelAck = 1; 1832124SN/A } 1842124SN/A 1852124SN/A EventWrapper<EnergyCtrl, &EnergyCtrl::updatePLAck> updateAckEvent; 1862124SN/A}; 1872124SN/A#endif //__DEV_ARM_ENERGY_CTRL_HH__ 1882124SN/A