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