Path: blob/21.2-virgl/src/broadcom/common/v3d_device_info.c
4560 views
/*1* Copyright © 2016 Broadcom2*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, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*/2223#include <errno.h>24#include <stdio.h>25#include <string.h>2627#include "common/v3d_device_info.h"28#include "drm-uapi/v3d_drm.h"2930bool31v3d_get_device_info(int fd, struct v3d_device_info* devinfo, v3d_ioctl_fun drm_ioctl) {32struct drm_v3d_get_param ident0 = {33.param = DRM_V3D_PARAM_V3D_CORE0_IDENT0,34};35struct drm_v3d_get_param ident1 = {36.param = DRM_V3D_PARAM_V3D_CORE0_IDENT1,37};38int ret;3940ret = drm_ioctl(fd, DRM_IOCTL_V3D_GET_PARAM, &ident0);41if (ret != 0) {42fprintf(stderr, "Couldn't get V3D core IDENT0: %s\n",43strerror(errno));44return false;45}46ret = drm_ioctl(fd, DRM_IOCTL_V3D_GET_PARAM, &ident1);47if (ret != 0) {48fprintf(stderr, "Couldn't get V3D core IDENT1: %s\n",49strerror(errno));50return false;51}5253uint32_t major = (ident0.value >> 24) & 0xff;54uint32_t minor = (ident1.value >> 0) & 0xf;5556devinfo->ver = major * 10 + minor;5758devinfo->vpm_size = (ident1.value >> 28 & 0xf) * 8192;5960int nslc = (ident1.value >> 4) & 0xf;61int qups = (ident1.value >> 8) & 0xf;62devinfo->qpu_count = nslc * qups;6364switch (devinfo->ver) {65case 33:66case 41:67case 42:68break;69default:70fprintf(stderr,71"V3D %d.%d not supported by this version of Mesa.\n",72devinfo->ver / 10,73devinfo->ver % 10);74return false;75}7677return true;78}798081