linux/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_powertune.c
<<
>>
Prefs
   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
  41        return 0;
  42}
  43
  44int vega20_validate_power_level_request(struct pp_hwmgr *hwmgr,
  45                uint32_t tdp_percentage_adjustment, uint32_t tdp_absolute_value_adjustment)
  46{
  47        return (tdp_percentage_adjustment > hwmgr->platform_descriptor.TDPLimit) ? -1 : 0;
  48}
  49
  50static int vega20_set_overdrive_target_percentage(struct pp_hwmgr *hwmgr,
  51                uint32_t adjust_percent)
  52{
  53        return smum_send_msg_to_smc_with_parameter(hwmgr,
  54                        PPSMC_MSG_OverDriveSetPercentage, adjust_percent);
  55}
  56
  57int vega20_power_control_set_level(struct pp_hwmgr *hwmgr)
  58{
  59        int adjust_percent, result = 0;
  60
  61        if (PP_CAP(PHM_PlatformCaps_PowerContainment)) {
  62                adjust_percent =
  63                                hwmgr->platform_descriptor.TDPAdjustmentPolarity ?
  64                                hwmgr->platform_descriptor.TDPAdjustment :
  65                                (-1 * hwmgr->platform_descriptor.TDPAdjustment);
  66                result = vega20_set_overdrive_target_percentage(hwmgr,
  67                                (uint32_t)adjust_percent);
  68        }
  69        return result;
  70}
  71