Documentation
¶
Overview ¶
Package hal defines the Hardware Abstraction Layer interfaces for an IPMI BMC.
Every sub-interface is optional: a HAL implementation may return nil for subsystems that do not exist on the target hardware. Handlers must nil-check sub-interfaces and return an appropriate IPMI completion code when the hardware capability is absent.
Portability ¶
The interfaces in this package are deliberately free of OS-specific types. The only concrete Go packages used in the interface signatures are from the standard library and only primitives (context, error, []byte, basic types). This makes it possible to implement HAL for:
- Linux via sysfs / hwmon / i2c-dev / libgpiod (not yet implemented in-tree)
- Bare-metal Go / TinyGo with direct MMIO or SPI/I2C drivers
- Simulation / test via pkg/hal/mock
- Bridges to existing daemon APIs (e.g. OpenBMC D-Bus)
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errNotFound{}
ErrNotFound is returned by storage HAL methods when a FRU device ID or SDR record ID is absent. Storage handlers map this to CBh (v2.0§5.2 Table 5-2).
var ErrNotSupported = errNotSupported{}
ErrNotSupported is returned by HAL methods when the hardware does not support the requested operation. Handlers translate this to an appropriate IPMI completion code: CodeParameterNotSupported 0x80 (v2.0§28.12/§28.13) for parameter-level operations, CodeUnspecifiedError 0xFF (v2.0§5.2 Table 5-2) via codeFromErr for general error paths.
Functions ¶
This section is empty.
Types ¶
type ChassisHAL ¶
type ChassisHAL interface {
// PowerState returns true when the managed system is powered on.
PowerState(ctx context.Context) (bool, error)
// SetPower powers the managed system on or off.
SetPower(ctx context.Context, on bool) error
// PowerCycle performs a full power cycle of the managed system
// (Chassis Control action 0x02, spec Table 28-3). The semantic meaning
// for a given BMC is defined by the upper-layer HAL implementation.
PowerCycle(ctx context.Context) error
// ColdReset performs a hardware cold reset of the managed system.
ColdReset(ctx context.Context) error
// WarmReset requests an OS-level warm reboot of the managed system.
WarmReset(ctx context.Context) error
// Identify pulses the chassis identification LED for the given duration.
// seconds == 0 means turn off; [ForcedIdentify] is expressed by the caller
// passing a large value (e.g., math.MaxUint8).
Identify(ctx context.Context, seconds uint8) error
// IntrusionState returns true when the chassis has been opened since last reset.
// Implementations that lack intrusion detection must return ErrNotSupported.
IntrusionState(ctx context.Context) (bool, error)
// SetBootFlags commits the full boot flags structure (spec Table 28-6).
// The upper layer decides which bits it cares about; HAL implementations
// must not silently drop fields they ignore. Implementations that do not
// maintain boot state return ErrNotSupported.
SetBootFlags(ctx context.Context, flags *types.BootOptionParam_BootFlags) error
// GetBootFlags reads back the current boot flags, symmetric with
// [SetBootFlags]. Implementations that cannot read boot flags back must
// return ErrNotSupported; handlers translate that to the
// CodeParameterNotSupported completion code.
GetBootFlags(ctx context.Context) (*types.BootOptionParam_BootFlags, error)
// SetBootInfoAcknowledge persists the boot initiator acknowledge data
// (spec Table 28-14, param #4). The HAL may implement this as a no-op
// (return nil) if it does not track boot initiator identity.
SetBootInfoAcknowledge(ctx context.Context, ack *types.BootOptionParam_BootInfoAcknowledge) error
// GetBootInfoAcknowledge reads back the stored acknowledge data.
// Implementations that do not persist this return ErrNotSupported.
GetBootInfoAcknowledge(ctx context.Context) (*types.BootOptionParam_BootInfoAcknowledge, error)
}
ChassisHAL controls physical chassis power, reset, and identity.
type FRUStore ¶
type FRUStore interface {
Read(ctx context.Context, deviceID uint8) ([]byte, error)
Write(ctx context.Context, deviceID uint8, data []byte) error
Delete(ctx context.Context, deviceID uint8) error
DeviceIDs(ctx context.Context) ([]uint8, error)
}
FRUStore holds wire-format FRU inventory blobs (v2.0§34). DeviceID 0 is the builtin MC FRU at LUN 00b.
type GPIOHAL ¶
type GPIOHAL interface {
// Set drives an output GPIO high (true) or low (false).
Set(ctx context.Context, pin string, high bool) error
// Get reads the current level of an input GPIO.
Get(ctx context.Context, pin string) (bool, error)
// Watch calls callback whenever the input level changes.
// The returned cancel function stops watching.
Watch(ctx context.Context, pin string, callback func(high bool)) (cancel func(), err error)
}
GPIOHAL provides access to discrete GPIO lines (status LEDs, front-panel buttons).
type HAL ¶
type HAL interface {
// Chassis returns chassis power and identification controls, or nil.
Chassis() ChassisHAL
// Sensors returns the sensor reading interface, or nil.
Sensors() SensorHAL
// Storage returns FRU/SDR blob stores for Storage NetFn handlers, or nil.
Storage() StorageHAL
// Network returns BMC NIC configuration, or nil.
Network() NetworkHAL
// GPIO returns discrete GPIO control (LEDs, buttons), or nil.
GPIO() GPIOHAL
// I2C returns raw I2C bus access for sensors or EEPROMs, or nil.
I2C() I2CHAL
// Close releases all hardware resources.
Close() error
}
HAL is the top-level hardware abstraction. Implementations may return nil for sub-interfaces that are not available on the target.
type I2CHAL ¶
type I2CHAL interface {
// Read performs a register read from an I2C device.
Read(ctx context.Context, bus int, addr uint8, reg uint8, length int) ([]byte, error)
// Write performs a register write to an I2C device.
Write(ctx context.Context, bus int, addr uint8, reg uint8, data []byte) error
}
I2CHAL provides raw I2C bus access for sensors or EEPROM-backed FRU devices.
type NetworkHAL ¶
type NetworkHAL interface {
GetConfig(ctx context.Context) (*IPConfig, error)
SetConfig(ctx context.Context, cfg *IPConfig) error
}
NetworkHAL configures the BMC's own network interface. This is separate from [transport.PacketConn]: transport is how packets arrive; NetworkHAL is how the LAN configuration commands read/write NIC parameters.
type SDRStore ¶
type SDRStore interface {
Read(ctx context.Context, recordID uint16) ([]byte, error)
Write(ctx context.Context, recordID uint16, data []byte) error
Delete(ctx context.Context, recordID uint16) error
RecordIDs(ctx context.Context) ([]uint16, error)
}
SDRStore holds wire-format SDR repository records (v2.0§33). RecordID 0 is not a valid stored ID; [bmc.SDRRepository.GetRecord] maps Get SDR(0000h) to the first record and Get SDR(FFFFh) to the last (v2.0§33.12).
type SensorDescriptor ¶
type SensorDescriptor struct {
ID uint8
Type uint8 // IPMI sensor type code (section 42 of IPMI spec)
Name string
}
SensorDescriptor describes a sensor exposed by the hardware.
type SensorHAL ¶
type SensorHAL interface {
// ReadRaw returns the raw sensor byte that the BMC formula maps to a real value.
ReadRaw(ctx context.Context, sensorID uint8) (uint8, error)
// List returns all sensors available on the hardware.
List(ctx context.Context) ([]SensorDescriptor, error)
}
SensorHAL reads hardware sensor values.
type StorageHAL ¶
StorageHAL groups persistent blob stores for Storage NetFn data (v2.0§33–§34). Each sub-store may be nil when the backing hardware is absent.