diff --git a/arch/arm64/boot/dts/apple/t8112-j473.dts b/arch/arm64/boot/dts/apple/t8112-j473.dts index 1327968da6fdb..5acd467133740 100644 --- a/arch/arm64/boot/dts/apple/t8112-j473.dts +++ b/arch/arm64/boot/dts/apple/t8112-j473.dts @@ -9,8 +9,6 @@ /dts-v1/; -#define T8112_TYPEC_DCP - #include "t8112.dtsi" #include "t8112-jxxx.dtsi" @@ -42,71 +40,36 @@ }; &dcpext { status = "okay"; - apple,connector-type = "HDMI-A"; - - /* HDMI HPD gpio, used as interrupt*/ - hdmi-hpd-gpios = <&pinctrl_aop 49 GPIO_ACTIVE_HIGH>; - - hdmi-pwren-gpios = <&smc_gpio 21 GPIO_ACTIVE_HIGH>; - dp2hdmi-pwren-gpios = <&smc_gpio 22 GPIO_ACTIVE_HIGH>; - - phys = <&dptxphy>; - phy-names = "dp-phy"; - apple,dptx-phy = <5>; }; &display { - /* dispext0_dart needs to be first for m1n1's */ - iommus = <&dispext0_dart 0 0x0 0x0 0xf 0xffff0000>, - <&disp0_dart 0 0x0 0x0 0xf 0xffff0000>; + /* the boot display (HDMI on dcp) DART first, for the boot loader */ + iommus = <&disp0_dart 0 0x0 0x0 0xf 0xffff0000>, + <&dispext0_dart 0 0x0 0x0 0xf 0xffff0000>; }; &disp0_dart { status = "okay"; }; +/* + * As macOS does: the HDMI port (DP to HDMI converter behind dptxphy, DFP + * endpoint 5 of the display switch) on the primary DCP, the USB-C ports on + * dcpext (t8112-jxxx.dtsi), which offers DSC. + */ &dcp { status = "okay"; - apple,connector-type = "USB-C"; - phys = <&atcphy0 PHY_TYPE_DP>, <&atcphy1 PHY_TYPE_DP>; - phy-names = "typec0", "typec1"; - mux-controls = <&atcphy0_xbar 0>, <&atcphy1_xbar 0>; - mux-control-names = "typec0", "typec1"; - apple,typec-mux-indices = <0 0>; - apple,typec-dptx-phys = <0 1>; - - typec-routes { - #address-cells = <1>; - #size-cells = <0>; - - route@0 { - reg = <0>; - mode-switch; - - port { - dcp_typec0: endpoint { - remote-endpoint = <&typec0_dcp>; - }; - }; - }; + apple,connector-type = "HDMI-A"; - route@1 { - reg = <1>; - mode-switch; + /* HDMI HPD gpio, used as interrupt*/ + hdmi-hpd-gpios = <&pinctrl_aop 49 GPIO_ACTIVE_HIGH>; - port { - dcp_typec1: endpoint { - remote-endpoint = <&typec1_dcp>; - }; - }; - }; - }; -}; + hdmi-pwren-gpios = <&smc_gpio 21 GPIO_ACTIVE_HIGH>; + dp2hdmi-pwren-gpios = <&smc_gpio 22 GPIO_ACTIVE_HIGH>; -&dcpext { - /delete-property/ mux-controls; - /delete-property/ mux-control-names; - /delete-property/ mux-index; + phys = <&dptxphy>; + phy-names = "dp-phy"; + apple,dptx-phy = <5>; }; /* @@ -129,45 +92,12 @@ status = "disabled"; }; -&typec0 { - ports { - port@3 { - reg = <3>; - typec0_dcp: endpoint { - remote-endpoint = <&dcp_typec0>; - }; - }; - }; -}; - -&typec1 { - ports { - port@3 { - reg = <3>; - typec1_dcp: endpoint { - remote-endpoint = <&dcp_typec1>; - }; - }; - }; -}; - /* - * Keep the power-domains used for the HDMI port on. + * Keep the power-domains used for the HDMI port on (disp0 stays always-on + * from t8112.dtsi). */ &framebuffer0 { - power-domains = <&ps_dispext_cpu0>, <&ps_dptx_ext_phy>; -}; - -/* - * The M2 Mac mini uses dispext for the HDMI output so it's not necessary to - * keep disp0 power-domains always-on. - */ -&ps_disp0_sys { - /delete-property/ apple,always-on; -}; - -&ps_disp0_fe { - /delete-property/ apple,always-on; + power-domains = <&ps_disp0_cpu0>, <&ps_dptx_ext_phy>; }; /* diff --git a/drivers/gpu/drm/apple/afk.c b/drivers/gpu/drm/apple/afk.c index 10e3586487a9d..7ad9bb7d1fc58 100644 --- a/drivers/gpu/drm/apple/afk.c +++ b/drivers/gpu/drm/apple/afk.c @@ -1888,7 +1888,8 @@ static void afk_recv_handle_init(struct apple_dcp_afkep *ep, u32 channel, (ep->dcp->fw_compat == DCP_FIRMWARE_V_27_0 && ep->dcp->hw.firmware_compat == DCP_FIRMWARE_H17P) || ep->dcp->v27_j714s || - (ep->dcp->fw_compat == DCP_FIRMWARE_V_27_0 && ep->dcp->dcpext) || + (ep->dcp->fw_compat == DCP_FIRMWARE_V_27_0 && + dcp_has_external_output(ep->dcp)) || (ep->dcp->v27_sleep_transport && !strcmp(name, "md-manager")))) { /* * H17G and firmware-27 T8142 can omit EPIC identity diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index fed8da33424ee..621a2083c5bbb 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -1614,6 +1614,16 @@ static inline bool dcp_is_v27_external(const struct apple_dcp *dcp) dcp->hw.dptx_endpoint == DPTX_ENDPOINT_V2; } +/* + * A DCP that drives an external connector: an external processor, Type-C + * display routes, or a fixed DP/HDMI PHY in its device tree node (a primary + * DCP can own the fixed HDMI route, as on the M2 Mac mini). + */ +static inline bool dcp_has_external_output(const struct apple_dcp *dcp) +{ + return dcp->dcpext || dcp->nr_typec_routes || dcp->fixed_phy; +} + /* The 14.7 internal panel (J514S/J516S), presented through DCPLink. */ static inline bool dcp_is_v14_7_panel(const struct apple_dcp *dcp) { diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index c886a9bcde7b0..0af9eac57b228 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -5100,7 +5100,7 @@ static int dcp_ext26_start_services(struct apple_dcp *dcp) static void dcp_v27_dptx_layout(struct apple_dcp *dcp) { if (dcp->fw_compat != DCP_FIRMWARE_V_27_0 || - (!dcp->dcpext && !dcp->nr_typec_routes) || dcp->hw.dptx_endpoint) + !dcp_has_external_output(dcp) || dcp->hw.dptx_endpoint) return; if (!apple_rtkit_has_endpoint(dcp->rtk, DPTX_CONTROLLER_ENDPOINT) || !apple_rtkit_has_endpoint(dcp->rtk, DPTX_ENDPOINT)) diff --git a/drivers/gpu/drm/apple/dptxep.c b/drivers/gpu/drm/apple/dptxep.c index 513514cd2cfb1..f7d4f8b8efba3 100644 --- a/drivers/gpu/drm/apple/dptxep.c +++ b/drivers/gpu/drm/apple/dptxep.c @@ -1676,7 +1676,7 @@ int dptxep_init(struct apple_dcp *dcp) */ if (dcp_fw_is_14_7(dcp) || dcp_is_ext26(dcp) || (dcp->fw_compat == DCP_FIRMWARE_V_27_0 && - (dcp->dcpext || dcp->nr_typec_routes))) { + dcp_has_external_output(dcp))) { dev_info(dcp->dev, "DPTX port %u not announced yet\n", port); return 0; diff --git a/tools/asahi/dcp-v27-dptx-layout-tests.py b/tools/asahi/dcp-v27-dptx-layout-tests.py index 1119c30a4acc9..bdb9b45e00b31 100755 --- a/tools/asahi/dcp-v27-dptx-layout-tests.py +++ b/tools/asahi/dcp-v27-dptx-layout-tests.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # SPDX-License-Identifier: GPL-2.0-only OR MIT -"""Where a firmware-27 dcpext, or a DCP with Type-C routes, opens its DPTX controller and ports. +"""Where a firmware-27 dcpext, or a DCP with Type-C routes or a fixed DP/HDMI PHY, opens its DPTX controller and ports. Builds the production dcp_v27_dptx_layout() and dptxep_init()'s endpoint choice, and runs them over firmware, processor role, advertised endpoints and @@ -22,14 +22,16 @@ MUTATIONS = { # Select on firmware 27 alone, without the advertisement. - 'ignore-advertisement': ('\tif (!apple_rtkit_has_endpoint(dcp->rtk, DPTX_CONTROLLER_ENDPOINT) ||\n' + 'ignore-advertisement': ('layout', '\tif (!apple_rtkit_has_endpoint(dcp->rtk, DPTX_CONTROLLER_ENDPOINT) ||\n' '\t !apple_rtkit_has_endpoint(dcp->rtk, DPTX_ENDPOINT))\n\t\treturn;\n', ''), # Override hardware data that already names an endpoint. - 'ignore-pinned': (' || dcp->hw.dptx_endpoint)\n', ')\n'), - # Apply to every processor, with or without Type-C routes. - 'ignore-dcpext': ('(!dcp->dcpext && !dcp->nr_typec_routes) || ', ''), + 'ignore-pinned': ('layout', ' || dcp->hw.dptx_endpoint)\n', ')\n'), + # Apply to every processor, with or without an external output. + 'ignore-dcpext': ('layout', '\n\t !dcp_has_external_output(dcp) ||', ''), # Leave a DCP with Type-C routes on the default endpoints. - 'ignore-typec-routes': ('(!dcp->dcpext && !dcp->nr_typec_routes)', '!dcp->dcpext'), + 'ignore-typec-routes': ('helper', 'dcp->nr_typec_routes || ', ''), + # Leave a DCP with a fixed DP/HDMI PHY (the M2 Mac mini's HDMI on dcp) on the default endpoints. + 'ignore-fixed-phy': ('helper', ' || dcp->fixed_phy', ''), } parser = argparse.ArgumentParser(description=__doc__) @@ -39,6 +41,7 @@ root = Path(__file__).resolve().parents[2] apple = root / 'drivers/gpu/drm/apple' dcp_c = (apple / 'dcp.c').read_text() +internal_h = (apple / 'dcp-internal.h').read_text() dptx_c = (apple / 'dptxep.c').read_text() @@ -79,10 +82,17 @@ def table(name): t6041 = t6041[:t6041.index('\n\t}\n')] assert 'dcp->hw.dptx_endpoint = DPTX_ENDPOINT_V2;' in t6041 +# dcpext, Type-C routes or a fixed PHY: the production helper. +helper = function(internal_h, 'static inline bool dcp_has_external_output(') + if args.mutation: - old, new = MUTATIONS[args.mutation] - assert layout.count(old) == 1, args.mutation - layout = layout.replace(old, new) + target, old, new = MUTATIONS[args.mutation] + if target == 'layout': + assert layout.count(old) == 1, args.mutation + layout = layout.replace(old, new) + else: + assert helper.count(old) == 1, args.mutation + helper = helper.replace(old, new) program = r''' #include @@ -96,14 +106,14 @@ def table(name): #define DPTX_CONTROLLER_ENDPOINT 0x24 #define DPTX_ENDPOINT 0x2a #define DPTX_ENDPOINT_V2 0x2c -struct apple_dcp { int fw_compat; bool dcpext, ext26; u32 nr_typec_routes; void *rtk, *dev; +struct apple_dcp { int fw_compat; bool dcpext, ext26; u32 nr_typec_routes; void *rtk, *dev, *fixed_phy; struct { u8 dptx_endpoint; bool dptx_controller; int iomfb_method_profile; } hw; }; static u32 advertised; static bool apple_rtkit_has_endpoint(void *rtk, int ep) { return advertised & (1u << (ep - 0x20)); } static bool dcp_is_ext26(struct apple_dcp *dcp) { return dcp->ext26; } static int info_lines; #define dev_info(...) (info_lines++) -''' + layout + r''' +''' + helper + '\n' + layout + r''' static u8 dptx_ep(struct apple_dcp *dcp) { bool wire_v2 = ''' + wire + r'''; @@ -126,12 +136,14 @@ def table(name): for (unsigned m = 0; m < 6; m++) for (unsigned p = 0; p < 3; p++) for (unsigned c = 0; c < 2; c++) - for (unsigned r = 0; r < 2; r++) { + for (unsigned r = 0; r < 2; r++) + for (unsigned ph = 0; ph < 2; ph++) { struct apple_dcp d = { .fw_compat = fws[f], .dcpext = ext, .nr_typec_routes = 2 * r, + .fixed_phy = ph ? &advertised : NULL, .hw.dptx_endpoint = pins[p], .hw.dptx_controller = c }; struct apple_dcp before = d; bool both = (maps[m] & BIT(0x24)) && (maps[m] & BIT(0x2a)); - bool chosen = fws[f] == DCP_FIRMWARE_V_27_0 && (ext || r) && !pins[p] && both; + bool chosen = fws[f] == DCP_FIRMWARE_V_27_0 && (ext || r || ph) && !pins[p] && both; advertised = maps[m]; info_lines = 0; @@ -179,4 +191,4 @@ def table(name): run = subprocess.run([str(exe)]) if run.returncode: sys.exit(f'FAIL: the layout matrix exited {run.returncode}') -print('PASS firmware-27 dcpext / Type-C-routed DCP DPTX layout from its advertised endpoints; pinned and other processors unchanged') +print('PASS firmware-27 dcpext / Type-C-routed / fixed-PHY DCP DPTX layout from its advertised endpoints; pinned and other processors unchanged') diff --git a/tools/asahi/dcpext26-startup-tests.py b/tools/asahi/dcpext26-startup-tests.py index a838f61630640..8e11963bd4f1b 100644 --- a/tools/asahi/dcpext26-startup-tests.py +++ b/tools/asahi/dcpext26-startup-tests.py @@ -94,7 +94,8 @@ def run(name,code,reject=False): struct apple_epic_service_ops {const char *name;bool reusable,optional,open_later,singleton;int (*prepare)(struct apple_epic_service *,const char *,const char *,s64);int (*revalidate)(struct apple_epic_service *,const char *,const char *,s64);void (*init)(struct apple_epic_service *,const char *,const char *,s64);void (*teardown)(struct apple_epic_service *);void (*init_props)(struct apple_epic_service *,s64,const void *,size_t);}; struct apple_epic_service {struct apple_dcp_afkep *ep;const struct apple_epic_service_ops *ops;bool enabled,torndown,pending_open,defer_start;unsigned users;int lock;u32 channel;void *cookie;const char *pending_name,*pending_class;s64 pending_unit;int cmd_map[1];}; struct dptx_port {struct apple_epic_service *service;s64 unit;bool enabled,connected;int enable_completion;}; -struct apple_dcp {const void *push_out_prefill;bool native,ext26_services_open,v27_j714s,v27_sleep_transport,dcpext;int fw_compat,index,dptx_controller_ready;struct {unsigned num_dptx_ports;int iomfb_method_profile,firmware_compat;bool afk_announced_names;} hw;struct dptx_port dptxport[2];void *dev;struct apple_dcp_afkep *systemep,*ibootep,*dptx_controller_ep,*dcpavservep,*dptxep,*ext26_aux[3];}; +struct apple_dcp {const void *push_out_prefill;bool native,ext26_services_open,v27_j714s,v27_sleep_transport,dcpext;int fw_compat,index,dptx_controller_ready;struct {unsigned num_dptx_ports;int iomfb_method_profile,firmware_compat;bool afk_announced_names;} hw;struct dptx_port dptxport[2];void *dev,*fixed_phy;u32 nr_typec_routes;struct apple_dcp_afkep *systemep,*ibootep,*dptx_controller_ep,*dcpavservep,*dptxep,*ext26_aux[3];}; +''' + fn((A/'dcp-internal.h').read_text(),'dcp_has_external_output') + r''' struct apple_dcp_afkep {struct apple_dcp *dcp;u32 endpoint,num_channels;bool wire_v2,stopping,match_epic_name,compact;int lock;void *wq,*service_work;const struct apple_epic_service_ops *ops,*unmatched_ops;struct apple_epic_service services[AFK_MAX_CHANNEL];int service_wq;}; #define wake_up_all(q) ((void)(q)) static bool dcp_is_ext26(struct apple_dcp *d){return d->native;} diff --git a/tools/asahi/run-host-tests.py b/tools/asahi/run-host-tests.py index 00123f40bd467..878bd523788b0 100755 --- a/tools/asahi/run-host-tests.py +++ b/tools/asahi/run-host-tests.py @@ -95,7 +95,7 @@ def mutations(flag, names, base, expect=KILL): '--mutation', ['eopnotsupp', 'accept-with-rate', 'refuse-drive'], []), 'dcp-v27-dptx-layout-tests.py': [([], PASS)] + mutations( '--mutation', ['ignore-advertisement', 'ignore-pinned', 'ignore-dcpext', - 'ignore-typec-routes'], []), + 'ignore-typec-routes', 'ignore-fixed-phy'], []), 'dptx-set-active-lane-count-tests.py': [([], PASS)] + mutations( '--mutation', ['drop-fixed-phy', 'skip-all-unexpected'], []), 'dcpext26-wire-tests.py': [([], PASS)], diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/edid.py b/tools/testing/selftests/drivers/gpu/apple-dcp/edid.py index d2ca8a50eb36a..ce1b70f09220a 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/edid.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/edid.py @@ -107,8 +107,8 @@ def function(file,signature): u64 opened_epoch,close_gen,terminated_epoch,close_epoch;bool opening;struct work_struct close_wq; } dcpavserv; /* A J714s firmware 27 processor's: this one is not. */ bool v27_j714s, v27_sleep_transport; struct apple_dcp_afkep *sleep_v27_ep[0x20], *panelav[0x20]; - /* Not a dcpext: none of these scenarios is an external processor. */ - bool dcpext; + /* Not a dcpext and no external output: none of these scenarios is an external processor. */ + bool dcpext; unsigned int nr_typec_routes; void *fixed_phy; }; #define DPTX_ENDPOINT_V2 0x2c '''+internal_inline(root,'dcp_fw_is_14_7')+internal_inline(root,'dcp_is_v14_7_external')+internal_inline(root,'dcp_is_v27_external')+r'''struct epic_cmd { u32 retcode;u64 rxbuf,txbuf;u32 rxlen,txlen; }; @@ -184,7 +184,7 @@ def function(file,signature): function('afk.c','static const struct apple_epic_service_ops *\nafk_match_service('), function('afk.c','static struct apple_epic_service *afk_epic_find_service('), function('afk.h','static inline bool afk_service_retired('),function('afk.h','static inline bool afk_service_supersede('),function('afk.c','static bool afk_epic_channel_retired('), - function('afk.c','static void afk_discard_pending_open('),function('afk.c','static void afk_retry_service_init('),function('afk.c','static void afk_service_worker('),function('afk.c','static void afk_recv_handle_init('), + function('afk.c','static void afk_discard_pending_open('),function('afk.c','static void afk_retry_service_init('),function('afk.c','static void afk_service_worker('),function('dcp-internal.h','static inline bool dcp_has_external_output('),function('afk.c','static void afk_recv_handle_init('), function('epic/dpavservep.c','static int dcpdpserv_prepare('), function('epic/dpavservep.c','static void dcpdpserv_teardown('),function('afk.c','static void afk_recv_handle_teardown('), function('afk.c','static void afk_recv_handle_reply(')]