github.com/u-root/u-root@v7.0.1-0.20200915234505-ad7babab0a8e+incompatible/pkg/uefivars/boot/efiDppHardware.go (about)

     1  // Copyright 2020 the u-root 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  // SPDX-License-Identifier: BSD-3-Clause
     6  //
     7  
     8  package boot
     9  
    10  import (
    11  	"fmt"
    12  )
    13  
    14  // EfiDppHwSubType is the dpp subtype for hardware.
    15  type EfiDppHwSubType EfiDevPathProtoSubType
    16  
    17  const (
    18  	DppHTypePCI EfiDppHwSubType = iota + 1
    19  	DppHTypePCCARD
    20  	DppHTypeMMap
    21  	DppHTypeVendor
    22  	DppHTypeCtrl
    23  	DppHTypeBMC
    24  )
    25  
    26  var efiDppHwSubTypeStrings = map[EfiDppHwSubType]string{
    27  	DppHTypePCI:    "PCI",
    28  	DppHTypePCCARD: "PCCARD",
    29  	DppHTypeMMap:   "MMap",
    30  	DppHTypeVendor: "Vendor",
    31  	DppHTypeCtrl:   "Control",
    32  	DppHTypeBMC:    "BMC",
    33  }
    34  
    35  func (e EfiDppHwSubType) String() string {
    36  	if s, ok := efiDppHwSubTypeStrings[e]; ok {
    37  		return s
    38  	}
    39  	return fmt.Sprintf("UNKNOWN-0x%x", uint8(e))
    40  }
    41  
    42  // DppHwPci is the struct in EfiDevicePathProtocol for DppHTypePCI
    43  type DppHwPci struct {
    44  	Hdr              EfiDevicePathProtocolHdr
    45  	Function, Device uint8
    46  }
    47  
    48  var _ EfiDevicePathProtocol = (*DppHwPci)(nil)
    49  
    50  // Parses input into a DppHwPci struct.
    51  func ParseDppHwPci(h EfiDevicePathProtocolHdr, b []byte) (*DppHwPci, error) {
    52  	if len(b) != 2 {
    53  		return nil, ErrParse
    54  	}
    55  	return &DppHwPci{
    56  		Hdr:      h,
    57  		Function: b[0],
    58  		Device:   b[1],
    59  	}, nil
    60  }
    61  
    62  func (e *DppHwPci) Header() EfiDevicePathProtocolHdr { return e.Hdr }
    63  
    64  // ProtoSubTypeStr returns the subtype as human readable.
    65  func (e *DppHwPci) ProtoSubTypeStr() string {
    66  	return EfiDppHwSubType(e.Hdr.ProtoSubType).String()
    67  }
    68  
    69  func (e *DppHwPci) String() string {
    70  	return fmt.Sprintf("PCI(0x%x,0x%x)", e.Function, e.Device)
    71  }
    72  
    73  // Resolver returns a nil EfiPathSegmentResolver and ErrUnimpl. See the comment
    74  // associated with ErrUnimpl.
    75  func (e *DppHwPci) Resolver() (EfiPathSegmentResolver, error) {
    76  	return nil, ErrUnimpl
    77  }