Path: blob/21.2-virgl/src/etnaviv/drm/etnaviv_gpu.c
4564 views
/*1* Copyright (C) 2015 Etnaviv Project2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,19* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE20* SOFTWARE.21*22* Authors:23* Christian Gmeiner <[email protected]>24*/2526#include "etnaviv_priv.h"27#include "etnaviv_drmif.h"2829static uint64_t get_param(struct etna_device *dev, uint32_t core, uint32_t param)30{31struct drm_etnaviv_param req = {32.pipe = core,33.param = param,34};35int ret;3637ret = drmCommandWriteRead(dev->fd, DRM_ETNAVIV_GET_PARAM, &req, sizeof(req));38if (ret) {39ERROR_MSG("get-param (%x) failed! %d (%s)", param, ret, strerror(errno));40return 0;41}4243return req.value;44}4546struct etna_gpu *etna_gpu_new(struct etna_device *dev, unsigned int core)47{48struct etna_gpu *gpu;4950gpu = calloc(1, sizeof(*gpu));51if (!gpu) {52ERROR_MSG("allocation failed");53goto fail;54}5556gpu->dev = dev;57gpu->core = core;5859gpu->model = get_param(dev, core, ETNAVIV_PARAM_GPU_MODEL);60gpu->revision = get_param(dev, core, ETNAVIV_PARAM_GPU_REVISION);6162if (!gpu->model)63goto fail;6465INFO_MSG(" GPU model: 0x%x (rev %x)", gpu->model, gpu->revision);6667return gpu;68fail:69if (gpu)70etna_gpu_del(gpu);7172return NULL;73}7475void etna_gpu_del(struct etna_gpu *gpu)76{77free(gpu);78}7980int etna_gpu_get_param(struct etna_gpu *gpu, enum etna_param_id param,81uint64_t *value)82{83struct etna_device *dev = gpu->dev;84unsigned int core = gpu->core;8586switch(param) {87case ETNA_GPU_MODEL:88*value = gpu->model;89return 0;90case ETNA_GPU_REVISION:91*value = gpu->revision;92return 0;93case ETNA_GPU_FEATURES_0:94*value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_0);95return 0;96case ETNA_GPU_FEATURES_1:97*value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_1);98return 0;99case ETNA_GPU_FEATURES_2:100*value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_2);101return 0;102case ETNA_GPU_FEATURES_3:103*value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_3);104return 0;105case ETNA_GPU_FEATURES_4:106*value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_4);107return 0;108case ETNA_GPU_FEATURES_5:109*value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_5);110return 0;111case ETNA_GPU_FEATURES_6:112*value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_6);113return 0;114case ETNA_GPU_FEATURES_7:115*value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_7);116return 0;117case ETNA_GPU_FEATURES_8:118*value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_8);119return 0;120case ETNA_GPU_STREAM_COUNT:121*value = get_param(dev, core, ETNA_GPU_STREAM_COUNT);122return 0;123case ETNA_GPU_REGISTER_MAX:124*value = get_param(dev, core, ETNA_GPU_REGISTER_MAX);125return 0;126case ETNA_GPU_THREAD_COUNT:127*value = get_param(dev, core, ETNA_GPU_THREAD_COUNT);128return 0;129case ETNA_GPU_VERTEX_CACHE_SIZE:130*value = get_param(dev, core, ETNA_GPU_VERTEX_CACHE_SIZE);131return 0;132case ETNA_GPU_SHADER_CORE_COUNT:133*value = get_param(dev, core, ETNA_GPU_SHADER_CORE_COUNT);134return 0;135case ETNA_GPU_PIXEL_PIPES:136*value = get_param(dev, core, ETNA_GPU_PIXEL_PIPES);137return 0;138case ETNA_GPU_VERTEX_OUTPUT_BUFFER_SIZE:139*value = get_param(dev, core, ETNA_GPU_VERTEX_OUTPUT_BUFFER_SIZE);140return 0;141case ETNA_GPU_BUFFER_SIZE:142*value = get_param(dev, core, ETNA_GPU_BUFFER_SIZE);143return 0;144case ETNA_GPU_INSTRUCTION_COUNT:145*value = get_param(dev, core, ETNA_GPU_INSTRUCTION_COUNT);146return 0;147case ETNA_GPU_NUM_CONSTANTS:148*value = get_param(dev, core, ETNA_GPU_NUM_CONSTANTS);149return 0;150case ETNA_GPU_NUM_VARYINGS:151*value = get_param(dev, core, ETNA_GPU_NUM_VARYINGS);152return 0;153154default:155ERROR_MSG("invalid param id: %d", param);156return -1;157}158159return 0;160}161162163