• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 /*
3  *
4  * (C) COPYRIGHT 2019-2021 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  * 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 int kbase_arbiter_pm_install_interrupts(struct kbase_device *kbdev);
106 
107 /**
108  * kbase_arbiter_pm_vm_event() - Dispatch VM event to the state machine
109  * @kbdev: The kbase device structure for the device (must be a valid pointer)
110  * @event: The event to dispatch
111  *
112  * The state machine function. Receives events and transitions states
113  * according the event received and the current state
114  */
115 void kbase_arbiter_pm_vm_event(struct kbase_device *kbdev,
116 	enum kbase_arbif_evt event);
117 
118 /**
119  * kbase_arbiter_pm_ctx_active_handle_suspend() - Handle suspend operation for
120  *                                                arbitration mode
121  * @kbdev: The kbase device structure for the device (must be a valid pointer)
122  * @suspend_handler: The handler code for how to handle a suspend
123  *                   that might occur
124  *
125  * This function handles a suspend event from the driver,
126  * communicating with the arbiter and waiting synchronously for the GPU
127  * to be granted again depending on the VM state.
128  *
129  * Return: 0 if success, 1 if failure due to system suspending/suspended
130  */
131 int kbase_arbiter_pm_ctx_active_handle_suspend(struct kbase_device *kbdev,
132 	enum kbase_pm_suspend_handler suspend_handler);
133 
134 
135 /**
136  * kbase_arbiter_pm_vm_stopped() - Handle stop event for the VM
137  * @kbdev: The kbase device structure for the device (must be a valid pointer)
138  *
139  * This function handles a stop event for the VM.
140  * It will update the VM state and forward the stop event to the driver.
141  */
142 void kbase_arbiter_pm_vm_stopped(struct kbase_device *kbdev);
143 
144 /**
145  * kbase_arbiter_set_max_config() - Set the max config data in kbase device.
146  * @kbdev: The kbase device structure for the device (must be a valid pointer).
147  * @max_l2_slices: The maximum number of L2 slices.
148  * @max_core_mask: The largest core mask.
149  *
150  * This function handles a stop event for the VM.
151  * It will update the VM state and forward the stop event to the driver.
152  */
153 void kbase_arbiter_set_max_config(struct kbase_device *kbdev,
154 				  uint32_t max_l2_slices,
155 				  uint32_t max_core_mask);
156 
157 /**
158  * kbase_arbiter_pm_gpu_assigned() - Determine if this VM has access to the GPU
159  * @kbdev: The kbase device structure for the device (must be a valid pointer)
160  *
161  * Return: 0 if the VM does not have access, 1 if it does, and a negative number
162  * if an error occurred
163  */
164 int kbase_arbiter_pm_gpu_assigned(struct kbase_device *kbdev);
165 
166 extern struct kbase_clk_rate_trace_op_conf arb_clk_rate_trace_ops;
167 
168 /**
169  * struct kbase_arbiter_freq - Holding the GPU clock frequency data retrieved
170  * from arbiter
171  * @arb_freq:      GPU clock frequency value
172  * @arb_freq_lock: Mutex protecting access to arbfreq value
173  * @nb:            Notifier block to receive rate change callbacks
174  * @freq_updated:  Flag to indicate whether a frequency changed has just been
175  *                 communicated to avoid "GPU_GRANTED when not expected" warning
176  */
177 struct kbase_arbiter_freq {
178 	uint32_t arb_freq;
179 	struct mutex arb_freq_lock;
180 	struct notifier_block *nb;
181 	bool freq_updated;
182 };
183 
184 /**
185  * kbase_arbiter_pm_update_gpu_freq() - Update GPU frequency
186  * @arb_freq: Pointer to GPU clock frequency data
187  * @freq:     The new frequency
188  *
189  * Updates the GPU frequency and triggers any notifications
190  */
191 void kbase_arbiter_pm_update_gpu_freq(struct kbase_arbiter_freq *arb_freq,
192 	uint32_t freq);
193 
194 #endif /*_MALI_KBASE_ARBITER_PM_H_ */
195