xref: /linux/drivers/gpu/drm/nouveau/nvkm/subdev/vfn/tu102.c (revision 0ea5c948cb64bab5bc7a5516774eb8536f05aa0d)
1f83d1c31SBen Skeggs /*
2f83d1c31SBen Skeggs  * Copyright 2021 Red Hat Inc.
3f83d1c31SBen Skeggs  *
4f83d1c31SBen Skeggs  * Permission is hereby granted, free of charge, to any person obtaining a
5f83d1c31SBen Skeggs  * copy of this software and associated documentation files (the "Software"),
6f83d1c31SBen Skeggs  * to deal in the Software without restriction, including without limitation
7f83d1c31SBen Skeggs  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8f83d1c31SBen Skeggs  * and/or sell copies of the Software, and to permit persons to whom the
9f83d1c31SBen Skeggs  * Software is furnished to do so, subject to the following conditions:
10f83d1c31SBen Skeggs  *
11f83d1c31SBen Skeggs  * The above copyright notice and this permission notice shall be included in
12f83d1c31SBen Skeggs  * all copies or substantial portions of the Software.
13f83d1c31SBen Skeggs  *
14f83d1c31SBen Skeggs  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15f83d1c31SBen Skeggs  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16f83d1c31SBen Skeggs  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17f83d1c31SBen Skeggs  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18f83d1c31SBen Skeggs  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19f83d1c31SBen Skeggs  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20f83d1c31SBen Skeggs  * OTHER DEALINGS IN THE SOFTWARE.
21f83d1c31SBen Skeggs  */
22f83d1c31SBen Skeggs #include "priv.h"
23f83d1c31SBen Skeggs 
24*426cce57SBen Skeggs #include <subdev/gsp.h>
25*426cce57SBen Skeggs 
2658c3d3c8SBen Skeggs #include <nvif/class.h>
2758c3d3c8SBen Skeggs 
28e6507380SBen Skeggs static void
tu102_vfn_intr_reset(struct nvkm_intr * intr,int leaf,u32 mask)29e6507380SBen Skeggs tu102_vfn_intr_reset(struct nvkm_intr *intr, int leaf, u32 mask)
30e6507380SBen Skeggs {
31e6507380SBen Skeggs 	struct nvkm_vfn *vfn = container_of(intr, typeof(*vfn), intr);
32e6507380SBen Skeggs 
33e6507380SBen Skeggs 	nvkm_wr32(vfn->subdev.device, vfn->addr.priv + 0x1000 + (leaf * 4), mask);
34e6507380SBen Skeggs }
35e6507380SBen Skeggs 
36e6507380SBen Skeggs static void
tu102_vfn_intr_allow(struct nvkm_intr * intr,int leaf,u32 mask)37e6507380SBen Skeggs tu102_vfn_intr_allow(struct nvkm_intr *intr, int leaf, u32 mask)
38e6507380SBen Skeggs {
39e6507380SBen Skeggs 	struct nvkm_vfn *vfn = container_of(intr, typeof(*vfn), intr);
40e6507380SBen Skeggs 
41e6507380SBen Skeggs 	nvkm_wr32(vfn->subdev.device, vfn->addr.priv + 0x1200 + (leaf * 4), mask);
42e6507380SBen Skeggs }
43e6507380SBen Skeggs 
44e6507380SBen Skeggs static void
tu102_vfn_intr_block(struct nvkm_intr * intr,int leaf,u32 mask)45e6507380SBen Skeggs tu102_vfn_intr_block(struct nvkm_intr *intr, int leaf, u32 mask)
46e6507380SBen Skeggs {
47e6507380SBen Skeggs 	struct nvkm_vfn *vfn = container_of(intr, typeof(*vfn), intr);
48e6507380SBen Skeggs 
49e6507380SBen Skeggs 	nvkm_wr32(vfn->subdev.device, vfn->addr.priv + 0x1400 + (leaf * 4), mask);
50e6507380SBen Skeggs }
51e6507380SBen Skeggs 
52e6507380SBen Skeggs static void
tu102_vfn_intr_rearm(struct nvkm_intr * intr)53e6507380SBen Skeggs tu102_vfn_intr_rearm(struct nvkm_intr *intr)
54e6507380SBen Skeggs {
55e6507380SBen Skeggs 	struct nvkm_vfn *vfn = container_of(intr, typeof(*vfn), intr);
56e6507380SBen Skeggs 
57e6507380SBen Skeggs 	nvkm_wr32(vfn->subdev.device, vfn->addr.priv + 0x1608, 0x0000000f);
58e6507380SBen Skeggs }
59e6507380SBen Skeggs 
60e6507380SBen Skeggs static void
tu102_vfn_intr_unarm(struct nvkm_intr * intr)61e6507380SBen Skeggs tu102_vfn_intr_unarm(struct nvkm_intr *intr)
62e6507380SBen Skeggs {
63e6507380SBen Skeggs 	struct nvkm_vfn *vfn = container_of(intr, typeof(*vfn), intr);
64e6507380SBen Skeggs 
65e6507380SBen Skeggs 	nvkm_wr32(vfn->subdev.device, vfn->addr.priv + 0x1610, 0x0000000f);
66e6507380SBen Skeggs }
67e6507380SBen Skeggs 
68e6507380SBen Skeggs static bool
tu102_vfn_intr_pending(struct nvkm_intr * intr)69e6507380SBen Skeggs tu102_vfn_intr_pending(struct nvkm_intr *intr)
70e6507380SBen Skeggs {
71e6507380SBen Skeggs 	struct nvkm_vfn *vfn = container_of(intr, typeof(*vfn), intr);
72e6507380SBen Skeggs 	struct nvkm_device *device = vfn->subdev.device;
73e6507380SBen Skeggs 	u32 intr_top = nvkm_rd32(device, vfn->addr.priv + 0x1600);
74e6507380SBen Skeggs 	int pending = 0, leaf;
75e6507380SBen Skeggs 
76e6507380SBen Skeggs 	for (leaf = 0; leaf < 8; leaf++) {
77e6507380SBen Skeggs 		if (intr_top & BIT(leaf / 2)) {
78e6507380SBen Skeggs 			intr->stat[leaf] = nvkm_rd32(device, vfn->addr.priv + 0x1000 + (leaf * 4));
79e6507380SBen Skeggs 			if (intr->stat[leaf])
80e6507380SBen Skeggs 				pending++;
81e6507380SBen Skeggs 		} else {
82e6507380SBen Skeggs 			intr->stat[leaf] = 0;
83e6507380SBen Skeggs 		}
84e6507380SBen Skeggs 	}
85e6507380SBen Skeggs 
86e6507380SBen Skeggs 	return pending != 0;
87e6507380SBen Skeggs }
88e6507380SBen Skeggs 
89e6507380SBen Skeggs const struct nvkm_intr_func
90e6507380SBen Skeggs tu102_vfn_intr = {
91e6507380SBen Skeggs 	.pending = tu102_vfn_intr_pending,
92e6507380SBen Skeggs 	.unarm = tu102_vfn_intr_unarm,
93e6507380SBen Skeggs 	.rearm = tu102_vfn_intr_rearm,
94e6507380SBen Skeggs 	.block = tu102_vfn_intr_block,
95e6507380SBen Skeggs 	.allow = tu102_vfn_intr_allow,
96e6507380SBen Skeggs 	.reset = tu102_vfn_intr_reset,
97e6507380SBen Skeggs };
98e6507380SBen Skeggs 
99f83d1c31SBen Skeggs static const struct nvkm_vfn_func
100f83d1c31SBen Skeggs tu102_vfn = {
101e6507380SBen Skeggs 	.intr = &tu102_vfn_intr,
10258c3d3c8SBen Skeggs 	.user = { 0x030000, 0x010000, { -1, -1, TURING_USERMODE_A } },
103f83d1c31SBen Skeggs };
104f83d1c31SBen Skeggs 
105f83d1c31SBen Skeggs int
tu102_vfn_new(struct nvkm_device * device,enum nvkm_subdev_type type,int inst,struct nvkm_vfn ** pvfn)106f83d1c31SBen Skeggs tu102_vfn_new(struct nvkm_device *device,
107f83d1c31SBen Skeggs 	      enum nvkm_subdev_type type, int inst, struct nvkm_vfn **pvfn)
108f83d1c31SBen Skeggs {
109*426cce57SBen Skeggs 	if (nvkm_gsp_rm(device->gsp))
110*426cce57SBen Skeggs 		return r535_vfn_new(&tu102_vfn, device, type, inst, 0xb80000, pvfn);
111*426cce57SBen Skeggs 
112f83d1c31SBen Skeggs 	return nvkm_vfn_new_(&tu102_vfn, device, type, inst, 0xb80000, pvfn);
113f83d1c31SBen Skeggs }
114