cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

vega20_powertune.c (2482B)


      1/*
      2 * Copyright 2018 Advanced Micro Devices, Inc.
      3 *
      4 * Permission is hereby granted, free of charge, to any person obtaining a
      5 * copy of this software and associated documentation files (the "Software"),
      6 * to deal in the Software without restriction, including without limitation
      7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      8 * and/or sell copies of the Software, and to permit persons to whom the
      9 * Software is furnished to do so, subject to the following conditions:
     10 *
     11 * The above copyright notice and this permission notice shall be included in
     12 * all copies or substantial portions of the Software.
     13 *
     14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
     18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
     19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
     20 * OTHER DEALINGS IN THE SOFTWARE.
     21 *
     22 */
     23
     24#include "hwmgr.h"
     25#include "vega20_hwmgr.h"
     26#include "vega20_powertune.h"
     27#include "vega20_smumgr.h"
     28#include "vega20_ppsmc.h"
     29#include "vega20_inc.h"
     30#include "pp_debug.h"
     31
     32int vega20_set_power_limit(struct pp_hwmgr *hwmgr, uint32_t n)
     33{
     34	struct vega20_hwmgr *data =
     35			(struct vega20_hwmgr *)(hwmgr->backend);
     36
     37	if (data->smu_features[GNLD_PPT].enabled)
     38		return smum_send_msg_to_smc_with_parameter(hwmgr,
     39				PPSMC_MSG_SetPptLimit, n,
     40				NULL);
     41
     42	return 0;
     43}
     44
     45int vega20_validate_power_level_request(struct pp_hwmgr *hwmgr,
     46		uint32_t tdp_percentage_adjustment, uint32_t tdp_absolute_value_adjustment)
     47{
     48	return (tdp_percentage_adjustment > hwmgr->platform_descriptor.TDPLimit) ? -1 : 0;
     49}
     50
     51static int vega20_set_overdrive_target_percentage(struct pp_hwmgr *hwmgr,
     52		uint32_t adjust_percent)
     53{
     54	return smum_send_msg_to_smc_with_parameter(hwmgr,
     55			PPSMC_MSG_OverDriveSetPercentage, adjust_percent,
     56			NULL);
     57}
     58
     59int vega20_power_control_set_level(struct pp_hwmgr *hwmgr)
     60{
     61	int adjust_percent, result = 0;
     62
     63	if (PP_CAP(PHM_PlatformCaps_PowerContainment)) {
     64		adjust_percent =
     65				hwmgr->platform_descriptor.TDPAdjustmentPolarity ?
     66				hwmgr->platform_descriptor.TDPAdjustment :
     67				(-1 * hwmgr->platform_descriptor.TDPAdjustment);
     68		result = vega20_set_overdrive_target_percentage(hwmgr,
     69				(uint32_t)adjust_percent);
     70	}
     71	return result;
     72}