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
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
|
#!/usr/bin/perl
# IBM_PROLOG_BEGIN_TAG
# This is an automatically generated prolog.
#
# $Source: src/build/debug/Hostboot/HwpfAttrOverride.pm $
#
# OpenPOWER HostBoot Project
#
# COPYRIGHT International Business Machines Corp. 2012,2014
#
# 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
#
# 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 attributeTank.H
use constant ATTR_POS_NA => 0xffff;
use constant ATTR_UNIT_POS_NA => 0xff;
use constant ATTR_NODE_NA => 0xf;
use constant ATTR_FLAG_CONST => 1;
# From fapiPlatAttrOverrideSync.C
use constant MAX_DIRECT_OVERRIDE_ATTR_SIZE_BYTES => 64;
my $overrideHeaderSymbol = 'fapi::g_attrOverrideHeader';
my $overrideSymbol = 'fapi::g_attrOverride';
my $overrideFapiTankSymbol = 'fapi::g_attrOverrideFapiTank';
# Expected filenames
my $fapiAttrInfoFileName = 'fapiAttrInfo.csv';
my $fapiAttrEnumInfoFileName = 'fapiAttrEnumInfo.csv';
my $targAttrInfoFileName = 'targAttrInfo.csv';
my $overrideFileName = 'OverrideAttrs.txt';
sub main
{
my ($packName,$args) = @_;
my $debug = 0;
if (defined $args->{"debug"})
{
$debug = 1;
}
#--------------------------------------------------------------------------
# Get the address of the Hostboot Attribute Override variables
#--------------------------------------------------------------------------
my $overrideHeaderSymAddr = (::findSymbolAddress("$overrideHeaderSymbol"))[0];
if (not defined $overrideHeaderSymAddr)
{
::userDisplay "Cannot find Hostboot symbol '$overrideHeaderSymbol'\n";
die;
}
my $overrideHeaderAddr = Hostboot::_DebugFrameworkVMM::getPhysicalAddr(
$overrideHeaderSymAddr, $debug, 0);
if ($overrideHeaderAddr eq Hostboot::_DebugFrameworkVMM::NotFound)
{
::userDisplay "Cannot translate '$overrideHeaderSymbol' to a phys addr\n";
die;
}
#--------------------------------------------------------------------------
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 phys addr\n";
die;
}
#--------------------------------------------------------------------------
my $overrideFapiTankSymAddr = (::findSymbolAddress("$overrideFapiTankSymbol"))[0];
if (not defined $overrideFapiTankSymAddr)
{
::userDisplay "Cannot find Hostboot symbol '$overrideFapiTankSymbol'\n";
die;
}
my $overrideFapiTankAddr = Hostboot::_DebugFrameworkVMM::getPhysicalAddr(
$overrideFapiTankSymAddr, $debug, 0);
if ($overrideFapiTankAddr eq Hostboot::_DebugFrameworkVMM::NotFound)
{
::userDisplay "Cannot translate '$overrideFapiTankSymbol' to a phys addr\n";
die;
}
#--------------------------------------------------------------------------
# Check if the Attribute info and Override files exist
#--------------------------------------------------------------------------
my $fapiAttrInfoFile = ::getImgPath();
$fapiAttrInfoFile .= "$fapiAttrInfoFileName";
unless (-e $fapiAttrInfoFile)
{
die "Cannot find file '$fapiAttrInfoFile'";
}
my $fapiAttrEnumInfoFile = ::getImgPath();
$fapiAttrEnumInfoFile .= "$fapiAttrEnumInfoFileName";
unless (-e $fapiAttrEnumInfoFile)
{
die "Cannot find file '$fapiAttrEnumInfoFile'";
}
my $targAttrInfoFile = ::getImgPath();
$targAttrInfoFile .= "$targAttrInfoFileName";
unless (-e $targAttrInfoFile)
{
die "Cannot find file '$targAttrInfoFile'";
}
my $overrideFile = ::getImgPath();
$overrideFile = $overrideFile."$overrideFileName";
unless (-e $overrideFile)
{
die "Cannot find file '$overrideFile'";
}
#--------------------------------------------------------------------------
# Process the FAPI Attribute Info file. Record the ATTR-ID-VAL and
# ATTR-TYPE in a hash indexed by ATTR-ID-STR. Note that for FAPI Attributes
# FAPI-ATTR-ID-STR and LAYER-ATTR-ID-STR will be identical
#
# Format: <FAPI-ATTR-ID-STR>,<LAYER-ATTR-ID-STR>,<ATTR-ID-VAL>,<ATTR-TYPE>
#--------------------------------------------------------------------------
my %fapiAttrInfo;
open(FAPIATTFILE, "< $fapiAttrInfoFile") or die
"Cannot open file '$fapiAttrInfoFile'";
while (my $line = <FAPIATTFILE>)
{
chomp($line);
# Skip comment lines
if (!($line =~ /^#/))
{
if ($line =~ /(ATTR_\S+),ATTR_\S+,0x(\S+),(\S+)/)
{
$fapiAttrInfo{$1}->{idVal} = hex $2;
$fapiAttrInfo{$1}->{typeStr} = $3;
}
}
}
close(FAPIATTFILE);
#--------------------------------------------------------------------------
# Process the TARG Attribute Info file. Record the ATTR-ID-VAL and
# ATTR-TYPE in a hash indexed by ATTR-ID-STR. Note that for TARG Attributes
# FAPI-ATTR-ID-STR and LAYER-ATTR-ID-STR may be different and if the
# TARG attribute does not map to a FAPI attribute then FAPI-ATTR-ID-STR
# will be NO-FAPI-ID
#
# Format: <FAPI-ATTR-ID-STR>,<LAYER-ATTR-ID-STR>,<ATTR-ID-VAL>,<ATTR-TYPE>
#--------------------------------------------------------------------------
my %targAttrInfo;
open(TARGATTFILE, "< $targAttrInfoFile") or die
"Cannot open file '$targAttrInfoFile'";
while (my $line = <TARGATTFILE>)
{
chomp($line);
# Skip comment lines
if (!($line =~ /^#/))
{
if ($line =~ /(\S+),(ATTR_\S+),0x(\S+),(\S+)/)
{
if ($1 ne "NO-FAPI-ID")
{
$targAttrInfo{$1}->{idVal} = hex $3;
$targAttrInfo{$1}->{typeStr} = $4;
}
$targAttrInfo{$2}->{idVal} = hex $3;
$targAttrInfo{$2}->{typeStr} = $4;
}
}
}
close(TARGATTFILE);
#--------------------------------------------------------------------------
# Process the FAPI Attribute Enum Info file. Record the values of the
# Attribute ENUMs in a hash
#--------------------------------------------------------------------------
my %fapiAttrEnumVals;
open(ENUMFILE, "< $fapiAttrEnumInfoFile") or die
"Cannot open file '$fapiAttrEnumInfoFile'";
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
$fapiAttrEnumVals{$1} = hex $2;
}
elsif ($line =~ /(ATTR_\S+) = ([0-9]+)/)
{
# Found a decimal attribute value enumeration
$fapiAttrEnumVals{$1} = $2;
}
}
close(ENUMFILE);
#--------------------------------------------------------------------------
# Process the Attribute Overrides file
#--------------------------------------------------------------------------
my $targLine = "";
my $numOverrides = 0;
my $attrString = "";
my @attrLines;
#--------------------------------------------------------------------------
# Iterate over all lines in the Attribute Overrides file
#--------------------------------------------------------------------------
open(OVFILE, "< $overrideFile") or die "Cannot open file '$overrideFile'";
my $line = <OVFILE>;
while ($line ne "")
{
#----------------------------------------------------------------------
# Find all lines making up a single attribute override. There are
# multiple lines for a multi-dimensional attribute
#----------------------------------------------------------------------
$attrString = "";
@attrLines = ();
while ($line ne "")
{
chomp($line);
if ($line =~ /^target/)
{
if ($attrString eq "")
{
# Not currently processing attribute lines, save the target
# line, it is for following attribute lines
$targLine = $line;
$line = <OVFILE>;
last;
}
else
{
# Currently processing attribute lines. Break out of the
# loop to process the current set and look at this target
# line in the next iteration
last;
}
}
elsif ($line =~ /^(ATTR_\w+)/)
{
# Found an attribute override line
if ($attrString eq "")
{
# First override line for an attribute
$attrString = $1;
}
elsif ($attrString ne $1)
{
# Override line for a different attribute. Break out of the
# loop to process the current attribute override and look
# at this line in the next main loop
last;
}
# Add the attribute override line to the set of lines to
# process for a single override and get the next line
push(@attrLines, $line);
$line = <OVFILE>;
}
else
{
# Not a target or attribute line, get the next line
$line = <OVFILE>;
}
} # end of finding all lines making up a single attr override
if (scalar(@attrLines) > 0)
{
#------------------------------------------------------------------
# Process the set of lines making up a single attribute override
#------------------------------------------------------------------
my $attrIdStr = "";
my $attrIdVal = 0;
my $fapiTank = 0;
my $elemSize = 0;
my $d1 = 1; # First dimension of the attribute
my $d2 = 1;
my $d3 = 1;
my $d4 = 1;
my $valSize = 0;
my $flags = 0;
foreach my $attrLine(@attrLines)
{
my $td1 = 0; # First dimension of this line's element
my $td2 = 0;
my $td3 = 0;
my $td4 = 0;
my $val = 0;
if ($attrIdStr eq "")
{
# This is the first line, figure out the attrIdStr
if ($attrLine =~ /^(ATTR_\w+)/)
{
$attrIdStr = $1;
}
else
{
::userDisplay "Cannot find attr id str in '$attrLine'\n";
die;
}
# Use the data gathered from the AttrInfo files to figure out
# the attrIdVal, typeStr and tank Info
my $typeStr = "";
if (exists $targAttrInfo{$attrIdStr})
{
$attrIdVal = $targAttrInfo{$attrIdStr}->{idVal};
$typeStr = $targAttrInfo{$attrIdStr}->{typeStr};
$fapiTank = 0;
}
elsif (exists $fapiAttrInfo{$attrIdStr})
{
$attrIdVal = $fapiAttrInfo{$attrIdStr}->{idVal};
$typeStr = $fapiAttrInfo{$attrIdStr}->{typeStr};
$fapiTank = 1;
}
else
{
::userDisplay "Cannot find '$attrIdStr' in attribute info files\n";
die;
}
# Figure out the attribute element size
if ($typeStr =~ /^u8/)
{
$elemSize = 1;
}
elsif ($typeStr =~ /^u16/)
{
$elemSize = 2;
}
elsif ($typeStr =~ /^u32/)
{
$elemSize = 4;
}
elsif ($typeStr =~ /^u64/)
{
$elemSize = 8;
}
else
{
::userDisplay "Bad type string '$typeStr' in attribute info file\n";
die;
}
# Remove the attribute element type from typeStr
$typeStr =~ s/u\w+//;
# Figure out the attribute array dimensions
if ($typeStr =~ /^\[(\d+)\]/)
{
$d1 = $1;
}
if ($typeStr =~ /^\[\d+\]\[(\d+)\]/)
{
$d2 = $1;
}
if ($typeStr =~ /^\[\d+\]\[\d+\]\[(\d+)\]/)
{
$d3 = $1;
}
if ($typeStr =~ /^\[\d+\]\[\d+\]\[\d+\]\[(\d+)\]/)
{
$d4 = $1;
}
# Calculate the attribute value size
$valSize = $elemSize * $d1 * $d2 * $d3 * $d4;
if ($valSize > MAX_DIRECT_OVERRIDE_ATTR_SIZE_BYTES)
{
::userDisplay "Attribute size too big ($valSize bytes) to directly override\n";
die;
}
}
# Figure out this element's dimensions
if ($attrLine =~ /^ATTR_\w+\[(\d+)\]/)
{
$td1 = $1;
}
if ($attrLine =~ /^ATTR_\w+\[\d+\]\[(\d+)\]/)
{
$td2 = $1;
}
if ($attrLine =~ /^ATTR_\w+\[\d+\]\[\d+\]\[(\d+)\]/)
{
$td3 = $1;
}
if ($attrLine =~ /^ATTR_\w+\[\d+\]\[\d+\]\[\d+\]\[(\d+)\]/)
{
$td4 = $1;
}
# Check for overflow
if (($td1 >= $d1) || ($td2 >= $d2) || ($td3 >= $d3) ||
($td4 >= $d4))
{
::userDisplay "Attribute '$attrLine' overflows its array\n";
::userDisplay "$td1:$d1:$td2:$d2:$td3:$d3:$td4:$d4\n";
die;
}
# Remove the Attribute ID and any dimensions from the line
$attrLine =~ s/^ATTR_\S+\s+//;
# If the line includes a type field then remove it
$attrLine =~ s/^u8\S*\s+//;
$attrLine =~ s/^u16\S*\s+//;
$attrLine =~ s/^u32\S*\s+//;
$attrLine =~ s/^u64\S*\s+//;
# Figure out the override value
if ($attrLine =~ /^([A-Za-z]+\S*)/)
{
# enumerator
my $enum = "$attrIdStr"."_$1";
if (exists $fapiAttrEnumVals{$enum})
{
$val = $fapiAttrEnumVals{$enum};
}
else
{
::userDisplay "Cannot find enum '$enum' in '$fapiAttrEnumInfoFile'\n";
die;
}
}
elsif ($attrLine =~ /^0x([0-9A-Za-z]+)/)
{
# Hex value
$val = hex $1;
}
elsif ($attrLine =~ /^(\d+)/)
{
# Decimal Value
$val = $1;
}
else
{
::userDisplay "Cannot find override value for '$attrIdStr'\n";
die;
}
# Figure out if it is a const override
if ($attrLine =~ /CONST\s*/)
{
$flags = ATTR_FLAG_CONST;
}
# Write element to Hostboot memory
my $addr = $overrideAddr;
my $elemNum = $td4 + ($td3*$d4) + ($td2*$d3*$d4) +
($td1*$d2*$d3*$d4);
$addr += $elemNum * $elemSize;
if ($elemSize == 1)
{
::write8($addr, $val);
}
elsif ($elemSize == 2)
{
::write16($addr, $val);
}
elsif ($elemSize == 4)
{
::write32($addr, $val);
}
elsif ($elemSize == 8)
{
::write64($addr, $val);
}
} # end of processing all lines making up a single attr override
#------------------------------------------------------------------
# Figure out the Target node/type/pos/unitpos
#------------------------------------------------------------------
my $targType = TARGET_TYPE_SYSTEM;
my $targPos = ATTR_POS_NA;
my $targUnitPos = ATTR_UNIT_POS_NA;
my $targNode = ATTR_NODE_NA;
my $targ = $targLine;
# Figure out the node number
if ($targ =~ /target = k0:n0:s0:?\s*$/)
{
# String representing system target
$targNode = ATTR_NODE_NA;
}
elsif ($targ =~ /target = k0:n(\d+)/)
{
$targNode = $1;
}
# Figure out the target type
if ($targ =~ /p8.ex/)
{
$targType = TARGET_TYPE_EX_CHIPLET;
$targ =~ s/^.*p8.ex//;
}
elsif ($targ =~ /centaur.mba/)
{
$targType = TARGET_TYPE_MBA_CHIPLET;
$targ =~ s/^.*centaur.mba//;
}
elsif ($targ =~ /p8.mcs/)
{
$targType = TARGET_TYPE_MCS_CHIPLET;
$targ =~ s/^.*p8.mcs//;
}
elsif ($targ =~ /p8.xbus/)
{
$targType = TARGET_TYPE_XBUS_ENDPOINT;
$targ =~ s/^.*p8.xbus//;
}
elsif ($targ =~ /p8.abus/)
{
$targType = TARGET_TYPE_ABUS_ENDPOINT;
$targ =~ s/^.*p8.abus//;
}
elsif ($targ =~ /centaur/)
{
$targType = TARGET_TYPE_MEMBUF_CHIP;
$targ =~ s/^.*centaur//;
}
elsif ($targ =~ /dimm/)
{
$targType = TARGET_TYPE_DIMM;
$targ =~ s/^.*dimm//;
}
elsif ($targ =~ /p8/)
{
$targType = TARGET_TYPE_PROC_CHIP;
$targ =~ s/^.*p8//;
}
# Figure out the position
if ($targ =~ /:p(\d+)/)
{
$targPos = $1;
}
else
{
$targPos = ATTR_POS_NA;
}
# Figure out the unit position
if ($targ =~ /:c(\d+)/)
{
$targUnitPos = $1;
}
else
{
$targUnitPos = ATTR_UNIT_POS_NA;
}
# Debug output
if ($debug)
{
if ($fapiTank)
{
::userDisplay "FAPI OVERRIDE.";
}
else
{
::userDisplay "TARG OVERRIDE.";
}
::userDisplay "ID: $attrIdVal, Node: $targNode,";
::userDisplay "TargType: $targType, Pos: $targPos,";
::userDisplay "UPos: $targUnitPos, Flags: $flags\n";
}
#------------------------------------------------------------------
# Write the overide to Hostboot memory
#------------------------------------------------------------------
# From attributeTank.H
# struct AttributeHeader
# {
# uint32_t iv_attrId; // Attribute ID
# uint32_t iv_targetType; // Target Type attribute is for
# 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_node : 4; // Target Node number
# uint8_t iv_flags : 4; // AttributeFlags enum value(s)
# uint32_t iv_valSize; // Size of the attribute value in bytes
# };
my $addr = $overrideHeaderAddr;
::write32($addr, $attrIdVal);
$addr += 4;
::write32($addr, $targType);
$addr += 4;
::write16($addr, $targPos);
$addr += 2;
::write8($addr, $targUnitPos);
$addr += 1;
::write8($addr, (($targNode << 4) + $flags));
$addr += 1;
::write32($addr, $valSize);
$addr = $overrideFapiTankAddr;
::write8($addr, $fapiTank);
#------------------------------------------------------------------
# Tell Hostboot to apply the override
#------------------------------------------------------------------
my $callFuncForce = 0;
my @callFuncParms;
Hostboot::CallFunc::execFunc("fapi::directOverride()",
$debug, $callFuncForce, \@callFuncParms);
if ($debug)
{
::userDisplay "$attrIdStr sent\n";
}
$numOverrides++;
} # end of if there is an atribute override to process
} # end of iterating over all lines in an attr override file
close(OVFILE);
::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 four files in the image directory",
"$fapiAttrInfoFileName: Contains FAPI attribute info",
"$fapiAttrEnumInfoFileName: Contains FAPI attribute enum info",
"$targAttrInfoFileName: Contains TARG attribute info",
"$overrideFileName: Contains the attribute overrides"]
);
}
|