source: svn/newcon3bcm2_21bu/nexus/modules/display/7552/src/nexus_display_module.c

Last change on this file was 76, checked in by megakiss, 10 years ago

1W 대기전력을 만족시키기 위하여 POWEROFF시 튜너를 Standby 상태로 함

  • Property svn:executable set to *
File size: 47.5 KB
Line 
1/***************************************************************************
2 *     (c)2007-2011 Broadcom Corporation
3 *
4 *  This program is the proprietary software of Broadcom Corporation and/or its licensors,
5 *  and may only be used, duplicated, modified or distributed pursuant to the terms and
6 *  conditions of a separate, written license agreement executed between you and Broadcom
7 *  (an "Authorized License").  Except as set forth in an Authorized License, Broadcom grants
8 *  no license (express or implied), right to use, or waiver of any kind with respect to the
9 *  Software, and Broadcom expressly reserves all rights in and to the Software and all
10 *  intellectual property rights therein.  IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU
11 *  HAVE NO RIGHT TO USE THIS SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY
12 *  NOTIFY BROADCOM AND DISCONTINUE ALL USE OF THE SOFTWARE.
13 *
14 *  Except as expressly set forth in the Authorized License,
15 *
16 *  1.     This program, including its structure, sequence and organization, constitutes the valuable trade
17 *  secrets of Broadcom, and you shall use all reasonable efforts to protect the confidentiality thereof,
18 *  and to use this information only in connection with your use of Broadcom integrated circuit products.
19 *
20 *  2.     TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
21 *  AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, REPRESENTATIONS OR
22 *  WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
23 *  THE SOFTWARE.  BROADCOM SPECIFICALLY DISCLAIMS ANY AND ALL IMPLIED WARRANTIES
24 *  OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE,
25 *  LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION
26 *  OR CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT OF
27 *  USE OR PERFORMANCE OF THE SOFTWARE.
28 *
29 *  3.     TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR ITS
30 *  LICENSORS BE LIABLE FOR (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR
31 *  EXEMPLARY DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO YOUR
32 *  USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM HAS BEEN ADVISED OF
33 *  THE POSSIBILITY OF SUCH DAMAGES; OR (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT
34 *  ACTUALLY PAID FOR THE SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE
35 *  LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF ESSENTIAL PURPOSE OF
36 *  ANY LIMITED REMEDY.
37 *
38 * $brcm_Workfile: nexus_display_module.c $
39 * $brcm_Revision: 110 $
40 * $brcm_Date: 11/15/11 3:27p $
41 *
42 * Module Description:
43 *
44 * Revision History:
45 *
46 * $brcm_Log: /nexus/modules/display/7400/src/nexus_display_module.c $
47 *
48 * 110   11/15/11 3:27p erickson
49 * SW7425-1747: remove old code
50 *
51 * 109   10/31/11 7:49p bandrews
52 * SW7231-391: merge to main
53 *
54 * SW7420-2078/1   10/31/11 7:34p bandrews
55 * SW7231-391: added dependency on transport for timebase calls
56 *
57 * 108   10/6/11 3:42p erickson
58 * SW7420-2070: add NEXUS_VBI_ENCODER_QUEUE_SIZE macro to control vbilib
59 *  allocations using (NEXUS_VBI_ENCODER_QUEUE_SIZE+1)*NEXUS_NUM_DISPLAYS
60 *  formula.
61 *
62 * 107   7/8/11 4:13p erickson
63 * SW7425-592: add NEXUS_DisplayAspectRatio_eSar for custom display
64 *  formats
65 *
66 * 106   5/24/11 4:17p erickson
67 * SW7422-280: without a video source, nexus graphics should default to
68 *  59.94/29.97/23.976 (i.e. drop frame)
69 *
70 * 105   3/29/11 3:04p erickson
71 * SW7420-1671: NEXUS_DisplayModule_Uninit must acquire lock before doing
72 *  cleanup
73 *
74 * 104   2/25/11 4:37p erickson
75 * SW7422-255: add AMOL support
76 *
77 * 103   1/17/11 9:55p jerrylim
78 * SW35125-54: Added 35125 cases for VDB calls
79 *
80 * 102   12/27/10 11:57a erickson
81 * SW7422-2: NEXUS_DisplayModule_Init can call
82 *  NEXUS_Heap_SetDisplayHeapSettings per heap
83 *
84 * 101   12/15/10 5:38p vsilyaev
85 * SW7405-4996: Revert StrCmp change
86 *
87 * SW7405-4996_1/1   12/14/10 10:59a calvinho
88 * SW7405-4996: Revert StrCmp change
89 *
90 * SW7420-1177/1   11/5/10 3:28p spothana
91 * SW7420-1177 : Add DVO to display dependency list
92 *
93 * 99   11/18/10 11:04p spothana
94 * SW7420-1078: assign heap index per video window
95 *
96 * 98   11/18/10 4:27p erickson
97 * SW7420-1078: SW7420-1078
98 *
99 * 97   11/17/10 7:12p vsilyaev
100 * SW7405-4996: Use strcmp function for string comparison
101 *
102 * SW7405-4996/1   11/16/10 10:05a calvinho
103 * SW7405-4996: Update string compare function calls
104 *
105 * 96   11/2/10 2:19p vsilyaev
106 * SW7422-64: Added API to set 3D framebuffer
107 *
108 * 95   10/14/10 11:44a jerrylim
109 * SW35230-1746: Custom PQ init to be done in app
110 *
111 * 94   10/12/10 5:00p spothana
112 * SW7420-1157 : Correct the HD and 2HD buffer assignment.
113 *
114 * 93   10/12/10 11:02a spothana
115 * SW7420-1157 : Match the VDC memory usage in the reference software to
116 *  memory worksheet
117 *
118 * 92   9/30/10 2:02p petlee
119 * SW35230-1001: Integrate latest backlight dimming changes from VDC
120 *
121 * 91   9/23/10 4:02p jerrylim
122 * SW35230-1332: populated RTS features to VDC context
123 *
124 * 90   9/22/10 4:01p mward
125 * SWDEPRECATED-3811: Eliminate warning for unused strings with DEBUG=n.
126 *
127 * 89   9/9/10 2:42p jerrylim
128 * SW35230-1262: Add PQ customization templates and examples
129 *
130 * 88   8/26/10 3:25p erickson
131 * SWDEPRECATED-3811: add more info to NEXUS_DisplayModule_Print
132 *
133 * 87   8/26/10 2:22p erickson
134 * SWDEPRECATED-3811: add NEXUS_DisplayModule_Print
135 *
136 * 86   8/19/10 11:37a petlee
137 * SW35230-760: Add new flag for disabling FRC upon VDC_Open
138 *
139 * 85   8/16/10 1:53p erickson
140 * SWNOOS-419: Fixed GHS compiler error.
141 *
142 * 84   8/13/10 1:44p petlee
143 * SW35230-1001: Integrate new backlight dimming feature from VDC
144 *
145 * 83   7/19/10 10:33a petlee
146 * SW35230-681: Fix logic for panel reversal
147 *
148 * 82   7/16/10 3:36p petlee
149 * SW35230-681: Integrate new panel reversal feature from VDC
150 *
151 * 81   7/6/10 10:58a erickson
152 * SW7405-4047: implement jail_xvd/vdc/xpt/rap using
153 *  BMRC_Monitor_JailByFilename
154 *
155 * 80   6/28/10 12:09p petlee
156 * SW35230-106: Add Close for anv
157 *
158 * 79   6/11/10 3:53p petlee
159 * SW35230-249: Merging to main
160 *
161 * SW35230-202/SW35230-249/6   6/9/10 3:34p petlee
162 * SW35230-249: Merge latest mainline updates.
163 *
164 * SW35230-202/SW35230-249/5   6/2/10 6:28p petlee
165 * SW35230-249: call BANV_Open with tmr
166 *
167 * SW35230-202/SW35230-249/4   6/2/10 3:54p petlee
168 * SW35230-249: Undo previous checkin
169 *
170 * SW35230-202/SW35230-249/3   6/2/10 3:20p petlee
171 * SW35230-249: BANV_Open() now requires a hanlde to timer
172 *
173 * SW35230-202/SW35230-249/2   6/1/10 11:40a petlee
174 * SW35230-249: Revert heap settings.
175 *
176 * SW35230-202/SW35230-249/1   5/30/10 8:28p petlee
177 * SW35230-249: Update heap settings for bringup. This is a temp fix .
178 *
179 * SW35230-202/1   5/21/10 6:03p petlee
180 * SW35230-202: Call
181 *  Nexus_DisplayModule_P_GetDefaultPanelOutputInitSettings() for 35230.
182 *
183 * 78   6/2/10 10:17a erickson
184 * SW3548-2962: refactor NEXUS_DisplayModule_SetConfigurationId for settop
185 *
186 * 77   5/13/10 10:37a erickson
187 * SW3548-2921: add pq_disabled=y support
188 *
189 * 76   3/26/10 2:19p erickson
190 * SW7405-3965: refactor mosaic to support hd/sd simul mode
191 *
192 * 75   3/23/10 3:25p petlee
193 * SW35230-106: Merging branch SW35230-106 to mainline
194 *
195 * SW35230-106a/1   3/1/10 2:34p petlee
196 * SW35230-106: Add Open for anv
197 *
198 * 74   1/8/10 3:16p erickson
199 * SW3556-979: add NEXUS_DisplayModuleSettings.vbi booleans to alloc
200 *  memory for CGMS-B and gemstar VBI types
201 *
202 * 73   8/19/09 10:21a erickson
203 * PR57747: add BDBG_WRN if clipBase.x or .y are non-zero
204 *
205 * 72   8/10/09 9:30a erickson
206 * PR56400: fix missing return value
207 *
208 * 71   8/10/09 8:17a gmohile
209 * PR 56400 : Merge legacy vdc support to main line
210 *
211 * 70   8/5/09 10:11a erickson
212 * PR51648: set default dacBandGapAdjust values from
213 *  BVDC_GetDefaultSettings
214 *
215 * 69   7/24/09 10:48a erickson
216 * PR51648: add NEXUS_DisplayModuleSettings.dacBandGapAdjust[]. move env
217 *  variable to Settop API shim.
218 *
219 * 68   7/22/09 11:40a erickson
220 * PR56997: separate AnalogVideoDecoder code
221 *
222 * 67   7/10/09 3:57p erickson
223 * PR56558: add NEXUS_DisplayModule_SetVideoDecoderModule to allow faster
224 *  start up time
225 *
226 * 66   6/12/09 10:50a erickson
227 * PR55967: convert NEXUS_DisplayModuleSettings heap settings to integers.
228 *  This makes them settable in the application.
229 *
230 * 65   6/8/09 7:06a erickson
231 * PR55617: rename NEXUS_P_DisplayAspectRatio_ToMagnum
232 *
233 * 64   5/28/09 11:06a erickson
234 * PR55483: give friendlier error message if NEXUS_DisplayHeapSettings is
235 *  not set
236 *
237 * 63   5/20/09 3:29p erickson
238 * PR54880: keep track of whether VDC heaps were created and only destroy
239 *  what was created
240 *
241 * 62   5/20/09 11:29a erickson
242 * PR55292: call NEXUS_VideoOutput_P_DestroyLink in
243 *  NEXUS_Display_RemoveOutput
244 *
245 * 61   5/19/09 10:59a erickson
246 * PR54880: fix heap handling. don't assume VideoDecoder will return NULL
247 *  heap for default.
248 *
249 * 60   3/30/09 12:53p erickson
250 * PR53453: set vbi module defaults using vbi pi
251 *
252 * 59   3/27/09 10:31a erickson
253 * PR48963: add heap and pipHeap to NEXUS_DisplayModuleSettings. allows
254 *  for more platform configurability.
255 *
256 * 58   3/13/09 10:54a erickson
257 * PR52722: improve error message on bad heap settings
258 *
259 * 57   3/6/09 7:37p jgarrett
260 * PR 52722: Handling heap size properly
261 *
262 * 56   3/2/09 6:10p jgarrett
263 * PR 52520: Moving scaler settings to common functions for VDB support
264 *
265 * 55   2/26/09 12:45p katrep
266 * PR48984: Use of string.h cause problems in the kernelmode
267 *
268 * 54   2/25/09 7:15p nickh
269 * PR52525: Implement SW workaround for 7420 3D graphics demos
270 *
271 * 53   2/23/09 6:40p jgarrett
272 * PR 48984: Adding no_vdb env variable
273 *
274 * 52   2/23/09 10:08a jgarrett
275 * PR 52266: Adding memory requirements interface
276 *
277 * 52   2/23/09 10:04a jgarrett
278 * PR 52266: Adding memory requirements interface
279 *
280 * 52   2/20/09 4:49p jgarrett
281 * PR 52266: Adding memory requirements interface
282 *
283 * 51   2/19/09 12:29p mward
284 * PR48984: Compiler warning about unused pEnv.
285 *
286 * 50   2/13/09 11:40a rgreen
287 * PR51991: Add support to modify LVDS_CHx_DATA_N_CFG
288 *
289 * PR51991/1   2/13/09 10:47a rgreen
290 * PR51991: Add support to modify LVDS_CHx_DATA_N_CFG
291 *
292 * 49   2/12/09 5:34p jgarrett
293 * PR 51958: Adding vecSwap option
294 *
295 * 48   2/12/09 4:06p jgarrett
296 * PR 48984: Disabling dynamic RTS for kylin (temporary workaround)
297 *
298 * 47   2/10/09 11:47a jgarrett
299 * PR 48984: Incorporating comments from vdb review
300 *
301 * 46   1/29/09 10:30a erickson
302 * PR51648: added DACx_BAND_GAP environment variable for internal testing
303 *
304 * 45   1/26/09 11:07a erickson
305 * PR51468: global variable naming convention
306 *
307 * 44   1/14/09 2:57p erickson
308 * PR51114: must do error checking of pixel and video format conversions
309 *
310 * 43   1/6/09 11:32a jgarrett
311 * PR 48984: Merge dynamic RTS code to main branch
312 *
313 * 42   12/18/08 3:23p erickson
314 * PR50501: fix DTV
315 *
316 * 41   12/17/08 11:40p erickson
317 * PR50501: refactor HdmiOutput to remove double BVDC_ApplyChanges and 400
318 *  msec wait on format change
319 *
320 * PR48984/3   12/5/08 4:23p jgarrett
321 * PR 48984: Updating to latest baseline
322 *
323 * 40   12/3/08 3:48p nickh
324 * PR48963: Add support for 7420 main window allocation from heap1 on
325 *  MEMC1
326 *
327 * PR48984/2   11/20/08 7:00p jgarrett
328 * PR 48984: Adding check in apply changes for window layout
329 *
330 * PR48984/1   11/20/08 6:47p jgarrett
331 * PR 48984: Adding VDB support
332 *
333 * 39   11/4/08 12:38p erickson
334 * PR47030: add NEXUS_Display_P_DestroyHeap, refactor so that all VDC
335 *  Sources are created by NEXUS_VideoInput_P_CreateLink
336 *
337 * 38   10/31/08 12:00p erickson
338 * PR47030: readd additionalLines
339 *
340 * 37   10/30/08 9:06p erickson
341 * PR47030: added DBG
342 *
343 * 36   10/30/08 8:55p erickson
344 * PR47030: manage VDC heap
345 *
346 * 35   10/17/08 3:23p erickson
347 * PR47030: impl shared analog/digital heap
348 *
349 * 34   10/16/08 12:39p jtna
350 * PR47892: Added GemStar encoding interface
351 *
352 * 33   10/8/08 12:05a erickson
353 * PR45121: set default panel.customLinkSettings
354 *
355 * 32   9/26/08 5:00p katrep
356 * PR47370: hdbuffer format should be NEXUS_VideoFormat_e1080i
357 *
358 * 31   9/22/08 9:54a erickson
359 * PR46063: set default lvds color mode
360 *
361 * 30   9/12/08 9:14a erickson
362 * PR46824: added NEXUS_DisplayModuleSettings.vbi.tteShiftDirMsb2Lsb
363 *
364 * 29   9/3/08 10:24a erickson
365 * PR46457: restore DTV functionaltiy
366 *
367 * 28   9/2/08 7:48p katrep
368 * PR46457: Configure nexus features at the run time based on board strap
369 *  options
370 *
371 * 27   8/22/08 10:07p erickson
372 * PR45795: increase # of HD buffers for 3548 failure
373 *
374 * 26   8/22/08 7:32p erickson
375 * PR45795: additional fixes
376 *
377 * 25   8/22/08 7:06p erickson
378 * PR45795: replace enum with 2HD/HD/SD buffer settings. this allows user
379 *  to fully configure VDC memory allocation.
380 *
381 * 24   8/7/08 5:56p jrubio
382 * PR45387: make sure we can reduce 7325/7335 to SD Display
383 *
384 * 23   8/4/08 2:31p erickson
385 * PR45271: keep track of AnalogVideoDecoder opens. prevent duplicates.
386 *  auto-close when DisplayModule closes.
387 *
388 * 22   7/30/08 11:54a erickson
389 * PR44919: cleaned up VDC buffer count logic for 740x, added SD only
390 *  display option support
391 *
392 * 21   7/17/08 4:18p erickson
393 * PR44919: remove B_HAS_LEGACY_VDC code, if NEXUS_NUM_DISPLAYS == 1,
394 *  allocated fewer picture buffers
395 *
396 * 20   7/16/08 11:20a erickson
397 * PR44853: clean up -Wstrict-prototypes warnings
398 *
399 * 19   7/10/08 4:46p erickson
400 * PR44598: added LVD link settings to NEXUS_DisplayModuleSettings.panel
401 *
402 * 18   7/7/08 2:40p erickson
403 * PR44619: prevent duplicate NEXUS_PanelOutput_Open calls
404 *
405 * 17   7/3/08 4:22p erickson
406 * PR44452: NEXUS_Display_Close on the last display should bring the
407 *  display module to a clean state. This makes implicit close for a
408 *  kernel mode driver possible.
409 *
410 * 16   7/1/08 5:03p erickson
411 * PR44391: Add RUL Log Capability to Help VDC Debug
412 *
413 * 15   6/23/08 5:15p vsilyaev
414 * PR 40921: Fixed ADC mapping for scart
415 *
416 * 14   6/23/08 7:19a erickson
417 * PR43914: move BLVD_Open before BVDC_Open
418 *
419 * 13   5/12/08 4:09p erickson
420 * PR42628: free NEXUS_VideoOutput_P_Link when DisplayModule closes
421 *
422 * 12   5/5/08 4:48p erickson
423 * PR42445: provide API's for better display frame rate control
424 *
425 * 11   5/1/08 3:27p jrubio
426 * PR42353: add 7335 support
427 *
428 * 10   4/8/08 3:18p erickson
429 * PR39453: add 3548 & 3556
430 *
431 * 9   4/8/08 1:53p erickson
432 * PR39453: add 3548 & 3556
433 *
434 * 8   4/3/08 10:17a erickson
435 * PR41122: move picture quality code to 7400
436 *
437 * 7   3/27/08 6:20p vsilyaev
438 * PR 40818: Added management of VDC heaps
439 *
440 * 6   3/27/08 2:29p erickson
441 * PR40928: implicit NEXUS_Display_Close with WRN
442 *
443 * 5   3/26/08 1:20p vsilyaev
444 * PR 40862: Fixed support for 1080p formats
445 *
446 * 4   3/4/08 4:36p jrubio
447 * PR40169: adding 7325
448 *
449 * 3   3/3/08 11:27a erickson
450 * PR40168: add BBS VideoTool backdoor to VDC
451 *
452 * 2   2/1/08 5:25p jgarrett
453 * PR 39017: Adding HdmiOutput
454 *
455 * 1   1/18/08 2:20p jgarrett
456 * PR 38808: Merging to main branch
457 *
458 **************************************************************************/
459#include "nexus_base.h"
460#include "nexus_display_module.h"
461#include "priv/nexus_core.h"
462#include "bkni.h"
463
464BDBG_MODULE(nexus_display_module);
465
466NEXUS_ModuleHandle g_NEXUS_displayModuleHandle = NULL;
467NEXUS_DisplayModule_State g_NEXUS_DisplayModule_State;
468
469void
470NEXUS_DisplayModule_GetDefaultSettings(NEXUS_DisplayModuleSettings *pSettings)
471{
472    BVDC_Settings vdcCfg;
473    BVBI_Settings vbiCfg;
474    unsigned i;
475
476    BDBG_ASSERT(pSettings);
477    BKNI_Memset(pSettings, 0, sizeof(*pSettings));
478
479    BVDC_GetDefaultSettings(&vdcCfg);
480    pSettings->vecSwap = vdcCfg.bVecSwap;
481    pSettings->dropFrame = true; /* without a video source, nexus graphics should default to 59.94/29.97/23.976 (i.e. drop frame) */
482
483    BDBG_CASSERT(BVDC_MAX_DACS == NEXUS_MAX_VIDEO_DACS);
484    for (i=0;i<NEXUS_MAX_VIDEO_DACS;i++) {
485        pSettings->dacBandGapAdjust[i] = vdcCfg.aulDacBandGapAdjust[i];
486    }
487
488    BVBI_GetDefaultSettings(&vbiCfg);
489    pSettings->vbi.tteShiftDirMsb2Lsb = vbiCfg.tteShiftDirMsb2Lsb;
490    pSettings->vbi.ccir656InputBufferSize = vbiCfg.in656bufferSize;
491
492#if NEXUS_HAS_DYNAMIC_RTS
493    {
494        const char *pEnv;
495    if ( NULL == NEXUS_GetEnv("no_dynamic_rts") )
496    {
497        pSettings->handleDynamicRts = true;     /* Expect dynamic RTS by default */
498    }
499    pEnv = NEXUS_GetEnv("bvn_usage");
500    if ( pEnv )
501    {
502        if ( !BKNI_Memcmp((const void*)pEnv, (const void*)"config", 6) )
503        {
504            pSettings->configurationId = NEXUS_atoi(pEnv+6);
505            BDBG_WRN(("Using BVN Configuration ID %u", pSettings->configurationId));
506        }
507    }
508    else
509    {
510        pEnv = NEXUS_GetEnv("bvn_config");
511        if ( pEnv )
512        {
513            pSettings->configurationId = NEXUS_atoi(pEnv);
514            BDBG_WRN(("Using BVN Configuration ID %u", pSettings->configurationId));
515        }
516    }
517    }
518#endif
519
520    /* default formats are based on typical usage. if you require a different use, please modify this in your platform or application. */
521    pSettings->primaryDisplayHeapIndex = 0;
522    pSettings->fullHdBuffers.format = NEXUS_VideoFormat_e1080p30hz;
523    pSettings->fullHdBuffers.pixelFormat = NEXUS_PixelFormat_eY18_Cb8_Y08_Cr8;
524    pSettings->hdBuffers.format = NEXUS_VideoFormat_e1080i;
525    pSettings->hdBuffers.pixelFormat = NEXUS_PixelFormat_eY18_Cb8_Y08_Cr8;
526    pSettings->sdBuffers.format = NEXUS_VideoFormat_ePalG;
527    pSettings->sdBuffers.pixelFormat = NEXUS_PixelFormat_eY18_Cb8_Y08_Cr8;
528
529    for(i=0;i<NEXUS_MAX_HEAPS;i++ )
530    {
531      pSettings->displayHeapSettings[i].fullHdBuffers.format = NEXUS_VideoFormat_e1080p30hz;
532      pSettings->displayHeapSettings[i].fullHdBuffers.pixelFormat = NEXUS_PixelFormat_eY18_Cb8_Y08_Cr8;
533      pSettings->displayHeapSettings[i].hdBuffers.format = NEXUS_VideoFormat_e1080i;
534      pSettings->displayHeapSettings[i].hdBuffers.pixelFormat = NEXUS_PixelFormat_eY18_Cb8_Y08_Cr8;
535      pSettings->displayHeapSettings[i].sdBuffers.format = NEXUS_VideoFormat_ePalG;
536      pSettings->displayHeapSettings[i].sdBuffers.pixelFormat = NEXUS_PixelFormat_eY18_Cb8_Y08_Cr8;
537    }
538
539    return;
540}
541
542static const struct {
543    BFMT_AspectRatio maspectRatio;
544    NEXUS_DisplayAspectRatio naspectRatio;
545} b_aspectRatio[] = {
546  {BFMT_AspectRatio_e4_3, NEXUS_DisplayAspectRatio_e4x3},
547  {BFMT_AspectRatio_e16_9, NEXUS_DisplayAspectRatio_e16x9},
548  {BFMT_AspectRatio_eSAR, NEXUS_DisplayAspectRatio_eSar}
549};
550
551BERR_Code
552NEXUS_P_DisplayAspectRatio_ToMagnum(NEXUS_DisplayAspectRatio aspectRatio, BFMT_AspectRatio *maspectRatio)
553{
554    unsigned i;
555    for(i=0;i<sizeof(b_aspectRatio)/sizeof(*b_aspectRatio);i++) {
556        if (aspectRatio==b_aspectRatio[i].naspectRatio) {
557            *maspectRatio = b_aspectRatio[i].maspectRatio;
558            return BERR_SUCCESS;
559        }
560    }
561    return BERR_TRACE(BERR_INVALID_PARAMETER);
562}
563
564bool
565NEXUS_P_Display_RectEqual(const NEXUS_Rect *r1,  const NEXUS_Rect *r2)
566{
567    BDBG_ASSERT(r1);
568    BDBG_ASSERT(r2);
569    return r1->x == r2->x && r1->width == r2->width && r1->y == r2->y && r1->height == r2->height;
570}
571
572static const NEXUS_Rect NEXUS_P_EmptyRect = {0,0,0,0};
573
574NEXUS_Error NEXUS_Display_P_GetScalerRect(const NEXUS_VideoWindowSettings *pSettings, NEXUS_Rect *pRect)
575{
576    /* if the user set clipBase.x and .y, they probably don't understand the API. put out this warning so we can catch problems. */
577    if (pSettings->clipBase.x || pSettings->clipBase.y) {
578        BDBG_WRN(("clipBase.x and .y are unused but clipBase was set to %d,%d,%d,%d.", pSettings->clipBase.x, pSettings->clipBase.y, pSettings->clipBase.width, pSettings->clipBase.height));
579    }
580
581    if (NEXUS_P_Display_RectEqual(&NEXUS_P_EmptyRect, &pSettings->clipRect)) {
582        /* no clipping */
583        pRect->x = pRect->y = 0;
584        pRect->width = pSettings->position.width;
585        pRect->height = pSettings->position.height;
586    }
587    else if (pSettings->clipBase.width == 0 && pSettings->clipBase.height == 0) {
588        /* if clipBase width & height are 0, pass clipRect directly into BVDC_Window_SetScalerOutput. This avoids
589        the clipBase/clipRect transformation. for now, this is an undocumented feature until its usage can be clarified. */
590        *pRect = pSettings->clipRect;
591    }
592    else {
593        unsigned x,y, width, height;
594        if(pSettings->clipRect.x < 0 ||  pSettings->clipRect.y < 0  ||
595           pSettings->clipRect.width == 0 || pSettings->clipRect.height == 0 ||
596           pSettings->clipBase.width == 0 || pSettings->clipBase.height == 0 ||
597           pSettings->clipRect.width+pSettings->clipRect.x > pSettings->clipBase.width || pSettings->clipRect.height+pSettings->clipRect.y > pSettings->clipBase.height) {
598            pRect->x = pRect->y = 0;
599            pRect->width = pSettings->position.width;
600            pRect->height = pSettings->position.height;
601            return BERR_TRACE(BERR_INVALID_PARAMETER);
602        }
603        x = (((unsigned)pSettings->position.width)*pSettings->clipRect.x)/pSettings->clipRect.width;
604        y = (((unsigned)pSettings->position.height)*pSettings->clipRect.y)/pSettings->clipRect.height;
605        width = (((unsigned)pSettings->position.width)*pSettings->clipBase.width)/pSettings->clipRect.width;
606        height = (((unsigned)pSettings->position.height)*pSettings->clipBase.height)/pSettings->clipRect.height;
607
608        pRect->x = x;
609        pRect->y = y;
610        pRect->width = width;
611        pRect->height = height;
612    }
613
614    return NEXUS_SUCCESS;
615}
616
617#ifdef BRDC_USE_CAPTURE_BUFFER
618#include <stdio.h>
619#include "brdc_dbg.h"
620void NEXUS_Display_P_RdcReadCapture(void *data)
621{
622    BRDC_Handle rdc = (BRDC_Handle)data;
623    int total;
624    uint8_t mem[4096];
625    static FILE *file = NULL;
626    static int filesize = 0;
627    const char *filename = NEXUS_GetEnv("capture_ruls");
628
629    BDBG_ASSERT(filename);
630    if (!file) {
631        static int filecnt = 0;
632        char buf[256];
633        BKNI_Snprintf(buf, 256, "%s%d", filename, filecnt++);
634        file = fopen(buf, "w+");
635    }
636
637    do {
638        BKNI_EnterCriticalSection();
639        BRDC_DBG_ReadCapture_isr(rdc, mem, 4096, &total);
640        BKNI_LeaveCriticalSection();
641        if (total) {
642            fwrite(mem, total, 1, file);
643            filesize += total;
644        }
645   } while (total);
646
647   if (filesize >= 100*1024*1024) {
648       fclose(file);
649       file = NULL;
650       filesize = 0;
651       /* on the next write, a new file will be opened. */
652   }
653
654    NEXUS_ScheduleTimer(1000, NEXUS_Display_P_RdcReadCapture, rdc);
655}
656#endif
657
658void NEXUS_DisplayModule_Print(void)
659{
660    #if BDBG_DEBUG_BUILD
661    unsigned i;
662    NEXUS_VideoInput_P_Link *input;
663
664    BDBG_MSG(("DisplayModule:"));
665    for (i=0;i<NEXUS_NUM_DISPLAYS;i++) {
666        unsigned j;
667        NEXUS_VideoOutput_P_Link *output;
668        NEXUS_DisplayHandle display = g_NEXUS_DisplayModule_State.displays[i];
669        if (!display) continue;
670
671        BDBG_MSG(("display %d: format=%d", i, display->cfg.format));
672        BDBG_MSG(("  graphics: vdcWindow=%p fb=%p %dx%d pixelFormat=%d", display->graphics.windowVdc, display->graphics.frameBuffer3D.main,
673            display->graphics.frameBufferWidth, display->graphics.frameBufferHeight, display->graphics.frameBufferPixelFormat));
674
675        for (j=0;j<NEXUS_NUM_VIDEO_WINDOWS;j++) {
676            NEXUS_VideoWindowHandle window = &display->windows[j];
677            if (!window->open) continue;
678            BDBG_MSG(("  window %d: visible=%d, position=%d,%d,%d,%d, NEXUS_VideoInput=%p",
679                window->windowId,
680                window->cfg.visible,
681                window->cfg.position.x, window->cfg.position.y, window->cfg.position.width, window->cfg.position.height,
682                window->input));
683        }
684
685        for (output=BLST_D_FIRST(&display->outputs);output;output=BLST_D_NEXT(output, link)) {
686            /* TODO: add type & index for debug*/
687            BDBG_MSG(("  output %p", output));
688        }
689    }
690
691    for (input=BLST_S_FIRST(&g_NEXUS_DisplayModule_State.inputs);input;input=BLST_S_NEXT(input, link)) {
692        static const char *g_BAVC_SourceId_str[] = {
693            "BAVC_SourceId_eMpeg0",
694            "BAVC_SourceId_eMpeg1",
695            "BAVC_SourceId_eVdec0",
696            "BAVC_SourceId_eVdec1",
697            "BAVC_SourceId_e656In0",
698            "BAVC_SourceId_e656In1",
699            "BAVC_SourceId_eGfx0",
700            "BAVC_SourceId_eGfx1",
701            "BAVC_SourceId_eGfx2",
702            "BAVC_SourceId_eGfx3",
703            "BAVC_SourceId_eHdDvi0",
704            "BAVC_SourceId_eHdDvi1",
705            "BAVC_SourceId_eDs0"
706        };
707        static const char *g_NEXUS_VideoInputResumeMode_str[] = {
708            "NEXUS_VideoInputResumeMode_eAuto", "NEXUS_VideoInputResumeMode_eManual", "NEXUS_VideoInputResumeMode_eNow", "NEXUS_VideoInputResumeMode_eFreezeRts" };
709
710        BDBG_MSG(("NEXUS_VideoInput %p: link=%p, %s, ref_cnt=%d",
711            input->input, input, g_BAVC_SourceId_str[input->id], input->ref_cnt));
712        BDBG_MSG(("      %s, in source_pending? %c",
713            g_NEXUS_VideoInputResumeMode_str[input->resumeMode], input->status.sourcePending?'y':'n'));
714    }
715    #endif
716
717}
718
719NEXUS_ModuleHandle
720NEXUS_DisplayModule_Init(const NEXUS_DisplayModuleSettings *pSettings)
721{
722    NEXUS_ModuleSettings moduleSettings;
723    BERR_Code rc;
724    BVDC_Settings vdcCfg;
725    NEXUS_DisplayModule_State *state = &g_NEXUS_DisplayModule_State;
726#ifndef B_HAS_LEGACY_VDC
727    BPXL_Format mPixelFormat;
728#endif
729    BFMT_VideoFmt mVideoFormat;
730    unsigned i;
731
732    if(!pSettings) {
733        rc = BERR_TRACE(BERR_INVALID_PARAMETER);
734        goto err_settings;
735    }
736
737    if ( pSettings->handleDynamicRts && pSettings->configurationId == 0 )
738    {
739        BDBG_ERR(("Configuration ID not specified for dynamic RTS."));
740        BDBG_ERR(("Export bvn_usage=configN where N=1 for WXGA, 2 for Full-HD, etc."));
741        BDBG_ERR(("Please see the usage modes spreadsheet for more information."));
742        BDBG_ASSERT(pSettings->configurationId != 0);
743        goto err_settings;
744    }
745
746    BKNI_Memset(state->vdcHeapMap, 0, sizeof(state->vdcHeapMap));
747    state->moduleSettings = *pSettings;
748    state->pqDisabled = (bool)NEXUS_GetEnv("pq_disabled");
749
750    if (pSettings->modules.surface == NULL) {
751        rc = BERR_TRACE(BERR_INVALID_PARAMETER);
752        goto err_settings;
753    }
754#if NEXUS_NUM_HDMI_INPUTS
755    if (pSettings->modules.hdmiInput == NULL) {
756        rc = BERR_TRACE(BERR_INVALID_PARAMETER);
757        goto err_settings;
758    }
759#endif
760    if (pSettings->modules.transport == NULL) {
761        rc = BERR_TRACE(BERR_INVALID_PARAMETER);
762        goto err_settings;
763    }
764
765    NEXUS_Module_GetDefaultSettings(&moduleSettings);
766    /* default priority */
767    moduleSettings.dbgPrint = NEXUS_DisplayModule_Print;
768    moduleSettings.dbgModules = "nexus_display_module";
769    g_NEXUS_displayModuleHandle = NEXUS_Module_Create("display", &moduleSettings);
770    if(!g_NEXUS_displayModuleHandle) { rc = BERR_TRACE(BERR_OS_ERROR); goto err_module; }
771
772    if (pSettings->modules.videoDecoder) {
773        NEXUS_UseModule(pSettings->modules.videoDecoder);
774    }
775    NEXUS_UseModule(pSettings->modules.surface);
776#if NEXUS_NUM_HDMI_INPUTS
777    NEXUS_UseModule(pSettings->modules.hdmiInput);
778#endif
779#if NEXUS_NUM_HDMI_OUTPUTS
780    NEXUS_UseModule(pSettings->modules.hdmiOutput);
781#endif
782#if NEXUS_NUM_HDMI_DVO
783    NEXUS_UseModule(pSettings->modules.hdmiDvo);
784#endif
785    NEXUS_UseModule(pSettings->modules.transport);
786    BLST_S_INIT(&state->inputs);
787    state->updateMode = NEXUS_DisplayUpdateMode_eAuto;
788    state->lastUpdateFailed = false;
789    state->modules = pSettings->modules;
790    for(i=0;i<sizeof(state->displays)/sizeof(state->displays[0]);i++) {
791        state->displays[i] = NULL;
792    }
793
794    /* get heap settings from NEXUS_DisplayModuleSettings and apply to individual nexus heaps */
795    for (i=0;i<NEXUS_MAX_HEAPS;i++) {
796        NEXUS_HeapHandle heap = g_pCoreHandles->nexusHeap[i];
797        if (heap) {
798            NEXUS_Heap_SetDisplayHeapSettings(heap, &pSettings->displayHeapSettings[i]);
799        }
800    }
801
802    rc = BRDC_Open(&state->rdc, g_pCoreHandles->chp, g_pCoreHandles->reg, g_pCoreHandles->heap[0], NULL);
803    if(rc!=BERR_SUCCESS) { rc = BERR_TRACE(rc); goto err_rdc; }
804
805#ifdef BRDC_USE_CAPTURE_BUFFER
806    if (NEXUS_GetEnv("capture_ruls")) {
807        NEXUS_ScheduleTimer(1000, NEXUS_Display_P_RdcReadCapture, state->rdc);
808    }
809#endif
810
811    /* open VDC */
812    BVDC_GetDefaultSettings(&vdcCfg);
813
814#if (BCHP_CHIP == 35230 || BCHP_CHIP == 35125 || BCHP_CHIP == 35121 || BCHP_CHIP == 35330)
815    /* In DTV chips, VDC modules need information about global features of the RTS
816     * configuration which is currently being used. To allow this VDB must be
817     * initalize prior to VDC open so that each VDC module can correctly get
818     * configured in VDC Open based on the features that the current RTS
819     * supports */
820    rc = NEXUS_Vdb_P_Init();
821    if ( rc )
822    {
823        (void) BERR_TRACE(rc);
824        goto err_vdb;
825    }
826
827    rc = NEXUS_vdb_P_GetRtsConfigFeatures(&vdcCfg.stRtsConfigFeatures);
828    if ( rc )
829    {
830        (void) BERR_TRACE(rc);
831        goto err_vdb;
832    }
833#endif
834
835    vdcCfg.bVecSwap = pSettings->vecSwap;
836
837#ifdef B_HAS_LEGACY_VDC
838    (void)NEXUS_P_VideoFormat_ToMagnum(pSettings->fullHdBuffers.format, &mVideoFormat);
839    vdcCfg.ulBufferCnt_2HD = pSettings->fullHdBuffers.count;
840    vdcCfg.ulBufferCnt_2HD_Pip = pSettings->fullHdBuffers.pipCount;
841    vdcCfg.eBufferFormat_2HD = mVideoFormat;
842    vdcCfg.ulAdditionalLines_2HD = pSettings->fullHdBuffers.additionalLines;
843
844    (void)NEXUS_P_VideoFormat_ToMagnum(pSettings->hdBuffers.format, &mVideoFormat);
845    vdcCfg.ulBufferCnt_HD = pSettings->hdBuffers.count;
846    vdcCfg.ulBufferCnt_HD_Pip = pSettings->hdBuffers.pipCount;
847    vdcCfg.eBufferFormat_HD = mVideoFormat;
848    vdcCfg.ulAdditionalLines_HD = pSettings->hdBuffers.additionalLines;
849
850    /* set default format based on hdBuffer format */
851    vdcCfg.eVideoFormat = mVideoFormat;
852
853    (void)NEXUS_P_VideoFormat_ToMagnum(pSettings->sdBuffers.format, &mVideoFormat);
854    vdcCfg.ulBufferCnt_SD = pSettings->sdBuffers.count;
855    vdcCfg.ulBufferCnt_SD_Pip = pSettings->sdBuffers.pipCount;
856    vdcCfg.eBufferFormat_SD = mVideoFormat;
857    vdcCfg.ulAdditionalLines_SD = pSettings->sdBuffers.additionalLines;
858
859    BDBG_MSG(("Creating main VDC heap: SD %u, HD %u, 2HD %u", vdcCfg.ulBufferCnt_SD, vdcCfg.ulBufferCnt_HD, vdcCfg.ulBufferCnt_2HD));
860#else
861    /*
862     * For platforms with single VDC heap,check for the  HD and SD buffers count.
863     * If all the buffer counts are zero, then the platform uses multiple VDC heaps.
864     */
865    if(pSettings->fullHdBuffers.count || pSettings->hdBuffers.count || pSettings->sdBuffers.count ||
866       pSettings->fullHdBuffers.pipCount || pSettings->hdBuffers.pipCount || pSettings->sdBuffers.pipCount){
867        (void)NEXUS_P_PixelFormat_ToMagnum(pSettings->fullHdBuffers.pixelFormat, &mPixelFormat);
868        (void)NEXUS_P_VideoFormat_ToMagnum(pSettings->fullHdBuffers.format, &mVideoFormat);
869        vdcCfg.stHeapSettings.ulBufferCnt_2HD = pSettings->fullHdBuffers.count;
870        vdcCfg.stHeapSettings.ulBufferCnt_2HD_Pip = pSettings->fullHdBuffers.pipCount;
871        vdcCfg.stHeapSettings.ePixelFormat_2HD = mPixelFormat;
872        vdcCfg.stHeapSettings.eBufferFormat_2HD = mVideoFormat;
873        vdcCfg.stHeapSettings.ulAdditionalLines_2HD = pSettings->fullHdBuffers.additionalLines;
874
875        (void)NEXUS_P_PixelFormat_ToMagnum(pSettings->hdBuffers.pixelFormat, &mPixelFormat);
876        (void)NEXUS_P_VideoFormat_ToMagnum(pSettings->hdBuffers.format, &mVideoFormat);
877        vdcCfg.stHeapSettings.ulBufferCnt_HD = pSettings->hdBuffers.count;
878        vdcCfg.stHeapSettings.ulBufferCnt_HD_Pip = pSettings->hdBuffers.pipCount;
879        vdcCfg.stHeapSettings.ePixelFormat_HD = mPixelFormat;
880        vdcCfg.stHeapSettings.eBufferFormat_HD = mVideoFormat;
881        vdcCfg.stHeapSettings.ulAdditionalLines_HD = pSettings->hdBuffers.additionalLines;
882
883        /* set default format based on hdBuffer format */
884        vdcCfg.eVideoFormat = mVideoFormat;
885
886        (void)NEXUS_P_PixelFormat_ToMagnum(pSettings->sdBuffers.pixelFormat, &mPixelFormat);
887        (void)NEXUS_P_VideoFormat_ToMagnum(pSettings->sdBuffers.format, &mVideoFormat);
888        vdcCfg.stHeapSettings.ulBufferCnt_SD = pSettings->sdBuffers.count;
889        vdcCfg.stHeapSettings.ulBufferCnt_SD_Pip = pSettings->sdBuffers.pipCount;
890        vdcCfg.stHeapSettings.ePixelFormat_SD = mPixelFormat;
891        vdcCfg.stHeapSettings.eBufferFormat_SD = mVideoFormat;
892        vdcCfg.stHeapSettings.ulAdditionalLines_SD = pSettings->sdBuffers.additionalLines;
893    }
894    else{
895
896        unsigned j, heapIndex = pSettings->primaryDisplayHeapIndex;
897
898        for (i=0;i<NEXUS_NUM_DISPLAYS;i++) {
899            for(j=0;j<NEXUS_NUM_VIDEO_WINDOWS;j++){
900                if (pSettings->videoWindowHeapIndex[i][j] >= NEXUS_MAX_HEAPS || !g_pCoreHandles->nexusHeap[pSettings->videoWindowHeapIndex[i][j]]) {
901                    rc = BERR_TRACE(NEXUS_INVALID_PARAMETER);
902                    goto err_vdc;
903                }
904            }
905        }
906
907        (void)NEXUS_P_PixelFormat_ToMagnum(pSettings->displayHeapSettings[heapIndex].fullHdBuffers.pixelFormat, &mPixelFormat);
908        (void)NEXUS_P_VideoFormat_ToMagnum(pSettings->displayHeapSettings[heapIndex].fullHdBuffers.format, &mVideoFormat);
909        vdcCfg.stHeapSettings.ulBufferCnt_2HD = pSettings->displayHeapSettings[heapIndex].fullHdBuffers.count;
910        vdcCfg.stHeapSettings.ulBufferCnt_2HD_Pip = pSettings->displayHeapSettings[heapIndex].fullHdBuffers.pipCount;
911        vdcCfg.stHeapSettings.ePixelFormat_2HD = mPixelFormat;
912        vdcCfg.stHeapSettings.eBufferFormat_2HD = mVideoFormat;
913        vdcCfg.stHeapSettings.ulAdditionalLines_2HD = pSettings->displayHeapSettings[heapIndex].fullHdBuffers.additionalLines;
914        (void)NEXUS_P_PixelFormat_ToMagnum(pSettings->displayHeapSettings[heapIndex].hdBuffers.pixelFormat, &mPixelFormat);
915        (void)NEXUS_P_VideoFormat_ToMagnum(pSettings->displayHeapSettings[heapIndex].hdBuffers.format, &mVideoFormat);
916        vdcCfg.stHeapSettings.ulBufferCnt_HD = pSettings->displayHeapSettings[heapIndex].hdBuffers.count;
917        vdcCfg.stHeapSettings.ulBufferCnt_HD_Pip =pSettings->displayHeapSettings[heapIndex].hdBuffers.pipCount;
918        vdcCfg.stHeapSettings.ePixelFormat_HD = mPixelFormat;
919        vdcCfg.stHeapSettings.eBufferFormat_HD = mVideoFormat;
920        vdcCfg.stHeapSettings.ulAdditionalLines_HD =pSettings->displayHeapSettings[heapIndex].hdBuffers.additionalLines;
921
922        /* set default format based on hdBuffer format */
923        vdcCfg.eVideoFormat = mVideoFormat;
924
925        (void)NEXUS_P_PixelFormat_ToMagnum(pSettings->displayHeapSettings[heapIndex].sdBuffers.pixelFormat, &mPixelFormat);
926        (void)NEXUS_P_VideoFormat_ToMagnum(pSettings->displayHeapSettings[heapIndex].sdBuffers.format, &mVideoFormat);
927        vdcCfg.stHeapSettings.ulBufferCnt_SD = pSettings->displayHeapSettings[heapIndex].sdBuffers.count;
928        vdcCfg.stHeapSettings.ulBufferCnt_SD_Pip = pSettings->displayHeapSettings[heapIndex].sdBuffers.pipCount;
929        vdcCfg.stHeapSettings.ePixelFormat_SD = mPixelFormat;
930        vdcCfg.stHeapSettings.eBufferFormat_SD = mVideoFormat;
931        vdcCfg.stHeapSettings.ulAdditionalLines_SD = pSettings->displayHeapSettings[heapIndex].sdBuffers.additionalLines;
932    }
933
934
935    BDBG_MSG(("Creating main VDC heap: SD %u, HD %u, 2HD %u, SD_PIP %u, HD_PIP %u, 2HD_PIP %u ",
936              vdcCfg.stHeapSettings.ulBufferCnt_SD, vdcCfg.stHeapSettings.ulBufferCnt_HD,
937              vdcCfg.stHeapSettings.ulBufferCnt_2HD,vdcCfg.stHeapSettings.ulBufferCnt_SD_Pip,
938              vdcCfg.stHeapSettings.ulBufferCnt_HD_Pip,vdcCfg.stHeapSettings.ulBufferCnt_2HD_Pip));
939#endif
940
941    vdcCfg.eDisplayFrameRate = pSettings->dropFrame ? BAVC_FrameRateCode_e59_94 : BAVC_FrameRateCode_e60;
942
943    BDBG_CASSERT(BVDC_MAX_DACS == NEXUS_MAX_VIDEO_DACS);
944    for (i=0;i<NEXUS_MAX_VIDEO_DACS;i++) {
945        vdcCfg.aulDacBandGapAdjust[i] = pSettings->dacBandGapAdjust[i];
946    }
947
948    if (pSettings->primaryDisplayHeapIndex >= NEXUS_MAX_HEAPS || !g_pCoreHandles->nexusHeap[pSettings->primaryDisplayHeapIndex]) {
949        rc = BERR_TRACE(NEXUS_INVALID_PARAMETER);
950        goto err_vdc;
951    }
952
953    state->heap = g_pCoreHandles->nexusHeap[pSettings->primaryDisplayHeapIndex];
954
955    if ( NEXUS_GetEnv("jail_vdc") ) {
956        NEXUS_MemoryStatus memStatus;
957        (void)NEXUS_Heap_GetStatus(state->heap, &memStatus);
958        BMRC_Monitor_JailByFilename(g_pCoreHandles->memc[memStatus.memcIndex].rmm, "bvdc_");
959        BMRC_Monitor_JailUpdate(g_pCoreHandles->memc[memStatus.memcIndex].rmm);
960    }
961
962    rc = BVDC_Open(&state->vdc, g_pCoreHandles->chp, g_pCoreHandles->reg, NEXUS_Heap_GetMemHandle(state->heap), g_pCoreHandles->bint, state->rdc, g_pCoreHandles->tmr, &vdcCfg);
963    if(rc!=BERR_SUCCESS) { rc = BERR_TRACE(rc); goto err_vdc; }
964
965    NEXUS_VideoOutputs_P_Init();
966
967#if B_HAS_VBI
968    {
969        BVBIlib_List_Settings vbilistsettings;
970        BVBI_Settings vbiSettings;
971
972        BVBI_GetDefaultSettings(&vbiSettings);
973        vbiSettings.tteShiftDirMsb2Lsb = pSettings->vbi.tteShiftDirMsb2Lsb;
974        vbiSettings.in656bufferSize = pSettings->vbi.ccir656InputBufferSize;
975        BDBG_MSG(("BVBI_Open"));
976        rc = BVBI_Open(&state->vbi, g_pCoreHandles->chp, g_pCoreHandles->reg, g_pCoreHandles->heap[0], &vbiSettings);
977        if(rc!=BERR_SUCCESS) { rc = BERR_TRACE(rc); goto err_vbi; }
978
979        rc = BVBIlib_Open (&state->vbilib, state->vbi);
980        if(rc!=BERR_SUCCESS) { rc = BERR_TRACE(rc); goto err_vbilib; }
981
982        BVBIlib_List_GetDefaultSettings(&vbilistsettings);
983        vbilistsettings.bAllowTeletext = true;
984        vbilistsettings.bAllowVPS = true;
985        vbilistsettings.bAllowGemstar = pSettings->vbi.allowGemStar;
986        vbilistsettings.bAllowCgmsB = pSettings->vbi.allowCgmsB;
987        vbilistsettings.bAllowAmol = pSettings->vbi.allowAmol;
988        rc = BVBIlib_List_Create(&state->vbilist, state->vbi,
989            (NEXUS_VBI_ENCODER_QUEUE_SIZE+1)*NEXUS_NUM_DISPLAYS, /* number of entries.
990                The +1 is because of vbilib internal resource management.
991                The *NEXUS_NUM_DISPLAYS is for each BVBIlib_Encode_Create */
992            &vbilistsettings);
993        if(rc!=BERR_SUCCESS) { rc = BERR_TRACE(rc); goto err_vbilist; }
994    }
995#endif
996
997#if !(BCHP_CHIP == 35230 || BCHP_CHIP == 35125 || BCHP_CHIP == 35121 || BCHP_CHIP == 35330)
998    rc = NEXUS_Vdb_P_Init();
999    if ( rc )
1000    {
1001        (void)BERR_TRACE(rc);
1002        goto err_vdb;
1003    }
1004#endif
1005
1006#if NEXUS_NUM_MOSAIC_DECODES
1007    for (i=0;i<NEXUS_NUM_MOSAIC_DECODE_SETS;i++) {
1008        NEXUS_VIDEO_INPUT_INIT(&state->mosaicInput[i].input, NEXUS_VideoInputType_eDecoder, NULL);
1009    }
1010#endif
1011
1012    return g_NEXUS_displayModuleHandle;
1013
1014err_vdb:
1015#if B_HAS_VBI
1016    BVBIlib_List_Destroy(state->vbilist);
1017err_vbilist:
1018    BVBIlib_Close(state->vbilib);
1019err_vbilib:
1020    BVBI_Close(state->vbi);
1021err_vbi:
1022#endif
1023    BVDC_Close(state->vdc);
1024err_vdc:
1025    BRDC_Close(state->rdc);
1026err_rdc:
1027    NEXUS_Module_Destroy(g_NEXUS_displayModuleHandle);
1028err_module:
1029err_settings:
1030    return NULL;
1031}
1032
1033void NEXUS_DisplayModule_GetSettings( NEXUS_DisplayModuleSettings *pSettings )
1034{
1035    *pSettings = g_NEXUS_DisplayModule_State.moduleSettings;
1036}
1037
1038void NEXUS_DisplayModule_Uninit(void)
1039{
1040    NEXUS_DisplayModule_State *state = &g_NEXUS_DisplayModule_State;
1041    BERR_Code rc;
1042    unsigned i;
1043
1044    /* auto cleanup must run with module lock held */
1045    NEXUS_LockModule();
1046    for (i=0;i<sizeof(state->displays)/sizeof(state->displays[0]);i++) {
1047        if (state->displays[i]) {
1048            BDBG_WRN(("Implicit NEXUS_Display_Close(%d) called", i));
1049            NEXUS_Display_Close(state->displays[i]);
1050        }
1051    }
1052#if NEXUS_NUM_ANALOG_VIDEO_DECODERS
1053    NEXUS_AnalogVideoDecoder_P_AutoClose();
1054#endif
1055    NEXUS_UnlockModule();
1056
1057    /* closing all displays should destroy all inputs and outputs */
1058    BDBG_ASSERT(!BLST_S_FIRST(&state->inputs));
1059
1060#if B_HAS_VBI
1061    BVBIlib_List_Destroy(state->vbilist);
1062    BVBIlib_Close(state->vbilib);
1063    BVBI_Close(state->vbi);
1064#endif
1065
1066#if NEXUS_DISPLAY_EXTENSION_PQ_CUSTOMIZATION
1067    rc = NEXUS_CustomPq_Uninit();
1068    if (rc!=BERR_SUCCESS) { rc = BERR_TRACE(rc);}
1069#endif
1070
1071    rc=BVDC_Close(state->vdc);
1072    if (rc!=BERR_SUCCESS) { rc = BERR_TRACE(rc); }
1073    rc=BRDC_Close(state->rdc);
1074    if (rc!=BERR_SUCCESS) { rc = BERR_TRACE(rc); }
1075
1076    NEXUS_Vdb_P_Uninit();
1077
1078    for (i=0;i<MAX_VDC_HEAPS;i++) {
1079        if (state->vdcHeapMap[i].refcnt) {
1080            BDBG_ERR(("VDC heap %d not destroyed. Internal state problem.", i));
1081        }
1082    }
1083
1084    NEXUS_Module_Destroy(g_NEXUS_displayModuleHandle);
1085    return;
1086}
1087
1088NEXUS_Error NEXUS_Display_P_ApplyChanges(void)
1089{
1090    if (g_NEXUS_DisplayModule_State.updateMode==NEXUS_DisplayUpdateMode_eAuto)
1091    {
1092        BERR_Code rc;
1093        rc = NEXUS_Vdb_P_CheckLayout();
1094        if ( rc )
1095        {
1096            (void)BERR_TRACE(rc);
1097        }
1098        rc = BVDC_ApplyChanges(g_NEXUS_DisplayModule_State.vdc);
1099        if (rc) return BERR_TRACE(rc);
1100
1101#if NEXUS_NUM_HDMI_OUTPUTS
1102        if (g_NEXUS_DisplayModule_State.hdmiOutput.display) {
1103            NEXUS_VideoOutput_P_PostSetHdmiFormat();
1104        }
1105#endif
1106    }
1107    return 0;
1108}
1109
1110#ifndef B_HAS_LEGACY_VDC
1111void NEXUS_Display_P_DestroyHeap(BVDC_Heap_Handle vdcHeap)
1112{
1113    NEXUS_DisplayModule_State *state = &g_NEXUS_DisplayModule_State;
1114    unsigned i;
1115
1116    for (i=0;i<MAX_VDC_HEAPS;i++) {
1117        if (state->vdcHeapMap[i].vdcHeap == vdcHeap) {
1118            BDBG_ASSERT(state->vdcHeapMap[i].refcnt);
1119            if (--state->vdcHeapMap[i].refcnt == 0) {
1120                BVDC_Heap_Destroy(state->vdcHeapMap[i].vdcHeap);
1121                state->vdcHeapMap[i].vdcHeap = NULL;
1122                state->vdcHeapMap[i].nexusHeap = NULL;
1123            }
1124            return;
1125        }
1126    }
1127    BDBG_ERR(("Couldn't find heap"));
1128    BDBG_ASSERT(0);
1129}
1130
1131BVDC_Heap_Handle NEXUS_Display_P_CreateHeap(NEXUS_HeapHandle heap)
1132{
1133    BVDC_Settings vdcCfg;
1134    BERR_Code rc;
1135    BPXL_Format mPixelFormat;
1136    BFMT_VideoFmt mVideoFormat;
1137    NEXUS_DisplayHeapSettings displayHeapSettings;
1138    int i, openSlot = -1;
1139    NEXUS_DisplayModule_State *state = &g_NEXUS_DisplayModule_State;
1140
1141    NEXUS_Heap_GetDisplayHeapSettings(heap, &displayHeapSettings);
1142
1143    if (!displayHeapSettings.fullHdBuffers.pixelFormat &&
1144        !displayHeapSettings.hdBuffers.pixelFormat &&
1145        !displayHeapSettings.sdBuffers.pixelFormat)
1146    {
1147        BDBG_ERR(("NEXUS_DisplayHeapSettings have not been set for heap %p", heap));
1148        return NULL;
1149    }
1150
1151    for (i=0;i<MAX_VDC_HEAPS;i++) {
1152        if (state->vdcHeapMap[i].nexusHeap == heap) {
1153            BDBG_ASSERT(state->vdcHeapMap[i].vdcHeap);
1154            BDBG_ASSERT(state->vdcHeapMap[i].refcnt);
1155            BDBG_MSG(("Reusing VDC heap %d", i));
1156            state->vdcHeapMap[i].refcnt++;
1157            return state->vdcHeapMap[i].vdcHeap;
1158        }
1159        else if (openSlot == -1 && !state->vdcHeapMap[i].nexusHeap) {
1160            openSlot = i;
1161            BDBG_ASSERT(!state->vdcHeapMap[i].vdcHeap);
1162            BDBG_ASSERT(!state->vdcHeapMap[i].refcnt);
1163        }
1164    }
1165    if (openSlot == -1) {
1166        BDBG_ERR(("Increase MAX_VDC_HEAPS"));
1167        return NULL;
1168    }
1169
1170    BVDC_GetDefaultSettings(&vdcCfg);
1171
1172    rc = NEXUS_P_PixelFormat_ToMagnum(displayHeapSettings.fullHdBuffers.pixelFormat, &mPixelFormat);
1173    if (rc) {rc = BERR_TRACE(rc);goto error;}
1174    rc = NEXUS_P_VideoFormat_ToMagnum(displayHeapSettings.fullHdBuffers.format, &mVideoFormat);
1175    if (rc) {rc = BERR_TRACE(rc);goto error;}
1176    vdcCfg.stHeapSettings.ePixelFormat_2HD = mPixelFormat;
1177    vdcCfg.stHeapSettings.eBufferFormat_2HD = mVideoFormat;
1178    vdcCfg.stHeapSettings.ulBufferCnt_2HD = displayHeapSettings.fullHdBuffers.count;
1179    vdcCfg.stHeapSettings.ulBufferCnt_2HD_Pip = displayHeapSettings.fullHdBuffers.pipCount;
1180    vdcCfg.stHeapSettings.ulAdditionalLines_2HD = displayHeapSettings.fullHdBuffers.additionalLines;
1181
1182    rc = NEXUS_P_PixelFormat_ToMagnum(displayHeapSettings.hdBuffers.pixelFormat, &mPixelFormat);
1183    if (rc) {rc = BERR_TRACE(rc);goto error;}
1184    rc = NEXUS_P_VideoFormat_ToMagnum(displayHeapSettings.hdBuffers.format, &mVideoFormat);
1185    if (rc) {rc = BERR_TRACE(rc);goto error;}
1186    vdcCfg.stHeapSettings.ePixelFormat_HD = mPixelFormat;
1187    vdcCfg.stHeapSettings.eBufferFormat_HD = mVideoFormat;
1188    vdcCfg.stHeapSettings.ulBufferCnt_HD = displayHeapSettings.hdBuffers.count;
1189    vdcCfg.stHeapSettings.ulBufferCnt_HD_Pip = displayHeapSettings.hdBuffers.pipCount;
1190    vdcCfg.stHeapSettings.ulAdditionalLines_HD = displayHeapSettings.hdBuffers.additionalLines;
1191
1192    rc = NEXUS_P_PixelFormat_ToMagnum(displayHeapSettings.sdBuffers.pixelFormat, &mPixelFormat);
1193    if (rc) {rc = BERR_TRACE(rc);goto error;}
1194    rc = NEXUS_P_VideoFormat_ToMagnum(displayHeapSettings.sdBuffers.format, &mVideoFormat);
1195    if (rc) {rc = BERR_TRACE(rc);goto error;}
1196    vdcCfg.stHeapSettings.ePixelFormat_SD = mPixelFormat;
1197    vdcCfg.stHeapSettings.eBufferFormat_SD = mVideoFormat;
1198    vdcCfg.stHeapSettings.ulBufferCnt_SD = displayHeapSettings.sdBuffers.count;
1199    vdcCfg.stHeapSettings.ulBufferCnt_SD_Pip = displayHeapSettings.sdBuffers.pipCount;
1200    vdcCfg.stHeapSettings.ulAdditionalLines_SD = displayHeapSettings.sdBuffers.additionalLines;
1201
1202    BDBG_MSG(("Creating VDC heap %d: SD %u, HD %u, 2HD %u, SD_PIP %u, HD_PIP %u, 2HD_PIP %u",
1203              openSlot, vdcCfg.stHeapSettings.ulBufferCnt_SD, vdcCfg.stHeapSettings.ulBufferCnt_HD,
1204              vdcCfg.stHeapSettings.ulBufferCnt_2HD,vdcCfg.stHeapSettings.ulBufferCnt_SD_Pip,
1205              vdcCfg.stHeapSettings.ulBufferCnt_HD_Pip,vdcCfg.stHeapSettings.ulBufferCnt_2HD_Pip));
1206
1207    rc = BVDC_Heap_Create(state->vdc, &state->vdcHeapMap[openSlot].vdcHeap,
1208        NEXUS_Heap_GetMemHandle(heap), &vdcCfg.stHeapSettings);
1209    if (rc) {rc = BERR_TRACE(rc);goto error;}
1210
1211    state->vdcHeapMap[openSlot].settings = displayHeapSettings;
1212    state->vdcHeapMap[openSlot].nexusHeap = heap;
1213    state->vdcHeapMap[openSlot].refcnt = 1;
1214
1215    return state->vdcHeapMap[openSlot].vdcHeap;
1216
1217error:
1218    BDBG_ERR(("Unable to create a display heap for this operation. User must call NEXUS_Heap_SetDisplayHeapSettings with correct settings beforehand."));
1219    return NULL;
1220}
1221#endif
1222
1223/**************************
1224BBS VideoTool backdoor
1225
1226These functions provide the BBS VideoTool raw access to VDC, REG, RDC and MEM along with a mutex which protects them.
1227This is not a public API and is subject to change.
1228**************************/
1229
1230void BVideoTool_LockDisplay(void)
1231{
1232    NEXUS_Module_Lock(g_NEXUS_displayModuleHandle);
1233}
1234
1235void BVideoTool_UnlockDisplay(void)
1236{
1237    NEXUS_Module_Unlock(g_NEXUS_displayModuleHandle);
1238}
1239
1240typedef struct BVideoToolDisplayHandles {
1241    BVDC_Handle vdc;
1242    BRDC_Handle rdc;
1243    BREG_Handle reg;
1244    BMEM_Heap_Handle heap;
1245} BVideoToolDisplayHandles;
1246
1247void BVideoTool_GetDisplayHandles(BVideoToolDisplayHandles *pDisplayHandles)
1248{
1249    pDisplayHandles->vdc = g_NEXUS_DisplayModule_State.vdc;
1250    pDisplayHandles->rdc = g_NEXUS_DisplayModule_State.rdc;
1251    pDisplayHandles->reg = g_pCoreHandles->reg;
1252    pDisplayHandles->heap = g_pCoreHandles->heap[g_NEXUS_DisplayModule_State.moduleSettings.primaryDisplayHeapIndex];
1253}
1254
1255/**
1256Summary:
1257Get the settings that were used in NEXUS_DisplayModule_Init.
1258
1259Description:
1260These cannot be changed without calling NEXUS_DisplayModule_Uninit then NEXUS_DisplayModule_Init.
1261This is for informational purposes.
1262**/
1263NEXUS_Error NEXUS_DisplayModule_GetMemorySettings(
1264    unsigned configurationId,                           /* Configuration ID */
1265    uint32_t mask,                                      /* Must contain at least one window and at least one input */
1266    NEXUS_DisplayBufferTypeSettings *pFullHdBuffers,    /* [out] Full HD buffer requirements */
1267    NEXUS_DisplayBufferTypeSettings *pHdBuffers,        /* [out] HD buffer requirements */
1268    NEXUS_DisplayBufferTypeSettings *pSdBuffers,        /* [out] SD buffer requirements */
1269    unsigned *pHeapSize                                 /* [out] Heap size in bytes */
1270    )
1271{
1272    #if NEXUS_HAS_DYNAMIC_RTS
1273    return NEXUS_Vdb_P_GetMemorySettings(
1274        configurationId,
1275        mask,
1276        pFullHdBuffers,
1277        pHdBuffers,
1278        pSdBuffers,
1279        pHeapSize);
1280    #else
1281    BSTD_UNUSED(configurationId);
1282    BSTD_UNUSED(mask);
1283    BSTD_UNUSED(pFullHdBuffers);
1284    BSTD_UNUSED(pHdBuffers);
1285    BSTD_UNUSED(pSdBuffers);
1286    BSTD_UNUSED(pHeapSize);
1287    return BERR_TRACE(BERR_NOT_SUPPORTED);
1288    #endif
1289}
1290
1291void NEXUS_DisplayModule_SetVideoDecoderModule( NEXUS_ModuleHandle videoDecoder )
1292{
1293    g_NEXUS_DisplayModule_State.modules.videoDecoder = videoDecoder;
1294}
1295
1296NEXUS_Error NEXUS_DisplayModule_SetConfigurationId( unsigned configurationId )
1297{
1298    BSTD_UNUSED(configurationId);
1299    return BERR_TRACE(NEXUS_NOT_SUPPORTED);
1300}
Note: See TracBrowser for help on using the repository browser.