xref: /linux/drivers/gpu/drm/nouveau/dispnv50/base907c.c (revision 3a39d672e7f48b8d6b91a09afa4b55352773b4b5)
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
base907c_image_set(struct nv50_wndw * wndw,struct nv50_wndw_atom * asyw)29ccd27db8SBen Skeggs base907c_image_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
30ccd27db8SBen Skeggs {
31*61671d85SBen 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 
37f844eb48SBen Skeggs 	PUSH_MTHD(push, NV907C, SET_PRESENT_CONTROL,
38f844eb48SBen Skeggs 		  NVVAL(NV907C, SET_PRESENT_CONTROL, BEGIN_MODE, asyw->image.mode) |
39f844eb48SBen Skeggs 		  NVDEF(NV907C, SET_PRESENT_CONTROL, TIMESTAMP_MODE, DISABLE) |
40f844eb48SBen Skeggs 		  NVVAL(NV907C, SET_PRESENT_CONTROL, MIN_PRESENT_INTERVAL, asyw->image.interval));
41f844eb48SBen Skeggs 
42f844eb48SBen Skeggs 	PUSH_MTHD(push, NV907C, SET_CONTEXT_DMAS_ISO(0), asyw->image.handle, 1);
43f844eb48SBen Skeggs 
44f844eb48SBen Skeggs 	PUSH_MTHD(push, NV907C, SURFACE_SET_OFFSET(0, 0), asyw->image.offset[0] >> 8,
45f844eb48SBen Skeggs 				SURFACE_SET_OFFSET(0, 1), 0x00000000,
46f844eb48SBen Skeggs 
47f844eb48SBen Skeggs 				SURFACE_SET_SIZE(0),
48f844eb48SBen Skeggs 		  NVVAL(NV907C, SURFACE_SET_SIZE, WIDTH, asyw->image.w) |
49f844eb48SBen Skeggs 		  NVVAL(NV907C, SURFACE_SET_SIZE, HEIGHT, asyw->image.h),
50f844eb48SBen Skeggs 
51f844eb48SBen Skeggs 				SURFACE_SET_STORAGE(0),
52f844eb48SBen Skeggs 		  NVVAL(NV907C, SURFACE_SET_STORAGE, BLOCK_HEIGHT, asyw->image.blockh) |
53f844eb48SBen Skeggs 		  NVVAL(NV907C, SURFACE_SET_STORAGE, PITCH, asyw->image.pitch[0] >> 8) |
54f844eb48SBen Skeggs 		  NVVAL(NV907C, SURFACE_SET_STORAGE, PITCH, asyw->image.blocks[0]) |
55f844eb48SBen Skeggs 		  NVVAL(NV907C, SURFACE_SET_STORAGE, MEMORY_LAYOUT, asyw->image.layout),
56f844eb48SBen Skeggs 
57f844eb48SBen Skeggs 				SURFACE_SET_PARAMS(0),
58f844eb48SBen Skeggs 		  NVVAL(NV907C, SURFACE_SET_PARAMS, FORMAT, asyw->image.format) |
59f844eb48SBen Skeggs 		  NVDEF(NV907C, SURFACE_SET_PARAMS, SUPER_SAMPLE, X1_AA) |
60f844eb48SBen Skeggs 		  NVDEF(NV907C, SURFACE_SET_PARAMS, GAMMA, LINEAR) |
61f844eb48SBen Skeggs 		  NVDEF(NV907C, SURFACE_SET_PARAMS, LAYOUT, FRM));
626d6e11e2SBen Skeggs 	return 0;
63ccd27db8SBen Skeggs }
64ccd27db8SBen Skeggs 
6534838908SBen Skeggs static int
base907c_xlut_clr(struct nv50_wndw * wndw)66119608a7SBen Skeggs base907c_xlut_clr(struct nv50_wndw *wndw)
67119608a7SBen Skeggs {
68*61671d85SBen Skeggs 	struct nvif_push *push = &wndw->wndw.push;
6934838908SBen Skeggs 	int ret;
7034838908SBen Skeggs 
7134838908SBen Skeggs 	if ((ret = PUSH_WAIT(push, 6)))
7234838908SBen Skeggs 		return ret;
7334838908SBen Skeggs 
7466f7b7bdSBen Skeggs 	PUSH_MTHD(push, NV907C, SET_BASE_LUT_LO,
7566f7b7bdSBen Skeggs 		  NVDEF(NV907C, SET_BASE_LUT_LO, ENABLE, DISABLE));
7666f7b7bdSBen Skeggs 
7766f7b7bdSBen Skeggs 	PUSH_MTHD(push, NV907C, SET_OUTPUT_LUT_LO,
7866f7b7bdSBen Skeggs 		  NVDEF(NV907C, SET_OUTPUT_LUT_LO, ENABLE, DISABLE));
7966f7b7bdSBen Skeggs 
8066f7b7bdSBen Skeggs 	PUSH_MTHD(push, NV907C, SET_CONTEXT_DMA_LUT, 0x00000000);
8134838908SBen Skeggs 	return 0;
82119608a7SBen Skeggs }
83119608a7SBen Skeggs 
84222439ebSBen Skeggs static int
base907c_xlut_set(struct nv50_wndw * wndw,struct nv50_wndw_atom * asyw)85119608a7SBen Skeggs base907c_xlut_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
86119608a7SBen Skeggs {
87*61671d85SBen Skeggs 	struct nvif_push *push = &wndw->wndw.push;
88222439ebSBen Skeggs 	int ret;
89222439ebSBen Skeggs 
90222439ebSBen Skeggs 	if ((ret = PUSH_WAIT(push, 6)))
91222439ebSBen Skeggs 		return ret;
92222439ebSBen Skeggs 
936833d2a0SBen Skeggs 	PUSH_MTHD(push, NV907C, SET_BASE_LUT_LO,
946833d2a0SBen Skeggs 		  NVVAL(NV907C, SET_BASE_LUT_LO, ENABLE, asyw->xlut.i.enable) |
956833d2a0SBen Skeggs 		  NVVAL(NV907C, SET_BASE_LUT_LO, MODE, asyw->xlut.i.mode),
966833d2a0SBen Skeggs 
976833d2a0SBen Skeggs 				SET_BASE_LUT_HI, asyw->xlut.i.offset >> 8,
986833d2a0SBen Skeggs 
996833d2a0SBen Skeggs 				SET_OUTPUT_LUT_LO,
1006833d2a0SBen Skeggs 		  NVDEF(NV907C, SET_OUTPUT_LUT_LO, ENABLE, USE_CORE_LUT));
1016833d2a0SBen Skeggs 
1026833d2a0SBen Skeggs 	PUSH_MTHD(push, NV907C, SET_CONTEXT_DMA_LUT, asyw->xlut.handle);
103222439ebSBen Skeggs 	return 0;
104119608a7SBen Skeggs }
105119608a7SBen Skeggs 
10679af598aSLyude Paul static void
base907c_ilut(struct nv50_wndw * wndw,struct nv50_wndw_atom * asyw,int size)10713199270SIlia Mirkin base907c_ilut(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw, int size)
108119608a7SBen Skeggs {
1096833d2a0SBen Skeggs 	if (size == 1024)
1106833d2a0SBen Skeggs 		asyw->xlut.i.mode = NV907C_SET_BASE_LUT_LO_MODE_INTERPOLATE_1025_UNITY_RANGE;
1116833d2a0SBen Skeggs 	else
1126833d2a0SBen Skeggs 		asyw->xlut.i.mode = NV907C_SET_BASE_LUT_LO_MODE_INTERPOLATE_257_UNITY_RANGE;
1136833d2a0SBen Skeggs 
1146833d2a0SBen Skeggs 	asyw->xlut.i.enable = NV907C_SET_BASE_LUT_LO_ENABLE_ENABLE;
115cb55cd0cSBen Skeggs 	asyw->xlut.i.load = head907d_olut_load;
116119608a7SBen Skeggs }
117119608a7SBen Skeggs 
11888b70352SIlia Mirkin static inline u32
csc_drm_to_base(u64 in)11988b70352SIlia Mirkin csc_drm_to_base(u64 in)
12088b70352SIlia Mirkin {
12188b70352SIlia Mirkin 	/* base takes a 19-bit 2's complement value in S3.16 format */
12288b70352SIlia Mirkin 	bool sign = in & BIT_ULL(63);
12388b70352SIlia Mirkin 	u32 integer = (in >> 32) & 0x7fffffff;
12488b70352SIlia Mirkin 	u32 fraction = in & 0xffffffff;
12588b70352SIlia Mirkin 
12688b70352SIlia Mirkin 	if (integer >= 4) {
12788b70352SIlia Mirkin 		return (1 << 18) - (sign ? 0 : 1);
12888b70352SIlia Mirkin 	} else {
12988b70352SIlia Mirkin 		u32 ret = (integer << 16) | (fraction >> 16);
13088b70352SIlia Mirkin 		if (sign)
13188b70352SIlia Mirkin 			ret = -ret;
13288b70352SIlia Mirkin 		return ret & GENMASK(18, 0);
13388b70352SIlia Mirkin 	}
13488b70352SIlia Mirkin }
13588b70352SIlia Mirkin 
136dffa4878SBen Skeggs void
base907c_csc(struct nv50_wndw * wndw,struct nv50_wndw_atom * asyw,const struct drm_color_ctm * ctm)13788b70352SIlia Mirkin base907c_csc(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw,
13888b70352SIlia Mirkin 	     const struct drm_color_ctm *ctm)
13988b70352SIlia Mirkin {
14088b70352SIlia Mirkin 	int i, j;
14188b70352SIlia Mirkin 
14288b70352SIlia Mirkin 	for (j = 0; j < 3; j++) {
14388b70352SIlia Mirkin 		for (i = 0; i < 4; i++) {
14488b70352SIlia Mirkin 			u32 *val = &asyw->csc.matrix[j * 4 + i];
14588b70352SIlia Mirkin 			/* DRM does not support constant offset, while
14688b70352SIlia Mirkin 			 * HW CSC does. Skip it. */
14788b70352SIlia Mirkin 			if (i == 3) {
14888b70352SIlia Mirkin 				*val = 0;
14988b70352SIlia Mirkin 			} else {
15088b70352SIlia Mirkin 				*val = csc_drm_to_base(ctm->matrix[j * 3 + i]);
15188b70352SIlia Mirkin 			}
15288b70352SIlia Mirkin 		}
15388b70352SIlia Mirkin 	}
15488b70352SIlia Mirkin }
15588b70352SIlia Mirkin 
156cfb4120dSBen Skeggs static int
base907c_csc_clr(struct nv50_wndw * wndw)15788b70352SIlia Mirkin base907c_csc_clr(struct nv50_wndw *wndw)
15888b70352SIlia Mirkin {
159*61671d85SBen Skeggs 	struct nvif_push *push = &wndw->wndw.push;
160cfb4120dSBen Skeggs 	int ret;
161cfb4120dSBen Skeggs 
162cfb4120dSBen Skeggs 	if ((ret = PUSH_WAIT(push, 2)))
163cfb4120dSBen Skeggs 		return ret;
164cfb4120dSBen Skeggs 
1652740edb3SBen Skeggs 	PUSH_MTHD(push, NV907C, SET_CSC_RED2RED,
1662740edb3SBen Skeggs 		  NVDEF(NV907C, SET_CSC_RED2RED, OWNER, CORE));
167cfb4120dSBen Skeggs 	return 0;
16888b70352SIlia Mirkin }
16988b70352SIlia Mirkin 
17072587dcaSBen Skeggs static int
base907c_csc_set(struct nv50_wndw * wndw,struct nv50_wndw_atom * asyw)17188b70352SIlia Mirkin base907c_csc_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
17288b70352SIlia Mirkin {
173*61671d85SBen Skeggs 	struct nvif_push *push = &wndw->wndw.push;
17472587dcaSBen Skeggs 	int ret;
17572587dcaSBen Skeggs 
17672587dcaSBen Skeggs 	if ((ret = PUSH_WAIT(push, 13)))
17772587dcaSBen Skeggs 		return ret;
17872587dcaSBen Skeggs 
17984e1d06bSBen Skeggs 	PUSH_MTHD(push, NV907C, SET_CSC_RED2RED,
18084e1d06bSBen Skeggs 		  NVDEF(NV907C, SET_CSC_RED2RED, OWNER, BASE) |
18184e1d06bSBen Skeggs 		  NVVAL(NV907C, SET_CSC_RED2RED, COEFF, asyw->csc.matrix[0]),
18284e1d06bSBen Skeggs 
18384e1d06bSBen Skeggs 				SET_CSC_GRN2RED, &asyw->csc.matrix[1], 11);
18472587dcaSBen Skeggs 	return 0;
18588b70352SIlia Mirkin }
18688b70352SIlia Mirkin 
18788b600d4SBen Skeggs const struct nv50_wndw_func
188ccd27db8SBen Skeggs base907c = {
189ccd27db8SBen Skeggs 	.acquire = base507c_acquire,
190ccd27db8SBen Skeggs 	.release = base507c_release,
191ccd27db8SBen Skeggs 	.sema_set = base507c_sema_set,
192ccd27db8SBen Skeggs 	.sema_clr = base507c_sema_clr,
193ccd27db8SBen Skeggs 	.ntfy_reset = base507c_ntfy_reset,
194ccd27db8SBen Skeggs 	.ntfy_set = base507c_ntfy_set,
195ccd27db8SBen Skeggs 	.ntfy_clr = base507c_ntfy_clr,
196ccd27db8SBen Skeggs 	.ntfy_wait_begun = base507c_ntfy_wait_begun,
197119608a7SBen Skeggs 	.ilut = base907c_ilut,
19888b70352SIlia Mirkin 	.csc = base907c_csc,
19988b70352SIlia Mirkin 	.csc_set = base907c_csc_set,
20088b70352SIlia Mirkin 	.csc_clr = base907c_csc_clr,
201119608a7SBen Skeggs 	.olut_core = true,
20213199270SIlia Mirkin 	.ilut_size = 1024,
203119608a7SBen Skeggs 	.xlut_set = base907c_xlut_set,
204119608a7SBen Skeggs 	.xlut_clr = base907c_xlut_clr,
205ccd27db8SBen Skeggs 	.image_set = base907c_image_set,
206ccd27db8SBen Skeggs 	.image_clr = base507c_image_clr,
20753e0a3e7SBen Skeggs 	.update = base507c_update,
208ccd27db8SBen Skeggs };
209ccd27db8SBen Skeggs 
210ccd27db8SBen Skeggs int
base907c_new(struct nouveau_drm * drm,int head,s32 oclass,struct nv50_wndw ** pwndw)211ccd27db8SBen Skeggs base907c_new(struct nouveau_drm *drm, int head, s32 oclass,
212ccd27db8SBen Skeggs 	     struct nv50_wndw **pwndw)
213ccd27db8SBen Skeggs {
21453e0a3e7SBen Skeggs 	return base507c_new_(&base907c, base507c_format, drm, head, oclass,
21553e0a3e7SBen Skeggs 			     0x00000002 << (head * 4), pwndw);
216ccd27db8SBen Skeggs }
217