From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.53.2 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796444129; b=cbOB6pNNoww4adschA2wbNjkav0nyy+7ila3gd+CJv/b1F8vgyuxAbqOiW+VSUPz9s1h mKJ4SDP52ezih3fEtEKQotcQ+4UETXJeTTCrP65Hq0Wc1qOESlIsrZeLjhfpAIGOOqUZj uXN3Gf6kmBCHFKDR0nJ61Pk9LdtnyOYRxYejd7QqvR5X1tPhPi2uEJgbTnhRLExhEPJ3d 7n7YHQt2ulMHWZqS0eqhtbI0btLIb6vzTjj7xBnVHFezagdkwp0WjMMdlMgAQS67cSZaG 4MKcuIYv6iwZVc1UhGJ2vzGqN3ZfBo5wxLUN69HeaH1Jow7F+cYZOzwIfKu1tou6OOA== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796444129; h=DMARC-Filter:DKIM-Signature:Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References: Content-Transfer-Encoding:Content-Type:X-ClientProxiedBy:MIME-Version: X-MS-PublicTrafficType:X-MS-TrafficTypeDiagnostic: X-MS-Office365-Filtering-Correlation-Id:X-MS-Exchange-SenderADCheck: X-MS-Exchange-AntiSpam-Relay:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=yvhs+PnQADZ5HuGukT0RyIipd07UtLSDPLXWn5EFNyY=; b=ZLQ127MJ5Wm8DN9ToxEoe3m9YD1s7YRDBnHETh1wenBiNUhvUhAVSDGejuTBe+jxhnlu TZ55jW0uktyCQ7ue/BsFuJagNC0UPrH84KipOvM9uahbqjzyc9w+lR++mAmOU3b2+kL1T XGH+/4L0YoJYQa+G4n/8Hqs55sbWZIEbbpXd2o7e6z7BHDfZ70LzuMJlTO4t7y5KiTFd7 p8+IJK3OurlGIfVOJr/NyWauzTqx6qgEO6hf1TAFJXPkZO1rqJX7WE7leKpYw57lsYkGY F62+iWGqHA/HGpH9q2J33MyhZZoeSoI4+aHegjbqzvRXMQhVR7qWEz+dew8MFt7Y3Gg== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=qGmgfery; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.53.2 Received: from BL0PR03CU003.outbound.protection.outlook.com (mail-eastusazon11012002.outbound.protection.outlook.com [52.101.53.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 38700606A322; Sat, 5 Dec 2026 04:15:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 38700606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=qGmgfery ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=FAVCPloSvGJiUFDGxdZEuHd1W4UqpovNKHKO2MbP/ZEVtR9YWDiCeVzCXoax3heWMqD8P76MfEiJbkg4muwhDZ15SI6lUJex1E6wTXaWtzIocWiDXWUow9vjz3+JZo+PtMBXx6kNpzHZVf+jR0/Z+vqR2l7KZ1dllMKv4DV8UyAScDWWakehfZKm2wF1o93Uz6tWltuiaOqH2Elv+bkcOJUzs0me/0Y+2yLkLaUdmM9AxKNtL8mu4JQRGe3zsoBnJlrX9YtH9PYM8aqMI9M8WGZuQGhg/L+mpRJowvXjuDmJsIBLeohlqntfO0ukISYyV870e6p3nrfy1w0U69p/IQ== 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=yvhs+PnQADZ5HuGukT0RyIipd07UtLSDPLXWn5EFNyY=; b=KDA3dTQvlewY80s0hi6T2OSOi626Hv/z1NHPN6o7lv8xfyJbNL7gI0CEDpu/kbwpmRXR6erlktc4HmMId79JuTXbwnzS4hYJOKv0kG3J6GemdntdL7KXMFmYt/r9IS5zyGip3LanLmDV2EbFCmiVl7aC3D+PnErLsQsPmGYXSVV0P0xIzo+OZk1mALx9yBYFXOjhKNybNT5LFz+pdR4UUATaaKhD4ZqAhk5bKUIR/XNlocBrOlIYHMYTCnH/PWrg3aY7cwjlUuBJddqbLH8MLdt87Pe7ZK/vnLqQFhSfS++9exATsntYY137E5EG2rBewdpB5NKifqdKUoCOcHYfpA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yvhs+PnQADZ5HuGukT0RyIipd07UtLSDPLXWn5EFNyY=; b=qGmgferyTBrdEYot2JObwReTuehw5IqnxriTreQht/eO2ayFZaIs/i0MPaTm4bepydYQZLxZX9jqGdACQbDmKsyLlbREbHO3gEo3OcrPCuMqyjOGx8/IqoTrZfHsaJqqhv3/8URfmps3TiRqVDdn0d53rMGokEoDuFgjnPtHxlWUz7rhc3R5X8RBs4oF+GT3pdkXC0ptVKOGGUZ2mI6tFFgcWkm9G5K6W9CnPkpYmAzkic8SmHxUJQ3TwIKFBkfjxqfhQqHnq1Bytg612o+Yt5DXlck2thNP7kY/Q3XXvF74efcvQY0qxOEVnFVNJnUg3y94/fPlEv+wQLNMbOIk+A== Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DSVPR12MB827618.namprd12.prod.outlook.com (2603:10b6:8:3e5::24) by CY8PR12MB7489.namprd12.prod.outlook.com (2603:10b6:930:90::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.13; Sat, 5 Dec 2026 04:15:23 +0000 Received: from DSVPR12MB827618.namprd12.prod.outlook.com ([fe80::c673:6b00:5b48:b56f]) by DSVPR12MB827618.namprd12.prod.outlook.com ([fe80::c673:6b00:5b48:b56f%5]) with mapi id 15.21.0688.011; Sat, 5 Dec 2026 04:15:23 +0000 From: Srirangan Madhavan To: Alison Schofield , Bjorn Helgaas , Dave Jiang , Davidlohr Bueso , Ira Weiny , Jonathan Cameron , Vishal Verma , linux-cxl@vger.kernel.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Li Ming , Joshua Machauer , Alex Williamson , vsethi@nvidia.com, alwilliamson@nvidia.com, Sai Yashwanth Reddy Kancherla , Vishal Aslot , Manish Honap , Jiandi An , Richard Cheng , linux-tegra@vger.kernel.org, Alejandro Lucero Palau , Srirangan Madhavan Subject: [PATCH v18 05/19] cxl: Introduce endpoint HDM decoder settings Date: Sat, 5 Dec 2026 04:14:39 +0000 Message-ID: <20261205041453.3946529-6-smadhavan@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261205041453.3946529-1-smadhavan@nvidia.com> References: <20261205041453.3946529-1-smadhavan@nvidia.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SJ0PR03CA0126.namprd03.prod.outlook.com (2603:10b6:a03:33c::11) To LY0PR12MB727857.namprd12.prod.outlook.com (2603:10b6:408:3ba::5) X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DSVPR12MB827618:EE_|CY8PR12MB7489:EE_ X-MS-Office365-Filtering-Correlation-Id: 542ce44a-327f-4e67-a2f5-08df5286618e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|23010399003|366016|376014|7416014|22082099003|18002099003|6133799003|921020|56012099006|11063799006|261009223027099003|10067099003|261102123227099003|261021121427099003|261021123027099003|261026140227099003|261026121527099003|261028144727099003|261022113327099003|261022075727099003|261022105027099003; X-Microsoft-Antispam-Message-Info: PL3bhf8T6rxS4QixuirrMiOog67skMhlDfMc/xh7oG0oNfAhlUy4UZukU1d1SiPrAXmj0/nGtknqv8WvLrFLCNl1PhPDlMYdU3wSv1aK1RpC+3pjVhzTfG7EOM4cAL6YDCCnod4Xe1w4DjGNUQC7+EGSYzMlISKGyKMunekGbfuybgYMs6br/EHQpKBalS8Jy67YaIkopGQKeViX+Y/oDyZ/UgU28Z9DKT4RKyLqtVmQQx0U6RZ8TELH3Ol1JEboE10GcqgOUpF0G3h/411LmgtGINUEXUgQoZ9UwnL3KV0QqbRtptd/fWRM1cXSr4Laen5lbYPa6Rl7HIU+c3AAR6BhtM1i133gyMxxXVlmkhyJh3CItgQ092wvrbe1H4oRFBPsZLH1aL+tpE2wrM6oCgu4xFA5Qam4ffmuOUvwQBtaNfifsPObGPpIsLzbtR24T4yniINU1oROiRdGUJShzq8owoDikGOEbLvkCPBRNAKMQVi+Mb+S2Kl0sJ9PNyGP2yKvNRnc5DCmZhHq1DDtfs9lvVUpb+q142yWQxCd0EG+wSnc0f47ngz52KYtrFm9TUMCc0XRXRFIyEQexDhkUF/+BOF0VW/1daMeAaY4st43zREMWmny8fejpAZTHJqcuytVlWFE88CtJqJPdu/iw4sfMrHOuzjgXbmbh8xeD8vRDM/9QjeSuOY7KJkwqXr4QgS/QZekM2XWXTgE0bL/PA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DSVPR12MB827618.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(23010399003)(366016)(376014)(7416014)(22082099003)(18002099003)(6133799003)(921020)(56012099006)(11063799006)(261009223027099003)(10067099003)(261102123227099003)(261021121427099003)(261021123027099003)(261026140227099003)(261026121527099003)(261028144727099003)(261022113327099003)(261022075727099003)(261022105027099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?O26PpGtAylUHUslPX59JuQTJC/ALxP89s+gqdzEVFcopJQSRndrgXZWh4aQV?= =?us-ascii?Q?t/GJ2+HfuesFmLKQBI0xcTi7amT5ieYy8Lm4HOpJfRcw4ODoOb07XnV9idjr?= =?us-ascii?Q?9d393JR0kkUP4rzynMutDuZl2K00TyWAXuK6OL6NiQ6XF/Ak43+jUXV2yYpI?= =?us-ascii?Q?rozolCJLkkkuMylSWJVLS5lZfZywOB60ZKdcR7EbT1f91lPESn/3obkopn1j?= =?us-ascii?Q?3k36n5bX5g5ZjAEDTDNlgNwIubk0NcLFT39f0yqs5ArWSgZsWHOYAUzn2W6b?= =?us-ascii?Q?bzmEaWYxakCgjZ2okbU9jDrfwQAoZl0BWhrviS4GKbsHqPTIjSjePjkxMTnS?= =?us-ascii?Q?4rKMDpWILbFgaKu35oHq+xV21WhVFkZW/cyHzN5DBTNbsfyIwDzEDzLfoBGe?= =?us-ascii?Q?JAEkQVD4kgKFMTmpzOnOir/k3iSXpDjF5ZubNPyI1mk6GTJKRa2L/Qo1cBlE?= =?us-ascii?Q?gd/lJ7/Ziy2K7JhKcUOZT7sB6qMstEMR68ms1kTIr07etcwMVgspOsgPCY0l?= =?us-ascii?Q?hdb3U5ufOh9K/L8EpDXzQEsKPZfCDSJeh/qWA+oITWdlEXEfoEqzG3aYw8oa?= =?us-ascii?Q?EeQ8vQKp6htrP/mxbri+iR19XpnQIiQ4v55fpfs8sYmkv4lGJ6kegp7qbESn?= =?us-ascii?Q?saC0OYhT0HAcO5dKkYfBSn/Ogy+JjCJWgvY2pSO+v6HdBtzhCP1f1Y9yMCYj?= =?us-ascii?Q?lvshhlgZ9+QV74I07N6yYZsuWLuV3FV/G5h/g5bQXtaveNn+R0qB6oFkvd/b?= =?us-ascii?Q?HxL45IXK+wVzJL5kBT+Xsl3C0DqbD9gPEAQ0jztyhbXn7tXQdDsdzF+C4p+F?= =?us-ascii?Q?L+VLsqW/VOoE3ZFYtRuzeHti7SrZlHNu3nBPLwM09sejawB0KyrR/ntuc2gJ?= =?us-ascii?Q?QimFVja15uMQrRx9ph60E29XyaTjBbs+ldTqenBexQCGnI8J71KbCWf7B9su?= =?us-ascii?Q?YlYWlkH7G6mc+GNaRiFJFIoJPD1+XSF2dloAUJJxBz7VAb+RUBr61+WqG8Ni?= =?us-ascii?Q?nh/L0b89rQP0LRkvkXF9ORKIgnWOU38idKchDZDV5P+TfS1JZ5NvKPmy+9iD?= =?us-ascii?Q?tpqhzHS3N2hBV2nTQNR8sPl/llT06a9Dxp1mWIo/wjKgoKmczOE+z2XAwcdN?= =?us-ascii?Q?g0wOtbET6bKFyFxsltxSb1+5UOsskAcIYR7+LVi8OUt1EPBHAEv+Mt8ODUYL?= =?us-ascii?Q?5DmwCk0xsux77/SPe7EBVbU3Oy4/PI+UbfK4QSJUuztsfKiR+NEZYbq9DZG9?= =?us-ascii?Q?mwj/yfW3ptG69kgDJ5wNcM5MvCE+kVCg1V/lo5jXlB58SqitJ+VOFE/8xVjX?= =?us-ascii?Q?WzxyDjLTBLvxEe6ogQnRyUgaXQlHq86nixIoAgWYSSsNldt4C+Hyu/OiY/rk?= =?us-ascii?Q?+NgU+EJKFO1n+jEoUxUnyNAHSCmUIoBLUDC3WzBs+krizG/dqGb2VbDOd6qZ?= =?us-ascii?Q?iZAvXFwo5ikWVnXt5PZWuinbJ2vqdZ5l+Mc0izWC9ee/X8ObUp2y1lE7fapE?= =?us-ascii?Q?lA7P1ea62XtZe6y6e3fXql4QzCtQCyxBbCjKEVOY237dcDRm2m9HZILJ1ZGZ?= =?us-ascii?Q?jb0VvP4kobPSKH3iHRtb08eZ7kbmrHHldnkIjFXpR6iEue+ejZ+Eq5dam51k?= =?us-ascii?Q?MTQlLMqP3wQNonfuWKe3cXntgBAts9tPSA5KyzQ/PNrgPiJD2BSAWSjb9Zzf?= =?us-ascii?Q?8L4X7UF19XK4hJDWK8KgG26EWffTFHnSjMuhDWuvcqAQstP33CFImoxSSLU7?= =?us-ascii?Q?E4fLOUO+kg=3D=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 542ce44a-327f-4e67-a2f5-08df5286618e X-MS-Exchange-CrossTenant-AuthSource: LY0PR12MB727857.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Dec 2026 04:15:22.9962 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ObuR7pUBT+COvi4ef30qysx5gtgY6ie/EH3/TEhMIx24a4b9B9Em6AeXwwVTg8Jxhvp+8m8czGO1yjfZQu9E8w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7489 Keep common decoder configuration in cxl_decoder_config and represent endpoint DPA skip in cxl_endpoint_decoder_settings. Share range programming, but keep endpoint skip and switch target-list writes in their respective commit paths. Separate commit initiation from completion waiting so reset restoration can reuse register programming without changing normal DPA-lock policy. Signed-off-by: Srirangan Madhavan Reviewed-by: Dave Jiang Reviewed-by: Li Ming --- drivers/cxl/core/core.h | 8 ++++ drivers/cxl/core/hdm.c | 95 ++++++++++++++++++++++++++++------------- include/cxl/hdm.h | 19 +++++++++ 3 files changed, 92 insertions(+), 30 deletions(-) create mode 100644 include/cxl/hdm.h diff --git a/drivers/cxl/core/core.h b/drivers/cxl/core/core.h index ee639ac2c670..da40521171ca 100644 --- a/drivers/cxl/core/core.h +++ b/drivers/cxl/core/core.h @@ -7,6 +7,8 @@ #include #include +struct cxl_endpoint_decoder_settings; + extern const struct device_type cxl_nvdimm_bridge_type; extern const struct device_type cxl_nvdimm_type; extern const struct device_type cxl_pmu_type; @@ -139,6 +141,12 @@ struct cxl_rwsem { extern struct cxl_rwsem cxl_rwsem; +void cxl_commit_start_endpoint(const struct cxl_endpoint_decoder_settings *settings, + void __iomem *hdm); +void cxl_commit_start_switch(const struct cxl_decoder_config *config, + u64 targets, void __iomem *hdm); +int cxld_await_commit(void __iomem *hdm, int id); + int cxl_memdev_init(void); void cxl_memdev_exit(void); void cxl_mbox_init(void); diff --git a/drivers/cxl/core/hdm.c b/drivers/cxl/core/hdm.c index 01c6455e1581..89261ec3595f 100644 --- a/drivers/cxl/core/hdm.c +++ b/drivers/cxl/core/hdm.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "cxlmem.h" #include "core.h" @@ -732,7 +733,7 @@ int cxl_dpa_alloc(struct cxl_endpoint_decoder *cxled, u64 size) return devm_add_action_or_reset(&port->dev, cxl_dpa_release, cxled); } -static void cxld_set_interleave(struct cxl_decoder *cxld, u32 *ctrl) +static void cxld_set_interleave(const struct cxl_decoder_config *config, u32 *ctrl) { u16 eig; u8 eiw; @@ -741,12 +742,12 @@ static void cxld_set_interleave(struct cxl_decoder *cxld, u32 *ctrl) * Input validation ensures these warns never fire, but otherwise * suppress unititalized variable usage warnings. */ - if (WARN_ONCE(ways_to_eiw(cxld->config.interleave_ways, &eiw), - "invalid interleave_ways: %d\n", cxld->config.interleave_ways)) + if (WARN_ONCE(ways_to_eiw(config->interleave_ways, &eiw), + "invalid interleave_ways: %d\n", config->interleave_ways)) return; - if (WARN_ONCE(granularity_to_eig(cxld->config.interleave_granularity, &eig), + if (WARN_ONCE(granularity_to_eig(config->interleave_granularity, &eig), "invalid interleave_granularity: %d\n", - cxld->config.interleave_granularity)) + config->interleave_granularity)) return; u32p_replace_bits(ctrl, eig, CXL_HDM_DECODER0_CTRL_IG_MASK); @@ -754,10 +755,10 @@ static void cxld_set_interleave(struct cxl_decoder *cxld, u32 *ctrl) *ctrl |= CXL_HDM_DECODER0_CTRL_COMMIT; } -static void cxld_set_type(struct cxl_decoder *cxld, u32 *ctrl) +static void cxld_set_type(const struct cxl_decoder_config *config, u32 *ctrl) { u32p_replace_bits(ctrl, - !!(cxld->config.target_type == CXL_DECODER_HOSTONLYMEM), + !!(config->target_type == CXL_DECODER_HOSTONLYMEM), CXL_HDM_DECODER0_CTRL_HOSTONLY); } @@ -789,7 +790,7 @@ static void cxlsd_set_targets(struct cxl_switch_decoder *cxlsd, u64 *tgt) * clock skew and other marginal behavior */ #define COMMIT_TIMEOUT_MS 20 -static int cxld_await_commit(void __iomem *hdm, int id) +int cxld_await_commit(void __iomem *hdm, int id) { u32 ctrl; int i; @@ -809,45 +810,79 @@ static int cxld_await_commit(void __iomem *hdm, int id) return -ETIMEDOUT; } -static void setup_hw_decoder(struct cxl_decoder *cxld, void __iomem *hdm) +static u32 cxl_hdm_write_range(void __iomem *hdm, + const struct cxl_decoder_config *config) { - int id = cxld->config.id; - u64 base, size; + u64 size = range_len(&config->hpa_range); + u64 base = config->hpa_range.start; + int id = config->id; u32 ctrl; - /* common decoder settings */ - ctrl = readl(hdm + CXL_HDM_DECODER0_CTRL_OFFSET(cxld->config.id)); - cxld_set_interleave(cxld, &ctrl); - cxld_set_type(cxld, &ctrl); - base = cxld->config.hpa_range.start; - size = range_len(&cxld->config.hpa_range); + ctrl = readl(hdm + CXL_HDM_DECODER0_CTRL_OFFSET(id)); + cxld_set_interleave(config, &ctrl); + cxld_set_type(config, &ctrl); writel(upper_32_bits(base), hdm + CXL_HDM_DECODER0_BASE_HIGH_OFFSET(id)); writel(lower_32_bits(base), hdm + CXL_HDM_DECODER0_BASE_LOW_OFFSET(id)); writel(upper_32_bits(size), hdm + CXL_HDM_DECODER0_SIZE_HIGH_OFFSET(id)); writel(lower_32_bits(size), hdm + CXL_HDM_DECODER0_SIZE_LOW_OFFSET(id)); + return ctrl; +} + +void cxl_commit_start_endpoint(const struct cxl_endpoint_decoder_settings *settings, + void __iomem *hdm) +{ + int id = settings->config.id; + u32 ctrl; + + lockdep_assert_held(&cxl_rwsem.dpa); + ctrl = cxl_hdm_write_range(hdm, &settings->config); + writel(upper_32_bits(settings->skip), hdm + CXL_HDM_DECODER0_SKIP_HIGH(id)); + writel(lower_32_bits(settings->skip), hdm + CXL_HDM_DECODER0_SKIP_LOW(id)); + writel(ctrl, hdm + CXL_HDM_DECODER0_CTRL_OFFSET(id)); +} + +void cxl_commit_start_switch(const struct cxl_decoder_config *config, + u64 targets, void __iomem *hdm) +{ + int id = config->id; + u32 ctrl; + + lockdep_assert_held(&cxl_rwsem.dpa); + ctrl = cxl_hdm_write_range(hdm, config); + writel(upper_32_bits(targets), hdm + CXL_HDM_DECODER0_TL_HIGH(id)); + writel(lower_32_bits(targets), hdm + CXL_HDM_DECODER0_TL_LOW(id)); + writel(ctrl, hdm + CXL_HDM_DECODER0_CTRL_OFFSET(id)); +} + +static void +cxl_endpoint_decoder_snapshot(struct cxl_endpoint_decoder *cxled, + struct cxl_endpoint_decoder_settings *settings) +{ + lockdep_assert_held(&cxl_rwsem.dpa); + + *settings = (struct cxl_endpoint_decoder_settings) { + .config = cxled->cxld.config, + .skip = cxled->skip, + }; +} + +static void setup_hw_decoder(struct cxl_decoder *cxld, void __iomem *hdm) +{ + struct cxl_endpoint_decoder_settings settings; if (is_switch_decoder(&cxld->dev)) { struct cxl_switch_decoder *cxlsd = to_cxl_switch_decoder(&cxld->dev); - void __iomem *tl_hi = hdm + CXL_HDM_DECODER0_TL_HIGH(id); - void __iomem *tl_lo = hdm + CXL_HDM_DECODER0_TL_LOW(id); u64 targets; cxlsd_set_targets(cxlsd, &targets); - writel(upper_32_bits(targets), tl_hi); - writel(lower_32_bits(targets), tl_lo); + cxl_commit_start_switch(&cxld->config, targets, hdm); } else { - struct cxl_endpoint_decoder *cxled = - to_cxl_endpoint_decoder(&cxld->dev); - void __iomem *sk_hi = hdm + CXL_HDM_DECODER0_SKIP_HIGH(id); - void __iomem *sk_lo = hdm + CXL_HDM_DECODER0_SKIP_LOW(id); - - writel(upper_32_bits(cxled->skip), sk_hi); - writel(lower_32_bits(cxled->skip), sk_lo); + cxl_endpoint_decoder_snapshot(to_cxl_endpoint_decoder(&cxld->dev), + &settings); + cxl_commit_start_endpoint(&settings, hdm); } - - writel(ctrl, hdm + CXL_HDM_DECODER0_CTRL_OFFSET(id)); } static int cxl_decoder_commit(struct cxl_decoder *cxld) diff --git a/include/cxl/hdm.h b/include/cxl/hdm.h new file mode 100644 index 000000000000..219b9bb67440 --- /dev/null +++ b/include/cxl/hdm.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright (c) 2026 NVIDIA Corporation & Affiliates */ +#ifndef __CXL_HDM_H__ +#define __CXL_HDM_H__ + +#include +#include + +/** + * struct cxl_endpoint_decoder_settings - endpoint HDM decoder programming + * @config: common decoder configuration + * @skip: length of DPA space skipped before this decoder's DPA mapping + */ +struct cxl_endpoint_decoder_settings { + struct cxl_decoder_config config; + u64 skip; +}; + +#endif /* __CXL_HDM_H__ */ -- 2.43.0