1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2*4882a593Smuzhiyun /* 3*4882a593Smuzhiyun * 4*4882a593Smuzhiyun * (C) COPYRIGHT 2010-2017, 2019-2022 ARM Limited. All rights reserved. 5*4882a593Smuzhiyun * 6*4882a593Smuzhiyun * This program is free software and is provided to you under the terms of the 7*4882a593Smuzhiyun * GNU General Public License version 2 as published by the Free Software 8*4882a593Smuzhiyun * Foundation, and any use by you of this program is subject to the terms 9*4882a593Smuzhiyun * of such GNU license. 10*4882a593Smuzhiyun * 11*4882a593Smuzhiyun * This program is distributed in the hope that it will be useful, 12*4882a593Smuzhiyun * but WITHOUT ANY WARRANTY; without even the implied warranty of 13*4882a593Smuzhiyun * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14*4882a593Smuzhiyun * GNU General Public License for more details. 15*4882a593Smuzhiyun * 16*4882a593Smuzhiyun * You should have received a copy of the GNU General Public License 17*4882a593Smuzhiyun * along with this program; if not, you can access it online at 18*4882a593Smuzhiyun * http://www.gnu.org/licenses/gpl-2.0.html. 19*4882a593Smuzhiyun * 20*4882a593Smuzhiyun */ 21*4882a593Smuzhiyun 22*4882a593Smuzhiyun /** 23*4882a593Smuzhiyun * DOC: Configuration API and Attributes for KBase 24*4882a593Smuzhiyun */ 25*4882a593Smuzhiyun 26*4882a593Smuzhiyun #ifndef _KBASE_CONFIG_H_ 27*4882a593Smuzhiyun #define _KBASE_CONFIG_H_ 28*4882a593Smuzhiyun 29*4882a593Smuzhiyun #include <linux/mm.h> 30*4882a593Smuzhiyun #include <mali_malisw.h> 31*4882a593Smuzhiyun #include <backend/gpu/mali_kbase_backend_config.h> 32*4882a593Smuzhiyun #include <linux/rbtree.h> 33*4882a593Smuzhiyun 34*4882a593Smuzhiyun /* Forward declaration of struct kbase_device */ 35*4882a593Smuzhiyun struct kbase_device; 36*4882a593Smuzhiyun 37*4882a593Smuzhiyun #if !MALI_USE_CSF 38*4882a593Smuzhiyun /* Forward declaration of struct kbase_context */ 39*4882a593Smuzhiyun struct kbase_context; 40*4882a593Smuzhiyun 41*4882a593Smuzhiyun /* Forward declaration of struct kbase_atom */ 42*4882a593Smuzhiyun struct kbase_jd_atom; 43*4882a593Smuzhiyun #endif 44*4882a593Smuzhiyun 45*4882a593Smuzhiyun /** 46*4882a593Smuzhiyun * struct kbase_platform_funcs_conf - Specifies platform integration function 47*4882a593Smuzhiyun * pointers for DDK events such as device init and term. 48*4882a593Smuzhiyun * 49*4882a593Smuzhiyun * Specifies the functions pointers for platform specific initialization and 50*4882a593Smuzhiyun * termination as well as other events. By default no functions are required. 51*4882a593Smuzhiyun * No additional platform specific control is necessary. 52*4882a593Smuzhiyun */ 53*4882a593Smuzhiyun struct kbase_platform_funcs_conf { 54*4882a593Smuzhiyun /** 55*4882a593Smuzhiyun * @platform_init_func: platform specific init function pointer 56*4882a593Smuzhiyun * @kbdev - kbase_device pointer 57*4882a593Smuzhiyun * 58*4882a593Smuzhiyun * Returns 0 on success, negative error code otherwise. 59*4882a593Smuzhiyun * 60*4882a593Smuzhiyun * Function pointer for platform specific initialization or NULL if no 61*4882a593Smuzhiyun * initialization function is required. At the point this the GPU is 62*4882a593Smuzhiyun * not active and its power and clocks are in unknown (platform specific 63*4882a593Smuzhiyun * state) as kbase doesn't yet have control of power and clocks. 64*4882a593Smuzhiyun * 65*4882a593Smuzhiyun * The platform specific private pointer kbase_device::platform_context 66*4882a593Smuzhiyun * can be accessed (and possibly initialized) in here. 67*4882a593Smuzhiyun */ 68*4882a593Smuzhiyun int (*platform_init_func)(struct kbase_device *kbdev); 69*4882a593Smuzhiyun /** 70*4882a593Smuzhiyun * @platform_term_func: platform specific termination function pointer 71*4882a593Smuzhiyun * @kbdev - kbase_device pointer 72*4882a593Smuzhiyun * 73*4882a593Smuzhiyun * Function pointer for platform specific termination or NULL if no 74*4882a593Smuzhiyun * termination function is required. At the point this the GPU will be 75*4882a593Smuzhiyun * idle but still powered and clocked. 76*4882a593Smuzhiyun * 77*4882a593Smuzhiyun * The platform specific private pointer kbase_device::platform_context 78*4882a593Smuzhiyun * can be accessed (and possibly terminated) in here. 79*4882a593Smuzhiyun */ 80*4882a593Smuzhiyun void (*platform_term_func)(struct kbase_device *kbdev); 81*4882a593Smuzhiyun 82*4882a593Smuzhiyun /** 83*4882a593Smuzhiyun * @platform_late_init_func: platform specific late init function pointer 84*4882a593Smuzhiyun * @kbdev - kbase_device pointer 85*4882a593Smuzhiyun * 86*4882a593Smuzhiyun * Function pointer to inform that the kbase driver initialization completed 87*4882a593Smuzhiyun * or NULL if no such function is required. At this point the GPU driver will be 88*4882a593Smuzhiyun * fully initialized. 89*4882a593Smuzhiyun * 90*4882a593Smuzhiyun * The platform specific private pointer kbase_device::platform_context 91*4882a593Smuzhiyun * can be accessed (and possibly terminated) in here. 92*4882a593Smuzhiyun */ 93*4882a593Smuzhiyun int (*platform_late_init_func)(struct kbase_device *kbdev); 94*4882a593Smuzhiyun 95*4882a593Smuzhiyun /** 96*4882a593Smuzhiyun * @platform_late_term_func: platform specific late termination function pointer 97*4882a593Smuzhiyun * @kbdev - kbase_device pointer 98*4882a593Smuzhiyun * 99*4882a593Smuzhiyun * Function pointer for platform specific termination or NULL if no 100*4882a593Smuzhiyun * termination function is required. At this point the GPU driver will complete 101*4882a593Smuzhiyun * termination process 102*4882a593Smuzhiyun * 103*4882a593Smuzhiyun * The platform specific private pointer kbase_device::platform_context 104*4882a593Smuzhiyun * can be accessed (and possibly terminated) in here. 105*4882a593Smuzhiyun */ 106*4882a593Smuzhiyun void (*platform_late_term_func)(struct kbase_device *kbdev); 107*4882a593Smuzhiyun 108*4882a593Smuzhiyun #if !MALI_USE_CSF 109*4882a593Smuzhiyun /** 110*4882a593Smuzhiyun * @platform_handler_context_init_func: platform specific handler for 111*4882a593Smuzhiyun * when a new kbase_context is created. 112*4882a593Smuzhiyun * @kctx - kbase_context pointer 113*4882a593Smuzhiyun * 114*4882a593Smuzhiyun * Returns 0 on success, negative error code otherwise. 115*4882a593Smuzhiyun * 116*4882a593Smuzhiyun * Function pointer for platform specific initialization of a kernel 117*4882a593Smuzhiyun * context or NULL if not required. Called at the last stage of kernel 118*4882a593Smuzhiyun * context initialization. 119*4882a593Smuzhiyun */ 120*4882a593Smuzhiyun int (*platform_handler_context_init_func)(struct kbase_context *kctx); 121*4882a593Smuzhiyun /** 122*4882a593Smuzhiyun * @platform_handler_context_term_func: platform specific handler for 123*4882a593Smuzhiyun * when a kbase_context is terminated. 124*4882a593Smuzhiyun * @kctx - kbase_context pointer 125*4882a593Smuzhiyun * 126*4882a593Smuzhiyun * Function pointer for platform specific termination of a kernel 127*4882a593Smuzhiyun * context or NULL if not required. Called at the first stage of kernel 128*4882a593Smuzhiyun * context termination. 129*4882a593Smuzhiyun */ 130*4882a593Smuzhiyun void (*platform_handler_context_term_func)(struct kbase_context *kctx); 131*4882a593Smuzhiyun /** 132*4882a593Smuzhiyun * @platform_handler_atom_submit_func: platform specific handler for 133*4882a593Smuzhiyun * when a kbase_jd_atom is submitted. 134*4882a593Smuzhiyun * @katom - kbase_jd_atom pointer 135*4882a593Smuzhiyun * 136*4882a593Smuzhiyun * Function pointer for platform specific handling at the point when an 137*4882a593Smuzhiyun * atom is submitted to the GPU or set to NULL if not required. The 138*4882a593Smuzhiyun * function cannot assume that it is running in a process context. 139*4882a593Smuzhiyun * 140*4882a593Smuzhiyun * Context: The caller must hold the hwaccess_lock. Function must be 141*4882a593Smuzhiyun * runnable in an interrupt context. 142*4882a593Smuzhiyun */ 143*4882a593Smuzhiyun void (*platform_handler_atom_submit_func)(struct kbase_jd_atom *katom); 144*4882a593Smuzhiyun /** 145*4882a593Smuzhiyun * @platform_handler_atom_complete_func: platform specific handler for 146*4882a593Smuzhiyun * when a kbase_jd_atom completes. 147*4882a593Smuzhiyun * @katom - kbase_jd_atom pointer 148*4882a593Smuzhiyun * 149*4882a593Smuzhiyun * Function pointer for platform specific handling at the point when an 150*4882a593Smuzhiyun * atom stops running on the GPU or set to NULL if not required. The 151*4882a593Smuzhiyun * function cannot assume that it is running in a process context. 152*4882a593Smuzhiyun * 153*4882a593Smuzhiyun * Context: The caller must hold the hwaccess_lock. Function must be 154*4882a593Smuzhiyun * runnable in an interrupt context. 155*4882a593Smuzhiyun */ 156*4882a593Smuzhiyun void (*platform_handler_atom_complete_func)( 157*4882a593Smuzhiyun struct kbase_jd_atom *katom); 158*4882a593Smuzhiyun #endif 159*4882a593Smuzhiyun }; 160*4882a593Smuzhiyun 161*4882a593Smuzhiyun /* 162*4882a593Smuzhiyun * @brief Specifies the callbacks for power management 163*4882a593Smuzhiyun * 164*4882a593Smuzhiyun * By default no callbacks will be made and the GPU must not be powered off. 165*4882a593Smuzhiyun */ 166*4882a593Smuzhiyun struct kbase_pm_callback_conf { 167*4882a593Smuzhiyun /** Callback for when the GPU is idle and the power to it can be switched off. 168*4882a593Smuzhiyun * 169*4882a593Smuzhiyun * The system integrator can decide whether to either do nothing, just switch off 170*4882a593Smuzhiyun * the clocks to the GPU, or to completely power down the GPU. 171*4882a593Smuzhiyun * The platform specific private pointer kbase_device::platform_context can be accessed and modified in here. It is the 172*4882a593Smuzhiyun * platform \em callbacks responsibility to initialize and terminate this pointer if used (see @ref kbase_platform_funcs_conf). 173*4882a593Smuzhiyun * 174*4882a593Smuzhiyun * If runtime PM is enabled and @power_runtime_gpu_idle_callback is used 175*4882a593Smuzhiyun * then this callback should power off the GPU (or switch off the clocks 176*4882a593Smuzhiyun * to GPU) immediately. If @power_runtime_gpu_idle_callback is not used, 177*4882a593Smuzhiyun * then this callback can set the autosuspend timeout (if desired) and 178*4882a593Smuzhiyun * let the GPU be powered down later. 179*4882a593Smuzhiyun */ 180*4882a593Smuzhiyun void (*power_off_callback)(struct kbase_device *kbdev); 181*4882a593Smuzhiyun 182*4882a593Smuzhiyun /** Callback for when the GPU is about to become active and power must be supplied. 183*4882a593Smuzhiyun * 184*4882a593Smuzhiyun * This function must not return until the GPU is powered and clocked sufficiently for register access to 185*4882a593Smuzhiyun * succeed. The return value specifies whether the GPU was powered down since the call to power_off_callback. 186*4882a593Smuzhiyun * If the GPU state has been lost then this function must return 1, otherwise it should return 0. 187*4882a593Smuzhiyun * The platform specific private pointer kbase_device::platform_context can be accessed and modified in here. It is the 188*4882a593Smuzhiyun * platform \em callbacks responsibility to initialize and terminate this pointer if used (see @ref kbase_platform_funcs_conf). 189*4882a593Smuzhiyun * 190*4882a593Smuzhiyun * The return value of the first call to this function is ignored. 191*4882a593Smuzhiyun * 192*4882a593Smuzhiyun * @return 1 if the GPU state may have been lost, 0 otherwise. 193*4882a593Smuzhiyun */ 194*4882a593Smuzhiyun int (*power_on_callback)(struct kbase_device *kbdev); 195*4882a593Smuzhiyun 196*4882a593Smuzhiyun /** Callback for when the system is requesting a suspend and GPU power 197*4882a593Smuzhiyun * must be switched off. 198*4882a593Smuzhiyun * 199*4882a593Smuzhiyun * Note that if this callback is present, then this may be called 200*4882a593Smuzhiyun * without a preceding call to power_off_callback. Therefore this 201*4882a593Smuzhiyun * callback must be able to take any action that might otherwise happen 202*4882a593Smuzhiyun * in power_off_callback. 203*4882a593Smuzhiyun * 204*4882a593Smuzhiyun * The platform specific private pointer kbase_device::platform_context 205*4882a593Smuzhiyun * can be accessed and modified in here. It is the platform \em 206*4882a593Smuzhiyun * callbacks responsibility to initialize and terminate this pointer if 207*4882a593Smuzhiyun * used (see @ref kbase_platform_funcs_conf). 208*4882a593Smuzhiyun */ 209*4882a593Smuzhiyun void (*power_suspend_callback)(struct kbase_device *kbdev); 210*4882a593Smuzhiyun 211*4882a593Smuzhiyun /** Callback for when the system is resuming from a suspend and GPU 212*4882a593Smuzhiyun * power must be switched on. 213*4882a593Smuzhiyun * 214*4882a593Smuzhiyun * Note that if this callback is present, then this may be called 215*4882a593Smuzhiyun * without a following call to power_on_callback. Therefore this 216*4882a593Smuzhiyun * callback must be able to take any action that might otherwise happen 217*4882a593Smuzhiyun * in power_on_callback. 218*4882a593Smuzhiyun * 219*4882a593Smuzhiyun * The platform specific private pointer kbase_device::platform_context 220*4882a593Smuzhiyun * can be accessed and modified in here. It is the platform \em 221*4882a593Smuzhiyun * callbacks responsibility to initialize and terminate this pointer if 222*4882a593Smuzhiyun * used (see @ref kbase_platform_funcs_conf). 223*4882a593Smuzhiyun */ 224*4882a593Smuzhiyun void (*power_resume_callback)(struct kbase_device *kbdev); 225*4882a593Smuzhiyun 226*4882a593Smuzhiyun /** Callback for handling runtime power management initialization. 227*4882a593Smuzhiyun * 228*4882a593Smuzhiyun * The runtime power management callbacks @ref power_runtime_off_callback and @ref power_runtime_on_callback 229*4882a593Smuzhiyun * will become active from calls made to the OS from within this function. 230*4882a593Smuzhiyun * The runtime calls can be triggered by calls from @ref power_off_callback and @ref power_on_callback. 231*4882a593Smuzhiyun * Note: for linux the kernel must have CONFIG_PM_RUNTIME enabled to use this feature. 232*4882a593Smuzhiyun * 233*4882a593Smuzhiyun * @return 0 on success, else int error code. 234*4882a593Smuzhiyun */ 235*4882a593Smuzhiyun int (*power_runtime_init_callback)(struct kbase_device *kbdev); 236*4882a593Smuzhiyun 237*4882a593Smuzhiyun /** Callback for handling runtime power management termination. 238*4882a593Smuzhiyun * 239*4882a593Smuzhiyun * The runtime power management callbacks @ref power_runtime_off_callback and @ref power_runtime_on_callback 240*4882a593Smuzhiyun * should no longer be called by the OS on completion of this function. 241*4882a593Smuzhiyun * Note: for linux the kernel must have CONFIG_PM_RUNTIME enabled to use this feature. 242*4882a593Smuzhiyun */ 243*4882a593Smuzhiyun void (*power_runtime_term_callback)(struct kbase_device *kbdev); 244*4882a593Smuzhiyun 245*4882a593Smuzhiyun /** Callback for runtime power-off power management callback 246*4882a593Smuzhiyun * 247*4882a593Smuzhiyun * For linux this callback will be called by the kernel runtime_suspend callback. 248*4882a593Smuzhiyun * Note: for linux the kernel must have CONFIG_PM_RUNTIME enabled to use this feature. 249*4882a593Smuzhiyun */ 250*4882a593Smuzhiyun void (*power_runtime_off_callback)(struct kbase_device *kbdev); 251*4882a593Smuzhiyun 252*4882a593Smuzhiyun /** Callback for runtime power-on power management callback 253*4882a593Smuzhiyun * 254*4882a593Smuzhiyun * For linux this callback will be called by the kernel runtime_resume callback. 255*4882a593Smuzhiyun * Note: for linux the kernel must have CONFIG_PM_RUNTIME enabled to use this feature. 256*4882a593Smuzhiyun * 257*4882a593Smuzhiyun * @return 0 on success, else OS error code. 258*4882a593Smuzhiyun */ 259*4882a593Smuzhiyun int (*power_runtime_on_callback)(struct kbase_device *kbdev); 260*4882a593Smuzhiyun 261*4882a593Smuzhiyun /* 262*4882a593Smuzhiyun * Optional callback for checking if GPU can be suspended when idle 263*4882a593Smuzhiyun * 264*4882a593Smuzhiyun * This callback will be called by the runtime power management core 265*4882a593Smuzhiyun * when the reference count goes to 0 to provide notification that the 266*4882a593Smuzhiyun * GPU now seems idle. 267*4882a593Smuzhiyun * 268*4882a593Smuzhiyun * If this callback finds that the GPU can't be powered off, or handles 269*4882a593Smuzhiyun * suspend by powering off directly or queueing up a power off, a 270*4882a593Smuzhiyun * non-zero value must be returned to prevent the runtime PM core from 271*4882a593Smuzhiyun * also triggering a suspend. 272*4882a593Smuzhiyun * 273*4882a593Smuzhiyun * Returning 0 will cause the runtime PM core to conduct a regular 274*4882a593Smuzhiyun * autosuspend. 275*4882a593Smuzhiyun * 276*4882a593Smuzhiyun * This callback is optional and if not provided regular autosuspend 277*4882a593Smuzhiyun * will be triggered. 278*4882a593Smuzhiyun * 279*4882a593Smuzhiyun * Note: The Linux kernel must have CONFIG_PM_RUNTIME enabled to use 280*4882a593Smuzhiyun * this feature. 281*4882a593Smuzhiyun * 282*4882a593Smuzhiyun * Return 0 if GPU can be suspended, positive value if it can not be 283*4882a593Smuzhiyun * suspeneded by runtime PM, else OS error code 284*4882a593Smuzhiyun */ 285*4882a593Smuzhiyun int (*power_runtime_idle_callback)(struct kbase_device *kbdev); 286*4882a593Smuzhiyun 287*4882a593Smuzhiyun /* 288*4882a593Smuzhiyun * Optional callback for software reset 289*4882a593Smuzhiyun * 290*4882a593Smuzhiyun * This callback will be called by the power management core to trigger 291*4882a593Smuzhiyun * a GPU soft reset. 292*4882a593Smuzhiyun * 293*4882a593Smuzhiyun * Return 0 if the soft reset was successful and the RESET_COMPLETED 294*4882a593Smuzhiyun * interrupt will be raised, or a positive value if the interrupt won't 295*4882a593Smuzhiyun * be raised. On error, return the corresponding OS error code. 296*4882a593Smuzhiyun */ 297*4882a593Smuzhiyun int (*soft_reset_callback)(struct kbase_device *kbdev); 298*4882a593Smuzhiyun 299*4882a593Smuzhiyun /* 300*4882a593Smuzhiyun * Optional callback invoked after GPU becomes idle, not supported on 301*4882a593Smuzhiyun * JM GPUs. 302*4882a593Smuzhiyun * 303*4882a593Smuzhiyun * This callback will be invoked by the Kbase when GPU becomes idle. 304*4882a593Smuzhiyun * For JM GPUs or when runtime PM is disabled, Kbase will not invoke 305*4882a593Smuzhiyun * this callback and @power_off_callback will be invoked directly. 306*4882a593Smuzhiyun * 307*4882a593Smuzhiyun * This callback is supposed to decrement the runtime PM core reference 308*4882a593Smuzhiyun * count to zero and trigger the auto-suspend timer, which implies that 309*4882a593Smuzhiyun * @power_off_callback shouldn't initiate the runtime suspend. 310*4882a593Smuzhiyun * 311*4882a593Smuzhiyun * GPU registers still remain accessible until @power_off_callback gets 312*4882a593Smuzhiyun * invoked later on the expiry of auto-suspend timer. 313*4882a593Smuzhiyun * 314*4882a593Smuzhiyun * Note: The Linux kernel must have CONFIG_PM_RUNTIME enabled to use 315*4882a593Smuzhiyun * this feature. 316*4882a593Smuzhiyun */ 317*4882a593Smuzhiyun void (*power_runtime_gpu_idle_callback)(struct kbase_device *kbdev); 318*4882a593Smuzhiyun 319*4882a593Smuzhiyun /* 320*4882a593Smuzhiyun * Optional callback invoked to change the runtime PM core state to 321*4882a593Smuzhiyun * active. 322*4882a593Smuzhiyun * 323*4882a593Smuzhiyun * This callback will be invoked by Kbase when GPU needs to be 324*4882a593Smuzhiyun * reactivated, but only if @power_runtime_gpu_idle_callback was invoked 325*4882a593Smuzhiyun * previously. So both @power_runtime_gpu_idle_callback and this 326*4882a593Smuzhiyun * callback needs to be implemented at the same time. 327*4882a593Smuzhiyun * 328*4882a593Smuzhiyun * Kbase will invoke @power_on_callback first before invoking this 329*4882a593Smuzhiyun * callback if the GPU was powered down previously, otherwise directly. 330*4882a593Smuzhiyun * 331*4882a593Smuzhiyun * This callback is supposed to increment the runtime PM core reference 332*4882a593Smuzhiyun * count to 1, which implies that @power_on_callback shouldn't initiate 333*4882a593Smuzhiyun * the runtime resume. The runtime resume may not happen synchronously 334*4882a593Smuzhiyun * to avoid a potential deadlock due to the runtime suspend happening 335*4882a593Smuzhiyun * simultaneously from some other thread. 336*4882a593Smuzhiyun * 337*4882a593Smuzhiyun * Note: The Linux kernel must have CONFIG_PM_RUNTIME enabled to use 338*4882a593Smuzhiyun * this feature. 339*4882a593Smuzhiyun */ 340*4882a593Smuzhiyun void (*power_runtime_gpu_active_callback)(struct kbase_device *kbdev); 341*4882a593Smuzhiyun }; 342*4882a593Smuzhiyun 343*4882a593Smuzhiyun /* struct kbase_gpu_clk_notifier_data - Data for clock rate change notifier. 344*4882a593Smuzhiyun * 345*4882a593Smuzhiyun * Pointer to this structure is supposed to be passed to the gpu clock rate 346*4882a593Smuzhiyun * change notifier function. This structure is deliberately aligned with the 347*4882a593Smuzhiyun * common clock framework notification structure 'struct clk_notifier_data' 348*4882a593Smuzhiyun * and such alignment should be maintained. 349*4882a593Smuzhiyun * 350*4882a593Smuzhiyun * @gpu_clk_handle: Handle of the GPU clock for which notifier was registered. 351*4882a593Smuzhiyun * @old_rate: Previous rate of this GPU clock in Hz. 352*4882a593Smuzhiyun * @new_rate: New rate of this GPU clock in Hz. 353*4882a593Smuzhiyun */ 354*4882a593Smuzhiyun struct kbase_gpu_clk_notifier_data { 355*4882a593Smuzhiyun void *gpu_clk_handle; 356*4882a593Smuzhiyun unsigned long old_rate; 357*4882a593Smuzhiyun unsigned long new_rate; 358*4882a593Smuzhiyun }; 359*4882a593Smuzhiyun 360*4882a593Smuzhiyun /** 361*4882a593Smuzhiyun * struct kbase_clk_rate_trace_op_conf - Specifies GPU clock rate trace 362*4882a593Smuzhiyun * operations. 363*4882a593Smuzhiyun * 364*4882a593Smuzhiyun * Specifies the functions pointers for platform specific GPU clock rate trace 365*4882a593Smuzhiyun * operations. By default no functions are required. 366*4882a593Smuzhiyun */ 367*4882a593Smuzhiyun struct kbase_clk_rate_trace_op_conf { 368*4882a593Smuzhiyun /** 369*4882a593Smuzhiyun * @enumerate_gpu_clk: Enumerate a GPU clock on the given index 370*4882a593Smuzhiyun * @kbdev - kbase_device pointer 371*4882a593Smuzhiyun * @index - GPU clock index 372*4882a593Smuzhiyun * 373*4882a593Smuzhiyun * Returns a handle unique to the given GPU clock, or NULL if the clock 374*4882a593Smuzhiyun * array has been exhausted at the given index value. 375*4882a593Smuzhiyun * 376*4882a593Smuzhiyun * Kbase will use this function pointer to enumerate the existence of a 377*4882a593Smuzhiyun * GPU clock on the given index. 378*4882a593Smuzhiyun */ 379*4882a593Smuzhiyun void *(*enumerate_gpu_clk)(struct kbase_device *kbdev, 380*4882a593Smuzhiyun unsigned int index); 381*4882a593Smuzhiyun 382*4882a593Smuzhiyun /** 383*4882a593Smuzhiyun * @get_gpu_clk_rate: Get the current rate for an enumerated clock. 384*4882a593Smuzhiyun * @kbdev - kbase_device pointer 385*4882a593Smuzhiyun * @gpu_clk_handle - Handle unique to the enumerated GPU clock 386*4882a593Smuzhiyun * 387*4882a593Smuzhiyun * Returns current rate of the GPU clock in unit of Hz. 388*4882a593Smuzhiyun */ 389*4882a593Smuzhiyun unsigned long (*get_gpu_clk_rate)(struct kbase_device *kbdev, 390*4882a593Smuzhiyun void *gpu_clk_handle); 391*4882a593Smuzhiyun 392*4882a593Smuzhiyun /** 393*4882a593Smuzhiyun * @gpu_clk_notifier_register: Register a clock rate change notifier. 394*4882a593Smuzhiyun * @kbdev - kbase_device pointer 395*4882a593Smuzhiyun * @gpu_clk_handle - Handle unique to the enumerated GPU clock 396*4882a593Smuzhiyun * @nb - notifier block containing the callback function 397*4882a593Smuzhiyun * pointer 398*4882a593Smuzhiyun * 399*4882a593Smuzhiyun * Returns 0 on success, negative error code otherwise. 400*4882a593Smuzhiyun * 401*4882a593Smuzhiyun * This function pointer is used to register a callback function that 402*4882a593Smuzhiyun * is supposed to be invoked whenever the rate of clock corresponding 403*4882a593Smuzhiyun * to @gpu_clk_handle changes. 404*4882a593Smuzhiyun * @nb contains the pointer to callback function. 405*4882a593Smuzhiyun * The callback function expects the pointer of type 406*4882a593Smuzhiyun * 'struct kbase_gpu_clk_notifier_data' as the third argument. 407*4882a593Smuzhiyun */ 408*4882a593Smuzhiyun int (*gpu_clk_notifier_register)(struct kbase_device *kbdev, 409*4882a593Smuzhiyun void *gpu_clk_handle, struct notifier_block *nb); 410*4882a593Smuzhiyun 411*4882a593Smuzhiyun /** 412*4882a593Smuzhiyun * @gpu_clk_notifier_unregister: Unregister clock rate change notifier 413*4882a593Smuzhiyun * @kbdev - kbase_device pointer 414*4882a593Smuzhiyun * @gpu_clk_handle - Handle unique to the enumerated GPU clock 415*4882a593Smuzhiyun * @nb - notifier block containing the callback function 416*4882a593Smuzhiyun * pointer 417*4882a593Smuzhiyun * 418*4882a593Smuzhiyun * This function pointer is used to unregister a callback function that 419*4882a593Smuzhiyun * was previously registered to get notified of the change in rate 420*4882a593Smuzhiyun * of clock corresponding to @gpu_clk_handle. 421*4882a593Smuzhiyun */ 422*4882a593Smuzhiyun void (*gpu_clk_notifier_unregister)(struct kbase_device *kbdev, 423*4882a593Smuzhiyun void *gpu_clk_handle, struct notifier_block *nb); 424*4882a593Smuzhiyun }; 425*4882a593Smuzhiyun 426*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_OF) 427*4882a593Smuzhiyun struct kbase_platform_config { 428*4882a593Smuzhiyun }; 429*4882a593Smuzhiyun #else 430*4882a593Smuzhiyun 431*4882a593Smuzhiyun /* 432*4882a593Smuzhiyun * @brief Specifies start and end of I/O memory region. 433*4882a593Smuzhiyun */ 434*4882a593Smuzhiyun struct kbase_io_memory_region { 435*4882a593Smuzhiyun u64 start; 436*4882a593Smuzhiyun u64 end; 437*4882a593Smuzhiyun }; 438*4882a593Smuzhiyun 439*4882a593Smuzhiyun /* 440*4882a593Smuzhiyun * @brief Specifies I/O related resources like IRQs and memory region for I/O operations. 441*4882a593Smuzhiyun */ 442*4882a593Smuzhiyun struct kbase_io_resources { 443*4882a593Smuzhiyun u32 job_irq_number; 444*4882a593Smuzhiyun u32 mmu_irq_number; 445*4882a593Smuzhiyun u32 gpu_irq_number; 446*4882a593Smuzhiyun struct kbase_io_memory_region io_memory_region; 447*4882a593Smuzhiyun }; 448*4882a593Smuzhiyun 449*4882a593Smuzhiyun struct kbase_platform_config { 450*4882a593Smuzhiyun const struct kbase_io_resources *io_resources; 451*4882a593Smuzhiyun }; 452*4882a593Smuzhiyun 453*4882a593Smuzhiyun #endif /* CONFIG_OF */ 454*4882a593Smuzhiyun 455*4882a593Smuzhiyun /** 456*4882a593Smuzhiyun * kbase_get_platform_config - Gets the pointer to platform config. 457*4882a593Smuzhiyun * 458*4882a593Smuzhiyun * Return: Pointer to the platform config 459*4882a593Smuzhiyun */ 460*4882a593Smuzhiyun struct kbase_platform_config *kbase_get_platform_config(void); 461*4882a593Smuzhiyun 462*4882a593Smuzhiyun /** 463*4882a593Smuzhiyun * kbasep_platform_device_init: - Platform specific call to initialize hardware 464*4882a593Smuzhiyun * @kbdev: kbase device pointer 465*4882a593Smuzhiyun * 466*4882a593Smuzhiyun * Function calls a platform defined routine if specified in the configuration 467*4882a593Smuzhiyun * attributes. The routine can initialize any hardware and context state that 468*4882a593Smuzhiyun * is required for the GPU block to function. 469*4882a593Smuzhiyun * 470*4882a593Smuzhiyun * Return: 0 if no errors have been found in the config. 471*4882a593Smuzhiyun * Negative error code otherwise. 472*4882a593Smuzhiyun */ 473*4882a593Smuzhiyun int kbasep_platform_device_init(struct kbase_device *kbdev); 474*4882a593Smuzhiyun 475*4882a593Smuzhiyun /** 476*4882a593Smuzhiyun * kbasep_platform_device_term - Platform specific call to terminate hardware 477*4882a593Smuzhiyun * @kbdev: Kbase device pointer 478*4882a593Smuzhiyun * 479*4882a593Smuzhiyun * Function calls a platform defined routine if specified in the configuration 480*4882a593Smuzhiyun * attributes. The routine can destroy any platform specific context state and 481*4882a593Smuzhiyun * shut down any hardware functionality that are outside of the Power Management 482*4882a593Smuzhiyun * callbacks. 483*4882a593Smuzhiyun * 484*4882a593Smuzhiyun */ 485*4882a593Smuzhiyun void kbasep_platform_device_term(struct kbase_device *kbdev); 486*4882a593Smuzhiyun 487*4882a593Smuzhiyun /** 488*4882a593Smuzhiyun * kbasep_platform_device_late_init: - Platform specific call to finish hardware 489*4882a593Smuzhiyun * initialization 490*4882a593Smuzhiyun * @kbdev: kbase device pointer 491*4882a593Smuzhiyun * 492*4882a593Smuzhiyun * Function calls a platform defined routine if specified in the configuration 493*4882a593Smuzhiyun * attributes. The routine can initialize any hardware and context state that 494*4882a593Smuzhiyun * is required for the GPU block to function. 495*4882a593Smuzhiyun * 496*4882a593Smuzhiyun * Return: 0 if no errors have been found in the config. 497*4882a593Smuzhiyun * Negative error code otherwise. 498*4882a593Smuzhiyun */ 499*4882a593Smuzhiyun int kbasep_platform_device_late_init(struct kbase_device *kbdev); 500*4882a593Smuzhiyun 501*4882a593Smuzhiyun /** 502*4882a593Smuzhiyun * kbasep_platform_device_late_term - Platform specific call to finish hardware 503*4882a593Smuzhiyun * termination 504*4882a593Smuzhiyun * @kbdev: Kbase device pointer 505*4882a593Smuzhiyun * 506*4882a593Smuzhiyun * Function calls a platform defined routine if specified in the configuration 507*4882a593Smuzhiyun * attributes. The routine can destroy any platform specific context state and 508*4882a593Smuzhiyun * shut down any hardware functionality that are outside of the Power Management 509*4882a593Smuzhiyun * callbacks. 510*4882a593Smuzhiyun * 511*4882a593Smuzhiyun */ 512*4882a593Smuzhiyun void kbasep_platform_device_late_term(struct kbase_device *kbdev); 513*4882a593Smuzhiyun 514*4882a593Smuzhiyun #if !MALI_USE_CSF 515*4882a593Smuzhiyun /** 516*4882a593Smuzhiyun * kbasep_platform_context_init - Platform specific callback when a kernel 517*4882a593Smuzhiyun * context is created 518*4882a593Smuzhiyun * @kctx: kbase_context pointer 519*4882a593Smuzhiyun * 520*4882a593Smuzhiyun * Function calls a platform defined routine if specified in the configuration 521*4882a593Smuzhiyun * attributes. The routine can initialize any per kernel context structures 522*4882a593Smuzhiyun * that are required for the GPU block to function. 523*4882a593Smuzhiyun * 524*4882a593Smuzhiyun * Return: 0 if no errors were encountered. Negative error code otherwise. 525*4882a593Smuzhiyun */ 526*4882a593Smuzhiyun int kbasep_platform_context_init(struct kbase_context *kctx); 527*4882a593Smuzhiyun 528*4882a593Smuzhiyun /** 529*4882a593Smuzhiyun * kbasep_platform_context_term - Platform specific callback when a kernel 530*4882a593Smuzhiyun * context is terminated 531*4882a593Smuzhiyun * @kctx: kbase_context pointer 532*4882a593Smuzhiyun * 533*4882a593Smuzhiyun * Function calls a platform defined routine if specified in the configuration 534*4882a593Smuzhiyun * attributes. The routine should terminate any per kernel context structures 535*4882a593Smuzhiyun * created as part of &kbasep_platform_context_init. 536*4882a593Smuzhiyun * 537*4882a593Smuzhiyun */ 538*4882a593Smuzhiyun void kbasep_platform_context_term(struct kbase_context *kctx); 539*4882a593Smuzhiyun 540*4882a593Smuzhiyun /** 541*4882a593Smuzhiyun * kbasep_platform_event_atom_submit - Platform specific callback when an atom 542*4882a593Smuzhiyun * is submitted to the GPU 543*4882a593Smuzhiyun * @katom: kbase_jd_atom pointer 544*4882a593Smuzhiyun * 545*4882a593Smuzhiyun * Function calls a platform defined routine if specified in the configuration 546*4882a593Smuzhiyun * attributes. The routine should not assume that it is in a process context. 547*4882a593Smuzhiyun * 548*4882a593Smuzhiyun * Return: 0 if no errors were encountered. Negative error code otherwise. 549*4882a593Smuzhiyun */ 550*4882a593Smuzhiyun void kbasep_platform_event_atom_submit(struct kbase_jd_atom *katom); 551*4882a593Smuzhiyun 552*4882a593Smuzhiyun /** 553*4882a593Smuzhiyun * kbasep_platform_event_atom_complete - Platform specific callback when an atom 554*4882a593Smuzhiyun * has stopped running on the GPU 555*4882a593Smuzhiyun * @katom: kbase_jd_atom pointer 556*4882a593Smuzhiyun * 557*4882a593Smuzhiyun * Function calls a platform defined routine if specified in the configuration 558*4882a593Smuzhiyun * attributes. The routine should not assume that it is in a process context. 559*4882a593Smuzhiyun * 560*4882a593Smuzhiyun */ 561*4882a593Smuzhiyun void kbasep_platform_event_atom_complete(struct kbase_jd_atom *katom); 562*4882a593Smuzhiyun #endif 563*4882a593Smuzhiyun 564*4882a593Smuzhiyun #ifndef CONFIG_OF 565*4882a593Smuzhiyun /** 566*4882a593Smuzhiyun * kbase_platform_register - Register a platform device for the GPU 567*4882a593Smuzhiyun * This can be used to register a platform device on systems where device tree 568*4882a593Smuzhiyun * is not enabled and the platform initialisation code in the kernel doesn't 569*4882a593Smuzhiyun * create the GPU device. Where possible device tree should be used instead. 570*4882a593Smuzhiyun * 571*4882a593Smuzhiyun * Return: 0 for success, any other fail causes module initialisation to fail 572*4882a593Smuzhiyun */ 573*4882a593Smuzhiyun int kbase_platform_register(void); 574*4882a593Smuzhiyun 575*4882a593Smuzhiyun /** 576*4882a593Smuzhiyun * kbase_platform_unregister - Unregister a fake platform device 577*4882a593Smuzhiyun * 578*4882a593Smuzhiyun * Unregister the platform device created with kbase_platform_register() 579*4882a593Smuzhiyun */ 580*4882a593Smuzhiyun void kbase_platform_unregister(void); 581*4882a593Smuzhiyun #endif 582*4882a593Smuzhiyun 583*4882a593Smuzhiyun #endif /* _KBASE_CONFIG_H_ */ 584