From 0cb64c16fa63f3ffb439c4f1e9689092c9a1d55c Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Sun, 22 Nov 2026 22:24:12 +1100 Subject: [PATCH 1/6] drm/apple: control the panel notch at run time A panel with a camera housing has apple,notch-height rows at its top. Until now the driver read them once at probe: hidden for the whole boot unless the boot loader kept them (chosen asahi,show-notch) or a module parameter said otherwise, with no way to change it without a reboot, and the text console drew under the notch whenever the notch was shown. The panel always runs its native timing; what changes is how much of it is drawn on. Keep both geometries of each panel timing in the mode catalogue: the full panel and its notch-free twin, with the notch rows folded into the vertical sync exactly as the boot-time hidden mode did. The mode a commit carries decides where the frame is scanned out (the twin starts below the notch rows, which stay black), and switching between the twins keeps the panel's mode, so it is no mode set. Which geometry is offered follows a policy: the boot loader's choice, then the new "notch" connector property (enum: hidden, shown), which a compositor sets atomically, or /sys/class/drm/cardN-eDP-1/notch for scripts. A change re-probes userspace and the console. The notch-free modes are always offered; the full ones only while they are wanted and a DRM master owns the device. When no master does (a text-only system, a VT switch, a compositor that dropped master or exited), the console gets the notch-free geometry and re-probes into it; its surface is sized to it, so it never draws under the notch. A master that comes back gets its own mode again, as a fast switch. The M4 (T8132) pipe, which only took full-panel frames, gets the same two modes: a notch-free frame is placed with the swap's destination rectangle. The standalone firmware 14.7/26.6 pipes keep the boot loader's geometry for the boot. Nothing is selected by board: the rows come from apple,notch-height, which the boot loader takes from the ADT, and a panel without them is unchanged. Signed-off-by: Ryan Murray --- drivers/gpu/drm/apple/apple_drv.c | 381 +++++++++++++++++- drivers/gpu/drm/apple/connector.c | 15 + drivers/gpu/drm/apple/connector.h | 6 + drivers/gpu/drm/apple/dcp-internal.h | 34 ++ drivers/gpu/drm/apple/dcp-m4-frame.h | 29 +- drivers/gpu/drm/apple/dcp-notch.h | 122 ++++++ drivers/gpu/drm/apple/dcp.c | 31 +- drivers/gpu/drm/apple/dcp.h | 2 + drivers/gpu/drm/apple/iomfb.c | 148 ++++++- drivers/gpu/drm/apple/iomfb_m4.c | 18 +- drivers/gpu/drm/apple/iomfb_m4.h | 8 + drivers/gpu/drm/apple/iomfb_m4_present.h | 13 +- drivers/gpu/drm/apple/iomfb_template.c | 15 +- drivers/gpu/drm/apple/parser.h | 5 +- .../drivers/gpu/apple-dcp/display.py | 104 +++++ .../drivers/gpu/apple-dcp/lifecycle.py | 4 +- .../selftests/drivers/gpu/apple-dcp/m4.py | 43 +- .../selftests/drivers/gpu/apple-dcp/rate.py | 11 +- .../selftests/drivers/gpu/apple-dcp/run.py | 2 + 19 files changed, 943 insertions(+), 48 deletions(-) create mode 100644 drivers/gpu/drm/apple/dcp-notch.h diff --git a/drivers/gpu/drm/apple/apple_drv.c b/drivers/gpu/drm/apple/apple_drv.c index 41a3327f47b41..f453828d50d12 100644 --- a/drivers/gpu/drm/apple/apple_drv.c +++ b/drivers/gpu/drm/apple/apple_drv.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -74,8 +75,48 @@ struct apple_drm_private { /* A dark wake left the outputs as the suspend did, for the next resume. */ bool dark_held; struct notifier_block pm_nb; + /* The "notch" connector property, on panels with notch rows (dcp-notch.h). */ + struct drm_property *notch_prop; + /* Re-probe after a "notch" change: userspace and the console. */ + struct work_struct notch_hotplug; + /* The console took the display back: it re-probes its notch-free modes. */ + struct work_struct notch_console; }; +static struct apple_drm_private *to_apple_drm(struct drm_device *drm) +{ + return container_of(drm, struct apple_drm_private, drm); +} + +/* A connector state with the panel's "notch" property. */ +struct apple_connector_state { + struct drm_connector_state base; + u8 notch; /* enum dcp_notch_policy */ +}; + +static struct apple_connector_state * +to_apple_connector_state(const struct drm_connector_state *state) +{ + return container_of(state, struct apple_connector_state, base); +} + +static const struct drm_connector_funcs apple_connector_funcs; + +/* The panel pipeline behind @connector if its panel has notch rows, else NULL. */ +static struct apple_dcp *apple_connector_notch_dcp(struct drm_connector *connector) +{ + struct platform_device *pdev; + struct apple_dcp *dcp; + + if (connector->funcs != &apple_connector_funcs) + return NULL; + pdev = READ_ONCE(to_apple_connector(connector)->dcp); + dcp = pdev ? platform_get_drvdata(pdev) : NULL; + + return dcp && dcp->notch_rows && dcp_notch_dynamic(dcp) && + connector->connector_type == DRM_MODE_CONNECTOR_eDP ? dcp : NULL; +} + static int apple_drm_pm_notify(struct notifier_block *nb, unsigned long action, void *data); /* Component readiness is later than platform probe/bind. */ @@ -205,10 +246,85 @@ static int apple_drm_fbdev_probe(struct drm_fb_helper *helper, } } + /* + * The console never draws under a panel's notch: its surface is the + * notch-free geometry, so every later probe of the fbdev client, which + * is bounded by its surface, picks the notch-free modes. Its first probe + * normally ran with no DRM master and picked them already; this covers + * a boot splash that held master then. + */ + drm_for_each_crtc(crtc, helper->dev) { + struct apple_dcp *dcp; + u32 rows; + + if (t8132_ext_crtc(crtc)) + continue; + dcp = platform_get_drvdata(to_apple_crtc(crtc)->dcp); + rows = READ_ONCE(dcp->notch_panel_rows); + if (!dcp->notch_rows || !dcp_notch_dynamic(dcp) || !rows || + sizes->surface_height != rows) + continue; + sizes->surface_height -= dcp->notch_rows; + sizes->fb_height = min(sizes->fb_height, sizes->surface_height); + break; + } + return drm_fbdev_dma_driver_fbdev_probe(helper, sizes); } #endif +/* + * Who owns the display decides the notch geometry offered (dcp-notch.h): a + * DRM master gets the policy, the console gets notch-free modes. When the + * master goes (a VT switch, a compositor that exits or drops master), the + * console client re-probes and so takes them; when one comes back, it is + * offered the policy's geometry at its next probe, and its own mode, full or + * notch-free, is a fast switch either way. + */ +static void apple_drm_notch_owner(struct drm_device *drm, bool owned) +{ + struct drm_crtc *crtc; + bool notch = false; + + drm_for_each_crtc(crtc, drm) { + struct apple_dcp *dcp; + + if (t8132_ext_crtc(crtc)) + continue; + dcp = platform_get_drvdata(to_apple_crtc(crtc)->dcp); + if (!dcp || !dcp->notch_rows || !dcp_notch_dynamic(dcp)) + continue; + WRITE_ONCE(dcp->notch_owned, owned); + notch = true; + } + /* master_drop() runs under master_mutex, which the console's restore takes. */ + if (notch && !owned) + schedule_work(&to_apple_drm(drm)->notch_console); +} + +static void apple_drm_master_set(struct drm_device *drm, struct drm_file *file, + bool from_open) +{ + apple_drm_notch_owner(drm, true); +} + +static void apple_drm_master_drop(struct drm_device *drm, struct drm_file *file) +{ + apple_drm_notch_owner(drm, false); +} + +static void apple_drm_notch_console(struct work_struct *work) +{ + drm_client_dev_hotplug(&container_of(work, struct apple_drm_private, + notch_console)->drm); +} + +static void apple_drm_notch_hotplug(struct work_struct *work) +{ + drm_kms_helper_hotplug_event(&container_of(work, struct apple_drm_private, + notch_hotplug)->drm); +} + /* * HDR is asked for by the compositor that set it, but connector properties * outlive their client. When it exits, the next client (Plymouth at @@ -300,6 +416,8 @@ static const struct drm_driver apple_drm_driver = { DRM_FBDEV_DMA_DRIVER_OPS, #endif .postclose = apple_drm_postclose, + .master_set = apple_drm_master_set, + .master_drop = apple_drm_master_drop, .name = DRIVER_NAME, .desc = DRIVER_DESC, .major = 1, @@ -786,6 +904,33 @@ static const struct drm_mode_config_funcs apple_mode_config_funcs = { .fb_create = drm_gem_fb_create, }; +/* + * A committed "notch" policy changes which modes are offered: tell + * userspace and the console to probe again. + */ +static void apple_commit_notch(struct drm_atomic_commit *state) +{ + struct drm_connector_state *old, *new; + struct drm_connector *conn; + bool changed = false; + int i; + + for_each_oldnew_connector_in_state(state, conn, old, new, i) { + struct apple_dcp *dcp = apple_connector_notch_dcp(conn); + u8 notch; + + if (!dcp) + continue; + notch = to_apple_connector_state(new)->notch; + if (notch == to_apple_connector_state(old)->notch) + continue; + WRITE_ONCE(dcp->notch_policy, notch); + changed = true; + } + if (changed) + schedule_work(&to_apple_drm(state->dev)->notch_hotplug); +} + static void apple_atomic_commit_tail(struct drm_atomic_commit *state) { struct drm_plane *plane; @@ -814,6 +959,7 @@ static void apple_atomic_commit_tail(struct drm_atomic_commit *state) DRM_PLANE_COMMIT_ACTIVE_ONLY); drm_atomic_helper_fake_vblank(state); drm_atomic_helper_commit_hw_done(state); + apple_commit_notch(state); drm_atomic_helper_wait_for_flip_done(state->dev, state); apple_fail_lost_flips(state); drm_atomic_helper_cleanup_planes(state->dev, state); @@ -841,22 +987,181 @@ static void appledrm_connector_cleanup(struct drm_connector *connector) kfree(apple_connector); } +/* Probe with the client's size limit at hand (see dcp_notch_offer()). */ +static int apple_connector_fill_modes(struct drm_connector *connector, + u32 max_x, u32 max_y) +{ + struct drm_mode_config *config = &connector->dev->mode_config; + + to_apple_connector(connector)->probe_max_y = max_y < config->max_height ? max_y : 0; + return drm_helper_probe_single_connector_modes(connector, max_x, max_y); +} + +static void apple_connector_reset(struct drm_connector *connector) +{ + struct apple_connector_state *state = kzalloc_obj(*state); + struct apple_dcp *dcp = apple_connector_notch_dcp(connector); + + if (connector->state) { + __drm_atomic_helper_connector_destroy_state(connector->state); + kfree(to_apple_connector_state(connector->state)); + connector->state = NULL; + } + if (!state) + return; + __drm_atomic_helper_connector_reset(connector, &state->base); + state->notch = dcp ? READ_ONCE(dcp->notch_policy) : DCP_NOTCH_HIDDEN; +} + +static struct drm_connector_state * +apple_connector_duplicate_state(struct drm_connector *connector) +{ + struct apple_connector_state *state; + + if (WARN_ON(!connector->state)) + return NULL; + state = kmemdup(to_apple_connector_state(connector->state), sizeof(*state), + GFP_KERNEL); + if (!state) + return NULL; + __drm_atomic_helper_connector_duplicate_state(connector, &state->base); + return &state->base; +} + +static void apple_connector_destroy_state(struct drm_connector *connector, + struct drm_connector_state *state) +{ + __drm_atomic_helper_connector_destroy_state(state); + kfree(to_apple_connector_state(state)); +} + +static int apple_connector_atomic_set_property(struct drm_connector *connector, + struct drm_connector_state *state, + struct drm_property *property, u64 val) +{ + if (property != to_apple_drm(connector->dev)->notch_prop || + val > DCP_NOTCH_SHOWN) + return -EINVAL; + to_apple_connector_state(state)->notch = val; + return 0; +} + +static int apple_connector_atomic_get_property(struct drm_connector *connector, + const struct drm_connector_state *state, + struct drm_property *property, u64 *val) +{ + if (property != to_apple_drm(connector->dev)->notch_prop) + return -EINVAL; + *val = to_apple_connector_state(state)->notch; + return 0; +} + +static const struct drm_prop_enum_list apple_notch_names[] = { + { DCP_NOTCH_HIDDEN, "hidden" }, + { DCP_NOTCH_SHOWN, "shown" }, +}; + +/* The sysfs words, indexed by enum dcp_notch_policy. */ +static const char * const apple_notch_words[] = { "hidden", "shown" }; + +/* Commit @notch for @connector, as a compositor setting "notch" would. */ +static int apple_connector_commit_notch(struct drm_connector *connector, u8 notch) +{ + struct drm_modeset_acquire_ctx ctx; + struct drm_connector_state *cs; + struct drm_atomic_commit *state; + int ret = -ENOMEM; + + drm_modeset_acquire_init(&ctx, 0); + state = drm_atomic_commit_alloc(connector->dev); + if (!state) + goto out_ctx; + state->acquire_ctx = &ctx; +retry: + cs = drm_atomic_get_connector_state(state, connector); + ret = PTR_ERR_OR_ZERO(cs); + if (!ret) { + to_apple_connector_state(cs)->notch = notch; + ret = drm_atomic_commit(state); + } + if (ret == -EDEADLK) { + drm_atomic_commit_clear(state); + drm_modeset_backoff(&ctx); + goto retry; + } + drm_atomic_commit_put(state); +out_ctx: + drm_modeset_drop_locks(&ctx); + drm_modeset_acquire_fini(&ctx); + return ret; +} + +/* + * /sys/class/drm/cardN-eDP-1/notch: "shown" or "hidden", the same policy as + * the "notch" connector property, for scripts. + */ +static ssize_t notch_show(struct device *kdev, struct device_attribute *attr, + char *buf) +{ + struct drm_connector *connector = dev_get_drvdata(kdev); + struct apple_dcp *dcp = apple_connector_notch_dcp(connector); + + if (!dcp) + return -ENODEV; + return sysfs_emit(buf, "%s\n", apple_notch_words[READ_ONCE(dcp->notch_policy) == + DCP_NOTCH_SHOWN]); +} + +static ssize_t notch_store(struct device *kdev, struct device_attribute *attr, + const char *buf, size_t len) +{ + struct drm_connector *connector = dev_get_drvdata(kdev); + int ret = sysfs_match_string(apple_notch_words, buf); + + if (ret < 0) { + bool on; + + if (kstrtobool(buf, &on)) + return -EINVAL; + ret = on ? DCP_NOTCH_SHOWN : DCP_NOTCH_HIDDEN; + } + if (!apple_connector_notch_dcp(connector)) + return -ENODEV; + ret = apple_connector_commit_notch(connector, ret); + return ret ? ret : len; +} +static DEVICE_ATTR_RW(notch); + static int apple_connector_late_register(struct drm_connector *connector) { - return apple_connector_backlight_late_register(to_apple_connector(connector)); + int ret; + + if (apple_connector_notch_dcp(connector)) { + ret = device_create_file(connector->kdev, &dev_attr_notch); + if (ret) + return ret; + } + ret = apple_connector_backlight_late_register(to_apple_connector(connector)); + if (ret) + device_remove_file(connector->kdev, &dev_attr_notch); + return ret; } static void apple_connector_early_unregister(struct drm_connector *connector) { apple_connector_backlight_early_unregister(to_apple_connector(connector)); + /* Nothing if it was never created. */ + device_remove_file(connector->kdev, &dev_attr_notch); } static const struct drm_connector_funcs apple_connector_funcs = { - .fill_modes = drm_helper_probe_single_connector_modes, + .fill_modes = apple_connector_fill_modes, .destroy = appledrm_connector_cleanup, - .reset = drm_atomic_helper_connector_reset, - .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, - .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, + .reset = apple_connector_reset, + .atomic_duplicate_state = apple_connector_duplicate_state, + .atomic_destroy_state = apple_connector_destroy_state, + .atomic_set_property = apple_connector_atomic_set_property, + .atomic_get_property = apple_connector_atomic_get_property, .detect = apple_connector_detect, .debugfs_init = apple_connector_debugfs_init, .oob_hotplug_event = apple_connector_oob_hotplug, @@ -912,6 +1217,33 @@ static u8 apple_connector_eotf(const struct drm_connector_state *state) return hdr->hdmi_metadata_type1.eotf; } +/* + * The two notch geometries of the panel's timing (dcp-notch.h) differ only in + * where the frame is scanned out: switching between them, the console taking + * the display back or a compositor taking it, keeps the panel's mode, so it + * is no mode set (no CRTC off and on, no firmware mode set). + */ +static void apple_connector_notch_fastset(struct drm_connector *conn, + struct drm_atomic_commit *state, + struct drm_connector_state *new) +{ + struct apple_dcp *dcp = apple_connector_notch_dcp(conn); + struct drm_crtc_state *old_cs, *new_cs; + + if (!dcp || !new->crtc) + 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 || + old_cs->vrr_enabled != new_cs->vrr_enabled || + !dcp_notch_twins(&old_cs->mode, &new_cs->mode, dcp->notch_rows) || + !dcp_notch_mode_known(dcp, &new_cs->mode)) + return; + new_cs->mode_changed = false; +} + static int apple_connector_atomic_check(struct drm_connector *conn, struct drm_atomic_commit *state) { @@ -919,6 +1251,9 @@ static int apple_connector_atomic_check(struct drm_connector *conn, struct drm_connector_state *new = drm_atomic_get_new_connector_state(state, conn); struct drm_crtc_state *crtc_state; + /* Before anything below asks for a real mode set again. */ + apple_connector_notch_fastset(conn, state, new); + if (!new->crtc || (old->colorspace == new->colorspace && drm_connector_atomic_hdr_metadata_equal(old, new))) return 0; @@ -1027,6 +1362,33 @@ static const struct drm_crtc_helper_funcs apple_crtc_helper_funcs = { .mode_fixup = dcp_crtc_mode_fixup, }; +/* + * "notch" (enum: hidden, shown) on a panel with notch rows: whether a + * compositor is offered the full panel height (dcp-notch.h). The modes + * follow a change; the mode a commit carries decides what is scanned out. + */ +static int apple_connector_attach_notch(struct drm_connector *connector) +{ + struct apple_drm_private *apple = to_apple_drm(connector->dev); + struct apple_dcp *dcp = apple_connector_notch_dcp(connector); + + if (!dcp) + return 0; + if (!apple->notch_prop) { + apple->notch_prop = drm_property_create_enum(connector->dev, 0, "notch", + apple_notch_names, + ARRAY_SIZE(apple_notch_names)); + if (!apple->notch_prop) + return -ENOMEM; + } + drm_object_attach_property(&connector->base, apple->notch_prop, + READ_ONCE(dcp->notch_policy)); + if (connector->state) + to_apple_connector_state(connector->state)->notch = + READ_ONCE(dcp->notch_policy); + return 0; +} + static int apple_connector_create(struct drm_device *drm, struct platform_device *dcp, struct apple_crtc *crtc, @@ -1065,6 +1427,9 @@ static int apple_connector_create(struct drm_device *drm, connector->base.polled = DRM_CONNECTOR_POLL_HPD; connector->connected = false; apple_connector_set_pipeline(connector, dcp); + ret = apple_connector_attach_notch(&connector->base); + if (ret) + goto err_cleanup; ret = drm_connector_attach_encoder(&connector->base, &encoder->base); if (ret) @@ -1738,6 +2103,8 @@ static int apple_drm_init(struct device *dev) return PTR_ERR(apple); dev_set_drvdata(dev, apple); + INIT_WORK(&apple->notch_hotplug, apple_drm_notch_hotplug); + INIT_WORK(&apple->notch_console, apple_drm_notch_console); ret = drmm_mode_config_init(&apple->drm); if (ret) @@ -1888,6 +2255,8 @@ static int apple_drm_init(struct device *dev) if (retained_modeset) drm_modeset_unlock_all(&apple->drm); err_unbind: + cancel_work_sync(&apple->notch_hotplug); + cancel_work_sync(&apple->notch_console); t8132_ext_drm_fini(&apple->drm); apple_drm_quiesce_connectors(&apple->drm); component_unbind_all(dev, NULL); @@ -1906,6 +2275,8 @@ static void apple_drm_uninit(struct device *dev) return; unregister_pm_notifier(&apple->pm_nb); + cancel_work_sync(&apple->notch_hotplug); + cancel_work_sync(&apple->notch_console); /* Before anything of the DRM device is torn down. */ t8132_ext_drm_fini(&apple->drm); diff --git a/drivers/gpu/drm/apple/connector.c b/drivers/gpu/drm/apple/connector.c index f3953abda3421..ade43851e3eae 100644 --- a/drivers/gpu/drm/apple/connector.c +++ b/drivers/gpu/drm/apple/connector.c @@ -139,6 +139,19 @@ static void dcp_afk_debugfs_root(struct platform_device *pdev, int ep, struct de #endif } +/* The panel's notch state (dcp-notch.h), for checking what is on screen. */ +static int notch_show(struct seq_file *m, void *v) +{ + struct apple_dcp *dcp = m->private; + + seq_printf(m, "rows %u\npanel_rows %u\npolicy %s\nowned %u\nscanout_y %u\n", + dcp->notch_rows, READ_ONCE(dcp->notch_panel_rows), + READ_ONCE(dcp->notch_policy) == DCP_NOTCH_SHOWN ? "shown" : "hidden", + READ_ONCE(dcp->notch_owned), READ_ONCE(dcp->notch_scanout_y)); + return 0; +} +DEFINE_SHOW_ATTRIBUTE(notch); + void apple_connector_debugfs_init(struct drm_connector *connector, struct dentry *root) { struct apple_connector *apple_con = to_apple_connector(connector); @@ -147,6 +160,8 @@ void apple_connector_debugfs_init(struct drm_connector *connector, struct dentry if (dcp && iomfb_is_m4(dcp)) iomfb_m4_debugfs_init(dcp, root); + if (dcp && dcp->notch_rows && dcp_notch_dynamic(dcp)) + debugfs_create_file("notch", 0444, root, dcp, ¬ch_fops); debugfs_create_file("ColorElements", 0444, root, apple_con, &chunk_color_fops); diff --git a/drivers/gpu/drm/apple/connector.h b/drivers/gpu/drm/apple/connector.h index 5d8c1674503fc..f32da7d3dee53 100644 --- a/drivers/gpu/drm/apple/connector.h +++ b/drivers/gpu/drm/apple/connector.h @@ -89,6 +89,12 @@ struct apple_connector { * chosen one; -1 until then, and nothing is sent. */ int bl_level; + /* + * The height limit of the probe in progress (fill_modes(), under + * mode_config.mutex): a client whose surface is shorter than the panel, + * the console's, is offered the notch-free modes (dcp-notch.h). + */ + u32 probe_max_y; }; #define to_apple_connector(x) container_of(x, struct apple_connector, base) diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index 515e6bf065f09..7a48832c82901 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -5,6 +5,7 @@ #define __APPLE_DCP_INTERNAL_H__ #include "dcp-indicator.h" +#include "dcp-notch.h" #include #include #include @@ -900,6 +901,8 @@ struct apple_dcp { struct mutex modes_lock; struct dcp_display_mode *modes; unsigned int nr_modes; + /* Of them, notch-free twins of the panel's timings (dcp-notch.h), last. */ + unsigned int nr_notch_twins; u64 modes_generation; u64 dimensions_generation; struct work_struct dimensions_wq; @@ -915,7 +918,21 @@ struct apple_dcp { /* an external display whose backlight DCP can drive */ bool ext_backlight; + /* + * Rows hidden for the whole boot, on the pipes that keep one notch + * geometry (firmware 14.7/26.6 standalone pipes); 0 elsewhere. + */ unsigned notch_height; + /* The panel's notch rows (apple,notch-height), shown or not; 0: no notch. */ + u32 notch_rows; + /* Active rows of the full panel, notch rows included (from its modes). */ + u32 notch_panel_rows; + /* enum dcp_notch_policy: the geometry asked for while a client owns the panel. */ + u8 notch_policy; + /* A DRM master owns the device (apple_drm_master_set/drop()). */ + bool notch_owned; + /* Panel rows above the last frame swapped in: the notch rows, or 0. */ + u32 notch_scanout_y; /* Workqueue for sending vblank events when a dcp swap is not possible */ struct work_struct vblank_wq; @@ -1183,6 +1200,23 @@ struct apple_dcp { }; /* T8132 firmware uses its own wire codec, with the common DRM/KMS owner. */ +/* The display's own timings: the catalogue less the notch-free twins. */ +static inline unsigned int dcp_nr_timings(const struct apple_dcp *dcp) +{ + return READ_ONCE(dcp->nr_modes) - READ_ONCE(dcp->nr_notch_twins); +} + +/* + * Pipes whose modes carry both notch geometries (dcp-notch.h). The + * standalone firmware 14.7/26.6 pipes build one mode from the boot + * framebuffer and keep the boot loader's geometry for the boot. + */ +static inline bool dcp_notch_dynamic(const struct apple_dcp *dcp) +{ + return dcp->fw_compat != DCP_FIRMWARE_V_14_7 && + dcp->fw_compat != DCP_FIRMWARE_V_26_6; +} + static inline bool iomfb_is_m4(const struct apple_dcp *dcp) { return IS_ENABLED(CONFIG_DRM_APPLE_DCP_T8132) && diff --git a/drivers/gpu/drm/apple/dcp-m4-frame.h b/drivers/gpu/drm/apple/dcp-m4-frame.h index e51fe0a239bcb..abc59f0550b2c 100644 --- a/drivers/gpu/drm/apple/dcp-m4-frame.h +++ b/drivers/gpu/drm/apple/dcp-m4-frame.h @@ -29,13 +29,19 @@ struct dcp_m4_frame { u32 height; u32 stride; enum dcp_m4_frame_format format; + /* Panel rows above the frame: a notch-free frame starts below the notch. */ + u32 dst_y; }; +/* Most notch rows a panel frame may start below (as MAX_NOTCH_HEIGHT). */ +#define DCP_M4_MAX_DST_Y 160U + static inline int dcp_m4_frame_check(const struct dcp_m4_frame *frame) { u64 size = (u64)frame->stride * frame->height; - if (frame->width != DCP_M4_PANEL_WIDTH || frame->height != DCP_M4_PANEL_HEIGHT || + if (frame->width != DCP_M4_PANEL_WIDTH || frame->dst_y > DCP_M4_MAX_DST_Y || + frame->height + frame->dst_y != DCP_M4_PANEL_HEIGHT || frame->stride < DCP_M4_PANEL_WIDTH * 4 || frame->stride % 64 || !size || size > 0xffffffffULL || frame->backing_size < size || !frame->dva || frame->dva % 0x4000 || frame->dva >= (1ULL << 42) || @@ -78,19 +84,31 @@ static inline int dcp_m4_direct_extent(u64 dva, u64 mapped, u64 needed) return 0; } -/* Describe a qualified client framebuffer at its SID0 DVA; no CPU access. */ -static inline int dcp_m4_direct_frame(struct dcp_m4_frame *frame, u64 dva, u64 mapped, - u32 width, u32 height, u32 pitch, bool alpha) +/* + * Describe a qualified client framebuffer at its SID0 DVA, @dst_y rows down + * the panel; no CPU access. + */ +static inline int dcp_m4_direct_frame_at(struct dcp_m4_frame *frame, u64 dva, u64 mapped, + u32 width, u32 height, u32 pitch, bool alpha, + u32 dst_y) { *frame = (struct dcp_m4_frame) { .dva = dva, .backing_size = mapped, .width = width, .height = height, .stride = pitch, .format = alpha ? DCP_M4_ARGB8888 : DCP_M4_XRGB8888, + .dst_y = dst_y, }; if (dcp_m4_direct_extent(dva, mapped, (u64)pitch * height)) return -ERANGE; return dcp_m4_frame_check(frame); } +/* A full-panel client framebuffer. */ +static inline int dcp_m4_direct_frame(struct dcp_m4_frame *frame, u64 dva, u64 mapped, + u32 width, u32 height, u32 pitch, bool alpha) +{ + return dcp_m4_direct_frame_at(frame, dva, mapped, width, height, pitch, alpha, 0); +} + /* Exact single-layer fixture, not an ABI for tiled or compressed surfaces. */ static inline void dcp_m4_surface_encode(u8 *surface, const struct dcp_m4_frame *frame) { @@ -143,6 +161,7 @@ static inline int dcp_m4_frame_check_ext(const struct dcp_m4_frame *frame) u64 size = (u64)frame->stride * frame->height; if (!frame->width || !frame->height || frame->width > 3840 || frame->height > 2160 || + frame->dst_y || frame->stride < frame->width * 4 || frame->stride % 64 || !size || size > 0xffffffffULL || frame->backing_size < size || !frame->dva || frame->dva % 0x4000 || frame->dva >= (1ULL << 42) || @@ -235,6 +254,8 @@ static inline int dcp_m4_swap_encode_on(void *output, size_t length, u32 swap_id put_unaligned_le32(1, data + 0x9c); put_unaligned_le32(frame->width, data + 0xb4); put_unaligned_le32(frame->height, data + 0xb8); + /* Destination x, y, w, h: below the notch for a notch-free frame. */ + put_unaligned_le32(frame->dst_y, data + 0x110); put_unaligned_le32(frame->width, data + 0x114); put_unaligned_le32(frame->height, data + 0x118); dcp_m4_surface_encode(data + dcp_m4_pf->swap_surface, frame); diff --git a/drivers/gpu/drm/apple/dcp-notch.h b/drivers/gpu/drm/apple/dcp-notch.h new file mode 100644 index 0000000000000..9b516ed90fc34 --- /dev/null +++ b/drivers/gpu/drm/apple/dcp-notch.h @@ -0,0 +1,122 @@ +/* SPDX-License-Identifier: GPL-2.0-only OR MIT */ +/* + * Runtime notch geometry of a built-in panel. + * + * A panel with a camera housing has apple,notch-height rows at its top that + * are only partly visible. The panel always runs its native timing; what + * changes is how much of it the OS draws on: + * + * - full: the mode covers the whole panel, notch rows included; + * - notch-free: the mode leaves out the notch rows. They are folded into + * the vertical sync, so the timing (clock, totals, rate) is + * the same, and the frame is scanned out below them; the + * rows stay black. + * + * Both geometries of a timing are in the mode catalogue, so the mode a commit + * carries chooses one, and switching between the two needs no mode set on the + * panel. Which one is offered to userspace follows a policy (the boot + * loader's choice, then the "notch" connector property or the connector's + * notch sysfs attribute) and, when no DRM master owns the device, the + * console: the console never draws under the notch. + */ +#ifndef APPLE_DCP_NOTCH_H +#define APPLE_DCP_NOTCH_H + +#ifndef DCP_NOTCH_HOST +#include +#include +#endif + +/* Values of the "notch" connector property. */ +enum dcp_notch_policy { + DCP_NOTCH_HIDDEN = 0, + DCP_NOTCH_SHOWN = 1, +}; + +/* + * Turn the full-panel @mode into its notch-free twin: @rows fewer active + * rows, folded into the vertical sync pulse. Returns false if the mode has + * no room for it. + */ +static inline bool dcp_notch_free_mode(struct drm_display_mode *mode, u32 rows) +{ + if (!rows || mode->vdisplay <= (int)rows || mode->vsync_start < mode->vdisplay) + return false; + mode->vdisplay -= rows; + mode->vsync_start -= rows; + return true; +} + +/* + * True if @free is the notch-free twin of the full-panel mode @full. DCP + * timings carry no skew or scan doubling, so those are not compared. + */ +static inline bool dcp_notch_twin_of(const struct drm_display_mode *full, + const struct drm_display_mode *free, u32 rows) +{ + return rows && full->clock == free->clock && + full->hdisplay == free->hdisplay && + full->hsync_start == free->hsync_start && + full->hsync_end == free->hsync_end && + full->htotal == free->htotal && + full->vdisplay == free->vdisplay + (int)rows && + full->vsync_start == free->vsync_start + (int)rows && + full->vsync_end == free->vsync_end && + full->vtotal == free->vtotal && + full->flags == free->flags; +} + +/* True if @a and @b are the two geometries of one timing (either order). */ +static inline bool dcp_notch_twins(const struct drm_display_mode *a, + const struct drm_display_mode *b, u32 rows) +{ + return dcp_notch_twin_of(a, b, rows) || dcp_notch_twin_of(b, a, rows); +} + +/* + * Rows to scan a frame of @mode out below: the notch rows for a notch-free + * mode of a panel @panel_rows high, 0 for a full one. + */ +static inline u32 dcp_notch_offset(const struct drm_display_mode *mode, + u32 panel_rows, u32 rows) +{ + return rows && panel_rows > rows && + mode->vdisplay == (int)(panel_rows - rows) ? rows : 0; +} + +/* + * The geometry userspace and the console are offered: the policy while a + * DRM master (a compositor, a boot splash) owns the device, notch-free + * otherwise, so that the text console never draws under the notch. + */ +static inline enum dcp_notch_policy +dcp_notch_effective(enum dcp_notch_policy policy, bool owned) +{ + return owned ? policy : DCP_NOTCH_HIDDEN; +} + +/* + * Whether a catalogue mode is offered, and as preferred: the modes of the + * effective geometry, so that a compositor follows a change of policy, and + * the notch-free ones also to a client that cannot take the full panel + * (@full_fits false: the console, whose surface is notch-free, re-probing + * while a compositor owns the device). The firmware's preferred timing + * stays preferred among what is offered. + */ +static inline bool dcp_notch_offer(bool notch_free, enum dcp_notch_policy effective, + bool full_fits, bool *preferred) +{ + bool offered = notch_free ? effective == DCP_NOTCH_HIDDEN || !full_fits : + effective == DCP_NOTCH_SHOWN && full_fits; + + *preferred = *preferred && offered; + return offered; +} + +/* A probe limited to @max_y rows (0: none) can take the @panel_rows panel. */ +static inline bool dcp_notch_full_fits(u32 max_y, u32 panel_rows) +{ + return !max_y || !panel_rows || max_y >= panel_rows; +} + +#endif diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index b16995083020d..5206de4057ead 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -374,7 +374,7 @@ bool dcp_h17p_external_ready(struct device_node *np) static bool show_notch; module_param(show_notch, bool, 0644); -MODULE_PARM_DESC(show_notch, "Use the full display height and show the notch (also when /chosen/asahi,show-notch is \"1\")"); +MODULE_PARM_DESC(show_notch, "Start with the notch shown (default: the boot loader's choice, /chosen/asahi,show-notch; it can be changed at run time)"); /* * DP/HDMI audio of external displays, on by default as on macOS: a display @@ -2020,7 +2020,10 @@ int dcp_crtc_atomic_check(struct drm_crtc *crtc, struct drm_atomic_commit *commi if (!(crtc_state->plane_mask & drm_plane_mask(crtc->primary))) return -EINVAL; ret = iomfb_m4_get_mode(dcp, &mode); - return ret ? ret : drm_mode_equal(&crtc_state->mode, &mode) ? 0 : -EINVAL; + if (ret) + return ret; + /* The panel's timing, full or notch-free (dcp-notch.h). */ + return dcp_notch_mode_known(dcp, &crtc_state->mode) ? 0 : -EINVAL; } if (dcp->fw_compat == DCP_FIRMWARE_V_26_6) return iomfb_v26_6_atomic_check(dcp, crtc, commit); @@ -6541,14 +6544,22 @@ static int dcp_comp_bind_pipe(struct device *dev, struct device *main, void *dat dev_info(dev, "DCP index:%u dptx target phy: %u dptx die: %u\n", dcp->index, dcp->dptx_phy, dcp->dptx_die); - if (!show_notch && !boot_show_notch()) - ret = of_property_read_u32(dev->of_node, "apple,notch-height", - &dcp->notch_height); - - if (dcp->notch_height > MAX_NOTCH_HEIGHT) - dcp->notch_height = MAX_NOTCH_HEIGHT; - if (dcp->notch_height > 0) - dev_info(dev, "Detected display with notch of %u pixel\n", dcp->notch_height); + /* + * The notch rows are a fact of the panel; whether they are drawn on is + * the boot loader's choice first, then the user's, at run time (see + * dcp-notch.h). + */ + of_property_read_u32(dev->of_node, "apple,notch-height", &dcp->notch_rows); + dcp->notch_rows = min_t(u32, dcp->notch_rows, MAX_NOTCH_HEIGHT); + dcp->notch_policy = show_notch || boot_show_notch() ? DCP_NOTCH_SHOWN : + DCP_NOTCH_HIDDEN; + if (!dcp_notch_dynamic(dcp) && dcp->notch_policy == DCP_NOTCH_HIDDEN) + dcp->notch_height = dcp->notch_rows; + if (dcp->notch_rows) + dev_info(dev, "Detected display with notch of %u pixel (%s%s)\n", + dcp->notch_rows, + dcp->notch_policy == DCP_NOTCH_SHOWN ? "shown" : "hidden", + dcp_notch_dynamic(dcp) ? "" : " for this boot"); /* initialize brightness scale to a sensible default to avoid divide by 0*/ dcp->brightness.scale = 65536; diff --git a/drivers/gpu/drm/apple/dcp.h b/drivers/gpu/drm/apple/dcp.h index f1d0f49026d60..081cb89f5701a 100644 --- a/drivers/gpu/drm/apple/dcp.h +++ b/drivers/gpu/drm/apple/dcp.h @@ -206,4 +206,6 @@ int dcp_peer_stop_26_6(struct apple_dcp *dcp); void dcp_peer_release_26_6(struct apple_dcp *dcp); void dcp_peer_bound_26_6(struct apple_dcp *dcp); +bool dcp_notch_mode_known(struct apple_dcp *dcp, const struct drm_display_mode *mode); + #endif diff --git a/drivers/gpu/drm/apple/iomfb.c b/drivers/gpu/drm/apple/iomfb.c index 38282c45ba88f..94070a9a57a35 100644 --- a/drivers/gpu/drm/apple/iomfb.c +++ b/drivers/gpu/drm/apple/iomfb.c @@ -2382,6 +2382,54 @@ struct dcp_display_mode *dcp_modes_dup(struct apple_dcp *dcp, return modes; } +/* Notch-free twins in a catalogue; dcp_notch_add_twins() puts them last. */ +static unsigned int dcp_notch_twin_count(const struct dcp_display_mode *modes, + unsigned int count) +{ + unsigned int i, twins = 0; + + for (i = 0; modes && i < count; i++) + twins += modes[i].notch_free; + return twins; +} + +/* + * Give every full-panel timing of a panel with @rows notch rows its + * notch-free twin (dcp-notch.h), after the full ones, and report the full + * panel's active rows in @panel_rows. The automatic 180 Hz exception is an + * external display's and gets none. + */ +static int dcp_notch_add_twins(struct dcp_display_mode **modes, unsigned int *count, + u32 rows, u32 *panel_rows) +{ + struct dcp_display_mode *all; + unsigned int i, n = *count, twins = 0; + + *panel_rows = 0; + if (!rows || !n) + return 0; + all = krealloc_array(*modes, 2 * n, sizeof(**modes), GFP_KERNEL | __GFP_NOWARN); + if (!all) + return -ENOMEM; + *modes = all; + for (i = 0; i < n; i++) { + struct dcp_display_mode *twin = &all[n + twins]; + + if (all[i].notch_free || all[i].automatic_rgb8_quirk) + continue; + if (all[i].mode.vdisplay > *panel_rows) + *panel_rows = all[i].mode.vdisplay; + *twin = all[i]; + if (!dcp_notch_free_mode(&twin->mode, rows)) + continue; + twin->notch_free = true; + drm_mode_set_name(&twin->mode); + twins++; + } + *count = n + twins; + return 0; +} + /* * A display came to @dcp from another pipeline without being unplugged: * offer the modes it had there until the firmware here describes it. @@ -2406,6 +2454,7 @@ void dcp_modes_adopt(struct apple_dcp *dcp, struct apple_connector *connector, spin_lock_irqsave(&dcp->metadata.lock, flags); dcp->modes = modes; dcp->nr_modes = count; + dcp->nr_notch_twins = dcp_notch_twin_count(modes, count); spin_unlock_irqrestore(&dcp->metadata.lock, flags); dcp->modes_admitted = true; dcp->modes_provisional = true; @@ -2435,7 +2484,7 @@ int dcp_modes_replace(struct apple_dcp *dcp, struct dcp_parse_ctx *ctx, unsigned int nr_modes = 0, i; unsigned long flags; bool provisional; - u32 entries = 0; + u32 entries = 0, panel_rows = 0; int ret = 0; /* A stale transfer is refused before it is parsed, as it is published. */ @@ -2481,6 +2530,16 @@ int dcp_modes_replace(struct apple_dcp *dcp, struct dcp_parse_ctx *ctx, kfree(modes); return -EINVAL; } else { + /* A notched panel offers both geometries of its timings. */ + if (dcp->fixed_connector_type == DRM_MODE_CONNECTOR_eDP && + dcp->notch_rows && dcp_notch_dynamic(dcp)) { + ret = dcp_notch_add_twins(&modes, &nr_modes, dcp->notch_rows, + &panel_rows); + if (ret) { + kfree(modes); + return ret; + } + } for (i = 0; i < nr_modes; i++) if (modes[i].automatic_rgb8_quirk) { modes[i].unsafe_rgb8_ticket = rate_ticket; @@ -2505,6 +2564,9 @@ int dcp_modes_replace(struct apple_dcp *dcp, struct dcp_parse_ctx *ctx, modes[i].automatic_catalog_sequence = dcp->rate_proof.catalog_sequence; dcp->modes = modes; dcp->nr_modes = nr_modes; + dcp->nr_notch_twins = dcp_notch_twin_count(modes, nr_modes); + if (panel_rows) + WRITE_ONCE(dcp->notch_panel_rows, panel_rows); /* Only a complete receipt for a current cable is that cable's catalogue. */ dcp->metadata.catalog_ticket = rate_ticket; dcp->metadata.catalog_ticket.associated &= nr_modes > 0; @@ -2638,6 +2700,7 @@ void dcp_modes_release(void *data) kfree(dcp->modes); dcp->modes = NULL; dcp->nr_modes = 0; + dcp->nr_notch_twins = 0; } /* Under mode_config.mutex, in get_modes: the identity of the EDID being published. */ static void dcp_note_edid(struct apple_connector *connector, const struct drm_edid *drm_edid) @@ -2717,6 +2780,8 @@ int dcp_get_modes(struct drm_connector *connector) bool vrr_capable = false; bool physical_edid; bool pending_180hz = false, published_180hz = false; + enum dcp_notch_policy effective; + bool full_fits; u64 edid_generation = 0; u64 service_epoch = 0; unsigned int i; @@ -2733,19 +2798,48 @@ int dcp_get_modes(struct drm_connector *connector) } dcp = platform_get_drvdata(pdev); if (iomfb_is_m4(dcp)) { - struct drm_display_mode fixed; + struct drm_display_mode fixed, free; + bool preferred; + int n = 0; if (iomfb_m4_get_mode(dcp, &fixed)) return 0; - mode = drm_mode_duplicate(dev, &fixed); - if (!mode) - return 0; - drm_mode_probed_add(connector, mode); + /* Its panel timing, in both notch geometries (dcp-notch.h). */ + free = fixed; + if (dcp->notch_rows && dcp_notch_free_mode(&free, dcp->notch_rows)) { + WRITE_ONCE(dcp->notch_panel_rows, fixed.vdisplay); + drm_mode_set_name(&free); + effective = dcp_notch_effective(READ_ONCE(dcp->notch_policy), + READ_ONCE(dcp->notch_owned)); + full_fits = dcp_notch_full_fits(apple_connector->probe_max_y, + fixed.vdisplay); + preferred = true; + if (dcp_notch_offer(false, effective, full_fits, &preferred)) { + mode = drm_mode_duplicate(dev, &fixed); + if (mode) { + drm_mode_probed_add(connector, mode); + n++; + } + } + preferred = true; + mode = NULL; + if (dcp_notch_offer(true, effective, full_fits, &preferred)) { + if (!preferred) + free.type &= ~DRM_MODE_TYPE_PREFERRED; + mode = drm_mode_duplicate(dev, &free); + } + } else { + mode = drm_mode_duplicate(dev, &fixed); + } + if (mode) { + drm_mode_probed_add(connector, mode); + n++; + } of_property_read_u32(dcp->dev->of_node, "apple,panel-width-mm", &connector->display_info.width_mm); of_property_read_u32(dcp->dev->of_node, "apple,panel-height-mm", &connector->display_info.height_mm); - return 1; + return n; } modes = dcp_modes_snapshot(dcp, apple_connector, &nr_modes); @@ -2884,7 +2978,10 @@ int dcp_get_modes(struct drm_connector *connector) u32 defaults = 0; bool panel = dcp->panel_identity && dcp_has_panel(dcp); const struct drm_edid *derived = nr_modes ? - (panel ? dcp_panel_edid_snapshot(dcp, modes, nr_modes, &generation) : + /* The panel's EDID lists its timings, not their notch-free twins. */ + (panel ? dcp_panel_edid_snapshot(dcp, modes, nr_modes - + dcp_notch_twin_count(modes, nr_modes), + &generation) : dcp_firmware_edid(dcp, &generation, &defaults)) : ERR_PTR(-ENODATA); if (!IS_ERR(derived)) { @@ -2931,13 +3028,24 @@ int dcp_get_modes(struct drm_connector *connector) modes = dcp_modes_snapshot(dcp, apple_connector, &nr_modes); } /* Publish after a possibly delayed raw read, under its physical generation. */ + effective = dcp_notch_effective(READ_ONCE(dcp->notch_policy), + READ_ONCE(dcp->notch_owned)); + full_fits = dcp_notch_full_fits(apple_connector->probe_max_y, + READ_ONCE(dcp->notch_panel_rows)); for (i = 0; i < nr_modes; ++i) { + bool preferred = modes[i].mode.type & DRM_MODE_TYPE_PREFERRED; + + if (dcp->notch_rows && dcp_notch_dynamic(dcp) && + !dcp_notch_offer(modes[i].notch_free, effective, full_fits, &preferred)) + continue; mode = drm_mode_duplicate(dev, &modes[i].mode); if (!mode) { dev_err(dev->dev, "Failed to duplicate display mode\n"); published = 0; goto modes_done; } + if (!preferred) + mode->type &= ~DRM_MODE_TYPE_PREFERRED; pending_180hz |= modes[i].automatic_rgb8_quirk && dcp_180hz_pending(dcp, &modes[i]); if (!dcp_publish_mode(dcp, connector, &modes[i], mode)) @@ -3443,6 +3551,19 @@ int dcp_crtc_check_hdr(struct apple_dcp *dcp, struct drm_crtc *crtc, } } +/* @mode is one of the panel's own, in either notch geometry (dcp-notch.h). */ +bool dcp_notch_mode_known(struct apple_dcp *dcp, const struct drm_display_mode *mode) +{ + struct drm_display_mode fixed; + + if (!iomfb_is_m4(dcp)) + return lookup_mode(dcp, mode, NULL); + if (iomfb_m4_get_mode(dcp, &fixed)) + return false; + return drm_mode_match(mode, &fixed, DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_CLOCK) || + dcp_notch_twin_of(&fixed, mode, dcp->notch_rows); +} + /* The user may own drm_display_mode, so we need to search for our copy */ bool lookup_mode(struct apple_dcp *dcp, const struct drm_display_mode *mode, struct dcp_display_mode *out) @@ -4327,9 +4448,16 @@ void dcp_flush(struct drm_crtc *crtc, struct drm_atomic_commit *commit) ret = iomfb_m4_error(dcp); /* A CRTC-only commit publishes no new framebuffer. */ if (!ret && plane) { + /* A notch-free mode is scanned out below the notch rows. */ + u32 dst_y = dcp_notch_offset(&new->mode, + READ_ONCE(dcp->notch_panel_rows), + dcp->notch_rows); + obj = plane->fb ? drm_fb_dma_get_gem_obj(plane->fb, 0) : NULL; - ret = obj ? iomfb_m4_present(dcp, plane->fb, obj->dma_addr, - obj->base.size) : -EINVAL; + ret = obj ? iomfb_m4_present_at(dcp, plane->fb, obj->dma_addr, + obj->base.size, dst_y) : -EINVAL; + if (!ret) + WRITE_ONCE(dcp->notch_scanout_y, dst_y); } if (ret) dcp_drm_crtc_error(to_apple_crtc(crtc), new, -EIO); diff --git a/drivers/gpu/drm/apple/iomfb_m4.c b/drivers/gpu/drm/apple/iomfb_m4.c index 42caa27a508a0..a7c1845677f15 100644 --- a/drivers/gpu/drm/apple/iomfb_m4.c +++ b/drivers/gpu/drm/apple/iomfb_m4.c @@ -2208,7 +2208,7 @@ static int dcp_m4_runtime_swap_full(struct dcp_m4_runtime *r, bool primary, !r->power_done || !r->background_done || !dcp->scanout)) return -EINVAL; if ((primary && frame && (check(frame) || frame->width != width || - frame->height != height)) || + frame->height + frame->dst_y != height)) || (upper && dcp_m4_upper_check_on(upper, width, height))) return -EINVAL; /* @@ -3564,8 +3564,9 @@ static int iomfb_m4_swap(struct iomfb_m4 *dcp, const struct dcp_m4_frame *frame) return ret; } -int iomfb_m4_present(struct apple_dcp *owner, struct drm_framebuffer *fb, - dma_addr_t dva, size_t mapped) +/* 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) { struct iomfb_m4 *dcp = owner->v26_6; struct drm_framebuffer *retire = NULL; @@ -3577,8 +3578,9 @@ int iomfb_m4_present(struct apple_dcp *owner, struct drm_framebuffer *fb, (fb->format->format != DRM_FORMAT_XRGB8888 && fb->format->format != DRM_FORMAT_ARGB8888)) return -EINVAL; - ret = dcp_m4_direct_frame(&frame, dva, mapped, fb->width, fb->height, - fb->pitches[0], fb->format->format == DRM_FORMAT_ARGB8888); + ret = dcp_m4_direct_frame_at(&frame, dva, mapped, fb->width, fb->height, + fb->pitches[0], fb->format->format == DRM_FORMAT_ARGB8888, + dst_y); if (ret) return ret; /* A power-down not yet started is not needed; one under way finishes first. */ @@ -3626,6 +3628,12 @@ int iomfb_m4_present(struct apple_dcp *owner, struct drm_framebuffer *fb, return ret; } +int iomfb_m4_present(struct apple_dcp *owner, struct drm_framebuffer *fb, + dma_addr_t dva, size_t mapped) +{ + return iomfb_m4_present_at(owner, fb, dva, mapped, 0); +} + int iomfb_m4_blank(struct apple_dcp *owner) { struct iomfb_m4 *dcp = owner->v26_6; diff --git a/drivers/gpu/drm/apple/iomfb_m4.h b/drivers/gpu/drm/apple/iomfb_m4.h index 6e09d07e0c899..785491a8308eb 100644 --- a/drivers/gpu/drm/apple/iomfb_m4.h +++ b/drivers/gpu/drm/apple/iomfb_m4.h @@ -85,6 +85,8 @@ bool iomfb_m4_ext_stopped(struct apple_dcp *dcp); /* The caller has waited for the producer fence before publishing the DMA GEM. */ int iomfb_m4_present(struct apple_dcp *dcp, struct drm_framebuffer *fb, dma_addr_t dva, size_t mapped); +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); int iomfb_m4_suspend(struct apple_dcp *dcp); int iomfb_m4_resume(struct apple_dcp *dcp); @@ -170,6 +172,12 @@ static inline int iomfb_m4_present(struct apple_dcp *dcp, struct drm_framebuffer { return -ENODEV; } + +static inline int iomfb_m4_present_at(struct apple_dcp *dcp, struct drm_framebuffer *fb, + dma_addr_t dva, size_t mapped, u32 dst_y) +{ + return -ENODEV; +} static inline int iomfb_m4_blank(struct apple_dcp *dcp) { 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; } diff --git a/drivers/gpu/drm/apple/iomfb_m4_present.h b/drivers/gpu/drm/apple/iomfb_m4_present.h index 6f51b936137b9..fc1ee3eba8cee 100644 --- a/drivers/gpu/drm/apple/iomfb_m4_present.h +++ b/drivers/gpu/drm/apple/iomfb_m4_present.h @@ -11,6 +11,11 @@ #include "dcp-m4-frame.h" +/* + * A frame of the @width x @height mode: the panel's, or its notch-free twin + * (dcp-notch.h), which dcp_crtc_atomic_check() admits and which starts its + * notch rows down the panel. + */ static inline int iomfb_m4_plane_frame(const struct drm_plane_state *state, u32 width, u32 height, struct dcp_m4_frame *frame) @@ -29,9 +34,11 @@ static inline int iomfb_m4_plane_frame(const struct drm_plane_state *state, obj = drm_fb_dma_get_gem_obj(fb, 0); if (!obj) return -EINVAL; - return dcp_m4_direct_frame(frame, obj->dma_addr, obj->base.size, - fb->width, fb->height, fb->pitches[0], - fb->format->format == DRM_FORMAT_ARGB8888); + return dcp_m4_direct_frame_at(frame, obj->dma_addr, obj->base.size, + fb->width, fb->height, fb->pitches[0], + fb->format->format == DRM_FORMAT_ARGB8888, + height < DCP_M4_PANEL_HEIGHT ? + DCP_M4_PANEL_HEIGHT - height : 0); } #endif diff --git a/drivers/gpu/drm/apple/iomfb_template.c b/drivers/gpu/drm/apple/iomfb_template.c index 0e9064dcb289b..ea485c4de7fc6 100644 --- a/drivers/gpu/drm/apple/iomfb_template.c +++ b/drivers/gpu/drm/apple/iomfb_template.c @@ -540,7 +540,7 @@ static bool __maybe_unused DCP_FW_NAME(dcp_fw27_keep_panel_mode)(struct apple_dc if (policy == 0 || !dcp->main_display || !dcp_has_panel(dcp)) return false; - return policy > 0 || READ_ONCE(dcp->nr_modes) == 1; + return policy > 0 || dcp_nr_timings(dcp) == 1; #else return false; #endif @@ -4006,7 +4006,7 @@ int DCP_FW_NAME(iomfb_modeset)(struct apple_dcp *dcp, * single fixed timing it advertises, already matched above. */ if (dcp_has_panel(dcp) && dcp->main_display && - READ_ONCE(dcp->nr_modes) == 1 && !mode->vrr) { + dcp_nr_timings(dcp) == 1 && !mode->vrr) { dcp->desktop->mode_live = true; return 0; } @@ -4305,7 +4305,7 @@ int DCP_FW_NAME(iomfb_modeset)(struct apple_dcp *dcp, dcp->hw.iomfb_method_profile != DCP_IOMFB_METHODS_H17P_EXTERNAL) { dev_info(dcp->dev, "inheriting the bootloader's display mode (%u fixed timing(s))\n", - READ_ONCE(dcp->nr_modes)); + dcp_nr_timings(dcp)); complete_set_digital_out_mode(dcp, NULL, cookie); } else #if (DCP_FW_H17(DCP_FW_VER) && DCP_FW_VER >= DCP_FW_VERSION(27, 0, 0)) @@ -4452,6 +4452,7 @@ void DCP_FW_NAME(iomfb_flush)(struct apple_dcp *dcp, struct drm_crtc *crtc, stru struct DCP_FW_NAME(dcp_swap_submit_req) *req = &DCP_FW_SWAP(dcp); int plane_idx, l; int has_surface = 0; + u32 notch_y; #if !DCP_FW_DESKTOP_26(DCP_FW_VER) bool update_brightness; @@ -4511,8 +4512,12 @@ void DCP_FW_NAME(iomfb_flush)(struct apple_dcp *dcp, struct drm_crtc *crtc, stru req->swap.surf_ids[apl_plane->iomfb_surf] = plane->base.id; #endif - if (dcp->notch_height > 0) - req->swap.dst_rect[l].y += dcp->notch_height; + /* A notch-free mode is scanned out below the notch rows. */ + notch_y = dcp_notch_offset(&crtc_state->mode, + READ_ONCE(dcp->notch_panel_rows), + dcp->notch_rows); + WRITE_ONCE(dcp->notch_scanout_y, notch_y); + req->swap.dst_rect[l].y += dcp->notch_height + notch_y; req->surf_iova[l] = apple_state->iova; req->surf[l].base = apple_state->surf; diff --git a/drivers/gpu/drm/apple/parser.h b/drivers/gpu/drm/apple/parser.h index f39ec76b9bb0b..a2020ba65de4b 100644 --- a/drivers/gpu/drm/apple/parser.h +++ b/drivers/gpu/drm/apple/parser.h @@ -177,6 +177,8 @@ struct dcp_display_mode { u64 automatic_catalog_sequence; bool automatic_service_pending; bool has_bootstrap; + /* The notch-free twin of a full-panel timing (dcp-notch.h). */ + bool notch_free; /* Immutable receipt provenance; never retag a cached exception. */ struct dcp_metadata_ticket unsafe_rgb8_ticket; u64 unsafe_rgb8_service_epoch; @@ -232,8 +234,7 @@ int dcp_modes_replace(struct apple_dcp *dcp, struct dcp_parse_ctx *handle, int parse_array_count(const struct dcp_parse_ctx *handle, u32 *count); -/* Caller serializes readers against replacement. */ -int replace_modes(struct dcp_parse_ctx *handle, +/* Caller serializes readers against replacement. */int replace_modes(struct dcp_parse_ctx *handle, struct dcp_display_mode **modes, unsigned int *count, int width_mm, int height_mm, unsigned int notch_height, bool internal); diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/display.py b/tools/testing/selftests/drivers/gpu/apple-dcp/display.py index dc3a99fcaf6ca..74d53125be973 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/display.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/display.py @@ -362,6 +362,110 @@ def case(elements, expected, ranges=None, desktop=True): return prefix + parser + '\n'.join(blobs) + '\nint main(void){' + '\n'.join(checks) + 'return 0;}' +def notch(root): + """Both notch geometries of a panel timing (dcp-notch.h), through the + production parser and catalogue code: the notch-free twin is exactly the + mode the boot-time hidden notch gave, and offer, offset and ownership + follow the policy.""" + f = rate.parser_fixture(root) + iomfb = (root / 'drivers/gpu/drm/apple/iomfb.c').read_text() + twins = (block(iomfb, 'static unsigned int dcp_notch_twin_count(') + '\n' + + block(iomfb, 'static int dcp_notch_add_twins(')) + prefix = (f['prefix'] + f['epoch'] + f['metadata'] + f['header']).replace( + 'static inline ', 'static inline __attribute__((unused)) ') + # The J615 panel timing as its DCP reports it (2880x1864 at 60 Hz, from our + # own boot log), with the 64 rows of its apple,notch-height. + m = copy.deepcopy(f['timing_fixture'][0]) + m['HorizontalAttributes'].update(Active=2880, FrontPorch=8, SyncWidth=32, Total=2960) + m['VerticalAttributes'].update(Active=1864, FrontPorch=47, SyncWidth=8, Total=1961) + raw = bytearray(struct.pack('