From patchwork Thu May 18 18:33:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 13247247 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78FC7C77B7D for ; Thu, 18 May 2023 18:33:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229957AbjERSdU (ORCPT ); Thu, 18 May 2023 14:33:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229436AbjERSdT (ORCPT ); Thu, 18 May 2023 14:33:19 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5ED7BE5E; Thu, 18 May 2023 11:33:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1684434784; x=1715970784; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ym1vv7zPqo8/CdI9upk2Hh8lxDICoH9AjB/IR2QKk64=; b=hR51GZnr5/U0wTdihfHFxZx9fnwfGT2aO8NAFVAxYCQB2nRqyvaEdqkg qeVQQIZcfFW/x8d2zniWkjbVGWPauxJlnWdFdmEPURmSiMvrJyC5x5p7Y VBr46txtVHHgl2LTA6Klb900XvybE0qyAEcF/vBUg1+wB+akDv1b9VC/N Geya9zvpMuhpbolYsJ/+3xG+yn4gljBCAwmChBvn++f+BvossicSoyR4S 1wcNSeVol9JoSH1/0ZlicmTDs5K4m5BkUhjc4JehcalYe1/KfXCD03dXf IaicKAhHjtFjvFJBCytAEzTRU2SNV1MV7hqMoqRryuwUr8Bg2C76Bmgcr Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10714"; a="341588700" X-IronPort-AV: E=Sophos;i="6.00,174,1681196400"; d="scan'208";a="341588700" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 May 2023 11:33:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10714"; a="814420260" X-IronPort-AV: E=Sophos;i="6.00,174,1681196400"; d="scan'208";a="814420260" Received: from djiang5-mobl3.amr.corp.intel.com (HELO [192.168.1.177]) ([10.212.16.136]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 May 2023 11:33:02 -0700 Subject: [PATCH v2 1/4] acpi: Move common tables helper functions to common lib From: Dave Jiang To: linux-acpi@vger.kernel.org, linux-cxl@vger.kernel.org Cc: rafael@kernel.org, lenb@kernel.org, dan.j.williams@intel.com, ira.weiny@intel.com, vishal.l.verma@intel.com, alison.schofield@intel.com, lukas@wunner.de, Jonathan.Cameron@huawei.com Date: Thu, 18 May 2023 11:33:02 -0700 Message-ID: <168443478260.2966470.6881416930240756285.stgit@djiang5-mobl3> In-Reply-To: <168443445827.2966470.16511867875780059322.stgit@djiang5-mobl3> References: <168443445827.2966470.16511867875780059322.stgit@djiang5-mobl3> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org Some of the routines in ACPI tables.c can be shared with parsing CDAT. However, CDAT is used by CXL and can exist on platforms that do not use ACPI. Split out the common routine from ACPI to accomodate platforms that do not support ACPI. The common routines can be built outside of ACPI if ACPI_TABLES_LIB is selected. Signed-off-by: Dave Jiang --- drivers/Makefile | 2 drivers/acpi/Kconfig | 4 + drivers/acpi/Makefile | 3 + drivers/acpi/tables.c | 173 ---------------------------------------- drivers/acpi/tables_lib.c | 194 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/acpi.h | 63 +++++++++------ 6 files changed, 241 insertions(+), 198 deletions(-) create mode 100644 drivers/acpi/tables_lib.c diff --git a/drivers/Makefile b/drivers/Makefile index 20b118dca999..1824797f7dfe 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -31,7 +31,7 @@ obj-y += idle/ # IPMI must come before ACPI in order to provide IPMI opregion support obj-y += char/ipmi/ -obj-$(CONFIG_ACPI) += acpi/ +obj-y += acpi/ # PnP must come after ACPI since it will eventually need to check if acpi # was used and do nothing if so diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig index ccbeab9500ec..ce74a20dc42f 100644 --- a/drivers/acpi/Kconfig +++ b/drivers/acpi/Kconfig @@ -6,12 +6,16 @@ config ARCH_SUPPORTS_ACPI bool +config ACPI_TABLES_LIB + bool + menuconfig ACPI bool "ACPI (Advanced Configuration and Power Interface) Support" depends on ARCH_SUPPORTS_ACPI select PNP select NLS select CRC32 + select ACPI_TABLES_LIB default y if X86 help Advanced Configuration and Power Interface (ACPI) support for diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile index feb36c0b9446..4558e2876823 100644 --- a/drivers/acpi/Makefile +++ b/drivers/acpi/Makefile @@ -13,6 +13,9 @@ tables.o: $(src)/../../include/$(CONFIG_ACPI_CUSTOM_DSDT_FILE) ; endif +obj-$(CONFIG_ACPI_TABLES_LIB) += acpi_tables_lib.o +acpi_tables_lib-y := tables_lib.o + obj-$(CONFIG_ACPI) += tables.o obj-$(CONFIG_X86) += blacklist.o diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c index 7b4680da57d7..cfc76efd8788 100644 --- a/drivers/acpi/tables.c +++ b/drivers/acpi/tables.c @@ -37,18 +37,6 @@ static struct acpi_table_desc initial_tables[ACPI_MAX_TABLES] __initdata; static int acpi_apic_instance __initdata_or_acpilib; -enum acpi_subtable_type { - ACPI_SUBTABLE_COMMON, - ACPI_SUBTABLE_HMAT, - ACPI_SUBTABLE_PRMT, - ACPI_SUBTABLE_CEDT, -}; - -struct acpi_subtable_entry { - union acpi_subtable_headers *hdr; - enum acpi_subtable_type type; -}; - /* * Disable table checksum verification for the early stage due to the size * limitation of the current x86 early mapping implementation. @@ -227,167 +215,6 @@ void acpi_table_print_madt_entry(struct acpi_subtable_header *header) } } -static unsigned long __init_or_acpilib -acpi_get_entry_type(struct acpi_subtable_entry *entry) -{ - switch (entry->type) { - case ACPI_SUBTABLE_COMMON: - return entry->hdr->common.type; - case ACPI_SUBTABLE_HMAT: - return entry->hdr->hmat.type; - case ACPI_SUBTABLE_PRMT: - return 0; - case ACPI_SUBTABLE_CEDT: - return entry->hdr->cedt.type; - } - return 0; -} - -static unsigned long __init_or_acpilib -acpi_get_entry_length(struct acpi_subtable_entry *entry) -{ - switch (entry->type) { - case ACPI_SUBTABLE_COMMON: - return entry->hdr->common.length; - case ACPI_SUBTABLE_HMAT: - return entry->hdr->hmat.length; - case ACPI_SUBTABLE_PRMT: - return entry->hdr->prmt.length; - case ACPI_SUBTABLE_CEDT: - return entry->hdr->cedt.length; - } - return 0; -} - -static unsigned long __init_or_acpilib -acpi_get_subtable_header_length(struct acpi_subtable_entry *entry) -{ - switch (entry->type) { - case ACPI_SUBTABLE_COMMON: - return sizeof(entry->hdr->common); - case ACPI_SUBTABLE_HMAT: - return sizeof(entry->hdr->hmat); - case ACPI_SUBTABLE_PRMT: - return sizeof(entry->hdr->prmt); - case ACPI_SUBTABLE_CEDT: - return sizeof(entry->hdr->cedt); - } - return 0; -} - -static enum acpi_subtable_type __init_or_acpilib -acpi_get_subtable_type(char *id) -{ - if (strncmp(id, ACPI_SIG_HMAT, 4) == 0) - return ACPI_SUBTABLE_HMAT; - if (strncmp(id, ACPI_SIG_PRMT, 4) == 0) - return ACPI_SUBTABLE_PRMT; - if (strncmp(id, ACPI_SIG_CEDT, 4) == 0) - return ACPI_SUBTABLE_CEDT; - return ACPI_SUBTABLE_COMMON; -} - -static __init_or_acpilib bool has_handler(struct acpi_subtable_proc *proc) -{ - return proc->handler || proc->handler_arg; -} - -static __init_or_acpilib int call_handler(struct acpi_subtable_proc *proc, - union acpi_subtable_headers *hdr, - unsigned long end) -{ - if (proc->handler) - return proc->handler(hdr, end); - if (proc->handler_arg) - return proc->handler_arg(hdr, proc->arg, end); - return -EINVAL; -} - -/** - * acpi_parse_entries_array - for each proc_num find a suitable subtable - * - * @id: table id (for debugging purposes) - * @table_size: size of the root table - * @table_header: where does the table start? - * @proc: array of acpi_subtable_proc struct containing entry id - * and associated handler with it - * @proc_num: how big proc is? - * @max_entries: how many entries can we process? - * - * For each proc_num find a subtable with proc->id and run proc->handler - * on it. Assumption is that there's only single handler for particular - * entry id. - * - * The table_size is not the size of the complete ACPI table (the length - * field in the header struct), but only the size of the root table; i.e., - * the offset from the very first byte of the complete ACPI table, to the - * first byte of the very first subtable. - * - * On success returns sum of all matching entries for all proc handlers. - * Otherwise, -ENODEV or -EINVAL is returned. - */ -static int __init_or_acpilib acpi_parse_entries_array( - char *id, unsigned long table_size, - struct acpi_table_header *table_header, struct acpi_subtable_proc *proc, - int proc_num, unsigned int max_entries) -{ - struct acpi_subtable_entry entry; - unsigned long table_end, subtable_len, entry_len; - int count = 0; - int errs = 0; - int i; - - table_end = (unsigned long)table_header + table_header->length; - - /* Parse all entries looking for a match. */ - - entry.type = acpi_get_subtable_type(id); - entry.hdr = (union acpi_subtable_headers *) - ((unsigned long)table_header + table_size); - subtable_len = acpi_get_subtable_header_length(&entry); - - while (((unsigned long)entry.hdr) + subtable_len < table_end) { - if (max_entries && count >= max_entries) - break; - - for (i = 0; i < proc_num; i++) { - if (acpi_get_entry_type(&entry) != proc[i].id) - continue; - if (!has_handler(&proc[i]) || - (!errs && - call_handler(&proc[i], entry.hdr, table_end))) { - errs++; - continue; - } - - proc[i].count++; - break; - } - if (i != proc_num) - count++; - - /* - * If entry->length is 0, break from this loop to avoid - * infinite loop. - */ - entry_len = acpi_get_entry_length(&entry); - if (entry_len == 0) { - pr_err("[%4.4s:0x%02x] Invalid zero length\n", id, proc->id); - return -EINVAL; - } - - entry.hdr = (union acpi_subtable_headers *) - ((unsigned long)entry.hdr + entry_len); - } - - if (max_entries && count > max_entries) { - pr_warn("[%4.4s:0x%02x] found the maximum %i entries\n", - id, proc->id, count); - } - - return errs ? -EINVAL : count; -} - int __init_or_acpilib acpi_table_parse_entries_array( char *id, unsigned long table_size, struct acpi_subtable_proc *proc, int proc_num, unsigned int max_entries) diff --git a/drivers/acpi/tables_lib.c b/drivers/acpi/tables_lib.c new file mode 100644 index 000000000000..701001610fa9 --- /dev/null +++ b/drivers/acpi/tables_lib.c @@ -0,0 +1,194 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * acpi_tables.c - ACPI Boot-Time Table Parsing + * + * Copyright (C) 2001 Paul Diefenbaugh + */ + +/* Uncomment next line to get verbose printout */ +/* #define DEBUG */ +#define pr_fmt(fmt) "ACPI: " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +enum acpi_subtable_type { + ACPI_SUBTABLE_COMMON, + ACPI_SUBTABLE_HMAT, + ACPI_SUBTABLE_PRMT, + ACPI_SUBTABLE_CEDT, +}; + +struct acpi_subtable_entry { + union acpi_subtable_headers *hdr; + enum acpi_subtable_type type; +}; + +static unsigned long acpi_get_entry_type(struct acpi_subtable_entry *entry) +{ + switch (entry->type) { + case ACPI_SUBTABLE_COMMON: + return entry->hdr->common.type; + case ACPI_SUBTABLE_HMAT: + return entry->hdr->hmat.type; + case ACPI_SUBTABLE_PRMT: + return 0; + case ACPI_SUBTABLE_CEDT: + return entry->hdr->cedt.type; + } + return 0; +} + +static unsigned long acpi_get_entry_length(struct acpi_subtable_entry *entry) +{ + switch (entry->type) { + case ACPI_SUBTABLE_COMMON: + return entry->hdr->common.length; + case ACPI_SUBTABLE_HMAT: + return entry->hdr->hmat.length; + case ACPI_SUBTABLE_PRMT: + return entry->hdr->prmt.length; + case ACPI_SUBTABLE_CEDT: + return entry->hdr->cedt.length; + } + return 0; +} + +static unsigned long +acpi_get_subtable_header_length(struct acpi_subtable_entry *entry) +{ + switch (entry->type) { + case ACPI_SUBTABLE_COMMON: + return sizeof(entry->hdr->common); + case ACPI_SUBTABLE_HMAT: + return sizeof(entry->hdr->hmat); + case ACPI_SUBTABLE_PRMT: + return sizeof(entry->hdr->prmt); + case ACPI_SUBTABLE_CEDT: + return sizeof(entry->hdr->cedt); + } + return 0; +} + +static enum acpi_subtable_type acpi_get_subtable_type(char *id) +{ + if (strncmp(id, ACPI_SIG_HMAT, 4) == 0) + return ACPI_SUBTABLE_HMAT; + if (strncmp(id, ACPI_SIG_PRMT, 4) == 0) + return ACPI_SUBTABLE_PRMT; + if (strncmp(id, ACPI_SIG_CEDT, 4) == 0) + return ACPI_SUBTABLE_CEDT; + return ACPI_SUBTABLE_COMMON; +} + +static bool has_handler(struct acpi_subtable_proc *proc) +{ + return proc->handler || proc->handler_arg; +} + +static int call_handler(struct acpi_subtable_proc *proc, + union acpi_subtable_headers *hdr, unsigned long end) +{ + if (proc->handler) + return proc->handler(hdr, end); + if (proc->handler_arg) + return proc->handler_arg(hdr, proc->arg, end); + return -EINVAL; +} + +/** + * acpi_parse_entries_array - for each proc_num find a suitable subtable + * + * @id: table id (for debugging purposes) + * @table_size: size of the root table + * @table_header: where does the table start? + * @proc: array of acpi_subtable_proc struct containing entry id + * and associated handler with it + * @proc_num: how big proc is? + * @max_entries: how many entries can we process? + * + * For each proc_num find a subtable with proc->id and run proc->handler + * on it. Assumption is that there's only single handler for particular + * entry id. + * + * The table_size is not the size of the complete ACPI table (the length + * field in the header struct), but only the size of the root table; i.e., + * the offset from the very first byte of the complete ACPI table, to the + * first byte of the very first subtable. + * + * On success returns sum of all matching entries for all proc handlers. + * Otherwise, -ENODEV or -EINVAL is returned. + */ +int acpi_parse_entries_array(char *id, unsigned long table_size, + struct acpi_table_header *table_header, + struct acpi_subtable_proc *proc, + int proc_num, unsigned int max_entries) +{ + struct acpi_subtable_entry entry; + unsigned long table_end, subtable_len, entry_len; + int count = 0; + int errs = 0; + int i; + + table_end = (unsigned long)table_header + table_header->length; + + /* Parse all entries looking for a match. */ + + entry.type = acpi_get_subtable_type(id); + entry.hdr = (union acpi_subtable_headers *) + ((unsigned long)table_header + table_size); + subtable_len = acpi_get_subtable_header_length(&entry); + + while (((unsigned long)entry.hdr) + subtable_len < table_end) { + if (max_entries && count >= max_entries) + break; + + for (i = 0; i < proc_num; i++) { + if (acpi_get_entry_type(&entry) != proc[i].id) + continue; + if (!has_handler(&proc[i]) || + (!errs && + call_handler(&proc[i], entry.hdr, table_end))) { + errs++; + continue; + } + + proc[i].count++; + break; + } + if (i != proc_num) + count++; + + /* + * If entry->length is 0, break from this loop to avoid + * infinite loop. + */ + entry_len = acpi_get_entry_length(&entry); + if (entry_len == 0) { + pr_err("[%4.4s:0x%02x] Invalid zero length\n", id, proc->id); + return -EINVAL; + } + + entry.hdr = (union acpi_subtable_headers *) + ((unsigned long)entry.hdr + entry_len); + } + + if (max_entries && count > max_entries) { + pr_warn("[%4.4s:0x%02x] found the maximum %i entries\n", + id, proc->id, count); + } + + return errs ? -EINVAL : count; +} +EXPORT_SYMBOL_GPL(acpi_parse_entries_array); diff --git a/include/linux/acpi.h b/include/linux/acpi.h index efff750f326d..57ffba91bfb5 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -21,6 +21,30 @@ #endif #include +/* Table Handlers */ +union acpi_subtable_headers { + struct acpi_subtable_header common; + struct acpi_hmat_structure hmat; + struct acpi_prmt_module_header prmt; + struct acpi_cedt_header cedt; +}; + +typedef int (*acpi_tbl_table_handler)(struct acpi_table_header *table); + +typedef int (*acpi_tbl_entry_handler)(union acpi_subtable_headers *header, + const unsigned long end); + +typedef int (*acpi_tbl_entry_handler_arg)(union acpi_subtable_headers *header, + void *arg, const unsigned long end); + +struct acpi_subtable_proc { + int id; + acpi_tbl_entry_handler handler; + acpi_tbl_entry_handler_arg handler_arg; + void *arg; + int count; +}; + #ifdef CONFIG_ACPI #include @@ -129,22 +153,6 @@ enum acpi_address_range_id { }; -/* Table Handlers */ -union acpi_subtable_headers { - struct acpi_subtable_header common; - struct acpi_hmat_structure hmat; - struct acpi_prmt_module_header prmt; - struct acpi_cedt_header cedt; -}; - -typedef int (*acpi_tbl_table_handler)(struct acpi_table_header *table); - -typedef int (*acpi_tbl_entry_handler)(union acpi_subtable_headers *header, - const unsigned long end); - -typedef int (*acpi_tbl_entry_handler_arg)(union acpi_subtable_headers *header, - void *arg, const unsigned long end); - /* Debugger support */ struct acpi_debugger_ops { @@ -218,14 +226,6 @@ static inline int acpi_debugger_notify_command_complete(void) (!entry) || (unsigned long)entry + sizeof(*entry) > end || \ ((struct acpi_subtable_header *)entry)->length < sizeof(*entry)) -struct acpi_subtable_proc { - int id; - acpi_tbl_entry_handler handler; - acpi_tbl_entry_handler_arg handler_arg; - void *arg; - int count; -}; - void __iomem *__acpi_map_table(unsigned long phys, unsigned long size); void __acpi_unmap_table(void __iomem *map, unsigned long size); int early_acpi_boot_init(void); @@ -1524,4 +1524,19 @@ static inline void acpi_device_notify(struct device *dev) { } static inline void acpi_device_notify_remove(struct device *dev) { } #endif +#ifdef CONFIG_ACPI_TABLES_LIB +int acpi_parse_entries_array(char *id, unsigned long table_size, + struct acpi_table_header *table_header, + struct acpi_subtable_proc *proc, + int proc_num, unsigned int max_entries); +#else +static inline int acpi_parse_entries_array( + char *id, unsigned long table_size, + struct acpi_table_header *table_header, struct acpi_subtable_proc *proc, + int proc_num, unsigned int max_entries) +{ + return -EOPNOTSUPP; +} +#endif + #endif /*_LINUX_ACPI_H*/ From patchwork Thu May 18 18:33:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 13247249 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B81CEC77B7D for ; Thu, 18 May 2023 18:33:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229978AbjERSd3 (ORCPT ); Thu, 18 May 2023 14:33:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229436AbjERSdW (ORCPT ); Thu, 18 May 2023 14:33:22 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E25BE4F; Thu, 18 May 2023 11:33:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1684434790; x=1715970790; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=E0iekXhDQiXRad0eHsJzH45+eKLx4A3ZMETtRelLzEQ=; b=QRxT/cudMGB2RKl+e87iSrDYj+oM3CqqAUQHDIgaUI6P6KgzCY9AOH5L Ig1LId4HmnFKGnMB/lQsyDkecaJcAEfm8XAo3BAc5gry6p7JDGMr5p4a5 Je6tpFK3+z7vA3OC30kUFZEoCsk1YKtyEgpx64qfUjsSs2LGEphENPM6A eTXI8AN4HQQigtdsHOvBY+CeKmbXEkRM2sDS9rCZ3b21uWt7r74AN/G4Q x1TQ8D4kIrAQPmY3LGaLOhn1NeOMWOW+KcM3POP32nSSr9WIY3fV3Ue8u pVXhf0dXy0e9WyIz+1rdOQtSu5Yn9EG1+anBn9cees8eno5Bxq2kW0cDs w==; X-IronPort-AV: E=McAfee;i="6600,9927,10714"; a="341588748" X-IronPort-AV: E=Sophos;i="6.00,174,1681196400"; d="scan'208";a="341588748" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 May 2023 11:33:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10714"; a="814420308" X-IronPort-AV: E=Sophos;i="6.00,174,1681196400"; d="scan'208";a="814420308" Received: from djiang5-mobl3.amr.corp.intel.com (HELO [192.168.1.177]) ([10.212.16.136]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 May 2023 11:33:08 -0700 Subject: [PATCH v2 2/4] acpi: tables: Add CDAT table parsing support From: Dave Jiang To: linux-acpi@vger.kernel.org, linux-cxl@vger.kernel.org Cc: "Rafael J. Wysocki" , Len Brown , rafael@kernel.org, lenb@kernel.org, dan.j.williams@intel.com, ira.weiny@intel.com, vishal.l.verma@intel.com, alison.schofield@intel.com, lukas@wunner.de, Jonathan.Cameron@huawei.com Date: Thu, 18 May 2023 11:33:08 -0700 Message-ID: <168443478863.2966470.17477171378435115702.stgit@djiang5-mobl3> In-Reply-To: <168443445827.2966470.16511867875780059322.stgit@djiang5-mobl3> References: <168443445827.2966470.16511867875780059322.stgit@djiang5-mobl3> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org The CDAT table is very similar to ACPI tables when it comes to sub-table and entry structures. The helper functions can be also used to parse the CDAT table. Add support to the helper functions to deal with an external CDAT table, and also handle the endieness since CDAT can be processed by a BE host. Export a function cdat_table_parse() for CXL driver to parse a CDAT table. In order to minimize ACPICA code changes, __force is being utilized to deal with the case of a big endien (BE) host parsing a CDAT. All CDAT data structure variables are being force casted to __leX as appropriate. Cc: Rafael J. Wysocki Cc: Len Brown Signed-off-by: Dave Jiang --- v2: - Make acpi_table_header and acpi_table_cdat a union. (Jonathan) - Use local var to make acpi_table_get_length() more readable. (Jonathan) - Remove ACPI_SIG_CDAT define, already defined. --- drivers/acpi/tables.c | 5 +++- drivers/acpi/tables_lib.c | 52 ++++++++++++++++++++++++++++++++++++++++++--- include/linux/acpi.h | 22 +++++++++++++++++-- 3 files changed, 72 insertions(+), 7 deletions(-) diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c index cfc76efd8788..f7e1ea192576 100644 --- a/drivers/acpi/tables.c +++ b/drivers/acpi/tables.c @@ -241,8 +241,9 @@ int __init_or_acpilib acpi_table_parse_entries_array( return -ENODEV; } - count = acpi_parse_entries_array(id, table_size, table_header, - proc, proc_num, max_entries); + count = acpi_parse_entries_array(id, table_size, + (union table_header *)table_header, + proc, proc_num, max_entries); acpi_put_table(table_header); return count; diff --git a/drivers/acpi/tables_lib.c b/drivers/acpi/tables_lib.c index 701001610fa9..71e2fb1735e5 100644 --- a/drivers/acpi/tables_lib.c +++ b/drivers/acpi/tables_lib.c @@ -28,6 +28,7 @@ enum acpi_subtable_type { ACPI_SUBTABLE_HMAT, ACPI_SUBTABLE_PRMT, ACPI_SUBTABLE_CEDT, + CDAT_SUBTABLE, }; struct acpi_subtable_entry { @@ -46,6 +47,8 @@ static unsigned long acpi_get_entry_type(struct acpi_subtable_entry *entry) return 0; case ACPI_SUBTABLE_CEDT: return entry->hdr->cedt.type; + case CDAT_SUBTABLE: + return entry->hdr->cdat.type; } return 0; } @@ -61,6 +64,11 @@ static unsigned long acpi_get_entry_length(struct acpi_subtable_entry *entry) return entry->hdr->prmt.length; case ACPI_SUBTABLE_CEDT: return entry->hdr->cedt.length; + case CDAT_SUBTABLE: { + __le16 length = (__force __le16)entry->hdr->cdat.length; + + return le16_to_cpu(length); + } } return 0; } @@ -77,6 +85,8 @@ acpi_get_subtable_header_length(struct acpi_subtable_entry *entry) return sizeof(entry->hdr->prmt); case ACPI_SUBTABLE_CEDT: return sizeof(entry->hdr->cedt); + case CDAT_SUBTABLE: + return sizeof(entry->hdr->cdat); } return 0; } @@ -89,9 +99,23 @@ static enum acpi_subtable_type acpi_get_subtable_type(char *id) return ACPI_SUBTABLE_PRMT; if (strncmp(id, ACPI_SIG_CEDT, 4) == 0) return ACPI_SUBTABLE_CEDT; + if (strncmp(id, ACPI_SIG_CDAT, 4) == 0) + return CDAT_SUBTABLE; return ACPI_SUBTABLE_COMMON; } +static unsigned long acpi_table_get_length(enum acpi_subtable_type type, + union table_header *hdr) +{ + if (type == CDAT_SUBTABLE) { + __le32 length = (__force __le32)hdr->cdat.length; + + return le32_to_cpu(length); + } + + return hdr->acpi.length; +} + static bool has_handler(struct acpi_subtable_proc *proc) { return proc->handler || proc->handler_arg; @@ -131,21 +155,24 @@ static int call_handler(struct acpi_subtable_proc *proc, * Otherwise, -ENODEV or -EINVAL is returned. */ int acpi_parse_entries_array(char *id, unsigned long table_size, - struct acpi_table_header *table_header, + union table_header *table_header, struct acpi_subtable_proc *proc, int proc_num, unsigned int max_entries) { struct acpi_subtable_entry entry; + enum acpi_subtable_type type; unsigned long table_end, subtable_len, entry_len; int count = 0; int errs = 0; int i; - table_end = (unsigned long)table_header + table_header->length; + type = acpi_get_subtable_type(id); + table_end = (unsigned long)table_header + + acpi_table_get_length(type, table_header); /* Parse all entries looking for a match. */ - entry.type = acpi_get_subtable_type(id); + entry.type = type; entry.hdr = (union acpi_subtable_headers *) ((unsigned long)table_header + table_size); subtable_len = acpi_get_subtable_header_length(&entry); @@ -192,3 +219,22 @@ int acpi_parse_entries_array(char *id, unsigned long table_size, return errs ? -EINVAL : count; } EXPORT_SYMBOL_GPL(acpi_parse_entries_array); + +int cdat_table_parse(enum acpi_cdat_type type, + acpi_tbl_entry_handler_arg handler_arg, void *arg, + struct acpi_table_cdat *table_header) +{ + struct acpi_subtable_proc proc = { + .id = type, + .handler_arg = handler_arg, + .arg = arg, + }; + + if (!table_header) + return -EINVAL; + + return acpi_parse_entries_array(ACPI_SIG_CDAT, + sizeof(struct acpi_table_cdat), + (union table_header *)table_header, &proc, 1, 0); +} +EXPORT_SYMBOL_NS_GPL(cdat_table_parse, CXL); diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 57ffba91bfb5..4a5b40463048 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -22,11 +22,17 @@ #include /* Table Handlers */ +union table_header { + struct acpi_table_header acpi; + struct acpi_table_cdat cdat; +}; + union acpi_subtable_headers { struct acpi_subtable_header common; struct acpi_hmat_structure hmat; struct acpi_prmt_module_header prmt; struct acpi_cedt_header cedt; + struct acpi_cdat_header cdat; }; typedef int (*acpi_tbl_table_handler)(struct acpi_table_header *table); @@ -1526,17 +1532,29 @@ static inline void acpi_device_notify_remove(struct device *dev) { } #ifdef CONFIG_ACPI_TABLES_LIB int acpi_parse_entries_array(char *id, unsigned long table_size, - struct acpi_table_header *table_header, + union table_header *table_header, struct acpi_subtable_proc *proc, int proc_num, unsigned int max_entries); + +int cdat_table_parse(enum acpi_cdat_type type, + acpi_tbl_entry_handler_arg handler, void *arg, + struct acpi_table_cdat *table_header); #else static inline int acpi_parse_entries_array( char *id, unsigned long table_size, - struct acpi_table_header *table_header, struct acpi_subtable_proc *proc, + union table_header *table_header, struct acpi_subtable_proc *proc, int proc_num, unsigned int max_entries) { return -EOPNOTSUPP; } + +static inline int cdat_table_parse( + enum acpi_cdat_type type, + acpi_tbl_entry_handler_arg handler, void *arg, + struct acpi_table_cdat *table_header) +{ + return -EOPNOTSUPP; +} #endif #endif /*_LINUX_ACPI_H*/ From patchwork Thu May 18 18:33:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 13247250 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B3063C7EE25 for ; Thu, 18 May 2023 18:33:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229767AbjERSdb (ORCPT ); Thu, 18 May 2023 14:33:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229961AbjERSd3 (ORCPT ); Thu, 18 May 2023 14:33:29 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AC77E6B; Thu, 18 May 2023 11:33:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1684434796; x=1715970796; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LNZ475whOSsnQ6FkXed6RBXv7ecgGn8gYpLhyzS8534=; b=M2rE9hZNC26RChF5YLmmEc1aw4T1OT6x6Xkn/aWc1N8fnuMBMKcMZtYB vnybJuT4LPLdVWAvZlUNNFQ4au5/gxSWfTprbMrWKQOl7WtV4cqFZGL2e wj4sFv1NFsJlWSTuuV+SW89Ke4voKxE7IcL6kfAA9S7ffUZ7E5kfOilOQ Kr4ff92Cq/8YXe7yq29RwWsDqeaM92jPalI/q0ittsU9P5BO1eo6vABqe /4DDTlX+TYFDoshWVHmeRKyeN6hFoiyBsthHnZ8LHxblH0ZSP9tbel2g9 RtCK6U+JoRqto8YiIkwjoW6uz7zgaODpATaz5Q2msz9fcBdJmQgzyNblg w==; X-IronPort-AV: E=McAfee;i="6600,9927,10714"; a="341588772" X-IronPort-AV: E=Sophos;i="6.00,174,1681196400"; d="scan'208";a="341588772" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 May 2023 11:33:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10714"; a="814420327" X-IronPort-AV: E=Sophos;i="6.00,174,1681196400"; d="scan'208";a="814420327" Received: from djiang5-mobl3.amr.corp.intel.com (HELO [192.168.1.177]) ([10.212.16.136]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 May 2023 11:33:14 -0700 Subject: [PATCH v2 3/4] acpi: fix misnamed define for CDAT DSMAS From: Dave Jiang To: linux-acpi@vger.kernel.org, linux-cxl@vger.kernel.org Cc: "Rafael J. Wysocki" , Len Brown , rafael@kernel.org, lenb@kernel.org, dan.j.williams@intel.com, ira.weiny@intel.com, vishal.l.verma@intel.com, alison.schofield@intel.com, lukas@wunner.de, Jonathan.Cameron@huawei.com Date: Thu, 18 May 2023 11:33:14 -0700 Message-ID: <168443479457.2966470.18010229834586488037.stgit@djiang5-mobl3> In-Reply-To: <168443445827.2966470.16511867875780059322.stgit@djiang5-mobl3> References: <168443445827.2966470.16511867875780059322.stgit@djiang5-mobl3> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org ACPI_CEDT_DSMAS_NON_VOLATILE should be defined as ACPI_CDAT_DSMAS_NON_VOLATILE. Fix misspelled define. Cc: Rafael J. Wysocki Cc: Len Brown Signed-off-by: Dave Jiang --- See https://github.com/acpica/acpica/pull/874 Merged --- include/acpi/actbl1.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/acpi/actbl1.h b/include/acpi/actbl1.h index 81b9e794424d..15df363b9144 100644 --- a/include/acpi/actbl1.h +++ b/include/acpi/actbl1.h @@ -356,7 +356,7 @@ struct acpi_cdat_dsmas { /* Flags for subtable above */ -#define ACPI_CEDT_DSMAS_NON_VOLATILE (1 << 2) +#define ACPI_CDAT_DSMAS_NON_VOLATILE (1 << 2) /* Subtable 1: Device scoped Latency and Bandwidth Information Structure (DSLBIS) */ From patchwork Thu May 18 18:33:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 13247251 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69066C7EE25 for ; Thu, 18 May 2023 18:33:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229436AbjERSdw (ORCPT ); Thu, 18 May 2023 14:33:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229569AbjERSdv (ORCPT ); Thu, 18 May 2023 14:33:51 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B02D6127; Thu, 18 May 2023 11:33:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1684434830; x=1715970830; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DQ00hd0YR4BGL/6CcDpbb4RmtqcJv+sUZVhHtSVJapg=; b=IwISkHbgjgSQUB2cPUsKmyNfhScZYh+THAtTTRgks/ARacmj/YHz76sM PHSljW5bFsNNEoC0lh6A8C6QbZE22he8PbX37auPxCBcP74xZ+/vPoslp DSlja4484rgfJO2Hu+CxxoMd+Fs7MMpsX5iVJ1ytIy6mAG49xeTfMdzEB 3gRg7uN1tCgViyqDS3aPSisK88HyD8qM7y8PONcBvfVflaLvsaq7RPHqN bBvswSyxSeQLheP0DguEvLISfpw/ceoQc3cKTQOsXCAb21Pzw0usLeQES DthEgvHpjuaTliyEPPLVKQu5ZyDqO5wEDWJqIYuvkduVx/lh78t4D8XrQ Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10714"; a="349669910" X-IronPort-AV: E=Sophos;i="6.00,174,1681196400"; d="scan'208";a="349669910" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 May 2023 11:33:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10714"; a="767330276" X-IronPort-AV: E=Sophos;i="6.00,174,1681196400"; d="scan'208";a="767330276" Received: from djiang5-mobl3.amr.corp.intel.com (HELO [192.168.1.177]) ([10.212.16.136]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 May 2023 11:33:20 -0700 Subject: [PATCH v2 4/4] acpi: Add defines for CDAT SSLBIS From: Dave Jiang To: linux-acpi@vger.kernel.org, linux-cxl@vger.kernel.org Cc: rafael@kernel.org, lenb@kernel.org, dan.j.williams@intel.com, ira.weiny@intel.com, vishal.l.verma@intel.com, alison.schofield@intel.com, lukas@wunner.de, Jonathan.Cameron@huawei.com Date: Thu, 18 May 2023 11:33:20 -0700 Message-ID: <168443480048.2966470.1931302851443645778.stgit@djiang5-mobl3> In-Reply-To: <168443445827.2966470.16511867875780059322.stgit@djiang5-mobl3> References: <168443445827.2966470.16511867875780059322.stgit@djiang5-mobl3> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org Add upstream port and any port definition for SSLBIS. Signed-off-by: Dave Jiang --- See https://github.com/acpica/acpica/pull/874 Merged --- include/acpi/actbl1.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/acpi/actbl1.h b/include/acpi/actbl1.h index 15df363b9144..c6189fafe87f 100644 --- a/include/acpi/actbl1.h +++ b/include/acpi/actbl1.h @@ -419,6 +419,9 @@ struct acpi_cdat_sslbe { u16 reserved; }; +#define ACPI_CDAT_SSLBIS_US_PORT 0x0100 +#define ACPI_CDAT_SSLBIS_ANY_PORT 0xffff + /******************************************************************************* * * CEDT - CXL Early Discovery Table