From nobody Thu Dec 18 07:38:35 2025 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 777E712BEAB for ; Wed, 1 May 2024 12:19:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714565986; cv=none; b=YVOsF08N/ERRKFwHV4iIN4tsPN+qVONjGPzogoJX+Y+74r7BQEFaSMgLJus4/RmqslhG9tDvo4C23bHxeSK2woaN1vXQvrygL3/Ff/6fP9T417rmqLWyTlvLi+gN2dadeATVFFCXvK83bjaIgl4iLV3PnOHW6xM3VkbJj3CIEvU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714565986; c=relaxed/simple; bh=ahgw0IfHPDtwuOAghidN1DUqYNQgZUOZv3r84r5UQZg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hlq81f6nMYayYS6u4n2lzRe/gGjAGTtr2fDcIfhQdhrWNLCwVhNOk7u9TR7t9q1ElmuFaMimSjonuKwcze1tPXlNmrAJjyXJva+OLVFipxv/bd+N4yuWzl9yHs/SOXDKKRN0DH7s/PgIL32HAlX69kj3+U4e6kwqqzYCvIBUVWY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=IaFa2q+Z; arc=none smtp.client-ip=209.85.214.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="IaFa2q+Z" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-1eb0e08bfd2so33076445ad.1 for ; Wed, 01 May 2024 05:19:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1714565985; x=1715170785; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zCPPOR1ckSAJZ1Ubedg9t4QsI9vLkLXGoLfn+9ixWV8=; b=IaFa2q+ZhE7Q1d5K01vyR1jz9On9WXxrLwe1Bgu/VPyfM+IbnUyEwtET6hM0VB6JIp Mo1xe22WoyUCcsNELfXuVhnrvvaOJixMQvRNgaOyFW9jJTCpx9TqriZRHhwYkzZZL/HD iLnBbReDPeNZtyAYmw6YDel/zclSt4qMEcNLm5gDt7BWissE+2qIOppXIpHCg79t/q0P fHgO7G5vO/V/IEVzSAYNOnVNX6BA+qd4aReEER3xh1PQzXqVO14/lOkgwh41OhhZtH2K TPaMrrczEbtcO7NymPAt0TsqdG25/niKIyhf6qZttyEKQ8tmszWESpRqchDFs9vjetUH JL6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714565985; x=1715170785; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zCPPOR1ckSAJZ1Ubedg9t4QsI9vLkLXGoLfn+9ixWV8=; b=FV9lVo8YbKEXKxM8vohws+D1HQuHKJKlcFvCA7V8QPRLvWj07YxSuoyYjnCmvMAgdN RhOPkP3DonYthnWY7nAqcMhcXrFTHRXZAOxNFwZt6w5BugfSmkb1X7a0ppkTJZ+yajRW 4uuoWhyXh/pfJn/l/0ZoMoOVnbARbthVD7itYZHydUDhuWfY2YqgKWyc+98JyYYdwJTD jAVA/3RFJVqQiQHOCOV1qduGci/YZa8BSFfwwwRHFaL2AOREpr+dLvkBKrTfgqXNouLx 149abE3abc3hXmprGeS9rVYlSrUAiAu88OtPEjE1LYaFHiykCdhmwMmGLQ04kzVCaUfE I16A== X-Forwarded-Encrypted: i=1; AJvYcCU/rdSlre6B1rpDFINrwOB23txlf4W/nF6J2VfpwAGFmYGbqzns6eA/6EeeW7ohRUjiHu9/WKZjt+Cj77TrBWfTgdqYZM99kaIvvbLx X-Gm-Message-State: AOJu0Yw/vmwpIy/GLkwNdhGiyvYeiEtIwRqvaZhnGLwwDE3kKvrhZdHh eeBQ6Oh9AGfCNsd31Die5EjuA3NNgMrvgRqAAjjLhQKlO5rKot4Di2xlqncR3jo= X-Google-Smtp-Source: AGHT+IFGyfzN/5kExRpukpNj4St1rBgfudB/pj+gt5M5G+xrt6pZdmPm+vpc0dav1zcXRIM1c0Qiiw== X-Received: by 2002:a17:902:e841:b0:1eb:66b6:930b with SMTP id t1-20020a170902e84100b001eb66b6930bmr2252492plg.55.1714565984846; Wed, 01 May 2024 05:19:44 -0700 (PDT) Received: from sunil-pc.Dlink ([106.51.188.106]) by smtp.gmail.com with ESMTPSA id im15-20020a170902bb0f00b001ec8888b22esm1336900plb.65.2024.05.01.05.19.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 May 2024 05:19:44 -0700 (PDT) From: Sunil V L To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-acpi@vger.kernel.org, linux-pci@vger.kernel.org, linux-serial@vger.kernel.org, acpica-devel@lists.linux.dev Cc: Catalin Marinas , Will Deacon , Paul Walmsley , Albert Ou , "Rafael J . Wysocki" , Len Brown , Bjorn Helgaas , Anup Patel , Thomas Gleixner , Samuel Holland , Greg Kroah-Hartman , Jiri Slaby , Robert Moore , Conor Dooley , Andrew Jones , Andy Shevchenko , Marc Zyngier , Atish Kumar Patra , Andrei Warkentin , Haibo1 Xu , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Sunil V L Subject: [PATCH v5 13/17] irqchip/riscv-intc: Add ACPI support for AIA Date: Wed, 1 May 2024 17:47:38 +0530 Message-Id: <20240501121742.1215792-14-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240501121742.1215792-1-sunilvl@ventanamicro.com> References: <20240501121742.1215792-1-sunilvl@ventanamicro.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 Content-Type: text/plain; charset="utf-8" The RINTC subtype structure in MADT also has information about other interrupt controllers. Save this information and provide interfaces to retrieve them when required by corresponding drivers. Signed-off-by: Sunil V L --- arch/riscv/include/asm/irq.h | 35 +++++++++++ drivers/irqchip/irq-riscv-intc.c | 102 ++++++++++++++++++++++++++++++- 2 files changed, 135 insertions(+), 2 deletions(-) diff --git a/arch/riscv/include/asm/irq.h b/arch/riscv/include/asm/irq.h index 44a0b128c602..6bd578b1ffc9 100644 --- a/arch/riscv/include/asm/irq.h +++ b/arch/riscv/include/asm/irq.h @@ -25,9 +25,22 @@ enum riscv_irqchip_type { ACPI_RISCV_IRQCHIP_APLIC =3D 0x03, }; =20 +/* + * The ext_intc_id format is as follows: + * Bits [31:24] APLIC/PLIC ID + * Bits [15:0] APLIC IDC ID / PLIC S-Mode Context ID for this hart + */ +#define APLIC_PLIC_ID(x) ((x) >> 24) +#define IDC_CONTEXT_ID(x) ((x) & 0x0000ffff) + int riscv_acpi_get_gsi_info(struct fwnode_handle *fwnode, u32 *gsi_base, u32 *id, u32 *nr_irqs, u32 *nr_idcs); struct fwnode_handle *riscv_acpi_get_gsi_domain_id(u32 gsi); +int __init acpi_get_intc_index_hartid(u32 index, unsigned long *hartid); +int acpi_get_ext_intc_parent_hartid(u8 id, u32 idx, unsigned long *hartid); +void acpi_get_plic_nr_contexts(u8 id, int *nr_contexts); +int acpi_get_plic_context(u8 id, u32 idx, int *context_id); +int __init acpi_get_imsic_mmio_info(u32 index, struct resource *res); =20 #else static inline int riscv_acpi_get_gsi_info(struct fwnode_handle *fwnode, u3= 2 *gsi_base, @@ -36,6 +49,28 @@ static inline int riscv_acpi_get_gsi_info(struct fwnode_= handle *fwnode, u32 *gsi return 0; } =20 +static inline int __init acpi_get_intc_index_hartid(u32 index, unsigned lo= ng *hartid) +{ + return -EINVAL; +} + +static inline int acpi_get_ext_intc_parent_hartid(u8 id, u32 idx, unsigned= long *hartid) +{ + return -EINVAL; +} + +static inline void acpi_get_plic_nr_contexts(u8 id, int *nr_contexts) { } + +static inline int acpi_get_plic_context(u8 id, u32 idx, int *context_id) +{ + return -EINVAL; +} + +static inline int __init acpi_get_imsic_mmio_info(u32 index, struct resour= ce *res) +{ + return 0; +} + #endif /* CONFIG_ACPI */ =20 #endif /* _ASM_RISCV_IRQ_H */ diff --git a/drivers/irqchip/irq-riscv-intc.c b/drivers/irqchip/irq-riscv-i= ntc.c index 9e71c4428814..af7a2f78f0ee 100644 --- a/drivers/irqchip/irq-riscv-intc.c +++ b/drivers/irqchip/irq-riscv-intc.c @@ -249,14 +249,105 @@ IRQCHIP_DECLARE(riscv, "riscv,cpu-intc", riscv_intc_= init); IRQCHIP_DECLARE(andes, "andestech,cpu-intc", riscv_intc_init); =20 #ifdef CONFIG_ACPI +struct rintc_data { + u32 ext_intc_id; + unsigned long hart_id; + u64 imsic_addr; + u32 imsic_size; +}; + +static u32 nr_rintc; +static struct rintc_data *rintc_acpi_data[NR_CPUS]; + +int acpi_get_intc_index_hartid(u32 index, unsigned long *hartid) +{ + if (index >=3D nr_rintc) + return -1; + + *hartid =3D rintc_acpi_data[index]->hart_id; + return 0; +} + +int acpi_get_ext_intc_parent_hartid(u8 id, u32 idx, unsigned long *hartid) +{ + int i, j =3D 0; + + for (i =3D 0; i < nr_rintc; i++) { + if (APLIC_PLIC_ID(rintc_acpi_data[i]->ext_intc_id) =3D=3D id) { + if (idx =3D=3D j) { + *hartid =3D rintc_acpi_data[i]->hart_id; + return 0; + } + j++; + } + } + + return -1; +} + +void acpi_get_plic_nr_contexts(u8 id, int *nr_contexts) +{ + int i, j =3D 0; + + for (i =3D 0; i < nr_rintc; i++) { + if (APLIC_PLIC_ID(rintc_acpi_data[i]->ext_intc_id) =3D=3D id) + j++; + } + + *nr_contexts =3D j; +} + +int acpi_get_plic_context(u8 id, u32 idx, int *context_id) +{ + int i, j =3D 0; + + for (i =3D 0; i < nr_rintc; i++) { + if (APLIC_PLIC_ID(rintc_acpi_data[i]->ext_intc_id) =3D=3D id) { + if (idx =3D=3D j) { + *context_id =3D IDC_CONTEXT_ID(rintc_acpi_data[i]->ext_intc_id); + return 0; + } + + j++; + } + } + + return -1; +} + +int acpi_get_imsic_mmio_info(u32 index, struct resource *res) +{ + if (index >=3D nr_rintc) + return -1; + + res->start =3D rintc_acpi_data[index]->imsic_addr; + res->end =3D res->start + rintc_acpi_data[index]->imsic_size - 1; + res->flags =3D IORESOURCE_MEM; + return 0; +} + +static struct fwnode_handle *ext_entc_get_gsi_domain_id(u32 gsi) +{ + return riscv_acpi_get_gsi_domain_id(gsi); +} =20 static int __init riscv_intc_acpi_init(union acpi_subtable_headers *header, const unsigned long end) { - struct fwnode_handle *fn; struct acpi_madt_rintc *rintc; + struct fwnode_handle *fn; + int rc; =20 rintc =3D (struct acpi_madt_rintc *)header; + rintc_acpi_data[nr_rintc] =3D kzalloc(sizeof(*rintc_acpi_data[0]), GFP_KE= RNEL); + if (!rintc_acpi_data[nr_rintc]) + return -ENOMEM; + + rintc_acpi_data[nr_rintc]->ext_intc_id =3D rintc->ext_intc_id; + rintc_acpi_data[nr_rintc]->hart_id =3D rintc->hart_id; + rintc_acpi_data[nr_rintc]->imsic_addr =3D rintc->imsic_addr; + rintc_acpi_data[nr_rintc]->imsic_size =3D rintc->imsic_size; + nr_rintc++; =20 /* * The ACPI MADT will have one INTC for each CPU (or HART) @@ -273,7 +364,14 @@ static int __init riscv_intc_acpi_init(union acpi_subt= able_headers *header, return -ENOMEM; } =20 - return riscv_intc_init_common(fn, &riscv_intc_chip); + rc =3D riscv_intc_init_common(fn, &riscv_intc_chip); + if (rc) { + irq_domain_free_fwnode(fn); + return rc; + } + + acpi_set_irq_model(ACPI_IRQ_MODEL_RINTC, ext_entc_get_gsi_domain_id); + return 0; } =20 IRQCHIP_ACPI_DECLARE(riscv_intc, ACPI_MADT_TYPE_RINTC, NULL, --=20 2.40.1