drm

package
v0.3.18 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 14 Imported by: 3 modules, 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 drm issues DRM ioctls on a device node, in pure Go: KMS resources, connectors, planes, properties and blobs, dumb buffers, framebuffers and atomic commits, capabilities, CRTC vblank sequences, and timeline syncobjs and sync files for explicit synchronization.

Index

Constants

View Source
const (
	// CapCursorWidth is DRM_CAP_CURSOR_WIDTH: the cursor plane's width in pixels.
	CapCursorWidth = 0x8
	// CapCursorHeight is DRM_CAP_CURSOR_HEIGHT: the cursor plane's height in pixels.
	CapCursorHeight = 0x9
	// CapAddFB2Modifiers is DRM_CAP_ADDFB2_MODIFIERS: AddFB2 takes format modifiers.
	CapAddFB2Modifiers = 0x10
	// CapAtomicAsyncFlip is DRM_CAP_ATOMIC_ASYNC_PAGE_FLIP: atomic commits take AtomicPageFlipAsync.
	CapAtomicAsyncFlip = 0x15
)

Device capabilities, as DRM_IOCTL_GET_CAP numbers them for Cap.

View Source
const (
	// ClientCapUniversal is DRM_CLIENT_CAP_UNIVERSAL_PLANES: Planes lists primary and cursor planes too.
	ClientCapUniversal = 2
	// ClientCapAtomic is DRM_CLIENT_CAP_ATOMIC: the client may Commit atomic requests.
	ClientCapAtomic = 3
	// ClientCapCursorHotspot is DRM_CLIENT_CAP_CURSOR_PLANE_HOTSPOT: the client sets cursor hotspots, as virtual GPUs need.
	ClientCapCursorHotspot = 6
)

Client capabilities, as DRM_IOCTL_SET_CLIENT_CAP numbers them for SetClientCap.

View Source
const (
	// ObjectCRTC is DRM_MODE_OBJECT_CRTC.
	ObjectCRTC = 0xcccccccc
	// ObjectConnector is DRM_MODE_OBJECT_CONNECTOR.
	ObjectConnector = 0xc0c0c0c0
	// ObjectPlane is DRM_MODE_OBJECT_PLANE.
	ObjectPlane = 0xeeeeeeee
)

KMS object types, the DRM_MODE_OBJECT_* values Properties takes.

View Source
const (
	// ModeTypePreferred is DRM_MODE_TYPE_PREFERRED: the sink's preferred mode.
	ModeTypePreferred = 1 << 3
	// ModeFlagInterlace is DRM_MODE_FLAG_INTERLACE: the mode scans interlaced fields.
	ModeFlagInterlace = 1 << 4
	// ModeFlagDoubleScan is DRM_MODE_FLAG_DBLSCAN: every line is scanned twice.
	ModeFlagDoubleScan = 1 << 5
)

Mode type and flag bits, as Mode.Type and Mode.Flags carry them.

View Source
const (
	// AtomicPageFlipEvent is DRM_MODE_PAGE_FLIP_EVENT: the commit queues a flip-complete event on the device fd.
	AtomicPageFlipEvent = 0x01
	// AtomicPageFlipAsync is DRM_MODE_PAGE_FLIP_ASYNC: the flip happens without waiting for vblank, tearing.
	AtomicPageFlipAsync = 0x02
	// AtomicTestOnly is DRM_MODE_ATOMIC_TEST_ONLY: the kernel checks the commit and applies nothing.
	AtomicTestOnly = 0x0100
	// AtomicNonblock is DRM_MODE_ATOMIC_NONBLOCK: Commit returns before the commit takes effect.
	AtomicNonblock = 0x0200
	// AtomicAllowModeset is DRM_MODE_ATOMIC_ALLOW_MODESET: the commit may change modes and routing.
	AtomicAllowModeset = 0x0400
)

Atomic commit flags, the DRM_MODE_PAGE_FLIP_* and DRM_MODE_ATOMIC_* bits Commit takes.

View Source
const (
	// CapSyncobj is DRM_CAP_SYNCOBJ: the device has binary sync objects.
	CapSyncobj = 0x13
	// CapSyncobjTimeline is DRM_CAP_SYNCOBJ_TIMELINE: the device has timeline sync objects.
	CapSyncobjTimeline = 0x14
)

Sync object capabilities, as Cap reads them.

View Source
const EventFlipComplete = 0x02

EventFlipComplete is DRM_EVENT_FLIP_COMPLETE, the event type ParseEvents reports as a FlipEvent.

View Source
const FBModifiers = 1 << 1

FBModifiers is DRM_MODE_FB_MODIFIERS, the ADDFB2 flag that makes the kernel read the per-plane modifiers.

Variables

View Source
var ErrNoCloseFB = errors.New("drm: no DRM_IOCTL_MODE_CLOSEFB before Linux 6.8")

ErrNoCloseFB is what CloseFB wraps on a kernel without DRM_IOCTL_MODE_CLOSEFB, one older than Linux 6.8.

View Source
var ErrNoVblankSequence = errors.New("drm: the driver keeps no vblank sequence")

ErrNoVblankSequence reports a driver that keeps no vblank count for DRM_IOCTL_CRTC_GET_SEQUENCE to read: one without vblank support, which fails it with EOPNOTSUPP, or NVIDIA's, which answers sequence 0 and a time that says nothing either.

Functions

func Modifiers

func Modifiers(inFormats []byte, format fourcc.Format) ([]fourcc.Modifier, error)

Modifiers lists the modifiers a plane's IN_FORMATS blob pairs with format, none when the plane lacks the format. It fails on a blob whose tables run past its end.

func ParseEvents

func ParseEvents(buf []byte, flip func(FlipEvent) error) error

ParseEvents walks the events read from the device fd in buf and calls flip for each flip-complete event, skipping other events. It stops at flip's first error and returns it, and fails on an event whose length is malformed, runs past buf or is cut short.

func SyncFileSignalTime

func SyncFileSignalTime(fd int) (time.Duration, bool, error)

SyncFileSignalTime reads when the sync file fd signaled, with SYNC_IOC_FILE_INFO: the latest signal timestamp of its fences, on CLOCK_MONOTONIC. It reports false while any fence is unsignaled or the file holds none. A file of up to syncFenceCapacity fences takes one ioctl and no allocation.

func SyncFileSignalled

func SyncFileSignalled(fd int) (bool, error)

SyncFileSignalled reports whether every fence in the sync file fd has signalled, in one SYNC_IOC_FILE_INFO that does not read the fences.

Types

type Connection

type Connection uint32

Connection is a connector's state, as the kernel's enum drm_connector_status.

const (
	Connected    Connection = 1
	Disconnected Connection = 2
	Unknown      Connection = 3
)

The connector states.

type Connector

type Connector struct {
	ID, Type, TypeID uint32
	Connection       Connection
	PhysicalMM       [2]uint32
	Modes            []Mode
	Encoders         []uint32
}

Connector is a KMS connector: its ID, its DRM_MODE_CONNECTOR_* type and the index among connectors of that type, its state, the physical size of the attached display in mm, its modes and the IDs of the encoders that can drive it.

func (Connector) Name

func (c Connector) Name() string

Name is the connector's name as the kernel and other compositors spell it, such as "eDP-1" or "HDMI-A-2", or "Type<N>-<index>" for a type this package does not know.

type Device

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

Device is an open DRM device node, a card or a render node.

func FromFD

func FromFD(fd int, path string) *Device

FromFD wraps an already open DRM device fd, such as one logind handed over, named path in errors. The Device takes ownership of fd and closes it in Close.

func Open

func Open(path string) (*Device, error)

Open opens the DRM device node at path read-write and close-on-exec.

func (*Device) AddFB2

func (d *Device) AddFB2(fb FB) (uint32, error)

AddFB2 makes a framebuffer of fb with DRM_IOCTL_MODE_ADDFB2, passing FBModifiers when fb.WithModifier is set, and returns its ID. Release it with RemoveFB.

func (*Device) Blob

func (d *Device) Blob(id uint32) ([]byte, error)

Blob reads property blob id, such as an EDID or IN_FORMATS, with DRM_IOCTL_MODE_GETPROPBLOB.

func (*Device) CRTCSequence

func (d *Device) CRTCSequence(crtc uint32) (Vblank, error)

CRTCSequence reads crtc's most recent vblank with DRM_IOCTL_CRTC_GET_SEQUENCE, what a frame clock re-anchors on after idle. A CRTC that is off fails with EINVAL, and a driver with no vblank count with ErrNoVblankSequence.

func (*Device) Cap

func (d *Device) Cap(capability uint64) (uint64, error)

Cap reads a device capability, one of the Cap* constants, with DRM_IOCTL_GET_CAP. An unknown capability fails with EINVAL.

func (*Device) Close

func (d *Device) Close() error

Close closes the device's fd.

func (*Device) CloseFB

func (d *Device) CloseFB(id uint32) error

CloseFB releases framebuffer id with DRM_IOCTL_MODE_CLOSEFB, which, unlike RemoveFB, leaves the planes showing it on screen until a commit replaces it or turns them off, so a picture outlives this process for the next master to take over. Before Linux 6.8 the kernel lacks the ioctl and CloseFB fails with ErrNoCloseFB wrapping its EINVAL or ENOTTY; it never falls back to RemoveFB. On an unplugged device (ENODEV) it succeeds.

func (*Device) CloseHandle

func (d *Device) CloseHandle(handle uint32) error

CloseHandle releases a GEM handle with DRM_IOCTL_GEM_CLOSE. On an unplugged device (ENODEV) it succeeds.

func (*Device) Commit

func (d *Device) Commit(r *Request, flags uint32, userData uint64) error

Commit applies r with DRM_IOCTL_MODE_ATOMIC, grouping its values by object. flags are the Atomic* constants; userData comes back in the FlipEvent when flags hold AtomicPageFlipEvent.

func (*Device) Connector

func (d *Device) Connector(id uint32) (Connector, error)

Connector reads connector id with DRM_IOCTL_MODE_GETCONNECTOR, which may probe the display, asking again whenever the mode, encoder or property counts change between the sizing call and the filling call.

func (*Device) CreateBlob

func (d *Device) CreateBlob(data []byte) (uint32, error)

CreateBlob makes a property blob holding data, such as a Mode's Bytes for MODE_ID, with DRM_IOCTL_MODE_CREATEPROPBLOB, and returns its ID. Release it with DestroyBlob.

func (*Device) CreateDumb

func (d *Device) CreateDumb(size image.Point) (Dumb, error)

CreateDumb makes a 32 bits per pixel dumb buffer of size pixels with DRM_IOCTL_MODE_CREATE_DUMB and maps it with DRM_IOCTL_MODE_MAP_DUMB and mmap. Each side must be between 1 and 65535. A failed mapping destroys the buffer again. Release it with DestroyDumb.

func (*Device) CreateSyncobj

func (d *Device) CreateSyncobj(signaled bool) (Syncobj, error)

CreateSyncobj makes a sync object with DRM_IOCTL_SYNCOBJ_CREATE, already signaled when signaled is set. Release it with DestroySyncobj.

func (*Device) DestroyBlob

func (d *Device) DestroyBlob(id uint32) error

DestroyBlob releases property blob id with DRM_IOCTL_MODE_DESTROYPROPBLOB. On an unplugged device (ENODEV) it succeeds, since the blob is gone with it.

func (*Device) DestroyDumb

func (d *Device) DestroyDumb(b Dumb) error

DestroyDumb unmaps b and releases it with DRM_IOCTL_MODE_DESTROY_DUMB. On an unplugged device (ENODEV) the release succeeds.

func (*Device) DestroySyncobj

func (d *Device) DestroySyncobj(s Syncobj) error

DestroySyncobj releases s with DRM_IOCTL_SYNCOBJ_DESTROY.

func (*Device) DropMaster

func (d *Device) DropMaster() error

DropMaster gives up this file's DRM master with DRM_IOCTL_DROP_MASTER, so another process can take the card. It fails with EINVAL when the file is not master.

func (*Device) Encoder

func (d *Device) Encoder(id uint32) (Encoder, error)

Encoder reads encoder id with DRM_IOCTL_MODE_GETENCODER.

func (*Device) EventFD

func (d *Device) EventFD(s Syncobj, point uint64, eventfd int, available bool) error

EventFD makes the kernel signal eventfd once timeline point point of s signals, or, with available set, once a fence for it is attached, with DRM_IOCTL_SYNCOBJ_EVENTFD.

func (*Device) ExportSyncFile

func (d *Device) ExportSyncFile(s Syncobj, point uint64) (int, error)

ExportSyncFile exports the fence at timeline point point of s as a new sync file fd, through a temporary binary sync object; the caller owns the fd. The point must already have a fence.

func (*Device) ExportSyncobj

func (d *Device) ExportSyncobj(s Syncobj) (int, error)

ExportSyncobj exports s as a new sync object fd with DRM_IOCTL_SYNCOBJ_HANDLE_TO_FD; the caller owns the fd.

func (*Device) FD

func (d *Device) FD() int

FD is the device's file descriptor, for polling it for events. The Device keeps owning it.

func (*Device) ImportSyncFile

func (d *Device) ImportSyncFile(s Syncobj, point uint64, syncFile int) error

ImportSyncFile attaches the fence in syncFile to timeline point point of s, through a temporary binary sync object and DRM_IOCTL_SYNCOBJ_TRANSFER. The fd stays the caller's.

func (*Device) ImportSyncobj

func (d *Device) ImportSyncobj(fd int) (Syncobj, error)

ImportSyncobj imports a sync object fd, as a client hands over for linux-drm-syncobj, with DRM_IOCTL_SYNCOBJ_FD_TO_HANDLE. The fd stays the caller's.

func (*Device) Number

func (d *Device) Number() (uint64, error)

Number is the device number (st_rdev) of the device's node, as linux-dmabuf feedback and logind name devices.

func (*Device) Path

func (d *Device) Path() string

Path is the device node's path.

func (*Device) Plane

func (d *Device) Plane(id uint32) (Plane, error)

Plane reads plane id with DRM_IOCTL_MODE_GETPLANE.

func (*Device) Planes

func (d *Device) Planes() ([]uint32, error)

Planes lists the card's plane IDs with DRM_IOCTL_MODE_GETPLANERESOURCES. Primary and cursor planes are listed only once ClientCapUniversal is set.

func (*Device) PrimeFDToHandle

func (d *Device) PrimeFDToHandle(fd int) (uint32, error)

PrimeFDToHandle imports dmabuf fd as a GEM handle on the device with DRM_IOCTL_PRIME_FD_TO_HANDLE. The fd stays the caller's; release the handle with CloseHandle.

func (*Device) Properties

func (d *Device) Properties(objectID, objectType uint32) (map[string]Property, error)

Properties reads an object's properties by name with DRM_IOCTL_MODE_OBJ_GETPROPERTIES. objectType is one of the Object* constants. Names are resolved through PropertyInfo.

func (*Device) PropertyInfo

func (d *Device) PropertyInfo(id uint32) (PropertyInfo, error)

PropertyInfo reads property id's name and enumerators with DRM_IOCTL_MODE_GETPROPERTY, once per Device: later calls are served from a cache, since a property's definition never changes. It is not safe for concurrent use.

func (*Device) Query

func (d *Device) Query(s Syncobj) (uint64, error)

Query reads the last signaled point of timeline s with DRM_IOCTL_SYNCOBJ_QUERY.

func (*Device) RemoveFB

func (d *Device) RemoveFB(id uint32) error

RemoveFB releases framebuffer id with DRM_IOCTL_MODE_RMFB, which also turns off every plane and CRTC still showing it. On an unplugged device (ENODEV) it succeeds.

func (*Device) Resources

func (d *Device) Resources() (Resources, error)

Resources reads the card's KMS objects with DRM_IOCTL_MODE_GETRESOURCES, asking again whenever the counts change between the sizing call and the filling call, as on a hotplug.

func (*Device) SetClientCap

func (d *Device) SetClientCap(capability, value uint64) error

SetClientCap sets a client capability, one of the ClientCap* constants, to value with DRM_IOCTL_SET_CLIENT_CAP.

func (*Device) SetMaster

func (d *Device) SetMaster() error

SetMaster makes this open file the card's DRM master with DRM_IOCTL_SET_MASTER, the right to change modes and commit, for a process that opens the card without logind. The first opener of a card nobody masters is master already. It fails with EBUSY while another file is master, and with EACCES unless the process has CAP_SYS_ADMIN or this file was master before.

func (*Device) Signal

func (d *Device) Signal(s Syncobj, point uint64) error

Signal signals timeline point point of s with DRM_IOCTL_SYNCOBJ_TIMELINE_SIGNAL.

type Dumb

type Dumb struct {
	Handle, Pitch uint32
	Pix           []byte
}

Dumb is a dumb buffer: its GEM handle, its pitch in bytes and its pixels, mapped read-write into this process.

type Encoder

type Encoder struct {
	ID, Type, CRTC, PossibleCRTCs, PossibleClones uint32
}

Encoder is a KMS encoder, laid out as struct drm_mode_get_encoder: its ID and type, the CRTC it drives (0 for none) and bitmasks of the CRTC indices it can drive and the encoders it can clone.

type FB

type FB struct {
	Width, Height    uint32
	Format           fourcc.Format
	Handles, Pitches [4]uint32
	Offsets          [4]uint32
	Modifier         fourcc.Modifier
	WithModifier     bool
}

FB describes a framebuffer for AddFB2: its size in pixels, its format and, per plane, the GEM handle, the pitch and the offset in bytes. Modifier applies to every plane with a handle, and only when WithModifier is set.

type FlipEvent

type FlipEvent struct {
	UserData uint64
	Sec      uint32
	Usec     uint32
	Sequence uint32
}

FlipEvent is a DRM_EVENT_FLIP_COMPLETE event: the commit's user data, the flip's CLOCK_MONOTONIC time in seconds and microseconds, and the CRTC's vblank sequence.

type Mode

type Mode struct {
	Clock                                         uint32
	HDisplay, HSyncStart, HSyncEnd, HTotal, HSkew uint16
	VDisplay, VSyncStart, VSyncEnd, VTotal, VScan uint16
	VRefresh, Flags, Type                         uint32
	Name                                          [32]byte
}

Mode is a display mode, laid out as the kernel's struct drm_mode_modeinfo: the pixel clock in kHz, the horizontal and vertical timings in pixels and lines, the nominal refresh in Hz, the DRM_MODE_FLAG_* and DRM_MODE_TYPE_* bits and the mode's name.

func ParseMode

func ParseMode(data []byte) (Mode, error)

ParseMode reads a struct drm_mode_modeinfo in native byte order, the payload of a MODE_ID property blob, as Bytes writes it. It fails when data is not exactly one mode long.

func (Mode) Bytes

func (m Mode) Bytes() []byte

Bytes is m as a struct drm_mode_modeinfo in native byte order, the payload of a MODE_ID property blob.

func (Mode) Preferred

func (m Mode) Preferred() bool

Preferred reports whether the sink marks m as its preferred mode.

func (Mode) RefreshMHz

func (m Mode) RefreshMHz() int32

RefreshMHz is the mode's refresh rate in mHz, computed from the pixel clock and the totals rather than the rounded VRefresh, and corrected for interlace, double scan and VScan. It is 0 when a total is 0.

type Plane

type Plane struct {
	ID, CRTC, FB, PossibleCRTCs uint32
	Formats                     []fourcc.Format
}

Plane is a KMS plane: its ID, the CRTC and framebuffer it shows now (0 for none), a bitmask of the CRTC indices it can be used with and the formats it scans out.

type Property

type Property struct {
	ID    uint32
	Value uint64
}

Property is a KMS object's property: its ID and current value.

type PropertyInfo

type PropertyInfo struct {
	Name  string
	Enums map[string]uint64
}

PropertyInfo is a property's name and, for an enum or bitmask property, the value of each enumerator by name.

type Request

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

Request is an atomic KMS commit being built: property values to set on KMS objects. The zero value is empty and ready. Reusing a Request across commits with Reset keeps its buffers.

func (*Request) Add

func (r *Request) Add(object, property uint32, value uint64)

Add sets property on KMS object to value.

func (*Request) Each

func (r *Request) Each(f func(object, property uint32, value uint64))

Each calls f for every value in r, in the order they were added until the next Commit, which sorts them by object.

func (*Request) Reset

func (r *Request) Reset()

Reset empties r and keeps its buffers.

type Resources

type Resources struct {
	CRTCs, Connectors, Encoders []uint32
	MinSize, MaxSize            [2]uint32
}

Resources are a card's KMS objects, as DRM_IOCTL_MODE_GETRESOURCES reports them: CRTC, connector and encoder IDs, and the smallest and largest framebuffer, each as width and height in pixels.

type Syncobj

type Syncobj uint32

Syncobj is a DRM sync object handle on its Device.

type Vblank

type Vblank struct {
	Sequence uint64
	Time     time.Duration
	Active   bool
}

Vblank is a CRTC's most recent vertical blank: its sequence number, counting up from some earlier vblank, and when its first pixel went out, on CLOCK_MONOTONIC. Active is whether the CRTC drives a display.

Jump to

Keyboard shortcuts

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