1 /* 2 * Copyright 2016 Red Hat Inc. 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 * OTHER DEALINGS IN THE SOFTWARE. 21 * 22 * Authors: Ben Skeggs <bskeggs@redhat.com> 23 */ 24 #include "priv.h" 25 26 static int 27 gk104_top_oneinit(struct nvkm_top *top) 28 { 29 struct nvkm_subdev *subdev = &top->subdev; 30 struct nvkm_device *device = subdev->device; 31 struct nvkm_top_device *info = NULL; 32 u32 data, type; 33 int i; 34 35 for (i = 0; i < 64; i++) { 36 if (!info) { 37 if (!(info = nvkm_top_device_new(top))) 38 return -ENOMEM; 39 type = ~0; 40 } 41 42 data = nvkm_rd32(device, 0x022700 + (i * 0x04)); 43 nvkm_trace(subdev, "%02x: %08x\n", i, data); 44 switch (data & 0x00000003) { 45 case 0x00000000: /* NOT_VALID */ 46 continue; 47 case 0x00000001: /* DATA */ 48 info->addr = (data & 0x00fff000); 49 info->fault = (data & 0x000000f8) >> 3; 50 break; 51 case 0x00000002: /* ENUM */ 52 if (data & 0x00000020) 53 info->engine = (data & 0x3c000000) >> 26; 54 if (data & 0x00000010) 55 info->runlist = (data & 0x01e00000) >> 21; 56 if (data & 0x00000008) 57 info->intr = (data & 0x000f8000) >> 15; 58 if (data & 0x00000004) 59 info->reset = (data & 0x00003e00) >> 9; 60 break; 61 case 0x00000003: /* ENGINE_TYPE */ 62 type = (data & 0x7ffffffc) >> 2; 63 break; 64 } 65 66 if (data & 0x80000000) 67 continue; 68 69 /* Translate engine type to NVKM engine identifier. */ 70 switch (type) { 71 case 0x00000000: info->index = NVKM_ENGINE_GR; break; 72 case 0x00000001: info->index = NVKM_ENGINE_CE0; break; 73 case 0x00000002: info->index = NVKM_ENGINE_CE1; break; 74 case 0x00000003: info->index = NVKM_ENGINE_CE2; break; 75 case 0x00000008: info->index = NVKM_ENGINE_MSPDEC; break; 76 case 0x00000009: info->index = NVKM_ENGINE_MSPPP; break; 77 case 0x0000000a: info->index = NVKM_ENGINE_MSVLD; break; 78 case 0x0000000b: info->index = NVKM_ENGINE_MSENC; break; 79 case 0x0000000c: info->index = NVKM_ENGINE_VIC; break; 80 case 0x0000000d: info->index = NVKM_ENGINE_SEC; break; 81 case 0x0000000e: info->index = NVKM_ENGINE_NVENC0; break; 82 case 0x0000000f: info->index = NVKM_ENGINE_NVENC1; break; 83 case 0x00000010: info->index = NVKM_ENGINE_NVDEC; break; 84 break; 85 default: 86 break; 87 } 88 89 nvkm_debug(subdev, "%02x (%8s): addr %06x fault %2d engine %2d " 90 "runlist %2d intr %2d reset %2d\n", type, 91 info->index == NVKM_SUBDEV_NR ? NULL : 92 nvkm_subdev_name[info->index], 93 info->addr, info->fault, info->engine, info->runlist, 94 info->intr, info->reset); 95 info = NULL; 96 } 97 98 return 0; 99 } 100 101 static const struct nvkm_top_func 102 gk104_top = { 103 .oneinit = gk104_top_oneinit, 104 }; 105 106 int 107 gk104_top_new(struct nvkm_device *device, int index, struct nvkm_top **ptop) 108 { 109 return nvkm_top_new_(&gk104_top, device, index, ptop); 110 } 111