xref: /third_party/libdrm/tests/tegra/vic30.c (revision d722e3fb)
1d722e3fbSopenharmony_ci/*
2d722e3fbSopenharmony_ci * Copyright © 2018 NVIDIA Corporation
3d722e3fbSopenharmony_ci *
4d722e3fbSopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
5d722e3fbSopenharmony_ci * copy of this software and associated documentation files (the "Software"),
6d722e3fbSopenharmony_ci * to deal in the Software without restriction, including without limitation
7d722e3fbSopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8d722e3fbSopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
9d722e3fbSopenharmony_ci * Software is furnished to do so, subject to the following conditions:
10d722e3fbSopenharmony_ci *
11d722e3fbSopenharmony_ci * The above copyright notice and this permission notice shall be included in
12d722e3fbSopenharmony_ci * all copies or substantial portions of the Software.
13d722e3fbSopenharmony_ci *
14d722e3fbSopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15d722e3fbSopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16d722e3fbSopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17d722e3fbSopenharmony_ci * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18d722e3fbSopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19d722e3fbSopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20d722e3fbSopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE.
21d722e3fbSopenharmony_ci */
22d722e3fbSopenharmony_ci
23d722e3fbSopenharmony_ci#include <errno.h>
24d722e3fbSopenharmony_ci#include <string.h>
25d722e3fbSopenharmony_ci
26d722e3fbSopenharmony_ci#include "private.h"
27d722e3fbSopenharmony_ci#include "tegra.h"
28d722e3fbSopenharmony_ci#include "vic.h"
29d722e3fbSopenharmony_ci#include "vic30.h"
30d722e3fbSopenharmony_ci
31d722e3fbSopenharmony_cistruct vic30 {
32d722e3fbSopenharmony_ci    struct vic base;
33d722e3fbSopenharmony_ci
34d722e3fbSopenharmony_ci    struct {
35d722e3fbSopenharmony_ci        struct drm_tegra_mapping *map;
36d722e3fbSopenharmony_ci        struct drm_tegra_bo *bo;
37d722e3fbSopenharmony_ci    } config;
38d722e3fbSopenharmony_ci
39d722e3fbSopenharmony_ci    struct {
40d722e3fbSopenharmony_ci        struct drm_tegra_mapping *map;
41d722e3fbSopenharmony_ci        struct drm_tegra_bo *bo;
42d722e3fbSopenharmony_ci    } filter;
43d722e3fbSopenharmony_ci
44d722e3fbSopenharmony_ci    struct {
45d722e3fbSopenharmony_ci        struct drm_tegra_mapping *map;
46d722e3fbSopenharmony_ci        struct drm_tegra_bo *bo;
47d722e3fbSopenharmony_ci    } hist;
48d722e3fbSopenharmony_ci};
49d722e3fbSopenharmony_ci
50d722e3fbSopenharmony_cistatic int vic30_fill(struct vic *v, struct vic_image *output,
51d722e3fbSopenharmony_ci                      unsigned int left, unsigned int top,
52d722e3fbSopenharmony_ci                      unsigned int right, unsigned int bottom,
53d722e3fbSopenharmony_ci                      unsigned int alpha, unsigned int red,
54d722e3fbSopenharmony_ci                      unsigned int green, unsigned int blue)
55d722e3fbSopenharmony_ci{
56d722e3fbSopenharmony_ci    struct vic30 *vic = container_of(v, struct vic30, base);
57d722e3fbSopenharmony_ci    ConfigStruct *c;
58d722e3fbSopenharmony_ci    int err;
59d722e3fbSopenharmony_ci
60d722e3fbSopenharmony_ci    err = drm_tegra_bo_map(vic->config.bo, (void **)&c);
61d722e3fbSopenharmony_ci    if (err < 0) {
62d722e3fbSopenharmony_ci        fprintf(stderr, "failed to map configuration structure: %s\n",
63d722e3fbSopenharmony_ci                strerror(-err));
64d722e3fbSopenharmony_ci        return err;
65d722e3fbSopenharmony_ci    }
66d722e3fbSopenharmony_ci
67d722e3fbSopenharmony_ci    memset(c, 0, sizeof(*c));
68d722e3fbSopenharmony_ci
69d722e3fbSopenharmony_ci    c->surfaceList0Struct.TargetRectLeft = left;
70d722e3fbSopenharmony_ci    c->surfaceList0Struct.TargetRectTop = top;
71d722e3fbSopenharmony_ci    c->surfaceList0Struct.TargetRectRight = right;
72d722e3fbSopenharmony_ci    c->surfaceList0Struct.TargetRectBottom = bottom;
73d722e3fbSopenharmony_ci
74d722e3fbSopenharmony_ci    c->blending0Struct.PixelFormat = output->format;
75d722e3fbSopenharmony_ci    c->blending0Struct.BackgroundAlpha = alpha;
76d722e3fbSopenharmony_ci    c->blending0Struct.BackgroundR = red;
77d722e3fbSopenharmony_ci    c->blending0Struct.BackgroundG = green;
78d722e3fbSopenharmony_ci    c->blending0Struct.BackgroundB = blue;
79d722e3fbSopenharmony_ci    c->blending0Struct.LumaWidth = output->stride - 1;
80d722e3fbSopenharmony_ci    c->blending0Struct.LumaHeight = output->height - 1;
81d722e3fbSopenharmony_ci    c->blending0Struct.ChromaWidth = 16383;
82d722e3fbSopenharmony_ci    c->blending0Struct.ChromaWidth = 16383;
83d722e3fbSopenharmony_ci    c->blending0Struct.TargetRectLeft = left;
84d722e3fbSopenharmony_ci    c->blending0Struct.TargetRectTop = top;
85d722e3fbSopenharmony_ci    c->blending0Struct.TargetRectRight = right;
86d722e3fbSopenharmony_ci    c->blending0Struct.TargetRectBottom = bottom;
87d722e3fbSopenharmony_ci    c->blending0Struct.SurfaceWidth = output->width - 1;
88d722e3fbSopenharmony_ci    c->blending0Struct.SurfaceHeight = output->height - 1;
89d722e3fbSopenharmony_ci    c->blending0Struct.BlkKind = output->kind;
90d722e3fbSopenharmony_ci    c->blending0Struct.BlkHeight = 0;
91d722e3fbSopenharmony_ci
92d722e3fbSopenharmony_ci    c->fetchControl0Struct.TargetRectLeft = left;
93d722e3fbSopenharmony_ci    c->fetchControl0Struct.TargetRectTop = top;
94d722e3fbSopenharmony_ci    c->fetchControl0Struct.TargetRectRight = right;
95d722e3fbSopenharmony_ci    c->fetchControl0Struct.TargetRectBottom = bottom;
96d722e3fbSopenharmony_ci
97d722e3fbSopenharmony_ci    drm_tegra_bo_unmap(vic->config.bo);
98d722e3fbSopenharmony_ci
99d722e3fbSopenharmony_ci    return 0;
100d722e3fbSopenharmony_ci}
101d722e3fbSopenharmony_ci
102d722e3fbSopenharmony_cistatic int vic30_blit(struct vic *v, struct vic_image *output,
103d722e3fbSopenharmony_ci                      struct vic_image *input)
104d722e3fbSopenharmony_ci{
105d722e3fbSopenharmony_ci    struct vic30 *vic = container_of(v, struct vic30, base);
106d722e3fbSopenharmony_ci    ColorConversionLumaAlphaStruct *ccla;
107d722e3fbSopenharmony_ci    ColorConversionMatrixStruct *ccm;
108d722e3fbSopenharmony_ci    ColorConversionClampStruct *ccc;
109d722e3fbSopenharmony_ci    SurfaceListSurfaceStruct *s;
110d722e3fbSopenharmony_ci    BlendingSurfaceStruct *b;
111d722e3fbSopenharmony_ci    SurfaceCache0Struct *sc;
112d722e3fbSopenharmony_ci    ConfigStruct *c;
113d722e3fbSopenharmony_ci    int err;
114d722e3fbSopenharmony_ci
115d722e3fbSopenharmony_ci    err = drm_tegra_bo_map(vic->config.bo, (void **)&c);
116d722e3fbSopenharmony_ci    if (err < 0) {
117d722e3fbSopenharmony_ci        fprintf(stderr, "failed to map configuration structure: %s\n",
118d722e3fbSopenharmony_ci                strerror(-err));
119d722e3fbSopenharmony_ci        return err;
120d722e3fbSopenharmony_ci    }
121d722e3fbSopenharmony_ci
122d722e3fbSopenharmony_ci    memset(c, 0, sizeof(*c));
123d722e3fbSopenharmony_ci
124d722e3fbSopenharmony_ci    c->surfaceList0Struct.TargetRectLeft = 0;
125d722e3fbSopenharmony_ci    c->surfaceList0Struct.TargetRectTop = 0;
126d722e3fbSopenharmony_ci    c->surfaceList0Struct.TargetRectRight = output->width - 1;
127d722e3fbSopenharmony_ci    c->surfaceList0Struct.TargetRectBottom = output->height - 1;
128d722e3fbSopenharmony_ci
129d722e3fbSopenharmony_ci    c->blending0Struct.PixelFormat = output->format;
130d722e3fbSopenharmony_ci    c->blending0Struct.BackgroundAlpha = 0;
131d722e3fbSopenharmony_ci    c->blending0Struct.BackgroundR = 0;
132d722e3fbSopenharmony_ci    c->blending0Struct.BackgroundG = 0;
133d722e3fbSopenharmony_ci    c->blending0Struct.BackgroundB = 0;
134d722e3fbSopenharmony_ci    c->blending0Struct.LumaWidth = output->stride - 1;
135d722e3fbSopenharmony_ci    c->blending0Struct.LumaHeight = output->height - 1;
136d722e3fbSopenharmony_ci    c->blending0Struct.ChromaWidth = 16383;
137d722e3fbSopenharmony_ci    c->blending0Struct.ChromaWidth = 16383;
138d722e3fbSopenharmony_ci    c->blending0Struct.TargetRectLeft = 0;
139d722e3fbSopenharmony_ci    c->blending0Struct.TargetRectTop = 0;
140d722e3fbSopenharmony_ci    c->blending0Struct.TargetRectRight = output->width - 1;
141d722e3fbSopenharmony_ci    c->blending0Struct.TargetRectBottom = output->height - 1;
142d722e3fbSopenharmony_ci    c->blending0Struct.SurfaceWidth = output->width - 1;
143d722e3fbSopenharmony_ci    c->blending0Struct.SurfaceHeight = output->height - 1;
144d722e3fbSopenharmony_ci    c->blending0Struct.BlkKind = output->kind;
145d722e3fbSopenharmony_ci    c->blending0Struct.BlkHeight = 0;
146d722e3fbSopenharmony_ci
147d722e3fbSopenharmony_ci    c->fetchControl0Struct.TargetRectLeft = 0;
148d722e3fbSopenharmony_ci    c->fetchControl0Struct.TargetRectTop = 0;
149d722e3fbSopenharmony_ci    c->fetchControl0Struct.TargetRectRight = output->width - 1;
150d722e3fbSopenharmony_ci    c->fetchControl0Struct.TargetRectBottom = output->height - 1;
151d722e3fbSopenharmony_ci
152d722e3fbSopenharmony_ci    /* setup fetch parameters for slot 0 */
153d722e3fbSopenharmony_ci    c->fetchControl0Struct.Enable0 = 0x1;
154d722e3fbSopenharmony_ci    c->fetchControl0Struct.Iir0 = 0x300;
155d722e3fbSopenharmony_ci
156d722e3fbSopenharmony_ci    /* setup cache parameters for slot 0 */
157d722e3fbSopenharmony_ci    sc = &c->surfaceCache0Struct;
158d722e3fbSopenharmony_ci    sc->PixelFormat0 = input->format;
159d722e3fbSopenharmony_ci
160d722e3fbSopenharmony_ci    /* setup surface configuration for slot 0 */
161d722e3fbSopenharmony_ci    s = &c->surfaceListSurfaceStruct[0];
162d722e3fbSopenharmony_ci    s->Enable = 1;
163d722e3fbSopenharmony_ci    s->FrameFormat = DXVAHD_FRAME_FORMAT_PROGRESSIVE;
164d722e3fbSopenharmony_ci    s->PixelFormat = input->format;
165d722e3fbSopenharmony_ci    s->SurfaceWidth = input->width - 1;
166d722e3fbSopenharmony_ci    s->SurfaceHeight = input->height - 1;
167d722e3fbSopenharmony_ci    s->LumaWidth = input->stride - 1;
168d722e3fbSopenharmony_ci    s->LumaHeight = input->height - 1;
169d722e3fbSopenharmony_ci    s->ChromaWidth = 16383;
170d722e3fbSopenharmony_ci    s->ChromaHeight = 16383;
171d722e3fbSopenharmony_ci    s->CacheWidth = VIC_CACHE_WIDTH_256Bx1; //VIC_CACHE_WIDTH_16Bx16;
172d722e3fbSopenharmony_ci    s->BlkKind = input->kind;
173d722e3fbSopenharmony_ci    s->BlkHeight = 0;
174d722e3fbSopenharmony_ci    s->DestRectLeft = 0;
175d722e3fbSopenharmony_ci    s->DestRectTop = 0;
176d722e3fbSopenharmony_ci    s->DestRectRight = output->width - 1;
177d722e3fbSopenharmony_ci    s->DestRectBottom = output->height - 1;
178d722e3fbSopenharmony_ci    s->SourceRectLeft = 0 << 16;
179d722e3fbSopenharmony_ci    s->SourceRectTop = 0 << 16;
180d722e3fbSopenharmony_ci    s->SourceRectRight = (input->width - 1) << 16;
181d722e3fbSopenharmony_ci    s->SourceRectBottom = (input->height - 1) << 16;
182d722e3fbSopenharmony_ci
183d722e3fbSopenharmony_ci    /* setup color conversion for slot 0 */
184d722e3fbSopenharmony_ci    ccla = &c->colorConversionLumaAlphaStruct[0];
185d722e3fbSopenharmony_ci    ccla->PlanarAlpha = 1023;
186d722e3fbSopenharmony_ci    ccla->ConstantAlpha = 0;
187d722e3fbSopenharmony_ci
188d722e3fbSopenharmony_ci    ccm = &c->colorConversionMatrixStruct[0];
189d722e3fbSopenharmony_ci    ccm->c00 = 1023;
190d722e3fbSopenharmony_ci    ccm->c11 = 1023;
191d722e3fbSopenharmony_ci    ccm->c22 = 1023;
192d722e3fbSopenharmony_ci
193d722e3fbSopenharmony_ci    ccc = &c->colorConversionClampStruct[0];
194d722e3fbSopenharmony_ci    ccc->low = 0;
195d722e3fbSopenharmony_ci    ccc->high = 1023;
196d722e3fbSopenharmony_ci
197d722e3fbSopenharmony_ci    /* setup blending for slot 0 */
198d722e3fbSopenharmony_ci    b = &c->blendingSurfaceStruct[0];
199d722e3fbSopenharmony_ci    b->AlphaK1 = 1023;
200d722e3fbSopenharmony_ci    b->SrcFactCMatchSelect = VIC_BLEND_SRCFACTC_K1;
201d722e3fbSopenharmony_ci    b->SrcFactAMatchSelect = VIC_BLEND_SRCFACTA_K1;
202d722e3fbSopenharmony_ci    b->DstFactCMatchSelect = VIC_BLEND_DSTFACTC_NEG_K1_TIMES_SRC;
203d722e3fbSopenharmony_ci    b->DstFactAMatchSelect = VIC_BLEND_DSTFACTA_NEG_K1_TIMES_SRC;
204d722e3fbSopenharmony_ci
205d722e3fbSopenharmony_ci    drm_tegra_bo_unmap(vic->config.bo);
206d722e3fbSopenharmony_ci
207d722e3fbSopenharmony_ci    return 0;
208d722e3fbSopenharmony_ci}
209d722e3fbSopenharmony_ci
210d722e3fbSopenharmony_cistatic int vic30_flip(struct vic *v, struct vic_image *output,
211d722e3fbSopenharmony_ci                      struct vic_image *input)
212d722e3fbSopenharmony_ci{
213d722e3fbSopenharmony_ci    struct vic30 *vic = container_of(v, struct vic30, base);
214d722e3fbSopenharmony_ci    ColorConversionLumaAlphaStruct *ccla;
215d722e3fbSopenharmony_ci    ColorConversionMatrixStruct *ccm;
216d722e3fbSopenharmony_ci    ColorConversionClampStruct *ccc;
217d722e3fbSopenharmony_ci    SurfaceListSurfaceStruct *s;
218d722e3fbSopenharmony_ci    BlendingSurfaceStruct *b;
219d722e3fbSopenharmony_ci    SurfaceCache0Struct *sc;
220d722e3fbSopenharmony_ci    ConfigStruct *c;
221d722e3fbSopenharmony_ci    int err;
222d722e3fbSopenharmony_ci
223d722e3fbSopenharmony_ci    err = drm_tegra_bo_map(vic->config.bo, (void **)&c);
224d722e3fbSopenharmony_ci    if (err < 0) {
225d722e3fbSopenharmony_ci        fprintf(stderr, "failed to map configuration structure: %s\n",
226d722e3fbSopenharmony_ci                strerror(-err));
227d722e3fbSopenharmony_ci        return err;
228d722e3fbSopenharmony_ci    }
229d722e3fbSopenharmony_ci
230d722e3fbSopenharmony_ci    memset(c, 0, sizeof(*c));
231d722e3fbSopenharmony_ci
232d722e3fbSopenharmony_ci    c->surfaceList0Struct.TargetRectLeft = 0;
233d722e3fbSopenharmony_ci    c->surfaceList0Struct.TargetRectTop = 0;
234d722e3fbSopenharmony_ci    c->surfaceList0Struct.TargetRectRight = output->width - 1;
235d722e3fbSopenharmony_ci    c->surfaceList0Struct.TargetRectBottom = output->height - 1;
236d722e3fbSopenharmony_ci
237d722e3fbSopenharmony_ci    c->blending0Struct.PixelFormat = output->format;
238d722e3fbSopenharmony_ci    c->blending0Struct.BackgroundAlpha = 0;
239d722e3fbSopenharmony_ci    c->blending0Struct.BackgroundR = 0;
240d722e3fbSopenharmony_ci    c->blending0Struct.BackgroundG = 0;
241d722e3fbSopenharmony_ci    c->blending0Struct.BackgroundB = 0;
242d722e3fbSopenharmony_ci    c->blending0Struct.LumaWidth = output->stride - 1;
243d722e3fbSopenharmony_ci    c->blending0Struct.LumaHeight = output->height - 1;
244d722e3fbSopenharmony_ci    c->blending0Struct.ChromaWidth = 16383;
245d722e3fbSopenharmony_ci    c->blending0Struct.ChromaWidth = 16383;
246d722e3fbSopenharmony_ci    c->blending0Struct.TargetRectLeft = 0;
247d722e3fbSopenharmony_ci    c->blending0Struct.TargetRectTop = 0;
248d722e3fbSopenharmony_ci    c->blending0Struct.TargetRectRight = output->width - 1;
249d722e3fbSopenharmony_ci    c->blending0Struct.TargetRectBottom = output->height - 1;
250d722e3fbSopenharmony_ci    c->blending0Struct.SurfaceWidth = output->width - 1;
251d722e3fbSopenharmony_ci    c->blending0Struct.SurfaceHeight = output->height - 1;
252d722e3fbSopenharmony_ci    c->blending0Struct.BlkKind = output->kind;
253d722e3fbSopenharmony_ci    c->blending0Struct.BlkHeight = 0;
254d722e3fbSopenharmony_ci    c->blending0Struct.OutputFlipY = 1;
255d722e3fbSopenharmony_ci
256d722e3fbSopenharmony_ci    c->fetchControl0Struct.TargetRectLeft = 0;
257d722e3fbSopenharmony_ci    c->fetchControl0Struct.TargetRectTop = 0;
258d722e3fbSopenharmony_ci    c->fetchControl0Struct.TargetRectRight = output->width - 1;
259d722e3fbSopenharmony_ci    c->fetchControl0Struct.TargetRectBottom = output->height - 1;
260d722e3fbSopenharmony_ci
261d722e3fbSopenharmony_ci    /* setup fetch parameters for slot 0 */
262d722e3fbSopenharmony_ci    c->fetchControl0Struct.Enable0 = 0x1;
263d722e3fbSopenharmony_ci    c->fetchControl0Struct.Iir0 = 0x300;
264d722e3fbSopenharmony_ci
265d722e3fbSopenharmony_ci    /* setup cache parameters for slot 0 */
266d722e3fbSopenharmony_ci    sc = &c->surfaceCache0Struct;
267d722e3fbSopenharmony_ci    sc->PixelFormat0 = input->format;
268d722e3fbSopenharmony_ci
269d722e3fbSopenharmony_ci    /* setup surface configuration for slot 0 */
270d722e3fbSopenharmony_ci    s = &c->surfaceListSurfaceStruct[0];
271d722e3fbSopenharmony_ci    s->Enable = 1;
272d722e3fbSopenharmony_ci    s->FrameFormat = DXVAHD_FRAME_FORMAT_PROGRESSIVE;
273d722e3fbSopenharmony_ci    s->PixelFormat = input->format;
274d722e3fbSopenharmony_ci    s->SurfaceWidth = input->width - 1;
275d722e3fbSopenharmony_ci    s->SurfaceHeight = input->height - 1;
276d722e3fbSopenharmony_ci    s->LumaWidth = input->stride - 1;
277d722e3fbSopenharmony_ci    s->LumaHeight = input->height - 1;
278d722e3fbSopenharmony_ci    s->ChromaWidth = 16383;
279d722e3fbSopenharmony_ci    s->ChromaHeight = 16383;
280d722e3fbSopenharmony_ci    s->CacheWidth = VIC_CACHE_WIDTH_256Bx1;
281d722e3fbSopenharmony_ci    s->BlkKind = input->kind;
282d722e3fbSopenharmony_ci    s->BlkHeight = 0;
283d722e3fbSopenharmony_ci    s->DestRectLeft = 0;
284d722e3fbSopenharmony_ci    s->DestRectTop = 0;
285d722e3fbSopenharmony_ci    s->DestRectRight = output->width - 1;
286d722e3fbSopenharmony_ci    s->DestRectBottom = output->height - 1;
287d722e3fbSopenharmony_ci    s->SourceRectLeft = 0 << 16;
288d722e3fbSopenharmony_ci    s->SourceRectTop = 0 << 16;
289d722e3fbSopenharmony_ci    s->SourceRectRight = (input->width - 1) << 16;
290d722e3fbSopenharmony_ci    s->SourceRectBottom = (input->height - 1) << 16;
291d722e3fbSopenharmony_ci
292d722e3fbSopenharmony_ci    /* setup color conversion for slot 0 */
293d722e3fbSopenharmony_ci    ccla = &c->colorConversionLumaAlphaStruct[0];
294d722e3fbSopenharmony_ci    ccla->PlanarAlpha = 1023;
295d722e3fbSopenharmony_ci    ccla->ConstantAlpha = 0;
296d722e3fbSopenharmony_ci
297d722e3fbSopenharmony_ci    ccm = &c->colorConversionMatrixStruct[0];
298d722e3fbSopenharmony_ci    ccm->c00 = 1023;
299d722e3fbSopenharmony_ci    ccm->c11 = 1023;
300d722e3fbSopenharmony_ci    ccm->c22 = 1023;
301d722e3fbSopenharmony_ci
302d722e3fbSopenharmony_ci    ccc = &c->colorConversionClampStruct[0];
303d722e3fbSopenharmony_ci    ccc->low = 0;
304d722e3fbSopenharmony_ci    ccc->high = 1023;
305d722e3fbSopenharmony_ci
306d722e3fbSopenharmony_ci    /* setup blending for slot 0 */
307d722e3fbSopenharmony_ci    b = &c->blendingSurfaceStruct[0];
308d722e3fbSopenharmony_ci    b->AlphaK1 = 1023;
309d722e3fbSopenharmony_ci    b->SrcFactCMatchSelect = VIC_BLEND_SRCFACTC_K1;
310d722e3fbSopenharmony_ci    b->SrcFactAMatchSelect = VIC_BLEND_SRCFACTA_K1;
311d722e3fbSopenharmony_ci    b->DstFactCMatchSelect = VIC_BLEND_DSTFACTC_NEG_K1_TIMES_SRC;
312d722e3fbSopenharmony_ci    b->DstFactAMatchSelect = VIC_BLEND_DSTFACTA_NEG_K1_TIMES_SRC;
313d722e3fbSopenharmony_ci
314d722e3fbSopenharmony_ci    drm_tegra_bo_unmap(vic->config.bo);
315d722e3fbSopenharmony_ci
316d722e3fbSopenharmony_ci    return 0;
317d722e3fbSopenharmony_ci}
318d722e3fbSopenharmony_ci
319d722e3fbSopenharmony_cistatic int vic30_execute(struct vic *v, struct drm_tegra_pushbuf *pushbuf,
320d722e3fbSopenharmony_ci                         uint32_t **ptrp, struct vic_image *output,
321d722e3fbSopenharmony_ci                         struct vic_image **inputs, unsigned int num_inputs)
322d722e3fbSopenharmony_ci{
323d722e3fbSopenharmony_ci    struct vic30 *vic = container_of(v, struct vic30, base);
324d722e3fbSopenharmony_ci    unsigned int i;
325d722e3fbSopenharmony_ci
326d722e3fbSopenharmony_ci    if (num_inputs > 1)
327d722e3fbSopenharmony_ci        return -EINVAL;
328d722e3fbSopenharmony_ci
329d722e3fbSopenharmony_ci    VIC_PUSH_METHOD(pushbuf, ptrp, NVA0B6_VIDEO_COMPOSITOR_SET_APPLICATION_ID, 1);
330d722e3fbSopenharmony_ci    VIC_PUSH_METHOD(pushbuf, ptrp, NVA0B6_VIDEO_COMPOSITOR_SET_CONTROL_PARAMS, (sizeof(ConfigStruct) / 16) << 16);
331d722e3fbSopenharmony_ci    VIC_PUSH_BUFFER(pushbuf, ptrp, NVA0B6_VIDEO_COMPOSITOR_SET_CONFIG_STRUCT_OFFSET, vic->config.map, 0, 0);
332d722e3fbSopenharmony_ci    VIC_PUSH_BUFFER(pushbuf, ptrp, NVA0B6_VIDEO_COMPOSITOR_SET_HIST_OFFSET, vic->hist.map, 0, 0);
333d722e3fbSopenharmony_ci    VIC_PUSH_BUFFER(pushbuf, ptrp, NVA0B6_VIDEO_COMPOSITOR_SET_OUTPUT_SURFACE_LUMA_OFFSET, output->map, 0, 0);
334d722e3fbSopenharmony_ci
335d722e3fbSopenharmony_ci    for (i = 0; i < num_inputs; i++)
336d722e3fbSopenharmony_ci        VIC_PUSH_BUFFER(pushbuf, ptrp, NVA0B6_VIDEO_COMPOSITOR_SET_SURFACE0_SLOT0_LUMA_OFFSET, inputs[i]->map, 0, 0);
337d722e3fbSopenharmony_ci
338d722e3fbSopenharmony_ci    VIC_PUSH_METHOD(pushbuf, ptrp, NVA0B6_VIDEO_COMPOSITOR_EXECUTE, 1 << 8);
339d722e3fbSopenharmony_ci
340d722e3fbSopenharmony_ci    return 0;
341d722e3fbSopenharmony_ci}
342d722e3fbSopenharmony_ci
343d722e3fbSopenharmony_cistatic void vic30_free(struct vic *v)
344d722e3fbSopenharmony_ci{
345d722e3fbSopenharmony_ci    struct vic30 *vic = container_of(v, struct vic30, base);
346d722e3fbSopenharmony_ci
347d722e3fbSopenharmony_ci    drm_tegra_channel_unmap(vic->hist.map);
348d722e3fbSopenharmony_ci    drm_tegra_bo_unref(vic->hist.bo);
349d722e3fbSopenharmony_ci
350d722e3fbSopenharmony_ci    drm_tegra_channel_unmap(vic->filter.map);
351d722e3fbSopenharmony_ci    drm_tegra_bo_unref(vic->filter.bo);
352d722e3fbSopenharmony_ci
353d722e3fbSopenharmony_ci    drm_tegra_channel_unmap(vic->config.map);
354d722e3fbSopenharmony_ci    drm_tegra_bo_unref(vic->config.bo);
355d722e3fbSopenharmony_ci
356d722e3fbSopenharmony_ci    drm_tegra_syncpoint_free(v->syncpt);
357d722e3fbSopenharmony_ci
358d722e3fbSopenharmony_ci    free(vic);
359d722e3fbSopenharmony_ci}
360d722e3fbSopenharmony_ci
361d722e3fbSopenharmony_cistatic const struct vic_ops vic30_ops = {
362d722e3fbSopenharmony_ci    .fill = vic30_fill,
363d722e3fbSopenharmony_ci    .blit = vic30_blit,
364d722e3fbSopenharmony_ci    .flip = vic30_flip,
365d722e3fbSopenharmony_ci    .execute = vic30_execute,
366d722e3fbSopenharmony_ci    .free = vic30_free,
367d722e3fbSopenharmony_ci};
368d722e3fbSopenharmony_ci
369d722e3fbSopenharmony_ciint vic30_new(struct drm_tegra *drm, struct drm_tegra_channel *channel,
370d722e3fbSopenharmony_ci              struct vic **vicp)
371d722e3fbSopenharmony_ci{
372d722e3fbSopenharmony_ci    struct vic30 *vic;
373d722e3fbSopenharmony_ci    void *ptr;
374d722e3fbSopenharmony_ci    int err;
375d722e3fbSopenharmony_ci
376d722e3fbSopenharmony_ci    vic = calloc(1, sizeof(*vic));
377d722e3fbSopenharmony_ci    if (!vic)
378d722e3fbSopenharmony_ci        return -ENOMEM;
379d722e3fbSopenharmony_ci
380d722e3fbSopenharmony_ci    vic->base.drm = drm;
381d722e3fbSopenharmony_ci    vic->base.channel = channel;
382d722e3fbSopenharmony_ci    vic->base.ops = &vic30_ops;
383d722e3fbSopenharmony_ci    vic->base.version = 0x40;
384d722e3fbSopenharmony_ci
385d722e3fbSopenharmony_ci    err = drm_tegra_syncpoint_new(drm, &vic->base.syncpt);
386d722e3fbSopenharmony_ci    if (err < 0) {
387d722e3fbSopenharmony_ci        fprintf(stderr, "failed to allocate syncpoint: %s\n", strerror(-err));
388d722e3fbSopenharmony_ci        return err;
389d722e3fbSopenharmony_ci    }
390d722e3fbSopenharmony_ci
391d722e3fbSopenharmony_ci    err = drm_tegra_bo_new(drm, 0, 16384, &vic->config.bo);
392d722e3fbSopenharmony_ci    if (err < 0) {
393d722e3fbSopenharmony_ci        fprintf(stderr, "failed to allocate configuration structure: %s\n",
394d722e3fbSopenharmony_ci                strerror(-err));
395d722e3fbSopenharmony_ci        return err;
396d722e3fbSopenharmony_ci    }
397d722e3fbSopenharmony_ci
398d722e3fbSopenharmony_ci    err = drm_tegra_channel_map(channel, vic->config.bo, DRM_TEGRA_CHANNEL_MAP_READ,
399d722e3fbSopenharmony_ci                                &vic->config.map);
400d722e3fbSopenharmony_ci    if (err < 0) {
401d722e3fbSopenharmony_ci        fprintf(stderr, "failed to map configuration structure: %s\n",
402d722e3fbSopenharmony_ci                strerror(-err));
403d722e3fbSopenharmony_ci        return err;
404d722e3fbSopenharmony_ci    }
405d722e3fbSopenharmony_ci
406d722e3fbSopenharmony_ci    err = drm_tegra_bo_new(drm, 0, 16384, &vic->filter.bo);
407d722e3fbSopenharmony_ci    if (err < 0) {
408d722e3fbSopenharmony_ci        fprintf(stderr, "failed to allocate filter buffer: %s\n",
409d722e3fbSopenharmony_ci                strerror(-err));
410d722e3fbSopenharmony_ci        return err;
411d722e3fbSopenharmony_ci    }
412d722e3fbSopenharmony_ci
413d722e3fbSopenharmony_ci    err = drm_tegra_bo_map(vic->filter.bo, &ptr);
414d722e3fbSopenharmony_ci    if (err < 0) {
415d722e3fbSopenharmony_ci        fprintf(stderr, "failed to map filter buffer: %s\n", strerror(-err));
416d722e3fbSopenharmony_ci        return err;
417d722e3fbSopenharmony_ci    }
418d722e3fbSopenharmony_ci
419d722e3fbSopenharmony_ci    memset(ptr, 0, 16384);
420d722e3fbSopenharmony_ci    drm_tegra_bo_unmap(vic->filter.bo);
421d722e3fbSopenharmony_ci
422d722e3fbSopenharmony_ci    err = drm_tegra_channel_map(channel, vic->filter.bo, DRM_TEGRA_CHANNEL_MAP_READ,
423d722e3fbSopenharmony_ci                                &vic->filter.map);
424d722e3fbSopenharmony_ci    if (err < 0) {
425d722e3fbSopenharmony_ci        fprintf(stderr, "failed to map filter buffer: %s\n",
426d722e3fbSopenharmony_ci                strerror(-err));
427d722e3fbSopenharmony_ci        return err;
428d722e3fbSopenharmony_ci    }
429d722e3fbSopenharmony_ci
430d722e3fbSopenharmony_ci    err = drm_tegra_bo_new(drm, 0, 4096, &vic->hist.bo);
431d722e3fbSopenharmony_ci    if (err < 0) {
432d722e3fbSopenharmony_ci        fprintf(stderr, "failed to allocate history buffer: %s\n",
433d722e3fbSopenharmony_ci                strerror(-err));
434d722e3fbSopenharmony_ci        return err;
435d722e3fbSopenharmony_ci    }
436d722e3fbSopenharmony_ci
437d722e3fbSopenharmony_ci    err = drm_tegra_bo_map(vic->hist.bo, &ptr);
438d722e3fbSopenharmony_ci    if (err < 0) {
439d722e3fbSopenharmony_ci        fprintf(stderr, "failed to map history buffer: %s\n", strerror(-err));
440d722e3fbSopenharmony_ci        return err;
441d722e3fbSopenharmony_ci    }
442d722e3fbSopenharmony_ci
443d722e3fbSopenharmony_ci    memset(ptr, 0, 4096);
444d722e3fbSopenharmony_ci    drm_tegra_bo_unmap(vic->hist.bo);
445d722e3fbSopenharmony_ci
446d722e3fbSopenharmony_ci    err = drm_tegra_channel_map(channel, vic->hist.bo, DRM_TEGRA_CHANNEL_MAP_READ_WRITE,
447d722e3fbSopenharmony_ci                                &vic->hist.map);
448d722e3fbSopenharmony_ci    if (err < 0) {
449d722e3fbSopenharmony_ci        fprintf(stderr, "failed to map histogram buffer: %s\n",
450d722e3fbSopenharmony_ci                strerror(-err));
451d722e3fbSopenharmony_ci        return err;
452d722e3fbSopenharmony_ci    }
453d722e3fbSopenharmony_ci
454d722e3fbSopenharmony_ci    if (vicp)
455d722e3fbSopenharmony_ci        *vicp = &vic->base;
456d722e3fbSopenharmony_ci
457d722e3fbSopenharmony_ci    return 0;
458d722e3fbSopenharmony_ci}
459