xref: /linux/drivers/gpu/drm/nouveau/nvkm/subdev/top/ga100.c (revision 24168c5e6dfbdd5b414f048f47f75d64533296ca)
1 /*
2  * Copyright 2021 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 #include "priv.h"
23 
24 #include <subdev/gsp.h>
25 
26 static int
27 ga100_top_parse(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, inst;
33 	int i, n, size = nvkm_rd32(device, 0x0224fc) >> 20;
34 
35 	for (i = 0, n = 0; i < size; i++) {
36 		if (!info) {
37 			if (!(info = nvkm_top_device_new(top)))
38 				return -ENOMEM;
39 			type = ~0;
40 			inst = 0;
41 		}
42 
43 		data = nvkm_rd32(device, 0x022800 + (i * 0x04));
44 		nvkm_trace(subdev, "%02x: %08x\n", i, data);
45 		if (!data && n == 0)
46 			continue;
47 
48 		switch (n++) {
49 		case 0:
50 			type	      = (data & 0x3f000000) >> 24;
51 			inst	      = (data & 0x000f0000) >> 16;
52 			info->fault   = (data & 0x0000007f);
53 			break;
54 		case 1:
55 			info->addr    = (data & 0x00fff000);
56 			info->reset   = (data & 0x0000001f);
57 			break;
58 		case 2:
59 			info->runlist = (data & 0x00fffc00);
60 			info->engine  = (data & 0x00000003);
61 			break;
62 		default:
63 			break;
64 		}
65 
66 		if (data & 0x80000000)
67 			continue;
68 		n = 0;
69 
70 		/* Translate engine type to NVKM engine identifier. */
71 #define I_(T,I) do { info->type = (T); info->inst = (I); } while(0)
72 #define O_(T,I) do { WARN_ON(inst); I_(T, I); } while (0)
73 		switch (type) {
74 		case 0x00000000: O_(NVKM_ENGINE_GR    ,    0); break;
75 		case 0x0000000d: O_(NVKM_ENGINE_SEC2  ,    0); break;
76 		case 0x0000000e: I_(NVKM_ENGINE_NVENC , inst); break;
77 		case 0x00000010: I_(NVKM_ENGINE_NVDEC , inst); break;
78 		case 0x00000012: I_(NVKM_SUBDEV_IOCTRL, inst); break;
79 		case 0x00000013: I_(NVKM_ENGINE_CE    , inst); break;
80 		case 0x00000014: O_(NVKM_SUBDEV_GSP   ,    0); break;
81 		case 0x00000015: I_(NVKM_ENGINE_NVJPG , inst); break;
82 		case 0x00000016: O_(NVKM_ENGINE_OFA   ,    0); break;
83 		case 0x00000017: O_(NVKM_SUBDEV_FLA   ,    0); break;
84 			break;
85 		default:
86 			break;
87 		}
88 
89 		nvkm_debug(subdev, "%02x.%d (%8s): addr %06x fault %2d "
90 				   "runlist %6x engine %2d reset %2d\n", type, inst,
91 			   info->type == NVKM_SUBDEV_NR ? "????????" : nvkm_subdev_type[info->type],
92 			   info->addr, info->fault, info->runlist < 0 ? 0 : info->runlist,
93 			   info->engine, info->reset);
94 		info = NULL;
95 	}
96 
97 	return 0;
98 }
99 
100 static const struct nvkm_top_func
101 ga100_top = {
102 	.parse = ga100_top_parse,
103 };
104 
105 int
106 ga100_top_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst,
107 	      struct nvkm_top **ptop)
108 {
109 	if (nvkm_gsp_rm(device->gsp))
110 		return -ENODEV;
111 
112 	return nvkm_top_new_(&ga100_top, device, type, inst, ptop);
113 }
114