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
73 changes: 72 additions & 1 deletion drivers/gpu/drm/apple/apple_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -777,11 +777,82 @@ static int apple_atomic_commit(struct drm_device *dev,
return ret;
}

static int apple_atomic_check(struct drm_device *dev,
struct drm_atomic_commit *state)
{
struct drm_plane *plane;
struct drm_plane_state *old_plane_state, *new_plane_state;
struct drm_crtc *crtc;
struct drm_crtc_state *crtc_state;
int i, ret;

ret = drm_atomic_helper_check_modeset(dev, state);
if (ret)
return ret;

/*
* Until a displayed KMS swap retires the boot scanout, pull the CRTC
* and its primary plane into every commit touching that CRTC so a
* cursor- or overlay-only commit replays the intended slot-zero state
* and framebuffer reference inside the atomic transaction.
*/
for_each_oldnew_plane_in_state(state, plane, old_plane_state,
new_plane_state, i) {
struct drm_crtc *targets[2] = {
old_plane_state->crtc,
new_plane_state->crtc,
};

for (int t = 0; t < ARRAY_SIZE(targets); t++) {
struct drm_crtc *target = targets[t];

if (!target || t8132_ext_crtc(target))
continue;
if (!dcp_boot_surface_pending(to_apple_crtc(target)->dcp))
continue;
crtc_state = drm_atomic_get_crtc_state(state, target);
if (IS_ERR(crtc_state))
return PTR_ERR(crtc_state);
}
}

for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
struct drm_plane_state *plane_state;

if (t8132_ext_crtc(crtc) || !crtc->primary)
continue;
if (!crtc_state->enable || !crtc_state->active)
continue;
if (!dcp_boot_surface_pending(to_apple_crtc(crtc)->dcp))
continue;

plane_state = drm_atomic_get_plane_state(state, crtc->primary);
if (IS_ERR(plane_state))
return PTR_ERR(plane_state);
crtc_state->planes_changed = true;
}

if (dev->mode_config.normalize_zpos) {
ret = drm_atomic_normalize_zpos(dev, state);
if (ret)
return ret;
}

ret = drm_atomic_helper_check_planes(dev, state);
if (ret)
return ret;

if (state->legacy_cursor_update)
state->async_update = !drm_atomic_helper_async_check(dev, state);

return 0;
}

static const struct drm_mode_config_funcs apple_mode_config_funcs = {
.atomic_state_alloc = apple_atomic_state_alloc,
.atomic_state_clear = apple_atomic_state_clear,
.atomic_state_free = apple_atomic_state_free,
.atomic_check = drm_atomic_helper_check,
.atomic_check = apple_atomic_check,
.atomic_commit = apple_atomic_commit,
.fb_create = drm_gem_fb_create,
};
Expand Down
2 changes: 2 additions & 0 deletions drivers/gpu/drm/apple/dcp-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,8 @@ struct apple_dcp {

/* clear all surfaces on init */
bool surfaces_cleared;
bool boot_surface_pending;
bool boot_scanout_reserved;

/* enable CRC calculation */
bool crc_enabled;
Expand Down
17 changes: 14 additions & 3 deletions drivers/gpu/drm/apple/dcp-peer-frames-v27.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
* outstanding swaps, as in the existing single-pipe retirement path.
*/
struct dcp_peer_frames_v27 {
u32 first, submitted, engine[2], retired;
bool active, armed, failed, have[2], have_retired;
u32 first, submitted, engine[2], retired, shown[2];
bool active, armed, failed, have[2], have_retired, have_shown[2];
};

static inline void dcp_peer_frame_submit_v27(struct dcp_peer_frames_v27 *s, u32 id)
Expand All @@ -21,9 +21,14 @@ static inline void dcp_peer_frame_submit_v27(struct dcp_peer_frames_v27 *s, u32
s->submitted = id;
}

/*
* *shown: both engines' firmware reported the retired swap itself as
* displayed, from completions of that swap ID.
*/
static inline bool dcp_peer_frame_complete_v27(struct dcp_peer_frames_v27 *s,
unsigned int engine, u32 id,
u32 *watermark)
bool shown_now, u32 *watermark,
bool *shown)
{
u32 done;

Expand All @@ -33,13 +38,19 @@ static inline bool dcp_peer_frame_complete_v27(struct dcp_peer_frames_v27 *s,
return false;
s->engine[engine] = id;
s->have[engine] = true;
if (shown_now) {
s->shown[engine] = id;
s->have_shown[engine] = true;
}
if (!s->have[0] || !s->have[1])
return false;
done = (s32)(s->engine[0] - s->engine[1]) < 0 ? s->engine[0] : s->engine[1];
if (s->have_retired && (s32)(done - s->retired) <= 0)
return false;
s->retired = *watermark = done;
s->have_retired = true;
*shown = s->have_shown[0] && s->shown[0] == done &&
s->have_shown[1] && s->shown[1] == done;
return true;
}
#endif
10 changes: 6 additions & 4 deletions drivers/gpu/drm/apple/dcp-peer-runtime-v27.inc
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,12 @@ void dcp_peer_swap_failed_v27(struct apple_dcp *dcp)
dcp_mode_invalidate(&dcp->mode_state);
}

bool dcp_peer_swap_complete_v27(struct apple_dcp *dcp, u32 id, ktime_t now,
void (*report)(struct apple_dcp *, u32, ktime_t))
bool dcp_peer_swap_complete_v27(struct apple_dcp *dcp, u32 id, ktime_t now, bool shown,
void (*report)(struct apple_dcp *, u32, ktime_t, bool))
{
struct apple_dcp *owner;
u32 watermark;
bool both_shown;

/* Independent CRTCs must not serialize through the pair's mutex. */
if (!peer_scanout || (!READ_ONCE(dcp->peer_frames.active) &&
Expand All @@ -339,9 +340,10 @@ bool dcp_peer_swap_complete_v27(struct apple_dcp *dcp, u32 id, ktime_t now,
owner = dcp->peer_owner ?: dcp;
if (!peer_scanout || !owner->peer_frames.active)
return false;
if (dcp_peer_frame_complete_v27(&owner->peer_frames, dcp != owner, id, &watermark))
if (dcp_peer_frame_complete_v27(&owner->peer_frames, dcp != owner, id, shown,
&watermark, &both_shown))
/* Queue the combined watermark to the primary IOMFB owner. */
report(owner, watermark, now);
report(owner, watermark, now, both_shown);
return true;
}

Expand Down
14 changes: 14 additions & 0 deletions drivers/gpu/drm/apple/dcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <linux/soc/apple/dart.h>
#include <linux/soc/apple/display.h>
#include <linux/soc/apple/dp-tunnel.h>
#include <linux/soc/apple/mcc.h>
#include <linux/moduleparam.h>
#include <linux/of.h>
#include <linux/of_address.h>
Expand Down Expand Up @@ -6104,6 +6105,19 @@ static int dcp_firmware_metadata_v27(struct apple_dcp *dcp)
dcp->dfb_region_size = resource_size(&resource);
if (!dcp->dfb_region_size)
return -EINVAL;
/*
* The boot surface is on screen until a displayed swap of ours
* replaces it. Reserve its retirement record before any present.
* Without the record the display still takes over, and a cache
* controller waiting on it keeps allocation off.
*/
ret = apple_mcc_boot_scanout_reserve(dev->of_node);
if (ret == -ENOMEM)
dev_warn(dev, "no boot scanout record: system cache allocation stays off\n");
else if (ret)
return ret;
dcp->boot_scanout_reserved = !ret;
WRITE_ONCE(dcp->boot_surface_pending, true);

clocks:
/*
Expand Down
5 changes: 3 additions & 2 deletions drivers/gpu/drm/apple/dcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ int dcp_peer_stop_v27(struct apple_dcp *dcp);
struct apple_dcp *dcp_peer_scanout_v27(struct apple_dcp *dcp);
void dcp_peer_swap_armed_v27(struct apple_dcp *dcp, u32 id);
void dcp_peer_swap_failed_v27(struct apple_dcp *dcp);
bool dcp_peer_swap_complete_v27(struct apple_dcp *dcp, u32 id, ktime_t now,
void (*report)(struct apple_dcp *, u32, ktime_t));
bool dcp_peer_swap_complete_v27(struct apple_dcp *dcp, u32 id, ktime_t now, bool shown,
void (*report)(struct apple_dcp *, u32, ktime_t, bool));
int dcp_set_crc(struct drm_crtc *crtc, bool enabled);
int dcp_crtc_atomic_check(struct drm_crtc *crtc, struct drm_atomic_commit *commit);
int dcp_get_connector_type(struct platform_device *pdev);
Expand All @@ -105,6 +105,7 @@ void dcp_ext26_open_services(struct apple_dcp *dcp);
int dcp_ext26_layout_stop(struct apple_dcp *dcp);
int dcp_wait_ready(struct platform_device *pdev, u64 timeout);
void dcp_flush(struct drm_crtc *crtc, struct drm_atomic_commit *commit);
bool dcp_boot_surface_pending(struct platform_device *pdev);
bool dcp_hdr_metadata_live(struct platform_device *pdev);
bool dcp_edr_live(struct platform_device *pdev);
void dcp_retain_framebuffer(struct platform_device *pdev,
Expand Down
21 changes: 21 additions & 0 deletions drivers/gpu/drm/apple/iomfb.c
Original file line number Diff line number Diff line change
Expand Up @@ -3796,6 +3796,20 @@ iomfb_scanout_prepare_h17p(struct apple_dcp *dcp, struct drm_crtc *crtc,
drm_framebuffer_get(new_state->fb);
}
}
if (dcp->boot_surface_pending && scanout->fb[0]) {
struct drm_plane_state *primary = crtc->primary ?
drm_atomic_get_new_plane_state(state, crtc->primary) : NULL;

/*
* Match the explicit slot-zero clear in iomfb_flush() when the
* primary plane is disabled; dcp->iomfb.scanout keeps its own
* reference pinned until completion replaces it.
*/
if (!primary || primary->crtc != crtc || !primary->visible || !primary->fb) {
drm_framebuffer_put(scanout->fb[0]);
scanout->fb[0] = NULL;
}
}
if (dcp_is_ext26(dcp)) {
struct iomfb_scanout_h17p *dropped;
u64 bytes = ext26_scanout_bytes(scanout);
Expand Down Expand Up @@ -4401,6 +4415,13 @@ static void iomfb_start(struct apple_dcp *dcp)
}
}

bool dcp_boot_surface_pending(struct platform_device *pdev)
{
struct apple_dcp *dcp = pdev ? platform_get_drvdata(pdev) : NULL;

return dcp && READ_ONCE(dcp->boot_surface_pending);
}

bool dcp_is_initialized(struct platform_device *pdev)
{
struct apple_dcp *dcp = platform_get_drvdata(pdev);
Expand Down
48 changes: 39 additions & 9 deletions drivers/gpu/drm/apple/iomfb_template.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <linux/overflow.h>
#include <linux/pm_runtime.h>
#include <linux/slab.h>
#include <linux/soc/apple/mcc.h>
#include <linux/unaligned.h>

#include <drm/drm_color_mgmt.h>
Expand Down Expand Up @@ -737,7 +738,7 @@ static u32 dcpep_cb_zero(struct apple_dcp *dcp)
return 0;
}

static void dcp_report_swap_complete(struct apple_dcp *dcp, u32 id, ktime_t now)
static void dcp_report_swap_complete(struct apple_dcp *dcp, u32 id, ktime_t now, bool shown)
{
bool retire = true;
if (dcp_is_ext26(dcp)) {
Expand Down Expand Up @@ -790,8 +791,18 @@ static void dcp_report_swap_complete(struct apple_dcp *dcp, u32 id, ktime_t now)
dcp->crashed = true;
return;
}
if (dcp->hw.iomfb_method_profile != DCP_IOMFB_METHODS_H17G)
if (dcp->hw.iomfb_method_profile != DCP_IOMFB_METHODS_H17G) {
/* Only a displayed KMS swap that touched boot slot zero retires it. */
if (dcp->boot_surface_pending && shown && dcp->iomfb.next_scanout &&
!iomfb_present_brightness_only_h17p(dcp) &&
(DCP_FW_SWAP(dcp).swap.swap_enabled & BIT(0))) {
WRITE_ONCE(dcp->boot_surface_pending, false);
dev_info(dcp->dev, "boot scanout retired by displayed swap %u\n", id);
if (dcp->boot_scanout_reserved)
apple_mcc_boot_scanout_retired(dcp->dev->of_node);
}
retire = iomfb_present_complete_h17p(dcp);
}
#endif
#if DCP_FW_DESKTOP_26(DCP_FW_VER)
/* Late or duplicate completions cannot retire the replacement's flip. */
Expand Down Expand Up @@ -825,15 +836,17 @@ static void dcp_report_swap_complete(struct apple_dcp *dcp, u32 id, ktime_t now)
}

#if (DCP_FW_H17(DCP_FW_VER) && DCP_FW_VER >= DCP_FW_VERSION(27, 0, 0))
struct dcp_peer_completion { u32 id; ktime_t time; };
struct dcp_peer_completion { u32 id; ktime_t time; bool shown; };

static void dcp_peer_report_on_owner(struct apple_dcp *owner, void *data, void *cookie)
{
struct dcp_peer_completion *completion = data;
dcp_report_swap_complete(owner, completion->id, completion->time);
dcp_report_swap_complete(owner, completion->id, completion->time, completion->shown);
}
static void dcp_peer_queue_completion(struct apple_dcp *owner, u32 id, ktime_t time)

static void dcp_peer_queue_completion(struct apple_dcp *owner, u32 id, ktime_t time, bool shown)
{
struct dcp_peer_completion completion = { id, time };
struct dcp_peer_completion completion = { id, time, shown };
if (iomfb_queue_callback(owner, dcp_peer_report_on_owner, &completion,
sizeof(completion), NULL)) {
WRITE_ONCE(owner->crashed, true);
Expand All @@ -848,10 +861,15 @@ static void dcpep_cb_swap_complete(struct apple_dcp *dcp,
ktime_t now = dcp_is_ext26(dcp) ? ns_to_ktime(dcp->ext26_rx_ns) : ktime_get();
trace_iomfb_swap_complete(dcp, resp->swap_id);
#if (DCP_FW_H17(DCP_FW_VER) && DCP_FW_VER >= DCP_FW_VERSION(27, 0, 0))
if (dcp_peer_swap_complete_v27(dcp, resp->swap_id, now, dcp_peer_queue_completion))
if (dcp_peer_swap_complete_v27(dcp, resp->swap_id, now, resp->unkbool,
dcp_peer_queue_completion))
return;
#endif
dcp_report_swap_complete(dcp, resp->swap_id, now);
#if DCP_FW_H17(DCP_FW_VER)
dcp_report_swap_complete(dcp, resp->swap_id, now, resp->unkbool);
#else
dcp_report_swap_complete(dcp, resp->swap_id, now, false);
#endif
}

/* special */
Expand Down Expand Up @@ -4540,9 +4558,21 @@ void DCP_FW_NAME(iomfb_flush)(struct apple_dcp *dcp, struct drm_crtc *crtc, stru
#endif
}

#if DCP_FW_H17(DCP_FW_VER)
/*
* Keep sending an explicit slot-zero update until a displayed KMS
* completion confirms the boot scanout has retired. An enabled primary
* plane is pulled into the atomic commit by apple_atomic_check(); if
* slot zero is still absent here, the primary plane is disabled and
* slot zero should be cleared.
*/
if (dcp->boot_surface_pending && !(req->swap.swap_enabled & BIT(0)))
req->swap.swap_enabled |= BIT(0);
#endif

if (!has_surface && !crtc_state->color_mgmt_changed) {
if (crtc_state->enable && crtc_state->active &&
!crtc_state->planes_changed) {
!crtc_state->planes_changed && !dcp->boot_surface_pending) {
schedule_work(&dcp->vblank_wq);
return;
}
Expand Down
Loading