diff --git a/Documentation/devicetree/bindings/display/apple,dcp.yaml b/Documentation/devicetree/bindings/display/apple,dcp.yaml index 680fc93ef2e5d..4f24471d404ba 100644 --- a/Documentation/devicetree/bindings/display/apple,dcp.yaml +++ b/Documentation/devicetree/bindings/display/apple,dcp.yaml @@ -17,6 +17,7 @@ description: properties: compatible: oneOf: + - const: apple,t6034-dcp - items: - enum: - apple,t8103-dcp diff --git a/Documentation/devicetree/bindings/display/apple,display-subsystem.yaml b/Documentation/devicetree/bindings/display/apple,display-subsystem.yaml index ac106575a9672..541b7c7fac11f 100644 --- a/Documentation/devicetree/bindings/display/apple,display-subsystem.yaml +++ b/Documentation/devicetree/bindings/display/apple,display-subsystem.yaml @@ -19,6 +19,8 @@ properties: - enum: - apple,display-subsystem - apple,t6031-display-subsystem + - apple,t6034-display-subsystem + - apple,t8122-display-subsystem - apple,t8132-display-subsystem - const: apple,t8132-display-diagnostics deprecated: true @@ -50,6 +52,15 @@ properties: type: boolean description: The loader validated the inherited J713 SID0 scanout mapping. + apple,dma-range: + $ref: /schemas/types.yaml#/definitions/uint64-array + minItems: 2 + maxItems: 2 + description: + Common scanout DMA aperture, encoded as a base and nonzero size. This + overrides the default aperture of each referenced DART stream. Other + consumers of the same DART retain their own apertures. + required: - compatible - iommus diff --git a/Documentation/devicetree/bindings/power/apple,t8140-pmp-report.yaml b/Documentation/devicetree/bindings/power/apple,t8140-pmp-report.yaml index 4b9c82d36514b..c14dc7a178570 100644 --- a/Documentation/devicetree/bindings/power/apple,t8140-pmp-report.yaml +++ b/Documentation/devicetree/bindings/power/apple,t8140-pmp-report.yaml @@ -55,7 +55,9 @@ properties: - apple,t8122-pmp-v2-report - apple,t8140-pmp-v2-report - items: - - const: apple,t6031-pmp-v2-report + - enum: + - apple,t6031-pmp-v2-report + - apple,t6034-pmp-v2-report - const: apple,t6020-pmp-v2-report reg: diff --git a/Documentation/devicetree/bindings/soc/apple/apple,pmp.yaml b/Documentation/devicetree/bindings/soc/apple/apple,pmp.yaml index 33c9d95e38243..d9cfa5ae5f9ee 100644 --- a/Documentation/devicetree/bindings/soc/apple/apple,pmp.yaml +++ b/Documentation/devicetree/bindings/soc/apple/apple,pmp.yaml @@ -26,6 +26,7 @@ properties: - enum: - apple,t6030-pmp-v2 - apple,t6031-pmp-v2 + - apple,t6034-pmp-v2 - apple,t6041-pmp-v2 - apple,t6050-pmp-v2 - apple,t8122-pmp-v2 diff --git a/arch/arm64/boot/dts/apple/t6034-dcp.dtsi b/arch/arm64/boot/dts/apple/t6034-dcp.dtsi new file mode 100644 index 0000000000000..824549363791b --- /dev/null +++ b/arch/arm64/boot/dts/apple/t6034-dcp.dtsi @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * J514M/T6034 internal display. Fresh ADT metadata identifies the same + * DCP/DART/PMP register layout and 14.7 firmware images as T6031, with a + * 400 MHz disp0 clock. Keep a separate handoff and component compatible; + * every consumer remains disabled until the T6034 gate validates it. + */ +#include "t6031-dcp.dtsi" + +&clk_disp0 { + clock-frequency = <400000000>; +}; + +&display { + compatible = "apple,t6034-display-subsystem"; +}; + +&dcp { + compatible = "apple,t6034-dcp"; +}; + +&pmp { + compatible = "apple,t6034-pmp-v2", "apple,t6000-pmp-v2"; +}; + +&pmp_report { + compatible = "apple,t6034-pmp-v2-report", "apple,t6020-pmp-v2-report"; +}; diff --git a/arch/arm64/boot/dts/apple/t6034-j514m.dts b/arch/arm64/boot/dts/apple/t6034-j514m.dts index f316f52dfa6cf..37ef5c0876755 100644 --- a/arch/arm64/boot/dts/apple/t6034-j514m.dts +++ b/arch/arm64/boot/dts/apple/t6034-j514m.dts @@ -10,7 +10,7 @@ /dts-v1/; #include "t6034.dtsi" -#include "t6031-dcp.dtsi" +#include "t6034-dcp.dtsi" #include "t603x-j514-j516.dtsi" / { diff --git a/arch/arm64/boot/dts/apple/t6034-j516m.dts b/arch/arm64/boot/dts/apple/t6034-j516m.dts index ee28181492a0a..4b617269f7ad4 100644 --- a/arch/arm64/boot/dts/apple/t6034-j516m.dts +++ b/arch/arm64/boot/dts/apple/t6034-j516m.dts @@ -71,3 +71,17 @@ status = "disabled"; }; }; + +/* + * J516M ADT confirms the J516C display register and interrupt layout. + * External displays (dcpext, HDMI) are not described here yet. + */ +&clk_disp0 { + /* + * Preserve the captured boot-clock metadata, as the J514M path does. + * Firmware warns that this is below its video clock; + * that warning is not proof of the programmed clock or a startup veto. + * The metadata does not qualify sustained power or thermal behavior. + */ + clock-frequency = <400000000>; +}; diff --git a/arch/arm64/boot/dts/apple/t8122-dcp.dtsi b/arch/arm64/boot/dts/apple/t8122-dcp.dtsi index 8d812eae377e8..59233e5138ed4 100644 --- a/arch/arm64/boot/dts/apple/t8122-dcp.dtsi +++ b/arch/arm64/boot/dts/apple/t8122-dcp.dtsi @@ -33,6 +33,8 @@ display: display-subsystem { compatible = "apple,t8122-display-subsystem"; iommus = <&disp0_dart 0>; + /* Keep the inherited scanout alias when adding external streams. */ + apple,dma-range = /bits/ 64 <0x10000000000 0x1000000000>; status = "disabled"; }; }; diff --git a/arch/arm64/boot/dts/apple/t8122-j504.dts b/arch/arm64/boot/dts/apple/t8122-j504.dts index f8258ba3a2f54..f290f01120677 100644 --- a/arch/arm64/boot/dts/apple/t8122-j504.dts +++ b/arch/arm64/boot/dts/apple/t8122-j504.dts @@ -39,13 +39,23 @@ &dcp { panel: panel { compatible = "apple,panel-j504", "apple,panel-mini-led", "apple,panel"; + /* + * The J514S panel: 3024x1964 at 254 ppi; 189 mm high without the + * 74 notch rows. The J504 boot framebuffer is 3024x1890 below them. + */ width-mm = <302>; height-mm = <196>; adj-height-mm = <189>; - apple,max-brightness = <600>; + apple,max-brightness = <500>; }; }; +/* The boot framebuffer is the same panel, as on the J613 (HiDPI scale for simpledrm). */ +&framebuffer0 { + panel = <&panel>; + post-init-providers = <&panel>; +}; + &wifi0 { brcm,board-type = "apple,tresco"; }; diff --git a/drivers/gpu/drm/apple/Makefile b/drivers/gpu/drm/apple/Makefile index 8b2d7288b5639..d9300006b163d 100644 --- a/drivers/gpu/drm/apple/Makefile +++ b/drivers/gpu/drm/apple/Makefile @@ -7,7 +7,7 @@ appledrm-y += afk.o dcp.o dcp-fabric.o dcp_backlight.o dptxep.o iomfb.o parser.o appledrm-y += dcp-hdmi.o appledrm-$(CONFIG_DRM_APPLE_AUDIO) += audio.o appledrm-$(CONFIG_DRM_APPLE_AUDIO) += av.o -appledrm-y += connector.o dcp-panel-adt.o dcp-display-metadata.o dcp-180hz.o +appledrm-y += connector.o dcp-panel-adt.o dcp-display-metadata.o dcp-180hz.o dcp-panel-edid.o appledrm-y += ibootep.o appledrm-y += dcpext_scanout.o appledrm-y += dcpext_drm.o @@ -29,6 +29,7 @@ appledrm-$(CONFIG_DRM_APPLE_KUNIT_TEST) += dcp_external_ready_test.o appledrm-$(CONFIG_DRM_APPLE_KUNIT_TEST) += dcp_external_announce_test.o appledrm-$(CONFIG_DRM_APPLE_KUNIT_TEST) += dcp_external_relink_test.o appledrm-$(CONFIG_DRM_APPLE_KUNIT_TEST) += dcp_dropped_swap_test.o +appledrm-$(CONFIG_DRM_APPLE_KUNIT_TEST) += dcp-panel-edid-test.o appledrm-y += iomfb_v26_6.o iomfb_v26_6_link.o j613_dcp_activate.o appledrm-y += iomfb_v27.o appledrm-y += epic/dpavservep.o diff --git a/drivers/gpu/drm/apple/apple_drv.c b/drivers/gpu/drm/apple/apple_drv.c index bd57a279537cb..6f4131543acec 100644 --- a/drivers/gpu/drm/apple/apple_drv.c +++ b/drivers/gpu/drm/apple/apple_drv.c @@ -82,6 +82,7 @@ static DEFINE_MUTEX(apple_g15_display_lock); static struct device *apple_t6030_display; static struct device *apple_t6031_display; static struct device *apple_t8132_display; +static struct device *apple_t6034_display; /* The publication slot of a G15/G16 SoC's internal display subsystem, or NULL. */ static struct device **apple_g15_display_slot(struct device *dev) @@ -92,6 +93,8 @@ static struct device **apple_g15_display_slot(struct device *dev) return &apple_t6031_display; if (of_device_is_compatible(dev->of_node, "apple,t8132-display-subsystem")) return &apple_t8132_display; + if (of_device_is_compatible(dev->of_node, "apple,t6034-display-subsystem")) + return &apple_t6034_display; return NULL; } @@ -165,6 +168,18 @@ int apple_drm_t8132_link_device(struct device *consumer) } EXPORT_SYMBOL_GPL(apple_drm_t8132_link_device); +int apple_drm_t6034_link_device(struct device *consumer) +{ + if (of_machine_is_compatible("apple,j516m")) + return apple_g15_link_device(consumer, "apple,t6034", "apple,agx-t6034", + &apple_t6031_display); + if (!of_machine_is_compatible("apple,j514m")) + return -ENODEV; + return apple_g15_link_device(consumer, "apple,t6034", "apple,agx-t6034", + &apple_t6034_display); +} +EXPORT_SYMBOL_GPL(apple_drm_t6034_link_device); + DEFINE_DRM_GEM_DMA_FOPS(apple_fops); #define DART_PAGE_SIZE 16384 @@ -1429,6 +1444,7 @@ static const struct of_device_id apple_dcp_id_tbl[] = { { .compatible = "apple,t6030-dcp" }, { .compatible = "apple,t8122-dcp" }, { .compatible = "apple,t6031-dcp" }, + { .compatible = "apple,t6034-dcp" }, #if IS_ENABLED(CONFIG_DRM_APPLE_DCP_T8132) { .compatible = "apple,t8132-dcp" }, #endif @@ -1937,6 +1953,7 @@ static const struct of_device_id of_match[] = { { .compatible = "apple,t6030-display-subsystem" }, { .compatible = "apple,t8122-display-subsystem" }, { .compatible = "apple,t6031-display-subsystem" }, + { .compatible = "apple,t6034-display-subsystem" }, #if IS_ENABLED(CONFIG_DRM_APPLE_DCP_T8132) { .compatible = "apple,t8132-display-subsystem" }, /* Accept the qualified handoff emitted by the existing boot loader. */ diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index 97b0db066bb93..5b4838c1dca87 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -29,6 +29,7 @@ #include "dcp-announce.h" #include "dcp-display-metadata.h" #include "dcp-metadata-epoch.h" +#include "dcp-panel-edid.h" #include "dcp-180hz.h" #include "iomfb.h" #include "iomfb_h17p.h" @@ -224,6 +225,8 @@ struct dcp_panel { u32 edr_ceiling; /// calibrated colour target from the raw ADT; NULL if not given const struct dcp_color_space *color_target; + /// make and product for the base EDID, from the panel's compatible + struct dcp_panel_id id; }; /* diff --git a/drivers/gpu/drm/apple/dcp-panel-edid-test.c b/drivers/gpu/drm/apple/dcp-panel-edid-test.c new file mode 100644 index 0000000000000..399f6e5bfd647 --- /dev/null +++ b/drivers/gpu/drm/apple/dcp-panel-edid-test.c @@ -0,0 +1,276 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT + +/* + * The built-in panel's EDID, read back with the DRM EDID helpers: the make, + * product, model year and native timing come from the panel's compatible and + * the model table; the base block holds the panel's geometry at 60 Hz with P3 + * colour and gamma 2.2, the DisplayID extension the 120 Hz timing; an update + * publishes both blocks on the connector and adds no mode. + */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "dcp-panel-edid.h" + +#define J516_W_MM 346 +#define J516_H_MM 216 + +static void panel_id_j516(struct kunit *test, struct dcp_panel_id *id) +{ + KUNIT_ASSERT_EQ(test, dcp_panel_id_from_compatible(id, "apple,panel-j516"), 0); +} + +static void panel_id_from_compatible(struct kunit *test) +{ + struct dcp_panel_id id; + + panel_id_j516(test, &id); + KUNIT_EXPECT_STREQ(test, id.vendor, "APP"); + KUNIT_EXPECT_STREQ(test, id.name, "J516"); + KUNIT_EXPECT_EQ(test, id.model_year, 2023); + KUNIT_EXPECT_EQ(test, id.timing.clock_khz, 1042130); + KUNIT_EXPECT_EQ(test, id.timing.vtotal, 2456); + /* A model without a known year and timing gets none, and no EDID. */ + KUNIT_ASSERT_EQ(test, dcp_panel_id_from_compatible(&id, "apple,panel-j999"), 0); + KUNIT_EXPECT_EQ(test, id.model_year, 0); + KUNIT_EXPECT_EQ(test, id.timing.clock_khz, 0); +} + +static void panel_id_needs_a_model_and_a_known_vendor(struct kunit *test) +{ + struct dcp_panel_id id; + + KUNIT_EXPECT_EQ(test, dcp_panel_id_from_compatible(&id, "apple,panel"), -EINVAL); + KUNIT_EXPECT_EQ(test, dcp_panel_id_from_compatible(&id, "apple,panel-"), -EINVAL); + KUNIT_EXPECT_EQ(test, dcp_panel_id_from_compatible(&id, "panel-j516"), -EINVAL); + KUNIT_EXPECT_EQ(test, dcp_panel_id_from_compatible(&id, "acme,panel-j516"), -ENOENT); + KUNIT_EXPECT_EQ(test, dcp_panel_id_from_compatible(&id, "apple,panel-j516 x"), -EINVAL); + KUNIT_EXPECT_EQ(test, dcp_panel_id_from_compatible(&id, + "apple,panel-j5160000000000"), + -EINVAL); +} + +static const struct drm_edid *panel_edid_j516(struct kunit *test, + u8 e[DCP_PANEL_EDID_BLOCKS * EDID_LENGTH]) +{ + struct dcp_panel_id id; + const struct drm_edid *edid; + + panel_id_j516(test, &id); + KUNIT_ASSERT_EQ(test, dcp_panel_edid_build(&id, J516_W_MM, J516_H_MM, e), 0); + edid = drm_edid_alloc(e, DCP_PANEL_EDID_BLOCKS * EDID_LENGTH); + KUNIT_ASSERT_NOT_NULL(test, edid); + return edid; +} + +static u8 sum(const u8 *p, size_t len) +{ + u8 s = 0; + + while (len--) + s += *p++; + return s; +} + +static void panel_edid_parses_with_make_product_and_size(struct kunit *test) +{ + struct drm_edid_product_id product; + u8 e[DCP_PANEL_EDID_BLOCKS * EDID_LENGTH]; + const struct drm_edid *edid = panel_edid_j516(test, e); + const struct edid *raw; + char vendor[4], name[14]; + + KUNIT_EXPECT_TRUE(test, drm_edid_valid(edid)); + drm_edid_get_product_id(edid, &product); + drm_edid_decode_mfg_id(be16_to_cpu(product.manufacturer_name), vendor); + KUNIT_EXPECT_STREQ(test, vendor, "APP"); + KUNIT_EXPECT_EQ(test, le16_to_cpu(product.product_code), 0); + KUNIT_EXPECT_EQ(test, le32_to_cpu(product.serial_number), 0); + + raw = drm_edid_raw(edid); + KUNIT_ASSERT_NOT_NULL(test, raw); + drm_edid_get_monitor_name(raw, name, sizeof(name)); + KUNIT_EXPECT_STREQ(test, name, "J516"); + /* The connector's size (the firmware's), in whole centimetres. */ + KUNIT_EXPECT_EQ(test, raw->width_cm, 35); + KUNIT_EXPECT_EQ(test, raw->height_cm, 22); + /* Gamma 2.2, not 1.00 (0) and not "in an extension" (0xff). */ + KUNIT_EXPECT_EQ(test, raw->gamma, 0x78); + /* Model year 2023: week 0xff, year 2023 - 1990. */ + KUNIT_EXPECT_EQ(test, raw->mfg_week, 0xff); + KUNIT_EXPECT_EQ(test, raw->mfg_year, 33); + /* P3 red (0.680, 0.320) and the D65 white point (0.3127, 0.3290), 10-bit. */ + KUNIT_EXPECT_EQ(test, raw->red_x << 2 | raw->red_green_lo >> 6, 696); + KUNIT_EXPECT_EQ(test, raw->red_y << 2 | (raw->red_green_lo >> 4 & 3), 328); + KUNIT_EXPECT_EQ(test, raw->white_x << 2 | (raw->blue_white_lo >> 2 & 3), 320); + KUNIT_EXPECT_EQ(test, raw->white_y << 2 | (raw->blue_white_lo & 3), 337); + /* One extension; both blocks sum to 0. */ + KUNIT_EXPECT_EQ(test, raw->extensions, 1); + KUNIT_EXPECT_EQ(test, sum(e, EDID_LENGTH), 0); + KUNIT_EXPECT_EQ(test, sum(e + EDID_LENGTH, EDID_LENGTH), 0); + drm_edid_free(edid); +} + +/* + * The base block's first descriptor is the panel's geometry at 60 Hz (its 120 Hz + * clock does not fit the 16-bit field); the DisplayID extension holds the real + * 120 Hz timing as its preferred Type VII timing. + */ +static void panel_edid_timings_are_the_panels(struct kunit *test) +{ + u8 e[DCP_PANEL_EDID_BLOCKS * EDID_LENGTH]; + const struct drm_edid *edid = panel_edid_j516(test, e); + const struct edid *raw = drm_edid_raw(edid); + const struct detailed_timing *d = &raw->detailed_timings[0]; + const struct detailed_pixel_timing *pt = &d->data.pixel_data; + const u8 *ext = e + EDID_LENGTH, *section = ext + 1, *t; + unsigned int i, names = 0; + + /* 3536 x 2456 x 60 Hz = 521.06 MHz, in 10 kHz. */ + KUNIT_EXPECT_EQ(test, le16_to_cpu(d->pixel_clock), 52106); + KUNIT_EXPECT_EQ(test, pt->hactive_lo | (pt->hactive_hblank_hi >> 4) << 8, 3456); + KUNIT_EXPECT_EQ(test, pt->hblank_lo | (pt->hactive_hblank_hi & 0xf) << 8, 80); + KUNIT_EXPECT_EQ(test, pt->vactive_lo | (pt->vactive_vblank_hi >> 4) << 8, 2234); + KUNIT_EXPECT_EQ(test, pt->vblank_lo | (pt->vactive_vblank_hi & 0xf) << 8, 222); + KUNIT_EXPECT_EQ(test, pt->hsync_offset_lo, 8); + KUNIT_EXPECT_EQ(test, pt->hsync_pulse_width_lo, 32); + /* The front porch at the field's 63, the sync width the panel's 8. */ + KUNIT_EXPECT_EQ(test, (pt->vsync_offset_pulse_width_lo >> 4) | + (pt->hsync_vsync_offset_pulse_width_hi >> 2 & 3) << 4, 63); + KUNIT_EXPECT_EQ(test, pt->vsync_offset_pulse_width_lo & 0xf, 8); + KUNIT_EXPECT_EQ(test, pt->width_mm_lo | (pt->width_height_mm_hi >> 4) << 8, J516_W_MM); + KUNIT_EXPECT_EQ(test, pt->height_mm_lo | (pt->width_height_mm_hi & 0xf) << 8, J516_H_MM); + /* It is not the preferred mode with its refresh rate. */ + KUNIT_EXPECT_EQ(test, raw->features & DRM_EDID_FEATURE_PREFERRED_TIMING, 0); + for (i = 1; i < ARRAY_SIZE(raw->detailed_timings); i++) { + const struct detailed_timing *o = &raw->detailed_timings[i]; + + KUNIT_EXPECT_EQ(test, le16_to_cpu(o->pixel_clock), 0); + KUNIT_EXPECT_NE(test, o->data.other_data.type, EDID_DETAIL_MONITOR_SERIAL); + KUNIT_EXPECT_NE(test, o->data.other_data.type, EDID_DETAIL_MONITOR_RANGE); + names += o->data.other_data.type == EDID_DETAIL_MONITOR_NAME; + } + KUNIT_EXPECT_EQ(test, names, 1); + for (i = 0; i < sizeof(raw->established_timings); i++) + KUNIT_EXPECT_EQ(test, ((const u8 *)&raw->established_timings)[i], 0); + + /* DisplayID 2.0, generic display, Display Parameters then one Type VII timing. */ + KUNIT_EXPECT_EQ(test, ext[0], 0x70); + KUNIT_EXPECT_EQ(test, section[0], 0x20); + KUNIT_EXPECT_EQ(test, section[2], 0x02); + KUNIT_ASSERT_EQ(test, section[1], 3 + 29 + 3 + 20); + KUNIT_EXPECT_EQ(test, sum(section, 4 + section[1] + 1), 0); + KUNIT_EXPECT_EQ(test, section[4], 0x21); + KUNIT_EXPECT_EQ(test, section[6], 29); + /* Image size in 0.1 mm, the native pixels, gamma 2.2. */ + KUNIT_EXPECT_EQ(test, section[7] | section[8] << 8, J516_W_MM * 10); + KUNIT_EXPECT_EQ(test, section[9] | section[10] << 8, J516_H_MM * 10); + KUNIT_EXPECT_EQ(test, section[11] | section[12] << 8, 3456); + KUNIT_EXPECT_EQ(test, section[13] | section[14] << 8, 2234); + KUNIT_EXPECT_EQ(test, section[7 + 28], 0x78); + t = section + 4 + 3 + 29; + KUNIT_EXPECT_EQ(test, t[0], 0x22); + KUNIT_EXPECT_EQ(test, t[2], 20); + t += 3; + /* 1042130 kHz, preferred, and the DCP mode line's porches (each minus one). */ + KUNIT_EXPECT_EQ(test, t[0] | t[1] << 8 | t[2] << 16, 1042130 - 1); + KUNIT_EXPECT_EQ(test, t[3] & 0x80, 0x80); + KUNIT_EXPECT_EQ(test, t[4] | t[5] << 8, 3456 - 1); + KUNIT_EXPECT_EQ(test, t[6] | t[7] << 8, 3536 - 3456 - 1); + KUNIT_EXPECT_EQ(test, (t[8] | t[9] << 8) & 0x7fff, 3464 - 3456 - 1); + KUNIT_EXPECT_EQ(test, t[10] | t[11] << 8, 3496 - 3464 - 1); + KUNIT_EXPECT_EQ(test, t[12] | t[13] << 8, 2234 - 1); + KUNIT_EXPECT_EQ(test, t[14] | t[15] << 8, 2456 - 2234 - 1); + KUNIT_EXPECT_EQ(test, (t[16] | t[17] << 8) & 0x7fff, 2352 - 2234 - 1); + KUNIT_EXPECT_EQ(test, t[18] | t[19] << 8, 2360 - 2352 - 1); + drm_edid_free(edid); +} + +static void panel_edid_refuses_a_size_it_cannot_hold(struct kunit *test) +{ + u8 e[DCP_PANEL_EDID_BLOCKS * EDID_LENGTH]; + struct dcp_panel_id id; + + panel_id_j516(test, &id); + KUNIT_EXPECT_EQ(test, dcp_panel_edid_build(&id, 0, J516_H_MM, e), -EINVAL); + KUNIT_EXPECT_EQ(test, dcp_panel_edid_build(&id, J516_W_MM, 2560, e), -EINVAL); + id.model_year = 2005; + KUNIT_EXPECT_EQ(test, dcp_panel_edid_build(&id, J516_W_MM, J516_H_MM, e), -EINVAL); + id.model_year = 2023; + id.timing.clock_khz = 0; + KUNIT_EXPECT_EQ(test, dcp_panel_edid_build(&id, J516_W_MM, J516_H_MM, e), -EINVAL); + panel_id_j516(test, &id); + id.vendor[0] = '\0'; + KUNIT_EXPECT_EQ(test, dcp_panel_edid_build(&id, J516_W_MM, J516_H_MM, e), -EINVAL); +} + +struct panel_edid_test { + struct drm_device drm; + struct drm_connector connector; +}; + +/* The DRM KUnit device is atomic: a connector needs its state helpers. */ +static const struct drm_connector_funcs panel_edid_connector_funcs = { + .reset = drm_atomic_helper_connector_reset, + .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, + .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, +}; + +static void panel_edid_update_publishes_the_block(struct kunit *test) +{ + struct panel_edid_test *t; + struct drm_connector *connector; + struct dcp_panel_id id; + struct device *dev; + int ret; + + dev = drm_kunit_helper_alloc_device(test); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev); + t = drm_kunit_helper_alloc_drm_device(test, dev, struct panel_edid_test, drm, + DRIVER_MODESET); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, t); + connector = &t->connector; + ret = drmm_connector_init(&t->drm, connector, &panel_edid_connector_funcs, + DRM_MODE_CONNECTOR_eDP, NULL); + KUNIT_ASSERT_EQ(test, ret, 0); + + panel_id_j516(test, &id); + mutex_lock(&t->drm.mode_config.mutex); + ret = dcp_panel_edid_update(connector, &id, J516_W_MM, J516_H_MM); + mutex_unlock(&t->drm.mode_config.mutex); + KUNIT_ASSERT_EQ(test, ret, 0); + + /* The update sets 350x220 from the block; dcp_get_modes() restores the mm. */ + KUNIT_EXPECT_EQ(test, connector->display_info.width_mm, 350); + KUNIT_EXPECT_EQ(test, connector->display_info.height_mm, 220); + KUNIT_ASSERT_NOT_NULL(test, connector->edid_blob_ptr); + KUNIT_EXPECT_EQ(test, connector->edid_blob_ptr->length, 2 * EDID_LENGTH); + /* The update adds no mode: the modes stay the firmware's. */ + KUNIT_EXPECT_TRUE(test, list_empty(&connector->probed_modes)); +} + +static struct kunit_case panel_edid_cases[] = { + KUNIT_CASE(panel_id_from_compatible), + KUNIT_CASE(panel_id_needs_a_model_and_a_known_vendor), + KUNIT_CASE(panel_edid_parses_with_make_product_and_size), + KUNIT_CASE(panel_edid_timings_are_the_panels), + KUNIT_CASE(panel_edid_refuses_a_size_it_cannot_hold), + KUNIT_CASE(panel_edid_update_publishes_the_block), + {} +}; + +static struct kunit_suite panel_edid_suite = { + .name = "apple-dcp-panel-edid", + .test_cases = panel_edid_cases, +}; + +kunit_test_suite(panel_edid_suite); diff --git a/drivers/gpu/drm/apple/dcp-panel-edid.c b/drivers/gpu/drm/apple/dcp-panel-edid.c new file mode 100644 index 0000000000000..97eee16101697 --- /dev/null +++ b/drivers/gpu/drm/apple/dcp-panel-edid.c @@ -0,0 +1,354 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* + * An EDID for a built-in panel. + * + * The DCP gives no EDID for a built-in panel, so a compositor sees no make, + * model or physical size for it. This builds one from what the panel's + * device-tree node and a table of the known panel models say: the vendor and + * model of its most specific compatible ("apple,panel-j516": make APP, name + * J516), the size the connector has, the model year, the panel's native timing + * as the DCP's mode line gives it with all rows shown, and the colour of a P3 + * wide-colour panel (P3 primaries, D65 white point and a nominal gamma of + * 2.2, which the sRGB transfer function of Display P3 approximates). + * + * The native timing is 3456x2234 at 120 Hz with a pixel clock of 1042 MHz. + * The base block's detailed timing cannot hold it: its pixel clock field is + * 16 bits in 10 kHz units (at most 655.35 MHz) and its vertical front porch 6 + * bits. The base block therefore carries the panel's geometry at 60 Hz (the + * same totals and horizontal porches, the vertical front porch at most 63 + * lines), and a DisplayID 2.0 extension carries the real 120 Hz timing as its + * preferred timing, with the display parameters. Neither is a mode source: + * the driver publishes the firmware's modes and never adds modes from this + * EDID. It makes no other claim: no product code or serial number, no + * manufacture week, no luminance and no refresh range. + */ + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "dcp-panel-edid.h" + +/* Device-tree vendor prefixes and their PNP IDs. */ +static const struct { + const char *prefix; + const char *pnp; +} dcp_panel_vendors[] = { + { "apple", "APP" }, +}; + +/* + * Panel models: the year their machines came out (the EDID model year) and the + * native timing of the DCP's mode line, with the rows the notch hides shown. + */ +static const struct { + const char *name; + u16 year; + struct dcp_panel_timing timing; +} dcp_panel_models[] = { + /* MacBook Pro (16-inch, M3 Pro or M3 Max): 3456x2234 at 120 Hz */ + { "J516", 2023, { 1042130, 3456, 3464, 3496, 3536, 2234, 2352, 2360, 2456 } }, +}; + +/* EDID 1.4: a nominal gamma of 2.2 is (2.2 - 1) * 100 = 120. */ +#define DCP_PANEL_EDID_GAMMA 120 +/* EDID 1.4: week 0xff marks the year byte as the model year, from 1990. */ +#define DCP_PANEL_EDID_MODEL_YEAR 0xff +/* The base block's detailed timing: the panel's geometry at this rate. */ +#define DCP_PANEL_EDID_DTD_HZ 60 +/* EDID 1.4 detailed timing: the vertical front porch field is 6 bits. */ +#define DCP_PANEL_EDID_DTD_VFP_MAX 63 + +/* P3 primaries and the D65 white point, CIE 1931 x and y in 1/10000. */ +static const u16 dcp_panel_p3[8] = { 6800, 3200, 2650, 6900, 1500, 600, 3127, 3290 }; + +/* DisplayID 2.0 (VESA DisplayID Standard v2.0). */ +#define DISPLAYID_EXT 0x70 /* EDID extension tag */ +#define DISPLAYID_V20 0x20 /* structure version 2, revision 0 */ +#define DISPLAYID_GENERIC 0x02 /* primary use case: generic display */ +#define DISPLAYID_PARAMS 0x21 /* Display Parameters data block */ +#define DISPLAYID_PARAMS_LEN 29 +#define DISPLAYID_TYPE7 0x22 /* Type VII detailed timing data block */ +#define DISPLAYID_TYPE7_LEN 20 +#define DISPLAYID_PREFERRED 0x80 /* timing options: preferred */ +#define DISPLAYID_ASPECT_NONE 0x08 /* aspect ratio not given (from the pixels) */ +#define DISPLAYID_SYNC_POS 0x8000 /* front porch word: positive sync */ +#define DISPLAYID_NO_SPEAKERS 0x80 /* features: audio not integrated */ +#define DISPLAYID_TECH_LCD 0x10 /* device technology: active-matrix LCD */ + +int dcp_panel_id_from_compatible(struct dcp_panel_id *id, const char *compatible) +{ + const char *comma = strchr(compatible, ','), *model; + size_t vendor_len, len, i; + + memset(id, 0, sizeof(*id)); + if (!comma) + return -EINVAL; + vendor_len = comma - compatible; + model = comma + 1; + if (str_has_prefix(model, "panel-")) + model += strlen("panel-"); + else + return -EINVAL; + len = strlen(model); + if (!len || len > DCP_PANEL_NAME_LEN) + return -EINVAL; + for (i = 0; i < len; i++) { + if (!isalnum(model[i]) && model[i] != '-') + return -EINVAL; + id->name[i] = toupper(model[i]); + } + + for (i = 0; i < ARRAY_SIZE(dcp_panel_models); i++) { + if (!strcmp(id->name, dcp_panel_models[i].name)) { + id->model_year = dcp_panel_models[i].year; + id->timing = dcp_panel_models[i].timing; + } + } + for (i = 0; i < ARRAY_SIZE(dcp_panel_vendors); i++) { + if (strlen(dcp_panel_vendors[i].prefix) == vendor_len && + !strncmp(compatible, dcp_panel_vendors[i].prefix, vendor_len)) { + strscpy(id->vendor, dcp_panel_vendors[i].pnp); + return 0; + } + } + memset(id, 0, sizeof(*id)); + return -ENOENT; +} + +static void put_le16(u8 *p, u16 v) +{ + p[0] = v; + p[1] = v >> 8; +} + +static void checksum(u8 *start, size_t len) +{ + u8 sum = 0; + size_t i; + + for (i = 0; i < len - 1; i++) + sum += start[i]; + start[len - 1] = -sum; +} + +static bool timing_valid(const struct dcp_panel_timing *t) +{ + return t->clock_khz && t->hdisplay < t->hsync_start && t->hsync_start < t->hsync_end && + t->hsync_end < t->htotal && t->htotal - t->hdisplay < 4096 && + t->vdisplay < t->vsync_start && t->vsync_start < t->vsync_end && + t->vsync_end < t->vtotal && t->vtotal - t->vdisplay < 4096 && + t->hsync_start - t->hdisplay < 1024 && t->hsync_end - t->hsync_start < 1024 && + t->vsync_end - t->vsync_start < 64; +} + +/* The base block's detailed timing: the panel's geometry at DCP_PANEL_EDID_DTD_HZ. */ +static void base_dtd(u8 *d, const struct dcp_panel_timing *t, int width_mm, int height_mm) +{ + u32 clock = DIV_ROUND_CLOSEST((u32)t->htotal * t->vtotal * DCP_PANEL_EDID_DTD_HZ, 10000); + u16 hblank = t->htotal - t->hdisplay, vblank = t->vtotal - t->vdisplay; + u16 hfp = t->hsync_start - t->hdisplay, hsw = t->hsync_end - t->hsync_start; + u16 vfp = min_t(u16, t->vsync_start - t->vdisplay, DCP_PANEL_EDID_DTD_VFP_MAX); + u16 vsw = t->vsync_end - t->vsync_start; + + put_le16(d, clock); + d[2] = t->hdisplay; + d[3] = hblank; + d[4] = (t->hdisplay >> 8) << 4 | hblank >> 8; + d[5] = t->vdisplay; + d[6] = vblank; + d[7] = (t->vdisplay >> 8) << 4 | vblank >> 8; + d[8] = hfp; + d[9] = hsw; + d[10] = (vfp & 0xf) << 4 | (vsw & 0xf); + d[11] = (hfp >> 8) << 6 | (hsw >> 8) << 4 | (vfp >> 4) << 2 | (vsw >> 4); + d[12] = width_mm; + d[13] = height_mm; + d[14] = (width_mm >> 8) << 4 | height_mm >> 8; + /* Digital separate sync, positive vertical and horizontal sync. */ + d[17] = 0x1e; +} + +/* The P3/D65 chromaticity of the base block, in 10-bit fractions. */ +static void base_chromaticity(struct edid *block) +{ + u16 v[8]; + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(v); i++) + v[i] = DIV_ROUND_CLOSEST(dcp_panel_p3[i] * 1024, 10000); + block->red_green_lo = (v[0] & 3) << 6 | (v[1] & 3) << 4 | (v[2] & 3) << 2 | (v[3] & 3); + block->blue_white_lo = (v[4] & 3) << 6 | (v[5] & 3) << 4 | (v[6] & 3) << 2 | (v[7] & 3); + block->red_x = v[0] >> 2; + block->red_y = v[1] >> 2; + block->green_x = v[2] >> 2; + block->green_y = v[3] >> 2; + block->blue_x = v[4] >> 2; + block->blue_y = v[5] >> 2; + block->white_x = v[6] >> 2; + block->white_y = v[7] >> 2; +} + +static int base_block(const struct dcp_panel_id *id, int width_mm, int height_mm, + struct edid *block) +{ + struct detailed_non_pixel *name; + u16 manufacturer = 0; + size_t len = strnlen(id->name, sizeof(id->name)); + unsigned int i; + + for (i = 0; i < 3; i++) { + if (id->vendor[i] < 'A' || id->vendor[i] > 'Z') + return -EINVAL; + manufacturer = manufacturer << 5 | (id->vendor[i] - '@'); + } + + memset(block, 0, sizeof(*block)); + memcpy(block->header, "\x00\xff\xff\xff\xff\xff\xff\x00", sizeof(block->header)); + block->product_id.manufacturer_name = cpu_to_be16(manufacturer); + block->mfg_week = DCP_PANEL_EDID_MODEL_YEAR; + block->mfg_year = id->model_year - 1990; + block->version = 1; + block->revision = 4; + block->input = DRM_EDID_INPUT_DIGITAL; + block->width_cm = DIV_ROUND_CLOSEST(width_mm, 10); + block->height_cm = DIV_ROUND_CLOSEST(height_mm, 10); + block->gamma = DCP_PANEL_EDID_GAMMA; + base_chromaticity(block); + /* Standard timings 0x0101 are unused slots. */ + memset(block->standard_timings, 0x01, sizeof(block->standard_timings)); + + /* EDID 1.4: the first descriptor is a detailed timing; the second names the panel. */ + base_dtd((u8 *)&block->detailed_timings[0], &id->timing, width_mm, height_mm); + name = &block->detailed_timings[1].data.other_data; + name->type = EDID_DETAIL_MONITOR_NAME; + memset(name->data.str.str, ' ', sizeof(name->data.str.str)); + memcpy(name->data.str.str, id->name, len); + if (len < sizeof(name->data.str.str)) + name->data.str.str[len] = '\n'; + for (i = 2; i < ARRAY_SIZE(block->detailed_timings); i++) + block->detailed_timings[i].data.other_data.type = 0x10; + block->extensions = DCP_PANEL_EDID_BLOCKS - 1; + checksum((u8 *)block, EDID_LENGTH); + return 0; +} + +/* DisplayID 2.0 CIE 1931 x/y pair in 12-bit fractions, packed in 3 bytes. */ +static void displayid_xy(u8 *p, u16 x, u16 y) +{ + u16 X = DIV_ROUND_CLOSEST(x * 4095, 10000), Y = DIV_ROUND_CLOSEST(y * 4095, 10000); + + p[0] = X; + p[1] = (X >> 8) | (Y & 0xf) << 4; + p[2] = Y >> 4; +} + +/* The DisplayID 2.0 extension: display parameters and the 120 Hz Type VII timing. */ +static void displayid_block(const struct dcp_panel_id *id, int width_mm, int height_mm, + u8 *ext) +{ + const struct dcp_panel_timing *t = &id->timing; + u8 *section = ext + 1, *p, *b; + unsigned int i; + + memset(ext, 0, EDID_LENGTH); + ext[0] = DISPLAYID_EXT; + section[0] = DISPLAYID_V20; + section[1] = 3 + DISPLAYID_PARAMS_LEN + 3 + DISPLAYID_TYPE7_LEN; + section[2] = DISPLAYID_GENERIC; + section[3] = 0; /* no further DisplayID extensions */ + + b = section + 4; + b[0] = DISPLAYID_PARAMS; + b[2] = DISPLAYID_PARAMS_LEN; + p = b + 3; + put_le16(p + 0, width_mm * 10); /* 0.1 mm */ + put_le16(p + 2, height_mm * 10); + put_le16(p + 4, t->hdisplay); + put_le16(p + 6, t->vdisplay); + /* Left to right, top to bottom; CIE 1931; the speakers are not the panel's. */ + p[8] = DISPLAYID_NO_SPEAKERS; + for (i = 0; i < 4; i++) + displayid_xy(p + 9 + 3 * i, dcp_panel_p3[2 * i], dcp_panel_p3[2 * i + 1]); + /* Bytes 21-26, the luminances, are not known: left 0. Colour depth not given. */ + p[27] = DISPLAYID_TECH_LCD; + p[28] = DCP_PANEL_EDID_GAMMA; + + b = p + DISPLAYID_PARAMS_LEN; + b[0] = DISPLAYID_TYPE7; + b[2] = DISPLAYID_TYPE7_LEN; + p = b + 3; + /* Pixel clock in kHz minus one, 24 bits. */ + p[0] = (t->clock_khz - 1); + p[1] = (t->clock_khz - 1) >> 8; + p[2] = (t->clock_khz - 1) >> 16; + p[3] = DISPLAYID_PREFERRED | DISPLAYID_ASPECT_NONE; + /* Each field minus one; the front porch words carry the sync polarity. */ + put_le16(p + 4, t->hdisplay - 1); + put_le16(p + 6, t->htotal - t->hdisplay - 1); + put_le16(p + 8, (t->hsync_start - t->hdisplay - 1) | DISPLAYID_SYNC_POS); + put_le16(p + 10, t->hsync_end - t->hsync_start - 1); + put_le16(p + 12, t->vdisplay - 1); + put_le16(p + 14, t->vtotal - t->vdisplay - 1); + put_le16(p + 16, (t->vsync_start - t->vdisplay - 1) | DISPLAYID_SYNC_POS); + put_le16(p + 18, t->vsync_end - t->vsync_start - 1); + + /* The section's checksum after its payload, then the block's. */ + checksum(section, 4 + section[1] + 1); + checksum(ext, EDID_LENGTH); +} + +int dcp_panel_edid_build(const struct dcp_panel_id *id, int width_mm, int height_mm, + u8 edid[DCP_PANEL_EDID_BLOCKS * EDID_LENGTH]) +{ + size_t len = strnlen(id->name, sizeof(id->name)); + int ret; + + if (width_mm <= 0 || height_mm <= 0 || width_mm > 4095 || height_mm > 4095 || + DIV_ROUND_CLOSEST(width_mm, 10) > 255 || DIV_ROUND_CLOSEST(height_mm, 10) > 255) + return -EINVAL; + if (strnlen(id->vendor, sizeof(id->vendor)) != 3 || !len || len > DCP_PANEL_NAME_LEN) + return -EINVAL; + /* EDID 1.4 reserves the years before 2006. */ + if (id->model_year < 2006 || id->model_year > 1990 + 255) + return -EINVAL; + if (!timing_valid(&id->timing)) + return -EINVAL; + ret = base_block(id, width_mm, height_mm, (struct edid *)edid); + if (ret) + return ret; + displayid_block(id, width_mm, height_mm, edid + EDID_LENGTH); + return 0; +} + +int dcp_panel_edid_update(struct drm_connector *connector, const struct dcp_panel_id *id, + int width_mm, int height_mm) +{ + const struct drm_edid *edid; + u8 *blocks; + int ret; + + blocks = kmalloc(DCP_PANEL_EDID_BLOCKS * EDID_LENGTH, GFP_KERNEL); + if (!blocks) + return -ENOMEM; + ret = dcp_panel_edid_build(id, width_mm, height_mm, blocks); + if (ret) + goto out; + edid = drm_edid_alloc(blocks, DCP_PANEL_EDID_BLOCKS * EDID_LENGTH); + if (!edid) { + ret = -ENOMEM; + goto out; + } + /* This sets the connector's size from the block, in whole centimetres. */ + ret = drm_edid_connector_update(connector, edid); + drm_edid_free(edid); +out: + kfree(blocks); + return ret; +} diff --git a/drivers/gpu/drm/apple/dcp-panel-edid.h b/drivers/gpu/drm/apple/dcp-panel-edid.h new file mode 100644 index 0000000000000..1e9a6242831b1 --- /dev/null +++ b/drivers/gpu/drm/apple/dcp-panel-edid.h @@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0-only OR MIT */ +/* A base EDID for a built-in panel, from its device-tree node. */ +#ifndef __APPLE_DCP_PANEL_EDID_H__ +#define __APPLE_DCP_PANEL_EDID_H__ + +#include + +/* The monitor-name text of an EDID descriptor holds 13 characters. */ +#define DCP_PANEL_NAME_LEN 13 + +/* An EDID of a base block and one DisplayID extension. */ +#define DCP_PANEL_EDID_BLOCKS 2 + +/* A panel's native timing, as the DCP's mode line gives it (all rows shown). */ +struct dcp_panel_timing { + u32 clock_khz; + u16 hdisplay, hsync_start, hsync_end, htotal; + u16 vdisplay, vsync_start, vsync_end, vtotal; +}; + +/* The make, product, model year and native timing of a panel. */ +struct dcp_panel_id { + char vendor[4]; /* PNP ID, empty if unknown */ + char name[DCP_PANEL_NAME_LEN + 1]; /* monitor name */ + u16 model_year; /* the model's year, 0 if unknown */ + struct dcp_panel_timing timing; /* zero if unknown */ +}; + +struct drm_connector; + +int dcp_panel_id_from_compatible(struct dcp_panel_id *id, const char *compatible); +int dcp_panel_edid_build(const struct dcp_panel_id *id, int width_mm, int height_mm, + u8 edid[DCP_PANEL_EDID_BLOCKS * 128]); +int dcp_panel_edid_update(struct drm_connector *connector, const struct dcp_panel_id *id, + int width_mm, int height_mm); + +#endif diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index df6a8e976455e..44c8468ba9214 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -6024,6 +6024,8 @@ static int dcp_comp_bind_pipe(struct device *dev, struct device *main, void *dat panel_np = of_get_compatible_child(dev->of_node, "apple,panel"); if (panel_np) { + const char *compatible; + if (dcp->fw_compat == DCP_FIRMWARE_V_26_6_DESKTOP) { /* * Desktop 26.x swaps carry nits, and the panel node @@ -6042,6 +6044,12 @@ static int dcp_comp_bind_pipe(struct device *dev, struct device *main, void *dat } dcp_panel_read_dimensions(dcp, panel_np); + /* The most specific compatible names the panel for its EDID. */ + if (iomfb_v14_7_base_edid(dcp) && + !of_property_read_string_index(panel_np, "compatible", 0, &compatible) && + dcp_panel_id_from_compatible(&dcp->panel.id, compatible)) + dev_dbg(dev, "no EDID make and product in '%s'\n", compatible); + of_node_put(panel_np); /* Read target metadata for H17P and desktop firmware alike. */ dcp_panel_read_adt(dcp); @@ -9210,6 +9218,7 @@ static const struct of_device_id of_match[] = { { .compatible = "apple,t6030-dcpext", .data = &apple_dcp_hw_t6030_dcpext, }, { .compatible = "apple,t8122-dcp", .data = &apple_dcp_hw_t8122, }, { .compatible = "apple,t6031-dcp", .data = &apple_dcp_hw_t6031, }, + { .compatible = "apple,t6034-dcp", .data = &apple_dcp_hw_t6031, }, { .compatible = "apple,t8122-dcpext", .data = &apple_dcp_hw_t8122_dcpext, }, { .compatible = "apple,dcp", .data = &apple_dcp_hw_dcp, }, { .compatible = "apple,dcpext", .data = &apple_dcp_hw_dcpext, }, diff --git a/drivers/gpu/drm/apple/iomfb.c b/drivers/gpu/drm/apple/iomfb.c index 3b41359bba82e..eabf90c1a140f 100644 --- a/drivers/gpu/drm/apple/iomfb.c +++ b/drivers/gpu/drm/apple/iomfb.c @@ -2785,6 +2785,22 @@ int dcp_get_modes(struct drm_connector *connector) if (dcp->hw.link_report) dcp_note_edid(apple_connector, apple_connector->drm_edid); } + } else if (nr_modes && dcp_is_v14_7_panel(dcp) && dcp->panel.id.vendor[0]) { + /* + * No EDID comes for this panel: publish the base block of its + * node, sized as the connector is (the firmware's size, else the + * node's), then give the connector back its size in millimetres. + */ + int update; + + dcp_update_connector_dimensions(dcp, connector); + update = dcp_panel_edid_update(connector, &dcp->panel.id, + connector->display_info.width_mm, + connector->display_info.height_mm); + dcp_update_connector_dimensions(dcp, connector); + apple_connector->drm_edid_firmware_derived = false; + if (update) + dev_warn_once(dcp->dev, "panel EDID publication failed: %d\n", update); } else { u64 generation = 0; u32 defaults = 0; diff --git a/drivers/gpu/drm/apple/iomfb_v14_7.c b/drivers/gpu/drm/apple/iomfb_v14_7.c index a99bfed67183f..5b3ac60fe53e9 100644 --- a/drivers/gpu/drm/apple/iomfb_v14_7.c +++ b/drivers/gpu/drm/apple/iomfb_v14_7.c @@ -136,6 +136,32 @@ static const struct dcp_v14_board dcp_v14_board_j615 = { .panel_width = 2880, .panel_height = 1864, .promotion = false, + .panel_nits = true, + .ctm_set = A(421), + .ctm_get = A(420), +}; + +/* + * J504 (MacBook Pro 14", M3): the J613 DCP image on the same T8122 DCP (the + * J504 ADT names it), driving the 14" mini-LED panel of the J514S: 3024x1964 + * with 74 notch rows above the 3024x1890 boot framebuffer, at 60 or 120 Hz. + * The colour matrix methods are this image's, and so is the panel level + * block the J613 qualified (brightness in nits, 500 at most here). Its swaps + * keep zero timestamps as on the Airs. Every panel timing and the + * display clock are logged for the first boots. + */ +static const struct dcp_v14_board dcp_v14_board_j504 = { + .name = "J504", + .debugfs = "dcp-j504", + .dcp_compatible = "apple,t8122-dcp", + .machine = "apple,j504", + .firmware_uuid = DCP_V14_J613_FIRMWARE_UUID, + .handoff = "apple,t8122-handoff", + .panel_width = 3024, + .panel_height = 1964, + .promotion = true, + .log_bringup = true, + .panel_nits = true, .ctm_set = A(421), .ctm_get = A(420), }; @@ -169,6 +195,27 @@ static const struct dcp_v14_board dcp_v14_board_j516c = { * at most), as the e272b67 path on this J516C presented it. */ .panel_nits = true, + .base_edid = true, +}; + +/* J516M uses the J516C image; its first boot offered only a 120 Hz panel timing. */ +static const struct dcp_v14_board dcp_v14_board_j516m = { + .name = "J516M", + .debugfs = "dcp-j516m", + .dcp_compatible = "apple,t6031-dcp", + .machine = "apple,j516m", + .soc = "apple,t6034", + .firmware_uuid = DCP_V14_J516C_FIRMWARE_UUID, + .handoff = "apple,t6031-handoff", + .panel_width = 3456, + .panel_height = 2234, + .promotion = true, + .log_bringup = true, + .base_edid = true, + /* Same pinned DCP image as J516C: zero stamps cap this panel at 60 fps. */ + .swap_timestamps = true, + /* J516C's 14.7 image uses the bounded nits block for the J516 panel. */ + .panel_nits = true, }; /* @@ -189,12 +236,28 @@ static const struct dcp_v14_board dcp_v14_board_j514c = { .log_bringup = true, }; +/* J514M's 14.7 DCP image and panel geometry; the root SoC is required too. */ +static const struct dcp_v14_board dcp_v14_board_j514m = { + .name = "J514M", + .debugfs = "dcp-j514m", + .dcp_compatible = "apple,t6034-dcp", + .machine = "apple,j514m", + .soc = "apple,t6034", + .firmware_uuid = DCP_V14_J516C_FIRMWARE_UUID, + .handoff = "apple,t6034-handoff", + .promotion = true, + .log_bringup = true, +}; + static const struct dcp_v14_board *const dcp_v14_boards[] = { &dcp_v14_board_t6030, &dcp_v14_board_j613, &dcp_v14_board_j615, + &dcp_v14_board_j504, &dcp_v14_board_j516c, &dcp_v14_board_j514c, + &dcp_v14_board_j514m, + &dcp_v14_board_j516m, }; struct dcp_v14_property { @@ -324,7 +387,7 @@ static int dcp_v14_callback(void *cookie, u32 tag, const void *input, u32 in_siz static void dcp_v14_backlight_work(struct work_struct *work); -/* The internal panel of a board whose swap level block was validated (T6030). */ +/* The internal panel of a board admitted to the bounded swap level path. */ static bool dcp_v14_board_nits(const struct apple_dcp_v14 *v14) { return !v14->external && v14->panel_nits && v14->board && v14->board->panel_nits; @@ -1651,7 +1714,8 @@ const struct dcp_v14_board *dcp_v14_board_select(dcp_v14_compat_fn dcp_is, if (!dcp_is(ctx, board->dcp_compatible)) continue; *dcp_known = true; - if (board->machine && !machine_is(ctx, board->machine)) + if ((board->machine && !machine_is(ctx, board->machine)) || + (board->soc && !machine_is(ctx, board->soc))) continue; return board; } @@ -1694,7 +1758,9 @@ static bool dcp_v14_panel_nits_admit(const struct dcp_v14_board *board, { return board && board->panel_nits && (machine_is(ctx, "apple,j514s") || machine_is(ctx, "apple,j516s") || - machine_is(ctx, "apple,j516c") || machine_is(ctx, "apple,j613")); + machine_is(ctx, "apple,j516c") || machine_is(ctx, "apple,j613") || + machine_is(ctx, "apple,j504") || machine_is(ctx, "apple,j516m") || + machine_is(ctx, "apple,j615")); } const char *iomfb_v14_7_board_name(const struct dcp_v14_board *board) @@ -1707,6 +1773,11 @@ bool dcp_v14_board_stamps_swaps(const struct dcp_v14_board *board, bool external return board && !external && board->swap_timestamps; } +bool iomfb_v14_7_base_edid(const struct apple_dcp *dcp) +{ + return dcp->v14 && dcp->v14->board && dcp->v14->board->base_edid; +} + int iomfb_v14_7_probe(struct apple_dcp *dcp) { struct device *dev = dcp->dev; diff --git a/drivers/gpu/drm/apple/iomfb_v14_7.h b/drivers/gpu/drm/apple/iomfb_v14_7.h index 8aa4eeda4be7a..7eb6ada2b1c26 100644 --- a/drivers/gpu/drm/apple/iomfb_v14_7.h +++ b/drivers/gpu/drm/apple/iomfb_v14_7.h @@ -28,6 +28,8 @@ const __be32 *of_translate_dma_region_checked(struct device_node *dev, */ const struct dcp_v14_board *iomfb_v14_7_board(struct device *dev); const char *iomfb_v14_7_board_name(const struct dcp_v14_board *board); +/* Whether the internal panel's board record gives it a base EDID. */ +bool iomfb_v14_7_base_edid(const struct apple_dcp *dcp); /* Platform probe: firmware identity, boot loader handoff, PMP acknowledgment. */ int iomfb_v14_7_probe(struct apple_dcp *dcp); diff --git a/drivers/gpu/drm/apple/iomfb_v14_7_backlight_test.c b/drivers/gpu/drm/apple/iomfb_v14_7_backlight_test.c index 3c1fc2f45d534..0c8fca3b3c370 100644 --- a/drivers/gpu/drm/apple/iomfb_v14_7_backlight_test.c +++ b/drivers/gpu/drm/apple/iomfb_v14_7_backlight_test.c @@ -8,7 +8,7 @@ * a refused level never becomes the actual one). * * The objects are built here, with no DCP: nothing in a case may reach an - * RPC. A J615 or J514C panel never initialises the backlight policy; + * RPC. A J514C panel never initialises the backlight policy; * its state is set to answer "yes" so that a case fails if anything on * those boards looks at it. */ @@ -122,13 +122,14 @@ static bool v14_bl_ctx_machine_is(const void *ctx, const char *compat) return !strcmp(((const char *const *)ctx)[1], compat); } -/* Only admitted T6030, J516C and J613 internal panels carry levels. */ +/* Only admitted T6030, J516C, J613, J615 and J504 internal panels carry levels. */ static void v14_bl_boards(struct kunit *test) { static const char *const t6030_j516s[] = { "apple,t6030-dcp", "apple,j516s" }; static const char *const t6030_j514s[] = { "apple,t6030-dcp", "apple,j514s" }; static const char *const j613[] = { "apple,t8122-dcp", "apple,j613" }; static const char *const j615[] = { "apple,t8122-dcp", "apple,j615" }; + static const char *const j504[] = { "apple,t8122-dcp", "apple,j504" }; static const char *const j516c[] = { "apple,t6031-dcp", "apple,j516c" }; static const char *const other_t6030[] = { "apple,t6030-dcp", "apple,other" }; const struct dcp_v14_board *board; @@ -152,10 +153,14 @@ static void v14_bl_boards(struct kunit *test) KUNIT_ASSERT_NOT_NULL(test, board); KUNIT_EXPECT_TRUE(test, board->panel_nits); KUNIT_EXPECT_TRUE(test, dcp_v14_panel_nits_admit(board, v14_bl_ctx_machine_is, j613)); - KUNIT_EXPECT_FALSE(test, dcp_v14_panel_nits_admit(board, v14_bl_ctx_machine_is, j615)); board = dcp_v14_board_select(v14_bl_ctx_dcp_is, v14_bl_ctx_machine_is, j615, &known); KUNIT_ASSERT_NOT_NULL(test, board); - KUNIT_EXPECT_FALSE(test, board->panel_nits); + KUNIT_EXPECT_TRUE(test, board->panel_nits); + KUNIT_EXPECT_TRUE(test, dcp_v14_panel_nits_admit(board, v14_bl_ctx_machine_is, j615)); + board = dcp_v14_board_select(v14_bl_ctx_dcp_is, v14_bl_ctx_machine_is, j504, &known); + KUNIT_ASSERT_NOT_NULL(test, board); + KUNIT_EXPECT_TRUE(test, board->panel_nits); + KUNIT_EXPECT_TRUE(test, dcp_v14_panel_nits_admit(board, v14_bl_ctx_machine_is, j504)); board = dcp_v14_board_select(v14_bl_ctx_dcp_is, v14_bl_ctx_machine_is, j516c, &known); KUNIT_ASSERT_NOT_NULL(test, board); KUNIT_EXPECT_TRUE(test, board->panel_nits); @@ -348,13 +353,13 @@ static bool v14_bl_queued(struct apple_dcp_v14 *v14) } /* - * The production paths on J615 and J514C: no policy is consulted, no + * The production path on J514C: no policy is consulted, no * level is encoded, the work does nothing, sleep leaves the gate alone. */ static void v14_bl_other_boards_untouched(struct kunit *test) { const struct dcp_v14_board *boards[] = { - &dcp_v14_board_j615, &dcp_v14_board_j514c, + &dcp_v14_board_j514c, }; struct dcp_backlight_present present; unsigned int i; @@ -477,6 +482,11 @@ static void v14_bl_j613_swap_levels(struct kunit *test) v14_bl_swap_levels(test, &dcp_v14_board_j613); } +static void v14_bl_j615_swap_levels(struct kunit *test) +{ + v14_bl_swap_levels(test, &dcp_v14_board_j615); +} + /* * The gate, through the production queue path: open, a kick queues the work; * suspended, nothing queues until resume; closed, nothing ever does. The @@ -566,6 +576,7 @@ static struct kunit_case v14_backlight_cases[] = { KUNIT_CASE(v14_bl_external_untouched), KUNIT_CASE(v14_bl_t6030_swap_levels), KUNIT_CASE(v14_bl_j613_swap_levels), + KUNIT_CASE(v14_bl_j615_swap_levels), KUNIT_CASE(v14_bl_t6030_gate), KUNIT_CASE(v14_bl_t6030_work), {} diff --git a/drivers/gpu/drm/apple/iomfb_v14_7_board.h b/drivers/gpu/drm/apple/iomfb_v14_7_board.h index 6de1ae9004122..634370fd31d21 100644 --- a/drivers/gpu/drm/apple/iomfb_v14_7_board.h +++ b/drivers/gpu/drm/apple/iomfb_v14_7_board.h @@ -19,6 +19,8 @@ struct dcp_v14_board { const char *dcp_compatible; /* The machine compatible; NULL for any machine with this DCP. */ const char *machine; + /* Optional additional root SoC restriction. */ + const char *soc; /* The firmware image whose layouts were tested on this board. */ const char *firmware_uuid; /* Set to <1> by the boot loader on the DCP, display and PIODMA nodes. */ @@ -48,6 +50,11 @@ struct dcp_v14_board { bool swap_timestamps; /* This board has a qualified panel level block; machine admission is separate. */ bool panel_nits; + /* + * The panel gets a base EDID (make, model and size) built from its + * device-tree node, as the firmware gives none. + */ + bool base_edid; }; /* Whether the DCP node or the machine (as @ctx gives them) has @compat. */ diff --git a/drivers/gpu/drm/apple/v14-board-test.c b/drivers/gpu/drm/apple/v14-board-test.c index f9b84ab36a7cc..858b5db4e2835 100644 --- a/drivers/gpu/drm/apple/v14-board-test.c +++ b/drivers/gpu/drm/apple/v14-board-test.c @@ -51,9 +51,15 @@ static const struct dcp_v14_board *board_for(const char *dcp, const char *const static const char *const j516c[] = { "apple,j516c", "apple,t6031", "apple,arm-platform", NULL }; static const char *const j514c[] = { "apple,j514c", "apple,t6031", "apple,arm-platform", NULL }; +static const char *const j514m[] = { "apple,j514m", "apple,t6034", "apple,arm-platform", NULL }; +static const char *const j514m_wrong_soc[] = { "apple,j514m", "apple,t6031", NULL }; static const char *const j516m[] = { "apple,j516m", "apple,t6034", "apple,arm-platform", NULL }; +static const char *const j516m_wrong_soc[] = { "apple,j516m", "apple,t6031", NULL }; +static const char *const t6034_other[] = { "apple,j999", "apple,t6034", "apple,arm-platform", NULL }; static const char *const j516s[] = { "apple,j516s", "apple,t6030", "apple,arm-platform", NULL }; static const char *const j613[] = { "apple,j613", "apple,t8122", "apple,arm-platform", NULL }; +static const char *const j504[] = { "apple,j504", "apple,t8122", "apple,arm-platform", NULL }; +static const char *const j433[] = { "apple,j433", "apple,t8122", "apple,arm-platform", NULL }; static void v14_board_j516c(struct kunit *test) { @@ -75,6 +81,7 @@ static void v14_board_j516c(struct kunit *test) /* No colour matrix method is known for this board. */ KUNIT_EXPECT_EQ(test, b->ctm_set, 0); KUNIT_EXPECT_EQ(test, b->ctm_get, 0); + KUNIT_EXPECT_TRUE(test, b->base_edid); } /* @@ -99,18 +106,74 @@ static void v14_board_j514c(struct kunit *test) KUNIT_EXPECT_TRUE(test, b->promotion); KUNIT_EXPECT_TRUE(test, b->log_bringup); KUNIT_EXPECT_EQ(test, b->ctm_set, 0); + /* Its panel is not the J516C's: no base EDID. */ + KUNIT_EXPECT_FALSE(test, b->base_edid); KUNIT_EXPECT_TRUE(test, dcp_v14_board_admits(b, J516C_DCP_IMAGE)); KUNIT_EXPECT_FALSE(test, dcp_v14_board_admits(b, T6030_DCP_IMAGE)); /* Not the J516C record. */ KUNIT_EXPECT_PTR_NE(test, b, board_for("apple,t6031-dcp", j516c, &known)); } -/* A T6031 DCP on a T6034 has no record: refused. */ +static void v14_board_j514m(struct kunit *test) +{ + const struct dcp_v14_board *b; + bool known; + + b = board_for("apple,t6034-dcp", j514m, &known); + KUNIT_ASSERT_NOT_NULL(test, b); + KUNIT_EXPECT_TRUE(test, known); + KUNIT_EXPECT_STREQ(test, b->machine, "apple,j514m"); + KUNIT_EXPECT_STREQ(test, b->soc, "apple,t6034"); + KUNIT_EXPECT_STREQ(test, b->handoff, "apple,t6034-handoff"); + KUNIT_EXPECT_TRUE(test, dcp_v14_board_admits(b, J516C_DCP_IMAGE)); + KUNIT_EXPECT_FALSE(test, dcp_v14_board_admits(b, T6030_DCP_IMAGE)); + KUNIT_EXPECT_FALSE(test, b->panel_nits); + KUNIT_EXPECT_NULL(test, board_for("apple,t6034-dcp", j514m_wrong_soc, &known)); + KUNIT_EXPECT_NULL(test, board_for("apple,t6034-dcp", j516m, &known)); + KUNIT_EXPECT_NULL(test, board_for("apple,t6031-dcp", j514m, &known)); +} + +/* + * The J516M: a T6034 with the T6031 DCP layout, running the J516C image on the + * J516 panel. Admitted only on its own record, with its own SoC. + */ +static void v14_board_j516m(struct kunit *test) +{ + const struct dcp_v14_board *b; + bool known; + + b = board_for("apple,t6031-dcp", j516m, &known); + KUNIT_ASSERT_NOT_NULL(test, b); + KUNIT_EXPECT_TRUE(test, known); + KUNIT_EXPECT_STREQ(test, b->name, "J516M"); + KUNIT_EXPECT_STREQ(test, b->debugfs, "dcp-j516m"); + KUNIT_EXPECT_STREQ(test, b->machine, "apple,j516m"); + KUNIT_EXPECT_STREQ(test, b->soc, "apple,t6034"); + KUNIT_EXPECT_STREQ(test, b->handoff, "apple,t6031-handoff"); + KUNIT_EXPECT_STREQ(test, b->firmware_uuid, J516C_DCP_IMAGE); + KUNIT_EXPECT_EQ(test, b->panel_width, 3456); + KUNIT_EXPECT_EQ(test, b->panel_height, 2234); + KUNIT_EXPECT_TRUE(test, b->promotion); + KUNIT_EXPECT_TRUE(test, b->base_edid); + KUNIT_EXPECT_TRUE(test, b->panel_nits); + KUNIT_EXPECT_TRUE(test, dcp_v14_board_stamps_swaps(b, false)); + KUNIT_EXPECT_TRUE(test, dcp_v14_board_admits(b, J516C_DCP_IMAGE)); + KUNIT_EXPECT_FALSE(test, dcp_v14_board_admits(b, T6030_DCP_IMAGE)); + /* Neither the J516C record nor the J514M one. */ + KUNIT_EXPECT_PTR_NE(test, b, board_for("apple,t6031-dcp", j516c, &known)); + KUNIT_EXPECT_PTR_NE(test, b, board_for("apple,t6034-dcp", j514m, &known)); + /* Its name on a T6031 root is not a J516M. */ + KUNIT_EXPECT_NULL(test, board_for("apple,t6031-dcp", j516m_wrong_soc, &known)); +} + +/* A T6031 DCP on any other T6034, or on a J514M, has no record: refused. */ static void v14_board_t6031_other_boards(struct kunit *test) { bool known; - KUNIT_EXPECT_NULL(test, board_for("apple,t6031-dcp", j516m, &known)); + KUNIT_EXPECT_NULL(test, board_for("apple,t6031-dcp", t6034_other, &known)); + KUNIT_EXPECT_TRUE(test, known); + KUNIT_EXPECT_NULL(test, board_for("apple,t6031-dcp", j514m, &known)); KUNIT_EXPECT_TRUE(test, known); /* Not a 14.x internal DCP at all. */ KUNIT_EXPECT_NULL(test, board_for("apple,t8112-dcp", j516c, &known)); @@ -157,6 +220,7 @@ static void v14_board_unchanged(struct kunit *test) KUNIT_EXPECT_TRUE(test, b->promotion); KUNIT_EXPECT_FALSE(test, b->log_bringup); KUNIT_EXPECT_EQ(test, b->ctm_set, 0); + KUNIT_EXPECT_FALSE(test, b->base_edid); KUNIT_EXPECT_TRUE(test, dcp_v14_board_admits(b, T6030_DCP_IMAGE)); KUNIT_EXPECT_FALSE(test, dcp_v14_board_admits(b, J613_DCP_IMAGE)); /* The T6030 record serves a T6030 DCP on any machine, as before. */ @@ -171,6 +235,7 @@ static void v14_board_unchanged(struct kunit *test) KUNIT_EXPECT_EQ(test, b->panel_height, 1664); KUNIT_EXPECT_FALSE(test, b->promotion); KUNIT_EXPECT_FALSE(test, b->log_bringup); + KUNIT_EXPECT_FALSE(test, b->base_edid); KUNIT_EXPECT_FALSE(test, dcp_v14_board_admits(b, T6030_DCP_IMAGE)); /* A T8122 DCP on a T6031 machine has no record. */ @@ -247,9 +312,50 @@ static void v14_swap_timestamps_encoding(struct kunit *test) } } +/* + * J504 (14" M3 MacBook Pro): the J613 image on the T8122 DCP, its own 3024x1964 + * ProMotion panel, the qualified level block (brightness) and unstamped swaps. The other T8122 + * Macs (J433, J434) have no record. + */ +static void v14_board_j504(struct kunit *test) +{ + const struct dcp_v14_board *b, *air; + bool known; + + b = board_for("apple,t8122-dcp", j504, &known); + KUNIT_ASSERT_NOT_NULL(test, b); + air = board_for("apple,t8122-dcp", j613, &known); + KUNIT_ASSERT_NOT_NULL(test, air); + KUNIT_EXPECT_PTR_NE(test, b, air); + KUNIT_EXPECT_STREQ(test, b->name, "J504"); + KUNIT_EXPECT_STREQ(test, b->machine, "apple,j504"); + KUNIT_EXPECT_STREQ(test, b->handoff, "apple,t8122-handoff"); + KUNIT_EXPECT_STREQ(test, b->firmware_uuid, J613_DCP_IMAGE); + KUNIT_EXPECT_EQ(test, b->panel_width, 3024); + KUNIT_EXPECT_EQ(test, b->panel_height, 1964); + KUNIT_EXPECT_TRUE(test, b->promotion); + KUNIT_EXPECT_TRUE(test, b->log_bringup); + KUNIT_EXPECT_TRUE(test, b->panel_nits); + KUNIT_EXPECT_FALSE(test, b->base_edid); + KUNIT_EXPECT_EQ(test, b->ctm_set, air->ctm_set); + KUNIT_EXPECT_EQ(test, b->ctm_get, air->ctm_get); + KUNIT_EXPECT_TRUE(test, dcp_v14_board_admits(b, J613_DCP_IMAGE)); + KUNIT_EXPECT_FALSE(test, dcp_v14_board_admits(b, T6030_DCP_IMAGE)); + KUNIT_EXPECT_FALSE(test, dcp_v14_board_admits(b, J516C_DCP_IMAGE)); + KUNIT_EXPECT_FALSE(test, dcp_v14_board_stamps_swaps(b, false)); + + KUNIT_EXPECT_NULL(test, board_for("apple,t8122-dcp", j433, &known)); + KUNIT_EXPECT_TRUE(test, known); + /* A J504 root with another SoC's DCP gets no J504 record. */ + KUNIT_EXPECT_NULL(test, board_for("apple,t6031-dcp", j504, &known)); +} + static struct kunit_case v14_board_cases[] = { + KUNIT_CASE(v14_board_j504), KUNIT_CASE(v14_board_j516c), KUNIT_CASE(v14_board_j514c), + KUNIT_CASE(v14_board_j514m), + KUNIT_CASE(v14_board_j516m), KUNIT_CASE(v14_board_t6031_other_boards), KUNIT_CASE(v14_board_j516c_image), KUNIT_CASE(v14_board_unchanged), diff --git a/drivers/gpu/drm/asahi/Kconfig b/drivers/gpu/drm/asahi/Kconfig index d383802ee8825..0df72bf32ae5b 100644 --- a/drivers/gpu/drm/asahi/Kconfig +++ b/drivers/gpu/drm/asahi/Kconfig @@ -79,11 +79,21 @@ config DRM_ASAHI_DEBUG_ALLOCATOR Say N unless you are debugging firmware structures or porting to a new firmware version. +config DRM_ASAHI_UAT_ADOPTION + bool + help + The firmware UAT handoff adoption shared by the G15 backend and the + T8122 runtime (g15/uat.rs, g15/regs.rs). + config DRM_ASAHI_M3_T8122 bool "M3 MacBook Air GPU runtime (T8122, 14.8.3 firmware)" depends on DRM_ASAHI - # The runtime adopts the firmware's UAT through the G15 backend's handoff helpers. - depends on DRM_ASAHI_G15 + # The runtime adopts the firmware's UAT as the G15 backend does, without + # needing that backend: M3 Pro/Max keep their own setting. + # Its PMP votes call apple-pmp directly (m3_device.rs). + depends on APPLE_PMP=y || (APPLE_PMP=m && DRM_ASAHI=m) + select DRM_ASAHI_UAT_ADOPTION + select APPLE_T8122_GPU_PMP_LINK select CRYPTO_LIB_SHA256 default n help @@ -101,6 +111,7 @@ config DRM_ASAHI_G15 depends on DRM_APPLE=y || (DRM_APPLE=m && DRM_ASAHI=m) select APPLE_T6030_GPU_PMP_LINK select CRYPTO_LIB_SHA256 + select DRM_ASAHI_UAT_ADOPTION default y help Backend for the M3 Pro (T6030) and M3 Max (T6031) GPUs on the diff --git a/drivers/gpu/drm/asahi/Makefile b/drivers/gpu/drm/asahi/Makefile index 890d47c40af6b..b39d2552dd900 100644 --- a/drivers/gpu/drm/asahi/Makefile +++ b/drivers/gpu/drm/asahi/Makefile @@ -5,6 +5,7 @@ aurora-y := asahi_core.o fwid.o legacy_sched.o sysfs.o g17/sync_input.o g17/sync CFLAGS_g17/trace.o := -I$(src)/g17 aurora-$(CONFIG_DRM_ASAHI_G15) += g15/glue.o +aurora-$(CONFIG_DRM_ASAHI_UAT_ADOPTION) += g15/uat_glue.o aurora-$(CONFIG_DRM_ASAHI_G16) += g16/glue.o diff --git a/drivers/gpu/drm/asahi/asahi_core.rs b/drivers/gpu/drm/asahi/asahi_core.rs index b970691651032..bd69152c3ce75 100644 --- a/drivers/gpu/drm/asahi/asahi_core.rs +++ b/drivers/gpu/drm/asahi/asahi_core.rs @@ -17,6 +17,10 @@ mod fw; mod fwid; #[cfg(CONFIG_DRM_ASAHI_G15)] mod g15; +// Without the G15 backend, only the UAT adoption the T8122 runtime shares with it. +#[cfg(all(CONFIG_DRM_ASAHI_UAT_ADOPTION, not(CONFIG_DRM_ASAHI_G15)))] +#[path = "g15/adopt.rs"] +mod g15; mod g17; mod gem; diff --git a/drivers/gpu/drm/asahi/g15/adopt.rs b/drivers/gpu/drm/asahi/g15/adopt.rs new file mode 100644 index 0000000000000..5dd54b04aaec6 --- /dev/null +++ b/drivers/gpu/drm/asahi/g15/adopt.rs @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT + +//! Without the G15 backend (`CONFIG_DRM_ASAHI_G15=n`), the parts of it the T8122 runtime uses to +//! adopt the firmware's UAT: the handoff window ([`uat`]), its mappings ([`regs`]) and the +//! hardware constants they name ([`hw`]). Nothing here probes a device. + +// Only the adoption is used; the rest of these files serves the G15 backend. +#![allow(dead_code)] + +// hw.rs's `t6031` submodule is cfg-gated on G15; were it built here, a #[path]-loaded file +// would look for it at g15/t6031.rs, not g15/hw/t6031.rs. +#[path = "hw.rs"] +pub(crate) mod hw; +#[path = "regs.rs"] +pub(crate) mod regs; +#[path = "uat.rs"] +pub(crate) mod uat; + +use kernel::prelude::*; + +extern "C" { + fn asahi_g15_memory_mode(start: u64, size: u64) -> u32; +} + +/// WB for complete reserved RAM, WC for aligned non-RAM carveouts; reject everything else. +pub(crate) fn memory_mode(start: u64, size: u64) -> Result { + // SAFETY: Only queries resources and page metadata; it does not create a mapping. + match unsafe { asahi_g15_memory_mode(start, size) } { + 0 => Err(EINVAL), + mode => Ok(mode), + } +} diff --git a/drivers/gpu/drm/asahi/g15/board.rs b/drivers/gpu/drm/asahi/g15/board.rs index f9682b2ead10c..5bb672fce6c49 100644 --- a/drivers/gpu/drm/asahi/g15/board.rs +++ b/drivers/gpu/drm/asahi/g15/board.rs @@ -158,6 +158,7 @@ pub(crate) fn hardware_record( }; } let inputs = record::Inputs { + chip_id: cfg.chip_id, props, zones: &zones, main: &main, diff --git a/drivers/gpu/drm/asahi/g15/board/record.rs b/drivers/gpu/drm/asahi/g15/board/record.rs index 119a692064391..e20116f513a16 100644 --- a/drivers/gpu/drm/asahi/g15/board/record.rs +++ b/drivers/gpu/drm/asahi/g15/board/record.rs @@ -183,6 +183,8 @@ pub(crate) struct IoSlot { /// Everything the record is built from. pub(crate) struct Inputs<'a> { + /// SoC identity of this G15C record. + pub(crate) chip_id: u32, pub(crate) props: [u32; PROPS.len()], /// `apple,power-zones` cells (triples). pub(crate) zones: &'a [u32], @@ -458,7 +460,7 @@ fn hwdata_b(out: &mut [u8], i: &Inputs<'_>, t: &Tables) -> R<()> { put32(out, IOMAPS + 32 * slot as usize + 0x18, 1)?; } // Identity and flags. - put32(out, 0xa28, 0x6031)?; + put32(out, 0xa28, i.chip_id)?; put32(out, 0xa2c, 1)?; put32(out, 0xa30, 2)?; for at in [0xa38, 0xa3c, 0xa40, 0xa50, 0xa58, 0xa60] { @@ -848,6 +850,9 @@ pub(crate) fn cross_check(built: &[u8], file: &[u8]) -> Option<(usize, u32, u32) /// Builds the record into `out` (zeroed first) from the inputs. pub(crate) fn build(out: &mut [u8], i: &Inputs<'_>) -> R<()> { + if !matches!(i.chip_id, 0x6031 | 0x6034) { + return Err("unsupported G15C record SoC"); + } if out.len() != SIZE { return Err("record of another size"); } @@ -950,6 +955,7 @@ mod tests { fn inputs<'a>(main: &'a [Opp], cs: &'a [Opp], slots: &'a [IoSlot]) -> Inputs<'a> { Inputs { + chip_id: 0x6031, props: props(), zones: &[], main, @@ -966,6 +972,31 @@ mod tests { } } + #[test] + fn t6034_identity_and_six_memory_channels() { + let main = main_opps(); + let cs = [opp(24, [635; CLUSTERS])]; + let slots = [IoSlot { + slot: 11, + pa: 0x220000000, + va: 0xfffffc2068000000, + total: 6 * 0xd8000, + element: 0xd8000, + writable: true, + }]; + let mut input = inputs(&main, &cs, &slots); + input.chip_id = 0x6034; + let mut out = vec![0u8; SIZE]; + build(&mut out, &input).unwrap(); + assert_eq!(get(&out, 0xa28), 0x6034); + assert_eq!(get(&out, IOMAPS + 32 * 11 + 0x10), 6 * 0xd8000); + assert_eq!(get(&out, IOMAPS + 32 * 11 + 0x14), 0xd8000); + // The fused 30-core part still has four ten-slot physical clusters. + assert_eq!(get(&out, 0xb54), 40); + input.chip_id = 0x6030; + assert_eq!(build(&mut out, &input), Err("unsupported G15C record SoC")); + } + #[test] fn factors() { assert_eq!(F_1, 1.0f32.to_bits()); @@ -1500,6 +1531,7 @@ mod tests { }) .collect(); let i = Inputs { + chip_id: 0x6031, props, zones: &zones, main: &main, diff --git a/drivers/gpu/drm/asahi/g15/boot.rs b/drivers/gpu/drm/asahi/g15/boot.rs index 95269e152177b..d96384763e74d 100644 --- a/drivers/gpu/drm/asahi/g15/boot.rs +++ b/drivers/gpu/drm/asahi/g15/boot.rs @@ -461,6 +461,23 @@ pub(crate) fn admit( ) -> Result { let dev = pdev.as_ref(); let pmp = cfg.platform == hw::Platform::AdtWithPmp; + // J514C uses the same-die T6031 path on a normal boot. This does not qualify + // the inherited J516C reference words. Keep exact board AND SoC checks; + // T6034 boards use their own profile and never inherit T6031 admission. + // The remaining display, DT/ADT, full firmware identity, hardware identity + // and record-builder admission below is unchanged. + let j514c_board = cfg.chip_id == 0x6031 + && cfg.platform == hw::Platform::DeviceTree + && glue::machine(kernel::c_str!("apple,j514c")) + && glue::machine(kernel::c_str!("apple,t6031")); + let j514m_board = cfg.chip_id == 0x6034 + && cfg.platform == hw::Platform::DeviceTree + && glue::machine(kernel::c_str!("apple,j514m")) + && glue::machine(kernel::c_str!("apple,t6034")); + let j516m_board = cfg.chip_id == 0x6034 + && cfg.platform == hw::Platform::DeviceTree + && glue::machine(kernel::c_str!("apple,j516m")) + && glue::machine(kernel::c_str!("apple,t6034")); if pmp { if !glue::board() { return Err(ENODEV); @@ -475,7 +492,9 @@ pub(crate) fn admit( } return Err(err); } - } else if !glue::machine(cfg.machine) { + } else if (cfg.chip_id == 0x6034 && !j514m_board && !j516m_board) + || (!glue::machine(cfg.machine) && !j514c_board) + { dev_err!(dev, "G15: not a {} machine\n", cfg.name); return Err(ENODEV); } else { @@ -490,9 +509,24 @@ pub(crate) fn admit( return Err(err); } } + if j514c_board || j514m_board || j516m_board { + if let hw::Board::DeviceTree(reference) = cfg.board { + dev_warn!( + dev, + "{} bring-up: unqualified J516C reference: max_power_mw={} relative_power={:?} fast_die_mask={:#018x} alarm_mask={:#018x}; OPP powers are boot-loader stand-ins\n", + cfg.name, + reference.max_power_mw, + reference.relative_power, + reference.fast_die_mask, + reference.alarm_mask + ); + } + } let adt = adt::read(dev, cfg) .inspect_err(|e| dev_err!(dev, "GPU regions not admitted: {:?}\n", e))?; - identity::firmware(dev, &adt, cfg.firmware) + // T6034 requires complete identities; the older profiles keep their + // existing explicitly requested bring-up prefix policy. + identity::firmware(dev, &adt, cfg.firmware, cfg.chip_id != 0x6034) .inspect_err(|e| dev_err!(dev, "loaded GFX TEXT identity mismatch: {:?}\n", e))?; dev_info!(dev, "M3: firmware identity accepted\n"); if cfg.board == hw::Board::None { @@ -645,6 +679,19 @@ pub(crate) fn start( ); return Err(eproto()); } + if cfg.chip_id == 0x6034 + && glue::machine(kernel::c_str!("apple,j516m")) + && !hw::j516m::identity_matches(id.version, id.counts, id.cores) + { + dev_err!( + d, + "J516M powered identity is not the 30-core G15C: version {:#x} counts {:#x} core-mask {:#x}\n", + id.version, + id.counts, + id.cores + ); + return Err(eproto()); + } // Binning: any non-empty enabled set in each cluster, nothing above the core slots. let clusters = cfg.num_clusters as usize; let slots = cfg.core_slots(); diff --git a/drivers/gpu/drm/asahi/g15/glue.c b/drivers/gpu/drm/asahi/g15/glue.c index 2a0346228c1e5..66730228704ac 100644 --- a/drivers/gpu/drm/asahi/g15/glue.c +++ b/drivers/gpu/drm/asahi/g15/glue.c @@ -29,9 +29,6 @@ void asahi_g15_release_power(struct device *dev); void asahi_g15_reprobe(void); void asahi_g15_report_loader_gpu(void); int asahi_g15_adt_phram(u64 *start, u64 *size); -bool asahi_g15_ram_disjoint(u64 start, u64 size); -bool asahi_g15_ram_within(u64 start, u64 size); -unsigned int asahi_g15_memory_mode(u64 start, u64 size); void __iomem *asahi_g15_ioremap_wc(u64 start, size_t size); bool asahi_g15_dma_coherent(struct device *dev); int asahi_g15_pmp_prepare(struct device *dev); @@ -55,6 +52,7 @@ void asahi_g15_report_loader_gpu(void) const char *compatible; } socs[] = { { "asahi,t6031-gpu", "apple,agx-t6031" }, + { "asahi,t6034-gpu", "apple,agx-t6034" }, { "asahi,t6030-gpu", "apple,agx-t6030" }, }; struct device_node *chosen, *np; @@ -145,7 +143,7 @@ int asahi_g15_pmp_prepare(struct device *dev) } /* - * T6031 has no PMP vote, but its first firmware start follows the native + * T6031/T6034 have no PMP vote, but its first firmware start follows the native * display as T6030's does: defer until that display is up. The display can * be off for this boot (no handoff, or not requested), so say once why. An * enabled display that is not published yet is said once too: if it never @@ -155,18 +153,36 @@ int asahi_g15_pmp_prepare(struct device *dev) int asahi_g15_display_prepare(struct device *dev) { struct device_node *np; + const char *compatible, *name; int ret; - if (!dev->of_node || !of_device_is_compatible(dev->of_node, "apple,agx-t6031")) + if (!dev->of_node) return -ENODEV; - ret = apple_drm_t6031_link_device(dev); + if (of_device_is_compatible(dev->of_node, "apple,agx-t6031")) { + compatible = "apple,t6031-display-subsystem"; + name = "T6031"; + ret = apple_drm_t6031_link_device(dev); + } else if (of_device_is_compatible(dev->of_node, "apple,agx-t6034")) { + compatible = of_machine_is_compatible("apple,j516m") ? + "apple,t6031-display-subsystem" : "apple,t6034-display-subsystem"; + name = "T6034"; + ret = apple_drm_t6034_link_device(dev); + } else { + return -ENODEV; + } if (ret != -EPROBE_DEFER) return ret; - np = of_find_compatible_node(NULL, NULL, "apple,t6031-display-subsystem"); + + np = of_find_compatible_node(NULL, NULL, compatible); if (!np || !of_device_is_available(np)) - dev_info_once(dev, "G15: waiting for the T6031 native display, which this boot did not enable (it needs the boot loader's display handoff, and apple_t6031_display.enable=1 except on the J516C)\n"); + dev_info_once(dev, + "G15: waiting for the %s native display, which this boot did not enable (it needs the boot loader's display handoff, and an admitted native-display board)\n", + name); else - dev_info_once(dev, "G15: waiting for the T6031 native display to come up: the GPU firmware starts only after the display is published\n"); + dev_info_once(dev, + "G15: waiting for the %s native display to come up: the GPU firmware starts only after the display is published\n", + name); + of_node_put(np); return ret; } @@ -275,13 +291,6 @@ int asahi_g15_adt_phram(u64 *start, u64 *size) return 0; } -/* The range is disjoint from System RAM (ADT region admission). */ -bool asahi_g15_ram_disjoint(u64 start, u64 size) -{ - return region_intersects(start, size, IORESOURCE_SYSTEM_RAM, IORES_DESC_NONE) == - REGION_DISJOINT; -} - /* * Whether DMA mappings of the device skip cache maintenance. The G15 firmware * objects rely on the DMA mapping cleaning their pages to the point of @@ -292,42 +301,6 @@ bool asahi_g15_dma_coherent(struct device *dev) return dev_is_dma_coherent(dev); } -/* - * Every page must be valid, System RAM and still reserved from the allocator. - * REGION_INTERSECTS alone also accepts RAM mixed with undefined memory holes. - */ -bool asahi_g15_ram_within(u64 start, u64 size) -{ - u64 end, pa; - - if (!size || !IS_ALIGNED(start, PAGE_SIZE) || - !IS_ALIGNED(size, PAGE_SIZE) || check_add_overflow(start, size, &end)) - return false; - for (pa = start; pa < end; pa += PAGE_SIZE) { - unsigned long pfn = PHYS_PFN(pa); - - if (!pfn_valid(pfn) || !page_is_ram(pfn) || - !PageReserved(pfn_to_page(pfn))) - return false; - } - return true; -} - -/* One classification for every adopted-UAT and firmware-region CPU mapping. */ -unsigned int asahi_g15_memory_mode(u64 start, u64 size) -{ - u64 end; - - if (!size || !IS_ALIGNED(start, PAGE_SIZE) || - !IS_ALIGNED(size, PAGE_SIZE) || check_add_overflow(start, size, &end)) - return 0; - if (asahi_g15_ram_within(start, size)) - return MEMREMAP_WB; - if (asahi_g15_ram_disjoint(start, size)) - return MEMREMAP_WC; - return 0; -} - /* The inherited RTKit buffer inside firmware DATA. */ void __iomem *asahi_g15_ioremap_wc(u64 start, size_t size) { diff --git a/drivers/gpu/drm/asahi/g15/hw.rs b/drivers/gpu/drm/asahi/g15/hw.rs index b211088310210..0e295f98376e0 100644 --- a/drivers/gpu/drm/asahi/g15/hw.rs +++ b/drivers/gpu/drm/asahi/g15/hw.rs @@ -7,7 +7,12 @@ use core::ops::Range; +#[cfg(CONFIG_DRM_ASAHI_G15)] pub(crate) mod t6031; +#[cfg(CONFIG_DRM_ASAHI_G15)] +pub(crate) mod t6034; +#[cfg(CONFIG_DRM_ASAHI_G15)] +pub(crate) mod j516m; /// Identification register values of a qualified G15S. pub(crate) struct HwId { @@ -91,6 +96,7 @@ pub(crate) struct ComputeRegs { } /// The T6030 configuration. +#[cfg(CONFIG_DRM_ASAHI_G15)] pub(crate) mod t6030 { use super::super::Config; use super::{ComputeRegs, FirmwareBuild, HwId, Layout}; @@ -175,6 +181,69 @@ pub(crate) mod t6030 { 0xe7, 0x9b, 0xb9, 0xb0, 0x22, 0x09, 0xdb, 0x53, ], }, + // J514S firmware measured on the 14.7 boot chain; desktop rendering + // was verified with the bring-up prefix override (issue #247). + FirmwareBuild { + name: "J514S cd05 firmware (14.7 boot chain)", + machine: Some(kernel::c_str!("apple,j514s")), + text_size: 0x5c000, + data_size: 0x114000, + marker: 0x58e88, + text_sha256: [ + 0xcd, 0x05, 0xaf, 0x6a, 0x82, 0x8b, 0x52, 0xe4, + 0xc2, 0xfe, 0xd2, 0x00, 0x86, 0xd3, 0xd1, 0x8a, + 0x7d, 0xb4, 0x2e, 0x03, 0xa8, 0xfd, 0x6f, 0x83, + 0x54, 0xf9, 0xf0, 0x6e, 0x0a, 0x61, 0x36, 0x3e, + ], + }, + // Some J516S units on the same 14.7 boot chain load a different B0 + // TEXT image with identical sizes and marker. Pin its complete + // measured digest for the J516S only. + FirmwareBuild { + name: "J516S cd05 firmware (14.7 boot chain)", + machine: Some(kernel::c_str!("apple,j516s")), + text_size: 0x5c000, + data_size: 0x114000, + marker: 0x58e88, + text_sha256: [ + 0xcd, 0x05, 0xaf, 0x6a, 0x82, 0x8b, 0x52, 0xe4, + 0xc2, 0xfe, 0xd2, 0x00, 0x86, 0xd3, 0xd1, 0x8a, + 0x7d, 0xb4, 0x2e, 0x03, 0xa8, 0xfd, 0x6f, 0x83, + 0x54, 0xf9, 0xf0, 0x6e, 0x0a, 0x61, 0x36, 0x3e, + ], + }, + // J514S (14-inch) firmware measured on the 14.7 boot chain with + // system firmware 26.6.2; the GPU reached READY with the bring-up + // prefix override (issue #247). + FirmwareBuild { + name: "J514S 4118 firmware (14.7 boot chain)", + machine: Some(kernel::c_str!("apple,j514s")), + text_size: 0x5c000, + data_size: 0x114000, + marker: 0x58e88, + text_sha256: [ + 0x41, 0x18, 0x33, 0xa7, 0xde, 0xd7, 0x73, 0xfe, + 0xea, 0xc4, 0xa1, 0x81, 0x55, 0x2e, 0x3f, 0xf5, + 0x58, 0x2e, 0xaf, 0x44, 0x35, 0xf2, 0xdd, 0x8f, + 0x62, 0x0c, 0x1e, 0xd0, 0xb3, 0x1d, 0xf1, 0xb0, + ], + }, + // J516S (16-inch) firmware measured on the 14.7 boot chain with + // system firmware 26.6.2; the GPU reached READY with the bring-up + // prefix override (issue #247). + FirmwareBuild { + name: "J516S 4118 firmware (14.7 boot chain)", + machine: Some(kernel::c_str!("apple,j516s")), + text_size: 0x5c000, + data_size: 0x114000, + marker: 0x58e88, + text_sha256: [ + 0x41, 0x18, 0x33, 0xa7, 0xde, 0xd7, 0x73, 0xfe, + 0xea, 0xc4, 0xa1, 0x81, 0x55, 0x2e, 0x3f, 0xf5, + 0x58, 0x2e, 0xaf, 0x44, 0x35, 0xf2, 0xdd, 0x8f, + 0x62, 0x0c, 0x1e, 0xd0, 0xb3, 0x1d, 0xf1, 0xb0, + ], + }, ], machine: kernel::c_str!("apple,t6030"), platform: super::Platform::AdtWithPmp, diff --git a/drivers/gpu/drm/asahi/g15/hw/j516m.rs b/drivers/gpu/drm/asahi/g15/hw/j516m.rs new file mode 100644 index 0000000000000..1ae58fe1a365d --- /dev/null +++ b/drivers/gpu/drm/asahi/g15/hw/j516m.rs @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT + +//! Measured J516M/T6034 30-core profile. Share the six-channel G15C layout +//! with J514M, but retain independent machine, firmware and fused-core admission. +//! Native rendering is verified; inherited J516C power/reference values remain +//! unqualified for sustained power and thermal behavior on this board. + +use super::super::Config; +use super::FirmwareBuild; + +pub(crate) const CONFIG: Config = Config { + machine: kernel::c_str!("apple,j516m"), + firmware: &[FirmwareBuild { + name: "J516M RTKit 2419.140.12 (power qualification pending)", + machine: Some(kernel::c_str!("apple,j516m")), + text_size: 0x64000, + data_size: 0x140000, + marker: 0x5cf28, + text_sha256: [ + 0x4c, 0xa2, 0x4b, 0x65, 0x8f, 0x8e, 0xbe, 0x7c, 0x27, 0x37, 0x5f, 0xdf, 0x38, 0xe4, + 0x1e, 0x5d, 0xaf, 0x86, 0x32, 0x51, 0x50, 0x77, 0xb5, 0x37, 0xca, 0x19, 0xe6, 0xd0, + 0xdc, 0x77, 0x04, 0xb7, + ], + }], + ..super::t6034::CONFIG +}; + +/// The 14-core-CPU, 30-core-GPU J516M: its G15C revision and counts, and exactly 30 enabled +/// cores. Which cores are fused off differs between Macs of the same bin, so the mask itself is +/// not pinned (the per-cluster plausibility check in `start()` still applies). +pub(crate) const ENABLED_CORES: u32 = 30; + +pub(crate) fn identity_matches(version: u32, counts: u32, cores: u64) -> bool { + version == 0x07041100 && counts == 0x0021040a && cores.count_ones() == ENABLED_CORES +} diff --git a/drivers/gpu/drm/asahi/g15/hw/t6031.rs b/drivers/gpu/drm/asahi/g15/hw/t6031.rs index 8bac33989db64..68a9b6704fe7a 100644 --- a/drivers/gpu/drm/asahi/g15/hw/t6031.rs +++ b/drivers/gpu/drm/asahi/g15/hw/t6031.rs @@ -1,6 +1,9 @@ // SPDX-License-Identifier: GPL-2.0-only OR MIT -//! T6031 (M3 Max, G15C) configuration, admitted on J516C only. +//! T6031 (M3 Max, G15C) configuration, qualified on J516C only. +//! +//! J514C uses these reference words on normal boots after its board, firmware, +//! and hardware checks pass. This is not J514C power/thermal qualification. //! //! One die, four clusters of ten core slots. The firmware is the same RTKit 2419 generation as //! the T6030's and the initdata graph keeps the T6030 canonical VAs; what differs is the SoC @@ -129,14 +132,16 @@ pub(crate) const CONFIG: Config = Config { version: 0x07041100, counts: 0x0021040a, }], - // The stubs the boot chains of this J516C leave loaded (RTKit-2419.140.12): the macOS 14.7 - // chain's and the macOS 14.8 boot volume's. Same segment sizes and marker; the layout, board - // images and initdata below do not depend on which one is loaded. A further build can be - // admitted for one boot with `g15_accept_text_prefix`, which logs its digest. + // The stubs the boot chains of J516Cs leave loaded (RTKit-2419.140.12): the macOS 14.7 + // chain's, the macOS 14.8 boot volume's and a third TEXT seen on two further J516Cs (omacom + // /linux-aurora#289). Same segment sizes and marker; the layout, board images and initdata + // below do not depend on which one is loaded. The names say where a digest was measured, + // not that it identifies one build. A further digest can be admitted for one boot with + // `g15_accept_text_prefix`, which logs it. firmware: &[ FirmwareBuild { name: "macOS 14.7 stub firmware (iBoot-10151.140.19.700.2), J516C", - machine: None, + machine: Some(kernel::c_str!("apple,j516c")), text_size: 0x64000, data_size: 0x140000, marker: 0x5cf28, @@ -148,7 +153,7 @@ pub(crate) const CONFIG: Config = Config { }, FirmwareBuild { name: "macOS 14.8 stub firmware, J516C", - machine: None, + machine: Some(kernel::c_str!("apple,j516c")), text_size: 0x64000, data_size: 0x140000, marker: 0x5cf28, @@ -158,9 +163,56 @@ pub(crate) const CONFIG: Config = Config { 0x9d, 0x6b, 0xcd, 0xa0, 0x26, 0xcf, ], }, + // Two J516Cs (iBoot2 iBoot-10151.140.19.700.2, OS firmware 14.7; iBoot1 mBoot-20457.1.29 + // and mBoot-20457.41.3) load this TEXT. On the second, 10 boots, glxinfo on the M3 Max + // renderer and a GLES compute job with no mismatches, no GPU faults (#289). + FirmwareBuild { + name: "J516C stub firmware, TEXT 125f0497 (seen with iBoot-10151.140.19.700.2)", + machine: Some(kernel::c_str!("apple,j516c")), + text_size: 0x64000, + data_size: 0x140000, + marker: 0x5cf28, + text_sha256: [ + 0x12, 0x5f, 0x04, 0x97, 0xc7, 0x90, 0x4f, 0xde, 0x87, 0xb0, 0x5a, 0x92, 0x64, + 0xa8, 0x8c, 0xf0, 0x3b, 0xdb, 0x35, 0x72, 0xa1, 0x71, 0x5c, 0xec, 0x91, 0xbd, + 0x0f, 0x9b, 0x78, 0x24, 0x55, 0x44, + ], + }, + // Measured by the normal driver on J514C's 14.7 boot chain (system + // firmware 26.5.2). Short native GL/Vulkan and normal-login checks passed; + // power/thermal qualification remains open. Exact board identity is required. + FirmwareBuild { + name: "J514C macOS 14.7 boot-chain firmware", + machine: Some(kernel::c_str!("apple,j514c")), + text_size: 0x64000, + data_size: 0x140000, + marker: 0x5cf28, + text_sha256: [ + 0x66, 0x99, 0x13, 0xfb, 0xa2, 0x73, 0x6e, 0x4b, 0x8f, 0x8a, 0x0f, 0x81, + 0xea, 0xdc, 0x5a, 0xc0, 0x0c, 0x9d, 0xc5, 0x1f, 0xdd, 0x4c, 0x9d, 0x37, + 0x70, 0xc6, 0x6d, 0x2b, 0x0a, 0x1e, 0x87, 0x86, + ], + }, + // The same TEXT as the J516C row above, on one J514C (OS firmware 14.7, system firmware + // 26.6.2). With `g15_accept_text_prefix`, 3 boots with the GPU up; OpenGL 4.6 accelerated + // and no asahi-g15 errors on the one checked; idle only. Exact board identity is + // required; Vulkan, load and power/thermal qualification remain open. + FirmwareBuild { + name: "J514C stub firmware, TEXT 125f0497", + machine: Some(kernel::c_str!("apple,j514c")), + text_size: 0x64000, + data_size: 0x140000, + marker: 0x5cf28, + text_sha256: [ + 0x12, 0x5f, 0x04, 0x97, 0xc7, 0x90, 0x4f, 0xde, 0x87, 0xb0, 0x5a, 0x92, 0x64, + 0xa8, 0x8c, 0xf0, 0x3b, 0xdb, 0x35, 0x72, 0xa1, 0x71, 0x5c, 0xec, 0x91, 0xbd, + 0x0f, 0x9b, 0x78, 0x24, 0x55, 0x44, + ], + }, ], - // The reference words and measured layout belong to the J516C, not - // every T6031 board (in particular, not the 14-inch J514C). + // This is the reference board. The exact J514C/T6031 pair also uses this + // configuration through normal admission, with the unmeasured reference + // power words reported explicitly for that chassis. machine: kernel::c_str!("apple,j516c"), platform: super::Platform::DeviceTree, layout: &LAYOUT, diff --git a/drivers/gpu/drm/asahi/g15/hw/t6034.rs b/drivers/gpu/drm/asahi/g15/hw/t6034.rs new file mode 100644 index 0000000000000..1c0ec130cc177 --- /dev/null +++ b/drivers/gpu/drm/asahi/g15/hw/t6034.rs @@ -0,0 +1,96 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT + +//! J514M/T6034 (M3 Max, G15C) measured boot-chain profile. +//! +//! The powered identity read on this J514M found four ten-slot clusters with +//! enabled masks [0x1fd, 0x1fd, 0x1fc, 0x1ed], or 30 enabled cores. Its ADT has +//! four voltage tables and six memory channels. The four-cluster G15C object +//! and command layouts below are inherited from T6031; they are not a native +//! macOS capture of this machine. The J516C power/reference words remain +//! unqualified for this board and are identified at admission. +//! +//! The loaded firmware identity below was measured after native display +//! publication on J514M. Runtime and power/thermal qualification remain +//! pending; this profile never permits the generic digest-prefix override. + +use super::super::Config; +use super::{FirmwareBuild, HwId, IoMap, Layout}; + +/// Six memory-cache elements, rather than the T6031 reference's eight. +const MCC_BYTES: u64 = 6 * 0xd_8000; +const IOMAP_GAP: u64 = 0x4000; + +/// Keep the shared G15C physical apertures and pack firmware VAs after the +/// smaller memory-cache aperture. No seventh or eighth element is mapped. +const fn iomaps() -> [IoMap; 17] { + let mut out = super::t6031::IOMAPS; + let mut va = out[0].va; + let mut k = 0; + while k < out.len() { + if out[k].slot == 11 { + out[k].map_bytes = MCC_BYTES; + } + out[k].va = va; + va += out[k].map_bytes + IOMAP_GAP; + k += 1; + } + out +} + +pub(crate) const IOMAPS: [IoMap; 17] = iomaps(); + +const fn record_slots() -> [(u32, u32, bool); 17] { + let mut out = [(0, 0, false); 17]; + let mut k = 0; + while k < out.len() { + out[k] = super::t6031::LAYOUT.record_slots[k]; + if IOMAPS[k].slot == 11 { + out[k].0 = MCC_BYTES as u32; + } + k += 1; + } + out +} + +const RECORD_SLOTS: [(u32, u32, bool); 17] = record_slots(); + +pub(crate) const LAYOUT: Layout = Layout { + iomaps: &IOMAPS, + record_slots: &RECORD_SLOTS, + ..super::t6031::LAYOUT +}; + +pub(crate) const CONFIG: Config = Config { + name: "T6034 G15C", + chip_id: 0x6034, + gpu_variant: crate::hw::GpuVariant::C, + // ID_VERSION's silicon revision byte: (0x07041100 >> 8) & 0xff. + gpu_revision: 0x11, + uat_ias: 42, + uat_oas: 42, + num_clusters: 4, + num_cores_per_cluster: 10, + hw_ids: &[HwId { + version: 0x07041100, + counts: 0x0021040a, + }], + firmware: &[FirmwareBuild { + name: "J514M RTKit 2419.140.12 (runtime qualification pending)", + machine: Some(kernel::c_str!("apple,j514m")), + text_size: 0x64000, + data_size: 0x140000, + marker: 0x5cf28, + text_sha256: [ + 0x4c, 0xa2, 0x4b, 0x65, 0x8f, 0x8e, 0xbe, 0x7c, 0x27, 0x37, 0x5f, 0xdf, 0x38, + 0xe4, 0x1e, 0x5d, 0xaf, 0x86, 0x32, 0x51, 0x50, 0x77, 0xb5, 0x37, 0xca, 0x19, + 0xe6, 0xd0, 0xdc, 0x77, 0x04, 0xb7, + ], + }], + machine: kernel::c_str!("apple,j514m"), + platform: super::Platform::DeviceTree, + layout: &LAYOUT, + board: super::Board::DeviceTree(&super::super::board::record::J516C), + // Binning changes enabled masks, not the four physical clusters or the + // ten slots per cluster used by these G15C command words. + compute: super::t6031::CONFIG.compute, +}; diff --git a/drivers/gpu/drm/asahi/g15/identity.rs b/drivers/gpu/drm/asahi/g15/identity.rs index 2bf95c8ad98db..4193a3cba9078 100644 --- a/drivers/gpu/drm/asahi/g15/identity.rs +++ b/drivers/gpu/drm/asahi/g15/identity.rs @@ -70,10 +70,12 @@ impl From<&FirmwareBuild> for Measured { /// Identifies the loaded firmware build: the pinned build, or `None` for a build admitted by /// its digest prefix (`g15_accept_text_prefix`). +/// With `allow_prefix` false, only a complete pinned identity may be admitted. pub(crate) fn firmware( dev: &device::Device, adt: &super::adt::GpuAdt, builds: &'static [FirmwareBuild], + allow_prefix: bool, ) -> Result> { let size = usize::try_from(adt.text.end - adt.text.start)?; let data_size = adt.data.end - adt.data.start; @@ -97,7 +99,14 @@ pub(crate) fn firmware( let qualified = builds .iter() .map(|b| (Measured::from(b), b.machine.map_or(true, glue::machine))); - match lookup::verdict(&m, qualified, super::params::accept_text_prefix()) { + // A profile may require exact identities even after its first build is + // pinned. Empty profiles remain measurement-only in either policy. + let accept_prefix = if !allow_prefix || builds.is_empty() { + 0 + } else { + super::params::accept_text_prefix() + }; + match lookup::verdict(&m, qualified, accept_prefix) { Verdict::Pinned(i) => { let build = builds.get(i).ok_or(EINVAL)?; dev_info!(dev, "GPU firmware build: {}\n", build.name); diff --git a/drivers/gpu/drm/asahi/g15/mod.rs b/drivers/gpu/drm/asahi/g15/mod.rs index 4cb221fb0a5df..05d3b3d5e9e63 100644 --- a/drivers/gpu/drm/asahi/g15/mod.rs +++ b/drivers/gpu/drm/asahi/g15/mod.rs @@ -139,7 +139,7 @@ impl Config { } /// OF match table of the G15 platform driver. -const OF_TABLE: kernel::device_id::IdArray = +const OF_TABLE: kernel::device_id::IdArray = kernel::device_id::IdArray::new([ ( of::DeviceId::new(c_str!("apple,agx-t6030")), @@ -149,6 +149,10 @@ const OF_TABLE: kernel::device_id::IdArray = of::DeviceId::new(c_str!("apple,agx-t6031")), &&hw::t6031::CONFIG, ), + ( + of::DeviceId::new(c_str!("apple,agx-t6034")), + &&hw::t6034::CONFIG, + ), ]); // Probe admission requires the native display before firmware starts (T6030 @@ -159,6 +163,7 @@ kernel::of_device_table!( [ of::DeviceId::new(c_str!("apple,agx-t6030")), of::DeviceId::new(c_str!("apple,agx-t6031")), + of::DeviceId::new(c_str!("apple,agx-t6034")), ] ); @@ -202,10 +207,18 @@ impl platform::Driver for Driver<'_> { // after probe_g15 started firmware would return an unbound device. try_pin_init!(Driver { _driver: { + // Not EPROBE_DEFER: a deferred device stays listed in devices_deferred until the + // deferred-probe work runs, even after activate()'s probe fails for good. Activation + // reprobes every unbound device; a device added later sees MODULE_READY set. if !MODULE_READY.load(Ordering::Acquire) { - return Err(EPROBE_DEFER); + return Err(ENODEV); } let cfg = *info.ok_or(ENODEV)?; + let cfg = if cfg.chip_id == 0x6034 && boot::glue::machine(c_str!("apple,j516m")) { + &hw::j516m::CONFIG + } else { + cfg + }; dev_info!(pdev.as_ref(), "G15: probing ({})\n", cfg.name); match crate::driver::AsahiPlatformDriver::probe_g15(pdev, cfg) { Ok(driver) => Some(driver), diff --git a/drivers/gpu/drm/asahi/g15/regs.rs b/drivers/gpu/drm/asahi/g15/regs.rs index 05a1b390b3dff..98e7d4c8cf78a 100644 --- a/drivers/gpu/drm/asahi/g15/regs.rs +++ b/drivers/gpu/drm/asahi/g15/regs.rs @@ -125,7 +125,7 @@ impl Mapping { if size == 0 { return Err(EINVAL); } - let mode = super::boot::glue::memory_mode(phys, size as u64)?; + let mode = super::memory_mode(phys, size as u64)?; if mode == bindings::MEMREMAP_WC as u32 { return Self::write_combined(phys, size); } @@ -252,6 +252,7 @@ impl Regs { /// Reads the identification words and the enabled-core mask (once the GPU is powered). A /// SoC with more than 32 core slots carries the mask in two words. + #[cfg(CONFIG_DRM_ASAHI_G15)] pub(crate) fn identity(&self, cfg: &super::Config) -> Result { let version = self.sgx.io().try_read32(SGX_ID)?; let counts = self.sgx.io().try_read32(SGX_ID + 0x10)?; diff --git a/drivers/gpu/drm/asahi/g15/uat.rs b/drivers/gpu/drm/asahi/g15/uat.rs index 0f91f7c9f0610..0f0aa01e23517 100644 --- a/drivers/gpu/drm/asahi/g15/uat.rs +++ b/drivers/gpu/drm/asahi/g15/uat.rs @@ -38,12 +38,14 @@ use kernel::{ bindings, device, io::Io, prelude::*, - sync::Arc, time::{delay::fsleep, Delta, Instant, Monotonic}, }; +#[cfg(CONFIG_DRM_ASAHI_G15)] +use kernel::sync::Arc; use super::hw; use super::regs::{mb, rmb, wmb, Mapping}; +#[cfg(CONFIG_DRM_ASAHI_G15)] use crate::driver::AsahiDrmDevice as AsahiDevice; use crate::{mmu, pgtable}; @@ -69,6 +71,7 @@ const fn indices(va: u64) -> [usize; 3] { } /// Creates the adopted UAT over the ADT regions (step 2 above). +#[cfg(CONFIG_DRM_ASAHI_G15)] pub(crate) fn adopt( dev: &AsahiDevice, cfg: &'static super::Config, @@ -201,6 +204,7 @@ pub(crate) struct Window { impl Window { /// Maps the UAT handoff regions ([`Mapping::region`]). + #[cfg(CONFIG_DRM_ASAHI_G15)] pub(crate) fn new(adt: &super::adt::GpuAdt) -> Result { Self::from_regions(adt.handoff.start, adt.ttbs.start, adt.tables.start, adt.shared_l2.start) } diff --git a/drivers/gpu/drm/asahi/g15/uat_glue.c b/drivers/gpu/drm/asahi/g15/uat_glue.c new file mode 100644 index 0000000000000..134ff4bb28ab6 --- /dev/null +++ b/drivers/gpu/drm/asahi/g15/uat_glue.c @@ -0,0 +1,59 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* + * C helpers of the UAT adoption (g15/uat.rs, g15/regs.rs), built for the G15 + * backend and for the T8122 runtime, which adopts the firmware's UAT the same + * way (CONFIG_DRM_ASAHI_UAT_ADOPTION). + */ +#include +#include +#include +#include +#include +#include + +bool asahi_g15_ram_disjoint(u64 start, u64 size); +bool asahi_g15_ram_within(u64 start, u64 size); +unsigned int asahi_g15_memory_mode(u64 start, u64 size); + +/* The range is disjoint from System RAM (ADT region admission). */ +bool asahi_g15_ram_disjoint(u64 start, u64 size) +{ + return region_intersects(start, size, IORESOURCE_SYSTEM_RAM, IORES_DESC_NONE) == + REGION_DISJOINT; +} + +/* + * Every page must be valid, System RAM and still reserved from the allocator. + * REGION_INTERSECTS alone also accepts RAM mixed with undefined memory holes. + */ +bool asahi_g15_ram_within(u64 start, u64 size) +{ + u64 end, pa; + + if (!size || !IS_ALIGNED(start, PAGE_SIZE) || + !IS_ALIGNED(size, PAGE_SIZE) || check_add_overflow(start, size, &end)) + return false; + for (pa = start; pa < end; pa += PAGE_SIZE) { + unsigned long pfn = PHYS_PFN(pa); + + if (!pfn_valid(pfn) || !page_is_ram(pfn) || + !PageReserved(pfn_to_page(pfn))) + return false; + } + return true; +} + +/* One classification for every adopted-UAT and firmware-region CPU mapping. */ +unsigned int asahi_g15_memory_mode(u64 start, u64 size) +{ + u64 end; + + if (!size || !IS_ALIGNED(start, PAGE_SIZE) || + !IS_ALIGNED(size, PAGE_SIZE) || check_add_overflow(start, size, &end)) + return 0; + if (asahi_g15_ram_within(start, size)) + return MEMREMAP_WB; + if (asahi_g15_ram_disjoint(start, size)) + return MEMREMAP_WC; + return 0; +} diff --git a/drivers/gpu/drm/asahi/m3/m3_params.rs b/drivers/gpu/drm/asahi/m3/m3_params.rs index 85033c88e4192..be675d60a730c 100644 --- a/drivers/gpu/drm/asahi/m3/m3_params.rs +++ b/drivers/gpu/drm/asahi/m3/m3_params.rs @@ -589,9 +589,9 @@ pub(crate) fn thermal_hot_param() -> (u64, bool) { /// Whether to start the runtime backend on a T8122 (`asahi.m3_backend`), and say why not. /// -/// The runtime starts only on the boards the T8122 table allows (the M3 MacBook Airs), with -/// `auto` and `runtime` alike: it has not run on any T8122, so nothing forces it onto another -/// board. The G15 manager backend is T6030-only. +/// The runtime starts only on the boards the T8122 table allows (the M3 MacBook Airs and the +/// 14" M3 MacBook Pro, `t8122_admission::T8122_BOARDS`), with `auto` and `runtime` alike: +/// nothing forces it onto another board. The G15 manager backend is T6030-only. pub(crate) fn t8122_backend(pdev: &platform::Device>) -> bool { let dev = pdev.as_ref(); match M3_BACKEND.load(Ordering::Relaxed) { @@ -610,7 +610,7 @@ pub(crate) fn t8122_backend(pdev: &platform::Device>) -> bool { _ => { dev_info!( dev, - "M3: no GPU backend on this T8122 board: the runtime backend may start only on the M3 MacBook Airs (J613, J615)\n" + "M3: no GPU backend on this T8122 board: the runtime backend may start only on the M3 MacBook Airs (J613, J615) and the 14\" M3 MacBook Pro (J504)\n" ); false } diff --git a/drivers/gpu/drm/asahi/m3/m3_runtime.rs b/drivers/gpu/drm/asahi/m3/m3_runtime.rs index 762c8bc26e75b..e521089c9ec46 100644 --- a/drivers/gpu/drm/asahi/m3/m3_runtime.rs +++ b/drivers/gpu/drm/asahi/m3/m3_runtime.rs @@ -1411,7 +1411,7 @@ fn adopt_uat(drm: &driver::AsahiDrmDevice, soc: &'static crate::m3::m3_soc::Soc, let range = |r: crate::m3::agx_resources::Region| r.base..r.base + r.size; let geometry = mmu::UatGeometry { ias: cfg.uat_ias.into(), oas: cfg.uat_oas }; let regions = mmu::AdoptedRegions { handoff: range(handoff), ttbs: range(ttbs), kernel_root: tables.base }; - let uat = mmu::Uat::new_adopted_with_user_upper(drm, geometry, ®ions, + let uat = mmu::Uat::new_adopted_ram_with_user_upper(drm, geometry, ®ions, profile == super::m3_profile::Profile::Legacy)?; let mut window = crate::g15::uat::Window::from_regions(handoff.base, ttbs.base, tables.base, shared_l2.base)?; window.bootstrap(drm.as_ref().as_ref(), &uat)?; diff --git a/drivers/gpu/drm/asahi/m3/m3_soc.rs b/drivers/gpu/drm/asahi/m3/m3_soc.rs index 7500822c4124c..3dcd15c896a48 100644 --- a/drivers/gpu/drm/asahi/m3/m3_soc.rs +++ b/drivers/gpu/drm/asahi/m3/m3_soc.rs @@ -284,9 +284,10 @@ pub(crate) static T8122: Soc = Soc { gpu_revision_id: hw::GpuRevisionID::C0, board: "apple,t8122", gpu: "apple,agx-t8122", - // The M3 MacBook Airs (13" J613, 15" J615). Allowed, not validated: the runtime has not run - // on either, and starts only behind a boot loader that hands the GPU over. - validated_boards: &[b"apple,j613", b"apple,j615"], + // The M3 MacBook Airs (13" J613, 15" J615) and the 14" M3 MacBook Pro (J504), which loads + // the same G15G image (`t8122_admission::T8122_BOARDS`). The runtime starts only behind a + // boot loader that hands the GPU over. + validated_boards: &crate::m3::t8122_admission::T8122_BOARDS, clusters: 1, cores_per_cluster: 10, mailbox_compatibles: &[ diff --git a/drivers/gpu/drm/asahi/m3/m3_thermal_policy.rs b/drivers/gpu/drm/asahi/m3/m3_thermal_policy.rs index 2ae70634ff556..1b2412b7f7809 100644 --- a/drivers/gpu/drm/asahi/m3/m3_thermal_policy.rs +++ b/drivers/gpu/drm/asahi/m3/m3_thermal_policy.rs @@ -271,6 +271,7 @@ mod zone_tests { } assert_eq!(required_zones(b"apple,j613\0"), 1); assert_eq!(required_zones(b"apple,j615\0"), 1); + assert_eq!(required_zones(b"apple,j504\0apple,t8122\0"), 1); } #[test] diff --git a/drivers/gpu/drm/asahi/m3/t8122_admission.rs b/drivers/gpu/drm/asahi/m3/t8122_admission.rs index fb280ebcde520..ff6d098f50a3c 100644 --- a/drivers/gpu/drm/asahi/m3/t8122_admission.rs +++ b/drivers/gpu/drm/asahi/m3/t8122_admission.rs @@ -4,6 +4,12 @@ use super::m3_profile::Profile; +/// The T8122 boards the M3 runtime starts on by default: the M3 MacBook Airs (13" J613, 15" J615) +/// and the 14" M3 MacBook Pro (J504). All three load the same 14.8.3 G15G image (UUID +/// `DF697F05-…`, checked separately by firmware admission). The other T8122 Macs (the J433 and +/// J434 iMacs) are not listed. +pub(crate) const T8122_BOARDS: [&[u8]; 3] = [b"apple,j613", b"apple,j615", b"apple,j504"]; + #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub(crate) struct Identity { pub(crate) active_cores: u32, @@ -195,6 +201,17 @@ pub(crate) fn read_identity_for( #[cfg(test)] mod tests { + use super::T8122_BOARDS; + + #[test] + fn the_t8122_runtime_boards_are_exactly_the_airs_and_the_14_inch_pro() { + // Exact: dropping the J504 or adding another T8122 Mac (J433, J434) must fail here. + assert_eq!(T8122_BOARDS, [&b"apple,j613"[..], b"apple,j615", b"apple,j504"]); + for other in [&b"apple,j433"[..], b"apple,j434", b"apple,t8122"] { + assert!(!T8122_BOARDS.contains(&other)); + } + } + use super::*; const G15G_C0: u32 = 0x0702_2000; diff --git a/drivers/gpu/drm/asahi/m3/t8122_start.rs b/drivers/gpu/drm/asahi/m3/t8122_start.rs index 737034dd6f8c1..f4fe2bae341aa 100644 --- a/drivers/gpu/drm/asahi/m3/t8122_start.rs +++ b/drivers/gpu/drm/asahi/m3/t8122_start.rs @@ -301,8 +301,8 @@ pub(crate) fn arm(dev: &device::Device, soc: &Soc) -> Result> e.mapping_count(), storage::IOMAP_BASE ); - // J613/J615 have no SoC die temperature zone yet, so a cap above the no-feedback limit runs - // the fanless GPU without any temperature feedback (`m3_thermal` holds the cap but gets no + // J615 and J504 have no SoC die temperature zone yet, so a cap above the no-feedback limit + // runs the GPU without any temperature feedback (`m3_thermal` holds the cap but gets no // reading). The runtime cap and the firmware ceiling stay equal, because the cap is at most // the no-feedback limit. if v.pstate_cap > knobs::PSTATE_CAP { diff --git a/drivers/gpu/drm/asahi/mmu.rs b/drivers/gpu/drm/asahi/mmu.rs index 4337024993025..34c697be9bdb7 100644 --- a/drivers/gpu/drm/asahi/mmu.rs +++ b/drivers/gpu/drm/asahi/mmu.rs @@ -505,10 +505,10 @@ fn lock_vm( Ok(VmExecGuard(unsafe { gpuvm.exec_lock(obj, interruptible)? })) } -#[cfg(any(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_G16))] +#[cfg(any(CONFIG_DRM_ASAHI_UAT_ADOPTION, CONFIG_DRM_ASAHI_G16))] pub(crate) struct VmReadGuard(VmExecGuard); -#[cfg(any(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_G16))] +#[cfg(any(CONFIG_DRM_ASAHI_UAT_ADOPTION, CONFIG_DRM_ASAHI_G16))] impl VmReadGuard { #[cfg(CONFIG_DRM_ASAHI_G15)] pub(crate) fn covers_range(&mut self, address: u64, size: u64, read: bool, write: bool) -> bool { @@ -2596,7 +2596,7 @@ impl Vm { /// Attach a status and job lifetime tracking before sharing a newly created user VM with /// queues, without the G17 canonical context views, shared-object footprints and idle /// residency reclaim of [`Self::with_status`]. Used by G15, whose user objects stay pinned. - #[cfg(any(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_G16))] + #[cfg(any(CONFIG_DRM_ASAHI_UAT_ADOPTION, CONFIG_DRM_ASAHI_G16))] pub(crate) fn with_tracked_status(mut self) -> Result { self.status = Some(Arc::pin_init( crate::g17::status::VmStatus::new(), @@ -2624,17 +2624,17 @@ impl Vm { /// and invalidated to the point of coherency first (never only invalidated: CPU-written lines /// may be dirty), so the copy sees what the GPU or a write-combined CPU view stored. The /// mappings cannot change during the copy (GPUVM exec lock). - #[cfg(any(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_G16))] + #[cfg(any(CONFIG_DRM_ASAHI_UAT_ADOPTION, CONFIG_DRM_ASAHI_G16))] pub(crate) fn read_user(&self, va: u64, buf: &mut [u8]) -> Result { self.read_lock()?.read_user(va, buf) } - #[cfg(any(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_G16))] + #[cfg(any(CONFIG_DRM_ASAHI_UAT_ADOPTION, CONFIG_DRM_ASAHI_G16))] pub(crate) fn read_lock(&self) -> Result { Ok(VmReadGuard(lock_vm(&self.gpuvm, None, false)?)) } - #[cfg(any(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_G16))] + #[cfg(any(CONFIG_DRM_ASAHI_UAT_ADOPTION, CONFIG_DRM_ASAHI_G16))] fn read_user_locked(inner: &mut VmInner, va: u64, buf: &mut [u8]) -> Result { let mut done = 0usize; while done < buf.len() { @@ -3477,7 +3477,7 @@ impl Drop for VmInner { /// Physical regions of a UAT whose handoff the generation has already established itself /// ([`Uat::new_adopted`]). None of them needs to be in the kernel linear map. -#[cfg(any(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_G16))] +#[cfg(any(CONFIG_DRM_ASAHI_UAT_ADOPTION, CONFIG_DRM_ASAHI_G16))] pub(crate) struct AdoptedRegions { /// The handoff region (PPL magic, lock and flush requests). pub(crate) handoff: Range, @@ -3500,7 +3500,7 @@ impl Uat { }) } - #[cfg(any(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_G16))] + #[cfg(any(CONFIG_DRM_ASAHI_UAT_ADOPTION, CONFIG_DRM_ASAHI_G16))] /// Map a region given by its physical range, write-combined. fn map_physical( range: &Range, @@ -3521,7 +3521,7 @@ impl Uat { let res: io::resource::Resource = unsafe { core::mem::transmute(kernel::types::Opaque::new(raw)) }; let flags = io::mem::MemFlag::WC; - #[cfg(CONFIG_DRM_ASAHI_G15)] + #[cfg(CONFIG_DRM_ASAHI_UAT_ADOPTION)] let flags = if reserved_ram { // G15 admits only whole reserved RAM pages or wholly non-RAM carveouts. if crate::g15::memory_mode(range.start, size as u64)? @@ -3534,7 +3534,7 @@ impl Uat { } else { flags }; - #[cfg(not(CONFIG_DRM_ASAHI_G15))] + #[cfg(not(CONFIG_DRM_ASAHI_UAT_ADOPTION))] let _ = reserved_ram; // SAFETY: The UAT regions are only accessed through this mapping by the CPU; // the GPU reaches them through its own translation. @@ -3545,7 +3545,7 @@ impl Uat { }) } - #[cfg(any(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_G16))] + #[cfg(any(CONFIG_DRM_ASAHI_UAT_ADOPTION, CONFIG_DRM_ASAHI_G16))] /// Creates a `Uat` for a handoff that the caller establishes itself (G15). /// /// This only maps the handoff and the TTBAT (write-combined); neither is written here. The @@ -3571,7 +3571,7 @@ impl Uat { /// Creates the same owned-RAM adopted UAT, choosing whether application contexts also /// name the firmware upper root. M4 qualifies only context 0 for firmware-upper access; /// its application TTBAT upper words stay zero. G15 preserves its existing shared upper. - #[cfg(any(CONFIG_DRM_ASAHI_G16, CONFIG_DRM_ASAHI_M3_T8122))] + #[cfg(CONFIG_DRM_ASAHI_G16)] pub(crate) fn new_adopted_with_user_upper( dev: &driver::AsahiDrmDevice, geometry: UatGeometry, @@ -3581,7 +3581,21 @@ impl Uat { Self::new_adopted_inner(dev, geometry, regions, map_kernel_to_user, false) } - #[cfg(any(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_G16))] + /// As [`Self::new_adopted_with_user_upper`], for regions that may be reserved System RAM: + /// each is mapped write-back when it is RAM and write-combined when it is a carveout, as + /// [`Self::new_adopted`] does. The M3 boot loaders leave the handoff and TTBAT regions in + /// the kernel's memory map as reserved RAM, which a write-combined mapping is refused for. + #[cfg(CONFIG_DRM_ASAHI_M3_T8122)] + pub(crate) fn new_adopted_ram_with_user_upper( + dev: &driver::AsahiDrmDevice, + geometry: UatGeometry, + regions: &AdoptedRegions, + map_kernel_to_user: bool, + ) -> Result { + Self::new_adopted_inner(dev, geometry, regions, map_kernel_to_user, true) + } + + #[cfg(any(CONFIG_DRM_ASAHI_UAT_ADOPTION, CONFIG_DRM_ASAHI_G16))] fn new_adopted_inner( dev: &driver::AsahiDrmDevice, geometry: UatGeometry, @@ -3672,13 +3686,13 @@ impl Uat { }) } - #[cfg(any(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_G16))] + #[cfg(any(CONFIG_DRM_ASAHI_UAT_ADOPTION, CONFIG_DRM_ASAHI_G16))] /// Root of the kernel lower `Vm`, for TTBAT context 0 of an adopted handoff. pub(crate) fn kernel_lower_root(&self) -> PhysicalAddr { self.kernel_lower_vm.ttb() } - #[cfg(any(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_G16))] + #[cfg(any(CONFIG_DRM_ASAHI_UAT_ADOPTION, CONFIG_DRM_ASAHI_G16))] /// Root whose driver-window entry names the second-level table of [`Self::kernel_vm`]'s /// driver window. With [`Self::new_adopted`] this is the shadow root that no context names. pub(crate) fn kernel_window_root(&self) -> PhysicalAddr { diff --git a/drivers/gpu/drm/asahi/pgtable.rs b/drivers/gpu/drm/asahi/pgtable.rs index 9fb2d0652e01e..0cc2fac3b340a 100644 --- a/drivers/gpu/drm/asahi/pgtable.rs +++ b/drivers/gpu/drm/asahi/pgtable.rs @@ -369,7 +369,7 @@ impl Prot { /// The protection bits of a leaf with this protection (no address, table type or non-global /// bits), for checking that a firmware leaf word round-trips through [`Self::from_pte`]. - #[cfg(any(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_G16))] + #[cfg(any(CONFIG_DRM_ASAHI_UAT_ADOPTION, CONFIG_DRM_ASAHI_G16))] pub(crate) const fn leaf_bits(&self) -> u64 { self.as_pte() } diff --git a/drivers/iommu/apple-dart-test.c b/drivers/iommu/apple-dart-test.c index dcb65db633d80..f5c8efc52e7f9 100644 --- a/drivers/iommu/apple-dart-test.c +++ b/drivers/iommu/apple-dart-test.c @@ -90,6 +90,108 @@ static void apple_dart_test_iommu_specifiers(struct kunit *test) } } +static void apple_dart_test_consumer_window(struct kunit *test) +{ + __be32 value[] = { cpu_to_be32(0x100), 0, cpu_to_be32(0x10), 0 }; + struct property property = { + .name = "apple,dma-range", + .length = sizeof(value), + .value = value, + }; + struct device_node node = { .properties = &property }; + struct of_phandle_args args = { .args_count = 1 }; + struct apple_dart *dart; + struct device *dev; + dma_addr_t dma_min, dma_max; + int i, ret; + + dev = kunit_device_register(test, "apple-dart-consumer-window-test"); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev); + dart = kunit_kzalloc(test, sizeof(*dart), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, dart); + dart->ias = 36; + dart->pgsize = SZ_16K; + dev->of_node = &node; + + /* J613's common scanout aperture must survive both DART defaults. */ + for (i = 0; i < 2; i++) { + dart->dma_min = i ? 0 : 0x10000000000; + dart->dma_max = i ? 0xffffeffff : 0x10fffffffff; + ret = apple_dart_parse_dma_window(dev, dart, &args, + &dma_min, &dma_max); + KUNIT_EXPECT_EQ(test, ret, 0); + KUNIT_EXPECT_EQ(test, dma_min, (dma_addr_t)0x10000000000); + KUNIT_EXPECT_EQ(test, dma_max, (dma_addr_t)0x10fffffffff); + } + + /* Domain allocation gives the consumer priority over five-cell args too. */ + args.args_count = 5; + args.args[3] = 0xf; + args.args[4] = 0xffff0000; + ret = apple_dart_parse_dma_window(dev, dart, &args, &dma_min, &dma_max); + KUNIT_EXPECT_EQ(test, ret, 0); + KUNIT_EXPECT_EQ(test, dma_min, (dma_addr_t)0x10000000000); + KUNIT_EXPECT_EQ(test, dma_max, (dma_addr_t)0x10fffffffff); + + /* An override must not make a malformed stream specifier acceptable. */ + args.args[3] = 0; + args.args[4] = 0; + KUNIT_EXPECT_EQ(test, apple_dart_parse_dma_window(dev, dart, &args, + &dma_min, &dma_max), -EINVAL); + + /* PIODMA is a different consumer of the same external display DART. */ + dev->of_node = NULL; + args.args_count = 1; + args.args[0] = 4; + ret = apple_dart_parse_dma_window(dev, dart, &args, &dma_min, &dma_max); + KUNIT_EXPECT_EQ(test, ret, 0); + KUNIT_EXPECT_EQ(test, dma_min, (dma_addr_t)0); + KUNIT_EXPECT_EQ(test, dma_max, (dma_addr_t)0xffffeffff); +} + +static void apple_dart_test_invalid_consumer_window(struct kunit *test) +{ + static const struct { + u64 base, size; + } windows[] = { + { 0, 0 }, + { U64_MAX - SZ_16K + 1, 2 * SZ_16K }, + { 1, SZ_16K }, + { 0, SZ_16K + 1 }, + { 0, BIT_ULL(37) }, + }; + __be64 value[2]; + struct property property = { + .name = "apple,dma-range", + .length = sizeof(value), + .value = value, + }; + struct device_node node = { .properties = &property }; + struct of_phandle_args args = { .args_count = 1 }; + struct apple_dart *dart; + struct device *dev; + dma_addr_t dma_min, dma_max; + int i; + + dev = kunit_device_register(test, "apple-dart-invalid-window-test"); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev); + dart = kunit_kzalloc(test, sizeof(*dart), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, dart); + dart->ias = 36; + dart->pgsize = SZ_16K; + dev->of_node = &node; + for (i = 0; i < ARRAY_SIZE(windows); i++) { + value[0] = cpu_to_be64(windows[i].base); + value[1] = cpu_to_be64(windows[i].size); + KUNIT_EXPECT_EQ(test, apple_dart_parse_dma_window(dev, dart, &args, + &dma_min, &dma_max), -EINVAL); + } + property.length = sizeof(__be32); + KUNIT_EXPECT_LT(test, apple_dart_parse_dma_window(dev, dart, &args, + &dma_min, &dma_max), 0); + dev->of_node = NULL; +} + static void apple_dart_test_before_attach(struct kunit *test) { struct apple_dart_master_cfg master = {}; @@ -1174,6 +1276,8 @@ static struct kunit_case apple_dart_test_cases[] = { KUNIT_CASE(apple_dart_test_strict_engines), KUNIT_CASE(apple_dart_test_topology), KUNIT_CASE(apple_dart_test_iommu_specifiers), + KUNIT_CASE(apple_dart_test_consumer_window), + KUNIT_CASE(apple_dart_test_invalid_consumer_window), KUNIT_CASE(apple_dart_test_independent_remap_roots), KUNIT_CASE(apple_dart_test_before_attach), KUNIT_CASE(apple_dart_test_locked_handoff), diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index b97b0c3378e45..c7ebb762d515e 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -3849,10 +3849,37 @@ static void apple_dart_domain_free(struct iommu_domain *domain) kfree(dart_domain); } +static int apple_dart_validate_dma_window(struct device *dev, + const struct apple_dart *dart, + dma_addr_t dma_min, dma_addr_t length, + dma_addr_t *dma_max) +{ + if (!length) + return -EINVAL; + if (!IS_ALIGNED(dma_min, dart->pgsize) || !IS_ALIGNED(length, dart->pgsize)) { + dev_err(dev, "Unaligned DMA window %pad, %pad (0x%x)\n", + &dma_min, &length, dart->pgsize); + return -EINVAL; + } + if (check_add_overflow(dma_min, length - 1, dma_max)) { + dev_err(dev, "DMA window length (%pad) overflows range for start %pad\n", + &length, &dma_min); + return -EINVAL; + } + + /* High bits may select an alias, but the window must fit within it. */ + if ((dma_min ^ *dma_max) & ~DMA_BIT_MASK(dart->ias)) { + dev_err(dev, "Invalid DMA window for ias=%d\n", dart->ias); + return -EINVAL; + } + return 0; +} + /* * Work out the DMA window of one "iommus" specifier. One cell is the stream * ID alone and keeps the window of the DART node. Five cells add the 64-bit - * start and length of the window that the device uses. + * start and length of the window that the device uses. A consumer's + * apple,dma-range overrides either default, as it does at domain allocation. */ static int apple_dart_parse_dma_window(struct device *dev, const struct apple_dart *dart, @@ -3861,43 +3888,33 @@ static int apple_dart_parse_dma_window(struct device *dev, dma_addr_t *dma_max) { dma_addr_t length; + u64 window[2]; + int ret; + if (args->args_count != 1 && args->args_count != 5) + return -EINVAL; *dma_min = dart->dma_min; *dma_max = dart->dma_max; - if (args->args_count == 1) - return 0; - if (args->args_count != 5) - return -EINVAL; - - length = ((dma_addr_t)args->args[3] << 32) | args->args[4]; - if (!length) - return -EINVAL; - - if (*dma_min != 0 || *dma_max != DMA_BIT_MASK(dart->ias)) - dev_err(dev, "still using legacy \"apple,dma-range\" property\n"); - - *dma_min = ((dma_addr_t)args->args[1] << 32) | args->args[2]; - - if (!IS_ALIGNED(*dma_min, dart->pgsize) || - !IS_ALIGNED(length, dart->pgsize)) { - dev_err(dev, "Unaligned DMA window %pad, %pad (0x%x)\n", - dma_min, &length, dart->pgsize); - return -EINVAL; - } - if (check_add_overflow(*dma_min, length - 1, dma_max)) { - dev_err(dev, "DMA window length (%pad) overflows range for start %pad\n", - &length, dma_min); - return -EINVAL; - } - - /* Ensure that the DMA window does not exceed the DART's ias. */ - if ((*dma_min ^ *dma_max) & ~DMA_BIT_MASK(dart->ias)) { - dev_err(dev, "Invalid DMA window for ias=%d\n", dart->ias); - return -EINVAL; + if (args->args_count == 5) { + if (*dma_min != 0 || *dma_max != DMA_BIT_MASK(dart->ias)) + dev_err(dev, "still using legacy \"apple,dma-range\" property\n"); + *dma_min = ((dma_addr_t)args->args[1] << 32) | args->args[2]; + length = ((dma_addr_t)args->args[3] << 32) | args->args[4]; + ret = apple_dart_validate_dma_window(dev, dart, *dma_min, length, dma_max); + if (ret) + return ret; } - return 0; + /* Apply the consumer aperture before intersecting its DART windows. */ + if (!of_property_present(dev->of_node, "apple,dma-range")) + return 0; + ret = of_property_read_u64_array(dev->of_node, "apple,dma-range", + window, ARRAY_SIZE(window)); + if (ret) + return ret; + *dma_min = window[0]; + return apple_dart_validate_dma_window(dev, dart, *dma_min, window[1], dma_max); } static int apple_dart_of_xlate(struct device *dev, diff --git a/drivers/media/platform/apple/isp/isp-drv.c b/drivers/media/platform/apple/isp/isp-drv.c index f0410cea88b5f..15beab6a5be98 100644 --- a/drivers/media/platform/apple/isp/isp-drv.c +++ b/drivers/media/platform/apple/isp/isp-drv.c @@ -743,6 +743,18 @@ static int apple_isp_probe(struct platform_device *pdev) /* the sensor connection layout, for firmware that takes it at boot */ of_property_read_u32(dev->of_node, "apple,cam-connections-scheme", &isp->cam_connections_scheme); + /* + * M3 MacBook Air firmware 14.7 stalls capture with temporal filter 1. + * The J615 has the J613's sensor and ISP configuration; only the J613 + * has been tested. + */ + if ((of_machine_is_compatible("apple,j613") || + of_machine_is_compatible("apple,j615")) && + isp->fw_compat == ISP_FIRMWARE_V_14_7 && + isp->temporal_filter == 1) { + dev_info(dev, "using temporal filter 0 on M3 Air firmware 14.7\n"); + isp->temporal_filter = 0; + } err = apple_isp_init_presets(isp); if (err) { @@ -1028,7 +1040,7 @@ static const struct apple_isp_hw apple_isp_hw_t6020 = { static const struct apple_isp_hw apple_isp_hw_t8122 = { .gen = ISP_GEN_T8112, - .pmu_base = 0x2d07040000, + .pmu_base = 0x2d0704000, .dsid_count = 1, .dsid_clr_base0 = 0x2221c4000, diff --git a/drivers/pmdomain/apple/pmp-report.c b/drivers/pmdomain/apple/pmp-report.c index 42bff817bfa78..aaf52fc2b51a5 100644 --- a/drivers/pmdomain/apple/pmp-report.c +++ b/drivers/pmdomain/apple/pmp-report.c @@ -687,6 +687,44 @@ static int apple_pmp_report_wait_t6030_14(struct device *supplier, unsigned int return ret; } +/* + * The T8122 (M3 MacBook Air) GPU on its 14.8.3 firmware, for the M3 runtime + * (APPLE_T8122_GPU_PMP_LINK): the unique T8122 report linked to this PMP, and + * its display request (DISP, reg 7) READY and acknowledged before AGX, as on + * the 7.1.12 kernel that runtime was qualified with. + */ +static int apple_pmp_report_wait_t8122_14(struct device *supplier, unsigned int timeout_ms) +{ + struct device_node *np, *report = NULL, *pmp, *entry; + int ret; + + if (!IS_ENABLED(CONFIG_APPLE_T8122_GPU_PMP_LINK) || + !of_machine_is_compatible("apple,t8122") || + !of_device_is_compatible(supplier->of_node, "apple,t8122-pmp-v2")) + return -ENODEV; + for_each_compatible_node(np, NULL, "apple,t8122-pmp-v2-report") { + if (report) { + of_node_put(np); + of_node_put(report); + return -ENODEV; + } + report = of_node_get(np); + } + if (!report || !of_device_is_available(report) || + of_property_count_u32_elems(report, "apple,pmp") != 1) { + of_node_put(report); + return -ENODEV; + } + pmp = of_parse_phandle(report, "apple,pmp", 0); + entry = apple_pmp_report_t6030_entry(report); + ret = pmp == supplier->of_node && entry ? + apple_pmp_report_wait_ready(entry, msecs_to_jiffies(timeout_ms)) : -ENODEV; + of_node_put(entry); + of_node_put(pmp); + of_node_put(report); + return ret; +} + /* The native 25G83 PMP starts through its supplier topology, after requests * are seeded. Its report is pinned against removal while readiness is read. */ @@ -701,8 +739,11 @@ int apple_pmp_report_wait_supplier_ready(struct device *supplier, unsigned int t int ret; /* A declared report always takes the existing native25 path below. */ - if (!np && !of_property_present(supplier->of_node, "apple,pmp-report")) + if (!np && !of_property_present(supplier->of_node, "apple,pmp-report")) { + if (of_machine_is_compatible("apple,t8122")) + return apple_pmp_report_wait_t8122_14(supplier, timeout_ms); return apple_pmp_report_wait_t6030_14(supplier, timeout_ms); + } if (!np || !of_device_is_compatible(np, t8132 ? "apple,t8132-pmp-v2-report" : "apple,j613-25g83-pmp-report")) { of_node_put(np); @@ -1161,10 +1202,18 @@ static void apple_pmp_start_finish(struct apple_pmp_start *st, int result) st->result = result; complete_all(&st->started); } - if (result && READ_ONCE(st->enabled)) + if (result && READ_ONCE(st->enabled)) { + const char *fallback = st->rep->offsets->fallback; + + /* J516M shares the T6031 report layout, but has its own display gate. */ + if (of_machine_is_compatible("apple,t6034") && + of_machine_is_compatible("apple,j516m")) + fallback = "apple_t6034_display.enable=0"; + dev_err(st->rep->dev, "%s PMP start failed (%d) after the PMP was enabled: it may keep running until the next reboot. Reboot to stop it; to boot without starting it: %s, or nomodeset\n", - st->rep->offsets->name, result, st->rep->offsets->fallback); + st->rep->offsets->name, result, fallback); + } } /* Teardown has begun: a start still in progress gives up early. */ @@ -2514,7 +2563,26 @@ static const struct apple_pmp_report_offsets apple_pmp_offsets_t6031 = { .status = 0x10, .starts_pmp = true, .name = "T6031", - .fallback = "leave out apple_t6031_display.enable=1", + .fallback = "apple_t6031_display.enable=0", + .pwrstate = "apple,t6031-pmgr-pwrstate", + .devices_ordered = true, +}; + +/* + * J514M/T6034's selected ADT ptd-range has the same request (index 0x200), + * acknowledge (0x208) and status (0x1) apertures. Its 35 soc-device records + * are in ID order; DISP is ID 17 with ACK and ANS is ID 34 without ACK. + * The exact T6034 display gate supplies the halted PMP and validated values. + * The generic T6020 fallback only observes an already-running PMP. + */ +static const struct apple_pmp_report_offsets apple_pmp_offsets_t6034 = { + .tgt_read = 0x2000, + .tgt_write = 0x11000, + .actual = 0x2080, + .status = 0x10, + .starts_pmp = true, + .name = "T6034", + .fallback = "apple_t6034_display.enable=0", .pwrstate = "apple,t6031-pmgr-pwrstate", .devices_ordered = true, }; @@ -2567,6 +2635,7 @@ static const struct of_device_id apple_pmp_report_of_match[] = { { .compatible = "apple,t6041-pmp-v2-report", .data = &apple_pmp_offsets_t6041 }, /* T6050: the ADT's ptd-range lists T6041's entries at the same places. */ { .compatible = "apple,t6050-pmp-v2-report", .data = &apple_pmp_offsets_t6041 }, + { .compatible = "apple,t6034-pmp-v2-report", .data = &apple_pmp_offsets_t6034 }, { .compatible = "apple,t8112-pmp-v2-report", .data = &apple_pmp_offsets_t8112 }, { .compatible = "apple,t8122-pmp-v2-report", .data = &apple_pmp_offsets_t8122 }, { .compatible = "apple,t8132-pmp-v2-report", .data = &apple_pmp_offsets_t8132 }, diff --git a/drivers/soc/apple/Kconfig b/drivers/soc/apple/Kconfig index c8b50840a7dda..e43b7c1471093 100644 --- a/drivers/soc/apple/Kconfig +++ b/drivers/soc/apple/Kconfig @@ -345,7 +345,7 @@ config APPLE_DISPLAY_GATE It also serves T6031 (M3 Max) device trees with apple,t6031-handoff, in the same way and only with the PMP values the boot loader passes. - There the native display is on by default on the J516C, unless + There the native display is on by default on J514C and J516C, unless apple_t6031_display.enable=0; the other T6031 boards need apple_t6031_display.enable=1 on the kernel command line. The T6031 GPU driver starts its firmware only after this native display is @@ -365,9 +365,23 @@ config APPLE_DISPLAY_GATE displays up. The Type-C ports work as USB ports after 20 seconds meanwhile, and take the display routes once the chain is up. + J514M/T6034 uses an independent apple,t6034-handoff profile and the + same checked PMP firmware layout. It starts on normal boots of that + exact board and SoC pair; apple_t6034_display.enable=0 retains the + boot framebuffer and keeps its GPU off. Other T6034 boards stay off. + Say 'y' if you want the native display on M3 Pro, M3 Max, M3 and M4 Pro Macs. +config APPLE_T8122_GPU_PMP_LINK + bool + depends on APPLE_PMP_REPORT + default n + help + Let T8122 (M3 MacBook Air) GPU power commands wait for the display + request the PMP report acknowledges on the 14.8.3 firmware, as the + M3 runtime of DRM_ASAHI_M3_T8122 requires. + config APPLE_T6030_GPU_PMP_LINK bool depends on APPLE_DISPLAY_GATE @@ -384,7 +398,7 @@ config APPLE_DISPLAY_GATE_KUNIT_TEST help Runs the display gate on test device trees with the T6030, T6031 and T8122 display nodes, without Apple hardware. On T6031: on by - default only on the default board (the J516C), otherwise only with + default only on J514C and J516C, otherwise only with apple_t6031_display.enable=1, off with apple_t6031_display.enable=0, only with the boot loader's handoff marker and this Mac's PMP values, and with nothing changed when a check fails. On T6030: on by default, as diff --git a/drivers/soc/apple/display-gate-test.c b/drivers/soc/apple/display-gate-test.c index 3b0b162ed6799..75fc70ffb3111 100644 --- a/drivers/soc/apple/display-gate-test.c +++ b/drivers/soc/apple/display-gate-test.c @@ -8,8 +8,8 @@ * the T6031 switch does not change it. Run first: the T6031 and T8122 * trees describe a PMP, and the T6030 gate refuses to add a second one. * - T6031 (t6031-gate-test.dtso): on by default only on the default board - * (the J516C; the cases point it at the test tree's own root to run that - * path), otherwise only with apple_t6031_display.enable=1, never with + * (J514C or J516C; the cases supply a synthetic root identity), + * otherwise only with apple_t6031_display.enable=1, never with * apple_t6031_display.enable=0; always with the full handoff, and nothing * changed when a check fails. * - T8122 (t8122-gate-test.dtso): on by default, with the full handoff, @@ -157,7 +157,7 @@ struct gate_test { struct of_changeset cs; /* this case's own edits to the test tree */ bool requested, t6031_requested; int t6031_switch; - const char *t6031_board; + const char *default_board; }; static struct device_node *__init gt_node(struct kunit *test, const char *path) @@ -396,6 +396,16 @@ static int __init gt_suite_init_t8122(struct kunit_suite *suite) return gt_apply_fixture(>_t8122, >_fixture_t8122); } +/* Static-stub resources are task-scoped and removed by KUnit case cleanup. */ +static bool __init gt_root_is_compatible(const char *compat) +{ + struct kunit *test = kunit_get_current_test(); + struct gate_test *t = test->priv; + + return t->default_board && + (!strcmp(compat, "apple,t6031") || !strcmp(compat, t->default_board)); +} + static int __init gt_init(struct kunit *test, const struct gt_soc *s) { struct gate_test *t = kunit_kzalloc(test, sizeof(*t), GFP_KERNEL); @@ -408,7 +418,6 @@ static int __init gt_init(struct kunit *test, const struct gt_soc *s) t->requested = gate_requested; t->t6031_requested = gate_t6031_requested; t->t6031_switch = gate_t6031_switch; - t->t6031_board = gate_t6031_board; of_changeset_init(&t->cs); gate_soc = s->soc; gate_pmp_values = NULL; @@ -419,6 +428,7 @@ static int __init gt_init(struct kunit *test, const struct gt_soc *s) gate_t6031_switch = -1; if (gt_live_soc) kunit_skip(test, "the booted device tree has its own /soc"); + kunit_activate_static_stub(test, gate_t6031_is_compatible, gt_root_is_compatible); return 0; } @@ -463,7 +473,6 @@ static void __init gt_exit(struct kunit *test) gate_requested = t->requested; gate_t6031_requested = t->t6031_requested; gate_t6031_switch = t->t6031_switch; - gate_t6031_board = t->t6031_board; gate_soc = NULL; } @@ -476,7 +485,7 @@ static void __init gate_t6031_param(struct kunit *test) KUNIT_EXPECT_FALSE(test, t->t6031_requested); KUNIT_EXPECT_EQ(test, t->t6031_switch, -1); - KUNIT_EXPECT_STREQ(test, t->t6031_board, "apple,j516c"); + KUNIT_EXPECT_NULL(test, gate_t6031_default_board()); KUNIT_EXPECT_TRUE(test, t->requested); KUNIT_EXPECT_EQ(test, gate_setup_t6031("1"), 0); @@ -514,14 +523,19 @@ static void __init gate_t6031_resolution(struct kunit *test) KUNIT_EXPECT_TRUE(test, gate_t6031_wanted(1, false)); } -/* Points the default board at the test tree's root, so gate_run() takes that path. */ +static const char * const gt_default_boards[] = { + "apple,j514c", + "apple,j516c", +}; +KUNIT_ARRAY_PARAM(gt_default_board, gt_default_boards, NULL); + +/* Exercise the real selector and gate_run(), with a test-scoped identity. */ static void __init gt_default_board(struct kunit *test) { - const char *root = NULL; + struct gate_test *t = test->priv; - if (of_property_read_string(of_root, "compatible", &root) || !root) - kunit_skip(test, "the test tree's root has no compatible"); - gate_t6031_board = root; + t->default_board = *(const char * const *)test->param_value; + KUNIT_ASSERT_STREQ(test, gate_t6031_default_board(), t->default_board); } /* On the default board, the full handoff and no switch: enabled. */ @@ -529,6 +543,7 @@ static void __init gate_t6031_default_board_on(struct kunit *test) { gt_default_board(test); gt_run(test); + KUNIT_EXPECT_TRUE(test, gate_t6031_requested); gt_expect_enabled(test); } @@ -538,6 +553,7 @@ static void __init gate_t6031_default_board_switched_off(struct kunit *test) gt_default_board(test); KUNIT_ASSERT_EQ(test, gate_setup_t6031("0"), 0); gt_run(test); + KUNIT_EXPECT_FALSE(test, gate_t6031_requested); gt_expect_untouched(test); } @@ -547,6 +563,7 @@ static void __init gate_t6031_default_board_no_marker(struct kunit *test) gt_default_board(test); gt_remove(test, gt_t6031.dcp, "apple,t6031-handoff"); gt_run(test); + KUNIT_EXPECT_TRUE(test, gate_t6031_requested); gt_expect_untouched(test); } @@ -901,9 +918,9 @@ static struct kunit_case gate_t6031_cases[] __refdata = { KUNIT_CASE(gate_t6031_param), KUNIT_CASE(gate_t6031_resolution), KUNIT_CASE(gate_t6031_off_by_default), - KUNIT_CASE(gate_t6031_default_board_on), - KUNIT_CASE(gate_t6031_default_board_switched_off), - KUNIT_CASE(gate_t6031_default_board_no_marker), + KUNIT_CASE_PARAM(gate_t6031_default_board_on, gt_default_board_gen_params), + KUNIT_CASE_PARAM(gate_t6031_default_board_switched_off, gt_default_board_gen_params), + KUNIT_CASE_PARAM(gate_t6031_default_board_no_marker, gt_default_board_gen_params), KUNIT_CASE(gate_t6031_switched_off), KUNIT_CASE(gate_t6031_enabled), KUNIT_CASE(gate_t6031_no_dcp_marker), diff --git a/drivers/soc/apple/display-gate.c b/drivers/soc/apple/display-gate.c index 03db5ed73e343..c7125e3788792 100644 --- a/drivers/soc/apple/display-gate.c +++ b/drivers/soc/apple/display-gate.c @@ -53,8 +53,8 @@ * option. * * On T6031 (M3 Max) the gate serves the same handoff, marked - * apple,t6031-handoff. Its default is scoped to the J516C: there the native - * display is on unless apple_t6031_display.enable=0; the other T6031 boards + * apple,t6031-handoff. Its default is scoped to J514C and J516C: there the native + * display is on unless apple_t6031_display.enable=0; other T6031 boards * need apple_t6031_display.enable=1. The T6031 GPU starts its firmware only * after this native display is up, so enable=0 (or a display that never * comes up) keeps the GPU off for that boot too: it is not a display-only @@ -115,6 +115,10 @@ #include #include