1 /* $NetBSD: nouveau_nvkm_subdev_ibus_gf100.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_gf100.c,v 1.3 2021/12/18 23:45:40 riastradh Exp $"); 28 29 #include "priv.h" 30 31 static void 32 gf100_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 * 0x0400)); 36 u32 data = nvkm_rd32(device, 0x122124 + (i * 0x0400)); 37 u32 stat = nvkm_rd32(device, 0x122128 + (i * 0x0400)); 38 nvkm_debug(ibus, "HUB%d: %06x %08x (%08x)\n", i, addr, data, stat); 39 nvkm_mask(device, 0x122128 + (i * 0x0400), 0x00000200, 0x00000000); 40 } 41 42 static void 43 gf100_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 * 0x0400)); 47 u32 data = nvkm_rd32(device, 0x124124 + (i * 0x0400)); 48 u32 stat = nvkm_rd32(device, 0x124128 + (i * 0x0400)); 49 nvkm_debug(ibus, "ROP%d: %06x %08x (%08x)\n", i, addr, data, stat); 50 nvkm_mask(device, 0x124128 + (i * 0x0400), 0x00000200, 0x00000000); 51 } 52 53 static void 54 gf100_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 * 0x0400)); 58 u32 data = nvkm_rd32(device, 0x128124 + (i * 0x0400)); 59 u32 stat = nvkm_rd32(device, 0x128128 + (i * 0x0400)); 60 nvkm_debug(ibus, "GPC%d: %06x %08x (%08x)\n", i, addr, data, stat); 61 nvkm_mask(device, 0x128128 + (i * 0x0400), 0x00000200, 0x00000000); 62 } 63 64 void 65 gf100_ibus_intr(struct nvkm_subdev *ibus) 66 { 67 struct nvkm_device *device = ibus->device; 68 u32 intr0 = nvkm_rd32(device, 0x121c58); 69 u32 intr1 = nvkm_rd32(device, 0x121c5c); 70 u32 hubnr = nvkm_rd32(device, 0x121c70); 71 u32 ropnr = nvkm_rd32(device, 0x121c74); 72 u32 gpcnr = nvkm_rd32(device, 0x121c78); 73 u32 i; 74 75 for (i = 0; (intr0 & 0x0000ff00) && i < hubnr; i++) { 76 u32 stat = 0x00000100 << i; 77 if (intr0 & stat) { 78 gf100_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 gf100_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 gf100_ibus_intr_gpc(ibus, i); 95 intr1 &= ~stat; 96 } 97 } 98 } 99 100 static int 101 gf100_ibus_init(struct nvkm_subdev *ibus) 102 { 103 struct nvkm_device *device = ibus->device; 104 nvkm_mask(device, 0x122310, 0x0003ffff, 0x00000800); 105 nvkm_wr32(device, 0x12232c, 0x00100064); 106 nvkm_wr32(device, 0x122330, 0x00100064); 107 nvkm_wr32(device, 0x122334, 0x00100064); 108 nvkm_mask(device, 0x122348, 0x0003ffff, 0x00000100); 109 return 0; 110 } 111 112 static const struct nvkm_subdev_func 113 gf100_ibus = { 114 .init = gf100_ibus_init, 115 .intr = gf100_ibus_intr, 116 }; 117 118 int 119 gf100_ibus_new(struct nvkm_device *device, int index, 120 struct nvkm_subdev **pibus) 121 { 122 struct nvkm_subdev *ibus; 123 if (!(ibus = *pibus = kzalloc(sizeof(*ibus), GFP_KERNEL))) 124 return -ENOMEM; 125 nvkm_subdev_ctor(&gf100_ibus, device, index, ibus); 126 return 0; 127 } 128