Home | History | Annotate | Line # | Download | only in radeon
      1  1.1  riastrad /*	$NetBSD: radeon_kv_dpm.c,v 1.2 2021/12/18 23:45:43 riastradh Exp $	*/
      2  1.1  riastrad 
      3  1.1  riastrad /*
      4  1.1  riastrad  * Copyright 2013 Advanced Micro Devices, Inc.
      5  1.1  riastrad  *
      6  1.1  riastrad  * Permission is hereby granted, free of charge, to any person obtaining a
      7  1.1  riastrad  * copy of this software and associated documentation files (the "Software"),
      8  1.1  riastrad  * to deal in the Software without restriction, including without limitation
      9  1.1  riastrad  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     10  1.1  riastrad  * and/or sell copies of the Software, and to permit persons to whom the
     11  1.1  riastrad  * Software is furnished to do so, subject to the following conditions:
     12  1.1  riastrad  *
     13  1.1  riastrad  * The above copyright notice and this permission notice shall be included in
     14  1.1  riastrad  * all copies or substantial portions of the Software.
     15  1.1  riastrad  *
     16  1.1  riastrad  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     17  1.1  riastrad  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     18  1.1  riastrad  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     19  1.1  riastrad  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
     20  1.1  riastrad  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
     21  1.1  riastrad  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
     22  1.1  riastrad  * OTHER DEALINGS IN THE SOFTWARE.
     23  1.1  riastrad  *
     24  1.1  riastrad  */
     25  1.1  riastrad 
     26  1.1  riastrad #include <sys/cdefs.h>
     27  1.1  riastrad __KERNEL_RCSID(0, "$NetBSD: radeon_kv_dpm.c,v 1.2 2021/12/18 23:45:43 riastradh Exp $");
     28  1.1  riastrad 
     29  1.2  riastrad #include <linux/pci.h>
     30  1.2  riastrad #include <linux/seq_file.h>
     31  1.2  riastrad 
     32  1.1  riastrad #include "cikd.h"
     33  1.2  riastrad #include "kv_dpm.h"
     34  1.1  riastrad #include "r600_dpm.h"
     35  1.2  riastrad #include "radeon.h"
     36  1.1  riastrad #include "radeon_asic.h"
     37  1.1  riastrad 
     38  1.1  riastrad #define KV_MAX_DEEPSLEEP_DIVIDER_ID     5
     39  1.1  riastrad #define KV_MINIMUM_ENGINE_CLOCK         800
     40  1.1  riastrad #define SMC_RAM_END                     0x40000
     41  1.1  riastrad 
     42  1.1  riastrad static int kv_enable_nb_dpm(struct radeon_device *rdev,
     43  1.1  riastrad 			    bool enable);
     44  1.1  riastrad static void kv_init_graphics_levels(struct radeon_device *rdev);
     45  1.1  riastrad static int kv_calculate_ds_divider(struct radeon_device *rdev);
     46  1.1  riastrad static int kv_calculate_nbps_level_settings(struct radeon_device *rdev);
     47  1.1  riastrad static int kv_calculate_dpm_settings(struct radeon_device *rdev);
     48  1.1  riastrad static void kv_enable_new_levels(struct radeon_device *rdev);
     49  1.1  riastrad static void kv_program_nbps_index_settings(struct radeon_device *rdev,
     50  1.1  riastrad 					   struct radeon_ps *new_rps);
     51  1.1  riastrad static int kv_set_enabled_level(struct radeon_device *rdev, u32 level);
     52  1.1  riastrad static int kv_set_enabled_levels(struct radeon_device *rdev);
     53  1.1  riastrad static int kv_force_dpm_highest(struct radeon_device *rdev);
     54  1.1  riastrad static int kv_force_dpm_lowest(struct radeon_device *rdev);
     55  1.1  riastrad static void kv_apply_state_adjust_rules(struct radeon_device *rdev,
     56  1.1  riastrad 					struct radeon_ps *new_rps,
     57  1.1  riastrad 					struct radeon_ps *old_rps);
     58  1.1  riastrad static int kv_set_thermal_temperature_range(struct radeon_device *rdev,
     59  1.1  riastrad 					    int min_temp, int max_temp);
     60  1.1  riastrad static int kv_init_fps_limits(struct radeon_device *rdev);
     61  1.1  riastrad 
     62  1.1  riastrad void kv_dpm_powergate_uvd(struct radeon_device *rdev, bool gate);
     63  1.1  riastrad static void kv_dpm_powergate_vce(struct radeon_device *rdev, bool gate);
     64  1.1  riastrad static void kv_dpm_powergate_samu(struct radeon_device *rdev, bool gate);
     65  1.1  riastrad static void kv_dpm_powergate_acp(struct radeon_device *rdev, bool gate);
     66  1.1  riastrad 
     67  1.1  riastrad extern void cik_enter_rlc_safe_mode(struct radeon_device *rdev);
     68  1.1  riastrad extern void cik_exit_rlc_safe_mode(struct radeon_device *rdev);
     69  1.1  riastrad extern void cik_update_cg(struct radeon_device *rdev,
     70  1.1  riastrad 			  u32 block, bool enable);
     71  1.1  riastrad 
     72  1.1  riastrad static const struct kv_lcac_config_values sx_local_cac_cfg_kv[] =
     73  1.1  riastrad {
     74  1.1  riastrad 	{  0,       4,        1    },
     75  1.1  riastrad 	{  1,       4,        1    },
     76  1.1  riastrad 	{  2,       5,        1    },
     77  1.1  riastrad 	{  3,       4,        2    },
     78  1.1  riastrad 	{  4,       1,        1    },
     79  1.1  riastrad 	{  5,       5,        2    },
     80  1.1  riastrad 	{  6,       6,        1    },
     81  1.1  riastrad 	{  7,       9,        2    },
     82  1.1  riastrad 	{ 0xffffffff }
     83  1.1  riastrad };
     84  1.1  riastrad 
     85  1.1  riastrad static const struct kv_lcac_config_values mc0_local_cac_cfg_kv[] =
     86  1.1  riastrad {
     87  1.1  riastrad 	{  0,       4,        1    },
     88  1.1  riastrad 	{ 0xffffffff }
     89  1.1  riastrad };
     90  1.1  riastrad 
     91  1.1  riastrad static const struct kv_lcac_config_values mc1_local_cac_cfg_kv[] =
     92  1.1  riastrad {
     93  1.1  riastrad 	{  0,       4,        1    },
     94  1.1  riastrad 	{ 0xffffffff }
     95  1.1  riastrad };
     96  1.1  riastrad 
     97  1.1  riastrad static const struct kv_lcac_config_values mc2_local_cac_cfg_kv[] =
     98  1.1  riastrad {
     99  1.1  riastrad 	{  0,       4,        1    },
    100  1.1  riastrad 	{ 0xffffffff }
    101  1.1  riastrad };
    102  1.1  riastrad 
    103  1.1  riastrad static const struct kv_lcac_config_values mc3_local_cac_cfg_kv[] =
    104  1.1  riastrad {
    105  1.1  riastrad 	{  0,       4,        1    },
    106  1.1  riastrad 	{ 0xffffffff }
    107  1.1  riastrad };
    108  1.1  riastrad 
    109  1.1  riastrad static const struct kv_lcac_config_values cpl_local_cac_cfg_kv[] =
    110  1.1  riastrad {
    111  1.1  riastrad 	{  0,       4,        1    },
    112  1.1  riastrad 	{  1,       4,        1    },
    113  1.1  riastrad 	{  2,       5,        1    },
    114  1.1  riastrad 	{  3,       4,        1    },
    115  1.1  riastrad 	{  4,       1,        1    },
    116  1.1  riastrad 	{  5,       5,        1    },
    117  1.1  riastrad 	{  6,       6,        1    },
    118  1.1  riastrad 	{  7,       9,        1    },
    119  1.1  riastrad 	{  8,       4,        1    },
    120  1.1  riastrad 	{  9,       2,        1    },
    121  1.1  riastrad 	{  10,      3,        1    },
    122  1.1  riastrad 	{  11,      6,        1    },
    123  1.1  riastrad 	{  12,      8,        2    },
    124  1.1  riastrad 	{  13,      1,        1    },
    125  1.1  riastrad 	{  14,      2,        1    },
    126  1.1  riastrad 	{  15,      3,        1    },
    127  1.1  riastrad 	{  16,      1,        1    },
    128  1.1  riastrad 	{  17,      4,        1    },
    129  1.1  riastrad 	{  18,      3,        1    },
    130  1.1  riastrad 	{  19,      1,        1    },
    131  1.1  riastrad 	{  20,      8,        1    },
    132  1.1  riastrad 	{  21,      5,        1    },
    133  1.1  riastrad 	{  22,      1,        1    },
    134  1.1  riastrad 	{  23,      1,        1    },
    135  1.1  riastrad 	{  24,      4,        1    },
    136  1.1  riastrad 	{  27,      6,        1    },
    137  1.1  riastrad 	{  28,      1,        1    },
    138  1.1  riastrad 	{ 0xffffffff }
    139  1.1  riastrad };
    140  1.1  riastrad 
    141  1.1  riastrad static const struct kv_lcac_config_reg sx0_cac_config_reg[] =
    142  1.1  riastrad {
    143  1.1  riastrad 	{ 0xc0400d00, 0x003e0000, 17, 0x3fc00000, 22, 0x0001fffe, 1, 0x00000001, 0 }
    144  1.1  riastrad };
    145  1.1  riastrad 
    146  1.1  riastrad static const struct kv_lcac_config_reg mc0_cac_config_reg[] =
    147  1.1  riastrad {
    148  1.1  riastrad 	{ 0xc0400d30, 0x003e0000, 17, 0x3fc00000, 22, 0x0001fffe, 1, 0x00000001, 0 }
    149  1.1  riastrad };
    150  1.1  riastrad 
    151  1.1  riastrad static const struct kv_lcac_config_reg mc1_cac_config_reg[] =
    152  1.1  riastrad {
    153  1.1  riastrad 	{ 0xc0400d3c, 0x003e0000, 17, 0x3fc00000, 22, 0x0001fffe, 1, 0x00000001, 0 }
    154  1.1  riastrad };
    155  1.1  riastrad 
    156  1.1  riastrad static const struct kv_lcac_config_reg mc2_cac_config_reg[] =
    157  1.1  riastrad {
    158  1.1  riastrad 	{ 0xc0400d48, 0x003e0000, 17, 0x3fc00000, 22, 0x0001fffe, 1, 0x00000001, 0 }
    159  1.1  riastrad };
    160  1.1  riastrad 
    161  1.1  riastrad static const struct kv_lcac_config_reg mc3_cac_config_reg[] =
    162  1.1  riastrad {
    163  1.1  riastrad 	{ 0xc0400d54, 0x003e0000, 17, 0x3fc00000, 22, 0x0001fffe, 1, 0x00000001, 0 }
    164  1.1  riastrad };
    165  1.1  riastrad 
    166  1.1  riastrad static const struct kv_lcac_config_reg cpl_cac_config_reg[] =
    167  1.1  riastrad {
    168  1.1  riastrad 	{ 0xc0400d80, 0x003e0000, 17, 0x3fc00000, 22, 0x0001fffe, 1, 0x00000001, 0 }
    169  1.1  riastrad };
    170  1.1  riastrad 
    171  1.1  riastrad static const struct kv_pt_config_reg didt_config_kv[] =
    172  1.1  riastrad {
    173  1.1  riastrad 	{ 0x10, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND },
    174  1.1  riastrad 	{ 0x10, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND },
    175  1.1  riastrad 	{ 0x10, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND },
    176  1.1  riastrad 	{ 0x10, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND },
    177  1.1  riastrad 	{ 0x11, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND },
    178  1.1  riastrad 	{ 0x11, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND },
    179  1.1  riastrad 	{ 0x11, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND },
    180  1.1  riastrad 	{ 0x11, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND },
    181  1.1  riastrad 	{ 0x12, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND },
    182  1.1  riastrad 	{ 0x12, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND },
    183  1.1  riastrad 	{ 0x12, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND },
    184  1.1  riastrad 	{ 0x12, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND },
    185  1.1  riastrad 	{ 0x2, 0x00003fff, 0, 0x4, KV_CONFIGREG_DIDT_IND },
    186  1.1  riastrad 	{ 0x2, 0x03ff0000, 16, 0x80, KV_CONFIGREG_DIDT_IND },
    187  1.1  riastrad 	{ 0x2, 0x78000000, 27, 0x3, KV_CONFIGREG_DIDT_IND },
    188  1.1  riastrad 	{ 0x1, 0x0000ffff, 0, 0x3FFF, KV_CONFIGREG_DIDT_IND },
    189  1.1  riastrad 	{ 0x1, 0xffff0000, 16, 0x3FFF, KV_CONFIGREG_DIDT_IND },
    190  1.1  riastrad 	{ 0x0, 0x00000001, 0, 0x0, KV_CONFIGREG_DIDT_IND },
    191  1.1  riastrad 	{ 0x30, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND },
    192  1.1  riastrad 	{ 0x30, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND },
    193  1.1  riastrad 	{ 0x30, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND },
    194  1.1  riastrad 	{ 0x30, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND },
    195  1.1  riastrad 	{ 0x31, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND },
    196  1.1  riastrad 	{ 0x31, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND },
    197  1.1  riastrad 	{ 0x31, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND },
    198  1.1  riastrad 	{ 0x31, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND },
    199  1.1  riastrad 	{ 0x32, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND },
    200  1.1  riastrad 	{ 0x32, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND },
    201  1.1  riastrad 	{ 0x32, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND },
    202  1.1  riastrad 	{ 0x32, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND },
    203  1.1  riastrad 	{ 0x22, 0x00003fff, 0, 0x4, KV_CONFIGREG_DIDT_IND },
    204  1.1  riastrad 	{ 0x22, 0x03ff0000, 16, 0x80, KV_CONFIGREG_DIDT_IND },
    205  1.1  riastrad 	{ 0x22, 0x78000000, 27, 0x3, KV_CONFIGREG_DIDT_IND },
    206  1.1  riastrad 	{ 0x21, 0x0000ffff, 0, 0x3FFF, KV_CONFIGREG_DIDT_IND },
    207  1.1  riastrad 	{ 0x21, 0xffff0000, 16, 0x3FFF, KV_CONFIGREG_DIDT_IND },
    208  1.1  riastrad 	{ 0x20, 0x00000001, 0, 0x0, KV_CONFIGREG_DIDT_IND },
    209  1.1  riastrad 	{ 0x50, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND },
    210  1.1  riastrad 	{ 0x50, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND },
    211  1.1  riastrad 	{ 0x50, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND },
    212  1.1  riastrad 	{ 0x50, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND },
    213  1.1  riastrad 	{ 0x51, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND },
    214  1.1  riastrad 	{ 0x51, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND },
    215  1.1  riastrad 	{ 0x51, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND },
    216  1.1  riastrad 	{ 0x51, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND },
    217  1.1  riastrad 	{ 0x52, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND },
    218  1.1  riastrad 	{ 0x52, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND },
    219  1.1  riastrad 	{ 0x52, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND },
    220  1.1  riastrad 	{ 0x52, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND },
    221  1.1  riastrad 	{ 0x42, 0x00003fff, 0, 0x4, KV_CONFIGREG_DIDT_IND },
    222  1.1  riastrad 	{ 0x42, 0x03ff0000, 16, 0x80, KV_CONFIGREG_DIDT_IND },
    223  1.1  riastrad 	{ 0x42, 0x78000000, 27, 0x3, KV_CONFIGREG_DIDT_IND },
    224  1.1  riastrad 	{ 0x41, 0x0000ffff, 0, 0x3FFF, KV_CONFIGREG_DIDT_IND },
    225  1.1  riastrad 	{ 0x41, 0xffff0000, 16, 0x3FFF, KV_CONFIGREG_DIDT_IND },
    226  1.1  riastrad 	{ 0x40, 0x00000001, 0, 0x0, KV_CONFIGREG_DIDT_IND },
    227  1.1  riastrad 	{ 0x70, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND },
    228  1.1  riastrad 	{ 0x70, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND },
    229  1.1  riastrad 	{ 0x70, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND },
    230  1.1  riastrad 	{ 0x70, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND },
    231  1.1  riastrad 	{ 0x71, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND },
    232  1.1  riastrad 	{ 0x71, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND },
    233  1.1  riastrad 	{ 0x71, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND },
    234  1.1  riastrad 	{ 0x71, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND },
    235  1.1  riastrad 	{ 0x72, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND },
    236  1.1  riastrad 	{ 0x72, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND },
    237  1.1  riastrad 	{ 0x72, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND },
    238  1.1  riastrad 	{ 0x72, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND },
    239  1.1  riastrad 	{ 0x62, 0x00003fff, 0, 0x4, KV_CONFIGREG_DIDT_IND },
    240  1.1  riastrad 	{ 0x62, 0x03ff0000, 16, 0x80, KV_CONFIGREG_DIDT_IND },
    241  1.1  riastrad 	{ 0x62, 0x78000000, 27, 0x3, KV_CONFIGREG_DIDT_IND },
    242  1.1  riastrad 	{ 0x61, 0x0000ffff, 0, 0x3FFF, KV_CONFIGREG_DIDT_IND },
    243  1.1  riastrad 	{ 0x61, 0xffff0000, 16, 0x3FFF, KV_CONFIGREG_DIDT_IND },
    244  1.1  riastrad 	{ 0x60, 0x00000001, 0, 0x0, KV_CONFIGREG_DIDT_IND },
    245  1.1  riastrad 	{ 0xFFFFFFFF }
    246  1.1  riastrad };
    247  1.1  riastrad 
    248  1.1  riastrad static struct kv_ps *kv_get_ps(struct radeon_ps *rps)
    249  1.1  riastrad {
    250  1.1  riastrad 	struct kv_ps *ps = rps->ps_priv;
    251  1.1  riastrad 
    252  1.1  riastrad 	return ps;
    253  1.1  riastrad }
    254  1.1  riastrad 
    255  1.1  riastrad static struct kv_power_info *kv_get_pi(struct radeon_device *rdev)
    256  1.1  riastrad {
    257  1.1  riastrad 	struct kv_power_info *pi = rdev->pm.dpm.priv;
    258  1.1  riastrad 
    259  1.1  riastrad 	return pi;
    260  1.1  riastrad }
    261  1.1  riastrad 
    262  1.1  riastrad #if 0
    263  1.1  riastrad static void kv_program_local_cac_table(struct radeon_device *rdev,
    264  1.1  riastrad 				       const struct kv_lcac_config_values *local_cac_table,
    265  1.1  riastrad 				       const struct kv_lcac_config_reg *local_cac_reg)
    266  1.1  riastrad {
    267  1.1  riastrad 	u32 i, count, data;
    268  1.1  riastrad 	const struct kv_lcac_config_values *values = local_cac_table;
    269  1.1  riastrad 
    270  1.1  riastrad 	while (values->block_id != 0xffffffff) {
    271  1.1  riastrad 		count = values->signal_id;
    272  1.1  riastrad 		for (i = 0; i < count; i++) {
    273  1.1  riastrad 			data = ((values->block_id << local_cac_reg->block_shift) &
    274  1.1  riastrad 				local_cac_reg->block_mask);
    275  1.1  riastrad 			data |= ((i << local_cac_reg->signal_shift) &
    276  1.1  riastrad 				 local_cac_reg->signal_mask);
    277  1.1  riastrad 			data |= ((values->t << local_cac_reg->t_shift) &
    278  1.1  riastrad 				 local_cac_reg->t_mask);
    279  1.1  riastrad 			data |= ((1 << local_cac_reg->enable_shift) &
    280  1.1  riastrad 				 local_cac_reg->enable_mask);
    281  1.1  riastrad 			WREG32_SMC(local_cac_reg->cntl, data);
    282  1.1  riastrad 		}
    283  1.1  riastrad 		values++;
    284  1.1  riastrad 	}
    285  1.1  riastrad }
    286  1.1  riastrad #endif
    287  1.1  riastrad 
    288  1.1  riastrad static int kv_program_pt_config_registers(struct radeon_device *rdev,
    289  1.1  riastrad 					  const struct kv_pt_config_reg *cac_config_regs)
    290  1.1  riastrad {
    291  1.1  riastrad 	const struct kv_pt_config_reg *config_regs = cac_config_regs;
    292  1.1  riastrad 	u32 data;
    293  1.1  riastrad 	u32 cache = 0;
    294  1.1  riastrad 
    295  1.1  riastrad 	if (config_regs == NULL)
    296  1.1  riastrad 		return -EINVAL;
    297  1.1  riastrad 
    298  1.1  riastrad 	while (config_regs->offset != 0xFFFFFFFF) {
    299  1.1  riastrad 		if (config_regs->type == KV_CONFIGREG_CACHE) {
    300  1.1  riastrad 			cache |= ((config_regs->value << config_regs->shift) & config_regs->mask);
    301  1.1  riastrad 		} else {
    302  1.1  riastrad 			switch (config_regs->type) {
    303  1.1  riastrad 			case KV_CONFIGREG_SMC_IND:
    304  1.1  riastrad 				data = RREG32_SMC(config_regs->offset);
    305  1.1  riastrad 				break;
    306  1.1  riastrad 			case KV_CONFIGREG_DIDT_IND:
    307  1.1  riastrad 				data = RREG32_DIDT(config_regs->offset);
    308  1.1  riastrad 				break;
    309  1.1  riastrad 			default:
    310  1.1  riastrad 				data = RREG32(config_regs->offset << 2);
    311  1.1  riastrad 				break;
    312  1.1  riastrad 			}
    313  1.1  riastrad 
    314  1.1  riastrad 			data &= ~config_regs->mask;
    315  1.1  riastrad 			data |= ((config_regs->value << config_regs->shift) & config_regs->mask);
    316  1.1  riastrad 			data |= cache;
    317  1.1  riastrad 			cache = 0;
    318  1.1  riastrad 
    319  1.1  riastrad 			switch (config_regs->type) {
    320  1.1  riastrad 			case KV_CONFIGREG_SMC_IND:
    321  1.1  riastrad 				WREG32_SMC(config_regs->offset, data);
    322  1.1  riastrad 				break;
    323  1.1  riastrad 			case KV_CONFIGREG_DIDT_IND:
    324  1.1  riastrad 				WREG32_DIDT(config_regs->offset, data);
    325  1.1  riastrad 				break;
    326  1.1  riastrad 			default:
    327  1.1  riastrad 				WREG32(config_regs->offset << 2, data);
    328  1.1  riastrad 				break;
    329  1.1  riastrad 			}
    330  1.1  riastrad 		}
    331  1.1  riastrad 		config_regs++;
    332  1.1  riastrad 	}
    333  1.1  riastrad 
    334  1.1  riastrad 	return 0;
    335  1.1  riastrad }
    336  1.1  riastrad 
    337  1.1  riastrad static void kv_do_enable_didt(struct radeon_device *rdev, bool enable)
    338  1.1  riastrad {
    339  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
    340  1.1  riastrad 	u32 data;
    341  1.1  riastrad 
    342  1.1  riastrad 	if (pi->caps_sq_ramping) {
    343  1.1  riastrad 		data = RREG32_DIDT(DIDT_SQ_CTRL0);
    344  1.1  riastrad 		if (enable)
    345  1.1  riastrad 			data |= DIDT_CTRL_EN;
    346  1.1  riastrad 		else
    347  1.1  riastrad 			data &= ~DIDT_CTRL_EN;
    348  1.1  riastrad 		WREG32_DIDT(DIDT_SQ_CTRL0, data);
    349  1.1  riastrad 	}
    350  1.1  riastrad 
    351  1.1  riastrad 	if (pi->caps_db_ramping) {
    352  1.1  riastrad 		data = RREG32_DIDT(DIDT_DB_CTRL0);
    353  1.1  riastrad 		if (enable)
    354  1.1  riastrad 			data |= DIDT_CTRL_EN;
    355  1.1  riastrad 		else
    356  1.1  riastrad 			data &= ~DIDT_CTRL_EN;
    357  1.1  riastrad 		WREG32_DIDT(DIDT_DB_CTRL0, data);
    358  1.1  riastrad 	}
    359  1.1  riastrad 
    360  1.1  riastrad 	if (pi->caps_td_ramping) {
    361  1.1  riastrad 		data = RREG32_DIDT(DIDT_TD_CTRL0);
    362  1.1  riastrad 		if (enable)
    363  1.1  riastrad 			data |= DIDT_CTRL_EN;
    364  1.1  riastrad 		else
    365  1.1  riastrad 			data &= ~DIDT_CTRL_EN;
    366  1.1  riastrad 		WREG32_DIDT(DIDT_TD_CTRL0, data);
    367  1.1  riastrad 	}
    368  1.1  riastrad 
    369  1.1  riastrad 	if (pi->caps_tcp_ramping) {
    370  1.1  riastrad 		data = RREG32_DIDT(DIDT_TCP_CTRL0);
    371  1.1  riastrad 		if (enable)
    372  1.1  riastrad 			data |= DIDT_CTRL_EN;
    373  1.1  riastrad 		else
    374  1.1  riastrad 			data &= ~DIDT_CTRL_EN;
    375  1.1  riastrad 		WREG32_DIDT(DIDT_TCP_CTRL0, data);
    376  1.1  riastrad 	}
    377  1.1  riastrad }
    378  1.1  riastrad 
    379  1.1  riastrad static int kv_enable_didt(struct radeon_device *rdev, bool enable)
    380  1.1  riastrad {
    381  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
    382  1.1  riastrad 	int ret;
    383  1.1  riastrad 
    384  1.1  riastrad 	if (pi->caps_sq_ramping ||
    385  1.1  riastrad 	    pi->caps_db_ramping ||
    386  1.1  riastrad 	    pi->caps_td_ramping ||
    387  1.1  riastrad 	    pi->caps_tcp_ramping) {
    388  1.1  riastrad 		cik_enter_rlc_safe_mode(rdev);
    389  1.1  riastrad 
    390  1.1  riastrad 		if (enable) {
    391  1.1  riastrad 			ret = kv_program_pt_config_registers(rdev, didt_config_kv);
    392  1.1  riastrad 			if (ret) {
    393  1.1  riastrad 				cik_exit_rlc_safe_mode(rdev);
    394  1.1  riastrad 				return ret;
    395  1.1  riastrad 			}
    396  1.1  riastrad 		}
    397  1.1  riastrad 
    398  1.1  riastrad 		kv_do_enable_didt(rdev, enable);
    399  1.1  riastrad 
    400  1.1  riastrad 		cik_exit_rlc_safe_mode(rdev);
    401  1.1  riastrad 	}
    402  1.1  riastrad 
    403  1.1  riastrad 	return 0;
    404  1.1  riastrad }
    405  1.1  riastrad 
    406  1.1  riastrad #if 0
    407  1.1  riastrad static void kv_initialize_hardware_cac_manager(struct radeon_device *rdev)
    408  1.1  riastrad {
    409  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
    410  1.1  riastrad 
    411  1.1  riastrad 	if (pi->caps_cac) {
    412  1.1  riastrad 		WREG32_SMC(LCAC_SX0_OVR_SEL, 0);
    413  1.1  riastrad 		WREG32_SMC(LCAC_SX0_OVR_VAL, 0);
    414  1.1  riastrad 		kv_program_local_cac_table(rdev, sx_local_cac_cfg_kv, sx0_cac_config_reg);
    415  1.1  riastrad 
    416  1.1  riastrad 		WREG32_SMC(LCAC_MC0_OVR_SEL, 0);
    417  1.1  riastrad 		WREG32_SMC(LCAC_MC0_OVR_VAL, 0);
    418  1.1  riastrad 		kv_program_local_cac_table(rdev, mc0_local_cac_cfg_kv, mc0_cac_config_reg);
    419  1.1  riastrad 
    420  1.1  riastrad 		WREG32_SMC(LCAC_MC1_OVR_SEL, 0);
    421  1.1  riastrad 		WREG32_SMC(LCAC_MC1_OVR_VAL, 0);
    422  1.1  riastrad 		kv_program_local_cac_table(rdev, mc1_local_cac_cfg_kv, mc1_cac_config_reg);
    423  1.1  riastrad 
    424  1.1  riastrad 		WREG32_SMC(LCAC_MC2_OVR_SEL, 0);
    425  1.1  riastrad 		WREG32_SMC(LCAC_MC2_OVR_VAL, 0);
    426  1.1  riastrad 		kv_program_local_cac_table(rdev, mc2_local_cac_cfg_kv, mc2_cac_config_reg);
    427  1.1  riastrad 
    428  1.1  riastrad 		WREG32_SMC(LCAC_MC3_OVR_SEL, 0);
    429  1.1  riastrad 		WREG32_SMC(LCAC_MC3_OVR_VAL, 0);
    430  1.1  riastrad 		kv_program_local_cac_table(rdev, mc3_local_cac_cfg_kv, mc3_cac_config_reg);
    431  1.1  riastrad 
    432  1.1  riastrad 		WREG32_SMC(LCAC_CPL_OVR_SEL, 0);
    433  1.1  riastrad 		WREG32_SMC(LCAC_CPL_OVR_VAL, 0);
    434  1.1  riastrad 		kv_program_local_cac_table(rdev, cpl_local_cac_cfg_kv, cpl_cac_config_reg);
    435  1.1  riastrad 	}
    436  1.1  riastrad }
    437  1.1  riastrad #endif
    438  1.1  riastrad 
    439  1.1  riastrad static int kv_enable_smc_cac(struct radeon_device *rdev, bool enable)
    440  1.1  riastrad {
    441  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
    442  1.1  riastrad 	int ret = 0;
    443  1.1  riastrad 
    444  1.1  riastrad 	if (pi->caps_cac) {
    445  1.1  riastrad 		if (enable) {
    446  1.1  riastrad 			ret = kv_notify_message_to_smu(rdev, PPSMC_MSG_EnableCac);
    447  1.1  riastrad 			if (ret)
    448  1.1  riastrad 				pi->cac_enabled = false;
    449  1.1  riastrad 			else
    450  1.1  riastrad 				pi->cac_enabled = true;
    451  1.1  riastrad 		} else if (pi->cac_enabled) {
    452  1.1  riastrad 			kv_notify_message_to_smu(rdev, PPSMC_MSG_DisableCac);
    453  1.1  riastrad 			pi->cac_enabled = false;
    454  1.1  riastrad 		}
    455  1.1  riastrad 	}
    456  1.1  riastrad 
    457  1.1  riastrad 	return ret;
    458  1.1  riastrad }
    459  1.1  riastrad 
    460  1.1  riastrad static int kv_process_firmware_header(struct radeon_device *rdev)
    461  1.1  riastrad {
    462  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
    463  1.1  riastrad 	u32 tmp;
    464  1.1  riastrad 	int ret;
    465  1.1  riastrad 
    466  1.1  riastrad 	ret = kv_read_smc_sram_dword(rdev, SMU7_FIRMWARE_HEADER_LOCATION +
    467  1.1  riastrad 				     offsetof(SMU7_Firmware_Header, DpmTable),
    468  1.1  riastrad 				     &tmp, pi->sram_end);
    469  1.1  riastrad 
    470  1.1  riastrad 	if (ret == 0)
    471  1.1  riastrad 		pi->dpm_table_start = tmp;
    472  1.1  riastrad 
    473  1.1  riastrad 	ret = kv_read_smc_sram_dword(rdev, SMU7_FIRMWARE_HEADER_LOCATION +
    474  1.1  riastrad 				     offsetof(SMU7_Firmware_Header, SoftRegisters),
    475  1.1  riastrad 				     &tmp, pi->sram_end);
    476  1.1  riastrad 
    477  1.1  riastrad 	if (ret == 0)
    478  1.1  riastrad 		pi->soft_regs_start = tmp;
    479  1.1  riastrad 
    480  1.1  riastrad 	return ret;
    481  1.1  riastrad }
    482  1.1  riastrad 
    483  1.1  riastrad static int kv_enable_dpm_voltage_scaling(struct radeon_device *rdev)
    484  1.1  riastrad {
    485  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
    486  1.1  riastrad 	int ret;
    487  1.1  riastrad 
    488  1.1  riastrad 	pi->graphics_voltage_change_enable = 1;
    489  1.1  riastrad 
    490  1.1  riastrad 	ret = kv_copy_bytes_to_smc(rdev,
    491  1.1  riastrad 				   pi->dpm_table_start +
    492  1.1  riastrad 				   offsetof(SMU7_Fusion_DpmTable, GraphicsVoltageChangeEnable),
    493  1.1  riastrad 				   &pi->graphics_voltage_change_enable,
    494  1.1  riastrad 				   sizeof(u8), pi->sram_end);
    495  1.1  riastrad 
    496  1.1  riastrad 	return ret;
    497  1.1  riastrad }
    498  1.1  riastrad 
    499  1.1  riastrad static int kv_set_dpm_interval(struct radeon_device *rdev)
    500  1.1  riastrad {
    501  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
    502  1.1  riastrad 	int ret;
    503  1.1  riastrad 
    504  1.1  riastrad 	pi->graphics_interval = 1;
    505  1.1  riastrad 
    506  1.1  riastrad 	ret = kv_copy_bytes_to_smc(rdev,
    507  1.1  riastrad 				   pi->dpm_table_start +
    508  1.1  riastrad 				   offsetof(SMU7_Fusion_DpmTable, GraphicsInterval),
    509  1.1  riastrad 				   &pi->graphics_interval,
    510  1.1  riastrad 				   sizeof(u8), pi->sram_end);
    511  1.1  riastrad 
    512  1.1  riastrad 	return ret;
    513  1.1  riastrad }
    514  1.1  riastrad 
    515  1.1  riastrad static int kv_set_dpm_boot_state(struct radeon_device *rdev)
    516  1.1  riastrad {
    517  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
    518  1.1  riastrad 	int ret;
    519  1.1  riastrad 
    520  1.1  riastrad 	ret = kv_copy_bytes_to_smc(rdev,
    521  1.1  riastrad 				   pi->dpm_table_start +
    522  1.1  riastrad 				   offsetof(SMU7_Fusion_DpmTable, GraphicsBootLevel),
    523  1.1  riastrad 				   &pi->graphics_boot_level,
    524  1.1  riastrad 				   sizeof(u8), pi->sram_end);
    525  1.1  riastrad 
    526  1.1  riastrad 	return ret;
    527  1.1  riastrad }
    528  1.1  riastrad 
    529  1.1  riastrad static void kv_program_vc(struct radeon_device *rdev)
    530  1.1  riastrad {
    531  1.1  riastrad 	WREG32_SMC(CG_FTV_0, 0x3FFFC100);
    532  1.1  riastrad }
    533  1.1  riastrad 
    534  1.1  riastrad static void kv_clear_vc(struct radeon_device *rdev)
    535  1.1  riastrad {
    536  1.1  riastrad 	WREG32_SMC(CG_FTV_0, 0);
    537  1.1  riastrad }
    538  1.1  riastrad 
    539  1.1  riastrad static int kv_set_divider_value(struct radeon_device *rdev,
    540  1.1  riastrad 				u32 index, u32 sclk)
    541  1.1  riastrad {
    542  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
    543  1.1  riastrad 	struct atom_clock_dividers dividers;
    544  1.1  riastrad 	int ret;
    545  1.1  riastrad 
    546  1.1  riastrad 	ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
    547  1.1  riastrad 					     sclk, false, &dividers);
    548  1.1  riastrad 	if (ret)
    549  1.1  riastrad 		return ret;
    550  1.1  riastrad 
    551  1.1  riastrad 	pi->graphics_level[index].SclkDid = (u8)dividers.post_div;
    552  1.1  riastrad 	pi->graphics_level[index].SclkFrequency = cpu_to_be32(sclk);
    553  1.1  riastrad 
    554  1.1  riastrad 	return 0;
    555  1.1  riastrad }
    556  1.1  riastrad 
    557  1.1  riastrad static u32 kv_convert_vid2_to_vid7(struct radeon_device *rdev,
    558  1.1  riastrad 				   struct sumo_vid_mapping_table *vid_mapping_table,
    559  1.1  riastrad 				   u32 vid_2bit)
    560  1.1  riastrad {
    561  1.1  riastrad 	struct radeon_clock_voltage_dependency_table *vddc_sclk_table =
    562  1.1  riastrad 		&rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk;
    563  1.1  riastrad 	u32 i;
    564  1.1  riastrad 
    565  1.1  riastrad 	if (vddc_sclk_table && vddc_sclk_table->count) {
    566  1.1  riastrad 		if (vid_2bit < vddc_sclk_table->count)
    567  1.1  riastrad 			return vddc_sclk_table->entries[vid_2bit].v;
    568  1.1  riastrad 		else
    569  1.1  riastrad 			return vddc_sclk_table->entries[vddc_sclk_table->count - 1].v;
    570  1.1  riastrad 	} else {
    571  1.1  riastrad 		for (i = 0; i < vid_mapping_table->num_entries; i++) {
    572  1.1  riastrad 			if (vid_mapping_table->entries[i].vid_2bit == vid_2bit)
    573  1.1  riastrad 				return vid_mapping_table->entries[i].vid_7bit;
    574  1.1  riastrad 		}
    575  1.1  riastrad 		return vid_mapping_table->entries[vid_mapping_table->num_entries - 1].vid_7bit;
    576  1.1  riastrad 	}
    577  1.1  riastrad }
    578  1.1  riastrad 
    579  1.1  riastrad static u32 kv_convert_vid7_to_vid2(struct radeon_device *rdev,
    580  1.1  riastrad 				   struct sumo_vid_mapping_table *vid_mapping_table,
    581  1.1  riastrad 				   u32 vid_7bit)
    582  1.1  riastrad {
    583  1.1  riastrad 	struct radeon_clock_voltage_dependency_table *vddc_sclk_table =
    584  1.1  riastrad 		&rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk;
    585  1.1  riastrad 	u32 i;
    586  1.1  riastrad 
    587  1.1  riastrad 	if (vddc_sclk_table && vddc_sclk_table->count) {
    588  1.1  riastrad 		for (i = 0; i < vddc_sclk_table->count; i++) {
    589  1.1  riastrad 			if (vddc_sclk_table->entries[i].v == vid_7bit)
    590  1.1  riastrad 				return i;
    591  1.1  riastrad 		}
    592  1.1  riastrad 		return vddc_sclk_table->count - 1;
    593  1.1  riastrad 	} else {
    594  1.1  riastrad 		for (i = 0; i < vid_mapping_table->num_entries; i++) {
    595  1.1  riastrad 			if (vid_mapping_table->entries[i].vid_7bit == vid_7bit)
    596  1.1  riastrad 				return vid_mapping_table->entries[i].vid_2bit;
    597  1.1  riastrad 		}
    598  1.1  riastrad 
    599  1.1  riastrad 		return vid_mapping_table->entries[vid_mapping_table->num_entries - 1].vid_2bit;
    600  1.1  riastrad 	}
    601  1.1  riastrad }
    602  1.1  riastrad 
    603  1.1  riastrad static u16 kv_convert_8bit_index_to_voltage(struct radeon_device *rdev,
    604  1.1  riastrad 					    u16 voltage)
    605  1.1  riastrad {
    606  1.1  riastrad 	return 6200 - (voltage * 25);
    607  1.1  riastrad }
    608  1.1  riastrad 
    609  1.1  riastrad static u16 kv_convert_2bit_index_to_voltage(struct radeon_device *rdev,
    610  1.1  riastrad 					    u32 vid_2bit)
    611  1.1  riastrad {
    612  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
    613  1.1  riastrad 	u32 vid_8bit = kv_convert_vid2_to_vid7(rdev,
    614  1.1  riastrad 					       &pi->sys_info.vid_mapping_table,
    615  1.1  riastrad 					       vid_2bit);
    616  1.1  riastrad 
    617  1.1  riastrad 	return kv_convert_8bit_index_to_voltage(rdev, (u16)vid_8bit);
    618  1.1  riastrad }
    619  1.1  riastrad 
    620  1.1  riastrad 
    621  1.1  riastrad static int kv_set_vid(struct radeon_device *rdev, u32 index, u32 vid)
    622  1.1  riastrad {
    623  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
    624  1.1  riastrad 
    625  1.1  riastrad 	pi->graphics_level[index].VoltageDownH = (u8)pi->voltage_drop_t;
    626  1.1  riastrad 	pi->graphics_level[index].MinVddNb =
    627  1.1  riastrad 		cpu_to_be32(kv_convert_2bit_index_to_voltage(rdev, vid));
    628  1.1  riastrad 
    629  1.1  riastrad 	return 0;
    630  1.1  riastrad }
    631  1.1  riastrad 
    632  1.1  riastrad static int kv_set_at(struct radeon_device *rdev, u32 index, u32 at)
    633  1.1  riastrad {
    634  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
    635  1.1  riastrad 
    636  1.1  riastrad 	pi->graphics_level[index].AT = cpu_to_be16((u16)at);
    637  1.1  riastrad 
    638  1.1  riastrad 	return 0;
    639  1.1  riastrad }
    640  1.1  riastrad 
    641  1.1  riastrad static void kv_dpm_power_level_enable(struct radeon_device *rdev,
    642  1.1  riastrad 				      u32 index, bool enable)
    643  1.1  riastrad {
    644  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
    645  1.1  riastrad 
    646  1.1  riastrad 	pi->graphics_level[index].EnabledForActivity = enable ? 1 : 0;
    647  1.1  riastrad }
    648  1.1  riastrad 
    649  1.1  riastrad static void kv_start_dpm(struct radeon_device *rdev)
    650  1.1  riastrad {
    651  1.1  riastrad 	u32 tmp = RREG32_SMC(GENERAL_PWRMGT);
    652  1.1  riastrad 
    653  1.1  riastrad 	tmp |= GLOBAL_PWRMGT_EN;
    654  1.1  riastrad 	WREG32_SMC(GENERAL_PWRMGT, tmp);
    655  1.1  riastrad 
    656  1.1  riastrad 	kv_smc_dpm_enable(rdev, true);
    657  1.1  riastrad }
    658  1.1  riastrad 
    659  1.1  riastrad static void kv_stop_dpm(struct radeon_device *rdev)
    660  1.1  riastrad {
    661  1.1  riastrad 	kv_smc_dpm_enable(rdev, false);
    662  1.1  riastrad }
    663  1.1  riastrad 
    664  1.1  riastrad static void kv_start_am(struct radeon_device *rdev)
    665  1.1  riastrad {
    666  1.1  riastrad 	u32 sclk_pwrmgt_cntl = RREG32_SMC(SCLK_PWRMGT_CNTL);
    667  1.1  riastrad 
    668  1.1  riastrad 	sclk_pwrmgt_cntl &= ~(RESET_SCLK_CNT | RESET_BUSY_CNT);
    669  1.1  riastrad 	sclk_pwrmgt_cntl |= DYNAMIC_PM_EN;
    670  1.1  riastrad 
    671  1.1  riastrad 	WREG32_SMC(SCLK_PWRMGT_CNTL, sclk_pwrmgt_cntl);
    672  1.1  riastrad }
    673  1.1  riastrad 
    674  1.1  riastrad static void kv_reset_am(struct radeon_device *rdev)
    675  1.1  riastrad {
    676  1.1  riastrad 	u32 sclk_pwrmgt_cntl = RREG32_SMC(SCLK_PWRMGT_CNTL);
    677  1.1  riastrad 
    678  1.1  riastrad 	sclk_pwrmgt_cntl |= (RESET_SCLK_CNT | RESET_BUSY_CNT);
    679  1.1  riastrad 
    680  1.1  riastrad 	WREG32_SMC(SCLK_PWRMGT_CNTL, sclk_pwrmgt_cntl);
    681  1.1  riastrad }
    682  1.1  riastrad 
    683  1.1  riastrad static int kv_freeze_sclk_dpm(struct radeon_device *rdev, bool freeze)
    684  1.1  riastrad {
    685  1.1  riastrad 	return kv_notify_message_to_smu(rdev, freeze ?
    686  1.1  riastrad 					PPSMC_MSG_SCLKDPM_FreezeLevel : PPSMC_MSG_SCLKDPM_UnfreezeLevel);
    687  1.1  riastrad }
    688  1.1  riastrad 
    689  1.1  riastrad static int kv_force_lowest_valid(struct radeon_device *rdev)
    690  1.1  riastrad {
    691  1.1  riastrad 	return kv_force_dpm_lowest(rdev);
    692  1.1  riastrad }
    693  1.1  riastrad 
    694  1.1  riastrad static int kv_unforce_levels(struct radeon_device *rdev)
    695  1.1  riastrad {
    696  1.1  riastrad 	if (rdev->family == CHIP_KABINI || rdev->family == CHIP_MULLINS)
    697  1.1  riastrad 		return kv_notify_message_to_smu(rdev, PPSMC_MSG_NoForcedLevel);
    698  1.1  riastrad 	else
    699  1.1  riastrad 		return kv_set_enabled_levels(rdev);
    700  1.1  riastrad }
    701  1.1  riastrad 
    702  1.1  riastrad static int kv_update_sclk_t(struct radeon_device *rdev)
    703  1.1  riastrad {
    704  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
    705  1.1  riastrad 	u32 low_sclk_interrupt_t = 0;
    706  1.1  riastrad 	int ret = 0;
    707  1.1  riastrad 
    708  1.1  riastrad 	if (pi->caps_sclk_throttle_low_notification) {
    709  1.1  riastrad 		low_sclk_interrupt_t = cpu_to_be32(pi->low_sclk_interrupt_t);
    710  1.1  riastrad 
    711  1.1  riastrad 		ret = kv_copy_bytes_to_smc(rdev,
    712  1.1  riastrad 					   pi->dpm_table_start +
    713  1.1  riastrad 					   offsetof(SMU7_Fusion_DpmTable, LowSclkInterruptT),
    714  1.1  riastrad 					   (u8 *)&low_sclk_interrupt_t,
    715  1.1  riastrad 					   sizeof(u32), pi->sram_end);
    716  1.1  riastrad 	}
    717  1.1  riastrad 	return ret;
    718  1.1  riastrad }
    719  1.1  riastrad 
    720  1.1  riastrad static int kv_program_bootup_state(struct radeon_device *rdev)
    721  1.1  riastrad {
    722  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
    723  1.1  riastrad 	u32 i;
    724  1.1  riastrad 	struct radeon_clock_voltage_dependency_table *table =
    725  1.1  riastrad 		&rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk;
    726  1.1  riastrad 
    727  1.1  riastrad 	if (table && table->count) {
    728  1.1  riastrad 		for (i = pi->graphics_dpm_level_count - 1; i > 0; i--) {
    729  1.1  riastrad 			if (table->entries[i].clk == pi->boot_pl.sclk)
    730  1.1  riastrad 				break;
    731  1.1  riastrad 		}
    732  1.1  riastrad 
    733  1.1  riastrad 		pi->graphics_boot_level = (u8)i;
    734  1.1  riastrad 		kv_dpm_power_level_enable(rdev, i, true);
    735  1.1  riastrad 	} else {
    736  1.1  riastrad 		struct sumo_sclk_voltage_mapping_table *table =
    737  1.1  riastrad 			&pi->sys_info.sclk_voltage_mapping_table;
    738  1.1  riastrad 
    739  1.1  riastrad 		if (table->num_max_dpm_entries == 0)
    740  1.1  riastrad 			return -EINVAL;
    741  1.1  riastrad 
    742  1.1  riastrad 		for (i = pi->graphics_dpm_level_count - 1; i > 0; i--) {
    743  1.1  riastrad 			if (table->entries[i].sclk_frequency == pi->boot_pl.sclk)
    744  1.1  riastrad 				break;
    745  1.1  riastrad 		}
    746  1.1  riastrad 
    747  1.1  riastrad 		pi->graphics_boot_level = (u8)i;
    748  1.1  riastrad 		kv_dpm_power_level_enable(rdev, i, true);
    749  1.1  riastrad 	}
    750  1.1  riastrad 	return 0;
    751  1.1  riastrad }
    752  1.1  riastrad 
    753  1.1  riastrad static int kv_enable_auto_thermal_throttling(struct radeon_device *rdev)
    754  1.1  riastrad {
    755  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
    756  1.1  riastrad 	int ret;
    757  1.1  riastrad 
    758  1.1  riastrad 	pi->graphics_therm_throttle_enable = 1;
    759  1.1  riastrad 
    760  1.1  riastrad 	ret = kv_copy_bytes_to_smc(rdev,
    761  1.1  riastrad 				   pi->dpm_table_start +
    762  1.1  riastrad 				   offsetof(SMU7_Fusion_DpmTable, GraphicsThermThrottleEnable),
    763  1.1  riastrad 				   &pi->graphics_therm_throttle_enable,
    764  1.1  riastrad 				   sizeof(u8), pi->sram_end);
    765  1.1  riastrad 
    766  1.1  riastrad 	return ret;
    767  1.1  riastrad }
    768  1.1  riastrad 
    769  1.1  riastrad static int kv_upload_dpm_settings(struct radeon_device *rdev)
    770  1.1  riastrad {
    771  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
    772  1.1  riastrad 	int ret;
    773  1.1  riastrad 
    774  1.1  riastrad 	ret = kv_copy_bytes_to_smc(rdev,
    775  1.1  riastrad 				   pi->dpm_table_start +
    776  1.1  riastrad 				   offsetof(SMU7_Fusion_DpmTable, GraphicsLevel),
    777  1.1  riastrad 				   (u8 *)&pi->graphics_level,
    778  1.1  riastrad 				   sizeof(SMU7_Fusion_GraphicsLevel) * SMU7_MAX_LEVELS_GRAPHICS,
    779  1.1  riastrad 				   pi->sram_end);
    780  1.1  riastrad 
    781  1.1  riastrad 	if (ret)
    782  1.1  riastrad 		return ret;
    783  1.1  riastrad 
    784  1.1  riastrad 	ret = kv_copy_bytes_to_smc(rdev,
    785  1.1  riastrad 				   pi->dpm_table_start +
    786  1.1  riastrad 				   offsetof(SMU7_Fusion_DpmTable, GraphicsDpmLevelCount),
    787  1.1  riastrad 				   &pi->graphics_dpm_level_count,
    788  1.1  riastrad 				   sizeof(u8), pi->sram_end);
    789  1.1  riastrad 
    790  1.1  riastrad 	return ret;
    791  1.1  riastrad }
    792  1.1  riastrad 
    793  1.1  riastrad static u32 kv_get_clock_difference(u32 a, u32 b)
    794  1.1  riastrad {
    795  1.1  riastrad 	return (a >= b) ? a - b : b - a;
    796  1.1  riastrad }
    797  1.1  riastrad 
    798  1.1  riastrad static u32 kv_get_clk_bypass(struct radeon_device *rdev, u32 clk)
    799  1.1  riastrad {
    800  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
    801  1.1  riastrad 	u32 value;
    802  1.1  riastrad 
    803  1.1  riastrad 	if (pi->caps_enable_dfs_bypass) {
    804  1.1  riastrad 		if (kv_get_clock_difference(clk, 40000) < 200)
    805  1.1  riastrad 			value = 3;
    806  1.1  riastrad 		else if (kv_get_clock_difference(clk, 30000) < 200)
    807  1.1  riastrad 			value = 2;
    808  1.1  riastrad 		else if (kv_get_clock_difference(clk, 20000) < 200)
    809  1.1  riastrad 			value = 7;
    810  1.1  riastrad 		else if (kv_get_clock_difference(clk, 15000) < 200)
    811  1.1  riastrad 			value = 6;
    812  1.1  riastrad 		else if (kv_get_clock_difference(clk, 10000) < 200)
    813  1.1  riastrad 			value = 8;
    814  1.1  riastrad 		else
    815  1.1  riastrad 			value = 0;
    816  1.1  riastrad 	} else {
    817  1.1  riastrad 		value = 0;
    818  1.1  riastrad 	}
    819  1.1  riastrad 
    820  1.1  riastrad 	return value;
    821  1.1  riastrad }
    822  1.1  riastrad 
    823  1.1  riastrad static int kv_populate_uvd_table(struct radeon_device *rdev)
    824  1.1  riastrad {
    825  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
    826  1.1  riastrad 	struct radeon_uvd_clock_voltage_dependency_table *table =
    827  1.1  riastrad 		&rdev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table;
    828  1.1  riastrad 	struct atom_clock_dividers dividers;
    829  1.1  riastrad 	int ret;
    830  1.1  riastrad 	u32 i;
    831  1.1  riastrad 
    832  1.1  riastrad 	if (table == NULL || table->count == 0)
    833  1.1  riastrad 		return 0;
    834  1.1  riastrad 
    835  1.1  riastrad 	pi->uvd_level_count = 0;
    836  1.1  riastrad 	for (i = 0; i < table->count; i++) {
    837  1.1  riastrad 		if (pi->high_voltage_t &&
    838  1.1  riastrad 		    (pi->high_voltage_t < table->entries[i].v))
    839  1.1  riastrad 			break;
    840  1.1  riastrad 
    841  1.1  riastrad 		pi->uvd_level[i].VclkFrequency = cpu_to_be32(table->entries[i].vclk);
    842  1.1  riastrad 		pi->uvd_level[i].DclkFrequency = cpu_to_be32(table->entries[i].dclk);
    843  1.1  riastrad 		pi->uvd_level[i].MinVddNb = cpu_to_be16(table->entries[i].v);
    844  1.1  riastrad 
    845  1.1  riastrad 		pi->uvd_level[i].VClkBypassCntl =
    846  1.1  riastrad 			(u8)kv_get_clk_bypass(rdev, table->entries[i].vclk);
    847  1.1  riastrad 		pi->uvd_level[i].DClkBypassCntl =
    848  1.1  riastrad 			(u8)kv_get_clk_bypass(rdev, table->entries[i].dclk);
    849  1.1  riastrad 
    850  1.1  riastrad 		ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
    851  1.1  riastrad 						     table->entries[i].vclk, false, &dividers);
    852  1.1  riastrad 		if (ret)
    853  1.1  riastrad 			return ret;
    854  1.1  riastrad 		pi->uvd_level[i].VclkDivider = (u8)dividers.post_div;
    855  1.1  riastrad 
    856  1.1  riastrad 		ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
    857  1.1  riastrad 						     table->entries[i].dclk, false, &dividers);
    858  1.1  riastrad 		if (ret)
    859  1.1  riastrad 			return ret;
    860  1.1  riastrad 		pi->uvd_level[i].DclkDivider = (u8)dividers.post_div;
    861  1.1  riastrad 
    862  1.1  riastrad 		pi->uvd_level_count++;
    863  1.1  riastrad 	}
    864  1.1  riastrad 
    865  1.1  riastrad 	ret = kv_copy_bytes_to_smc(rdev,
    866  1.1  riastrad 				   pi->dpm_table_start +
    867  1.1  riastrad 				   offsetof(SMU7_Fusion_DpmTable, UvdLevelCount),
    868  1.1  riastrad 				   (u8 *)&pi->uvd_level_count,
    869  1.1  riastrad 				   sizeof(u8), pi->sram_end);
    870  1.1  riastrad 	if (ret)
    871  1.1  riastrad 		return ret;
    872  1.1  riastrad 
    873  1.1  riastrad 	pi->uvd_interval = 1;
    874  1.1  riastrad 
    875  1.1  riastrad 	ret = kv_copy_bytes_to_smc(rdev,
    876  1.1  riastrad 				   pi->dpm_table_start +
    877  1.1  riastrad 				   offsetof(SMU7_Fusion_DpmTable, UVDInterval),
    878  1.1  riastrad 				   &pi->uvd_interval,
    879  1.1  riastrad 				   sizeof(u8), pi->sram_end);
    880  1.1  riastrad 	if (ret)
    881  1.1  riastrad 		return ret;
    882  1.1  riastrad 
    883  1.1  riastrad 	ret = kv_copy_bytes_to_smc(rdev,
    884  1.1  riastrad 				   pi->dpm_table_start +
    885  1.1  riastrad 				   offsetof(SMU7_Fusion_DpmTable, UvdLevel),
    886  1.1  riastrad 				   (u8 *)&pi->uvd_level,
    887  1.1  riastrad 				   sizeof(SMU7_Fusion_UvdLevel) * SMU7_MAX_LEVELS_UVD,
    888  1.1  riastrad 				   pi->sram_end);
    889  1.1  riastrad 
    890  1.1  riastrad 	return ret;
    891  1.1  riastrad 
    892  1.1  riastrad }
    893  1.1  riastrad 
    894  1.1  riastrad static int kv_populate_vce_table(struct radeon_device *rdev)
    895  1.1  riastrad {
    896  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
    897  1.1  riastrad 	int ret;
    898  1.1  riastrad 	u32 i;
    899  1.1  riastrad 	struct radeon_vce_clock_voltage_dependency_table *table =
    900  1.1  riastrad 		&rdev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table;
    901  1.1  riastrad 	struct atom_clock_dividers dividers;
    902  1.1  riastrad 
    903  1.1  riastrad 	if (table == NULL || table->count == 0)
    904  1.1  riastrad 		return 0;
    905  1.1  riastrad 
    906  1.1  riastrad 	pi->vce_level_count = 0;
    907  1.1  riastrad 	for (i = 0; i < table->count; i++) {
    908  1.1  riastrad 		if (pi->high_voltage_t &&
    909  1.1  riastrad 		    pi->high_voltage_t < table->entries[i].v)
    910  1.1  riastrad 			break;
    911  1.1  riastrad 
    912  1.1  riastrad 		pi->vce_level[i].Frequency = cpu_to_be32(table->entries[i].evclk);
    913  1.1  riastrad 		pi->vce_level[i].MinVoltage = cpu_to_be16(table->entries[i].v);
    914  1.1  riastrad 
    915  1.1  riastrad 		pi->vce_level[i].ClkBypassCntl =
    916  1.1  riastrad 			(u8)kv_get_clk_bypass(rdev, table->entries[i].evclk);
    917  1.1  riastrad 
    918  1.1  riastrad 		ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
    919  1.1  riastrad 						     table->entries[i].evclk, false, &dividers);
    920  1.1  riastrad 		if (ret)
    921  1.1  riastrad 			return ret;
    922  1.1  riastrad 		pi->vce_level[i].Divider = (u8)dividers.post_div;
    923  1.1  riastrad 
    924  1.1  riastrad 		pi->vce_level_count++;
    925  1.1  riastrad 	}
    926  1.1  riastrad 
    927  1.1  riastrad 	ret = kv_copy_bytes_to_smc(rdev,
    928  1.1  riastrad 				   pi->dpm_table_start +
    929  1.1  riastrad 				   offsetof(SMU7_Fusion_DpmTable, VceLevelCount),
    930  1.1  riastrad 				   (u8 *)&pi->vce_level_count,
    931  1.1  riastrad 				   sizeof(u8),
    932  1.1  riastrad 				   pi->sram_end);
    933  1.1  riastrad 	if (ret)
    934  1.1  riastrad 		return ret;
    935  1.1  riastrad 
    936  1.1  riastrad 	pi->vce_interval = 1;
    937  1.1  riastrad 
    938  1.1  riastrad 	ret = kv_copy_bytes_to_smc(rdev,
    939  1.1  riastrad 				   pi->dpm_table_start +
    940  1.1  riastrad 				   offsetof(SMU7_Fusion_DpmTable, VCEInterval),
    941  1.1  riastrad 				   (u8 *)&pi->vce_interval,
    942  1.1  riastrad 				   sizeof(u8),
    943  1.1  riastrad 				   pi->sram_end);
    944  1.1  riastrad 	if (ret)
    945  1.1  riastrad 		return ret;
    946  1.1  riastrad 
    947  1.1  riastrad 	ret = kv_copy_bytes_to_smc(rdev,
    948  1.1  riastrad 				   pi->dpm_table_start +
    949  1.1  riastrad 				   offsetof(SMU7_Fusion_DpmTable, VceLevel),
    950  1.1  riastrad 				   (u8 *)&pi->vce_level,
    951  1.1  riastrad 				   sizeof(SMU7_Fusion_ExtClkLevel) * SMU7_MAX_LEVELS_VCE,
    952  1.1  riastrad 				   pi->sram_end);
    953  1.1  riastrad 
    954  1.1  riastrad 	return ret;
    955  1.1  riastrad }
    956  1.1  riastrad 
    957  1.1  riastrad static int kv_populate_samu_table(struct radeon_device *rdev)
    958  1.1  riastrad {
    959  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
    960  1.1  riastrad 	struct radeon_clock_voltage_dependency_table *table =
    961  1.1  riastrad 		&rdev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table;
    962  1.1  riastrad 	struct atom_clock_dividers dividers;
    963  1.1  riastrad 	int ret;
    964  1.1  riastrad 	u32 i;
    965  1.1  riastrad 
    966  1.1  riastrad 	if (table == NULL || table->count == 0)
    967  1.1  riastrad 		return 0;
    968  1.1  riastrad 
    969  1.1  riastrad 	pi->samu_level_count = 0;
    970  1.1  riastrad 	for (i = 0; i < table->count; i++) {
    971  1.1  riastrad 		if (pi->high_voltage_t &&
    972  1.1  riastrad 		    pi->high_voltage_t < table->entries[i].v)
    973  1.1  riastrad 			break;
    974  1.1  riastrad 
    975  1.1  riastrad 		pi->samu_level[i].Frequency = cpu_to_be32(table->entries[i].clk);
    976  1.1  riastrad 		pi->samu_level[i].MinVoltage = cpu_to_be16(table->entries[i].v);
    977  1.1  riastrad 
    978  1.1  riastrad 		pi->samu_level[i].ClkBypassCntl =
    979  1.1  riastrad 			(u8)kv_get_clk_bypass(rdev, table->entries[i].clk);
    980  1.1  riastrad 
    981  1.1  riastrad 		ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
    982  1.1  riastrad 						     table->entries[i].clk, false, &dividers);
    983  1.1  riastrad 		if (ret)
    984  1.1  riastrad 			return ret;
    985  1.1  riastrad 		pi->samu_level[i].Divider = (u8)dividers.post_div;
    986  1.1  riastrad 
    987  1.1  riastrad 		pi->samu_level_count++;
    988  1.1  riastrad 	}
    989  1.1  riastrad 
    990  1.1  riastrad 	ret = kv_copy_bytes_to_smc(rdev,
    991  1.1  riastrad 				   pi->dpm_table_start +
    992  1.1  riastrad 				   offsetof(SMU7_Fusion_DpmTable, SamuLevelCount),
    993  1.1  riastrad 				   (u8 *)&pi->samu_level_count,
    994  1.1  riastrad 				   sizeof(u8),
    995  1.1  riastrad 				   pi->sram_end);
    996  1.1  riastrad 	if (ret)
    997  1.1  riastrad 		return ret;
    998  1.1  riastrad 
    999  1.1  riastrad 	pi->samu_interval = 1;
   1000  1.1  riastrad 
   1001  1.1  riastrad 	ret = kv_copy_bytes_to_smc(rdev,
   1002  1.1  riastrad 				   pi->dpm_table_start +
   1003  1.1  riastrad 				   offsetof(SMU7_Fusion_DpmTable, SAMUInterval),
   1004  1.1  riastrad 				   (u8 *)&pi->samu_interval,
   1005  1.1  riastrad 				   sizeof(u8),
   1006  1.1  riastrad 				   pi->sram_end);
   1007  1.1  riastrad 	if (ret)
   1008  1.1  riastrad 		return ret;
   1009  1.1  riastrad 
   1010  1.1  riastrad 	ret = kv_copy_bytes_to_smc(rdev,
   1011  1.1  riastrad 				   pi->dpm_table_start +
   1012  1.1  riastrad 				   offsetof(SMU7_Fusion_DpmTable, SamuLevel),
   1013  1.1  riastrad 				   (u8 *)&pi->samu_level,
   1014  1.1  riastrad 				   sizeof(SMU7_Fusion_ExtClkLevel) * SMU7_MAX_LEVELS_SAMU,
   1015  1.1  riastrad 				   pi->sram_end);
   1016  1.1  riastrad 	if (ret)
   1017  1.1  riastrad 		return ret;
   1018  1.1  riastrad 
   1019  1.1  riastrad 	return ret;
   1020  1.1  riastrad }
   1021  1.1  riastrad 
   1022  1.1  riastrad 
   1023  1.1  riastrad static int kv_populate_acp_table(struct radeon_device *rdev)
   1024  1.1  riastrad {
   1025  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   1026  1.1  riastrad 	struct radeon_clock_voltage_dependency_table *table =
   1027  1.1  riastrad 		&rdev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table;
   1028  1.1  riastrad 	struct atom_clock_dividers dividers;
   1029  1.1  riastrad 	int ret;
   1030  1.1  riastrad 	u32 i;
   1031  1.1  riastrad 
   1032  1.1  riastrad 	if (table == NULL || table->count == 0)
   1033  1.1  riastrad 		return 0;
   1034  1.1  riastrad 
   1035  1.1  riastrad 	pi->acp_level_count = 0;
   1036  1.1  riastrad 	for (i = 0; i < table->count; i++) {
   1037  1.1  riastrad 		pi->acp_level[i].Frequency = cpu_to_be32(table->entries[i].clk);
   1038  1.1  riastrad 		pi->acp_level[i].MinVoltage = cpu_to_be16(table->entries[i].v);
   1039  1.1  riastrad 
   1040  1.1  riastrad 		ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
   1041  1.1  riastrad 						     table->entries[i].clk, false, &dividers);
   1042  1.1  riastrad 		if (ret)
   1043  1.1  riastrad 			return ret;
   1044  1.1  riastrad 		pi->acp_level[i].Divider = (u8)dividers.post_div;
   1045  1.1  riastrad 
   1046  1.1  riastrad 		pi->acp_level_count++;
   1047  1.1  riastrad 	}
   1048  1.1  riastrad 
   1049  1.1  riastrad 	ret = kv_copy_bytes_to_smc(rdev,
   1050  1.1  riastrad 				   pi->dpm_table_start +
   1051  1.1  riastrad 				   offsetof(SMU7_Fusion_DpmTable, AcpLevelCount),
   1052  1.1  riastrad 				   (u8 *)&pi->acp_level_count,
   1053  1.1  riastrad 				   sizeof(u8),
   1054  1.1  riastrad 				   pi->sram_end);
   1055  1.1  riastrad 	if (ret)
   1056  1.1  riastrad 		return ret;
   1057  1.1  riastrad 
   1058  1.1  riastrad 	pi->acp_interval = 1;
   1059  1.1  riastrad 
   1060  1.1  riastrad 	ret = kv_copy_bytes_to_smc(rdev,
   1061  1.1  riastrad 				   pi->dpm_table_start +
   1062  1.1  riastrad 				   offsetof(SMU7_Fusion_DpmTable, ACPInterval),
   1063  1.1  riastrad 				   (u8 *)&pi->acp_interval,
   1064  1.1  riastrad 				   sizeof(u8),
   1065  1.1  riastrad 				   pi->sram_end);
   1066  1.1  riastrad 	if (ret)
   1067  1.1  riastrad 		return ret;
   1068  1.1  riastrad 
   1069  1.1  riastrad 	ret = kv_copy_bytes_to_smc(rdev,
   1070  1.1  riastrad 				   pi->dpm_table_start +
   1071  1.1  riastrad 				   offsetof(SMU7_Fusion_DpmTable, AcpLevel),
   1072  1.1  riastrad 				   (u8 *)&pi->acp_level,
   1073  1.1  riastrad 				   sizeof(SMU7_Fusion_ExtClkLevel) * SMU7_MAX_LEVELS_ACP,
   1074  1.1  riastrad 				   pi->sram_end);
   1075  1.1  riastrad 	if (ret)
   1076  1.1  riastrad 		return ret;
   1077  1.1  riastrad 
   1078  1.1  riastrad 	return ret;
   1079  1.1  riastrad }
   1080  1.1  riastrad 
   1081  1.1  riastrad static void kv_calculate_dfs_bypass_settings(struct radeon_device *rdev)
   1082  1.1  riastrad {
   1083  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   1084  1.1  riastrad 	u32 i;
   1085  1.1  riastrad 	struct radeon_clock_voltage_dependency_table *table =
   1086  1.1  riastrad 		&rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk;
   1087  1.1  riastrad 
   1088  1.1  riastrad 	if (table && table->count) {
   1089  1.1  riastrad 		for (i = 0; i < pi->graphics_dpm_level_count; i++) {
   1090  1.1  riastrad 			if (pi->caps_enable_dfs_bypass) {
   1091  1.1  riastrad 				if (kv_get_clock_difference(table->entries[i].clk, 40000) < 200)
   1092  1.1  riastrad 					pi->graphics_level[i].ClkBypassCntl = 3;
   1093  1.1  riastrad 				else if (kv_get_clock_difference(table->entries[i].clk, 30000) < 200)
   1094  1.1  riastrad 					pi->graphics_level[i].ClkBypassCntl = 2;
   1095  1.1  riastrad 				else if (kv_get_clock_difference(table->entries[i].clk, 26600) < 200)
   1096  1.1  riastrad 					pi->graphics_level[i].ClkBypassCntl = 7;
   1097  1.1  riastrad 				else if (kv_get_clock_difference(table->entries[i].clk , 20000) < 200)
   1098  1.1  riastrad 					pi->graphics_level[i].ClkBypassCntl = 6;
   1099  1.1  riastrad 				else if (kv_get_clock_difference(table->entries[i].clk , 10000) < 200)
   1100  1.1  riastrad 					pi->graphics_level[i].ClkBypassCntl = 8;
   1101  1.1  riastrad 				else
   1102  1.1  riastrad 					pi->graphics_level[i].ClkBypassCntl = 0;
   1103  1.1  riastrad 			} else {
   1104  1.1  riastrad 				pi->graphics_level[i].ClkBypassCntl = 0;
   1105  1.1  riastrad 			}
   1106  1.1  riastrad 		}
   1107  1.1  riastrad 	} else {
   1108  1.1  riastrad 		struct sumo_sclk_voltage_mapping_table *table =
   1109  1.1  riastrad 			&pi->sys_info.sclk_voltage_mapping_table;
   1110  1.1  riastrad 		for (i = 0; i < pi->graphics_dpm_level_count; i++) {
   1111  1.1  riastrad 			if (pi->caps_enable_dfs_bypass) {
   1112  1.1  riastrad 				if (kv_get_clock_difference(table->entries[i].sclk_frequency, 40000) < 200)
   1113  1.1  riastrad 					pi->graphics_level[i].ClkBypassCntl = 3;
   1114  1.1  riastrad 				else if (kv_get_clock_difference(table->entries[i].sclk_frequency, 30000) < 200)
   1115  1.1  riastrad 					pi->graphics_level[i].ClkBypassCntl = 2;
   1116  1.1  riastrad 				else if (kv_get_clock_difference(table->entries[i].sclk_frequency, 26600) < 200)
   1117  1.1  riastrad 					pi->graphics_level[i].ClkBypassCntl = 7;
   1118  1.1  riastrad 				else if (kv_get_clock_difference(table->entries[i].sclk_frequency, 20000) < 200)
   1119  1.1  riastrad 					pi->graphics_level[i].ClkBypassCntl = 6;
   1120  1.1  riastrad 				else if (kv_get_clock_difference(table->entries[i].sclk_frequency, 10000) < 200)
   1121  1.1  riastrad 					pi->graphics_level[i].ClkBypassCntl = 8;
   1122  1.1  riastrad 				else
   1123  1.1  riastrad 					pi->graphics_level[i].ClkBypassCntl = 0;
   1124  1.1  riastrad 			} else {
   1125  1.1  riastrad 				pi->graphics_level[i].ClkBypassCntl = 0;
   1126  1.1  riastrad 			}
   1127  1.1  riastrad 		}
   1128  1.1  riastrad 	}
   1129  1.1  riastrad }
   1130  1.1  riastrad 
   1131  1.1  riastrad static int kv_enable_ulv(struct radeon_device *rdev, bool enable)
   1132  1.1  riastrad {
   1133  1.1  riastrad 	return kv_notify_message_to_smu(rdev, enable ?
   1134  1.1  riastrad 					PPSMC_MSG_EnableULV : PPSMC_MSG_DisableULV);
   1135  1.1  riastrad }
   1136  1.1  riastrad 
   1137  1.1  riastrad static void kv_reset_acp_boot_level(struct radeon_device *rdev)
   1138  1.1  riastrad {
   1139  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   1140  1.1  riastrad 
   1141  1.1  riastrad 	pi->acp_boot_level = 0xff;
   1142  1.1  riastrad }
   1143  1.1  riastrad 
   1144  1.1  riastrad static void kv_update_current_ps(struct radeon_device *rdev,
   1145  1.1  riastrad 				 struct radeon_ps *rps)
   1146  1.1  riastrad {
   1147  1.1  riastrad 	struct kv_ps *new_ps = kv_get_ps(rps);
   1148  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   1149  1.1  riastrad 
   1150  1.1  riastrad 	pi->current_rps = *rps;
   1151  1.1  riastrad 	pi->current_ps = *new_ps;
   1152  1.1  riastrad 	pi->current_rps.ps_priv = &pi->current_ps;
   1153  1.1  riastrad }
   1154  1.1  riastrad 
   1155  1.1  riastrad static void kv_update_requested_ps(struct radeon_device *rdev,
   1156  1.1  riastrad 				   struct radeon_ps *rps)
   1157  1.1  riastrad {
   1158  1.1  riastrad 	struct kv_ps *new_ps = kv_get_ps(rps);
   1159  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   1160  1.1  riastrad 
   1161  1.1  riastrad 	pi->requested_rps = *rps;
   1162  1.1  riastrad 	pi->requested_ps = *new_ps;
   1163  1.1  riastrad 	pi->requested_rps.ps_priv = &pi->requested_ps;
   1164  1.1  riastrad }
   1165  1.1  riastrad 
   1166  1.1  riastrad void kv_dpm_enable_bapm(struct radeon_device *rdev, bool enable)
   1167  1.1  riastrad {
   1168  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   1169  1.1  riastrad 	int ret;
   1170  1.1  riastrad 
   1171  1.1  riastrad 	if (pi->bapm_enable) {
   1172  1.1  riastrad 		ret = kv_smc_bapm_enable(rdev, enable);
   1173  1.1  riastrad 		if (ret)
   1174  1.1  riastrad 			DRM_ERROR("kv_smc_bapm_enable failed\n");
   1175  1.1  riastrad 	}
   1176  1.1  riastrad }
   1177  1.1  riastrad 
   1178  1.1  riastrad static void kv_enable_thermal_int(struct radeon_device *rdev, bool enable)
   1179  1.1  riastrad {
   1180  1.1  riastrad 	u32 thermal_int;
   1181  1.1  riastrad 
   1182  1.1  riastrad 	thermal_int = RREG32_SMC(CG_THERMAL_INT_CTRL);
   1183  1.1  riastrad 	if (enable)
   1184  1.1  riastrad 		thermal_int |= THERM_INTH_MASK | THERM_INTL_MASK;
   1185  1.1  riastrad 	else
   1186  1.1  riastrad 		thermal_int &= ~(THERM_INTH_MASK | THERM_INTL_MASK);
   1187  1.1  riastrad 	WREG32_SMC(CG_THERMAL_INT_CTRL, thermal_int);
   1188  1.1  riastrad 
   1189  1.1  riastrad }
   1190  1.1  riastrad 
   1191  1.1  riastrad int kv_dpm_enable(struct radeon_device *rdev)
   1192  1.1  riastrad {
   1193  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   1194  1.1  riastrad 	int ret;
   1195  1.1  riastrad 
   1196  1.1  riastrad 	ret = kv_process_firmware_header(rdev);
   1197  1.1  riastrad 	if (ret) {
   1198  1.1  riastrad 		DRM_ERROR("kv_process_firmware_header failed\n");
   1199  1.1  riastrad 		return ret;
   1200  1.1  riastrad 	}
   1201  1.1  riastrad 	kv_init_fps_limits(rdev);
   1202  1.1  riastrad 	kv_init_graphics_levels(rdev);
   1203  1.1  riastrad 	ret = kv_program_bootup_state(rdev);
   1204  1.1  riastrad 	if (ret) {
   1205  1.1  riastrad 		DRM_ERROR("kv_program_bootup_state failed\n");
   1206  1.1  riastrad 		return ret;
   1207  1.1  riastrad 	}
   1208  1.1  riastrad 	kv_calculate_dfs_bypass_settings(rdev);
   1209  1.1  riastrad 	ret = kv_upload_dpm_settings(rdev);
   1210  1.1  riastrad 	if (ret) {
   1211  1.1  riastrad 		DRM_ERROR("kv_upload_dpm_settings failed\n");
   1212  1.1  riastrad 		return ret;
   1213  1.1  riastrad 	}
   1214  1.1  riastrad 	ret = kv_populate_uvd_table(rdev);
   1215  1.1  riastrad 	if (ret) {
   1216  1.1  riastrad 		DRM_ERROR("kv_populate_uvd_table failed\n");
   1217  1.1  riastrad 		return ret;
   1218  1.1  riastrad 	}
   1219  1.1  riastrad 	ret = kv_populate_vce_table(rdev);
   1220  1.1  riastrad 	if (ret) {
   1221  1.1  riastrad 		DRM_ERROR("kv_populate_vce_table failed\n");
   1222  1.1  riastrad 		return ret;
   1223  1.1  riastrad 	}
   1224  1.1  riastrad 	ret = kv_populate_samu_table(rdev);
   1225  1.1  riastrad 	if (ret) {
   1226  1.1  riastrad 		DRM_ERROR("kv_populate_samu_table failed\n");
   1227  1.1  riastrad 		return ret;
   1228  1.1  riastrad 	}
   1229  1.1  riastrad 	ret = kv_populate_acp_table(rdev);
   1230  1.1  riastrad 	if (ret) {
   1231  1.1  riastrad 		DRM_ERROR("kv_populate_acp_table failed\n");
   1232  1.1  riastrad 		return ret;
   1233  1.1  riastrad 	}
   1234  1.1  riastrad 	kv_program_vc(rdev);
   1235  1.1  riastrad #if 0
   1236  1.1  riastrad 	kv_initialize_hardware_cac_manager(rdev);
   1237  1.1  riastrad #endif
   1238  1.1  riastrad 	kv_start_am(rdev);
   1239  1.1  riastrad 	if (pi->enable_auto_thermal_throttling) {
   1240  1.1  riastrad 		ret = kv_enable_auto_thermal_throttling(rdev);
   1241  1.1  riastrad 		if (ret) {
   1242  1.1  riastrad 			DRM_ERROR("kv_enable_auto_thermal_throttling failed\n");
   1243  1.1  riastrad 			return ret;
   1244  1.1  riastrad 		}
   1245  1.1  riastrad 	}
   1246  1.1  riastrad 	ret = kv_enable_dpm_voltage_scaling(rdev);
   1247  1.1  riastrad 	if (ret) {
   1248  1.1  riastrad 		DRM_ERROR("kv_enable_dpm_voltage_scaling failed\n");
   1249  1.1  riastrad 		return ret;
   1250  1.1  riastrad 	}
   1251  1.1  riastrad 	ret = kv_set_dpm_interval(rdev);
   1252  1.1  riastrad 	if (ret) {
   1253  1.1  riastrad 		DRM_ERROR("kv_set_dpm_interval failed\n");
   1254  1.1  riastrad 		return ret;
   1255  1.1  riastrad 	}
   1256  1.1  riastrad 	ret = kv_set_dpm_boot_state(rdev);
   1257  1.1  riastrad 	if (ret) {
   1258  1.1  riastrad 		DRM_ERROR("kv_set_dpm_boot_state failed\n");
   1259  1.1  riastrad 		return ret;
   1260  1.1  riastrad 	}
   1261  1.1  riastrad 	ret = kv_enable_ulv(rdev, true);
   1262  1.1  riastrad 	if (ret) {
   1263  1.1  riastrad 		DRM_ERROR("kv_enable_ulv failed\n");
   1264  1.1  riastrad 		return ret;
   1265  1.1  riastrad 	}
   1266  1.1  riastrad 	kv_start_dpm(rdev);
   1267  1.1  riastrad 	ret = kv_enable_didt(rdev, true);
   1268  1.1  riastrad 	if (ret) {
   1269  1.1  riastrad 		DRM_ERROR("kv_enable_didt failed\n");
   1270  1.1  riastrad 		return ret;
   1271  1.1  riastrad 	}
   1272  1.1  riastrad 	ret = kv_enable_smc_cac(rdev, true);
   1273  1.1  riastrad 	if (ret) {
   1274  1.1  riastrad 		DRM_ERROR("kv_enable_smc_cac failed\n");
   1275  1.1  riastrad 		return ret;
   1276  1.1  riastrad 	}
   1277  1.1  riastrad 
   1278  1.1  riastrad 	kv_reset_acp_boot_level(rdev);
   1279  1.1  riastrad 
   1280  1.1  riastrad 	ret = kv_smc_bapm_enable(rdev, false);
   1281  1.1  riastrad 	if (ret) {
   1282  1.1  riastrad 		DRM_ERROR("kv_smc_bapm_enable failed\n");
   1283  1.1  riastrad 		return ret;
   1284  1.1  riastrad 	}
   1285  1.1  riastrad 
   1286  1.1  riastrad 	kv_update_current_ps(rdev, rdev->pm.dpm.boot_ps);
   1287  1.1  riastrad 
   1288  1.1  riastrad 	return ret;
   1289  1.1  riastrad }
   1290  1.1  riastrad 
   1291  1.1  riastrad int kv_dpm_late_enable(struct radeon_device *rdev)
   1292  1.1  riastrad {
   1293  1.1  riastrad 	int ret = 0;
   1294  1.1  riastrad 
   1295  1.1  riastrad 	if (rdev->irq.installed &&
   1296  1.1  riastrad 	    r600_is_internal_thermal_sensor(rdev->pm.int_thermal_type)) {
   1297  1.1  riastrad 		ret = kv_set_thermal_temperature_range(rdev, R600_TEMP_RANGE_MIN, R600_TEMP_RANGE_MAX);
   1298  1.1  riastrad 		if (ret) {
   1299  1.1  riastrad 			DRM_ERROR("kv_set_thermal_temperature_range failed\n");
   1300  1.1  riastrad 			return ret;
   1301  1.1  riastrad 		}
   1302  1.1  riastrad 		kv_enable_thermal_int(rdev, true);
   1303  1.1  riastrad 	}
   1304  1.1  riastrad 
   1305  1.1  riastrad 	/* powerdown unused blocks for now */
   1306  1.1  riastrad 	kv_dpm_powergate_acp(rdev, true);
   1307  1.1  riastrad 	kv_dpm_powergate_samu(rdev, true);
   1308  1.1  riastrad 	kv_dpm_powergate_vce(rdev, true);
   1309  1.1  riastrad 	kv_dpm_powergate_uvd(rdev, true);
   1310  1.1  riastrad 
   1311  1.1  riastrad 	return ret;
   1312  1.1  riastrad }
   1313  1.1  riastrad 
   1314  1.1  riastrad void kv_dpm_disable(struct radeon_device *rdev)
   1315  1.1  riastrad {
   1316  1.1  riastrad 	kv_smc_bapm_enable(rdev, false);
   1317  1.1  riastrad 
   1318  1.1  riastrad 	if (rdev->family == CHIP_MULLINS)
   1319  1.1  riastrad 		kv_enable_nb_dpm(rdev, false);
   1320  1.1  riastrad 
   1321  1.1  riastrad 	/* powerup blocks */
   1322  1.1  riastrad 	kv_dpm_powergate_acp(rdev, false);
   1323  1.1  riastrad 	kv_dpm_powergate_samu(rdev, false);
   1324  1.1  riastrad 	kv_dpm_powergate_vce(rdev, false);
   1325  1.1  riastrad 	kv_dpm_powergate_uvd(rdev, false);
   1326  1.1  riastrad 
   1327  1.1  riastrad 	kv_enable_smc_cac(rdev, false);
   1328  1.1  riastrad 	kv_enable_didt(rdev, false);
   1329  1.1  riastrad 	kv_clear_vc(rdev);
   1330  1.1  riastrad 	kv_stop_dpm(rdev);
   1331  1.1  riastrad 	kv_enable_ulv(rdev, false);
   1332  1.1  riastrad 	kv_reset_am(rdev);
   1333  1.1  riastrad 	kv_enable_thermal_int(rdev, false);
   1334  1.1  riastrad 
   1335  1.1  riastrad 	kv_update_current_ps(rdev, rdev->pm.dpm.boot_ps);
   1336  1.1  riastrad }
   1337  1.1  riastrad 
   1338  1.1  riastrad #if 0
   1339  1.1  riastrad static int kv_write_smc_soft_register(struct radeon_device *rdev,
   1340  1.1  riastrad 				      u16 reg_offset, u32 value)
   1341  1.1  riastrad {
   1342  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   1343  1.1  riastrad 
   1344  1.1  riastrad 	return kv_copy_bytes_to_smc(rdev, pi->soft_regs_start + reg_offset,
   1345  1.1  riastrad 				    (u8 *)&value, sizeof(u16), pi->sram_end);
   1346  1.1  riastrad }
   1347  1.1  riastrad 
   1348  1.1  riastrad static int kv_read_smc_soft_register(struct radeon_device *rdev,
   1349  1.1  riastrad 				     u16 reg_offset, u32 *value)
   1350  1.1  riastrad {
   1351  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   1352  1.1  riastrad 
   1353  1.1  riastrad 	return kv_read_smc_sram_dword(rdev, pi->soft_regs_start + reg_offset,
   1354  1.1  riastrad 				      value, pi->sram_end);
   1355  1.1  riastrad }
   1356  1.1  riastrad #endif
   1357  1.1  riastrad 
   1358  1.1  riastrad static void kv_init_sclk_t(struct radeon_device *rdev)
   1359  1.1  riastrad {
   1360  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   1361  1.1  riastrad 
   1362  1.1  riastrad 	pi->low_sclk_interrupt_t = 0;
   1363  1.1  riastrad }
   1364  1.1  riastrad 
   1365  1.1  riastrad static int kv_init_fps_limits(struct radeon_device *rdev)
   1366  1.1  riastrad {
   1367  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   1368  1.1  riastrad 	int ret = 0;
   1369  1.1  riastrad 
   1370  1.1  riastrad 	if (pi->caps_fps) {
   1371  1.1  riastrad 		u16 tmp;
   1372  1.1  riastrad 
   1373  1.1  riastrad 		tmp = 45;
   1374  1.1  riastrad 		pi->fps_high_t = cpu_to_be16(tmp);
   1375  1.1  riastrad 		ret = kv_copy_bytes_to_smc(rdev,
   1376  1.1  riastrad 					   pi->dpm_table_start +
   1377  1.1  riastrad 					   offsetof(SMU7_Fusion_DpmTable, FpsHighT),
   1378  1.1  riastrad 					   (u8 *)&pi->fps_high_t,
   1379  1.1  riastrad 					   sizeof(u16), pi->sram_end);
   1380  1.1  riastrad 
   1381  1.1  riastrad 		tmp = 30;
   1382  1.1  riastrad 		pi->fps_low_t = cpu_to_be16(tmp);
   1383  1.1  riastrad 
   1384  1.1  riastrad 		ret = kv_copy_bytes_to_smc(rdev,
   1385  1.1  riastrad 					   pi->dpm_table_start +
   1386  1.1  riastrad 					   offsetof(SMU7_Fusion_DpmTable, FpsLowT),
   1387  1.1  riastrad 					   (u8 *)&pi->fps_low_t,
   1388  1.1  riastrad 					   sizeof(u16), pi->sram_end);
   1389  1.1  riastrad 
   1390  1.1  riastrad 	}
   1391  1.1  riastrad 	return ret;
   1392  1.1  riastrad }
   1393  1.1  riastrad 
   1394  1.1  riastrad static void kv_init_powergate_state(struct radeon_device *rdev)
   1395  1.1  riastrad {
   1396  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   1397  1.1  riastrad 
   1398  1.1  riastrad 	pi->uvd_power_gated = false;
   1399  1.1  riastrad 	pi->vce_power_gated = false;
   1400  1.1  riastrad 	pi->samu_power_gated = false;
   1401  1.1  riastrad 	pi->acp_power_gated = false;
   1402  1.1  riastrad 
   1403  1.1  riastrad }
   1404  1.1  riastrad 
   1405  1.1  riastrad static int kv_enable_uvd_dpm(struct radeon_device *rdev, bool enable)
   1406  1.1  riastrad {
   1407  1.1  riastrad 	return kv_notify_message_to_smu(rdev, enable ?
   1408  1.1  riastrad 					PPSMC_MSG_UVDDPM_Enable : PPSMC_MSG_UVDDPM_Disable);
   1409  1.1  riastrad }
   1410  1.1  riastrad 
   1411  1.1  riastrad static int kv_enable_vce_dpm(struct radeon_device *rdev, bool enable)
   1412  1.1  riastrad {
   1413  1.1  riastrad 	return kv_notify_message_to_smu(rdev, enable ?
   1414  1.1  riastrad 					PPSMC_MSG_VCEDPM_Enable : PPSMC_MSG_VCEDPM_Disable);
   1415  1.1  riastrad }
   1416  1.1  riastrad 
   1417  1.1  riastrad static int kv_enable_samu_dpm(struct radeon_device *rdev, bool enable)
   1418  1.1  riastrad {
   1419  1.1  riastrad 	return kv_notify_message_to_smu(rdev, enable ?
   1420  1.1  riastrad 					PPSMC_MSG_SAMUDPM_Enable : PPSMC_MSG_SAMUDPM_Disable);
   1421  1.1  riastrad }
   1422  1.1  riastrad 
   1423  1.1  riastrad static int kv_enable_acp_dpm(struct radeon_device *rdev, bool enable)
   1424  1.1  riastrad {
   1425  1.1  riastrad 	return kv_notify_message_to_smu(rdev, enable ?
   1426  1.1  riastrad 					PPSMC_MSG_ACPDPM_Enable : PPSMC_MSG_ACPDPM_Disable);
   1427  1.1  riastrad }
   1428  1.1  riastrad 
   1429  1.1  riastrad static int kv_update_uvd_dpm(struct radeon_device *rdev, bool gate)
   1430  1.1  riastrad {
   1431  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   1432  1.1  riastrad 	struct radeon_uvd_clock_voltage_dependency_table *table =
   1433  1.1  riastrad 		&rdev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table;
   1434  1.1  riastrad 	int ret;
   1435  1.1  riastrad 	u32 mask;
   1436  1.1  riastrad 
   1437  1.1  riastrad 	if (!gate) {
   1438  1.1  riastrad 		if (table->count)
   1439  1.1  riastrad 			pi->uvd_boot_level = table->count - 1;
   1440  1.1  riastrad 		else
   1441  1.1  riastrad 			pi->uvd_boot_level = 0;
   1442  1.1  riastrad 
   1443  1.1  riastrad 		if (!pi->caps_uvd_dpm || pi->caps_stable_p_state) {
   1444  1.1  riastrad 			mask = 1 << pi->uvd_boot_level;
   1445  1.1  riastrad 		} else {
   1446  1.1  riastrad 			mask = 0x1f;
   1447  1.1  riastrad 		}
   1448  1.1  riastrad 
   1449  1.1  riastrad 		ret = kv_copy_bytes_to_smc(rdev,
   1450  1.1  riastrad 					   pi->dpm_table_start +
   1451  1.1  riastrad 					   offsetof(SMU7_Fusion_DpmTable, UvdBootLevel),
   1452  1.1  riastrad 					   (uint8_t *)&pi->uvd_boot_level,
   1453  1.1  riastrad 					   sizeof(u8), pi->sram_end);
   1454  1.1  riastrad 		if (ret)
   1455  1.1  riastrad 			return ret;
   1456  1.1  riastrad 
   1457  1.1  riastrad 		kv_send_msg_to_smc_with_parameter(rdev,
   1458  1.1  riastrad 						  PPSMC_MSG_UVDDPM_SetEnabledMask,
   1459  1.1  riastrad 						  mask);
   1460  1.1  riastrad 	}
   1461  1.1  riastrad 
   1462  1.1  riastrad 	return kv_enable_uvd_dpm(rdev, !gate);
   1463  1.1  riastrad }
   1464  1.1  riastrad 
   1465  1.1  riastrad static u8 kv_get_vce_boot_level(struct radeon_device *rdev, u32 evclk)
   1466  1.1  riastrad {
   1467  1.1  riastrad 	u8 i;
   1468  1.1  riastrad 	struct radeon_vce_clock_voltage_dependency_table *table =
   1469  1.1  riastrad 		&rdev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table;
   1470  1.1  riastrad 
   1471  1.1  riastrad 	for (i = 0; i < table->count; i++) {
   1472  1.1  riastrad 		if (table->entries[i].evclk >= evclk)
   1473  1.1  riastrad 			break;
   1474  1.1  riastrad 	}
   1475  1.1  riastrad 
   1476  1.1  riastrad 	return i;
   1477  1.1  riastrad }
   1478  1.1  riastrad 
   1479  1.1  riastrad static int kv_update_vce_dpm(struct radeon_device *rdev,
   1480  1.1  riastrad 			     struct radeon_ps *radeon_new_state,
   1481  1.1  riastrad 			     struct radeon_ps *radeon_current_state)
   1482  1.1  riastrad {
   1483  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   1484  1.1  riastrad 	struct radeon_vce_clock_voltage_dependency_table *table =
   1485  1.1  riastrad 		&rdev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table;
   1486  1.1  riastrad 	int ret;
   1487  1.1  riastrad 
   1488  1.1  riastrad 	if (radeon_new_state->evclk > 0 && radeon_current_state->evclk == 0) {
   1489  1.1  riastrad 		kv_dpm_powergate_vce(rdev, false);
   1490  1.1  riastrad 		/* turn the clocks on when encoding */
   1491  1.1  riastrad 		cik_update_cg(rdev, RADEON_CG_BLOCK_VCE, false);
   1492  1.1  riastrad 		if (pi->caps_stable_p_state)
   1493  1.1  riastrad 			pi->vce_boot_level = table->count - 1;
   1494  1.1  riastrad 		else
   1495  1.1  riastrad 			pi->vce_boot_level = kv_get_vce_boot_level(rdev, radeon_new_state->evclk);
   1496  1.1  riastrad 
   1497  1.1  riastrad 		ret = kv_copy_bytes_to_smc(rdev,
   1498  1.1  riastrad 					   pi->dpm_table_start +
   1499  1.1  riastrad 					   offsetof(SMU7_Fusion_DpmTable, VceBootLevel),
   1500  1.1  riastrad 					   (u8 *)&pi->vce_boot_level,
   1501  1.1  riastrad 					   sizeof(u8),
   1502  1.1  riastrad 					   pi->sram_end);
   1503  1.1  riastrad 		if (ret)
   1504  1.1  riastrad 			return ret;
   1505  1.1  riastrad 
   1506  1.1  riastrad 		if (pi->caps_stable_p_state)
   1507  1.1  riastrad 			kv_send_msg_to_smc_with_parameter(rdev,
   1508  1.1  riastrad 							  PPSMC_MSG_VCEDPM_SetEnabledMask,
   1509  1.1  riastrad 							  (1 << pi->vce_boot_level));
   1510  1.1  riastrad 
   1511  1.1  riastrad 		kv_enable_vce_dpm(rdev, true);
   1512  1.1  riastrad 	} else if (radeon_new_state->evclk == 0 && radeon_current_state->evclk > 0) {
   1513  1.1  riastrad 		kv_enable_vce_dpm(rdev, false);
   1514  1.1  riastrad 		/* turn the clocks off when not encoding */
   1515  1.1  riastrad 		cik_update_cg(rdev, RADEON_CG_BLOCK_VCE, true);
   1516  1.1  riastrad 		kv_dpm_powergate_vce(rdev, true);
   1517  1.1  riastrad 	}
   1518  1.1  riastrad 
   1519  1.1  riastrad 	return 0;
   1520  1.1  riastrad }
   1521  1.1  riastrad 
   1522  1.1  riastrad static int kv_update_samu_dpm(struct radeon_device *rdev, bool gate)
   1523  1.1  riastrad {
   1524  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   1525  1.1  riastrad 	struct radeon_clock_voltage_dependency_table *table =
   1526  1.1  riastrad 		&rdev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table;
   1527  1.1  riastrad 	int ret;
   1528  1.1  riastrad 
   1529  1.1  riastrad 	if (!gate) {
   1530  1.1  riastrad 		if (pi->caps_stable_p_state)
   1531  1.1  riastrad 			pi->samu_boot_level = table->count - 1;
   1532  1.1  riastrad 		else
   1533  1.1  riastrad 			pi->samu_boot_level = 0;
   1534  1.1  riastrad 
   1535  1.1  riastrad 		ret = kv_copy_bytes_to_smc(rdev,
   1536  1.1  riastrad 					   pi->dpm_table_start +
   1537  1.1  riastrad 					   offsetof(SMU7_Fusion_DpmTable, SamuBootLevel),
   1538  1.1  riastrad 					   (u8 *)&pi->samu_boot_level,
   1539  1.1  riastrad 					   sizeof(u8),
   1540  1.1  riastrad 					   pi->sram_end);
   1541  1.1  riastrad 		if (ret)
   1542  1.1  riastrad 			return ret;
   1543  1.1  riastrad 
   1544  1.1  riastrad 		if (pi->caps_stable_p_state)
   1545  1.1  riastrad 			kv_send_msg_to_smc_with_parameter(rdev,
   1546  1.1  riastrad 							  PPSMC_MSG_SAMUDPM_SetEnabledMask,
   1547  1.1  riastrad 							  (1 << pi->samu_boot_level));
   1548  1.1  riastrad 	}
   1549  1.1  riastrad 
   1550  1.1  riastrad 	return kv_enable_samu_dpm(rdev, !gate);
   1551  1.1  riastrad }
   1552  1.1  riastrad 
   1553  1.1  riastrad static u8 kv_get_acp_boot_level(struct radeon_device *rdev)
   1554  1.1  riastrad {
   1555  1.1  riastrad 	u8 i;
   1556  1.1  riastrad 	struct radeon_clock_voltage_dependency_table *table =
   1557  1.1  riastrad 		&rdev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table;
   1558  1.1  riastrad 
   1559  1.1  riastrad 	for (i = 0; i < table->count; i++) {
   1560  1.1  riastrad #if 0		/* XXX Upstream has changed this to make sense.  */
   1561  1.1  riastrad 		if (table->entries[i].clk >= 0) /* XXX */
   1562  1.1  riastrad 			break;
   1563  1.1  riastrad #endif
   1564  1.1  riastrad 	}
   1565  1.1  riastrad 
   1566  1.1  riastrad 	if (i >= table->count)
   1567  1.1  riastrad 		i = table->count - 1;
   1568  1.1  riastrad 
   1569  1.1  riastrad 	return i;
   1570  1.1  riastrad }
   1571  1.1  riastrad 
   1572  1.1  riastrad static void kv_update_acp_boot_level(struct radeon_device *rdev)
   1573  1.1  riastrad {
   1574  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   1575  1.1  riastrad 	u8 acp_boot_level;
   1576  1.1  riastrad 
   1577  1.1  riastrad 	if (!pi->caps_stable_p_state) {
   1578  1.1  riastrad 		acp_boot_level = kv_get_acp_boot_level(rdev);
   1579  1.1  riastrad 		if (acp_boot_level != pi->acp_boot_level) {
   1580  1.1  riastrad 			pi->acp_boot_level = acp_boot_level;
   1581  1.1  riastrad 			kv_send_msg_to_smc_with_parameter(rdev,
   1582  1.1  riastrad 							  PPSMC_MSG_ACPDPM_SetEnabledMask,
   1583  1.1  riastrad 							  (1 << pi->acp_boot_level));
   1584  1.1  riastrad 		}
   1585  1.1  riastrad 	}
   1586  1.1  riastrad }
   1587  1.1  riastrad 
   1588  1.1  riastrad static int kv_update_acp_dpm(struct radeon_device *rdev, bool gate)
   1589  1.1  riastrad {
   1590  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   1591  1.1  riastrad 	struct radeon_clock_voltage_dependency_table *table =
   1592  1.1  riastrad 		&rdev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table;
   1593  1.1  riastrad 	int ret;
   1594  1.1  riastrad 
   1595  1.1  riastrad 	if (!gate) {
   1596  1.1  riastrad 		if (pi->caps_stable_p_state)
   1597  1.1  riastrad 			pi->acp_boot_level = table->count - 1;
   1598  1.1  riastrad 		else
   1599  1.1  riastrad 			pi->acp_boot_level = kv_get_acp_boot_level(rdev);
   1600  1.1  riastrad 
   1601  1.1  riastrad 		ret = kv_copy_bytes_to_smc(rdev,
   1602  1.1  riastrad 					   pi->dpm_table_start +
   1603  1.1  riastrad 					   offsetof(SMU7_Fusion_DpmTable, AcpBootLevel),
   1604  1.1  riastrad 					   (u8 *)&pi->acp_boot_level,
   1605  1.1  riastrad 					   sizeof(u8),
   1606  1.1  riastrad 					   pi->sram_end);
   1607  1.1  riastrad 		if (ret)
   1608  1.1  riastrad 			return ret;
   1609  1.1  riastrad 
   1610  1.1  riastrad 		if (pi->caps_stable_p_state)
   1611  1.1  riastrad 			kv_send_msg_to_smc_with_parameter(rdev,
   1612  1.1  riastrad 							  PPSMC_MSG_ACPDPM_SetEnabledMask,
   1613  1.1  riastrad 							  (1 << pi->acp_boot_level));
   1614  1.1  riastrad 	}
   1615  1.1  riastrad 
   1616  1.1  riastrad 	return kv_enable_acp_dpm(rdev, !gate);
   1617  1.1  riastrad }
   1618  1.1  riastrad 
   1619  1.1  riastrad void kv_dpm_powergate_uvd(struct radeon_device *rdev, bool gate)
   1620  1.1  riastrad {
   1621  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   1622  1.1  riastrad 
   1623  1.1  riastrad 	if (pi->uvd_power_gated == gate)
   1624  1.1  riastrad 		return;
   1625  1.1  riastrad 
   1626  1.1  riastrad 	pi->uvd_power_gated = gate;
   1627  1.1  riastrad 
   1628  1.1  riastrad 	if (gate) {
   1629  1.1  riastrad 		if (pi->caps_uvd_pg) {
   1630  1.1  riastrad 			uvd_v1_0_stop(rdev);
   1631  1.1  riastrad 			cik_update_cg(rdev, RADEON_CG_BLOCK_UVD, false);
   1632  1.1  riastrad 		}
   1633  1.1  riastrad 		kv_update_uvd_dpm(rdev, gate);
   1634  1.1  riastrad 		if (pi->caps_uvd_pg)
   1635  1.1  riastrad 			kv_notify_message_to_smu(rdev, PPSMC_MSG_UVDPowerOFF);
   1636  1.1  riastrad 	} else {
   1637  1.1  riastrad 		if (pi->caps_uvd_pg) {
   1638  1.1  riastrad 			kv_notify_message_to_smu(rdev, PPSMC_MSG_UVDPowerON);
   1639  1.1  riastrad 			uvd_v4_2_resume(rdev);
   1640  1.1  riastrad 			uvd_v1_0_start(rdev);
   1641  1.1  riastrad 			cik_update_cg(rdev, RADEON_CG_BLOCK_UVD, true);
   1642  1.1  riastrad 		}
   1643  1.1  riastrad 		kv_update_uvd_dpm(rdev, gate);
   1644  1.1  riastrad 	}
   1645  1.1  riastrad }
   1646  1.1  riastrad 
   1647  1.1  riastrad static void kv_dpm_powergate_vce(struct radeon_device *rdev, bool gate)
   1648  1.1  riastrad {
   1649  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   1650  1.1  riastrad 
   1651  1.1  riastrad 	if (pi->vce_power_gated == gate)
   1652  1.1  riastrad 		return;
   1653  1.1  riastrad 
   1654  1.1  riastrad 	pi->vce_power_gated = gate;
   1655  1.1  riastrad 
   1656  1.1  riastrad 	if (gate) {
   1657  1.1  riastrad 		if (pi->caps_vce_pg) {
   1658  1.1  riastrad 			/* XXX do we need a vce_v1_0_stop() ?  */
   1659  1.1  riastrad 			kv_notify_message_to_smu(rdev, PPSMC_MSG_VCEPowerOFF);
   1660  1.1  riastrad 		}
   1661  1.1  riastrad 	} else {
   1662  1.1  riastrad 		if (pi->caps_vce_pg) {
   1663  1.1  riastrad 			kv_notify_message_to_smu(rdev, PPSMC_MSG_VCEPowerON);
   1664  1.1  riastrad 			vce_v2_0_resume(rdev);
   1665  1.1  riastrad 			vce_v1_0_start(rdev);
   1666  1.1  riastrad 		}
   1667  1.1  riastrad 	}
   1668  1.1  riastrad }
   1669  1.1  riastrad 
   1670  1.1  riastrad static void kv_dpm_powergate_samu(struct radeon_device *rdev, bool gate)
   1671  1.1  riastrad {
   1672  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   1673  1.1  riastrad 
   1674  1.1  riastrad 	if (pi->samu_power_gated == gate)
   1675  1.1  riastrad 		return;
   1676  1.1  riastrad 
   1677  1.1  riastrad 	pi->samu_power_gated = gate;
   1678  1.1  riastrad 
   1679  1.1  riastrad 	if (gate) {
   1680  1.1  riastrad 		kv_update_samu_dpm(rdev, true);
   1681  1.1  riastrad 		if (pi->caps_samu_pg)
   1682  1.1  riastrad 			kv_notify_message_to_smu(rdev, PPSMC_MSG_SAMPowerOFF);
   1683  1.1  riastrad 	} else {
   1684  1.1  riastrad 		if (pi->caps_samu_pg)
   1685  1.1  riastrad 			kv_notify_message_to_smu(rdev, PPSMC_MSG_SAMPowerON);
   1686  1.1  riastrad 		kv_update_samu_dpm(rdev, false);
   1687  1.1  riastrad 	}
   1688  1.1  riastrad }
   1689  1.1  riastrad 
   1690  1.1  riastrad static void kv_dpm_powergate_acp(struct radeon_device *rdev, bool gate)
   1691  1.1  riastrad {
   1692  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   1693  1.1  riastrad 
   1694  1.1  riastrad 	if (pi->acp_power_gated == gate)
   1695  1.1  riastrad 		return;
   1696  1.1  riastrad 
   1697  1.1  riastrad 	if (rdev->family == CHIP_KABINI || rdev->family == CHIP_MULLINS)
   1698  1.1  riastrad 		return;
   1699  1.1  riastrad 
   1700  1.1  riastrad 	pi->acp_power_gated = gate;
   1701  1.1  riastrad 
   1702  1.1  riastrad 	if (gate) {
   1703  1.1  riastrad 		kv_update_acp_dpm(rdev, true);
   1704  1.1  riastrad 		if (pi->caps_acp_pg)
   1705  1.1  riastrad 			kv_notify_message_to_smu(rdev, PPSMC_MSG_ACPPowerOFF);
   1706  1.1  riastrad 	} else {
   1707  1.1  riastrad 		if (pi->caps_acp_pg)
   1708  1.1  riastrad 			kv_notify_message_to_smu(rdev, PPSMC_MSG_ACPPowerON);
   1709  1.1  riastrad 		kv_update_acp_dpm(rdev, false);
   1710  1.1  riastrad 	}
   1711  1.1  riastrad }
   1712  1.1  riastrad 
   1713  1.1  riastrad static void kv_set_valid_clock_range(struct radeon_device *rdev,
   1714  1.1  riastrad 				     struct radeon_ps *new_rps)
   1715  1.1  riastrad {
   1716  1.1  riastrad 	struct kv_ps *new_ps = kv_get_ps(new_rps);
   1717  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   1718  1.1  riastrad 	u32 i;
   1719  1.1  riastrad 	struct radeon_clock_voltage_dependency_table *table =
   1720  1.1  riastrad 		&rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk;
   1721  1.1  riastrad 
   1722  1.1  riastrad 	if (table && table->count) {
   1723  1.1  riastrad 		for (i = 0; i < pi->graphics_dpm_level_count; i++) {
   1724  1.1  riastrad 			if ((table->entries[i].clk >= new_ps->levels[0].sclk) ||
   1725  1.1  riastrad 			    (i == (pi->graphics_dpm_level_count - 1))) {
   1726  1.1  riastrad 				pi->lowest_valid = i;
   1727  1.1  riastrad 				break;
   1728  1.1  riastrad 			}
   1729  1.1  riastrad 		}
   1730  1.1  riastrad 
   1731  1.1  riastrad 		for (i = pi->graphics_dpm_level_count - 1; i > 0; i--) {
   1732  1.1  riastrad 			if (table->entries[i].clk <= new_ps->levels[new_ps->num_levels - 1].sclk)
   1733  1.1  riastrad 				break;
   1734  1.1  riastrad 		}
   1735  1.1  riastrad 		pi->highest_valid = i;
   1736  1.1  riastrad 
   1737  1.1  riastrad 		if (pi->lowest_valid > pi->highest_valid) {
   1738  1.1  riastrad 			if ((new_ps->levels[0].sclk - table->entries[pi->highest_valid].clk) >
   1739  1.1  riastrad 			    (table->entries[pi->lowest_valid].clk - new_ps->levels[new_ps->num_levels - 1].sclk))
   1740  1.1  riastrad 				pi->highest_valid = pi->lowest_valid;
   1741  1.1  riastrad 			else
   1742  1.1  riastrad 				pi->lowest_valid =  pi->highest_valid;
   1743  1.1  riastrad 		}
   1744  1.1  riastrad 	} else {
   1745  1.1  riastrad 		struct sumo_sclk_voltage_mapping_table *table =
   1746  1.1  riastrad 			&pi->sys_info.sclk_voltage_mapping_table;
   1747  1.1  riastrad 
   1748  1.1  riastrad 		for (i = 0; i < (int)pi->graphics_dpm_level_count; i++) {
   1749  1.1  riastrad 			if (table->entries[i].sclk_frequency >= new_ps->levels[0].sclk ||
   1750  1.1  riastrad 			    i == (int)(pi->graphics_dpm_level_count - 1)) {
   1751  1.1  riastrad 				pi->lowest_valid = i;
   1752  1.1  riastrad 				break;
   1753  1.1  riastrad 			}
   1754  1.1  riastrad 		}
   1755  1.1  riastrad 
   1756  1.1  riastrad 		for (i = pi->graphics_dpm_level_count - 1; i > 0; i--) {
   1757  1.1  riastrad 			if (table->entries[i].sclk_frequency <=
   1758  1.1  riastrad 			    new_ps->levels[new_ps->num_levels - 1].sclk)
   1759  1.1  riastrad 				break;
   1760  1.1  riastrad 		}
   1761  1.1  riastrad 		pi->highest_valid = i;
   1762  1.1  riastrad 
   1763  1.1  riastrad 		if (pi->lowest_valid > pi->highest_valid) {
   1764  1.1  riastrad 			if ((new_ps->levels[0].sclk -
   1765  1.1  riastrad 			     table->entries[pi->highest_valid].sclk_frequency) >
   1766  1.1  riastrad 			    (table->entries[pi->lowest_valid].sclk_frequency -
   1767  1.1  riastrad 			     new_ps->levels[new_ps->num_levels -1].sclk))
   1768  1.1  riastrad 				pi->highest_valid = pi->lowest_valid;
   1769  1.1  riastrad 			else
   1770  1.1  riastrad 				pi->lowest_valid =  pi->highest_valid;
   1771  1.1  riastrad 		}
   1772  1.1  riastrad 	}
   1773  1.1  riastrad }
   1774  1.1  riastrad 
   1775  1.1  riastrad static int kv_update_dfs_bypass_settings(struct radeon_device *rdev,
   1776  1.1  riastrad 					 struct radeon_ps *new_rps)
   1777  1.1  riastrad {
   1778  1.1  riastrad 	struct kv_ps *new_ps = kv_get_ps(new_rps);
   1779  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   1780  1.1  riastrad 	int ret = 0;
   1781  1.1  riastrad 	u8 clk_bypass_cntl;
   1782  1.1  riastrad 
   1783  1.1  riastrad 	if (pi->caps_enable_dfs_bypass) {
   1784  1.1  riastrad 		clk_bypass_cntl = new_ps->need_dfs_bypass ?
   1785  1.1  riastrad 			pi->graphics_level[pi->graphics_boot_level].ClkBypassCntl : 0;
   1786  1.1  riastrad 		ret = kv_copy_bytes_to_smc(rdev,
   1787  1.1  riastrad 					   (pi->dpm_table_start +
   1788  1.1  riastrad 					    offsetof(SMU7_Fusion_DpmTable, GraphicsLevel) +
   1789  1.1  riastrad 					    (pi->graphics_boot_level * sizeof(SMU7_Fusion_GraphicsLevel)) +
   1790  1.1  riastrad 					    offsetof(SMU7_Fusion_GraphicsLevel, ClkBypassCntl)),
   1791  1.1  riastrad 					   &clk_bypass_cntl,
   1792  1.1  riastrad 					   sizeof(u8), pi->sram_end);
   1793  1.1  riastrad 	}
   1794  1.1  riastrad 
   1795  1.1  riastrad 	return ret;
   1796  1.1  riastrad }
   1797  1.1  riastrad 
   1798  1.1  riastrad static int kv_enable_nb_dpm(struct radeon_device *rdev,
   1799  1.1  riastrad 			    bool enable)
   1800  1.1  riastrad {
   1801  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   1802  1.1  riastrad 	int ret = 0;
   1803  1.1  riastrad 
   1804  1.1  riastrad 	if (enable) {
   1805  1.1  riastrad 		if (pi->enable_nb_dpm && !pi->nb_dpm_enabled) {
   1806  1.1  riastrad 			ret = kv_notify_message_to_smu(rdev, PPSMC_MSG_NBDPM_Enable);
   1807  1.1  riastrad 			if (ret == 0)
   1808  1.1  riastrad 				pi->nb_dpm_enabled = true;
   1809  1.1  riastrad 		}
   1810  1.1  riastrad 	} else {
   1811  1.1  riastrad 		if (pi->enable_nb_dpm && pi->nb_dpm_enabled) {
   1812  1.1  riastrad 			ret = kv_notify_message_to_smu(rdev, PPSMC_MSG_NBDPM_Disable);
   1813  1.1  riastrad 			if (ret == 0)
   1814  1.1  riastrad 				pi->nb_dpm_enabled = false;
   1815  1.1  riastrad 		}
   1816  1.1  riastrad 	}
   1817  1.1  riastrad 
   1818  1.1  riastrad 	return ret;
   1819  1.1  riastrad }
   1820  1.1  riastrad 
   1821  1.1  riastrad int kv_dpm_force_performance_level(struct radeon_device *rdev,
   1822  1.1  riastrad 				   enum radeon_dpm_forced_level level)
   1823  1.1  riastrad {
   1824  1.1  riastrad 	int ret;
   1825  1.1  riastrad 
   1826  1.1  riastrad 	if (level == RADEON_DPM_FORCED_LEVEL_HIGH) {
   1827  1.1  riastrad 		ret = kv_force_dpm_highest(rdev);
   1828  1.1  riastrad 		if (ret)
   1829  1.1  riastrad 			return ret;
   1830  1.1  riastrad 	} else if (level == RADEON_DPM_FORCED_LEVEL_LOW) {
   1831  1.1  riastrad 		ret = kv_force_dpm_lowest(rdev);
   1832  1.1  riastrad 		if (ret)
   1833  1.1  riastrad 			return ret;
   1834  1.1  riastrad 	} else if (level == RADEON_DPM_FORCED_LEVEL_AUTO) {
   1835  1.1  riastrad 		ret = kv_unforce_levels(rdev);
   1836  1.1  riastrad 		if (ret)
   1837  1.1  riastrad 			return ret;
   1838  1.1  riastrad 	}
   1839  1.1  riastrad 
   1840  1.1  riastrad 	rdev->pm.dpm.forced_level = level;
   1841  1.1  riastrad 
   1842  1.1  riastrad 	return 0;
   1843  1.1  riastrad }
   1844  1.1  riastrad 
   1845  1.1  riastrad int kv_dpm_pre_set_power_state(struct radeon_device *rdev)
   1846  1.1  riastrad {
   1847  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   1848  1.1  riastrad 	struct radeon_ps requested_ps = *rdev->pm.dpm.requested_ps;
   1849  1.1  riastrad 	struct radeon_ps *new_ps = &requested_ps;
   1850  1.1  riastrad 
   1851  1.1  riastrad 	kv_update_requested_ps(rdev, new_ps);
   1852  1.1  riastrad 
   1853  1.1  riastrad 	kv_apply_state_adjust_rules(rdev,
   1854  1.1  riastrad 				    &pi->requested_rps,
   1855  1.1  riastrad 				    &pi->current_rps);
   1856  1.1  riastrad 
   1857  1.1  riastrad 	return 0;
   1858  1.1  riastrad }
   1859  1.1  riastrad 
   1860  1.1  riastrad int kv_dpm_set_power_state(struct radeon_device *rdev)
   1861  1.1  riastrad {
   1862  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   1863  1.1  riastrad 	struct radeon_ps *new_ps = &pi->requested_rps;
   1864  1.1  riastrad 	struct radeon_ps *old_ps = &pi->current_rps;
   1865  1.1  riastrad 	int ret;
   1866  1.1  riastrad 
   1867  1.1  riastrad 	if (pi->bapm_enable) {
   1868  1.1  riastrad 		ret = kv_smc_bapm_enable(rdev, rdev->pm.dpm.ac_power);
   1869  1.1  riastrad 		if (ret) {
   1870  1.1  riastrad 			DRM_ERROR("kv_smc_bapm_enable failed\n");
   1871  1.1  riastrad 			return ret;
   1872  1.1  riastrad 		}
   1873  1.1  riastrad 	}
   1874  1.1  riastrad 
   1875  1.1  riastrad 	if (rdev->family == CHIP_KABINI || rdev->family == CHIP_MULLINS) {
   1876  1.1  riastrad 		if (pi->enable_dpm) {
   1877  1.1  riastrad 			kv_set_valid_clock_range(rdev, new_ps);
   1878  1.1  riastrad 			kv_update_dfs_bypass_settings(rdev, new_ps);
   1879  1.1  riastrad 			ret = kv_calculate_ds_divider(rdev);
   1880  1.1  riastrad 			if (ret) {
   1881  1.1  riastrad 				DRM_ERROR("kv_calculate_ds_divider failed\n");
   1882  1.1  riastrad 				return ret;
   1883  1.1  riastrad 			}
   1884  1.1  riastrad 			kv_calculate_nbps_level_settings(rdev);
   1885  1.1  riastrad 			kv_calculate_dpm_settings(rdev);
   1886  1.1  riastrad 			kv_force_lowest_valid(rdev);
   1887  1.1  riastrad 			kv_enable_new_levels(rdev);
   1888  1.1  riastrad 			kv_upload_dpm_settings(rdev);
   1889  1.1  riastrad 			kv_program_nbps_index_settings(rdev, new_ps);
   1890  1.1  riastrad 			kv_unforce_levels(rdev);
   1891  1.1  riastrad 			kv_set_enabled_levels(rdev);
   1892  1.1  riastrad 			kv_force_lowest_valid(rdev);
   1893  1.1  riastrad 			kv_unforce_levels(rdev);
   1894  1.1  riastrad 
   1895  1.1  riastrad 			ret = kv_update_vce_dpm(rdev, new_ps, old_ps);
   1896  1.1  riastrad 			if (ret) {
   1897  1.1  riastrad 				DRM_ERROR("kv_update_vce_dpm failed\n");
   1898  1.1  riastrad 				return ret;
   1899  1.1  riastrad 			}
   1900  1.1  riastrad 			kv_update_sclk_t(rdev);
   1901  1.1  riastrad 			if (rdev->family == CHIP_MULLINS)
   1902  1.1  riastrad 				kv_enable_nb_dpm(rdev, true);
   1903  1.1  riastrad 		}
   1904  1.1  riastrad 	} else {
   1905  1.1  riastrad 		if (pi->enable_dpm) {
   1906  1.1  riastrad 			kv_set_valid_clock_range(rdev, new_ps);
   1907  1.1  riastrad 			kv_update_dfs_bypass_settings(rdev, new_ps);
   1908  1.1  riastrad 			ret = kv_calculate_ds_divider(rdev);
   1909  1.1  riastrad 			if (ret) {
   1910  1.1  riastrad 				DRM_ERROR("kv_calculate_ds_divider failed\n");
   1911  1.1  riastrad 				return ret;
   1912  1.1  riastrad 			}
   1913  1.1  riastrad 			kv_calculate_nbps_level_settings(rdev);
   1914  1.1  riastrad 			kv_calculate_dpm_settings(rdev);
   1915  1.1  riastrad 			kv_freeze_sclk_dpm(rdev, true);
   1916  1.1  riastrad 			kv_upload_dpm_settings(rdev);
   1917  1.1  riastrad 			kv_program_nbps_index_settings(rdev, new_ps);
   1918  1.1  riastrad 			kv_freeze_sclk_dpm(rdev, false);
   1919  1.1  riastrad 			kv_set_enabled_levels(rdev);
   1920  1.1  riastrad 			ret = kv_update_vce_dpm(rdev, new_ps, old_ps);
   1921  1.1  riastrad 			if (ret) {
   1922  1.1  riastrad 				DRM_ERROR("kv_update_vce_dpm failed\n");
   1923  1.1  riastrad 				return ret;
   1924  1.1  riastrad 			}
   1925  1.1  riastrad 			kv_update_acp_boot_level(rdev);
   1926  1.1  riastrad 			kv_update_sclk_t(rdev);
   1927  1.1  riastrad 			kv_enable_nb_dpm(rdev, true);
   1928  1.1  riastrad 		}
   1929  1.1  riastrad 	}
   1930  1.1  riastrad 
   1931  1.1  riastrad 	return 0;
   1932  1.1  riastrad }
   1933  1.1  riastrad 
   1934  1.1  riastrad void kv_dpm_post_set_power_state(struct radeon_device *rdev)
   1935  1.1  riastrad {
   1936  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   1937  1.1  riastrad 	struct radeon_ps *new_ps = &pi->requested_rps;
   1938  1.1  riastrad 
   1939  1.1  riastrad 	kv_update_current_ps(rdev, new_ps);
   1940  1.1  riastrad }
   1941  1.1  riastrad 
   1942  1.1  riastrad void kv_dpm_setup_asic(struct radeon_device *rdev)
   1943  1.1  riastrad {
   1944  1.1  riastrad 	sumo_take_smu_control(rdev, true);
   1945  1.1  riastrad 	kv_init_powergate_state(rdev);
   1946  1.1  riastrad 	kv_init_sclk_t(rdev);
   1947  1.1  riastrad }
   1948  1.1  riastrad 
   1949  1.1  riastrad #if 0
   1950  1.1  riastrad void kv_dpm_reset_asic(struct radeon_device *rdev)
   1951  1.1  riastrad {
   1952  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   1953  1.1  riastrad 
   1954  1.1  riastrad 	if (rdev->family == CHIP_KABINI || rdev->family == CHIP_MULLINS) {
   1955  1.1  riastrad 		kv_force_lowest_valid(rdev);
   1956  1.1  riastrad 		kv_init_graphics_levels(rdev);
   1957  1.1  riastrad 		kv_program_bootup_state(rdev);
   1958  1.1  riastrad 		kv_upload_dpm_settings(rdev);
   1959  1.1  riastrad 		kv_force_lowest_valid(rdev);
   1960  1.1  riastrad 		kv_unforce_levels(rdev);
   1961  1.1  riastrad 	} else {
   1962  1.1  riastrad 		kv_init_graphics_levels(rdev);
   1963  1.1  riastrad 		kv_program_bootup_state(rdev);
   1964  1.1  riastrad 		kv_freeze_sclk_dpm(rdev, true);
   1965  1.1  riastrad 		kv_upload_dpm_settings(rdev);
   1966  1.1  riastrad 		kv_freeze_sclk_dpm(rdev, false);
   1967  1.1  riastrad 		kv_set_enabled_level(rdev, pi->graphics_boot_level);
   1968  1.1  riastrad 	}
   1969  1.1  riastrad }
   1970  1.1  riastrad #endif
   1971  1.1  riastrad 
   1972  1.1  riastrad //XXX use sumo_dpm_display_configuration_changed
   1973  1.1  riastrad 
   1974  1.1  riastrad static void kv_construct_max_power_limits_table(struct radeon_device *rdev,
   1975  1.1  riastrad 						struct radeon_clock_and_voltage_limits *table)
   1976  1.1  riastrad {
   1977  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   1978  1.1  riastrad 
   1979  1.1  riastrad 	if (pi->sys_info.sclk_voltage_mapping_table.num_max_dpm_entries > 0) {
   1980  1.1  riastrad 		int idx = pi->sys_info.sclk_voltage_mapping_table.num_max_dpm_entries - 1;
   1981  1.1  riastrad 		table->sclk =
   1982  1.1  riastrad 			pi->sys_info.sclk_voltage_mapping_table.entries[idx].sclk_frequency;
   1983  1.1  riastrad 		table->vddc =
   1984  1.1  riastrad 			kv_convert_2bit_index_to_voltage(rdev,
   1985  1.1  riastrad 							 pi->sys_info.sclk_voltage_mapping_table.entries[idx].vid_2bit);
   1986  1.1  riastrad 	}
   1987  1.1  riastrad 
   1988  1.1  riastrad 	table->mclk = pi->sys_info.nbp_memory_clock[0];
   1989  1.1  riastrad }
   1990  1.1  riastrad 
   1991  1.1  riastrad static void kv_patch_voltage_values(struct radeon_device *rdev)
   1992  1.1  riastrad {
   1993  1.1  riastrad 	int i;
   1994  1.1  riastrad 	struct radeon_uvd_clock_voltage_dependency_table *uvd_table =
   1995  1.1  riastrad 		&rdev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table;
   1996  1.1  riastrad 	struct radeon_vce_clock_voltage_dependency_table *vce_table =
   1997  1.1  riastrad 		&rdev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table;
   1998  1.1  riastrad 	struct radeon_clock_voltage_dependency_table *samu_table =
   1999  1.1  riastrad 		&rdev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table;
   2000  1.1  riastrad 	struct radeon_clock_voltage_dependency_table *acp_table =
   2001  1.1  riastrad 		&rdev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table;
   2002  1.1  riastrad 
   2003  1.1  riastrad 	if (uvd_table->count) {
   2004  1.1  riastrad 		for (i = 0; i < uvd_table->count; i++)
   2005  1.1  riastrad 			uvd_table->entries[i].v =
   2006  1.1  riastrad 				kv_convert_8bit_index_to_voltage(rdev,
   2007  1.1  riastrad 								 uvd_table->entries[i].v);
   2008  1.1  riastrad 	}
   2009  1.1  riastrad 
   2010  1.1  riastrad 	if (vce_table->count) {
   2011  1.1  riastrad 		for (i = 0; i < vce_table->count; i++)
   2012  1.1  riastrad 			vce_table->entries[i].v =
   2013  1.1  riastrad 				kv_convert_8bit_index_to_voltage(rdev,
   2014  1.1  riastrad 								 vce_table->entries[i].v);
   2015  1.1  riastrad 	}
   2016  1.1  riastrad 
   2017  1.1  riastrad 	if (samu_table->count) {
   2018  1.1  riastrad 		for (i = 0; i < samu_table->count; i++)
   2019  1.1  riastrad 			samu_table->entries[i].v =
   2020  1.1  riastrad 				kv_convert_8bit_index_to_voltage(rdev,
   2021  1.1  riastrad 								 samu_table->entries[i].v);
   2022  1.1  riastrad 	}
   2023  1.1  riastrad 
   2024  1.1  riastrad 	if (acp_table->count) {
   2025  1.1  riastrad 		for (i = 0; i < acp_table->count; i++)
   2026  1.1  riastrad 			acp_table->entries[i].v =
   2027  1.1  riastrad 				kv_convert_8bit_index_to_voltage(rdev,
   2028  1.1  riastrad 								 acp_table->entries[i].v);
   2029  1.1  riastrad 	}
   2030  1.1  riastrad 
   2031  1.1  riastrad }
   2032  1.1  riastrad 
   2033  1.1  riastrad static void kv_construct_boot_state(struct radeon_device *rdev)
   2034  1.1  riastrad {
   2035  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   2036  1.1  riastrad 
   2037  1.1  riastrad 	pi->boot_pl.sclk = pi->sys_info.bootup_sclk;
   2038  1.1  riastrad 	pi->boot_pl.vddc_index = pi->sys_info.bootup_nb_voltage_index;
   2039  1.1  riastrad 	pi->boot_pl.ds_divider_index = 0;
   2040  1.1  riastrad 	pi->boot_pl.ss_divider_index = 0;
   2041  1.1  riastrad 	pi->boot_pl.allow_gnb_slow = 1;
   2042  1.1  riastrad 	pi->boot_pl.force_nbp_state = 0;
   2043  1.1  riastrad 	pi->boot_pl.display_wm = 0;
   2044  1.1  riastrad 	pi->boot_pl.vce_wm = 0;
   2045  1.1  riastrad }
   2046  1.1  riastrad 
   2047  1.1  riastrad static int kv_force_dpm_highest(struct radeon_device *rdev)
   2048  1.1  riastrad {
   2049  1.1  riastrad 	int ret;
   2050  1.1  riastrad 	u32 enable_mask, i;
   2051  1.1  riastrad 
   2052  1.1  riastrad 	ret = kv_dpm_get_enable_mask(rdev, &enable_mask);
   2053  1.1  riastrad 	if (ret)
   2054  1.1  riastrad 		return ret;
   2055  1.1  riastrad 
   2056  1.1  riastrad 	for (i = SMU7_MAX_LEVELS_GRAPHICS - 1; i > 0; i--) {
   2057  1.1  riastrad 		if (enable_mask & (1 << i))
   2058  1.1  riastrad 			break;
   2059  1.1  riastrad 	}
   2060  1.1  riastrad 
   2061  1.1  riastrad 	if (rdev->family == CHIP_KABINI || rdev->family == CHIP_MULLINS)
   2062  1.1  riastrad 		return kv_send_msg_to_smc_with_parameter(rdev, PPSMC_MSG_DPM_ForceState, i);
   2063  1.1  riastrad 	else
   2064  1.1  riastrad 		return kv_set_enabled_level(rdev, i);
   2065  1.1  riastrad }
   2066  1.1  riastrad 
   2067  1.1  riastrad static int kv_force_dpm_lowest(struct radeon_device *rdev)
   2068  1.1  riastrad {
   2069  1.1  riastrad 	int ret;
   2070  1.1  riastrad 	u32 enable_mask, i;
   2071  1.1  riastrad 
   2072  1.1  riastrad 	ret = kv_dpm_get_enable_mask(rdev, &enable_mask);
   2073  1.1  riastrad 	if (ret)
   2074  1.1  riastrad 		return ret;
   2075  1.1  riastrad 
   2076  1.1  riastrad 	for (i = 0; i < SMU7_MAX_LEVELS_GRAPHICS; i++) {
   2077  1.1  riastrad 		if (enable_mask & (1 << i))
   2078  1.1  riastrad 			break;
   2079  1.1  riastrad 	}
   2080  1.1  riastrad 
   2081  1.1  riastrad 	if (rdev->family == CHIP_KABINI || rdev->family == CHIP_MULLINS)
   2082  1.1  riastrad 		return kv_send_msg_to_smc_with_parameter(rdev, PPSMC_MSG_DPM_ForceState, i);
   2083  1.1  riastrad 	else
   2084  1.1  riastrad 		return kv_set_enabled_level(rdev, i);
   2085  1.1  riastrad }
   2086  1.1  riastrad 
   2087  1.1  riastrad static u8 kv_get_sleep_divider_id_from_clock(struct radeon_device *rdev,
   2088  1.1  riastrad 					     u32 sclk, u32 min_sclk_in_sr)
   2089  1.1  riastrad {
   2090  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   2091  1.1  riastrad 	u32 i;
   2092  1.1  riastrad 	u32 temp;
   2093  1.1  riastrad 	u32 min = (min_sclk_in_sr > KV_MINIMUM_ENGINE_CLOCK) ?
   2094  1.1  riastrad 		min_sclk_in_sr : KV_MINIMUM_ENGINE_CLOCK;
   2095  1.1  riastrad 
   2096  1.1  riastrad 	if (sclk < min)
   2097  1.1  riastrad 		return 0;
   2098  1.1  riastrad 
   2099  1.1  riastrad 	if (!pi->caps_sclk_ds)
   2100  1.1  riastrad 		return 0;
   2101  1.1  riastrad 
   2102  1.1  riastrad 	for (i = KV_MAX_DEEPSLEEP_DIVIDER_ID; i > 0; i--) {
   2103  1.1  riastrad 		temp = sclk / sumo_get_sleep_divider_from_id(i);
   2104  1.1  riastrad 		if (temp >= min)
   2105  1.1  riastrad 			break;
   2106  1.1  riastrad 	}
   2107  1.1  riastrad 
   2108  1.1  riastrad 	return (u8)i;
   2109  1.1  riastrad }
   2110  1.1  riastrad 
   2111  1.1  riastrad static int kv_get_high_voltage_limit(struct radeon_device *rdev, int *limit)
   2112  1.1  riastrad {
   2113  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   2114  1.1  riastrad 	struct radeon_clock_voltage_dependency_table *table =
   2115  1.1  riastrad 		&rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk;
   2116  1.1  riastrad 	int i;
   2117  1.1  riastrad 
   2118  1.1  riastrad 	if (table && table->count) {
   2119  1.1  riastrad 		for (i = table->count - 1; i >= 0; i--) {
   2120  1.1  riastrad 			if (pi->high_voltage_t &&
   2121  1.1  riastrad 			    (kv_convert_8bit_index_to_voltage(rdev, table->entries[i].v) <=
   2122  1.1  riastrad 			     pi->high_voltage_t)) {
   2123  1.1  riastrad 				*limit = i;
   2124  1.1  riastrad 				return 0;
   2125  1.1  riastrad 			}
   2126  1.1  riastrad 		}
   2127  1.1  riastrad 	} else {
   2128  1.1  riastrad 		struct sumo_sclk_voltage_mapping_table *table =
   2129  1.1  riastrad 			&pi->sys_info.sclk_voltage_mapping_table;
   2130  1.1  riastrad 
   2131  1.1  riastrad 		for (i = table->num_max_dpm_entries - 1; i >= 0; i--) {
   2132  1.1  riastrad 			if (pi->high_voltage_t &&
   2133  1.1  riastrad 			    (kv_convert_2bit_index_to_voltage(rdev, table->entries[i].vid_2bit) <=
   2134  1.1  riastrad 			     pi->high_voltage_t)) {
   2135  1.1  riastrad 				*limit = i;
   2136  1.1  riastrad 				return 0;
   2137  1.1  riastrad 			}
   2138  1.1  riastrad 		}
   2139  1.1  riastrad 	}
   2140  1.1  riastrad 
   2141  1.1  riastrad 	*limit = 0;
   2142  1.1  riastrad 	return 0;
   2143  1.1  riastrad }
   2144  1.1  riastrad 
   2145  1.1  riastrad static void kv_apply_state_adjust_rules(struct radeon_device *rdev,
   2146  1.1  riastrad 					struct radeon_ps *new_rps,
   2147  1.1  riastrad 					struct radeon_ps *old_rps)
   2148  1.1  riastrad {
   2149  1.1  riastrad 	struct kv_ps *ps = kv_get_ps(new_rps);
   2150  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   2151  1.1  riastrad 	u32 min_sclk = 10000; /* ??? */
   2152  1.1  riastrad 	u32 sclk, mclk = 0;
   2153  1.1  riastrad 	int i, limit;
   2154  1.1  riastrad 	bool force_high;
   2155  1.1  riastrad 	struct radeon_clock_voltage_dependency_table *table =
   2156  1.1  riastrad 		&rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk;
   2157  1.1  riastrad 	u32 stable_p_state_sclk = 0;
   2158  1.1  riastrad 	struct radeon_clock_and_voltage_limits *max_limits =
   2159  1.1  riastrad 		&rdev->pm.dpm.dyn_state.max_clock_voltage_on_ac;
   2160  1.1  riastrad 
   2161  1.1  riastrad 	if (new_rps->vce_active) {
   2162  1.1  riastrad 		new_rps->evclk = rdev->pm.dpm.vce_states[rdev->pm.dpm.vce_level].evclk;
   2163  1.1  riastrad 		new_rps->ecclk = rdev->pm.dpm.vce_states[rdev->pm.dpm.vce_level].ecclk;
   2164  1.1  riastrad 	} else {
   2165  1.1  riastrad 		new_rps->evclk = 0;
   2166  1.1  riastrad 		new_rps->ecclk = 0;
   2167  1.1  riastrad 	}
   2168  1.1  riastrad 
   2169  1.1  riastrad 	mclk = max_limits->mclk;
   2170  1.1  riastrad 	sclk = min_sclk;
   2171  1.1  riastrad 
   2172  1.1  riastrad 	if (pi->caps_stable_p_state) {
   2173  1.1  riastrad 		stable_p_state_sclk = (max_limits->sclk * 75) / 100;
   2174  1.1  riastrad 
   2175  1.2  riastrad 		for (i = table->count - 1; i >= 0; i--) {
   2176  1.1  riastrad 			if (stable_p_state_sclk >= table->entries[i].clk) {
   2177  1.1  riastrad 				stable_p_state_sclk = table->entries[i].clk;
   2178  1.1  riastrad 				break;
   2179  1.1  riastrad 			}
   2180  1.1  riastrad 		}
   2181  1.1  riastrad 
   2182  1.1  riastrad 		if (i > 0)
   2183  1.1  riastrad 			stable_p_state_sclk = table->entries[0].clk;
   2184  1.1  riastrad 
   2185  1.1  riastrad 		sclk = stable_p_state_sclk;
   2186  1.1  riastrad 	}
   2187  1.1  riastrad 
   2188  1.1  riastrad 	if (new_rps->vce_active) {
   2189  1.1  riastrad 		if (sclk < rdev->pm.dpm.vce_states[rdev->pm.dpm.vce_level].sclk)
   2190  1.1  riastrad 			sclk = rdev->pm.dpm.vce_states[rdev->pm.dpm.vce_level].sclk;
   2191  1.1  riastrad 	}
   2192  1.1  riastrad 
   2193  1.1  riastrad 	ps->need_dfs_bypass = true;
   2194  1.1  riastrad 
   2195  1.1  riastrad 	for (i = 0; i < ps->num_levels; i++) {
   2196  1.1  riastrad 		if (ps->levels[i].sclk < sclk)
   2197  1.1  riastrad 			ps->levels[i].sclk = sclk;
   2198  1.1  riastrad 	}
   2199  1.1  riastrad 
   2200  1.1  riastrad 	if (table && table->count) {
   2201  1.1  riastrad 		for (i = 0; i < ps->num_levels; i++) {
   2202  1.1  riastrad 			if (pi->high_voltage_t &&
   2203  1.1  riastrad 			    (pi->high_voltage_t <
   2204  1.1  riastrad 			     kv_convert_8bit_index_to_voltage(rdev, ps->levels[i].vddc_index))) {
   2205  1.1  riastrad 				kv_get_high_voltage_limit(rdev, &limit);
   2206  1.1  riastrad 				ps->levels[i].sclk = table->entries[limit].clk;
   2207  1.1  riastrad 			}
   2208  1.1  riastrad 		}
   2209  1.1  riastrad 	} else {
   2210  1.1  riastrad 		struct sumo_sclk_voltage_mapping_table *table =
   2211  1.1  riastrad 			&pi->sys_info.sclk_voltage_mapping_table;
   2212  1.1  riastrad 
   2213  1.1  riastrad 		for (i = 0; i < ps->num_levels; i++) {
   2214  1.1  riastrad 			if (pi->high_voltage_t &&
   2215  1.1  riastrad 			    (pi->high_voltage_t <
   2216  1.1  riastrad 			     kv_convert_8bit_index_to_voltage(rdev, ps->levels[i].vddc_index))) {
   2217  1.1  riastrad 				kv_get_high_voltage_limit(rdev, &limit);
   2218  1.1  riastrad 				ps->levels[i].sclk = table->entries[limit].sclk_frequency;
   2219  1.1  riastrad 			}
   2220  1.1  riastrad 		}
   2221  1.1  riastrad 	}
   2222  1.1  riastrad 
   2223  1.1  riastrad 	if (pi->caps_stable_p_state) {
   2224  1.1  riastrad 		for (i = 0; i < ps->num_levels; i++) {
   2225  1.1  riastrad 			ps->levels[i].sclk = stable_p_state_sclk;
   2226  1.1  riastrad 		}
   2227  1.1  riastrad 	}
   2228  1.1  riastrad 
   2229  1.1  riastrad 	pi->video_start = new_rps->dclk || new_rps->vclk ||
   2230  1.1  riastrad 		new_rps->evclk || new_rps->ecclk;
   2231  1.1  riastrad 
   2232  1.1  riastrad 	if ((new_rps->class & ATOM_PPLIB_CLASSIFICATION_UI_MASK) ==
   2233  1.1  riastrad 	    ATOM_PPLIB_CLASSIFICATION_UI_BATTERY)
   2234  1.1  riastrad 		pi->battery_state = true;
   2235  1.1  riastrad 	else
   2236  1.1  riastrad 		pi->battery_state = false;
   2237  1.1  riastrad 
   2238  1.1  riastrad 	if (rdev->family == CHIP_KABINI || rdev->family == CHIP_MULLINS) {
   2239  1.1  riastrad 		ps->dpm0_pg_nb_ps_lo = 0x1;
   2240  1.1  riastrad 		ps->dpm0_pg_nb_ps_hi = 0x0;
   2241  1.1  riastrad 		ps->dpmx_nb_ps_lo = 0x1;
   2242  1.1  riastrad 		ps->dpmx_nb_ps_hi = 0x0;
   2243  1.1  riastrad 	} else {
   2244  1.1  riastrad 		ps->dpm0_pg_nb_ps_lo = 0x3;
   2245  1.1  riastrad 		ps->dpm0_pg_nb_ps_hi = 0x0;
   2246  1.1  riastrad 		ps->dpmx_nb_ps_lo = 0x3;
   2247  1.1  riastrad 		ps->dpmx_nb_ps_hi = 0x0;
   2248  1.1  riastrad 
   2249  1.1  riastrad 		if (pi->sys_info.nb_dpm_enable) {
   2250  1.1  riastrad 			force_high = (mclk >= pi->sys_info.nbp_memory_clock[3]) ||
   2251  1.1  riastrad 				pi->video_start || (rdev->pm.dpm.new_active_crtc_count >= 3) ||
   2252  1.1  riastrad 				pi->disable_nb_ps3_in_battery;
   2253  1.1  riastrad 			ps->dpm0_pg_nb_ps_lo = force_high ? 0x2 : 0x3;
   2254  1.1  riastrad 			ps->dpm0_pg_nb_ps_hi = 0x2;
   2255  1.1  riastrad 			ps->dpmx_nb_ps_lo = force_high ? 0x2 : 0x3;
   2256  1.1  riastrad 			ps->dpmx_nb_ps_hi = 0x2;
   2257  1.1  riastrad 		}
   2258  1.1  riastrad 	}
   2259  1.1  riastrad }
   2260  1.1  riastrad 
   2261  1.1  riastrad static void kv_dpm_power_level_enabled_for_throttle(struct radeon_device *rdev,
   2262  1.1  riastrad 						    u32 index, bool enable)
   2263  1.1  riastrad {
   2264  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   2265  1.1  riastrad 
   2266  1.1  riastrad 	pi->graphics_level[index].EnabledForThrottle = enable ? 1 : 0;
   2267  1.1  riastrad }
   2268  1.1  riastrad 
   2269  1.1  riastrad static int kv_calculate_ds_divider(struct radeon_device *rdev)
   2270  1.1  riastrad {
   2271  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   2272  1.1  riastrad 	u32 sclk_in_sr = 10000; /* ??? */
   2273  1.1  riastrad 	u32 i;
   2274  1.1  riastrad 
   2275  1.1  riastrad 	if (pi->lowest_valid > pi->highest_valid)
   2276  1.1  riastrad 		return -EINVAL;
   2277  1.1  riastrad 
   2278  1.1  riastrad 	for (i = pi->lowest_valid; i <= pi->highest_valid; i++) {
   2279  1.1  riastrad 		pi->graphics_level[i].DeepSleepDivId =
   2280  1.1  riastrad 			kv_get_sleep_divider_id_from_clock(rdev,
   2281  1.1  riastrad 							   be32_to_cpu(pi->graphics_level[i].SclkFrequency),
   2282  1.1  riastrad 							   sclk_in_sr);
   2283  1.1  riastrad 	}
   2284  1.1  riastrad 	return 0;
   2285  1.1  riastrad }
   2286  1.1  riastrad 
   2287  1.1  riastrad static int kv_calculate_nbps_level_settings(struct radeon_device *rdev)
   2288  1.1  riastrad {
   2289  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   2290  1.1  riastrad 	u32 i;
   2291  1.1  riastrad 	bool force_high;
   2292  1.1  riastrad 	struct radeon_clock_and_voltage_limits *max_limits =
   2293  1.1  riastrad 		&rdev->pm.dpm.dyn_state.max_clock_voltage_on_ac;
   2294  1.1  riastrad 	u32 mclk = max_limits->mclk;
   2295  1.1  riastrad 
   2296  1.1  riastrad 	if (pi->lowest_valid > pi->highest_valid)
   2297  1.1  riastrad 		return -EINVAL;
   2298  1.1  riastrad 
   2299  1.1  riastrad 	if (rdev->family == CHIP_KABINI || rdev->family == CHIP_MULLINS) {
   2300  1.1  riastrad 		for (i = pi->lowest_valid; i <= pi->highest_valid; i++) {
   2301  1.1  riastrad 			pi->graphics_level[i].GnbSlow = 1;
   2302  1.1  riastrad 			pi->graphics_level[i].ForceNbPs1 = 0;
   2303  1.1  riastrad 			pi->graphics_level[i].UpH = 0;
   2304  1.1  riastrad 		}
   2305  1.1  riastrad 
   2306  1.1  riastrad 		if (!pi->sys_info.nb_dpm_enable)
   2307  1.1  riastrad 			return 0;
   2308  1.1  riastrad 
   2309  1.1  riastrad 		force_high = ((mclk >= pi->sys_info.nbp_memory_clock[3]) ||
   2310  1.1  riastrad 			      (rdev->pm.dpm.new_active_crtc_count >= 3) || pi->video_start);
   2311  1.1  riastrad 
   2312  1.1  riastrad 		if (force_high) {
   2313  1.1  riastrad 			for (i = pi->lowest_valid; i <= pi->highest_valid; i++)
   2314  1.1  riastrad 				pi->graphics_level[i].GnbSlow = 0;
   2315  1.1  riastrad 		} else {
   2316  1.1  riastrad 			if (pi->battery_state)
   2317  1.1  riastrad 				pi->graphics_level[0].ForceNbPs1 = 1;
   2318  1.1  riastrad 
   2319  1.1  riastrad 			pi->graphics_level[1].GnbSlow = 0;
   2320  1.1  riastrad 			pi->graphics_level[2].GnbSlow = 0;
   2321  1.1  riastrad 			pi->graphics_level[3].GnbSlow = 0;
   2322  1.1  riastrad 			pi->graphics_level[4].GnbSlow = 0;
   2323  1.1  riastrad 		}
   2324  1.1  riastrad 	} else {
   2325  1.1  riastrad 		for (i = pi->lowest_valid; i <= pi->highest_valid; i++) {
   2326  1.1  riastrad 			pi->graphics_level[i].GnbSlow = 1;
   2327  1.1  riastrad 			pi->graphics_level[i].ForceNbPs1 = 0;
   2328  1.1  riastrad 			pi->graphics_level[i].UpH = 0;
   2329  1.1  riastrad 		}
   2330  1.1  riastrad 
   2331  1.1  riastrad 		if (pi->sys_info.nb_dpm_enable && pi->battery_state) {
   2332  1.1  riastrad 			pi->graphics_level[pi->lowest_valid].UpH = 0x28;
   2333  1.1  riastrad 			pi->graphics_level[pi->lowest_valid].GnbSlow = 0;
   2334  1.1  riastrad 			if (pi->lowest_valid != pi->highest_valid)
   2335  1.1  riastrad 				pi->graphics_level[pi->lowest_valid].ForceNbPs1 = 1;
   2336  1.1  riastrad 		}
   2337  1.1  riastrad 	}
   2338  1.1  riastrad 	return 0;
   2339  1.1  riastrad }
   2340  1.1  riastrad 
   2341  1.1  riastrad static int kv_calculate_dpm_settings(struct radeon_device *rdev)
   2342  1.1  riastrad {
   2343  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   2344  1.1  riastrad 	u32 i;
   2345  1.1  riastrad 
   2346  1.1  riastrad 	if (pi->lowest_valid > pi->highest_valid)
   2347  1.1  riastrad 		return -EINVAL;
   2348  1.1  riastrad 
   2349  1.1  riastrad 	for (i = pi->lowest_valid; i <= pi->highest_valid; i++)
   2350  1.1  riastrad 		pi->graphics_level[i].DisplayWatermark = (i == pi->highest_valid) ? 1 : 0;
   2351  1.1  riastrad 
   2352  1.1  riastrad 	return 0;
   2353  1.1  riastrad }
   2354  1.1  riastrad 
   2355  1.1  riastrad static void kv_init_graphics_levels(struct radeon_device *rdev)
   2356  1.1  riastrad {
   2357  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   2358  1.1  riastrad 	u32 i;
   2359  1.1  riastrad 	struct radeon_clock_voltage_dependency_table *table =
   2360  1.1  riastrad 		&rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk;
   2361  1.1  riastrad 
   2362  1.1  riastrad 	if (table && table->count) {
   2363  1.1  riastrad 		u32 vid_2bit;
   2364  1.1  riastrad 
   2365  1.1  riastrad 		pi->graphics_dpm_level_count = 0;
   2366  1.1  riastrad 		for (i = 0; i < table->count; i++) {
   2367  1.1  riastrad 			if (pi->high_voltage_t &&
   2368  1.1  riastrad 			    (pi->high_voltage_t <
   2369  1.1  riastrad 			     kv_convert_8bit_index_to_voltage(rdev, table->entries[i].v)))
   2370  1.1  riastrad 				break;
   2371  1.1  riastrad 
   2372  1.1  riastrad 			kv_set_divider_value(rdev, i, table->entries[i].clk);
   2373  1.1  riastrad 			vid_2bit = kv_convert_vid7_to_vid2(rdev,
   2374  1.1  riastrad 							   &pi->sys_info.vid_mapping_table,
   2375  1.1  riastrad 							   table->entries[i].v);
   2376  1.1  riastrad 			kv_set_vid(rdev, i, vid_2bit);
   2377  1.1  riastrad 			kv_set_at(rdev, i, pi->at[i]);
   2378  1.1  riastrad 			kv_dpm_power_level_enabled_for_throttle(rdev, i, true);
   2379  1.1  riastrad 			pi->graphics_dpm_level_count++;
   2380  1.1  riastrad 		}
   2381  1.1  riastrad 	} else {
   2382  1.1  riastrad 		struct sumo_sclk_voltage_mapping_table *table =
   2383  1.1  riastrad 			&pi->sys_info.sclk_voltage_mapping_table;
   2384  1.1  riastrad 
   2385  1.1  riastrad 		pi->graphics_dpm_level_count = 0;
   2386  1.1  riastrad 		for (i = 0; i < table->num_max_dpm_entries; i++) {
   2387  1.1  riastrad 			if (pi->high_voltage_t &&
   2388  1.1  riastrad 			    pi->high_voltage_t <
   2389  1.1  riastrad 			    kv_convert_2bit_index_to_voltage(rdev, table->entries[i].vid_2bit))
   2390  1.1  riastrad 				break;
   2391  1.1  riastrad 
   2392  1.1  riastrad 			kv_set_divider_value(rdev, i, table->entries[i].sclk_frequency);
   2393  1.1  riastrad 			kv_set_vid(rdev, i, table->entries[i].vid_2bit);
   2394  1.1  riastrad 			kv_set_at(rdev, i, pi->at[i]);
   2395  1.1  riastrad 			kv_dpm_power_level_enabled_for_throttle(rdev, i, true);
   2396  1.1  riastrad 			pi->graphics_dpm_level_count++;
   2397  1.1  riastrad 		}
   2398  1.1  riastrad 	}
   2399  1.1  riastrad 
   2400  1.1  riastrad 	for (i = 0; i < SMU7_MAX_LEVELS_GRAPHICS; i++)
   2401  1.1  riastrad 		kv_dpm_power_level_enable(rdev, i, false);
   2402  1.1  riastrad }
   2403  1.1  riastrad 
   2404  1.1  riastrad static void kv_enable_new_levels(struct radeon_device *rdev)
   2405  1.1  riastrad {
   2406  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   2407  1.1  riastrad 	u32 i;
   2408  1.1  riastrad 
   2409  1.1  riastrad 	for (i = 0; i < SMU7_MAX_LEVELS_GRAPHICS; i++) {
   2410  1.1  riastrad 		if (i >= pi->lowest_valid && i <= pi->highest_valid)
   2411  1.1  riastrad 			kv_dpm_power_level_enable(rdev, i, true);
   2412  1.1  riastrad 	}
   2413  1.1  riastrad }
   2414  1.1  riastrad 
   2415  1.1  riastrad static int kv_set_enabled_level(struct radeon_device *rdev, u32 level)
   2416  1.1  riastrad {
   2417  1.1  riastrad 	u32 new_mask = (1 << level);
   2418  1.1  riastrad 
   2419  1.1  riastrad 	return kv_send_msg_to_smc_with_parameter(rdev,
   2420  1.1  riastrad 						 PPSMC_MSG_SCLKDPM_SetEnabledMask,
   2421  1.1  riastrad 						 new_mask);
   2422  1.1  riastrad }
   2423  1.1  riastrad 
   2424  1.1  riastrad static int kv_set_enabled_levels(struct radeon_device *rdev)
   2425  1.1  riastrad {
   2426  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   2427  1.1  riastrad 	u32 i, new_mask = 0;
   2428  1.1  riastrad 
   2429  1.1  riastrad 	for (i = pi->lowest_valid; i <= pi->highest_valid; i++)
   2430  1.1  riastrad 		new_mask |= (1 << i);
   2431  1.1  riastrad 
   2432  1.1  riastrad 	return kv_send_msg_to_smc_with_parameter(rdev,
   2433  1.1  riastrad 						 PPSMC_MSG_SCLKDPM_SetEnabledMask,
   2434  1.1  riastrad 						 new_mask);
   2435  1.1  riastrad }
   2436  1.1  riastrad 
   2437  1.1  riastrad static void kv_program_nbps_index_settings(struct radeon_device *rdev,
   2438  1.1  riastrad 					   struct radeon_ps *new_rps)
   2439  1.1  riastrad {
   2440  1.1  riastrad 	struct kv_ps *new_ps = kv_get_ps(new_rps);
   2441  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   2442  1.1  riastrad 	u32 nbdpmconfig1;
   2443  1.1  riastrad 
   2444  1.1  riastrad 	if (rdev->family == CHIP_KABINI || rdev->family == CHIP_MULLINS)
   2445  1.1  riastrad 		return;
   2446  1.1  riastrad 
   2447  1.1  riastrad 	if (pi->sys_info.nb_dpm_enable) {
   2448  1.1  riastrad 		nbdpmconfig1 = RREG32_SMC(NB_DPM_CONFIG_1);
   2449  1.1  riastrad 		nbdpmconfig1 &= ~(Dpm0PgNbPsLo_MASK | Dpm0PgNbPsHi_MASK |
   2450  1.1  riastrad 				  DpmXNbPsLo_MASK | DpmXNbPsHi_MASK);
   2451  1.1  riastrad 		nbdpmconfig1 |= (Dpm0PgNbPsLo(new_ps->dpm0_pg_nb_ps_lo) |
   2452  1.1  riastrad 				 Dpm0PgNbPsHi(new_ps->dpm0_pg_nb_ps_hi) |
   2453  1.1  riastrad 				 DpmXNbPsLo(new_ps->dpmx_nb_ps_lo) |
   2454  1.1  riastrad 				 DpmXNbPsHi(new_ps->dpmx_nb_ps_hi));
   2455  1.1  riastrad 		WREG32_SMC(NB_DPM_CONFIG_1, nbdpmconfig1);
   2456  1.1  riastrad 	}
   2457  1.1  riastrad }
   2458  1.1  riastrad 
   2459  1.1  riastrad static int kv_set_thermal_temperature_range(struct radeon_device *rdev,
   2460  1.1  riastrad 					    int min_temp, int max_temp)
   2461  1.1  riastrad {
   2462  1.1  riastrad 	int low_temp = 0 * 1000;
   2463  1.1  riastrad 	int high_temp = 255 * 1000;
   2464  1.1  riastrad 	u32 tmp;
   2465  1.1  riastrad 
   2466  1.1  riastrad 	if (low_temp < min_temp)
   2467  1.1  riastrad 		low_temp = min_temp;
   2468  1.1  riastrad 	if (high_temp > max_temp)
   2469  1.1  riastrad 		high_temp = max_temp;
   2470  1.1  riastrad 	if (high_temp < low_temp) {
   2471  1.1  riastrad 		DRM_ERROR("invalid thermal range: %d - %d\n", low_temp, high_temp);
   2472  1.1  riastrad 		return -EINVAL;
   2473  1.1  riastrad 	}
   2474  1.1  riastrad 
   2475  1.1  riastrad 	tmp = RREG32_SMC(CG_THERMAL_INT_CTRL);
   2476  1.1  riastrad 	tmp &= ~(DIG_THERM_INTH_MASK | DIG_THERM_INTL_MASK);
   2477  1.1  riastrad 	tmp |= (DIG_THERM_INTH(49 + (high_temp / 1000)) |
   2478  1.1  riastrad 		DIG_THERM_INTL(49 + (low_temp / 1000)));
   2479  1.1  riastrad 	WREG32_SMC(CG_THERMAL_INT_CTRL, tmp);
   2480  1.1  riastrad 
   2481  1.1  riastrad 	rdev->pm.dpm.thermal.min_temp = low_temp;
   2482  1.1  riastrad 	rdev->pm.dpm.thermal.max_temp = high_temp;
   2483  1.1  riastrad 
   2484  1.1  riastrad 	return 0;
   2485  1.1  riastrad }
   2486  1.1  riastrad 
   2487  1.1  riastrad union igp_info {
   2488  1.1  riastrad 	struct _ATOM_INTEGRATED_SYSTEM_INFO info;
   2489  1.1  riastrad 	struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 info_2;
   2490  1.1  riastrad 	struct _ATOM_INTEGRATED_SYSTEM_INFO_V5 info_5;
   2491  1.1  riastrad 	struct _ATOM_INTEGRATED_SYSTEM_INFO_V6 info_6;
   2492  1.1  riastrad 	struct _ATOM_INTEGRATED_SYSTEM_INFO_V1_7 info_7;
   2493  1.1  riastrad 	struct _ATOM_INTEGRATED_SYSTEM_INFO_V1_8 info_8;
   2494  1.1  riastrad };
   2495  1.1  riastrad 
   2496  1.1  riastrad static int kv_parse_sys_info_table(struct radeon_device *rdev)
   2497  1.1  riastrad {
   2498  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   2499  1.1  riastrad 	struct radeon_mode_info *mode_info = &rdev->mode_info;
   2500  1.1  riastrad 	int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
   2501  1.1  riastrad 	union igp_info *igp_info;
   2502  1.1  riastrad 	u8 frev, crev;
   2503  1.1  riastrad 	u16 data_offset;
   2504  1.1  riastrad 	int i;
   2505  1.1  riastrad 
   2506  1.1  riastrad 	if (atom_parse_data_header(mode_info->atom_context, index, NULL,
   2507  1.1  riastrad 				   &frev, &crev, &data_offset)) {
   2508  1.1  riastrad 		igp_info = (union igp_info *)(mode_info->atom_context->bios +
   2509  1.1  riastrad 					      data_offset);
   2510  1.1  riastrad 
   2511  1.1  riastrad 		if (crev != 8) {
   2512  1.1  riastrad 			DRM_ERROR("Unsupported IGP table: %d %d\n", frev, crev);
   2513  1.1  riastrad 			return -EINVAL;
   2514  1.1  riastrad 		}
   2515  1.1  riastrad 		pi->sys_info.bootup_sclk = le32_to_cpu(igp_info->info_8.ulBootUpEngineClock);
   2516  1.1  riastrad 		pi->sys_info.bootup_uma_clk = le32_to_cpu(igp_info->info_8.ulBootUpUMAClock);
   2517  1.1  riastrad 		pi->sys_info.bootup_nb_voltage_index =
   2518  1.1  riastrad 			le16_to_cpu(igp_info->info_8.usBootUpNBVoltage);
   2519  1.1  riastrad 		if (igp_info->info_8.ucHtcTmpLmt == 0)
   2520  1.1  riastrad 			pi->sys_info.htc_tmp_lmt = 203;
   2521  1.1  riastrad 		else
   2522  1.1  riastrad 			pi->sys_info.htc_tmp_lmt = igp_info->info_8.ucHtcTmpLmt;
   2523  1.1  riastrad 		if (igp_info->info_8.ucHtcHystLmt == 0)
   2524  1.1  riastrad 			pi->sys_info.htc_hyst_lmt = 5;
   2525  1.1  riastrad 		else
   2526  1.1  riastrad 			pi->sys_info.htc_hyst_lmt = igp_info->info_8.ucHtcHystLmt;
   2527  1.1  riastrad 		if (pi->sys_info.htc_tmp_lmt <= pi->sys_info.htc_hyst_lmt) {
   2528  1.1  riastrad 			DRM_ERROR("The htcTmpLmt should be larger than htcHystLmt.\n");
   2529  1.1  riastrad 		}
   2530  1.1  riastrad 
   2531  1.1  riastrad 		if (le32_to_cpu(igp_info->info_8.ulSystemConfig) & (1 << 3))
   2532  1.1  riastrad 			pi->sys_info.nb_dpm_enable = true;
   2533  1.1  riastrad 		else
   2534  1.1  riastrad 			pi->sys_info.nb_dpm_enable = false;
   2535  1.1  riastrad 
   2536  1.1  riastrad 		for (i = 0; i < KV_NUM_NBPSTATES; i++) {
   2537  1.1  riastrad 			pi->sys_info.nbp_memory_clock[i] =
   2538  1.1  riastrad 				le32_to_cpu(igp_info->info_8.ulNbpStateMemclkFreq[i]);
   2539  1.1  riastrad 			pi->sys_info.nbp_n_clock[i] =
   2540  1.1  riastrad 				le32_to_cpu(igp_info->info_8.ulNbpStateNClkFreq[i]);
   2541  1.1  riastrad 		}
   2542  1.1  riastrad 		if (le32_to_cpu(igp_info->info_8.ulGPUCapInfo) &
   2543  1.1  riastrad 		    SYS_INFO_GPUCAPS__ENABEL_DFS_BYPASS)
   2544  1.1  riastrad 			pi->caps_enable_dfs_bypass = true;
   2545  1.1  riastrad 
   2546  1.1  riastrad 		sumo_construct_sclk_voltage_mapping_table(rdev,
   2547  1.1  riastrad 							  &pi->sys_info.sclk_voltage_mapping_table,
   2548  1.1  riastrad 							  igp_info->info_8.sAvail_SCLK);
   2549  1.1  riastrad 
   2550  1.1  riastrad 		sumo_construct_vid_mapping_table(rdev,
   2551  1.1  riastrad 						 &pi->sys_info.vid_mapping_table,
   2552  1.1  riastrad 						 igp_info->info_8.sAvail_SCLK);
   2553  1.1  riastrad 
   2554  1.1  riastrad 		kv_construct_max_power_limits_table(rdev,
   2555  1.1  riastrad 						    &rdev->pm.dpm.dyn_state.max_clock_voltage_on_ac);
   2556  1.1  riastrad 	}
   2557  1.1  riastrad 	return 0;
   2558  1.1  riastrad }
   2559  1.1  riastrad 
   2560  1.1  riastrad union power_info {
   2561  1.1  riastrad 	struct _ATOM_POWERPLAY_INFO info;
   2562  1.1  riastrad 	struct _ATOM_POWERPLAY_INFO_V2 info_2;
   2563  1.1  riastrad 	struct _ATOM_POWERPLAY_INFO_V3 info_3;
   2564  1.1  riastrad 	struct _ATOM_PPLIB_POWERPLAYTABLE pplib;
   2565  1.1  riastrad 	struct _ATOM_PPLIB_POWERPLAYTABLE2 pplib2;
   2566  1.1  riastrad 	struct _ATOM_PPLIB_POWERPLAYTABLE3 pplib3;
   2567  1.1  riastrad };
   2568  1.1  riastrad 
   2569  1.1  riastrad union pplib_clock_info {
   2570  1.1  riastrad 	struct _ATOM_PPLIB_R600_CLOCK_INFO r600;
   2571  1.1  riastrad 	struct _ATOM_PPLIB_RS780_CLOCK_INFO rs780;
   2572  1.1  riastrad 	struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO evergreen;
   2573  1.1  riastrad 	struct _ATOM_PPLIB_SUMO_CLOCK_INFO sumo;
   2574  1.1  riastrad };
   2575  1.1  riastrad 
   2576  1.1  riastrad union pplib_power_state {
   2577  1.1  riastrad 	struct _ATOM_PPLIB_STATE v1;
   2578  1.1  riastrad 	struct _ATOM_PPLIB_STATE_V2 v2;
   2579  1.1  riastrad };
   2580  1.1  riastrad 
   2581  1.1  riastrad static void kv_patch_boot_state(struct radeon_device *rdev,
   2582  1.1  riastrad 				struct kv_ps *ps)
   2583  1.1  riastrad {
   2584  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   2585  1.1  riastrad 
   2586  1.1  riastrad 	ps->num_levels = 1;
   2587  1.1  riastrad 	ps->levels[0] = pi->boot_pl;
   2588  1.1  riastrad }
   2589  1.1  riastrad 
   2590  1.1  riastrad static void kv_parse_pplib_non_clock_info(struct radeon_device *rdev,
   2591  1.1  riastrad 					  struct radeon_ps *rps,
   2592  1.1  riastrad 					  struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info,
   2593  1.1  riastrad 					  u8 table_rev)
   2594  1.1  riastrad {
   2595  1.1  riastrad 	struct kv_ps *ps = kv_get_ps(rps);
   2596  1.1  riastrad 
   2597  1.1  riastrad 	rps->caps = le32_to_cpu(non_clock_info->ulCapsAndSettings);
   2598  1.1  riastrad 	rps->class = le16_to_cpu(non_clock_info->usClassification);
   2599  1.1  riastrad 	rps->class2 = le16_to_cpu(non_clock_info->usClassification2);
   2600  1.1  riastrad 
   2601  1.1  riastrad 	if (ATOM_PPLIB_NONCLOCKINFO_VER1 < table_rev) {
   2602  1.1  riastrad 		rps->vclk = le32_to_cpu(non_clock_info->ulVCLK);
   2603  1.1  riastrad 		rps->dclk = le32_to_cpu(non_clock_info->ulDCLK);
   2604  1.1  riastrad 	} else {
   2605  1.1  riastrad 		rps->vclk = 0;
   2606  1.1  riastrad 		rps->dclk = 0;
   2607  1.1  riastrad 	}
   2608  1.1  riastrad 
   2609  1.1  riastrad 	if (rps->class & ATOM_PPLIB_CLASSIFICATION_BOOT) {
   2610  1.1  riastrad 		rdev->pm.dpm.boot_ps = rps;
   2611  1.1  riastrad 		kv_patch_boot_state(rdev, ps);
   2612  1.1  riastrad 	}
   2613  1.1  riastrad 	if (rps->class & ATOM_PPLIB_CLASSIFICATION_UVDSTATE)
   2614  1.1  riastrad 		rdev->pm.dpm.uvd_ps = rps;
   2615  1.1  riastrad }
   2616  1.1  riastrad 
   2617  1.1  riastrad static void kv_parse_pplib_clock_info(struct radeon_device *rdev,
   2618  1.1  riastrad 				      struct radeon_ps *rps, int index,
   2619  1.1  riastrad 					union pplib_clock_info *clock_info)
   2620  1.1  riastrad {
   2621  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   2622  1.1  riastrad 	struct kv_ps *ps = kv_get_ps(rps);
   2623  1.1  riastrad 	struct kv_pl *pl = &ps->levels[index];
   2624  1.1  riastrad 	u32 sclk;
   2625  1.1  riastrad 
   2626  1.1  riastrad 	sclk = le16_to_cpu(clock_info->sumo.usEngineClockLow);
   2627  1.1  riastrad 	sclk |= clock_info->sumo.ucEngineClockHigh << 16;
   2628  1.1  riastrad 	pl->sclk = sclk;
   2629  1.1  riastrad 	pl->vddc_index = clock_info->sumo.vddcIndex;
   2630  1.1  riastrad 
   2631  1.1  riastrad 	ps->num_levels = index + 1;
   2632  1.1  riastrad 
   2633  1.1  riastrad 	if (pi->caps_sclk_ds) {
   2634  1.1  riastrad 		pl->ds_divider_index = 5;
   2635  1.1  riastrad 		pl->ss_divider_index = 5;
   2636  1.1  riastrad 	}
   2637  1.1  riastrad }
   2638  1.1  riastrad 
   2639  1.1  riastrad static int kv_parse_power_table(struct radeon_device *rdev)
   2640  1.1  riastrad {
   2641  1.1  riastrad 	struct radeon_mode_info *mode_info = &rdev->mode_info;
   2642  1.1  riastrad 	struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
   2643  1.1  riastrad 	union pplib_power_state *power_state;
   2644  1.1  riastrad 	int i, j, k, non_clock_array_index, clock_array_index;
   2645  1.1  riastrad 	union pplib_clock_info *clock_info;
   2646  1.1  riastrad 	struct _StateArray *state_array;
   2647  1.1  riastrad 	struct _ClockInfoArray *clock_info_array;
   2648  1.1  riastrad 	struct _NonClockInfoArray *non_clock_info_array;
   2649  1.1  riastrad 	union power_info *power_info;
   2650  1.1  riastrad 	int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
   2651  1.2  riastrad 	u16 data_offset;
   2652  1.1  riastrad 	u8 frev, crev;
   2653  1.1  riastrad 	u8 *power_state_offset;
   2654  1.1  riastrad 	struct kv_ps *ps;
   2655  1.1  riastrad 
   2656  1.1  riastrad 	if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
   2657  1.1  riastrad 				   &frev, &crev, &data_offset))
   2658  1.1  riastrad 		return -EINVAL;
   2659  1.1  riastrad 	power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
   2660  1.1  riastrad 
   2661  1.1  riastrad 	state_array = (struct _StateArray *)
   2662  1.1  riastrad 		(mode_info->atom_context->bios + data_offset +
   2663  1.1  riastrad 		 le16_to_cpu(power_info->pplib.usStateArrayOffset));
   2664  1.1  riastrad 	clock_info_array = (struct _ClockInfoArray *)
   2665  1.1  riastrad 		(mode_info->atom_context->bios + data_offset +
   2666  1.1  riastrad 		 le16_to_cpu(power_info->pplib.usClockInfoArrayOffset));
   2667  1.1  riastrad 	non_clock_info_array = (struct _NonClockInfoArray *)
   2668  1.1  riastrad 		(mode_info->atom_context->bios + data_offset +
   2669  1.1  riastrad 		 le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset));
   2670  1.1  riastrad 
   2671  1.2  riastrad 	rdev->pm.dpm.ps = kcalloc(state_array->ucNumEntries,
   2672  1.2  riastrad 				  sizeof(struct radeon_ps),
   2673  1.2  riastrad 				  GFP_KERNEL);
   2674  1.1  riastrad 	if (!rdev->pm.dpm.ps)
   2675  1.1  riastrad 		return -ENOMEM;
   2676  1.1  riastrad 	power_state_offset = (u8 *)state_array->states;
   2677  1.1  riastrad 	for (i = 0; i < state_array->ucNumEntries; i++) {
   2678  1.1  riastrad 		u8 *idx;
   2679  1.1  riastrad 		power_state = (union pplib_power_state *)power_state_offset;
   2680  1.1  riastrad 		non_clock_array_index = power_state->v2.nonClockInfoIndex;
   2681  1.1  riastrad 		non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
   2682  1.1  riastrad 			&non_clock_info_array->nonClockInfo[non_clock_array_index];
   2683  1.1  riastrad 		if (!rdev->pm.power_state[i].clock_info)
   2684  1.1  riastrad 			return -EINVAL;
   2685  1.1  riastrad 		ps = kzalloc(sizeof(struct kv_ps), GFP_KERNEL);
   2686  1.1  riastrad 		if (ps == NULL) {
   2687  1.1  riastrad 			kfree(rdev->pm.dpm.ps);
   2688  1.1  riastrad 			return -ENOMEM;
   2689  1.1  riastrad 		}
   2690  1.1  riastrad 		rdev->pm.dpm.ps[i].ps_priv = ps;
   2691  1.1  riastrad 		k = 0;
   2692  1.1  riastrad 		idx = (u8 *)&power_state->v2.clockInfoIndex[0];
   2693  1.1  riastrad 		for (j = 0; j < power_state->v2.ucNumDPMLevels; j++) {
   2694  1.1  riastrad 			clock_array_index = idx[j];
   2695  1.1  riastrad 			if (clock_array_index >= clock_info_array->ucNumEntries)
   2696  1.1  riastrad 				continue;
   2697  1.1  riastrad 			if (k >= SUMO_MAX_HARDWARE_POWERLEVELS)
   2698  1.1  riastrad 				break;
   2699  1.1  riastrad 			clock_info = (union pplib_clock_info *)
   2700  1.1  riastrad 				((u8 *)&clock_info_array->clockInfo[0] +
   2701  1.1  riastrad 				 (clock_array_index * clock_info_array->ucEntrySize));
   2702  1.1  riastrad 			kv_parse_pplib_clock_info(rdev,
   2703  1.1  riastrad 						  &rdev->pm.dpm.ps[i], k,
   2704  1.1  riastrad 						  clock_info);
   2705  1.1  riastrad 			k++;
   2706  1.1  riastrad 		}
   2707  1.1  riastrad 		kv_parse_pplib_non_clock_info(rdev, &rdev->pm.dpm.ps[i],
   2708  1.1  riastrad 					      non_clock_info,
   2709  1.1  riastrad 					      non_clock_info_array->ucEntrySize);
   2710  1.1  riastrad 		power_state_offset += 2 + power_state->v2.ucNumDPMLevels;
   2711  1.1  riastrad 	}
   2712  1.1  riastrad 	rdev->pm.dpm.num_ps = state_array->ucNumEntries;
   2713  1.1  riastrad 
   2714  1.1  riastrad 	/* fill in the vce power states */
   2715  1.1  riastrad 	for (i = 0; i < RADEON_MAX_VCE_LEVELS; i++) {
   2716  1.1  riastrad 		u32 sclk;
   2717  1.1  riastrad 		clock_array_index = rdev->pm.dpm.vce_states[i].clk_idx;
   2718  1.1  riastrad 		clock_info = (union pplib_clock_info *)
   2719  1.1  riastrad 			&clock_info_array->clockInfo[clock_array_index * clock_info_array->ucEntrySize];
   2720  1.1  riastrad 		sclk = le16_to_cpu(clock_info->sumo.usEngineClockLow);
   2721  1.1  riastrad 		sclk |= clock_info->sumo.ucEngineClockHigh << 16;
   2722  1.1  riastrad 		rdev->pm.dpm.vce_states[i].sclk = sclk;
   2723  1.1  riastrad 		rdev->pm.dpm.vce_states[i].mclk = 0;
   2724  1.1  riastrad 	}
   2725  1.1  riastrad 
   2726  1.1  riastrad 	return 0;
   2727  1.1  riastrad }
   2728  1.1  riastrad 
   2729  1.1  riastrad int kv_dpm_init(struct radeon_device *rdev)
   2730  1.1  riastrad {
   2731  1.1  riastrad 	struct kv_power_info *pi;
   2732  1.1  riastrad 	int ret, i;
   2733  1.1  riastrad 
   2734  1.1  riastrad 	pi = kzalloc(sizeof(struct kv_power_info), GFP_KERNEL);
   2735  1.1  riastrad 	if (pi == NULL)
   2736  1.1  riastrad 		return -ENOMEM;
   2737  1.1  riastrad 	rdev->pm.dpm.priv = pi;
   2738  1.1  riastrad 
   2739  1.1  riastrad 	ret = r600_get_platform_caps(rdev);
   2740  1.1  riastrad 	if (ret)
   2741  1.1  riastrad 		return ret;
   2742  1.1  riastrad 
   2743  1.1  riastrad 	ret = r600_parse_extended_power_table(rdev);
   2744  1.1  riastrad 	if (ret)
   2745  1.1  riastrad 		return ret;
   2746  1.1  riastrad 
   2747  1.1  riastrad 	for (i = 0; i < SUMO_MAX_HARDWARE_POWERLEVELS; i++)
   2748  1.1  riastrad 		pi->at[i] = TRINITY_AT_DFLT;
   2749  1.1  riastrad 
   2750  1.2  riastrad 	pi->sram_end = SMC_RAM_END;
   2751  1.1  riastrad 
   2752  1.1  riastrad 	/* Enabling nb dpm on an asrock system prevents dpm from working */
   2753  1.1  riastrad 	if (rdev->pdev->subsystem_vendor == 0x1849)
   2754  1.1  riastrad 		pi->enable_nb_dpm = false;
   2755  1.1  riastrad 	else
   2756  1.1  riastrad 		pi->enable_nb_dpm = true;
   2757  1.1  riastrad 
   2758  1.1  riastrad 	pi->caps_power_containment = true;
   2759  1.1  riastrad 	pi->caps_cac = true;
   2760  1.1  riastrad 	pi->enable_didt = false;
   2761  1.1  riastrad 	if (pi->enable_didt) {
   2762  1.1  riastrad 		pi->caps_sq_ramping = true;
   2763  1.1  riastrad 		pi->caps_db_ramping = true;
   2764  1.1  riastrad 		pi->caps_td_ramping = true;
   2765  1.1  riastrad 		pi->caps_tcp_ramping = true;
   2766  1.1  riastrad 	}
   2767  1.1  riastrad 
   2768  1.1  riastrad 	pi->caps_sclk_ds = true;
   2769  1.1  riastrad 	pi->enable_auto_thermal_throttling = true;
   2770  1.1  riastrad 	pi->disable_nb_ps3_in_battery = false;
   2771  1.1  riastrad 	if (radeon_bapm == -1) {
   2772  1.1  riastrad 		/* only enable bapm on KB, ML by default */
   2773  1.1  riastrad 		if (rdev->family == CHIP_KABINI || rdev->family == CHIP_MULLINS)
   2774  1.1  riastrad 			pi->bapm_enable = true;
   2775  1.1  riastrad 		else
   2776  1.1  riastrad 			pi->bapm_enable = false;
   2777  1.1  riastrad 	} else if (radeon_bapm == 0) {
   2778  1.1  riastrad 		pi->bapm_enable = false;
   2779  1.1  riastrad 	} else {
   2780  1.1  riastrad 		pi->bapm_enable = true;
   2781  1.1  riastrad 	}
   2782  1.1  riastrad 	pi->voltage_drop_t = 0;
   2783  1.1  riastrad 	pi->caps_sclk_throttle_low_notification = false;
   2784  1.1  riastrad 	pi->caps_fps = false; /* true? */
   2785  1.1  riastrad 	pi->caps_uvd_pg = true;
   2786  1.1  riastrad 	pi->caps_uvd_dpm = true;
   2787  1.1  riastrad 	pi->caps_vce_pg = false; /* XXX true */
   2788  1.1  riastrad 	pi->caps_samu_pg = false;
   2789  1.1  riastrad 	pi->caps_acp_pg = false;
   2790  1.1  riastrad 	pi->caps_stable_p_state = false;
   2791  1.1  riastrad 
   2792  1.1  riastrad 	ret = kv_parse_sys_info_table(rdev);
   2793  1.1  riastrad 	if (ret)
   2794  1.1  riastrad 		return ret;
   2795  1.1  riastrad 
   2796  1.1  riastrad 	kv_patch_voltage_values(rdev);
   2797  1.1  riastrad 	kv_construct_boot_state(rdev);
   2798  1.1  riastrad 
   2799  1.1  riastrad 	ret = kv_parse_power_table(rdev);
   2800  1.1  riastrad 	if (ret)
   2801  1.1  riastrad 		return ret;
   2802  1.1  riastrad 
   2803  1.1  riastrad 	pi->enable_dpm = true;
   2804  1.1  riastrad 
   2805  1.1  riastrad 	return 0;
   2806  1.1  riastrad }
   2807  1.1  riastrad 
   2808  1.1  riastrad #ifdef CONFIG_DEBUG_FS
   2809  1.1  riastrad void kv_dpm_debugfs_print_current_performance_level(struct radeon_device *rdev,
   2810  1.1  riastrad 						    struct seq_file *m)
   2811  1.1  riastrad {
   2812  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   2813  1.1  riastrad 	u32 current_index =
   2814  1.1  riastrad 		(RREG32_SMC(TARGET_AND_CURRENT_PROFILE_INDEX) & CURR_SCLK_INDEX_MASK) >>
   2815  1.1  riastrad 		CURR_SCLK_INDEX_SHIFT;
   2816  1.1  riastrad 	u32 sclk, tmp;
   2817  1.1  riastrad 	u16 vddc;
   2818  1.1  riastrad 
   2819  1.1  riastrad 	if (current_index >= SMU__NUM_SCLK_DPM_STATE) {
   2820  1.1  riastrad 		seq_printf(m, "invalid dpm profile %d\n", current_index);
   2821  1.1  riastrad 	} else {
   2822  1.1  riastrad 		sclk = be32_to_cpu(pi->graphics_level[current_index].SclkFrequency);
   2823  1.1  riastrad 		tmp = (RREG32_SMC(SMU_VOLTAGE_STATUS) & SMU_VOLTAGE_CURRENT_LEVEL_MASK) >>
   2824  1.1  riastrad 			SMU_VOLTAGE_CURRENT_LEVEL_SHIFT;
   2825  1.1  riastrad 		vddc = kv_convert_8bit_index_to_voltage(rdev, (u16)tmp);
   2826  1.1  riastrad 		seq_printf(m, "uvd    %sabled\n", pi->uvd_power_gated ? "dis" : "en");
   2827  1.1  riastrad 		seq_printf(m, "vce    %sabled\n", pi->vce_power_gated ? "dis" : "en");
   2828  1.1  riastrad 		seq_printf(m, "power level %d    sclk: %u vddc: %u\n",
   2829  1.1  riastrad 			   current_index, sclk, vddc);
   2830  1.1  riastrad 	}
   2831  1.1  riastrad }
   2832  1.1  riastrad #endif	/* CONFIG_DEBUG_FS */
   2833  1.1  riastrad 
   2834  1.1  riastrad u32 kv_dpm_get_current_sclk(struct radeon_device *rdev)
   2835  1.1  riastrad {
   2836  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   2837  1.1  riastrad 	u32 current_index =
   2838  1.1  riastrad 		(RREG32_SMC(TARGET_AND_CURRENT_PROFILE_INDEX) & CURR_SCLK_INDEX_MASK) >>
   2839  1.1  riastrad 		CURR_SCLK_INDEX_SHIFT;
   2840  1.1  riastrad 	u32 sclk;
   2841  1.1  riastrad 
   2842  1.1  riastrad 	if (current_index >= SMU__NUM_SCLK_DPM_STATE) {
   2843  1.1  riastrad 		return 0;
   2844  1.1  riastrad 	} else {
   2845  1.1  riastrad 		sclk = be32_to_cpu(pi->graphics_level[current_index].SclkFrequency);
   2846  1.1  riastrad 		return sclk;
   2847  1.1  riastrad 	}
   2848  1.1  riastrad }
   2849  1.1  riastrad 
   2850  1.1  riastrad u32 kv_dpm_get_current_mclk(struct radeon_device *rdev)
   2851  1.1  riastrad {
   2852  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   2853  1.1  riastrad 
   2854  1.1  riastrad 	return pi->sys_info.bootup_uma_clk;
   2855  1.1  riastrad }
   2856  1.1  riastrad 
   2857  1.1  riastrad void kv_dpm_print_power_state(struct radeon_device *rdev,
   2858  1.1  riastrad 			      struct radeon_ps *rps)
   2859  1.1  riastrad {
   2860  1.1  riastrad 	int i;
   2861  1.1  riastrad 	struct kv_ps *ps = kv_get_ps(rps);
   2862  1.1  riastrad 
   2863  1.1  riastrad 	r600_dpm_print_class_info(rps->class, rps->class2);
   2864  1.1  riastrad 	r600_dpm_print_cap_info(rps->caps);
   2865  1.1  riastrad 	printk("\tuvd    vclk: %d dclk: %d\n", rps->vclk, rps->dclk);
   2866  1.1  riastrad 	for (i = 0; i < ps->num_levels; i++) {
   2867  1.1  riastrad 		struct kv_pl *pl = &ps->levels[i];
   2868  1.1  riastrad 		printk("\t\tpower level %d    sclk: %u vddc: %u\n",
   2869  1.1  riastrad 		       i, pl->sclk,
   2870  1.1  riastrad 		       kv_convert_8bit_index_to_voltage(rdev, pl->vddc_index));
   2871  1.1  riastrad 	}
   2872  1.1  riastrad 	r600_dpm_print_ps_status(rdev, rps);
   2873  1.1  riastrad }
   2874  1.1  riastrad 
   2875  1.1  riastrad void kv_dpm_fini(struct radeon_device *rdev)
   2876  1.1  riastrad {
   2877  1.1  riastrad 	int i;
   2878  1.1  riastrad 
   2879  1.1  riastrad 	for (i = 0; i < rdev->pm.dpm.num_ps; i++) {
   2880  1.1  riastrad 		kfree(rdev->pm.dpm.ps[i].ps_priv);
   2881  1.1  riastrad 	}
   2882  1.1  riastrad 	kfree(rdev->pm.dpm.ps);
   2883  1.1  riastrad 	kfree(rdev->pm.dpm.priv);
   2884  1.1  riastrad 	r600_free_extended_power_table(rdev);
   2885  1.1  riastrad }
   2886  1.1  riastrad 
   2887  1.1  riastrad void kv_dpm_display_configuration_changed(struct radeon_device *rdev)
   2888  1.1  riastrad {
   2889  1.1  riastrad 
   2890  1.1  riastrad }
   2891  1.1  riastrad 
   2892  1.1  riastrad u32 kv_dpm_get_sclk(struct radeon_device *rdev, bool low)
   2893  1.1  riastrad {
   2894  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   2895  1.1  riastrad 	struct kv_ps *requested_state = kv_get_ps(&pi->requested_rps);
   2896  1.1  riastrad 
   2897  1.1  riastrad 	if (low)
   2898  1.1  riastrad 		return requested_state->levels[0].sclk;
   2899  1.1  riastrad 	else
   2900  1.1  riastrad 		return requested_state->levels[requested_state->num_levels - 1].sclk;
   2901  1.1  riastrad }
   2902  1.1  riastrad 
   2903  1.1  riastrad u32 kv_dpm_get_mclk(struct radeon_device *rdev, bool low)
   2904  1.1  riastrad {
   2905  1.1  riastrad 	struct kv_power_info *pi = kv_get_pi(rdev);
   2906  1.1  riastrad 
   2907  1.1  riastrad 	return pi->sys_info.bootup_uma_clk;
   2908  1.1  riastrad }
   2909  1.1  riastrad 
   2910