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
29 changes: 29 additions & 0 deletions drivers/gpu/drm/apple/apple_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1695,6 +1695,34 @@ static int apple_connector_notch_fastset(struct drm_connector *conn,
return drm_atomic_add_affected_planes(state, new->crtc);
}

/*
* The panel's paced rates (dcp_paced_rates()) are one timing to the DCP:
* switching between them changes only how the swaps are paced, so it is no
* mode set (a mode set away from that timing crashes the T6050 DCP).
*/
static void apple_connector_rate_fastset(struct drm_connector *conn,
struct drm_atomic_commit *state,
struct drm_connector_state *new)
{
struct platform_device *pdev;
struct drm_crtc_state *old_cs, *new_cs;

if (conn->funcs != &apple_connector_funcs || !new->crtc)
return;
pdev = READ_ONCE(to_apple_connector(conn)->dcp);
if (!pdev)
return;
old_cs = drm_atomic_get_old_crtc_state(state, new->crtc);
new_cs = drm_atomic_get_new_crtc_state(state, new->crtc);
if (!old_cs || !new_cs || !new_cs->mode_changed || new_cs->active_changed ||
new_cs->connectors_changed || !old_cs->active || !new_cs->active ||
old_cs->enable != new_cs->enable ||
!dcp_paced_fastset(platform_get_drvdata(pdev), &old_cs->mode, &new_cs->mode))
return;
new_cs->mode_changed = false;
drm_mode_copy(&new_cs->adjusted_mode, &new_cs->mode);
}

static int apple_connector_atomic_check(struct drm_connector *conn,
struct drm_atomic_commit *state)
{
Expand All @@ -1708,6 +1736,7 @@ static int apple_connector_atomic_check(struct drm_connector *conn,
ret = apple_connector_notch_fastset(conn, state, new);
if (ret)
return ret;
apple_connector_rate_fastset(conn, state, new);

if (blob && (blob->length != sizeof(struct hdr_output_metadata) ||
!dcp_hdr_is_type1(blob->data)))
Expand Down
3 changes: 3 additions & 0 deletions drivers/gpu/drm/apple/dcp-display-metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,9 @@ const struct drm_edid *dcp_panel_edid(const struct dcp_display_metadata *metadat
}
if (!timing || clock > 2550000)
return ERR_PTR(-ERANGE);
/* A swap-paced panel takes any rate down to its lowest, not only its timings'. */
if (metadata->vrr_min_hz && metadata->vrr_min_hz < min_v)
min_v = metadata->vrr_min_hz;

memcpy(block.header, "\x00\xff\xff\xff\xff\xff\xff\x00", 8);
block.product_id.manufacturer_name = cpu_to_be16(manufacturer);
Expand Down
2 changes: 2 additions & 0 deletions drivers/gpu/drm/apple/dcp-display-metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ struct dcp_display_metadata {
u32 max_luminance, max_fall, min_luminance; /* 16.16 cd/m2 */
/* DCP_METADATA_DEFAULT_*: what the sink left out, so the EDID leaves undefined */
u32 defaults;
/* A swap-paced panel's lowest rate (dcp_refresh_swap_paced()); 0 if none */
u32 vrr_min_hz;
};

#define DCP_METADATA_DEFAULT_SIZE BIT(0)
Expand Down
12 changes: 12 additions & 0 deletions drivers/gpu/drm/apple/dcp-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ struct iomfb_transaction {
bool brightness_only;
bool presentation;
bool completed;
/* A paced rate's frame time (dcp_paced_rates()); 0 sends at once. */
u32 pace_ns;
};
struct apple_dcp_typec_port;

Expand Down Expand Up @@ -1534,6 +1536,13 @@ struct apple_dcp {
struct delayed_work backlight_retry;
/* A firmware 27 panel's EDR ramp on a still frame (iomfb_edr_tick()) */
struct delayed_work edr_tick;
/*
* A paced rate's timeline (iomfb_pace_hold()): when the next
* swap is due to be shown, and when the last one was.
*/
struct hrtimer pace_timer;
ktime_t pace_next;
ktime_t last_complete;
unsigned long deadline;
unsigned int queued;
bool stopped;
Expand Down Expand Up @@ -1781,6 +1790,9 @@ void dcp_backlight_s2r_restore(struct apple_dcp *dcp);
s32 dcp_ext_backlight_value(struct apple_dcp *dcp);
bool dcp_ext_backlight_nits(struct apple_dcp *dcp, u64 *nits);
bool dcp_has_panel(struct apple_dcp *dcp);
bool dcp_paced_rates(struct apple_dcp *dcp);
bool dcp_paced_fastset(struct apple_dcp *dcp, const struct drm_display_mode *old,
const struct drm_display_mode *new);
extern int fw27_panel_boot_mode;
extern int notify_clients_form;

Expand Down
16 changes: 16 additions & 0 deletions drivers/gpu/drm/apple/dcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
#include "dcp-fabric.h"
#include "dcp-hdmi.h"
#include "dcp-syslog.h"
#include "dcp-refresh.h"
#include "dcp-internal.h"
#include "j613-25g83.h"
#include "dcp-external-bw.h"
Expand Down Expand Up @@ -1747,6 +1748,19 @@ bool dcp_panel_metadata_current(struct apple_dcp *dcp, u64 generation)
return valid;
}

/* The lowest rate a firmware 27 panel's timings are paced to, 0 for none. */
static u32 dcp_panel_paced_min(struct apple_dcp *dcp, const struct dcp_display_mode *modes,
unsigned int count)
{
u32 low, high, min = 0;

for (unsigned int i = 0; i < count && dcp->fw_compat == DCP_FIRMWARE_V_27_0; i++)
if (dcp_refresh_swap_paced((u32)drm_mode_vrefresh(&modes[i].mode) << 16,
modes[i].vrr, dcp_has_panel(dcp), &low, &high))
min = low >> 16;
return min;
}

const struct drm_edid *dcp_panel_edid_snapshot(struct apple_dcp *dcp,
const struct dcp_display_mode *modes,
unsigned int count, u64 *generation)
Expand Down Expand Up @@ -1778,6 +1792,8 @@ const struct drm_edid *dcp_panel_edid_snapshot(struct apple_dcp *dcp,
metadata.max_fall = metadata.max_luminance;
metadata.min_luminance = 0;
}
/* Its range reaches the lowest rate the panel paces. */
metadata.vrr_min_hz = dcp_panel_paced_min(dcp, modes, count);
/* The caller supplies the same retained catalog it is publishing. */
edid = size ? drm_edid_alloc(raw, size) :
dcp_panel_edid(&metadata, dcp->panel.color_target, modes, count,
Expand Down
127 changes: 124 additions & 3 deletions drivers/gpu/drm/apple/iomfb.c
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,48 @@ static void iomfb_queue_advance(struct apple_dcp *dcp)
schedule_work(&dcp->iomfb.work);
}

/* Sent this early, a swap makes the panel's tick at its due time. */
#define IOMFB_PACE_LEAD_NS (2 * NSEC_PER_MSEC)

static enum hrtimer_restart iomfb_pace_fire(struct hrtimer *timer)
{
struct apple_dcp *dcp = container_of(timer, struct apple_dcp, iomfb.pace_timer);

schedule_work(&dcp->iomfb.work);
return HRTIMER_NORESTART;
}

/*
* Whether a paced swap waits for its due time (dcp_paced_rates()). The due
* times are whole periods apart, so a rate that is no whole number of panel
* ticks keeps its average; a swap a period or more late starts them again from
* the last swap shown. Other transactions leave the schedule alone.
*/
static bool iomfb_pace_hold(struct apple_dcp *dcp, struct iomfb_transaction *transaction)
{
ktime_t now = ktime_get(), due, last;

if (!transaction->presentation)
return false;
if (!transaction->pace_ns) {
dcp->iomfb.pace_next = 0;
return false;
}
due = dcp->iomfb.pace_next;
if (!due || ktime_before(ktime_add_ns(due, transaction->pace_ns), now)) {
last = READ_ONCE(dcp->iomfb.last_complete);
due = last ? ktime_add_ns(last, transaction->pace_ns) : now;
}
if (ktime_before(now, ktime_sub_ns(due, IOMFB_PACE_LEAD_NS))) {
dcp->iomfb.pace_next = due;
hrtimer_start(&dcp->iomfb.pace_timer,
ktime_sub_ns(due, IOMFB_PACE_LEAD_NS), HRTIMER_MODE_ABS);
return true;
}
dcp->iomfb.pace_next = ktime_add_ns(due, transaction->pace_ns);
return false;
}

/* Start the first pending transaction if nothing holds the queue; true if one started. */
static bool iomfb_start_next_locked(struct apple_dcp *dcp)
{
Expand All @@ -529,6 +571,9 @@ static bool iomfb_start_next_locked(struct apple_dcp *dcp)

transaction = list_first_entry(&dcp->iomfb.pending,
struct iomfb_transaction, link);
/* A paced swap not yet due: iomfb_pace_fire() schedules the worker. */
if (iomfb_pace_hold(dcp, transaction))
return false;
list_del(&transaction->link);
dcp->iomfb.queued--;
dcp->iomfb.active = transaction;
Expand Down Expand Up @@ -727,6 +772,8 @@ void iomfb_queue_init(struct apple_dcp *dcp)
init_waitqueue_head(&dcp->channels_idle_wq);
spin_lock_init(&dcp->v27_idle_lock);
INIT_DELAYED_WORK(&dcp->v27_idle_cache_work, iomfb_v27_idle_cache_work);
hrtimer_setup(&dcp->iomfb.pace_timer, iomfb_pace_fire, CLOCK_MONOTONIC,
HRTIMER_MODE_ABS);
atomic_set(&dcp->iomfb.opaque_x_state, IOMFB_OPAQUE_X_WAITING);
}

Expand Down Expand Up @@ -778,6 +825,7 @@ void iomfb_queue_stop(struct apple_dcp *dcp)
spin_unlock_irqrestore(&dcp->iomfb.callback_lock, flags);
iomfb_discard_pending(dcp);
mutex_unlock(&dcp->iomfb.lock);
hrtimer_cancel(&dcp->iomfb.pace_timer);
cancel_work_sync(&dcp->iomfb.work);
cancel_work_sync(&dcp->iomfb.callback_work);
while ((item = iomfb_pop_callback(dcp)))
Expand Down Expand Up @@ -4663,6 +4711,49 @@ bool dcp_notch_mode_known(struct apple_dcp *dcp, const struct drm_display_mode *
dcp_notch_twin_of(&fixed, mode, dcp->notch_rows);
}

/*
* Firmware 27 lists the ProMotion panel's fixed rates (60, 59.94, 50, 48 and
* 47.95 Hz, each "IsPromoted") with its 120 Hz timing: the set macOS offers.
* A mode set to one of them crashes the T6050 internal DCP (see
* dcp_mode_settable()), but the panel shows each swap on the first 240 Hz tick
* after it arrives (dcp_refresh_swap_paced()). So such a rate is offered as a
* mode that keeps the DCP on the 120 Hz timing of its size, and the swaps are
* paced to the rate (iomfb_pace_hold()): 60 and 48 Hz are whole ticks, the
* others land on the nearest tick and keep their average. Only while the
* panel runs that 120 Hz timing: a panel iBoot left at 60 Hz keeps just that.
*/
bool dcp_paced_rates(struct apple_dcp *dcp)
{
u32 boot = READ_ONCE(dcp->boot_rate);

return dcp->hw.only_120hz_modes && dcp->fw_compat == DCP_FIRMWARE_V_27_0 &&
(!boot || boot == 120) && dcp_has_panel(dcp);
}

static bool dcp_mode_is_promotion(const struct drm_display_mode *mode)
{
return dcp_refresh_is_promotion((u32)drm_mode_vrefresh(mode) << 16);
}

/* The timing the DCP runs for @found: its own, or for a paced rate the 120 Hz one. */
static const struct dcp_display_mode *
dcp_paced_base(struct apple_dcp *dcp, const struct dcp_display_mode *modes,
unsigned int count, const struct dcp_display_mode *found)
{
unsigned int i;

if (!dcp_paced_rates(dcp) || dcp_mode_is_promotion(&found->mode))
return found;
for (i = 0; i < count; i++)
if (!modes[i].automatic_rgb8_quirk &&
modes[i].mode.hdisplay == found->mode.hdisplay &&
modes[i].mode.vdisplay == found->mode.vdisplay &&
dcp_mode_is_promotion(&modes[i].mode))
return &modes[i];
/* No 120 Hz timing of its size: dcp_mode_settable() refuses it. */
return found;
}

static const struct dcp_display_mode *
dcp_find_mode(struct apple_dcp *dcp, const struct drm_display_mode *mode)
{
Expand All @@ -4677,7 +4768,7 @@ dcp_find_mode(struct apple_dcp *dcp, const struct drm_display_mode *mode)
DRM_MODE_MATCH_TIMINGS |
DRM_MODE_MATCH_CLOCK)) {
if (!modes[i].automatic_rgb8_quirk)
return &modes[i];
return dcp_paced_base(dcp, modes, count, &modes[i]);
mutex_lock(&dcp->hpd_mutex);
mutex_lock(&dcp->dcpavserv.lock);
spin_lock_irqsave(&dcp->metadata.lock, flags);
Expand Down Expand Up @@ -4707,6 +4798,31 @@ bool lookup_mode(struct apple_dcp *dcp, const struct drm_display_mode *mode,
return true;
}

/* Two modes the DCP runs as one timing: paced rates of the same size. */
bool dcp_paced_fastset(struct apple_dcp *dcp, const struct drm_display_mode *old,
const struct drm_display_mode *new)
{
const struct dcp_display_mode *a, *b;

if (!dcp_paced_rates(dcp))
return false;
a = dcp_find_mode(dcp, old);
b = dcp_find_mode(dcp, new);
return a && a == b;
}

/* A paced rate's frame time in ns, 0 for a mode the swaps need no pacing for. */
static u32 dcp_pace_ns(struct apple_dcp *dcp, const struct drm_crtc_state *state)
{
const struct drm_display_mode *mode = &state->mode;

if (!state->active || state->vrr_enabled || !dcp_paced_rates(dcp) ||
mode->clock <= 0 || !mode->htotal || !mode->vtotal ||
dcp_mode_is_promotion(mode))
return 0;
return div_u64((u64)mode->htotal * mode->vtotal * 1000000ULL, mode->clock);
}

/*
* H17P keeps the mode the bootloader programmed and never sends
* set_digital_out_mode (see DCP_INHERIT_BOOT_MODE in iomfb_template.c), so a
Expand All @@ -4732,11 +4848,13 @@ static bool dcp_mode_settable(struct apple_dcp *dcp,
* DCPs crash on a mode set away from the timing iBoot left the panel
* at: 120 -> 60 Hz, and 60 -> 120 Hz when macOS left it at 60 Hz.
* Offer only the rate the firmware reported at start
* (dcp_rtk_syslog_boot_rate()), 120 Hz when it reported none.
* (dcp_rtk_syslog_boot_rate()), 120 Hz when it reported none. A paced
* rate runs that timing (dcp_paced_rates()): dcp_find_mode() gave its
* 120 Hz entry.
*/
if (dcp->hw.only_120hz_modes &&
dcp->fw_compat == DCP_FIRMWARE_V_27_0 &&
drm_mode_vrefresh(mode) != (READ_ONCE(dcp->boot_rate) ?: 120))
drm_mode_vrefresh(&dcp_mode->mode) != (READ_ONCE(dcp->boot_rate) ?: 120))
return false;

return true;
Expand Down Expand Up @@ -5899,6 +6017,7 @@ static void iomfb_queue_atomic(struct apple_dcp *dcp, struct drm_crtc *crtc,
struct drm_atomic_commit *state)
{
struct iomfb_atomic_transaction *atomic;
struct drm_crtc_state *crtc_state;
int ret;

if (READ_ONCE(dcp->iomfb.presentation_paused) ||
Expand All @@ -5915,6 +6034,8 @@ static void iomfb_queue_atomic(struct apple_dcp *dcp, struct drm_crtc *crtc,
atomic->state = drm_atomic_commit_get(state);
atomic->crtc = crtc;
atomic->dcp = dcp;
crtc_state = drm_atomic_get_new_crtc_state(state, crtc);
atomic->transaction.pace_ns = crtc_state ? dcp_pace_ns(dcp, crtc_state) : 0;
ret = iomfb_queue_admit(dcp, &atomic->transaction,
iomfb_commit_starts_direct(state));
if (!ret)
Expand Down
3 changes: 3 additions & 0 deletions drivers/gpu/drm/apple/iomfb_template.c
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,9 @@ static void dcp_report_swap_complete(struct apple_dcp *dcp, u32 id, ktime_t now,
dcp->have_swap_complete = true;
dcp_swap_watchdog_complete(dcp);
if (retire) {
/* Where a paced rate's next swap is due from (iomfb_pace_hold()). */
if (shown)
WRITE_ONCE(dcp->iomfb.last_complete, now);
dcp_release_retained_framebuffers(dcp, id);
dcp_drm_crtc_page_flip(dcp, now);
#if (DCP_FW_H17(DCP_FW_VER) && DCP_FW_VER >= DCP_FW_VERSION(27, 0, 0))
Expand Down
Loading
Loading