Initial commit
[kernel/linux-3.0.git] / drivers / media / video / samsung / mali_r3p0 / common / mali_session.h
1 /*
2  * Copyright (C) 2010-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         _mali_osk_lock_t *memory_lock; /**< Lock protecting the vm manipulation */
24         mali_descriptor_mapping * descriptor_mapping; /**< Mapping between userspace descriptors and our pointers */
25         _mali_osk_list_t memory_head; /**< Track all the memory allocated in this session, for freeing on abnormal termination */
26
27         struct mali_page_directory *page_directory; /**< MMU page directory for this session */
28
29         _MALI_OSK_LIST_HEAD(link); /**< Link for list of all sessions */
30 };
31
32 _mali_osk_errcode_t mali_session_initialize(void);
33 void mali_session_terminate(void);
34
35 /* List of all sessions. Actual list head in mali_kernel_core.c */
36 extern _mali_osk_list_t mali_sessions;
37 /* Lock to protect modification and access to the mali_sessions list */
38 extern _mali_osk_lock_t *mali_sessions_lock;
39
40 MALI_STATIC_INLINE void mali_session_lock(void)
41 {
42         _mali_osk_lock_wait(mali_sessions_lock, _MALI_OSK_LOCKMODE_RW);
43 }
44
45 MALI_STATIC_INLINE void mali_session_unlock(void)
46 {
47         _mali_osk_lock_signal(mali_sessions_lock, _MALI_OSK_LOCKMODE_RW);
48 }
49
50 void mali_session_add(struct mali_session_data *session);
51 void mali_session_remove(struct mali_session_data *session);
52 #define MALI_SESSION_FOREACH(session, tmp, link) \
53         _MALI_OSK_LIST_FOREACHENTRY(session, tmp, &mali_sessions, struct mali_session_data, link)
54
55 MALI_STATIC_INLINE struct mali_page_directory *mali_session_get_page_directory(struct mali_session_data *session)
56 {
57         return session->page_directory;
58 }
59
60 MALI_STATIC_INLINE void mali_session_send_notification(struct mali_session_data *session, _mali_osk_notification_t *object)
61 {
62         _mali_osk_notification_queue_send(session->ioctl_queue, object);
63 }
64
65 #endif /* __MALI_KERNEL_SESSION_MANAGER_H__ */