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 struct drm_v3d_get_param max_perfcnt = {
43 .param = DRM_V3D_PARAM_MAX_PERF_COUNTERS,
44 };
45 int ret;
46
47 ret = drm_ioctl(fd, DRM_IOCTL_V3D_GET_PARAM, &ident0);
48 if (ret != 0) {
49 fprintf(stderr, "Couldn't get V3D core IDENT0: %s\n",
50 strerror(errno));
51 return false;
52 }
53 ret = drm_ioctl(fd, DRM_IOCTL_V3D_GET_PARAM, &ident1);
54 if (ret != 0) {
55 fprintf(stderr, "Couldn't get V3D core IDENT1: %s\n",
56 strerror(errno));
57 return false;
58 }
59
60 uint32_t major = (ident0.value >> 24) & 0xff;
61 uint32_t minor = (ident1.value >> 0) & 0xf;
62
63 devinfo->ver = major * 10 + minor;
64
65 devinfo->vpm_size = (ident1.value >> 28 & 0xf) * 8192;
66
67 int nslc = (ident1.value >> 4) & 0xf;
68 int qups = (ident1.value >> 8) & 0xf;
69 devinfo->qpu_count = nslc * qups;
70
71 devinfo->has_accumulators = devinfo->ver < 71;
72
73 switch (devinfo->ver) {
74 case 42:
75 devinfo->clipper_xy_granularity = 256.0f;
76 devinfo->cle_readahead = 256u;
77 devinfo->cle_buffer_min_size = 4096u;
78 break;
79 case 71:
80 devinfo->clipper_xy_granularity = 64.0f;
81 devinfo->cle_readahead = 1024u;
82 devinfo->cle_buffer_min_size = 16384u;
83 break;
84 default:
85 fprintf(stderr,
86 "V3D %d.%d not supported by this version of Mesa.\n",
87 devinfo->ver / 10,
88 devinfo->ver % 10);
89 return false;
90 }
91
92 ret = drm_ioctl(fd, DRM_IOCTL_V3D_GET_PARAM, &hub_ident3);
93 if (ret != 0) {
94 fprintf(stderr, "Couldn't get V3D core HUB IDENT3: %s\n",
95 strerror(errno));
96 return false;
97 }
98
99 devinfo->rev = (hub_ident3.value >> 8) & 0xff;
100 devinfo->compat_rev = (hub_ident3.value >> 16) & 0xff;
101
102 ret = drm_ioctl(fd, DRM_IOCTL_V3D_GET_PARAM, &max_perfcnt);
103 if (ret != 0) {
104 /* Kernel doesn't have support to return the maximum number of
105 * performance counters.
106 */
107 devinfo->max_perfcnt = 0;
108 } else {
109 devinfo->max_perfcnt = max_perfcnt.value;
110 }
111
112 return true;
113 }
114