~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to drivers/gpu/pvr/power.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**********************************************************************
 
2
 *
 
3
 * Copyright (C) Imagination Technologies Ltd. All rights reserved.
 
4
 * 
 
5
 * This program is free software; you can redistribute it and/or modify it
 
6
 * under the terms and conditions of the GNU General Public License,
 
7
 * version 2, as published by the Free Software Foundation.
 
8
 * 
 
9
 * This program is distributed in the hope it will be useful but, except 
 
10
 * as otherwise stated in writing, without any warranty; without even the 
 
11
 * implied warranty of merchantability or fitness for a particular purpose. 
 
12
 * See the GNU General Public License for more details.
 
13
 * 
 
14
 * You should have received a copy of the GNU General Public License along with
 
15
 * this program; if not, write to the Free Software Foundation, Inc.,
 
16
 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
 
17
 * 
 
18
 * The full GNU General Public License is included in this distribution in
 
19
 * the file called "COPYING".
 
20
 *
 
21
 * Contact Information:
 
22
 * Imagination Technologies Ltd. <gpl-support@imgtec.com>
 
23
 * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK 
 
24
 *
 
25
 ******************************************************************************/
 
26
 
 
27
#include "services_headers.h"
 
28
#include "pdump_km.h"
 
29
 
 
30
#include "lists.h"
 
31
 
 
32
static IMG_BOOL gbInitServerRunning = IMG_FALSE;
 
33
static IMG_BOOL gbInitServerRan = IMG_FALSE;
 
34
static IMG_BOOL gbInitSuccessful = IMG_FALSE;
 
35
 
 
36
IMG_EXPORT
 
37
PVRSRV_ERROR PVRSRVSetInitServerState(PVRSRV_INIT_SERVER_STATE eInitServerState, IMG_BOOL bState)
 
38
{
 
39
 
 
40
        switch(eInitServerState)
 
41
        {
 
42
                case PVRSRV_INIT_SERVER_RUNNING:
 
43
                        gbInitServerRunning     = bState;
 
44
                        break;
 
45
                case PVRSRV_INIT_SERVER_RAN:
 
46
                        gbInitServerRan = bState;
 
47
                        break;
 
48
                case PVRSRV_INIT_SERVER_SUCCESSFUL:
 
49
                        gbInitSuccessful = bState;
 
50
                        break;
 
51
                default:
 
52
                        PVR_DPF((PVR_DBG_ERROR,
 
53
                                "PVRSRVSetInitServerState : Unknown state %x", eInitServerState));
 
54
                        return PVRSRV_ERROR_UNKNOWN_INIT_SERVER_STATE;
 
55
        }
 
56
 
 
57
        return PVRSRV_OK;
 
58
}
 
59
 
 
60
IMG_EXPORT
 
61
IMG_BOOL PVRSRVGetInitServerState(PVRSRV_INIT_SERVER_STATE eInitServerState)
 
62
{
 
63
        IMG_BOOL        bReturnVal;
 
64
 
 
65
        switch(eInitServerState)
 
66
        {
 
67
                case PVRSRV_INIT_SERVER_RUNNING:
 
68
                        bReturnVal = gbInitServerRunning;
 
69
                        break;
 
70
                case PVRSRV_INIT_SERVER_RAN:
 
71
                        bReturnVal = gbInitServerRan;
 
72
                        break;
 
73
                case PVRSRV_INIT_SERVER_SUCCESSFUL:
 
74
                        bReturnVal = gbInitSuccessful;
 
75
                        break;
 
76
                default:
 
77
                        PVR_DPF((PVR_DBG_ERROR,
 
78
                                "PVRSRVGetInitServerState : Unknown state %x", eInitServerState));
 
79
                        bReturnVal = IMG_FALSE;
 
80
        }
 
81
 
 
82
        return bReturnVal;
 
83
}
 
84
 
 
85
static IMG_BOOL _IsSystemStatePowered(PVRSRV_SYS_POWER_STATE eSystemPowerState)
 
86
{
 
87
        return (IMG_BOOL)(eSystemPowerState < PVRSRV_SYS_POWER_STATE_D2);
 
88
}
 
89
 
 
90
 
 
91
IMG_EXPORT
 
92
PVRSRV_ERROR PVRSRVPowerLock(IMG_UINT32 ui32CallerID,
 
93
                                                         IMG_BOOL       bSystemPowerEvent)
 
94
{
 
95
        PVRSRV_ERROR    eError;
 
96
        SYS_DATA                *psSysData;
 
97
        IMG_UINT32              ui32Timeout = 1000000;
 
98
 
 
99
        SysAcquireData(&psSysData);
 
100
 
 
101
        eError = OSPowerLockWrap();
 
102
        if (eError != PVRSRV_OK)
 
103
        {
 
104
                return eError;
 
105
        }
 
106
 
 
107
        do
 
108
        {
 
109
                eError = OSLockResource(&psSysData->sPowerStateChangeResource,
 
110
                                                                ui32CallerID);
 
111
                if (eError == PVRSRV_OK)
 
112
                {
 
113
                        break;
 
114
                }
 
115
                else if (ui32CallerID == ISR_ID)
 
116
                {
 
117
                        
 
118
 
 
119
                        eError = PVRSRV_ERROR_RETRY;
 
120
                        break;
 
121
                }
 
122
 
 
123
                OSWaitus(1);
 
124
                ui32Timeout--;
 
125
        } while (ui32Timeout > 0);
 
126
 
 
127
        if (eError != PVRSRV_OK)
 
128
        {
 
129
                OSPowerLockUnwrap();
 
130
        }
 
131
 
 
132
         
 
133
        if ((eError == PVRSRV_OK) &&
 
134
                !bSystemPowerEvent &&
 
135
                !_IsSystemStatePowered(psSysData->eCurrentPowerState))
 
136
        {
 
137
                
 
138
                PVRSRVPowerUnlock(ui32CallerID);
 
139
                eError = PVRSRV_ERROR_RETRY;
 
140
        }
 
141
 
 
142
        return eError;
 
143
}
 
144
 
 
145
 
 
146
IMG_EXPORT
 
147
IMG_VOID PVRSRVPowerUnlock(IMG_UINT32   ui32CallerID)
 
148
{
 
149
        OSUnlockResource(&gpsSysData->sPowerStateChangeResource, ui32CallerID);
 
150
        OSPowerLockUnwrap();
 
151
}
 
152
 
 
153
 
 
154
static PVRSRV_ERROR PVRSRVDevicePrePowerStateKM_AnyVaCb(PVRSRV_POWER_DEV *psPowerDevice, va_list va)
 
155
{
 
156
        PVRSRV_DEV_POWER_STATE  eNewDevicePowerState;
 
157
        PVRSRV_ERROR                    eError;
 
158
 
 
159
        
 
160
        IMG_BOOL                                bAllDevices;
 
161
        IMG_UINT32                              ui32DeviceIndex;
 
162
        PVRSRV_DEV_POWER_STATE  eNewPowerState;
 
163
 
 
164
        
 
165
        bAllDevices = va_arg(va, IMG_BOOL);
 
166
        ui32DeviceIndex = va_arg(va, IMG_UINT32);
 
167
        eNewPowerState = va_arg(va, PVRSRV_DEV_POWER_STATE);
 
168
 
 
169
        if (bAllDevices || (ui32DeviceIndex == psPowerDevice->ui32DeviceIndex))
 
170
        {
 
171
                eNewDevicePowerState = (eNewPowerState == PVRSRV_DEV_POWER_STATE_DEFAULT) ?
 
172
                                                        psPowerDevice->eDefaultPowerState : eNewPowerState;
 
173
 
 
174
                if (psPowerDevice->eCurrentPowerState != eNewDevicePowerState)
 
175
                {
 
176
                        if (psPowerDevice->pfnPrePower != IMG_NULL)
 
177
                        {
 
178
                                
 
179
                                eError = psPowerDevice->pfnPrePower(psPowerDevice->hDevCookie,
 
180
                                                                                                        eNewDevicePowerState,
 
181
                                                                                                        psPowerDevice->eCurrentPowerState);
 
182
                                if (eError != PVRSRV_OK)
 
183
                                {
 
184
                                        return eError;
 
185
                                }
 
186
                        }
 
187
 
 
188
                        
 
189
                        eError = SysDevicePrePowerState(psPowerDevice->ui32DeviceIndex,
 
190
                                                                                        eNewDevicePowerState,
 
191
                                                                                        psPowerDevice->eCurrentPowerState);
 
192
                        if (eError != PVRSRV_OK)
 
193
                        {
 
194
                                return eError;
 
195
                        }
 
196
                }
 
197
        }
 
198
 
 
199
        return  PVRSRV_OK;
 
200
}
 
201
 
 
202
static
 
203
PVRSRV_ERROR PVRSRVDevicePrePowerStateKM(IMG_BOOL                               bAllDevices,
 
204
                                                                                 IMG_UINT32                             ui32DeviceIndex,
 
205
                                                                                 PVRSRV_DEV_POWER_STATE eNewPowerState)
 
206
{
 
207
        PVRSRV_ERROR            eError;
 
208
        SYS_DATA                        *psSysData;
 
209
 
 
210
        SysAcquireData(&psSysData);
 
211
 
 
212
        
 
213
        eError = List_PVRSRV_POWER_DEV_PVRSRV_ERROR_Any_va(psSysData->psPowerDeviceList,
 
214
                                                                                                                &PVRSRVDevicePrePowerStateKM_AnyVaCb,
 
215
                                                                                                                bAllDevices,
 
216
                                                                                                                ui32DeviceIndex,
 
217
                                                                                                                eNewPowerState);
 
218
 
 
219
        return eError;
 
220
}
 
221
 
 
222
static PVRSRV_ERROR PVRSRVDevicePostPowerStateKM_AnyVaCb(PVRSRV_POWER_DEV *psPowerDevice, va_list va)
 
223
{
 
224
        PVRSRV_DEV_POWER_STATE  eNewDevicePowerState;
 
225
        PVRSRV_ERROR                    eError;
 
226
 
 
227
        
 
228
        IMG_BOOL                                bAllDevices;
 
229
        IMG_UINT32                              ui32DeviceIndex;
 
230
        PVRSRV_DEV_POWER_STATE  eNewPowerState;
 
231
 
 
232
        
 
233
        bAllDevices = va_arg(va, IMG_BOOL);
 
234
        ui32DeviceIndex = va_arg(va, IMG_UINT32);
 
235
        eNewPowerState = va_arg(va, PVRSRV_DEV_POWER_STATE);
 
236
 
 
237
        if (bAllDevices || (ui32DeviceIndex == psPowerDevice->ui32DeviceIndex))
 
238
        {
 
239
                eNewDevicePowerState = (eNewPowerState == PVRSRV_DEV_POWER_STATE_DEFAULT) ?
 
240
                                                                psPowerDevice->eDefaultPowerState : eNewPowerState;
 
241
 
 
242
                if (psPowerDevice->eCurrentPowerState != eNewDevicePowerState)
 
243
                {
 
244
                        
 
245
                        eError = SysDevicePostPowerState(psPowerDevice->ui32DeviceIndex,
 
246
                                                                                         eNewDevicePowerState,
 
247
                                                                                         psPowerDevice->eCurrentPowerState);
 
248
                        if (eError != PVRSRV_OK)
 
249
                        {
 
250
                                return eError;
 
251
                        }
 
252
 
 
253
                        if (psPowerDevice->pfnPostPower != IMG_NULL)
 
254
                        {
 
255
                                
 
256
                                eError = psPowerDevice->pfnPostPower(psPowerDevice->hDevCookie,
 
257
                                                                                                         eNewDevicePowerState,
 
258
                                                                                                         psPowerDevice->eCurrentPowerState);
 
259
                                if (eError != PVRSRV_OK)
 
260
                                {
 
261
                                        return eError;
 
262
                                }
 
263
                        }
 
264
 
 
265
                        psPowerDevice->eCurrentPowerState = eNewDevicePowerState;
 
266
                }
 
267
        }
 
268
        return PVRSRV_OK;
 
269
}
 
270
 
 
271
static
 
272
PVRSRV_ERROR PVRSRVDevicePostPowerStateKM(IMG_BOOL                                      bAllDevices,
 
273
                                                                                  IMG_UINT32                            ui32DeviceIndex,
 
274
                                                                                  PVRSRV_DEV_POWER_STATE        eNewPowerState)
 
275
{
 
276
        PVRSRV_ERROR            eError;
 
277
        SYS_DATA                        *psSysData;
 
278
 
 
279
        SysAcquireData(&psSysData);
 
280
 
 
281
        
 
282
        eError = List_PVRSRV_POWER_DEV_PVRSRV_ERROR_Any_va(psSysData->psPowerDeviceList,
 
283
                                                                                                                &PVRSRVDevicePostPowerStateKM_AnyVaCb,
 
284
                                                                                                                bAllDevices,
 
285
                                                                                                                ui32DeviceIndex,
 
286
                                                                                                                eNewPowerState);
 
287
 
 
288
        return eError;
 
289
}
 
290
 
 
291
 
 
292
IMG_EXPORT
 
293
PVRSRV_ERROR PVRSRVSetDevicePowerStateKM(IMG_UINT32                             ui32DeviceIndex,
 
294
                                                                                 PVRSRV_DEV_POWER_STATE eNewPowerState,
 
295
                                                                                 IMG_UINT32                             ui32CallerID,
 
296
                                                                                 IMG_BOOL                               bRetainMutex)
 
297
{
 
298
        PVRSRV_ERROR    eError;
 
299
        SYS_DATA                *psSysData;
 
300
 
 
301
        SysAcquireData(&psSysData);
 
302
 
 
303
        eError = PVRSRVPowerLock(ui32CallerID, IMG_FALSE);
 
304
        if(eError != PVRSRV_OK)
 
305
        {
 
306
                return eError;
 
307
        }
 
308
 
 
309
        #if defined(PDUMP)
 
310
        if (eNewPowerState == PVRSRV_DEV_POWER_STATE_DEFAULT)
 
311
        {
 
312
                
 
313
 
 
314
 
 
315
 
 
316
                eError = PVRSRVDevicePrePowerStateKM(IMG_FALSE, ui32DeviceIndex, PVRSRV_DEV_POWER_STATE_ON);
 
317
                if(eError != PVRSRV_OK)
 
318
                {
 
319
                        goto Exit;
 
320
                }
 
321
 
 
322
                eError = PVRSRVDevicePostPowerStateKM(IMG_FALSE, ui32DeviceIndex, PVRSRV_DEV_POWER_STATE_ON);
 
323
 
 
324
                if (eError != PVRSRV_OK)
 
325
                {
 
326
                        goto Exit;
 
327
                }
 
328
 
 
329
                PDUMPSUSPEND();
 
330
        }
 
331
        #endif 
 
332
 
 
333
        eError = PVRSRVDevicePrePowerStateKM(IMG_FALSE, ui32DeviceIndex, eNewPowerState);
 
334
        if(eError != PVRSRV_OK)
 
335
        {
 
336
                if (eNewPowerState == PVRSRV_DEV_POWER_STATE_DEFAULT)
 
337
                {
 
338
                        PDUMPRESUME();
 
339
                }
 
340
                goto Exit;
 
341
        }
 
342
 
 
343
        eError = PVRSRVDevicePostPowerStateKM(IMG_FALSE, ui32DeviceIndex, eNewPowerState);
 
344
 
 
345
        if (eNewPowerState == PVRSRV_DEV_POWER_STATE_DEFAULT)
 
346
        {
 
347
                PDUMPRESUME();
 
348
        }
 
349
 
 
350
Exit:
 
351
 
 
352
        if(eError != PVRSRV_OK)
 
353
        {
 
354
                PVR_DPF((PVR_DBG_ERROR,
 
355
                                "PVRSRVSetDevicePowerStateKM : Transition to %d FAILED 0x%x", eNewPowerState, eError));
 
356
        }
 
357
 
 
358
        if (!bRetainMutex || (eError != PVRSRV_OK))
 
359
        {
 
360
                PVRSRVPowerUnlock(ui32CallerID);
 
361
        }
 
362
 
 
363
        return eError;
 
364
}
 
365
 
 
366
 
 
367
IMG_EXPORT
 
368
PVRSRV_ERROR PVRSRVSystemPrePowerStateKM(PVRSRV_SYS_POWER_STATE eNewSysPowerState)
 
369
{
 
370
        PVRSRV_ERROR                    eError;
 
371
        SYS_DATA                                *psSysData;
 
372
        PVRSRV_DEV_POWER_STATE  eNewDevicePowerState;
 
373
 
 
374
        SysAcquireData(&psSysData);
 
375
 
 
376
        
 
377
        eError = PVRSRVPowerLock(KERNEL_ID, IMG_TRUE);
 
378
        if(eError != PVRSRV_OK)
 
379
        {
 
380
                return eError;
 
381
        }
 
382
 
 
383
        if (_IsSystemStatePowered(eNewSysPowerState) !=
 
384
                _IsSystemStatePowered(psSysData->eCurrentPowerState))
 
385
        {
 
386
                if (_IsSystemStatePowered(eNewSysPowerState))
 
387
                {
 
388
                        
 
389
                        eNewDevicePowerState = PVRSRV_DEV_POWER_STATE_DEFAULT;
 
390
                }
 
391
                else
 
392
                {
 
393
                        eNewDevicePowerState = PVRSRV_DEV_POWER_STATE_OFF;
 
394
                }
 
395
 
 
396
                
 
397
                eError = PVRSRVDevicePrePowerStateKM(IMG_TRUE, 0, eNewDevicePowerState);
 
398
                if (eError != PVRSRV_OK)
 
399
                {
 
400
                        goto ErrorExit;
 
401
                }
 
402
        }
 
403
 
 
404
        if (eNewSysPowerState != psSysData->eCurrentPowerState)
 
405
        {
 
406
                
 
407
                eError = SysSystemPrePowerState(eNewSysPowerState);
 
408
                if (eError != PVRSRV_OK)
 
409
                {
 
410
                        goto ErrorExit;
 
411
                }
 
412
        }
 
413
 
 
414
        return eError;
 
415
 
 
416
ErrorExit:
 
417
 
 
418
        PVR_DPF((PVR_DBG_ERROR,
 
419
                        "PVRSRVSystemPrePowerStateKM: Transition from %d to %d FAILED 0x%x",
 
420
                        psSysData->eCurrentPowerState, eNewSysPowerState, eError));
 
421
 
 
422
        
 
423
        psSysData->eFailedPowerState = eNewSysPowerState;
 
424
 
 
425
        PVRSRVPowerUnlock(KERNEL_ID);
 
426
 
 
427
        return eError;
 
428
}
 
429
 
 
430
 
 
431
IMG_EXPORT
 
432
PVRSRV_ERROR PVRSRVSystemPostPowerStateKM(PVRSRV_SYS_POWER_STATE eNewSysPowerState)
 
433
{
 
434
        PVRSRV_ERROR                    eError = PVRSRV_OK;
 
435
        SYS_DATA                                *psSysData;
 
436
        PVRSRV_DEV_POWER_STATE  eNewDevicePowerState;
 
437
 
 
438
        SysAcquireData(&psSysData);
 
439
 
 
440
        if (eNewSysPowerState != psSysData->eCurrentPowerState)
 
441
        {
 
442
                
 
443
                eError = SysSystemPostPowerState(eNewSysPowerState);
 
444
                if (eError != PVRSRV_OK)
 
445
                {
 
446
                        goto Exit;
 
447
                }
 
448
        }
 
449
 
 
450
        if (_IsSystemStatePowered(eNewSysPowerState) !=
 
451
                _IsSystemStatePowered(psSysData->eCurrentPowerState))
 
452
        {
 
453
                if (_IsSystemStatePowered(eNewSysPowerState))
 
454
                {
 
455
                        
 
456
                        eNewDevicePowerState = PVRSRV_DEV_POWER_STATE_DEFAULT;
 
457
                }
 
458
                else
 
459
                {
 
460
                        eNewDevicePowerState = PVRSRV_DEV_POWER_STATE_OFF;
 
461
                }
 
462
 
 
463
                
 
464
                eError = PVRSRVDevicePostPowerStateKM(IMG_TRUE, 0, eNewDevicePowerState);
 
465
                if (eError != PVRSRV_OK)
 
466
                {
 
467
                        goto Exit;
 
468
                }
 
469
        }
 
470
 
 
471
        PVR_DPF((PVR_DBG_MESSAGE,
 
472
                        "PVRSRVSystemPostPowerStateKM: System Power Transition from %d to %d OK",
 
473
                        psSysData->eCurrentPowerState, eNewSysPowerState));
 
474
 
 
475
        psSysData->eCurrentPowerState = eNewSysPowerState;
 
476
 
 
477
Exit:
 
478
 
 
479
        PVRSRVPowerUnlock(KERNEL_ID);
 
480
 
 
481
         
 
482
        if (_IsSystemStatePowered(eNewSysPowerState) &&
 
483
                        PVRSRVGetInitServerState(PVRSRV_INIT_SERVER_SUCCESSFUL))
 
484
        {
 
485
                
 
486
 
 
487
 
 
488
                PVRSRVScheduleDeviceCallbacks();
 
489
        }
 
490
 
 
491
        return eError;
 
492
}
 
493
 
 
494
 
 
495
IMG_EXPORT
 
496
PVRSRV_ERROR PVRSRVSetPowerStateKM(PVRSRV_SYS_POWER_STATE eNewSysPowerState)
 
497
{
 
498
        PVRSRV_ERROR    eError;
 
499
        SYS_DATA                *psSysData;
 
500
 
 
501
        SysAcquireData(&psSysData);
 
502
 
 
503
        eError = PVRSRVSystemPrePowerStateKM(eNewSysPowerState);
 
504
        if(eError != PVRSRV_OK)
 
505
        {
 
506
                goto ErrorExit;
 
507
        }
 
508
 
 
509
        eError = PVRSRVSystemPostPowerStateKM(eNewSysPowerState);
 
510
        if(eError != PVRSRV_OK)
 
511
        {
 
512
                goto ErrorExit;
 
513
        }
 
514
 
 
515
        
 
516
        psSysData->eFailedPowerState = PVRSRV_SYS_POWER_STATE_Unspecified;
 
517
 
 
518
        return PVRSRV_OK;
 
519
 
 
520
ErrorExit:
 
521
 
 
522
        PVR_DPF((PVR_DBG_ERROR,
 
523
                        "PVRSRVSetPowerStateKM: Transition from %d to %d FAILED 0x%x",
 
524
                        psSysData->eCurrentPowerState, eNewSysPowerState, eError));
 
525
 
 
526
        
 
527
        psSysData->eFailedPowerState = eNewSysPowerState;
 
528
 
 
529
        return eError;
 
530
}
 
531
 
 
532
 
 
533
PVRSRV_ERROR PVRSRVRegisterPowerDevice(IMG_UINT32                                       ui32DeviceIndex,
 
534
                                                                           PFN_PRE_POWER                                pfnPrePower,
 
535
                                                                           PFN_POST_POWER                               pfnPostPower,
 
536
                                                                           PFN_PRE_CLOCKSPEED_CHANGE    pfnPreClockSpeedChange,
 
537
                                                                           PFN_POST_CLOCKSPEED_CHANGE   pfnPostClockSpeedChange,
 
538
                                                                           IMG_HANDLE                                   hDevCookie,
 
539
                                                                           PVRSRV_DEV_POWER_STATE               eCurrentPowerState,
 
540
                                                                           PVRSRV_DEV_POWER_STATE               eDefaultPowerState)
 
541
{
 
542
        PVRSRV_ERROR            eError;
 
543
        SYS_DATA                        *psSysData;
 
544
        PVRSRV_POWER_DEV        *psPowerDevice;
 
545
 
 
546
        if (pfnPrePower == IMG_NULL &&
 
547
                pfnPostPower == IMG_NULL)
 
548
        {
 
549
                return PVRSRVRemovePowerDevice(ui32DeviceIndex);
 
550
        }
 
551
 
 
552
        SysAcquireData(&psSysData);
 
553
 
 
554
        eError = OSAllocMem( PVRSRV_OS_NON_PAGEABLE_HEAP,
 
555
                                                 sizeof(PVRSRV_POWER_DEV),
 
556
                                                 (IMG_VOID **)&psPowerDevice, IMG_NULL,
 
557
                                                 "Power Device");
 
558
        if(eError != PVRSRV_OK)
 
559
        {
 
560
                PVR_DPF((PVR_DBG_ERROR,"PVRSRVRegisterPowerDevice: Failed to alloc PVRSRV_POWER_DEV"));
 
561
                return eError;
 
562
        }
 
563
 
 
564
        
 
565
        psPowerDevice->pfnPrePower = pfnPrePower;
 
566
        psPowerDevice->pfnPostPower = pfnPostPower;
 
567
        psPowerDevice->pfnPreClockSpeedChange = pfnPreClockSpeedChange;
 
568
        psPowerDevice->pfnPostClockSpeedChange = pfnPostClockSpeedChange;
 
569
        psPowerDevice->hDevCookie = hDevCookie;
 
570
        psPowerDevice->ui32DeviceIndex = ui32DeviceIndex;
 
571
        psPowerDevice->eCurrentPowerState = eCurrentPowerState;
 
572
        psPowerDevice->eDefaultPowerState = eDefaultPowerState;
 
573
 
 
574
        
 
575
        List_PVRSRV_POWER_DEV_Insert(&(psSysData->psPowerDeviceList), psPowerDevice);
 
576
 
 
577
        return (PVRSRV_OK);
 
578
}
 
579
 
 
580
 
 
581
PVRSRV_ERROR PVRSRVRemovePowerDevice (IMG_UINT32 ui32DeviceIndex)
 
582
{
 
583
        SYS_DATA                        *psSysData;
 
584
        PVRSRV_POWER_DEV        *psPowerDev;
 
585
 
 
586
        SysAcquireData(&psSysData);
 
587
 
 
588
        
 
589
        psPowerDev = (PVRSRV_POWER_DEV*)
 
590
                                        List_PVRSRV_POWER_DEV_Any_va(psSysData->psPowerDeviceList,
 
591
                                                                                                 &MatchPowerDeviceIndex_AnyVaCb,
 
592
                                                                                                 ui32DeviceIndex);
 
593
 
 
594
        if (psPowerDev)
 
595
        {
 
596
                List_PVRSRV_POWER_DEV_Remove(psPowerDev);
 
597
                OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP, sizeof(PVRSRV_POWER_DEV), psPowerDev, IMG_NULL);
 
598
                
 
599
        }
 
600
 
 
601
        return (PVRSRV_OK);
 
602
}
 
603
 
 
604
 
 
605
IMG_EXPORT
 
606
IMG_BOOL PVRSRVIsDevicePowered(IMG_UINT32 ui32DeviceIndex)
 
607
{
 
608
        SYS_DATA                        *psSysData;
 
609
        PVRSRV_POWER_DEV        *psPowerDevice;
 
610
 
 
611
        SysAcquireData(&psSysData);
 
612
 
 
613
         
 
614
        if (OSIsResourceLocked(&psSysData->sPowerStateChangeResource, KERNEL_ID) ||
 
615
                OSIsResourceLocked(&psSysData->sPowerStateChangeResource, ISR_ID))
 
616
        {
 
617
                return IMG_FALSE;
 
618
        }
 
619
 
 
620
        psPowerDevice = (PVRSRV_POWER_DEV*)
 
621
                                        List_PVRSRV_POWER_DEV_Any_va(psSysData->psPowerDeviceList,
 
622
                                                                                                 &MatchPowerDeviceIndex_AnyVaCb,
 
623
                                                                                                 ui32DeviceIndex);
 
624
        return (psPowerDevice && (psPowerDevice->eCurrentPowerState == PVRSRV_DEV_POWER_STATE_ON))
 
625
                        ? IMG_TRUE : IMG_FALSE;
 
626
}
 
627
 
 
628
 
 
629
PVRSRV_ERROR PVRSRVDevicePreClockSpeedChange(IMG_UINT32 ui32DeviceIndex,
 
630
                                                                                         IMG_BOOL       bIdleDevice,
 
631
                                                                                         IMG_VOID       *pvInfo)
 
632
{
 
633
        PVRSRV_ERROR            eError = PVRSRV_OK;
 
634
        SYS_DATA                        *psSysData;
 
635
        PVRSRV_POWER_DEV        *psPowerDevice;
 
636
 
 
637
        PVR_UNREFERENCED_PARAMETER(pvInfo);
 
638
 
 
639
        SysAcquireData(&psSysData);
 
640
 
 
641
        if (bIdleDevice)
 
642
        {
 
643
                
 
644
                eError = PVRSRVPowerLock(KERNEL_ID, IMG_FALSE);
 
645
                if (eError != PVRSRV_OK)
 
646
                {
 
647
                        PVR_DPF((PVR_DBG_ERROR, "PVRSRVDevicePreClockSpeedChange : failed to acquire lock, error:0x%x", eError));
 
648
                        return eError;
 
649
                }
 
650
        }
 
651
 
 
652
        
 
653
        psPowerDevice = (PVRSRV_POWER_DEV*)
 
654
                                        List_PVRSRV_POWER_DEV_Any_va(psSysData->psPowerDeviceList,
 
655
                                                                                                 &MatchPowerDeviceIndex_AnyVaCb,
 
656
                                                                                                 ui32DeviceIndex);
 
657
 
 
658
        if (psPowerDevice && psPowerDevice->pfnPostClockSpeedChange)
 
659
        {
 
660
                        eError = psPowerDevice->pfnPreClockSpeedChange(psPowerDevice->hDevCookie,
 
661
                                                                                                                   bIdleDevice,
 
662
                                                                                                                   psPowerDevice->eCurrentPowerState);
 
663
                        if (eError != PVRSRV_OK)
 
664
                        {
 
665
                                PVR_DPF((PVR_DBG_ERROR,
 
666
                                                "PVRSRVDevicePreClockSpeedChange : Device %u failed, error:0x%x",
 
667
                                                ui32DeviceIndex, eError));
 
668
                        }
 
669
        }
 
670
 
 
671
        if (bIdleDevice && eError != PVRSRV_OK)
 
672
        {
 
673
                PVRSRVPowerUnlock(KERNEL_ID);
 
674
        }
 
675
 
 
676
        return eError;
 
677
}
 
678
 
 
679
 
 
680
IMG_VOID PVRSRVDevicePostClockSpeedChange(IMG_UINT32    ui32DeviceIndex,
 
681
                                                                                  IMG_BOOL              bIdleDevice,
 
682
                                                                                  IMG_VOID              *pvInfo)
 
683
{
 
684
        PVRSRV_ERROR            eError;
 
685
        SYS_DATA                        *psSysData;
 
686
        PVRSRV_POWER_DEV        *psPowerDevice;
 
687
 
 
688
        PVR_UNREFERENCED_PARAMETER(pvInfo);
 
689
 
 
690
        SysAcquireData(&psSysData);
 
691
 
 
692
        
 
693
        psPowerDevice = (PVRSRV_POWER_DEV*)
 
694
                                        List_PVRSRV_POWER_DEV_Any_va(psSysData->psPowerDeviceList,
 
695
                                                                                                 &MatchPowerDeviceIndex_AnyVaCb,
 
696
                                                                                                 ui32DeviceIndex);
 
697
 
 
698
        if (psPowerDevice && psPowerDevice->pfnPostClockSpeedChange)
 
699
        {
 
700
                eError = psPowerDevice->pfnPostClockSpeedChange(psPowerDevice->hDevCookie,
 
701
                                                                                                                bIdleDevice,
 
702
                                                                                                                psPowerDevice->eCurrentPowerState);
 
703
                if (eError != PVRSRV_OK)
 
704
                {
 
705
                        PVR_DPF((PVR_DBG_ERROR,
 
706
                                        "PVRSRVDevicePostClockSpeedChange : Device %u failed, error:0x%x",
 
707
                                        ui32DeviceIndex, eError));
 
708
                }
 
709
        }
 
710
 
 
711
 
 
712
        if (bIdleDevice)
 
713
        {
 
714
                
 
715
                PVRSRVPowerUnlock(KERNEL_ID);
 
716
        }
 
717
}
 
718