1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 /* 3 * 4 * (C) COPYRIGHT 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 #ifndef _KBASE_DEBUG_CORESIGHT_INTERNAL_CSF_H_ 23 #define _KBASE_DEBUG_CORESIGHT_INTERNAL_CSF_H_ 24 25 #include <mali_kbase.h> 26 #include <linux/mali_kbase_debug_coresight_csf.h> 27 28 /** 29 * struct kbase_debug_coresight_csf_client - Coresight client definition 30 * 31 * @drv_data: Pointer to driver device data. 32 * @addr_ranges: Arrays of address ranges used by the registered client. 33 * @nr_ranges: Size of @addr_ranges array. 34 * @link: Link item of a Coresight client. 35 * Linked to &struct_kbase_device.csf.coresight.clients. 36 */ 37 struct kbase_debug_coresight_csf_client { 38 void *drv_data; 39 struct kbase_debug_coresight_csf_address_range *addr_ranges; 40 u32 nr_ranges; 41 struct list_head link; 42 }; 43 44 /** 45 * enum kbase_debug_coresight_csf_state - Coresight configuration states 46 * 47 * @KBASE_DEBUG_CORESIGHT_CSF_DISABLED: Coresight configuration is disabled. 48 * @KBASE_DEBUG_CORESIGHT_CSF_ENABLED: Coresight configuration is enabled. 49 */ 50 enum kbase_debug_coresight_csf_state { 51 KBASE_DEBUG_CORESIGHT_CSF_DISABLED = 0, 52 KBASE_DEBUG_CORESIGHT_CSF_ENABLED, 53 }; 54 55 /** 56 * struct kbase_debug_coresight_csf_config - Coresight configuration definition 57 * 58 * @client: Pointer to the client for which the configuration is created. 59 * @enable_seq: Array of operations for Coresight client enable sequence. Can be NULL. 60 * @disable_seq: Array of operations for Coresight client disable sequence. Can be NULL. 61 * @state: Current Coresight configuration state. 62 * @error: Error code used to know if an error occurred during the execution 63 * of the enable or disable sequences. 64 * @link: Link item of a Coresight configuration. 65 * Linked to &struct_kbase_device.csf.coresight.configs. 66 */ 67 struct kbase_debug_coresight_csf_config { 68 void *client; 69 struct kbase_debug_coresight_csf_sequence *enable_seq; 70 struct kbase_debug_coresight_csf_sequence *disable_seq; 71 enum kbase_debug_coresight_csf_state state; 72 int error; 73 struct list_head link; 74 }; 75 76 /** 77 * struct kbase_debug_coresight_device - Object representing the Coresight device 78 * 79 * @clients: List head to maintain Coresight clients. 80 * @configs: List head to maintain Coresight configs. 81 * @lock: A lock to protect client/config lists. 82 * Lists can be accessed concurrently by 83 * Coresight kernel modules and kernel threads. 84 * @workq: Work queue for Coresight enable/disable execution. 85 * @enable_work: Work item used to enable Coresight. 86 * @disable_work: Work item used to disable Coresight. 87 * @event_wait: Wait queue for Coresight events. 88 * @enable_on_pmode_exit: Flag used by the PM state machine to 89 * identify if Coresight enable is needed. 90 * @disable_on_pmode_enter: Flag used by the PM state machine to 91 * identify if Coresight disable is needed. 92 */ 93 struct kbase_debug_coresight_device { 94 struct list_head clients; 95 struct list_head configs; 96 spinlock_t lock; 97 struct workqueue_struct *workq; 98 struct work_struct enable_work; 99 struct work_struct disable_work; 100 wait_queue_head_t event_wait; 101 bool enable_on_pmode_exit; 102 bool disable_on_pmode_enter; 103 }; 104 105 /** 106 * kbase_debug_coresight_csf_init - Initialize Coresight resources. 107 * 108 * @kbdev: Instance of a GPU platform device that implements a CSF interface. 109 * 110 * This function should be called once at device initialization. 111 * 112 * Return: 0 on success. 113 */ 114 int kbase_debug_coresight_csf_init(struct kbase_device *kbdev); 115 116 /** 117 * kbase_debug_coresight_csf_term - Terminate Coresight resources. 118 * 119 * @kbdev: Instance of a GPU platform device that implements a CSF interface. 120 * 121 * This function should be called at device termination to prevent any 122 * memory leaks if Coresight module would have been removed without calling 123 * kbasep_debug_coresight_csf_trace_disable(). 124 */ 125 void kbase_debug_coresight_csf_term(struct kbase_device *kbdev); 126 127 /** 128 * kbase_debug_coresight_csf_disable_pmode_enter - Disable Coresight on Protected 129 * mode enter. 130 * 131 * @kbdev: Instance of a GPU platform device that implements a CSF interface. 132 * 133 * This function should be called just before requesting to enter protected mode. 134 * It will trigger a PM state machine transition from MCU_ON 135 * to ON_PMODE_ENTER_CORESIGHT_DISABLE. 136 */ 137 void kbase_debug_coresight_csf_disable_pmode_enter(struct kbase_device *kbdev); 138 139 /** 140 * kbase_debug_coresight_csf_enable_pmode_exit - Enable Coresight on Protected 141 * mode enter. 142 * 143 * @kbdev: Instance of a GPU platform device that implements a CSF interface. 144 * 145 * This function should be called after protected mode exit is acknowledged. 146 * It will trigger a PM state machine transition from MCU_ON 147 * to ON_PMODE_EXIT_CORESIGHT_ENABLE. 148 */ 149 void kbase_debug_coresight_csf_enable_pmode_exit(struct kbase_device *kbdev); 150 151 /** 152 * kbase_debug_coresight_csf_state_request - Request Coresight state transition. 153 * 154 * @kbdev: Instance of a GPU platform device that implements a CSF interface. 155 * @state: Coresight state to check for. 156 */ 157 void kbase_debug_coresight_csf_state_request(struct kbase_device *kbdev, 158 enum kbase_debug_coresight_csf_state state); 159 160 /** 161 * kbase_debug_coresight_csf_state_check - Check Coresight state. 162 * 163 * @kbdev: Instance of a GPU platform device that implements a CSF interface. 164 * @state: Coresight state to check for. 165 * 166 * Return: true if all states of configs are @state. 167 */ 168 bool kbase_debug_coresight_csf_state_check(struct kbase_device *kbdev, 169 enum kbase_debug_coresight_csf_state state); 170 171 /** 172 * kbase_debug_coresight_csf_state_wait - Wait for Coresight state transition to complete. 173 * 174 * @kbdev: Instance of a GPU platform device that implements a CSF interface. 175 * @state: Coresight state to wait for. 176 * 177 * Return: true if all configs become @state in pre-defined time period. 178 */ 179 bool kbase_debug_coresight_csf_state_wait(struct kbase_device *kbdev, 180 enum kbase_debug_coresight_csf_state state); 181 182 #endif /* _KBASE_DEBUG_CORESIGHT_INTERNAL_CSF_H_ */ 183