UPSTREAM: DT/arm,gic-v3: Documment PPI partition support
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / arm / mali400 / mali / common / mali_gp_job.c
1 /*
2  * Copyright (C) 2011-2014 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         MALI_DEBUG_ASSERT(_mali_osk_list_empty(&job->list));
86
87         /* de-allocate the pre-allocated oom notifications */
88         if (NULL != job->oom_notification) {
89                 _mali_osk_notification_delete(job->oom_notification);
90                 job->oom_notification = NULL;
91         }
92         if (NULL != job->finished_notification) {
93                 _mali_osk_notification_delete(job->finished_notification);
94                 job->finished_notification = NULL;
95         }
96
97         _mali_osk_free(job);
98 }
99
100 void mali_gp_job_list_add(struct mali_gp_job *job, _mali_osk_list_t *list)
101 {
102         struct mali_gp_job *iter;
103         struct mali_gp_job *tmp;
104
105         MALI_DEBUG_ASSERT_POINTER(job);
106         MALI_DEBUG_ASSERT_SCHEDULER_LOCK_HELD();
107
108         /* Find position in list/queue where job should be added. */
109         _MALI_OSK_LIST_FOREACHENTRY_REVERSE(iter, tmp, list,
110                                             struct mali_gp_job, list) {
111
112                 /* A span is used to handle job ID wrapping. */
113                 bool job_is_after = (mali_gp_job_get_id(job) -
114                                      mali_gp_job_get_id(iter)) <
115                                     MALI_SCHEDULER_JOB_ID_SPAN;
116
117                 if (job_is_after) {
118                         break;
119                 }
120         }
121
122         _mali_osk_list_add(&job->list, &iter->list);
123 }
124
125 u32 mali_gp_job_get_gp_counter_src0(void)
126 {
127         return gp_counter_src0;
128 }
129
130 void mali_gp_job_set_gp_counter_src0(u32 counter)
131 {
132         gp_counter_src0 = counter;
133 }
134
135 u32 mali_gp_job_get_gp_counter_src1(void)
136 {
137         return gp_counter_src1;
138 }
139
140 void mali_gp_job_set_gp_counter_src1(u32 counter)
141 {
142         gp_counter_src1 = counter;
143 }
144
145 mali_scheduler_mask mali_gp_job_signal_pp_tracker(struct mali_gp_job *job, mali_bool success)
146 {
147         mali_scheduler_mask schedule_mask = MALI_SCHEDULER_MASK_EMPTY;
148
149         MALI_DEBUG_ASSERT_POINTER(job);
150
151         if (NULL != job->pp_tracker) {
152                 schedule_mask |= mali_timeline_system_tracker_put(job->session->timeline_system, job->pp_tracker, MALI_FALSE == success);
153                 job->pp_tracker = NULL;
154         }
155
156         return schedule_mask;
157 }