2 * Copyright (C) 2011-2012 ARM Limited. All rights reserved.
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.
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.
11 #include "mali_gp_job.h"
13 #include "mali_osk_list.h"
14 #include "mali_uk_types.h"
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 */
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)
21 struct mali_gp_job *job;
22 u32 perf_counter_flag;
24 job = _mali_osk_malloc(sizeof(struct mali_gp_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) {
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);
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);
46 perf_counter_flag = mali_gp_job_get_perf_counter_flag(job);
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());
56 _mali_osk_list_init(&job->list);
57 job->session = session;
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();
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
69 mali_timeline_system_tracker_get(session->timeline_system, pp_tracker);
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));
81 void mali_gp_job_delete(struct mali_gp_job *job)
83 MALI_DEBUG_ASSERT_POINTER(job);
84 MALI_DEBUG_ASSERT(NULL == job->pp_tracker);
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;
91 if (NULL != job->finished_notification) {
92 _mali_osk_notification_delete(job->finished_notification);
93 job->finished_notification = NULL;
99 u32 mali_gp_job_get_gp_counter_src0(void)
101 return gp_counter_src0;
104 void mali_gp_job_set_gp_counter_src0(u32 counter)
106 gp_counter_src0 = counter;
109 u32 mali_gp_job_get_gp_counter_src1(void)
111 return gp_counter_src1;
114 void mali_gp_job_set_gp_counter_src1(u32 counter)
116 gp_counter_src1 = counter;
119 mali_scheduler_mask mali_gp_job_signal_pp_tracker(struct mali_gp_job *job, mali_bool success)
121 mali_scheduler_mask schedule_mask = MALI_SCHEDULER_MASK_EMPTY;
123 MALI_DEBUG_ASSERT_POINTER(job);
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;
130 return schedule_mask;