Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drm: apple: backlight: force backlight update after resume #252

Closed
wants to merge 181 commits into from

Conversation

kettenis
Copy link

If the DCP firmware indicates that it didn't restore the brightness, schedule an update. Wait for 1 frame duration and check if the brightness update has been taken care of by a swap that happened in the meantime.
Fixes restoring the brightness after resume when running on a dumb framebuffer where swaps may not happen for a very long time.

alyssarosenzweig and others added 30 commits November 19, 2023 15:41
Add a DRM/KMS driver for Apple system on chips using the DCP
coprocessor, namely the Apple M1. The DCP was added in Apple A14; this
driver does not apply to older iDevices.

This driver targets the DCP firmware API shipped by macOS 12.1.
Currently no incompatibilities with macOS 12.0.1 or 12.2.1 are known.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Co-developed-by: Janne Grunau <j@jannau.net>
Signed-off-by: Janne Grunau <j@jannau.net>
Signed-off-by: Janne Grunau <j@jannau.net>
Xorg startup with modesetting driver triggers this. Move vblank
signalling to dcp to avoid a circular dependency between apple_drv
and dcp.

Signed-off-by: Janne Grunau <j@jannau.net>
Frequency differs between M1 and M1 Pro/Max/Ultra.

Signed-off-by: Janne Grunau <j@jannau.net>
Signed-off-by: Janne Grunau <j@jannau.net>
Signed-off-by: Janne Grunau <j@jannau.net>
The framebuffer can be unreferenced by GEM while the display controller
is still using it for scanout resulting in IOVA faults and crashed dcp.
dcp has to hold a reference until the swap is complete.

Signed-off-by: Janne Grunau <j@jannau.net>
Signed-off-by: Janne Grunau <j@jannau.net>
Use the firmware setPowerState callback.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
fixup! WIP: drm/apple: Add DCP display driver

Signed-off-by: Janne Grunau <j@jannau.net>
The swap completes only after the async reply from DCP. Uses
drm_atomic_helper_wait_for_flip_done instead of
drm_atomic_helper_wait_for_vblanks. This should allow ius to get rid
of the scheduled fake vblanks.

Signed-off-by: Janne Grunau <j@jannau.net>
Mostly for the generic callbacks nop, true, false.

Signed-off-by: Janne Grunau <j@jannau.net>
Signed-off-by: Janne Grunau <j@jannau.net>
Avoids unexpected callbacks on nesting state errors. Encountered when
making DCP calls from a second thread for the backlight.

Signed-off-by: Janne Grunau <j@jannau.net>
Call power-on/-off handling explicitly from apple_crtc_atomic_enable /
apple_crtc_atomic_disable. This makes DPMS work.

Signed-off-by: Janne Grunau <j@jannau.net>
squash! WIP: GPU/apple: t600x work in progress

Signed-off-by: Janne Grunau <j@jannau.net>
Signed-off-by: Janne Grunau <j@jannau.net>
Signed-off-by: Janne Grunau <j@jannau.net>
Handling it with trampoline_false can result in errors due to
uninitialized data.

Signed-off-by: Janne Grunau <j@jannau.net>
If there is a mismatch in the output size this way we have at leas
consistant results.

Signed-off-by: Janne Grunau <j@jannau.net>
Used by dcp on mode changes on the Macbook Pro 14" (M1 Max).

Signed-off-by: Janne Grunau <j@jannau.net>
This seems to be incorrect but the flag seems to be related to clearing.

Allows unmapping surfaces after the swap finished.

Signed-off-by: Janne Grunau <j@jannau.net>
Use a device_link to ensure piodma has is bound to its DART.

fixup! WIP: drm/apple: Add DCP display driver

Signed-off-by: Janne Grunau <j@jannau.net>
Signed-off-by: Asahi Lina <lina@asahilina.net>
Fixes a display wakeup issue seen with Plasma/X11.

Signed-off-by: Janne Grunau <j@jannau.net>
Signed-off-by: Janne Grunau <j@jannau.net>
For external display support DCP will use more endpoints.

Signed-off-by: Janne Grunau <j@jannau.net>
Signed-off-by: Janne Grunau <j@jannau.net>
jannau and others added 24 commits November 23, 2023 11:44
Signed-off-by: Janne Grunau <j@jannau.net>
squash! drm: apple: Extract modeset crtc's atomic_flush()
Fixes: 99d7bb8 ("drm: apple: Extract modeset crtc's atomic_flush()")
Signed-off-by: Janne Grunau <j@jannau.net>
- Do not trigger an hotplug event from disconnect. DCP/iomfb notices that
  itself.
- Check HPD status before disconnecting DPTX in the crtc disable
  path.
- disconnect on suspend to allow an orderly re-connect on resume

Signed-off-by: Janne Grunau <j@jannau.net>
Avoid device wide hotplugs as DCP knowns the affected connector.

Signed-off-by: Janne Grunau <j@jannau.net>
Signed-off-by: Janne Grunau <j@jannau.net>
Only observed with dcp/dptx in linux after initialisation and reset in
m1n1. On the initial startup dcp sends two D576 (hotPlug_notify_gated)
presumendly due to state confusion due to  the multiple dptx
connections.

Signed-off-by: Janne Grunau <j@jannau.net>
Signed-off-by: Janne Grunau <j@jannau.net>
Under unknown but slightly broken conditions dcp sends timing modes
without linked color modes. Log a warning when this happens and log the
number of valid modes before emitting HPD events.

Signed-off-by: Janne Grunau <j@jannau.net>
DSC setup seems to require extra steps. dcp reports itself a bandwith
limit of 926484480:
`IOMFB removing mode: 3840 x 2160 @ 119, bw: 987033600 max: 926484480`

Signed-off-by: Janne Grunau <j@jannau.net>
DPTX setup from an initialized connection and display with sleeping and
reset dcp is unfortunately quite fragile. The display connection has to
be stopped and reestablished. Goodbye flicker free boot.
If the IOMFB endpoint is started too early dcp might provide incomplete
timing modes which prevent modesets.
On display standby a HPD is triggered should result in a fully
initialized dcp. If not a display cable unplug and plug should help.
MacOS doesn't handle this at all and just gives up.

Signed-off-by: Janne Grunau <j@jannau.net>
Signed-off-by: Janne Grunau <j@jannau.net>
Should make connect more reliable by avoiding hardcoded waits which are
either to long or too short. In the second case the display can't be
brought up since dcp fails to report any modes during start.

Signed-off-by: Janne Grunau <j@jannau.net>
DCP color mode scoring seems to prefer high bit depth color modes even
when it it would require DSC. For example 12-bit 4k 60 Hz YCbCr 4:4:4
over a 600 MHz HDMI 2.0 link.
Prefer 8-/10-bit RGB or YCbCr 4:4:4 modes if available.

Signed-off-by: Janne Grunau <j@jannau.net>
Fixes missing physical display dimensions for HDMI display on Macbook
Pros.

Signed-off-by: Janne Grunau <j@jannau.net>
Signed-off-by: Janne Grunau <j@jannau.net>
The payload is not necessarily epic_std_service_ap_call. The powerlog
service on the system endpoint passes serialized dictionaries as
payload.

Signed-off-by: Janne Grunau <j@jannau.net>
The 13.5 firmware has stopped updating the NITS property on backlight
brightness changes. Parse system log events instead which report
backlight's brightness in millinits.
Fixes the backlight device's "actual_brightness" property used by the
systemd backlight service to save and restore brightness.

Signed-off-by: Janne Grunau <j@jannau.net>
If the DCP firmware indicates that it didn't restore the
brightness, schedule an update.  Wait for 1 frame duration and
check if the brightness update has been taken care of by a swap
that happened in the meantime.
Fixes restoring the brightness after resume when running on a
dumb framebuffer where swaps may not happen for a very long time.

Signed-off-by: Mark Kettenis <kettenis@openbsd.org>
@kettenis
Copy link
Author

@jannau This implements the idea we discussed a few days ago on icb. Seems to work on OpenBSD. Not even sure this compiles on linux ;)

@jannau
Copy link
Member

jannau commented Dec 28, 2023

looks good to me, thanks

@jannau
Copy link
Member

jannau commented Mar 5, 2024

@jannau
Copy link
Member

jannau commented Apr 29, 2024

merged in asahi-wip / asahi-6.8.8-1

@jannau jannau closed this Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants