1/*	$NetBSD: nouveau_nvkm_engine_disp_piocnv50.c,v 1.3 2021/12/18 23:45:35 riastradh Exp $	*/
2
3/*
4 * Copyright 2012 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 * Authors: Ben Skeggs
25 */
26#include <sys/cdefs.h>
27__KERNEL_RCSID(0, "$NetBSD: nouveau_nvkm_engine_disp_piocnv50.c,v 1.3 2021/12/18 23:45:35 riastradh Exp $");
28
29#include "channv50.h"
30#include "rootnv50.h"
31
32#include <subdev/timer.h>
33
34static void
35nv50_disp_pioc_fini(struct nv50_disp_chan *chan)
36{
37	struct nv50_disp *disp = chan->disp;
38	struct nvkm_subdev *subdev = &disp->base.engine.subdev;
39	struct nvkm_device *device = subdev->device;
40	int ctrl = chan->chid.ctrl;
41	int user = chan->chid.user;
42
43	nvkm_mask(device, 0x610200 + (ctrl * 0x10), 0x00000001, 0x00000000);
44	if (nvkm_msec(device, 2000,
45		if (!(nvkm_rd32(device, 0x610200 + (ctrl * 0x10)) & 0x00030000))
46			break;
47	) < 0) {
48		nvkm_error(subdev, "ch %d timeout: %08x\n", user,
49			   nvkm_rd32(device, 0x610200 + (ctrl * 0x10)));
50	}
51}
52
53static int
54nv50_disp_pioc_init(struct nv50_disp_chan *chan)
55{
56	struct nv50_disp *disp = chan->disp;
57	struct nvkm_subdev *subdev = &disp->base.engine.subdev;
58	struct nvkm_device *device = subdev->device;
59	int ctrl = chan->chid.ctrl;
60	int user = chan->chid.user;
61
62	nvkm_wr32(device, 0x610200 + (ctrl * 0x10), 0x00002000);
63	if (nvkm_msec(device, 2000,
64		if (!(nvkm_rd32(device, 0x610200 + (ctrl * 0x10)) & 0x00030000))
65			break;
66	) < 0) {
67		nvkm_error(subdev, "ch %d timeout0: %08x\n", user,
68			   nvkm_rd32(device, 0x610200 + (ctrl * 0x10)));
69		return -EBUSY;
70	}
71
72	nvkm_wr32(device, 0x610200 + (ctrl * 0x10), 0x00000001);
73	if (nvkm_msec(device, 2000,
74		u32 tmp = nvkm_rd32(device, 0x610200 + (ctrl * 0x10));
75		if ((tmp & 0x00030000) == 0x00010000)
76			break;
77	) < 0) {
78		nvkm_error(subdev, "ch %d timeout1: %08x\n", user,
79			   nvkm_rd32(device, 0x610200 + (ctrl * 0x10)));
80		return -EBUSY;
81	}
82
83	return 0;
84}
85
86const struct nv50_disp_chan_func
87nv50_disp_pioc_func = {
88	.init = nv50_disp_pioc_init,
89	.fini = nv50_disp_pioc_fini,
90	.intr = nv50_disp_chan_intr,
91	.user = nv50_disp_chan_user,
92};
93