Documentation
¶
Overview ¶
Package hwapi provides access to low level hardware
Index ¶
- Constants
- Variables
- func IterateOverE820Ranges(t string, callback func(start uint64, end uint64) bool) (bool, error)
- func MockPCReadMemory(addr uint64) byte
- type ACPIRsdp
- type APIInterfaces
- type DMAProtectedRange
- type HashAlg
- type IA32Debug
- type PCR
- type SMRR
- type TCGVendorID
- type TPM
- func (t *TPM) Close() error
- func (t *TPM) GetCapability(cap, subcap uint32) ([]interface{}, error)
- func (t *TPM) GetVersion() TPMVersion
- func (t *TPM) Info() (*TPMInfo, error)
- func (t *TPM) MeasurementLog() ([]byte, error)
- func (t *TPM) NVReadValue(index uint32, ownerPassword string, size, offhandle uint32) ([]byte, error)
- func (t *TPM) ReadNVPublic(index uint32) ([]byte, error)
- func (t *TPM) ReadPCR(pcrIndex uint32) ([]byte, error)
- func (t *TPM) ReadPCRs(alg HashAlg) ([]PCR, error)
- type TPMInfo
- type TPMInterface
- type TPMVersion
- type TxtAPI
- func (t TxtAPI) AddressRangesIsDMAProtected(first, end uint64) (bool, error)
- func (t TxtAPI) AllowsVMXInSMX() (bool, error)
- func (t TxtAPI) CPUBlacklistTXTSupport() bool
- func (t TxtAPI) CPULogCount() uint32
- func (t TxtAPI) CPUSignature() uint32
- func (t TxtAPI) CPUWhitelistTXTSupport() bool
- func (t TxtAPI) GetACPITable(n string) ([]byte, error)
- func (t TxtAPI) GetSMRRInfo() (SMRR, error)
- func (t TxtAPI) HasMTRR() bool
- func (t TxtAPI) HasSMRR() (bool, error)
- func (t TxtAPI) HasSMX() bool
- func (t TxtAPI) HasVMX() bool
- func (t TxtAPI) IA32DebugInterfaceEnabledOrLocked() (*IA32Debug, error)
- func (t TxtAPI) IA32FeatureControlIsLocked() (bool, error)
- func (t TxtAPI) IA32PlatformID() (uint64, error)
- func (t TxtAPI) IsReservedInE820(start uint64, end uint64) (bool, error)
- func (t TxtAPI) LookupIOAddress(addr uint64, regs VTdRegisters) ([]uint64, error)
- func (t TxtAPI) NVLocked(tpmCon *TPM) (bool, error)
- func (t TxtAPI) NVReadValue(tpmCon *TPM, index uint32, password string, size, offhandle uint32) ([]byte, error)
- func (t TxtAPI) NewTPM() (*TPM, error)
- func (t TxtAPI) PCIReadConfig16(bus int, device int, devFn int, off int) (uint16, error)
- func (t TxtAPI) PCIReadConfig32(bus int, device int, devFn int, off int) (uint32, error)
- func (t TxtAPI) PCIReadConfigSpace(bus int, device int, devFn int, off int, buf interface{}) error
- func (t TxtAPI) PCIReadDeviceID(bus int, device int, devFn int) (uint16, error)
- func (t TxtAPI) PCIReadVendorID(bus int, device int, devFn int) (uint16, error)
- func (t TxtAPI) ProcessorBrandName() string
- func (t TxtAPI) ReadHostBridgeDPR() (DMAProtectedRange, error)
- func (t TxtAPI) ReadHostBridgeTseg() (uint32, uint32, error)
- func (t TxtAPI) ReadNVPublic(tpmCon *TPM, index uint32) ([]byte, error)
- func (t TxtAPI) ReadPCR(tpmCon *TPM, pcr uint32) ([]byte, error)
- func (t TxtAPI) ReadPhys(addr int64, data UintN) error
- func (t TxtAPI) ReadPhysBuf(addr int64, buf []byte) error
- func (t TxtAPI) TXTLeavesAreEnabled() (bool, error)
- func (t TxtAPI) VersionString() string
- func (t TxtAPI) WritePhys(addr int64, data UintN) error
- type Uint16
- type Uint32
- type Uint64
- type Uint8
- type UintN
- type VTdRegisters
Constants ¶
const ( // TsegPCIRegSandyAndNewer is the offset withing the MCH PCI config space since SandyBridge TsegPCIRegSandyAndNewer = 0xb8 // TSEGPCIBroadwellde is the offset withing the MCH PCI config space TSEGPCIBroadwellde = 0xa8 // DPRPCIRegSandyAndNewer is the offset withing the MCH PCI config space since SandyBridge DPRPCIRegSandyAndNewer = 0x5c // DPRPciRegBroadwellDE offset withing the VTd PCI config space DPRPciRegBroadwellDE = 0x290 )
Variables ¶
var ( // HostbridgeIDsBroadwellDE lookup table is special... HostbridgeIDsBroadwellDE = []uint16{ 0x2F00, 0x6F00, } // HostbridgeIDsSandyCompatible lookup table for most stuff that seems compatible with Sandy Bridge HostbridgeIDsSandyCompatible = []uint16{ 0x0100, 0x0104, 0x0150, 0x0154, 0x0158, 0x0c00, 0x0c04, 0x0a04, 0x0c08, 0x1980, 0x1995, 0x1604, 0x1610, 0x1614, 0x5af0, 0x31f0, 0x1900, 0x1904, 0x190c, 0x190f, 0x1910, 0x1918, 0x191f, 0x1924, 0x5904, 0x590c, 0x590f, 0x5910, 0x5914, 0x5918, 0x591f, 0x5a04, 0x5a02, 0x3E34, 0x3E35, 0x3ED0, 0x3ec4, 0x3e20, 0x3ec2, 0x3e30, 0x3e31, 0x8A12, 0x8A02, 0x8A10, 0x8A00, 0x9B61, 0x9B71, 0x9B51, 0x9B60, 0x9B55, 0x9B35, 0x9B54, 0x9B44, } )
var ( // HashSHA1 is the TPM 1.2 identifier for SHA1 HashSHA1 = HashAlg(tpm2.AlgSHA1) // HashSHA256 is the TPM 2.0 identifier for SHA256 HashSHA256 = HashAlg(tpm2.AlgSHA256) )
var ( //TXTSupportedCPUs is a whitelist of TXT enabled CPUs TXTSupportedCPUs = []brandNameMetaWl{}/* 774 elements not displayed */ )
var ( //TXTUnSupportedCPUs is a lookup table for CPUs not supporting TXT TXTUnSupportedCPUs = []brandNameMetaBl{}/* 1001 elements not displayed */ )
Functions ¶
func IterateOverE820Ranges ¶
IterateOverE820Ranges iterates over all e820 entries and invokes the callback for every matching type
func MockPCReadMemory ¶
MockPCReadMemory emulates a x86_64 platform memory map
Types ¶
type ACPIRsdp ¶
type ACPIRsdp struct { Signature [8]uint8 Checksum uint8 OEMID [6]uint8 Revision uint8 RSDTPtr uint32 RSDPLen uint32 XSDTLen uint32 XSDTPtr uint64 ExtendedChecksum uint8 Reserved [3]uint8 }
ACPIRsdp as defined in ACPI Spec 6.2 "5.2.5.3 Root System Description Pointer (RSDP) Structure"
type APIInterfaces ¶
type APIInterfaces interface { // cpu_whitelist.go - cpu_blacklist.go CPUBlacklistTXTSupport() bool CPUWhitelistTXTSupport() bool // cpuid.go VersionString() string HasSMX() bool HasVMX() bool HasMTRR() bool ProcessorBrandName() string CPUSignature() uint32 CPULogCount() uint32 // e820.go IsReservedInE820(start uint64, end uint64) (bool, error) // iommu.go LookupIOAddress(addr uint64, regs VTdRegisters) ([]uint64, error) AddressRangesIsDMAProtected(first, end uint64) (bool, error) // msr.go HasSMRR() (bool, error) GetSMRRInfo() (SMRR, error) IA32FeatureControlIsLocked() (bool, error) IA32PlatformID() (uint64, error) AllowsVMXInSMX() (bool, error) TXTLeavesAreEnabled() (bool, error) IA32DebugInterfaceEnabledOrLocked() (*IA32Debug, error) // pci.go PCIReadConfigSpace(bus int, device int, devFn int, off int, buf interface{}) error PCIReadConfig16(bus int, device int, devFn int, off int) (uint16, error) PCIReadConfig32(bus int, device int, devFn int, off int) (uint32, error) PCIReadVendorID(bus int, device int, devFn int) (uint16, error) PCIReadDeviceID(bus int, device int, devFn int) (uint16, error) ReadHostBridgeTseg() (uint32, uint32, error) ReadHostBridgeDPR() (DMAProtectedRange, error) // phys.go ReadPhys(addr int64, data UintN) error ReadPhysBuf(addr int64, buf []byte) error WritePhys(addr int64, data UintN) error // tpm.go NewTPM() (*TPM, error) NVLocked(tpmCon *TPM) (bool, error) ReadNVPublic(tpmCon *TPM, index uint32) ([]byte, error) NVReadValue(tpmCon *TPM, index uint32, password string, size, offhandle uint32) ([]byte, error) ReadPCR(tpmCon *TPM, pcr uint32) ([]byte, error) // acpi.go GetACPITable(n string) ([]byte, error) }
APIInterfaces provides methods to access hardware found on modern x86_64 platforms
func GetPcMock ¶
func GetPcMock(ReadMemoryFunc func(uint64) byte) APIInterfaces
GetPcMock returns APIInterfaces for mocking the hwapi used in unittests
type DMAProtectedRange ¶
DMAProtectedRange encodes the DPR register
type TCGVendorID ¶
type TCGVendorID uint32
TCGVendorID TPM manufacturer id
func (TCGVendorID) String ¶
func (id TCGVendorID) String() string
type TPM ¶
type TPM struct { Version TPMVersion Interf TPMInterface SysPath string RWC io.ReadWriteCloser }
TPM interfaces with a TPM device on the system.
func (*TPM) GetCapability ¶
GetCapability requests the TPMs capability function and returns an interface. User needs to take care of the data for now.
func (*TPM) MeasurementLog ¶
MeasurementLog reads the TCPA eventlog in binary format from the Linux kernel
func (*TPM) NVReadValue ¶
func (t *TPM) NVReadValue(index uint32, ownerPassword string, size, offhandle uint32) ([]byte, error)
NVReadValue reads a value from a given NVRAM index Type and byte order for TPM1.2 interface: (offset uint32) Type and byte oder for TPM2.0 interface: (authhandle uint32)
func (*TPM) ReadNVPublic ¶
ReadNVPublic reads public data about an NVRAM index. Permissions and what so not.
type TPMInfo ¶
type TPMInfo struct { Version TPMVersion Interface TPMInterface VendorInfo string Manufacturer TCGVendorID // FirmwareVersionMajor and FirmwareVersionMinor describe // the firmware version of the TPM, but are only available // for TPM 2.0 devices. FirmwareVersionMajor int FirmwareVersionMinor int }
TPMInfo contains information about the version & interface of an open TPM.
type TPMInterface ¶
type TPMInterface uint8
TPMInterface indicates how the client communicates with the TPM.
const ( TPMInterfaceDirect TPMInterface = iota TPMInterfaceKernelManaged TPMInterfaceDaemonManaged )
TPM interfaces
type TPMVersion ¶
type TPMVersion uint8
TPMVersion is used to configure a preference in which TPM to use, if multiple are available.
const ( TPMVersionAgnostic TPMVersion = iota TPMVersion12 TPMVersion20 )
TPM versions
type TxtAPI ¶
type TxtAPI struct{}
TxtAPI The context object for TXT Api
func (TxtAPI) AddressRangesIsDMAProtected ¶
AddressRangesIsDMAProtected returns true if the address is DMA protected by the IOMMU
func (TxtAPI) AllowsVMXInSMX ¶
AllowsVMXInSMX returns true if VMX is allowed in SMX
func (TxtAPI) CPUBlacklistTXTSupport ¶
CPUBlacklistTXTSupport - Returns true if the CPU is blacklisted
func (TxtAPI) CPULogCount ¶
CPULogCount returns number of logical CPU cores
func (TxtAPI) CPUWhitelistTXTSupport ¶
CPUWhitelistTXTSupport returns true if the CPU is whitelisted
func (TxtAPI) GetACPITable ¶
GetACPITable returns the requested ACPI table, for DSDT use argument "DSDT"
func (TxtAPI) GetSMRRInfo ¶
GetSMRRInfo returns SMRR config of the platform
func (TxtAPI) IA32DebugInterfaceEnabledOrLocked ¶
IA32DebugInterfaceEnabledOrLocked returns the enabled, locked and pchStrap state of IA32_DEBUG_INTERFACE msr
func (TxtAPI) IA32FeatureControlIsLocked ¶
IA32FeatureControlIsLocked returns true if the IA32_FEATURE_CONTROL msr is locked
func (TxtAPI) IA32PlatformID ¶
IA32PlatformID returns the IA32_PLATFORM_ID msr
func (TxtAPI) IsReservedInE820 ¶
IsReservedInE820 reads the e820 table exported via /sys/firmware/memmap and checks whether the range [start; end] is marked as reserved. Returns true if it is reserved, false if not.
func (TxtAPI) LookupIOAddress ¶
func (t TxtAPI) LookupIOAddress(addr uint64, regs VTdRegisters) ([]uint64, error)
LookupIOAddress returns the address of the root Tbl
func (TxtAPI) NVReadValue ¶
func (t TxtAPI) NVReadValue(tpmCon *TPM, index uint32, password string, size, offhandle uint32) ([]byte, error)
NVReadValue reads a given NV index
func (TxtAPI) PCIReadConfig16 ¶
PCIReadConfig16 reads 16bits from PCI config space
func (TxtAPI) PCIReadConfig32 ¶
PCIReadConfig32 reads 32bits from PCI config space
func (TxtAPI) PCIReadConfigSpace ¶
PCIReadConfigSpace reads from PCI config space into buf
func (TxtAPI) PCIReadDeviceID ¶
PCIReadDeviceID reads the device ID from PCI config space
func (TxtAPI) PCIReadVendorID ¶
PCIReadVendorID reads the device vendor ID from PCI config space
func (TxtAPI) ProcessorBrandName ¶
ProcessorBrandName returns the CPU brand name
func (TxtAPI) ReadHostBridgeDPR ¶
func (t TxtAPI) ReadHostBridgeDPR() (DMAProtectedRange, error)
ReadHostBridgeDPR reads the DPR register from PCI config space
func (TxtAPI) ReadHostBridgeTseg ¶
ReadHostBridgeTseg returns TSEG base and TSEG limit
func (TxtAPI) ReadNVPublic ¶
ReadNVPublic reads public data about an NV index
func (TxtAPI) ReadPhys ¶
ReadPhys reads data from physical memory at address addr. On x86 platforms, this uses the seek+read syscalls.
func (TxtAPI) ReadPhysBuf ¶
ReadPhysBuf reads data from physical memory at address addr. On x86 platforms, this uses the seek+read syscalls.
func (TxtAPI) TXTLeavesAreEnabled ¶
TXTLeavesAreEnabled returns true if all TXT leaves are enabled
func (TxtAPI) VersionString ¶
VersionString returns the vendor ID
type UintN ¶
type UintN interface { // Return size in bytes. Size() int64 // Return string formatted in hex. String() string // contains filtered or unexported methods }
UintN is a wrapper around uint types and provides a few io-related functions.
type VTdRegisters ¶
type VTdRegisters struct { Version uint32 // Architecture version supported by the implementation. Reserved1 uint32 // Reserved Capabilities uint64 // Hardware reporting of capabilities. ExtendedCapabilities uint64 // Hardware reporting of extended capabilities. GlobalCommand uint32 // Register controlling general functions. GlobalStatus uint32 // Register reporting general status. RootTableAddress uint64 // Register to set up location of root table. ContextCommand uint64 // Register to manage context-entry cache. Reserved2 uint32 // Reserved FaultStatus uint32 // Register to report Fault/Error status FaultEventControl uint32 // Interrupt control register for fault events. FaultEventData uint32 // Interrupt message data register for fault events. FaultEventAddress uint32 // Interrupt message address register for fault event messages. FaultEventUpperAddress uint32 // Interrupt message upper address register for fault event messages. Reserved3 uint64 // Reserved Reserved4 uint64 // Reserved AdvancedFaultLog uint64 // Register to configure and manage advanced fault logging. Reserved5 uint32 // Reserved ProtectedMemoryEnable uint32 // Register to enable DMA-protected memory region(s). ProtectedLowMemoryBase uint32 // Register pointing to base of DMA-protected low memory region. ProtectedLowMemoryLimit uint32 // Register pointing to last address (limit) of the DMA-protected low memory region. ProtectedHighMemoryBase uint64 // Register pointing to base of DMA-protected high memory region. ProtectedHighMemoryLimit uint64 // Register pointing to last address (limit) of the DMA-protected high memory region. InvalidationQueueHead uint64 // Offset to the invalidation queue entry that will be read next by hardware. InvalidationQueueTail uint64 // Offset to the invalidation queue entry that will be written next by software. InvalidationQueueAddress uint64 // Base address of memory-resident invalidation queue. Reserved6 uint32 // Reserved InvalidationCompletionStatus uint32 // Register to indicate the completion of an Invalidation Wait Descriptor with IF=1. InvalidationCompletionEventControl uint32 // Register to control Invalidation Queue Events InvalidationCompletionEventData uint32 // Invalidation Queue Event message data register for Invalidation Queue events. InvalidationCompletionEventAddress uint32 // Invalidation Queue Event message address register for Invalidation Queue events. InvalidationCompletionEventUpperAddress uint32 // Invalidation Queue Event message upper address register for Invalidation Queue events. Reserved7 uint64 // Reserved. InterruptRemappingTableAddress uint64 // Register indicating Base Address of Interrupt Remapping Table. PageRequestQueueHead uint64 // Offset to the page request queue entry that will be processed next by software. PageRequestQueueTail uint64 // Offset to the page request queue entry that will be written next by hardware. PageRequestQueueAddress uint64 // Base address of memory-resident page request queue. Reserved8 uint32 // Reserved PageRequestStatus uint32 // Register to indicate one or more pending page requests in page request queue. PageRequestEventControl uint32 // Register to control page request events. PageRequestEventData uint32 // Page request event message data register. PageRequestEventAddress uint32 // Page request event message address register PageRequestEventUpperAddress uint32 // Page request event message upper address register. MTRRCapability uint64 // Register for MTRR capability reporting. MTRRDefaultType uint64 // Register to configure MTRR default type. FixedRangeMTRR64K00000 uint64 // Fixed-range memory type range register for 64K range starting at 00000h. FixedRangeMTRR16K80000 uint64 // Fixed-range memory type range register for 16K range starting at 80000h. FixedRangeMTRR16KA0000 uint64 // Fixed-range memory type range register for 16K range starting at A0000h. FixedRangeMTRR4KC0000 uint64 // Fixed-range memory type range register for 4K range starting at C0000h. FixedRangeMTRR4KC8000 uint64 // Fixed-range memory type range register for 4K range starting at C8000h. FixedRangeMTRR4KD0000 uint64 // Fixed-range memory type range register for 4K range starting at D0000h. FixedRangeMTRR4KD8000 uint64 // Fixed-range memory type range register for 4K range starting at D8000h. FixedRangeMTRR4KE0000 uint64 // Fixed-range memory type range register for 4K range starting at E0000h. FixedRangeMTRR4KE8000 uint64 // Fixed-range memory type range register for 4K range starting at E8000h. FixedRangeMTRR4KF0000 uint64 // Fixed-range memory type range register for 4K range starting at F0000h. FixedRangeMTRR4KF8000 uint64 // Fixed-range memory type range register for 4K range starting at F8000h. VariableRangeMTRRBase0 uint64 // Variable-range memory type range0 base register. VariableRangeMTRRMask0 uint64 // Variable-range memory type range0 mask register. VariableRangeMTRRBase1 uint64 // Variable-range memory type range1 base register. VariableRangeMTRRMask1 uint64 // Variable-range memory type range1 mask register. VariableRangeMTRRBase2 uint64 // Variable-range memory type range2 base register. VariableRangeMTRRMask2 uint64 // Variable-range memory type range2 mask register. VariableRangeMTRRBase3 uint64 // Variable-range memory type range3 base register. VariableRangeMTRRMask3 uint64 // Variable-range memory type range3 mask register. VariableRangeMTRRBase4 uint64 // Variable-range memory type range4 base register. VariableRangeMTRRMask4 uint64 // Variable-range memory type range4 mask register. VariableRangeMTRRBase5 uint64 // Variable-range memory type range5 base register. VariableRangeMTRRMask5 uint64 // Variable-range memory type range5 mask register. VariableRangeMTRRBase6 uint64 // Variable-range memory type range6 base register. VariableRangeMTRRMask6 uint64 // Variable-range memory type range6 mask register. VariableRangeMTRRBase7 uint64 // Variable-range memory type range7 base register. VariableRangeMTRRMask7 uint64 // Variable-range memory type range7 mask register. VariableRangeMTRRBase8 uint64 // Variable-range memory type range8 base register. VariableRangeMTRRMask8 uint64 // Variable-range memory type range8 mask register. VariableRangeMTRRBase9 uint64 // Variable-range memory type range9 base register. VariableRangeMTRRMask9 uint64 // Variable-range memory type range9 mask register. VirtualCommandCapability uint64 // Hardware reporting of commands supported by virtual-DMA Remapping hardware. Reserved10 uint64 // Reserved for future expansion of Virtual Command Capability Register. VirtualCommand uint64 // Register to submit commands to virtual DMA Remapping hardware. Reserved11 uint64 // Reserved for future expansion of Virtual Command Register. VirtualCommandResponse uint64 // Register to receive responses from virtual DMA Remapping hardware. Reserved12 uint64 // Reserved for future expansion of Virtual Command Response Register. }
VTdRegisters represents the IOMMIO space