Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1709360pxb; Mon, 8 Mar 2021 04:36:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJxSBqI4rcxLF/OgmYfMwuv2dJwNw+fWN1LNncqbhb1ph3Ic3u9uqQZUFzgOMcmzpINbfINU X-Received: by 2002:a17:906:2ad8:: with SMTP id m24mr14974413eje.512.1615206998869; Mon, 08 Mar 2021 04:36:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615206998; cv=none; d=google.com; s=arc-20160816; b=ymjiiDWV/H1yK2iRX8Q414JReigTzOpa7ATAzCViyjnc3q348ZiF8KZyEGQBiOZY6+ wLIRf8F5747tQRo8N8w29y81+k5ACVZpSe9F6TvviIoOpm4gh50IvT/Yutf3qBaho/sF 9jsQpm61Z1zHHBFFwZmNIwtAx3IZSn/58GkimaGdWfUTFah+er1TqFj5IkTWHmS7wHox Wb05akOyX/dIK/fpssFZPuVADPftElUKn+5jUEGmYm7oAqtQluPcG5M70hKEnKujF/NU 1Y/IXbzARNnXCCkh45A02RjzBQp4fvn+fl1sNRmYQGOfxspFjJyWQJ0Euu3qBjA1nK2J C9FQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/J58ZUvhyFtZ8d3MOOz4e9ek7DFkfuR8vNKg7tOmSYg=; b=Dr37efR9xMapgaW/gqhkiKa7iMvuJUT23uOCPkEh7kTJvC7e8HOTZd+IxD0GRqA51y hPiUKATFnID9b+PVvFciUrvdNlhJRptcWmX/nojOTPEBJbmz5WEL5JEAR9U0ljba03Gn wwjfd7jC0hFcVC7AevGq7M2on7PvoEqk6YB4hOsxMp78TG22dOipAX7q6ij3ouTAW1Cd CEWmYWTpnyBTfSeB+RceMDh9mo9Xq0GHIaxBEoE5cHx2E8B4b9Jv67weqZgD3kwETHlb 5kI71ZEaTX7q369Iri58HpzpwsoU5c2ekz31Cx9WXoUioaKr+7XqbyjLtlHkkLfnZYvO Nfhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=T7RPL9ZL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z24si6246978ejx.462.2021.03.08.04.36.15; Mon, 08 Mar 2021 04:36:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=T7RPL9ZL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231995AbhCHMfI (ORCPT + 99 others); Mon, 8 Mar 2021 07:35:08 -0500 Received: from mail.kernel.org ([198.145.29.99]:43450 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229578AbhCHMee (ORCPT ); Mon, 8 Mar 2021 07:34:34 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 28ABB651CF; Mon, 8 Mar 2021 12:34:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615206873; bh=pR5mEFRqToVqr9pTU17jnruAwkAHEAdgulMiemI0xF4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T7RPL9ZLqoX7brXLjvdB+9gO86tJ/Syvlz/1teG4/fYIrbg5SFHyXJiY/JDNcQyJm UFYgwev809zgQa5AKPVue4aqJHQTPaDoQyudGqtYMojo6PdWNJGnZzBkri//9rcAMg NqRsgbe7nOI7ZnhotOlMj1z6WOyEPxFZAUuSeRpY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pierre-Louis Bossart , Guennadi Liakhovetski , Rander Wang , Kai Vehmanen , Takashi Iwai , Sasha Levin Subject: [PATCH 5.10 35/42] ALSA: hda: intel-nhlt: verify config type Date: Mon, 8 Mar 2021 13:31:01 +0100 Message-Id: <20210308122719.836519835@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210308122718.120213856@linuxfoundation.org> References: <20210308122718.120213856@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pierre-Louis Bossart [ Upstream commit a864e8f159b13babf552aff14a5fbe11abc017e4 ] Multiple bug reports report issues with the SOF and SST drivers when dealing with single microphone cases. We currently read the DMIC array information unconditionally but we don't check that the configuration type is actually a mic array. When the DMIC link does not rely on a mic array configuration, the recommendation is to check the format information to infer the maximum number of channels, and map this to the number of microphones. This leaves a potential for a mismatch between actual microphones available in hardware and what the ACPI table contains, but we have no other source of information. Note that single microphone configurations can alternatively be handled with a 'mic array' configuration along with a 'vendor-defined' geometry. Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=201251 BugLink: https://github.com/thesofproject/linux/issues/2725 Fixes: 7a33ea70e1868 ('ALSA: hda: intel-nhlt: handle NHLT VENDOR_DEFINED DMIC geometry') Signed-off-by: Pierre-Louis Bossart Reviewed-by: Guennadi Liakhovetski Reviewed-by: Rander Wang Reviewed-by: Kai Vehmanen Link: https://lore.kernel.org/r/20210302000146.1177770-1-pierre-louis.bossart@linux.intel.com Signed-off-by: Takashi Iwai Signed-off-by: Sasha Levin --- include/sound/intel-nhlt.h | 5 ++++ sound/hda/intel-nhlt.c | 54 +++++++++++++++++++++++++++++++------- 2 files changed, 50 insertions(+), 9 deletions(-) diff --git a/include/sound/intel-nhlt.h b/include/sound/intel-nhlt.h index 743c2f442280..d0574805865f 100644 --- a/include/sound/intel-nhlt.h +++ b/include/sound/intel-nhlt.h @@ -112,6 +112,11 @@ struct nhlt_vendor_dmic_array_config { /* TODO add vendor mic config */ } __packed; +enum { + NHLT_CONFIG_TYPE_GENERIC = 0, + NHLT_CONFIG_TYPE_MIC_ARRAY = 1 +}; + enum { NHLT_MIC_ARRAY_2CH_SMALL = 0xa, NHLT_MIC_ARRAY_2CH_BIG = 0xb, diff --git a/sound/hda/intel-nhlt.c b/sound/hda/intel-nhlt.c index 059aaf04f536..d053beccfaec 100644 --- a/sound/hda/intel-nhlt.c +++ b/sound/hda/intel-nhlt.c @@ -31,18 +31,44 @@ int intel_nhlt_get_dmic_geo(struct device *dev, struct nhlt_acpi_table *nhlt) struct nhlt_endpoint *epnt; struct nhlt_dmic_array_config *cfg; struct nhlt_vendor_dmic_array_config *cfg_vendor; + struct nhlt_fmt *fmt_configs; unsigned int dmic_geo = 0; - u8 j; + u16 max_ch = 0; + u8 i, j; if (!nhlt) return 0; - epnt = (struct nhlt_endpoint *)nhlt->desc; + for (j = 0, epnt = nhlt->desc; j < nhlt->endpoint_count; j++, + epnt = (struct nhlt_endpoint *)((u8 *)epnt + epnt->length)) { - for (j = 0; j < nhlt->endpoint_count; j++) { - if (epnt->linktype == NHLT_LINK_DMIC) { - cfg = (struct nhlt_dmic_array_config *) - (epnt->config.caps); + if (epnt->linktype != NHLT_LINK_DMIC) + continue; + + cfg = (struct nhlt_dmic_array_config *)(epnt->config.caps); + fmt_configs = (struct nhlt_fmt *)(epnt->config.caps + epnt->config.size); + + /* find max number of channels based on format_configuration */ + if (fmt_configs->fmt_count) { + dev_dbg(dev, "%s: found %d format definitions\n", + __func__, fmt_configs->fmt_count); + + for (i = 0; i < fmt_configs->fmt_count; i++) { + struct wav_fmt_ext *fmt_ext; + + fmt_ext = &fmt_configs->fmt_config[i].fmt_ext; + + if (fmt_ext->fmt.channels > max_ch) + max_ch = fmt_ext->fmt.channels; + } + dev_dbg(dev, "%s: max channels found %d\n", __func__, max_ch); + } else { + dev_dbg(dev, "%s: No format information found\n", __func__); + } + + if (cfg->device_config.config_type != NHLT_CONFIG_TYPE_MIC_ARRAY) { + dmic_geo = max_ch; + } else { switch (cfg->array_type) { case NHLT_MIC_ARRAY_2CH_SMALL: case NHLT_MIC_ARRAY_2CH_BIG: @@ -59,13 +85,23 @@ int intel_nhlt_get_dmic_geo(struct device *dev, struct nhlt_acpi_table *nhlt) dmic_geo = cfg_vendor->nb_mics; break; default: - dev_warn(dev, "undefined DMIC array_type 0x%0x\n", - cfg->array_type); + dev_warn(dev, "%s: undefined DMIC array_type 0x%0x\n", + __func__, cfg->array_type); + } + + if (dmic_geo > 0) { + dev_dbg(dev, "%s: Array with %d dmics\n", __func__, dmic_geo); + } + if (max_ch > dmic_geo) { + dev_dbg(dev, "%s: max channels %d exceed dmic number %d\n", + __func__, max_ch, dmic_geo); } } - epnt = (struct nhlt_endpoint *)((u8 *)epnt + epnt->length); } + dev_dbg(dev, "%s: dmic number %d max_ch %d\n", + __func__, dmic_geo, max_ch); + return dmic_geo; } EXPORT_SYMBOL_GPL(intel_nhlt_get_dmic_geo); -- 2.30.1