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>
30 #include <nvif/pushc37b.h>
33 wndwc57e_image_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
37 if (!(push = evo_wait(&wndw->wndw, 17)))
40 evo_mthd(push, 0x0308, 1);
41 evo_data(push, asyw->image.mode << 4 | asyw->image.interval);
42 evo_mthd(push, 0x0224, 4);
43 evo_data(push, asyw->image.h << 16 | asyw->image.w);
44 evo_data(push, asyw->image.layout << 4 | asyw->image.blockh);
45 evo_data(push, asyw->image.colorspace << 8 |
47 evo_data(push, asyw->image.blocks[0] | (asyw->image.pitch[0] >> 6));
48 evo_mthd(push, 0x0240, 1);
49 evo_data(push, asyw->image.handle[0]);
50 evo_mthd(push, 0x0260, 1);
51 evo_data(push, asyw->image.offset[0] >> 8);
52 evo_mthd(push, 0x0290, 1);
53 evo_data(push, (asyw->state.src_y >> 16) << 16 |
54 (asyw->state.src_x >> 16));
55 evo_mthd(push, 0x0298, 1);
56 evo_data(push, (asyw->state.src_h >> 16) << 16 |
57 (asyw->state.src_w >> 16));
58 evo_mthd(push, 0x02a4, 1);
59 evo_data(push, asyw->state.crtc_h << 16 |
61 evo_kick(push, &wndw->wndw);
65 wndwc57e_csc_clr(struct nv50_wndw *wndw)
67 struct nvif_push *push = wndw->wndw.push;
68 const u32 identity[12] = {
69 0x00010000, 0x00000000, 0x00000000, 0x00000000,
70 0x00000000, 0x00010000, 0x00000000, 0x00000000,
71 0x00000000, 0x00000000, 0x00010000, 0x00000000,
75 if ((ret = PUSH_WAIT(push, 1 + ARRAY_SIZE(identity))))
78 PUSH_NVSQ(push, NVC57E, 0x0400, identity, ARRAY_SIZE(identity));
83 wndwc57e_csc_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
85 struct nvif_push *push = wndw->wndw.push;
88 if ((ret = PUSH_WAIT(push, 13)))
91 PUSH_NVSQ(push, NVC57E, 0x0400, asyw->csc.matrix, 12);
96 wndwc57e_ilut_clr(struct nv50_wndw *wndw)
99 if ((push = evo_wait(&wndw->wndw, 2))) {
100 evo_mthd(push, 0x0444, 1);
101 evo_data(push, 0x00000000);
102 evo_kick(push, &wndw->wndw);
107 wndwc57e_ilut_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
109 struct nvif_push *push = wndw->wndw.push;
112 if ((ret = PUSH_WAIT(push, 4)))
115 PUSH_NVSQ(push, NVC57E, 0x0440, asyw->xlut.i.size << 8 |
116 asyw->xlut.i.mode << 2 |
117 asyw->xlut.i.output_mode,
118 0x0444, asyw->xlut.handle,
119 0x0448, asyw->xlut.i.offset >> 8);
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 /****************************************************************
177 * Log2(block height) ----------------------------+ *
178 * Page Kind ----------------------------------+ | *
179 * Gob Height/Page Kind Generation ------+ | | *
180 * Sector layout -------+ | | | *
181 * Compression ------+ | | | | */
182 const u64 wndwc57e_modifiers[] = { /* | | | | | */
183 DRM_FORMAT_MOD_NVIDIA_BLOCK_LINEAR_2D(0, 1, 2, 0x06, 0),
184 DRM_FORMAT_MOD_NVIDIA_BLOCK_LINEAR_2D(0, 1, 2, 0x06, 1),
185 DRM_FORMAT_MOD_NVIDIA_BLOCK_LINEAR_2D(0, 1, 2, 0x06, 2),
186 DRM_FORMAT_MOD_NVIDIA_BLOCK_LINEAR_2D(0, 1, 2, 0x06, 3),
187 DRM_FORMAT_MOD_NVIDIA_BLOCK_LINEAR_2D(0, 1, 2, 0x06, 4),
188 DRM_FORMAT_MOD_NVIDIA_BLOCK_LINEAR_2D(0, 1, 2, 0x06, 5),
189 DRM_FORMAT_MOD_LINEAR,
190 DRM_FORMAT_MOD_INVALID
193 static const struct nv50_wndw_func
195 .acquire = wndwc37e_acquire,
196 .release = wndwc37e_release,
197 .sema_set = wndwc37e_sema_set,
198 .sema_clr = wndwc37e_sema_clr,
199 .ntfy_set = wndwc37e_ntfy_set,
200 .ntfy_clr = wndwc37e_ntfy_clr,
201 .ntfy_reset = corec37d_ntfy_init,
202 .ntfy_wait_begun = base507c_ntfy_wait_begun,
203 .ilut = wndwc57e_ilut,
204 .ilut_identity = true,
206 .xlut_set = wndwc57e_ilut_set,
207 .xlut_clr = wndwc57e_ilut_clr,
209 .csc_set = wndwc57e_csc_set,
210 .csc_clr = wndwc57e_csc_clr,
211 .image_set = wndwc57e_image_set,
212 .image_clr = wndwc37e_image_clr,
213 .blend_set = wndwc37e_blend_set,
214 .update = wndwc37e_update,
218 wndwc57e_new(struct nouveau_drm *drm, enum drm_plane_type type, int index,
219 s32 oclass, struct nv50_wndw **pwndw)
221 return wndwc37e_new_(&wndwc57e, drm, type, index, oclass,
222 BIT(index >> 1), pwndw);