source: svn/trunk/newcon3bcm2_21bu/magnum/portinginterface/xpt/7552/bxpt.c

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

first commit

  • Property svn:executable set to *
File size: 110.7 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2003-2012, Broadcom Corporation
3 *     All Rights Reserved
4 *     Confidential Property of Broadcom Corporation
5 *
6 *  THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE
7 *  AGREEMENT  BETWEEN THE USER AND BROADCOM.  YOU HAVE NO RIGHT TO USE OR
8 *  EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT.
9 *
10 * $brcm_Workfile: bxpt.c $
11 * $brcm_Revision: Hydra_Software_Devel/48 $
12 * $brcm_Date: 3/8/12 3:41p $
13 *
14 * Porting interface code for the data transport core.
15 *
16 * Revision History:
17 *
18 * $brcm_Log: /magnum/portinginterface/xpt/base2/bxpt.c $
19 *
20 * Hydra_Software_Devel/48   3/8/12 3:41p gmullen
21 * SW7425-2497: Merged to Hydra
22 *
23 * Hydra_Software_Devel/SW7425-2497/2   3/8/12 3:19p gmullen
24 * SW7425-2497: Added BXPT_HAS_PIPELINE_ERROR_REPORTING around code
25 *
26 * Hydra_Software_Devel/SW7425-2497/1   3/5/12 4:30p gmullen
27 * SW7425-2497: Checks for errors in data pipeline
28 *
29 * Hydra_Software_Devel/47   2/3/12 12:01p jtna
30 * SW7425-2248: add BXPT_P_ParserClients.ToMpodRs
31 *
32 * Hydra_Software_Devel/46   12/20/11 1:29p gmullen
33 * SW7358-176: Merged to Hydra
34 *
35 * Hydra_Software_Devel/SW7358-176/1   12/20/11 1:05p gmullen
36 * SW7358-175: Added per-client control of XC and RS buffer alloc
37 *
38 * Hydra_Software_Devel/45   12/12/11 12:17p jtna
39 * SW7425-1863: release SRAM resource on BXPT_Close()
40 *
41 * Hydra_Software_Devel/44   12/2/11 12:12p jtna
42 * SW7425-1863: refactor xpt standby power management
43 *
44 * Hydra_Software_Devel/43   11/14/11 9:49a gmullen
45 * SW7231-451: Merged to Hydra
46 *
47 * Hydra_Software_Devel/SW7231-451/1   11/14/11 9:35a gmullen
48 * SW7231-451: Removed writes to START_ADDR_ regs in RAVE, added BDBG_MSGs
49 *
50 * Hydra_Software_Devel/42   11/8/11 4:02p gmullen
51 * SW7346-502: Added virtual to physical parser mapping for
52 * Get/SetParserConfig()
53 *
54 * Hydra_Software_Devel/41   10/26/11 11:41a gmullen
55 * SW7231-403: Merged to Hydra
56 *
57 * Hydra_Software_Devel/SW7231-403/1   10/26/11 11:35a gmullen
58 * SW7231-403: Original PID channel to buffer mapping interfered with
59 * subsequent mappings
60 *
61 * Hydra_Software_Devel/40   10/20/11 8:37a gmullen
62 * SW7425-1491: Added check for older MTSIF cores.
63 *
64 * Hydra_Software_Devel/39   10/19/11 8:06p gmullen
65 * SW7425-1491: Removed API.
66 *
67 * Hydra_Software_Devel/38   10/19/11 5:40p gmullen
68 * SW7425-1491: Fixed define usage.
69 *
70 * Hydra_Software_Devel/37   10/19/11 5:27p gmullen
71 * SW7425-1491: Added BXPT_P_RxMode()
72 *
73 * Hydra_Software_Devel/36   10/14/11 8:09a gmullen
74 * SW7425-1487: Fixed compile error
75 *
76 * Hydra_Software_Devel/SW7425-1487/1   10/13/11 3:57p gmullen
77 * SW7425-1487: Fixed compiler error
78 *
79 * Hydra_Software_Devel/35   10/12/11 5:26p gmullen
80 * SW7425-1487: Inverted RxClockPol for certain parts
81 *
82 * Hydra_Software_Devel/34   10/11/11 10:24a gmullen
83 * SW7425-1470: Fixed coverity issues
84 *
85 * Hydra_Software_Devel/33   10/5/11 4:25p gmullen
86 * SW7346-502: Merged to Hydra
87 *
88 * Hydra_Software_Devel/SW7346-502/1   10/5/11 4:03p gmullen
89 * SW7346-502: Added AcceptAdapt00 support
90 *
91 * Hydra_Software_Devel/32   9/30/11 3:10p gmullen
92 * SW7425-1183: Merged to Hydra
93 *
94 * Hydra_Software_Devel/SW7425-1183/1   8/30/11 9:05a gmullen
95 * SW7425-1183: Acquire the CLK216 resource when entering standby
96 *
97 * Hydra_Software_Devel/31   9/30/11 10:49a gmullen
98 * SW7552-109: Do not update CC enables when all-pass is in use; update
99 * when CC is disabled
100 *
101 * Hydra_Software_Devel/30   9/28/11 11:47a gmullen
102 * SW7425-1323: Cached RAVE settings in DRAM to reduce overhead
103 *
104 * Hydra_Software_Devel/29   9/12/11 4:36p gmullen
105 * SW7344-193: Merged changes to Hydra
106 *
107 * Hydra_Software_Devel/SW7344-193/1   9/7/11 4:34p gmullen
108 * SW7344-193: Added tri-state logic to jitter API
109 *
110 * Hydra_Software_Devel/28   9/2/11 2:41p gmullen
111 * SW7231-319: Merge workaround to Hydra branch
112 *
113 * Hydra_Software_Devel/SW7231-319/1   9/1/11 11:12a gmullen
114 * SW7231-319: Temporary workaround for incorrect SRAM addresses
115 *
116 * Hydra_Software_Devel/27   7/27/11 9:01a gmullen
117 * SW7346-338: Fixed compiler warning about unused var
118 *
119 * Hydra_Software_Devel/26   7/25/11 4:50p gmullen
120 * SW7346-338: Added compile-time check to fix Coverity warning
121 *
122 * Hydra_Software_Devel/25   7/13/11 2:49p jtna
123 * SW7231-296: added missing non-sram register range. removed comments
124 *
125 * Hydra_Software_Devel/24   7/12/11 3:52p jtna
126 * SW7231-296: initial non-sram pm work
127 *
128 * Hydra_Software_Devel/23   7/11/11 5:39p gmullen
129 * SW7346-184: BXPT_ParserAllPassMode() must check if parser is
130 * transitioning from all-pass to NON all-pass
131 *
132 * Hydra_Software_Devel/22   7/1/11 2:45p gmullen
133 * SW7231-186: Enable SRAM power management for 7231 only, for now
134 *
135 * Hydra_Software_Devel/21   6/27/11 2:39p gmullen
136 * SW7231-186: Merged power management code to Hydra branch
137 *
138 * Hydra_Software_Devel/SW7231-186/1   6/13/11 5:59p gmullen
139 * SW7231-186: Implemented SRAM save and restore for XPT standby/resume
140 *
141 * Hydra_Software_Devel/20   5/12/11 4:59p gmullen
142 * SW7231-128: Merged to mainline
143 *
144 * Hydra_Software_Devel/SW7231-128/2   5/12/11 1:24p gmohile
145 * SW7231-128 : Fix MTSIF code
146 *
147 * Hydra_Software_Devel/SW7231-128/1   5/10/11 1:40p gmohile
148 * SW7231-128 : Add power management support
149 *
150 * Hydra_Software_Devel/18   4/18/11 1:31p gmullen
151 * SW7425-313: Added PID parser mapping to other 40nm chips
152 *
153 * Hydra_Software_Devel/17   4/15/11 4:49p gmullen
154 * SW7425-313: Merged to mainline
155 *
156 * Hydra_Software_Devel/SW7425-313/2   4/15/11 4:32p gmullen
157 * SW7425-313: BXPT_GetParserMapping() did not initialize all parser
158 * mappings
159 *
160 * Hydra_Software_Devel/SW7425-313/1   4/13/11 2:05p gmullen
161 * SW7425-313: Added parser remapping support
162 *
163 * Hydra_Software_Devel/16   4/11/11 9:15a gmullen
164 * SW7346-119: Merged fix to mainline
165 *
166 * Hydra_Software_Devel/SW7346-119/1   4/7/11 3:43p gmullen
167 * SW7346-119: Disable CC checking when enabling all-pass mode. Restore
168 * when exiting all-pass
169 *
170 * Hydra_Software_Devel/15   3/28/11 12:05p jtna
171 * SW7346-119: remove error from BXPT_ParserAllPassMode
172 *
173 * Hydra_Software_Devel/14   3/23/11 5:12p gmullen
174 * SW7346-124: Do not allocate XC buffers for unused remux blocks
175 *
176 * Hydra_Software_Devel/13   3/22/11 1:42p gmullen
177 * SW7425-223: Added code to correctly map STC broadcasts
178 *
179 * Hydra_Software_Devel/12   2/17/11 4:22p gmullen
180 * SW7422-266: Clear MSB of parser input select
181 *
182 * Hydra_Software_Devel/11   2/16/11 5:21p gmullen
183 * SW7422-266: MSB for parser data source had moved
184 *
185 * Hydra_Software_Devel/10   2/15/11 8:36a gmullen
186 * SWBLURAY-23703: Incorrect iterator in BXPT_GetDefaultSettings
187 *
188 * Hydra_Software_Devel/9   1/28/11 9:34a gmullen
189 * SW7425-15: Set Pid2Buff mapping to true by default
190 *
191 * Hydra_Software_Devel/8   12/30/10 1:36p gmullen
192 * SW7425-15: Only update pacing and pause maps for playback channels
193 * involve in muxing
194 *
195 * Hydra_Software_Devel/7   12/3/10 3:20p gmullen
196 * SW7425-15: Allow setting the initial CC for generation
197 *
198 * Hydra_Software_Devel/6   11/11/10 5:28p gmullen
199 * SW7422-20: Access SUN_TOP_CTRL_SW_INIT_0_SET through BREG_Write32
200 *
201 * Hydra_Software_Devel/5   11/9/10 2:57p gmullen
202 * SW7422-20: Fixed register overwrite in BXPT_Open(). Changed RS and XC
203 * defines; buffer init was not called
204 *
205 * Hydra_Software_Devel/4   11/6/10 4:56p gmullen
206 * SW7422-20: Use atomic access for reset registers
207 *
208 * Hydra_Software_Devel/3   10/28/10 2:08p gmullen
209 * SW7422-20: Checkin ported files
210 *
211 * Hydra_Software_Devel/2   10/25/10 5:32p gmullen
212 * SW7422-20: Changed _P_MAX defines to _NUM
213 *
214 * Hydra_Software_Devel/1   10/25/10 2:09p gmullen
215 * SW7425-15: Moved srcs to base2 folder
216 *
217 * Hydra_Software_Devel/1   10/25/10 9:11a gmullen
218 * SW7425-15: Updated headers and added stub versions of C files
219 *
220 * Hydra_Software_Devel/111   8/23/10 6:04p gmullen
221 * SW7420-977: Updated SCB client mapping for usage 1 in RTS spreadsheet
222 *
223 * Hydra_Software_Devel/110   8/23/10 2:03p gmullen
224 * SW35230-2: Updated SCB assignments to match RTS spreadsheet
225 *
226 * Hydra_Software_Devel/109   8/20/10 3:01p gmullen
227 * SW35230-2: Fixed compilation error
228 *
229 * Hydra_Software_Devel/108   8/20/10 10:22a gmullen
230 * SW7403-924: Missed a register read in BXPT_P_SetPidChannelDestination()
231 *
232 * Hydra_Software_Devel/107   8/17/10 4:52p gmullen
233 * SW7403-924: Merged to Hydra_Software_Devel
234 *
235 * Hydra_Software_Devel/SW7403-924/3   8/17/10 4:42p gmullen
236 * SW7403-924: Reduce MAX_PID_CHANNELS when PSUB PID channels are not
237 * changed
238 *
239 * Hydra_Software_Devel/SW7403-924/2   8/11/10 10:53a gmullen
240 * SW7403-924: New method: change band_num in PSUB
241 *
242 * Hydra_Software_Devel/SW7403-924/1   8/9/10 9:07a gmullen
243 * SW7403-924: See the JIRA for the workaround notes
244 *
245 * Hydra_Software_Devel/106   8/5/10 3:43p gmullen
246 * SW7400-2889: Merged fix
247 *
248 * Hydra_Software_Devel/SW7400-2889/1   8/5/10 3:38p gmullen
249 * SW7400-2889: SetChannelEnable() should not disable a PID channel when
250 * playback muxing requests it be enabled
251 *
252 * Hydra_Software_Devel/105   7/8/10 2:14p gmullen
253 * SW7630-81: Fixed typo in BCHP_VER_ for 7630B2
254 *
255 * Hydra_Software_Devel/104   7/4/10 5:33p gmullen
256 * SW7630-81: Added support for QUICK
257 *
258 * Hydra_Software_Devel/103   6/5/10 10:43a gmullen
259 * SW35230-2: Workaround for ICAM support and different endian strap
260 * register
261 *
262 * Hydra_Software_Devel/102   3/25/10 3:53p gmullen
263 * SW35230-127: Updated code for requirements in this JIRA
264 *
265 * Hydra_Software_Devel/101   2/17/10 11:47a gmullen
266 * SW3548-2787: Use InputBandConfig->ParallelInputSel for arg checking
267 *
268 * Hydra_Software_Devel/100   2/16/10 5:26p gmullen
269 * SW3548-2697: SetInputBandConfig returned early for 3548/3556
270 *
271 * Hydra_Software_Devel/99   2/12/10 4:49p gmullen
272 * SW3548-2697: Return error if user tries to configure IB5 in serial mode
273 *
274 * Hydra_Software_Devel/98   2/11/10 10:46a jgarrett
275 * SW7408-71: Adding critical section around soft reset of XPT block
276 *
277 * Hydra_Software_Devel/97   1/14/10 2:57p gmullen
278 * SW3548-2697: Fixed compilation bug
279 *
280 * Hydra_Software_Devel/96   1/4/10 8:42p gmullen
281 * SW3548-2697: Return ParallelInputSel = true for parallel-only inputs.
282 *
283 * Hydra_Software_Devel/95   12/29/09 1:07p piyushg
284 * HW7408-91: Revert changes made in Rev 93. To be reviewed and
285 * enable later.
286 *
287 * Hydra_Software_Devel/94   11/30/09 10:06a gmullen
288 * SW7405-3507: Fixed timebase check in BXPT_GetParserConfig()
289 *
290 * Hydra_Software_Devel/93   11/18/09 9:27a gmullen
291 * HW7408-91: Init PCR Offset block
292 *
293 * Hydra_Software_Devel/92   11/17/09 3:07p gmullen
294 * SW7408-9: Finished adding 7408 support to XPT
295 *
296 * Hydra_Software_Devel/91   11/2/09 10:53a gmullen
297 * SW3548-2589: Use reference counting when deciding to disable PID
298 * channels
299 *
300 * Hydra_Software_Devel/90   10/30/09 3:48p ronchan
301 * SW7340-77: set 7340 input bands to parallel
302 *
303 * Hydra_Software_Devel/89   9/23/09 2:26p gmullen
304 * SW7405-2994: Merged fix to Hydra_Software_Devel
305 *
306 * Hydra_Software_Devel/88   9/22/09 4:47p gmullen
307 * SW7342-40: Changed bounds checking logic. Arg is 1-based, not 0-based.
308 *
309 * Hydra_Software_Devel/87   9/3/09 1:37p gmullen
310 * SW7125-7:Do not force parallel enabled on IB 2, 3, and 5. DS0 and DS1
311 * are serial interfaced to XPT.
312 *
313 * Hydra_Software_Devel/86   8/31/09 3:23p gmullen
314 * SW7342-32:Added BXPT_SetPidChannelSwitchedISR()
315 *
316 * Hydra_Software_Devel/85   8/19/09 12:14p piyushg
317 * PR56771: Add support for 7342. Hence the previous usage
318 * of constant PARSER_REG_STEPSIZE does not work for this chip.
319 * Added new function to calculate offset.
320 *
321 * Hydra_Software_Devel/84   8/11/09 10:38a piyushg
322 * PR55216: Added initial 7340 XPT support.
323 *
324 * Hydra_Software_Devel/83   8/5/09 4:51p piyushg
325 * PR55545: Add 7125 XPT PI support
326 * Added file element "bxpt_rave_ihex.c".
327 * Added file element "bxpt_rave_ihex.h".
328 *
329 * Hydra_Software_Devel/82   7/31/09 3:26p piyushg
330 * PR56771: Add support for 7342.
331 *
332 * Hydra_Software_Devel/81   7/31/09 2:44p gmullen
333 * PR54331: Added 35130 to XPT support.
334 *
335 * Hydra_Software_Devel/80   7/16/09 1:40p gmullen
336 * PR56110: RAVE_CX_MODE skipped during BXPT_Open for 7550. Fixed.
337 *
338 * Hydra_Software_Devel/79   7/14/09 10:20a piyushg
339 * PR56771: Add XPT PI code for 7342.
340 *
341 * Hydra_Software_Devel/78   6/18/09 11:11a gmullen
342 * PR56110: Checked for mesg support.
343 *
344 * Hydra_Software_Devel/77   6/18/09 8:07a gmullen
345 * PR56110: Fixed build errors for other chips.
346 *
347 * Hydra_Software_Devel/76   6/17/09 6:46p gmullen
348 * PR56110: Added support.xpt/7550/uif_image/a0
349 *
350 * Hydra_Software_Devel/75   6/8/09 6:04p gmullen
351 * PR55700: Added BXPT_IsDataPresent().
352 *
353 * Hydra_Software_Devel/74   6/8/09 2:13p gmullen
354 * PR55817: Duplicate PID check now considers only channels that are
355 * enabled.
356 *
357 * Hydra_Software_Devel/73   6/3/09 10:01a gmullen
358 * PR55511: Removed check for PID channel destination. Interferes with
359 * nexus playback mux support.
360 *
361 * Hydra_Software_Devel/72   4/19/09 9:28a gmullen
362 * PR53662: Added hook to determine if XPT can be powered down.
363 *
364 * Hydra_Software_Devel/71   4/7/09 5:25p piyushg
365 * PR52986: Add support for 7635
366 * Added directory element "7635".
367 *
368 * Hydra_Software_Devel/70   1/27/09 1:09p gmullen
369 * PR51625: Added 7336 support
370 *
371 * Hydra_Software_Devel/69   12/15/08 2:36p gmullen
372 * PR48908: Removed power management code from XPT PI.
373 *
374 * Hydra_Software_Devel/68   11/26/08 4:14p gmullen
375 * PR47755: Added support for 7420.
376 *
377 * Hydra_Software_Devel/67   11/6/08 11:24a gmullen
378 * PR46544: Added public PI call to incr/decr power reference count.
379 *
380 * Hydra_Software_Devel/66   10/29/08 9:11a gmullen
381 * PR46544: Fixed compile error.
382 *
383 * Hydra_Software_Devel/65   10/28/08 6:18p gmullen
384 * PR46544: Default power management to ON. Added compile-time support to
385 * disable power management.
386 *
387 * Hydra_Software_Devel/64   10/28/08 4:58p gmullen
388 * PR46544: Added power management support, default to disabled for now.
389 *
390 * Hydra_Software_Devel/63   9/22/08 2:53p gmullen
391 * PR47074: Do not disable PID channel if its used by the PCR Offset
392 * block.
393 *
394 * Hydra_Software_Devel/62   9/4/08 10:06a vishk
395 * PR 46315: Sample code for PID remapping
396 * PR 46545: Reallocation of max bitrate for all pass parser band only
397 * reallocates XC bw for rave. Rate increase for RMX1 and MSG still needs
398 * to be added.
399 *
400 * Hydra_Software_Devel/61   9/3/08 7:38p vishk
401 * PR 46315: Sample code for PID remapping
402 * PR 46545: Reallocation of max bitrate for all pass parser band only
403 * reallocates XC bw for rave. Rate increase for RMX1 and MSG still needs
404 * to be added.
405 *
406 * Hydra_Software_Devel/60   8/18/08 3:58p gmullen
407 * PR45362: Number of playback channels that support muxing should be
408 * programmable.
409 *
410 * Hydra_Software_Devel/59   8/15/08 10:48a gmullen
411 * PR45362: Removed calls to BKNI_Enter/LeaveCriticalSectionISR()
412 *
413 * Hydra_Software_Devel/58   8/8/08 5:47p gmullen
414 * PR45362: Merged SanJose_CDI_Devel changes to Hydra_Software_Devel
415 *
416 * Hydra_Software_Devel/SanJose_CDI_Devel/4   8/4/08 11:11a bhsu
417 * PR45362 : Fixed Kernel oops for AM21.
418 *
419 * Hydra_Software_Devel/57   7/16/08 3:43p gmullen
420 * PR37867: Merged playback mux code to Hydra_Software_Devel
421 *
422 * Hydra_Software_Devel/56   7/14/08 8:47p gmullen
423 * PR44803: Used atomic access to set/clear xpt reset in sundry
424 *
425 * Hydra_Software_Devel/56   7/14/08 8:44p gmullen
426 * PR44803: Used atomic update to set/clear xpt reset.
427 *
428 * Hydra_Software_Devel/55   6/20/08 1:53p gmullen
429 * PR43907: Incorrect band rate passed to XC buff PI.
430 *
431 * Hydra_Software_Devel/54   6/17/08 5:55p gmullen
432 * PR43710: Fixed parser all-pass mode.
433 *
434 * Hydra_Software_Devel/53   6/16/08 11:55a piyushg
435 * PR39234: Change some comments and API names for setting up
436 * multiple message buffers for same PID channel.
437 *
438 * Hydra_Software_Devel/52   5/15/08 3:29p gmullen
439 * PR42738: Added PSUB and MSG_WR to arbiter setup for 3563.
440 *
441 * Hydra_Software_Devel/51   5/7/08 10:47a gmullen
442 * PR42443: Removed call to change band rates when changing parser mode.
443 *
444 * Hydra_Software_Devel/50   3/26/08 11:23a gmullen
445 * PR38954: Added 3548 support to XPT PI.
446 *
447 * Hydra_Software_Devel/49   3/17/08 1:03p gmullen
448 * PR40675: Added support to route all mesg filter data on R-pipe.
449 *
450 * Hydra_Software_Devel/48   3/11/08 9:04a gmullen
451 * PR40463: Update arbiter config on BXPT_Open()
452 *
453 * Hydra_Software_Devel/47   3/7/08 4:54p gmullen
454 * PR38618: Added 7118C0 support
455 *
456 * Hydra_Software_Devel/46   3/6/08 3:47p piyushg
457 * PR39234: Initial checkin for API's to support PID Duplication.
458 *
459 * Hydra_Software_Devel/45   2/22/08 2:23p gmullen
460 * PR39816: Enabled BXPT_P_ConfigArbiter() for 7400.
461 *
462 * Hydra_Software_Devel/44   1/24/08 9:29a gmullen
463 * PR38941: Cleared IB_ERROR_INPUT_EN in BXPT_SetInputBandConfig().
464 *
465 * Hydra_Software_Devel/43   12/21/07 10:53a agin
466 * PR37975: Set proper input bands for BCM7335 ) || ( BCHP_CHIP == 7336 .
467 *
468 * Hydra_Software_Devel/42   12/19/07 9:01a gmullen
469 * PR38274: Updated PI for final version of D0 RDB.
470 *
471 * Hydra_Software_Devel/41   12/5/07 10:56p agin
472 * PR37869: 7325 band 2 set to parallel only.
473 *
474 * Hydra_Software_Devel/SanJose_CDI_Devel/2   12/17/07 6:27p shuang
475 * PR37867:Merge Jethead patch in order to support DirecTV AM21 project
476 * which ATSC data will input through USB interface.
477 * Merge Magnum Phase 7.0.
478 *
479 * Hydra_Software_Devel/40   11/28/07 10:33a gmullen
480 * PR36900: Added 7335 support.
481 *
482 * Hydra_Software_Devel/39   10/30/07 3:11p gmullen
483 * PR35018: Added support for 7325
484 *
485 * Hydra_Software_Devel/38   9/28/07 11:16a gmullen
486 * PR35427: Added BXPT_GetDefaultParserConfig() and
487 * BXPT_GetDefaultInputBandConfig()
488 *
489 * Hydra_Software_Devel/37   9/13/07 1:36p gmullen
490 * PR32868: Changes to support bmsglib
491 *
492 * Hydra_Software_Devel/36   8/1/07 4:50p gmullen
493 * PR33710: Custom arbiter setup for 7440.
494 *
495 * Hydra_Software_Devel/35   7/31/07 9:05a gmullen
496 * PR33639: Disabled PID channel version checking
497 *
498 * Hydra_Software_Devel/34   7/24/07 11:59a gmullen
499 * PR33366: Do not write identical config to a PID channel register.
500 *
501 * Hydra_Software_Devel/33   7/9/07 3:42p gmullen
502 * PR27642: Updated for new RDB names of xmemif arbiters.
503 *
504 * Hydra_Software_Devel/32   5/17/07 2:17p gmullen
505 * PR30877: Added support for dedicated playback heap handle.
506 *
507 * Hydra_Software_Devel/31   5/16/07 4:30p gmullen
508 * PR30726: Fixed compiler warning.
509 *
510 * Hydra_Software_Devel/30   5/16/07 9:38a gmullen
511 * PR30726: BXPT_P_SetPidChannelDestination should increase XC rate only
512 * when both R and G pipes are enabled.
513 *
514 * Hydra_Software_Devel/29   2/14/07 1:09p gmullen
515 * PR27642: Added support for 7405.
516 *
517 * Hydra_Software_Devel/28   1/16/07 5:39p gmullen
518 * PR26109: Removed arbiter workaround.
519 *
520 * Hydra_Software_Devel/27   1/9/07 4:38p gmullen
521 * PR26109: Workaround for arbiter issue
522 *
523 * Hydra_Software_Devel/26   11/22/06 4:58p gmullen
524 * PR26109: Updated for 7403.
525 *
526 * Hydra_Software_Devel/25   11/17/06 5:34p gmullen
527 * PR26034: Fixed BXPT_Remux_AllocPidMap().
528 *
529 * Hydra_Software_Devel/24   11/15/06 3:22p gmullen
530 * PR15309: Added BXPT_P_EnablePidChannel.
531 *
532 * Hydra_Software_Devel/23   11/2/06 4:31p gmullen
533 * PR25402: Added support for secure heap to RS and XC buffer code.
534 *
535 * Hydra_Software_Devel/22   11/2/06 8:40a gmullen
536 * PR23189: Added 3563 support.
537 *
538 * Hydra_Software_Devel/21   10/27/06 10:31a katrep
539 * PR25024: Configure the arbiter for 7401. Remove after CFE supports
540 * this.
541 *
542 * Hydra_Software_Devel/20   9/26/06 1:33p katrep
543 * PR20624: Fixed message buffer endian issue for 7400 big endian.
544 *
545 * Hydra_Software_Devel/19   9/15/06 3:04p gmullen
546 * PR15309: Fixed compiler warnings re unused variables.
547 *
548 * Hydra_Software_Devel/18   9/1/06 10:20a gmullen
549 * PR20624: Fixed mesg buffer endian setup issue.
550 *
551 * Hydra_Software_Devel/17   8/23/06 4:26p gmullen
552 * PR23861: Check for duplicated channels on enable.
553 *
554 * Hydra_Software_Devel/16   8/17/06 6:01p katrep
555 * PR23114: Added Support for 7440 chip
556 *
557 * Hydra_Software_Devel/15   8/11/06 2:07p katrep
558 * PR23349: RS buffer valid for ony input parser bands.
559 *
560 * Hydra_Software_Devel/14   8/10/06 7:21p katrep
561 * PR23349: Increase RS/XC buffer bandwidth during All pass record and
562 * Increase XC buffer BW when Rave R and G pipe destinations are enabled.
563 *
564 * Hydra_Software_Devel/13   8/10/06 2:51p gmullen
565 * PR23189: Added defines for 3563.
566 *
567 * Hydra_Software_Devel/12   8/7/06 2:02p gmullen
568 * PR18998: BXPT_Disa
569 blePidChannel() incorrectly checked for pid channel
570 * diestination.
571 *
572 * Hydra_Software_Devel/11   7/27/06 10:58a gmullen
573 * PR15309: BXPT_ConfigurePidChannel() now checks for duplicated PID
574 * channels
575 *
576 * Hydra_Software_Devel/10   7/21/06 11:52a gmullen
577 * PR18998: Default XC buffer for mesg block was 200kb, should be 8kb.
578 *
579 * Hydra_Software_Devel/9   7/17/06 5:18p gmullen
580 * PR20624: Added code for 7118.
581 *
582 * Hydra_Software_Devel/8   7/13/06 11:37a katrep
583 * PR20316: Added support to set/unset PSI setting per pid channel basis
584 * as it's supported by new HW arch.PR20315:Also added support for 32
585 * byte filters.Default filter size is 16 bytes.32 Bytes filters can be
586 * enabled at compile time by -DBXPT_FILTER_32
587 *
588 * Hydra_Software_Devel/7   7/12/06 5:54p gmullen
589 * PR21042: XC and RS buffers can be customized to reduce total memory
590 * needs.
591 *
592 * Hydra_Software_Devel/6   6/22/06 12:59p katrep
593 * PR20999: Diabled rewrite of the PID_TABLE_i reg if PID channel is
594 * already enabled and request is to enable it again.This prevents
595 * PID_VERSION from changing.
596 *
597 * Hydra_Software_Devel/5   6/5/06 6:27p katrep
598 * PR20631: disabled endian toggling as 7401 B0 xpt configures itself to
599 * correct endianess.
600 *
601 * Hydra_Software_Devel/4   6/5/06 5:54p gmullen
602 * PR18998: Added support for control of ACCEPT_ADAPT_00 in parser regs.
603 *
604 * Hydra_Software_Devel/3   2/17/06 3:31p gmullen
605 * PR18998: Fixed memory overwrite in InitContext().
606 *
607 * Hydra_Software_Devel/2   2/14/06 11:48a gmullen
608 * PR18998: BXPT_Close() deallocated buffers for channels that didn't have
609 * them. Fixed,
610 *
611 * Hydra_Software_Devel/12   1/6/06 2:22p gmullen
612 * PR18489: Added PID destination workaround for hardware PR 18919.
613 *
614 * Hydra_Software_Devel/11   11/23/05 9:18a gmullen
615 * PR15309: More updates.
616 *
617 * Hydra_Software_Devel/10   9/21/05 2:17p gmullen
618 * PR15309: Added support for AAC HE and AC3+ audio, fixed bug in playback
619 * PI, modified RAVE PI to support channel change and reset.
620 *
621 * Hydra_Software_Devel/9   9/1/05 10:36a gmullen
622 * PR15309: Fixed compiler warnings on release builds.
623 *
624 * Hydra_Software_Devel/8   8/31/05 10:58a gmullen
625 * PR15309: Fixed bugs in PSI extraction and MPEG audio support.
626 *
627 * Hydra_Software_Devel/7   8/26/05 2:00p gmullen
628 * PR15309: Added DirecTV support, RAVE video support, cleaned up RS and
629 * XC buffer code.
630 *
631 * Hydra_Software_Devel/6   8/18/05 9:58a gmullen
632 * PR15309: Added more DirecTV support.
633 *
634 * Hydra_Software_Devel/5   8/12/05 8:57a gmullen
635 * PR15309: Added PCR, PCR Offset, DirecTV, RAVE video, and ITB/CDB
636 * endianess support. Tested same.
637 *
638 * Hydra_Software_Devel/4   8/4/05 8:14a gmullen
639 * PR15309: Added PCR support.
640 *
641 * Hydra_Software_Devel/3   7/26/05 5:48p gmullen
642 * PR15309: Fixed buffer size issue in bxpt_rave.c and added buffer
643 * shutdown code to other blocks.
644 *
645 * Hydra_Software_Devel/2   7/19/05 1:27p gmullen
646 * PR15309: Fixed buffer alloc bugs.
647 *
648 * Hydra_Software_Devel/1   7/15/05 9:03a gmullen
649 * PR15309: Inita i
650 *
651 *
652 ***************************************************************************/
653
654#include "bstd.h"
655#include "bxpt_priv.h"
656#include "bxpt.h"
657#include "bkni.h"
658#include "bint.h"
659
660#if BCHP_PWR_SUPPORT
661#include "bchp_pwr.h"
662#include "bxpt_pwr_mgmt_priv.h"
663#endif
664
665#if BXPT_HAS_FIXED_RSBUF_CONFIG
666        #include "bxpt_rsbuf_priv.h"
667#endif
668
669#if BXPT_HAS_FIXED_XCBUF_CONFIG
670        #include "bxpt_xcbuf_priv.h"
671#endif
672
673#include "bmem.h"
674#include "bxpt_rave.h"
675#include "bxpt_pcr_offset.h"
676
677#include "bchp_sun_top_ctrl.h"
678#include "bchp_xpt_fe.h"
679
680#if BXPT_HAS_MESG_BUFFERS
681    #include "bchp_xpt_msg.h"
682#endif 
683
684#if BXPT_HAS_PLAYBACK_PARSERS
685        #include "bchp_xpt_pb0.h"
686        #include "bchp_xpt_pb1.h"
687        #define PB_PARSER_REG_STEPSIZE  ( BCHP_XPT_PB1_CTRL1 - BCHP_XPT_PB0_CTRL1 )
688#endif
689
690#include "bchp_xpt_bus_if.h"
691#include "bchp_xpt_xmemif.h"
692#include "bchp_xpt_rave.h"
693
694#if BXPT_HAS_PACKETSUB
695    #include "bchp_xpt_psub.h"
696    #include "bxpt_packetsub.h"
697        #define PACKET_SUB_REGISTER_STEP        ( BCHP_XPT_PSUB_PSUB1_CTRL0 - BCHP_XPT_PSUB_PSUB0_CTRL0 )
698#endif
699
700#if BXPT_HAS_TSMUX
701    #include "bxpt_tsmux.h"
702#endif
703
704#if BXPT_HAS_REMUX
705#include "bxpt_remux.h"
706#endif
707
708/* Distance between Item X regs and Item X+1 */
709#define PID_CHNL_STEPSIZE               ( 4 )
710#define SPID_CHNL_STEPSIZE              ( 4 )
711
712/* Locally defined interrupt IDs. The RDB structure makes it impossible to generate these automatically at the moment. */
713#define BCHP_INT_ID_XPT_MSG_INTR_FLAG         BCHP_INT_ID_CREATE( BCHP_XPT_MSG_BUF_DAT_RDY_INTR_00_31, BCHP_XPT_MSG_BUF_DAT_RDY_INTR_00_31_INTR_FLAG_SHIFT )
714#define BCHP_INT_ID_XPT_MSG_OVFL_INTR_FLAG    BCHP_INT_ID_CREATE( BCHP_XPT_MSG_BUF_OVFL_INTR_00_31, BCHP_XPT_MSG_BUF_OVFL_INTR_00_31_INTR_FLAG_SHIFT )
715#define MESG_FILTER_ARRAY_ELEMENTS      ( 512 )
716
717#if BXPT_HAS_MTSIF
718#define MTSIF_STEPSIZE ( BCHP_XPT_FE_MTSIF_RX1_CTRL1 - BCHP_XPT_FE_MTSIF_RX0_CTRL1 )
719#endif
720
721#if( BDBG_DEBUG_BUILD == 1 )
722        BDBG_MODULE( xpt );
723#endif
724
725static void SetChannelEnable( BXPT_Handle hXpt, unsigned int PidChannelNum, bool EnableIt );
726static bool PidChannelHasDestination( BXPT_Handle hXpt, unsigned int PidChannelNum );
727static bool IsPidDuplicated( BXPT_Handle hXpt, unsigned int PidChannelNum );
728static void BXPT_P_ConfigArbiter(BREG_Handle hReg);             
729void BXPT_Mesg_SetPid2Buff( BXPT_Handle hXpt, bool SetPid2Buff );
730static unsigned int GetParserIndex( BXPT_Handle hXpt, unsigned ParserNum );
731
732BERR_Code BXPT_GetDefaultSettings(
733        BXPT_DefaultSettings *Defaults, /* [out] Defaults to use during init.*/
734        BCHP_Handle hChip                               /* [in] Handle to used chip. */
735        )
736{
737    unsigned ii;
738
739        BERR_Code ExitCode = BERR_SUCCESS;
740
741        BDBG_ASSERT( Defaults );
742        BDBG_ASSERT( hChip );
743
744        BSTD_UNUSED( hChip );
745        BSTD_UNUSED( ii );              /* Might not be used if no XC and RS buffers are instantiated. */
746
747        #if BXPT_HAS_FIXED_XCBUF_CONFIG || BXPT_HAS_FIXED_RSBUF_CONFIG
748                #if BXPT_HAS_IB_PID_PARSERS
749                for( ii = 0; ii < BXPT_NUM_PID_PARSERS; ii++ )
750                {
751                        Defaults->BandwidthConfig.MaxInputRate[ ii ] = BXPT_P_INITIAL_BUF_BITRATE;
752            Defaults->BandwidthConfig.IbParserClients[ ii ].ToRave = true;
753            Defaults->BandwidthConfig.IbParserClients[ ii ].ToMsg = true;
754            #if BXPT_HAS_REMUX
755            {
756                unsigned remuxNum;
757
758                for( remuxNum = 0; remuxNum < BXPT_NUM_REMULTIPLEXORS; remuxNum++ )
759                {
760                    Defaults->BandwidthConfig.IbParserClients[ ii ].ToRmx[ remuxNum ] = true;
761                }
762            }
763            #endif
764            Defaults->BandwidthConfig.IbParserClients[ ii ].ToMpodRs = false;
765                }
766                #endif
767
768                #if BXPT_HAS_PLAYBACK_PARSERS
769                for( ii = 0; ii < BXPT_NUM_PLAYBACKS; ii++ )
770                {
771                        Defaults->BandwidthConfig.MaxPlaybackRate[ ii ] = BXPT_P_INITIAL_BUF_BITRATE;
772            Defaults->BandwidthConfig.PlaybackParserClients[ ii ].ToRave = true;
773            Defaults->BandwidthConfig.PlaybackParserClients[ ii ].ToMsg = true;
774            #if BXPT_HAS_REMUX
775            {
776                unsigned remuxNum;
777
778                for( remuxNum = 0; remuxNum < BXPT_NUM_REMULTIPLEXORS; remuxNum++ )
779                {
780                    Defaults->BandwidthConfig.PlaybackParserClients[ ii ].ToRmx[ remuxNum ] = true;
781                }
782            }
783            #endif
784                }
785                #endif
786        #endif
787
788    #if BXPT_HAS_REMUX
789    for( ii = 0; ii < BXPT_NUM_REMULTIPLEXORS; ii++ )
790    {
791        Defaults->BandwidthConfig.RemuxUsed[ ii ] = true;
792    }
793    #endif
794
795    Defaults->hRHeap = NULL;
796    Defaults->hPbHeap = NULL;
797    Defaults->MesgDataOnRPipe = false;
798
799    #if BXPT_HAS_MTSIF
800    for( ii = 0; ii < BXPT_NUM_MTSIF; ii++ ) 
801    {
802        Defaults->MtsifConfig[ ii ].RxInterfaceWidth = 8; /* 8 bits wide */
803        Defaults->MtsifConfig[ ii ].RxClockPolarity = 0;    /* Neg edge */
804        Defaults->MtsifConfig[ ii ].Enable = false;
805    }
806    #endif
807
808    return( ExitCode );
809}
810
811BERR_Code BXPT_Open(
812        BXPT_Handle *hXpt,                                              /* [out] Transport handle. */
813        BCHP_Handle hChip,                                              /* [in] Handle to used chip. */
814        BREG_Handle hRegister,                                  /* [in] Handle to access regiters. */
815        BMEM_Handle hMemory,                                    /* [in] Handle to memory heap to use. */
816        BINT_Handle hInt,                                               /* [in] Handle to interrupt interface to use. */
817        const BXPT_DefaultSettings *Defaults    /* [in] Defaults to use during init.*/
818        )
819{
820        BXPT_Handle lhXpt;
821        unsigned i;
822
823        BERR_Code ExitCode = BERR_SUCCESS;
824
825        BDBG_ENTER( BXPT_Open );
826
827        /* Sanity check on the handles we've been given. */
828        BDBG_ASSERT( hXpt );
829        BDBG_ASSERT( hChip );
830        BDBG_ASSERT( hRegister );
831        BDBG_ASSERT( hMemory );
832        BDBG_ASSERT( hInt );
833        BDBG_ASSERT( Defaults );
834
835        /* Alloc memory from the system heap. */
836        lhXpt = BKNI_Malloc( sizeof( BXPT_P_TransportData ) );
837        if( lhXpt == NULL )
838        {
839                BDBG_ERR(( "BKNI_Malloc() failed!" ));
840                ExitCode = BERR_TRACE( BERR_OUT_OF_SYSTEM_MEMORY );
841                goto done;
842        }
843               
844        BKNI_Memset( (void *) lhXpt, 0, sizeof( BXPT_P_TransportData ));                         
845        lhXpt->hChip = hChip;
846        lhXpt->hRegister = hRegister;
847        lhXpt->hMemory = hMemory;
848        lhXpt->hInt = hInt;
849
850        lhXpt->hRHeap = Defaults->hRHeap;
851        lhXpt->hPbHeap = Defaults->hPbHeap;
852        lhXpt->MesgDataOnRPipe = Defaults->MesgDataOnRPipe;
853
854#ifdef BCHP_PWR_RESOURCE_XPT
855        /* turn on the 108M and 216M for BXPT_Open */
856        BCHP_PWR_AcquireResource(hChip, BCHP_PWR_RESOURCE_XPT_108M);
857        BCHP_PWR_AcquireResource(hChip, BCHP_PWR_RESOURCE_XPT_XMEMIF);
858
859        #ifdef BCHP_PWR_RESOURCE_XPT_SRAM
860        BCHP_PWR_AcquireResource(hChip, BCHP_PWR_RESOURCE_XPT_SRAM);
861   
862        lhXpt->SRAM_Backup = BKNI_Malloc(XPT_SRAM_LIST_TOTAL_SIZE);
863        if (lhXpt->SRAM_Backup == NULL) 
864        {
865                ExitCode = BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY);
866                goto done;
867        }
868        BDBG_MSG(("XPT SRAM storage uses %u bytes", XPT_SRAM_LIST_TOTAL_SIZE));
869
870        lhXpt->Reg_Backup = BKNI_Malloc(XPT_REG_SAVE_LIST_TOTAL_SIZE);
871        if (lhXpt->Reg_Backup == NULL) 
872        {
873                ExitCode = BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY);
874                goto done;
875        }
876        BDBG_MSG(("XPT REG storage uses %u bytes", XPT_REG_SAVE_LIST_TOTAL_SIZE));
877        #endif
878#endif
879
880        /* Reset the hardware. Make sure the SCB client mapping is correct. */
881        BXPT_P_ResetTransport( hRegister );
882        BXPT_P_ConfigArbiter( hRegister );
883
884        /* Set the number of resources this transport has. */
885        lhXpt->MaxPlaybacks = BXPT_NUM_PLAYBACKS; 
886        lhXpt->MaxPidChannels = BXPT_NUM_PID_CHANNELS; 
887
888#if BXPT_HAS_IB_PID_PARSERS
889        lhXpt->MaxPidParsers = BXPT_NUM_PID_PARSERS; 
890        lhXpt->MaxInputBands = BXPT_NUM_INPUT_BANDS; 
891#endif
892
893        lhXpt->MaxTpitPids = BXPT_NUM_TPIT_PIDS; 
894
895#if BXPT_HAS_MESG_BUFFERS
896        lhXpt->MaxFilterBanks = BXPT_NUM_FILTER_BANKS; 
897        lhXpt->MaxFiltersPerBank = BXPT_NUM_FILTERS_PER_BANK; 
898#endif
899
900#if BXPT_HAS_PACKETSUB
901        lhXpt->MaxPacketSubs = BXPT_NUM_PACKETSUBS;
902#endif
903
904#if BXPT_HAS_DPCRS
905        lhXpt->MaxPcrs = BXPT_NUM_PCRS;
906#endif
907
908        lhXpt->MaxRaveContexts = BXPT_NUM_RAVE_CONTEXTS; 
909
910#ifdef ENABLE_PLAYBACK_MUX
911        /* By default, use one playback block for muxing. */
912        lhXpt->NumPlaybackMuxes = 1; 
913#endif
914 
915#if BXPT_HAS_MTSIF
916    for( i = 0; i < BXPT_NUM_MTSIF; i++ ) 
917    {
918        uint32_t Reg, RegAddr;
919        unsigned ClockPol;
920
921        unsigned IfWidth = 3;   /* 8 bit wide */
922
923        if( Defaults->MtsifConfig[ i ].RxInterfaceWidth != 8 ) 
924        {   
925            BDBG_ERR(( "Support for other than 8-bit wide MTSIF needs to be added" ));
926            ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
927            BKNI_Free( lhXpt );
928            lhXpt = NULL;
929            goto done;
930        }
931       
932        if( Defaults->MtsifConfig[ i ].RxClockPolarity > 1 ) 
933        {   
934            BDBG_ERR(( "Invalid MTSIF RX clock edge. Valid values are 0 and 1" ));
935            ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
936            BKNI_Free( lhXpt );
937            lhXpt = NULL;
938            goto done; 
939        }
940       
941    /* SW7425-1487: Invert the polarity on some parts. */
942    #if (BCHP_CHIP == 7425 && BCHP_VER < BCHP_VER_B0) \
943    || (BCHP_CHIP == 7346 && BCHP_VER < BCHP_VER_B0) \
944    || (BCHP_CHIP == 7344 && BCHP_VER < BCHP_VER_B0) \
945    || (BCHP_CHIP == 7422) \
946    || (BCHP_CHIP == 7358 && BCHP_VER <= BCHP_VER_A1) \
947    || (BCHP_CHIP == 7231 && BCHP_VER < BCHP_VER_B0)
948        ClockPol = Defaults->MtsifConfig[ i ].RxClockPolarity;  /* Older parts do *NOT* need the flop. */
949    #else   
950        ClockPol = Defaults->MtsifConfig[ i ].RxClockPolarity ? 0 : 1;  /* Newer parts do. */
951    #endif
952
953        RegAddr = BCHP_XPT_FE_MTSIF_RX0_CTRL1 + i * MTSIF_STEPSIZE;
954        Reg = BREG_Read32( hRegister, RegAddr );
955        Reg &= ~(
956             BCHP_MASK( XPT_FE_MTSIF_RX0_CTRL1, MTSIF_RX_IF_WIDTH ) |
957             BCHP_MASK( XPT_FE_MTSIF_RX0_CTRL1, MTSIF_RX_CLOCK_POL_SEL ) |
958             BCHP_MASK( XPT_FE_MTSIF_RX0_CTRL1, PARSER_ENABLE ) 
959        );
960        Reg |= ( 
961            BCHP_FIELD_DATA( XPT_FE_MTSIF_RX0_CTRL1, MTSIF_RX_IF_WIDTH, IfWidth ) |
962            BCHP_FIELD_DATA( XPT_FE_MTSIF_RX0_CTRL1, MTSIF_RX_CLOCK_POL_SEL, ClockPol ) |
963            BCHP_FIELD_DATA( XPT_FE_MTSIF_RX0_CTRL1, PARSER_ENABLE, Defaults->MtsifConfig[ i ].Enable == true ? 1 : 0 ) 
964        );
965        BREG_Write32( hRegister, RegAddr, Reg );
966
967        #ifdef BCHP_XPT_FE_MTSIF_RX0_SECRET_WORD
968        BREG_Write32( hRegister, BCHP_XPT_FE_MTSIF_RX0_SECRET_WORD + (i * MTSIF_STEPSIZE), 0x829eecde ); 
969        #endif
970    }
971#endif
972
973        /* Create and init the PID channel table. */
974        for( i = 0; i < lhXpt->MaxPidChannels; i++ )
975        {
976                /*
977                ** On some devices, not all PID channels have a message buffer. HasMessageBuffer
978                ** will be updated below, when we init the message buffer table
979                */
980#ifdef ENABLE_PLAYBACK_MUX
981    #if BXPT_SW7425_1323_WORKAROUND
982                PidChannelTableEntry InitEntry = { false, false, false, 0, 0, false, false, false, 0, false, false };
983    #else
984                PidChannelTableEntry InitEntry = { false, false, false, 0, 0, false, false, false, 0 };
985    #endif
986#else /*ENABLE_PLAYBACK_MUX*/
987    #if BXPT_SW7425_1323_WORKAROUND
988                PidChannelTableEntry InitEntry = { false, false, false, 0, 0, false, 0, false, false  };
989    #else
990                PidChannelTableEntry InitEntry = { false, false, false, 0, 0, false, 0 };
991    #endif
992#endif /*ENABLE_PLAYBACK_MUX*/
993
994        BXPT_PidChannel_CC_Config DefaultCcConfig = { true, true, false, 0 };
995
996        lhXpt->PidChannelTable[ i ] = InitEntry;
997
998                BREG_Write32( hRegister, BCHP_XPT_FE_PID_TABLE_i_ARRAY_BASE + ( 4 * i ), 1 << 28 );
999                BREG_Write32( hRegister, BCHP_XPT_FE_SPID_TABLE_i_ARRAY_BASE + ( 4 * i ), 0 );
1000
1001        lhXpt->CcConfigBeforeAllPass[ i ] = DefaultCcConfig;
1002        BXPT_SetPidChannel_CC_Config( lhXpt, i, &DefaultCcConfig );
1003        }
1004
1005#if BXPT_HAS_MESG_BUFFERS
1006        /* Create and init the message buffer table. */
1007        for( i = 0; i < BXPT_NUM_MESG_BUFFERS; i++ )
1008        {
1009                MessageBufferEntry InitEntry = { false, 0, 0 };
1010                lhXpt->MessageBufferTable[ i ] = InitEntry;     
1011
1012                lhXpt->MesgBufferIsInitialized[ i ] = false;
1013
1014                lhXpt->PidChannelTable[ i ].HasMessageBuffer = true;
1015                lhXpt->PidChannelTable[ i ].MessageBuffercount = 0;
1016
1017                lhXpt->MesgIntrCallbacks[ i ].Callback = ( BINT_CallbackFunc ) NULL;
1018                lhXpt->OverflowIntrCallbacks[ i ].Callback = ( BINT_CallbackFunc ) NULL;
1019
1020                BREG_Write32( hRegister, BCHP_XPT_MSG_BUF_CTRL1_TABLE_i_ARRAY_BASE + ( 4 * i ), 0 );
1021                BREG_Write32( hRegister, BCHP_XPT_MSG_BUF_CTRL2_TABLE_i_ARRAY_BASE + ( 4 * i ), 0 );
1022                BREG_Write32( hRegister, BCHP_XPT_MSG_DMA_BP_TABLE_i_ARRAY_BASE + ( 4 * i ), 0 );
1023                BREG_Write32( hRegister, BCHP_XPT_MSG_GEN_FILT_EN_i_ARRAY_BASE + ( 4 * i ), 0 );
1024
1025        /* for normal legacy mode set false, set true to override settings */
1026        lhXpt->PidChannelParserConfigOverride[i] = false;
1027        }
1028
1029        /* Mark all the PSI filters as not allocated ( or unused ). */
1030        for( i = 0; i < lhXpt->MaxFilterBanks; i++ )
1031    {
1032            unsigned j;
1033
1034                for( j = 0; j < lhXpt->MaxFiltersPerBank; j++ )
1035                {
1036                        lhXpt->FilterTable[ i ][ j ].IsAllocated = false;
1037                }
1038    }
1039
1040        /* Clear the mesg filter banks. */
1041        for( i = 0; i < MESG_FILTER_ARRAY_ELEMENTS; i++ )
1042        {
1043                BREG_Write32( hRegister, BCHP_XPT_MSG_GEN_FILT_COEF_i_ARRAY_BASE + ( 4 * i ), 0 );
1044                BREG_Write32( hRegister, BCHP_XPT_MSG_GEN_FILT_MASK_i_ARRAY_BASE + ( 4 * i ), 0 );
1045                BREG_Write32( hRegister, BCHP_XPT_MSG_GEN_FILT_EXCL_i_ARRAY_BASE + ( 4 * i ), 0 );
1046        }
1047#endif
1048
1049#if BXPT_HAS_IB_PID_PARSERS && BXPT_HAS_MESG_BUFFERS
1050        /*
1051        ** All parser bands initially do NOT modify PSI messages in the DMA buffers.
1052        ** This is the hardware default.
1053        */
1054        for( i = 0; i < BXPT_NUM_PID_PARSERS; i++ )
1055        {
1056                ParserConfig ParserInit = { false, false, false, BXPT_PsiMesgModModes_eNoMod };
1057
1058                lhXpt->IbParserTable[ i ] = ParserInit;
1059        lhXpt->IsParserInAllPass[ i ] = false;
1060    }                     
1061#endif
1062
1063        /* Each playback has a hard-wired PID parser. So init the table for those too. */
1064        for( i = 0; i < BXPT_NUM_PLAYBACKS; i++ )
1065        {
1066                ParserConfig ParserInit = { false, false, false, BXPT_PsiMesgModModes_eNoMod };
1067
1068                lhXpt->PbParserTable[ i ] = ParserInit;
1069        }
1070
1071        /* Init the RAVE structure in the xpt handle. */
1072        for( i = 0; i < BXPT_NUM_RAVE_CHANNELS; i++ )
1073        {
1074                lhXpt->RaveChannels[ i ].Allocated = false;
1075        }
1076
1077        /* Init the RAVE structure in the xpt handle. */
1078        for( i = 0; i < BXPT_NUM_PCR_OFFSET_CHANNELS; i++ )
1079        {
1080                lhXpt->PcrOffsets[ i ].Handle = NULL;
1081                lhXpt->PcrOffsets[ i ].Allocated = false;
1082        }
1083                                   
1084#if BXPT_HAS_MESG_BUFFERS
1085        /* Register our message and overflow interrupts */
1086        ExitCode = BERR_TRACE( BINT_CreateCallback( &lhXpt->hMsgCb, lhXpt->hInt, BCHP_INT_ID_XPT_MSG_INTR_FLAG, (BINT_CallbackFunc) BXPT_P_Interrupt_MsgVector_isr, lhXpt, 0 ));
1087        if( ExitCode != BERR_SUCCESS )
1088        {
1089                BDBG_ERR(("Unabled to create XPT Message Interrupt Callback!"));
1090                goto done;
1091        }
1092       
1093        ExitCode = BERR_TRACE( BINT_CreateCallback( &lhXpt->hMsgOverflowCb, lhXpt->hInt, BCHP_INT_ID_XPT_MSG_OVFL_INTR_FLAG, (BINT_CallbackFunc) BXPT_P_Interrupt_MsgOverflowVector_isr, lhXpt, 0 ));
1094        if( ExitCode != BERR_SUCCESS )
1095        {
1096                BDBG_ERR(("Unabled to create XPT Message Overflow Callback!"));
1097                goto done;
1098        }
1099#endif
1100
1101#if BXPT_HAS_FIXED_RSBUF_CONFIG
1102        ExitCode = BERR_TRACE( BXPT_P_RsBuf_Init( lhXpt, &Defaults->BandwidthConfig ) );
1103        if( ExitCode != BERR_SUCCESS )
1104        {
1105                BDBG_ERR(("Rate smoothing buffer init FAILED!"));
1106                goto done;
1107        }
1108#endif
1109
1110#if BXPT_HAS_FIXED_XCBUF_CONFIG
1111        ExitCode = BERR_TRACE( BXPT_P_XcBuf_Init( lhXpt, &Defaults->BandwidthConfig ) );
1112        if( ExitCode != BERR_SUCCESS )
1113        {
1114                BDBG_ERR(("XPT client buffer init FAILED!"));
1115                goto done;
1116        }
1117#endif
1118
1119    BXPT_P_PcrOffset_ModuleInit( lhXpt );
1120
1121#if BXPT_HAS_MESG_BUFFERS
1122    BXPT_Mesg_SetPid2Buff( lhXpt, true );
1123#endif
1124
1125#if BXPT_HAS_TSMUX
1126    BXPT_TsMux_P_ResetBandPauseMap( lhXpt );
1127    BXPT_TsMux_P_ResetPacingPauseMap( lhXpt );
1128#endif
1129
1130#if BXPT_HAS_PARSER_REMAPPING
1131    {
1132        BXPT_ParserBandMapping ParserMap;
1133        unsigned ii;
1134       
1135        /* Default virtual parser to equal the underlying physical parser. */
1136        for( ii = 0; ii < BXPT_NUM_PID_PARSERS; ii++ ) 
1137        {
1138            ParserMap.FrontEnd[ ii ].VirtualParserBandNum = ii;
1139            ParserMap.FrontEnd[ ii ].VirtualParserIsPlayback = false;
1140        }
1141
1142        for( ii = 0; ii < BXPT_NUM_PLAYBACKS; ii++ ) 
1143        {
1144            ParserMap.Playback[ ii ].VirtualParserBandNum = ii;
1145            ParserMap.Playback[ ii ].VirtualParserIsPlayback = true;
1146        }
1147
1148        BXPT_SetParserMapping( lhXpt, &ParserMap );
1149    }
1150#endif
1151
1152#if BXPT_HAS_DPCRS
1153    {
1154        unsigned Index;
1155
1156        for( Index = 0; Index < BXPT_NUM_PCRS; Index++ )
1157        {
1158            lhXpt->JitterTimestamp[ Index ] = BXPT_PCR_JitterTimestampMode_eAuto; 
1159            lhXpt->PbJitterDisable[ Index ] = BXPT_PCR_JitterCorrection_eAuto;
1160            lhXpt->LiveJitterDisable[ Index ] = BXPT_PCR_JitterCorrection_eAuto;
1161        }
1162    }
1163#endif
1164
1165#if BXPT_HAS_MPOD_RSBUF
1166    for( i = 0; i < lhXpt->MaxPidParsers; i++ )
1167    {
1168        /* must be called after BXPT_SetParserMapping has been called above */
1169        uint32_t Addr = BXPT_P_GetParserCtrlRegAddr( lhXpt, i, BCHP_XPT_FE_MINI_PID_PARSER0_CTRL2 );
1170        uint32_t Reg = BREG_Read32( hRegister, Addr );
1171        Reg &= ~(
1172            BCHP_MASK( XPT_FE_MINI_PID_PARSER0_CTRL2, MPOD_MODE_SEL )
1173        );
1174        Reg |= (
1175            BCHP_FIELD_DATA( XPT_FE_MINI_PID_PARSER0_CTRL2, MPOD_MODE_SEL, 
1176                Defaults->BandwidthConfig.IbParserClients[ i ].ToMpodRs ? 1 : 0 )
1177        );
1178        BREG_Write32( hRegister, Addr, Reg );
1179    }
1180#endif
1181
1182        done:
1183        *hXpt = lhXpt;
1184        BDBG_LEAVE( BXPT_Open );
1185
1186#ifdef BCHP_PWR_RESOURCE_XPT
1187        /* a failed BXPT_Open powers down the 216 and 108M */
1188        if (ExitCode!=BERR_SUCCESS) {   
1189                BCHP_PWR_ReleaseResource(hChip, BCHP_PWR_RESOURCE_XPT_XMEMIF);
1190                BCHP_PWR_ReleaseResource(hChip, BCHP_PWR_RESOURCE_XPT_108M);
1191
1192        #ifdef BCHP_PWR_RESOURCE_XPT_SRAM
1193                BCHP_PWR_ReleaseResource(hChip, BCHP_PWR_RESOURCE_XPT_SRAM);
1194        #endif 
1195        }
1196#endif
1197
1198        return( ExitCode );
1199}
1200
1201void BXPT_Close(
1202        BXPT_Handle hXpt                /* [in] Handle for the Transport to be closed. */ 
1203        )
1204{
1205        unsigned int Index;
1206
1207        BERR_Code Res;
1208
1209        BDBG_ASSERT( hXpt );
1210
1211        /* Shutdown PID parsers and playbacks before XC and RS buffers. */
1212#if BXPT_HAS_IB_PID_PARSERS
1213    for( Index = 0; Index < hXpt->MaxPidParsers; Index++ )
1214            BXPT_SetParserEnable( hXpt, Index, false );
1215#endif
1216
1217#if BXPT_HAS_FIXED_RSBUF_CONFIG
1218        Res = BXPT_P_RsBuf_Shutdown( hXpt );
1219        BDBG_ASSERT( Res == BERR_SUCCESS );
1220#endif
1221
1222#if BXPT_HAS_FIXED_XCBUF_CONFIG
1223        Res = BXPT_P_XcBuf_Shutdown( hXpt );
1224        BDBG_ASSERT( Res == BERR_SUCCESS );
1225#endif
1226
1227        for( Index = 0; Index < BXPT_NUM_RAVE_CHANNELS; Index++ )
1228                if( hXpt->RaveChannels[ Index ].Allocated == true )
1229                {
1230                        Res = BXPT_Rave_CloseChannel( ( BXPT_Rave_Handle ) hXpt->RaveChannels[ Index ].Handle );
1231                        BDBG_ASSERT( Res == BERR_SUCCESS );
1232                }
1233       
1234        for( Index = 0; Index < BXPT_NUM_PCR_OFFSET_CHANNELS; Index++ )
1235                if( hXpt->PcrOffsets[ Index ].Allocated == true ) 
1236                {
1237                        Res = BXPT_PcrOffset_Close( ( BXPT_PcrOffset_Handle ) hXpt->PcrOffsets[ Index ].Handle );
1238                        BDBG_ASSERT( Res == BERR_SUCCESS );
1239                }
1240       
1241        for ( Index = 0; Index < BXPT_NUM_PLAYBACKS; Index++ ) {
1242                if ( hXpt->PlaybackHandles[Index].Opened == true ) {
1243                        BXPT_Playback_CloseChannel( (BXPT_Playback_Handle) &hXpt->PlaybackHandles[Index] );
1244                }
1245        }
1246
1247#if BXPT_HAS_PACKETSUB
1248        for ( Index = 0; Index < BXPT_NUM_PACKETSUBS; Index++ ) {
1249                if ( hXpt->PacketSubHandles[Index].Opened == true ) {
1250                        BXPT_PacketSub_CloseChannel( (BXPT_PacketSub_Handle) &hXpt->PacketSubHandles[Index]);           
1251                }
1252        }
1253#endif
1254
1255#if BXPT_HAS_REMUX
1256        for ( Index = 0; Index < BXPT_NUM_REMULTIPLEXORS; Index++ ) {
1257                if ( hXpt->RemuxHandles[Index].Opened == true ) {
1258                        BXPT_Remux_CloseChannel( (BXPT_Remux_Handle) &hXpt->RemuxHandles[Index]);
1259                }
1260        }
1261#endif
1262
1263#if BXPT_HAS_MESG_BUFFERS
1264        /*
1265        ** Free any message buffers we've allocated. If the user has allocated any, its
1266        ** the their responsibility to free them.
1267        */
1268        for( Index = 0; Index < BXPT_NUM_MESG_BUFFERS; Index++ )
1269        {
1270                MessageBufferEntry *Buffer = &hXpt->MessageBufferTable[ Index ];
1271                 
1272                /* Free the old buffer, if there is one. */
1273                if( Buffer->IsAllocated == true )
1274                {
1275                        if( Buffer->Address )
1276                                BMEM_Free( hXpt->hMemory, ( void * ) Buffer->Address );
1277                        Buffer->IsAllocated = false;
1278                }
1279        }
1280
1281        BINT_DestroyCallback(hXpt->hMsgCb);
1282        BINT_DestroyCallback(hXpt->hMsgOverflowCb);
1283#endif
1284
1285        /* Reset the core, thus stopping any unwanted interrupts. */
1286        BXPT_P_ResetTransport( hXpt->hRegister );
1287
1288#ifdef BCHP_PWR_RESOURCE_XPT
1289        #ifdef BCHP_PWR_RESOURCE_XPT_SRAM
1290        BCHP_PWR_ReleaseResource(hXpt->hChip, BCHP_PWR_RESOURCE_XPT_SRAM);
1291        BKNI_Free(hXpt->SRAM_Backup);
1292        BKNI_Free(hXpt->Reg_Backup);
1293        #endif
1294   
1295        /* release the 261 and 108M after BXPT_P_ResetTransport */
1296        BCHP_PWR_ReleaseResource(hXpt->hChip, BCHP_PWR_RESOURCE_XPT_XMEMIF);
1297        BCHP_PWR_ReleaseResource(hXpt->hChip, BCHP_PWR_RESOURCE_XPT_108M);
1298#endif
1299
1300        /* Dont need the transport handle any more. */
1301        BKNI_Free( hXpt );
1302}
1303
1304
1305void BXPT_GetDefaultStandbySettings(
1306    BXPT_StandbySettings *pSettings
1307    )
1308{
1309        pSettings->UseWakeupPacket = false;
1310        pSettings->S3Standby = false;
1311}
1312
1313BERR_Code BXPT_Standby(
1314        BXPT_Handle hXpt,
1315        BXPT_StandbySettings *pSettings
1316        )
1317{
1318#ifdef BCHP_PWR_RESOURCE_XPT
1319        unsigned int Index;
1320#endif
1321        BDBG_ASSERT(pSettings);   
1322
1323#ifdef BCHP_PWR_RESOURCE_XPT
1324        if (hXpt->bStandby) {
1325                BDBG_ERR(("Already in standby"));
1326                return BERR_UNKNOWN;
1327        }
1328   
1329        /* check if XPT is still in use. if so, we cannot enter standby */
1330
1331#if BXPT_HAS_IB_PID_PARSERS 
1332        for( Index = 0; Index < hXpt->MaxPidParsers; Index++ ) {
1333                uint32_t Reg, RegAddr;
1334                RegAddr = BXPT_P_GetParserCtrlRegAddr( hXpt, Index, BCHP_XPT_FE_MINI_PID_PARSER0_CTRL1 );
1335                Reg = BREG_Read32( hXpt->hRegister, RegAddr );
1336                if (BCHP_GET_FIELD_DATA(Reg, XPT_FE_MINI_PID_PARSER0_CTRL1, PARSER_ENABLE)) {
1337                        BDBG_ERR(("One or more parsers still enabled. Cannot enter standby"));
1338                        return BERR_UNKNOWN;
1339                }
1340        }
1341#endif
1342
1343        for ( Index = 0; Index < BXPT_NUM_PLAYBACKS; Index++ ) {
1344                if ( hXpt->PlaybackHandles[Index].Running == true ) {
1345                        BDBG_ERR(("One or more playback channels still running. Cannot enter standby"));
1346                        return BERR_UNKNOWN;
1347                }
1348        }
1349
1350#if BXPT_HAS_PACKETSUB
1351        for ( Index = 0; Index < BXPT_NUM_PACKETSUBS; Index++ ) {
1352                if ( hXpt->PacketSubHandles[Index].Running == true ) {
1353                        BDBG_ERR(("One or more packetsub channels still running. Cannot enter standby"));
1354                        return BERR_UNKNOWN;
1355                }
1356        }
1357#endif
1358
1359#if BXPT_HAS_REMUX
1360        for ( Index = 0; Index < BXPT_NUM_REMULTIPLEXORS; Index++ ) {
1361                if ( hXpt->RemuxHandles[Index].Running == true ) {
1362                        BDBG_ERR(("One or more remux channels still running. Cannot enter standby"));
1363                        return BERR_UNKNOWN;
1364                }
1365        }
1366#endif
1367
1368    /* if we get to this point, then XPT is not in use */
1369
1370#ifdef BCHP_PWR_RESOURCE_XPT_SRAM
1371        if( pSettings->S3Standby ) 
1372        {
1373                BCHP_PWR_AcquireResource(hXpt->hChip, BCHP_PWR_RESOURCE_XPT_REMUX);
1374                BXPT_P_RegisterToMemory(hXpt->hRegister, hXpt->Reg_Backup, XPT_REG_SAVE_LIST);
1375                BCHP_PWR_ReleaseResource(hXpt->hChip, BCHP_PWR_RESOURCE_XPT_REMUX);
1376        }
1377        hXpt->bS3Standby = pSettings->S3Standby;
1378   
1379        BXPT_P_RegisterToMemory(hXpt->hRegister, hXpt->SRAM_Backup, XPT_SRAM_LIST);
1380        BCHP_PWR_ReleaseResource(hXpt->hChip, BCHP_PWR_RESOURCE_XPT_SRAM);
1381#endif
1382
1383        /* XPT can now release the 216 and 108M */
1384        BCHP_PWR_ReleaseResource(hXpt->hChip, BCHP_PWR_RESOURCE_XPT_XMEMIF);
1385        BCHP_PWR_ReleaseResource(hXpt->hChip, BCHP_PWR_RESOURCE_XPT_108M);
1386
1387#ifdef BCHP_PWR_RESOURCE_XPT_WAKEUP
1388    /* Keep the 216 clock running for the XPT_WAKEUP block */
1389    if( true == pSettings->UseWakeupPacket && !hXpt->WakeupEnabled )
1390    {
1391        BCHP_PWR_AcquireResource(hXpt->hChip, BCHP_PWR_RESOURCE_XPT_WAKEUP);
1392        hXpt->WakeupEnabled = true;
1393    }
1394#endif /* BCHP_PWR_RESOURCE_XPT_WAKEUP */
1395
1396        hXpt->bStandby = true;
1397#else
1398        BSTD_UNUSED( hXpt );
1399#endif /* #ifdef BCHP_PWR_RESOURCE_XPT */
1400
1401    return BERR_SUCCESS;
1402}
1403
1404BERR_Code BXPT_Resume(
1405        BXPT_Handle hXpt
1406        )
1407{
1408#ifdef BCHP_PWR_RESOURCE_XPT
1409        if (!hXpt->bStandby) {
1410                BDBG_ERR(("Not in standby"));
1411                return BERR_UNKNOWN;       
1412        }
1413        BCHP_PWR_AcquireResource(hXpt->hChip, BCHP_PWR_RESOURCE_XPT_XMEMIF);
1414        BCHP_PWR_AcquireResource(hXpt->hChip, BCHP_PWR_RESOURCE_XPT_108M);
1415
1416#ifdef BCHP_PWR_RESOURCE_XPT_SRAM
1417        BCHP_PWR_AcquireResource(hXpt->hChip, BCHP_PWR_RESOURCE_XPT_SRAM);
1418        BXPT_P_MemoryToRegister(hXpt->hRegister, hXpt->SRAM_Backup, XPT_SRAM_LIST);
1419
1420        if( hXpt->bS3Standby ) 
1421        {
1422                BCHP_PWR_AcquireResource(hXpt->hChip, BCHP_PWR_RESOURCE_XPT_REMUX);
1423                BXPT_P_MemoryToRegister(hXpt->hRegister, hXpt->Reg_Backup, XPT_REG_SAVE_LIST);
1424                BCHP_PWR_ReleaseResource(hXpt->hChip, BCHP_PWR_RESOURCE_XPT_REMUX);
1425        }
1426   
1427        BXPT_P_RaveRamInit( (BXPT_Rave_Handle) hXpt->vhRave );
1428#endif
1429
1430#ifdef BCHP_PWR_RESOURCE_XPT_WAKEUP
1431    if( hXpt->WakeupEnabled )
1432    {
1433        BCHP_PWR_ReleaseResource(hXpt->hChip, BCHP_PWR_RESOURCE_XPT_WAKEUP);
1434        hXpt->WakeupEnabled = false;
1435    }
1436#endif /* BCHP_PWR_RESOURCE_XPT_WAKEUP */
1437
1438        hXpt->bStandby = false;
1439#else
1440    BSTD_UNUSED( hXpt );
1441#endif /* #ifdef BCHP_PWR_RESOURCE_XPT */
1442
1443        return BERR_SUCCESS;
1444}
1445
1446void BXPT_GetCapability(
1447        BXPT_Handle hXpt,                       /* [in] Which transport to get data. */
1448        BXPT_Capability *Capability     /* [out] Where to put the capability data. */
1449        )
1450{
1451        BSTD_UNUSED( hXpt );
1452        BDBG_ASSERT( Capability );
1453
1454        /*
1455        ** Set the values in the caller's structure. 
1456        */
1457#if BXPT_HAS_PLAYBACK_PARSERS
1458        Capability->MaxPlaybacks = BXPT_NUM_PLAYBACKS; 
1459        Capability->MaxPidChannels = BXPT_NUM_PID_CHANNELS; 
1460#endif
1461
1462#if BXPT_HAS_IB_PID_PARSERS
1463        Capability->MaxPidParsers = BXPT_NUM_PID_PARSERS; 
1464        Capability->MaxInputBands = BXPT_NUM_INPUT_BANDS; 
1465#endif
1466
1467        Capability->MaxTpitPids = BXPT_NUM_TPIT_PIDS;
1468
1469#if BXPT_HAS_MESG_BUFFERS       
1470        Capability->MaxFilterBanks = BXPT_NUM_FILTER_BANKS;                       
1471        Capability->MaxFiltersPerBank = BXPT_NUM_FILTERS_PER_BANK; 
1472#endif
1473
1474#if BXPT_HAS_PACKETSUB
1475        Capability->MaxPacketSubs = BXPT_NUM_PACKETSUBS;
1476#endif
1477
1478#if BXPT_HAS_DPCRS
1479        Capability->MaxPcrs = BXPT_NUM_PCRS;
1480#endif
1481
1482        Capability->MaxRaveContexts = BXPT_NUM_RAVE_CONTEXTS; 
1483}
1484
1485
1486#if BXPT_HAS_IB_PID_PARSERS
1487
1488BERR_Code BXPT_GetParserConfig(
1489        BXPT_Handle hXpt,                               /* [in] Handle for the transport to access. */
1490        unsigned int ParserNum,                         /* [in] Which parser band to access. */
1491        BXPT_ParserConfig *ParserConfig /* [out] The current settings */
1492        )
1493{
1494        uint32_t Reg, RegAddr;
1495
1496        BERR_Code ExitCode = BERR_SUCCESS;
1497
1498        BDBG_ASSERT( hXpt );
1499        BDBG_ASSERT( ParserConfig );
1500
1501        /* Is the parser number within range? */
1502        if( ParserNum > hXpt->MaxPidParsers )
1503        {
1504                /* Bad parser number. Complain. */
1505                BDBG_ERR(( "ParserNum %lu is out of range!", ParserNum ));
1506                ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );                                                 
1507        }
1508        else
1509        {
1510        RegAddr = BXPT_P_GetParserCtrlRegAddr( hXpt, ParserNum, BCHP_XPT_FE_MINI_PID_PARSER0_CTRL1 );
1511                Reg = BREG_Read32( hXpt->hRegister, RegAddr );
1512
1513                ParserConfig->ErrorInputIgnore = BCHP_GET_FIELD_DATA( Reg, XPT_FE_MINI_PID_PARSER0_CTRL1, PARSER_ERROR_INPUT_TEI_IGNORE );
1514                ParserConfig->TsMode = BCHP_GET_FIELD_DATA( Reg, XPT_FE_MINI_PID_PARSER0_CTRL1, PARSER_TIMESTAMP_MODE );
1515                ParserConfig->AcceptNulls = BCHP_GET_FIELD_DATA( Reg, XPT_FE_MINI_PID_PARSER0_CTRL1, PARSER_ACCEPT_NULL_PKT_PRE_MPOD );
1516
1517#if BCHP_XPT_FULL_PID_PARSER_IBP_ACCEPT_ADAPT_00_PARSER0_ACCEPT_ADP_00_MASK != 0x00000001 || BXPT_NUM_PID_PARSERS > 32
1518    #error "PI NEEDS UPDATING"
1519#else
1520                Reg = BREG_Read32( hXpt->hRegister, BCHP_XPT_FULL_PID_PARSER_IBP_ACCEPT_ADAPT_00 );
1521                ParserConfig->AcceptAdapt00 = (Reg >> GetParserIndex (hXpt, ParserNum)) & 0x01 ? true : false;
1522#endif
1523        }
1524
1525        return( ExitCode );
1526}
1527
1528BERR_Code BXPT_GetDefaultParserConfig(
1529        BXPT_Handle hXpt,                               /* [in] Handle for the transport to access. */
1530        unsigned int ParserNum,                         /* [in] Which parser band to access. */
1531        BXPT_ParserConfig *ParserConfig /* [out] The current settings */
1532        )
1533{
1534        BERR_Code ExitCode = BERR_SUCCESS;
1535
1536        BDBG_ASSERT( hXpt );
1537        BDBG_ASSERT( ParserConfig );
1538
1539        /* Is the parser number within range? */
1540        if( ParserNum > hXpt->MaxPidParsers )
1541        {
1542                /* Bad parser number. Complain. */
1543                BDBG_ERR(( "ParserNum %lu is out of range!", ParserNum ));
1544                ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
1545        }
1546        else
1547        {
1548                ParserConfig->ErrorInputIgnore = false;
1549                ParserConfig->TsMode = BXPT_ParserTimestampMode_eAutoSelect;
1550                ParserConfig->AcceptNulls = false;
1551        ParserConfig->AcceptAdapt00 = false;
1552        }
1553
1554        return( ExitCode );
1555}
1556
1557BERR_Code BXPT_SetParserConfig(
1558        BXPT_Handle hXpt,                                               /* [in] Handle for the transport to access. */
1559        unsigned int ParserNum,                         /* [in] Which parser band to access. */
1560        const BXPT_ParserConfig *ParserConfig   /* [in] The new settings */
1561        )
1562{
1563        uint32_t Reg, RegAddr;
1564
1565        BERR_Code ExitCode = BERR_SUCCESS;
1566
1567        BDBG_ASSERT( hXpt );
1568        BDBG_ASSERT( ParserConfig );
1569
1570        /* Is the parser number within range? */
1571        if( ParserNum > hXpt->MaxPidParsers )
1572        {
1573                /* Bad parser number. Complain. */
1574                BDBG_ERR(( "ParserNum %lu is out of range!", ParserNum ));
1575                ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
1576        }
1577        else
1578        {
1579                /* The parser config registers are at consecutive addresses. */
1580                RegAddr = BXPT_P_GetParserCtrlRegAddr( hXpt, ParserNum, BCHP_XPT_FE_MINI_PID_PARSER0_CTRL1 );
1581                Reg = BREG_Read32( hXpt->hRegister, RegAddr );
1582               
1583                /* Clear all the bits we are about to change. */
1584                Reg &= ~(
1585                        BCHP_MASK( XPT_FE_MINI_PID_PARSER0_CTRL1, PARSER_ERROR_INPUT_TEI_IGNORE ) |
1586                        BCHP_MASK( XPT_FE_MINI_PID_PARSER0_CTRL1, PARSER_TIMESTAMP_MODE ) |
1587                        BCHP_MASK( XPT_FE_MINI_PID_PARSER0_CTRL1, PARSER_ACCEPT_NULL_PKT_PRE_MPOD ) 
1588                );
1589
1590                /* Now set the new values. */
1591                Reg |= (
1592                        BCHP_FIELD_DATA( XPT_FE_MINI_PID_PARSER0_CTRL1, PARSER_ERROR_INPUT_TEI_IGNORE, ParserConfig->ErrorInputIgnore ) |
1593                        BCHP_FIELD_DATA( XPT_FE_MINI_PID_PARSER0_CTRL1, PARSER_TIMESTAMP_MODE, ParserConfig->TsMode ) |
1594                        BCHP_FIELD_DATA( XPT_FE_MINI_PID_PARSER0_CTRL1, PARSER_ACCEPT_NULL_PKT_PRE_MPOD, ParserConfig->AcceptNulls )
1595                );
1596
1597                BREG_Write32( hXpt->hRegister, RegAddr, Reg );
1598
1599
1600#if BCHP_XPT_FULL_PID_PARSER_IBP_ACCEPT_ADAPT_00_PARSER0_ACCEPT_ADP_00_MASK != 0x00000001 || BXPT_NUM_PID_PARSERS > 32
1601    #error "PI NEEDS UPDATING"
1602#else
1603                Reg = BREG_Read32( hXpt->hRegister, BCHP_XPT_FULL_PID_PARSER_IBP_ACCEPT_ADAPT_00 );
1604                Reg &= ~(0x01 << ParserNum);
1605        if( ParserConfig->AcceptAdapt00 ) 
1606            Reg |= (0x01 << GetParserIndex (hXpt, ParserNum));
1607                BREG_Write32( hXpt->hRegister, BCHP_XPT_FULL_PID_PARSER_IBP_ACCEPT_ADAPT_00, Reg );
1608#endif
1609        }
1610
1611        return( ExitCode );
1612}
1613
1614BERR_Code BXPT_GetDefaultInputBandConfig(
1615        BXPT_Handle hXpt,                                               /* [in] Handle for the transport to access. */
1616        unsigned int BandNum,                                           /* [in] Which input band to access. */
1617        BXPT_InputBandConfig *InputBandConfig   /* [in] The current settings */
1618        )
1619{
1620        BERR_Code ExitCode = BERR_SUCCESS;
1621
1622        BDBG_ASSERT( hXpt );
1623        BDBG_ASSERT( InputBandConfig );
1624
1625        /* Is the parser number within range? */
1626        if( BandNum > hXpt->MaxInputBands )
1627        {
1628                /* Bad parser number. Complain. */
1629                BDBG_ERR(( "BandNum %lu is out of range!", BandNum ));
1630                ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
1631        }
1632        else
1633        {
1634                InputBandConfig->ClockPolSel = BXPT_Polarity_eActiveHigh;
1635                InputBandConfig->SyncPolSel = BXPT_Polarity_eActiveHigh;
1636                InputBandConfig->DataPolSel = BXPT_Polarity_eActiveHigh;
1637                InputBandConfig->ValidPolSel = BXPT_Polarity_eActiveHigh;
1638                InputBandConfig->ForceValid = false;
1639                InputBandConfig->SyncDetectEn = false;
1640                InputBandConfig->LsbFirst = false;
1641                InputBandConfig->UseSyncAsValid = false;
1642                InputBandConfig->ErrorPolSel = BXPT_Polarity_eActiveHigh;
1643                InputBandConfig->EnableErrorInput = false;
1644                InputBandConfig->IbPktLength = 188;     /* Default to MPEG */
1645
1646                if ( BandNum == 4 ) 
1647                        InputBandConfig->ParallelInputSel = true;
1648                else 
1649                        InputBandConfig->ParallelInputSel = false;
1650        }
1651
1652        return( ExitCode );
1653}
1654
1655BERR_Code BXPT_GetInputBandConfig(
1656        BXPT_Handle hXpt,                                               /* [in] Handle for the transport to access. */
1657        unsigned int BandNum,                                           /* [in] Which input band to access. */
1658        BXPT_InputBandConfig *InputBandConfig   /* [in] The current settings */
1659        )
1660{
1661        uint32_t Reg, RegAddr;
1662
1663        BERR_Code ExitCode = BERR_SUCCESS;
1664
1665        BDBG_ASSERT( hXpt );
1666        BDBG_ASSERT( InputBandConfig );
1667
1668        /* Is the parser number within range? */
1669        if( BandNum > hXpt->MaxInputBands )
1670        {
1671                /* Bad parser number. Complain. */
1672                BDBG_ERR(( "BandNum %lu is out of range!", BandNum ));
1673                ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
1674        }
1675        else
1676        {
1677                /* The parser config registers are at consecutive addresses. */
1678                RegAddr =  BCHP_XPT_FE_IB0_CTRL + ( BandNum * IB_REG_STEPSIZE );
1679                Reg = BREG_Read32( hXpt->hRegister, RegAddr );
1680               
1681                InputBandConfig->ClockPolSel = BCHP_GET_FIELD_DATA( Reg, XPT_FE_IB0_CTRL, IB_CLOCK_POL_SEL ) ? 
1682                        BXPT_Polarity_eActiveLow : BXPT_Polarity_eActiveHigh;
1683
1684                InputBandConfig->SyncPolSel = BCHP_GET_FIELD_DATA( Reg, XPT_FE_IB0_CTRL, IB_SYNC_POL_SEL ) ? 
1685                        BXPT_Polarity_eActiveLow : BXPT_Polarity_eActiveHigh;
1686
1687                InputBandConfig->DataPolSel = BCHP_GET_FIELD_DATA( Reg, XPT_FE_IB0_CTRL, IB_DATA_POL_SEL ) ? 
1688                        BXPT_Polarity_eActiveLow : BXPT_Polarity_eActiveHigh;
1689
1690                InputBandConfig->ValidPolSel = BCHP_GET_FIELD_DATA( Reg, XPT_FE_IB0_CTRL, IB_VALID_POL_SEL ) ? 
1691                        BXPT_Polarity_eActiveLow : BXPT_Polarity_eActiveHigh;
1692
1693                InputBandConfig->ForceValid = BCHP_GET_FIELD_DATA( Reg, XPT_FE_IB0_CTRL, IB_FORCE_VALID ) ?
1694                        true : false;
1695
1696                InputBandConfig->SyncDetectEn = BCHP_GET_FIELD_DATA( Reg, XPT_FE_IB0_CTRL, IB_SYNC_DETECT_EN ) ?
1697                        true : false;
1698
1699                InputBandConfig->LsbFirst = BCHP_GET_FIELD_DATA( Reg, XPT_FE_IB0_CTRL, IB_LSB_FIRST ) ?
1700                        true : false;
1701
1702                InputBandConfig->UseSyncAsValid = BCHP_GET_FIELD_DATA( Reg, XPT_FE_IB0_CTRL, IB_USE_SYNC_AS_VALID ) ?
1703                        true : false;
1704
1705                InputBandConfig->ErrorPolSel = BCHP_GET_FIELD_DATA( Reg, XPT_FE_IB0_CTRL, IB_ERROR_POL_SEL ) ? 
1706                        BXPT_Polarity_eActiveLow : BXPT_Polarity_eActiveHigh;
1707
1708                InputBandConfig->EnableErrorInput = BCHP_GET_FIELD_DATA( Reg, XPT_FE_IB0_CTRL, IB_ERROR_INPUT_EN ) ?
1709                        true : false;
1710
1711                InputBandConfig->IbPktLength = ( int ) BCHP_GET_FIELD_DATA( Reg, XPT_FE_IB0_CTRL, IB_PKT_LENGTH );
1712
1713                InputBandConfig->ParallelInputSel = BCHP_GET_FIELD_DATA( Reg, XPT_FE_IB0_CTRL, IB_PARALLEL_INPUT_SEL ) ? true : false;
1714        }
1715
1716        return( ExitCode );
1717}
1718
1719BERR_Code BXPT_SetInputBandConfig(
1720        BXPT_Handle hXpt,                                                       /* [in] Handle for the transport to access. */
1721        unsigned int BandNum,                                           /* [in] Which input band to access. */
1722        const BXPT_InputBandConfig *InputBandConfig     /* [in] The new settings */
1723        )
1724{
1725        uint32_t Reg, RegAddr;
1726
1727        BERR_Code ExitCode = BERR_SUCCESS;
1728        unsigned short ParallelInputEn = 0;
1729
1730        BDBG_ASSERT( hXpt );
1731        BDBG_ASSERT( InputBandConfig );
1732
1733        /* Is the parser number within range? */
1734        if( BandNum > hXpt->MaxInputBands )
1735        {
1736                /* Bad parser number. Complain. */
1737                BDBG_ERR(( "BandNum %lu is out of range!", BandNum ));
1738                ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
1739        }
1740        else
1741        {
1742                /* The parser config registers are at consecutive addresses. */
1743                RegAddr =  BCHP_XPT_FE_IB0_CTRL + ( BandNum * IB_REG_STEPSIZE );
1744                Reg = BREG_Read32( hXpt->hRegister, RegAddr );
1745               
1746                /* Clear all the bits we are about to change. */
1747                Reg &= ~(
1748                        BCHP_MASK( XPT_FE_IB0_CTRL, IB_PARALLEL_INPUT_SEL ) |
1749                        BCHP_MASK( XPT_FE_IB0_CTRL, IB_CLOCK_POL_SEL ) |
1750                        BCHP_MASK( XPT_FE_IB0_CTRL, IB_SYNC_POL_SEL ) |
1751                        BCHP_MASK( XPT_FE_IB0_CTRL, IB_DATA_POL_SEL ) |
1752                        BCHP_MASK( XPT_FE_IB0_CTRL, IB_VALID_POL_SEL ) |
1753                        BCHP_MASK( XPT_FE_IB0_CTRL, IB_FORCE_VALID ) |
1754                        BCHP_MASK( XPT_FE_IB0_CTRL, IB_SYNC_DETECT_EN ) |
1755                        BCHP_MASK( XPT_FE_IB0_CTRL, IB_LSB_FIRST ) |
1756                        BCHP_MASK( XPT_FE_IB0_CTRL, IB_USE_SYNC_AS_VALID ) |
1757                        BCHP_MASK( XPT_FE_IB0_CTRL, IB_ERROR_POL_SEL ) |
1758                        BCHP_MASK( XPT_FE_IB0_CTRL, IB_ERROR_INPUT_EN ) |
1759                        BCHP_MASK( XPT_FE_IB0_CTRL, IB_PKT_LENGTH ) 
1760                );
1761
1762                /* Only band 4 has parallel input support. */
1763                if( BandNum == 4 )
1764                        ParallelInputEn = InputBandConfig->ParallelInputSel == true ? 1 : 0;
1765                else
1766                {
1767                        if( InputBandConfig->ParallelInputSel == true )
1768                        {
1769                                BDBG_ERR(( "Parallel input is not supported on IB %u", BandNum ));
1770                                goto Done;
1771                        }
1772                }
1773               
1774       
1775                /* Now set the new values. */
1776                Reg |= (       
1777                        BCHP_FIELD_DATA( XPT_FE_IB0_CTRL, IB_PARALLEL_INPUT_SEL, ParallelInputEn ) |
1778
1779                        BCHP_FIELD_DATA( XPT_FE_IB0_CTRL, IB_CLOCK_POL_SEL, 
1780                                InputBandConfig->ClockPolSel == BXPT_Polarity_eActiveLow ? 1 : 0 ) |
1781
1782                        BCHP_FIELD_DATA( XPT_FE_IB0_CTRL, IB_SYNC_POL_SEL, 
1783                                InputBandConfig->SyncPolSel == BXPT_Polarity_eActiveLow ? 1 : 0 ) |
1784
1785                        BCHP_FIELD_DATA( XPT_FE_IB0_CTRL, IB_DATA_POL_SEL, 
1786                                InputBandConfig->DataPolSel == BXPT_Polarity_eActiveLow ? 1 : 0 ) |
1787
1788                        BCHP_FIELD_DATA( XPT_FE_IB0_CTRL, IB_VALID_POL_SEL, 
1789                                InputBandConfig->ValidPolSel == BXPT_Polarity_eActiveLow ? 1 : 0 ) |
1790
1791                        BCHP_FIELD_DATA( XPT_FE_IB0_CTRL, IB_FORCE_VALID, 
1792                                InputBandConfig->ForceValid == true ? 1 : 0 ) |
1793
1794                        BCHP_FIELD_DATA( XPT_FE_IB0_CTRL, IB_SYNC_DETECT_EN, 
1795                                InputBandConfig->SyncDetectEn == true ? 1 : 0 ) |
1796
1797                        BCHP_FIELD_DATA( XPT_FE_IB0_CTRL, IB_LSB_FIRST, 
1798                                InputBandConfig->LsbFirst == true ? 1 : 0 ) |
1799
1800                        BCHP_FIELD_DATA( XPT_FE_IB0_CTRL, IB_USE_SYNC_AS_VALID, 
1801                                InputBandConfig->UseSyncAsValid == true ? 1 : 0 ) |
1802
1803                        BCHP_FIELD_DATA( XPT_FE_IB0_CTRL, IB_ERROR_POL_SEL, 
1804                                InputBandConfig->ErrorPolSel == BXPT_Polarity_eActiveLow ? 1 : 0 ) |
1805
1806                        BCHP_FIELD_DATA( XPT_FE_IB0_CTRL, IB_ERROR_INPUT_EN, 
1807                                InputBandConfig->EnableErrorInput == true ? 1 : 0 ) |
1808
1809                        BCHP_FIELD_DATA( XPT_FE_IB0_CTRL, IB_PKT_LENGTH, InputBandConfig->IbPktLength ) 
1810                );
1811
1812                BREG_Write32( hXpt->hRegister, RegAddr, Reg );
1813        }
1814
1815        Done:
1816
1817        return( ExitCode );
1818}
1819
1820BERR_Code BXPT_ParserAllPassMode( 
1821        BXPT_Handle hXpt,       /* [in] Handle for the transport to access. */
1822        unsigned int ParserNum,                                         /* [in] Which input band to access. */
1823        bool AllPass            /* [in] All-pass enabled if true, or not if false. */
1824        )
1825{
1826        uint32_t ParserReg, ParserRegAddr;
1827
1828        BERR_Code ExitCode = BERR_SUCCESS;
1829
1830        BDBG_ASSERT( hXpt );
1831
1832        /* Is the parser number within range? */
1833        if( ParserNum > hXpt->MaxPidParsers )
1834        {
1835                /* Bad parser number. Complain. */
1836                BDBG_ERR(( "ParserNum %lu is out of range!", ParserNum ));
1837                ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
1838        }
1839        else
1840        {
1841                /* The parser config registers are at consecutive addresses. */
1842        ParserRegAddr = BXPT_P_GetParserCtrlRegAddr( hXpt, ParserNum, BCHP_XPT_FE_MINI_PID_PARSER0_CTRL1 );
1843                ParserReg = BREG_Read32( hXpt->hRegister, ParserRegAddr );
1844                ParserReg &= ~(
1845                        BCHP_MASK( XPT_FE_MINI_PID_PARSER0_CTRL1, PARSER_ALL_PASS_CTRL_PRE_MPOD ) 
1846                );
1847
1848        /* Also need to update the Primary and Secondary CC checking: in all-pass mode, the will see the multitude of
1849        ** different IDs as so many CC errors, and drop 'duplicated' PIDs. In all-pass, the PIDs for accepted by parser
1850        ** X are all mapped to PID channel X. 
1851        */ 
1852
1853                /* Now set the new values. */
1854        if( AllPass && false == hXpt->IsParserInAllPass[ ParserNum ] )
1855        {
1856            BXPT_PidChannel_CC_Config AllCcDisabled = { false, false, false, 0 };
1857
1858            ParserReg |= BCHP_FIELD_DATA( XPT_FE_MINI_PID_PARSER0_CTRL1, PARSER_ALL_PASS_CTRL_PRE_MPOD, 1 );
1859            /* RS and XC blockouts are set at BXPT_Open() */
1860
1861            /* Remember the config before entering all-pass. */
1862            BXPT_GetPidChannel_CC_Config( hXpt, ParserNum, &hXpt->CcConfigBeforeAllPass[ ParserNum ] );
1863
1864            /* Now disable the CC checks */
1865            BXPT_SetPidChannel_CC_Config( hXpt, ParserNum, &AllCcDisabled );
1866            hXpt->IsParserInAllPass[ ParserNum ] = true;
1867            BREG_Write32( hXpt->hRegister, ParserRegAddr, ParserReg );
1868        }
1869        else if( false == AllPass && true == hXpt->IsParserInAllPass[ ParserNum ] ) 
1870        {
1871            /* Restore the config we had before entering all-pass. */
1872            BXPT_SetPidChannel_CC_Config( hXpt, ParserNum, &hXpt->CcConfigBeforeAllPass[ ParserNum ] );
1873            hXpt->IsParserInAllPass[ ParserNum ] = false;
1874            BREG_Write32( hXpt->hRegister, ParserRegAddr, ParserReg );
1875        }
1876        }
1877
1878        return( ExitCode );
1879}
1880
1881BERR_Code BXPT_SetParserDataSource( 
1882        BXPT_Handle hXpt,                               /* [in] Handle for this transport */
1883        unsigned int ParserNum,                         /* [in] Which parser to configure */
1884        BXPT_DataSource DataSource,     /* [in] The data source. */
1885        unsigned int WhichSource                        /* [in] Which instance of the source */
1886        )
1887{
1888        uint32_t Reg, RegAddr;
1889
1890        BERR_Code ExitCode = BERR_SUCCESS;
1891
1892        BDBG_ASSERT( hXpt );
1893
1894        /* Is the parser number within range? */
1895        if( ParserNum > hXpt->MaxPidParsers )
1896        {
1897                /* Bad parser number. Complain. */
1898                BDBG_ERR(( "ParserNum %lu is out of range!", ParserNum ));
1899                ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
1900        }
1901        /* Is the requested DataSource valid? */
1902        else if( DataSource == BXPT_DataSource_eInputBand && WhichSource > hXpt->MaxInputBands )
1903        {
1904                /* Requested an input band we dont support. Complain. */
1905                BDBG_ERR(( "WhichSource %lu is out of range!. Not enough input bands.", WhichSource ));
1906                ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
1907        }
1908        else
1909        {
1910                /* The parser config registers are at consecutive addresses. */
1911        RegAddr = BXPT_P_GetParserCtrlRegAddr( hXpt, ParserNum, BCHP_XPT_FE_MINI_PID_PARSER0_CTRL1 );
1912                Reg = BREG_Read32( hXpt->hRegister, RegAddr );
1913               
1914                /* Clear all the bits we are about to change. */
1915                Reg &= ~( 
1916             BCHP_MASK( XPT_FE_MINI_PID_PARSER0_CTRL1, PARSER_INPUT_SEL_MSB ) |
1917             BCHP_MASK( XPT_FE_MINI_PID_PARSER0_CTRL1, PARSER_INPUT_SEL ) 
1918        );
1919
1920                /* Now set the new values. */                                                                                                                                                                                                                   
1921                switch( DataSource )
1922                {
1923                        /* Values for input band selection start at 0 and are sequential. */
1924                        case BXPT_DataSource_eInputBand:
1925                        Reg |= ( BCHP_FIELD_DATA( XPT_FE_MINI_PID_PARSER0_CTRL1, PARSER_INPUT_SEL, WhichSource ) );
1926                        break;
1927
1928                        /* Values for remux feedback selection start at 0x0E and are sequential. */
1929                        case BXPT_DataSource_eRemuxFeedback:
1930            Reg |= ( 
1931                BCHP_FIELD_DATA( XPT_FE_MINI_PID_PARSER0_CTRL1, PARSER_INPUT_SEL_MSB, 1 ) |
1932                BCHP_FIELD_DATA( XPT_FE_MINI_PID_PARSER0_CTRL1, PARSER_INPUT_SEL, WhichSource ) 
1933            );
1934                        break;
1935
1936                        default:
1937                        BDBG_ERR(( "Unsupported DataSource %lu!", ( unsigned long ) DataSource ));
1938                        ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
1939                        break;
1940                } 
1941
1942                BREG_Write32( hXpt->hRegister, RegAddr, Reg );
1943        }
1944
1945        return( ExitCode );
1946}
1947
1948BERR_Code BXPT_GetParserDataSource( 
1949        BXPT_Handle hXpt,                               /* [in] Handle for this transport */
1950        unsigned int ParserNum,                         /* [in] Which parser to configure */
1951        BXPT_DataSource *DataSource,    /* [out] The data source. */
1952        unsigned int *WhichSource                       /* [out] Which instance of the source */
1953        )
1954{
1955        uint32_t Reg, RegAddr, InputBits;
1956
1957        BERR_Code ExitCode = BERR_SUCCESS;
1958
1959        BDBG_ASSERT( hXpt );
1960
1961        /* Is the parser number within range? */
1962        if( ParserNum > hXpt->MaxPidParsers )
1963        {
1964                /* Bad parser number. Complain. */
1965                BDBG_ERR(( "ParserNum %lu is out of range!", ParserNum ));
1966                ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
1967        }
1968        else
1969        {
1970                /* The parser config registers are at consecutive addresses. */
1971        RegAddr = BXPT_P_GetParserCtrlRegAddr( hXpt, ParserNum, BCHP_XPT_FE_MINI_PID_PARSER0_CTRL1 );
1972                Reg = BREG_Read32( hXpt->hRegister, RegAddr );
1973                InputBits = BCHP_GET_FIELD_DATA( Reg, XPT_FE_MINI_PID_PARSER0_CTRL1, PARSER_INPUT_SEL );
1974               
1975                if( InputBits < 0x10)
1976                {
1977                        *DataSource     = BXPT_DataSource_eInputBand;
1978                        *WhichSource = InputBits;
1979                }
1980                else if( InputBits >= 0x10 )
1981                {
1982                        #if BXPT_HAS_REMUX
1983                                *DataSource     = BXPT_DataSource_eRemuxFeedback;
1984                                *WhichSource = InputBits - 0x10;
1985                        #else
1986                                BDBG_ERR(( "DataSource %lu is out of range!", InputBits ));
1987                                ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
1988                        #endif
1989                }
1990        }
1991
1992        return( ExitCode );
1993}
1994
1995BERR_Code BXPT_SetParserEnable( 
1996        BXPT_Handle hXpt,                               /* [in] Handle for this transport */
1997        unsigned int ParserNum,                         /* [in] Which parser to configure */
1998        bool Enable                                     /* [in] Parser enabled if true, disabled if false. */
1999        )
2000{
2001        uint32_t Reg, RegAddr;
2002
2003        BERR_Code ExitCode = BERR_SUCCESS;
2004
2005#ifdef BCHP_PWR_RESOURCE_XPT_PARSER
2006        unsigned wasEnabled;
2007#endif
2008
2009        BDBG_ASSERT( hXpt );
2010
2011        /* Is the parser number within range? */
2012        if( ParserNum > hXpt->MaxPidParsers )
2013        {
2014                /* Bad parser number. Complain. */
2015                BDBG_ERR(( "ParserNum %lu is out of range!", ParserNum ));
2016                ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
2017        }
2018        else
2019        {
2020                /* The parser config registers are at consecutive addresses. */
2021                RegAddr = BXPT_P_GetParserCtrlRegAddr( hXpt, ParserNum, BCHP_XPT_FE_MINI_PID_PARSER0_CTRL1 );
2022                Reg = BREG_Read32( hXpt->hRegister, RegAddr );
2023               
2024#ifdef BCHP_PWR_RESOURCE_XPT_PARSER
2025                wasEnabled = BCHP_GET_FIELD_DATA(Reg, XPT_FE_MINI_PID_PARSER0_CTRL1, PARSER_ENABLE);
2026                /* only change refcnt if changing state */
2027                if (!wasEnabled && Enable) {
2028                        BCHP_PWR_AcquireResource(hXpt->hChip, BCHP_PWR_RESOURCE_XPT_PARSER);
2029                }
2030#endif
2031
2032                /* Clear all the bits we are about to change. */
2033                Reg &= ~( BCHP_MASK( XPT_FE_MINI_PID_PARSER0_CTRL1, PARSER_ENABLE ) );
2034                Reg |= ( BCHP_FIELD_DATA( XPT_FE_MINI_PID_PARSER0_CTRL1, PARSER_ENABLE, Enable == true ? 1 : 0 ) );
2035                BREG_Write32( hXpt->hRegister, RegAddr, Reg );
2036
2037#ifdef BCHP_PWR_RESOURCE_XPT_PARSER
2038                if (wasEnabled && !Enable) {
2039                        BCHP_PWR_ReleaseResource(hXpt->hChip, BCHP_PWR_RESOURCE_XPT_PARSER);
2040                }
2041#endif
2042        }
2043
2044        return( ExitCode );
2045}
2046
2047#endif
2048
2049BERR_Code BXPT_EnablePidChannel( 
2050        BXPT_Handle hXpt,                               /* [in] Handle for this transport */
2051        unsigned int PidChannelNum                      /* [in] Which PID channel. */
2052        )
2053{
2054        BERR_Code ExitCode = BERR_SUCCESS;
2055
2056        BDBG_ASSERT( hXpt );
2057
2058        /* Sanity check on the arguments. */
2059        if( PidChannelNum > hXpt->MaxPidChannels )
2060        {
2061                /* Bad PID channel number. Complain. */
2062                BDBG_ERR(( "PidChannelNum %lu is out of range!", ( unsigned long ) PidChannelNum ));
2063                ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
2064        }
2065    else if( IsPidDuplicated( hXpt, PidChannelNum ) )
2066    {
2067                ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
2068    } 
2069        else
2070        {
2071        BXPT_P_EnablePidChannel( hXpt, PidChannelNum );
2072        }
2073
2074        return( ExitCode );
2075}
2076
2077BERR_Code BXPT_P_EnablePidChannel(
2078        BXPT_Handle hXpt,                               /* [in] Handle for this transport */
2079        unsigned int PidChannelNum                      /* [in] Which PID channel. */
2080    )
2081{ 
2082        BERR_Code ExitCode = BERR_SUCCESS;
2083
2084#ifdef ENABLE_PLAYBACK_MUX
2085        /*gain access to the pid table*/
2086        BKNI_EnterCriticalSection();
2087#endif /*ENABLE_PLAYBACK_MUX*/
2088
2089    hXpt->PidChannelTable[ PidChannelNum ].EnableRequested = true;
2090
2091    if( PidChannelHasDestination( hXpt, PidChannelNum ) )
2092        SetChannelEnable( hXpt, PidChannelNum, true );
2093
2094#ifdef ENABLE_PLAYBACK_MUX
2095        /*leave pid table protected area*/
2096        BKNI_LeaveCriticalSection();
2097#endif /*ENABLE_PLAYBACK_MUX*/
2098
2099        return( ExitCode );
2100}
2101
2102BERR_Code BXPT_DisablePidChannel( 
2103        BXPT_Handle hXpt,                               /* [in] Handle for this transport */
2104        unsigned int PidChannelNum                      /* [in] Which PID channel. */
2105        )
2106{
2107        BERR_Code ExitCode = BERR_SUCCESS;
2108
2109        BDBG_ASSERT( hXpt );
2110
2111        /* Sanity check on the arguments. */
2112        if( PidChannelNum > hXpt->MaxPidChannels )
2113        {
2114                /* Bad PID channel number. Complain. */
2115                BDBG_ERR(( "PidChannelNum %lu is out of range!", ( unsigned long ) PidChannelNum ));
2116                ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
2117        }
2118        else                                                   
2119        {
2120#ifdef ENABLE_PLAYBACK_MUX
2121                /*gain access to the pid table*/
2122                BKNI_EnterCriticalSection();
2123#endif /*ENABLE_PLAYBACK_MUX*/
2124
2125                hXpt->PidChannelTable[ PidChannelNum ].EnableRequested = false;
2126/* PR 55511: Need to allow nexus to shut off the PID channel even when there are still consumers attached.     
2127So, don't do the destination check before calling SetChannelEnable().
2128                if( PidChannelHasDestination( hXpt, PidChannelNum ) == false )     */
2129                        SetChannelEnable( hXpt, PidChannelNum, false );
2130
2131#ifdef ENABLE_PLAYBACK_MUX
2132                /*leave pid table protected area*/
2133                BKNI_LeaveCriticalSection();
2134#endif /*ENABLE_PLAYBACK_MUX*/
2135        }
2136
2137        return( ExitCode );
2138}
2139
2140BERR_Code BXPT_AllocPidChannel( 
2141        BXPT_Handle hXpt,                       /* [in] Handle for this transport */
2142        bool NeedMessageBuffer,         /* [in] Is a message buffer required? */
2143        unsigned int *PidChannelNum     /* [out] The allocated channel number. */
2144        )
2145{
2146        unsigned int i = 0;
2147
2148        BERR_Code ExitCode = BERR_SUCCESS;
2149
2150        BDBG_ASSERT( hXpt );
2151
2152        /* Search for channels with buffers, if thats what they asked for. */
2153        if( NeedMessageBuffer == true )
2154        {
2155                for( i = 0; i < hXpt->MaxPidChannels; i++ )
2156                {
2157                        if( hXpt->PidChannelTable[ i ].IsAllocated == false 
2158                        && hXpt->PidChannelTable[ i ].HasMessageBuffer ==  true )
2159                        {
2160                                hXpt->PidChannelTable[ i ].IsAllocated = true;
2161                                break;
2162                        }
2163                }
2164        }
2165        else
2166        {
2167                /* Otherwise, grab the first free channel we find. */
2168                for( i= 0; i < hXpt->MaxPidChannels; i++ )
2169                {
2170                        if( hXpt->PidChannelTable[ i ].IsAllocated == false )
2171                        {
2172                                hXpt->PidChannelTable[ i ].IsAllocated = true;
2173                                break;
2174                        }
2175                }
2176        }
2177
2178        *PidChannelNum = i;
2179
2180        return( ExitCode );
2181}
2182
2183BERR_Code BXPT_ConfigurePidChannel( 
2184        BXPT_Handle hXpt,                       /* [in] Handle for this transport */
2185        unsigned int PidChannelNum,     /* [in] Which channel to configure. */
2186        unsigned int Pid,                               /* [in] PID to use. */
2187        unsigned int Band                               /* [in] The parser band to use. */
2188        )
2189{
2190        uint32_t Reg, RegAddr;
2191
2192        BERR_Code ExitCode = BERR_SUCCESS;
2193
2194        BDBG_ASSERT( hXpt );
2195    BDBG_MSG(( "BXPT_ConfigurePidChannel: PidChannel %u, PID 0x%04X, %s parser %u", 
2196               PidChannelNum, Pid, BXPT_P_IS_PB( Band ) ? "Playback" : "Live", Band & 0x7FFF));
2197
2198        if( Pid >= 0x2000 )
2199        {
2200                /* Bad PID. Complain. */
2201                BDBG_ERR(( "Pid %lu is out of range!", ( unsigned long ) Pid ));
2202                ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
2203        }
2204        else if( PidChannelNum > hXpt->MaxPidChannels )
2205        {
2206                /* Bad PID channel number. Complain. */
2207                BDBG_ERR(( "PidChannelNum %lu is out of range!", ( unsigned long ) PidChannelNum ));
2208                ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
2209        }
2210        else                                                                     
2211        {
2212#if BXPT_HAS_IB_PID_PARSERS
2213                unsigned FeSel = 0;
2214                unsigned OldFeSel = 255;
2215        unsigned OldPid = 0x2000;
2216        unsigned OldBand = 0x2000;     /* Never have this many parser bands. */
2217
2218                PidChannelTableEntry *Entry = &hXpt->PidChannelTable[ PidChannelNum ];
2219
2220#ifdef ENABLE_PLAYBACK_MUX
2221                /*gain access to the pid table*/
2222                BKNI_EnterCriticalSection();
2223#endif /*ENABLE_PLAYBACK_MUX*/
2224
2225                Entry->Pid = Pid;
2226                Entry->Band = Band;
2227                Entry->IsAllocated = true;
2228
2229
2230                RegAddr = BCHP_XPT_FE_PID_TABLE_i_ARRAY_BASE + ( PidChannelNum * PID_CHNL_STEPSIZE );
2231                Reg = BREG_Read32( hXpt->hRegister, RegAddr );
2232
2233                if( BXPT_P_IS_PB( Band ) )
2234                {
2235                        BXPT_P_CLEAR_PB_FLAG( Band );   /* Remove the PB parser flag. */
2236                        FeSel = 1;
2237                }
2238
2239#if BXPT_SW7425_1323_WORKAROUND
2240        Entry->IsPb = FeSel;
2241#endif
2242             
2243        OldFeSel = BCHP_GET_FIELD_DATA( Reg, XPT_FE_PID_TABLE_i, PLAYBACK_FE_SEL );
2244        OldBand = BCHP_GET_FIELD_DATA( Reg, XPT_FE_PID_TABLE_i, INPUT_BAND_PARSER_PID_CHANNEL_INPUT_SELECT );
2245
2246#if BXPT_HAS_DIRECTV_SUPPORT
2247                /* Need to preserve the HD filter bits, if enabled */
2248                if( BCHP_GET_FIELD_DATA( Reg, XPT_FE_PID_TABLE_i, ENABLE_HD_FILTER ) )
2249                {
2250            OldPid = BCHP_GET_FIELD_DATA( Reg, XPT_FE_PID_TABLE_i, HD_FILT_EN_PID_CHANNEL_SCID );
2251
2252                        Reg &= ~( 
2253                                BCHP_MASK( XPT_FE_PID_TABLE_i, PLAYBACK_FE_SEL ) |
2254                                BCHP_MASK( XPT_FE_PID_TABLE_i, INPUT_BAND_PARSER_PID_CHANNEL_INPUT_SELECT ) |
2255                                BCHP_MASK( XPT_FE_PID_TABLE_i, HD_FILT_EN_PID_CHANNEL_SCID ) 
2256                        );
2257                 
2258                        Reg |= ( 
2259                                BCHP_FIELD_DATA( XPT_FE_PID_TABLE_i, PLAYBACK_FE_SEL, FeSel ) |
2260                                BCHP_FIELD_DATA( XPT_FE_PID_TABLE_i, INPUT_BAND_PARSER_PID_CHANNEL_INPUT_SELECT, Band ) |
2261                                BCHP_FIELD_DATA( XPT_FE_PID_TABLE_i, HD_FILT_EN_PID_CHANNEL_SCID, Pid ) 
2262                        );
2263                }
2264                else
2265                {
2266            OldPid = BCHP_GET_FIELD_DATA( Reg, XPT_FE_PID_TABLE_i, HD_FILT_DIS_PID_CHANNEL_PID );
2267
2268                        Reg &= ~( 
2269                                BCHP_MASK( XPT_FE_PID_TABLE_i, PLAYBACK_FE_SEL ) |
2270                                BCHP_MASK( XPT_FE_PID_TABLE_i, INPUT_BAND_PARSER_PID_CHANNEL_INPUT_SELECT ) |
2271                                BCHP_MASK( XPT_FE_PID_TABLE_i, HD_FILT_DIS_PID_CHANNEL_PID ) 
2272                        );
2273                 
2274                        Reg |= ( 
2275                                BCHP_FIELD_DATA( XPT_FE_PID_TABLE_i, PLAYBACK_FE_SEL, FeSel ) |
2276                                BCHP_FIELD_DATA( XPT_FE_PID_TABLE_i, INPUT_BAND_PARSER_PID_CHANNEL_INPUT_SELECT, Band ) |
2277                                BCHP_FIELD_DATA( XPT_FE_PID_TABLE_i, HD_FILT_DIS_PID_CHANNEL_PID, Pid ) 
2278                        );
2279                }
2280#else
2281        OldPid = BCHP_GET_FIELD_DATA( Reg, XPT_FE_PID_TABLE_i, PID_CHANNEL_PID );
2282
2283                Reg &= ~( 
2284                        BCHP_MASK( XPT_FE_PID_TABLE_i, PLAYBACK_FE_SEL ) |
2285                        BCHP_MASK( XPT_FE_PID_TABLE_i, INPUT_BAND_PARSER_PID_CHANNEL_INPUT_SELECT ) |
2286                        BCHP_MASK( XPT_FE_PID_TABLE_i, PID_CHANNEL_PID ) 
2287                );
2288         
2289                Reg |= ( 
2290                        BCHP_FIELD_DATA( XPT_FE_PID_TABLE_i, PLAYBACK_FE_SEL, FeSel ) |
2291                        BCHP_FIELD_DATA( XPT_FE_PID_TABLE_i, INPUT_BAND_PARSER_PID_CHANNEL_INPUT_SELECT, Band ) |
2292                        BCHP_FIELD_DATA( XPT_FE_PID_TABLE_i, PID_CHANNEL_PID, Pid ) 
2293                );
2294#endif
2295
2296        /* Write to the PID table ONLY if the configuration has changed. */
2297        if( OldFeSel != FeSel || OldBand != Band || OldPid != Pid )
2298        {
2299                BREG_Write32( hXpt->hRegister, RegAddr, Reg );
2300        }
2301
2302                Entry->IsPidChannelConfigured = true;
2303#ifdef ENABLE_PLAYBACK_MUX
2304                /*leave pid table protected area*/
2305                BKNI_LeaveCriticalSection();
2306#endif /*ENABLE_PLAYBACK_MUX*/
2307
2308#else /* BXPT_HAS_IB_PID_PARSERS */
2309                PidChannelTableEntry *Entry = &hXpt->PidChannelTable[ PidChannelNum ];
2310                RegAddr = BCHP_XPT_FE_PID_TABLE_i_ARRAY_BASE + ( PidChannelNum * PID_CHNL_STEPSIZE );
2311                Reg = BREG_Read32( hXpt->hRegister, RegAddr );
2312
2313#if (BCHP_CHIP == 7630 && BCHP_VER >= BCHP_VER_B2 )
2314                Reg &= ~( 
2315                        BCHP_MASK( XPT_FE_PID_TABLE_i, PLAYBACK_FE_SEL ) |
2316                        BCHP_MASK( XPT_FE_PID_TABLE_i, PID_CHANNEL_INPUT_SELECT ) |
2317                        BCHP_MASK( XPT_FE_PID_TABLE_i, HD_FILT_DIS_PID_CHANNEL_PID ) 
2318                );
2319                Reg |= ( 
2320                        BCHP_FIELD_DATA( XPT_FE_PID_TABLE_i, PLAYBACK_FE_SEL, 1 ) |
2321                        BCHP_FIELD_DATA( XPT_FE_PID_TABLE_i, PID_CHANNEL_INPUT_SELECT, Band ) |
2322                        BCHP_FIELD_DATA( XPT_FE_PID_TABLE_i, HD_FILT_DIS_PID_CHANNEL_PID, Pid ) 
2323                );
2324#else
2325                Reg &= ~( 
2326                        BCHP_MASK( XPT_FE_PID_TABLE_i, PLAYBACK_FE_SEL ) |
2327                        BCHP_MASK( XPT_FE_PID_TABLE_i, INPUT_BAND_PARSER_PID_CHANNEL_INPUT_SELECT ) |
2328                        BCHP_MASK( XPT_FE_PID_TABLE_i, HD_FILT_DIS_PID_CHANNEL_PID ) 
2329                );
2330                Reg |= ( 
2331                        BCHP_FIELD_DATA( XPT_FE_PID_TABLE_i, PLAYBACK_FE_SEL, 1 ) |
2332                        BCHP_FIELD_DATA( XPT_FE_PID_TABLE_i, INPUT_BAND_PARSER_PID_CHANNEL_INPUT_SELECT, Band ) |
2333                        BCHP_FIELD_DATA( XPT_FE_PID_TABLE_i, HD_FILT_DIS_PID_CHANNEL_PID, Pid ) 
2334                );
2335#endif
2336
2337                BREG_Write32( hXpt->hRegister, RegAddr, Reg );
2338
2339#if BXPT_SW7425_1323_WORKAROUND
2340        Entry->IsPb = true;
2341#endif
2342                Entry->IsPidChannelConfigured = true;
2343#endif /* BXPT_HAS_IB_PID_PARSERS */
2344        }
2345
2346        return( ExitCode );
2347}
2348
2349#ifdef ENABLE_PLAYBACK_MUX
2350
2351BERR_Code BXPT_SetPidChannelSwitched(
2352        BXPT_Handle hXpt,                               /* [in] Handle for this transport */
2353        unsigned int PidChannelNum,                     /* [in] Which PID channel. */
2354        bool IsSwitched
2355        )
2356{
2357        BERR_Code ExitCode = BERR_SUCCESS;
2358
2359    /*gain access to the pid table*/
2360    BKNI_EnterCriticalSection();
2361   
2362    ExitCode = BXPT_SetPidChannelSwitched_isr( hXpt, PidChannelNum, IsSwitched );
2363   
2364    /*leave pid table protected area*/
2365    BKNI_LeaveCriticalSection();
2366
2367    return ExitCode;
2368}
2369
2370BERR_Code BXPT_SetPidChannelSwitched_isr(
2371        BXPT_Handle hXpt,                               /* [in] Handle for this transport */
2372        unsigned int PidChannelNum,                     /* [in] Which PID channel. */
2373        bool IsSwitched
2374        )
2375{
2376        uint32_t Reg, RegAddr;
2377        BERR_Code ExitCode = BERR_SUCCESS;
2378
2379        BDBG_ASSERT( hXpt );
2380
2381        /* Sanity check on the arguments. */
2382        if( PidChannelNum > hXpt->MaxPidChannels )
2383        {
2384                /* Bad parser band number. Complain. */
2385                BDBG_ERR(( "PidChannelNum %lu is out of range!", ( unsigned long ) PidChannelNum ));
2386                ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
2387        }
2388        else
2389        {
2390                /* Set the PID channels enable bit. */
2391                RegAddr = BCHP_XPT_FE_PID_TABLE_i_ARRAY_BASE + ( PidChannelNum * PID_CHNL_STEPSIZE );
2392                Reg = BREG_Read32( hXpt->hRegister, RegAddr );
2393
2394                if(IsSwitched)
2395                {
2396                        /*ignore pid version so our transport buffers aren't flushed*/
2397                        Reg |= BCHP_FIELD_DATA( XPT_FE_PID_TABLE_i, IGNORE_PID_VERSION, 1 );
2398                }
2399                else
2400                {
2401                        /*look at pid versions to behave like normal*/
2402                        Reg &= ~BCHP_MASK( XPT_FE_PID_TABLE_i, IGNORE_PID_VERSION );
2403                }
2404
2405                BREG_Write32( hXpt->hRegister, RegAddr, Reg );
2406        }
2407
2408        return(ExitCode);
2409}
2410
2411bool BXPT_SwitchPidChannel(
2412        BXPT_Handle hXpt,                               /* [in] Handle for this transport */
2413        unsigned int PidChannelNum,                     /* [in] Which PID channel. */
2414        bool EnableIt
2415        )
2416{
2417        uint32_t Reg, RegAddr;
2418
2419        bool result = true;
2420
2421        BDBG_ASSERT( hXpt );
2422
2423        /* Sanity check on the arguments. */
2424        if( PidChannelNum > hXpt->MaxPidChannels )
2425        {
2426                /* Bad parser band number. Complain. */
2427                BDBG_ERR(( "PidChannelNum %lu is out of range!", ( unsigned long ) PidChannelNum ));
2428                return(false);
2429        }
2430        else if(!hXpt->PidChannelTable[PidChannelNum].IsAllocated)
2431        {
2432                return(false);
2433        }
2434
2435        /*gain access to the pid table*/
2436        BKNI_EnterCriticalSection();
2437
2438        /*set whether the muxed pid is enabled or not*/
2439        hXpt->PidChannelTable[PidChannelNum].MuxEnable = EnableIt;
2440
2441#if BXPT_SW7425_1323_WORKAROUND
2442        hXpt->PidChannelTable[PidChannelNum].IsEnabled = EnableIt;
2443#endif
2444
2445        /* Set the PID channels enable bit. */
2446        RegAddr = BCHP_XPT_FE_PID_TABLE_i_ARRAY_BASE + ( PidChannelNum * PID_CHNL_STEPSIZE );
2447        Reg = BREG_Read32( hXpt->hRegister, RegAddr );
2448        Reg &= ~BCHP_MASK( XPT_FE_PID_TABLE_i, PID_CHANNEL_ENABLE );
2449
2450        /*check if we're supposed to enable the channel*/
2451        if(EnableIt)
2452        {
2453                /*need to enable the channel*/
2454                if(!hXpt->PidChannelTable[PidChannelNum].EnableRequested)
2455                {
2456                        result = false;
2457                }
2458                else if(!PidChannelHasDestination( hXpt, PidChannelNum ))
2459                {
2460                        result = false;
2461                }
2462                else
2463                {
2464                        Reg |= BCHP_FIELD_DATA( XPT_FE_PID_TABLE_i, PID_CHANNEL_ENABLE, 1 );
2465                }
2466        }
2467
2468        BREG_Write32( hXpt->hRegister, RegAddr, Reg );
2469
2470        /*leave pid table protected area*/
2471        BKNI_LeaveCriticalSection();
2472
2473        return(result);
2474}
2475
2476bool BXPT_SwitchPidChannelISR(
2477        BXPT_Handle hXpt,                                       /* [in] Handle for this transport */
2478        unsigned int PidChannelNum,                     /* [in] Which PID channel. */
2479        bool EnableIt
2480        )
2481{
2482        uint32_t Reg, RegAddr;
2483        bool result = true;
2484
2485        BDBG_ASSERT( hXpt );
2486
2487        /* Sanity check on the arguments. */
2488        if( PidChannelNum > hXpt->MaxPidChannels )
2489        {
2490                /* Bad parser band number. Complain. */
2491                BDBG_ERR(( "PidChannelNum %lu is out of range!", ( unsigned long ) PidChannelNum ));
2492                return(false);
2493        }
2494        else if(!hXpt->PidChannelTable[PidChannelNum].IsAllocated)
2495        {
2496                return(false);
2497        }
2498
2499        /*set whether the muxed pid is enabled or not*/
2500        hXpt->PidChannelTable[PidChannelNum].MuxEnable = EnableIt;
2501
2502        /* Set the PID channels enable bit. */
2503        RegAddr = BCHP_XPT_FE_PID_TABLE_i_ARRAY_BASE + ( PidChannelNum * PID_CHNL_STEPSIZE );
2504        Reg = BREG_Read32( hXpt->hRegister, RegAddr );
2505        Reg &= ~BCHP_MASK( XPT_FE_PID_TABLE_i, PID_CHANNEL_ENABLE );
2506
2507#if BXPT_SW7425_1323_WORKAROUND
2508        hXpt->PidChannelTable[PidChannelNum].IsEnabled = EnableIt;
2509#endif
2510
2511        /*check if we're supposed to enable the channel*/
2512        if(EnableIt)
2513        {
2514                /*need to enable the channel*/
2515                if(!hXpt->PidChannelTable[PidChannelNum].EnableRequested)
2516                {
2517                        result = false;
2518                }
2519                else if(!PidChannelHasDestination( hXpt, PidChannelNum ))
2520                {
2521                        result = false;
2522                }
2523                else
2524                {
2525                        Reg |= BCHP_FIELD_DATA( XPT_FE_PID_TABLE_i, PID_CHANNEL_ENABLE, 1 );
2526                }
2527        }
2528       
2529    BREG_Write32( hXpt->hRegister, RegAddr, Reg );
2530
2531        return(result);
2532}
2533
2534BERR_Code BXPT_SetNumPlaybackMux(
2535        BXPT_Handle hXpt,                               /* [in] Handle for this transport */
2536        unsigned int Num                                /* [in] Number of playback mux blocks*/
2537        )
2538{
2539        BDBG_ASSERT( hXpt );
2540
2541        /* Sanity check on the arguments. The 'Num' argument is 1-based, not 0-based like everything else. */
2542        if( Num > BXPT_NUM_PLAYBACKS )
2543        {
2544                /* Bad parser band number. Complain. */
2545                BDBG_ERR(( "Num %u is out of range!", Num ));
2546                return(BERR_INVALID_PARAMETER);
2547        }
2548
2549        hXpt->NumPlaybackMuxes = Num;
2550
2551        return(BERR_SUCCESS);
2552}
2553
2554#endif /*ENABLE_PLAYBACK_MUX*/
2555 
2556BERR_Code BXPT_GetPidChannelConfig(
2557        BXPT_Handle hXpt,                           /* [in] Handle for this transport */
2558        unsigned int PidChannelNum,     /* [in] Which channel to get config for. */
2559        unsigned int *Pid,                              /* [out] The PID its using. */
2560        unsigned int *Band,                             /* [out] The parser band the channel is mapped to. */
2561    bool *IsPlayback                /* [out] true if band is a playback parser, false if input */
2562    )
2563{
2564        BERR_Code ExitCode = BERR_SUCCESS;
2565
2566        BDBG_ASSERT( hXpt );
2567        BDBG_ASSERT( Pid );
2568        BDBG_ASSERT( Band );
2569
2570        if( PidChannelNum > hXpt->MaxPidChannels )
2571        {
2572                /* Bad PID channel number. Complain. */
2573                BDBG_ERR(( "PidChannelNum %lu is out of range!", ( unsigned long ) PidChannelNum ));
2574                ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
2575        }
2576        else
2577        {
2578            uint32_t Reg, RegAddr;
2579   
2580                RegAddr = BCHP_XPT_FE_PID_TABLE_i_ARRAY_BASE + ( PidChannelNum * PID_CHNL_STEPSIZE );
2581                Reg = BREG_Read32( hXpt->hRegister, RegAddr );
2582        *IsPlayback = BCHP_GET_FIELD_DATA( Reg, XPT_FE_PID_TABLE_i, PLAYBACK_FE_SEL ) ? true : false;
2583        *Band = (unsigned int) BCHP_GET_FIELD_DATA( Reg, XPT_FE_PID_TABLE_i, INPUT_BAND_PARSER_PID_CHANNEL_INPUT_SELECT );
2584
2585                if( BCHP_GET_FIELD_DATA( Reg, XPT_FE_PID_TABLE_i, ENABLE_HD_FILTER ) )
2586                {
2587            *Pid = (unsigned int) BCHP_GET_FIELD_DATA( Reg, XPT_FE_PID_TABLE_i, HD_FILT_EN_PID_CHANNEL_SCID );
2588                }
2589                else
2590                {
2591            *Pid = (unsigned int) BCHP_GET_FIELD_DATA( Reg, XPT_FE_PID_TABLE_i, HD_FILT_DIS_PID_CHANNEL_PID );
2592                }
2593        }       
2594       
2595    return ExitCode;                                                             
2596}
2597
2598BERR_Code BXPT_FreePidChannel( 
2599        BXPT_Handle hXpt,                       /* [in] Handle for this transport */
2600        unsigned int PidChannelNum              /* [in] PID channel to free up. */
2601        )
2602{
2603        BERR_Code ExitCode = BERR_SUCCESS;
2604
2605        BDBG_ASSERT( hXpt );
2606
2607        /* Sanity check on the arguments. */
2608        if( PidChannelNum > hXpt->MaxPidChannels )
2609        {
2610                /* Bad parser band number. Complain. */
2611                BDBG_ERR(( "PidChannelNum %lu is out of range!", ( unsigned long ) PidChannelNum ));
2612                ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
2613        }
2614        else
2615        {
2616                /* Must be done BEFORE disabling the PID channel. */
2617                BXPT_P_ClearAllPidChannelDestinations( hXpt, PidChannelNum );
2618
2619                BXPT_DisablePidChannel( hXpt, PidChannelNum );
2620                hXpt->PidChannelTable[ PidChannelNum ].IsAllocated = false;
2621                hXpt->PidChannelTable[ PidChannelNum ].Pid = 0x2000;
2622                hXpt->PidChannelTable[ PidChannelNum ].IsPidChannelConfigured = false;
2623#ifdef ENABLE_PLAYBACK_MUX
2624                hXpt->PidChannelTable[ PidChannelNum ].MuxEnable = false;
2625                hXpt->PidChannelTable[ PidChannelNum ].HasDestination = false;
2626#endif /*ENABLE_PLAYBACK_MUX*/
2627        }
2628
2629        return( ExitCode );
2630}
2631
2632void BXPT_FreeAllPidChannels( 
2633        BXPT_Handle hXpt                        /* [in] Handle for this transport */
2634        )
2635{
2636        unsigned int i;
2637
2638        BDBG_ASSERT( hXpt );
2639
2640        for( i= 0; i < hXpt->MaxPidChannels; i++ )
2641        {
2642                /* Must be done BEFORE disabling the PID channel. */
2643                BXPT_P_ClearAllPidChannelDestinations( hXpt, i );
2644
2645                BXPT_DisablePidChannel( hXpt, i );
2646                hXpt->PidChannelTable[ i ].IsAllocated = false;
2647                hXpt->PidChannelTable[ i ].Pid = 0x2000;
2648                hXpt->PidChannelTable[ i ].IsPidChannelConfigured = false;
2649#ifdef ENABLE_PLAYBACK_MUX
2650                hXpt->PidChannelTable[ i ].MuxEnable = false;
2651                hXpt->PidChannelTable[ i ].HasDestination = false;
2652#endif /*ENABLE_PLAYBACK_MUX*/
2653        }
2654}
2655
2656BERR_Code BXPT_RequestPidChannel(
2657        BXPT_Handle hXpt,               /* [Input] Handle for this transport */
2658        unsigned int PidChannelNum      /* [Output] The channel number the user wants. */ 
2659        )
2660{
2661        BERR_Code ExitCode = BERR_SUCCESS;
2662
2663        BDBG_ASSERT( hXpt );
2664
2665        /* Sanity check on the arguments. */
2666        if( PidChannelNum > hXpt->MaxPidChannels )         
2667        {
2668                /* Bad parser band number. Complain. */
2669                BDBG_ERR(( "PidChannelNum %lu is out of range!", ( unsigned long ) PidChannelNum ));
2670                ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
2671        }
2672        else
2673        {
2674                if( hXpt->PidChannelTable[ PidChannelNum ].IsAllocated == false )
2675                        hXpt->PidChannelTable[ PidChannelNum ].IsAllocated = true;             
2676                else
2677                        ExitCode = BXPT_ERR_PID_ALREADY_ALLOCATED;
2678        }
2679
2680        return( ExitCode );
2681}
2682
2683
2684void BXPT_P_ResetTransport( 
2685        BREG_Handle hReg                 
2686        )
2687{
2688        uint32_t Reg;
2689
2690        BDBG_ASSERT( hReg );
2691
2692    BKNI_EnterCriticalSection();
2693
2694    /* Assert the transport core reset */
2695        BREG_Write32( hReg, BCHP_SUN_TOP_CTRL_SW_INIT_0_SET,
2696                             BCHP_SUN_TOP_CTRL_SW_INIT_0_SET_xpt_sw_init_MASK );
2697
2698    /* Now clear the reset. */     
2699        BREG_Write32( hReg, BCHP_SUN_TOP_CTRL_SW_INIT_0_CLEAR, 
2700                             BCHP_SUN_TOP_CTRL_SW_INIT_0_CLEAR_xpt_sw_init_MASK );
2701
2702        Reg = BREG_Read32( hReg, BCHP_SUN_TOP_CTRL_FINAL_SW_INIT_0_MONITOR );
2703        if( BCHP_GET_FIELD_DATA( Reg, SUN_TOP_CTRL_FINAL_SW_INIT_0_MONITOR, xpt_sw_init ) )
2704        {
2705                BDBG_ERR(( "XPT did not leave init state!" ));
2706        }
2707
2708    BKNI_LeaveCriticalSection();
2709}
2710
2711void SetChannelEnable(
2712        BXPT_Handle hXpt,                               /* [in] Handle for this transport */
2713        unsigned int PidChannelNum,                     /* [in] Which PID channel. */
2714        bool EnableIt
2715        )
2716{
2717        uint32_t Reg, RegAddr;
2718
2719#ifdef ENABLE_PLAYBACK_MUX
2720        if(EnableIt && hXpt->PidChannelTable[PidChannelNum].Band > 
2721                BXPT_PB_PARSER((BXPT_NUM_PLAYBACKS - hXpt->NumPlaybackMuxes)))
2722        {
2723                return;
2724        }
2725
2726        /* If the channel is enabled for playback muxing, don't disable it here. BXPT_SwitchPidChannel() will do it instead. */
2727        if( hXpt->PidChannelTable[PidChannelNum].MuxEnable )
2728        {
2729                return;
2730        }
2731#endif /*ENABLE_PLAYBACK_MUX*/
2732
2733#if BXPT_SW7425_1323_WORKAROUND
2734        hXpt->PidChannelTable[PidChannelNum].IsEnabled = EnableIt;
2735#endif
2736
2737        /* Set the PID channels enable bit. */
2738        RegAddr = BCHP_XPT_FE_PID_TABLE_i_ARRAY_BASE + ( PidChannelNum * PID_CHNL_STEPSIZE );
2739        Reg = BREG_Read32( hXpt->hRegister, RegAddr );
2740
2741    /* if the pid channel is already enabled, and request is to enable it again
2742       then make sure that we do not write the PID table register, this will prevent
2743       PID version from changing to a new value hence the buffers will not be flushed
2744       by the XPT HW.This step is imortant to get a glitch free av when record.
2745     */
2746    if((Reg & BCHP_MASK( XPT_FE_PID_TABLE_i, PID_CHANNEL_ENABLE )) && EnableIt)
2747        return;
2748
2749        Reg &= ~BCHP_MASK( XPT_FE_PID_TABLE_i, PID_CHANNEL_ENABLE );
2750        if( EnableIt )
2751        {
2752                Reg |= BCHP_FIELD_DATA( XPT_FE_PID_TABLE_i, PID_CHANNEL_ENABLE, 1 );
2753        }
2754
2755    BREG_Write32( hXpt->hRegister, RegAddr, Reg );
2756}
2757
2758bool PidChannelHasDestination( 
2759        BXPT_Handle hXpt,                           
2760        unsigned int PidChannelNum
2761        )
2762{
2763        uint32_t Reg, RegAddr;
2764
2765        /* Set the PID channels enable bit. */
2766        RegAddr = BCHP_XPT_FE_SPID_TABLE_i_ARRAY_BASE + ( PidChannelNum * SPID_CHNL_STEPSIZE );
2767    Reg = BREG_Read32( hXpt->hRegister, RegAddr );
2768
2769        if( BCHP_GET_FIELD_DATA( Reg, XPT_FE_SPID_TABLE_i, PID_DESTINATION ) )
2770                return true;
2771        else
2772                return false;
2773}
2774
2775BERR_Code BXPT_P_ClearAllPidChannelDestinations( 
2776        BXPT_Handle hXpt,
2777        unsigned int PidChannelNum
2778        )
2779{
2780        uint32_t Reg, RegAddr;
2781
2782        BERR_Code ExitCode = BERR_SUCCESS;
2783
2784#ifdef ENABLE_PLAYBACK_MUX
2785        BKNI_EnterCriticalSection();
2786#endif /*ENABLE_PLAYBACK_MUX*/
2787
2788        /* Disable PID channel */
2789        SetChannelEnable( hXpt, PidChannelNum, false );
2790
2791        RegAddr = BCHP_XPT_FE_SPID_TABLE_i_ARRAY_BASE + ( PidChannelNum * SPID_CHNL_STEPSIZE );
2792        Reg = BREG_Read32( hXpt->hRegister, RegAddr );
2793        Reg &= ~BCHP_MASK( XPT_FE_SPID_TABLE_i, PID_DESTINATION );
2794        BREG_Write32( hXpt->hRegister, RegAddr, Reg );
2795
2796#ifdef ENABLE_PLAYBACK_MUX
2797        /*leave pid table protected area*/
2798        BKNI_LeaveCriticalSection();
2799#endif /*ENABLE_PLAYBACK_MUX*/
2800        return ExitCode;
2801}
2802
2803BERR_Code BXPT_P_SetPidChannelDestination( 
2804        BXPT_Handle hXpt, 
2805        unsigned int PidChannelNum, 
2806        unsigned SelectedDestination,
2807        bool EnableIt
2808        )
2809{
2810        uint32_t Reg, RegAddr, CurrentDestinations;
2811
2812        BERR_Code ExitCode = BERR_SUCCESS;
2813
2814        RegAddr = BCHP_XPT_FE_SPID_TABLE_i_ARRAY_BASE + ( PidChannelNum * SPID_CHNL_STEPSIZE );
2815        Reg = BREG_Read32( hXpt->hRegister, RegAddr );
2816        CurrentDestinations = BCHP_GET_FIELD_DATA( Reg, XPT_FE_SPID_TABLE_i, PID_DESTINATION );
2817        Reg &= ~BCHP_MASK( XPT_FE_SPID_TABLE_i, PID_DESTINATION );
2818
2819        if( EnableIt )
2820        {
2821                CurrentDestinations |= ( 1ul << SelectedDestination );  /* Enable the pipe */
2822                Reg |= BCHP_FIELD_DATA( XPT_FE_SPID_TABLE_i, PID_DESTINATION, CurrentDestinations );
2823                BREG_Write32( hXpt->hRegister, RegAddr, Reg );
2824
2825                /* TODO: Enable PID channel if it was requested */
2826                if( hXpt->PidChannelTable[ PidChannelNum ].EnableRequested == true )
2827                        SetChannelEnable( hXpt, PidChannelNum, true );
2828        }
2829        else
2830        {
2831                CurrentDestinations &= ~( 1ul << SelectedDestination ); /* Clear pipe enables */       
2832
2833                /* Disable PID channel if there are no other destinations selected */
2834                if( !CurrentDestinations )
2835                        SetChannelEnable( hXpt, PidChannelNum, false );
2836
2837                Reg |= BCHP_FIELD_DATA( XPT_FE_SPID_TABLE_i, PID_DESTINATION, CurrentDestinations );
2838                BREG_Write32( hXpt->hRegister, RegAddr, Reg );
2839        }
2840
2841        return ExitCode;
2842}
2843
2844bool IsPidDuplicated(
2845        BXPT_Handle hXpt,                       /* [Input] Handle for this transport */
2846        unsigned int PidChannelNum     
2847        )
2848{
2849        unsigned int i, TargetChannelCfg, ThisChannelCfg, ThisChannelEnable;
2850        uint32_t RegAddr, Reg;
2851
2852        bool IsDuplicated = false;
2853
2854#ifdef ENABLE_PLAYBACK_MUX
2855        if(hXpt->PidChannelTable[PidChannelNum].Band > 
2856                BXPT_PB_PARSER((BXPT_NUM_PLAYBACKS - hXpt->NumPlaybackMuxes)))
2857        {
2858                /*there are allowed to be duplicated pids on the muxed band*/
2859                return(false);
2860        }
2861
2862        /*gain access to the pid table*/
2863        BKNI_EnterCriticalSection();
2864#endif /*ENABLE_PLAYBACK_MUX*/
2865
2866        RegAddr = BCHP_XPT_FE_PID_TABLE_i_ARRAY_BASE + ( PidChannelNum * PID_CHNL_STEPSIZE );
2867    TargetChannelCfg = BREG_Read32( hXpt->hRegister, RegAddr );
2868
2869        /* This mask covers all the bitfields we need to compare. */
2870    TargetChannelCfg &= ( 
2871        BCHP_MASK( XPT_FE_PID_TABLE_i, PLAYBACK_FE_SEL ) |
2872        BCHP_MASK( XPT_FE_PID_TABLE_i, INPUT_BAND_PARSER_PID_CHANNEL_INPUT_SELECT ) |
2873        BCHP_MASK( XPT_FE_PID_TABLE_i, ENABLE_HD_FILTER ) |
2874        BCHP_MASK( XPT_FE_PID_TABLE_i, HD_FILT_DIS_PID_CHANNEL_PID )
2875    );
2876
2877        for( i = 0; i < hXpt->MaxPidChannels; i++ )
2878        {
2879                /* Skip the legitimate channel assignment. */
2880                if( i == PidChannelNum )
2881                        continue;
2882
2883                if( hXpt->PidChannelTable[ i ].IsPidChannelConfigured == true )
2884                {
2885                RegAddr = BCHP_XPT_FE_PID_TABLE_i_ARRAY_BASE + ( i * PID_CHNL_STEPSIZE );
2886            ThisChannelCfg = Reg = BREG_Read32( hXpt->hRegister, RegAddr );
2887            ThisChannelCfg &= ( 
2888                BCHP_MASK( XPT_FE_PID_TABLE_i, PLAYBACK_FE_SEL ) |
2889                BCHP_MASK( XPT_FE_PID_TABLE_i, INPUT_BAND_PARSER_PID_CHANNEL_INPUT_SELECT ) |
2890                BCHP_MASK( XPT_FE_PID_TABLE_i, ENABLE_HD_FILTER ) |
2891                BCHP_MASK( XPT_FE_PID_TABLE_i, HD_FILT_DIS_PID_CHANNEL_PID )
2892            );
2893
2894            /* We need to know if the channel has been enabled or has just been *requested* to be enabled */
2895            ThisChannelEnable = BCHP_GET_FIELD_DATA( Reg, XPT_FE_PID_TABLE_i, PID_CHANNEL_ENABLE ) || hXpt->PidChannelTable[ i ].EnableRequested == true;
2896
2897            if( TargetChannelCfg == ThisChannelCfg && ThisChannelEnable )
2898                {
2899                        BDBG_ERR(( "Pid channels %lu and %lu are duplicates!", i, PidChannelNum ));
2900                                IsDuplicated = true;
2901                                break;
2902                        } 
2903                }
2904        }
2905
2906#ifdef ENABLE_PLAYBACK_MUX
2907        /*leave pid table protected area*/
2908        BKNI_LeaveCriticalSection();
2909#endif /*ENABLE_PLAYBACK_MUX*/
2910
2911        return( IsDuplicated );
2912}
2913
2914static void BXPT_P_ConfigArbiter(BREG_Handle hReg)
2915{
2916    /* Nothing specific needed yet. */
2917    BSTD_UNUSED( hReg ); 
2918}
2919
2920BERR_Code BXPT_GetPidChannel_CC_Config(
2921        BXPT_Handle hXpt,                           /* [in] Handle for this transport */
2922        unsigned int PidChannelNum,     /* [in] Which channel to get config for. */
2923        BXPT_PidChannel_CC_Config *Cfg
2924    )
2925{
2926        BERR_Code ExitCode = BERR_SUCCESS;
2927
2928        BDBG_ASSERT( hXpt );
2929        BDBG_ASSERT( Cfg );
2930
2931        if( PidChannelNum > hXpt->MaxPidChannels )
2932        {
2933                /* Bad PID channel number. Complain. */
2934                BDBG_ERR(( "PidChannelNum %lu is out of range!", ( unsigned long ) PidChannelNum ));
2935                ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
2936        }
2937        else
2938        {
2939        /* All-pass mode overrides the user settings, so return the last ones they gave before all-pass was enabled */
2940        if( hXpt->IsParserInAllPass[ PidChannelNum ] )
2941        {
2942            *Cfg = hXpt->CcConfigBeforeAllPass[ PidChannelNum ];
2943        }
2944        else
2945        {
2946                uint32_t Reg, RegAddr;
2947   
2948                    RegAddr = BCHP_XPT_FULL_PID_PARSER_STATE_CONFIG_0_i_ARRAY_BASE + ( PidChannelNum * PID_CHNL_STEPSIZE );
2949                    Reg = BREG_Read32( hXpt->hRegister, RegAddr );
2950                    Cfg->Primary_CC_CheckEnable = BCHP_GET_FIELD_DATA( Reg, XPT_FULL_PID_PARSER_STATE_CONFIG_0_i, PCC_ERROR_EN ) ? true : false;
2951                    Cfg->Secondary_CC_CheckEnable = BCHP_GET_FIELD_DATA( Reg, XPT_FULL_PID_PARSER_STATE_CONFIG_0_i, SCC_ERROR_EN ) ? true : false;
2952                    Cfg->Generate_CC_Enable = BCHP_GET_FIELD_DATA( Reg, XPT_FULL_PID_PARSER_STATE_CONFIG_0_i, PROC_CC ) ? true : false;
2953
2954                    RegAddr = BCHP_XPT_FULL_PID_PARSER_STATE_CONFIG_3_i_ARRAY_BASE + ( PidChannelNum * PID_CHNL_STEPSIZE );
2955                    Reg = BREG_Read32( hXpt->hRegister, RegAddr );
2956                    Cfg->Initial_CC_Value = BCHP_GET_FIELD_DATA( Reg, XPT_FULL_PID_PARSER_STATE_CONFIG_3_i, PKT_INSERTED );
2957        }
2958        }       
2959       
2960    return ExitCode;                                                             
2961}
2962
2963BERR_Code BXPT_SetPidChannel_CC_Config(
2964        BXPT_Handle hXpt,                           /* [in] Handle for this transport */
2965        unsigned int PidChannelNum,     /* [in] Which channel to get config for. */
2966        const BXPT_PidChannel_CC_Config *Cfg
2967    )
2968{
2969        BERR_Code ExitCode = BERR_SUCCESS;
2970
2971        BDBG_ASSERT( hXpt );
2972        BDBG_ASSERT( Cfg );
2973
2974        if( PidChannelNum > hXpt->MaxPidChannels )
2975        {
2976                /* Bad PID channel number. Complain. */
2977                BDBG_ERR(( "PidChannelNum %lu is out of range!", ( unsigned long ) PidChannelNum ));
2978                ExitCode = BERR_TRACE( BERR_INVALID_PARAMETER );
2979        }
2980        else
2981        {
2982        /* All-pass must override the new settings, so store them until all-pass is disabled */
2983        if( hXpt->IsParserInAllPass[ PidChannelNum ] )
2984        {
2985            hXpt->CcConfigBeforeAllPass[ PidChannelNum ] = *Cfg;
2986        }
2987        else
2988        {
2989                uint32_t Reg, RegAddr;
2990   
2991                    RegAddr = BCHP_XPT_FULL_PID_PARSER_STATE_CONFIG_0_i_ARRAY_BASE + ( PidChannelNum * PID_CHNL_STEPSIZE );
2992                    Reg = BREG_Read32( hXpt->hRegister, RegAddr );
2993                    Reg &= ~(
2994                            BCHP_MASK( XPT_FULL_PID_PARSER_STATE_CONFIG_0_i, PCC_ERROR_EN ) |
2995                            BCHP_MASK( XPT_FULL_PID_PARSER_STATE_CONFIG_0_i, SCC_ERROR_EN ) |
2996                            BCHP_MASK( XPT_FULL_PID_PARSER_STATE_CONFIG_0_i, PROC_CC ) 
2997                    );
2998                    Reg |= (
2999                            BCHP_FIELD_DATA( XPT_FULL_PID_PARSER_STATE_CONFIG_0_i, PCC_ERROR_EN, Cfg->Primary_CC_CheckEnable ? 1 : 0 ) |
3000                            BCHP_FIELD_DATA( XPT_FULL_PID_PARSER_STATE_CONFIG_0_i, SCC_ERROR_EN, Cfg->Secondary_CC_CheckEnable ? 1 : 0 ) |
3001                            BCHP_FIELD_DATA( XPT_FULL_PID_PARSER_STATE_CONFIG_0_i, PROC_CC, Cfg->Generate_CC_Enable ? 1 : 0 ) 
3002                    );
3003                    BREG_Write32( hXpt->hRegister, RegAddr, Reg );
3004
3005                    RegAddr = BCHP_XPT_FULL_PID_PARSER_STATE_CONFIG_3_i_ARRAY_BASE + ( PidChannelNum * PID_CHNL_STEPSIZE );
3006                    Reg = BREG_Read32( hXpt->hRegister, RegAddr );
3007                    Reg &= ~(
3008                            BCHP_MASK( XPT_FULL_PID_PARSER_STATE_CONFIG_3_i, PKT_INSERTED ) 
3009                    );
3010                    Reg |= (
3011                            BCHP_FIELD_DATA( XPT_FULL_PID_PARSER_STATE_CONFIG_3_i, PKT_INSERTED, Cfg->Initial_CC_Value ) 
3012                    );
3013                    BREG_Write32( hXpt->hRegister, RegAddr, Reg );
3014        }
3015        }       
3016       
3017    return ExitCode;                                                             
3018}
3019
3020#if BXPT_HAS_PARSER_REMAPPING
3021
3022void BXPT_GetParserMapping(
3023    BXPT_Handle hXpt,           /* [in] Handle for the Transport. */ 
3024    BXPT_ParserBandMapping *ParserMap
3025    )
3026{
3027    uint32_t Reg;
3028
3029        BDBG_ASSERT( hXpt );
3030        BDBG_ASSERT( ParserMap );
3031
3032    *ParserMap = hXpt->BandMap;
3033
3034    Reg = BREG_Read32( hXpt->hRegister, BCHP_XPT_FE_MINI_PID_PARSER0_TO_PARSER3_BAND_ID );
3035    ParserMap->FrontEnd[ 0 ].VirtualParserBandNum = 
3036        BCHP_GET_FIELD_DATA( Reg, XPT_FE_MINI_PID_PARSER0_TO_PARSER3_BAND_ID, PARSER0_BAND_ID );
3037    ParserMap->FrontEnd[ 0 ].VirtualParserIsPlayback = 
3038        BCHP_GET_FIELD_DATA( Reg, XPT_FE_MINI_PID_PARSER0_TO_PARSER3_BAND_ID, PARSER0_PARSER_SEL ) ? true : false;
3039    ParserMap->FrontEnd[ 1 ].VirtualParserBandNum = 
3040        BCHP_GET_FIELD_DATA( Reg, XPT_FE_MINI_PID_PARSER0_TO_PARSER3_BAND_ID, PARSER1_BAND_ID );
3041    ParserMap->FrontEnd[ 1 ].VirtualParserIsPlayback = 
3042        BCHP_GET_FIELD_DATA( Reg, XPT_FE_MINI_PID_PARSER0_TO_PARSER3_BAND_ID, PARSER1_PARSER_SEL ) ? true : false;
3043    ParserMap->FrontEnd[ 2 ].VirtualParserBandNum = 
3044        BCHP_GET_FIELD_DATA( Reg, XPT_FE_MINI_PID_PARSER0_TO_PARSER3_BAND_ID, PARSER2_BAND_ID );
3045    ParserMap->FrontEnd[ 2 ].VirtualParserIsPlayback = 
3046        BCHP_GET_FIELD_DATA( Reg, XPT_FE_MINI_PID_PARSER0_TO_PARSER3_BAND_ID, PARSER2_PARSER_SEL ) ? true : false;
3047    ParserMap->FrontEnd[ 3 ].VirtualParserBandNum = 
3048        BCHP_GET_FIELD_DATA( Reg, XPT_FE_MINI_PID_PARSER0_TO_PARSER3_BAND_ID, PARSER3_BAND_ID );
3049    ParserMap->FrontEnd[ 3 ].VirtualParserIsPlayback = 
3050        BCHP_GET_FIELD_DATA( Reg, XPT_FE_MINI_PID_PARSER0_TO_PARSER3_BAND_ID, PARSER3_PARSER_SEL ) ? true : false;
3051
3052    Reg = BREG_Read32( hXpt->hRegister, BCHP_XPT_FE_MINI_PID_PARSER4_TO_PARSER7_BAND_ID );
3053    ParserMap->FrontEnd[ 4 ].VirtualParserBandNum = 
3054        BCHP_GET_FIELD_DATA( Reg, XPT_FE_MINI_PID_PARSER4_TO_PARSER7_BAND_ID, PARSER4_BAND_ID );
3055    ParserMap->FrontEnd[ 4 ].VirtualParserIsPlayback = 
3056        BCHP_GET_FIELD_DATA( Reg, XPT_FE_MINI_PID_PARSER4_TO_PARSER7_BAND_ID, PARSER4_PARSER_SEL ) ? true : false;
3057    ParserMap->FrontEnd[ 5 ].VirtualParserBandNum = 
3058        BCHP_GET_FIELD_DATA( Reg, XPT_FE_MINI_PID_PARSER4_TO_PARSER7_BAND_ID, PARSER5_BAND_ID );
3059    ParserMap->FrontEnd[ 5 ].VirtualParserIsPlayback = 
3060        BCHP_GET_FIELD_DATA( Reg, XPT_FE_MINI_PID_PARSER4_TO_PARSER7_BAND_ID, PARSER5_PARSER_SEL ) ? true : false;
3061    ParserMap->FrontEnd[ 6 ].VirtualParserBandNum = 
3062        BCHP_GET_FIELD_DATA( Reg, XPT_FE_MINI_PID_PARSER4_TO_PARSER7_BAND_ID, PARSER6_BAND_ID );
3063    ParserMap->FrontEnd[ 6 ].VirtualParserIsPlayback = 
3064        BCHP_GET_FIELD_DATA( Reg, XPT_FE_MINI_PID_PARSER4_TO_PARSER7_BAND_ID, PARSER6_PARSER_SEL ) ? true : false;
3065    ParserMap->FrontEnd[ 7 ].VirtualParserBandNum = 
3066        BCHP_GET_FIELD_DATA( Reg, XPT_FE_MINI_PID_PARSER4_TO_PARSER7_BAND_ID, PARSER7_BAND_ID );
3067    ParserMap->FrontEnd[ 7 ].VirtualParserIsPlayback = 
3068        BCHP_GET_FIELD_DATA( Reg, XPT_FE_MINI_PID_PARSER4_TO_PARSER7_BAND_ID, PARSER7_PARSER_SEL ) ? true : false;
3069
3070    Reg = BREG_Read32( hXpt->hRegister, BCHP_XPT_FE_MINI_PID_PARSER4_TO_PARSER7_BAND_ID );
3071    ParserMap->FrontEnd[ 4 ].VirtualParserBandNum = 
3072        BCHP_GET_FIELD_DATA( Reg, XPT_FE_MINI_PID_PARSER4_TO_PARSER7_BAND_ID, PARSER4_BAND_ID );
3073    ParserMap->FrontEnd[ 4 ].VirtualParserIsPlayback = 
3074        BCHP_GET_FIELD_DATA( Reg, XPT_FE_MINI_PID_PARSER4_TO_PARSER7_BAND_ID, PARSER4_PARSER_SEL ) ? true : false;
3075    ParserMap->FrontEnd[ 5 ].VirtualParserBandNum = 
3076        BCHP_GET_FIELD_DATA( Reg, XPT_FE_MINI_PID_PARSER4_TO_PARSER7_BAND_ID, PARSER5_BAND_ID );
3077    ParserMap->FrontEnd[ 5 ].VirtualParserIsPlayback = 
3078        BCHP_GET_FIELD_DATA( Reg, XPT_FE_MINI_PID_PARSER4_TO_PARSER7_BAND_ID, PARSER5_PARSER_SEL ) ? true : false;
3079    ParserMap->FrontEnd[ 6 ].VirtualParserBandNum = 
3080        BCHP_GET_FIELD_DATA( Reg, XPT_FE_MINI_PID_PARSER4_TO_PARSER7_BAND_ID, PARSER6_BAND_ID );
3081    ParserMap->FrontEnd[ 6 ].VirtualParserIsPlayback = 
3082        BCHP_GET_FIELD_DATA( Reg, XPT_FE_MINI_PID_PARSER4_TO_PARSER7_BAND_ID, PARSER6_PARSER_SEL ) ? true : false;
3083    ParserMap->FrontEnd[ 7 ].VirtualParserBandNum = 
3084        BCHP_GET_FIELD_DATA( Reg, XPT_FE_MINI_PID_PARSER4_TO_PARSER7_BAND_ID, PARSER7_BAND_ID );
3085    ParserMap->FrontEnd[ 7 ].VirtualParserIsPlayback = 
3086        BCHP_GET_FIELD_DATA( Reg, XPT_FE_MINI_PID_PARSER4_TO_PARSER7_BAND_ID, PARSER7_PARSER_SEL ) ? true : false;
3087
3088    Reg = BREG_Read32( hXpt->hRegister, BCHP_XPT_FE_MINI_PID_PARSER8_TO_PARSER11_BAND_ID );
3089    ParserMap->FrontEnd[ 8 ].VirtualParserBandNum = 
3090        BCHP_GET_FIELD_DATA( Reg, XPT_FE_MINI_PID_PARSER8_TO_PARSER11_BAND_ID, PARSER8_BAND_ID );
3091    ParserMap->FrontEnd[ 8 ].VirtualParserIsPlayback = 
3092        BCHP_GET_FIELD_DATA( Reg, XPT_FE_MINI_PID_PARSER8_TO_PARSER11_BAND_ID, PARSER8_PARSER_SEL ) ? true : false;
3093    ParserMap->FrontEnd[ 9 ].VirtualParserBandNum = 
3094        BCHP_GET_FIELD_DATA( Reg, XPT_FE_MINI_PID_PARSER8_TO_PARSER11_BAND_ID, PARSER9_BAND_ID );
3095    ParserMap->FrontEnd[ 9 ].VirtualParserIsPlayback = 
3096        BCHP_GET_FIELD_DATA( Reg, XPT_FE_MINI_PID_PARSER8_TO_PARSER11_BAND_ID, PARSER9_PARSER_SEL ) ? true : false;
3097#if BXPT_NUM_REMAPPABLE_FE_PARSERS > 10
3098    ParserMap->FrontEnd[ 10 ].VirtualParserBandNum = 
3099        BCHP_GET_FIELD_DATA( Reg, XPT_FE_MINI_PID_PARSER8_TO_PARSER11_BAND_ID, PARSER10_BAND_ID );
3100    ParserMap->FrontEnd[ 10 ].VirtualParserIsPlayback = 
3101        BCHP_GET_FIELD_DATA( Reg, XPT_FE_MINI_PID_PARSER8_TO_PARSER11_BAND_ID, PARSER10_PARSER_SEL ) ? true : false;
3102    ParserMap->FrontEnd[ 11 ].VirtualParserBandNum = 
3103        BCHP_GET_FIELD_DATA( Reg, XPT_FE_MINI_PID_PARSER8_TO_PARSER11_BAND_ID, PARSER11_BAND_ID );
3104    ParserMap->FrontEnd[ 11 ].VirtualParserIsPlayback = 
3105        BCHP_GET_FIELD_DATA( Reg, XPT_FE_MINI_PID_PARSER8_TO_PARSER11_BAND_ID, PARSER11_PARSER_SEL ) ? true : false;
3106#endif
3107
3108    /* ToDo: Add playback support. */
3109}
3110
3111BERR_Code BXPT_SetParserMapping(
3112    BXPT_Handle hXpt,           /* [in] Handle for the Transport. */ 
3113    const BXPT_ParserBandMapping *ParserMap
3114    )
3115{
3116    uint32_t Reg;
3117    unsigned ii;
3118
3119        BDBG_ASSERT( hXpt );
3120        BDBG_ASSERT( ParserMap );
3121
3122    /* Only certain parsers can be remapped. Check for attempted remapping of parsers that don't support it. */
3123#if BXPT_NUM_REMAPPABLE_FE_PARSERS < BXPT_NUM_PID_PARSERS
3124    for( ii = BXPT_NUM_REMAPPABLE_FE_PARSERS; ii < BXPT_NUM_PID_PARSERS; ii++ ) 
3125    {
3126        const BXPT_BandMap *Mapping;
3127
3128        Mapping = &ParserMap->FrontEnd[ ii ];
3129        if( Mapping->VirtualParserBandNum != ii || Mapping->VirtualParserIsPlayback ) 
3130        {
3131            BDBG_ERR(( "ParserNum %lu cannot be remapped", ii ));
3132            return BERR_TRACE( BERR_INVALID_PARAMETER );
3133        }
3134    }
3135#else
3136        BSTD_UNUSED( ii );
3137#endif
3138
3139    hXpt->BandMap = *ParserMap;
3140
3141    Reg = BREG_Read32( hXpt->hRegister, BCHP_XPT_FE_MINI_PID_PARSER0_TO_PARSER3_BAND_ID );
3142    Reg &= ~( 
3143        BCHP_MASK( XPT_FE_MINI_PID_PARSER0_TO_PARSER3_BAND_ID, PARSER0_BAND_ID ) |
3144        BCHP_MASK( XPT_FE_MINI_PID_PARSER0_TO_PARSER3_BAND_ID, PARSER0_PARSER_SEL ) |
3145        BCHP_MASK( XPT_FE_MINI_PID_PARSER0_TO_PARSER3_BAND_ID, PARSER1_BAND_ID ) |
3146        BCHP_MASK( XPT_FE_MINI_PID_PARSER0_TO_PARSER3_BAND_ID, PARSER1_PARSER_SEL ) |
3147        BCHP_MASK( XPT_FE_MINI_PID_PARSER0_TO_PARSER3_BAND_ID, PARSER2_BAND_ID ) |
3148        BCHP_MASK( XPT_FE_MINI_PID_PARSER0_TO_PARSER3_BAND_ID, PARSER2_PARSER_SEL ) |
3149        BCHP_MASK( XPT_FE_MINI_PID_PARSER0_TO_PARSER3_BAND_ID, PARSER3_BAND_ID ) |
3150        BCHP_MASK( XPT_FE_MINI_PID_PARSER0_TO_PARSER3_BAND_ID, PARSER3_PARSER_SEL ) 
3151    );
3152    Reg |= ( 
3153        BCHP_FIELD_DATA( XPT_FE_MINI_PID_PARSER0_TO_PARSER3_BAND_ID, PARSER0_BAND_ID, ParserMap->FrontEnd[ 0 ].VirtualParserBandNum ) |
3154        BCHP_FIELD_DATA( XPT_FE_MINI_PID_PARSER0_TO_PARSER3_BAND_ID, PARSER0_PARSER_SEL, ParserMap->FrontEnd[ 0 ].VirtualParserIsPlayback ? 1 : 0 ) |
3155        BCHP_FIELD_DATA( XPT_FE_MINI_PID_PARSER0_TO_PARSER3_BAND_ID, PARSER1_BAND_ID, ParserMap->FrontEnd[ 1 ].VirtualParserBandNum ) |
3156        BCHP_FIELD_DATA( XPT_FE_MINI_PID_PARSER0_TO_PARSER3_BAND_ID, PARSER1_PARSER_SEL, ParserMap->FrontEnd[ 1 ].VirtualParserIsPlayback ? 1 : 0 ) |
3157        BCHP_FIELD_DATA( XPT_FE_MINI_PID_PARSER0_TO_PARSER3_BAND_ID, PARSER2_BAND_ID, ParserMap->FrontEnd[ 2 ].VirtualParserBandNum ) |
3158        BCHP_FIELD_DATA( XPT_FE_MINI_PID_PARSER0_TO_PARSER3_BAND_ID, PARSER2_PARSER_SEL, ParserMap->FrontEnd[ 2 ].VirtualParserIsPlayback ? 1 : 0 ) |
3159        BCHP_FIELD_DATA( XPT_FE_MINI_PID_PARSER0_TO_PARSER3_BAND_ID, PARSER3_BAND_ID, ParserMap->FrontEnd[ 3 ].VirtualParserBandNum ) |
3160        BCHP_FIELD_DATA( XPT_FE_MINI_PID_PARSER0_TO_PARSER3_BAND_ID, PARSER3_PARSER_SEL, ParserMap->FrontEnd[ 3 ].VirtualParserIsPlayback ? 1 : 0 ) 
3161    );
3162    BREG_Write32( hXpt->hRegister, BCHP_XPT_FE_MINI_PID_PARSER0_TO_PARSER3_BAND_ID, Reg );
3163
3164    Reg = BREG_Read32( hXpt->hRegister, BCHP_XPT_FE_MINI_PID_PARSER4_TO_PARSER7_BAND_ID );
3165    Reg &= ~( 
3166        BCHP_MASK( XPT_FE_MINI_PID_PARSER4_TO_PARSER7_BAND_ID, PARSER4_BAND_ID ) |
3167        BCHP_MASK( XPT_FE_MINI_PID_PARSER4_TO_PARSER7_BAND_ID, PARSER4_PARSER_SEL ) |
3168        BCHP_MASK( XPT_FE_MINI_PID_PARSER4_TO_PARSER7_BAND_ID, PARSER5_BAND_ID ) |
3169        BCHP_MASK( XPT_FE_MINI_PID_PARSER4_TO_PARSER7_BAND_ID, PARSER5_PARSER_SEL ) |
3170        BCHP_MASK( XPT_FE_MINI_PID_PARSER4_TO_PARSER7_BAND_ID, PARSER6_BAND_ID ) |
3171        BCHP_MASK( XPT_FE_MINI_PID_PARSER4_TO_PARSER7_BAND_ID, PARSER6_PARSER_SEL ) |
3172        BCHP_MASK( XPT_FE_MINI_PID_PARSER4_TO_PARSER7_BAND_ID, PARSER7_BAND_ID ) |
3173        BCHP_MASK( XPT_FE_MINI_PID_PARSER4_TO_PARSER7_BAND_ID, PARSER7_PARSER_SEL ) 
3174    );
3175    Reg |= ( 
3176        BCHP_FIELD_DATA( XPT_FE_MINI_PID_PARSER4_TO_PARSER7_BAND_ID, PARSER4_BAND_ID, ParserMap->FrontEnd[ 4 ].VirtualParserBandNum ) |
3177        BCHP_FIELD_DATA( XPT_FE_MINI_PID_PARSER4_TO_PARSER7_BAND_ID, PARSER4_PARSER_SEL, ParserMap->FrontEnd[ 4 ].VirtualParserIsPlayback ? 1 : 0 ) |
3178        BCHP_FIELD_DATA( XPT_FE_MINI_PID_PARSER4_TO_PARSER7_BAND_ID, PARSER5_BAND_ID, ParserMap->FrontEnd[ 5 ].VirtualParserBandNum ) |
3179        BCHP_FIELD_DATA( XPT_FE_MINI_PID_PARSER4_TO_PARSER7_BAND_ID, PARSER5_PARSER_SEL, ParserMap->FrontEnd[ 5 ].VirtualParserIsPlayback ? 1 : 0 ) |
3180        BCHP_FIELD_DATA( XPT_FE_MINI_PID_PARSER4_TO_PARSER7_BAND_ID, PARSER6_BAND_ID, ParserMap->FrontEnd[ 6 ].VirtualParserBandNum ) |
3181        BCHP_FIELD_DATA( XPT_FE_MINI_PID_PARSER4_TO_PARSER7_BAND_ID, PARSER6_PARSER_SEL, ParserMap->FrontEnd[ 6 ].VirtualParserIsPlayback ? 1 : 0 ) |
3182        BCHP_FIELD_DATA( XPT_FE_MINI_PID_PARSER4_TO_PARSER7_BAND_ID, PARSER7_BAND_ID, ParserMap->FrontEnd[ 7 ].VirtualParserBandNum ) |
3183        BCHP_FIELD_DATA( XPT_FE_MINI_PID_PARSER4_TO_PARSER7_BAND_ID, PARSER7_PARSER_SEL, ParserMap->FrontEnd[ 7 ].VirtualParserIsPlayback ? 1 : 0 ) 
3184    );
3185    BREG_Write32( hXpt->hRegister, BCHP_XPT_FE_MINI_PID_PARSER4_TO_PARSER7_BAND_ID, Reg );
3186
3187    Reg = BREG_Read32( hXpt->hRegister, BCHP_XPT_FE_MINI_PID_PARSER8_TO_PARSER11_BAND_ID );
3188    Reg &= ~( 
3189        BCHP_MASK( XPT_FE_MINI_PID_PARSER8_TO_PARSER11_BAND_ID, PARSER8_BAND_ID ) |
3190        BCHP_MASK( XPT_FE_MINI_PID_PARSER8_TO_PARSER11_BAND_ID, PARSER8_PARSER_SEL ) |
3191        BCHP_MASK( XPT_FE_MINI_PID_PARSER8_TO_PARSER11_BAND_ID, PARSER9_BAND_ID ) |
3192        BCHP_MASK( XPT_FE_MINI_PID_PARSER8_TO_PARSER11_BAND_ID, PARSER9_PARSER_SEL ) 
3193
3194#if BXPT_NUM_REMAPPABLE_FE_PARSERS > 10
3195        |
3196        BCHP_MASK( XPT_FE_MINI_PID_PARSER8_TO_PARSER11_BAND_ID, PARSER10_BAND_ID ) |
3197        BCHP_MASK( XPT_FE_MINI_PID_PARSER8_TO_PARSER11_BAND_ID, PARSER10_PARSER_SEL ) |
3198        BCHP_MASK( XPT_FE_MINI_PID_PARSER8_TO_PARSER11_BAND_ID, PARSER11_BAND_ID ) |
3199        BCHP_MASK( XPT_FE_MINI_PID_PARSER8_TO_PARSER11_BAND_ID, PARSER11_PARSER_SEL ) 
3200#endif
3201    );
3202    Reg |= ( 
3203        BCHP_FIELD_DATA( XPT_FE_MINI_PID_PARSER8_TO_PARSER11_BAND_ID, PARSER8_BAND_ID, ParserMap->FrontEnd[ 8 ].VirtualParserBandNum ) |
3204        BCHP_FIELD_DATA( XPT_FE_MINI_PID_PARSER8_TO_PARSER11_BAND_ID, PARSER8_PARSER_SEL, ParserMap->FrontEnd[ 8 ].VirtualParserIsPlayback ? 1 : 0 ) |
3205        BCHP_FIELD_DATA( XPT_FE_MINI_PID_PARSER8_TO_PARSER11_BAND_ID, PARSER9_BAND_ID, ParserMap->FrontEnd[ 9 ].VirtualParserBandNum ) |
3206        BCHP_FIELD_DATA( XPT_FE_MINI_PID_PARSER8_TO_PARSER11_BAND_ID, PARSER9_PARSER_SEL, ParserMap->FrontEnd[ 9 ].VirtualParserIsPlayback ? 1 : 0 ) 
3207#if BXPT_NUM_REMAPPABLE_FE_PARSERS > 10
3208        |
3209        BCHP_FIELD_DATA( XPT_FE_MINI_PID_PARSER8_TO_PARSER11_BAND_ID, PARSER10_BAND_ID, ParserMap->FrontEnd[ 10 ].VirtualParserBandNum ) |
3210        BCHP_FIELD_DATA( XPT_FE_MINI_PID_PARSER8_TO_PARSER11_BAND_ID, PARSER10_PARSER_SEL, ParserMap->FrontEnd[ 10 ].VirtualParserIsPlayback ? 1 : 0 ) |
3211        BCHP_FIELD_DATA( XPT_FE_MINI_PID_PARSER8_TO_PARSER11_BAND_ID, PARSER11_BAND_ID, ParserMap->FrontEnd[ 11 ].VirtualParserBandNum ) |
3212        BCHP_FIELD_DATA( XPT_FE_MINI_PID_PARSER8_TO_PARSER11_BAND_ID, PARSER11_PARSER_SEL, ParserMap->FrontEnd[ 11 ].VirtualParserIsPlayback ? 1 : 0 ) 
3213#endif
3214    );
3215    BREG_Write32( hXpt->hRegister, BCHP_XPT_FE_MINI_PID_PARSER8_TO_PARSER11_BAND_ID, Reg );
3216
3217        return BERR_SUCCESS;
3218}
3219
3220#endif
3221
3222
3223uint32_t BXPT_P_GetParserCtrlRegAddr(
3224        BXPT_Handle hXpt,                               /* [in] Handle for the transport to access. */
3225    unsigned ParserNum,
3226    unsigned Reg0
3227    )
3228{
3229#if BXPT_HAS_PARSER_REMAPPING
3230    {
3231        if( BCHP_XPT_FE_MINI_PID_PARSER0_CTRL1 == Reg0 || BCHP_XPT_FE_MINI_PID_PARSER0_CTRL2 == Reg0 ) 
3232        {
3233            unsigned ii;
3234
3235            for (ii = 0; ii < BXPT_NUM_PID_PARSERS; ii++) 
3236            {
3237                BXPT_BandMap *pMap = &hXpt->BandMap.FrontEnd[ ii ];
3238
3239                if( pMap->VirtualParserBandNum == ParserNum && !pMap->VirtualParserIsPlayback )
3240                {
3241                    return Reg0 + ( ii * PARSER_REG_STEPSIZE );
3242                }
3243            }
3244
3245            /* Had to be an invalid band number to get this far. */
3246            BDBG_ERR(( "Invalid virtual parser band number" ));
3247            return 0;
3248        }
3249        else
3250        {
3251            /* Read or write of addr 0 will probably cause a segfault, but we were passed an unsupported Reg0 anyway. */
3252            BDBG_ERR(( "Parser reg %lu is unsupported", Reg0 ));
3253            return 0;
3254        }
3255    }
3256#else
3257    BSTD_UNUSED( hXpt );
3258    return Reg0 + ( ParserNum * PARSER_REG_STEPSIZE );
3259#endif
3260}
3261
3262static unsigned int GetParserIndex(
3263    BXPT_Handle hXpt,                               /* [in] Handle for the transport to access. */
3264    unsigned ParserNum )
3265{
3266    unsigned ii;
3267
3268#if BXPT_HAS_PARSER_REMAPPING
3269    for (ii = 0; ii < BXPT_NUM_PID_PARSERS; ii++)
3270    {
3271        BXPT_BandMap *pMap = &hXpt->BandMap.FrontEnd[ ii ];
3272
3273        if( pMap->VirtualParserBandNum == ParserNum && !pMap->VirtualParserIsPlayback )
3274        {
3275            break;
3276        }
3277    }
3278
3279    if (ii == BXPT_NUM_PID_PARSERS)
3280            BDBG_ERR(( "Invalid virtual parser band number" ));
3281#else
3282    ii = ParserNum;
3283#endif
3284    return ii;
3285}
3286
3287#if BXPT_HAS_PIPELINE_ERROR_REPORTING
3288BERR_Code BXPT_CheckPipelineErrors(
3289    BXPT_Handle hXpt
3290    )
3291{
3292        BERR_Code status = BERR_SUCCESS;
3293
3294#if BXPT_HAS_FIXED_RSBUF_CONFIG
3295    status |= BXPT_P_RsBuf_ReportOverflows( hXpt );
3296#endif
3297#if BXPT_HAS_FIXED_XCBUF_CONFIG
3298    status |= BXPT_P_XcBuf_ReportOverflows( hXpt );
3299#endif
3300
3301    return status ? BXPT_ERR_DATA_PIPELINE : status;
3302}
3303#endif
3304
3305/* end of file */
3306
3307
Note: See TracBrowser for help on using the repository browser.