2 * Copyright 2019 Advanced Micro Devices, Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
22 #ifndef __AMDGPU_SMU_H__
23 #define __AMDGPU_SMU_H__
26 #include "kgd_pp_interface.h"
27 #include "dm_pp_interface.h"
28 #include "dm_pp_smu.h"
29 #include "smu_types.h"
31 #define SMU_THERMAL_MINIMUM_ALERT_TEMP 0
32 #define SMU_THERMAL_MAXIMUM_ALERT_TEMP 255
33 #define SMU_TEMPERATURE_UNITS_PER_CENTIGRADES 1000
34 #define SMU_FW_NAME_LEN 0x24
36 struct smu_hw_power_state {
40 struct smu_power_state;
42 enum smu_state_ui_label {
43 SMU_STATE_UI_LABEL_NONE,
44 SMU_STATE_UI_LABEL_BATTERY,
45 SMU_STATE_UI_TABEL_MIDDLE_LOW,
46 SMU_STATE_UI_LABEL_BALLANCED,
47 SMU_STATE_UI_LABEL_MIDDLE_HIGHT,
48 SMU_STATE_UI_LABEL_PERFORMANCE,
49 SMU_STATE_UI_LABEL_BACO,
52 enum smu_state_classification_flag {
53 SMU_STATE_CLASSIFICATION_FLAG_BOOT = 0x0001,
54 SMU_STATE_CLASSIFICATION_FLAG_THERMAL = 0x0002,
55 SMU_STATE_CLASSIFICATIN_FLAG_LIMITED_POWER_SOURCE = 0x0004,
56 SMU_STATE_CLASSIFICATION_FLAG_RESET = 0x0008,
57 SMU_STATE_CLASSIFICATION_FLAG_FORCED = 0x0010,
58 SMU_STATE_CLASSIFICATION_FLAG_USER_3D_PERFORMANCE = 0x0020,
59 SMU_STATE_CLASSIFICATION_FLAG_USER_2D_PERFORMANCE = 0x0040,
60 SMU_STATE_CLASSIFICATION_FLAG_3D_PERFORMANCE = 0x0080,
61 SMU_STATE_CLASSIFICATION_FLAG_AC_OVERDIRVER_TEMPLATE = 0x0100,
62 SMU_STATE_CLASSIFICATION_FLAG_UVD = 0x0200,
63 SMU_STATE_CLASSIFICATION_FLAG_3D_PERFORMANCE_LOW = 0x0400,
64 SMU_STATE_CLASSIFICATION_FLAG_ACPI = 0x0800,
65 SMU_STATE_CLASSIFICATION_FLAG_HD2 = 0x1000,
66 SMU_STATE_CLASSIFICATION_FLAG_UVD_HD = 0x2000,
67 SMU_STATE_CLASSIFICATION_FLAG_UVD_SD = 0x4000,
68 SMU_STATE_CLASSIFICATION_FLAG_USER_DC_PERFORMANCE = 0x8000,
69 SMU_STATE_CLASSIFICATION_FLAG_DC_OVERDIRVER_TEMPLATE = 0x10000,
70 SMU_STATE_CLASSIFICATION_FLAG_BACO = 0x20000,
71 SMU_STATE_CLASSIFICATIN_FLAG_LIMITED_POWER_SOURCE2 = 0x40000,
72 SMU_STATE_CLASSIFICATION_FLAG_ULV = 0x80000,
73 SMU_STATE_CLASSIFICATION_FLAG_UVD_MVC = 0x100000,
76 struct smu_state_classification_block {
77 enum smu_state_ui_label ui_label;
78 enum smu_state_classification_flag flags;
84 struct smu_state_pcie_block {
88 enum smu_refreshrate_source {
89 SMU_REFRESHRATE_SOURCE_EDID,
90 SMU_REFRESHRATE_SOURCE_EXPLICIT
93 struct smu_state_display_block {
94 bool disable_frame_modulation;
95 bool limit_refreshrate;
96 enum smu_refreshrate_source refreshrate_source;
97 int explicit_refreshrate;
98 int edid_refreshrate_index;
99 bool enable_vari_bright;
102 struct smu_state_memory_block {
108 struct smu_state_software_algorithm_block {
109 bool disable_load_balancing;
110 bool enable_sleep_for_timestamps;
113 struct smu_temperature_range {
116 int edge_emergency_max;
118 int hotspot_crit_max;
119 int hotspot_emergency_max;
122 int mem_emergency_max;
123 int software_shutdown_temp;
126 struct smu_state_validation_block {
127 bool single_display_only;
129 uint8_t supported_power_levels;
132 struct smu_uvd_clocks {
138 * Structure to hold a SMU Power State.
140 struct smu_power_state {
142 struct list_head ordered_list;
143 struct list_head all_states_list;
145 struct smu_state_classification_block classification;
146 struct smu_state_validation_block validation;
147 struct smu_state_pcie_block pcie;
148 struct smu_state_display_block display;
149 struct smu_state_memory_block memory;
150 struct smu_state_software_algorithm_block software;
151 struct smu_uvd_clocks uvd_clocks;
152 struct smu_hw_power_state hardware;
155 enum smu_power_src_type
159 SMU_POWER_SOURCE_COUNT,
162 enum smu_memory_pool_size
164 SMU_MEMORY_POOL_SIZE_ZERO = 0,
165 SMU_MEMORY_POOL_SIZE_256_MB = 0x10000000,
166 SMU_MEMORY_POOL_SIZE_512_MB = 0x20000000,
167 SMU_MEMORY_POOL_SIZE_1_GB = 0x40000000,
168 SMU_MEMORY_POOL_SIZE_2_GB = 0x80000000,
171 #define SMU_TABLE_INIT(tables, table_id, s, a, d) \
173 tables[table_id].size = s; \
174 tables[table_id].align = a; \
175 tables[table_id].domain = d; \
184 struct amdgpu_bo *bo;
187 enum smu_perf_level_designation {
189 PERF_LEVEL_POWER_CONTAINMENT,
192 struct smu_performance_level {
194 uint32_t memory_clock;
197 uint32_t non_local_mem_freq;
198 uint32_t non_local_mem_width;
201 struct smu_clock_info {
202 uint32_t min_mem_clk;
203 uint32_t max_mem_clk;
204 uint32_t min_eng_clk;
205 uint32_t max_eng_clk;
206 uint32_t min_bus_bandwidth;
207 uint32_t max_bus_bandwidth;
210 struct smu_bios_boot_up_values
225 uint32_t pp_table_id;
226 uint32_t format_revision;
227 uint32_t content_revision;
230 uint32_t firmware_caps;
235 SMU_TABLE_PPTABLE = 0,
236 SMU_TABLE_WATERMARKS,
237 SMU_TABLE_CUSTOM_DPM,
240 SMU_TABLE_AVFS_PSM_DEBUG,
241 SMU_TABLE_AVFS_FUSE_OVERRIDE,
242 SMU_TABLE_PMSTATUSLOG,
243 SMU_TABLE_SMU_METRICS,
244 SMU_TABLE_DRIVER_SMU_CONFIG,
245 SMU_TABLE_ACTIVITY_MONITOR_COEFF,
247 SMU_TABLE_I2C_COMMANDS,
252 struct smu_table_context
254 void *power_play_table;
255 uint32_t power_play_table_size;
256 void *hardcode_pptable;
257 unsigned long metrics_time;
260 void *watermarks_table;
262 void *max_sustainable_clocks;
263 struct smu_bios_boot_up_values boot_values;
264 void *driver_pptable;
265 struct smu_table tables[SMU_TABLE_COUNT];
267 * The driver table is just a staging buffer for
268 * uploading/downloading content from the SMU.
270 * And the table_id for SMU_MSG_TransferTableSmu2Dram/
271 * SMU_MSG_TransferTableDram2Smu instructs SMU
272 * which content driver is interested.
274 struct smu_table driver_table;
275 struct smu_table memory_pool;
276 struct smu_table dummy_read_1_table;
277 uint8_t thermal_controller_type;
279 void *overdrive_table;
280 void *boot_overdrive_table;
282 uint32_t gpu_metrics_table_size;
283 void *gpu_metrics_table;
286 struct smu_dpm_context {
287 uint32_t dpm_context_size;
289 void *golden_dpm_context;
290 bool enable_umd_pstate;
291 enum amd_dpm_forced_level dpm_level;
292 enum amd_dpm_forced_level saved_dpm_level;
293 enum amd_dpm_forced_level requested_dpm_level;
294 struct smu_power_state *dpm_request_power_state;
295 struct smu_power_state *dpm_current_power_state;
296 struct mclock_latency_table *mclk_latency_table;
299 struct smu_power_gate {
304 struct mutex vcn_gate_lock;
305 struct mutex jpeg_gate_lock;
308 struct smu_power_context {
310 uint32_t power_context_size;
311 struct smu_power_gate power_gate;
315 #define SMU_FEATURE_MAX (64)
318 uint32_t feature_num;
319 DECLARE_BITMAP(supported, SMU_FEATURE_MAX);
320 DECLARE_BITMAP(allowed, SMU_FEATURE_MAX);
321 DECLARE_BITMAP(enabled, SMU_FEATURE_MAX);
326 uint32_t engine_clock;
327 uint32_t memory_clock;
328 uint32_t bus_bandwidth;
329 uint32_t engine_clock_in_sr;
331 uint32_t dcef_clock_in_sr;
334 #define MAX_REGULAR_DPM_NUM 16
335 struct mclk_latency_entries {
339 struct mclock_latency_table {
341 struct mclk_latency_entries entries[MAX_REGULAR_DPM_NUM];
353 SMU_BACO_STATE_ENTER = 0,
357 struct smu_baco_context
361 bool platform_support;
364 struct pstates_clk_freq {
370 struct smu_umd_pstate_table {
371 struct pstates_clk_freq gfxclk_pstate;
372 struct pstates_clk_freq socclk_pstate;
373 struct pstates_clk_freq uclk_pstate;
374 struct pstates_clk_freq vclk_pstate;
375 struct pstates_clk_freq dclk_pstate;
378 struct cmn2asic_msg_mapping {
384 struct cmn2asic_mapping {
389 #define WORKLOAD_POLICY_MAX 7
392 struct amdgpu_device *adev;
393 struct amdgpu_irq_src irq_source;
395 const struct pptable_funcs *ppt_funcs;
396 const struct cmn2asic_msg_mapping *message_map;
397 const struct cmn2asic_mapping *clock_map;
398 const struct cmn2asic_mapping *feature_map;
399 const struct cmn2asic_mapping *table_map;
400 const struct cmn2asic_mapping *pwr_src_map;
401 const struct cmn2asic_mapping *workload_map;
403 struct mutex sensor_lock;
404 struct mutex metrics_lock;
405 struct mutex message_lock;
408 struct smu_table_context smu_table;
409 struct smu_dpm_context smu_dpm;
410 struct smu_power_context smu_power;
411 struct smu_feature smu_feature;
412 struct amd_pp_display_configuration *display_config;
413 struct smu_baco_context smu_baco;
414 struct smu_temperature_range thermal_range;
416 #if defined(CONFIG_DEBUG_FS)
417 struct dentry *debugfs_sclk;
420 struct smu_umd_pstate_table pstate_table;
421 uint32_t pstate_sclk;
422 uint32_t pstate_mclk;
425 uint32_t current_power_limit;
426 uint32_t max_power_limit;
429 uint32_t ppt_offset_bytes;
430 uint32_t ppt_size_bytes;
431 uint8_t *ppt_start_addr;
433 bool support_power_containment;
434 bool disable_watermark;
436 #define WATERMARKS_EXIST (1 << 0)
437 #define WATERMARKS_LOADED (1 << 1)
438 uint32_t watermarks_bitmap;
439 uint32_t hard_min_uclk_req_from_dal;
440 bool disable_uclk_switch;
442 uint32_t workload_mask;
443 uint32_t workload_prority[WORKLOAD_POLICY_MAX];
444 uint32_t workload_setting[WORKLOAD_POLICY_MAX];
445 uint32_t power_profile_mode;
446 uint32_t default_power_profile_mode;
450 uint32_t smc_driver_if_version;
451 uint32_t smc_fw_if_version;
452 uint32_t smc_fw_version;
454 bool uploading_custom_pp_table;
455 bool dc_controlled_by_gpio;
457 struct work_struct throttling_logging_work;
458 atomic64_t throttle_int_counter;
459 struct work_struct interrupt_work;
461 unsigned fan_max_rpm;
462 unsigned manual_fan_speed_rpm;
464 uint32_t gfx_default_hard_min_freq;
465 uint32_t gfx_default_soft_max_freq;
466 uint32_t gfx_actual_hard_min_freq;
467 uint32_t gfx_actual_soft_max_freq;
470 uint32_t cpu_default_soft_min_freq;
471 uint32_t cpu_default_soft_max_freq;
472 uint32_t cpu_actual_soft_min_freq;
473 uint32_t cpu_actual_soft_max_freq;
474 uint32_t cpu_core_id_select;
475 uint16_t cpu_core_num;
481 * struct pptable_funcs - Callbacks used to interact with the SMU.
483 struct pptable_funcs {
485 * @run_btc: Calibrate voltage/frequency curve to fit the system's
486 * power delivery and voltage margins. Required for adaptive
487 * voltage frequency scaling (AVFS).
489 int (*run_btc)(struct smu_context *smu);
492 * @get_allowed_feature_mask: Get allowed feature mask.
493 * &feature_mask: Array to store feature mask.
494 * &num: Elements in &feature_mask.
496 int (*get_allowed_feature_mask)(struct smu_context *smu, uint32_t *feature_mask, uint32_t num);
499 * @get_current_power_state: Get the current power state.
501 * Return: Current power state on success, negative errno on failure.
503 enum amd_pm_state_type (*get_current_power_state)(struct smu_context *smu);
506 * @set_default_dpm_table: Retrieve the default overdrive settings from
509 int (*set_default_dpm_table)(struct smu_context *smu);
511 int (*set_power_state)(struct smu_context *smu);
514 * @populate_umd_state_clk: Populate the UMD power state table with
517 int (*populate_umd_state_clk)(struct smu_context *smu);
520 * @print_clk_levels: Print DPM clock levels for a clock domain
521 * to buffer. Star current level.
523 * Used for sysfs interfaces.
525 int (*print_clk_levels)(struct smu_context *smu, enum smu_clk_type clk_type, char *buf);
528 * @force_clk_levels: Set a range of allowed DPM levels for a clock
530 * &clk_type: Clock domain.
531 * &mask: Range of allowed DPM levels.
533 int (*force_clk_levels)(struct smu_context *smu, enum smu_clk_type clk_type, uint32_t mask);
536 * @od_edit_dpm_table: Edit the custom overdrive DPM table.
537 * &type: Type of edit.
538 * &input: Edit parameters.
539 * &size: Size of &input.
541 int (*od_edit_dpm_table)(struct smu_context *smu,
542 enum PP_OD_DPM_TABLE_COMMAND type,
543 long *input, uint32_t size);
546 * @get_clock_by_type_with_latency: Get the speed and latency of a clock
549 int (*get_clock_by_type_with_latency)(struct smu_context *smu,
550 enum smu_clk_type clk_type,
552 pp_clock_levels_with_latency
555 * @get_clock_by_type_with_voltage: Get the speed and voltage of a clock
558 int (*get_clock_by_type_with_voltage)(struct smu_context *smu,
559 enum amd_pp_clock_type type,
561 pp_clock_levels_with_voltage
565 * @get_power_profile_mode: Print all power profile modes to
566 * buffer. Star current mode.
568 int (*get_power_profile_mode)(struct smu_context *smu, char *buf);
571 * @set_power_profile_mode: Set a power profile mode. Also used to
572 * create/set custom power profile modes.
573 * &input: Power profile mode parameters.
574 * &size: Size of &input.
576 int (*set_power_profile_mode)(struct smu_context *smu, long *input, uint32_t size);
579 * @dpm_set_vcn_enable: Enable/disable VCN engine dynamic power
582 int (*dpm_set_vcn_enable)(struct smu_context *smu, bool enable);
585 * @dpm_set_jpeg_enable: Enable/disable JPEG engine dynamic power
588 int (*dpm_set_jpeg_enable)(struct smu_context *smu, bool enable);
591 * @read_sensor: Read data from a sensor.
592 * &sensor: Sensor to read data from.
593 * &data: Sensor reading.
594 * &size: Size of &data.
596 int (*read_sensor)(struct smu_context *smu, enum amd_pp_sensors sensor,
597 void *data, uint32_t *size);
600 * @pre_display_config_changed: Prepare GPU for a display configuration
603 * Disable display tracking and pin memory clock speed to maximum. Used
604 * in display component synchronization.
606 int (*pre_display_config_changed)(struct smu_context *smu);
609 * @display_config_changed: Notify the SMU of the current display
612 * Allows SMU to properly track blanking periods for memory clock
613 * adjustment. Used in display component synchronization.
615 int (*display_config_changed)(struct smu_context *smu);
617 int (*apply_clocks_adjust_rules)(struct smu_context *smu);
620 * @notify_smc_display_config: Applies display requirements to the
621 * current power state.
623 * Optimize deep sleep DCEFclk and mclk for the current display
624 * configuration. Used in display component synchronization.
626 int (*notify_smc_display_config)(struct smu_context *smu);
629 * @is_dpm_running: Check if DPM is running.
631 * Return: True if DPM is running, false otherwise.
633 bool (*is_dpm_running)(struct smu_context *smu);
636 * @get_fan_speed_rpm: Get the current fan speed in RPM.
638 int (*get_fan_speed_rpm)(struct smu_context *smu, uint32_t *speed);
641 * @set_watermarks_table: Configure and upload the watermarks tables to
644 int (*set_watermarks_table)(struct smu_context *smu,
645 struct pp_smu_wm_range_sets *clock_ranges);
648 * @get_thermal_temperature_range: Get safe thermal limits in Celcius.
650 int (*get_thermal_temperature_range)(struct smu_context *smu, struct smu_temperature_range *range);
653 * @get_uclk_dpm_states: Get memory clock DPM levels in kHz.
654 * &clocks_in_khz: Array of DPM levels.
655 * &num_states: Elements in &clocks_in_khz.
657 int (*get_uclk_dpm_states)(struct smu_context *smu, uint32_t *clocks_in_khz, uint32_t *num_states);
660 * @set_default_od_settings: Set the overdrive tables to defaults.
662 int (*set_default_od_settings)(struct smu_context *smu);
665 * @set_performance_level: Set a performance level.
667 int (*set_performance_level)(struct smu_context *smu, enum amd_dpm_forced_level level);
670 * @display_disable_memory_clock_switch: Enable/disable dynamic memory
673 * Disabling this feature forces memory clock speed to maximum.
674 * Enabling sets the minimum memory clock capable of driving the
675 * current display configuration.
677 int (*display_disable_memory_clock_switch)(struct smu_context *smu, bool disable_memory_clock_switch);
680 * @dump_pptable: Print the power play table to the system log.
682 void (*dump_pptable)(struct smu_context *smu);
685 * @get_power_limit: Get the device's power limits.
687 int (*get_power_limit)(struct smu_context *smu);
690 * @set_df_cstate: Set data fabric cstate.
692 int (*set_df_cstate)(struct smu_context *smu, enum pp_df_cstate state);
695 * @allow_xgmi_power_down: Enable/disable external global memory
696 * interconnect power down.
698 int (*allow_xgmi_power_down)(struct smu_context *smu, bool en);
701 * @update_pcie_parameters: Update and upload the system's PCIe
702 * capabilites to the SMU.
703 * &pcie_gen_cap: Maximum allowed PCIe generation.
704 * &pcie_width_cap: Maximum allowed PCIe width.
706 int (*update_pcie_parameters)(struct smu_context *smu, uint32_t pcie_gen_cap, uint32_t pcie_width_cap);
709 * @i2c_init: Initialize i2c.
711 * The i2c bus is used internally by the SMU voltage regulators and
712 * other devices. The i2c's EEPROM also stores bad page tables on boards
715 int (*i2c_init)(struct smu_context *smu, struct i2c_adapter *control);
718 * @i2c_fini: Tear down i2c.
720 void (*i2c_fini)(struct smu_context *smu, struct i2c_adapter *control);
723 * @get_unique_id: Get the GPU's unique id. Used for asset tracking.
725 void (*get_unique_id)(struct smu_context *smu);
728 * @get_dpm_clock_table: Get a copy of the DPM clock table.
730 * Used by display component in bandwidth and watermark calculations.
732 int (*get_dpm_clock_table)(struct smu_context *smu, struct dpm_clocks *clock_table);
735 * @init_microcode: Request the SMU's firmware from the kernel.
737 int (*init_microcode)(struct smu_context *smu);
740 * @load_microcode: Load firmware onto the SMU.
742 int (*load_microcode)(struct smu_context *smu);
745 * @fini_microcode: Release the SMU's firmware.
747 void (*fini_microcode)(struct smu_context *smu);
750 * @init_smc_tables: Initialize the SMU tables.
752 int (*init_smc_tables)(struct smu_context *smu);
755 * @fini_smc_tables: Release the SMU tables.
757 int (*fini_smc_tables)(struct smu_context *smu);
760 * @init_power: Initialize the power gate table context.
762 int (*init_power)(struct smu_context *smu);
765 * @fini_power: Release the power gate table context.
767 int (*fini_power)(struct smu_context *smu);
770 * @check_fw_status: Check the SMU's firmware status.
772 * Return: Zero if check passes, negative errno on failure.
774 int (*check_fw_status)(struct smu_context *smu);
777 * @setup_pptable: Initialize the power play table and populate it with
780 int (*setup_pptable)(struct smu_context *smu);
783 * @get_vbios_bootup_values: Get default boot values from the VBIOS.
785 int (*get_vbios_bootup_values)(struct smu_context *smu);
788 * @check_fw_version: Print driver and SMU interface versions to the
791 * Interface mismatch is not a critical failure.
793 int (*check_fw_version)(struct smu_context *smu);
796 * @powergate_sdma: Power up/down system direct memory access.
798 int (*powergate_sdma)(struct smu_context *smu, bool gate);
801 * @set_gfx_cgpg: Enable/disable graphics engine course grain power
804 int (*set_gfx_cgpg)(struct smu_context *smu, bool enable);
807 * @write_pptable: Write the power play table to the SMU.
809 int (*write_pptable)(struct smu_context *smu);
812 * @set_driver_table_location: Send the location of the driver table to
815 int (*set_driver_table_location)(struct smu_context *smu);
818 * @set_tool_table_location: Send the location of the tool table to the
821 int (*set_tool_table_location)(struct smu_context *smu);
824 * @notify_memory_pool_location: Send the location of the memory pool to
827 int (*notify_memory_pool_location)(struct smu_context *smu);
830 * @system_features_control: Enable/disable all SMU features.
832 int (*system_features_control)(struct smu_context *smu, bool en);
835 * @send_smc_msg_with_param: Send a message with a parameter to the SMU.
836 * &msg: Type of message.
837 * ¶m: Message parameter.
838 * &read_arg: SMU response (optional).
840 int (*send_smc_msg_with_param)(struct smu_context *smu,
841 enum smu_message_type msg, uint32_t param, uint32_t *read_arg);
844 * @send_smc_msg: Send a message to the SMU.
845 * &msg: Type of message.
846 * &read_arg: SMU response (optional).
848 int (*send_smc_msg)(struct smu_context *smu,
849 enum smu_message_type msg,
853 * @init_display_count: Notify the SMU of the number of display
854 * components in current display configuration.
856 int (*init_display_count)(struct smu_context *smu, uint32_t count);
859 * @set_allowed_mask: Notify the SMU of the features currently allowed
862 int (*set_allowed_mask)(struct smu_context *smu);
865 * @get_enabled_mask: Get a mask of features that are currently enabled
867 * &feature_mask: Array representing enabled feature mask.
868 * &num: Elements in &feature_mask.
870 int (*get_enabled_mask)(struct smu_context *smu, uint32_t *feature_mask, uint32_t num);
873 * @feature_is_enabled: Test if a feature is enabled.
875 * Return: One if enabled, zero if disabled.
877 int (*feature_is_enabled)(struct smu_context *smu, enum smu_feature_mask mask);
880 * @disable_all_features_with_exception: Disable all features with
881 * exception to those in &mask.
883 int (*disable_all_features_with_exception)(struct smu_context *smu, enum smu_feature_mask mask);
886 * @notify_display_change: Enable fast memory clock switching.
888 * Allows for fine grained memory clock switching but has more stringent
889 * timing requirements.
891 int (*notify_display_change)(struct smu_context *smu);
894 * @set_power_limit: Set power limit in watts.
896 int (*set_power_limit)(struct smu_context *smu, uint32_t n);
899 * @init_max_sustainable_clocks: Populate max sustainable clock speed
900 * table with values from the SMU.
902 int (*init_max_sustainable_clocks)(struct smu_context *smu);
905 * @enable_thermal_alert: Enable thermal alert interrupts.
907 int (*enable_thermal_alert)(struct smu_context *smu);
910 * @disable_thermal_alert: Disable thermal alert interrupts.
912 int (*disable_thermal_alert)(struct smu_context *smu);
915 * @set_min_dcef_deep_sleep: Set a minimum display fabric deep sleep
916 * clock speed in MHz.
918 int (*set_min_dcef_deep_sleep)(struct smu_context *smu, uint32_t clk);
921 * @display_clock_voltage_request: Set a hard minimum frequency
922 * for a clock domain.
924 int (*display_clock_voltage_request)(struct smu_context *smu, struct
925 pp_display_clock_request
929 * @get_fan_control_mode: Get the current fan control mode.
931 uint32_t (*get_fan_control_mode)(struct smu_context *smu);
934 * @set_fan_control_mode: Set the fan control mode.
936 int (*set_fan_control_mode)(struct smu_context *smu, uint32_t mode);
939 * @set_fan_speed_rpm: Set a static fan speed in RPM.
941 int (*set_fan_speed_rpm)(struct smu_context *smu, uint32_t speed);
944 * @set_xgmi_pstate: Set inter-chip global memory interconnect pstate.
945 * &pstate: Pstate to set. D0 if Nonzero, D3 otherwise.
947 int (*set_xgmi_pstate)(struct smu_context *smu, uint32_t pstate);
950 * @gfx_off_control: Enable/disable graphics engine poweroff.
952 int (*gfx_off_control)(struct smu_context *smu, bool enable);
956 * @get_gfx_off_status: Get graphics engine poweroff status.
959 * 0 - GFXOFF(default).
960 * 1 - Transition out of GFX State.
962 * 3 - Transition into GFXOFF.
964 uint32_t (*get_gfx_off_status)(struct smu_context *smu);
967 * @register_irq_handler: Register interupt request handlers.
969 int (*register_irq_handler)(struct smu_context *smu);
972 * @set_azalia_d3_pme: Wake the audio decode engine from d3 sleep.
974 int (*set_azalia_d3_pme)(struct smu_context *smu);
977 * @get_max_sustainable_clocks_by_dc: Get a copy of the max sustainable
978 * clock speeds table.
980 * Provides a way for the display component (DC) to get the max
981 * sustainable clocks from the SMU.
983 int (*get_max_sustainable_clocks_by_dc)(struct smu_context *smu, struct pp_smu_nv_clock_table *max_clocks);
986 * @baco_is_support: Check if GPU supports BACO (Bus Active, Chip Off).
988 bool (*baco_is_support)(struct smu_context *smu);
991 * @baco_get_state: Get the current BACO state.
993 * Return: Current BACO state.
995 enum smu_baco_state (*baco_get_state)(struct smu_context *smu);
998 * @baco_set_state: Enter/exit BACO.
1000 int (*baco_set_state)(struct smu_context *smu, enum smu_baco_state state);
1003 * @baco_enter: Enter BACO.
1005 int (*baco_enter)(struct smu_context *smu);
1008 * @baco_exit: Exit Baco.
1010 int (*baco_exit)(struct smu_context *smu);
1013 * @mode1_reset_is_support: Check if GPU supports mode1 reset.
1015 bool (*mode1_reset_is_support)(struct smu_context *smu);
1018 * @mode1_reset: Perform mode1 reset.
1020 * Complete GPU reset.
1022 int (*mode1_reset)(struct smu_context *smu);
1025 * @mode2_reset: Perform mode2 reset.
1027 * Mode2 reset generally does not reset as many IPs as mode1 reset. The
1028 * IPs reset varies by asic.
1030 int (*mode2_reset)(struct smu_context *smu);
1033 * @get_dpm_ultimate_freq: Get the hard frequency range of a clock
1036 int (*get_dpm_ultimate_freq)(struct smu_context *smu, enum smu_clk_type clk_type, uint32_t *min, uint32_t *max);
1039 * @set_soft_freq_limited_range: Set the soft frequency range of a clock
1042 int (*set_soft_freq_limited_range)(struct smu_context *smu, enum smu_clk_type clk_type, uint32_t min, uint32_t max);
1045 * @set_power_source: Notify the SMU of the current power source.
1047 int (*set_power_source)(struct smu_context *smu, enum smu_power_src_type power_src);
1050 * @log_thermal_throttling_event: Print a thermal throttling warning to
1053 void (*log_thermal_throttling_event)(struct smu_context *smu);
1056 * @get_pp_feature_mask: Print a human readable table of enabled
1057 * features to buffer.
1059 size_t (*get_pp_feature_mask)(struct smu_context *smu, char *buf);
1062 * @set_pp_feature_mask: Request the SMU enable/disable features to
1063 * match those enabled in &new_mask.
1065 int (*set_pp_feature_mask)(struct smu_context *smu, uint64_t new_mask);
1068 * @get_gpu_metrics: Get a copy of the GPU metrics table from the SMU.
1070 * Return: Size of &table
1072 ssize_t (*get_gpu_metrics)(struct smu_context *smu, void **table);
1075 * @enable_mgpu_fan_boost: Enable multi-GPU fan boost.
1077 int (*enable_mgpu_fan_boost)(struct smu_context *smu);
1080 * @gfx_ulv_control: Enable/disable ultra low voltage.
1082 int (*gfx_ulv_control)(struct smu_context *smu, bool enablement);
1085 * @deep_sleep_control: Enable/disable deep sleep.
1087 int (*deep_sleep_control)(struct smu_context *smu, bool enablement);
1090 * @get_fan_parameters: Get fan parameters.
1092 * Get maximum fan speed from the power play table.
1094 int (*get_fan_parameters)(struct smu_context *smu);
1097 * @post_init: Helper function for asic specific workarounds.
1099 int (*post_init)(struct smu_context *smu);
1102 * @interrupt_work: Work task scheduled from SMU interrupt handler.
1104 void (*interrupt_work)(struct smu_context *smu);
1107 * @gpo_control: Enable/disable graphics power optimization if supported.
1109 int (*gpo_control)(struct smu_context *smu, bool enablement);
1112 * @gfx_state_change_set: Send the current graphics state to the SMU.
1114 int (*gfx_state_change_set)(struct smu_context *smu, uint32_t state);
1117 * @set_fine_grain_gfx_freq_parameters: Set fine grain graphics clock
1118 * parameters to defaults.
1120 int (*set_fine_grain_gfx_freq_parameters)(struct smu_context *smu);
1124 METRICS_CURR_GFXCLK,
1125 METRICS_CURR_SOCCLK,
1132 METRICS_CURR_DCEFCLK,
1133 METRICS_AVERAGE_CPUCLK,
1134 METRICS_AVERAGE_GFXCLK,
1135 METRICS_AVERAGE_SOCCLK,
1136 METRICS_AVERAGE_FCLK,
1137 METRICS_AVERAGE_UCLK,
1138 METRICS_AVERAGE_VCLK,
1139 METRICS_AVERAGE_DCLK,
1140 METRICS_AVERAGE_GFXACTIVITY,
1141 METRICS_AVERAGE_MEMACTIVITY,
1142 METRICS_AVERAGE_VCNACTIVITY,
1143 METRICS_AVERAGE_SOCKETPOWER,
1144 METRICS_TEMPERATURE_EDGE,
1145 METRICS_TEMPERATURE_HOTSPOT,
1146 METRICS_TEMPERATURE_MEM,
1147 METRICS_TEMPERATURE_VRGFX,
1148 METRICS_TEMPERATURE_VRSOC,
1149 METRICS_TEMPERATURE_VRMEM,
1150 METRICS_THROTTLER_STATUS,
1151 METRICS_CURR_FANSPEED,
1152 METRICS_VOLTAGE_VDDSOC,
1153 METRICS_VOLTAGE_VDDGFX,
1156 enum smu_cmn2asic_mapping_type {
1157 CMN2ASIC_MAPPING_MSG,
1158 CMN2ASIC_MAPPING_CLK,
1159 CMN2ASIC_MAPPING_FEATURE,
1160 CMN2ASIC_MAPPING_TABLE,
1161 CMN2ASIC_MAPPING_PWR,
1162 CMN2ASIC_MAPPING_WORKLOAD,
1165 #define MSG_MAP(msg, index, valid_in_vf) \
1166 [SMU_MSG_##msg] = {1, (index), (valid_in_vf)}
1168 #define CLK_MAP(clk, index) \
1169 [SMU_##clk] = {1, (index)}
1171 #define FEA_MAP(fea) \
1172 [SMU_FEATURE_##fea##_BIT] = {1, FEATURE_##fea##_BIT}
1174 #define FEA_MAP_REVERSE(fea) \
1175 [SMU_FEATURE_DPM_##fea##_BIT] = {1, FEATURE_##fea##_DPM_BIT}
1177 #define FEA_MAP_HALF_REVERSE(fea) \
1178 [SMU_FEATURE_DPM_##fea##CLK_BIT] = {1, FEATURE_##fea##_DPM_BIT}
1180 #define TAB_MAP(tab) \
1181 [SMU_TABLE_##tab] = {1, TABLE_##tab}
1183 #define TAB_MAP_VALID(tab) \
1184 [SMU_TABLE_##tab] = {1, TABLE_##tab}
1186 #define TAB_MAP_INVALID(tab) \
1187 [SMU_TABLE_##tab] = {0, TABLE_##tab}
1189 #define PWR_MAP(tab) \
1190 [SMU_POWER_SOURCE_##tab] = {1, POWER_SOURCE_##tab}
1192 #define WORKLOAD_MAP(profile, workload) \
1193 [profile] = {1, (workload)}
1195 #if !defined(SWSMU_CODE_LAYER_L2) && !defined(SWSMU_CODE_LAYER_L3) && !defined(SWSMU_CODE_LAYER_L4)
1196 int smu_load_microcode(struct smu_context *smu);
1198 int smu_check_fw_status(struct smu_context *smu);
1200 int smu_set_gfx_cgpg(struct smu_context *smu, bool enabled);
1202 int smu_set_fan_speed_rpm(struct smu_context *smu, uint32_t speed);
1204 int smu_get_power_limit(struct smu_context *smu,
1208 int smu_set_power_limit(struct smu_context *smu, uint32_t limit);
1209 int smu_print_clk_levels(struct smu_context *smu, enum smu_clk_type clk_type, char *buf);
1211 int smu_od_edit_dpm_table(struct smu_context *smu,
1212 enum PP_OD_DPM_TABLE_COMMAND type,
1213 long *input, uint32_t size);
1215 int smu_read_sensor(struct smu_context *smu,
1216 enum amd_pp_sensors sensor,
1217 void *data, uint32_t *size);
1218 int smu_get_power_profile_mode(struct smu_context *smu, char *buf);
1220 int smu_set_power_profile_mode(struct smu_context *smu,
1222 uint32_t param_size,
1224 int smu_get_fan_control_mode(struct smu_context *smu);
1225 int smu_set_fan_control_mode(struct smu_context *smu, int value);
1226 int smu_get_fan_speed_percent(struct smu_context *smu, uint32_t *speed);
1227 int smu_set_fan_speed_percent(struct smu_context *smu, uint32_t speed);
1228 int smu_get_fan_speed_rpm(struct smu_context *smu, uint32_t *speed);
1230 int smu_set_deep_sleep_dcefclk(struct smu_context *smu, int clk);
1232 int smu_get_clock_by_type_with_latency(struct smu_context *smu,
1233 enum smu_clk_type clk_type,
1234 struct pp_clock_levels_with_latency *clocks);
1236 int smu_display_clock_voltage_request(struct smu_context *smu,
1237 struct pp_display_clock_request *clock_req);
1238 int smu_display_disable_memory_clock_switch(struct smu_context *smu, bool disable_memory_clock_switch);
1240 int smu_set_xgmi_pstate(struct smu_context *smu,
1243 int smu_set_azalia_d3_pme(struct smu_context *smu);
1245 bool smu_baco_is_support(struct smu_context *smu);
1247 int smu_baco_get_state(struct smu_context *smu, enum smu_baco_state *state);
1249 int smu_baco_enter(struct smu_context *smu);
1250 int smu_baco_exit(struct smu_context *smu);
1252 bool smu_mode1_reset_is_support(struct smu_context *smu);
1253 int smu_mode1_reset(struct smu_context *smu);
1254 int smu_mode2_reset(struct smu_context *smu);
1256 extern const struct amd_ip_funcs smu_ip_funcs;
1258 extern const struct amdgpu_ip_block_version smu_v11_0_ip_block;
1259 extern const struct amdgpu_ip_block_version smu_v12_0_ip_block;
1261 bool is_support_sw_smu(struct amdgpu_device *adev);
1262 bool is_support_cclk_dpm(struct amdgpu_device *adev);
1263 int smu_reset(struct smu_context *smu);
1264 int smu_sys_get_pp_table(struct smu_context *smu, void **table);
1265 int smu_sys_set_pp_table(struct smu_context *smu, void *buf, size_t size);
1266 int smu_get_power_num_states(struct smu_context *smu, struct pp_states_info *state_info);
1267 enum amd_pm_state_type smu_get_current_power_state(struct smu_context *smu);
1268 int smu_write_watermarks_table(struct smu_context *smu);
1269 int smu_set_watermarks_for_clock_ranges(
1270 struct smu_context *smu,
1271 struct pp_smu_wm_range_sets *clock_ranges);
1273 /* smu to display interface */
1274 extern int smu_display_configuration_change(struct smu_context *smu, const
1275 struct amd_pp_display_configuration
1277 extern int smu_dpm_set_power_gate(struct smu_context *smu,uint32_t block_type, bool gate);
1278 extern int smu_handle_task(struct smu_context *smu,
1279 enum amd_dpm_forced_level level,
1280 enum amd_pp_task task_id,
1282 int smu_switch_power_profile(struct smu_context *smu,
1283 enum PP_SMC_POWER_PROFILE type,
1285 int smu_get_dpm_freq_range(struct smu_context *smu, enum smu_clk_type clk_type,
1286 uint32_t *min, uint32_t *max);
1287 int smu_set_soft_freq_range(struct smu_context *smu, enum smu_clk_type clk_type,
1288 uint32_t min, uint32_t max);
1289 enum amd_dpm_forced_level smu_get_performance_level(struct smu_context *smu);
1290 int smu_force_performance_level(struct smu_context *smu, enum amd_dpm_forced_level level);
1291 int smu_set_display_count(struct smu_context *smu, uint32_t count);
1292 int smu_set_ac_dc(struct smu_context *smu);
1293 size_t smu_sys_get_pp_feature_mask(struct smu_context *smu, char *buf);
1294 int smu_sys_set_pp_feature_mask(struct smu_context *smu, uint64_t new_mask);
1295 int smu_force_clk_levels(struct smu_context *smu,
1296 enum smu_clk_type clk_type,
1298 int smu_set_mp1_state(struct smu_context *smu,
1299 enum pp_mp1_state mp1_state);
1300 int smu_set_df_cstate(struct smu_context *smu,
1301 enum pp_df_cstate state);
1302 int smu_allow_xgmi_power_down(struct smu_context *smu, bool en);
1304 int smu_get_max_sustainable_clocks_by_dc(struct smu_context *smu,
1305 struct pp_smu_nv_clock_table *max_clocks);
1307 int smu_get_uclk_dpm_states(struct smu_context *smu,
1308 unsigned int *clock_values_in_khz,
1309 unsigned int *num_states);
1311 int smu_get_dpm_clock_table(struct smu_context *smu,
1312 struct dpm_clocks *clock_table);
1314 int smu_get_status_gfxoff(struct amdgpu_device *adev, uint32_t *value);
1316 ssize_t smu_sys_get_gpu_metrics(struct smu_context *smu, void **table);
1318 int smu_enable_mgpu_fan_boost(struct smu_context *smu);
1319 int smu_gfx_state_change_set(struct smu_context *smu, uint32_t state);