Files
mac_linuxgpu/dext/MacLinuxGPU.iig
T
geramyloveless f1557dd66c dext: sleep, device low power and client low-power requests
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.
2026-10-03 10:03:32 -07:00

45 lines
1.8 KiB
Plaintext

//
// MacLinuxGPU.iig — Driver class interface.
//
// This is the IOService subclass that matches the PCI device and
// spawns one MacLinuxGPUUserClient per open. Lifecycle only — the
// upstream KMD bringup happens on first UserClient claim (T-bringup-dext),
// not here. Ported from mac_amdgpu/MacAMDGPU.iig, renamed MacAMDGPU →
// MacLinuxGPU.
//
// NOTE: this .iig is processed by the Xcode DriverKit build-phase codegen
// (the `iig` tool) into a derived .h + .iig.cpp. A plain make/clang build
// does NOT run that codegen, so the make `make dext` path uses the
// hand-rolled MacLinuxGPU.mm (compile-clean class decl + lifecycle) and the
// .iig is the source of truth for the Xcode build (activation, T-hostapp-
// sysextd). Do not try to #include this .iig directly in a make build.
//
#ifndef MacLinuxGPU_h
#define MacLinuxGPU_h
#include <Availability.h>
#include <DriverKit/IOService.iig>
#include <DriverKit/IOInterruptDispatchSource.iig>
#include <PCIDriverKit/IOPCIDevice.iig>
class MacLinuxGPU: public IOService
{
public:
virtual void free() override;
virtual kern_return_t Start(IOService *provider) override;
virtual kern_return_t Stop(IOService *provider) override;
void FinishSession() LOCALONLY;
void FinishStop(IOService *provider) LOCALONLY;
virtual kern_return_t NewUserClient(uint32_t type,
IOUserClient **userClient) override;
virtual kern_return_t SetPowerState(uint32_t powerFlags) override;
void AckPowerState(uint32_t powerFlags) LOCALONLY;
virtual void InterruptOccurred(OSAction *action,
uint64_t count,
uint64_t time)
TYPE(IOInterruptDispatchSource::InterruptOccurred) QUEUENAME(Interrupts);
};
#endif /* MacLinuxGPU_h */