drm/amd/powerplay: Introduce iceland powerplay support
Subsystems (2)
cover drm/amd/powerplay: Introduce iceland powerplay support
From: Huang Rui <[email protected]>
Hi all,
Part I: https://lists.freedesktop.org/archives/amd-gfx/2016-July/000569.html
After add the prep (Part I) of iceland powerplay, this part (Part II) introduces iceland powerplay support, and there is two sub-part:
1) Patch 1 - 9: add SMU and HW manager function support.
2) Patch 10 - 15: resolve the DPM issue.
Thanks,
Rui
Huang Rui (15):
drm/amd/powerplay: add SMU71 header files for iceland (v2) drm/amd/powerplay: add iceland SMU mananger
drm/amdgpu: add new definition in bif header drm/amd/powerplay: add iceland_dyn_defaults header drm/amdgpu: make amdgpu_cgs_call_acpi_method as static drm/amdgpu: fix incorrect type of info_id
drm/amdgpu: add query device id and revision id into system info entry
at CGS
drm/amd/powerplay: add iceland HW manager
drm/amdgpu: enable iceland powerplay manually drm/amd/powerplay: rename smum header guards drm/amd/powerplay: fix the incorrect checking condition drm/amd/powerplay: add deep sleep initialization drm/amd/powerplay: set the platform capability flags for iceland drm/amd/powerplay: add enabling voltage controller back drm/amd/powerplay: add DPM running checking back
drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c | 10 +- drivers/gpu/drm/amd/amdgpu/amdgpu_powerplay.c | 4 +- drivers/gpu/drm/amd/amdgpu/iceland_smum.h | 4 +- .../gpu/drm/amd/include/asic_reg/bif/bif_5_0_d.h | 1 + drivers/gpu/drm/amd/include/cgs_common.h | 12 +- drivers/gpu/drm/amd/powerplay/hwmgr/Makefile | 4 +- drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c | 4 + .../amd/powerplay/hwmgr/iceland_clockpowergating.c | 119 + .../amd/powerplay/hwmgr/iceland_clockpowergating.h | 38 + .../drm/amd/powerplay/hwmgr/iceland_dyn_defaults.h | 41 + .../gpu/drm/amd/powerplay/hwmgr/iceland_hwmgr.c | 5698 ++++++++++++++++++++ .../gpu/drm/amd/powerplay/hwmgr/iceland_hwmgr.h | 424 ++ .../drm/amd/powerplay/hwmgr/iceland_powertune.c | 491 ++ .../drm/amd/powerplay/hwmgr/iceland_powertune.h | 74 + .../gpu/drm/amd/powerplay/hwmgr/iceland_thermal.c | 595 ++ .../gpu/drm/amd/powerplay/hwmgr/iceland_thermal.h | 58 + drivers/gpu/drm/amd/powerplay/inc/smu71.h | 510 ++ drivers/gpu/drm/amd/powerplay/inc/smu71_discrete.h | 631 +++ drivers/gpu/drm/amd/powerplay/smumgr/Makefile | 3 +- .../gpu/drm/amd/powerplay/smumgr/iceland_smumgr.c | 713 +++ .../gpu/drm/amd/powerplay/smumgr/iceland_smumgr.h | 64 + drivers/gpu/drm/amd/powerplay/smumgr/smumgr.c | 4 + 22 files changed, 9490 insertions(+), 12 deletions(-) create mode 100644 drivers/gpu/drm/amd/powerplay/hwmgr/iceland_clockpowergating.c create mode 100644 drivers/gpu/drm/amd/powerplay/hwmgr/iceland_clockpowergating.h create mode 100644 drivers/gpu/drm/amd/powerplay/hwmgr/iceland_dyn_defaults.h create mode 100644 drivers/gpu/drm/amd/powerplay/hwmgr/iceland_hwmgr.c create mode 100644 drivers/gpu/drm/amd/powerplay/hwmgr/iceland_hwmgr.h create mode 100644 drivers/gpu/drm/amd/powerplay/hwmgr/iceland_powertune.c create mode 100644 drivers/gpu/drm/amd/powerplay/hwmgr/iceland_powertune.h create mode 100644 drivers/gpu/drm/amd/powerplay/hwmgr/iceland_thermal.c create mode 100644 drivers/gpu/drm/amd/powerplay/hwmgr/iceland_thermal.h create mode 100644 drivers/gpu/drm/amd/powerplay/inc/smu71.h create mode 100644 drivers/gpu/drm/amd/powerplay/inc/smu71_discrete.h create mode 100644 drivers/gpu/drm/amd/powerplay/smumgr/iceland_smumgr.c create mode 100644 drivers/gpu/drm/amd/powerplay/smumgr/iceland_smumgr.h
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 1469690705-877-1-git-send-email-ray.huang-5C7GfCeVMHo@public.gmane.org
PATCH 1/15 drm/amd/powerplay: add SMU71 header files for iceland (v2)
v2: cleanup headers, add copyright
--- drivers/gpu/drm/amd/powerplay/inc/smu71.h | 510 +++++++++++++++++ drivers/gpu/drm/amd/powerplay/inc/smu71_discrete.h | 631 +++++++++++++++++++++ 2 files changed, 1141 insertions(+) create mode 100644 drivers/gpu/drm/amd/powerplay/inc/smu71.h create mode 100644 drivers/gpu/drm/amd/powerplay/inc/smu71_discrete.h
drivers/gpu/drm/amd/powerplay/inc/smu71.h new file +510 -0
@@ -0,0 +1,510 @@ +/* +* Copyright 2016 Advanced Micro Devices, Inc. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +* +*/ +#ifndef SMU71_H +#define SMU71_H + +#if !defined(SMC_MICROCODE ) +#pragma pack(push, 1) +#endif + +#define SMU__NUM_PCIE_DPM_LEVELS 8 +#define SMU__NUM_SCLK_DPM_STATE 8 +#define SMU__NUM_MCLK_DPM_LEVELS 4 +#define SMU__VARIANT__ICELAND 1 +#define SMU__DGPU_ONLY 1 +#define SMU__DYNAMIC_MCARB_SETTINGS 1 + +enum SID_OPTION { +SID_OPTION_HI , +SID_OPTION_LO , +SID_OPTION_COUNT +}; + +typedef struct { +uint32_t high; +uint32_t low; +}data_64_t ; + +typedef struct { +data_64_t high; +data_64_t low; +}data_128_t ; + +#define SMU7_CONTEXT_ID_SMC 1 +#define SMU7_CONTEXT_ID_VBIOS 2 + +#define SMU71_MAX_LEVELS_VDDC 8 +#define SMU71_MAX_LEVELS_VDDCI 4 +#define SMU71_MAX_LEVELS_MVDD 4 +#define SMU71_MAX_LEVELS_VDDNB 8 + +#define SMU71_MAX_LEVELS_GRAPHICS SMU__NUM_SCLK_DPM_STATE +#define SMU71_MAX_LEVELS_MEMORY SMU__NUM_MCLK_DPM_LEVELS +#define SMU71_MAX_LEVELS_GIO SMU__NUM_LCLK_DPM_LEVELS +#define SMU71_MAX_LEVELS_LINK SMU__NUM_PCIE_DPM_LEVELS +#define SMU71_MAX_ENTRIES_SMIO 32 + +#define DPM_NO_LIMIT 0 +#define DPM_NO_UP 1 +#define DPM_GO_DOWN 2 +#define DPM_GO_UP 3 + +#define SMU7_FIRST_DPM_GRAPHICS_LEVEL 0 +#define SMU7_FIRST_DPM_MEMORY_LEVEL 0 + +#define GPIO_CLAMP_MODE_VRHOT 1 +#define GPIO_CLAMP_MODE_THERM 2 +#define GPIO_CLAMP_MODE_DC 4 + +#define SCRATCH_B_TARG_PCIE_INDEX_SHIFT 0 +#define SCRATCH_B_TARG_PCIE_INDEX_MASK (0x7<<SCRATCH_B_TARG_PCIE_INDEX_SHIFT) +#define SCRATCH_B_CURR_PCIE_INDEX_SHIFT 3 +#define SCRATCH_B_CURR_PCIE_INDEX_MASK (0x7<<SCRATCH_B_CURR_PCIE_INDEX_SHIFT) +#define SCRATCH_B_TARG_UVD_INDEX_SHIFT 6 +#define SCRATCH_B_TARG_UVD_INDEX_MASK (0x7<<SCRATCH_B_TARG_UVD_INDEX_SHIFT) +#define SCRATCH_B_CURR_UVD_INDEX_SHIFT 9 +#define SCRATCH_B_CURR_UVD_INDEX_MASK (0x7<<SCRATCH_B_CURR_UVD_INDEX_SHIFT) +#define SCRATCH_B_TARG_VCE_INDEX_SHIFT 12 +#define SCRATCH_B_TARG_VCE_INDEX_MASK (0x7<<SCRATCH_B_TARG_VCE_INDEX_SHIFT) +#define SCRATCH_B_CURR_VCE_INDEX_SHIFT 15 +#define SCRATCH_B_CURR_VCE_INDEX_MASK (0x7<<SCRATCH_B_CURR_VCE_INDEX_SHIFT) +#define SCRATCH_B_TARG_ACP_INDEX_SHIFT 18 +#define SCRATCH_B_TARG_ACP_INDEX_MASK (0x7<<SCRATCH_B_TARG_ACP_INDEX_SHIFT) +#define SCRATCH_B_CURR_ACP_INDEX_SHIFT 21 +#define SCRATCH_B_CURR_ACP_INDEX_MASK (0x7<<SCRATCH_B_CURR_ACP_INDEX_SHIFT) +#define SCRATCH_B_TARG_SAMU_INDEX_SHIFT 24 +#define SCRATCH_B_TARG_SAMU_INDEX_MASK (0x7<<SCRATCH_B_TARG_SAMU_INDEX_SHIFT) +#define SCRATCH_B_CURR_SAMU_INDEX_SHIFT 27 +#define SCRATCH_B_CURR_SAMU_INDEX_MASK (0x7<<SCRATCH_B_CURR_SAMU_INDEX_SHIFT) + + +#if definedSMU__DGPU_ONLY +#define SMU71_DTE_ITERATIONS 5 +#define SMU71_DTE_SOURCES 3 +#define SMU71_DTE_SINKS 1 +#define SMU71_NUM_CPU_TES 0 +#define SMU71_NUM_GPU_TES 1 +#define SMU71_NUM_NON_TES 2 + +#endif + +#if definedSMU__FUSION_ONLY +#define SMU7_DTE_ITERATIONS 5 +#define SMU7_DTE_SOURCES 5 +#define SMU7_DTE_SINKS 3 +#define SMU7_NUM_CPU_TES 2 +#define SMU7_NUM_GPU_TES 1 +#define SMU7_NUM_NON_TES 2 + +#endif + +struct SMU71_PIDController +{ +uint32_t Ki; +int32_t LFWindupUpperLim; +int32_t LFWindupLowerLim; +uint32_t StatePrecision; +uint32_t LfPrecision; +uint32_t LfOffset; +uint32_t MaxState; +uint32_t MaxLfFraction; +uint32_t StateShift; +}; + +typedef struct SMU71_PIDController SMU71_PIDController ; + +struct SMU7_LocalDpmScoreboard +{ +uint32_t PercentageBusy; + +int32_t PIDError; +int32_t PIDIntegral; +int32_t PIDOutput; + +uint32_t SigmaDeltaAccum; +uint32_t SigmaDeltaOutput; +uint32_t SigmaDeltaLevel; + +uint32_t UtilizationSetpoint; + +uint8_t TdpClampMode; +uint8_t TdcClampMode; +uint8_t ThermClampMode; +uint8_t VoltageBusy; + +int8_t CurrLevel; +int8_t TargLevel; +uint8_t LevelChangeInProgress; +uint8_t UpHyst; + +uint8_t DownHyst; +uint8_t VoltageDownHyst; +uint8_t DpmEnable; +uint8_t DpmRunning; + +uint8_t DpmForce; +uint8_t DpmForceLevel; +uint8_t DisplayWatermark; +uint8_t McArbIndex; + +uint32_t MinimumPerfSclk; + +uint8_t AcpiReq; +uint8_t AcpiAck; +uint8_t GfxClkSlow; +uint8_t GpioClampMode; + +uint8_t FpsFilterWeight; +uint8_t EnabledLevelsChange; +uint8_t DteClampMode; +uint8_t FpsClampMode; + +uint16_t LevelResidencyCounters [SMU71_MAX_LEVELS_GRAPHICS ]; +uint16_t LevelSwitchCounters [SMU71_MAX_LEVELS_GRAPHICS ]; + +void (*TargetStateCalculator)(uint8_t ); +void (*SavedTargetStateCalculator)(uint8_t ); + +uint16_t AutoDpmInterval; +uint16_t AutoDpmRange; + +uint8_t FpsEnabled; +uint8_t MaxPerfLevel; +uint8_t AllowLowClkInterruptToHost; +uint8_t FpsRunning; + +uint32_t MaxAllowedFrequency; +}; + +typedef struct SMU7_LocalDpmScoreboard SMU7_LocalDpmScoreboard ; + +#define SMU7_MAX_VOLTAGE_CLIENTS 12 + +struct SMU7_VoltageScoreboard +{ +uint16_t CurrentVoltage; +uint16_t HighestVoltage; +uint16_t MaxVid; +uint8_t HighestVidOffset; +uint8_t CurrentVidOffset; +#if defined (SMU__DGPU_ONLY ) +uint8_t CurrentPhases; +uint8_t HighestPhases; +#else +uint8_t AvsOffset; +uint8_t AvsOffsetApplied; +#endif +uint8_t ControllerBusy; +uint8_t CurrentVid; +uint16_t RequestedVoltage[SMU7_MAX_VOLTAGE_CLIENTS ]; +#if defined (SMU__DGPU_ONLY ) +uint8_t RequestedPhases[SMU7_MAX_VOLTAGE_CLIENTS ]; +#endif +uint8_t EnabledRequest[SMU7_MAX_VOLTAGE_CLIENTS ]; +uint8_t TargetIndex; +uint8_t Delay; +uint8_t ControllerEnable; +uint8_t ControllerRunning; +uint16_t CurrentStdVoltageHiSidd; +uint16_t CurrentStdVoltageLoSidd; +#if defined (SMU__DGPU_ONLY ) +uint16_t RequestedVddci; +uint16_t CurrentVddci; +uint16_t HighestVddci; +uint8_t CurrentVddciVid; +uint8_t TargetVddciIndex; +#endif +}; + +typedef struct SMU7_VoltageScoreboard SMU7_VoltageScoreboard ; + +// ------------------------------------------------------------------------------------------------------------------------- +#define SMU7_MAX_PCIE_LINK_SPEEDS 3/* 0:Gen1 1:Gen2 2:Gen3 */ + +struct SMU7_PCIeLinkSpeedScoreboard +{ +uint8_t DpmEnable; +uint8_t DpmRunning; +uint8_t DpmForce; +uint8_t DpmForceLevel; + +uint8_t CurrentLinkSpeed; +uint8_t EnabledLevelsChange; +uint16_t AutoDpmInterval; + +uint16_t AutoDpmRange; +uint16_t AutoDpmCount; + +uint8_t DpmMode; +uint8_t AcpiReq; +uint8_t AcpiAck; +uint8_t CurrentLinkLevel; + +}; + +typedef struct SMU7_PCIeLinkSpeedScoreboard SMU7_PCIeLinkSpeedScoreboard ; + +// -------------------------------------------------------- CAC table ------------------------------------------------------ +#define SMU7_LKGE_LUT_NUM_OF_TEMP_ENTRIES 16 +#define SMU7_LKGE_LUT_NUM_OF_VOLT_ENTRIES 16 + +#define SMU7_SCALE_I 7 +#define SMU7_SCALE_R 12 + +struct SMU7_PowerScoreboard +{ +uint16_t MinVoltage; +uint16_t MaxVoltage; + +uint32_t AvgGpuPower; + +uint16_t VddcLeakagePower[SID_OPTION_COUNT ]; +uint16_t VddcSclkConstantPower[SID_OPTION_COUNT ]; +uint16_t VddcSclkDynamicPower[SID_OPTION_COUNT ]; +uint16_t VddcNonSclkDynamicPower[SID_OPTION_COUNT ]; +uint16_t VddcTotalPower[SID_OPTION_COUNT ]; +uint16_t VddcTotalCurrent[SID_OPTION_COUNT ]; +uint16_t VddcLoadVoltage[SID_OPTION_COUNT ]; +uint16_t VddcNoLoadVoltage[SID_OPTION_COUNT ]; + +uint16_t DisplayPhyPower; +uint16_t PciePhyPower; + +uint16_t VddciTotalPower; +uint16_t Vddr1TotalPower; + +uint32_t RocPower; + +uint32_t last_power; +uint32_t enableWinAvg; + +uint32_t lkg_acc; +uint16_t VoltLkgeScaler; +uint16_t TempLkgeScaler; + +uint32_t uvd_cac_dclk; +uint32_t uvd_cac_vclk; +uint32_t vce_cac_eclk; +uint32_t samu_cac_samclk; +uint32_t display_cac_dispclk; +uint32_t acp_cac_aclk; +uint32_t unb_cac; + +uint32_t WinTime; + +uint16_t GpuPwr_MAWt; +uint16_t FilteredVddcTotalPower; + +uint8_t CalculationRepeats; +uint8_t WaterfallUp; +uint8_t WaterfallDown; +uint8_t WaterfallLimit; +}; + +typedef struct SMU7_PowerScoreboard SMU7_PowerScoreboard ; + +// -------------------------------------------------------------------------------------------------- + +struct SMU7_ThermalScoreboard +{ +int16_t GpuLimit; +int16_t GpuHyst; +uint16_t CurrGnbTemp; +uint16_t FilteredGnbTemp; +uint8_t ControllerEnable; +uint8_t ControllerRunning; +uint8_t WaterfallUp; +uint8_t WaterfallDown; +uint8_t WaterfallLimit; +uint8_t padding[3 ]; +}; + +typedef struct SMU7_ThermalScoreboard SMU7_ThermalScoreboard ; + +// For FeatureEnables: +#define SMU7_SCLK_DPM_CONFIG_MASK 0x01 +#define SMU7_VOLTAGE_CONTROLLER_CONFIG_MASK 0x02 +#define SMU7_THERMAL_CONTROLLER_CONFIG_MASK 0x04 +#define SMU7_MCLK_DPM_CONFIG_MASK 0x08 +#define SMU7_UVD_DPM_CONFIG_MASK 0x10 +#define SMU7_VCE_DPM_CONFIG_MASK 0x20 +#define SMU7_ACP_DPM_CONFIG_MASK 0x40 +#define SMU7_SAMU_DPM_CONFIG_MASK 0x80 +#define SMU7_PCIEGEN_DPM_CONFIG_MASK 0x100 + +#define SMU7_ACP_MCLK_HANDSHAKE_DISABLE 0x00000001 +#define SMU7_ACP_SCLK_HANDSHAKE_DISABLE 0x00000002 +#define SMU7_UVD_MCLK_HANDSHAKE_DISABLE 0x00000100 +#define SMU7_UVD_SCLK_HANDSHAKE_DISABLE 0x00000200 +#define SMU7_VCE_MCLK_HANDSHAKE_DISABLE 0x00010000 +#define SMU7_VCE_SCLK_HANDSHAKE_DISABLE 0x00020000 + +// All 'soft registers' should be uint32_t. +struct SMU71_SoftRegisters +{ +uint32_t RefClockFrequency; +uint32_t PmTimerPeriod; +uint32_t FeatureEnables; +#if defined (SMU__DGPU_ONLY ) +uint32_t PreVBlankGap; +uint32_t VBlankTimeout; +uint32_t TrainTimeGap; +uint32_t MvddSwitchTime; +uint32_t LongestAcpiTrainTime; +uint32_t AcpiDelay; +uint32_t G5TrainTime; +uint32_t DelayMpllPwron; +uint32_t VoltageChangeTimeout; +#endif +uint32_t HandshakeDisables; + +uint8_t DisplayPhy1Config; +uint8_t DisplayPhy2Config; +uint8_t DisplayPhy3Config; +uint8_t DisplayPhy4Config; + +uint8_t DisplayPhy5Config; +uint8_t DisplayPhy6Config; +uint8_t DisplayPhy7Config; +uint8_t DisplayPhy8Config; + +uint32_t AverageGraphicsActivity; +uint32_t AverageMemoryActivity; +uint32_t AverageGioActivity; + +uint8_t SClkDpmEnabledLevels; +uint8_t MClkDpmEnabledLevels; +uint8_t LClkDpmEnabledLevels; +uint8_t PCIeDpmEnabledLevels; + +uint32_t DRAM_LOG_ADDR_H; +uint32_t DRAM_LOG_ADDR_L; +uint32_t DRAM_LOG_PHY_ADDR_H; +uint32_t DRAM_LOG_PHY_ADDR_L; +uint32_t DRAM_LOG_BUFF_SIZE; +uint32_t UlvEnterCount; +uint32_t UlvTime; +uint32_t UcodeLoadStatus; +uint8_t DPMFreezeAndForced; +uint8_t Activity_Weight; +uint8_t Reserved8[2 ]; +uint32_t Reserved; +}; + +typedef struct SMU71_SoftRegisters SMU71_SoftRegisters ; + +struct SMU71_Firmware_Header +{ +uint32_t Digest[5 ]; +uint32_t Version; +uint32_t HeaderSize; +uint32_t Flags; +uint32_t EntryPoint; +uint32_t CodeSize; +uint32_t ImageSize; + +uint32_t Rtos; +uint32_t SoftRegisters; +uint32_t DpmTable; +uint32_t FanTable; +uint32_t CacConfigTable; +uint32_t CacStatusTable; + +uint32_t mcRegisterTable; + +uint32_t mcArbDramTimingTable; + +uint32_t PmFuseTable; +uint32_t Globals; +uint32_t UvdDpmTable; +uint32_t AcpDpmTable; +uint32_t VceDpmTable; +uint32_t SamuDpmTable; +uint32_t UlvSettings; +uint32_t Reserved[37 ]; +uint32_t Signature; +}; + +typedef struct SMU71_Firmware_Header SMU71_Firmware_Header ; + +struct SMU7_HystController_Data +{ +uint8_t waterfall_up; +uint8_t waterfall_down; +uint8_t pstate; +uint8_t clamp_mode; +}; + +typedef struct SMU7_HystController_Data SMU7_HystController_Data ; + +#define SMU71_FIRMWARE_HEADER_LOCATION 0x20000 + +enum DisplayConfig { + PowerDown =1 , + DP54x4, + DP54x2, + DP54x1, + DP27x4, + DP27x2, + DP27x1, +HDMI297 , +HDMI162 , +LVDS , + DP324x4, + DP324x2, + DP324x1 +}; + +//#define SX_BLOCK_COUNT 8 +//#define MC_BLOCK_COUNT 1 +//#define CPL_BLOCK_COUNT 27 + +#if definedSMU__VARIANT__ICELAND +#define SX_BLOCK_COUNT 8 +#define MC_BLOCK_COUNT 1 +#define CPL_BLOCK_COUNT 29 +#endif + +struct SMU7_Local_Cac { +uint8_t BlockId; +uint8_t SignalId; +uint8_t Threshold; +uint8_t Padding; +}; + +typedef struct SMU7_Local_Cac SMU7_Local_Cac ; + +struct SMU7_Local_Cac_Table { +SMU7_Local_Cac SxLocalCac[SX_BLOCK_COUNT ]; +SMU7_Local_Cac CplLocalCac[CPL_BLOCK_COUNT ]; +SMU7_Local_Cac McLocalCac[MC_BLOCK_COUNT ]; +}; + +typedef struct SMU7_Local_Cac_Table SMU7_Local_Cac_Table ; + +#if !defined(SMC_MICROCODE ) +#pragma pack(pop) +#endif + +#endif +
drivers/gpu/drm/amd/powerplay/inc/smu71_discrete.h new file +631 -0
631 lines not on this page · raw message
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 2/15 drm/amd/powerplay: add iceland SMU mananger
In reply to a message not in the archiveThe system management unit (SMU) is a subcomponent of the northbridge that is responsible for a variety of system and power management tasks during boot and runtime for GPU. In powerplay, it will be used on firmware loading and power task management. This patch adds SMU mananger for iceland.
--- drivers/gpu/drm/amd/powerplay/smumgr/Makefile | 3 +- .../gpu/drm/amd/powerplay/smumgr/iceland_smumgr.c | 713 +++++++++++++++++++++ .../gpu/drm/amd/powerplay/smumgr/iceland_smumgr.h | 64 ++ drivers/gpu/drm/amd/powerplay/smumgr/smumgr.c | 4 + 4 files changed, 783 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/amd/powerplay/smumgr/iceland_smumgr.c create mode 100644 drivers/gpu/drm/amd/powerplay/smumgr/iceland_smumgr.h
drivers/gpu/drm/amd/powerplay/smumgr/Makefile +2 -1
@@ -2,7 +2,8 @@ # Makefile for the 'smu manager' sub-component of powerplay. # It provides the smu management services for the driver. -SMU_MGR = smumgr.o cz_smumgr.o tonga_smumgr.o fiji_smumgr.o polaris10_smumgr.o +SMU_MGR = smumgr.o cz_smumgr.o tonga_smumgr.o fiji_smumgr.o \ + polaris10_smumgr.o iceland_smumgr.o AMD_PP_SMUMGR = $(addprefix $(AMD_PP_PATH)/smumgr/,$(SMU_MGR))
drivers/gpu/drm/amd/powerplay/smumgr/iceland_smumgr.c new file +713 -0
713 lines not on this page · raw message
drivers/gpu/drm/amd/powerplay/smumgr/iceland_smumgr.h new file +64 -0
64 lines not on this page · raw message
drivers/gpu/drm/amd/powerplay/smumgr/smumgr.c +4 -0
@@ -30,6 +30,7 @@#include "linux/delay.h" #include "cz_smumgr.h" #include "tonga_smumgr.h" +#include "iceland_smumgr.h" #include "fiji_smumgr.h" #include "polaris10_smumgr.h"
@@ -58,6 +59,9 @@ int smum_init(struct amd_pp_init *pp_init, struct pp_instance *handle)break ;case AMDGPU_FAMILY_VI :switch (smumgr->chip_id) { +case CHIP_TOPAZ : +iceland_smum_init (smumgr); +break ;case CHIP_TONGA :tonga_smum_init (smumgr);break ;
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 3/15 drm/amdgpu: add new definition in bif header
In reply to a message not in the archiveThis patch adds new definition in bif header, and will be used on iceland HW powertune part.
--- drivers/gpu/drm/amd/include/asic_reg/bif/bif_5_0_d.h | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/include/asic_reg/bif/bif_5_0_d.h +1 -0
@@ -27,6 +27,7 @@#define mmMM_INDEX 0x0#define mmMM_INDEX_HI 0x6#define mmMM_DATA 0x1 +#define mmCC_BIF_BX_STRAP2 0x152A#define mmBIF_MM_INDACCESS_CNTL 0x1500#define mmBIF_DOORBELL_APER_EN 0x1501#define mmBUS_CNTL 0x1508
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 4/15 drm/amd/powerplay: add iceland_dyn_defaults header
In reply to a message not in the archive--- .../drm/amd/powerplay/hwmgr/iceland_dyn_defaults.h | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 drivers/gpu/drm/amd/powerplay/hwmgr/iceland_dyn_defaults.h
drivers/gpu/drm/amd/powerplay/hwmgr/iceland_dyn_defaults.h new file +41 -0
@@ -0,0 +1,41 @@ +#ifndef ICELAND_DYN_DEFAULTS_H +#define ICELAND_DYN_DEFAULTS_H + +enum ICELANDdpm_TrendDetection +{ + ICELANDdpm_TrendDetection_AUTO, + ICELANDdpm_TrendDetection_UP, + ICELANDdpm_TrendDetection_DOWN +}; +typedef enum ICELANDdpm_TrendDetection ICELANDdpm_TrendDetection ; + + +#define PPICELAND_VOTINGRIGHTSCLIENTS_DFLT0 0x3FFFC102 +#define PPICELAND_VOTINGRIGHTSCLIENTS_DFLT1 0x000400 +#define PPICELAND_VOTINGRIGHTSCLIENTS_DFLT2 0xC00080 +#define PPICELAND_VOTINGRIGHTSCLIENTS_DFLT3 0xC00200 +#define PPICELAND_VOTINGRIGHTSCLIENTS_DFLT4 0xC01680 +#define PPICELAND_VOTINGRIGHTSCLIENTS_DFLT5 0xC00033 +#define PPICELAND_VOTINGRIGHTSCLIENTS_DFLT6 0xC00033 +#define PPICELAND_VOTINGRIGHTSCLIENTS_DFLT7 0x3FFFC000 + + +#define PPICELAND_THERMALPROTECTCOUNTER_DFLT 0x200 + +#define PPICELAND_STATICSCREENTHRESHOLDUNIT_DFLT 0 + +#define PPICELAND_STATICSCREENTHRESHOLD_DFLT 0x00C8 + +#define PPICELAND_GFXIDLECLOCKSTOPTHRESHOLD_DFLT 0x200 + +#define PPICELAND_REFERENCEDIVIDER_DFLT 4 + +#define PPICELAND_ULVVOLTAGECHANGEDELAY_DFLT 1687 + +#define PPICELAND_CGULVPARAMETER_DFLT 0x00040035 +#define PPICELAND_CGULVCONTROL_DFLT 0x00007450 +#define PPICELAND_TARGETACTIVITY_DFLT 30 +#define PPICELAND_MCLK_TARGETACTIVITY_DFLT 10 + +#endif +
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 5/15 drm/amdgpu: make amdgpu_cgs_call_acpi_method as static
In reply to a message not in the archive--- drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c +1 -1
@@ -1078,7 +1078,7 @@ static int amdgpu_cgs_acpi_eval_object(struct cgs_device *cgs_device, }#endif -int amdgpu_cgs_call_acpi_method(struct cgs_device *cgs_device, +static int amdgpu_cgs_call_acpi_method(struct cgs_device *cgs_device, uint32_t acpi_method, uint32_t acpi_function, void *pinput, void *poutput,
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 6/15 drm/amdgpu: fix incorrect type of info_id
In reply to a message not in the archive--- drivers/gpu/drm/amd/include/cgs_common.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/include/cgs_common.h +5 -5
@@ -121,13 +121,13 @@ enum cgs_system_info_id { };struct cgs_system_info { -uint64_t size; -uint64_t info_id; +uint64_t size; +enum cgs_system_info_id info_id;union { -void *ptr; -uint64_t value; +void *ptr; +uint64_t value; }; -uint64_t padding[13 ]; +uint64_t padding[13 ]; };/*
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 7/15 drm/amdgpu: add query device id and revision id into system info entry at CGS
In reply to a message not in the archiveThis patch adds device id and revision into system info entry at CGS, it's able to get PCI device id and revision id from amdgpu, it might get more info in future.
PCI device id will be also used on powerplay part at current.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c | 8 +++++++- drivers/gpu/drm/amd/include/cgs_common.h | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c +7 -1
@@ -810,7 +810,7 @@ static int amdgpu_cgs_get_firmware_info(struct cgs_device *cgs_device, }static int amdgpu_cgs_query_system_info (struct cgs_device *cgs_device, -struct cgs_system_info *sys_info) +struct cgs_system_info *sys_info) {CGS_FUNC_ADEV ;
@@ -830,6 +830,12 @@ static int amdgpu_cgs_query_system_info(struct cgs_device *cgs_device,case CGS_SYSTEM_INFO_PCIE_MLW : sys_info->value = adev->pm.pcie_mlw_mask;break ; +case CGS_SYSTEM_INFO_PCIE_DEV : + sys_info->value = adev->pdev->device; +break ; +case CGS_SYSTEM_INFO_PCIE_REV : + sys_info->value = adev->pdev->revision; +break ;case CGS_SYSTEM_INFO_CG_FLAGS : sys_info->value = adev->cg_flags;break ;
drivers/gpu/drm/amd/include/cgs_common.h +2 -0
@@ -113,6 +113,8 @@ enum cgs_system_info_id {CGS_SYSTEM_INFO_ADAPTER_BDF_ID =1 ,CGS_SYSTEM_INFO_PCIE_GEN_INFO ,CGS_SYSTEM_INFO_PCIE_MLW , +CGS_SYSTEM_INFO_PCIE_DEV , +CGS_SYSTEM_INFO_PCIE_REV ,CGS_SYSTEM_INFO_CG_FLAGS ,CGS_SYSTEM_INFO_PG_FLAGS , CGS_SYSTEM_INFO_GFX_CU_INFO,
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 8/15 drm/amd/powerplay: add iceland HW manager
In reply to a message not in the archiveThis patch introduces the iceland HW manager of powerplay which includes HW manager, clockpowergating, thermal, and powertune.
--- drivers/gpu/drm/amd/powerplay/hwmgr/Makefile | 4 +- drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c | 4 + .../amd/powerplay/hwmgr/iceland_clockpowergating.c | 119 + .../amd/powerplay/hwmgr/iceland_clockpowergating.h | 38 + .../gpu/drm/amd/powerplay/hwmgr/iceland_hwmgr.c | 5617 ++++++++++++++++++++ .../gpu/drm/amd/powerplay/hwmgr/iceland_hwmgr.h | 424 ++ .../drm/amd/powerplay/hwmgr/iceland_powertune.c | 491 ++ .../drm/amd/powerplay/hwmgr/iceland_powertune.h | 74 + .../gpu/drm/amd/powerplay/hwmgr/iceland_thermal.c | 595 +++ .../gpu/drm/amd/powerplay/hwmgr/iceland_thermal.h | 58 + 10 files changed, 7423 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/amd/powerplay/hwmgr/iceland_clockpowergating.c create mode 100644 drivers/gpu/drm/amd/powerplay/hwmgr/iceland_clockpowergating.h create mode 100644 drivers/gpu/drm/amd/powerplay/hwmgr/iceland_hwmgr.c create mode 100644 drivers/gpu/drm/amd/powerplay/hwmgr/iceland_hwmgr.h create mode 100644 drivers/gpu/drm/amd/powerplay/hwmgr/iceland_powertune.c create mode 100644 drivers/gpu/drm/amd/powerplay/hwmgr/iceland_powertune.h create mode 100644 drivers/gpu/drm/amd/powerplay/hwmgr/iceland_thermal.c create mode 100644 drivers/gpu/drm/amd/powerplay/hwmgr/iceland_thermal.h
drivers/gpu/drm/amd/powerplay/hwmgr/Makefile +3 -1
@@ -10,7 +10,9 @@ HARDWARE_MGR = hwmgr.o processpptables.o functiontables.o \ fiji_powertune.o fiji_hwmgr.o tonga_clockpowergating.o \ fiji_clockpowergating.o fiji_thermal.o \ polaris10_hwmgr.o polaris10_powertune.o polaris10_thermal.o \ - polaris10_clockpowergating.o + polaris10_clockpowergating.o iceland_hwmgr.o \ + iceland_clockpowergating.o iceland_thermal.o \ + iceland_powertune.o AMD_PP_HWMGR = $(addprefix $(AMD_PP_PATH)/hwmgr/,$(HARDWARE_MGR))
drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c +4 -0
@@ -39,6 +39,7 @@ extern int cz_hwmgr_init(struct pp_hwmgr *hwmgr);extern int tonga_hwmgr_init (struct pp_hwmgr *hwmgr);extern int fiji_hwmgr_init (struct pp_hwmgr *hwmgr);extern int polaris10_hwmgr_init (struct pp_hwmgr *hwmgr); +extern int iceland_hwmgr_init (struct pp_hwmgr *hwmgr);int hwmgr_init (struct amd_pp_init *pp_init,struct pp_instance *handle) {
@@ -67,6 +68,9 @@ int hwmgr_init(struct amd_pp_init *pp_init, struct pp_instance *handle)break ;case AMDGPU_FAMILY_VI :switch (hwmgr->chip_id) { +case CHIP_TOPAZ : +iceland_hwmgr_init (hwmgr); +break ;case CHIP_TONGA :tonga_hwmgr_init (hwmgr);break ;
drivers/gpu/drm/amd/powerplay/hwmgr/iceland_clockpowergating.c new file +119 -0
119 lines not on this page · raw message
drivers/gpu/drm/amd/powerplay/hwmgr/iceland_clockpowergating.h new file +38 -0
@@ -0,0 +1,38 @@ +/* +* Copyright 2016 Advanced Micro Devices, Inc. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +* +* Author: Huang Rui <[email protected]> +* +*/ + +#ifndef _ICELAND_CLOCK_POWER_GATING_H_ +#define _ICELAND_CLOCK_POWER_GATING_H_ + +#include "iceland_hwmgr.h" +#include "pp_asicblocks.h" + +extern int iceland_phm_set_asic_block_gating (struct pp_hwmgr *hwmgr,enum PHM_AsicBlock block,enum PHM_ClockGateSetting gating); +extern int iceland_phm_powergate_vce (struct pp_hwmgr *hwmgr,bool bgate); +extern int iceland_phm_powergate_uvd (struct pp_hwmgr *hwmgr,bool bgate); +extern int iceland_phm_powerdown_uvd (struct pp_hwmgr *hwmgr); +extern int iceland_phm_disable_clock_power_gating (struct pp_hwmgr *hwmgr); +extern int iceland_phm_update_clock_gatings (struct pp_hwmgr *hwmgr,const uint32_t *msg_id); +#endif /* _ICELAND_CLOCK_POWER_GATING_H_ */
drivers/gpu/drm/amd/powerplay/hwmgr/iceland_hwmgr.c new file +5617 -0
2,817 lines not on this page · raw message
drivers/gpu/drm/amd/powerplay/hwmgr/iceland_hwmgr.h new file +424 -0
424 lines not on this page · raw message
drivers/gpu/drm/amd/powerplay/hwmgr/iceland_powertune.c new file +491 -0
491 lines not on this page · raw message
drivers/gpu/drm/amd/powerplay/hwmgr/iceland_powertune.h new file +74 -0
74 lines not on this page · raw message
drivers/gpu/drm/amd/powerplay/hwmgr/iceland_thermal.c new file +595 -0
595 lines not on this page · raw message
drivers/gpu/drm/amd/powerplay/hwmgr/iceland_thermal.h new file +58 -0
58 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Part of the diff is not shown here. View the raw message.
A message that is not in the archive (sent off-list or not yet received): 1469690705-877-9-git-send-email-ray.huang-5C7GfCeVMHo@public.gmane.org
Re: [Part II PATCH 08/15] drm/amd/powerplay: add iceland HW manager
Quoted 3,754 lines · Huang Rui
This patch introduces the iceland HW manager of powerplay which includes HW manager, clockpowergating, thermal, and powertune.
Signed-off-by Huang Rui <[email protected]>Reviewed-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/powerplay/hwmgr/Makefile | 4 +- drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c | 4 + .../amd/powerplay/hwmgr/iceland_clockpowergating.c | 119 + .../amd/powerplay/hwmgr/iceland_clockpowergating.h | 38 + .../gpu/drm/amd/powerplay/hwmgr/iceland_hwmgr.c | 5617 ++++++++++++++++++++ .../gpu/drm/amd/powerplay/hwmgr/iceland_hwmgr.h | 424 ++ .../drm/amd/powerplay/hwmgr/iceland_powertune.c | 491 ++ .../drm/amd/powerplay/hwmgr/iceland_powertune.h | 74 + .../gpu/drm/amd/powerplay/hwmgr/iceland_thermal.c | 595 +++ .../gpu/drm/amd/powerplay/hwmgr/iceland_thermal.h | 58 + 10 files changed, 7423 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/amd/powerplay/hwmgr/iceland_clockpowergating.c create mode 100644 drivers/gpu/drm/amd/powerplay/hwmgr/iceland_clockpowergating.h create mode 100644 drivers/gpu/drm/amd/powerplay/hwmgr/iceland_hwmgr.c create mode 100644 drivers/gpu/drm/amd/powerplay/hwmgr/iceland_hwmgr.h create mode 100644 drivers/gpu/drm/amd/powerplay/hwmgr/iceland_powertune.c create mode 100644 drivers/gpu/drm/amd/powerplay/hwmgr/iceland_powertune.h create mode 100644 drivers/gpu/drm/amd/powerplay/hwmgr/iceland_thermal.c create mode 100644 drivers/gpu/drm/amd/powerplay/hwmgr/iceland_thermal.hdrivers/gpu/drm/amd/powerplay/hwmgr/Makefile +3
-1@@ -10,7 +10,9 @@ HARDWARE_MGR = hwmgr.o processpptables.o functiontables.o \ fiji_powertune.o fiji_hwmgr.o tonga_clockpowergating.o \ fiji_clockpowergating.o fiji_thermal.o \ polaris10_hwmgr.o polaris10_powertune.o polaris10_thermal.o \ - polaris10_clockpowergating.o + polaris10_clockpowergating.o iceland_hwmgr.o \ + iceland_clockpowergating.o iceland_thermal.o \ + iceland_powertune.o AMD_PP_HWMGR = $(addprefix $(AMD_PP_PATH)/hwmgr/,$(HARDWARE_MGR))drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c +4
-0@@ -39,6 +39,7 @@ extern int cz_hwmgr_init(struct pp_hwmgr *hwmgr);extern int tonga_hwmgr_init (struct pp_hwmgr *hwmgr);extern int fiji_hwmgr_init (struct pp_hwmgr *hwmgr);extern int polaris10_hwmgr_init (struct pp_hwmgr *hwmgr); +extern int iceland_hwmgr_init (struct pp_hwmgr *hwmgr);int hwmgr_init (struct amd_pp_init *pp_init,struct pp_instance *handle) {@@ -67,6 +68,9 @@ int hwmgr_init(struct amd_pp_init *pp_init, struct pp_instance *handle)break ;case AMDGPU_FAMILY_VI :switch (hwmgr->chip_id) { +case CHIP_TOPAZ : +iceland_hwmgr_init (hwmgr); +break ;case CHIP_TONGA :tonga_hwmgr_init (hwmgr);break ;drivers/gpu/drm/amd/powerplay/hwmgr/iceland_clockpowergating.c new file +119
-0@@ -0,0 +1,119 @@ +/* +* Copyright 2016 Advanced Micro Devices, Inc. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +* +* Author: Huang Rui <[email protected]> +* +*/ + +#include "hwmgr.h" +#include "iceland_clockpowergating.h" +#include "ppsmc.h" +#include "iceland_hwmgr.h" + +int iceland_phm_powerdown_uvd (struct pp_hwmgr *hwmgr) +{ +/* iceland does not have MM hardware block */ +return 0 ; +} + +static int iceland_phm_powerup_uvd (struct pp_hwmgr *hwmgr) +{ +/* iceland does not have MM hardware block */ +return 0 ; +} + +static int iceland_phm_powerdown_vce (struct pp_hwmgr *hwmgr) +{ +/* iceland does not have MM hardware block */ +return 0 ; +} + +static int iceland_phm_powerup_vce (struct pp_hwmgr *hwmgr) +{ +/* iceland does not have MM hardware block */ +return 0 ; +} + +int iceland_phm_set_asic_block_gating (struct pp_hwmgr *hwmgr,enum +PHM_AsicBlock block,enum PHM_ClockGateSetting gating) +{ +int ret =0 ; + +switch (block) { +case PHM_AsicBlock_UVD_MVC: +case PHM_AsicBlock_UVD: +case PHM_AsicBlock_UVD_HD: +case PHM_AsicBlock_UVD_SD: +if (gating == PHM_ClockGateSetting_StaticOff) + ret =iceland_phm_powerdown_uvd (hwmgr); +else + ret =iceland_phm_powerup_uvd (hwmgr); +break ; +case PHM_AsicBlock_GFX: +default : +break ; + } + +return ret; +} + +int iceland_phm_disable_clock_power_gating (struct pp_hwmgr *hwmgr) +{ +struct iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend); + + data->uvd_power_gated = false; + data->vce_power_gated = false; + +iceland_phm_powerup_uvd (hwmgr); +iceland_phm_powerup_vce (hwmgr); + +return 0 ; +} + +int iceland_phm_powergate_uvd (struct pp_hwmgr *hwmgr,bool bgate) +{ +if (bgate) { +iceland_update_uvd_dpm (hwmgr, true); +iceland_phm_powerdown_uvd (hwmgr); + }else { +iceland_phm_powerup_uvd (hwmgr); +iceland_update_uvd_dpm (hwmgr, false); + } + +return 0 ; +} + +int iceland_phm_powergate_vce (struct pp_hwmgr *hwmgr,bool bgate) +{ +if (bgate) +return iceland_phm_powerdown_vce (hwmgr); +else +return iceland_phm_powerup_vce (hwmgr); + +return 0 ; +} + +int iceland_phm_update_clock_gatings (struct pp_hwmgr *hwmgr, +const uint32_t *msg_id) +{ +/* iceland does not have MM hardware block */ +return 0 ; +}drivers/gpu/drm/amd/powerplay/hwmgr/iceland_clockpowergating.h new file +38
-0@@ -0,0 +1,38 @@ +/* +* Copyright 2016 Advanced Micro Devices, Inc. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +* +* Author: Huang Rui <[email protected]> +* +*/ + +#ifndef _ICELAND_CLOCK_POWER_GATING_H_ +#define _ICELAND_CLOCK_POWER_GATING_H_ + +#include "iceland_hwmgr.h" +#include "pp_asicblocks.h" + +extern int iceland_phm_set_asic_block_gating (struct pp_hwmgr *hwmgr,enum PHM_AsicBlock block,enum PHM_ClockGateSetting gating); +extern int iceland_phm_powergate_vce (struct pp_hwmgr *hwmgr,bool bgate); +extern int iceland_phm_powergate_uvd (struct pp_hwmgr *hwmgr,bool bgate); +extern int iceland_phm_powerdown_uvd (struct pp_hwmgr *hwmgr); +extern int iceland_phm_disable_clock_power_gating (struct pp_hwmgr *hwmgr); +extern int iceland_phm_update_clock_gatings (struct pp_hwmgr *hwmgr,const uint32_t *msg_id); +#endif /* _ICELAND_CLOCK_POWER_GATING_H_ */ drivers/gpu/drm/amd/powerplay/hwmgr/iceland_hwmgr.c new file +3516
-0@@ -0,0 +1,5617 @@ +/* +* Copyright 2016 Advanced Micro Devices, Inc. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +* +* Author: Huang Rui <[email protected]> +* +*/ +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/fb.h> +#include "linux/delay.h" +#include "pp_acpi.h" +#include "hwmgr.h" +#include <atombios.h> +#include "iceland_hwmgr.h" +#include "pptable.h" +#include "processpptables.h" +#include "pp_debug.h" +#include "ppsmc.h" +#include "cgs_common.h" +#include "pppcielanes.h" +#include "iceland_dyn_defaults.h" +#include "smumgr.h" +#include "iceland_smumgr.h" +#include "iceland_clockpowergating.h" +#include "iceland_thermal.h" +#include "iceland_powertune.h" + +#include "gmc/gmc_8_1_d.h" +#include "gmc/gmc_8_1_sh_mask.h" + +#include "bif/bif_5_0_d.h" +#include "bif/bif_5_0_sh_mask.h" + +#include "smu/smu_7_1_1_d.h" +#include "smu/smu_7_1_1_sh_mask.h" + +#include "cgs_linux.h" +#include "eventmgr.h" +#include "amd_pcie_helpers.h" + +#define MC_CG_ARB_FREQ_F0 0x0a +#define MC_CG_ARB_FREQ_F1 0x0b +#define MC_CG_ARB_FREQ_F2 0x0c +#define MC_CG_ARB_FREQ_F3 0x0d + +#define MC_CG_SEQ_DRAMCONF_S0 0x05 +#define MC_CG_SEQ_DRAMCONF_S1 0x06 +#define MC_CG_SEQ_YCLK_SUSPEND 0x04 +#define MC_CG_SEQ_YCLK_RESUME 0x0a + +#define PCIE_BUS_CLK 10000 +#define TCLK (PCIE_BUS_CLK / 10) + +#define SMC_RAM_END 0x40000 +#define SMC_CG_IND_START 0xc0030000 +#define SMC_CG_IND_END 0xc0040000/* First byte after SMC_CG_IND*/ + +#define VOLTAGE_SCALE 4 +#define VOLTAGE_VID_OFFSET_SCALE1 625 +#define VOLTAGE_VID_OFFSET_SCALE2 100 + +const uint32_t iceland_magic = (uint32_t )(PHM_VIslands_Magic); + +#define MC_SEQ_MISC0_GDDR5_SHIFT 28 +#define MC_SEQ_MISC0_GDDR5_MASK 0xf0000000 +#define MC_SEQ_MISC0_GDDR5_VALUE 5 + +/** Values for the CG_THERMAL_CTRL::DPM_EVENT_SRC field. */ +enum DPM_EVENT_SRC { +DPM_EVENT_SRC_ANALOG =0 ,/* Internal analog trip point */ +DPM_EVENT_SRC_EXTERNAL =1 ,/* External (GPIO 17) signal */ +DPM_EVENT_SRC_DIGITAL =2 ,/* Internal digital trip point (DIG_THERM_DPM) */ +DPM_EVENT_SRC_ANALOG_OR_EXTERNAL =3 ,/* Internal analog or external */ +DPM_EVENT_SRC_DIGITAL_OR_EXTERNAL =4 /* Internal digital or external */ +}; + +static int iceland_read_clock_registers (struct pp_hwmgr *hwmgr) +{ +iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend); + + data->clock_registers.vCG_SPLL_FUNC_CNTL = +cgs_read_ind_register (hwmgr->device,CGS_IND_REG__SMC , ixCG_SPLL_FUNC_CNTL); + data->clock_registers.vCG_SPLL_FUNC_CNTL_2 = +cgs_read_ind_register (hwmgr->device,CGS_IND_REG__SMC , ixCG_SPLL_FUNC_CNTL_2); + data->clock_registers.vCG_SPLL_FUNC_CNTL_3 = +cgs_read_ind_register (hwmgr->device,CGS_IND_REG__SMC , ixCG_SPLL_FUNC_CNTL_3); + data->clock_registers.vCG_SPLL_FUNC_CNTL_4 = +cgs_read_ind_register (hwmgr->device,CGS_IND_REG__SMC , ixCG_SPLL_FUNC_CNTL_4); + data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM = +cgs_read_ind_register (hwmgr->device,CGS_IND_REG__SMC , ixCG_SPLL_SPREAD_SPECTRUM); + data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM_2 = +cgs_read_ind_register (hwmgr->device,CGS_IND_REG__SMC , ixCG_SPLL_SPREAD_SPECTRUM_2); + data->clock_registers.vDLL_CNTL = +cgs_read_register (hwmgr->device, mmDLL_CNTL); + data->clock_registers.vMCLK_PWRMGT_CNTL = +cgs_read_register (hwmgr->device, mmMCLK_PWRMGT_CNTL); + data->clock_registers.vMPLL_AD_FUNC_CNTL = +cgs_read_register (hwmgr->device, mmMPLL_AD_FUNC_CNTL); + data->clock_registers.vMPLL_DQ_FUNC_CNTL = +cgs_read_register (hwmgr->device, mmMPLL_DQ_FUNC_CNTL); + data->clock_registers.vMPLL_FUNC_CNTL = +cgs_read_register (hwmgr->device, mmMPLL_FUNC_CNTL); + data->clock_registers.vMPLL_FUNC_CNTL_1 = +cgs_read_register (hwmgr->device, mmMPLL_FUNC_CNTL_1); + data->clock_registers.vMPLL_FUNC_CNTL_2 = +cgs_read_register (hwmgr->device, mmMPLL_FUNC_CNTL_2); + data->clock_registers.vMPLL_SS1 = +cgs_read_register (hwmgr->device, mmMPLL_SS1); + data->clock_registers.vMPLL_SS2 = +cgs_read_register (hwmgr->device, mmMPLL_SS2); + +return 0 ; +} + +/** +* Find out if memory is GDDR5. +* +* @param hwmgr the address of the powerplay hardware manager. +* @return always 0 +*/ +int iceland_get_memory_type (struct pp_hwmgr *hwmgr) +{ +iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend); +uint32_t temp; + + temp =cgs_read_register (hwmgr->device, mmMC_SEQ_MISC0); + + data->is_memory_GDDR5 = (MC_SEQ_MISC0_GDDR5_VALUE == + ((temp &MC_SEQ_MISC0_GDDR5_MASK ) >> +MC_SEQ_MISC0_GDDR5_SHIFT )); + +return 0 ; +} + +int iceland_update_uvd_dpm (struct pp_hwmgr *hwmgr,bool bgate) +{ +/* iceland does not have MM hardware blocks */ +return 0 ; +} + +/** +* Enables Dynamic Power Management by SMC +* +* @param hwmgr the address of the powerplay hardware manager. +* @return always 0 +*/ +int iceland_enable_acpi_power_management (struct pp_hwmgr *hwmgr) +{ +PHM_WRITE_VFPF_INDIRECT_FIELD (hwmgr->device,CGS_IND_REG__SMC ,GENERAL_PWRMGT ,STATIC_PM_EN ,1 ); + +return 0 ; +} + +/** +* Find the MC microcode version and store it in the HwMgr struct +* +* @param hwmgr the address of the powerplay hardware manager. +* @return always 0 +*/ +int iceland_get_mc_microcode_version (struct pp_hwmgr *hwmgr) +{ +cgs_write_register (hwmgr->device, mmMC_SEQ_IO_DEBUG_INDEX,0x9F ); + + hwmgr->microcode_version_info.MC =cgs_read_register (hwmgr->device, mmMC_SEQ_IO_DEBUG_DATA); + +return 0 ; +} + +static int iceland_init_sclk_threshold (struct pp_hwmgr *hwmgr) +{ +iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend); + + data->low_sclk_interrupt_threshold =0 ; + +return 0 ; +} + + +static int iceland_setup_asic_task (struct pp_hwmgr *hwmgr) +{ +int tmp_result, result =0 ; + + tmp_result =iceland_read_clock_registers (hwmgr); +PP_ASSERT_WITH_CODE ((0 == tmp_result), +"Failed to read clock registers!" , result = tmp_result); + + tmp_result =iceland_get_memory_type (hwmgr); +PP_ASSERT_WITH_CODE ((0 == tmp_result), +"Failed to get memory type!" , result = tmp_result); + + tmp_result =iceland_enable_acpi_power_management (hwmgr); +PP_ASSERT_WITH_CODE ((0 == tmp_result), +"Failed to enable ACPI power management!" , result = tmp_result); + + tmp_result =iceland_get_mc_microcode_version (hwmgr); +PP_ASSERT_WITH_CODE ((0 == tmp_result), +"Failed to get MC microcode version!" , result = tmp_result); + + tmp_result =iceland_init_sclk_threshold (hwmgr); +PP_ASSERT_WITH_CODE ((0 == tmp_result), +"Failed to init sclk threshold!" , result = tmp_result); + +return result; +} + +static bool cf_iceland_voltage_control (struct pp_hwmgr *hwmgr) +{ +struct iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend); + +return ICELAND_VOLTAGE_CONTROL_NONE != data->voltage_control; +} + +/* +* -------------- Voltage Tables ---------------------- +* If the voltage table would be bigger than what will fit into the +* state table on the SMC keep only the higher entries. +*/ + +static void iceland_trim_voltage_table_to_fit_state_table ( +struct pp_hwmgr *hwmgr, +uint32_t max_voltage_steps, +pp_atomctrl_voltage_table *voltage_table) +{ +unsigned int i, diff; + +if (voltage_table->count <= max_voltage_steps) { +return ; + } + + diff = voltage_table->count - max_voltage_steps; + +for (i =0 ; i < max_voltage_steps; i++) { + voltage_table->entries[i] = voltage_table->entries[i + diff]; + } + + voltage_table->count = max_voltage_steps; + +return ; +} + +/** +* Enable voltage control +* +* @param hwmgr the address of the powerplay hardware manager. +* @return always 0 +*/ +int iceland_enable_voltage_control (struct pp_hwmgr *hwmgr) +{ +/* enable voltage control */ +PHM_WRITE_VFPF_INDIRECT_FIELD (hwmgr->device,CGS_IND_REG__SMC ,GENERAL_PWRMGT ,VOLT_PWRMGT_EN ,1 ); + +return 0 ; +} + +static int iceland_get_svi2_voltage_table (struct pp_hwmgr *hwmgr, +struct phm_clock_voltage_dependency_table *voltage_dependency_table, +pp_atomctrl_voltage_table *voltage_table) +{ +uint32_t i; + +PP_ASSERT_WITH_CODE ((NULL != voltage_table), + "Voltage Dependency Table empty.", return -EINVAL;); + + voltage_table->mask_low =0 ; + voltage_table->phase_delay =0 ; + voltage_table->count = voltage_dependency_table->count; + +for (i =0 ; i < voltage_dependency_table->count; i++) { + voltage_table->entries[i].value = + voltage_dependency_table->entries[i].v; + voltage_table->entries[i].smio_low =0 ; + } + +return 0 ; +} + +/** +* Create Voltage Tables. +* +* @param hwmgr the address of the powerplay hardware manager. +* @return always 0 +*/ +int iceland_construct_voltage_tables (struct pp_hwmgr *hwmgr) +{ +iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend); +int result; + +/* GPIO voltage */ +if (ICELAND_VOLTAGE_CONTROL_BY_GPIO == data->voltage_control) { + result =atomctrl_get_voltage_table_v3 (hwmgr, +VOLTAGE_TYPE_VDDC ,VOLTAGE_OBJ_GPIO_LUT , + &data->vddc_voltage_table); +PP_ASSERT_WITH_CODE ((0 == result), + "Failed to retrieve VDDC table.", return result;); + }else if (ICELAND_VOLTAGE_CONTROL_BY_SVID2 == data->voltage_control) { +/* SVI2 VDDC voltage */ + result =iceland_get_svi2_voltage_table (hwmgr, + hwmgr->dyn_state.vddc_dependency_on_mclk, + &data->vddc_voltage_table); +PP_ASSERT_WITH_CODE ((0 == result), + "Failed to retrieve SVI2 VDDC table from dependancy table.", return result;); + } + +PP_ASSERT_WITH_CODE ( + (data->vddc_voltage_table.count <= (SMU71_MAX_LEVELS_VDDC )), +"Too many voltage values for VDDC. Trimming to fit state table." , +iceland_trim_voltage_table_to_fit_state_table (hwmgr, + SMU71_MAX_LEVELS_VDDC, &(data->vddc_voltage_table)); + ); + +/* GPIO */ +if (ICELAND_VOLTAGE_CONTROL_BY_GPIO == data->vdd_ci_control) { + result =atomctrl_get_voltage_table_v3 (hwmgr, +VOLTAGE_TYPE_VDDCI ,VOLTAGE_OBJ_GPIO_LUT , &(data->vddci_voltage_table)); +PP_ASSERT_WITH_CODE ((0 == result), + "Failed to retrieve VDDCI table.", return result;); + } + +/* SVI2 VDDCI voltage */ +if (ICELAND_VOLTAGE_CONTROL_BY_SVID2 == data->vdd_ci_control) { + result =iceland_get_svi2_voltage_table (hwmgr, + hwmgr->dyn_state.vddci_dependency_on_mclk, + &data->vddci_voltage_table); +PP_ASSERT_WITH_CODE ((0 == result), + "Failed to retrieve SVI2 VDDCI table from dependancy table.", return result;); + } + +PP_ASSERT_WITH_CODE ( + (data->vddci_voltage_table.count <= (SMU71_MAX_LEVELS_VDDCI )), +"Too many voltage values for VDDCI. Trimming to fit state table." , +iceland_trim_voltage_table_to_fit_state_table (hwmgr, + SMU71_MAX_LEVELS_VDDCI, &(data->vddci_voltage_table)); + ); + + +/* GPIO */ +if (ICELAND_VOLTAGE_CONTROL_BY_GPIO == data->mvdd_control) { + result =atomctrl_get_voltage_table_v3 (hwmgr, +VOLTAGE_TYPE_MVDDC ,VOLTAGE_OBJ_GPIO_LUT , &(data->mvdd_voltage_table)); +PP_ASSERT_WITH_CODE ((0 == result), + "Failed to retrieve table.", return result;); + } + +/* SVI2 voltage control */ +if (ICELAND_VOLTAGE_CONTROL_BY_SVID2 == data->mvdd_control) { + result =iceland_get_svi2_voltage_table (hwmgr, + hwmgr->dyn_state.mvdd_dependency_on_mclk, + &data->mvdd_voltage_table); +PP_ASSERT_WITH_CODE ((0 == result), + "Failed to retrieve SVI2 MVDD table from dependancy table.", return result;); + } + +PP_ASSERT_WITH_CODE ( + (data->mvdd_voltage_table.count <= (SMU71_MAX_LEVELS_MVDD )), +"Too many voltage values for MVDD. Trimming to fit state table." , +iceland_trim_voltage_table_to_fit_state_table (hwmgr, + SMU71_MAX_LEVELS_MVDD, &(data->mvdd_voltage_table)); + ); + +return 0 ; +} + +/*---------------------------MC----------------------------*/ + +uint8_t iceland_get_memory_module_index (struct pp_hwmgr *hwmgr) +{ +return (uint8_t ) (0xFF & (cgs_read_register (hwmgr->device, mmBIOS_SCRATCH_4) >>16 )); +} + +bool iceland_check_s0_mc_reg_index (uint16_t inReg,uint16_t *outReg) +{ +bool result = true; + +switch (inReg) { +case mmMC_SEQ_RAS_TIMING: + *outReg = mmMC_SEQ_RAS_TIMING_LP; +break ; + +case mmMC_SEQ_DLL_STBY: + *outReg = mmMC_SEQ_DLL_STBY_LP; +break ; + +case mmMC_SEQ_G5PDX_CMD0: + *outReg = mmMC_SEQ_G5PDX_CMD0_LP; +break ; + +case mmMC_SEQ_G5PDX_CMD1: + *outReg = mmMC_SEQ_G5PDX_CMD1_LP; +break ; + +case mmMC_SEQ_G5PDX_CTRL: + *outReg = mmMC_SEQ_G5PDX_CTRL_LP; +break ; + +case mmMC_SEQ_CAS_TIMING: + *outReg = mmMC_SEQ_CAS_TIMING_LP; +break ; + +case mmMC_SEQ_MISC_TIMING: + *outReg = mmMC_SEQ_MISC_TIMING_LP; +break ; + +case mmMC_SEQ_MISC_TIMING2: + *outReg = mmMC_SEQ_MISC_TIMING2_LP; +break ; + +case mmMC_SEQ_PMG_DVS_CMD: + *outReg = mmMC_SEQ_PMG_DVS_CMD_LP; +break ; + +case mmMC_SEQ_PMG_DVS_CTL: + *outReg = mmMC_SEQ_PMG_DVS_CTL_LP; +break ; + +case mmMC_SEQ_RD_CTL_D0: + *outReg = mmMC_SEQ_RD_CTL_D0_LP; +break ; + +case mmMC_SEQ_RD_CTL_D1: + *outReg = mmMC_SEQ_RD_CTL_D1_LP; +break ; + +case mmMC_SEQ_WR_CTL_D0: + *outReg = mmMC_SEQ_WR_CTL_D0_LP; +break ; + +case mmMC_SEQ_WR_CTL_D1: + *outReg = mmMC_SEQ_WR_CTL_D1_LP; +break ; + +case mmMC_PMG_CMD_EMRS: + *outReg = mmMC_SEQ_PMG_CMD_EMRS_LP; +break ; + +case mmMC_PMG_CMD_MRS: + *outReg = mmMC_SEQ_PMG_CMD_MRS_LP; +break ; + +case mmMC_PMG_CMD_MRS1: + *outReg = mmMC_SEQ_PMG_CMD_MRS1_LP; +break ; + +case mmMC_SEQ_PMG_TIMING: + *outReg = mmMC_SEQ_PMG_TIMING_LP; +break ; + +case mmMC_PMG_CMD_MRS2: + *outReg = mmMC_SEQ_PMG_CMD_MRS2_LP; +break ; + +case mmMC_SEQ_WR_CTL_2: + *outReg = mmMC_SEQ_WR_CTL_2_LP; +break ; + +default : + result = false; +break ; + } + +return result; +} + +int iceland_set_s0_mc_reg_index (phw_iceland_mc_reg_table *table) +{ +uint32_t i; +uint16_t address; + +for (i =0 ; i < table->last; i++) { + table->mc_reg_address[i].s0 = +iceland_check_s0_mc_reg_index (table->mc_reg_address[i].s1, &address) + ? address : table->mc_reg_address[i].s1; + } +return 0 ; +} + +int iceland_copy_vbios_smc_reg_table (const pp_atomctrl_mc_reg_table *table,phw_iceland_mc_reg_table *ni_table) +{ +uint8_t i, j; + +PP_ASSERT_WITH_CODE ((table->last <=SMU71_DISCRETE_MC_REGISTER_ARRAY_SIZE ), +"Invalid VramInfo table." , return -1 ); +PP_ASSERT_WITH_CODE ((table->num_entries <=MAX_AC_TIMING_ENTRIES ), +"Invalid VramInfo table." , return -1 ); + +for (i =0 ; i < table->last; i++) { + ni_table->mc_reg_address[i].s1 = table->mc_reg_address[i].s1; + } + ni_table->last = table->last; + +for (i =0 ; i < table->num_entries; i++) { + ni_table->mc_reg_table_entry[i].mclk_max = + table->mc_reg_table_entry[i].mclk_max; +for (j =0 ; j < table->last; j++) { + ni_table->mc_reg_table_entry[i].mc_data[j] = + table->mc_reg_table_entry[i].mc_data[j]; + } + } + + ni_table->num_entries = table->num_entries; + +return 0 ; +} + +/** +* VBIOS omits some information to reduce size, we need to recover them here. +* 1. when we see mmMC_SEQ_MISC1, bit[31:16] EMRS1, need to be write to mmMC_PMG_CMD_EMRS /_LP[15:0]. +* Bit[15:0] MRS, need to be update mmMC_PMG_CMD_MRS/_LP[15:0] +* 2. when we see mmMC_SEQ_RESERVE_M, bit[15:0] EMRS2, need to be write to mmMC_PMG_CMD_MRS1/_LP[15:0]. +* 3. need to set these data for each clock range +* +* @param hwmgr the address of the powerplay hardware manager. +* @param table the address of MCRegTable +* @return always 0 +*/ +static int iceland_set_mc_special_registers (struct pp_hwmgr *hwmgr,phw_iceland_mc_reg_table *table) +{ +uint8_t i, j, k; +uint32_t temp_reg; +const iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend); + +for (i =0 , j = table->last; i < table->last; i++) { +PP_ASSERT_WITH_CODE ((j <SMU71_DISCRETE_MC_REGISTER_ARRAY_SIZE ), +"Invalid VramInfo table." , return -1 ); +switch (table->mc_reg_address[i].s1) { +/* +* mmMC_SEQ_MISC1, bit[31:16] EMRS1, need to be write +* to mmMC_PMG_CMD_EMRS/_LP[15:0]. Bit[15:0] MRS, need +* to be update mmMC_PMG_CMD_MRS/_LP[15:0] +*/ +case mmMC_SEQ_MISC1: + temp_reg =cgs_read_register (hwmgr->device, mmMC_PMG_CMD_EMRS); + table->mc_reg_address[j].s1 = mmMC_PMG_CMD_EMRS; + table->mc_reg_address[j].s0 = mmMC_SEQ_PMG_CMD_EMRS_LP; +for (k =0 ; k < table->num_entries; k++) { + table->mc_reg_table_entry[k].mc_data[j] = + ((temp_reg &0xffff0000 )) | + ((table->mc_reg_table_entry[k].mc_data[i] &0xffff0000 ) >>16 ); + } + j++; +PP_ASSERT_WITH_CODE ((j <SMU71_DISCRETE_MC_REGISTER_ARRAY_SIZE ), +"Invalid VramInfo table." , return -1 ); + + temp_reg =cgs_read_register (hwmgr->device, mmMC_PMG_CMD_MRS); + table->mc_reg_address[j].s1 = mmMC_PMG_CMD_MRS; + table->mc_reg_address[j].s0 = mmMC_SEQ_PMG_CMD_MRS_LP; +for (k =0 ; k < table->num_entries; k++) { + table->mc_reg_table_entry[k].mc_data[j] = + (temp_reg &0xffff0000 ) | + (table->mc_reg_table_entry[k].mc_data[i] &0x0000ffff ); + +if (!data->is_memory_GDDR5) { + table->mc_reg_table_entry[k].mc_data[j] |=0x100 ; + } + } + j++; +PP_ASSERT_WITH_CODE ((j <=SMU71_DISCRETE_MC_REGISTER_ARRAY_SIZE ), +"Invalid VramInfo table." , return -1 ); + +if (!data->is_memory_GDDR5) { + table->mc_reg_address[j].s1 = mmMC_PMG_AUTO_CMD; + table->mc_reg_address[j].s0 = mmMC_PMG_AUTO_CMD; +for (k =0 ; k < table->num_entries; k++) { + table->mc_reg_table_entry[k].mc_data[j] = + (table->mc_reg_table_entry[k].mc_data[i] &0xffff0000 ) >>16 ; + } + j++; +PP_ASSERT_WITH_CODE ((j <=SMU71_DISCRETE_MC_REGISTER_ARRAY_SIZE ), +"Invalid VramInfo table." , return -1 ); + } + +break ; + +case mmMC_SEQ_RESERVE_M: + temp_reg =cgs_read_register (hwmgr->device, mmMC_PMG_CMD_MRS1); + table->mc_reg_address[j].s1 = mmMC_PMG_CMD_MRS1; + table->mc_reg_address[j].s0 = mmMC_SEQ_PMG_CMD_MRS1_LP; +for (k =0 ; k < table->num_entries; k++) { + table->mc_reg_table_entry[k].mc_data[j] = + (temp_reg &0xffff0000 ) | + (table->mc_reg_table_entry[k].mc_data[i] &0x0000ffff ); + } + j++; +PP_ASSERT_WITH_CODE ((j <=SMU71_DISCRETE_MC_REGISTER_ARRAY_SIZE ), +"Invalid VramInfo table." , return -1 ); +break ; + +default : +break ; + } + + } + + table->last = j; + +return 0 ; +} + + +static int iceland_set_valid_flag (phw_iceland_mc_reg_table *table) +{ +uint8_t i, j; +for (i =0 ; i < table->last; i++) { +for (j =1 ; j < table->num_entries; j++) { +if (table->mc_reg_table_entry[j-1 ].mc_data[i] != + table->mc_reg_table_entry[j].mc_data[i]) { + table->validflag |= (1 <<i); +break ; + } + } + } + +return 0 ; +} + +static int iceland_initialize_mc_reg_table (struct pp_hwmgr *hwmgr) +{ +int result; +iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend); +pp_atomctrl_mc_reg_table *table; +phw_iceland_mc_reg_table *ni_table = &data->iceland_mc_reg_table; +uint8_t module_index =iceland_get_memory_module_index (hwmgr); + + table =kzalloc (sizeof (pp_atomctrl_mc_reg_table),GFP_KERNEL ); + +if (NULL == table) +return -ENOMEM ; + +/* Program additional LP registers that are no longer programmed by VBIOS */ +cgs_write_register (hwmgr->device, mmMC_SEQ_RAS_TIMING_LP,cgs_read_register (hwmgr->device, mmMC_SEQ_RAS_TIMING)); +cgs_write_register (hwmgr->device, mmMC_SEQ_CAS_TIMING_LP,cgs_read_register (hwmgr->device, mmMC_SEQ_CAS_TIMING)); +cgs_write_register (hwmgr->device, mmMC_SEQ_DLL_STBY_LP,cgs_read_register (hwmgr->device, mmMC_SEQ_DLL_STBY)); +cgs_write_register (hwmgr->device, mmMC_SEQ_G5PDX_CMD0_LP,cgs_read_register (hwmgr->device, mmMC_SEQ_G5PDX_CMD0)); +cgs_write_register (hwmgr->device, mmMC_SEQ_G5PDX_CMD1_LP,cgs_read_register (hwmgr->device, mmMC_SEQ_G5PDX_CMD1)); +cgs_write_register (hwmgr->device, mmMC_SEQ_G5PDX_CTRL_LP,cgs_read_register (hwmgr->device, mmMC_SEQ_G5PDX_CTRL)); +cgs_write_register (hwmgr->device, mmMC_SEQ_PMG_DVS_CMD_LP,cgs_read_register (hwmgr->device, mmMC_SEQ_PMG_DVS_CMD)); +cgs_write_register (hwmgr->device, mmMC_SEQ_PMG_DVS_CTL_LP,cgs_read_register (hwmgr->device, mmMC_SEQ_PMG_DVS_CTL)); +cgs_write_register (hwmgr->device, mmMC_SEQ_MISC_TIMING_LP,cgs_read_register (hwmgr->device, mmMC_SEQ_MISC_TIMING)); +cgs_write_register (hwmgr->device, mmMC_SEQ_MISC_TIMING2_LP,cgs_read_register (hwmgr->device, mmMC_SEQ_MISC_TIMING2)); +cgs_write_register (hwmgr->device, mmMC_SEQ_PMG_CMD_EMRS_LP,cgs_read_register (hwmgr->device, mmMC_PMG_CMD_EMRS)); +cgs_write_register (hwmgr->device, mmMC_SEQ_PMG_CMD_MRS_LP,cgs_read_register (hwmgr->device, mmMC_PMG_CMD_MRS)); +cgs_write_register (hwmgr->device, mmMC_SEQ_PMG_CMD_MRS1_LP,cgs_read_register (hwmgr->device, mmMC_PMG_CMD_MRS1)); +cgs_write_register (hwmgr->device, mmMC_SEQ_WR_CTL_D0_LP,cgs_read_register (hwmgr->device, mmMC_SEQ_WR_CTL_D0)); +cgs_write_register (hwmgr->device, mmMC_SEQ_WR_CTL_D1_LP,cgs_read_register (hwmgr->device, mmMC_SEQ_WR_CTL_D1)); +cgs_write_register (hwmgr->device, mmMC_SEQ_RD_CTL_D0_LP,cgs_read_register (hwmgr->device, mmMC_SEQ_RD_CTL_D0)); +cgs_write_register (hwmgr->device, mmMC_SEQ_RD_CTL_D1_LP,cgs_read_register (hwmgr->device, mmMC_SEQ_RD_CTL_D1)); +cgs_write_register (hwmgr->device, mmMC_SEQ_PMG_TIMING_LP,cgs_read_register (hwmgr->device, mmMC_SEQ_PMG_TIMING)); +cgs_write_register (hwmgr->device, mmMC_SEQ_PMG_CMD_MRS2_LP,cgs_read_register (hwmgr->device, mmMC_PMG_CMD_MRS2)); +cgs_write_register (hwmgr->device, mmMC_SEQ_WR_CTL_2_LP,cgs_read_register (hwmgr->device, mmMC_SEQ_WR_CTL_2)); + +memset (table,0x00 ,sizeof (pp_atomctrl_mc_reg_table)); + + result =atomctrl_initialize_mc_reg_table (hwmgr, module_index, table); + +if (0 == result) + result =iceland_copy_vbios_smc_reg_table (table, ni_table); + +if (0 == result) { +iceland_set_s0_mc_reg_index (ni_table); + result =iceland_set_mc_special_registers (hwmgr, ni_table); + } + +if (0 == result) +iceland_set_valid_flag (ni_table); + +kfree (table); +return result; +} + +/** +* Programs static screed detection parameters +* +* @param hwmgr the address of the powerplay hardware manager. +* @return always 0 +*/ +int iceland_program_static_screen_threshold_parameters (struct pp_hwmgr *hwmgr) +{ +iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend); + +/* Set static screen threshold unit*/ +PHM_WRITE_VFPF_INDIRECT_FIELD (hwmgr->device, +CGS_IND_REG__SMC ,CG_STATIC_SCREEN_PARAMETER ,STATIC_SCREEN_THRESHOLD_UNIT , + data->static_screen_threshold_unit); +/* Set static screen threshold*/ +PHM_WRITE_VFPF_INDIRECT_FIELD (hwmgr->device, +CGS_IND_REG__SMC ,CG_STATIC_SCREEN_PARAMETER ,STATIC_SCREEN_THRESHOLD , + data->static_screen_threshold); + +return 0 ; +} + +/** +* Setup display gap for glitch free memory clock switching. +* +* @param hwmgr the address of the powerplay hardware manager. +* @return always 0 +*/ +int iceland_enable_display_gap (struct pp_hwmgr *hwmgr) +{ +uint32_t display_gap =cgs_read_ind_register (hwmgr->device, +CGS_IND_REG__SMC , ixCG_DISPLAY_GAP_CNTL); + + display_gap =PHM_SET_FIELD (display_gap, +CG_DISPLAY_GAP_CNTL ,DISP_GAP ,DISPLAY_GAP_IGNORE ); + + display_gap =PHM_SET_FIELD (display_gap, +CG_DISPLAY_GAP_CNTL ,DISP_GAP_MCHG ,DISPLAY_GAP_VBLANK ); + +cgs_write_ind_register (hwmgr->device,CGS_IND_REG__SMC , + ixCG_DISPLAY_GAP_CNTL, display_gap); + +return 0 ; +} + +/** +* Programs activity state transition voting clients +* +* @param hwmgr the address of the powerplay hardware manager. +* @return always 0 +*/ +int iceland_program_voting_clients (struct pp_hwmgr *hwmgr) +{ +iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend); + +/* Clear reset for voting clients before enabling DPM */ +PHM_WRITE_VFPF_INDIRECT_FIELD (hwmgr->device,CGS_IND_REG__SMC , +SCLK_PWRMGT_CNTL ,RESET_SCLK_CNT ,0 ); +PHM_WRITE_VFPF_INDIRECT_FIELD (hwmgr->device,CGS_IND_REG__SMC , +SCLK_PWRMGT_CNTL ,RESET_BUSY_CNT ,0 ); + +cgs_write_ind_register (hwmgr->device,CGS_IND_REG__SMC , + ixCG_FREQ_TRAN_VOTING_0, data->voting_rights_clients0); +cgs_write_ind_register (hwmgr->device,CGS_IND_REG__SMC , + ixCG_FREQ_TRAN_VOTING_1, data->voting_rights_clients1); +cgs_write_ind_register (hwmgr->device,CGS_IND_REG__SMC , + ixCG_FREQ_TRAN_VOTING_2, data->voting_rights_clients2); +cgs_write_ind_register (hwmgr->device,CGS_IND_REG__SMC , + ixCG_FREQ_TRAN_VOTING_3, data->voting_rights_clients3); +cgs_write_ind_register (hwmgr->device,CGS_IND_REG__SMC , + ixCG_FREQ_TRAN_VOTING_4, data->voting_rights_clients4); +cgs_write_ind_register (hwmgr->device,CGS_IND_REG__SMC , + ixCG_FREQ_TRAN_VOTING_5, data->voting_rights_clients5); +cgs_write_ind_register (hwmgr->device,CGS_IND_REG__SMC , + ixCG_FREQ_TRAN_VOTING_6, data->voting_rights_clients6); +cgs_write_ind_register (hwmgr->device,CGS_IND_REG__SMC , + ixCG_FREQ_TRAN_VOTING_7, data->voting_rights_clients7); + +return 0 ; +} + +static int iceland_upload_firmware (struct pp_hwmgr *hwmgr) +{ +int ret =0 ; + +if (!iceland_is_smc_ram_running (hwmgr->smumgr)) + ret =iceland_smu_upload_firmware_image (hwmgr->smumgr); + +return ret; +} + +/** +* Get the location of various tables inside the FW image. +* +* @param hwmgr the address of the powerplay hardware manager. +* @return always 0 +*/ +int iceland_process_firmware_header (struct pp_hwmgr *hwmgr) +{ +iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend); + +uint32_t tmp; +int result; +bool error =0 ; + + result =iceland_read_smc_sram_dword (hwmgr->smumgr, +SMU71_FIRMWARE_HEADER_LOCATION + + offsetof(SMU71_Firmware_Header , DpmTable), + &tmp, data->sram_end); + +if (0 == result) { + data->dpm_table_start = tmp; + } + + error |= (0 != result); + + result =iceland_read_smc_sram_dword (hwmgr->smumgr, +SMU71_FIRMWARE_HEADER_LOCATION + + offsetof(SMU71_Firmware_Header , SoftRegisters), + &tmp, data->sram_end); + +if (0 == result) { + data->soft_regs_start = tmp; + } + + error |= (0 != result); + + + result =iceland_read_smc_sram_dword (hwmgr->smumgr, +SMU71_FIRMWARE_HEADER_LOCATION + + offsetof(SMU71_Firmware_Header , mcRegisterTable), + &tmp, data->sram_end); + +if (0 == result) { + data->mc_reg_table_start = tmp; + } + + result =iceland_read_smc_sram_dword (hwmgr->smumgr, +SMU71_FIRMWARE_HEADER_LOCATION + + offsetof(SMU71_Firmware_Header , FanTable), + &tmp, data->sram_end); + +if (0 == result) { + data->fan_table_start = tmp; + } + + error |= (0 != result); + + result =iceland_read_smc_sram_dword (hwmgr->smumgr, +SMU71_FIRMWARE_HEADER_LOCATION + + offsetof(SMU71_Firmware_Header , mcArbDramTimingTable), + &tmp, data->sram_end); + +if (0 == result) { + data->arb_table_start = tmp; + } + + error |= (0 != result); + + + result =iceland_read_smc_sram_dword (hwmgr->smumgr, +SMU71_FIRMWARE_HEADER_LOCATION + + offsetof(SMU71_Firmware_Header , Version), + &tmp, data->sram_end); + +if (0 == result) { + hwmgr->microcode_version_info.SMC = tmp; + } + + error |= (0 != result); + + result =iceland_read_smc_sram_dword (hwmgr->smumgr, +SMU71_FIRMWARE_HEADER_LOCATION + + offsetof(SMU71_Firmware_Header , UlvSettings), + &tmp, data->sram_end); + +if (0 == result) { + data->ulv_settings_start = tmp; + } + + error |= (0 != result); + +return error ?1 :0 ; +} + +/* +* Copy one arb setting to another and then switch the active set. +* arbFreqSrc and arbFreqDest is one of the MC_CG_ARB_FREQ_Fx constants. +*/ +int iceland_copy_and_switch_arb_sets (struct pp_hwmgr *hwmgr, +uint32_t arbFreqSrc,uint32_t arbFreqDest) +{ +uint32_t mc_arb_dram_timing; +uint32_t mc_arb_dram_timing2; +uint32_t burst_time; +uint32_t mc_cg_config; + +switch (arbFreqSrc) { +case MC_CG_ARB_FREQ_F0 : + mc_arb_dram_timing =cgs_read_register (hwmgr->device, mmMC_ARB_DRAM_TIMING); + mc_arb_dram_timing2 =cgs_read_register (hwmgr->device, mmMC_ARB_DRAM_TIMING2); + burst_time =PHM_READ_FIELD (hwmgr->device,MC_ARB_BURST_TIME ,STATE0 ); +break ; + +case MC_CG_ARB_FREQ_F1 : + mc_arb_dram_timing =cgs_read_register (hwmgr->device, mmMC_ARB_DRAM_TIMING_1); + mc_arb_dram_timing2 =cgs_read_register (hwmgr->device, mmMC_ARB_DRAM_TIMING2_1); + burst_time =PHM_READ_FIELD (hwmgr->device,MC_ARB_BURST_TIME ,STATE1 ); +break ; + +default : +return -1 ; + } + +switch (arbFreqDest) { +case MC_CG_ARB_FREQ_F0 : +cgs_write_register (hwmgr->device, mmMC_ARB_DRAM_TIMING, mc_arb_dram_timing); +cgs_write_register (hwmgr->device, mmMC_ARB_DRAM_TIMING2, mc_arb_dram_timing2); +PHM_WRITE_FIELD (hwmgr->device,MC_ARB_BURST_TIME ,STATE0 , burst_time); +break ; + +case MC_CG_ARB_FREQ_F1 : +cgs_write_register (hwmgr->device, mmMC_ARB_DRAM_TIMING_1, mc_arb_dram_timing); +cgs_write_register (hwmgr->device, mmMC_ARB_DRAM_TIMING2_1, mc_arb_dram_timing2); +PHM_WRITE_FIELD (hwmgr->device,MC_ARB_BURST_TIME ,STATE1 , burst_time); +break ; + +default : +return -1 ; + } + + mc_cg_config =cgs_read_register (hwmgr->device, mmMC_CG_CONFIG); + mc_cg_config |=0x0000000F ; +cgs_write_register (hwmgr->device, mmMC_CG_CONFIG, mc_cg_config); +PHM_WRITE_FIELD (hwmgr->device,MC_ARB_CG ,CG_ARB_REQ , arbFreqDest); + +return 0 ; +} + +/** +* Initial switch from ARB F0->F1 +* +* @param hwmgr the address of the powerplay hardware manager. +* @return always 0 +* This function is to be called from the SetPowerState table. +*/ +int iceland_initial_switch_from_arb_f0_to_f1 (struct pp_hwmgr *hwmgr) +{ +return iceland_copy_and_switch_arb_sets (hwmgr,MC_CG_ARB_FREQ_F0 ,MC_CG_ARB_FREQ_F1 ); +} + +/* ---------------------------------------- ULV related functions ----------------------------------------------------*/ + + +static int iceland_reset_single_dpm_table ( +struct pp_hwmgr *hwmgr, +struct iceland_single_dpm_table *dpm_table, +uint32_t count) +{ +uint32_t i; +if (!(count <=MAX_REGULAR_DPM_NUMBER )) +printk (KERN_ERR "[ powerplay ] Fatal error, can not set up single DPM \ +table entries to exceed max number! \n" ); + + dpm_table->count = count; +for (i =0 ; i <MAX_REGULAR_DPM_NUMBER ; i++) { + dpm_table->dpm_levels[i].enabled =0 ; + } + +return 0 ; +} + +static void iceland_setup_pcie_table_entry ( +struct iceland_single_dpm_table *dpm_table, +uint32_t index,uint32_t pcie_gen, +uint32_t pcie_lanes) +{ + dpm_table->dpm_levels[index].value = pcie_gen; + dpm_table->dpm_levels[index].param1 = pcie_lanes; + dpm_table->dpm_levels[index].enabled =1 ; +} + +/* +* Set up the PCIe DPM table as follows: +* +* A = Performance State, Max, Gen Speed +* C = Performance State, Min, Gen Speed +* 1 = Performance State, Max, Lane # +* 3 = Performance State, Min, Lane # +* +* B = Power Saving State, Max, Gen Speed +* D = Power Saving State, Min, Gen Speed +* 2 = Power Saving State, Max, Lane # +* 4 = Power Saving State, Min, Lane # +* +* +* DPM Index Gen Speed Lane # +* 5 A 1 +* 4 B 2 +* 3 C 1 +* 2 D 2 +* 1 C 3 +* 0 D 4 +* +*/ +static int iceland_setup_default_pcie_tables (struct pp_hwmgr *hwmgr) +{ +iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend); + +PP_ASSERT_WITH_CODE ((data->use_pcie_performance_levels || + data->use_pcie_power_saving_levels), +"No pcie performance levels!" , return -EINVAL ); + +if (data->use_pcie_performance_levels && !data->use_pcie_power_saving_levels) { + data->pcie_gen_power_saving = data->pcie_gen_performance; + data->pcie_lane_power_saving = data->pcie_lane_performance; + }else if (!data->use_pcie_performance_levels && data->use_pcie_power_saving_levels) { + data->pcie_gen_performance = data->pcie_gen_power_saving; + data->pcie_lane_performance = data->pcie_lane_power_saving; + } + +iceland_reset_single_dpm_table (hwmgr, &data->dpm_table.pcie_speed_table,SMU71_MAX_LEVELS_LINK ); + +/* Hardcode Pcie Table */ +iceland_setup_pcie_table_entry (&data->dpm_table.pcie_speed_table,0 , +get_pcie_gen_support (data->pcie_gen_cap, PP_Min_PCIEGen), +get_pcie_lane_support (data->pcie_lane_cap, PP_Max_PCIELane)); +iceland_setup_pcie_table_entry (&data->dpm_table.pcie_speed_table,1 , +get_pcie_gen_support (data->pcie_gen_cap, PP_Min_PCIEGen), +get_pcie_lane_support (data->pcie_lane_cap, PP_Max_PCIELane)); +iceland_setup_pcie_table_entry (&data->dpm_table.pcie_speed_table,2 , +get_pcie_gen_support (data->pcie_gen_cap, PP_Max_PCIEGen), +get_pcie_lane_support (data->pcie_lane_cap, PP_Max_PCIELane)); +iceland_setup_pcie_table_entry (&data->dpm_table.pcie_speed_table,3 , +get_pcie_gen_support (data->pcie_gen_cap, PP_Max_PCIEGen), +get_pcie_lane_support (data->pcie_lane_cap, PP_Max_PCIELane)); +iceland_setup_pcie_table_entry (&data->dpm_table.pcie_speed_table,4 , +get_pcie_gen_support (data->pcie_gen_cap, PP_Max_PCIEGen), +get_pcie_lane_support (data->pcie_lane_cap, PP_Max_PCIELane)); +iceland_setup_pcie_table_entry (&data->dpm_table.pcie_speed_table,5 , +get_pcie_gen_support (data->pcie_gen_cap, PP_Max_PCIEGen), +get_pcie_lane_support (data->pcie_lane_cap, PP_Max_PCIELane)); + data->dpm_table.pcie_speed_table.count =6 ; + +return 0 ; + +} + + +/* +* This function is to initalize all DPM state tables for SMU7 based on the dependency table. +* Dynamic state patching function will then trim these state tables to the allowed range based +* on the power policy or external client requests, such as UVD request, etc. +*/ +static int iceland_setup_default_dpm_tables (struct pp_hwmgr *hwmgr) +{ +iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend); +uint32_t i; + +struct phm_clock_voltage_dependency_table *allowed_vdd_sclk_table = + hwmgr->dyn_state.vddc_dependency_on_sclk; +struct phm_clock_voltage_dependency_table *allowed_vdd_mclk_table = + hwmgr->dyn_state.vddc_dependency_on_mclk; +struct phm_cac_leakage_table *std_voltage_table = + hwmgr->dyn_state.cac_leakage_table; + +PP_ASSERT_WITH_CODE (allowed_vdd_sclk_table !=NULL , +"SCLK dependency table is missing. This table is mandatory" , return -1 ); +PP_ASSERT_WITH_CODE (allowed_vdd_sclk_table->count >=1 , +"SCLK dependency table has to have is missing. This table is mandatory" , return -1 ); + +PP_ASSERT_WITH_CODE (allowed_vdd_mclk_table !=NULL , +"MCLK dependency table is missing. This table is mandatory" , return -1 ); +PP_ASSERT_WITH_CODE (allowed_vdd_mclk_table->count >=1 , +"VMCLK dependency table has to have is missing. This table is mandatory" , return -1 ); + +/* clear the state table to reset everything to default */ +memset (&(data->dpm_table),0x00 ,sizeof (data->dpm_table)); +iceland_reset_single_dpm_table (hwmgr, &data->dpm_table.sclk_table,SMU71_MAX_LEVELS_GRAPHICS ); +iceland_reset_single_dpm_table (hwmgr, &data->dpm_table.mclk_table,SMU71_MAX_LEVELS_MEMORY ); +iceland_reset_single_dpm_table (hwmgr, &data->dpm_table.vddc_table,SMU71_MAX_LEVELS_VDDC ); +iceland_reset_single_dpm_table (hwmgr, &data->dpm_table.vdd_ci_table,SMU71_MAX_LEVELS_VDDCI ); +iceland_reset_single_dpm_table (hwmgr, &data->dpm_table.mvdd_table,SMU71_MAX_LEVELS_MVDD ); + +PP_ASSERT_WITH_CODE (allowed_vdd_sclk_table !=NULL , +"SCLK dependency table is missing. This table is mandatory" , return -1 ); +/* Initialize Sclk DPM table based on allow Sclk values*/ + data->dpm_table.sclk_table.count =0 ; + +for (i =0 ; i < allowed_vdd_sclk_table->count; i++) { +if (i ==0 || data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count-1 ].value != + allowed_vdd_sclk_table->entries[i].clk) { + data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count].value = + allowed_vdd_sclk_table->entries[i].clk; + data->dpm_table.sclk_table.dpm_levels[data->dpm_table.sclk_table.count].enabled =1 ;/*(i==0) ? 1 : 0; to do */ + data->dpm_table.sclk_table.count++; + } + } + +PP_ASSERT_WITH_CODE (allowed_vdd_mclk_table !=NULL , +"MCLK dependency table is missing. This table is mandatory" , return -1 ); +/* Initialize Mclk DPM table based on allow Mclk values */ + data->dpm_table.mclk_table.count =0 ; +for (i =0 ; i < allowed_vdd_mclk_table->count; i++) { +if (i ==0 || data->dpm_table.mclk_table.dpm_levels[data->dpm_table.mclk_table.count-1 ].value != + allowed_vdd_mclk_table->entries[i].clk) { + data->dpm_table.mclk_table.dpm_levels[data->dpm_table.mclk_table.count].value = + allowed_vdd_mclk_table->entries[i].clk; + data->dpm_table.mclk_table.dpm_levels[data->dpm_table.mclk_table.count].enabled =1 ;/*(i==0) ? 1 : 0; */ + data->dpm_table.mclk_table.count++; + } + } + +/* Initialize Vddc DPM table based on allow Vddc values. And populate corresponding std values. */ +for (i =0 ; i < allowed_vdd_sclk_table->count; i++) { + data->dpm_table.vddc_table.dpm_levels[i].value = allowed_vdd_mclk_table->entries[i].v; + data->dpm_table.vddc_table.dpm_levels[i].param1 = std_voltage_table->entries[i].Leakage; +/* param1 is for corresponding std voltage */ + data->dpm_table.vddc_table.dpm_levels[i].enabled =1 ; + } + + data->dpm_table.vddc_table.count = allowed_vdd_sclk_table->count; + allowed_vdd_mclk_table = hwmgr->dyn_state.vddci_dependency_on_mclk; + +if (NULL != allowed_vdd_mclk_table) { +/* Initialize Vddci DPM table based on allow Mclk values */ +for (i =0 ; i < allowed_vdd_mclk_table->count; i++) { + data->dpm_table.vdd_ci_table.dpm_levels[i].value = allowed_vdd_mclk_table->entries[i].v; + data->dpm_table.vdd_ci_table.dpm_levels[i].enabled =1 ; + } + data->dpm_table.vdd_ci_table.count = allowed_vdd_mclk_table->count; + } + + allowed_vdd_mclk_table = hwmgr->dyn_state.mvdd_dependency_on_mclk; + +if (NULL != allowed_vdd_mclk_table) { +/* +* Initialize MVDD DPM table based on allow Mclk +* values +*/ +for (i =0 ; i < allowed_vdd_mclk_table->count; i++) { + data->dpm_table.mvdd_table.dpm_levels[i].value = allowed_vdd_mclk_table->entries[i].v; + data->dpm_table.mvdd_table.dpm_levels[i].enabled =1 ; + } + data->dpm_table.mvdd_table.count = allowed_vdd_mclk_table->count; + } + +/* setup PCIE gen speed levels*/ +iceland_setup_default_pcie_tables (hwmgr); + +/* save a copy of the default DPM table*/ +memcpy (&(data->golden_dpm_table), &(data->dpm_table),sizeof (struct iceland_dpm_table )); + +return 0 ; +} + +/** +* @brief PhwIceland_GetVoltageOrder +* Returns index of requested voltage record in lookup(table) +* @param hwmgr - pointer to hardware manager +* @param lookutab - lookup list to search in +* @param voltage - voltage to look for +* @return 0 on success +*/ +uint8_t iceland_get_voltage_index (phm_ppt_v1_voltage_lookup_table *look_up_table, +uint16_t voltage) +{ +uint8_t count = (uint8_t ) (look_up_table->count); +uint8_t i; + + PP_ASSERT_WITH_CODE((NULL != look_up_table), "Lookup Table empty.", return 0;); + PP_ASSERT_WITH_CODE((0 != count), "Lookup Table empty.", return 0;); + +for (i =0 ; i < count; i++) { +/* find first voltage equal or bigger than requested */ +if (look_up_table->entries[i].us_vdd >= voltage) +return i; + } + +/* voltage is bigger than max voltage in the table */ +return i-1 ; +} + + +static int iceland_get_std_voltage_value_sidd (struct pp_hwmgr *hwmgr, +pp_atomctrl_voltage_table_entry *tab,uint16_t *hi, +uint16_t *lo) +{ +uint16_t v_index; +bool vol_found = false; + *hi = tab->value *VOLTAGE_SCALE ; + *lo = tab->value *VOLTAGE_SCALE ; + +/* SCLK/VDDC Dependency Table has to exist. */ +PP_ASSERT_WITH_CODE (NULL != hwmgr->dyn_state.vddc_dependency_on_sclk, +"The SCLK/VDDC Dependency Table does not exist.\n" , + return -EINVAL ); + +if (NULL == hwmgr->dyn_state.cac_leakage_table) { +pr_warning ("CAC Leakage Table does not exist, using vddc.\n" ); +return 0 ; + } + +/* +* Since voltage in the sclk/vddc dependency table is not +* necessarily in ascending order because of ELB voltage +* patching, loop through entire list to find exact voltage. +*/ +for (v_index =0 ; (uint32_t )v_index < hwmgr->dyn_state.vddc_dependency_on_sclk->count; v_index++) { +if (tab->value == hwmgr->dyn_state.vddc_dependency_on_sclk->entries[v_index].v) { + vol_found = true; +if ((uint32_t )v_index < hwmgr->dyn_state.cac_leakage_table->count) { + *lo = hwmgr->dyn_state.cac_leakage_table->entries[v_index].Vddc *VOLTAGE_SCALE ; + *hi = (uint16_t )(hwmgr->dyn_state.cac_leakage_table->entries[v_index].Leakage *VOLTAGE_SCALE ); + }else { +pr_warning ("Index from SCLK/VDDC Dependency Table exceeds the CAC Leakage Table index, using maximum index from CAC table.\n" ); + *lo = hwmgr->dyn_state.cac_leakage_table->entries[hwmgr->dyn_state.cac_leakage_table->count -1 ].Vddc *VOLTAGE_SCALE ; + *hi = (uint16_t )(hwmgr->dyn_state.cac_leakage_table->entries[hwmgr->dyn_state.cac_leakage_table->count -1 ].Leakage *VOLTAGE_SCALE ); + } +break ; + } + } + +/* +* If voltage is not found in the first pass, loop again to +* find the best match, equal or higher value. +*/ +if (!vol_found) { +for (v_index =0 ; (uint32_t )v_index < hwmgr->dyn_state.vddc_dependency_on_sclk->count; v_index++) { +if (tab->value <= hwmgr->dyn_state.vddc_dependency_on_sclk->entries[v_index].v) { + vol_found = true; +if ((uint32_t )v_index < hwmgr->dyn_state.cac_leakage_table->count) { + *lo = hwmgr->dyn_state.cac_leakage_table->entries[v_index].Vddc *VOLTAGE_SCALE ; + *hi = (uint16_t )(hwmgr->dyn_state.cac_leakage_table->entries[v_index].Leakage) *VOLTAGE_SCALE ; + }else { +pr_warning ("Index from SCLK/VDDC Dependency Table exceeds the CAC Leakage Table index in second look up, using maximum index from CAC table." ); + *lo = hwmgr->dyn_state.cac_leakage_table->entries[hwmgr->dyn_state.cac_leakage_table->count -1 ].Vddc *VOLTAGE_SCALE ; + *hi = (uint16_t )(hwmgr->dyn_state.cac_leakage_table->entries[hwmgr->dyn_state.cac_leakage_table->count -1 ].Leakage *VOLTAGE_SCALE ); + } +break ; + } + } + +if (!vol_found) +pr_warning ("Unable to get std_vddc from SCLK/VDDC Dependency Table, using vddc.\n" ); + } + +return 0 ; +} + +static int iceland_populate_smc_voltage_table (struct pp_hwmgr *hwmgr, +pp_atomctrl_voltage_table_entry *tab, +SMU71_Discrete_VoltageLevel *smc_voltage_tab) { +int result; + + + result =iceland_get_std_voltage_value_sidd (hwmgr, tab, + &smc_voltage_tab->StdVoltageHiSidd, + &smc_voltage_tab->StdVoltageLoSidd); +if (0 != result) { + smc_voltage_tab->StdVoltageHiSidd = tab->value *VOLTAGE_SCALE ; + smc_voltage_tab->StdVoltageLoSidd = tab->value *VOLTAGE_SCALE ; + } + + smc_voltage_tab->Voltage =PP_HOST_TO_SMC_US (tab->value *VOLTAGE_SCALE ); +CONVERT_FROM_HOST_TO_SMC_US (smc_voltage_tab->StdVoltageHiSidd); +CONVERT_FROM_HOST_TO_SMC_US (smc_voltage_tab->StdVoltageHiSidd); + +return 0 ; +} + +/** +* Vddc table preparation for SMC. +* +* @param hwmgr the address of the hardware manager +* @param table the SMC DPM table structure to be populated +* @return always 0 +*/ +static int iceland_populate_smc_vddc_table (struct pp_hwmgr *hwmgr, +SMU71_Discrete_DpmTable *table) +{ +unsigned int count; +int result; + +iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend); + + table->VddcLevelCount = data->vddc_voltage_table.count; +for (count =0 ; count < table->VddcLevelCount; count++) { + result =iceland_populate_smc_voltage_table (hwmgr, + &data->vddc_voltage_table.entries[count], + &table->VddcLevel[count]); +PP_ASSERT_WITH_CODE (0 == result,"do not populate SMC VDDC voltage table" , return -EINVAL ); + +/* GPIO voltage control */ +if (ICELAND_VOLTAGE_CONTROL_BY_GPIO == data->voltage_control) + table->VddcLevel[count].Smio |= data->vddc_voltage_table.entries[count].smio_low; +else if (ICELAND_VOLTAGE_CONTROL_BY_SVID2 == data->voltage_control) + table->VddcLevel[count].Smio =0 ; + } + +CONVERT_FROM_HOST_TO_SMC_UL (table->VddcLevelCount); + +return 0 ; +} + +/** +* Vddci table preparation for SMC. +* +* @param *hwmgr The address of the hardware manager. +* @param *table The SMC DPM table structure to be populated. +* @return 0 +*/ +static int iceland_populate_smc_vdd_ci_table (struct pp_hwmgr *hwmgr, +SMU71_Discrete_DpmTable *table) +{ +int result; +uint32_t count; +iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend); + + table->VddciLevelCount = data->vddci_voltage_table.count; +for (count =0 ; count < table->VddciLevelCount; count++) { + result =iceland_populate_smc_voltage_table (hwmgr, + &data->vddci_voltage_table.entries[count], + &table->VddciLevel[count]); +PP_ASSERT_WITH_CODE (0 == result,"do not populate SMC VDDCI voltage table" , return -EINVAL ); + +/* GPIO voltage control */ +if (ICELAND_VOLTAGE_CONTROL_BY_GPIO == data->vdd_ci_control) + table->VddciLevel[count].Smio |= data->vddci_voltage_table.entries[count].smio_low; +else + table->VddciLevel[count].Smio =0 ; + } + +CONVERT_FROM_HOST_TO_SMC_UL (table->VddcLevelCount); + +return 0 ; +} + +/** +* Mvdd table preparation for SMC. +* +* @param *hwmgr The address of the hardware manager. +* @param *table The SMC DPM table structure to be populated. +* @return 0 +*/ +static int iceland_populate_smc_mvdd_table (struct pp_hwmgr *hwmgr, +SMU71_Discrete_DpmTable *table) +{ +int result; +uint32_t count; +iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend); + + table->MvddLevelCount = data->mvdd_voltage_table.count; +for (count =0 ; count < table->MvddLevelCount; count++) { + result =iceland_populate_smc_voltage_table (hwmgr, + &data->mvdd_voltage_table.entries[count], + &table->MvddLevel[count]); +PP_ASSERT_WITH_CODE (0 == result,"do not populate SMC VDDCI voltage table" , return -EINVAL ); + +/* GPIO voltage control */ +if (ICELAND_VOLTAGE_CONTROL_BY_GPIO == data->mvdd_control) + table->MvddLevel[count].Smio |= data->mvdd_voltage_table.entries[count].smio_low; +else + table->MvddLevel[count].Smio =0 ; + } + +CONVERT_FROM_HOST_TO_SMC_UL (table->MvddLevelCount); + +return 0 ; +} + +/** +* Convert a voltage value in mv unit to VID number required by SMU firmware +*/ +static uint8_t convert_to_vid (uint16_t vddc) +{ +return (uint8_t ) ((6200 - (vddc *VOLTAGE_SCALE )) /25 ); +} + +int iceland_populate_bapm_vddc_vid_sidd (struct pp_hwmgr *hwmgr) +{ +int i; +struct iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend); +uint8_t * hi_vid = data->power_tune_table.BapmVddCVidHiSidd; +uint8_t * lo_vid = data->power_tune_table.BapmVddCVidLoSidd; + +PP_ASSERT_WITH_CODE (NULL != hwmgr->dyn_state.cac_leakage_table, +"The CAC Leakage table does not exist!" , return -EINVAL ); +PP_ASSERT_WITH_CODE (hwmgr->dyn_state.cac_leakage_table->count <=8 , +"There should never be more than 8 entries for BapmVddcVid!!!" , return -EINVAL ); +PP_ASSERT_WITH_CODE (hwmgr->dyn_state.cac_leakage_table->count == hwmgr->dyn_state.vddc_dependency_on_sclk->count, +"CACLeakageTable->count and VddcDependencyOnSCLk->count not equal" , return -EINVAL ); + +if (phm_cap_enabled (hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_EVV)) { +for (i =0 ; (uint32_t ) i < hwmgr->dyn_state.cac_leakage_table->count; i++) { + lo_vid[i] =convert_to_vid (hwmgr->dyn_state.cac_leakage_table->entries[i].Vddc1); + hi_vid[i] =convert_to_vid (hwmgr->dyn_state.cac_leakage_table->entries[i].Vddc2); + } + }else { +PP_ASSERT_WITH_CODE (false,"Iceland should always support EVV" , return -EINVAL ); + } + +return 0 ; +} + +int iceland_populate_vddc_vid (struct pp_hwmgr *hwmgr) +{ +int i; +struct iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend); +uint8_t *vid = data->power_tune_table.VddCVid; + +PP_ASSERT_WITH_CODE (data->vddc_voltage_table.count <=8 , +"There should never be more than 8 entries for VddcVid!!!" , + return -EINVAL ); + +for (i =0 ; i < (int )data->vddc_voltage_table.count; i++) { + vid[i] =convert_to_vid (data->vddc_voltage_table.entries[i].value); + } + +return 0 ; +} + +/** +* Preparation of voltage tables for SMC. +* +* @param hwmgr the address of the hardware manager +* @param table the SMC DPM table structure to be populated +* @return always 0 +*/ + +int iceland_populate_smc_voltage_tables (struct pp_hwmgr *hwmgr, +SMU71_Discrete_DpmTable *table) +{ +int result; + + result =iceland_populate_smc_vddc_table (hwmgr, table); +PP_ASSERT_WITH_CODE (0 == result, +"can not populate VDDC voltage table to SMC" , return -1 ); + + result =iceland_populate_smc_vdd_ci_table (hwmgr, table); +PP_ASSERT_WITH_CODE (0 == result, +"can not populate VDDCI voltage table to SMC" , return -1 ); + + result =iceland_populate_smc_mvdd_table (hwmgr, table); +PP_ASSERT_WITH_CODE (0 == result, +"can not populate MVDD voltage table to SMC" , return -1 ); + +return 0 ; +} + + +/** +* Re-generate the DPM level mask value +* @param hwmgr the address of the hardware manager +*/ +static uint32_t iceland_get_dpm_level_enable_mask_value ( +struct iceland_single_dpm_table * dpm_table) +{ +uint32_t i; +uint32_t mask_value =0 ; + +for (i = dpm_table->count; i >0 ; i--) { + mask_value = mask_value <<1 ; + +if (dpm_table->dpm_levels[i-1 ].enabled) + mask_value |=0x1 ; +else + mask_value &=0xFFFFFFFE ; + } +return mask_value; +} + +int iceland_populate_memory_timing_parameters ( +struct pp_hwmgr *hwmgr, +uint32_t engine_clock, +uint32_t memory_clock, +struct SMU71_Discrete_MCArbDramTimingTableEntry *arb_regs + ) +{ +uint32_t dramTiming; +uint32_t dramTiming2; +uint32_t burstTime; +int result; + + result =atomctrl_set_engine_dram_timings_rv770 (hwmgr, + engine_clock, memory_clock); + +PP_ASSERT_WITH_CODE (result ==0 , + "Error calling VBIOS to set DRAM_TIMING.", return result); + + dramTiming =cgs_read_register (hwmgr->device, mmMC_ARB_DRAM_TIMING); + dramTiming2 =cgs_read_register (hwmgr->device, mmMC_ARB_DRAM_TIMING2); + burstTime =PHM_READ_FIELD (hwmgr->device,MC_ARB_BURST_TIME ,STATE0 ); + + arb_regs->McArbDramTiming =PP_HOST_TO_SMC_UL (dramTiming); + arb_regs->McArbDramTiming2 =PP_HOST_TO_SMC_UL (dramTiming2); + arb_regs->McArbBurstTime = (uint8_t )burstTime; + +return 0 ; +} + +/** +* Setup parameters for the MC ARB. +* +* @param hwmgr the address of the powerplay hardware manager. +* @return always 0 +* This function is to be called from the SetPowerState table. +*/ +int iceland_program_memory_timing_parameters (struct pp_hwmgr *hwmgr) +{ +iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend); +int result =0 ; +SMU71_Discrete_MCArbDramTimingTable arb_regs; +uint32_t i, j; + +memset (&arb_regs,0x00 ,sizeof (SMU71_Discrete_MCArbDramTimingTable)); + +for (i =0 ; i < data->dpm_table.sclk_table.count; i++) { +for (j =0 ; j < data->dpm_table.mclk_table.count; j++) { + result =iceland_populate_memory_timing_parameters + (hwmgr, data->dpm_table.sclk_table.dpm_levels[i].value, + data->dpm_table.mclk_table.dpm_levels[j].value, + &arb_regs.entries[i][j]); + +if (0 != result) { +break ; + } + } + } + +if (0 == result) { + result =iceland_copy_bytes_to_smc ( + hwmgr->smumgr, + data->arb_table_start, + (uint8_t *)&arb_regs, +sizeof (SMU71_Discrete_MCArbDramTimingTable), + data->sram_end + ); + } + +return result; +} + +static int iceland_populate_smc_link_level (struct pp_hwmgr *hwmgr,SMU71_Discrete_DpmTable *table) +{ +iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend); +struct iceland_dpm_table *dpm_table = &data->dpm_table; +uint32_t i; + +/* Index (dpm_table->pcie_speed_table.count) is reserved for PCIE boot level. */ +for (i =0 ; i <= dpm_table->pcie_speed_table.count; i++) { + table->LinkLevel[i].PcieGenSpeed = + (uint8_t )dpm_table->pcie_speed_table.dpm_levels[i].value; + table->LinkLevel[i].PcieLaneCount = + (uint8_t )encode_pcie_lane_width (dpm_table->pcie_speed_table.dpm_levels[i].param1); + table->LinkLevel[i].EnabledForActivity = +1 ; + table->LinkLevel[i].SPC = + (uint8_t )(data->pcie_spc_cap &0xff ); + table->LinkLevel[i].DownThreshold = +PP_HOST_TO_SMC_UL (5 ); + table->LinkLevel[i].UpThreshold = +PP_HOST_TO_SMC_UL (30 ); + } + + data->smc_state_table.LinkLevelCount = + (uint8_t )dpm_table->pcie_speed_table.count; + data->dpm_level_enable_mask.pcie_dpm_enable_mask = +iceland_get_dpm_level_enable_mask_value (&dpm_table->pcie_speed_table); + +return 0 ; +} + +static int iceland_populate_smc_uvd_level (struct pp_hwmgr *hwmgr, +SMU71_Discrete_DpmTable *table) +{ +return 0 ; +} + +uint8_t iceland_get_voltage_id (pp_atomctrl_voltage_table *voltage_table, +uint32_t voltage) +{ +uint8_t count = (uint8_t ) (voltage_table->count); +uint8_t i =0 ; + +PP_ASSERT_WITH_CODE ((NULL != voltage_table), + "Voltage Table empty.", return 0;); +PP_ASSERT_WITH_CODE ((0 != count), + "Voltage Table empty.", return 0;); + +for (i =0 ; i < count; i++) { +/* find first voltage bigger than requested */ +if (voltage_table->entries[i].value >= voltage) +return i; + } + +/* voltage is bigger than max voltage in the table */ +return i -1 ; +} + +static int iceland_populate_smc_vce_level (struct pp_hwmgr *hwmgr, +SMU71_Discrete_DpmTable *table) +{ +return 0 ; +} + +static int iceland_populate_smc_acp_level (struct pp_hwmgr *hwmgr, +SMU71_Discrete_DpmTable *table) +{ +return 0 ; +} + +static int iceland_populate_smc_samu_level (struct pp_hwmgr *hwmgr, +SMU71_Discrete_DpmTable *table) +{ +return 0 ; +} + + +static int iceland_populate_smc_svi2_config (struct pp_hwmgr *hwmgr, +SMU71_Discrete_DpmTable *tab) +{ +iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend); + +if (ICELAND_VOLTAGE_CONTROL_BY_SVID2 == data->voltage_control) + tab->SVI2Enable |=VDDC_ON_SVI2 ; + +if (ICELAND_VOLTAGE_CONTROL_BY_SVID2 == data->vdd_ci_control) + tab->SVI2Enable |=VDDCI_ON_SVI2 ; +else + tab->MergedVddci =1 ; + +if (ICELAND_VOLTAGE_CONTROL_BY_SVID2 == data->mvdd_control) + tab->SVI2Enable |=MVDD_ON_SVI2 ; + +PP_ASSERT_WITH_CODE ( tab->SVI2Enable != (VDDC_ON_SVI2 |VDDCI_ON_SVI2 |MVDD_ON_SVI2 ) && + (tab->SVI2Enable &VDDC_ON_SVI2 ),"SVI2 domain configuration is incorrect!" , return -EINVAL ); + +return 0 ; +} + +static int iceland_get_dependecy_volt_by_clk (struct pp_hwmgr *hwmgr, +struct phm_clock_voltage_dependency_table *allowed_clock_voltage_table, +uint32_t clock,uint32_t *vol) +{ +uint32_t i =0 ; + +/* clock - voltage dependency table is empty table */ +if (allowed_clock_voltage_table->count ==0 ) +return -EINVAL ; + +for (i =0 ; i < allowed_clock_voltage_table->count; i++) { +/* find first sclk bigger than request */ +if (allowed_clock_voltage_table->entries[i].clk >= clock) { + *vol = allowed_clock_voltage_table->entries[i].v; +return 0 ; + } + } + +/* sclk is bigger than max sclk in the dependence table */ + *vol = allowed_clock_voltage_table->entries[i -1 ].v; + +return 0 ; +} + +static uint8_t iceland_get_mclk_frequency_ratio (uint32_t memory_clock, +bool strobe_mode) +{ +uint8_t mc_para_index; + +if (strobe_mode) { +if (memory_clock <12500 ) { + mc_para_index =0x00 ; + }else if (memory_clock >47500 ) { + mc_para_index =0x0f ; + }else { + mc_para_index = (uint8_t )((memory_clock -10000 ) /2500 ); + } + }else { +if (memory_clock <65000 ) { + mc_para_index =0x00 ; + }else if (memory_clock >135000 ) { + mc_para_index =0x0f ; + }else { + mc_para_index = (uint8_t )((memory_clock -60000 ) /5000 ); + } + } + +return mc_para_index; +} + +static uint8_t iceland_get_ddr3_mclk_frequency_ratio (uint32_t memory_clock) +{ +uint8_t mc_para_index; + +if (memory_clock <10000 ) { + mc_para_index =0 ; + }else if (memory_clock >=80000 ) { + mc_para_index =0x0f ; + }else { + mc_para_index = (uint8_t )((memory_clock -10000 ) /5000 +1 ); + } + +return mc_para_index; +} + +static int iceland_populate_phase_value_based_on_sclk (struct pp_hwmgr *hwmgr,const struct phm_phase_shedding_limits_table *pl, +uint32_t sclk,uint32_t *p_shed) +{ +unsigned int i; + +/* use the minimum phase shedding */ + *p_shed =1 ; + +/* +* PPGen ensures the phase shedding limits table is sorted +* from lowest voltage/sclk/mclk to highest voltage/sclk/mclk. +* VBIOS ensures the phase shedding masks table is sorted from +* least phases enabled (phase shedding on) to most phases +* enabled (phase shedding off). +*/ +for (i =0 ; i < pl->count; i++) { +if (sclk < pl->entries[i].Sclk) { +/* Enable phase shedding */ + *p_shed = i; +break ; + } + } + +return 0 ; +} + +static int iceland_populate_phase_value_based_on_mclk (struct pp_hwmgr *hwmgr,const struct phm_phase_shedding_limits_table *pl, +uint32_t memory_clock,uint32_t *p_shed) +{ +unsigned int i; + +/* use the minimum phase shedding */ + *p_shed =1 ; + +/* +* PPGen ensures the phase shedding limits table is sorted +* from lowest voltage/sclk/mclk to highest voltage/sclk/mclk. +* VBIOS ensures the phase shedding masks table is sorted from +* least phases enabled (phase shedding on) to most phases +* enabled (phase shedding off). +*/ +for (i =0 ; i < pl->count; i++) { +if (memory_clock < pl->entries[i].Mclk) { +/* Enable phase shedding */ + *p_shed = i; +break ; + } + } + +return 0 ; +} + +/** +* Populates the SMC MCLK structure using the provided memory clock +* +* @param hwmgr the address of the hardware manager +* @param memory_clock the memory clock to use to populate the structure +* @param sclk the SMC SCLK structure to be populated +*/ +static int iceland_calculate_mclk_params ( +struct pp_hwmgr *hwmgr, +uint32_t memory_clock, +SMU71_Discrete_MemoryLevel *mclk, +bool strobe_mode, +bool dllStateOn + ) +{ +const iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend); +uint32_t dll_cntl = data->clock_registers.vDLL_CNTL; +uint32_t mclk_pwrmgt_cntl = data->clock_registers.vMCLK_PWRMGT_CNTL; +uint32_t mpll_ad_func_cntl = data->clock_registers.vMPLL_AD_FUNC_CNTL; +uint32_t mpll_dq_func_cntl = data->clock_registers.vMPLL_DQ_FUNC_CNTL; +uint32_t mpll_func_cntl = data->clock_registers.vMPLL_FUNC_CNTL; +uint32_t mpll_func_cntl_1 = data->clock_registers.vMPLL_FUNC_CNTL_1; +uint32_t mpll_func_cntl_2 = data->clock_registers.vMPLL_FUNC_CNTL_2; +uint32_t mpll_ss1 = data->clock_registers.vMPLL_SS1; +uint32_t mpll_ss2 = data->clock_registers.vMPLL_SS2; + +pp_atomctrl_memory_clock_param mpll_param; +int result; + + result =atomctrl_get_memory_pll_dividers_si (hwmgr, + memory_clock, &mpll_param, strobe_mode); +PP_ASSERT_WITH_CODE (0 == result, + "Error retrieving Memory Clock Parameters from VBIOS.", return result); + +/* MPLL_FUNC_CNTL setup*/ + mpll_func_cntl =PHM_SET_FIELD (mpll_func_cntl,MPLL_FUNC_CNTL ,BWCTRL , mpll_param.bw_ctrl); + +/* MPLL_FUNC_CNTL_1 setup*/ + mpll_func_cntl_1 =PHM_SET_FIELD (mpll_func_cntl_1, +MPLL_FUNC_CNTL_1 ,CLKF , mpll_param.mpll_fb_divider.cl_kf); + mpll_func_cntl_1 =PHM_SET_FIELD (mpll_func_cntl_1, +MPLL_FUNC_CNTL_1 ,CLKFRAC , mpll_param.mpll_fb_divider.clk_frac); + mpll_func_cntl_1 =PHM_SET_FIELD (mpll_func_cntl_1, +MPLL_FUNC_CNTL_1 ,VCO_MODE , mpll_param.vco_mode); + +/* MPLL_AD_FUNC_CNTL setup*/ + mpll_ad_func_cntl =PHM_SET_FIELD (mpll_ad_func_cntl, +MPLL_AD_FUNC_CNTL ,YCLK_POST_DIV , mpll_param.mpll_post_divider); + +if (data->is_memory_GDDR5) { +/* MPLL_DQ_FUNC_CNTL setup*/ + mpll_dq_func_cntl =PHM_SET_FIELD (mpll_dq_func_cntl, +MPLL_DQ_FUNC_CNTL ,YCLK_SEL , mpll_param.yclk_sel); + mpll_dq_func_cntl =PHM_SET_FIELD (mpll_dq_func_cntl, +MPLL_DQ_FUNC_CNTL ,YCLK_POST_DIV , mpll_param.mpll_post_divider); + } + +if (phm_cap_enabled (hwmgr->platform_descriptor.platformCaps, + PHM_PlatformCaps_MemorySpreadSpectrumSupport)) { +/* +************************************ +Fref = Reference Frequency +NF = Feedback divider ratio +NR = Reference divider ratio +Fnom = Nominal VCO output frequency = Fref * NF / NR +Fs = Spreading Rate +D = Percentage down-spread / 2 +Fint = Reference input frequency to PFD = Fref / NR +NS = Spreading rate divider ratio = int(Fint / (2 * Fs)) +CLKS = NS - 1 = ISS_STEP_NUM[11:0] +NV = D * Fs / Fnom * 4 * ((Fnom/Fref * NR) ^ 2) +CLKV = 65536 * NV = ISS_STEP_SIZE[25:0] +************************************* +*/ +pp_atomctrl_internal_ss_info ss_info; +uint32_t freq_nom; +uint32_t tmp; +uint32_t reference_clock =atomctrl_get_mpll_reference_clock (hwmgr); + +/* for GDDR5 for all modes and DDR3 */ +if (1 == mpll_param.qdr) + freq_nom = memory_clock *4 * (1 << mpll_param.mpll_post_divider); +else + freq_nom = memory_clock *2 * (1 << mpll_param.mpll_post_divider); + +/* tmp = (freq_nom / reference_clock * reference_divider) ^ 2 Note: S.I. reference_divider = 1*/ + tmp = (freq_nom / reference_clock); + tmp = tmp * tmp; + +if (0 ==atomctrl_get_memory_clock_spread_spectrum (hwmgr, freq_nom, &ss_info)) { +/* ss_info.speed_spectrum_percentage -- in unit of 0.01% */ +/* ss.Info.speed_spectrum_rate -- in unit of khz */ +/* CLKS = reference_clock / (2 * speed_spectrum_rate * reference_divider) * 10 */ +/* = reference_clock * 5 / speed_spectrum_rate */ +uint32_t clks = reference_clock *5 / ss_info.speed_spectrum_rate; + +/* CLKV = 65536 * speed_spectrum_percentage / 2 * spreadSpecrumRate / freq_nom * 4 / 100000 * ((freq_nom / reference_clock) ^ 2) */ +/* = 131 * speed_spectrum_percentage * speed_spectrum_rate / 100 * ((freq_nom / reference_clock) ^ 2) / freq_nom */ +uint32_t clkv = + (uint32_t )((((131 * ss_info.speed_spectrum_percentage * + ss_info.speed_spectrum_rate) /100 ) * tmp) / freq_nom); + + mpll_ss1 =PHM_SET_FIELD (mpll_ss1,MPLL_SS1 ,CLKV , clkv); + mpll_ss2 =PHM_SET_FIELD (mpll_ss2,MPLL_SS2 ,CLKS , clks); + } + } + +/* MCLK_PWRMGT_CNTL setup */ + mclk_pwrmgt_cntl =PHM_SET_FIELD (mclk_pwrmgt_cntl, +MCLK_PWRMGT_CNTL ,DLL_SPEED , mpll_param.dll_speed); + mclk_pwrmgt_cntl =PHM_SET_FIELD (mclk_pwrmgt_cntl, +MCLK_PWRMGT_CNTL ,MRDCK0_PDNB , dllStateOn); + mclk_pwrmgt_cntl =PHM_SET_FIELD (mclk_pwrmgt_cntl, +MCLK_PWRMGT_CNTL ,MRDCK1_PDNB , dllStateOn); + + +/* Save the result data to outpupt memory level structure */ + mclk->MclkFrequency = memory_clock; + mclk->MpllFuncCntl = mpll_func_cntl; + mclk->MpllFuncCntl_1 = mpll_func_cntl_1; + mclk->MpllFuncCntl_2 = mpll_func_cntl_2; + mclk->MpllAdFuncCntl = mpll_ad_func_cntl; + mclk->MpllDqFuncCntl = mpll_dq_func_cntl; + mclk->MclkPwrmgtCntl = mclk_pwrmgt_cntl; + mclk->DllCntl = dll_cntl; + mclk->MpllSs1 = mpll_ss1; + mclk->MpllSs2 = mpll_ss2; + +return 0 ; +} + +static int iceland_populate_single_memory_level ( +struct pp_hwmgr *hwmgr, +uint32_t memory_clock, +SMU71_Discrete_MemoryLevel *memory_level + ) +{ +iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend); +int result =0 ; +bool dllStateOn; +struct cgs_display_info info = {0 }; + + +if (NULL != hwmgr->dyn_state.vddc_dependency_on_mclk) { + result =iceland_get_dependecy_volt_by_clk (hwmgr, + hwmgr->dyn_state.vddc_dependency_on_mclk, memory_clock, &memory_level->MinVddc); +PP_ASSERT_WITH_CODE ((0 == result), + "can not find MinVddc voltage value from memory VDDC voltage dependency table", return result); + } + +if (data->vdd_ci_control ==ICELAND_VOLTAGE_CONTROL_NONE ) { + memory_level->MinVddci = memory_level->MinVddc; + }else if (NULL != hwmgr->dyn_state.vddci_dependency_on_mclk) { + result =iceland_get_dependecy_volt_by_clk (hwmgr, + hwmgr->dyn_state.vddci_dependency_on_mclk, + memory_clock, + &memory_level->MinVddci); +PP_ASSERT_WITH_CODE ((0 == result), + "can not find MinVddci voltage value from memory VDDCI voltage dependency table", return result); + } + +if (NULL != hwmgr->dyn_state.mvdd_dependency_on_mclk) { + result =iceland_get_dependecy_volt_by_clk (hwmgr, + hwmgr->dyn_state.mvdd_dependency_on_mclk, memory_clock, &memory_level->MinMvdd); +PP_ASSERT_WITH_CODE ((0 == result), + "can not find MinMVDD voltage value from memory MVDD voltage dependency table", return result); + } + + memory_level->MinVddcPhases =1 ; + +if (data->vddc_phase_shed_control) { +iceland_populate_phase_value_based_on_mclk (hwmgr, hwmgr->dyn_state.vddc_phase_shed_limits_table, + memory_clock, &memory_level->MinVddcPhases); + } + + memory_level->EnabledForThrottle =1 ; + memory_level->EnabledForActivity =1 ; + memory_level->UpHyst =0 ; + memory_level->DownHyst =100 ; + memory_level->VoltageDownHyst =0 ; + +/* Indicates maximum activity level for this performance level.*/ + memory_level->ActivityLevel = (uint16_t )data->mclk_activity_target; + memory_level->StutterEnable =0 ; + memory_level->StrobeEnable =0 ; + memory_level->EdcReadEnable =0 ; + memory_level->EdcWriteEnable =0 ; + memory_level->RttEnable =0 ; + +/* default set to low watermark. Highest level will be set to high later.*/ + memory_level->DisplayWatermark =PPSMC_DISPLAY_WATERMARK_LOW ; + +cgs_get_active_displays_info (hwmgr->device, &info); + data->display_timing.num_existing_displays = info.display_count; + +//if ((data->mclk_stutter_mode_threshold != 0) && +// (memory_clock <= data->mclk_stutter_mode_threshold) && +// (data->is_uvd_enabled == 0) +// && (PHM_READ_FIELD(hwmgr->device, DPG_PIPE_STUTTER_CONTROL, STUTTER_ENABLE) & 0x1) +// && (data->display_timing.num_existing_displays <= 2) +// && (data->display_timing.num_existing_displays != 0)) +// memory_level->StutterEnable = 1; + +/* decide strobe mode*/ + memory_level->StrobeEnable = (data->mclk_strobe_mode_threshold !=0 ) && + (memory_clock <= data->mclk_strobe_mode_threshold); + +/* decide EDC mode and memory clock ratio*/ +if (data->is_memory_GDDR5) { + memory_level->StrobeRatio =iceland_get_mclk_frequency_ratio (memory_clock, + memory_level->StrobeEnable); + +if ((data->mclk_edc_enable_threshold !=0 ) && + (memory_clock > data->mclk_edc_enable_threshold)) { + memory_level->EdcReadEnable =1 ; + } + +if ((data->mclk_edc_wr_enable_threshold !=0 ) && + (memory_clock > data->mclk_edc_wr_enable_threshold)) { + memory_level->EdcWriteEnable =1 ; + } + +if (memory_level->StrobeEnable) { +if (iceland_get_mclk_frequency_ratio (memory_clock,1 ) >= + ((cgs_read_register (hwmgr->device, mmMC_SEQ_MISC7) >>16 ) &0xf )) { + dllStateOn = ((cgs_read_register (hwmgr->device, mmMC_SEQ_MISC5) >>1 ) &0x1 ) ?1 :0 ; + }else { + dllStateOn = ((cgs_read_register (hwmgr->device, mmMC_SEQ_MISC6) >>1 ) &0x1 ) ?1 :0 ; + } + + }else { + dllStateOn = data->dll_defaule_on; + } + }else { + memory_level->StrobeRatio = +iceland_get_ddr3_mclk_frequency_ratio (memory_clock); + dllStateOn = ((cgs_read_register (hwmgr->device, mmMC_SEQ_MISC5) >>1 ) &0x1 ) ?1 :0 ; + } + + result =iceland_calculate_mclk_params (hwmgr, + memory_clock, memory_level, memory_level->StrobeEnable, dllStateOn); + +if (0 == result) { + memory_level->MinVddc =PP_HOST_TO_SMC_UL (memory_level->MinVddc *VOLTAGE_SCALE ); +CONVERT_FROM_HOST_TO_SMC_UL (memory_level->MinVddcPhases); + memory_level->MinVddci =PP_HOST_TO_SMC_UL (memory_level->MinVddci *VOLTAGE_SCALE ); + memory_level->MinMvdd =PP_HOST_TO_SMC_UL (memory_level->MinMvdd *VOLTAGE_SCALE ); +/* MCLK frequency in units of 10KHz*/ +CONVERT_FROM_HOST_TO_SMC_UL (memory_level->MclkFrequency); +/* Indicates maximum activity level for this performance level.*/ +CONVERT_FROM_HOST_TO_SMC_US (memory_level->ActivityLevel); +CONVERT_FROM_HOST_TO_SMC_UL (memory_level->MpllFuncCntl); +CONVERT_FROM_HOST_TO_SMC_UL (memory_level->MpllFuncCntl_1); +CONVERT_FROM_HOST_TO_SMC_UL (memory_level->MpllFuncCntl_2); +CONVERT_FROM_HOST_TO_SMC_UL (memory_level->MpllAdFuncCntl); +CONVERT_FROM_HOST_TO_SMC_UL (memory_level->MpllDqFuncCntl); +CONVERT_FROM_HOST_TO_SMC_UL (memory_level->MclkPwrmgtCntl); +CONVERT_FROM_HOST_TO_SMC_UL (memory_level->DllCntl); +CONVERT_FROM_HOST_TO_SMC_UL (memory_level->MpllSs1); +CONVERT_FROM_HOST_TO_SMC_UL (memory_level->MpllSs2); + } + +return result; +} + +/** +* Populates the SMC MVDD structure using the provided memory clock. +* +* @param hwmgr the address of the hardware manager +* @param mclk the MCLK value to be used in the decision if MVDD should be high or low. +* @param voltage the SMC VOLTAGE structure to be populated +*/ +int iceland_populate_mvdd_value (struct pp_hwmgr *hwmgr,uint32_t mclk,SMU71_Discrete_VoltageLevel *voltage) +{ +const iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend); +uint32_t i =0 ; + +if (ICELAND_VOLTAGE_CONTROL_NONE != data->mvdd_control) { +/* find mvdd value which clock is more than request */ +for (i =0 ; i < hwmgr->dyn_state.mvdd_dependency_on_mclk->count; i++) { +if (mclk <= hwmgr->dyn_state.mvdd_dependency_on_mclk->entries[i].clk) { +/* Always round to higher voltage. */ + voltage->Voltage = data->mvdd_voltage_table.entries[i].value; +break ; + } + } + +PP_ASSERT_WITH_CODE (i < hwmgr->dyn_state.mvdd_dependency_on_mclk->count, +"MVDD Voltage is outside the supported range." , return -1 ); + + }else { +return -1 ; + } + +return 0 ; +} + + +static int iceland_populate_smc_acpi_level (struct pp_hwmgr *hwmgr, +SMU71_Discrete_DpmTable *table) +{ +int result =0 ; +const iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend); +pp_atomctrl_clock_dividers_vi dividers; +SMU71_Discrete_VoltageLevel voltage_level; +uint32_t spll_func_cntl = data->clock_registers.vCG_SPLL_FUNC_CNTL; +uint32_t spll_func_cntl_2 = data->clock_registers.vCG_SPLL_FUNC_CNTL_2; +uint32_t dll_cntl = data->clock_registers.vDLL_CNTL; +uint32_t mclk_pwrmgt_cntl = data->clock_registers.vMCLK_PWRMGT_CNTL; + +/* The ACPI state should not do DPM on DC (or ever).*/ + table->ACPILevel.Flags &= ~PPSMC_SWSTATE_FLAG_DC ; + +if (data->acpi_vddc) + table->ACPILevel.MinVddc =PP_HOST_TO_SMC_UL (data->acpi_vddc *VOLTAGE_SCALE ); +else + table->ACPILevel.MinVddc =PP_HOST_TO_SMC_UL (data->min_vddc_in_pp_table *VOLTAGE_SCALE ); + + table->ACPILevel.MinVddcPhases = (data->vddc_phase_shed_control) ?0 :1 ; + +/* assign zero for now*/ + table->ACPILevel.SclkFrequency =atomctrl_get_reference_clock (hwmgr); + +/* get the engine clock dividers for this clock value*/ + result =atomctrl_get_engine_pll_dividers_vi (hwmgr, + table->ACPILevel.SclkFrequency, ÷rs); + +PP_ASSERT_WITH_CODE (result ==0 , + "Error retrieving Engine Clock dividers from VBIOS.", return result); + +/* divider ID for required SCLK*/ + table->ACPILevel.SclkDid = (uint8_t )dividers.pll_post_divider; + table->ACPILevel.DisplayWatermark =PPSMC_DISPLAY_WATERMARK_LOW ; + table->ACPILevel.DeepSleepDivId =0 ; + + spll_func_cntl =PHM_SET_FIELD (spll_func_cntl, +CG_SPLL_FUNC_CNTL ,SPLL_PWRON ,0 ); + spll_func_cntl =PHM_SET_FIELD (spll_func_cntl, +CG_SPLL_FUNC_CNTL ,SPLL_RESET ,1 ); + spll_func_cntl_2 =PHM_SET_FIELD (spll_func_cntl_2, +CG_SPLL_FUNC_CNTL_2 ,SCLK_MUX_SEL ,4 ); + + table->ACPILevel.CgSpllFuncCntl = spll_func_cntl; + table->ACPILevel.CgSpllFuncCntl2 = spll_func_cntl_2; + table->ACPILevel.CgSpllFuncCntl3 = data->clock_registers.vCG_SPLL_FUNC_CNTL_3; + table->ACPILevel.CgSpllFuncCntl4 = data->clock_registers.vCG_SPLL_FUNC_CNTL_4; + table->ACPILevel.SpllSpreadSpectrum = data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM; + table->ACPILevel.SpllSpreadSpectrum2 = data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM_2; + table->ACPILevel.CcPwrDynRm =0 ; + table->ACPILevel.CcPwrDynRm1 =0 ; + + +/* For various features to be enabled/disabled while this level is active.*/ +CONVERT_FROM_HOST_TO_SMC_UL (table->ACPILevel.Flags); +/* SCLK frequency in units of 10KHz*/ +CONVERT_FROM_HOST_TO_SMC_UL (table->ACPILevel.SclkFrequency); +CONVERT_FROM_HOST_TO_SMC_UL (table->ACPILevel.CgSpllFuncCntl); +CONVERT_FROM_HOST_TO_SMC_UL (table->ACPILevel.CgSpllFuncCntl2); +CONVERT_FROM_HOST_TO_SMC_UL (table->ACPILevel.CgSpllFuncCntl3); +CONVERT_FROM_HOST_TO_SMC_UL (table->ACPILevel.CgSpllFuncCntl4); +CONVERT_FROM_HOST_TO_SMC_UL (table->ACPILevel.SpllSpreadSpectrum); +CONVERT_FROM_HOST_TO_SMC_UL (table->ACPILevel.SpllSpreadSpectrum2); +CONVERT_FROM_HOST_TO_SMC_UL (table->ACPILevel.CcPwrDynRm); +CONVERT_FROM_HOST_TO_SMC_UL (table->ACPILevel.CcPwrDynRm1); + + table->MemoryACPILevel.MinVddc = table->ACPILevel.MinVddc; + table->MemoryACPILevel.MinVddcPhases = table->ACPILevel.MinVddcPhases; + +/* CONVERT_FROM_HOST_TO_SMC_UL(table->MemoryACPILevel.MinVoltage);*/ + +if (0 ==iceland_populate_mvdd_value (hwmgr,0 , &voltage_level)) + table->MemoryACPILevel.MinMvdd = +PP_HOST_TO_SMC_UL (voltage_level.Voltage *VOLTAGE_SCALE ); +else + table->MemoryACPILevel.MinMvdd =0 ; + +/* Force reset on DLL*/ + mclk_pwrmgt_cntl =PHM_SET_FIELD (mclk_pwrmgt_cntl, +MCLK_PWRMGT_CNTL ,MRDCK0_RESET ,0x1 ); + mclk_pwrmgt_cntl =PHM_SET_FIELD (mclk_pwrmgt_cntl, +MCLK_PWRMGT_CNTL ,MRDCK1_RESET ,0x1 ); + +/* Disable DLL in ACPIState*/ + mclk_pwrmgt_cntl =PHM_SET_FIELD (mclk_pwrmgt_cntl, +MCLK_PWRMGT_CNTL ,MRDCK0_PDNB ,0 ); + mclk_pwrmgt_cntl =PHM_SET_FIELD (mclk_pwrmgt_cntl, +MCLK_PWRMGT_CNTL ,MRDCK1_PDNB ,0 ); + +/* Enable DLL bypass signal*/ + dll_cntl =PHM_SET_FIELD (dll_cntl, +DLL_CNTL ,MRDCK0_BYPASS ,0 ); + dll_cntl =PHM_SET_FIELD (dll_cntl, +DLL_CNTL ,MRDCK1_BYPASS ,0 ); + + table->MemoryACPILevel.DllCntl = +PP_HOST_TO_SMC_UL (dll_cntl); + table->MemoryACPILevel.MclkPwrmgtCntl = +PP_HOST_TO_SMC_UL (mclk_pwrmgt_cntl); + table->MemoryACPILevel.MpllAdFuncCntl = +PP_HOST_TO_SMC_UL (data->clock_registers.vMPLL_AD_FUNC_CNTL); + table->MemoryACPILevel.MpllDqFuncCntl = +PP_HOST_TO_SMC_UL (data->clock_registers.vMPLL_DQ_FUNC_CNTL); + table->MemoryACPILevel.MpllFuncCntl = +PP_HOST_TO_SMC_UL (data->clock_registers.vMPLL_FUNC_CNTL); + table->MemoryACPILevel.MpllFuncCntl_1 = +PP_HOST_TO_SMC_UL (data->clock_registers.vMPLL_FUNC_CNTL_1); + table->MemoryACPILevel.MpllFuncCntl_2 = +PP_HOST_TO_SMC_UL (data->clock_registers.vMPLL_FUNC_CNTL_2); + table->MemoryACPILevel.MpllSs1 = +PP_HOST_TO_SMC_UL (data->clock_registers.vMPLL_SS1); + table->MemoryACPILevel.MpllSs2 = +PP_HOST_TO_SMC_UL (data->clock_registers.vMPLL_SS2); + + table->MemoryACPILevel.EnabledForThrottle =0 ; + table->MemoryACPILevel.EnabledForActivity =0 ; + table->MemoryACPILevel.UpHyst =0 ; + table->MemoryACPILevel.DownHyst =100 ; + table->MemoryACPILevel.VoltageDownHyst =0 ; +/* Indicates maximum activity level for this performance level.*/ + table->MemoryACPILevel.ActivityLevel =PP_HOST_TO_SMC_US ((uint16_t )data->mclk_activity_target); + + table->MemoryACPILevel.StutterEnable =0 ; + table->MemoryACPILevel.StrobeEnable =0 ; + table->MemoryACPILevel.EdcReadEnable =0 ; + table->MemoryACPILevel.EdcWriteEnable =0 ; + table->MemoryACPILevel.RttEnable =0 ; + +return result; +} + +static int iceland_find_boot_level (struct iceland_single_dpm_table *table,uint32_t value,uint32_t *boot_level) +{ +int result =0 ; +uint32_t i; + +for (i =0 ; i < table->count; i++) { +if (value == table->dpm_levels[i].value) { + *boot_level = i; + result =0 ; + } + } +return result; +} + +/** +* Calculates the SCLK dividers using the provided engine clock +* +* @param hwmgr the address of the hardware manager +* @param engine_clock the engine clock to use to populate the structure +* @param sclk the SMC SCLK structure to be populated +*/ +int iceland_calculate_sclk_params (struct pp_hwmgr *hwmgr, +uint32_t engine_clock,SMU71_Discrete_GraphicsLevel *sclk) +{ +const iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend); +pp_atomctrl_clock_dividers_vi dividers; +uint32_t spll_func_cntl = data->clock_registers.vCG_SPLL_FUNC_CNTL; +uint32_t spll_func_cntl_3 = data->clock_registers.vCG_SPLL_FUNC_CNTL_3; +uint32_t spll_func_cntl_4 = data->clock_registers.vCG_SPLL_FUNC_CNTL_4; +uint32_t cg_spll_spread_spectrum = data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM; +uint32_t cg_spll_spread_spectrum_2 = data->clock_registers.vCG_SPLL_SPREAD_SPECTRUM_2; +uint32_t reference_clock; +uint32_t reference_divider; +uint32_t fbdiv; +int result; + +/* get the engine clock dividers for this clock value*/ + result =atomctrl_get_engine_pll_dividers_vi (hwmgr, engine_clock, ÷rs); + +PP_ASSERT_WITH_CODE (result ==0 , + "Error retrieving Engine Clock dividers from VBIOS.", return result); + +/* To get FBDIV we need to multiply this by 16384 and divide it by Fref.*/ + reference_clock =atomctrl_get_reference_clock (hwmgr); + + reference_divider =1 + dividers.uc_pll_ref_div; + +/* low 14 bits is fraction and high 12 bits is divider*/ + fbdiv = dividers.ul_fb_div.ul_fb_divider &0x3FFFFFF ; + +/* SPLL_FUNC_CNTL setup*/ + spll_func_cntl =PHM_SET_FIELD (spll_func_cntl, +CG_SPLL_FUNC_CNTL ,SPLL_REF_DIV , dividers.uc_pll_ref_div); + spll_func_cntl =PHM_SET_FIELD (spll_func_cntl, +CG_SPLL_FUNC_CNTL ,SPLL_PDIV_A , dividers.uc_pll_post_div); + +/* SPLL_FUNC_CNTL_3 setup*/ + spll_func_cntl_3 =PHM_SET_FIELD (spll_func_cntl_3, +CG_SPLL_FUNC_CNTL_3 ,SPLL_FB_DIV , fbdiv); + +/* set to use fractional accumulation*/ + spll_func_cntl_3 =PHM_SET_FIELD (spll_func_cntl_3, +CG_SPLL_FUNC_CNTL_3 ,SPLL_DITHEN ,1 ); + +if (phm_cap_enabled (hwmgr->platform_descriptor.platformCaps, + PHM_PlatformCaps_EngineSpreadSpectrumSupport)) { +pp_atomctrl_internal_ss_info ss_info; + +uint32_t vcoFreq = engine_clock * dividers.uc_pll_post_div; +if (0 ==atomctrl_get_engine_clock_spread_spectrum (hwmgr, vcoFreq, &ss_info)) { +/* +* ss_info.speed_spectrum_percentage -- in unit of 0.01% +* ss_info.speed_spectrum_rate -- in unit of khz +*/ +/* clks = reference_clock * 10 / (REFDIV + 1) / speed_spectrum_rate / 2 */ +uint32_t clkS = reference_clock *5 / (reference_divider * ss_info.speed_spectrum_rate); + +/* clkv = 2 * D * fbdiv / NS */ +uint32_t clkV =4 * ss_info.speed_spectrum_percentage * fbdiv / (clkS *10000 ); + + cg_spll_spread_spectrum = +PHM_SET_FIELD (cg_spll_spread_spectrum,CG_SPLL_SPREAD_SPECTRUM ,CLKS , clkS); + cg_spll_spread_spectrum = +PHM_SET_FIELD (cg_spll_spread_spectrum,CG_SPLL_SPREAD_SPECTRUM ,SSEN ,1 ); + cg_spll_spread_spectrum_2 = +PHM_SET_FIELD (cg_spll_spread_spectrum_2,CG_SPLL_SPREAD_SPECTRUM_2 ,CLKV , clkV); + } + } + + sclk->SclkFrequency = engine_clock; + sclk->CgSpllFuncCntl3 = spll_func_cntl_3; + sclk->CgSpllFuncCntl4 = spll_func_cntl_4; + sclk->SpllSpreadSpectrum = cg_spll_spread_spectrum; + sclk->SpllSpreadSpectrum2 = cg_spll_spread_spectrum_2; + sclk->SclkDid = (uint8_t )dividers.pll_post_divider; + +return 0 ; +} + +static uint8_t iceland_get_sleep_divider_id_from_clock (struct pp_hwmgr *hwmgr, +uint32_t engine_clock,uint32_t min_engine_clock_in_sr) +{ +uint32_t i, temp; +uint32_t min = (min_engine_clock_in_sr >ICELAND_MINIMUM_ENGINE_CLOCK ) ? + min_engine_clock_in_sr :ICELAND_MINIMUM_ENGINE_CLOCK ; + +PP_ASSERT_WITH_CODE ((engine_clock >= min), + "Engine clock can't satisfy stutter requirement!", return 0); + +for (i =ICELAND_MAX_DEEPSLEEP_DIVIDER_ID ;; i--) { + temp = engine_clock / (1 << i); + +if (temp >= min || i ==0 ) +break ; + } +return (uint8_t )i; +} + +/** +* Populates single SMC SCLK structure using the provided engine clock +* +* @param hwmgr the address of the hardware manager +* @param engine_clock the engine clock to use to populate the structure +* @param sclk the SMC SCLK structure to be populated +*/ +static int iceland_populate_single_graphic_level (struct pp_hwmgr *hwmgr, +uint32_t engine_clock,uint16_t sclk_activity_level_threshold, +SMU71_Discrete_GraphicsLevel *graphic_level) +{ +int result; +uint32_t threshold; +iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend); + + result =iceland_calculate_sclk_params (hwmgr, engine_clock, graphic_level); + + +/* populate graphics levels*/ + result =iceland_get_dependecy_volt_by_clk (hwmgr, + hwmgr->dyn_state.vddc_dependency_on_sclk, engine_clock, &graphic_level->MinVddc); +PP_ASSERT_WITH_CODE ((0 == result), + "can not find VDDC voltage value for VDDC engine clock dependency table", return result); + +/* SCLK frequency in units of 10KHz*/ + graphic_level->SclkFrequency = engine_clock; + +/* +* Minimum VDDC phases required to support this level, it +* should get from dependence table. +*/ + graphic_level->MinVddcPhases =1 ; + +if (data->vddc_phase_shed_control) { +iceland_populate_phase_value_based_on_sclk (hwmgr, + hwmgr->dyn_state.vddc_phase_shed_limits_table, + engine_clock, + &graphic_level->MinVddcPhases); + } + +/* Indicates maximum activity level for this performance level. 50% for now*/ + graphic_level->ActivityLevel = sclk_activity_level_threshold; + + graphic_level->CcPwrDynRm =0 ; + graphic_level->CcPwrDynRm1 =0 ; +/* this level can be used if activity is high enough.*/ + graphic_level->EnabledForActivity =1 ; +/* this level can be used for throttling.*/ + graphic_level->EnabledForThrottle =1 ; + graphic_level->UpHyst =0 ; + graphic_level->DownHyst =100 ; + graphic_level->VoltageDownHyst =0 ; + graphic_level->PowerThrottle =0 ; + + threshold = engine_clock * data->fast_watermark_threshold /100 ; + +if (phm_cap_enabled (hwmgr->platform_descriptor.platformCaps, + PHM_PlatformCaps_SclkDeepSleep)) { + graphic_level->DeepSleepDivId = +iceland_get_sleep_divider_id_from_clock (hwmgr, engine_clock, + data->display_timing.min_clock_insr); + } + +/* Default to slow, highest DPM level will be set to PPSMC_DISPLAY_WATERMARK_LOW later.*/ + graphic_level->DisplayWatermark =PPSMC_DISPLAY_WATERMARK_LOW ; + +if (0 == result) { + graphic_level->MinVddc =PP_HOST_TO_SMC_UL (graphic_level->MinVddc *VOLTAGE_SCALE ); +/* CONVERT_FROM_HOST_TO_SMC_UL(graphic_level->MinVoltage);*/ +CONVERT_FROM_HOST_TO_SMC_UL (graphic_level->MinVddcPhases); +CONVERT_FROM_HOST_TO_SMC_UL (graphic_level->SclkFrequency); +CONVERT_FROM_HOST_TO_SMC_US (graphic_level->ActivityLevel); +CONVERT_FROM_HOST_TO_SMC_UL (graphic_level->CgSpllFuncCntl3); +CONVERT_FROM_HOST_TO_SMC_UL (graphic_level->CgSpllFuncCntl4); +CONVERT_FROM_HOST_TO_SMC_UL (graphic_level->SpllSpreadSpectrum); +CONVERT_FROM_HOST_TO_SMC_UL (graphic_level->SpllSpreadSpectrum2); +CONVERT_FROM_HOST_TO_SMC_UL (graphic_level->CcPwrDynRm); +CONVERT_FROM_HOST_TO_SMC_UL (graphic_level->CcPwrDynRm1); + } + +return result; +} + +/** +* Populates all SMC SCLK levels' structure based on the trimmed allowed dpm engine clock states +* +* @param hwmgr the address of the hardware manager +*/ +static int iceland_populate_all_graphic_levels (struct pp_hwmgr *hwmgr) +{ +iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend); +struct iceland_dpm_table *dpm_table = &data->dpm_table; +int result =0 ; +uint32_t level_array_adress = data->dpm_table_start + + offsetof(SMU71_Discrete_DpmTable , GraphicsLevel); + +uint32_t level_array_size =sizeof (SMU71_Discrete_GraphicsLevel) *SMU71_MAX_LEVELS_GRAPHICS ; +SMU71_Discrete_GraphicsLevel *levels = data->smc_state_table.GraphicsLevel; +uint32_t i; +uint8_t highest_pcie_level_enabled =0 , lowest_pcie_level_enabled =0 , mid_pcie_level_enabled =0 , count =0 ; +memset (levels,0x00 , level_array_size); + +for (i =0 ; i < dpm_table->sclk_table.count; i++) { + result =iceland_populate_single_graphic_level (hwmgr, + dpm_table->sclk_table.dpm_levels[i].value, + (uint16_t )data->activity_target[i], + &(data->smc_state_table.GraphicsLevel[i])); +if (0 != result) +return result; + +/* Making sure only DPM level 0-1 have Deep Sleep Div ID populated. */ +if (i >1 ) + data->smc_state_table.GraphicsLevel[i].DeepSleepDivId =0 ; + } + +/* set highest level watermark to high */ +if (dpm_table->sclk_table.count >1 ) + data->smc_state_table.GraphicsLevel[dpm_table->sclk_table.count-1 ].DisplayWatermark = +PPSMC_DISPLAY_WATERMARK_HIGH ; + + data->smc_state_table.GraphicsDpmLevelCount = + (uint8_t )dpm_table->sclk_table.count; + data->dpm_level_enable_mask.sclk_dpm_enable_mask = +iceland_get_dpm_level_enable_mask_value (&dpm_table->sclk_table); + +while ((data->dpm_level_enable_mask.pcie_dpm_enable_mask & + (1 << (highest_pcie_level_enabled +1 ))) !=0 ) { + highest_pcie_level_enabled++; + } + +while ((data->dpm_level_enable_mask.pcie_dpm_enable_mask & + (1 << lowest_pcie_level_enabled)) ==0 ) { + lowest_pcie_level_enabled++; + } + +while ((count < highest_pcie_level_enabled) && + ((data->dpm_level_enable_mask.pcie_dpm_enable_mask & + (1 << (lowest_pcie_level_enabled +1 + count))) ==0 )) { + count++; + } + + mid_pcie_level_enabled = (lowest_pcie_level_enabled+1 +count) < highest_pcie_level_enabled ? + (lowest_pcie_level_enabled +1 + count) : highest_pcie_level_enabled; + +/* set pcieDpmLevel to highest_pcie_level_enabled*/ +for (i =2 ; i < dpm_table->sclk_table.count; i++) { + data->smc_state_table.GraphicsLevel[i].pcieDpmLevel = highest_pcie_level_enabled; + } + +/* set pcieDpmLevel to lowest_pcie_level_enabled*/ + data->smc_state_table.GraphicsLevel[0 ].pcieDpmLevel = lowest_pcie_level_enabled; + +/* set pcieDpmLevel to mid_pcie_level_enabled*/ + data->smc_state_table.GraphicsLevel[1 ].pcieDpmLevel = mid_pcie_level_enabled; + +for (i =0 ; i < dpm_table->sclk_table.count; i++) + +/* level count will send to smc once at init smc table and never change*/ + result =iceland_copy_bytes_to_smc (hwmgr->smumgr, level_array_adress, (uint8_t *)levels, (uint32_t )level_array_size, data->sram_end); + +if (0 != result) +return result; + +return 0 ; +} + +/** +* Populates all SMC MCLK levels' structure based on the trimmed allowed dpm memory clock states +* +* @param hwmgr the address of the hardware manager +*/ + +static int iceland_populate_all_memory_levels (struct pp_hwmgr *hwmgr) +{ +iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend); +struct iceland_dpm_table *dpm_table = &data->dpm_table; +int result; +/* populate MCLK dpm table to SMU7 */ +uint32_t level_array_adress = data->dpm_table_start + offsetof(SMU71_Discrete_DpmTable , MemoryLevel); +uint32_t level_array_size =sizeof (SMU71_Discrete_MemoryLevel) *SMU71_MAX_LEVELS_MEMORY ; +SMU71_Discrete_MemoryLevel *levels = data->smc_state_table.MemoryLevel; +uint32_t i; + +memset (levels,0x00 , level_array_size); + +for (i =0 ; i < dpm_table->mclk_table.count; i++) { +PP_ASSERT_WITH_CODE ((0 != dpm_table->mclk_table.dpm_levels[i].value), +"can not populate memory level as memory clock is zero" , return -1 ); + result =iceland_populate_single_memory_level (hwmgr, dpm_table->mclk_table.dpm_levels[i].value, + &(data->smc_state_table.MemoryLevel[i])); +if (0 != result) { +return result; + } + } + +/* Only enable level 0 for now.*/ + data->smc_state_table.MemoryLevel[0 ].EnabledForActivity =1 ; + +/* +* in order to prevent MC activity from stutter mode to push DPM up. +* the UVD change complements this by putting the MCLK in a higher state +* by default such that we are not effected by up threshold or and MCLK DPM latency. +*/ + data->smc_state_table.MemoryLevel[0 ].ActivityLevel =0x1F ; +CONVERT_FROM_HOST_TO_SMC_US (data->smc_state_table.MemoryLevel[0 ].ActivityLevel); + + data->smc_state_table.MemoryDpmLevelCount = (uint8_t )dpm_table->mclk_table.count; + data->dpm_level_enable_mask.mclk_dpm_enable_mask =iceland_get_dpm_level_enable_mask_value (&dpm_table->mclk_table); +/* set highest level watermark to high*/ + data->smc_state_table.MemoryLevel[dpm_table->mclk_table.count-1 ].DisplayWatermark =PPSMC_DISPLAY_WATERMARK_HIGH ; + +/* level count will send to smc once at init smc table and never change*/ + result =iceland_copy_bytes_to_smc (hwmgr->smumgr, + level_array_adress, (uint8_t *)levels, (uint32_t )level_array_size, data->sram_end); + +if (0 != result) { +return result; + } + +return 0 ; +} + +struct ICELAND_DLL_SPEED_SETTING +{ +uint16_t Min;/* Minimum Data Rate*/ +uint16_t Max;/* Maximum Data Rate*/ +uint32_t dll_speed;/* The desired DLL_SPEED setting*/ +}; + +static int iceland_populate_ulv_level (struct pp_hwmgr *hwmgr,SMU71_Discrete_Ulv *pstate) +{ +int result =0 ; +iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend); +uint32_t voltage_response_time, ulv_voltage; + + pstate->CcPwrDynRm =0 ; + pstate->CcPwrDynRm1 =0 ; + +//backbiasResponseTime is use for ULV state voltage value. + result =pp_tables_get_response_times (hwmgr, &voltage_response_time, &ulv_voltage); + PP_ASSERT_WITH_CODE((0 == result), "can not get ULV voltage value", return result;); + +if (!ulv_voltage) { + data->ulv.ulv_supported = false; +return 0 ; + } + +if (ICELAND_VOLTAGE_CONTROL_BY_SVID2 != data->voltage_control) { +/* use minimum voltage if ulv voltage in pptable is bigger than minimum voltage */ +if (ulv_voltage > hwmgr->dyn_state.vddc_dependency_on_sclk->entries[0 ].v) { + pstate->VddcOffset =0 ; + } +else { +/* used in SMIO Mode. not implemented for now. this is backup only for CI. */ + pstate->VddcOffset = (uint16_t )(hwmgr->dyn_state.vddc_dependency_on_sclk->entries[0 ].v - ulv_voltage); + } + }else { +/* use minimum voltage if ulv voltage in pptable is bigger than minimum voltage */ +if (ulv_voltage > hwmgr->dyn_state.vddc_dependency_on_sclk->entries[0 ].v) { + pstate->VddcOffsetVid =0 ; + }else { +/* used in SVI2 Mode */ + pstate->VddcOffsetVid = (uint8_t )((hwmgr->dyn_state.vddc_dependency_on_sclk->entries[0 ].v - ulv_voltage) *VOLTAGE_VID_OFFSET_SCALE2 /VOLTAGE_VID_OFFSET_SCALE1 ); + } + } + +/* used in SVI2 Mode to shed phase */ + pstate->VddcPhase = (data->vddc_phase_shed_control) ?0 :1 ; + +if (0 == result) { +CONVERT_FROM_HOST_TO_SMC_UL (pstate->CcPwrDynRm); +CONVERT_FROM_HOST_TO_SMC_UL (pstate->CcPwrDynRm1); +CONVERT_FROM_HOST_TO_SMC_US (pstate->VddcOffset); + } + +return result; +} + +static int iceland_populate_ulv_state (struct pp_hwmgr *hwmgr,SMU71_Discrete_Ulv *ulv) +{ +return iceland_populate_ulv_level (hwmgr, ulv); +} + +static int iceland_populate_smc_initial_state (struct pp_hwmgr *hwmgr) +{ +iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend); +uint8_t count, level; + + count = (uint8_t )(hwmgr->dyn_state.vddc_dependency_on_sclk->count); + +for (level =0 ; level < count; level++) { +if (hwmgr->dyn_state.vddc_dependency_on_sclk->entries[level].clk + >= data->vbios_boot_state.sclk_bootup_value) { + data->smc_state_table.GraphicsBootLevel = level; +break ; + } + } + + count = (uint8_t )(hwmgr->dyn_state.vddc_dependency_on_mclk->count); + +for (level =0 ; level < count; level++) { +if (hwmgr->dyn_state.vddc_dependency_on_mclk->entries[level].clk + >= data->vbios_boot_state.mclk_bootup_value) { + data->smc_state_table.MemoryBootLevel = level; +break ; + } + } + +return 0 ; +} + +/** +* Initializes the SMC table and uploads it +* +* @param hwmgr the address of the powerplay hardware manager. +* @param pInput the pointer to input data (PowerState) +* @return always 0 +*/ +int iceland_init_smc_table (struct pp_hwmgr *hwmgr) +{ +int result; +iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend); +SMU71_Discrete_DpmTable *table = &(data->smc_state_table); +const struct phw_iceland_ulv_parm *ulv = &(data->ulv); + + result =iceland_setup_default_dpm_tables (hwmgr); +PP_ASSERT_WITH_CODE (0 == result, + "Failed to setup default DPM tables!", return result;); +memset (&(data->smc_state_table),0x00 ,sizeof (data->smc_state_table)); + +if (ICELAND_VOLTAGE_CONTROL_NONE != data->voltage_control) { +iceland_populate_smc_voltage_tables (hwmgr, table); + } + +if (phm_cap_enabled (hwmgr->platform_descriptor.platformCaps, + PHM_PlatformCaps_AutomaticDCTransition)) { + table->SystemFlags |=PPSMC_SYSTEMFLAG_GPIO_DC ; + } + +if (phm_cap_enabled (hwmgr->platform_descriptor.platformCaps, + PHM_PlatformCaps_StepVddc)) { + table->SystemFlags |=PPSMC_SYSTEMFLAG_STEPVDDC ; + } + +if (data->is_memory_GDDR5) { + table->SystemFlags |=PPSMC_SYSTEMFLAG_GDDR5 ; + } + +if (ulv->ulv_supported) { + result =iceland_populate_ulv_state (hwmgr, &data->ulv_setting); +PP_ASSERT_WITH_CODE (0 == result, + "Failed to initialize ULV state!", return result;); + +cgs_write_ind_register (hwmgr->device,CGS_IND_REG__SMC , + ixCG_ULV_PARAMETER, ulv->ch_ulv_parameter); + } + + result =iceland_populate_smc_link_level (hwmgr, table); +PP_ASSERT_WITH_CODE (0 == result, + "Failed to initialize Link Level!", return result;); + + result =iceland_populate_all_graphic_levels (hwmgr); +PP_ASSERT_WITH_CODE (0 == result, + "Failed to initialize Graphics Level!", return result;); + + result =iceland_populate_all_memory_levels (hwmgr); +PP_ASSERT_WITH_CODE (0 == result, + "Failed to initialize Memory Level!", return result;); + + result =iceland_populate_smc_acpi_level (hwmgr, table); +PP_ASSERT_WITH_CODE (0 == result, + "Failed to initialize ACPI Level!", return result;); + + result =iceland_populate_smc_vce_level (hwmgr, table); +PP_ASSERT_WITH_CODE (0 == result, + "Failed to initialize VCE Level!", return result;); + + result =iceland_populate_smc_acp_level (hwmgr, table); +PP_ASSERT_WITH_CODE (0 == result, + "Failed to initialize ACP Level!", return result;); + + result =iceland_populate_smc_samu_level (hwmgr, table); +PP_ASSERT_WITH_CODE (0 == result, + "Failed to initialize SAMU Level!", return result;); + +/* +* Since only the initial state is completely set up at this +* point (the other states are just copies of the boot state) +* we only need to populate the ARB settings for the initial +* state. +*/ + result =iceland_program_memory_timing_parameters (hwmgr); +PP_ASSERT_WITH_CODE (0 == result, + "Failed to Write ARB settings for the initial state.", return result;); + + result =iceland_populate_smc_uvd_level (hwmgr, table); +PP_ASSERT_WITH_CODE (0 == result, + "Failed to initialize UVD Level!", return result;); + + table->GraphicsBootLevel =0 ; + table->MemoryBootLevel =0 ; + +/* find boot level from dpm table */ + result =iceland_find_boot_level (&(data->dpm_table.sclk_table), + data->vbios_boot_state.sclk_bootup_value, + (uint32_t *)&(data->smc_state_table.GraphicsBootLevel)); + +if (result) +pr_warning ("VBIOS did not find boot engine clock value in dependency table.\n" ); + + result =iceland_find_boot_level (&(data->dpm_table.mclk_table), + data->vbios_boot_state.mclk_bootup_value, + (uint32_t *)&(data->smc_state_table.MemoryBootLevel)); + +if (result) +pr_warning ("VBIOS did not find boot memory clock value in dependency table.\n" ); + + table->BootVddc = data->vbios_boot_state.vddc_bootup_value; +if (ICELAND_VOLTAGE_CONTROL_NONE == data->vdd_ci_control) { + table->BootVddci = table->BootVddc; + } +else { + table->BootVddci = data->vbios_boot_state.vddci_bootup_value; + } + table->BootMVdd = data->vbios_boot_state.mvdd_bootup_value; + + result =iceland_populate_smc_initial_state (hwmgr); + PP_ASSERT_WITH_CODE(0 == result, "Failed to initialize Boot State!", return result); + + result =iceland_populate_bapm_parameters_in_dpm_table (hwmgr); + PP_ASSERT_WITH_CODE(0 == result, "Failed to populate BAPM Parameters!", return result); + + table->GraphicsVoltageChangeEnable =1 ; + table->GraphicsThermThrottleEnable =1 ; + table->GraphicsInterval =1 ; + table->VoltageInterval =1 ; + table->ThermalInterval =1 ; + table->TemperatureLimitHigh = + (data->thermal_temp_setting.temperature_high * +ICELAND_Q88_FORMAT_CONVERSION_UNIT ) /PP_TEMPERATURE_UNITS_PER_CENTIGRADES ; + table->TemperatureLimitLow = + (data->thermal_temp_setting.temperature_low * +ICELAND_Q88_FORMAT_CONVERSION_UNIT ) /PP_TEMPERATURE_UNITS_PER_CENTIGRADES ; + table->MemoryVoltageChangeEnable =1 ; + table->MemoryInterval =1 ; + table->VoltageResponseTime =0 ; + table->PhaseResponseTime =0 ; + table->MemoryThermThrottleEnable =1 ; + table->PCIeBootLinkLevel =0 ; + table->PCIeGenInterval =1 ; + + result =iceland_populate_smc_svi2_config (hwmgr, table); +PP_ASSERT_WITH_CODE (0 == result, + "Failed to populate SVI2 setting!", return result); + + table->ThermGpio =17 ; + table->SclkStepSize =0x4000 ; + +CONVERT_FROM_HOST_TO_SMC_UL (table->SystemFlags); +CONVERT_FROM_HOST_TO_SMC_UL (table->SmioMaskVddcVid); +CONVERT_FROM_HOST_TO_SMC_UL (table->SmioMaskVddcPhase); +CONVERT_FROM_HOST_TO_SMC_UL (table->SmioMaskVddciVid); +CONVERT_FROM_HOST_TO_SMC_UL (table->SmioMaskMvddVid); +CONVERT_FROM_HOST_TO_SMC_UL (table->SclkStepSize); +CONVERT_FROM_HOST_TO_SMC_US (table->TemperatureLimitHigh); +CONVERT_FROM_HOST_TO_SMC_US (table->TemperatureLimitLow); +CONVERT_FROM_HOST_TO_SMC_US (table->VoltageResponseTime); +CONVERT_FROM_HOST_TO_SMC_US (table->PhaseResponseTime); + + table->BootVddc =PP_HOST_TO_SMC_US (table->BootVddc *VOLTAGE_SCALE ); + table->BootVddci =PP_HOST_TO_SMC_US (table->BootVddci *VOLTAGE_SCALE ); + table->BootMVdd =PP_HOST_TO_SMC_US (table->BootMVdd *VOLTAGE_SCALE ); + +/* Upload all dpm data to SMC memory.(dpm level, dpm level count etc) */ + result =iceland_copy_bytes_to_smc (hwmgr->smumgr, data->dpm_table_start + + offsetof(SMU71_Discrete_DpmTable , SystemFlags), + (uint8_t *)&(table->SystemFlags), +sizeof (SMU71_Discrete_DpmTable) -3 *sizeof (SMU71_PIDController), + data->sram_end); + +PP_ASSERT_WITH_CODE (0 == result, + "Failed to upload dpm data to SMC memory!", return result); + +/* Upload all ulv setting to SMC memory.(dpm level, dpm level count etc) */ + result =iceland_copy_bytes_to_smc (hwmgr->smumgr, + data->ulv_settings_start, + (uint8_t *)&(data->ulv_setting), +sizeof (SMU71_Discrete_Ulv), + data->sram_end); + +#if 0 +/* Notify SMC to follow new GPIO scheme */ +if (phm_cap_enabled (hwmgr->platform_descriptor.platformCaps, + PHM_PlatformCaps_AutomaticDCTransition)) { +if (0 ==iceland_send_msg_to_smc (hwmgr->smumgr, PPSMC_MSG_UseNewGPIOScheme)) +phm_cap_set (hwmgr->platform_descriptor.platformCaps, + PHM_PlatformCaps_SMCtoPPLIBAcdcGpioScheme); + } +#endif + +return result; +} + +int iceland_populate_mc_reg_address (struct pp_hwmgr *hwmgr,SMU71_Discrete_MCRegisters *mc_reg_table) +{ +const struct iceland_hwmgr *data = (struct iceland_hwmgr *)(hwmgr->backend); + +uint32_t i, j; + +for (i =0 , j =0 ; j < data->iceland_mc_reg_table.last; j++) { +if (data->iceland_mc_reg_table.validflag &1 <<j) { +PP_ASSERT_WITH_CODE (i <SMU71_DISCRETE_MC_REGISTER_ARRAY_SIZE , +"Index of mc_reg_table->address[] array out of boundary" , return -1 ); + mc_reg_table->address[i].s0 = +PP_HOST_TO_SMC_US (data->iceland_mc_reg_table.mc_reg_address[j].s0);Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
drivers/gpu/drm/amd/powerplay/hwmgr/iceland_hwmgr.c line 2817
Quoted 10 lines
drivers/gpu/drm/amd/powerplay/hwmgr/iceland_hwmgr.c new file +10
-0+ mc_reg_table->address[i].s1 = +PP_HOST_TO_SMC_US (data->iceland_mc_reg_table.mc_reg_address[j].s1); + i++; + } + } + + mc_reg_table->last = (uint8_t )i; + +return 0 ; +}
No need for the type cast here.
Kind Regards,
Edward.
drivers/gpu/drm/amd/powerplay/hwmgr/iceland_thermal.h
Quoted 3,764 lines
drivers/gpu/drm/amd/powerplay/hwmgr/iceland_hwmgr.c new file +2091
-0Lines of this file are not shown. View the raw message.
drivers/gpu/drm/amd/powerplay/hwmgr/iceland_hwmgr.h new file +424
-0Lines of this file are not shown. View the raw message.
drivers/gpu/drm/amd/powerplay/hwmgr/iceland_powertune.c new file +491
-0Lines of this file are not shown. View the raw message.
drivers/gpu/drm/amd/powerplay/hwmgr/iceland_powertune.h new file +74
-0Lines of this file are not shown. View the raw message.
drivers/gpu/drm/amd/powerplay/hwmgr/iceland_thermal.c new file +595
-0Lines of this file are not shown. View the raw message.
drivers/gpu/drm/amd/powerplay/hwmgr/iceland_thermal.h new file +58
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Part of the diff is not shown here. View the raw message.
PATCH 9/15 drm/amdgpu: enable iceland powerplay manually
In reply to a message not in the archiveIt's able to enable iceland powerplay manually via the module parameter. The default state is disabled.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_powerplay.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_powerplay.c +3 -1
@@ -110,13 +110,15 @@ static int amdgpu_pp_early_init(void *handle)case CHIP_STONEY : adev->pp_enabled = (amdgpu_powerplay ==0 ) ? false : true;break ; +case CHIP_TOPAZ : + adev->pp_enabled = (amdgpu_powerplay >0 ) ? true : false; +break ;/* These chips don't have powerplay implemenations */ case CHIP_BONAIRE :case CHIP_HAWAII :case CHIP_KABINI :case CHIP_MULLINS :case CHIP_KAVERI : -case CHIP_TOPAZ :default : adev->pp_enabled = false;break ;
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 10/15 drm/amd/powerplay: rename smum header guards
In reply to a message not in the archiveThis patch renames the smum header guards to align with the file name.
--- drivers/gpu/drm/amd/amdgpu/iceland_smum.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/iceland_smum.h +2 -2
@@ -21,8 +21,8 @@* */ -#ifndef ICELAND_SMUMGR_H -#define ICELAND_SMUMGR_H +#ifndef ICELAND_SMUM_H +#define ICELAND_SMUM_H #include "ppsmc.h"
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 11/15 drm/amd/powerplay: fix the incorrect checking condition
In reply to a message not in the archive--- drivers/gpu/drm/amd/powerplay/hwmgr/iceland_hwmgr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/powerplay/hwmgr/iceland_hwmgr.c +1 -1
@@ -4170,7 +4170,7 @@ int iceland_unforce_dpm_levels(struct pp_hwmgr *hwmgr) return -1); } -if (0 == data->pcie_dpm_key_disabled) { +if (0 == data->mclk_dpm_key_disabled) { PP_ASSERT_WITH_CODE((0 == smum_send_msg_to_smc( hwmgr->smumgr, PPSMC_MSG_MCLKDPM_NoForcedLevel)),
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 12/15 drm/amd/powerplay: add deep sleep initialization
In reply to a message not in the archiveThis patch adds the deep sleep initialization at DPM, it needs send a message to SMC to enable this feature before enable voltage controller.
--- .../gpu/drm/amd/powerplay/hwmgr/iceland_hwmgr.c | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+)
drivers/gpu/drm/amd/powerplay/hwmgr/iceland_hwmgr.c +34 -0
@@ -3069,6 +3069,36 @@ static int iceland_tf_start_smc(struct pp_hwmgr *hwmgr)return ret; } +/** +* Programs the Deep Sleep registers +* +* @param pHwMgr the address of the powerplay hardware manager. +* @param pInput the pointer to input data (PhwEvergreen_DisplayConfiguration) +* @param pOutput the pointer to output data (unused) +* @param pStorage the pointer to temporary storage (unused) +* @param Result the last failure code (unused) +* @return always 0 +*/ +static int iceland_enable_deep_sleep_master_switch (struct pp_hwmgr *hwmgr) +{ +if (phm_cap_enabled (hwmgr->platform_descriptor.platformCaps, + PHM_PlatformCaps_SclkDeepSleep)) { +if (smum_send_msg_to_smc (hwmgr->smumgr, + PPSMC_MSG_MASTER_DeepSleep_ON) !=0 ) +PP_ASSERT_WITH_CODE (false, +"Attempt to enable Master Deep Sleep switch failed!" , + return -EINVAL ); + }else { +if (smum_send_msg_to_smc (hwmgr->smumgr, + PPSMC_MSG_MASTER_DeepSleep_OFF) !=0 ) +PP_ASSERT_WITH_CODE (false, +"Attempt to disable Master Deep Sleep switch failed!" , + return -EINVAL ); + } + +return 0 ; +} +static int iceland_enable_dpm_tasks (struct pp_hwmgr *hwmgr) {int tmp_result, result =0 ;
@@ -3133,6 +3163,10 @@ static int iceland_enable_dpm_tasks(struct pp_hwmgr *hwmgr)PP_ASSERT_WITH_CODE ((0 == tmp_result), "Failed to enable SCLK control!", return tmp_result); + tmp_result =iceland_enable_deep_sleep_master_switch (hwmgr); +PP_ASSERT_WITH_CODE ((tmp_result ==0 ), + "Failed to enable deep sleep!", return tmp_result); +/* enable DPM */ tmp_result =iceland_start_dpm (hwmgr); PP_ASSERT_WITH_CODE((0 == tmp_result),
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 13/15 drm/amd/powerplay: set the platform capability flags for iceland
In reply to a message not in the archive--- .../gpu/drm/amd/powerplay/hwmgr/iceland_hwmgr.c | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+)
drivers/gpu/drm/amd/powerplay/hwmgr/iceland_hwmgr.c +51 -0
@@ -3801,6 +3801,57 @@ static int iceland_hwmgr_backend_init(struct pp_hwmgr *hwmgr) stay_in_boot =phm_cap_enabled (hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_StayInBootState); +phm_cap_set (hwmgr->platform_descriptor.platformCaps, + PHM_PlatformCaps_DynamicPowerManagement); + +phm_cap_set (hwmgr->platform_descriptor.platformCaps, + PHM_PlatformCaps_ActivityReporting); + +phm_cap_set (hwmgr->platform_descriptor.platformCaps, + PHM_PlatformCaps_GFXClockGatingSupport); + +phm_cap_set (hwmgr->platform_descriptor.platformCaps, + PHM_PlatformCaps_MemorySpreadSpectrumSupport); +phm_cap_set (hwmgr->platform_descriptor.platformCaps, + PHM_PlatformCaps_EngineSpreadSpectrumSupport); + +phm_cap_set (hwmgr->platform_descriptor.platformCaps, + PHM_PlatformCaps_DynamicPCIEGen2Support); +phm_cap_set (hwmgr->platform_descriptor.platformCaps, + PHM_PlatformCaps_SMC); + +phm_cap_unset (hwmgr->platform_descriptor.platformCaps, + PHM_PlatformCaps_DisablePowerGating); +phm_cap_unset (hwmgr->platform_descriptor.platformCaps, + PHM_PlatformCaps_BACO); + +phm_cap_set (hwmgr->platform_descriptor.platformCaps, + PHM_PlatformCaps_ThermalAutoThrottling); +phm_cap_set (hwmgr->platform_descriptor.platformCaps, + PHM_PlatformCaps_DisableLSClockGating); +phm_cap_set (hwmgr->platform_descriptor.platformCaps, + PHM_PlatformCaps_SamuDPM); +phm_cap_set (hwmgr->platform_descriptor.platformCaps, + PHM_PlatformCaps_AcpDPM); +phm_cap_set (hwmgr->platform_descriptor.platformCaps, + PHM_PlatformCaps_OD6inACSupport); +phm_cap_unset (hwmgr->platform_descriptor.platformCaps, + PHM_PlatformCaps_EnablePlatformPowerManagement); + +phm_cap_set (hwmgr->platform_descriptor.platformCaps, + PHM_PlatformCaps_PauseMMSessions); + +phm_cap_set (hwmgr->platform_descriptor.platformCaps, + PHM_PlatformCaps_OD6PlusinACSupport); +phm_cap_set (hwmgr->platform_descriptor.platformCaps, + PHM_PlatformCaps_PauseMMSessions); +phm_cap_set (hwmgr->platform_descriptor.platformCaps, + PHM_PlatformCaps_GFXClockGatingManagedInCAIL); +phm_cap_set (hwmgr->platform_descriptor.platformCaps, + PHM_PlatformCaps_IcelandULPSSWWorkAround); +phm_cap_set (hwmgr->platform_descriptor.platformCaps, + PHM_PlatformCaps_PowerContainment); +/* iceland doesn't support UVD and VCE */ phm_cap_unset (hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_UVDPowerGating);
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 14/15 drm/amd/powerplay: add enabling voltage controller back
In reply to a message not in the archive--- drivers/gpu/drm/amd/powerplay/hwmgr/iceland_hwmgr.c | 2 -- 1 file changed, 2 deletions(-)
drivers/gpu/drm/amd/powerplay/hwmgr/iceland_hwmgr.c +0 -2
@@ -2970,13 +2970,11 @@ int iceland_start_dpm(struct pp_hwmgr *hwmgr)PHM_WRITE_INDIRECT_FIELD (hwmgr->device,CGS_IND_REG__PCIE ,SWRST_COMMAND_1 ,RESETLC ,0x0 ); -#if 0 PP_ASSERT_WITH_CODE ( (0 ==smum_send_msg_to_smc (hwmgr->smumgr, PPSMC_MSG_Voltage_Cntl_Enable)),"Failed to enable voltage DPM during DPM Start Function!" , return -1 ); -#endif if (0 !=iceland_enable_sclk_mclk_dpm (hwmgr)) {PP_ASSERT_WITH_CODE (0 ,"Failed to enable Sclk DPM and Mclk DPM!" , return -1 );
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 15/15 drm/amd/powerplay: add DPM running checking back
In reply to a message not in the archiveThis patch adds DPM running checking back, because the DPM issue is fixed.
--- drivers/gpu/drm/amd/powerplay/hwmgr/iceland_hwmgr.c | 2 -- 1 file changed, 2 deletions(-)
drivers/gpu/drm/amd/powerplay/hwmgr/iceland_hwmgr.c +0 -2
@@ -4239,11 +4239,9 @@ int iceland_unforce_dpm_levels(struct pp_hwmgr *hwmgr) { iceland_hwmgr *data = (iceland_hwmgr *)(hwmgr->backend); -#if 0 PP_ASSERT_WITH_CODE (0 == iceland_is_dpm_running(hwmgr), "Trying to Unforce DPM when DPM is disabled. Returning without sending SMC message.", return -1); -#endif if (0 == data->sclk_dpm_key_disabled) { PP_ASSERT_WITH_CODE((0 == smum_send_msg_to_smc(
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx