rk3288 gpu : update GPU driver r4p0_eac version
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / arm / midgard / mali_kbase_config.c
1 /*
2  *
3  * (C) COPYRIGHT ARM Limited. All rights reserved.
4  *
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
8  * of such GNU licence.
9  *
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.
13  *
14  */
15
16
17
18
19
20 #include <mali_kbase.h>
21 #include <mali_kbase_defs.h>
22 #include <mali_kbase_cpuprops.h>
23 #include <mali_kbase_config_defaults.h>
24
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
29
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
33
34 int kbasep_get_config_attribute_count(const kbase_attribute *attributes)
35 {
36         int count = 1;
37
38         if (!attributes)
39                 return -EINVAL;
40
41         while (attributes->id != KBASE_CONFIG_ATTR_END) {
42                 attributes++;
43                 count++;
44         }
45
46         return count;
47 }
48
49 const kbase_attribute *kbasep_get_next_attribute(const kbase_attribute *attributes, int attribute_id)
50 {
51         KBASE_DEBUG_ASSERT(attributes != NULL);
52
53         while (attributes->id != KBASE_CONFIG_ATTR_END) {
54                 if (attributes->id == attribute_id)
55                         return attributes;
56
57                 attributes++;
58         }
59         return NULL;
60 }
61
62 KBASE_EXPORT_TEST_API(kbasep_get_next_attribute)
63
64 uintptr_t kbasep_get_config_value(struct kbase_device *kbdev, const kbase_attribute *attributes, int attribute_id)
65 {
66         const kbase_attribute *attr;
67
68         KBASE_DEBUG_ASSERT(attributes != NULL);
69
70         attr = kbasep_get_next_attribute(attributes, attribute_id);
71         if (attr != NULL)
72                 return attr->data;
73
74         /* default values */
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;
88                 else
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;
103                 else
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:
113                 return 0;
114         case KBASE_CONFIG_ATTR_PLATFORM_FUNCS:
115                 return 0;
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:
121                 return 0;
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;
134
135         default:
136                 dev_err(kbdev->dev, "kbasep_get_config_value. Cannot get value of attribute with id=%d and no default value defined", attribute_id);
137                 return 0;
138         }
139 }
140
141 KBASE_EXPORT_TEST_API(kbasep_get_config_value)
142
143 mali_bool kbasep_platform_device_init(kbase_device *kbdev)
144 {
145         kbase_platform_funcs_conf *platform_funcs;
146
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);
151         }
152         return MALI_TRUE;
153 }
154
155 void kbasep_platform_device_term(kbase_device *kbdev)
156 {
157         kbase_platform_funcs_conf *platform_funcs;
158
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);
163         }
164 }
165
166 static mali_bool kbasep_validate_gpu_clock_freq(kbase_device *kbdev, const kbase_attribute *attributes)
167 {
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);
170
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);
173                 return MALI_FALSE;
174         }
175
176         return MALI_TRUE;
177 }
178
179 static mali_bool kbasep_validate_pm_callback(const kbase_pm_callback_conf *callbacks, const kbase_device * kbdev )
180 {
181         if (callbacks == NULL) {
182                 /* Having no callbacks is valid */
183                 return MALI_TRUE;
184         }
185
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");
188                 return MALI_FALSE;
189         }
190         return MALI_TRUE;
191 }
192
193 static mali_bool kbasep_validate_cpu_speed_func(kbase_cpuprops_clock_speed_function fcn)
194 {
195         return fcn != NULL;
196 }
197
198 mali_bool kbasep_validate_configuration_attributes(kbase_device *kbdev, const kbase_attribute *attributes)
199 {
200         int i;
201         mali_bool had_gpu_freq_min = MALI_FALSE, had_gpu_freq_max = MALI_FALSE;
202
203         KBASE_DEBUG_ASSERT(attributes);
204
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);
208                         return MALI_FALSE;
209                 }
210
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() */
216                                 return MALI_FALSE;
217                         }
218                         break;
219
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() */
224                                 return MALI_FALSE;
225                         }
226                         break;
227
228                         /* Only non-zero unsigned 32-bit values accepted */
229                 case KBASE_CONFIG_ATTR_JS_SCHEDULING_TICK_NS:
230 #if CSTD_CPU_64BIT
231                         if (attributes[i].data == 0u || (u64) attributes[i].data > (u64) U32_MAX)
232 #else
233                         if (attributes[i].data == 0u)
234 #endif
235                         {
236                                 dev_warn(kbdev->dev, "Invalid Job Scheduling Configuration attribute for " "KBASE_CONFIG_ATTR_JS_SCHEDULING_TICKS_NS: %d", (int)attributes[i].data);
237                                 return MALI_FALSE;
238                         }
239                         break;
240
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:
254 #if CSTD_CPU_64BIT
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);
257                                 return MALI_FALSE;
258                         }
259 #endif
260                         break;
261
262                 case KBASE_CONFIG_ATTR_GPU_IRQ_THROTTLE_TIME_US:
263 #if CSTD_CPU_64BIT
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);
266                                 return MALI_FALSE;
267                         }
268 #endif
269                         break;
270
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() */
274                                 return MALI_FALSE;
275                         }
276                         break;
277
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);
281                                 return MALI_FALSE;
282                         }
283                         break;
284
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");
288                                 return MALI_FALSE;
289                         }
290                         break;
291
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");
295                                 return MALI_FALSE;
296                         }
297                         break;
298
299                 case KBASE_CONFIG_ATTR_PLATFORM_FUNCS:
300                         /* any value is allowed */
301                         break;
302
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");
307                                 return MALI_FALSE;
308                         }
309                         break;
310
311                 case KBASE_CONFIG_ATTR_POWER_MANAGEMENT_DVFS_FREQ:
312 #if CSTD_CPU_64BIT
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);
315                                 return MALI_FALSE;
316                         }
317 #endif
318                         break;
319
320                 case KBASE_CONFIG_ATTR_PM_GPU_POWEROFF_TICK_NS:
321 #if CSTD_CPU_64BIT
322                         if (attributes[i].data == 0u || (u64) attributes[i].data > (u64) U32_MAX) {
323 #else
324                         if (attributes[i].data == 0u) {
325 #endif
326                                 dev_warn(kbdev->dev, "Invalid Power Manager Configuration attribute for " "KBASE_CONFIG_ATTR_PM_GPU_POWEROFF_TICK_NS: %d", (int)attributes[i].data);
327                                 return MALI_FALSE;
328                         }
329                         break;
330
331         case KBASE_CONFIG_ATTR_PM_POWEROFF_TICK_SHADER:
332         case KBASE_CONFIG_ATTR_PM_POWEROFF_TICK_GPU:
333 #if CSTD_CPU_64BIT
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);
336                                 return MALI_FALSE;
337                         }
338 #endif
339                         break;
340
341                 default:
342                         dev_warn(kbdev->dev, "Invalid attribute found in configuration: %d", attributes[i].id);
343                         return MALI_FALSE;
344                 }
345         }
346
347         if (!had_gpu_freq_min) {
348                 dev_warn(kbdev->dev, "Configuration does not include mandatory attribute KBASE_CONFIG_ATTR_GPU_FREQ_KHZ_MIN");
349                 return MALI_FALSE;
350         }
351
352         if (!had_gpu_freq_max) {
353                 dev_warn(kbdev->dev, "Configuration does not include mandatory attribute KBASE_CONFIG_ATTR_GPU_FREQ_KHZ_MAX");
354                 return MALI_FALSE;
355         }
356
357         return MALI_TRUE;
358 }