1 /*
2 * Copyright (C) 2020 ARM Limited. All rights reserved.
3 *
4 * Copyright (C) 2008 The Android Open Source Project
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 #include "gralloc_capabilities.h"
20
21 #include <string.h>
22 #include <dlfcn.h>
23 #include <inttypes.h>
24 #include <assert.h>
25 #include <pthread.h>
26
27 #include "core/format_info.h"
28
29 /* Writing to runtime_caps_read is guarded by mutex caps_init_mutex. */
30 static pthread_mutex_t caps_init_mutex = PTHREAD_MUTEX_INITIALIZER;
31 static bool runtime_caps_read = false;
32
33 mali_gralloc_format_caps cpu_runtime_caps;
34 mali_gralloc_format_caps dpu_runtime_caps;
35 mali_gralloc_format_caps vpu_runtime_caps;
36 mali_gralloc_format_caps gpu_runtime_caps;
37 mali_gralloc_format_caps cam_runtime_caps;
38 mali_gralloc_format_caps bo_runtime_caps;
39 mali_gralloc_format_caps mfc_runtime_caps;
40
get_ip_capabilities(void)41 void get_ip_capabilities(void)
42 {
43 /* Ensure capability setting is not interrupted by other
44 * allocations during start-up.
45 */
46 pthread_mutex_lock(&caps_init_mutex);
47
48 if (runtime_caps_read)
49 {
50 goto already_init;
51 }
52
53 sanitize_formats();
54
55 /* Determine CPU IP capabilities */
56 cpu_runtime_caps.caps_mask |= MALI_GRALLOC_FORMAT_CAPABILITY_OPTIONS_PRESENT;
57 cpu_runtime_caps.caps_mask |= MALI_GRALLOC_FORMAT_CAPABILITY_PIXFMT_RGBA1010102;
58 cpu_runtime_caps.caps_mask |= MALI_GRALLOC_FORMAT_CAPABILITY_PIXFMT_RGBA16161616;
59
60 /* Determine DPU IP capabilities */
61 dpu_runtime_caps.caps_mask |= MALI_GRALLOC_FORMAT_CAPABILITY_OPTIONS_PRESENT;
62 dpu_runtime_caps.caps_mask |= MALI_GRALLOC_FORMAT_CAPABILITY_AFBC_BASIC;
63 dpu_runtime_caps.caps_mask |= MALI_GRALLOC_FORMAT_CAPABILITY_AFBC_YUV_READ;
64 #if defined(GRALLOC_DPU_SUPPORT_1010102_AFBC) && (GRALLOC_DPU_SUPPORT_1010102_AFBC == 1)
65 dpu_runtime_caps.caps_mask |= MALI_GRALLOC_FORMAT_CAPABILITY_PIXFMT_RGBA1010102;
66 #endif
67
68 #if defined(MALI_GPU_SUPPORT_AFBC_BASIC) && (MALI_GPU_SUPPORT_AFBC_BASIC == 1)
69 gpu_runtime_caps.caps_mask |= MALI_GRALLOC_FORMAT_CAPABILITY_OPTIONS_PRESENT;
70 gpu_runtime_caps.caps_mask |= MALI_GRALLOC_FORMAT_CAPABILITY_AFBC_BASIC;
71 gpu_runtime_caps.caps_mask |= MALI_GRALLOC_FORMAT_CAPABILITY_AFBC_YUV_READ;
72 gpu_runtime_caps.caps_mask |= MALI_GRALLOC_FORMAT_CAPABILITY_PIXFMT_RGBA1010102;
73 gpu_runtime_caps.caps_mask |= MALI_GRALLOC_FORMAT_CAPABILITY_PIXFMT_RGBA16161616;
74
75 #if defined(MALI_GPU_SUPPORT_AFBC_YUV_WRITE) && (MALI_GPU_SUPPORT_AFBC_YUV_WRITE == 1)
76 gpu_runtime_caps.caps_mask |= MALI_GRALLOC_FORMAT_CAPABILITY_AFBC_YUV_WRITE;
77 #endif
78
79 #if defined(MALI_GPU_SUPPORT_AFBC_SPLITBLK) && (MALI_GPU_SUPPORT_AFBC_SPLITBLK == 1)
80 gpu_runtime_caps.caps_mask |= MALI_GRALLOC_FORMAT_CAPABILITY_AFBC_SPLITBLK;
81 #endif
82
83 #if defined(MALI_GPU_SUPPORT_AFBC_WIDEBLK) && (MALI_GPU_SUPPORT_AFBC_WIDEBLK == 1)
84 gpu_runtime_caps.caps_mask |= MALI_GRALLOC_FORMAT_CAPABILITY_AFBC_SPLITBLK;
85 gpu_runtime_caps.caps_mask |= MALI_GRALLOC_FORMAT_CAPABILITY_AFBC_WIDEBLK;
86 #endif
87
88 #if defined(MALI_GPU_SUPPORT_AFBC_TILED_HEADERS) && (MALI_GPU_SUPPORT_AFBC_TILED_HEADERS == 1)
89 gpu_runtime_caps.caps_mask |= MALI_GRALLOC_FORMAT_CAPABILITY_AFBC_SPLITBLK;
90 gpu_runtime_caps.caps_mask |= MALI_GRALLOC_FORMAT_CAPABILITY_AFBC_WIDEBLK;
91 gpu_runtime_caps.caps_mask |= MALI_GRALLOC_FORMAT_CAPABILITY_AFBC_TILED_HEADERS;
92 #endif
93 #endif /* defined(MALI_GPU_SUPPORT_AFBC_BASIC) && (MALI_GPU_SUPPORT_AFBC_BASIC == 1) */
94
95 /* Determine BIGOCEAN IP capabilities */
96 bo_runtime_caps.caps_mask |= MALI_GRALLOC_FORMAT_CAPABILITY_OPTIONS_PRESENT;
97 bo_runtime_caps.caps_mask |= MALI_GRALLOC_FORMAT_CAPABILITY_AFBC_BASIC;
98 bo_runtime_caps.caps_mask |= MALI_GRALLOC_FORMAT_CAPABILITY_AFBC_YUV_WRITE;
99
100 /* Determine MFC IP capabilities */
101 mfc_runtime_caps.caps_mask |= MALI_GRALLOC_FORMAT_CAPABILITY_OPTIONS_PRESENT;
102
103 /* Determine VPU IP capabilities */
104 vpu_runtime_caps.caps_mask |= MALI_GRALLOC_FORMAT_CAPABILITY_OPTIONS_PRESENT;
105 vpu_runtime_caps.caps_mask |= MALI_GRALLOC_FORMAT_CAPABILITY_AFBC_BASIC;
106 vpu_runtime_caps.caps_mask |= MALI_GRALLOC_FORMAT_CAPABILITY_AFBC_YUV_WRITE;
107
108 /* Build specific capability changes */
109 #if defined(GRALLOC_ARM_NO_EXTERNAL_AFBC) && (GRALLOC_ARM_NO_EXTERNAL_AFBC == 1)
110 dpu_runtime_caps.caps_mask &= ~MALI_GRALLOC_FORMAT_CAPABILITY_AFBCENABLE_MASK;
111 gpu_runtime_caps.caps_mask &= ~MALI_GRALLOC_FORMAT_CAPABILITY_AFBCENABLE_MASK;
112 vpu_runtime_caps.caps_mask &= ~MALI_GRALLOC_FORMAT_CAPABILITY_AFBCENABLE_MASK;
113 cam_runtime_caps.caps_mask &= ~MALI_GRALLOC_FORMAT_CAPABILITY_AFBCENABLE_MASK;
114 #endif
115
116 cam_runtime_caps.caps_mask |= MALI_GRALLOC_FORMAT_CAPABILITY_OPTIONS_PRESENT;
117
118 runtime_caps_read = true;
119
120 already_init:
121 pthread_mutex_unlock(&caps_init_mutex);
122
123 MALI_GRALLOC_LOGV("GPU format capabilities 0x%" PRIx64, gpu_runtime_caps.caps_mask);
124 MALI_GRALLOC_LOGV("DPU format capabilities 0x%" PRIx64, dpu_runtime_caps.caps_mask);
125 MALI_GRALLOC_LOGV("VPU format capabilities 0x%" PRIx64, vpu_runtime_caps.caps_mask);
126 MALI_GRALLOC_LOGV("CAM format capabilities 0x%" PRIx64, cam_runtime_caps.caps_mask);
127 MALI_GRALLOC_LOGV("BO format capabilities 0x%" PRIx64, bo_runtime_caps.caps_mask);
128 MALI_GRALLOC_LOGV("MFC format capabilities 0x%" PRIx64, mfc_runtime_caps.caps_mask);
129 }
130
131
132 /* This is used by the unit tests to get the capabilities for each IP. */
133 extern "C" {
mali_gralloc_get_caps(struct mali_gralloc_format_caps * gpu_caps,struct mali_gralloc_format_caps * vpu_caps,struct mali_gralloc_format_caps * dpu_caps,struct mali_gralloc_format_caps * cam_caps)134 void mali_gralloc_get_caps(struct mali_gralloc_format_caps *gpu_caps,
135 struct mali_gralloc_format_caps *vpu_caps,
136 struct mali_gralloc_format_caps *dpu_caps,
137 struct mali_gralloc_format_caps *cam_caps)
138 {
139 get_ip_capabilities();
140
141 memcpy(gpu_caps, (void *)&gpu_runtime_caps, sizeof(*gpu_caps));
142 memcpy(vpu_caps, (void *)&vpu_runtime_caps, sizeof(*vpu_caps));
143 memcpy(dpu_caps, (void *)&dpu_runtime_caps, sizeof(*dpu_caps));
144 memcpy(cam_caps, (void *)&cam_runtime_caps, sizeof(*cam_caps));
145 }
146 }
147