xref: /netbsd-src/sys/external/bsd/drm2/dist/drm/nouveau/dispnv50/nouveau_dispnv50_base907c.c (revision 41ec02673d281bbb3d38e6c78504ce6e30c228c1)
1 /*	$NetBSD: nouveau_dispnv50_base907c.c,v 1.2 2021/12/18 23:45:32 riastradh Exp $	*/
2 
3 /*
4  * Copyright 2018 Red Hat Inc.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22  * OTHER DEALINGS IN THE SOFTWARE.
23  */
24 #include <sys/cdefs.h>
25 __KERNEL_RCSID(0, "$NetBSD: nouveau_dispnv50_base907c.c,v 1.2 2021/12/18 23:45:32 riastradh Exp $");
26 
27 #include "base.h"
28 
29 static void
base907c_image_set(struct nv50_wndw * wndw,struct nv50_wndw_atom * asyw)30 base907c_image_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
31 {
32 	u32 *push;
33 	if ((push = evo_wait(&wndw->wndw, 10))) {
34 		evo_mthd(push, 0x0084, 1);
35 		evo_data(push, asyw->image.mode << 8 |
36 			       asyw->image.interval << 4);
37 		evo_mthd(push, 0x00c0, 1);
38 		evo_data(push, asyw->image.handle[0]);
39 		evo_mthd(push, 0x0400, 5);
40 		evo_data(push, asyw->image.offset[0] >> 8);
41 		evo_data(push, 0x00000000);
42 		evo_data(push, asyw->image.h << 16 | asyw->image.w);
43 		evo_data(push, asyw->image.layout << 24 |
44 			       (asyw->image.pitch[0] >> 8) << 8 |
45 			       asyw->image.blocks[0] << 8 |
46 			       asyw->image.blockh);
47 		evo_data(push, asyw->image.format << 8);
48 		evo_kick(push, &wndw->wndw);
49 	}
50 }
51 
52 static void
base907c_xlut_clr(struct nv50_wndw * wndw)53 base907c_xlut_clr(struct nv50_wndw *wndw)
54 {
55 	u32 *push;
56 	if ((push = evo_wait(&wndw->wndw, 6))) {
57 		evo_mthd(push, 0x00e0, 1);
58 		evo_data(push, 0x00000000);
59 		evo_mthd(push, 0x00e8, 1);
60 		evo_data(push, 0x00000000);
61 		evo_mthd(push, 0x00fc, 1);
62 		evo_data(push, 0x00000000);
63 		evo_kick(push, &wndw->wndw);
64 	}
65 }
66 
67 static void
base907c_xlut_set(struct nv50_wndw * wndw,struct nv50_wndw_atom * asyw)68 base907c_xlut_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
69 {
70 	u32 *push;
71 	if ((push = evo_wait(&wndw->wndw, 6))) {
72 		evo_mthd(push, 0x00e0, 3);
73 		evo_data(push, asyw->xlut.i.enable << 30 |
74 			       asyw->xlut.i.mode << 24);
75 		evo_data(push, asyw->xlut.i.offset >> 8);
76 		evo_data(push, 0x40000000);
77 		evo_mthd(push, 0x00fc, 1);
78 		evo_data(push, asyw->xlut.handle);
79 		evo_kick(push, &wndw->wndw);
80 	}
81 }
82 
83 static bool
base907c_ilut(struct nv50_wndw * wndw,struct nv50_wndw_atom * asyw,int size)84 base907c_ilut(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw, int size)
85 {
86 	if (size != 256 && size != 1024)
87 		return false;
88 
89 	asyw->xlut.i.mode = size == 1024 ? 4 : 7;
90 	asyw->xlut.i.enable = 2;
91 	asyw->xlut.i.load = head907d_olut_load;
92 	return true;
93 }
94 
95 static inline u32
csc_drm_to_base(u64 in)96 csc_drm_to_base(u64 in)
97 {
98 	/* base takes a 19-bit 2's complement value in S3.16 format */
99 	bool sign = in & BIT_ULL(63);
100 	u32 integer = (in >> 32) & 0x7fffffff;
101 	u32 fraction = in & 0xffffffff;
102 
103 	if (integer >= 4) {
104 		return (1 << 18) - (sign ? 0 : 1);
105 	} else {
106 		u32 ret = (integer << 16) | (fraction >> 16);
107 		if (sign)
108 			ret = -ret;
109 		return ret & GENMASK(18, 0);
110 	}
111 }
112 
113 void
base907c_csc(struct nv50_wndw * wndw,struct nv50_wndw_atom * asyw,const struct drm_color_ctm * ctm)114 base907c_csc(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw,
115 	     const struct drm_color_ctm *ctm)
116 {
117 	int i, j;
118 
119 	for (j = 0; j < 3; j++) {
120 		for (i = 0; i < 4; i++) {
121 			u32 *val = &asyw->csc.matrix[j * 4 + i];
122 			/* DRM does not support constant offset, while
123 			 * HW CSC does. Skip it. */
124 			if (i == 3) {
125 				*val = 0;
126 			} else {
127 				*val = csc_drm_to_base(ctm->matrix[j * 3 + i]);
128 			}
129 		}
130 	}
131 }
132 
133 static void
base907c_csc_clr(struct nv50_wndw * wndw)134 base907c_csc_clr(struct nv50_wndw *wndw)
135 {
136 	u32 *push;
137 	if ((push = evo_wait(&wndw->wndw, 2))) {
138 		evo_mthd(push, 0x0140, 1);
139 		evo_data(push, 0x00000000);
140 		evo_kick(push, &wndw->wndw);
141 	}
142 }
143 
144 static void
base907c_csc_set(struct nv50_wndw * wndw,struct nv50_wndw_atom * asyw)145 base907c_csc_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
146 {
147 	u32 *push, i;
148 	if ((push = evo_wait(&wndw->wndw, 13))) {
149 		evo_mthd(push, 0x0140, 12);
150 		evo_data(push, asyw->csc.matrix[0] | 0x80000000);
151 		for (i = 1; i < 12; i++)
152 			evo_data(push, asyw->csc.matrix[i]);
153 		evo_kick(push, &wndw->wndw);
154 	}
155 }
156 
157 const struct nv50_wndw_func
158 base907c = {
159 	.acquire = base507c_acquire,
160 	.release = base507c_release,
161 	.sema_set = base507c_sema_set,
162 	.sema_clr = base507c_sema_clr,
163 	.ntfy_reset = base507c_ntfy_reset,
164 	.ntfy_set = base507c_ntfy_set,
165 	.ntfy_clr = base507c_ntfy_clr,
166 	.ntfy_wait_begun = base507c_ntfy_wait_begun,
167 	.ilut = base907c_ilut,
168 	.csc = base907c_csc,
169 	.csc_set = base907c_csc_set,
170 	.csc_clr = base907c_csc_clr,
171 	.olut_core = true,
172 	.ilut_size = 1024,
173 	.xlut_set = base907c_xlut_set,
174 	.xlut_clr = base907c_xlut_clr,
175 	.image_set = base907c_image_set,
176 	.image_clr = base507c_image_clr,
177 	.update = base507c_update,
178 };
179 
180 int
base907c_new(struct nouveau_drm * drm,int head,s32 oclass,struct nv50_wndw ** pwndw)181 base907c_new(struct nouveau_drm *drm, int head, s32 oclass,
182 	     struct nv50_wndw **pwndw)
183 {
184 	return base507c_new_(&base907c, base507c_format, drm, head, oclass,
185 			     0x00000002 << (head * 4), pwndw);
186 }
187