forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/drivers/gpu/arm/bifrost/jm/mali_kbase_jm_defs.h
....@@ -1,7 +1,7 @@
11 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
22 /*
33 *
4
- * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved.
4
+ * (C) COPYRIGHT 2019-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
....@@ -87,8 +87,6 @@
8787 #define KBASE_KATOM_FLAG_FAIL_BLOCKER (1<<8)
8888 /* Atom is currently in the list of atoms blocked on cross-slot dependencies */
8989 #define KBASE_KATOM_FLAG_JSCTX_IN_X_DEP_LIST (1<<9)
90
-/* Atom is currently holding a context reference */
91
-#define KBASE_KATOM_FLAG_HOLDING_CTX_REF (1<<10)
9290 /* Atom requires GPU to be in protected mode */
9391 #define KBASE_KATOM_FLAG_PROTECTED (1<<11)
9492 /* Atom has been stored in runnable_tree */
....@@ -125,6 +123,25 @@
125123 #define KBASE_SERIALIZE_INTER_SLOT (1 << 1)
126124 /* Reset the GPU after each atom completion */
127125 #define KBASE_SERIALIZE_RESET (1 << 2)
126
+
127
+/**
128
+ * enum kbase_timeout_selector - The choice of which timeout to get scaled
129
+ * using the lowest GPU frequency.
130
+ * @MMU_AS_INACTIVE_WAIT_TIMEOUT: Maximum waiting time in ms for the completion
131
+ * of a MMU operation
132
+ * @JM_DEFAULT_JS_FREE_TIMEOUT: Maximum timeout to wait for JS_COMMAND_NEXT
133
+ * to be updated on HW side so a Job Slot is
134
+ * considered free.
135
+ * @KBASE_TIMEOUT_SELECTOR_COUNT: Number of timeout selectors. Must be last in
136
+ * the enum.
137
+ */
138
+enum kbase_timeout_selector {
139
+ MMU_AS_INACTIVE_WAIT_TIMEOUT,
140
+ JM_DEFAULT_JS_FREE_TIMEOUT,
141
+
142
+ /* Must be the last in the enum */
143
+ KBASE_TIMEOUT_SELECTOR_COUNT
144
+};
128145
129146 #if IS_ENABLED(CONFIG_DEBUG_FS)
130147 /**
....@@ -176,8 +193,6 @@
176193 static inline const struct kbase_jd_atom *
177194 kbase_jd_katom_dep_atom(const struct kbase_jd_atom_dependency *dep)
178195 {
179
- LOCAL_ASSERT(dep != NULL);
180
-
181196 return (const struct kbase_jd_atom *)(dep->atom);
182197 }
183198
....@@ -191,8 +206,6 @@
191206 static inline u8 kbase_jd_katom_dep_type(
192207 const struct kbase_jd_atom_dependency *dep)
193208 {
194
- LOCAL_ASSERT(dep != NULL);
195
-
196209 return dep->dep_type;
197210 }
198211
....@@ -209,8 +222,6 @@
209222 {
210223 struct kbase_jd_atom_dependency *dep;
211224
212
- LOCAL_ASSERT(const_dep != NULL);
213
-
214225 dep = (struct kbase_jd_atom_dependency *)const_dep;
215226
216227 dep->atom = a;
....@@ -226,8 +237,6 @@
226237 const struct kbase_jd_atom_dependency *const_dep)
227238 {
228239 struct kbase_jd_atom_dependency *dep;
229
-
230
- LOCAL_ASSERT(const_dep != NULL);
231240
232241 dep = (struct kbase_jd_atom_dependency *)const_dep;
233242
....@@ -343,19 +352,6 @@
343352 };
344353
345354 /**
346
- * struct kbase_ext_res - Contains the info for external resources referred
347
- * by an atom, which have been mapped on GPU side.
348
- * @gpu_address: Start address of the memory region allocated for
349
- * the resource from GPU virtual address space.
350
- * @alloc: pointer to physical pages tracking object, set on
351
- * mapping the external resource on GPU side.
352
- */
353
-struct kbase_ext_res {
354
- u64 gpu_address;
355
- struct kbase_mem_phy_alloc *alloc;
356
-};
357
-
358
-/**
359355 * struct kbase_jd_atom - object representing the atom, containing the complete
360356 * state and attributes of an atom.
361357 * @work: work item for the bottom half processing of the atom,
....@@ -388,7 +384,8 @@
388384 * each allocation is read in order to enforce an
389385 * overall physical memory usage limit.
390386 * @nr_extres: number of external resources referenced by the atom.
391
- * @extres: pointer to the location containing info about
387
+ * @extres: Pointer to @nr_extres VA regions containing the external
388
+ * resource allocation and other information.
392389 * @nr_extres external resources referenced by the atom.
393390 * @device_nr: indicates the coregroup with which the atom is
394391 * associated, when
....@@ -406,16 +403,21 @@
406403 * sync through soft jobs and for the implicit
407404 * synchronization required on access to external
408405 * resources.
409
- * @dma_fence.fence_in: Input fence
406
+ * @dma_fence.fence_in: Points to the dma-buf input fence for this atom.
407
+ * The atom would complete only after the fence is
408
+ * signaled.
410409 * @dma_fence.fence: Points to the dma-buf output fence for this atom.
410
+ * @dma_fence.fence_cb: The object that is passed at the time of adding the
411
+ * callback that gets invoked when @dma_fence.fence_in
412
+ * is signaled.
413
+ * @dma_fence.fence_cb_added: Flag to keep a track if the callback was successfully
414
+ * added for @dma_fence.fence_in, which is supposed to be
415
+ * invoked on the signaling of fence.
411416 * @dma_fence.context: The dma-buf fence context number for this atom. A
412417 * unique context number is allocated to each katom in
413418 * the context on context creation.
414419 * @dma_fence.seqno: The dma-buf fence sequence number for this atom. This
415420 * is increased every time this katom uses dma-buf fence
416
- * @dma_fence.callbacks: List of all callbacks set up to wait on other fences
417
- * @dma_fence.dep_count: Atomic counter of number of outstandind dma-buf fence
418
- * dependencies for this atom.
419421 * @event_code: Event code for the job chain represented by the atom,
420422 * both HW and low-level SW events are represented by
421423 * event codes.
....@@ -498,7 +500,6 @@
498500 * BASE_JD_REQ_START_RENDERPASS set in its core requirements
499501 * with an atom that has BASE_JD_REQ_END_RENDERPASS set.
500502 * @jc_fragment: Set of GPU fragment job chains
501
- * @retry_count: TODO: Not used,to be removed
502503 */
503504 struct kbase_jd_atom {
504505 struct work_struct work;
....@@ -518,21 +519,17 @@
518519 #endif /* MALI_JIT_PRESSURE_LIMIT_BASE */
519520
520521 u16 nr_extres;
521
- struct kbase_ext_res *extres;
522
+ struct kbase_va_region **extres;
522523
523524 u32 device_nr;
524525 u64 jc;
525526 void *softjob_data;
526
-#if defined(CONFIG_SYNC)
527
- struct sync_fence *fence;
528
- struct sync_fence_waiter sync_waiter;
529
-#endif /* CONFIG_SYNC */
530
-#if defined(CONFIG_MALI_BIFROST_DMA_FENCE) || defined(CONFIG_SYNC_FILE)
527
+#if IS_ENABLED(CONFIG_SYNC_FILE)
531528 struct {
532529 /* Use the functions/API defined in mali_kbase_fence.h to
533530 * when working with this sub struct
534531 */
535
-#if defined(CONFIG_SYNC_FILE)
532
+#if IS_ENABLED(CONFIG_SYNC_FILE)
536533 #if (KERNEL_VERSION(4, 10, 0) > LINUX_VERSION_CODE)
537534 struct fence *fence_in;
538535 #else
....@@ -555,38 +552,21 @@
555552 #else
556553 struct dma_fence *fence;
557554 #endif
555
+
556
+ /* This is the callback object that is registered for the fence_in.
557
+ * The callback is invoked when the fence_in is signaled.
558
+ */
559
+#if (KERNEL_VERSION(4, 10, 0) > LINUX_VERSION_CODE)
560
+ struct fence_cb fence_cb;
561
+#else
562
+ struct dma_fence_cb fence_cb;
563
+#endif
564
+ bool fence_cb_added;
565
+
558566 unsigned int context;
559567 atomic_t seqno;
560
- /* This contains a list of all callbacks set up to wait on
561
- * other fences. This atom must be held back from JS until all
562
- * these callbacks have been called and dep_count have reached
563
- * 0. The initial value of dep_count must be equal to the
564
- * number of callbacks on this list.
565
- *
566
- * This list is protected by jctx.lock. Callbacks are added to
567
- * this list when the atom is built and the wait are set up.
568
- * All the callbacks then stay on the list until all callbacks
569
- * have been called and the atom is queued, or cancelled, and
570
- * then all callbacks are taken off the list and freed.
571
- */
572
- struct list_head callbacks;
573
- /* Atomic counter of number of outstandind dma-buf fence
574
- * dependencies for this atom. When dep_count reaches 0 the
575
- * atom may be queued.
576
- *
577
- * The special value "-1" may only be set after the count
578
- * reaches 0, while holding jctx.lock. This indicates that the
579
- * atom has been handled, either queued in JS or cancelled.
580
- *
581
- * If anyone but the dma-fence worker sets this to -1 they must
582
- * ensure that any potentially queued worker must have
583
- * completed before allowing the atom to be marked as unused.
584
- * This can be done by flushing the fence work queue:
585
- * kctx->dma_fence.wq.
586
- */
587
- atomic_t dep_count;
588568 } dma_fence;
589
-#endif /* CONFIG_MALI_BIFROST_DMA_FENCE || CONFIG_SYNC_FILE */
569
+#endif /* CONFIG_SYNC_FILE */
590570
591571 /* Note: refer to kbasep_js_atom_retained_state, which will take a copy
592572 * of some of the following members
....@@ -605,11 +585,9 @@
605585 #if IS_ENABLED(CONFIG_GPU_TRACEPOINTS)
606586 int work_id;
607587 #endif
608
- int slot_nr;
588
+ unsigned int slot_nr;
609589
610590 u32 atom_flags;
611
-
612
- int retry_count;
613591
614592 enum kbase_atom_gpu_rb_state gpu_rb_state;
615593
....@@ -653,6 +631,51 @@
653631 return (bool)(katom->atom_flags & KBASE_KATOM_FLAG_PROTECTED);
654632 }
655633
634
+/**
635
+ * kbase_jd_atom_is_younger - query if one atom is younger by age than another
636
+ *
637
+ * @katom_a: the first atom
638
+ * @katom_b: the second atom
639
+ *
640
+ * Return: true if the first atom is strictly younger than the second,
641
+ * false otherwise.
642
+ */
643
+static inline bool kbase_jd_atom_is_younger(const struct kbase_jd_atom *katom_a,
644
+ const struct kbase_jd_atom *katom_b)
645
+{
646
+ return ((s32)(katom_a->age - katom_b->age) < 0);
647
+}
648
+
649
+/**
650
+ * kbase_jd_atom_is_earlier - Check whether the first atom has been submitted
651
+ * earlier than the second one
652
+ *
653
+ * @katom_a: the first atom
654
+ * @katom_b: the second atom
655
+ *
656
+ * Return: true if the first atom has been submitted earlier than the
657
+ * second atom. It is used to understand if an atom that is ready has been
658
+ * submitted earlier than the currently running atom, so that the currently
659
+ * running atom should be preempted to allow the ready atom to run.
660
+ */
661
+static inline bool kbase_jd_atom_is_earlier(const struct kbase_jd_atom *katom_a,
662
+ const struct kbase_jd_atom *katom_b)
663
+{
664
+ /* No seq_nr set? */
665
+ if (!katom_a->seq_nr || !katom_b->seq_nr)
666
+ return false;
667
+
668
+ /* Efficiently handle the unlikely case of wrapping.
669
+ * The following code assumes that the delta between the sequence number
670
+ * of the two atoms is less than INT64_MAX.
671
+ * In the extremely unlikely case where the delta is higher, the comparison
672
+ * defaults for no preemption.
673
+ * The code also assumes that the conversion from unsigned to signed types
674
+ * works because the signed integers are 2's complement.
675
+ */
676
+ return (s64)(katom_a->seq_nr - katom_b->seq_nr) < 0;
677
+}
678
+
656679 /*
657680 * Theory of operations:
658681 *
....@@ -690,17 +713,13 @@
690713 * A state machine is used to control incremental rendering.
691714 */
692715 enum kbase_jd_renderpass_state {
693
- KBASE_JD_RP_COMPLETE, /* COMPLETE => START */
694
- KBASE_JD_RP_START, /* START => PEND_OOM or COMPLETE */
695
- KBASE_JD_RP_PEND_OOM, /* PEND_OOM => OOM or COMPLETE */
696
- KBASE_JD_RP_OOM, /* OOM => RETRY */
697
- KBASE_JD_RP_RETRY, /* RETRY => RETRY_PEND_OOM or
698
- * COMPLETE
699
- */
700
- KBASE_JD_RP_RETRY_PEND_OOM, /* RETRY_PEND_OOM => RETRY_OOM or
701
- * COMPLETE
702
- */
703
- KBASE_JD_RP_RETRY_OOM, /* RETRY_OOM => RETRY */
716
+ KBASE_JD_RP_COMPLETE, /* COMPLETE => START */
717
+ KBASE_JD_RP_START, /* START => PEND_OOM or COMPLETE */
718
+ KBASE_JD_RP_PEND_OOM, /* PEND_OOM => OOM or COMPLETE */
719
+ KBASE_JD_RP_OOM, /* OOM => RETRY */
720
+ KBASE_JD_RP_RETRY, /* RETRY => RETRY_PEND_OOM or COMPLETE */
721
+ KBASE_JD_RP_RETRY_PEND_OOM, /* RETRY_PEND_OOM => RETRY_OOM or COMPLETE */
722
+ KBASE_JD_RP_RETRY_OOM /* RETRY_OOM => RETRY */
704723 };
705724
706725 /**
....@@ -773,7 +792,7 @@
773792 * atom completes
774793 * execution on GPU or the input fence get signaled.
775794 * @tb_lock: Lock to serialize the write access made to @tb to
776
- * to store the register access trace messages.
795
+ * store the register access trace messages.
777796 * @tb: Pointer to the Userspace accessible buffer storing
778797 * the trace messages for register read/write
779798 * accesses made by the Kbase. The buffer is filled
....@@ -840,6 +859,10 @@
840859 * @pf_data: Data relating to Page fault.
841860 * @bf_data: Data relating to Bus fault.
842861 * @current_setup: Stores the MMU configuration for this address space.
862
+ * @is_unresponsive: Flag to indicate MMU is not responding.
863
+ * Set if a MMU command isn't completed within
864
+ * &kbase_device:mmu_as_inactive_wait_time_ms.
865
+ * Clear by kbase_ctx_sched_restore_all_as() after GPU reset completes.
843866 */
844867 struct kbase_as {
845868 int number;
....@@ -849,6 +872,7 @@
849872 struct kbase_fault pf_data;
850873 struct kbase_fault bf_data;
851874 struct kbase_mmu_setup current_setup;
875
+ bool is_unresponsive;
852876 };
853877
854878 #endif /* _KBASE_JM_DEFS_H_ */