summaryrefslogtreecommitdiffstats
path: root/src/usr/hwpf/fapi/fapiCreateL3DeltaVals.pl
blob: 08093f8e7928ba37ecd3181000d717ffb4015e0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#!/usr/bin/perl -w
# IBM_PROLOG_BEGIN_TAG
# This is an automatically generated prolog.
#
# $Source: src/usr/hwpf/fapi/fapiCreateL3DeltaVals.pl $
#
# IBM CONFIDENTIAL
#
# COPYRIGHT International Business Machines Corp. 2013,2014
#
# p1
#
# Object Code Only (OCO) source materials
# Licensed Internal Code Source Materials
# IBM HostBoot Licensed Internal Code
#
# The source code for this program is not published or otherwise
# divested of its trade secrets, irrespective of what has been
# deposited with the U.S. Copyright Office.
#
# Origin: 30
#
# IBM_PROLOG_END_TAG
# $Id: fapiCreateL3DeltaVals.pl,v 1.3 2014/03/20 16:25:04 whs 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
#                                     
#
# 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 <stdlib.h>\n";
print OUTFILE "\n";
print OUTFILE "#include <fapiAttributeIds.H>\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 (<FILE>)
    {   
        # 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";
                }
                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  <output directory> [<attributes-file1> [<attributes-file2> ...]] [--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);
        }
    }
}
OpenPOWER on IntegriCloud