panfrost: Move instancing routines to encoder/
[mesa.git] / src / panfrost / encoder / pan_props.c
1 /*
2 * Copyright (C) 2019 Collabora, Ltd.
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 FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 *
23 * Authors:
24 * Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
25 */
26
27 #include <xf86drm.h>
28
29 #include "util/u_math.h"
30 #include "util/macros.h"
31 #include "drm-uapi/panfrost_drm.h"
32 #include "pan_encoder.h"
33
34 /* Abstraction over the raw drm_panfrost_get_param ioctl for fetching
35 * information about devices */
36
37 static __u64
38 panfrost_query_raw(
39 int fd,
40 enum drm_panfrost_param param,
41 bool required,
42 unsigned default_value)
43 {
44 struct drm_panfrost_get_param get_param = {0,};
45 ASSERTED int ret;
46
47 get_param.param = DRM_PANFROST_PARAM_GPU_PROD_ID;
48 ret = drmIoctl(fd, DRM_IOCTL_PANFROST_GET_PARAM, &get_param);
49
50 if (ret) {
51 assert(!required);
52 return default_value;
53 }
54
55 return get_param.value;
56 }
57
58 unsigned
59 panfrost_query_gpu_version(int fd)
60 {
61 return panfrost_query_raw(fd, DRM_PANFROST_PARAM_GPU_PROD_ID, true, 0);
62 }
63
64 unsigned
65 panfrost_query_core_count(int fd)
66 {
67 /* On older kernels, worst-case to 16 cores */
68
69 unsigned mask = panfrost_query_raw(fd,
70 DRM_PANFROST_PARAM_SHADER_PRESENT, false, 0xffff);
71
72 return util_bitcount(mask);
73 }
74
75 unsigned
76 panfrost_query_thread_tls_alloc(int fd)
77 {
78 /* On older kernels, we worst-case to 1024 threads, the architectural
79 * maximum for Midgard */
80
81 return panfrost_query_raw(fd,
82 DRM_PANFROST_PARAM_THREAD_TLS_ALLOC, false, 1024);
83 }
84
85 /* Given a GPU ID like 0x860, return a prettified model name */
86
87 const char *
88 panfrost_model_name(unsigned gpu_id)
89 {
90 switch (gpu_id) {
91 case 0x600: return "Mali T600 (Panfrost)";
92 case 0x620: return "Mali T620 (Panfrost)";
93 case 0x720: return "Mali T720 (Panfrost)";
94 case 0x820: return "Mali T820 (Panfrost)";
95 case 0x830: return "Mali T830 (Panfrost)";
96 case 0x750: return "Mali T760 (Panfrost)";
97 case 0x860: return "Mali T860 (Panfrost)";
98 case 0x880: return "Mali T880 (Panfrost)";
99 default:
100 unreachable("Invalid GPU ID");
101 }
102 }