blob: 387fa3f71312d97d53f364e8cefa7253cccd6050 [file] [log] [blame]
Zane Shelleyba5dc162020-11-09 21:47:55 -06001#!/usr/bin/env perl
Zane Shelleyabc51c22020-11-09 21:35:35 -06002
3use warnings;
4use strict;
5
6use Data::Dumper;
7use Getopt::Long qw(:config no_ignore_case);
8use File::Path qw(make_path);
9use XML::Simple qw(:strict);
Zane Shelley0a905012021-04-26 17:07:24 -050010use JSON;
Zane Shelleyabc51c22020-11-09 21:35:35 -060011
12# Pull in from the lib directory
13use FindBin qw($RealBin);
14use FindBin qw($RealScript);
15use lib "$RealBin/lib";
16
17use BitRange;
18
19#-------------------------------------------------------------------------------
20# Global Variables
21#-------------------------------------------------------------------------------
22
23# Supported file versions and their values.
24my $FILE_VERSION =
25{
26 VER_01 => 0x01,
27};
28
29# This is a map of all currently supported models/ECs and their IDs.
30my $SUPPORTED_MODEL_EC =
31{
Zane Shelley13d04082021-06-04 08:40:48 -050032 EXPLORER_11 => { id => 0x60D20011, type => "ocmb", desc => "Explorer 1.1" },
33 EXPLORER_20 => { id => 0x60D20020, type => "ocmb", desc => "Explorer 2.0" },
34 P10_10 => { id => 0x20DA0010, type => "proc", desc => "P10 1.0" },
35 P10_20 => { id => 0x20DA0020, type => "proc", desc => "P10 2.0" },
Zane Shelleyabc51c22020-11-09 21:35:35 -060036};
37
38# All models/ECs that may exist in the XML, but no longer needs to be built.
39# This is useful for build optimization and also help prevent build breaks when
40# the XML still exists, but not needed anymore.
41my $DEPRECATED_MODEL_EC = [];
42
43# Supported register types and their values.
44my $REGISTER_TYPE =
45{
46 SCOM => { id => 0x01, addr_size => 4, reg_size => 8 },
47 IDSCOM => { id => 0x02, addr_size => 8, reg_size => 8 },
48};
49
50# Supported attention types and their values.
51my $ATTN_TYPE =
52{
Zane Shelley3d308902021-06-04 16:35:33 -050053 CS => [ 1, 'checkstop' ], # System checkstop hardware attention
54 UCS => [ 2, 'unit checkstop' ], # Unit checkstop hardware attention
55 RE => [ 3, 'recoverable' ], # Recoverable hardware attention
56 SPA => [ 4, 'special attention' ], # event requiring action by the SP FW
57 HA => [ 5, 'host attention' ], # event requiring action by the host FW
Zane Shelleyabc51c22020-11-09 21:35:35 -060058};
59
60#-------------------------------------------------------------------------------
61# Help function
62#-------------------------------------------------------------------------------
63
64sub help()
65{
66 print <<EOF;
67Usage: $RealScript -h
68 $RealScript -i <input_dir> -o <output_dir>
69
Zane Shelley738276a2021-05-24 12:55:34 -050070Generates specified data files from the input Chip Data XML.
Zane Shelleyabc51c22020-11-09 21:35:35 -060071
Zane Shelley738276a2021-05-24 12:55:34 -050072General options:
73
Zane Shelleyabc51c22020-11-09 21:35:35 -060074 -h, --help Prints this menu.
75 -i, --input Directory containing the Chip Data XML files.
Zane Shelley738276a2021-05-24 12:55:34 -050076 -o, --output Directory that will contain the data files.
77
78Data file options (must specify at least one):
79
80 --cdb Generates Chip Data Binary files.
81 --json Generates PEL Parser Data JSON files.
82
Zane Shelleyabc51c22020-11-09 21:35:35 -060083EOF
84
85 exit;
86}
87
88#-------------------------------------------------------------------------------
89# Input
90#-------------------------------------------------------------------------------
91
92help() unless @ARGV; # print help if no arguments
93
94# Get options
Zane Shelley738276a2021-05-24 12:55:34 -050095my ( $help, $src_dir, $dest_dir, $gen_cdb, $gen_json );
96help() unless GetOptions(
97 'h|help' => \$help,
98 'i|input=s' => \$src_dir,
99 'o|output=s' => \$dest_dir,
100 'cdb' => \$gen_cdb,
101 'json' => \$gen_json,
102);
Zane Shelleyabc51c22020-11-09 21:35:35 -0600103
104help() if @ARGV; # print usage if there are extra arguments
105
106# -h,--help
107help() if ( $help );
108
109# -i,--input
110die "ERROR> Option -i required." unless ( defined $src_dir );
111die "ERROR> '$src_dir' is not a directory" unless ( -d $src_dir );
112
113# -o,--output
114die "ERROR> Option -o required." unless ( defined $dest_dir );
115make_path( $dest_dir, {error => \my $err} );
116if ( @{$err} )
117{
118 my ( $file, $message ) = %{shift @{$err}};
119 die "ERROR> $message: $file\n";
120}
121
Zane Shelley738276a2021-05-24 12:55:34 -0500122# --cdb, --json
123unless ( $gen_cdb or $gen_json )
124{
125 die "ERROR> Must specify at least one data file option.";
126}
127
Zane Shelleyabc51c22020-11-09 21:35:35 -0600128#-------------------------------------------------------------------------------
129# Prototypes
130#-------------------------------------------------------------------------------
131
132sub importXML($);
133sub normalizeXML($);
Zane Shelley738276a2021-05-24 12:55:34 -0500134sub buildDataFiles($$);
Zane Shelleyabc51c22020-11-09 21:35:35 -0600135
136#-------------------------------------------------------------------------------
137# Main
138#-------------------------------------------------------------------------------
139
140# Validate and import the XML.
141my $chip_data_xml = importXML( $src_dir );
142
143# There are some fields in the XML that are shorthand and need to be expanded
144# before building the binary files.
145my $normalized_data = normalizeXML( $chip_data_xml );
146
147# The XML should now be in a format to start building the binary files.
Zane Shelley738276a2021-05-24 12:55:34 -0500148buildDataFiles( $dest_dir, $normalized_data );
Zane Shelleyabc51c22020-11-09 21:35:35 -0600149
150#-------------------------------------------------------------------------------
151# Helper functions
152#-------------------------------------------------------------------------------
153
154sub FAIL($) { die( "ERROR> " . shift @_ ); }
155
156#-------------------------------------------------------------------------------
157# Import functions
158#-------------------------------------------------------------------------------
159
160# For each supported XML file in the given directory:
161# - Ensures the XML is well-formed.
162# - Ensures the XML validates against the schema.
163# - Imports the XML into Perl data structures.
164sub importXML($)
165{
166 my ( $dir ) = @_;
167
168 my $data = {};
169
170 # Get a list of all the XML files.
171 opendir DIR, $dir or die "Couldn't open dir '$dir': $!";
172 my @files = grep { /^.+\.xml$/ } readdir DIR;
173 closedir DIR;
174
175 # Iterate each supported file type.
176 for my $type ( "chip", "node" )
177 {
178 for my $file ( grep { /^$type\_.+\.xml$/ } @files )
179 {
180 my $path = "$dir/$file";
181
182 # Ensure the XML is well-formed and validates against the schema.
Zane Shelleyfc4aa5e2021-01-14 13:45:39 -0600183 my $out = `xmllint --noout --schema $RealBin/$type.xsd $path 2>&1`;
184 die "$out\nRAS XML validation failed on $file" if ( 0 != $? );
Zane Shelleyabc51c22020-11-09 21:35:35 -0600185
186 # Import the XML.
187 my $xml = XMLin( $path, KeyAttr => {}, ForceArray => 1 );
188
189 # Add the file path to the XML for error output.
190 $xml->{path} = $path;
191
192 # Push each file's data to a list for each file type.
193 push @{$data->{$type}}, $xml;
194 }
195 }
196
197 return $data;
198}
199
200#-------------------------------------------------------------------------------
201# Normalize functions
202#-------------------------------------------------------------------------------
203
204# Takes a string of models/ECs separated by ',' and returns a list of supported
205# models/ECs. See $SUPPORTED_MODEL_EC and $DEPRECATED_MODEL_EC.
206sub __expandModelEc($)
207{
208 my ( $str ) = @_;
209
210 my @list = split(/,/, $str);
211
212 # Remove any deprecated models/ECs.
213 for my $d ( @{$DEPRECATED_MODEL_EC} )
214 {
215 @list = grep { $d ne $_ } @list;
216 }
217
218 # Validate the remaining models/ECs.
219 for my $m ( @list )
220 {
221 unless ( defined $SUPPORTED_MODEL_EC->{$m} )
222 {
223 FAIL("Unsupported model/EC: $m");
224 }
225 }
226
227 return @list;
228}
229
230#-------------------------------------------------------------------------------
231
232sub __getInstRange($)
233{
234 my ( $insts ) = @_;
235
236 my $list = [];
237 for ( @{$insts} ) { push @{$list}, $_->{reg_inst}; }
238
239 @{$list} = sort @{$list}; # Sort the list just in case.
240
241 return BitRange::compress($list);
242}
243
244sub __getReg($$$$)
245{
246 my ( $inst_in, $reg_type, $name, $addr_mod ) = @_;
247
248 my $inst_out = [];
249 for ( @{$inst_in} )
250 {
251 my $addr = "";
252 if ( "SCOM" eq $reg_type )
253 {
254 $addr = sprintf( "0x%08x", hex($_->{addr}) + $addr_mod );
255 }
256 elsif ( "IDSCOM" eq $reg_type )
257 {
258 # TODO: Need a portable way of handling 64-bit numbers.
259 FAIL("IDSCOM address currently not supported");
260 }
261 else
262 {
263 FAIL("Unsupported register type for node: $name");
264 }
265
266 push @{$inst_out}, { reg_inst => $_->{reg_inst}, addr => $addr };
267 }
268
269 return { name => $name, instance => $inst_out };
270}
271
272sub __getExpr($$)
273{
274 my ( $name, $config ) = @_;
275
276 # Get the register expression.
277 my $expr = { type => 'reg', value1 => $name };
278
279 if ( '0' eq $config )
280 {
281 # Take the NOT of the register expression.
282 $expr = { type => 'not', expr => [ $expr ] };
283 }
284
285 return $expr;
286}
287
288sub __getAct($$$$)
289{
290 my ( $fir, $range, $type, $config ) = @_;
291
292 FAIL("Invalid action config: $config") unless ( $config =~ /^[01]{2,3}$/ );
293
294 my @c = split( //, $config );
295
296 my $e = [];
297 push( @{$e}, __getExpr("${fir}", '1' ) );
298 push( @{$e}, __getExpr("${fir}_MASK", '0' ) );
299 push( @{$e}, __getExpr("${fir}_ACT0", shift @c) );
300 push( @{$e}, __getExpr("${fir}_ACT1", shift @c) );
301 push( @{$e}, __getExpr("${fir}_ACT2", shift @c) ) if ( 0 < scalar @c );
302
303 return { node_inst => $range, attn_type => $type,
304 expr => [ { type => 'and', expr => $e } ] };
305}
306
307#-------------------------------------------------------------------------------
308
309sub __normalizeLocalFir($)
310{
311 my ( $node ) = @_;
312
313 return unless ( defined $node->{local_fir} );
314
315 # Note that the isolator will implicitly add all register referenced by the
316 # rules to the capture group. To reduce redundancy and overall file size, we
317 # won't add these registers to the capture group.
318
319 $node->{register} = [] unless ( defined $node->{register} );
320 $node->{rule} = [] unless ( defined $node->{rule} );
321
322 for my $l ( @{$node->{local_fir}} )
323 {
324 my $n = $l->{name};
325 my $i = $l->{instance};
326 my $t = $node->{reg_type};
327
328 my $inst_range = __getInstRange($i);
329
330 my $r = [];
331 push @{$r}, __getReg($i, $t, "${n}", 0);
332 push @{$r}, __getReg($i, $t, "${n}_MASK", 3);
333 push @{$r}, __getReg($i, $t, "${n}_ACT0", 6);
334 push @{$r}, __getReg($i, $t, "${n}_ACT1", 7);
335 push @{$r}, __getReg($i, $t, "${n}_WOF", 8) if ($l->{config} =~ /W/);
336 push @{$r}, __getReg($i, $t, "${n}_ACT2", 9) if ($l->{config} =~ /2/);
337
338 push @{$node->{register}}, @{$r};
339
340 for ( @{$l->{action}} )
341 {
342 push @{$node->{rule}},
343 __getAct( $n, $inst_range, $_->{attn_type}, $_->{config} );
344 }
345 }
346
347 delete $node->{local_fir};
348}
349
350#-------------------------------------------------------------------------------
351
352# This is not very efficient, especially for large data structures. It is
353# recommended to use Data::Compare, but that is not available on the pool
354# machines.
355sub __dirtyCompare($$)
356{
357 local $Data::Dumper::Terse = 1;
358 local $Data::Dumper::Indent = 0;
359 local $Data::Dumper::Sortkeys = 1;
360 my ( $a, $b ) = ( Dumper(shift), Dumper(shift) );
361 return $a eq $b;
362}
363
364#-------------------------------------------------------------------------------
365
366sub __normalizeRegister($$)
367{
368 my ( $node, $regs ) = @_;
369
Zane Shelley467bce82021-07-15 20:16:54 -0500370 return unless ( defined $node->{register} );
Zane Shelleyabc51c22020-11-09 21:35:35 -0600371
372 # All of the registers will be put in the master register list for the chip.
373 for my $r ( @{$node->{register}} )
374 {
375 # Set the default access if needed.
376 $r->{access} = 'RW' unless ( defined $r->{access} );
377
378 # Each register will keep track of its type.
379 $r->{reg_type} = $node->{reg_type};
380
Zane Shelleyd6826e52020-11-10 17:39:00 -0600381 for my $model_ec ( __expandModelEc($node->{model_ec}) )
Zane Shelleyabc51c22020-11-09 21:35:35 -0600382 {
Zane Shelleyd6826e52020-11-10 17:39:00 -0600383 if ( defined $regs->{$model_ec}->{$r->{name}} )
Zane Shelleyabc51c22020-11-09 21:35:35 -0600384 {
Zane Shelleyd6826e52020-11-10 17:39:00 -0600385 # This register already exists so check the contents for
386 # accuracy
387 unless ( __dirtyCompare($r, $regs->{$model_ec}->{$r->{name}}) )
388 {
389 FAIL("Duplicate register: $r->{name}");
390 }
Zane Shelleyabc51c22020-11-09 21:35:35 -0600391 }
Zane Shelleyd6826e52020-11-10 17:39:00 -0600392 else
393 {
394 # Add this node's register to the master register list.
395 $regs->{$model_ec}->{$r->{name}} = $r;
396 }
Zane Shelleyabc51c22020-11-09 21:35:35 -0600397 }
398 }
399
400 # Clean up this node's register data.
401 delete $node->{register};
402}
403
404#-------------------------------------------------------------------------------
405
406sub __normalizeCaptureGroup($$)
407{
408 my ( $node, $insts_data ) = @_;
409
410 # Capture groups are optional (although recommended).
411 return unless ( defined $node->{capture_group} );
412
413 for my $c ( @{$node->{capture_group}} )
414 {
415 # There must be at least one capture_register.
416 unless ( defined $c->{capture_register} and
417 0 < scalar @{$c->{capture_register}} )
418 {
419 FAIL("<capture_group> for node $node->{name} does not contain at " .
420 "least one <capture_register>" );
421 }
422
423 my @node_insts = BitRange::expand($c->{node_inst});
424
425 for my $r ( @{$c->{capture_register}} )
426 {
427 # node_inst and reg_inst must be the same size.
428 my @reg_insts = BitRange::expand($r->{reg_inst});
429 unless ( scalar @node_insts == scalar @reg_insts )
430 {
431 FAIL("capture_group/\@node_inst and capture_register/" .
432 "\@reg_inst list sized not equal for node $node->{name}");
433 }
434
435 # Expand the capture groups so there is one per node instance.
436 for ( 0 .. (scalar @node_insts - 1) )
437 {
438 my ( $ni, $ri ) = ( $node_insts[$_], $reg_insts[$_] );
439 push @{$insts_data->{$ni}->{capture_group}},
440 { reg_name => $r->{reg_name}, reg_inst => $ri };
441 }
442 }
443 }
444
445 # Clean up this node's capture group data.
446 delete $node->{capture_group};
447}
448
449#-------------------------------------------------------------------------------
450
451sub __normalizeExpr($$$$); # Called recursively
452
453sub __normalizeExpr($$$$)
454{
455 my ( $in, $ni, $idx, $size ) = @_;
456
457 my ( $t, $e, $v1, $v2 ) = ( $in->{type}, $in->{expr},
458 $in->{value1}, $in->{value2} );
459
460 my $out = { type => $t };
461
462 if ( "and" eq $t or "or" eq $t )
463 {
464 if ( defined $v1 or defined $v2 or
465 not defined $e or not (0 < scalar @{$e}) )
466 {
467 FAIL("Invalid parameters for and/or expression");
468 }
469
470 # Iterate each sub expression.
471 push @{$out->{expr}}, __normalizeExpr($_, $ni, $idx, $size) for (@{$e});
472 }
473 elsif ( "not" eq $t )
474 {
475 if ( defined $v1 or defined $v2 or
476 not defined $e or not (1 == scalar @{$e}) )
477 {
478 FAIL("Invalid parameters for not expression");
479 }
480
481 # Iterate each sub expression.
482 push @{$out->{expr}}, __normalizeExpr($_, $ni, $idx, $size) for (@{$e});
483 }
484 elsif ( "lshift" eq $t or "rshift" eq $t )
485 {
486 if ( not defined $v1 or defined $v2 or
487 not defined $e or not (1 == scalar @{$e}) )
488 {
489 FAIL("Invalid parameters for lshift/rshift expression");
490 }
491
492 # Copy value1.
493 $out->{value1} = $v1;
494
495 # Iterate each sub expression.
496 push @{$out->{expr}}, __normalizeExpr($_, $ni, $idx, $size) for (@{$e});
497 }
498 elsif ( "reg" eq $t )
499 {
500 if ( not defined $v1 or defined $e )
501 {
502 FAIL("Invalid parameters for reg expression");
503 }
504
505 # Copy value1.
506 $out->{value1} = $v1;
507
508 # value2 is optional in the XML, update the value to the node or
509 # register instance.
510 if ( defined $v2 )
511 {
512 my @reg_insts = BitRange::expand($v2);
513 unless ( $size == scalar @reg_insts )
514 {
515 FAIL("reg expression value2:$v2 list not the same ".
516 "size as containing node's rule instances:$size");
517 }
518
519 $out->{value2} = $reg_insts[$idx];
520 }
521 else
522 {
523 # The register instance is the same as the node instance.
524 $out->{value2} = $ni;
525 }
526 }
527 elsif ( "int" eq $t )
528 {
529 if ( not defined $v1 or defined $v2 or defined $e )
530 {
531 FAIL("Invalid parameters for int expression");
532 }
533
534 # Copy value1.
535 $out->{value1} = $v1;
536 }
537 else
538 {
539 FAIL("Unsupported expression type: $t");
540 }
541
542 return $out;
543}
544
545#-------------------------------------------------------------------------------
546
547sub __normalizeRule($$)
548{
549 my ( $node, $insts_data ) = @_;
550
Zane Shelleyabc51c22020-11-09 21:35:35 -0600551 # There should be only one rule per attention type and node instance for
552 # this node.
553 my $rule_dups = {};
554
555 for my $r ( @{$node->{rule}} )
556 {
557 # There should be exactly one parent expression.
558 unless ( 1 == scalar @{$r->{expr}} )
559 {
560 FAIL("Multiple parent expressions for rule: $node->{name} " .
561 "$r->{attn_type}");
562 }
563 my $expr = $r->{expr}->[0];
564
565 my @node_insts = BitRange::expand($r->{node_inst});
566 my $sz_insts = scalar @node_insts;
567
568 # Expand the expression for each node instance.
569 for my $idx ( 0 .. ($sz_insts - 1) )
570 {
571 my $ni = $node_insts[$idx];
572
573 # Check for duplicates.
574 if ( defined $rule_dups->{$r->{attn_type}}->{$ni} )
575 {
576 FAIL("Duplicate rule: $node->{name} $r->{attn_type} $ni");
577 }
578 else
579 {
580 $rule_dups->{$r->{attn_type}}->{$ni} = 1;
581 }
582
583 # Add the rule for this expression.
584 push @{$insts_data->{$ni}->{rule}},
585 { attn_type => $r->{attn_type},
586 expr => __normalizeExpr($expr, $ni, $idx, $sz_insts) };
587 }
588 }
589
590 # Clean up this node's rule data.
591 delete $node->{rule};
592}
593
594#-------------------------------------------------------------------------------
595
596sub __normalizeBit($$$)
597{
598 my ( $node, $sigs, $insts_data ) = @_;
599
Zane Shelleyabc51c22020-11-09 21:35:35 -0600600 my @node_insts = sort keys %{$insts_data};
601 my $sz_insts = scalar @node_insts;
602
603 # There should be only one child node per node instance bit position.
604 my $child_dups = {};
605
606 for my $b ( sort {$a->{pos} cmp $b->{pos}} @{$node->{bit}} )
607 {
608 my @child_insts = ();
609
610 # Ensure child_node and node_inst are set properly.
611 if ( defined $b->{child_node} )
612 {
613 # Ensure each bit has a default node_inst attribute if needed.
614 $b->{node_inst} = "0" unless ( defined $b->{node_inst} );
615
616 # Get all of the instances for this child node.
617 @child_insts = BitRange::expand($b->{node_inst});
618
619 # Both inst list must be equal in size.
620 unless ( $sz_insts == scalar @child_insts )
621 {
622 FAIL("node_inst attribute list size for node:$node->{name} " .
623 "bit:$b->{pos} does not match node instances " .
624 "represented by the <rule> element");
625 }
626 }
627 elsif ( defined $b->{node_inst} )
628 {
629 FAIL("node_inst attribute exists for node:$node->{name} " .
630 "bit:$b->{pos} with no child_node attribute");
631 }
632
633 # Get the signatures for each node, instance, and bit position.
634 for my $p ( BitRange::expand($b->{pos}) )
635 {
636 for my $i ( 0 .. ($sz_insts-1) )
637 {
638 my ( $n, $ni ) = ( $node->{name}, $node_insts[$i] );
639
640 # This is to cover a bug in the figtree information where there
641 # currently is no comment for some bits.
642 $b->{content} = "" unless ( defined $b->{content} );
643
Zane Shelleyd6826e52020-11-10 17:39:00 -0600644 for my $model_ec ( __expandModelEc($node->{model_ec}) )
Zane Shelleyabc51c22020-11-09 21:35:35 -0600645 {
Zane Shelleyd6826e52020-11-10 17:39:00 -0600646 # Check if this signature already exists.
647 if ( defined $sigs->{$model_ec}->{$n}->{$ni}->{$p} and
648 $b->{content} ne $sigs->{$model_ec}->{$n}->{$ni}->{$p} )
649 {
650 FAIL("Duplicate signature for $n $ni $p");
651 }
Zane Shelleyabc51c22020-11-09 21:35:35 -0600652
Zane Shelleyd6826e52020-11-10 17:39:00 -0600653 # Get the signatures for each node, instance, and bit
654 # position.
655 $sigs->{$model_ec}->{$n}->{$ni}->{$p} = $b->{content};
656 }
Zane Shelleyabc51c22020-11-09 21:35:35 -0600657
658 # Move onto the next instance unless a child node exists.
659 next unless ( defined $b->{child_node} );
660
661 my $pi = $child_insts[$i];
662
663 my $child = { pos => $p,
664 child_node => $b->{child_node},
665 node_inst => $pi };
666
667 # Ensure this child node doesn't already exist.
668 if ( defined $child_dups->{$ni}->{$p} and
669 not __dirtyCompare($child, $child_dups->{$ni}->{$p}) )
670 {
671 FAIL("Duplicate child_node for $n $ni $p");
672 }
673
674 # Add this child node.
675 push @{$insts_data->{$ni}->{bit}}, $child;
676 }
677 }
678 }
679
680 # Clean up this node's bit data.
681 delete $node->{bit};
682}
683
684#-------------------------------------------------------------------------------
685
686sub __normalizeNode($$$)
687{
688 my ( $node, $regs, $sigs ) = @_;
689
690 # Ensure a valid register type.
691 unless ( grep { /^$node->{reg_type}$/ } keys %{$REGISTER_TYPE} )
692 {
693 FAIL( "Unsupported register type: $node->{reg_type}" );
694 }
695
696 my $insts_data = {}; # Collect data for each instance of this node.
697
698 # First, expand the <local_fir> data if it exists.
699 __normalizeLocalFir($node);
700
701 # All registers will be put in a master register list for the chip.
702 __normalizeRegister($node, $regs);
703
704 # Split the capture group information per node instance.
705 __normalizeCaptureGroup($node, $insts_data);
706
Zane Shelleybcb43952021-07-08 22:13:57 -0500707 my $is_rule = (defined $node->{rule} and 0 < scalar @{$node->{rule}}) ? 1 : 0;
708 my $is_bit = (defined $node->{bit} and 0 < scalar @{$node->{bit}}) ? 1 : 0;
Zane Shelleyabc51c22020-11-09 21:35:35 -0600709
Zane Shelleybcb43952021-07-08 22:13:57 -0500710 # If a rule is defined, a bit must be defined as well. It is possible for
711 # neither to be defined (FFDC-only node).
712 if ( $is_rule and $is_bit )
713 {
714 # Split the rule information per node instance. The sorted instance list
715 # will be used as indexes for the node_inst attribute of the <bit>
716 # elements.
717 __normalizeRule($node, $insts_data);
718
719 # Finally, collect the signature details and split the bit information
720 # per node instance.
721 __normalizeBit($node, $sigs, $insts_data);
722 }
723 elsif ( $is_rule or $is_bit )
724 {
725 # One is defined and the other is not. This is an error.
726 FAIL("Node $node->{name} has a bit or rule defined and the other is not.");
727 }
Zane Shelleyabc51c22020-11-09 21:35:35 -0600728
729 # Now that we have all of the node data, collapse the instance data into
730 # a list.
731 for ( sort keys %{$insts_data} )
732 {
733 $insts_data->{$_}->{node_inst} = $_;
734 push @{$node->{instance}}, $insts_data->{$_};
735 }
736}
737
738#-------------------------------------------------------------------------------
739
740sub normalizeXML($)
741{
742 my ( $xml ) = @_;
743
744 my $data = {};
745
746 # Iterate each chip file.
747 for my $chip ( @{$xml->{chip}} )
748 {
749 # Iterate each model/EC.
750 for my $model_ec ( __expandModelEc($chip->{model_ec}) )
751 {
752 # Ensure there is not a duplicate definition for a model/EC.
753 if ( $data->{$model_ec}->{chip} )
754 {
755 FAIL("Duplicate data for model/EC $model_ec in:\n" .
756 " $data->{$model_ec}->{chip}->{path}\n" .
757 " $chip->{path}");
758 }
759
760 # Add this chip to the data.
761 $data->{$model_ec}->{attn_tree} = $chip->{attn_tree};
762 }
763 }
764
765 # Extract the data for each node.
766 my ( $regs, $sigs, $node_dups ) = ( {}, {}, {} );
767 for my $node ( sort { $a->{name} cmp $b->{name} } @{$xml->{node}} )
768 {
769 # A node may be defined for more than one model/EC.
770 for my $model_ec ( __expandModelEc($node->{model_ec}) )
771 {
772 # A node can only be defined once per model/EC.
773 if ( defined $node_dups->{$model_ec}->{$node->{name}} )
774 {
775 FAIL( "Duplicate node defined for $model_ec -> $node->{name} ");
776 }
777 else
778 {
779 $node_dups->{$model_ec}->{$node->{name}} = 1;
780 }
781
Zane Shelleyd6826e52020-11-10 17:39:00 -0600782 # Initialize the master list of registers and signatures of this
783 # model/EC, if necessary.
Zane Shelleyabc51c22020-11-09 21:35:35 -0600784
Zane Shelleyd6826e52020-11-10 17:39:00 -0600785 $regs->{$model_ec} = {} unless ( defined $regs->{$model_ec} );
786 $sigs->{$model_ec} = {} unless ( defined $sigs->{$model_ec} );
787 }
Zane Shelleyabc51c22020-11-09 21:35:35 -0600788
Zane Shelleyd6826e52020-11-10 17:39:00 -0600789 # The same node content will be used for each model/EC characterized by
790 # this node. There is some normalization that needs to happen because of
791 # shorthand elements, like <local_fir>, and some error checking. This
792 # only needs to be done once per node, not per model/EC.
793 __normalizeNode( $node, $regs, $sigs );
Zane Shelleyabc51c22020-11-09 21:35:35 -0600794
Zane Shelleyd6826e52020-11-10 17:39:00 -0600795 # Push the node data for each model/EC.
796 for my $model_ec ( __expandModelEc($node->{model_ec}) )
797 {
Zane Shelleyabc51c22020-11-09 21:35:35 -0600798 push @{$data->{$model_ec}->{node}}, $node;
799 }
800 }
801
802 # Sort and collapse the master register list.
803 for my $m ( keys %{$regs} )
804 {
805 for my $n ( sort keys %{$regs->{$m}} )
806 {
807 push @{$data->{$m}->{register}}, $regs->{$m}->{$n};
808 }
809 }
810
811 # Collapse the signature lists.
812 for my $m ( keys %{$sigs} )
813 {
814 for my $n ( sort keys %{$sigs->{$m}} )
815 {
816 for my $i ( sort {$a <=> $b} keys %{$sigs->{$m}->{$n}} )
817 {
818 for my $b ( sort {$a <=> $b} keys %{$sigs->{$m}->{$n}->{$i}} )
819 {
820 push @{$data->{$m}->{signature}},
821 { name => $n, inst => $i, bit => $b,
822 desc => $sigs->{$m}->{$n}->{$i}->{$b} };
823 }
824 }
825 }
826 }
827
828 return $data;
829}
830
831#-------------------------------------------------------------------------------
832# Output functions
833#-------------------------------------------------------------------------------
834
835# The $num passed into this function can be a numeric of string. All values are
836# converted to a hex string and then into the binary format. This helps avoid
837# portability issues with endianess. Requirements:
838# - Hex strings must start with '0x'.
839# - For portability, 64-bit numbers must be passed as a hex string.
840sub __bin($$$)
841{
842 my ( $fh, $bytes, $num ) = @_;
843
844 # $bytes must be a positive integer.
845 die "Invalid bytes: $bytes" unless ( 0 < $bytes );
846
847 my $str = ''; # Default invalid string
848
849 my $char = $bytes * 2; # Number of characters in the string.
850
851 # Check if $num is a hex string.
852 if ( $num =~ /^0[x|X](.*)/ )
853 {
854 $str = $1; # strip the '0x'
855 }
856 # Check if $num is string or numeric decimal integer (32-bit max).
857 elsif ( $num =~ /^[0-9]+$/ and $bytes <= 4 )
858 {
859 $str = sprintf("%0${char}x", $num); # Convert to hex string
860 }
861
862 # Check for a hex number with the valid size.
863 unless ( $str =~ /^[0-9a-fA-F]{$char}$/ )
864 {
865 die "Invalid number: $num (size: $bytes)";
866 }
867
868 # Print the binary string.
869 print $fh pack( "H$char", $str );
870}
871
872#-------------------------------------------------------------------------------
873
874sub __hash($$)
875{
876 my $bytes = shift;
877 my @str = unpack("C*", shift); # returns an array of ascii values
878
879 # Currently only supporting 1, 2, 3, and 4 byte hashes.
880 unless ( 1 <= $bytes and $bytes <= 4 )
881 {
882 FAIL("Unsupported hash size: $bytes");
883 }
884
885 # Add padding to the end of the character array so that the size is
886 # divisible by $bytes.
887 push @str, 0 until ( 0 == scalar(@str) % $bytes );
888
889 # This hash is a simple "n*s[0] + (n-1)*s[1] + ... + s[n-1]" algorithm,
890 # where s[i] is a $bytes size chunk of the input string.
891
892 my ( $sumA, $sumB ) = ( 0, 0 );
893 while ( my @chunk = splice @str, 0, $bytes )
894 {
895 # Combine the chunk array into a single value.
896 my $val = 0; for ( @chunk ) { $val <<= 8; $val |= $_; }
897
898 # Apply the simple hash.
899 $sumA += $val;
900 $sumB += $sumA;
901 }
902
903 # Mask off everything except the target number of bytes.
904 $sumB &= 0xffffffff >> ((4 - $bytes) * 8);
905
906 return $sumB;
907}
908
909#-------------------------------------------------------------------------------
910
911sub __printRegisters($$)
912{
913 my ( $fh, $data ) = @_;
914
915 my $num_regs = scalar @{$data};
916 FAIL("No registers defined") unless ( 0 < $num_regs );
917
918 # Register list metadata
919 __bin($fh, 1, $_) for ( unpack("C*", "REGS") );
920 __bin($fh, 3, $num_regs);
921
922 my $reg_ids = {}; # for hash duplicate checking
923
924 for my $r ( @{$data} )
925 {
926 # Get the hash of the register name and check for duplicates.
927 my $id = __hash(3, $r->{name});
928 if ( defined $reg_ids->{$id} )
929 {
930 FAIL("Duplicate register ID hash " . sprintf('0x%08x', $id) .
931 " for $r->{name} and $reg_ids->{$id}");
932 }
933 else
934 {
935 $reg_ids->{$id} = $r->{name};
936 }
937
938 # Get the attribute flags.
939 my $flags = 0x00;
940 $flags |= 0x80 if ( $r->{access} =~ /R/ );
941 $flags |= 0x40 if ( $r->{access} =~ /W/ );
942
943 # Get the number of address instances.
944 my $num_inst = scalar @{$r->{instance}};
945 unless ( 0 < $num_inst )
946 {
947 FAIL("No register instances defined for $r->{name}");
948 }
949
950 # Register metadata
951 __bin($fh, 3, $id );
952 __bin($fh, 1, $REGISTER_TYPE->{$r->{reg_type}}->{id});
953 __bin($fh, 1, $flags );
954 __bin($fh, 1, $num_inst);
955
956 for my $i ( @{$r->{instance}} )
957 {
958 my $s = $REGISTER_TYPE->{$r->{reg_type}}->{addr_size};
959
960 # Register Instance metadata
961 __bin($fh, 1, $i->{reg_inst});
962 __bin($fh, $s, $i->{addr} );
963 }
964 }
965}
966
967#-------------------------------------------------------------------------------
968
969sub __printExpr($$$);
970
971sub __printExpr($$$)
972{
973 my ( $fh, $size, $expr ) = @_;
974
975 my ( $t, $e, $v1, $v2 ) = ( $expr->{type}, $expr->{expr},
976 $expr->{value1}, $expr->{value2} );
977
978 if ( "reg" eq $t )
979 {
980 __bin($fh, 1, 0x01); # expression type for "reg"
981 __bin($fh, 3, __hash(3,$v1)); # register id
982 __bin($fh, 1, $v2); # register instance
983 }
984 elsif ( "int" eq $t )
985 {
986 __bin($fh, 1, 0x02); # expression type for "int"
987 __bin($fh, $size, $v1); # integer value
988 }
989 elsif ( "and" eq $t )
990 {
991 __bin($fh, 1, 0x10); # expression type for "and"
992 __bin($fh, 1, scalar @{$e}); # number of sub-expressions
993 __printExpr($fh, $size, $_) for ( @{$e} ); # add each sub-expression
994 }
995 elsif ( "or" eq $t )
996 {
997 __bin($fh, 1, 0x11); # expression type for "or"
998 __bin($fh, 1, scalar @{$e}); # number of sub-expressions
999 __printExpr($fh, $size, $_) for ( @{$e} ); # add each sub-expression
1000 }
1001 elsif ( "not" eq $t )
1002 {
1003 __bin($fh, 1, 0x12); # expression type for "not"
1004 __printExpr($fh, $size, $e->[0]); # add only sub-expression
1005 }
1006 elsif ( "lshift" eq $t )
1007 {
1008 __bin($fh, 1, 0x13); # expression type for "lshift"
1009 __bin($fh, 1, $v1); # shift amount
1010 __printExpr($fh, $size, $e->[0]); # add only sub-expression
1011 }
1012 elsif ( "rshift" eq $t )
1013 {
1014 __bin($fh, 1, 0x14); # expression type for "rshift"
1015 __bin($fh, 1, $v1); # shift amount
1016 __printExpr($fh, $size, $e->[0]); # add only sub-expression
1017 }
1018}
1019
1020#-------------------------------------------------------------------------------
1021
1022sub __printNodes($$)
1023{
1024 my ( $fh, $data ) = @_;
1025
1026 my $num_nodes = scalar @{$data};
1027 FAIL("No nodes defined") unless ( 0 < $num_nodes );
1028
1029 # Isolation Node list metadata
1030 __bin($fh, 1, $_) for ( unpack("C*", "NODE") );
1031 __bin($fh, 2, $num_nodes);
1032
1033 my $node_ids = {}; # for hash duplicate checking
1034
1035 for my $n ( @{$data} )
1036 {
1037 # Get the hash of the node name and check for duplicates.
1038 my $id = __hash(2, $n->{name});
1039 if ( defined $node_ids->{$id} )
1040 {
1041 FAIL("Duplicate node ID hash " . sprintf('0x%08x', $id) .
1042 " for $n->{name} and $node_ids->{$id}");
1043 }
1044 else
1045 {
1046 $node_ids->{$id} = $n->{name};
1047 }
1048
1049 my $num_insts = scalar @{$n->{instance}};
1050 unless ( 0 < $num_insts )
1051 {
1052 FAIL("No nodes instances defined for $n->{name}");
1053 }
1054
1055 my $reg_type = $REGISTER_TYPE->{$n->{reg_type}}->{id};
1056 my $reg_size = $REGISTER_TYPE->{$n->{reg_type}}->{reg_size};
1057
1058 # Register metadata
1059 __bin($fh, 2, $id);
1060 __bin($fh, 1, $reg_type);
1061 __bin($fh, 1, $num_insts);
1062
1063 for my $i ( @{$n->{instance}} )
1064 {
1065 # Capture groups are optional.
1066 my $num_cap_regs = (defined $i->{capture_group})
1067 ? scalar @{$i->{capture_group}} : 0;
1068
Zane Shelleybcb43952021-07-08 22:13:57 -05001069 # Rules may not exist for this node.
1070 my $num_rules = (defined $i->{rule}) ? scalar @{$i->{rule}} : 0;
Zane Shelleyabc51c22020-11-09 21:35:35 -06001071
1072 # Child nodes may not exist for this node.
1073 my $num_bit = (defined $i->{bit}) ? scalar @{$i->{bit}} : 0;
1074
1075 # Register instance metadata
1076 __bin($fh, 1, $i->{node_inst});
1077 __bin($fh, 1, $num_cap_regs );
1078 __bin($fh, 1, $num_rules );
1079 __bin($fh, 1, $num_bit );
1080
1081 if ( 0 < $num_cap_regs )
1082 {
1083 for my $cg ( @{$i->{capture_group}} )
1084 {
1085 # Register capture register metadata
1086 __bin($fh, 3, __hash(3, $cg->{reg_name}));
1087 __bin($fh, 1, $cg->{reg_inst} );
1088 }
1089 }
1090
Zane Shelleybcb43952021-07-08 22:13:57 -05001091 if ( 0 < $num_rules )
Zane Shelleyabc51c22020-11-09 21:35:35 -06001092 {
Zane Shelleybcb43952021-07-08 22:13:57 -05001093 for my $r ( @{$i->{rule}} )
1094 {
1095 # Register rule metadata
1096 __bin($fh, 1, $ATTN_TYPE->{$r->{attn_type}}->[0]);
1097 __printExpr($fh, $reg_size, $r->{expr});
1098 }
Zane Shelleyabc51c22020-11-09 21:35:35 -06001099 }
1100
1101 if ( 0 < $num_bit )
1102 {
1103 for my $b ( @{$i->{bit}} )
1104 {
1105 # Register child node metadata
1106 __bin($fh, 1, $b->{pos} );
1107 __bin($fh, 2, __hash(2, $b->{child_node}));
1108 __bin($fh, 1, $b->{node_inst} );
1109 }
1110 }
1111 }
1112 }
1113}
1114
1115#-------------------------------------------------------------------------------
1116
1117sub __printAttnTree($$)
1118{
1119 my ( $fh, $data ) = @_;
1120
1121 my $num_root_nodes = scalar @{$data};
1122 FAIL("No root nodes defined") unless ( 0 < $num_root_nodes );
1123
1124 # Root Node list metadata
1125 __bin($fh, 1, $_) for ( unpack("C*", "ROOT") );
1126 __bin($fh, 1, $num_root_nodes);
1127
1128 for my $r ( @{$data} )
1129 {
1130 # Root Node metadata
Zane Shelley3d308902021-06-04 16:35:33 -05001131 __bin($fh, 1, $ATTN_TYPE->{$r->{attn_type}}->[0]);
1132 __bin($fh, 2, __hash(2, $r->{root_node}) );
1133 __bin($fh, 1, $r->{node_inst} );
Zane Shelleyabc51c22020-11-09 21:35:35 -06001134 }
1135}
1136
1137#-------------------------------------------------------------------------------
1138
Zane Shelley0a905012021-04-26 17:07:24 -05001139sub __printParserData($$$$)
Zane Shelleyabc51c22020-11-09 21:35:35 -06001140{
Zane Shelley0a905012021-04-26 17:07:24 -05001141 my ( $fh, $model_ec, $sig_list, $reg_list) = @_;
Zane Shelleyabc51c22020-11-09 21:35:35 -06001142
Zane Shelley74678c12021-06-04 15:46:16 -05001143 # IMPORTANT: All hash keys with hex values must be lowercase.
1144
Zane Shelley3d308902021-06-04 16:35:33 -05001145 my $attns = {};
Zane Shelley0a905012021-04-26 17:07:24 -05001146 my $regs = {};
1147 my $sigs = {};
Zane Shelleyabc51c22020-11-09 21:35:35 -06001148
Zane Shelley13d04082021-06-04 08:40:48 -05001149 # Get the chip info.
1150 my $info = $SUPPORTED_MODEL_EC->{$model_ec};
1151 $info->{'id'} = sprintf('%08x', $info->{'id'});
1152
Zane Shelley3d308902021-06-04 16:35:33 -05001153 # Get the list of attention types.
1154 while ( my ($k, $v) = each %{$ATTN_TYPE} )
1155 {
1156 $attns->{$v->[0]} = $v->[1];
1157 }
1158
Zane Shelleybc3c0402021-06-04 16:11:21 -05001159 # Get the signature data.
Zane Shelley0a905012021-04-26 17:07:24 -05001160 for my $s ( @{$sig_list} )
Zane Shelleyabc51c22020-11-09 21:35:35 -06001161 {
Zane Shelleybc3c0402021-06-04 16:11:21 -05001162 # Format is:
1163 # { id : [ name, { bit : desc, ... } ], ... }
Zane Shelley0a905012021-04-26 17:07:24 -05001164
Zane Shelleybc3c0402021-06-04 16:11:21 -05001165 # The ID is a 2-byte hash of the node name (lowercase).
1166 my $id = sprintf('%04x', __hash(2, $s->{name}));
1167
1168 if ( exists($sigs->{$id}) )
Zane Shelley0a905012021-04-26 17:07:24 -05001169 {
Zane Shelleybc3c0402021-06-04 16:11:21 -05001170 # Check for hash collisions.
1171 if ($sigs->{$id}->[0] ne $s->{name} )
1172 {
1173 FAIL("Node hash collision for $id: $sigs->{$id}->[0] " .
1174 "and $s->{name}");
1175 }
1176 }
1177 else
1178 {
1179 # Initialize this node.
1180 $sigs->{$id} = [ $s->{name}, {} ];
Zane Shelley0a905012021-04-26 17:07:24 -05001181 }
1182
Zane Shelleybc3c0402021-06-04 16:11:21 -05001183 # Check for signature collisions.
1184 if ( exists($sigs->{$id}->[1]->{$s->{bit}}) )
Zane Shelley0a905012021-04-26 17:07:24 -05001185 {
Zane Shelleybc3c0402021-06-04 16:11:21 -05001186 # Check for signature collisions.
1187 if ( $sigs->{$id}->[1]->{$s->{bit}} ne $s->{desc} )
1188 {
1189 FAIL("Multiple signatures for $s->{name} bit $s->{bit}:\n" .
1190 " $sigs->{$id}->[1]->{$s->{bit}}\n" .
1191 " $s->{desc}");
1192 }
Zane Shelley0a905012021-04-26 17:07:24 -05001193 }
Zane Shelleybc3c0402021-06-04 16:11:21 -05001194 else
1195 {
1196 # Set the signature for this bit.
1197 $sigs->{$id}->[1]->{$s->{bit}} = $s->{desc};
1198 }
Zane Shelleyabc51c22020-11-09 21:35:35 -06001199 }
Zane Shelley0a905012021-04-26 17:07:24 -05001200
Zane Shelley74678c12021-06-04 15:46:16 -05001201 # Get the register data.
Zane Shelley0a905012021-04-26 17:07:24 -05001202 for my $r ( @{$reg_list} )
1203 {
Zane Shelley74678c12021-06-04 15:46:16 -05001204 # Format is:
1205 # { id : [ name, { inst : addr, ... } ], ... }
1206
1207 # The ID is a 3-byte hash of the register name (lowercase).
Zane Shelley0a905012021-04-26 17:07:24 -05001208 my $id = sprintf('%06x', __hash(3, $r->{name}));
1209
Zane Shelley74678c12021-06-04 15:46:16 -05001210 if ( exists($regs->{$id}) )
Zane Shelley0a905012021-04-26 17:07:24 -05001211 {
Zane Shelley74678c12021-06-04 15:46:16 -05001212 # Check for hash collisions.
1213 if ( $regs->{$id}->[0] ne $r->{name} )
1214 {
1215 FAIL("Register hash collision for $id: " .
1216 "$regs->{$id}->[0] and $r->{name}");
1217 }
1218 }
1219 else
1220 {
1221 # Initialize this register.
1222 $regs->{$id} = [ $r->{name}, {} ];
Zane Shelley0a905012021-04-26 17:07:24 -05001223 }
1224
Zane Shelley74678c12021-06-04 15:46:16 -05001225 # Add the address for each instance of the register (shouldn't have to
1226 # worry about duplicates).
1227 for ( @{$r->{instance}} )
1228 {
1229 $regs->{$id}->[1]->{$_->{reg_inst}} = $_->{addr};
1230 }
Zane Shelley0a905012021-04-26 17:07:24 -05001231 }
1232
1233 my $data =
1234 {
Zane Shelley13d04082021-06-04 08:40:48 -05001235 'model_ec' => $info,
Zane Shelley3d308902021-06-04 16:35:33 -05001236 'attn_types' => $attns,
Zane Shelleybc3c0402021-06-04 16:11:21 -05001237 'registers' => $regs,
1238 'signatures' => $sigs,
Zane Shelley0a905012021-04-26 17:07:24 -05001239 };
1240
1241 print $fh to_json( $data, {utf8 => 1, pretty => 1, canonical => 1} );
Zane Shelleyabc51c22020-11-09 21:35:35 -06001242}
1243
1244#-------------------------------------------------------------------------------
1245
Zane Shelley738276a2021-05-24 12:55:34 -05001246sub buildDataFiles($$)
Zane Shelleyabc51c22020-11-09 21:35:35 -06001247{
1248 my ( $dir, $data ) = @_;
1249
1250 while ( my ($model_ec, $chip) = each %{$data} )
1251 {
1252 unless ( defined $chip->{register} )
1253 {
1254 FAIL("Chip $model_ec does not contain registers");
1255 }
1256 unless ( defined $chip->{node} )
1257 {
1258 FAIL("Chip $model_ec does not contain nodes");
1259 }
1260 unless ( defined $chip->{attn_tree} )
1261 {
1262 FAIL("Chip $model_ec does not contain attn_tree information");
1263 }
Zane Shelley0a905012021-04-26 17:07:24 -05001264 unless ( defined $chip->{signature} )
1265 {
1266 FAIL("Chip $model_ec does not contain signatures");
1267 }
1268
1269 # Chip Data Binary files ###############################################
Zane Shelleyabc51c22020-11-09 21:35:35 -06001270
Zane Shelley738276a2021-05-24 12:55:34 -05001271 if ( $gen_cdb )
1272 {
1273 my $bin_file = "$dir/chip_data_" . lc $model_ec . ".cdb";
1274 open my $bin_fh, '>', $bin_file or die "Cannot open $bin_file: $!";
1275 binmode $bin_fh; # writes a binary file
Zane Shelleyabc51c22020-11-09 21:35:35 -06001276
Zane Shelley738276a2021-05-24 12:55:34 -05001277 # Chip Data File metadata
1278 __bin($bin_fh, 1, $_) for ( unpack("C*", "CHIPDATA") );
Zane Shelley13d04082021-06-04 08:40:48 -05001279 __bin($bin_fh, 4, $SUPPORTED_MODEL_EC->{$model_ec}->{id});
1280 __bin($bin_fh, 1, $FILE_VERSION->{VER_01} );
Zane Shelleyabc51c22020-11-09 21:35:35 -06001281
Zane Shelley738276a2021-05-24 12:55:34 -05001282 __printRegisters( $bin_fh, $chip->{register} );
1283 __printNodes( $bin_fh, $chip->{node} );
1284 __printAttnTree( $bin_fh, $chip->{attn_tree} );
Zane Shelleyabc51c22020-11-09 21:35:35 -06001285
Zane Shelley738276a2021-05-24 12:55:34 -05001286 close $bin_fh;
1287 }
Zane Shelleyabc51c22020-11-09 21:35:35 -06001288
Zane Shelley0a905012021-04-26 17:07:24 -05001289 # eBMC PEL parsing JSON ################################################
Zane Shelleyabc51c22020-11-09 21:35:35 -06001290
Zane Shelley738276a2021-05-24 12:55:34 -05001291 if ( $gen_json )
1292 {
1293 my $file = "$dir/pel_parser_data_" . lc $model_ec . ".json";
1294 open my $fh, '>', $file or die "Cannot open $file: $!";
Zane Shelleyabc51c22020-11-09 21:35:35 -06001295
Zane Shelley738276a2021-05-24 12:55:34 -05001296 __printParserData( $fh, $model_ec, $chip->{signature},
1297 $chip->{register} );
Zane Shelleyabc51c22020-11-09 21:35:35 -06001298
Zane Shelley738276a2021-05-24 12:55:34 -05001299 close $fh;
1300 }
Zane Shelleyabc51c22020-11-09 21:35:35 -06001301 }
1302}
1303