Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions drivers/gpu/drm/apple/apple_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1992,8 +1992,11 @@ static int apple_probe_per_dcp(struct device *dev,
return ret;

drm_crtc_helper_add(&crtc->base, &apple_crtc_helper_funcs);
/* T8132 has no qualified CTM transaction. */
if (!iomfb_is_m4(dcp_data)) {
/* The M4 panel takes a colour matrix and no gamma table. */
if (iomfb_is_m4(dcp_data)) {
if (iomfb_m4_has_ctm(dcp_data))
drm_crtc_enable_color_mgmt(&crtc->base, 0, true, 0);
} else {
unsigned int gamma_size = dcp_gamma_lut_size(dcp);

drm_crtc_enable_color_mgmt(&crtc->base, 0, true, gamma_size);
Expand Down
3 changes: 2 additions & 1 deletion drivers/gpu/drm/apple/dcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2576,7 +2576,8 @@ int dcp_crtc_atomic_check(struct drm_crtc *crtc, struct drm_atomic_commit *commi
crtc_state = drm_atomic_get_new_crtc_state(commit, crtc);
if (!crtc_state)
return 0;
if (crtc_state->vrr_enabled || crtc_state->ctm ||
if (crtc_state->vrr_enabled ||
(crtc_state->ctm && !iomfb_m4_has_ctm(dcp)) ||
crtc_state->degamma_lut || crtc_state->gamma_lut)
return -EINVAL;
if (!crtc_state->enable)
Expand Down
3 changes: 3 additions & 0 deletions drivers/gpu/drm/apple/iomfb.c
Original file line number Diff line number Diff line change
Expand Up @@ -5891,6 +5891,9 @@ void dcp_flush(struct drm_crtc *crtc, struct drm_atomic_commit *commit)
if (!new || !new->active)
return;
ret = iomfb_m4_error(dcp);
/* The colour matrix goes with this commit's frame, else the one shown. */
if (!ret && new->color_mgmt_changed && iomfb_m4_has_ctm(dcp))
ret = iomfb_m4_set_ctm(dcp, new->ctm ? new->ctm->data : NULL, !plane);
/* A CRTC-only commit publishes no new framebuffer. */
if (!ret && plane) {
/* A notch-free mode is scanned out below the notch rows. */
Expand Down
86 changes: 86 additions & 0 deletions drivers/gpu/drm/apple/iomfb_m4.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,13 @@ struct iomfb_m4 {
struct drm_framebuffer *uncertain_fb;
struct dcp_m4_frame active_frame;
u64 flips, blanks, brightness_swaps;
/*
* The internal panel's colour matrix as the firmware takes it, whether
* the CRTC ever asked for one (until then the firmware keeps its own),
* and whether the next frame sends it
*/
u64 ctm[9];
bool ctm_set, ctm_pending;
struct delayed_work idle_cache;
/*
* Framebuffer references a window let go of, put
Expand Down Expand Up @@ -3737,6 +3744,78 @@ static int iomfb_m4_swap(struct iomfb_m4 *dcp, const struct dcp_m4_frame *frame)
return ret;
}

/*
* Send the pending colour matrix, before the swap that is to show it: set_matrix
* (A423) at location 9, as iomfb_v26_6.c does. A refused matrix leaves the
* previous one in place and the frame goes out all the same; only a transport
* failure, which has failed the session, is returned.
*/
static int iomfb_m4_send_ctm(struct iomfb_m4 *dcp)
{
struct iomfb_set_matrix_req req = { .location = 9 };
struct iomfb_set_matrix_resp resp = {};
int ret;

lockdep_assert_held(&dcp->lock);
if (!dcp->ctm_pending)
return 0;
memcpy(req.matrix, dcp->ctm, sizeof(req.matrix));
ret = dcp_m4_runtime_call(dcp->runtime, 423, false, &req, sizeof(req),
&resp, sizeof(resp));
if (ret)
return ret;
dcp->ctm_pending = false;
if (resp.ret)
dev_warn_ratelimited(dcp->dev, "colour matrix not applied (status %u)\n",
resp.ret);
return 0;
}

bool iomfb_m4_has_ctm(struct apple_dcp *owner)
{
return owner->v26_6 && !owner->v26_6->external;
}

/*
* The CRTC's colour matrix as of a commit (NULL: none), for the commit's own
* frame or, with @present, for the frame on screen presented again. Nothing is
* sent until the CRTC first has a matrix, nor for an unchanged one.
*/
int iomfb_m4_set_ctm(struct apple_dcp *owner, const struct drm_color_ctm *ctm, bool present)
{
struct iomfb_m4 *dcp = owner->v26_6;
u64 fw[9];
int ret = 0;

if (!dcp || dcp->external || !dcp->runtime)
return 0;
dcp_ctm_to_fw(fw, ctm);
mutex_lock(&dcp->lock);
if (!ctm && !dcp->ctm_set)
goto out;
if (!dcp->ctm_set || memcmp(fw, dcp->ctm, sizeof(fw))) {
memcpy(dcp->ctm, fw, sizeof(fw));
dcp->ctm_set = true;
dcp->ctm_pending = true;
}
/* Blanked or powered down: the frame that powers it up sends it. */
if (!present || !dcp->ctm_pending || !dcp->active_frame.dva || dcp->display_off ||
dcp->gated || dcp->powered_off)
goto out;
ret = dcp_m4_runtime_live(dcp->runtime);
if (!ret)
ret = iomfb_m4_send_ctm(dcp);
if (!ret)
ret = iomfb_m4_swap(dcp, &dcp->active_frame);
if (ret)
dcp_m4_failed(dcp, ret);
else
iomfb_m4_idle_cache_kick(dcp);
out:
mutex_unlock(&dcp->lock);
return ret;
}

/* As iomfb_m4_present(), @dst_y panel rows down: a notch-free frame. */
int iomfb_m4_present_at(struct apple_dcp *owner, struct drm_framebuffer *fb,
dma_addr_t dva, size_t mapped, u32 dst_y)
Expand Down Expand Up @@ -3778,6 +3857,10 @@ int iomfb_m4_present_at(struct apple_dcp *owner, struct drm_framebuffer *fb,
dcp->display_on_us_max);
}
}
if (ret)
goto out;
/* A new colour matrix goes out before the frame it is to be seen with. */
ret = iomfb_m4_send_ctm(dcp);
if (ret)
goto out;
/* Keep the source before the first work descriptor can become visible. */
Expand Down Expand Up @@ -3890,6 +3973,9 @@ static int dcp_m4_set_power_state(struct iomfb_m4 *dcp, bool on)
ret = -EIO;
dcp_m4_failed(dcp, ret);
}
/* The firmware may lose the colour matrix with the display off. */
if (!ret && !on && dcp->ctm_set)
dcp->ctm_pending = true;
/* A display powered back up starts outside the idle cache. */
if (!ret && on) {
dcp->runtime->idle_state = 0;
Expand Down
10 changes: 10 additions & 0 deletions drivers/gpu/drm/apple/iomfb_m4.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
struct apple_dcp;
struct device;
struct dentry;
struct drm_color_ctm;
struct drm_connector;
struct drm_edid;
struct drm_display_mode;
Expand Down Expand Up @@ -97,6 +98,9 @@ int iomfb_m4_present(struct apple_dcp *dcp, struct drm_framebuffer *fb,
int iomfb_m4_present_at(struct apple_dcp *dcp, struct drm_framebuffer *fb,
dma_addr_t dva, size_t mapped, u32 dst_y);
int iomfb_m4_blank(struct apple_dcp *dcp);
/* The internal panel's CRTC colour matrix (DRM CTM; NULL: none). */
bool iomfb_m4_has_ctm(struct apple_dcp *dcp);
int iomfb_m4_set_ctm(struct apple_dcp *dcp, const struct drm_color_ctm *ctm, bool present);
int iomfb_m4_suspend(struct apple_dcp *dcp);
int iomfb_m4_resume(struct apple_dcp *dcp);
void iomfb_m4_configure_backlight(struct apple_dcp *dcp);
Expand Down Expand Up @@ -201,6 +205,12 @@ static inline int iomfb_m4_present_at(struct apple_dcp *dcp, struct drm_framebuf
return -ENODEV;
}
static inline int iomfb_m4_blank(struct apple_dcp *dcp) { return -ENODEV; }
static inline bool iomfb_m4_has_ctm(struct apple_dcp *dcp) { return false; }
static inline int iomfb_m4_set_ctm(struct apple_dcp *dcp, const struct drm_color_ctm *ctm,
bool present)
{
return -ENODEV;
}
static inline int iomfb_m4_suspend(struct apple_dcp *dcp) { return -ENODEV; }
static inline int iomfb_m4_resume(struct apple_dcp *dcp) { return -ENODEV; }
static inline void iomfb_m4_configure_backlight(struct apple_dcp *dcp) { }
Expand Down
10 changes: 10 additions & 0 deletions tools/testing/selftests/drivers/gpu/apple-dcp/README
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,16 @@ changed value, a missing or duplicated ID 2, a second preferred element and
more elements than the profile allows. This does not show what the firmware
reports on hardware.

The m4-panel-ctm case runs the actual colour-matrix, present and blank
functions with a mock set_matrix transport. Nothing is sent until the CRTC
first has a matrix, and an unchanged one is not sent again. A matrix goes out
as set_matrix (A423, location 9, two's complement Q32.32) before the swap of
its commit's frame, or before the frame on screen presented again for a
commit without one; while blanked it waits for the frame that powers the
display up. A refused matrix leaves frames going; a failed transport fails the
session before any swap. Whether the firmware applies the matrix is a hardware
question.

run-native-m4-kms.py defaults to dry run; --compile-only needs libdrm development
headers and never opens DRM. Explicit --execute requires root, an exact fresh
source/Image/boot identity, the common appledrm module, a stopped display
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2130,6 +2130,7 @@ def vrr(root):
struct drm_crtc_state *c)
{ (void)s; (void)c; assert(d->fw_compat == DCP_FIRMWARE_V_27_0); peer_checks++; return d->peer_check; }
static int iomfb_m4_error(struct apple_dcp *d) { (void)d; assert(false); return -ENODEV; }
static bool iomfb_m4_has_ctm(struct apple_dcp *d) { (void)d; assert(false); return false; }
static int iomfb_m4_get_mode(struct apple_dcp *d,struct drm_display_mode *m)
{ (void)d; (void)m; assert(false); return -ENODEV; }
static unsigned drm_plane_mask(void *p) { (void)p; assert(false); return 0; }
Expand Down
Loading
Loading