1 /*
2 * Copyright © 2016 Broadcom
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
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #include <errno.h>
25 #include <stdio.h>
26 #include <string.h>
27
28 #include "common/v3d_device_info.h"
29 #include "drm-uapi/v3d_drm.h"
30
31 bool
v3d_get_device_info(int fd,struct v3d_device_info * devinfo,v3d_ioctl_fun drm_ioctl)32 v3d_get_device_info(int fd, struct v3d_device_info* devinfo, v3d_ioctl_fun drm_ioctl) {
33 struct drm_v3d_get_param ident0 = {
34 .param = DRM_V3D_PARAM_V3D_CORE0_IDENT0,
35 };
36 struct drm_v3d_get_param ident1 = {
37 .param = DRM_V3D_PARAM_V3D_CORE0_IDENT1,
38 };
39 struct drm_v3d_get_param hub_ident3 = {
40 .param = DRM_V3D_PARAM_V3D_HUB_IDENT3,
41 };
42 int ret;
43
44 ret = drm_ioctl(fd, DRM_IOCTL_V3D_GET_PARAM, &ident0);
45 if (ret != 0) {
46 fprintf(stderr, "Couldn't get V3D core IDENT0: %s\n",
47 strerror(errno));
48 return false;
49 }
50 ret = drm_ioctl(fd, DRM_IOCTL_V3D_GET_PARAM, &ident1);
51 if (ret != 0) {
52 fprintf(stderr, "Couldn't get V3D core IDENT1: %s\n",
53 strerror(errno));
54 return false;
55 }
56
57 uint32_t major = (ident0.value >> 24) & 0xff;
58 uint32_t minor = (ident1.value >> 0) & 0xf;
59
60 devinfo->ver = major * 10 + minor;
61
62 devinfo->vpm_size = (ident1.value >> 28 & 0xf) * 8192;
63
64 int nslc = (ident1.value >> 4) & 0xf;
65 int qups = (ident1.value >> 8) & 0xf;
66 devinfo->qpu_count = nslc * qups;
67
68 devinfo->has_accumulators = devinfo->ver < 71;
69
70 switch (devinfo->ver) {
71 case 42:
72 case 71:
73 break;
74 default:
75 fprintf(stderr,
76 "V3D %d.%d not supported by this version of Mesa.\n",
77 devinfo->ver / 10,
78 devinfo->ver % 10);
79 return false;
80 }
81
82 ret = drm_ioctl(fd, DRM_IOCTL_V3D_GET_PARAM, &hub_ident3);
83 if (ret != 0) {
84 fprintf(stderr, "Couldn't get V3D core HUB IDENT3: %s\n",
85 strerror(errno));
86 return false;
87 }
88
89 devinfo->rev = (hub_ident3.value >> 8) & 0xff;
90
91 return true;
92 }
93