meson/broadcom: libbroadcom_cle also needs zlib
[mesa.git] / src / broadcom / common / v3d_device_info.c
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
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 int ret;
40
41 ret = drm_ioctl(fd, DRM_IOCTL_V3D_GET_PARAM, &ident0);
42 if (ret != 0) {
43 fprintf(stderr, "Couldn't get V3D core IDENT0: %s\n",
44 strerror(errno));
45 return false;
46 }
47 ret = drm_ioctl(fd, DRM_IOCTL_V3D_GET_PARAM, &ident1);
48 if (ret != 0) {
49 fprintf(stderr, "Couldn't get V3D core IDENT1: %s\n",
50 strerror(errno));
51 return false;
52 }
53
54 uint32_t major = (ident0.value >> 24) & 0xff;
55 uint32_t minor = (ident1.value >> 0) & 0xf;
56
57 devinfo->ver = major * 10 + minor;
58
59 devinfo->vpm_size = (ident1.value >> 28 & 0xf) * 8192;
60
61 int nslc = (ident1.value >> 4) & 0xf;
62 int qups = (ident1.value >> 8) & 0xf;
63 devinfo->qpu_count = nslc * qups;
64
65 switch (devinfo->ver) {
66 case 33:
67 case 41:
68 case 42:
69 break;
70 default:
71 fprintf(stderr,
72 "V3D %d.%d not supported by this version of Mesa.\n",
73 devinfo->ver / 10,
74 devinfo->ver % 10);
75 return false;
76 }
77
78 return true;
79 }