device

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 15 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package device contains the small pure-Go access layer for the Xilinx XDMA character devices. It deliberately uses os.File Read/Write and ReadAt/ WriteAt rather than cgo or a vendor userspace library.

Index

Constants

View Source
const (
	RegCtrl               uint32 = 0x00
	RegStatus             uint32 = 0x04
	RegInputSizeLo        uint32 = 0x08
	RegInputSizeHi        uint32 = 0x0c
	RegOutBytesLo         uint32 = 0x10
	RegOutBytesHi         uint32 = 0x14
	RegInBytesLo          uint32 = 0x18
	RegInBytesHi          uint32 = 0x1c
	RegC2HRequestLen      uint32 = 0x20
	RegDebug              uint32 = 0x24
	RegCapabilities       uint32 = 0x40
	CapabilitiesPacketEOP uint32 = 0x475a0001
)

User-BAR register offsets for the gzip shell implemented in the FPGA.

View Source
const (
	CtrlStart     uint32 = 1 << 0
	CtrlSoftReset uint32 = 1 << 1
	CtrlC2HStart  uint32 = 1 << 2
)

Control register bits.

View Source
const (
	StatusBusy      uint32 = 1 << 0
	StatusDone      uint32 = 1 << 1
	StatusResetBusy uint32 = 1 << 2
	StatusError     uint32 = 1 << 3
	StatusC2HDone   uint32 = 1 << 4
)

Status register bits.

Variables

This section is empty.

Functions

func StatusName

func StatusName(status uint32) string

Types

type Device

type Device struct {
	// contains filtered or unexported fields
}

Device is a handle to the user BAR and one H2C/C2H streaming pair.

func Open

func Open(paths Paths) (*Device, error)

Open opens the three device nodes. The caller owns the returned device and must call Close.

func (*Device) Close

func (d *Device) Close() error

Close closes all device files; see CloseStreams for in-flight I/O behavior.

func (*Device) CloseStreams

func (d *Device) CloseStreams() error

CloseStreams closes the DMA handles. It is safe to call more than once and is used by cancellation handling. An in-flight character-device syscall may remain blocked until the driver completes or times out the transfer.

func (*Device) EnableRegisterMmap added in v0.0.3

func (d *Device) EnableRegisterMmap() error

EnableRegisterMmap maps the selected bank's page through the XDMA driver's noncached BAR mapping. Select the bank before enabling it. On Linux/amd64, aligned 32-bit accesses preserve MMIO transaction width and x86 UC ordering. Other platforms retain the portable ReadAt/WriteAt register path.

func (*Device) FirmwareInfo added in v0.0.3

func (d *Device) FirmwareInfo(ctx context.Context) (firmware.Info, error)

FirmwareInfo reads the image identity without resetting or starting a task.

func (*Device) PacketReadsEnabled added in v0.0.3

func (d *Device) PacketReadsEnabled() bool

PacketReadsEnabled reports negotiated end-of-gzip packets and XDMA EOP flush.

func (*Device) ReadC2H

func (d *Device) ReadC2H(p []byte) (int, error)

ReadC2H reads one FPGA output packet. The caller intentionally controls the requested length because the gzip shell exposes a length-defined packetizer.

func (*Device) ReadReg32

func (d *Device) ReadReg32(_ context.Context, offset uint32) (uint32, error)

ReadReg32 reads a little-endian 32-bit user-BAR register.

func (*Device) ReadReg64Stable

func (d *Device) ReadReg64Stable(ctx context.Context, loOffset, hiOffset uint32) (uint64, error)

ReadReg64Stable reads a 64-bit counter exposed as adjacent low/high words.

func (*Device) SetRegisterBase added in v0.0.3

func (d *Device) SetRegisterBase(base uint32) error

SetRegisterBase selects a bank before the first transaction. Do not call it concurrently with register access or DMA. It also allows callers built with an older SDK to discover multi-bank support through an optional interface.

func (*Device) Snapshot

func (d *Device) Snapshot(ctx context.Context) (Snapshot, error)

Snapshot reads the status and byte counters from the gzip shell.

func (*Device) SoftReset

func (d *Device) SoftReset(ctx context.Context, timeout time.Duration) error

SoftReset asserts the shell reset bit and waits for RESET_BUSY to clear.

func (*Device) Start

func (d *Device) Start(ctx context.Context, inputSize uint64, timeout time.Duration) error

Start writes the input length, verifies it, and starts one gzip operation.

func (*Device) StartC2HRequest

func (d *Device) StartC2HRequest(ctx context.Context, requestLen uint32) error

StartC2HRequest arms the packetizer for exactly requestLen bytes.

func (*Device) TransferSnapshot

func (d *Device) TransferSnapshot(ctx context.Context) (Snapshot, error)

TransferSnapshot is the low-latency snapshot used by the C2H drain loop. The reference C implementation reads only STATUS and OUT_BYTES on this hot path; DEBUG is fetched only when the shell reports an error. Keeping IN_BYTES out of the poll loop avoids unnecessary PCIe MMIO reads at high throughput.

func (*Device) WriteH2C

func (d *Device) WriteH2C(p []byte) (int, error)

WriteH2C writes one or more bytes to the FPGA input stream.

func (*Device) WriteReg32

func (d *Device) WriteReg32(_ context.Context, offset uint32, value uint32) error

WriteReg32 writes a little-endian 32-bit user-BAR register.

type Lease added in v0.0.3

type Lease struct {
	*Device
	// contains filtered or unexported fields
}

Lease must be closed by the caller, even after a failed or cancelled run.

func (*Lease) Close added in v0.0.3

func (l *Lease) Close() error

type Paths

type Paths struct {
	User string
	H2C  string
	C2H  string
	// RegisterBase selects an independent control bank. The validated four-core
	// shell uses core*0x1000; DMA channel indices must match that core.
	RegisterBase uint32
	// LegacyPackets forces the original exact-length protocol for diagnosis.
	LegacyPackets bool
}

Paths identifies the XDMA character devices created by xdma.ko.

func FourCorePaths added in v0.0.3

func FourCorePaths(first Paths, count int) ([]Paths, error)

FourCorePaths maps the validated four-core shell's independent DMA channels to their control banks. Explicit opt-in is required: node count alone does not establish that a bitstream contains independent gzip cores.

type Pool added in v0.0.3

type Pool struct {
	// contains filtered or unexported fields
}

Pool leases independent streams. Each lease opens fresh handles and retains its core until Close, including after RunReader closes the streaming FDs. Pool owns no persistent FDs and requires no shutdown call.

func NewPool added in v0.0.3

func NewPool(paths []Paths) (*Pool, error)

func (*Pool) Acquire added in v0.0.3

func (p *Pool) Acquire(ctx context.Context) (*Lease, error)

func (*Pool) AcquireActive added in v0.0.3

func (p *Pool) AcquireActive(ctx context.Context) (*Lease, error)

AcquireActive limits admission to the cores advertised by the current image. This lets a four-channel daemon follow a two-core Zstd image without serving alternate requests on inactive banks. Identity checks in the transaction remain mandatory because a switch can occur after this read-only probe.

type Snapshot

type Snapshot struct {
	Status   uint32
	Debug    uint32
	InBytes  uint64
	OutBytes uint64
}

Snapshot is the gzip shell's observable progress state.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL