xref: /netbsd-src/sys/external/bsd/drm2/dist/drm/nouveau/dispnv50/nouveau_dispnv50_wimmc37b.c (revision 41ec02673d281bbb3d38e6c78504ce6e30c228c1)
1 /*	$NetBSD: nouveau_dispnv50_wimmc37b.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_wimmc37b.c,v 1.2 2021/12/18 23:45:32 riastradh Exp $");
26 
27 #include "wimm.h"
28 #include "atom.h"
29 #include "wndw.h"
30 
31 #include <nvif/clc37b.h>
32 
33 static void
wimmc37b_update(struct nv50_wndw * wndw,u32 * interlock)34 wimmc37b_update(struct nv50_wndw *wndw, u32 *interlock)
35 {
36 	u32 *push;
37 	if ((push = evo_wait(&wndw->wimm, 2))) {
38 		evo_mthd(push, 0x0200, 1);
39 		if (interlock[NV50_DISP_INTERLOCK_WNDW] & wndw->interlock.data)
40 			evo_data(push, 0x00000003);
41 		else
42 			evo_data(push, 0x00000001);
43 		evo_kick(push, &wndw->wimm);
44 	}
45 }
46 
47 static void
wimmc37b_point(struct nv50_wndw * wndw,struct nv50_wndw_atom * asyw)48 wimmc37b_point(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
49 {
50 	u32 *push;
51 	if ((push = evo_wait(&wndw->wimm, 2))) {
52 		evo_mthd(push, 0x0208, 1);
53 		evo_data(push, asyw->point.y << 16 | asyw->point.x);
54 		evo_kick(push, &wndw->wimm);
55 	}
56 }
57 
58 static const struct nv50_wimm_func
59 wimmc37b = {
60 	.point = wimmc37b_point,
61 	.update = wimmc37b_update,
62 };
63 
64 static int
wimmc37b_init_(const struct nv50_wimm_func * func,struct nouveau_drm * drm,s32 oclass,struct nv50_wndw * wndw)65 wimmc37b_init_(const struct nv50_wimm_func *func, struct nouveau_drm *drm,
66 	       s32 oclass, struct nv50_wndw *wndw)
67 {
68 	struct nvc37b_window_imm_channel_dma_v0 args = {
69 		.pushbuf = 0xb0007b00 | wndw->id,
70 		.index = wndw->id,
71 	};
72 	struct nv50_disp *disp = nv50_disp(drm->dev);
73 	int ret;
74 
75 	ret = nv50_dmac_create(&drm->client.device, &disp->disp->object,
76 			       &oclass, 0, &args, sizeof(args), 0,
77 			       &wndw->wimm);
78 	if (ret) {
79 		NV_ERROR(drm, "wimm%04x allocation failed: %d\n", oclass, ret);
80 		return ret;
81 	}
82 
83 	wndw->interlock.wimm = wndw->interlock.data;
84 	wndw->immd = func;
85 	return 0;
86 }
87 
88 int
wimmc37b_init(struct nouveau_drm * drm,s32 oclass,struct nv50_wndw * wndw)89 wimmc37b_init(struct nouveau_drm *drm, s32 oclass, struct nv50_wndw *wndw)
90 {
91 	return wimmc37b_init_(&wimmc37b, drm, oclass, wndw);
92 }
93