Skip to content

Commit 4f6d9e3

Browse files
Wayne Linalexdeucher
authored andcommitted
drm/amd/display: Add polling method to handle MST reply packet
[Why] Specific TBT4 dock doesn't send out short HPD to notify source that IRQ event DOWN_REP_MSG_RDY is set. Which violates the spec and cause source can't send out streams to mst sinks. [How] To cover this misbehavior, add an additional polling method to detect DOWN_REP_MSG_RDY is set. HPD driven handling method is still kept. Just hook up our handler to drm mgr->cbs->poll_hpd_irq(). Cc: Mario Limonciello <[email protected]> Cc: Alex Deucher <[email protected]> Cc: [email protected] Reviewed-by: Jerry Zuo <[email protected]> Acked-by: Alan Liu <[email protected]> Signed-off-by: Wayne Lin <[email protected]> Tested-by: Daniel Wheeler <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent 87279fd commit 4f6d9e3

File tree

4 files changed

+159
-86
lines changed

4 files changed

+159
-86
lines changed

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Lines changed: 31 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,6 +1347,15 @@ static void dm_handle_hpd_rx_offload_work(struct work_struct *work)
13471347
if (amdgpu_in_reset(adev))
13481348
goto skip;
13491349

1350+
if (offload_work->data.bytes.device_service_irq.bits.UP_REQ_MSG_RDY ||
1351+
offload_work->data.bytes.device_service_irq.bits.DOWN_REP_MSG_RDY) {
1352+
dm_handle_mst_sideband_msg_ready_event(&aconnector->mst_mgr, DOWN_OR_UP_MSG_RDY_EVENT);
1353+
spin_lock_irqsave(&offload_work->offload_wq->offload_lock, flags);
1354+
offload_work->offload_wq->is_handling_mst_msg_rdy_event = false;
1355+
spin_unlock_irqrestore(&offload_work->offload_wq->offload_lock, flags);
1356+
goto skip;
1357+
}
1358+
13501359
mutex_lock(&adev->dm.dc_lock);
13511360
if (offload_work->data.bytes.device_service_irq.bits.AUTOMATED_TEST) {
13521361
dc_link_dp_handle_automated_test(dc_link);
@@ -3232,87 +3241,6 @@ static void handle_hpd_irq(void *param)
32323241

32333242
}
32343243

3235-
static void dm_handle_mst_sideband_msg(struct amdgpu_dm_connector *aconnector)
3236-
{
3237-
u8 esi[DP_PSR_ERROR_STATUS - DP_SINK_COUNT_ESI] = { 0 };
3238-
u8 dret;
3239-
bool new_irq_handled = false;
3240-
int dpcd_addr;
3241-
int dpcd_bytes_to_read;
3242-
3243-
const int max_process_count = 30;
3244-
int process_count = 0;
3245-
3246-
const struct dc_link_status *link_status = dc_link_get_status(aconnector->dc_link);
3247-
3248-
if (link_status->dpcd_caps->dpcd_rev.raw < 0x12) {
3249-
dpcd_bytes_to_read = DP_LANE0_1_STATUS - DP_SINK_COUNT;
3250-
/* DPCD 0x200 - 0x201 for downstream IRQ */
3251-
dpcd_addr = DP_SINK_COUNT;
3252-
} else {
3253-
dpcd_bytes_to_read = DP_PSR_ERROR_STATUS - DP_SINK_COUNT_ESI;
3254-
/* DPCD 0x2002 - 0x2005 for downstream IRQ */
3255-
dpcd_addr = DP_SINK_COUNT_ESI;
3256-
}
3257-
3258-
dret = drm_dp_dpcd_read(
3259-
&aconnector->dm_dp_aux.aux,
3260-
dpcd_addr,
3261-
esi,
3262-
dpcd_bytes_to_read);
3263-
3264-
while (dret == dpcd_bytes_to_read &&
3265-
process_count < max_process_count) {
3266-
u8 ack[DP_PSR_ERROR_STATUS - DP_SINK_COUNT_ESI] = {};
3267-
u8 retry;
3268-
3269-
dret = 0;
3270-
3271-
process_count++;
3272-
3273-
DRM_DEBUG_DRIVER("ESI %02x %02x %02x\n", esi[0], esi[1], esi[2]);
3274-
/* handle HPD short pulse irq */
3275-
if (aconnector->mst_mgr.mst_state)
3276-
drm_dp_mst_hpd_irq_handle_event(&aconnector->mst_mgr,
3277-
esi,
3278-
ack,
3279-
&new_irq_handled);
3280-
3281-
if (new_irq_handled) {
3282-
/* ACK at DPCD to notify down stream */
3283-
for (retry = 0; retry < 3; retry++) {
3284-
ssize_t wret;
3285-
3286-
wret = drm_dp_dpcd_writeb(&aconnector->dm_dp_aux.aux,
3287-
dpcd_addr + 1,
3288-
ack[1]);
3289-
if (wret == 1)
3290-
break;
3291-
}
3292-
3293-
if (retry == 3) {
3294-
DRM_ERROR("Failed to ack MST event.\n");
3295-
return;
3296-
}
3297-
3298-
drm_dp_mst_hpd_irq_send_new_request(&aconnector->mst_mgr);
3299-
/* check if there is new irq to be handled */
3300-
dret = drm_dp_dpcd_read(
3301-
&aconnector->dm_dp_aux.aux,
3302-
dpcd_addr,
3303-
esi,
3304-
dpcd_bytes_to_read);
3305-
3306-
new_irq_handled = false;
3307-
} else {
3308-
break;
3309-
}
3310-
}
3311-
3312-
if (process_count == max_process_count)
3313-
DRM_DEBUG_DRIVER("Loop exceeded max iterations\n");
3314-
}
3315-
33163244
static void schedule_hpd_rx_offload_work(struct hpd_rx_irq_offload_work_queue *offload_wq,
33173245
union hpd_irq_data hpd_irq_data)
33183246
{
@@ -3374,7 +3302,23 @@ static void handle_hpd_rx_irq(void *param)
33743302
if (dc_link_dp_allow_hpd_rx_irq(dc_link)) {
33753303
if (hpd_irq_data.bytes.device_service_irq.bits.UP_REQ_MSG_RDY ||
33763304
hpd_irq_data.bytes.device_service_irq.bits.DOWN_REP_MSG_RDY) {
3377-
dm_handle_mst_sideband_msg(aconnector);
3305+
bool skip = false;
3306+
3307+
/*
3308+
* DOWN_REP_MSG_RDY is also handled by polling method
3309+
* mgr->cbs->poll_hpd_irq()
3310+
*/
3311+
spin_lock(&offload_wq->offload_lock);
3312+
skip = offload_wq->is_handling_mst_msg_rdy_event;
3313+
3314+
if (!skip)
3315+
offload_wq->is_handling_mst_msg_rdy_event = true;
3316+
3317+
spin_unlock(&offload_wq->offload_lock);
3318+
3319+
if (!skip)
3320+
schedule_hpd_rx_offload_work(offload_wq, hpd_irq_data);
3321+
33783322
goto out;
33793323
}
33803324

@@ -3483,11 +3427,11 @@ static void register_hpd_handlers(struct amdgpu_device *adev)
34833427
amdgpu_dm_irq_register_interrupt(adev, &int_params,
34843428
handle_hpd_rx_irq,
34853429
(void *) aconnector);
3486-
3487-
if (adev->dm.hpd_rx_offload_wq)
3488-
adev->dm.hpd_rx_offload_wq[dc_link->link_index].aconnector =
3489-
aconnector;
34903430
}
3431+
3432+
if (adev->dm.hpd_rx_offload_wq)
3433+
adev->dm.hpd_rx_offload_wq[connector->index].aconnector =
3434+
aconnector;
34913435
}
34923436
}
34933437

@@ -7296,6 +7240,7 @@ void amdgpu_dm_connector_init_helper(struct amdgpu_display_manager *dm,
72967240
aconnector->as_type = ADAPTIVE_SYNC_TYPE_NONE;
72977241
memset(&aconnector->vsdb_info, 0, sizeof(aconnector->vsdb_info));
72987242
mutex_init(&aconnector->hpd_lock);
7243+
mutex_init(&aconnector->handle_mst_msg_ready);
72997244

73007245
/*
73017246
* configure support HPD hot plug connector_>polled default value is 0

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@ struct hpd_rx_irq_offload_work_queue {
194194
* we're handling link loss
195195
*/
196196
bool is_handling_link_loss;
197+
/**
198+
* @is_handling_mst_msg_rdy_event: Used to prevent inserting mst message
199+
* ready event when we're already handling mst message ready event
200+
*/
201+
bool is_handling_mst_msg_rdy_event;
197202
/**
198203
* @aconnector: The aconnector that this work queue is attached to
199204
*/
@@ -638,6 +643,8 @@ struct amdgpu_dm_connector {
638643
struct drm_dp_mst_port *mst_output_port;
639644
struct amdgpu_dm_connector *mst_root;
640645
struct drm_dp_aux *dsc_aux;
646+
struct mutex handle_mst_msg_ready;
647+
641648
/* TODO see if we can merge with ddc_bus or make a dm_connector */
642649
struct amdgpu_i2c_adapter *i2c;
643650

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,8 +619,118 @@ dm_dp_add_mst_connector(struct drm_dp_mst_topology_mgr *mgr,
619619
return connector;
620620
}
621621

622+
void dm_handle_mst_sideband_msg_ready_event(
623+
struct drm_dp_mst_topology_mgr *mgr,
624+
enum mst_msg_ready_type msg_rdy_type)
625+
{
626+
uint8_t esi[DP_PSR_ERROR_STATUS - DP_SINK_COUNT_ESI] = { 0 };
627+
uint8_t dret;
628+
bool new_irq_handled = false;
629+
int dpcd_addr;
630+
uint8_t dpcd_bytes_to_read;
631+
const uint8_t max_process_count = 30;
632+
uint8_t process_count = 0;
633+
u8 retry;
634+
struct amdgpu_dm_connector *aconnector =
635+
container_of(mgr, struct amdgpu_dm_connector, mst_mgr);
636+
637+
638+
const struct dc_link_status *link_status = dc_link_get_status(aconnector->dc_link);
639+
640+
if (link_status->dpcd_caps->dpcd_rev.raw < 0x12) {
641+
dpcd_bytes_to_read = DP_LANE0_1_STATUS - DP_SINK_COUNT;
642+
/* DPCD 0x200 - 0x201 for downstream IRQ */
643+
dpcd_addr = DP_SINK_COUNT;
644+
} else {
645+
dpcd_bytes_to_read = DP_PSR_ERROR_STATUS - DP_SINK_COUNT_ESI;
646+
/* DPCD 0x2002 - 0x2005 for downstream IRQ */
647+
dpcd_addr = DP_SINK_COUNT_ESI;
648+
}
649+
650+
mutex_lock(&aconnector->handle_mst_msg_ready);
651+
652+
while (process_count < max_process_count) {
653+
u8 ack[DP_PSR_ERROR_STATUS - DP_SINK_COUNT_ESI] = {};
654+
655+
process_count++;
656+
657+
dret = drm_dp_dpcd_read(
658+
&aconnector->dm_dp_aux.aux,
659+
dpcd_addr,
660+
esi,
661+
dpcd_bytes_to_read);
662+
663+
if (dret != dpcd_bytes_to_read) {
664+
DRM_DEBUG_KMS("DPCD read and acked number is not as expected!");
665+
break;
666+
}
667+
668+
DRM_DEBUG_DRIVER("ESI %02x %02x %02x\n", esi[0], esi[1], esi[2]);
669+
670+
switch (msg_rdy_type) {
671+
case DOWN_REP_MSG_RDY_EVENT:
672+
/* Only handle DOWN_REP_MSG_RDY case*/
673+
esi[1] &= DP_DOWN_REP_MSG_RDY;
674+
break;
675+
case UP_REQ_MSG_RDY_EVENT:
676+
/* Only handle UP_REQ_MSG_RDY case*/
677+
esi[1] &= DP_UP_REQ_MSG_RDY;
678+
break;
679+
default:
680+
/* Handle both cases*/
681+
esi[1] &= (DP_DOWN_REP_MSG_RDY | DP_UP_REQ_MSG_RDY);
682+
break;
683+
}
684+
685+
if (!esi[1])
686+
break;
687+
688+
/* handle MST irq */
689+
if (aconnector->mst_mgr.mst_state)
690+
drm_dp_mst_hpd_irq_handle_event(&aconnector->mst_mgr,
691+
esi,
692+
ack,
693+
&new_irq_handled);
694+
695+
if (new_irq_handled) {
696+
/* ACK at DPCD to notify down stream */
697+
for (retry = 0; retry < 3; retry++) {
698+
ssize_t wret;
699+
700+
wret = drm_dp_dpcd_writeb(&aconnector->dm_dp_aux.aux,
701+
dpcd_addr + 1,
702+
ack[1]);
703+
if (wret == 1)
704+
break;
705+
}
706+
707+
if (retry == 3) {
708+
DRM_ERROR("Failed to ack MST event.\n");
709+
return;
710+
}
711+
712+
drm_dp_mst_hpd_irq_send_new_request(&aconnector->mst_mgr);
713+
714+
new_irq_handled = false;
715+
} else {
716+
break;
717+
}
718+
}
719+
720+
mutex_unlock(&aconnector->handle_mst_msg_ready);
721+
722+
if (process_count == max_process_count)
723+
DRM_DEBUG_DRIVER("Loop exceeded max iterations\n");
724+
}
725+
726+
static void dm_handle_mst_down_rep_msg_ready(struct drm_dp_mst_topology_mgr *mgr)
727+
{
728+
dm_handle_mst_sideband_msg_ready_event(mgr, DOWN_REP_MSG_RDY_EVENT);
729+
}
730+
622731
static const struct drm_dp_mst_topology_cbs dm_mst_cbs = {
623732
.add_connector = dm_dp_add_mst_connector,
733+
.poll_hpd_irq = dm_handle_mst_down_rep_msg_ready,
624734
};
625735

626736
void amdgpu_dm_initialize_dp_connector(struct amdgpu_display_manager *dm,

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@
4949
#define PBN_FEC_OVERHEAD_MULTIPLIER_8B_10B 1031
5050
#define PBN_FEC_OVERHEAD_MULTIPLIER_128B_132B 1000
5151

52+
enum mst_msg_ready_type {
53+
NONE_MSG_RDY_EVENT = 0,
54+
DOWN_REP_MSG_RDY_EVENT = 1,
55+
UP_REQ_MSG_RDY_EVENT = 2,
56+
DOWN_OR_UP_MSG_RDY_EVENT = 3
57+
};
58+
5259
struct amdgpu_display_manager;
5360
struct amdgpu_dm_connector;
5461

@@ -61,6 +68,10 @@ void amdgpu_dm_initialize_dp_connector(struct amdgpu_display_manager *dm,
6168
void
6269
dm_dp_create_fake_mst_encoders(struct amdgpu_device *adev);
6370

71+
void dm_handle_mst_sideband_msg_ready_event(
72+
struct drm_dp_mst_topology_mgr *mgr,
73+
enum mst_msg_ready_type msg_rdy_type);
74+
6475
struct dsc_mst_fairness_vars {
6576
int pbn;
6677
bool dsc_enabled;

0 commit comments

Comments
 (0)