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
2458c3d3c8SBen Skeggs #include <nvif/class.h>
2558c3d3c8SBen Skeggs
26*e6507380SBen Skeggs static void
tu102_vfn_intr_reset(struct nvkm_intr * intr,int leaf,u32 mask)27*e6507380SBen Skeggs tu102_vfn_intr_reset(struct nvkm_intr *intr, int leaf, u32 mask)
28*e6507380SBen Skeggs {
29*e6507380SBen Skeggs struct nvkm_vfn *vfn = container_of(intr, typeof(*vfn), intr);
30*e6507380SBen Skeggs
31*e6507380SBen Skeggs nvkm_wr32(vfn->subdev.device, vfn->addr.priv + 0x1000 + (leaf * 4), mask);
32*e6507380SBen Skeggs }
33*e6507380SBen Skeggs
34*e6507380SBen Skeggs static void
tu102_vfn_intr_allow(struct nvkm_intr * intr,int leaf,u32 mask)35*e6507380SBen Skeggs tu102_vfn_intr_allow(struct nvkm_intr *intr, int leaf, u32 mask)
36*e6507380SBen Skeggs {
37*e6507380SBen Skeggs struct nvkm_vfn *vfn = container_of(intr, typeof(*vfn), intr);
38*e6507380SBen Skeggs
39*e6507380SBen Skeggs nvkm_wr32(vfn->subdev.device, vfn->addr.priv + 0x1200 + (leaf * 4), mask);
40*e6507380SBen Skeggs }
41*e6507380SBen Skeggs
42*e6507380SBen Skeggs static void
tu102_vfn_intr_block(struct nvkm_intr * intr,int leaf,u32 mask)43*e6507380SBen Skeggs tu102_vfn_intr_block(struct nvkm_intr *intr, int leaf, u32 mask)
44*e6507380SBen Skeggs {
45*e6507380SBen Skeggs struct nvkm_vfn *vfn = container_of(intr, typeof(*vfn), intr);
46*e6507380SBen Skeggs
47*e6507380SBen Skeggs nvkm_wr32(vfn->subdev.device, vfn->addr.priv + 0x1400 + (leaf * 4), mask);
48*e6507380SBen Skeggs }
49*e6507380SBen Skeggs
50*e6507380SBen Skeggs static void
tu102_vfn_intr_rearm(struct nvkm_intr * intr)51*e6507380SBen Skeggs tu102_vfn_intr_rearm(struct nvkm_intr *intr)
52*e6507380SBen Skeggs {
53*e6507380SBen Skeggs struct nvkm_vfn *vfn = container_of(intr, typeof(*vfn), intr);
54*e6507380SBen Skeggs
55*e6507380SBen Skeggs nvkm_wr32(vfn->subdev.device, vfn->addr.priv + 0x1608, 0x0000000f);
56*e6507380SBen Skeggs }
57*e6507380SBen Skeggs
58*e6507380SBen Skeggs static void
tu102_vfn_intr_unarm(struct nvkm_intr * intr)59*e6507380SBen Skeggs tu102_vfn_intr_unarm(struct nvkm_intr *intr)
60*e6507380SBen Skeggs {
61*e6507380SBen Skeggs struct nvkm_vfn *vfn = container_of(intr, typeof(*vfn), intr);
62*e6507380SBen Skeggs
63*e6507380SBen Skeggs nvkm_wr32(vfn->subdev.device, vfn->addr.priv + 0x1610, 0x0000000f);
64*e6507380SBen Skeggs }
65*e6507380SBen Skeggs
66*e6507380SBen Skeggs static bool
tu102_vfn_intr_pending(struct nvkm_intr * intr)67*e6507380SBen Skeggs tu102_vfn_intr_pending(struct nvkm_intr *intr)
68*e6507380SBen Skeggs {
69*e6507380SBen Skeggs struct nvkm_vfn *vfn = container_of(intr, typeof(*vfn), intr);
70*e6507380SBen Skeggs struct nvkm_device *device = vfn->subdev.device;
71*e6507380SBen Skeggs u32 intr_top = nvkm_rd32(device, vfn->addr.priv + 0x1600);
72*e6507380SBen Skeggs int pending = 0, leaf;
73*e6507380SBen Skeggs
74*e6507380SBen Skeggs for (leaf = 0; leaf < 8; leaf++) {
75*e6507380SBen Skeggs if (intr_top & BIT(leaf / 2)) {
76*e6507380SBen Skeggs intr->stat[leaf] = nvkm_rd32(device, vfn->addr.priv + 0x1000 + (leaf * 4));
77*e6507380SBen Skeggs if (intr->stat[leaf])
78*e6507380SBen Skeggs pending++;
79*e6507380SBen Skeggs } else {
80*e6507380SBen Skeggs intr->stat[leaf] = 0;
81*e6507380SBen Skeggs }
82*e6507380SBen Skeggs }
83*e6507380SBen Skeggs
84*e6507380SBen Skeggs return pending != 0;
85*e6507380SBen Skeggs }
86*e6507380SBen Skeggs
87*e6507380SBen Skeggs const struct nvkm_intr_func
88*e6507380SBen Skeggs tu102_vfn_intr = {
89*e6507380SBen Skeggs .pending = tu102_vfn_intr_pending,
90*e6507380SBen Skeggs .unarm = tu102_vfn_intr_unarm,
91*e6507380SBen Skeggs .rearm = tu102_vfn_intr_rearm,
92*e6507380SBen Skeggs .block = tu102_vfn_intr_block,
93*e6507380SBen Skeggs .allow = tu102_vfn_intr_allow,
94*e6507380SBen Skeggs .reset = tu102_vfn_intr_reset,
95*e6507380SBen Skeggs };
96*e6507380SBen Skeggs
97f83d1c31SBen Skeggs static const struct nvkm_vfn_func
98f83d1c31SBen Skeggs tu102_vfn = {
99*e6507380SBen Skeggs .intr = &tu102_vfn_intr,
10058c3d3c8SBen Skeggs .user = { 0x030000, 0x010000, { -1, -1, TURING_USERMODE_A } },
101f83d1c31SBen Skeggs };
102f83d1c31SBen Skeggs
103f83d1c31SBen Skeggs int
tu102_vfn_new(struct nvkm_device * device,enum nvkm_subdev_type type,int inst,struct nvkm_vfn ** pvfn)104f83d1c31SBen Skeggs tu102_vfn_new(struct nvkm_device *device,
105f83d1c31SBen Skeggs enum nvkm_subdev_type type, int inst, struct nvkm_vfn **pvfn)
106f83d1c31SBen Skeggs {
107f83d1c31SBen Skeggs return nvkm_vfn_new_(&tu102_vfn, device, type, inst, 0xb80000, pvfn);
108f83d1c31SBen Skeggs }
109