This source file includes following definitions.
- drm_dsc_dp_pps_header_init
- drm_dsc_pps_payload_pack
- drm_dsc_compute_rc_parameters
1
2
3
4
5
6
7
8
9 #include <linux/kernel.h>
10 #include <linux/module.h>
11 #include <linux/init.h>
12 #include <linux/errno.h>
13 #include <linux/byteorder/generic.h>
14 #include <drm/drm_print.h>
15 #include <drm/drm_dp_helper.h>
16 #include <drm/drm_dsc.h>
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 void drm_dsc_dp_pps_header_init(struct dp_sdp_header *pps_header)
44 {
45 memset(pps_header, 0, sizeof(*pps_header));
46
47 pps_header->HB1 = DP_SDP_PPS;
48 pps_header->HB2 = DP_SDP_PPS_HEADER_PAYLOAD_BYTES_MINUS_1;
49 }
50 EXPORT_SYMBOL(drm_dsc_dp_pps_header_init);
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69 void drm_dsc_pps_payload_pack(struct drm_dsc_picture_parameter_set *pps_payload,
70 const struct drm_dsc_config *dsc_cfg)
71 {
72 int i;
73
74
75 BUILD_BUG_ON(sizeof(*pps_payload) !=
76 DP_SDP_PPS_HEADER_PAYLOAD_BYTES_MINUS_1 + 1);
77
78 memset(pps_payload, 0, sizeof(*pps_payload));
79
80
81 pps_payload->dsc_version =
82 dsc_cfg->dsc_version_minor |
83 dsc_cfg->dsc_version_major << DSC_PPS_VERSION_MAJOR_SHIFT;
84
85
86
87
88 pps_payload->pps_3 =
89 dsc_cfg->line_buf_depth |
90 dsc_cfg->bits_per_component << DSC_PPS_BPC_SHIFT;
91
92
93 pps_payload->pps_4 =
94 ((dsc_cfg->bits_per_pixel & DSC_PPS_BPP_HIGH_MASK) >>
95 DSC_PPS_MSB_SHIFT) |
96 dsc_cfg->vbr_enable << DSC_PPS_VBR_EN_SHIFT |
97 dsc_cfg->simple_422 << DSC_PPS_SIMPLE422_SHIFT |
98 dsc_cfg->convert_rgb << DSC_PPS_CONVERT_RGB_SHIFT |
99 dsc_cfg->block_pred_enable << DSC_PPS_BLOCK_PRED_EN_SHIFT;
100
101
102 pps_payload->bits_per_pixel_low =
103 (dsc_cfg->bits_per_pixel & DSC_PPS_LSB_MASK);
104
105
106
107
108
109
110
111
112
113 pps_payload->pic_height = cpu_to_be16(dsc_cfg->pic_height);
114
115
116 pps_payload->pic_width = cpu_to_be16(dsc_cfg->pic_width);
117
118
119 pps_payload->slice_height = cpu_to_be16(dsc_cfg->slice_height);
120
121
122 pps_payload->slice_width = cpu_to_be16(dsc_cfg->slice_width);
123
124
125 pps_payload->chunk_size = cpu_to_be16(dsc_cfg->slice_chunk_size);
126
127
128 pps_payload->initial_xmit_delay_high =
129 ((dsc_cfg->initial_xmit_delay &
130 DSC_PPS_INIT_XMIT_DELAY_HIGH_MASK) >>
131 DSC_PPS_MSB_SHIFT);
132
133
134 pps_payload->initial_xmit_delay_low =
135 (dsc_cfg->initial_xmit_delay & DSC_PPS_LSB_MASK);
136
137
138 pps_payload->initial_dec_delay =
139 cpu_to_be16(dsc_cfg->initial_dec_delay);
140
141
142
143
144 pps_payload->initial_scale_value =
145 dsc_cfg->initial_scale_value;
146
147
148 pps_payload->scale_increment_interval =
149 cpu_to_be16(dsc_cfg->scale_increment_interval);
150
151
152 pps_payload->scale_decrement_interval_high =
153 ((dsc_cfg->scale_decrement_interval &
154 DSC_PPS_SCALE_DEC_INT_HIGH_MASK) >>
155 DSC_PPS_MSB_SHIFT);
156
157
158 pps_payload->scale_decrement_interval_low =
159 (dsc_cfg->scale_decrement_interval & DSC_PPS_LSB_MASK);
160
161
162
163
164 pps_payload->first_line_bpg_offset =
165 dsc_cfg->first_line_bpg_offset;
166
167
168 pps_payload->nfl_bpg_offset =
169 cpu_to_be16(dsc_cfg->nfl_bpg_offset);
170
171
172 pps_payload->slice_bpg_offset =
173 cpu_to_be16(dsc_cfg->slice_bpg_offset);
174
175
176 pps_payload->initial_offset =
177 cpu_to_be16(dsc_cfg->initial_offset);
178
179
180 pps_payload->final_offset = cpu_to_be16(dsc_cfg->final_offset);
181
182
183 pps_payload->flatness_min_qp = dsc_cfg->flatness_min_qp;
184
185
186 pps_payload->flatness_max_qp = dsc_cfg->flatness_max_qp;
187
188
189 pps_payload->rc_model_size =
190 cpu_to_be16(DSC_RC_MODEL_SIZE_CONST);
191
192
193 pps_payload->rc_edge_factor = DSC_RC_EDGE_FACTOR_CONST;
194
195
196 pps_payload->rc_quant_incr_limit0 =
197 dsc_cfg->rc_quant_incr_limit0;
198
199
200 pps_payload->rc_quant_incr_limit1 =
201 dsc_cfg->rc_quant_incr_limit1;
202
203
204 pps_payload->rc_tgt_offset = DSC_RC_TGT_OFFSET_LO_CONST |
205 DSC_RC_TGT_OFFSET_HI_CONST << DSC_PPS_RC_TGT_OFFSET_HI_SHIFT;
206
207
208 for (i = 0; i < DSC_NUM_BUF_RANGES - 1; i++)
209 pps_payload->rc_buf_thresh[i] =
210 dsc_cfg->rc_buf_thresh[i];
211
212
213
214
215
216
217 for (i = 0; i < DSC_NUM_BUF_RANGES; i++) {
218 pps_payload->rc_range_parameters[i] =
219 ((dsc_cfg->rc_range_params[i].range_min_qp <<
220 DSC_PPS_RC_RANGE_MINQP_SHIFT) |
221 (dsc_cfg->rc_range_params[i].range_max_qp <<
222 DSC_PPS_RC_RANGE_MAXQP_SHIFT) |
223 (dsc_cfg->rc_range_params[i].range_bpg_offset));
224 pps_payload->rc_range_parameters[i] =
225 cpu_to_be16(pps_payload->rc_range_parameters[i]);
226 }
227
228
229 pps_payload->native_422_420 = dsc_cfg->native_422 |
230 dsc_cfg->native_420 << DSC_PPS_NATIVE_420_SHIFT;
231
232
233 pps_payload->second_line_bpg_offset =
234 dsc_cfg->second_line_bpg_offset;
235
236
237 pps_payload->nsl_bpg_offset =
238 cpu_to_be16(dsc_cfg->nsl_bpg_offset);
239
240
241 pps_payload->second_line_offset_adj =
242 cpu_to_be16(dsc_cfg->second_line_offset_adj);
243
244
245 }
246 EXPORT_SYMBOL(drm_dsc_pps_payload_pack);
247
248
249
250
251
252
253
254
255
256
257
258 int drm_dsc_compute_rc_parameters(struct drm_dsc_config *vdsc_cfg)
259 {
260 unsigned long groups_per_line = 0;
261 unsigned long groups_total = 0;
262 unsigned long num_extra_mux_bits = 0;
263 unsigned long slice_bits = 0;
264 unsigned long hrd_delay = 0;
265 unsigned long final_scale = 0;
266 unsigned long rbs_min = 0;
267
268 if (vdsc_cfg->native_420 || vdsc_cfg->native_422) {
269
270 groups_per_line = DIV_ROUND_UP(vdsc_cfg->slice_width / 2,
271 DSC_RC_PIXELS_PER_GROUP);
272
273
274 vdsc_cfg->slice_chunk_size = DIV_ROUND_UP(vdsc_cfg->slice_width / 2 *
275 vdsc_cfg->bits_per_pixel,
276 (8 * 16));
277 } else {
278
279 groups_per_line = DIV_ROUND_UP(vdsc_cfg->slice_width,
280 DSC_RC_PIXELS_PER_GROUP);
281
282
283 vdsc_cfg->slice_chunk_size = DIV_ROUND_UP(vdsc_cfg->slice_width *
284 vdsc_cfg->bits_per_pixel,
285 (8 * 16));
286 }
287
288 if (vdsc_cfg->convert_rgb)
289 num_extra_mux_bits = 3 * (vdsc_cfg->mux_word_size +
290 (4 * vdsc_cfg->bits_per_component + 4)
291 - 2);
292 else if (vdsc_cfg->native_422)
293 num_extra_mux_bits = 4 * vdsc_cfg->mux_word_size +
294 (4 * vdsc_cfg->bits_per_component + 4) +
295 3 * (4 * vdsc_cfg->bits_per_component) - 2;
296 else
297 num_extra_mux_bits = 3 * vdsc_cfg->mux_word_size +
298 (4 * vdsc_cfg->bits_per_component + 4) +
299 2 * (4 * vdsc_cfg->bits_per_component) - 2;
300
301 slice_bits = 8 * vdsc_cfg->slice_chunk_size * vdsc_cfg->slice_height;
302
303 while ((num_extra_mux_bits > 0) &&
304 ((slice_bits - num_extra_mux_bits) % vdsc_cfg->mux_word_size))
305 num_extra_mux_bits--;
306
307 if (groups_per_line < vdsc_cfg->initial_scale_value - 8)
308 vdsc_cfg->initial_scale_value = groups_per_line + 8;
309
310
311 if (vdsc_cfg->initial_scale_value > 8)
312 vdsc_cfg->scale_decrement_interval = groups_per_line /
313 (vdsc_cfg->initial_scale_value - 8);
314 else
315 vdsc_cfg->scale_decrement_interval = DSC_SCALE_DECREMENT_INTERVAL_MAX;
316
317 vdsc_cfg->final_offset = vdsc_cfg->rc_model_size -
318 (vdsc_cfg->initial_xmit_delay *
319 vdsc_cfg->bits_per_pixel + 8) / 16 + num_extra_mux_bits;
320
321 if (vdsc_cfg->final_offset >= vdsc_cfg->rc_model_size) {
322 DRM_DEBUG_KMS("FinalOfs < RcModelSze for this InitialXmitDelay\n");
323 return -ERANGE;
324 }
325
326 final_scale = (vdsc_cfg->rc_model_size * 8) /
327 (vdsc_cfg->rc_model_size - vdsc_cfg->final_offset);
328 if (vdsc_cfg->slice_height > 1)
329
330
331
332
333
334 vdsc_cfg->nfl_bpg_offset = DIV_ROUND_UP((vdsc_cfg->first_line_bpg_offset << 11),
335 (vdsc_cfg->slice_height - 1));
336 else
337 vdsc_cfg->nfl_bpg_offset = 0;
338
339
340 if (vdsc_cfg->nfl_bpg_offset > 65535) {
341 DRM_DEBUG_KMS("NflBpgOffset is too large for this slice height\n");
342 return -ERANGE;
343 }
344
345
346 groups_total = groups_per_line * vdsc_cfg->slice_height;
347
348
349 vdsc_cfg->slice_bpg_offset = DIV_ROUND_UP(((vdsc_cfg->rc_model_size -
350 vdsc_cfg->initial_offset +
351 num_extra_mux_bits) << 11),
352 groups_total);
353
354 if (final_scale > 9) {
355
356
357
358
359
360
361 vdsc_cfg->scale_increment_interval =
362 (vdsc_cfg->final_offset * (1 << 11)) /
363 ((vdsc_cfg->nfl_bpg_offset +
364 vdsc_cfg->slice_bpg_offset) *
365 (final_scale - 9));
366 } else {
367
368
369
370
371 vdsc_cfg->scale_increment_interval = 0;
372 }
373
374 if (vdsc_cfg->scale_increment_interval > 65535) {
375 DRM_DEBUG_KMS("ScaleIncrementInterval is large for slice height\n");
376 return -ERANGE;
377 }
378
379
380
381
382
383
384 rbs_min = vdsc_cfg->rc_model_size - vdsc_cfg->initial_offset +
385 DIV_ROUND_UP(vdsc_cfg->initial_xmit_delay *
386 vdsc_cfg->bits_per_pixel, 16) +
387 groups_per_line * vdsc_cfg->first_line_bpg_offset;
388
389 hrd_delay = DIV_ROUND_UP((rbs_min * 16), vdsc_cfg->bits_per_pixel);
390 vdsc_cfg->rc_bits = (hrd_delay * vdsc_cfg->bits_per_pixel) / 16;
391 vdsc_cfg->initial_dec_delay = hrd_delay - vdsc_cfg->initial_xmit_delay;
392
393 return 0;
394 }
395 EXPORT_SYMBOL(drm_dsc_compute_rc_parameters);