Home | History | Annotate | Download | only in etnaviv
      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 (at) gmail.com>
     25  */
     26 
     27 #include "etnaviv_priv.h"
     28 #include "etnaviv_drmif.h"
     29 
     30 static uint64_t get_param(struct etna_device *dev, uint32_t core, uint32_t param)
     31 {
     32 	struct drm_etnaviv_param req = {
     33 		.pipe = core,
     34 		.param = param,
     35 	};
     36 	int ret;
     37 
     38 	ret = drmCommandWriteRead(dev->fd, DRM_ETNAVIV_GET_PARAM, &req, sizeof(req));
     39 	if (ret) {
     40 		ERROR_MSG("get-param (%x) failed! %d (%s)", param, ret, strerror(errno));
     41 		return 0;
     42 	}
     43 
     44 	return req.value;
     45 }
     46 
     47 struct etna_gpu *etna_gpu_new(struct etna_device *dev, unsigned int core)
     48 {
     49 	struct etna_gpu *gpu;
     50 
     51 	gpu = calloc(1, sizeof(*gpu));
     52 	if (!gpu) {
     53 		ERROR_MSG("allocation failed");
     54 		goto fail;
     55 	}
     56 
     57 	gpu->dev = dev;
     58 	gpu->core = core;
     59 
     60 	gpu->model    	= get_param(dev, core, ETNAVIV_PARAM_GPU_MODEL);
     61 	gpu->revision 	= get_param(dev, core, ETNAVIV_PARAM_GPU_REVISION);
     62 
     63 	if (!gpu->model)
     64 		goto fail;
     65 
     66 	INFO_MSG(" GPU model:          0x%x (rev %x)", gpu->model, gpu->revision);
     67 
     68 	return gpu;
     69 fail:
     70 	if (gpu)
     71 		etna_gpu_del(gpu);
     72 
     73 	return NULL;
     74 }
     75 
     76 void etna_gpu_del(struct etna_gpu *gpu)
     77 {
     78 	free(gpu);
     79 }
     80 
     81 int etna_gpu_get_param(struct etna_gpu *gpu, enum etna_param_id param,
     82 		uint64_t *value)
     83 {
     84 	struct etna_device *dev = gpu->dev;
     85 	unsigned int core = gpu->core;
     86 
     87 	switch(param) {
     88 	case ETNA_GPU_MODEL:
     89 		*value = gpu->model;
     90 		return 0;
     91 	case ETNA_GPU_REVISION:
     92 		*value = gpu->revision;
     93 		return 0;
     94 	case ETNA_GPU_FEATURES_0:
     95 		*value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_0);
     96 		return 0;
     97 	case ETNA_GPU_FEATURES_1:
     98 		*value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_1);
     99 		return 0;
    100 	case ETNA_GPU_FEATURES_2:
    101 		*value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_2);
    102 		return 0;
    103 	case ETNA_GPU_FEATURES_3:
    104 		*value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_3);
    105 		return 0;
    106 	case ETNA_GPU_FEATURES_4:
    107 		*value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_4);
    108 		return 0;
    109 	case ETNA_GPU_FEATURES_5:
    110 		*value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_5);
    111 		return 0;
    112 	case ETNA_GPU_FEATURES_6:
    113 		*value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_6);
    114 		return 0;
    115 	case ETNA_GPU_STREAM_COUNT:
    116 		*value = get_param(dev, core, ETNA_GPU_STREAM_COUNT);
    117 		return 0;
    118 	case ETNA_GPU_REGISTER_MAX:
    119 		*value = get_param(dev, core, ETNA_GPU_REGISTER_MAX);
    120 		return 0;
    121 	case ETNA_GPU_THREAD_COUNT:
    122 		*value = get_param(dev, core, ETNA_GPU_THREAD_COUNT);
    123 		return 0;
    124 	case ETNA_GPU_VERTEX_CACHE_SIZE:
    125 		*value = get_param(dev, core, ETNA_GPU_VERTEX_CACHE_SIZE);
    126 		return 0;
    127 	case ETNA_GPU_SHADER_CORE_COUNT:
    128 		*value = get_param(dev, core, ETNA_GPU_SHADER_CORE_COUNT);
    129 		return 0;
    130 	case ETNA_GPU_PIXEL_PIPES:
    131 		*value = get_param(dev, core, ETNA_GPU_PIXEL_PIPES);
    132 		return 0;
    133 	case ETNA_GPU_VERTEX_OUTPUT_BUFFER_SIZE:
    134 		*value = get_param(dev, core, ETNA_GPU_VERTEX_OUTPUT_BUFFER_SIZE);
    135 		return 0;
    136 	case ETNA_GPU_BUFFER_SIZE:
    137 		*value = get_param(dev, core, ETNA_GPU_BUFFER_SIZE);
    138 		return 0;
    139 	case ETNA_GPU_INSTRUCTION_COUNT:
    140 		*value = get_param(dev, core, ETNA_GPU_INSTRUCTION_COUNT);
    141 		return 0;
    142 	case ETNA_GPU_NUM_CONSTANTS:
    143 		*value = get_param(dev, core, ETNA_GPU_NUM_CONSTANTS);
    144 		return 0;
    145 	case ETNA_GPU_NUM_VARYINGS:
    146 		*value = get_param(dev, core, ETNA_GPU_NUM_VARYINGS);
    147 		return 0;
    148 
    149 	default:
    150 		ERROR_MSG("invalid param id: %d", param);
    151 		return -1;
    152 	}
    153 
    154 	return 0;
    155 }
    156