3 * (C) COPYRIGHT 2010-2015 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.
21 * @file mali_kbase_config.h
22 * Configuration API and Attributes for KBase
25 #ifndef _KBASE_CONFIG_H_
26 #define _KBASE_CONFIG_H_
30 #include <mali_malisw.h>
31 #include <mali_kbase_backend_config.h>
34 * @addtogroup base_api
39 * @addtogroup base_kbase_api
44 * @addtogroup kbase_config Configuration API and Attributes
48 #if !MALI_CUSTOMER_RELEASE
49 /* This flag is set for internal builds so we can run tests without credentials. */
50 #define KBASE_HWCNT_DUMP_BYPASS_ROOT 1
52 #define KBASE_HWCNT_DUMP_BYPASS_ROOT 0
55 #include <linux/rbtree.h>
57 /* Forward declaration of struct kbase_device */
61 * kbase_platform_funcs_conf - Specifies platform init/term function pointers
63 * Specifies the functions pointers for platform specific initialization and
64 * termination. By default no functions are required. No additional platform
65 * specific control is necessary.
67 struct kbase_platform_funcs_conf {
70 * - platform specific init function pointer
71 * @kbdev - kbase_device pointer
73 * Returns 0 on success,
74 * negative error code otherwise.
76 * Function pointer for platform specific initialization or NULL if no
77 * initialization function is required. At the point this the GPU is
78 * not active and its power and clocks are in unknown (platform specific
79 * state) as kbase doesn't yet have control of power and clocks.
81 * The platform specific private pointer kbase_device::platform_context
82 * can be accessed (and possibly initialized) in here.
84 int (*platform_init_func)(struct kbase_device *kbdev);
86 * platform_term_func - platform specific termination function pointer
87 * @kbdev - kbase_device pointer
89 * Function pointer for platform specific termination or NULL if no
90 * termination function is required. At the point this the GPU will be
91 * idle but still powered and clocked.
93 * The platform specific private pointer kbase_device::platform_context
94 * can be accessed (and possibly terminated) in here.
96 void (*platform_term_func)(struct kbase_device *kbdev);
100 * @brief Specifies the callbacks for power management
102 * By default no callbacks will be made and the GPU must not be powered off.
104 struct kbase_pm_callback_conf {
105 /** Callback for when the GPU is idle and the power to it can be switched off.
107 * The system integrator can decide whether to either do nothing, just switch off
108 * the clocks to the GPU, or to completely power down the GPU.
109 * The platform specific private pointer kbase_device::platform_context can be accessed and modified in here. It is the
110 * platform \em callbacks responsiblity to initialize and terminate this pointer if used (see @ref kbase_platform_funcs_conf).
112 void (*power_off_callback)(struct kbase_device *kbdev);
114 /** Callback for when the GPU is about to become active and power must be supplied.
116 * This function must not return until the GPU is powered and clocked sufficiently for register access to
117 * succeed. The return value specifies whether the GPU was powered down since the call to power_off_callback.
118 * If the GPU state has been lost then this function must return 1, otherwise it should return 0.
119 * The platform specific private pointer kbase_device::platform_context can be accessed and modified in here. It is the
120 * platform \em callbacks responsiblity to initialize and terminate this pointer if used (see @ref kbase_platform_funcs_conf).
122 * The return value of the first call to this function is ignored.
124 * @return 1 if the GPU state may have been lost, 0 otherwise.
126 int (*power_on_callback)(struct kbase_device *kbdev);
128 /** Callback for when the system is requesting a suspend and GPU power
129 * must be switched off.
131 * Note that if this callback is present, then this may be called
132 * without a preceding call to power_off_callback. Therefore this
133 * callback must be able to take any action that might otherwise happen
134 * in power_off_callback.
136 * The platform specific private pointer kbase_device::platform_context
137 * can be accessed and modified in here. It is the platform \em
138 * callbacks responsibility to initialize and terminate this pointer if
139 * used (see @ref kbase_platform_funcs_conf).
141 void (*power_suspend_callback)(struct kbase_device *kbdev);
143 /** Callback for when the system is resuming from a suspend and GPU
144 * power must be switched on.
146 * Note that if this callback is present, then this may be called
147 * without a following call to power_on_callback. Therefore this
148 * callback must be able to take any action that might otherwise happen
149 * in power_on_callback.
151 * The platform specific private pointer kbase_device::platform_context
152 * can be accessed and modified in here. It is the platform \em
153 * callbacks responsibility to initialize and terminate this pointer if
154 * used (see @ref kbase_platform_funcs_conf).
156 void (*power_resume_callback)(struct kbase_device *kbdev);
158 /** Callback for handling runtime power management initialization.
160 * The runtime power management callbacks @ref power_runtime_off_callback and @ref power_runtime_on_callback
161 * will become active from calls made to the OS from within this function.
162 * The runtime calls can be triggered by calls from @ref power_off_callback and @ref power_on_callback.
163 * Note: for linux the kernel must have CONFIG_PM_RUNTIME enabled to use this feature.
165 * @return 0 on success, else int erro code.
167 int (*power_runtime_init_callback)(struct kbase_device *kbdev);
169 /** Callback for handling runtime power management termination.
171 * The runtime power management callbacks @ref power_runtime_off_callback and @ref power_runtime_on_callback
172 * should no longer be called by the OS on completion of this function.
173 * Note: for linux the kernel must have CONFIG_PM_RUNTIME enabled to use this feature.
175 void (*power_runtime_term_callback)(struct kbase_device *kbdev);
177 /** Callback for runtime power-off power management callback
179 * For linux this callback will be called by the kernel runtime_suspend callback.
180 * Note: for linux the kernel must have CONFIG_PM_RUNTIME enabled to use this feature.
182 * @return 0 on success, else OS error code.
184 void (*power_runtime_off_callback)(struct kbase_device *kbdev);
186 /** Callback for runtime power-on power management callback
188 * For linux this callback will be called by the kernel runtime_resume callback.
189 * Note: for linux the kernel must have CONFIG_PM_RUNTIME enabled to use this feature.
191 int (*power_runtime_on_callback)(struct kbase_device *kbdev);
194 * Optional callback for checking if GPU can be suspended when idle
196 * This callback will be called by the runtime power management core
197 * when the reference count goes to 0 to provide notification that the
198 * GPU now seems idle.
200 * If this callback finds that the GPU can't be powered off, or handles
201 * suspend by powering off directly or queueing up a power off, a
202 * non-zero value must be returned to prevent the runtime PM core from
203 * also triggering a suspend.
205 * Returning 0 will cause the runtime PM core to conduct a regular
208 * This callback is optional and if not provided regular ausosuspend
211 * Note: The Linux kernel must have CONFIG_PM_RUNTIME enabled to use
214 * Return 0 if GPU can be suspended, positive value if it can not be
215 * suspeneded by runtime PM, else OS error code
217 int (*power_runtime_idle_callback)(struct kbase_device *kbdev);
221 * kbase_cpuprops_get_default_clock_speed - default for CPU_SPEED_FUNC
222 * @clock_speed - see kbase_cpu_clk_speed_func for details on the parameters
224 * Returns 0 on success, negative error code otherwise.
226 * Default implementation of CPU_SPEED_FUNC. This function sets clock_speed
227 * to 100, so will be an underestimate for any real system.
229 int kbase_cpuprops_get_default_clock_speed(u32 * const clock_speed);
232 * kbase_cpu_clk_speed_func - Type of the function pointer for CPU_SPEED_FUNC
233 * @param clock_speed - pointer to store the current CPU clock speed in MHz
235 * Returns 0 on success, otherwise negative error code.
237 * This is mainly used to implement OpenCL's clGetDeviceInfo().
239 typedef int (*kbase_cpu_clk_speed_func) (u32 *clock_speed);
242 * kbase_gpu_clk_speed_func - Type of the function pointer for GPU_SPEED_FUNC
243 * @param clock_speed - pointer to store the current GPU clock speed in MHz
245 * Returns 0 on success, otherwise negative error code.
246 * When an error is returned the caller assumes maximum GPU speed stored in
249 * If the system timer is not available then this function is required
250 * for the OpenCL queue profiling to return correct timing information.
253 typedef int (*kbase_gpu_clk_speed_func) (u32 *clock_speed);
256 struct kbase_platform_config {
261 * @brief Specifies start and end of I/O memory region.
263 struct kbase_io_memory_region {
269 * @brief Specifies I/O related resources like IRQs and memory region for I/O operations.
271 struct kbase_io_resources {
275 struct kbase_io_memory_region io_memory_region;
278 struct kbase_platform_config {
279 const struct kbase_io_resources *io_resources;
282 #endif /* CONFIG_OF */
285 * @brief Gets the pointer to platform config.
287 * @return Pointer to the platform config
289 struct kbase_platform_config *kbase_get_platform_config(void);
292 * kbasep_platform_device_init: - Platform specific call to initialize hardware
293 * @kbdev: kbase device pointer
295 * Function calls a platform defined routine if specified in the configuration
296 * attributes. The routine can initialize any hardware and context state that
297 * is required for the GPU block to function.
299 * Return: 0 if no errors have been found in the config.
300 * Negative error code otherwise.
302 int kbasep_platform_device_init(struct kbase_device *kbdev);
305 * kbasep_platform_device_term - Platform specific call to terminate hardware
306 * @kbdev: Kbase device pointer
308 * Function calls a platform defined routine if specified in the configuration
309 * attributes. The routine can destroy any platform specific context state and
310 * shut down any hardware functionality that are outside of the Power Management
314 void kbasep_platform_device_term(struct kbase_device *kbdev);
318 * kbase_platform_early_init - Early initialisation of the platform code
320 * This function will be called when the module is loaded to perform any
321 * early initialisation required by the platform code. Such as reading
322 * platform specific device tree entries for the GPU.
324 * Return: 0 for success, any other fail causes module initialisation to fail
326 int kbase_platform_early_init(void);
329 #ifdef CONFIG_MALI_PLATFORM_FAKE
331 * kbase_platform_fake_register - Register a platform device for the GPU
333 * This can be used to register a platform device on systems where device tree
334 * is not enabled and the platform initialisation code in the kernel doesn't
335 * create the GPU device. Where possible device tree should be used instead.
337 * Return: 0 for success, any other fail causes module initialisation to fail
339 int kbase_platform_fake_register(void);
342 * kbase_platform_fake_unregister - Unregister a fake platform device
344 * Unregister the platform device created with kbase_platform_fake_register()
346 void kbase_platform_fake_unregister(void);
350 /** @} *//* end group kbase_config */
351 /** @} *//* end group base_kbase_api */
352 /** @} *//* end group base_api */
354 #endif /* _KBASE_CONFIG_H_ */