1 /* $NetBSD: nouveau_nvkm_subdev_ibus_gk104.c,v 1.3 2021/12/18 23:45:40 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_subdev_ibus_gk104.c,v 1.3 2021/12/18 23:45:40 riastradh Exp $");
28
29 #include "priv.h"
30
31 static void
gk104_ibus_intr_hub(struct nvkm_subdev * ibus,int i)32 gk104_ibus_intr_hub(struct nvkm_subdev *ibus, int i)
33 {
34 struct nvkm_device *device = ibus->device;
35 u32 addr = nvkm_rd32(device, 0x122120 + (i * 0x0800));
36 u32 data = nvkm_rd32(device, 0x122124 + (i * 0x0800));
37 u32 stat = nvkm_rd32(device, 0x122128 + (i * 0x0800));
38 nvkm_debug(ibus, "HUB%d: %06x %08x (%08x)\n", i, addr, data, stat);
39 nvkm_mask(device, 0x122128 + (i * 0x0800), 0x00000200, 0x00000000);
40 }
41
42 static void
gk104_ibus_intr_rop(struct nvkm_subdev * ibus,int i)43 gk104_ibus_intr_rop(struct nvkm_subdev *ibus, int i)
44 {
45 struct nvkm_device *device = ibus->device;
46 u32 addr = nvkm_rd32(device, 0x124120 + (i * 0x0800));
47 u32 data = nvkm_rd32(device, 0x124124 + (i * 0x0800));
48 u32 stat = nvkm_rd32(device, 0x124128 + (i * 0x0800));
49 nvkm_debug(ibus, "ROP%d: %06x %08x (%08x)\n", i, addr, data, stat);
50 nvkm_mask(device, 0x124128 + (i * 0x0800), 0x00000200, 0x00000000);
51 }
52
53 static void
gk104_ibus_intr_gpc(struct nvkm_subdev * ibus,int i)54 gk104_ibus_intr_gpc(struct nvkm_subdev *ibus, int i)
55 {
56 struct nvkm_device *device = ibus->device;
57 u32 addr = nvkm_rd32(device, 0x128120 + (i * 0x0800));
58 u32 data = nvkm_rd32(device, 0x128124 + (i * 0x0800));
59 u32 stat = nvkm_rd32(device, 0x128128 + (i * 0x0800));
60 nvkm_debug(ibus, "GPC%d: %06x %08x (%08x)\n", i, addr, data, stat);
61 nvkm_mask(device, 0x128128 + (i * 0x0800), 0x00000200, 0x00000000);
62 }
63
64 void
gk104_ibus_intr(struct nvkm_subdev * ibus)65 gk104_ibus_intr(struct nvkm_subdev *ibus)
66 {
67 struct nvkm_device *device = ibus->device;
68 u32 intr0 = nvkm_rd32(device, 0x120058);
69 u32 intr1 = nvkm_rd32(device, 0x12005c);
70 u32 hubnr = nvkm_rd32(device, 0x120070);
71 u32 ropnr = nvkm_rd32(device, 0x120074);
72 u32 gpcnr = nvkm_rd32(device, 0x120078);
73 u32 i;
74
75 for (i = 0; (intr0 & 0x0000ff00) && i < hubnr; i++) {
76 u32 stat = 0x00000100 << i;
77 if (intr0 & stat) {
78 gk104_ibus_intr_hub(ibus, i);
79 intr0 &= ~stat;
80 }
81 }
82
83 for (i = 0; (intr0 & 0xffff0000) && i < ropnr; i++) {
84 u32 stat = 0x00010000 << i;
85 if (intr0 & stat) {
86 gk104_ibus_intr_rop(ibus, i);
87 intr0 &= ~stat;
88 }
89 }
90
91 for (i = 0; intr1 && i < gpcnr; i++) {
92 u32 stat = 0x00000001 << i;
93 if (intr1 & stat) {
94 gk104_ibus_intr_gpc(ibus, i);
95 intr1 &= ~stat;
96 }
97 }
98 }
99
100 static int
gk104_ibus_init(struct nvkm_subdev * ibus)101 gk104_ibus_init(struct nvkm_subdev *ibus)
102 {
103 struct nvkm_device *device = ibus->device;
104 nvkm_mask(device, 0x122318, 0x0003ffff, 0x00001000);
105 nvkm_mask(device, 0x12231c, 0x0003ffff, 0x00000200);
106 nvkm_mask(device, 0x122310, 0x0003ffff, 0x00000800);
107 nvkm_mask(device, 0x122348, 0x0003ffff, 0x00000100);
108 nvkm_mask(device, 0x1223b0, 0x0003ffff, 0x00000fff);
109 nvkm_mask(device, 0x122348, 0x0003ffff, 0x00000200);
110 nvkm_mask(device, 0x122358, 0x0003ffff, 0x00002880);
111 return 0;
112 }
113
114 static const struct nvkm_subdev_func
115 gk104_ibus = {
116 .preinit = gk104_ibus_init,
117 .init = gk104_ibus_init,
118 .intr = gk104_ibus_intr,
119 };
120
121 int
gk104_ibus_new(struct nvkm_device * device,int index,struct nvkm_subdev ** pibus)122 gk104_ibus_new(struct nvkm_device *device, int index,
123 struct nvkm_subdev **pibus)
124 {
125 struct nvkm_subdev *ibus;
126 if (!(ibus = *pibus = kzalloc(sizeof(*ibus), GFP_KERNEL)))
127 return -ENOMEM;
128 nvkm_subdev_ctor(&gk104_ibus, device, index, ibus);
129 return 0;
130 }
131