~thopiekar/arm-mali/mali-400-kernel-drivers-sunxi

« back to all changes in this revision

Viewing changes to driver/src/devicedrv/mali/linux/mali_kernel_pm.c

  • Committer: Dmitriy Beykun
  • Date: 2012-10-21 16:12:55 UTC
  • Revision ID: git-v1:23debc5a26ce858ef020405dbf91b2f268a72f44
added r3p0-04rel0 kernel drivers

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
 
11
11
/**
12
12
 * @file mali_kernel_pm.c
13
 
 * Implementation of the Linux Power Management for Mali GPU kernel driver
 
13
 * Linux Power Management integration
14
14
 */
15
15
 
16
 
#if USING_MALI_PMM
17
16
#include <linux/sched.h>
18
 
 
19
 
#ifdef CONFIG_PM_RUNTIME
20
 
#include <linux/pm_runtime.h>
21
 
#endif /* CONFIG_PM_RUNTIME */
22
 
 
23
17
#include <linux/platform_device.h>
24
18
#include <linux/version.h>
25
19
#include <asm/current.h>
26
20
#include <linux/suspend.h>
27
 
 
28
 
#include "mali_platform.h" 
 
21
#include <linux/module.h>
 
22
#ifdef CONFIG_PM_RUNTIME
 
23
#include <linux/pm_runtime.h>
 
24
#endif
29
25
#include "mali_osk.h"
30
26
#include "mali_uk_types.h"
31
 
#include "mali_pmm.h"
32
 
#include "mali_ukk.h"
33
27
#include "mali_kernel_common.h"
34
28
#include "mali_kernel_license.h"
35
 
#include "mali_kernel_pm.h"
36
 
#include "mali_device_pause_resume.h"
37
29
#include "mali_linux_pm.h"
38
 
 
39
 
#if MALI_GPU_UTILIZATION
40
 
#include "mali_kernel_utilization.h"
41
 
#endif /* MALI_GPU_UTILIZATION */
42
 
 
43
 
#if MALI_POWER_MGMT_TEST_SUITE
44
 
#ifdef CONFIG_PM
45
 
#include "mali_linux_pm_testsuite.h"
46
 
#include "mali_platform_pmu_internal_testing.h"
47
 
unsigned int pwr_mgmt_status_reg = 0;
48
 
#endif /* CONFIG_PM */
49
 
#endif /* MALI_POWER_MGMT_TEST_SUITE */
50
 
 
51
 
static int is_os_pmm_thread_waiting = 0;
52
 
 
53
 
/* kernel should be configured with power management support */
54
 
#ifdef CONFIG_PM
55
 
 
56
 
#if MALI_LICENSE_IS_GPL
57
 
 
58
 
/* Linux kernel major version */
59
 
#define LINUX_KERNEL_MAJOR_VERSION 2
60
 
 
61
 
/* Linux kernel minor version */
62
 
#define LINUX_KERNEL_MINOR_VERSION 6
63
 
 
64
 
/* Linux kernel development version */
65
 
#define LINUX_KERNEL_DEVELOPMENT_VERSION 29
66
 
 
67
 
#ifdef CONFIG_PM_DEBUG
68
 
static const char* const mali_states[_MALI_MAX_DEBUG_OPERATIONS] = {
69
 
        [_MALI_DEVICE_SUSPEND] = "suspend",
70
 
        [_MALI_DEVICE_RESUME] = "resume",
71
 
        [_MALI_DVFS_PAUSE_EVENT] = "dvfs_pause",
72
 
        [_MALI_DVFS_RESUME_EVENT] = "dvfs_resume",
73
 
};
74
 
 
75
 
#endif /* CONFIG_PM_DEBUG */
76
 
 
77
 
#ifdef CONFIG_PM_RUNTIME
78
 
#if MALI_PMM_RUNTIME_JOB_CONTROL_ON
79
 
static int mali_pwr_suspend_notifier(struct notifier_block *nb,unsigned long event,void* dummy);
80
 
 
81
 
static struct notifier_block mali_pwr_notif_block = {
82
 
        .notifier_call = mali_pwr_suspend_notifier
83
 
};
84
 
#endif /* MALI_PMM_RUNTIME_JOB_CONTROL_ON */
85
 
#endif /* CONFIG_PM_RUNTIME */
86
 
 
87
 
/* Power management thread pointer */
88
 
struct task_struct *pm_thread;
89
 
 
90
 
/* dvfs power management thread */
91
 
struct task_struct *dvfs_pm_thread;
92
 
 
93
 
/* is wake up needed */
94
 
short is_wake_up_needed = 0;
95
 
int timeout_fired = 2;
96
 
unsigned int is_mali_pmm_testsuite_enabled = 0;
97
 
 
98
 
_mali_device_power_states mali_device_state = _MALI_DEVICE_RESUME;
99
 
_mali_device_power_states mali_dvfs_device_state = _MALI_DEVICE_RESUME;
100
 
_mali_osk_lock_t *lock;
101
 
 
102
 
#if MALI_POWER_MGMT_TEST_SUITE
103
 
 
104
 
const char* const mali_pmm_recording_events[_MALI_DEVICE_MAX_PMM_EVENTS] = {
105
 
        [_MALI_DEVICE_PMM_TIMEOUT_EVENT] = "timeout",
106
 
        [_MALI_DEVICE_PMM_JOB_SCHEDULING_EVENTS] = "job_scheduling",
107
 
        [_MALI_DEVICE_PMM_REGISTERED_CORES] = "cores",
108
 
 
109
 
};
110
 
 
111
 
unsigned int mali_timeout_event_recording_on = 0;
112
 
unsigned int mali_job_scheduling_events_recording_on = 0;
113
 
unsigned int is_mali_pmu_present = 0;
114
 
#endif /* MALI_POWER_MGMT_TEST_SUITE */
115
 
 
116
 
/* Function prototypes */
117
 
static int mali_pm_probe(struct platform_device *pdev);
118
 
static int mali_pm_remove(struct platform_device *pdev);
119
 
 
120
 
/* Mali device suspend function */
121
 
static int mali_pm_suspend(struct device *dev);
122
 
 
123
 
/* Mali device resume function */
124
 
static int mali_pm_resume(struct device *dev);
125
 
 
126
 
/* Run time suspend and resume functions */
127
 
#ifdef CONFIG_PM_RUNTIME
128
 
#if MALI_PMM_RUNTIME_JOB_CONTROL_ON
129
 
static int mali_device_runtime_suspend(struct device *dev);
130
 
static int mali_device_runtime_resume(struct device *dev);
131
 
#endif /* MALI_PMM_RUNTIME_JOB_CONTROL_ON */
132
 
#endif /* CONFIG_PM_RUNTIME */
133
 
 
134
 
/* OS suspend and resume callbacks */
135
 
#if !MALI_PMM_RUNTIME_JOB_CONTROL_ON
136
 
#ifndef CONFIG_PM_RUNTIME
137
 
#if (LINUX_VERSION_CODE < KERNEL_VERSION(LINUX_KERNEL_MAJOR_VERSION,LINUX_KERNEL_MINOR_VERSION,LINUX_KERNEL_DEVELOPMENT_VERSION))
138
 
static int mali_pm_os_suspend(struct platform_device *pdev, pm_message_t state);
139
 
#else
140
 
static int mali_pm_os_suspend(struct device *dev);
141
 
#endif
142
 
 
143
 
#if (LINUX_VERSION_CODE < KERNEL_VERSION(LINUX_KERNEL_MAJOR_VERSION,LINUX_KERNEL_MINOR_VERSION,LINUX_KERNEL_DEVELOPMENT_VERSION))
144
 
static int mali_pm_os_resume(struct platform_device *pdev);
145
 
#else
146
 
static int mali_pm_os_resume(struct device *dev);
147
 
#endif
148
 
#endif /* CONFIG_PM_RUNTIME */
149
 
#endif /* MALI_PMM_RUNTIME_JOB_CONTROL_ON */
150
 
 
151
 
/* OS Hibernation suspend callback */
152
 
static int mali_pm_os_suspend_on_hibernation(struct device *dev);
153
 
 
154
 
/* OS Hibernation resume callback */
155
 
static int mali_pm_os_resume_on_hibernation(struct device *dev);
156
 
 
157
 
static void _mali_release_pm(struct device* device);
158
 
 
159
 
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(LINUX_KERNEL_MAJOR_VERSION,LINUX_KERNEL_MINOR_VERSION,LINUX_KERNEL_DEVELOPMENT_VERSION))
160
 
static const struct dev_pm_ops mali_dev_pm_ops = {
161
 
 
162
 
#ifdef CONFIG_PM_RUNTIME
163
 
#if MALI_PMM_RUNTIME_JOB_CONTROL_ON
164
 
        .runtime_suspend = mali_device_runtime_suspend,
165
 
        .runtime_resume = mali_device_runtime_resume,
166
 
#endif  /* MALI_PMM_RUNTIME_JOB_CONTROL_ON */
167
 
#endif  /* CONFIG_PM_RUNTIME */
168
 
 
169
 
#ifndef CONFIG_PM_RUNTIME
170
 
#if !MALI_PMM_RUNTIME_JOB_CONTROL_ON
171
 
        .suspend = mali_pm_os_suspend,
172
 
        .resume = mali_pm_os_resume,
173
 
#endif /* MALI_PMM_RUNTIME_JOB_CONTROL_ON */
174
 
#endif /* CONFIG_PM_RUNTIME */
175
 
        .freeze = mali_pm_os_suspend_on_hibernation,
176
 
        .poweroff = mali_pm_os_suspend_on_hibernation,
177
 
        .thaw = mali_pm_os_resume_on_hibernation,
178
 
        .restore = mali_pm_os_resume_on_hibernation,
179
 
};
180
 
#endif
181
 
 
182
 
#if (LINUX_VERSION_CODE < KERNEL_VERSION(LINUX_KERNEL_MAJOR_VERSION,LINUX_KERNEL_MINOR_VERSION,LINUX_KERNEL_DEVELOPMENT_VERSION))
183
 
struct pm_ext_ops mali_pm_operations = {
184
 
        .base = {
185
 
                .freeze = mali_pm_os_suspend_on_hibernation,
186
 
                .thaw =   mali_pm_os_resume_on_hibernation,
187
 
                .poweroff = mali_pm_os_resume_on_hibernation,
188
 
                .restore = mali_pm_os_resume_on_hibernation,
 
30
#include "mali_pm.h"
 
31
#include "mali_platform.h"
 
32
 
 
33
#if ! MALI_LICENSE_IS_GPL
 
34
#undef CONFIG_PM_RUNTIME
 
35
#endif
 
36
 
 
37
static int mali_probe(struct platform_device *pdev);
 
38
static int mali_remove(struct platform_device *pdev);
 
39
 
 
40
#ifdef CONFIG_PM_RUNTIME
 
41
static int mali_runtime_suspend(struct device *dev);
 
42
static int mali_runtime_resume(struct device *dev);
 
43
#endif
 
44
 
 
45
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29))
 
46
static int mali_os_suspend(struct platform_device *pdev, pm_message_t state);
 
47
static int mali_os_resume(struct platform_device *pdev);
 
48
#else
 
49
static int mali_os_suspend(struct device *dev);
 
50
static int mali_os_resume(struct device *dev);
 
51
#endif
 
52
 
 
53
 
 
54
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29))
 
55
static const struct dev_pm_ops mali_dev_pm_ops =
 
56
{
 
57
#ifdef CONFIG_PM_RUNTIME
 
58
        .runtime_suspend = mali_runtime_suspend,
 
59
        .runtime_resume = mali_runtime_resume,
 
60
        .runtime_idle = NULL,
 
61
#else
 
62
        .suspend = mali_os_suspend,
 
63
        .resume = mali_os_resume,
 
64
#endif
 
65
 
 
66
        .freeze = mali_os_suspend,
 
67
        .poweroff = mali_os_suspend,
 
68
        .thaw = mali_os_resume,
 
69
        .restore = mali_os_resume,
 
70
};
 
71
#elif (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29))
 
72
struct pm_ext_ops mali_ext_pm_operations =
 
73
{
 
74
        .base =
 
75
        {
 
76
                .freeze = mali_os_suspend,
 
77
                .thaw =   mali_os_resume,
 
78
                .poweroff = mali_os_suspend,
 
79
                .restore = mali_os_resume,
189
80
        },
190
81
};
191
82
#endif
192
83
 
193
 
static struct platform_driver mali_plat_driver = {
194
 
        .probe  = mali_pm_probe,
195
 
        .remove = mali_pm_remove,
196
 
#if (LINUX_VERSION_CODE < KERNEL_VERSION(LINUX_KERNEL_MAJOR_VERSION,LINUX_KERNEL_MINOR_VERSION,LINUX_KERNEL_DEVELOPMENT_VERSION))
197
 
#ifndef CONFIG_PM_RUNTIME
198
 
#if !MALI_PMM_RUNTIME_JOB_CONTROL_ON
199
 
        .suspend = mali_pm_os_suspend,
200
 
        .resume  = mali_pm_os_resume,
201
 
#endif /* CONFIG_PM_RUNTIME */
202
 
#endif /* MALI_PMM_RUNTIME_JOB_CONTROL_ON */
203
 
        .pm = &mali_pm_operations,
 
84
 
 
85
static struct platform_driver mali_plat_driver =
 
86
{
 
87
        .probe  = mali_probe,
 
88
        .remove = mali_remove,
 
89
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29))
 
90
        .suspend = mali_os_suspend,
 
91
        .resume  = mali_os_resume,
 
92
        .pm = &mali_ext_pm_operations,
204
93
#endif
205
94
 
206
 
        .driver         = {
 
95
        .driver =
 
96
        {
207
97
                .name   = "mali_dev",
208
98
                .owner  = THIS_MODULE,
 
99
#if MALI_LICENSE_IS_GPL
209
100
                .bus = &platform_bus_type,
210
 
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(LINUX_KERNEL_MAJOR_VERSION,LINUX_KERNEL_MINOR_VERSION,LINUX_KERNEL_DEVELOPMENT_VERSION))
 
101
#endif
 
102
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29))
211
103
                .pm = &mali_dev_pm_ops,
212
104
#endif
213
 
                },
214
 
};
215
 
 
216
 
/* Mali GPU platform device */
217
 
struct platform_device mali_gpu_device = {
 
105
        },
 
106
};
 
107
 
 
108
#ifdef CONFIG_PM_RUNTIME
 
109
static int mali_pwr_suspend_notifier(struct notifier_block *nb,unsigned long event,void* dummy);
 
110
 
 
111
static struct notifier_block mali_pwr_notif_block =
 
112
{
 
113
        .notifier_call = mali_pwr_suspend_notifier
 
114
};
 
115
#endif
 
116
 
 
117
/** This function is called when platform device is unregistered. This function
 
118
 * is necessary when the platform device is unregistered.
 
119
 */
 
120
static void _mali_release_pm(struct device *device)
 
121
{
 
122
}
 
123
struct platform_device mali_gpu_device =
 
124
{
218
125
        .name = "mali_dev",
219
126
        .id = 0,
220
127
        .dev.release = _mali_release_pm
221
128
};
222
129
 
223
 
/** This function is called when platform device is unregistered. This function
224
 
 * is necessary when the platform device is unregistered.
225
 
 */
226
 
static void _mali_release_pm(struct device *device)
227
 
{
228
 
        MALI_DEBUG_PRINT(4, ("OSPMM: MALI Platform device removed\n" ));
229
 
}
230
 
 
231
 
#if MALI_POWER_MGMT_TEST_SUITE
232
 
void mali_is_pmu_present(void)
233
 
{
234
 
        int temp = 0;
235
 
        temp = pmu_get_power_up_down_info();
236
 
        if (4095 == temp)
237
 
        {
238
 
                is_mali_pmu_present = 0;
239
 
        }
240
 
        else
241
 
        {
242
 
                is_mali_pmu_present = 1;
243
 
        }
244
 
}
245
 
#endif /* MALI_POWER_MGMT_TEST_SUITE */
246
 
#endif /* MALI_LICENSE_IS_GPL */
247
 
 
248
 
#if MALI_LICENSE_IS_GPL
249
 
 
250
 
static int mali_wait_for_power_management_policy_event(void)
251
 
{
252
 
        int err = 0;
253
 
        for (; ;)
254
 
        {
255
 
                set_current_state(TASK_INTERRUPTIBLE);
256
 
                if (signal_pending(current))
257
 
                {
258
 
                        err = -EINTR;
259
 
                        break;
260
 
                }
261
 
                if (is_wake_up_needed == 1)
262
 
                {
263
 
                        break;
264
 
                }
265
 
                schedule();
266
 
        }
267
 
        __set_current_state(TASK_RUNNING);
268
 
        is_wake_up_needed =0;
269
 
        return err;
270
 
}
271
 
 
272
 
/** This function is invoked when mali device is suspended
273
 
 */
274
 
int mali_device_suspend(unsigned int event_id, struct task_struct **pwr_mgmt_thread)
275
 
{
276
 
        int err = 0;    
277
 
        _mali_uk_pmm_message_s event = {
278
 
                                       NULL,
279
 
                                       event_id,
280
 
                                       timeout_fired};
281
 
        *pwr_mgmt_thread = current;
282
 
        MALI_DEBUG_PRINT(4, ("OSPMM: MALI device is being suspended\n" ));
283
 
        _mali_ukk_pmm_event_message(&event);
284
 
        is_os_pmm_thread_waiting = 1;
285
 
        err = mali_wait_for_power_management_policy_event();
286
 
        is_os_pmm_thread_waiting = 0;
287
 
        return err;
288
 
}
289
 
 
290
 
/** This function is called when Operating system wants to power down
291
 
 * the mali GPU device.
292
 
 */
293
 
static int mali_pm_suspend(struct device *dev)
294
 
{
295
 
        int err = 0;
296
 
        _mali_osk_lock_wait(lock, _MALI_OSK_LOCKMODE_RW);
297
 
#if MALI_GPU_UTILIZATION
298
 
        mali_utilization_suspend();
299
 
#endif /* MALI_GPU_UTILIZATION */
300
 
        if ((mali_device_state == _MALI_DEVICE_SUSPEND))
301
 
        {
302
 
                _mali_osk_lock_signal(lock, _MALI_OSK_LOCKMODE_RW);
303
 
                return err;
304
 
        }
305
 
        err = mali_device_suspend(MALI_PMM_EVENT_OS_POWER_DOWN, &pm_thread);
306
 
        mali_device_state = _MALI_DEVICE_SUSPEND;
307
 
        _mali_osk_lock_signal(lock, _MALI_OSK_LOCKMODE_RW);
308
 
        return err;
309
 
}
310
 
 
311
 
#ifndef CONFIG_PM_RUNTIME
312
 
#if !MALI_PMM_RUNTIME_JOB_CONTROL_ON
313
 
#if (LINUX_VERSION_CODE < KERNEL_VERSION(LINUX_KERNEL_MAJOR_VERSION,LINUX_KERNEL_MINOR_VERSION,LINUX_KERNEL_DEVELOPMENT_VERSION))
314
 
static int mali_pm_os_suspend(struct platform_device *pdev, pm_message_t state)
315
 
#else
316
 
static int mali_pm_os_suspend(struct device *dev)
 
130
/** This function is called when the device is probed */
 
131
static int mali_probe(struct platform_device *pdev)
 
132
{
 
133
        return 0;
 
134
}
 
135
 
 
136
static int mali_remove(struct platform_device *pdev)
 
137
{
 
138
#ifdef CONFIG_PM_RUNTIME
 
139
        pm_runtime_disable(&pdev->dev);
317
140
#endif
318
 
{
319
 
        int err = 0;
320
 
        err = mali_pm_suspend(NULL);
321
 
        return err;
 
141
        return 0;
322
142
}
323
 
#endif /* MALI_PMM_RUNTIME_JOB_CONTROL_ON */
324
 
#endif /* CONFIG_PM_RUNTIME */
325
143
 
326
144
#ifdef CONFIG_PM_RUNTIME
327
 
#if MALI_PMM_RUNTIME_JOB_CONTROL_ON
328
145
static int mali_pwr_suspend_notifier(struct notifier_block *nb,unsigned long event,void* dummy)
329
146
{
330
 
        int err = 0;
331
147
        switch (event)
332
148
        {
333
149
                case PM_SUSPEND_PREPARE:
334
 
                        err = mali_pm_suspend(NULL);
335
 
                break;
336
 
 
 
150
                        MALI_DEBUG_PRINT(2, ("mali_pwr_suspend_notifier(PM_SUSPEND_PREPARE) called\n"));
 
151
                        mali_pm_os_suspend();
 
152
                        break;
337
153
                case PM_POST_SUSPEND:
338
 
                        err = mali_pm_resume(NULL);
339
 
                break;
 
154
                        MALI_DEBUG_PRINT(2, ("mali_pwr_suspend_notifier(PM_SUSPEND_PREPARE) called\n"));
 
155
                        mali_pm_os_resume();
 
156
                        break;
340
157
                default:
341
 
                break;
342
 
        }
343
 
        return 0;
344
 
}
345
 
#endif /* MALI_PMM_RUNTIME_JOB_CONTROL_ON */
346
 
#endif /* CONFIG_PM_RUNTIME */
347
 
 
348
 
/** This function is called when mali GPU device is to be resumed.
349
 
 */
350
 
int mali_device_resume(unsigned int event_id, struct task_struct **pwr_mgmt_thread)
351
 
{
352
 
        int err = 0;
353
 
        _mali_uk_pmm_message_s event = {
354
 
                                       NULL,
355
 
                                       event_id,
356
 
                                       timeout_fired};
357
 
        *pwr_mgmt_thread = current;
358
 
        MALI_DEBUG_PRINT(4, ("OSPMM: MALI device is being resumed\n" ));
359
 
        _mali_ukk_pmm_event_message(&event);
360
 
        MALI_DEBUG_PRINT(4, ("OSPMM: MALI Power up  event is scheduled\n" ));
361
 
        is_os_pmm_thread_waiting = 1;
362
 
        err = mali_wait_for_power_management_policy_event();
363
 
        is_os_pmm_thread_waiting = 0;
364
 
        return err;
365
 
}
366
 
 
367
 
/** This function is called when mali GPU device is to be resumed
368
 
 */
369
 
 
370
 
static int mali_pm_resume(struct device *dev)
371
 
{
372
 
        int err = 0;
373
 
        _mali_osk_lock_wait(lock, _MALI_OSK_LOCKMODE_RW);
374
 
        if (mali_device_state == _MALI_DEVICE_RESUME)
375
 
        {
376
 
                _mali_osk_lock_signal(lock, _MALI_OSK_LOCKMODE_RW);
377
 
                return err;
378
 
        }
379
 
        err = mali_device_resume(MALI_PMM_EVENT_OS_POWER_UP, &pm_thread);
380
 
        mali_device_state = _MALI_DEVICE_RESUME;
381
 
        mali_dvfs_device_state = _MALI_DEVICE_RESUME;
382
 
        _mali_osk_lock_signal(lock, _MALI_OSK_LOCKMODE_RW);
383
 
        return err;
384
 
}
385
 
 
386
 
#ifndef CONFIG_PM_RUNTIME
387
 
#if !MALI_PMM_RUNTIME_JOB_CONTROL_ON
388
 
#if (LINUX_VERSION_CODE < KERNEL_VERSION(LINUX_KERNEL_MAJOR_VERSION,LINUX_KERNEL_MINOR_VERSION,LINUX_KERNEL_DEVELOPMENT_VERSION))
389
 
static int mali_pm_os_resume(struct platform_device *pdev)
390
 
#else
391
 
static int mali_pm_os_resume(struct device *dev)
392
 
#endif
393
 
{
394
 
        int err = 0;
395
 
        err = mali_pm_resume(NULL);
396
 
        return err;
397
 
}
398
 
#endif /* MALI_PMM_RUNTIME_JOB_CONTROL_ON */
399
 
#endif /* CONFIG_PM_RUNTIME */
400
 
 
401
 
static int mali_pm_os_suspend_on_hibernation(struct device *dev)
402
 
{
403
 
        int err = 0;
404
 
        err = mali_pm_suspend(NULL);
405
 
        return err;
406
 
}
407
 
 
408
 
static int mali_pm_os_resume_on_hibernation(struct device *dev)
409
 
{
410
 
        int err = 0;
411
 
        err = mali_pm_resume(NULL);
412
 
        return err;
413
 
}
414
 
 
415
 
#ifdef CONFIG_PM_RUNTIME
416
 
#if MALI_PMM_RUNTIME_JOB_CONTROL_ON
417
 
/** This function is called when runtime suspend of mali device is required.
418
 
 */
419
 
static int mali_device_runtime_suspend(struct device *dev)
420
 
{
421
 
        MALI_DEBUG_PRINT(4, ("PMMDEBUG: Mali device Run time suspended \n" ));
422
 
        return 0;
423
 
}
424
 
 
425
 
/** This function is called when runtime resume of mali device is required.
426
 
 */
427
 
static int mali_device_runtime_resume(struct device *dev)
428
 
{
429
 
        MALI_DEBUG_PRINT(4, ("PMMDEBUG: Mali device Run time Resumed \n" ));
430
 
        return 0;
431
 
}
432
 
#endif /* MALI_PMM_RUNTIME_JOB_CONTROL_ON */
433
 
#endif /*  CONFIG_PM_RUNTIME */
434
 
 
435
 
#ifdef CONFIG_PM_DEBUG
436
 
 
437
 
/** This function is used for debugging purposes when the user want to see
438
 
 * which power management operations are supported for
439
 
 * mali device.
440
 
 */
441
 
static ssize_t show_file(struct device *dev, struct device_attribute *attr, char *buf)
442
 
{
443
 
        char *str = buf;
444
 
#if !MALI_POWER_MGMT_TEST_SUITE
445
 
        int pm_counter = 0;
446
 
        for (pm_counter = 0; pm_counter<_MALI_MAX_DEBUG_OPERATIONS; pm_counter++) 
447
 
        {
448
 
                str += sprintf(str, "%s  ", mali_states[pm_counter]);
449
 
        }
450
 
#else
451
 
        str += sprintf(str, "%d  ",pwr_mgmt_status_reg);
452
 
#endif
453
 
        if (str != buf)
454
 
        {
455
 
                *(str-1) = '\n';
456
 
        }
457
 
        return (str-buf);
458
 
}
459
 
 
460
 
/** This function is called when user wants to suspend the mali GPU device in order
461
 
 * to simulate the power up and power down events.
462
 
 */
463
 
static ssize_t store_file(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
464
 
{
465
 
        int err = 0;
466
 
 
467
 
#if MALI_POWER_MGMT_TEST_SUITE
468
 
        int test_flag_dvfs = 0;
469
 
        pwr_mgmt_status_reg = 0;
470
 
        mali_is_pmu_present();
471
 
 
472
 
#endif
473
 
        if (!strncmp(buf,mali_states[_MALI_DEVICE_SUSPEND],strlen(mali_states[_MALI_DEVICE_SUSPEND])))
474
 
        {
475
 
                MALI_DEBUG_PRINT(4, ("PMMDEBUG: MALI suspend Power operation is scheduled\n" ));
476
 
                err = mali_pm_suspend(NULL);
477
 
        }
478
 
 
479
 
#if MALI_POWER_MGMT_TEST_SUITE
480
 
        else if (!strncmp(buf,mali_pmm_recording_events[_MALI_DEVICE_PMM_REGISTERED_CORES],strlen(mali_pmm_recording_events[_MALI_DEVICE_PMM_REGISTERED_CORES])))
481
 
        {
482
 
                MALI_DEBUG_PRINT(4, ("PMMDEBUG: MALI Device get number of registerd cores\n" ));
483
 
                pwr_mgmt_status_reg = _mali_pmm_cores_list();
484
 
                return count;
485
 
        }
486
 
        else if (!strncmp(buf,mali_pmm_recording_events[_MALI_DEVICE_PMM_TIMEOUT_EVENT],strlen(mali_pmm_recording_events[_MALI_DEVICE_PMM_TIMEOUT_EVENT])))
487
 
        {
488
 
                MALI_DEBUG_PRINT(4, ("PMMDEBUG: MALI timeout event recording is enabled\n" ));
489
 
                mali_timeout_event_recording_on = 1;
490
 
        }
491
 
        else if (!strncmp(buf,mali_pmm_recording_events[_MALI_DEVICE_PMM_JOB_SCHEDULING_EVENTS],strlen(mali_pmm_recording_events[_MALI_DEVICE_PMM_JOB_SCHEDULING_EVENTS])))
492
 
        {
493
 
                MALI_DEBUG_PRINT(4, ("PMMDEBUG: MALI Job scheduling  events recording is enabled\n" ));
494
 
                mali_job_scheduling_events_recording_on = 1;
495
 
        }
496
 
#endif /* MALI_POWER_MGMT_TEST_SUITE */
497
 
 
498
 
        else if (!strncmp(buf,mali_states[_MALI_DEVICE_RESUME],strlen(mali_states[_MALI_DEVICE_RESUME]))) 
499
 
        {
500
 
                MALI_DEBUG_PRINT(4, ("PMMDEBUG: MALI Resume Power operation is scheduled\n" ));
501
 
                err = mali_pm_resume(NULL);
502
 
        }
503
 
        else if (!strncmp(buf,mali_states[_MALI_DVFS_PAUSE_EVENT],strlen(mali_states[_MALI_DVFS_PAUSE_EVENT])))
504
 
        {
505
 
                MALI_DEBUG_PRINT(4, ("PMMDEBUG: MALI DVFS Pause Power operation is scheduled\n" ));
506
 
                err = mali_dev_pause();
507
 
#if MALI_POWER_MGMT_TEST_SUITE
508
 
                test_flag_dvfs = 1;
509
 
#endif /* MALI_POWER_MGMT_TEST_SUITE */
510
 
        }
511
 
        else if (!strncmp(buf,mali_states[_MALI_DVFS_RESUME_EVENT],strlen(mali_states[_MALI_DVFS_RESUME_EVENT])))
512
 
        {
513
 
                MALI_DEBUG_PRINT(4, ("PMMDEBUG: MALI DVFS Resume Power operation is scheduled\n" ));
514
 
                err = mali_dev_resume();
515
 
#if MALI_POWER_MGMT_TEST_SUITE
516
 
                test_flag_dvfs = 1;
517
 
#endif /* MALI_POWER_MGMT_TEST_SUITE */
518
 
        }
519
 
        else 
520
 
        {
521
 
                MALI_DEBUG_PRINT(4, ("PMMDEBUG: Invalid Power Mode Operation selected\n" ));
522
 
        }
523
 
#if MALI_POWER_MGMT_TEST_SUITE
524
 
        if (test_flag_dvfs == 1)
525
 
        {
526
 
                if (err)
527
 
                {
528
 
                        pwr_mgmt_status_reg = 2;
529
 
                }
530
 
                else
531
 
                {
532
 
                        pwr_mgmt_status_reg = 1;
533
 
                }
534
 
        }
535
 
        else
536
 
        {
537
 
                if (1 == is_mali_pmu_present)
538
 
                {
539
 
                        pwr_mgmt_status_reg = pmu_get_power_up_down_info();
540
 
                }
541
 
        }
542
 
#endif /* MALI_POWER_MGMT_TEST_SUITE */
543
 
        return count;
544
 
}
545
 
 
546
 
/* Device attribute file */
547
 
static DEVICE_ATTR(file, 0644, show_file, store_file);
548
 
#endif /* CONFIG_PM_DEBUG */
549
 
 
550
 
static int mali_pm_remove(struct platform_device *pdev)
551
 
{
552
 
#ifdef CONFIG_PM_DEBUG
553
 
        device_remove_file(&mali_gpu_device.dev, &dev_attr_file);
554
 
#endif /* CONFIG_PM_DEBUG */
555
 
#ifdef CONFIG_PM_RUNTIME
556
 
#if MALI_PMM_RUNTIME_JOB_CONTROL_ON
557
 
        pm_runtime_disable(&pdev->dev);
558
 
#endif /* MALI_PMM_RUNTIME_JOB_CONTROL_ON */
559
 
#endif /* CONFIG_PM_RUNTIME */
560
 
        return 0;
561
 
}
562
 
 
563
 
/** This function is called when the device is probed */
564
 
static int mali_pm_probe(struct platform_device *pdev)
565
 
{
566
 
#ifdef CONFIG_PM_DEBUG
567
 
        int err;
568
 
        err = device_create_file(&mali_gpu_device.dev, &dev_attr_file);
569
 
        if (err)
570
 
        {
571
 
                MALI_DEBUG_PRINT(4, ("PMMDEBUG: Error in creating device file\n" ));
572
 
        }
573
 
#endif /* CONFIG_PM_DEBUG */
574
 
        return 0;
575
 
}
 
158
                        break;
 
159
        }
 
160
        return 0;
 
161
}
 
162
#endif
 
163
 
 
164
 
 
165
#ifdef CONFIG_PM_RUNTIME
 
166
 
 
167
static int mali_runtime_suspend(struct device *dev)
 
168
{
 
169
        MALI_DEBUG_PRINT(3, ("mali_runtime_suspend() called\n"));
 
170
        mali_pm_runtime_suspend();
 
171
        return 0; /* all ok */
 
172
}
 
173
 
 
174
static int mali_runtime_resume(struct device *dev)
 
175
{
 
176
        MALI_DEBUG_PRINT(3, ("mali_runtime_resume() called\n"));
 
177
        mali_pm_runtime_resume();
 
178
        return 0; /* all ok */
 
179
}
 
180
 
 
181
#endif
 
182
 
 
183
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29))
 
184
 
 
185
static int mali_os_suspend(struct platform_device *pdev, pm_message_t state)
 
186
{
 
187
        MALI_DEBUG_PRINT(3, ("mali_os_suspend(old) called\n"));
 
188
        mali_pm_os_suspend();
 
189
        return 0; /* all ok */
 
190
}
 
191
 
 
192
static int mali_os_resume(struct platform_device *pdev)
 
193
{
 
194
        MALI_DEBUG_PRINT(3, ("mali_os_resume(old) called\n"));
 
195
        mali_pm_os_resume();
 
196
        return 0; /* all ok */
 
197
}
 
198
 
 
199
#else
 
200
 
 
201
static int mali_os_suspend(struct device *dev)
 
202
{
 
203
        MALI_DEBUG_PRINT(3, ("mali_os_suspend(new) called\n"));
 
204
        mali_pm_os_suspend();
 
205
        return 0; /* all ok */
 
206
}
 
207
 
 
208
static int mali_os_resume(struct device *dev)
 
209
{
 
210
        MALI_DEBUG_PRINT(3, ("mali_os_resume(new) called\n"));
 
211
        mali_pm_os_resume();
 
212
        return 0; /* all ok */
 
213
}
 
214
 
 
215
#endif
576
216
 
577
217
/** This function is called when Mali GPU device is initialized
578
218
 */
579
219
int _mali_dev_platform_register(void)
580
220
{
581
221
        int err;
582
 
#if MALI_PMM_RUNTIME_JOB_CONTROL_ON     
 
222
 
 
223
#ifdef CONFIG_PM_RUNTIME
583
224
        set_mali_parent_power_domain((void *)&mali_gpu_device);
584
225
#endif
585
226
 
586
227
#ifdef CONFIG_PM_RUNTIME
587
 
#if MALI_PMM_RUNTIME_JOB_CONTROL_ON
588
228
        err = register_pm_notifier(&mali_pwr_notif_block);
589
229
        if (err)
590
230
        {
591
231
                return err;
592
232
        }
593
 
#endif /* MALI_PMM_RUNTIME_JOB_CONTROL_ON */
594
 
#endif /* CONFIG_PM_RUNTIME */
 
233
#endif
 
234
 
 
235
#if MALI_LICENSE_IS_GPL
595
236
        err = platform_device_register(&mali_gpu_device);
596
 
        lock = _mali_osk_lock_init((_mali_osk_lock_flags_t)( _MALI_OSK_LOCKFLAG_READERWRITER | _MALI_OSK_LOCKFLAG_ORDERED), 0, 0);
597
237
        if (!err) 
598
238
        {
599
239
                err = platform_driver_register(&mali_plat_driver);
600
240
                if (err)
601
241
                {
602
 
                        _mali_osk_lock_term(lock);
603
242
#ifdef CONFIG_PM_RUNTIME
604
 
#if MALI_PMM_RUNTIME_JOB_CONTROL_ON
605
243
                        unregister_pm_notifier(&mali_pwr_notif_block);
606
 
#endif /* MALI_PMM_RUNTIME_JOB_CONTROL_ON */
607
 
#endif /* CONFIG_PM_RUNTIME */
 
244
#endif
608
245
                        platform_device_unregister(&mali_gpu_device);
609
246
                }
610
247
        }
 
248
#endif
 
249
 
611
250
        return err;
612
251
}
613
252
 
615
254
 */
616
255
void _mali_dev_platform_unregister(void)
617
256
{
618
 
        _mali_osk_lock_term(lock);
619
 
 
620
257
#ifdef CONFIG_PM_RUNTIME
621
 
#if MALI_PMM_RUNTIME_JOB_CONTROL_ON
622
258
        unregister_pm_notifier(&mali_pwr_notif_block);
623
 
#endif /* MALI_PMM_RUNTIME_JOB_CONTROL_ON */
624
 
#endif /* CONFIG_PM_RUNTIME */
 
259
#endif
625
260
 
 
261
#if MALI_LICENSE_IS_GPL
626
262
        platform_driver_unregister(&mali_plat_driver);
627
263
        platform_device_unregister(&mali_gpu_device);
628
 
}
629
 
 
630
 
int mali_get_ospmm_thread_state(void)
631
 
{
632
 
        return is_os_pmm_thread_waiting;
633
 
}
634
 
 
635
 
#endif /* MALI_LICENSE_IS_GPL */
636
 
#endif /* CONFIG_PM */
637
 
 
638
 
#if MALI_STATE_TRACKING
639
 
u32 mali_pmm_dump_os_thread_state( char *buf, u32 size )
640
 
{
641
 
        return snprintf(buf, size, "OSPMM: OS PMM thread is waiting: %s\n", is_os_pmm_thread_waiting ? "true" : "false");
642
 
}
643
 
#endif /* MALI_STATE_TRACKING */
644
 
#endif /* USING_MALI_PMM */
 
264
#endif
 
265
}