From nobody Sun Feb 8 23:23:15 2026 Received: from PH8PR06CU001.outbound.protection.outlook.com (mail-westus3azon11012053.outbound.protection.outlook.com [40.107.209.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0F40A325719; Sat, 10 Jan 2026 11:47:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.209.53 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768045672; cv=fail; b=upgPi6X1KelpTVux8fYzKPcj1HoP+EoEKKdzSP6e1rAZlJhhZxHJRZc5fVVHRZ+DEfXChkJyM8LczBttz7DKDI2HsAVkEBRKtek6ZTHU1psK+t2DP5NvHKtLSqZ+H+tI3+uzgr0ciH5Jy5TMAn4g2p7IoIn+M/cbNqphOhNT6KA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768045672; c=relaxed/simple; bh=WSbH2s9PaDomQZYuGg0sG1E7ksIZMUsa6WgnHbwvoCg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DpsD1vmviPtlWkA+vZXyUtxtaueJzuf99a71x6Ybz53pYAUOgiJXIXzV7Qksf2+2jBmS88kDnQmySfRDbNOLHgb/3LARTyLs6FQcjEW7x7OLg6C17wdO0aHBKDQ2PWwpkl6RiGRFDhU2BN5Ccxe53BDOGCKtXgsboS2F7GePr60= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=iktTxsPt; arc=fail smtp.client-ip=40.107.209.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="iktTxsPt" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=c+Q4CBXR6cm5zo3CiHGCWzN2PRmtvxHVnFW5hGjilUzz3pzUD3oJ1h3RP1PkMtnlFU8lJjxM++sKXwR0pkkUWGlPgIXVBW3ddSOS5jqFF+4xxDIjO48y64KjPyAbpbUqPht7L0K9xfEBDS9QRyHKkjmwFEiacX1zDADcE/viUP0d5iYko6kExEpHgXxdai13+e+5iI6uI2LiSPazEzVpQGvV1POsDcPOglk05SOAiIdJR75JK9r4id80R2Xy/edFBev0AzY+Nz2CRDzTJD8ZTRduwMRAHHVkA06XGiFp/Tq1Jyf/CkY2c9/fQPWKpMVpkR5X1UpyFeHpUxGbJhwuCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=g7xuUajMDYVJSVKG4pfP3zjDyTBmde8Weshptk5gOjU=; b=QIrrGcKmOk2+S6jdLcOz9jPiDgXVBvvxHUSsRxhhW1EB8C1f9J76oY2O268YJ5A/qHiESi/wUBoXi3G/ovJ2zpqpDctogwQiZed4zF8QmOLiL7ry7kXhWQu1n0Qqi7zoO73NBrxsWTt1Rjh9p8zpXthTwebjkZ07XV5qBRnkEMR5XEZhF6PRwd5pYX+rD9VyXpI7i5JVyjzNfxz2mOsZ140VblELPq1RewbnNZ2+SuiqPh3EdIXIKzmnJ5jQ3kV28RuqzwUhoKxTQGPaTt+JE/dJbWYH0sT+uvi37RUmwXzGylaf+sOrPhdHC5nO5fhVoTghNu3OnErM2nPi6ulsZg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=intel.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=g7xuUajMDYVJSVKG4pfP3zjDyTBmde8Weshptk5gOjU=; b=iktTxsPt3pk+Xd5miK3EDWaUbOnv97LDjYjkpPFrAnl1n78JJKgkjj2n0SM2VEYjxExZBqQlJkAqF0FJaaYPI5xJ8eBu2Z1xIWO+f/OrWO83TtKEK8aCeHZDbJB+EbT/yV4qItsUxC/MpRNl4FgKL+VpQBg8s+dmUlYUgSooTxg= Received: from SA0PR11CA0174.namprd11.prod.outlook.com (2603:10b6:806:1bb::29) by IA1PR12MB9465.namprd12.prod.outlook.com (2603:10b6:208:593::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9499.6; Sat, 10 Jan 2026 11:47:45 +0000 Received: from SN1PEPF000397B4.namprd05.prod.outlook.com (2603:10b6:806:1bb:cafe::46) by SA0PR11CA0174.outlook.office365.com (2603:10b6:806:1bb::29) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9499.6 via Frontend Transport; Sat, 10 Jan 2026 11:47:44 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by SN1PEPF000397B4.mail.protection.outlook.com (10.167.248.58) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9520.1 via Frontend Transport; Sat, 10 Jan 2026 11:47:44 +0000 Received: from rric.localdomain (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Sat, 10 Jan 2026 05:47:40 -0600 From: Robert Richter To: Alison Schofield , Vishal Verma , Ira Weiny , Dan Williams , Jonathan Cameron , Dave Jiang , Davidlohr Bueso CC: , , Gregory Price , "Fabio M. De Francesco" , Terry Bowman , Joshua Hahn , Robert Richter Subject: [PATCH v9 05/13] cxl/region: Separate region parameter setup and region construction Date: Sat, 10 Jan 2026 12:46:50 +0100 Message-ID: <20260110114705.681676-6-rrichter@amd.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260110114705.681676-1-rrichter@amd.com> References: <20260110114705.681676-1-rrichter@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF000397B4:EE_|IA1PR12MB9465:EE_ X-MS-Office365-Filtering-Correlation-Id: 6effea68-fb87-47bd-a2ba-08de503e11c6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|1800799024|36860700013|376014|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?977KcBMunvQtu3dSt+SJ0bQCyp5rn1mnSzN49iY3CAqdUuQlk0eDTRXq3KrX?= =?us-ascii?Q?cV7gcJ5fqML4ZsXezZBIs/nwb1rGxzORKNxKflQcMChEls98GVrcY9DPeGOv?= =?us-ascii?Q?ooW0rRjYeCPqysrZj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OPXsyx?= =?us-ascii?Q?pRMNfAsJAACNi5w5Cugjf7XOm4JFisnX3qL8//ijYbpuJLn6VODv6HK68F8W?= =?us-ascii?Q?gzeyiyAQ2Taoprr5OskM4KSsEQWoTUGg+9DV80wkS2ca/4OOXAa7MAdTEsGc?= =?us-ascii?Q?613Ehb67C2827CG5UXFZvq6g4ahmVkbKMOCMOHEa6PvKc/7HVhDRK2x+Tc+1?= =?us-ascii?Q?DlbdiEmPAeWp4yKDo308PTzSAb1yp/6Ed/lksXCXytXRi5aSMKi8yqgOOA6D?= =?us-ascii?Q?0tAYIKGE7jl/SDnV1aubzy50TgokdUzsKh1drz6vic4+i05+ShwXlPr/WZMg?= =?us-ascii?Q?QHfk3wC/MLrs8z4J+v4yOA4YtGlxUlFCS7KCc2zfvACeBh+8UT63KRiIJDd5?= =?us-ascii?Q?x8gZ45tncJPtyncN07EIIVkuta2F5UJl07kSiS5+LLCL1n0PZqIFONN7c9A+?= =?us-ascii?Q?6CwquSapI1vA87TqrEUFSdq8M1Om+t5apTsWCuo7J51U2HgzZI17OKv4F/8t?= =?us-ascii?Q?dwLc8jN2meuKOob2PzE5Ak1J/PoNnDmuJevLBylMNuj2yMYuYxjMbQvC0lLq?= =?us-ascii?Q?aDKooPviz2N6PZSW5m0=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(7416014)(1800799024)(36860700013)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jan 2026 11:47:44.9253 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6effea68-fb87-47bd-a2ba-08de503e11c6 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF000397B4.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB9465 Content-Type: text/plain; charset="utf-8" To construct a region, the region parameters such as address range and interleaving config need to be determined. This is done while constructing the region by inspecting the endpoint decoder configuration. The endpoint decoder is passed as a function argument. With address translation the endpoint decoder data is no longer sufficient to extract the region parameters as some of the information is obtained using other methods such as using firmware calls. In a first step, separate code to determine the region parameters from the region construction. Temporarily store all the data to create the region in the new struct cxl_region_context. Once the region data is determined and struct cxl_region_context is filled, construct the region. Patch is a prerequisite to implement address translation. The code separation helps to later extend it to determine region parameters using other methods as needed, esp. to support address translation. Reviewed-by: Gregory Price Reviewed-by: Dave Jiang Reviewed-by: Jonathan Cameron Tested-by: Gregory Price Signed-off-by: Robert Richter Reviewed-by: Alison Schofield --- drivers/cxl/core/core.h | 8 ++++++++ drivers/cxl/core/region.c | 27 ++++++++++++++++++--------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/drivers/cxl/core/core.h b/drivers/cxl/core/core.h index 1fb66132b777..ae9e1bb51562 100644 --- a/drivers/cxl/core/core.h +++ b/drivers/cxl/core/core.h @@ -19,6 +19,14 @@ enum cxl_detach_mode { }; =20 #ifdef CONFIG_CXL_REGION + +struct cxl_region_context { + struct cxl_endpoint_decoder *cxled; + struct range hpa_range; + int interleave_ways; + int interleave_granularity; +}; + extern struct device_attribute dev_attr_create_pmem_region; extern struct device_attribute dev_attr_create_ram_region; extern struct device_attribute dev_attr_delete_region; diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index 04c3ff66ec81..5ae77e9feb4d 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -3565,11 +3565,12 @@ static int cxl_extended_linear_cache_resize(struct = cxl_region *cxlr, } =20 static int __construct_region(struct cxl_region *cxlr, - struct cxl_endpoint_decoder *cxled) + struct cxl_region_context *ctx) { + struct cxl_endpoint_decoder *cxled =3D ctx->cxled; struct cxl_root_decoder *cxlrd =3D cxlr->cxlrd; struct cxl_memdev *cxlmd =3D cxled_to_memdev(cxled); - struct range *hpa_range =3D &cxled->cxld.hpa_range; + struct range *hpa_range =3D &ctx->hpa_range; struct cxl_region_params *p; struct resource *res; int rc; @@ -3622,8 +3623,8 @@ static int __construct_region(struct cxl_region *cxlr, } =20 p->res =3D res; - p->interleave_ways =3D cxled->cxld.interleave_ways; - p->interleave_granularity =3D cxled->cxld.interleave_granularity; + p->interleave_ways =3D ctx->interleave_ways; + p->interleave_granularity =3D ctx->interleave_granularity; p->state =3D CXL_CONFIG_INTERLEAVE_ACTIVE; =20 rc =3D sysfs_update_group(&cxlr->dev.kobj, get_cxl_region_target_group()); @@ -3643,8 +3644,9 @@ static int __construct_region(struct cxl_region *cxlr, =20 /* Establish an empty region covering the given HPA range */ static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd, - struct cxl_endpoint_decoder *cxled) + struct cxl_region_context *ctx) { + struct cxl_endpoint_decoder *cxled =3D ctx->cxled; struct cxl_memdev *cxlmd =3D cxled_to_memdev(cxled); struct cxl_port *port =3D cxlrd_to_port(cxlrd); struct cxl_dev_state *cxlds =3D cxlmd->cxlds; @@ -3664,7 +3666,7 @@ static struct cxl_region *construct_region(struct cxl= _root_decoder *cxlrd, return cxlr; } =20 - rc =3D __construct_region(cxlr, cxled); + rc =3D __construct_region(cxlr, ctx); if (rc) { devm_release_action(port->uport_dev, unregister_region, cxlr); return ERR_PTR(rc); @@ -3689,11 +3691,18 @@ cxl_find_region_by_range(struct cxl_root_decoder *c= xlrd, =20 int cxl_add_to_region(struct cxl_endpoint_decoder *cxled) { - struct range *hpa_range =3D &cxled->cxld.hpa_range; + struct cxl_region_context ctx; struct cxl_region_params *p; bool attach =3D false; int rc; =20 + ctx =3D (struct cxl_region_context) { + .cxled =3D cxled, + .hpa_range =3D cxled->cxld.hpa_range, + .interleave_ways =3D cxled->cxld.interleave_ways, + .interleave_granularity =3D cxled->cxld.interleave_granularity, + }; + struct cxl_root_decoder *cxlrd __free(put_cxl_root_decoder) =3D cxl_find_root_decoder(cxled); if (!cxlrd) @@ -3706,9 +3715,9 @@ int cxl_add_to_region(struct cxl_endpoint_decoder *cx= led) */ mutex_lock(&cxlrd->range_lock); struct cxl_region *cxlr __free(put_cxl_region) =3D - cxl_find_region_by_range(cxlrd, hpa_range); + cxl_find_region_by_range(cxlrd, &ctx.hpa_range); if (!cxlr) - cxlr =3D construct_region(cxlrd, cxled); + cxlr =3D construct_region(cxlrd, &ctx); mutex_unlock(&cxlrd->range_lock); =20 rc =3D PTR_ERR_OR_ZERO(cxlr); --=20 2.47.3