hwmgr.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  1. /*
  2. * Copyright 2015 Advanced Micro Devices, Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. */
  23. #ifndef _HWMGR_H_
  24. #define _HWMGR_H_
  25. #include <linux/seq_file.h>
  26. #include "amd_powerplay.h"
  27. #include "pp_instance.h"
  28. #include "hardwaremanager.h"
  29. #include "pp_power_source.h"
  30. #include "hwmgr_ppt.h"
  31. #include "ppatomctrl.h"
  32. #include "hwmgr_ppt.h"
  33. #include "power_state.h"
  34. struct pp_instance;
  35. struct pp_hwmgr;
  36. struct phm_fan_speed_info;
  37. struct pp_atomctrl_voltage_table;
  38. #define VOLTAGE_SCALE 4
  39. uint8_t convert_to_vid(uint16_t vddc);
  40. enum DISPLAY_GAP {
  41. DISPLAY_GAP_VBLANK_OR_WM = 0, /* Wait for vblank or MCHG watermark. */
  42. DISPLAY_GAP_VBLANK = 1, /* Wait for vblank. */
  43. DISPLAY_GAP_WATERMARK = 2, /* Wait for MCHG watermark. (Note that HW may deassert WM in VBI depending on DC_STUTTER_CNTL.) */
  44. DISPLAY_GAP_IGNORE = 3 /* Do not wait. */
  45. };
  46. typedef enum DISPLAY_GAP DISPLAY_GAP;
  47. struct vi_dpm_level {
  48. bool enabled;
  49. uint32_t value;
  50. uint32_t param1;
  51. };
  52. struct vi_dpm_table {
  53. uint32_t count;
  54. struct vi_dpm_level dpm_level[1];
  55. };
  56. enum PP_Result {
  57. PP_Result_TableImmediateExit = 0x13,
  58. };
  59. #define PCIE_PERF_REQ_REMOVE_REGISTRY 0
  60. #define PCIE_PERF_REQ_FORCE_LOWPOWER 1
  61. #define PCIE_PERF_REQ_GEN1 2
  62. #define PCIE_PERF_REQ_GEN2 3
  63. #define PCIE_PERF_REQ_GEN3 4
  64. enum PP_FEATURE_MASK {
  65. PP_SCLK_DPM_MASK = 0x1,
  66. PP_MCLK_DPM_MASK = 0x2,
  67. PP_PCIE_DPM_MASK = 0x4,
  68. PP_SCLK_DEEP_SLEEP_MASK = 0x8,
  69. PP_POWER_CONTAINMENT_MASK = 0x10,
  70. PP_UVD_HANDSHAKE_MASK = 0x20,
  71. PP_SMC_VOLTAGE_CONTROL_MASK = 0x40,
  72. PP_VBI_TIME_SUPPORT_MASK = 0x80,
  73. PP_ULV_MASK = 0x100,
  74. PP_ENABLE_GFX_CG_THRU_SMU = 0x200,
  75. PP_CLOCK_STRETCH_MASK = 0x400,
  76. PP_OD_FUZZY_FAN_CONTROL_MASK = 0x800
  77. };
  78. enum PHM_BackEnd_Magic {
  79. PHM_Dummy_Magic = 0xAA5555AA,
  80. PHM_RV770_Magic = 0xDCBAABCD,
  81. PHM_Kong_Magic = 0x239478DF,
  82. PHM_NIslands_Magic = 0x736C494E,
  83. PHM_Sumo_Magic = 0x8339FA11,
  84. PHM_SIslands_Magic = 0x369431AC,
  85. PHM_Trinity_Magic = 0x96751873,
  86. PHM_CIslands_Magic = 0x38AC78B0,
  87. PHM_Kv_Magic = 0xDCBBABC0,
  88. PHM_VIslands_Magic = 0x20130307,
  89. PHM_Cz_Magic = 0x67DCBA25
  90. };
  91. #define PHM_PCIE_POWERGATING_TARGET_GFX 0
  92. #define PHM_PCIE_POWERGATING_TARGET_DDI 1
  93. #define PHM_PCIE_POWERGATING_TARGET_PLLCASCADE 2
  94. #define PHM_PCIE_POWERGATING_TARGET_PHY 3
  95. typedef int (*phm_table_function)(struct pp_hwmgr *hwmgr, void *input,
  96. void *output, void *storage, int result);
  97. typedef bool (*phm_check_function)(struct pp_hwmgr *hwmgr);
  98. struct phm_set_power_state_input {
  99. const struct pp_hw_power_state *pcurrent_state;
  100. const struct pp_hw_power_state *pnew_state;
  101. };
  102. struct phm_acp_arbiter {
  103. uint32_t acpclk;
  104. };
  105. struct phm_uvd_arbiter {
  106. uint32_t vclk;
  107. uint32_t dclk;
  108. uint32_t vclk_ceiling;
  109. uint32_t dclk_ceiling;
  110. };
  111. struct phm_vce_arbiter {
  112. uint32_t evclk;
  113. uint32_t ecclk;
  114. };
  115. struct phm_gfx_arbiter {
  116. uint32_t sclk;
  117. uint32_t mclk;
  118. uint32_t sclk_over_drive;
  119. uint32_t mclk_over_drive;
  120. uint32_t sclk_threshold;
  121. uint32_t num_cus;
  122. };
  123. /* Entries in the master tables */
  124. struct phm_master_table_item {
  125. phm_check_function isFunctionNeededInRuntimeTable;
  126. phm_table_function tableFunction;
  127. };
  128. enum phm_master_table_flag {
  129. PHM_MasterTableFlag_None = 0,
  130. PHM_MasterTableFlag_ExitOnError = 1,
  131. };
  132. /* The header of the master tables */
  133. struct phm_master_table_header {
  134. uint32_t storage_size;
  135. uint32_t flags;
  136. const struct phm_master_table_item *master_list;
  137. };
  138. struct phm_runtime_table_header {
  139. uint32_t storage_size;
  140. bool exit_error;
  141. phm_table_function *function_list;
  142. };
  143. struct phm_clock_array {
  144. uint32_t count;
  145. uint32_t values[1];
  146. };
  147. struct phm_clock_voltage_dependency_record {
  148. uint32_t clk;
  149. uint32_t v;
  150. };
  151. struct phm_vceclock_voltage_dependency_record {
  152. uint32_t ecclk;
  153. uint32_t evclk;
  154. uint32_t v;
  155. };
  156. struct phm_uvdclock_voltage_dependency_record {
  157. uint32_t vclk;
  158. uint32_t dclk;
  159. uint32_t v;
  160. };
  161. struct phm_samuclock_voltage_dependency_record {
  162. uint32_t samclk;
  163. uint32_t v;
  164. };
  165. struct phm_acpclock_voltage_dependency_record {
  166. uint32_t acpclk;
  167. uint32_t v;
  168. };
  169. struct phm_clock_voltage_dependency_table {
  170. uint32_t count; /* Number of entries. */
  171. struct phm_clock_voltage_dependency_record entries[1]; /* Dynamically allocate count entries. */
  172. };
  173. struct phm_phase_shedding_limits_record {
  174. uint32_t Voltage;
  175. uint32_t Sclk;
  176. uint32_t Mclk;
  177. };
  178. extern int phm_dispatch_table(struct pp_hwmgr *hwmgr,
  179. struct phm_runtime_table_header *rt_table,
  180. void *input, void *output);
  181. extern int phm_construct_table(struct pp_hwmgr *hwmgr,
  182. const struct phm_master_table_header *master_table,
  183. struct phm_runtime_table_header *rt_table);
  184. extern int phm_destroy_table(struct pp_hwmgr *hwmgr,
  185. struct phm_runtime_table_header *rt_table);
  186. struct phm_uvd_clock_voltage_dependency_record {
  187. uint32_t vclk;
  188. uint32_t dclk;
  189. uint32_t v;
  190. };
  191. struct phm_uvd_clock_voltage_dependency_table {
  192. uint8_t count;
  193. struct phm_uvd_clock_voltage_dependency_record entries[1];
  194. };
  195. struct phm_acp_clock_voltage_dependency_record {
  196. uint32_t acpclk;
  197. uint32_t v;
  198. };
  199. struct phm_acp_clock_voltage_dependency_table {
  200. uint32_t count;
  201. struct phm_acp_clock_voltage_dependency_record entries[1];
  202. };
  203. struct phm_vce_clock_voltage_dependency_record {
  204. uint32_t ecclk;
  205. uint32_t evclk;
  206. uint32_t v;
  207. };
  208. struct phm_phase_shedding_limits_table {
  209. uint32_t count;
  210. struct phm_phase_shedding_limits_record entries[1];
  211. };
  212. struct phm_vceclock_voltage_dependency_table {
  213. uint8_t count; /* Number of entries. */
  214. struct phm_vceclock_voltage_dependency_record entries[1]; /* Dynamically allocate count entries. */
  215. };
  216. struct phm_uvdclock_voltage_dependency_table {
  217. uint8_t count; /* Number of entries. */
  218. struct phm_uvdclock_voltage_dependency_record entries[1]; /* Dynamically allocate count entries. */
  219. };
  220. struct phm_samuclock_voltage_dependency_table {
  221. uint8_t count; /* Number of entries. */
  222. struct phm_samuclock_voltage_dependency_record entries[1]; /* Dynamically allocate count entries. */
  223. };
  224. struct phm_acpclock_voltage_dependency_table {
  225. uint32_t count; /* Number of entries. */
  226. struct phm_acpclock_voltage_dependency_record entries[1]; /* Dynamically allocate count entries. */
  227. };
  228. struct phm_vce_clock_voltage_dependency_table {
  229. uint8_t count;
  230. struct phm_vce_clock_voltage_dependency_record entries[1];
  231. };
  232. struct pp_hwmgr_func {
  233. int (*backend_init)(struct pp_hwmgr *hw_mgr);
  234. int (*backend_fini)(struct pp_hwmgr *hw_mgr);
  235. int (*asic_setup)(struct pp_hwmgr *hw_mgr);
  236. int (*get_power_state_size)(struct pp_hwmgr *hw_mgr);
  237. int (*apply_state_adjust_rules)(struct pp_hwmgr *hwmgr,
  238. struct pp_power_state *prequest_ps,
  239. const struct pp_power_state *pcurrent_ps);
  240. int (*force_dpm_level)(struct pp_hwmgr *hw_mgr,
  241. enum amd_dpm_forced_level level);
  242. int (*dynamic_state_management_enable)(
  243. struct pp_hwmgr *hw_mgr);
  244. int (*dynamic_state_management_disable)(
  245. struct pp_hwmgr *hw_mgr);
  246. int (*patch_boot_state)(struct pp_hwmgr *hwmgr,
  247. struct pp_hw_power_state *hw_ps);
  248. int (*get_pp_table_entry)(struct pp_hwmgr *hwmgr,
  249. unsigned long, struct pp_power_state *);
  250. int (*get_num_of_pp_table_entries)(struct pp_hwmgr *hwmgr);
  251. int (*powerdown_uvd)(struct pp_hwmgr *hwmgr);
  252. int (*powergate_vce)(struct pp_hwmgr *hwmgr, bool bgate);
  253. int (*powergate_uvd)(struct pp_hwmgr *hwmgr, bool bgate);
  254. int (*get_mclk)(struct pp_hwmgr *hwmgr, bool low);
  255. int (*get_sclk)(struct pp_hwmgr *hwmgr, bool low);
  256. int (*power_state_set)(struct pp_hwmgr *hwmgr,
  257. const void *state);
  258. int (*enable_clock_power_gating)(struct pp_hwmgr *hwmgr);
  259. int (*notify_smc_display_config_after_ps_adjustment)(struct pp_hwmgr *hwmgr);
  260. int (*display_config_changed)(struct pp_hwmgr *hwmgr);
  261. int (*disable_clock_power_gating)(struct pp_hwmgr *hwmgr);
  262. int (*update_clock_gatings)(struct pp_hwmgr *hwmgr,
  263. const uint32_t *msg_id);
  264. int (*set_max_fan_rpm_output)(struct pp_hwmgr *hwmgr, uint16_t us_max_fan_pwm);
  265. int (*set_max_fan_pwm_output)(struct pp_hwmgr *hwmgr, uint16_t us_max_fan_pwm);
  266. int (*get_temperature)(struct pp_hwmgr *hwmgr);
  267. int (*stop_thermal_controller)(struct pp_hwmgr *hwmgr);
  268. int (*get_fan_speed_info)(struct pp_hwmgr *hwmgr, struct phm_fan_speed_info *fan_speed_info);
  269. int (*set_fan_control_mode)(struct pp_hwmgr *hwmgr, uint32_t mode);
  270. int (*get_fan_control_mode)(struct pp_hwmgr *hwmgr);
  271. int (*set_fan_speed_percent)(struct pp_hwmgr *hwmgr, uint32_t percent);
  272. int (*get_fan_speed_percent)(struct pp_hwmgr *hwmgr, uint32_t *speed);
  273. int (*set_fan_speed_rpm)(struct pp_hwmgr *hwmgr, uint32_t percent);
  274. int (*get_fan_speed_rpm)(struct pp_hwmgr *hwmgr, uint32_t *speed);
  275. int (*reset_fan_speed_to_default)(struct pp_hwmgr *hwmgr);
  276. int (*uninitialize_thermal_controller)(struct pp_hwmgr *hwmgr);
  277. int (*register_internal_thermal_interrupt)(struct pp_hwmgr *hwmgr,
  278. const void *thermal_interrupt_info);
  279. bool (*check_smc_update_required_for_display_configuration)(struct pp_hwmgr *hwmgr);
  280. int (*check_states_equal)(struct pp_hwmgr *hwmgr,
  281. const struct pp_hw_power_state *pstate1,
  282. const struct pp_hw_power_state *pstate2,
  283. bool *equal);
  284. int (*set_cpu_power_state)(struct pp_hwmgr *hwmgr);
  285. int (*store_cc6_data)(struct pp_hwmgr *hwmgr, uint32_t separation_time,
  286. bool cc6_disable, bool pstate_disable,
  287. bool pstate_switch_disable);
  288. int (*get_dal_power_level)(struct pp_hwmgr *hwmgr,
  289. struct amd_pp_simple_clock_info *info);
  290. int (*get_performance_level)(struct pp_hwmgr *, const struct pp_hw_power_state *,
  291. PHM_PerformanceLevelDesignation, uint32_t, PHM_PerformanceLevel *);
  292. int (*get_current_shallow_sleep_clocks)(struct pp_hwmgr *hwmgr,
  293. const struct pp_hw_power_state *state, struct pp_clock_info *clock_info);
  294. int (*get_clock_by_type)(struct pp_hwmgr *hwmgr, enum amd_pp_clock_type type, struct amd_pp_clocks *clocks);
  295. int (*get_max_high_clocks)(struct pp_hwmgr *hwmgr, struct amd_pp_simple_clock_info *clocks);
  296. int (*power_off_asic)(struct pp_hwmgr *hwmgr);
  297. int (*force_clock_level)(struct pp_hwmgr *hwmgr, enum pp_clock_type type, uint32_t mask);
  298. int (*print_clock_levels)(struct pp_hwmgr *hwmgr, enum pp_clock_type type, char *buf);
  299. int (*enable_per_cu_power_gating)(struct pp_hwmgr *hwmgr, bool enable);
  300. int (*get_sclk_od)(struct pp_hwmgr *hwmgr);
  301. int (*set_sclk_od)(struct pp_hwmgr *hwmgr, uint32_t value);
  302. int (*get_mclk_od)(struct pp_hwmgr *hwmgr);
  303. int (*set_mclk_od)(struct pp_hwmgr *hwmgr, uint32_t value);
  304. int (*read_sensor)(struct pp_hwmgr *hwmgr, int idx, int32_t *value);
  305. int (*request_firmware)(struct pp_hwmgr *hwmgr);
  306. int (*release_firmware)(struct pp_hwmgr *hwmgr);
  307. };
  308. struct pp_table_func {
  309. int (*pptable_init)(struct pp_hwmgr *hw_mgr);
  310. int (*pptable_fini)(struct pp_hwmgr *hw_mgr);
  311. int (*pptable_get_number_of_vce_state_table_entries)(struct pp_hwmgr *hw_mgr);
  312. int (*pptable_get_vce_state_table_entry)(
  313. struct pp_hwmgr *hwmgr,
  314. unsigned long i,
  315. struct amd_vce_state *vce_state,
  316. void **clock_info,
  317. unsigned long *flag);
  318. };
  319. union phm_cac_leakage_record {
  320. struct {
  321. uint16_t Vddc; /* in CI, we use it for StdVoltageHiSidd */
  322. uint32_t Leakage; /* in CI, we use it for StdVoltageLoSidd */
  323. };
  324. struct {
  325. uint16_t Vddc1;
  326. uint16_t Vddc2;
  327. uint16_t Vddc3;
  328. };
  329. };
  330. struct phm_cac_leakage_table {
  331. uint32_t count;
  332. union phm_cac_leakage_record entries[1];
  333. };
  334. struct phm_samu_clock_voltage_dependency_record {
  335. uint32_t samclk;
  336. uint32_t v;
  337. };
  338. struct phm_samu_clock_voltage_dependency_table {
  339. uint8_t count;
  340. struct phm_samu_clock_voltage_dependency_record entries[1];
  341. };
  342. struct phm_cac_tdp_table {
  343. uint16_t usTDP;
  344. uint16_t usConfigurableTDP;
  345. uint16_t usTDC;
  346. uint16_t usBatteryPowerLimit;
  347. uint16_t usSmallPowerLimit;
  348. uint16_t usLowCACLeakage;
  349. uint16_t usHighCACLeakage;
  350. uint16_t usMaximumPowerDeliveryLimit;
  351. uint16_t usOperatingTempMinLimit;
  352. uint16_t usOperatingTempMaxLimit;
  353. uint16_t usOperatingTempStep;
  354. uint16_t usOperatingTempHyst;
  355. uint16_t usDefaultTargetOperatingTemp;
  356. uint16_t usTargetOperatingTemp;
  357. uint16_t usPowerTuneDataSetID;
  358. uint16_t usSoftwareShutdownTemp;
  359. uint16_t usClockStretchAmount;
  360. uint16_t usTemperatureLimitHotspot;
  361. uint16_t usTemperatureLimitLiquid1;
  362. uint16_t usTemperatureLimitLiquid2;
  363. uint16_t usTemperatureLimitVrVddc;
  364. uint16_t usTemperatureLimitVrMvdd;
  365. uint16_t usTemperatureLimitPlx;
  366. uint8_t ucLiquid1_I2C_address;
  367. uint8_t ucLiquid2_I2C_address;
  368. uint8_t ucLiquid_I2C_Line;
  369. uint8_t ucVr_I2C_address;
  370. uint8_t ucVr_I2C_Line;
  371. uint8_t ucPlx_I2C_address;
  372. uint8_t ucPlx_I2C_Line;
  373. uint32_t usBoostPowerLimit;
  374. uint8_t ucCKS_LDO_REFSEL;
  375. };
  376. struct phm_ppm_table {
  377. uint8_t ppm_design;
  378. uint16_t cpu_core_number;
  379. uint32_t platform_tdp;
  380. uint32_t small_ac_platform_tdp;
  381. uint32_t platform_tdc;
  382. uint32_t small_ac_platform_tdc;
  383. uint32_t apu_tdp;
  384. uint32_t dgpu_tdp;
  385. uint32_t dgpu_ulv_power;
  386. uint32_t tj_max;
  387. };
  388. struct phm_vq_budgeting_record {
  389. uint32_t ulCUs;
  390. uint32_t ulSustainableSOCPowerLimitLow;
  391. uint32_t ulSustainableSOCPowerLimitHigh;
  392. uint32_t ulMinSclkLow;
  393. uint32_t ulMinSclkHigh;
  394. uint8_t ucDispConfig;
  395. uint32_t ulDClk;
  396. uint32_t ulEClk;
  397. uint32_t ulSustainableSclk;
  398. uint32_t ulSustainableCUs;
  399. };
  400. struct phm_vq_budgeting_table {
  401. uint8_t numEntries;
  402. struct phm_vq_budgeting_record entries[1];
  403. };
  404. struct phm_clock_and_voltage_limits {
  405. uint32_t sclk;
  406. uint32_t mclk;
  407. uint16_t vddc;
  408. uint16_t vddci;
  409. uint16_t vddgfx;
  410. };
  411. /* Structure to hold PPTable information */
  412. struct phm_ppt_v1_information {
  413. struct phm_ppt_v1_clock_voltage_dependency_table *vdd_dep_on_sclk;
  414. struct phm_ppt_v1_clock_voltage_dependency_table *vdd_dep_on_mclk;
  415. struct phm_clock_array *valid_sclk_values;
  416. struct phm_clock_array *valid_mclk_values;
  417. struct phm_clock_and_voltage_limits max_clock_voltage_on_dc;
  418. struct phm_clock_and_voltage_limits max_clock_voltage_on_ac;
  419. struct phm_clock_voltage_dependency_table *vddc_dep_on_dal_pwrl;
  420. struct phm_ppm_table *ppm_parameter_table;
  421. struct phm_cac_tdp_table *cac_dtp_table;
  422. struct phm_ppt_v1_mm_clock_voltage_dependency_table *mm_dep_table;
  423. struct phm_ppt_v1_voltage_lookup_table *vddc_lookup_table;
  424. struct phm_ppt_v1_voltage_lookup_table *vddgfx_lookup_table;
  425. struct phm_ppt_v1_pcie_table *pcie_table;
  426. uint16_t us_ulv_voltage_offset;
  427. };
  428. struct phm_dynamic_state_info {
  429. struct phm_clock_voltage_dependency_table *vddc_dependency_on_sclk;
  430. struct phm_clock_voltage_dependency_table *vddci_dependency_on_mclk;
  431. struct phm_clock_voltage_dependency_table *vddc_dependency_on_mclk;
  432. struct phm_clock_voltage_dependency_table *mvdd_dependency_on_mclk;
  433. struct phm_clock_voltage_dependency_table *vddc_dep_on_dal_pwrl;
  434. struct phm_clock_array *valid_sclk_values;
  435. struct phm_clock_array *valid_mclk_values;
  436. struct phm_clock_and_voltage_limits max_clock_voltage_on_dc;
  437. struct phm_clock_and_voltage_limits max_clock_voltage_on_ac;
  438. uint32_t mclk_sclk_ratio;
  439. uint32_t sclk_mclk_delta;
  440. uint32_t vddc_vddci_delta;
  441. uint32_t min_vddc_for_pcie_gen2;
  442. struct phm_cac_leakage_table *cac_leakage_table;
  443. struct phm_phase_shedding_limits_table *vddc_phase_shed_limits_table;
  444. struct phm_vce_clock_voltage_dependency_table
  445. *vce_clock_voltage_dependency_table;
  446. struct phm_uvd_clock_voltage_dependency_table
  447. *uvd_clock_voltage_dependency_table;
  448. struct phm_acp_clock_voltage_dependency_table
  449. *acp_clock_voltage_dependency_table;
  450. struct phm_samu_clock_voltage_dependency_table
  451. *samu_clock_voltage_dependency_table;
  452. struct phm_ppm_table *ppm_parameter_table;
  453. struct phm_cac_tdp_table *cac_dtp_table;
  454. struct phm_clock_voltage_dependency_table *vdd_gfx_dependency_on_sclk;
  455. struct phm_vq_budgeting_table *vq_budgeting_table;
  456. };
  457. struct pp_fan_info {
  458. bool bNoFan;
  459. uint8_t ucTachometerPulsesPerRevolution;
  460. uint32_t ulMinRPM;
  461. uint32_t ulMaxRPM;
  462. };
  463. struct pp_advance_fan_control_parameters {
  464. uint16_t usTMin; /* The temperature, in 0.01 centigrades, below which we just run at a minimal PWM. */
  465. uint16_t usTMed; /* The middle temperature where we change slopes. */
  466. uint16_t usTHigh; /* The high temperature for setting the second slope. */
  467. uint16_t usPWMMin; /* The minimum PWM value in percent (0.01% increments). */
  468. uint16_t usPWMMed; /* The PWM value (in percent) at TMed. */
  469. uint16_t usPWMHigh; /* The PWM value at THigh. */
  470. uint8_t ucTHyst; /* Temperature hysteresis. Integer. */
  471. uint32_t ulCycleDelay; /* The time between two invocations of the fan control routine in microseconds. */
  472. uint16_t usTMax; /* The max temperature */
  473. uint8_t ucFanControlMode;
  474. uint16_t usFanPWMMinLimit;
  475. uint16_t usFanPWMMaxLimit;
  476. uint16_t usFanPWMStep;
  477. uint16_t usDefaultMaxFanPWM;
  478. uint16_t usFanOutputSensitivity;
  479. uint16_t usDefaultFanOutputSensitivity;
  480. uint16_t usMaxFanPWM; /* The max Fan PWM value for Fuzzy Fan Control feature */
  481. uint16_t usFanRPMMinLimit; /* Minimum limit range in percentage, need to calculate based on minRPM/MaxRpm */
  482. uint16_t usFanRPMMaxLimit; /* Maximum limit range in percentage, usually set to 100% by default */
  483. uint16_t usFanRPMStep; /* Step increments/decerements, in percent */
  484. uint16_t usDefaultMaxFanRPM; /* The max Fan RPM value for Fuzzy Fan Control feature, default from PPTable */
  485. uint16_t usMaxFanRPM; /* The max Fan RPM value for Fuzzy Fan Control feature, user defined */
  486. uint16_t usFanCurrentLow; /* Low current */
  487. uint16_t usFanCurrentHigh; /* High current */
  488. uint16_t usFanRPMLow; /* Low RPM */
  489. uint16_t usFanRPMHigh; /* High RPM */
  490. uint32_t ulMinFanSCLKAcousticLimit; /* Minimum Fan Controller SCLK Frequency Acoustic Limit. */
  491. uint8_t ucTargetTemperature; /* Advanced fan controller target temperature. */
  492. uint8_t ucMinimumPWMLimit; /* The minimum PWM that the advanced fan controller can set. This should be set to the highest PWM that will run the fan at its lowest RPM. */
  493. uint16_t usFanGainEdge; /* The following is added for Fiji */
  494. uint16_t usFanGainHotspot;
  495. uint16_t usFanGainLiquid;
  496. uint16_t usFanGainVrVddc;
  497. uint16_t usFanGainVrMvdd;
  498. uint16_t usFanGainPlx;
  499. uint16_t usFanGainHbm;
  500. };
  501. struct pp_thermal_controller_info {
  502. uint8_t ucType;
  503. uint8_t ucI2cLine;
  504. uint8_t ucI2cAddress;
  505. struct pp_fan_info fanInfo;
  506. struct pp_advance_fan_control_parameters advanceFanControlParameters;
  507. };
  508. struct phm_microcode_version_info {
  509. uint32_t SMC;
  510. uint32_t DMCU;
  511. uint32_t MC;
  512. uint32_t NB;
  513. };
  514. enum PP_TABLE_VERSION {
  515. PP_TABLE_V0 = 0,
  516. PP_TABLE_V1,
  517. PP_TABLE_V2,
  518. PP_TABLE_MAX
  519. };
  520. /**
  521. * The main hardware manager structure.
  522. */
  523. struct pp_hwmgr {
  524. uint32_t chip_family;
  525. uint32_t chip_id;
  526. uint32_t pp_table_version;
  527. void *device;
  528. struct pp_smumgr *smumgr;
  529. const void *soft_pp_table;
  530. uint32_t soft_pp_table_size;
  531. void *hardcode_pp_table;
  532. bool need_pp_table_upload;
  533. struct amd_vce_state vce_states[AMD_MAX_VCE_LEVELS];
  534. uint32_t num_vce_state_tables;
  535. enum amd_dpm_forced_level dpm_level;
  536. enum amd_dpm_forced_level saved_dpm_level;
  537. bool block_hw_access;
  538. struct phm_gfx_arbiter gfx_arbiter;
  539. struct phm_acp_arbiter acp_arbiter;
  540. struct phm_uvd_arbiter uvd_arbiter;
  541. struct phm_vce_arbiter vce_arbiter;
  542. uint32_t usec_timeout;
  543. void *pptable;
  544. struct phm_platform_descriptor platform_descriptor;
  545. void *backend;
  546. enum PP_DAL_POWERLEVEL dal_power_level;
  547. struct phm_dynamic_state_info dyn_state;
  548. struct phm_runtime_table_header setup_asic;
  549. struct phm_runtime_table_header power_down_asic;
  550. struct phm_runtime_table_header disable_dynamic_state_management;
  551. struct phm_runtime_table_header enable_dynamic_state_management;
  552. struct phm_runtime_table_header set_power_state;
  553. struct phm_runtime_table_header enable_clock_power_gatings;
  554. struct phm_runtime_table_header display_configuration_changed;
  555. struct phm_runtime_table_header start_thermal_controller;
  556. struct phm_runtime_table_header set_temperature_range;
  557. const struct pp_hwmgr_func *hwmgr_func;
  558. const struct pp_table_func *pptable_func;
  559. struct pp_power_state *ps;
  560. enum pp_power_source power_source;
  561. uint32_t num_ps;
  562. struct pp_thermal_controller_info thermal_controller;
  563. bool fan_ctrl_is_in_default_mode;
  564. uint32_t fan_ctrl_default_mode;
  565. uint32_t tmin;
  566. struct phm_microcode_version_info microcode_version_info;
  567. uint32_t ps_size;
  568. struct pp_power_state *current_ps;
  569. struct pp_power_state *request_ps;
  570. struct pp_power_state *boot_ps;
  571. struct pp_power_state *uvd_ps;
  572. struct amd_pp_display_configuration display_config;
  573. uint32_t feature_mask;
  574. };
  575. extern int hwmgr_early_init(struct pp_instance *handle);
  576. extern int hwmgr_hw_init(struct pp_instance *handle);
  577. extern int hwmgr_hw_fini(struct pp_instance *handle);
  578. extern int phm_wait_on_register(struct pp_hwmgr *hwmgr, uint32_t index,
  579. uint32_t value, uint32_t mask);
  580. extern void phm_wait_on_indirect_register(struct pp_hwmgr *hwmgr,
  581. uint32_t indirect_port,
  582. uint32_t index,
  583. uint32_t value,
  584. uint32_t mask);
  585. extern bool phm_cf_want_uvd_power_gating(struct pp_hwmgr *hwmgr);
  586. extern bool phm_cf_want_vce_power_gating(struct pp_hwmgr *hwmgr);
  587. extern bool phm_cf_want_microcode_fan_ctrl(struct pp_hwmgr *hwmgr);
  588. extern int phm_trim_voltage_table(struct pp_atomctrl_voltage_table *vol_table);
  589. extern int phm_get_svi2_mvdd_voltage_table(struct pp_atomctrl_voltage_table *vol_table, phm_ppt_v1_clock_voltage_dependency_table *dep_table);
  590. extern int phm_get_svi2_vddci_voltage_table(struct pp_atomctrl_voltage_table *vol_table, phm_ppt_v1_clock_voltage_dependency_table *dep_table);
  591. extern int phm_get_svi2_vdd_voltage_table(struct pp_atomctrl_voltage_table *vol_table, phm_ppt_v1_voltage_lookup_table *lookup_table);
  592. extern void phm_trim_voltage_table_to_fit_state_table(uint32_t max_vol_steps, struct pp_atomctrl_voltage_table *vol_table);
  593. extern int phm_reset_single_dpm_table(void *table, uint32_t count, int max);
  594. extern void phm_setup_pcie_table_entry(void *table, uint32_t index, uint32_t pcie_gen, uint32_t pcie_lanes);
  595. extern int32_t phm_get_dpm_level_enable_mask_value(void *table);
  596. extern uint8_t phm_get_voltage_id(struct pp_atomctrl_voltage_table *voltage_table,
  597. uint32_t voltage);
  598. extern uint8_t phm_get_voltage_index(struct phm_ppt_v1_voltage_lookup_table *lookup_table, uint16_t voltage);
  599. extern uint16_t phm_find_closest_vddci(struct pp_atomctrl_voltage_table *vddci_table, uint16_t vddci);
  600. extern int phm_find_boot_level(void *table, uint32_t value, uint32_t *boot_level);
  601. extern int phm_get_sclk_for_voltage_evv(struct pp_hwmgr *hwmgr, phm_ppt_v1_voltage_lookup_table *lookup_table,
  602. uint16_t virtual_voltage_id, int32_t *sclk);
  603. extern int phm_initializa_dynamic_state_adjustment_rule_settings(struct pp_hwmgr *hwmgr);
  604. extern uint32_t phm_get_lowest_enabled_level(struct pp_hwmgr *hwmgr, uint32_t mask);
  605. extern void phm_apply_dal_min_voltage_request(struct pp_hwmgr *hwmgr);
  606. extern int smu7_init_function_pointers(struct pp_hwmgr *hwmgr);
  607. extern int phm_get_voltage_evv_on_sclk(struct pp_hwmgr *hwmgr, uint8_t voltage_type,
  608. uint32_t sclk, uint16_t id, uint16_t *voltage);
  609. #define PHM_ENTIRE_REGISTER_MASK 0xFFFFFFFFU
  610. #define PHM_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT
  611. #define PHM_FIELD_MASK(reg, field) reg##__##field##_MASK
  612. #define PHM_SET_FIELD(origval, reg, field, fieldval) \
  613. (((origval) & ~PHM_FIELD_MASK(reg, field)) | \
  614. (PHM_FIELD_MASK(reg, field) & ((fieldval) << PHM_FIELD_SHIFT(reg, field))))
  615. #define PHM_GET_FIELD(value, reg, field) \
  616. (((value) & PHM_FIELD_MASK(reg, field)) >> \
  617. PHM_FIELD_SHIFT(reg, field))
  618. /* Operations on named fields. */
  619. #define PHM_READ_FIELD(device, reg, field) \
  620. PHM_GET_FIELD(cgs_read_register(device, mm##reg), reg, field)
  621. #define PHM_READ_INDIRECT_FIELD(device, port, reg, field) \
  622. PHM_GET_FIELD(cgs_read_ind_register(device, port, ix##reg), \
  623. reg, field)
  624. #define PHM_READ_VFPF_INDIRECT_FIELD(device, port, reg, field) \
  625. PHM_GET_FIELD(cgs_read_ind_register(device, port, ix##reg), \
  626. reg, field)
  627. #define PHM_WRITE_FIELD(device, reg, field, fieldval) \
  628. cgs_write_register(device, mm##reg, PHM_SET_FIELD( \
  629. cgs_read_register(device, mm##reg), reg, field, fieldval))
  630. #define PHM_WRITE_INDIRECT_FIELD(device, port, reg, field, fieldval) \
  631. cgs_write_ind_register(device, port, ix##reg, \
  632. PHM_SET_FIELD(cgs_read_ind_register(device, port, ix##reg), \
  633. reg, field, fieldval))
  634. #define PHM_WRITE_VFPF_INDIRECT_FIELD(device, port, reg, field, fieldval) \
  635. cgs_write_ind_register(device, port, ix##reg, \
  636. PHM_SET_FIELD(cgs_read_ind_register(device, port, ix##reg), \
  637. reg, field, fieldval))
  638. #define PHM_WAIT_INDIRECT_REGISTER_GIVEN_INDEX(hwmgr, port, index, value, mask) \
  639. phm_wait_on_indirect_register(hwmgr, mm##port##_INDEX, index, value, mask)
  640. #define PHM_WAIT_INDIRECT_REGISTER(hwmgr, port, reg, value, mask) \
  641. PHM_WAIT_INDIRECT_REGISTER_GIVEN_INDEX(hwmgr, port, ix##reg, value, mask)
  642. #define PHM_WAIT_INDIRECT_FIELD(hwmgr, port, reg, field, fieldval) \
  643. PHM_WAIT_INDIRECT_REGISTER(hwmgr, port, reg, (fieldval) \
  644. << PHM_FIELD_SHIFT(reg, field), PHM_FIELD_MASK(reg, field))
  645. #endif /* _HWMGR_H_ */