xref: /linux/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu9_baco.c (revision 36ec807b627b4c0a0a382f0ae48eac7187d14b2b)
1518f6a54SAlex Deucher /*
2518f6a54SAlex Deucher  * Copyright 2018 Advanced Micro Devices, Inc.
3518f6a54SAlex Deucher  *
4518f6a54SAlex Deucher  * Permission is hereby granted, free of charge, to any person obtaining a
5518f6a54SAlex Deucher  * copy of this software and associated documentation files (the "Software"),
6518f6a54SAlex Deucher  * to deal in the Software without restriction, including without limitation
7518f6a54SAlex Deucher  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8518f6a54SAlex Deucher  * and/or sell copies of the Software, and to permit persons to whom the
9518f6a54SAlex Deucher  * Software is furnished to do so, subject to the following conditions:
10518f6a54SAlex Deucher  *
11518f6a54SAlex Deucher  * The above copyright notice and this permission notice shall be included in
12518f6a54SAlex Deucher  * all copies or substantial portions of the Software.
13518f6a54SAlex Deucher  *
14518f6a54SAlex Deucher  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15518f6a54SAlex Deucher  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16518f6a54SAlex Deucher  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17518f6a54SAlex Deucher  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18518f6a54SAlex Deucher  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19518f6a54SAlex Deucher  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20518f6a54SAlex Deucher  * OTHER DEALINGS IN THE SOFTWARE.
21518f6a54SAlex Deucher  *
22518f6a54SAlex Deucher  */
23518f6a54SAlex Deucher #include "amdgpu.h"
24518f6a54SAlex Deucher #include "soc15.h"
25518f6a54SAlex Deucher #include "soc15_hw_ip.h"
26518f6a54SAlex Deucher #include "vega10_ip_offset.h"
27518f6a54SAlex Deucher #include "soc15_common.h"
28518f6a54SAlex Deucher #include "vega10_inc.h"
29518f6a54SAlex Deucher #include "smu9_baco.h"
30518f6a54SAlex Deucher 
smu9_get_bamaco_support(struct pp_hwmgr * hwmgr)31b2207dc6SMa Jun int smu9_get_bamaco_support(struct pp_hwmgr *hwmgr)
32518f6a54SAlex Deucher {
33518f6a54SAlex Deucher 	struct amdgpu_device *adev = (struct amdgpu_device *)(hwmgr->adev);
34518f6a54SAlex Deucher 	uint32_t reg, data;
35518f6a54SAlex Deucher 
36518f6a54SAlex Deucher 	if (!phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_BACO))
37b2207dc6SMa Jun 		return 0;
38518f6a54SAlex Deucher 
39518f6a54SAlex Deucher 	WREG32(0x12074, 0xFFF0003B);
40518f6a54SAlex Deucher 	data = RREG32(0x12075);
41518f6a54SAlex Deucher 
42518f6a54SAlex Deucher 	if (data == 0x1) {
43518f6a54SAlex Deucher 		reg = RREG32_SOC15(NBIF, 0, mmRCC_BIF_STRAP0);
44518f6a54SAlex Deucher 
45518f6a54SAlex Deucher 		if (reg & RCC_BIF_STRAP0__STRAP_PX_CAPABLE_MASK)
46b2207dc6SMa Jun 			return BACO_SUPPORT;
47518f6a54SAlex Deucher 	}
48518f6a54SAlex Deucher 
49b2207dc6SMa Jun 	return 0;
50518f6a54SAlex Deucher }
51518f6a54SAlex Deucher 
smu9_baco_get_state(struct pp_hwmgr * hwmgr,enum BACO_STATE * state)52518f6a54SAlex Deucher int smu9_baco_get_state(struct pp_hwmgr *hwmgr, enum BACO_STATE *state)
53518f6a54SAlex Deucher {
54518f6a54SAlex Deucher 	struct amdgpu_device *adev = (struct amdgpu_device *)(hwmgr->adev);
55518f6a54SAlex Deucher 	uint32_t reg;
56518f6a54SAlex Deucher 
57518f6a54SAlex Deucher 	reg = RREG32_SOC15(NBIF, 0, mmBACO_CNTL);
58518f6a54SAlex Deucher 
59518f6a54SAlex Deucher 	if (reg & BACO_CNTL__BACO_MODE_MASK)
60518f6a54SAlex Deucher 		/* gfx has already entered BACO state */
61518f6a54SAlex Deucher 		*state = BACO_STATE_IN;
62518f6a54SAlex Deucher 	else
63518f6a54SAlex Deucher 		*state = BACO_STATE_OUT;
64518f6a54SAlex Deucher 	return 0;
65518f6a54SAlex Deucher }
66