hc
2023-12-06 08f87f769b595151be1afeff53e144f543faa614
kernel/drivers/gpu/arm/bifrost/mali_kbase.h
....@@ -1,7 +1,7 @@
11 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
22 /*
33 *
4
- * (C) COPYRIGHT 2010-2021 ARM Limited. All rights reserved.
4
+ * (C) COPYRIGHT 2010-2022 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
....@@ -70,7 +70,9 @@
7070 #include "mali_kbase_jd_debugfs.h"
7171 #include "mali_kbase_jm.h"
7272 #include "mali_kbase_js.h"
73
-#endif /* !MALI_USE_CSF */
73
+#else /* !MALI_USE_CSF */
74
+#include "csf/mali_kbase_debug_csf_fault.h"
75
+#endif /* MALI_USE_CSF */
7476
7577 #include "ipa/mali_kbase_ipa.h"
7678
....@@ -82,14 +84,7 @@
8284
8385 #if MALI_USE_CSF
8486 #include "csf/mali_kbase_csf.h"
85
-#endif
8687
87
-#ifndef u64_to_user_ptr
88
-/* Introduced in Linux v4.6 */
89
-#define u64_to_user_ptr(x) ((void __user *)(uintptr_t)x)
90
-#endif
91
-
92
-#if MALI_USE_CSF
9388 /* Physical memory group ID for CSF user I/O.
9489 */
9590 #define KBASE_MEM_GROUP_CSF_IO BASE_MEM_GROUP_DEFAULT
....@@ -109,12 +104,19 @@
109104
110105 struct kbase_device *kbase_device_alloc(void);
111106 /*
112
-* note: configuration attributes member of kbdev needs to have
113
-* been setup before calling kbase_device_init
114
-*/
107
+ * note: configuration attributes member of kbdev needs to have
108
+ * been setup before calling kbase_device_init
109
+ */
115110
116111 int kbase_device_misc_init(struct kbase_device *kbdev);
117112 void kbase_device_misc_term(struct kbase_device *kbdev);
113
+
114
+#if !MALI_USE_CSF
115
+void kbase_enable_quick_reset(struct kbase_device *kbdev);
116
+void kbase_disable_quick_reset(struct kbase_device *kbdev);
117
+bool kbase_is_quick_reset_enabled(struct kbase_device *kbdev);
118
+#endif
119
+
118120 void kbase_device_free(struct kbase_device *kbdev);
119121 int kbase_device_has_feature(struct kbase_device *kbdev, u32 feature);
120122
....@@ -256,8 +258,26 @@
256258 kbasep_js_atom_done_code done_code);
257259 void kbase_jd_cancel(struct kbase_device *kbdev, struct kbase_jd_atom *katom);
258260 void kbase_jd_zap_context(struct kbase_context *kctx);
259
-bool jd_done_nolock(struct kbase_jd_atom *katom,
260
- struct list_head *completed_jobs_ctx);
261
+
262
+/*
263
+ * kbase_jd_done_nolock - Perform the necessary handling of an atom that has completed
264
+ * the execution.
265
+ *
266
+ * @katom: Pointer to the atom that completed the execution
267
+ * @post_immediately: Flag indicating that completion event can be posted
268
+ * immediately for @katom and the other atoms depdendent
269
+ * on @katom which also completed execution. The flag is
270
+ * false only for the case where the function is called by
271
+ * kbase_jd_done_worker() on the completion of atom running
272
+ * on the GPU.
273
+ *
274
+ * Note that if this is a soft-job that has had kbase_prepare_soft_job called on it then the caller
275
+ * is responsible for calling kbase_finish_soft_job *before* calling this function.
276
+ *
277
+ * The caller must hold the kbase_jd_context.lock.
278
+ */
279
+bool kbase_jd_done_nolock(struct kbase_jd_atom *katom, bool post_immediately);
280
+
261281 void kbase_jd_free_external_resources(struct kbase_jd_atom *katom);
262282 void kbase_jd_dep_clear_locked(struct kbase_jd_atom *katom);
263283
....@@ -299,19 +319,60 @@
299319 * virtual address space in a growable memory region and the atom currently
300320 * executing on a job slot is the tiler job chain at the start of a renderpass.
301321 *
302
- * Return 0 if successful, otherwise a negative error code.
322
+ * Return: 0 if successful, otherwise a negative error code.
303323 */
304324 int kbase_job_slot_softstop_start_rp(struct kbase_context *kctx,
305325 struct kbase_va_region *reg);
306326
327
+/**
328
+ * kbase_job_slot_softstop - Soft-stop the specified job slot
329
+ *
330
+ * @kbdev: The kbase device
331
+ * @js: The job slot to soft-stop
332
+ * @target_katom: The job that should be soft-stopped (or NULL for any job)
333
+ * Context:
334
+ * The job slot lock must be held when calling this function.
335
+ * The job slot must not already be in the process of being soft-stopped.
336
+ *
337
+ * Where possible any job in the next register is evicted before the soft-stop.
338
+ */
307339 void kbase_job_slot_softstop(struct kbase_device *kbdev, int js,
308340 struct kbase_jd_atom *target_katom);
309
-void kbase_job_slot_softstop_swflags(struct kbase_device *kbdev, int js,
310
- struct kbase_jd_atom *target_katom, u32 sw_flags);
311
-void kbase_job_slot_hardstop(struct kbase_context *kctx, int js,
312
- struct kbase_jd_atom *target_katom);
341
+
342
+void kbase_job_slot_softstop_swflags(struct kbase_device *kbdev, unsigned int js,
343
+ struct kbase_jd_atom *target_katom, u32 sw_flags);
344
+
345
+/**
346
+ * kbase_job_check_enter_disjoint - potentiall enter disjoint mode
347
+ * @kbdev: kbase device
348
+ * @action: the event which has occurred
349
+ * @core_reqs: core requirements of the atom
350
+ * @target_katom: the atom which is being affected
351
+ *
352
+ * For a certain soft-stop action, work out whether to enter disjoint
353
+ * state.
354
+ *
355
+ * This does not register multiple disjoint events if the atom has already
356
+ * started a disjoint period
357
+ *
358
+ * @core_reqs can be supplied as 0 if the atom had not started on the hardware
359
+ * (and so a 'real' soft/hard-stop was not required, but it still interrupted
360
+ * flow, perhaps on another context)
361
+ *
362
+ * kbase_job_check_leave_disjoint() should be used to end the disjoint
363
+ * state when the soft/hard-stop action is complete
364
+ */
313365 void kbase_job_check_enter_disjoint(struct kbase_device *kbdev, u32 action,
314366 base_jd_core_req core_reqs, struct kbase_jd_atom *target_katom);
367
+
368
+/**
369
+ * kbase_job_check_leave_disjoint - potentially leave disjoint state
370
+ * @kbdev: kbase device
371
+ * @target_katom: atom which is finishing
372
+ *
373
+ * Work out whether to leave disjoint state when finishing an atom that was
374
+ * originated by kbase_job_check_enter_disjoint().
375
+ */
315376 void kbase_job_check_leave_disjoint(struct kbase_device *kbdev,
316377 struct kbase_jd_atom *target_katom);
317378
....@@ -334,7 +395,7 @@
334395 * allocation is to be validated.
335396 * @info: Pointer to struct @base_jit_alloc_info
336397 * which is to be validated.
337
- * @return: 0 if jit allocation is valid; negative error code otherwise
398
+ * Return: 0 if jit allocation is valid; negative error code otherwise
338399 */
339400 int kbasep_jit_alloc_validate(struct kbase_context *kctx,
340401 struct base_jit_alloc_info *info);
....@@ -374,16 +435,6 @@
374435 }
375436 }
376437
377
-/**
378
- * kbase_mem_copy_from_extres() - Copy from external resources.
379
- *
380
- * @kctx: kbase context within which the copying is to take place.
381
- * @buf_data: Pointer to the information about external resources:
382
- * pages pertaining to the external resource, number of
383
- * pages to copy.
384
- */
385
-int kbase_mem_copy_from_extres(struct kbase_context *kctx,
386
- struct kbase_debug_copy_buffer *buf_data);
387438 #if !MALI_USE_CSF
388439 int kbase_process_soft_job(struct kbase_jd_atom *katom);
389440 int kbase_prepare_soft_job(struct kbase_jd_atom *katom);
....@@ -391,7 +442,7 @@
391442 void kbase_cancel_soft_job(struct kbase_jd_atom *katom);
392443 void kbase_resume_suspended_soft_jobs(struct kbase_device *kbdev);
393444 void kbasep_remove_waiting_soft_job(struct kbase_jd_atom *katom);
394
-#if defined(CONFIG_SYNC) || defined(CONFIG_SYNC_FILE)
445
+#if IS_ENABLED(CONFIG_SYNC_FILE)
395446 void kbase_soft_event_wait_callback(struct kbase_jd_atom *katom);
396447 #endif
397448 int kbase_soft_event_update(struct kbase_context *kctx,
....@@ -405,7 +456,9 @@
405456 void kbasep_as_do_poke(struct work_struct *work);
406457
407458 /**
408
- * Check whether a system suspend is in progress, or has already been suspended
459
+ * kbase_pm_is_suspending - Check whether a system suspend is in progress,
460
+ * or has already been suspended
461
+ *
409462 * @kbdev: The kbase device structure for the device
410463 *
411464 * The caller should ensure that either kbdev->pm.active_count_lock is held, or
....@@ -474,6 +527,21 @@
474527 }
475528
476529 /**
530
+ * kbase_pm_lowest_gpu_freq_init() - Find the lowest frequency that the GPU can
531
+ * run as using the device tree, and save this
532
+ * within kbdev.
533
+ * @kbdev: Pointer to kbase device.
534
+ *
535
+ * This function could be called from kbase_clk_rate_trace_manager_init,
536
+ * but is left separate as it can be called as soon as
537
+ * dev_pm_opp_of_add_table() has been called to initialize the OPP table,
538
+ * which occurs in power_control_init().
539
+ *
540
+ * Return: 0 in any case.
541
+ */
542
+int kbase_pm_lowest_gpu_freq_init(struct kbase_device *kbdev);
543
+
544
+/**
477545 * kbase_pm_metrics_start - Start the utilization metrics timer
478546 * @kbdev: Pointer to the kbase device for which to start the utilization
479547 * metrics calculation thread.
....@@ -491,14 +559,57 @@
491559 */
492560 void kbase_pm_metrics_stop(struct kbase_device *kbdev);
493561
562
+#if MALI_USE_CSF && defined(KBASE_PM_RUNTIME)
563
+/**
564
+ * kbase_pm_handle_runtime_suspend - Handle the runtime suspend of GPU
565
+ *
566
+ * @kbdev: The kbase device structure for the device (must be a valid pointer)
567
+ *
568
+ * This function is called from the runtime suspend callback function for
569
+ * saving the HW state and powering down GPU, if GPU was in sleep state mode.
570
+ * It does the following steps
571
+ * - Powers up the L2 cache and re-activates the MCU.
572
+ * - Suspend the CSGs
573
+ * - Halts the MCU
574
+ * - Powers down the L2 cache.
575
+ * - Invokes the power_off callback to power down the GPU.
576
+ *
577
+ * Return: 0 if the GPU was already powered down or no error was encountered
578
+ * in the power down, otherwise an error code.
579
+ */
580
+int kbase_pm_handle_runtime_suspend(struct kbase_device *kbdev);
581
+
582
+/**
583
+ * kbase_pm_force_mcu_wakeup_after_sleep - Force the wake up of MCU from sleep
584
+ *
585
+ * @kbdev: The kbase device structure for the device (must be a valid pointer)
586
+ *
587
+ * This function forces the wake up of MCU from sleep state and wait for
588
+ * MCU to become active.
589
+ * It usually gets called from the runtime suspend callback function.
590
+ * It also gets called from the GPU reset handler or at the time of system
591
+ * suspend or when User tries to terminate/suspend the on-slot group.
592
+ *
593
+ * Note: @gpu_wakeup_override flag that forces the reactivation of MCU is
594
+ * set by this function and it is the caller's responsibility to
595
+ * clear the flag.
596
+ *
597
+ * Return: 0 if the wake up was successful.
598
+ */
599
+int kbase_pm_force_mcu_wakeup_after_sleep(struct kbase_device *kbdev);
600
+#endif
601
+
494602 #if !MALI_USE_CSF
495603 /**
496
- * Return the atom's ID, as was originally supplied by userspace in
604
+ * kbase_jd_atom_id - Return the atom's ID, as was originally supplied by userspace in
497605 * base_jd_atom::atom_number
498606 * @kctx: KBase context pointer
499607 * @katom: Atome for which to return ID
608
+ *
609
+ * Return: the atom's ID.
500610 */
501
-static inline int kbase_jd_atom_id(struct kbase_context *kctx, struct kbase_jd_atom *katom)
611
+static inline int kbase_jd_atom_id(struct kbase_context *kctx,
612
+ const struct kbase_jd_atom *katom)
502613 {
503614 int result;
504615
....@@ -526,7 +637,9 @@
526637 #endif /* !MALI_USE_CSF */
527638
528639 /**
529
- * Initialize the disjoint state
640
+ * kbase_disjoint_init - Initialize the disjoint state
641
+ *
642
+ * @kbdev: The kbase device
530643 *
531644 * The disjoint event count and state are both set to zero.
532645 *
....@@ -548,14 +661,12 @@
548661 * The disjoint event counter is also incremented immediately whenever a job is soft stopped
549662 * and during context creation.
550663 *
551
- * @kbdev: The kbase device
552
- *
553664 * Return: 0 on success and non-zero value on failure.
554665 */
555666 void kbase_disjoint_init(struct kbase_device *kbdev);
556667
557668 /**
558
- * Increase the count of disjoint events
669
+ * kbase_disjoint_event - Increase the count of disjoint events
559670 * called when a disjoint event has happened
560671 *
561672 * @kbdev: The kbase device
....@@ -563,42 +674,44 @@
563674 void kbase_disjoint_event(struct kbase_device *kbdev);
564675
565676 /**
566
- * Increase the count of disjoint events only if the GPU is in a disjoint state
677
+ * kbase_disjoint_event_potential - Increase the count of disjoint events
678
+ * only if the GPU is in a disjoint state
679
+ *
680
+ * @kbdev: The kbase device
567681 *
568682 * This should be called when something happens which could be disjoint if the GPU
569683 * is in a disjoint state. The state refcount keeps track of this.
570
- *
571
- * @kbdev: The kbase device
572684 */
573685 void kbase_disjoint_event_potential(struct kbase_device *kbdev);
574686
575687 /**
576
- * Returns the count of disjoint events
688
+ * kbase_disjoint_event_get - Returns the count of disjoint events
577689 *
578690 * @kbdev: The kbase device
579
- * @return the count of disjoint events
691
+ * Return: the count of disjoint events
580692 */
581693 u32 kbase_disjoint_event_get(struct kbase_device *kbdev);
582694
583695 /**
584
- * Increment the refcount state indicating that the GPU is in a disjoint state.
696
+ * kbase_disjoint_state_up - Increment the refcount state indicating that
697
+ * the GPU is in a disjoint state.
698
+ *
699
+ * @kbdev: The kbase device
585700 *
586701 * Also Increment the disjoint event count (calls @ref kbase_disjoint_event)
587702 * eventually after the disjoint state has completed @ref kbase_disjoint_state_down
588703 * should be called
589
- *
590
- * @kbdev: The kbase device
591704 */
592705 void kbase_disjoint_state_up(struct kbase_device *kbdev);
593706
594707 /**
595
- * Decrement the refcount state
708
+ * kbase_disjoint_state_down - Decrement the refcount state
709
+ *
710
+ * @kbdev: The kbase device
596711 *
597712 * Also Increment the disjoint event count (calls @ref kbase_disjoint_event)
598713 *
599714 * Called after @ref kbase_disjoint_state_up once the disjoint state is over
600
- *
601
- * @kbdev: The kbase device
602715 */
603716 void kbase_disjoint_state_down(struct kbase_device *kbdev);
604717
....@@ -627,8 +740,8 @@
627740 void kbase_device_pcm_dev_term(struct kbase_device *const kbdev);
628741
629742 /**
630
- * If a job is soft stopped and the number of contexts is >= this value
631
- * it is reported as a disjoint event
743
+ * KBASE_DISJOINT_STATE_INTERLEAVED_CONTEXT_COUNT_THRESHOLD - If a job is soft stopped
744
+ * and the number of contexts is >= this value it is reported as a disjoint event
632745 */
633746 #define KBASE_DISJOINT_STATE_INTERLEAVED_CONTEXT_COUNT_THRESHOLD 2
634747