-
Notifications
You must be signed in to change notification settings - Fork 97
/
populate_hbruntime.C
2169 lines (1834 loc) · 79.9 KB
/
populate_hbruntime.C
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
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* IBM_PROLOG_BEGIN_TAG */
/* This is an automatically generated prolog. */
/* */
/* $Source: src/usr/runtime/populate_hbruntime.C $ */
/* */
/* OpenPOWER HostBoot Project */
/* */
/* Contributors Listed Below - COPYRIGHT 2016,2017 */
/* [+] 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 */
/**
* @file populate_runtime.C
*
* @brief Populate HDAT Area for Host runtime data
*/
#include <kernel/vmmmgr.H>
#include <sys/misc.h>
#include <trace/interface.H>
#include <errl/errlentry.H>
#include <initservice/initserviceif.H>
#include <targeting/common/target.H>
#include <targeting/common/targetservice.H>
#include <targeting/common/utilFilter.H>
#include <targeting/common/entitypath.H>
#include <targeting/common/commontargeting.H>
#include <runtime/runtime_reasoncodes.H>
#include <runtime/runtime.H>
#include "hdatstructs.H"
#include <mbox/ipc_msg_types.H>
#include <sys/task.h>
#include <intr/interrupt.H>
#include <errl/errlmanager.H>
#include <sys/internode.h>
#include <vpd/vpd_if.H>
#include <pnor/pnorif.H>
#include <targeting/attrrp.H>
#include <sys/mm.h>
#include <util/align.H>
#include <secureboot/trustedbootif.H>
#include <secureboot/service.H>
#include <hdat/hdat.H>
#include <config.h>
#include "../hdat/hdattpmdata.H"
#include "../hdat/hdatpcrd.H"
#include "../secureboot/trusted/tpmLogMgr.H"
#include "../secureboot/trusted/trustedboot.H"
#include <targeting/common/attributeTank.H>
#include <runtime/interface.h>
#include <targeting/attrPlatOverride.H>
#include <sbeio/sbeioif.H>
#include <sbeio/sbe_psudd.H>
#include <sbeio/runtime/sbe_msg_passing.H>
#include <kernel/bltohbdatamgr.H>
#include <util/utilrsvdmem.H>
#include <util/utillidpnor.H>
#include <stdio.h>
namespace RUNTIME
{
mutex_t g_rhbMutex = MUTEX_INITIALIZER;
// used for populating the TPM required bit in HDAT
const uint16_t TPM_REQUIRED_BIT = 0x8000; //leftmost bit of uint16_t set to 1
const uint8_t BITS_PER_BYTE = 8;
trace_desc_t *g_trac_runtime = nullptr;
TRAC_INIT(&g_trac_runtime, RUNTIME_COMP_NAME, KILOBYTE);
/**
* @brief Get a pointer to the next available
* HDAT HB Reserved Memory entry
* @param[out] o_rngPtr Pointer to the addr range entry
* @return Error handle if error
*/
errlHndl_t getNextRhbAddrRange(hdatMsVpdRhbAddrRange_t* & o_rngPtr)
{
errlHndl_t l_elog = nullptr;
mutex_lock( &g_rhbMutex );
do {
TARGETING::Target * l_sys = nullptr;
TARGETING::targetService().getTopLevelTarget( l_sys );
assert(l_sys != nullptr);
uint32_t l_nextSection =
l_sys->getAttr<TARGETING::ATTR_HB_RSV_MEM_NEXT_SECTION>();
uint64_t l_rsvMemDataAddr = 0;
uint64_t l_rsvMemDataSizeMax = 0;
// Get the address of the next section
l_elog = RUNTIME::get_host_data_section( RUNTIME::RESERVED_MEM,
l_nextSection,
l_rsvMemDataAddr,
l_rsvMemDataSizeMax );
if(l_elog != nullptr)
{
TRACFCOMP( g_trac_runtime,
"getNextRhbAddrRange fail get_host_data_section %d",
l_nextSection );
break;
}
o_rngPtr =
reinterpret_cast<hdatMsVpdRhbAddrRange_t *>(l_rsvMemDataAddr);
l_nextSection++;
l_sys->setAttr
<TARGETING::ATTR_HB_RSV_MEM_NEXT_SECTION>(l_nextSection);
} while(0);
mutex_unlock( &g_rhbMutex );
return(l_elog);
}
/**
* @brief Map physical address to virtual
* @param[in] i_addr Physical address
* @param[in] i_size Size of block to be mapped
* @param[out] o_addr Virtual address
* @return Error handle if error
*/
errlHndl_t mapPhysAddr(uint64_t i_addr,
uint64_t i_size,
uint64_t& o_addr)
{
errlHndl_t l_elog = nullptr;
o_addr = reinterpret_cast<uint64_t>(mm_block_map(
reinterpret_cast<void*>(i_addr), i_size));
// Check if address returned from the block map is NULL
if(o_addr == 0)
{
TRACFCOMP( g_trac_runtime,
"mapPhysAddr fail to map physical addr %p, size %lx",
reinterpret_cast<void*>(i_addr), i_size );
/*@ errorlog tag
* @errortype ERRORLOG::ERRL_SEV_UNRECOVERABLE
* @moduleid RUNTIME::MOD_MAP_PHYS_ADDR
* @reasoncode RUNTIME::RC_CANNOT_MAP_MEMORY
* @userdata1 Phys address we are trying to map
* @userdata2 Size of memory we are trying to map
*
* @devdesc Error mapping a virtual memory map
* @custdesc Kernel failed to map memory
*/
l_elog = new ERRORLOG::ErrlEntry(
ERRORLOG::ERRL_SEV_UNRECOVERABLE,
RUNTIME::MOD_MAP_PHYS_ADDR,
RUNTIME::RC_CANNOT_MAP_MEMORY,
i_addr,
i_size,
true);
}
return l_elog;
}
/**
* @brief Unmap virtual address block
* @param[in] i_addr Virtual address
* @return Error handle if error
*/
errlHndl_t unmapVirtAddr(uint64_t i_addr)
{
errlHndl_t l_elog = nullptr;
int l_rc = mm_block_unmap(reinterpret_cast<void*>(i_addr));
if(l_rc)
{
TRACFCOMP( g_trac_runtime,
"unmapVirtAddr fail to unmap virt addr %p",
reinterpret_cast<void*>(i_addr));
/*@ errorlog tag
* @errortype ERRORLOG::ERRL_SEV_UNRECOVERABLE
* @moduleid RUNTIME::MOD_UNMAP_VIRT_ADDR
* @reasoncode RUNTIME::RC_UNMAP_FAIL
* @userdata1 Virtual address we are trying to unmap
*
* @devdesc Error unmapping a virtual memory map
* @custdesc Kernel failed to unmap memory
*/
l_elog = new ERRORLOG::ErrlEntry(
ERRORLOG::ERRL_SEV_UNRECOVERABLE,
RUNTIME::MOD_UNMAP_VIRT_ADDR,
RUNTIME::RC_UNMAP_FAIL,
i_addr,
true);
}
return l_elog;
}
void traceHbRsvMemRange(hdatMsVpdRhbAddrRange_t* & i_rngPtr )
{
TRACFCOMP(g_trac_runtime,
"Setting HDAT HB Reserved Memory Range: "
"%s RangeType 0x%X RangeId 0x%X "
"StartAddress 0x%16llX EndAddress 0x%16llX Permissions 0x%.2X",
i_rngPtr->hdatRhbLabelString,
i_rngPtr->hdatRhbRngType,
i_rngPtr->hdatRhbRngId,
i_rngPtr->hdatRhbAddrRngStrAddr,
i_rngPtr->hdatRhbAddrRngEndAddr,
i_rngPtr->hdatRhbPermission);
}
/**
* @brief Get the next Reserved HB memory range and set all member variables
* of struct. Additionally trace out relevant parts of the struct
* @param[in] i_type, Range type
* @param[in] i_rangeId, Range ID
* @param[in] i_startAddr, Range Starting Address
* @param[in] i_size, Size of address space to reserve
* @param[in] i_label, Label String Ptr
*
* @return errlHndl_t, nullptr on success; otherwise errlog
*/
errlHndl_t setNextHbRsvMemEntry(const HDAT::hdatMsVpdRhbAddrRangeType i_type,
const uint16_t i_rangeId,
const uint64_t i_startAddr,
const uint64_t i_size,
const char* i_label,
const HDAT::hdatRhbPermType i_permission =
HDAT::RHB_READ_WRITE
)
{
errlHndl_t l_elog = nullptr;
do {
// Get a pointer to the next available HDAT HB Rsv Mem entry
hdatMsVpdRhbAddrRange_t* l_rngPtr = nullptr;
l_elog = getNextRhbAddrRange(l_rngPtr);
if(l_elog)
{
break;
}
assert(l_rngPtr != nullptr, "getNextRhbAddrRange returned nullptr");
// Determine starting address
// Logical OR staring adddress with enum FORCE_PHYS_ADDR to
// ignore the HRMOR bit
uint64_t l_startAddr = i_startAddr | VmmManager::FORCE_PHYS_ADDR;
// Fill in the entry
l_rngPtr->set(i_type, i_rangeId, l_startAddr, i_size, i_label,
i_permission);
traceHbRsvMemRange(l_rngPtr);
} while(0);
return l_elog;
}
/**
* @brief Load the HB_DATA section for reserved memory
*
* ----- HB Data Layout -------
* io_start_address
* -- HB Table of Contents
* -- ATTR Override Data
* -- ATTR Data
* -- VPD
* -- Padding
* io_end_address
*
* Either pass in a low starting physical address (io_start_address) or
* a high ending physical address (io_end_address).
* The function will then calculate the size of data and
* determine the opposite address.
* Set i_startAddressValid to true, if you set io_start_address.
* Set i_startAddressValid to false, if you set io_end_address.
*
* @param[in/out] io_start_address where to start loading data
* @param[in/out] io_end_address where to stop loading data
* @param[in] i_startAddressValid Is io_start_address valid?
* @param[out] io_size if not zero, maxSize in bytes allowed
* returns Total 64kb aligned size for all the data
* @return Error handle if error
*/
errlHndl_t fill_RsvMem_hbData(uint64_t & io_start_address,
uint64_t & io_end_address,
bool i_startAddressValid,
uint64_t & io_size)
{
TRACFCOMP( g_trac_runtime, ENTER_MRK"fill_RsvMem_hbData> io_start_address=0x%.16llX,io_end_address=0x%.16llX,startAddressValid=%d",
io_start_address, io_end_address, i_startAddressValid?1:0 );
errlHndl_t l_elog = nullptr;
uint64_t l_vAddr = 0x0;
uint64_t l_prevDataAddr = 0;
uint64_t l_prevDataSize = 0;
// TOC to be filled in and added to beginning of HB Data section
Util::hbrtTableOfContents_t l_hbTOC;
strcpy(l_hbTOC.toc_header, "Hostboot Table of Contents");
l_hbTOC.toc_version = Util::HBRT_TOC_VERSION_1;
l_hbTOC.total_entries = 0;
/////////////////////////////////////////////////////////////
// Figure out the total size needed so we can place the TOC
// at the beginning
/////////////////////////////////////////////////////////////
uint64_t l_totalSectionSize = 0;
// Begin with ATTROVER
// default to the minimum space we have to allocate anyway
size_t l_attrOverMaxSize = HBRT_RSVD_MEM_OPAL_ALIGN;
// copy overrides into local buffer
uint8_t* l_overrideData =
reinterpret_cast<uint8_t*>(malloc(l_attrOverMaxSize));
size_t l_actualSize = l_attrOverMaxSize;
l_elog = TARGETING::AttrRP::saveOverrides( l_overrideData,
l_actualSize );
if( l_elog )
{
// check if the issue was a lack of space (unlikely)
if( unlikely( l_actualSize > 0 ) )
{
TRACFCOMP( g_trac_runtime, "Expanding override section to %d", l_actualSize );
free(l_overrideData);
l_overrideData =
reinterpret_cast<uint8_t*>(malloc(l_actualSize));
l_elog = TARGETING::AttrRP::saveOverrides( l_overrideData,
l_actualSize );
}
// overrides are not critical so just commit this
// and keep going without any
if( l_elog )
{
TRACFCOMP( g_trac_runtime, "Errors applying overrides, just skipping" );
errlCommit( l_elog, RUNTIME_COMP_ID );
l_elog = NULL;
l_actualSize = 0;
}
}
// Should we create an ATTROVER section?
if (l_actualSize > 0)
{
l_hbTOC.entry[l_hbTOC.total_entries].label =
Util::HBRT_MEM_LABEL_ATTROVER;
l_hbTOC.entry[l_hbTOC.total_entries].offset = 0;
l_hbTOC.entry[l_hbTOC.total_entries].size = l_actualSize;
l_totalSectionSize += ALIGN_PAGE(l_actualSize);
l_hbTOC.total_entries++;
}
// Now calculate ATTR size
l_hbTOC.entry[l_hbTOC.total_entries].label = Util::HBRT_MEM_LABEL_ATTR;
l_hbTOC.entry[l_hbTOC.total_entries].offset = 0;
l_hbTOC.entry[l_hbTOC.total_entries].size =
TARGETING::AttrRP::maxSize();
l_totalSectionSize +=
ALIGN_PAGE(l_hbTOC.entry[l_hbTOC.total_entries].size);
l_hbTOC.total_entries++;
// Fill in VPD size
l_hbTOC.entry[l_hbTOC.total_entries].label = Util::HBRT_MEM_LABEL_VPD;
l_hbTOC.entry[l_hbTOC.total_entries].offset = 0;
l_hbTOC.entry[l_hbTOC.total_entries].size = VMM_RT_VPD_SIZE;
l_totalSectionSize +=
ALIGN_PAGE(l_hbTOC.entry[l_hbTOC.total_entries].size);
l_hbTOC.total_entries++;
l_totalSectionSize += sizeof(l_hbTOC); // Add 4KB Table of Contents
// Fill in PADDING size
// Now calculate how much padding is needed for OPAL alignment
// of the whole data section
size_t l_totalSizeAligned = ALIGN_X( l_totalSectionSize,
HBRT_RSVD_MEM_OPAL_ALIGN );
// l_actualSizeAligned will bring section to OPAL alignment
uint64_t l_actualSizeAligned = l_totalSizeAligned - l_totalSectionSize;
// Do we need a Padding section?
if (l_actualSizeAligned > 0)
{
// Add padding section
l_hbTOC.entry[l_hbTOC.total_entries].label =
Util::HBRT_MEM_LABEL_PADDING;
l_hbTOC.entry[l_hbTOC.total_entries].offset = 0;
l_hbTOC.entry[l_hbTOC.total_entries].size = l_actualSizeAligned;
l_hbTOC.total_entries++;
}
// Set total_size to the 64k aligned size
l_hbTOC.total_size = l_totalSizeAligned;
do {
if ((io_size != 0) && (io_size < l_totalSizeAligned))
{
// create an error
TRACFCOMP( g_trac_runtime, "fill_RsvMem_hbData - Will exceed max allowed size %lld, need %lld",
io_size, l_totalSizeAligned);
/*@ errorlog tag
* @errortype ERRORLOG::ERRL_SEV_UNRECOVERABLE
* @moduleid RUNTIME::MOD_FILL_RSVMEM_HBDATA
* @reasoncode RUNTIME::RC_EXCEEDED_MEMORY
* @userdata1 Total size needed
* @userdata2 Size allowed
*
* @devdesc Unable to fill in HB data memory
*/
l_elog = new ERRORLOG::ErrlEntry(
ERRORLOG::ERRL_SEV_UNRECOVERABLE,
RUNTIME::MOD_FILL_RSVMEM_HBDATA,
RUNTIME::RC_EXCEEDED_MEMORY,
l_totalSizeAligned,
io_size,
true);
break;
}
// update return size to amount filled in
io_size = l_totalSizeAligned;
// Figure out the start and end addresses
if (i_startAddressValid)
{
io_end_address = io_start_address + l_totalSizeAligned;
}
else
{
io_start_address = io_end_address - l_totalSizeAligned;
}
TRACFCOMP( g_trac_runtime, "fill_RsvMem_hbData> mapping 0x%.16llX address, size %lld",
io_start_address, l_totalSizeAligned );
// Grab the virtual address for the entire HB Data section
l_elog = mapPhysAddr(io_start_address, l_totalSizeAligned, l_vAddr);
if(l_elog)
{
break;
}
TRACFCOMP( g_trac_runtime, "fill_RsvMem_hbData> virtual start address: %p", l_vAddr);
// Skip TOC at the beginning, pretend it was added
l_prevDataAddr = l_vAddr;
l_prevDataSize = sizeof(l_hbTOC);
uint64_t l_offset = 0;
int i = 0;
while ( i < l_hbTOC.total_entries )
{
uint64_t actual_size = l_hbTOC.entry[i].size;
uint64_t aligned_size = ALIGN_PAGE(actual_size);
l_offset += l_prevDataSize;
// update offset to current data section
l_hbTOC.entry[i].offset = l_offset;
l_prevDataAddr += l_prevDataSize;
l_prevDataSize = aligned_size;
switch ( l_hbTOC.entry[i].label )
{
case Util::HBRT_MEM_LABEL_ATTROVER:
TRACFCOMP( g_trac_runtime, "fill_RsvMem_hbData> ATTROVER address 0x%.16llX, size: %lld", l_prevDataAddr, aligned_size);
TRACFCOMP( g_trac_runtime, "fill_RsvMem_hbData> memcpy %d size", actual_size);
memcpy( reinterpret_cast<void*>(l_prevDataAddr),
l_overrideData,
actual_size);
break;
case Util::HBRT_MEM_LABEL_ATTR:
TRACFCOMP( g_trac_runtime, "fill_RsvMem_hbData> ATTR address 0x%.16llX, size: %lld", l_prevDataAddr, aligned_size);
l_elog = TARGETING::AttrRP::save(
reinterpret_cast<uint8_t*>(l_prevDataAddr),
aligned_size);
if(l_elog)
{
TRACFCOMP( g_trac_runtime,
"populate_HbRsvMem fail ATTR save call" );
break;
}
TRACFCOMP( g_trac_runtime, "fill_RsvMem_hbData> TARGETING::AttrRP::save(0x%.16llX) done", l_prevDataAddr);
break;
case Util::HBRT_MEM_LABEL_VPD:
TRACFCOMP( g_trac_runtime, "fill_RsvMem_hbData> VPD address 0x%.16llX, size: %lld", l_prevDataAddr, aligned_size);
l_elog = VPD::vpd_load_rt_image(l_prevDataAddr);
if(l_elog)
{
TRACFCOMP( g_trac_runtime,
"fill_RsvMem_hbData> failed VPD call" );
break;
}
TRACFCOMP( g_trac_runtime, "fill_RsvMem_hbData> VPD address 0x%.16llX, size: %lld done", l_prevDataAddr, aligned_size);
break;
default:
break;
}
i++;
}
// exit if we hit an error
if(l_elog)
{
break;
}
TRACFCOMP( g_trac_runtime, "fill_RsvMem_hbData> TOC address 0x%.16llX, size: %lld", l_vAddr, sizeof(l_hbTOC));
// Now copy the TOC at the head of the HB Data section
memcpy( reinterpret_cast<void*>(l_vAddr),
&l_hbTOC,
sizeof(l_hbTOC));
} while (0);
if (l_vAddr != 0)
{
// release the virtual address
errlHndl_t l_errl = unmapVirtAddr(l_vAddr);
if (l_errl)
{
TRACFCOMP( g_trac_runtime, "fill_RsvMem_hbData> unmap %p failed", l_vAddr );
if (l_elog)
{
// Already have an error log so just commit this new one
errlCommit(l_errl, RUNTIME_COMP_ID);
}
else
{
l_elog = l_errl;
}
}
l_vAddr = 0;
}
// free ATTR_OVERRIDE memory
free(l_overrideData);
TRACFCOMP( g_trac_runtime,EXIT_MRK"fill_RsvMem_hbData> io_start_address=0x%.16llX,io_end_address=0x%.16llX,size=%lld",
io_start_address, io_end_address, io_size );
return l_elog;
}
errlHndl_t hbResvLoadSecureSection (const PNOR::SectionId i_sec,
const uint64_t i_rangeId,
uint64_t& io_prevAddr,
uint64_t& io_prevSize)
{
TRACFCOMP( g_trac_runtime,ENTER_MRK"hbResvloadSecureSection() sec %s",
PNOR::SectionIdToString(i_sec));
errlHndl_t l_elog = nullptr;
PNOR::SectionInfo_t l_info;
uint64_t l_tmpVaddr = 0;
do {
l_elog = PNOR::getSectionInfo( i_sec, l_info );
if(l_elog)
{
//No need to commit error here, it gets handled later
//just break out to escape this function
TRACFCOMP( g_trac_runtime, ERR_MRK"hbResvloadSecureSection() getSectionInfo failed");
break;
}
#ifdef CONFIG_SECUREBOOT
// Skip verification if a section does not have a Secureboot Header
if (l_info.secure)
{
// Securely Load PNOR section
l_elog = loadSecureSection(i_sec);
if (l_elog)
{
TRACFCOMP( g_trac_runtime,
ERR_MRK"hbResvloadSecureSection() - Error from "
"loadSecureSection(%s)", PNOR::SectionIdToString(i_sec));
break;
}
}
#endif
auto l_pnorVaddr = l_info.vaddr;
auto l_imgSize = l_info.size;
// If section is signed, only the protected size was loaded into memory
#ifdef CONFIG_SECUREBOOT
if (l_info.secure)
{
l_imgSize = l_info.secureProtectedPayloadSize;
// Include secure header
l_pnorVaddr -= PAGESIZE;
l_imgSize += PAGESIZE;
}
#endif
// Align size for OPAL
size_t l_imgSizeAligned = ALIGN_X(l_imgSize, HBRT_RSVD_MEM_OPAL_ALIGN);
// For PHYP we build up starting at the end of the previously allocated
// areas, for OPAL we build downwards from the top of memory
uint64_t l_imgAdd = 0x0;
if(TARGETING::is_phyp_load())
{
l_imgAdd = io_prevAddr + io_prevSize;
}
else if(TARGETING::is_sapphire_load())
{
l_imgAdd = io_prevAddr - l_imgSizeAligned;
}
auto l_lids = Util::getPnorSecLidIds(i_sec);
TRACFCOMP(g_trac_runtime, "hbResvloadSecureSection() getPnorSecLidIds lid = 0x%X, containerLid = 0x%X",
l_lids.lid, l_lids.containerLid);
assert(l_lids.lid != Util::INVALID_LIDID,"Pnor Section = %s not associated with any Lids", PNOR::SectionIdToString(i_sec));
// @TODO RTC:178163 enabled when HDAT support is complete for extra HB resv mem entries
// PHYP will use these 2 entries in the future
/*
// Verified Lid - Header Only
char l_containerLidStr [Util::lidIdStrLength];
snprintf (l_containerLidStr, Util::lidIdStrLength, "%X",
l_lids.containerLid);
l_elog = setNextHbRsvMemEntry(HDAT::RHB_TYPE_VERIFIED_LIDS,
i_rangeId,
l_imgAdd,
l_imgSizeAligned,
l_containerLidStr);
if(l_elog)
{
TRACFCOMP( g_trac_runtime, ERR_MRK"hbResvloadSecureSection() setNextHbRsvMemEntry Lid header failed");
break;
}
// Verified Lid - Content Only
char l_lidStr[Util::lidIdStrLength];
snprintf (l_lidStr, Util::lidIdStrLength, "%X",l_lids.lid);
l_elog = setNextHbRsvMemEntry(HDAT::RHB_TYPE_VERIFIED_LIDS,
i_rangeId,
l_imgAdd+PAGE_SIZE,
l_imgSizeAligned,
l_lidStr);
if(l_elog)
{
TRACFCOMP( g_trac_runtime, ERR_MRK"hbResvloadSecureSection() setNextHbRsvMemEntry Lid content failed");
break;
}
*/
// Verified PNOR - Header + Content
l_elog = setNextHbRsvMemEntry(HDAT::RHB_TYPE_VERIFIED_PNOR,
i_rangeId,
l_imgAdd,
l_imgSizeAligned,
PNOR::SectionIdToString(i_sec),
HDAT::RHB_READ_ONLY);
if(l_elog)
{
TRACFCOMP( g_trac_runtime, ERR_MRK"hbResvloadSecureSection() setNextHbRsvMemEntry PNOR content failed");
break;
}
io_prevAddr = l_imgAdd;
// Use aligned size for OPAL alignment even if that means there is some
// wasted space.
io_prevSize = l_imgSizeAligned;
// Load the Verified image into HB resv memory
l_elog = mapPhysAddr(l_imgAdd, l_imgSize, l_tmpVaddr);
if(l_elog)
{
TRACFCOMP( g_trac_runtime, ERR_MRK"hbResvloadSecureSection() mapPhysAddr failed");
break;
}
// Include Header page from pnor image.
memcpy(reinterpret_cast<void*>(l_tmpVaddr),
reinterpret_cast<void*>(l_pnorVaddr),
l_imgSize);
l_elog = unmapVirtAddr(l_tmpVaddr);
if(l_elog)
{
TRACFCOMP( g_trac_runtime, ERR_MRK"hbResvloadSecureSection() unmapVirtAddr failed");
break;
}
} while(0);
return l_elog;
}
/**
* @brief Load the HDAT HB Reserved Memory
* address range structures on given node
* @param[in] i_nodeId Node ID
* @return Error handle if error
*/
errlHndl_t populate_HbRsvMem(uint64_t i_nodeId)
{
TRACFCOMP( g_trac_runtime, ENTER_MRK"populate_HbRsvMem> i_nodeId=%d", i_nodeId );
errlHndl_t l_elog = nullptr;
do {
// Wipe out our cache of the NACA/SPIRA pointers
RUNTIME::rediscover_hdat();
// Wipe out all HB reserved memory sections
l_elog = RUNTIME::clear_host_data_section(RUNTIME::RESERVED_MEM);
if(l_elog)
{
break;
}
uint64_t l_topMemAddr = 0x0;
uint64_t l_vAddr = 0x0;
// Get list of processor chips
TARGETING::TargetHandleList l_procChips;
getAllChips( l_procChips,
TARGETING::TYPE_PROC,
true);
if(TARGETING::is_phyp_load())
{
// First phyp entry is for the entire 256M HB space
uint64_t l_hbAddr = cpu_spr_value(CPU_SPR_HRMOR)
- VMM_HRMOR_OFFSET;
l_elog = setNextHbRsvMemEntry(HDAT::RHB_TYPE_PRIMARY,
i_nodeId,
l_hbAddr,
VMM_HB_RSV_MEM_SIZE,
HBRT_RSVD_MEM__PRIMARY);
if(l_elog != nullptr)
{
break;
}
}
else if(TARGETING::is_sapphire_load())
{
// Opal data goes at top_of_mem
l_topMemAddr = TARGETING::get_top_mem_addr();
assert (l_topMemAddr != 0,
"populate_HbRsvMem: Top of memory was 0!");
// Opal HB reserved memory data
// -----TOP_OF_MEM-------
// -----OCC Common-------
// -----HOMER_N----------
// -----...--------------
// -----HOMER_0----------
// -----HB Data ---------
// -- VPD
// -- ATTR Data
// -- ATTR Override Data
// -- HB TOC
// -----HBRT Image-------
// -----SBE Comm---------
// -----SBE FFDC---------
// -----Secureboot cryptographic algorithms code---------
// -----Verified Images---------
// -- OCC
// -- WOFDATA
// -- HCODE
// First opal entries are for the HOMERs
uint64_t l_homerAddr = l_topMemAddr;
// Loop through all functional Procs
for (const auto & l_procChip: l_procChips)
{
l_homerAddr = l_procChip->getAttr
<TARGETING::ATTR_HOMER_PHYS_ADDR>();
// Note: the instance we use to retrieve the data must
// match the value we used to populate HDAT originally
l_elog = setNextHbRsvMemEntry(HDAT::RHB_TYPE_HOMER_OCC,
l_procChip->getAttr<TARGETING::ATTR_HBRT_HYP_ID>(),
l_homerAddr,
VMM_HOMER_INSTANCE_SIZE,
HBRT_RSVD_MEM__HOMER);
if(l_elog)
{
break;
}
}
if(l_elog)
{
break;
}
#ifdef CONFIG_START_OCC_DURING_BOOT
///////////////////////////////////////////////////
// OCC Common entry
if( !(TARGETING::is_phyp_load()) )
{
TARGETING::Target * l_sys = nullptr;
TARGETING::targetService().getTopLevelTarget( l_sys );
assert(l_sys != nullptr);
uint64_t l_occCommonAddr = l_sys->getAttr
<TARGETING::ATTR_OCC_COMMON_AREA_PHYS_ADDR>();
l_elog = setNextHbRsvMemEntry(HDAT::RHB_TYPE_HOMER_OCC,
i_nodeId,
l_occCommonAddr,
VMM_OCC_COMMON_SIZE,
HBRT_RSVD_MEM__OCC_COMMON);
if(l_elog)
{
break;
}
}
#endif
}
////////////////////////////////////////////////////
// HB Data area
////////////////////////////////////////////////////
//====================
// Note that for PHYP we build up starting at the end of the
// previously allocated HOMER/OCC areas, for OPAL we build
// downwards from the top of memory where the HOMER/OCC
// areas were placed
uint64_t l_startAddr = 0;
uint64_t l_endAddr = 0;
uint64_t l_totalSizeAligned = 0;
bool startAddressValid = true;
if(TARGETING::is_phyp_load())
{
l_startAddr = cpu_spr_value(CPU_SPR_HRMOR)
+ VMM_HB_DATA_TOC_START_OFFSET;
}
else if(TARGETING::is_sapphire_load())
{
l_endAddr = l_topMemAddr -
VMM_ALL_HOMER_OCC_MEMORY_SIZE;
startAddressValid = false;
}
// fills in the reserved memory with HD Data and
// will update addresses and totalSize
l_elog = fill_RsvMem_hbData(l_startAddr, l_endAddr,
startAddressValid, l_totalSizeAligned);
if (l_elog)
{
break;
}
// Loop through all functional Procs
for (const auto & l_procChip: l_procChips)
{
//Pass start address down to SBE via chipop
l_elog = SBEIO::sendPsuStashKeyAddrRequest(SBEIO::RSV_MEM_ATTR_ADDR,
l_startAddr,
l_procChip);
if (l_elog)
{
TRACFCOMP( g_trac_runtime, "sendPsuStashKeyAddrRequest failed for target: %x",
TARGETING::get_huid(l_procChip) );
break;
}
}
if (l_elog)
{
break;
}
l_elog = setNextHbRsvMemEntry(HDAT::RHB_TYPE_HBRT,
i_nodeId,
l_startAddr,
l_totalSizeAligned,
HBRT_RSVD_MEM__DATA);
if(l_elog)
{
break;
}
// Establish a couple variables to keep track of where the
// next section lands as we deal with the less statically
// sized areas. These values must always remain 64KB
// aligned
uint64_t l_prevDataAddr = l_startAddr;
uint64_t l_prevDataSize = l_totalSizeAligned;
//////////////////////////////////////////////////////////
// HBRT image entry
// OPAL w/ FSP could get the hbrt image from the LID
// Include hbrt_code_image here to be consistent with P8
if(TARGETING::is_sapphire_load())
{
uint64_t l_hbrtImageAddr = 0x0;
#ifdef CONFIG_SECUREBOOT
l_elog = loadSecureSection(PNOR::HB_RUNTIME);
if(l_elog)
{
break;
}
#endif
PNOR::SectionInfo_t l_pnorInfo;
l_elog = getSectionInfo( PNOR::HB_RUNTIME , l_pnorInfo);
if (l_elog)
{
break;
}
// Find start of image.
// For Secureboot we might need to deal with the header but
// for now that is hidden by the PNOR-RP.
uint64_t l_imageStart = l_pnorInfo.vaddr;
// The "VFS_LAST_ADDRESS" variable is 2 pages in.
uint64_t l_vfsLastAddress =
*reinterpret_cast<uint64_t*>(l_imageStart + 2*PAGE_SIZE);
// At the end of the image are the relocations, get the number.
uint64_t l_relocateCount =
*reinterpret_cast<uint64_t*>
(l_imageStart + l_vfsLastAddress);
// Sum up the total size.
uint64_t l_imageSize = l_vfsLastAddress +
(l_relocateCount+1)*sizeof(uint64_t);
// Set the image address, align down for OPAL
l_hbrtImageAddr = ALIGN_PAGE_DOWN(l_prevDataAddr);
l_hbrtImageAddr = ALIGN_PAGE_DOWN(l_hbrtImageAddr - l_imageSize);
l_hbrtImageAddr = ALIGN_DOWN_X(l_hbrtImageAddr,
HBRT_RSVD_MEM_OPAL_ALIGN);
size_t l_hbrtImageSizeAligned = ALIGN_X( l_imageSize,
HBRT_RSVD_MEM_OPAL_ALIGN);
l_elog = setNextHbRsvMemEntry(HDAT::RHB_TYPE_HBRT,
i_nodeId,
l_hbrtImageAddr,
l_hbrtImageSizeAligned,
HBRT_RSVD_MEM__CODE);
if(l_elog)
{
break;
}
l_prevDataAddr = l_hbrtImageAddr;
l_prevDataSize = l_hbrtImageSizeAligned;
// Load the HBRT image into memory
l_elog = mapPhysAddr(l_hbrtImageAddr, l_imageSize, l_vAddr);
if(l_elog)
{
break;
}
memcpy(reinterpret_cast<void*>(l_vAddr),
reinterpret_cast<void*>(l_imageStart),
l_imageSize);