Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions src/kboot_display_routes.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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))
Expand All @@ -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;
}
Expand All @@ -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];

Expand All @@ -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)) {
Expand All @@ -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",
Expand Down
15 changes: 14 additions & 1 deletion tests/python/test_dcp_typec_routes_adt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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)}
Expand Down Expand Up @@ -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"));
Expand Down
Loading