From f92290a8d94b811fbc5bc1a476928cc909a13951 Mon Sep 17 00:00:00 2001 From: Andreas Bergmeier Date: Sun, 14 Jul 2019 22:23:15 +0200 Subject: [PATCH] broadcom: Move v3d_get_device_info to common In common we can use implementation for Vulkan. --- src/broadcom/common/v3d_device_info.c | 79 +++++++++++++++++++++++++++ src/broadcom/common/v3d_device_info.h | 6 ++ src/broadcom/meson.build | 2 +- src/gallium/drivers/v3d/v3d_screen.c | 53 +----------------- 4 files changed, 88 insertions(+), 52 deletions(-) create mode 100644 src/broadcom/common/v3d_device_info.c diff --git a/src/broadcom/common/v3d_device_info.c b/src/broadcom/common/v3d_device_info.c new file mode 100644 index 00000000000..272190eb2e5 --- /dev/null +++ b/src/broadcom/common/v3d_device_info.c @@ -0,0 +1,79 @@ +/* + * Copyright © 2016 Broadcom + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include +#include +#include + +#include "common/v3d_device_info.h" +#include "drm-uapi/v3d_drm.h" + +bool +v3d_get_device_info(int fd, struct v3d_device_info* devinfo, v3d_ioctl_fun drm_ioctl) { + struct drm_v3d_get_param ident0 = { + .param = DRM_V3D_PARAM_V3D_CORE0_IDENT0, + }; + struct drm_v3d_get_param ident1 = { + .param = DRM_V3D_PARAM_V3D_CORE0_IDENT1, + }; + int ret; + + ret = drm_ioctl(fd, DRM_IOCTL_V3D_GET_PARAM, &ident0); + if (ret != 0) { + fprintf(stderr, "Couldn't get V3D core IDENT0: %s\n", + strerror(errno)); + return false; + } + ret = drm_ioctl(fd, DRM_IOCTL_V3D_GET_PARAM, &ident1); + if (ret != 0) { + fprintf(stderr, "Couldn't get V3D core IDENT1: %s\n", + strerror(errno)); + return false; + } + + uint32_t major = (ident0.value >> 24) & 0xff; + uint32_t minor = (ident1.value >> 0) & 0xf; + + devinfo->ver = major * 10 + minor; + + devinfo->vpm_size = (ident1.value >> 28 & 0xf) * 8192; + + int nslc = (ident1.value >> 4) & 0xf; + int qups = (ident1.value >> 8) & 0xf; + devinfo->qpu_count = nslc * qups; + + switch (devinfo->ver) { + case 33: + case 41: + case 42: + break; + default: + fprintf(stderr, + "V3D %d.%d not supported by this version of Mesa.\n", + devinfo->ver / 10, + devinfo->ver % 10); + return false; + } + + return true; +} diff --git a/src/broadcom/common/v3d_device_info.h b/src/broadcom/common/v3d_device_info.h index 608b5845444..97abd9b8d9f 100644 --- a/src/broadcom/common/v3d_device_info.h +++ b/src/broadcom/common/v3d_device_info.h @@ -24,6 +24,7 @@ #ifndef V3D_CHIP_H #define V3D_CHIP_H +#include #include /** @@ -40,4 +41,9 @@ struct v3d_device_info { int qpu_count; }; +typedef int (*v3d_ioctl_fun)(int fd, unsigned long request, void *arg); + +bool +v3d_get_device_info(int fd, struct v3d_device_info* devinfo, v3d_ioctl_fun fun); + #endif diff --git a/src/broadcom/meson.build b/src/broadcom/meson.build index d3ea362f200..b744e7ed81b 100644 --- a/src/broadcom/meson.build +++ b/src/broadcom/meson.build @@ -47,7 +47,7 @@ endforeach libbroadcom_v3d = static_library( 'libbroadcom_v3d', [ - files('common/v3d_debug.c', 'clif/clif_dump.c'), + files('common/v3d_debug.c', 'common/v3d_device_info.c', 'clif/clif_dump.c'), v3d_xml_pack, ], include_directories : [inc_common, inc_broadcom, inc_src], diff --git a/src/gallium/drivers/v3d/v3d_screen.c b/src/gallium/drivers/v3d/v3d_screen.c index 41020a49409..b128df34072 100644 --- a/src/gallium/drivers/v3d/v3d_screen.c +++ b/src/gallium/drivers/v3d/v3d_screen.c @@ -24,6 +24,7 @@ #include +#include "common/v3d_device_info.h" #include "util/os_misc.h" #include "pipe/p_defines.h" #include "pipe/p_screen.h" @@ -585,56 +586,6 @@ static int handle_compare(void *key1, void *key2) return PTR_TO_UINT(key1) != PTR_TO_UINT(key2); } -static bool -v3d_get_device_info(struct v3d_screen *screen) -{ - struct drm_v3d_get_param ident0 = { - .param = DRM_V3D_PARAM_V3D_CORE0_IDENT0, - }; - struct drm_v3d_get_param ident1 = { - .param = DRM_V3D_PARAM_V3D_CORE0_IDENT1, - }; - int ret; - - ret = v3d_ioctl(screen->fd, DRM_IOCTL_V3D_GET_PARAM, &ident0); - if (ret != 0) { - fprintf(stderr, "Couldn't get V3D core IDENT0: %s\n", - strerror(errno)); - return false; - } - ret = v3d_ioctl(screen->fd, DRM_IOCTL_V3D_GET_PARAM, &ident1); - if (ret != 0) { - fprintf(stderr, "Couldn't get V3D core IDENT1: %s\n", - strerror(errno)); - return false; - } - - uint32_t major = (ident0.value >> 24) & 0xff; - uint32_t minor = (ident1.value >> 0) & 0xf; - screen->devinfo.ver = major * 10 + minor; - - screen->devinfo.vpm_size = (ident1.value >> 28 & 0xf) * 8192; - - int nslc = (ident1.value >> 4) & 0xf; - int qups = (ident1.value >> 8) & 0xf; - screen->devinfo.qpu_count = nslc * qups; - - switch (screen->devinfo.ver) { - case 33: - case 41: - case 42: - break; - default: - fprintf(stderr, - "V3D %d.%d not supported by this version of Mesa.\n", - screen->devinfo.ver / 10, - screen->devinfo.ver % 10); - return false; - } - - return true; -} - static const void * v3d_screen_get_compiler_options(struct pipe_screen *pscreen, enum pipe_shader_ir ir, unsigned shader) @@ -703,7 +654,7 @@ v3d_screen_create(int fd, const struct pipe_screen_config *config, v3d_simulator_init(screen); #endif - if (!v3d_get_device_info(screen)) + if (!v3d_get_device_info(screen->fd, &screen->devinfo, &v3d_ioctl)) goto fail; /* We have to driCheckOption for the simulator mode to not assertion -- 2.30.2