MacLinuxGPUHost init and drm-selftest.py --init called InitDevice
without placing the host window (selector 54), so compute start failed
with gart status -19. Query the aperture size, reserve it aligned, set
the base, then probe, as the HSA runtime does.
MacLinuxGPUHost display-agent --dry-run [--once] [--interval ms] [--init]
follows the GPU's connected monitors through an observer client. It polls
the cached connector state (selector 84 STATUS) and, when the hotplug
epoch moves, probes, reads each connected monitor's mode list (MODES)
and EDID (sysfs), and prints the CGVirtualDisplay it would create, then
the add, update and remove changes against what it had. It creates no
display; without --dry-run it refuses.
The plan takes the identity and colour from the EDID: the monitor name
(else PNP ID and product), the PNP ID word as vendor, the product, the
serial (or a stable hash of the serial string), the CIE primaries and
white point. It takes the modes from the driver's list for the link:
progressive only, duplicates dropped, preferred first, and the largest
mode as max pixels. The size comes from the driver's display_info (else
the EDID's). hiDPI is 0. A monitor with no valid EDID or no progressive
mode is reported and skipped.
The model (report/modes/EDID decoding, the plan, the agent's changes)
moves to host/DisplayAgent.swift, Foundation only, which the Xcode
target now builds; test-display-agent compiles it with a test of its
own. docs/macos-displays.md records what of the frame path exists.
dext_dma_import() takes a memory descriptor a client passed (a display
agent's IOSurface pages, as a structure-input descriptor), retains it and
prepares it for DMA with an IODMACommand on the bound device, limited to
the device's DMA width. Every segment must be whole 16 KiB pages below
that width and together exactly the requested length; otherwise the
mapping is completed again and refused. The mapping is recorded in the
same table as the coherent mappings, under an import id, so the existing
rules hold for it: dext_dma_release_import() completes it, or under the
shutdown hold only retires it until the endpoint reset; a quarantine
retains it; fini refuses while it lives; the shutdown hold counts its
bytes. Coherent-allocation lookups (descriptor copies, range
descriptors, frees by CPU address) never match an import.
Table entries now hold an IOMemoryDescriptor, the type IODMACommand
prepares. The DriverKit mocks prepare several segments when asked, and
test-iokit-dma's "import" scenario covers the lifetime, release under
the shutdown hold, refusals (partial pages, no room, PrepareForDMA
failure, a misaligned run, an IOVA beyond the DMA width) and quarantine
retention.
rt/surface.h: memory of another process that the platform mapped for the
device (a display agent's IOSurface, mapped by the dext's IODMACommand),
given as DMA segments, is imported the way Linux imports any foreign
buffer: an exporter whose sg_table carries those DMA addresses,
amdgpu_gem_prime_import() (an SG BO), pinned in GTT and bound in the
GART. rt_surface_copy() copies dirty rectangles from it into an amdgpu
VRAM buffer with the SDMA buffer functions on the TTM entity: one copy
packet per contiguous run (whole rows with equal pitches are one range),
up to 1024 packets per job, the last fence added to both buffers and
waited for with a bound. The CPU touches no pixel and no other copy
mechanism exists.
The provider's release runs exactly once, when the dma-buf is released:
after the BO is destroyed, which TTM delays until its fences signalled.
A failed import never runs it.
The DART layer gains imported mappings (linuxu_dart_import): charged to
the budget and live for containment while imported.
test-surface-import runs it on the CS fixture device, whose software
SDMA engine reads system memory through the GART table upstream filled
and faults on anything the DART does not map: a surface in three
separately allocated segments, a whole frame with differing pitches (360
row copies, one job), damage rectangles with clipping, 1100 rectangles
(two jobs), a band with equal pitches (one packet), refused imports and
destinations, and the release after the BO is gone.
status prints the cached connector state and the hotplug epoch without
detecting anything; modes <connector> lists that connector's probed
modes with refresh, pixel clock, the preferred mode and physical size.
Brings in feature/ipad-next (power and robust). The CS fixture keeps both
sides: the DART fault model, narrow BAR, held SDMA, TTM eviction checks and
self-test v2 counters from main, and the R9700 configuration, driver-stream
modeling and BAR memory for the loopback from the Vulkan work.
cs_fixture_bar_memory now maps only the CPU-visible part of VRAM, so a
narrowed BAR is honored. The README keeps main's sleep limitation and notes
that Vulkan has no presentation yet.
--display sets MacLinuxGPUDisplay=true in every MacLinuxGPU personality
of the built dext's Info.plist before its final signature: in the local
profile path the dext is signed afterwards as before; after Xcode's
automatic signing the dext is signed again with its own identity,
entitlements and flags, then the app. The source Info.plist is not
changed. Without --display the built personality is checked to carry no
display key, so an install without the flag is compute-only.
read-sysfs.py read a file until its reported length; a bin attribute of
size 0, such as a DRM connector's edid, reports none, so it stopped after
the first chunk. It now ends such a read at a short chunk. The usage text
shows the connector directories.
read-driver-log.py --display prints only the lines of display bring-up
and the display test: the display opt-in, DMCUB/DMUB, Display Core and
its clock manager, SMU, HPD, EDID, link training, commits and their
waits, connectors and the display test's own lines.
display-test.py drives selector 84 through an observer client:
probe [--edid] every connector with status, mode count, preferred
mode and EDID size; --edid reads each connected
EDID from sysfs (drm/cardN/cardN-<conn>/edid) and
decodes vendor, product, serial, name, size and
preferred timing
show [--connector NAME] [--pattern bars|white|gradient] [--seconds N]
the pattern on every connected output, or one;
with --seconds it is turned off afterwards, also on
Ctrl-C
off the recorded configuration restored
--init brings the GPU up through a session client held for the run (a
show then defaults to 30 seconds, since the session ends with the
script). Errors name the failing step's errno; nothing else is tried.
test-display-test runs it against a fake selector.
MLG_SELECTOR_DISPLAY (84, after DrmSelfTest 82 and PowerControl 83 on
feature/power; 96-103 stay the Linux-file selectors) runs the display
test client (rt/display.h) for observer clients, admitted like the other
observer reads, one op at a time (Busy otherwise):
scalar in [0] op: probe, show or off [1] pattern (show only)
[2] MLG_DISPLAY_CONFIRM ("DISP")
struct in show only, optional connector name; none means every
connected output
struct out struct rt_display_report
scalar out [0] 0 or the op's negative Linux errno
The observer policy accepts only that shape. Each op is logged with its
probe, commit and restore status, the connected and lit outputs, the
framebuffer and the fill and commit times.
close_session turns a showing pattern off right after observer
admission drains and before anything else is torn down, so the
configuration it replaced is committed again while the driver still
runs; a quarantined session keeps the client with every other upstream
owner. test-session-shutdown covers both orders and the selector policy.
test-dm-offline now continues past dm_hw_init the way amdgpu_pci_probe
does: drm_dev_register(), with the PCI function as the DRM device's
parent and a client file opened like amdgpu_driver_open_kms opens one
(its VM with CPU page-table updates, a scheduler no job reaches, the
real amdgpu_driver_postclose_kms), so dumb buffers and framebuffers are
amdgpu's own.
Two connectors get a sink the way Linux emulates a monitor (forced on,
a synthetic EDID through drm_edid_override_set, as video=<conn>:e and
debugfs edid_override do): HDMI-A-1 with a CTA-861 HDMI block and DP-2
with a base block only; DP-1 and DP-3 stay empty. The test then checks:
- connector sysfs as Linux shows it under drm/card0: status unknown
before probing, connected/disconnected after, enabled, dpms, the mode
list and the EDID bytes;
- probe: status, mode count, EDID size and the 1920x1080@60 preferred
mode per connector;
- refusals: an unknown pattern (-EINVAL), an output with no sink and a
connector that does not exist (-ENOENT), each leaving nothing behind;
- show on one connector, then on the other, then on every connected
output (each on its own CRTC), with the pattern bytes in VRAM, an OTG
programmed with 2200x1125 totals and a HUBP scanning out the
framebuffer address;
- off: the recorded configuration restored (enabled=disabled, the OTG's
master enable cleared), and the session-close stop;
- drm_dev_unregister() removing the connector and glue directories.
The fixture runs no DMCUB firmware, so DMUB and power-gate waits time
out and a run takes about three minutes.
llama.cpp is the first application of the Vulkan path. third_party/llama.cpp
pins b11379 as an optional, unpatched upstream (sparse, update = none);
scripts/bootstrap.sh --llama-only fetches it and verify-upstream.py checks
it once checked out.
scripts/build-llama-vulkan.sh (make llama-vulkan) builds it with
GGML_VULKAN against the Vulkan loader (Homebrew's or the LunarG SDK's),
Metal, BLAS and libcurl off, into build/llama.cpp/bin: llama-bench,
llama-completion and test-backend-ops. Its shaders need shaderc's glslc.
scripts/llama-radv.sh runs any program with the loader pointed at the RADV
ICD alone, so a MoltenVK installation is not used.
test-llama-offline brings the CS fixture device up inside llama.cpp's own
test-backend-ops (vulkan/tests/fixture_preload.c, inserted through
MLG_PRELOAD) so its Vulkan backend runs on RADV on the software GPU:
llama.cpp lists the R9700, and in performance mode ADD and the Q4_0/Q4_K
matrix multiplications of a feed-forward layer (matrix-vector and
matrix-matrix pipelines) are compiled by ACO, allocated, submitted and
fenced. It skips unless RADV and llama.cpp are built.
scripts/build-radv.sh (make radv) builds RADV from third_party/mesa on
libdrm-mlg: Meson with the ACO compiler and no LLVM, no window-system
platform (headless WSI), no GL, video, zstd or SPIRV-Tools, so the driver
links only the system and libdrm-mlg. It installs a relocatable ICD into
build/radv/install (libvulkan_radeon.dylib, libdrm_mlg.dylib,
libmlg_drm.dylib, share/vulkan/icd.d/radeon_icd.json with a relative
library path) and fails if any symbol other than the weak layer
entrypoints is left unresolved. Mesa's Python generators get a virtualenv
when python3 lacks mako, PyYAML or packaging.
test-radv-offline (vulkan/tests/test_radv_offline.c) loads the ICD as the
loader does and runs it on the CS fixture device through libdrm-mlg and
the loopback transport, against unmodified upstream DRM/amdgpu: instance
and enumeration ("AMD Radeon AI Pro R9700 (RADV GFX1201)", Vulkan 1.4, PCI
bus info), device creation, host-visible memory, an empty submit with a
fence, vkCmdFillBuffer and vkCmdUpdateBuffer executed by the software GPU
and checked through the mapping, a compute pipeline compiled by ACO, and a
dispatch submitted with a timeline semaphore and a fence (the software GPU
runs no shaders, so its result is not checked). It skips when RADV has not
been built.
third_party/mesa is Mesa at mesa-26.2.4, the latest stable release,
declared in patches/manifest.json as an optional upstream: a shallow,
partial, sparse submodule of what a RADV-only Meson build reads (about
60 MB), marked update = none so a recursive clone does not fetch it. Only
the Vulkan build needs it; scripts/bootstrap.sh --with-mesa fetches it
with the rest, --mesa-only alone, and once checked out it is kept at the
pin and patched like the Linux tree.
The patch set, 88 lines added and 9 removed in 8 files:
- radv-macos-build.patch: find libdrm through pkg-config on Darwin when
RADV is built, select addrlib's portable type definitions instead of
the Apple kernel driver's private header, and link RADV with
-undefined dynamic_lookup as KosmicKrisp does.
- drm-file-ops.patch: util/os_drm.h issues requests through drmIoctl and
wraps open, stat, mmap and munmap of DRM nodes and files in libdrm's
drmFile* functions when libdrm defines LIBDRM_FILE_OPS; RADV's six call
sites use the wrappers. Nothing changes for a kernel libdrm.
bootstrap.sh sets up any manifest upstream the same way now (pin fetched
by SHA, sparse before the first checkout, declared patches applied).
verify-upstream.py checks Mesa's pin, sparse set, patches and working tree
once it is checked out, and takes --only linux|mesa; lib-dext verifies the
Linux tree alone (make verify-linux), so local Mesa work cannot block a
driver build, while make verify-source checks every tree.
Mesa's amdgpu drivers reach the kernel through libdrm's core API, through
libdrm_amdgpu (devices, buffers, GPU virtual address ranges) and through a
few system calls on the DRM descriptors. libmlg_drm/libdrm provides the
part of xf86drm.h, amdgpu.h and libsync.h they use, over libmlg_drm, with
libdrm's names, types and return conventions, so RADV's stock amdgpu
winsys and Mesa's native ac_linux_drm path build and run unchanged.
The driver's files live in the dext's per-client Linux process. Each one
the library hands out (an opened render node, and every syncobj,
sync_file and dma-buf descriptor a request returns) is represented by one
end of a socket pair, the library keeping the other end: close, dup,
fcntl and fork work on it as on any descriptor, and when the last copy is
closed a watcher thread sees end-of-file and closes the driver's file, the
lifetime a kernel file has. Requests carrying descriptors are translated
both ways, with O_CLOEXEC in Linux's value. drmFileOpen, drmFileStat,
drmFileMmap and drmFileMunmap, declared under LIBDRM_FILE_OPS, stand in
for the system calls that cannot reach the driver. sync_wait and
sync_merge work through temporary syncobjs of an open render node.
The amdgpu part follows libdrm_amdgpu (MIT), from which its VA manager
and buffer handling are derived: device deduplication, the PRT half-range
reservation, dma-buf import by GEM_OP rather than lseek, no userptr.
LIBDRM_MLG_DEBUG=1 reports refused requests and descriptor lifetimes.
make libdrm-mlg installs build/libdrm-mlg with the uapi headers as the
kernel installs them and libdrm.pc and libdrm_amdgpu.pc for Meson.
test-libdrm-mlg runs it end to end against the CS fixture device. The
Makefile's depfile search now skips the Meson and CMake trees the Vulkan
builds will put under build/.
The KFD test fixture gained MES failure modes on both branches. Keep
both: power's one-shot removal failures (mes_fail_removes) and robust's
hung, dead and slow MES queues, with arrays sized FIXTURE_MES_SLOTS.
REMOVE_QUEUE honours the one-shot failures first. The GPU reset request
still trips the test unless a MES call failed, and is logged as recovery
being off.
The self-test (selector 82, drm-selftest.py) copied VRAM into GTT only
through the client's own GPUVM, never through the path an eviction takes.
Two steps now move its VRAM buffer the way a client's submission moves
it: AMDGPU_GEM_OP SET_PLACEMENT, then an SDMA copy of the buffer whose
AMDGPU_CS validates it there. Into GTT, TTM's move goes through a GART
transfer window as an eviction's does (SDMA uploads the window PTEs,
flushes VMID 0, copies); the copy made afterwards must still hold the
buffer's known contents. The move back runs the source window. Each wait
is bounded: a move that never completes fails the step with -ETIME and
parks the test process as before.
The result is version 2 (240 bytes): the two steps, the bytes TTM moved
during each, their times and the words read back. drm-selftest.py reads
versions 1 and 2 and prints the TTM line; the dext logs the new fields.
The CS fixture's software GPU now checks every system-memory page it
touches against the live DMA mappings, as the DART would: an access
outside them is counted as a DART fault and fails like a GPU fault. Its
BAR can be narrower than VRAM (the iPad's covers 256 MiB), and its SDMA
engine can be held like the compute engine.
ttm_evict_check runs TTM moves through the unmodified upstream code with
a 64 MiB BAR over 256 MiB of VRAM: a BO beyond the BAR validated to GTT
and back, then evicted under VRAM pressure, each through
amdgpu_move_blit's GART transfer windows. It checks the contents and the
window PTEs SDMA uploaded: valid, system, snooped for cached pages,
writable, exactly the ttm_tt's DMA addresses, each inside a live mapping.
No GPU or DART fault occurs.
It then holds SDMA while a kernel BO moves: the move fails after TTM's
15 s wait with the same log lines as the iPad's failure, the BO stays in
VRAM, and the pages TTM released stay mapped until the engine catches up,
so its late copy faults nothing. CS_FIXTURE_NO_DMA_HOLD=1 runs the
negative control, in which that copy hits unmapped DMA addresses.
Once a KFD client left GPU completion uncertain, every later stop and
client release returned EBUSY before trying anything, so a client killed
after a failed queue removal always quarantined the session, even when
its session could still recover.
Record whether only KFD clients froze the device. Releasing a client and
stopping compute then close its KFD process anyway, since the close
retries the session's recovery (hung-queue reset and removal, a copy
that outlived its timeout); when every KFD client is certain again the
device thaws. Stop tries every client before giving up. The client's
queue handles go with it and its dext client owns the queue records, so
a close that keeps the client leaves no stale handle behind.
dext_kfd_close destroys retained queue records too instead of refusing,
and dext_kfd_settle retries what left a client uncertain without closing
it. The production test covers a client that dies after a failed removal,
both when the close recovers it and when it is kept until a later stop.
A client killed with an open engine left its session uncertain whenever
DESTROY_QUEUE failed: remove_queue_mes times out when a wave neither
finishes nor preempts, KFD asks for a GPU reset that recovery-off turns
into a log line, and the session kept every buffer. The dext then
quarantined the device until a replug.
Tear a dying client down as upstream recovers a hung MES user queue
(amdgpu_userq's detect_and_reset before the unmap): when DESTROY_QUEUE
fails after KFD already took the queue off its lists, MES resets the
compute queues it finds hung and removes this one again with
remove_queue_after_reset, under the device queue manager's lock as
remove_queue_mes runs. A queue KFD still lists is retried with
DESTROY_QUEUE instead, never a second DESTROY_QUEUE on a detached one.
Close tries every queue, and keeps memory only while something is still
unconfirmed.
An SDMA copy that outlives its timeout keeps its fence: the session
settles once it signals, and close waits for it once more, bounded.
rt_kfd_session_settle retries all of this without closing, and
rt_kfd_session_failure names the first step that could not confirm the
GPU let go. Each failure and recovery is logged with the queue and
doorbell.
The KFD fixture gains a MES whose queues can hang (REMOVE_QUEUE fails
until a hung-queue reset), die or answer slowly, kfd_hws_hang's reset
request as recovery-off logs it, and an SDMA engine that holds copies.
The tests kill clients mid-session with a hung queue, a slow MES, a MES
that never answers (kept, then recovered by closing again), a destroy
retried by a settle, a copy that outlives its timeout, a bounded launch
whose wave never preempts, and a client closed with a hung persistent
queue; every buffer and allocation is accounted for afterwards.
The runtime now follows the driver's device power state.
While the device is suspending, suspended or resuming the driver
refuses GPU work with kIOReturnOffline, having submitted nothing. The
IOKit transport returns that as HSA_STATUS_ERROR_RESOURCE_BUSY and
keeps the session healthy instead of faulting it. A queue whose
doorbell is refused keeps the highest value rung (its packets are in
the ring already); its service thread polls gently and rings it again
once the device takes work, so a generation in flight pauses and
continues. Allocations, transfers, queue creation and bounded launches
fail with the same retryable status.
Once a host sleep has closed the session the device's memory is gone:
queue error callbacks and the power API report HSA_STATUS_ERROR_FATAL,
which a client takes as "reload": release everything, hsa_shut_down,
hsa_init (the next initialization probes the device afresh), load
again.
mac_hsa_power.h, included by mac_hsa.h, gives clients the agent's power
state (state, generation, flags with VRAM preserved, cause, counters,
queues holding a doorbell); mac_hsa_agent_prepare_low_power, which
stops ringing this process's doorbells, waits a bounded time for the
packets already rung to finish, and asks the driver to quiesce;
mac_hsa_agent_resume, which drops the request and rings what waited;
and a bounded wait for the next power change. The iPad app calls
prepare on willResignActive and resume on didBecomeActive; neither is
needed for correctness, since the driver handles sleep itself.
The fake transport models the driver's power state for the new host
test, which covers paused and replayed doorbells (by the service and
by resume), retryable refusals, prepare and resume, waiting for a
change, and lost memory reported to a queue's error callback. A
transport test covers the IOKit status mapping. The runtime's copy of
the protocol names its state enum PowerState, which no longer collides
with the snapshot's State word.
The driver now handles DriverKit's power changes and gives clients a
power state, a way to ask for low power, and a way to wait for changes.
SetPowerState(Low), the device in a reduced power state while the
system runs, and a client's PowerControl PREPARE quiesce the compute
session through upstream KFD suspend (rt/power.h): every user queue off
MES with its work saved, VRAM untouched. RESUME by the last holder, or
SetPowerState(On), resumes it through upstream KFD resume and the saved
work continues.
SetPowerState(Off), system sleep, takes the Thunderbolt link and with
it the endpoint's state; VRAM cannot survive it on these hosts, and
upstream's only dGPU path evicts all of VRAM to system memory through
SDMA, which neither fits on the iPad nor is safe over the link. The
driver closes the compute session through its ordinary close path
before acknowledging the change; the acknowledgement waits for the close
on the default queue, with a watcher that acknowledges at a deadline so
a stuck close never stalls the sleep. On wake the state is lost if a
session was closed, and the next InitDevice probes afresh and makes it
active again. A quiesced session closes as it is, its queues already
off MES; the KFD suspend is handed back before upstream removal takes
its own, so upstream's suspend count stays balanced across sessions.
A failed quiesce or resume hands the suspend back, so MES maps the
queues again and the close removes them through MES; a GPU that cannot
prove itself idle leaves the session to the existing quarantine rather
than freeing memory it may use.
Clients see state, generation, flags (VRAM preserved among them),
cause, error and counters through QueryInfo tag "LPWR" (observers too)
and the PowerControl selector 83: QUERY, PREPARE, RESUME and an async
WAIT completing at the next generation change. While suspending,
suspended or resuming, selectors that would put work on the GPU are
refused with kIOReturnOffline, which a client retries after resume;
frees, queue destruction and cached queries stay available. A closing
client's waits end and its hold is dropped. Observers may request
transitions only with the session-release entitlement.
power_state.h holds the state machine, the snapshot, the admission
policy and the plan each event leads to, with a host test that also
checks the runtime's copy of the protocol. The session shutdown test
covers the removal hook and the observer policy for the new tag and
selector, and read-driver-log.py prints the power state.
A low-power period that keeps VRAM needs every user queue off the GPU
with its work saved, and the same queues back afterwards. Upstream
amdgpu has no suspend flavour for a discrete GPU that keeps VRAM: S3,
s2idle and BACO/BAMACO runtime PM all run amdgpu_device_prepare and
amdgpu_device_suspend, which evict all of VRAM to system memory through
TTM and SDMA. What it does offer without touching VRAM is the KFD half
of those paths, amdgpu_amdkfd_suspend(adev, true), which on a dGPU is
kgd2kfd_suspend(kfd, true): every KFD process's queues are evicted
through MES (waves saved through CWSR), eviction fences are signaled,
new processes are held off, and the queue managers stop. Its pair,
kgd2kfd_resume(kfd, true), restores the processes' buffers in place and
maps the queues back.
rt/power.h wraps exactly those two calls for the dext and reads
upstream's own state around them: the queue lists, the queue managers'
scheduling flag, and the reset mark kfd_hws_hang() leaves when MES fails
a removal. A failed MES removal is reported as -EIO even though upstream
marks the queue inactive before asking MES, so a queue the GPU may still
be running is never mistaken for a quiesced one. Upstream counts
suspends, so the module keeps its own suspend until it is resumed.
The new fixture test drives both entry points from the unmodified
kfd_device.c over the KFD session fixture: a suspend unmaps the queue
and holds new processes off, work published meanwhile waits, the resume
maps the same queue back and the work runs, a session closed while
suspended issues no MES operation and the resume that follows lets KFD
take processes again, and an injected MES removal failure is reported.
The fixture gains a process restore that replaces the eviction fence as
upstream does, MES removal failure injection, a non-fatal
kfd_hws_hang() reset request after an injected failure, and the SMI
event list kfd_init_node sets up.
The driver says how much VRAM the process holds; nothing said what holds
it. Each connection now records every VRAM and shared buffer it gets
from the driver with the return addresses of the allocating call, and
reports buffer counts and bytes, a VRAM size histogram and the callers
holding the most VRAM (frames named by dladdr where exported, otherwise
image+offset for atos).
The report is printed with every refused allocation and is available
as mac_hsa_memory_report(); MAC_HSA_VRAM_TRACE=1 also logs each buffer
as it is allocated and freed.
Adds the Linux file RPC (user client type 2) that carries DRM and KFD
ioctls with Linux numbering, libmlg_drm for clients, the in-dext command
submission self-test, and fixes the DRM_COMMAND_BASE override in the
linuxu drm.h.
The libmlg_drm end-to-end test exports a syncobj's fence as a sync_file,
imports it into another syncobj and waits on it, and takes a CS fence as
a sync_file directly, as WSI and external semaphores do; all of them are
descriptors of the client's Linux process. DRM_IOCTL_SYNCOBJ_EVENTFD
fails, as on a kernel without CONFIG_EVENTFD, which is linuxu's.
drm-selftest.py --init initializes the GPU through a session client
(InitDevice) and keeps it open for the test, for a smoke test with no
other client running.
In the KFD session test a Linux-file client opens /dev/kfd and the
render node into its own process and runs libhsakmt's first requests as
framed by the shared tables: GET_VERSION, GET_PROCESS_APERTURES_NEW (the
count, then the array written through its pointer), ACQUIRE_VM finding
the render descriptor in the same descriptor table, and an SVM request
refused before KFD. Its exit runs KFD's notifier release and closes both
files; the test's allocation balance still holds.
User-client type 2 (MLG_USER_CLIENT_LINUX_FILE) is a Linux process of
its own: LX_OPEN, LX_CLOSE, LX_IOCTL, LX_IOCTL_ASYNC, LX_RESULT, LX_MMAP,
LX_MMAP_COMMIT and LX_MUNMAP (selectors 96-103, rt/lx_abi.h) run its
system calls through lx_files on the client's own dispatch queue, so no
call waits behind another client's. Request frames arrive as structure
input or, above 4096 bytes, as a descriptor; replies go back the same
way. Waits run on workers of the process and complete through
AsyncCompletion with the reply inline when it fits. LX_MMAP memory types
resolve in CopyClientMemoryForType to the buffer's page runs or to BAR
sub-ranges (CPU-visible VRAM, doorbells). Ping, RuntimeBuild, QueryInfo
and InitDevice hop to the owner's queue as observers' calls do; nothing
else of the MacAMDGPU ABI is offered to this type, and types 0 and 1
are unchanged.
The client joins the session at its first call, as a session client
does. Its calls are admitted only while the upstream driver runs; a
session close or quarantine closes the admission, waits for calls in
flight, and makes every client process exit (waits return, files close
through upstream postclose) before anything is removed. A client's Stop
does the same for its own process on its queue, then leaves the session
on the owner's queue.
Observer selector 82 (DrmSelfTest, confirmed with "CSST") runs the CS
self-test and returns its result; one test at a time. A test whose GPU
work never completed keeps its process; a session close reaps it once
idle or quarantines with compute uncertain. scripts/drm-selftest.py runs
it on hardware.
The client side of the Linux-file RPC for a macOS process: mlg_open,
mlg_close, mlg_ioctl, mlg_mmap and mlg_munmap on /dev/dri/renderD128 and
/dev/kfd, mirroring the system calls, for a Mesa winsys or libdrm shim.
Requests are Linux ones: the Linux uapi headers are built through
libmlg_drm/compat with Linux ioctl encodings on any host, and
mlg_ioctl_from_bsd converts what a macOS build of the same headers
produces. Each request is described with the shared tables
(lx_describe.c), framed (lx_frame.c), and its reply copied back; waits
with a deadline go through LX_IOCTL_ASYNC and complete on a per-thread
notification port, deadlines travel as time left, mmaps go through
IOConnectMapMemory64 with the cache mode the driver reports, and errors
come back as this platform's errno (mlg_last_linux_errno keeps the
Linux one).
The default transport is the dext's Linux-file user client (type 2);
tests install their own. make libmlg_drm builds a static and a shared
library. Tests: the library alone against a recording transport, and a
RADV-like client end to end through the core into upstream DRM/amdgpu on
the CS fixture: INFO, contexts, GEM, a BO list, AMDGPU_CS, WAIT_CS,
WAIT_FENCES and SYNCOBJ_WAIT on async workers, syncobj and fence export
as descriptors of the driver process.
rt/cs_selftest.h runs what a Vulkan driver does on a render node, as a
client of the Linux-file transport inside the dext: DRM_IOCTL_VERSION,
AMDGPU_INFO, a context, syncobjs, GTT and VRAM buffers mapped with
GEM_VA and mmap, then AMDGPU_CS of a PM4 WRITE_DATA IB on the compute
ring (BO list, user fence, out syncobj) waited with AMDGPU_WAIT_CS on an
async worker and with DRM_IOCTL_SYNCOBJ_WAIT, and two SDMA submissions
built from the device's own buffer functions, the second waiting on the
first through a syncobj, copying VRAM back to GTT. Every value is
checked through the CPU mapping, then everything is undone. Rings,
alignments and the VA range come from AMDGPU_INFO. A test whose jobs
are still running at the end (a hung queue) keeps its process until
they complete (rt_cs_selftest_reap), since tearing it down would wait
for them with GPU recovery off.
The offline test brings up a fixture device the way amdgpu_device_init
does: upstream TTM, GART, write-back, seq64, IB pool, VM manager,
amdgpu_ring_init with fences, drm_sched with amdgpu_sched_ops, TTM's
buffer-function entities and a registered render node. A software GPU
executes the rings, walking the page tables upstream wrote through the
SDMA engine and running amdgpu_fence_process on fence interrupts. The
test runs the self-test twice, then once with the compute queue held,
which times out, parks and is reaped once released.
test-dm-offline runs the unmodified dm_ip_block (dm_early_init,
dm_sw_init, dm_hw_init, dm_hw_fini, dm_sw_fini) from the host library
against a device with no GPU behind it:
- a synthetic atomfirmware VBIOS (ROM header v2.2, master data table
v2.1, firmware info v3.4, DCE info v4.5, SMU info v4.0, display object
info v1.5 with three DisplayPort and one HDMI path, DDC/HPD records and
a GPIO pin LUT at the DCN 4.0.1 GPIO registers);
- a register file behind amdgpu's indirect register hooks, with only the
DMCUB-present fuse preset;
- 64 MiB of host-memory VRAM under the real amdgpu_ttm_init(), with the
GMC v12 callbacks, and the device interrupt from amdgpu_irq_init();
- the locked linux-firmware DMCUB image from the embedded firmware table.
It reaches: DMCUB image request and validation, the DCN401 DMUB service
with its framebuffer in VRAM, dc_create() on DCN 4.0.1 (BIOS parser,
resource pool, five links: four connectors plus the virtual one), DMUB
hardware init up to the auto-load wait, dc_hardware_init(), and the DRM
CRTCs, planes and connectors (DP-1..3, HDMI-A-1). It stops where silicon
is required: no DMCUB executes the loaded image, so the auto-load wait
and later DMUB commands time out, power-gate status waits time out, and
with no sink every connector stays undetected. Teardown completes.
The generator negative tests and the generated-category contracts used
hrtimer_* and drm_gem_fb_get_obj() as probe stubs; those are real code
now. The probes use symbols that are still generated with the same
return kinds (irq_domain_remove, amdgpu_ras_mgr_gen_ras_event_seqno,
amdgpu_ras_mgr_is_rma, irq_domain_create_linear, irq_create_mapping),
and the contracts test calls amdgpu_ras_mgr_is_rma() and component_add()
instead of hrtimer_active().
A client on macOS issues open, ioctl, mmap, munmap and close on the
GPU's render node or /dev/kfd; the dext runs each call in a linuxu
process of its own through the file's file_operations, as Linux runs
the system call.
rt/lx_abi.h is the wire ABI: request frames carry the ioctl argument
block and every range its pointers name as segments at the client's own
addresses, so unmodified upstream copy_{from,to}_user reaches nested
memory (CS chunks and BO lists, syncobj arrays, INFO return pointers).
lx_describe.c holds the per-ioctl tables for the DRM core, amdgpu and
KFD commands and is also the dext's admission list; lx_frame.c checks
frames, encodes them and applies replies. Absolute wait deadlines
travel as time left and are rebased on the process's clock.
lx_files.c keeps one process per client: its descriptor table, argument
pages shared and reference counted across concurrent calls, waits on
worker threads with completion callbacks, and mmaps described as page
runs or BAR ranges. GEM buffers are placed as the Linux fault path
would place them and pinned while a client maps them (lx_gem.c), since
a macOS mapping can be neither faulted nor revoked. Teardown kills the
process so waits return, joins the workers, unmaps and exits.
Tests: the framing under fuzz against a reference checker, and the core
against fixture render and KFD devices.
With Display Core, the drm_kms_helper and drm_display_helper modules and
the hrtimer service built, the 48 symbols that were generated as
"unreachable" display/vkms stubs (drm_atomic_helper_*, drm_crtc_helper_*,
drm_kms_helper_poll_*, drm_helper_hpd_irq_event, drm_dp_aux_* and
drm_dp_dpcd_*, drm_gem_fb_*, hrtimer_*) are classified "external" with the
upstream file or linuxu/src/timer.c that defines them.
drm_crtc_helper_add() and drm_privacy_screen_put() are upstream inlines in
the vendored headers and leave the list. The display-path link adds one
symbol, isxdigit() (lib/uuid.c), implemented next to the other ctype
helpers for DriverKit. No new unreachable stub was added.
Implement hrtimer_setup(), hrtimer_start_range_ns(), hrtimer_try_to_cancel(),
hrtimer_cancel(), hrtimer_active(), hrtimer_forward(),
hrtimer_cb_get_time() and __hrtimer_get_remaining() in linuxu/src/timer.c.
The existing worker thread now serves both timer_list (jiffies) and
hrtimer (nanosecond deadlines on CLOCK_MONOTONIC, CLOCK_REALTIME or
CLOCK_BOOTTIME), sleeping until the earliest of either.
Semantics follow kernel/time/hrtimer.c: the timer is dequeued before
its callback, HRTIMER_RESTART re-enqueues it at the expiry the callback
forwarded to, try_to_cancel() returns -1 while the callback runs,
hrtimer_cancel() waits for it, and a NORESTART timer is not touched after
its callback returns. drm_vblank's timer-based vblank and amdgpu_vkms use
this; the hrtimer stubs that called them unreachable are gone.
scripts/test-hrtimer.sh covers one-shot and periodic timers, forward
overrun arithmetic, cancel while running, the drm_vblank
active/try_to_cancel loop and coexistence with timer_list timers. The
timer service test now links timekeeping.c for the clocks.
Linux gives a task exclusive use of its CPU's per-CPU copy between
preempt_disable() and preempt_enable(). linuxu threads all run as CPU 0
concurrently and preemption control excludes nobody, so one shared copy
would be raced. linux/percpu.h therefore keeps per-CPU variables per
task: the first this_cpu_*() access copies the definition's initial
value into storage owned by the task (released by put_task_struct()),
which is exactly what a pinned task observes on Linux. per_cpu() names
the boot copy; no built source inspects other CPUs' copies.
linux/fpu.h provides kernel_fpu_available()/kernel_fpu_begin()/end().
In a process the FP/SIMD registers belong to the running thread and the
OS preserves them across switches, so nothing is saved; the section is
tracked per task and nesting or an unbalanced end warns as on Linux.
This is what Display Core's dc_fpu.c (DC_FP_START/END and its per-CPU
recursion depth) runs on.
scripts/test-percpu-fpu.sh checks per-thread isolation of the copies,
initial values, the boot copy and the dc_fpu depth pattern under
ASan/UBSan.
Add drivers/gpu/drm/display/ to the sparse checkout and compile the
display side of upstream amdgpu:
- mk/upstream_sources.mk gains the 498 objects of AMD_DISPLAY_FILES
(amd/display/Makefile and the Makefiles it includes, evaluated with
DRM_AMD_DC=y, DRM_AMD_DC_FP=y, DEBUG_FS=y), the drm_display_helper
module for the DRM_DISPLAY_* helpers amdgpu selects, the whole
drm_kms_helper module and the panel orientation/backlight quirk tables.
DCN 4.0.1 links the dcn10..dcn35 code it reuses, so every DCN is built.
- mk/kernel_config.mk and linux/autoconf.h enable DRM_AMD_DC, DC_FP and
the display helper configs; CEC, DP AUX chardev/CEC, DP tunnel, bridge
connector, SI DCE and secure display stay off.
- INCPATHS carries the subdir-ccflags-y include roots of the display
Makefiles in upstream order.
- CONFIG_DRM_AMD_DC_FP is declared in patches/manifest.json as a config
intervention: Kconfig drops it for clang+arm64 because of kernel FPU
rules that do not apply to userspace. scripts/verify-upstream.py checks
that each declared config intervention names a Kconfig symbol and is
set in autoconf.h.
- linux/kconfig.h provides IS_ENABLED/IS_REACHABLE as kbuild's forced
include does; autoconf.h pulls it in after the CONFIG table.
Display stays off at runtime by default; that gating follows separately.
Runs the unmodified upstream Linux amdgpu and amdkfd drivers on Apple
Silicon Macs inside a DriverKit system extension, for AMD GPUs attached
over Thunderbolt. The Linux sources come from a pinned submodule and are
compiled against linuxu, a userspace implementation of the Linux kernel
APIs they use. Includes the HSA runtime, the host installer app, the
setup and firmware fetch scripts, and the offline test suite.