Skip to content

Power management

ebenali edited this page Dec 1, 2026 · 1 revision

Power management

Part III of the system development guide.

Suspending to RAM, hibernating and powering parts of a device down while idle all need every driver's cooperation: save state, stop the hardware, and bring it back. Parts marked (stub) are abridged.

NetBSD: pmf(9)

A driver registers suspend and resume handlers at attach and deregisters them at detach:

if (!pmf_device_register(self, mydrv_suspend, mydrv_resume))
	aprint_error_dev(self, "couldn't establish power handler\n");
...
pmf_device_deregister(self);

Handlers return bool and receive a pmf_qual_t describing the kind of suspend. The framework also calls bus and class layers: PCI saves and restores configuration space and power state around the driver's handlers; network and input classes have their own helpers (pmf_class_network_register(), pmf_class_input_register()). pmf_device_register1() adds a shutdown handler.

System suspend (pmf_system_suspend(), kern_pmf.c):

  1. refuses outright if any attached device has no pmf handlers (pmf_check_system_drivers() prints "Devices without power management support: ..."), so every driver must register, even with handlers that do nothing;
  2. syncs file systems;
  3. suspends devices leaves first (children before parents, DEVITER_F_LEAVES_FIRST). A handler that returns false is only logged ("(failed)"): the suspend is not aborted (an XXX in the code).

Linux: dev_pm_ops (stub)

  • struct dev_pm_ops on the driver: suspend/resume for sleep; freeze/thaw/poweroff/restore for hibernation; _late and _noirq phases for ordering; prepare/complete.
  • Runtime PM: devices power down while idle on their own; pm_runtime_get_sync()/pm_runtime_put_autosuspend() around use, runtime_suspend/runtime_resume callbacks. GPUs use it heavily (discrete GPUs in laptops sleep when not rendering).

aiBSD

  • Each attachment registers pmf handlers that call the Linux driver's own suspend and resume code — not its dev_pm_ops, but the driver-internal functions behind them (amdgpu_do_suspend() calls drm_suspend_ioctl() and amdgpu_device_suspend()).
  • Runtime PM calls are no-ops (<linux/pm_runtime.h>): devices stay powered. struct dev_pm_info is minimal.
  • Hibernation is not supported by NetBSD.

Further reading

pmf(9), sys/kern/kern_pmf.c, sys/sys/pmf.h; sys/external/bsd/drm2/<driver>/<driver>_pci.c; sys/external/bsd/drm2/include/linux/pm_runtime.h.

Clone this wiki locally