From patchwork Thu Sep 1 09:09:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Hu X-Patchwork-Id: 1672758 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=fwts-devel-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=KrNwPsku; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MJFc23n3qz1ygc for ; Thu, 1 Sep 2022 19:09:37 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1oTgCY-0000ow-2V; Thu, 01 Sep 2022 09:09:30 +0000 Received: from smtp-relay-canonical-1.internal ([10.131.114.174] helo=smtp-relay-canonical-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1oTgCV-0000ok-Mb for fwts-devel@lists.ubuntu.com; Thu, 01 Sep 2022 09:09:27 +0000 Received: from canonical.com (unknown [175.182.177.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-1.canonical.com (Postfix) with ESMTPSA id AE96C415AA for ; Thu, 1 Sep 2022 09:09:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1662023367; bh=+Y0wV6e0LDsFAmAEnW3qFldjx53AxD1A4wmzA+/MRCc=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=KrNwPskuOtmEJBf9e1C8xpzAMYyB9h67GCquovpMz+mSOJvoYZGNZO3rEZPMTQgDP 01iS6es8XKruMdxBy/82G3MiqLsewS65HowC2tMcDq4t3jkHkiS6vTTi51WQiBEnSz MlsYw/3ohBgVMpcwAPe4H5RkXHNVxRNgrpxxFWMKXuGefCDmIJRMztpdlEpIHXIwqX +F7oYwkhx9B8dtDGYh1E7on2xF2sAgTwO3/D8YD/cM8bHTSppKmUeYuRrjN2MSOJWA +Ij4qd/mQWYL+MNaF5ezVVcIAoAen+UHUsETfNAN1ejJHQZbLaglAHGVzcUBUHTw40 1Vz+nVi1B85Mw== From: Ivan Hu To: fwts-devel@lists.ubuntu.com Subject: [PATCH 1/2] acpi: nhltdump: add dumping nhlt table for audio configurations Date: Thu, 1 Sep 2022 17:09:13 +0800 Message-Id: <20220901090914.9309-1-ivan.hu@canonical.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: fwts-devel-bounces@lists.ubuntu.com Sender: "fwts-devel" Refer to Intel Smart Sound Technology NHLT Specification https://01.org/sites/default/files/595976_intel_sst_nhlt.pdf Signed-off-by: Ivan Hu --- src/Makefile.am | 1 + src/acpi/nhltdump/nhltdump.c | 146 +++++++++++++++++++++++++++++++++++ src/lib/include/fwts_acpi.h | 50 ++++++++++++ 3 files changed, 197 insertions(+) create mode 100644 src/acpi/nhltdump/nhltdump.c diff --git a/src/Makefile.am b/src/Makefile.am index a8c60b79..a3e09cad 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -115,6 +115,7 @@ fwts_SOURCES = main.c \ acpi/msdm/msdm.c \ acpi/method/method.c \ acpi/nfit/nfit.c \ + acpi/nhltdump/nhltdump.c \ acpi/osilinux/osilinux.c \ acpi/pcc/pcc.c \ acpi/pcct/pcct.c \ diff --git a/src/acpi/nhltdump/nhltdump.c b/src/acpi/nhltdump/nhltdump.c new file mode 100644 index 00000000..0869acf9 --- /dev/null +++ b/src/acpi/nhltdump/nhltdump.c @@ -0,0 +1,146 @@ +/* + * Copyright (C) 2022 Canonical + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +#include "fwts.h" + +#if defined(FWTS_HAS_ACPI) + +#include +#include +#include +#include +#include + +static fwts_acpi_table_info *table; +acpi_table_init(NHLT, &table) + +static void nhltdump_data_hexdump(fwts_framework *fw, uint8_t *data, size_t size) +{ + size_t i; + + for (i = 0; i < size; i += 16) { + char buffer[128]; + size_t left = size - i; + + fwts_dump_raw_data(buffer, sizeof(buffer), data + i, i, left > 16 ? 16 : left); + fwts_log_info_verbatim(fw, " %s", buffer + 2); + } +} + +/* + * NHLT Table + * see https://01.org/sites/default/files/595976_intel_sst_nhlt.pdf + */ +static int nhltdump_test1(fwts_framework *fw) +{ + fwts_acpi_table_nhlt *nhlt = (fwts_acpi_table_nhlt *)table->data; + uint32_t i, j; + fwts_acpi_table_nhlt_ep_descriptor *ep_descriptor = (fwts_acpi_table_nhlt_ep_descriptor *) + ((uint8_t *)table->data + sizeof(fwts_acpi_table_nhlt)); + fwts_acpi_table_nhlt_specific_config *spec_config = NULL; + fwts_acpi_table_nhlt_formats_configuration *formats_conf = NULL; + fwts_acpi_table_nhlt_format_configuration *format_conf = NULL; + char guid_str[37]; + uint32_t table_length = table->length; + uint32_t offset = 0; + + fwts_log_info_simp_int(fw, "TableLength: ", table_length); + offset += sizeof(fwts_acpi_table_nhlt); + if (offset > table_length) { + fwts_log_info_verbatim(fw, "Table too short, skip dumping remaining data."); + return FWTS_OK; + } + fwts_log_info_verbatim(fw, "NHLT Table:"); + fwts_log_info_verbatim(fw, " EndpointDescriptorCount: %" PRIu8, nhlt->ep_descriptor_count); + + for (i = 0; i < nhlt->ep_descriptor_count; i++) { + offset += ep_descriptor->ep_descriptor_len; + if (offset > table_length) { + fwts_log_info_verbatim(fw, "Table too short, skip dumping remaining data."); + return FWTS_OK; + } + fwts_log_info_verbatim(fw, " EndpointDescriptor %" PRIu8, (i + 1)); + fwts_log_info_simp_int(fw, " EndpointDescriptorLength: ", ep_descriptor->ep_descriptor_len); + fwts_log_info_simp_int(fw, " LinkType: ", ep_descriptor->link_type); + fwts_log_info_simp_int(fw, " Instance ID: ", ep_descriptor->instance_id); + fwts_log_info_simp_int(fw, " Vendor ID: ", ep_descriptor->vendor_id); + fwts_log_info_simp_int(fw, " Device ID: ", ep_descriptor->device_id); + fwts_log_info_simp_int(fw, " Revision ID: ", ep_descriptor->revision_id); + fwts_log_info_simp_int(fw, " Subsystem ID: ", ep_descriptor->subsystem_id); + fwts_log_info_simp_int(fw, " Device Type: ", ep_descriptor->device_type); + fwts_log_info_simp_int(fw, " Direction: ", ep_descriptor->direction); + fwts_log_info_simp_int(fw, " Virtual Bus ID: ", ep_descriptor->virtual_bus_id); + + spec_config = (fwts_acpi_table_nhlt_specific_config *)((uint8_t *)ep_descriptor + + sizeof(fwts_acpi_table_nhlt_ep_descriptor)); + fwts_log_info_verbatim(fw, " EndpointConfig"); + fwts_log_info_simp_int(fw, " CapabilitiesSize: ", spec_config->capabilities_size); + fwts_log_info_verbatim(fw, " Capabilities:"); + nhltdump_data_hexdump(fw, spec_config->capabilities, spec_config->capabilities_size); + + fwts_log_info_verbatim(fw, " FormatsConfig"); + formats_conf = (fwts_acpi_table_nhlt_formats_configuration *)((uint8_t *)spec_config + + sizeof(spec_config->capabilities_size) + spec_config->capabilities_size); + + fwts_log_info_verbatim(fw, " FormatsCount %" PRIu8, formats_conf->formatscount); + format_conf = formats_conf->formatsconfiguration; + for (j = 0; j < formats_conf->formatscount; j++) { + fwts_log_info_verbatim(fw, " FormatConfig %" PRIu8, (j + 1)); + fwts_log_info_simp_int(fw, " wFormatTag: ", format_conf->format.wformattag); + fwts_log_info_simp_int(fw, " nChannels: ", format_conf->format.nchannels); + fwts_log_info_simp_int(fw, " nSamplesPerSec: ", format_conf->format.nsamplespersec); + fwts_log_info_simp_int(fw, " nAvgBytesPerSec: ", format_conf->format.navgbytespersec); + fwts_log_info_simp_int(fw, " nBlockAlign: ", format_conf->format.nblockalign); + fwts_log_info_simp_int(fw, " wBitsPerSample: ", format_conf->format.wbitspersample); + fwts_log_info_simp_int(fw, " cbSize: ", format_conf->format.cbsize); + fwts_log_info_simp_int(fw, " wValidBitsPerSample: ", format_conf->format.wvalidbitspersample); + fwts_log_info_simp_int(fw, " dwChannelMask: ", format_conf->format.dwchannelmask); + fwts_guid_buf_to_str(format_conf->format.subformat, guid_str, sizeof(guid_str)); + fwts_log_info_verbatim(fw, " SubFormat: %s", guid_str); + + fwts_log_info_verbatim(fw, " SpecificConfig"); + fwts_log_info_simp_int(fw, " CapabilitiesSize: ", format_conf->formatconfiguration.capabilities_size); + fwts_log_info_verbatim(fw, " Capabilities:"); + nhltdump_data_hexdump(fw, format_conf->formatconfiguration.capabilities, + format_conf->formatconfiguration.capabilities_size); + format_conf = (fwts_acpi_table_nhlt_format_configuration *) + ((uint8_t *)format_conf->formatconfiguration.capabilities + + format_conf->formatconfiguration.capabilities_size); + } + ep_descriptor = (fwts_acpi_table_nhlt_ep_descriptor *)((uint8_t *)ep_descriptor + ep_descriptor->ep_descriptor_len); + } + + /* TODO: dumping the OEDConfig, currently the specification not clear defined the remaining data */ + + return FWTS_OK; +} + +static fwts_framework_minor_test nhltdump_tests[] = { + { nhltdump_test1, "Dump non-HD Audio endpoints configuration performed via ACPI(NHLT)." }, + { NULL, NULL } +}; + +static fwts_framework_ops nhltdump_ops = { + .description = "Dump configurations performed via NHLT.", + .init = NHLT_init, + .minor_tests = nhltdump_tests +}; + +FWTS_REGISTER("nhltdump", &nhltdump_ops, FWTS_TEST_ANYTIME, FWTS_FLAG_UTILS) + +#endif diff --git a/src/lib/include/fwts_acpi.h b/src/lib/include/fwts_acpi.h index 8381c351..ad50e30b 100644 --- a/src/lib/include/fwts_acpi.h +++ b/src/lib/include/fwts_acpi.h @@ -2219,4 +2219,54 @@ typedef struct { uint32_t amrt_addr_end; } __attribute__ ((packed)) fwts_acpi_table_aspt; +/* + * NHLT Table + * see https://01.org/sites/default/files/595976_intel_sst_nhlt.pdf +*/ +typedef struct { + fwts_acpi_table_header header; + uint8_t ep_descriptor_count; +} __attribute__ ((packed)) fwts_acpi_table_nhlt; + +typedef struct { + uint32_t ep_descriptor_len; + uint8_t link_type; + uint8_t instance_id; + uint16_t vendor_id; + uint16_t device_id; + uint16_t revision_id; + uint32_t subsystem_id; + uint8_t device_type; + uint8_t direction; + uint8_t virtual_bus_id; +}__attribute__ ((packed)) fwts_acpi_table_nhlt_ep_descriptor; + +typedef struct { + uint32_t capabilities_size; + uint8_t capabilities[0]; +} __attribute__ ((packed)) fwts_acpi_table_nhlt_specific_config; + +typedef struct { + uint16_t wformattag; + uint16_t nchannels; + uint32_t nsamplespersec; + uint32_t navgbytespersec; + uint16_t nblockalign; + uint16_t wbitspersample; + uint16_t cbsize; + uint16_t wvalidbitspersample; + uint32_t dwchannelmask; + uint8_t subformat[16]; +} __attribute__ ((packed)) fwts_acpi_table_nhlt_waveformatextensible; + +typedef struct { + fwts_acpi_table_nhlt_waveformatextensible format; + fwts_acpi_table_nhlt_specific_config formatconfiguration; +} __attribute__ ((packed)) fwts_acpi_table_nhlt_format_configuration; + +typedef struct { + uint8_t formatscount; + fwts_acpi_table_nhlt_format_configuration formatsconfiguration[0]; +} __attribute__ ((packed)) fwts_acpi_table_nhlt_formats_configuration; + #endif From patchwork Thu Sep 1 09:09:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Hu X-Patchwork-Id: 1672759 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=fwts-devel-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=SdqJEYHM; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MJFc23tTGz1yn9 for ; Thu, 1 Sep 2022 19:09:37 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1oTgCb-0000pZ-5n; Thu, 01 Sep 2022 09:09:33 +0000 Received: from smtp-relay-canonical-0.internal ([10.131.114.83] helo=smtp-relay-canonical-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1oTgCZ-0000pC-Hf for fwts-devel@lists.ubuntu.com; Thu, 01 Sep 2022 09:09:31 +0000 Received: from canonical.com (unknown [175.182.177.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-0.canonical.com (Postfix) with ESMTPSA id 90B484094A for ; Thu, 1 Sep 2022 09:09:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1662023371; bh=lg7B6s0R0x905kvOcILwwxb8/RfSBbqbYK86tilRf+c=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SdqJEYHMhOXND7gMqSrdnZhBqg13wYcoyALQ7RoPqt1f9i+gEgnjvC0AF9Zs73VQ+ 3GEc0F4EOVmiYT26t35PH1F5UVmZQpBlTP/C+rnPlOyvKtSDLR/dwIvWFTyM0RGy7z v41nF01pf/T/m63UsnIAqRVzWqmCYJ8qWF90QNM+7gh7DNZvO7j92OGTSq/+VRh9HS TcsUmVuQhbsVqdIyvMGT2H3e3cITok2OlXsNhq3YiWLBYxCaElgnxvsrlyVk87VmUH K3b8nktTsTL0cERuQgbwNDSTtEl1+d07pJqQ+pmAQmN+11DxNtfupiGbWl/aL167WZ 25iagI1+8tbfw== From: Ivan Hu To: fwts-devel@lists.ubuntu.com Subject: [PATCH 2/2] acpi: nhltdump: add endpoint discriptor string description Date: Thu, 1 Sep 2022 17:09:14 +0800 Message-Id: <20220901090914.9309-2-ivan.hu@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220901090914.9309-1-ivan.hu@canonical.com> References: <20220901090914.9309-1-ivan.hu@canonical.com> MIME-Version: 1.0 X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: fwts-devel-bounces@lists.ubuntu.com Sender: "fwts-devel" Signed-off-by: Ivan Hu --- src/acpi/nhltdump/nhltdump.c | 106 ++++++++++++++++++++++++++++++++++- 1 file changed, 103 insertions(+), 3 deletions(-) diff --git a/src/acpi/nhltdump/nhltdump.c b/src/acpi/nhltdump/nhltdump.c index 0869acf9..90837154 100644 --- a/src/acpi/nhltdump/nhltdump.c +++ b/src/acpi/nhltdump/nhltdump.c @@ -42,6 +42,102 @@ static void nhltdump_data_hexdump(fwts_framework *fw, uint8_t *data, size_t size } } +static char *nhltdump_linktype_to_string(const uint8_t linktype) +{ + char *str; + + switch (linktype) { + case 0: + str = "HD-Audio"; + break; + case 1: + str = "DSP "; + break; + case 2: + str = "PDM"; + break; + case 3: + str = "SSP"; + break; + case 4: + str = "Slimbus"; + break; + case 5: + str = "SoundWire"; + break; + default: + str = "reserved"; + break; + } + + return str; +} + +static char *nhltdump_devtype_to_string(const uint8_t linktype, const uint8_t devtype) +{ + char *str; + + if (linktype == 2) { + switch (devtype) { + case 0: + str = "PDM on cAVS1.8 (CNL+) platforms only"; + break; + case 1: + str = "PDM on cAVS1.5 (KBL) based platforms"; + break; + default: + str = "reserved"; + break; + } + } else if (linktype == 3) { + switch (devtype) { + case 0: + str = "BT Sideband"; + break; + case 1: + str = "FM"; + break; + case 2: + str = "Modem"; + break; + case 4: + str = "SSP Analog Codec"; + break; + default: + str = "reserved"; + break; + } + } else + str = "TBD"; + + return str; +} + +static char *nhltdump_direction_to_string(const uint8_t direction) +{ + char *str; + + switch (direction) { + case 0: + str = "Render"; + break; + case 1: + str = "Capture"; + break; + case 2: + str = "Render with loopback / feedback"; + break; + case 3: + str = "Feedback for render (smartamp)"; + break; + default: + str = ""; + break; + } + + return str; +} + /* * NHLT Table * see https://01.org/sites/default/files/595976_intel_sst_nhlt.pdf @@ -58,6 +154,7 @@ static int nhltdump_test1(fwts_framework *fw) char guid_str[37]; uint32_t table_length = table->length; uint32_t offset = 0; + char *str_info; fwts_log_info_simp_int(fw, "TableLength: ", table_length); offset += sizeof(fwts_acpi_table_nhlt); @@ -76,14 +173,17 @@ static int nhltdump_test1(fwts_framework *fw) } fwts_log_info_verbatim(fw, " EndpointDescriptor %" PRIu8, (i + 1)); fwts_log_info_simp_int(fw, " EndpointDescriptorLength: ", ep_descriptor->ep_descriptor_len); - fwts_log_info_simp_int(fw, " LinkType: ", ep_descriptor->link_type); + str_info = nhltdump_linktype_to_string(ep_descriptor->link_type); + fwts_log_info_verbatim(fw, " LinkType: %" PRIu8 " (%s)", ep_descriptor->link_type, str_info); fwts_log_info_simp_int(fw, " Instance ID: ", ep_descriptor->instance_id); fwts_log_info_simp_int(fw, " Vendor ID: ", ep_descriptor->vendor_id); fwts_log_info_simp_int(fw, " Device ID: ", ep_descriptor->device_id); fwts_log_info_simp_int(fw, " Revision ID: ", ep_descriptor->revision_id); fwts_log_info_simp_int(fw, " Subsystem ID: ", ep_descriptor->subsystem_id); - fwts_log_info_simp_int(fw, " Device Type: ", ep_descriptor->device_type); - fwts_log_info_simp_int(fw, " Direction: ", ep_descriptor->direction); + str_info = nhltdump_devtype_to_string(ep_descriptor->link_type, ep_descriptor->device_type); + fwts_log_info_verbatim(fw, " Device Type: %" PRIu8 " (%s)", ep_descriptor->device_type, str_info); + str_info = nhltdump_direction_to_string(ep_descriptor->direction); + fwts_log_info_verbatim(fw, " Direction: %" PRIu8 " (%s)", ep_descriptor->direction, str_info); fwts_log_info_simp_int(fw, " Virtual Bus ID: ", ep_descriptor->virtual_bus_id); spec_config = (fwts_acpi_table_nhlt_specific_config *)((uint8_t *)ep_descriptor