Received: by 2002:a05:7412:d008:b0:f9:6acb:47ec with SMTP id bd8csp78036rdb; Tue, 19 Dec 2023 09:49:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IE/6ZsGDYiN+3TRzDl/Rc5Do3zSuBuEujYkqU1k5cy1y6wAsXwlhqhQ8YHJcKJDvJpsUPG9 X-Received: by 2002:a17:902:f690:b0:1d3:e647:1e36 with SMTP id l16-20020a170902f69000b001d3e6471e36mr819065plg.6.1703008160226; Tue, 19 Dec 2023 09:49:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703008160; cv=none; d=google.com; s=arc-20160816; b=EaJEs8DBoLTxn3JKVkfdcBmu3yFiUoA3lGcXwz5I0PUFTBazO9+4Rn4ZKoXUc4edJE dtSGku7mHVWwfDIFmBuLH1xaZIUu1LlzCw4BeyzmtHM8Q8hapJBdCGS7SBN+hccp4F5F DYiANeqH3W/lrA1XR6+nazZ20x0hyaJYLMtUvDJ+T9faKvzhvDtnegGZjkRebmV1EJ28 Qi6zV3+n9Yi/WU+7L/DVe/8jx6FTDH7eeTMqVnTHPRRJtVhdi5XAEd2REzkY42OPhTPn 8S+LWjZOKrr/xm1LumfGL56iLCV7CwVC009qdA49rVaBhYE4Hp/98b7uFwVAtvRilnK+ 7dLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=6M2Ttr5IEog4zhXC7a0v2EI78vgaHJj9cNeT2PJ69Bo=; fh=G3MkS2cP7FkeH+7kxy0LRzNpJgfwnUWZciURRBohxGI=; b=ERuZ0lEb2IDN3rZagq2L+ZsbvyFRFoVFvOtdduoHFCJTq4hcFtBz/aVfPm2wBHfBWm JOeAy/P0HEZeD9LXUy2czgCzxc3tpIouL7Vvwv8e+VhjUZLKQDyBRDO63JyN3bGQymUz HyFyxP5aqKhoMxVno0gUwCwCmduMjuj1A1nrJYaPlQEdIvIolbjhvL6U8fCkIG2ZgzDh hR4F8oVYwSN1rgwjUpeK6zC5r2eB5YdxmcRxcMOfddZ/JkZBKSHy6tOpx9BCXMBKZ82N ogQKER6ifmpVrPqr26bjM9jTGHANydvK9gAukZERq3nnuPwxHYAlWroqhzsoI2PWga+u mnKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=B5UFlInX; spf=pass (google.com: domain of linux-kernel+bounces-5721-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-5721-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id s5-20020a170902ea0500b001d3c0a31d72si3540910plg.556.2023.12.19.09.49.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 09:49:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-5721-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=B5UFlInX; spf=pass (google.com: domain of linux-kernel+bounces-5721-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-5721-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id B31F6283620 for ; Tue, 19 Dec 2023 17:49:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D1C983B187; Tue, 19 Dec 2023 17:46:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="B5UFlInX" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (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 56FAF3B198 for ; Tue, 19 Dec 2023 17:46:26 +0000 (UTC) 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 Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1d3eae5c1d7so1010595ad.2 for ; Tue, 19 Dec 2023 09:46:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1703007985; x=1703612785; 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=6M2Ttr5IEog4zhXC7a0v2EI78vgaHJj9cNeT2PJ69Bo=; b=B5UFlInX+D4zHQn5jvIHIgAYNRAiJriaJe4mFP3ddjr2RbXq0TQN1GrkJFlBs5uJUU 2/ZMVqZYEGOWybxpBeRva5VcWGLgsv/I1jJENuOilQoyv4CKxaXjG53jNYdYGryoQqjG rxUOZgnaPCTQlebIkEG6N+Dw5NxSHUL6nm3RoIN9/ucEus9+nQ99hPAMrkudtDmVp/ol bUFI/15EY1HklnvVdchWkkuJvfcfKdyDwXxbYo/PPVsu29s//Zc8kOek11/ZL6AiVaR9 dK1b1cwLW2uIWRfMB+l0PQgpOPkHyJbz0iJi59olSW65tNNoXX1O38xxIvRY7FzypN4t 6f/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703007985; x=1703612785; 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=6M2Ttr5IEog4zhXC7a0v2EI78vgaHJj9cNeT2PJ69Bo=; b=C0DrHj9rUYgnxO0sTcc0L4f4ajBg/rN2turyRVa/mnvW2LKI6E2g85pgQaF8+9/diG PfSNdDPhJUZy9bKuDM7wzYp9DXSiTLHW9EmTnzGJzklsWBxXrSdUwLaGPZgwuTU9FVdR 6Jb1jsdUrv1Q25WvvG+VMHgR/0R1xYFXU15GCyZcdHDEOCM7sgIS+Q8Fm+PMEMILIekI h1bHhFE7R7B/0q9yzdfjAUmM7LAV8uN6aaVkYv6nZQY99uio1R0eILFhKlO4kFHw30/S WU14xAA6TPpV7FegC49mPPndVsm/EVaA7zp2LBdf57MF1UDgX7b/mu5CSRlGRqUDFpK0 9K6w== X-Gm-Message-State: AOJu0YzaXpMUHoXcbYeaVHlRs1iFxUbC5tW9OjNuRolbXXdUYsrC7VD4 vTc5hdlidJXvT4zt388tLm6WNQ== X-Received: by 2002:a17:903:98c:b0:1d3:e786:ab05 with SMTP id mb12-20020a170903098c00b001d3e786ab05mr648299plb.39.1703007985615; Tue, 19 Dec 2023 09:46:25 -0800 (PST) Received: from sunil-pc.Dlink ([106.51.188.200]) by smtp.gmail.com with ESMTPSA id n16-20020a170903111000b001d3320f6143sm14453015plh.269.2023.12.19.09.46.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 09:46:25 -0800 (PST) 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 Cc: Catalin Marinas , Will Deacon , Paul Walmsley , Palmer Dabbelt , Albert Ou , "Rafael J . Wysocki" , Len Brown , Anup Patel , Thomas Gleixner , Bjorn Helgaas , Haibo Xu , Conor Dooley , Andrew Jones , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Marc Zyngier , Sunil V L Subject: [RFC PATCH v3 09/17] irqchip: riscv-intc: Add ACPI support for AIA Date: Tue, 19 Dec 2023 23:15:18 +0530 Message-Id: <20231219174526.2235150-10-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231219174526.2235150-1-sunilvl@ventanamicro.com> References: <20231219174526.2235150-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: 8bit 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 | 45 +++++++++++++++ drivers/irqchip/irq-riscv-intc.c | 95 +++++++++++++++++++++++++++++++- 2 files changed, 139 insertions(+), 1 deletion(-) diff --git a/arch/riscv/include/asm/irq.h b/arch/riscv/include/asm/irq.h index 8e10a94430a2..232314e5f007 100644 --- a/arch/riscv/include/asm/irq.h +++ b/arch/riscv/include/asm/irq.h @@ -12,8 +12,53 @@ #include +#ifdef CONFIG_ACPI + +/* + * 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 __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); + +#else +static inline struct fwnode_handle *ext_entc_get_gsi_domain_id(u32 gsi) +{ + return NULL; +} + +static inline int __init acpi_get_intc_index_hartid(u32 index, unsigned long *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 resource *res) +{ + return -EINVAL; +} +#endif + void riscv_set_intc_hwnode_fn(struct fwnode_handle *(*fn)(void)); struct fwnode_handle *riscv_get_intc_hwnode(void); +int acpi_imsic_probe(struct fwnode_handle *parent); #endif /* _ASM_RISCV_IRQ_H */ diff --git a/drivers/irqchip/irq-riscv-intc.c b/drivers/irqchip/irq-riscv-intc.c index bab536bbaf2c..24bbc5bfc30f 100644 --- a/drivers/irqchip/irq-riscv-intc.c +++ b/drivers/irqchip/irq-riscv-intc.c @@ -195,13 +195,100 @@ IRQCHIP_DECLARE(riscv, "riscv,cpu-intc", riscv_intc_init); #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 >= nr_rintc) + return -1; + + *hartid = 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 = 0; + + for (i = 0; i < nr_rintc; i++) { + if (APLIC_PLIC_ID(rintc_acpi_data[i]->ext_intc_id) == id) { + if (idx == j) { + *hartid = 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 = 0; + + for (i = 0; i < nr_rintc; i++) { + if (APLIC_PLIC_ID(rintc_acpi_data[i]->ext_intc_id) == id) + j++; + } + + *nr_contexts = j; +} + +int acpi_get_plic_context(u8 id, u32 idx, int *context_id) +{ + int i, j = 0; + + for (i = 0; i < nr_rintc; i++) { + if (APLIC_PLIC_ID(rintc_acpi_data[i]->ext_intc_id) == id) { + if (idx == j) { + *context_id = 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 >= nr_rintc) + return -1; + + res->start = rintc_acpi_data[index]->imsic_addr; + res->end = res->start + rintc_acpi_data[index]->imsic_size - 1; + res->flags = IORESOURCE_MEM; + return 0; +} + 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; + int rc; rintc = (struct acpi_madt_rintc *)header; + rintc_acpi_data[nr_rintc] = kzalloc(sizeof(*rintc_acpi_data[0]), GFP_KERNEL); + if (!rintc_acpi_data[nr_rintc]) + return -ENOMEM; + + rintc_acpi_data[nr_rintc]->ext_intc_id = rintc->ext_intc_id; + rintc_acpi_data[nr_rintc]->hart_id = rintc->hart_id; + rintc_acpi_data[nr_rintc]->imsic_addr = rintc->imsic_addr; + rintc_acpi_data[nr_rintc]->imsic_size = rintc->imsic_size; + nr_rintc++; /* * The ACPI MADT will have one INTC for each CPU (or HART) @@ -218,7 +305,13 @@ static int __init riscv_intc_acpi_init(union acpi_subtable_headers *header, return -ENOMEM; } - return riscv_intc_init_common(fn); + rc = riscv_intc_init_common(fn); + if (rc) { + irq_domain_free_fwnode(fn); + return rc; + } + + return 0; } IRQCHIP_ACPI_DECLARE(riscv_intc, ACPI_MADT_TYPE_RINTC, NULL, -- 2.39.2