MALI: utgard: upgrade DDK to r7p0-00rel0
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / arm / mali400 / mali / common / mali_session.h
1 /*
2  * Copyright (C) 2010-2016 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_SESSION_H__
12 #define __MALI_SESSION_H__
13
14 #include "mali_mmu_page_directory.h"
15 #include "mali_osk.h"
16 #include "mali_osk_list.h"
17 #include "mali_memory_types.h"
18 #include "mali_memory_manager.h"
19
20 struct mali_timeline_system;
21 struct mali_soft_system;
22
23 /* Number of frame builder job lists per session. */
24 #define MALI_PP_JOB_FB_LOOKUP_LIST_SIZE 16
25 #define MALI_PP_JOB_FB_LOOKUP_LIST_MASK (MALI_PP_JOB_FB_LOOKUP_LIST_SIZE - 1)
26 /*Max pending big job allowed in kernel*/
27 #define MALI_MAX_PENDING_BIG_JOB (2)
28
29 struct mali_session_data {
30         _mali_osk_notification_queue_t *ioctl_queue;
31
32         _mali_osk_wait_queue_t *wait_queue; /**The wait queue to wait for the number of pp job become 0.*/
33
34         _mali_osk_mutex_t *memory_lock; /**< Lock protecting the vm manipulation */
35         _mali_osk_mutex_t *cow_lock; /** < Lock protecting the cow memory free manipulation */
36 #if 0
37         _mali_osk_list_t memory_head; /**< Track all the memory allocated in this session, for freeing on abnormal termination */
38 #endif
39         struct mali_page_directory *page_directory; /**< MMU page directory for this session */
40
41         _MALI_OSK_LIST_HEAD(link); /**< Link for list of all sessions */
42         _MALI_OSK_LIST_HEAD(pp_job_list); /**< List of all PP jobs on this session */
43
44 #if defined(CONFIG_MALI_DVFS)
45         _mali_osk_atomic_t number_of_window_jobs; /**< Record the window jobs completed on this session in a period */
46 #endif
47         _mali_osk_atomic_t number_of_pp_jobs; /** < Record the pp jobs on this session */
48
49         _mali_osk_list_t pp_job_fb_lookup_list[MALI_PP_JOB_FB_LOOKUP_LIST_SIZE]; /**< List of PP job lists per frame builder id.  Used to link jobs from same frame builder. */
50         struct mali_soft_job_system *soft_job_system; /**< Soft job system for this session. */
51         struct mali_timeline_system *timeline_system; /**< Timeline system for this session. */
52
53         mali_bool is_aborting; /**< MALI_TRUE if the session is aborting, MALI_FALSE if not. */
54         mali_bool use_high_priority_job_queue; /**< If MALI_TRUE, jobs added from this session will use the high priority job queues. */
55         u32 pid;
56         char *comm;
57         atomic_t mali_mem_array[MALI_MEM_TYPE_MAX]; /**< The array to record mem types' usage for this session. */
58         atomic_t mali_mem_allocated_pages; /** The current allocated mali memory pages, which include mali os memory and mali dedicated memory.*/
59         size_t max_mali_mem_allocated_size; /**< The past max mali memory allocated size, which include mali os memory and mali dedicated memory. */
60         /* Added for new memroy system */
61         struct mali_allocation_manager allocation_mgr;
62
63 #if defined(CONFIG_MALI_DMA_BUF_FENCE)
64         u32 fence_context;      /** <  The execution dma fence context this fence is run on. */
65         _mali_osk_atomic_t fence_seqno; /** < Alinear increasing sequence number for this dma fence context. */
66 #endif
67 };
68
69 _mali_osk_errcode_t mali_session_initialize(void);
70 void mali_session_terminate(void);
71
72 /* List of all sessions. Actual list head in mali_kernel_core.c */
73 extern _mali_osk_list_t mali_sessions;
74 /* Lock to protect modification and access to the mali_sessions list */
75 extern _mali_osk_spinlock_irq_t *mali_sessions_lock;
76
77 MALI_STATIC_INLINE void mali_session_lock(void)
78 {
79         _mali_osk_spinlock_irq_lock(mali_sessions_lock);
80 }
81
82 MALI_STATIC_INLINE void mali_session_unlock(void)
83 {
84         _mali_osk_spinlock_irq_unlock(mali_sessions_lock);
85 }
86
87 void mali_session_add(struct mali_session_data *session);
88 void mali_session_remove(struct mali_session_data *session);
89 u32 mali_session_get_count(void);
90 mali_bool mali_session_pp_job_is_empty(void *data);
91 wait_queue_head_t *mali_session_get_wait_queue(void);
92
93 #define MALI_SESSION_FOREACH(session, tmp, link) \
94         _MALI_OSK_LIST_FOREACHENTRY(session, tmp, &mali_sessions, struct mali_session_data, link)
95
96 MALI_STATIC_INLINE struct mali_page_directory *mali_session_get_page_directory(struct mali_session_data *session)
97 {
98         return session->page_directory;
99 }
100
101 MALI_STATIC_INLINE void mali_session_memory_lock(struct mali_session_data *session)
102 {
103         MALI_DEBUG_ASSERT_POINTER(session);
104         _mali_osk_mutex_wait(session->memory_lock);
105 }
106
107 MALI_STATIC_INLINE void mali_session_memory_unlock(struct mali_session_data *session)
108 {
109         MALI_DEBUG_ASSERT_POINTER(session);
110         _mali_osk_mutex_signal(session->memory_lock);
111 }
112
113 MALI_STATIC_INLINE void mali_session_send_notification(struct mali_session_data *session, _mali_osk_notification_t *object)
114 {
115         _mali_osk_notification_queue_send(session->ioctl_queue, object);
116 }
117
118 #if defined(CONFIG_MALI_DVFS)
119
120 MALI_STATIC_INLINE void mali_session_inc_num_window_jobs(struct mali_session_data *session)
121 {
122         MALI_DEBUG_ASSERT_POINTER(session);
123         _mali_osk_atomic_inc(&session->number_of_window_jobs);
124 }
125
126 /*
127  * Get the max completed window jobs from all active session,
128  * which will be used in  window render frame per sec calculate
129  */
130 u32 mali_session_max_window_num(void);
131
132 #endif
133
134 void mali_session_memory_tracking(_mali_osk_print_ctx *print_ctx);
135
136 #endif /* __MALI_SESSION_H__ */