xref: /linux/drivers/gpu/drm/nouveau/dispnv50/base907c.c (revision 6833d2a0c778252929805fabfdc89e4e181fcb82)
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 
2684e1d06bSBen Skeggs #include <nvhw/class/cl907c.h>
2784e1d06bSBen Skeggs 
286d6e11e2SBen Skeggs static int
29ccd27db8SBen Skeggs base907c_image_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
30ccd27db8SBen Skeggs {
316d6e11e2SBen Skeggs 	struct nvif_push *push = wndw->wndw.push;
326d6e11e2SBen Skeggs 	int ret;
336d6e11e2SBen Skeggs 
346d6e11e2SBen Skeggs 	if ((ret = PUSH_WAIT(push, 10)))
356d6e11e2SBen Skeggs 		return ret;
366d6e11e2SBen Skeggs 
376d6e11e2SBen Skeggs 	PUSH_NVSQ(push, NV907C, 0x0084, asyw->image.mode << 8 |
38ccd27db8SBen Skeggs 					asyw->image.interval << 4);
396d6e11e2SBen Skeggs 	PUSH_NVSQ(push, NV907C, 0x00c0, asyw->image.handle[0]);
406d6e11e2SBen Skeggs 	PUSH_NVSQ(push, NV907C, 0x0400, asyw->image.offset[0] >> 8,
416d6e11e2SBen Skeggs 				0x0404, 0x00000000,
426d6e11e2SBen Skeggs 				0x0408, asyw->image.h << 16 | asyw->image.w,
436d6e11e2SBen Skeggs 				0x040c, asyw->image.layout << 24 |
44b05d8738SBen Skeggs 				       (asyw->image.pitch[0] >> 8) << 8 |
45b05d8738SBen Skeggs 				        asyw->image.blocks[0] << 8 |
466d6e11e2SBen Skeggs 					asyw->image.blockh,
476d6e11e2SBen Skeggs 				0x0410, asyw->image.format << 8);
486d6e11e2SBen Skeggs 	return 0;
49ccd27db8SBen Skeggs }
50ccd27db8SBen Skeggs 
5134838908SBen Skeggs static int
52119608a7SBen Skeggs base907c_xlut_clr(struct nv50_wndw *wndw)
53119608a7SBen Skeggs {
5434838908SBen Skeggs 	struct nvif_push *push = wndw->wndw.push;
5534838908SBen Skeggs 	int ret;
5634838908SBen Skeggs 
5734838908SBen Skeggs 	if ((ret = PUSH_WAIT(push, 6)))
5834838908SBen Skeggs 		return ret;
5934838908SBen Skeggs 
6034838908SBen Skeggs 	PUSH_NVSQ(push, NV907C, 0x00e0, 0x00000000);
6134838908SBen Skeggs 	PUSH_NVSQ(push, NV907C, 0x00e8, 0x00000000);
6234838908SBen Skeggs 	PUSH_NVSQ(push, NV907C, 0x00fc, 0x00000000);
6334838908SBen Skeggs 	return 0;
64119608a7SBen Skeggs }
65119608a7SBen Skeggs 
66222439ebSBen Skeggs static int
67119608a7SBen Skeggs base907c_xlut_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
68119608a7SBen Skeggs {
69222439ebSBen Skeggs 	struct nvif_push *push = wndw->wndw.push;
70222439ebSBen Skeggs 	int ret;
71222439ebSBen Skeggs 
72222439ebSBen Skeggs 	if ((ret = PUSH_WAIT(push, 6)))
73222439ebSBen Skeggs 		return ret;
74222439ebSBen Skeggs 
75*6833d2a0SBen Skeggs 	PUSH_MTHD(push, NV907C, SET_BASE_LUT_LO,
76*6833d2a0SBen Skeggs 		  NVVAL(NV907C, SET_BASE_LUT_LO, ENABLE, asyw->xlut.i.enable) |
77*6833d2a0SBen Skeggs 		  NVVAL(NV907C, SET_BASE_LUT_LO, MODE, asyw->xlut.i.mode),
78*6833d2a0SBen Skeggs 
79*6833d2a0SBen Skeggs 				SET_BASE_LUT_HI, asyw->xlut.i.offset >> 8,
80*6833d2a0SBen Skeggs 
81*6833d2a0SBen Skeggs 				SET_OUTPUT_LUT_LO,
82*6833d2a0SBen Skeggs 		  NVDEF(NV907C, SET_OUTPUT_LUT_LO, ENABLE, USE_CORE_LUT));
83*6833d2a0SBen Skeggs 
84*6833d2a0SBen Skeggs 	PUSH_MTHD(push, NV907C, SET_CONTEXT_DMA_LUT, asyw->xlut.handle);
85222439ebSBen Skeggs 	return 0;
86119608a7SBen Skeggs }
87119608a7SBen Skeggs 
8813199270SIlia Mirkin static bool
8913199270SIlia Mirkin base907c_ilut(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw, int size)
90119608a7SBen Skeggs {
9113199270SIlia Mirkin 	if (size != 256 && size != 1024)
9213199270SIlia Mirkin 		return false;
9313199270SIlia Mirkin 
94*6833d2a0SBen Skeggs 	if (size == 1024)
95*6833d2a0SBen Skeggs 		asyw->xlut.i.mode = NV907C_SET_BASE_LUT_LO_MODE_INTERPOLATE_1025_UNITY_RANGE;
96*6833d2a0SBen Skeggs 	else
97*6833d2a0SBen Skeggs 		asyw->xlut.i.mode = NV907C_SET_BASE_LUT_LO_MODE_INTERPOLATE_257_UNITY_RANGE;
98*6833d2a0SBen Skeggs 
99*6833d2a0SBen Skeggs 	asyw->xlut.i.enable = NV907C_SET_BASE_LUT_LO_ENABLE_ENABLE;
100cb55cd0cSBen Skeggs 	asyw->xlut.i.load = head907d_olut_load;
10113199270SIlia Mirkin 	return true;
102119608a7SBen Skeggs }
103119608a7SBen Skeggs 
10488b70352SIlia Mirkin static inline u32
10588b70352SIlia Mirkin csc_drm_to_base(u64 in)
10688b70352SIlia Mirkin {
10788b70352SIlia Mirkin 	/* base takes a 19-bit 2's complement value in S3.16 format */
10888b70352SIlia Mirkin 	bool sign = in & BIT_ULL(63);
10988b70352SIlia Mirkin 	u32 integer = (in >> 32) & 0x7fffffff;
11088b70352SIlia Mirkin 	u32 fraction = in & 0xffffffff;
11188b70352SIlia Mirkin 
11288b70352SIlia Mirkin 	if (integer >= 4) {
11388b70352SIlia Mirkin 		return (1 << 18) - (sign ? 0 : 1);
11488b70352SIlia Mirkin 	} else {
11588b70352SIlia Mirkin 		u32 ret = (integer << 16) | (fraction >> 16);
11688b70352SIlia Mirkin 		if (sign)
11788b70352SIlia Mirkin 			ret = -ret;
11888b70352SIlia Mirkin 		return ret & GENMASK(18, 0);
11988b70352SIlia Mirkin 	}
12088b70352SIlia Mirkin }
12188b70352SIlia Mirkin 
122dffa4878SBen Skeggs void
12388b70352SIlia Mirkin base907c_csc(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw,
12488b70352SIlia Mirkin 	     const struct drm_color_ctm *ctm)
12588b70352SIlia Mirkin {
12688b70352SIlia Mirkin 	int i, j;
12788b70352SIlia Mirkin 
12888b70352SIlia Mirkin 	for (j = 0; j < 3; j++) {
12988b70352SIlia Mirkin 		for (i = 0; i < 4; i++) {
13088b70352SIlia Mirkin 			u32 *val = &asyw->csc.matrix[j * 4 + i];
13188b70352SIlia Mirkin 			/* DRM does not support constant offset, while
13288b70352SIlia Mirkin 			 * HW CSC does. Skip it. */
13388b70352SIlia Mirkin 			if (i == 3) {
13488b70352SIlia Mirkin 				*val = 0;
13588b70352SIlia Mirkin 			} else {
13688b70352SIlia Mirkin 				*val = csc_drm_to_base(ctm->matrix[j * 3 + i]);
13788b70352SIlia Mirkin 			}
13888b70352SIlia Mirkin 		}
13988b70352SIlia Mirkin 	}
14088b70352SIlia Mirkin }
14188b70352SIlia Mirkin 
142cfb4120dSBen Skeggs static int
14388b70352SIlia Mirkin base907c_csc_clr(struct nv50_wndw *wndw)
14488b70352SIlia Mirkin {
145cfb4120dSBen Skeggs 	struct nvif_push *push = wndw->wndw.push;
146cfb4120dSBen Skeggs 	int ret;
147cfb4120dSBen Skeggs 
148cfb4120dSBen Skeggs 	if ((ret = PUSH_WAIT(push, 2)))
149cfb4120dSBen Skeggs 		return ret;
150cfb4120dSBen Skeggs 
1512740edb3SBen Skeggs 	PUSH_MTHD(push, NV907C, SET_CSC_RED2RED,
1522740edb3SBen Skeggs 		  NVDEF(NV907C, SET_CSC_RED2RED, OWNER, CORE));
153cfb4120dSBen Skeggs 	return 0;
15488b70352SIlia Mirkin }
15588b70352SIlia Mirkin 
15672587dcaSBen Skeggs static int
15788b70352SIlia Mirkin base907c_csc_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
15888b70352SIlia Mirkin {
15972587dcaSBen Skeggs 	struct nvif_push *push = wndw->wndw.push;
16072587dcaSBen Skeggs 	int ret;
16172587dcaSBen Skeggs 
16272587dcaSBen Skeggs 	if ((ret = PUSH_WAIT(push, 13)))
16372587dcaSBen Skeggs 		return ret;
16472587dcaSBen Skeggs 
16584e1d06bSBen Skeggs 	PUSH_MTHD(push, NV907C, SET_CSC_RED2RED,
16684e1d06bSBen Skeggs 		  NVDEF(NV907C, SET_CSC_RED2RED, OWNER, BASE) |
16784e1d06bSBen Skeggs 		  NVVAL(NV907C, SET_CSC_RED2RED, COEFF, asyw->csc.matrix[0]),
16884e1d06bSBen Skeggs 
16984e1d06bSBen Skeggs 				SET_CSC_GRN2RED, &asyw->csc.matrix[1], 11);
17072587dcaSBen Skeggs 	return 0;
17188b70352SIlia Mirkin }
17288b70352SIlia Mirkin 
17388b600d4SBen Skeggs const struct nv50_wndw_func
174ccd27db8SBen Skeggs base907c = {
175ccd27db8SBen Skeggs 	.acquire = base507c_acquire,
176ccd27db8SBen Skeggs 	.release = base507c_release,
177ccd27db8SBen Skeggs 	.sema_set = base507c_sema_set,
178ccd27db8SBen Skeggs 	.sema_clr = base507c_sema_clr,
179ccd27db8SBen Skeggs 	.ntfy_reset = base507c_ntfy_reset,
180ccd27db8SBen Skeggs 	.ntfy_set = base507c_ntfy_set,
181ccd27db8SBen Skeggs 	.ntfy_clr = base507c_ntfy_clr,
182ccd27db8SBen Skeggs 	.ntfy_wait_begun = base507c_ntfy_wait_begun,
183119608a7SBen Skeggs 	.ilut = base907c_ilut,
18488b70352SIlia Mirkin 	.csc = base907c_csc,
18588b70352SIlia Mirkin 	.csc_set = base907c_csc_set,
18688b70352SIlia Mirkin 	.csc_clr = base907c_csc_clr,
187119608a7SBen Skeggs 	.olut_core = true,
18813199270SIlia Mirkin 	.ilut_size = 1024,
189119608a7SBen Skeggs 	.xlut_set = base907c_xlut_set,
190119608a7SBen Skeggs 	.xlut_clr = base907c_xlut_clr,
191ccd27db8SBen Skeggs 	.image_set = base907c_image_set,
192ccd27db8SBen Skeggs 	.image_clr = base507c_image_clr,
19353e0a3e7SBen Skeggs 	.update = base507c_update,
194ccd27db8SBen Skeggs };
195ccd27db8SBen Skeggs 
196ccd27db8SBen Skeggs int
197ccd27db8SBen Skeggs base907c_new(struct nouveau_drm *drm, int head, s32 oclass,
198ccd27db8SBen Skeggs 	     struct nv50_wndw **pwndw)
199ccd27db8SBen Skeggs {
20053e0a3e7SBen Skeggs 	return base507c_new_(&base907c, base507c_format, drm, head, oclass,
20153e0a3e7SBen Skeggs 			     0x00000002 << (head * 4), pwndw);
202ccd27db8SBen Skeggs }
203