hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/gpu/arm/bifrost/csf/mali_kbase_csf.h
....@@ -1,7 +1,7 @@
11 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
22 /*
33 *
4
- * (C) COPYRIGHT 2018-2021 ARM Limited. All rights reserved.
4
+ * (C) COPYRIGHT 2018-2023 ARM Limited. All rights reserved.
55 *
66 * This program is free software and is provided to you under the terms of the
77 * GNU General Public License version 2 as published by the Free Software
....@@ -26,6 +26,7 @@
2626 #include "mali_kbase_csf_scheduler.h"
2727 #include "mali_kbase_csf_firmware.h"
2828 #include "mali_kbase_csf_protected_memory.h"
29
+#include "mali_kbase_hwaccess_time.h"
2930
3031 /* Indicate invalid CS h/w interface
3132 */
....@@ -39,132 +40,18 @@
3940 */
4041 #define KBASEP_USER_DB_NR_INVALID ((s8)-1)
4142
42
-#define FIRMWARE_PING_INTERVAL_MS (4000) /* 4 seconds */
43
+/* Number of pages used for GPU command queue's User input & output data */
44
+#define KBASEP_NUM_CS_USER_IO_PAGES (2)
4345
44
-#define FIRMWARE_IDLE_HYSTERESIS_TIME_MS (10) /* Default 10 milliseconds */
45
-
46
-/**
47
- * enum kbase_csf_event_callback_action - return type for CSF event callbacks.
48
- *
49
- * @KBASE_CSF_EVENT_CALLBACK_FIRST: Never set explicitly.
50
- * It doesn't correspond to any action or type of event callback.
51
- *
52
- * @KBASE_CSF_EVENT_CALLBACK_KEEP: The callback will remain registered.
53
- *
54
- * @KBASE_CSF_EVENT_CALLBACK_REMOVE: The callback will be removed
55
- * immediately upon return.
56
- *
57
- * @KBASE_CSF_EVENT_CALLBACK_LAST: Never set explicitly.
58
- * It doesn't correspond to any action or type of event callback.
46
+/* Indicates an invalid value for the scan out sequence number, used to
47
+ * signify there is no group that has protected mode execution pending.
5948 */
60
-enum kbase_csf_event_callback_action {
61
- KBASE_CSF_EVENT_CALLBACK_FIRST = 0,
62
- KBASE_CSF_EVENT_CALLBACK_KEEP,
63
- KBASE_CSF_EVENT_CALLBACK_REMOVE,
64
- KBASE_CSF_EVENT_CALLBACK_LAST,
65
-};
49
+#define KBASEP_TICK_PROTM_PEND_SCAN_SEQ_NR_INVALID (U32_MAX)
6650
67
-/**
68
- * kbase_csf_event_callback_action - type for callback functions to be
69
- * called upon CSF events.
70
- *
71
- * This is the type of callback functions that can be registered
72
- * for CSF events. These function calls shall be triggered by any call
73
- * to kbase_csf_event_signal.
74
- *
75
- * @param: Generic parameter to pass to the callback function.
76
- *
77
- * Return: KBASE_CSF_EVENT_CALLBACK_KEEP if the callback should remain
78
- * registered, or KBASE_CSF_EVENT_CALLBACK_REMOVE if it should be removed.
79
- */
80
-typedef enum kbase_csf_event_callback_action kbase_csf_event_callback(void *param);
51
+#define FIRMWARE_IDLE_HYSTERESIS_TIME_USEC (10000) /* Default 10 milliseconds */
8152
82
-/**
83
- * kbase_csf_event_wait_add - Add a CSF event callback
84
- *
85
- * This function adds an event callback to the list of CSF event callbacks
86
- * belonging to a given Kbase context, to be triggered when a CSF event is
87
- * signalled by kbase_csf_event_signal.
88
- *
89
- * @kctx: The Kbase context the @callback should be registered to.
90
- * @callback: The callback function to register.
91
- * @param: Custom parameter to be passed to the @callback function.
92
- *
93
- * Return: 0 on success, or negative on failure.
94
- */
95
-int kbase_csf_event_wait_add(struct kbase_context *kctx,
96
- kbase_csf_event_callback *callback, void *param);
97
-
98
-/**
99
- * kbase_csf_event_wait_remove - Remove a CSF event callback
100
- *
101
- * This function removes an event callback from the list of CSF event callbacks
102
- * belonging to a given Kbase context.
103
- *
104
- * @kctx: The kbase context the @callback should be removed from.
105
- * @callback: The callback function to remove.
106
- * @param: Custom parameter that would have been passed to the @p callback
107
- * function.
108
- */
109
-void kbase_csf_event_wait_remove(struct kbase_context *kctx,
110
- kbase_csf_event_callback *callback, void *param);
111
-
112
-/**
113
- * kbase_csf_event_wait_remove_all - Removes all CSF event callbacks
114
- *
115
- * This function empties the list of CSF event callbacks belonging to a given
116
- * Kbase context.
117
- *
118
- * @kctx: The kbase context for which CSF event callbacks have to be removed.
119
- */
120
-void kbase_csf_event_wait_remove_all(struct kbase_context *kctx);
121
-
122
-/**
123
- * kbase_csf_read_error - Read CS fatal error
124
- *
125
- * This function takes the CS fatal error from context's ordered
126
- * error_list, copies its contents to @event_data.
127
- *
128
- * @kctx: The kbase context to read fatal error from
129
- * @event_data: Caller-provided buffer to copy the fatal error to
130
- *
131
- * Return: true if fatal error is read successfully.
132
- */
133
-bool kbase_csf_read_error(struct kbase_context *kctx,
134
- struct base_csf_notification *event_data);
135
-
136
-/**
137
- * kbase_csf_error_pending - Check whether fatal error is pending
138
- *
139
- * @kctx: The kbase context to check fatal error upon.
140
- *
141
- * Return: true if fatal error is pending.
142
- */
143
-bool kbase_csf_error_pending(struct kbase_context *kctx);
144
-
145
-/**
146
- * kbase_csf_event_signal - Signal a CSF event
147
- *
148
- * This function triggers all the CSF event callbacks that are registered to
149
- * a given Kbase context, and also signals the event handling thread of
150
- * userspace driver waiting for the CSF event.
151
- *
152
- * @kctx: The kbase context whose CSF event callbacks shall be triggered.
153
- * @notify_gpu: Flag to indicate if CSF firmware should be notified of the
154
- * signaling of event that happened on the Driver side, either
155
- * the signal came from userspace or from kcpu queues.
156
- */
157
-void kbase_csf_event_signal(struct kbase_context *kctx, bool notify_gpu);
158
-
159
-static inline void kbase_csf_event_signal_notify_gpu(struct kbase_context *kctx)
160
-{
161
- kbase_csf_event_signal(kctx, true);
162
-}
163
-
164
-static inline void kbase_csf_event_signal_cpu_only(struct kbase_context *kctx)
165
-{
166
- kbase_csf_event_signal(kctx, false);
167
-}
53
+/* Idle hysteresis time can be scaled down when GPU sleep feature is used */
54
+#define FIRMWARE_IDLE_HYSTERESIS_GPU_SLEEP_SCALER (5)
16855
16956 /**
17057 * kbase_csf_ctx_init - Initialize the CSF interface for a GPU address space.
....@@ -179,11 +66,11 @@
17966 * kbase_csf_ctx_handle_fault - Terminate queue groups & notify fault upon
18067 * GPU bus fault, MMU page fault or similar.
18168 *
182
- * This function terminates all GPU command queue groups in the context and
183
- * notifies the event notification thread of the fault.
184
- *
18569 * @kctx: Pointer to faulty kbase context.
18670 * @fault: Pointer to the fault.
71
+ *
72
+ * This function terminates all GPU command queue groups in the context and
73
+ * notifies the event notification thread of the fault.
18774 */
18875 void kbase_csf_ctx_handle_fault(struct kbase_context *kctx,
18976 struct kbase_fault *fault);
....@@ -191,10 +78,10 @@
19178 /**
19279 * kbase_csf_ctx_term - Terminate the CSF interface for a GPU address space.
19380 *
81
+ * @kctx: Pointer to the kbase context which is being terminated.
82
+ *
19483 * This function terminates any remaining CSGs and CSs which weren't destroyed
19584 * before context termination.
196
- *
197
- * @kctx: Pointer to the kbase context which is being terminated.
19885 */
19986 void kbase_csf_ctx_term(struct kbase_context *kctx);
20087
....@@ -240,16 +127,35 @@
240127 struct kbase_ioctl_cs_queue_terminate *term);
241128
242129 /**
130
+ * kbase_csf_free_command_stream_user_pages() - Free the resources allocated
131
+ * for a queue at the time of bind.
132
+ *
133
+ * @kctx: Address of the kbase context within which the queue was created.
134
+ * @queue: Pointer to the queue to be unlinked.
135
+ *
136
+ * This function will free the pair of physical pages allocated for a GPU
137
+ * command queue, and also release the hardware doorbell page, that were mapped
138
+ * into the process address space to enable direct submission of commands to
139
+ * the hardware. Also releases the reference taken on the queue when the mapping
140
+ * was created.
141
+ *
142
+ * If an explicit or implicit unbind was missed by the userspace then the
143
+ * mapping will persist. On process exit kernel itself will remove the mapping.
144
+ */
145
+void kbase_csf_free_command_stream_user_pages(struct kbase_context *kctx,
146
+ struct kbase_queue *queue);
147
+
148
+/**
243149 * kbase_csf_alloc_command_stream_user_pages - Allocate resources for a
244150 * GPU command queue.
245
- *
246
- * This function allocates a pair of User mode input/output pages for a
247
- * GPU command queue and maps them in the shared interface segment of MCU
248
- * firmware address space. Also reserves a hardware doorbell page for the queue.
249151 *
250152 * @kctx: Pointer to the kbase context within which the resources
251153 * for the queue are being allocated.
252154 * @queue: Pointer to the queue for which to allocate resources.
155
+ *
156
+ * This function allocates a pair of User mode input/output pages for a
157
+ * GPU command queue and maps them in the shared interface segment of MCU
158
+ * firmware address space. Also reserves a hardware doorbell page for the queue.
253159 *
254160 * Return: 0 on success, or negative on failure.
255161 */
....@@ -275,8 +181,9 @@
275181 * are any.
276182 *
277183 * @queue: Pointer to queue to be unbound.
184
+ * @process_exit: Flag to indicate if process exit is happening.
278185 */
279
-void kbase_csf_queue_unbind(struct kbase_queue *queue);
186
+void kbase_csf_queue_unbind(struct kbase_queue *queue, bool process_exit);
280187
281188 /**
282189 * kbase_csf_queue_unbind_stopped - Unbind a GPU command queue in the case
....@@ -291,9 +198,9 @@
291198 /**
292199 * kbase_csf_queue_kick - Schedule a GPU command queue on the firmware
293200 *
294
- * @kctx: The kbase context.
295
- * @kick: Pointer to the struct which specifies the queue
296
- * that needs to be scheduled.
201
+ * @kctx: The kbase context.
202
+ * @kick: Pointer to the struct which specifies the queue
203
+ * that needs to be scheduled.
297204 *
298205 * Return: 0 on success, or negative on failure.
299206 */
....@@ -301,14 +208,28 @@
301208 struct kbase_ioctl_cs_queue_kick *kick);
302209
303210 /**
211
+ * kbase_csf_queue_group_handle_is_valid - Find the queue group corresponding
212
+ * to the indicated handle.
213
+ *
214
+ * @kctx: The kbase context under which the queue group exists.
215
+ * @group_handle: Handle for the group which uniquely identifies it within
216
+ * the context with which it was created.
217
+ *
218
+ * This function is used to find the queue group when passed a handle.
219
+ *
220
+ * Return: Pointer to a queue group on success, NULL on failure
221
+ */
222
+struct kbase_queue_group *kbase_csf_find_queue_group(struct kbase_context *kctx, u8 group_handle);
223
+
224
+/**
304225 * kbase_csf_queue_group_handle_is_valid - Find if the given queue group handle
305226 * is valid.
306
- *
307
- * This function is used to determine if the queue group handle is valid.
308227 *
309228 * @kctx: The kbase context under which the queue group exists.
310229 * @group_handle: Handle for the group which uniquely identifies it within
311230 * the context with which it was created.
231
+ *
232
+ * This function is used to determine if the queue group handle is valid.
312233 *
313234 * Return: 0 on success, or negative on failure.
314235 */
....@@ -353,10 +274,9 @@
353274 */
354275 void kbase_csf_term_descheduled_queue_group(struct kbase_queue_group *group);
355276
277
+#if IS_ENABLED(CONFIG_MALI_VECTOR_DUMP) || MALI_UNIT_TEST
356278 /**
357279 * kbase_csf_queue_group_suspend - Suspend a GPU command queue group
358
- *
359
- * This function is used to suspend a queue group and copy the suspend buffer.
360280 *
361281 * @kctx: The kbase context for which the queue group is to be
362282 * suspended.
....@@ -365,11 +285,14 @@
365285 * @group_handle: Handle for the group which uniquely identifies it within
366286 * the context within which it was created.
367287 *
288
+ * This function is used to suspend a queue group and copy the suspend buffer.
289
+ *
368290 * Return: 0 on success or negative value if failed to suspend
369291 * queue group and copy suspend buffer contents.
370292 */
371293 int kbase_csf_queue_group_suspend(struct kbase_context *kctx,
372294 struct kbase_suspend_copy_buffer *sus_buf, u8 group_handle);
295
+#endif
373296
374297 /**
375298 * kbase_csf_add_group_fatal_error - Report a fatal group error to userspace
....@@ -394,11 +317,11 @@
394317 * the update of userspace mapping of HW
395318 * doorbell page.
396319 *
320
+ * @kbdev: Instance of a GPU platform device that implements a CSF interface.
321
+ *
397322 * The function creates a file and allocates a dummy page to facilitate the
398323 * update of userspace mapping to point to the dummy page instead of the real
399324 * HW doorbell page after the suspend of queue group.
400
- *
401
- * @kbdev: Instance of a GPU platform device that implements a CSF interface.
402325 *
403326 * Return: 0 on success, or negative on failure.
404327 */
....@@ -417,13 +340,13 @@
417340 * instead of the User register page after
418341 * the GPU power down.
419342 *
343
+ * @kbdev: Instance of a GPU platform device that implements a CSF interface.
344
+ *
420345 * The function allocates a dummy page which is used to replace the User
421346 * register page in the userspace mapping after the power down of GPU.
422347 * On the power up of GPU, the mapping is updated to point to the real
423348 * User register page. The mapping is used to allow access to LATEST_FLUSH
424349 * register from userspace.
425
- *
426
- * @kbdev: Instance of a GPU platform device that implements a CSF interface.
427350 *
428351 * Return: 0 on success, or negative on failure.
429352 */
....@@ -431,7 +354,7 @@
431354
432355 /**
433356 * kbase_csf_free_dummy_user_reg_page - Free the dummy page that was used
434
- * used to replace the User register page
357
+ * to replace the User register page
435358 *
436359 * @kbdev: Instance of a GPU platform device that implements a CSF interface.
437360 */
....@@ -440,10 +363,10 @@
440363 /**
441364 * kbase_csf_ring_csg_doorbell - ring the doorbell for a CSG interface.
442365 *
443
- * The function kicks a notification on the CSG interface to firmware.
444
- *
445366 * @kbdev: Instance of a GPU platform device that implements a CSF interface.
446367 * @slot: Index of CSG interface for ringing the door-bell.
368
+ *
369
+ * The function kicks a notification on the CSG interface to firmware.
447370 */
448371 void kbase_csf_ring_csg_doorbell(struct kbase_device *kbdev, int slot);
449372
....@@ -451,10 +374,10 @@
451374 * kbase_csf_ring_csg_slots_doorbell - ring the doorbell for a set of CSG
452375 * interfaces.
453376 *
454
- * The function kicks a notification on a set of CSG interfaces to firmware.
455
- *
456377 * @kbdev: Instance of a GPU platform device that implements a CSF interface.
457378 * @slot_bitmap: bitmap for the given slots, slot-0 on bit-0, etc.
379
+ *
380
+ * The function kicks a notification on a set of CSG interfaces to firmware.
458381 */
459382 void kbase_csf_ring_csg_slots_doorbell(struct kbase_device *kbdev,
460383 u32 slot_bitmap);
....@@ -462,9 +385,6 @@
462385 /**
463386 * kbase_csf_ring_cs_kernel_doorbell - ring the kernel doorbell for a CSI
464387 * assigned to a GPU queue
465
- *
466
- * The function sends a doorbell interrupt notification to the firmware for
467
- * a CSI assigned to a GPU queue.
468388 *
469389 * @kbdev: Instance of a GPU platform device that implements a CSF interface.
470390 * @csi_index: ID of the CSI assigned to the GPU queue.
....@@ -476,6 +396,9 @@
476396 * The flag is supposed be false only when the input page
477397 * for bound GPU queues is programmed at the time of
478398 * starting/resuming the group on a CSG slot.
399
+ *
400
+ * The function sends a doorbell interrupt notification to the firmware for
401
+ * a CSI assigned to a GPU queue.
479402 */
480403 void kbase_csf_ring_cs_kernel_doorbell(struct kbase_device *kbdev,
481404 int csi_index, int csg_nr,
....@@ -485,11 +408,11 @@
485408 * kbase_csf_ring_cs_user_doorbell - ring the user doorbell allocated for a
486409 * queue.
487410 *
488
- * The function kicks a notification to the firmware on the doorbell assigned
489
- * to the queue.
490
- *
491411 * @kbdev: Instance of a GPU platform device that implements a CSF interface.
492412 * @queue: Pointer to the queue for ringing the door-bell.
413
+ *
414
+ * The function kicks a notification to the firmware on the doorbell assigned
415
+ * to the queue.
493416 */
494417 void kbase_csf_ring_cs_user_doorbell(struct kbase_device *kbdev,
495418 struct kbase_queue *queue);
....@@ -560,5 +483,24 @@
560483 return kbasep_csf_queue_group_priority_to_relative[priority];
561484 }
562485
486
+/**
487
+ * kbase_csf_ktrace_gpu_cycle_cnt - Wrapper to retreive the GPU cycle counter
488
+ * value for Ktrace purpose.
489
+ *
490
+ * @kbdev: Instance of a GPU platform device that implements a CSF interface.
491
+ *
492
+ * This function is just a wrapper to retreive the GPU cycle counter value, to
493
+ * avoid any overhead on Release builds where Ktrace is disabled by default.
494
+ *
495
+ * Return: Snapshot of the GPU cycle count register.
496
+ */
497
+static inline u64 kbase_csf_ktrace_gpu_cycle_cnt(struct kbase_device *kbdev)
498
+{
499
+#if KBASE_KTRACE_ENABLE
500
+ return kbase_backend_get_cycle_cnt(kbdev);
501
+#else
502
+ return 0;
503
+#endif
504
+}
563505
564506 #endif /* _KBASE_CSF_H_ */