1 /*
2 * Copyright 2016 Advanced Micro Devices, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * Authors: AMD
23 *
24 */
25
26 #include "dm_services.h"
27 #include "dc.h"
28
29 #include "resource.h"
30 #include "include/irq_service_interface.h"
31 #include "dcn10/dcn10_resource.h"
32
33 #include "dcn10/dcn10_ipp.h"
34 #include "dcn10/dcn10_mpc.h"
35 #include "irq/dcn10/irq_service_dcn10.h"
36 #include "dcn10/dcn10_dpp.h"
37 #include "dcn10_optc.h"
38 #include "dcn10/dcn10_hw_sequencer.h"
39 #include "dce110/dce110_hw_sequencer.h"
40 #include "dcn10/dcn10_opp.h"
41 #include "dcn10/dcn10_link_encoder.h"
42 #include "dcn10/dcn10_stream_encoder.h"
43 #include "dce/dce_clocks.h"
44 #include "dce/dce_clock_source.h"
45 #include "dce/dce_audio.h"
46 #include "dce/dce_hwseq.h"
47 #include "../virtual/virtual_stream_encoder.h"
48 #include "dce110/dce110_resource.h"
49 #include "dce112/dce112_resource.h"
50 #include "dcn10_hubp.h"
51 #include "dcn10_hubbub.h"
52
53 #include "soc15_hw_ip.h"
54 #include "vega10_ip_offset.h"
55
56 #include "dcn/dcn_1_0_offset.h"
57 #include "dcn/dcn_1_0_sh_mask.h"
58
59 #include "nbio/nbio_7_0_offset.h"
60
61 #include "mmhub/mmhub_9_1_offset.h"
62 #include "mmhub/mmhub_9_1_sh_mask.h"
63
64 #include "reg_helper.h"
65 #include "dce/dce_abm.h"
66 #include "dce/dce_dmcu.h"
67 #include "dce/dce_aux.h"
68
69 const struct _vcs_dpi_ip_params_st dcn1_0_ip = {
70 .rob_buffer_size_kbytes = 64,
71 .det_buffer_size_kbytes = 164,
72 .dpte_buffer_size_in_pte_reqs = 42,
73 .dpp_output_buffer_pixels = 2560,
74 .opp_output_buffer_lines = 1,
75 .pixel_chunk_size_kbytes = 8,
76 .pte_enable = 1,
77 .pte_chunk_size_kbytes = 2,
78 .meta_chunk_size_kbytes = 2,
79 .writeback_chunk_size_kbytes = 2,
80 .line_buffer_size_bits = 589824,
81 .max_line_buffer_lines = 12,
82 .IsLineBufferBppFixed = 0,
83 .LineBufferFixedBpp = -1,
84 .writeback_luma_buffer_size_kbytes = 12,
85 .writeback_chroma_buffer_size_kbytes = 8,
86 .max_num_dpp = 4,
87 .max_num_wb = 2,
88 .max_dchub_pscl_bw_pix_per_clk = 4,
89 .max_pscl_lb_bw_pix_per_clk = 2,
90 .max_lb_vscl_bw_pix_per_clk = 4,
91 .max_vscl_hscl_bw_pix_per_clk = 4,
92 .max_hscl_ratio = 4,
93 .max_vscl_ratio = 4,
94 .hscl_mults = 4,
95 .vscl_mults = 4,
96 .max_hscl_taps = 8,
97 .max_vscl_taps = 8,
98 .dispclk_ramp_margin_percent = 1,
99 .underscan_factor = 1.10,
100 .min_vblank_lines = 14,
101 .dppclk_delay_subtotal = 90,
102 .dispclk_delay_subtotal = 42,
103 .dcfclk_cstate_latency = 10,
104 .max_inter_dcn_tile_repeaters = 8,
105 .can_vstartup_lines_exceed_vsync_plus_back_porch_lines_minus_one = 0,
106 .bug_forcing_LC_req_same_size_fixed = 0,
107 };
108
109 const struct _vcs_dpi_soc_bounding_box_st dcn1_0_soc = {
110 .sr_exit_time_us = 9.0,
111 .sr_enter_plus_exit_time_us = 11.0,
112 .urgent_latency_us = 4.0,
113 .writeback_latency_us = 12.0,
114 .ideal_dram_bw_after_urgent_percent = 80.0,
115 .max_request_size_bytes = 256,
116 .downspread_percent = 0.5,
117 .dram_page_open_time_ns = 50.0,
118 .dram_rw_turnaround_time_ns = 17.5,
119 .dram_return_buffer_per_channel_bytes = 8192,
120 .round_trip_ping_latency_dcfclk_cycles = 128,
121 .urgent_out_of_order_return_per_channel_bytes = 256,
122 .channel_interleave_bytes = 256,
123 .num_banks = 8,
124 .num_chans = 2,
125 .vmm_page_size_bytes = 4096,
126 .dram_clock_change_latency_us = 17.0,
127 .writeback_dram_clock_change_latency_us = 23.0,
128 .return_bus_width_bytes = 64,
129 };
130
131 #ifndef mmDP0_DP_DPHY_INTERNAL_CTRL
132 #define mmDP0_DP_DPHY_INTERNAL_CTRL 0x210f
133 #define mmDP0_DP_DPHY_INTERNAL_CTRL_BASE_IDX 2
134 #define mmDP1_DP_DPHY_INTERNAL_CTRL 0x220f
135 #define mmDP1_DP_DPHY_INTERNAL_CTRL_BASE_IDX 2
136 #define mmDP2_DP_DPHY_INTERNAL_CTRL 0x230f
137 #define mmDP2_DP_DPHY_INTERNAL_CTRL_BASE_IDX 2
138 #define mmDP3_DP_DPHY_INTERNAL_CTRL 0x240f
139 #define mmDP3_DP_DPHY_INTERNAL_CTRL_BASE_IDX 2
140 #define mmDP4_DP_DPHY_INTERNAL_CTRL 0x250f
141 #define mmDP4_DP_DPHY_INTERNAL_CTRL_BASE_IDX 2
142 #define mmDP5_DP_DPHY_INTERNAL_CTRL 0x260f
143 #define mmDP5_DP_DPHY_INTERNAL_CTRL_BASE_IDX 2
144 #define mmDP6_DP_DPHY_INTERNAL_CTRL 0x270f
145 #define mmDP6_DP_DPHY_INTERNAL_CTRL_BASE_IDX 2
146 #endif
147
148
149 enum dcn10_clk_src_array_id {
150 DCN10_CLK_SRC_PLL0,
151 DCN10_CLK_SRC_PLL1,
152 DCN10_CLK_SRC_PLL2,
153 DCN10_CLK_SRC_PLL3,
154 DCN10_CLK_SRC_TOTAL
155 };
156
157 /* begin *********************
158 * macros to expend register list macro defined in HW object header file */
159
160 /* DCN */
161 #define BASE_INNER(seg) \
162 DCE_BASE__INST0_SEG ## seg
163
164 #define BASE(seg) \
165 BASE_INNER(seg)
166
167 #define SR(reg_name)\
168 .reg_name = BASE(mm ## reg_name ## _BASE_IDX) + \
169 mm ## reg_name
170
171 #define SRI(reg_name, block, id)\
172 .reg_name = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
173 mm ## block ## id ## _ ## reg_name
174
175
176 #define SRII(reg_name, block, id)\
177 .reg_name[id] = BASE(mm ## block ## id ## _ ## reg_name ## _BASE_IDX) + \
178 mm ## block ## id ## _ ## reg_name
179
180 /* NBIO */
181 #define NBIO_BASE_INNER(seg) \
182 NBIF_BASE__INST0_SEG ## seg
183
184 #define NBIO_BASE(seg) \
185 NBIO_BASE_INNER(seg)
186
187 #define NBIO_SR(reg_name)\
188 .reg_name = NBIO_BASE(mm ## reg_name ## _BASE_IDX) + \
189 mm ## reg_name
190
191 /* MMHUB */
192 #define MMHUB_BASE_INNER(seg) \
193 MMHUB_BASE__INST0_SEG ## seg
194
195 #define MMHUB_BASE(seg) \
196 MMHUB_BASE_INNER(seg)
197
198 #define MMHUB_SR(reg_name)\
199 .reg_name = MMHUB_BASE(mm ## reg_name ## _BASE_IDX) + \
200 mm ## reg_name
201
202 /* macros to expend register list macro defined in HW object header file
203 * end *********************/
204
205
206 static const struct dce_dmcu_registers dmcu_regs = {
207 DMCU_DCN10_REG_LIST()
208 };
209
210 static const struct dce_dmcu_shift dmcu_shift = {
211 DMCU_MASK_SH_LIST_DCN10(__SHIFT)
212 };
213
214 static const struct dce_dmcu_mask dmcu_mask = {
215 DMCU_MASK_SH_LIST_DCN10(_MASK)
216 };
217
218 static const struct dce_abm_registers abm_regs = {
219 ABM_DCN10_REG_LIST(0)
220 };
221
222 static const struct dce_abm_shift abm_shift = {
223 ABM_MASK_SH_LIST_DCN10(__SHIFT)
224 };
225
226 static const struct dce_abm_mask abm_mask = {
227 ABM_MASK_SH_LIST_DCN10(_MASK)
228 };
229
230 #define stream_enc_regs(id)\
231 [id] = {\
232 SE_DCN_REG_LIST(id)\
233 }
234
235 static const struct dcn10_stream_enc_registers stream_enc_regs[] = {
236 stream_enc_regs(0),
237 stream_enc_regs(1),
238 stream_enc_regs(2),
239 stream_enc_regs(3),
240 };
241
242 static const struct dcn10_stream_encoder_shift se_shift = {
243 SE_COMMON_MASK_SH_LIST_DCN10(__SHIFT)
244 };
245
246 static const struct dcn10_stream_encoder_mask se_mask = {
247 SE_COMMON_MASK_SH_LIST_DCN10(_MASK)
248 };
249
250 #define audio_regs(id)\
251 [id] = {\
252 AUD_COMMON_REG_LIST(id)\
253 }
254
255 static const struct dce_audio_registers audio_regs[] = {
256 audio_regs(0),
257 audio_regs(1),
258 audio_regs(2),
259 audio_regs(3),
260 };
261
262 #define DCE120_AUD_COMMON_MASK_SH_LIST(mask_sh)\
263 SF(AZF0ENDPOINT0_AZALIA_F0_CODEC_ENDPOINT_INDEX, AZALIA_ENDPOINT_REG_INDEX, mask_sh),\
264 SF(AZF0ENDPOINT0_AZALIA_F0_CODEC_ENDPOINT_DATA, AZALIA_ENDPOINT_REG_DATA, mask_sh),\
265 AUD_COMMON_MASK_SH_LIST_BASE(mask_sh)
266
267 static const struct dce_audio_shift audio_shift = {
268 DCE120_AUD_COMMON_MASK_SH_LIST(__SHIFT)
269 };
270
271 static const struct dce_aduio_mask audio_mask = {
272 DCE120_AUD_COMMON_MASK_SH_LIST(_MASK)
273 };
274
275 #define aux_regs(id)\
276 [id] = {\
277 AUX_REG_LIST(id)\
278 }
279
280 static const struct dcn10_link_enc_aux_registers link_enc_aux_regs[] = {
281 aux_regs(0),
282 aux_regs(1),
283 aux_regs(2),
284 aux_regs(3)
285 };
286
287 #define hpd_regs(id)\
288 [id] = {\
289 HPD_REG_LIST(id)\
290 }
291
292 static const struct dcn10_link_enc_hpd_registers link_enc_hpd_regs[] = {
293 hpd_regs(0),
294 hpd_regs(1),
295 hpd_regs(2),
296 hpd_regs(3)
297 };
298
299 #define link_regs(id)\
300 [id] = {\
301 LE_DCN10_REG_LIST(id), \
302 SRI(DP_DPHY_INTERNAL_CTRL, DP, id) \
303 }
304
305 static const struct dcn10_link_enc_registers link_enc_regs[] = {
306 link_regs(0),
307 link_regs(1),
308 link_regs(2),
309 link_regs(3)
310 };
311
312 static const struct dcn10_link_enc_shift le_shift = {
313 LINK_ENCODER_MASK_SH_LIST_DCN10(__SHIFT)
314 };
315
316 static const struct dcn10_link_enc_mask le_mask = {
317 LINK_ENCODER_MASK_SH_LIST_DCN10(_MASK)
318 };
319
320 #define ipp_regs(id)\
321 [id] = {\
322 IPP_REG_LIST_DCN10(id),\
323 }
324
325 static const struct dcn10_ipp_registers ipp_regs[] = {
326 ipp_regs(0),
327 ipp_regs(1),
328 ipp_regs(2),
329 ipp_regs(3),
330 };
331
332 static const struct dcn10_ipp_shift ipp_shift = {
333 IPP_MASK_SH_LIST_DCN10(__SHIFT)
334 };
335
336 static const struct dcn10_ipp_mask ipp_mask = {
337 IPP_MASK_SH_LIST_DCN10(_MASK),
338 };
339
340 #define opp_regs(id)\
341 [id] = {\
342 OPP_REG_LIST_DCN10(id),\
343 }
344
345 static const struct dcn10_opp_registers opp_regs[] = {
346 opp_regs(0),
347 opp_regs(1),
348 opp_regs(2),
349 opp_regs(3),
350 };
351
352 static const struct dcn10_opp_shift opp_shift = {
353 OPP_MASK_SH_LIST_DCN10(__SHIFT)
354 };
355
356 static const struct dcn10_opp_mask opp_mask = {
357 OPP_MASK_SH_LIST_DCN10(_MASK),
358 };
359
360 #define aux_engine_regs(id)\
361 [id] = {\
362 AUX_COMMON_REG_LIST(id), \
363 .AUX_RESET_MASK = 0 \
364 }
365
366 static const struct dce110_aux_registers aux_engine_regs[] = {
367 aux_engine_regs(0),
368 aux_engine_regs(1),
369 aux_engine_regs(2),
370 aux_engine_regs(3),
371 aux_engine_regs(4),
372 aux_engine_regs(5)
373 };
374
375 #define tf_regs(id)\
376 [id] = {\
377 TF_REG_LIST_DCN10(id),\
378 }
379
380 static const struct dcn_dpp_registers tf_regs[] = {
381 tf_regs(0),
382 tf_regs(1),
383 tf_regs(2),
384 tf_regs(3),
385 };
386
387 static const struct dcn_dpp_shift tf_shift = {
388 TF_REG_LIST_SH_MASK_DCN10(__SHIFT),
389 TF_DEBUG_REG_LIST_SH_DCN10
390
391 };
392
393 static const struct dcn_dpp_mask tf_mask = {
394 TF_REG_LIST_SH_MASK_DCN10(_MASK),
395 TF_DEBUG_REG_LIST_MASK_DCN10
396 };
397
398 static const struct dcn_mpc_registers mpc_regs = {
399 MPC_COMMON_REG_LIST_DCN1_0(0),
400 MPC_COMMON_REG_LIST_DCN1_0(1),
401 MPC_COMMON_REG_LIST_DCN1_0(2),
402 MPC_COMMON_REG_LIST_DCN1_0(3),
403 MPC_OUT_MUX_COMMON_REG_LIST_DCN1_0(0),
404 MPC_OUT_MUX_COMMON_REG_LIST_DCN1_0(1),
405 MPC_OUT_MUX_COMMON_REG_LIST_DCN1_0(2),
406 MPC_OUT_MUX_COMMON_REG_LIST_DCN1_0(3)
407 };
408
409 static const struct dcn_mpc_shift mpc_shift = {
410 MPC_COMMON_MASK_SH_LIST_DCN1_0(__SHIFT)
411 };
412
413 static const struct dcn_mpc_mask mpc_mask = {
414 MPC_COMMON_MASK_SH_LIST_DCN1_0(_MASK),
415 };
416
417 #define tg_regs(id)\
418 [id] = {TG_COMMON_REG_LIST_DCN1_0(id)}
419
420 static const struct dcn_optc_registers tg_regs[] = {
421 tg_regs(0),
422 tg_regs(1),
423 tg_regs(2),
424 tg_regs(3),
425 };
426
427 static const struct dcn_optc_shift tg_shift = {
428 TG_COMMON_MASK_SH_LIST_DCN1_0(__SHIFT)
429 };
430
431 static const struct dcn_optc_mask tg_mask = {
432 TG_COMMON_MASK_SH_LIST_DCN1_0(_MASK)
433 };
434
435
436 static const struct bios_registers bios_regs = {
437 NBIO_SR(BIOS_SCRATCH_3),
438 NBIO_SR(BIOS_SCRATCH_6)
439 };
440
441 #define hubp_regs(id)\
442 [id] = {\
443 HUBP_REG_LIST_DCN10(id)\
444 }
445
446
447 static const struct dcn_mi_registers hubp_regs[] = {
448 hubp_regs(0),
449 hubp_regs(1),
450 hubp_regs(2),
451 hubp_regs(3),
452 };
453
454 static const struct dcn_mi_shift hubp_shift = {
455 HUBP_MASK_SH_LIST_DCN10(__SHIFT)
456 };
457
458 static const struct dcn_mi_mask hubp_mask = {
459 HUBP_MASK_SH_LIST_DCN10(_MASK)
460 };
461
462
463 static const struct dcn_hubbub_registers hubbub_reg = {
464 HUBBUB_REG_LIST_DCN10(0)
465 };
466
467 static const struct dcn_hubbub_shift hubbub_shift = {
468 HUBBUB_MASK_SH_LIST_DCN10(__SHIFT)
469 };
470
471 static const struct dcn_hubbub_mask hubbub_mask = {
472 HUBBUB_MASK_SH_LIST_DCN10(_MASK)
473 };
474
475 #define clk_src_regs(index, pllid)\
476 [index] = {\
477 CS_COMMON_REG_LIST_DCN1_0(index, pllid),\
478 }
479
480 static const struct dce110_clk_src_regs clk_src_regs[] = {
481 clk_src_regs(0, A),
482 clk_src_regs(1, B),
483 clk_src_regs(2, C),
484 clk_src_regs(3, D)
485 };
486
487 static const struct dce110_clk_src_shift cs_shift = {
488 CS_COMMON_MASK_SH_LIST_DCN1_0(__SHIFT)
489 };
490
491 static const struct dce110_clk_src_mask cs_mask = {
492 CS_COMMON_MASK_SH_LIST_DCN1_0(_MASK)
493 };
494
495
496 static const struct resource_caps res_cap = {
497 .num_timing_generator = 4,
498 .num_opp = 4,
499 .num_video_plane = 4,
500 .num_audio = 4,
501 .num_stream_encoder = 4,
502 .num_pll = 4,
503 };
504
505 static const struct dc_debug_options debug_defaults_drv = {
506 .sanity_checks = true,
507 .disable_dmcu = true,
508 .force_abm_enable = false,
509 .timing_trace = false,
510 .clock_trace = true,
511
512 /* raven smu dones't allow 0 disp clk,
513 * smu min disp clk limit is 50Mhz
514 * keep min disp clk 100Mhz avoid smu hang
515 */
516 .min_disp_clk_khz = 100000,
517
518 .disable_pplib_clock_request = false,
519 .disable_pplib_wm_range = false,
520 .pplib_wm_report_mode = WM_REPORT_DEFAULT,
521 .pipe_split_policy = MPC_SPLIT_AVOID_MULT_DISP,
522 .force_single_disp_pipe_split = true,
523 .disable_dcc = DCC_ENABLE,
524 .voltage_align_fclk = true,
525 .disable_stereo_support = true,
526 .vsr_support = true,
527 .performance_trace = false,
528 .az_endpoint_mute_only = true,
529 .recovery_enabled = false, /*enable this by default after testing.*/
530 .max_downscale_src_width = 3840,
531 };
532
533 static const struct dc_debug_options debug_defaults_diags = {
534 .disable_dmcu = true,
535 .force_abm_enable = false,
536 .timing_trace = true,
537 .clock_trace = true,
538 .disable_stutter = true,
539 .disable_pplib_clock_request = true,
540 .disable_pplib_wm_range = true
541 };
542
dcn10_dpp_destroy(struct dpp ** dpp)543 static void dcn10_dpp_destroy(struct dpp **dpp)
544 {
545 kfree(TO_DCN10_DPP(*dpp));
546 *dpp = NULL;
547 }
548
dcn10_dpp_create(struct dc_context * ctx,uint32_t inst)549 static struct dpp *dcn10_dpp_create(
550 struct dc_context *ctx,
551 uint32_t inst)
552 {
553 struct dcn10_dpp *dpp =
554 kzalloc(sizeof(struct dcn10_dpp), GFP_KERNEL);
555
556 if (!dpp)
557 return NULL;
558
559 dpp1_construct(dpp, ctx, inst,
560 &tf_regs[inst], &tf_shift, &tf_mask);
561 return &dpp->base;
562 }
563
dcn10_ipp_create(struct dc_context * ctx,uint32_t inst)564 static struct input_pixel_processor *dcn10_ipp_create(
565 struct dc_context *ctx, uint32_t inst)
566 {
567 struct dcn10_ipp *ipp =
568 kzalloc(sizeof(struct dcn10_ipp), GFP_KERNEL);
569
570 if (!ipp) {
571 BREAK_TO_DEBUGGER();
572 return NULL;
573 }
574
575 dcn10_ipp_construct(ipp, ctx, inst,
576 &ipp_regs[inst], &ipp_shift, &ipp_mask);
577 return &ipp->base;
578 }
579
580
dcn10_opp_create(struct dc_context * ctx,uint32_t inst)581 static struct output_pixel_processor *dcn10_opp_create(
582 struct dc_context *ctx, uint32_t inst)
583 {
584 struct dcn10_opp *opp =
585 kzalloc(sizeof(struct dcn10_opp), GFP_KERNEL);
586
587 if (!opp) {
588 BREAK_TO_DEBUGGER();
589 return NULL;
590 }
591
592 dcn10_opp_construct(opp, ctx, inst,
593 &opp_regs[inst], &opp_shift, &opp_mask);
594 return &opp->base;
595 }
596
dcn10_aux_engine_create(struct dc_context * ctx,uint32_t inst)597 struct aux_engine *dcn10_aux_engine_create(
598 struct dc_context *ctx,
599 uint32_t inst)
600 {
601 struct aux_engine_dce110 *aux_engine =
602 kzalloc(sizeof(struct aux_engine_dce110), GFP_KERNEL);
603
604 if (!aux_engine)
605 return NULL;
606
607 dce110_aux_engine_construct(aux_engine, ctx, inst,
608 SW_AUX_TIMEOUT_PERIOD_MULTIPLIER * AUX_TIMEOUT_PERIOD,
609 &aux_engine_regs[inst]);
610
611 return &aux_engine->base;
612 }
613
dcn10_mpc_create(struct dc_context * ctx)614 static struct mpc *dcn10_mpc_create(struct dc_context *ctx)
615 {
616 struct dcn10_mpc *mpc10 = kzalloc(sizeof(struct dcn10_mpc),
617 GFP_KERNEL);
618
619 if (!mpc10)
620 return NULL;
621
622 dcn10_mpc_construct(mpc10, ctx,
623 &mpc_regs,
624 &mpc_shift,
625 &mpc_mask,
626 4);
627
628 return &mpc10->base;
629 }
630
dcn10_hubbub_create(struct dc_context * ctx)631 static struct hubbub *dcn10_hubbub_create(struct dc_context *ctx)
632 {
633 struct hubbub *hubbub = kzalloc(sizeof(struct hubbub),
634 GFP_KERNEL);
635
636 if (!hubbub)
637 return NULL;
638
639 hubbub1_construct(hubbub, ctx,
640 &hubbub_reg,
641 &hubbub_shift,
642 &hubbub_mask);
643
644 return hubbub;
645 }
646
dcn10_timing_generator_create(struct dc_context * ctx,uint32_t instance)647 static struct timing_generator *dcn10_timing_generator_create(
648 struct dc_context *ctx,
649 uint32_t instance)
650 {
651 struct optc *tgn10 =
652 kzalloc(sizeof(struct optc), GFP_KERNEL);
653
654 if (!tgn10)
655 return NULL;
656
657 tgn10->base.inst = instance;
658 tgn10->base.ctx = ctx;
659
660 tgn10->tg_regs = &tg_regs[instance];
661 tgn10->tg_shift = &tg_shift;
662 tgn10->tg_mask = &tg_mask;
663
664 dcn10_timing_generator_init(tgn10);
665
666 return &tgn10->base;
667 }
668
669 static const struct encoder_feature_support link_enc_feature = {
670 .max_hdmi_deep_color = COLOR_DEPTH_121212,
671 .max_hdmi_pixel_clock = 600000,
672 .ycbcr420_supported = true,
673 .flags.bits.IS_HBR2_CAPABLE = true,
674 .flags.bits.IS_HBR3_CAPABLE = true,
675 .flags.bits.IS_TPS3_CAPABLE = true,
676 .flags.bits.IS_TPS4_CAPABLE = true,
677 .flags.bits.IS_YCBCR_CAPABLE = true
678 };
679
dcn10_link_encoder_create(const struct encoder_init_data * enc_init_data)680 struct link_encoder *dcn10_link_encoder_create(
681 const struct encoder_init_data *enc_init_data)
682 {
683 struct dcn10_link_encoder *enc10 =
684 kzalloc(sizeof(struct dcn10_link_encoder), GFP_KERNEL);
685
686 if (!enc10)
687 return NULL;
688
689 dcn10_link_encoder_construct(enc10,
690 enc_init_data,
691 &link_enc_feature,
692 &link_enc_regs[enc_init_data->transmitter],
693 &link_enc_aux_regs[enc_init_data->channel - 1],
694 &link_enc_hpd_regs[enc_init_data->hpd_source],
695 &le_shift,
696 &le_mask);
697
698 return &enc10->base;
699 }
700
dcn10_clock_source_create(struct dc_context * ctx,struct dc_bios * bios,enum clock_source_id id,const struct dce110_clk_src_regs * regs,bool dp_clk_src)701 struct clock_source *dcn10_clock_source_create(
702 struct dc_context *ctx,
703 struct dc_bios *bios,
704 enum clock_source_id id,
705 const struct dce110_clk_src_regs *regs,
706 bool dp_clk_src)
707 {
708 struct dce110_clk_src *clk_src =
709 kzalloc(sizeof(struct dce110_clk_src), GFP_KERNEL);
710
711 if (!clk_src)
712 return NULL;
713
714 if (dce110_clk_src_construct(clk_src, ctx, bios, id,
715 regs, &cs_shift, &cs_mask)) {
716 clk_src->base.dp_clk_src = dp_clk_src;
717 return &clk_src->base;
718 }
719
720 kfree(clk_src);
721 BREAK_TO_DEBUGGER();
722 return NULL;
723 }
724
read_dce_straps(struct dc_context * ctx,struct resource_straps * straps)725 static void read_dce_straps(
726 struct dc_context *ctx,
727 struct resource_straps *straps)
728 {
729 generic_reg_get(ctx, mmDC_PINSTRAPS + BASE(mmDC_PINSTRAPS_BASE_IDX),
730 FN(DC_PINSTRAPS, DC_PINSTRAPS_AUDIO), &straps->dc_pinstraps_audio);
731 }
732
create_audio(struct dc_context * ctx,unsigned int inst)733 static struct audio *create_audio(
734 struct dc_context *ctx, unsigned int inst)
735 {
736 return dce_audio_create(ctx, inst,
737 &audio_regs[inst], &audio_shift, &audio_mask);
738 }
739
dcn10_stream_encoder_create(enum engine_id eng_id,struct dc_context * ctx)740 static struct stream_encoder *dcn10_stream_encoder_create(
741 enum engine_id eng_id,
742 struct dc_context *ctx)
743 {
744 struct dcn10_stream_encoder *enc1 =
745 kzalloc(sizeof(struct dcn10_stream_encoder), GFP_KERNEL);
746
747 if (!enc1)
748 return NULL;
749
750 dcn10_stream_encoder_construct(enc1, ctx, ctx->dc_bios, eng_id,
751 &stream_enc_regs[eng_id],
752 &se_shift, &se_mask);
753 return &enc1->base;
754 }
755
756 static const struct dce_hwseq_registers hwseq_reg = {
757 HWSEQ_DCN1_REG_LIST()
758 };
759
760 static const struct dce_hwseq_shift hwseq_shift = {
761 HWSEQ_DCN1_MASK_SH_LIST(__SHIFT)
762 };
763
764 static const struct dce_hwseq_mask hwseq_mask = {
765 HWSEQ_DCN1_MASK_SH_LIST(_MASK)
766 };
767
dcn10_hwseq_create(struct dc_context * ctx)768 static struct dce_hwseq *dcn10_hwseq_create(
769 struct dc_context *ctx)
770 {
771 struct dce_hwseq *hws = kzalloc(sizeof(struct dce_hwseq), GFP_KERNEL);
772
773 if (hws) {
774 hws->ctx = ctx;
775 hws->regs = &hwseq_reg;
776 hws->shifts = &hwseq_shift;
777 hws->masks = &hwseq_mask;
778 hws->wa.DEGVIDCN10_253 = true;
779 hws->wa.false_optc_underflow = true;
780 hws->wa.DEGVIDCN10_254 = true;
781 }
782 return hws;
783 }
784
785 static const struct resource_create_funcs res_create_funcs = {
786 .read_dce_straps = read_dce_straps,
787 .create_audio = create_audio,
788 .create_stream_encoder = dcn10_stream_encoder_create,
789 .create_hwseq = dcn10_hwseq_create,
790 };
791
792 static const struct resource_create_funcs res_create_maximus_funcs = {
793 .read_dce_straps = NULL,
794 .create_audio = NULL,
795 .create_stream_encoder = NULL,
796 .create_hwseq = dcn10_hwseq_create,
797 };
798
dcn10_clock_source_destroy(struct clock_source ** clk_src)799 void dcn10_clock_source_destroy(struct clock_source **clk_src)
800 {
801 kfree(TO_DCE110_CLK_SRC(*clk_src));
802 *clk_src = NULL;
803 }
804
dcn10_pp_smu_create(struct dc_context * ctx)805 static struct pp_smu_funcs_rv *dcn10_pp_smu_create(struct dc_context *ctx)
806 {
807 struct pp_smu_funcs_rv *pp_smu = kzalloc(sizeof(*pp_smu), GFP_KERNEL);
808
809 if (!pp_smu)
810 return pp_smu;
811
812 dm_pp_get_funcs_rv(ctx, pp_smu);
813 return pp_smu;
814 }
815
destruct(struct dcn10_resource_pool * pool)816 static void destruct(struct dcn10_resource_pool *pool)
817 {
818 unsigned int i;
819
820 for (i = 0; i < pool->base.stream_enc_count; i++) {
821 if (pool->base.stream_enc[i] != NULL) {
822 /* TODO: free dcn version of stream encoder once implemented
823 * rather than using virtual stream encoder
824 */
825 kfree(pool->base.stream_enc[i]);
826 pool->base.stream_enc[i] = NULL;
827 }
828 }
829
830 if (pool->base.mpc != NULL) {
831 kfree(TO_DCN10_MPC(pool->base.mpc));
832 pool->base.mpc = NULL;
833 }
834
835 if (pool->base.hubbub != NULL) {
836 kfree(pool->base.hubbub);
837 pool->base.hubbub = NULL;
838 }
839
840 for (i = 0; i < pool->base.pipe_count; i++) {
841 if (pool->base.opps[i] != NULL)
842 pool->base.opps[i]->funcs->opp_destroy(&pool->base.opps[i]);
843
844 if (pool->base.dpps[i] != NULL)
845 dcn10_dpp_destroy(&pool->base.dpps[i]);
846
847 if (pool->base.ipps[i] != NULL)
848 pool->base.ipps[i]->funcs->ipp_destroy(&pool->base.ipps[i]);
849
850 if (pool->base.hubps[i] != NULL) {
851 kfree(TO_DCN10_HUBP(pool->base.hubps[i]));
852 pool->base.hubps[i] = NULL;
853 }
854
855 if (pool->base.irqs != NULL) {
856 dal_irq_service_destroy(&pool->base.irqs);
857 }
858
859 if (pool->base.timing_generators[i] != NULL) {
860 kfree(DCN10TG_FROM_TG(pool->base.timing_generators[i]));
861 pool->base.timing_generators[i] = NULL;
862 }
863
864 if (pool->base.engines[i] != NULL)
865 pool->base.engines[i]->funcs->destroy_engine(&pool->base.engines[i]);
866 }
867
868 for (i = 0; i < pool->base.stream_enc_count; i++)
869 kfree(pool->base.stream_enc[i]);
870
871 for (i = 0; i < pool->base.audio_count; i++) {
872 if (pool->base.audios[i])
873 dce_aud_destroy(&pool->base.audios[i]);
874 }
875
876 for (i = 0; i < pool->base.clk_src_count; i++) {
877 if (pool->base.clock_sources[i] != NULL) {
878 dcn10_clock_source_destroy(&pool->base.clock_sources[i]);
879 pool->base.clock_sources[i] = NULL;
880 }
881 }
882
883 if (pool->base.dp_clock_source != NULL) {
884 dcn10_clock_source_destroy(&pool->base.dp_clock_source);
885 pool->base.dp_clock_source = NULL;
886 }
887
888 if (pool->base.abm != NULL)
889 dce_abm_destroy(&pool->base.abm);
890
891 if (pool->base.dmcu != NULL)
892 dce_dmcu_destroy(&pool->base.dmcu);
893
894 if (pool->base.dccg != NULL)
895 dce_dccg_destroy(&pool->base.dccg);
896
897 kfree(pool->base.pp_smu);
898 }
899
dcn10_hubp_create(struct dc_context * ctx,uint32_t inst)900 static struct hubp *dcn10_hubp_create(
901 struct dc_context *ctx,
902 uint32_t inst)
903 {
904 struct dcn10_hubp *hubp1 =
905 kzalloc(sizeof(struct dcn10_hubp), GFP_KERNEL);
906
907 if (!hubp1)
908 return NULL;
909
910 dcn10_hubp_construct(hubp1, ctx, inst,
911 &hubp_regs[inst], &hubp_shift, &hubp_mask);
912 return &hubp1->base;
913 }
914
get_pixel_clock_parameters(const struct pipe_ctx * pipe_ctx,struct pixel_clk_params * pixel_clk_params)915 static void get_pixel_clock_parameters(
916 const struct pipe_ctx *pipe_ctx,
917 struct pixel_clk_params *pixel_clk_params)
918 {
919 const struct dc_stream_state *stream = pipe_ctx->stream;
920 pixel_clk_params->requested_pix_clk = stream->timing.pix_clk_khz;
921 pixel_clk_params->encoder_object_id = stream->sink->link->link_enc->id;
922 pixel_clk_params->signal_type = pipe_ctx->stream->signal;
923 pixel_clk_params->controller_id = pipe_ctx->stream_res.tg->inst + 1;
924 /* TODO: un-hardcode*/
925 pixel_clk_params->requested_sym_clk = LINK_RATE_LOW *
926 LINK_RATE_REF_FREQ_IN_KHZ;
927 pixel_clk_params->flags.ENABLE_SS = 0;
928 pixel_clk_params->color_depth =
929 stream->timing.display_color_depth;
930 pixel_clk_params->flags.DISPLAY_BLANKED = 1;
931 pixel_clk_params->pixel_encoding = stream->timing.pixel_encoding;
932
933 if (stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR422)
934 pixel_clk_params->color_depth = COLOR_DEPTH_888;
935
936 if (stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR420)
937 pixel_clk_params->requested_pix_clk /= 2;
938
939 }
940
build_clamping_params(struct dc_stream_state * stream)941 static void build_clamping_params(struct dc_stream_state *stream)
942 {
943 stream->clamping.clamping_level = CLAMPING_FULL_RANGE;
944 stream->clamping.c_depth = stream->timing.display_color_depth;
945 stream->clamping.pixel_encoding = stream->timing.pixel_encoding;
946 }
947
build_pipe_hw_param(struct pipe_ctx * pipe_ctx)948 static void build_pipe_hw_param(struct pipe_ctx *pipe_ctx)
949 {
950
951 get_pixel_clock_parameters(pipe_ctx, &pipe_ctx->stream_res.pix_clk_params);
952
953 pipe_ctx->clock_source->funcs->get_pix_clk_dividers(
954 pipe_ctx->clock_source,
955 &pipe_ctx->stream_res.pix_clk_params,
956 &pipe_ctx->pll_settings);
957
958 pipe_ctx->stream->clamping.pixel_encoding = pipe_ctx->stream->timing.pixel_encoding;
959
960 resource_build_bit_depth_reduction_params(pipe_ctx->stream,
961 &pipe_ctx->stream->bit_depth_params);
962 build_clamping_params(pipe_ctx->stream);
963 }
964
build_mapped_resource(const struct dc * dc,struct dc_state * context,struct dc_stream_state * stream)965 static enum dc_status build_mapped_resource(
966 const struct dc *dc,
967 struct dc_state *context,
968 struct dc_stream_state *stream)
969 {
970 struct pipe_ctx *pipe_ctx = resource_get_head_pipe_for_stream(&context->res_ctx, stream);
971
972 /*TODO Seems unneeded anymore */
973 /* if (old_context && resource_is_stream_unchanged(old_context, stream)) {
974 if (stream != NULL && old_context->streams[i] != NULL) {
975 todo: shouldn't have to copy missing parameter here
976 resource_build_bit_depth_reduction_params(stream,
977 &stream->bit_depth_params);
978 stream->clamping.pixel_encoding =
979 stream->timing.pixel_encoding;
980
981 resource_build_bit_depth_reduction_params(stream,
982 &stream->bit_depth_params);
983 build_clamping_params(stream);
984
985 continue;
986 }
987 }
988 */
989
990 if (!pipe_ctx)
991 return DC_ERROR_UNEXPECTED;
992
993 build_pipe_hw_param(pipe_ctx);
994 return DC_OK;
995 }
996
dcn10_add_stream_to_ctx(struct dc * dc,struct dc_state * new_ctx,struct dc_stream_state * dc_stream)997 enum dc_status dcn10_add_stream_to_ctx(
998 struct dc *dc,
999 struct dc_state *new_ctx,
1000 struct dc_stream_state *dc_stream)
1001 {
1002 enum dc_status result = DC_ERROR_UNEXPECTED;
1003
1004 result = resource_map_pool_resources(dc, new_ctx, dc_stream);
1005
1006 if (result == DC_OK)
1007 result = resource_map_phy_clock_resources(dc, new_ctx, dc_stream);
1008
1009
1010 if (result == DC_OK)
1011 result = build_mapped_resource(dc, new_ctx, dc_stream);
1012
1013 return result;
1014 }
1015
dcn10_acquire_idle_pipe_for_layer(struct dc_state * context,const struct resource_pool * pool,struct dc_stream_state * stream)1016 static struct pipe_ctx *dcn10_acquire_idle_pipe_for_layer(
1017 struct dc_state *context,
1018 const struct resource_pool *pool,
1019 struct dc_stream_state *stream)
1020 {
1021 struct resource_context *res_ctx = &context->res_ctx;
1022 struct pipe_ctx *head_pipe = resource_get_head_pipe_for_stream(res_ctx, stream);
1023 struct pipe_ctx *idle_pipe = find_idle_secondary_pipe(res_ctx, pool);
1024
1025 if (!head_pipe) {
1026 ASSERT(0);
1027 return NULL;
1028 }
1029
1030 if (!idle_pipe)
1031 return NULL;
1032
1033 idle_pipe->stream = head_pipe->stream;
1034 idle_pipe->stream_res.tg = head_pipe->stream_res.tg;
1035 idle_pipe->stream_res.abm = head_pipe->stream_res.abm;
1036 idle_pipe->stream_res.opp = head_pipe->stream_res.opp;
1037
1038 idle_pipe->plane_res.hubp = pool->hubps[idle_pipe->pipe_idx];
1039 idle_pipe->plane_res.ipp = pool->ipps[idle_pipe->pipe_idx];
1040 idle_pipe->plane_res.dpp = pool->dpps[idle_pipe->pipe_idx];
1041 idle_pipe->plane_res.mpcc_inst = pool->dpps[idle_pipe->pipe_idx]->inst;
1042
1043 return idle_pipe;
1044 }
1045
dcn10_get_dcc_compression_cap(const struct dc * dc,const struct dc_dcc_surface_param * input,struct dc_surface_dcc_cap * output)1046 static bool dcn10_get_dcc_compression_cap(const struct dc *dc,
1047 const struct dc_dcc_surface_param *input,
1048 struct dc_surface_dcc_cap *output)
1049 {
1050 return dc->res_pool->hubbub->funcs->get_dcc_compression_cap(
1051 dc->res_pool->hubbub,
1052 input,
1053 output);
1054 }
1055
dcn10_destroy_resource_pool(struct resource_pool ** pool)1056 static void dcn10_destroy_resource_pool(struct resource_pool **pool)
1057 {
1058 struct dcn10_resource_pool *dcn10_pool = TO_DCN10_RES_POOL(*pool);
1059
1060 destruct(dcn10_pool);
1061 kfree(dcn10_pool);
1062 *pool = NULL;
1063 }
1064
dcn10_validate_plane(const struct dc_plane_state * plane_state,struct dc_caps * caps)1065 static enum dc_status dcn10_validate_plane(const struct dc_plane_state *plane_state, struct dc_caps *caps)
1066 {
1067 if (plane_state->format >= SURFACE_PIXEL_FORMAT_VIDEO_BEGIN
1068 && caps->max_video_width != 0
1069 && plane_state->src_rect.width > caps->max_video_width)
1070 return DC_FAIL_SURFACE_VALIDATE;
1071
1072 return DC_OK;
1073 }
1074
1075 static const struct dc_cap_funcs cap_funcs = {
1076 .get_dcc_compression_cap = dcn10_get_dcc_compression_cap
1077 };
1078
1079 static const struct resource_funcs dcn10_res_pool_funcs = {
1080 .destroy = dcn10_destroy_resource_pool,
1081 .link_enc_create = dcn10_link_encoder_create,
1082 .validate_bandwidth = dcn_validate_bandwidth,
1083 .acquire_idle_pipe_for_layer = dcn10_acquire_idle_pipe_for_layer,
1084 .validate_plane = dcn10_validate_plane,
1085 .add_stream_to_ctx = dcn10_add_stream_to_ctx
1086 };
1087
read_pipe_fuses(struct dc_context * ctx)1088 static uint32_t read_pipe_fuses(struct dc_context *ctx)
1089 {
1090 uint32_t value = dm_read_reg_soc15(ctx, mmCC_DC_PIPE_DIS, 0);
1091 /* RV1 support max 4 pipes */
1092 value = value & 0xf;
1093 return value;
1094 }
1095
construct(uint8_t num_virtual_links,struct dc * dc,struct dcn10_resource_pool * pool)1096 static bool construct(
1097 uint8_t num_virtual_links,
1098 struct dc *dc,
1099 struct dcn10_resource_pool *pool)
1100 {
1101 int i;
1102 int j;
1103 struct dc_context *ctx = dc->ctx;
1104 uint32_t pipe_fuses = read_pipe_fuses(ctx);
1105
1106 ctx->dc_bios->regs = &bios_regs;
1107
1108 pool->base.res_cap = &res_cap;
1109 pool->base.funcs = &dcn10_res_pool_funcs;
1110
1111 /*
1112 * TODO fill in from actual raven resource when we create
1113 * more than virtual encoder
1114 */
1115
1116 /*************************************************
1117 * Resource + asic cap harcoding *
1118 *************************************************/
1119 pool->base.underlay_pipe_index = NO_UNDERLAY_PIPE;
1120
1121 /* max pipe num for ASIC before check pipe fuses */
1122 pool->base.pipe_count = pool->base.res_cap->num_timing_generator;
1123
1124 dc->caps.max_video_width = 3840;
1125 dc->caps.max_downscale_ratio = 200;
1126 dc->caps.i2c_speed_in_khz = 100;
1127 dc->caps.max_cursor_size = 256;
1128 dc->caps.max_slave_planes = 1;
1129 dc->caps.is_apu = true;
1130 dc->caps.post_blend_color_processing = false;
1131 /* Raven DP PHY HBR2 eye diagram pattern is not stable. Use TP4 */
1132 dc->caps.force_dp_tps4_for_cp2520 = true;
1133
1134 if (dc->ctx->dce_environment == DCE_ENV_PRODUCTION_DRV)
1135 dc->debug = debug_defaults_drv;
1136 else
1137 dc->debug = debug_defaults_diags;
1138
1139 /*************************************************
1140 * Create resources *
1141 *************************************************/
1142
1143 pool->base.clock_sources[DCN10_CLK_SRC_PLL0] =
1144 dcn10_clock_source_create(ctx, ctx->dc_bios,
1145 CLOCK_SOURCE_COMBO_PHY_PLL0,
1146 &clk_src_regs[0], false);
1147 pool->base.clock_sources[DCN10_CLK_SRC_PLL1] =
1148 dcn10_clock_source_create(ctx, ctx->dc_bios,
1149 CLOCK_SOURCE_COMBO_PHY_PLL1,
1150 &clk_src_regs[1], false);
1151 pool->base.clock_sources[DCN10_CLK_SRC_PLL2] =
1152 dcn10_clock_source_create(ctx, ctx->dc_bios,
1153 CLOCK_SOURCE_COMBO_PHY_PLL2,
1154 &clk_src_regs[2], false);
1155 pool->base.clock_sources[DCN10_CLK_SRC_PLL3] =
1156 dcn10_clock_source_create(ctx, ctx->dc_bios,
1157 CLOCK_SOURCE_COMBO_PHY_PLL3,
1158 &clk_src_regs[3], false);
1159
1160 pool->base.clk_src_count = DCN10_CLK_SRC_TOTAL;
1161
1162 pool->base.dp_clock_source =
1163 dcn10_clock_source_create(ctx, ctx->dc_bios,
1164 CLOCK_SOURCE_ID_DP_DTO,
1165 /* todo: not reuse phy_pll registers */
1166 &clk_src_regs[0], true);
1167
1168 for (i = 0; i < pool->base.clk_src_count; i++) {
1169 if (pool->base.clock_sources[i] == NULL) {
1170 dm_error("DC: failed to create clock sources!\n");
1171 BREAK_TO_DEBUGGER();
1172 goto fail;
1173 }
1174 }
1175
1176 pool->base.dccg = dcn1_dccg_create(ctx);
1177 if (pool->base.dccg == NULL) {
1178 dm_error("DC: failed to create display clock!\n");
1179 BREAK_TO_DEBUGGER();
1180 goto fail;
1181 }
1182
1183 pool->base.dmcu = dcn10_dmcu_create(ctx,
1184 &dmcu_regs,
1185 &dmcu_shift,
1186 &dmcu_mask);
1187 if (pool->base.dmcu == NULL) {
1188 dm_error("DC: failed to create dmcu!\n");
1189 BREAK_TO_DEBUGGER();
1190 goto fail;
1191 }
1192
1193 pool->base.abm = dce_abm_create(ctx,
1194 &abm_regs,
1195 &abm_shift,
1196 &abm_mask);
1197 if (pool->base.abm == NULL) {
1198 dm_error("DC: failed to create abm!\n");
1199 BREAK_TO_DEBUGGER();
1200 goto fail;
1201 }
1202
1203 dml_init_instance(&dc->dml, DML_PROJECT_RAVEN1);
1204 memcpy(dc->dcn_ip, &dcn10_ip_defaults, sizeof(dcn10_ip_defaults));
1205 memcpy(dc->dcn_soc, &dcn10_soc_defaults, sizeof(dcn10_soc_defaults));
1206
1207 if (ASICREV_IS_RV1_F0(dc->ctx->asic_id.hw_internal_rev)) {
1208 dc->dcn_soc->urgent_latency = 3;
1209 dc->debug.disable_dmcu = true;
1210 dc->dcn_soc->fabric_and_dram_bandwidth_vmax0p9 = 41.60f;
1211 }
1212
1213
1214 dc->dcn_soc->number_of_channels = dc->ctx->asic_id.vram_width / ddr4_dram_width;
1215 ASSERT(dc->dcn_soc->number_of_channels < 3);
1216 if (dc->dcn_soc->number_of_channels == 0)/*old sbios bug*/
1217 dc->dcn_soc->number_of_channels = 2;
1218
1219 if (dc->dcn_soc->number_of_channels == 1) {
1220 dc->dcn_soc->fabric_and_dram_bandwidth_vmax0p9 = 19.2f;
1221 dc->dcn_soc->fabric_and_dram_bandwidth_vnom0p8 = 17.066f;
1222 dc->dcn_soc->fabric_and_dram_bandwidth_vmid0p72 = 14.933f;
1223 dc->dcn_soc->fabric_and_dram_bandwidth_vmin0p65 = 12.8f;
1224 if (ASICREV_IS_RV1_F0(dc->ctx->asic_id.hw_internal_rev)) {
1225 dc->dcn_soc->fabric_and_dram_bandwidth_vmax0p9 = 20.80f;
1226 }
1227 }
1228
1229 pool->base.pp_smu = dcn10_pp_smu_create(ctx);
1230
1231 if (!dc->debug.disable_pplib_clock_request)
1232 dcn_bw_update_from_pplib(dc);
1233 dcn_bw_sync_calcs_and_dml(dc);
1234 if (!dc->debug.disable_pplib_wm_range) {
1235 dc->res_pool = &pool->base;
1236 dcn_bw_notify_pplib_of_wm_ranges(dc);
1237 }
1238
1239 {
1240 struct irq_service_init_data init_data;
1241 init_data.ctx = dc->ctx;
1242 pool->base.irqs = dal_irq_service_dcn10_create(&init_data);
1243 if (!pool->base.irqs)
1244 goto fail;
1245 }
1246
1247 /* index to valid pipe resource */
1248 j = 0;
1249 /* mem input -> ipp -> dpp -> opp -> TG */
1250 for (i = 0; i < pool->base.pipe_count; i++) {
1251 /* if pipe is disabled, skip instance of HW pipe,
1252 * i.e, skip ASIC register instance
1253 */
1254 if ((pipe_fuses & (1 << i)) != 0)
1255 continue;
1256
1257 pool->base.hubps[j] = dcn10_hubp_create(ctx, i);
1258 if (pool->base.hubps[j] == NULL) {
1259 BREAK_TO_DEBUGGER();
1260 dm_error(
1261 "DC: failed to create memory input!\n");
1262 goto fail;
1263 }
1264
1265 pool->base.ipps[j] = dcn10_ipp_create(ctx, i);
1266 if (pool->base.ipps[j] == NULL) {
1267 BREAK_TO_DEBUGGER();
1268 dm_error(
1269 "DC: failed to create input pixel processor!\n");
1270 goto fail;
1271 }
1272
1273 pool->base.dpps[j] = dcn10_dpp_create(ctx, i);
1274 if (pool->base.dpps[j] == NULL) {
1275 BREAK_TO_DEBUGGER();
1276 dm_error(
1277 "DC: failed to create dpp!\n");
1278 goto fail;
1279 }
1280
1281 pool->base.opps[j] = dcn10_opp_create(ctx, i);
1282 if (pool->base.opps[j] == NULL) {
1283 BREAK_TO_DEBUGGER();
1284 dm_error(
1285 "DC: failed to create output pixel processor!\n");
1286 goto fail;
1287 }
1288
1289 pool->base.timing_generators[j] = dcn10_timing_generator_create(
1290 ctx, i);
1291 if (pool->base.timing_generators[j] == NULL) {
1292 BREAK_TO_DEBUGGER();
1293 dm_error("DC: failed to create tg!\n");
1294 goto fail;
1295 }
1296
1297 pool->base.engines[i] = dcn10_aux_engine_create(ctx, i);
1298 if (pool->base.engines[i] == NULL) {
1299 BREAK_TO_DEBUGGER();
1300 dm_error(
1301 "DC:failed to create aux engine!!\n");
1302 goto fail;
1303 }
1304
1305 /* check next valid pipe */
1306 j++;
1307 }
1308
1309 /* valid pipe num */
1310 pool->base.pipe_count = j;
1311 pool->base.timing_generator_count = j;
1312
1313 /* within dml lib, it is hard code to 4. If ASIC pipe is fused,
1314 * the value may be changed
1315 */
1316 dc->dml.ip.max_num_dpp = pool->base.pipe_count;
1317 dc->dcn_ip->max_num_dpp = pool->base.pipe_count;
1318
1319 pool->base.mpc = dcn10_mpc_create(ctx);
1320 if (pool->base.mpc == NULL) {
1321 BREAK_TO_DEBUGGER();
1322 dm_error("DC: failed to create mpc!\n");
1323 goto fail;
1324 }
1325
1326 pool->base.hubbub = dcn10_hubbub_create(ctx);
1327 if (pool->base.hubbub == NULL) {
1328 BREAK_TO_DEBUGGER();
1329 dm_error("DC: failed to create hubbub!\n");
1330 goto fail;
1331 }
1332
1333 if (!resource_construct(num_virtual_links, dc, &pool->base,
1334 (!IS_FPGA_MAXIMUS_DC(dc->ctx->dce_environment) ?
1335 &res_create_funcs : &res_create_maximus_funcs)))
1336 goto fail;
1337
1338 dcn10_hw_sequencer_construct(dc);
1339 dc->caps.max_planes = pool->base.pipe_count;
1340
1341 dc->cap_funcs = cap_funcs;
1342
1343 return true;
1344
1345 fail:
1346
1347 destruct(pool);
1348
1349 return false;
1350 }
1351
dcn10_create_resource_pool(uint8_t num_virtual_links,struct dc * dc)1352 struct resource_pool *dcn10_create_resource_pool(
1353 uint8_t num_virtual_links,
1354 struct dc *dc)
1355 {
1356 struct dcn10_resource_pool *pool =
1357 kzalloc(sizeof(struct dcn10_resource_pool), GFP_KERNEL);
1358
1359 if (!pool)
1360 return NULL;
1361
1362 if (construct(num_virtual_links, dc, pool))
1363 return &pool->base;
1364
1365 kfree(pool);
1366 BREAK_TO_DEBUGGER();
1367 return NULL;
1368 }
1369