summaryrefslogtreecommitdiff
path: root/drivers/gpu/mali/mali400ko/driver/src/devicedrv/mali/linux/mali_osk_pm.c
blob: 04fcd4572dfd6c509c808a238c0dc740121bf258 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/**
 * Copyright (C) 2010-2011 ARM Limited. All rights reserved.
 * 
 * This program is free software and is provided to you under the terms of the GNU General Public License version 2
 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence.
 * 
 * A copy of the licence is included with the program, and can also be obtained from Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

/**
 * @file mali_osk_pm.c
 * Implementation of the callback functions from common power management
 */

#include <linux/sched.h>

#ifdef CONFIG_PM_RUNTIME
#include <linux/pm_runtime.h>
#endif /* CONFIG_PM_RUNTIME */

#include <linux/platform_device.h>

#include "mali_platform.h"
#include "mali_osk.h"
#include "mali_uk_types.h"
#include "mali_pmm.h"
#include "mali_ukk.h"
#include "mali_kernel_common.h"
#include "mali_kernel_license.h"
#include "mali_kernel_pm.h"
#include "mali_device_pause_resume.h"
#include "mali_linux_pm.h"
#include "mali_linux_pm_testsuite.h"

#if MALI_PMM_RUNTIME_JOB_CONTROL_ON
#ifdef CONFIG_PM_RUNTIME
static int is_runtime =0;
#endif /* CONFIG_PM_RUNTIME */
#endif /* MALI_PMM_RUNTIME_JOB_CONTROL_ON */

#if MALI_POWER_MGMT_TEST_SUITE

#ifdef CONFIG_PM
unsigned int mali_pmm_events_triggered_mask = 0;
#endif /* CONFIG_PM */

void _mali_osk_pmm_policy_events_notifications(mali_pmm_event_id mali_pmm_event)
{
#if MALI_LICENSE_IS_GPL
#ifdef CONFIG_PM

	switch (mali_pmm_event)
	{
		case MALI_PMM_EVENT_JOB_QUEUED:
			if (mali_job_scheduling_events_recording_on == 1)
			{
				mali_pmm_events_triggered_mask |= (1<<0);
			}
		break;

		case MALI_PMM_EVENT_JOB_SCHEDULED:
			if (mali_job_scheduling_events_recording_on == 1)
			{
				mali_pmm_events_triggered_mask |= (1<<1);
			}
		break;

		case MALI_PMM_EVENT_JOB_FINISHED:
			if (mali_job_scheduling_events_recording_on == 1)
			{
				mali_pmm_events_triggered_mask |= (1<<2);
				mali_job_scheduling_events_recording_on = 0;
				pwr_mgmt_status_reg = mali_pmm_events_triggered_mask;
			}
		break;

		case MALI_PMM_EVENT_TIMEOUT:
			if (mali_timeout_event_recording_on == 1)
			{
				pwr_mgmt_status_reg = (1<<3);
				mali_timeout_event_recording_on = 0;
			}
		break;

		default:

		break;

	}
#endif /* CONFIG_PM */

#endif /* MALI_LICENSE_IS_GPL */
}
#endif /* MALI_POWER_MGMT_TEST_SUITE */

/** This function is called when the Mali device has completed power up
 * operation.
 */
void _mali_osk_pmm_power_up_done(mali_pmm_message_data data)
{
#if MALI_LICENSE_IS_GPL
#ifdef CONFIG_PM
	is_wake_up_needed = 1;
	wake_up_process(pm_thread);
	MALI_DEBUG_PRINT(4, ("OSPMM: MALI OSK Power up Done\n" ));
	return;
#endif /* CONFIG_PM */
#endif /* MALI_LICENSE_IS_GPL */
}

/** This function is called when the Mali device has completed power down
 * operation.
 */
void _mali_osk_pmm_power_down_done(mali_pmm_message_data data)
{
#if MALI_LICENSE_IS_GPL
#ifdef CONFIG_PM
	is_wake_up_needed = 1;
#if MALI_POWER_MGMT_TEST_SUITE
	if (is_mali_pmu_present == 0)
	{
		pwr_mgmt_status_reg = _mali_pmm_cores_list();
	}
#endif /* MALI_POWER_MGMT_TEST_SUITE */
	wake_up_process(pm_thread);
	MALI_DEBUG_PRINT(4, ("OSPMM: MALI Power down Done\n" ));
	return;

#endif /* CONFIG_PM */
#endif /* MALI_LICENSE_IS_GPL */
}

/** This function is invoked when mali device is idle.
*/
_mali_osk_errcode_t _mali_osk_pmm_dev_idle(void)
{
	_mali_osk_errcode_t err = 0;
#if MALI_LICENSE_IS_GPL
#ifdef CONFIG_PM_RUNTIME
#if MALI_PMM_RUNTIME_JOB_CONTROL_ON

	err = pm_runtime_put_sync(&(mali_gpu_device.dev));	
	if(err)
	{
		MALI_DEBUG_PRINT(4, ("OSPMM: Error in _mali_osk_pmm_dev_idle\n" ));	
	}
#endif /* MALI_PMM_RUNTIME_JOB_CONTROL_ON */
#endif /* CONFIG_PM_RUNTIME */
#endif /* MALI_LICENSE_IS_GPL */
	return err;
}

/** This funtion is invoked when mali device needs to be activated.
*/
void _mali_osk_pmm_dev_activate(void)
{
	
#if MALI_LICENSE_IS_GPL
#ifdef CONFIG_PM_RUNTIME
#if MALI_PMM_RUNTIME_JOB_CONTROL_ON
	int err = 0;
	if(is_runtime == 0)
	{
		pm_suspend_ignore_children(&(mali_gpu_device.dev), true);
		pm_runtime_enable(&(mali_gpu_device.dev));
 		pm_runtime_get_sync(&(mali_gpu_device.dev));
		is_runtime = 1;
	}
	else
	{
		err = pm_runtime_get_sync(&(mali_gpu_device.dev));
	}
	if(err)
        {
		MALI_DEBUG_PRINT(4, ("OSPMM: Error in _mali_osk_pmm_dev_activate\n" ));
        }
#endif /* MALI_PMM_RUNTIME_JOB_CONTROL_ON */
#endif /* CONFIG_PM_RUNTIME */
#endif /* MALI_LICENSE_IS_GPL */
}

void _mali_osk_pmm_dvfs_operation_done(mali_pmm_message_data data)
{
#if MALI_LICENSE_IS_GPL
#ifdef CONFIG_PM
	is_wake_up_needed = 1;
	wake_up_process(dvfs_pm_thread);
	MALI_DEBUG_PRINT(4, ("OSPMM: MALI OSK DVFS Operation done\n" ));
	return;
#endif /* CONFIG_PM */
#endif /* MALI_LICENSE_IS_GPL */
}