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