tizen 2.4 release
[kernel/linux-3.0.git] / drivers / gpu / arm / mali400 / mali / common / mali_pp_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_pp_job.h"
12 #include "mali_osk.h"
13 #include "mali_osk_list.h"
14 #include "mali_kernel_common.h"
15 #include "mali_uk_types.h"
16
17 static u32 pp_counter_src0 = MALI_HW_CORE_NO_COUNTER;      /**< Performance counter 0, MALI_HW_CORE_NO_COUNTER for disabled */
18 static u32 pp_counter_src1 = MALI_HW_CORE_NO_COUNTER;      /**< Performance counter 1, MALI_HW_CORE_NO_COUNTER for disabled */
19
20 struct mali_pp_job *mali_pp_job_create(struct mali_session_data *session, _mali_uk_pp_start_job_s *uargs, u32 id)
21 {
22         struct mali_pp_job *job;
23         u32 perf_counter_flag;
24
25         job = _mali_osk_malloc(sizeof(struct mali_pp_job));
26         if (NULL != job)
27         {
28                 u32 i;
29
30                 if (0 != _mali_osk_copy_from_user(&job->uargs, uargs, sizeof(_mali_uk_pp_start_job_s)))
31                 {
32                         _mali_osk_free(job);
33                         return NULL;
34                 }
35
36                 if (job->uargs.num_cores > _MALI_PP_MAX_SUB_JOBS)
37                 {
38                         MALI_PRINT_ERROR(("Mali PP job: Too many sub jobs specified in job object\n"));
39                         _mali_osk_free(job);
40                         return NULL;
41                 }
42
43                 if (!mali_pp_job_use_no_notification(job))
44                 {
45                         job->finished_notification = _mali_osk_notification_create(_MALI_NOTIFICATION_PP_FINISHED, sizeof(_mali_uk_pp_job_finished_s));
46                         if (NULL == job->finished_notification)
47                         {
48                                 _mali_osk_free(job);
49                                 return NULL;
50                         }
51                 }
52                 else
53                 {
54                         job->finished_notification = NULL;
55                 }
56
57                 perf_counter_flag = mali_pp_job_get_perf_counter_flag(job);
58
59                 /* case when no counters came from user space
60                  * so pass the debugfs / DS-5 provided global ones to the job object */
61                 if (!((perf_counter_flag & _MALI_PERFORMANCE_COUNTER_FLAG_SRC0_ENABLE) ||
62                                 (perf_counter_flag & _MALI_PERFORMANCE_COUNTER_FLAG_SRC1_ENABLE)))
63                 {
64                         mali_pp_job_set_perf_counter_src0(job, mali_pp_job_get_pp_counter_src0());
65                         mali_pp_job_set_perf_counter_src1(job, mali_pp_job_get_pp_counter_src1());
66                 }
67
68                 _mali_osk_list_init(&job->list);
69                 job->session = session;
70                 _mali_osk_list_init(&job->session_list);
71                 job->id = id;
72
73                 for (i = 0; i < job->uargs.num_cores; i++)
74                 {
75                         job->perf_counter_value0[i] = 0;
76                         job->perf_counter_value1[i] = 0;
77                 }
78                 job->sub_jobs_num = job->uargs.num_cores ? job->uargs.num_cores : 1;
79                 job->sub_jobs_started = 0;
80                 job->sub_jobs_completed = 0;
81                 job->sub_job_errors = 0;
82                 job->pid = _mali_osk_get_pid();
83                 job->tid = _mali_osk_get_tid();
84 #if defined(CONFIG_SYNC)
85 /* MALI_SEC */
86 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0)
87                 job->sync_point = NULL;
88                 job->pre_fence = NULL;
89                 job->sync_work = NULL;
90 #endif
91 #endif
92
93                 return job;
94         }
95
96         return NULL;
97 }
98
99 void mali_pp_job_delete(struct mali_pp_job *job)
100 {
101 #ifdef CONFIG_SYNC
102 /* MALI_SEC */
103 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0)
104         if (NULL != job->pre_fence) sync_fence_put(job->pre_fence);
105         if (NULL != job->sync_point) sync_fence_put(job->sync_point->fence);
106 #endif
107 #endif
108         if (NULL != job->finished_notification)
109         {
110                 _mali_osk_notification_delete(job->finished_notification);
111         }
112         _mali_osk_free(job);
113 }
114
115 u32 mali_pp_job_get_pp_counter_src0(void)
116 {
117         return pp_counter_src0;
118 }
119
120 mali_bool mali_pp_job_set_pp_counter_src0(u32 counter)
121 {
122         pp_counter_src0 = counter;
123
124         return MALI_TRUE;
125 }
126
127 u32 mali_pp_job_get_pp_counter_src1(void)
128 {
129         return pp_counter_src1;
130 }
131
132 mali_bool mali_pp_job_set_pp_counter_src1(u32 counter)
133 {
134         pp_counter_src1 = counter;
135
136         return MALI_TRUE;
137 }