3 * (C) COPYRIGHT ARM Limited. All rights reserved.
5 * This program is free software and is provided to you under the terms of the
6 * GNU General Public License version 2 as published by the Free Software
7 * Foundation, and any use by you of this program is subject to the terms
10 * A copy of the licence is included with the program, and can also be obtained
11 * from Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
12 * Boston, MA 02110-1301, USA.
20 #include <mali_kbase.h>
21 #include <mali_kbase_defs.h>
22 #include <mali_kbase_cpuprops.h>
23 #include <mali_kbase_config_defaults.h>
25 /* Specifies how many attributes are permitted in the config (excluding terminating attribute).
26 * This is used in validation function so we can detect if configuration is properly terminated. This value can be
27 * changed if we need to introduce more attributes or many memory regions need to be defined */
28 #define ATTRIBUTE_COUNT_MAX 32
30 /* Limits for gpu frequency configuration parameters. These will use for config validation. */
31 #define MAX_GPU_ALLOWED_FREQ_KHZ 1000000
32 #define MIN_GPU_ALLOWED_FREQ_KHZ 1
34 int kbasep_get_config_attribute_count(const kbase_attribute *attributes)
41 while (attributes->id != KBASE_CONFIG_ATTR_END) {
49 const kbase_attribute *kbasep_get_next_attribute(const kbase_attribute *attributes, int attribute_id)
51 KBASE_DEBUG_ASSERT(attributes != NULL);
53 while (attributes->id != KBASE_CONFIG_ATTR_END) {
54 if (attributes->id == attribute_id)
62 KBASE_EXPORT_TEST_API(kbasep_get_next_attribute)
64 uintptr_t kbasep_get_config_value(struct kbase_device *kbdev, const kbase_attribute *attributes, int attribute_id)
66 const kbase_attribute *attr;
68 KBASE_DEBUG_ASSERT(attributes != NULL);
70 attr = kbasep_get_next_attribute(attributes, attribute_id);
75 switch (attribute_id) {
76 case KBASE_CONFIG_ATTR_GPU_IRQ_THROTTLE_TIME_US:
77 return DEFAULT_IRQ_THROTTLE_TIME_US;
78 /* Begin scheduling defaults */
79 case KBASE_CONFIG_ATTR_JS_SCHEDULING_TICK_NS:
80 return DEFAULT_JS_SCHEDULING_TICK_NS;
81 case KBASE_CONFIG_ATTR_JS_SOFT_STOP_TICKS:
82 return DEFAULT_JS_SOFT_STOP_TICKS;
83 case KBASE_CONFIG_ATTR_JS_SOFT_STOP_TICKS_CL:
84 return DEFAULT_JS_SOFT_STOP_TICKS_CL;
85 case KBASE_CONFIG_ATTR_JS_HARD_STOP_TICKS_SS:
86 if (kbase_hw_has_issue(kbdev, BASE_HW_ISSUE_8408))
87 return DEFAULT_JS_HARD_STOP_TICKS_SS_HW_ISSUE_8408;
89 return DEFAULT_JS_HARD_STOP_TICKS_SS;
90 case KBASE_CONFIG_ATTR_JS_HARD_STOP_TICKS_CL:
91 return DEFAULT_JS_HARD_STOP_TICKS_CL;
92 case KBASE_CONFIG_ATTR_JS_HARD_STOP_TICKS_NSS:
93 return DEFAULT_JS_HARD_STOP_TICKS_NSS;
94 case KBASE_CONFIG_ATTR_JS_CTX_TIMESLICE_NS:
95 return DEFAULT_JS_CTX_TIMESLICE_NS;
96 case KBASE_CONFIG_ATTR_JS_CFS_CTX_RUNTIME_INIT_SLICES:
97 return DEFAULT_JS_CFS_CTX_RUNTIME_INIT_SLICES;
98 case KBASE_CONFIG_ATTR_JS_CFS_CTX_RUNTIME_MIN_SLICES:
99 return DEFAULT_JS_CFS_CTX_RUNTIME_MIN_SLICES;
100 case KBASE_CONFIG_ATTR_JS_RESET_TICKS_SS:
101 if (kbase_hw_has_issue(kbdev, BASE_HW_ISSUE_8408))
102 return DEFAULT_JS_RESET_TICKS_SS_HW_ISSUE_8408;
104 return DEFAULT_JS_RESET_TICKS_SS;
105 case KBASE_CONFIG_ATTR_JS_RESET_TICKS_CL:
106 return DEFAULT_JS_RESET_TICKS_CL;
107 case KBASE_CONFIG_ATTR_JS_RESET_TICKS_NSS:
108 return DEFAULT_JS_RESET_TICKS_NSS;
109 case KBASE_CONFIG_ATTR_JS_RESET_TIMEOUT_MS:
110 return DEFAULT_JS_RESET_TIMEOUT_MS;
111 /* End scheduling defaults */
112 case KBASE_CONFIG_ATTR_POWER_MANAGEMENT_CALLBACKS:
114 case KBASE_CONFIG_ATTR_PLATFORM_FUNCS:
116 case KBASE_CONFIG_ATTR_SECURE_BUT_LOSS_OF_PERFORMANCE:
117 return DEFAULT_SECURE_BUT_LOSS_OF_PERFORMANCE;
118 case KBASE_CONFIG_ATTR_CPU_SPEED_FUNC:
119 return DEFAULT_CPU_SPEED_FUNC;
120 case KBASE_CONFIG_ATTR_GPU_SPEED_FUNC:
122 case KBASE_CONFIG_ATTR_ARID_LIMIT:
123 return DEFAULT_ARID_LIMIT;
124 case KBASE_CONFIG_ATTR_AWID_LIMIT:
125 return DEFAULT_AWID_LIMIT;
126 case KBASE_CONFIG_ATTR_POWER_MANAGEMENT_DVFS_FREQ:
127 return DEFAULT_PM_DVFS_FREQ;
128 case KBASE_CONFIG_ATTR_PM_GPU_POWEROFF_TICK_NS:
129 return DEFAULT_PM_GPU_POWEROFF_TICK_NS;
130 case KBASE_CONFIG_ATTR_PM_POWEROFF_TICK_SHADER:
131 return DEFAULT_PM_POWEROFF_TICK_SHADER;
132 case KBASE_CONFIG_ATTR_PM_POWEROFF_TICK_GPU:
133 return DEFAULT_PM_POWEROFF_TICK_GPU;
136 dev_err(kbdev->dev, "kbasep_get_config_value. Cannot get value of attribute with id=%d and no default value defined", attribute_id);
141 KBASE_EXPORT_TEST_API(kbasep_get_config_value)
143 mali_bool kbasep_platform_device_init(kbase_device *kbdev)
145 kbase_platform_funcs_conf *platform_funcs;
147 platform_funcs = (kbase_platform_funcs_conf *) kbasep_get_config_value(kbdev, kbdev->config_attributes, KBASE_CONFIG_ATTR_PLATFORM_FUNCS);
148 if (platform_funcs) {
149 if (platform_funcs->platform_init_func)
150 return platform_funcs->platform_init_func(kbdev);
155 void kbasep_platform_device_term(kbase_device *kbdev)
157 kbase_platform_funcs_conf *platform_funcs;
159 platform_funcs = (kbase_platform_funcs_conf *) kbasep_get_config_value(kbdev, kbdev->config_attributes, KBASE_CONFIG_ATTR_PLATFORM_FUNCS);
160 if (platform_funcs) {
161 if (platform_funcs->platform_term_func)
162 platform_funcs->platform_term_func(kbdev);
166 static mali_bool kbasep_validate_gpu_clock_freq(kbase_device *kbdev, const kbase_attribute *attributes)
168 uintptr_t freq_min = kbasep_get_config_value(kbdev, attributes, KBASE_CONFIG_ATTR_GPU_FREQ_KHZ_MIN);
169 uintptr_t freq_max = kbasep_get_config_value(kbdev, attributes, KBASE_CONFIG_ATTR_GPU_FREQ_KHZ_MAX);
171 if ((freq_min > MAX_GPU_ALLOWED_FREQ_KHZ) || (freq_min < MIN_GPU_ALLOWED_FREQ_KHZ) || (freq_max > MAX_GPU_ALLOWED_FREQ_KHZ) || (freq_max < MIN_GPU_ALLOWED_FREQ_KHZ) || (freq_min > freq_max)) {
172 dev_warn(kbdev->dev, "Invalid GPU frequencies found in configuration: min=%ldkHz, max=%ldkHz.", freq_min, freq_max);
179 static mali_bool kbasep_validate_pm_callback(const kbase_pm_callback_conf *callbacks, const kbase_device * kbdev )
181 if (callbacks == NULL) {
182 /* Having no callbacks is valid */
186 if ((callbacks->power_off_callback != NULL && callbacks->power_on_callback == NULL) || (callbacks->power_off_callback == NULL && callbacks->power_on_callback != NULL)) {
187 dev_warn(kbdev->dev, "Invalid power management callbacks: Only one of power_off_callback and power_on_callback was specified");
193 static mali_bool kbasep_validate_cpu_speed_func(kbase_cpuprops_clock_speed_function fcn)
198 mali_bool kbasep_validate_configuration_attributes(kbase_device *kbdev, const kbase_attribute *attributes)
201 mali_bool had_gpu_freq_min = MALI_FALSE, had_gpu_freq_max = MALI_FALSE;
203 KBASE_DEBUG_ASSERT(attributes);
205 for (i = 0; attributes[i].id != KBASE_CONFIG_ATTR_END; i++) {
206 if (i >= ATTRIBUTE_COUNT_MAX) {
207 dev_warn(kbdev->dev, "More than ATTRIBUTE_COUNT_MAX=%d configuration attributes defined. Is attribute list properly terminated?", ATTRIBUTE_COUNT_MAX);
211 switch (attributes[i].id) {
212 case KBASE_CONFIG_ATTR_GPU_FREQ_KHZ_MIN:
213 had_gpu_freq_min = MALI_TRUE;
214 if (MALI_FALSE == kbasep_validate_gpu_clock_freq(kbdev, attributes)) {
215 /* Warning message handled by kbasep_validate_gpu_clock_freq() */
220 case KBASE_CONFIG_ATTR_GPU_FREQ_KHZ_MAX:
221 had_gpu_freq_max = MALI_TRUE;
222 if (MALI_FALSE == kbasep_validate_gpu_clock_freq(kbdev, attributes)) {
223 /* Warning message handled by kbasep_validate_gpu_clock_freq() */
228 /* Only non-zero unsigned 32-bit values accepted */
229 case KBASE_CONFIG_ATTR_JS_SCHEDULING_TICK_NS:
231 if (attributes[i].data == 0u || (u64) attributes[i].data > (u64) U32_MAX)
233 if (attributes[i].data == 0u)
236 dev_warn(kbdev->dev, "Invalid Job Scheduling Configuration attribute for " "KBASE_CONFIG_ATTR_JS_SCHEDULING_TICKS_NS: %d", (int)attributes[i].data);
241 /* All these Job Scheduling attributes are FALLTHROUGH: only unsigned 32-bit values accepted */
242 case KBASE_CONFIG_ATTR_JS_SOFT_STOP_TICKS:
243 case KBASE_CONFIG_ATTR_JS_SOFT_STOP_TICKS_CL:
244 case KBASE_CONFIG_ATTR_JS_HARD_STOP_TICKS_SS:
245 case KBASE_CONFIG_ATTR_JS_HARD_STOP_TICKS_CL:
246 case KBASE_CONFIG_ATTR_JS_HARD_STOP_TICKS_NSS:
247 case KBASE_CONFIG_ATTR_JS_RESET_TICKS_SS:
248 case KBASE_CONFIG_ATTR_JS_RESET_TICKS_CL:
249 case KBASE_CONFIG_ATTR_JS_RESET_TICKS_NSS:
250 case KBASE_CONFIG_ATTR_JS_RESET_TIMEOUT_MS:
251 case KBASE_CONFIG_ATTR_JS_CTX_TIMESLICE_NS:
252 case KBASE_CONFIG_ATTR_JS_CFS_CTX_RUNTIME_INIT_SLICES:
253 case KBASE_CONFIG_ATTR_JS_CFS_CTX_RUNTIME_MIN_SLICES:
255 if ((u64) attributes[i].data > (u64) U32_MAX) {
256 dev_warn(kbdev->dev, "Job Scheduling Configuration attribute exceeds 32-bits: " "id==%d val==%d", attributes[i].id, (int)attributes[i].data);
262 case KBASE_CONFIG_ATTR_GPU_IRQ_THROTTLE_TIME_US:
264 if ((u64) attributes[i].data > (u64) U32_MAX) {
265 dev_warn(kbdev->dev, "IRQ throttle time attribute exceeds 32-bits: " "id==%d val==%d", attributes[i].id, (int)attributes[i].data);
271 case KBASE_CONFIG_ATTR_POWER_MANAGEMENT_CALLBACKS:
272 if (MALI_FALSE == kbasep_validate_pm_callback((kbase_pm_callback_conf *) attributes[i].data, kbdev)) {
273 /* Warning message handled by kbasep_validate_pm_callback() */
278 case KBASE_CONFIG_ATTR_SECURE_BUT_LOSS_OF_PERFORMANCE:
279 if (attributes[i].data != MALI_TRUE && attributes[i].data != MALI_FALSE) {
280 dev_warn(kbdev->dev, "Value for KBASE_CONFIG_ATTR_SECURE_BUT_LOSS_OF_PERFORMANCE was not " "MALI_TRUE or MALI_FALSE: %u", (unsigned int)attributes[i].data);
285 case KBASE_CONFIG_ATTR_CPU_SPEED_FUNC:
286 if (MALI_FALSE == kbasep_validate_cpu_speed_func((kbase_cpuprops_clock_speed_function) attributes[i].data)) {
287 dev_warn(kbdev->dev, "Invalid function pointer in KBASE_CONFIG_ATTR_CPU_SPEED_FUNC");
292 case KBASE_CONFIG_ATTR_GPU_SPEED_FUNC:
293 if (0 == attributes[i].data) {
294 dev_warn(kbdev->dev, "Invalid function pointer in KBASE_CONFIG_ATTR_GPU_SPEED_FUNC");
299 case KBASE_CONFIG_ATTR_PLATFORM_FUNCS:
300 /* any value is allowed */
303 case KBASE_CONFIG_ATTR_AWID_LIMIT:
304 case KBASE_CONFIG_ATTR_ARID_LIMIT:
305 if ((u32) attributes[i].data > 0x3) {
306 dev_warn(kbdev->dev, "Invalid AWID or ARID limit");
311 case KBASE_CONFIG_ATTR_POWER_MANAGEMENT_DVFS_FREQ:
313 if ((u64) attributes[i].data > (u64) U32_MAX) {
314 dev_warn(kbdev->dev, "PM DVFS interval exceeds 32-bits: " "id==%d val==%d", attributes[i].id, (int)attributes[i].data);
320 case KBASE_CONFIG_ATTR_PM_GPU_POWEROFF_TICK_NS:
322 if (attributes[i].data == 0u || (u64) attributes[i].data > (u64) U32_MAX) {
324 if (attributes[i].data == 0u) {
326 dev_warn(kbdev->dev, "Invalid Power Manager Configuration attribute for " "KBASE_CONFIG_ATTR_PM_GPU_POWEROFF_TICK_NS: %d", (int)attributes[i].data);
331 case KBASE_CONFIG_ATTR_PM_POWEROFF_TICK_SHADER:
332 case KBASE_CONFIG_ATTR_PM_POWEROFF_TICK_GPU:
334 if ((u64) attributes[i].data > (u64) U32_MAX) {
335 dev_warn(kbdev->dev, "Power Manager Configuration attribute exceeds 32-bits: " "id==%d val==%d", attributes[i].id, (int)attributes[i].data);
342 dev_warn(kbdev->dev, "Invalid attribute found in configuration: %d", attributes[i].id);
347 if (!had_gpu_freq_min) {
348 dev_warn(kbdev->dev, "Configuration does not include mandatory attribute KBASE_CONFIG_ATTR_GPU_FREQ_KHZ_MIN");
352 if (!had_gpu_freq_max) {
353 dev_warn(kbdev->dev, "Configuration does not include mandatory attribute KBASE_CONFIG_ATTR_GPU_FREQ_KHZ_MAX");