1/*	$NetBSD: atom.h,v 1.3 2021/12/19 10:49:47 riastradh Exp $	*/
2
3#ifndef __NV50_KMS_ATOM_H__
4#define __NV50_KMS_ATOM_H__
5#define nv50_atom(p) container_of((p), struct nv50_atom, state)
6#include <drm/drm_atomic.h>
7
8struct nv50_atom {
9	struct drm_atomic_state state;
10
11	struct list_head outp;
12	bool lock_core;
13	bool flush_disable;
14};
15
16#define nv50_head_atom(p) container_of((p), struct nv50_head_atom, state)
17
18#ifdef __NetBSD__
19#  define	__lut_iomem	volatile
20#  define	__iomem		__lut_iomem
21#endif
22
23struct nv50_head_atom {
24	struct drm_crtc_state state;
25
26	struct {
27		u32 mask;
28		u32 olut;
29	} wndw;
30
31	struct {
32		u16 iW;
33		u16 iH;
34		u16 oW;
35		u16 oH;
36	} view;
37
38	struct nv50_head_mode {
39		bool interlace;
40		u32 clock;
41		struct {
42			u16 active;
43			u16 synce;
44			u16 blanke;
45			u16 blanks;
46		} h;
47		struct {
48			u32 active;
49			u16 synce;
50			u16 blanke;
51			u16 blanks;
52			u16 blank2s;
53			u16 blank2e;
54			u16 blankus;
55		} v;
56	} mode;
57
58	struct {
59		bool visible;
60		u32 handle;
61		u64 offset:40;
62		u8 buffer:1;
63		u8 mode:4;
64		u16 size:11;
65		u8 range:2;
66		u8 output_mode:2;
67		void (*load)(struct drm_color_lut *, int size, void __iomem *);
68	} olut;
69
70	struct {
71		bool visible;
72		u32 handle;
73		u64 offset:40;
74		u8  format;
75		u8  kind:7;
76		u8  layout:1;
77		u8  blockh:4;
78		u16 blocks:12;
79		u32 pitch:20;
80		u16 x;
81		u16 y;
82		u16 w;
83		u16 h;
84	} core;
85
86	struct {
87		bool visible;
88		u32 handle;
89		u64 offset:40;
90		u8  layout:2;
91		u8  format:8;
92	} curs;
93
94	struct {
95		u8  depth;
96		u8  cpp;
97		u16 x;
98		u16 y;
99		u16 w;
100		u16 h;
101	} base;
102
103	struct {
104		u8 cpp;
105	} ovly;
106
107	struct {
108		bool enable:1;
109		u8 bits:2;
110		u8 mode:4;
111	} dither;
112
113	struct {
114		struct {
115			u16 cos:12;
116			u16 sin:12;
117		} sat;
118	} procamp;
119
120	struct {
121		u8 nhsync:1;
122		u8 nvsync:1;
123		u8 depth:4;
124		u8 bpc;
125	} or;
126
127	/* Currently only used for MST */
128	struct {
129		int pbn;
130		u8 tu:6;
131	} dp;
132
133	union nv50_head_atom_mask {
134		struct {
135			bool olut:1;
136			bool core:1;
137			bool curs:1;
138			bool view:1;
139			bool mode:1;
140			bool base:1;
141			bool ovly:1;
142			bool dither:1;
143			bool procamp:1;
144			bool or:1;
145		};
146		u16 mask;
147	} set, clr;
148};
149
150static inline struct nv50_head_atom *
151nv50_head_atom_get(struct drm_atomic_state *state, struct drm_crtc *crtc)
152{
153	struct drm_crtc_state *statec = drm_atomic_get_crtc_state(state, crtc);
154	if (IS_ERR(statec))
155		return (void *)statec;
156	return nv50_head_atom(statec);
157}
158
159#define nv50_wndw_atom(p) container_of((p), struct nv50_wndw_atom, state)
160
161struct nv50_wndw_atom {
162	struct drm_plane_state state;
163
164	struct drm_property_blob *ilut;
165	bool visible;
166
167	struct {
168		u32  handle;
169		u16  offset:12;
170		bool awaken:1;
171	} ntfy;
172
173	struct {
174		u32 handle;
175		u16 offset:12;
176		u32 acquire;
177		u32 release;
178	} sema;
179
180	struct {
181		u32 handle;
182		struct {
183			u64 offset:40;
184			u8  buffer:1;
185			u8  enable:2;
186			u8  mode:4;
187			u16 size:11;
188			u8  range:2;
189			u8  output_mode:2;
190			void (*load)(struct drm_color_lut *, int size,
191				     void __iomem *);
192		} i;
193	} xlut;
194
195	struct {
196		u32 matrix[12];
197		bool valid;
198	} csc;
199
200	struct {
201		u8  mode:2;
202		u8  interval:4;
203
204		u8  colorspace:2;
205		u8  format;
206		u8  kind:7;
207		u8  layout:1;
208		u8  blockh:4;
209		u16 blocks[3];
210		u32 pitch[3];
211		u16 w;
212		u16 h;
213
214		u32 handle[6];
215		u64 offset[6];
216	} image;
217
218	struct {
219		u16 sx;
220		u16 sy;
221		u16 sw;
222		u16 sh;
223		u16 dw;
224		u16 dh;
225	} scale;
226
227	struct {
228		u16 x;
229		u16 y;
230	} point;
231
232	struct {
233		u8 depth;
234		u8 k1;
235		u8 src_color:4;
236		u8 dst_color:4;
237	} blend;
238
239	union nv50_wndw_atom_mask {
240		struct {
241			bool ntfy:1;
242			bool sema:1;
243			bool xlut:1;
244			bool csc:1;
245			bool image:1;
246			bool scale:1;
247			bool point:1;
248			bool blend:1;
249		};
250		u8 mask;
251	} set, clr;
252};
253
254#ifdef __NetBSD__
255#  undef	__iomem
256#endif
257
258#endif
259