1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright (C) 2015 Etnaviv Project
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
10bf215546Sopenharmony_ci *
11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
13bf215546Sopenharmony_ci * Software.
14bf215546Sopenharmony_ci *
15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20bf215546Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21bf215546Sopenharmony_ci * SOFTWARE.
22bf215546Sopenharmony_ci *
23bf215546Sopenharmony_ci * Authors:
24bf215546Sopenharmony_ci *    Christian Gmeiner <christian.gmeiner@gmail.com>
25bf215546Sopenharmony_ci */
26bf215546Sopenharmony_ci
27bf215546Sopenharmony_ci#include "etnaviv_priv.h"
28bf215546Sopenharmony_ci#include "etnaviv_drmif.h"
29bf215546Sopenharmony_ci
30bf215546Sopenharmony_cistatic uint64_t get_param(struct etna_device *dev, uint32_t core, uint32_t param)
31bf215546Sopenharmony_ci{
32bf215546Sopenharmony_ci	struct drm_etnaviv_param req = {
33bf215546Sopenharmony_ci		.pipe = core,
34bf215546Sopenharmony_ci		.param = param,
35bf215546Sopenharmony_ci	};
36bf215546Sopenharmony_ci	int ret;
37bf215546Sopenharmony_ci
38bf215546Sopenharmony_ci	ret = drmCommandWriteRead(dev->fd, DRM_ETNAVIV_GET_PARAM, &req, sizeof(req));
39bf215546Sopenharmony_ci	if (ret) {
40bf215546Sopenharmony_ci		ERROR_MSG("get-param (%x) failed! %d (%s)", param, ret, strerror(errno));
41bf215546Sopenharmony_ci		return 0;
42bf215546Sopenharmony_ci	}
43bf215546Sopenharmony_ci
44bf215546Sopenharmony_ci	return req.value;
45bf215546Sopenharmony_ci}
46bf215546Sopenharmony_ci
47bf215546Sopenharmony_cistruct etna_gpu *etna_gpu_new(struct etna_device *dev, unsigned int core)
48bf215546Sopenharmony_ci{
49bf215546Sopenharmony_ci	struct etna_gpu *gpu;
50bf215546Sopenharmony_ci
51bf215546Sopenharmony_ci	gpu = calloc(1, sizeof(*gpu));
52bf215546Sopenharmony_ci	if (!gpu) {
53bf215546Sopenharmony_ci		ERROR_MSG("allocation failed");
54bf215546Sopenharmony_ci		goto fail;
55bf215546Sopenharmony_ci	}
56bf215546Sopenharmony_ci
57bf215546Sopenharmony_ci	gpu->dev = dev;
58bf215546Sopenharmony_ci	gpu->core = core;
59bf215546Sopenharmony_ci
60bf215546Sopenharmony_ci	gpu->model    	= get_param(dev, core, ETNAVIV_PARAM_GPU_MODEL);
61bf215546Sopenharmony_ci	gpu->revision 	= get_param(dev, core, ETNAVIV_PARAM_GPU_REVISION);
62bf215546Sopenharmony_ci
63bf215546Sopenharmony_ci	if (!gpu->model)
64bf215546Sopenharmony_ci		goto fail;
65bf215546Sopenharmony_ci
66bf215546Sopenharmony_ci	DEBUG_MSG(" GPU model:          0x%x (rev %x)", gpu->model, gpu->revision);
67bf215546Sopenharmony_ci
68bf215546Sopenharmony_ci	return gpu;
69bf215546Sopenharmony_cifail:
70bf215546Sopenharmony_ci	if (gpu)
71bf215546Sopenharmony_ci		etna_gpu_del(gpu);
72bf215546Sopenharmony_ci
73bf215546Sopenharmony_ci	return NULL;
74bf215546Sopenharmony_ci}
75bf215546Sopenharmony_ci
76bf215546Sopenharmony_civoid etna_gpu_del(struct etna_gpu *gpu)
77bf215546Sopenharmony_ci{
78bf215546Sopenharmony_ci	free(gpu);
79bf215546Sopenharmony_ci}
80bf215546Sopenharmony_ci
81bf215546Sopenharmony_ciint etna_gpu_get_param(struct etna_gpu *gpu, enum etna_param_id param,
82bf215546Sopenharmony_ci		uint64_t *value)
83bf215546Sopenharmony_ci{
84bf215546Sopenharmony_ci	struct etna_device *dev = gpu->dev;
85bf215546Sopenharmony_ci	unsigned int core = gpu->core;
86bf215546Sopenharmony_ci
87bf215546Sopenharmony_ci	switch(param) {
88bf215546Sopenharmony_ci	case ETNA_GPU_MODEL:
89bf215546Sopenharmony_ci		*value = gpu->model;
90bf215546Sopenharmony_ci		return 0;
91bf215546Sopenharmony_ci	case ETNA_GPU_REVISION:
92bf215546Sopenharmony_ci		*value = gpu->revision;
93bf215546Sopenharmony_ci		return 0;
94bf215546Sopenharmony_ci	case ETNA_GPU_FEATURES_0:
95bf215546Sopenharmony_ci		*value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_0);
96bf215546Sopenharmony_ci		return 0;
97bf215546Sopenharmony_ci	case ETNA_GPU_FEATURES_1:
98bf215546Sopenharmony_ci		*value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_1);
99bf215546Sopenharmony_ci		return 0;
100bf215546Sopenharmony_ci	case ETNA_GPU_FEATURES_2:
101bf215546Sopenharmony_ci		*value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_2);
102bf215546Sopenharmony_ci		return 0;
103bf215546Sopenharmony_ci	case ETNA_GPU_FEATURES_3:
104bf215546Sopenharmony_ci		*value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_3);
105bf215546Sopenharmony_ci		return 0;
106bf215546Sopenharmony_ci	case ETNA_GPU_FEATURES_4:
107bf215546Sopenharmony_ci		*value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_4);
108bf215546Sopenharmony_ci		return 0;
109bf215546Sopenharmony_ci	case ETNA_GPU_FEATURES_5:
110bf215546Sopenharmony_ci		*value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_5);
111bf215546Sopenharmony_ci		return 0;
112bf215546Sopenharmony_ci	case ETNA_GPU_FEATURES_6:
113bf215546Sopenharmony_ci		*value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_6);
114bf215546Sopenharmony_ci		return 0;
115bf215546Sopenharmony_ci	case ETNA_GPU_FEATURES_7:
116bf215546Sopenharmony_ci		*value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_7);
117bf215546Sopenharmony_ci		return 0;
118bf215546Sopenharmony_ci	case ETNA_GPU_FEATURES_8:
119bf215546Sopenharmony_ci		*value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_8);
120bf215546Sopenharmony_ci		return 0;
121bf215546Sopenharmony_ci	case ETNA_GPU_FEATURES_9:
122bf215546Sopenharmony_ci		*value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_9);
123bf215546Sopenharmony_ci		return 0;
124bf215546Sopenharmony_ci	case ETNA_GPU_FEATURES_10:
125bf215546Sopenharmony_ci		*value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_10);
126bf215546Sopenharmony_ci		return 0;
127bf215546Sopenharmony_ci	case ETNA_GPU_FEATURES_11:
128bf215546Sopenharmony_ci		*value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_11);
129bf215546Sopenharmony_ci		return 0;
130bf215546Sopenharmony_ci	case ETNA_GPU_FEATURES_12:
131bf215546Sopenharmony_ci		*value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_12);
132bf215546Sopenharmony_ci		return 0;
133bf215546Sopenharmony_ci	case ETNA_GPU_STREAM_COUNT:
134bf215546Sopenharmony_ci		*value = get_param(dev, core, ETNA_GPU_STREAM_COUNT);
135bf215546Sopenharmony_ci		return 0;
136bf215546Sopenharmony_ci	case ETNA_GPU_REGISTER_MAX:
137bf215546Sopenharmony_ci		*value = get_param(dev, core, ETNA_GPU_REGISTER_MAX);
138bf215546Sopenharmony_ci		return 0;
139bf215546Sopenharmony_ci	case ETNA_GPU_THREAD_COUNT:
140bf215546Sopenharmony_ci		*value = get_param(dev, core, ETNA_GPU_THREAD_COUNT);
141bf215546Sopenharmony_ci		return 0;
142bf215546Sopenharmony_ci	case ETNA_GPU_VERTEX_CACHE_SIZE:
143bf215546Sopenharmony_ci		*value = get_param(dev, core, ETNA_GPU_VERTEX_CACHE_SIZE);
144bf215546Sopenharmony_ci		return 0;
145bf215546Sopenharmony_ci	case ETNA_GPU_SHADER_CORE_COUNT:
146bf215546Sopenharmony_ci		*value = get_param(dev, core, ETNA_GPU_SHADER_CORE_COUNT);
147bf215546Sopenharmony_ci		return 0;
148bf215546Sopenharmony_ci	case ETNA_GPU_PIXEL_PIPES:
149bf215546Sopenharmony_ci		*value = get_param(dev, core, ETNA_GPU_PIXEL_PIPES);
150bf215546Sopenharmony_ci		return 0;
151bf215546Sopenharmony_ci	case ETNA_GPU_VERTEX_OUTPUT_BUFFER_SIZE:
152bf215546Sopenharmony_ci		*value = get_param(dev, core, ETNA_GPU_VERTEX_OUTPUT_BUFFER_SIZE);
153bf215546Sopenharmony_ci		return 0;
154bf215546Sopenharmony_ci	case ETNA_GPU_BUFFER_SIZE:
155bf215546Sopenharmony_ci		*value = get_param(dev, core, ETNA_GPU_BUFFER_SIZE);
156bf215546Sopenharmony_ci		return 0;
157bf215546Sopenharmony_ci	case ETNA_GPU_INSTRUCTION_COUNT:
158bf215546Sopenharmony_ci		*value = get_param(dev, core, ETNA_GPU_INSTRUCTION_COUNT);
159bf215546Sopenharmony_ci		return 0;
160bf215546Sopenharmony_ci	case ETNA_GPU_NUM_CONSTANTS:
161bf215546Sopenharmony_ci		*value = get_param(dev, core, ETNA_GPU_NUM_CONSTANTS);
162bf215546Sopenharmony_ci		return 0;
163bf215546Sopenharmony_ci	case ETNA_GPU_NUM_VARYINGS:
164bf215546Sopenharmony_ci		*value = get_param(dev, core, ETNA_GPU_NUM_VARYINGS);
165bf215546Sopenharmony_ci		return 0;
166bf215546Sopenharmony_ci
167bf215546Sopenharmony_ci	default:
168bf215546Sopenharmony_ci		ERROR_MSG("invalid param id: %d", param);
169bf215546Sopenharmony_ci		return -1;
170bf215546Sopenharmony_ci	}
171bf215546Sopenharmony_ci
172bf215546Sopenharmony_ci	return 0;
173bf215546Sopenharmony_ci}
174