summaryrefslogtreecommitdiffstats
path: root/src/build/debug/Hostboot/HwpfAttrOverride.pm
blob: ef595bcee9b9d5b7aa815927b036c60f33281146 (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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
#!/usr/bin/perl
#  IBM_PROLOG_BEGIN_TAG
#  This is an automatically generated prolog.
#
#  $Source: src/build/debug/Hostboot/HwpfAttrOverride.pm $
#
#  IBM CONFIDENTIAL
#
#  COPYRIGHT International Business Machines Corp. 2012
#
#  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 other-
#  wise divested of its trade secrets, irrespective of what has
#  been deposited with the U.S. Copyright Office.
#
#  Origin: 30
#
#  IBM_PROLOG_END_TAG

#
# This perl module will be used in a standalone Hostboot environment
# (Simics or VBU) to process a FAPI Attribute Override Text File and
# send the overrides to Hostboot
#
# Author: Mike Jones
#

use strict;
package Hostboot::HwpfAttrOverride;
use Hostboot::_DebugFrameworkVMM;
use Hostboot::CallFunc;
use Exporter;
our @EXPORT_OK = ('main');

#------------------------------------------------------------------------------
# Constants
#------------------------------------------------------------------------------

# From fapiTarget.H
use constant TARGET_TYPE_SYSTEM => 0x00000001;
use constant TARGET_TYPE_DIMM => 0x00000002;
use constant TARGET_TYPE_PROC_CHIP => 0x00000004;
use constant TARGET_TYPE_MEMBUF_CHIP => 0x00000008;
use constant TARGET_TYPE_EX_CHIPLET => 0x00000010;
use constant TARGET_TYPE_MBA_CHIPLET => 0x00000020;
use constant TARGET_TYPE_MCS_CHIPLET => 0x00000040;
use constant TARGET_TYPE_XBUS_ENDPOINT => 0x00000080;
use constant TARGET_TYPE_ABUS_ENDPOINT => 0x00000100;

# From fapiAttributeTank.H
use constant ATTR_POS_NA => 0xffff;
use constant ATTR_UNIT_POS_NA => 0xff;
use constant ATTR_ARRAYD_NA => 0xff;
use constant ATTR_FLAG_CONST => 1;

# From fapiPlatAttrOverrideDirect.C
my $overrideSymbol = 'fapi::g_attrOverride';

# Expected filenames
my $attributeIdsFileName = 'fapiAttributeIds.txt';
my $attributeEnumsFileName = 'fapiAttributeEnums.txt';
my $overrideFileName = 'OverrideAttrs.txt';

sub main
{
    my ($packName,$args) = @_;
    my $debug = 0;
    if (defined $args->{"debug"})
    {
        $debug = 1;
    }

    #--------------------------------------------------------------------------
    # Check if the Attribute IDs/Enums and Attribute Overrides files exist
    #--------------------------------------------------------------------------
    my $attributeIdsFile = ::getImgPath();
    $attributeIdsFile = $attributeIdsFile."$attributeIdsFileName";
    unless (-e $attributeIdsFile)
    {
        die "Cannot find file $attributeIdsFile";
    }

    my $attributeEnumsFile = ::getImgPath();
    $attributeEnumsFile = $attributeEnumsFile."$attributeEnumsFileName";
    unless (-e $attributeEnumsFile)
    {
        die "Cannot find file $attributeEnumsFile";
    }

    my $overrideFile = ::getImgPath();
    $overrideFile = $overrideFile."$overrideFileName";
    unless (-e $overrideFile)
    {
        die "Cannot find file $overrideFile";
    }

    #--------------------------------------------------------------------------
    # Process the Attribute ID file. Record the values of the Attribute IDs in
    # a hash
    #--------------------------------------------------------------------------
    my %attributeIdVals;

    open(IDFILE, "< $attributeIdsFile") or die "Cannot open file $attributeIdsFile";
    while (my $line = <IDFILE>)
    {
        chomp($line);

        if ($line =~ /(ATTR_\S+) 0x(\S+)/)
        {
            # Found an attribute ID
            $attributeIdVals{$1} = hex $2
        }
    }
    close(IDFILE);

    #--------------------------------------------------------------------------
    # Process the Attribute ENUM file. Record the values of the Attribute ENUMs
    # in a hash
    #--------------------------------------------------------------------------
    my %attributeEnumVals;

    open(ENUMFILE, "< $attributeEnumsFile") or die "Cannot open file $attributeEnumsFile";
    while (my $line = <ENUMFILE>)
    {
        # Note that enumerated values can end with 'ULL'
        if ($line =~ /(ATTR_\S+) = 0x([a-fA-F0-9]+)/)
        {
            # Found a hex attribute value enumeration
            $attributeEnumVals{$1} = hex $2;
        }
        elsif ($line =~ /(ATTR_\S+) = ([0-9]+)/)
        {
            # Found a decimal attribute value enumeration
            $attributeEnumVals{$1} = $2;
        }
    }
    close(ENUMFILE);

    # Debug output
    if ($debug)
    {
        foreach my $key (keys %attributeIdVals)
        {
            ::userDisplay "AttrIdVal: $key => $attributeIdVals{$key}\n";
        }
        foreach my $key (keys %attributeEnumVals)
        {
            ::userDisplay "AttrEnumVal: $key => $attributeEnumVals{$key}\n";
        }
    }

    #--------------------------------------------------------------------------
    # Process the Attribute Overrides file. Record the information for each
    # override in arrays
    #--------------------------------------------------------------------------
    my @attrIdString;
    my @val;
    my @attrId;
    my @targetType;
    my @pos;
    my @unitPos;
    my @flags;
    my @arrayD1;
    my @arrayD2;
    my @arrayD3;
    my @arrayD4;

    my $numOverrides = 0;
    my $curTargetType = TARGET_TYPE_SYSTEM;
    my $curPos = ATTR_POS_NA;
    my $curUnitPos = ATTR_UNIT_POS_NA;

    open(OVFILE, "< $overrideFile") or die "Cannot open file $overrideFile";

    while (my $line = <OVFILE>)
    {
        chomp($line);

        if ($line =~ /^target = /)
        {
            # Found a target
            my $p8pres = 0;

            # Figure out the target type
            if ($line =~ /p8.ex/)
            {
                $p8pres = 1;
                $curTargetType = TARGET_TYPE_EX_CHIPLET;
            }
            elsif ($line =~ /centaur.mba/)
            {
                $curTargetType = TARGET_TYPE_MBA_CHIPLET;
            }
            elsif ($line =~ /p8.mcs/)
            {
                $p8pres = 1;
                $curTargetType = TARGET_TYPE_MCS_CHIPLET;
            }
            elsif ($line =~ /p8.xbus/)
            {
                $p8pres = 1;
                $curTargetType = TARGET_TYPE_XBUS_ENDPOINT;
            }
            elsif ($line =~ /p8.abus/)
            {
                $p8pres = 1;
                $curTargetType = TARGET_TYPE_ABUS_ENDPOINT;
            }
            elsif ($line =~ /centaur/)
            {
                $curTargetType = TARGET_TYPE_MEMBUF_CHIP;
            }
            elsif ($line =~ /p8/)
            {
                $p8pres = 1;
                $curTargetType = TARGET_TYPE_PROC_CHIP;
            }
            elsif ($line =~ /dimm/)
            {
                $curTargetType = TARGET_TYPE_DIMM;
            }
            else
            {
                $curTargetType = TARGET_TYPE_SYSTEM;
            }

            # Figure out the position
            if ($p8pres == 1)
            {
                # Do not confuse 'p8' for position 8
                if ($line =~ /p8\S*:p(\d+)/)
                {
                    $curPos = $1;
                }
                else
                {
                    $curPos = ATTR_POS_NA;
                }
            }
            else
            {
                if ($line =~ /:p(\d+)/)
                {
                    $curPos = $1;
                }
                else
                {
                    $curPos = ATTR_POS_NA;
                }
            }

            # Figure out the unit position
            if ($line =~ /:c(\d+)/)
            {
                $curUnitPos = $1;
            }
            else
            {
                $curUnitPos = ATTR_UNIT_POS_NA;
            }
        }
        elsif ($line =~ /^(ATTR_\w+)/)
        {
            # Found an override
            $attrIdString[$numOverrides] = $1;
            $targetType[$numOverrides] = $curTargetType;
            $pos[$numOverrides] = $curPos;
            $unitPos[$numOverrides] = $curUnitPos;

            # Figure out the attribute ID
            if (exists $attributeIdVals{$1})
            {
                $attrId[$numOverrides] = $attributeIdVals{$1};
            }
            else
            {
                ::userDisplay "Cannot find ID $1 in $attributeIdsFile\n";
                die; 
            }

            # Figure out the attribute array dimensions
            if ($line =~ /^ATTR_\w+\[(\d)\]\[(\d)\]\[(\d)\]\[(\d)\] /)
            {
                # 4D array override
                $arrayD1[$numOverrides] = $1;
                $arrayD2[$numOverrides] = $2;
                $arrayD3[$numOverrides] = $3;
                $arrayD4[$numOverrides] = $4;
            }
            elsif ($line =~ /^ATTR_\w+\[(\d)\]\[(\d)\]\[(\d)\] /)
            {
                # 3D array override
                $arrayD1[$numOverrides] = $1;
                $arrayD2[$numOverrides] = $2;
                $arrayD3[$numOverrides] = $3;
                $arrayD4[$numOverrides] = ATTR_ARRAYD_NA;
            }
            elsif ($line =~ /^ATTR_\w+\[(\d)\]\[(\d)\] /)
            {
                # 2D array override
                $arrayD1[$numOverrides] = $1;
                $arrayD2[$numOverrides] = $2;
                $arrayD3[$numOverrides] = ATTR_ARRAYD_NA;
                $arrayD4[$numOverrides] = ATTR_ARRAYD_NA;
            }
            elsif ($line =~ /^ATTR_\w+\[(\d)\] /)
            {
                # 1D array override
                $arrayD1[$numOverrides] = $1;
                $arrayD2[$numOverrides] = ATTR_ARRAYD_NA;
                $arrayD3[$numOverrides] = ATTR_ARRAYD_NA;
                $arrayD4[$numOverrides] = ATTR_ARRAYD_NA;
            }
            else
            {
                # Non-array attribute
                $arrayD1[$numOverrides] = ATTR_ARRAYD_NA;
                $arrayD2[$numOverrides] = ATTR_ARRAYD_NA;
                $arrayD3[$numOverrides] = ATTR_ARRAYD_NA;
                $arrayD4[$numOverrides] = ATTR_ARRAYD_NA;
            }

            # Figure out the override value
            if ($line =~ /^ATTR_\S+\s+([A-Za-z]+\S*)/)
            {
                # enumerator
                my $enum = "$attrIdString[$numOverrides]"."_$1";
                if (exists $attributeEnumVals{$enum})
                {
                    $val[$numOverrides] = $attributeEnumVals{$enum};
                }
                else
                {
                    ::userDisplay "Cannot find enum $enum in $attributeEnumsFile\n";
                    die;
                }
            }
            elsif ($line =~ /^ATTR_\S+\s+0x([0-9A-Za-z]+)/)
            {
                # Hex value
                $val[$numOverrides] = hex $1;
            }
            elsif ($line =~ /^ATTR_\S+\s+(\d+)/)
            {
                # Decimal Value
                $val[$numOverrides] = $1;
            }
            else
            {
                ::userDisplay "Cannot find override value for $attrIdString[$numOverrides]\n";
                die;
            }

            # Figure out if it is a const override
            if ($line =~ /CONST\s*/)
            {
                $flags[$numOverrides] = ATTR_FLAG_CONST;
            }
            else
            {
                $flags[$numOverrides] = 0;
            }

            # Debug output
            if ($debug)
            {
                ::userDisplay "OVERRIDE. Val: $val[$numOverrides]. ";
                ::userDisplay "ID: $attrId[$numOverrides]. ";
                ::userDisplay "TargType: $targetType[$numOverrides]. ";
                ::userDisplay "Pos: $pos[$numOverrides].$unitPos[$numOverrides].\n";
                ::userDisplay "          OFlags: $flags[$numOverrides]. ";
                ::userDisplay "Dims: $arrayD1[$numOverrides].";
                ::userDisplay "$arrayD2[$numOverrides].";
                ::userDisplay "$arrayD3[$numOverrides].";
                ::userDisplay "$arrayD4[$numOverrides]\n";
            }

            $numOverrides++;
        }
    }
    close(OVFILE);

    #--------------------------------------------------------------------------
    # Get the address of the Hostboot Attribute Override variable
    #--------------------------------------------------------------------------
    my $overrideSymAddr = (::findSymbolAddress("$overrideSymbol"))[0];

    if (not defined $overrideSymAddr)
    {
        ::userDisplay "Cannot find Hostboot symbol $overrideSymbol\n";
        die;
    }

    my $overrideAddr =
        Hostboot::_DebugFrameworkVMM::getPhysicalAddr($overrideSymAddr, $debug, 0);

    if ($overrideAddr eq Hostboot::_DebugFrameworkVMM::NotFound)
    {
        ::userDisplay "Cannot translate $overrideSymbol to a physical address\n";
        die;
    }

    # From fapiAttributeOverride.H
    # struct AttributeOverride
    # {
    #     uint64_t iv_val;        // Large enough to hold the biggest attribute size
    #     uint32_t iv_attrId;     // fapi::AttributeId enum value
    #     uint32_t iv_targetType; // fapi::TargetType enum value
    #     uint16_t iv_pos;        // For chips/dimms the position
    #                             // For chiplets the parent chip position
    #     uint8_t  iv_unitPos;    // For chiplets the position
    #     uint8_t  iv_flags;      // fapi::AttributeFlags enum value
    #     uint8_t  iv_arrayD1;    // Applies to element D1 in 1D or more array atts
    #     uint8_t  iv_arrayD2;    // Applies to element D2 in 2D or more array atts
    #     uint8_t  iv_arrayD3;    // Applies to element D3 in 3D or more array atts
    #     uint8_t  iv_arrayD4;    // Applies to element D4 in 4D array atts
    # };

    #--------------------------------------------------------------------------
    # Send the overrides to Hostboot
    #--------------------------------------------------------------------------    
    for (my $i = 0; $i < $numOverrides; $i++)
    {
        # Write override to Hostboot
        my $addr = $overrideAddr;
        ::write64($addr, $val[$i]);
        $addr += 8;
        ::write32($addr, $attrId[$i]);
        $addr += 4;
        ::write32($addr, $targetType[$i]);
        $addr += 4;
        ::write16($addr, $pos[$i]);
        $addr += 2;
        ::write8($addr, $unitPos[$i]);
        $addr++;
        ::write8($addr, $flags[$i]);
        $addr++;
        ::write8($addr, $arrayD1[$i]);
        $addr++;
        ::write8($addr, $arrayD2[$i]);
        $addr++;
        ::write8($addr, $arrayD3[$i]);
        $addr++;
        ::write8($addr, $arrayD4[$i]);

        # Tell Hostboot to process the override
        my $callFuncForce = 0;
        my @callFuncParms;
        Hostboot::CallFunc::execFunc("fapi::attrOverrideSync::directOverride()",
            $debug, $callFuncForce, \@callFuncParms);

        if ($debug)
        {
            ::userDisplay "$attrIdString[$i] sent\n";
        }
    }

    ::userDisplay "All $numOverrides override(s) successfully sent to Hostboot\n";
}

sub helpInfo
{
    my %info = (
        name => "HwpfAttrOverride",
        intro => ["Applies HWPF Attribute Overrides to Hostboot"],
        options => {
                    "debug" => ["More debug output."],
                   },
        notes => ["Looks for three files in the image directory",
                  "$attributeIdsFileName: Contains attribute id values",
                  "$attributeEnumsFileName: Contains attribute enum values",
                  "$overrideFileName: Contains the attribute overrides"]
    );
}
OpenPOWER on IntegriCloud