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
- Variables
- func Modifiers(inFormats []byte, format fourcc.Format) ([]fourcc.Modifier, error)
- func ParseEvents(buf []byte, flip func(FlipEvent) error) error
- func SyncFileSignalTime(fd int) (time.Duration, bool, error)
- func SyncFileSignalled(fd int) (bool, error)
- type Connection
- type Connector
- type Device
- func (d *Device) AddFB2(fb FB) (uint32, error)
- func (d *Device) Blob(id uint32) ([]byte, error)
- func (d *Device) CRTCSequence(crtc uint32) (Vblank, error)
- func (d *Device) Cap(capability uint64) (uint64, error)
- func (d *Device) Close() error
- func (d *Device) CloseFB(id uint32) error
- func (d *Device) CloseHandle(handle uint32) error
- func (d *Device) Commit(r *Request, flags uint32, userData uint64) error
- func (d *Device) Connector(id uint32) (Connector, error)
- func (d *Device) CreateBlob(data []byte) (uint32, error)
- func (d *Device) CreateDumb(size image.Point) (Dumb, error)
- func (d *Device) CreateSyncobj(signaled bool) (Syncobj, error)
- func (d *Device) DestroyBlob(id uint32) error
- func (d *Device) DestroyDumb(b Dumb) error
- func (d *Device) DestroySyncobj(s Syncobj) error
- func (d *Device) DropMaster() error
- func (d *Device) Encoder(id uint32) (Encoder, error)
- func (d *Device) EventFD(s Syncobj, point uint64, eventfd int, available bool) error
- func (d *Device) ExportSyncFile(s Syncobj, point uint64) (int, error)
- func (d *Device) ExportSyncobj(s Syncobj) (int, error)
- func (d *Device) FD() int
- func (d *Device) GetFB2(id uint32) (FB, error)
- func (d *Device) ImportSyncFile(s Syncobj, point uint64, syncFile int) error
- func (d *Device) ImportSyncobj(fd int) (Syncobj, error)
- func (d *Device) Number() (uint64, error)
- func (d *Device) Path() string
- func (d *Device) Plane(id uint32) (Plane, error)
- func (d *Device) Planes() ([]uint32, error)
- func (d *Device) PrimeFDToHandle(fd int) (uint32, error)
- func (d *Device) PrimeHandleToFD(handle uint32) (int, error)
- func (d *Device) Properties(objectID, objectType uint32) (map[string]Property, error)
- func (d *Device) PropertyInfo(id uint32) (PropertyInfo, error)
- func (d *Device) Query(s Syncobj) (uint64, error)
- func (d *Device) RemoveFB(id uint32) error
- func (d *Device) Resources() (Resources, error)
- func (d *Device) SetClientCap(capability, value uint64) error
- func (d *Device) SetMaster() error
- func (d *Device) Signal(s Syncobj, point uint64) error
- type Dumb
- type Encoder
- type FB
- type FlipEvent
- type Mode
- type Plane
- type Property
- type PropertyInfo
- type Request
- type Resources
- type Syncobj
- type Vblank
Constants ¶
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.
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.
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.
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.
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.
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.
const EventFlipComplete = 0x02
EventFlipComplete is DRM_EVENT_FLIP_COMPLETE, the event type ParseEvents reports as a FlipEvent.
const FBModifiers = 1 << 1
FBModifiers is DRM_MODE_FB_MODIFIERS, the ADDFB2 flag that makes the kernel read the per-plane modifiers.
Variables ¶
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.
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 ¶
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 ¶
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 ¶
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 ¶
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.
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 ¶
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 (*Device) AddFB2 ¶
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 ¶
Blob reads property blob id, such as an EDID or IN_FORMATS, with DRM_IOCTL_MODE_GETPROPBLOB.
func (*Device) CRTCSequence ¶
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 ¶
Cap reads a device capability, one of the Cap* constants, with DRM_IOCTL_GET_CAP. An unknown capability fails with EINVAL.
func (*Device) CloseFB ¶
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 ¶
CloseHandle releases a GEM handle with DRM_IOCTL_GEM_CLOSE. On an unplugged device (ENODEV) it succeeds.
func (*Device) Commit ¶
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 ¶
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 ¶
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 ¶
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 ¶
CreateSyncobj makes a sync object with DRM_IOCTL_SYNCOBJ_CREATE, already signaled when signaled is set. Release it with DestroySyncobj.
func (*Device) DestroyBlob ¶
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 ¶
DestroyDumb unmaps b and releases it with DRM_IOCTL_MODE_DESTROY_DUMB. On an unplugged device (ENODEV) the release succeeds.
func (*Device) DestroySyncobj ¶
DestroySyncobj releases s with DRM_IOCTL_SYNCOBJ_DESTROY.
func (*Device) DropMaster ¶
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) EventFD ¶
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 ¶
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 ¶
ExportSyncobj exports s as a new sync object fd with DRM_IOCTL_SYNCOBJ_HANDLE_TO_FD; the caller owns the fd.
func (*Device) FD ¶
FD is the device's file descriptor, for polling it for events. The Device keeps owning it.
func (*Device) GetFB2 ¶
GetFB2 reads framebuffer id with DRM_IOCTL_MODE_GETFB2, whoever made it. The kernel opens a GEM handle per plane only for a DRM master or a caller with CAP_SYS_ADMIN, and leaves Handles zero otherwise; release each distinct handle with CloseHandle.
func (*Device) ImportSyncFile ¶
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 ¶
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 ¶
Number is the device number (st_rdev) of the device's node, as linux-dmabuf feedback and logind name devices.
func (*Device) Planes ¶
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 ¶
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) PrimeHandleToFD ¶
PrimeHandleToFD exports GEM handle as a dmabuf with DRM_IOCTL_PRIME_HANDLE_TO_FD, readable and writable and closed on exec. The fd is the caller's to close; the handle stays open.
func (*Device) Properties ¶
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 ¶
Query reads the last signaled point of timeline s with DRM_IOCTL_SYNCOBJ_QUERY.
func (*Device) RemoveFB ¶
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 ¶
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 ¶
SetClientCap sets a client capability, one of the ClientCap* constants, to value with DRM_IOCTL_SET_CLIENT_CAP.
func (*Device) SetMaster ¶
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.
type Dumb ¶
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 ¶
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 ¶
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 ¶
Bytes is m as a struct drm_mode_modeinfo in native byte order, the payload of a MODE_ID property blob.
func (Mode) RefreshMHz ¶
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 ¶
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 PropertyInfo ¶
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.