Skip to content

Commit

Permalink
ALSA: x86: Avoid register accesses during disconnection
Browse files Browse the repository at this point in the history
It seems that accessing registers during disconnection often leads to
the GPU pipe error.  The original driver had a similar check in the
past, but it was lost through refactoring.  Now put a connection check
in the register access functions.

One exception is the irq handler: it still needs to access the raw
register even while disconnected, because it has to read and write to
ACK the irq mask.  Although the irq shouldn't be raised while
disconnected (the stream should have been disabled), let's make it
safer for now.

Signed-off-by: Takashi Iwai <[email protected]>
  • Loading branch information
tiwai committed Feb 16, 2017
1 parent a72ccfb commit 28ed125
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions sound/x86/intel_hdmi_audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,28 @@ static void had_substream_put(struct snd_intelhad *intelhaddata)
}

/* Register access functions */
static u32 had_read_register_raw(struct snd_intelhad *ctx, u32 reg)
{
return ioread32(ctx->mmio_start + ctx->had_config_offset + reg);
}

static void had_write_register_raw(struct snd_intelhad *ctx, u32 reg, u32 val)
{
iowrite32(val, ctx->mmio_start + ctx->had_config_offset + reg);
}

static void had_read_register(struct snd_intelhad *ctx, u32 reg, u32 *val)
{
*val = ioread32(ctx->mmio_start + ctx->had_config_offset + reg);
if (!ctx->connected)
*val = 0;
else
*val = had_read_register_raw(ctx, reg);
}

static void had_write_register(struct snd_intelhad *ctx, u32 reg, u32 val)
{
iowrite32(val, ctx->mmio_start + ctx->had_config_offset + reg);
if (ctx->connected)
had_write_register_raw(ctx, reg, val);
}

/*
Expand Down Expand Up @@ -229,6 +243,8 @@ static void had_ack_irqs(struct snd_intelhad *ctx)
{
u32 status_reg;

if (!ctx->connected)
return;
had_read_register(ctx, AUD_HDMI_STATUS, &status_reg);
status_reg |= HDMI_AUDIO_BUFFER_DONE | HDMI_AUDIO_UNDERRUN;
had_write_register(ctx, AUD_HDMI_STATUS, status_reg);
Expand Down Expand Up @@ -998,7 +1014,7 @@ static void wait_clear_underrun_bit(struct snd_intelhad *intelhaddata)
*/
static void had_do_reset(struct snd_intelhad *intelhaddata)
{
if (!intelhaddata->need_reset)
if (!intelhaddata->need_reset || !intelhaddata->connected)
return;

/* Reset buffer pointers */
Expand Down Expand Up @@ -1526,18 +1542,20 @@ static const struct snd_kcontrol_new had_controls[] = {
static irqreturn_t display_pipe_interrupt_handler(int irq, void *dev_id)
{
struct snd_intelhad *ctx = dev_id;
u32 audio_stat, audio_reg;
u32 audio_stat;

audio_reg = AUD_HDMI_STATUS;
had_read_register(ctx, audio_reg, &audio_stat);
/* use raw register access to ack IRQs even while disconnected */
audio_stat = had_read_register_raw(ctx, AUD_HDMI_STATUS);

if (audio_stat & HDMI_AUDIO_UNDERRUN) {
had_write_register(ctx, audio_reg, HDMI_AUDIO_UNDERRUN);
had_write_register_raw(ctx, AUD_HDMI_STATUS,
HDMI_AUDIO_UNDERRUN);
had_process_buffer_underrun(ctx);
}

if (audio_stat & HDMI_AUDIO_BUFFER_DONE) {
had_write_register(ctx, audio_reg, HDMI_AUDIO_BUFFER_DONE);
had_write_register_raw(ctx, AUD_HDMI_STATUS,
HDMI_AUDIO_BUFFER_DONE);
had_process_buffer_done(ctx);
}

Expand Down

0 comments on commit 28ed125

Please sign in to comment.