From e11535d226e241a45e3751aa893824a1d54b076d Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sat, 28 Nov 2026 17:38:44 +1100 Subject: [PATCH] kboot: display routes: match a port's PD controller by port type too The ADT numbers ports per port type. On the 14-inch M5 Pro MacBook Pro (K114s) the left-back USB-C port's controller (hpm0, port-type 2) and the MagSafe 3 controller (hpm5, port-type 17, no transports) both carry port-number 1, and the HDMI output (atc3-dpphy, port-type 6) does too. The route writer took any controller with the output's number, found two for the left-back port and gave it no route. Take a controller only if its port-type matches the output's, when both name one. Outputs or controllers without a port-type match as before. On the K114s ADT (27.2) with the current K114s tree the written tree is byte-identical (ports 2 and 3 routed as before); port 1 now resolves to hpm0 and stops at "its ATC PHY is not described for Linux", which is what the tree says. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- src/kboot_display_routes.c | 25 ++++++++++++++++------- tests/python/test_dcp_typec_routes_adt.py | 15 +++++++++++++- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/kboot_display_routes.c b/src/kboot_display_routes.c index 55f234854..9911809fe 100644 --- a/src/kboot_display_routes.c +++ b/src/kboot_display_routes.c @@ -13,8 +13,9 @@ * (dp-switch-dfp-domain), DPTX target (dp-switch-dfp-endpoint), crossbar output cell * (dp-switch-dfp-port), its ATC PHY (atc-phy), its port's crossbar (dpxbar-parent) and * port-number; - * - the port's PD controller: the node below a bus with the same port-number, at its address - * on that bus. + * - the port's PD controller: the node below a bus with the same port-number and port-type + * (when both carry one: port numbers count per port type, so a MagSafe controller can share + * a USB-C port's number), at its address on that bus. * * Every output on the processor's die whose PHY, crossbar and PD controller the tree describes * becomes a route, matched by register address: the tree decides which ports Linux may have @@ -70,8 +71,11 @@ static ROUTES_TEXT int adt_reg_at(const char *path, int idx, u64 *addr) return adt_get_reg(adt, trace, "reg", idx, addr, NULL) ? -1 : 0; } -/* The PD controller of port `port`: a node below an /arm-io bus with that port-number */ -static ROUTES_TEXT int adt_port_controller(const char *name, u32 port, +/* + * The PD controller of port `port`: a node below an /arm-io bus with that port-number and, if + * both the output and the controller name one, the output's port-type (`type`, ~0 for none) + */ +static ROUTES_TEXT int adt_port_controller(const char *name, u32 port, u32 type, struct dcp_typec_port_facts *p) { int arm = adt_path_offset(adt, "/arm-io"), found = 0; @@ -89,6 +93,8 @@ static ROUTES_TEXT int adt_port_controller(const char *name, u32 port, const u32 *reg = adt_getprop(adt, hpm, "reg", &len); if (adt_u32(hpm, "port-number", &v) || v != port || !reg || len < 4) continue; + if (type != ~0U && !adt_u32(hpm, "port-type", &v) && v != type) + continue; /* another kind of port with the same number */ char path[64]; snprintf(path, sizeof(path), "/arm-io/%s", adt_get_name(adt, bus)); if (adt_reg_at(path, 0, &p->bus)) @@ -97,7 +103,10 @@ static ROUTES_TEXT int adt_port_controller(const char *name, u32 port, found++; } } - if (found != 1) + if (found != 1 && type != ~0U) + rlog("port %u (port-type %u): %d PD controllers in the ADT, not one: no route\n", port, + type, found); + else if (found != 1) rlog("port %u: %d PD controllers in the ADT, not one: no route\n", port, found); return found == 1 ? 0 : -1; } @@ -123,7 +132,7 @@ ROUTES_TEXT int dcp_typec_facts_from_adt(const char *adt_engine, struct dcp_type int out = arm; ADT_FOREACH_CHILD(adt, out) { - u32 xparent, tunneled, odomain = 0, phy_ph, xbar_ph; + u32 xparent, tunneled, odomain = 0, phy_ph, xbar_ph, type = ~0U, v; struct dcp_typec_port_facts p = {0}; char path[64]; @@ -134,6 +143,8 @@ ROUTES_TEXT int dcp_typec_facts_from_adt(const char *adt_engine, struct dcp_type adt_u32(out, "atc-phy", &phy_ph) || adt_u32(out, "dpxbar-parent", &xbar_ph)) continue; adt_u32(out, "dp-switch-dfp-domain", &odomain); + if (!adt_u32(out, "port-type", &v)) + type = v; if (odomain != domain) continue; if (adt_by_phandle(xbar_ph, path, sizeof(path)) < 0 || adt_reg_at(path, 0, &p.xbar)) { @@ -146,7 +157,7 @@ ROUTES_TEXT int dcp_typec_facts_from_adt(const char *adt_engine, struct dcp_type } while (p.nphy < DCP_TYPEC_PHY_REGS && !adt_reg_at(path, p.nphy, &p.phy[p.nphy])) p.nphy++; - if (!p.nphy || adt_port_controller(name, p.port, &p)) + if (!p.nphy || adt_port_controller(name, p.port, type, &p)) continue; if (f->nports == DCP_TYPEC_MAX_PORTS) { rlog("more than %d DP outputs on die %u: port %u and later not considered\n", diff --git a/tests/python/test_dcp_typec_routes_adt.py b/tests/python/test_dcp_typec_routes_adt.py index a65bfc540..7b4800a42 100644 --- a/tests/python/test_dcp_typec_routes_adt.py +++ b/tests/python/test_dcp_typec_routes_adt.py @@ -11,7 +11,7 @@ XBAR = 406 -def adt_nodes(duplicate_port=None): +def adt_nodes(duplicate_port=None, typed_port=None): nodes = [{"path": "/arm-io"}, {"path": "/arm-io/display-crossbar0", "props": {"AAPL,phandle": u32(XBAR)}}] atc = [(0, 1, 0, 0x2a3000000, 0x2a324c000), (1, 2, 0, 0x2ab000000, 0x2ab24c000), @@ -42,6 +42,14 @@ def adt_nodes(duplicate_port=None): if duplicate_port: nodes.append({"path": "/arm-io/nub-spmi-a2/hpm9", "props": { "port-number": u32(duplicate_port), "reg": u32(0x2, 3, 0, 4)}}) + if typed_port: + # Port types on the outputs and controllers (2: USB-C), and a MagSafe controller (17) + # that shares the port's number, as on the 14-inch M5 Pro MacBook Pro + for node in nodes: + if "port-number" in node.get("props", {}): + node["props"]["port-type"] = u32(2) + nodes.append({"path": "/arm-io/nub-spmi-a2/hpm5", "props": { + "port-number": u32(typed_port), "port-type": u32(17), "reg": u32(0x2, 3, 0, 4)}}) for n, ep, die in ((0, 0, 0), (1, 1, 0), (4, 0, 1)): props = {"dp-switch-parent": u32(XBAR), "dp-switch-ufp-endpoint": u32(ep), "dp-switch-ufp-port": u32(0)} @@ -207,6 +215,11 @@ def test_contradictory_adt_routes_nothing_on_that_port(tmp_path): assert "port 3: 2 PD controllers in the ADT, not one" in out and "ROUTES0 2" in out +def test_another_port_type_with_the_same_number_is_not_the_controller(tmp_path): + out = run(tmp_path, adt_nodes(typed_port=3), ENGINES, dt_setup()) + assert "PD controllers in the ADT" not in out and "ROUTES0 3" in out + + def test_a_tree_without_the_request_is_untouched(tmp_path): out = run(tmp_path, adt_nodes(), r''' fdt_del_node(dt, node("%(e0)s/typec-routes"));