tizen 2.4 release
[kernel/linux-3.0.git] / drivers / gpu / arm / mali400 / r4p0_rel0 / 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, struct mali_timeline_tracker *pp_tracker)
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                 job->finished_notification = _mali_osk_notification_create(_MALI_NOTIFICATION_GP_FINISHED, sizeof(_mali_uk_gp_job_finished_s));
27                 if (NULL == job->finished_notification) {
28                         _mali_osk_free(job);
29                         return NULL;
30                 }
31
32                 job->oom_notification = _mali_osk_notification_create(_MALI_NOTIFICATION_GP_STALLED, sizeof(_mali_uk_gp_job_suspended_s));
33                 if (NULL == job->oom_notification) {
34                         _mali_osk_notification_delete(job->finished_notification);
35                         _mali_osk_free(job);
36                         return NULL;
37                 }
38
39                 if (0 != _mali_osk_copy_from_user(&job->uargs, uargs, sizeof(_mali_uk_gp_start_job_s))) {
40                         _mali_osk_notification_delete(job->finished_notification);
41                         _mali_osk_notification_delete(job->oom_notification);
42                         _mali_osk_free(job);
43                         return NULL;
44                 }
45
46                 perf_counter_flag = mali_gp_job_get_perf_counter_flag(job);
47
48                 /* case when no counters came from user space
49                  * so pass the debugfs / DS-5 provided global ones to the job object */
50                 if (!((perf_counter_flag & _MALI_PERFORMANCE_COUNTER_FLAG_SRC0_ENABLE) ||
51                       (perf_counter_flag & _MALI_PERFORMANCE_COUNTER_FLAG_SRC1_ENABLE))) {
52                         mali_gp_job_set_perf_counter_src0(job, mali_gp_job_get_gp_counter_src0());
53                         mali_gp_job_set_perf_counter_src1(job, mali_gp_job_get_gp_counter_src1());
54                 }
55
56                 _mali_osk_list_init(&job->list);
57                 job->session = session;
58                 job->id = id;
59                 job->heap_current_addr = job->uargs.frame_registers[4];
60                 job->perf_counter_value0 = 0;
61                 job->perf_counter_value1 = 0;
62                 job->pid = _mali_osk_get_pid();
63                 job->tid = _mali_osk_get_tid();
64
65                 job->pp_tracker = pp_tracker;
66                 if (NULL != job->pp_tracker) {
67                         /* Take a reference on PP job's tracker that will be released when the GP
68                            job is done. */
69                         mali_timeline_system_tracker_get(session->timeline_system, pp_tracker);
70                 }
71
72                 mali_timeline_tracker_init(&job->tracker, MALI_TIMELINE_TRACKER_GP, NULL, job);
73                 mali_timeline_fence_copy_uk_fence(&(job->tracker.fence), &(job->uargs.fence));
74
75                 return job;
76         }
77
78         return NULL;
79 }
80
81 void mali_gp_job_delete(struct mali_gp_job *job)
82 {
83         MALI_DEBUG_ASSERT_POINTER(job);
84         MALI_DEBUG_ASSERT(NULL == job->pp_tracker);
85
86         /* de-allocate the pre-allocated oom notifications */
87         if (NULL != job->oom_notification) {
88                 _mali_osk_notification_delete(job->oom_notification);
89                 job->oom_notification = NULL;
90         }
91         if (NULL != job->finished_notification) {
92                 _mali_osk_notification_delete(job->finished_notification);
93                 job->finished_notification = NULL;
94         }
95
96         _mali_osk_free(job);
97 }
98
99 u32 mali_gp_job_get_gp_counter_src0(void)
100 {
101         return gp_counter_src0;
102 }
103
104 void mali_gp_job_set_gp_counter_src0(u32 counter)
105 {
106         gp_counter_src0 = counter;
107 }
108
109 u32 mali_gp_job_get_gp_counter_src1(void)
110 {
111         return gp_counter_src1;
112 }
113
114 void mali_gp_job_set_gp_counter_src1(u32 counter)
115 {
116         gp_counter_src1 = counter;
117 }
118
119 mali_scheduler_mask mali_gp_job_signal_pp_tracker(struct mali_gp_job *job, mali_bool success)
120 {
121         mali_scheduler_mask schedule_mask = MALI_SCHEDULER_MASK_EMPTY;
122
123         MALI_DEBUG_ASSERT_POINTER(job);
124
125         if (NULL != job->pp_tracker) {
126                 schedule_mask |= mali_timeline_system_tracker_put(job->session->timeline_system, job->pp_tracker, MALI_FALSE == success);
127                 job->pp_tracker = NULL;
128         }
129
130         return schedule_mask;
131 }