tizen 2.4 release
[kernel/linux-3.0.git] / drivers / gpu / arm / mali400 / mali / common / mali_gp_job.c
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 #include "mali_gp_job.h"
12 #include "mali_osk.h"
13 #include "mali_osk_list.h"
14 #include "mali_uk_types.h"
15
16 static u32 gp_counter_src0 = MALI_HW_CORE_NO_COUNTER;      /**< Performance counter 0, MALI_HW_CORE_NO_COUNTER for disabled */
17 static u32 gp_counter_src1 = MALI_HW_CORE_NO_COUNTER;           /**< Performance counter 1, MALI_HW_CORE_NO_COUNTER for disabled */
18
19 struct mali_gp_job *mali_gp_job_create(struct mali_session_data *session, _mali_uk_gp_start_job_s *uargs, u32 id)
20 {
21         struct mali_gp_job *job;
22         u32 perf_counter_flag;
23
24         job = _mali_osk_malloc(sizeof(struct mali_gp_job));
25         if (NULL != job)
26         {
27                 job->finished_notification = _mali_osk_notification_create(_MALI_NOTIFICATION_GP_FINISHED, sizeof(_mali_uk_gp_job_finished_s));
28                 if (NULL == job->finished_notification)
29                 {
30                         _mali_osk_free(job);
31                         return NULL;
32                 }
33
34                 job->oom_notification = _mali_osk_notification_create(_MALI_NOTIFICATION_GP_STALLED, sizeof(_mali_uk_gp_job_suspended_s));
35                 if (NULL == job->oom_notification)
36                 {
37                         _mali_osk_notification_delete(job->finished_notification);
38                         _mali_osk_free(job);
39                         return NULL;
40                 }
41
42                 if (0 != copy_from_user(&job->uargs, uargs, sizeof(_mali_uk_gp_start_job_s)))
43                 {
44                         _mali_osk_notification_delete(job->finished_notification);
45                         _mali_osk_notification_delete(job->oom_notification);
46                         _mali_osk_free(job);
47                         return NULL;
48                 }
49
50                 perf_counter_flag = mali_gp_job_get_perf_counter_flag(job);
51
52                 /* case when no counters came from user space
53                  * so pass the debugfs / DS-5 provided global ones to the job object */
54                 if (!((perf_counter_flag & _MALI_PERFORMANCE_COUNTER_FLAG_SRC0_ENABLE) ||
55                                 (perf_counter_flag & _MALI_PERFORMANCE_COUNTER_FLAG_SRC1_ENABLE)))
56                 {
57                         mali_gp_job_set_perf_counter_src0(job, mali_gp_job_get_gp_counter_src0());
58                         mali_gp_job_set_perf_counter_src1(job, mali_gp_job_get_gp_counter_src1());
59                 }
60
61                 _mali_osk_list_init(&job->list);
62                 job->session = session;
63                 job->id = id;
64                 job->heap_current_addr = job->uargs.frame_registers[4];
65                 job->perf_counter_value0 = 0;
66                 job->perf_counter_value1 = 0;
67                 job->pid = _mali_osk_get_pid();
68                 job->tid = _mali_osk_get_tid();
69
70                 return job;
71         }
72
73         return NULL;
74 }
75
76 void mali_gp_job_delete(struct mali_gp_job *job)
77 {
78
79         /* de-allocate the pre-allocated oom notifications */
80         if (NULL != job->oom_notification)
81         {
82                 _mali_osk_notification_delete(job->oom_notification);
83                 job->oom_notification = NULL;
84         }
85         if (NULL != job->finished_notification)
86         {
87                 _mali_osk_notification_delete(job->finished_notification);
88                 job->finished_notification = NULL;
89         }
90
91         _mali_osk_free(job);
92 }
93
94 u32 mali_gp_job_get_gp_counter_src0(void)
95 {
96         return gp_counter_src0;
97 }
98
99 mali_bool mali_gp_job_set_gp_counter_src0(u32 counter)
100 {
101         gp_counter_src0 = counter;
102
103         return MALI_TRUE;
104 }
105
106 u32 mali_gp_job_get_gp_counter_src1(void)
107 {
108         return gp_counter_src1;
109 }
110
111 mali_bool mali_gp_job_set_gp_counter_src1(u32 counter)
112 {
113         gp_counter_src1 = counter;
114
115         return MALI_TRUE;
116 }