dmub_cmd.h 74.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/*
 * Copyright 2019 Advanced Micro Devices, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 * Authors: AMD
 *
 */

26 27
#ifndef DMUB_CMD_H
#define DMUB_CMD_H
28

29 30 31 32 33 34 35 36 37
#if defined(_TEST_HARNESS) || defined(FPGA_USB4)
#include "dmub_fw_types.h"
#include "include_legacy/atomfirmware.h"

#if defined(_TEST_HARNESS)
#include <string.h>
#endif
#else

38 39 40 41 42
#include <asm/byteorder.h>
#include <linux/types.h>
#include <linux/string.h>
#include <linux/delay.h>

43
#include "atomfirmware.h"
44

45 46
#endif // defined(_TEST_HARNESS) || defined(FPGA_USB4)

47 48
/* Firmware versioning. */
#ifdef DMUB_EXPOSE_VERSION
49
#define DMUB_FW_VERSION_GIT_HASH 0x1422ef84
50
#define DMUB_FW_VERSION_MAJOR 0
51
#define DMUB_FW_VERSION_MINOR 0
52
#define DMUB_FW_VERSION_REVISION 104
53 54 55 56 57 58 59 60 61 62
#define DMUB_FW_VERSION_TEST 0
#define DMUB_FW_VERSION_VBIOS 0
#define DMUB_FW_VERSION_HOTFIX 0
#define DMUB_FW_VERSION_UCODE (((DMUB_FW_VERSION_MAJOR & 0xFF) << 24) | \
		((DMUB_FW_VERSION_MINOR & 0xFF) << 16) | \
		((DMUB_FW_VERSION_REVISION & 0xFF) << 8) | \
		((DMUB_FW_VERSION_TEST & 0x1) << 7) | \
		((DMUB_FW_VERSION_VBIOS & 0x1) << 6) | \
		(DMUB_FW_VERSION_HOTFIX & 0x3F))

63
#endif
64 65 66

//<DMUB_TYPES>==================================================================
/* Basic type definitions. */
67

68 69
#define __forceinline inline

70 71 72 73
/**
 * Flag from driver to indicate that ABM should be disabled gradually
 * by slowly reversing all backlight programming and pixel compensation.
 */
74
#define SET_ABM_PIPE_GRADUALLY_DISABLE           0
75 76 77 78 79

/**
 * Flag from driver to indicate that ABM should be disabled immediately
 * and undo all backlight programming and pixel compensation.
 */
80
#define SET_ABM_PIPE_IMMEDIATELY_DISABLE         255
81 82 83 84 85

/**
 * Flag from driver to indicate that ABM should be disabled immediately
 * and keep the current backlight programming and pixel compensation.
 */
86
#define SET_ABM_PIPE_IMMEDIATE_KEEP_GAIN_DISABLE 254
87 88 89 90

/**
 * Flag from driver to set the current ABM pipe index or ABM operating level.
 */
91
#define SET_ABM_PIPE_NORMAL                      1
92

93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
/**
 * Number of ambient light levels in ABM algorithm.
 */
#define NUM_AMBI_LEVEL                  5

/**
 * Number of operating/aggression levels in ABM algorithm.
 */
#define NUM_AGGR_LEVEL                  4

/**
 * Number of segments in the gamma curve.
 */
#define NUM_POWER_FN_SEGS               8

/**
 * Number of segments in the backlight curve.
 */
#define NUM_BL_CURVE_SEGS               16

113 114 115 116 117 118
/* Maximum number of streams on any ASIC. */
#define DMUB_MAX_STREAMS 6

/* Maximum number of planes on any ASIC. */
#define DMUB_MAX_PLANES 6

119 120 121
/* Trace buffer offset for entry */
#define TRACE_BUFFER_ENTRY_OFFSET  16

122 123 124 125 126 127 128 129 130 131 132
/**
 *
 * PSR control version legacy
 */
#define DMUB_CMD_PSR_CONTROL_VERSION_UNKNOWN 0x0
/**
 * PSR control version with multi edp support
 */
#define DMUB_CMD_PSR_CONTROL_VERSION_1 0x1


133
/**
134
 * ABM control version legacy
135
 */
136
#define DMUB_CMD_ABM_CONTROL_VERSION_UNKNOWN 0x0
137 138

/**
139
 * ABM control version with multi edp support
140
 */
141
#define DMUB_CMD_ABM_CONTROL_VERSION_1 0x1
142

143 144 145
/**
 * Physical framebuffer address location, 64-bit.
 */
146 147 148 149
#ifndef PHYSICAL_ADDRESS_LOC
#define PHYSICAL_ADDRESS_LOC union large_integer
#endif

150 151 152
/**
 * OS/FW agnostic memcpy
 */
153 154 155 156
#ifndef dmub_memcpy
#define dmub_memcpy(dest, source, bytes) memcpy((dest), (source), (bytes))
#endif

157 158 159
/**
 * OS/FW agnostic memset
 */
160 161 162 163
#ifndef dmub_memset
#define dmub_memset(dest, val, bytes) memset((dest), (val), (bytes))
#endif

164 165 166 167
#if defined(__cplusplus)
extern "C" {
#endif

168 169 170
/**
 * OS/FW agnostic udelay
 */
171 172 173 174
#ifndef dmub_udelay
#define dmub_udelay(microseconds) udelay(microseconds)
#endif

175 176 177
/**
 * union dmub_addr - DMUB physical/virtual 64-bit address.
 */
178 179
union dmub_addr {
	struct {
180 181 182 183
		uint32_t low_part; /**< Lower 32 bits */
		uint32_t high_part; /**< Upper 32 bits */
	} u; /*<< Low/high bit access */
	uint64_t quad_part; /*<< 64 bit address */
184 185
};

186 187 188
/**
 * Flags that can be set by driver to change some PSR behaviour.
 */
189
union dmub_psr_debug_flags {
190 191 192
	/**
	 * Debug flags.
	 */
193
	struct {
194 195 196
		/**
		 * Enable visual confirm in FW.
		 */
197
		uint32_t visual_confirm : 1;
198 199 200
		/**
		 * Use HW Lock Mgr object to do HW locking in FW.
		 */
201
		uint32_t use_hw_lock_mgr : 1;
202 203

		/**
204
		 * Use TPS3 signal when restore main link.
205
		 */
206
		uint32_t force_wakeup_by_tps3 : 1;
207 208
	} bitfields;

209 210 211
	/**
	 * Union for debug flags.
	 */
212
	uint32_t u32All;
213 214
};

215 216 217 218
/**
 * DMUB feature capabilities.
 * After DMUB init, driver will query FW capabilities prior to enabling certain features.
 */
219
struct dmub_feature_caps {
220 221 222
	/**
	 * Max PSR version supported by FW.
	 */
223 224 225 226
	uint8_t psr;
	uint8_t reserved[7];
};

227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
#if defined(__cplusplus)
}
#endif

//==============================================================================
//</DMUB_TYPES>=================================================================
//==============================================================================
//< DMUB_META>==================================================================
//==============================================================================
#pragma pack(push, 1)

/* Magic value for identifying dmub_fw_meta_info */
#define DMUB_FW_META_MAGIC 0x444D5542

/* Offset from the end of the file to the dmub_fw_meta_info */
#define DMUB_FW_META_OFFSET 0x24

/**
 * struct dmub_fw_meta_info - metadata associated with fw binary
 *
 * NOTE: This should be considered a stable API. Fields should
 *       not be repurposed or reordered. New fields should be
 *       added instead to extend the structure.
 *
 * @magic_value: magic value identifying DMUB firmware meta info
 * @fw_region_size: size of the firmware state region
 * @trace_buffer_size: size of the tracebuffer region
 * @fw_version: the firmware version information
255
 * @dal_fw: 1 if the firmware is DAL
256 257
 */
struct dmub_fw_meta_info {
258 259 260 261 262 263
	uint32_t magic_value; /**< magic value identifying DMUB firmware meta info */
	uint32_t fw_region_size; /**< size of the firmware state region */
	uint32_t trace_buffer_size; /**< size of the tracebuffer region */
	uint32_t fw_version; /**< the firmware version information */
	uint8_t dal_fw; /**< 1 if the firmware is DAL */
	uint8_t reserved[3]; /**< padding bits */
264 265
};

266 267 268
/**
 * union dmub_fw_meta - ensures that dmub_fw_meta_info remains 64 bytes
 */
269
union dmub_fw_meta {
270 271
	struct dmub_fw_meta_info info; /**< metadata info */
	uint8_t reserved[64]; /**< padding bits */
272 273 274
};

#pragma pack(pop)
275

276 277 278
//==============================================================================
//< DMUB Trace Buffer>================================================================
//==============================================================================
279 280 281
/**
 * dmub_trace_code_t - firmware trace code, 32-bits
 */
282 283
typedef uint32_t dmub_trace_code_t;

284 285 286
/**
 * struct dmcub_trace_buf_entry - Firmware trace entry
 */
287
struct dmcub_trace_buf_entry {
288 289 290 291
	dmub_trace_code_t trace_code; /**< trace code for the event */
	uint32_t tick_count; /**< the tick count at time of trace */
	uint32_t param0; /**< trace defined parameter 0 */
	uint32_t param1; /**< trace defined parameter 1 */
292 293
};

294 295 296 297 298 299 300 301
//==============================================================================
//< DMUB_STATUS>================================================================
//==============================================================================

/**
 * DMCUB scratch registers can be used to determine firmware status.
 * Current scratch register usage is as follows:
 *
302
 * SCRATCH0: FW Boot Status register
303
 * SCRATCH5: LVTMA Status Register
304
 * SCRATCH15: FW Boot Options register
305 306
 */

307 308 309
/**
 * union dmub_fw_boot_status - Status bit definitions for SCRATCH0.
 */
310 311
union dmub_fw_boot_status {
	struct {
312 313 314 315
		uint32_t dal_fw : 1; /**< 1 if DAL FW */
		uint32_t mailbox_rdy : 1; /**< 1 if mailbox ready */
		uint32_t optimized_init_done : 1; /**< 1 if optimized init done */
		uint32_t restore_required : 1; /**< 1 if driver should call restore */
316 317 318 319
		uint32_t defer_load : 1; /**< 1 if VBIOS data is deferred programmed */
		uint32_t reserved : 1;
		uint32_t detection_required: 1; /**<  if detection need to be triggered by driver */

320 321
	} bits; /**< status bits */
	uint32_t all; /**< 32-bit access to status bits */
322 323
};

324 325 326
/**
 * enum dmub_fw_boot_status_bit - Enum bit definitions for SCRATCH0.
 */
327
enum dmub_fw_boot_status_bit {
328 329 330 331
	DMUB_FW_BOOT_STATUS_BIT_DAL_FIRMWARE = (1 << 0), /**< 1 if DAL FW */
	DMUB_FW_BOOT_STATUS_BIT_MAILBOX_READY = (1 << 1), /**< 1 if mailbox ready */
	DMUB_FW_BOOT_STATUS_BIT_OPTIMIZED_INIT_DONE = (1 << 2), /**< 1 if init done */
	DMUB_FW_BOOT_STATUS_BIT_RESTORE_REQUIRED = (1 << 3), /**< 1 if driver should call restore */
332
	DMUB_FW_BOOT_STATUS_BIT_DEFERRED_LOADED = (1 << 4), /**< 1 if VBIOS data is deferred programmed */
333
	DMUB_FW_BOOT_STATUS_BIT_DETECTION_REQUIRED = (1 << 6), /**< 1 if detection need to be triggered by driver*/
334 335
};

336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
/* Register bit definition for SCRATCH5 */
union dmub_lvtma_status {
	struct {
		uint32_t psp_ok : 1;
		uint32_t edp_on : 1;
		uint32_t reserved : 30;
	} bits;
	uint32_t all;
};

enum dmub_lvtma_status_bit {
	DMUB_LVTMA_STATUS_BIT_PSP_OK = (1 << 0),
	DMUB_LVTMA_STATUS_BIT_EDP_ON = (1 << 1),
};

351
/**
352
 * union dmub_fw_boot_options - Boot option definitions for SCRATCH14
353
 */
354 355
union dmub_fw_boot_options {
	struct {
356 357 358 359 360 361
		uint32_t pemu_env : 1; /**< 1 if PEMU */
		uint32_t fpga_env : 1; /**< 1 if FPGA */
		uint32_t optimized_init : 1; /**< 1 if optimized init */
		uint32_t skip_phy_access : 1; /**< 1 if PHY access should be skipped */
		uint32_t disable_clk_gate: 1; /**< 1 if clock gating should be disabled */
		uint32_t skip_phy_init_panel_sequence: 1; /**< 1 to skip panel init seq */
362
		uint32_t z10_disable: 1; /**< 1 to disable z10 */
363
		uint32_t enable_dpia: 1; /**< 1 if DPIA should be enabled */
364
		uint32_t invalid_vbios_data: 1; /**< 1 if VBIOS data table is invalid */
365 366 367 368
		uint32_t dpia_supported: 1; /**< 1 if DPIA is supported on this platform */
		uint32_t sel_mux_phy_c_d_phy_f_g: 1; /**< 1 if PHYF/PHYG should be enabled */
		/**< 1 if all root clock gating is enabled and low power memory is enabled*/
		uint32_t power_optimization: 1;
369
		uint32_t diag_env: 1; /* 1 if diagnostic environment */
370
		uint32_t gpint_scratch8: 1; /* 1 if GPINT is in scratch8*/
371

372
		uint32_t reserved : 18; /**< reserved */
373 374
	} bits; /**< boot bits */
	uint32_t all; /**< 32-bit access to bits */
375 376 377
};

enum dmub_fw_boot_options_bit {
378 379 380
	DMUB_FW_BOOT_OPTION_BIT_PEMU_ENV = (1 << 0), /**< 1 if PEMU */
	DMUB_FW_BOOT_OPTION_BIT_FPGA_ENV = (1 << 1), /**< 1 if FPGA */
	DMUB_FW_BOOT_OPTION_BIT_OPTIMIZED_INIT_DONE = (1 << 2), /**< 1 if optimized init done */
381 382
};

383
//==============================================================================
384
//</DMUB_STATUS>================================================================
385 386 387 388 389
//==============================================================================
//< DMUB_VBIOS>=================================================================
//==============================================================================

/*
390 391
 * enum dmub_cmd_vbios_type - VBIOS commands.
 *
392 393 394 395
 * Command IDs should be treated as stable ABI.
 * Do not reuse or modify IDs.
 */
enum dmub_cmd_vbios_type {
396 397 398
	/**
	 * Configures the DIG encoder.
	 */
399
	DMUB_CMD__VBIOS_DIGX_ENCODER_CONTROL = 0,
400 401 402
	/**
	 * Controls the PHY.
	 */
403
	DMUB_CMD__VBIOS_DIG1_TRANSMITTER_CONTROL = 1,
404 405 406
	/**
	 * Sets the pixel clock/symbol clock.
	 */
407
	DMUB_CMD__VBIOS_SET_PIXEL_CLOCK = 2,
408 409 410
	/**
	 * Enables or disables power gating.
	 */
411
	DMUB_CMD__VBIOS_ENABLE_DISP_POWER_GATING = 3,
412 413 414
	/**
	 * Controls embedded panels.
	 */
415
	DMUB_CMD__VBIOS_LVTMA_CONTROL = 15,
416 417 418 419
	/**
	 * Query DP alt status on a transmitter.
	 */
	DMUB_CMD__VBIOS_TRANSMITTER_QUERY_DP_ALT  = 26,
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445
};

//==============================================================================
//</DMUB_VBIOS>=================================================================
//==============================================================================
//< DMUB_GPINT>=================================================================
//==============================================================================

/**
 * The shifts and masks below may alternatively be used to format and read
 * the command register bits.
 */

#define DMUB_GPINT_DATA_PARAM_MASK 0xFFFF
#define DMUB_GPINT_DATA_PARAM_SHIFT 0

#define DMUB_GPINT_DATA_COMMAND_CODE_MASK 0xFFF
#define DMUB_GPINT_DATA_COMMAND_CODE_SHIFT 16

#define DMUB_GPINT_DATA_STATUS_MASK 0xF
#define DMUB_GPINT_DATA_STATUS_SHIFT 28

/**
 * Command responses.
 */

446 447 448
/**
 * Return response for DMUB_GPINT__STOP_FW command.
 */
449 450 451
#define DMUB_GPINT__STOP_FW_RESPONSE 0xDEADDEAD

/**
452
 * union dmub_gpint_data_register - Format for sending a command via the GPINT.
453 454 455
 */
union dmub_gpint_data_register {
	struct {
456 457 458 459 460
		uint32_t param : 16; /**< 16-bit parameter */
		uint32_t command_code : 12; /**< GPINT command */
		uint32_t status : 4; /**< Command status bit */
	} bits; /**< GPINT bit access */
	uint32_t all; /**< GPINT  32-bit access */
461 462 463
};

/*
464 465
 * enum dmub_gpint_command - GPINT command to DMCUB FW
 *
466 467 468 469
 * Command IDs should be treated as stable ABI.
 * Do not reuse or modify IDs.
 */
enum dmub_gpint_command {
470 471 472
	/**
	 * Invalid command, ignored.
	 */
473
	DMUB_GPINT__INVALID_COMMAND = 0,
474 475 476 477
	/**
	 * DESC: Queries the firmware version.
	 * RETURN: Firmware version.
	 */
478
	DMUB_GPINT__GET_FW_VERSION = 1,
479 480 481 482
	/**
	 * DESC: Halts the firmware.
	 * RETURN: DMUB_GPINT__STOP_FW_RESPONSE (0xDEADDEAD) when halted
	 */
483
	DMUB_GPINT__STOP_FW = 2,
484 485 486 487
	/**
	 * DESC: Get PSR state from FW.
	 * RETURN: PSR state enum. This enum may need to be converted to the legacy PSR state value.
	 */
488
	DMUB_GPINT__GET_PSR_STATE = 7,
489 490 491 492 493
	/**
	 * DESC: Notifies DMCUB of the currently active streams.
	 * ARGS: Stream mask, 1 bit per active stream index.
	 */
	DMUB_GPINT__IDLE_OPT_NOTIFY_STREAM_MASK = 8,
494 495 496 497 498 499
	/**
	 * DESC: Start PSR residency counter. Stop PSR resdiency counter and get value.
	 * ARGS: We can measure residency from various points. The argument will specify the residency mode.
	 *       By default, it is measured from after we powerdown the PHY, to just before we powerup the PHY.
	 * RETURN: PSR residency in milli-percent.
	 */
500
	DMUB_GPINT__PSR_RESIDENCY = 9,
501 502 503 504 505

	/**
	 * DESC: Notifies DMCUB detection is done so detection required can be cleared.
	 */
	DMUB_GPINT__NOTIFY_DETECTION_DONE = 12,
506 507
};

508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526
/**
 * INBOX0 generic command definition
 */
union dmub_inbox0_cmd_common {
	struct {
		uint32_t command_code: 8; /**< INBOX0 command code */
		uint32_t param: 24; /**< 24-bit parameter */
	} bits;
	uint32_t all;
};

/**
 * INBOX0 hw_lock command definition
 */
union dmub_inbox0_cmd_lock_hw {
	struct {
		uint32_t command_code: 8;

		/* NOTE: Must be have enough bits to match: enum hw_lock_client */
527
		uint32_t hw_lock_client: 2;
528 529 530 531 532 533 534 535 536 537 538 539 540 541

		/* NOTE: Below fields must match with: struct dmub_hw_lock_inst_flags */
		uint32_t otg_inst: 3;
		uint32_t opp_inst: 3;
		uint32_t dig_inst: 3;

		/* NOTE: Below fields must match with: union dmub_hw_lock_flags */
		uint32_t lock_pipe: 1;
		uint32_t lock_cursor: 1;
		uint32_t lock_dig: 1;
		uint32_t triple_buffer_lock: 1;

		uint32_t lock: 1;				/**< Lock */
		uint32_t should_release: 1;		/**< Release */
542
		uint32_t reserved: 7; 			/**< Reserved for extending more clients, HW, etc. */
543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562
	} bits;
	uint32_t all;
};

union dmub_inbox0_data_register {
	union dmub_inbox0_cmd_common inbox0_cmd_common;
	union dmub_inbox0_cmd_lock_hw inbox0_cmd_lock_hw;
};

enum dmub_inbox0_command {
	/**
	 * DESC: Invalid command, ignored.
	 */
	DMUB_INBOX0_CMD__INVALID_COMMAND = 0,
	/**
	 * DESC: Notification to acquire/release HW lock
	 * ARGS:
	 */
	DMUB_INBOX0_CMD__HW_LOCK = 1,
};
563 564 565 566 567 568
//==============================================================================
//</DMUB_GPINT>=================================================================
//==============================================================================
//< DMUB_CMD>===================================================================
//==============================================================================

569 570 571
/**
 * Size in bytes of each DMUB command.
 */
572
#define DMUB_RB_CMD_SIZE 64
573 574 575 576

/**
 * Maximum number of items in the DMUB ringbuffer.
 */
577
#define DMUB_RB_MAX_ENTRY 128
578 579 580 581

/**
 * Ringbuffer size in bytes.
 */
582
#define DMUB_RB_SIZE (DMUB_RB_CMD_SIZE * DMUB_RB_MAX_ENTRY)
583 584 585 586

/**
 * REG_SET mask for reg offload.
 */
587 588
#define REG_SET_MASK 0xFFFF

589
/*
590 591
 * enum dmub_cmd_type - DMUB inbox command.
 *
592 593 594 595
 * Command IDs should be treated as stable ABI.
 * Do not reuse or modify IDs.
 */
enum dmub_cmd_type {
596 597 598
	/**
	 * Invalid command.
	 */
599
	DMUB_CMD__NULL = 0,
600 601 602
	/**
	 * Read modify write register sequence offload.
	 */
603
	DMUB_CMD__REG_SEQ_READ_MODIFY_WRITE = 1,
604 605 606
	/**
	 * Field update register sequence offload.
	 */
607
	DMUB_CMD__REG_SEQ_FIELD_UPDATE_SEQ = 2,
608 609 610
	/**
	 * Burst write sequence offload.
	 */
611
	DMUB_CMD__REG_SEQ_BURST_WRITE = 3,
612 613 614
	/**
	 * Reg wait sequence offload.
	 */
615
	DMUB_CMD__REG_REG_WAIT = 4,
616 617 618
	/**
	 * Workaround to avoid HUBP underflow during NV12 playback.
	 */
619
	DMUB_CMD__PLAT_54186_WA = 5,
620 621 622
	/**
	 * Command type used to query FW feature caps.
	 */
623
	DMUB_CMD__QUERY_FEATURE_CAPS = 6,
624 625 626
	/**
	 * Command type used for all PSR commands.
	 */
627
	DMUB_CMD__PSR = 64,
628 629 630
	/**
	 * Command type used for all MALL commands.
	 */
631
	DMUB_CMD__MALL = 65,
632 633 634
	/**
	 * Command type used for all ABM commands.
	 */
635
	DMUB_CMD__ABM = 66,
636 637 638
	/**
	 * Command type used for HW locking in FW.
	 */
639
	DMUB_CMD__HW_LOCK = 69,
640 641 642
	/**
	 * Command type used to access DP AUX.
	 */
643
	DMUB_CMD__DP_AUX_ACCESS = 70,
644 645 646
	/**
	 * Command type used for OUTBOX1 notification enable
	 */
647
	DMUB_CMD__OUTBOX1_ENABLE = 71,
648

649 650 651 652 653 654 655 656 657 658 659 660
	/**
	 * Command type used for all idle optimization commands.
	 */
	DMUB_CMD__IDLE_OPT = 72,
	/**
	 * Command type used for all clock manager commands.
	 */
	DMUB_CMD__CLK_MGR = 73,
	/**
	 * Command type used for all panel control commands.
	 */
	DMUB_CMD__PANEL_CNTL = 74,
661

662 663 664 665
	/**
	 * Command type used for interfacing with DPIA.
	 */
	DMUB_CMD__DPIA = 77,
666 667 668 669
	/**
	 * Command type used for EDID CEA parsing
	 */
	DMUB_CMD__EDID_CEA = 79,
670 671 672 673
	/**
	 * Command type used for getting usbc cable ID
	 */
	DMUB_CMD_GET_USBC_CABLE_ID = 81,
674 675 676
	/**
	 * Command type used for all VBIOS interface commands.
	 */
677
	DMUB_CMD__VBIOS = 128,
678 679
};

680 681 682
/**
 * enum dmub_out_cmd_type - DMUB outbox commands.
 */
683
enum dmub_out_cmd_type {
684 685 686
	/**
	 * Invalid outbox command, ignored.
	 */
687
	DMUB_OUT_CMD__NULL = 0,
688 689 690
	/**
	 * Command type used for DP AUX Reply data notification
	 */
691
	DMUB_OUT_CMD__DP_AUX_REPLY = 1,
692 693 694 695
	/**
	 * Command type used for DP HPD event notification
	 */
	DMUB_OUT_CMD__DP_HPD_NOTIFY = 2,
696 697 698 699
	/**
	 * Command type used for SET_CONFIG Reply notification
	 */
	DMUB_OUT_CMD__SET_CONFIG_REPLY = 3,
700 701
};

702 703 704
/* DMUB_CMD__DPIA command sub-types. */
enum dmub_cmd_dpia_type {
	DMUB_CMD__DPIA_DIG1_DPIA_CONTROL = 0,
705
	DMUB_CMD__DPIA_SET_CONFIG_ACCESS = 1,
706
	DMUB_CMD__DPIA_MST_ALLOC_SLOTS = 2,
707 708
};

709 710
#pragma pack(push, 1)

711 712 713
/**
 * struct dmub_cmd_header - Common command header fields.
 */
714
struct dmub_cmd_header {
715 716 717
	unsigned int type : 8; /**< command type */
	unsigned int sub_type : 8; /**< command sub type */
	unsigned int ret_status : 1; /**< 1 if returned data, 0 otherwise */
718 719
	unsigned int multi_cmd_pending : 1; /**< 1 if multiple commands chained together */
	unsigned int reserved0 : 6; /**< reserved bits */
720 721
	unsigned int payload_bytes : 6;  /* payload excluding header - up to 60 bytes */
	unsigned int reserved1 : 2; /**< reserved bits */
722 723 724
};

/*
725
 * struct dmub_cmd_read_modify_write_sequence - Read modify write
726 727 728 729 730 731 732 733 734 735
 *
 * 60 payload bytes can hold up to 5 sets of read modify writes,
 * each take 3 dwords.
 *
 * number of sequences = header.payload_bytes / sizeof(struct dmub_cmd_read_modify_write_sequence)
 *
 * modify_mask = 0xffff'ffff means all fields are going to be updated.  in this case
 * command parser will skip the read and we can use modify_mask = 0xffff'ffff as reg write
 */
struct dmub_cmd_read_modify_write_sequence {
736 737 738
	uint32_t addr; /**< register address */
	uint32_t modify_mask; /**< modify mask */
	uint32_t modify_value; /**< modify value */
739 740
};

741 742 743 744 745 746 747 748
/**
 * Maximum number of ops in read modify write sequence.
 */
#define DMUB_READ_MODIFY_WRITE_SEQ__MAX 5

/**
 * struct dmub_cmd_read_modify_write_sequence - Read modify write command.
 */
749
struct dmub_rb_cmd_read_modify_write {
750 751 752 753
	struct dmub_cmd_header header;  /**< command header */
	/**
	 * Read modify write sequence.
	 */
754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770
	struct dmub_cmd_read_modify_write_sequence seq[DMUB_READ_MODIFY_WRITE_SEQ__MAX];
};

/*
 * Update a register with specified masks and values sequeunce
 *
 * 60 payload bytes can hold address + up to 7 sets of mask/value combo, each take 2 dword
 *
 * number of field update sequence = (header.payload_bytes - sizeof(addr)) / sizeof(struct read_modify_write_sequence)
 *
 *
 * USE CASE:
 *   1. auto-increment register where additional read would update pointer and produce wrong result
 *   2. toggle a bit without read in the middle
 */

struct dmub_cmd_reg_field_update_sequence {
771 772
	uint32_t modify_mask; /**< 0xffff'ffff to skip initial read */
	uint32_t modify_value; /**< value to update with */
773 774
};

775 776 777 778 779 780 781 782
/**
 * Maximum number of ops in field update sequence.
 */
#define DMUB_REG_FIELD_UPDATE_SEQ__MAX 7

/**
 * struct dmub_rb_cmd_reg_field_update_sequence - Field update command.
 */
783
struct dmub_rb_cmd_reg_field_update_sequence {
784 785 786 787 788
	struct dmub_cmd_header header; /**< command header */
	uint32_t addr; /**< register address */
	/**
	 * Field update sequence.
	 */
789 790 791
	struct dmub_cmd_reg_field_update_sequence seq[DMUB_REG_FIELD_UPDATE_SEQ__MAX];
};

792 793 794 795 796 797

/**
 * Maximum number of burst write values.
 */
#define DMUB_BURST_WRITE_VALUES__MAX  14

798
/*
799
 * struct dmub_rb_cmd_burst_write - Burst write
800 801 802 803 804 805 806 807
 *
 * support use case such as writing out LUTs.
 *
 * 60 payload bytes can hold up to 14 values to write to given address
 *
 * number of payload = header.payload_bytes / sizeof(struct read_modify_write_sequence)
 */
struct dmub_rb_cmd_burst_write {
808 809 810 811 812
	struct dmub_cmd_header header; /**< command header */
	uint32_t addr; /**< register start address */
	/**
	 * Burst write register values.
	 */
813 814 815
	uint32_t write_values[DMUB_BURST_WRITE_VALUES__MAX];
};

816 817 818
/**
 * struct dmub_rb_cmd_common - Common command header
 */
819
struct dmub_rb_cmd_common {
820 821 822 823
	struct dmub_cmd_header header; /**< command header */
	/**
	 * Padding to RB_CMD_SIZE
	 */
824 825 826
	uint8_t cmd_buffer[DMUB_RB_CMD_SIZE - sizeof(struct dmub_cmd_header)];
};

827 828 829
/**
 * struct dmub_cmd_reg_wait_data - Register wait data
 */
830
struct dmub_cmd_reg_wait_data {
831 832 833 834
	uint32_t addr; /**< Register address */
	uint32_t mask; /**< Mask for register bits */
	uint32_t condition_field_value; /**< Value to wait for */
	uint32_t time_out_us; /**< Time out for reg wait in microseconds */
835 836
};

837 838 839
/**
 * struct dmub_rb_cmd_reg_wait - Register wait command
 */
840
struct dmub_rb_cmd_reg_wait {
841 842
	struct dmub_cmd_header header; /**< Command header */
	struct dmub_cmd_reg_wait_data reg_wait; /**< Register wait data */
843 844
};

845 846 847 848 849
/**
 * struct dmub_cmd_PLAT_54186_wa - Underflow workaround
 *
 * Reprograms surface parameters to avoid underflow.
 */
850
struct dmub_cmd_PLAT_54186_wa {
851 852 853 854 855
	uint32_t DCSURF_SURFACE_CONTROL; /**< reg value */
	uint32_t DCSURF_PRIMARY_SURFACE_ADDRESS_HIGH; /**< reg value */
	uint32_t DCSURF_PRIMARY_SURFACE_ADDRESS; /**< reg value */
	uint32_t DCSURF_PRIMARY_SURFACE_ADDRESS_HIGH_C; /**< reg value */
	uint32_t DCSURF_PRIMARY_SURFACE_ADDRESS_C; /**< reg value */
856
	struct {
857 858 859 860 861 862 863 864
		uint8_t hubp_inst : 4; /**< HUBP instance */
		uint8_t tmz_surface : 1; /**< TMZ enable or disable */
		uint8_t immediate :1; /**< Immediate flip */
		uint8_t vmid : 4; /**< VMID */
		uint8_t grph_stereo : 1; /**< 1 if stereo */
		uint32_t reserved : 21; /**< Reserved */
	} flip_params; /**< Pageflip parameters */
	uint32_t reserved[9]; /**< Reserved bits */
865 866
};

867 868 869
/**
 * struct dmub_rb_cmd_PLAT_54186_wa - Underflow workaround command
 */
870
struct dmub_rb_cmd_PLAT_54186_wa {
871 872
	struct dmub_cmd_header header; /**< Command header */
	struct dmub_cmd_PLAT_54186_wa flip; /**< Flip data */
873 874
};

875 876 877
/**
 * struct dmub_rb_cmd_mall - MALL command data.
 */
878
struct dmub_rb_cmd_mall {
879 880 881 882 883 884 885 886 887 888
	struct dmub_cmd_header header; /**< Common command header */
	union dmub_addr cursor_copy_src; /**< Cursor copy address */
	union dmub_addr cursor_copy_dst; /**< Cursor copy destination */
	uint32_t tmr_delay; /**< Timer delay */
	uint32_t tmr_scale; /**< Timer scale */
	uint16_t cursor_width; /**< Cursor width in pixels */
	uint16_t cursor_pitch; /**< Cursor pitch in pixels */
	uint16_t cursor_height; /**< Cursor height in pixels */
	uint8_t cursor_bpp; /**< Cursor bits per pixel */
	uint8_t debug_bits; /**< Debug bits */
889

890 891
	uint8_t reserved1; /**< Reserved bits */
	uint8_t reserved2; /**< Reserved bits */
892 893
};

894 895 896 897 898 899 900 901
/**
 * enum dmub_cmd_idle_opt_type - Idle optimization command type.
 */
enum dmub_cmd_idle_opt_type {
	/**
	 * DCN hardware restore.
	 */
	DMUB_CMD__IDLE_OPT_DCN_RESTORE = 0,
902 903 904 905 906

	/**
	 * DCN hardware save.
	 */
	DMUB_CMD__IDLE_OPT_DCN_SAVE_INIT = 1
907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942
};

/**
 * struct dmub_rb_cmd_idle_opt_dcn_restore - DCN restore command data.
 */
struct dmub_rb_cmd_idle_opt_dcn_restore {
	struct dmub_cmd_header header; /**< header */
};

/**
 * struct dmub_clocks - Clock update notification.
 */
struct dmub_clocks {
	uint32_t dispclk_khz; /**< dispclk kHz */
	uint32_t dppclk_khz; /**< dppclk kHz */
	uint32_t dcfclk_khz; /**< dcfclk kHz */
	uint32_t dcfclk_deep_sleep_khz; /**< dcfclk deep sleep kHz */
};

/**
 * enum dmub_cmd_clk_mgr_type - Clock manager commands.
 */
enum dmub_cmd_clk_mgr_type {
	/**
	 * Notify DMCUB of clock update.
	 */
	DMUB_CMD__CLK_MGR_NOTIFY_CLOCKS = 0,
};

/**
 * struct dmub_rb_cmd_clk_mgr_notify_clocks - Clock update notification.
 */
struct dmub_rb_cmd_clk_mgr_notify_clocks {
	struct dmub_cmd_header header; /**< header */
	struct dmub_clocks clocks; /**< clock data */
};
943

944 945 946
/**
 * struct dmub_cmd_digx_encoder_control_data - Encoder control data.
 */
947
struct dmub_cmd_digx_encoder_control_data {
948
	union dig_encoder_control_parameters_v1_5 dig; /**< payload */
949 950
};

951 952 953
/**
 * struct dmub_rb_cmd_digx_encoder_control - Encoder control command.
 */
954
struct dmub_rb_cmd_digx_encoder_control {
955 956
	struct dmub_cmd_header header;  /**< header */
	struct dmub_cmd_digx_encoder_control_data encoder_control; /**< payload */
957 958
};

959 960 961
/**
 * struct dmub_cmd_set_pixel_clock_data - Set pixel clock data.
 */
962
struct dmub_cmd_set_pixel_clock_data {
963
	struct set_pixel_clock_parameter_v1_7 clk; /**< payload */
964 965
};

966 967 968
/**
 * struct dmub_cmd_set_pixel_clock_data - Set pixel clock command.
 */
969
struct dmub_rb_cmd_set_pixel_clock {
970 971
	struct dmub_cmd_header header; /**< header */
	struct dmub_cmd_set_pixel_clock_data pixel_clock; /**< payload */
972 973
};

974 975 976
/**
 * struct dmub_cmd_enable_disp_power_gating_data - Display power gating.
 */
977
struct dmub_cmd_enable_disp_power_gating_data {
978
	struct enable_disp_power_gating_parameters_v2_1 pwr; /**< payload */
979 980
};

981 982 983
/**
 * struct dmub_rb_cmd_enable_disp_power_gating - Display power command.
 */
984
struct dmub_rb_cmd_enable_disp_power_gating {
985 986
	struct dmub_cmd_header header; /**< header */
	struct dmub_cmd_enable_disp_power_gating_data power_gating;  /**< payload */
987 988
};

989 990 991
/**
 * struct dmub_dig_transmitter_control_data_v1_7 - Transmitter control.
 */
992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005
struct dmub_dig_transmitter_control_data_v1_7 {
	uint8_t phyid; /**< 0=UNIPHYA, 1=UNIPHYB, 2=UNIPHYC, 3=UNIPHYD, 4=UNIPHYE, 5=UNIPHYF */
	uint8_t action; /**< Defined as ATOM_TRANSMITER_ACTION_xxx */
	union {
		uint8_t digmode; /**< enum atom_encode_mode_def */
		uint8_t dplaneset; /**< DP voltage swing and pre-emphasis value, "DP_LANE_SET__xDB_y_zV" */
	} mode_laneset;
	uint8_t lanenum; /**< Number of lanes */
	union {
		uint32_t symclk_10khz; /**< Symbol Clock in 10Khz */
	} symclk_units;
	uint8_t hpdsel; /**< =1: HPD1, =2: HPD2, ..., =6: HPD6, =0: HPD is not assigned */
	uint8_t digfe_sel; /**< DIG front-end selection, bit0 means DIG0 FE is enabled */
	uint8_t connobj_id; /**< Connector Object Id defined in ObjectId.h */
1006
	uint8_t HPO_instance; /**< HPO instance (0: inst0, 1: inst1) */
1007 1008 1009 1010 1011
	uint8_t reserved1; /**< For future use */
	uint8_t reserved2[3]; /**< For future use */
	uint32_t reserved3[11]; /**< For future use */
};

1012 1013 1014
/**
 * union dmub_cmd_dig1_transmitter_control_data - Transmitter control data.
 */
1015
union dmub_cmd_dig1_transmitter_control_data {
1016 1017
	struct dig_transmitter_control_parameters_v1_6 dig; /**< payload */
	struct dmub_dig_transmitter_control_data_v1_7 dig_v1_7;  /**< payload 1.7 */
1018 1019
};

1020 1021 1022
/**
 * struct dmub_rb_cmd_dig1_transmitter_control - Transmitter control command.
 */
1023
struct dmub_rb_cmd_dig1_transmitter_control {
1024 1025
	struct dmub_cmd_header header; /**< header */
	union dmub_cmd_dig1_transmitter_control_data transmitter_control; /**< payload */
1026 1027
};

1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055
/**
 * DPIA tunnel command parameters.
 */
struct dmub_cmd_dig_dpia_control_data {
	uint8_t enc_id;         /** 0 = ENGINE_ID_DIGA, ... */
	uint8_t action;         /** ATOM_TRANSMITER_ACTION_DISABLE/ENABLE/SETUP_VSEMPH */
	union {
		uint8_t digmode;    /** enum atom_encode_mode_def */
		uint8_t dplaneset;  /** DP voltage swing and pre-emphasis value */
	} mode_laneset;
	uint8_t lanenum;        /** Lane number 1, 2, 4, 8 */
	uint32_t symclk_10khz;  /** Symbol Clock in 10Khz */
	uint8_t hpdsel;         /** =0: HPD is not assigned */
	uint8_t digfe_sel;      /** DIG stream( front-end ) selection, bit0 - DIG0 FE */
	uint8_t dpia_id;        /** Index of DPIA */
	uint8_t fec_rdy : 1;
	uint8_t reserved : 7;
	uint32_t reserved1;
};

/**
 * DMUB command for DPIA tunnel control.
 */
struct dmub_rb_cmd_dig1_dpia_control {
	struct dmub_cmd_header header;
	struct dmub_cmd_dig_dpia_control_data dpia_control;
};

1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080
/**
 * SET_CONFIG Command Payload
 */
struct set_config_cmd_payload {
	uint8_t msg_type; /* set config message type */
	uint8_t msg_data; /* set config message data */
};

/**
 * Data passed from driver to FW in a DMUB_CMD__DPIA_SET_CONFIG_ACCESS command.
 */
struct dmub_cmd_set_config_control_data {
	struct set_config_cmd_payload cmd_pkt;
	uint8_t instance; /* DPIA instance */
	uint8_t immed_status; /* Immediate status returned in case of error */
};

/**
 * DMUB command structure for SET_CONFIG command.
 */
struct dmub_rb_cmd_set_config_access {
	struct dmub_cmd_header header; /* header */
	struct dmub_cmd_set_config_control_data set_config_control; /* set config data */
};

1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098
/**
 * Data passed from driver to FW in a DMUB_CMD__DPIA_MST_ALLOC_SLOTS command.
 */
struct dmub_cmd_mst_alloc_slots_control_data {
	uint8_t mst_alloc_slots; /* mst slots to be allotted */
	uint8_t instance; /* DPIA instance */
	uint8_t immed_status; /* Immediate status returned as there is no outbox msg posted */
	uint8_t mst_slots_in_use; /* returns slots in use for error cases */
};

/**
 * DMUB command structure for SET_ command.
 */
struct dmub_rb_cmd_set_mst_alloc_slots {
	struct dmub_cmd_header header; /* header */
	struct dmub_cmd_mst_alloc_slots_control_data mst_slots_control; /* mst slots control */
};

1099 1100 1101
/**
 * struct dmub_rb_cmd_dpphy_init - DPPHY init.
 */
1102
struct dmub_rb_cmd_dpphy_init {
1103 1104
	struct dmub_cmd_header header; /**< header */
	uint8_t reserved[60]; /**< reserved bits */
1105 1106
};

1107 1108 1109 1110 1111
/**
 * enum dp_aux_request_action - DP AUX request command listing.
 *
 * 4 AUX request command bits are shifted to high nibble.
 */
1112
enum dp_aux_request_action {
1113
	/** I2C-over-AUX write request */
1114
	DP_AUX_REQ_ACTION_I2C_WRITE		= 0x00,
1115
	/** I2C-over-AUX read request */
1116
	DP_AUX_REQ_ACTION_I2C_READ		= 0x10,
1117
	/** I2C-over-AUX write status request */
1118
	DP_AUX_REQ_ACTION_I2C_STATUS_REQ	= 0x20,
1119
	/** I2C-over-AUX write request with MOT=1 */
1120
	DP_AUX_REQ_ACTION_I2C_WRITE_MOT		= 0x40,
1121
	/** I2C-over-AUX read request with MOT=1 */
1122
	DP_AUX_REQ_ACTION_I2C_READ_MOT		= 0x50,
1123
	/** I2C-over-AUX write status request with MOT=1 */
1124
	DP_AUX_REQ_ACTION_I2C_STATUS_REQ_MOT	= 0x60,
1125
	/** Native AUX write request */
1126
	DP_AUX_REQ_ACTION_DPCD_WRITE		= 0x80,
1127
	/** Native AUX read request */
1128 1129 1130
	DP_AUX_REQ_ACTION_DPCD_READ		= 0x90
};

1131 1132 1133
/**
 * enum aux_return_code_type - DP AUX process return code listing.
 */
1134
enum aux_return_code_type {
1135
	/** AUX process succeeded */
1136
	AUX_RET_SUCCESS = 0,
1137
	/** AUX process failed with unknown reason */
1138
	AUX_RET_ERROR_UNKNOWN,
1139
	/** AUX process completed with invalid reply */
1140
	AUX_RET_ERROR_INVALID_REPLY,
1141
	/** AUX process timed out */
1142
	AUX_RET_ERROR_TIMEOUT,
1143
	/** HPD was low during AUX process */
1144
	AUX_RET_ERROR_HPD_DISCON,
1145
	/** Failed to acquire AUX engine */
1146
	AUX_RET_ERROR_ENGINE_ACQUIRE,
1147
	/** AUX request not supported */
1148
	AUX_RET_ERROR_INVALID_OPERATION,
1149
	/** AUX process not available */
1150 1151 1152
	AUX_RET_ERROR_PROTOCOL_ERROR,
};

1153 1154 1155
/**
 * enum aux_channel_type - DP AUX channel type listing.
 */
1156
enum aux_channel_type {
1157
	/** AUX thru Legacy DP AUX */
1158
	AUX_CHANNEL_LEGACY_DDC,
1159
	/** AUX thru DPIA DP tunneling */
1160 1161 1162
	AUX_CHANNEL_DPIA
};

1163 1164 1165
/**
 * struct aux_transaction_parameters - DP AUX request transaction data
 */
1166
struct aux_transaction_parameters {
1167 1168 1169 1170 1171 1172
	uint8_t is_i2c_over_aux; /**< 0=native AUX, 1=I2C-over-AUX */
	uint8_t action; /**< enum dp_aux_request_action */
	uint8_t length; /**< DP AUX request data length */
	uint8_t reserved; /**< For future use */
	uint32_t address; /**< DP AUX address */
	uint8_t data[16]; /**< DP AUX write data */
1173 1174
};

1175 1176 1177
/**
 * Data passed from driver to FW in a DMUB_CMD__DP_AUX_ACCESS command.
 */
1178
struct dmub_cmd_dp_aux_control_data {
1179 1180 1181 1182 1183 1184 1185 1186
	uint8_t instance; /**< AUX instance or DPIA instance */
	uint8_t manual_acq_rel_enable; /**< manual control for acquiring or releasing AUX channel */
	uint8_t sw_crc_enabled; /**< Use software CRC for tunneling packet instead of hardware CRC */
	uint8_t reserved0; /**< For future use */
	uint16_t timeout; /**< timeout time in us */
	uint16_t reserved1; /**< For future use */
	enum aux_channel_type type; /**< enum aux_channel_type */
	struct aux_transaction_parameters dpaux; /**< struct aux_transaction_parameters */
1187 1188
};

1189 1190 1191
/**
 * Definition of a DMUB_CMD__DP_AUX_ACCESS command.
 */
1192
struct dmub_rb_cmd_dp_aux_access {
1193 1194 1195
	/**
	 * Command header.
	 */
1196
	struct dmub_cmd_header header;
1197 1198 1199
	/**
	 * Data passed from driver to FW in a DMUB_CMD__DP_AUX_ACCESS command.
	 */
1200 1201 1202
	struct dmub_cmd_dp_aux_control_data aux_control;
};

1203 1204 1205
/**
 * Definition of a DMUB_CMD__OUTBOX1_ENABLE command.
 */
1206
struct dmub_rb_cmd_outbox1_enable {
1207 1208 1209
	/**
	 * Command header.
	 */
1210
	struct dmub_cmd_header header;
1211 1212 1213 1214
	/**
	 *  enable: 0x0 -> disable outbox1 notification (default value)
	 *			0x1 -> enable outbox1 notification
	 */
1215 1216 1217 1218
	uint32_t enable;
};

/* DP AUX Reply command - OutBox Cmd */
1219 1220 1221
/**
 * Data passed to driver from FW in a DMUB_OUT_CMD__DP_AUX_REPLY command.
 */
1222
struct aux_reply_data {
1223 1224 1225
	/**
	 * Aux cmd
	 */
1226
	uint8_t command;
1227 1228 1229
	/**
	 * Aux reply data length (max: 16 bytes)
	 */
1230
	uint8_t length;
1231 1232 1233
	/**
	 * Alignment only
	 */
1234
	uint8_t pad[2];
1235 1236 1237
	/**
	 * Aux reply data
	 */
1238 1239 1240
	uint8_t data[16];
};

1241 1242 1243
/**
 * Control Data passed to driver from FW in a DMUB_OUT_CMD__DP_AUX_REPLY command.
 */
1244
struct aux_reply_control_data {
1245 1246 1247
	/**
	 * Reserved for future use
	 */
1248
	uint32_t handle;
1249 1250 1251
	/**
	 * Aux Instance
	 */
1252
	uint8_t instance;
1253 1254 1255
	/**
	 * Aux transaction result: definition in enum aux_return_code_type
	 */
1256
	uint8_t result;
1257 1258 1259
	/**
	 * Alignment only
	 */
1260 1261 1262
	uint16_t pad;
};

1263 1264 1265
/**
 * Definition of a DMUB_OUT_CMD__DP_AUX_REPLY command.
 */
1266
struct dmub_rb_cmd_dp_aux_reply {
1267 1268 1269
	/**
	 * Command header.
	 */
1270
	struct dmub_cmd_header header;
1271 1272 1273
	/**
	 * Control Data passed to driver from FW in a DMUB_OUT_CMD__DP_AUX_REPLY command.
	 */
1274
	struct aux_reply_control_data control;
1275 1276 1277
	/**
	 * Data passed to driver from FW in a DMUB_OUT_CMD__DP_AUX_REPLY command.
	 */
1278 1279 1280
	struct aux_reply_data reply_data;
};

1281
/* DP HPD Notify command - OutBox Cmd */
1282 1283 1284
/**
 * DP HPD Type
 */
1285
enum dp_hpd_type {
1286 1287 1288
	/**
	 * Normal DP HPD
	 */
1289
	DP_HPD = 0,
1290 1291 1292
	/**
	 * DP HPD short pulse
	 */
1293 1294 1295
	DP_IRQ
};

1296 1297 1298
/**
 * DP HPD Status
 */
1299
enum dp_hpd_status {
1300 1301 1302
	/**
	 * DP_HPD status low
	 */
1303
	DP_HPD_UNPLUG = 0,
1304 1305 1306
	/**
	 * DP_HPD status high
	 */
1307 1308 1309
	DP_HPD_PLUG
};

1310 1311 1312
/**
 * Data passed to driver from FW in a DMUB_OUT_CMD__DP_HPD_NOTIFY command.
 */
1313
struct dp_hpd_data {
1314 1315 1316
	/**
	 * DP HPD instance
	 */
1317
	uint8_t instance;
1318 1319 1320
	/**
	 * HPD type
	 */
1321
	uint8_t hpd_type;
1322 1323 1324
	/**
	 * HPD status: only for type: DP_HPD to indicate status
	 */
1325
	uint8_t hpd_status;
1326 1327 1328
	/**
	 * Alignment only
	 */
1329 1330 1331
	uint8_t pad;
};

1332 1333 1334
/**
 * Definition of a DMUB_OUT_CMD__DP_HPD_NOTIFY command.
 */
1335
struct dmub_rb_cmd_dp_hpd_notify {
1336 1337 1338
	/**
	 * Command header.
	 */
1339
	struct dmub_cmd_header header;
1340 1341 1342
	/**
	 * Data passed to driver from FW in a DMUB_OUT_CMD__DP_HPD_NOTIFY command.
	 */
1343 1344 1345
	struct dp_hpd_data hpd_data;
};

1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372
/**
 * Definition of a SET_CONFIG reply from DPOA.
 */
enum set_config_status {
	SET_CONFIG_PENDING = 0,
	SET_CONFIG_ACK_RECEIVED,
	SET_CONFIG_RX_TIMEOUT,
	SET_CONFIG_UNKNOWN_ERROR,
};

/**
 * Definition of a set_config reply
 */
struct set_config_reply_control_data {
	uint8_t instance; /* DPIA Instance */
	uint8_t status; /* Set Config reply */
	uint16_t pad; /* Alignment */
};

/**
 * Definition of a DMUB_OUT_CMD__SET_CONFIG_REPLY command.
 */
struct dmub_rb_cmd_dp_set_config_reply {
	struct dmub_cmd_header header;
	struct set_config_reply_control_data set_config_reply_control;
};

1373 1374 1375 1376 1377
/*
 * Command IDs should be treated as stable ABI.
 * Do not reuse or modify IDs.
 */

1378 1379 1380
/**
 * PSR command sub-types.
 */
1381
enum dmub_cmd_psr_type {
1382 1383 1384
	/**
	 * Set PSR version support.
	 */
1385
	DMUB_CMD__PSR_SET_VERSION		= 0,
1386 1387 1388
	/**
	 * Copy driver-calculated parameters to PSR state.
	 */
1389
	DMUB_CMD__PSR_COPY_SETTINGS		= 1,
1390 1391 1392
	/**
	 * Enable PSR.
	 */
1393
	DMUB_CMD__PSR_ENABLE			= 2,
1394 1395 1396 1397

	/**
	 * Disable PSR.
	 */
1398
	DMUB_CMD__PSR_DISABLE			= 3,
1399 1400 1401 1402 1403 1404

	/**
	 * Set PSR level.
	 * PSR level is a 16-bit value dicated by driver that
	 * will enable/disable different functionality.
	 */
1405
	DMUB_CMD__PSR_SET_LEVEL			= 4,
1406 1407 1408 1409

	/**
	 * Forces PSR enabled until an explicit PSR disable call.
	 */
1410
	DMUB_CMD__PSR_FORCE_STATIC		= 5,
1411 1412 1413 1414
	/**
	 * Set PSR power option
	 */
	DMUB_CMD__SET_PSR_POWER_OPT = 7,
1415 1416
};

1417 1418 1419
/**
 * PSR versions.
 */
1420
enum psr_version {
1421 1422 1423
	/**
	 * PSR version 1.
	 */
1424
	PSR_VERSION_1				= 0,
1425 1426 1427
	/**
	 * PSR not supported.
	 */
1428 1429 1430
	PSR_VERSION_UNSUPPORTED			= 0xFFFFFFFF,
};

1431 1432 1433
/**
 * enum dmub_cmd_mall_type - MALL commands
 */
1434
enum dmub_cmd_mall_type {
1435 1436 1437
	/**
	 * Allows display refresh from MALL.
	 */
1438
	DMUB_CMD__MALL_ACTION_ALLOW = 0,
1439 1440 1441
	/**
	 * Disallows display refresh from MALL.
	 */
1442
	DMUB_CMD__MALL_ACTION_DISALLOW = 1,
1443 1444 1445
	/**
	 * Cursor copy for MALL.
	 */
1446
	DMUB_CMD__MALL_ACTION_COPY_CURSOR = 2,
1447 1448 1449
	/**
	 * Controls DF requests.
	 */
1450
	DMUB_CMD__MALL_ACTION_NO_DF_REQ = 3,
1451 1452
};

1453

1454 1455 1456
/**
 * Data passed from driver to FW in a DMUB_CMD__PSR_COPY_SETTINGS command.
 */
1457
struct dmub_cmd_psr_copy_settings_data {
1458 1459 1460
	/**
	 * Flags that can be set by driver to change some PSR behaviour.
	 */
A
Anthony Koo 已提交
1461
	union dmub_psr_debug_flags debug;
1462 1463 1464
	/**
	 * 16-bit value dicated by driver that will enable/disable different functionality.
	 */
1465
	uint16_t psr_level;
1466 1467 1468
	/**
	 * DPP HW instance.
	 */
1469
	uint8_t dpp_inst;
1470 1471 1472
	/**
	 * MPCC HW instance.
	 * Not used in dmub fw,
1473 1474
	 * dmub fw will get active opp by reading odm registers.
	 */
1475
	uint8_t mpcc_inst;
1476 1477 1478 1479 1480
	/**
	 * OPP HW instance.
	 * Not used in dmub fw,
	 * dmub fw will get active opp by reading odm registers.
	 */
1481
	uint8_t opp_inst;
1482 1483 1484
	/**
	 * OTG HW instance.
	 */
1485
	uint8_t otg_inst;
1486 1487 1488
	/**
	 * DIG FE HW instance.
	 */
1489
	uint8_t digfe_inst;
1490 1491 1492
	/**
	 * DIG BE HW instance.
	 */
1493
	uint8_t digbe_inst;
1494 1495 1496
	/**
	 * DP PHY HW instance.
	 */
1497
	uint8_t dpphy_inst;
1498 1499 1500
	/**
	 * AUX HW instance.
	 */
1501
	uint8_t aux_inst;
1502 1503 1504
	/**
	 * Determines if SMU optimzations are enabled/disabled.
	 */
1505
	uint8_t smu_optimizations_en;
1506 1507 1508 1509
	/**
	 * Unused.
	 * TODO: Remove.
	 */
1510
	uint8_t frame_delay;
1511 1512 1513 1514 1515 1516 1517
	/**
	 * If RFB setup time is greater than the total VBLANK time,
	 * it is not possible for the sink to capture the video frame
	 * in the same frame the SDP is sent. In this case,
	 * the frame capture indication bit should be set and an extra
	 * static frame should be transmitted to the sink.
	 */
1518
	uint8_t frame_cap_ind;
1519 1520 1521
	/**
	 * Explicit padding to 4 byte boundary.
	 */
1522
	uint8_t pad[2];
1523 1524 1525
	/**
	 * Multi-display optimizations are implemented on certain ASICs.
	 */
1526
	uint8_t multi_disp_optimizations_en;
1527 1528 1529 1530
	/**
	 * The last possible line SDP may be transmitted without violating
	 * the RFB setup time or entering the active video frame.
	 */
1531
	uint16_t init_sdp_deadline;
1532 1533 1534
	/**
	 * Explicit padding to 4 byte boundary.
	 */
1535
	uint16_t pad2;
1536 1537 1538
	/**
	 * Length of each horizontal line in us.
	 */
1539
	uint32_t line_time_in_us;
1540 1541 1542 1543 1544 1545 1546 1547 1548 1549
	/**
	 * FEC enable status in driver
	 */
	uint8_t fec_enable_status;
	/**
	 * FEC re-enable delay when PSR exit.
	 * unit is 100us, range form 0~255(0xFF).
	 */
	uint8_t fec_enable_delay_in100us;
	/**
1550 1551 1552 1553 1554 1555 1556
	 * PSR control version.
	 */
	uint8_t cmd_version;
	/**
	 * Panel Instance.
	 * Panel isntance to identify which psr_state to use
	 * Currently the support is only for 0 or 1
1557
	 */
1558
	uint8_t panel_inst;
1559 1560 1561 1562
	/*
	 * DSC enable status in driver
	 */
	uint8_t dsc_enable_status;
1563 1564 1565 1566
	/*
	 * Use FSM state for PSR power up/down
	 */
	uint8_t use_phy_fsm;
1567
	/**
1568
	 * Explicit padding to 2 byte boundary.
1569
	 */
1570
	uint8_t pad3[2];
1571 1572
};

1573 1574 1575
/**
 * Definition of a DMUB_CMD__PSR_COPY_SETTINGS command.
 */
1576
struct dmub_rb_cmd_psr_copy_settings {
1577 1578 1579
	/**
	 * Command header.
	 */
1580
	struct dmub_cmd_header header;
1581 1582 1583
	/**
	 * Data passed from driver to FW in a DMUB_CMD__PSR_COPY_SETTINGS command.
	 */
1584 1585 1586
	struct dmub_cmd_psr_copy_settings_data psr_copy_settings_data;
};

1587 1588 1589
/**
 * Data passed from driver to FW in a DMUB_CMD__PSR_SET_LEVEL command.
 */
1590
struct dmub_cmd_psr_set_level_data {
1591 1592 1593
	/**
	 * 16-bit value dicated by driver that will enable/disable different functionality.
	 */
1594
	uint16_t psr_level;
1595
	/**
1596
	 * PSR control version.
1597
	 */
1598 1599 1600 1601 1602 1603 1604
	uint8_t cmd_version;
	/**
	 * Panel Instance.
	 * Panel isntance to identify which psr_state to use
	 * Currently the support is only for 0 or 1
	 */
	uint8_t panel_inst;
1605 1606
};

1607 1608 1609
/**
 * Definition of a DMUB_CMD__PSR_SET_LEVEL command.
 */
1610
struct dmub_rb_cmd_psr_set_level {
1611 1612 1613
	/**
	 * Command header.
	 */
1614
	struct dmub_cmd_header header;
1615 1616 1617
	/**
	 * Definition of a DMUB_CMD__PSR_SET_LEVEL command.
	 */
1618 1619 1620
	struct dmub_cmd_psr_set_level_data psr_set_level_data;
};

1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637
struct dmub_rb_cmd_psr_enable_data {
	/**
	 * PSR control version.
	 */
	uint8_t cmd_version;
	/**
	 * Panel Instance.
	 * Panel isntance to identify which psr_state to use
	 * Currently the support is only for 0 or 1
	 */
	uint8_t panel_inst;
	/**
	 * Explicit padding to 4 byte boundary.
	 */
	uint8_t pad[2];
};

1638 1639 1640 1641
/**
 * Definition of a DMUB_CMD__PSR_ENABLE command.
 * PSR enable/disable is controlled using the sub_type.
 */
1642
struct dmub_rb_cmd_psr_enable {
1643 1644 1645
	/**
	 * Command header.
	 */
1646
	struct dmub_cmd_header header;
1647 1648

	struct dmub_rb_cmd_psr_enable_data data;
1649 1650
};

1651 1652 1653
/**
 * Data passed from driver to FW in a DMUB_CMD__PSR_SET_VERSION command.
 */
1654
struct dmub_cmd_psr_set_version_data {
1655 1656 1657 1658
	/**
	 * PSR version that FW should implement.
	 */
	enum psr_version version;
1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672
	/**
	 * PSR control version.
	 */
	uint8_t cmd_version;
	/**
	 * Panel Instance.
	 * Panel isntance to identify which psr_state to use
	 * Currently the support is only for 0 or 1
	 */
	uint8_t panel_inst;
	/**
	 * Explicit padding to 4 byte boundary.
	 */
	uint8_t pad[2];
1673 1674
};

1675 1676 1677
/**
 * Definition of a DMUB_CMD__PSR_SET_VERSION command.
 */
1678
struct dmub_rb_cmd_psr_set_version {
1679 1680 1681
	/**
	 * Command header.
	 */
1682
	struct dmub_cmd_header header;
1683 1684 1685
	/**
	 * Data passed from driver to FW in a DMUB_CMD__PSR_SET_VERSION command.
	 */
1686
	struct dmub_cmd_psr_set_version_data psr_set_version_data;
1687 1688
};

1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705
struct dmub_cmd_psr_force_static_data {
	/**
	 * PSR control version.
	 */
	uint8_t cmd_version;
	/**
	 * Panel Instance.
	 * Panel isntance to identify which psr_state to use
	 * Currently the support is only for 0 or 1
	 */
	uint8_t panel_inst;
	/**
	 * Explicit padding to 4 byte boundary.
	 */
	uint8_t pad[2];
};

1706 1707 1708
/**
 * Definition of a DMUB_CMD__PSR_FORCE_STATIC command.
 */
1709
struct dmub_rb_cmd_psr_force_static {
1710 1711 1712
	/**
	 * Command header.
	 */
1713
	struct dmub_cmd_header header;
1714 1715 1716 1717
	/**
	 * Data passed from driver to FW in a DMUB_CMD__PSR_FORCE_STATIC command.
	 */
	struct dmub_cmd_psr_force_static_data psr_force_static_data;
1718 1719
};

1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757
/**
 * Data passed from driver to FW in a DMUB_CMD__SET_PSR_POWER_OPT command.
 */
struct dmub_cmd_psr_set_power_opt_data {
	/**
	 * PSR control version.
	 */
	uint8_t cmd_version;
	/**
	 * Panel Instance.
	 * Panel isntance to identify which psr_state to use
	 * Currently the support is only for 0 or 1
	 */
	uint8_t panel_inst;
	/**
	 * Explicit padding to 4 byte boundary.
	 */
	uint8_t pad[2];
	/**
	 * PSR power option
	 */
	uint32_t power_opt;
};

/**
 * Definition of a DMUB_CMD__SET_PSR_POWER_OPT command.
 */
struct dmub_rb_cmd_psr_set_power_opt {
	/**
	 * Command header.
	 */
	struct dmub_cmd_header header;
	/**
	 * Definition of a DMUB_CMD__SET_PSR_POWER_OPT command.
	 */
	struct dmub_cmd_psr_set_power_opt_data psr_set_power_opt_data;
};

1758 1759
/**
 * Set of HW components that can be locked.
1760 1761 1762
 *
 * Note: If updating with more HW components, fields
 * in dmub_inbox0_cmd_lock_hw must be updated to match.
1763
 */
1764
union dmub_hw_lock_flags {
1765 1766 1767
	/**
	 * Set of HW components that can be locked.
	 */
1768
	struct {
1769 1770 1771
		/**
		 * Lock/unlock OTG master update lock.
		 */
1772
		uint8_t lock_pipe   : 1;
1773 1774 1775
		/**
		 * Lock/unlock cursor.
		 */
1776
		uint8_t lock_cursor : 1;
1777 1778 1779
		/**
		 * Lock/unlock global update lock.
		 */
1780
		uint8_t lock_dig    : 1;
1781 1782 1783
		/**
		 * Triple buffer lock requires additional hw programming to usual OTG master lock.
		 */
1784 1785 1786
		uint8_t triple_buffer_lock : 1;
	} bits;

1787 1788 1789
	/**
	 * Union for HW Lock flags.
	 */
1790 1791 1792
	uint8_t u8All;
};

1793 1794
/**
 * Instances of HW to be locked.
1795 1796 1797
 *
 * Note: If updating with more HW components, fields
 * in dmub_inbox0_cmd_lock_hw must be updated to match.
1798
 */
1799
struct dmub_hw_lock_inst_flags {
1800 1801 1802
	/**
	 * OTG HW instance for OTG master update lock.
	 */
1803
	uint8_t otg_inst;
1804 1805 1806
	/**
	 * OPP instance for cursor lock.
	 */
1807
	uint8_t opp_inst;
1808 1809 1810 1811
	/**
	 * OTG HW instance for global update lock.
	 * TODO: Remove, and re-use otg_inst.
	 */
1812
	uint8_t dig_inst;
1813 1814 1815
	/**
	 * Explicit pad to 4 byte boundary.
	 */
1816 1817 1818
	uint8_t pad;
};

1819 1820
/**
 * Clients that can acquire the HW Lock Manager.
1821 1822 1823
 *
 * Note: If updating with more clients, fields in
 * dmub_inbox0_cmd_lock_hw must be updated to match.
1824
 */
1825
enum hw_lock_client {
1826 1827 1828
	/**
	 * Driver is the client of HW Lock Manager.
	 */
1829
	HW_LOCK_CLIENT_DRIVER = 0,
1830 1831 1832
	/**
	 * Invalid client.
	 */
1833 1834 1835
	HW_LOCK_CLIENT_INVALID = 0xFFFFFFFF,
};

1836 1837 1838
/**
 * Data passed to HW Lock Mgr in a DMUB_CMD__HW_LOCK command.
 */
1839
struct dmub_cmd_lock_hw_data {
1840 1841 1842
	/**
	 * Specifies the client accessing HW Lock Manager.
	 */
1843
	enum hw_lock_client client;
1844 1845 1846
	/**
	 * HW instances to be locked.
	 */
1847
	struct dmub_hw_lock_inst_flags inst_flags;
1848 1849 1850
	/**
	 * Which components to be locked.
	 */
1851
	union dmub_hw_lock_flags hw_locks;
1852 1853 1854
	/**
	 * Specifies lock/unlock.
	 */
1855
	uint8_t lock;
1856 1857 1858 1859
	/**
	 * HW can be unlocked separately from releasing the HW Lock Mgr.
	 * This flag is set if the client wishes to release the object.
	 */
1860
	uint8_t should_release;
1861 1862 1863
	/**
	 * Explicit padding to 4 byte boundary.
	 */
1864 1865 1866
	uint8_t pad;
};

1867 1868 1869 1870
/**
 * Definition of a DMUB_CMD__HW_LOCK command.
 * Command is used by driver and FW.
 */
1871
struct dmub_rb_cmd_lock_hw {
1872 1873 1874
	/**
	 * Command header.
	 */
1875
	struct dmub_cmd_header header;
1876 1877 1878
	/**
	 * Data passed to HW Lock Mgr in a DMUB_CMD__HW_LOCK command.
	 */
1879 1880 1881
	struct dmub_cmd_lock_hw_data lock_hw_data;
};

1882 1883 1884
/**
 * ABM command sub-types.
 */
1885
enum dmub_cmd_abm_type {
1886 1887 1888 1889
	/**
	 * Initialize parameters for ABM algorithm.
	 * Data is passed through an indirect buffer.
	 */
1890
	DMUB_CMD__ABM_INIT_CONFIG	= 0,
1891 1892 1893
	/**
	 * Set OTG and panel HW instance.
	 */
1894
	DMUB_CMD__ABM_SET_PIPE		= 1,
1895 1896 1897
	/**
	 * Set user requested backklight level.
	 */
1898
	DMUB_CMD__ABM_SET_BACKLIGHT	= 2,
1899 1900 1901
	/**
	 * Set ABM operating/aggression level.
	 */
1902
	DMUB_CMD__ABM_SET_LEVEL		= 3,
1903 1904 1905
	/**
	 * Set ambient light level.
	 */
1906
	DMUB_CMD__ABM_SET_AMBIENT_LEVEL	= 4,
1907 1908 1909
	/**
	 * Enable/disable fractional duty cycle for backlight PWM.
	 */
1910
	DMUB_CMD__ABM_SET_PWM_FRAC	= 5,
1911 1912 1913 1914 1915

	/**
	 * unregister vertical interrupt after steady state is reached
	 */
	DMUB_CMD__ABM_PAUSE	= 6,
1916 1917
};

1918 1919 1920 1921 1922 1923
/**
 * Parameters for ABM2.4 algorithm. Passed from driver to FW via an indirect buffer.
 * Requirements:
 *  - Padded explicitly to 32-bit boundary.
 *  - Must ensure this structure matches the one on driver-side,
 *    otherwise it won't be aligned.
1924 1925
 */
struct abm_config_table {
1926 1927 1928
	/**
	 * Gamma curve thresholds, used for crgb conversion.
	 */
1929
	uint16_t crgb_thresh[NUM_POWER_FN_SEGS];                 // 0B
1930 1931 1932
	/**
	 * Gamma curve offsets, used for crgb conversion.
	 */
1933
	uint16_t crgb_offset[NUM_POWER_FN_SEGS];                 // 16B
1934 1935 1936
	/**
	 * Gamma curve slopes, used for crgb conversion.
	 */
1937
	uint16_t crgb_slope[NUM_POWER_FN_SEGS];                  // 32B
1938 1939 1940
	/**
	 * Custom backlight curve thresholds.
	 */
1941
	uint16_t backlight_thresholds[NUM_BL_CURVE_SEGS];        // 48B
1942 1943 1944
	/**
	 * Custom backlight curve offsets.
	 */
1945
	uint16_t backlight_offsets[NUM_BL_CURVE_SEGS];           // 78B
1946 1947 1948
	/**
	 * Ambient light thresholds.
	 */
1949
	uint16_t ambient_thresholds_lux[NUM_AMBI_LEVEL];         // 112B
1950 1951 1952
	/**
	 * Minimum programmable backlight.
	 */
1953
	uint16_t min_abm_backlight;                              // 122B
1954 1955 1956
	/**
	 * Minimum reduction values.
	 */
1957
	uint8_t min_reduction[NUM_AMBI_LEVEL][NUM_AGGR_LEVEL];   // 124B
1958 1959 1960
	/**
	 * Maximum reduction values.
	 */
1961
	uint8_t max_reduction[NUM_AMBI_LEVEL][NUM_AGGR_LEVEL];   // 144B
1962 1963 1964
	/**
	 * Bright positive gain.
	 */
1965
	uint8_t bright_pos_gain[NUM_AMBI_LEVEL][NUM_AGGR_LEVEL]; // 164B
1966 1967 1968
	/**
	 * Dark negative gain.
	 */
1969
	uint8_t dark_pos_gain[NUM_AMBI_LEVEL][NUM_AGGR_LEVEL];   // 184B
1970 1971 1972
	/**
	 * Hybrid factor.
	 */
1973
	uint8_t hybrid_factor[NUM_AGGR_LEVEL];                   // 204B
1974 1975 1976
	/**
	 * Contrast factor.
	 */
1977
	uint8_t contrast_factor[NUM_AGGR_LEVEL];                 // 208B
1978 1979 1980
	/**
	 * Deviation gain.
	 */
1981
	uint8_t deviation_gain[NUM_AGGR_LEVEL];                  // 212B
1982 1983 1984
	/**
	 * Minimum knee.
	 */
1985
	uint8_t min_knee[NUM_AGGR_LEVEL];                        // 216B
1986 1987 1988
	/**
	 * Maximum knee.
	 */
1989
	uint8_t max_knee[NUM_AGGR_LEVEL];                        // 220B
1990 1991 1992
	/**
	 * Unused.
	 */
1993
	uint8_t iir_curve[NUM_AMBI_LEVEL];                       // 224B
1994 1995 1996
	/**
	 * Explicit padding to 4 byte boundary.
	 */
1997
	uint8_t pad3[3];                                         // 229B
1998 1999 2000
	/**
	 * Backlight ramp reduction.
	 */
2001
	uint16_t blRampReduction[NUM_AGGR_LEVEL];                // 232B
2002 2003 2004
	/**
	 * Backlight ramp start.
	 */
2005
	uint16_t blRampStart[NUM_AGGR_LEVEL];                    // 240B
2006 2007
};

2008 2009 2010
/**
 * Data passed from driver to FW in a DMUB_CMD__ABM_SET_PIPE command.
 */
2011
struct dmub_cmd_abm_set_pipe_data {
2012 2013 2014
	/**
	 * OTG HW instance.
	 */
A
Anthony Koo 已提交
2015
	uint8_t otg_inst;
2016 2017 2018 2019

	/**
	 * Panel Control HW instance.
	 */
A
Anthony Koo 已提交
2020
	uint8_t panel_inst;
2021 2022 2023 2024

	/**
	 * Controls how ABM will interpret a set pipe or set level command.
	 */
A
Anthony Koo 已提交
2025
	uint8_t set_pipe_option;
2026 2027 2028 2029 2030 2031

	/**
	 * Unused.
	 * TODO: Remove.
	 */
	uint8_t ramping_boundary;
2032 2033
};

2034 2035 2036
/**
 * Definition of a DMUB_CMD__ABM_SET_PIPE command.
 */
2037
struct dmub_rb_cmd_abm_set_pipe {
2038 2039 2040
	/**
	 * Command header.
	 */
2041
	struct dmub_cmd_header header;
2042 2043 2044 2045

	/**
	 * Data passed from driver to FW in a DMUB_CMD__ABM_SET_PIPE command.
	 */
2046 2047 2048
	struct dmub_cmd_abm_set_pipe_data abm_set_pipe_data;
};

2049 2050 2051
/**
 * Data passed from driver to FW in a DMUB_CMD__ABM_SET_BACKLIGHT command.
 */
2052
struct dmub_cmd_abm_set_backlight_data {
2053 2054 2055
	/**
	 * Number of frames to ramp to backlight user level.
	 */
2056
	uint32_t frame_ramp;
2057 2058 2059 2060

	/**
	 * Requested backlight level from user.
	 */
2061
	uint32_t backlight_user_level;
2062 2063

	/**
2064
	 * ABM control version.
2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078
	 */
	uint8_t version;

	/**
	 * Panel Control HW instance mask.
	 * Bit 0 is Panel Control HW instance 0.
	 * Bit 1 is Panel Control HW instance 1.
	 */
	uint8_t panel_mask;

	/**
	 * Explicit padding to 4 byte boundary.
	 */
	uint8_t pad[2];
2079 2080
};

2081 2082 2083
/**
 * Definition of a DMUB_CMD__ABM_SET_BACKLIGHT command.
 */
2084
struct dmub_rb_cmd_abm_set_backlight {
2085 2086 2087
	/**
	 * Command header.
	 */
2088
	struct dmub_cmd_header header;
2089 2090 2091 2092

	/**
	 * Data passed from driver to FW in a DMUB_CMD__ABM_SET_BACKLIGHT command.
	 */
2093 2094 2095
	struct dmub_cmd_abm_set_backlight_data abm_set_backlight_data;
};

2096 2097 2098
/**
 * Data passed from driver to FW in a DMUB_CMD__ABM_SET_LEVEL command.
 */
2099
struct dmub_cmd_abm_set_level_data {
2100 2101 2102
	/**
	 * Set current ABM operating/aggression level.
	 */
2103
	uint32_t level;
2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120

	/**
	 * ABM control version.
	 */
	uint8_t version;

	/**
	 * Panel Control HW instance mask.
	 * Bit 0 is Panel Control HW instance 0.
	 * Bit 1 is Panel Control HW instance 1.
	 */
	uint8_t panel_mask;

	/**
	 * Explicit padding to 4 byte boundary.
	 */
	uint8_t pad[2];
2121 2122
};

2123 2124 2125
/**
 * Definition of a DMUB_CMD__ABM_SET_LEVEL command.
 */
2126
struct dmub_rb_cmd_abm_set_level {
2127 2128 2129
	/**
	 * Command header.
	 */
2130
	struct dmub_cmd_header header;
2131 2132 2133 2134

	/**
	 * Data passed from driver to FW in a DMUB_CMD__ABM_SET_LEVEL command.
	 */
2135 2136 2137
	struct dmub_cmd_abm_set_level_data abm_set_level_data;
};

2138 2139 2140
/**
 * Data passed from driver to FW in a DMUB_CMD__ABM_SET_AMBIENT_LEVEL command.
 */
2141
struct dmub_cmd_abm_set_ambient_level_data {
2142 2143 2144
	/**
	 * Ambient light sensor reading from OS.
	 */
2145
	uint32_t ambient_lux;
2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162

	/**
	 * ABM control version.
	 */
	uint8_t version;

	/**
	 * Panel Control HW instance mask.
	 * Bit 0 is Panel Control HW instance 0.
	 * Bit 1 is Panel Control HW instance 1.
	 */
	uint8_t panel_mask;

	/**
	 * Explicit padding to 4 byte boundary.
	 */
	uint8_t pad[2];
2163 2164
};

2165 2166 2167
/**
 * Definition of a DMUB_CMD__ABM_SET_AMBIENT_LEVEL command.
 */
2168
struct dmub_rb_cmd_abm_set_ambient_level {
2169 2170 2171
	/**
	 * Command header.
	 */
2172
	struct dmub_cmd_header header;
2173 2174 2175 2176

	/**
	 * Data passed from driver to FW in a DMUB_CMD__ABM_SET_AMBIENT_LEVEL command.
	 */
2177 2178 2179
	struct dmub_cmd_abm_set_ambient_level_data abm_set_ambient_level_data;
};

2180 2181 2182
/**
 * Data passed from driver to FW in a DMUB_CMD__ABM_SET_PWM_FRAC command.
 */
2183
struct dmub_cmd_abm_set_pwm_frac_data {
2184 2185 2186 2187
	/**
	 * Enable/disable fractional duty cycle for backlight PWM.
	 * TODO: Convert to uint8_t.
	 */
2188
	uint32_t fractional_pwm;
2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205

	/**
	 * ABM control version.
	 */
	uint8_t version;

	/**
	 * Panel Control HW instance mask.
	 * Bit 0 is Panel Control HW instance 0.
	 * Bit 1 is Panel Control HW instance 1.
	 */
	uint8_t panel_mask;

	/**
	 * Explicit padding to 4 byte boundary.
	 */
	uint8_t pad[2];
2206 2207
};

2208 2209 2210
/**
 * Definition of a DMUB_CMD__ABM_SET_PWM_FRAC command.
 */
2211
struct dmub_rb_cmd_abm_set_pwm_frac {
2212 2213 2214
	/**
	 * Command header.
	 */
2215
	struct dmub_cmd_header header;
2216 2217 2218 2219

	/**
	 * Data passed from driver to FW in a DMUB_CMD__ABM_SET_PWM_FRAC command.
	 */
2220 2221 2222
	struct dmub_cmd_abm_set_pwm_frac_data abm_set_pwm_frac_data;
};

2223 2224 2225
/**
 * Data passed from driver to FW in a DMUB_CMD__ABM_INIT_CONFIG command.
 */
2226
struct dmub_cmd_abm_init_config_data {
2227 2228 2229
	/**
	 * Location of indirect buffer used to pass init data to ABM.
	 */
2230
	union dmub_addr src;
2231 2232 2233 2234

	/**
	 * Indirect buffer length.
	 */
2235
	uint16_t bytes;
2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253


	/**
	 * ABM control version.
	 */
	uint8_t version;

	/**
	 * Panel Control HW instance mask.
	 * Bit 0 is Panel Control HW instance 0.
	 * Bit 1 is Panel Control HW instance 1.
	 */
	uint8_t panel_mask;

	/**
	 * Explicit padding to 4 byte boundary.
	 */
	uint8_t pad[2];
2254 2255
};

2256 2257 2258
/**
 * Definition of a DMUB_CMD__ABM_INIT_CONFIG command.
 */
2259
struct dmub_rb_cmd_abm_init_config {
2260 2261 2262
	/**
	 * Command header.
	 */
2263
	struct dmub_cmd_header header;
2264 2265 2266 2267

	/**
	 * Data passed from driver to FW in a DMUB_CMD__ABM_INIT_CONFIG command.
	 */
2268 2269 2270
	struct dmub_cmd_abm_init_config_data abm_init_config_data;
};

2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314
/**
 * Data passed from driver to FW in a DMUB_CMD__ABM_PAUSE command.
 */

struct dmub_cmd_abm_pause_data {

	/**
	 * Panel Control HW instance mask.
	 * Bit 0 is Panel Control HW instance 0.
	 * Bit 1 is Panel Control HW instance 1.
	 */
	uint8_t panel_mask;

	/**
	 * OTG hw instance
	 */
	uint8_t otg_inst;

	/**
	 * Enable or disable ABM pause
	 */
	uint8_t enable;

	/**
	 * Explicit padding to 4 byte boundary.
	 */
	uint8_t pad[1];
};

/**
 * Definition of a DMUB_CMD__ABM_PAUSE command.
 */
struct dmub_rb_cmd_abm_pause {
	/**
	 * Command header.
	 */
	struct dmub_cmd_header header;

	/**
	 * Data passed from driver to FW in a DMUB_CMD__ABM_PAUSE command.
	 */
	struct dmub_cmd_abm_pause_data abm_pause_data;
};

2315 2316 2317
/**
 * Data passed from driver to FW in a DMUB_CMD__QUERY_FEATURE_CAPS command.
 */
2318
struct dmub_cmd_query_feature_caps_data {
2319 2320 2321 2322 2323
	/**
	 * DMUB feature capabilities.
	 * After DMUB init, driver will query FW capabilities prior to enabling certain features.
	 */
	struct dmub_feature_caps feature_caps;
2324 2325
};

2326 2327 2328
/**
 * Definition of a DMUB_CMD__QUERY_FEATURE_CAPS command.
 */
2329
struct dmub_rb_cmd_query_feature_caps {
2330 2331 2332 2333 2334 2335 2336 2337
	/**
	 * Command header.
	 */
	struct dmub_cmd_header header;
	/**
	 * Data passed from driver to FW in a DMUB_CMD__QUERY_FEATURE_CAPS command.
	 */
	struct dmub_cmd_query_feature_caps_data query_feature_caps_data;
2338 2339
};

2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354
struct dmub_optc_state {
	uint32_t v_total_max;
	uint32_t v_total_min;
	uint32_t v_total_mid;
	uint32_t v_total_mid_frame_num;
	uint32_t tg_inst;
	uint32_t enable_manual_trigger;
	uint32_t clear_force_vsync;
};

struct dmub_rb_cmd_drr_update {
		struct dmub_cmd_header header;
		struct dmub_optc_state dmub_optc_state_req;
};

2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389
/**
 * enum dmub_cmd_panel_cntl_type - Panel control command.
 */
enum dmub_cmd_panel_cntl_type {
	/**
	 * Initializes embedded panel hardware blocks.
	 */
	DMUB_CMD__PANEL_CNTL_HW_INIT = 0,
	/**
	 * Queries backlight info for the embedded panel.
	 */
	DMUB_CMD__PANEL_CNTL_QUERY_BACKLIGHT_INFO = 1,
};

/**
 * struct dmub_cmd_panel_cntl_data - Panel control data.
 */
struct dmub_cmd_panel_cntl_data {
	uint32_t inst; /**< panel instance */
	uint32_t current_backlight; /* in/out */
	uint32_t bl_pwm_cntl; /* in/out */
	uint32_t bl_pwm_period_cntl; /* in/out */
	uint32_t bl_pwm_ref_div1; /* in/out */
	uint8_t is_backlight_on : 1; /* in/out */
	uint8_t is_powered_on : 1; /* in/out */
};

/**
 * struct dmub_rb_cmd_panel_cntl - Panel control command.
 */
struct dmub_rb_cmd_panel_cntl {
	struct dmub_cmd_header header; /**< header */
	struct dmub_cmd_panel_cntl_data data; /**< payload */
};

2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413
/**
 * Data passed from driver to FW in a DMUB_CMD__VBIOS_LVTMA_CONTROL command.
 */
struct dmub_cmd_lvtma_control_data {
	uint8_t uc_pwr_action; /**< LVTMA_ACTION */
	uint8_t reserved_0[3]; /**< For future use */
	uint8_t panel_inst; /**< LVTMA control instance */
	uint8_t reserved_1[3]; /**< For future use */
};

/**
 * Definition of a DMUB_CMD__VBIOS_LVTMA_CONTROL command.
 */
struct dmub_rb_cmd_lvtma_control {
	/**
	 * Command header.
	 */
	struct dmub_cmd_header header;
	/**
	 * Data passed from driver to FW in a DMUB_CMD__VBIOS_LVTMA_CONTROL command.
	 */
	struct dmub_cmd_lvtma_control_data data;
};

2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431
/**
 * Data passed in/out in a DMUB_CMD__VBIOS_TRANSMITTER_QUERY_DP_ALT command.
 */
struct dmub_rb_cmd_transmitter_query_dp_alt_data {
	uint8_t phy_id; /**< 0=UNIPHYA, 1=UNIPHYB, 2=UNIPHYC, 3=UNIPHYD, 4=UNIPHYE, 5=UNIPHYF */
	uint8_t is_usb; /**< is phy is usb */
	uint8_t is_dp_alt_disable; /**< is dp alt disable */
	uint8_t is_dp4; /**< is dp in 4 lane */
};

/**
 * Definition of a DMUB_CMD__VBIOS_TRANSMITTER_QUERY_DP_ALT command.
 */
struct dmub_rb_cmd_transmitter_query_dp_alt {
	struct dmub_cmd_header header; /**< header */
	struct dmub_rb_cmd_transmitter_query_dp_alt_data data; /**< payload */
};

2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442
/**
 * Maximum number of bytes a chunk sent to DMUB for parsing
 */
#define DMUB_EDID_CEA_DATA_CHUNK_BYTES 8

/**
 *  Represent a chunk of CEA blocks sent to DMUB for parsing
 */
struct dmub_cmd_send_edid_cea {
	uint16_t offset;	/**< offset into the CEA block */
	uint8_t length;	/**< number of bytes in payload to copy as part of CEA block */
2443
	uint16_t cea_total_length;  /**< total length of the CEA block */
2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493
	uint8_t payload[DMUB_EDID_CEA_DATA_CHUNK_BYTES]; /**< data chunk of the CEA block */
	uint8_t pad[3]; /**< padding and for future expansion */
};

/**
 * Result of VSDB parsing from CEA block
 */
struct dmub_cmd_edid_cea_amd_vsdb {
	uint8_t vsdb_found;		/**< 1 if parsing has found valid AMD VSDB */
	uint8_t freesync_supported;	/**< 1 if Freesync is supported */
	uint16_t amd_vsdb_version;	/**< AMD VSDB version */
	uint16_t min_frame_rate;	/**< Maximum frame rate */
	uint16_t max_frame_rate;	/**< Minimum frame rate */
};

/**
 * Result of sending a CEA chunk
 */
struct dmub_cmd_edid_cea_ack {
	uint16_t offset;	/**< offset of the chunk into the CEA block */
	uint8_t success;	/**< 1 if this sending of chunk succeeded */
	uint8_t pad;		/**< padding and for future expansion */
};

/**
 * Specify whether the result is an ACK/NACK or the parsing has finished
 */
enum dmub_cmd_edid_cea_reply_type {
	DMUB_CMD__EDID_CEA_AMD_VSDB	= 1, /**< VSDB parsing has finished */
	DMUB_CMD__EDID_CEA_ACK		= 2, /**< acknowledges the CEA sending is OK or failing */
};

/**
 * Definition of a DMUB_CMD__EDID_CEA command.
 */
struct dmub_rb_cmd_edid_cea {
	struct dmub_cmd_header header;	/**< Command header */
	union dmub_cmd_edid_cea_data {
		struct dmub_cmd_send_edid_cea input; /**< input to send CEA chunks */
		struct dmub_cmd_edid_cea_output { /**< output with results */
			uint8_t type;	/**< dmub_cmd_edid_cea_reply_type */
			union {
				struct dmub_cmd_edid_cea_amd_vsdb amd_vsdb;
				struct dmub_cmd_edid_cea_ack ack;
			};
		} output;	/**< output to retrieve ACK/NACK or VSDB parsing results */
	} data;	/**< Command data */

};

2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525
/**
 * struct dmub_cmd_cable_id_input - Defines the input of DMUB_CMD_GET_USBC_CABLE_ID command.
 */
struct dmub_cmd_cable_id_input {
	uint8_t phy_inst;  /**< phy inst for cable id data */
};

/**
 * struct dmub_cmd_cable_id_input - Defines the output of DMUB_CMD_GET_USBC_CABLE_ID command.
 */
struct dmub_cmd_cable_id_output {
	uint8_t UHBR10_20_CAPABILITY	:2; /**< b'01 for UHBR10 support, b'10 for both UHBR10 and UHBR20 support */
	uint8_t UHBR13_5_CAPABILITY	:1; /**< b'1 for UHBR13.5 support */
	uint8_t CABLE_TYPE		:3; /**< b'01 for passive cable, b'10 for active LRD cable, b'11 for active retimer cable */
	uint8_t RESERVED		:2; /**< reserved means not defined */
};

/**
 * Definition of a DMUB_CMD_GET_USBC_CABLE_ID command
 */
struct dmub_rb_cmd_get_usbc_cable_id {
	struct dmub_cmd_header header; /**< Command header */
	/**
	 * Data passed from driver to FW in a DMUB_CMD_GET_USBC_CABLE_ID command.
	 */
	union dmub_cmd_cable_id_data {
		struct dmub_cmd_cable_id_input input; /**< Input */
		struct dmub_cmd_cable_id_output output; /**< Output */
		uint8_t output_raw; /**< Raw data output */
	} data;
};

2526 2527 2528
/**
 * union dmub_rb_cmd - DMUB inbox command.
 */
2529
union dmub_rb_cmd {
2530
	struct dmub_rb_cmd_lock_hw lock_hw;
2531 2532 2533 2534 2535 2536 2537
	/**
	 * Elements shared with all commands.
	 */
	struct dmub_rb_cmd_common cmd_common;
	/**
	 * Definition of a DMUB_CMD__REG_SEQ_READ_MODIFY_WRITE command.
	 */
2538
	struct dmub_rb_cmd_read_modify_write read_modify_write;
2539 2540 2541
	/**
	 * Definition of a DMUB_CMD__REG_SEQ_FIELD_UPDATE_SEQ command.
	 */
2542
	struct dmub_rb_cmd_reg_field_update_sequence reg_field_update_seq;
2543 2544 2545
	/**
	 * Definition of a DMUB_CMD__REG_SEQ_BURST_WRITE command.
	 */
2546
	struct dmub_rb_cmd_burst_write burst_write;
2547 2548 2549
	/**
	 * Definition of a DMUB_CMD__REG_REG_WAIT command.
	 */
2550
	struct dmub_rb_cmd_reg_wait reg_wait;
2551 2552 2553
	/**
	 * Definition of a DMUB_CMD__VBIOS_DIGX_ENCODER_CONTROL command.
	 */
2554
	struct dmub_rb_cmd_digx_encoder_control digx_encoder_control;
2555 2556 2557
	/**
	 * Definition of a DMUB_CMD__VBIOS_SET_PIXEL_CLOCK command.
	 */
2558
	struct dmub_rb_cmd_set_pixel_clock set_pixel_clock;
2559 2560 2561
	/**
	 * Definition of a DMUB_CMD__VBIOS_ENABLE_DISP_POWER_GATING command.
	 */
2562
	struct dmub_rb_cmd_enable_disp_power_gating enable_disp_power_gating;
2563 2564 2565
	/**
	 * Definition of a DMUB_CMD__VBIOS_DPPHY_INIT command.
	 */
2566
	struct dmub_rb_cmd_dpphy_init dpphy_init;
2567 2568 2569
	/**
	 * Definition of a DMUB_CMD__VBIOS_DIG1_TRANSMITTER_CONTROL command.
	 */
2570
	struct dmub_rb_cmd_dig1_transmitter_control dig1_transmitter_control;
2571 2572 2573
	/**
	 * Definition of a DMUB_CMD__PSR_SET_VERSION command.
	 */
2574
	struct dmub_rb_cmd_psr_set_version psr_set_version;
2575 2576 2577
	/**
	 * Definition of a DMUB_CMD__PSR_COPY_SETTINGS command.
	 */
2578
	struct dmub_rb_cmd_psr_copy_settings psr_copy_settings;
2579 2580 2581
	/**
	 * Definition of a DMUB_CMD__PSR_ENABLE command.
	 */
2582
	struct dmub_rb_cmd_psr_enable psr_enable;
2583 2584 2585
	/**
	 * Definition of a DMUB_CMD__PSR_SET_LEVEL command.
	 */
2586
	struct dmub_rb_cmd_psr_set_level psr_set_level;
2587 2588 2589
	/**
	 * Definition of a DMUB_CMD__PSR_FORCE_STATIC command.
	 */
2590
	struct dmub_rb_cmd_psr_force_static psr_force_static;
2591 2592 2593 2594
	/**
	 * Definition of a DMUB_CMD__SET_PSR_POWER_OPT command.
	 */
	struct dmub_rb_cmd_psr_set_power_opt psr_set_power_opt;
2595 2596 2597
	/**
	 * Definition of a DMUB_CMD__PLAT_54186_WA command.
	 */
2598
	struct dmub_rb_cmd_PLAT_54186_wa PLAT_54186_wa;
2599 2600 2601
	/**
	 * Definition of a DMUB_CMD__MALL command.
	 */
2602
	struct dmub_rb_cmd_mall mall;
2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616
	/**
	 * Definition of a DMUB_CMD__IDLE_OPT_DCN_RESTORE command.
	 */
	struct dmub_rb_cmd_idle_opt_dcn_restore dcn_restore;

	/**
	 * Definition of a DMUB_CMD__CLK_MGR_NOTIFY_CLOCKS command.
	 */
	struct dmub_rb_cmd_clk_mgr_notify_clocks notify_clocks;

	/**
	 * Definition of DMUB_CMD__PANEL_CNTL commands.
	 */
	struct dmub_rb_cmd_panel_cntl panel_cntl;
2617 2618 2619
	/**
	 * Definition of a DMUB_CMD__ABM_SET_PIPE command.
	 */
2620
	struct dmub_rb_cmd_abm_set_pipe abm_set_pipe;
2621 2622 2623 2624

	/**
	 * Definition of a DMUB_CMD__ABM_SET_BACKLIGHT command.
	 */
2625
	struct dmub_rb_cmd_abm_set_backlight abm_set_backlight;
2626 2627 2628 2629

	/**
	 * Definition of a DMUB_CMD__ABM_SET_LEVEL command.
	 */
2630
	struct dmub_rb_cmd_abm_set_level abm_set_level;
2631 2632 2633 2634

	/**
	 * Definition of a DMUB_CMD__ABM_SET_AMBIENT_LEVEL command.
	 */
2635
	struct dmub_rb_cmd_abm_set_ambient_level abm_set_ambient_level;
2636 2637 2638 2639

	/**
	 * Definition of a DMUB_CMD__ABM_SET_PWM_FRAC command.
	 */
2640
	struct dmub_rb_cmd_abm_set_pwm_frac abm_set_pwm_frac;
2641 2642 2643 2644

	/**
	 * Definition of a DMUB_CMD__ABM_INIT_CONFIG command.
	 */
2645
	struct dmub_rb_cmd_abm_init_config abm_init_config;
2646

2647 2648 2649 2650 2651
	/**
	 * Definition of a DMUB_CMD__ABM_PAUSE command.
	 */
	struct dmub_rb_cmd_abm_pause abm_pause;

2652 2653 2654
	/**
	 * Definition of a DMUB_CMD__DP_AUX_ACCESS command.
	 */
2655
	struct dmub_rb_cmd_dp_aux_access dp_aux_access;
2656

2657 2658 2659
	/**
	 * Definition of a DMUB_CMD__OUTBOX1_ENABLE command.
	 */
2660
	struct dmub_rb_cmd_outbox1_enable outbox1_enable;
2661

2662
	/**
2663
	 * Definition of a DMUB_CMD__QUERY_FEATURE_CAPS command.
2664
	 */
2665
	struct dmub_rb_cmd_query_feature_caps query_feature_caps;
2666
	struct dmub_rb_cmd_drr_update drr_update;
2667 2668 2669 2670
	/**
	 * Definition of a DMUB_CMD__VBIOS_LVTMA_CONTROL command.
	 */
	struct dmub_rb_cmd_lvtma_control lvtma_control;
2671 2672 2673 2674
	/**
	 * Definition of a DMUB_CMD__VBIOS_TRANSMITTER_QUERY_DP_ALT command.
	 */
	struct dmub_rb_cmd_transmitter_query_dp_alt query_dp_alt;
2675 2676 2677 2678
	/**
	 * Definition of a DMUB_CMD__DPIA_DIG1_CONTROL command.
	 */
	struct dmub_rb_cmd_dig1_dpia_control dig1_dpia_control;
2679 2680 2681 2682
	/**
	 * Definition of a DMUB_CMD__DPIA_SET_CONFIG_ACCESS command.
	 */
	struct dmub_rb_cmd_set_config_access set_config_access;
2683 2684 2685 2686
	/**
	 * Definition of a DMUB_CMD__DPIA_MST_ALLOC_SLOTS command.
	 */
	struct dmub_rb_cmd_set_mst_alloc_slots set_mst_alloc_slots;
2687 2688 2689 2690
	/**
	 * Definition of a DMUB_CMD__EDID_CEA command.
	 */
	struct dmub_rb_cmd_edid_cea edid_cea;
2691 2692 2693 2694
	/**
	 * Definition of a DMUB_CMD_GET_USBC_CABLE_ID command.
	 */
	struct dmub_rb_cmd_get_usbc_cable_id cable_id;
2695 2696
};

2697 2698 2699
/**
 * union dmub_rb_out_cmd - Outbox command
 */
2700
union dmub_rb_out_cmd {
2701 2702 2703
	/**
	 * Parameters common to every command.
	 */
2704
	struct dmub_rb_cmd_common cmd_common;
2705 2706 2707
	/**
	 * AUX reply command.
	 */
2708
	struct dmub_rb_cmd_dp_aux_reply dp_aux_reply;
2709 2710 2711
	/**
	 * HPD notify command.
	 */
2712
	struct dmub_rb_cmd_dp_hpd_notify dp_hpd_notify;
2713 2714 2715 2716
	/**
	 * SET_CONFIG reply command.
	 */
	struct dmub_rb_cmd_dp_set_config_reply set_config_reply;
2717
};
2718 2719
#pragma pack(pop)

2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730

//==============================================================================
//</DMUB_CMD>===================================================================
//==============================================================================
//< DMUB_RB>====================================================================
//==============================================================================

#if defined(__cplusplus)
extern "C" {
#endif

2731 2732 2733
/**
 * struct dmub_rb_init_params - Initialization params for DMUB ringbuffer
 */
2734
struct dmub_rb_init_params {
2735 2736 2737 2738 2739
	void *ctx; /**< Caller provided context pointer */
	void *base_address; /**< CPU base address for ring's data */
	uint32_t capacity; /**< Ringbuffer capacity in bytes */
	uint32_t read_ptr; /**< Initial read pointer for consumer in bytes */
	uint32_t write_ptr; /**< Initial write pointer for producer in bytes */
2740 2741
};

2742 2743 2744
/**
 * struct dmub_rb - Inbox or outbox DMUB ringbuffer
 */
2745
struct dmub_rb {
2746 2747 2748 2749
	void *base_address; /**< CPU address for the ring's data */
	uint32_t rptr; /**< Read pointer for consumer in bytes */
	uint32_t wrpt; /**< Write pointer for producer in bytes */
	uint32_t capacity; /**< Ringbuffer capacity in bytes */
2750

2751 2752
	void *ctx; /**< Caller provided context pointer */
	void *dmub; /**< Pointer to the DMUB interface */
2753 2754
};

2755 2756 2757 2758 2759 2760 2761
/**
 * @brief Checks if the ringbuffer is empty.
 *
 * @param rb DMUB Ringbuffer
 * @return true if empty
 * @return false otherwise
 */
2762 2763 2764 2765 2766
static inline bool dmub_rb_empty(struct dmub_rb *rb)
{
	return (rb->wrpt == rb->rptr);
}

2767 2768 2769 2770 2771 2772 2773
/**
 * @brief Checks if the ringbuffer is full
 *
 * @param rb DMUB Ringbuffer
 * @return true if full
 * @return false otherwise
 */
2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785
static inline bool dmub_rb_full(struct dmub_rb *rb)
{
	uint32_t data_count;

	if (rb->wrpt >= rb->rptr)
		data_count = rb->wrpt - rb->rptr;
	else
		data_count = rb->capacity - (rb->rptr - rb->wrpt);

	return (data_count == (rb->capacity - DMUB_RB_CMD_SIZE));
}

2786 2787 2788 2789 2790 2791 2792 2793
/**
 * @brief Pushes a command into the ringbuffer
 *
 * @param rb DMUB ringbuffer
 * @param cmd The command to push
 * @return true if the ringbuffer was not full
 * @return false otherwise
 */
2794 2795 2796
static inline bool dmub_rb_push_front(struct dmub_rb *rb,
				      const union dmub_rb_cmd *cmd)
{
2797
	uint64_t volatile *dst = (uint64_t volatile *)((uint8_t *)(rb->base_address) + rb->wrpt);
2798 2799
	const uint64_t *src = (const uint64_t *)cmd;
	uint8_t i;
2800 2801 2802 2803 2804

	if (dmub_rb_full(rb))
		return false;

	// copying data
2805 2806
	for (i = 0; i < DMUB_RB_CMD_SIZE / sizeof(uint64_t); i++)
		*dst++ = *src++;
2807 2808 2809 2810 2811 2812 2813 2814 2815

	rb->wrpt += DMUB_RB_CMD_SIZE;

	if (rb->wrpt >= rb->capacity)
		rb->wrpt %= rb->capacity;

	return true;
}

2816 2817 2818 2819 2820 2821 2822 2823
/**
 * @brief Pushes a command into the DMUB outbox ringbuffer
 *
 * @param rb DMUB outbox ringbuffer
 * @param cmd Outbox command
 * @return true if not full
 * @return false otherwise
 */
2824 2825 2826 2827
static inline bool dmub_rb_out_push_front(struct dmub_rb *rb,
				      const union dmub_rb_out_cmd *cmd)
{
	uint8_t *dst = (uint8_t *)(rb->base_address) + rb->wrpt;
2828
	const uint8_t *src = (const uint8_t *)cmd;
2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842

	if (dmub_rb_full(rb))
		return false;

	dmub_memcpy(dst, src, DMUB_RB_CMD_SIZE);

	rb->wrpt += DMUB_RB_CMD_SIZE;

	if (rb->wrpt >= rb->capacity)
		rb->wrpt %= rb->capacity;

	return true;
}

2843 2844 2845 2846 2847 2848 2849 2850
/**
 * @brief Returns the next unprocessed command in the ringbuffer.
 *
 * @param rb DMUB ringbuffer
 * @param cmd The command to return
 * @return true if not empty
 * @return false otherwise
 */
2851
static inline bool dmub_rb_front(struct dmub_rb *rb,
2852
				 union dmub_rb_cmd  **cmd)
2853
{
2854
	uint8_t *rb_cmd = (uint8_t *)(rb->base_address) + rb->rptr;
2855 2856 2857 2858

	if (dmub_rb_empty(rb))
		return false;

2859
	*cmd = (union dmub_rb_cmd *)rb_cmd;
2860 2861 2862 2863

	return true;
}

2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903
/**
 * @brief Determines the next ringbuffer offset.
 *
 * @param rb DMUB inbox ringbuffer
 * @param num_cmds Number of commands
 * @param next_rptr The next offset in the ringbuffer
 */
static inline void dmub_rb_get_rptr_with_offset(struct dmub_rb *rb,
				  uint32_t num_cmds,
				  uint32_t *next_rptr)
{
	*next_rptr = rb->rptr + DMUB_RB_CMD_SIZE * num_cmds;

	if (*next_rptr >= rb->capacity)
		*next_rptr %= rb->capacity;
}

/**
 * @brief Returns a pointer to a command in the inbox.
 *
 * @param rb DMUB inbox ringbuffer
 * @param cmd The inbox command to return
 * @param rptr The ringbuffer offset
 * @return true if not empty
 * @return false otherwise
 */
static inline bool dmub_rb_peek_offset(struct dmub_rb *rb,
				 union dmub_rb_cmd  **cmd,
				 uint32_t rptr)
{
	uint8_t *rb_cmd = (uint8_t *)(rb->base_address) + rptr;

	if (dmub_rb_empty(rb))
		return false;

	*cmd = (union dmub_rb_cmd *)rb_cmd;

	return true;
}

2904 2905 2906 2907 2908 2909 2910 2911
/**
 * @brief Returns the next unprocessed command in the outbox.
 *
 * @param rb DMUB outbox ringbuffer
 * @param cmd The outbox command to return
 * @return true if not empty
 * @return false otherwise
 */
2912
static inline bool dmub_rb_out_front(struct dmub_rb *rb,
2913
				 union dmub_rb_out_cmd *cmd)
2914
{
2915
	const uint64_t volatile *src = (const uint64_t volatile *)((uint8_t *)(rb->base_address) + rb->rptr);
2916 2917
	uint64_t *dst = (uint64_t *)cmd;
	uint8_t i;
2918 2919 2920 2921 2922

	if (dmub_rb_empty(rb))
		return false;

	// copying data
2923 2924
	for (i = 0; i < DMUB_RB_CMD_SIZE / sizeof(uint64_t); i++)
		*dst++ = *src++;
2925 2926 2927 2928

	return true;
}

2929 2930 2931 2932 2933 2934 2935
/**
 * @brief Removes the front entry in the ringbuffer.
 *
 * @param rb DMUB ringbuffer
 * @return true if the command was removed
 * @return false if there were no commands
 */
2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948
static inline bool dmub_rb_pop_front(struct dmub_rb *rb)
{
	if (dmub_rb_empty(rb))
		return false;

	rb->rptr += DMUB_RB_CMD_SIZE;

	if (rb->rptr >= rb->capacity)
		rb->rptr %= rb->capacity;

	return true;
}

2949 2950 2951 2952 2953 2954 2955 2956
/**
 * @brief Flushes commands in the ringbuffer to framebuffer memory.
 *
 * Avoids a race condition where DMCUB accesses memory while
 * there are still writes in flight to framebuffer.
 *
 * @param rb DMUB ringbuffer
 */
2957 2958 2959 2960 2961 2962
static inline void dmub_rb_flush_pending(const struct dmub_rb *rb)
{
	uint32_t rptr = rb->rptr;
	uint32_t wptr = rb->wrpt;

	while (rptr != wptr) {
2963
		uint64_t volatile *data = (uint64_t volatile *)((uint8_t *)(rb->base_address) + rptr);
2964 2965 2966
		//uint64_t volatile *p = (uint64_t volatile *)data;
		uint64_t temp;
		uint8_t i;
2967

2968 2969 2970 2971
		/* Don't remove this.
		 * The contents need to actually be read from the ring buffer
		 * for this function to be effective.
		 */
2972 2973
		for (i = 0; i < DMUB_RB_CMD_SIZE / sizeof(uint64_t); i++)
			temp = *data++;
2974 2975 2976 2977 2978 2979 2980

		rptr += DMUB_RB_CMD_SIZE;
		if (rptr >= rb->capacity)
			rptr %= rb->capacity;
	}
}

2981 2982 2983 2984 2985 2986
/**
 * @brief Initializes a DMCUB ringbuffer
 *
 * @param rb DMUB ringbuffer
 * @param init_params initial configuration for the ringbuffer
 */
2987 2988 2989 2990 2991 2992 2993 2994 2995
static inline void dmub_rb_init(struct dmub_rb *rb,
				struct dmub_rb_init_params *init_params)
{
	rb->base_address = init_params->base_address;
	rb->capacity = init_params->capacity;
	rb->rptr = init_params->read_ptr;
	rb->wrpt = init_params->write_ptr;
}

2996 2997 2998 2999 3000 3001
/**
 * @brief Copies output data from in/out commands into the given command.
 *
 * @param rb DMUB ringbuffer
 * @param cmd Command to copy data into
 */
3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012
static inline void dmub_rb_get_return_data(struct dmub_rb *rb,
					   union dmub_rb_cmd *cmd)
{
	// Copy rb entry back into command
	uint8_t *rd_ptr = (rb->rptr == 0) ?
		(uint8_t *)rb->base_address + rb->capacity - DMUB_RB_CMD_SIZE :
		(uint8_t *)rb->base_address + rb->rptr - DMUB_RB_CMD_SIZE;

	dmub_memcpy(cmd, rd_ptr, DMUB_RB_CMD_SIZE);
}

3013 3014 3015 3016 3017 3018 3019 3020
#if defined(__cplusplus)
}
#endif

//==============================================================================
//</DMUB_RB>====================================================================
//==============================================================================

3021
#endif /* _DMUB_CMD_H_ */