1ccd27db8SBen Skeggs /* 2ccd27db8SBen Skeggs * Copyright 2018 Red Hat Inc. 3ccd27db8SBen Skeggs * 4ccd27db8SBen Skeggs * Permission is hereby granted, free of charge, to any person obtaining a 5ccd27db8SBen Skeggs * copy of this software and associated documentation files (the "Software"), 6ccd27db8SBen Skeggs * to deal in the Software without restriction, including without limitation 7ccd27db8SBen Skeggs * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8ccd27db8SBen Skeggs * and/or sell copies of the Software, and to permit persons to whom the 9ccd27db8SBen Skeggs * Software is furnished to do so, subject to the following conditions: 10ccd27db8SBen Skeggs * 11ccd27db8SBen Skeggs * The above copyright notice and this permission notice shall be included in 12ccd27db8SBen Skeggs * all copies or substantial portions of the Software. 13ccd27db8SBen Skeggs * 14ccd27db8SBen Skeggs * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15ccd27db8SBen Skeggs * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16ccd27db8SBen Skeggs * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17ccd27db8SBen Skeggs * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18ccd27db8SBen Skeggs * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19ccd27db8SBen Skeggs * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20ccd27db8SBen Skeggs * OTHER DEALINGS IN THE SOFTWARE. 21ccd27db8SBen Skeggs */ 22ccd27db8SBen Skeggs #include "base.h" 23ccd27db8SBen Skeggs 2472587dcaSBen Skeggs #include <nvif/push507c.h> 2572587dcaSBen Skeggs 26*6d6e11e2SBen Skeggs static int 27ccd27db8SBen Skeggs base907c_image_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw) 28ccd27db8SBen Skeggs { 29*6d6e11e2SBen Skeggs struct nvif_push *push = wndw->wndw.push; 30*6d6e11e2SBen Skeggs int ret; 31*6d6e11e2SBen Skeggs 32*6d6e11e2SBen Skeggs if ((ret = PUSH_WAIT(push, 10))) 33*6d6e11e2SBen Skeggs return ret; 34*6d6e11e2SBen Skeggs 35*6d6e11e2SBen Skeggs PUSH_NVSQ(push, NV907C, 0x0084, asyw->image.mode << 8 | 36ccd27db8SBen Skeggs asyw->image.interval << 4); 37*6d6e11e2SBen Skeggs PUSH_NVSQ(push, NV907C, 0x00c0, asyw->image.handle[0]); 38*6d6e11e2SBen Skeggs PUSH_NVSQ(push, NV907C, 0x0400, asyw->image.offset[0] >> 8, 39*6d6e11e2SBen Skeggs 0x0404, 0x00000000, 40*6d6e11e2SBen Skeggs 0x0408, asyw->image.h << 16 | asyw->image.w, 41*6d6e11e2SBen Skeggs 0x040c, asyw->image.layout << 24 | 42b05d8738SBen Skeggs (asyw->image.pitch[0] >> 8) << 8 | 43b05d8738SBen Skeggs asyw->image.blocks[0] << 8 | 44*6d6e11e2SBen Skeggs asyw->image.blockh, 45*6d6e11e2SBen Skeggs 0x0410, asyw->image.format << 8); 46*6d6e11e2SBen Skeggs return 0; 47ccd27db8SBen Skeggs } 48ccd27db8SBen Skeggs 4934838908SBen Skeggs static int 50119608a7SBen Skeggs base907c_xlut_clr(struct nv50_wndw *wndw) 51119608a7SBen Skeggs { 5234838908SBen Skeggs struct nvif_push *push = wndw->wndw.push; 5334838908SBen Skeggs int ret; 5434838908SBen Skeggs 5534838908SBen Skeggs if ((ret = PUSH_WAIT(push, 6))) 5634838908SBen Skeggs return ret; 5734838908SBen Skeggs 5834838908SBen Skeggs PUSH_NVSQ(push, NV907C, 0x00e0, 0x00000000); 5934838908SBen Skeggs PUSH_NVSQ(push, NV907C, 0x00e8, 0x00000000); 6034838908SBen Skeggs PUSH_NVSQ(push, NV907C, 0x00fc, 0x00000000); 6134838908SBen Skeggs return 0; 62119608a7SBen Skeggs } 63119608a7SBen Skeggs 64222439ebSBen Skeggs static int 65119608a7SBen Skeggs base907c_xlut_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw) 66119608a7SBen Skeggs { 67222439ebSBen Skeggs struct nvif_push *push = wndw->wndw.push; 68222439ebSBen Skeggs int ret; 69222439ebSBen Skeggs 70222439ebSBen Skeggs if ((ret = PUSH_WAIT(push, 6))) 71222439ebSBen Skeggs return ret; 72222439ebSBen Skeggs 73222439ebSBen Skeggs PUSH_NVSQ(push, NV907C, 0x00e0, asyw->xlut.i.enable << 30 | 74222439ebSBen Skeggs asyw->xlut.i.mode << 24, 75222439ebSBen Skeggs 0x00e4, asyw->xlut.i.offset >> 8, 76222439ebSBen Skeggs 0x00e8, 0x40000000); 77222439ebSBen Skeggs PUSH_NVSQ(push, NV907C, 0x00fc, asyw->xlut.handle); 78222439ebSBen Skeggs return 0; 79119608a7SBen Skeggs } 80119608a7SBen Skeggs 8113199270SIlia Mirkin static bool 8213199270SIlia Mirkin base907c_ilut(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw, int size) 83119608a7SBen Skeggs { 8413199270SIlia Mirkin if (size != 256 && size != 1024) 8513199270SIlia Mirkin return false; 8613199270SIlia Mirkin 8713199270SIlia Mirkin asyw->xlut.i.mode = size == 1024 ? 4 : 7; 88119608a7SBen Skeggs asyw->xlut.i.enable = 2; 89cb55cd0cSBen Skeggs asyw->xlut.i.load = head907d_olut_load; 9013199270SIlia Mirkin return true; 91119608a7SBen Skeggs } 92119608a7SBen Skeggs 9388b70352SIlia Mirkin static inline u32 9488b70352SIlia Mirkin csc_drm_to_base(u64 in) 9588b70352SIlia Mirkin { 9688b70352SIlia Mirkin /* base takes a 19-bit 2's complement value in S3.16 format */ 9788b70352SIlia Mirkin bool sign = in & BIT_ULL(63); 9888b70352SIlia Mirkin u32 integer = (in >> 32) & 0x7fffffff; 9988b70352SIlia Mirkin u32 fraction = in & 0xffffffff; 10088b70352SIlia Mirkin 10188b70352SIlia Mirkin if (integer >= 4) { 10288b70352SIlia Mirkin return (1 << 18) - (sign ? 0 : 1); 10388b70352SIlia Mirkin } else { 10488b70352SIlia Mirkin u32 ret = (integer << 16) | (fraction >> 16); 10588b70352SIlia Mirkin if (sign) 10688b70352SIlia Mirkin ret = -ret; 10788b70352SIlia Mirkin return ret & GENMASK(18, 0); 10888b70352SIlia Mirkin } 10988b70352SIlia Mirkin } 11088b70352SIlia Mirkin 111dffa4878SBen Skeggs void 11288b70352SIlia Mirkin base907c_csc(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw, 11388b70352SIlia Mirkin const struct drm_color_ctm *ctm) 11488b70352SIlia Mirkin { 11588b70352SIlia Mirkin int i, j; 11688b70352SIlia Mirkin 11788b70352SIlia Mirkin for (j = 0; j < 3; j++) { 11888b70352SIlia Mirkin for (i = 0; i < 4; i++) { 11988b70352SIlia Mirkin u32 *val = &asyw->csc.matrix[j * 4 + i]; 12088b70352SIlia Mirkin /* DRM does not support constant offset, while 12188b70352SIlia Mirkin * HW CSC does. Skip it. */ 12288b70352SIlia Mirkin if (i == 3) { 12388b70352SIlia Mirkin *val = 0; 12488b70352SIlia Mirkin } else { 12588b70352SIlia Mirkin *val = csc_drm_to_base(ctm->matrix[j * 3 + i]); 12688b70352SIlia Mirkin } 12788b70352SIlia Mirkin } 12888b70352SIlia Mirkin } 12988b70352SIlia Mirkin } 13088b70352SIlia Mirkin 131cfb4120dSBen Skeggs static int 13288b70352SIlia Mirkin base907c_csc_clr(struct nv50_wndw *wndw) 13388b70352SIlia Mirkin { 134cfb4120dSBen Skeggs struct nvif_push *push = wndw->wndw.push; 135cfb4120dSBen Skeggs int ret; 136cfb4120dSBen Skeggs 137cfb4120dSBen Skeggs if ((ret = PUSH_WAIT(push, 2))) 138cfb4120dSBen Skeggs return ret; 139cfb4120dSBen Skeggs 140cfb4120dSBen Skeggs PUSH_NVSQ(push, NV907C, 0x0140, 0x00000000); 141cfb4120dSBen Skeggs return 0; 14288b70352SIlia Mirkin } 14388b70352SIlia Mirkin 14472587dcaSBen Skeggs static int 14588b70352SIlia Mirkin base907c_csc_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw) 14688b70352SIlia Mirkin { 14772587dcaSBen Skeggs struct nvif_push *push = wndw->wndw.push; 14872587dcaSBen Skeggs int ret; 14972587dcaSBen Skeggs 15072587dcaSBen Skeggs if ((ret = PUSH_WAIT(push, 13))) 15172587dcaSBen Skeggs return ret; 15272587dcaSBen Skeggs 15372587dcaSBen Skeggs PUSH_NVSQ(push, NV907C, 0x0140, asyw->csc.matrix[0] | 0x80000000, 15472587dcaSBen Skeggs 0x0144, &asyw->csc.matrix[1], 11); 15572587dcaSBen Skeggs return 0; 15688b70352SIlia Mirkin } 15788b70352SIlia Mirkin 15888b600d4SBen Skeggs const struct nv50_wndw_func 159ccd27db8SBen Skeggs base907c = { 160ccd27db8SBen Skeggs .acquire = base507c_acquire, 161ccd27db8SBen Skeggs .release = base507c_release, 162ccd27db8SBen Skeggs .sema_set = base507c_sema_set, 163ccd27db8SBen Skeggs .sema_clr = base507c_sema_clr, 164ccd27db8SBen Skeggs .ntfy_reset = base507c_ntfy_reset, 165ccd27db8SBen Skeggs .ntfy_set = base507c_ntfy_set, 166ccd27db8SBen Skeggs .ntfy_clr = base507c_ntfy_clr, 167ccd27db8SBen Skeggs .ntfy_wait_begun = base507c_ntfy_wait_begun, 168119608a7SBen Skeggs .ilut = base907c_ilut, 16988b70352SIlia Mirkin .csc = base907c_csc, 17088b70352SIlia Mirkin .csc_set = base907c_csc_set, 17188b70352SIlia Mirkin .csc_clr = base907c_csc_clr, 172119608a7SBen Skeggs .olut_core = true, 17313199270SIlia Mirkin .ilut_size = 1024, 174119608a7SBen Skeggs .xlut_set = base907c_xlut_set, 175119608a7SBen Skeggs .xlut_clr = base907c_xlut_clr, 176ccd27db8SBen Skeggs .image_set = base907c_image_set, 177ccd27db8SBen Skeggs .image_clr = base507c_image_clr, 17853e0a3e7SBen Skeggs .update = base507c_update, 179ccd27db8SBen Skeggs }; 180ccd27db8SBen Skeggs 181ccd27db8SBen Skeggs int 182ccd27db8SBen Skeggs base907c_new(struct nouveau_drm *drm, int head, s32 oclass, 183ccd27db8SBen Skeggs struct nv50_wndw **pwndw) 184ccd27db8SBen Skeggs { 18553e0a3e7SBen Skeggs return base507c_new_(&base907c, base507c_format, drm, head, oclass, 18653e0a3e7SBen Skeggs 0x00000002 << (head * 4), pwndw); 187ccd27db8SBen Skeggs } 188