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