2 * Copyright 2018 Red Hat Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
25 #include <drm/drm_atomic_helper.h>
26 #include <drm/drm_plane_helper.h>
27 #include <nouveau_bo.h>
29 #include <nvif/clc37e.h>
32 wndwc57e_image_set(struct nv50_wndw
*wndw
, struct nv50_wndw_atom
*asyw
)
36 if (!(push
= evo_wait(&wndw
->wndw
, 17)))
39 evo_mthd(push
, 0x0308, 1);
40 evo_data(push
, asyw
->image
.mode
<< 4 | asyw
->image
.interval
);
41 evo_mthd(push
, 0x0224, 4);
42 evo_data(push
, asyw
->image
.h
<< 16 | asyw
->image
.w
);
43 evo_data(push
, asyw
->image
.layout
<< 4 | asyw
->image
.blockh
);
44 evo_data(push
, asyw
->image
.colorspace
<< 8 |
46 evo_data(push
, asyw
->image
.blocks
[0] | (asyw
->image
.pitch
[0] >> 6));
47 evo_mthd(push
, 0x0240, 1);
48 evo_data(push
, asyw
->image
.handle
[0]);
49 evo_mthd(push
, 0x0260, 1);
50 evo_data(push
, asyw
->image
.offset
[0] >> 8);
51 evo_mthd(push
, 0x0290, 1);
52 evo_data(push
, (asyw
->state
.src_y
>> 16) << 16 |
53 (asyw
->state
.src_x
>> 16));
54 evo_mthd(push
, 0x0298, 1);
55 evo_data(push
, (asyw
->state
.src_h
>> 16) << 16 |
56 (asyw
->state
.src_w
>> 16));
57 evo_mthd(push
, 0x02a4, 1);
58 evo_data(push
, asyw
->state
.crtc_h
<< 16 |
60 evo_kick(push
, &wndw
->wndw
);
64 wndwc57e_csc_clr(struct nv50_wndw
*wndw
)
67 if ((push
= evo_wait(&wndw
->wndw
, 13))) {
68 evo_mthd(push
, 0x0400, 12);
69 evo_data(push
, 0x00010000);
70 evo_data(push
, 0x00000000);
71 evo_data(push
, 0x00000000);
72 evo_data(push
, 0x00000000);
73 evo_data(push
, 0x00000000);
74 evo_data(push
, 0x00010000);
75 evo_data(push
, 0x00000000);
76 evo_data(push
, 0x00000000);
77 evo_data(push
, 0x00000000);
78 evo_data(push
, 0x00000000);
79 evo_data(push
, 0x00010000);
80 evo_data(push
, 0x00000000);
81 evo_kick(push
, &wndw
->wndw
);
86 wndwc57e_csc_set(struct nv50_wndw
*wndw
, struct nv50_wndw_atom
*asyw
)
89 if ((push
= evo_wait(&wndw
->wndw
, 13))) {
90 evo_mthd(push
, 0x0400, 12);
91 for (i
= 0; i
< 12; i
++)
92 evo_data(push
, asyw
->csc
.matrix
[i
]);
93 evo_kick(push
, &wndw
->wndw
);
98 wndwc57e_ilut_clr(struct nv50_wndw
*wndw
)
101 if ((push
= evo_wait(&wndw
->wndw
, 2))) {
102 evo_mthd(push
, 0x0444, 1);
103 evo_data(push
, 0x00000000);
104 evo_kick(push
, &wndw
->wndw
);
109 wndwc57e_ilut_set(struct nv50_wndw
*wndw
, struct nv50_wndw_atom
*asyw
)
112 if ((push
= evo_wait(&wndw
->wndw
, 4))) {
113 evo_mthd(push
, 0x0440, 3);
114 evo_data(push
, asyw
->xlut
.i
.size
<< 8 |
115 asyw
->xlut
.i
.mode
<< 2 |
116 asyw
->xlut
.i
.output_mode
);
117 evo_data(push
, asyw
->xlut
.handle
);
118 evo_data(push
, asyw
->xlut
.i
.offset
>> 8);
119 evo_kick(push
, &wndw
->wndw
);
124 fixedU0_16_FP16(u16 fixed
)
126 int sign
= 0, exp
= 0, man
= 0;
128 while (--exp
&& !(fixed
& 0x8000))
130 man
= ((fixed
<< 1) & 0xffc0) >> 6;
133 return (sign
<< 15) | (exp
<< 10) | man
;
137 wndwc57e_ilut_load(struct drm_color_lut
*in
, int size
, void __iomem
*mem
)
139 memset_io(mem
, 0x00, 0x20); /* VSS header. */
142 for (; size
--; in
++, mem
+= 0x08) {
143 u16 r
= fixedU0_16_FP16(drm_color_lut_extract(in
-> red
, 16));
144 u16 g
= fixedU0_16_FP16(drm_color_lut_extract(in
->green
, 16));
145 u16 b
= fixedU0_16_FP16(drm_color_lut_extract(in
-> blue
, 16));
151 /* INTERPOLATE modes require a "next" entry to interpolate with,
152 * so we replicate the last entry to deal with this for now.
154 writew(readw(mem
- 8), mem
+ 0);
155 writew(readw(mem
- 6), mem
+ 2);
156 writew(readw(mem
- 4), mem
+ 4);
160 wndwc57e_ilut(struct nv50_wndw
*wndw
, struct nv50_wndw_atom
*asyw
, int size
)
162 if (size
= size
? size
: 1024, size
!= 256 && size
!= 1024)
166 asyw
->xlut
.i
.mode
= 1; /* DIRECT8. */
168 asyw
->xlut
.i
.mode
= 2; /* DIRECT10. */
170 asyw
->xlut
.i
.size
= 4 /* VSS header. */ + size
+ 1 /* Entries. */;
171 asyw
->xlut
.i
.output_mode
= 0; /* INTERPOLATE_DISABLE. */
172 asyw
->xlut
.i
.load
= wndwc57e_ilut_load
;
176 static const struct nv50_wndw_func
178 .acquire
= wndwc37e_acquire
,
179 .release
= wndwc37e_release
,
180 .sema_set
= wndwc37e_sema_set
,
181 .sema_clr
= wndwc37e_sema_clr
,
182 .ntfy_set
= wndwc37e_ntfy_set
,
183 .ntfy_clr
= wndwc37e_ntfy_clr
,
184 .ntfy_reset
= corec37d_ntfy_init
,
185 .ntfy_wait_begun
= base507c_ntfy_wait_begun
,
186 .ilut
= wndwc57e_ilut
,
187 .ilut_identity
= true,
189 .xlut_set
= wndwc57e_ilut_set
,
190 .xlut_clr
= wndwc57e_ilut_clr
,
192 .csc_set
= wndwc57e_csc_set
,
193 .csc_clr
= wndwc57e_csc_clr
,
194 .image_set
= wndwc57e_image_set
,
195 .image_clr
= wndwc37e_image_clr
,
196 .blend_set
= wndwc37e_blend_set
,
197 .update
= wndwc37e_update
,
201 wndwc57e_new(struct nouveau_drm
*drm
, enum drm_plane_type type
, int index
,
202 s32 oclass
, struct nv50_wndw
**pwndw
)
204 return wndwc37e_new_(&wndwc57e
, drm
, type
, index
, oclass
,
205 BIT(index
>> 1), pwndw
);