2b9b9a7ba97a2d954612a4531f8b9ac13087b7a7
[linux-2.6-microblaze.git] / drivers / gpu / drm / amd / pm / inc / amdgpu_smu.h
1 /*
2  * Copyright 2019 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 #ifndef __AMDGPU_SMU_H__
23 #define __AMDGPU_SMU_H__
24
25 #include "amdgpu.h"
26 #include "kgd_pp_interface.h"
27 #include "dm_pp_interface.h"
28 #include "dm_pp_smu.h"
29 #include "smu_types.h"
30
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
35
36 #define SMU_DPM_USER_PROFILE_RESTORE (1 << 0)
37 #define SMU_CUSTOM_FAN_SPEED_RPM     (1 << 1)
38 #define SMU_CUSTOM_FAN_SPEED_PWM     (1 << 2)
39
40 // Power Throttlers
41 #define SMU_THROTTLER_PPT0_BIT                  0
42 #define SMU_THROTTLER_PPT1_BIT                  1
43 #define SMU_THROTTLER_PPT2_BIT                  2
44 #define SMU_THROTTLER_PPT3_BIT                  3
45 #define SMU_THROTTLER_SPL_BIT                   4
46 #define SMU_THROTTLER_FPPT_BIT                  5
47 #define SMU_THROTTLER_SPPT_BIT                  6
48 #define SMU_THROTTLER_SPPT_APU_BIT              7
49
50 // Current Throttlers
51 #define SMU_THROTTLER_TDC_GFX_BIT               16
52 #define SMU_THROTTLER_TDC_SOC_BIT               17
53 #define SMU_THROTTLER_TDC_MEM_BIT               18
54 #define SMU_THROTTLER_TDC_VDD_BIT               19
55 #define SMU_THROTTLER_TDC_CVIP_BIT              20
56 #define SMU_THROTTLER_EDC_CPU_BIT               21
57 #define SMU_THROTTLER_EDC_GFX_BIT               22
58 #define SMU_THROTTLER_APCC_BIT                  23
59
60 // Temperature
61 #define SMU_THROTTLER_TEMP_GPU_BIT              32
62 #define SMU_THROTTLER_TEMP_CORE_BIT             33
63 #define SMU_THROTTLER_TEMP_MEM_BIT              34
64 #define SMU_THROTTLER_TEMP_EDGE_BIT             35
65 #define SMU_THROTTLER_TEMP_HOTSPOT_BIT          36
66 #define SMU_THROTTLER_TEMP_SOC_BIT              37
67 #define SMU_THROTTLER_TEMP_VR_GFX_BIT           38
68 #define SMU_THROTTLER_TEMP_VR_SOC_BIT           39
69 #define SMU_THROTTLER_TEMP_VR_MEM0_BIT          40
70 #define SMU_THROTTLER_TEMP_VR_MEM1_BIT          41
71 #define SMU_THROTTLER_TEMP_LIQUID0_BIT          42
72 #define SMU_THROTTLER_TEMP_LIQUID1_BIT          43
73 #define SMU_THROTTLER_VRHOT0_BIT                44
74 #define SMU_THROTTLER_VRHOT1_BIT                45
75 #define SMU_THROTTLER_PROCHOT_CPU_BIT           46
76 #define SMU_THROTTLER_PROCHOT_GFX_BIT           47
77
78 // Other
79 #define SMU_THROTTLER_PPM_BIT                   56
80 #define SMU_THROTTLER_FIT_BIT                   57
81
82 struct smu_hw_power_state {
83         unsigned int magic;
84 };
85
86 struct smu_power_state;
87
88 enum smu_state_ui_label {
89         SMU_STATE_UI_LABEL_NONE,
90         SMU_STATE_UI_LABEL_BATTERY,
91         SMU_STATE_UI_TABEL_MIDDLE_LOW,
92         SMU_STATE_UI_LABEL_BALLANCED,
93         SMU_STATE_UI_LABEL_MIDDLE_HIGHT,
94         SMU_STATE_UI_LABEL_PERFORMANCE,
95         SMU_STATE_UI_LABEL_BACO,
96 };
97
98 enum smu_state_classification_flag {
99         SMU_STATE_CLASSIFICATION_FLAG_BOOT                     = 0x0001,
100         SMU_STATE_CLASSIFICATION_FLAG_THERMAL                  = 0x0002,
101         SMU_STATE_CLASSIFICATIN_FLAG_LIMITED_POWER_SOURCE      = 0x0004,
102         SMU_STATE_CLASSIFICATION_FLAG_RESET                    = 0x0008,
103         SMU_STATE_CLASSIFICATION_FLAG_FORCED                   = 0x0010,
104         SMU_STATE_CLASSIFICATION_FLAG_USER_3D_PERFORMANCE      = 0x0020,
105         SMU_STATE_CLASSIFICATION_FLAG_USER_2D_PERFORMANCE      = 0x0040,
106         SMU_STATE_CLASSIFICATION_FLAG_3D_PERFORMANCE           = 0x0080,
107         SMU_STATE_CLASSIFICATION_FLAG_AC_OVERDIRVER_TEMPLATE   = 0x0100,
108         SMU_STATE_CLASSIFICATION_FLAG_UVD                      = 0x0200,
109         SMU_STATE_CLASSIFICATION_FLAG_3D_PERFORMANCE_LOW       = 0x0400,
110         SMU_STATE_CLASSIFICATION_FLAG_ACPI                     = 0x0800,
111         SMU_STATE_CLASSIFICATION_FLAG_HD2                      = 0x1000,
112         SMU_STATE_CLASSIFICATION_FLAG_UVD_HD                   = 0x2000,
113         SMU_STATE_CLASSIFICATION_FLAG_UVD_SD                   = 0x4000,
114         SMU_STATE_CLASSIFICATION_FLAG_USER_DC_PERFORMANCE      = 0x8000,
115         SMU_STATE_CLASSIFICATION_FLAG_DC_OVERDIRVER_TEMPLATE   = 0x10000,
116         SMU_STATE_CLASSIFICATION_FLAG_BACO                     = 0x20000,
117         SMU_STATE_CLASSIFICATIN_FLAG_LIMITED_POWER_SOURCE2      = 0x40000,
118         SMU_STATE_CLASSIFICATION_FLAG_ULV                      = 0x80000,
119         SMU_STATE_CLASSIFICATION_FLAG_UVD_MVC                  = 0x100000,
120 };
121
122 struct smu_state_classification_block {
123         enum smu_state_ui_label         ui_label;
124         enum smu_state_classification_flag  flags;
125         int                          bios_index;
126         bool                      temporary_state;
127         bool                      to_be_deleted;
128 };
129
130 struct smu_state_pcie_block {
131         unsigned int lanes;
132 };
133
134 enum smu_refreshrate_source {
135         SMU_REFRESHRATE_SOURCE_EDID,
136         SMU_REFRESHRATE_SOURCE_EXPLICIT
137 };
138
139 struct smu_state_display_block {
140         bool              disable_frame_modulation;
141         bool              limit_refreshrate;
142         enum smu_refreshrate_source refreshrate_source;
143         int                  explicit_refreshrate;
144         int                  edid_refreshrate_index;
145         bool              enable_vari_bright;
146 };
147
148 struct smu_state_memory_block {
149         bool              dll_off;
150         uint8_t                 m3arb;
151         uint8_t                 unused[3];
152 };
153
154 struct smu_state_software_algorithm_block {
155         bool disable_load_balancing;
156         bool enable_sleep_for_timestamps;
157 };
158
159 struct smu_temperature_range {
160         int min;
161         int max;
162         int edge_emergency_max;
163         int hotspot_min;
164         int hotspot_crit_max;
165         int hotspot_emergency_max;
166         int mem_min;
167         int mem_crit_max;
168         int mem_emergency_max;
169         int software_shutdown_temp;
170 };
171
172 struct smu_state_validation_block {
173         bool single_display_only;
174         bool disallow_on_dc;
175         uint8_t supported_power_levels;
176 };
177
178 struct smu_uvd_clocks {
179         uint32_t vclk;
180         uint32_t dclk;
181 };
182
183 /**
184 * Structure to hold a SMU Power State.
185 */
186 struct smu_power_state {
187         uint32_t                                      id;
188         struct list_head                              ordered_list;
189         struct list_head                              all_states_list;
190
191         struct smu_state_classification_block         classification;
192         struct smu_state_validation_block             validation;
193         struct smu_state_pcie_block                   pcie;
194         struct smu_state_display_block                display;
195         struct smu_state_memory_block                 memory;
196         struct smu_state_software_algorithm_block     software;
197         struct smu_uvd_clocks                         uvd_clocks;
198         struct smu_hw_power_state                     hardware;
199 };
200
201 enum smu_power_src_type
202 {
203         SMU_POWER_SOURCE_AC,
204         SMU_POWER_SOURCE_DC,
205         SMU_POWER_SOURCE_COUNT,
206 };
207
208 enum smu_ppt_limit_type
209 {
210         SMU_DEFAULT_PPT_LIMIT = 0,
211         SMU_FAST_PPT_LIMIT,
212 };
213
214 enum smu_ppt_limit_level
215 {
216         SMU_PPT_LIMIT_MIN = -1,
217         SMU_PPT_LIMIT_CURRENT,
218         SMU_PPT_LIMIT_DEFAULT,
219         SMU_PPT_LIMIT_MAX,
220 };
221
222 enum smu_memory_pool_size
223 {
224     SMU_MEMORY_POOL_SIZE_ZERO   = 0,
225     SMU_MEMORY_POOL_SIZE_256_MB = 0x10000000,
226     SMU_MEMORY_POOL_SIZE_512_MB = 0x20000000,
227     SMU_MEMORY_POOL_SIZE_1_GB   = 0x40000000,
228     SMU_MEMORY_POOL_SIZE_2_GB   = 0x80000000,
229 };
230
231 struct smu_user_dpm_profile {
232         uint32_t fan_mode;
233         uint32_t power_limit;
234         uint32_t fan_speed_pwm;
235         uint32_t fan_speed_rpm;
236         uint32_t flags;
237         uint32_t user_od;
238
239         /* user clock state information */
240         uint32_t clk_mask[SMU_CLK_COUNT];
241         uint32_t clk_dependency;
242 };
243
244 enum smu_event_type {
245
246         SMU_EVENT_RESET_COMPLETE = 0,
247 };
248
249 #define SMU_TABLE_INIT(tables, table_id, s, a, d)       \
250         do {                                            \
251                 tables[table_id].size = s;              \
252                 tables[table_id].align = a;             \
253                 tables[table_id].domain = d;            \
254         } while (0)
255
256 struct smu_table {
257         uint64_t size;
258         uint32_t align;
259         uint8_t domain;
260         uint64_t mc_address;
261         void *cpu_addr;
262         struct amdgpu_bo *bo;
263 };
264
265 enum smu_perf_level_designation {
266         PERF_LEVEL_ACTIVITY,
267         PERF_LEVEL_POWER_CONTAINMENT,
268 };
269
270 struct smu_performance_level {
271         uint32_t core_clock;
272         uint32_t memory_clock;
273         uint32_t vddc;
274         uint32_t vddci;
275         uint32_t non_local_mem_freq;
276         uint32_t non_local_mem_width;
277 };
278
279 struct smu_clock_info {
280         uint32_t min_mem_clk;
281         uint32_t max_mem_clk;
282         uint32_t min_eng_clk;
283         uint32_t max_eng_clk;
284         uint32_t min_bus_bandwidth;
285         uint32_t max_bus_bandwidth;
286 };
287
288 struct smu_bios_boot_up_values
289 {
290         uint32_t                        revision;
291         uint32_t                        gfxclk;
292         uint32_t                        uclk;
293         uint32_t                        socclk;
294         uint32_t                        dcefclk;
295         uint32_t                        eclk;
296         uint32_t                        vclk;
297         uint32_t                        dclk;
298         uint16_t                        vddc;
299         uint16_t                        vddci;
300         uint16_t                        mvddc;
301         uint16_t                        vdd_gfx;
302         uint8_t                         cooling_id;
303         uint32_t                        pp_table_id;
304         uint32_t                        format_revision;
305         uint32_t                        content_revision;
306         uint32_t                        fclk;
307         uint32_t                        lclk;
308         uint32_t                        firmware_caps;
309 };
310
311 enum smu_table_id
312 {
313         SMU_TABLE_PPTABLE = 0,
314         SMU_TABLE_WATERMARKS,
315         SMU_TABLE_CUSTOM_DPM,
316         SMU_TABLE_DPMCLOCKS,
317         SMU_TABLE_AVFS,
318         SMU_TABLE_AVFS_PSM_DEBUG,
319         SMU_TABLE_AVFS_FUSE_OVERRIDE,
320         SMU_TABLE_PMSTATUSLOG,
321         SMU_TABLE_SMU_METRICS,
322         SMU_TABLE_DRIVER_SMU_CONFIG,
323         SMU_TABLE_ACTIVITY_MONITOR_COEFF,
324         SMU_TABLE_OVERDRIVE,
325         SMU_TABLE_I2C_COMMANDS,
326         SMU_TABLE_PACE,
327         SMU_TABLE_ECCINFO,
328         SMU_TABLE_COUNT,
329 };
330
331 struct smu_table_context
332 {
333         void                            *power_play_table;
334         uint32_t                        power_play_table_size;
335         void                            *hardcode_pptable;
336         unsigned long                   metrics_time;
337         void                            *metrics_table;
338         void                            *clocks_table;
339         void                            *watermarks_table;
340
341         void                            *max_sustainable_clocks;
342         struct smu_bios_boot_up_values  boot_values;
343         void                            *driver_pptable;
344         void                            *ecc_table;
345         struct smu_table                tables[SMU_TABLE_COUNT];
346         /*
347          * The driver table is just a staging buffer for
348          * uploading/downloading content from the SMU.
349          *
350          * And the table_id for SMU_MSG_TransferTableSmu2Dram/
351          * SMU_MSG_TransferTableDram2Smu instructs SMU
352          * which content driver is interested.
353          */
354         struct smu_table                driver_table;
355         struct smu_table                memory_pool;
356         struct smu_table                dummy_read_1_table;
357         uint8_t                         thermal_controller_type;
358
359         void                            *overdrive_table;
360         void                            *boot_overdrive_table;
361         void                            *user_overdrive_table;
362
363         uint32_t                        gpu_metrics_table_size;
364         void                            *gpu_metrics_table;
365 };
366
367 struct smu_dpm_context {
368         uint32_t dpm_context_size;
369         void *dpm_context;
370         void *golden_dpm_context;
371         bool enable_umd_pstate;
372         enum amd_dpm_forced_level dpm_level;
373         enum amd_dpm_forced_level saved_dpm_level;
374         enum amd_dpm_forced_level requested_dpm_level;
375         struct smu_power_state *dpm_request_power_state;
376         struct smu_power_state *dpm_current_power_state;
377         struct mclock_latency_table *mclk_latency_table;
378 };
379
380 struct smu_power_gate {
381         bool uvd_gated;
382         bool vce_gated;
383         atomic_t vcn_gated;
384         atomic_t jpeg_gated;
385         struct mutex vcn_gate_lock;
386         struct mutex jpeg_gate_lock;
387 };
388
389 struct smu_power_context {
390         void *power_context;
391         uint32_t power_context_size;
392         struct smu_power_gate power_gate;
393 };
394
395 #define SMU_FEATURE_MAX (64)
396 struct smu_feature
397 {
398         uint32_t feature_num;
399         DECLARE_BITMAP(supported, SMU_FEATURE_MAX);
400         DECLARE_BITMAP(allowed, SMU_FEATURE_MAX);
401         DECLARE_BITMAP(enabled, SMU_FEATURE_MAX);
402         struct mutex mutex;
403 };
404
405 struct smu_clocks {
406         uint32_t engine_clock;
407         uint32_t memory_clock;
408         uint32_t bus_bandwidth;
409         uint32_t engine_clock_in_sr;
410         uint32_t dcef_clock;
411         uint32_t dcef_clock_in_sr;
412 };
413
414 #define MAX_REGULAR_DPM_NUM 16
415 struct mclk_latency_entries {
416         uint32_t  frequency;
417         uint32_t  latency;
418 };
419 struct mclock_latency_table {
420         uint32_t  count;
421         struct mclk_latency_entries  entries[MAX_REGULAR_DPM_NUM];
422 };
423
424 enum smu_reset_mode
425 {
426     SMU_RESET_MODE_0,
427     SMU_RESET_MODE_1,
428     SMU_RESET_MODE_2,
429 };
430
431 enum smu_baco_state
432 {
433         SMU_BACO_STATE_ENTER = 0,
434         SMU_BACO_STATE_EXIT,
435 };
436
437 struct smu_baco_context
438 {
439         struct mutex mutex;
440         uint32_t state;
441         bool platform_support;
442 };
443
444 struct smu_freq_info {
445         uint32_t min;
446         uint32_t max;
447         uint32_t freq_level;
448 };
449
450 struct pstates_clk_freq {
451         uint32_t                        min;
452         uint32_t                        standard;
453         uint32_t                        peak;
454         struct smu_freq_info            custom;
455         struct smu_freq_info            curr;
456 };
457
458 struct smu_umd_pstate_table {
459         struct pstates_clk_freq         gfxclk_pstate;
460         struct pstates_clk_freq         socclk_pstate;
461         struct pstates_clk_freq         uclk_pstate;
462         struct pstates_clk_freq         vclk_pstate;
463         struct pstates_clk_freq         dclk_pstate;
464 };
465
466 struct cmn2asic_msg_mapping {
467         int     valid_mapping;
468         int     map_to;
469         int     valid_in_vf;
470 };
471
472 struct cmn2asic_mapping {
473         int     valid_mapping;
474         int     map_to;
475 };
476
477 struct stb_context {
478         uint32_t stb_buf_size;
479         bool enabled;
480         spinlock_t lock;
481 };
482
483 #define WORKLOAD_POLICY_MAX 7
484
485 struct smu_context
486 {
487         struct amdgpu_device            *adev;
488         struct amdgpu_irq_src           irq_source;
489
490         const struct pptable_funcs      *ppt_funcs;
491         const struct cmn2asic_msg_mapping       *message_map;
492         const struct cmn2asic_mapping   *clock_map;
493         const struct cmn2asic_mapping   *feature_map;
494         const struct cmn2asic_mapping   *table_map;
495         const struct cmn2asic_mapping   *pwr_src_map;
496         const struct cmn2asic_mapping   *workload_map;
497         struct mutex                    mutex;
498         struct mutex                    sensor_lock;
499         struct mutex                    metrics_lock;
500         struct mutex                    message_lock;
501         uint64_t pool_size;
502
503         struct smu_table_context        smu_table;
504         struct smu_dpm_context          smu_dpm;
505         struct smu_power_context        smu_power;
506         struct smu_feature              smu_feature;
507         struct amd_pp_display_configuration  *display_config;
508         struct smu_baco_context         smu_baco;
509         struct smu_temperature_range    thermal_range;
510         void *od_settings;
511
512         struct smu_umd_pstate_table     pstate_table;
513         uint32_t pstate_sclk;
514         uint32_t pstate_mclk;
515
516         bool od_enabled;
517         uint32_t current_power_limit;
518         uint32_t default_power_limit;
519         uint32_t max_power_limit;
520
521         /* soft pptable */
522         uint32_t ppt_offset_bytes;
523         uint32_t ppt_size_bytes;
524         uint8_t  *ppt_start_addr;
525
526         bool support_power_containment;
527         bool disable_watermark;
528
529 #define WATERMARKS_EXIST        (1 << 0)
530 #define WATERMARKS_LOADED       (1 << 1)
531         uint32_t watermarks_bitmap;
532         uint32_t hard_min_uclk_req_from_dal;
533         bool disable_uclk_switch;
534
535         uint32_t workload_mask;
536         uint32_t workload_prority[WORKLOAD_POLICY_MAX];
537         uint32_t workload_setting[WORKLOAD_POLICY_MAX];
538         uint32_t power_profile_mode;
539         uint32_t default_power_profile_mode;
540         bool pm_enabled;
541         bool is_apu;
542
543         uint32_t smc_driver_if_version;
544         uint32_t smc_fw_if_version;
545         uint32_t smc_fw_version;
546
547         bool uploading_custom_pp_table;
548         bool dc_controlled_by_gpio;
549
550         struct work_struct throttling_logging_work;
551         atomic64_t throttle_int_counter;
552         struct work_struct interrupt_work;
553
554         unsigned fan_max_rpm;
555         unsigned manual_fan_speed_pwm;
556
557         uint32_t gfx_default_hard_min_freq;
558         uint32_t gfx_default_soft_max_freq;
559         uint32_t gfx_actual_hard_min_freq;
560         uint32_t gfx_actual_soft_max_freq;
561
562         /* APU only */
563         uint32_t cpu_default_soft_min_freq;
564         uint32_t cpu_default_soft_max_freq;
565         uint32_t cpu_actual_soft_min_freq;
566         uint32_t cpu_actual_soft_max_freq;
567         uint32_t cpu_core_id_select;
568         uint16_t cpu_core_num;
569
570         struct smu_user_dpm_profile user_dpm_profile;
571
572         struct stb_context stb_context;
573 };
574
575 struct i2c_adapter;
576
577 /**
578  * struct pptable_funcs - Callbacks used to interact with the SMU.
579  */
580 struct pptable_funcs {
581         /**
582          * @run_btc: Calibrate voltage/frequency curve to fit the system's
583          *           power delivery and voltage margins. Required for adaptive
584          *           voltage frequency scaling (AVFS).
585          */
586         int (*run_btc)(struct smu_context *smu);
587
588         /**
589          * @get_allowed_feature_mask: Get allowed feature mask.
590          * &feature_mask: Array to store feature mask.
591          * &num: Elements in &feature_mask.
592          */
593         int (*get_allowed_feature_mask)(struct smu_context *smu, uint32_t *feature_mask, uint32_t num);
594
595         /**
596          * @get_current_power_state: Get the current power state.
597          *
598          * Return: Current power state on success, negative errno on failure.
599          */
600         enum amd_pm_state_type (*get_current_power_state)(struct smu_context *smu);
601
602         /**
603          * @set_default_dpm_table: Retrieve the default overdrive settings from
604          *                         the SMU.
605          */
606         int (*set_default_dpm_table)(struct smu_context *smu);
607
608         int (*set_power_state)(struct smu_context *smu);
609
610         /**
611          * @populate_umd_state_clk: Populate the UMD power state table with
612          *                          defaults.
613          */
614         int (*populate_umd_state_clk)(struct smu_context *smu);
615
616         /**
617          * @print_clk_levels: Print DPM clock levels for a clock domain
618          *                    to buffer. Star current level.
619          *
620          * Used for sysfs interfaces.
621          */
622         int (*print_clk_levels)(struct smu_context *smu, enum smu_clk_type clk_type, char *buf);
623
624         /**
625          * @force_clk_levels: Set a range of allowed DPM levels for a clock
626          *                    domain.
627          * &clk_type: Clock domain.
628          * &mask: Range of allowed DPM levels.
629          */
630         int (*force_clk_levels)(struct smu_context *smu, enum smu_clk_type clk_type, uint32_t mask);
631
632         /**
633          * @od_edit_dpm_table: Edit the custom overdrive DPM table.
634          * &type: Type of edit.
635          * &input: Edit parameters.
636          * &size: Size of &input.
637          */
638         int (*od_edit_dpm_table)(struct smu_context *smu,
639                                  enum PP_OD_DPM_TABLE_COMMAND type,
640                                  long *input, uint32_t size);
641
642         /**
643          * @restore_user_od_settings: Restore the user customized
644          *                            OD settings on S3/S4/Runpm resume.
645          */
646         int (*restore_user_od_settings)(struct smu_context *smu);
647
648         /**
649          * @get_clock_by_type_with_latency: Get the speed and latency of a clock
650          *                                  domain.
651          */
652         int (*get_clock_by_type_with_latency)(struct smu_context *smu,
653                                               enum smu_clk_type clk_type,
654                                               struct
655                                               pp_clock_levels_with_latency
656                                               *clocks);
657         /**
658          * @get_clock_by_type_with_voltage: Get the speed and voltage of a clock
659          *                                  domain.
660          */
661         int (*get_clock_by_type_with_voltage)(struct smu_context *smu,
662                                               enum amd_pp_clock_type type,
663                                               struct
664                                               pp_clock_levels_with_voltage
665                                               *clocks);
666
667         /**
668          * @get_power_profile_mode: Print all power profile modes to
669          *                          buffer. Star current mode.
670          */
671         int (*get_power_profile_mode)(struct smu_context *smu, char *buf);
672
673         /**
674          * @set_power_profile_mode: Set a power profile mode. Also used to
675          *                          create/set custom power profile modes.
676          * &input: Power profile mode parameters.
677          * &size: Size of &input.
678          */
679         int (*set_power_profile_mode)(struct smu_context *smu, long *input, uint32_t size);
680
681         /**
682          * @dpm_set_vcn_enable: Enable/disable VCN engine dynamic power
683          *                      management.
684          */
685         int (*dpm_set_vcn_enable)(struct smu_context *smu, bool enable);
686
687         /**
688          * @dpm_set_jpeg_enable: Enable/disable JPEG engine dynamic power
689          *                       management.
690          */
691         int (*dpm_set_jpeg_enable)(struct smu_context *smu, bool enable);
692
693         /**
694          * @read_sensor: Read data from a sensor.
695          * &sensor: Sensor to read data from.
696          * &data: Sensor reading.
697          * &size: Size of &data.
698          */
699         int (*read_sensor)(struct smu_context *smu, enum amd_pp_sensors sensor,
700                            void *data, uint32_t *size);
701
702         /**
703          * @pre_display_config_changed: Prepare GPU for a display configuration
704          *                              change.
705          *
706          * Disable display tracking and pin memory clock speed to maximum. Used
707          * in display component synchronization.
708          */
709         int (*pre_display_config_changed)(struct smu_context *smu);
710
711         /**
712          * @display_config_changed: Notify the SMU of the current display
713          *                          configuration.
714          *
715          * Allows SMU to properly track blanking periods for memory clock
716          * adjustment. Used in display component synchronization.
717          */
718         int (*display_config_changed)(struct smu_context *smu);
719
720         int (*apply_clocks_adjust_rules)(struct smu_context *smu);
721
722         /**
723          * @notify_smc_display_config: Applies display requirements to the
724          *                             current power state.
725          *
726          * Optimize deep sleep DCEFclk and mclk for the current display
727          * configuration. Used in display component synchronization.
728          */
729         int (*notify_smc_display_config)(struct smu_context *smu);
730
731         /**
732          * @is_dpm_running: Check if DPM is running.
733          *
734          * Return: True if DPM is running, false otherwise.
735          */
736         bool (*is_dpm_running)(struct smu_context *smu);
737
738         /**
739          * @get_fan_speed_pwm: Get the current fan speed in PWM.
740          */
741         int (*get_fan_speed_pwm)(struct smu_context *smu, uint32_t *speed);
742
743         /**
744          * @get_fan_speed_rpm: Get the current fan speed in rpm.
745          */
746         int (*get_fan_speed_rpm)(struct smu_context *smu, uint32_t *speed);
747
748         /**
749          * @set_watermarks_table: Configure and upload the watermarks tables to
750          *                        the SMU.
751          */
752         int (*set_watermarks_table)(struct smu_context *smu,
753                                     struct pp_smu_wm_range_sets *clock_ranges);
754
755         /**
756          * @get_thermal_temperature_range: Get safe thermal limits in Celcius.
757          */
758         int (*get_thermal_temperature_range)(struct smu_context *smu, struct smu_temperature_range *range);
759
760         /**
761          * @get_uclk_dpm_states: Get memory clock DPM levels in kHz.
762          * &clocks_in_khz: Array of DPM levels.
763          * &num_states: Elements in &clocks_in_khz.
764          */
765         int (*get_uclk_dpm_states)(struct smu_context *smu, uint32_t *clocks_in_khz, uint32_t *num_states);
766
767         /**
768          * @set_default_od_settings: Set the overdrive tables to defaults.
769          */
770         int (*set_default_od_settings)(struct smu_context *smu);
771
772         /**
773          * @set_performance_level: Set a performance level.
774          */
775         int (*set_performance_level)(struct smu_context *smu, enum amd_dpm_forced_level level);
776
777         /**
778          * @display_disable_memory_clock_switch: Enable/disable dynamic memory
779          *                                       clock switching.
780          *
781          * Disabling this feature forces memory clock speed to maximum.
782          * Enabling sets the minimum memory clock capable of driving the
783          * current display configuration.
784          */
785         int (*display_disable_memory_clock_switch)(struct smu_context *smu, bool disable_memory_clock_switch);
786
787         /**
788          * @dump_pptable: Print the power play table to the system log.
789          */
790         void (*dump_pptable)(struct smu_context *smu);
791
792         /**
793          * @get_power_limit: Get the device's power limits.
794          */
795         int (*get_power_limit)(struct smu_context *smu,
796                                uint32_t *current_power_limit,
797                                uint32_t *default_power_limit,
798                                uint32_t *max_power_limit);
799
800         /**
801          * @get_ppt_limit: Get the device's ppt limits.
802          */
803         int (*get_ppt_limit)(struct smu_context *smu, uint32_t *ppt_limit,
804                         enum smu_ppt_limit_type limit_type, enum smu_ppt_limit_level limit_level);
805
806         /**
807          * @set_df_cstate: Set data fabric cstate.
808          */
809         int (*set_df_cstate)(struct smu_context *smu, enum pp_df_cstate state);
810
811         /**
812          * @allow_xgmi_power_down: Enable/disable external global memory
813          *                         interconnect power down.
814          */
815         int (*allow_xgmi_power_down)(struct smu_context *smu, bool en);
816
817         /**
818          * @update_pcie_parameters: Update and upload the system's PCIe
819          *                          capabilites to the SMU.
820          * &pcie_gen_cap: Maximum allowed PCIe generation.
821          * &pcie_width_cap: Maximum allowed PCIe width.
822          */
823         int (*update_pcie_parameters)(struct smu_context *smu, uint32_t pcie_gen_cap, uint32_t pcie_width_cap);
824
825         /**
826          * @i2c_init: Initialize i2c.
827          *
828          * The i2c bus is used internally by the SMU voltage regulators and
829          * other devices. The i2c's EEPROM also stores bad page tables on boards
830          * with ECC.
831          */
832         int (*i2c_init)(struct smu_context *smu, struct i2c_adapter *control);
833
834         /**
835          * @i2c_fini: Tear down i2c.
836          */
837         void (*i2c_fini)(struct smu_context *smu, struct i2c_adapter *control);
838
839         /**
840          * @get_unique_id: Get the GPU's unique id. Used for asset tracking.
841          */
842         void (*get_unique_id)(struct smu_context *smu);
843
844         /**
845          * @get_dpm_clock_table: Get a copy of the DPM clock table.
846          *
847          * Used by display component in bandwidth and watermark calculations.
848          */
849         int (*get_dpm_clock_table)(struct smu_context *smu, struct dpm_clocks *clock_table);
850
851         /**
852          * @init_microcode: Request the SMU's firmware from the kernel.
853          */
854         int (*init_microcode)(struct smu_context *smu);
855
856         /**
857          * @load_microcode: Load firmware onto the SMU.
858          */
859         int (*load_microcode)(struct smu_context *smu);
860
861         /**
862          * @fini_microcode: Release the SMU's firmware.
863          */
864         void (*fini_microcode)(struct smu_context *smu);
865
866         /**
867          * @init_smc_tables: Initialize the SMU tables.
868          */
869         int (*init_smc_tables)(struct smu_context *smu);
870
871         /**
872          * @fini_smc_tables: Release the SMU tables.
873          */
874         int (*fini_smc_tables)(struct smu_context *smu);
875
876         /**
877          * @init_power: Initialize the power gate table context.
878          */
879         int (*init_power)(struct smu_context *smu);
880
881         /**
882          * @fini_power: Release the power gate table context.
883          */
884         int (*fini_power)(struct smu_context *smu);
885
886         /**
887          * @check_fw_status: Check the SMU's firmware status.
888          *
889          * Return: Zero if check passes, negative errno on failure.
890          */
891         int (*check_fw_status)(struct smu_context *smu);
892
893         /**
894          * @set_mp1_state: put SMU into a correct state for comming
895          *                 resume from runpm or gpu reset.
896          */
897         int (*set_mp1_state)(struct smu_context *smu,
898                              enum pp_mp1_state mp1_state);
899
900         /**
901          * @setup_pptable: Initialize the power play table and populate it with
902          *                 default values.
903          */
904         int (*setup_pptable)(struct smu_context *smu);
905
906         /**
907          * @get_vbios_bootup_values: Get default boot values from the VBIOS.
908          */
909         int (*get_vbios_bootup_values)(struct smu_context *smu);
910
911         /**
912          * @check_fw_version: Print driver and SMU interface versions to the
913          *                    system log.
914          *
915          * Interface mismatch is not a critical failure.
916          */
917         int (*check_fw_version)(struct smu_context *smu);
918
919         /**
920          * @powergate_sdma: Power up/down system direct memory access.
921          */
922         int (*powergate_sdma)(struct smu_context *smu, bool gate);
923
924         /**
925          * @set_gfx_cgpg: Enable/disable graphics engine course grain power
926          *                gating.
927          */
928         int (*set_gfx_cgpg)(struct smu_context *smu, bool enable);
929
930         /**
931          * @write_pptable: Write the power play table to the SMU.
932          */
933         int (*write_pptable)(struct smu_context *smu);
934
935         /**
936          * @set_driver_table_location: Send the location of the driver table to
937          *                             the SMU.
938          */
939         int (*set_driver_table_location)(struct smu_context *smu);
940
941         /**
942          * @set_tool_table_location: Send the location of the tool table to the
943          *                           SMU.
944          */
945         int (*set_tool_table_location)(struct smu_context *smu);
946
947         /**
948          * @notify_memory_pool_location: Send the location of the memory pool to
949          *                               the SMU.
950          */
951         int (*notify_memory_pool_location)(struct smu_context *smu);
952
953         /**
954          * @system_features_control: Enable/disable all SMU features.
955          */
956         int (*system_features_control)(struct smu_context *smu, bool en);
957
958         /**
959          * @send_smc_msg_with_param: Send a message with a parameter to the SMU.
960          * &msg: Type of message.
961          * &param: Message parameter.
962          * &read_arg: SMU response (optional).
963          */
964         int (*send_smc_msg_with_param)(struct smu_context *smu,
965                                        enum smu_message_type msg, uint32_t param, uint32_t *read_arg);
966
967         /**
968          * @send_smc_msg: Send a message to the SMU.
969          * &msg: Type of message.
970          * &read_arg: SMU response (optional).
971          */
972         int (*send_smc_msg)(struct smu_context *smu,
973                             enum smu_message_type msg,
974                             uint32_t *read_arg);
975
976         /**
977          * @init_display_count: Notify the SMU of the number of display
978          *                      components in current display configuration.
979          */
980         int (*init_display_count)(struct smu_context *smu, uint32_t count);
981
982         /**
983          * @set_allowed_mask: Notify the SMU of the features currently allowed
984          *                    by the driver.
985          */
986         int (*set_allowed_mask)(struct smu_context *smu);
987
988         /**
989          * @get_enabled_mask: Get a mask of features that are currently enabled
990          *                    on the SMU.
991          * &feature_mask: Array representing enabled feature mask.
992          * &num: Elements in &feature_mask.
993          */
994         int (*get_enabled_mask)(struct smu_context *smu, uint32_t *feature_mask, uint32_t num);
995
996         /**
997          * @feature_is_enabled: Test if a feature is enabled.
998          *
999          * Return: One if enabled, zero if disabled.
1000          */
1001         int (*feature_is_enabled)(struct smu_context *smu, enum smu_feature_mask mask);
1002
1003         /**
1004          * @disable_all_features_with_exception: Disable all features with
1005          *                                       exception to those in &mask.
1006          */
1007         int (*disable_all_features_with_exception)(struct smu_context *smu,
1008                                                    bool no_hw_disablement,
1009                                                    enum smu_feature_mask mask);
1010
1011         /**
1012          * @notify_display_change: Enable fast memory clock switching.
1013          *
1014          * Allows for fine grained memory clock switching but has more stringent
1015          * timing requirements.
1016          */
1017         int (*notify_display_change)(struct smu_context *smu);
1018
1019         /**
1020          * @set_power_limit: Set power limit in watts.
1021          */
1022         int (*set_power_limit)(struct smu_context *smu,
1023                                enum smu_ppt_limit_type limit_type,
1024                                uint32_t limit);
1025
1026         /**
1027          * @init_max_sustainable_clocks: Populate max sustainable clock speed
1028          *                               table with values from the SMU.
1029          */
1030         int (*init_max_sustainable_clocks)(struct smu_context *smu);
1031
1032         /**
1033          * @enable_thermal_alert: Enable thermal alert interrupts.
1034          */
1035         int (*enable_thermal_alert)(struct smu_context *smu);
1036
1037         /**
1038          * @disable_thermal_alert: Disable thermal alert interrupts.
1039          */
1040         int (*disable_thermal_alert)(struct smu_context *smu);
1041
1042         /**
1043          * @set_min_dcef_deep_sleep: Set a minimum display fabric deep sleep
1044          *                           clock speed in MHz.
1045          */
1046         int (*set_min_dcef_deep_sleep)(struct smu_context *smu, uint32_t clk);
1047
1048         /**
1049          * @display_clock_voltage_request: Set a hard minimum frequency
1050          * for a clock domain.
1051          */
1052         int (*display_clock_voltage_request)(struct smu_context *smu, struct
1053                                              pp_display_clock_request
1054                                              *clock_req);
1055
1056         /**
1057          * @get_fan_control_mode: Get the current fan control mode.
1058          */
1059         uint32_t (*get_fan_control_mode)(struct smu_context *smu);
1060
1061         /**
1062          * @set_fan_control_mode: Set the fan control mode.
1063          */
1064         int (*set_fan_control_mode)(struct smu_context *smu, uint32_t mode);
1065
1066         /**
1067          * @set_fan_speed_pwm: Set a static fan speed in PWM.
1068          */
1069         int (*set_fan_speed_pwm)(struct smu_context *smu, uint32_t speed);
1070
1071         /**
1072          * @set_fan_speed_rpm: Set a static fan speed in rpm.
1073          */
1074         int (*set_fan_speed_rpm)(struct smu_context *smu, uint32_t speed);
1075
1076         /**
1077          * @set_xgmi_pstate: Set inter-chip global memory interconnect pstate.
1078          * &pstate: Pstate to set. D0 if Nonzero, D3 otherwise.
1079          */
1080         int (*set_xgmi_pstate)(struct smu_context *smu, uint32_t pstate);
1081
1082         /**
1083          * @gfx_off_control: Enable/disable graphics engine poweroff.
1084          */
1085         int (*gfx_off_control)(struct smu_context *smu, bool enable);
1086
1087
1088         /**
1089          * @get_gfx_off_status: Get graphics engine poweroff status.
1090          *
1091          * Return:
1092          * 0 - GFXOFF(default).
1093          * 1 - Transition out of GFX State.
1094          * 2 - Not in GFXOFF.
1095          * 3 - Transition into GFXOFF.
1096          */
1097         uint32_t (*get_gfx_off_status)(struct smu_context *smu);
1098
1099         /**
1100          * @register_irq_handler: Register interupt request handlers.
1101          */
1102         int (*register_irq_handler)(struct smu_context *smu);
1103
1104         /**
1105          * @set_azalia_d3_pme: Wake the audio decode engine from d3 sleep.
1106          */
1107         int (*set_azalia_d3_pme)(struct smu_context *smu);
1108
1109         /**
1110          * @get_max_sustainable_clocks_by_dc: Get a copy of the max sustainable
1111          *                                    clock speeds table.
1112          *
1113          * Provides a way for the display component (DC) to get the max
1114          * sustainable clocks from the SMU.
1115          */
1116         int (*get_max_sustainable_clocks_by_dc)(struct smu_context *smu, struct pp_smu_nv_clock_table *max_clocks);
1117
1118         /**
1119          * @baco_is_support: Check if GPU supports BACO (Bus Active, Chip Off).
1120          */
1121         bool (*baco_is_support)(struct smu_context *smu);
1122
1123         /**
1124          * @baco_get_state: Get the current BACO state.
1125          *
1126          * Return: Current BACO state.
1127          */
1128         enum smu_baco_state (*baco_get_state)(struct smu_context *smu);
1129
1130         /**
1131          * @baco_set_state: Enter/exit BACO.
1132          */
1133         int (*baco_set_state)(struct smu_context *smu, enum smu_baco_state state);
1134
1135         /**
1136          * @baco_enter: Enter BACO.
1137          */
1138         int (*baco_enter)(struct smu_context *smu);
1139
1140         /**
1141          * @baco_exit: Exit Baco.
1142          */
1143         int (*baco_exit)(struct smu_context *smu);
1144
1145         /**
1146          * @mode1_reset_is_support: Check if GPU supports mode1 reset.
1147          */
1148         bool (*mode1_reset_is_support)(struct smu_context *smu);
1149         /**
1150          * @mode2_reset_is_support: Check if GPU supports mode2 reset.
1151          */
1152         bool (*mode2_reset_is_support)(struct smu_context *smu);
1153
1154         /**
1155          * @mode1_reset: Perform mode1 reset.
1156          *
1157          * Complete GPU reset.
1158          */
1159         int (*mode1_reset)(struct smu_context *smu);
1160
1161         /**
1162          * @mode2_reset: Perform mode2 reset.
1163          *
1164          * Mode2 reset generally does not reset as many IPs as mode1 reset. The
1165          * IPs reset varies by asic.
1166          */
1167         int (*mode2_reset)(struct smu_context *smu);
1168
1169         /**
1170          * @get_dpm_ultimate_freq: Get the hard frequency range of a clock
1171          *                         domain in MHz.
1172          */
1173         int (*get_dpm_ultimate_freq)(struct smu_context *smu, enum smu_clk_type clk_type, uint32_t *min, uint32_t *max);
1174
1175         /**
1176          * @set_soft_freq_limited_range: Set the soft frequency range of a clock
1177          *                               domain in MHz.
1178          */
1179         int (*set_soft_freq_limited_range)(struct smu_context *smu, enum smu_clk_type clk_type, uint32_t min, uint32_t max);
1180
1181         /**
1182          * @set_power_source: Notify the SMU of the current power source.
1183          */
1184         int (*set_power_source)(struct smu_context *smu, enum smu_power_src_type power_src);
1185
1186         /**
1187          * @log_thermal_throttling_event: Print a thermal throttling warning to
1188          *                                the system's log.
1189          */
1190         void (*log_thermal_throttling_event)(struct smu_context *smu);
1191
1192         /**
1193          * @get_pp_feature_mask: Print a human readable table of enabled
1194          *                       features to buffer.
1195          */
1196         size_t (*get_pp_feature_mask)(struct smu_context *smu, char *buf);
1197
1198         /**
1199          * @set_pp_feature_mask: Request the SMU enable/disable features to
1200          *                       match those enabled in &new_mask.
1201          */
1202         int (*set_pp_feature_mask)(struct smu_context *smu, uint64_t new_mask);
1203
1204         /**
1205          * @get_gpu_metrics: Get a copy of the GPU metrics table from the SMU.
1206          *
1207          * Return: Size of &table
1208          */
1209         ssize_t (*get_gpu_metrics)(struct smu_context *smu, void **table);
1210
1211         /**
1212          * @enable_mgpu_fan_boost: Enable multi-GPU fan boost.
1213          */
1214         int (*enable_mgpu_fan_boost)(struct smu_context *smu);
1215
1216         /**
1217          * @gfx_ulv_control: Enable/disable ultra low voltage.
1218          */
1219         int (*gfx_ulv_control)(struct smu_context *smu, bool enablement);
1220
1221         /**
1222          * @deep_sleep_control: Enable/disable deep sleep.
1223          */
1224         int (*deep_sleep_control)(struct smu_context *smu, bool enablement);
1225
1226         /**
1227          * @get_fan_parameters: Get fan parameters.
1228          *
1229          * Get maximum fan speed from the power play table.
1230          */
1231         int (*get_fan_parameters)(struct smu_context *smu);
1232
1233         /**
1234          * @post_init: Helper function for asic specific workarounds.
1235          */
1236         int (*post_init)(struct smu_context *smu);
1237
1238         /**
1239          * @interrupt_work: Work task scheduled from SMU interrupt handler.
1240          */
1241         void (*interrupt_work)(struct smu_context *smu);
1242
1243         /**
1244          * @gpo_control: Enable/disable graphics power optimization if supported.
1245          */
1246         int (*gpo_control)(struct smu_context *smu, bool enablement);
1247
1248         /**
1249          * @gfx_state_change_set: Send the current graphics state to the SMU.
1250          */
1251         int (*gfx_state_change_set)(struct smu_context *smu, uint32_t state);
1252
1253         /**
1254          * @set_fine_grain_gfx_freq_parameters: Set fine grain graphics clock
1255          *                                      parameters to defaults.
1256          */
1257         int (*set_fine_grain_gfx_freq_parameters)(struct smu_context *smu);
1258
1259         /**
1260          * @set_light_sbr:  Set light sbr mode for the SMU.
1261          */
1262         int (*set_light_sbr)(struct smu_context *smu, bool enable);
1263
1264         /**
1265          * @wait_for_event:  Wait for events from SMU.
1266          */
1267         int (*wait_for_event)(struct smu_context *smu,
1268                               enum smu_event_type event, uint64_t event_arg);
1269
1270         /**
1271          * @sned_hbm_bad_pages_num:  message SMU to update bad page number
1272          *                                                                              of SMUBUS table.
1273          */
1274         int (*send_hbm_bad_pages_num)(struct smu_context *smu, uint32_t size);
1275
1276         /**
1277          * @get_ecc_table:  message SMU to get ECC INFO table.
1278          */
1279         ssize_t (*get_ecc_info)(struct smu_context *smu, void *table);
1280         
1281         
1282         /**
1283          * @stb_collect_info: Collects Smart Trace Buffers data.
1284          */
1285         int (*stb_collect_info)(struct smu_context *smu, void *buf, uint32_t size);
1286 };
1287
1288 typedef enum {
1289         METRICS_CURR_GFXCLK,
1290         METRICS_CURR_SOCCLK,
1291         METRICS_CURR_UCLK,
1292         METRICS_CURR_VCLK,
1293         METRICS_CURR_VCLK1,
1294         METRICS_CURR_DCLK,
1295         METRICS_CURR_DCLK1,
1296         METRICS_CURR_FCLK,
1297         METRICS_CURR_DCEFCLK,
1298         METRICS_AVERAGE_CPUCLK,
1299         METRICS_AVERAGE_GFXCLK,
1300         METRICS_AVERAGE_SOCCLK,
1301         METRICS_AVERAGE_FCLK,
1302         METRICS_AVERAGE_UCLK,
1303         METRICS_AVERAGE_VCLK,
1304         METRICS_AVERAGE_DCLK,
1305         METRICS_AVERAGE_GFXACTIVITY,
1306         METRICS_AVERAGE_MEMACTIVITY,
1307         METRICS_AVERAGE_VCNACTIVITY,
1308         METRICS_AVERAGE_SOCKETPOWER,
1309         METRICS_TEMPERATURE_EDGE,
1310         METRICS_TEMPERATURE_HOTSPOT,
1311         METRICS_TEMPERATURE_MEM,
1312         METRICS_TEMPERATURE_VRGFX,
1313         METRICS_TEMPERATURE_VRSOC,
1314         METRICS_TEMPERATURE_VRMEM,
1315         METRICS_THROTTLER_STATUS,
1316         METRICS_CURR_FANSPEED,
1317         METRICS_VOLTAGE_VDDSOC,
1318         METRICS_VOLTAGE_VDDGFX,
1319         METRICS_SS_APU_SHARE,
1320         METRICS_SS_DGPU_SHARE,
1321 } MetricsMember_t;
1322
1323 enum smu_cmn2asic_mapping_type {
1324         CMN2ASIC_MAPPING_MSG,
1325         CMN2ASIC_MAPPING_CLK,
1326         CMN2ASIC_MAPPING_FEATURE,
1327         CMN2ASIC_MAPPING_TABLE,
1328         CMN2ASIC_MAPPING_PWR,
1329         CMN2ASIC_MAPPING_WORKLOAD,
1330 };
1331
1332 #define MSG_MAP(msg, index, valid_in_vf) \
1333         [SMU_MSG_##msg] = {1, (index), (valid_in_vf)}
1334
1335 #define CLK_MAP(clk, index) \
1336         [SMU_##clk] = {1, (index)}
1337
1338 #define FEA_MAP(fea) \
1339         [SMU_FEATURE_##fea##_BIT] = {1, FEATURE_##fea##_BIT}
1340
1341 #define FEA_MAP_REVERSE(fea) \
1342         [SMU_FEATURE_DPM_##fea##_BIT] = {1, FEATURE_##fea##_DPM_BIT}
1343
1344 #define FEA_MAP_HALF_REVERSE(fea) \
1345         [SMU_FEATURE_DPM_##fea##CLK_BIT] = {1, FEATURE_##fea##_DPM_BIT}
1346
1347 #define TAB_MAP(tab) \
1348         [SMU_TABLE_##tab] = {1, TABLE_##tab}
1349
1350 #define TAB_MAP_VALID(tab) \
1351         [SMU_TABLE_##tab] = {1, TABLE_##tab}
1352
1353 #define TAB_MAP_INVALID(tab) \
1354         [SMU_TABLE_##tab] = {0, TABLE_##tab}
1355
1356 #define PWR_MAP(tab) \
1357         [SMU_POWER_SOURCE_##tab] = {1, POWER_SOURCE_##tab}
1358
1359 #define WORKLOAD_MAP(profile, workload) \
1360         [profile] = {1, (workload)}
1361
1362 /**
1363  * smu_memcpy_trailing - Copy the end of one structure into the middle of another
1364  *
1365  * @dst: Pointer to destination struct
1366  * @first_dst_member: The member name in @dst where the overwrite begins
1367  * @last_dst_member: The member name in @dst where the overwrite ends after
1368  * @src: Pointer to the source struct
1369  * @first_src_member: The member name in @src where the copy begins
1370  *
1371  */
1372 #define smu_memcpy_trailing(dst, first_dst_member, last_dst_member,        \
1373                             src, first_src_member)                         \
1374 ({                                                                         \
1375         size_t __src_offset = offsetof(typeof(*(src)), first_src_member);  \
1376         size_t __src_size = sizeof(*(src)) - __src_offset;                 \
1377         size_t __dst_offset = offsetof(typeof(*(dst)), first_dst_member);  \
1378         size_t __dst_size = offsetofend(typeof(*(dst)), last_dst_member) - \
1379                             __dst_offset;                                  \
1380         BUILD_BUG_ON(__src_size != __dst_size);                            \
1381         __builtin_memcpy((u8 *)(dst) + __dst_offset,                       \
1382                          (u8 *)(src) + __src_offset,                       \
1383                          __dst_size);                                      \
1384 })
1385
1386 #if !defined(SWSMU_CODE_LAYER_L2) && !defined(SWSMU_CODE_LAYER_L3) && !defined(SWSMU_CODE_LAYER_L4)
1387 int smu_get_power_limit(void *handle,
1388                         uint32_t *limit,
1389                         enum pp_power_limit_level pp_limit_level,
1390                         enum pp_power_type pp_power_type);
1391
1392 bool smu_mode1_reset_is_support(struct smu_context *smu);
1393 bool smu_mode2_reset_is_support(struct smu_context *smu);
1394 int smu_mode1_reset(struct smu_context *smu);
1395
1396 extern const struct amd_ip_funcs smu_ip_funcs;
1397
1398 extern const struct amdgpu_ip_block_version smu_v11_0_ip_block;
1399 extern const struct amdgpu_ip_block_version smu_v12_0_ip_block;
1400 extern const struct amdgpu_ip_block_version smu_v13_0_ip_block;
1401
1402 bool is_support_sw_smu(struct amdgpu_device *adev);
1403 bool is_support_cclk_dpm(struct amdgpu_device *adev);
1404 int smu_write_watermarks_table(struct smu_context *smu);
1405
1406 int smu_get_dpm_freq_range(struct smu_context *smu, enum smu_clk_type clk_type,
1407                            uint32_t *min, uint32_t *max);
1408
1409 int smu_set_soft_freq_range(struct smu_context *smu, enum smu_clk_type clk_type,
1410                             uint32_t min, uint32_t max);
1411
1412 int smu_set_ac_dc(struct smu_context *smu);
1413
1414 int smu_allow_xgmi_power_down(struct smu_context *smu, bool en);
1415
1416 int smu_get_status_gfxoff(struct amdgpu_device *adev, uint32_t *value);
1417
1418 int smu_set_light_sbr(struct smu_context *smu, bool enable);
1419
1420 int smu_wait_for_event(struct amdgpu_device *adev, enum smu_event_type event,
1421                        uint64_t event_arg);
1422 int smu_get_ecc_info(struct smu_context *smu, void *umc_ecc);
1423 int smu_stb_collect_info(struct smu_context *smu, void *buff, uint32_t size);
1424 void amdgpu_smu_stb_debug_fs_init(struct amdgpu_device *adev);
1425
1426 #endif
1427 #endif