From nobody Sat Nov 23 19:25:15 2024 Received: from mail-oa1-f48.google.com (mail-oa1-f48.google.com [209.85.160.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F69C2595; Mon, 11 Nov 2024 04:01:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731297708; cv=none; b=qQARnP4TxRN0Nfbo6KqDIuelG+dffZ8lArhs0RtFHj8A06veBtQGy9jIJl2GSPlhTPmeaEeWSm6yvWRSOlLygTFO7kEQHYMXC5KF6YdLkdoCED44wcuUhpPIoH0cglgWYFGd3W3oG+qdB38fvIbv89nsB6w0mov5cDENtjIl0dE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731297708; c=relaxed/simple; bh=B7rNC05z3ig3dMog4AogDbn2qu8s5SQA6WyErnTnIzo=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=XxY1w4tbx7zam4Gz3GNx+H0SpO0e1UsZLKAPxId8bFZBgs0WQ07fnGSCP1fq0Bbk10BVlP4BYdVhA8s/f2BT6ZCRjaccvEMcluZu83KkWXsOHkkBkrLzxDrWjaOhARs2xDEvSaGM4cJZyjnAiriKMlPCn1VkRJTE27YJOqqiaRs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=DJZBb5h8; arc=none smtp.client-ip=209.85.160.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DJZBb5h8" Received: by mail-oa1-f48.google.com with SMTP id 586e51a60fabf-294ec8e1d8aso2443976fac.1; Sun, 10 Nov 2024 20:01:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731297705; x=1731902505; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=eyhBOJdbdb7U/MAw6LoCSVUFgTElIIRFybioC9VTZuM=; b=DJZBb5h8llu84Qa+25l/YMNUKTo5/FmHTlgwhT4OdKbzGD4X2scfLa2MHNMPabn/FQ OOLmsGE2ZImX1kT1CaAMQB1iMdR7KSHlJSGYG9mKAKaE3srNU+h1TfxkKPKNrr8X97gm BIfQqOLBPKvsiOOR5ZMJv1/RjYsxYtzUHO32AOyF0pBO8+/Y/zI2wRnXo2II8jJzxJ7S UVUq2WOaEBxJIBvx0/1gAh7gN/2U8QsFQiY2VT6cPlq0f4a5xzkFcrYIdzz84CWEHHhw +oFMVjPOWjoGGC3fmhUKhFcNoW86cqLCCR6amop67AbJ5xH1XoR4oefbkB8L0MkwU1x9 y8sA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731297705; x=1731902505; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eyhBOJdbdb7U/MAw6LoCSVUFgTElIIRFybioC9VTZuM=; b=rQWLQmunQgdNe8x31qOsr9jNONYzI1kBwwP7EmUd7EnUDEABRTh7qw0klksICxt7XK jVdCVvk4A5bU0uRR6eUgN3WL76RUNJezmhBGFxCmSXaHSDKC/vW1i9shg7AaTSe8lg0M NZEDjtMoJTi6HU6vbdCsj5+eIS3ZXgh/htSfn/mkkE/aQZdDwHuMtTcDqSF9MqO/vgbL IEIWzogfeu9B3b4fxa8Js1BiU0HEpYXEOe6pesdz3CeWwKw8qqPQllSuLIpSp1da9tEu YzDpfu19AHFBXczJno/cNTKFOTgcm9laBqlh6gkzV7VPF+RRUa4WHMRLP2080MgOQfiz BJVA== X-Forwarded-Encrypted: i=1; AJvYcCVdZrRUKnEllQ7AoEZjde27xmeMuJn4rkuhp2+GK1Tl0Hy7eEWVwTeB4kvlmv19V4Q5zN3OJKMTiA5J@vger.kernel.org, AJvYcCXuB0NDgNvTckkYxlXsvG8hLiE796LXrT0ZgnCA/qjlD/DDIPtoapZkjFogKr+Igl1Rm4hvIn3pRlN0U9DX@vger.kernel.org X-Gm-Message-State: AOJu0YwdmpBFDPj1nioXKO+e7E6+xMTr+8lVJnSfo/9JZyFJMdYJnEjq n2IjmPiT53UQaHlDpjluEcIeSlcYvuuHmcY6mUfmopMxxoDjNB1h X-Google-Smtp-Source: AGHT+IExdqCVvtfANRWv9lUO362sv1gaRUggc3/UVeXpal0yMHNBYIFFnDgdeYQf/09eHGl1kDf7cg== X-Received: by 2002:a05:6871:7a9:b0:287:e3e1:15f2 with SMTP id 586e51a60fabf-295601585f1mr8943535fac.25.1731297705248; Sun, 10 Nov 2024 20:01:45 -0800 (PST) Received: from localhost.localdomain ([122.8.183.87]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-29546d0085csm2622580fac.22.2024.11.10.20.01.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Nov 2024 20:01:44 -0800 (PST) From: Chen Wang To: u.kleine-koenig@baylibre.com, aou@eecs.berkeley.edu, arnd@arndb.de, unicorn_wang@outlook.com, conor+dt@kernel.org, guoren@kernel.org, inochiama@outlook.com, krzk+dt@kernel.org, palmer@dabbelt.com, paul.walmsley@sifive.com, robh@kernel.org, tglx@linutronix.de, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, chao.wei@sophgo.com, xiaoguang.xing@sophgo.com, fengchun.li@sophgo.com Subject: [PATCH 1/3] dt-bindings: interrupt-controller: Add Sophgo SG2042 MSI Date: Mon, 11 Nov 2024 12:01:36 +0800 Message-Id: <5186bb9c7feebb87136eb5e5e117fb1142dba4c2.1731296803.git.unicorn_wang@outlook.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: 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 Content-Type: text/plain; charset="utf-8" From: Chen Wang Add binding for Sophgo SG2042 MSI controller. Signed-off-by: Chen Wang --- .../sophgo,sg2042-msi.yaml | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 Documentation/devicetree/bindings/interrupt-controller/= sophgo,sg2042-msi.yaml diff --git a/Documentation/devicetree/bindings/interrupt-controller/sophgo,= sg2042-msi.yaml b/Documentation/devicetree/bindings/interrupt-controller/so= phgo,sg2042-msi.yaml new file mode 100644 index 000000000000..9fe99b74c211 --- /dev/null +++ b/Documentation/devicetree/bindings/interrupt-controller/sophgo,sg2042-= msi.yaml @@ -0,0 +1,78 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/interrupt-controller/sophgo,sg2042-msi.= yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Sophgo SG2042 MSI Controller + +maintainers: + - Chen Wang + +description: + This interrupt controller is in Sophgo SG2042 for transforming interrupt= s from + PCIe MSI to PLIC interrupts. + +allOf: + - $ref: /schemas/interrupts.yaml# + - $ref: /schemas/interrupt-controller/msi-controller.yaml# + +properties: + compatible: + const: sophgo,sg2042-msi + + reg: + items: + - description: clear register + + reg-names: + items: + - const: clr + + sophgo,msi-doorbell-addr: + description: + u64 value of the MSI doorbell address + $ref: /schemas/types.yaml#/definitions/uint64 + + sophgo,msi-base-vec: + description: + u32 value of the base of parent PLIC vector allocated + to MSI. + $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 64 + maximum: 95 + + sophgo,msi-num-vecs: + description: + u32 value of the number of parent PLIC vectors allocated + to MSI. + $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 1 + maximum: 32 + + msi-controller: true + +required: + - compatible + - reg + - reg-names + - msi-controller + - sophgo,msi-doorbell-addr + - sophgo,msi-base-vec + - sophgo,msi-num-vecs + +additionalProperties: true + +examples: + - | + #include + msi: msi-controller@30000000 { + compatible =3D "sophgo,sg2042-msi"; + reg =3D <0x30000000 0x4>; + reg-names =3D "clr"; + msi-controller; + sophgo,msi-doorbell-addr =3D <0x00000070 0x30010300>; + sophgo,msi-base-vec =3D <64>; + sophgo,msi-num-vecs =3D <32>; + interrupt-parent =3D <&plic>; + }; --=20 2.34.1 From nobody Sat Nov 23 19:25:15 2024 Received: from mail-oa1-f42.google.com (mail-oa1-f42.google.com [209.85.160.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5498A4B5C1; Mon, 11 Nov 2024 04:02:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731297728; cv=none; b=eQX8q8NVlvXfpMv3W1phMNbNIYDOEIh1j+MalhaZset4hiY5BY6ilwvTRahgBLD6YCgH54/pOmCGVf91Q8M2qAVDiI5Z2JUNDNe1KhtqM6n3S0wLcocRANJ3vazhoiAb7A4q79i+49l/7rd3ln/KDrv2Ez9NKODtJuplrCRmxUg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731297728; c=relaxed/simple; bh=Nunq7MnSPv4qHaqYemlbcRJmOW7gXkEcCPOBhtRAPWc=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TedIjcm/1cv+tmb8pz0PKS1WmiAKSSN7HHRdw8cQi0rKHNkIPj0TwUMzbkskpGlefFxWytj0AbI9wa6dQ0JVpOnbf7a1D9GWF9ntz6uAyv6xaNv+ZgZOcmAtxgHy8x2yoTOxJtn1J+sGZ8af6O/flRWGbSWJo1X22/QnAf4mXkk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=eehK6ffx; arc=none smtp.client-ip=209.85.160.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eehK6ffx" Received: by mail-oa1-f42.google.com with SMTP id 586e51a60fabf-288d4da7221so2238323fac.1; Sun, 10 Nov 2024 20:02:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731297725; x=1731902525; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=R+fPQhcktyhn766PuZ6e67L6+1wcYRMcJZUggR/XiQ0=; b=eehK6ffxPQlt5EP8dPecd2AuzQjGfXiyhHUkl3Sui0HAnaVHik9nlzzxmhocbOJXf4 u2kdkRHj2Zh1ACADIa+JDy3pOtAfDpgewCefB274z6S1e8WOZBYqC1ghvfQjAKmrFE8M GJ9ot3Iabw00N2mPZgn6g4uJHsA6Jf9TU19F0PSWWYy9096j1Kvh931O2piEHo9a3BmR 3vA27zXtFeoPUA7ZMeCTzS2YXfEWjLpiOpw0oZ53nDRrr6/C193F37SAPD/9hMuVyqIj 2aENf1jW0RbChp+AG6WRy5iuxX4WyUQiBpOsXRvvLjTv1uvZi/ua7oVWcSUgLWLH7UE0 dejg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731297725; x=1731902525; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=R+fPQhcktyhn766PuZ6e67L6+1wcYRMcJZUggR/XiQ0=; b=NiWR5uJsaIoKGYo8n0OMd2tqIgn/HrbUpFkQqW0QS/TcKIQwskZf+0EJo38qhtgO+o iPDUzpn8o1QWN1kDYEdDkJCj9mTB21Dto/ja6omLitZvSYiUx4rDZfUH6FCtPFfkC9wz 9TeV3ipP0QMsgESh4EK5yEA9DqEXGHt3+hCSIt5L2VFlikmT6MqAQSY0Dap8VFVwYW8w 2gOfw6WpzU24UE33gcJNcc6q+YU0CaPd2C1fEjnbgtN5k3auX4R4KQZBp1T9nd/grpfM sKDtft6CL3T2u9cdo/kH4JplOV0vb0EjDSey7Dxxg+FczFH08BO3hudVNw4QU3EjcC7O YPYw== X-Forwarded-Encrypted: i=1; AJvYcCUCDXGxB/F4yq8KVBEiB4svsqKiNlo1xVTGes4AEp3LVI72h6W06OB+Y8+kLveFFglrjWdiwOtBmYKAlQjP@vger.kernel.org, AJvYcCVgiJlS0ysZbVvLEOBLWmHXng1zNLNp0w0tSr+cAE727r8YKCgAlk9C6ng8G7kEyan5cny13n4GyLsv@vger.kernel.org X-Gm-Message-State: AOJu0YwR7O3taUtJ4RXQ9ywMRZB+UsONE39wcmbigSvEY1lPoc+kVW8+ qaRXZRDrQIqr/Nbkpeq6C0z4owWKz3NCyoiAO/X5e8bV/3u0vpFO X-Google-Smtp-Source: AGHT+IE1+3vDt96wuzJHta3Nkt+aV05zWOrqsajEFRzvGnq1988dsLWPrG80m3LN6mFGflF/nyetBQ== X-Received: by 2002:a05:6870:380d:b0:277:e08a:23a0 with SMTP id 586e51a60fabf-295602fd28cmr7803476fac.41.1731297723750; Sun, 10 Nov 2024 20:02:03 -0800 (PST) Received: from localhost.localdomain ([122.8.183.87]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-71a108e29f8sm2121721a34.47.2024.11.10.20.02.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Nov 2024 20:02:02 -0800 (PST) From: Chen Wang To: u.kleine-koenig@baylibre.com, aou@eecs.berkeley.edu, arnd@arndb.de, unicorn_wang@outlook.com, conor+dt@kernel.org, guoren@kernel.org, inochiama@outlook.com, krzk+dt@kernel.org, palmer@dabbelt.com, paul.walmsley@sifive.com, robh@kernel.org, tglx@linutronix.de, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, chao.wei@sophgo.com, xiaoguang.xing@sophgo.com, fengchun.li@sophgo.com Subject: [PATCH 2/3] irqchip: Add the Sophgo SG2042 MSI interrupt controller Date: Mon, 11 Nov 2024 12:01:55 +0800 Message-Id: <8076fe2af9f2b007a42c986ed193ba50ff674bfa.1731296803.git.unicorn_wang@outlook.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: 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 Content-Type: text/plain; charset="utf-8" From: Chen Wang Add driver for Sophgo SG2042 MSI interrupt controller. Signed-off-by: Chen Wang --- drivers/irqchip/Kconfig | 8 + drivers/irqchip/Makefile | 1 + drivers/irqchip/irq-sg2042-msi.c | 255 +++++++++++++++++++++++++++++++ 3 files changed, 264 insertions(+) create mode 100644 drivers/irqchip/irq-sg2042-msi.c diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig index d82bcab233a1..76a38a4d62eb 100644 --- a/drivers/irqchip/Kconfig +++ b/drivers/irqchip/Kconfig @@ -729,6 +729,14 @@ config MCHP_EIC help Support for Microchip External Interrupt Controller. =20 +config SOPHGO_SG2042_MSI + bool "Sophgo SG2042 MSI controller" + depends on ARCH_SOPHGO || COMPILE_TEST + help + Support for the Sophgo SG2042 MSI Controller. + This on-chip interrupt controller enables MSI sources to be + routed to the primary PLIC controller on SoC. + config SUNPLUS_SP7021_INTC bool "Sunplus SP7021 interrupt controller" if COMPILE_TEST default SOC_SP7021 diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile index e3679ec2b9f7..53617890268a 100644 --- a/drivers/irqchip/Makefile +++ b/drivers/irqchip/Makefile @@ -125,4 +125,5 @@ obj-$(CONFIG_WPCM450_AIC) +=3D irq-wpcm450-aic.o obj-$(CONFIG_IRQ_IDT3243X) +=3D irq-idt3243x.o obj-$(CONFIG_APPLE_AIC) +=3D irq-apple-aic.o obj-$(CONFIG_MCHP_EIC) +=3D irq-mchp-eic.o +obj-$(CONFIG_SOPHGO_SG2042_MSI) +=3D irq-sg2042-msi.o obj-$(CONFIG_SUNPLUS_SP7021_INTC) +=3D irq-sp7021-intc.o diff --git a/drivers/irqchip/irq-sg2042-msi.c b/drivers/irqchip/irq-sg2042-= msi.c new file mode 100644 index 000000000000..79449f974ed5 --- /dev/null +++ b/drivers/irqchip/irq-sg2042-msi.c @@ -0,0 +1,255 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * SG2042 MSI Controller + * + * Copyright (C) 2024 Sophgo Technology Inc. + * Copyright (C) 2024 Chen Wang + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct sg2042_msi_data { + void __iomem *reg_clr; /* clear reg, see TRM, 10.1.33, GP_INTR0_CLR */ + + u64 doorbell_addr; /* see TRM, 10.1.32, GP_INTR0_SET */ + + u32 irq_first; /* The vector number that MSIs starts */ + u32 num_irqs; /* The number of vectors for MSIs */ + + unsigned long *msi_map; + struct mutex msi_map_lock; /* lock for msi_map */ +}; + +static int sg2042_msi_allocate_hwirq(struct sg2042_msi_data *priv, int num= _req) +{ + int first; + + mutex_lock(&priv->msi_map_lock); + + first =3D bitmap_find_free_region(priv->msi_map, priv->num_irqs, + get_count_order(num_req)); + if (first < 0) { + mutex_unlock(&priv->msi_map_lock); + return -ENOSPC; + } + + mutex_unlock(&priv->msi_map_lock); + + return priv->irq_first + first; +} + +static void sg2042_msi_free_hwirq(struct sg2042_msi_data *priv, + int hwirq, int num_req) +{ + int first =3D hwirq - priv->irq_first; + + mutex_lock(&priv->msi_map_lock); + bitmap_release_region(priv->msi_map, first, get_count_order(num_req)); + mutex_unlock(&priv->msi_map_lock); +} + +static void sg2042_msi_irq_ack(struct irq_data *d) +{ + struct sg2042_msi_data *data =3D irq_data_get_irq_chip_data(d); + int bit_off =3D d->hwirq - data->irq_first; + + writel(1 << bit_off, (unsigned int *)data->reg_clr); + + irq_chip_ack_parent(d); +} + +static void sg2042_msi_irq_compose_msi_msg(struct irq_data *data, + struct msi_msg *msg) +{ + struct sg2042_msi_data *priv =3D irq_data_get_irq_chip_data(data); + + msg->address_hi =3D upper_32_bits(priv->doorbell_addr); + msg->address_lo =3D lower_32_bits(priv->doorbell_addr); + msg->data =3D 1 << (data->hwirq - priv->irq_first); + + pr_debug("%s hwirq[%d]: address_hi[%#x], address_lo[%#x], data[%#x]\n", + __func__, + (int)data->hwirq, msg->address_hi, msg->address_lo, msg->data); +} + +static struct irq_chip sg2042_msi_middle_irq_chip =3D { + .name =3D "SG2042 MSI", + .irq_ack =3D sg2042_msi_irq_ack, + .irq_mask =3D irq_chip_mask_parent, + .irq_unmask =3D irq_chip_unmask_parent, +#ifdef CONFIG_SMP + .irq_set_affinity =3D irq_chip_set_affinity_parent, +#endif + .irq_compose_msi_msg =3D sg2042_msi_irq_compose_msi_msg, +}; + +static int sg2042_msi_parent_domain_alloc(struct irq_domain *domain, + unsigned int virq, int hwirq) +{ + struct irq_fwspec fwspec; + struct irq_data *d; + int ret; + + fwspec.fwnode =3D domain->parent->fwnode; + fwspec.param_count =3D 2; + fwspec.param[0] =3D hwirq; + fwspec.param[1] =3D IRQ_TYPE_EDGE_RISING; + + ret =3D irq_domain_alloc_irqs_parent(domain, virq, 1, &fwspec); + if (ret) + return ret; + + d =3D irq_domain_get_irq_data(domain->parent, virq); + return d->chip->irq_set_type(d, IRQ_TYPE_EDGE_RISING); +} + +static int sg2042_msi_middle_domain_alloc(struct irq_domain *domain, + unsigned int virq, + unsigned int nr_irqs, void *args) +{ + struct sg2042_msi_data *priv =3D domain->host_data; + int hwirq, err, i; + + hwirq =3D sg2042_msi_allocate_hwirq(priv, nr_irqs); + if (hwirq < 0) + return hwirq; + + for (i =3D 0; i < nr_irqs; i++) { + err =3D sg2042_msi_parent_domain_alloc(domain, virq + i, hwirq + i); + if (err) + goto err_hwirq; + + pr_debug("%s: virq[%d], hwirq[%d]\n", + __func__, virq + i, (int)hwirq + i); + + irq_domain_set_hwirq_and_chip(domain, virq + i, hwirq + i, + &sg2042_msi_middle_irq_chip, priv); + } + + return 0; + +err_hwirq: + sg2042_msi_free_hwirq(priv, hwirq, nr_irqs); + irq_domain_free_irqs_parent(domain, virq, i); + + return err; +} + +static void sg2042_msi_middle_domain_free(struct irq_domain *domain, + unsigned int virq, + unsigned int nr_irqs) +{ + struct irq_data *d =3D irq_domain_get_irq_data(domain, virq); + struct sg2042_msi_data *priv =3D irq_data_get_irq_chip_data(d); + + irq_domain_free_irqs_parent(domain, virq, nr_irqs); + sg2042_msi_free_hwirq(priv, d->hwirq, nr_irqs); +} + +static const struct irq_domain_ops pch_msi_middle_domain_ops =3D { + .alloc =3D sg2042_msi_middle_domain_alloc, + .free =3D sg2042_msi_middle_domain_free, +}; + +static int sg2042_msi_init_domains(struct sg2042_msi_data *priv, + struct device_node *node) +{ + struct irq_domain *plic_domain, *middle_domain; + struct device_node *plic_node; + struct fwnode_handle *fwnode =3D of_node_to_fwnode(node); + + if (!of_find_property(node, "interrupt-parent", NULL)) { + pr_err("Can't find interrupt-parent!\n"); + return -EINVAL; + } + + plic_node =3D of_irq_find_parent(node); + if (!plic_node) { + pr_err("Failed to find the PLIC node!\n"); + return -ENXIO; + } + + plic_domain =3D irq_find_host(plic_node); + of_node_put(plic_node); + if (!plic_domain) { + pr_err("Failed to find the PLIC domain\n"); + return -ENXIO; + } + + middle_domain =3D irq_domain_create_hierarchy(plic_domain, 0, priv->num_i= rqs, + fwnode, + &pch_msi_middle_domain_ops, + priv); + if (!middle_domain) { + pr_err("Failed to create the MSI middle domain\n"); + return -ENOMEM; + } + + return 0; +} + +static int sg2042_msi_probe(struct platform_device *pdev) +{ + struct sg2042_msi_data *data; + + data =3D devm_kzalloc(&pdev->dev, sizeof(struct sg2042_msi_data), GFP_KER= NEL); + if (!data) + return -ENOMEM; + + data->reg_clr =3D devm_platform_ioremap_resource_byname(pdev, "clr"); + if (IS_ERR(data->reg_clr)) { + dev_err(&pdev->dev, "Failed to map clear register\n"); + return PTR_ERR(data->reg_clr); + } + + if (of_property_read_u64(pdev->dev.of_node, "sophgo,msi-doorbell-addr", + &data->doorbell_addr)) { + dev_err(&pdev->dev, "Unable to parse MSI doorbell addr\n"); + return -EINVAL; + } + + if (of_property_read_u32(pdev->dev.of_node, "sophgo,msi-base-vec", + &data->irq_first)) { + dev_err(&pdev->dev, "Unable to parse MSI vec base\n"); + return -EINVAL; + } + + if (of_property_read_u32(pdev->dev.of_node, "sophgo,msi-num-vecs", + &data->num_irqs)) { + dev_err(&pdev->dev, "Unable to parse MSI vec number\n"); + return -EINVAL; + } + + mutex_init(&data->msi_map_lock); + + data->msi_map =3D bitmap_zalloc(data->num_irqs, GFP_KERNEL); + if (!data->msi_map) + return -ENOMEM; + + return sg2042_msi_init_domains(data, pdev->dev.of_node); +} + +static const struct of_device_id sg2042_msi_of_match[] =3D { + { .compatible =3D "sophgo,sg2042-msi" }, + {} +}; + +static struct platform_driver sg2042_msi_driver =3D { + .driver =3D { + .name =3D "sg2042-msi", + .of_match_table =3D of_match_ptr(sg2042_msi_of_match), + }, + .probe =3D sg2042_msi_probe, +}; +builtin_platform_driver(sg2042_msi_driver); --=20 2.34.1 From nobody Sat Nov 23 19:25:15 2024 Received: from mail-ot1-f49.google.com (mail-ot1-f49.google.com [209.85.210.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 634CC6F06B; Mon, 11 Nov 2024 04:02:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731297743; cv=none; b=oNVnHzVrNCmP3x6eE2B/jbzYo3n5b5oKB4h0vX5TeG+MTABwTvh8ZBPIaw5SEI8iHiTDrvzi1doxW84Ww3uPs5lS9FX3Tw8h32WdKHjExrZdjmz8eWUUC/Dlu/CJqT3fkJOoIAB/6aB+62aUULKr21aQxaoS05cjXpGdivXOCS4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731297743; c=relaxed/simple; bh=iPkYnIO31AuQKCXhK+uEnPJKdf4HdKu6kAS06fDAsMo=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=b8KZUIvGTCmk7sBS2ezqYoyXzuA+M3TZDPCYZEo2lGueKwUxBqkEyDrXKAVEdVM4x8fO8XOMfCN9i/0HoHa6wNJ6KuT3X1umaESut/o/rI6b51zUP0hYQffWa41TKM2G4l8Lx13PMx5xEQqL+9EmHiF8l0y+M5MRkI9WqnclrnU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Tp6C1pux; arc=none smtp.client-ip=209.85.210.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Tp6C1pux" Received: by mail-ot1-f49.google.com with SMTP id 46e09a7af769-7187e0041d5so2414024a34.2; Sun, 10 Nov 2024 20:02:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731297741; x=1731902541; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=bjbTWmVjfUhEoQ8d2IpKkdBlmgYXhZxjwlzph6pX4qM=; b=Tp6C1puxOiMFXqJtEW+HAK0t5OCpB9jipAaMWcZxVW1lD+ooCBJswE9u9hBH1NKvmg GLhWYONVuOEVBCsdkBnNAe0xgWsM8fZ08NtlRwB33Y84XgtuvlluFGa7l5i2PWqBa25x MH3EJZidRJoUPKVEhowVcsm16xBZMi/IiAsw8oLwvIMJEETPrOiDDKQMssKVvwsdVrxr Ww2dLh2anq2CTilmtTD8a0djtUNpPuOSPVAhDP05n3/IcD/cinC0UjlozkBCXnIxE2ka ijuZ1mDWDQuLUoaVVUN9N6CnVg8tqhv+iAhb5HUrpkgQyGN0sYwtBaSY59rT52epzLeG ZsVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731297741; x=1731902541; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bjbTWmVjfUhEoQ8d2IpKkdBlmgYXhZxjwlzph6pX4qM=; b=a1x2PQJiSTqttvGIIeHfV/hJmYdigECJuN2L5HztSSolb3ufzrzvpVX4qlPWuGVQZ+ wQ1lHkMcGkraPUDtsTn3GIouL7cZWOkd6NrqxQjdI9K0LHY2Bi0mpu+KBhsgzHnwA6hF 6d2eaxD/6uGSXz4cdkvdIbLVDHFT+lzWTVBvU00oefr+cf8UasC/KrUhX6wmLqTYjSt6 kMhWF8nt5tQbfL32U7gYCtp79NlmdM1d2pmcjK2aLbGaLlP+VMJEbLVjaJwCT1KZIaeu Xc8gq5x7kcQ+pIkY/4K3KvIh5gI+DO2ZmFHQOypzqq2Fmp6BJsDBR4EnDlfbaP/niGUy ez0A== X-Forwarded-Encrypted: i=1; AJvYcCVcbMtnawVLFe+twg4RLdEB/Keq6SEGyzkerH/WZ2O02WRI65IlFb3YHGZVJMYlxjh1Hb4tSieSUztB@vger.kernel.org, AJvYcCWMlFhyNglp3vPM+2pz3oO4XeVYvWurUQDfhN2/gONkmYlqC8WQCRzHvimqQRYJdXVyxod9rU76X7AxqhBU@vger.kernel.org X-Gm-Message-State: AOJu0YxXKtBWqk0sAkjcVqO6RP+T+WIw6Ix5bysdYqgGE6TE9eGYxqF7 pVnquaR1VtYSh9+NIACpwsusjCJ62S485ZNIid3o4SFwEsnkiwO9 X-Google-Smtp-Source: AGHT+IHRYsyTEdBELcqPuXy/sNavXTBAGqMPTcuBIGgQENdK8cQW/SG/AKtr2fmcdqlADupSFPq7ng== X-Received: by 2002:a05:6830:3c10:b0:718:1cb6:e593 with SMTP id 46e09a7af769-71a1c2b1247mr10068611a34.27.1731297741396; Sun, 10 Nov 2024 20:02:21 -0800 (PST) Received: from localhost.localdomain ([122.8.183.87]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-71a10834aabsm2083654a34.32.2024.11.10.20.02.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Nov 2024 20:02:20 -0800 (PST) From: Chen Wang To: u.kleine-koenig@baylibre.com, aou@eecs.berkeley.edu, arnd@arndb.de, unicorn_wang@outlook.com, conor+dt@kernel.org, guoren@kernel.org, inochiama@outlook.com, krzk+dt@kernel.org, palmer@dabbelt.com, paul.walmsley@sifive.com, robh@kernel.org, tglx@linutronix.de, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, chao.wei@sophgo.com, xiaoguang.xing@sophgo.com, fengchun.li@sophgo.com Subject: [PATCH 3/3] riscv: sophgo: dts: add msi controller for SG2042 Date: Mon, 11 Nov 2024 12:02:12 +0800 Message-Id: <90bce35ca34b3c9f86f1af89d70ab34b2e497e0e.1731296803.git.unicorn_wang@outlook.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: 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 Content-Type: text/plain; charset="utf-8" From: Chen Wang Add msi-controller node to dts for SG2042. Signed-off-by: Chen Wang --- arch/riscv/boot/dts/sophgo/sg2042.dtsi | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/arch/riscv/boot/dts/sophgo/sg2042.dtsi b/arch/riscv/boot/dts/s= ophgo/sg2042.dtsi index e62ac51ac55a..35651cbac764 100644 --- a/arch/riscv/boot/dts/sophgo/sg2042.dtsi +++ b/arch/riscv/boot/dts/sophgo/sg2042.dtsi @@ -173,6 +173,19 @@ pllclk: clock-controller@70300100c0 { #clock-cells =3D <1>; }; =20 + msi: msi-controller@7030010304 { + compatible =3D "sophgo,sg2042-msi"; + reg =3D <0x70 0x30010304 0x0 0x4>; + reg-names =3D "clr"; + interrupt-controller; + #interrupt-cells =3D <1>; + msi-controller; + sophgo,msi-doorbell-addr =3D <0x00000070 0x30010300>; + sophgo,msi-base-vec =3D <64>; + sophgo,msi-num-vecs =3D <32>; + interrupt-parent =3D <&intc>; + }; + rpgate: clock-controller@7030010368 { compatible =3D "sophgo,sg2042-rpgate"; reg =3D <0x70 0x30010368 0x0 0x98>; --=20 2.34.1