e0a2805b13d3a22d7e00ab94ef2b189ff76973ab
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / arm / mali400 / mali / common / mali_session.c
1 /*
2  * Copyright (C) 2012-2015 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 #include "mali_osk.h"
12 #include "mali_osk_list.h"
13 #include "mali_session.h"
14 #include "mali_ukk.h"
15 #ifdef MALI_MEM_SWAP_TRACKING
16 #include "mali_memory_swap_alloc.h"
17 #endif
18
19 _MALI_OSK_LIST_HEAD(mali_sessions);
20 static u32 mali_session_count = 0;
21
22 _mali_osk_spinlock_irq_t *mali_sessions_lock = NULL;
23 wait_queue_head_t pending_queue;
24
25 _mali_osk_errcode_t mali_session_initialize(void)
26 {
27         _MALI_OSK_INIT_LIST_HEAD(&mali_sessions);
28         /* init wait queue for big varying job */
29         init_waitqueue_head(&pending_queue);
30
31         mali_sessions_lock = _mali_osk_spinlock_irq_init(
32                                      _MALI_OSK_LOCKFLAG_ORDERED,
33                                      _MALI_OSK_LOCK_ORDER_SESSIONS);
34         if (NULL == mali_sessions_lock) {
35                 return _MALI_OSK_ERR_NOMEM;
36         }
37
38         return _MALI_OSK_ERR_OK;
39 }
40
41 void mali_session_terminate(void)
42 {
43         if (NULL != mali_sessions_lock) {
44                 _mali_osk_spinlock_irq_term(mali_sessions_lock);
45                 mali_sessions_lock = NULL;
46         }
47 }
48
49 void mali_session_add(struct mali_session_data *session)
50 {
51         mali_session_lock();
52         _mali_osk_list_add(&session->link, &mali_sessions);
53         mali_session_count++;
54         mali_session_unlock();
55 }
56
57 void mali_session_remove(struct mali_session_data *session)
58 {
59         mali_session_lock();
60         _mali_osk_list_delinit(&session->link);
61         mali_session_count--;
62         mali_session_unlock();
63 }
64
65 u32 mali_session_get_count(void)
66 {
67         return mali_session_count;
68 }
69
70 wait_queue_head_t *mali_session_get_wait_queue(void)
71 {
72         return &pending_queue;
73 }
74
75 /*
76  * Get the max completed window jobs from all active session,
77  * which will be used in window render frame per sec calculate
78  */
79 #if defined(CONFIG_MALI_DVFS)
80 u32 mali_session_max_window_num(void)
81 {
82         struct mali_session_data *session, *tmp;
83         u32 max_window_num = 0;
84         u32 tmp_number = 0;
85
86         mali_session_lock();
87
88         MALI_SESSION_FOREACH(session, tmp, link) {
89                 tmp_number = _mali_osk_atomic_xchg(
90                                      &session->number_of_window_jobs, 0);
91                 if (max_window_num < tmp_number) {
92                         max_window_num = tmp_number;
93                 }
94         }
95
96         mali_session_unlock();
97
98         return max_window_num;
99 }
100 #endif
101
102 void mali_session_memory_tracking(_mali_osk_print_ctx *print_ctx)
103 {
104         struct mali_session_data *session, *tmp;
105         u32 mali_mem_usage;
106         u32 total_mali_mem_size;
107 #ifdef MALI_MEM_SWAP_TRACKING
108         u32 swap_pool_size;
109         u32 swap_unlock_size;
110 #endif
111
112         MALI_DEBUG_ASSERT_POINTER(print_ctx);
113         mali_session_lock();
114         MALI_SESSION_FOREACH(session, tmp, link) {
115 #ifdef MALI_MEM_SWAP_TRACKING
116                 _mali_osk_ctxprintf(print_ctx, "  %-25s  %-10u  %-10u  %-15u  %-15u  %-10u  %-10u  %-10u\n",
117                                     session->comm, session->pid,
118                                     (atomic_read(&session->mali_mem_allocated_pages)) * _MALI_OSK_MALI_PAGE_SIZE,
119                                     session->max_mali_mem_allocated_size,
120                                     (atomic_read(&session->mali_mem_array[MALI_MEM_EXTERNAL])) * _MALI_OSK_MALI_PAGE_SIZE,
121                                     (atomic_read(&session->mali_mem_array[MALI_MEM_UMP])) * _MALI_OSK_MALI_PAGE_SIZE,
122                                     (atomic_read(&session->mali_mem_array[MALI_MEM_DMA_BUF])) * _MALI_OSK_MALI_PAGE_SIZE,
123                                     (atomic_read(&session->mali_mem_array[MALI_MEM_SWAP])) * _MALI_OSK_MALI_PAGE_SIZE
124                                    );
125 #else
126                 _mali_osk_ctxprintf(print_ctx, "  %-25s  %-10u  %-10u  %-15u  %-15u  %-10u  %-10u  \n",
127                                     session->comm, session->pid,
128                                     (atomic_read(&session->mali_mem_allocated_pages)) * _MALI_OSK_MALI_PAGE_SIZE,
129                                     session->max_mali_mem_allocated_size,
130                                     (atomic_read(&session->mali_mem_array[MALI_MEM_EXTERNAL])) * _MALI_OSK_MALI_PAGE_SIZE,
131                                     (atomic_read(&session->mali_mem_array[MALI_MEM_UMP])) * _MALI_OSK_MALI_PAGE_SIZE,
132                                     (atomic_read(&session->mali_mem_array[MALI_MEM_DMA_BUF])) * _MALI_OSK_MALI_PAGE_SIZE
133                                    );
134 #endif
135         }
136         mali_session_unlock();
137         mali_mem_usage  = _mali_ukk_report_memory_usage();
138         total_mali_mem_size = _mali_ukk_report_total_memory_size();
139         _mali_osk_ctxprintf(print_ctx, "Mali mem usage: %u\nMali mem limit: %u\n", mali_mem_usage, total_mali_mem_size);
140 #ifdef MALI_MEM_SWAP_TRACKING
141         mali_mem_swap_tracking(&swap_pool_size, &swap_unlock_size);
142         _mali_osk_ctxprintf(print_ctx, "Mali swap mem pool : %u\nMali swap mem unlock: %u\n", swap_pool_size, swap_unlock_size);
143 #endif
144 }