diff --git a/drivers/gpu/drm/apple/dcp-m4-profile.h b/drivers/gpu/drm/apple/dcp-m4-profile.h index 2ea10cca57577..82485a3048b2e 100644 --- a/drivers/gpu/drm/apple/dcp-m4-profile.h +++ b/drivers/gpu/drm/apple/dcp-m4-profile.h @@ -24,12 +24,13 @@ struct dcp_m4_profile { u32 brightness_max, brightness_default; u32 width_mm, height_mm; /* - * The qualified preferred timing, horizontal then vertical: Active, - * Total, FrontPorch, SyncWidth, BackPorch, PreciseSyncRate, + * The qualified preferred timing (ID 2), horizontal then vertical: + * Active, Total, FrontPorch, SyncWidth, BackPorch, PreciseSyncRate, * SyncPolarity, PixelRepetition. NULL: none, so the panel is not * adopted. */ const u32 (*timing)[8]; + u32 timing_elements; /* most timing elements reported */ }; static const u32 dcp_m4_timing_j713[2][8] = { @@ -47,7 +48,7 @@ static const struct dcp_m4_profile dcp_m4_profile_j713 = { .done_method = 590, .done_size = 0x730, .open_method = 457, .brightness_max = 500, .brightness_default = 120, .width_mm = 0, .height_mm = 0, - .timing = dcp_m4_timing_j713, + .timing = dcp_m4_timing_j713, .timing_elements = 1, }; /* The J715's panel timing, as macOS reports it (TimingElements, ID 2). */ @@ -67,12 +68,36 @@ static const struct dcp_m4_profile dcp_m4_profile_j715 = { .done_method = 590, .done_size = 0x730, .open_method = 457, .brightness_max = 500, .brightness_default = 120, .width_mm = 0, .height_mm = 0, - .timing = dcp_m4_timing_j715, + .timing = dcp_m4_timing_j715, .timing_elements = 1, +}; + +/* The J604's preferred 120 Hz timing (macOS TimingElements, ID 2). */ +static const u32 dcp_m4_timing_j604[2][8] = { + { 3024, 3104, 8, 32, 40, 16986999, 1, 0 }, + { 1964, 2160, 102, 8, 86, 7864351, 1, 0 }, +}; + +/* + * The J604: assumed to be the same firmware ABI, with a 3024x1964 XDR panel + * rated 1000 nits for SDR. It reports six timings; only ID 2 is adopted. + */ +static const struct dcp_m4_profile dcp_m4_profile_j604 = { + .name = "J604", .machine = "apple,j604", + .panel_width = 3024, .panel_height = 1964, .boot_stride = 12096, + .swap_size = 0x1bd8, .swap_surface = 0x588, .swap_dva = 0xe38, + .swap_nullable = 0x1bcb, .swap_tail = 0x1bd6, .swap_nits = 0x35e, + .swap_intent = 0x17c, + .disabled_color = 0xff000000, + .done_method = 590, .done_size = 0x730, .open_method = 457, + .brightness_max = 1000, .brightness_default = 120, + .width_mm = 0, .height_mm = 0, + .timing = dcp_m4_timing_j604, .timing_elements = 6, }; static const struct dcp_m4_profile *const dcp_m4_profiles[] = { &dcp_m4_profile_j713, &dcp_m4_profile_j715, + &dcp_m4_profile_j604, }; /* The machine's profile, set before the first DCP session starts. */ diff --git a/drivers/gpu/drm/apple/dcp-m4-timing.h b/drivers/gpu/drm/apple/dcp-m4-timing.h index b8eabc880c7be..13af59e83c770 100644 --- a/drivers/gpu/drm/apple/dcp-m4-timing.h +++ b/drivers/gpu/drm/apple/dcp-m4-timing.h @@ -170,6 +170,7 @@ static inline int dcp_m4_parse_timing(const void *data, size_t size, struct dcp_ }; static const u32 color_values[] = { 1, 8, 0, 0, 0, 16, 0 }; int ret = -EINVAL, colors, color; + unsigned int mode = 0, element = 1; const u32 *h, *v; if (!dcp_m4_pf->timing) @@ -186,21 +187,35 @@ static inline int dcp_m4_parse_timing(const void *data, size_t size, struct dcp_ if (ret) goto done; ret = -EINVAL; - if (p->pos != size || p->token[0].type != 2 || p->token[0].count != 1 || - p->token[1].type != 1 || - !dcp_m4_timing_equals(p, 1, "ID", 4, 2) || - !dcp_m4_timing_equals(p, 1, "IsVirtual", 11, 0) || - !dcp_m4_timing_equals(p, 1, "IsPreferred", 11, 1) || - !dcp_m4_timing_equals(p, 1, "IsInterlaced", 11, 0) || - !dcp_m4_timing_equals(p, 1, "IsSplit", 11, 0) || - !dcp_m4_timing_equals(p, 1, "IsOverscanned", 11, 0) || - !dcp_m4_timing_equals(p, 1, "TimingType", 4, 3) || - !dcp_m4_timing_equals(p, 1, "MinimumVariableRefreshRate", 4, 0) || - !dcp_m4_timing_equals(p, 1, "MaximumVariableRefreshRate", 4, 0) || - dcp_m4_timing_axis(p, 1, "HorizontalAttributes", false) || - dcp_m4_timing_axis(p, 1, "VerticalAttributes", true)) + if (p->pos != size || p->token[0].type != 2 || !p->token[0].count || + p->token[0].count > dcp_m4_pf->timing_elements) goto done; - colors = dcp_m4_timing_field(p, 1, "ColorModes", 2); + /* Exactly one element is ID 2, and no other is preferred. */ + for (unsigned int i = 0; i < p->token[0].count; + i++, element = p->token[element].next) { + if (dcp_m4_timing_field(p, element, "ID", 4) < 0) + goto done; + if (dcp_m4_timing_equals(p, element, "ID", 4, 2)) { + if (mode) + goto done; + mode = element; + } else if (!dcp_m4_timing_equals(p, element, "IsPreferred", 11, 0)) { + goto done; + } + } + if (!mode || + !dcp_m4_timing_equals(p, mode, "IsVirtual", 11, 0) || + !dcp_m4_timing_equals(p, mode, "IsPreferred", 11, 1) || + !dcp_m4_timing_equals(p, mode, "IsInterlaced", 11, 0) || + !dcp_m4_timing_equals(p, mode, "IsSplit", 11, 0) || + !dcp_m4_timing_equals(p, mode, "IsOverscanned", 11, 0) || + !dcp_m4_timing_equals(p, mode, "TimingType", 4, 3) || + !dcp_m4_timing_equals(p, mode, "MinimumVariableRefreshRate", 4, 0) || + !dcp_m4_timing_equals(p, mode, "MaximumVariableRefreshRate", 4, 0) || + dcp_m4_timing_axis(p, mode, "HorizontalAttributes", false) || + dcp_m4_timing_axis(p, mode, "VerticalAttributes", true)) + goto done; + colors = dcp_m4_timing_field(p, mode, "ColorModes", 2); if (colors < 0 || p->token[colors].count != 1) goto done; color = colors + 1; diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/README b/tools/testing/selftests/drivers/gpu/apple-dcp/README index 4934b7eb7eef2..633702781763c 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/README +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/README @@ -150,6 +150,15 @@ the real common backlight state/wrappers run with a bounded mock transport, covering DPMS-off before delayed work and retaining active plus uncertain framebuffers when one of the two required receipts never arrives. +The m4-panel-timing case runs the actual internal-panel timing parser on +encoded TimingElements reports. The J713 and J715 reports have one element. +The J604 fixture is the six-element report from macOS 26B123: a preferred +120 Hz element and five 48-60 Hz ones. Only the preferred ID 2 element is +adopted, and only with the profile's exact values. The parser refuses a +changed value, a missing or duplicated ID 2, a second preferred element and +more elements than the profile allows. This does not show what the firmware +reports on hardware. + run-native-m4-kms.py defaults to dry run; --compile-only needs libdrm development headers and never opens DRM. Explicit --execute requires root, an exact fresh source/Image/boot identity, the common appledrm module, a stopped display diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/m4-fixtures/timing-elements.json b/tools/testing/selftests/drivers/gpu/apple-dcp/m4-fixtures/timing-elements.json new file mode 100644 index 0000000000000..0e4e0bd94084c --- /dev/null +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/m4-fixtures/timing-elements.json @@ -0,0 +1,396 @@ +{ + "schema": 1, + "scope": "J604 (MacBook Pro 14-inch, M4) internal panel TimingElements as macOS 26B123 reports them (ioreg disp0). Types: integer, boolean, string, {\"data\": hex}, array, dictionary; key order kept.", + "j604": [ + { + "StandardType": 0, + "DiscreteMediaRefreshRates": [], + "ElementType": 0, + "IsSplit": false, + "IsPromoted": false, + "IsInterlaced": false, + "HorizontalAttributes": { + "Total": 3104, + "Active": 3024, + "PixelRepetition": 0, + "PreciseSyncRate": 16986999, + "BackPorch": 40, + "SyncWidth": 32, + "FrontPorch": 8, + "SyncPolarity": 1, + "SyncRate": 16973824 + }, + "VerticalAttributes": { + "Total": 2160, + "Active": 1964, + "PixelRepetition": 0, + "PreciseSyncRate": 7864351, + "BackPorch": 86, + "SyncWidth": 8, + "FrontPorch": 102, + "SyncPolarity": 1, + "SyncRate": 7864320 + }, + "UnsafeColorElementIDs": [], + "Score": 16813, + "MinimumVariableRefreshRate": 0, + "ColorModes": [ + { + "ElementData": { + "data": "0800000000000000000000001000000000000000000000000000000000000000" + }, + "StandardType": 0, + "Score": 240999, + "IsVirtual": false, + "ID": 1, + "PixelEncoding": 0, + "ElementType": 1, + "SupportsDSC": 0, + "EOTF": 0, + "Colorimetry": 16, + "DynamicRange": 0, + "Depth": 8 + } + ], + "IsOverscanned": false, + "IsVirtual": false, + "ElementData": { + "data": "00000000200c0000d00b000020000000280000000800000077330301010000000000000070080000ac0700000800000056000000660000001f0078000100000000000000809cf42f0c00000000000000" + }, + "IsPreferred": true, + "ScanInformation": 0, + "TimingType": 3, + "DSCRequiredColorElementIDs": [], + "ID": 2, + "AspectRatio": 12, + "MaximumVariableRefreshRate": 0, + "ValidPixelEncodings": 1, + "PreciseAspectRatio": 100906 + }, + { + "StandardType": 0, + "DiscreteMediaRefreshRates": [], + "ElementType": 0, + "IsSplit": false, + "IsPromoted": true, + "IsInterlaced": false, + "HorizontalAttributes": { + "Total": 3104, + "Active": 3024, + "PixelRepetition": 0, + "PreciseSyncRate": 16986999, + "BackPorch": 40, + "SyncWidth": 32, + "FrontPorch": 8, + "SyncPolarity": 1, + "SyncRate": 16973824 + }, + "VerticalAttributes": { + "Total": 2160, + "Active": 1964, + "PixelRepetition": 0, + "PreciseSyncRate": 3932160, + "BackPorch": 86, + "SyncWidth": 8, + "FrontPorch": 102, + "SyncPolarity": 1, + "SyncRate": 3932160 + }, + "UnsafeColorElementIDs": [], + "Score": 15416, + "MinimumVariableRefreshRate": 0, + "ColorModes": [ + { + "ElementData": { + "data": "0800000000000000000000001000000000000000000000000000000000000000" + }, + "StandardType": 0, + "Score": 240999, + "IsVirtual": false, + "ID": 1, + "PixelEncoding": 0, + "ElementType": 1, + "SupportsDSC": 0, + "EOTF": 0, + "Colorimetry": 16, + "DynamicRange": 0, + "Depth": 8 + } + ], + "IsOverscanned": false, + "IsVirtual": false, + "ElementData": { + "data": "00000000200c0000d00b000020000000280000000800000077330301010000000000000070080000ac07000008000000560000006600000000003c000100000000000000809cf42f0c00000000000000" + }, + "IsPreferred": false, + "ScanInformation": 0, + "TimingType": 3, + "DSCRequiredColorElementIDs": [], + "ID": 3, + "AspectRatio": 12, + "MaximumVariableRefreshRate": 0, + "ValidPixelEncodings": 1, + "PreciseAspectRatio": 100906 + }, + { + "StandardType": 0, + "DiscreteMediaRefreshRates": [], + "ElementType": 0, + "IsSplit": false, + "IsPromoted": true, + "IsInterlaced": false, + "HorizontalAttributes": { + "Total": 3104, + "Active": 3024, + "PixelRepetition": 0, + "PreciseSyncRate": 16986999, + "BackPorch": 40, + "SyncWidth": 32, + "FrontPorch": 8, + "SyncPolarity": 1, + "SyncRate": 16973824 + }, + "VerticalAttributes": { + "Total": 2160, + "Active": 1964, + "PixelRepetition": 0, + "PreciseSyncRate": 3145728, + "BackPorch": 86, + "SyncWidth": 8, + "FrontPorch": 102, + "SyncPolarity": 1, + "SyncRate": 3145728 + }, + "UnsafeColorElementIDs": [], + "Score": 15333, + "MinimumVariableRefreshRate": 0, + "ColorModes": [ + { + "ElementData": { + "data": "0800000000000000000000001000000000000000000000000000000000000000" + }, + "StandardType": 0, + "Score": 240999, + "IsVirtual": false, + "ID": 1, + "PixelEncoding": 0, + "ElementType": 1, + "SupportsDSC": 0, + "EOTF": 0, + "Colorimetry": 16, + "DynamicRange": 0, + "Depth": 8 + } + ], + "IsOverscanned": false, + "IsVirtual": false, + "ElementData": { + "data": "00000000200c0000d00b000020000000280000000800000077330301010000000000000070080000ac070000080000005600000066000000000030000100000000000000809cf42f0c00000000000000" + }, + "IsPreferred": false, + "ScanInformation": 0, + "TimingType": 3, + "DSCRequiredColorElementIDs": [], + "ID": 4, + "AspectRatio": 12, + "MaximumVariableRefreshRate": 0, + "ValidPixelEncodings": 1, + "PreciseAspectRatio": 100906 + }, + { + "StandardType": 0, + "DiscreteMediaRefreshRates": [], + "ElementType": 0, + "IsSplit": false, + "IsPromoted": true, + "IsInterlaced": false, + "HorizontalAttributes": { + "Total": 3104, + "Active": 3024, + "PixelRepetition": 0, + "PreciseSyncRate": 16969960, + "BackPorch": 40, + "SyncWidth": 32, + "FrontPorch": 8, + "SyncPolarity": 1, + "SyncRate": 16973824 + }, + "VerticalAttributes": { + "Total": 2160, + "Active": 1964, + "PixelRepetition": 0, + "PreciseSyncRate": 3928232, + "BackPorch": 86, + "SyncWidth": 8, + "FrontPorch": 102, + "SyncPolarity": 1, + "SyncRate": 3932160 + }, + "UnsafeColorElementIDs": [], + "Score": 15416, + "MinimumVariableRefreshRate": 0, + "ColorModes": [ + { + "ElementData": { + "data": "0800000000000000000000001000000000000000000000000000000000000000" + }, + "StandardType": 0, + "Score": 240999, + "IsVirtual": false, + "ID": 1, + "PixelEncoding": 0, + "ElementType": 1, + "SupportsDSC": 0, + "EOTF": 0, + "Colorimetry": 16, + "DynamicRange": 0, + "Depth": 8 + } + ], + "IsOverscanned": false, + "IsVirtual": false, + "ElementData": { + "data": "00000000200c0000d00b0000200000002800000008000000e8f00201010000000000000070080000ac070000080000005600000066000000a8f03b000100000000000000284ce82f0c00000000000000" + }, + "IsPreferred": false, + "ScanInformation": 0, + "TimingType": 3, + "DSCRequiredColorElementIDs": [], + "ID": 5, + "AspectRatio": 12, + "MaximumVariableRefreshRate": 0, + "ValidPixelEncodings": 1, + "PreciseAspectRatio": 100906 + }, + { + "StandardType": 0, + "DiscreteMediaRefreshRates": [], + "ElementType": 0, + "IsSplit": false, + "IsPromoted": true, + "IsInterlaced": false, + "HorizontalAttributes": { + "Total": 3104, + "Active": 3024, + "PixelRepetition": 0, + "PreciseSyncRate": 16969960, + "BackPorch": 40, + "SyncWidth": 32, + "FrontPorch": 8, + "SyncPolarity": 1, + "SyncRate": 16973824 + }, + "VerticalAttributes": { + "Total": 2160, + "Active": 1964, + "PixelRepetition": 0, + "PreciseSyncRate": 3142585, + "BackPorch": 86, + "SyncWidth": 8, + "FrontPorch": 102, + "SyncPolarity": 1, + "SyncRate": 3145728 + }, + "UnsafeColorElementIDs": [], + "Score": 15333, + "MinimumVariableRefreshRate": 0, + "ColorModes": [ + { + "ElementData": { + "data": "0800000000000000000000001000000000000000000000000000000000000000" + }, + "StandardType": 0, + "Score": 240999, + "IsVirtual": false, + "ID": 1, + "PixelEncoding": 0, + "ElementType": 1, + "SupportsDSC": 0, + "EOTF": 0, + "Colorimetry": 16, + "DynamicRange": 0, + "Depth": 8 + } + ], + "IsOverscanned": false, + "IsVirtual": false, + "ElementData": { + "data": "00000000200c0000d00b0000200000002800000008000000e8f00201010000000000000070080000ac070000080000005600000066000000b9f32f000100000000000000284ce82f0c00000000000000" + }, + "IsPreferred": false, + "ScanInformation": 0, + "TimingType": 3, + "DSCRequiredColorElementIDs": [], + "ID": 6, + "AspectRatio": 12, + "MaximumVariableRefreshRate": 0, + "ValidPixelEncodings": 1, + "PreciseAspectRatio": 100906 + }, + { + "StandardType": 0, + "DiscreteMediaRefreshRates": [], + "ElementType": 0, + "IsSplit": false, + "IsPromoted": true, + "IsInterlaced": false, + "HorizontalAttributes": { + "Total": 3104, + "Active": 3024, + "PixelRepetition": 0, + "PreciseSyncRate": 16986931, + "BackPorch": 40, + "SyncWidth": 32, + "FrontPorch": 8, + "SyncPolarity": 1, + "SyncRate": 16973824 + }, + "VerticalAttributes": { + "Total": 2592, + "Active": 1964, + "PixelRepetition": 0, + "PreciseSyncRate": 3276800, + "BackPorch": 86, + "SyncWidth": 8, + "FrontPorch": 534, + "SyncPolarity": 1, + "SyncRate": 3276800 + }, + "UnsafeColorElementIDs": [], + "Score": 15347, + "MinimumVariableRefreshRate": 0, + "ColorModes": [ + { + "ElementData": { + "data": "0800000000000000000000001000000000000000000000000000000000000000" + }, + "StandardType": 0, + "Score": 240999, + "IsVirtual": false, + "ID": 1, + "PixelEncoding": 0, + "ElementType": 1, + "SupportsDSC": 0, + "EOTF": 0, + "Colorimetry": 16, + "DynamicRange": 0, + "Depth": 8 + } + ], + "IsOverscanned": false, + "IsVirtual": false, + "ElementData": { + "data": "00000000200c0000d00b0000200000002800000008000000333303010100000000000000200a0000ac0700000800000056000000160200000000320001000000000000000090f42f0c00000000000000" + }, + "IsPreferred": false, + "ScanInformation": 0, + "TimingType": 3, + "DSCRequiredColorElementIDs": [], + "ID": 7, + "AspectRatio": 12, + "MaximumVariableRefreshRate": 0, + "ValidPixelEncodings": 1, + "PreciseAspectRatio": 100906 + } + ] +} diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/m4.py b/tools/testing/selftests/drivers/gpu/apple-dcp/m4.py index 79f4c23ebc677..4d0e9c50a1082 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/m4.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/m4.py @@ -5,8 +5,10 @@ not the implementation under test. Transport, MMIO and DRM core are not emulated. """ import base64 +import copy import hashlib import json +import struct import subprocess import zlib from pathlib import Path @@ -645,3 +647,212 @@ def blank(root): return 0; } ''' + + +# macOS's preferred internal-panel timings (ID 2), horizontal then vertical, in +# the profile's field order. The J604's also come from its fixture report. +TIMING_FIELDS = ('Active', 'Total', 'FrontPorch', 'SyncWidth', 'BackPorch', + 'PreciseSyncRate', 'SyncPolarity', 'PixelRepetition') +PANEL_TIMINGS = { + 'j713': ((2560, 2640, 8, 32, 40, 6877358, 1, 0), (1664, 1749, 33, 8, 44, 3932166, 1, 0)), + 'j715': ((2880, 2960, 8, 32, 40, 7710975, 1, 0), (1864, 1961, 47, 8, 42, 3932165, 1, 0)), + 'j604': ((3024, 3104, 8, 32, 40, 16986999, 1, 0), (1964, 2160, 102, 8, 86, 7864351, 1, 0)), +} +# hdisplay, hsync_start, hsync_end, htotal, vdisplay, vsync_start, vsync_end, +# vtotal, clock_khz, refresh_16_16 +PANEL_MODES = { + 'j713': (2560, 2568, 2600, 2640, 1664, 1697, 1705, 1749, 277042, 3932166), + 'j715': (2880, 2888, 2920, 2960, 1864, 1911, 1919, 1961, 348274, 3932165), + 'j604': (3024, 3032, 3064, 3104, 1964, 2066, 2074, 2160, 804560, 7864351), +} + +TIMING_SHIMS = r''' +#include +#define GFP_KERNEL 0 +static void *kzalloc(size_t size, int flags) { (void)flags; return calloc(1, size); } +static void kfree(void *p) { free(p); } +static inline u64 get_unaligned_le64(const void *p) { + const u8 *b = p; u64 v = 0; + for (unsigned i = 0; i < 8; i++) v |= (u64)b[i] << (8 * i); + return v; +} +''' + +TIMING_MAIN = r''' +struct timing_case { + const char *name; + const struct dcp_m4_profile *profile; + const u8 *data; + size_t size; + int expect; + u32 mode[10]; +}; +static const struct timing_case cases[] = { +%s +}; +int main(void) +{ + for (size_t i = 0; i < sizeof(cases) / sizeof(cases[0]); i++) { + const struct timing_case *c = &cases[i]; + struct dcp_m4_timing t; + int ret; + memset(&t, 0xa5, sizeof(t)); + dcp_m4_pf = c->profile; + ret = dcp_m4_parse_timing(c->data, c->size, &t); + if (ret != c->expect) { + printf("FAIL %%s: %%d, expected %%d\n", c->name, ret, c->expect); + return 1; + } + if (!ret) { + const u32 got[10] = {t.hdisplay, t.hsync_start, t.hsync_end, t.htotal, + t.vdisplay, t.vsync_start, t.vsync_end, t.vtotal, t.clock_khz, t.refresh_16_16}; + if (t.id != 2 || t.color_id != 1 || memcmp(got, c->mode, sizeof(got))) { + printf("FAIL %%s: wrong mode\n", c->name); + return 1; + } + } + printf("PASS %%s: %%s\n", c->name, ret ? "refused" : "adopted"); + } + return 0; +} +''' + + +def serialize(elements): + """The DCP's binary dictionary encoding of a TimingElements array.""" + out = bytearray(struct.pack('