radeon_trinity_smc.c revision 1.1
1/* $NetBSD: radeon_trinity_smc.c,v 1.1 2018/08/27 14:38:20 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.1 2018/08/27 14:38:20 riastradh Exp $"); 28 29#include "drmP.h" 30#include "radeon.h" 31#include "trinityd.h" 32#include "trinity_dpm.h" 33#include "ppsmc.h" 34 35static int trinity_notify_message_to_smu(struct radeon_device *rdev, u32 id) 36{ 37 int i; 38 u32 v = 0; 39 40 WREG32(SMC_MESSAGE_0, id); 41 for (i = 0; i < rdev->usec_timeout; i++) { 42 if (RREG32(SMC_RESP_0) != 0) 43 break; 44 udelay(1); 45 } 46 v = RREG32(SMC_RESP_0); 47 48 if (v != 1) { 49 if (v == 0xFF) { 50 DRM_ERROR("SMC failed to handle the message!\n"); 51 return -EINVAL; 52 } else if (v == 0xFE) { 53 DRM_ERROR("Unknown SMC message!\n"); 54 return -EINVAL; 55 } 56 } 57 58 return 0; 59} 60 61int trinity_dpm_bapm_enable(struct radeon_device *rdev, bool enable) 62{ 63 if (enable) 64 return trinity_notify_message_to_smu(rdev, PPSMC_MSG_EnableBAPM); 65 else 66 return trinity_notify_message_to_smu(rdev, PPSMC_MSG_DisableBAPM); 67} 68 69int trinity_dpm_config(struct radeon_device *rdev, bool enable) 70{ 71 if (enable) 72 WREG32_SMC(SMU_SCRATCH0, 1); 73 else 74 WREG32_SMC(SMU_SCRATCH0, 0); 75 76 return trinity_notify_message_to_smu(rdev, PPSMC_MSG_DPM_Config); 77} 78 79int trinity_dpm_force_state(struct radeon_device *rdev, u32 n) 80{ 81 WREG32_SMC(SMU_SCRATCH0, n); 82 83 return trinity_notify_message_to_smu(rdev, PPSMC_MSG_DPM_ForceState); 84} 85 86int trinity_dpm_n_levels_disabled(struct radeon_device *rdev, u32 n) 87{ 88 WREG32_SMC(SMU_SCRATCH0, n); 89 90 return trinity_notify_message_to_smu(rdev, PPSMC_MSG_DPM_N_LevelsDisabled); 91} 92 93int trinity_uvd_dpm_config(struct radeon_device *rdev) 94{ 95 return trinity_notify_message_to_smu(rdev, PPSMC_MSG_UVD_DPM_Config); 96} 97 98int trinity_dpm_no_forced_level(struct radeon_device *rdev) 99{ 100 return trinity_notify_message_to_smu(rdev, PPSMC_MSG_NoForcedLevel); 101} 102 103int trinity_dce_enable_voltage_adjustment(struct radeon_device *rdev, 104 bool enable) 105{ 106 if (enable) 107 return trinity_notify_message_to_smu(rdev, PPSMC_MSG_DCE_AllowVoltageAdjustment); 108 else 109 return trinity_notify_message_to_smu(rdev, PPSMC_MSG_DCE_RemoveVoltageAdjustment); 110} 111 112int trinity_gfx_dynamic_mgpg_config(struct radeon_device *rdev) 113{ 114 return trinity_notify_message_to_smu(rdev, PPSMC_MSG_PG_SIMD_Config); 115} 116 117void trinity_acquire_mutex(struct radeon_device *rdev) 118{ 119 int i; 120 121 WREG32(SMC_INT_REQ, 1); 122 for (i = 0; i < rdev->usec_timeout; i++) { 123 if ((RREG32(SMC_INT_REQ) & 0xffff) == 1) 124 break; 125 udelay(1); 126 } 127} 128 129void trinity_release_mutex(struct radeon_device *rdev) 130{ 131 WREG32(SMC_INT_REQ, 0); 132} 133