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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
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
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
|
/*
* Copyright (c) 2015-2016 The Linux Foundation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
* only version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#define pr_fmt(fmt) "[drm:%s:%d] " fmt, __func__, __LINE__
#include <linux/debugfs.h>
#include "sde_encoder_phys.h"
#include "sde_formats.h"
#include "sde_hw_top.h"
#include "sde_hw_interrupts.h"
#include "sde_core_irq.h"
#include "sde_wb.h"
#include "sde_vbif.h"
#define to_sde_encoder_phys_wb(x) \
container_of(x, struct sde_encoder_phys_wb, base)
#define WBID(wb_enc) ((wb_enc) ? wb_enc->wb_dev->wb_idx : -1)
/**
* sde_encoder_phys_wb_is_master - report wb always as master encoder
*/
static bool sde_encoder_phys_wb_is_master(struct sde_encoder_phys *phys_enc)
{
return true;
}
/**
* sde_encoder_phys_wb_get_intr_type - get interrupt type based on block mode
* @hw_wb: Pointer to h/w writeback driver
*/
static enum sde_intr_type sde_encoder_phys_wb_get_intr_type(
struct sde_hw_wb *hw_wb)
{
return (hw_wb->caps->features & BIT(SDE_WB_BLOCK_MODE)) ?
SDE_IRQ_TYPE_WB_ROT_COMP : SDE_IRQ_TYPE_WB_WFD_COMP;
}
/**
* sde_encoder_phys_wb_set_ot_limit - set OT limit for writeback interface
* @phys_enc: Pointer to physical encoder
*/
static void sde_encoder_phys_wb_set_ot_limit(
struct sde_encoder_phys *phys_enc)
{
struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
struct sde_vbif_set_ot_params ot_params;
memset(&ot_params, 0, sizeof(ot_params));
ot_params.xin_id = hw_wb->caps->xin_id;
ot_params.num = hw_wb->idx - WB_0;
ot_params.width = wb_enc->wb_roi.w;
ot_params.height = wb_enc->wb_roi.h;
ot_params.is_wfd = true;
ot_params.frame_rate = phys_enc->cached_mode.vrefresh;
ot_params.vbif_idx = hw_wb->caps->vbif_idx;
ot_params.clk_ctrl = hw_wb->caps->clk_ctrl;
ot_params.rd = false;
sde_vbif_set_ot_limit(phys_enc->sde_kms, &ot_params);
}
/**
* sde_encoder_phys_wb_set_traffic_shaper - set traffic shaper for writeback
* @phys_enc: Pointer to physical encoder
*/
static void sde_encoder_phys_wb_set_traffic_shaper(
struct sde_encoder_phys *phys_enc)
{
struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
struct sde_hw_wb_cfg *wb_cfg = &wb_enc->wb_cfg;
/* traffic shaper is only enabled for rotator */
wb_cfg->ts_cfg.en = false;
}
/**
* sde_encoder_phys_setup_cdm - setup chroma down block
* @phys_enc: Pointer to physical encoder
* @fb: Pointer to output framebuffer
* @format: Output format
*/
void sde_encoder_phys_setup_cdm(struct sde_encoder_phys *phys_enc,
struct drm_framebuffer *fb, const struct sde_format *format,
struct sde_rect *wb_roi)
{
struct sde_hw_cdm *hw_cdm = phys_enc->hw_cdm;
struct sde_hw_cdm_cfg *cdm_cfg = &phys_enc->cdm_cfg;
int ret;
if (!SDE_FORMAT_IS_YUV(format)) {
SDE_DEBUG("[cdm_disable fmt:%x]\n",
format->base.pixel_format);
if (hw_cdm && hw_cdm->ops.disable)
hw_cdm->ops.disable(hw_cdm);
return;
}
memset(cdm_cfg, 0, sizeof(struct sde_hw_cdm_cfg));
cdm_cfg->output_width = wb_roi->w;
cdm_cfg->output_height = wb_roi->h;
cdm_cfg->output_fmt = format;
cdm_cfg->output_type = CDM_CDWN_OUTPUT_WB;
cdm_cfg->output_bit_depth = SDE_FORMAT_IS_DX(format) ?
CDM_CDWN_OUTPUT_10BIT : CDM_CDWN_OUTPUT_8BIT;
/* enable 10 bit logic */
switch (cdm_cfg->output_fmt->chroma_sample) {
case SDE_CHROMA_RGB:
cdm_cfg->h_cdwn_type = CDM_CDWN_DISABLE;
cdm_cfg->v_cdwn_type = CDM_CDWN_DISABLE;
break;
case SDE_CHROMA_H2V1:
cdm_cfg->h_cdwn_type = CDM_CDWN_COSITE;
cdm_cfg->v_cdwn_type = CDM_CDWN_DISABLE;
break;
case SDE_CHROMA_420:
cdm_cfg->h_cdwn_type = CDM_CDWN_COSITE;
cdm_cfg->v_cdwn_type = CDM_CDWN_OFFSITE;
break;
case SDE_CHROMA_H1V2:
default:
SDE_ERROR("unsupported chroma sampling type\n");
cdm_cfg->h_cdwn_type = CDM_CDWN_DISABLE;
cdm_cfg->v_cdwn_type = CDM_CDWN_DISABLE;
break;
}
SDE_DEBUG("[cdm_enable:%d,%d,%X,%d,%d,%d,%d]\n",
cdm_cfg->output_width,
cdm_cfg->output_height,
cdm_cfg->output_fmt->base.pixel_format,
cdm_cfg->output_type,
cdm_cfg->output_bit_depth,
cdm_cfg->h_cdwn_type,
cdm_cfg->v_cdwn_type);
if (hw_cdm && hw_cdm->ops.setup_cdwn) {
ret = hw_cdm->ops.setup_cdwn(hw_cdm, cdm_cfg);
if (ret < 0) {
SDE_ERROR("failed to setup CDM %d\n", ret);
return;
}
}
if (hw_cdm && hw_cdm->ops.enable) {
ret = hw_cdm->ops.enable(hw_cdm, cdm_cfg);
if (ret < 0) {
SDE_ERROR("failed to enable CDM %d\n", ret);
return;
}
}
}
/**
* sde_encoder_phys_wb_setup_fb - setup output framebuffer
* @phys_enc: Pointer to physical encoder
* @fb: Pointer to output framebuffer
* @wb_roi: Pointer to output region of interest
*/
static void sde_encoder_phys_wb_setup_fb(struct sde_encoder_phys *phys_enc,
struct drm_framebuffer *fb, struct sde_rect *wb_roi)
{
struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
struct sde_hw_wb *hw_wb;
struct sde_hw_wb_cfg *wb_cfg;
const struct msm_format *format;
int ret;
struct msm_gem_address_space *aspace;
if (!phys_enc) {
SDE_ERROR("invalid encoder\n");
return;
}
hw_wb = wb_enc->hw_wb;
wb_cfg = &wb_enc->wb_cfg;
memset(wb_cfg, 0, sizeof(struct sde_hw_wb_cfg));
wb_cfg->intf_mode = phys_enc->intf_mode;
wb_cfg->is_secure = (fb->flags & DRM_MODE_FB_SECURE) ? true : false;
aspace = (wb_cfg->is_secure) ?
wb_enc->aspace[SDE_IOMMU_DOMAIN_SECURE] :
wb_enc->aspace[SDE_IOMMU_DOMAIN_UNSECURE];
SDE_DEBUG("[fb_secure:%d]\n", wb_cfg->is_secure);
format = msm_framebuffer_format(fb);
if (!format) {
SDE_DEBUG("invalid format for fb\n");
return;
}
wb_cfg->dest.format = sde_get_sde_format_ext(
format->pixel_format,
fb->modifier,
drm_format_num_planes(fb->pixel_format));
if (!wb_cfg->dest.format) {
/* this error should be detected during atomic_check */
SDE_ERROR("failed to get format %x\n", format->pixel_format);
return;
}
wb_cfg->roi = *wb_roi;
if (hw_wb->caps->features & BIT(SDE_WB_XY_ROI_OFFSET)) {
ret = sde_format_populate_layout(aspace, fb, &wb_cfg->dest);
if (ret) {
SDE_DEBUG("failed to populate layout %d\n", ret);
return;
}
wb_cfg->dest.width = fb->width;
wb_cfg->dest.height = fb->height;
wb_cfg->dest.num_planes = wb_cfg->dest.format->num_planes;
} else {
ret = sde_format_populate_layout_with_roi(aspace, fb, wb_roi,
&wb_cfg->dest);
if (ret) {
/* this error should be detected during atomic_check */
SDE_DEBUG("failed to populate layout %d\n", ret);
return;
}
}
if ((wb_cfg->dest.format->fetch_planes == SDE_PLANE_PLANAR) &&
(wb_cfg->dest.format->element[0] == C1_B_Cb))
swap(wb_cfg->dest.plane_addr[1], wb_cfg->dest.plane_addr[2]);
SDE_DEBUG("[fb_offset:%8.8x,%8.8x,%8.8x,%8.8x]\n",
wb_cfg->dest.plane_addr[0],
wb_cfg->dest.plane_addr[1],
wb_cfg->dest.plane_addr[2],
wb_cfg->dest.plane_addr[3]);
SDE_DEBUG("[fb_stride:%8.8x,%8.8x,%8.8x,%8.8x]\n",
wb_cfg->dest.plane_pitch[0],
wb_cfg->dest.plane_pitch[1],
wb_cfg->dest.plane_pitch[2],
wb_cfg->dest.plane_pitch[3]);
if (hw_wb->ops.setup_roi)
hw_wb->ops.setup_roi(hw_wb, wb_cfg);
if (hw_wb->ops.setup_outformat)
hw_wb->ops.setup_outformat(hw_wb, wb_cfg);
if (hw_wb->ops.setup_outaddress)
hw_wb->ops.setup_outaddress(hw_wb, wb_cfg);
}
/**
* sde_encoder_phys_wb_setup_cdp - setup chroma down prefetch block
* @phys_enc: Pointer to physical encoder
*/
static void sde_encoder_phys_wb_setup_cdp(struct sde_encoder_phys *phys_enc)
{
struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
struct sde_hw_intf_cfg *intf_cfg = &wb_enc->intf_cfg;
memset(intf_cfg, 0, sizeof(struct sde_hw_intf_cfg));
intf_cfg->intf = SDE_NONE;
intf_cfg->wb = hw_wb->idx;
intf_cfg->mode_3d = sde_encoder_helper_get_3d_blend_mode(phys_enc);
if (phys_enc->hw_ctl && phys_enc->hw_ctl->ops.setup_intf_cfg)
phys_enc->hw_ctl->ops.setup_intf_cfg(phys_enc->hw_ctl,
intf_cfg);
}
/**
* sde_encoder_phys_wb_atomic_check - verify and fixup given atomic states
* @phys_enc: Pointer to physical encoder
* @crtc_state: Pointer to CRTC atomic state
* @conn_state: Pointer to connector atomic state
*/
static int sde_encoder_phys_wb_atomic_check(
struct sde_encoder_phys *phys_enc,
struct drm_crtc_state *crtc_state,
struct drm_connector_state *conn_state)
{
struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
const struct sde_wb_cfg *wb_cfg = hw_wb->caps;
struct drm_framebuffer *fb;
const struct sde_format *fmt;
struct sde_rect wb_roi;
const struct drm_display_mode *mode = &crtc_state->mode;
int rc;
SDE_DEBUG("[atomic_check:%d,%d,\"%s\",%d,%d]\n",
hw_wb->idx - WB_0, mode->base.id, mode->name,
mode->hdisplay, mode->vdisplay);
if (!conn_state || !conn_state->connector) {
SDE_ERROR("invalid connector state\n");
return -EINVAL;
} else if (conn_state->connector->status !=
connector_status_connected) {
SDE_ERROR("connector not connected %d\n",
conn_state->connector->status);
return -EINVAL;
}
memset(&wb_roi, 0, sizeof(struct sde_rect));
rc = sde_wb_connector_state_get_output_roi(conn_state, &wb_roi);
if (rc) {
SDE_ERROR("failed to get roi %d\n", rc);
return rc;
}
SDE_DEBUG("[roi:%u,%u,%u,%u]\n", wb_roi.x, wb_roi.y,
wb_roi.w, wb_roi.h);
fb = sde_wb_connector_state_get_output_fb(conn_state);
if (!fb) {
SDE_ERROR("no output framebuffer\n");
return -EINVAL;
}
SDE_DEBUG("[fb_id:%u][fb:%u,%u]\n", fb->base.id,
fb->width, fb->height);
fmt = sde_get_sde_format_ext(fb->pixel_format, fb->modifier,
drm_format_num_planes(fb->pixel_format));
if (!fmt) {
SDE_ERROR("unsupported output pixel format:%x\n",
fb->pixel_format);
return -EINVAL;
}
SDE_DEBUG("[fb_fmt:%x,%llx]\n", fb->pixel_format,
fb->modifier[0]);
if (SDE_FORMAT_IS_YUV(fmt) &&
!(wb_cfg->features & BIT(SDE_WB_YUV_CONFIG))) {
SDE_ERROR("invalid output format %x\n", fmt->base.pixel_format);
return -EINVAL;
}
if (SDE_FORMAT_IS_UBWC(fmt) &&
!(wb_cfg->features & BIT(SDE_WB_UBWC_1_0))) {
SDE_ERROR("invalid output format %x\n", fmt->base.pixel_format);
return -EINVAL;
}
if (SDE_FORMAT_IS_YUV(fmt) != !!phys_enc->hw_cdm)
crtc_state->mode_changed = true;
if (wb_roi.w && wb_roi.h) {
if (wb_roi.w != mode->hdisplay) {
SDE_ERROR("invalid roi w=%d, mode w=%d\n", wb_roi.w,
mode->hdisplay);
return -EINVAL;
} else if (wb_roi.h != mode->vdisplay) {
SDE_ERROR("invalid roi h=%d, mode h=%d\n", wb_roi.h,
mode->vdisplay);
return -EINVAL;
} else if (wb_roi.x + wb_roi.w > fb->width) {
SDE_ERROR("invalid roi x=%d, w=%d, fb w=%d\n",
wb_roi.x, wb_roi.w, fb->width);
return -EINVAL;
} else if (wb_roi.y + wb_roi.h > fb->height) {
SDE_ERROR("invalid roi y=%d, h=%d, fb h=%d\n",
wb_roi.y, wb_roi.h, fb->height);
return -EINVAL;
} else if (wb_roi.w > wb_cfg->sblk->maxlinewidth) {
SDE_ERROR("invalid roi w=%d, maxlinewidth=%u\n",
wb_roi.w, wb_cfg->sblk->maxlinewidth);
return -EINVAL;
}
} else {
if (wb_roi.x || wb_roi.y) {
SDE_ERROR("invalid roi x=%d, y=%d\n",
wb_roi.x, wb_roi.y);
return -EINVAL;
} else if (fb->width != mode->hdisplay) {
SDE_ERROR("invalid fb w=%d, mode w=%d\n", fb->width,
mode->hdisplay);
return -EINVAL;
} else if (fb->height != mode->vdisplay) {
SDE_ERROR("invalid fb h=%d, mode h=%d\n", fb->height,
mode->vdisplay);
return -EINVAL;
} else if (fb->width > wb_cfg->sblk->maxlinewidth) {
SDE_ERROR("invalid fb w=%d, maxlinewidth=%u\n",
fb->width, wb_cfg->sblk->maxlinewidth);
return -EINVAL;
}
}
return 0;
}
/**
* sde_encoder_phys_wb_flush - flush hardware update
* @phys_enc: Pointer to physical encoder
*/
static void sde_encoder_phys_wb_flush(struct sde_encoder_phys *phys_enc)
{
struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
struct sde_hw_ctl *hw_ctl = phys_enc->hw_ctl;
struct sde_hw_cdm *hw_cdm = phys_enc->hw_cdm;
u32 flush_mask = 0;
SDE_DEBUG("[wb:%d]\n", hw_wb->idx - WB_0);
if (!hw_ctl) {
SDE_DEBUG("[wb:%d] no ctl assigned\n", hw_wb->idx - WB_0);
return;
}
if (hw_ctl->ops.get_bitmask_wb)
hw_ctl->ops.get_bitmask_wb(hw_ctl, &flush_mask, hw_wb->idx);
if (hw_ctl->ops.get_bitmask_cdm && hw_cdm)
hw_ctl->ops.get_bitmask_cdm(hw_ctl, &flush_mask, hw_cdm->idx);
if (hw_ctl->ops.update_pending_flush)
hw_ctl->ops.update_pending_flush(hw_ctl, flush_mask);
SDE_DEBUG("Flushing CTL_ID %d, flush_mask %x, WB %d\n",
hw_ctl->idx - CTL_0, flush_mask, hw_wb->idx - WB_0);
}
/**
* sde_encoder_phys_wb_setup - setup writeback encoder
* @phys_enc: Pointer to physical encoder
*/
static void sde_encoder_phys_wb_setup(
struct sde_encoder_phys *phys_enc)
{
struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
struct drm_display_mode mode = phys_enc->cached_mode;
struct drm_framebuffer *fb;
struct sde_rect *wb_roi = &wb_enc->wb_roi;
SDE_DEBUG("[mode_set:%d,%d,\"%s\",%d,%d]\n",
hw_wb->idx - WB_0, mode.base.id, mode.name,
mode.hdisplay, mode.vdisplay);
memset(wb_roi, 0, sizeof(struct sde_rect));
fb = sde_wb_get_output_fb(wb_enc->wb_dev);
if (!fb) {
SDE_DEBUG("no output framebuffer\n");
return;
}
SDE_DEBUG("[fb_id:%u][fb:%u,%u]\n", fb->base.id,
fb->width, fb->height);
sde_wb_get_output_roi(wb_enc->wb_dev, wb_roi);
if (wb_roi->w == 0 || wb_roi->h == 0) {
wb_roi->x = 0;
wb_roi->y = 0;
wb_roi->w = fb->width;
wb_roi->h = fb->height;
}
SDE_DEBUG("[roi:%u,%u,%u,%u]\n", wb_roi->x, wb_roi->y,
wb_roi->w, wb_roi->h);
wb_enc->wb_fmt = sde_get_sde_format_ext(fb->pixel_format, fb->modifier,
drm_format_num_planes(fb->pixel_format));
if (!wb_enc->wb_fmt) {
SDE_ERROR("unsupported output pixel format: %d\n",
fb->pixel_format);
return;
}
SDE_DEBUG("[fb_fmt:%x,%llx]\n", fb->pixel_format,
fb->modifier[0]);
sde_encoder_phys_wb_set_ot_limit(phys_enc);
sde_encoder_phys_wb_set_traffic_shaper(phys_enc);
sde_encoder_phys_setup_cdm(phys_enc, fb, wb_enc->wb_fmt, wb_roi);
sde_encoder_phys_wb_setup_fb(phys_enc, fb, wb_roi);
sde_encoder_phys_wb_setup_cdp(phys_enc);
}
/**
* sde_encoder_phys_wb_unregister_irq - unregister writeback interrupt handler
* @phys_enc: Pointer to physical encoder
*/
static int sde_encoder_phys_wb_unregister_irq(
struct sde_encoder_phys *phys_enc)
{
struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
if (wb_enc->bypass_irqreg)
return 0;
sde_core_irq_disable(phys_enc->sde_kms, &wb_enc->irq_idx, 1);
sde_core_irq_unregister_callback(phys_enc->sde_kms, wb_enc->irq_idx,
&wb_enc->irq_cb);
SDE_DEBUG("un-register IRQ for wb %d, irq_idx=%d\n",
hw_wb->idx - WB_0,
wb_enc->irq_idx);
return 0;
}
/**
* sde_encoder_phys_wb_done_irq - writeback interrupt handler
* @arg: Pointer to writeback encoder
* @irq_idx: interrupt index
*/
static void sde_encoder_phys_wb_done_irq(void *arg, int irq_idx)
{
struct sde_encoder_phys_wb *wb_enc = arg;
struct sde_encoder_phys *phys_enc = &wb_enc->base;
struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
SDE_DEBUG("[wb:%d,%u]\n", hw_wb->idx - WB_0,
wb_enc->frame_count);
if (phys_enc->parent_ops.handle_frame_done)
phys_enc->parent_ops.handle_frame_done(phys_enc->parent,
phys_enc, SDE_ENCODER_FRAME_EVENT_DONE);
phys_enc->parent_ops.handle_vblank_virt(phys_enc->parent,
phys_enc);
complete_all(&wb_enc->wbdone_complete);
}
/**
* sde_encoder_phys_wb_register_irq - register writeback interrupt handler
* @phys_enc: Pointer to physical encoder
*/
static int sde_encoder_phys_wb_register_irq(struct sde_encoder_phys *phys_enc)
{
struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
struct sde_irq_callback *irq_cb = &wb_enc->irq_cb;
enum sde_intr_type intr_type;
int ret = 0;
if (wb_enc->bypass_irqreg)
return 0;
intr_type = sde_encoder_phys_wb_get_intr_type(hw_wb);
wb_enc->irq_idx = sde_core_irq_idx_lookup(phys_enc->sde_kms,
intr_type, hw_wb->idx);
if (wb_enc->irq_idx < 0) {
SDE_ERROR(
"failed to lookup IRQ index for WB_DONE with wb=%d\n",
hw_wb->idx - WB_0);
return -EINVAL;
}
irq_cb->func = sde_encoder_phys_wb_done_irq;
irq_cb->arg = wb_enc;
ret = sde_core_irq_register_callback(phys_enc->sde_kms,
wb_enc->irq_idx, irq_cb);
if (ret) {
SDE_ERROR("failed to register IRQ callback WB_DONE\n");
return ret;
}
ret = sde_core_irq_enable(phys_enc->sde_kms, &wb_enc->irq_idx, 1);
if (ret) {
SDE_ERROR(
"failed to enable IRQ for WB_DONE, wb %d, irq_idx=%d\n",
hw_wb->idx - WB_0,
wb_enc->irq_idx);
wb_enc->irq_idx = -EINVAL;
/* Unregister callback on IRQ enable failure */
sde_core_irq_unregister_callback(phys_enc->sde_kms,
wb_enc->irq_idx, irq_cb);
return ret;
}
SDE_DEBUG("registered IRQ for wb %d, irq_idx=%d\n",
hw_wb->idx - WB_0,
wb_enc->irq_idx);
return ret;
}
/**
* sde_encoder_phys_wb_mode_set - set display mode
* @phys_enc: Pointer to physical encoder
* @mode: Pointer to requested display mode
* @adj_mode: Pointer to adjusted display mode
*/
static void sde_encoder_phys_wb_mode_set(
struct sde_encoder_phys *phys_enc,
struct drm_display_mode *mode,
struct drm_display_mode *adj_mode)
{
struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
struct sde_rm *rm = &phys_enc->sde_kms->rm;
struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
struct sde_rm_hw_iter iter;
int i, instance;
phys_enc->cached_mode = *adj_mode;
instance = phys_enc->split_role == ENC_ROLE_SLAVE ? 1 : 0;
SDE_DEBUG("[mode_set_cache:%d,%d,\"%s\",%d,%d]\n",
hw_wb->idx - WB_0, mode->base.id,
mode->name, mode->hdisplay, mode->vdisplay);
phys_enc->hw_ctl = NULL;
phys_enc->hw_cdm = NULL;
/* Retrieve previously allocated HW Resources. CTL shouldn't fail */
sde_rm_init_hw_iter(&iter, phys_enc->parent->base.id, SDE_HW_BLK_CTL);
for (i = 0; i <= instance; i++) {
sde_rm_get_hw(rm, &iter);
if (i == instance)
phys_enc->hw_ctl = (struct sde_hw_ctl *) iter.hw;
}
if (IS_ERR_OR_NULL(phys_enc->hw_ctl)) {
SDE_ERROR("failed init ctl: %ld\n", PTR_ERR(phys_enc->hw_ctl));
phys_enc->hw_ctl = NULL;
return;
}
/* CDM is optional */
sde_rm_init_hw_iter(&iter, phys_enc->parent->base.id, SDE_HW_BLK_CDM);
for (i = 0; i <= instance; i++) {
sde_rm_get_hw(rm, &iter);
if (i == instance)
phys_enc->hw_cdm = (struct sde_hw_cdm *) iter.hw;
}
if (IS_ERR(phys_enc->hw_cdm)) {
SDE_ERROR("CDM required but not allocated: %ld\n",
PTR_ERR(phys_enc->hw_cdm));
phys_enc->hw_ctl = NULL;
}
}
/**
* sde_encoder_phys_wb_wait_for_commit_done - wait until request is committed
* @phys_enc: Pointer to physical encoder
*/
static int sde_encoder_phys_wb_wait_for_commit_done(
struct sde_encoder_phys *phys_enc)
{
unsigned long ret;
struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
u32 irq_status;
u64 wb_time = 0;
int rc = 0;
/* Return EWOULDBLOCK since we know the wait isn't necessary */
if (WARN_ON(phys_enc->enable_state != SDE_ENC_ENABLED))
return -EWOULDBLOCK;
SDE_EVT32(DRMID(phys_enc->parent), WBID(wb_enc), wb_enc->frame_count);
ret = wait_for_completion_timeout(&wb_enc->wbdone_complete,
KICKOFF_TIMEOUT_JIFFIES);
if (!ret) {
SDE_EVT32(DRMID(phys_enc->parent), WBID(wb_enc),
wb_enc->frame_count);
irq_status = sde_core_irq_read(phys_enc->sde_kms,
wb_enc->irq_idx, true);
if (irq_status) {
SDE_DEBUG("wb:%d done but irq not triggered\n",
wb_enc->wb_dev->wb_idx - WB_0);
sde_encoder_phys_wb_done_irq(wb_enc, wb_enc->irq_idx);
} else {
SDE_ERROR("wb:%d kickoff timed out\n",
wb_enc->wb_dev->wb_idx - WB_0);
if (phys_enc->parent_ops.handle_frame_done)
phys_enc->parent_ops.handle_frame_done(
phys_enc->parent, phys_enc,
SDE_ENCODER_FRAME_EVENT_ERROR);
rc = -ETIMEDOUT;
}
}
sde_encoder_phys_wb_unregister_irq(phys_enc);
if (!rc)
wb_enc->end_time = ktime_get();
/* once operation is done, disable traffic shaper */
if (wb_enc->wb_cfg.ts_cfg.en && wb_enc->hw_wb &&
wb_enc->hw_wb->ops.setup_trafficshaper) {
wb_enc->wb_cfg.ts_cfg.en = false;
wb_enc->hw_wb->ops.setup_trafficshaper(
wb_enc->hw_wb, &wb_enc->wb_cfg);
}
/* remove vote for iommu/clk/bus */
wb_enc->frame_count++;
if (!rc) {
wb_time = (u64)ktime_to_us(wb_enc->end_time) -
(u64)ktime_to_us(wb_enc->start_time);
SDE_DEBUG("wb:%d took %llu us\n",
wb_enc->wb_dev->wb_idx - WB_0, wb_time);
}
SDE_EVT32(DRMID(phys_enc->parent), WBID(wb_enc), wb_enc->frame_count,
wb_time);
return rc;
}
/**
* sde_encoder_phys_wb_prepare_for_kickoff - pre-kickoff processing
* @phys_enc: Pointer to physical encoder
*/
static void sde_encoder_phys_wb_prepare_for_kickoff(
struct sde_encoder_phys *phys_enc)
{
struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
int ret;
SDE_DEBUG("[wb:%d,%u]\n", wb_enc->hw_wb->idx - WB_0,
wb_enc->kickoff_count);
reinit_completion(&wb_enc->wbdone_complete);
ret = sde_encoder_phys_wb_register_irq(phys_enc);
if (ret) {
SDE_ERROR("failed to register irq %d\n", ret);
return;
}
wb_enc->kickoff_count++;
/* set OT limit & enable traffic shaper */
sde_encoder_phys_wb_setup(phys_enc);
sde_encoder_phys_wb_flush(phys_enc);
/* vote for iommu/clk/bus */
wb_enc->start_time = ktime_get();
SDE_EVT32(DRMID(phys_enc->parent), WBID(wb_enc), wb_enc->kickoff_count);
}
/**
* sde_encoder_phys_wb_handle_post_kickoff - post-kickoff processing
* @phys_enc: Pointer to physical encoder
*/
static void sde_encoder_phys_wb_handle_post_kickoff(
struct sde_encoder_phys *phys_enc)
{
struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
SDE_DEBUG("[wb:%d]\n", wb_enc->hw_wb->idx - WB_0);
SDE_EVT32(DRMID(phys_enc->parent), WBID(wb_enc));
}
/**
* sde_encoder_phys_wb_enable - enable writeback encoder
* @phys_enc: Pointer to physical encoder
*/
static void sde_encoder_phys_wb_enable(struct sde_encoder_phys *phys_enc)
{
struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
struct drm_device *dev;
struct drm_connector *connector;
SDE_DEBUG("[wb:%d]\n", hw_wb->idx - WB_0);
if (!wb_enc->base.parent || !wb_enc->base.parent->dev) {
SDE_ERROR("invalid drm device\n");
return;
}
dev = wb_enc->base.parent->dev;
/* find associated writeback connector */
mutex_lock(&dev->mode_config.mutex);
drm_for_each_connector(connector, phys_enc->parent->dev) {
if (connector->encoder == phys_enc->parent)
break;
}
mutex_unlock(&dev->mode_config.mutex);
if (!connector || connector->encoder != phys_enc->parent) {
SDE_ERROR("failed to find writeback connector\n");
return;
}
wb_enc->wb_dev = sde_wb_connector_get_wb(connector);
phys_enc->enable_state = SDE_ENC_ENABLED;
}
/**
* sde_encoder_phys_wb_disable - disable writeback encoder
* @phys_enc: Pointer to physical encoder
*/
static void sde_encoder_phys_wb_disable(struct sde_encoder_phys *phys_enc)
{
struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
SDE_DEBUG("[wb:%d]\n", hw_wb->idx - WB_0);
if (phys_enc->enable_state == SDE_ENC_DISABLED) {
SDE_ERROR("encoder is already disabled\n");
return;
}
if (wb_enc->frame_count != wb_enc->kickoff_count) {
SDE_DEBUG("[wait_for_done: wb:%d, frame:%u, kickoff:%u]\n",
hw_wb->idx - WB_0, wb_enc->frame_count,
wb_enc->kickoff_count);
sde_encoder_phys_wb_wait_for_commit_done(phys_enc);
}
if (phys_enc->hw_cdm && phys_enc->hw_cdm->ops.disable) {
SDE_DEBUG_DRIVER("[cdm_disable]\n");
phys_enc->hw_cdm->ops.disable(phys_enc->hw_cdm);
}
phys_enc->enable_state = SDE_ENC_DISABLED;
}
/**
* sde_encoder_phys_wb_get_hw_resources - get hardware resources
* @phys_enc: Pointer to physical encoder
* @hw_res: Pointer to encoder resources
*/
static void sde_encoder_phys_wb_get_hw_resources(
struct sde_encoder_phys *phys_enc,
struct sde_encoder_hw_resources *hw_res,
struct drm_connector_state *conn_state)
{
struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
struct sde_hw_wb *hw_wb;
struct drm_framebuffer *fb;
const struct sde_format *fmt;
if (!phys_enc) {
SDE_ERROR("invalid encoder\n");
return;
}
fb = sde_wb_connector_state_get_output_fb(conn_state);
if (!fb) {
SDE_ERROR("no output framebuffer\n");
return;
}
fmt = sde_get_sde_format_ext(fb->pixel_format, fb->modifier,
drm_format_num_planes(fb->pixel_format));
if (!fmt) {
SDE_ERROR("unsupported output pixel format:%d\n",
fb->pixel_format);
return;
}
hw_wb = wb_enc->hw_wb;
hw_res->wbs[hw_wb->idx - WB_0] = phys_enc->intf_mode;
hw_res->needs_cdm = SDE_FORMAT_IS_YUV(fmt);
SDE_DEBUG("[wb:%d] intf_mode=%d needs_cdm=%d\n", hw_wb->idx - WB_0,
hw_res->wbs[hw_wb->idx - WB_0],
hw_res->needs_cdm);
}
#ifdef CONFIG_DEBUG_FS
/**
* sde_encoder_phys_wb_init_debugfs - initialize writeback encoder debugfs
* @phys_enc: Pointer to physical encoder
* @sde_kms: Pointer to SDE KMS object
*/
static int sde_encoder_phys_wb_init_debugfs(
struct sde_encoder_phys *phys_enc, struct sde_kms *kms)
{
struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
if (!phys_enc || !kms || !wb_enc->hw_wb)
return -EINVAL;
snprintf(wb_enc->wb_name, ARRAY_SIZE(wb_enc->wb_name), "encoder_wb%d",
wb_enc->hw_wb->idx - WB_0);
wb_enc->debugfs_root =
debugfs_create_dir(wb_enc->wb_name,
sde_debugfs_get_root(kms));
if (!wb_enc->debugfs_root) {
SDE_ERROR("failed to create debugfs\n");
return -ENOMEM;
}
if (!debugfs_create_u32("wbdone_timeout", S_IRUGO | S_IWUSR,
wb_enc->debugfs_root, &wb_enc->wbdone_timeout)) {
SDE_ERROR("failed to create debugfs/wbdone_timeout\n");
return -ENOMEM;
}
if (!debugfs_create_u32("bypass_irqreg", S_IRUGO | S_IWUSR,
wb_enc->debugfs_root, &wb_enc->bypass_irqreg)) {
SDE_ERROR("failed to create debugfs/bypass_irqreg\n");
return -ENOMEM;
}
return 0;
}
/**
* sde_encoder_phys_wb_destroy_debugfs - destroy writeback encoder debugfs
* @phys_enc: Pointer to physical encoder
*/
static void sde_encoder_phys_wb_destroy_debugfs(
struct sde_encoder_phys *phys_enc)
{
struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
if (!phys_enc)
return;
debugfs_remove_recursive(wb_enc->debugfs_root);
}
#else
static int sde_encoder_phys_wb_init_debugfs(
struct sde_encoder_phys *phys_enc, struct sde_kms *kms)
{
return 0;
}
static void sde_encoder_phys_wb_destroy_debugfs(
struct sde_encoder_phys *phys_enc)
{
}
#endif
/**
* sde_encoder_phys_wb_destroy - destroy writeback encoder
* @phys_enc: Pointer to physical encoder
*/
static void sde_encoder_phys_wb_destroy(struct sde_encoder_phys *phys_enc)
{
struct sde_encoder_phys_wb *wb_enc = to_sde_encoder_phys_wb(phys_enc);
struct sde_hw_wb *hw_wb = wb_enc->hw_wb;
SDE_DEBUG("[wb:%d]\n", hw_wb->idx - WB_0);
if (!phys_enc)
return;
sde_encoder_phys_wb_destroy_debugfs(phys_enc);
kfree(wb_enc);
}
/**
* sde_encoder_phys_wb_init_ops - initialize writeback operations
* @ops: Pointer to encoder operation table
*/
static void sde_encoder_phys_wb_init_ops(struct sde_encoder_phys_ops *ops)
{
ops->is_master = sde_encoder_phys_wb_is_master;
ops->mode_set = sde_encoder_phys_wb_mode_set;
ops->enable = sde_encoder_phys_wb_enable;
ops->disable = sde_encoder_phys_wb_disable;
ops->destroy = sde_encoder_phys_wb_destroy;
ops->atomic_check = sde_encoder_phys_wb_atomic_check;
ops->get_hw_resources = sde_encoder_phys_wb_get_hw_resources;
ops->wait_for_commit_done = sde_encoder_phys_wb_wait_for_commit_done;
ops->prepare_for_kickoff = sde_encoder_phys_wb_prepare_for_kickoff;
ops->handle_post_kickoff = sde_encoder_phys_wb_handle_post_kickoff;
ops->trigger_start = sde_encoder_helper_trigger_start;
}
/**
* sde_encoder_phys_wb_init - initialize writeback encoder
* @init: Pointer to init info structure with initialization params
*/
struct sde_encoder_phys *sde_encoder_phys_wb_init(
struct sde_enc_phys_init_params *p)
{
struct sde_encoder_phys *phys_enc;
struct sde_encoder_phys_wb *wb_enc;
struct sde_hw_mdp *hw_mdp;
int ret = 0;
SDE_DEBUG("\n");
wb_enc = kzalloc(sizeof(*wb_enc), GFP_KERNEL);
if (!wb_enc) {
ret = -ENOMEM;
goto fail_alloc;
}
wb_enc->irq_idx = -EINVAL;
wb_enc->wbdone_timeout = KICKOFF_TIMEOUT_MS;
init_completion(&wb_enc->wbdone_complete);
phys_enc = &wb_enc->base;
if (p->sde_kms->vbif[VBIF_NRT]) {
wb_enc->aspace[SDE_IOMMU_DOMAIN_UNSECURE] =
p->sde_kms->aspace[MSM_SMMU_DOMAIN_NRT_UNSECURE];
wb_enc->aspace[SDE_IOMMU_DOMAIN_SECURE] =
p->sde_kms->aspace[MSM_SMMU_DOMAIN_NRT_SECURE];
} else {
wb_enc->aspace[SDE_IOMMU_DOMAIN_UNSECURE] =
p->sde_kms->aspace[MSM_SMMU_DOMAIN_UNSECURE];
wb_enc->aspace[SDE_IOMMU_DOMAIN_SECURE] =
p->sde_kms->aspace[MSM_SMMU_DOMAIN_SECURE];
}
hw_mdp = sde_rm_get_mdp(&p->sde_kms->rm);
if (IS_ERR_OR_NULL(hw_mdp)) {
ret = PTR_ERR(hw_mdp);
SDE_ERROR("failed to init hw_top: %d\n", ret);
goto fail_mdp_init;
}
phys_enc->hw_mdptop = hw_mdp;
/**
* hw_wb resource permanently assigned to this encoder
* Other resources allocated at atomic commit time by use case
*/
if (p->wb_idx != SDE_NONE) {
struct sde_rm_hw_iter iter;
sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_WB);
while (sde_rm_get_hw(&p->sde_kms->rm, &iter)) {
struct sde_hw_wb *hw_wb = (struct sde_hw_wb *)iter.hw;
if (hw_wb->idx == p->wb_idx) {
wb_enc->hw_wb = hw_wb;
break;
}
}
if (!wb_enc->hw_wb) {
ret = -EINVAL;
SDE_ERROR("failed to init hw_wb%d\n", p->wb_idx - WB_0);
goto fail_wb_init;
}
} else {
ret = -EINVAL;
SDE_ERROR("invalid wb_idx\n");
goto fail_wb_check;
}
sde_encoder_phys_wb_init_ops(&phys_enc->ops);
phys_enc->parent = p->parent;
phys_enc->parent_ops = p->parent_ops;
phys_enc->sde_kms = p->sde_kms;
phys_enc->split_role = p->split_role;
phys_enc->intf_mode = INTF_MODE_WB_LINE;
phys_enc->intf_idx = p->intf_idx;
phys_enc->enc_spinlock = p->enc_spinlock;
INIT_LIST_HEAD(&wb_enc->irq_cb.list);
ret = sde_encoder_phys_wb_init_debugfs(phys_enc, p->sde_kms);
if (ret) {
SDE_ERROR("failed to init debugfs %d\n", ret);
goto fail_debugfs_init;
}
SDE_DEBUG("Created sde_encoder_phys_wb for wb %d\n",
wb_enc->hw_wb->idx - WB_0);
return phys_enc;
fail_debugfs_init:
fail_wb_init:
fail_wb_check:
fail_mdp_init:
kfree(wb_enc);
fail_alloc:
return ERR_PTR(ret);
}
|