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 <nvif/push507c.h>
28 head507d_procamp(struct nv50_head *head, struct nv50_head_atom *asyh)
30 struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
32 if ((push = evo_wait(core, 2))) {
33 evo_mthd(push, 0x08a8 + (head->base.index * 0x400), 1);
34 evo_data(push, asyh->procamp.sat.sin << 20 |
35 asyh->procamp.sat.cos << 8);
41 head507d_dither(struct nv50_head *head, struct nv50_head_atom *asyh)
43 struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
45 if ((push = evo_wait(core, 2))) {
46 evo_mthd(push, 0x08a0 + (head->base.index * 0x0400), 1);
47 evo_data(push, asyh->dither.mode << 3 |
48 asyh->dither.bits << 1 |
55 head507d_ovly(struct nv50_head *head, struct nv50_head_atom *asyh)
57 struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
58 const int i = head->base.index;
63 switch (asyh->ovly.cpp) {
64 case 4: bounds |= 0x00000300; break;
65 case 2: bounds |= 0x00000100; break;
75 if ((ret = PUSH_WAIT(push, 2)))
78 PUSH_NVSQ(push, NV507D, 0x0904 + (i * 0x400), bounds);
83 head507d_base(struct nv50_head *head, struct nv50_head_atom *asyh)
85 struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
86 const int i = head->base.index;
91 switch (asyh->base.cpp) {
92 case 8: bounds |= 0x00000500; break;
93 case 4: bounds |= 0x00000300; break;
94 case 2: bounds |= 0x00000100; break;
95 case 1: bounds |= 0x00000000; break;
100 bounds |= 0x00000001;
103 if ((ret = PUSH_WAIT(push, 2)))
106 PUSH_NVSQ(push, NV507D, 0x0900 + (i * 0x400), bounds);
111 head507d_curs_clr(struct nv50_head *head)
113 struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
114 const int i = head->base.index;
117 if ((ret = PUSH_WAIT(push, 2)))
120 PUSH_NVSQ(push, NV507D, 0x0880 + (i * 0x400), 0x05000000);
125 head507d_curs_set(struct nv50_head *head, struct nv50_head_atom *asyh)
127 struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
128 const int i = head->base.index;
131 if ((ret = PUSH_WAIT(push, 3)))
134 PUSH_NVSQ(push, NV507D, 0x0880 + (i * 0x400), 0x80000000 |
135 asyh->curs.layout << 26 |
136 asyh->curs.format << 24,
137 0x0884 + (i * 0x400), asyh->curs.offset >> 8);
142 head507d_curs_format(struct nv50_head *head, struct nv50_wndw_atom *asyw,
143 struct nv50_head_atom *asyh)
145 switch (asyw->image.format) {
146 case 0xcf: asyh->curs.format = 1; break;
155 head507d_curs_layout(struct nv50_head *head, struct nv50_wndw_atom *asyw,
156 struct nv50_head_atom *asyh)
158 switch (asyw->image.w) {
159 case 32: asyh->curs.layout = 0; break;
160 case 64: asyh->curs.layout = 1; break;
168 head507d_core_clr(struct nv50_head *head)
170 struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
171 const int i = head->base.index;
174 if ((ret = PUSH_WAIT(push, 2)))
177 PUSH_NVSQ(push, NV507D, 0x0874 + (i * 0x400), 0x00000000);
182 head507d_core_set(struct nv50_head *head, struct nv50_head_atom *asyh)
184 struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
185 const int i = head->base.index;
188 if ((ret = PUSH_WAIT(push, 9)))
191 PUSH_NVSQ(push, NV507D, 0x0860 + (i * 0x400), asyh->core.offset >> 8);
192 PUSH_NVSQ(push, NV507D, 0x0868 + (i * 0x400), asyh->core.h << 16 | asyh->core.w,
193 0x086c + (i * 0x400), asyh->core.layout << 20 |
194 (asyh->core.pitch >> 8) << 8 |
195 asyh->core.blocks << 8 |
197 0x0870 + (i * 0x400), asyh->core.kind << 16 |
198 asyh->core.format << 8,
199 0x0874 + (i * 0x400), asyh->core.handle);
200 PUSH_NVSQ(push, NV507D, 0x08c0 + (i * 0x400), asyh->core.y << 16 | asyh->core.x);
202 /* EVO will complain with INVALID_STATE if we have an
203 * active cursor and (re)specify HeadSetContextDmaIso
204 * without also updating HeadSetOffsetCursor.
206 asyh->set.curs = asyh->curs.visible;
207 asyh->set.olut = asyh->olut.handle != 0;
212 head507d_core_calc(struct nv50_head *head, struct nv50_head_atom *asyh)
214 struct nv50_disp *disp = nv50_disp(head->base.base.dev);
215 if ((asyh->core.visible = (asyh->base.cpp != 0))) {
216 asyh->core.x = asyh->base.x;
217 asyh->core.y = asyh->base.y;
218 asyh->core.w = asyh->base.w;
219 asyh->core.h = asyh->base.h;
221 if ((asyh->core.visible = (asyh->ovly.cpp != 0)) ||
222 (asyh->core.visible = asyh->curs.visible)) {
223 /*XXX: We need to either find some way of having the
224 * primary base layer appear black, while still
225 * being able to display the other layers, or we
226 * need to allocate a dummy black surface here.
230 asyh->core.w = asyh->state.mode.hdisplay;
231 asyh->core.h = asyh->state.mode.vdisplay;
233 asyh->core.handle = disp->core->chan.vram.handle;
234 asyh->core.offset = 0;
235 asyh->core.format = 0xcf;
237 asyh->core.layout = 1;
238 asyh->core.blockh = 0;
239 asyh->core.blocks = 0;
240 asyh->core.pitch = ALIGN(asyh->core.w, 64) * 4;
244 head507d_olut_clr(struct nv50_head *head)
246 struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
247 const int i = head->base.index;
250 if ((ret = PUSH_WAIT(push, 2)))
253 PUSH_NVSQ(push, NV507D, 0x0840 + (i * 0x400), 0x00000000);
258 head507d_olut_set(struct nv50_head *head, struct nv50_head_atom *asyh)
260 struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
261 const int i = head->base.index;
264 if ((ret = PUSH_WAIT(push, 3)))
267 PUSH_NVSQ(push, NV507D, 0x0840 + (i * 0x400), 0x80000000 | asyh->olut.mode << 30,
268 0x0844 + (i * 0x400), asyh->olut.offset >> 8);
273 head507d_olut_load(struct drm_color_lut *in, int size, void __iomem *mem)
275 for (; size--; in++, mem += 8) {
276 writew(drm_color_lut_extract(in-> red, 11) << 3, mem + 0);
277 writew(drm_color_lut_extract(in->green, 11) << 3, mem + 2);
278 writew(drm_color_lut_extract(in-> blue, 11) << 3, mem + 4);
281 /* INTERPOLATE modes require a "next" entry to interpolate with,
282 * so we replicate the last entry to deal with this for now.
284 writew(readw(mem - 8), mem + 0);
285 writew(readw(mem - 6), mem + 2);
286 writew(readw(mem - 4), mem + 4);
290 head507d_olut(struct nv50_head *head, struct nv50_head_atom *asyh, int size)
295 if (asyh->base.cpp == 1)
300 asyh->olut.load = head507d_olut_load;
305 head507d_mode(struct nv50_head *head, struct nv50_head_atom *asyh)
307 struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
308 struct nv50_head_mode *m = &asyh->mode;
309 const int i = head->base.index;
312 if ((ret = PUSH_WAIT(push, 13)))
315 PUSH_NVSQ(push, NV507D, 0x0804 + (i * 0x400), 0x00800000 | m->clock,
316 0x0808 + (i * 0x400), m->interlace ? 0x00000002 : 0x00000000);
317 PUSH_NVSQ(push, NV507D, 0x0810 + (i * 0x400), 0x00000000,
318 0x0814 + (i * 0x400), m->v.active << 16 | m->h.active,
319 0x0818 + (i * 0x400), m->v.synce << 16 | m->h.synce,
320 0x081c + (i * 0x400), m->v.blanke << 16 | m->h.blanke,
321 0x0820 + (i * 0x400), m->v.blanks << 16 | m->h.blanks,
322 0x0824 + (i * 0x400), m->v.blank2e << 16 | m->v.blank2s,
323 0x0828 + (i * 0x400), asyh->mode.v.blankus);
324 PUSH_NVSQ(push, NV507D, 0x082c + (i * 0x400), 0x00000000);
329 head507d_view(struct nv50_head *head, struct nv50_head_atom *asyh)
331 struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
332 const int i = head->base.index;
335 if ((ret = PUSH_WAIT(push, 7)))
338 PUSH_NVSQ(push, NV507D, 0x08a4 + (i * 0x400), 0x00000000);
339 PUSH_NVSQ(push, NV507D, 0x08c8 + (i * 0x400), asyh->view.iH << 16 | asyh->view.iW);
340 PUSH_NVSQ(push, NV507D, 0x08d8 + (i * 0x400), asyh->view.oH << 16 | asyh->view.oW,
341 0x08dc + (i * 0x400), asyh->view.oH << 16 | asyh->view.oW);
345 const struct nv50_head_func
347 .view = head507d_view,
348 .mode = head507d_mode,
349 .olut = head507d_olut,
351 .olut_set = head507d_olut_set,
352 .olut_clr = head507d_olut_clr,
353 .core_calc = head507d_core_calc,
354 .core_set = head507d_core_set,
355 .core_clr = head507d_core_clr,
356 .curs_layout = head507d_curs_layout,
357 .curs_format = head507d_curs_format,
358 .curs_set = head507d_curs_set,
359 .curs_clr = head507d_curs_clr,
360 .base = head507d_base,
361 .ovly = head507d_ovly,
362 .dither = head507d_dither,
363 .procamp = head507d_procamp,