#!/usr/bin/perl -w # IBM_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # $Source: src/usr/hwpf/fapi/fapiCreateL3DeltaVals.pl $ # # OpenPOWER HostBoot Project # # Contributors Listed Below - COPYRIGHT 2013,2015 # [+] International Business Machines Corp. # # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or # implied. See the License for the specific language governing # permissions and limitations under the License. # # IBM_PROLOG_END_TAG # $Id: fapiCreateL3DeltaVals.pl,v 1.4 2014/12/17 23:43:11 thi Exp $ # # Purpose: This perl script will parse HWP Attribute XML files # and add attribute information to a file called fapiL3DeltaDataAttr.H # # Author: Dale Peterson # Last Updated: 09/20/2013 # # Version: 1.0 # # Change Log ********************************************************** # # Flag Track# Userid Date Description # ---- -------- -------- -------- ----------- # 873826 dpeterso 09/16/13 Based on fapiCreatePllRingAttrVals.pl # 920311 whs 03/23/14 PROC_EX_FUNC_L3_LENGTH from # mrw to hwp accessor # # # End Change Log ****************************************************** use strict; use Cwd 'chdir'; use Env; sub help; my $ProgName = "fapiCreateL3DeltaVals.pl"; my $ringAttrFile; my $outputPwd; my $DEBUG = 0; my $VERBOSE = 0; my $chip = ""; my $ec = ""; my $revision = ""; my $fileName = "fapiL3DeltaDataAttr.H"; my @fileList = (); #Pull out the args passed in &parseArgs; my $outputFile = "$outputPwd" . "$fileName"; my $line = ""; my $count = 0; my $dataCount = 0; # Start to generate header file. open (OUTFILE, ">$outputFile") or die "Couldn't open $outputFile for output. \n"; #Initial data types and definitions here print OUTFILE "// fapiL3DeltaDataAttr.H\n"; print OUTFILE "// This file is generated by perl script fapiCreateL3DeltaVals.pl\n"; print OUTFILE "\n"; print OUTFILE "\n"; print OUTFILE "#ifndef FAPIL3DELTADATAATTR_H_\n"; print OUTFILE "#define FAPIL3DELTADATAATTR_H_\n"; print OUTFILE "//----------------------------------------------------------------------\n"; print OUTFILE "// Includes\n"; print OUTFILE "//----------------------------------------------------------------------\n"; print OUTFILE "#include \n"; print OUTFILE "\n"; print OUTFILE "#include \n"; print OUTFILE "\n"; print OUTFILE "#define DELTA_DATA_SIZE 64\n"; # Create array structure for L3_DELTA_DATA attribute print OUTFILE "struct L3_DELTA_DATA_ATTR {\n"; print OUTFILE " uint8_t l_ATTR_SELECT;\n"; print OUTFILE " uint8_t l_ATTR_CHIPTYPE;\n"; print OUTFILE " uint8_t l_ATTR_EC;\n"; print OUTFILE " uint32_t l_ATTR_BIT_LENGTH;\n"; print OUTFILE " uint32_t l_ATTR_L3_DELTA_DATA[DELTA_DATA_SIZE];\n"; print OUTFILE "};\n"; print OUTFILE "\n"; print OUTFILE "\n" . "const L3_DELTA_DATA_ATTR L3_DELTA_DATA_array [] = {\n"; # Loop over all attribute files foreach $ringAttrFile (@fileList) { if ($ringAttrFile =~ m"(\S+/)?(\S+?)_(\d+?)_winkle_ring.attributes") { $chip = $2; $ec = $3; } else { die "$ProgName ERROR : Couldn't parse chip type and ec from file $ringAttrFile \n\n"; } my $count = 0; my $dataCount = 0; my $dataArrayString = ""; my $selectVal = 0; my $lengthVal = 0; # open the winkle ring attribute file open (FILE, "$ringAttrFile") or die "Couldn't open $ringAttrFile for input.\n"; if ($ringAttrFile =~ m"\S+/(\S+)") { my $fileName = $1; my $temp = `head -1 $ringAttrFile`; if ($temp =~ m"Id: $fileName,v (\S+)") { $revision = $1; } } if (($DEBUG) || ($VERBOSE)) { print "Chip: $chip \n"; print "EC: $ec \n"; print "File: $ringAttrFile \n"; print "Output File: $outputFile\n"; } #Embed some version info print OUTFILE "/**\n"; print OUTFILE " \@kdbfile $ringAttrFile\n"; print OUTFILE " \@chip $chip\n"; print OUTFILE " \@ec $ec\n"; print OUTFILE " \@version $revision\n"; print OUTFILE "*/\n"; while () { # Each section we are interested in begins with ===BEGIN and ends with ===END if (/\===BEGIN/../\===END/) { # Keep track of how many instances we have in the file and reset some sub-counters. if (/\===BEGIN/) { $count++; $dataCount = 0; } # Store select value in array if ($_ =~ m"^#SELECT=(\d)") { $selectVal = $1; } if ($_ =~ m"^ATTR_PROC_EX_FUNC_L3_LENGTH u32\s+(\d+)\s+") { $lengthVal = $1; if ($selectVal != ($count-1)) { die "$ProgName ERROR: Select value in file $ringAttrFile does not appear to be sequential. There may be a script problem or a corrupted ring attribute file.\n"; } my $chipEnum = 0; # Map chip type to fapi attribute enum values (p8=01, s1=02 if ($chip eq "s1") { $chipEnum = "fapi::ENUM_ATTR_NAME_MURANO"; } elsif ($chip eq "p8") { $chipEnum = "fapi::ENUM_ATTR_NAME_VENICE"; } elsif ($chip eq "n1") { $chipEnum = "fapi::ENUM_ATTR_NAME_NAPLES"; } else { die "$ProgName ERROR: Chip type $chip not supported by this script. Either the ring attribute file is in error or support for the new chip type needs to be added.\n"; } print OUTFILE "{\n"; print OUTFILE " $selectVal, \t// ATTR_PROC_PBIEX_ASYNC_SEL \n"; print OUTFILE " $chipEnum, \t// CHIP TYPE \n"; print OUTFILE " 0x$ec, \t// EC LEVEL \n"; print OUTFILE " $lengthVal, \t// RING LENGTH \n"; print OUTFILE " {\n"; } # Store values in array if ($_ =~ m"^ATTR_PROC_EX_FUNC_L3_DELTA_DATA\[(\d+)\]\s+\S+\s+(\S+)") { if ($dataCount != $1) { die "$ProgName: ERROR: Data array index value in file $ringAttrFile does not appear to be sequential. There may be a script problem or a corrupted ring attribute file.\n"; } $dataCount++; $dataArrayString = $dataArrayString . $2 . ", "; # If this is the last entry in the array (delta data size = 64 if ($dataCount eq 64) { print OUTFILE " $dataArrayString\n"; print OUTFILE " }, // ATTR_PROC_EX_FUNC_L3_DELTA_DATA\n"; print OUTFILE "},\n"; $dataArrayString = ""; } } } } close (FILE); } print OUTFILE "}; \n\n"; print OUTFILE "#endif // FAPIL3DELTADATAATTR_H_\n"; close (OUTFILE); exit 0; sub help { printf("Usage: $ProgName [ [ ...]] [--help|-h]\n"); printf("Generates C header file from KB winkle_ring.attributes file(s). \n"); printf("Example: $ProgName \$PWD p8_10_winkle_ring.attributes s1_10_winkle_ring.attributes -v\n\n"); exit(0); } sub parseArgs { #Note that arg 0 MUST be output dir. If no args are specified, usage is printed. if (!defined $ARGV[0]) { &help; } # Output directory is first parameter $outputPwd = $ARGV[0]; $outputPwd .= "/"; foreach my $argnum (1 .. $#ARGV) { my $Arg = $ARGV[$argnum]; if ($Arg =~ m"^--debug" || $Arg =~ m"^-d") { $DEBUG = 1; } elsif ($Arg =~ m"^--verbose" || $Arg =~ m"^-v") { $VERBOSE = 1; } elsif ($Arg =~ m"^--help" || $Arg =~ m"^-h") { &help; exit 1; } else { push(@fileList,$Arg); } } }