github.com/linuxboot/fiano@v1.2.0/pkg/amd/apcb/internal.go (about)

     1  // Copyright 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  package apcb
     6  
     7  //
     8  // See: AgesaPkg/Addendum/Apcb/Inc/CommonV3/ApcbV3Arch.h for more details
     9  //
    10  
    11  type headerSignature uint32
    12  
    13  const (
    14  	headerV2Signature       headerSignature = 0x42435041
    15  	headerV3Signature       headerSignature = 0x32424345
    16  	headerV3EndingSignature headerSignature = 0x41424342
    17  	tokenGroupSignature     headerSignature = 0x4E4B4F54 // NKOT
    18  )
    19  
    20  type headerV2 struct {
    21  	// ASCII "APCB", 'A' is LSB
    22  	Signature headerSignature
    23  	// Size of header
    24  	SizeOfHeader uint16
    25  	// Version, BCD. Version 1.2 is 0x12
    26  	Version uint16
    27  	// SizeOfAPCB is size of APCB
    28  	SizeOfAPCB uint32
    29  	// UniqueAPCBInstance to ensure compatibility for given flashed BIOS life cycle
    30  	UniqueAPCBInstance uint32
    31  	// CheckSumByte is APCB Checksum Byte
    32  	CheckSumByte uint8
    33  	// Reserved1 is reserved, should be zeros
    34  	Reserved1 [3]uint8
    35  	// Reserved2 is reserved, should be zeros
    36  	Reserved2 [3]uint32
    37  }
    38  
    39  type headerV3 struct {
    40  	V2Header headerV2
    41  
    42  	// Signature2 is "ECB2", 'E' is LSB
    43  	Signature2 headerSignature
    44  	// ReservedFixed1 fixed with 0. To be compatible with APCB_GROUP_HEADER_COMP.GroupId
    45  	ReservedFixed1 uint16
    46  	// Reserved, fixed with 0x10. To be compatible with APCB_GROUP_HEADER_COMP.SizeOfHeader
    47  	ReservedFixed2 uint16
    48  
    49  	// StructVersion integer. 0x12 is Version 18.
    50  	StructVersion uint16 // Version, Hex. integer. 0x12 is Version 18.
    51  	// DataVersion 0x100 is Version 256.
    52  	DataVersion uint16
    53  	// SizeOfExtendedHeader - size of extended header (size of APCB_v3_HEADER minus APCB_v2_HEADER). To be compatible with APCB_GROUP_HEADER_COMP.SizeOfGroup
    54  	SizeOfExtendedHeader uint32
    55  
    56  	// ReservedFixed3 fixed with 0. To be compatible with APCB_TYPE_HEADER.GroupId
    57  	ReservedFixed3 uint16
    58  	// ReservedFixed4 fixed with 0xFFFF. To be compatible with APCB_TYPE_HEADER.TypeId
    59  	ReservedFixed4 uint16
    60  	//  ReservedFixed5 fixed with 64d, 0x40, value to include extended header. To be compatible with APCB_TYPE_HEADER.SizeOfType
    61  	ReservedFixed5 uint16
    62  	// ReservedFixed6 fixed with 0x0000. To be compatible with APCB_TYPE_HEADER.InstanceId
    63  	ReservedFixed6 uint16
    64  	// Reserved3 should be zeros
    65  	Reserved3 [2]uint32
    66  
    67  	// DataOffset defines data starting offset, defined per APCB version. Fixed at size of APCB_V3_HEADER (88d, 0x58)
    68  	DataOffset uint16
    69  
    70  	// HeaderCheckSum is headerV3 Checksum Byte, needs to be filled
    71  	HeaderCheckSum uint8
    72  	// Reserved4 should be zeros
    73  	Reserved4 uint8
    74  	// Reserved5 should be zeros
    75  	Reserved5 [3]uint32
    76  
    77  	// APCB integrity signature, 0x20, 32 bytes
    78  	IntegritySignature [32]uint8
    79  	// Reserved6 should be zeros
    80  	Reserved6 [3]uint32
    81  	// SignatureEnding should be ASCII "BCPA", 'B' is LSB, Mark ending of header
    82  	SignatureEnding headerSignature
    83  }
    84  
    85  type groupHeader struct {
    86  	// ASCII Signature
    87  	Signature    headerSignature
    88  	GroupID      groupID
    89  	SizeOfHeader uint16
    90  	// Version, BCD. Version 1.2 is 0x12
    91  	Version     uint16
    92  	Reserved    uint16
    93  	SizeOfGroup uint32
    94  }
    95  
    96  type contextType uint8
    97  
    98  const (
    99  	structureContextType contextType = 0
   100  	parameterContextType contextType = 1
   101  	tokenV3ContextType   contextType = 2
   102  )
   103  
   104  type contextFormat uint8
   105  
   106  const (
   107  	nativeRawContextFormat          contextFormat = 0
   108  	sortAscByUnitSizeContextFormat  contextFormat = 1
   109  	sortDescByUnitSizeContextFormat contextFormat = 2
   110  )
   111  
   112  type tokenType uint16
   113  
   114  const (
   115  	booleanTokenType   tokenType = 0
   116  	oneByteTokenType   tokenType = 1
   117  	twoBytesTokenType  tokenType = 2
   118  	fourBytesTokenType tokenType = 4
   119  )
   120  
   121  type groupID uint16
   122  
   123  const (
   124  	tokensGroupID groupID = 0x3000
   125  )
   126  
   127  type typeHeaderV3 struct {
   128  	GroupID groupID
   129  	TypeID  tokenType
   130  	// SizeOfType defines size of type, in bytes
   131  	SizeOfType uint16
   132  	InstanceID uint16
   133  
   134  	ContextType   contextType
   135  	ContextFormat contextFormat
   136  	// UnitSize determines size in byte. Applicable when ContextType = 2, value should be 8.
   137  	UnitSize     uint8
   138  	PriorityMask PriorityMask
   139  	// KeySize defines sorting key size. Should be smaller than or equal to UnitSize. Applicable when ContextFormat = 1. (or != 0)
   140  	KeySize uint8
   141  	// KeyPos defines Sorting key position of the unit specified of UnitSize.
   142  	KeyPos uint8
   143  	// Board specific APCB instance mask
   144  	BoardMask uint16
   145  }
   146  
   147  type tokenPair struct {
   148  	ID    TokenID
   149  	Value uint32
   150  }