aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv6/reassembly.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/ipv6/reassembly.c')
0 files changed, 0 insertions, 0 deletions
pan>
15e7791b6








7ee8d2379
15e7791b6
7ee8d2379
15e7791b6




58e1ef3e1
ecba97acb
15e7791b6


ecba97acb
15e7791b6
















ecba97acb
3e9a54fbf
15e7791b6


ecba97acb
15e7791b6










ecba97acb
3e9a54fbf
15e7791b6

a6b5caf69
15e7791b6

ecba97acb
15e7791b6

a6b5caf69









































15e7791b6

ecba97acb

15e7791b6
ecba97acb

15e7791b6
7ee8d2379
15e7791b6
ecba97acb
15e7791b6




ecba97acb






7ee8d2379
ecba97acb




2f4a5483e

ecba97acb
7ee8d2379
1df65fce9
372c169d6
ecba97acb

372c169d6
ecba97acb

372c169d6
1c6f209e7







ecba97acb
5e05312a2
ecba97acb


1c6f209e7
ecba97acb








7c1eb45a1






ecba97acb


372c169d6
1c6f209e7







ecba97acb
5e05312a2
ecba97acb


1c6f209e7
ecba97acb


22f2dc0da
ecba97acb




7c1eb45a1






ecba97acb



1c6f209e7





ecba97acb


1c6f209e7
ecba97acb
15e7791b6
7ee8d2379
15e7791b6
58e1ef3e1
15e7791b6



b5ecc6ac8
5f7468c7c

8338162c4


1df65fce9
15e7791b6

5f7468c7c
15e7791b6

5f7468c7c
b5ecc6ac8
e1b40cb9a
1dcf1b46c




e1b40cb9a

1dcf1b46c
e1b40cb9a



b5ecc6ac8
174e63e29
5f7468c7c


15e7791b6


















































a31ac7cc6

f5cd200f7




3e9a54fbf
f5cd200f7



98d9d1ac0



5d2e3f2f0
98d9d1ac0













f5cd200f7

21fe774e5
f5cd200f7
21fe774e5
f5cd200f7

98d9d1ac0



















f5cd200f7






98d9d1ac0













f5cd200f7

f41d52ffc







ca0f068f2











f41d52ffc


ca0f068f2
f41d52ffc
ca0f068f2
58e1ef3e1



























































ca0f068f2
0a7a7484f
0447ae81d



f870d253a
3e9a54fbf
0447ae81d





0447ae81d
3e9a54fbf
0447ae81d








f870d253a
3e9a54fbf
0447ae81d

33eb6f286



3e9a54fbf
8442769e5













115d6b926
0447ae81d


59838cdfe





ab2eb7357
15e7791b6
15e7791b6
b6c8d7446
f5cd200f7
ecba97acb

15e7791b6
66fbe8b07




72dc26043
15e7791b6
66fbe8b07















ca0f068f2




3e9a54fbf
ca0f068f2







66fbe8b07
847eadae7
15e7791b6
46a594331
f5cd200f7
15e7791b6




5a127a995
15e7791b6

5a127a995
372c169d6

f5cd200f7


15e7791b6
15e7791b6






93f2d94c5
46a594331
15e7791b6
2ff2d89ec

45bc29c75

2ff2d89ec



e29f1f1cc
2ff2d89ec



15e7791b6
93f2d94c5
15e7791b6

372c169d6















b6c8d7446









3c01a69d9
1843545da
3c01a69d9

3c01a69d9












72dc26043
2f34966e8
9a35f0b3c
72dc26043

2f34966e8



4506f0625



3c01a69d9


86a8ec5c5



15e7791b6
3c01a69d9
58e1ef3e1


66fbe8b07
15e7791b6


98d9d1ac0


98d9d1ac0



98d9d1ac0




15e7791b6
f5cd200f7
48a55cdc4
f5cd200f7
48a55cdc4


f5cd200f7




15e7791b6
8229523b8
15e7791b6
8229523b8

5a127a995
15e7791b6
5a127a995
8229523b8
15e7791b6
8229523b8


15e7791b6
8229523b8

15e7791b6



5a127a995
8229523b8
497034ae3
8229523b8
a2fcc55a1
5a127a995



15e7791b6

15e7791b6
d8e5a40e3




15e7791b6


98d9d1ac0
15e7791b6
15e7791b6
d8e5a40e3
15e7791b6



98d9d1ac0





f389f64fb


497034ae3
98d9d1ac0
8229523b8
98d9d1ac0
8229523b8

98d9d1ac0
8229523b8
98d9d1ac0
8229523b8

98d9d1ac0
8229523b8
98d9d1ac0
8229523b8

98d9d1ac0














15e7791b6











5a127a995



















15e7791b6
5a127a995
15e7791b6
f5cd200f7
15e7791b6
f5cd200f7
15e7791b6
4b354cded







5e05312a2



5e05312a2







138f22f9e
d52a44df5











138f22f9e
d52a44df5
47517cf39
15e7791b6
f5cd200f7
15e7791b6
f5cd200f7

98d9d1ac0





a9d23a337




503f1ec30


f5cd200f7
15e7791b6
b6c8d7446
15e7791b6
a9c2e64c2
15e7791b6

ecba97acb




1c6f209e7
1df65fce9

a6c7c51cb
3e9a54fbf
a6c7c51cb
15e7791b6



26292ddeb
15e7791b6
dc6bc741b
e4546cf23



59838cdfe
15e7791b6

8eaad7b98


ee4902c25
b6c8d7446




15e7791b6

75e21e5aa
462f4ecd6

15e7791b6

b2c3388cd
15e7791b6

b2c3388cd

15e7791b6






ab2eb7357



b6c8d7446









3e9a54fbf
b6c8d7446





59838cdfe







ab2eb7357
59838cdfe







8338162c4


59838cdfe























ab2eb7357



















59838cdfe






aa5e37bc7

59838cdfe


ab2eb7357
59838cdfe

ab2eb7357
59838cdfe
ab2eb7357














59838cdfe





59838cdfe

b6c8d7446
33eb6f286


0447ae81d
59838cdfe
15e7791b6



aa5e37bc7
15e7791b6







5b6fb416e
15e7791b6
98d9d1ac0
5b6fb416e

5d2e3f2f0
5b6fb416e

98d9d1ac0
5b6fb416e
15e7791b6
1df65fce9

a6c7c51cb
3e9a54fbf
e1b40cb9a
5b6fb416e



a6c7c51cb
5b6fb416e

15e7791b6
5b6fb416e
a6c7c51cb
75e21e5aa



15e7791b6
15e7791b6


f2a60de3d
f49125b1e
15e7791b6





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
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
  
                                       


                                  
                                                                    













                                                                       
                         
                        
                           
                                 
                     
                          

               


                      
                      
 
             








                                                                      
                                        
                                     
                 




                    
                              
                                                                            


                           
                                              
















                                                             
                                                         
                                                                                


                  
                                                   










                                                           
                                                         
                                                                        

                                   
                          

                                                 
                                           

                                      









































                                                                                       

 

                                                             
 

                                              
 
                              
                      
                                                                       




                                                                  






                                                                          
                            




                                                             

                                               
 
                              
                                                                        
                                                               

                                 
                                                           

                                                              
                                                                        







                                                                       
                                           
                                                                   


                                                                       
      








                                                                             






                                                                               


                                                                     
                                                                              







                                                                       
                                           
                                                                   


                                                                       
      


                                                               
                                                                             




                                                                






                                                                               



                                                                     





                                                                       


                                                                       
      
                 
         
                            
 
                             



                                                                  
                    

                                             


                               
                                                          

                               
                         

                               
                               
                              
 




                                                                     

                                                                             
                                            



                                                
                                
 


                                                


















































                                                                           

                                                          




                                                                       
 



                                                 



                                                                     
                                                                                













                                                                               

                                                                      
                                                           
                                               
                                                           

                                              



















                                                                                






                                                                      













                                                                        

 







                                                                            











                                                                         


                                                                             
 
 
 



























































                                                                               
 
                                                       



                                              
                                     
                       





                                                                    
                              
                








                                                        
                                     
                       

                          



                                                                         
                













                                                                               
                                                                         


         





                                                                                
                                             
 
                                                    
                                      
                                  

                                      
              




                                       
                                
 















                                                                    




                                                                                
 







                                                                        
 
                                 
                                                      
                                                                                
                                     




                                                                            
                                                                   

                                                                                
                                                                  

                              


                                                                        
 






                                                                 
 
                                                         
                                                                   

                                                    

                                                                             



                                                                                
                                                                       



                                                                                
                                 
 

                 















                                                                                









                                                                            
                                
                                        

                                                           












                                                                                
                                                        
                                                  
                                                           

                                                                      



                                                                      



                                                                                


                                                         



                                                                     
 
 


                                                                        
 


                                                                        


                                                                   



                                                                   




                                                                        
 
                                         
                                
                                                       


                                                         




                                                                             
 
                                                                     
                                              

                                                                     
                                      
                                                                             
                                  
                                                                               
                                                        


                                                                               
                                                        

                                                                               



                                                               
                        
                                                                               
                                                        
                                                                               
                                                           



                                                                       

                 
                               




                                                                     


                                  
                             
                                                                       
 
                                                           



                                                           





                                                                        


                                                             
                                                             
                           
                                                                                
                                                               

                                                                                
 
                                                                                
                                                               

                                                                                
                                   
                                                                                
                                                               

                                                                                














                                                                        











                                                                          



















                                                                               
 
      
                        
                                                  
                                                         
                                                    
 







                                                                              



                                                                              







                                                                                
                                          











                                                                            
      
                 
 
                                                              
                                                 
 

                                                               





                                                                   




                                                           


                                                  
                                                                     
 
                                  
 
                                             

         




                                                                  
 

                                                                   
                                                                              
 
                                       



                                                          
                                     
 
                                                                          



                                                                        
                                                            

                                                                    


                                                                   
 




                                                                             

                                                             
                                                                    

                                                               

         
                                                          

                                                                         

                               






                                                                  



                                                                       









                                                                               
 





                                                                            







                                                                         
                                                              







                                 


                               























                                                                              



















                                                                              






                                             

                                                                 


                                                                   
                                                                

                                                                 
                                                                
      














                                                                                        





                                                            

                                                                    
 


                                              
                                    
     



                                                        
                 







                                                  
                                   
 
                                      

                                                                    
                                                                 

                                                         
      
 
                                                       

                                                           
                                                                      
 
                                                 



                                                            
                                               

                                              
                        
                                                                              
                                               



                                              
                 


                     
                                                                  
                                                            





                                                                   
/*
 * window.c: tegra dc window interface.
 *
 * Copyright (C) 2010 Google, Inc.
 *
 * Copyright (c) 2010-2017, NVIDIA CORPORATION, All rights reserved.
 *
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * 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.
 *
 */
#include <linux/err.h>
#include <linux/types.h>
#include <linux/moduleparam.h>
#include <linux/export.h>
#include <linux/delay.h>
#include <soc/tegra/fuse.h>
#include <trace/events/display.h>
#include <linux/fb.h>
#include <linux/version.h>

#include "dc.h"
#include "dc_reg.h"
#include "dc_config.h"
#include "dc_priv.h"
#include "dc_common.h"

int no_vsync;

module_param_named(no_vsync, no_vsync, int, S_IRUGO | S_IWUSR);

static bool tegra_dc_windows_are_clean(struct tegra_dc_win *windows[],
					     int n)
{
	int i;

	for (i = 0; i < n; i++) {
		if (windows[i]->dirty) {
			return false;
		}
	}

	return true;
}

#ifndef CONFIG_TEGRA_NVDISPLAY
static int get_topmost_window(u32 *depths, unsigned long *wins, int win_num)
{
	int idx, best = -1;

	for_each_set_bit(idx, wins, win_num) {
		if (best == -1 || depths[idx] < depths[best])
			best = idx;
	}
	clear_bit(best, wins);
	return best;
}

static u32 blend_topwin(u32 flags)
{
	if (flags & TEGRA_WIN_FLAG_BLEND_COVERAGE)
		return BLEND(NOKEY, ALPHA, 0xff, 0xff);
	else if (flags & TEGRA_WIN_FLAG_BLEND_PREMULT)
		return BLEND(NOKEY, PREMULT, 0xff, 0xff);
	else
		return BLEND(NOKEY, FIX, 0xff, 0xff);
}

static u32 blend_2win(int idx, unsigned long behind_mask,
						u32 *flags, int xy, int win_num)
{
	int other;

	for (other = 0; other < win_num; other++) {
		if (other != idx && (xy-- == 0))
			break;
	}
	if (BIT(other) & behind_mask)
		return blend_topwin(flags[idx]);
	else if (flags[other])
		return BLEND(NOKEY, DEPENDANT, 0x00, 0x00);
	else
		return BLEND(NOKEY, FIX, 0x00, 0x00);
}

static u32 blend_3win(int idx, unsigned long behind_mask,
						u32 *flags, int win_num)
{
	unsigned long infront_mask;
	int first, second;

	infront_mask = ~(behind_mask | BIT(idx));
	infront_mask &= (BIT(win_num) - 1);
	first = ffs(infront_mask) - 1;

	if (win_num != 3) {
		if (!infront_mask)
			return blend_topwin(flags[idx]);
		else if (behind_mask && first != -1 && flags[first])
			return BLEND(NOKEY, DEPENDANT, 0x00, 0x00);
		else
			return BLEND(NOKEY, FIX, 0x0, 0x0);
	} else {
		if (!infront_mask) {
			return blend_topwin(flags[idx]);
		} else if (behind_mask) {
			/* If the first (top) window is not opaque, check if the
			 * current (middle) window is not opaque. If yes then we need
			 * to enable appropriate blending mode otherwise current window
			 * is dependent on the first window. If the first window is
			 * opaque then the current window has no contribution and we
			 * set its weight to 0.
			 */

			if (flags[first]) {
				if (flags[idx])
					return blend_topwin(flags[idx]);
				else
					return BLEND(NOKEY, DEPENDANT, 0x00, 0x00);
			} else {
				return BLEND(NOKEY, FIX, 0x00, 0x00);
			}
		} else {
			infront_mask &= ~(BIT(first));
			second = ffs(infront_mask) - 1;

			/* If both windows above the bottom window are not opaque then
			 * the bottom window is dependent otherwise the bottom window
			 * has no contribution and we set its weight to 0.
			 */

			if (flags[first] && flags[second])
				return BLEND(NOKEY, DEPENDANT, 0x00, 0x00);
			else
				return BLEND(NOKEY, FIX, 0x00, 0x00);
		}
	}
}

static void tegra_dc_blend_parallel(struct tegra_dc *dc,
				struct tegra_dc_blend *blend)
{
	int win_num = dc->gen1_blend_num;
	unsigned long mask = BIT(win_num) - 1;

	tegra_dc_io_start(dc);
	while (mask) {
		int idx = get_topmost_window(blend->z, &mask, win_num);

		tegra_dc_writel(dc, WINDOW_A_SELECT << idx,
				DC_CMD_DISPLAY_WINDOW_HEADER);
		tegra_dc_writel(dc, BLEND(NOKEY, FIX, 0xff, 0xff),
				DC_WIN_BLEND_NOKEY);
		tegra_dc_writel(dc, blend_2win(idx, mask, blend->flags, 0,
				win_num), DC_WIN_BLEND_2WIN_X);
		tegra_dc_writel(dc, blend_2win(idx, mask, blend->flags, 1,
				win_num), DC_WIN_BLEND_2WIN_Y);
		tegra_dc_writel(dc, blend_3win(idx, mask, blend->flags,
				win_num), DC_WIN_BLEND_3WIN_XY);
	}
	tegra_dc_io_end(dc);
}

static void tegra_dc_blend_sequential(struct tegra_dc *dc,
				struct tegra_dc_blend *blend)
{
	int idx;
	unsigned long mask = dc->valid_windows;

	tegra_dc_io_start(dc);
	for_each_set_bit(idx, &mask, tegra_dc_get_numof_dispwindows()) {
		if (!tegra_dc_feature_is_gen2_blender(dc, idx))
			continue;

		tegra_dc_writel(dc, WINDOW_A_SELECT << idx,
				DC_CMD_DISPLAY_WINDOW_HEADER);

		if (blend->flags[idx] & TEGRA_WIN_FLAG_BLEND_COVERAGE) {
#if defined(CONFIG_TEGRA_DC_BLENDER_DEPTH)
			tegra_dc_writel(dc,
					WIN_K1(blend->alpha[idx]) |
					WIN_K2(0xff) |
					WIN_BLEND_ENABLE |
					WIN_DEPTH(dc->blend.z[idx]),
					DC_WINBUF_BLEND_LAYER_CONTROL);
#else
			tegra_dc_writel(dc,
					WIN_K1(blend->alpha[idx]) |
					WIN_K2(0xff) |
					WIN_BLEND_ENABLE,
					DC_WINBUF_BLEND_LAYER_CONTROL);
#endif

			tegra_dc_writel(dc,
			WIN_BLEND_FACT_SRC_COLOR_MATCH_SEL_K1_TIMES_SRC |
			WIN_BLEND_FACT_DST_COLOR_MATCH_SEL_NEG_K1_TIMES_SRC |
			WIN_BLEND_FACT_SRC_ALPHA_MATCH_SEL_K2 |
			WIN_BLEND_FACT_DST_ALPHA_MATCH_SEL_ZERO,
			DC_WINBUF_BLEND_MATCH_SELECT);

			tegra_dc_writel(dc,
			WIN_BLEND_FACT_SRC_COLOR_NOMATCH_SEL_K1_TIMES_SRC |
			WIN_BLEND_FACT_DST_COLOR_NOMATCH_SEL_NEG_K1_TIMES_SRC |
			WIN_BLEND_FACT_SRC_ALPHA_NOMATCH_SEL_K2 |
			WIN_BLEND_FACT_DST_ALPHA_NOMATCH_SEL_ZERO,
			DC_WINBUF_BLEND_NOMATCH_SELECT);

			tegra_dc_writel(dc,
					WIN_ALPHA_1BIT_WEIGHT0(0) |
					WIN_ALPHA_1BIT_WEIGHT1(0xff),
					DC_WINBUF_BLEND_ALPHA_1BIT);
		} else if (blend->flags[idx] & TEGRA_WIN_FLAG_BLEND_PREMULT) {
#if defined(CONFIG_TEGRA_DC_BLENDER_DEPTH)
			tegra_dc_writel(dc,
					WIN_K1(blend->alpha[idx]) |
					WIN_K2(0xff) |
					WIN_BLEND_ENABLE |
					WIN_DEPTH(dc->blend.z[idx]),
					DC_WINBUF_BLEND_LAYER_CONTROL);
#else
			tegra_dc_writel(dc,
					WIN_K1(blend->alpha[idx]) |
					WIN_K2(0xff) |
					WIN_BLEND_ENABLE,
					DC_WINBUF_BLEND_LAYER_CONTROL);
#endif

			tegra_dc_writel(dc,
			WIN_BLEND_FACT_SRC_COLOR_MATCH_SEL_K1 |
			WIN_BLEND_FACT_DST_COLOR_MATCH_SEL_NEG_K1_TIMES_SRC |
			WIN_BLEND_FACT_SRC_ALPHA_MATCH_SEL_K2 |
			WIN_BLEND_FACT_DST_ALPHA_MATCH_SEL_ZERO,
			DC_WINBUF_BLEND_MATCH_SELECT);

			tegra_dc_writel(dc,
			WIN_BLEND_FACT_SRC_COLOR_NOMATCH_SEL_NEG_K1_TIMES_DST |
			WIN_BLEND_FACT_DST_COLOR_NOMATCH_SEL_K1 |
			WIN_BLEND_FACT_SRC_ALPHA_NOMATCH_SEL_K2 |
			WIN_BLEND_FACT_DST_ALPHA_NOMATCH_SEL_ZERO,
			DC_WINBUF_BLEND_NOMATCH_SELECT);

			tegra_dc_writel(dc,
					WIN_ALPHA_1BIT_WEIGHT0(0) |
					WIN_ALPHA_1BIT_WEIGHT1(0xff),
					DC_WINBUF_BLEND_ALPHA_1BIT);
		} else {
#if defined(CONFIG_TEGRA_DC_BLENDER_DEPTH)
			tegra_dc_writel(dc,
					WIN_BLEND_BYPASS |
					WIN_DEPTH(dc->blend.z[idx]),
					DC_WINBUF_BLEND_LAYER_CONTROL);
#else
			tegra_dc_writel(dc,
					WIN_BLEND_BYPASS,
					DC_WINBUF_BLEND_LAYER_CONTROL);
#endif
		}
	}
	tegra_dc_io_end(dc);
}
#endif	/* TEGRA_NVDISPLAY */

/* does not support syncing windows on multiple dcs in one call */
int tegra_dc_sync_windows(struct tegra_dc_win *windows[], int n)
{
	int ret = 0;
	struct tegra_dc *dc = windows[0]->dc;

	if (dc == NULL)
		return -EFAULT;

	if (n < 1 || n > tegra_dc_get_numof_dispwindows())
		return -EINVAL;

	if (!dc->enabled)
		return -EFAULT;

	trace_sync_windows(dc);
	mutex_lock(&dc->lock);

	/*
	 * Putting the task state as TASK_UINTERRUPTIBLE makes
	 * task wait till windows status promoted or timeout occurred
	 * and wont be interrupted by signal or any other reason.
	 */
	ret = ___wait_event(dc->wq,
		___wait_cond_timeout(tegra_dc_windows_are_clean(windows, n)),
		TASK_UNINTERRUPTIBLE, 0, HZ,
		mutex_unlock(&dc->lock);
		__ret = schedule_timeout(__ret);
		mutex_lock(&dc->lock));

	mutex_unlock(&dc->lock);

	if (dc->out_ops && dc->out_ops->release)
		dc->out_ops->release(dc);

	return ret;
}
EXPORT_SYMBOL(tegra_dc_sync_windows);

static inline u32 compute_dda_inc(fixed20_12 in, unsigned out_int,
				  bool v, unsigned Bpp)
{
	/*
	 * min(round((prescaled_size_in_pixels - 1) * 0x1000 /
	 *	     (post_scaled_size_in_pixels - 1)), MAX)
	 * Where the value of MAX is as follows:
	 * For V_DDA_INCREMENT: 15.0 (0xF000)
	 * For H_DDA_INCREMENT:  4.0 (0x4000) for 4 Bytes/pix formats.
	 *			 8.0 (0x8000) for 2 Bytes/pix formats.
	 */

	fixed20_12 out = dfixed_init(out_int);
	u32 dda_inc;
	int max;

	if (v) {
		max = 15;
	} else {
		switch (Bpp) {
		default:
			WARN_ON_ONCE(1);
			/* fallthrough */
		case 4:
			max = 4;
			break;
		case 2:
			max = 8;
			break;
		}
	}

	out.full = max_t(u32, out.full - dfixed_const(1), dfixed_const(1));
	in.full -= dfixed_const(1);

	dda_inc = dfixed_div(in, out);

	dda_inc = min_t(u32, dda_inc, dfixed_const(max));

	return dda_inc;
}

static inline u32 compute_initial_dda(fixed20_12 in)
{
	return dfixed_frac(in);
}

static inline void __maybe_unused tegra_dc_update_scaling(
				struct tegra_dc *dc,
				struct tegra_dc_win *win, unsigned Bpp,
				unsigned Bpp_bw, bool scan_column)
{
	u32 h_dda, h_dda_init;
	u32 v_dda, v_dda_init;

	h_dda_init = compute_initial_dda(win->x);
	v_dda_init = compute_initial_dda(win->y);

	if (scan_column) {
		if (tegra_dc_feature_has_interlace(dc, win->idx)
			&& (dc->mode.vmode == FB_VMODE_INTERLACED)) {
			if (WIN_IS_INTERLACE(win))
				tegra_dc_writel(dc,
					V_PRESCALED_SIZE(dfixed_trunc(win->w)) |
					H_PRESCALED_SIZE(dfixed_trunc(win->h)
					* Bpp),
					DC_WIN_PRESCALED_SIZE);
			else
				tegra_dc_writel(dc,
					V_PRESCALED_SIZE(dfixed_trunc(win->w))
					| H_PRESCALED_SIZE(dfixed_trunc(win->h)
					* Bpp), DC_WIN_PRESCALED_SIZE);
		} else {
			tegra_dc_writel(dc,
				V_PRESCALED_SIZE(dfixed_trunc(win->w)) |
				H_PRESCALED_SIZE(dfixed_trunc(win->h) * Bpp),
				DC_WIN_PRESCALED_SIZE);
		}
		tegra_dc_writel(dc, v_dda_init, DC_WIN_H_INITIAL_DDA);
		tegra_dc_writel(dc, h_dda_init, DC_WIN_V_INITIAL_DDA);
		h_dda = compute_dda_inc(win->h, win->out_w,
				false, Bpp_bw);
		v_dda = compute_dda_inc(win->w, win->out_h,
				true, Bpp_bw);
	} else {
		if (tegra_dc_feature_has_interlace(dc, win->idx)
			&& (dc->mode.vmode == FB_VMODE_INTERLACED)) {
			if (WIN_IS_INTERLACE(win))
				tegra_dc_writel(dc,
					V_PRESCALED_SIZE(dfixed_trunc(win->h)
					>> 1) |
					H_PRESCALED_SIZE(dfixed_trunc(win->w)
					* Bpp), DC_WIN_PRESCALED_SIZE);
			else
				tegra_dc_writel(dc,
					V_PRESCALED_SIZE(dfixed_trunc(win->h)) |
					H_PRESCALED_SIZE(dfixed_trunc(win->w)
					* Bpp),
					DC_WIN_PRESCALED_SIZE);
		} else {
			tegra_dc_writel(dc,
				V_PRESCALED_SIZE(dfixed_trunc(win->h)) |
				H_PRESCALED_SIZE(dfixed_trunc(win->w) * Bpp),
				DC_WIN_PRESCALED_SIZE);
		}
		tegra_dc_writel(dc, h_dda_init, DC_WIN_H_INITIAL_DDA);
		tegra_dc_writel(dc, v_dda_init, DC_WIN_V_INITIAL_DDA);
		h_dda = compute_dda_inc(win->w, win->out_w,
				false, Bpp_bw);
		v_dda = compute_dda_inc(win->h, win->out_h,
				true, Bpp_bw);
	}

	if (tegra_dc_feature_has_interlace(dc, win->idx) &&
		(dc->mode.vmode == FB_VMODE_INTERLACED)) {
		if (WIN_IS_INTERLACE(win))
			tegra_dc_writel(dc, V_DDA_INC(v_dda) |
				H_DDA_INC(h_dda), DC_WIN_DDA_INCREMENT);
		else
			tegra_dc_writel(dc, V_DDA_INC(v_dda << 1) |
				H_DDA_INC(h_dda), DC_WIN_DDA_INCREMENT);

	} else {
		tegra_dc_writel(dc, V_DDA_INC(v_dda) |
			H_DDA_INC(h_dda), DC_WIN_DDA_INCREMENT);
	}
}


/*
 * The immediate flip with hsync can change only few registers, so this call
 * should filter out changes from previous flip that may cause a change to
 * these registers.
 */
bool  update_is_hsync_safe(struct tegra_dc_win *cur_win,
			   struct tegra_dc_win *new_win)
{
	return ((cur_win->fmt == new_win->fmt) &&
		(cur_win->flags == new_win->flags) &&
		(dfixed_trunc(cur_win->x) == dfixed_trunc(new_win->x)) &&
		(dfixed_trunc(cur_win->y) == dfixed_trunc(new_win->y)) &&
		(dfixed_trunc(cur_win->w) == dfixed_trunc(new_win->w)) &&
		(dfixed_trunc(cur_win->h) == dfixed_trunc(new_win->h)) &&
		(cur_win->out_x == new_win->out_x) &&
		(cur_win->out_y == new_win->out_y) &&
		(cur_win->out_w == new_win->out_w) &&
		(cur_win->out_h == new_win->out_h) &&
		(cur_win->z == new_win->z) &&
		(cur_win->dc == new_win->dc) &&
		(!memcmp(&cur_win->csc, &new_win->csc, sizeof(cur_win->csc)))
		);
}


void tegra_dc_win_partial_update(struct tegra_dc *dc, struct tegra_dc_win *win,
	unsigned int xoff, unsigned int yoff, unsigned int width,
	unsigned int height)
{
	if (!win->out_w || !win->out_h ||
		(win->out_x >= (xoff + width)) ||
		(win->out_y >= (yoff + height)) ||
		(xoff >= (win->out_x + win->out_w)) ||
		(yoff >= (win->out_y + win->out_h))) {
		tegra_dc_writel(dc, 0, DC_WIN_WIN_OPTIONS);
		return;
	} else {
		u64 tmp_64;
		fixed20_12 fixed_tmp;
		unsigned int xoff_2;
		unsigned int yoff_2;
		unsigned int width_2;
		unsigned int height_2;

		xoff_2 = (win->out_x < xoff) ? xoff : win->out_x;
		yoff_2 = (win->out_y < yoff) ? yoff : win->out_y;
		width_2 = ((win->out_x + win->out_w) > (xoff + width)) ?
			(xoff + width - xoff_2) :
			(win->out_x + win->out_w - xoff_2);
		height_2 = ((win->out_y + win->out_h) > (yoff + height)) ?
			(yoff + height - yoff_2) :
			(win->out_y + win->out_h - yoff_2);

		tmp_64 = (u64)(xoff_2 - win->out_x) * win->w.full;
		do_div(tmp_64, win->out_w);
		fixed_tmp.full = (u32)tmp_64;
		win->x.full += dfixed_floor(fixed_tmp);

		tmp_64 = (u64)(yoff_2 - win->out_y) * win->h.full;
		do_div(tmp_64, win->out_h);
		fixed_tmp.full = (u32)tmp_64;
		win->y.full += dfixed_floor(fixed_tmp);

		tmp_64 = (u64)(width_2) * win->w.full;
		do_div(tmp_64, win->out_w);
		fixed_tmp.full = (u32)tmp_64;
		win->w.full = dfixed_floor(fixed_tmp);

		tmp_64 = (u64)(height_2) * win->h.full;
		do_div(tmp_64, win->out_h);
		fixed_tmp.full = (u32)tmp_64;
		win->h.full = dfixed_floor(fixed_tmp);

		/* Move the partial region to the up-left corner
		 * so dc can only scan out this region. */
		win->out_x = xoff_2 - xoff;
		win->out_y = yoff_2 - yoff;
		win->out_w = width_2;
		win->out_h = height_2;

		/* Update shadow registers */
		memcpy(&dc->shadow_windows[win->idx], win,
			sizeof(struct tegra_dc_win));
	}
}

static void tegra_dc_vrr_flip_time(struct tegra_dc *dc)
{
	struct timespec time_now;
	struct tegra_vrr *vrr  = dc->out->vrr;

	if (!vrr || !vrr->capability)
		return;

	if (vrr->enable) {
		vrr->lastenable = 1;
		getnstimeofday(&time_now);
		vrr->curr_flip_us = (s64)time_now.tv_sec * 1000000 +
				time_now.tv_nsec / 1000;
		vrr->flip = 1;
	} else {
		vrr->curr_flip_us = 0;
		vrr->last_flip_us = 0;
	}
}

static void tegra_dc_vrr_cancel_vfp(struct tegra_dc *dc)
{
	struct tegra_vrr *vrr  = dc->out->vrr;

	if (!vrr || !vrr->capability)
		return;

	if (vrr->enable) {
		if (dc->out->type == TEGRA_DC_OUT_DSI)
			tegra_dc_set_act_vfp(dc, vrr->vfp_shrink);
		else
			tegra_dc_set_act_vfp(dc, dc->mode.v_front_porch);
	} else {
		if (dc->out->type == TEGRA_DC_OUT_DSI) {
			if (vrr->lastenable && vrr->dcb <= vrr->db_tolerance) {
				tegra_dc_set_act_vfp(dc,
						dc->mode.v_front_porch);
				vrr->lastenable = 0;
				vrr->frame_type = 0;
				vrr->last_frame_us = 0;
				vrr->flip_interval_us = 0;
				vrr->frame_count = 0;
				vrr->flip_count = 0;
				vrr->vfp_shrink = vrr->v_front_porch_min;
				vrr->vfp_extend = vrr->v_front_porch_max;
			}
		} else
			tegra_dc_set_act_vfp(dc, dc->mode.v_front_porch);
	}
}


#if !defined(CONFIG_TEGRA_NVDISPLAY)
/* Program registers for each window. struct tegra_dc_win --> Assembly registers
 */
static int _tegra_dc_program_windows(struct tegra_dc *dc,
	struct tegra_dc_win *windows[], int n, u16 *dirty_rect,
	bool wait_for_vblank, bool lock_flip)
{
	unsigned long update_mask = GENERAL_ACT_REQ;
	unsigned long act_control = 0;
	unsigned long win_options;
	bool update_blend_par = false;
	bool update_blend_seq = false;
	int i;
	bool do_partial_update = false;
	unsigned int xoff;
	unsigned int yoff;
	unsigned int width;
	unsigned int height;
	enum tegra_revision rev;

	if (dirty_rect) {
		xoff = dirty_rect[0];
		yoff = dirty_rect[1];
		width = dirty_rect[2];
		height = dirty_rect[3];
		do_partial_update = !dc->out_ops->partial_update(dc,
			&xoff, &yoff, &width, &height);

		if (do_partial_update) {
			tegra_dc_writel(dc, width | (height << 16),
				DC_DISP_DISP_ACTIVE);

			dc->disp_active_dirty = true;
		}
	}

	/* If any of the window updates requires vsync to program the window
	   update safely, vsync all windows in this flip.  Safety overrides both
	   the requested wait_for_vblank, and also the no_vsync global. */
	for (i = 0; i < n; i++) {
		struct tegra_dc_win *win = windows[i];

		if ((!wait_for_vblank &&
		    !update_is_hsync_safe(&dc->shadow_windows[win->idx],
					  win)) || do_partial_update)
			wait_for_vblank = 1;

		memcpy(&dc->shadow_windows[win->idx], win,
		       sizeof(struct tegra_dc_win));
	}

	for (i = 0; i < n; i++) {
		struct tegra_dc_win *win = windows[i];
		struct tegra_dc_win *dc_win = tegra_dc_get_window(dc, win->idx);
		bool scan_column = 0;
		fixed20_12 h_offset, v_offset;
		bool invert_h = (win->flags & TEGRA_WIN_FLAG_INVERT_H) != 0;
		bool invert_v = (win->flags & TEGRA_WIN_FLAG_INVERT_V) != 0;
		bool yuv = tegra_dc_is_yuv(win->fmt);
		bool yuvp = tegra_dc_is_yuv_planar(win->fmt);
		bool yuvsp = tegra_dc_is_yuv_semi_planar(win->fmt);
		unsigned Bpp = tegra_dc_fmt_bpp(win->fmt) / 8;
		/* Bytes per pixel of bandwidth, used for dda_inc calculation */
		unsigned Bpp_bw = Bpp * ((yuvp || yuvsp) ? 2 : 1);
		bool filter_h;
		bool filter_v;
#if defined(CONFIG_TEGRA_DC_SCAN_COLUMN)
		scan_column = (win->flags & TEGRA_WIN_FLAG_SCAN_COLUMN);
#endif

		tegra_dc_writel(dc, WINDOW_A_SELECT << win->idx,
				DC_CMD_DISPLAY_WINDOW_HEADER);

		if (!no_vsync)
			update_mask |= WIN_A_ACT_REQ << win->idx;

		if (!WIN_IS_ENABLED(win)) {

			dc_win->dirty = no_vsync ? 0 : 1;
			tegra_dc_writel(dc, 0, DC_WIN_WIN_OPTIONS);
			if (dc->yuv_bypass) {
				if (dc->mode.vmode &
					(FB_VMODE_Y420 | FB_VMODE_Y420_ONLY |
					 FB_VMODE_Y24))
					tegra_dc_writel(dc,
						RGB_TO_YUV420_8BPC_BLACK_PIX,
						DC_DISP_BLEND_BACKGROUND_COLOR);
				else if (dc->mode.vmode &
					(FB_VMODE_Y422 | FB_VMODE_Y36))
					tegra_dc_writel(dc,
						RGB_TO_YUV422_10BPC_BLACK_PIX,
						DC_DISP_BLEND_BACKGROUND_COLOR);
			}
			continue;

		}