github.com/linuxboot/fiano@v1.2.0/pkg/intel/metadata/bg/bgbootpolicy/se.go (about) 1 // Copyright 2017-2023 the LinuxBoot Authors. All rights reserved 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 //go:generate manifestcodegen 6 7 package bgbootpolicy 8 9 import ( 10 "fmt" 11 "math" 12 "time" 13 14 "github.com/linuxboot/fiano/pkg/intel/metadata/bg" 15 ) 16 17 // PrettyString: IBB Segments Element 18 type SE struct { 19 StructInfo `id:"__IBBS__" version:"0x10"` 20 Reserved0 [1]byte `require:"0" json:"seReserved0,omitempty"` 21 Reserved1 [1]byte `require:"0" json:"seReserved1,omitempty"` 22 PBETValue PBETValue `json:"sePBETValue"` 23 Flags SEFlags `json:"seFlags"` 24 // PrettyString: IBB MCHBAR 25 IBBMCHBAR uint64 `json:"seIBBMCHBAR"` 26 // PrettyString: VT-d BAR 27 VTdBAR uint64 `json:"seVTdBAR"` 28 // PrettyString: DMA Protection 0 Base Address 29 PMRLBase uint32 `json:"seDMAProtBase0"` 30 // PrettyString: DMA Protection 0 Limit Address 31 PMRLLimit uint32 `json:"seDMAProtLimit0"` 32 // PrettyString: DMA Protection 1 Base Address 33 Reserved2 [8]byte `json:"seDMAProtBase1"` 34 // PrettyString: DMA Protection 2 Limit Address 35 Reserved3 [8]byte `json:"seDMAProtLimit1"` 36 37 PostIBBHash bg.HashStructureFill `json:"sePostIBBHash"` 38 39 IBBEntryPoint uint32 `json:"seIBBEntry"` 40 41 Digest bg.HashStructure `json:"seDigestList"` 42 43 IBBSegments []IBBSegment `countType:"uint8" json:"seIBBSegments,omitempty"` 44 } 45 46 type PBETValue uint8 47 48 // PBETValue returns the raw value of the timer setting. 49 func (pbet PBETValue) PBETValue() uint8 { 50 return uint8(pbet) & 0x0f 51 } 52 53 // Duration returns the value as time.Duration. 54 func (pbet PBETValue) Duration() time.Duration { 55 v := pbet.PBETValue() 56 if v == 0 { 57 return math.MaxInt64 58 } 59 return time.Second * time.Duration(5+v) 60 } 61 62 func (pbet *PBETValue) SetDuration(duration time.Duration) time.Duration { 63 v := duration.Nanoseconds()/time.Second.Nanoseconds() - 5 64 if v <= 0 { 65 v = 1 66 } 67 if v >= 16 { 68 v = 0 69 } 70 *pbet = PBETValue(v) 71 72 return pbet.Duration() 73 } 74 75 type SEFlags uint32 76 77 func (flags SEFlags) Reserved0() uint32 { 78 return uint32(flags & 0xffffffe0) 79 } 80 81 // PrettyString-true: BIOS supports Top Swap remediation action 82 // PrettyString-false: BIOS does not support Top Swap remediation action 83 func (flags SEFlags) SupportsTopSwapRemediation() bool { 84 return flags&0x10 != 0 85 } 86 87 // PrettyString-true: Leave Hierarchies enabled. Cap all PCRs on failure. 88 // PrettyString-false: Do not leave enabled. Disable all Hierarchies or deactivate on failure. 89 func (flags SEFlags) TPMFailureLeavesHierarchiesEnabled() bool { 90 return flags&0x08 != 0 91 } 92 93 // PrettyString-true: Extend Authority Measurements into the Authority PCR 7 94 // PrettyString-false: Do not extend into the Authority PCR 7 95 func (flags SEFlags) AuthorityMeasure() bool { 96 return flags&0x04 != 0 97 } 98 99 // PrettyString-true: Issue TPM Start-up from Locality 3 100 // PrettyString-false: Disabled 101 func (flags SEFlags) Locality3Startup() bool { 102 return flags&0x02 != 0 103 } 104 105 // PrettyString-true: Enable DMA Protection 106 // PrettyString-false: Disable DMA Protection 107 func (flags SEFlags) DMAProtection() bool { 108 return flags&0x01 != 0 109 } 110 111 type IBBSegment struct { 112 Reserved [2]byte `require:"0" json:"ibbSegReserved"` 113 Flags uint16 `json:"ibbSegFlags"` 114 Base uint32 `json:"ibbSegBase"` 115 Size uint32 `json:"ibbSegSize"` 116 } 117 118 type CachingType uint8 119 120 const ( 121 CachingTypeWriteProtect = CachingType(iota) 122 CachingTypeWriteBack 123 CachingTypeReserved0 124 CachingTypeReserved1 125 ) 126 127 // String implements fmt.Stringer. 128 func (c CachingType) String() string { 129 switch c { 130 case CachingTypeWriteProtect: 131 return "write_protect" 132 case CachingTypeWriteBack: 133 return "write_back" 134 case CachingTypeReserved0: 135 return "value_0x02" 136 case CachingTypeReserved1: 137 return "value_0x03" 138 } 139 return fmt.Sprintf("unexpected_value_0x%02X", uint8(c)) 140 }