R3: KMS object model, atomic commit, vblank events and EDID (WI-455) #5
Loading…
Reference in a new issue
No description provided.
Delete branch "r3-kms"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Anima work item: WI-455
01a0e387-b132-7a82-a056-9171bf5f4df4Milestone R3: kernel mode setting. Adds the KMS object model, atomic commit with the legacy ioctls built on it, vblank counters and events through
read(2)/poll(2), EDID parsing, and a virtual display inrdrmnull.Needs illumos-ddi illumos/illumos-ddi#4 (chpoll(9E) glue, pinned here at
5c792b3229). Stacked onloose-ends-20260928(illumos-drm PR 4) and illumos-ddiloose-ends-20260928(PR 3), which are not merged yet, so the diff againstmainalso shows their commits until they are.What was built
crates/drm/src/kms/:modesholds the mode type and its conversion to and fromdrm_mode_modeinfo, with Linux's validation. It also has the VESA DMT, established-timing and CTA-861 VIC tables, CVT in integer arithmetic, and the mode list order.edidparses the base block (header repair, checksum, detailed, standard, established timings, CVT codes, the name) and CTA-861 extensions (VIC data block, HDMI VSDB, extension DTDs).formatsholds the fourcc codes, the legacyADDFBformats and theIN_FORMATSblob.propshas the standard properties with Linux's names, types and flags.objectshas one ID space for all mode objects, the driverLayout, blobs, framebuffers and theADDFB2checks.statehas the CRTC/plane/connector states, atomic updates that duplicate on first touch (dropping one is the rollback), and theKmsDrivertrait with check and commit hooks per CRTC, plane and connector.corecovers the registry, getters, probing, and framebuffer and blob lifetimes.atomicdoes property setting, the core checks and the commit.legacyhasSETCRTC,PAGE_FLIP,SETPLANE,CURSOR/CURSOR2, theDPMSproperty and gamma, all as atomic updates.eventshas vblank counters, flip and sequence events, and per-file queues; it is allocation-free on the delivery path.ioctlis the table with Linux'sdrm_ioctls[]flags.devis the kernel layer: locks, argument copies, GEM lookups,read(9E),chpoll(9E), thekmskstat and theVblankHandle.softis a software vblank onddi_periodic(9F).Shared files:
Driver::kms, which defaults toNone, so render-only drivers are unaffected.Deviceroutes the KMS table, and handles open, close, read, chpoll and detach.GET_CAP:ADDFB2_MODIFIERScomes from the driver'sModeConfig;CRTC_IN_VBLANK_EVENTandVBLANK_HIGH_CRTCare 1.Plainfor integers.rdrmnullgets one virtual connector with a synthesized EDID (1024x768 preferred; 1280x1024, 800x600, 640x480), one encoder, and one CRTC with primary and cursor planes. It also gets a software vblank at the mode's refresh, a software scanout that latches the primary framebuffer at the next vblank, and a test-onlyRDRMNULL_IOCTL_SCANOUTthat reports the framebuffer on screen and an FNV-1a checksum of its visible pixels.Tests:
crates/drm/tests/edid/: three EDIDs synthesized bygen_edid.py. The provenance is in the script: nothing is captured or copied, and the files are MPL-2.0.tools/test/drm_r3_test.c: 184 checks.tools/test/run-r3-test.sh: runs R0, R1, R3 andmodetest.Decisions
kms/and the driver side is a separate trait (KmsDriver), as decided. Everything exceptdevandsoftis plain data with host tests.KmsCoreand an event lock aroundEventCore, taken in that order; GEM locks come after the mode-setting lock. The vblank path takes only the event lock and wakes pollers after dropping it, on aPollHeadsarray that lives as long as the device. So a wakeup that races with a close finds a valid head.atomic_remove_fb). Blobs are destroyed. The clone ID is released only after the file's KMS and GEM state.PAGE_FLIPwith a flip pending getsEBUSY. Blocking commits wait for the previous flip and their own (1 s bound each).read(2)returns whole events only, and readers of one file take turns.O_NONBLOCKgivesEAGAIN.poll(2)reportsPOLLIN.VblankHandle::vblankdemands theSleepabletoken, because the event lock has no interrupt priority.SoftVblankpolls every 10 ms (theddi_periodicresolution) and reports every frame boundary with its exactgethrtimetime: 60 Hz on average, each vblank up to 10 ms late.IN_FENCE_FDandOUT_FENCE_PTRexist so their IDs are known, but no object carries them, and setting them isEINVAL. They are a follow-up after R2.EACCES).Deviations from Linux
Blobs, framebuffers and events are locked kernel memory that any card-node file may create, so they are bounded; going past a bound is
ENOMEM:MODE_ATOMICis bounded at 1024 objects and 16384 properties (EINVAL).GETCONNECTORforces a probe only for the master, as current Linux does.DIRTYFBreturnsENOSYS, as Linux does for a driver without damage tracking.Verification
Host, with illumos-ddi at
5c792b3229:cargo test -p drm -p drm-uapi: 84 tests, including EDID parsing against the three blobs, CVT against the VESA generator, extreme timings, atomic state duplication and rollback, every check errno, lifetimes, event lists and caps, and the ioctl table.-D warnings(also withpanic-drill), fmt, rustdoc-D warnings, anduapi-check(0 differences).Kernel: disposable OpenIndiana guest on hephaistos (illumos
cda5b9a49f, fresh overlay from the golden image).run-r3-test.shgivesfail=0:modetest(packagesystem/test/libdrm, gfx-drm's build of the libdrm 2.4.109 tests), four steps:-M rdrmnulllists all objects and properties and decodesIN_FORMATS.-s 25@23:1024x768sets the mode with a dumb framebuffer.-vpage-flips with vblank events at 60.00 Hz.-a -s … -P …sets the mode and plane atomically.TEST_ONLY(nothing changes), then real blocking andNONBLOCKcommits withPAGE_FLIP_EVENT, whose events are read throughpoll(2)+read(2). The scanout checksum matches the written pattern after each flip.ADDFB2withI915_FORMAT_MOD_X_TILEDgivesEINVAL.ENOMEM.kmsandgemkstats are back at idle before unload (framebuffers 0, blobs 3 device-owned, events outstanding 0).modunloadis refused while a file is open and succeeds after it closes./etcand/deviceshashes are unchanged.Logs (workspace):
logs/hephaistos/illumos-drm/20260929-r3-kms-run5.logis the final revision04a21f9with the module from8602beb;04a21f9only changes a doc comment.-run1to-run4are earlier iterations.-run1had test-side errno mistakes (libdrm setters return -errno). No panic occurred in any run.Reviewed locally against the Anima review bar: round 1 was a reject, and every finding was fixed; round 2 approved on the condition that the illumos-ddi repin lands, which is the last commit here.
Open issues and follow-ups
IN_FENCE_FD,OUT_FENCE_PTR) after R2.Atomicvblank entry point, for the first driver with a hardware vblank interrupt (R4's virtio-gpu uses the software vblank).GAMMA_LUT, …; legacy gamma works),VRR_ENABLED, writeback, rotation,zpos,TILE, damage clips.ATOMICto processes namedX*needs the process name; no committed DDI interface provides it.detachis refused after the KMS state was released (GEM objects still referenced), the device stays attached with every CRTC off.IN_FORMATSis attached even for drivers without modifiers.PAGE_FLIPon an inactive CRTC without an event is accepted.Update: detach checks before teardown
Device::detachnow evaluates every refusal condition (open files, GEM objects and mappings, KMS state) before tearing anything down, so a refused detach leaves a fully working device.rdrmnullgained a test-only HOLD ioctl that keeps a GEM object alive;run-r3-test.shholds one, checks thatmodunloadis refused, then checks that modetest still lists the display and page-flips with vblank events at about 60 Hz, then releases and unloads cleanly. Kernel run on illumos cda5b9a49f: 476 PASS, 0 FAIL.