Initial commit
[kernel/linux-3.0.git] / drivers / gpu / vithar / osk / src / linux / include / osk / mali_osk_arch_credentials.h
1 /*
2  *
3  * (C) COPYRIGHT 2008-2011 ARM Limited. All rights reserved.
4  *
5  * This program is free software and is provided to you under the terms of the GNU General Public License version 2
6  * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence.
7  * 
8  * A copy of the licence is included with the program, and can also be obtained from Free Software
9  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
10  * 
11  */
12
13
14
15 /**
16  * @file
17  * Implementation of the OS abstraction layer for the kernel device driver
18  */
19
20 #ifndef _OSK_ARCH_CREDENTIALS_H_
21 #define _OSK_ARCH_CREDENTIALS_H_
22
23 #ifndef _OSK_H_
24 #error "Include mali_osk.h directly"
25 #endif
26
27 #include <linux/cred.h>
28
29 OSK_STATIC_INLINE mali_bool osk_is_privileged(void)
30 {
31         mali_bool is_privileged = MALI_FALSE;
32
33         /* Check if the caller is root */
34         if (current_euid() == 0)
35         {
36                 is_privileged = MALI_TRUE;
37         }
38
39         return is_privileged;
40 }
41
42 OSK_STATIC_INLINE mali_bool osk_is_policy_realtime(void)
43 {
44         int policy = current->policy;
45
46         if (policy == SCHED_FIFO || policy == SCHED_RR)
47         {
48                 return MALI_TRUE;
49         }
50
51         return MALI_FALSE;
52 }
53
54 OSK_STATIC_INLINE void osk_get_process_priority(osk_process_priority *prio)
55 {
56         /* Note that we return the current process priority.
57          * If called from a kernel thread the priority returned
58          * will be the kernel thread priority and not the user
59          * process that is currently submitting jobs to the scheduler.
60          */
61         OSK_ASSERT(prio);
62
63         if(osk_is_policy_realtime())
64         {
65                 prio->is_realtime = MALI_TRUE;
66                 /* NOTE: realtime range was in the range 0..99 (lowest to highest) so we invert
67                  * the priority and scale to -20..0 to normalize the result with the NICE range 
68                  */
69                 prio->priority = (((MAX_RT_PRIO-1) - current->rt_priority) / 5) - 20;
70                 /* Realtime range returned:
71                  * -20 - highest priority
72                  *  0  - lowest priority
73                  */
74         }
75         else
76         {
77                 prio->is_realtime = MALI_FALSE;
78                 prio->priority = (current->static_prio - MAX_RT_PRIO) - 20;
79                 /* NICE range returned:
80                  * -20 - highest priority
81                  * +19 - lowest priority
82                  */
83         }
84 }
85
86 #endif /* _OSK_ARCH_CREDENTIALS_H_ */