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
13 changes: 7 additions & 6 deletions drivers/gpu/drm/apple/dcp-fabric.c
Original file line number Diff line number Diff line change
Expand Up @@ -2257,22 +2257,23 @@ static int dcp_typec_route_apply(struct typec_mux_dev *mux,
struct apple_dcp *dcp = port->owner->dcp;

/*
* A T6030 external processor services the request itself, and
* reads the display again if it changed; elsewhere the active
* mode is applied again. H17P always applies it again. A running
* relink connects the sink anew; see dcp_typec_sink_relink().
* The request goes to the firmware's DPTX port, which reads the
* sink's status and services it (dcp_dptx_sink_irq()). H17P
* applies the active mode again. A running relink connects the
* sink anew; see dcp_typec_sink_relink(). A sink the firmware
* disconnected is recovered (dcp_dptx_recover_irq()).
*/
if (dcp->typec_connector && dcp->fw_compat == DCP_FIRMWARE_H17P)
dcp_retrain_oob(dcp->typec_connector);
else if (dcp->typec_connector && dcp->external_native)
dcp_external_sink_irq(dcp);
dcp_dptx_sink_irq(dcp);
else if (dcp->typec_connector && !dcp_typec_sink_relink(dcp)) {
if (!READ_ONCE(dcp->typec_connector->connected)) {
ret = dcp_dptx_recover_irq(dcp);
if (ret)
return ret;
} else {
dcp_retrain_oob(dcp->typec_connector);
dcp_dptx_sink_irq(dcp);
}
}
}
Expand Down
18 changes: 11 additions & 7 deletions drivers/gpu/drm/apple/dcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -3151,25 +3151,29 @@ void dcp_external_retry_work(struct work_struct *work)
}

/*
* The sink of a native external pipe raised IRQ_HPD with HPD staying high,
* as a DP branch device does when the display behind it changes. Pass the
* request to the firmware, which services it as a DP source does. If it
* The sink of a connected DPTX link raised IRQ_HPD with HPD staying high: it
* asks the source to read its status, because its link lost lock, a display
* behind a branch device changed, or for HDCP, MCCS or a test request. Only
* the firmware's DPTX port can read the sink's status over AUX, so pass the
* request to it, as its own HPD input would: the DP source is the one to read
* that status and train a link the sink lost again. The USB4 tunnel path
* passes the request the same way (dcp_tb_event_work()). If the firmware
* cannot take the request, connect the display link anew, which makes the
* firmware read the display again.
* firmware train it and read the display again.
*/
void dcp_external_sink_irq(struct apple_dcp *dcp)
void dcp_dptx_sink_irq(struct apple_dcp *dcp)
{
struct platform_device *pdev = to_platform_device(dcp->dev);
struct apple_epic_service *service = READ_ONCE(dcp->dptxport[0].service);
int ret;

/* With no link up, the next connect reads the display anyway. */
if (!dcp->external_native || !service || !dptx_service_available(&dcp->dptxport[0]) ||
if (!service || !dptx_service_available(&dcp->dptxport[0]) ||
!READ_ONCE(dcp->dptxport[0].connected))
return;
ret = dptxport_sink_irq(service);
if (!ret) {
dev_info(dcp->dev, "display sink IRQ_HPD passed to the firmware\n");
dev_dbg(dcp->dev, "display sink IRQ_HPD passed to the firmware\n");
return;
}
dev_info(dcp->dev, "display sink IRQ_HPD not passed (%d): connecting the display anew\n",
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/apple/dcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void dcp_external_ready(struct apple_dcp *dcp);
void dcp_external_retry(struct apple_dcp *dcp, const char *why, int error,
unsigned int base_ms);
void dcp_external_retry_work(struct work_struct *work);
void dcp_external_sink_irq(struct apple_dcp *dcp);
void dcp_dptx_sink_irq(struct apple_dcp *dcp);
void dcp_tb_event_work(struct work_struct *work);
void dcp_queue_typec_reconnect(struct apple_dcp *dcp, unsigned long delay);
int dcp_dptx_recover_irq(struct apple_dcp *dcp);
Expand Down
77 changes: 75 additions & 2 deletions tools/testing/selftests/drivers/gpu/apple-dcp/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,9 @@ def check(name, unit, cases=((),), negative=False, flags=()):
#ifndef DCP_IOMFB_METHODS_H17P_EXTERNAL
#define DCP_IOMFB_METHODS_H17P_EXTERNAL 2
#endif
/* T6030 external processors (dcp->external_native) are not in these scenarios. */
static void __attribute__((unused)) dcp_external_sink_irq(struct apple_dcp *d) { (void)d;assert(!"T6030 external sink IRQ"); }
/* A connected sink's IRQ_HPD goes to the firmware's DPTX port; these scenarios only count it. */
static int sink_irqs;
static void __attribute__((unused)) dcp_dptx_sink_irq(struct apple_dcp *d) { (void)d;sink_irqs++; }
static bool __attribute__((unused)) iomfb_v14_7_external_failed(struct apple_dcp *d) { (void)d;assert(!"T6030 external state");return false; }
/* fw_compat is UNKNOWN here: never H17P, 14.7 or 26.6. */
#ifndef DCP_FIRMWARE_H17P
Expand Down Expand Up @@ -203,6 +204,20 @@ def check(name, unit, cases=((),), negative=False, flags=()):
fprintf(stderr,"DP after failed SAFE: ret=%d connects=%d pending=%d wanted=%d hpd=%d\n",ret,connect_calls,port.safe_pending,port.dp_wanted,port.hpd);
assert(ret<0&&connect_calls==0&&!port.dp_wanted);
}
if(argv[1][0]=='i') {
/* A connected sink's IRQ_HPD goes to the firmware's DPTX port, once per request. */
struct typec_altmode alt={.svid=USB_TYPEC_DP_SID};
struct typec_displayport_data data={.status=DP_STATUS_HPD_STATE};
struct typec_mux_state dp={.alt=&alt,.mode=TYPEC_DP_STATE_A,.data=&data};
int ret=typec_mux_set(&mux,&dp);
fprintf(stderr,"DP: ret=%d connects=%d hpd=%d sink_irqs=%d\n",ret,connect_calls,port.hpd,sink_irqs);
assert(ret==0&&port.hpd&&sink_irqs==0);
data.status=DP_STATUS_HPD_STATE|DP_STATUS_IRQ_HPD;
ret=typec_mux_set(&mux,&dp);
fprintf(stderr,"IRQ_HPD: ret=%d sink_irqs=%d\n",ret,sink_irqs);
assert(ret==0&&sink_irqs==1);
puts("PASS a connected sink's IRQ_HPD is passed to the firmware's DPTX port");
}
if(argv[1][0]=='a') {
struct altmode alt={.mux=&mux,.adev={.svid=USB_TYPEC_DP_SID}};phy_error=-ETIMEDOUT;
int ret=typec_altmode_set_mux(&alt,TYPEC_STATE_SAFE,NULL);
Expand Down Expand Up @@ -234,6 +249,64 @@ def check(name, unit, cases=((),), negative=False, flags=()):
check('provider-order-releases-failed-lease',actual,(('release',),))
check('failed-safe-allows-new-dp-admission',actual,(('dp',),))
check('altmode-safe-skips-quiescence',actual,(('altmode',),))
check('connected-irq-hpd-to-firmware',actual,(('irq',),))

# Exact production dcp_dptx_sink_irq(): passed-through, reconnect fallback,
# disconnect-error stop, and no-link/unavailable guards.
sink_irq_unit = r'''
#include <assert.h>
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#define READ_ONCE(x) (x)
#define dev_dbg(...) ((void)0)
#define dev_info(...) ((void)0)
struct device { int unused; };
struct platform_device { struct device dev; };
struct apple_epic_service { int id; };
struct apple_dptxport { struct apple_epic_service *service; bool available, connected; };
struct apple_dcp { struct device *dev; struct apple_dptxport dptxport[1]; };
static struct platform_device pdev_inst;
static struct platform_device *to_platform_device(struct device *d) { (void)d; return &pdev_inst; }
static bool dptx_service_available(struct apple_dptxport *p) { return p->available; }
static int sink_irq_error, disconnect_error;
static int sink_irq_calls, disconnect_calls, connect_calls;
static char seq[16];
static void rec(char c) { size_t n = strlen(seq); if (n + 1 < sizeof(seq)) { seq[n] = c; seq[n + 1] = 0; } }
static int dptxport_sink_irq(struct apple_epic_service *s) { (void)s; rec('I'); sink_irq_calls++; return sink_irq_error; }
static int dcp_dptx_disconnect_oob(struct platform_device *p, unsigned idx) { (void)p; assert(idx == 0); rec('D'); disconnect_calls++; return disconnect_error; }
static int dcp_dptx_connect_oob(struct platform_device *p, unsigned idx) { (void)p; assert(idx == 0); rec('C'); connect_calls++; return 0; }
''' + block(dcp, 'void dcp_dptx_sink_irq(') + r'''
static void reset(void) { sink_irq_error = disconnect_error = 0; sink_irq_calls = disconnect_calls = connect_calls = 0; seq[0] = 0; }
int main(void) {
struct apple_epic_service svc = { .id = 1 };
struct apple_dcp dcp = { .dev = &pdev_inst.dev, .dptxport = {{ .service = &svc, .available = true, .connected = true }} };
/* Passed to firmware: no reconnect. */
reset();
dcp_dptx_sink_irq(&dcp);
assert(sink_irq_calls == 1 && disconnect_calls == 0 && connect_calls == 0 && !strcmp(seq, "I"));
/* Firmware refuses/fails call: fall back to disconnect then connect. */
reset(); sink_irq_error = -EOPNOTSUPP;
dcp_dptx_sink_irq(&dcp);
assert(sink_irq_calls == 1 && disconnect_calls == 1 && connect_calls == 1 && !strcmp(seq, "IDC"));
/* Disconnect error stops before reconnect. */
reset(); sink_irq_error = -EIO; disconnect_error = -ENODEV;
dcp_dptx_sink_irq(&dcp);
assert(sink_irq_calls == 1 && disconnect_calls == 1 && connect_calls == 0 && !strcmp(seq, "ID"));
/* Early guards: missing service, unavailable service, or disconnected link. */
reset(); dcp.dptxport[0].service = NULL;
dcp_dptx_sink_irq(&dcp);
dcp.dptxport[0].service = &svc; dcp.dptxport[0].available = false;
dcp_dptx_sink_irq(&dcp);
dcp.dptxport[0].available = true; dcp.dptxport[0].connected = false;
dcp_dptx_sink_irq(&dcp);
assert(sink_irq_calls == 0 && disconnect_calls == 0 && connect_calls == 0 && seq[0] == 0);
puts("PASS dcp_dptx_sink_irq passes IRQ_HPD to firmware and falls back to reconnect on error");
return 0;
}
'''
check('dcp-sink-irq-fallback', sink_irq_unit)

# Real pthread fabric/consumer mutexes. Pause the SAFE actor after its actual
# DCP prepare has returned and released its locks, before any set callback.
Expand Down
Loading