1160814Ssimon/*	$NetBSD: nouveau_nvkm_engine_disp_dmacgp102.c,v 1.2 2021/12/18 23:45:35 riastradh Exp $	*/
2296341Sdelphij
3296341Sdelphij/*
4296341Sdelphij * Copyright 2016 Red Hat Inc.
5160814Ssimon *
6160814Ssimon * Permission is hereby granted, free of charge, to any person obtaining a
7160814Ssimon * copy of this software and associated documentation files (the "Software"),
8160814Ssimon * to deal in the Software without restriction, including without limitation
9160814Ssimon * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10160814Ssimon * and/or sell copies of the Software, and to permit persons to whom the
11160814Ssimon * Software is furnished to do so, subject to the following conditions:
12160814Ssimon *
13160814Ssimon * The above copyright notice and this permission notice shall be included in
14296341Sdelphij * all copies or substantial portions of the Software.
15160814Ssimon *
16160814Ssimon * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17160814Ssimon * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18160814Ssimon * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19160814Ssimon * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20160814Ssimon * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21160814Ssimon * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22160814Ssimon * OTHER DEALINGS IN THE SOFTWARE.
23160814Ssimon *
24160814Ssimon * Authors: Ben Skeggs <bskeggs@redhat.com>
25160814Ssimon */
26160814Ssimon#include <sys/cdefs.h>
27160814Ssimon__KERNEL_RCSID(0, "$NetBSD: nouveau_nvkm_engine_disp_dmacgp102.c,v 1.2 2021/12/18 23:45:35 riastradh Exp $");
28160814Ssimon
29160814Ssimon#include "channv50.h"
30160814Ssimon
31160814Ssimon#include <subdev/timer.h>
32160814Ssimon
33160814Ssimonstatic int
34160814Ssimongp102_disp_dmac_init(struct nv50_disp_chan *chan)
35160814Ssimon{
36160814Ssimon	struct nvkm_subdev *subdev = &chan->disp->base.engine.subdev;
37160814Ssimon	struct nvkm_device *device = subdev->device;
38160814Ssimon	int ctrl = chan->chid.ctrl;
39160814Ssimon	int user = chan->chid.user;
40160814Ssimon
41160814Ssimon	/* initialise channel for dma command submission */
42160814Ssimon	nvkm_wr32(device, 0x611494 + (ctrl * 0x0010), chan->push);
43160814Ssimon	nvkm_wr32(device, 0x611498 + (ctrl * 0x0010), 0x00010000);
44160814Ssimon	nvkm_wr32(device, 0x61149c + (ctrl * 0x0010), 0x00000001);
45160814Ssimon	nvkm_mask(device, 0x610490 + (ctrl * 0x0010), 0x00000010, 0x00000010);
46160814Ssimon	nvkm_wr32(device, 0x640000 + (ctrl * 0x1000), 0x00000000);
47160814Ssimon	nvkm_wr32(device, 0x610490 + (ctrl * 0x0010), 0x00000013);
48160814Ssimon
49160814Ssimon	/* wait for it to go inactive */
50160814Ssimon	if (nvkm_msec(device, 2000,
51160814Ssimon		if (!(nvkm_rd32(device, 0x610490 + (ctrl * 0x10)) & 0x80000000))
52160814Ssimon			break;
53160814Ssimon	) < 0) {
54160814Ssimon		nvkm_error(subdev, "ch %d init: %08x\n", user,
55160814Ssimon			   nvkm_rd32(device, 0x610490 + (ctrl * 0x10)));
56160814Ssimon		return -EBUSY;
57160814Ssimon	}
58160814Ssimon
59160814Ssimon	return 0;
60160814Ssimon}
61160814Ssimon
62160814Ssimonconst struct nv50_disp_chan_func
63160814Ssimongp102_disp_dmac_func = {
64296341Sdelphij	.init = gp102_disp_dmac_init,
65296341Sdelphij	.fini = gf119_disp_dmac_fini,
66296341Sdelphij	.intr = gf119_disp_chan_intr,
67296341Sdelphij	.user = nv50_disp_chan_user,
68296341Sdelphij	.bind = gf119_disp_dmac_bind,
69296341Sdelphij};
70296341Sdelphij