diff --git a/drivers/gpu/drm/apple/dcp-peer-modeset-probe-v27.inc b/drivers/gpu/drm/apple/dcp-peer-modeset-probe-v27.inc index a5aa449b446dd..0ac6d6c344761 100644 --- a/drivers/gpu/drm/apple/dcp-peer-modeset-probe-v27.inc +++ b/drivers/gpu/drm/apple/dcp-peer-modeset-probe-v27.inc @@ -7,11 +7,16 @@ static int dcp_peer_probe_power(struct apple_dcp *dcp, struct apple_dcp *peer, bool on) { struct dcp_peer_video_wait *wait; - struct dcp_method_entry method = { .name = "peer_power_test", - .tag = {'A', '4', '8', '4'} }; + struct dcp_method_entry method = { .name = "peer_power_test" }; u8 power[16] = {}, response[8]; + char peer_tag[4]; int ret; + ret = iomfb_v27_tag(dcp->v27_methods, "A484", method.tag) ?: + iomfb_v27_tag(peer->v27_methods, "A484", peer_tag); + if (ret) + return ret; + wait = kzalloc(sizeof(*wait), GFP_KERNEL); if (!wait) return -ENOMEM; @@ -134,13 +139,18 @@ static int dcp_peer_probe_modeset(struct apple_dcp *dcp, struct apple_dcp *peer, bool firmware_requires_merge) { struct dcp_peer_video_wait *wait; - struct dcp_method_entry method = { .name = "peer_modeset_test", - .tag = {'A', '4', '1', '3'} }; + struct dcp_method_entry method = { .name = "peer_modeset_test" }; __le32 mode[2] = {video->color_id, video->timing_id}; u32 primary_id, peer_id, phase, status; unsigned long deadline; + char peer_tag[4]; int ret; + ret = iomfb_v27_tag(dcp->v27_methods, "A413", method.tag) ?: + iomfb_v27_tag(peer->v27_methods, "A413", peer_tag); + if (ret) + return ret; + { guard(mutex)(&dcp_peer_lock); if (dcp->peer_reserved != peer || peer->peer_owner != dcp || diff --git a/drivers/gpu/drm/apple/dcp-peer-probe-v27.inc b/drivers/gpu/drm/apple/dcp-peer-probe-v27.inc index 33def11c752ea..a1c017c98e085 100644 --- a/drivers/gpu/drm/apple/dcp-peer-probe-v27.inc +++ b/drivers/gpu/drm/apple/dcp-peer-probe-v27.inc @@ -24,9 +24,7 @@ static ssize_t peer_setup_test_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - static const struct dcp_method_entry method = { - .name = "setup_peer_dcp", .tag = {'A', '3', '6', '6'}, - }; + struct dcp_method_entry method = { .name = "setup_peer_dcp" }; struct apple_dcp *dcp = dev_get_drvdata(dev); struct dcp_peer_probe_wait *wait; __le32 enabled = cpu_to_le32(1); @@ -55,6 +53,11 @@ static ssize_t peer_setup_test_store(struct device *dev, kref_put(&wait->refs, dcp_peer_probe_free); return -EBUSY; } + ret = iomfb_v27_tag(dcp->v27_methods, "A366", method.tag); + if (ret) { + kref_put(&wait->refs, dcp_peer_probe_free); + return ret; + } kref_get(&wait->refs); /* Peer-DCP setup (one bool argument): four input * bytes (boolean followed by zero padding), no output. diff --git a/drivers/gpu/drm/apple/dcp-peer-swap-probe-v27.inc b/drivers/gpu/drm/apple/dcp-peer-swap-probe-v27.inc index ed73f355eda7e..343fa1872bada 100644 --- a/drivers/gpu/drm/apple/dcp-peer-swap-probe-v27.inc +++ b/drivers/gpu/drm/apple/dcp-peer-swap-probe-v27.inc @@ -6,6 +6,7 @@ struct dcp_peer_background { struct iomfb_transaction transaction; struct dcp_peer_video_wait *wait; struct dcp_swap_submit_req_v27 wire; + char tag[4]; bool sent; }; @@ -26,10 +27,11 @@ static void dcp_peer_background_start(struct apple_dcp *dcp, { struct dcp_peer_background *background = container_of(transaction, struct dcp_peer_background, transaction); - struct dcp_method_entry method = { .name = "peer_background_test", - .tag = {'A', '4', '0', '8'} }; + struct dcp_method_entry method = { .name = "peer_background_test" }; struct dcp_swap_submit_resp_v27 failed = { .ret = ~0U }; + memcpy(method.tag, background->tag, sizeof(method.tag)); + background->sent = true; if (!dcp_present_begin_h17p(&dcp->present_state_h17p, background->wire.swap.swap_id)) { @@ -55,13 +57,18 @@ static int dcp_peer_queue_background(struct apple_dcp *dcp, struct dcp_peer_video_wait *wait) { struct dcp_peer_background *background; + char tag[4]; int ret; + ret = iomfb_v27_tag(dcp->v27_methods, "A408", tag); + if (ret) + return ret; background = kzalloc_obj(*background); if (!background) return -ENOMEM; background->wire = *wire; background->wait = wait; + memcpy(background->tag, tag, sizeof(background->tag)); kref_get(&wait->refs); background->transaction.start = dcp_peer_background_start; background->transaction.release = dcp_peer_background_release; @@ -185,6 +192,7 @@ static void dcp_peer_a407_background_start(struct apple_dcp *dcp, { struct dcp_peer_a407_background *background = container_of(transaction, struct dcp_peer_a407_background, transaction); + /* The J714s's 27.0 swap form, whose table names A407 (iomfb_v27_methods_j714s()). */ struct dcp_method_entry method = { .name = "peer_background_test", .tag = {'A', '4', '0', '7'} }; struct dcp_swap_submit_resp_v27 failed = { .ret = ~0U }; @@ -345,6 +353,8 @@ static ssize_t peer_swap_test_store(struct device *dev, dcp->crtc->base.state->active || peer->crtc->base.state->active || dcp->fw_compat != DCP_FIRMWARE_V_27_0 || peer->fw_compat != DCP_FIRMWARE_V_27_0 || + /* Both engines must take the swap form the owner sends. */ + dcp->v27_a407 != peer->v27_a407 || !device_trylock(peer->dev)) { ret = -EBUSY; goto out; diff --git a/drivers/gpu/drm/apple/dcp-peer-video-probe-v27.inc b/drivers/gpu/drm/apple/dcp-peer-video-probe-v27.inc index 3560cfc447a99..86b0f20b5823d 100644 --- a/drivers/gpu/drm/apple/dcp-peer-video-probe-v27.inc +++ b/drivers/gpu/drm/apple/dcp-peer-video-probe-v27.inc @@ -37,6 +37,10 @@ static int dcp_peer_video_call_stream(struct apple_dcp *dcp, bool independent, if (out_size > sizeof(wait->reply)) return -EINVAL; + /* The calls name 27.0 IDs: this engine's build may number them differently. */ + ret = iomfb_v27_tag(dcp->v27_methods, tag, method.tag); + if (ret) + return ret; /* An unrelated AP thread gets its own firmware stream. A369/A367/etc. * must not be mistaken for nested callbacks of the pending A413. * Stream1 (the driver's OOB context) is independent of stream0. @@ -46,7 +50,6 @@ static int dcp_peer_video_call_stream(struct apple_dcp *dcp, bool independent, wait = kzalloc(sizeof(*wait), GFP_KERNEL); if (!wait) return -ENOMEM; - memcpy(method.tag, tag, sizeof(method.tag)); wait->size = out_size; init_completion(&wait->done); kref_init(&wait->refs); diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index 0666748f436d0..b23ba12367334 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -5926,31 +5926,25 @@ static bool dcp_ext26_admitted(struct device_node *np) } /* - * J716c shares the 27.0 endpoint-control wire format, not the J714s normal - * IOMFB method or panel profile. Establish this before RTKit can receive any - * application traffic, including traffic that invalidates a later inventory. + * Firmware 27 (T6050) sleep endpoint-control transport. Establish this before + * RTKit can receive any application traffic, including traffic that invalidates + * a later inventory. Admitted for a T6050 DCP/DCPEXT whose firmware 27 method + * table has an ID for every call the sleep sends. */ static bool dcp_v27_sleep_transport_supported(struct apple_dcp *dcp) { struct device *dev = dcp->dev; - char compat[DCP_FW_VERSION_STR_LEN]; if (!IS_ENABLED(CONFIG_APPLE_SOC_SLEEP)) return false; - if (dcp->v27_j714s) - return true; - if (!of_machine_is_compatible("apple,j716c") || - !of_machine_is_compatible("apple,t6050") || - !(of_device_is_compatible(dev->of_node, "apple,t6050-dcp") || + if (!(of_device_is_compatible(dev->of_node, "apple,t6050-dcp") || of_device_is_compatible(dev->of_node, "apple,t6050-dcpext")) || !dcp->hw.adopt_live_session || dcp->hw.iomfb_method_profile != DCP_IOMFB_METHODS_DEFAULT || dcp->fw_compat != DCP_FIRMWARE_V_27_0) return false; - /* The enum also covers later 27.x method tables. */ - return dcp_read_fw_version(dev, "apple,firmware-compat", compat) >= 0 && - !strcmp(compat, "27.0.0"); + return iomfb_v27_sleep_methods_complete(dcp->v27_methods); } /* diff --git a/drivers/gpu/drm/apple/iomfb.c b/drivers/gpu/drm/apple/iomfb.c index 1de9af271a402..0e877825b8dba 100644 --- a/drivers/gpu/drm/apple/iomfb.c +++ b/drivers/gpu/drm/apple/iomfb.c @@ -899,11 +899,14 @@ static void iomfb_v27_sleep_start(struct apple_dcp *dcp, rpc->data, iomfb_v27_sleep_done, rpc); dcp->push_out_prefill = NULL; if ((rpc->a442 || rpc->a442_key) && !rpc->oob) { - static const struct dcp_method_entry a442 = { - .name = "v27_a442", .tag = { 'A', '4', '4', '2' }, - }; + struct dcp_method_entry a442 = { .name = "v27_a442" }; u8 in[92]; + if (iomfb_v27_tag(dcp->v27_methods, "A442", a442.tag)) { + dev_warn_once(dcp->dev, "skipping v27 wake A442: unmapped method tag\n"); + return; + } + memset(in, 0xaa, sizeof(in)); memset(in, 0, 16); in[8] = rpc->a442_key ?: 0x41; @@ -911,6 +914,9 @@ static void iomfb_v27_sleep_start(struct apple_dcp *dcp, if (rpc->a442_key) { memset(in + 80, 0, 12); in[84] = 0x20; + } else if (iomfb_v27_methods_renumbered(dcp->v27_methods)) { + /* 27.2 reads the filler as an index count and a block size. */ + memset(in + 16, 0, sizeof(in) - 16); } dcp_push(dcp, true, &a442, sizeof(in), 4100, in, iomfb_v27_a442_done, NULL); } @@ -988,6 +994,9 @@ int iomfb_v27_sleep_plain(struct apple_dcp *dcp, bool on) static int iomfb_v27_rpc(struct apple_dcp *dcp, bool a500, bool on, bool flags) { + struct dcp_method_entry method = { + .name = a500 ? "v27_sleep_500" : "v27_sleep_power", + }; struct iomfb_v27_sleep_rpc *rpc; u8 args[IOMFB_V27_SLEEP_ARGS]; int ret; @@ -998,6 +1007,9 @@ static int iomfb_v27_rpc(struct apple_dcp *dcp, bool a500, bool on, bool flags) (a500 || flags ? iomfb_v27_sleep_args(dcp, a500, args) : iomfb_v27_display_args(dcp, false, args))) return -EOPNOTSUPP; + ret = iomfb_v27_tag(dcp->v27_methods, a500 ? "A500" : "A484", method.tag); + if (ret) + return ret; rpc = kzalloc_obj(*rpc); if (!rpc) return -ENOMEM; @@ -1006,10 +1018,7 @@ static int iomfb_v27_rpc(struct apple_dcp *dcp, bool a500, bool on, bool flags) rpc->status = ~0U; rpc->transaction.start = iomfb_v27_sleep_start; rpc->transaction.release = iomfb_v27_sleep_release; - rpc->method = (struct dcp_method_entry) { - .name = a500 ? "v27_sleep_500" : "v27_sleep_power", - }; - memcpy(rpc->method.tag, a500 ? "A500" : "A484", 4); + rpc->method = method; /* * Off, before each DCP's and DCPEXT's sleep idle: A484 with the sleep's flags, then * A500's sleep form. On, after the wake: A500's wake form, then A484 with the flags. @@ -1081,6 +1090,7 @@ int iomfb_v27_sleep_a115(struct apple_dcp *dcp, bool awake) static int iomfb_v27_call(struct apple_dcp *dcp, const char *tag, const void *in, u32 in_len, u32 out_len, bool inout, u8 a442_key) { + struct dcp_method_entry method = { .name = "v27_display_stage" }; struct iomfb_v27_sleep_rpc *rpc; int ret; @@ -1088,6 +1098,9 @@ static int iomfb_v27_call(struct apple_dcp *dcp, const char *tag, const void *in dcp->fw_compat != DCP_FIRMWARE_V_27_0 || in_len > sizeof(rpc->data) || (inout && out_len > sizeof(rpc->data))) return -EOPNOTSUPP; + ret = iomfb_v27_tag(dcp->v27_methods, tag, method.tag); + if (ret) + return ret; rpc = kzalloc_obj(*rpc); if (!rpc) return -ENOMEM; @@ -1097,8 +1110,7 @@ static int iomfb_v27_call(struct apple_dcp *dcp, const char *tag, const void *in rpc->any_reply = true; rpc->transaction.start = iomfb_v27_sleep_start; rpc->transaction.release = iomfb_v27_sleep_release; - rpc->method = (struct dcp_method_entry) { .name = "v27_display_stage" }; - memcpy(rpc->method.tag, tag, 4); + rpc->method = method; rpc->input = in_len; rpc->output = out_len; rpc->inout = inout; diff --git a/drivers/gpu/drm/apple/iomfb.h b/drivers/gpu/drm/apple/iomfb.h index e230a9eac9c5c..0b2c04b7c6123 100644 --- a/drivers/gpu/drm/apple/iomfb.h +++ b/drivers/gpu/drm/apple/iomfb.h @@ -198,6 +198,28 @@ enum dcpep_method { dcpep_pipe_set_476, dcpep_unnamed_500, iomfbep_set_brightness_correction, + /* + * Firmware 27.x sleep and paired-mode calls named by their 27.0 ID. + * Optional for single-engine boot (iomfb_v27_missing_method() skips + * them); iomfb_v27_tag() refuses any call missing from a renumbered + * table. + */ + dcpep_v27_sleep_a115, + dcpep_v27_wake_a442, + dcpep_v27_peer_a360, + dcpep_v27_peer_a361, + dcpep_v27_peer_a362, + dcpep_v27_peer_a364, + dcpep_v27_peer_a365, + dcpep_v27_peer_a366, + dcpep_v27_peer_a367, + dcpep_v27_peer_a368, + dcpep_v27_peer_a369, + dcpep_v27_peer_a370, + dcpep_v27_peer_a371, + dcpep_v27_peer_a372, + dcpep_v27_peer_a373, + dcpep_v27_peer_a449, dcpep_num_methods }; @@ -220,6 +242,9 @@ struct dcp_method_entry { /* The IOMFB method table of a firmware 27.x build, by its compat string; NULL if unknown. */ const struct dcp_method_entry *iomfb_v27_methods(const char *compat); +bool iomfb_v27_methods_renumbered(const struct dcp_method_entry *methods); +int iomfb_v27_tag(const struct dcp_method_entry *methods, const char *tag, char *out); +bool iomfb_v27_sleep_methods_complete(const struct dcp_method_entry *methods); const struct dcp_method_entry *iomfb_v27_methods_j714s(struct device *dev, const struct dcp_method_entry *methods); /* The first method of a firmware 27.x table that has no ID, NULL if none. */ diff --git a/drivers/gpu/drm/apple/iomfb_v27.c b/drivers/gpu/drm/apple/iomfb_v27.c index a7d7d6b93f341..041ce575f8823 100644 --- a/drivers/gpu/drm/apple/iomfb_v27.c +++ b/drivers/gpu/drm/apple/iomfb_v27.c @@ -164,6 +164,22 @@ static const struct dcp_method_entry dcp_methods_27_0[dcpep_num_methods] = { * the IOMFB calls around it; 27.2 moved both to A550/A551. */ IOMFB_METHOD("A500", dcpep_unnamed_500), + IOMFB_METHOD("A115", dcpep_v27_sleep_a115), + IOMFB_METHOD("A442", dcpep_v27_wake_a442), + IOMFB_METHOD("A360", dcpep_v27_peer_a360), + IOMFB_METHOD("A361", dcpep_v27_peer_a361), + IOMFB_METHOD("A362", dcpep_v27_peer_a362), + IOMFB_METHOD("A364", dcpep_v27_peer_a364), + IOMFB_METHOD("A365", dcpep_v27_peer_a365), + IOMFB_METHOD("A366", dcpep_v27_peer_a366), + IOMFB_METHOD("A367", dcpep_v27_peer_a367), + IOMFB_METHOD("A368", dcpep_v27_peer_a368), + IOMFB_METHOD("A369", dcpep_v27_peer_a369), + IOMFB_METHOD("A370", dcpep_v27_peer_a370), + IOMFB_METHOD("A371", dcpep_v27_peer_a371), + IOMFB_METHOD("A372", dcpep_v27_peer_a372), + IOMFB_METHOD("A373", dcpep_v27_peer_a373), + IOMFB_METHOD("A449", dcpep_v27_peer_a449), }; /* @@ -222,6 +238,22 @@ static const struct dcp_method_entry dcp_methods_27_2[dcpep_num_methods] = { * dispatch where 26A428's compares 'A500' (0x1df68c vs 0x1de0dc, same code). */ IOMFB_METHOD("A550", dcpep_unnamed_500), + IOMFB_METHOD("A115", dcpep_v27_sleep_a115), + IOMFB_METHOD("A492", dcpep_v27_wake_a442), + IOMFB_METHOD("A360", dcpep_v27_peer_a360), + IOMFB_METHOD("A361", dcpep_v27_peer_a361), + IOMFB_METHOD("A362", dcpep_v27_peer_a362), + IOMFB_METHOD("A364", dcpep_v27_peer_a364), + IOMFB_METHOD("A365", dcpep_v27_peer_a365), + IOMFB_METHOD("A366", dcpep_v27_peer_a366), + IOMFB_METHOD("A367", dcpep_v27_peer_a367), + IOMFB_METHOD("A368", dcpep_v27_peer_a368), + IOMFB_METHOD("A369", dcpep_v27_peer_a369), + IOMFB_METHOD("A370", dcpep_v27_peer_a370), + IOMFB_METHOD("A371", dcpep_v27_peer_a371), + IOMFB_METHOD("A372", dcpep_v27_peer_a372), + IOMFB_METHOD("A373", dcpep_v27_peer_a373), + IOMFB_METHOD("A499", dcpep_v27_peer_a449), }; /* @@ -269,6 +301,76 @@ const struct dcp_method_entry *iomfb_v27_methods(const char *compat) return NULL; } +/* + * Translate @tag, a 27.0 ID named directly by sleep or paired-mode callers, + * into the build of @methods (4 bytes in @out). On 27.0 (including the J714s + * copy) the tag is sent unchanged. On a renumbered build every ID must come + * from @methods; a missing entry returns -EOPNOTSUPP instead of sending an + * unknown tag that would panic the firmware. + */ +int iomfb_v27_tag(const struct dcp_method_entry *methods, const char *tag, char *out) +{ + unsigned int i; + char in[4]; + + if (!methods) + return -EOPNOTSUPP; + memcpy(in, tag, 4); + if (!iomfb_v27_methods_renumbered(methods)) { + memcpy(out, in, 4); + return 0; + } + for (i = 0; i < dcpep_num_methods; i++) { + if (dcp_methods_27_0[i].tag[0] && !memcmp(dcp_methods_27_0[i].tag, in, 4)) { + if (!methods[i].tag[0]) + return -EOPNOTSUPP; + memcpy(out, methods[i].tag, 4); + return 0; + } + } + return -EOPNOTSUPP; +} + +/* Whether @methods is a build's table whose AP method IDs differ from 27.0's. */ +bool iomfb_v27_methods_renumbered(const struct dcp_method_entry *methods) +{ + unsigned int i; + + if (!methods || methods == dcp_methods_27_0) + return false; + for (i = 0; i < dcpep_num_methods; i++) { + if (memcmp(methods[i].tag, dcp_methods_27_0[i].tag, 4) && + !(i == dcpep_swap_submit && !memcmp(methods[i].tag, "A407", 4))) + return true; + } + return false; +} + +static const enum dcpep_method iomfb_v27_sleep_methods[] = { + dcpep_is_main_display, + dcpep_pipe_cfg_414, + dcpep_set_power_state, + dcpep_pipe_set_476, + dcpep_pipe_query_478, + dcpep_unnamed_500, + dcpep_v27_sleep_a115, + dcpep_v27_wake_a442, +}; + +/* Whether @methods names an ID for every call the firmware 27 display sleep sends. */ +bool iomfb_v27_sleep_methods_complete(const struct dcp_method_entry *methods) +{ + unsigned int i; + + if (!methods) + return false; + for (i = 0; i < ARRAY_SIZE(iomfb_v27_sleep_methods); i++) { + if (!methods[iomfb_v27_sleep_methods[i]].tag[0]) + return false; + } + return true; +} + /* * The 27.0 table for the J714s, the board the firmware 27 sleep has run on (dcp->v27_j714s): a * copy with the sleep's A500 added. The shared table keeps the methods it had, so every other @@ -309,9 +411,14 @@ const char *iomfb_v27_missing_method(const struct dcp_method_entry *methods, *count = 0; for (i = 0; i < dcpep_num_methods; i++) { - /* Only a firmware sleep sends unnamed_500, and it checks the build's table. */ + /* + * Only sleep and paired-mode paths send unnamed_500 and the + * v27-optional entries; each checks the build's table before + * sending. + */ if (!dcp_methods_27_0[i].tag[0] || methods[i].tag[0] || - i == dcpep_dfb_ready_query || i == dcpep_unnamed_500) + i == dcpep_dfb_ready_query || i == dcpep_unnamed_500 || + i >= dcpep_v27_sleep_a115) continue; if (!first) first = dcp_methods_27_0[i].name; diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py b/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py index 7a23fdb3ff45f..a4e74b38a57d9 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py @@ -216,10 +216,12 @@ def _v27_prelude(root, helpers): method_table = block(dcp_c, 'static enum dcp_firmware_version dcp_v27_method_table(') return r''' #include +#include #include #include #include #include +#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) typedef uint32_t u32; enum dcp_firmware_version { DCP_FIRMWARE_UNKNOWN, @@ -555,3 +557,194 @@ def t8122_dcpext_v27_admission(root): return 0; } ''' + + +def v27_tag_translation(root): + iomfb_h = (root / 'drivers/gpu/drm/apple/iomfb.h').read_text() + methods_decl = iomfb_h[iomfb_h.index('enum dcpep_method {'): + iomfb_h.index('#define IOMFB_MAX_CB')] + v27_c = (root / 'drivers/gpu/drm/apple/iomfb_v27.c').read_text() + v27_tables = v27_c[v27_c.index('static const struct dcp_method_entry dcp_methods_27_0'): + v27_c.index('/* The template\'s calls resolve through')] + dcp_c = (root / 'drivers/gpu/drm/apple/dcp.c').read_text() + transport = block(dcp_c, 'static bool dcp_v27_sleep_transport_supported(') + return r''' +#include +#include +#include +#include +#include +#include +#include +#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) +#define CONFIG_APPLE_SOC_SLEEP 1 +#define IS_ENABLED(option) (option) +#define GFP_KERNEL 0 +enum dcp_firmware_version { + DCP_FIRMWARE_UNKNOWN, + DCP_FIRMWARE_V_27_0, +}; +enum dcp_iomfb_method_profile { + DCP_IOMFB_METHODS_DEFAULT, + DCP_IOMFB_METHODS_H17G, +}; +struct device_node { const char *compatible; }; +struct device { struct device_node *of_node; }; +struct apple_dcp_hw_data { + bool adopt_live_session; + enum dcp_iomfb_method_profile iomfb_method_profile; +}; +struct apple_dcp { + struct device *dev; + struct apple_dcp_hw_data hw; + enum dcp_firmware_version fw_compat; + const struct dcp_method_entry *v27_methods; +}; +static int of_device_is_compatible(const struct device_node *np, const char *s) +{ + return np && np->compatible && !strcmp(np->compatible, s); +} +static void *devm_kmemdup(struct device *dev, const void *src, size_t len, unsigned int gfp) +{ + void *copy = malloc(len); + (void)dev; (void)gfp; + if (copy) + memcpy(copy, src, len); + return copy; +} +''' + methods_decl + '\n' + v27_tables + '\n' + transport + r''' +static void expect_tag(const struct dcp_method_entry *methods, const char *in, const char *want) +{ + char out[4] = { 'X', 'X', 'X', 'X' }; + assert(iomfb_v27_tag(methods, in, out) == 0); + assert(memcmp(out, want, 4) == 0); +} + +static void expect_tag_fail(const struct dcp_method_entry *methods, const char *in) +{ + char out[4] = { 'X', 'X', 'X', 'X' }; + assert(iomfb_v27_tag(methods, in, out) == -EOPNOTSUPP); + assert(memcmp(out, "XXXX", 4) == 0); +} + +int main(void) +{ + struct device_node node = { .compatible = "apple,t6050-dcp" }; + struct device dev = { .of_node = &node }; + const struct dcp_method_entry *m27_0 = iomfb_v27_methods("27.0.0"); + const struct dcp_method_entry *m27_2 = iomfb_v27_methods("27.2.0"); + const struct dcp_method_entry *m27_3 = iomfb_v27_methods("27.3.0"); + const struct dcp_method_entry *j714s = iomfb_v27_methods_j714s(&dev, m27_0); + struct dcp_method_entry partial_27_2[dcpep_num_methods]; + unsigned int missing_count; + + assert(m27_0 && m27_2 && m27_3 && j714s); + assert(!iomfb_v27_methods_renumbered(NULL)); + assert(!iomfb_v27_methods_renumbered(m27_0)); + assert(!iomfb_v27_methods_renumbered(j714s)); + assert(iomfb_v27_methods_renumbered(m27_2)); + assert(iomfb_v27_methods_renumbered(m27_3)); + + /* NULL table fails closed. */ + expect_tag_fail(NULL, "A411"); + assert(!iomfb_v27_sleep_methods_complete(NULL)); + + /* 27.0 and J714s copy keep 27.0 IDs unchanged. */ + expect_tag(m27_0, "A411", "A411"); + expect_tag(m27_0, "A484", "A484"); + expect_tag(m27_0, "A500", "A500"); + expect_tag(m27_0, "A442", "A442"); + expect_tag(m27_0, "A449", "A449"); + expect_tag(m27_0, "A115", "A115"); + expect_tag(m27_0, "A364", "A364"); + expect_tag(j714s, "A411", "A411"); + expect_tag(j714s, "A408", "A408"); + expect_tag(j714s, "A500", "A500"); + assert(iomfb_v27_sleep_methods_complete(m27_0)); + assert(iomfb_v27_sleep_methods_complete(j714s)); + assert(!iomfb_v27_missing_method(m27_0, &missing_count) && missing_count == 0); + + /* 27.2 translates every recorded shifted and unchanged paired/sleep tag. */ + const struct { const char *in, *out; } map_27_2[] = { + { "A406", "A456" }, { "A408", "A458" }, { "A411", "A461" }, { "A412", "A462" }, + { "A413", "A463" }, { "A414", "A464" }, { "A423", "A473" }, { "A428", "A478" }, + { "A442", "A492" }, { "A449", "A499" }, { "A450", "A500" }, { "A453", "A503" }, + { "A484", "A534" }, { "A487", "A537" }, { "A489", "A539" }, { "A500", "A550" }, + { "A115", "A115" }, + { "A360", "A360" }, { "A361", "A361" }, { "A362", "A362" }, { "A364", "A364" }, + { "A365", "A365" }, { "A366", "A366" }, { "A367", "A367" }, { "A368", "A368" }, + { "A369", "A369" }, { "A370", "A370" }, { "A371", "A371" }, { "A372", "A372" }, + { "A373", "A373" }, + }; + for (unsigned int i = 0; i < ARRAY_SIZE(map_27_2); i++) + expect_tag(m27_2, map_27_2[i].in, map_27_2[i].out); + assert(iomfb_v27_sleep_methods_complete(m27_2)); + assert(!iomfb_v27_missing_method(m27_2, &missing_count) && missing_count == 0); + + /* Unrecorded tags on 27.2 fail closed (no +50 arithmetic, no 27.0 fallback). */ + expect_tag_fail(m27_2, "A495"); + expect_tag_fail(m27_2, "A499"); + expect_tag_fail(m27_2, "A375"); + expect_tag_fail(m27_2, "A999"); + + /* Incomplete renumbered table (27.3) translates recorded entries and fails closed on missing ones. */ + expect_tag(m27_3, "A453", "A503"); + const char *missing_27_3[] = { + "A411", "A413", "A484", "A500", "A442", "A449", "A115", "A364", "A367", + }; + for (unsigned int i = 0; i < ARRAY_SIZE(missing_27_3); i++) + expect_tag_fail(m27_3, missing_27_3[i]); + assert(!iomfb_v27_sleep_methods_complete(m27_3)); + assert(iomfb_v27_missing_method(m27_3, &missing_count) && missing_count > 0); + + /* Dropping an optional sleep/paired entry does not block basic boot admission, + * but does mark sleep incomplete when a sleep entry is missing, and any table + * other than 27.0 or the J714s copy fails closed as renumbered. */ + memcpy(partial_27_2, m27_2, sizeof(partial_27_2)); + partial_27_2[dcpep_v27_wake_a442].tag[0] = '\0'; + assert(iomfb_v27_methods_renumbered(partial_27_2)); + expect_tag_fail(partial_27_2, "A442"); + assert(!iomfb_v27_missing_method(partial_27_2, &missing_count) && missing_count == 0); + assert(!iomfb_v27_sleep_methods_complete(partial_27_2)); + + struct dcp_method_entry future_27_x[dcpep_num_methods]; + memcpy(future_27_x, m27_0, sizeof(future_27_x)); + memcpy(future_27_x[dcpep_start_signal].tag, "A501", 4); + future_27_x[dcpep_v27_wake_a442].tag[0] = '\0'; + assert(iomfb_v27_methods_renumbered(future_27_x)); + expect_tag_fail(future_27_x, "A442"); + + /* + * Sleep transport admission keys on T6050 DCP/DCPEXT and table completeness. + * No of_machine_is_compatible() stub exists in this translation unit, enforcing + * at compile time that admission does not gate on a board model. + */ + struct apple_dcp dcp = { + .dev = &dev, + .hw = { .adopt_live_session = true, .iomfb_method_profile = DCP_IOMFB_METHODS_DEFAULT }, + .fw_compat = DCP_FIRMWARE_V_27_0, + }; + const char *t6050_compats[] = { "apple,t6050-dcp", "apple,t6050-dcpext" }; + for (unsigned int i = 0; i < ARRAY_SIZE(t6050_compats); i++) { + node.compatible = t6050_compats[i]; + dcp.v27_methods = m27_0; assert(dcp_v27_sleep_transport_supported(&dcp)); + dcp.v27_methods = j714s; assert(dcp_v27_sleep_transport_supported(&dcp)); + dcp.v27_methods = m27_2; assert(dcp_v27_sleep_transport_supported(&dcp)); + dcp.v27_methods = m27_3; assert(!dcp_v27_sleep_transport_supported(&dcp)); + dcp.v27_methods = partial_27_2; assert(!dcp_v27_sleep_transport_supported(&dcp)); + dcp.v27_methods = NULL; assert(!dcp_v27_sleep_transport_supported(&dcp)); + } + dcp.v27_methods = m27_2; + node.compatible = "apple,t6041-dcp"; assert(!dcp_v27_sleep_transport_supported(&dcp)); + node.compatible = "apple,t6050-dcp"; + dcp.hw.adopt_live_session = false; assert(!dcp_v27_sleep_transport_supported(&dcp)); + dcp.hw.adopt_live_session = true; + dcp.hw.iomfb_method_profile = DCP_IOMFB_METHODS_H17G; assert(!dcp_v27_sleep_transport_supported(&dcp)); + dcp.hw.iomfb_method_profile = DCP_IOMFB_METHODS_DEFAULT; + dcp.fw_compat = DCP_FIRMWARE_UNKNOWN; assert(!dcp_v27_sleep_transport_supported(&dcp)); + + free((void *)j714s); + puts("PASS v27 tag translation fail-closed and table-driven sleep transport admission"); + return 0; +} +''' diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/run.py b/tools/testing/selftests/drivers/gpu/apple-dcp/run.py index 87140d980dc95..f716cdbb5941b 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/run.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/run.py @@ -93,6 +93,7 @@ def main(): ('boot', 'syslog-policy', boot.syslog, ((),), ()), ('boot', 't6041-v27-admission', boot.t6041_v27_admission, ((),), ()), ('boot', 't8122-dcpext-v27-admission', boot.t8122_dcpext_v27_admission, ((),), ('-Wno-unused-function',)), + ('boot', 'v27-tag-translation', boot.v27_tag_translation, ((),), ()), ('edid', 'dpavserv-start', edid.startup, ((),), ()), ('edid', 'service-rebind', edid.rebind, ((),), ()), ('edid', 'provider-admission', edid.admission, ((),), ()),