drm/amd/display: [FW Promotion] Release 0.0.68
[linux-2.6-microblaze.git] / drivers / gpu / drm / amd / display / dmub / inc / dmub_cmd.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  * Authors: AMD
23  *
24  */
25
26 #ifndef _DMUB_CMD_H_
27 #define _DMUB_CMD_H_
28
29 #if defined(_TEST_HARNESS) || defined(FPGA_USB4)
30 #include "dmub_fw_types.h"
31 #include "include_legacy/atomfirmware.h"
32
33 #if defined(_TEST_HARNESS)
34 #include <string.h>
35 #endif
36 #else
37
38 #include <asm/byteorder.h>
39 #include <linux/types.h>
40 #include <linux/string.h>
41 #include <linux/delay.h>
42 #include <stdarg.h>
43
44 #include "atomfirmware.h"
45
46 #endif // defined(_TEST_HARNESS) || defined(FPGA_USB4)
47
48 /* Firmware versioning. */
49 #ifdef DMUB_EXPOSE_VERSION
50 #define DMUB_FW_VERSION_GIT_HASH 0xeb3203315
51 #define DMUB_FW_VERSION_MAJOR 0
52 #define DMUB_FW_VERSION_MINOR 0
53 #define DMUB_FW_VERSION_REVISION 68
54 #define DMUB_FW_VERSION_TEST 0
55 #define DMUB_FW_VERSION_VBIOS 0
56 #define DMUB_FW_VERSION_HOTFIX 0
57 #define DMUB_FW_VERSION_UCODE (((DMUB_FW_VERSION_MAJOR & 0xFF) << 24) | \
58                 ((DMUB_FW_VERSION_MINOR & 0xFF) << 16) | \
59                 ((DMUB_FW_VERSION_REVISION & 0xFF) << 8) | \
60                 ((DMUB_FW_VERSION_TEST & 0x1) << 7) | \
61                 ((DMUB_FW_VERSION_VBIOS & 0x1) << 6) | \
62                 (DMUB_FW_VERSION_HOTFIX & 0x3F))
63
64 #endif
65
66 //<DMUB_TYPES>==================================================================
67 /* Basic type definitions. */
68
69 #define __forceinline inline
70
71 /**
72  * Flag from driver to indicate that ABM should be disabled gradually
73  * by slowly reversing all backlight programming and pixel compensation.
74  */
75 #define SET_ABM_PIPE_GRADUALLY_DISABLE           0
76
77 /**
78  * Flag from driver to indicate that ABM should be disabled immediately
79  * and undo all backlight programming and pixel compensation.
80  */
81 #define SET_ABM_PIPE_IMMEDIATELY_DISABLE         255
82
83 /**
84  * Flag from driver to indicate that ABM should be disabled immediately
85  * and keep the current backlight programming and pixel compensation.
86  */
87 #define SET_ABM_PIPE_IMMEDIATE_KEEP_GAIN_DISABLE 254
88
89 /**
90  * Flag from driver to set the current ABM pipe index or ABM operating level.
91  */
92 #define SET_ABM_PIPE_NORMAL                      1
93
94 /**
95  * Number of ambient light levels in ABM algorithm.
96  */
97 #define NUM_AMBI_LEVEL                  5
98
99 /**
100  * Number of operating/aggression levels in ABM algorithm.
101  */
102 #define NUM_AGGR_LEVEL                  4
103
104 /**
105  * Number of segments in the gamma curve.
106  */
107 #define NUM_POWER_FN_SEGS               8
108
109 /**
110  * Number of segments in the backlight curve.
111  */
112 #define NUM_BL_CURVE_SEGS               16
113
114 /* Maximum number of streams on any ASIC. */
115 #define DMUB_MAX_STREAMS 6
116
117 /* Maximum number of planes on any ASIC. */
118 #define DMUB_MAX_PLANES 6
119
120 /* Trace buffer offset for entry */
121 #define TRACE_BUFFER_ENTRY_OFFSET  16
122
123 /**
124  *
125  * PSR control version legacy
126  */
127 #define DMUB_CMD_PSR_CONTROL_VERSION_UNKNOWN 0x0
128 /**
129  * PSR control version with multi edp support
130  */
131 #define DMUB_CMD_PSR_CONTROL_VERSION_1 0x1
132
133
134 /**
135  * ABM control version legacy
136  */
137 #define DMUB_CMD_ABM_CONTROL_VERSION_UNKNOWN 0x0
138
139 /**
140  * ABM control version with multi edp support
141  */
142 #define DMUB_CMD_ABM_CONTROL_VERSION_1 0x1
143
144 /**
145  * Physical framebuffer address location, 64-bit.
146  */
147 #ifndef PHYSICAL_ADDRESS_LOC
148 #define PHYSICAL_ADDRESS_LOC union large_integer
149 #endif
150
151 /**
152  * OS/FW agnostic memcpy
153  */
154 #ifndef dmub_memcpy
155 #define dmub_memcpy(dest, source, bytes) memcpy((dest), (source), (bytes))
156 #endif
157
158 /**
159  * OS/FW agnostic memset
160  */
161 #ifndef dmub_memset
162 #define dmub_memset(dest, val, bytes) memset((dest), (val), (bytes))
163 #endif
164
165 #if defined(__cplusplus)
166 extern "C" {
167 #endif
168
169 /**
170  * OS/FW agnostic udelay
171  */
172 #ifndef dmub_udelay
173 #define dmub_udelay(microseconds) udelay(microseconds)
174 #endif
175
176 /**
177  * Number of nanoseconds per DMUB tick.
178  * DMCUB_TIMER_CURRENT increments in DMUB ticks, which are 10ns by default.
179  * If DMCUB_TIMER_WINDOW is non-zero this will no longer be true.
180  */
181 #define NS_PER_DMUB_TICK 10
182
183 /**
184  * union dmub_addr - DMUB physical/virtual 64-bit address.
185  */
186 union dmub_addr {
187         struct {
188                 uint32_t low_part; /**< Lower 32 bits */
189                 uint32_t high_part; /**< Upper 32 bits */
190         } u; /*<< Low/high bit access */
191         uint64_t quad_part; /*<< 64 bit address */
192 };
193
194 /**
195  * Flags that can be set by driver to change some PSR behaviour.
196  */
197 union dmub_psr_debug_flags {
198         /**
199          * Debug flags.
200          */
201         struct {
202                 /**
203                  * Enable visual confirm in FW.
204                  */
205                 uint32_t visual_confirm : 1;
206                 /**
207                  * Use HW Lock Mgr object to do HW locking in FW.
208                  */
209                 uint32_t use_hw_lock_mgr : 1;
210
211                 /**
212                  * Unused.
213                  * TODO: Remove.
214                  */
215                 uint32_t log_line_nums : 1;
216         } bitfields;
217
218         /**
219          * Union for debug flags.
220          */
221         uint32_t u32All;
222 };
223
224 /**
225  * DMUB feature capabilities.
226  * After DMUB init, driver will query FW capabilities prior to enabling certain features.
227  */
228 struct dmub_feature_caps {
229         /**
230          * Max PSR version supported by FW.
231          */
232         uint8_t psr;
233         uint8_t reserved[7];
234 };
235
236 #if defined(__cplusplus)
237 }
238 #endif
239
240 //==============================================================================
241 //</DMUB_TYPES>=================================================================
242 //==============================================================================
243 //< DMUB_META>==================================================================
244 //==============================================================================
245 #pragma pack(push, 1)
246
247 /* Magic value for identifying dmub_fw_meta_info */
248 #define DMUB_FW_META_MAGIC 0x444D5542
249
250 /* Offset from the end of the file to the dmub_fw_meta_info */
251 #define DMUB_FW_META_OFFSET 0x24
252
253 /**
254  * struct dmub_fw_meta_info - metadata associated with fw binary
255  *
256  * NOTE: This should be considered a stable API. Fields should
257  *       not be repurposed or reordered. New fields should be
258  *       added instead to extend the structure.
259  *
260  * @magic_value: magic value identifying DMUB firmware meta info
261  * @fw_region_size: size of the firmware state region
262  * @trace_buffer_size: size of the tracebuffer region
263  * @fw_version: the firmware version information
264  * @dal_fw: 1 if the firmware is DAL
265  */
266 struct dmub_fw_meta_info {
267         uint32_t magic_value; /**< magic value identifying DMUB firmware meta info */
268         uint32_t fw_region_size; /**< size of the firmware state region */
269         uint32_t trace_buffer_size; /**< size of the tracebuffer region */
270         uint32_t fw_version; /**< the firmware version information */
271         uint8_t dal_fw; /**< 1 if the firmware is DAL */
272         uint8_t reserved[3]; /**< padding bits */
273 };
274
275 /**
276  * union dmub_fw_meta - ensures that dmub_fw_meta_info remains 64 bytes
277  */
278 union dmub_fw_meta {
279         struct dmub_fw_meta_info info; /**< metadata info */
280         uint8_t reserved[64]; /**< padding bits */
281 };
282
283 #pragma pack(pop)
284
285 //==============================================================================
286 //< DMUB Trace Buffer>================================================================
287 //==============================================================================
288 /**
289  * dmub_trace_code_t - firmware trace code, 32-bits
290  */
291 typedef uint32_t dmub_trace_code_t;
292
293 /**
294  * struct dmcub_trace_buf_entry - Firmware trace entry
295  */
296 struct dmcub_trace_buf_entry {
297         dmub_trace_code_t trace_code; /**< trace code for the event */
298         uint32_t tick_count; /**< the tick count at time of trace */
299         uint32_t param0; /**< trace defined parameter 0 */
300         uint32_t param1; /**< trace defined parameter 1 */
301 };
302
303 //==============================================================================
304 //< DMUB_STATUS>================================================================
305 //==============================================================================
306
307 /**
308  * DMCUB scratch registers can be used to determine firmware status.
309  * Current scratch register usage is as follows:
310  *
311  * SCRATCH0: FW Boot Status register
312  * SCRATCH15: FW Boot Options register
313  */
314
315 /**
316  * union dmub_fw_boot_status - Status bit definitions for SCRATCH0.
317  */
318 union dmub_fw_boot_status {
319         struct {
320                 uint32_t dal_fw : 1; /**< 1 if DAL FW */
321                 uint32_t mailbox_rdy : 1; /**< 1 if mailbox ready */
322                 uint32_t optimized_init_done : 1; /**< 1 if optimized init done */
323                 uint32_t restore_required : 1; /**< 1 if driver should call restore */
324         } bits; /**< status bits */
325         uint32_t all; /**< 32-bit access to status bits */
326 };
327
328 /**
329  * enum dmub_fw_boot_status_bit - Enum bit definitions for SCRATCH0.
330  */
331 enum dmub_fw_boot_status_bit {
332         DMUB_FW_BOOT_STATUS_BIT_DAL_FIRMWARE = (1 << 0), /**< 1 if DAL FW */
333         DMUB_FW_BOOT_STATUS_BIT_MAILBOX_READY = (1 << 1), /**< 1 if mailbox ready */
334         DMUB_FW_BOOT_STATUS_BIT_OPTIMIZED_INIT_DONE = (1 << 2), /**< 1 if init done */
335         DMUB_FW_BOOT_STATUS_BIT_RESTORE_REQUIRED = (1 << 3), /**< 1 if driver should call restore */
336 };
337
338 /**
339  * union dmub_fw_boot_options - Boot option definitions for SCRATCH15
340  */
341 union dmub_fw_boot_options {
342         struct {
343                 uint32_t pemu_env : 1; /**< 1 if PEMU */
344                 uint32_t fpga_env : 1; /**< 1 if FPGA */
345                 uint32_t optimized_init : 1; /**< 1 if optimized init */
346                 uint32_t skip_phy_access : 1; /**< 1 if PHY access should be skipped */
347                 uint32_t disable_clk_gate: 1; /**< 1 if clock gating should be disabled */
348                 uint32_t skip_phy_init_panel_sequence: 1; /**< 1 to skip panel init seq */
349 #ifdef CONFIG_DRM_AMD_DC_DCN3_1
350                 uint32_t z10_disable: 1; /**< 1 to disable z10 */
351 #else
352                 uint32_t reserved_unreleased: 1; /**< reserved for an unreleased feature */
353 #endif
354                 uint32_t reserved : 25; /**< reserved */
355         } bits; /**< boot bits */
356         uint32_t all; /**< 32-bit access to bits */
357 };
358
359 enum dmub_fw_boot_options_bit {
360         DMUB_FW_BOOT_OPTION_BIT_PEMU_ENV = (1 << 0), /**< 1 if PEMU */
361         DMUB_FW_BOOT_OPTION_BIT_FPGA_ENV = (1 << 1), /**< 1 if FPGA */
362         DMUB_FW_BOOT_OPTION_BIT_OPTIMIZED_INIT_DONE = (1 << 2), /**< 1 if optimized init done */
363 };
364
365 //==============================================================================
366 //</DMUB_STATUS>================================================================
367 //==============================================================================
368 //< DMUB_VBIOS>=================================================================
369 //==============================================================================
370
371 /*
372  * enum dmub_cmd_vbios_type - VBIOS commands.
373  *
374  * Command IDs should be treated as stable ABI.
375  * Do not reuse or modify IDs.
376  */
377 enum dmub_cmd_vbios_type {
378         /**
379          * Configures the DIG encoder.
380          */
381         DMUB_CMD__VBIOS_DIGX_ENCODER_CONTROL = 0,
382         /**
383          * Controls the PHY.
384          */
385         DMUB_CMD__VBIOS_DIG1_TRANSMITTER_CONTROL = 1,
386         /**
387          * Sets the pixel clock/symbol clock.
388          */
389         DMUB_CMD__VBIOS_SET_PIXEL_CLOCK = 2,
390         /**
391          * Enables or disables power gating.
392          */
393         DMUB_CMD__VBIOS_ENABLE_DISP_POWER_GATING = 3,
394         DMUB_CMD__VBIOS_LVTMA_CONTROL = 15,
395 };
396
397 //==============================================================================
398 //</DMUB_VBIOS>=================================================================
399 //==============================================================================
400 //< DMUB_GPINT>=================================================================
401 //==============================================================================
402
403 /**
404  * The shifts and masks below may alternatively be used to format and read
405  * the command register bits.
406  */
407
408 #define DMUB_GPINT_DATA_PARAM_MASK 0xFFFF
409 #define DMUB_GPINT_DATA_PARAM_SHIFT 0
410
411 #define DMUB_GPINT_DATA_COMMAND_CODE_MASK 0xFFF
412 #define DMUB_GPINT_DATA_COMMAND_CODE_SHIFT 16
413
414 #define DMUB_GPINT_DATA_STATUS_MASK 0xF
415 #define DMUB_GPINT_DATA_STATUS_SHIFT 28
416
417 /**
418  * Command responses.
419  */
420
421 /**
422  * Return response for DMUB_GPINT__STOP_FW command.
423  */
424 #define DMUB_GPINT__STOP_FW_RESPONSE 0xDEADDEAD
425
426 /**
427  * union dmub_gpint_data_register - Format for sending a command via the GPINT.
428  */
429 union dmub_gpint_data_register {
430         struct {
431                 uint32_t param : 16; /**< 16-bit parameter */
432                 uint32_t command_code : 12; /**< GPINT command */
433                 uint32_t status : 4; /**< Command status bit */
434         } bits; /**< GPINT bit access */
435         uint32_t all; /**< GPINT  32-bit access */
436 };
437
438 /*
439  * enum dmub_gpint_command - GPINT command to DMCUB FW
440  *
441  * Command IDs should be treated as stable ABI.
442  * Do not reuse or modify IDs.
443  */
444 enum dmub_gpint_command {
445         /**
446          * Invalid command, ignored.
447          */
448         DMUB_GPINT__INVALID_COMMAND = 0,
449         /**
450          * DESC: Queries the firmware version.
451          * RETURN: Firmware version.
452          */
453         DMUB_GPINT__GET_FW_VERSION = 1,
454         /**
455          * DESC: Halts the firmware.
456          * RETURN: DMUB_GPINT__STOP_FW_RESPONSE (0xDEADDEAD) when halted
457          */
458         DMUB_GPINT__STOP_FW = 2,
459         /**
460          * DESC: Get PSR state from FW.
461          * RETURN: PSR state enum. This enum may need to be converted to the legacy PSR state value.
462          */
463         DMUB_GPINT__GET_PSR_STATE = 7,
464         /**
465          * DESC: Notifies DMCUB of the currently active streams.
466          * ARGS: Stream mask, 1 bit per active stream index.
467          */
468         DMUB_GPINT__IDLE_OPT_NOTIFY_STREAM_MASK = 8,
469         /**
470          * DESC: Start PSR residency counter. Stop PSR resdiency counter and get value.
471          * ARGS: We can measure residency from various points. The argument will specify the residency mode.
472          *       By default, it is measured from after we powerdown the PHY, to just before we powerup the PHY.
473          * RETURN: PSR residency in milli-percent.
474          */
475         DMUB_GPINT__PSR_RESIDENCY = 9,
476 };
477
478 /**
479  * INBOX0 generic command definition
480  */
481 union dmub_inbox0_cmd_common {
482         struct {
483                 uint32_t command_code: 8; /**< INBOX0 command code */
484                 uint32_t param: 24; /**< 24-bit parameter */
485         } bits;
486         uint32_t all;
487 };
488
489 /**
490  * INBOX0 hw_lock command definition
491  */
492 union dmub_inbox0_cmd_lock_hw {
493         struct {
494                 uint32_t command_code: 8;
495
496                 /* NOTE: Must be have enough bits to match: enum hw_lock_client */
497                 uint32_t hw_lock_client: 1;
498
499                 /* NOTE: Below fields must match with: struct dmub_hw_lock_inst_flags */
500                 uint32_t otg_inst: 3;
501                 uint32_t opp_inst: 3;
502                 uint32_t dig_inst: 3;
503
504                 /* NOTE: Below fields must match with: union dmub_hw_lock_flags */
505                 uint32_t lock_pipe: 1;
506                 uint32_t lock_cursor: 1;
507                 uint32_t lock_dig: 1;
508                 uint32_t triple_buffer_lock: 1;
509
510                 uint32_t lock: 1;                               /**< Lock */
511                 uint32_t should_release: 1;             /**< Release */
512                 uint32_t reserved: 8;                   /**< Reserved for extending more clients, HW, etc. */
513         } bits;
514         uint32_t all;
515 };
516
517 union dmub_inbox0_data_register {
518         union dmub_inbox0_cmd_common inbox0_cmd_common;
519         union dmub_inbox0_cmd_lock_hw inbox0_cmd_lock_hw;
520 };
521
522 enum dmub_inbox0_command {
523         /**
524          * DESC: Invalid command, ignored.
525          */
526         DMUB_INBOX0_CMD__INVALID_COMMAND = 0,
527         /**
528          * DESC: Notification to acquire/release HW lock
529          * ARGS:
530          */
531         DMUB_INBOX0_CMD__HW_LOCK = 1,
532 };
533 //==============================================================================
534 //</DMUB_GPINT>=================================================================
535 //==============================================================================
536 //< DMUB_CMD>===================================================================
537 //==============================================================================
538
539 /**
540  * Size in bytes of each DMUB command.
541  */
542 #define DMUB_RB_CMD_SIZE 64
543
544 /**
545  * Maximum number of items in the DMUB ringbuffer.
546  */
547 #define DMUB_RB_MAX_ENTRY 128
548
549 /**
550  * Ringbuffer size in bytes.
551  */
552 #define DMUB_RB_SIZE (DMUB_RB_CMD_SIZE * DMUB_RB_MAX_ENTRY)
553
554 /**
555  * REG_SET mask for reg offload.
556  */
557 #define REG_SET_MASK 0xFFFF
558
559 /*
560  * enum dmub_cmd_type - DMUB inbox command.
561  *
562  * Command IDs should be treated as stable ABI.
563  * Do not reuse or modify IDs.
564  */
565 enum dmub_cmd_type {
566         /**
567          * Invalid command.
568          */
569         DMUB_CMD__NULL = 0,
570         /**
571          * Read modify write register sequence offload.
572          */
573         DMUB_CMD__REG_SEQ_READ_MODIFY_WRITE = 1,
574         /**
575          * Field update register sequence offload.
576          */
577         DMUB_CMD__REG_SEQ_FIELD_UPDATE_SEQ = 2,
578         /**
579          * Burst write sequence offload.
580          */
581         DMUB_CMD__REG_SEQ_BURST_WRITE = 3,
582         /**
583          * Reg wait sequence offload.
584          */
585         DMUB_CMD__REG_REG_WAIT = 4,
586         /**
587          * Workaround to avoid HUBP underflow during NV12 playback.
588          */
589         DMUB_CMD__PLAT_54186_WA = 5,
590         /**
591          * Command type used to query FW feature caps.
592          */
593         DMUB_CMD__QUERY_FEATURE_CAPS = 6,
594         /**
595          * Command type used for all PSR commands.
596          */
597         DMUB_CMD__PSR = 64,
598         /**
599          * Command type used for all MALL commands.
600          */
601         DMUB_CMD__MALL = 65,
602         /**
603          * Command type used for all ABM commands.
604          */
605         DMUB_CMD__ABM = 66,
606         /**
607          * Command type used for HW locking in FW.
608          */
609         DMUB_CMD__HW_LOCK = 69,
610         /**
611          * Command type used to access DP AUX.
612          */
613         DMUB_CMD__DP_AUX_ACCESS = 70,
614         /**
615          * Command type used for OUTBOX1 notification enable
616          */
617         DMUB_CMD__OUTBOX1_ENABLE = 71,
618 #ifdef CONFIG_DRM_AMD_DC_DCN3_1
619         /**
620          * Command type used for all idle optimization commands.
621          */
622         DMUB_CMD__IDLE_OPT = 72,
623         /**
624          * Command type used for all clock manager commands.
625          */
626         DMUB_CMD__CLK_MGR = 73,
627         /**
628          * Command type used for all panel control commands.
629          */
630         DMUB_CMD__PANEL_CNTL = 74,
631 #endif
632         /**
633          * Command type used for all VBIOS interface commands.
634          */
635         DMUB_CMD__VBIOS = 128,
636 };
637
638 /**
639  * enum dmub_out_cmd_type - DMUB outbox commands.
640  */
641 enum dmub_out_cmd_type {
642         /**
643          * Invalid outbox command, ignored.
644          */
645         DMUB_OUT_CMD__NULL = 0,
646         /**
647          * Command type used for DP AUX Reply data notification
648          */
649         DMUB_OUT_CMD__DP_AUX_REPLY = 1,
650 };
651
652 #pragma pack(push, 1)
653
654 /**
655  * struct dmub_cmd_header - Common command header fields.
656  */
657 struct dmub_cmd_header {
658         unsigned int type : 8; /**< command type */
659         unsigned int sub_type : 8; /**< command sub type */
660         unsigned int ret_status : 1; /**< 1 if returned data, 0 otherwise */
661         unsigned int multi_cmd_pending : 1; /**< 1 if multiple commands chained together */
662         unsigned int reserved0 : 6; /**< reserved bits */
663         unsigned int payload_bytes : 6;  /* payload excluding header - up to 60 bytes */
664         unsigned int reserved1 : 2; /**< reserved bits */
665 };
666
667 /*
668  * struct dmub_cmd_read_modify_write_sequence - Read modify write
669  *
670  * 60 payload bytes can hold up to 5 sets of read modify writes,
671  * each take 3 dwords.
672  *
673  * number of sequences = header.payload_bytes / sizeof(struct dmub_cmd_read_modify_write_sequence)
674  *
675  * modify_mask = 0xffff'ffff means all fields are going to be updated.  in this case
676  * command parser will skip the read and we can use modify_mask = 0xffff'ffff as reg write
677  */
678 struct dmub_cmd_read_modify_write_sequence {
679         uint32_t addr; /**< register address */
680         uint32_t modify_mask; /**< modify mask */
681         uint32_t modify_value; /**< modify value */
682 };
683
684 /**
685  * Maximum number of ops in read modify write sequence.
686  */
687 #define DMUB_READ_MODIFY_WRITE_SEQ__MAX 5
688
689 /**
690  * struct dmub_cmd_read_modify_write_sequence - Read modify write command.
691  */
692 struct dmub_rb_cmd_read_modify_write {
693         struct dmub_cmd_header header;  /**< command header */
694         /**
695          * Read modify write sequence.
696          */
697         struct dmub_cmd_read_modify_write_sequence seq[DMUB_READ_MODIFY_WRITE_SEQ__MAX];
698 };
699
700 /*
701  * Update a register with specified masks and values sequeunce
702  *
703  * 60 payload bytes can hold address + up to 7 sets of mask/value combo, each take 2 dword
704  *
705  * number of field update sequence = (header.payload_bytes - sizeof(addr)) / sizeof(struct read_modify_write_sequence)
706  *
707  *
708  * USE CASE:
709  *   1. auto-increment register where additional read would update pointer and produce wrong result
710  *   2. toggle a bit without read in the middle
711  */
712
713 struct dmub_cmd_reg_field_update_sequence {
714         uint32_t modify_mask; /**< 0xffff'ffff to skip initial read */
715         uint32_t modify_value; /**< value to update with */
716 };
717
718 /**
719  * Maximum number of ops in field update sequence.
720  */
721 #define DMUB_REG_FIELD_UPDATE_SEQ__MAX 7
722
723 /**
724  * struct dmub_rb_cmd_reg_field_update_sequence - Field update command.
725  */
726 struct dmub_rb_cmd_reg_field_update_sequence {
727         struct dmub_cmd_header header; /**< command header */
728         uint32_t addr; /**< register address */
729         /**
730          * Field update sequence.
731          */
732         struct dmub_cmd_reg_field_update_sequence seq[DMUB_REG_FIELD_UPDATE_SEQ__MAX];
733 };
734
735
736 /**
737  * Maximum number of burst write values.
738  */
739 #define DMUB_BURST_WRITE_VALUES__MAX  14
740
741 /*
742  * struct dmub_rb_cmd_burst_write - Burst write
743  *
744  * support use case such as writing out LUTs.
745  *
746  * 60 payload bytes can hold up to 14 values to write to given address
747  *
748  * number of payload = header.payload_bytes / sizeof(struct read_modify_write_sequence)
749  */
750 struct dmub_rb_cmd_burst_write {
751         struct dmub_cmd_header header; /**< command header */
752         uint32_t addr; /**< register start address */
753         /**
754          * Burst write register values.
755          */
756         uint32_t write_values[DMUB_BURST_WRITE_VALUES__MAX];
757 };
758
759 /**
760  * struct dmub_rb_cmd_common - Common command header
761  */
762 struct dmub_rb_cmd_common {
763         struct dmub_cmd_header header; /**< command header */
764         /**
765          * Padding to RB_CMD_SIZE
766          */
767         uint8_t cmd_buffer[DMUB_RB_CMD_SIZE - sizeof(struct dmub_cmd_header)];
768 };
769
770 /**
771  * struct dmub_cmd_reg_wait_data - Register wait data
772  */
773 struct dmub_cmd_reg_wait_data {
774         uint32_t addr; /**< Register address */
775         uint32_t mask; /**< Mask for register bits */
776         uint32_t condition_field_value; /**< Value to wait for */
777         uint32_t time_out_us; /**< Time out for reg wait in microseconds */
778 };
779
780 /**
781  * struct dmub_rb_cmd_reg_wait - Register wait command
782  */
783 struct dmub_rb_cmd_reg_wait {
784         struct dmub_cmd_header header; /**< Command header */
785         struct dmub_cmd_reg_wait_data reg_wait; /**< Register wait data */
786 };
787
788 /**
789  * struct dmub_cmd_PLAT_54186_wa - Underflow workaround
790  *
791  * Reprograms surface parameters to avoid underflow.
792  */
793 struct dmub_cmd_PLAT_54186_wa {
794         uint32_t DCSURF_SURFACE_CONTROL; /**< reg value */
795         uint32_t DCSURF_PRIMARY_SURFACE_ADDRESS_HIGH; /**< reg value */
796         uint32_t DCSURF_PRIMARY_SURFACE_ADDRESS; /**< reg value */
797         uint32_t DCSURF_PRIMARY_SURFACE_ADDRESS_HIGH_C; /**< reg value */
798         uint32_t DCSURF_PRIMARY_SURFACE_ADDRESS_C; /**< reg value */
799         struct {
800                 uint8_t hubp_inst : 4; /**< HUBP instance */
801                 uint8_t tmz_surface : 1; /**< TMZ enable or disable */
802                 uint8_t immediate :1; /**< Immediate flip */
803                 uint8_t vmid : 4; /**< VMID */
804                 uint8_t grph_stereo : 1; /**< 1 if stereo */
805                 uint32_t reserved : 21; /**< Reserved */
806         } flip_params; /**< Pageflip parameters */
807         uint32_t reserved[9]; /**< Reserved bits */
808 };
809
810 /**
811  * struct dmub_rb_cmd_PLAT_54186_wa - Underflow workaround command
812  */
813 struct dmub_rb_cmd_PLAT_54186_wa {
814         struct dmub_cmd_header header; /**< Command header */
815         struct dmub_cmd_PLAT_54186_wa flip; /**< Flip data */
816 };
817
818 /**
819  * struct dmub_rb_cmd_mall - MALL command data.
820  */
821 struct dmub_rb_cmd_mall {
822         struct dmub_cmd_header header; /**< Common command header */
823         union dmub_addr cursor_copy_src; /**< Cursor copy address */
824         union dmub_addr cursor_copy_dst; /**< Cursor copy destination */
825         uint32_t tmr_delay; /**< Timer delay */
826         uint32_t tmr_scale; /**< Timer scale */
827         uint16_t cursor_width; /**< Cursor width in pixels */
828         uint16_t cursor_pitch; /**< Cursor pitch in pixels */
829         uint16_t cursor_height; /**< Cursor height in pixels */
830         uint8_t cursor_bpp; /**< Cursor bits per pixel */
831         uint8_t debug_bits; /**< Debug bits */
832
833         uint8_t reserved1; /**< Reserved bits */
834         uint8_t reserved2; /**< Reserved bits */
835 };
836
837 #ifdef CONFIG_DRM_AMD_DC_DCN3_1
838
839 /**
840  * enum dmub_cmd_idle_opt_type - Idle optimization command type.
841  */
842 enum dmub_cmd_idle_opt_type {
843         /**
844          * DCN hardware restore.
845          */
846         DMUB_CMD__IDLE_OPT_DCN_RESTORE = 0,
847 };
848
849 /**
850  * struct dmub_rb_cmd_idle_opt_dcn_restore - DCN restore command data.
851  */
852 struct dmub_rb_cmd_idle_opt_dcn_restore {
853         struct dmub_cmd_header header; /**< header */
854 };
855
856 /**
857  * struct dmub_clocks - Clock update notification.
858  */
859 struct dmub_clocks {
860         uint32_t dispclk_khz; /**< dispclk kHz */
861         uint32_t dppclk_khz; /**< dppclk kHz */
862         uint32_t dcfclk_khz; /**< dcfclk kHz */
863         uint32_t dcfclk_deep_sleep_khz; /**< dcfclk deep sleep kHz */
864 };
865
866 /**
867  * enum dmub_cmd_clk_mgr_type - Clock manager commands.
868  */
869 enum dmub_cmd_clk_mgr_type {
870         /**
871          * Notify DMCUB of clock update.
872          */
873         DMUB_CMD__CLK_MGR_NOTIFY_CLOCKS = 0,
874 };
875
876 /**
877  * struct dmub_rb_cmd_clk_mgr_notify_clocks - Clock update notification.
878  */
879 struct dmub_rb_cmd_clk_mgr_notify_clocks {
880         struct dmub_cmd_header header; /**< header */
881         struct dmub_clocks clocks; /**< clock data */
882 };
883 #endif
884 /**
885  * struct dmub_cmd_digx_encoder_control_data - Encoder control data.
886  */
887 struct dmub_cmd_digx_encoder_control_data {
888         union dig_encoder_control_parameters_v1_5 dig; /**< payload */
889 };
890
891 /**
892  * struct dmub_rb_cmd_digx_encoder_control - Encoder control command.
893  */
894 struct dmub_rb_cmd_digx_encoder_control {
895         struct dmub_cmd_header header;  /**< header */
896         struct dmub_cmd_digx_encoder_control_data encoder_control; /**< payload */
897 };
898
899 /**
900  * struct dmub_cmd_set_pixel_clock_data - Set pixel clock data.
901  */
902 struct dmub_cmd_set_pixel_clock_data {
903         struct set_pixel_clock_parameter_v1_7 clk; /**< payload */
904 };
905
906 /**
907  * struct dmub_cmd_set_pixel_clock_data - Set pixel clock command.
908  */
909 struct dmub_rb_cmd_set_pixel_clock {
910         struct dmub_cmd_header header; /**< header */
911         struct dmub_cmd_set_pixel_clock_data pixel_clock; /**< payload */
912 };
913
914 /**
915  * struct dmub_cmd_enable_disp_power_gating_data - Display power gating.
916  */
917 struct dmub_cmd_enable_disp_power_gating_data {
918         struct enable_disp_power_gating_parameters_v2_1 pwr; /**< payload */
919 };
920
921 /**
922  * struct dmub_rb_cmd_enable_disp_power_gating - Display power command.
923  */
924 struct dmub_rb_cmd_enable_disp_power_gating {
925         struct dmub_cmd_header header; /**< header */
926         struct dmub_cmd_enable_disp_power_gating_data power_gating;  /**< payload */
927 };
928
929 /**
930  * struct dmub_dig_transmitter_control_data_v1_7 - Transmitter control.
931  */
932 struct dmub_dig_transmitter_control_data_v1_7 {
933         uint8_t phyid; /**< 0=UNIPHYA, 1=UNIPHYB, 2=UNIPHYC, 3=UNIPHYD, 4=UNIPHYE, 5=UNIPHYF */
934         uint8_t action; /**< Defined as ATOM_TRANSMITER_ACTION_xxx */
935         union {
936                 uint8_t digmode; /**< enum atom_encode_mode_def */
937                 uint8_t dplaneset; /**< DP voltage swing and pre-emphasis value, "DP_LANE_SET__xDB_y_zV" */
938         } mode_laneset;
939         uint8_t lanenum; /**< Number of lanes */
940         union {
941                 uint32_t symclk_10khz; /**< Symbol Clock in 10Khz */
942         } symclk_units;
943         uint8_t hpdsel; /**< =1: HPD1, =2: HPD2, ..., =6: HPD6, =0: HPD is not assigned */
944         uint8_t digfe_sel; /**< DIG front-end selection, bit0 means DIG0 FE is enabled */
945         uint8_t connobj_id; /**< Connector Object Id defined in ObjectId.h */
946         uint8_t reserved0; /**< For future use */
947         uint8_t reserved1; /**< For future use */
948         uint8_t reserved2[3]; /**< For future use */
949         uint32_t reserved3[11]; /**< For future use */
950 };
951
952 /**
953  * union dmub_cmd_dig1_transmitter_control_data - Transmitter control data.
954  */
955 union dmub_cmd_dig1_transmitter_control_data {
956         struct dig_transmitter_control_parameters_v1_6 dig; /**< payload */
957         struct dmub_dig_transmitter_control_data_v1_7 dig_v1_7;  /**< payload 1.7 */
958 };
959
960 /**
961  * struct dmub_rb_cmd_dig1_transmitter_control - Transmitter control command.
962  */
963 struct dmub_rb_cmd_dig1_transmitter_control {
964         struct dmub_cmd_header header; /**< header */
965         union dmub_cmd_dig1_transmitter_control_data transmitter_control; /**< payload */
966 };
967
968 /**
969  * struct dmub_rb_cmd_dpphy_init - DPPHY init.
970  */
971 struct dmub_rb_cmd_dpphy_init {
972         struct dmub_cmd_header header; /**< header */
973         uint8_t reserved[60]; /**< reserved bits */
974 };
975
976 /**
977  * enum dp_aux_request_action - DP AUX request command listing.
978  *
979  * 4 AUX request command bits are shifted to high nibble.
980  */
981 enum dp_aux_request_action {
982         /** I2C-over-AUX write request */
983         DP_AUX_REQ_ACTION_I2C_WRITE             = 0x00,
984         /** I2C-over-AUX read request */
985         DP_AUX_REQ_ACTION_I2C_READ              = 0x10,
986         /** I2C-over-AUX write status request */
987         DP_AUX_REQ_ACTION_I2C_STATUS_REQ        = 0x20,
988         /** I2C-over-AUX write request with MOT=1 */
989         DP_AUX_REQ_ACTION_I2C_WRITE_MOT         = 0x40,
990         /** I2C-over-AUX read request with MOT=1 */
991         DP_AUX_REQ_ACTION_I2C_READ_MOT          = 0x50,
992         /** I2C-over-AUX write status request with MOT=1 */
993         DP_AUX_REQ_ACTION_I2C_STATUS_REQ_MOT    = 0x60,
994         /** Native AUX write request */
995         DP_AUX_REQ_ACTION_DPCD_WRITE            = 0x80,
996         /** Native AUX read request */
997         DP_AUX_REQ_ACTION_DPCD_READ             = 0x90
998 };
999
1000 /**
1001  * enum aux_return_code_type - DP AUX process return code listing.
1002  */
1003 enum aux_return_code_type {
1004         /** AUX process succeeded */
1005         AUX_RET_SUCCESS = 0,
1006         /** AUX process failed with unknown reason */
1007         AUX_RET_ERROR_UNKNOWN,
1008         /** AUX process completed with invalid reply */
1009         AUX_RET_ERROR_INVALID_REPLY,
1010         /** AUX process timed out */
1011         AUX_RET_ERROR_TIMEOUT,
1012         /** HPD was low during AUX process */
1013         AUX_RET_ERROR_HPD_DISCON,
1014         /** Failed to acquire AUX engine */
1015         AUX_RET_ERROR_ENGINE_ACQUIRE,
1016         /** AUX request not supported */
1017         AUX_RET_ERROR_INVALID_OPERATION,
1018         /** AUX process not available */
1019         AUX_RET_ERROR_PROTOCOL_ERROR,
1020 };
1021
1022 /**
1023  * enum aux_channel_type - DP AUX channel type listing.
1024  */
1025 enum aux_channel_type {
1026         /** AUX thru Legacy DP AUX */
1027         AUX_CHANNEL_LEGACY_DDC,
1028         /** AUX thru DPIA DP tunneling */
1029         AUX_CHANNEL_DPIA
1030 };
1031
1032 /**
1033  * struct aux_transaction_parameters - DP AUX request transaction data
1034  */
1035 struct aux_transaction_parameters {
1036         uint8_t is_i2c_over_aux; /**< 0=native AUX, 1=I2C-over-AUX */
1037         uint8_t action; /**< enum dp_aux_request_action */
1038         uint8_t length; /**< DP AUX request data length */
1039         uint8_t reserved; /**< For future use */
1040         uint32_t address; /**< DP AUX address */
1041         uint8_t data[16]; /**< DP AUX write data */
1042 };
1043
1044 /**
1045  * Data passed from driver to FW in a DMUB_CMD__DP_AUX_ACCESS command.
1046  */
1047 struct dmub_cmd_dp_aux_control_data {
1048         uint8_t instance; /**< AUX instance or DPIA instance */
1049         uint8_t manual_acq_rel_enable; /**< manual control for acquiring or releasing AUX channel */
1050         uint8_t sw_crc_enabled; /**< Use software CRC for tunneling packet instead of hardware CRC */
1051         uint8_t reserved0; /**< For future use */
1052         uint16_t timeout; /**< timeout time in us */
1053         uint16_t reserved1; /**< For future use */
1054         enum aux_channel_type type; /**< enum aux_channel_type */
1055         struct aux_transaction_parameters dpaux; /**< struct aux_transaction_parameters */
1056 };
1057
1058 /**
1059  * Definition of a DMUB_CMD__DP_AUX_ACCESS command.
1060  */
1061 struct dmub_rb_cmd_dp_aux_access {
1062         /**
1063          * Command header.
1064          */
1065         struct dmub_cmd_header header;
1066         /**
1067          * Data passed from driver to FW in a DMUB_CMD__DP_AUX_ACCESS command.
1068          */
1069         struct dmub_cmd_dp_aux_control_data aux_control;
1070 };
1071
1072 /**
1073  * Definition of a DMUB_CMD__OUTBOX1_ENABLE command.
1074  */
1075 struct dmub_rb_cmd_outbox1_enable {
1076         /**
1077          * Command header.
1078          */
1079         struct dmub_cmd_header header;
1080         /**
1081          *  enable: 0x0 -> disable outbox1 notification (default value)
1082          *                      0x1 -> enable outbox1 notification
1083          */
1084         uint32_t enable;
1085 };
1086
1087 /* DP AUX Reply command - OutBox Cmd */
1088 /**
1089  * Data passed to driver from FW in a DMUB_OUT_CMD__DP_AUX_REPLY command.
1090  */
1091 struct aux_reply_data {
1092         /**
1093          * Aux cmd
1094          */
1095         uint8_t command;
1096         /**
1097          * Aux reply data length (max: 16 bytes)
1098          */
1099         uint8_t length;
1100         /**
1101          * Alignment only
1102          */
1103         uint8_t pad[2];
1104         /**
1105          * Aux reply data
1106          */
1107         uint8_t data[16];
1108 };
1109
1110 /**
1111  * Control Data passed to driver from FW in a DMUB_OUT_CMD__DP_AUX_REPLY command.
1112  */
1113 struct aux_reply_control_data {
1114         /**
1115          * Reserved for future use
1116          */
1117         uint32_t handle;
1118         /**
1119          * Aux Instance
1120          */
1121         uint8_t instance;
1122         /**
1123          * Aux transaction result: definition in enum aux_return_code_type
1124          */
1125         uint8_t result;
1126         /**
1127          * Alignment only
1128          */
1129         uint16_t pad;
1130 };
1131
1132 /**
1133  * Definition of a DMUB_OUT_CMD__DP_AUX_REPLY command.
1134  */
1135 struct dmub_rb_cmd_dp_aux_reply {
1136         /**
1137          * Command header.
1138          */
1139         struct dmub_cmd_header header;
1140         /**
1141          * Control Data passed to driver from FW in a DMUB_OUT_CMD__DP_AUX_REPLY command.
1142          */
1143         struct aux_reply_control_data control;
1144         /**
1145          * Data passed to driver from FW in a DMUB_OUT_CMD__DP_AUX_REPLY command.
1146          */
1147         struct aux_reply_data reply_data;
1148 };
1149
1150 /* DP HPD Notify command - OutBox Cmd */
1151 /**
1152  * DP HPD Type
1153  */
1154 enum dp_hpd_type {
1155         /**
1156          * Normal DP HPD
1157          */
1158         DP_HPD = 0,
1159         /**
1160          * DP HPD short pulse
1161          */
1162         DP_IRQ
1163 };
1164
1165 /**
1166  * DP HPD Status
1167  */
1168 enum dp_hpd_status {
1169         /**
1170          * DP_HPD status low
1171          */
1172         DP_HPD_UNPLUG = 0,
1173         /**
1174          * DP_HPD status high
1175          */
1176         DP_HPD_PLUG
1177 };
1178
1179 /**
1180  * Data passed to driver from FW in a DMUB_OUT_CMD__DP_HPD_NOTIFY command.
1181  */
1182 struct dp_hpd_data {
1183         /**
1184          * DP HPD instance
1185          */
1186         uint8_t instance;
1187         /**
1188          * HPD type
1189          */
1190         uint8_t hpd_type;
1191         /**
1192          * HPD status: only for type: DP_HPD to indicate status
1193          */
1194         uint8_t hpd_status;
1195         /**
1196          * Alignment only
1197          */
1198         uint8_t pad;
1199 };
1200
1201 /**
1202  * Definition of a DMUB_OUT_CMD__DP_HPD_NOTIFY command.
1203  */
1204 struct dmub_rb_cmd_dp_hpd_notify {
1205         /**
1206          * Command header.
1207          */
1208         struct dmub_cmd_header header;
1209         /**
1210          * Data passed to driver from FW in a DMUB_OUT_CMD__DP_HPD_NOTIFY command.
1211          */
1212         struct dp_hpd_data hpd_data;
1213 };
1214
1215 /*
1216  * Command IDs should be treated as stable ABI.
1217  * Do not reuse or modify IDs.
1218  */
1219
1220 /**
1221  * PSR command sub-types.
1222  */
1223 enum dmub_cmd_psr_type {
1224         /**
1225          * Set PSR version support.
1226          */
1227         DMUB_CMD__PSR_SET_VERSION               = 0,
1228         /**
1229          * Copy driver-calculated parameters to PSR state.
1230          */
1231         DMUB_CMD__PSR_COPY_SETTINGS             = 1,
1232         /**
1233          * Enable PSR.
1234          */
1235         DMUB_CMD__PSR_ENABLE                    = 2,
1236
1237         /**
1238          * Disable PSR.
1239          */
1240         DMUB_CMD__PSR_DISABLE                   = 3,
1241
1242         /**
1243          * Set PSR level.
1244          * PSR level is a 16-bit value dicated by driver that
1245          * will enable/disable different functionality.
1246          */
1247         DMUB_CMD__PSR_SET_LEVEL                 = 4,
1248
1249         /**
1250          * Forces PSR enabled until an explicit PSR disable call.
1251          */
1252         DMUB_CMD__PSR_FORCE_STATIC              = 5,
1253 };
1254
1255 /**
1256  * PSR versions.
1257  */
1258 enum psr_version {
1259         /**
1260          * PSR version 1.
1261          */
1262         PSR_VERSION_1                           = 0,
1263         /**
1264          * PSR not supported.
1265          */
1266         PSR_VERSION_UNSUPPORTED                 = 0xFFFFFFFF,
1267 };
1268
1269 /**
1270  * enum dmub_cmd_mall_type - MALL commands
1271  */
1272 enum dmub_cmd_mall_type {
1273         /**
1274          * Allows display refresh from MALL.
1275          */
1276         DMUB_CMD__MALL_ACTION_ALLOW = 0,
1277         /**
1278          * Disallows display refresh from MALL.
1279          */
1280         DMUB_CMD__MALL_ACTION_DISALLOW = 1,
1281         /**
1282          * Cursor copy for MALL.
1283          */
1284         DMUB_CMD__MALL_ACTION_COPY_CURSOR = 2,
1285         /**
1286          * Controls DF requests.
1287          */
1288         DMUB_CMD__MALL_ACTION_NO_DF_REQ = 3,
1289 };
1290
1291
1292 /**
1293  * Data passed from driver to FW in a DMUB_CMD__PSR_COPY_SETTINGS command.
1294  */
1295 struct dmub_cmd_psr_copy_settings_data {
1296         /**
1297          * Flags that can be set by driver to change some PSR behaviour.
1298          */
1299         union dmub_psr_debug_flags debug;
1300         /**
1301          * 16-bit value dicated by driver that will enable/disable different functionality.
1302          */
1303         uint16_t psr_level;
1304         /**
1305          * DPP HW instance.
1306          */
1307         uint8_t dpp_inst;
1308         /**
1309          * MPCC HW instance.
1310          * Not used in dmub fw,
1311          * dmub fw will get active opp by reading odm registers.
1312          */
1313         uint8_t mpcc_inst;
1314         /**
1315          * OPP HW instance.
1316          * Not used in dmub fw,
1317          * dmub fw will get active opp by reading odm registers.
1318          */
1319         uint8_t opp_inst;
1320         /**
1321          * OTG HW instance.
1322          */
1323         uint8_t otg_inst;
1324         /**
1325          * DIG FE HW instance.
1326          */
1327         uint8_t digfe_inst;
1328         /**
1329          * DIG BE HW instance.
1330          */
1331         uint8_t digbe_inst;
1332         /**
1333          * DP PHY HW instance.
1334          */
1335         uint8_t dpphy_inst;
1336         /**
1337          * AUX HW instance.
1338          */
1339         uint8_t aux_inst;
1340         /**
1341          * Determines if SMU optimzations are enabled/disabled.
1342          */
1343         uint8_t smu_optimizations_en;
1344         /**
1345          * Unused.
1346          * TODO: Remove.
1347          */
1348         uint8_t frame_delay;
1349         /**
1350          * If RFB setup time is greater than the total VBLANK time,
1351          * it is not possible for the sink to capture the video frame
1352          * in the same frame the SDP is sent. In this case,
1353          * the frame capture indication bit should be set and an extra
1354          * static frame should be transmitted to the sink.
1355          */
1356         uint8_t frame_cap_ind;
1357         /**
1358          * Explicit padding to 4 byte boundary.
1359          */
1360         uint8_t pad[2];
1361         /**
1362          * Multi-display optimizations are implemented on certain ASICs.
1363          */
1364         uint8_t multi_disp_optimizations_en;
1365         /**
1366          * The last possible line SDP may be transmitted without violating
1367          * the RFB setup time or entering the active video frame.
1368          */
1369         uint16_t init_sdp_deadline;
1370         /**
1371          * Explicit padding to 4 byte boundary.
1372          */
1373         uint16_t pad2;
1374         /**
1375          * Length of each horizontal line in us.
1376          */
1377         uint32_t line_time_in_us;
1378         /**
1379          * FEC enable status in driver
1380          */
1381         uint8_t fec_enable_status;
1382         /**
1383          * FEC re-enable delay when PSR exit.
1384          * unit is 100us, range form 0~255(0xFF).
1385          */
1386         uint8_t fec_enable_delay_in100us;
1387         /**
1388          * PSR control version.
1389          */
1390         uint8_t cmd_version;
1391         /**
1392          * Panel Instance.
1393          * Panel isntance to identify which psr_state to use
1394          * Currently the support is only for 0 or 1
1395          */
1396         uint8_t panel_inst;
1397 };
1398
1399 /**
1400  * Definition of a DMUB_CMD__PSR_COPY_SETTINGS command.
1401  */
1402 struct dmub_rb_cmd_psr_copy_settings {
1403         /**
1404          * Command header.
1405          */
1406         struct dmub_cmd_header header;
1407         /**
1408          * Data passed from driver to FW in a DMUB_CMD__PSR_COPY_SETTINGS command.
1409          */
1410         struct dmub_cmd_psr_copy_settings_data psr_copy_settings_data;
1411 };
1412
1413 /**
1414  * Data passed from driver to FW in a DMUB_CMD__PSR_SET_LEVEL command.
1415  */
1416 struct dmub_cmd_psr_set_level_data {
1417         /**
1418          * 16-bit value dicated by driver that will enable/disable different functionality.
1419          */
1420         uint16_t psr_level;
1421                 /**
1422          * PSR control version.
1423          */
1424         uint8_t cmd_version;
1425         /**
1426          * Panel Instance.
1427          * Panel isntance to identify which psr_state to use
1428          * Currently the support is only for 0 or 1
1429          */
1430         uint8_t panel_inst;
1431 };
1432
1433 /**
1434  * Definition of a DMUB_CMD__PSR_SET_LEVEL command.
1435  */
1436 struct dmub_rb_cmd_psr_set_level {
1437         /**
1438          * Command header.
1439          */
1440         struct dmub_cmd_header header;
1441         /**
1442          * Definition of a DMUB_CMD__PSR_SET_LEVEL command.
1443          */
1444         struct dmub_cmd_psr_set_level_data psr_set_level_data;
1445 };
1446
1447 struct dmub_rb_cmd_psr_enable_data {
1448         /**
1449          * PSR control version.
1450          */
1451         uint8_t cmd_version;
1452         /**
1453          * Panel Instance.
1454          * Panel isntance to identify which psr_state to use
1455          * Currently the support is only for 0 or 1
1456          */
1457         uint8_t panel_inst;
1458         /**
1459          * Explicit padding to 4 byte boundary.
1460          */
1461         uint8_t pad[2];
1462 };
1463
1464 /**
1465  * Definition of a DMUB_CMD__PSR_ENABLE command.
1466  * PSR enable/disable is controlled using the sub_type.
1467  */
1468 struct dmub_rb_cmd_psr_enable {
1469         /**
1470          * Command header.
1471          */
1472         struct dmub_cmd_header header;
1473
1474         struct dmub_rb_cmd_psr_enable_data data;
1475 };
1476
1477 /**
1478  * Data passed from driver to FW in a DMUB_CMD__PSR_SET_VERSION command.
1479  */
1480 struct dmub_cmd_psr_set_version_data {
1481         /**
1482          * PSR version that FW should implement.
1483          */
1484         enum psr_version version;
1485         /**
1486          * PSR control version.
1487          */
1488         uint8_t cmd_version;
1489         /**
1490          * Panel Instance.
1491          * Panel isntance to identify which psr_state to use
1492          * Currently the support is only for 0 or 1
1493          */
1494         uint8_t panel_inst;
1495         /**
1496          * Explicit padding to 4 byte boundary.
1497          */
1498         uint8_t pad[2];
1499 };
1500
1501 /**
1502  * Definition of a DMUB_CMD__PSR_SET_VERSION command.
1503  */
1504 struct dmub_rb_cmd_psr_set_version {
1505         /**
1506          * Command header.
1507          */
1508         struct dmub_cmd_header header;
1509         /**
1510          * Data passed from driver to FW in a DMUB_CMD__PSR_SET_VERSION command.
1511          */
1512         struct dmub_cmd_psr_set_version_data psr_set_version_data;
1513 };
1514
1515 struct dmub_cmd_psr_force_static_data {
1516         /**
1517          * PSR control version.
1518          */
1519         uint8_t cmd_version;
1520         /**
1521          * Panel Instance.
1522          * Panel isntance to identify which psr_state to use
1523          * Currently the support is only for 0 or 1
1524          */
1525         uint8_t panel_inst;
1526         /**
1527          * Explicit padding to 4 byte boundary.
1528          */
1529         uint8_t pad[2];
1530 };
1531
1532 /**
1533  * Definition of a DMUB_CMD__PSR_FORCE_STATIC command.
1534  */
1535 struct dmub_rb_cmd_psr_force_static {
1536         /**
1537          * Command header.
1538          */
1539         struct dmub_cmd_header header;
1540         /**
1541          * Data passed from driver to FW in a DMUB_CMD__PSR_FORCE_STATIC command.
1542          */
1543         struct dmub_cmd_psr_force_static_data psr_force_static_data;
1544 };
1545
1546 /**
1547  * Set of HW components that can be locked.
1548  *
1549  * Note: If updating with more HW components, fields
1550  * in dmub_inbox0_cmd_lock_hw must be updated to match.
1551  */
1552 union dmub_hw_lock_flags {
1553         /**
1554          * Set of HW components that can be locked.
1555          */
1556         struct {
1557                 /**
1558                  * Lock/unlock OTG master update lock.
1559                  */
1560                 uint8_t lock_pipe   : 1;
1561                 /**
1562                  * Lock/unlock cursor.
1563                  */
1564                 uint8_t lock_cursor : 1;
1565                 /**
1566                  * Lock/unlock global update lock.
1567                  */
1568                 uint8_t lock_dig    : 1;
1569                 /**
1570                  * Triple buffer lock requires additional hw programming to usual OTG master lock.
1571                  */
1572                 uint8_t triple_buffer_lock : 1;
1573         } bits;
1574
1575         /**
1576          * Union for HW Lock flags.
1577          */
1578         uint8_t u8All;
1579 };
1580
1581 /**
1582  * Instances of HW to be locked.
1583  *
1584  * Note: If updating with more HW components, fields
1585  * in dmub_inbox0_cmd_lock_hw must be updated to match.
1586  */
1587 struct dmub_hw_lock_inst_flags {
1588         /**
1589          * OTG HW instance for OTG master update lock.
1590          */
1591         uint8_t otg_inst;
1592         /**
1593          * OPP instance for cursor lock.
1594          */
1595         uint8_t opp_inst;
1596         /**
1597          * OTG HW instance for global update lock.
1598          * TODO: Remove, and re-use otg_inst.
1599          */
1600         uint8_t dig_inst;
1601         /**
1602          * Explicit pad to 4 byte boundary.
1603          */
1604         uint8_t pad;
1605 };
1606
1607 /**
1608  * Clients that can acquire the HW Lock Manager.
1609  *
1610  * Note: If updating with more clients, fields in
1611  * dmub_inbox0_cmd_lock_hw must be updated to match.
1612  */
1613 enum hw_lock_client {
1614         /**
1615          * Driver is the client of HW Lock Manager.
1616          */
1617         HW_LOCK_CLIENT_DRIVER = 0,
1618         /**
1619          * Invalid client.
1620          */
1621         HW_LOCK_CLIENT_INVALID = 0xFFFFFFFF,
1622 };
1623
1624 /**
1625  * Data passed to HW Lock Mgr in a DMUB_CMD__HW_LOCK command.
1626  */
1627 struct dmub_cmd_lock_hw_data {
1628         /**
1629          * Specifies the client accessing HW Lock Manager.
1630          */
1631         enum hw_lock_client client;
1632         /**
1633          * HW instances to be locked.
1634          */
1635         struct dmub_hw_lock_inst_flags inst_flags;
1636         /**
1637          * Which components to be locked.
1638          */
1639         union dmub_hw_lock_flags hw_locks;
1640         /**
1641          * Specifies lock/unlock.
1642          */
1643         uint8_t lock;
1644         /**
1645          * HW can be unlocked separately from releasing the HW Lock Mgr.
1646          * This flag is set if the client wishes to release the object.
1647          */
1648         uint8_t should_release;
1649         /**
1650          * Explicit padding to 4 byte boundary.
1651          */
1652         uint8_t pad;
1653 };
1654
1655 /**
1656  * Definition of a DMUB_CMD__HW_LOCK command.
1657  * Command is used by driver and FW.
1658  */
1659 struct dmub_rb_cmd_lock_hw {
1660         /**
1661          * Command header.
1662          */
1663         struct dmub_cmd_header header;
1664         /**
1665          * Data passed to HW Lock Mgr in a DMUB_CMD__HW_LOCK command.
1666          */
1667         struct dmub_cmd_lock_hw_data lock_hw_data;
1668 };
1669
1670 /**
1671  * ABM command sub-types.
1672  */
1673 enum dmub_cmd_abm_type {
1674         /**
1675          * Initialize parameters for ABM algorithm.
1676          * Data is passed through an indirect buffer.
1677          */
1678         DMUB_CMD__ABM_INIT_CONFIG       = 0,
1679         /**
1680          * Set OTG and panel HW instance.
1681          */
1682         DMUB_CMD__ABM_SET_PIPE          = 1,
1683         /**
1684          * Set user requested backklight level.
1685          */
1686         DMUB_CMD__ABM_SET_BACKLIGHT     = 2,
1687         /**
1688          * Set ABM operating/aggression level.
1689          */
1690         DMUB_CMD__ABM_SET_LEVEL         = 3,
1691         /**
1692          * Set ambient light level.
1693          */
1694         DMUB_CMD__ABM_SET_AMBIENT_LEVEL = 4,
1695         /**
1696          * Enable/disable fractional duty cycle for backlight PWM.
1697          */
1698         DMUB_CMD__ABM_SET_PWM_FRAC      = 5,
1699 };
1700
1701 /**
1702  * Parameters for ABM2.4 algorithm. Passed from driver to FW via an indirect buffer.
1703  * Requirements:
1704  *  - Padded explicitly to 32-bit boundary.
1705  *  - Must ensure this structure matches the one on driver-side,
1706  *    otherwise it won't be aligned.
1707  */
1708 struct abm_config_table {
1709         /**
1710          * Gamma curve thresholds, used for crgb conversion.
1711          */
1712         uint16_t crgb_thresh[NUM_POWER_FN_SEGS];                 // 0B
1713         /**
1714          * Gamma curve offsets, used for crgb conversion.
1715          */
1716         uint16_t crgb_offset[NUM_POWER_FN_SEGS];                 // 16B
1717         /**
1718          * Gamma curve slopes, used for crgb conversion.
1719          */
1720         uint16_t crgb_slope[NUM_POWER_FN_SEGS];                  // 32B
1721         /**
1722          * Custom backlight curve thresholds.
1723          */
1724         uint16_t backlight_thresholds[NUM_BL_CURVE_SEGS];        // 48B
1725         /**
1726          * Custom backlight curve offsets.
1727          */
1728         uint16_t backlight_offsets[NUM_BL_CURVE_SEGS];           // 78B
1729         /**
1730          * Ambient light thresholds.
1731          */
1732         uint16_t ambient_thresholds_lux[NUM_AMBI_LEVEL];         // 112B
1733         /**
1734          * Minimum programmable backlight.
1735          */
1736         uint16_t min_abm_backlight;                              // 122B
1737         /**
1738          * Minimum reduction values.
1739          */
1740         uint8_t min_reduction[NUM_AMBI_LEVEL][NUM_AGGR_LEVEL];   // 124B
1741         /**
1742          * Maximum reduction values.
1743          */
1744         uint8_t max_reduction[NUM_AMBI_LEVEL][NUM_AGGR_LEVEL];   // 144B
1745         /**
1746          * Bright positive gain.
1747          */
1748         uint8_t bright_pos_gain[NUM_AMBI_LEVEL][NUM_AGGR_LEVEL]; // 164B
1749         /**
1750          * Dark negative gain.
1751          */
1752         uint8_t dark_pos_gain[NUM_AMBI_LEVEL][NUM_AGGR_LEVEL];   // 184B
1753         /**
1754          * Hybrid factor.
1755          */
1756         uint8_t hybrid_factor[NUM_AGGR_LEVEL];                   // 204B
1757         /**
1758          * Contrast factor.
1759          */
1760         uint8_t contrast_factor[NUM_AGGR_LEVEL];                 // 208B
1761         /**
1762          * Deviation gain.
1763          */
1764         uint8_t deviation_gain[NUM_AGGR_LEVEL];                  // 212B
1765         /**
1766          * Minimum knee.
1767          */
1768         uint8_t min_knee[NUM_AGGR_LEVEL];                        // 216B
1769         /**
1770          * Maximum knee.
1771          */
1772         uint8_t max_knee[NUM_AGGR_LEVEL];                        // 220B
1773         /**
1774          * Unused.
1775          */
1776         uint8_t iir_curve[NUM_AMBI_LEVEL];                       // 224B
1777         /**
1778          * Explicit padding to 4 byte boundary.
1779          */
1780         uint8_t pad3[3];                                         // 229B
1781         /**
1782          * Backlight ramp reduction.
1783          */
1784         uint16_t blRampReduction[NUM_AGGR_LEVEL];                // 232B
1785         /**
1786          * Backlight ramp start.
1787          */
1788         uint16_t blRampStart[NUM_AGGR_LEVEL];                    // 240B
1789 };
1790
1791 /**
1792  * Data passed from driver to FW in a DMUB_CMD__ABM_SET_PIPE command.
1793  */
1794 struct dmub_cmd_abm_set_pipe_data {
1795         /**
1796          * OTG HW instance.
1797          */
1798         uint8_t otg_inst;
1799
1800         /**
1801          * Panel Control HW instance.
1802          */
1803         uint8_t panel_inst;
1804
1805         /**
1806          * Controls how ABM will interpret a set pipe or set level command.
1807          */
1808         uint8_t set_pipe_option;
1809
1810         /**
1811          * Unused.
1812          * TODO: Remove.
1813          */
1814         uint8_t ramping_boundary;
1815 };
1816
1817 /**
1818  * Definition of a DMUB_CMD__ABM_SET_PIPE command.
1819  */
1820 struct dmub_rb_cmd_abm_set_pipe {
1821         /**
1822          * Command header.
1823          */
1824         struct dmub_cmd_header header;
1825
1826         /**
1827          * Data passed from driver to FW in a DMUB_CMD__ABM_SET_PIPE command.
1828          */
1829         struct dmub_cmd_abm_set_pipe_data abm_set_pipe_data;
1830 };
1831
1832 /**
1833  * Data passed from driver to FW in a DMUB_CMD__ABM_SET_BACKLIGHT command.
1834  */
1835 struct dmub_cmd_abm_set_backlight_data {
1836         /**
1837          * Number of frames to ramp to backlight user level.
1838          */
1839         uint32_t frame_ramp;
1840
1841         /**
1842          * Requested backlight level from user.
1843          */
1844         uint32_t backlight_user_level;
1845
1846         /**
1847          * ABM control version.
1848          */
1849         uint8_t version;
1850
1851         /**
1852          * Panel Control HW instance mask.
1853          * Bit 0 is Panel Control HW instance 0.
1854          * Bit 1 is Panel Control HW instance 1.
1855          */
1856         uint8_t panel_mask;
1857
1858         /**
1859          * Explicit padding to 4 byte boundary.
1860          */
1861         uint8_t pad[2];
1862 };
1863
1864 /**
1865  * Definition of a DMUB_CMD__ABM_SET_BACKLIGHT command.
1866  */
1867 struct dmub_rb_cmd_abm_set_backlight {
1868         /**
1869          * Command header.
1870          */
1871         struct dmub_cmd_header header;
1872
1873         /**
1874          * Data passed from driver to FW in a DMUB_CMD__ABM_SET_BACKLIGHT command.
1875          */
1876         struct dmub_cmd_abm_set_backlight_data abm_set_backlight_data;
1877 };
1878
1879 /**
1880  * Data passed from driver to FW in a DMUB_CMD__ABM_SET_LEVEL command.
1881  */
1882 struct dmub_cmd_abm_set_level_data {
1883         /**
1884          * Set current ABM operating/aggression level.
1885          */
1886         uint32_t level;
1887
1888         /**
1889          * ABM control version.
1890          */
1891         uint8_t version;
1892
1893         /**
1894          * Panel Control HW instance mask.
1895          * Bit 0 is Panel Control HW instance 0.
1896          * Bit 1 is Panel Control HW instance 1.
1897          */
1898         uint8_t panel_mask;
1899
1900         /**
1901          * Explicit padding to 4 byte boundary.
1902          */
1903         uint8_t pad[2];
1904 };
1905
1906 /**
1907  * Definition of a DMUB_CMD__ABM_SET_LEVEL command.
1908  */
1909 struct dmub_rb_cmd_abm_set_level {
1910         /**
1911          * Command header.
1912          */
1913         struct dmub_cmd_header header;
1914
1915         /**
1916          * Data passed from driver to FW in a DMUB_CMD__ABM_SET_LEVEL command.
1917          */
1918         struct dmub_cmd_abm_set_level_data abm_set_level_data;
1919 };
1920
1921 /**
1922  * Data passed from driver to FW in a DMUB_CMD__ABM_SET_AMBIENT_LEVEL command.
1923  */
1924 struct dmub_cmd_abm_set_ambient_level_data {
1925         /**
1926          * Ambient light sensor reading from OS.
1927          */
1928         uint32_t ambient_lux;
1929
1930         /**
1931          * ABM control version.
1932          */
1933         uint8_t version;
1934
1935         /**
1936          * Panel Control HW instance mask.
1937          * Bit 0 is Panel Control HW instance 0.
1938          * Bit 1 is Panel Control HW instance 1.
1939          */
1940         uint8_t panel_mask;
1941
1942         /**
1943          * Explicit padding to 4 byte boundary.
1944          */
1945         uint8_t pad[2];
1946 };
1947
1948 /**
1949  * Definition of a DMUB_CMD__ABM_SET_AMBIENT_LEVEL command.
1950  */
1951 struct dmub_rb_cmd_abm_set_ambient_level {
1952         /**
1953          * Command header.
1954          */
1955         struct dmub_cmd_header header;
1956
1957         /**
1958          * Data passed from driver to FW in a DMUB_CMD__ABM_SET_AMBIENT_LEVEL command.
1959          */
1960         struct dmub_cmd_abm_set_ambient_level_data abm_set_ambient_level_data;
1961 };
1962
1963 /**
1964  * Data passed from driver to FW in a DMUB_CMD__ABM_SET_PWM_FRAC command.
1965  */
1966 struct dmub_cmd_abm_set_pwm_frac_data {
1967         /**
1968          * Enable/disable fractional duty cycle for backlight PWM.
1969          * TODO: Convert to uint8_t.
1970          */
1971         uint32_t fractional_pwm;
1972
1973         /**
1974          * ABM control version.
1975          */
1976         uint8_t version;
1977
1978         /**
1979          * Panel Control HW instance mask.
1980          * Bit 0 is Panel Control HW instance 0.
1981          * Bit 1 is Panel Control HW instance 1.
1982          */
1983         uint8_t panel_mask;
1984
1985         /**
1986          * Explicit padding to 4 byte boundary.
1987          */
1988         uint8_t pad[2];
1989 };
1990
1991 /**
1992  * Definition of a DMUB_CMD__ABM_SET_PWM_FRAC command.
1993  */
1994 struct dmub_rb_cmd_abm_set_pwm_frac {
1995         /**
1996          * Command header.
1997          */
1998         struct dmub_cmd_header header;
1999
2000         /**
2001          * Data passed from driver to FW in a DMUB_CMD__ABM_SET_PWM_FRAC command.
2002          */
2003         struct dmub_cmd_abm_set_pwm_frac_data abm_set_pwm_frac_data;
2004 };
2005
2006 /**
2007  * Data passed from driver to FW in a DMUB_CMD__ABM_INIT_CONFIG command.
2008  */
2009 struct dmub_cmd_abm_init_config_data {
2010         /**
2011          * Location of indirect buffer used to pass init data to ABM.
2012          */
2013         union dmub_addr src;
2014
2015         /**
2016          * Indirect buffer length.
2017          */
2018         uint16_t bytes;
2019
2020
2021         /**
2022          * ABM control version.
2023          */
2024         uint8_t version;
2025
2026         /**
2027          * Panel Control HW instance mask.
2028          * Bit 0 is Panel Control HW instance 0.
2029          * Bit 1 is Panel Control HW instance 1.
2030          */
2031         uint8_t panel_mask;
2032
2033         /**
2034          * Explicit padding to 4 byte boundary.
2035          */
2036         uint8_t pad[2];
2037 };
2038
2039 /**
2040  * Definition of a DMUB_CMD__ABM_INIT_CONFIG command.
2041  */
2042 struct dmub_rb_cmd_abm_init_config {
2043         /**
2044          * Command header.
2045          */
2046         struct dmub_cmd_header header;
2047
2048         /**
2049          * Data passed from driver to FW in a DMUB_CMD__ABM_INIT_CONFIG command.
2050          */
2051         struct dmub_cmd_abm_init_config_data abm_init_config_data;
2052 };
2053
2054 /**
2055  * Data passed from driver to FW in a DMUB_CMD__QUERY_FEATURE_CAPS command.
2056  */
2057 struct dmub_cmd_query_feature_caps_data {
2058         /**
2059          * DMUB feature capabilities.
2060          * After DMUB init, driver will query FW capabilities prior to enabling certain features.
2061          */
2062         struct dmub_feature_caps feature_caps;
2063 };
2064
2065 /**
2066  * Definition of a DMUB_CMD__QUERY_FEATURE_CAPS command.
2067  */
2068 struct dmub_rb_cmd_query_feature_caps {
2069         /**
2070          * Command header.
2071          */
2072         struct dmub_cmd_header header;
2073         /**
2074          * Data passed from driver to FW in a DMUB_CMD__QUERY_FEATURE_CAPS command.
2075          */
2076         struct dmub_cmd_query_feature_caps_data query_feature_caps_data;
2077 };
2078
2079 struct dmub_optc_state {
2080         uint32_t v_total_max;
2081         uint32_t v_total_min;
2082         uint32_t v_total_mid;
2083         uint32_t v_total_mid_frame_num;
2084         uint32_t tg_inst;
2085         uint32_t enable_manual_trigger;
2086         uint32_t clear_force_vsync;
2087 };
2088
2089 struct dmub_rb_cmd_drr_update {
2090                 struct dmub_cmd_header header;
2091                 struct dmub_optc_state dmub_optc_state_req;
2092 };
2093
2094 #ifdef CONFIG_DRM_AMD_DC_DCN3_1
2095 /**
2096  * enum dmub_cmd_panel_cntl_type - Panel control command.
2097  */
2098 enum dmub_cmd_panel_cntl_type {
2099         /**
2100          * Initializes embedded panel hardware blocks.
2101          */
2102         DMUB_CMD__PANEL_CNTL_HW_INIT = 0,
2103         /**
2104          * Queries backlight info for the embedded panel.
2105          */
2106         DMUB_CMD__PANEL_CNTL_QUERY_BACKLIGHT_INFO = 1,
2107 };
2108
2109 /**
2110  * struct dmub_cmd_panel_cntl_data - Panel control data.
2111  */
2112 struct dmub_cmd_panel_cntl_data {
2113         uint32_t inst; /**< panel instance */
2114         uint32_t current_backlight; /* in/out */
2115         uint32_t bl_pwm_cntl; /* in/out */
2116         uint32_t bl_pwm_period_cntl; /* in/out */
2117         uint32_t bl_pwm_ref_div1; /* in/out */
2118         uint8_t is_backlight_on : 1; /* in/out */
2119         uint8_t is_powered_on : 1; /* in/out */
2120 };
2121
2122 /**
2123  * struct dmub_rb_cmd_panel_cntl - Panel control command.
2124  */
2125 struct dmub_rb_cmd_panel_cntl {
2126         struct dmub_cmd_header header; /**< header */
2127         struct dmub_cmd_panel_cntl_data data; /**< payload */
2128 };
2129 #endif
2130
2131 /**
2132  * Data passed from driver to FW in a DMUB_CMD__VBIOS_LVTMA_CONTROL command.
2133  */
2134 struct dmub_cmd_lvtma_control_data {
2135         uint8_t uc_pwr_action; /**< LVTMA_ACTION */
2136         uint8_t reserved_0[3]; /**< For future use */
2137         uint8_t panel_inst; /**< LVTMA control instance */
2138         uint8_t reserved_1[3]; /**< For future use */
2139 };
2140
2141 /**
2142  * Definition of a DMUB_CMD__VBIOS_LVTMA_CONTROL command.
2143  */
2144 struct dmub_rb_cmd_lvtma_control {
2145         /**
2146          * Command header.
2147          */
2148         struct dmub_cmd_header header;
2149         /**
2150          * Data passed from driver to FW in a DMUB_CMD__VBIOS_LVTMA_CONTROL command.
2151          */
2152         struct dmub_cmd_lvtma_control_data data;
2153 };
2154
2155 /**
2156  * union dmub_rb_cmd - DMUB inbox command.
2157  */
2158 union dmub_rb_cmd {
2159         struct dmub_rb_cmd_lock_hw lock_hw;
2160         /**
2161          * Elements shared with all commands.
2162          */
2163         struct dmub_rb_cmd_common cmd_common;
2164         /**
2165          * Definition of a DMUB_CMD__REG_SEQ_READ_MODIFY_WRITE command.
2166          */
2167         struct dmub_rb_cmd_read_modify_write read_modify_write;
2168         /**
2169          * Definition of a DMUB_CMD__REG_SEQ_FIELD_UPDATE_SEQ command.
2170          */
2171         struct dmub_rb_cmd_reg_field_update_sequence reg_field_update_seq;
2172         /**
2173          * Definition of a DMUB_CMD__REG_SEQ_BURST_WRITE command.
2174          */
2175         struct dmub_rb_cmd_burst_write burst_write;
2176         /**
2177          * Definition of a DMUB_CMD__REG_REG_WAIT command.
2178          */
2179         struct dmub_rb_cmd_reg_wait reg_wait;
2180         /**
2181          * Definition of a DMUB_CMD__VBIOS_DIGX_ENCODER_CONTROL command.
2182          */
2183         struct dmub_rb_cmd_digx_encoder_control digx_encoder_control;
2184         /**
2185          * Definition of a DMUB_CMD__VBIOS_SET_PIXEL_CLOCK command.
2186          */
2187         struct dmub_rb_cmd_set_pixel_clock set_pixel_clock;
2188         /**
2189          * Definition of a DMUB_CMD__VBIOS_ENABLE_DISP_POWER_GATING command.
2190          */
2191         struct dmub_rb_cmd_enable_disp_power_gating enable_disp_power_gating;
2192         /**
2193          * Definition of a DMUB_CMD__VBIOS_DPPHY_INIT command.
2194          */
2195         struct dmub_rb_cmd_dpphy_init dpphy_init;
2196         /**
2197          * Definition of a DMUB_CMD__VBIOS_DIG1_TRANSMITTER_CONTROL command.
2198          */
2199         struct dmub_rb_cmd_dig1_transmitter_control dig1_transmitter_control;
2200         /**
2201          * Definition of a DMUB_CMD__PSR_SET_VERSION command.
2202          */
2203         struct dmub_rb_cmd_psr_set_version psr_set_version;
2204         /**
2205          * Definition of a DMUB_CMD__PSR_COPY_SETTINGS command.
2206          */
2207         struct dmub_rb_cmd_psr_copy_settings psr_copy_settings;
2208         /**
2209          * Definition of a DMUB_CMD__PSR_ENABLE command.
2210          */
2211         struct dmub_rb_cmd_psr_enable psr_enable;
2212         /**
2213          * Definition of a DMUB_CMD__PSR_SET_LEVEL command.
2214          */
2215         struct dmub_rb_cmd_psr_set_level psr_set_level;
2216         /**
2217          * Definition of a DMUB_CMD__PSR_FORCE_STATIC command.
2218          */
2219         struct dmub_rb_cmd_psr_force_static psr_force_static;
2220         /**
2221          * Definition of a DMUB_CMD__PLAT_54186_WA command.
2222          */
2223         struct dmub_rb_cmd_PLAT_54186_wa PLAT_54186_wa;
2224         /**
2225          * Definition of a DMUB_CMD__MALL command.
2226          */
2227         struct dmub_rb_cmd_mall mall;
2228 #ifdef CONFIG_DRM_AMD_DC_DCN3_1
2229         /**
2230          * Definition of a DMUB_CMD__IDLE_OPT_DCN_RESTORE command.
2231          */
2232         struct dmub_rb_cmd_idle_opt_dcn_restore dcn_restore;
2233
2234         /**
2235          * Definition of a DMUB_CMD__CLK_MGR_NOTIFY_CLOCKS command.
2236          */
2237         struct dmub_rb_cmd_clk_mgr_notify_clocks notify_clocks;
2238
2239         /**
2240          * Definition of DMUB_CMD__PANEL_CNTL commands.
2241          */
2242         struct dmub_rb_cmd_panel_cntl panel_cntl;
2243 #endif
2244         /**
2245          * Definition of a DMUB_CMD__ABM_SET_PIPE command.
2246          */
2247         struct dmub_rb_cmd_abm_set_pipe abm_set_pipe;
2248
2249         /**
2250          * Definition of a DMUB_CMD__ABM_SET_BACKLIGHT command.
2251          */
2252         struct dmub_rb_cmd_abm_set_backlight abm_set_backlight;
2253
2254         /**
2255          * Definition of a DMUB_CMD__ABM_SET_LEVEL command.
2256          */
2257         struct dmub_rb_cmd_abm_set_level abm_set_level;
2258
2259         /**
2260          * Definition of a DMUB_CMD__ABM_SET_AMBIENT_LEVEL command.
2261          */
2262         struct dmub_rb_cmd_abm_set_ambient_level abm_set_ambient_level;
2263
2264         /**
2265          * Definition of a DMUB_CMD__ABM_SET_PWM_FRAC command.
2266          */
2267         struct dmub_rb_cmd_abm_set_pwm_frac abm_set_pwm_frac;
2268
2269         /**
2270          * Definition of a DMUB_CMD__ABM_INIT_CONFIG command.
2271          */
2272         struct dmub_rb_cmd_abm_init_config abm_init_config;
2273
2274         /**
2275          * Definition of a DMUB_CMD__DP_AUX_ACCESS command.
2276          */
2277         struct dmub_rb_cmd_dp_aux_access dp_aux_access;
2278
2279         /**
2280          * Definition of a DMUB_CMD__OUTBOX1_ENABLE command.
2281          */
2282         struct dmub_rb_cmd_outbox1_enable outbox1_enable;
2283
2284         /**
2285          * Definition of a DMUB_CMD__QUERY_FEATURE_CAPS command.
2286          */
2287         struct dmub_rb_cmd_query_feature_caps query_feature_caps;
2288         struct dmub_rb_cmd_drr_update drr_update;
2289         /**
2290          * Definition of a DMUB_CMD__VBIOS_LVTMA_CONTROL command.
2291          */
2292         struct dmub_rb_cmd_lvtma_control lvtma_control;
2293 };
2294
2295 /**
2296  * union dmub_rb_out_cmd - Outbox command
2297  */
2298 union dmub_rb_out_cmd {
2299         /**
2300          * Parameters common to every command.
2301          */
2302         struct dmub_rb_cmd_common cmd_common;
2303         /**
2304          * AUX reply command.
2305          */
2306         struct dmub_rb_cmd_dp_aux_reply dp_aux_reply;
2307         /**
2308          * HPD notify command.
2309          */
2310         struct dmub_rb_cmd_dp_hpd_notify dp_hpd_notify;
2311 };
2312 #pragma pack(pop)
2313
2314
2315 //==============================================================================
2316 //</DMUB_CMD>===================================================================
2317 //==============================================================================
2318 //< DMUB_RB>====================================================================
2319 //==============================================================================
2320
2321 #if defined(__cplusplus)
2322 extern "C" {
2323 #endif
2324
2325 /**
2326  * struct dmub_rb_init_params - Initialization params for DMUB ringbuffer
2327  */
2328 struct dmub_rb_init_params {
2329         void *ctx; /**< Caller provided context pointer */
2330         void *base_address; /**< CPU base address for ring's data */
2331         uint32_t capacity; /**< Ringbuffer capacity in bytes */
2332         uint32_t read_ptr; /**< Initial read pointer for consumer in bytes */
2333         uint32_t write_ptr; /**< Initial write pointer for producer in bytes */
2334 };
2335
2336 /**
2337  * struct dmub_rb - Inbox or outbox DMUB ringbuffer
2338  */
2339 struct dmub_rb {
2340         void *base_address; /**< CPU address for the ring's data */
2341         uint32_t rptr; /**< Read pointer for consumer in bytes */
2342         uint32_t wrpt; /**< Write pointer for producer in bytes */
2343         uint32_t capacity; /**< Ringbuffer capacity in bytes */
2344
2345         void *ctx; /**< Caller provided context pointer */
2346         void *dmub; /**< Pointer to the DMUB interface */
2347 };
2348
2349 /**
2350  * @brief Checks if the ringbuffer is empty.
2351  *
2352  * @param rb DMUB Ringbuffer
2353  * @return true if empty
2354  * @return false otherwise
2355  */
2356 static inline bool dmub_rb_empty(struct dmub_rb *rb)
2357 {
2358         return (rb->wrpt == rb->rptr);
2359 }
2360
2361 /**
2362  * @brief Checks if the ringbuffer is full
2363  *
2364  * @param rb DMUB Ringbuffer
2365  * @return true if full
2366  * @return false otherwise
2367  */
2368 static inline bool dmub_rb_full(struct dmub_rb *rb)
2369 {
2370         uint32_t data_count;
2371
2372         if (rb->wrpt >= rb->rptr)
2373                 data_count = rb->wrpt - rb->rptr;
2374         else
2375                 data_count = rb->capacity - (rb->rptr - rb->wrpt);
2376
2377         return (data_count == (rb->capacity - DMUB_RB_CMD_SIZE));
2378 }
2379
2380 /**
2381  * @brief Pushes a command into the ringbuffer
2382  *
2383  * @param rb DMUB ringbuffer
2384  * @param cmd The command to push
2385  * @return true if the ringbuffer was not full
2386  * @return false otherwise
2387  */
2388 static inline bool dmub_rb_push_front(struct dmub_rb *rb,
2389                                       const union dmub_rb_cmd *cmd)
2390 {
2391         uint64_t volatile *dst = (uint64_t volatile *)(rb->base_address) + rb->wrpt / sizeof(uint64_t);
2392         const uint64_t *src = (const uint64_t *)cmd;
2393         uint8_t i;
2394
2395         if (dmub_rb_full(rb))
2396                 return false;
2397
2398         // copying data
2399         for (i = 0; i < DMUB_RB_CMD_SIZE / sizeof(uint64_t); i++)
2400                 *dst++ = *src++;
2401
2402         rb->wrpt += DMUB_RB_CMD_SIZE;
2403
2404         if (rb->wrpt >= rb->capacity)
2405                 rb->wrpt %= rb->capacity;
2406
2407         return true;
2408 }
2409
2410 /**
2411  * @brief Pushes a command into the DMUB outbox ringbuffer
2412  *
2413  * @param rb DMUB outbox ringbuffer
2414  * @param cmd Outbox command
2415  * @return true if not full
2416  * @return false otherwise
2417  */
2418 static inline bool dmub_rb_out_push_front(struct dmub_rb *rb,
2419                                       const union dmub_rb_out_cmd *cmd)
2420 {
2421         uint8_t *dst = (uint8_t *)(rb->base_address) + rb->wrpt;
2422         const uint8_t *src = (uint8_t *)cmd;
2423
2424         if (dmub_rb_full(rb))
2425                 return false;
2426
2427         dmub_memcpy(dst, src, DMUB_RB_CMD_SIZE);
2428
2429         rb->wrpt += DMUB_RB_CMD_SIZE;
2430
2431         if (rb->wrpt >= rb->capacity)
2432                 rb->wrpt %= rb->capacity;
2433
2434         return true;
2435 }
2436
2437 /**
2438  * @brief Returns the next unprocessed command in the ringbuffer.
2439  *
2440  * @param rb DMUB ringbuffer
2441  * @param cmd The command to return
2442  * @return true if not empty
2443  * @return false otherwise
2444  */
2445 static inline bool dmub_rb_front(struct dmub_rb *rb,
2446                                  union dmub_rb_cmd  **cmd)
2447 {
2448         uint8_t *rb_cmd = (uint8_t *)(rb->base_address) + rb->rptr;
2449
2450         if (dmub_rb_empty(rb))
2451                 return false;
2452
2453         *cmd = (union dmub_rb_cmd *)rb_cmd;
2454
2455         return true;
2456 }
2457
2458 /**
2459  * @brief Determines the next ringbuffer offset.
2460  *
2461  * @param rb DMUB inbox ringbuffer
2462  * @param num_cmds Number of commands
2463  * @param next_rptr The next offset in the ringbuffer
2464  */
2465 static inline void dmub_rb_get_rptr_with_offset(struct dmub_rb *rb,
2466                                   uint32_t num_cmds,
2467                                   uint32_t *next_rptr)
2468 {
2469         *next_rptr = rb->rptr + DMUB_RB_CMD_SIZE * num_cmds;
2470
2471         if (*next_rptr >= rb->capacity)
2472                 *next_rptr %= rb->capacity;
2473 }
2474
2475 /**
2476  * @brief Returns a pointer to a command in the inbox.
2477  *
2478  * @param rb DMUB inbox ringbuffer
2479  * @param cmd The inbox command to return
2480  * @param rptr The ringbuffer offset
2481  * @return true if not empty
2482  * @return false otherwise
2483  */
2484 static inline bool dmub_rb_peek_offset(struct dmub_rb *rb,
2485                                  union dmub_rb_cmd  **cmd,
2486                                  uint32_t rptr)
2487 {
2488         uint8_t *rb_cmd = (uint8_t *)(rb->base_address) + rptr;
2489
2490         if (dmub_rb_empty(rb))
2491                 return false;
2492
2493         *cmd = (union dmub_rb_cmd *)rb_cmd;
2494
2495         return true;
2496 }
2497
2498 /**
2499  * @brief Returns the next unprocessed command in the outbox.
2500  *
2501  * @param rb DMUB outbox ringbuffer
2502  * @param cmd The outbox command to return
2503  * @return true if not empty
2504  * @return false otherwise
2505  */
2506 static inline bool dmub_rb_out_front(struct dmub_rb *rb,
2507                                  union dmub_rb_out_cmd  *cmd)
2508 {
2509         const uint64_t volatile *src = (const uint64_t volatile *)(rb->base_address) + rb->rptr / sizeof(uint64_t);
2510         uint64_t *dst = (uint64_t *)cmd;
2511         uint8_t i;
2512
2513         if (dmub_rb_empty(rb))
2514                 return false;
2515
2516         // copying data
2517         for (i = 0; i < DMUB_RB_CMD_SIZE / sizeof(uint64_t); i++)
2518                 *dst++ = *src++;
2519
2520         return true;
2521 }
2522
2523 /**
2524  * @brief Removes the front entry in the ringbuffer.
2525  *
2526  * @param rb DMUB ringbuffer
2527  * @return true if the command was removed
2528  * @return false if there were no commands
2529  */
2530 static inline bool dmub_rb_pop_front(struct dmub_rb *rb)
2531 {
2532         if (dmub_rb_empty(rb))
2533                 return false;
2534
2535         rb->rptr += DMUB_RB_CMD_SIZE;
2536
2537         if (rb->rptr >= rb->capacity)
2538                 rb->rptr %= rb->capacity;
2539
2540         return true;
2541 }
2542
2543 /**
2544  * @brief Flushes commands in the ringbuffer to framebuffer memory.
2545  *
2546  * Avoids a race condition where DMCUB accesses memory while
2547  * there are still writes in flight to framebuffer.
2548  *
2549  * @param rb DMUB ringbuffer
2550  */
2551 static inline void dmub_rb_flush_pending(const struct dmub_rb *rb)
2552 {
2553         uint32_t rptr = rb->rptr;
2554         uint32_t wptr = rb->wrpt;
2555
2556         while (rptr != wptr) {
2557                 uint64_t volatile *data = (uint64_t volatile *)rb->base_address + rptr / sizeof(uint64_t);
2558                 uint8_t i;
2559
2560                 for (i = 0; i < DMUB_RB_CMD_SIZE / sizeof(uint64_t); i++)
2561                         *data++;
2562
2563                 rptr += DMUB_RB_CMD_SIZE;
2564                 if (rptr >= rb->capacity)
2565                         rptr %= rb->capacity;
2566         }
2567 }
2568
2569 /**
2570  * @brief Initializes a DMCUB ringbuffer
2571  *
2572  * @param rb DMUB ringbuffer
2573  * @param init_params initial configuration for the ringbuffer
2574  */
2575 static inline void dmub_rb_init(struct dmub_rb *rb,
2576                                 struct dmub_rb_init_params *init_params)
2577 {
2578         rb->base_address = init_params->base_address;
2579         rb->capacity = init_params->capacity;
2580         rb->rptr = init_params->read_ptr;
2581         rb->wrpt = init_params->write_ptr;
2582 }
2583
2584 /**
2585  * @brief Copies output data from in/out commands into the given command.
2586  *
2587  * @param rb DMUB ringbuffer
2588  * @param cmd Command to copy data into
2589  */
2590 static inline void dmub_rb_get_return_data(struct dmub_rb *rb,
2591                                            union dmub_rb_cmd *cmd)
2592 {
2593         // Copy rb entry back into command
2594         uint8_t *rd_ptr = (rb->rptr == 0) ?
2595                 (uint8_t *)rb->base_address + rb->capacity - DMUB_RB_CMD_SIZE :
2596                 (uint8_t *)rb->base_address + rb->rptr - DMUB_RB_CMD_SIZE;
2597
2598         dmub_memcpy(cmd, rd_ptr, DMUB_RB_CMD_SIZE);
2599 }
2600
2601 #if defined(__cplusplus)
2602 }
2603 #endif
2604
2605 //==============================================================================
2606 //</DMUB_RB>====================================================================
2607 //==============================================================================
2608
2609 #endif /* _DMUB_CMD_H_ */