Home | History | Annotate | Line # | Download | only in radeon
      1 /*	$NetBSD: radeon_trinity_smc.c,v 1.2 2021/12/18 23:45:43 riastradh Exp $	*/
      2 
      3 /*
      4  * Copyright 2012 Advanced Micro Devices, Inc.
      5  *
      6  * Permission is hereby granted, free of charge, to any person obtaining a
      7  * copy of this software and associated documentation files (the "Software"),
      8  * to deal in the Software without restriction, including without limitation
      9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     10  * and/or sell copies of the Software, and to permit persons to whom the
     11  * Software is furnished to do so, subject to the following conditions:
     12  *
     13  * The above copyright notice and this permission notice shall be included in
     14  * all copies or substantial portions of the Software.
     15  *
     16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     19  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
     20  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
     21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
     22  * OTHER DEALINGS IN THE SOFTWARE.
     23  *
     24  */
     25 
     26 #include <sys/cdefs.h>
     27 __KERNEL_RCSID(0, "$NetBSD: radeon_trinity_smc.c,v 1.2 2021/12/18 23:45:43 riastradh Exp $");
     28 
     29 #include "radeon.h"
     30 #include "trinityd.h"
     31 #include "trinity_dpm.h"
     32 #include "ppsmc.h"
     33 
     34 static int trinity_notify_message_to_smu(struct radeon_device *rdev, u32 id)
     35 {
     36 	int i;
     37 	u32 v = 0;
     38 
     39 	WREG32(SMC_MESSAGE_0, id);
     40 	for (i = 0; i < rdev->usec_timeout; i++) {
     41 		if (RREG32(SMC_RESP_0) != 0)
     42 			break;
     43 		udelay(1);
     44 	}
     45 	v = RREG32(SMC_RESP_0);
     46 
     47 	if (v != 1) {
     48 		if (v == 0xFF) {
     49 			DRM_ERROR("SMC failed to handle the message!\n");
     50 			return -EINVAL;
     51 		} else if (v == 0xFE) {
     52 			DRM_ERROR("Unknown SMC message!\n");
     53 			return -EINVAL;
     54 		}
     55 	}
     56 
     57 	return 0;
     58 }
     59 
     60 int trinity_dpm_bapm_enable(struct radeon_device *rdev, bool enable)
     61 {
     62 	if (enable)
     63 		return trinity_notify_message_to_smu(rdev, PPSMC_MSG_EnableBAPM);
     64 	else
     65 		return trinity_notify_message_to_smu(rdev, PPSMC_MSG_DisableBAPM);
     66 }
     67 
     68 int trinity_dpm_config(struct radeon_device *rdev, bool enable)
     69 {
     70 	if (enable)
     71 		WREG32_SMC(SMU_SCRATCH0, 1);
     72 	else
     73 		WREG32_SMC(SMU_SCRATCH0, 0);
     74 
     75 	return trinity_notify_message_to_smu(rdev, PPSMC_MSG_DPM_Config);
     76 }
     77 
     78 int trinity_dpm_force_state(struct radeon_device *rdev, u32 n)
     79 {
     80 	WREG32_SMC(SMU_SCRATCH0, n);
     81 
     82 	return trinity_notify_message_to_smu(rdev, PPSMC_MSG_DPM_ForceState);
     83 }
     84 
     85 int trinity_dpm_n_levels_disabled(struct radeon_device *rdev, u32 n)
     86 {
     87 	WREG32_SMC(SMU_SCRATCH0, n);
     88 
     89 	return trinity_notify_message_to_smu(rdev, PPSMC_MSG_DPM_N_LevelsDisabled);
     90 }
     91 
     92 int trinity_uvd_dpm_config(struct radeon_device *rdev)
     93 {
     94 	return trinity_notify_message_to_smu(rdev, PPSMC_MSG_UVD_DPM_Config);
     95 }
     96 
     97 int trinity_dpm_no_forced_level(struct radeon_device *rdev)
     98 {
     99 	return trinity_notify_message_to_smu(rdev, PPSMC_MSG_NoForcedLevel);
    100 }
    101 
    102 int trinity_dce_enable_voltage_adjustment(struct radeon_device *rdev,
    103 					  bool enable)
    104 {
    105 	if (enable)
    106 		return trinity_notify_message_to_smu(rdev, PPSMC_MSG_DCE_AllowVoltageAdjustment);
    107 	else
    108 		return trinity_notify_message_to_smu(rdev, PPSMC_MSG_DCE_RemoveVoltageAdjustment);
    109 }
    110 
    111 int trinity_gfx_dynamic_mgpg_config(struct radeon_device *rdev)
    112 {
    113 	return trinity_notify_message_to_smu(rdev, PPSMC_MSG_PG_SIMD_Config);
    114 }
    115 
    116 void trinity_acquire_mutex(struct radeon_device *rdev)
    117 {
    118 	int i;
    119 
    120 	WREG32(SMC_INT_REQ, 1);
    121 	for (i = 0; i < rdev->usec_timeout; i++) {
    122 		if ((RREG32(SMC_INT_REQ) & 0xffff) == 1)
    123 			break;
    124 		udelay(1);
    125 	}
    126 }
    127 
    128 void trinity_release_mutex(struct radeon_device *rdev)
    129 {
    130 	WREG32(SMC_INT_REQ, 0);
    131 }
    132