From patchwork Fri May 5 17:32:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 679770 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 71DAFC7EE2C for ; Fri, 5 May 2023 17:33:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232177AbjEERda (ORCPT ); Fri, 5 May 2023 13:33:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232137AbjEERdH (ORCPT ); Fri, 5 May 2023 13:33:07 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B6A22722; Fri, 5 May 2023 10:32:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1683307978; x=1714843978; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FD/FDXX8oEQ3rexE82FfQ+JHlAlbXlbkJwbvnDyY0Bo=; b=c+VH92R9hcFYgtETcQzOCZbNEOQmHsRLqSoZElx+VSmaIzJURzUsumJ6 AONTK+aoFl0RB5okPpNIIHQd41dDgUrVe/GF953WODKS+WE/0K2CWYs/N 1B8zi1FyFH4i1x87CPpXNB6rzh0N3Y+j4MdmysndylJ6BKapC1yB0A9ot jKnqmGgPFYKwse9LCjMKOf3ZS+TtVC/RvX1maXcpH3QHlqKDW/OBnvBu4 6ext6mPzMTZn9cwQhwwFbzMtPrHoJQf78jJCpxvC4lAjLiOCSnVYi7jqL mNGZNFmHC5ViYuupGabjS6OmnT7mPEDfjHQXxLyEc7N52TJ8Ou76QSXOu A==; X-IronPort-AV: E=McAfee;i="6600,9927,10701"; a="349301198" X-IronPort-AV: E=Sophos;i="5.99,252,1677571200"; d="scan'208";a="349301198" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2023 10:32:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10701"; a="700531219" X-IronPort-AV: E=Sophos;i="5.99,252,1677571200"; d="scan'208";a="700531219" Received: from djiang5-mobl3.amr.corp.intel.com (HELO [192.168.1.177]) ([10.212.77.78]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2023 10:32:57 -0700 Subject: [PATCH 1/4] acpi: tables: Add CDAT table parsing support 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: Fri, 05 May 2023 10:32:56 -0700 Message-ID: <168330797672.2042604.12339416734589446371.stgit@djiang5-mobl3> In-Reply-To: <168330787964.2042604.17648905811002211147.stgit@djiang5-mobl3> References: <168330787964.2042604.17648905811002211147.stgit@djiang5-mobl3> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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 acpi_table_parse_cdat() for CXL driver to parse a CDAT table. In order to minimize ACPI 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 --- drivers/acpi/tables.c | 47 +++++++++++++++++++++++++++++++++++++++++++++-- include/acpi/actbl1.h | 3 +++ include/linux/acpi.h | 4 ++++ 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c index 7b4680da57d7..08486f6df442 100644 --- a/drivers/acpi/tables.c +++ b/drivers/acpi/tables.c @@ -42,6 +42,7 @@ enum acpi_subtable_type { ACPI_SUBTABLE_HMAT, ACPI_SUBTABLE_PRMT, ACPI_SUBTABLE_CEDT, + ACPI_SUBTABLE_CDAT, }; struct acpi_subtable_entry { @@ -239,6 +240,8 @@ acpi_get_entry_type(struct acpi_subtable_entry *entry) return 0; case ACPI_SUBTABLE_CEDT: return entry->hdr->cedt.type; + case ACPI_SUBTABLE_CDAT: + return entry->hdr->cdat.type; } return 0; } @@ -255,6 +258,8 @@ acpi_get_entry_length(struct acpi_subtable_entry *entry) return entry->hdr->prmt.length; case ACPI_SUBTABLE_CEDT: return entry->hdr->cedt.length; + case ACPI_SUBTABLE_CDAT: + return le16_to_cpu((__force __le16)entry->hdr->cdat.length); } return 0; } @@ -271,6 +276,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 ACPI_SUBTABLE_CDAT: + return sizeof(entry->hdr->cdat); } return 0; } @@ -284,9 +291,22 @@ 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 ACPI_SUBTABLE_CDAT; return ACPI_SUBTABLE_COMMON; } +static unsigned long __init_or_acpilib +acpi_table_get_length(enum acpi_subtable_type type, + struct acpi_table_header *hdr) +{ + if (type == ACPI_SUBTABLE_CDAT) + return le32_to_cpu( + (__force __le32)((struct acpi_table_cdat *)hdr)->length); + + return hdr->length; +} + static __init_or_acpilib bool has_handler(struct acpi_subtable_proc *proc) { return proc->handler || proc->handler_arg; @@ -332,16 +352,19 @@ static int __init_or_acpilib acpi_parse_entries_array( 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); @@ -464,6 +487,26 @@ int __init acpi_table_parse_madt(enum acpi_madt_type id, handler, max_entries); } +int acpi_table_parse_cdat(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), + (struct acpi_table_header *)table_header, + &proc, 1, 0); +} +EXPORT_SYMBOL_NS_GPL(acpi_table_parse_cdat, CXL); + /** * acpi_table_parse - find table with @id, run @handler on it * @id: table id to find diff --git a/include/acpi/actbl1.h b/include/acpi/actbl1.h index 81b9e794424d..3119be093cfe 100644 --- a/include/acpi/actbl1.h +++ b/include/acpi/actbl1.h @@ -66,6 +66,9 @@ #define ACPI_SIG_IEIT "IEIT" #endif +/* External to ACPI */ +#define ACPI_SIG_CDAT "CDAT" /* Coherent Device Attribute Table */ + /* * All tables must be byte-packed to match the ACPI specification, since * the tables are provided by the system BIOS. diff --git a/include/linux/acpi.h b/include/linux/acpi.h index efff750f326d..4c3dfe7587e9 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -135,6 +135,7 @@ union acpi_subtable_headers { 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); @@ -266,6 +267,9 @@ acpi_table_parse_cedt(enum acpi_cedt_type id, int acpi_parse_mcfg (struct acpi_table_header *header); void acpi_table_print_madt_entry (struct acpi_subtable_header *madt); +int acpi_table_parse_cdat(enum acpi_cdat_type type, + acpi_tbl_entry_handler_arg handler, void *arg, + struct acpi_table_cdat *table_header); /* the following numa functions are architecture-dependent */ void acpi_numa_slit_init (struct acpi_table_slit *slit); From patchwork Fri May 5 17: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: 679378 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 94AC4C7EE2F for ; Fri, 5 May 2023 17:33:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231563AbjEERda (ORCPT ); Fri, 5 May 2023 13:33:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232767AbjEERdJ (ORCPT ); Fri, 5 May 2023 13:33:09 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE6BDAD0A; Fri, 5 May 2023 10: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=1683307984; x=1714843984; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=z/YQtogYQbIISXUUKIz/FcxkfBirKCCFl1KoqVUT/aM=; b=GFHVEFb41TUfQIjyoDZlnnDTJe1KKBLNjVX8naAM/Db1I0JKqHyBUjOq Kk0Go4ihodkI8sRvvtf+mRn6bU5D9ohtvU6tHFAgWryBf0hx8CEqTN6R+ LzZLmEq1Xn21XzWMdDASKFp+T0OJvr49bgKffNELjkAfx/X3dkTreObXH 94pxibssJE74b3bnEFrIpWGMWNR1wGyVtUtqNpQH31fvpYEPEAaio0GsV YidqzdqAFEB8ra+7UfjPJW4kzOVyxWh7ty889DlhtgEj7/9Miq2F/tUsh H4klcbH4B6tlmQyetyUvTfXM03qOFlPU2yuIHRjEgVC8Rdyj914cumdga w==; X-IronPort-AV: E=McAfee;i="6600,9927,10701"; a="349301217" X-IronPort-AV: E=Sophos;i="5.99,252,1677571200"; d="scan'208";a="349301217" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2023 10:33:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10701"; a="700531240" X-IronPort-AV: E=Sophos;i="5.99,252,1677571200"; d="scan'208";a="700531240" Received: from djiang5-mobl3.amr.corp.intel.com (HELO [192.168.1.177]) ([10.212.77.78]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2023 10:33:03 -0700 Subject: [PATCH 2/4] acpi: Add header struct in CDAT subtables 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: Fri, 05 May 2023 10:33:02 -0700 Message-ID: <168330798275.2042604.11217169699695338532.stgit@djiang5-mobl3> In-Reply-To: <168330787964.2042604.17648905811002211147.stgit@djiang5-mobl3> References: <168330787964.2042604.17648905811002211147.stgit@djiang5-mobl3> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Add the common header struct in all CDAT subtables. This change complies with other ACPI sub-tables in the header file. The change also eases the usage with the helper functions in tables.c. Cc: Rafael J. Wysocki Cc: Len Brown Signed-off-by: Dave Jiang Reviewed-by: Jonathan Cameron --- include/acpi/actbl1.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/acpi/actbl1.h b/include/acpi/actbl1.h index 3119be093cfe..166337b04306 100644 --- a/include/acpi/actbl1.h +++ b/include/acpi/actbl1.h @@ -350,6 +350,7 @@ enum acpi_cdat_type { /* Subtable 0: Device Scoped Memory Affinity Structure (DSMAS) */ struct acpi_cdat_dsmas { + struct acpi_cdat_header header; u8 dsmad_handle; u8 flags; u16 reserved; @@ -364,6 +365,7 @@ struct acpi_cdat_dsmas { /* Subtable 1: Device scoped Latency and Bandwidth Information Structure (DSLBIS) */ struct acpi_cdat_dslbis { + struct acpi_cdat_header header; u8 handle; u8 flags; /* If Handle matches a DSMAS handle, the definition of this field matches * Flags field in HMAT System Locality Latency */ @@ -377,6 +379,7 @@ struct acpi_cdat_dslbis { /* Subtable 2: Device Scoped Memory Side Cache Information Structure (DSMSCIS) */ struct acpi_cdat_dsmscis { + struct acpi_cdat_header header; u8 dsmas_handle; u8 reserved[3]; u64 side_cache_size; @@ -386,6 +389,7 @@ struct acpi_cdat_dsmscis { /* Subtable 3: Device Scoped Initiator Structure (DSIS) */ struct acpi_cdat_dsis { + struct acpi_cdat_header header; u8 flags; u8 handle; u16 reserved; @@ -398,6 +402,7 @@ struct acpi_cdat_dsis { /* Subtable 4: Device Scoped EFI Memory Type Structure (DSEMTS) */ struct acpi_cdat_dsemts { + struct acpi_cdat_header header; u8 dsmas_handle; u8 memory_type; u16 reserved; @@ -408,6 +413,7 @@ struct acpi_cdat_dsemts { /* Subtable 5: Switch Scoped Latency and Bandwidth Information Structure (SSLBIS) */ struct acpi_cdat_sslbis { + struct acpi_cdat_header header; u8 data_type; u8 reserved[3]; u64 entry_base_unit; From patchwork Fri May 5 17: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: 679769 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 A8763C7EE24 for ; Fri, 5 May 2023 17:33:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232167AbjEERdb (ORCPT ); Fri, 5 May 2023 13:33:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232818AbjEERdK (ORCPT ); Fri, 5 May 2023 13:33:10 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6A513C34; Fri, 5 May 2023 10:33:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1683307989; x=1714843989; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YN+oJapGmyCTPCfCe0BSQmXfdb6zKqYD+fIXjEyZ1y0=; b=bmSs6SbnCZQb2YmQ3Sb/XjiU2Zii23v3oVPstEgr4iWtLpLN0FYlJCS7 7yzvCNd5G6AroBmXoUgy8BscZjz01J1f7+qEImckEuViAkXYa1ObMCRKJ Wyv9Hs2MgWgJhRzyoCuJcoUO2/AgGyVG2Ua4gTMAC5bw55tmvgUM1o6E2 mwogh+iX41YVabyQqpfclY2FYVNBIl64gg1VuSkDYul/oJhnsdShbuwpS NxE1xNrIJm65VNe84vtvuAeag6KvSjM3J8qw5Kr91ZGopCfBGVaUq2nVf mMfdCQoJaMWAYk/6HHFCarYTB9h76FJ5siZP3tPKcq8s+je6lMWYpTg0O A==; X-IronPort-AV: E=McAfee;i="6600,9927,10701"; a="349301234" X-IronPort-AV: E=Sophos;i="5.99,252,1677571200"; d="scan'208";a="349301234" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2023 10:33:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10701"; a="700531264" X-IronPort-AV: E=Sophos;i="5.99,252,1677571200"; d="scan'208";a="700531264" Received: from djiang5-mobl3.amr.corp.intel.com (HELO [192.168.1.177]) ([10.212.77.78]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2023 10:33:09 -0700 Subject: [PATCH 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@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: Fri, 05 May 2023 10:33:08 -0700 Message-ID: <168330798865.2042604.4255466100952700191.stgit@djiang5-mobl3> In-Reply-To: <168330787964.2042604.17648905811002211147.stgit@djiang5-mobl3> References: <168330787964.2042604.17648905811002211147.stgit@djiang5-mobl3> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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 Reviewed-by: Jonathan Cameron --- 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 166337b04306..8ea7e5d64bc1 100644 --- a/include/acpi/actbl1.h +++ b/include/acpi/actbl1.h @@ -360,7 +360,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 Fri May 5 17: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: 679377 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 93C92C7EE22 for ; Fri, 5 May 2023 17:33:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232643AbjEERdc (ORCPT ); Fri, 5 May 2023 13:33:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229591AbjEERdR (ORCPT ); Fri, 5 May 2023 13:33:17 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAD7F3C02; Fri, 5 May 2023 10:33:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1683307995; x=1714843995; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BcqKT+UhKNUQksbe6xIXUe8nlh5CDuzSwNs608X3Sxs=; b=PA/HRyT+ymufYOnH0024VvYXlOX4KqabdOJz0arzQsJRMp6YtTHub+z3 yX9S6x6cvhHU4qszIuL6HQFAQrIR4UTblKr2y+JQ1KmHgxAaSSObliS5X rsxmkzEJ7tz5nGMpS4QKVZleSKXZ4QfypaDVkordpEu96NKGgNcIGTW27 60wr5qoTnsY8HCG10PQM/KeTJvFl/FINYSsoZqmE9EAo5eoH5J04n785Q zobmB2F7f6wmCVFoxstTDWYkR8blTl1l4J1I5mTLEclijSYyvUN3Ef3hC YwWHzaVszRZ6kL9a0Ze6z8zA/J/ynpDyrlwqmiJbjBg+RMQ05+JngdeBk w==; X-IronPort-AV: E=McAfee;i="6600,9927,10701"; a="349301250" X-IronPort-AV: E=Sophos;i="5.99,252,1677571200"; d="scan'208";a="349301250" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2023 10:33:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10701"; a="700531288" X-IronPort-AV: E=Sophos;i="5.99,252,1677571200"; d="scan'208";a="700531288" Received: from djiang5-mobl3.amr.corp.intel.com (HELO [192.168.1.177]) ([10.212.77.78]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2023 10:33:15 -0700 Subject: [PATCH 4/4] cxl: Add callback to parse the DSMAS subtables from CDAT 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: Fri, 05 May 2023 10:33:14 -0700 Message-ID: <168330799471.2042604.1887260521284311424.stgit@djiang5-mobl3> In-Reply-To: <168330787964.2042604.17648905811002211147.stgit@djiang5-mobl3> References: <168330787964.2042604.17648905811002211147.stgit@djiang5-mobl3> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Provide a callback function to the CDAT parser in order to parse the Device Scoped Memory Affinity Structure (DSMAS). Each DSMAS structure contains the DPA range and its associated attributes in each entry. See the CDAT specification for details. The device handle and the DPA range is saved and to be associated with the DSLBIS locality data when the DSLBIS entries are parsed. The list is a local list. When the total path performance data is calculated and storred this list can be discarded. Coherent Device Attribute Table 1.03 2.1 Device Scoped memory Affinity Structure (DSMAS) Signed-off-by: Dave Jiang --- v5: - Update commit log to indicate what list is used for. (Jonathan, Dan) - Use acpi_table_parse_cdat() - Isolate cdat code behind CONFIG_ACPI v3: - Add spec section number. (Alison) - Remove cast from void *. (Alison) - Refactor cxl_port_probe() block. (Alison) - Move CDAT parse to cxl_endpoint_port_probe() v2: - Add DSMAS table size check. (Lukas) - Use local DSMAS header for LE handling. - Remove dsmas lock. (Jonathan) - Fix handle size (Jonathan) - Add LE to host conversion for DSMAS address and length. - Make dsmas_list local --- drivers/cxl/core/Makefile | 1 + drivers/cxl/core/cdat.c | 40 ++++++++++++++++++++++++++++++++++++++++ drivers/cxl/cxl.h | 18 ++++++++++++++++++ drivers/cxl/port.c | 22 ++++++++++++++++++++++ 4 files changed, 81 insertions(+) create mode 100644 drivers/cxl/core/cdat.c diff --git a/drivers/cxl/core/Makefile b/drivers/cxl/core/Makefile index ca4ae31d8f57..98ddfd110f9b 100644 --- a/drivers/cxl/core/Makefile +++ b/drivers/cxl/core/Makefile @@ -12,5 +12,6 @@ cxl_core-y += memdev.o cxl_core-y += mbox.o cxl_core-y += pci.o cxl_core-y += hdm.o +cxl_core-$(CONFIG_ACPI) += cdat.o cxl_core-$(CONFIG_TRACING) += trace.o cxl_core-$(CONFIG_CXL_REGION) += region.o diff --git a/drivers/cxl/core/cdat.c b/drivers/cxl/core/cdat.c new file mode 100644 index 000000000000..61979f0789aa --- /dev/null +++ b/drivers/cxl/core/cdat.c @@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright(c) 2023 Intel Corporation. All rights reserved. */ +#include +#include "cxlpci.h" +#include "cxl.h" + +static int cdat_dsmas_handler(union acpi_subtable_headers *header, void *arg, + const unsigned long end) +{ + struct acpi_cdat_dsmas *dsmas = (struct acpi_cdat_dsmas *)header; + struct list_head *dsmas_list = arg; + struct dsmas_entry *dent; + u16 len; + + len = le16_to_cpu((__force __le16)dsmas->header.length); + if (len != sizeof(*dsmas) || (unsigned long)header + len > end) { + pr_warn("Malformed DSMAS table length: (%lu:%u)\n", + (unsigned long)sizeof(*dsmas), len); + return -EINVAL; + } + + dent = kzalloc(sizeof(*dent), GFP_KERNEL); + if (!dent) + return -ENOMEM; + + dent->handle = dsmas->dsmad_handle; + dent->dpa_range.start = le64_to_cpu((__force __le64)dsmas->dpa_base_address); + dent->dpa_range.end = le64_to_cpu((__force __le64)dsmas->dpa_base_address) + + le64_to_cpu((__force __le64)dsmas->dpa_length) - 1; + list_add_tail(&dent->list, dsmas_list); + + return 0; +} + +int cxl_cdat_endpoint_process(struct cxl_port *port, struct list_head *list) +{ + return acpi_table_parse_cdat(ACPI_CDAT_TYPE_DSMAS, cdat_dsmas_handler, + list, port->cdat.table); +} +EXPORT_SYMBOL_NS_GPL(cxl_cdat_endpoint_process, CXL); diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h index 4577d808ac6d..dda7238b47f5 100644 --- a/drivers/cxl/cxl.h +++ b/drivers/cxl/cxl.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -791,6 +792,23 @@ static inline struct cxl_dax_region *to_cxl_dax_region(struct device *dev) } #endif +/* CDAT related bits */ +struct dsmas_entry { + struct list_head list; + struct range dpa_range; + u8 handle; +}; + +#ifdef CONFIG_ACPI +int cxl_cdat_endpoint_process(struct cxl_port *port, struct list_head *list); +#else +static inline int cxl_cdat_endpoint_process(struct cxl_port *port, + struct list_head *list) +{ + return -EOPNOTSUPP; +} +#endif + /* * Unit test builds overrides this to __weak, find the 'strong' version * of these symbols in tools/testing/cxl/. diff --git a/drivers/cxl/port.c b/drivers/cxl/port.c index a49f5eb149f1..da023feaa6e2 100644 --- a/drivers/cxl/port.c +++ b/drivers/cxl/port.c @@ -57,6 +57,16 @@ static int discover_region(struct device *dev, void *root) return 0; } +static void dsmas_list_destroy(struct list_head *dsmas_list) +{ + struct dsmas_entry *dentry, *n; + + list_for_each_entry_safe(dentry, n, dsmas_list, list) { + list_del(&dentry->list); + kfree(dentry); + } +} + static int cxl_switch_port_probe(struct cxl_port *port) { struct cxl_hdm *cxlhdm; @@ -131,6 +141,18 @@ static int cxl_endpoint_port_probe(struct cxl_port *port) device_for_each_child(&port->dev, root, discover_region); put_device(&root->dev); + if (port->cdat.table) { + LIST_HEAD(dsmas_list); + + rc = cxl_cdat_endpoint_process(port, &dsmas_list); + if (rc < 0) + dev_dbg(&port->dev, "Failed to parse CDAT: %d\n", rc); + + /* Performance data processing */ + + dsmas_list_destroy(&dsmas_list); + } + return 0; }