Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
CTCaer
GitHub Repository: CTCaer/hekate
Path: blob/master/bdk/display/vic.c
3694 views
1
/*
2
* VIC (4.0) driver for Tegra X1
3
*
4
* Copyright (c) 2018-2024 CTCaer
5
*
6
* This program is free software; you can redistribute it and/or modify it
7
* under the terms and conditions of the GNU General Public License,
8
* version 2, as published by the Free Software Foundation.
9
*
10
* This program is distributed in the hope it will be useful, but WITHOUT
11
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13
* more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
*/
18
19
#include <string.h>
20
21
#include "vic.h"
22
#include <mem/heap.h>
23
#include <soc/bpmp.h>
24
#include <soc/clock.h>
25
#include <soc/timer.h>
26
#include <soc/t210.h>
27
#include <utils/types.h>
28
29
/* VIC Private registers */
30
#define PVIC_FALCON_PA_OFFSET 0x1000
31
#define PVIC_FALCON_ADDR 0x10AC
32
#define PVIC_FALCON_IDLESTATE 0x104C
33
34
/* VIC Control and Status registers. */
35
/* Fetch Control registers. */
36
#define VIC_FC_COMPOSE 0x10000
37
#define COMPOSE_START BIT(0)
38
39
#define VIC_FC_CFG_STRUCT_SLOT_INDEX 0x10B00
40
41
#define VIC_FC_CFG_STRUCT_SLOT_CFG0 0x10B04
42
#define SLOT_ENABLE BIT(0)
43
#define FIELD_CURRENT_ENABLE BIT(8)
44
45
#define VIC_FC_CFG_STRUCT_SLOT_CFG2 0x10B0C
46
#define CACHE_WIDTH(n) ((n) << 16)
47
#define CACHE_WIDTH_16BX16 0 // Block Linear.
48
#define CACHE_WIDTH_32BX8 1 // Block Linear.
49
#define CACHE_WIDTH_64BX4 2 // Block Linear, Pitch. Recommended.
50
#define CACHE_WIDTH_128BX2 3 // Block Linear, Pitch.
51
#define CACHE_WIDTH_256BX1 4 // Pitch.
52
#define OUTPUT_FLIP_X BIT(20)
53
#define OUTPUT_FLIP_Y BIT(21)
54
#define OUTPUT_TRANSPOSE BIT(22)
55
56
#define VIC_FC_CFG_STRUCT_SLOT_SFC_SIZE 0x10B10
57
#define VIC_FC_CFG_STRUCT_SLOT_LUMA_SIZE 0x10B14
58
#define VIC_FC_CFG_STRUCT_SLOT_CHROMA_SIZE 0x10B18
59
#define VIC_FC_CFG_STRUCT_SLOT_SRC_RECT_LR 0x10B1C
60
#define VIC_FC_CFG_STRUCT_SLOT_SRC_RECT_TB 0x10B20
61
#define VIC_FC_CFG_STRUCT_SLOT_DST_RECT_LR 0x10B30
62
#define VIC_FC_CFG_STRUCT_SLOT_DST_RECT_TB 0x10B34
63
#define VIC_FC_CFG_STRUCT_TGT_RECT_LR 0x10B38
64
#define VIC_FC_CFG_STRUCT_TGT_RECT_TB 0x10B3C
65
#define VIC_FC_SLOT_MAP 0x10C00
66
67
#define VIC_FC_FCE_CTRL 0x11000
68
#define START_TRIGGER BIT(0)
69
#define HALT_TRIGGER BIT(1)
70
#define CLEAR_ERROR BIT(8)
71
72
#define VIC_FC_FCE_UCODE_ADDR 0x11200
73
#define VIC_FC_FCE_UCODE_INST 0x11300
74
75
/* Surface List registers. */
76
#define VIC_SL_CFG_STRUCT_SLOT_INDEX 0x12100
77
#define VIC_SL_CFG_STRUCT_SLOT_DST_RECT_LR 0x12200
78
#define VIC_SL_CFG_STRUCT_SLOT_DST_RECT_TB 0x12300
79
#define VIC_SL_CFG_STRUCT_TGT_RECT_LR 0x12400
80
#define VIC_SL_CFG_STRUCT_TGT_RECT_TB 0x12500
81
#define VIC_SL_CFG_STRUCT_SLOT_CFG0 0x12600
82
83
/* Surface Cache registers. */
84
#define VIC_SC_PRAMBASE 0x14000
85
#define VIC_SC_PRAMSIZE 0x14100
86
#define VIC_SC_SFC0_BASE_LUMA(n) (0x14300 + (n) * 0x100)
87
88
/* Blending Output registers. */
89
#define VIC_BL_TARGET_BASADR 0x22000
90
#define VIC_BL_CONFIG 0x22800
91
#define SUBPARTITION_MODE BIT(0)
92
#define PROCESS_CFG_STRUCT_TRIGGER BIT(2)
93
#define SLOTMASK(n) ((n) << 8)
94
95
#define VIC_BL_CFG_STRUCT_CFG0 0x22C00
96
#define VIC_BL_CFG_STRUCT_SFC_SIZE 0x22C04
97
#define VIC_BL_CFG_STRUCT_LUMA_SIZE 0x22C08
98
#define VIC_BL_CFG_STRUCT_CHROMA_SIZE 0x22C0C
99
#define VIC_BL_CFG_STRUCT_TGT_RECT_LR 0x22C10
100
#define VIC_BL_CFG_STRUCT_TGT_RECT_TB 0x22C14
101
102
// VIC_FC_CFG_STRUCT_SLOT_CFG2 & VIC_BL_CFG_STRUCT_CFG0.
103
#define BLK_KIND(n) ((n) << 8)
104
#define BLK_KIND_PITCH 0
105
#define BLK_KIND_GENERIC_16BX2 1
106
#define BLK_HEIGHT(n) ((n) << 12)
107
#define BLK_HEIGHT_ONE_GOB 0
108
#define BLK_HEIGHT_SIXTEEN_GOBS 4
109
110
// Generic size macros.
111
#define SIZE_WIDTH(n) (((n) - 1) << 0)
112
#define SIZE_HEIGHT(n) (((n) - 1) << 16)
113
#define RECT_LEFT(n) ((n) << 0)
114
#define RECT_RIGHT(n) (((n) - 1) << 16)
115
#define RECT_TOP(n) ((n) << 0)
116
#define RECT_BOTTOM(n) (((n) - 1) << 16)
117
118
#define FORMAT_PROGRESSIVE 0
119
#define SOFT_CLAMP_MIN 0
120
#define SOFT_CLAMP_MAX 0x3FFu
121
#define ALPHA_1_0 0x3FFu
122
123
typedef struct _OutputConfig {
124
u64 AlphaFillMode:3;
125
u64 AlphaFillSlot:3;
126
u64 BackgroundAlpha:10;
127
u64 BackgroundR:10;
128
u64 BackgroundG:10;
129
u64 BackgroundB:10;
130
u64 RegammaMode:2;
131
u64 OutputFlipX:1;
132
u64 OutputFlipY:1;
133
u64 OutputTranspose:1;
134
u64 rsvd1:1;
135
u64 rsvd2:12;
136
u64 TargetRectLeft:14;
137
u64 rsvd3:2;
138
u64 TargetRectRight:14;
139
u64 rsvd4:2;
140
u64 TargetRectTop:14;
141
u64 rsvd5:2;
142
u64 TargetRectBottom:14;
143
u64 rsvd6:2;
144
} OutputConfig;
145
146
typedef struct _OutputSurfaceConfig {
147
u64 OutPixelFormat:7;
148
u64 OutChromaLocHoriz:2;
149
u64 OutChromaLocVert:2;
150
u64 OutBlkKind:4;
151
u64 OutBlkHeight:4;
152
u64 rsvd0:3;
153
u64 rsvd1:10;
154
u64 OutSurfaceWidth:14;
155
u64 OutSurfaceHeight:14;
156
u64 rsvd2:4;
157
u64 OutLumaWidth:14;
158
u64 OutLumaHeight:14;
159
u64 rsvd3:4;
160
u64 OutChromaWidth:14;
161
u64 OutChromaHeight:14;
162
u64 rsvd4:4;
163
} OutputSurfaceConfig;
164
165
typedef struct _SlotConfig {
166
u64 SlotEnable:1;
167
u64 DeNoise:1;
168
u64 AdvancedDenoise:1;
169
u64 CadenceDetect:1;
170
u64 MotionMap:1;
171
u64 MMapCombine:1;
172
u64 IsEven:1;
173
u64 ChromaEven:1;
174
u64 CurrentFieldEnable:1;
175
u64 PrevFieldEnable:1;
176
u64 NextFieldEnable:1;
177
u64 NextNrFieldEnable:1;
178
u64 CurMotionFieldEnable:1;
179
u64 PrevMotionFieldEnable:1;
180
u64 PpMotionFieldEnable:1;
181
u64 CombMotionFieldEnable:1;
182
u64 FrameFormat:4;
183
u64 FilterLengthY:2;
184
u64 FilterLengthX:2;
185
u64 Panoramic:12;
186
u64 rsvd1:22;
187
u64 DetailFltClamp:6;
188
u64 FilterNoise:10;
189
u64 FilterDetail:10;
190
u64 ChromaNoise:10;
191
u64 ChromaDetail:10;
192
u64 DeinterlaceMode:4;
193
u64 MotionAccumWeight:3;
194
u64 NoiseIir:11;
195
u64 LightLevel:4;
196
u64 rsvd4:2;
197
u64 SoftClampLow:10;
198
u64 SoftClampHigh:10;
199
u64 rsvd5:3;
200
u64 rsvd6:9;
201
u64 PlanarAlpha:10;
202
u64 ConstantAlpha:1;
203
u64 StereoInterleave:3;
204
u64 ClipEnabled:1;
205
u64 ClearRectMask:8;
206
u64 DegammaMode:2;
207
u64 rsvd7:1;
208
u64 DecompressEnable:1;
209
u64 rsvd9:5;
210
u64 DecompressCtbCount:8;
211
u64 DecompressZbcColor:32;
212
u64 rsvd12:24;
213
u64 SourceRectLeft:30;
214
u64 rsvd14:2;
215
u64 SourceRectRight:30;
216
u64 rsvd15:2;
217
u64 SourceRectTop:30;
218
u64 rsvd16:2;
219
u64 SourceRectBottom:30;
220
u64 rsvd17:2;
221
u64 DestRectLeft:14;
222
u64 rsvd18:2;
223
u64 DestRectRight:14;
224
u64 rsvd19:2;
225
u64 DestRectTop:14;
226
u64 rsvd20:2;
227
u64 DestRectBottom:14;
228
u64 rsvd21:2;
229
u64 rsvd22:32;
230
u64 rsvd23:32;
231
} SlotConfig;
232
233
typedef struct _SlotSurfaceConfig {
234
u64 SlotPixelFormat:7;
235
u64 SlotChromaLocHoriz:2;
236
u64 SlotChromaLocVert:2;
237
u64 SlotBlkKind:4;
238
u64 SlotBlkHeight:4;
239
u64 SlotCacheWidth:3;
240
u64 rsvd0:10;
241
u64 SlotSurfaceWidth:14;
242
u64 SlotSurfaceHeight:14;
243
u64 rsvd1:4;
244
u64 SlotLumaWidth:14;
245
u64 SlotLumaHeight:14;
246
u64 rsvd2:4;
247
u64 SlotChromaWidth:14;
248
u64 SlotChromaHeight:14;
249
u64 rsvd3:4;
250
} SlotSurfaceConfig;
251
252
typedef struct _SlotStruct {
253
SlotConfig slot_cfg;
254
SlotSurfaceConfig slot_sfc_cfg;
255
256
// No need to configure. Reset to zeros.
257
u8 lumaKeyStruct[0x10];
258
u8 colorMatrixStruct[0x20];
259
u8 gamutMatrixStruct[0x20];
260
u8 blendingSlotStruct[0x10];
261
} SlotStruct;
262
263
typedef struct _vic_config_t {
264
// No need to configure. Reset to zeros.
265
u8 pipeConfig[0x10];
266
267
OutputConfig out_cfg;
268
OutputSurfaceConfig out_sfc_cfg;
269
270
// No need to configure. Reset to zeros.
271
u8 out_color_matrix[0x20];
272
u8 clear_rect[0x10 * 4];
273
274
SlotStruct slots[8];
275
} vic_config_t;
276
277
// VIC Fetch Control Engine microcode. Dumped from L4T r33.
278
u8 vic_fce_ucode[] = {
279
0x66, 0x00, 0x00, 0x00, 0x60, 0x07, 0x00, 0x00, 0x42, 0x40, 0x10, 0x00, 0x4E, 0x01, 0x40, 0x00,
280
0x6A, 0x07, 0x00, 0x00, 0x6E, 0x23, 0x04, 0x00, 0x6C, 0x00, 0x00, 0x00, 0x4E, 0x01, 0x04, 0x00,
281
0x6A, 0x0B, 0x00, 0x00, 0x6E, 0x1F, 0x04, 0x00, 0x6C, 0x00, 0x00, 0x00, 0x4E, 0x01, 0x10, 0x00,
282
0x6A, 0x0F, 0x00, 0x00, 0x6E, 0x1F, 0x04, 0x00, 0x6C, 0x00, 0x00, 0x00, 0x48, 0x80, 0x02, 0x00,
283
0x0E, 0x11, 0x00, 0x00, 0x6A, 0x14, 0x00, 0x00, 0x6E, 0x08, 0x06, 0x00, 0x6C, 0x00, 0x00, 0x00,
284
0x4E, 0x01, 0x08, 0x00, 0x6A, 0x18, 0x00, 0x00, 0x6E, 0x26, 0x04, 0x00, 0x6C, 0x00, 0x00, 0x00,
285
0x4E, 0x01, 0x20, 0x00, 0x6A, 0x1C, 0x00, 0x00, 0x6E, 0x26, 0x04, 0x00, 0x6C, 0x00, 0x00, 0x00,
286
0x4E, 0x01, 0x02, 0x00, 0x6A, 0x20, 0x00, 0x00, 0x6E, 0x24, 0x00, 0x00, 0x6C, 0x00, 0x00, 0x00,
287
0x56, 0x00, 0x10, 0x00, 0x56, 0x40, 0x10, 0x00, 0x22, 0x41, 0x01, 0x00, 0x6C, 0x00, 0x00, 0x00,
288
0x62, 0x80, 0x01, 0x00, 0x60, 0x47, 0x00, 0x00, 0x60, 0x87, 0x00, 0x00, 0x01, 0x4A, 0x00, 0x00,
289
0x55, 0xC0, 0x20, 0x00, 0x00, 0x59, 0x00, 0x00, 0x60, 0x87, 0x00, 0x00, 0x60, 0xC7, 0x00, 0x00,
290
0x01, 0x93, 0x00, 0x00, 0x40, 0x82, 0x02, 0x00, 0x4E, 0x02, 0x00, 0x00, 0x6B, 0x34, 0x00, 0x00,
291
0x43, 0xC1, 0x10, 0x00, 0x42, 0x02, 0x03, 0x00, 0x00, 0x23, 0x01, 0x00, 0x24, 0xD4, 0x00, 0x00,
292
0x56, 0x40, 0x3D, 0x00, 0x04, 0xEB, 0x00, 0x00, 0x60, 0x07, 0x01, 0x00, 0x60, 0x47, 0x00, 0x00,
293
0x6A, 0x3E, 0x00, 0x00, 0x55, 0xC0, 0x30, 0x00, 0x48, 0x00, 0x01, 0x00, 0x48, 0x40, 0x01, 0x00,
294
0x48, 0x80, 0x01, 0x00, 0x6B, 0x28, 0x02, 0x00, 0x56, 0x40, 0x09, 0x00, 0x04, 0x4D, 0x01, 0x00,
295
0x06, 0x4D, 0x00, 0x00, 0x42, 0xC0, 0x03, 0x00, 0x56, 0x80, 0x09, 0x00, 0x04, 0xFE, 0x01, 0x00,
296
0x00, 0xF9, 0x01, 0x00, 0x4E, 0x02, 0x00, 0x00, 0x6B, 0x32, 0x02, 0x00, 0x55, 0x40, 0x2F, 0x00,
297
0x56, 0x80, 0x0D, 0x00, 0x4F, 0x00, 0x00, 0x00, 0x6A, 0x0D, 0x02, 0x00, 0x55, 0x40, 0x31, 0x00,
298
0x56, 0x80, 0x0B, 0x00, 0x0C, 0x2B, 0x00, 0x00, 0x6A, 0x13, 0x02, 0x00, 0x43, 0x45, 0x03, 0x00,
299
0x42, 0x86, 0x03, 0x00, 0x4D, 0x06, 0x02, 0x00, 0x6A, 0x0D, 0x02, 0x00, 0x42, 0x86, 0x03, 0x00,
300
0x22, 0x7E, 0x01, 0x00, 0x4E, 0x04, 0x00, 0x00, 0x6B, 0x32, 0x02, 0x00, 0x55, 0x40, 0x17, 0x00,
301
0x0D, 0x2C, 0x00, 0x00, 0x56, 0xC0, 0x09, 0x00, 0x6A, 0x1E, 0x02, 0x00, 0x48, 0xC0, 0x01, 0x00,
302
0x43, 0x04, 0x03, 0x00, 0x6C, 0x20, 0x02, 0x00, 0x55, 0x40, 0x19, 0x00, 0x01, 0x2C, 0x01, 0x00,
303
0x65, 0x23, 0x01, 0x00, 0x42, 0x42, 0x03, 0x00, 0x00, 0x2C, 0x01, 0x00, 0x24, 0x14, 0x01, 0x00,
304
0x00, 0x2C, 0x01, 0x00, 0x24, 0x14, 0x01, 0x00, 0x00, 0x3C, 0x01, 0x00, 0x42, 0x04, 0x09, 0x00,
305
0x42, 0xC3, 0x02, 0x00, 0x65, 0x54, 0x01, 0x00, 0x65, 0x55, 0x01, 0x00, 0x42, 0x45, 0x0D, 0x00,
306
0x62, 0x03, 0x00, 0x00, 0x62, 0x44, 0x00, 0x00, 0x62, 0x85, 0x00, 0x00, 0x62, 0xC2, 0x00, 0x00,
307
0x22, 0x48, 0x1F, 0x00, 0x6F, 0x00, 0x00, 0x00, 0x48, 0x00, 0x01, 0x00, 0x6C, 0x28, 0x02, 0x00,
308
0x62, 0x80, 0x01, 0x00, 0x60, 0x07, 0x00, 0x00, 0x60, 0x47, 0x00, 0x00, 0x60, 0x87, 0x00, 0x00,
309
0x01, 0x01, 0x00, 0x00, 0x43, 0x00, 0x02, 0x00, 0x40, 0x00, 0x02, 0x00, 0x01, 0xCA, 0x01, 0x00,
310
0x60, 0x03, 0x01, 0x00, 0x01, 0xA0, 0x01, 0x00, 0x60, 0x40, 0x00, 0x00, 0x65, 0x01, 0x00, 0x00,
311
0x55, 0xC0, 0x2E, 0x00, 0x01, 0x18, 0x00, 0x00, 0x43, 0x00, 0x04, 0x00, 0x43, 0x41, 0x06, 0x00,
312
0x6F, 0x00, 0x00, 0x00, 0x61, 0xC1, 0x00, 0x00, 0x61, 0x42, 0x01, 0x00, 0x65, 0xB5, 0x00, 0x00,
313
0x65, 0x73, 0x01, 0x00, 0x65, 0x35, 0x01, 0x00, 0x65, 0x34, 0x01, 0x00, 0x42, 0x04, 0x0D, 0x00,
314
0x01, 0x14, 0x01, 0x00, 0x42, 0x04, 0x03, 0x00, 0x00, 0x20, 0x00, 0x00, 0x43, 0x03, 0x05, 0x00,
315
0x43, 0x85, 0x02, 0x00, 0x00, 0xAA, 0x00, 0x00, 0x48, 0x46, 0x01, 0x00, 0x65, 0xEB, 0x00, 0x00,
316
0x00, 0x9A, 0x00, 0x00, 0x65, 0xB2, 0x01, 0x00, 0x00, 0xA6, 0x01, 0x00, 0x42, 0x86, 0x0D, 0x00,
317
0x61, 0x42, 0x01, 0x00, 0x01, 0xAE, 0x01, 0x00, 0x00, 0x71, 0x00, 0x00, 0x42, 0x82, 0x08, 0x00,
318
0x42, 0xC3, 0x08, 0x00, 0x48, 0x40, 0x01, 0x00, 0x6F, 0x00, 0x00, 0x00, 0x6E, 0x34, 0x02, 0x00,
319
0x65, 0x79, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x6C, 0x36, 0x04, 0x00, 0x6E, 0x34, 0x02, 0x00,
320
0x48, 0x7F, 0x01, 0x00, 0x6C, 0x0A, 0x06, 0x00, 0x6E, 0x34, 0x02, 0x00, 0x6E, 0x05, 0x04, 0x00,
321
0x65, 0x79, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x41, 0x87, 0x03, 0x00, 0x65, 0xBA, 0x00, 0x00,
322
0x65, 0xB2, 0x00, 0x00, 0x42, 0x82, 0x02, 0x00, 0x00, 0x51, 0x00, 0x00, 0x61, 0xC1, 0x00, 0x00,
323
0x65, 0xFB, 0x00, 0x00, 0x65, 0xF3, 0x00, 0x00, 0x41, 0x87, 0x05, 0x00, 0x65, 0xF3, 0x00, 0x00,
324
0x42, 0xC3, 0x08, 0x00, 0x00, 0x59, 0x00, 0x00, 0x60, 0xC7, 0x00, 0x00, 0x60, 0xC7, 0x00, 0x00,
325
0x56, 0xC0, 0x21, 0x00, 0x04, 0xDF, 0x01, 0x00, 0x43, 0xC7, 0x15, 0x00, 0x00, 0x38, 0x00, 0x00,
326
0x00, 0x79, 0x00, 0x00, 0x42, 0xC3, 0x20, 0x00, 0x43, 0xC3, 0x04, 0x00, 0x42, 0x00, 0x30, 0x00,
327
0x42, 0x41, 0x30, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x4B, 0x00, 0x00, 0x60, 0xC7, 0x01, 0x00,
328
0x22, 0x78, 0x01, 0x00, 0x22, 0x79, 0x03, 0x00, 0x22, 0x7F, 0x1F, 0x00, 0x6F, 0x00, 0x00, 0x00,
329
0x6E, 0x34, 0x02, 0x00, 0x6E, 0x05, 0x04, 0x00, 0x4B, 0x41, 0x00, 0x00, 0x60, 0xC7, 0x01, 0x00,
330
0x60, 0x87, 0x01, 0x00, 0x43, 0x86, 0x15, 0x00, 0x00, 0x30, 0x00, 0x00, 0x65, 0x39, 0x01, 0x00,
331
0x42, 0x04, 0x05, 0x00, 0x4E, 0x05, 0x7E, 0x00, 0x6A, 0x1B, 0x06, 0x00, 0x55, 0xC0, 0x3D, 0x00,
332
0x0A, 0x3C, 0x01, 0x00, 0x60, 0xC7, 0x01, 0x00, 0x22, 0x78, 0x01, 0x00, 0x22, 0x79, 0x03, 0x00,
333
0x22, 0x7C, 0x09, 0x00, 0x22, 0x7F, 0x1F, 0x00, 0x6F, 0x00, 0x00, 0x00, 0x65, 0x7A, 0x01, 0x00,
334
0x42, 0x45, 0x05, 0x00, 0x65, 0xBB, 0x01, 0x00, 0x42, 0x86, 0x05, 0x00, 0x55, 0xC0, 0x3D, 0x00,
335
0x0A, 0x7D, 0x01, 0x00, 0x0A, 0xBE, 0x01, 0x00, 0x07, 0xC7, 0x01, 0x00, 0x0B, 0x7D, 0x01, 0x00,
336
0x0B, 0xBE, 0x01, 0x00, 0x55, 0xC0, 0x3D, 0x00, 0x0A, 0x3C, 0x01, 0x00, 0x60, 0xC7, 0x01, 0x00,
337
0x22, 0x78, 0x01, 0x00, 0x22, 0x79, 0x03, 0x00, 0x22, 0x7A, 0x05, 0x00, 0x22, 0x7B, 0x07, 0x00,
338
0x22, 0x7C, 0x09, 0x00, 0x22, 0x7D, 0x0B, 0x00, 0x22, 0x7E, 0x0D, 0x00, 0x22, 0x7F, 0x1F, 0x00,
339
0x6F, 0x00, 0x00, 0x00
340
};
341
342
vic_config_t __attribute__((aligned (0x100))) vic_cfg = {0};
343
344
u32 _vic_read_priv(u32 addr)
345
{
346
u32 addr_lsb = addr & 0xFF;
347
348
// Set address LSB.
349
if (addr_lsb)
350
VIC(PVIC_FALCON_ADDR) = addr_lsb >> 2;
351
352
// Set address.
353
u32 val = VIC(PVIC_FALCON_PA_OFFSET + (addr >> 6));
354
355
// Unset address LSB.
356
if (addr_lsb)
357
VIC(PVIC_FALCON_ADDR) = 0;
358
359
return val;
360
}
361
362
static void _vic_write_priv(u32 addr, u32 data)
363
{
364
u32 addr_lsb = addr & 0xFF;
365
366
// Set address LSB.
367
if (addr_lsb)
368
VIC(PVIC_FALCON_ADDR) = addr_lsb >> 2;
369
370
// Set address.
371
VIC(PVIC_FALCON_PA_OFFSET + (addr >> 6)) = data;
372
373
// Unset address LSB.
374
if (addr_lsb)
375
VIC(PVIC_FALCON_ADDR) = 0;
376
}
377
378
int vic_wait_idle()
379
{
380
u32 timeout_count = 15000; // 150ms.
381
382
while (VIC(PVIC_FALCON_IDLESTATE))
383
{
384
usleep(10);
385
386
timeout_count--;
387
if (!timeout_count)
388
return 1;
389
};
390
391
return 0;
392
}
393
394
void vic_set_surface(const vic_surface_t *sfc)
395
{
396
u32 flip_x = 0;
397
u32 flip_y = 0;
398
u32 swap_xy = 0;
399
u32 const_alpha = 0;
400
401
u32 width = sfc->width;
402
u32 height = sfc->height;
403
u32 pix_fmt = sfc->pix_fmt;
404
u32 src_buf = sfc->src_buf;
405
u32 dst_buf = sfc->dst_buf;
406
407
// Get format alpha type.
408
switch (sfc->pix_fmt)
409
{
410
case VIC_PIX_FORMAT_L8:
411
case VIC_PIX_FORMAT_X1B5G5R5:
412
case VIC_PIX_FORMAT_B5G5R5X1:
413
case VIC_PIX_FORMAT_X8B8G8R8:
414
case VIC_PIX_FORMAT_X8R8G8B8:
415
case VIC_PIX_FORMAT_B8G8R8X8:
416
case VIC_PIX_FORMAT_R8G8B8X8:
417
const_alpha = 1;
418
break;
419
420
case VIC_PIX_FORMAT_A8B8G8R8:
421
case VIC_PIX_FORMAT_A8R8G8B8:
422
case VIC_PIX_FORMAT_B8G8R8A8:
423
case VIC_PIX_FORMAT_R8G8B8A8:
424
default:
425
break;
426
}
427
428
// Get rotation parameters.
429
switch (sfc->rotation)
430
{
431
case VIC_ROTATION_90:
432
swap_xy = 1;
433
break;
434
435
case VIC_ROTATION_180:
436
flip_x = 1;
437
flip_y = 1;
438
break;
439
440
case VIC_ROTATION_270:
441
flip_x = 1;
442
swap_xy = 1;
443
break;
444
445
case VIC_ROTATION_0:
446
default:
447
break;
448
}
449
450
// Set output surface format.
451
vic_cfg.out_sfc_cfg.OutPixelFormat = pix_fmt;
452
vic_cfg.out_sfc_cfg.OutBlkKind = BLK_KIND_PITCH;
453
vic_cfg.out_sfc_cfg.OutBlkHeight = 0;
454
455
// Set output rotation/flip.
456
vic_cfg.out_cfg.OutputFlipX = flip_x;
457
vic_cfg.out_cfg.OutputFlipY = flip_y;
458
vic_cfg.out_cfg.OutputTranspose = swap_xy;
459
460
// Set output surface resolution.
461
vic_cfg.out_sfc_cfg.OutSurfaceWidth = width - 1;
462
vic_cfg.out_sfc_cfg.OutSurfaceHeight = height - 1;
463
vic_cfg.out_sfc_cfg.OutLumaWidth = width - 1;
464
vic_cfg.out_sfc_cfg.OutLumaHeight = height - 1;
465
466
// Set output destination rectangle. Anything outside will not be touched at output buffer.
467
vic_cfg.out_cfg.TargetRectLeft = 0;
468
vic_cfg.out_cfg.TargetRectRight = width - 1;
469
vic_cfg.out_cfg.TargetRectTop = 0;
470
vic_cfg.out_cfg.TargetRectBottom = height - 1;
471
472
// Initialize slot parameters.
473
vic_cfg.slots[0].slot_cfg.SlotEnable = 1;
474
vic_cfg.slots[0].slot_cfg.SoftClampLow = SOFT_CLAMP_MIN;
475
vic_cfg.slots[0].slot_cfg.SoftClampHigh = SOFT_CLAMP_MAX;
476
vic_cfg.slots[0].slot_cfg.PlanarAlpha = ALPHA_1_0;
477
vic_cfg.slots[0].slot_cfg.ConstantAlpha = const_alpha;
478
vic_cfg.slots[0].slot_cfg.FrameFormat = FORMAT_PROGRESSIVE;
479
480
// Set input source rectangle.
481
vic_cfg.slots[0].slot_cfg.SourceRectLeft = 0;
482
vic_cfg.slots[0].slot_cfg.SourceRectRight = (width - 1) << 16;
483
vic_cfg.slots[0].slot_cfg.SourceRectTop = 0;
484
vic_cfg.slots[0].slot_cfg.SourceRectBottom = (height - 1) << 16;
485
486
// Set input destination rectangle.
487
vic_cfg.slots[0].slot_cfg.DestRectLeft = 0;
488
vic_cfg.slots[0].slot_cfg.DestRectRight = (width - 1);
489
vic_cfg.slots[0].slot_cfg.DestRectTop = 0;
490
vic_cfg.slots[0].slot_cfg.DestRectBottom = (height - 1);
491
492
// Set input surface format.
493
vic_cfg.slots[0].slot_sfc_cfg.SlotPixelFormat = pix_fmt;
494
vic_cfg.slots[0].slot_sfc_cfg.SlotBlkKind = BLK_KIND_PITCH;
495
vic_cfg.slots[0].slot_sfc_cfg.SlotBlkHeight = 0;
496
vic_cfg.slots[0].slot_sfc_cfg.SlotCacheWidth = CACHE_WIDTH_64BX4;
497
498
// Set input surface resolution.
499
vic_cfg.slots[0].slot_sfc_cfg.SlotSurfaceWidth = width - 1;
500
vic_cfg.slots[0].slot_sfc_cfg.SlotSurfaceHeight = height - 1;
501
vic_cfg.slots[0].slot_sfc_cfg.SlotLumaWidth = width - 1;
502
vic_cfg.slots[0].slot_sfc_cfg.SlotLumaHeight = height - 1;
503
504
// Flush data.
505
bpmp_mmu_maintenance(BPMP_MMU_MAINT_CLEAN_WAY, false);
506
507
// Set parameters base and size. Causes a parse by surface cache.
508
_vic_write_priv(VIC_SC_PRAMBASE, (u32)&vic_cfg >> 8);
509
_vic_write_priv(VIC_SC_PRAMSIZE, sizeof(vic_config_t) >> 6);
510
511
// Wait for surface cache to get ready.
512
vic_wait_idle();
513
514
// Set slot mapping.
515
_vic_write_priv(VIC_FC_SLOT_MAP, 0xFFFFFFF0);
516
517
// Set input surface buffer.
518
_vic_write_priv(VIC_SC_SFC0_BASE_LUMA(0), src_buf >> 8);
519
520
// Set output surface buffer.
521
_vic_write_priv(VIC_BL_TARGET_BASADR, dst_buf >> 8);
522
523
// Set blending config and push changes to surface cache.
524
_vic_write_priv(VIC_BL_CONFIG, SLOTMASK(0x1F) | PROCESS_CFG_STRUCT_TRIGGER | SUBPARTITION_MODE);
525
526
// Wait for surface cache to get ready.
527
vic_wait_idle();
528
}
529
530
int vic_compose()
531
{
532
// Wait for surface cache to get ready. Otherwise VIC will hang.
533
int res = vic_wait_idle();
534
535
// Start composition of a single frame.
536
_vic_write_priv(VIC_FC_COMPOSE, COMPOSE_START);
537
538
return res;
539
}
540
541
int vic_init()
542
{
543
clock_enable_vic();
544
545
// Load Fetch Control Engine microcode.
546
for (u32 i = 0; i < sizeof(vic_fce_ucode) / sizeof(u32); i++)
547
{
548
_vic_write_priv(VIC_FC_FCE_UCODE_ADDR, (i * sizeof(u32)));
549
_vic_write_priv(VIC_FC_FCE_UCODE_INST, *(u32 *)&vic_fce_ucode[i * sizeof(u32)]);
550
}
551
552
// Start Fetch Control Engine.
553
_vic_write_priv(VIC_FC_FCE_CTRL, START_TRIGGER);
554
555
return vic_wait_idle();
556
}
557
558
void vic_end()
559
{
560
clock_disable_vic();
561
}
562
563