1*4882a593Smuzhiyun /* 2*4882a593Smuzhiyun * 3*4882a593Smuzhiyun * (C) COPYRIGHT 2010-2016 ARM Limited. All rights reserved. 4*4882a593Smuzhiyun * 5*4882a593Smuzhiyun * This program is free software and is provided to you under the terms of the 6*4882a593Smuzhiyun * GNU General Public License version 2 as published by the Free Software 7*4882a593Smuzhiyun * Foundation, and any use by you of this program is subject to the terms 8*4882a593Smuzhiyun * of such GNU licence. 9*4882a593Smuzhiyun * 10*4882a593Smuzhiyun * A copy of the licence is included with the program, and can also be obtained 11*4882a593Smuzhiyun * from Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 12*4882a593Smuzhiyun * Boston, MA 02110-1301, USA. 13*4882a593Smuzhiyun * 14*4882a593Smuzhiyun */ 15*4882a593Smuzhiyun 16*4882a593Smuzhiyun 17*4882a593Smuzhiyun 18*4882a593Smuzhiyun 19*4882a593Smuzhiyun 20*4882a593Smuzhiyun /** 21*4882a593Smuzhiyun * @file mali_kbase_config.h 22*4882a593Smuzhiyun * Configuration API and Attributes for KBase 23*4882a593Smuzhiyun */ 24*4882a593Smuzhiyun 25*4882a593Smuzhiyun #ifndef _KBASE_CONFIG_H_ 26*4882a593Smuzhiyun #define _KBASE_CONFIG_H_ 27*4882a593Smuzhiyun 28*4882a593Smuzhiyun #include <asm/page.h> 29*4882a593Smuzhiyun 30*4882a593Smuzhiyun #include <mali_malisw.h> 31*4882a593Smuzhiyun #include <mali_kbase_backend_config.h> 32*4882a593Smuzhiyun 33*4882a593Smuzhiyun /** 34*4882a593Smuzhiyun * @addtogroup base_api 35*4882a593Smuzhiyun * @{ 36*4882a593Smuzhiyun */ 37*4882a593Smuzhiyun 38*4882a593Smuzhiyun /** 39*4882a593Smuzhiyun * @addtogroup base_kbase_api 40*4882a593Smuzhiyun * @{ 41*4882a593Smuzhiyun */ 42*4882a593Smuzhiyun 43*4882a593Smuzhiyun /** 44*4882a593Smuzhiyun * @addtogroup kbase_config Configuration API and Attributes 45*4882a593Smuzhiyun * @{ 46*4882a593Smuzhiyun */ 47*4882a593Smuzhiyun 48*4882a593Smuzhiyun #include <linux/rbtree.h> 49*4882a593Smuzhiyun 50*4882a593Smuzhiyun /* Forward declaration of struct kbase_device */ 51*4882a593Smuzhiyun struct kbase_device; 52*4882a593Smuzhiyun 53*4882a593Smuzhiyun /** 54*4882a593Smuzhiyun * kbase_platform_funcs_conf - Specifies platform init/term function pointers 55*4882a593Smuzhiyun * 56*4882a593Smuzhiyun * Specifies the functions pointers for platform specific initialization and 57*4882a593Smuzhiyun * termination. By default no functions are required. No additional platform 58*4882a593Smuzhiyun * specific control is necessary. 59*4882a593Smuzhiyun */ 60*4882a593Smuzhiyun struct kbase_platform_funcs_conf { 61*4882a593Smuzhiyun /** 62*4882a593Smuzhiyun * platform_init_func - platform specific init function pointer 63*4882a593Smuzhiyun * @kbdev - kbase_device pointer 64*4882a593Smuzhiyun * 65*4882a593Smuzhiyun * Returns 0 on success, negative error code otherwise. 66*4882a593Smuzhiyun * 67*4882a593Smuzhiyun * Function pointer for platform specific initialization or NULL if no 68*4882a593Smuzhiyun * initialization function is required. At the point this the GPU is 69*4882a593Smuzhiyun * not active and its power and clocks are in unknown (platform specific 70*4882a593Smuzhiyun * state) as kbase doesn't yet have control of power and clocks. 71*4882a593Smuzhiyun * 72*4882a593Smuzhiyun * The platform specific private pointer kbase_device::platform_context 73*4882a593Smuzhiyun * can be accessed (and possibly initialized) in here. 74*4882a593Smuzhiyun */ 75*4882a593Smuzhiyun int (*platform_init_func)(struct kbase_device *kbdev); 76*4882a593Smuzhiyun /** 77*4882a593Smuzhiyun * platform_term_func - platform specific termination function pointer 78*4882a593Smuzhiyun * @kbdev - kbase_device pointer 79*4882a593Smuzhiyun * 80*4882a593Smuzhiyun * Function pointer for platform specific termination or NULL if no 81*4882a593Smuzhiyun * termination function is required. At the point this the GPU will be 82*4882a593Smuzhiyun * idle but still powered and clocked. 83*4882a593Smuzhiyun * 84*4882a593Smuzhiyun * The platform specific private pointer kbase_device::platform_context 85*4882a593Smuzhiyun * can be accessed (and possibly terminated) in here. 86*4882a593Smuzhiyun */ 87*4882a593Smuzhiyun void (*platform_term_func)(struct kbase_device *kbdev); 88*4882a593Smuzhiyun }; 89*4882a593Smuzhiyun 90*4882a593Smuzhiyun /* 91*4882a593Smuzhiyun * @brief Specifies the callbacks for power management 92*4882a593Smuzhiyun * 93*4882a593Smuzhiyun * By default no callbacks will be made and the GPU must not be powered off. 94*4882a593Smuzhiyun */ 95*4882a593Smuzhiyun struct kbase_pm_callback_conf { 96*4882a593Smuzhiyun /** Callback for when the GPU is idle and the power to it can be switched off. 97*4882a593Smuzhiyun * 98*4882a593Smuzhiyun * The system integrator can decide whether to either do nothing, just switch off 99*4882a593Smuzhiyun * the clocks to the GPU, or to completely power down the GPU. 100*4882a593Smuzhiyun * The platform specific private pointer kbase_device::platform_context can be accessed and modified in here. It is the 101*4882a593Smuzhiyun * platform \em callbacks responsibility to initialize and terminate this pointer if used (see @ref kbase_platform_funcs_conf). 102*4882a593Smuzhiyun */ 103*4882a593Smuzhiyun void (*power_off_callback)(struct kbase_device *kbdev); 104*4882a593Smuzhiyun 105*4882a593Smuzhiyun /** Callback for when the GPU is about to become active and power must be supplied. 106*4882a593Smuzhiyun * 107*4882a593Smuzhiyun * This function must not return until the GPU is powered and clocked sufficiently for register access to 108*4882a593Smuzhiyun * succeed. The return value specifies whether the GPU was powered down since the call to power_off_callback. 109*4882a593Smuzhiyun * If the GPU state has been lost then this function must return 1, otherwise it should return 0. 110*4882a593Smuzhiyun * The platform specific private pointer kbase_device::platform_context can be accessed and modified in here. It is the 111*4882a593Smuzhiyun * platform \em callbacks responsibility to initialize and terminate this pointer if used (see @ref kbase_platform_funcs_conf). 112*4882a593Smuzhiyun * 113*4882a593Smuzhiyun * The return value of the first call to this function is ignored. 114*4882a593Smuzhiyun * 115*4882a593Smuzhiyun * @return 1 if the GPU state may have been lost, 0 otherwise. 116*4882a593Smuzhiyun */ 117*4882a593Smuzhiyun int (*power_on_callback)(struct kbase_device *kbdev); 118*4882a593Smuzhiyun 119*4882a593Smuzhiyun /** Callback for when the system is requesting a suspend and GPU power 120*4882a593Smuzhiyun * must be switched off. 121*4882a593Smuzhiyun * 122*4882a593Smuzhiyun * Note that if this callback is present, then this may be called 123*4882a593Smuzhiyun * without a preceding call to power_off_callback. Therefore this 124*4882a593Smuzhiyun * callback must be able to take any action that might otherwise happen 125*4882a593Smuzhiyun * in power_off_callback. 126*4882a593Smuzhiyun * 127*4882a593Smuzhiyun * The platform specific private pointer kbase_device::platform_context 128*4882a593Smuzhiyun * can be accessed and modified in here. It is the platform \em 129*4882a593Smuzhiyun * callbacks responsibility to initialize and terminate this pointer if 130*4882a593Smuzhiyun * used (see @ref kbase_platform_funcs_conf). 131*4882a593Smuzhiyun */ 132*4882a593Smuzhiyun void (*power_suspend_callback)(struct kbase_device *kbdev); 133*4882a593Smuzhiyun 134*4882a593Smuzhiyun /** Callback for when the system is resuming from a suspend and GPU 135*4882a593Smuzhiyun * power must be switched on. 136*4882a593Smuzhiyun * 137*4882a593Smuzhiyun * Note that if this callback is present, then this may be called 138*4882a593Smuzhiyun * without a following call to power_on_callback. Therefore this 139*4882a593Smuzhiyun * callback must be able to take any action that might otherwise happen 140*4882a593Smuzhiyun * in power_on_callback. 141*4882a593Smuzhiyun * 142*4882a593Smuzhiyun * The platform specific private pointer kbase_device::platform_context 143*4882a593Smuzhiyun * can be accessed and modified in here. It is the platform \em 144*4882a593Smuzhiyun * callbacks responsibility to initialize and terminate this pointer if 145*4882a593Smuzhiyun * used (see @ref kbase_platform_funcs_conf). 146*4882a593Smuzhiyun */ 147*4882a593Smuzhiyun void (*power_resume_callback)(struct kbase_device *kbdev); 148*4882a593Smuzhiyun 149*4882a593Smuzhiyun /** Callback for handling runtime power management initialization. 150*4882a593Smuzhiyun * 151*4882a593Smuzhiyun * The runtime power management callbacks @ref power_runtime_off_callback and @ref power_runtime_on_callback 152*4882a593Smuzhiyun * will become active from calls made to the OS from within this function. 153*4882a593Smuzhiyun * The runtime calls can be triggered by calls from @ref power_off_callback and @ref power_on_callback. 154*4882a593Smuzhiyun * Note: for linux the kernel must have CONFIG_PM_RUNTIME enabled to use this feature. 155*4882a593Smuzhiyun * 156*4882a593Smuzhiyun * @return 0 on success, else int error code. 157*4882a593Smuzhiyun */ 158*4882a593Smuzhiyun int (*power_runtime_init_callback)(struct kbase_device *kbdev); 159*4882a593Smuzhiyun 160*4882a593Smuzhiyun /** Callback for handling runtime power management termination. 161*4882a593Smuzhiyun * 162*4882a593Smuzhiyun * The runtime power management callbacks @ref power_runtime_off_callback and @ref power_runtime_on_callback 163*4882a593Smuzhiyun * should no longer be called by the OS on completion of this function. 164*4882a593Smuzhiyun * Note: for linux the kernel must have CONFIG_PM_RUNTIME enabled to use this feature. 165*4882a593Smuzhiyun */ 166*4882a593Smuzhiyun void (*power_runtime_term_callback)(struct kbase_device *kbdev); 167*4882a593Smuzhiyun 168*4882a593Smuzhiyun /** Callback for runtime power-off power management callback 169*4882a593Smuzhiyun * 170*4882a593Smuzhiyun * For linux this callback will be called by the kernel runtime_suspend callback. 171*4882a593Smuzhiyun * Note: for linux the kernel must have CONFIG_PM_RUNTIME enabled to use this feature. 172*4882a593Smuzhiyun * 173*4882a593Smuzhiyun * @return 0 on success, else OS error code. 174*4882a593Smuzhiyun */ 175*4882a593Smuzhiyun void (*power_runtime_off_callback)(struct kbase_device *kbdev); 176*4882a593Smuzhiyun 177*4882a593Smuzhiyun /** Callback for runtime power-on power management callback 178*4882a593Smuzhiyun * 179*4882a593Smuzhiyun * For linux this callback will be called by the kernel runtime_resume callback. 180*4882a593Smuzhiyun * Note: for linux the kernel must have CONFIG_PM_RUNTIME enabled to use this feature. 181*4882a593Smuzhiyun */ 182*4882a593Smuzhiyun int (*power_runtime_on_callback)(struct kbase_device *kbdev); 183*4882a593Smuzhiyun 184*4882a593Smuzhiyun /* 185*4882a593Smuzhiyun * Optional callback for checking if GPU can be suspended when idle 186*4882a593Smuzhiyun * 187*4882a593Smuzhiyun * This callback will be called by the runtime power management core 188*4882a593Smuzhiyun * when the reference count goes to 0 to provide notification that the 189*4882a593Smuzhiyun * GPU now seems idle. 190*4882a593Smuzhiyun * 191*4882a593Smuzhiyun * If this callback finds that the GPU can't be powered off, or handles 192*4882a593Smuzhiyun * suspend by powering off directly or queueing up a power off, a 193*4882a593Smuzhiyun * non-zero value must be returned to prevent the runtime PM core from 194*4882a593Smuzhiyun * also triggering a suspend. 195*4882a593Smuzhiyun * 196*4882a593Smuzhiyun * Returning 0 will cause the runtime PM core to conduct a regular 197*4882a593Smuzhiyun * autosuspend. 198*4882a593Smuzhiyun * 199*4882a593Smuzhiyun * This callback is optional and if not provided regular autosuspend 200*4882a593Smuzhiyun * will be triggered. 201*4882a593Smuzhiyun * 202*4882a593Smuzhiyun * Note: The Linux kernel must have CONFIG_PM_RUNTIME enabled to use 203*4882a593Smuzhiyun * this feature. 204*4882a593Smuzhiyun * 205*4882a593Smuzhiyun * Return 0 if GPU can be suspended, positive value if it can not be 206*4882a593Smuzhiyun * suspeneded by runtime PM, else OS error code 207*4882a593Smuzhiyun */ 208*4882a593Smuzhiyun int (*power_runtime_idle_callback)(struct kbase_device *kbdev); 209*4882a593Smuzhiyun }; 210*4882a593Smuzhiyun 211*4882a593Smuzhiyun /** 212*4882a593Smuzhiyun * kbase_cpuprops_get_default_clock_speed - default for CPU_SPEED_FUNC 213*4882a593Smuzhiyun * @clock_speed - see kbase_cpu_clk_speed_func for details on the parameters 214*4882a593Smuzhiyun * 215*4882a593Smuzhiyun * Returns 0 on success, negative error code otherwise. 216*4882a593Smuzhiyun * 217*4882a593Smuzhiyun * Default implementation of CPU_SPEED_FUNC. This function sets clock_speed 218*4882a593Smuzhiyun * to 100, so will be an underestimate for any real system. 219*4882a593Smuzhiyun */ 220*4882a593Smuzhiyun int kbase_cpuprops_get_default_clock_speed(u32 * const clock_speed); 221*4882a593Smuzhiyun 222*4882a593Smuzhiyun /** 223*4882a593Smuzhiyun * kbase_cpu_clk_speed_func - Type of the function pointer for CPU_SPEED_FUNC 224*4882a593Smuzhiyun * @param clock_speed - pointer to store the current CPU clock speed in MHz 225*4882a593Smuzhiyun * 226*4882a593Smuzhiyun * Returns 0 on success, otherwise negative error code. 227*4882a593Smuzhiyun * 228*4882a593Smuzhiyun * This is mainly used to implement OpenCL's clGetDeviceInfo(). 229*4882a593Smuzhiyun */ 230*4882a593Smuzhiyun typedef int (*kbase_cpu_clk_speed_func) (u32 *clock_speed); 231*4882a593Smuzhiyun 232*4882a593Smuzhiyun /** 233*4882a593Smuzhiyun * kbase_gpu_clk_speed_func - Type of the function pointer for GPU_SPEED_FUNC 234*4882a593Smuzhiyun * @param clock_speed - pointer to store the current GPU clock speed in MHz 235*4882a593Smuzhiyun * 236*4882a593Smuzhiyun * Returns 0 on success, otherwise negative error code. 237*4882a593Smuzhiyun * When an error is returned the caller assumes maximum GPU speed stored in 238*4882a593Smuzhiyun * gpu_freq_khz_max. 239*4882a593Smuzhiyun * 240*4882a593Smuzhiyun * If the system timer is not available then this function is required 241*4882a593Smuzhiyun * for the OpenCL queue profiling to return correct timing information. 242*4882a593Smuzhiyun * 243*4882a593Smuzhiyun */ 244*4882a593Smuzhiyun typedef int (*kbase_gpu_clk_speed_func) (u32 *clock_speed); 245*4882a593Smuzhiyun 246*4882a593Smuzhiyun #ifdef CONFIG_OF 247*4882a593Smuzhiyun struct kbase_platform_config { 248*4882a593Smuzhiyun }; 249*4882a593Smuzhiyun #else 250*4882a593Smuzhiyun 251*4882a593Smuzhiyun /* 252*4882a593Smuzhiyun * @brief Specifies start and end of I/O memory region. 253*4882a593Smuzhiyun */ 254*4882a593Smuzhiyun struct kbase_io_memory_region { 255*4882a593Smuzhiyun u64 start; 256*4882a593Smuzhiyun u64 end; 257*4882a593Smuzhiyun }; 258*4882a593Smuzhiyun 259*4882a593Smuzhiyun /* 260*4882a593Smuzhiyun * @brief Specifies I/O related resources like IRQs and memory region for I/O operations. 261*4882a593Smuzhiyun */ 262*4882a593Smuzhiyun struct kbase_io_resources { 263*4882a593Smuzhiyun u32 job_irq_number; 264*4882a593Smuzhiyun u32 mmu_irq_number; 265*4882a593Smuzhiyun u32 gpu_irq_number; 266*4882a593Smuzhiyun struct kbase_io_memory_region io_memory_region; 267*4882a593Smuzhiyun }; 268*4882a593Smuzhiyun 269*4882a593Smuzhiyun struct kbase_platform_config { 270*4882a593Smuzhiyun const struct kbase_io_resources *io_resources; 271*4882a593Smuzhiyun }; 272*4882a593Smuzhiyun 273*4882a593Smuzhiyun #endif /* CONFIG_OF */ 274*4882a593Smuzhiyun 275*4882a593Smuzhiyun /** 276*4882a593Smuzhiyun * @brief Gets the pointer to platform config. 277*4882a593Smuzhiyun * 278*4882a593Smuzhiyun * @return Pointer to the platform config 279*4882a593Smuzhiyun */ 280*4882a593Smuzhiyun struct kbase_platform_config *kbase_get_platform_config(void); 281*4882a593Smuzhiyun 282*4882a593Smuzhiyun /** 283*4882a593Smuzhiyun * kbasep_platform_device_init: - Platform specific call to initialize hardware 284*4882a593Smuzhiyun * @kbdev: kbase device pointer 285*4882a593Smuzhiyun * 286*4882a593Smuzhiyun * Function calls a platform defined routine if specified in the configuration 287*4882a593Smuzhiyun * attributes. The routine can initialize any hardware and context state that 288*4882a593Smuzhiyun * is required for the GPU block to function. 289*4882a593Smuzhiyun * 290*4882a593Smuzhiyun * Return: 0 if no errors have been found in the config. 291*4882a593Smuzhiyun * Negative error code otherwise. 292*4882a593Smuzhiyun */ 293*4882a593Smuzhiyun int kbasep_platform_device_init(struct kbase_device *kbdev); 294*4882a593Smuzhiyun 295*4882a593Smuzhiyun /** 296*4882a593Smuzhiyun * kbasep_platform_device_term - Platform specific call to terminate hardware 297*4882a593Smuzhiyun * @kbdev: Kbase device pointer 298*4882a593Smuzhiyun * 299*4882a593Smuzhiyun * Function calls a platform defined routine if specified in the configuration 300*4882a593Smuzhiyun * attributes. The routine can destroy any platform specific context state and 301*4882a593Smuzhiyun * shut down any hardware functionality that are outside of the Power Management 302*4882a593Smuzhiyun * callbacks. 303*4882a593Smuzhiyun * 304*4882a593Smuzhiyun */ 305*4882a593Smuzhiyun void kbasep_platform_device_term(struct kbase_device *kbdev); 306*4882a593Smuzhiyun 307*4882a593Smuzhiyun 308*4882a593Smuzhiyun /** 309*4882a593Smuzhiyun * kbase_platform_early_init - Early initialisation of the platform code 310*4882a593Smuzhiyun * 311*4882a593Smuzhiyun * This function will be called when the module is loaded to perform any 312*4882a593Smuzhiyun * early initialisation required by the platform code. Such as reading 313*4882a593Smuzhiyun * platform specific device tree entries for the GPU. 314*4882a593Smuzhiyun * 315*4882a593Smuzhiyun * Return: 0 for success, any other fail causes module initialisation to fail 316*4882a593Smuzhiyun */ 317*4882a593Smuzhiyun int kbase_platform_early_init(void); 318*4882a593Smuzhiyun 319*4882a593Smuzhiyun #ifndef CONFIG_OF 320*4882a593Smuzhiyun #ifdef CONFIG_MALI_PLATFORM_FAKE 321*4882a593Smuzhiyun /** 322*4882a593Smuzhiyun * kbase_platform_fake_register - Register a platform device for the GPU 323*4882a593Smuzhiyun * 324*4882a593Smuzhiyun * This can be used to register a platform device on systems where device tree 325*4882a593Smuzhiyun * is not enabled and the platform initialisation code in the kernel doesn't 326*4882a593Smuzhiyun * create the GPU device. Where possible device tree should be used instead. 327*4882a593Smuzhiyun * 328*4882a593Smuzhiyun * Return: 0 for success, any other fail causes module initialisation to fail 329*4882a593Smuzhiyun */ 330*4882a593Smuzhiyun int kbase_platform_fake_register(void); 331*4882a593Smuzhiyun 332*4882a593Smuzhiyun /** 333*4882a593Smuzhiyun * kbase_platform_fake_unregister - Unregister a fake platform device 334*4882a593Smuzhiyun * 335*4882a593Smuzhiyun * Unregister the platform device created with kbase_platform_fake_register() 336*4882a593Smuzhiyun */ 337*4882a593Smuzhiyun void kbase_platform_fake_unregister(void); 338*4882a593Smuzhiyun #endif 339*4882a593Smuzhiyun #endif 340*4882a593Smuzhiyun 341*4882a593Smuzhiyun /** @} *//* end group kbase_config */ 342*4882a593Smuzhiyun /** @} *//* end group base_kbase_api */ 343*4882a593Smuzhiyun /** @} *//* end group base_api */ 344*4882a593Smuzhiyun 345*4882a593Smuzhiyun #endif /* _KBASE_CONFIG_H_ */ 346