Skip to content
Merged
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
14 changes: 8 additions & 6 deletions drivers/gpu/drm/apple/dcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -3844,19 +3844,21 @@ static void dcp_drain_for_sleep(struct apple_dcp *dcp)
* the first attempt and the policy's three retries.
*/
for (pass = 0; pass < 4; pass++) {
/*
* A crashed or stopped DCP takes no more presents, so a level
* still pending there can never be sent and is not waited for.
*/
if (READ_ONCE(dcp->crashed) || READ_ONCE(dcp->iomfb.stopped))
return;
flush_delayed_work(&dcp->iomfb.backlight_retry);
if (dcp_has_panel(dcp))
flush_work(&dcp->bl_update_wq);
if (!iomfb_queue_drain(dcp, msecs_to_jiffies(500))) {
dev_warn(dcp->dev, "display updates still pending at suspend\n");
return;
}
/*
* A crashed or stopped DCP takes no more presents, so a level
* still pending there can never be sent and is not waited for.
* Checking after the drain, which returns at once for such a
* DCP, also covers a crash during the pass.
*/
if (READ_ONCE(dcp->crashed) || READ_ONCE(dcp->iomfb.stopped))
return;
if (!dcp_backlight_active(dcp) || !dcp_backlight_pending(dcp))
return;
}
Expand Down
6 changes: 5 additions & 1 deletion drivers/gpu/drm/apple/dcp_backlight.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,12 @@ static inline int dcp_bl_request(struct dcp_backlight_state *state, u32 nits,
return -ERANGE;
state->controlled = true;
state->retries = 0;
/*
* Until a present carries a level, the panel does not show the target,
* so even a request for the reported default has to be presented.
*/
if (state->target != nits || state->core_blank != core_blank ||
state->suspended != suspended) {
state->suspended != suspended || !state->level_known) {
state->target = nits;
state->core_blank = core_blank;
state->suspended = suspended;
Expand Down
36 changes: 36 additions & 0 deletions drivers/gpu/drm/apple/dcp_backlight_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,41 @@ static void backlight_fallback_test(struct kunit *test)
KUNIT_EXPECT_EQ(test, present.nits, 262U);
}

static void backlight_fallback_same_level_test(struct kunit *test)
{
struct dcp_backlight_state state;
struct dcp_backlight_present present;

/* A userspace write of the reported default is still presented. */
KUNIT_ASSERT_EQ(test, dcp_bl_init(&state, 525, false, 0, true, 262), 0);
KUNIT_ASSERT_EQ(test, dcp_bl_request(&state, 262, false, false), 0);
KUNIT_EXPECT_TRUE(test, state.dirty);
KUNIT_ASSERT_EQ(test, dcp_bl_prepare(&state, true, &present), 0);
KUNIT_EXPECT_EQ(test, present.nits, 262U);
KUNIT_EXPECT_TRUE(test, dcp_bl_complete(&state, present.sequence, true));
KUNIT_EXPECT_TRUE(test, state.level_known);

/* Once the level is known, repeating it presents nothing. */
KUNIT_ASSERT_EQ(test, dcp_bl_request(&state, 262, false, false), 0);
KUNIT_EXPECT_FALSE(test, state.dirty);
KUNIT_EXPECT_EQ(test, dcp_bl_prepare(&state, true, &present), -EALREADY);

/* A rejected present leaves it unknown, so the same write is retried. */
KUNIT_ASSERT_EQ(test, dcp_bl_init(&state, 525, false, 0, true, 262), 0);
KUNIT_ASSERT_EQ(test, dcp_bl_request(&state, 262, false, false), 0);
KUNIT_ASSERT_EQ(test, dcp_bl_prepare(&state, true, &present), 0);
KUNIT_EXPECT_TRUE(test, dcp_bl_complete(&state, present.sequence, false));
KUNIT_EXPECT_FALSE(test, state.level_known);
state.dirty = false;
KUNIT_ASSERT_EQ(test, dcp_bl_request(&state, 262, false, false), 0);
KUNIT_EXPECT_TRUE(test, state.dirty);

/* An inherited level is known from the start. */
KUNIT_ASSERT_EQ(test, dcp_bl_init(&state, 525, true, 180, false, 0), 0);
KUNIT_ASSERT_EQ(test, dcp_bl_request(&state, 180, false, false), 0);
KUNIT_EXPECT_FALSE(test, state.dirty);
}

static void backlight_seed_known_test(struct kunit *test)
{
struct dcp_backlight_state state;
Expand Down Expand Up @@ -329,6 +364,7 @@ static struct kunit_case backlight_cases[] = {
KUNIT_CASE(backlight_inflight_dpms_test),
KUNIT_CASE(backlight_resend_test),
KUNIT_CASE(backlight_fallback_test),
KUNIT_CASE(backlight_fallback_same_level_test),
KUNIT_CASE(backlight_seed_known_test),
{}
};
Expand Down
29 changes: 21 additions & 8 deletions drivers/gpu/drm/apple/iomfb_template.c
Original file line number Diff line number Diff line change
Expand Up @@ -1398,24 +1398,29 @@ static bool dcp_present_begin(struct apple_dcp *dcp, u32 swap_id)
return true;
}

static bool dcp_present_submit(struct apple_dcp *dcp, u32 swap_id, bool accepted)
/*
* Returns 0 if the submitted present stands, -ECANCELED if the firmware
* aborted it before replying (already reported), or -EPROTO if no present
* was expecting this reply.
*/
static int dcp_present_submit(struct apple_dcp *dcp, u32 swap_id, bool accepted)
{
#if DCP_FW_VERSION(26, 0, 0) <= DCP_FW_VER
if (dcp->hw.iomfb_method_profile != DCP_IOMFB_METHODS_H17G &&
!dcp_present_submit_h17p(&dcp->present_state_h17p, swap_id, accepted)) {
dev_err(dcp->dev, "unexpected present submission %u\n", swap_id);
dcp->crashed = true;
return false;
return -EPROTO;
}
/* An abort received before this reply turns acceptance into failure. */
if (dcp->hw.iomfb_method_profile != DCP_IOMFB_METHODS_H17G &&
accepted && dcp->present_state_h17p.aborted) {
dev_warn_ratelimited(dcp->dev, "firmware aborted present %u\n",
swap_id);
return false;
return -ECANCELED;
}
#endif
return true;
return 0;
}

static void dcp_prepare_clear_swap(struct apple_dcp *dcp, void *request)
Expand Down Expand Up @@ -1461,12 +1466,16 @@ static void dcp_swap_cleared(struct apple_dcp *dcp, void *data, void *cookie)
struct dcp_swap_cookie *info = cookie;
u32 swap_id = DCP_FW_UNION(dcp->swap).swap.swap_id;
u32 status = resp ? resp->ret : ~0U;
int ret;

if (!dcp_present_submit(dcp, swap_id, !status))
ret = dcp_present_submit(dcp, swap_id, !status);
if (ret)
status = ~0U;

if (status) {
dev_err(dcp->dev, "swap_clear failed! status %u\n", status);
/* An aborted present has already been reported. */
if (ret != -ECANCELED)
dev_err(dcp->dev, "swap_clear failed! status %u\n", status);
dcp_present_failed(dcp);
if (dcp_present_retires(dcp)) {
dcp_unarm_retained_framebuffers(dcp, swap_id);
Expand Down Expand Up @@ -2004,6 +2013,7 @@ TRAMPOLINE_OUT(trampoline_create_backlight_service, dcpep_cb_create_backlight_se

static void dcp_swapped(struct apple_dcp *dcp, void *data, void *cookie)
{
int ret;
struct DCP_FW_NAME(dcp_swap_submit_resp) *resp = data;
u32 swap_id = DCP_FW_UNION(dcp->swap).swap.swap_id;
#if DCP_FW_VERSION(26, 0, 0) <= DCP_FW_VER
Expand All @@ -2012,11 +2022,14 @@ static void dcp_swapped(struct apple_dcp *dcp, void *data, void *cookie)
u32 status = resp->ret;
#endif

if (!dcp_present_submit(dcp, swap_id, !status))
ret = dcp_present_submit(dcp, swap_id, !status);
if (ret)
status = ~0U;

if (status) {
dev_err(dcp->dev, "swap failed! status %u\n", status);
/* An aborted present has already been reported. */
if (ret != -ECANCELED)
dev_err(dcp->dev, "swap failed! status %u\n", status);
dcp_present_failed(dcp);
if (dcp_present_retires(dcp)) {
dcp_unarm_retained_framebuffers(dcp, swap_id);
Expand Down