• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 Etnaviv Project
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 (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21  * SOFTWARE.
22  *
23  * Authors:
24  *    Christian Gmeiner <christian.gmeiner@gmail.com>
25  */
26 
27 #ifdef HAVE_CONFIG_H
28 # include <config.h>
29 #endif
30 
31 #include "etnaviv_priv.h"
32 #include "etnaviv_drmif.h"
33 
get_param(struct etna_device * dev,uint32_t core,uint32_t param)34 static uint64_t get_param(struct etna_device *dev, uint32_t core, uint32_t param)
35 {
36 	struct drm_etnaviv_param req = {
37 		.pipe = core,
38 		.param = param,
39 	};
40 	int ret;
41 
42 	ret = drmCommandWriteRead(dev->fd, DRM_ETNAVIV_GET_PARAM, &req, sizeof(req));
43 	if (ret) {
44 		ERROR_MSG("get-param (%x) failed! %d (%s)", param, ret, strerror(errno));
45 		return 0;
46 	}
47 
48 	return req.value;
49 }
50 
etna_gpu_new(struct etna_device * dev,unsigned int core)51 struct etna_gpu *etna_gpu_new(struct etna_device *dev, unsigned int core)
52 {
53 	struct etna_gpu *gpu;
54 
55 	gpu = calloc(1, sizeof(*gpu));
56 	if (!gpu) {
57 		ERROR_MSG("allocation failed");
58 		goto fail;
59 	}
60 
61 	gpu->dev = dev;
62 	gpu->core = core;
63 
64 	/* get specs from kernel space */
65 	gpu->specs.model    	= get_param(dev, core, ETNAVIV_PARAM_GPU_MODEL);
66 	gpu->specs.revision 	= get_param(dev, core, ETNAVIV_PARAM_GPU_REVISION);
67 	gpu->specs.features[0] = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_0);
68 	gpu->specs.features[1] = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_1);
69 	gpu->specs.features[2] = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_2);
70 	gpu->specs.features[3] = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_3);
71 	gpu->specs.features[4] = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_4);
72 	gpu->specs.features[5] = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_5);
73 	gpu->specs.features[6] = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_6);
74 	gpu->specs.stream_count = get_param(dev, core, ETNA_GPU_STREAM_COUNT);
75 	gpu->specs.register_max = get_param(dev, core, ETNA_GPU_REGISTER_MAX);
76 	gpu->specs.thread_count = get_param(dev, core, ETNA_GPU_THREAD_COUNT);
77 	gpu->specs.vertex_cache_size = get_param(dev, core, ETNA_GPU_VERTEX_CACHE_SIZE);
78 	gpu->specs.shader_core_count = get_param(dev, core, ETNA_GPU_SHADER_CORE_COUNT);
79 	gpu->specs.pixel_pipes = get_param(dev, core, ETNA_GPU_PIXEL_PIPES);
80 	gpu->specs.vertex_output_buffer_size = get_param(dev, core, ETNA_GPU_VERTEX_OUTPUT_BUFFER_SIZE);
81 	gpu->specs.buffer_size = get_param(dev, core, ETNA_GPU_BUFFER_SIZE);
82 	gpu->specs.instruction_count = get_param(dev, core, ETNA_GPU_INSTRUCTION_COUNT);
83 	gpu->specs.num_constants = get_param(dev, core, ETNA_GPU_NUM_CONSTANTS);
84 	gpu->specs.num_varyings = get_param(dev, core, ETNA_GPU_NUM_VARYINGS);
85 
86 	if (!gpu->specs.model)
87 		goto fail;
88 
89 	INFO_MSG(" GPU model:          0x%x (rev %x)", gpu->specs.model, gpu->specs.revision);
90 
91 	return gpu;
92 fail:
93 	if (gpu)
94 		etna_gpu_del(gpu);
95 
96 	return NULL;
97 }
98 
etna_gpu_del(struct etna_gpu * gpu)99 void etna_gpu_del(struct etna_gpu *gpu)
100 {
101 	free(gpu);
102 }
103 
etna_gpu_get_param(struct etna_gpu * gpu,enum etna_param_id param,uint64_t * value)104 int etna_gpu_get_param(struct etna_gpu *gpu, enum etna_param_id param,
105 		uint64_t *value)
106 {
107 	switch(param) {
108 	case ETNA_GPU_MODEL:
109 		*value = gpu->specs.model;
110 		return 0;
111 	case ETNA_GPU_REVISION:
112 		*value = gpu->specs.revision;
113 		return 0;
114 	case ETNA_GPU_FEATURES_0:
115 		*value = gpu->specs.features[0];
116 		return 0;
117 	case ETNA_GPU_FEATURES_1:
118 		*value = gpu->specs.features[1];
119 		return 0;
120 	case ETNA_GPU_FEATURES_2:
121 		*value = gpu->specs.features[2];
122 		return 0;
123 	case ETNA_GPU_FEATURES_3:
124 		*value = gpu->specs.features[3];
125 		return 0;
126 	case ETNA_GPU_FEATURES_4:
127 		*value = gpu->specs.features[4];
128 		return 0;
129 	case ETNA_GPU_FEATURES_5:
130 		*value = gpu->specs.features[5];
131 		return 0;
132 	case ETNA_GPU_FEATURES_6:
133 		*value = gpu->specs.features[6];
134 		return 0;
135 	case ETNA_GPU_STREAM_COUNT:
136 		*value = gpu->specs.stream_count;
137 		return 0;
138 	case ETNA_GPU_REGISTER_MAX:
139 		*value = gpu->specs.register_max;
140 		return 0;
141 	case ETNA_GPU_THREAD_COUNT:
142 		*value = gpu->specs.thread_count;
143 		return 0;
144 	case ETNA_GPU_VERTEX_CACHE_SIZE:
145 		*value = gpu->specs.vertex_cache_size;
146 		return 0;
147 	case ETNA_GPU_SHADER_CORE_COUNT:
148 		*value = gpu->specs.shader_core_count;
149 		return 0;
150 	case ETNA_GPU_PIXEL_PIPES:
151 		*value = gpu->specs.pixel_pipes;
152 		return 0;
153 	case ETNA_GPU_VERTEX_OUTPUT_BUFFER_SIZE:
154 		*value = gpu->specs.vertex_output_buffer_size;
155 		return 0;
156 	case ETNA_GPU_BUFFER_SIZE:
157 		*value = gpu->specs.buffer_size;
158 		return 0;
159 	case ETNA_GPU_INSTRUCTION_COUNT:
160 		*value = gpu->specs.instruction_count;
161 		return 0;
162 	case ETNA_GPU_NUM_CONSTANTS:
163 		*value = gpu->specs.num_constants;
164 		return 0;
165 	case ETNA_GPU_NUM_VARYINGS:
166 		*value = gpu->specs.num_varyings;
167 		return 0;
168 
169 	default:
170 		ERROR_MSG("invalid param id: %d", param);
171 		return -1;
172 	}
173 
174 	return 0;
175 }
176