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.72.30 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796406707; b=RWSlluVwUhZp5FcOlu7/9VSwJ33aHAlexQJFDbaVORbrXZ6wCxUiQEpaA+PCmNv45MEZ MHheZ/Jz5VLJH11r4NzQqMEJzKhd5xrSuxVfKArLH27JJPMha4FWWqpqvntW3pBKKAAtg 9DQgWegyz2UH0IZZZKTzEuhKKr/NCh0jrBKRaPQrbxo/jqNA/+1q1HsCg44bWXqXp3SMB mU1Z23PoSZgBl03Cpi5oiCj27k2co5oVcOlELbtT353beKIpqMdzMvuy7U2bEsaVODGdD 0GXX+lmg79VEuLi+ZLJUEJwzCrrzfgJb8UlRLfzrTe1ChaRIaJ9Ae2LHbCCl+yCYQ6A== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796406707; h=DMARC-Filter:DKIM-Signature:Received:Received:Date:From:To:Cc: Subject:Message-ID:References:Content-Type:Content-Disposition: In-Reply-To:X-ClientProxiedBy:MIME-Version:X-MS-PublicTrafficType: X-MS-TrafficTypeDiagnostic:X-MS-Office365-Filtering-Correlation-Id: X-LD-Processed: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=lbXCI5ORfdIyxd0eKL3BFsmipZLRY6vtv0/rpfPYVI0=; b=IJwr5SWdX4nUCNP+YqFCreAdAkSjLSYqwdS6OG4C6ApzdRNy6fhDPMbq265/miRvKLp5 fwfgRxIfhCVN8iMc8Ngx4Xaff77Ip/9VzRYHwmNdI/YatHf996X2msgXVbtg5UkRfU/w+ t5CPo47JbqmilslCC2vL4uYVe3aHl7LtHVxGNEJ+Oq+5M+eJyb8ZHUIE/gQoRLwjtFMxs a5Hs6AKO5iq8G0z+VoH9/u0Kgp0QxKlVAgFrT4ueDaFZeEk74sNXU7UNTalG7bU7BddkX x76HfeqTNaXiYsvHsH3k23xq3FuODnWAO6LCKblMxy/CyAqaeegYNQpmnjrUDxiS2WQ== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=oss.nxp.com; spf=pass smtp.mailfrom=oss.nxp.com; dkim=pass header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.a=rsa-sha256 header.s=selector1-NXP1-onmicrosoft-com header.b="okLMU4B/"; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.72.30 Received: from AM0PR02CU008.outbound.protection.outlook.com (mail-westeuropeazon11013030.outbound.protection.outlook.com [52.101.72.30]) (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 EA874606A322; Fri, 4 Dec 2026 17:51:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org EA874606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.a=rsa-sha256 header.s=selector1-NXP1-onmicrosoft-com header.b=okLMU4B/ ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=SPtiWsfUfhPisQdCOqwrSLkptOHFTSvOSLstsKoawsji5H5P843C3yxEuF5rkVBA43d04reRyHvflBm4UvToJcv2AuQN30SnjJsQE5I4ywnUITwEcicbuW/ShCt92t8BPLSUX5a3/pOl5HnHEkuyZ+7qdAtJKVrcBTD/HpdrW1RAL/xeYoxj/b6jGmawwS9jn5j/sLO5X3SuP0A4pjsqejRDXI4MnBNEuzmLsqQ1wCnEkP87tpa0R4mrbEMXekCXp8MSDO40jwubhJLyTHo2r0UerrFteLrHXYlhch7ahsTdNxeZhUZhixp07alS61aAkIduhyioWCMyN6jxNwJhhQ== 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=lbXCI5ORfdIyxd0eKL3BFsmipZLRY6vtv0/rpfPYVI0=; b=kbw0PkmgGQiOr19AFqAr3DSujdnNl5wvre7YTNHFcEvWZn1FVQtbQpHZh00LffsRwYK0Q8DSoMHEUVZJojJY+kXNZf9VlUZebSqWLfz7psYFrr11LFToGMDbV5Sh++Pxq8wLHWXqvXl8HFNaO0EHNPfJfdVLQTt8dZwjf1AM5GPsUEwANftMCaTbCxOd0tHvGZ7Hg8Ad86HXiB2Qr6uCNuQnPqbK+W8lpwF0uu8nwywTWIA1VQBG3fe70JhgF0TrB80GIfM4/UEAPqDtgkTEkyECA1GEIgOVgzly0PA/17IatB5KWiY/GrB7sRSOxR5qf5lCMNWloeNk23q+mGjlSQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector1-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lbXCI5ORfdIyxd0eKL3BFsmipZLRY6vtv0/rpfPYVI0=; b=okLMU4B/K3NpEd7qvImdcRGW9e8JU9Qke+xS5OOmH1A86d40IciZf5vXBCOnHTZeJ7Zv+e9X1YzknkIEGOTTlI0TotDdKC8PN6AhD3KgmqnTlOVoPj7QCwvgLRfdAelwj9CSBuraqww5xtuixoHrL1xvEhZiSp0p8Cr/g92MpiCFBP+wlLAUoVgAqQ6aIEHy6iR6Ly7p3oAkDM5QdlofJDaGBXWw9/jMN+CFnVdIUuYO/oA6mbCIUFFfwZe6f6rtrofqSnJXed3RjQZaJZ3ydYdoWrYR0+c2tF/QYbMYX4gnSWTtCOHa6P4rBZvAmOAPN+MKhvEKmZe4L646K/xF2w== Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from MI3PR04MB12438.eurprd04.prod.outlook.com (2603:10a6:290:76::14) by DB9PR04MB9555.eurprd04.prod.outlook.com (2603:10a6:10:303::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.10; Fri, 4 Dec 2026 17:51:41 +0000 Received: from MI3PR04MB12438.eurprd04.prod.outlook.com ([fe80::c715:c32:8bb1:b70b]) by MI3PR04MB12438.eurprd04.prod.outlook.com ([fe80::c715:c32:8bb1:b70b%4]) with mapi id 15.21.0688.009; Fri, 4 Dec 2026 17:51:41 +0000 Date: Fri, 4 Dec 2026 11:51:31 -0600 From: Frank Li To: ghennadi.procopciuc@oss.nxp.com Cc: Thomas Gleixner , Krzysztof Kozlowski , Sascha Hauer , Rob Herring , Frank Li , Conor Dooley , Pengutronix Kernel Team , imx@lists.linux.dev, devicetree@vger.kernel.org, NXP S32 Linux Team , linux-kernel@vger.kernel.org, Fabio Estevam , Radu Rendec , linux-arm-kernel@lists.infradead.org, echanude@redhat.com, clizzi@redhat.com, aruizrui@redhat.com, eballetb@redhat.com Subject: Re: [PATCH 2/6] irqchip: Add NXP S32N79 MRU MSI controller driver Message-ID: References: <20261204-b4-s32n79-mru-msi-v1-0-e66f9b0dfa79@oss.nxp.com> <20261204-b4-s32n79-mru-msi-v1-2-e66f9b0dfa79@oss.nxp.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261204-b4-s32n79-mru-msi-v1-2-e66f9b0dfa79@oss.nxp.com> X-ClientProxiedBy: CPCP307CA0005.DNKP307.PROD.OUTLOOK.COM (2603:10a6:380::14) To MI3PR04MB12438.eurprd04.prod.outlook.com (2603:10a6:290:76::14) X-Mailing-List: devicetree@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: MI3PR04MB12438:EE_|DB9PR04MB9555:EE_ X-MS-Office365-Filtering-Correlation-Id: c2ce3b64-7236-4329-dabd-08df522f408e X-LD-Processed: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|23010399003|7416014|1800799024|19092799006|261102130727099003|56012099006|10067099003|261022075727099003|11063799006|261022105027099003|261026140227099003|261026121527099003|261022113327099003|261021121427099003|261028144727099003|261102123227099003|261009223027099003|18002099003|22082099003|4143699003|6133799003; X-Microsoft-Antispam-Message-Info: 03OjkJKWZzL1l8Vd6odnbDgVE1TVP2RuYFYG971SM6sgqnlnf06ggy/hSnKkGFatua4a6a218hRe+BDtcKNRM1WFS9RME2U4rpiWXcnEXvDygjbqOUInTIW5TUijpHCyBMwcy6LyKjvmvD+WToIOgr4KOzOMM5xJ8EoTrBTNMt9a8KZwvis/t5av3HqNkYDEj4yc0WOxA1alEW9tJjfFs5EIDxY7xR0MJQIUqSycyZEwPBkYa0eMErfu31Q8SOKF0aq8N03rKqA6eMUoLB6AIHdv0+6M6aWmEJfsvrZl5jbRzllgavJPseci4JicVaCNFY6dZEgjbpR0c4kC6ZEXvdYmU19cPQmhtBhR9uvMoC8Rg1nMrxcfKmSWEslj9tJKdwgU3s45H7NjH4hhuWgqFG8ilG5u/Od7UKb9jdmAqNSDbah9UnA7Mq5hrFoyshPbDImm4BcTbEu6pJylNVOqCv/RZddswkqAza3NKAYjDTAciDFcn92MBdk6tACIFp/ENUe9tDO2wnAzmvpV/3Vviq9WI0hwBopdMfxbdkWRJuQuPcbqzyrnx4ORHfYzjw93NybiG0wO0jPwTFsYgrPg8aSwBuxeZljeQWCeIHqfsVV3anyBYBadtcMp/FetG4JgE+h8+n8YOPo52gKBxjGtKR79L0zVwzzBSiszgscpkCM= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MI3PR04MB12438.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(376014)(23010399003)(7416014)(1800799024)(19092799006)(261102130727099003)(56012099006)(10067099003)(261022075727099003)(11063799006)(261022105027099003)(261026140227099003)(261026121527099003)(261022113327099003)(261021121427099003)(261028144727099003)(261102123227099003)(261009223027099003)(18002099003)(22082099003)(4143699003)(6133799003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?X8oHaLUP9YLjiBwNgKN1gvOInoyeCVlnw0Sq5hEmcCocWIPrMab3Ac2N+4Zb?= =?us-ascii?Q?cwdgupDXW8lq9zEks/WFPl/N0FcdzQFvx8NY6piCVazreCe7PDtP3iZJwyaS?= =?us-ascii?Q?iV71CPcOC5e7lq7svFfQoMiREAISajQn60CeNLfnS/jvF/gNNU1xzzHH7ViD?= =?us-ascii?Q?7hLtGmQyKM9fhlpC7uG8K6cMq/RWyuFLrfJLAzXyxMoEWeV4V1l4n2VuCuJd?= =?us-ascii?Q?l5r5BbVOYFIOvvRrMicLW+NXcvExixIlytc5asOLo7Ea8R0k1lIxP8lVGb6l?= =?us-ascii?Q?YtI0lGytxMdI85mrDpxZUqblYBrhYtuZ8EQ5ySWEkhFX1KyK1VB8cxnSfRpW?= =?us-ascii?Q?glDwyLMX99gzxvUjgQoCO190VHnyfavM2Fi9su/BLPpUwfbYe4IyRiwJjERL?= =?us-ascii?Q?BoN3JmofHKVa8vGNHonuHtCWo839TSmKxEuNo8Tzz7RY4J5KeyY3qr8iTdTo?= =?us-ascii?Q?1oa1D3YiE8xOu87NRJKPTj0Q6COFBDchjDMYdhvzs9z9YUjEg2g8IIjKJ5Ij?= =?us-ascii?Q?8JmMzTw2upCjh9s0Fsp1QwfWJ/BE2b/6BxPrt4XrsjyVm9DTaWc/UG8xccK1?= =?us-ascii?Q?UpOszChbLJhC5+2e1DhPFOHAwKfzOkAtwwt4rERZAaXSSKY3Klwzjik0Amwo?= =?us-ascii?Q?ZUdJkyj76QWEAuOdbab7YNIp5Ta8bAOhXyODanodmrVKmhNPdDYT9ppKVogu?= =?us-ascii?Q?4ew8ycuzQgCMLuYLGn4eloJts4oHOhtkdb37mTDZCyvqKSsVZidrJy5XkBqw?= =?us-ascii?Q?Og1SAq5qBAjsUWuZ9e6HHxnmg6xHZvA0BB/F53I9PBfiEdppxKExBq+X+7ww?= =?us-ascii?Q?gL/rR/QStzBSANyLoJET2/9SC1jp/vUjWNHZdT0ZmMD5oEj0Bz4/jOnn+QG0?= =?us-ascii?Q?M311T2IIjnGbx8QUf9HDNc0+iBENXO0tNtYCJGt5R/8XUh4mMZmDiToSdEwq?= =?us-ascii?Q?9EoYOR4LdoRgUnByhp1TCX9XB0TdCW8gc9YbsaLrGAw5HbPnyq3+K027kQmd?= =?us-ascii?Q?NYja2u9d7I2f63EaZZNhwHsSZS4fMu+4KcX7IgGdpPTeC0bU2umfE3Cft/hR?= =?us-ascii?Q?yGlMmcJIX7C8th9eMqBwpjxWBxFL06sLdMxGpgsL3Buq/qIfH5W0bWW0yKJq?= =?us-ascii?Q?yvpeqdr3WZco81hsTrF9ug3+pfgvJK+5+r8uHjjW5gz/aeg6rBHPCu2kbHDw?= =?us-ascii?Q?UA3V8T22vRowMwviYYqVu+1lYiPeHxm/6rlHrseW/6HbbnHedlGZlNMbLn0V?= =?us-ascii?Q?Os8jVWLjDsCTdOX8eqHsw90hSJbX3Bzz0rtv9RbKMaqPjzG7plqB0ilpMrLY?= =?us-ascii?Q?Jnm5N+dW/dmWMNSdAu7VIv2uV/h0tnYFGM3o6RZtJGEhu98LZv3XZR3G82pr?= =?us-ascii?Q?IvL7+NH6uzrHwZQ8ofL+WcFPW/4opirGYS/sG1ThDzUGYZXPvz03X8mVPnSb?= =?us-ascii?Q?cFe4YorMKaqRrQnjJsun0M0gKpGyMHK9EyXk0WY/hqGk9cSDHuNBMUzWeh0a?= =?us-ascii?Q?1faW1kZmJPwWhuKnazb3d/0H6zDOkFVsTtbaB7f/oN5EnmQsDUOBDCQ6Iw8y?= =?us-ascii?Q?A0V8hmRIstSmHCerJbK3TGbbhMbCPEjpD8Qja6WtzTsXNWLtSo85n+eYCDWU?= =?us-ascii?Q?SljSeQMBAujhhE1CoR8CUDGOE0Op6A55b93PcuCujNxHWY4ArDb+8ER8bwvE?= =?us-ascii?Q?GZMXDk+LDPqade5wmNi3kk4BoN3lpLkn/3OvE9KryZZS+/UEEGVotssoXS35?= =?us-ascii?Q?E2Sr4x5GCDgl7t6YuHN/ZWLEDqmDb90xEveiqoAEQ42fu1W0Eq2Y?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: c2ce3b64-7236-4329-dabd-08df522f408e X-MS-Exchange-CrossTenant-AuthSource: MI3PR04MB12438.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Dec 2026 17:51:41.2485 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: cm9QAhEsT5ozSaygZJcETqmCdlSrKNApWTQNtcng+gq/3+pwezv6AmzTIxIXJ1tCEkyhmbH0L9EM2BIInV1ozNCqH2G9jC+ukJoTpNK2Ba9lSdXWV2ggbbOwSLgb0oh/ X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB9555 On Fri, Dec 04, 2026 at 02:56:47PM +0200, Ghennadi Procopciuc via B4 Relay wrote: > [You don't often get email from devnull+ghennadi.procopciuc.oss.nxp.com@kernel.org. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ] > > From: Ghennadi Procopciuc > > On S32N79, a hardware erratum prevents the MSI writes of the integrated > NETC endpoints from being translated by the GIC ITS. Add a driver that > uses the Message Receive Unit (MRU) blocks as the MSI controller for > these endpoints instead. > > Each MRU has three channels. A write to the first mailbox of a channel > sets its status bit and raises the channel interrupt, and the channel > interrupts of an MRU are ORed into one GIC SPI. A chained handler reads > the status of the channels, clears it and dispatches the vector of every > channel with a pending message. The status is cleared before the > dispatch, because the vector may run later on another CPU. > > Each vector gets a channel of its own. The channels sit in separate > 64 KiB pages, so PCI functions that are isolated by the IOMMU cannot > write to each other's mailboxes. The channels of all the MRUs are handed > out channel index first, so consecutive vectors land on different MRUs > and do not share an SPI. > > Since the channels of an MRU share one SPI, per-vector affinity uses the > interrupt redirection for demultiplexed interrupts: if the SPI is taken > on a CPU outside the affinity mask of a vector, the vector handler runs > from irq_work on a CPU that is in the mask. The SPIs of the MRUs are > spread over the online CPUs at probe. > > When the endpoint sits behind an IOMMU, the mailbox page is mapped with > iommu_dma_prepare_msi(). That helper is not exported, so the driver can > only be built in. It is enabled by default on ARCH_S32, because the NETC > endpoints have no working MSI parent without it. > > Signed-off-by: Ghennadi Procopciuc > --- > drivers/irqchip/Kconfig | 21 +++ > drivers/irqchip/Makefile | 1 + > drivers/irqchip/irq-mru-msi.c | 402 ++++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 424 insertions(+) > > diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig > index 136bab41f801..b80243d09791 100644 > --- a/drivers/irqchip/Kconfig > +++ b/drivers/irqchip/Kconfig > @@ -852,4 +852,25 @@ config IRQCHIP_XILINX_SMMU_CSR > ZynqMP-class platforms where a vendor CSR block mediates SMMU > interrupts. > > +config NXP_MRU_MSI > + bool "NXP S32N79 MRU MSI controller" > + depends on ARCH_S32 || COMPILE_TEST > + depends on OF && PCI_MSI > + default ARCH_S32 > + select GENERIC_IRQ_EFFECTIVE_AFF_MASK if SMP > + select IRQ_DOMAIN_HIERARCHY > + select IRQ_MSI_IOMMU > + select IRQ_MSI_LIB > + help > + Support for the Message Receive Unit (MRU) block of the NXP S32N79 > + used as an MSI and MSI-X controller. The mailboxes of the MRU > + instances are the targets of the MSI writes of PCI devices, and > + the channel interrupts are forwarded to the GIC as SPIs. > + > + The integrated NETC endpoints of the S32N79 need it, because > + their MSI writes do not reach the GIC ITS. > + > + This driver cannot be built as a module because the IOMMU MSI > + mapping helper it calls is not exported. > + > endmenu > diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile > index 16a5fd126c9a..379781d3e2b3 100644 > --- a/drivers/irqchip/Makefile > +++ b/drivers/irqchip/Makefile > @@ -136,3 +136,4 @@ obj-$(CONFIG_MCHP_EIC) += irq-mchp-eic.o > obj-$(CONFIG_SOPHGO_SG2042_MSI) += irq-sg2042-msi.o > obj-$(CONFIG_SUNPLUS_SP7021_INTC) += irq-sp7021-intc.o > obj-$(CONFIG_IRQCHIP_XILINX_SMMU_CSR) += irq-xilinx-smmu-csr.o > +obj-$(CONFIG_NXP_MRU_MSI) += irq-mru-msi.o > diff --git a/drivers/irqchip/irq-mru-msi.c b/drivers/irqchip/irq-mru-msi.c > new file mode 100644 > index 000000000000..13d184b2ca2c > --- /dev/null > +++ b/drivers/irqchip/irq-mru-msi.c > @@ -0,0 +1,402 @@ > +// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause > +/* > + * Copyright 2025 NXP > + * > + * This driver exposes a set of Message Receive Units (MRUs) as an MSI > + * controller. Each MRU is organized into multiple channels, and each channel > + * contains a mailbox. A write to the first mailbox of a channel raises the > + * interrupt of that channel. > + * > + * The channel interrupts of an MRU are ORed into a single SPI, which a chained > + * handler demultiplexes. All the channels of all the MRUs are tracked in one > + * bitmap, ordered by channel index first: > + * > + * ----------------||---------------||----------------- > + * Bitmap bits | 0 | 1 | 2 | 3 || 4 | 5 | 6 | 7 || 8 | 9 | 10 | 11 | > + * ----------------||---------------||----------------- > + * MRU Index 0 1 2 3 || 0 1 2 3 || 0 1 2 3 > + * Channel index 0 0 0 0 || 1 1 1 1 || 2 2 2 2 > + * > + * Assumptions for the example above: > + * - Number of MRUs: 4 > + * - Number of channels per MRU: 3 > + * > + * The channels are handed out in bitmap order, so consecutive vectors land on > + * different MRUs and therefore on different SPIs. The redirection only moves > + * the vector handler to a CPU in its affinity mask: the SPI is still taken and > + * demultiplexed on the CPU it is routed to. Spreading the vectors over the > + * SPIs keeps that work from piling up on a single CPU. > + */ Add empty line here. > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#define MRU_CHANS_PER_MRU 3 > + > +/* Each channel has a 16 byte block of control registers. */ > +#define MRU_CH_STRIDE 0x10 > +#define MRU_CH_CFG0 0x0 > +#define MRU_CH_MBSTAT 0x8 > + > +#define MRU_CFG0_CHE BIT(0) > +#define MRU_CFG0_CHR BIT(1) > +#define MRU_CFG0_IE BIT(2) > +#define MRU_CFG0_MBE0 BIT(16) > + > +#define MRU_MBSTAT_MBS0 BIT(16) > + > +/* > + * The first 64 KiB page holds the channel controls. The mailboxes of channel n > + * start at the page n + 1. > + */ > +#define MRU_PAGE_SIZE SZ_64K > +#define MRU_REGION_SIZE ((MRU_CHANS_PER_MRU + 1) * MRU_PAGE_SIZE) > + > +struct mru_msi; > + > +struct mru { > + struct mru_msi *priv; > + void __iomem *base; > + phys_addr_t addr; > + unsigned int index; > + int irq; > +}; > + > +struct mru_msi { > + struct irq_domain *domain; > + unsigned long *chans_bitmap; > + struct device *dev; > + struct mru *mrus; > + unsigned int nmrus; > + unsigned int nchans; > +}; > + > +static unsigned int mru_pos2mru(const struct mru_msi *priv, unsigned int pos) > +{ > + return pos % priv->nmrus; > +} > + > +static unsigned int mru_pos2chan(const struct mru_msi *priv, unsigned int pos) > +{ > + return pos / priv->nmrus; > +} > + > +static unsigned int mru_mru2pos(const struct mru_msi *priv, unsigned int mru, > + unsigned int chan) > +{ > + return chan * priv->nmrus + mru; > +} > + > +static void __iomem *mru_chan_base(const struct mru_msi *priv, > + unsigned int pos) > +{ > + const struct mru *mru = &priv->mrus[mru_pos2mru(priv, pos)]; > + > + return mru->base + mru_pos2chan(priv, pos) * MRU_CH_STRIDE; > +} > + > +static phys_addr_t mru_mailbox_phys(const struct mru_msi *priv, > + unsigned int pos) > +{ > + const struct mru *mru = &priv->mrus[mru_pos2mru(priv, pos)]; > + > + return mru->addr + (mru_pos2chan(priv, pos) + 1) * MRU_PAGE_SIZE; > +} > + > +/* > + * The channel registers ignore writes while CHE is clear, so CHE has to be set > + * by a write of its own before the other bits can be changed. Only CHE and > + * CHR are writable while CHE is clear. > + */ > +static void mru_chan_enable(void __iomem *chan) > +{ > + u32 cfg0 = readl(chan + MRU_CH_CFG0); > + > + cfg0 |= MRU_CFG0_CHE; > + writel(cfg0, chan + MRU_CH_CFG0); > + > + /* > + * Only mailbox 0 is enabled. The mailboxes of a channel sit in one > + * IOMMU page, so a device that may write one of them may write all > + * of them. Every vector therefore gets a channel of its own. > + */ > + cfg0 |= MRU_CFG0_MBE0; > + writel(cfg0, chan + MRU_CH_CFG0); > + > + /* > + * A message left from before the channel was disabled would raise the > + * interrupt as soon as IE is set. > + */ > + writel(MRU_MBSTAT_MBS0, chan + MRU_CH_MBSTAT); > + > + cfg0 |= MRU_CFG0_IE; > + writel(cfg0, chan + MRU_CH_CFG0); > +} > + > +static void mru_chan_disable(void __iomem *chan) > +{ > + u32 cfg0 = readl(chan + MRU_CH_CFG0); > + > + cfg0 &= ~MRU_CFG0_IE; > + writel(cfg0, chan + MRU_CH_CFG0); > + > + cfg0 &= ~MRU_CFG0_MBE0; > + writel(cfg0, chan + MRU_CH_CFG0); > + > + cfg0 &= ~MRU_CFG0_CHE; > + writel(cfg0, chan + MRU_CH_CFG0); > +} > + > +/* > + * The chained handler clears the status of the channel before it dispatches > + * the vector. The vector can run later on another CPU, and by then the next > + * message must be able to raise the SPI again. The flow handler of the device > + * domain still needs an irq_ack() to call. > + */ > +static void mru_msi_irq_ack(struct irq_data *d) > +{ > +} > + > +static void mru_msi_compose_msg(struct irq_data *d, struct msi_msg *msg) > +{ > + struct mru_msi *priv = irq_data_get_irq_chip_data(d); > + > + msi_msg_set_addr(irq_data_get_msi_desc(d), msg, > + mru_mailbox_phys(priv, d->hwirq)); > + msg->data = 0; > +} > + > +static const struct irq_chip mru_msi_parent_chip = { > + .name = "MRU", > + .irq_ack = mru_msi_irq_ack, > + .irq_compose_msi_msg = mru_msi_compose_msg, > +#ifdef CONFIG_SMP > + .irq_set_affinity = irq_chip_redirect_set_affinity, > +#endif > +}; > + > +static int mru_msi_domain_alloc(struct irq_domain *domain, unsigned int virq, > + unsigned int nr_irqs, void *args) > +{ > + struct mru_msi *priv = domain->host_data; > + msi_alloc_info_t *info = args; > + unsigned int pos; > + int ret; > + > + lockdep_assert_held(&domain->root->mutex); > + > + if (WARN_ON_ONCE(nr_irqs != 1)) > + return -EINVAL; > + > + pos = find_first_zero_bit(priv->chans_bitmap, priv->nchans); > + if (pos >= priv->nchans) > + return -ENOSPC; > + > + ret = iommu_dma_prepare_msi(info->desc, mru_mailbox_phys(priv, pos)); > + if (ret) > + return ret; > + > + __set_bit(pos, priv->chans_bitmap); > + > + irq_domain_set_info(domain, virq, pos, &mru_msi_parent_chip, priv, > + handle_edge_irq, NULL, NULL); > + > + mru_chan_enable(mru_chan_base(priv, pos)); > + > + return 0; > +} > + > +static void mru_msi_domain_free(struct irq_domain *domain, unsigned int virq, > + unsigned int nr_irqs) > +{ > + struct irq_data *d = irq_domain_get_irq_data(domain, virq); > + struct mru_msi *priv = domain->host_data; > + > + lockdep_assert_held(&domain->root->mutex); > + > + mru_chan_disable(mru_chan_base(priv, d->hwirq)); > + __clear_bit(d->hwirq, priv->chans_bitmap); > +} > + > +static const struct irq_domain_ops mru_msi_domain_ops = { > + .select = msi_lib_irq_domain_select, > + .alloc = mru_msi_domain_alloc, > + .free = mru_msi_domain_free, > +}; > + > +#define MRU_MSI_FLAGS_REQUIRED (MSI_FLAG_USE_DEF_DOM_OPS | \ > + MSI_FLAG_USE_DEF_CHIP_OPS) > + > +#define MRU_MSI_FLAGS_SUPPORTED (MSI_GENERIC_FLAGS_MASK | \ > + MSI_FLAG_PCI_MSIX) > + > +static const struct msi_parent_ops mru_msi_parent_ops = { > + .required_flags = MRU_MSI_FLAGS_REQUIRED, > + .supported_flags = MRU_MSI_FLAGS_SUPPORTED, > + .chip_flags = MSI_CHIP_FLAG_SET_ACK, > + .bus_select_token = DOMAIN_BUS_NEXUS, > + .bus_select_mask = MATCH_PCI_MSI, > + .prefix = "MRU-", > + .init_dev_msi_info = msi_lib_init_dev_msi_info, > +}; > + > +static void mru_msi_irq_handler(struct irq_desc *desc) > +{ > + struct mru *mru = irq_desc_get_handler_data(desc); > + struct irq_chip *chip = irq_desc_get_chip(desc); > + struct mru_msi *priv = mru->priv; > + unsigned int chan, pos; > + > + chained_irq_enter(chip, desc); > + > + for (chan = 0; chan < MRU_CHANS_PER_MRU; chan++) { > + void __iomem *mbstat = mru->base + chan * MRU_CH_STRIDE + > + MRU_CH_MBSTAT; > + > + if (!(readl(mbstat) & MRU_MBSTAT_MBS0)) > + continue; > + > + writel(MRU_MBSTAT_MBS0, mbstat); > + > + pos = mru_mru2pos(priv, mru->index, chan); > + if (!generic_handle_demux_domain_irq(priv->domain, pos)) > + dev_err_ratelimited(priv->dev, > + "unexpected message on MRU%u channel %u\n", > + mru->index, chan); > + } > + > + chained_irq_exit(chip, desc); > +} > + > +static int mru_msi_create_domain(struct mru_msi *priv) > +{ > + struct irq_domain_info info = { > + .fwnode = dev_fwnode(priv->dev), > + .size = priv->nchans, > + .ops = &mru_msi_domain_ops, > + .host_data = priv, > + }; > + > + priv->domain = msi_create_parent_irq_domain(&info, &mru_msi_parent_ops); > + if (!priv->domain) > + return dev_err_probe(priv->dev, -ENOMEM, > + "failed to create the MSI parent domain\n"); > + > + return 0; > +} > + > +static int mru_msi_probe(struct platform_device *pdev) > +{ > + struct device *dev = &pdev->dev; > + struct mru_msi *priv; > + struct resource *res; > + unsigned int i, chan; > + int ret; > + > + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); Now have devm_kzalloc_obj() > + if (!priv) > + return -ENOMEM; > + > + priv->dev = dev; > + > + while (platform_get_resource(pdev, IORESOURCE_MEM, priv->nmrus)) > + priv->nmrus++; > + > + if (!priv->nmrus) > + return dev_err_probe(dev, -EINVAL, "no MRU register space\n"); > + > + priv->nchans = priv->nmrus * MRU_CHANS_PER_MRU; > + > + priv->mrus = devm_kcalloc(dev, priv->nmrus, sizeof(*priv->mrus), > + GFP_KERNEL); devm_kzalloc_objs() Frank > + if (!priv->mrus) > + return -ENOMEM; > + > + priv->chans_bitmap = devm_bitmap_zalloc(dev, priv->nchans, GFP_KERNEL); > + if (!priv->chans_bitmap) > + return -ENOMEM; > + > + for (i = 0; i < priv->nmrus; i++) { > + struct mru *mru = &priv->mrus[i]; > + > + mru->priv = priv; > + mru->index = i; > + > + mru->base = devm_platform_get_and_ioremap_resource(pdev, i, > + &res); > + if (IS_ERR(mru->base)) > + return PTR_ERR(mru->base); > + > + if (resource_size(res) < MRU_REGION_SIZE) > + return dev_err_probe(dev, -EINVAL, > + "MRU%u register space too small\n", i); > + > + mru->addr = res->start; > + > + mru->irq = platform_get_irq(pdev, i); > + if (mru->irq < 0) > + return mru->irq; > + > + /* Reset the channels, in case they were left enabled. */ > + for (chan = 0; chan < MRU_CHANS_PER_MRU; chan++) > + writel(MRU_CFG0_CHR, mru->base + chan * MRU_CH_STRIDE + > + MRU_CH_CFG0); > + } > + > + ret = mru_msi_create_domain(priv); > + if (ret) > + return ret; > + > + /* The handlers use the domain, so they are installed last. */ > + for (i = 0; i < priv->nmrus; i++) { > + struct mru *mru = &priv->mrus[i]; > + unsigned int cpu; > + > + irq_set_chained_handler_and_data(mru->irq, mru_msi_irq_handler, > + mru); > + > + /* > + * The vectors choose their own CPU through the redirection, so > + * the SPIs are only spread to keep the demux work of the > + * instances on different CPUs. A failure is not fatal. > + */ > + cpu = cpumask_local_spread(i, NUMA_NO_NODE); > + ret = irq_set_affinity(mru->irq, cpumask_of(cpu)); > + if (ret) > + dev_warn(dev, "MRU%u: cannot set the SPI affinity: %d\n", > + i, ret); > + } > + > + return 0; > +} > + > +static const struct of_device_id mru_msi_of_match[] = { > + { .compatible = "nxp,s32n79-mru-msi" }, > + { } > +}; > + > +static struct platform_driver mru_msi_driver = { > + .probe = mru_msi_probe, > + .driver = { > + .name = "nxp-mru-msi", > + .of_match_table = mru_msi_of_match, > + /* The MSI parent domain cannot be removed once it is in use. */ > + .suppress_bind_attrs = true, > + }, > +}; > +builtin_platform_driver(mru_msi_driver); > > -- > 2.43.0 > > >