18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright 2018 Red Hat Inc. 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 58c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 68c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation 78c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 88c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 98c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 108c2ecf20Sopenharmony_ci * 118c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice shall be included in 128c2ecf20Sopenharmony_ci * all copies or substantial portions of the Software. 138c2ecf20Sopenharmony_ci * 148c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 158c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 168c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 178c2ecf20Sopenharmony_ci * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 188c2ecf20Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 198c2ecf20Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 208c2ecf20Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE. 218c2ecf20Sopenharmony_ci */ 228c2ecf20Sopenharmony_ci#include "wndw.h" 238c2ecf20Sopenharmony_ci#include "atom.h" 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci#include <drm/drm_atomic_helper.h> 268c2ecf20Sopenharmony_ci#include <drm/drm_plane_helper.h> 278c2ecf20Sopenharmony_ci#include <nouveau_bo.h> 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci#include <nvif/clc37e.h> 308c2ecf20Sopenharmony_ci#include <nvif/pushc37b.h> 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci#include <nvhw/class/clc57e.h> 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_cistatic int 358c2ecf20Sopenharmony_ciwndwc57e_image_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw) 368c2ecf20Sopenharmony_ci{ 378c2ecf20Sopenharmony_ci struct nvif_push *push = wndw->wndw.push; 388c2ecf20Sopenharmony_ci int ret; 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci if ((ret = PUSH_WAIT(push, 17))) 418c2ecf20Sopenharmony_ci return ret; 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci PUSH_MTHD(push, NVC57E, SET_PRESENT_CONTROL, 448c2ecf20Sopenharmony_ci NVVAL(NVC57E, SET_PRESENT_CONTROL, MIN_PRESENT_INTERVAL, asyw->image.interval) | 458c2ecf20Sopenharmony_ci NVVAL(NVC57E, SET_PRESENT_CONTROL, BEGIN_MODE, asyw->image.mode) | 468c2ecf20Sopenharmony_ci NVDEF(NVC57E, SET_PRESENT_CONTROL, TIMESTAMP_MODE, DISABLE)); 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci PUSH_MTHD(push, NVC57E, SET_SIZE, 498c2ecf20Sopenharmony_ci NVVAL(NVC57E, SET_SIZE, WIDTH, asyw->image.w) | 508c2ecf20Sopenharmony_ci NVVAL(NVC57E, SET_SIZE, HEIGHT, asyw->image.h), 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci SET_STORAGE, 538c2ecf20Sopenharmony_ci NVVAL(NVC57E, SET_STORAGE, BLOCK_HEIGHT, asyw->image.blockh) | 548c2ecf20Sopenharmony_ci NVVAL(NVC57E, SET_STORAGE, MEMORY_LAYOUT, asyw->image.layout), 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci SET_PARAMS, 578c2ecf20Sopenharmony_ci NVVAL(NVC57E, SET_PARAMS, FORMAT, asyw->image.format) | 588c2ecf20Sopenharmony_ci NVDEF(NVC57E, SET_PARAMS, CLAMP_BEFORE_BLEND, DISABLE) | 598c2ecf20Sopenharmony_ci NVDEF(NVC57E, SET_PARAMS, SWAP_UV, DISABLE) | 608c2ecf20Sopenharmony_ci NVDEF(NVC57E, SET_PARAMS, FMT_ROUNDING_MODE, ROUND_TO_NEAREST), 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci SET_PLANAR_STORAGE(0), 638c2ecf20Sopenharmony_ci NVVAL(NVC57E, SET_PLANAR_STORAGE, PITCH, asyw->image.blocks[0]) | 648c2ecf20Sopenharmony_ci NVVAL(NVC57E, SET_PLANAR_STORAGE, PITCH, asyw->image.pitch[0] >> 6)); 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci PUSH_MTHD(push, NVC57E, SET_CONTEXT_DMA_ISO(0), asyw->image.handle, 1); 678c2ecf20Sopenharmony_ci PUSH_MTHD(push, NVC57E, SET_OFFSET(0), asyw->image.offset[0] >> 8); 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci PUSH_MTHD(push, NVC57E, SET_POINT_IN(0), 708c2ecf20Sopenharmony_ci NVVAL(NVC57E, SET_POINT_IN, X, asyw->state.src_x >> 16) | 718c2ecf20Sopenharmony_ci NVVAL(NVC57E, SET_POINT_IN, Y, asyw->state.src_y >> 16)); 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci PUSH_MTHD(push, NVC57E, SET_SIZE_IN, 748c2ecf20Sopenharmony_ci NVVAL(NVC57E, SET_SIZE_IN, WIDTH, asyw->state.src_w >> 16) | 758c2ecf20Sopenharmony_ci NVVAL(NVC57E, SET_SIZE_IN, HEIGHT, asyw->state.src_h >> 16)); 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci PUSH_MTHD(push, NVC57E, SET_SIZE_OUT, 788c2ecf20Sopenharmony_ci NVVAL(NVC57E, SET_SIZE_OUT, WIDTH, asyw->state.crtc_w) | 798c2ecf20Sopenharmony_ci NVVAL(NVC57E, SET_SIZE_OUT, HEIGHT, asyw->state.crtc_h)); 808c2ecf20Sopenharmony_ci return 0; 818c2ecf20Sopenharmony_ci} 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_cistatic int 848c2ecf20Sopenharmony_ciwndwc57e_csc_clr(struct nv50_wndw *wndw) 858c2ecf20Sopenharmony_ci{ 868c2ecf20Sopenharmony_ci struct nvif_push *push = wndw->wndw.push; 878c2ecf20Sopenharmony_ci const u32 identity[12] = { 888c2ecf20Sopenharmony_ci 0x00010000, 0x00000000, 0x00000000, 0x00000000, 898c2ecf20Sopenharmony_ci 0x00000000, 0x00010000, 0x00000000, 0x00000000, 908c2ecf20Sopenharmony_ci 0x00000000, 0x00000000, 0x00010000, 0x00000000, 918c2ecf20Sopenharmony_ci }; 928c2ecf20Sopenharmony_ci int ret; 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci if ((ret = PUSH_WAIT(push, 1 + ARRAY_SIZE(identity)))) 958c2ecf20Sopenharmony_ci return ret; 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci PUSH_MTHD(push, NVC57E, SET_FMT_COEFFICIENT_C00, identity, ARRAY_SIZE(identity)); 988c2ecf20Sopenharmony_ci return 0; 998c2ecf20Sopenharmony_ci} 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_cistatic int 1028c2ecf20Sopenharmony_ciwndwc57e_csc_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw) 1038c2ecf20Sopenharmony_ci{ 1048c2ecf20Sopenharmony_ci struct nvif_push *push = wndw->wndw.push; 1058c2ecf20Sopenharmony_ci int ret; 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci if ((ret = PUSH_WAIT(push, 13))) 1088c2ecf20Sopenharmony_ci return ret; 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ci PUSH_MTHD(push, NVC57E, SET_FMT_COEFFICIENT_C00, asyw->csc.matrix, 12); 1118c2ecf20Sopenharmony_ci return 0; 1128c2ecf20Sopenharmony_ci} 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_cistatic int 1158c2ecf20Sopenharmony_ciwndwc57e_ilut_clr(struct nv50_wndw *wndw) 1168c2ecf20Sopenharmony_ci{ 1178c2ecf20Sopenharmony_ci struct nvif_push *push = wndw->wndw.push; 1188c2ecf20Sopenharmony_ci int ret; 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_ci if ((ret = PUSH_WAIT(push, 2))) 1218c2ecf20Sopenharmony_ci return ret; 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci PUSH_MTHD(push, NVC57E, SET_CONTEXT_DMA_ILUT, 0x00000000); 1248c2ecf20Sopenharmony_ci return 0; 1258c2ecf20Sopenharmony_ci} 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_cistatic int 1288c2ecf20Sopenharmony_ciwndwc57e_ilut_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw) 1298c2ecf20Sopenharmony_ci{ 1308c2ecf20Sopenharmony_ci struct nvif_push *push = wndw->wndw.push; 1318c2ecf20Sopenharmony_ci int ret; 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci if ((ret = PUSH_WAIT(push, 4))) 1348c2ecf20Sopenharmony_ci return ret; 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci PUSH_MTHD(push, NVC57E, SET_ILUT_CONTROL, 1378c2ecf20Sopenharmony_ci NVVAL(NVC57E, SET_ILUT_CONTROL, SIZE, asyw->xlut.i.size) | 1388c2ecf20Sopenharmony_ci NVVAL(NVC57E, SET_ILUT_CONTROL, MODE, asyw->xlut.i.mode) | 1398c2ecf20Sopenharmony_ci NVVAL(NVC57E, SET_ILUT_CONTROL, INTERPOLATE, asyw->xlut.i.output_mode), 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_ci SET_CONTEXT_DMA_ILUT, asyw->xlut.handle, 1428c2ecf20Sopenharmony_ci SET_OFFSET_ILUT, asyw->xlut.i.offset >> 8); 1438c2ecf20Sopenharmony_ci return 0; 1448c2ecf20Sopenharmony_ci} 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_cistatic u16 1478c2ecf20Sopenharmony_cifixedU0_16_FP16(u16 fixed) 1488c2ecf20Sopenharmony_ci{ 1498c2ecf20Sopenharmony_ci int sign = 0, exp = 0, man = 0; 1508c2ecf20Sopenharmony_ci if (fixed) { 1518c2ecf20Sopenharmony_ci while (--exp && !(fixed & 0x8000)) 1528c2ecf20Sopenharmony_ci fixed <<= 1; 1538c2ecf20Sopenharmony_ci man = ((fixed << 1) & 0xffc0) >> 6; 1548c2ecf20Sopenharmony_ci exp += 15; 1558c2ecf20Sopenharmony_ci } 1568c2ecf20Sopenharmony_ci return (sign << 15) | (exp << 10) | man; 1578c2ecf20Sopenharmony_ci} 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_cistatic void 1608c2ecf20Sopenharmony_ciwndwc57e_ilut_load(struct drm_color_lut *in, int size, void __iomem *mem) 1618c2ecf20Sopenharmony_ci{ 1628c2ecf20Sopenharmony_ci memset_io(mem, 0x00, 0x20); /* VSS header. */ 1638c2ecf20Sopenharmony_ci mem += 0x20; 1648c2ecf20Sopenharmony_ci 1658c2ecf20Sopenharmony_ci for (; size--; in++, mem += 0x08) { 1668c2ecf20Sopenharmony_ci u16 r = fixedU0_16_FP16(drm_color_lut_extract(in-> red, 16)); 1678c2ecf20Sopenharmony_ci u16 g = fixedU0_16_FP16(drm_color_lut_extract(in->green, 16)); 1688c2ecf20Sopenharmony_ci u16 b = fixedU0_16_FP16(drm_color_lut_extract(in-> blue, 16)); 1698c2ecf20Sopenharmony_ci writew(r, mem + 0); 1708c2ecf20Sopenharmony_ci writew(g, mem + 2); 1718c2ecf20Sopenharmony_ci writew(b, mem + 4); 1728c2ecf20Sopenharmony_ci } 1738c2ecf20Sopenharmony_ci 1748c2ecf20Sopenharmony_ci /* INTERPOLATE modes require a "next" entry to interpolate with, 1758c2ecf20Sopenharmony_ci * so we replicate the last entry to deal with this for now. 1768c2ecf20Sopenharmony_ci */ 1778c2ecf20Sopenharmony_ci writew(readw(mem - 8), mem + 0); 1788c2ecf20Sopenharmony_ci writew(readw(mem - 6), mem + 2); 1798c2ecf20Sopenharmony_ci writew(readw(mem - 4), mem + 4); 1808c2ecf20Sopenharmony_ci} 1818c2ecf20Sopenharmony_ci 1828c2ecf20Sopenharmony_cistatic bool 1838c2ecf20Sopenharmony_ciwndwc57e_ilut(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw, int size) 1848c2ecf20Sopenharmony_ci{ 1858c2ecf20Sopenharmony_ci if (size = size ? size : 1024, size != 256 && size != 1024) 1868c2ecf20Sopenharmony_ci return false; 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_ci if (size == 256) 1898c2ecf20Sopenharmony_ci asyw->xlut.i.mode = NVC57E_SET_ILUT_CONTROL_MODE_DIRECT8; 1908c2ecf20Sopenharmony_ci else 1918c2ecf20Sopenharmony_ci asyw->xlut.i.mode = NVC57E_SET_ILUT_CONTROL_MODE_DIRECT10; 1928c2ecf20Sopenharmony_ci 1938c2ecf20Sopenharmony_ci asyw->xlut.i.size = 4 /* VSS header. */ + size + 1 /* Entries. */; 1948c2ecf20Sopenharmony_ci asyw->xlut.i.output_mode = NVC57E_SET_ILUT_CONTROL_INTERPOLATE_DISABLE; 1958c2ecf20Sopenharmony_ci asyw->xlut.i.load = wndwc57e_ilut_load; 1968c2ecf20Sopenharmony_ci return true; 1978c2ecf20Sopenharmony_ci} 1988c2ecf20Sopenharmony_ci 1998c2ecf20Sopenharmony_ci/**************************************************************** 2008c2ecf20Sopenharmony_ci * Log2(block height) ----------------------------+ * 2018c2ecf20Sopenharmony_ci * Page Kind ----------------------------------+ | * 2028c2ecf20Sopenharmony_ci * Gob Height/Page Kind Generation ------+ | | * 2038c2ecf20Sopenharmony_ci * Sector layout -------+ | | | * 2048c2ecf20Sopenharmony_ci * Compression ------+ | | | | */ 2058c2ecf20Sopenharmony_ciconst u64 wndwc57e_modifiers[] = { /* | | | | | */ 2068c2ecf20Sopenharmony_ci DRM_FORMAT_MOD_NVIDIA_BLOCK_LINEAR_2D(0, 1, 2, 0x06, 0), 2078c2ecf20Sopenharmony_ci DRM_FORMAT_MOD_NVIDIA_BLOCK_LINEAR_2D(0, 1, 2, 0x06, 1), 2088c2ecf20Sopenharmony_ci DRM_FORMAT_MOD_NVIDIA_BLOCK_LINEAR_2D(0, 1, 2, 0x06, 2), 2098c2ecf20Sopenharmony_ci DRM_FORMAT_MOD_NVIDIA_BLOCK_LINEAR_2D(0, 1, 2, 0x06, 3), 2108c2ecf20Sopenharmony_ci DRM_FORMAT_MOD_NVIDIA_BLOCK_LINEAR_2D(0, 1, 2, 0x06, 4), 2118c2ecf20Sopenharmony_ci DRM_FORMAT_MOD_NVIDIA_BLOCK_LINEAR_2D(0, 1, 2, 0x06, 5), 2128c2ecf20Sopenharmony_ci DRM_FORMAT_MOD_LINEAR, 2138c2ecf20Sopenharmony_ci DRM_FORMAT_MOD_INVALID 2148c2ecf20Sopenharmony_ci}; 2158c2ecf20Sopenharmony_ci 2168c2ecf20Sopenharmony_cistatic const struct nv50_wndw_func 2178c2ecf20Sopenharmony_ciwndwc57e = { 2188c2ecf20Sopenharmony_ci .acquire = wndwc37e_acquire, 2198c2ecf20Sopenharmony_ci .release = wndwc37e_release, 2208c2ecf20Sopenharmony_ci .sema_set = wndwc37e_sema_set, 2218c2ecf20Sopenharmony_ci .sema_clr = wndwc37e_sema_clr, 2228c2ecf20Sopenharmony_ci .ntfy_set = wndwc37e_ntfy_set, 2238c2ecf20Sopenharmony_ci .ntfy_clr = wndwc37e_ntfy_clr, 2248c2ecf20Sopenharmony_ci .ntfy_reset = corec37d_ntfy_init, 2258c2ecf20Sopenharmony_ci .ntfy_wait_begun = base507c_ntfy_wait_begun, 2268c2ecf20Sopenharmony_ci .ilut = wndwc57e_ilut, 2278c2ecf20Sopenharmony_ci .ilut_identity = true, 2288c2ecf20Sopenharmony_ci .ilut_size = 1024, 2298c2ecf20Sopenharmony_ci .xlut_set = wndwc57e_ilut_set, 2308c2ecf20Sopenharmony_ci .xlut_clr = wndwc57e_ilut_clr, 2318c2ecf20Sopenharmony_ci .csc = base907c_csc, 2328c2ecf20Sopenharmony_ci .csc_set = wndwc57e_csc_set, 2338c2ecf20Sopenharmony_ci .csc_clr = wndwc57e_csc_clr, 2348c2ecf20Sopenharmony_ci .image_set = wndwc57e_image_set, 2358c2ecf20Sopenharmony_ci .image_clr = wndwc37e_image_clr, 2368c2ecf20Sopenharmony_ci .blend_set = wndwc37e_blend_set, 2378c2ecf20Sopenharmony_ci .update = wndwc37e_update, 2388c2ecf20Sopenharmony_ci}; 2398c2ecf20Sopenharmony_ci 2408c2ecf20Sopenharmony_ciint 2418c2ecf20Sopenharmony_ciwndwc57e_new(struct nouveau_drm *drm, enum drm_plane_type type, int index, 2428c2ecf20Sopenharmony_ci s32 oclass, struct nv50_wndw **pwndw) 2438c2ecf20Sopenharmony_ci{ 2448c2ecf20Sopenharmony_ci return wndwc37e_new_(&wndwc57e, drm, type, index, oclass, 2458c2ecf20Sopenharmony_ci BIT(index >> 1), pwndw); 2468c2ecf20Sopenharmony_ci} 247