|
1 // Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Implementation of Virtual Video Hardware Interface |
|
15 |
|
16 |
|
17 // INCLUDE FILES |
|
18 #include <platform.h> |
|
19 #include <kern_priv.h> |
|
20 |
|
21 #include <graphics/guestvideodriverinterfaceconstants.h> |
|
22 #include <graphics/virtualvideohwinterface.h> |
|
23 #include <graphics/virtualvideotracing.h> |
|
24 #include "syborg.h" |
|
25 |
|
26 // CONSTANTS |
|
27 |
|
28 #ifdef PLATSIM_CONFIG |
|
29 _LIT( KVirtualVideoHwInterfacePanic, "DVirtualVideoHwInterface" ); |
|
30 #endif |
|
31 |
|
32 // ============================ LOCAL DATA TYPES =============================== |
|
33 |
|
34 TPhysAddr DVirtualVideoHwInterface::iVideoRamBasePhys = NULL; |
|
35 |
|
36 // Register offsets for playback and recording channels |
|
37 // Note: The orders of these must match the order of enumarations |
|
38 const TLinAddr KRegisterOffsets[] = |
|
39 { |
|
40 VVI_R_ID, |
|
41 VVI_R_IRQ_ENABLE, |
|
42 VVI_R_IRQ_STATUS, |
|
43 VVI_R_COMMAND, |
|
44 VVI_R_PARAMETER_LOAD, |
|
45 VVI_R_ERROR, |
|
46 VVI_R_INPUT_BUFFER_TAIL, |
|
47 VVI_R_INPUT_BUFFER_HEAD, |
|
48 VVI_R_INPUT_BUFFER_READ_COUNT, |
|
49 VVI_R_INPUT_BUFFER_WRITE_COUNT, |
|
50 VVI_R_INPUT_BUFFER_MAX_TAIL, |
|
51 VVI_R_REQUEST_ID, |
|
52 VVI_R_SHARED_CMD_MEMORY_BASE, |
|
53 VVI_R_SHARED_SURFACEBUFFER_MEMORY_BASE |
|
54 }; |
|
55 #define ASSERT_PANIC(c,p) __ASSERT_DEBUG(c,Kern::PanicCurrentThread(KVirtualVideoHwInterfacePanic,p)); |
|
56 |
|
57 // ============================ LOCAL FUNCTIONS ================================ |
|
58 |
|
59 // Get register offset for certain register range and register |
|
60 inline TLinAddr RegisterOffset( DVirtualVideoHwInterface::TRegister aRegister ) |
|
61 { |
|
62 return KRegisterOffsets[aRegister]; |
|
63 } |
|
64 |
|
65 // ============================ MEMBER FUNCTIONS =============================== |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 // DVirtualVideoHwInterface::DVirtualVideoHwInterface |
|
69 // ----------------------------------------------------------------------------- |
|
70 // |
|
71 DVirtualVideoHwInterface::DVirtualVideoHwInterface() |
|
72 { |
|
73 VVHW_TRACE("DVirtualVideoHwInterface::DVirtualVideoHwInterface()>"); |
|
74 iInputParametersMemoryChunk = NULL; |
|
75 iOutputParametersMemoryChunk = NULL; |
|
76 iRegisterMemoryChunk = NULL; |
|
77 |
|
78 #ifdef PLATSIM_CONFIG |
|
79 iVideoRamBasePhys = VVI_BASE; |
|
80 #else |
|
81 // Reserve a contiguous memory chunk for graphics usage |
|
82 TUint32 ramSize = VVI_PARAMETERS_INPUT_MEMORY_SIZE + |
|
83 VVI_PARAMETERS_OUTPUT_MEMORY_SIZE + |
|
84 VVI_SURFACEBUFFER_MEMORY_SIZE; |
|
85 TInt r = Epoc::AllocPhysicalRam( ramSize, iVideoRamBasePhys ); |
|
86 VVHW_TRACE("DVirtualVideoHwInterface::DVirtualVideoHwInterface() AllocPhysicalRam %d", r); |
|
87 if (r != KErrNone) |
|
88 { |
|
89 NKern::ThreadLeaveCS(); |
|
90 Kern::Fault("DVirtualVideoHwInterface Allocate Ram %d",r); |
|
91 } |
|
92 SetSharedCmdMemBase( iVideoRamBasePhys + VVI_PARAMETERS_INPUT_BASE_ADDRESS ); |
|
93 SetSharedSurfacebufferMemBase( iVideoRamBasePhys + VVI_SURFACEBUFFER_BASE_ADDRESS ); |
|
94 |
|
95 #endif // PLATSIM_CONFIG |
|
96 VVHW_TRACE("DVirtualVideoHwInterface::DVirtualVideoHwInterface()<"); |
|
97 } |
|
98 |
|
99 |
|
100 // ----------------------------------------------------------------------------- |
|
101 // DVirtualVideoHwInterface::~DVirtualVideoHwInterface |
|
102 // ----------------------------------------------------------------------------- |
|
103 // |
|
104 DVirtualVideoHwInterface::~DVirtualVideoHwInterface() |
|
105 { |
|
106 // Enter critical section |
|
107 NKern::ThreadEnterCS(); |
|
108 |
|
109 if ( iInputParametersMemoryChunk ) |
|
110 { |
|
111 Kern::ChunkClose( iInputParametersMemoryChunk ); |
|
112 } |
|
113 |
|
114 if ( iOutputParametersMemoryChunk ) |
|
115 { |
|
116 Kern::ChunkClose( iOutputParametersMemoryChunk ); |
|
117 } |
|
118 |
|
119 if ( iRegisterMemoryChunk ) |
|
120 { |
|
121 Kern::ChunkClose( iRegisterMemoryChunk ); |
|
122 } |
|
123 |
|
124 iInputParametersMemoryChunk = NULL; |
|
125 iOutputParametersMemoryChunk = NULL; |
|
126 iRegisterMemoryChunk = NULL; |
|
127 |
|
128 // Leave critical section |
|
129 NKern::ThreadLeaveCS(); |
|
130 } |
|
131 |
|
132 TInt DVirtualVideoHwInterface::InitParametersInputMemory() |
|
133 { |
|
134 return InitPhysicalMemory( iVideoRamBasePhys + VVI_PARAMETERS_INPUT_BASE_ADDRESS, |
|
135 VVI_PARAMETERS_INPUT_MEMORY_SIZE, iInputParametersMemoryChunk, |
|
136 iInputParametersChunkKernelAddress ); |
|
137 } |
|
138 |
|
139 TInt DVirtualVideoHwInterface::InitParametersOutputMemory() |
|
140 { |
|
141 return InitPhysicalMemory( iVideoRamBasePhys + VVI_PARAMETERS_OUTPUT_BASE_ADDRESS, |
|
142 VVI_PARAMETERS_OUTPUT_MEMORY_SIZE, iOutputParametersMemoryChunk, |
|
143 iOutputParametersChunkKernelAddress ); |
|
144 } |
|
145 |
|
146 TInt DVirtualVideoHwInterface::InitRegisterMemory() |
|
147 { |
|
148 #ifdef PLATSIM_CONFIG |
|
149 return InitPhysicalMemory( VVI_REGISTERS_BASE_ADDRESS, |
|
150 VVI_REGISTERS_MEMORY_SIZE, iRegisterMemoryChunk, |
|
151 iRegisterChunkKernelAddress ); |
|
152 #else |
|
153 return KErrNone; |
|
154 #endif // PLATSIM_CONFIG |
|
155 } |
|
156 |
|
157 // ----------------------------------------------------------------------------- |
|
158 // DVirtualVideoHwInterface::InitPhysicalMemory |
|
159 // ----------------------------------------------------------------------------- |
|
160 // |
|
161 TInt DVirtualVideoHwInterface::InitPhysicalMemory( TUint32 aPhysicalAddress, |
|
162 TInt aMaxSize, DChunk*& aChunk, TLinAddr& aLinAddr ) |
|
163 { |
|
164 TInt error = KErrNoMemory; |
|
165 TChunkCreateInfo info; |
|
166 info.iType = TChunkCreateInfo::ESharedKernelSingle; |
|
167 info.iMaxSize = aMaxSize; |
|
168 info.iMapAttr = EMapAttrFullyBlocking; |
|
169 info.iOwnsMemory = EFalse; |
|
170 info.iDestroyedDfc = NULL; |
|
171 DChunk* chunk = NULL; |
|
172 TUint32 mapAttr = 0; |
|
173 TLinAddr chunkKernelAddress = 0; |
|
174 |
|
175 // Enter critical section while creating the chunk and commiting memory |
|
176 NKern::ThreadEnterCS(); |
|
177 |
|
178 error = Kern::ChunkCreate( info, chunk, chunkKernelAddress, mapAttr ); |
|
179 if ( !error ) |
|
180 { |
|
181 error = Kern::ChunkCommitPhysical( |
|
182 chunk, 0, aMaxSize, aPhysicalAddress ); |
|
183 if ( error ) |
|
184 { |
|
185 Kern::ChunkClose( chunk ); |
|
186 } |
|
187 else |
|
188 { |
|
189 // Physical memory has been successfully committed to chunk |
|
190 aChunk = chunk; |
|
191 aLinAddr = chunkKernelAddress; |
|
192 } |
|
193 } |
|
194 chunk = NULL; |
|
195 |
|
196 // Leave critical section |
|
197 NKern::ThreadLeaveCS(); |
|
198 |
|
199 VVHW_TRACE("DVirtualVideoHwInterface::InitPhysicalMemory return %d", error); |
|
200 return error; |
|
201 } |
|
202 |
|
203 // ----------------------------------------------------------------------------- |
|
204 // ----------------------------------------------------------------------------- |
|
205 // DVirtualVideoHwInterface::EnableInterrupts |
|
206 // ----------------------------------------------------------------------------- |
|
207 // |
|
208 void DVirtualVideoHwInterface::EnableInterrupts( TUint32 aInterruptBitField ) |
|
209 { |
|
210 SetRegisterValue( ERegIrqEnable, aInterruptBitField ); |
|
211 } |
|
212 |
|
213 |
|
214 // ----------------------------------------------------------------------------- |
|
215 // DVirtualVideoHwInterface::GetInterruptEnabledState |
|
216 // ----------------------------------------------------------------------------- |
|
217 // |
|
218 void DVirtualVideoHwInterface::GetInterruptEnabledState( TUint32& aInterruptBitField ) |
|
219 { |
|
220 GetRegisterValue( ERegIrqEnable, aInterruptBitField ); |
|
221 } |
|
222 |
|
223 |
|
224 // ----------------------------------------------------------------------------- |
|
225 // DVirtualVideoHwInterface::GetInterruptStatus |
|
226 // ----------------------------------------------------------------------------- |
|
227 // |
|
228 void DVirtualVideoHwInterface::GetInterruptStatus( TUint32& aInterruptBitField ) |
|
229 { |
|
230 GetRegisterValue( ERegIrqStatus, aInterruptBitField ); |
|
231 } |
|
232 |
|
233 |
|
234 // ----------------------------------------------------------------------------- |
|
235 // DVirtualVideoHwInterface::ResetInterruptStatus |
|
236 // ----------------------------------------------------------------------------- |
|
237 // |
|
238 void DVirtualVideoHwInterface::ResetInterruptStatus( TUint32 aInterruptBitField ) |
|
239 { |
|
240 SetRegisterValue( ERegIrqStatus, aInterruptBitField ); |
|
241 } |
|
242 |
|
243 |
|
244 // DVirtualVideoHwInterface::IssueCommand |
|
245 // ----------------------------------------------------------------------------- |
|
246 // |
|
247 void DVirtualVideoHwInterface::IssueCommand( TUint32 aCommand ) |
|
248 { |
|
249 SetRegisterValue( ERegCommand, aCommand ); |
|
250 } |
|
251 |
|
252 // DVirtualVideoHwInterface::SetSharedCmdMemBase |
|
253 // ----------------------------------------------------------------------------- |
|
254 // |
|
255 void DVirtualVideoHwInterface::SetSharedCmdMemBase( TUint32 aPhysicalAddress ) |
|
256 { |
|
257 VVHW_TRACE("DVirtualVideoHwInterface::SetSharedCmdMemBase 0x%08x", aPhysicalAddress); |
|
258 SetRegisterValue( ERegSharedCmdMemBase, aPhysicalAddress ); |
|
259 } |
|
260 |
|
261 void DVirtualVideoHwInterface::SetSharedSurfacebufferMemBase( TUint32 aPhysicalAddress ) |
|
262 { |
|
263 VVHW_TRACE("DVirtualVideoHwInterface::SetSharedSurfacebufferMemBase 0x%08x", aPhysicalAddress); |
|
264 SetRegisterValue( ERegSharedSurfacebufferMemBase, aPhysicalAddress ); |
|
265 } |
|
266 |
|
267 // ----------------------------------------------------------------------------- |
|
268 // DVirtualVideoHwInterface::GetRegisterValue |
|
269 // ----------------------------------------------------------------------------- |
|
270 // |
|
271 void DVirtualVideoHwInterface::GetRegisterValue( |
|
272 TRegister aRegister, |
|
273 TUint32& aValue ) |
|
274 { |
|
275 if ( iRegisterMemoryChunk ) |
|
276 { |
|
277 TLinAddr offset = RegisterOffset( aRegister ); |
|
278 TUint32* ptr = reinterpret_cast<TUint32*>( iRegisterChunkKernelAddress + offset ); |
|
279 aValue = *ptr; |
|
280 } |
|
281 else |
|
282 { |
|
283 #ifdef PLATSIM_CONFIG |
|
284 Kern::PanicCurrentThread( KVirtualVideoHwInterfacePanic, KErrNotReady ); |
|
285 #else |
|
286 TLinAddr offset = RegisterOffset( aRegister ); |
|
287 aValue = ReadReg( KHwGraphicsRegBase, offset ); |
|
288 #endif // PLATSIM_CONFIG |
|
289 } |
|
290 } |
|
291 |
|
292 |
|
293 // ----------------------------------------------------------------------------- |
|
294 // DVirtualVideoHwInterface::SetRegisterValue |
|
295 // ----------------------------------------------------------------------------- |
|
296 // |
|
297 void DVirtualVideoHwInterface::SetRegisterValue( |
|
298 TRegister aRegister, |
|
299 TUint32 aValue ) |
|
300 { |
|
301 if ( iRegisterMemoryChunk ) |
|
302 { |
|
303 TLinAddr offset = RegisterOffset( aRegister ); |
|
304 TUint32* ptr = reinterpret_cast<TUint32*>( iRegisterChunkKernelAddress + offset ); |
|
305 *ptr = aValue; |
|
306 } |
|
307 else |
|
308 { |
|
309 #ifdef PLATSIM_CONFIG |
|
310 Kern::PanicCurrentThread( KVirtualVideoHwInterfacePanic, KErrNotReady ); |
|
311 #else |
|
312 TLinAddr offset = RegisterOffset( aRegister ); |
|
313 WriteReg( KHwGraphicsRegBase, offset, aValue ); |
|
314 #endif // PLATSIM_CONFIG |
|
315 } |
|
316 } |
|
317 |
|
318 EXPORT_C TPhysAddr DVirtualVideoHwInterface::GetSurfaceBufferBase() |
|
319 { |
|
320 TPhysAddr ret = 0; |
|
321 if( iVideoRamBasePhys != 0 ) |
|
322 { |
|
323 ret = iVideoRamBasePhys + VVI_SURFACEBUFFER_BASE_ADDRESS; |
|
324 } |
|
325 return ret; |
|
326 } |
|
327 |