etnaviv_gpu.c revision d8807b2f
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 34static 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 51struct 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 gpu->model = get_param(dev, core, ETNAVIV_PARAM_GPU_MODEL); 65 gpu->revision = get_param(dev, core, ETNAVIV_PARAM_GPU_REVISION); 66 67 if (!gpu->model) 68 goto fail; 69 70 INFO_MSG(" GPU model: 0x%x (rev %x)", gpu->model, gpu->revision); 71 72 return gpu; 73fail: 74 if (gpu) 75 etna_gpu_del(gpu); 76 77 return NULL; 78} 79 80void etna_gpu_del(struct etna_gpu *gpu) 81{ 82 free(gpu); 83} 84 85int etna_gpu_get_param(struct etna_gpu *gpu, enum etna_param_id param, 86 uint64_t *value) 87{ 88 struct etna_device *dev = gpu->dev; 89 unsigned int core = gpu->core; 90 91 switch(param) { 92 case ETNA_GPU_MODEL: 93 *value = gpu->model; 94 return 0; 95 case ETNA_GPU_REVISION: 96 *value = gpu->revision; 97 return 0; 98 case ETNA_GPU_FEATURES_0: 99 *value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_0); 100 return 0; 101 case ETNA_GPU_FEATURES_1: 102 *value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_1); 103 return 0; 104 case ETNA_GPU_FEATURES_2: 105 *value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_2); 106 return 0; 107 case ETNA_GPU_FEATURES_3: 108 *value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_3); 109 return 0; 110 case ETNA_GPU_FEATURES_4: 111 *value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_4); 112 return 0; 113 case ETNA_GPU_FEATURES_5: 114 *value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_5); 115 return 0; 116 case ETNA_GPU_FEATURES_6: 117 *value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_6); 118 return 0; 119 case ETNA_GPU_STREAM_COUNT: 120 *value = get_param(dev, core, ETNA_GPU_STREAM_COUNT); 121 return 0; 122 case ETNA_GPU_REGISTER_MAX: 123 *value = get_param(dev, core, ETNA_GPU_REGISTER_MAX); 124 return 0; 125 case ETNA_GPU_THREAD_COUNT: 126 *value = get_param(dev, core, ETNA_GPU_THREAD_COUNT); 127 return 0; 128 case ETNA_GPU_VERTEX_CACHE_SIZE: 129 *value = get_param(dev, core, ETNA_GPU_VERTEX_CACHE_SIZE); 130 return 0; 131 case ETNA_GPU_SHADER_CORE_COUNT: 132 *value = get_param(dev, core, ETNA_GPU_SHADER_CORE_COUNT); 133 return 0; 134 case ETNA_GPU_PIXEL_PIPES: 135 *value = get_param(dev, core, ETNA_GPU_PIXEL_PIPES); 136 return 0; 137 case ETNA_GPU_VERTEX_OUTPUT_BUFFER_SIZE: 138 *value = get_param(dev, core, ETNA_GPU_VERTEX_OUTPUT_BUFFER_SIZE); 139 return 0; 140 case ETNA_GPU_BUFFER_SIZE: 141 *value = get_param(dev, core, ETNA_GPU_BUFFER_SIZE); 142 return 0; 143 case ETNA_GPU_INSTRUCTION_COUNT: 144 *value = get_param(dev, core, ETNA_GPU_INSTRUCTION_COUNT); 145 return 0; 146 case ETNA_GPU_NUM_CONSTANTS: 147 *value = get_param(dev, core, ETNA_GPU_NUM_CONSTANTS); 148 return 0; 149 case ETNA_GPU_NUM_VARYINGS: 150 *value = get_param(dev, core, ETNA_GPU_NUM_VARYINGS); 151 return 0; 152 153 default: 154 ERROR_MSG("invalid param id: %d", param); 155 return -1; 156 } 157 158 return 0; 159} 160