drm_dsc.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. /* SPDX-License-Identifier: MIT
  2. * Copyright (C) 2018 Intel Corp.
  3. *
  4. * Authors:
  5. * Manasi Navare <manasi.d.navare@intel.com>
  6. */
  7. #ifndef DRM_DSC_H_
  8. #define DRM_DSC_H_
  9. #include <drm/display/drm_dp.h>
  10. /* VESA Display Stream Compression DSC 1.2 constants */
  11. #define DSC_NUM_BUF_RANGES 15
  12. #define DSC_MUX_WORD_SIZE_8_10_BPC 48
  13. #define DSC_MUX_WORD_SIZE_12_BPC 64
  14. #define DSC_RC_PIXELS_PER_GROUP 3
  15. #define DSC_SCALE_DECREMENT_INTERVAL_MAX 4095
  16. #define DSC_RANGE_BPG_OFFSET_MASK 0x3f
  17. /* DSC Rate Control Constants */
  18. #define DSC_RC_MODEL_SIZE_CONST 8192
  19. #define DSC_RC_EDGE_FACTOR_CONST 6
  20. #define DSC_RC_TGT_OFFSET_HI_CONST 3
  21. #define DSC_RC_TGT_OFFSET_LO_CONST 3
  22. /* DSC PPS constants and macros */
  23. #define DSC_PPS_VERSION_MAJOR_SHIFT 4
  24. #define DSC_PPS_BPC_SHIFT 4
  25. #define DSC_PPS_MSB_SHIFT 8
  26. #define DSC_PPS_LSB_MASK (0xFF << 0)
  27. #define DSC_PPS_BPP_HIGH_MASK (0x3 << 8)
  28. #define DSC_PPS_VBR_EN_SHIFT 2
  29. #define DSC_PPS_SIMPLE422_SHIFT 3
  30. #define DSC_PPS_CONVERT_RGB_SHIFT 4
  31. #define DSC_PPS_BLOCK_PRED_EN_SHIFT 5
  32. #define DSC_PPS_INIT_XMIT_DELAY_HIGH_MASK (0x3 << 8)
  33. #define DSC_PPS_SCALE_DEC_INT_HIGH_MASK (0xF << 8)
  34. #define DSC_PPS_RC_TGT_OFFSET_HI_SHIFT 4
  35. #define DSC_PPS_RC_RANGE_MINQP_SHIFT 11
  36. #define DSC_PPS_RC_RANGE_MAXQP_SHIFT 6
  37. #define DSC_PPS_NATIVE_420_SHIFT 1
  38. /**
  39. * struct drm_dsc_rc_range_parameters - DSC Rate Control range parameters
  40. *
  41. * This defines different rate control parameters used by the DSC engine
  42. * to compress the frame.
  43. */
  44. struct drm_dsc_rc_range_parameters {
  45. /**
  46. * @range_min_qp: Min Quantization Parameters allowed for this range
  47. */
  48. u8 range_min_qp;
  49. /**
  50. * @range_max_qp: Max Quantization Parameters allowed for this range
  51. */
  52. u8 range_max_qp;
  53. /**
  54. * @range_bpg_offset:
  55. * Bits/group offset to apply to target for this group
  56. */
  57. u8 range_bpg_offset;
  58. };
  59. /**
  60. * struct drm_dsc_config - Parameters required to configure DSC
  61. *
  62. * Driver populates this structure with all the parameters required
  63. * to configure the display stream compression on the source.
  64. */
  65. struct drm_dsc_config {
  66. /**
  67. * @line_buf_depth:
  68. * Bits per component for previous reconstructed line buffer
  69. */
  70. u8 line_buf_depth;
  71. /**
  72. * @bits_per_component: Bits per component to code (8/10/12)
  73. */
  74. u8 bits_per_component;
  75. /**
  76. * @convert_rgb:
  77. * Flag to indicate if RGB - YCoCg conversion is needed
  78. * True if RGB input, False if YCoCg input
  79. */
  80. bool convert_rgb;
  81. /**
  82. * @slice_count: Number fo slices per line used by the DSC encoder
  83. */
  84. u8 slice_count;
  85. /**
  86. * @slice_width: Width of each slice in pixels
  87. */
  88. u16 slice_width;
  89. /**
  90. * @slice_height: Slice height in pixels
  91. */
  92. u16 slice_height;
  93. /**
  94. * @simple_422: True if simple 4_2_2 mode is enabled else False
  95. */
  96. bool simple_422;
  97. /**
  98. * @pic_width: Width of the input display frame in pixels
  99. */
  100. u16 pic_width;
  101. /**
  102. * @pic_height: Vertical height of the input display frame
  103. */
  104. u16 pic_height;
  105. /**
  106. * @rc_tgt_offset_high:
  107. * Offset to bits/group used by RC to determine QP adjustment
  108. */
  109. u8 rc_tgt_offset_high;
  110. /**
  111. * @rc_tgt_offset_low:
  112. * Offset to bits/group used by RC to determine QP adjustment
  113. */
  114. u8 rc_tgt_offset_low;
  115. /**
  116. * @bits_per_pixel:
  117. * Target bits per pixel with 4 fractional bits, bits_per_pixel << 4
  118. */
  119. u16 bits_per_pixel;
  120. /**
  121. * @rc_edge_factor:
  122. * Factor to determine if an edge is present based on the bits produced
  123. */
  124. u8 rc_edge_factor;
  125. /**
  126. * @rc_quant_incr_limit1:
  127. * Slow down incrementing once the range reaches this value
  128. */
  129. u8 rc_quant_incr_limit1;
  130. /**
  131. * @rc_quant_incr_limit0:
  132. * Slow down incrementing once the range reaches this value
  133. */
  134. u8 rc_quant_incr_limit0;
  135. /**
  136. * @initial_xmit_delay:
  137. * Number of pixels to delay the initial transmission
  138. */
  139. u16 initial_xmit_delay;
  140. /**
  141. * @initial_dec_delay:
  142. * Initial decoder delay, number of pixel times that the decoder
  143. * accumulates data in its rate buffer before starting to decode
  144. * and output pixels.
  145. */
  146. u16 initial_dec_delay;
  147. /**
  148. * @block_pred_enable:
  149. * True if block prediction is used to code any groups within the
  150. * picture. False if BP not used
  151. */
  152. bool block_pred_enable;
  153. /**
  154. * @first_line_bpg_offset:
  155. * Number of additional bits allocated for each group on the first
  156. * line of slice.
  157. */
  158. u8 first_line_bpg_offset;
  159. /**
  160. * @initial_offset: Value to use for RC model offset at slice start
  161. */
  162. u16 initial_offset;
  163. /**
  164. * @rc_buf_thresh: Thresholds defining each of the buffer ranges
  165. */
  166. u16 rc_buf_thresh[DSC_NUM_BUF_RANGES - 1];
  167. /**
  168. * @rc_range_params:
  169. * Parameters for each of the RC ranges defined in
  170. * &struct drm_dsc_rc_range_parameters
  171. */
  172. struct drm_dsc_rc_range_parameters rc_range_params[DSC_NUM_BUF_RANGES];
  173. /**
  174. * @rc_model_size: Total size of RC model
  175. */
  176. u16 rc_model_size;
  177. /**
  178. * @flatness_min_qp: Minimum QP where flatness information is sent
  179. */
  180. u8 flatness_min_qp;
  181. /**
  182. * @flatness_max_qp: Maximum QP where flatness information is sent
  183. */
  184. u8 flatness_max_qp;
  185. /**
  186. * @initial_scale_value: Initial value for the scale factor
  187. */
  188. u8 initial_scale_value;
  189. /**
  190. * @scale_decrement_interval:
  191. * Specifies number of group times between decrementing the scale factor
  192. * at beginning of a slice.
  193. */
  194. u16 scale_decrement_interval;
  195. /**
  196. * @scale_increment_interval:
  197. * Number of group times between incrementing the scale factor value
  198. * used at the beginning of a slice.
  199. */
  200. u16 scale_increment_interval;
  201. /**
  202. * @nfl_bpg_offset: Non first line BPG offset to be used
  203. */
  204. u16 nfl_bpg_offset;
  205. /**
  206. * @slice_bpg_offset: BPG offset used to enforce slice bit
  207. */
  208. u16 slice_bpg_offset;
  209. /**
  210. * @final_offset: Final RC linear transformation offset value
  211. */
  212. u16 final_offset;
  213. /**
  214. * @vbr_enable: True if VBR mode is enabled, false if disabled
  215. */
  216. bool vbr_enable;
  217. /**
  218. * @mux_word_size: Mux word size (in bits) for SSM mode
  219. */
  220. u8 mux_word_size;
  221. /**
  222. * @slice_chunk_size:
  223. * The (max) size in bytes of the "chunks" that are used in slice
  224. * multiplexing.
  225. */
  226. u16 slice_chunk_size;
  227. /**
  228. * @rc_bits: Rate control buffer size in bits
  229. */
  230. u16 rc_bits;
  231. /**
  232. * @dsc_version_minor: DSC minor version
  233. */
  234. u8 dsc_version_minor;
  235. /**
  236. * @dsc_version_major: DSC major version
  237. */
  238. u8 dsc_version_major;
  239. /**
  240. * @native_422: True if Native 4:2:2 supported, else false
  241. */
  242. bool native_422;
  243. /**
  244. * @native_420: True if Native 4:2:0 supported else false.
  245. */
  246. bool native_420;
  247. /**
  248. * @second_line_bpg_offset:
  249. * Additional bits/grp for seconnd line of slice for native 4:2:0
  250. */
  251. u8 second_line_bpg_offset;
  252. /**
  253. * @nsl_bpg_offset:
  254. * Num of bits deallocated for each grp that is not in second line of
  255. * slice
  256. */
  257. u16 nsl_bpg_offset;
  258. /**
  259. * @second_line_offset_adj:
  260. * Offset adjustment for second line in Native 4:2:0 mode
  261. */
  262. u16 second_line_offset_adj;
  263. };
  264. /**
  265. * struct drm_dsc_picture_parameter_set - Represents 128 bytes of
  266. * Picture Parameter Set
  267. *
  268. * The VESA DSC standard defines picture parameter set (PPS) which display
  269. * stream compression encoders must communicate to decoders.
  270. * The PPS is encapsulated in 128 bytes (PPS 0 through PPS 127). The fields in
  271. * this structure are as per Table 4.1 in Vesa DSC specification v1.1/v1.2.
  272. * The PPS fields that span over more than a byte should be stored in Big Endian
  273. * format.
  274. */
  275. struct drm_dsc_picture_parameter_set {
  276. /**
  277. * @dsc_version:
  278. * PPS0[3:0] - dsc_version_minor: Contains Minor version of DSC
  279. * PPS0[7:4] - dsc_version_major: Contains major version of DSC
  280. */
  281. u8 dsc_version;
  282. /**
  283. * @pps_identifier:
  284. * PPS1[7:0] - Application specific identifier that can be
  285. * used to differentiate between different PPS tables.
  286. */
  287. u8 pps_identifier;
  288. /**
  289. * @pps_reserved:
  290. * PPS2[7:0]- RESERVED Byte
  291. */
  292. u8 pps_reserved;
  293. /**
  294. * @pps_3:
  295. * PPS3[3:0] - linebuf_depth: Contains linebuffer bit depth used to
  296. * generate the bitstream. (0x0 - 16 bits for DSC 1.2, 0x8 - 8 bits,
  297. * 0xA - 10 bits, 0xB - 11 bits, 0xC - 12 bits, 0xD - 13 bits,
  298. * 0xE - 14 bits for DSC1.2, 0xF - 14 bits for DSC 1.2.
  299. * PPS3[7:4] - bits_per_component: Bits per component for the original
  300. * pixels of the encoded picture.
  301. * 0x0 = 16bpc (allowed only when dsc_version_minor = 0x2)
  302. * 0x8 = 8bpc, 0xA = 10bpc, 0xC = 12bpc, 0xE = 14bpc (also
  303. * allowed only when dsc_minor_version = 0x2)
  304. */
  305. u8 pps_3;
  306. /**
  307. * @pps_4:
  308. * PPS4[1:0] -These are the most significant 2 bits of
  309. * compressed BPP bits_per_pixel[9:0] syntax element.
  310. * PPS4[2] - vbr_enable: 0 = VBR disabled, 1 = VBR enabled
  311. * PPS4[3] - simple_422: Indicates if decoder drops samples to
  312. * reconstruct the 4:2:2 picture.
  313. * PPS4[4] - Convert_rgb: Indicates if DSC color space conversion is
  314. * active.
  315. * PPS4[5] - blobk_pred_enable: Indicates if BP is used to code any
  316. * groups in picture
  317. * PPS4[7:6] - Reseved bits
  318. */
  319. u8 pps_4;
  320. /**
  321. * @bits_per_pixel_low:
  322. * PPS5[7:0] - This indicates the lower significant 8 bits of
  323. * the compressed BPP bits_per_pixel[9:0] element.
  324. */
  325. u8 bits_per_pixel_low;
  326. /**
  327. * @pic_height:
  328. * PPS6[7:0], PPS7[7:0] -pic_height: Specifies the number of pixel rows
  329. * within the raster.
  330. */
  331. __be16 pic_height;
  332. /**
  333. * @pic_width:
  334. * PPS8[7:0], PPS9[7:0] - pic_width: Number of pixel columns within
  335. * the raster.
  336. */
  337. __be16 pic_width;
  338. /**
  339. * @slice_height:
  340. * PPS10[7:0], PPS11[7:0] - Slice height in units of pixels.
  341. */
  342. __be16 slice_height;
  343. /**
  344. * @slice_width:
  345. * PPS12[7:0], PPS13[7:0] - Slice width in terms of pixels.
  346. */
  347. __be16 slice_width;
  348. /**
  349. * @chunk_size:
  350. * PPS14[7:0], PPS15[7:0] - Size in units of bytes of the chunks
  351. * that are used for slice multiplexing.
  352. */
  353. __be16 chunk_size;
  354. /**
  355. * @initial_xmit_delay_high:
  356. * PPS16[1:0] - Most Significant two bits of initial transmission delay.
  357. * It specifies the number of pixel times that the encoder waits before
  358. * transmitting data from its rate buffer.
  359. * PPS16[7:2] - Reserved
  360. */
  361. u8 initial_xmit_delay_high;
  362. /**
  363. * @initial_xmit_delay_low:
  364. * PPS17[7:0] - Least significant 8 bits of initial transmission delay.
  365. */
  366. u8 initial_xmit_delay_low;
  367. /**
  368. * @initial_dec_delay:
  369. *
  370. * PPS18[7:0], PPS19[7:0] - Initial decoding delay which is the number
  371. * of pixel times that the decoder accumulates data in its rate buffer
  372. * before starting to decode and output pixels.
  373. */
  374. __be16 initial_dec_delay;
  375. /**
  376. * @pps20_reserved:
  377. *
  378. * PPS20[7:0] - Reserved
  379. */
  380. u8 pps20_reserved;
  381. /**
  382. * @initial_scale_value:
  383. * PPS21[5:0] - Initial rcXformScale factor used at beginning
  384. * of a slice.
  385. * PPS21[7:6] - Reserved
  386. */
  387. u8 initial_scale_value;
  388. /**
  389. * @scale_increment_interval:
  390. * PPS22[7:0], PPS23[7:0] - Number of group times between incrementing
  391. * the rcXformScale factor at end of a slice.
  392. */
  393. __be16 scale_increment_interval;
  394. /**
  395. * @scale_decrement_interval_high:
  396. * PPS24[3:0] - Higher 4 bits indicating number of group times between
  397. * decrementing the rcXformScale factor at beginning of a slice.
  398. * PPS24[7:4] - Reserved
  399. */
  400. u8 scale_decrement_interval_high;
  401. /**
  402. * @scale_decrement_interval_low:
  403. * PPS25[7:0] - Lower 8 bits of scale decrement interval
  404. */
  405. u8 scale_decrement_interval_low;
  406. /**
  407. * @pps26_reserved:
  408. * PPS26[7:0]
  409. */
  410. u8 pps26_reserved;
  411. /**
  412. * @first_line_bpg_offset:
  413. * PPS27[4:0] - Number of additional bits that are allocated
  414. * for each group on first line of a slice.
  415. * PPS27[7:5] - Reserved
  416. */
  417. u8 first_line_bpg_offset;
  418. /**
  419. * @nfl_bpg_offset:
  420. * PPS28[7:0], PPS29[7:0] - Number of bits including frac bits
  421. * deallocated for each group for groups after the first line of slice.
  422. */
  423. __be16 nfl_bpg_offset;
  424. /**
  425. * @slice_bpg_offset:
  426. * PPS30, PPS31[7:0] - Number of bits that are deallocated for each
  427. * group to enforce the slice constraint.
  428. */
  429. __be16 slice_bpg_offset;
  430. /**
  431. * @initial_offset:
  432. * PPS32,33[7:0] - Initial value for rcXformOffset
  433. */
  434. __be16 initial_offset;
  435. /**
  436. * @final_offset:
  437. * PPS34,35[7:0] - Maximum end-of-slice value for rcXformOffset
  438. */
  439. __be16 final_offset;
  440. /**
  441. * @flatness_min_qp:
  442. * PPS36[4:0] - Minimum QP at which flatness is signaled and
  443. * flatness QP adjustment is made.
  444. * PPS36[7:5] - Reserved
  445. */
  446. u8 flatness_min_qp;
  447. /**
  448. * @flatness_max_qp:
  449. * PPS37[4:0] - Max QP at which flatness is signalled and
  450. * the flatness adjustment is made.
  451. * PPS37[7:5] - Reserved
  452. */
  453. u8 flatness_max_qp;
  454. /**
  455. * @rc_model_size:
  456. * PPS38,39[7:0] - Number of bits within RC Model.
  457. */
  458. __be16 rc_model_size;
  459. /**
  460. * @rc_edge_factor:
  461. * PPS40[3:0] - Ratio of current activity vs, previous
  462. * activity to determine presence of edge.
  463. * PPS40[7:4] - Reserved
  464. */
  465. u8 rc_edge_factor;
  466. /**
  467. * @rc_quant_incr_limit0:
  468. * PPS41[4:0] - QP threshold used in short term RC
  469. * PPS41[7:5] - Reserved
  470. */
  471. u8 rc_quant_incr_limit0;
  472. /**
  473. * @rc_quant_incr_limit1:
  474. * PPS42[4:0] - QP threshold used in short term RC
  475. * PPS42[7:5] - Reserved
  476. */
  477. u8 rc_quant_incr_limit1;
  478. /**
  479. * @rc_tgt_offset:
  480. * PPS43[3:0] - Lower end of the variability range around the target
  481. * bits per group that is allowed by short term RC.
  482. * PPS43[7:4]- Upper end of the variability range around the target
  483. * bits per group that i allowed by short term rc.
  484. */
  485. u8 rc_tgt_offset;
  486. /**
  487. * @rc_buf_thresh:
  488. * PPS44[7:0] - PPS57[7:0] - Specifies the thresholds in RC model for
  489. * the 15 ranges defined by 14 thresholds.
  490. */
  491. u8 rc_buf_thresh[DSC_NUM_BUF_RANGES - 1];
  492. /**
  493. * @rc_range_parameters:
  494. * PPS58[7:0] - PPS87[7:0]
  495. * Parameters that correspond to each of the 15 ranges.
  496. */
  497. __be16 rc_range_parameters[DSC_NUM_BUF_RANGES];
  498. /**
  499. * @native_422_420:
  500. * PPS88[0] - 0 = Native 4:2:2 not used
  501. * 1 = Native 4:2:2 used
  502. * PPS88[1] - 0 = Native 4:2:0 not use
  503. * 1 = Native 4:2:0 used
  504. * PPS88[7:2] - Reserved 6 bits
  505. */
  506. u8 native_422_420;
  507. /**
  508. * @second_line_bpg_offset:
  509. * PPS89[4:0] - Additional bits/group budget for the
  510. * second line of a slice in Native 4:2:0 mode.
  511. * Set to 0 if DSC minor version is 1 or native420 is 0.
  512. * PPS89[7:5] - Reserved
  513. */
  514. u8 second_line_bpg_offset;
  515. /**
  516. * @nsl_bpg_offset:
  517. * PPS90[7:0], PPS91[7:0] - Number of bits that are deallocated
  518. * for each group that is not in the second line of a slice.
  519. */
  520. __be16 nsl_bpg_offset;
  521. /**
  522. * @second_line_offset_adj:
  523. * PPS92[7:0], PPS93[7:0] - Used as offset adjustment for the second
  524. * line in Native 4:2:0 mode.
  525. */
  526. __be16 second_line_offset_adj;
  527. /**
  528. * @pps_long_94_reserved:
  529. * PPS 94, 95, 96, 97 - Reserved
  530. */
  531. u32 pps_long_94_reserved;
  532. /**
  533. * @pps_long_98_reserved:
  534. * PPS 98, 99, 100, 101 - Reserved
  535. */
  536. u32 pps_long_98_reserved;
  537. /**
  538. * @pps_long_102_reserved:
  539. * PPS 102, 103, 104, 105 - Reserved
  540. */
  541. u32 pps_long_102_reserved;
  542. /**
  543. * @pps_long_106_reserved:
  544. * PPS 106, 107, 108, 109 - reserved
  545. */
  546. u32 pps_long_106_reserved;
  547. /**
  548. * @pps_long_110_reserved:
  549. * PPS 110, 111, 112, 113 - reserved
  550. */
  551. u32 pps_long_110_reserved;
  552. /**
  553. * @pps_long_114_reserved:
  554. * PPS 114 - 117 - reserved
  555. */
  556. u32 pps_long_114_reserved;
  557. /**
  558. * @pps_long_118_reserved:
  559. * PPS 118 - 121 - reserved
  560. */
  561. u32 pps_long_118_reserved;
  562. /**
  563. * @pps_long_122_reserved:
  564. * PPS 122- 125 - reserved
  565. */
  566. u32 pps_long_122_reserved;
  567. /**
  568. * @pps_short_126_reserved:
  569. * PPS 126, 127 - reserved
  570. */
  571. __be16 pps_short_126_reserved;
  572. } __packed;
  573. /**
  574. * struct drm_dsc_pps_infoframe - DSC infoframe carrying the Picture Parameter
  575. * Set Metadata
  576. *
  577. * This structure represents the DSC PPS infoframe required to send the Picture
  578. * Parameter Set metadata required before enabling VESA Display Stream
  579. * Compression. This is based on the DP Secondary Data Packet structure and
  580. * comprises of SDP Header as defined &struct dp_sdp_header in drm_dp_helper.h
  581. * and PPS payload defined in &struct drm_dsc_picture_parameter_set.
  582. *
  583. * @pps_header: Header for PPS as per DP SDP header format of type
  584. * &struct dp_sdp_header
  585. * @pps_payload: PPS payload fields as per DSC specification Table 4-1
  586. * as represented in &struct drm_dsc_picture_parameter_set
  587. */
  588. struct drm_dsc_pps_infoframe {
  589. struct dp_sdp_header pps_header;
  590. struct drm_dsc_picture_parameter_set pps_payload;
  591. } __packed;
  592. #endif /* _DRM_DSC_H_ */