Skip to content

Commit 0bdf5a0

Browse files
committed
drm/i915: Add reverse mapping between port and intel_encoder
This patch adds a reverse mapping from a digital port number to intel_encoder object containing the corresponding intel_digital_port. It simplifies the query of the encoder a lot. Note that, even if it's a valid digital port, the dig_port_map[] might point still to NULL -- usually it implies a DP MST port. Due to this fact, the NULL check in each place has no WARN_ON() and just skips the port. Once when the situation changes in future, we might introduce WARN_ON() for a more strict check. Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent cae666c commit 0bdf5a0

File tree

5 files changed

+30
-35
lines changed

5 files changed

+30
-35
lines changed

drivers/gpu/drm/i915/i915_drv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,6 +1944,8 @@ struct drm_i915_private {
19441944
/* perform PHY state sanity checks? */
19451945
bool chv_phy_assert[2];
19461946

1947+
struct intel_encoder *dig_port_map[I915_MAX_PORTS];
1948+
19471949
/*
19481950
* NOTE: This is the dri1/ums dungeon, don't add stuff here. Your patch
19491951
* will be rejected. Instead look for a better place.

drivers/gpu/drm/i915/intel_audio.c

Lines changed: 24 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -636,15 +636,14 @@ static int i915_audio_component_sync_audio_rate(struct device *dev,
636636
int port, int rate)
637637
{
638638
struct drm_i915_private *dev_priv = dev_to_i915(dev);
639-
struct drm_device *drm_dev = dev_priv->dev;
640639
struct intel_encoder *intel_encoder;
641-
struct intel_digital_port *intel_dig_port;
642640
struct intel_crtc *crtc;
643641
struct drm_display_mode *mode;
644642
struct i915_audio_component *acomp = dev_priv->audio_component;
645-
enum pipe pipe = -1;
643+
enum pipe pipe = INVALID_PIPE;
646644
u32 tmp;
647645
int n;
646+
int err = 0;
648647

649648
/* HSW, BDW, SKL, KBL need this fix */
650649
if (!IS_SKYLAKE(dev_priv) &&
@@ -655,26 +654,22 @@ static int i915_audio_component_sync_audio_rate(struct device *dev,
655654

656655
mutex_lock(&dev_priv->av_mutex);
657656
/* 1. get the pipe */
658-
for_each_intel_encoder(drm_dev, intel_encoder) {
659-
if (intel_encoder->type != INTEL_OUTPUT_HDMI)
660-
continue;
661-
intel_dig_port = enc_to_dig_port(&intel_encoder->base);
662-
if (port == intel_dig_port->port) {
663-
crtc = to_intel_crtc(intel_encoder->base.crtc);
664-
if (!crtc) {
665-
DRM_DEBUG_KMS("%s: crtc is NULL\n", __func__);
666-
continue;
667-
}
668-
pipe = crtc->pipe;
669-
break;
670-
}
657+
intel_encoder = dev_priv->dig_port_map[port];
658+
/* intel_encoder might be NULL for DP MST */
659+
if (!intel_encoder || !intel_encoder->base.crtc ||
660+
intel_encoder->type != INTEL_OUTPUT_HDMI) {
661+
DRM_DEBUG_KMS("no valid port %c\n", port_name(port));
662+
err = -ENODEV;
663+
goto unlock;
671664
}
672-
665+
crtc = to_intel_crtc(intel_encoder->base.crtc);
666+
pipe = crtc->pipe;
673667
if (pipe == INVALID_PIPE) {
674668
DRM_DEBUG_KMS("no pipe for the port %c\n", port_name(port));
675-
mutex_unlock(&dev_priv->av_mutex);
676-
return -ENODEV;
669+
err = -ENODEV;
670+
goto unlock;
677671
}
672+
678673
DRM_DEBUG_KMS("pipe %c connects port %c\n",
679674
pipe_name(pipe), port_name(port));
680675
mode = &crtc->config->base.adjusted_mode;
@@ -687,8 +682,7 @@ static int i915_audio_component_sync_audio_rate(struct device *dev,
687682
tmp = I915_READ(HSW_AUD_CFG(pipe));
688683
tmp &= ~AUD_CONFIG_N_PROG_ENABLE;
689684
I915_WRITE(HSW_AUD_CFG(pipe), tmp);
690-
mutex_unlock(&dev_priv->av_mutex);
691-
return 0;
685+
goto unlock;
692686
}
693687

694688
n = audio_config_get_n(mode, rate);
@@ -698,45 +692,40 @@ static int i915_audio_component_sync_audio_rate(struct device *dev,
698692
tmp = I915_READ(HSW_AUD_CFG(pipe));
699693
tmp &= ~AUD_CONFIG_N_PROG_ENABLE;
700694
I915_WRITE(HSW_AUD_CFG(pipe), tmp);
701-
mutex_unlock(&dev_priv->av_mutex);
702-
return 0;
695+
goto unlock;
703696
}
704697

705698
/* 3. set the N/CTS/M */
706699
tmp = I915_READ(HSW_AUD_CFG(pipe));
707700
tmp = audio_config_setup_n_reg(n, tmp);
708701
I915_WRITE(HSW_AUD_CFG(pipe), tmp);
709702

703+
unlock:
710704
mutex_unlock(&dev_priv->av_mutex);
711-
return 0;
705+
return err;
712706
}
713707

714708
static int i915_audio_component_get_eld(struct device *dev, int port,
715709
bool *enabled,
716710
unsigned char *buf, int max_bytes)
717711
{
718712
struct drm_i915_private *dev_priv = dev_to_i915(dev);
719-
struct drm_device *drm_dev = dev_priv->dev;
720713
struct intel_encoder *intel_encoder;
721714
struct intel_digital_port *intel_dig_port;
722715
const u8 *eld;
723716
int ret = -EINVAL;
724717

725718
mutex_lock(&dev_priv->av_mutex);
726-
for_each_intel_encoder(drm_dev, intel_encoder) {
727-
if (intel_encoder->type != INTEL_OUTPUT_DISPLAYPORT &&
728-
intel_encoder->type != INTEL_OUTPUT_HDMI)
729-
continue;
719+
intel_encoder = dev_priv->dig_port_map[port];
720+
/* intel_encoder might be NULL for DP MST */
721+
if (intel_encoder) {
722+
ret = 0;
730723
intel_dig_port = enc_to_dig_port(&intel_encoder->base);
731-
if (port == intel_dig_port->port) {
732-
ret = 0;
733-
*enabled = intel_dig_port->audio_connector != NULL;
734-
if (!*enabled)
735-
break;
724+
*enabled = intel_dig_port->audio_connector != NULL;
725+
if (*enabled) {
736726
eld = intel_dig_port->audio_connector->eld;
737727
ret = drm_eld_size(eld);
738728
memcpy(buf, eld, min(max_bytes, ret));
739-
break;
740729
}
741730
}
742731

drivers/gpu/drm/i915/intel_ddi.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3295,6 +3295,7 @@ void intel_ddi_init(struct drm_device *dev, enum port port)
32953295
intel_encoder->get_config = intel_ddi_get_config;
32963296

32973297
intel_dig_port->port = port;
3298+
dev_priv->dig_port_map[port] = intel_encoder;
32983299
intel_dig_port->saved_port_bits = I915_READ(DDI_BUF_CTL(port)) &
32993300
(DDI_BUF_PORT_REVERSAL |
33003301
DDI_A_4_LANES);

drivers/gpu/drm/i915/intel_dp.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6003,6 +6003,7 @@ intel_dp_init(struct drm_device *dev,
60036003
}
60046004

60056005
intel_dig_port->port = port;
6006+
dev_priv->dig_port_map[port] = intel_encoder;
60066007
intel_dig_port->dp.output_reg = output_reg;
60076008

60086009
intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;

drivers/gpu/drm/i915/intel_hdmi.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2148,6 +2148,7 @@ void intel_hdmi_init_connector(struct intel_digital_port *intel_dig_port,
21482148
void intel_hdmi_init(struct drm_device *dev,
21492149
i915_reg_t hdmi_reg, enum port port)
21502150
{
2151+
struct drm_i915_private *dev_priv = dev->dev_private;
21512152
struct intel_digital_port *intel_dig_port;
21522153
struct intel_encoder *intel_encoder;
21532154
struct intel_connector *intel_connector;
@@ -2216,6 +2217,7 @@ void intel_hdmi_init(struct drm_device *dev,
22162217
intel_encoder->cloneable |= 1 << INTEL_OUTPUT_HDMI;
22172218

22182219
intel_dig_port->port = port;
2220+
dev_priv->dig_port_map[port] = intel_encoder;
22192221
intel_dig_port->hdmi.hdmi_reg = hdmi_reg;
22202222
intel_dig_port->dp.output_reg = INVALID_MMIO_REG;
22212223

0 commit comments

Comments
 (0)