20100903+0m5
[sgx.git] / pvr / syscommon.h
1 /**********************************************************************
2  *
3  * Copyright(c) 2008 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 #ifndef _SYSCOMMON_H
28 #define _SYSCOMMON_H
29
30 #include "sysconfig.h"
31 #include "sysinfo.h"
32 #include "servicesint.h"
33 #include "queue.h"
34 #include "power.h"
35 #include "resman.h"
36 #include "ra.h"
37 #include "device.h"
38 #include "buffer_manager.h"
39
40
41 struct SYS_DEVICE_ID {
42         u32 uiID;
43         IMG_BOOL bInUse;
44
45 };
46
47 #define SYS_MAX_LOCAL_DEVMEM_ARENAS     4
48
49 struct SYS_DATA {
50         u32 ui32NumDevices;
51         struct SYS_DEVICE_ID sDeviceID[SYS_DEVICE_COUNT];
52         struct PVRSRV_DEVICE_NODE *psDeviceNodeList;
53         struct PVRSRV_POWER_DEV *psPowerDeviceList;
54         struct PVRSRV_RESOURCE sPowerStateChangeResource;
55         enum PVR_POWER_STATE eCurrentPowerState;
56         enum PVR_POWER_STATE eFailedPowerState;
57         u32 ui32CurrentOSPowerState;
58         struct PVRSRV_QUEUE_INFO *psQueueList;
59         struct PVRSRV_KERNEL_SYNC_INFO *psSharedSyncInfoList;
60         void *pvEnvSpecificData;
61         void *pvSysSpecificData;
62         struct PVRSRV_RESOURCE sQProcessResource;
63         void *pvSOCRegsBase;
64         void *hSOCTimerRegisterOSMemHandle;
65         u32 *pvSOCTimerRegisterKM;
66         void *pvSOCClockGateRegsBase;
67         u32 ui32SOCClockGateRegsSize;
68         IMG_BOOL (**ppfnCmdProcList[SYS_DEVICE_COUNT])(void *, u32, void *);
69
70         struct COMMAND_COMPLETE_DATA **ppsCmdCompleteData[SYS_DEVICE_COUNT];
71
72         IMG_BOOL bReProcessQueues;
73
74         struct RA_ARENA *apsLocalDevMemArena[SYS_MAX_LOCAL_DEVMEM_ARENAS];
75
76         char *pszVersionString;
77         struct PVRSRV_EVENTOBJECT *psGlobalEventObject;
78 };
79
80 enum PVRSRV_ERROR SysInitialise(void);
81 enum PVRSRV_ERROR SysFinalise(void);
82
83 u32 GetCPUTranslatedAddress(void);
84
85 enum PVRSRV_ERROR SysDeinitialise(struct SYS_DATA *psSysData);
86
87 enum PVRSRV_ERROR SysGetDeviceMemoryMap(enum PVRSRV_DEVICE_TYPE eDeviceType,
88                                    void **ppvDeviceMap);
89
90 void SysRegisterExternalDevice(struct PVRSRV_DEVICE_NODE *psDeviceNode);
91 void SysRemoveExternalDevice(struct PVRSRV_DEVICE_NODE *psDeviceNode);
92
93 u32 SysGetInterruptSource(struct SYS_DATA *psSysData,
94                                  struct PVRSRV_DEVICE_NODE *psDeviceNode);
95
96 void SysClearInterrupts(struct SYS_DATA *psSysData,
97                             u32 ui32ClearBits);
98
99 enum PVRSRV_ERROR SysResetDevice(u32 ui32DeviceIndex);
100
101 enum PVRSRV_ERROR SysSystemPrePowerState(enum PVR_POWER_STATE eNewPowerState);
102 enum PVRSRV_ERROR SysSystemPostPowerState(enum PVR_POWER_STATE eNewPowerState);
103 enum PVRSRV_ERROR SysDevicePrePowerState(u32 ui32DeviceIndex,
104                                     enum PVR_POWER_STATE eNewPowerState,
105                                     enum PVR_POWER_STATE eCurrentPowerState);
106 enum PVRSRV_ERROR SysDevicePostPowerState(u32 ui32DeviceIndex,
107                                      enum PVR_POWER_STATE eNewPowerState,
108                                      enum PVR_POWER_STATE
109                                      eCurrentPowerState);
110
111 enum PVRSRV_ERROR SysOEMFunction(u32 ui32ID,
112                             void *pvIn,
113                             u32 ulInSize,
114                             void *pvOut, u32 ulOutSize);
115
116 struct IMG_DEV_PHYADDR SysCpuPAddrToDevPAddr(
117                         enum PVRSRV_DEVICE_TYPE eDeviceType,
118                         struct IMG_CPU_PHYADDR cpu_paddr);
119 struct IMG_DEV_PHYADDR SysSysPAddrToDevPAddr(
120                         enum PVRSRV_DEVICE_TYPE eDeviceType,
121                         struct IMG_SYS_PHYADDR SysPAddr);
122 struct IMG_SYS_PHYADDR SysDevPAddrToSysPAddr(
123                         enum PVRSRV_DEVICE_TYPE eDeviceType,
124                         struct IMG_DEV_PHYADDR SysPAddr);
125 struct IMG_CPU_PHYADDR SysSysPAddrToCpuPAddr(struct IMG_SYS_PHYADDR SysPAddr);
126 struct IMG_SYS_PHYADDR SysCpuPAddrToSysPAddr(struct IMG_CPU_PHYADDR cpu_paddr);
127
128 extern struct SYS_DATA *gpsSysData;
129
130
131 static inline enum PVRSRV_ERROR SysAcquireData(struct SYS_DATA **ppsSysData)
132 {
133         *ppsSysData = gpsSysData;
134
135         if (!gpsSysData)
136                 return PVRSRV_ERROR_GENERIC;
137
138         return PVRSRV_OK;
139 }
140
141 static inline enum PVRSRV_ERROR SysInitialiseCommon(struct SYS_DATA *psSysData)
142 {
143         enum PVRSRV_ERROR eError;
144         eError = PVRSRVInit(psSysData);
145         return eError;
146 }
147
148 static inline void SysDeinitialiseCommon(struct SYS_DATA *psSysData)
149 {
150         PVRSRVDeInit(psSysData);
151         OSDestroyResource(&psSysData->sPowerStateChangeResource);
152 }
153
154 #define SysReadHWReg(p, o) OSReadHWReg(p, o)
155 #define SysWriteHWReg(p, o, v) OSWriteHWReg(p, o, v)
156
157
158 #endif