1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 /* 3 * 4 * (C) COPYRIGHT 2019-2022 ARM Limited. All rights reserved. 5 * 6 * This program is free software and is provided to you under the terms of the 7 * GNU General Public License version 2 as published by the Free Software 8 * Foundation, and any use by you of this program is subject to the terms 9 * of such GNU license. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, you can access it online at 18 * http://www.gnu.org/licenses/gpl-2.0.html. 19 * 20 */ 21 22 /** 23 * DOC: Mali arbiter power manager state machine and APIs 24 */ 25 26 #ifndef _MALI_KBASE_ARBITER_PM_H_ 27 #define _MALI_KBASE_ARBITER_PM_H_ 28 29 #include "mali_kbase_arbif.h" 30 31 /** 32 * enum kbase_vm_state - Current PM Arbitration state. 33 * 34 * @KBASE_VM_STATE_INITIALIZING: Special state before arbiter is initialized. 35 * @KBASE_VM_STATE_INITIALIZING_WITH_GPU: Initialization after GPU 36 * has been granted. 37 * @KBASE_VM_STATE_SUSPENDED: KBase is suspended by OS and GPU is not assigned. 38 * @KBASE_VM_STATE_STOPPED: GPU is not assigned to KBase and is not required. 39 * @KBASE_VM_STATE_STOPPED_GPU_REQUESTED: GPU is not assigned to KBase 40 * but a request has been made. 41 * @KBASE_VM_STATE_STARTING: GPU is assigned and KBase is getting ready to run. 42 * @KBASE_VM_STATE_IDLE: GPU is assigned but KBase has no work to do 43 * @KBASE_VM_STATE_ACTIVE: GPU is assigned and KBase is busy using it 44 * @KBASE_VM_STATE_SUSPEND_PENDING: OS is going into suspend mode. 45 * @KBASE_VM_STATE_SUSPEND_WAIT_FOR_GRANT: OS is going into suspend mode but GPU 46 * has already been requested. 47 * In this situation we must wait for 48 * the Arbiter to send a GRANTED message 49 * and respond immediately with 50 * a STOPPED message before entering 51 * the suspend mode. 52 * @KBASE_VM_STATE_STOPPING_IDLE: Arbiter has sent a stopped message and there 53 * is currently no work to do on the GPU. 54 * @KBASE_VM_STATE_STOPPING_ACTIVE: Arbiter has sent a stopped message when 55 * KBase has work to do. 56 */ 57 enum kbase_vm_state { 58 KBASE_VM_STATE_INITIALIZING, 59 KBASE_VM_STATE_INITIALIZING_WITH_GPU, 60 KBASE_VM_STATE_SUSPENDED, 61 KBASE_VM_STATE_STOPPED, 62 KBASE_VM_STATE_STOPPED_GPU_REQUESTED, 63 KBASE_VM_STATE_STARTING, 64 KBASE_VM_STATE_IDLE, 65 KBASE_VM_STATE_ACTIVE, 66 KBASE_VM_STATE_SUSPEND_PENDING, 67 KBASE_VM_STATE_SUSPEND_WAIT_FOR_GRANT, 68 KBASE_VM_STATE_STOPPING_IDLE, 69 KBASE_VM_STATE_STOPPING_ACTIVE 70 }; 71 72 /** 73 * kbase_arbiter_pm_early_init() - Initialize arbiter for VM Paravirtualized use 74 * @kbdev: The kbase device structure for the device (must be a valid pointer) 75 * 76 * Initialize the arbiter and other required resources during the runtime 77 * and request the GPU for the VM for the first time. 78 * 79 * Return: 0 if successful, otherwise a standard Linux error code 80 */ 81 int kbase_arbiter_pm_early_init(struct kbase_device *kbdev); 82 83 /** 84 * kbase_arbiter_pm_early_term() - Shutdown arbiter and free resources. 85 * @kbdev: The kbase device structure for the device (must be a valid pointer) 86 * 87 * Clean up all the resources 88 */ 89 void kbase_arbiter_pm_early_term(struct kbase_device *kbdev); 90 91 /** 92 * kbase_arbiter_pm_release_interrupts() - Release the GPU interrupts 93 * @kbdev: The kbase device structure for the device (must be a valid pointer) 94 * 95 * Releases interrupts and set the interrupt flag to false 96 */ 97 void kbase_arbiter_pm_release_interrupts(struct kbase_device *kbdev); 98 99 /** 100 * kbase_arbiter_pm_install_interrupts() - Install the GPU interrupts 101 * @kbdev: The kbase device structure for the device (must be a valid pointer) 102 * 103 * Install interrupts and set the interrupt_install flag to true. 104 * 105 * Return: 0 if success, or a Linux error code 106 */ 107 int kbase_arbiter_pm_install_interrupts(struct kbase_device *kbdev); 108 109 /** 110 * kbase_arbiter_pm_vm_event() - Dispatch VM event to the state machine 111 * @kbdev: The kbase device structure for the device (must be a valid pointer) 112 * @event: The event to dispatch 113 * 114 * The state machine function. Receives events and transitions states 115 * according the event received and the current state 116 */ 117 void kbase_arbiter_pm_vm_event(struct kbase_device *kbdev, 118 enum kbase_arbif_evt event); 119 120 /** 121 * kbase_arbiter_pm_ctx_active_handle_suspend() - Handle suspend operation for 122 * arbitration mode 123 * @kbdev: The kbase device structure for the device (must be a valid pointer) 124 * @suspend_handler: The handler code for how to handle a suspend 125 * that might occur 126 * 127 * This function handles a suspend event from the driver, 128 * communicating with the arbiter and waiting synchronously for the GPU 129 * to be granted again depending on the VM state. 130 * 131 * Return: 0 if success, 1 if failure due to system suspending/suspended 132 */ 133 int kbase_arbiter_pm_ctx_active_handle_suspend(struct kbase_device *kbdev, 134 enum kbase_pm_suspend_handler suspend_handler); 135 136 137 /** 138 * kbase_arbiter_pm_vm_stopped() - Handle stop event for the VM 139 * @kbdev: The kbase device structure for the device (must be a valid pointer) 140 * 141 * This function handles a stop event for the VM. 142 * It will update the VM state and forward the stop event to the driver. 143 */ 144 void kbase_arbiter_pm_vm_stopped(struct kbase_device *kbdev); 145 146 /** 147 * kbase_arbiter_set_max_config() - Set the max config data in kbase device. 148 * @kbdev: The kbase device structure for the device (must be a valid pointer). 149 * @max_l2_slices: The maximum number of L2 slices. 150 * @max_core_mask: The largest core mask. 151 * 152 * This function handles a stop event for the VM. 153 * It will update the VM state and forward the stop event to the driver. 154 */ 155 void kbase_arbiter_set_max_config(struct kbase_device *kbdev, 156 uint32_t max_l2_slices, 157 uint32_t max_core_mask); 158 159 /** 160 * kbase_arbiter_pm_gpu_assigned() - Determine if this VM has access to the GPU 161 * @kbdev: The kbase device structure for the device (must be a valid pointer) 162 * 163 * Return: 0 if the VM does not have access, 1 if it does, and a negative number 164 * if an error occurred 165 */ 166 int kbase_arbiter_pm_gpu_assigned(struct kbase_device *kbdev); 167 168 extern struct kbase_clk_rate_trace_op_conf arb_clk_rate_trace_ops; 169 170 /** 171 * struct kbase_arbiter_freq - Holding the GPU clock frequency data retrieved 172 * from arbiter 173 * @arb_freq: GPU clock frequency value 174 * @arb_freq_lock: Mutex protecting access to arbfreq value 175 * @nb: Notifier block to receive rate change callbacks 176 * @freq_updated: Flag to indicate whether a frequency changed has just been 177 * communicated to avoid "GPU_GRANTED when not expected" warning 178 */ 179 struct kbase_arbiter_freq { 180 uint32_t arb_freq; 181 struct mutex arb_freq_lock; 182 struct notifier_block *nb; 183 bool freq_updated; 184 }; 185 186 /** 187 * kbase_arbiter_pm_update_gpu_freq() - Update GPU frequency 188 * @arb_freq: Pointer to GPU clock frequency data 189 * @freq: The new frequency 190 * 191 * Updates the GPU frequency and triggers any notifications 192 */ 193 void kbase_arbiter_pm_update_gpu_freq(struct kbase_arbiter_freq *arb_freq, 194 uint32_t freq); 195 196 #endif /*_MALI_KBASE_ARBITER_PM_H_ */ 197