dmub_cmd.h 54.1 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 26 27 28
/*
 * 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
 *
 */

#ifndef _DMUB_CMD_H_
#define _DMUB_CMD_H_

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 43
#include <asm/byteorder.h>
#include <linux/types.h>
#include <linux/string.h>
#include <linux/delay.h>
#include <stdarg.h>

44
#include "atomfirmware.h"
45

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

48 49
/* Firmware versioning. */
#ifdef DMUB_EXPOSE_VERSION
50
#define DMUB_FW_VERSION_GIT_HASH 0x899019e5c
51
#define DMUB_FW_VERSION_MAJOR 0
52
#define DMUB_FW_VERSION_MINOR 0
53
#define DMUB_FW_VERSION_REVISION 57
54 55 56 57 58 59 60 61 62 63
#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))

64
#endif
65 66 67

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

69 70
#define __forceinline inline

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

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

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

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

94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
/**
 * 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

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

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

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

123 124 125
/**
 * Physical framebuffer address location, 64-bit.
 */
126 127 128 129
#ifndef PHYSICAL_ADDRESS_LOC
#define PHYSICAL_ADDRESS_LOC union large_integer
#endif

130 131 132
/**
 * OS/FW agnostic memcpy
 */
133 134 135 136
#ifndef dmub_memcpy
#define dmub_memcpy(dest, source, bytes) memcpy((dest), (source), (bytes))
#endif

137 138 139
/**
 * OS/FW agnostic memset
 */
140 141 142 143
#ifndef dmub_memset
#define dmub_memset(dest, val, bytes) memset((dest), (val), (bytes))
#endif

144 145 146 147
#if defined(__cplusplus)
extern "C" {
#endif

148 149 150
/**
 * OS/FW agnostic udelay
 */
151 152 153 154
#ifndef dmub_udelay
#define dmub_udelay(microseconds) udelay(microseconds)
#endif

155 156 157
/**
 * union dmub_addr - DMUB physical/virtual 64-bit address.
 */
158 159
union dmub_addr {
	struct {
160 161 162 163
		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 */
164 165
};

166 167 168
/**
 * Flags that can be set by driver to change some PSR behaviour.
 */
169
union dmub_psr_debug_flags {
170 171 172
	/**
	 * Debug flags.
	 */
173
	struct {
174 175 176
		/**
		 * Enable visual confirm in FW.
		 */
177
		uint32_t visual_confirm : 1;
178 179 180
		/**
		 * Use HW Lock Mgr object to do HW locking in FW.
		 */
181
		uint32_t use_hw_lock_mgr : 1;
182 183 184 185 186

		/**
		 * Unused.
		 * TODO: Remove.
		 */
187
		uint32_t log_line_nums : 1;
188 189
	} bitfields;

190 191 192
	/**
	 * Union for debug flags.
	 */
193
	uint32_t u32All;
194 195
};

196 197 198 199
/**
 * DMUB feature capabilities.
 * After DMUB init, driver will query FW capabilities prior to enabling certain features.
 */
200
struct dmub_feature_caps {
201 202 203
	/**
	 * Max PSR version supported by FW.
	 */
204 205 206 207
	uint8_t psr;
	uint8_t reserved[7];
};

208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
#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
236
 * @dal_fw: 1 if the firmware is DAL
237 238
 */
struct dmub_fw_meta_info {
239 240 241 242 243 244
	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 */
245 246
};

247 248 249
/**
 * union dmub_fw_meta - ensures that dmub_fw_meta_info remains 64 bytes
 */
250
union dmub_fw_meta {
251 252
	struct dmub_fw_meta_info info; /**< metadata info */
	uint8_t reserved[64]; /**< padding bits */
253 254 255
};

#pragma pack(pop)
256

257 258 259
//==============================================================================
//< DMUB Trace Buffer>================================================================
//==============================================================================
260 261 262
/**
 * dmub_trace_code_t - firmware trace code, 32-bits
 */
263 264
typedef uint32_t dmub_trace_code_t;

265 266 267
/**
 * struct dmcub_trace_buf_entry - Firmware trace entry
 */
268
struct dmcub_trace_buf_entry {
269 270 271 272
	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 */
273 274
};

275 276 277 278 279 280 281 282
//==============================================================================
//< DMUB_STATUS>================================================================
//==============================================================================

/**
 * DMCUB scratch registers can be used to determine firmware status.
 * Current scratch register usage is as follows:
 *
283 284
 * SCRATCH0: FW Boot Status register
 * SCRATCH15: FW Boot Options register
285 286
 */

287 288 289
/**
 * union dmub_fw_boot_status - Status bit definitions for SCRATCH0.
 */
290 291
union dmub_fw_boot_status {
	struct {
292 293 294 295 296 297
		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 */
	} bits; /**< status bits */
	uint32_t all; /**< 32-bit access to status bits */
298 299
};

300 301 302
/**
 * enum dmub_fw_boot_status_bit - Enum bit definitions for SCRATCH0.
 */
303
enum dmub_fw_boot_status_bit {
304 305 306 307
	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 */
308 309
};

310 311 312
/**
 * union dmub_fw_boot_options - Boot option definitions for SCRATCH15
 */
313 314
union dmub_fw_boot_options {
	struct {
315 316 317 318 319 320 321 322 323
		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 */
		uint32_t reserved : 26; /**< reserved */
	} bits; /**< boot bits */
	uint32_t all; /**< 32-bit access to bits */
324 325 326
};

enum dmub_fw_boot_options_bit {
327 328 329
	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 */
330 331
};

332
//==============================================================================
333
//</DMUB_STATUS>================================================================
334 335 336 337 338
//==============================================================================
//< DMUB_VBIOS>=================================================================
//==============================================================================

/*
339 340
 * enum dmub_cmd_vbios_type - VBIOS commands.
 *
341 342 343 344
 * Command IDs should be treated as stable ABI.
 * Do not reuse or modify IDs.
 */
enum dmub_cmd_vbios_type {
345 346 347
	/**
	 * Configures the DIG encoder.
	 */
348
	DMUB_CMD__VBIOS_DIGX_ENCODER_CONTROL = 0,
349 350 351
	/**
	 * Controls the PHY.
	 */
352
	DMUB_CMD__VBIOS_DIG1_TRANSMITTER_CONTROL = 1,
353 354 355
	/**
	 * Sets the pixel clock/symbol clock.
	 */
356
	DMUB_CMD__VBIOS_SET_PIXEL_CLOCK = 2,
357 358 359
	/**
	 * Enables or disables power gating.
	 */
360
	DMUB_CMD__VBIOS_ENABLE_DISP_POWER_GATING = 3,
361
	DMUB_CMD__VBIOS_LVTMA_CONTROL = 15,
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387
};

//==============================================================================
//</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.
 */

388 389 390
/**
 * Return response for DMUB_GPINT__STOP_FW command.
 */
391 392 393
#define DMUB_GPINT__STOP_FW_RESPONSE 0xDEADDEAD

/**
394
 * union dmub_gpint_data_register - Format for sending a command via the GPINT.
395 396 397
 */
union dmub_gpint_data_register {
	struct {
398 399 400 401 402
		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 */
403 404 405
};

/*
406 407
 * enum dmub_gpint_command - GPINT command to DMCUB FW
 *
408 409 410 411
 * Command IDs should be treated as stable ABI.
 * Do not reuse or modify IDs.
 */
enum dmub_gpint_command {
412 413 414
	/**
	 * Invalid command, ignored.
	 */
415
	DMUB_GPINT__INVALID_COMMAND = 0,
416 417 418 419
	/**
	 * DESC: Queries the firmware version.
	 * RETURN: Firmware version.
	 */
420
	DMUB_GPINT__GET_FW_VERSION = 1,
421 422 423 424
	/**
	 * DESC: Halts the firmware.
	 * RETURN: DMUB_GPINT__STOP_FW_RESPONSE (0xDEADDEAD) when halted
	 */
425
	DMUB_GPINT__STOP_FW = 2,
426 427 428 429
	/**
	 * DESC: Get PSR state from FW.
	 * RETURN: PSR state enum. This enum may need to be converted to the legacy PSR state value.
	 */
430
	DMUB_GPINT__GET_PSR_STATE = 7,
431 432 433 434 435
	/**
	 * 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,
436 437 438 439 440 441
	/**
	 * 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.
	 */
442
	DMUB_GPINT__PSR_RESIDENCY = 9,
443 444 445 446 447 448 449 450
};

//==============================================================================
//</DMUB_GPINT>=================================================================
//==============================================================================
//< DMUB_CMD>===================================================================
//==============================================================================

451 452 453
/**
 * Size in bytes of each DMUB command.
 */
454
#define DMUB_RB_CMD_SIZE 64
455 456 457 458

/**
 * Maximum number of items in the DMUB ringbuffer.
 */
459
#define DMUB_RB_MAX_ENTRY 128
460 461 462 463

/**
 * Ringbuffer size in bytes.
 */
464
#define DMUB_RB_SIZE (DMUB_RB_CMD_SIZE * DMUB_RB_MAX_ENTRY)
465 466 467 468

/**
 * REG_SET mask for reg offload.
 */
469 470
#define REG_SET_MASK 0xFFFF

471
/*
472 473
 * enum dmub_cmd_type - DMUB inbox command.
 *
474 475 476 477
 * Command IDs should be treated as stable ABI.
 * Do not reuse or modify IDs.
 */
enum dmub_cmd_type {
478 479 480
	/**
	 * Invalid command.
	 */
481
	DMUB_CMD__NULL = 0,
482 483 484
	/**
	 * Read modify write register sequence offload.
	 */
485
	DMUB_CMD__REG_SEQ_READ_MODIFY_WRITE = 1,
486 487 488
	/**
	 * Field update register sequence offload.
	 */
489
	DMUB_CMD__REG_SEQ_FIELD_UPDATE_SEQ = 2,
490 491 492
	/**
	 * Burst write sequence offload.
	 */
493
	DMUB_CMD__REG_SEQ_BURST_WRITE = 3,
494 495 496
	/**
	 * Reg wait sequence offload.
	 */
497
	DMUB_CMD__REG_REG_WAIT = 4,
498 499 500
	/**
	 * Workaround to avoid HUBP underflow during NV12 playback.
	 */
501
	DMUB_CMD__PLAT_54186_WA = 5,
502 503 504
	/**
	 * Command type used to query FW feature caps.
	 */
505
	DMUB_CMD__QUERY_FEATURE_CAPS = 6,
506 507 508
	/**
	 * Command type used for all PSR commands.
	 */
509
	DMUB_CMD__PSR = 64,
510 511 512
	/**
	 * Command type used for all MALL commands.
	 */
513
	DMUB_CMD__MALL = 65,
514 515 516
	/**
	 * Command type used for all ABM commands.
	 */
517
	DMUB_CMD__ABM = 66,
518 519 520
	/**
	 * Command type used for HW locking in FW.
	 */
521
	DMUB_CMD__HW_LOCK = 69,
522 523 524
	/**
	 * Command type used to access DP AUX.
	 */
525
	DMUB_CMD__DP_AUX_ACCESS = 70,
526 527 528
	/**
	 * Command type used for OUTBOX1 notification enable
	 */
529
	DMUB_CMD__OUTBOX1_ENABLE = 71,
530 531 532
	/**
	 * Command type used for all VBIOS interface commands.
	 */
533
	DMUB_CMD__VBIOS = 128,
534 535
};

536 537 538
/**
 * enum dmub_out_cmd_type - DMUB outbox commands.
 */
539
enum dmub_out_cmd_type {
540 541 542
	/**
	 * Invalid outbox command, ignored.
	 */
543
	DMUB_OUT_CMD__NULL = 0,
544 545 546
	/**
	 * Command type used for DP AUX Reply data notification
	 */
547
	DMUB_OUT_CMD__DP_AUX_REPLY = 1,
548 549 550
	/**
	 * Command type used for DP HPD event notification
	 */
551
	DMUB_OUT_CMD__DP_HPD_NOTIFY = 2,
552 553
};

554 555
#pragma pack(push, 1)

556 557 558
/**
 * struct dmub_cmd_header - Common command header fields.
 */
559
struct dmub_cmd_header {
560 561 562 563 564 565
	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 */
	unsigned int reserved0 : 7; /**< reserved bits */
	unsigned int payload_bytes : 6;  /* payload excluding header - up to 60 bytes */
	unsigned int reserved1 : 2; /**< reserved bits */
566 567 568
};

/*
569
 * struct dmub_cmd_read_modify_write_sequence - Read modify write
570 571 572 573 574 575 576 577 578 579
 *
 * 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 {
580 581 582
	uint32_t addr; /**< register address */
	uint32_t modify_mask; /**< modify mask */
	uint32_t modify_value; /**< modify value */
583 584
};

585 586 587 588 589 590 591 592
/**
 * 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.
 */
593
struct dmub_rb_cmd_read_modify_write {
594 595 596 597
	struct dmub_cmd_header header;  /**< command header */
	/**
	 * Read modify write sequence.
	 */
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614
	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 {
615 616
	uint32_t modify_mask; /**< 0xffff'ffff to skip initial read */
	uint32_t modify_value; /**< value to update with */
617 618
};

619 620 621 622 623 624 625 626
/**
 * 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.
 */
627
struct dmub_rb_cmd_reg_field_update_sequence {
628 629 630 631 632
	struct dmub_cmd_header header; /**< command header */
	uint32_t addr; /**< register address */
	/**
	 * Field update sequence.
	 */
633 634 635
	struct dmub_cmd_reg_field_update_sequence seq[DMUB_REG_FIELD_UPDATE_SEQ__MAX];
};

636 637 638 639 640 641

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

642
/*
643
 * struct dmub_rb_cmd_burst_write - Burst write
644 645 646 647 648 649 650 651
 *
 * 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 {
652 653 654 655 656
	struct dmub_cmd_header header; /**< command header */
	uint32_t addr; /**< register start address */
	/**
	 * Burst write register values.
	 */
657 658 659
	uint32_t write_values[DMUB_BURST_WRITE_VALUES__MAX];
};

660 661 662
/**
 * struct dmub_rb_cmd_common - Common command header
 */
663
struct dmub_rb_cmd_common {
664 665 666 667
	struct dmub_cmd_header header; /**< command header */
	/**
	 * Padding to RB_CMD_SIZE
	 */
668 669 670
	uint8_t cmd_buffer[DMUB_RB_CMD_SIZE - sizeof(struct dmub_cmd_header)];
};

671 672 673
/**
 * struct dmub_cmd_reg_wait_data - Register wait data
 */
674
struct dmub_cmd_reg_wait_data {
675 676 677 678
	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 */
679 680
};

681 682 683
/**
 * struct dmub_rb_cmd_reg_wait - Register wait command
 */
684
struct dmub_rb_cmd_reg_wait {
685 686
	struct dmub_cmd_header header; /**< Command header */
	struct dmub_cmd_reg_wait_data reg_wait; /**< Register wait data */
687 688
};

689 690 691 692 693
/**
 * struct dmub_cmd_PLAT_54186_wa - Underflow workaround
 *
 * Reprograms surface parameters to avoid underflow.
 */
694
struct dmub_cmd_PLAT_54186_wa {
695 696 697 698 699
	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 */
700
	struct {
701 702 703 704 705 706 707 708
		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 */
709 710
};

711 712 713
/**
 * struct dmub_rb_cmd_PLAT_54186_wa - Underflow workaround command
 */
714
struct dmub_rb_cmd_PLAT_54186_wa {
715 716
	struct dmub_cmd_header header; /**< Command header */
	struct dmub_cmd_PLAT_54186_wa flip; /**< Flip data */
717 718
};

719 720 721
/**
 * struct dmub_rb_cmd_mall - MALL command data.
 */
722
struct dmub_rb_cmd_mall {
723 724 725 726 727 728 729 730 731 732
	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 */
733

734 735
	uint8_t reserved1; /**< Reserved bits */
	uint8_t reserved2; /**< Reserved bits */
736 737
};

738 739 740
/**
 * struct dmub_cmd_digx_encoder_control_data - Encoder control data.
 */
741
struct dmub_cmd_digx_encoder_control_data {
742
	union dig_encoder_control_parameters_v1_5 dig; /**< payload */
743 744
};

745 746 747
/**
 * struct dmub_rb_cmd_digx_encoder_control - Encoder control command.
 */
748
struct dmub_rb_cmd_digx_encoder_control {
749 750
	struct dmub_cmd_header header;  /**< header */
	struct dmub_cmd_digx_encoder_control_data encoder_control; /**< payload */
751 752
};

753 754 755
/**
 * struct dmub_cmd_set_pixel_clock_data - Set pixel clock data.
 */
756
struct dmub_cmd_set_pixel_clock_data {
757
	struct set_pixel_clock_parameter_v1_7 clk; /**< payload */
758 759
};

760 761 762
/**
 * struct dmub_cmd_set_pixel_clock_data - Set pixel clock command.
 */
763
struct dmub_rb_cmd_set_pixel_clock {
764 765
	struct dmub_cmd_header header; /**< header */
	struct dmub_cmd_set_pixel_clock_data pixel_clock; /**< payload */
766 767
};

768 769 770
/**
 * struct dmub_cmd_enable_disp_power_gating_data - Display power gating.
 */
771
struct dmub_cmd_enable_disp_power_gating_data {
772
	struct enable_disp_power_gating_parameters_v2_1 pwr; /**< payload */
773 774
};

775 776 777
/**
 * struct dmub_rb_cmd_enable_disp_power_gating - Display power command.
 */
778
struct dmub_rb_cmd_enable_disp_power_gating {
779 780
	struct dmub_cmd_header header; /**< header */
	struct dmub_cmd_enable_disp_power_gating_data power_gating;  /**< payload */
781 782
};

783 784 785
/**
 * struct dmub_dig_transmitter_control_data_v1_7 - Transmitter control.
 */
786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805
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 */
	uint8_t reserved0; /**< For future use */
	uint8_t reserved1; /**< For future use */
	uint8_t reserved2[3]; /**< For future use */
	uint32_t reserved3[11]; /**< For future use */
};

806 807 808
/**
 * union dmub_cmd_dig1_transmitter_control_data - Transmitter control data.
 */
809
union dmub_cmd_dig1_transmitter_control_data {
810 811
	struct dig_transmitter_control_parameters_v1_6 dig; /**< payload */
	struct dmub_dig_transmitter_control_data_v1_7 dig_v1_7;  /**< payload 1.7 */
812 813
};

814 815 816
/**
 * struct dmub_rb_cmd_dig1_transmitter_control - Transmitter control command.
 */
817
struct dmub_rb_cmd_dig1_transmitter_control {
818 819
	struct dmub_cmd_header header; /**< header */
	union dmub_cmd_dig1_transmitter_control_data transmitter_control; /**< payload */
820 821
};

822 823 824
/**
 * struct dmub_rb_cmd_dpphy_init - DPPHY init.
 */
825
struct dmub_rb_cmd_dpphy_init {
826 827
	struct dmub_cmd_header header; /**< header */
	uint8_t reserved[60]; /**< reserved bits */
828 829
};

830 831 832 833 834
/**
 * enum dp_aux_request_action - DP AUX request command listing.
 *
 * 4 AUX request command bits are shifted to high nibble.
 */
835
enum dp_aux_request_action {
836
	/** I2C-over-AUX write request */
837
	DP_AUX_REQ_ACTION_I2C_WRITE		= 0x00,
838
	/** I2C-over-AUX read request */
839
	DP_AUX_REQ_ACTION_I2C_READ		= 0x10,
840
	/** I2C-over-AUX write status request */
841
	DP_AUX_REQ_ACTION_I2C_STATUS_REQ	= 0x20,
842
	/** I2C-over-AUX write request with MOT=1 */
843
	DP_AUX_REQ_ACTION_I2C_WRITE_MOT		= 0x40,
844
	/** I2C-over-AUX read request with MOT=1 */
845
	DP_AUX_REQ_ACTION_I2C_READ_MOT		= 0x50,
846
	/** I2C-over-AUX write status request with MOT=1 */
847
	DP_AUX_REQ_ACTION_I2C_STATUS_REQ_MOT	= 0x60,
848
	/** Native AUX write request */
849
	DP_AUX_REQ_ACTION_DPCD_WRITE		= 0x80,
850
	/** Native AUX read request */
851 852 853
	DP_AUX_REQ_ACTION_DPCD_READ		= 0x90
};

854 855 856
/**
 * enum aux_return_code_type - DP AUX process return code listing.
 */
857
enum aux_return_code_type {
858
	/** AUX process succeeded */
859
	AUX_RET_SUCCESS = 0,
860
	/** AUX process failed with unknown reason */
861
	AUX_RET_ERROR_UNKNOWN,
862
	/** AUX process completed with invalid reply */
863
	AUX_RET_ERROR_INVALID_REPLY,
864
	/** AUX process timed out */
865
	AUX_RET_ERROR_TIMEOUT,
866
	/** HPD was low during AUX process */
867
	AUX_RET_ERROR_HPD_DISCON,
868
	/** Failed to acquire AUX engine */
869
	AUX_RET_ERROR_ENGINE_ACQUIRE,
870
	/** AUX request not supported */
871
	AUX_RET_ERROR_INVALID_OPERATION,
872
	/** AUX process not available */
873 874 875
	AUX_RET_ERROR_PROTOCOL_ERROR,
};

876 877 878
/**
 * enum aux_channel_type - DP AUX channel type listing.
 */
879
enum aux_channel_type {
880
	/** AUX thru Legacy DP AUX */
881
	AUX_CHANNEL_LEGACY_DDC,
882
	/** AUX thru DPIA DP tunneling */
883 884 885
	AUX_CHANNEL_DPIA
};

886 887 888
/**
 * struct aux_transaction_parameters - DP AUX request transaction data
 */
889
struct aux_transaction_parameters {
890 891 892 893 894 895
	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 */
896 897
};

898 899 900
/**
 * Data passed from driver to FW in a DMUB_CMD__DP_AUX_ACCESS command.
 */
901
struct dmub_cmd_dp_aux_control_data {
902 903 904 905 906 907 908 909
	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 */
910 911
};

912 913 914
/**
 * Definition of a DMUB_CMD__DP_AUX_ACCESS command.
 */
915
struct dmub_rb_cmd_dp_aux_access {
916 917 918
	/**
	 * Command header.
	 */
919
	struct dmub_cmd_header header;
920 921 922
	/**
	 * Data passed from driver to FW in a DMUB_CMD__DP_AUX_ACCESS command.
	 */
923 924 925
	struct dmub_cmd_dp_aux_control_data aux_control;
};

926 927 928
/**
 * Definition of a DMUB_CMD__OUTBOX1_ENABLE command.
 */
929
struct dmub_rb_cmd_outbox1_enable {
930 931 932
	/**
	 * Command header.
	 */
933
	struct dmub_cmd_header header;
934 935 936 937
	/**
	 *  enable: 0x0 -> disable outbox1 notification (default value)
	 *			0x1 -> enable outbox1 notification
	 */
938 939 940 941
	uint32_t enable;
};

/* DP AUX Reply command - OutBox Cmd */
942 943 944
/**
 * Data passed to driver from FW in a DMUB_OUT_CMD__DP_AUX_REPLY command.
 */
945
struct aux_reply_data {
946 947 948
	/**
	 * Aux cmd
	 */
949
	uint8_t command;
950 951 952
	/**
	 * Aux reply data length (max: 16 bytes)
	 */
953
	uint8_t length;
954 955 956
	/**
	 * Alignment only
	 */
957
	uint8_t pad[2];
958 959 960
	/**
	 * Aux reply data
	 */
961 962 963
	uint8_t data[16];
};

964 965 966
/**
 * Control Data passed to driver from FW in a DMUB_OUT_CMD__DP_AUX_REPLY command.
 */
967
struct aux_reply_control_data {
968 969 970
	/**
	 * Reserved for future use
	 */
971
	uint32_t handle;
972 973 974
	/**
	 * Aux Instance
	 */
975
	uint8_t instance;
976 977 978
	/**
	 * Aux transaction result: definition in enum aux_return_code_type
	 */
979
	uint8_t result;
980 981 982
	/**
	 * Alignment only
	 */
983 984 985
	uint16_t pad;
};

986 987 988
/**
 * Definition of a DMUB_OUT_CMD__DP_AUX_REPLY command.
 */
989
struct dmub_rb_cmd_dp_aux_reply {
990 991 992
	/**
	 * Command header.
	 */
993
	struct dmub_cmd_header header;
994 995 996
	/**
	 * Control Data passed to driver from FW in a DMUB_OUT_CMD__DP_AUX_REPLY command.
	 */
997
	struct aux_reply_control_data control;
998 999 1000
	/**
	 * Data passed to driver from FW in a DMUB_OUT_CMD__DP_AUX_REPLY command.
	 */
1001 1002 1003
	struct aux_reply_data reply_data;
};

1004
/* DP HPD Notify command - OutBox Cmd */
1005 1006 1007
/**
 * DP HPD Type
 */
1008
enum dp_hpd_type {
1009 1010 1011
	/**
	 * Normal DP HPD
	 */
1012
	DP_HPD = 0,
1013 1014 1015
	/**
	 * DP HPD short pulse
	 */
1016 1017 1018
	DP_IRQ
};

1019 1020 1021
/**
 * DP HPD Status
 */
1022
enum dp_hpd_status {
1023 1024 1025
	/**
	 * DP_HPD status low
	 */
1026
	DP_HPD_UNPLUG = 0,
1027 1028 1029
	/**
	 * DP_HPD status high
	 */
1030 1031 1032
	DP_HPD_PLUG
};

1033 1034 1035
/**
 * Data passed to driver from FW in a DMUB_OUT_CMD__DP_HPD_NOTIFY command.
 */
1036
struct dp_hpd_data {
1037 1038 1039
	/**
	 * DP HPD instance
	 */
1040
	uint8_t instance;
1041 1042 1043
	/**
	 * HPD type
	 */
1044
	uint8_t hpd_type;
1045 1046 1047
	/**
	 * HPD status: only for type: DP_HPD to indicate status
	 */
1048
	uint8_t hpd_status;
1049 1050 1051
	/**
	 * Alignment only
	 */
1052 1053 1054
	uint8_t pad;
};

1055 1056 1057
/**
 * Definition of a DMUB_OUT_CMD__DP_HPD_NOTIFY command.
 */
1058
struct dmub_rb_cmd_dp_hpd_notify {
1059 1060 1061
	/**
	 * Command header.
	 */
1062
	struct dmub_cmd_header header;
1063 1064 1065
	/**
	 * Data passed to driver from FW in a DMUB_OUT_CMD__DP_HPD_NOTIFY command.
	 */
1066 1067 1068
	struct dp_hpd_data hpd_data;
};

1069 1070 1071 1072 1073
/*
 * Command IDs should be treated as stable ABI.
 * Do not reuse or modify IDs.
 */

1074 1075 1076
/**
 * PSR command sub-types.
 */
1077
enum dmub_cmd_psr_type {
1078 1079 1080
	/**
	 * Set PSR version support.
	 */
1081
	DMUB_CMD__PSR_SET_VERSION		= 0,
1082 1083 1084
	/**
	 * Copy driver-calculated parameters to PSR state.
	 */
1085
	DMUB_CMD__PSR_COPY_SETTINGS		= 1,
1086 1087 1088
	/**
	 * Enable PSR.
	 */
1089
	DMUB_CMD__PSR_ENABLE			= 2,
1090 1091 1092 1093

	/**
	 * Disable PSR.
	 */
1094
	DMUB_CMD__PSR_DISABLE			= 3,
1095 1096 1097 1098 1099 1100

	/**
	 * Set PSR level.
	 * PSR level is a 16-bit value dicated by driver that
	 * will enable/disable different functionality.
	 */
1101
	DMUB_CMD__PSR_SET_LEVEL			= 4,
1102 1103 1104 1105

	/**
	 * Forces PSR enabled until an explicit PSR disable call.
	 */
1106
	DMUB_CMD__PSR_FORCE_STATIC		= 5,
1107 1108
};

1109 1110 1111
/**
 * PSR versions.
 */
1112
enum psr_version {
1113 1114 1115
	/**
	 * PSR version 1.
	 */
1116
	PSR_VERSION_1				= 0,
1117 1118 1119
	/**
	 * PSR not supported.
	 */
1120 1121 1122
	PSR_VERSION_UNSUPPORTED			= 0xFFFFFFFF,
};

1123 1124 1125
/**
 * enum dmub_cmd_mall_type - MALL commands
 */
1126
enum dmub_cmd_mall_type {
1127 1128 1129
	/**
	 * Allows display refresh from MALL.
	 */
1130
	DMUB_CMD__MALL_ACTION_ALLOW = 0,
1131 1132 1133
	/**
	 * Disallows display refresh from MALL.
	 */
1134
	DMUB_CMD__MALL_ACTION_DISALLOW = 1,
1135 1136 1137
	/**
	 * Cursor copy for MALL.
	 */
1138
	DMUB_CMD__MALL_ACTION_COPY_CURSOR = 2,
1139 1140 1141
	/**
	 * Controls DF requests.
	 */
1142
	DMUB_CMD__MALL_ACTION_NO_DF_REQ = 3,
1143 1144
};

1145

1146 1147 1148
/**
 * Data passed from driver to FW in a DMUB_CMD__PSR_COPY_SETTINGS command.
 */
1149
struct dmub_cmd_psr_copy_settings_data {
1150 1151 1152
	/**
	 * Flags that can be set by driver to change some PSR behaviour.
	 */
A
Anthony Koo 已提交
1153
	union dmub_psr_debug_flags debug;
1154 1155 1156
	/**
	 * 16-bit value dicated by driver that will enable/disable different functionality.
	 */
1157
	uint16_t psr_level;
1158 1159 1160
	/**
	 * DPP HW instance.
	 */
1161
	uint8_t dpp_inst;
1162 1163 1164
	/**
	 * MPCC HW instance.
	 * Not used in dmub fw,
1165 1166
	 * dmub fw will get active opp by reading odm registers.
	 */
1167
	uint8_t mpcc_inst;
1168 1169 1170 1171 1172
	/**
	 * OPP HW instance.
	 * Not used in dmub fw,
	 * dmub fw will get active opp by reading odm registers.
	 */
1173
	uint8_t opp_inst;
1174 1175 1176
	/**
	 * OTG HW instance.
	 */
1177
	uint8_t otg_inst;
1178 1179 1180
	/**
	 * DIG FE HW instance.
	 */
1181
	uint8_t digfe_inst;
1182 1183 1184
	/**
	 * DIG BE HW instance.
	 */
1185
	uint8_t digbe_inst;
1186 1187 1188
	/**
	 * DP PHY HW instance.
	 */
1189
	uint8_t dpphy_inst;
1190 1191 1192
	/**
	 * AUX HW instance.
	 */
1193
	uint8_t aux_inst;
1194 1195 1196
	/**
	 * Determines if SMU optimzations are enabled/disabled.
	 */
1197
	uint8_t smu_optimizations_en;
1198 1199 1200 1201
	/**
	 * Unused.
	 * TODO: Remove.
	 */
1202
	uint8_t frame_delay;
1203 1204 1205 1206 1207 1208 1209
	/**
	 * 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.
	 */
1210
	uint8_t frame_cap_ind;
1211 1212 1213
	/**
	 * Explicit padding to 4 byte boundary.
	 */
1214
	uint8_t pad[2];
1215 1216 1217
	/**
	 * Multi-display optimizations are implemented on certain ASICs.
	 */
1218
	uint8_t multi_disp_optimizations_en;
1219 1220 1221 1222
	/**
	 * The last possible line SDP may be transmitted without violating
	 * the RFB setup time or entering the active video frame.
	 */
1223
	uint16_t init_sdp_deadline;
1224 1225 1226
	/**
	 * Explicit padding to 4 byte boundary.
	 */
1227
	uint16_t pad2;
1228 1229 1230
	/**
	 * Length of each horizontal line in us.
	 */
1231
	uint32_t line_time_in_us;
1232 1233
};

1234 1235 1236
/**
 * Definition of a DMUB_CMD__PSR_COPY_SETTINGS command.
 */
1237
struct dmub_rb_cmd_psr_copy_settings {
1238 1239 1240
	/**
	 * Command header.
	 */
1241
	struct dmub_cmd_header header;
1242 1243 1244
	/**
	 * Data passed from driver to FW in a DMUB_CMD__PSR_COPY_SETTINGS command.
	 */
1245 1246 1247
	struct dmub_cmd_psr_copy_settings_data psr_copy_settings_data;
};

1248 1249 1250
/**
 * Data passed from driver to FW in a DMUB_CMD__PSR_SET_LEVEL command.
 */
1251
struct dmub_cmd_psr_set_level_data {
1252 1253 1254
	/**
	 * 16-bit value dicated by driver that will enable/disable different functionality.
	 */
1255
	uint16_t psr_level;
1256 1257 1258
	/**
	 * Explicit padding to 4 byte boundary.
	 */
A
Anthony Koo 已提交
1259
	uint8_t pad[2];
1260 1261
};

1262 1263 1264
/**
 * Definition of a DMUB_CMD__PSR_SET_LEVEL command.
 */
1265
struct dmub_rb_cmd_psr_set_level {
1266 1267 1268
	/**
	 * Command header.
	 */
1269
	struct dmub_cmd_header header;
1270 1271 1272
	/**
	 * Definition of a DMUB_CMD__PSR_SET_LEVEL command.
	 */
1273 1274 1275
	struct dmub_cmd_psr_set_level_data psr_set_level_data;
};

1276 1277 1278 1279
/**
 * Definition of a DMUB_CMD__PSR_ENABLE command.
 * PSR enable/disable is controlled using the sub_type.
 */
1280
struct dmub_rb_cmd_psr_enable {
1281 1282 1283
	/**
	 * Command header.
	 */
1284 1285 1286
	struct dmub_cmd_header header;
};

1287 1288 1289
/**
 * Data passed from driver to FW in a DMUB_CMD__PSR_SET_VERSION command.
 */
1290
struct dmub_cmd_psr_set_version_data {
1291 1292 1293 1294
	/**
	 * PSR version that FW should implement.
	 */
	enum psr_version version;
1295 1296
};

1297 1298 1299
/**
 * Definition of a DMUB_CMD__PSR_SET_VERSION command.
 */
1300
struct dmub_rb_cmd_psr_set_version {
1301 1302 1303
	/**
	 * Command header.
	 */
1304
	struct dmub_cmd_header header;
1305 1306 1307
	/**
	 * Data passed from driver to FW in a DMUB_CMD__PSR_SET_VERSION command.
	 */
1308
	struct dmub_cmd_psr_set_version_data psr_set_version_data;
1309 1310
};

1311 1312 1313
/**
 * Definition of a DMUB_CMD__PSR_FORCE_STATIC command.
 */
1314
struct dmub_rb_cmd_psr_force_static {
1315 1316 1317
	/**
	 * Command header.
	 */
1318 1319 1320
	struct dmub_cmd_header header;
};

1321 1322 1323
/**
 * Set of HW components that can be locked.
 */
1324
union dmub_hw_lock_flags {
1325 1326 1327
	/**
	 * Set of HW components that can be locked.
	 */
1328
	struct {
1329 1330 1331
		/**
		 * Lock/unlock OTG master update lock.
		 */
1332
		uint8_t lock_pipe   : 1;
1333 1334 1335
		/**
		 * Lock/unlock cursor.
		 */
1336
		uint8_t lock_cursor : 1;
1337 1338 1339
		/**
		 * Lock/unlock global update lock.
		 */
1340
		uint8_t lock_dig    : 1;
1341 1342 1343
		/**
		 * Triple buffer lock requires additional hw programming to usual OTG master lock.
		 */
1344 1345 1346
		uint8_t triple_buffer_lock : 1;
	} bits;

1347 1348 1349
	/**
	 * Union for HW Lock flags.
	 */
1350 1351 1352
	uint8_t u8All;
};

1353 1354 1355
/**
 * Instances of HW to be locked.
 */
1356
struct dmub_hw_lock_inst_flags {
1357 1358 1359
	/**
	 * OTG HW instance for OTG master update lock.
	 */
1360
	uint8_t otg_inst;
1361 1362 1363
	/**
	 * OPP instance for cursor lock.
	 */
1364
	uint8_t opp_inst;
1365 1366 1367 1368
	/**
	 * OTG HW instance for global update lock.
	 * TODO: Remove, and re-use otg_inst.
	 */
1369
	uint8_t dig_inst;
1370 1371 1372
	/**
	 * Explicit pad to 4 byte boundary.
	 */
1373 1374 1375
	uint8_t pad;
};

1376 1377 1378
/**
 * Clients that can acquire the HW Lock Manager.
 */
1379
enum hw_lock_client {
1380 1381 1382
	/**
	 * Driver is the client of HW Lock Manager.
	 */
1383
	HW_LOCK_CLIENT_DRIVER = 0,
1384 1385 1386
	/**
	 * FW is the client of HW Lock Manager.
	 */
1387
	HW_LOCK_CLIENT_FW,
1388 1389 1390
	/**
	 * Invalid client.
	 */
1391 1392 1393
	HW_LOCK_CLIENT_INVALID = 0xFFFFFFFF,
};

1394 1395 1396
/**
 * Data passed to HW Lock Mgr in a DMUB_CMD__HW_LOCK command.
 */
1397
struct dmub_cmd_lock_hw_data {
1398 1399 1400
	/**
	 * Specifies the client accessing HW Lock Manager.
	 */
1401
	enum hw_lock_client client;
1402 1403 1404
	/**
	 * HW instances to be locked.
	 */
1405
	struct dmub_hw_lock_inst_flags inst_flags;
1406 1407 1408
	/**
	 * Which components to be locked.
	 */
1409
	union dmub_hw_lock_flags hw_locks;
1410 1411 1412
	/**
	 * Specifies lock/unlock.
	 */
1413
	uint8_t lock;
1414 1415 1416 1417
	/**
	 * HW can be unlocked separately from releasing the HW Lock Mgr.
	 * This flag is set if the client wishes to release the object.
	 */
1418
	uint8_t should_release;
1419 1420 1421
	/**
	 * Explicit padding to 4 byte boundary.
	 */
1422 1423 1424
	uint8_t pad;
};

1425 1426 1427 1428
/**
 * Definition of a DMUB_CMD__HW_LOCK command.
 * Command is used by driver and FW.
 */
1429
struct dmub_rb_cmd_lock_hw {
1430 1431 1432
	/**
	 * Command header.
	 */
1433
	struct dmub_cmd_header header;
1434 1435 1436
	/**
	 * Data passed to HW Lock Mgr in a DMUB_CMD__HW_LOCK command.
	 */
1437 1438 1439
	struct dmub_cmd_lock_hw_data lock_hw_data;
};

1440 1441 1442
/**
 * ABM command sub-types.
 */
1443
enum dmub_cmd_abm_type {
1444 1445 1446 1447
	/**
	 * Initialize parameters for ABM algorithm.
	 * Data is passed through an indirect buffer.
	 */
1448
	DMUB_CMD__ABM_INIT_CONFIG	= 0,
1449 1450 1451
	/**
	 * Set OTG and panel HW instance.
	 */
1452
	DMUB_CMD__ABM_SET_PIPE		= 1,
1453 1454 1455
	/**
	 * Set user requested backklight level.
	 */
1456
	DMUB_CMD__ABM_SET_BACKLIGHT	= 2,
1457 1458 1459
	/**
	 * Set ABM operating/aggression level.
	 */
1460
	DMUB_CMD__ABM_SET_LEVEL		= 3,
1461 1462 1463
	/**
	 * Set ambient light level.
	 */
1464
	DMUB_CMD__ABM_SET_AMBIENT_LEVEL	= 4,
1465 1466 1467
	/**
	 * Enable/disable fractional duty cycle for backlight PWM.
	 */
1468 1469 1470
	DMUB_CMD__ABM_SET_PWM_FRAC	= 5,
};

1471 1472 1473 1474 1475 1476
/**
 * 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.
1477 1478
 */
struct abm_config_table {
1479 1480 1481
	/**
	 * Gamma curve thresholds, used for crgb conversion.
	 */
1482
	uint16_t crgb_thresh[NUM_POWER_FN_SEGS];                 // 0B
1483 1484 1485
	/**
	 * Gamma curve offsets, used for crgb conversion.
	 */
1486
	uint16_t crgb_offset[NUM_POWER_FN_SEGS];                 // 16B
1487 1488 1489
	/**
	 * Gamma curve slopes, used for crgb conversion.
	 */
1490
	uint16_t crgb_slope[NUM_POWER_FN_SEGS];                  // 32B
1491 1492 1493
	/**
	 * Custom backlight curve thresholds.
	 */
1494
	uint16_t backlight_thresholds[NUM_BL_CURVE_SEGS];        // 48B
1495 1496 1497
	/**
	 * Custom backlight curve offsets.
	 */
1498
	uint16_t backlight_offsets[NUM_BL_CURVE_SEGS];           // 78B
1499 1500 1501
	/**
	 * Ambient light thresholds.
	 */
1502
	uint16_t ambient_thresholds_lux[NUM_AMBI_LEVEL];         // 112B
1503 1504 1505
	/**
	 * Minimum programmable backlight.
	 */
1506
	uint16_t min_abm_backlight;                              // 122B
1507 1508 1509
	/**
	 * Minimum reduction values.
	 */
1510
	uint8_t min_reduction[NUM_AMBI_LEVEL][NUM_AGGR_LEVEL];   // 124B
1511 1512 1513
	/**
	 * Maximum reduction values.
	 */
1514
	uint8_t max_reduction[NUM_AMBI_LEVEL][NUM_AGGR_LEVEL];   // 144B
1515 1516 1517
	/**
	 * Bright positive gain.
	 */
1518
	uint8_t bright_pos_gain[NUM_AMBI_LEVEL][NUM_AGGR_LEVEL]; // 164B
1519 1520 1521
	/**
	 * Dark negative gain.
	 */
1522
	uint8_t dark_pos_gain[NUM_AMBI_LEVEL][NUM_AGGR_LEVEL];   // 184B
1523 1524 1525
	/**
	 * Hybrid factor.
	 */
1526
	uint8_t hybrid_factor[NUM_AGGR_LEVEL];                   // 204B
1527 1528 1529
	/**
	 * Contrast factor.
	 */
1530
	uint8_t contrast_factor[NUM_AGGR_LEVEL];                 // 208B
1531 1532 1533
	/**
	 * Deviation gain.
	 */
1534
	uint8_t deviation_gain[NUM_AGGR_LEVEL];                  // 212B
1535 1536 1537
	/**
	 * Minimum knee.
	 */
1538
	uint8_t min_knee[NUM_AGGR_LEVEL];                        // 216B
1539 1540 1541
	/**
	 * Maximum knee.
	 */
1542
	uint8_t max_knee[NUM_AGGR_LEVEL];                        // 220B
1543 1544 1545
	/**
	 * Unused.
	 */
1546
	uint8_t iir_curve[NUM_AMBI_LEVEL];                       // 224B
1547 1548 1549
	/**
	 * Explicit padding to 4 byte boundary.
	 */
1550
	uint8_t pad3[3];                                         // 229B
1551 1552 1553
	/**
	 * Backlight ramp reduction.
	 */
1554
	uint16_t blRampReduction[NUM_AGGR_LEVEL];                // 232B
1555 1556 1557
	/**
	 * Backlight ramp start.
	 */
1558
	uint16_t blRampStart[NUM_AGGR_LEVEL];                    // 240B
1559 1560
};

1561 1562 1563
/**
 * Data passed from driver to FW in a DMUB_CMD__ABM_SET_PIPE command.
 */
1564
struct dmub_cmd_abm_set_pipe_data {
1565 1566 1567
	/**
	 * OTG HW instance.
	 */
A
Anthony Koo 已提交
1568
	uint8_t otg_inst;
1569 1570 1571 1572

	/**
	 * Panel Control HW instance.
	 */
A
Anthony Koo 已提交
1573
	uint8_t panel_inst;
1574 1575 1576 1577

	/**
	 * Controls how ABM will interpret a set pipe or set level command.
	 */
A
Anthony Koo 已提交
1578
	uint8_t set_pipe_option;
1579 1580 1581 1582 1583 1584

	/**
	 * Unused.
	 * TODO: Remove.
	 */
	uint8_t ramping_boundary;
1585 1586
};

1587 1588 1589
/**
 * Definition of a DMUB_CMD__ABM_SET_PIPE command.
 */
1590
struct dmub_rb_cmd_abm_set_pipe {
1591 1592 1593
	/**
	 * Command header.
	 */
1594
	struct dmub_cmd_header header;
1595 1596 1597 1598

	/**
	 * Data passed from driver to FW in a DMUB_CMD__ABM_SET_PIPE command.
	 */
1599 1600 1601
	struct dmub_cmd_abm_set_pipe_data abm_set_pipe_data;
};

1602 1603 1604
/**
 * Data passed from driver to FW in a DMUB_CMD__ABM_SET_BACKLIGHT command.
 */
1605
struct dmub_cmd_abm_set_backlight_data {
1606 1607 1608
	/**
	 * Number of frames to ramp to backlight user level.
	 */
1609
	uint32_t frame_ramp;
1610 1611 1612 1613

	/**
	 * Requested backlight level from user.
	 */
1614
	uint32_t backlight_user_level;
1615 1616
};

1617 1618 1619
/**
 * Definition of a DMUB_CMD__ABM_SET_BACKLIGHT command.
 */
1620
struct dmub_rb_cmd_abm_set_backlight {
1621 1622 1623
	/**
	 * Command header.
	 */
1624
	struct dmub_cmd_header header;
1625 1626 1627 1628

	/**
	 * Data passed from driver to FW in a DMUB_CMD__ABM_SET_BACKLIGHT command.
	 */
1629 1630 1631
	struct dmub_cmd_abm_set_backlight_data abm_set_backlight_data;
};

1632 1633 1634
/**
 * Data passed from driver to FW in a DMUB_CMD__ABM_SET_LEVEL command.
 */
1635
struct dmub_cmd_abm_set_level_data {
1636 1637 1638
	/**
	 * Set current ABM operating/aggression level.
	 */
1639 1640 1641
	uint32_t level;
};

1642 1643 1644
/**
 * Definition of a DMUB_CMD__ABM_SET_LEVEL command.
 */
1645
struct dmub_rb_cmd_abm_set_level {
1646 1647 1648
	/**
	 * Command header.
	 */
1649
	struct dmub_cmd_header header;
1650 1651 1652 1653

	/**
	 * Data passed from driver to FW in a DMUB_CMD__ABM_SET_LEVEL command.
	 */
1654 1655 1656
	struct dmub_cmd_abm_set_level_data abm_set_level_data;
};

1657 1658 1659
/**
 * Data passed from driver to FW in a DMUB_CMD__ABM_SET_AMBIENT_LEVEL command.
 */
1660
struct dmub_cmd_abm_set_ambient_level_data {
1661 1662 1663
	/**
	 * Ambient light sensor reading from OS.
	 */
1664 1665 1666
	uint32_t ambient_lux;
};

1667 1668 1669
/**
 * Definition of a DMUB_CMD__ABM_SET_AMBIENT_LEVEL command.
 */
1670
struct dmub_rb_cmd_abm_set_ambient_level {
1671 1672 1673
	/**
	 * Command header.
	 */
1674
	struct dmub_cmd_header header;
1675 1676 1677 1678

	/**
	 * Data passed from driver to FW in a DMUB_CMD__ABM_SET_AMBIENT_LEVEL command.
	 */
1679 1680 1681
	struct dmub_cmd_abm_set_ambient_level_data abm_set_ambient_level_data;
};

1682 1683 1684
/**
 * Data passed from driver to FW in a DMUB_CMD__ABM_SET_PWM_FRAC command.
 */
1685
struct dmub_cmd_abm_set_pwm_frac_data {
1686 1687 1688 1689
	/**
	 * Enable/disable fractional duty cycle for backlight PWM.
	 * TODO: Convert to uint8_t.
	 */
1690 1691 1692
	uint32_t fractional_pwm;
};

1693 1694 1695
/**
 * Definition of a DMUB_CMD__ABM_SET_PWM_FRAC command.
 */
1696
struct dmub_rb_cmd_abm_set_pwm_frac {
1697 1698 1699
	/**
	 * Command header.
	 */
1700
	struct dmub_cmd_header header;
1701 1702 1703 1704

	/**
	 * Data passed from driver to FW in a DMUB_CMD__ABM_SET_PWM_FRAC command.
	 */
1705 1706 1707
	struct dmub_cmd_abm_set_pwm_frac_data abm_set_pwm_frac_data;
};

1708 1709 1710
/**
 * Data passed from driver to FW in a DMUB_CMD__ABM_INIT_CONFIG command.
 */
1711
struct dmub_cmd_abm_init_config_data {
1712 1713 1714
	/**
	 * Location of indirect buffer used to pass init data to ABM.
	 */
1715
	union dmub_addr src;
1716 1717 1718 1719

	/**
	 * Indirect buffer length.
	 */
1720 1721 1722
	uint16_t bytes;
};

1723 1724 1725
/**
 * Definition of a DMUB_CMD__ABM_INIT_CONFIG command.
 */
1726
struct dmub_rb_cmd_abm_init_config {
1727 1728 1729
	/**
	 * Command header.
	 */
1730
	struct dmub_cmd_header header;
1731 1732 1733 1734

	/**
	 * Data passed from driver to FW in a DMUB_CMD__ABM_INIT_CONFIG command.
	 */
1735 1736 1737
	struct dmub_cmd_abm_init_config_data abm_init_config_data;
};

1738 1739 1740
/**
 * Data passed from driver to FW in a DMUB_CMD__QUERY_FEATURE_CAPS command.
 */
1741
struct dmub_cmd_query_feature_caps_data {
1742 1743 1744 1745 1746
	/**
	 * DMUB feature capabilities.
	 * After DMUB init, driver will query FW capabilities prior to enabling certain features.
	 */
	struct dmub_feature_caps feature_caps;
1747 1748
};

1749 1750 1751
/**
 * Definition of a DMUB_CMD__QUERY_FEATURE_CAPS command.
 */
1752
struct dmub_rb_cmd_query_feature_caps {
1753 1754 1755 1756 1757 1758 1759 1760
	/**
	 * 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;
1761 1762
};

1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777
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;
};

1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801
/**
 * 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;
};

1802 1803 1804
/**
 * union dmub_rb_cmd - DMUB inbox command.
 */
1805
union dmub_rb_cmd {
1806
	struct dmub_rb_cmd_lock_hw lock_hw;
1807 1808 1809 1810 1811 1812 1813
	/**
	 * Elements shared with all commands.
	 */
	struct dmub_rb_cmd_common cmd_common;
	/**
	 * Definition of a DMUB_CMD__REG_SEQ_READ_MODIFY_WRITE command.
	 */
1814
	struct dmub_rb_cmd_read_modify_write read_modify_write;
1815 1816 1817
	/**
	 * Definition of a DMUB_CMD__REG_SEQ_FIELD_UPDATE_SEQ command.
	 */
1818
	struct dmub_rb_cmd_reg_field_update_sequence reg_field_update_seq;
1819 1820 1821
	/**
	 * Definition of a DMUB_CMD__REG_SEQ_BURST_WRITE command.
	 */
1822
	struct dmub_rb_cmd_burst_write burst_write;
1823 1824 1825
	/**
	 * Definition of a DMUB_CMD__REG_REG_WAIT command.
	 */
1826
	struct dmub_rb_cmd_reg_wait reg_wait;
1827 1828 1829
	/**
	 * Definition of a DMUB_CMD__VBIOS_DIGX_ENCODER_CONTROL command.
	 */
1830
	struct dmub_rb_cmd_digx_encoder_control digx_encoder_control;
1831 1832 1833
	/**
	 * Definition of a DMUB_CMD__VBIOS_SET_PIXEL_CLOCK command.
	 */
1834
	struct dmub_rb_cmd_set_pixel_clock set_pixel_clock;
1835 1836 1837
	/**
	 * Definition of a DMUB_CMD__VBIOS_ENABLE_DISP_POWER_GATING command.
	 */
1838
	struct dmub_rb_cmd_enable_disp_power_gating enable_disp_power_gating;
1839 1840 1841
	/**
	 * Definition of a DMUB_CMD__VBIOS_DPPHY_INIT command.
	 */
1842
	struct dmub_rb_cmd_dpphy_init dpphy_init;
1843 1844 1845
	/**
	 * Definition of a DMUB_CMD__VBIOS_DIG1_TRANSMITTER_CONTROL command.
	 */
1846
	struct dmub_rb_cmd_dig1_transmitter_control dig1_transmitter_control;
1847 1848 1849
	/**
	 * Definition of a DMUB_CMD__PSR_SET_VERSION command.
	 */
1850
	struct dmub_rb_cmd_psr_set_version psr_set_version;
1851 1852 1853
	/**
	 * Definition of a DMUB_CMD__PSR_COPY_SETTINGS command.
	 */
1854
	struct dmub_rb_cmd_psr_copy_settings psr_copy_settings;
1855 1856 1857
	/**
	 * Definition of a DMUB_CMD__PSR_ENABLE command.
	 */
1858
	struct dmub_rb_cmd_psr_enable psr_enable;
1859 1860 1861
	/**
	 * Definition of a DMUB_CMD__PSR_SET_LEVEL command.
	 */
1862
	struct dmub_rb_cmd_psr_set_level psr_set_level;
1863 1864 1865
	/**
	 * Definition of a DMUB_CMD__PSR_FORCE_STATIC command.
	 */
1866
	struct dmub_rb_cmd_psr_force_static psr_force_static;
1867 1868 1869
	/**
	 * Definition of a DMUB_CMD__PLAT_54186_WA command.
	 */
1870
	struct dmub_rb_cmd_PLAT_54186_wa PLAT_54186_wa;
1871 1872 1873
	/**
	 * Definition of a DMUB_CMD__MALL command.
	 */
1874
	struct dmub_rb_cmd_mall mall;
1875 1876 1877
	/**
	 * Definition of a DMUB_CMD__ABM_SET_PIPE command.
	 */
1878
	struct dmub_rb_cmd_abm_set_pipe abm_set_pipe;
1879 1880 1881 1882

	/**
	 * Definition of a DMUB_CMD__ABM_SET_BACKLIGHT command.
	 */
1883
	struct dmub_rb_cmd_abm_set_backlight abm_set_backlight;
1884 1885 1886 1887

	/**
	 * Definition of a DMUB_CMD__ABM_SET_LEVEL command.
	 */
1888
	struct dmub_rb_cmd_abm_set_level abm_set_level;
1889 1890 1891 1892

	/**
	 * Definition of a DMUB_CMD__ABM_SET_AMBIENT_LEVEL command.
	 */
1893
	struct dmub_rb_cmd_abm_set_ambient_level abm_set_ambient_level;
1894 1895 1896 1897

	/**
	 * Definition of a DMUB_CMD__ABM_SET_PWM_FRAC command.
	 */
1898
	struct dmub_rb_cmd_abm_set_pwm_frac abm_set_pwm_frac;
1899 1900 1901 1902

	/**
	 * Definition of a DMUB_CMD__ABM_INIT_CONFIG command.
	 */
1903
	struct dmub_rb_cmd_abm_init_config abm_init_config;
1904 1905 1906 1907

	/**
	 * Definition of a DMUB_CMD__DP_AUX_ACCESS command.
	 */
1908
	struct dmub_rb_cmd_dp_aux_access dp_aux_access;
1909

1910 1911 1912
	/**
	 * Definition of a DMUB_CMD__OUTBOX1_ENABLE command.
	 */
1913
	struct dmub_rb_cmd_outbox1_enable outbox1_enable;
1914

1915
	/**
1916
	 * Definition of a DMUB_CMD__QUERY_FEATURE_CAPS command.
1917
	 */
1918
	struct dmub_rb_cmd_query_feature_caps query_feature_caps;
1919
	struct dmub_rb_cmd_drr_update drr_update;
1920 1921 1922 1923
	/**
	 * Definition of a DMUB_CMD__VBIOS_LVTMA_CONTROL command.
	 */
	struct dmub_rb_cmd_lvtma_control lvtma_control;
1924 1925
};

1926 1927 1928
/**
 * union dmub_rb_out_cmd - Outbox command
 */
1929
union dmub_rb_out_cmd {
1930 1931 1932
	/**
	 * Parameters common to every command.
	 */
1933
	struct dmub_rb_cmd_common cmd_common;
1934 1935 1936
	/**
	 * AUX reply command.
	 */
1937
	struct dmub_rb_cmd_dp_aux_reply dp_aux_reply;
1938 1939 1940
	/**
	 * HPD notify command.
	 */
1941 1942
	struct dmub_rb_cmd_dp_hpd_notify dp_hpd_notify;
};
1943 1944
#pragma pack(pop)

1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955

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

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

1956 1957 1958
/**
 * struct dmub_rb_init_params - Initialization params for DMUB ringbuffer
 */
1959
struct dmub_rb_init_params {
1960 1961 1962 1963 1964
	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 */
1965 1966
};

1967 1968 1969
/**
 * struct dmub_rb - Inbox or outbox DMUB ringbuffer
 */
1970
struct dmub_rb {
1971 1972 1973 1974
	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 */
1975

1976 1977
	void *ctx; /**< Caller provided context pointer */
	void *dmub; /**< Pointer to the DMUB interface */
1978 1979
};

1980 1981 1982 1983 1984 1985 1986
/**
 * @brief Checks if the ringbuffer is empty.
 *
 * @param rb DMUB Ringbuffer
 * @return true if empty
 * @return false otherwise
 */
1987 1988 1989 1990 1991
static inline bool dmub_rb_empty(struct dmub_rb *rb)
{
	return (rb->wrpt == rb->rptr);
}

1992 1993 1994 1995 1996 1997 1998
/**
 * @brief Checks if the ringbuffer is full
 *
 * @param rb DMUB Ringbuffer
 * @return true if full
 * @return false otherwise
 */
1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010
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));
}

2011 2012 2013 2014 2015 2016 2017 2018
/**
 * @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
 */
2019 2020 2021 2022 2023
static inline bool dmub_rb_push_front(struct dmub_rb *rb,
				      const union dmub_rb_cmd *cmd)
{
	uint64_t volatile *dst = (uint64_t volatile *)(rb->base_address) + rb->wrpt / sizeof(uint64_t);
	const uint64_t *src = (const uint64_t *)cmd;
2024
	uint8_t i;
2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040

	if (dmub_rb_full(rb))
		return false;

	// copying data
	for (i = 0; i < DMUB_RB_CMD_SIZE / sizeof(uint64_t); i++)
		*dst++ = *src++;

	rb->wrpt += DMUB_RB_CMD_SIZE;

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

	return true;
}

2041 2042 2043 2044 2045 2046 2047 2048
/**
 * @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
 */
2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067
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;
	const uint8_t *src = (uint8_t *)cmd;

	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;
}

2068 2069 2070 2071 2072 2073 2074 2075
/**
 * @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
 */
2076
static inline bool dmub_rb_front(struct dmub_rb *rb,
2077
				 union dmub_rb_cmd  **cmd)
2078
{
2079
	uint8_t *rb_cmd = (uint8_t *)(rb->base_address) + rb->rptr;
2080 2081 2082 2083

	if (dmub_rb_empty(rb))
		return false;

2084
	*cmd = (union dmub_rb_cmd *)rb_cmd;
2085 2086 2087 2088

	return true;
}

2089 2090 2091 2092 2093 2094 2095 2096
/**
 * @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
 */
2097 2098 2099 2100 2101
static inline bool dmub_rb_out_front(struct dmub_rb *rb,
				 union dmub_rb_out_cmd  *cmd)
{
	const uint64_t volatile *src = (const uint64_t volatile *)(rb->base_address) + rb->rptr / sizeof(uint64_t);
	uint64_t *dst = (uint64_t *)cmd;
2102
	uint8_t i;
2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113

	if (dmub_rb_empty(rb))
		return false;

	// copying data
	for (i = 0; i < DMUB_RB_CMD_SIZE / sizeof(uint64_t); i++)
		*dst++ = *src++;

	return true;
}

2114 2115 2116 2117 2118 2119 2120
/**
 * @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
 */
2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133
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;
}

2134 2135 2136 2137 2138 2139 2140 2141
/**
 * @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
 */
2142 2143 2144 2145 2146 2147 2148
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) {
		uint64_t volatile *data = (uint64_t volatile *)rb->base_address + rptr / sizeof(uint64_t);
2149
		uint8_t i;
2150 2151

		for (i = 0; i < DMUB_RB_CMD_SIZE / sizeof(uint64_t); i++)
2152
			*data++;
2153 2154 2155 2156 2157 2158 2159

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

2160 2161 2162 2163 2164 2165
/**
 * @brief Initializes a DMCUB ringbuffer
 *
 * @param rb DMUB ringbuffer
 * @param init_params initial configuration for the ringbuffer
 */
2166 2167 2168 2169 2170 2171 2172 2173 2174
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;
}

2175 2176 2177 2178 2179 2180
/**
 * @brief Copies output data from in/out commands into the given command.
 *
 * @param rb DMUB ringbuffer
 * @param cmd Command to copy data into
 */
2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191
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);
}

2192 2193 2194 2195 2196 2197 2198 2199
#if defined(__cplusplus)
}
#endif

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

2200
#endif /* _DMUB_CMD_H_ */