tizen 2.4 release
[kernel/linux-3.0.git] / drivers / gpu / arm / mali400 / mali / common / mali_session.h
1 /*
2  * Copyright (C) 2011-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 #ifndef __MALI_SESSION_H__
12 #define __MALI_SESSION_H__
13
14 #include "mali_mmu_page_directory.h"
15 #include "mali_kernel_descriptor_mapping.h"
16 #include "mali_osk.h"
17 #include "mali_osk_list.h"
18
19 struct mali_session_data
20 {
21         _mali_osk_notification_queue_t * ioctl_queue;
22
23 #ifdef CONFIG_SYNC
24 /* MALI_SEC */
25 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0)
26         _mali_osk_list_t pending_jobs;
27         _mali_osk_lock_t *pending_jobs_lock;
28 #endif
29 #endif
30
31         _mali_osk_lock_t *memory_lock; /**< Lock protecting the vm manipulation */
32         mali_descriptor_mapping * descriptor_mapping; /**< Mapping between userspace descriptors and our pointers */
33         _mali_osk_list_t memory_head; /**< Track all the memory allocated in this session, for freeing on abnormal termination */
34
35         struct mali_page_directory *page_directory; /**< MMU page directory for this session */
36
37         _MALI_OSK_LIST_HEAD(link); /**< Link for list of all sessions */
38
39         _MALI_OSK_LIST_HEAD(job_list); /**< List of all jobs on this session */
40 };
41
42 _mali_osk_errcode_t mali_session_initialize(void);
43 void mali_session_terminate(void);
44
45 /* List of all sessions. Actual list head in mali_kernel_core.c */
46 extern _mali_osk_list_t mali_sessions;
47 /* Lock to protect modification and access to the mali_sessions list */
48 extern _mali_osk_lock_t *mali_sessions_lock;
49
50 MALI_STATIC_INLINE void mali_session_lock(void)
51 {
52         _mali_osk_lock_wait(mali_sessions_lock, _MALI_OSK_LOCKMODE_RW);
53 }
54
55 MALI_STATIC_INLINE void mali_session_unlock(void)
56 {
57         _mali_osk_lock_signal(mali_sessions_lock, _MALI_OSK_LOCKMODE_RW);
58 }
59
60 void mali_session_add(struct mali_session_data *session);
61 void mali_session_remove(struct mali_session_data *session);
62 #define MALI_SESSION_FOREACH(session, tmp, link) \
63         _MALI_OSK_LIST_FOREACHENTRY(session, tmp, &mali_sessions, struct mali_session_data, link)
64
65 MALI_STATIC_INLINE struct mali_page_directory *mali_session_get_page_directory(struct mali_session_data *session)
66 {
67         return session->page_directory;
68 }
69
70 MALI_STATIC_INLINE void mali_session_send_notification(struct mali_session_data *session, _mali_osk_notification_t *object)
71 {
72         _mali_osk_notification_queue_send(session->ioctl_queue, object);
73 }
74
75 #endif /* __MALI_SESSION_H__ */