xref: /OK3568_Linux_fs/kernel/drivers/gpu/arm/mali400/mali/common/mali_scheduler.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Copyright (C) 2012-2017 ARM Limited. All rights reserved.
3  *
4  * This program is free software and is provided to you under the terms of the GNU General Public License version 2
5  * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence.
6  *
7  * A copy of the licence is included with the program, and can also be obtained from Free Software
8  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
9  */
10 
11 #ifndef __MALI_SCHEDULER_H__
12 #define __MALI_SCHEDULER_H__
13 
14 #include "mali_osk.h"
15 #include "mali_osk_list.h"
16 #include "mali_scheduler_types.h"
17 #include "mali_session.h"
18 
19 struct mali_scheduler_job_queue {
20 	_MALI_OSK_LIST_HEAD(normal_pri); /* Queued jobs with normal priority */
21 	_MALI_OSK_LIST_HEAD(high_pri);   /* Queued jobs with high priority */
22 	u32 depth;                       /* Depth of combined queues. */
23 	u32 big_job_num;
24 };
25 
26 extern _mali_osk_spinlock_irq_t *mali_scheduler_lock_obj;
27 
28 /* Queue of jobs to be executed on the GP group */
29 extern struct mali_scheduler_job_queue job_queue_gp;
30 
31 /* Queue of PP jobs */
32 extern struct mali_scheduler_job_queue job_queue_pp;
33 
34 extern _mali_osk_atomic_t mali_job_id_autonumber;
35 extern _mali_osk_atomic_t mali_job_cache_order_autonumber;
36 
37 #define MALI_DEBUG_ASSERT_SCHEDULER_LOCK_HELD() MALI_DEBUG_ASSERT_LOCK_HELD(mali_scheduler_lock_obj);
38 
39 _mali_osk_errcode_t mali_scheduler_initialize(void);
40 void mali_scheduler_terminate(void);
41 
mali_scheduler_lock(void)42 MALI_STATIC_INLINE void mali_scheduler_lock(void)
43 {
44 	_mali_osk_spinlock_irq_lock(mali_scheduler_lock_obj);
45 	MALI_DEBUG_PRINT(5, ("Mali scheduler: scheduler lock taken.\n"));
46 }
47 
mali_scheduler_unlock(void)48 MALI_STATIC_INLINE void mali_scheduler_unlock(void)
49 {
50 	MALI_DEBUG_PRINT(5, ("Mali scheduler: Releasing scheduler lock.\n"));
51 	_mali_osk_spinlock_irq_unlock(mali_scheduler_lock_obj);
52 }
53 
mali_scheduler_job_gp_count(void)54 MALI_STATIC_INLINE u32 mali_scheduler_job_gp_count(void)
55 {
56 	return job_queue_gp.depth;
57 }
mali_scheduler_job_gp_big_job_count(void)58 MALI_STATIC_INLINE u32 mali_scheduler_job_gp_big_job_count(void)
59 {
60 	return job_queue_gp.big_job_num;
61 }
62 
63 u32 mali_scheduler_job_physical_head_count(mali_bool gpu_mode_is_secure);
64 
65 mali_bool mali_scheduler_job_next_is_virtual(void);
66 struct mali_pp_job *mali_scheduler_job_pp_next(void);
67 
68 struct mali_gp_job *mali_scheduler_job_gp_get(void);
69 struct mali_pp_job *mali_scheduler_job_pp_physical_peek(void);
70 struct mali_pp_job *mali_scheduler_job_pp_virtual_peek(void);
71 struct mali_pp_job *mali_scheduler_job_pp_physical_get(u32 *sub_job);
72 struct mali_pp_job *mali_scheduler_job_pp_virtual_get(void);
73 
mali_scheduler_get_new_id(void)74 MALI_STATIC_INLINE u32 mali_scheduler_get_new_id(void)
75 {
76 	return _mali_osk_atomic_inc_return(&mali_job_id_autonumber);
77 }
78 
mali_scheduler_get_new_cache_order(void)79 MALI_STATIC_INLINE u32 mali_scheduler_get_new_cache_order(void)
80 {
81 	return _mali_osk_atomic_inc_return(&mali_job_cache_order_autonumber);
82 }
83 
84 /**
85  * @brief Used by the Timeline system to queue a GP job.
86  *
87  * @note @ref mali_executor_schedule_from_mask() should be called if this
88  * function returns non-zero.
89  *
90  * @param job The GP job that is being activated.
91  *
92  * @return A scheduling bitmask that can be used to decide if scheduling is
93  * necessary after this call.
94  */
95 mali_scheduler_mask mali_scheduler_activate_gp_job(struct mali_gp_job *job);
96 
97 /**
98  * @brief Used by the Timeline system to queue a PP job.
99  *
100  * @note @ref mali_executor_schedule_from_mask() should be called if this
101  * function returns non-zero.
102  *
103  * @param job The PP job that is being activated.
104  *
105  * @return A scheduling bitmask that can be used to decide if scheduling is
106  * necessary after this call.
107  */
108 mali_scheduler_mask mali_scheduler_activate_pp_job(struct mali_pp_job *job);
109 
110 void mali_scheduler_complete_gp_job(struct mali_gp_job *job,
111 				    mali_bool success,
112 				    mali_bool user_notification,
113 				    mali_bool dequeued);
114 
115 void mali_scheduler_complete_pp_job(struct mali_pp_job *job,
116 				    u32 num_cores_in_virtual,
117 				    mali_bool user_notification,
118 				    mali_bool dequeued);
119 
120 void mali_scheduler_abort_session(struct mali_session_data *session);
121 
122 void mali_scheduler_return_pp_job_to_user(struct mali_pp_job *job,
123 		u32 num_cores_in_virtual);
124 
125 #if MALI_STATE_TRACKING
126 u32 mali_scheduler_dump_state(char *buf, u32 size);
127 #endif
128 
129 void mali_scheduler_gp_pp_job_queue_print(void);
130 
131 #endif /* __MALI_SCHEDULER_H__ */
132