1*e4a580baSriastradh /* $NetBSD: amd_shared.h,v 1.4 2021/12/19 10:59:02 riastradh Exp $ */ 2efa246c0Sriastradh 3efa246c0Sriastradh /* 4efa246c0Sriastradh * Copyright 2015 Advanced Micro Devices, Inc. 5efa246c0Sriastradh * 6efa246c0Sriastradh * Permission is hereby granted, free of charge, to any person obtaining a 7efa246c0Sriastradh * copy of this software and associated documentation files (the "Software"), 8efa246c0Sriastradh * to deal in the Software without restriction, including without limitation 9efa246c0Sriastradh * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10efa246c0Sriastradh * and/or sell copies of the Software, and to permit persons to whom the 11efa246c0Sriastradh * Software is furnished to do so, subject to the following conditions: 12efa246c0Sriastradh * 13efa246c0Sriastradh * The above copyright notice and this permission notice shall be included in 14efa246c0Sriastradh * all copies or substantial portions of the Software. 15efa246c0Sriastradh * 16efa246c0Sriastradh * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17efa246c0Sriastradh * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18efa246c0Sriastradh * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19efa246c0Sriastradh * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 20efa246c0Sriastradh * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21efa246c0Sriastradh * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22efa246c0Sriastradh * OTHER DEALINGS IN THE SOFTWARE. 23efa246c0Sriastradh */ 24efa246c0Sriastradh 25efa246c0Sriastradh #ifndef __AMD_SHARED_H__ 26efa246c0Sriastradh #define __AMD_SHARED_H__ 27efa246c0Sriastradh 2841ec0267Sriastradh #include <drm/amd_asic_type.h> 29efa246c0Sriastradh 30efa246c0Sriastradh 3141ec0267Sriastradh #define AMD_MAX_USEC_TIMEOUT 1000000 /* 1000 ms */ 32efa246c0Sriastradh 33efa246c0Sriastradh /* 34efa246c0Sriastradh * Chip flags 35efa246c0Sriastradh */ 36efa246c0Sriastradh enum amd_chip_flags { 37efa246c0Sriastradh AMD_ASIC_MASK = 0x0000ffffUL, 38efa246c0Sriastradh AMD_FLAGS_MASK = 0xffff0000UL, 39efa246c0Sriastradh AMD_IS_MOBILITY = 0x00010000UL, 40efa246c0Sriastradh AMD_IS_APU = 0x00020000UL, 41efa246c0Sriastradh AMD_IS_PX = 0x00040000UL, 42efa246c0Sriastradh AMD_EXP_HW_SUPPORT = 0x00080000UL, 43efa246c0Sriastradh }; 44efa246c0Sriastradh 45efa246c0Sriastradh enum amd_ip_block_type { 46efa246c0Sriastradh AMD_IP_BLOCK_TYPE_COMMON, 47efa246c0Sriastradh AMD_IP_BLOCK_TYPE_GMC, 48efa246c0Sriastradh AMD_IP_BLOCK_TYPE_IH, 49efa246c0Sriastradh AMD_IP_BLOCK_TYPE_SMC, 5041ec0267Sriastradh AMD_IP_BLOCK_TYPE_PSP, 51efa246c0Sriastradh AMD_IP_BLOCK_TYPE_DCE, 52efa246c0Sriastradh AMD_IP_BLOCK_TYPE_GFX, 53efa246c0Sriastradh AMD_IP_BLOCK_TYPE_SDMA, 54efa246c0Sriastradh AMD_IP_BLOCK_TYPE_UVD, 55efa246c0Sriastradh AMD_IP_BLOCK_TYPE_VCE, 5641ec0267Sriastradh AMD_IP_BLOCK_TYPE_ACP, 5741ec0267Sriastradh AMD_IP_BLOCK_TYPE_VCN, 5841ec0267Sriastradh AMD_IP_BLOCK_TYPE_MES, 5941ec0267Sriastradh AMD_IP_BLOCK_TYPE_JPEG 60efa246c0Sriastradh }; 61efa246c0Sriastradh 62efa246c0Sriastradh enum amd_clockgating_state { 63efa246c0Sriastradh AMD_CG_STATE_GATE = 0, 64efa246c0Sriastradh AMD_CG_STATE_UNGATE, 65efa246c0Sriastradh }; 66efa246c0Sriastradh 6741ec0267Sriastradh 68efa246c0Sriastradh enum amd_powergating_state { 69efa246c0Sriastradh AMD_PG_STATE_GATE = 0, 70efa246c0Sriastradh AMD_PG_STATE_UNGATE, 71efa246c0Sriastradh }; 72efa246c0Sriastradh 7341ec0267Sriastradh 7441ec0267Sriastradh /* CG flags */ 7541ec0267Sriastradh #define AMD_CG_SUPPORT_GFX_MGCG (1 << 0) 7641ec0267Sriastradh #define AMD_CG_SUPPORT_GFX_MGLS (1 << 1) 7741ec0267Sriastradh #define AMD_CG_SUPPORT_GFX_CGCG (1 << 2) 7841ec0267Sriastradh #define AMD_CG_SUPPORT_GFX_CGLS (1 << 3) 7941ec0267Sriastradh #define AMD_CG_SUPPORT_GFX_CGTS (1 << 4) 8041ec0267Sriastradh #define AMD_CG_SUPPORT_GFX_CGTS_LS (1 << 5) 8141ec0267Sriastradh #define AMD_CG_SUPPORT_GFX_CP_LS (1 << 6) 8241ec0267Sriastradh #define AMD_CG_SUPPORT_GFX_RLC_LS (1 << 7) 8341ec0267Sriastradh #define AMD_CG_SUPPORT_MC_LS (1 << 8) 8441ec0267Sriastradh #define AMD_CG_SUPPORT_MC_MGCG (1 << 9) 8541ec0267Sriastradh #define AMD_CG_SUPPORT_SDMA_LS (1 << 10) 8641ec0267Sriastradh #define AMD_CG_SUPPORT_SDMA_MGCG (1 << 11) 8741ec0267Sriastradh #define AMD_CG_SUPPORT_BIF_LS (1 << 12) 8841ec0267Sriastradh #define AMD_CG_SUPPORT_UVD_MGCG (1 << 13) 8941ec0267Sriastradh #define AMD_CG_SUPPORT_VCE_MGCG (1 << 14) 9041ec0267Sriastradh #define AMD_CG_SUPPORT_HDP_LS (1 << 15) 9141ec0267Sriastradh #define AMD_CG_SUPPORT_HDP_MGCG (1 << 16) 9241ec0267Sriastradh #define AMD_CG_SUPPORT_ROM_MGCG (1 << 17) 9341ec0267Sriastradh #define AMD_CG_SUPPORT_DRM_LS (1 << 18) 9441ec0267Sriastradh #define AMD_CG_SUPPORT_BIF_MGCG (1 << 19) 9541ec0267Sriastradh #define AMD_CG_SUPPORT_GFX_3D_CGCG (1 << 20) 9641ec0267Sriastradh #define AMD_CG_SUPPORT_GFX_3D_CGLS (1 << 21) 9741ec0267Sriastradh #define AMD_CG_SUPPORT_DRM_MGCG (1 << 22) 9841ec0267Sriastradh #define AMD_CG_SUPPORT_DF_MGCG (1 << 23) 9941ec0267Sriastradh #define AMD_CG_SUPPORT_VCN_MGCG (1 << 24) 10041ec0267Sriastradh #define AMD_CG_SUPPORT_HDP_DS (1 << 25) 10141ec0267Sriastradh #define AMD_CG_SUPPORT_HDP_SD (1 << 26) 10241ec0267Sriastradh #define AMD_CG_SUPPORT_IH_CG (1 << 27) 10341ec0267Sriastradh #define AMD_CG_SUPPORT_ATHUB_LS (1 << 28) 10441ec0267Sriastradh #define AMD_CG_SUPPORT_ATHUB_MGCG (1 << 29) 10541ec0267Sriastradh #define AMD_CG_SUPPORT_JPEG_MGCG (1 << 30) 10641ec0267Sriastradh /* PG flags */ 10741ec0267Sriastradh #define AMD_PG_SUPPORT_GFX_PG (1 << 0) 10841ec0267Sriastradh #define AMD_PG_SUPPORT_GFX_SMG (1 << 1) 10941ec0267Sriastradh #define AMD_PG_SUPPORT_GFX_DMG (1 << 2) 11041ec0267Sriastradh #define AMD_PG_SUPPORT_UVD (1 << 3) 11141ec0267Sriastradh #define AMD_PG_SUPPORT_VCE (1 << 4) 11241ec0267Sriastradh #define AMD_PG_SUPPORT_CP (1 << 5) 11341ec0267Sriastradh #define AMD_PG_SUPPORT_GDS (1 << 6) 11441ec0267Sriastradh #define AMD_PG_SUPPORT_RLC_SMU_HS (1 << 7) 11541ec0267Sriastradh #define AMD_PG_SUPPORT_SDMA (1 << 8) 11641ec0267Sriastradh #define AMD_PG_SUPPORT_ACP (1 << 9) 11741ec0267Sriastradh #define AMD_PG_SUPPORT_SAMU (1 << 10) 11841ec0267Sriastradh #define AMD_PG_SUPPORT_GFX_QUICK_MG (1 << 11) 11941ec0267Sriastradh #define AMD_PG_SUPPORT_GFX_PIPELINE (1 << 12) 12041ec0267Sriastradh #define AMD_PG_SUPPORT_MMHUB (1 << 13) 12141ec0267Sriastradh #define AMD_PG_SUPPORT_VCN (1 << 14) 12241ec0267Sriastradh #define AMD_PG_SUPPORT_VCN_DPG (1 << 15) 12341ec0267Sriastradh #define AMD_PG_SUPPORT_ATHUB (1 << 16) 12441ec0267Sriastradh #define AMD_PG_SUPPORT_JPEG (1 << 17) 12541ec0267Sriastradh 12641ec0267Sriastradh enum PP_FEATURE_MASK { 12741ec0267Sriastradh PP_SCLK_DPM_MASK = 0x1, 12841ec0267Sriastradh PP_MCLK_DPM_MASK = 0x2, 12941ec0267Sriastradh PP_PCIE_DPM_MASK = 0x4, 13041ec0267Sriastradh PP_SCLK_DEEP_SLEEP_MASK = 0x8, 13141ec0267Sriastradh PP_POWER_CONTAINMENT_MASK = 0x10, 13241ec0267Sriastradh PP_UVD_HANDSHAKE_MASK = 0x20, 13341ec0267Sriastradh PP_SMC_VOLTAGE_CONTROL_MASK = 0x40, 13441ec0267Sriastradh PP_VBI_TIME_SUPPORT_MASK = 0x80, 13541ec0267Sriastradh PP_ULV_MASK = 0x100, 13641ec0267Sriastradh PP_ENABLE_GFX_CG_THRU_SMU = 0x200, 13741ec0267Sriastradh PP_CLOCK_STRETCH_MASK = 0x400, 13841ec0267Sriastradh PP_OD_FUZZY_FAN_CONTROL_MASK = 0x800, 13941ec0267Sriastradh PP_SOCCLK_DPM_MASK = 0x1000, 14041ec0267Sriastradh PP_DCEFCLK_DPM_MASK = 0x2000, 14141ec0267Sriastradh PP_OVERDRIVE_MASK = 0x4000, 14241ec0267Sriastradh PP_GFXOFF_MASK = 0x8000, 14341ec0267Sriastradh PP_ACG_MASK = 0x10000, 14441ec0267Sriastradh PP_STUTTER_MODE = 0x20000, 14541ec0267Sriastradh PP_AVFS_MASK = 0x40000, 14641ec0267Sriastradh }; 14741ec0267Sriastradh 14841ec0267Sriastradh enum DC_FEATURE_MASK { 14941ec0267Sriastradh DC_FBC_MASK = 0x1, 15041ec0267Sriastradh DC_MULTI_MON_PP_MCLK_SWITCH_MASK = 0x2, 15141ec0267Sriastradh DC_DISABLE_FRACTIONAL_PWM_MASK = 0x4, 15241ec0267Sriastradh DC_PSR_MASK = 0x8, 15341ec0267Sriastradh }; 15441ec0267Sriastradh 15541ec0267Sriastradh enum amd_dpm_forced_level; 15641ec0267Sriastradh /** 15741ec0267Sriastradh * struct amd_ip_funcs - general hooks for managing amdgpu IP Blocks 15841ec0267Sriastradh */ 159efa246c0Sriastradh struct amd_ip_funcs { 16041ec0267Sriastradh /** @name: Name of IP block */ 161*e4a580baSriastradh const char *name; 16241ec0267Sriastradh /** 16341ec0267Sriastradh * @early_init: 16441ec0267Sriastradh * 16541ec0267Sriastradh * sets up early driver state (pre sw_init), 16641ec0267Sriastradh * does not configure hw - Optional 16741ec0267Sriastradh */ 168efa246c0Sriastradh int (*early_init)(void *handle); 16941ec0267Sriastradh /** @late_init: sets up late driver/hw state (post hw_init) - Optional */ 170efa246c0Sriastradh int (*late_init)(void *handle); 17141ec0267Sriastradh /** @sw_init: sets up driver state, does not configure hw */ 172efa246c0Sriastradh int (*sw_init)(void *handle); 17341ec0267Sriastradh /** @sw_fini: tears down driver state, does not configure hw */ 174efa246c0Sriastradh int (*sw_fini)(void *handle); 17541ec0267Sriastradh /** @hw_init: sets up the hw state */ 176efa246c0Sriastradh int (*hw_init)(void *handle); 17741ec0267Sriastradh /** @hw_fini: tears down the hw state */ 178efa246c0Sriastradh int (*hw_fini)(void *handle); 17941ec0267Sriastradh /** @late_fini: final cleanup */ 18041ec0267Sriastradh void (*late_fini)(void *handle); 18141ec0267Sriastradh /** @suspend: handles IP specific hw/sw changes for suspend */ 182efa246c0Sriastradh int (*suspend)(void *handle); 18341ec0267Sriastradh /** @resume: handles IP specific hw/sw changes for resume */ 184efa246c0Sriastradh int (*resume)(void *handle); 18541ec0267Sriastradh /** @is_idle: returns current IP block idle status */ 186efa246c0Sriastradh bool (*is_idle)(void *handle); 18741ec0267Sriastradh /** @wait_for_idle: poll for idle */ 188efa246c0Sriastradh int (*wait_for_idle)(void *handle); 18941ec0267Sriastradh /** @check_soft_reset: check soft reset the IP block */ 19041ec0267Sriastradh bool (*check_soft_reset)(void *handle); 19141ec0267Sriastradh /** @pre_soft_reset: pre soft reset the IP block */ 19241ec0267Sriastradh int (*pre_soft_reset)(void *handle); 19341ec0267Sriastradh /** @soft_reset: soft reset the IP block */ 194efa246c0Sriastradh int (*soft_reset)(void *handle); 19541ec0267Sriastradh /** @post_soft_reset: post soft reset the IP block */ 19641ec0267Sriastradh int (*post_soft_reset)(void *handle); 19741ec0267Sriastradh /** @set_clockgating_state: enable/disable cg for the IP block */ 198efa246c0Sriastradh int (*set_clockgating_state)(void *handle, 199efa246c0Sriastradh enum amd_clockgating_state state); 20041ec0267Sriastradh /** @set_powergating_state: enable/disable pg for the IP block */ 201efa246c0Sriastradh int (*set_powergating_state)(void *handle, 202efa246c0Sriastradh enum amd_powergating_state state); 20341ec0267Sriastradh /** @get_clockgating_state: get current clockgating status */ 20441ec0267Sriastradh void (*get_clockgating_state)(void *handle, u32 *flags); 20541ec0267Sriastradh /** @enable_umd_pstate: enable UMD powerstate */ 20641ec0267Sriastradh int (*enable_umd_pstate)(void *handle, enum amd_dpm_forced_level *level); 207efa246c0Sriastradh }; 208efa246c0Sriastradh 20941ec0267Sriastradh 210efa246c0Sriastradh #endif /* __AMD_SHARED_H__ */ 211