source: svn/trunk/newcon3bcm2_21bu/magnum/portinginterface/xvd/7552/bxvd_priv.c

Last change on this file was 2, checked in by jglee, 11 years ago

first commit

  • Property svn:executable set to *
File size: 112.5 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2004-2006, Broad-com Corporation
3 *     All Rights Reserved
4 *     Confidential Property of Broad-com Corporation
5 *
6 *  THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE
7 *  AGREEMENT  BETWEEN THE USER AND BROAD-COM.  YOU HAVE NO RIGHT TO USE OR
8 *  EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT.
9 *
10 * $brcm_Workfile: bxvd_priv.c $
11 * $brcm_Revision: Hydra_Software_Devel/212 $
12 * $brcm_Date: 3/16/12 11:58a $
13 *
14 * Module Description:
15 *   See Module Overview below.
16 *
17 * Revision History:
18 *
19 * $brcm_Log: /magnum/portinginterface/xvd/7401/bxvd_priv.c $
20 *
21 * Hydra_Software_Devel/212   3/16/12 11:58a btosi
22 * SW7425-2536: added support for displayInterruptStatus_isr
23 *
24 * Hydra_Software_Devel/211   2/16/12 6:12p davidp
25 * SW7425-2419: Add BXVD_P_DestroyInterrupts().
26 *
27 * Hydra_Software_Devel/210   2/9/12 7:57p davidp
28 * SW7425-2284: Add BXVD_P_InitChannel to be used in BXVD_OpenChannel.
29 *
30 * Hydra_Software_Devel/209   2/2/12 3:02p davidp
31 * SW7425-2024: Validate decode protocol specified in BXVD_StartDecode is
32 * supported on platform.
33 *
34 * Hydra_Software_Devel/208   1/20/12 3:47p davidp
35 * SW7208-175: Add support for 1920 portrait decode.
36 *
37 * Hydra_Software_Devel/207   12/14/11 5:05p davidp
38 * FWAVDTEST-31: Update AVS memory config table.
39 *
40 * Hydra_Software_Devel/206   11/10/11 2:37p davidp
41 * SW7425-1599: Add bSVCProgressiveOnly flag to BXVD_ChannelSettings.
42 *
43 * Hydra_Software_Devel/205   10/20/11 3:21p davidp
44 * SW7425-1564: Add support for SVC interlaced decode.
45 *
46 * Hydra_Software_Devel/204   9/27/11 6:40p davidp
47 * SW7340-279: Allocate Still Channel context in BXVD_Open.
48 *
49 * Hydra_Software_Devel/203   9/20/11 3:56p davidp
50 * SW7346-420: Add memory config support for VP8, RV9 and Spark protocols.
51 *
52 * Hydra_Software_Devel/202   7/20/11 3:27p davidp
53 * SW7231-127: Add BXVD_Standby and BXVD_Resume support.
54 *
55 * Hydra_Software_Devel/201   6/30/11 4:06p davidp
56 * SW7425-826: Clear vsync interrupt when vsync interrupt mask is
57 * registered with XVD.
58 *
59 * Hydra_Software_Devel/200   6/27/11 4:13p davidp
60 * SW7425-542: Merge devel branch to mainline.
61 *
62 * Hydra_Software_Devel/SW7425-542/1   6/9/11 4:15p davidp
63 * SW7425-542: Increase context memory size for extended PPB.
64 *
65 * Hydra_Software_Devel/199   4/20/11 4:25p davidp
66 * SW7231-127: Disable BXVD_P_GetHibernateState on platforms that use the
67 * BCHP_PWR routines.
68 *
69 * Hydra_Software_Devel/198   3/25/11 3:56p davidp
70 * SW7405-5101: Add checks to verify AVD code space, CDB/ITB and memory
71 * used is in memory region below 768mb for ARC300 based cores.
72 *
73 * Hydra_Software_Devel/197   2/16/11 4:09p davidp
74 * SW7422-22: Increase FW context memory for Rev K core support.
75 *
76 * Hydra_Software_Devel/196   12/9/10 5:13p davidp
77 * SW7422-22: Fix SVC support, allocate FW memory for AVD.
78 *
79 * Hydra_Software_Devel/195   11/30/10 5:59p davidp
80 * SW7422-22: Free FW interlayer picture buffers in BXVD_P_FreeFWMem.
81 *
82 * Hydra_Software_Devel/194   11/23/10 6:12p davidp
83 * SW7422-22: Fix SVC support.
84 *
85 * Hydra_Software_Devel/193   10/18/10 5:39p davidp
86 * SW7425-16: Fix compiler warning.
87 *
88 * Hydra_Software_Devel/192   10/18/10 4:54p davidp
89 * SW7425-16: Fix compiler warning.
90 *
91 * Hydra_Software_Devel/191   10/15/10 6:35p davidp
92 * SW7425-16: Add support for base layer ARC, new memory config,
93 * additional FW api memory arguments.
94 *
95 * Hydra_Software_Devel/190   10/6/10 2:00p davidp
96 * SW7405-4923: Set XVD handle type to invalid when context is freed.
97 *
98 * Hydra_Software_Devel/189   10/5/10 10:24a davidp
99 * SW7405-4923: Resolve latest coverity run issues for non-debug builds.
100 *
101 * Hydra_Software_Devel/188   9/9/10 5:27p davidp
102 * SW7420-972: Only include bchp_pwr.h on platforms that support bchp_pwr.
103 *
104 * Hydra_Software_Devel/187   9/9/10 2:59p davidp
105 * SW7420-972: Use BCHP_PWR routines for dynamic power management in XVD.
106 *
107 * Hydra_Software_Devel/186   7/30/10 2:10p pblanco
108 * SW7400-2857: Backed out memory reduction changes.
109 *
110 * Hydra_Software_Devel/184   4/1/10 3:13p davidp
111 * SW7405-4160: Output DBG warning message if power management is not
112 * supported on the platform when code is built to use dymanic PM.
113 *
114 * Hydra_Software_Devel/183   3/8/10 5:46p davidp
115 * SW7405-3849: Increase CABAC memory allocated for AVC and MPEG2 stills.
116 *
117 * Hydra_Software_Devel/182   1/19/10 4:45p davidp
118 * SW7405-3667: Clear decoder context bIfBusy flag on FW command timeout
119 * and when resetting the decoder.
120 *
121 * Hydra_Software_Devel/181   1/6/10 2:28p btosi
122 * SW7405-3137: merged branch into mainline
123 *
124 * Hydra_Software_Devel/180   11/30/09 4:41p btosi
125 * SW7405-3245: added BXVD_DBG_* macros.  Map to either BDBG_INSTANCE_* or
126 * BDBG_* at compile.
127 *
128 * Hydra_Software_Devel/179   9/29/09 4:06p davidp
129 * SW7405-3049: Add 1k to context memory for AVC HD/SD buffers to support
130 * AVC in AVI decode.
131 *
132 * Hydra_Software_Devel/178   7/6/09 3:35p davidp
133 * PR56374: Turn on clocks in BXVD_Close to access AVD FW and AVD
134 * registers.
135 *
136 * Hydra_Software_Devel/177   6/30/09 4:20p davidp
137 * PR56374: Power down AVD related clocks in BXVD_Close.
138 *
139 * Hydra_Software_Devel/176   6/25/09 6:05p davidp
140 * PR56375: Remove unneeded callback for AVD FW command processing. This
141 * fixes the polled debug method of cmd acknowledgement.
142 *
143 * Hydra_Software_Devel/175   6/1/09 11:13p davidp
144 * PR55198: Add conditional around BXVD_P_Hibernate.
145 *
146 * Hydra_Software_Devel/174   6/1/09 6:35p davidp
147 * PR55198: Add dynamic power management support to most STB platforms.
148 *
149 * Hydra_Software_Devel/173   5/27/09 4:38p davidp
150 * PR50178: Keep AVD clocks enabled when closing still compatibility
151 * channel.
152 *
153 * Hydra_Software_Devel/172   4/24/09 12:36p davidp
154 * PR43272: Update BluRay memory configuration picture block size and
155 * count.
156 *
157 * Hydra_Software_Devel/171   4/9/09 5:33p davidp
158 * PR52344: Fix blk size and blk count table lookup.
159 *
160 * Hydra_Software_Devel/170   3/31/09 5:30p davidp
161 * PR52344: Add bAVC51Enable flag to channel settings to use more memory
162 * for AVC 5.1 compliant streams.
163 *
164 * Hydra_Software_Devel/169   2/26/09 3:27p nilesh
165 * PR52516: Added const specifier to static sChannelFWMemCfg_bExcessDir to
166 * adhere to magnum architecture rules
167 *
168 * Hydra_Software_Devel/168   1/27/09 1:48p nilesh
169 * PR51621: Resolved possible global variable naming conflict by either
170 * explicitly declaring globals as static (where possible) or adding
171 * BXVD_P_ prefix
172 *
173 * Hydra_Software_Devel/167   1/21/09 2:02p nilesh
174 * PR45052: Converted BDBG_xxx to BDBG_INSTANCE_xxx calls to support
175 * multiple channels
176 *
177 * Hydra_Software_Devel/166   11/26/08 1:54p davidp
178 * PR49602: Allocate CABAC bin buffer 256 byte aligned.
179 *
180 * Hydra_Software_Devel/165   11/21/08 6:30p davidp
181 * PR48684: Fix compiler warning message.
182 *
183 * Hydra_Software_Devel/164   11/19/08 5:15p davidp
184 * PR48684: Add debug messages to indicate the still picture decode
185 * resolution.
186 *
187 * Hydra_Software_Devel/163   11/14/08 1:42p davidp
188 * PR48684: Remove decode code from BXVD_P_GetStillDecodeFWMemSize.
189 *
190 * Hydra_Software_Devel/162   11/12/08 6:06p davidp
191 * PR48264: Increase cabac bin HD and SD memory size.
192 *
193 * Hydra_Software_Devel/161   11/10/08 11:06a davidp
194 * PR48684: Flag coverity deadcode failure as false.
195 *
196 * Hydra_Software_Devel/160   10/28/08 12:30p davidp
197 * PR47278: Add support for ExcessDirMode, allocate more direct memory for
198 * certain AVC streams when flag is set.
199 *
200 * Hydra_Software_Devel/159   10/23/08 5:08p davidp
201 * PR48295: Stripe width of 256 not currently supported. Do not allow QCIF
202 * and CIF still picture decodes.
203 *
204 * Hydra_Software_Devel/158   9/18/08 2:03p davidp
205 * PR46650: Fix MemCfgMode enum field names, change BDBG_WRN to BDBG_MSG.
206 *
207 * Hydra_Software_Devel/157   9/10/08 4:21p davidp
208 * PR46650: Output a warning when separate picture heap is specified with
209 * a zero picture memory size.
210 *
211 * Hydra_Software_Devel/156   9/8/08 6:42p davidp
212 * PR46650: Add BXVD_P_GET_MEMORY_CONFIG macro and BXVD_P_ValidateHeaps to
213 * sanity check heaps passed to BXVD_Open.
214 *
215 * Hydra_Software_Devel/155   8/28/08 4:54p davidp
216 * PR44341: Add coverity overide comments for false positive coverity
217 * defects.
218 *
219 * Hydra_Software_Devel/154   8/20/08 5:03p davidp
220 * PR43272: Init local vars in
221 * BXVD_P_InitializeFWMemConfigCompatibilityModeTable().
222 *
223 * Hydra_Software_Devel/153   8/5/08 3:56p nilesh
224 * PR45322: BXVD_DMDBG_P_DumpYUV() no longer uses hard coded stripe width
225 *
226 * Hydra_Software_Devel/152   8/4/08 4:07p davidp
227 * PR43272: Update AVC still picture memory table.
228 *
229 * Hydra_Software_Devel/151   8/1/08 4:57p davidp
230 * PR43272: Merge PR43272 branch to mainline, new FW memory configuration
231 * API.
232 *
233 * Hydra_Software_Devel/PR43272/1   7/17/08 12:36p davidp
234 * PR43272: Add support for additional FW memory configuration parameters,
235 * Direct mode and IL Work list memory.
236 *
237 * Hydra_Software_Devel/150   4/21/08 11:13a nilesh
238 * PR41276: Added explicit bounds check for StripeMultiple before using it
239 * to index into an array
240 *
241 * Hydra_Software_Devel/149   4/3/08 2:17p nilesh
242 * PR41276: Fixed possible out of bounds condition for StripeWidth and
243 * StripeMultiple
244 *
245 * Hydra_Software_Devel/148   4/1/08 2:41p davidp
246 * PR27168: Add routine description for
247 * BXVD_P_SetupStillPictureCompatibilityMode
248 *
249 * Hydra_Software_Devel/147   3/25/08 5:20p davidp
250 * PR40316: Merge branch PR40316 changes to mainline, update CABAC bin
251 * sizes per FW doc.
252 *
253 * Hydra_Software_Devel/146   3/18/08 1:58p davidp
254 * PR40316: Reduce cabac memory size for HD AVC still picture decode.
255 *
256 * Hydra_Software_Devel/145   3/17/08 4:41p davidp
257 * PR40316: Temporarily increase the cabac size for AVC HD Still decode.
258 *
259 * Hydra_Software_Devel/144   3/7/08 10:38a nilesh
260 * PR40349: Update memory tables according to AVD Mosaic API doc v2.19
261 *
262 * Hydra_Software_Devel/143   2/13/08 5:06p nilesh
263 * PR39469: Update memory tables according to AVD Mosaic API doc v2.18
264 *
265 * Hydra_Software_Devel/142   1/31/08 12:40p nilesh
266 * PR39174: Updated memory tables to match AVD Mosaic API doc v2.17.
267 * Restructured memory size calculation code.
268 *
269 * Hydra_Software_Devel/141   1/24/08 11:40a nilesh
270 * PR38570: Merge CABAC worklist API changes to mainline
271 *
272 * Hydra_Software_Devel/PR38570/2   1/22/08 2:16p nilesh
273 * PR38570: Fixed compatibility mode memory table for still picture modes
274 *
275 * Hydra_Software_Devel/PR38570/1   1/21/08 5:12p nilesh
276 * PR38570: Added support for cabac worklist buffer and size parameter to
277 * AVD ChannelOpen
278 *
279 * Hydra_Software_Devel/140   1/8/08 11:56a nilesh
280 * PR38570: Updated memory table to match AVD Mosaic API document v2.15
281 *
282 * Hydra_Software_Devel/139   11/19/07 3:37p nilesh
283 * PR36916: Updated context sizes based on AVD Mosaic API document v2.13
284 *
285 * Hydra_Software_Devel/138   11/6/07 2:19p davidp
286 * PR27168: Remove use of SETUP_HEAP macro and associated routines per
287 * code review
288 *
289 * Hydra_Software_Devel/137   9/28/07 12:22p nilesh
290 * PR27168: BXVD_P_ParseDecodeMode now checks for invalid decode mode in
291 * list
292 *
293 * Hydra_Software_Devel/136   9/6/07 5:35p nilesh
294 * PR29915: Added BERR_TRACE wrapper around all return codes
295 *
296 * Hydra_Software_Devel/135   9/4/07 10:10a nilesh
297 * PR29915: Fix error handling in BXVD_OpenChannel() when any error
298 * occurs.  BXVD_CloseChannel() is now called to free any allocated
299 * memory before returning an error.
300 *
301 * Hydra_Software_Devel/134   8/31/07 3:24p nilesh
302 * PR29915: Fix boot result code propogation
303 *
304 * Hydra_Software_Devel/133   8/31/07 11:41a nilesh
305 * PR29915: Fix FGT support for DVD platforms
306 *
307 * Hydra_Software_Devel/132   8/30/07 12:20p nilesh
308 * PR34430: Channel specific heaps are now used for address conversion
309 *
310 * Hydra_Software_Devel/131   8/29/07 4:38p nilesh
311 * PR34430: XVD now supports a general memory size of 0 specified at
312 * BXVD_Open
313 *
314 * Hydra_Software_Devel/130   8/29/07 1:08p nilesh
315 * PR34430: Added support for channel specific memory heaps
316 *
317 * Hydra_Software_Devel/129   8/22/07 3:49p nilesh
318 * PR29915: The FW memory config table for compatibility mode is now
319 * generated on-the-fly at runtime
320 *
321 * Hydra_Software_Devel/128   8/21/07 3:04p davidp
322 * PR34052: Remove nolonger used register addr pointers from BXVD_Handle,
323 * use platform_info.stReg structure to reference registers
324 *
325 * Hydra_Software_Devel/127   8/20/07 4:03p nilesh
326 * PR29915: Fixed size of Atom A for odd multiple of 64
327 *
328 * Hydra_Software_Devel/126   8/20/07 4:02p nilesh
329 * PR29915: Fixed secure heap memory allocation
330 *
331 * Hydra_Software_Devel/125   8/13/07 4:08p nilesh
332 * PR29915: Multi-decode merge to mainline
333 *
334 * Hydra_Software_Devel/xvd_PR29915_Rel_Mosaic_FW_API/25   8/9/07 4:06p nilesh
335 * PR29915: Updated AVC QCIF (1.1) Cabac Size
336 *
337 * Hydra_Software_Devel/xvd_PR29915_Rel_Mosaic_FW_API/24   8/9/07 3:50p nilesh
338 * PR29915: Updated memory tables according to AVD Mosaic Doc v2.11 (Aug
339 * 9, 2007)
340 *
341 * Hydra_Software_Devel/xvd_PR29915_Rel_Mosaic_FW_API/23   7/26/07 4:00p nilesh
342 * PR29915: Add MPEG2 w/o BTP support
343 *
344 * Hydra_Software_Devel/xvd_PR29915_Rel_Mosaic_FW_API/22   7/19/07 5:17p nilesh
345 * PR29915: Fixed stripe_width value in still picture buffer
346 *
347 * Hydra_Software_Devel/xvd_PR29915_Rel_Mosaic_FW_API/21   7/19/07 5:14p nilesh
348 * PR29915: Update BXVD_GetBufferConfig() and BXVD_P_ParseDecodeMode() to
349 * handle BXVD_DecodeMode_eCustom
350 *
351 * Hydra_Software_Devel/xvd_PR29915_Rel_Mosaic_FW_API/20   7/19/07 2:43p nilesh
352 * PR29915: Cleaned up variable naming style
353 *
354 * Hydra_Software_Devel/xvd_PR29915_Rel_Mosaic_FW_API/19   7/17/07 11:35a nilesh
355 * PR29915: Fixed incorrect atom size for MPEG2 QCIF
356 *
357 * Hydra_Software_Devel/xvd_PR29915_Rel_Mosaic_FW_API/18   7/13/07 5:15p nilesh
358 * PR29915: Updated memory tables based on v2.9 of Mosaic API doc
359 *
360 * Hydra_Software_Devel/xvd_PR29915_Rel_Mosaic_FW_API/17   7/10/07 5:18p nilesh
361 * PR29915: Fixed bookkeeping related to still picture channel allocation
362 * when using new API
363 *
364 * Hydra_Software_Devel/xvd_PR29915_Rel_Mosaic_FW_API/16   7/3/07 12:09p nilesh
365 * PR29915: Added FGT support
366 *
367 * Hydra_Software_Devel/xvd_PR29915_Rel_Mosaic_FW_API/15   6/28/07 1:36p davidp
368 * PR29915: Move remaining data structure definitions for
369 * bxvd_devcmds_priv.h to bxvd_vdec_api.h
370 *
371 * Hydra_Software_Devel/xvd_PR29915_Rel_Mosaic_FW_API/14   6/19/07 2:33p nilesh
372 * PR29915: Changed VideoCmprCount -> uiVideoCmprCount to match notation
373 * of other fields in BXVD_ChannelSettings
374 *
375 * Hydra_Software_Devel/xvd_PR29915_Rel_Mosaic_FW_API/13   6/19/07 12:13p nilesh
376 * PR29915: Merge from mainline
377 *
378 * Hydra_Software_Devel/124   6/5/07 1:40p davidp
379 * PR31721: Clear edge triggered BVNF register after FW is reloaded and
380 * started.
381 *
382 * Hydra_Software_Devel/123   4/24/07 1:39p nilesh
383 * PR22766: Added support for new FW API to provide FGT buffer address and
384 * size
385 *
386 * Hydra_Software_Devel/122   3/27/07 2:02p pblanco
387 * PR27168: Removed deprecated bxvd_mem.h include.
388 *
389 * Hydra_Software_Devel/121   3/2/07 1:36p nilesh
390 * PR26188: Merged 7400B0 bring-up branch to mainline.  Cleaned up heap
391 * naming and usage.
392 *
393 * Hydra_Software_Devel/PR26188/3   2/28/07 4:27p nilesh
394 * PR26188: Fixed incorrect calculation of FW Context base phy addr on
395 * 7400B0
396 *
397 * Hydra_Software_Devel/PR26188/2   2/27/07 6:03p nilesh
398 * PR26188: Remove hack to set picture buffer address on 7400B0
399 *
400 * Hydra_Software_Devel/PR26188/1   2/27/07 4:05p nilesh
401 * PR26188: 7400B0 Bring-Up
402 *
403 * Hydra_Software_Devel/120   2/26/07 8:47p nilesh
404 * PR26188: 7400B0 Bring Up - Hack to get private video memory addresses
405 * sent to fw correctly
406 *
407 * Hydra_Software_Devel/119   2/6/07 11:07a nilesh
408 * PR27575: Fix 7440 Watchdog and make watchdog more robust on all
409 * platforms.
410 *
411 * Hydra_Software_Devel/PR27575/1   2/2/07 2:12p nilesh
412 * PR27575: Fix 7440 Watchdog
413 *
414 * Hydra_Software_Devel/117   12/12/06 3:00p davidp
415 * PR25443: Merge Simplified FW API branch into mainline
416 *
417 * Hydra_Software_Devel/116   12/11/06 2:51p nilesh
418 * PR26414: Merge branch PR26414 to mainline
419 *
420 * Hydra_Software_Devel/PR26414/1   12/11/06 10:53a nilesh
421 * PR26414: Added AVD response callback error handling during a watchdog
422 * reset
423 *
424 * Hydra_Software_Devel/115   11/17/06 4:50p nilesh
425 * PR25868: Merged authenticated image support to mainline
426 *
427 * Hydra_Software_Devel/PR25868/1   11/16/06 3:35p nilesh
428 * PR25868: Added error checking
429 *
430 * Hydra_Software_Devel/114   10/20/06 3:16p davidp
431 * PR25038: Enabled HD still picture decode when BXVD_DecodeMode_eAll is
432 * in decode mode list.
433 *
434 * Hydra_Software_Devel/113   9/22/06 2:22p davidp
435 * PR22867: Update FW memory usage table, add secure memory heap support.
436 *
437 * Hydra_Software_Devel/112   9/5/06 3:05p davidp
438 * PR22867: Merge secure heap (Cabac) support
439 *
440 * Hydra_Software_Devel/xvd_cabac_heap/1   8/30/06 5:10p davidp
441 * 22867: Separate FW memory so Cabac bin memory can me moved to secure
442 * heap.
443 *
444 * Hydra_Software_Devel/111   7/19/06 11:22a pblanco
445 * PR22673: Added the remainder of bxvd_priv.c conditionalized code to
446 * platform and core modules.
447 *
448 * Hydra_Software_Devel/110   7/18/06 3:30p pblanco
449 * PR22673: Moved FW load to platform appropriate modules for 7400, 7401
450 * and 7118.
451 *
452 * Hydra_Software_Devel/109   7/18/06 10:16a pblanco
453 * PR22673: Added additional comments to clarify the boundaries of the
454 * 7400, 7401 and 7118 conditional code.
455 *
456 * Hydra_Software_Devel/108   7/18/06 12:11a nilesh
457 * PR22673: Code restructure for 97400, 97401 B0, and 97118
458 *
459 * Hydra_Software_Devel/PR22673/2   7/17/06 2:51p nilesh
460 * PR22673: Restructure on 97400
461 *
462 * Hydra_Software_Devel/PR22673/1   7/17/06 2:33p nilesh
463 * PR22673: Restructure on 97401
464 *
465 * Hydra_Software_Devel/107   7/17/06 1:56p pblanco
466 * PR22673: Removed 7401a0 conditionalized code and restructured some of
467 * the remaining conditional code.
468 *
469 * Hydra_Software_Devel/106   7/13/06 4:56p davidp
470 * PR22673: Add BXVD_P_SetWatchdog_7401B0 routine, remove some 7401A0
471 * support.
472 *
473 * Hydra_Software_Devel/105   7/13/06 1:46p davidp
474 * PR20017: Add 7118 L2 AVD interrupt definition include file
475 *
476 * Hydra_Software_Devel/104   7/12/06 4:48p davidp
477 * PR20017: Cleanup BXVD_Open, add platform specific setup routines
478 *
479 * Hydra_Software_Devel/103   7/11/06 5:06p davidp
480 * PR20017: Add FW inner loop Watchdog support, also add platform specific
481 * SetupInterrupts routines
482 *
483 * Hydra_Software_Devel/102   7/6/06 9:55a pblanco
484 * PR21943: Conditionalized for 7118. Somehow this was missed yesterday.
485 *
486 * Hydra_Software_Devel/100   6/28/06 4:45p davidp
487 * PR20017: FW end of code register is actually the size of the FW code
488 * region.
489 *
490 * Hydra_Software_Devel/99   6/22/06 1:47p pblanco
491 * PR22301: Removed include of bmem_priv.h
492 *
493 * Hydra_Software_Devel/98   6/13/06 10:58a pblanco
494 * PR22093: Made suggested changes based on the PR details.
495 *
496 * Hydra_Software_Devel/97   6/12/06 6:09p davidp
497 * PR20017: Allocate memory for FW code out of framework heap.
498 *
499 * Hydra_Software_Devel/96   6/9/06 6:25p davidp
500 * PR21846: Fixed compiler warnings caused by gcc option "-O3"
501 *
502 * Hydra_Software_Devel/95   6/8/06 9:18a pblanco
503 * PR20017: Changed chip version test conditionals from A0 and B0 to
504 * BCHP_VER_A0 and BCHP_VER_B0 to conform with the rest of magnum.
505 *
506 * Hydra_Software_Devel/94   5/26/06 4:37p davidp
507 * PR20017: Disable FW mailbox polling for all but 7401 B0
508 *
509 * Hydra_Software_Devel/93   5/25/06 4:17p pblanco
510 * PR20017: Changed global IO register from CPUREGS to CPUREGS2.
511 *
512 * Hydra_Software_Devel/92   5/25/06 3:52p pblanco
513 * PR20017: Change heap referenced by B0 communication vectors.
514 *
515 * Hydra_Software_Devel/91   5/25/06 3:09p pblanco
516 * PR20017: Reloc sanity check in.
517 *
518 * Hydra_Software_Devel/90   5/24/06 12:11p pblanco
519 * PR20017: Removed offset from inner loop end of code address. It's
520 * already offset by the relocation engine.
521 *
522 * Hydra_Software_Devel/89   5/24/06 11:16a pblanco
523 * PR20017: Code now uses defined constant for inner loop address offset
524 * instead of a hardwired value.
525 *
526 * Hydra_Software_Devel/88   5/24/06 10:07a pblanco
527 * PR20017: Pull relocation address from XVD context structure.
528 *
529 * Hydra_Software_Devel/87   5/24/06 10:02a pblanco
530 * PR20017: Added code necessary to enable execution of relocated FW.
531 *
532 * Hydra_Software_Devel/86   5/23/06 4:05p pblanco
533 * PR20017: Pull in bchp_decode_cpuregs.h
534 *
535 * Hydra_Software_Devel/85   5/23/06 2:41p pblanco
536 * PR20017: Conditionalized the relocatable vs non-relocatable FW load by
537 * chip revision type.
538 *
539 * Hydra_Software_Devel/84   5/18/06 9:54a pblanco
540 * PR21612: Made sure we don't attempt to use an unassigned data pointer
541 * and removed the dereference from the pointer increment.
542 *
543 * Hydra_Software_Devel/83   5/16/06 10:20a pblanco
544 * PR20649: Cleanup for B0. Conditionals must be replaced or removed in
545 * later development.
546 *
547 * Hydra_Software_Devel/82   5/15/06 1:43p pblanco
548 * PR20017: Moved external references for relocatable FW arrays to
549 * bxvd_img.h
550 *
551 * Hydra_Software_Devel/81   5/11/06 3:03p pblanco
552 * PR20017: Fixed relocatable FW load addresses.
553 *
554 * Hydra_Software_Devel/80   5/10/06 4:18p pblanco
555 * PR20017: Changed from header based FW code to C source base.
556 *
557 * Hydra_Software_Devel/79   5/10/06 11:01a pblanco
558 * PR19877: Removed unused host commands identified by Gaurav.
559 *
560 * Hydra_Software_Devel/78   5/5/06 2:10p davidp
561 * PR21156: Add BXVD_P_ReleasePPB_isr and related _isr routines for DM to
562 * use at ISR time.
563 *
564 * Hydra_Software_Devel/77   5/5/06 1:23p pblanco
565 * PR20017: Incremental relocation code checkin.
566 *
567 * Hydra_Software_Devel/76   5/4/06 3:01p pblanco
568 * PR20017: Initial relocatable test code on 7401a0. Checked in with
569 * "normal" code paths active (no relocation).
570 *
571 * Hydra_Software_Devel/75   4/26/06 11:51a pblanco
572 * PR20649: Added temporary definition of
573 * BCHP_DECODE_CPUREGS2_REG_CPU_INT_BASE_1 until the name is fixed in
574 * CHP. It is _INST_ instead of _INT_ in rdb/b0.
575 *
576 * Hydra_Software_Devel/74   4/24/06 2:11p davidp
577 * PR18043: Add support for Sequence Header interrupt processing
578 *
579 * Hydra_Software_Devel/73   4/17/06 3:57p pblanco
580 * PR1923: Modified BXVD_P_SVChipEnableExecution to use page register init
581 * value definitions instead of hard coded values.
582 *
583 * Hydra_Software_Devel/72   4/12/06 12:49p davidp
584 * PR19600: Move 7401 FW load address to 48mb, also decrease size to 1mb
585 *
586 * Hydra_Software_Devel/71   3/29/06 2:07p pblanco
587 * PR19877: Added BXVD_P_GetSeqHdr API.
588 *
589 * Hydra_Software_Devel/70   3/22/06 5:16p davidp
590 * PR20347: Add L2 interrupt support
591 *
592 * Hydra_Software_Devel/69   3/6/06 8:47a pblanco
593 * PR20017: Check in of Olive's changes after successful weekend
594 * regression test.
595 *
596 * Hydra_Software_Devel/67   2/13/06 3:38p pblanco
597 * PR19123: Disable enabling of L2 interrupts during chip initialization.
598 *
599 * Hydra_Software_Devel/66   2/2/06 4:04p pblanco
600 * PR19123: More code cleanup. Changed all instances of uAvcInstance to
601 * uDecoderInstance and removed last remaining references to the old
602 * decoder context array.
603 *
604 * Hydra_Software_Devel/65   2/2/06 1:29p pblanco
605 * PR19085: Moved manually generated register define from bchp_7401.h to
606 * source.
607 *
608 * Hydra_Software_Devel/64   2/2/06 10:56a pblanco
609 * PR19123: Only reset the appropriate instance of the decoder on init.
610 *
611 * Hydra_Software_Devel/63   2/1/06 3:54p pblanco
612 * PR19123: Changed "AVC" instance array in XVD context structure to a
613 * single instance of type BXVD_DecoderContext. Tested against 7401 with
614 * no regressions and against 7400 with no regressions.
615 *
616 * Hydra_Software_Devel/62   1/30/06 2:42p pblanco
617 * PR19123: Clean up decoder instance usage throughout code.
618 *
619 * Hydra_Software_Devel/61   1/27/06 4:16p pblanco
620 * PR19123: Reversed order of shim register initialization (DB & PFRI) as
621 * requested by Olive. Also removed some unused GPIO initialization code.
622 *
623 * Hydra_Software_Devel/60   1/27/06 1:38p pblanco
624 * PR19123: Modified GPIO pin-mux setup to work with new kernel spin. Now
625 * all UARTs are where they should be.
626 *
627 * Hydra_Software_Devel/59   1/26/06 5:34p davidp
628 * PR19123: Remove OS specific include file usage:
629 *
630 * Hydra_Software_Devel/58   1/26/06 4:03p davidp
631 * PR19123: Remove printf debug messages, clean up compiler warnings:
632 *
633 * Hydra_Software_Devel/57   1/25/06 6:53p davidp
634 * PR19123: Add platform specific definition of FS_MAP_SIZE:
635 *
636 * Hydra_Software_Devel/56   1/25/06 11:51a pblanco
637 * PR19123: Added debugging printfs for 7400 (will be removed later).
638 *
639 * Hydra_Software_Devel/54   1/24/06 2:51p pblanco
640 * PR19123: 7400 firmware bring up debugging changes.
641 *
642 * Hydra_Software_Devel/53   1/23/06 1:46p pblanco
643 * PR19123: Added correct page register initialization based on Ray's
644 * calculations.
645 *
646 * Hydra_Software_Devel/52   1/20/06 11:01a pblanco
647 * PR19123: Fix link error caused by 7400 external definitions.
648 *
649 * Hydra_Software_Devel/51   1/20/06 10:53a pblanco
650 * PR19123: Support for 7400 decoder instances.
651 *
652 * Hydra_Software_Devel/50   1/18/06 2:09p pblanco
653 * PR19123: Modifications for 7400 port so code will build for xvd_test on
654 * that platform.
655 *
656 * Hydra_Software_Devel/49   1/18/06 10:04a pblanco
657 * PR19123: Initial porting work for 7400 FW loading and initialization.
658 *
659 * Hydra_Software_Devel/48   1/16/06 1:28p davidp
660 * PR16792: BXVD_Open now uses two heap pointers, one for FW code (2MB)
661 * the other for FW picture buffers.:
662 *
663 * Hydra_Software_Devel/47   1/13/06 11:42a pblanco
664 * PR16052: Initial 7400 porting changes.
665 *
666 * Hydra_Software_Devel/46   1/9/06 12:42p pblanco
667 * PR16052: Removed unused code and did some general code cleanup before
668 * 7400 port.
669 *
670 * Hydra_Software_Devel/45   12/22/05 1:30p pblanco
671 * PR16052: Temporary fix to send still picture decode flag to FW.
672 *
673 * Hydra_Software_Devel/44   12/9/05 3:19p vsilyaev
674 * PR 18019: Fixed include files
675 *
676 * Hydra_Software_Devel/43   12/2/05 9:58a pblanco
677 * PR16052: Moved BXVD_ReleasePPB to BXVD_P_ReleasePPB.
678 *
679 * Hydra_Software_Devel/42   11/28/05 3:06p davidp
680 * PR18263: Remove addition unused posix include files:
681 *
682 * Hydra_Software_Devel/41   11/28/05 2:58p davidp
683 * PR18263: OS dependant include files removed, not needed:
684 *
685 * Hydra_Software_Devel/40   11/15/05 11:15a pblanco
686 * PR16052: Removed queueing code and disabled XVD control of ARC UARTS.
687 *
688 * Hydra_Software_Devel/39   11/10/05 1:35p pblanco
689 * PR16052: Turn off FW relocation.
690 *
691 * Hydra_Software_Devel/38   11/10/05 7:52a pblanco
692 * PR16052: FW now uses heap info to determine load and execution
693 * addresses. Also removed unused code that existed when XVD used to
694 * create and map its own heap. Corresponding changes were made in
695 * related modules also checked in at this time.
696 *
697 * Hydra_Software_Devel/37   11/8/05 1:00p pblanco
698 * PR16052: Changed register defines to new values. Also some (commented
699 * out) changes for relocatable FW.
700 *
701 * Hydra_Software_Devel/36   11/4/05 9:17a pblanco
702 * PR16052: Conditionalized return value declaration for XVD UART control.
703 *
704 * Hydra_Software_Devel/35   11/1/05 8:09a pblanco
705 * PR16052: Moved bxvd_arc_load.h include into conditional section.
706 *
707 * Hydra_Software_Devel/34   10/26/05 10:16a davidp
708 * PR16052: Cleaned up compiler warnings:
709 *
710 * Hydra_Software_Devel/33   10/25/05 7:58p davidp
711 * PR16052: Fix compiler warnings and remove <CR> from report message
712 * strings:
713 *
714 * Hydra_Software_Devel/32   10/21/05 6:43a pblanco
715 * PR16052: This checkin contains a temporary fix for ARC UART control
716 * until it is implemented in the app layer. It also contains a new
717 * version of the relocatable firmware code which can be conditionalized
718 * out until we're comfortable with all the issues. By default this code
719 * is built with relocatable FW off and the temporary UART code on.
720 *
721 * Hydra_Software_Devel/31   10/19/05 7:04a pblanco
722 * PR17672: Removed code that overwrote I2C pin mux settings.
723 *
724 * Hydra_Software_Devel/30   10/11/05 6:39p davidp
725 * PR17374: Remove mmap calls, let application allocate FW memory regions:
726 *
727 * Hydra_Software_Devel/29   10/7/05 3:30p pblanco
728 * PR16052: Added queue management APIs.
729 *
730 * Hydra_Software_Devel/28   10/4/05 9:50a pblanco
731 * PR16052: Added some BDBG_MSG output to dump start of FW and shared
732 * memory.
733 *
734 * Hydra_Software_Devel/27   9/29/05 5:59p pblanco
735 * PR16052: Checked in Dave's changes to reduce debug output.
736 *
737 * Hydra_Software_Devel/26   9/26/05 6:35p davidp
738 * PR16052: Use BMEM_CreateHeapSystem to force BMEM to not use the created
739 * heap for bookkeeping structure.:
740 *
741 * Hydra_Software_Devel/25   9/26/05 2:26p pblanco
742 * PR16052: Added experimental code to convert vaddr to physical offset.
743 *
744 * Hydra_Software_Devel/24   9/22/05 2:58p davidp
745 * PR16052: Create BMEM heap for the FW/XVD shared memory block to allow
746 * VDC to use BMEM calls to translate VM/Phys addresses:
747 *
748 * Hydra_Software_Devel/23   9/16/05 8:36a pblanco
749 * PR16052: Moved decoder control functions pause, resume and reset from
750 * bxvd.c to private (_P_) functions.
751 *
752 * Hydra_Software_Devel/22   9/8/05 8:55p davidp
753 * PR16052: Add AVD reset to BXVD_P_Reset7401 routine:
754 *
755 * Hydra_Software_Devel/20   9/6/05 1:09p pblanco
756 * PR16052: Changed BXVD_P_GetFWVOffset to determine if the physical
757 * address argument is in the FW or shared memory area and return the
758 * appropriate virtual address.
759 *
760 * Hydra_Software_Devel/19   9/6/05 10:25a pblanco
761 * PR16052: Added new function protoypes for physical to virtual address
762 * translation and moved some defines from bxvd_priv.c
763 *
764 * Hydra_Software_Devel/18   9/2/05 10:05a pblanco
765 * PR16052: Fixed compile errors when DEBUG=y.
766 *
767 * Hydra_Software_Devel/17   8/31/05 3:04p pblanco
768 * PR16052: Moved the shared memory area up in memory.
769 *
770 * Hydra_Software_Devel/16   8/29/05 8:37a pblanco
771 * PR16052: Support for new FW.
772 *
773 * Hydra_Software_Devel/15   8/25/05 1:37p pblanco
774 * PR16052: mmap failure now returns a BXVD error code instead of -1.
775 *
776 * Hydra_Software_Devel/14   8/24/05 1:14p pblanco
777 * PR16052: Added support for multiple AVC instances and cleaned up some
778 * code.
779 *
780 * Hydra_Software_Devel/13   8/18/05 2:12p pblanco
781 * PR16052: Code fixes for BXVD_OpenChannel and BXVD_StartDecode.
782 *
783 * Hydra_Software_Devel/12   8/16/05 1:06p pblanco
784 * PR16052: FW download and execution are working... this is a sanity
785 * checkin.
786 *
787 * Hydra_Software_Devel/11   8/12/05 7:03a pblanco
788 * PR16052: Sanity checkin so Dave can build the latest test harness code.
789 *
790 * Hydra_Software_Devel/10   8/5/05 3:46p pblanco
791 * PR16052: Many changes to support firmware downloading.
792 *
793 * Hydra_Software_Devel/9   7/26/05 11:34a pblanco
794 * PR16052: Changed DRAM configuration code after talking to Gaurav.
795 *
796 * Hydra_Software_Devel/8   7/26/05 10:29a pblanco
797 * PR16052: Added DRAM setup and chip reset code.
798 *
799 * Hydra_Software_Devel/7   7/25/05 4:01p pblanco
800 * PR16052: Code changes per review with Jason. Moved locally defined
801 * error code to bxvd_error.h
802 *
803 * Hydra_Software_Devel/6   7/25/05 12:26p ebrakus
804 * PR16052: use Avc contexts
805 *
806 * Hydra_Software_Devel/5   7/22/05 11:36a pblanco
807 * PR16052: Code cleanup and data structure factoring.
808 *
809 * Hydra_Software_Devel/4   7/15/05 1:08p pblanco
810 * PR16052: Clean build with new code and data.
811 *
812 * Hydra_Software_Devel/3   7/13/05 12:33p pblanco
813 * PR16052: Changed ARC memory and register references to XVD.
814 *
815 * Hydra_Software_Devel/1   7/13/05 8:40a pblanco
816 * PR16052: Initial check in with some code additions.
817 *
818 ***************************************************************************/
819#include "bstd.h"
820#include "bkni.h"          /* For malloc */
821#include "bmem.h"
822#include "bxvd.h"
823#include "bxvd_platform.h"
824#include "bxvd_priv.h"
825#include "bxvd_img.h"
826#include "bxvd_reg.h"
827#include "bxvd_errors.h"
828#include "bxvd_intr.h"
829
830#ifdef BCHP_PWR_SUPPORT
831#include "bchp_pwr.h"
832#endif
833
834#define BXVD_P_TEST_CHUNK 16
835
836/*
837 * For testing during initial bringup, we may not want to send an init host
838 * command, so setting this define to 0 will skip the init.
839 */
840#define FW_INIT 1
841
842/* Temporary until this is properly defined */
843#ifndef BCHP_DECODE_CPUREGS2_REG_CPU_INT_BASE_1
844#define BCHP_DECODE_CPUREGS2_REG_CPU_INT_BASE_1 0x00800f8c
845#endif
846
847/* AVD Memory requirements based on "AVD Core Mosaic Mode API", Rev
848 * 2.19, March 3, 2008 */
849
850#define BXVD_P_STRIPE_VIDEO_ATOM_NUM 10
851
852static const uint32_t sVideoAtomSize[BXVD_P_STRIPE_WIDTH_NUM][BXVD_P_STRIPE_MULTIPLE_NUM][BXVD_P_STRIPE_VIDEO_ATOM_NUM] =
853{
854   {
855      {3194880,  688128,  172032,  159744, 2064384, 6389760, 5898240, 12779520, 6389760, 3207168}, /* 0/0 (64/32) */
856      {3276800,  688128,  196608,  221184, 2064384, 6389760, 6553600, 12779520, 6881280, 3203072}, /* 0/1 (64/64) */
857      {3440640,  786432,  294912,  294912, 2359296, 6881280, 6553600, 13762560, 7864320, 3342336}  /* 0/2 (64/128) */
858   },   
859   {
860      {3194880,  688128,  172032,  196608, 2064384, 6389760, 5898240, 12779520, 6389760, 3391488}, /* 1/0 (128/32) */
861      {3276800,  688128,  196608,  294912, 2064384, 6389760, 6553600, 12779520, 6881280, 3391488}, /* 1/1 (128/64) */
862      {3440640,  786432,  294912,  393216, 2359296, 6881280, 6553600, 13762560, 7864320, 3538944}  /* 1/2 (128/128) */
863   }
864};
865
866/* Only stripe widths of 64 and 128 are supported. */ 
867const uint32_t BXVD_P_StripeWidthLUT[BXVD_P_STRIPE_WIDTH_NUM] =
868{
869   64,
870   128
871};
872
873typedef enum BXVD_VideoProtocol
874{
875   BXVD_VideoProtocol_eAVC,   /* AVC, H264 */
876   BXVD_VideoProtocol_eMPEG2, /* MPEG2, H261, H263, MPEG1, MPEG2DTV, MPEG2_DSS_PES */
877   BXVD_VideoProtocol_eVC1,   /* VC1, VC1-SM */
878   BXVD_VideoProtocol_eMPEG4, /* MPEG2 Part 2, DivX */
879   BXVD_VideoProtocol_eAVS,   /* AVS */
880   BXVD_VideoProtocol_eVP8,   /* VP8 */
881   BXVD_VideoProtocol_eMVC,   /* Multi View Coding */
882   BXVD_VideoProtocol_eSVC,   /* Scaleable Video Coding */
883   
884   /* Add new protocols ABOVE this line */
885   BXVD_VideoProtocol_eMax
886} BXVD_VideoProtocol;
887
888static const BXVD_P_FWMemConfig_V2 sChannelFWMemCfg[BXVD_VideoProtocol_eMax][BXVD_DecodeResolution_eMaxModes] =
889{  /* Context, InnerLoop WL, DirectMode, Cabac bin,  Cabac WL,  Vid Blk (index),  Blk Cnt */
890
891   /* BXVD_VideoProtocol_eAVC */
892   { 
893      {261440, 1572864, 1638400, 5210112, 131072, BXVD_P_VideoAtomIndex_eA, 7}, /* AVC HD */
894      {261440,  786432,  388800, 2084864,  65536, BXVD_P_VideoAtomIndex_eE, 3}, /* AVC SD */
895      {261440,  393216,  221760,  417792,  16384, BXVD_P_VideoAtomIndex_eC, 9}, /* AVC CIF */
896      {261440,  196608,   44000,  106496,  16384, BXVD_P_VideoAtomIndex_eD, 4}  /* AVC QCIF */
897   },
898
899   /* BXVD_VideoProtocol_eMPEG2 */
900   { 
901      {154944, 65536, 0, 2097152, 131072, BXVD_P_VideoAtomIndex_eA, 6}, /* MPEG2 HD w/ BTP */
902      {154944, 65536, 0, 1048576,  65536, BXVD_P_VideoAtomIndex_eB, 6}, /* MPEG2 SD w/ BTP */
903      {154944, 16384, 0,  312448,  16384, BXVD_P_VideoAtomIndex_eC, 5}, /* MPEG2 CIF */
904      {154944, 16384, 0,   54656,  16384, BXVD_P_VideoAtomIndex_eD, 2}  /* MPEG2 QCIF */
905   },
906
907   /* BXVD_VideoProtocol_eVC1 */
908   { 
909      {154944,  917504, 103680, 3906176, 131072, BXVD_P_VideoAtomIndex_eA, 5}, /* VC1 HD */
910      {154944,  204800,  21632, 1562496,  65536, BXVD_P_VideoAtomIndex_eB, 5}, /* VC1 SD */
911      {154944,  102400,   5888,  312448,  16384, BXVD_P_VideoAtomIndex_eC, 5}, /* VC1 CIF */
912      {154944,  102400,   1792,   54656,  16384, BXVD_P_VideoAtomIndex_eD, 2}  /* VC1 QCIF */
913   },
914
915   /* BXVD_VideoProtocol_eMPEG4 */
916   { 
917      {154944, 98304, 168960, 3906176, 131072, BXVD_P_VideoAtomIndex_eA, 5}, /* MPEG4/DivX HD */
918      {154944, 98304,  34624, 1562496,  65536, BXVD_P_VideoAtomIndex_eB, 5}, /* MPEG4/DivX SD */
919      {154944, 20480,   9024,  312448,  16384, BXVD_P_VideoAtomIndex_eC, 5}, /* MPEG4/DivX CIF */
920      {154944, 20480,   2560,   54656,  16384, BXVD_P_VideoAtomIndex_eD, 2}  /* MPEG4/DivX QCIF */
921   },
922
923   /* BXVD_VideoProtocol_eAVS */
924   { 
925      {154944, 65536, 587520, 3906176, 131072, BXVD_P_VideoAtomIndex_eA, 5}, /* AVS HD */
926      {154944, 65536, 116600, 1562496,  65536, BXVD_P_VideoAtomIndex_eB, 5}, /* AVS SD */
927      {154944, 16384,  28512,  312448,  16384, BXVD_P_VideoAtomIndex_eC, 5}, /* AVS CIF */
928      {154944, 16384,   7128,   54656,  16384, BXVD_P_VideoAtomIndex_eD, 2}  /* AVS QCIF */
929   },
930
931   /* BXVD_VideoProtocol_eVP8 */
932   { 
933      {154944, 917504, 2774420, 5210112, 131072, BXVD_P_VideoAtomIndex_eA, 5}, /* VP8 HD */
934      {154944, 204800,   21632, 1562496,  65536, BXVD_P_VideoAtomIndex_eB, 5}, /* VP8 SD */
935      {154944, 102400,    5888,  312448,  16384, BXVD_P_VideoAtomIndex_eC, 5}, /* VP8 CIF */
936      {154944, 102400,    1792,   54656,  16384, BXVD_P_VideoAtomIndex_eD, 2}  /* VP8 QCIF */
937   }
938};
939
940static const BXVD_P_FWMemConfig_V2 sChannelStillFWMemCfg[BXVD_VideoProtocol_eMax][BXVD_DecodeResolution_eSD+1] =
941{  /* Context, InnerLoop WL, DirectMode, Cabac bin,  Cabac WL,  Vid Blk (index),  Blk Cnt */
942
943   /* BXVD_VideoProtocol_eAVC */
944   {
945      { 261440, 131072, 0, 921600, 8192, BXVD_P_VideoAtomIndex_eA, 1}, /* AVC HD Still */
946      { 261440,  32768, 0, 409600, 8192, BXVD_P_VideoAtomIndex_eB, 1}  /* AVC SD Still */
947   },
948   
949   /* BXVD_VideoProtocol_eMPEG2 */
950   {
951      { 154944, 1024, 0, 921600, 8192, BXVD_P_VideoAtomIndex_eA, 1}, /* MPEG2 HD Still */
952      { 154944, 1024, 0, 204800, 8192, BXVD_P_VideoAtomIndex_eB, 1}  /* MPEG2 SD Still */
953   },
954
955   /* BXVD_VideoProtocol_eVC1 */
956   {
957      { 154944, 8192, 0, 307200, 8192, BXVD_P_VideoAtomIndex_eA, 1}, /* VC1 HD Still */
958      { 154944, 8192, 0, 204800, 8192, BXVD_P_VideoAtomIndex_eB, 1}  /* VC1 SD Still */
959   },
960
961   /* BXVD_VideoProtocol_eMPEG4 */
962   {
963      { 154944, 1024, 0, 307200, 8192, BXVD_P_VideoAtomIndex_eA, 1}, /* MPEG4/DivX HD Still */
964      { 154944, 1024, 0, 204800, 8192, BXVD_P_VideoAtomIndex_eB, 1}  /* MPEG4/DivX SD Still */
965   },
966
967   /* BXVD_VideoProtocol_eAVS */
968   {
969      { 154944, 1024, 0, 307200, 8192, BXVD_P_VideoAtomIndex_eA, 1}, /* AVS HD Still */
970      { 154944, 1024, 0, 204800, 8192, BXVD_P_VideoAtomIndex_eB, 1}  /* AVS SD Still */
971   }
972};
973
974
975static const BXVD_P_FWMemConfig_V2 sChannelFWMemCfg_BluRay[2] =
976{ /* Context, InnerLoop WL, DirectMode, Cabac bin,  Cabac WL,  Vid Blk (index),  Blk Cnt */
977
978   /* BXVD_VideoProtocol_eAVC for BluRay*/
979   {261440, 786432, 1638400, 4194304, 131072, BXVD_P_VideoAtomIndex_eA, 7}, /* AVC HD */
980   {261440, 524288,  388800, 2084864,  65536, BXVD_P_VideoAtomIndex_eE, 3}  /* AVC SD */
981};
982
983static const BXVD_P_FWMemConfig_V2 sChannelFWMemCfg_AVC41[1] =
984{ 
985   /* BXVD_VideoProtocol_eAVC 4.1 */
986   {261440, 3145728, 1638400, 13107200, 131072, BXVD_P_VideoAtomIndex_eA, 7} /* AVC 4.1 HD */
987};
988
989static const BXVD_P_FWMemConfig_V2 sChannelFWMemCfg_AVC51[1] =
990{ 
991   /* BXVD_VideoProtocol_eAVC 5.1 */
992   {261440, 3145728, 5570560, 13107200, 131072, BXVD_P_VideoAtomIndex_eF, 9} /* AVC 5.1 HD */
993};
994
995/* Support AVC streams that require more direct memory to be decoded. The streams are
996   non compliant, however other STBs in the world decode them, so our customer would
997   like this chip to decode the streams as well */
998
999static const BXVD_P_FWMemConfig_V2 sChannelFWMemCfg_bExcessDir[2] =
1000{ 
1001   /* Context, IL WL, DirectMode, Cabac bin,  Cabac WL,  Vid Blk (index),  Blk Cnt */
1002
1003   {261440, 1572864, (1638400*2), 5210112, 131072, BXVD_P_VideoAtomIndex_eA, 7}, /* AVC HD */
1004   {261440,  786432,  (388800*2), 2084864,  65536, BXVD_P_VideoAtomIndex_eE, 3}, /* AVC SD */
1005};
1006
1007static const BXVD_P_FWMemConfig_V2 sChannelFWMemCfg_MVC[1] =
1008{ 
1009   /* BXVD_VideoProtocol_eMVC 4.1 */
1010   {522880, 1572864, 3276800, 10420224, 131072, BXVD_P_VideoAtomIndex_eF, 7} /* MVC 4.1 HD */
1011};
1012
1013
1014static const BXVD_P_FWMemConfig_SVC sChannelFWMemCfg_SVC[3] =
1015{
1016   /* Context, IL WL,  DirectMode,     Inter Video,          Inter MV,  Cabac bin,  Cabac WL,  Vid Blk (index),      Blk Cnt */
1017   {522880,   3145728,  1638400,   BXVD_P_VideoAtomIndex_eI,  2219520,   9961472,    131072,   BXVD_P_VideoAtomIndex_eA, 7}, /* Interlaced */
1018   {522880,   3145728,  1638400,   BXVD_P_VideoAtomIndex_eG,  2219520,   9961472,    131072,   BXVD_P_VideoAtomIndex_eA, 7}, /* Progressive */
1019   {522880,   3145728,  1638400,   BXVD_P_VideoAtomIndex_eH,  2219520,   9961472,    131072,   BXVD_P_VideoAtomIndex_eA, 7}, /* 3D */
1020};
1021
1022BDBG_MODULE(BXVD_PRIV);
1023
1024void BXVD_P_ValidateHeaps(BXVD_Handle        hXvd,
1025                          BXVD_P_MemCfgMode  eMemCfgMode)
1026{
1027   /* UMA memory configuration */
1028   if (eMemCfgMode == BXVD_P_MemCfgMode_eUMA)
1029   {
1030      if (hXvd->hSystemHeap != hXvd->hPictureHeap)
1031      {
1032         BXVD_DBG_MSG(hXvd, ("UMA Mode, Picture buffers using separate heap"));
1033      }
1034      else
1035      {
1036         BXVD_DBG_MSG(hXvd, ("UMA Mode, Picture buffers using system heap as expected."));
1037      }
1038   } 
1039
1040   /* NON-UMA memory configuration */
1041   else if (eMemCfgMode == BXVD_P_MemCfgMode_eNONUMA)
1042   {
1043      if (hXvd->hSystemHeap == hXvd->hPictureHeap)
1044      {
1045         BXVD_DBG_WRN(hXvd, ("****NON UMA MODE Error: Picture buffers should not use system heap"));
1046      }
1047      else
1048      {
1049         BXVD_DBG_MSG(hXvd, ("NON-UMA Mode, Picture buffers using separate heap as expected."));
1050      }
1051   }
1052
1053   /* UNKNOWN memory configuration */
1054   else
1055   {
1056      if (hXvd->hSystemHeap == hXvd->hPictureHeap)
1057      {
1058         BXVD_DBG_MSG(hXvd, ("UMA Mode, Picture buffers using system heap."));
1059      }
1060      else
1061      {
1062         BXVD_DBG_MSG(hXvd, ("UNKNOWN UMA/NON UMA Mode, Picture buffers using separate heap."));
1063      }
1064   }
1065
1066   /* If private picture heap is specified, but the specified picture heap size is 0, output a warning.
1067    * This use of the API is most likely not intentional. Non zero general heap size indicates custom
1068    * memory decode mode. Old memory API method (compatibility mode) will have a zero picture heap size. */
1069
1070   if ((hXvd->hSystemHeap != hXvd->hPictureHeap) && 
1071       (hXvd->stSettings.stFWMemConfig.uiPictureHeapSize == 0) &&
1072       (hXvd->stSettings.stFWMemConfig.uiGeneralHeapSize != 0))
1073   {
1074      BXVD_DBG_WRN(hXvd, ("Separate picture heap specified with picture memory size of 0. Pictures are NOT expected to be displayed."));
1075   }
1076}
1077
1078
1079bool BXVD_P_IsDecodeProtocolSupported(BXVD_Handle               hXvd,
1080                                      BAVC_VideoCompressionStd  eVideoCmprStd)
1081{
1082   bool rc = false;
1083
1084   /* Platform may be capable to decode RV9, but it may have been disabled by OTP */
1085   if (eVideoCmprStd == BAVC_VideoCompressionStd_eRV9) 
1086   {
1087      if (hXvd->bRV9Capable)
1088      {
1089         rc = true;
1090      }
1091   }
1092
1093   else if (eVideoCmprStd == BAVC_VideoCompressionStd_eSVC) 
1094   {
1095      if (hXvd->bSVCCapable)
1096      {
1097         rc = true;
1098      }
1099   }
1100
1101   else if (eVideoCmprStd >= BAVC_VideoCompressionStd_eMPEG4Part2)
1102   {
1103      if (BXVD_P_CREATE_PROTOCOLS_MASK(eVideoCmprStd) & hXvd->uiSupportedProtocolsMask)
1104      {
1105         rc = true;
1106      }
1107   }
1108
1109   /* All others are supported on all platforms */
1110   else if (eVideoCmprStd < BAVC_VideoCompressionStd_eMPEG4Part2)
1111   {
1112      rc = true;
1113   }
1114
1115   return rc;
1116}
1117
1118BERR_Code BXVD_P_SetupFWSubHeap(BXVD_Handle hXvd)
1119{
1120   BERR_Code rc = BERR_SUCCESS;
1121
1122   hXvd->SubGenMem = NULL;
1123   hXvd->SubSecureMem = NULL;
1124   hXvd->SubPicMem = NULL;
1125
1126   if (hXvd->uiFWGenMemSize != 0)
1127   {
1128      BXVD_DBG_MSG(hXvd, ("Creating BXVD_Memory sub-heaps: Gen VA: %08x, PA: %08x, Size:%08x", 
1129                               hXvd->uiFWGenMemVirtAddr, hXvd->uiFWGenMemPhyAddr, hXvd->uiFWGenMemSize));
1130
1131      rc = BERR_TRACE(BXVD_P_Memory_Open(hXvd, &hXvd->SubGenMem, (void *) hXvd->uiFWGenMemVirtAddr, 
1132                                         hXvd->uiFWGenMemPhyAddr,  hXvd->uiFWGenMemSize,
1133                                         BXVD_P_Memory_Protection_eDontProtect));
1134      if (rc != BERR_SUCCESS)
1135      {
1136         return BERR_TRACE(rc);
1137      }
1138   }
1139
1140   if (hXvd->uiFWCabacMemSize != 0)
1141   {
1142      BXVD_DBG_MSG(hXvd, ("Creating BXVD_Memory sub-heaps: Secure VA: %08x, PA: %08x, Size:%08x",
1143                               hXvd->uiFWCabacMemVirtAddr, hXvd->uiFWCabacMemPhyAddr, hXvd->uiFWCabacMemSize));
1144
1145      rc = BERR_TRACE(BXVD_P_Memory_Open(hXvd, &hXvd->SubSecureMem, (void *) hXvd->uiFWCabacMemVirtAddr, 
1146                                         hXvd->uiFWCabacMemPhyAddr,  hXvd->uiFWCabacMemSize, 
1147                                         BXVD_P_Memory_Protection_eDontProtect));
1148      if (rc != BERR_SUCCESS)
1149      {
1150         return BERR_TRACE(rc);
1151      }
1152   }
1153
1154   if (hXvd->uiFWPicMemSize != 0)
1155   {
1156      BXVD_DBG_MSG(hXvd, ("Creating BXVD_Memory sub-heaps: Pic VA: %08x, PA: %08x, Size:%08x",
1157                               hXvd->uiFWPicMemVirtAddr, hXvd->uiFWPicMemPhyAddr, hXvd->uiFWPicMemSize));
1158
1159      rc = BERR_TRACE(BXVD_P_Memory_Open(hXvd, &hXvd->SubPicMem, (void *) hXvd->uiFWPicMemVirtAddr, 
1160                                         hXvd->uiFWPicMemPhyAddr,  hXvd->uiFWPicMemSize,
1161                                         BXVD_P_Memory_Protection_eDontProtect));
1162      if (rc != BERR_SUCCESS)
1163      {
1164         return BERR_TRACE(rc);
1165      }
1166   }
1167
1168   BXVD_DBG_MSG(hXvd, ("BXVD_Memory sub-heaps created successfully"));
1169   return BERR_TRACE(rc);
1170
1171}
1172
1173BERR_Code BXVD_P_TeardownFWSubHeap(BXVD_Handle hXvd)
1174{
1175   BERR_Code rc = BERR_SUCCESS;
1176
1177   if (hXvd->SubGenMem != NULL)
1178   {
1179      rc = BERR_TRACE(BXVD_P_Memory_Close(hXvd->SubGenMem));
1180      if (rc != BERR_SUCCESS)
1181      {
1182         return BERR_TRACE(rc);
1183      }
1184      hXvd->SubGenMem = NULL;
1185   }
1186
1187   if (hXvd->SubSecureMem != NULL)
1188   {
1189      rc = BERR_TRACE(BXVD_P_Memory_Close(hXvd->SubSecureMem));
1190      if (rc != BERR_SUCCESS)
1191      {
1192         return BERR_TRACE(rc);
1193      }
1194      hXvd->SubSecureMem = NULL;
1195   }
1196
1197   if (hXvd->SubPicMem != NULL)
1198   {
1199      rc = BERR_TRACE(BXVD_P_Memory_Close(hXvd->SubPicMem));
1200      if (rc != BERR_SUCCESS)
1201      {
1202         return BERR_TRACE(rc);
1203      }
1204      hXvd->SubPicMem = NULL;
1205   }
1206 
1207   return BERR_TRACE(rc);
1208
1209}
1210
1211
1212BERR_Code BXVD_P_GetDecodeFWMemSize(BXVD_Handle hXvd,
1213                                    BXVD_DecodeResolution eDecodeResolution,
1214                                    BAVC_VideoCompressionStd aeVideoCmprStd[],
1215                                    uint32_t  uiVideoCmprCount,
1216                                    const BXVD_ChannelSettings *pChSettings,
1217                                    BXVD_P_DecodeFWMemSize     *pstDecodeFWMemSize)
1218{
1219
1220   uint32_t i;
1221   uint32_t genMemReq = 0;
1222   uint32_t cabacMemReq = 0;
1223   uint32_t vidBlkIndex = 0;   
1224   uint32_t vidBlkSizeLookedUp = 0;   
1225   uint32_t vidBlkCountLookedUp = 0;   
1226   uint32_t vidBlkSizeReq = 0;   
1227   uint32_t vidBlkCountReq = 0;
1228   uint32_t cabacWorklistMemReq = 0;
1229   uint32_t directModeMemReq = 0;
1230   uint32_t innerLoopWorklistMemReq = 0;
1231
1232   BXVD_VideoProtocol eVideoProtocol_TableIndex;
1233
1234   BXVD_P_FWMemConfig_V2 *pChannelFWMemCfg; 
1235   BXVD_P_FWMemConfig_SVC *pSVCChannelFWMemCfg;
1236
1237
1238   BDBG_ASSERT(hXvd->uiDecode_StripeWidth < BXVD_P_STRIPE_WIDTH_NUM);
1239   BDBG_ASSERT(hXvd->uiDecode_StripeMultiple < BXVD_P_STRIPE_MULTIPLE_NUM);
1240
1241   /* Set SVD BL optional sizes to zero */
1242   pstDecodeFWMemSize->uiFWInterLayerPicSize = 0;
1243   pstDecodeFWMemSize->uiFWInterLayerMVSize = 0;
1244
1245   for (i = 0; i < uiVideoCmprCount; i++)
1246   {
1247      switch (aeVideoCmprStd[i])
1248      {
1249         case BAVC_VideoCompressionStd_eH264:
1250         case BAVC_VideoCompressionStd_eRV9:
1251            BXVD_DBG_MSG(hXvd, ("Video Protocol Memory Config: AVC"));
1252            eVideoProtocol_TableIndex = BXVD_VideoProtocol_eAVC;
1253            break;
1254
1255         case BAVC_VideoCompressionStd_eMPEG2:
1256         case BAVC_VideoCompressionStd_eH261:
1257         case BAVC_VideoCompressionStd_eH263:
1258         case BAVC_VideoCompressionStd_eMPEG1:
1259         case BAVC_VideoCompressionStd_eMPEG2DTV:
1260         case BAVC_VideoCompressionStd_eMPEG2_DSS_PES:
1261         case BAVC_VideoCompressionStd_eSPARK:
1262            BXVD_DBG_MSG(hXvd, ("Video Protocol Memory Config: MPEG2"));
1263            eVideoProtocol_TableIndex = BXVD_VideoProtocol_eMPEG2;
1264            break;
1265           
1266         case BAVC_VideoCompressionStd_eVC1:
1267         case BAVC_VideoCompressionStd_eVC1SimpleMain:
1268            BXVD_DBG_MSG(hXvd, ("Video Protocol Memory Config: VC1"));
1269            eVideoProtocol_TableIndex = BXVD_VideoProtocol_eVC1;
1270            break;
1271           
1272         case BAVC_VideoCompressionStd_eMPEG4Part2:
1273            BXVD_DBG_MSG(hXvd, ("Video Protocol Memory Config: MPEG4"));
1274            eVideoProtocol_TableIndex = BXVD_VideoProtocol_eMPEG4;
1275            break;
1276           
1277         case BAVC_VideoCompressionStd_eAVS:
1278            BXVD_DBG_MSG(hXvd, ("Video Protocol Memory Config: AVS"));
1279            eVideoProtocol_TableIndex = BXVD_VideoProtocol_eAVS;
1280            break; 
1281
1282         case BAVC_VideoCompressionStd_eMVC:
1283            BXVD_DBG_MSG(hXvd, ("Video Protocol Memory Config: MVC"));
1284            eVideoProtocol_TableIndex = BXVD_VideoProtocol_eMVC;
1285            break; 
1286
1287         case BAVC_VideoCompressionStd_eSVC:
1288            BXVD_DBG_MSG(hXvd, ("Video Protocol Memory Config: SVC"));
1289            eVideoProtocol_TableIndex = BXVD_VideoProtocol_eSVC;
1290            break; 
1291
1292         case BAVC_VideoCompressionStd_eVP6:
1293         case BAVC_VideoCompressionStd_eVP7:
1294         case BAVC_VideoCompressionStd_eVP8:
1295            BXVD_DBG_MSG(hXvd, ("Video Protocol Memory Config: VP8"));
1296            eVideoProtocol_TableIndex = BXVD_VideoProtocol_eVP8;
1297            break; 
1298
1299         default:
1300            BXVD_DBG_WRN(hXvd, ("Video Protocol: Unknown - Defaulting to AVC Memory Config!"));
1301            eVideoProtocol_TableIndex = BXVD_VideoProtocol_eAVC;
1302            break;             
1303      }
1304     
1305      switch (eDecodeResolution)
1306      {
1307         case BXVD_DecodeResolution_eHD:
1308            BXVD_DBG_MSG(hXvd, ("Video Resolution: HD"));
1309            break;
1310
1311         case BXVD_DecodeResolution_eSD:
1312            BXVD_DBG_MSG(hXvd, ("Video Resolution: SD"));
1313            break;           
1314           
1315         case BXVD_DecodeResolution_eCIF:
1316            BXVD_DBG_MSG(hXvd, ("Video Resolution: CIF"));
1317            break;           
1318           
1319         case BXVD_DecodeResolution_eQCIF:
1320            BXVD_DBG_MSG(hXvd, ("Video Resolution: QCIF"));
1321            break;               
1322           
1323         default:
1324            BXVD_DBG_WRN(hXvd, ("Video Resolution: Unknown - Defaulting to HD!"));
1325            eDecodeResolution = BXVD_DecodeResolution_eHD;
1326            break;
1327      }
1328
1329      /* Default SVC memory configuration is entry [0]. */
1330      pSVCChannelFWMemCfg = (BXVD_P_FWMemConfig_SVC *)&(sChannelFWMemCfg_SVC[0]);
1331
1332      /* Default non SVC memory configuration entry */
1333      pChannelFWMemCfg = (BXVD_P_FWMemConfig_V2 *)&(sChannelFWMemCfg[eVideoProtocol_TableIndex][eDecodeResolution]);
1334
1335      /* AVC 4.1 enabled */
1336      if (pChSettings->bAVC41Enable && 
1337          (eDecodeResolution == BXVD_DecodeResolution_eHD) && 
1338          (eVideoProtocol_TableIndex== BXVD_VideoProtocol_eAVC))
1339      {
1340         pChannelFWMemCfg = (BXVD_P_FWMemConfig_V2 *)&sChannelFWMemCfg_AVC41;
1341
1342         vidBlkIndex = pChannelFWMemCfg->video_block_size_index;
1343         vidBlkSizeLookedUp = sVideoAtomSize[hXvd->uiDecode_StripeWidth][hXvd->uiDecode_StripeMultiple][vidBlkIndex];
1344         vidBlkCountLookedUp = pChannelFWMemCfg->video_block_count;
1345      }
1346
1347      /* AVC 5.1 enabled */
1348      else if (pChSettings->bAVC51Enable && 
1349               (eDecodeResolution == BXVD_DecodeResolution_eHD) && 
1350               (eVideoProtocol_TableIndex == BXVD_VideoProtocol_eAVC))
1351      {
1352         pChannelFWMemCfg = (BXVD_P_FWMemConfig_V2 *)&sChannelFWMemCfg_AVC51;
1353
1354         vidBlkIndex = pChannelFWMemCfg->video_block_size_index;
1355         vidBlkSizeLookedUp = sVideoAtomSize[hXvd->uiDecode_StripeWidth][hXvd->uiDecode_StripeMultiple][vidBlkIndex];
1356         vidBlkCountLookedUp = pChannelFWMemCfg->video_block_count;
1357      }
1358
1359      /* BluRay enabled AVC */
1360      else if (pChSettings->bBluRayEnable && (eVideoProtocol_TableIndex == BXVD_VideoProtocol_eAVC) &&
1361               ((eDecodeResolution == BXVD_DecodeResolution_eHD) ||
1362                (eDecodeResolution == BXVD_DecodeResolution_eSD)))
1363      {
1364         pChannelFWMemCfg = (BXVD_P_FWMemConfig_V2 *)&(sChannelFWMemCfg_BluRay[eDecodeResolution]);
1365
1366         vidBlkIndex = pChannelFWMemCfg->video_block_size_index;
1367         vidBlkSizeLookedUp = sVideoAtomSize[hXvd->uiDecode_StripeWidth][hXvd->uiDecode_StripeMultiple][vidBlkIndex];
1368         vidBlkCountLookedUp = pChannelFWMemCfg->video_block_count;
1369      }
1370
1371      /* Excess direct memory mode enabled AVC */
1372      else if (pChSettings->bExcessDirModeEnable && (eVideoProtocol_TableIndex == BXVD_VideoProtocol_eAVC) &&
1373               ((eDecodeResolution == BXVD_DecodeResolution_eHD) ||
1374                (eDecodeResolution == BXVD_DecodeResolution_eSD)))
1375      {
1376         pChannelFWMemCfg = (BXVD_P_FWMemConfig_V2 *)&(sChannelFWMemCfg_bExcessDir[eDecodeResolution]);
1377
1378         vidBlkIndex = pChannelFWMemCfg->video_block_size_index;
1379         vidBlkSizeLookedUp = sVideoAtomSize[hXvd->uiDecode_StripeWidth][hXvd->uiDecode_StripeMultiple][vidBlkIndex];
1380         vidBlkCountLookedUp = pChannelFWMemCfg->video_block_count;
1381      }
1382
1383      /* MVC */
1384      else if (eVideoProtocol_TableIndex == BXVD_VideoProtocol_eMVC) 
1385      {
1386         pChannelFWMemCfg = (BXVD_P_FWMemConfig_V2 *)&(sChannelFWMemCfg_MVC);
1387
1388         vidBlkIndex = pChannelFWMemCfg->video_block_size_index;
1389         vidBlkSizeLookedUp = sVideoAtomSize[hXvd->uiDecode_StripeWidth][hXvd->uiDecode_StripeMultiple][vidBlkIndex];
1390         vidBlkCountLookedUp = pChannelFWMemCfg->video_block_count;
1391      }
1392
1393      /* SVC */
1394      else if ((eVideoProtocol_TableIndex == BXVD_VideoProtocol_eSVC) && (hXvd->bSVCCapable == true))
1395      {
1396         if (pChSettings->bSVC3DModeEnable)
1397         {
1398            pSVCChannelFWMemCfg = (BXVD_P_FWMemConfig_SVC *)&(sChannelFWMemCfg_SVC[2]);
1399         }
1400         else if (pChSettings->bSVCProgressiveOnly == true)
1401         {
1402            pSVCChannelFWMemCfg = (BXVD_P_FWMemConfig_SVC *)&(sChannelFWMemCfg_SVC[1]);
1403         }
1404
1405         vidBlkIndex = pSVCChannelFWMemCfg->video_block_size_index;
1406         vidBlkSizeLookedUp = sVideoAtomSize[hXvd->uiDecode_StripeWidth][hXvd->uiDecode_StripeMultiple][vidBlkIndex];
1407         vidBlkCountLookedUp = pSVCChannelFWMemCfg->video_block_count;
1408
1409#if BXVD_P_ILS_BUFFERS_INTERNAL
1410         pstDecodeFWMemSize->uiFWInterLayerPicSize = 0;
1411         pstDecodeFWMemSize->uiFWInterLayerMVSize = 0; 
1412#else
1413         vidBlkIndex = pSVCChannelFWMemCfg->inter_layer_video_size_index;
1414         
1415         if (hXvd->stSettings.bInterLayerBandwidthOptimized)
1416         {
1417            /* Multiply by 1.5 for Bandwidth optimization */
1418            pstDecodeFWMemSize->uiFWInterLayerPicSize = 
1419               ((sVideoAtomSize[hXvd->uiDecode_StripeWidth][hXvd->uiDecode_StripeMultiple][vidBlkIndex] * 15) / 10);
1420
1421            pstDecodeFWMemSize->uiFWInterLayerMVSize = ( (pSVCChannelFWMemCfg->inter_layer_mv_size * 15 ) / 10);
1422         }
1423         else
1424         {
1425            pstDecodeFWMemSize->uiFWInterLayerPicSize = 
1426               sVideoAtomSize[hXvd->uiDecode_StripeWidth][hXvd->uiDecode_StripeMultiple][vidBlkIndex];
1427
1428            pstDecodeFWMemSize->uiFWInterLayerMVSize =  pSVCChannelFWMemCfg->inter_layer_mv_size;
1429         }
1430#endif
1431      }
1432
1433      /* Normal memory configuration */
1434      else
1435      {
1436         pChannelFWMemCfg = (BXVD_P_FWMemConfig_V2 *)&(sChannelFWMemCfg[eVideoProtocol_TableIndex][eDecodeResolution]);
1437
1438         vidBlkIndex = sChannelFWMemCfg[eVideoProtocol_TableIndex][eDecodeResolution].video_block_size_index;
1439
1440         /* Select Atom size "AT" instead of size "A" if in 1920 Portrait mode for certain decode protocols. */
1441         if ((pChSettings->b1920PortraitModeEnable == true) && 
1442             (pChSettings->bBluRayEnable == false) && (vidBlkIndex == BXVD_P_VideoAtomIndex_eA) && 
1443             (eVideoProtocol_TableIndex != BXVD_VideoProtocol_eSVC))
1444            {
1445               vidBlkIndex = BXVD_P_VideoAtomIndex_eAT;
1446            }
1447
1448         vidBlkSizeLookedUp = sVideoAtomSize[hXvd->uiDecode_StripeWidth][hXvd->uiDecode_StripeMultiple][vidBlkIndex];
1449         vidBlkCountLookedUp = sChannelFWMemCfg[eVideoProtocol_TableIndex][eDecodeResolution].video_block_count;
1450      }
1451
1452      if((eVideoProtocol_TableIndex == BXVD_VideoProtocol_eSVC) && (hXvd->bSVCCapable == true))
1453      {
1454         /* Use SVC memory config entry */
1455         if (pSVCChannelFWMemCfg->context_memory_size > genMemReq)
1456         {
1457            genMemReq = pSVCChannelFWMemCfg->context_memory_size;
1458         }
1459     
1460         if (pSVCChannelFWMemCfg->cabac_bin_size > cabacMemReq)
1461         {
1462            cabacMemReq = pSVCChannelFWMemCfg->cabac_bin_size;
1463         }
1464
1465         if (pSVCChannelFWMemCfg->cabac_wl_size > cabacWorklistMemReq)
1466         {
1467            cabacWorklistMemReq = pSVCChannelFWMemCfg->cabac_wl_size;
1468         }
1469
1470         if (pSVCChannelFWMemCfg->direct_mode_size > directModeMemReq)
1471         {
1472            directModeMemReq = pSVCChannelFWMemCfg->direct_mode_size;
1473         }
1474
1475         if (pSVCChannelFWMemCfg->inner_loop_wl_size > innerLoopWorklistMemReq)
1476         {
1477            innerLoopWorklistMemReq = pSVCChannelFWMemCfg->inner_loop_wl_size;
1478         }
1479      }
1480      else
1481      {
1482         /* Use NON SVC memory config entry */
1483         if (pChannelFWMemCfg->general_memory_size > genMemReq)
1484         {
1485            genMemReq = pChannelFWMemCfg->general_memory_size;
1486         }
1487     
1488         if (pChannelFWMemCfg->cabac_bin_size > cabacMemReq)
1489         {
1490            cabacMemReq = pChannelFWMemCfg->cabac_bin_size;
1491         }
1492
1493         if (pChannelFWMemCfg->cabac_wl_size > cabacWorklistMemReq)
1494         {
1495            cabacWorklistMemReq = pChannelFWMemCfg->cabac_wl_size;
1496         }
1497
1498         if (pChannelFWMemCfg->direct_mode_size > directModeMemReq)
1499         {
1500            directModeMemReq = pChannelFWMemCfg->direct_mode_size;
1501         }
1502
1503         if (pChannelFWMemCfg->inner_loop_wl_size > innerLoopWorklistMemReq)
1504         {
1505            innerLoopWorklistMemReq = pChannelFWMemCfg->inner_loop_wl_size;
1506         }
1507
1508      }
1509      /* Check bounds of stripe multiple */
1510      if (hXvd->uiDecode_StripeMultiple >= BXVD_P_STRIPE_MULTIPLE_NUM)
1511      {
1512         BXVD_DBG_ERR(hXvd, ("Unsupported stripe multiple: %d", hXvd->uiDecode_StripeMultiple));
1513         return BERR_TRACE(BERR_INVALID_PARAMETER);
1514      }
1515
1516      /* Handle BTP Mode */
1517      if (!pChSettings->bMPEG2BTPEnable && 
1518          ((eVideoProtocol_TableIndex == BXVD_VideoProtocol_eMPEG2) &&
1519           ((eDecodeResolution == BXVD_DecodeResolution_eHD) ||
1520            (eDecodeResolution == BXVD_DecodeResolution_eSD))))
1521      {
1522         /* Reduce block count by 1 if we do not want BTP capability
1523          * in MPEG2 HD/SD */
1524         vidBlkCountLookedUp -= 1;
1525      }
1526
1527      if ((vidBlkSizeLookedUp * vidBlkCountLookedUp) > 
1528          (vidBlkSizeReq * vidBlkCountReq))
1529      {         
1530         vidBlkSizeReq = vidBlkSizeLookedUp;
1531         vidBlkCountReq = vidBlkCountLookedUp;
1532      }
1533   }
1534
1535#if BXVD_P_PPB_EXTENDED
1536   /* Context memory needs to be increased by 32k when using extended PPB */ 
1537   genMemReq += (32 * 1024);
1538#endif
1539
1540   pstDecodeFWMemSize->uiFWContextSize = genMemReq;
1541   pstDecodeFWMemSize->uiFWCabacSize = cabacMemReq;
1542   pstDecodeFWMemSize->uiFWPicBlockSize = vidBlkSizeReq;
1543   pstDecodeFWMemSize->uiFWPicBlockCount = vidBlkCountReq;
1544   pstDecodeFWMemSize->uiFWCabacWorklistSize = cabacWorklistMemReq;
1545
1546   pstDecodeFWMemSize->uiFWDirectModeSize = directModeMemReq;
1547   pstDecodeFWMemSize->uiFWInnerLoopWorklistSize = innerLoopWorklistMemReq;
1548
1549   BXVD_DBG_MSG(hXvd, ("ContextSize:0x%x (%d)", genMemReq, genMemReq));
1550   BXVD_DBG_MSG(hXvd, ("cabacMemReq:0x%x (%d)", cabacMemReq, cabacMemReq));
1551   BXVD_DBG_MSG(hXvd, ("VidBlockSize:0x%x (%d) , BlkCnt:%d", vidBlkSizeReq, vidBlkSizeReq, vidBlkCountReq));
1552   BXVD_DBG_MSG(hXvd, ("cabacWorklistMemReq:0x%x (%d)", cabacWorklistMemReq, cabacWorklistMemReq));
1553   BXVD_DBG_MSG(hXvd, ("directModeMemSize: 0x%x (%d)", directModeMemReq, directModeMemReq));
1554   BXVD_DBG_MSG(hXvd, ("innerLoopWorklistSize: 0x%x (%d)", innerLoopWorklistMemReq, innerLoopWorklistMemReq));
1555   return BERR_TRACE(BERR_SUCCESS);
1556}
1557
1558BERR_Code BXVD_P_GetStillDecodeFWMemSize(BXVD_Handle hXvd,
1559                                         BXVD_DecodeResolution eDecodeResolution,
1560                                         BAVC_VideoCompressionStd aeVideoCmprStd[], 
1561                                         uint32_t  uiVideoCmprCount,
1562                                         BXVD_P_DecodeFWMemSize       *pstDecodeFWMemSize)
1563{
1564   uint32_t i;
1565   uint32_t genMemReq = 0;
1566   uint32_t cabacMemSizeLookedUp = 0;
1567   uint32_t cabacMemReq = 0;
1568   uint32_t vidBlkSizeLookedUp = 0;
1569   uint32_t vidBlkSizeReq = 0;
1570   uint32_t vidBlkCountReq = 0;
1571   uint32_t cabacWorklistMemSizeLookedUp = 0;
1572   uint32_t cabacWorklistMemReq = 0;
1573   uint32_t innerLoopWorklistMemReq = 0;
1574
1575   BXVD_VideoProtocol eVideoProtocol;
1576
1577   BDBG_ASSERT(hXvd->uiDecode_StripeWidth < BXVD_P_STRIPE_WIDTH_NUM);
1578   BDBG_ASSERT(hXvd->uiDecode_StripeMultiple < BXVD_P_STRIPE_MULTIPLE_NUM);             
1579
1580   if ((eDecodeResolution != BXVD_DecodeResolution_eHD) &&
1581       (eDecodeResolution != BXVD_DecodeResolution_eSD))
1582   {
1583      /* coverity[dead_error_line: FALSE] */
1584      BXVD_DBG_ERR(hXvd, ("Unsupported Still Picture Decode Resolution: %d", eDecodeResolution));
1585      return BERR_TRACE(BERR_INVALID_PARAMETER);
1586   }
1587
1588   /* Set SVD BL optional sizes to zero, these are not used in still decode. */
1589   pstDecodeFWMemSize->uiFWInterLayerPicSize = 0;
1590   pstDecodeFWMemSize->uiFWInterLayerMVSize = 0;
1591
1592   for (i = 0; i < uiVideoCmprCount; i++)
1593   {
1594      switch (aeVideoCmprStd[i])
1595      {
1596         case BAVC_VideoCompressionStd_eH264:
1597            BXVD_DBG_MSG(hXvd, ("Still Protocol: AVC"));
1598            eVideoProtocol = BXVD_VideoProtocol_eAVC;
1599            break;
1600
1601         case BAVC_VideoCompressionStd_eMPEG2:
1602         case BAVC_VideoCompressionStd_eH261:
1603         case BAVC_VideoCompressionStd_eH263:
1604         case BAVC_VideoCompressionStd_eMPEG1:
1605         case BAVC_VideoCompressionStd_eMPEG2DTV:
1606         case BAVC_VideoCompressionStd_eMPEG2_DSS_PES:
1607            BXVD_DBG_MSG(hXvd, ("Still Protocol: MPEG2"));
1608            eVideoProtocol = BXVD_VideoProtocol_eMPEG2;
1609            break;
1610           
1611         case BAVC_VideoCompressionStd_eVC1:
1612         case BAVC_VideoCompressionStd_eVC1SimpleMain:
1613            BXVD_DBG_MSG(hXvd, ("Still Protocol: VC1"));
1614            eVideoProtocol = BXVD_VideoProtocol_eVC1;
1615            break;
1616           
1617         case BAVC_VideoCompressionStd_eMPEG4Part2:
1618            BXVD_DBG_MSG(hXvd, ("Still Protocol: MPEG4"));
1619            eVideoProtocol = BXVD_VideoProtocol_eMPEG4;
1620            break;
1621           
1622         case BAVC_VideoCompressionStd_eAVS:
1623            BXVD_DBG_MSG(hXvd, ("Still Protocol: AVS"));
1624            eVideoProtocol = BXVD_VideoProtocol_eAVS;
1625            break; 
1626
1627         default:
1628            BXVD_DBG_WRN(hXvd, ("Still Protocol: Unknown - Defaulting to AVC!"));
1629            eVideoProtocol = BXVD_VideoProtocol_eAVC;
1630            break;             
1631      }
1632
1633      if (eDecodeResolution == BXVD_DecodeResolution_eHD)
1634      {
1635         BXVD_DBG_MSG(hXvd, ("Still Resolution: HD"));
1636      }
1637      else
1638      {
1639         BXVD_DBG_MSG(hXvd, ("Still Resolution: SD"));
1640      }
1641     
1642      if (sChannelStillFWMemCfg[eVideoProtocol][eDecodeResolution].general_memory_size > genMemReq)
1643      {
1644         genMemReq = sChannelStillFWMemCfg[eVideoProtocol][eDecodeResolution].general_memory_size;
1645      }
1646
1647      if (sChannelStillFWMemCfg[eVideoProtocol][eDecodeResolution].inner_loop_wl_size > innerLoopWorklistMemReq)
1648      {
1649         innerLoopWorklistMemReq = sChannelStillFWMemCfg[eVideoProtocol][eDecodeResolution].inner_loop_wl_size;
1650      }
1651
1652      cabacMemSizeLookedUp = sChannelStillFWMemCfg[eVideoProtocol][eDecodeResolution].cabac_bin_size;
1653      cabacWorklistMemSizeLookedUp = sChannelStillFWMemCfg[eVideoProtocol][eDecodeResolution].cabac_wl_size;
1654
1655      /* Handle Still Picture Compatibility Mode */
1656      if (hXvd->bStillPictureCompatibilityMode && 
1657          (eVideoProtocol == BXVD_VideoProtocol_eMPEG2))
1658      {         
1659         /* In still picture compatibility mode, to reduce memory
1660            requirements, we do not allocate a separate cabac.
1661            Instead, we pass in the CDB as the cabac buffer. */
1662         cabacMemSizeLookedUp = 0;
1663      }
1664     
1665      if ((cabacMemSizeLookedUp + cabacWorklistMemSizeLookedUp) > 
1666          (cabacMemReq + cabacWorklistMemReq))
1667      {
1668         cabacMemReq = cabacMemSizeLookedUp;
1669         cabacWorklistMemReq = cabacWorklistMemSizeLookedUp;
1670      }
1671
1672      /* Check bounds of stripe multiple */
1673      if (hXvd->uiDecode_StripeMultiple >= BXVD_P_STRIPE_MULTIPLE_NUM)
1674      {
1675         BXVD_DBG_ERR(hXvd, ("Unsupported stripe multiple: %d", hXvd->uiDecode_StripeMultiple));
1676         return BERR_TRACE(BERR_INVALID_PARAMETER);
1677      }
1678
1679      vidBlkSizeLookedUp = sVideoAtomSize[hXvd->uiDecode_StripeWidth][hXvd->uiDecode_StripeMultiple][sChannelStillFWMemCfg[eVideoProtocol][eDecodeResolution].video_block_size_index];
1680      if ( (vidBlkSizeLookedUp * 
1681            sChannelStillFWMemCfg[eVideoProtocol][eDecodeResolution].video_block_count) > 
1682           (vidBlkSizeReq * vidBlkCountReq))
1683      {
1684         vidBlkSizeReq = vidBlkSizeLookedUp;
1685         vidBlkCountReq =  sChannelStillFWMemCfg[eVideoProtocol][eDecodeResolution].video_block_count;
1686      }
1687   }
1688
1689#if BXVD_P_PPB_EXTENDED
1690   /* Context memory needs to be increased by 32k when using extended PPB */ 
1691   genMemReq += (32 * 1024);
1692#endif
1693
1694   pstDecodeFWMemSize->uiFWContextSize = genMemReq;
1695   pstDecodeFWMemSize->uiFWCabacSize = cabacMemReq;
1696   pstDecodeFWMemSize->uiFWPicBlockSize = vidBlkSizeReq;
1697   pstDecodeFWMemSize->uiFWPicBlockCount = vidBlkCountReq;
1698   pstDecodeFWMemSize->uiFWCabacWorklistSize = cabacWorklistMemReq;
1699   pstDecodeFWMemSize->uiFWInnerLoopWorklistSize = innerLoopWorklistMemReq;
1700
1701   BXVD_DBG_MSG(hXvd, ("ContextSize:0x%x (%d)", genMemReq, genMemReq));
1702   BXVD_DBG_MSG(hXvd, ("cabacMemReq:0x%x (%d)", cabacMemReq, cabacMemReq));
1703   BXVD_DBG_MSG(hXvd, ("VidBlockSize:0x%x (%d) , BlkCnt:%d", vidBlkSizeReq, vidBlkSizeReq, vidBlkCountReq));
1704   BXVD_DBG_MSG(hXvd, ("cabacWorklistMemReq:0x%x (%d)", cabacWorklistMemReq, cabacWorklistMemReq));
1705   BXVD_DBG_MSG(hXvd, ("innerLoopWorklistSize: 0x%x (%d)", innerLoopWorklistMemReq, innerLoopWorklistMemReq));
1706
1707   return BERR_TRACE(BERR_SUCCESS);
1708}
1709
1710BERR_Code BXVD_P_AllocateFWMem(BXVD_Handle hXvd,
1711                               BXVD_ChannelHandle hXvdCh,
1712                               BXVD_P_DecodeFWMemSize  *pstDecodeFWMemSize,
1713                               BXVD_P_DecodeFWBaseAddrs *pstDecodeFWBaseAddrs)
1714{
1715   uint32_t uiFWGenMemSize;
1716   uint32_t uiFWPicMemSize;
1717   uint32_t uiFWCabacMemSize;
1718
1719   uint32_t *uiContextVirtAddr;
1720   uint32_t *uiPicBufVirtAddr;
1721   uint32_t *uiCabacVirtAddr;
1722
1723   uint32_t uiMemBlockAddr;
1724   uint32_t uiTempPicMemAlignedSize;
1725
1726   pstDecodeFWBaseAddrs->uiFWContextBase = 0;
1727   pstDecodeFWBaseAddrs->uiFWPicBlockBase = 0;
1728   pstDecodeFWBaseAddrs->uiFWCabacBase = 0;
1729   pstDecodeFWBaseAddrs->uiFWCabacWorklistBase = 0;
1730   pstDecodeFWBaseAddrs->uiFWInterLayerPicBase = 0;
1731   pstDecodeFWBaseAddrs->uiFWInterLayerMVBase = 0;
1732
1733   BXVD_DBG_MSG(hXvdCh, ("SubGenMem : %08x", hXvd->SubGenMem)); 
1734   BXVD_DBG_MSG(hXvdCh, ("SubSecureMem : %08x", hXvd->SubSecureMem)); 
1735   BXVD_DBG_MSG(hXvdCh, ("SubPicMem : %08x", hXvd->SubPicMem)); 
1736   BXVD_DBG_MSG(hXvdCh, ("Context Size: %d, Direct mode Size: %d, Inner Loop Work list size: %d", 
1737                         pstDecodeFWMemSize->uiFWContextSize, pstDecodeFWMemSize->uiFWDirectModeSize, 
1738                         pstDecodeFWMemSize->uiFWInnerLoopWorklistSize));
1739
1740   BXVD_DBG_MSG(hXvdCh, ("Cabac Size: %d, Cabac Worklist Size: %d", 
1741                         pstDecodeFWMemSize->uiFWCabacSize, pstDecodeFWMemSize->uiFWCabacWorklistSize));
1742
1743   BXVD_DBG_MSG(hXvdCh, ("Block Size: %d, Block Count: %d",
1744                         pstDecodeFWMemSize->uiFWPicBlockSize, pstDecodeFWMemSize->uiFWPicBlockCount));
1745
1746   BXVD_DBG_MSG(hXvdCh, ("Inter Layer Pic Size: %d", pstDecodeFWMemSize->uiFWInterLayerPicSize));
1747   BXVD_DBG_MSG(hXvdCh, ("Inter Layer MV Size: %d", pstDecodeFWMemSize->uiFWInterLayerMVSize));
1748
1749
1750   /* Initialize FW Gen Mem Size to contain at least the context, Direct mode and IL Work list buffers */
1751   uiFWGenMemSize = pstDecodeFWMemSize->uiFWContextSize + pstDecodeFWMemSize->uiFWDirectModeSize +
1752      pstDecodeFWMemSize->uiFWInnerLoopWorklistSize + pstDecodeFWMemSize->uiFWInterLayerMVSize;
1753
1754   uiFWPicMemSize = pstDecodeFWMemSize->uiFWPicBlockSize * pstDecodeFWMemSize->uiFWPicBlockCount;
1755   uiFWCabacMemSize = pstDecodeFWMemSize->uiFWCabacSize + pstDecodeFWMemSize->uiFWCabacWorklistSize;
1756
1757   /* Allocate picture memory from picture heap, if it exists */ 
1758   if (hXvdCh->sChSettings.hChannelPictureHeap != NULL)
1759   {
1760      BXVD_DBG_MSG(hXvdCh, ("Allocating %d bytes of picture memory from CHANNEL picture heap", uiFWPicMemSize));
1761      uiPicBufVirtAddr = (uint32_t *)BMEM_AllocAligned(hXvdCh->sChSettings.hChannelPictureHeap, 
1762                                                       uiFWPicMemSize,
1763                                                       12,
1764                                                       0);
1765
1766      if (uiPicBufVirtAddr == NULL)
1767      {
1768         BXVD_DBG_ERR(hXvdCh, ("Picture memory allocation failure!"));
1769         return BERR_TRACE(BERR_OUT_OF_DEVICE_MEMORY);
1770      }
1771     
1772      BMEM_ConvertAddressToOffset(hXvdCh->sChSettings.hChannelPictureHeap, uiPicBufVirtAddr, &(pstDecodeFWBaseAddrs->uiFWPicBlockBase));
1773
1774      if (pstDecodeFWMemSize->uiFWInterLayerPicSize != 0)
1775      {
1776         uiPicBufVirtAddr = (uint32_t *)BMEM_AllocAligned(hXvdCh->sChSettings.hChannelPictureHeap, 
1777                                                          pstDecodeFWMemSize->uiFWInterLayerPicSize,
1778                                                          12,
1779                                                          0);
1780
1781         if (uiPicBufVirtAddr == NULL)
1782         {
1783            BXVD_DBG_ERR(hXvdCh, ("Inter Layer Picture memory allocation failure!"));
1784            return BERR_TRACE(BERR_OUT_OF_DEVICE_MEMORY);
1785         }
1786     
1787         BMEM_ConvertAddressToOffset(hXvdCh->sChSettings.hChannelPictureHeap, uiPicBufVirtAddr, &(pstDecodeFWBaseAddrs->uiFWInterLayerPicBase));
1788      }
1789
1790      hXvdCh->hPictureHeap = hXvdCh->sChSettings.hChannelPictureHeap;
1791   }
1792   else if (hXvd->SubPicMem != NULL)
1793   {
1794      BXVD_DBG_MSG(hXvdCh, ("Allocating %d bytes of picture memory from DEVICE picture heap", uiFWPicMemSize));
1795      uiPicBufVirtAddr = (uint32_t *)BXVD_P_Memory_Allocate(hXvd->SubPicMem, uiFWPicMemSize, 12, 0);
1796     
1797      if (uiPicBufVirtAddr == NULL)
1798      {
1799         BXVD_DBG_ERR(hXvdCh, ("Picture memory allocation failure!"));
1800         return BERR_TRACE(BERR_OUT_OF_DEVICE_MEMORY);
1801      }
1802     
1803     
1804      BMEM_ConvertAddressToOffset(hXvd->hPictureHeap, uiPicBufVirtAddr, &(pstDecodeFWBaseAddrs->uiFWPicBlockBase));
1805
1806      if (pstDecodeFWMemSize->uiFWInterLayerPicSize != 0)
1807      {
1808         BXVD_DBG_MSG(hXvdCh, ("Allocating %d bytes of picture memory from DEVICE picture heap",
1809                               pstDecodeFWMemSize->uiFWInterLayerPicSize));
1810
1811         uiPicBufVirtAddr = (uint32_t *)BXVD_P_Memory_Allocate(hXvd->SubPicMem, pstDecodeFWMemSize->uiFWInterLayerPicSize, 12, 0);
1812     
1813         if (uiPicBufVirtAddr == NULL)
1814         {
1815            BXVD_DBG_ERR(hXvdCh, ("Picture memory allocation failure!"));
1816            return BERR_TRACE(BERR_OUT_OF_DEVICE_MEMORY);
1817         }
1818     
1819         BMEM_ConvertAddressToOffset(hXvd->hPictureHeap, uiPicBufVirtAddr, &(pstDecodeFWBaseAddrs->uiFWInterLayerPicBase));
1820      }
1821
1822      hXvdCh->hPictureHeap = hXvd->hPictureHeap;
1823   }
1824   else
1825   {
1826      if (pstDecodeFWMemSize->uiFWInterLayerPicSize != 0)
1827      {
1828         /* Need to make sure Interlayer picture memory starts on 4k boundary. Force normal Picture memory
1829          * buffer to end on 4k boundary */
1830         uiTempPicMemAlignedSize = ((uiFWPicMemSize + 4095) / 4096) * 4096;
1831         
1832         uiFWGenMemSize += uiTempPicMemAlignedSize + pstDecodeFWMemSize->uiFWInterLayerPicSize;
1833      }
1834      else
1835      {
1836         uiFWGenMemSize += uiFWPicMemSize;
1837      }
1838
1839      hXvdCh->hPictureHeap = hXvd->hSystemHeap;
1840   }
1841   
1842   /* Allocate cabac from secure heap, if it exists */
1843   if (uiFWCabacMemSize != 0) 
1844   {
1845      if (hXvdCh->sChSettings.hChannelCabacHeap != NULL)
1846      {
1847         BXVD_DBG_MSG(hXvdCh, ("Allocating %d bytes of cabac memory from CHANNEL cabac heap", uiFWCabacMemSize));
1848         uiCabacVirtAddr = (uint32_t *)BMEM_AllocAligned(hXvdCh->sChSettings.hChannelCabacHeap, 
1849                                                         uiFWCabacMemSize,
1850                                                         8,
1851                                                         0);
1852         if (uiCabacVirtAddr == NULL)
1853         {
1854            BXVD_DBG_ERR(hXvdCh, ("Secure memory allocation failure!"));
1855            return BERR_TRACE(BERR_OUT_OF_DEVICE_MEMORY);
1856         }
1857         
1858         BMEM_ConvertAddressToOffset(hXvdCh->sChSettings.hChannelCabacHeap, uiCabacVirtAddr, &(pstDecodeFWBaseAddrs->uiFWCabacBase));
1859         hXvdCh->hCabacHeap = hXvdCh->sChSettings.hChannelCabacHeap;
1860
1861         /* Pre rev K cores CABAC must be in memory lower than 768 MB */ 
1862#if !BXVD_P_AVD_ARC600
1863         if ((pstDecodeFWBaseAddrs->uiFWCabacBase + uiFWCabacMemSize) >= BXVD_P_ARC300_RAM_LIMIT)
1864         {
1865            BXVD_DBG_ERR(hXvdCh, ("Cabac buffer (%0x) allocated in memory greater than 768MB!", pstDecodeFWBaseAddrs->uiFWCabacBase));
1866            return BERR_TRACE(BERR_INVALID_PARAMETER);
1867         }
1868#endif
1869         /* Assign CABAC worklist base at end of CABAC buffer */
1870         pstDecodeFWBaseAddrs->uiFWCabacWorklistBase = pstDecodeFWBaseAddrs->uiFWCabacBase + pstDecodeFWMemSize->uiFWCabacSize;
1871      }
1872      else if (hXvd->SubSecureMem != NULL)
1873      {
1874         BXVD_DBG_MSG(hXvdCh, ("Allocating %d bytes of cabac memory from DEVICE cabac heap", uiFWCabacMemSize));
1875         uiCabacVirtAddr = (uint32_t *)BXVD_P_Memory_Allocate(hXvd->SubSecureMem, uiFWCabacMemSize, 8, 0);
1876         
1877         if (uiCabacVirtAddr == NULL)
1878         {
1879            BXVD_DBG_ERR(hXvdCh, ("Secure memory allocation failure!"));
1880            return BERR_TRACE(BERR_OUT_OF_DEVICE_MEMORY);
1881         }
1882         BMEM_ConvertAddressToOffset(hXvd->hCabacHeap, uiCabacVirtAddr, &(pstDecodeFWBaseAddrs->uiFWCabacBase));
1883
1884         /* Pre rev K cores CABAC must be in memory lower than 768 MB */ 
1885#if !BXVD_P_AVD_ARC600
1886         if ((pstDecodeFWBaseAddrs->uiFWCabacBase + uiFWCabacMemSize) > BXVD_P_ARC300_RAM_LIMIT)
1887         {
1888            BXVD_DBG_ERR(hXvdCh, ("Cabac buffer allocated in memory greater than 768MB!"));
1889            return BERR_TRACE(BERR_INVALID_PARAMETER);
1890         }
1891#endif
1892         hXvdCh->hCabacHeap = hXvd->hCabacHeap;
1893
1894         /* Assign CABAC worklist base at end of CABAC buffer */
1895         pstDecodeFWBaseAddrs->uiFWCabacWorklistBase = pstDecodeFWBaseAddrs->uiFWCabacBase + pstDecodeFWMemSize->uiFWCabacSize;
1896      }
1897      else
1898      {
1899         uiFWGenMemSize += uiFWCabacMemSize;
1900         hXvdCh->hCabacHeap = hXvd->hSystemHeap;
1901      }
1902   }
1903
1904   /* Allocate general heap */
1905   if (hXvdCh->sChSettings.hChannelSystemHeap != NULL)
1906   {
1907      BXVD_DBG_MSG(hXvdCh, ("Allocating %d bytes of system memory from CHANNEL system heap", uiFWGenMemSize));
1908      uiContextVirtAddr = (uint32_t *)BMEM_AllocAligned(hXvdCh->sChSettings.hChannelSystemHeap, 
1909                                                      uiFWGenMemSize,
1910                                                      12,
1911                                                      0);
1912     
1913      if (uiContextVirtAddr == NULL)
1914      {
1915         BXVD_DBG_ERR(hXvdCh, ("General memory allocation failure!"));
1916         return BERR_TRACE(BERR_OUT_OF_DEVICE_MEMORY);
1917      }
1918     
1919      BMEM_ConvertAddressToOffset(hXvdCh->sChSettings.hChannelSystemHeap, uiContextVirtAddr, &uiMemBlockAddr);
1920      hXvdCh->hSystemHeap = hXvdCh->sChSettings.hChannelSystemHeap;
1921   }
1922   else
1923   {
1924      BXVD_DBG_MSG(hXvdCh, ("Allocating %d bytes of system memory from DEVICE system heap", uiFWGenMemSize));
1925      uiContextVirtAddr = (uint32_t *)BXVD_P_Memory_Allocate(hXvd->SubGenMem, uiFWGenMemSize, 12, 0); 
1926
1927      if (uiContextVirtAddr == NULL)
1928      {
1929         BXVD_DBG_ERR(hXvdCh, ("General memory allocation failure!"));
1930         return BERR_TRACE(BERR_OUT_OF_DEVICE_MEMORY);
1931      }
1932
1933      BMEM_ConvertAddressToOffset(hXvd->hSystemHeap, (void *)uiContextVirtAddr, &uiMemBlockAddr); 
1934
1935      /* Pre rev K core general memory must be in region lower than 768 MB */ 
1936#if !BXVD_P_AVD_ARC600
1937      if ((uiMemBlockAddr + uiFWGenMemSize) >= BXVD_P_ARC300_RAM_LIMIT)
1938         {
1939            BXVD_DBG_ERR(hXvdCh, ("General AVD Firmware memory (%0x) allocated in region greater than 768MB!", uiMemBlockAddr));
1940            return BERR_TRACE(BERR_INVALID_PARAMETER);
1941         }
1942#endif
1943
1944      hXvdCh->hSystemHeap = hXvd->hSystemHeap;
1945   }
1946
1947   /* Assign picture buffer from general heap if it is not already allocated */
1948   if ((uiFWPicMemSize != 0) && (pstDecodeFWBaseAddrs->uiFWPicBlockBase == 0))
1949   {
1950      pstDecodeFWBaseAddrs->uiFWPicBlockBase = uiMemBlockAddr;
1951
1952      if( pstDecodeFWMemSize->uiFWInterLayerPicSize != 0)
1953      {
1954         /* Need to make sure Interlayer picture memory starts on 4k boundary. Force normal Picture memory
1955          * buffer to end on 4k boundary */
1956         uiTempPicMemAlignedSize = ((uiFWPicMemSize + 4095) / 4096) * 4096;
1957         uiMemBlockAddr += uiTempPicMemAlignedSize;
1958
1959         pstDecodeFWBaseAddrs->uiFWInterLayerPicBase = uiMemBlockAddr;
1960         uiMemBlockAddr += pstDecodeFWMemSize->uiFWInterLayerPicSize;
1961      }
1962      else
1963      {
1964         uiMemBlockAddr += uiFWPicMemSize;
1965      }
1966   }
1967
1968   /* Assign cabac buffer from general heap if it is not already allocated */
1969   if ((pstDecodeFWMemSize->uiFWCabacSize != 0) && (pstDecodeFWBaseAddrs->uiFWCabacBase == 0))
1970   {
1971      pstDecodeFWBaseAddrs->uiFWCabacBase = uiMemBlockAddr;     
1972      uiMemBlockAddr += pstDecodeFWMemSize->uiFWCabacSize;
1973   }
1974
1975   /* Assign cabac worklist buffer from general heap if it is not already allocated */
1976   if ((pstDecodeFWMemSize->uiFWCabacWorklistSize != 0) && (pstDecodeFWBaseAddrs->uiFWCabacWorklistBase == 0))
1977   {
1978      pstDecodeFWBaseAddrs->uiFWCabacWorklistBase = uiMemBlockAddr;     
1979      uiMemBlockAddr += pstDecodeFWMemSize->uiFWCabacWorklistSize;
1980   }
1981   
1982   /* Assign context buffer */
1983   if ((pstDecodeFWMemSize->uiFWContextSize != 0) && (pstDecodeFWBaseAddrs->uiFWContextBase == 0))
1984   {
1985      pstDecodeFWBaseAddrs->uiFWContextBase = uiMemBlockAddr;     
1986      uiMemBlockAddr += pstDecodeFWMemSize->uiFWContextSize;
1987   }
1988
1989   /* Assign Direct mode buffer */
1990   if (pstDecodeFWMemSize->uiFWDirectModeSize != 0)
1991   {
1992      pstDecodeFWBaseAddrs->uiFWDirectModeBase = uiMemBlockAddr;
1993      uiMemBlockAddr += pstDecodeFWMemSize->uiFWDirectModeSize;
1994   }
1995
1996   /* Assign inner loop work list buffer address */
1997   if (pstDecodeFWMemSize->uiFWInnerLoopWorklistSize != 0)
1998   {
1999      pstDecodeFWBaseAddrs->uiFWInnerLoopWorklistBase = uiMemBlockAddr;
2000      uiMemBlockAddr += pstDecodeFWMemSize->uiFWInnerLoopWorklistSize;
2001   }
2002
2003   if ( pstDecodeFWMemSize->uiFWInterLayerMVSize != 0)
2004   {
2005      pstDecodeFWBaseAddrs->uiFWInterLayerMVBase = uiMemBlockAddr;
2006   }
2007
2008   
2009   BXVD_DBG_MSG(hXvdCh, ("FWContextBase PA: %08x", pstDecodeFWBaseAddrs->uiFWContextBase));   
2010   BXVD_DBG_MSG(hXvdCh, ("FWPicBase PA: %08x", pstDecodeFWBaseAddrs->uiFWPicBlockBase));   
2011   BXVD_DBG_MSG(hXvdCh, ("FWCabacBase PA: %08x", pstDecodeFWBaseAddrs->uiFWCabacBase));
2012   BXVD_DBG_MSG(hXvdCh, ("FWDirectModeBase PA: %08x", pstDecodeFWBaseAddrs->uiFWDirectModeBase));
2013   BXVD_DBG_MSG(hXvdCh, ("FWInnerLoopWorklistBase PA: %08x", pstDecodeFWBaseAddrs->uiFWInnerLoopWorklistBase));
2014   BXVD_DBG_MSG(hXvdCh, ("FWInterLayerPicBase PA: %08x", pstDecodeFWBaseAddrs->uiFWInterLayerPicBase));
2015   BXVD_DBG_MSG(hXvdCh, ("FWInterLayerMVBase PA: %08x", pstDecodeFWBaseAddrs->uiFWInterLayerMVBase));
2016
2017   return BERR_TRACE(BERR_SUCCESS); 
2018}
2019
2020
2021BERR_Code BXVD_P_FreeFWMem(BXVD_Handle hXvd,
2022                           BXVD_ChannelHandle hXvdCh,
2023                           uint32_t uiFWContextBase, 
2024                           uint32_t uiFWCabacBase, 
2025                           uint32_t uiFWPicBlockBase,
2026                           uint32_t uiFWCabacWorklistBase,
2027                           uint32_t uiFWInterLayerPicBase)
2028{
2029
2030   uint32_t *uiContextVirtAddr;
2031   uint32_t *uiPicBufVirtAddr;
2032   uint32_t *uiCabacVirtAddr;
2033
2034   uint32_t uiMemBlockAddr;
2035
2036   bool bPicBufFreed = false;
2037   bool bCabacFreed = false;
2038   BERR_Code rc = BERR_SUCCESS;
2039
2040   BSTD_UNUSED(uiFWCabacWorklistBase);
2041
2042   BXVD_DBG_MSG(hXvdCh, ("SubGenMem : %08x", hXvd->SubGenMem)); 
2043   BXVD_DBG_MSG(hXvdCh, ("SubSecureMem : %08x", hXvd->SubSecureMem)); 
2044   BXVD_DBG_MSG(hXvdCh, ("SubPicMem : %08x", hXvd->SubPicMem)); 
2045
2046   if (uiFWPicBlockBase)
2047   {
2048      BXVD_DBG_MSG(hXvdCh, ("Picture buffers in specified heap, Free sub-allocation\n"));
2049
2050      if (hXvdCh->sChSettings.hChannelPictureHeap != NULL)
2051      {
2052         /* Free picture buffer sub-allocated block */
2053         BMEM_ConvertOffsetToAddress(hXvdCh->sChSettings.hChannelPictureHeap, uiFWPicBlockBase, (void *)&uiPicBufVirtAddr);
2054         
2055         rc = BMEM_Free(hXvdCh->sChSettings.hChannelPictureHeap, uiPicBufVirtAddr);
2056         
2057         if ( rc != BERR_SUCCESS)
2058         {
2059            BXVD_DBG_ERR(hXvdCh, ("failed to free sub allocated Picture memory"));
2060            return BERR_TRACE(BERR_LEAKED_RESOURCE);
2061         }
2062
2063         if (uiFWInterLayerPicBase != 0)
2064         {
2065
2066            /* Free inter layer picture buffer sub-allocated block */
2067            BMEM_ConvertOffsetToAddress(hXvdCh->sChSettings.hChannelPictureHeap, uiFWInterLayerPicBase, (void *)&uiPicBufVirtAddr);
2068         
2069            rc = BMEM_Free(hXvdCh->sChSettings.hChannelPictureHeap, uiPicBufVirtAddr);
2070         
2071            if ( rc != BERR_SUCCESS)
2072            {
2073               BXVD_DBG_ERR(hXvdCh, ("failed to free sub allocated Inter Layer Picture memory"));
2074               return BERR_TRACE(BERR_LEAKED_RESOURCE);
2075            }
2076         }
2077
2078         bPicBufFreed = true;
2079      }
2080      else if (hXvd->SubPicMem != NULL)
2081      {
2082         /* Free picture buffer sub-allocated block */
2083         BMEM_ConvertOffsetToAddress(hXvd->hPictureHeap, uiFWPicBlockBase, (void *)&uiPicBufVirtAddr);
2084         
2085         rc = BXVD_P_Memory_Free(hXvd->SubPicMem, uiPicBufVirtAddr);
2086         
2087         if ( rc != BERR_SUCCESS)
2088         {
2089            BXVD_DBG_ERR(hXvdCh, ("failed to free sub allocated Picture memory"));
2090            return BERR_TRACE(BERR_LEAKED_RESOURCE);
2091         }
2092
2093         /* If interlayer picture memory is allocated, free it */
2094         if (uiFWInterLayerPicBase != 0)
2095         {
2096            /* Free inter layer picture buffer sub-allocated block */
2097            BMEM_ConvertOffsetToAddress(hXvd->hPictureHeap, uiFWInterLayerPicBase, (void *)&uiPicBufVirtAddr);
2098         
2099            rc = BXVD_P_Memory_Free(hXvd->SubPicMem, uiPicBufVirtAddr);
2100         
2101            if ( rc != BERR_SUCCESS)
2102            {
2103               BXVD_DBG_ERR(hXvdCh, ("failed to free sub allocated Inter Layer Picture memory"));
2104               return BERR_TRACE(BERR_LEAKED_RESOURCE);
2105            }
2106         }
2107
2108         bPicBufFreed = true;
2109      }
2110   }
2111
2112   if (uiFWCabacBase)
2113   {     
2114      BXVD_DBG_MSG(hXvdCh, ("Cabac in Secure memory, Free sub-allocation \n"));
2115
2116      if (hXvdCh->sChSettings.hChannelCabacHeap != NULL)
2117      {
2118         BMEM_ConvertOffsetToAddress(hXvdCh->sChSettings.hChannelCabacHeap, uiFWCabacBase, (void *)&uiCabacVirtAddr);
2119         
2120         rc = BMEM_Free(hXvdCh->sChSettings.hChannelCabacHeap, uiCabacVirtAddr);
2121         
2122         if ( rc != BERR_SUCCESS)
2123         {
2124            BXVD_DBG_ERR(hXvdCh, ("failed to free sub allocated CABAC memory"));
2125            return BERR_TRACE(BERR_LEAKED_RESOURCE);
2126         }         
2127         bCabacFreed = true;
2128      }     
2129      else if (hXvd->SubSecureMem != NULL)
2130      {
2131         BMEM_ConvertOffsetToAddress(hXvd->hCabacHeap, uiFWCabacBase, (void *)&uiCabacVirtAddr);
2132         
2133         rc = BXVD_P_Memory_Free(hXvd->SubSecureMem, uiCabacVirtAddr);
2134         
2135         if ( rc != BERR_SUCCESS)
2136         {
2137            BXVD_DBG_ERR(hXvdCh, ("failed to free sub allocated CABAC memory"));
2138            return BERR_TRACE(BERR_LEAKED_RESOURCE);
2139         }         
2140         bCabacFreed = true;
2141      }
2142   }
2143
2144   BXVD_DBG_MSG(hXvdCh, ("Free Context sub-allocation\n"));     
2145   if (uiFWPicBlockBase && !bPicBufFreed)
2146   {     
2147      uiMemBlockAddr = uiFWPicBlockBase;
2148   }
2149   else if (uiFWCabacBase && !bCabacFreed)
2150   {
2151      uiMemBlockAddr = uiFWCabacBase; 
2152   }
2153   else
2154   {
2155      uiMemBlockAddr = uiFWContextBase;
2156   }
2157   
2158   if (uiFWContextBase)
2159   {
2160      /* Free context memory, this also could contain the picture and
2161       * cabac memory if not in their own heaps */ 
2162      if (hXvdCh->sChSettings.hChannelSystemHeap != NULL)
2163      {
2164         BMEM_ConvertOffsetToAddress(hXvdCh->sChSettings.hChannelSystemHeap, uiMemBlockAddr, (void *)&uiContextVirtAddr);
2165         
2166         rc = BMEM_Free(hXvdCh->sChSettings.hChannelSystemHeap, uiContextVirtAddr);
2167         
2168         if (rc != BERR_SUCCESS)
2169         {
2170            BXVD_DBG_ERR(hXvdCh, ("failed to free sub allocated Context memory"));
2171            return BERR_TRACE(BERR_LEAKED_RESOURCE);
2172         }   
2173      }
2174      else
2175      {
2176         BMEM_ConvertOffsetToAddress(hXvd->hSystemHeap, uiMemBlockAddr, (void *)&uiContextVirtAddr);
2177         
2178         rc = BXVD_P_Memory_Free(hXvd->SubGenMem, uiContextVirtAddr);
2179         
2180         if (rc != BERR_SUCCESS)
2181         {
2182            BXVD_DBG_ERR(hXvdCh, ("failed to free sub allocated Context memory"));
2183            return BERR_TRACE(BERR_LEAKED_RESOURCE);
2184         }               
2185      }
2186   }
2187   
2188   return BERR_TRACE(rc); 
2189}
2190
2191/*
2192 * This function maps FW and shared memory, loads the inner and outer loop
2193 * FW images and kick starts the outer loop ARC.
2194 */
2195BERR_Code BXVD_P_ChipInit(BXVD_Handle hXvd, uint32_t uDecoderInstance)
2196{
2197   uint32_t     *p_FirmWareVBase;
2198   uint32_t     ui_PhysicalBase;
2199   BERR_Code rc;
2200
2201   p_FirmWareVBase = (void *)hXvd->uiFWMemVirtAddr; 
2202   ui_PhysicalBase = hXvd->uiFWMemPhyAddr; 
2203
2204   rc = BXVD_P_FW_LOAD(hXvd, uDecoderInstance);
2205   if (rc != BERR_SUCCESS) return BERR_TRACE(rc);
2206
2207   /* Enable 740x operation */
2208
2209   BXVD_DBG_MSG(hXvd, ("Enabling chip execution"));
2210   rc = BXVD_P_CHIP_ENABLE(hXvd);
2211   if (rc != BERR_SUCCESS) return BERR_TRACE(rc);
2212
2213   BXVD_DBG_MSG(hXvd, ("Shared memory start addr: 0x%x", hXvd->uiFWGenMemPhyAddr));
2214
2215#if FW_INIT
2216   rc = BXVD_P_HostCmdSendInit(hXvd,
2217                               uDecoderInstance,
2218                               hXvd->stSettings.eRaveEndianess
2219                               );
2220
2221   if (rc != BERR_SUCCESS) return BERR_TRACE(rc);
2222#endif
2223   return BERR_TRACE(BERR_SUCCESS);
2224}
2225
2226/*
2227 * Reset 740x SDRAM parameters.
2228 */
2229BERR_Code BXVD_P_Reset740x(BXVD_Handle  hXvd, uint32_t uDecoderInstance)
2230{
2231   BERR_Code rc;
2232
2233   BSTD_UNUSED(uDecoderInstance);
2234 
2235   /* Reset Video Decoder */
2236   rc = BXVD_P_RESET_CHIP(hXvd);
2237
2238   /* AVD has been reset, clear device busy */
2239   hXvd->stDecoderContext.bIfBusy = 0; 
2240
2241   return BERR_TRACE(rc);
2242}
2243
2244/***************************************************************************
2245  BXVD_P_StillPictureEnabled: Enable still pictures
2246****************************************************************************/
2247BERR_Code BXVD_P_StillPictureEnabled(BXVD_Handle hXvd, bool *pEnableState, BXVD_DecodeMode *pSPDecodeMode)
2248{
2249   BXVD_DecodeMode *pTMPDecodeMode;
2250
2251   BDBG_ASSERT(hXvd);
2252
2253   BXVD_DBG_MSG(hXvd, ("SPEnabled?"));
2254
2255   *pSPDecodeMode = BXVD_DecodeMode_eTerminateList;
2256
2257   pTMPDecodeMode = (BXVD_DecodeMode *)hXvd->stSettings.pDecodeModes;
2258       
2259   *pEnableState = false;
2260
2261   while (*pTMPDecodeMode !=  BXVD_DecodeMode_eTerminateList)
2262   {
2263      BXVD_DBG_MSG(hXvd, ("\tDecodemode:%x", *pTMPDecodeMode));
2264
2265      if (*pTMPDecodeMode >= BXVD_DecodeMode_eMaxModes)
2266      {
2267         return BERR_TRACE(BERR_INVALID_PARAMETER);
2268      }
2269
2270      if ((*pTMPDecodeMode == BXVD_DecodeMode_eStill_SD) && (*pSPDecodeMode != BXVD_DecodeMode_eStill_HD))
2271      {
2272         *pEnableState = true;
2273         *pSPDecodeMode = BXVD_DecodeMode_eStill_SD;
2274      }
2275      else if ((*pTMPDecodeMode == BXVD_DecodeMode_eStill_HD) || (*pTMPDecodeMode == BXVD_DecodeMode_eAll))
2276      {
2277         *pEnableState = true;
2278         *pSPDecodeMode = BXVD_DecodeMode_eStill_HD;
2279      }
2280      pTMPDecodeMode++;
2281   }
2282
2283   return BERR_TRACE(BERR_SUCCESS);
2284}
2285
2286/***************************************************************************
2287  BXVD_P_ParseDecodeMode: Return buffer size info for indicated decode mode
2288****************************************************************************/
2289BERR_Code BXVD_P_ParseDecodeMode(BXVD_Handle hXvd,
2290                                 BXVD_DecodeMode *pDecodeModeList,
2291                                 BXVD_DecodeMode *eDecodeMode)
2292{
2293   int32_t PicBufSize = 0;
2294   
2295   BXVD_DecodeMode *pTmpDecMode = pDecodeModeList;
2296
2297   BDBG_ASSERT(pDecodeModeList);
2298   BDBG_ASSERT(eDecodeMode);
2299
2300   *eDecodeMode = BXVD_DecodeMode_eTerminateList;
2301
2302   while ((*pTmpDecMode != BXVD_DecodeMode_eTerminateList))
2303   {
2304      int32_t videoMemSize;
2305
2306      if (*pTmpDecMode >= BXVD_DecodeMode_eMaxModes)
2307      {
2308         BXVD_DBG_ERR(hXvd, ("Invalid decode mode in list"));
2309         return BERR_TRACE(BERR_INVALID_PARAMETER);
2310      }
2311     
2312      if ((*eDecodeMode == BXVD_DecodeMode_eCustom) &&
2313          !((*pTmpDecMode == BXVD_DecodeMode_eCustom) ||
2314            (*pTmpDecMode == BXVD_DecodeMode_eStill_HD) ||
2315            (*pTmpDecMode == BXVD_DecodeMode_eStill_SD)))
2316      {
2317         /* If eCustom is already set, we need to return an error if
2318          * any other decode mode (other than stills) is in the list.
2319          * We only support the following three combinations:
2320            1) Any number of BXVD_DecodeMode_eXXX other than eCustom
2321            2) eCustom and (eStill_HD and/or eStill_SD)
2322            3) eCustom only
2323         */
2324         BXVD_DBG_ERR(hXvd, ("Invalid combination in decode mode list"));
2325         return BERR_TRACE(BERR_INVALID_PARAMETER);
2326      }
2327     
2328      if ((*pTmpDecMode == BXVD_DecodeMode_eCustom) &&
2329          ((*eDecodeMode != BXVD_DecodeMode_eTerminateList) &&
2330           (*eDecodeMode != BXVD_DecodeMode_eCustom) &&
2331           (*eDecodeMode != BXVD_DecodeMode_eStill_HD) &&
2332           (*eDecodeMode != BXVD_DecodeMode_eStill_SD)))
2333      {
2334         /* If the current decode mode in the list is eCustom, but
2335          * some other decode mode (other than stills) is set, then we
2336          * also need to return an error. We only support the
2337          * following three combinations:
2338            1) Any combination of BXVD_DecodeMode_eXXX (other than eCustom)
2339            2) eCustom and (eStill_HD and/or eStill_SD)
2340            3) eCustom only
2341         */
2342         BXVD_DBG_ERR(hXvd, ("Invalid combination in decode mode list"));
2343         return BERR_TRACE(BERR_INVALID_PARAMETER);         
2344      }
2345     
2346      if (*pTmpDecMode == BXVD_DecodeMode_eCustom)
2347      {
2348         /* eCustom takes precendence over all other decode modes */
2349         *eDecodeMode = *pTmpDecMode;
2350      }
2351      else if (*eDecodeMode != BXVD_DecodeMode_eCustom) /* Only change the decode mode if it not already eCustom */
2352      {     
2353         videoMemSize = hXvd->stFWMemCfg[*pTmpDecMode].video_block_size * hXvd->stFWMemCfg[*pTmpDecMode].video_block_count;
2354         
2355         if ( PicBufSize < videoMemSize)
2356         {
2357            PicBufSize = videoMemSize;
2358            *eDecodeMode = *pTmpDecMode;
2359         }
2360      }
2361                       
2362      pTmpDecMode++; /* Point to next item in list */
2363   }
2364
2365   if (*eDecodeMode == BXVD_DecodeMode_eTerminateList)
2366   {
2367      /* In case list is bogus, return max size */
2368      *eDecodeMode = BXVD_DecodeMode_eAll;
2369   }
2370
2371   return BERR_TRACE(BERR_SUCCESS);
2372}
2373
2374BERR_Code BXVD_P_Boot(BXVD_Handle hXvd)
2375{
2376   BERR_Code rc;
2377
2378   /* Reset 740x */
2379   rc = BERR_TRACE(BXVD_P_Reset740x(hXvd, hXvd->uDecoderInstance));
2380   if(rc != BERR_SUCCESS) 
2381   { 
2382      return BERR_TRACE(rc);
2383   }
2384       
2385   /* Initialize interrupts */
2386   rc = BXVD_P_SETUP_INTERRUPTS(hXvd);
2387   if (rc != BERR_SUCCESS)
2388   {
2389      return BERR_TRACE(rc);
2390   }
2391       
2392   /* Initialize the inner and outer loop firmware. */
2393   rc = BXVD_P_ChipInit(hXvd, hXvd->uDecoderInstance);
2394   if(rc != BERR_SUCCESS) 
2395   { 
2396      return BERR_TRACE(rc);
2397   }
2398       
2399   /* Start the watchdog after the decoder starts */
2400   rc = BXVD_P_SETUP_WATCHDOG(hXvd);
2401   if (rc != BERR_SUCCESS)
2402   {
2403      return BERR_TRACE(rc);
2404   }
2405       
2406   return BERR_TRACE(BERR_SUCCESS);
2407}
2408
2409static const BAVC_VideoCompressionStd  StillCmprStdList[] =
2410{
2411   BAVC_VideoCompressionStd_eMPEG2
2412};
2413
2414/*
2415 * Description:
2416 *
2417 *   When an applications is using the multi-decode API but specifying
2418 * video decode modes from the single decode api, a channel is opened
2419 * for still picture decode. This routine opens the channel for MPEG2
2420 * still picture decoding if XVD has determined still picture compatibility
2421 * mode is being used.
2422 */
2423
2424BERR_Code BXVD_P_SetupStillPictureCompatibilityMode(BXVD_Handle hXvd)
2425{
2426   BERR_Code rc;
2427   BXVD_ChannelHandle hXvdCh;
2428
2429   /* coverity[var_decl: FALSE] */
2430   BXVD_ChannelSettings sChSettings;
2431
2432   uint32_t uiStillChannelNum = BXVD_MAX_VIDEO_CHANNELS - 1;
2433
2434   if (hXvd->bStillPictureCompatibilityMode)
2435   {
2436      if (hXvd->uiOpenChannels >= BXVD_MAX_VIDEO_CHANNELS) 
2437      {
2438         BXVD_DBG_ERR(hXvd, ("Still Picture Compatibility Mode: No channels available for the implicit creation of still picture channel"));
2439         return BERR_TRACE(BERR_INVALID_PARAMETER);
2440      }
2441
2442      if (hXvd->ahChannel[uiStillChannelNum] != NULL)
2443      {
2444         BXVD_DBG_ERR(hXvd, ("Still Picture Compatibility Mode: Channel[%d] not available for the implicit creation of still picture channel", uiStillChannelNum));
2445         return BERR_TRACE(BERR_INVALID_PARAMETER);           
2446      }
2447      /* coverity[uninit_use_in_call: FALSE] */
2448      BXVD_GetChannelDefaultSettings(hXvd,
2449                                     uiStillChannelNum,
2450                                     &sChSettings);
2451
2452      /* Settings for MPEG2 Still Decode */
2453      sChSettings.peVideoCmprStdList = (BAVC_VideoCompressionStd*) &StillCmprStdList;
2454      sChSettings.uiVideoCmprCount = 1;
2455      sChSettings.eChannelMode = BXVD_ChannelMode_eStill;
2456
2457      if (hXvd->bStillHDCapable)
2458      {
2459         sChSettings.eDecodeResolution = BXVD_DecodeResolution_eHD;
2460      }
2461
2462      else
2463      {
2464         sChSettings.eDecodeResolution = BXVD_DecodeResolution_eSD;
2465      }
2466
2467      rc = BXVD_OpenChannel(
2468         hXvd,
2469         &hXvdCh,
2470         uiStillChannelNum,
2471         &sChSettings);
2472
2473      if (rc != BERR_SUCCESS)
2474      {
2475         BXVD_DBG_ERR(hXvd, ("Still Picture Compatibility Mode: Error opening still channel[%d]", uiStillChannelNum));
2476         return BERR_TRACE(rc);
2477      }
2478
2479      BXVD_DBG_WRN(hXvd, ("Still Picture Compatibility Mode: created implicit still picture channel [%d]",                   
2480                               hXvdCh->ulChannelNum));
2481   }
2482
2483   return BERR_TRACE(BERR_SUCCESS);
2484}
2485
2486BERR_Code BXVD_P_TeardownStillPictureCompatibilityMode(BXVD_Handle hXvd)
2487{
2488   BERR_Code rc;
2489
2490   if ((hXvd->bStillPictureCompatibilityMode) && (hXvd->ahChannel != NULL))
2491   {
2492      if (hXvd->ahChannel[hXvd->uiStillChannelNum] != NULL)
2493      {         
2494         rc = BXVD_CloseChannel(hXvd->ahChannel[hXvd->uiStillChannelNum]);
2495         if (rc != BERR_SUCCESS)
2496         {
2497            BXVD_DBG_ERR(hXvd, ("Still Picture Compatibility Mode: Error closing still channel[%d]", hXvd->uiStillChannelNum));
2498            return BERR_TRACE(rc);
2499         }
2500
2501#if BXVD_P_POWER_MANAGEMENT
2502         /* Wake up the decoder, may have been put to sleep closing the still channel  */
2503         BXVD_P_SetHibernateState(hXvd, false);
2504#endif         
2505      }
2506   }
2507   return BERR_TRACE(BERR_SUCCESS);
2508}
2509
2510BERR_Code BXVD_P_InitializeFWMemConfigCompatibilityModeTable(BXVD_Handle hXvd)
2511{
2512   BERR_Code rc;
2513   BXVD_DecodeResolution eDecodeResolution;
2514   BAVC_VideoCompressionStd aeVideoCmprStd[1];
2515   BXVD_DecodeMode eDecodeModeIndex = 0;
2516   BXVD_ChannelSettings ChSettings;
2517   BXVD_P_DecodeFWMemSize stDecodeFWMemSize;
2518
2519   /* BXVD_DecodeMode_eAVC_HD */
2520   eDecodeResolution = BXVD_DecodeResolution_eHD;
2521   aeVideoCmprStd[0] = BAVC_VideoCompressionStd_eH264;
2522
2523   ChSettings.bMPEG2BTPEnable = true;
2524   ChSettings.bAVC41Enable = false;
2525   ChSettings.bAVC51Enable = false;
2526   ChSettings.bBluRayEnable = false;
2527   ChSettings.bExcessDirModeEnable = false;
2528   ChSettings.bSVC3DModeEnable = false;
2529   ChSettings.bSVCProgressiveOnly = false;
2530   ChSettings.b1920PortraitModeEnable = false;
2531
2532   rc = BXVD_P_GetDecodeFWMemSize(hXvd,
2533                                  eDecodeResolution,
2534                                  aeVideoCmprStd,
2535                                  1,
2536                                  &ChSettings,
2537                                  &stDecodeFWMemSize);
2538
2539   hXvd->stFWMemCfg[BXVD_DecodeMode_eAVC_HD].general_memory_size = stDecodeFWMemSize.uiFWContextSize;
2540   hXvd->stFWMemCfg[BXVD_DecodeMode_eAVC_HD].cabac_bin_size  = stDecodeFWMemSize.uiFWCabacSize;
2541   hXvd->stFWMemCfg[BXVD_DecodeMode_eAVC_HD].video_block_size = stDecodeFWMemSize.uiFWPicBlockSize;
2542   hXvd->stFWMemCfg[BXVD_DecodeMode_eAVC_HD].video_block_count =  stDecodeFWMemSize.uiFWPicBlockCount;
2543
2544   hXvd->stFWMemCfg[BXVD_DecodeMode_eAVC_HD].cabac_bin_size += stDecodeFWMemSize.uiFWCabacWorklistSize;
2545
2546   hXvd->stFWMemCfg[BXVD_DecodeMode_eAVC_HD].general_memory_size += 
2547      stDecodeFWMemSize.uiFWDirectModeSize + stDecodeFWMemSize.uiFWInnerLoopWorklistSize;
2548
2549   if (rc != BERR_SUCCESS)
2550   {
2551      return BERR_TRACE(rc);
2552   }
2553   
2554 
2555   /* BXVD_DecodeMode_eAVC_SD */
2556   eDecodeResolution = BXVD_DecodeResolution_eSD;
2557   aeVideoCmprStd[0] = BAVC_VideoCompressionStd_eH264;
2558   rc = BXVD_P_GetDecodeFWMemSize(hXvd,
2559                                  eDecodeResolution,
2560                                  aeVideoCmprStd,
2561                                  1,
2562                                  &ChSettings,
2563                                  &stDecodeFWMemSize);
2564
2565   hXvd->stFWMemCfg[BXVD_DecodeMode_eAVC_SD].general_memory_size = stDecodeFWMemSize.uiFWContextSize;
2566   hXvd->stFWMemCfg[BXVD_DecodeMode_eAVC_SD].cabac_bin_size  = stDecodeFWMemSize.uiFWCabacSize;
2567   hXvd->stFWMemCfg[BXVD_DecodeMode_eAVC_SD].video_block_size = stDecodeFWMemSize.uiFWPicBlockSize;
2568   hXvd->stFWMemCfg[BXVD_DecodeMode_eAVC_SD].video_block_count =  stDecodeFWMemSize.uiFWPicBlockCount;
2569
2570   hXvd->stFWMemCfg[BXVD_DecodeMode_eAVC_SD].cabac_bin_size += stDecodeFWMemSize.uiFWCabacWorklistSize;
2571
2572   hXvd->stFWMemCfg[BXVD_DecodeMode_eAVC_SD].general_memory_size += 
2573      stDecodeFWMemSize.uiFWDirectModeSize + stDecodeFWMemSize.uiFWInnerLoopWorklistSize;
2574
2575   if (rc != BERR_SUCCESS)
2576   {
2577      return BERR_TRACE(rc);
2578   }
2579                                 
2580   /* BXVD_DecodeMode_eMPEG2_HD */
2581   eDecodeResolution = BXVD_DecodeResolution_eHD;
2582   aeVideoCmprStd[0] = BAVC_VideoCompressionStd_eMPEG2;
2583   rc = BXVD_P_GetDecodeFWMemSize(hXvd,
2584                                  eDecodeResolution,
2585                                  aeVideoCmprStd,
2586                                  1,
2587                                  &ChSettings,
2588                                  &stDecodeFWMemSize);
2589
2590   hXvd->stFWMemCfg[BXVD_DecodeMode_eMPEG2_HD].video_block_size = stDecodeFWMemSize.uiFWPicBlockSize;
2591   hXvd->stFWMemCfg[BXVD_DecodeMode_eMPEG2_HD].video_block_count =  stDecodeFWMemSize.uiFWPicBlockCount;
2592
2593   hXvd->stFWMemCfg[BXVD_DecodeMode_eMPEG2_HD].general_memory_size = stDecodeFWMemSize.uiFWContextSize + 
2594      stDecodeFWMemSize.uiFWDirectModeSize + stDecodeFWMemSize.uiFWInnerLoopWorklistSize;
2595
2596   hXvd->stFWMemCfg[BXVD_DecodeMode_eMPEG2_HD].cabac_bin_size = 
2597      stDecodeFWMemSize.uiFWCabacSize + stDecodeFWMemSize.uiFWCabacWorklistSize;
2598
2599   if (rc != BERR_SUCCESS)
2600   {
2601      return BERR_TRACE(rc);
2602   }
2603
2604   /* BXVD_DecodeMode_eMPEG2_SD */
2605   eDecodeResolution = BXVD_DecodeResolution_eSD;
2606   aeVideoCmprStd[0] = BAVC_VideoCompressionStd_eMPEG2;
2607   rc = BXVD_P_GetDecodeFWMemSize(hXvd,
2608                                  eDecodeResolution,
2609                                  aeVideoCmprStd,
2610                                  1,
2611                                  &ChSettings,
2612                                  &stDecodeFWMemSize);
2613
2614   hXvd->stFWMemCfg[BXVD_DecodeMode_eMPEG2_SD].video_block_size = stDecodeFWMemSize.uiFWPicBlockSize;
2615   hXvd->stFWMemCfg[BXVD_DecodeMode_eMPEG2_SD].video_block_count =  stDecodeFWMemSize.uiFWPicBlockCount;
2616
2617   hXvd->stFWMemCfg[BXVD_DecodeMode_eMPEG2_SD].general_memory_size = stDecodeFWMemSize.uiFWContextSize + 
2618      stDecodeFWMemSize.uiFWDirectModeSize + stDecodeFWMemSize.uiFWInnerLoopWorklistSize;
2619
2620   hXvd->stFWMemCfg[BXVD_DecodeMode_eMPEG2_SD].cabac_bin_size = 
2621      stDecodeFWMemSize.uiFWCabacSize + stDecodeFWMemSize.uiFWCabacWorklistSize;
2622
2623   if (rc != BERR_SUCCESS)
2624   {
2625      return BERR_TRACE(rc);
2626   }
2627   
2628   /* BXVD_DecodeMode_eVC1_HD */
2629   eDecodeResolution = BXVD_DecodeResolution_eHD;
2630   aeVideoCmprStd[0] = BAVC_VideoCompressionStd_eVC1;
2631   rc = BXVD_P_GetDecodeFWMemSize(hXvd,
2632                                  eDecodeResolution,
2633                                  aeVideoCmprStd,
2634                                  1,
2635                                  &ChSettings,
2636                                  &stDecodeFWMemSize);
2637
2638   hXvd->stFWMemCfg[BXVD_DecodeMode_eVC1_HD].video_block_size = stDecodeFWMemSize.uiFWPicBlockSize;
2639   hXvd->stFWMemCfg[BXVD_DecodeMode_eVC1_HD].video_block_count =  stDecodeFWMemSize.uiFWPicBlockCount;
2640
2641   hXvd->stFWMemCfg[BXVD_DecodeMode_eVC1_HD].general_memory_size = stDecodeFWMemSize.uiFWContextSize + 
2642      stDecodeFWMemSize.uiFWDirectModeSize + stDecodeFWMemSize.uiFWInnerLoopWorklistSize;
2643
2644   hXvd->stFWMemCfg[BXVD_DecodeMode_eVC1_HD].cabac_bin_size = 
2645      stDecodeFWMemSize.uiFWCabacSize + stDecodeFWMemSize.uiFWCabacWorklistSize;
2646
2647   if (rc != BERR_SUCCESS)
2648   {
2649      return BERR_TRACE(rc);
2650   }
2651
2652   /* BXVD_DecodeMode_eVC1_SD */
2653   eDecodeResolution = BXVD_DecodeResolution_eSD;
2654   aeVideoCmprStd[0] = BAVC_VideoCompressionStd_eVC1;
2655   rc = BXVD_P_GetDecodeFWMemSize(hXvd,
2656                                  eDecodeResolution,
2657                                  aeVideoCmprStd,
2658                                  1,
2659                                  &ChSettings,
2660                                  &stDecodeFWMemSize);
2661
2662   hXvd->stFWMemCfg[BXVD_DecodeMode_eVC1_SD].video_block_size = stDecodeFWMemSize.uiFWPicBlockSize;
2663   hXvd->stFWMemCfg[BXVD_DecodeMode_eVC1_SD].video_block_count =  stDecodeFWMemSize.uiFWPicBlockCount;
2664
2665   hXvd->stFWMemCfg[BXVD_DecodeMode_eVC1_SD].general_memory_size = stDecodeFWMemSize.uiFWContextSize + 
2666      stDecodeFWMemSize.uiFWDirectModeSize + stDecodeFWMemSize.uiFWInnerLoopWorklistSize;
2667
2668   hXvd->stFWMemCfg[BXVD_DecodeMode_eVC1_SD].cabac_bin_size = 
2669      stDecodeFWMemSize.uiFWCabacSize + stDecodeFWMemSize.uiFWCabacWorklistSize;
2670
2671   if (rc != BERR_SUCCESS)
2672   {
2673      return BERR_TRACE(rc);
2674   }
2675
2676   /* BXVD_DecodeMode_eStill_HD */
2677   eDecodeResolution = BXVD_DecodeResolution_eHD;
2678   aeVideoCmprStd[0] = BAVC_VideoCompressionStd_eMPEG2;
2679   rc = BXVD_P_GetStillDecodeFWMemSize(hXvd,
2680                                       eDecodeResolution,
2681                                       aeVideoCmprStd,
2682                                       1,
2683                                       &stDecodeFWMemSize);
2684
2685   hXvd->stFWMemCfg[BXVD_DecodeMode_eStill_HD].video_block_size = stDecodeFWMemSize.uiFWPicBlockSize;
2686   hXvd->stFWMemCfg[BXVD_DecodeMode_eStill_HD].video_block_count =  stDecodeFWMemSize.uiFWPicBlockCount;
2687
2688   hXvd->stFWMemCfg[BXVD_DecodeMode_eStill_HD].general_memory_size = 
2689      stDecodeFWMemSize.uiFWContextSize + stDecodeFWMemSize.uiFWInnerLoopWorklistSize;
2690
2691   /* Use reduced memory still footprint for compatibility table */
2692   hXvd->stFWMemCfg[BXVD_DecodeMode_eStill_HD].cabac_bin_size = stDecodeFWMemSize.uiFWCabacWorklistSize;
2693
2694   if (rc != BERR_SUCCESS)
2695   {
2696      return BERR_TRACE(rc);
2697   }
2698
2699   /* BXVD_DecodeMode_eStill_SD */
2700   eDecodeResolution = BXVD_DecodeResolution_eSD;
2701   aeVideoCmprStd[0] = BAVC_VideoCompressionStd_eMPEG2;
2702   rc = BXVD_P_GetStillDecodeFWMemSize(hXvd,
2703                                       eDecodeResolution,
2704                                       aeVideoCmprStd,
2705                                       1,
2706                                       &stDecodeFWMemSize);
2707
2708   hXvd->stFWMemCfg[BXVD_DecodeMode_eStill_SD].video_block_size = stDecodeFWMemSize.uiFWPicBlockSize;
2709   hXvd->stFWMemCfg[BXVD_DecodeMode_eStill_SD].video_block_count =  stDecodeFWMemSize.uiFWPicBlockCount;
2710
2711   hXvd->stFWMemCfg[BXVD_DecodeMode_eStill_SD].general_memory_size = 
2712      stDecodeFWMemSize.uiFWContextSize + stDecodeFWMemSize.uiFWInnerLoopWorklistSize;
2713
2714   /* Use reduced memory still footprint for compatibility table */
2715   hXvd->stFWMemCfg[BXVD_DecodeMode_eStill_SD].cabac_bin_size = stDecodeFWMemSize.uiFWCabacWorklistSize;
2716
2717   if (rc != BERR_SUCCESS)
2718   {
2719      return BERR_TRACE(rc);
2720   }
2721
2722   /* BXVD_DecodeMode_eAll */
2723   /* Set the BXVD_DecodeMode_eAll entry to the decode mode that requires the most memory */
2724   for (eDecodeModeIndex = BXVD_DecodeMode_eAVC_HD; eDecodeModeIndex <= BXVD_DecodeMode_eStill_SD; eDecodeModeIndex++)
2725   {
2726      if ((hXvd->stFWMemCfg[eDecodeModeIndex].general_memory_size + 
2727           hXvd->stFWMemCfg[eDecodeModeIndex].cabac_bin_size + 
2728           (hXvd->stFWMemCfg[eDecodeModeIndex].video_block_size *
2729            hXvd->stFWMemCfg[eDecodeModeIndex].video_block_count)) >         
2730          (hXvd->stFWMemCfg[BXVD_DecodeMode_eAll].general_memory_size + 
2731           hXvd->stFWMemCfg[BXVD_DecodeMode_eAll].cabac_bin_size + 
2732           (hXvd->stFWMemCfg[BXVD_DecodeMode_eAll].video_block_size *
2733            hXvd->stFWMemCfg[BXVD_DecodeMode_eAll].video_block_count)))
2734      {
2735         hXvd->stFWMemCfg[BXVD_DecodeMode_eAll] = hXvd->stFWMemCfg[eDecodeModeIndex];
2736      }
2737   }
2738         
2739   for (eDecodeModeIndex = BXVD_DecodeMode_eTerminateList; eDecodeModeIndex <= BXVD_DecodeMode_eStill_SD; eDecodeModeIndex++)
2740   {
2741      BXVD_DBG_MSG(hXvd, ("Decode Mode %d: { %8d, %8d, %8d, %2d }",
2742                               eDecodeModeIndex,
2743                               hXvd->stFWMemCfg[eDecodeModeIndex].general_memory_size,
2744                               hXvd->stFWMemCfg[eDecodeModeIndex].cabac_bin_size,
2745                               hXvd->stFWMemCfg[eDecodeModeIndex].video_block_size,
2746                               hXvd->stFWMemCfg[eDecodeModeIndex].video_block_count));     
2747   }
2748
2749   return BERR_TRACE(BERR_SUCCESS);
2750}
2751
2752BERR_Code BXVD_P_InitChannel(BXVD_ChannelHandle  hXvdCh)
2753{
2754   BXDM_Decoder_Interface stDecoderInterface;
2755   void *pPrivateContext;
2756
2757   BXVD_3DSetting st3DSettings;
2758
2759   BXVD_Handle hXvd;
2760
2761   BERR_Code rc;
2762
2763   hXvd = hXvdCh->pXvd;
2764
2765   /* Initialize channel settings */
2766   hXvdCh->eDecoderState = BXVD_P_DecoderState_eNotActive;
2767   hXvdCh->bPreserveState = false;
2768
2769   hXvdCh->eCurrentSkipMode = BXVD_SkipMode_eDecode_IPB;
2770
2771   rc = BXDM_PictureProvider_SetTimerHandle_isr(hXvdCh->hPictureProvider, hXvd->hTimer);
2772
2773   if (rc != BERR_SUCCESS)
2774   {
2775      return BERR_TRACE(rc);
2776   }
2777
2778   rc = BXDM_PictureProvider_GetDefaultDecoderInterface_isr( &stDecoderInterface );
2779
2780   if (rc != BERR_SUCCESS)
2781   {
2782      return BERR_TRACE(rc);
2783   }
2784
2785   rc = BXVD_Decoder_GetDMInterface(
2786      hXvdCh,
2787      &stDecoderInterface,
2788      &pPrivateContext
2789      );
2790
2791   if (rc != BERR_SUCCESS)
2792   {
2793      return BERR_TRACE(rc);
2794   }
2795
2796   rc = BXDM_PictureProvider_SetDecoderInterface_isr(
2797      hXvdCh->hPictureProvider,
2798      &stDecoderInterface,
2799      pPrivateContext);
2800
2801   if (rc != BERR_SUCCESS)
2802   {
2803   
2804      return BERR_TRACE(rc);
2805   }
2806
2807   /* SW7422-72: set the default 3D behavior to support legacy MVC systems.
2808    * The original MVC behavior on the DVD chips was to set "pNext" in the MFD structure
2809    * of frame 0 to point to frame 1.  By setting the default here, the older
2810    * DVD platforms will get this behavior without having to change any code.
2811    */
2812   rc = BXVD_GetDefault3D( hXvdCh, &st3DSettings );
2813
2814   if (rc != BERR_SUCCESS)
2815   {
2816      return BERR_TRACE(rc);
2817   }
2818
2819   rc = BXVD_Set3D_isr( hXvdCh, &st3DSettings );
2820
2821   if (rc != BERR_SUCCESS)
2822   {
2823      return BERR_TRACE(rc);
2824   }
2825
2826   rc = BXVD_SetPictureDropMode_isr(hXvdCh, hXvdCh->sChSettings.ePictureDropMode );
2827
2828   if (rc != BERR_SUCCESS)
2829   {
2830      return BERR_TRACE(rc);
2831   }
2832
2833   rc = BXVD_SetPtsStcDiffThreshold_isr(hXvdCh, hXvdCh->sChSettings.uiVsyncDiffThreshDefault);
2834
2835   if (rc != BERR_SUCCESS)
2836   {
2837      BXVD_CloseChannel(hXvdCh);
2838      return BERR_TRACE(rc);
2839   }
2840
2841   rc = BXVD_SetMonitorRefreshRate_isr(hXvdCh, hXvdCh->sChSettings.ui32MonitorRefreshRate);
2842
2843   if (rc != BERR_SUCCESS)
2844   {
2845      return BERR_TRACE(rc);
2846   }
2847
2848   rc = BXVD_Set1080pScanMode_isr(hXvdCh, hXvdCh->sChSettings.e1080pScanMode);
2849
2850   if (rc != BERR_SUCCESS)
2851   {
2852      return BERR_TRACE(rc);
2853   }
2854
2855   return rc;
2856}
2857
2858
2859BERR_Code BXVD_P_DestroyInterrupts(BXVD_Handle hXvd)
2860{
2861   BXVD_DisplayInterrupt eDisplayInterrupt;
2862
2863   BERR_Code rc;
2864
2865   if (hXvd->stDecoderContext.pCbAVC_MBX_ISR)
2866   {
2867      rc = BINT_DestroyCallback(hXvd->stDecoderContext.pCbAVC_MBX_ISR);
2868      if (BERR_SUCCESS != rc)
2869      {
2870         return BERR_TRACE(rc);
2871      }
2872   }
2873
2874   if (hXvd->stDecoderContext.pCbAVC_StillPicRdy_ISR)
2875   {
2876      rc = BINT_DestroyCallback(hXvd->stDecoderContext.pCbAVC_StillPicRdy_ISR);
2877      if (BERR_SUCCESS != rc)
2878      {
2879         return BERR_TRACE(rc);
2880      }
2881   }
2882
2883   if (hXvd->stDecoderContext.pCbAVC_Watchdog_ISR)
2884   {
2885      rc = BINT_DestroyCallback(hXvd->stDecoderContext.pCbAVC_Watchdog_ISR);
2886      if (BERR_SUCCESS != rc)
2887      {
2888         return BERR_TRACE(rc);
2889      }
2890   }
2891
2892   if (hXvd->stDecoderContext.pCbAVC_VICHReg_ISR)
2893   {
2894      rc = BINT_DestroyCallback(hXvd->stDecoderContext.pCbAVC_VICHReg_ISR);
2895      if (BERR_SUCCESS != rc)
2896      {
2897         return BERR_TRACE(rc);
2898      }
2899   }
2900
2901   if (hXvd->stDecoderContext.pCbAVC_VICHSCB_ISR)
2902   {
2903      rc = BINT_DestroyCallback(hXvd->stDecoderContext.pCbAVC_VICHSCB_ISR);
2904      if (BERR_SUCCESS != rc)
2905      {
2906         return BERR_TRACE(rc);
2907      }
2908   }
2909
2910   if (hXvd->stDecoderContext.pCbAVC_VICHInstrRd_ISR)
2911   {
2912      rc = BINT_DestroyCallback(hXvd->stDecoderContext.pCbAVC_VICHInstrRd_ISR);
2913      if (BERR_SUCCESS != rc)
2914      {
2915         return BERR_TRACE(rc);
2916      }
2917   }
2918
2919#if BXVD_P_AVD_ARC600
2920   if (hXvd->stDecoderContext.pCbAVC_VICHILInstrRd_ISR)
2921   {
2922      rc = BINT_DestroyCallback(hXvd->stDecoderContext.pCbAVC_VICHILInstrRd_ISR);
2923      if (BERR_SUCCESS != rc)
2924      {
2925         return BERR_TRACE(rc);
2926      }
2927   }
2928
2929   if (hXvd->bSVCCapable == true)
2930   {
2931      if (hXvd->stDecoderContext.pCbAVC_VICHBLInstrRd_ISR)
2932      {
2933         rc = BINT_DestroyCallback(hXvd->stDecoderContext.pCbAVC_VICHBLInstrRd_ISR);
2934         if (BERR_SUCCESS != rc)
2935         {
2936            return BERR_TRACE(rc);
2937         }
2938      }
2939   }
2940#endif
2941
2942   if (hXvd->stDecoderContext.pCbAVC_StereoSeqError_ISR)
2943   {
2944      rc = BINT_DestroyCallback(hXvd->stDecoderContext.pCbAVC_StereoSeqError_ISR);
2945      if (BERR_SUCCESS != rc)
2946      {
2947         return BERR_TRACE(rc);
2948      }
2949   }
2950
2951   for ( eDisplayInterrupt = 0; eDisplayInterrupt < BXVD_DisplayInterrupt_eMax; eDisplayInterrupt++ )
2952   {
2953      rc = BXVD_DisplayInterruptProvider_P_CloseChannel( hXvd->hXvdDipCh[eDisplayInterrupt] );
2954      if (rc != BERR_SUCCESS)
2955      {
2956         return BERR_TRACE(rc);
2957      }
2958
2959      rc = BXDM_DisplayInterruptHandler_Destroy( hXvd->hXdmDih[eDisplayInterrupt] );
2960      if (rc != BERR_SUCCESS)
2961      {
2962         return BERR_TRACE(rc);
2963      }
2964   }
2965
2966   return rc;
2967}
2968
2969void BXVD_P_FreeXVDContext(BXVD_Handle hXvd)
2970{
2971   /* Destroy the FW command event */
2972   if (hXvd->stDecoderContext.hFWCmdDoneEvent)
2973   {
2974      BKNI_DestroyEvent(hXvd->stDecoderContext.hFWCmdDoneEvent);
2975   }
2976
2977   /* Free the channel handle array */
2978   if (hXvd->ahChannel)
2979   {
2980      BKNI_Free(hXvd->ahChannel);
2981   }
2982
2983   /* Free the Still Picture Channel Handle */
2984   if (hXvd->hStillChannel)
2985   {
2986      BKNI_Free(hXvd->hStillChannel);
2987   }
2988
2989   /* Free the multi-decode picture list */
2990   if (hXvd->pVDCPictureBuffers)
2991   {
2992      BKNI_Free(hXvd->pVDCPictureBuffers);
2993   }
2994
2995   /* Free decode mode list (if allocated) */
2996   if (hXvd->bAllocDecodeModeList)
2997   {
2998      BKNI_Free(hXvd->stSettings.pDecodeModes);
2999      hXvd->stSettings.pDecodeModes = NULL;
3000      hXvd->bAllocDecodeModeList = false;
3001   }
3002
3003   /* Destroy Timer */
3004   if (hXvd->hTimer)
3005   {
3006      BTMR_DestroyTimer(hXvd->hTimer);
3007   }
3008
3009   /* Set eHandleType to invalid to prevent handle from being used again */
3010   hXvd->eHandleType = BXVD_P_HandleType_Invalid;
3011
3012   /* Release the main context */
3013   BKNI_Free(hXvd);
3014}
3015
3016#if BXVD_P_POWER_MANAGEMENT
3017#if !BCHP_PWR_RESOURCE_AVD0
3018
3019void BXVD_P_GetHibernateState(BXVD_Handle hXvd, bool *bHibernateState)
3020{
3021   uint32_t uiRegVal;
3022
3023   /* Assume clocks are on */
3024   *bHibernateState = false;
3025
3026   /* Check to if PM reg pointers are NULL */
3027   if ( (hXvd->stPlatformInfo.stReg.uiClkGen_CoreClkCtrl == 0) &&
3028        (hXvd->stPlatformInfo.stReg.uiVCXO_AVDCtrl == 0) &&
3029        (hXvd->stPlatformInfo.stReg.uiClkGen_SCBClkCtrl == 0) &&
3030        (hXvd->stPlatformInfo.stReg.uiClkGen_GISBClkCtrl == 0) )
3031   {
3032      BXVD_DBG_WRN(hXvd, ("XVD Powermanagement is not supported on this platform!"));
3033
3034      return;
3035   }
3036
3037   /* Test each clock, if any one is off, set hibernate state to true. */
3038
3039   uiRegVal = BXVD_Reg_Read32(hXvd, hXvd->stPlatformInfo.stReg.uiClkGen_CoreClkCtrl);
3040
3041   if ( uiRegVal & hXvd->stPlatformInfo.stReg.uiClkGen_CoreClkCtrl_PwrDnMask)
3042   {
3043      *bHibernateState = true;
3044   }
3045
3046   if (hXvd->stPlatformInfo.stReg.uiVCXO_AVDCtrl != (uint32_t)NULL)
3047   {
3048      uiRegVal = BXVD_Reg_Read32(hXvd, hXvd->stPlatformInfo.stReg.uiVCXO_AVDCtrl);
3049
3050      if (uiRegVal & hXvd->stPlatformInfo.stReg.uiVCXO_AVDCtrl_PwrDnMask)
3051      {
3052         *bHibernateState = true;
3053      }
3054   }
3055   
3056   uiRegVal = BXVD_Reg_Read32(hXvd, hXvd->stPlatformInfo.stReg.uiClkGen_SCBClkCtrl);
3057
3058   if ( uiRegVal & hXvd->stPlatformInfo.stReg.uiClkGen_SCBClkCtrl_PwrDnMask)
3059   {
3060      *bHibernateState = true;
3061   }
3062
3063   uiRegVal = BXVD_Reg_Read32(hXvd, hXvd->stPlatformInfo.stReg.uiClkGen_GISBClkCtrl);
3064
3065   if ( uiRegVal &hXvd->stPlatformInfo.stReg.uiClkGen_GISBClkCtrl_PwrDnMask)
3066   {
3067      *bHibernateState = true;
3068   }
3069}
3070#endif
3071
3072void BXVD_P_SetHibernateState(BXVD_Handle hXvd, bool bHibernateState)
3073{
3074
3075   if ((bHibernateState == false) && (hXvd->bHibernate == true))
3076   {
3077      BXVD_DBG_MSG(hXvd, ("SetHibernate(false), acquire power resource AVD%d", hXvd->uDecoderInstance));
3078
3079      BXVD_P_SET_POWER_STATE(hXvd, BXVD_P_PowerState_eOn);
3080
3081      hXvd->bHibernate = false;
3082   }
3083   else if ((bHibernateState == true) && (hXvd->bHibernate == false))
3084   {
3085      BXVD_DBG_MSG(hXvd, ("SetHibernate(true), release power resource AVD%d", hXvd->uDecoderInstance));
3086
3087      BXVD_P_SET_POWER_STATE(hXvd, BXVD_P_PowerState_eClkOff);
3088
3089      hXvd->bHibernate = true;
3090   }
3091}
3092
3093#endif
Note: See TracBrowser for help on using the repository browser.