tizen 2.4 release
[kernel/linux-3.0.git] / drivers / gpu / arm / mali400 / r4p0_rel0 / common / mali_session.c
1 /*
2  * Copyright (C) 2012 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
15 _MALI_OSK_LIST_HEAD(mali_sessions);
16 static u32 mali_session_count = 0;
17
18 _mali_osk_spinlock_irq_t *mali_sessions_lock;
19
20 _mali_osk_errcode_t mali_session_initialize(void)
21 {
22         _MALI_OSK_INIT_LIST_HEAD(&mali_sessions);
23
24         mali_sessions_lock = _mali_osk_spinlock_irq_init(_MALI_OSK_LOCKFLAG_ORDERED, _MALI_OSK_LOCK_ORDER_SESSIONS);
25
26         if (NULL == mali_sessions_lock) return _MALI_OSK_ERR_NOMEM;
27
28         return _MALI_OSK_ERR_OK;
29 }
30
31 void mali_session_terminate(void)
32 {
33         _mali_osk_spinlock_irq_term(mali_sessions_lock);
34 }
35
36 void mali_session_add(struct mali_session_data *session)
37 {
38         mali_session_lock();
39         _mali_osk_list_add(&session->link, &mali_sessions);
40         mali_session_count++;
41         mali_session_unlock();
42 }
43
44 void mali_session_remove(struct mali_session_data *session)
45 {
46         mali_session_lock();
47         _mali_osk_list_delinit(&session->link);
48         mali_session_count--;
49         mali_session_unlock();
50 }
51
52 u32 mali_session_get_count(void)
53 {
54         return mali_session_count;
55 }
56
57 /*
58  * Get the max completed window jobs from all active session,
59  * which will be used in window render frame per sec calculate
60  */
61 #if defined(CONFIG_MALI400_POWER_PERFORMANCE_POLICY)
62 u32 mali_session_max_window_num(void)
63 {
64         struct mali_session_data *session, *tmp;
65         u32 max_window_num = 0;
66         u32 tmp_number = 0;
67
68         mali_session_lock();
69
70         MALI_SESSION_FOREACH(session, tmp, link) {
71                 tmp_number = _mali_osk_atomic_xchg(&session->number_of_window_jobs, 0);
72                 if (max_window_num < tmp_number) {
73                         max_window_num = tmp_number;
74                 }
75         }
76
77         mali_session_unlock();
78
79         return max_window_num;
80 }
81 #endif