diff --git a/Documentation/gpu/apple-dcp-notch.rst b/Documentation/gpu/apple-dcp-notch.rst index b24d8ea2a2c5b..b6dba9a8f7690 100644 --- a/Documentation/gpu/apple-dcp-notch.rst +++ b/Documentation/gpu/apple-dcp-notch.rst @@ -59,3 +59,34 @@ tree gives it, otherwise the full height scaled by the rows. The standalone firmware 14.7 and 26.6 pipes build their one mode from the boot framebuffer and keep the boot loader's geometry for the boot. + +The touch screen +================ + +A touch screen on the panel (``hid-apple-mtp-kiwi``) reports positions over +the whole panel, notch rows included, and its ABS ranges never change. The +display driver publishes what it scans out with every frame it swaps in: +the panel's active rows and the rows above the picture +(``include/linux/soc/apple/panel-notch.h``, built in, so neither driver +depends on the other). While the picture is notch-free, the touch driver +maps the panel below the notch onto the whole ``ABS_MT_POSITION_Y`` range: +the notch band's lower edge reports 0 and the panel's bottom edge the +maximum, so a compositor that maps the range onto its output needs no +notch support. The geometry is the one scanned out, so it follows the +property, the sysfs attribute, the boot default and the console alike. + +* A contact in the notch band is not reported until it first reaches the + picture; a swipe down from the glass edge then starts at the picture's + top edge, and a tap on the band is never seen. +* A reported contact that slides into the band stays on the picture's top + edge. +* When the geometry changes with fingers down, every contact is lifted for + one frame and touches down again under the new geometry, as a new + contact. Userspace sees a release at the finger's position. + +Without the display driver, or before its first frame, nothing is +published and positions cover the whole panel. The standalone firmware +14.7 and 26.6 pipes, which keep the boot loader's geometry for the boot, +publish nothing either. ``ABS_MT_POSITION_Y``'s +resolution stays the whole panel's; while the notch is hidden one unit is +slightly shorter on the glass. diff --git a/MAINTAINERS b/MAINTAINERS index ebbb5aadd1cc2..3300147485b13 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2061,6 +2061,8 @@ F: Documentation/devicetree/bindings/display/apple,dcp-typec-routes.yaml F: Documentation/gpu/apple-dcp-*.rst F: drivers/gpu/drm/apple/ F: drivers/gpu/drm/apple/dcp-fabric* +F: drivers/soc/apple/panel-notch* +F: include/linux/soc/apple/panel-notch.h F: tools/asahi/afk-compact-start-tests.py F: tools/asahi/dcp-tunnel-prepare-tests.py F: tools/testing/selftests/drivers/gpu/apple-afkv2/ diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index f719801e5a998..05b408e7dcfc3 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -6,6 +6,7 @@ #include "dcp-indicator.h" #include "dcp-notch.h" +#include #include #include #include @@ -1131,6 +1132,8 @@ struct apple_dcp { bool notch_owned; /* Panel rows above the last frame swapped in: the notch rows, or 0. */ u32 notch_scanout_y; + /* The same for the swap being submitted, until the firmware takes it. */ + u32 notch_swap_y; /* The notch-free geometry is what a compositor is offered now. */ bool notch_free_offered; @@ -1442,6 +1445,18 @@ static inline bool dcp_notch_dynamic(const struct apple_dcp *dcp) dcp->fw_compat != DCP_FIRMWARE_V_26_6; } +/* + * A frame was swapped in @rows below the notch rows' top (dcp-notch.h): keep + * it for debugfs and publish the panel's picture to the touch screen + * (panel-notch.h), which maps its whole-panel coordinates onto it. + */ +static inline void dcp_notch_scanned_out(struct apple_dcp *dcp, u32 rows) +{ + WRITE_ONCE(dcp->notch_scanout_y, rows); + if (dcp->notch_rows) + apple_panel_notch_publish(READ_ONCE(dcp->notch_panel_rows), rows); +} + 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.c b/drivers/gpu/drm/apple/dcp.c index a4f5310176b43..b717bb6fff5a9 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -7837,6 +7837,9 @@ VISIBLE_IF_KUNIT void dcp_comp_unbind(struct device *dev, struct device *main, v if (!dcp) return; + /* The touch screen goes back to the whole panel (panel-notch.h). */ + if (dcp->notch_rows) + apple_panel_notch_publish(0, 0); if (IS_ENABLED(CONFIG_APPLE_SOC_SLEEP)) apple_sleep_v27_unregister(dev); /* Restore a soft-off panel while the IOMFB queue is still active. */ diff --git a/drivers/gpu/drm/apple/iomfb.c b/drivers/gpu/drm/apple/iomfb.c index 06d0cd9170f3c..1ce572d0c3aa3 100644 --- a/drivers/gpu/drm/apple/iomfb.c +++ b/drivers/gpu/drm/apple/iomfb.c @@ -4804,7 +4804,7 @@ void dcp_flush(struct drm_crtc *crtc, struct drm_atomic_commit *commit) 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); + dcp_notch_scanned_out(dcp, dst_y); } if (ret) dcp_drm_crtc_error(to_apple_crtc(crtc), new, -EIO); diff --git a/drivers/gpu/drm/apple/iomfb_template.c b/drivers/gpu/drm/apple/iomfb_template.c index 642749c0ba373..33ad3f79ed06c 100644 --- a/drivers/gpu/drm/apple/iomfb_template.c +++ b/drivers/gpu/drm/apple/iomfb_template.c @@ -3616,6 +3616,8 @@ static void dcp_swapped(struct apple_dcp *dcp, void *data, void *cookie) } return; } + /* A rejected swap above keeps the previous frame's notch geometry. */ + dcp_notch_scanned_out(dcp, READ_ONCE(dcp->notch_swap_y)); if (dcp_is_ext26(dcp) && dcp->ext26_early_complete && dcp->ext26_early_id == swap_id) { u64 received = dcp->ext26_rx_ns; @@ -4704,7 +4706,8 @@ void DCP_FW_NAME(iomfb_flush)(struct apple_dcp *dcp, struct drm_crtc *crtc, stru 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); + /* Published once the firmware takes the swap (dcp_swapped()). */ + WRITE_ONCE(dcp->notch_swap_y, notch_y); req->swap.dst_rect[l].y += dcp->notch_height + notch_y; req->surf_iova[l] = apple_state->iova; diff --git a/drivers/hid/hid-apple-mtp-kiwi.c b/drivers/hid/hid-apple-mtp-kiwi.c index e41646a140918..2fa8b37c1b741 100644 --- a/drivers/hid/hid-apple-mtp-kiwi.c +++ b/drivers/hid/hid-apple-mtp-kiwi.c @@ -30,6 +30,16 @@ * and a per-row mean is removed from the rest. The raw image has no * baseline, so the driver keeps one per cell, picks local maxima of * (baseline - raw), and centroids 3x3. + * + * The sensor covers the whole panel, notch rows included, and so do the ABS + * ranges. While the display hides the notch rows the picture is shorter + * than the panel, and a compositor maps the whole ABS range onto it: the + * driver then maps the panel below the notch onto the whole range + * (panel-notch.h). A contact in the notch band is not reported until it + * first reaches the picture (an edge swipe then starts at its top edge); + * once reported, a contact that slides into the band stays on the top edge. + * When the geometry changes, every contact lifts and touches down again + * under the new one. */ #include @@ -38,6 +48,7 @@ #include #include #include +#include #include #include @@ -92,12 +103,14 @@ struct kiwi_contact { int bx, by; /* birth position: net drift past a cell over a sane hold = phantom */ s16 b_sig; /* signal at the birth cell when born: flatness marks a stuck cell */ bool lively; /* the birth-cell signal moved more than KIWI_STILL_COUNTS */ + bool shown; /* has reached the picture (panel-notch.h): reported */ }; struct kiwi { struct input_dev *input; int size_x, size_y; int res_x, res_y; + u32 notch_band; /* ABS_Y positions hidden above the picture, 0: none */ spinlock_t lock; /* serialises kiwi_raw_event() against kiwi_input_open() */ bool have_base; int rowmean[KIWI_ROWS]; /* per-row mean of the last frame, pre-removal */ @@ -458,6 +471,7 @@ static void kiwi_centroid(struct kiwi *k, int r, int c, struct kiwi_contact *out out->size = cells; out->on = true; out->miss = 0; + out->shown = false; /* shape and pressure: weighted second moments over 5x5, cells up to the peak's level */ for (dr = -2; dr <= 2; dr++) { @@ -583,11 +597,22 @@ static void kiwi_sup_mark(struct kiwi *k, int row, int col) static void kiwi_report(struct kiwi *k) { + struct apple_panel_notch notch = apple_panel_notch_get(); struct input_dev *input = k->input; + bool relift = false; + u32 band; int j, j2; + /* a new picture: lift every contact, they touch down again next frame */ + band = apple_panel_notch_band(¬ch, k->size_y); + if (band != k->notch_band) { + k->notch_band = band; + relift = true; + } + for (j = 0; j < KIWI_MAX_SLOTS; j++) { struct kiwi_contact *c = &k->cont[j]; + bool report; int x, y; if (c->on && k->now - c->born >= KIWI_STATIC_FRAMES && !c->lively) { @@ -651,14 +676,27 @@ static void kiwi_report(struct kiwi *k) k->last_end = k->now; } input_mt_slot(input, j); - input_mt_report_slot_state(input, MT_TOOL_FINGER, c->on); - if (!c->on) + report = c->on; + if (c->on) { + bool on_picture; + u32 py; + + x = div_s64((s64)c->x * k->size_x, KIWI_COLS * KIWI_FP); + y = div_s64((s64)c->y * k->size_y, KIWI_ROWS * KIWI_FP); + /* Row 0 is the bottom edge of the panel. */ + x = clamp(x, 0, k->size_x - 1); + y = clamp(k->size_y - 1 - y, 0, k->size_y - 1); + on_picture = apple_panel_notch_map(k->notch_band, k->size_y, y, &py); + y = py; + if (relift) + c->shown = false; + else if (on_picture) + c->shown = true; + report = c->shown; + } + input_mt_report_slot_state(input, MT_TOOL_FINGER, report); + if (!report) continue; - x = div_s64((s64)c->x * k->size_x, KIWI_COLS * KIWI_FP); - y = div_s64((s64)c->y * k->size_y, KIWI_ROWS * KIWI_FP); - /* Row 0 is the bottom edge of the panel. */ - x = clamp(x, 0, k->size_x - 1); - y = clamp(k->size_y - 1 - y, 0, k->size_y - 1); input_report_abs(input, ABS_MT_POSITION_X, x); input_report_abs(input, ABS_MT_POSITION_Y, y); input_report_abs(input, ABS_MT_TOUCH_MAJOR, @@ -687,6 +725,7 @@ static void kiwi_track(struct kiwi *k, struct kiwi_contact *found, int n) int bx = k->cont[j].bx, by = k->cont[j].by; s16 bs = k->cont[j].b_sig; bool lv = k->cont[j].lively; + bool shown = k->cont[j].shown; k->cont[j] = found[i]; k->cont[j].born = b; @@ -695,6 +734,7 @@ static void kiwi_track(struct kiwi *k, struct kiwi_contact *found, int n) k->cont[j].b_sig = bs; /* liveliness is sticky: the claim copy must not wipe it */ k->cont[j].lively = lv; + k->cont[j].shown = shown; /* still the same touch */ if (!k->cont[j].lively) { int d = k->sig[(by / KIWI_FP) * KIWI_COLS + (bx / KIWI_FP)] - bs; diff --git a/drivers/soc/apple/Kconfig b/drivers/soc/apple/Kconfig index 5f211a3a52379..ab20d7fa91e95 100644 --- a/drivers/soc/apple/Kconfig +++ b/drivers/soc/apple/Kconfig @@ -12,6 +12,28 @@ config APPLE_J613_DISPLAY_SYNC Built-in arbitration between the J613 display handoff and USB PD. State survives an absent, failed or later-loaded display module. +config APPLE_PANEL_NOTCH + bool + default DRM_APPLE != n + help + Built-in record of the notch geometry the built-in panel scans + out. The display driver publishes it; drivers whose coordinates + span the whole panel, such as the touch screen, map onto the + picture with it. Without a publisher it reads as the whole panel. + +config APPLE_PANEL_NOTCH_KUNIT_TEST + tristate "KUnit tests for the Apple panel notch geometry" if !KUNIT_ALL_TESTS + depends on KUNIT + select APPLE_PANEL_NOTCH + default KUNIT_ALL_TESTS + help + Pack and unpack the panel notch record, and map a touch axis + that spans the whole panel onto the picture below a hidden notch: + the band is dropped, the edges stay the axis's edges. The tests + touch no hardware. + + If unsure, say N. + config APPLE_DBGVIEW tristate "Apple SoC read-only debug register views" depends on ARCH_APPLE || COMPILE_TEST diff --git a/drivers/soc/apple/Makefile b/drivers/soc/apple/Makefile index 216234e3aba5d..7cfc1004d2a36 100644 --- a/drivers/soc/apple/Makefile +++ b/drivers/soc/apple/Makefile @@ -4,6 +4,9 @@ obj-$(CONFIG_APPLE_MCC_BOOT_DMA) += mcc-boot-dma.o obj-$(CONFIG_APPLE_J613_DISPLAY_SYNC) += j613-display.o +obj-$(CONFIG_APPLE_PANEL_NOTCH) += panel-notch.o +obj-$(CONFIG_APPLE_PANEL_NOTCH_KUNIT_TEST) += panel-notch-test.o + obj-$(CONFIG_APPLE_DBGVIEW) += apple-dbgview.o apple-dbgview-y = dbgview.o obj-$(CONFIG_APPLE_DBGVIEW_KUNIT_TEST) += dbgview-test.o diff --git a/drivers/soc/apple/panel-notch-test.c b/drivers/soc/apple/panel-notch-test.c new file mode 100644 index 0000000000000..7f53ae1b6021e --- /dev/null +++ b/drivers/soc/apple/panel-notch-test.c @@ -0,0 +1,117 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* + * KUnit tests for the built-in panel's notch geometry (panel-notch.h): the + * record's packed form, and the translation of a whole-panel touch axis onto the + * picture below a hidden notch. + */ +#include +#include + +/* A 1986-row panel with 74 notch rows, its touch axis 1986 positions. */ +#define ROWS 1986 +#define NOTCH 74 + +/* The record's word, on a value of the test's own: the live record is the display's. */ +static void panel_notch_state(struct kunit *test) +{ + struct apple_panel_notch n; + + n = apple_panel_notch_unpack(apple_panel_notch_pack(ROWS, NOTCH)); + KUNIT_EXPECT_EQ(test, n.panel_rows, ROWS); + KUNIT_EXPECT_EQ(test, n.top, NOTCH); + + n = apple_panel_notch_unpack(apple_panel_notch_pack(ROWS, 0)); + KUNIT_EXPECT_EQ(test, n.panel_rows, ROWS); + KUNIT_EXPECT_EQ(test, n.top, 0); + + /* Withdrawn, or no picture left: nothing published. */ + KUNIT_EXPECT_EQ(test, apple_panel_notch_pack(0, NOTCH), 0); + KUNIT_EXPECT_EQ(test, apple_panel_notch_pack(ROWS, ROWS), 0); + KUNIT_EXPECT_EQ(test, apple_panel_notch_pack(ROWS, U32_MAX), 0); + n = apple_panel_notch_unpack(0); + KUNIT_EXPECT_EQ(test, n.panel_rows, 0); + KUNIT_EXPECT_EQ(test, n.top, 0); + KUNIT_EXPECT_EQ(test, apple_panel_notch_band(&n, ROWS), 0); +} + +static void panel_notch_band(struct kunit *test) +{ + struct apple_panel_notch hidden = { ROWS, NOTCH }; + struct apple_panel_notch shown = { ROWS, 0 }; + struct apple_panel_notch none = { }; + struct apple_panel_notch full = { ROWS, ROWS }; + + KUNIT_EXPECT_EQ(test, apple_panel_notch_band(&hidden, ROWS), NOTCH); + /* An axis of another size gets the band in its own positions. */ + KUNIT_EXPECT_EQ(test, apple_panel_notch_band(&hidden, ROWS / 2), NOTCH / 2); + KUNIT_EXPECT_EQ(test, apple_panel_notch_band(&hidden, 2 * ROWS), 2 * NOTCH); + KUNIT_EXPECT_EQ(test, apple_panel_notch_band(&shown, ROWS), 0); + KUNIT_EXPECT_EQ(test, apple_panel_notch_band(&none, ROWS), 0); + KUNIT_EXPECT_EQ(test, apple_panel_notch_band(&full, ROWS), 0); + KUNIT_EXPECT_EQ(test, apple_panel_notch_band(&hidden, 1), 0); +} + +static void panel_notch_map_shown(struct kunit *test) +{ + u32 y, out; + + /* No band: identity everywhere, nothing dropped. */ + for (y = 0; y < ROWS; y += 97) { + KUNIT_EXPECT_TRUE(test, apple_panel_notch_map(0, ROWS, y, &out)); + KUNIT_EXPECT_EQ(test, out, y); + } + KUNIT_EXPECT_TRUE(test, apple_panel_notch_map(0, ROWS, ROWS - 1, &out)); + KUNIT_EXPECT_EQ(test, out, ROWS - 1); +} + +static void panel_notch_map_hidden(struct kunit *test) +{ + u32 y, out, last = 0; + + /* The band is dropped and pinned to the picture's top edge. */ + KUNIT_EXPECT_FALSE(test, apple_panel_notch_map(NOTCH, ROWS, 0, &out)); + KUNIT_EXPECT_EQ(test, out, 0); + KUNIT_EXPECT_FALSE(test, apple_panel_notch_map(NOTCH, ROWS, NOTCH - 1, &out)); + KUNIT_EXPECT_EQ(test, out, 0); + + /* The picture's edges are the axis's edges. */ + KUNIT_EXPECT_TRUE(test, apple_panel_notch_map(NOTCH, ROWS, NOTCH, &out)); + KUNIT_EXPECT_EQ(test, out, 0); + KUNIT_EXPECT_TRUE(test, apple_panel_notch_map(NOTCH, ROWS, ROWS - 1, &out)); + KUNIT_EXPECT_EQ(test, out, ROWS - 1); + KUNIT_EXPECT_TRUE(test, apple_panel_notch_map(NOTCH, ROWS, ROWS + 5, &out)); + KUNIT_EXPECT_EQ(test, out, ROWS - 1); + + /* The picture's middle row is the axis's middle. */ + KUNIT_EXPECT_TRUE(test, apple_panel_notch_map(NOTCH, ROWS, + NOTCH + (ROWS - 1 - NOTCH) / 2, &out)); + KUNIT_EXPECT_EQ(test, out, (ROWS - 1) / 2); + + /* Monotonic, no gap wider than the stretch (span + 1 over span). */ + for (y = NOTCH; y < ROWS; y++) { + KUNIT_ASSERT_TRUE(test, apple_panel_notch_map(NOTCH, ROWS, y, &out)); + if (y > NOTCH) { + KUNIT_EXPECT_GE(test, out, last); + KUNIT_EXPECT_LE(test, out - last, 2); + } + last = out; + } +} + +static struct kunit_case panel_notch_cases[] = { + KUNIT_CASE(panel_notch_state), + KUNIT_CASE(panel_notch_band), + KUNIT_CASE(panel_notch_map_shown), + KUNIT_CASE(panel_notch_map_hidden), + { } +}; + +static struct kunit_suite panel_notch_suite = { + .name = "apple-panel-notch", + .test_cases = panel_notch_cases, +}; + +kunit_test_suite(panel_notch_suite); + +MODULE_DESCRIPTION("KUnit tests for the Apple panel notch geometry"); +MODULE_LICENSE("Dual MIT/GPL"); diff --git a/drivers/soc/apple/panel-notch.c b/drivers/soc/apple/panel-notch.c new file mode 100644 index 0000000000000..3ff572525801b --- /dev/null +++ b/drivers/soc/apple/panel-notch.c @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* + * The built-in panel's scanned-out notch geometry (panel-notch.h), built in + * so that the display driver and its readers need not load in any order or + * at all: a reader without a publisher sees the whole panel. + */ +#include +#include +#include + +/* apple_panel_notch_pack(): one state, written and read whole. */ +static atomic64_t apple_panel_notch_state = ATOMIC64_INIT(0); + +/** + * apple_panel_notch_publish - record what the built-in panel scans out + * @panel_rows: active rows of the whole panel; 0 withdraws the geometry + * @top: panel rows above the picture, 0 for a picture on the whole panel + * + * A @top that leaves no picture withdraws the geometry. Safe in any context. + */ +void apple_panel_notch_publish(u32 panel_rows, u32 top) +{ + atomic64_set(&apple_panel_notch_state, apple_panel_notch_pack(panel_rows, top)); +} +EXPORT_SYMBOL_GPL(apple_panel_notch_publish); + +/** + * apple_panel_notch_get - the last published geometry + * + * Return: the geometry, all zero if none is published. Safe in any context. + */ +struct apple_panel_notch apple_panel_notch_get(void) +{ + return apple_panel_notch_unpack(atomic64_read(&apple_panel_notch_state)); +} +EXPORT_SYMBOL_GPL(apple_panel_notch_get); diff --git a/drivers/soc/apple/panel-notch.kunitconfig b/drivers/soc/apple/panel-notch.kunitconfig new file mode 100644 index 0000000000000..bbb7a09ba678b --- /dev/null +++ b/drivers/soc/apple/panel-notch.kunitconfig @@ -0,0 +1,5 @@ +CONFIG_KUNIT=y +CONFIG_COMPILE_TEST=y +CONFIG_APPLE_PANEL_NOTCH_KUNIT_TEST=y +CONFIG_UBSAN=y +CONFIG_UBSAN_BOUNDS=y diff --git a/include/linux/soc/apple/panel-notch.h b/include/linux/soc/apple/panel-notch.h new file mode 100644 index 0000000000000..f29884692302f --- /dev/null +++ b/include/linux/soc/apple/panel-notch.h @@ -0,0 +1,100 @@ +/* SPDX-License-Identifier: GPL-2.0-only OR MIT */ +/* + * The notch geometry of the built-in panel, as the display driver scans it + * out, for drivers whose coordinates span the whole panel (the touch screen). + * + * The display driver publishes the panel's active rows and the rows above + * the picture on every frame it swaps in; a reader takes the last published + * state whenever it needs it. Nothing published (no display driver, or not + * bound yet) reads as a picture covering the whole panel. + */ +#ifndef _APPLE_PANEL_NOTCH_H +#define _APPLE_PANEL_NOTCH_H + +#include +#include +#include +#include +#include + +/** + * struct apple_panel_notch - what the built-in panel scans out + * @panel_rows: active rows of the whole panel, notch rows included; 0: unknown + * @top: panel rows above the picture: the notch rows while they are hidden, + * 0 while the picture covers the whole panel + */ +struct apple_panel_notch { + u32 panel_rows; + u32 top; +}; + +/* + * The record as one word, panel_rows high and top low, so that it is + * written and read whole. A geometry without a picture packs as nothing + * published. + */ +static inline u64 apple_panel_notch_pack(u32 panel_rows, u32 top) +{ + return panel_rows && top < panel_rows ? (u64)panel_rows << 32 | top : 0; +} + +static inline struct apple_panel_notch apple_panel_notch_unpack(u64 state) +{ + return (struct apple_panel_notch){ + .panel_rows = upper_32_bits(state), + .top = lower_32_bits(state), + }; +} + +#if IS_ENABLED(CONFIG_APPLE_PANEL_NOTCH) +void apple_panel_notch_publish(u32 panel_rows, u32 top); +struct apple_panel_notch apple_panel_notch_get(void); +#else +static inline void apple_panel_notch_publish(u32 panel_rows, u32 top) { } + +static inline struct apple_panel_notch apple_panel_notch_get(void) +{ + return (struct apple_panel_notch){ }; +} +#endif + +/* + * The hidden band at the top of an axis of @size positions that spans the + * whole panel, in those positions; 0 if the picture covers the whole panel. + */ +static inline u32 apple_panel_notch_band(const struct apple_panel_notch *n, u32 size) +{ + u32 band; + + if (!n->panel_rows || !n->top || n->top >= n->panel_rows || size < 2) + return 0; + band = div_u64((u64)n->top * size + n->panel_rows / 2, n->panel_rows); + return band < size - 1 ? band : 0; +} + +/* + * Map @y, on an axis of @size positions that spans the whole panel with 0 at + * the top, onto the picture below a hidden band of @band positions: the + * band's lower edge goes to 0 and the panel's bottom edge stays at + * @size - 1, so the whole axis covers the picture alone. Returns false for + * a @y inside the band; *@out is then 0, the picture's top edge. + */ +static inline bool apple_panel_notch_map(u32 band, u32 size, u32 y, u32 *out) +{ + u32 span; + + if (!band || band >= size - 1) { + *out = y; + return true; + } + if (y < band) { + *out = 0; + return false; + } + y = min(y, size - 1) - band; + span = size - 1 - band; + *out = div_u64((u64)y * (size - 1) + span / 2, span); + return true; +} + +#endif diff --git a/scripts/ci/apple-kunit.py b/scripts/ci/apple-kunit.py index 035ee38351a2e..3bdbd44930fc4 100755 --- a/scripts/ci/apple-kunit.py +++ b/scripts/ci/apple-kunit.py @@ -26,6 +26,8 @@ SUITES = [ ('ane-boot', 'drivers/accel/ane/boot.kunitconfig', False, ['drivers/accel/ane/', 'include/uapi/drm/ane*'], []), ('clpc', 'drivers/soc/apple/clpc.kunitconfig', False, ['drivers/soc/apple/clpc*', 'drivers/pmdomain/apple/pmc*'], []), + ('panel-notch', 'drivers/soc/apple/panel-notch.kunitconfig', False, + ['drivers/soc/apple/panel-notch*', 'include/linux/soc/apple/panel-notch.h', 'drivers/hid/hid-apple-mtp-kiwi.c'], []), ('ane-pm', 'tools/testing/selftests/drivers/ane/pm.kunitconfig', False, ['drivers/accel/ane/', 'tools/testing/selftests/drivers/ane/'], []), ('dcp-fabric', 'drivers/gpu/drm/apple/tests/.kunitconfig', False, ['drivers/gpu/drm/apple/'], []), diff --git a/tools/asahi/dcpext26-present-tests.py b/tools/asahi/dcpext26-present-tests.py index bdc3accb16580..4b4fb2b1ee8c0 100644 --- a/tools/asahi/dcpext26-present-tests.py +++ b/tools/asahi/dcpext26-present-tests.py @@ -17,6 +17,7 @@ def function(name): #include typedef uint32_t u32;typedef uint64_t u64; #define WRITE_ONCE(x,y) ((x)=(y)) +#define READ_ONCE(x) (x) #define DCP_FW_NAME(n) n #define DCP_FW_UNION(x) ((x).h17p) #define DCP_FW_SWAP(d) ((d)->swap.h17p) @@ -28,11 +29,12 @@ def function(name): #define trace_iomfb_swap_submit(...) ((void)0) struct dcp_swap_submit_resp { u32 ret; }; struct dcp_swap_start_resp { u32 swap_id,ret; }; -struct apple_dcp { bool native,crashed,ext26_blocked,ext26_early_complete;u32 ext26_early_id,started_swap_id; +struct apple_dcp { bool native,crashed,ext26_blocked,ext26_early_complete;u32 ext26_early_id,started_swap_id,notch_swap_y; u64 ext26_rx_ns,ext26_early_ns,swap_start,swap_submit_timestamp;void *dev,*crtc; struct { struct { struct {u32 swap_id;} swap; } h17p; } swap; }; static int submit_result;static bool begin_allowed=true; -static unsigned failures,events,armed,watchdogs,completed,sent;static u64 completion_time; +static unsigned failures,events,armed,watchdogs,completed,sent,published;static u64 completion_time;static u32 published_rows; +static void dcp_notch_scanned_out(struct apple_dcp *d,u32 rows) { (void)d;published++;published_rows=rows; } static bool dcp_is_ext26(struct apple_dcp *d) { return d->native; } static int dcp_present_submit(struct apple_dcp *d,u32 id,bool ok) { (void)d;(void)id;(void)ok;return submit_result; } static void dcp_present_failed(struct apple_dcp *d) { (void)d;failures++; } @@ -57,7 +59,7 @@ def function(name): check=r''' static struct apple_dcp fresh(bool native) { struct apple_dcp d={.native=native};d.swap.h17p.swap.swap_id=7; - failures=events=armed=watchdogs=completed=sent=0;submit_result=0;begin_allowed=true;return d; + failures=events=armed=watchdogs=completed=sent=published=0;published_rows=~0U;submit_result=0;begin_allowed=true;return d; } int main(void) { struct dcp_swap_submit_resp bad={1},ok={0};struct apple_dcp d=fresh(true); @@ -68,12 +70,18 @@ def function(name): d=fresh(true);d.ext26_early_complete=true;d.ext26_early_id=7;d.ext26_early_ns=15;d.ext26_rx_ns=20; dcp_swapped(&d,&ok,NULL);assert(completed==1&&completion_time==15&&d.ext26_rx_ns==20&&!d.ext26_early_complete&&!watchdogs&&!d.crashed); d=fresh(true);dcp_swapped(&d,&ok,NULL);assert(watchdogs==1&&!d.crashed&&!failures); + /* The notch geometry follows only a swap the firmware took (panel-notch.h). */ + d=fresh(false);d.notch_swap_y=74;dcp_swapped(&d,&bad,NULL);assert(!published); + d=fresh(false);d.notch_swap_y=74;dcp_swapped(&d,NULL,NULL);assert(!published); + d=fresh(false);d.notch_swap_y=74;submit_result=-ECANCELED;dcp_swapped(&d,&ok,NULL);assert(!published); + d=fresh(false);d.notch_swap_y=74;dcp_swapped(&d,&ok,NULL);assert(published==1&&published_rows==74); + d=fresh(false);d.notch_swap_y=0;dcp_swapped(&d,&ok,NULL);assert(published==1&&published_rows==0); struct dcp_swap_start_resp start={8,1};d=fresh(true);dcp_swap_started(&d,&start,NULL);assert(d.crashed&&d.ext26_blocked&&!armed&&!sent); d=fresh(false);dcp_swap_started(&d,&start,NULL);assert(!d.crashed&&!sent); d=fresh(true);start=(struct dcp_swap_start_resp){0,0};dcp_swap_started(&d,&start,NULL);assert(d.crashed&&!sent); d=fresh(true);start.swap_id=8;begin_allowed=false;dcp_swap_started(&d,&start,NULL);assert(d.crashed&&!sent&&!armed); d=fresh(true);dcp_swap_started(&d,&start,NULL);assert(!d.crashed&&sent==1&&armed==1&&d.swap.h17p.swap.swap_id==8); - puts("PASS actual native DRM start/submit rejection, classic controls and original-time early D590 joining"); + puts("PASS actual native DRM start/submit rejection, classic controls, original-time early D590 joining and notch publish on accepted swaps only"); } ''' with tempfile.TemporaryDirectory() as t: