Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp63405lqj; Sat, 1 Jun 2024 08:08:42 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWlYpwSbd39oA90CzwC/EUAvH4s/I9hhTIM7gaPj+zKru85R0qZZdf91hAqk49Eb+BBU5qzusX8TEkGPEqHgHZI6szpdeX/QOV8nMbm6w== X-Google-Smtp-Source: AGHT+IHTHvhq1eAnzazDYAhFIFxj3v8KKrhd1EThX14KFbZxvqGk+fHVOcbGiJQrVc3Zu+3v4Rgo X-Received: by 2002:a05:6a20:8405:b0:1af:939b:d477 with SMTP id adf61e73a8af0-1b26f1858d2mr5459752637.36.1717254521918; Sat, 01 Jun 2024 08:08:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717254521; cv=pass; d=google.com; s=arc-20160816; b=EgAzhlOHyqfVHxUmg4TDRHqLDtGQbBd1/NWge4O0fCdaMtaDEpb1sNwL4DPsPIZZFK 8aEnGflMXDizUfegRXle3pmz0Dul1exPjMMN+c8DT/eTVOjAYWevOioAE59+sxwc9ppt NC98GSw+kCvMmn0QbCQrF872IvQVhRZan3cMgK1OtVB0mGT4ZxqpWRFU740F/tVlYB90 0V/knvQveCnvzrRXTcEkvEqsGf6cQXJcMHk2cwlCZp2y3C0RmOU0+KPOv6UNCEGSXWph 8Fza9WIg7pn9GFn1z3Xe2cXIbaRhan/aqLUuqOhxY6f9y6kHD/VgRe2/7/K/hYZJSMVR L3gA== ARC-Message-Signature: i=2; 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=DRgQ4J8YfksV/Gcn1aZkdoBTGJR4bgqwnPhHrgwgqwc=; fh=ul3q6L1ddNF8PZ+QCjCuSTw6lL+Jlcbl0tDxDRBiOcw=; b=seexAIsPLV18eqCheGNYE5DDsST34ct7V9/oCU7wumYqJnbT5eHmTmiEGqEfiruByx LRS3bZKXLnscQmSQ4CfgdtEGp0cgFjwqdsRitLZb3psvYZ9PtmM76uQ5l3dLHXNAIs+L VB6PG0LKBc6ot+HfkrKful/Xw4IOzFHd2Gxgz6Ke9wI+pdmY2cjL+HfilnvU2SY5qFqc IR/hjKOAZVy12sM5iYlmy6XaZINxsM9E5Yh4rIo3mjMx/5JrVke0Zd0mGAJrkBsWjVsU EWSiLQPO/JXPhNKX3z1VuwnxSpBwSmtFo0rnR+xcRD1lIqU5OLsntpg+5hCFe+C/dnNi 34jQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=WXIYCQRr; arc=pass (i=1 spf=pass spfdomain=ventanamicro.com dkim=pass dkdomain=ventanamicro.com); spf=pass (google.com: domain of linux-kernel+bounces-197922-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-197922-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2c1a77b89cdsi5400273a91.95.2024.06.01.08.08.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Jun 2024 08:08:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-197922-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=WXIYCQRr; arc=pass (i=1 spf=pass spfdomain=ventanamicro.com dkim=pass dkdomain=ventanamicro.com); spf=pass (google.com: domain of linux-kernel+bounces-197922-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-197922-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 8FD7BB207E8 for ; Sat, 1 Jun 2024 15:08:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5B519153BD7; Sat, 1 Jun 2024 15:06:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="WXIYCQRr" Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (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 B526F15532D for ; Sat, 1 Jun 2024 15:06:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717254377; cv=none; b=Z9rCOaQ6reoLN2zP26kg1O6tQGlPfc8heoQHivzfzDbMnrJjYa7yGsq+UlcOeZwBLvGXEFI6BIuSn7BHkbMP/7nMOMSV9a2HSU1Dm0cJV8HtIJTGZ9iKXmDvtiNn0H+rPql9Ceo7ZSSHNBB29SzjGO3eXXEVhq7UWSS4Eno6Xzw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717254377; c=relaxed/simple; bh=vu8VI6XaJA42cKoE9NZhH8Bc2MppqSPlxbAiRcq+CaY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=iIPyWxYA7gJxnDRDEsYVkt1Gop/k/XK570AnOxWrV0Ksn15MxjGUf5P/5F/w6T2w4ASqPUjT1kj2TikbYaP4WoRGBofKD+otzUY4kWqeWSmr5w/TQ2OYfJZcGd/VRFQfd4BwBVuoTZpf0HYXOoNsaf7Nkk8oV+46Y4tCpJ2pBsk= 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=WXIYCQRr; arc=none smtp.client-ip=209.85.210.169 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-pf1-f169.google.com with SMTP id d2e1a72fcca58-701ae8698d8so2390871b3a.0 for ; Sat, 01 Jun 2024 08:06:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1717254375; x=1717859175; 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=DRgQ4J8YfksV/Gcn1aZkdoBTGJR4bgqwnPhHrgwgqwc=; b=WXIYCQRrXuEpQgSRlZeamiB1zcvrox2cxYA/4JgH/fbR3xZUjOBRUqhfZYcdUN4hBw XFjyjIoKpwHo70hxKB8Q/EYTDytRr4MlZTXbLsG92O0BS+y8rZZh6b0c09bQZW2TnbJi OkfunSgbgbJzq2cFBhZzzPAEduWOWKs38zs8NLy5N0RQGEYZI8jRD/avJQgd4FirS6vo kbXM+dUxU5Wd0BlgUvpJs0ksGHYlLgazlO8KObKCNzwsz6NqszTzTFl5omuRdBz3Fse1 2q4iv/xTBVEU0pOXgo+ukP82h00WwyTok6Ft/0yhyQgCi066tL6PTQkeuV6ommzo76MZ WAKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717254375; x=1717859175; 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=DRgQ4J8YfksV/Gcn1aZkdoBTGJR4bgqwnPhHrgwgqwc=; b=JQ2t6hu7MUCa1ESrLU8IsR4JlzlwV2tVGQY4rzHO68GnR8xzz4igVjeSj+vAzUWOwS HqLxgVWPnYXnIvp3k/At2xHIUTE4HKCeheZi1UbeVxrpNwuuj/FJ6Ce63M63VAxYpEBB tWLZzXv0lVvr+eIgEdI8DFeR841ziseSe3F0W44gkP+ZThumH9Dmxf/bIitMa/YdKpG+ Yspq9BbU8jRNMmkW3zdQB4/T1qr6suLtKkm0gEYKNzygpqUtQK9EaFDIsvlspG5Vj08p ZL58WTvfqHLLTNWjMFAFpXZP1hAv/UBV7H5X7MCN+BCZn3uhGrxVw+zu169YiIIt8RbX bKLg== X-Forwarded-Encrypted: i=1; AJvYcCXMbThUz/DnbCNZMmt2szPLFzamFF3RDhcuv6VSdeWCwHlZP5tM9vCmWcrZ6+DU5gInfwp2ux9p2vqLk08Y0uGhF5vjnArAVXwKSkFX X-Gm-Message-State: AOJu0YwAbq70eHGS5r3HeQ7j+PMtBbNUyjwxfA7sYBSEPIxvc6asU/Zd gpFQcqbwY/kETc8Tku7wCs0hv0+kIQJUSsFsAbQVFP/eGU06jcueculL1sTWe6Y= X-Received: by 2002:a05:6a21:32a0:b0:1a7:94ea:a9b4 with SMTP id adf61e73a8af0-1b26f1855f2mr5494518637.32.1717254375001; Sat, 01 Jun 2024 08:06:15 -0700 (PDT) Received: from sunil-pc.Dlink ([106.51.187.237]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-6c35a4ba741sm2559410a12.85.2024.06.01.08.06.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Jun 2024 08:06:14 -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, acpica-devel@lists.linux.dev Cc: Catalin Marinas , Will Deacon , Paul Walmsley , Palmer Dabbelt , Albert Ou , "Rafael J . Wysocki" , Len Brown , Bjorn Helgaas , Anup Patel , Thomas Gleixner , Samuel Holland , Robert Moore , Conor Dooley , Andrew Jones , Andy Shevchenko , Marc Zyngier , Atish Kumar Patra , Haibo1 Xu , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Sunil V L Subject: [PATCH v6 16/17] irqchip/riscv-aplic: Add ACPI support Date: Sat, 1 Jun 2024 20:34:10 +0530 Message-Id: <20240601150411.1929783-17-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240601150411.1929783-1-sunilvl@ventanamicro.com> References: <20240601150411.1929783-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 Add ACPI support in APLIC drivers. Use the mapping created early during boot to get the details about the APLIC. Signed-off-by: Sunil V L --- drivers/irqchip/irq-riscv-aplic-direct.c | 22 +++++--- drivers/irqchip/irq-riscv-aplic-main.c | 68 ++++++++++++++++-------- drivers/irqchip/irq-riscv-aplic-main.h | 1 + drivers/irqchip/irq-riscv-aplic-msi.c | 9 +++- 4 files changed, 68 insertions(+), 32 deletions(-) diff --git a/drivers/irqchip/irq-riscv-aplic-direct.c b/drivers/irqchip/irq-riscv-aplic-direct.c index 4a3ffe856d6c..34540a0ca4da 100644 --- a/drivers/irqchip/irq-riscv-aplic-direct.c +++ b/drivers/irqchip/irq-riscv-aplic-direct.c @@ -4,6 +4,7 @@ * Copyright (C) 2022 Ventana Micro Systems Inc. */ +#include #include #include #include @@ -189,17 +190,22 @@ static int aplic_direct_starting_cpu(unsigned int cpu) } static int aplic_direct_parse_parent_hwirq(struct device *dev, u32 index, - u32 *parent_hwirq, unsigned long *parent_hartid) + u32 *parent_hwirq, unsigned long *parent_hartid, + struct aplic_priv *priv) { struct of_phandle_args parent; + unsigned long hartid; int rc; - /* - * Currently, only OF fwnode is supported so extend this - * function for ACPI support. - */ - if (!is_of_node(dev->fwnode)) - return -EINVAL; + if (!is_of_node(dev->fwnode)) { + hartid = acpi_get_ext_intc_parent_hartid(priv->id, index); + if (hartid == INVALID_HARTID) + return -ENODEV; + + *parent_hartid = hartid; + *parent_hwirq = RV_IRQ_EXT; + return 0; + } rc = of_irq_parse_one(to_of_node(dev->fwnode), index, &parent); if (rc) @@ -237,7 +243,7 @@ int aplic_direct_setup(struct device *dev, void __iomem *regs) /* Setup per-CPU IDC and target CPU mask */ current_cpu = get_cpu(); for (i = 0; i < priv->nr_idcs; i++) { - rc = aplic_direct_parse_parent_hwirq(dev, i, &hwirq, &hartid); + rc = aplic_direct_parse_parent_hwirq(dev, i, &hwirq, &hartid, priv); if (rc) { dev_warn(dev, "parent irq for IDC%d not found\n", i); continue; diff --git a/drivers/irqchip/irq-riscv-aplic-main.c b/drivers/irqchip/irq-riscv-aplic-main.c index 774a0c97fdab..c1fd328ddf7d 100644 --- a/drivers/irqchip/irq-riscv-aplic-main.c +++ b/drivers/irqchip/irq-riscv-aplic-main.c @@ -4,8 +4,10 @@ * Copyright (C) 2022 Ventana Micro Systems Inc. */ +#include #include #include +#include #include #include #include @@ -125,39 +127,50 @@ static void aplic_init_hw_irqs(struct aplic_priv *priv) writel(0, priv->regs + APLIC_DOMAINCFG); } +#ifdef CONFIG_ACPI +static const struct acpi_device_id aplic_acpi_match[] = { + { "RSCV0002", 0 }, + {} +}; +MODULE_DEVICE_TABLE(acpi, aplic_acpi_match); + +#endif + int aplic_setup_priv(struct aplic_priv *priv, struct device *dev, void __iomem *regs) { struct of_phandle_args parent; int rc; - /* - * Currently, only OF fwnode is supported so extend this - * function for ACPI support. - */ - if (!is_of_node(dev->fwnode)) - return -EINVAL; - /* Save device pointer and register base */ priv->dev = dev; priv->regs = regs; - /* Find out number of interrupt sources */ - rc = of_property_read_u32(to_of_node(dev->fwnode), "riscv,num-sources", - &priv->nr_irqs); - if (rc) { - dev_err(dev, "failed to get number of interrupt sources\n"); - return rc; - } + if (is_of_node(dev->fwnode)) { + /* Find out number of interrupt sources */ + rc = of_property_read_u32(to_of_node(dev->fwnode), "riscv,num-sources", + &priv->nr_irqs); + if (rc) { + dev_err(dev, "failed to get number of interrupt sources\n"); + return rc; + } - /* - * Find out number of IDCs based on parent interrupts - * - * If "msi-parent" property is present then we ignore the - * APLIC IDCs which forces the APLIC driver to use MSI mode. - */ - if (!of_property_present(to_of_node(dev->fwnode), "msi-parent")) { - while (!of_irq_parse_one(to_of_node(dev->fwnode), priv->nr_idcs, &parent)) - priv->nr_idcs++; + /* + * Find out number of IDCs based on parent interrupts + * + * If "msi-parent" property is present then we ignore the + * APLIC IDCs which forces the APLIC driver to use MSI mode. + */ + if (!of_property_present(to_of_node(dev->fwnode), "msi-parent")) { + while (!of_irq_parse_one(to_of_node(dev->fwnode), priv->nr_idcs, &parent)) + priv->nr_idcs++; + } + } else { + rc = riscv_acpi_get_gsi_info(dev->fwnode, &priv->gsi_base, &priv->id, + &priv->nr_irqs, &priv->nr_idcs); + if (rc) { + dev_err(dev, "failed to find GSI mapping\n"); + return rc; + } } /* Setup initial state APLIC interrupts */ @@ -186,6 +199,9 @@ static int aplic_probe(struct platform_device *pdev) */ if (is_of_node(dev->fwnode)) msi_mode = of_property_present(to_of_node(dev->fwnode), "msi-parent"); + else + msi_mode = imsic_acpi_get_fwnode(NULL) ? 1 : 0; + if (msi_mode) rc = aplic_msi_setup(dev, regs); else @@ -193,6 +209,11 @@ static int aplic_probe(struct platform_device *pdev) if (rc) dev_err(dev, "failed to setup APLIC in %s mode\n", msi_mode ? "MSI" : "direct"); +#ifdef CONFIG_ACPI + if (!acpi_disabled) + acpi_dev_clear_dependencies(ACPI_COMPANION(dev)); +#endif + return rc; } @@ -205,6 +226,7 @@ static struct platform_driver aplic_driver = { .driver = { .name = "riscv-aplic", .of_match_table = aplic_match, + .acpi_match_table = ACPI_PTR(aplic_acpi_match), }, .probe = aplic_probe, }; diff --git a/drivers/irqchip/irq-riscv-aplic-main.h b/drivers/irqchip/irq-riscv-aplic-main.h index 4393927d8c80..9fbf45c7b4f7 100644 --- a/drivers/irqchip/irq-riscv-aplic-main.h +++ b/drivers/irqchip/irq-riscv-aplic-main.h @@ -28,6 +28,7 @@ struct aplic_priv { u32 gsi_base; u32 nr_irqs; u32 nr_idcs; + u32 id; void __iomem *regs; struct aplic_msicfg msicfg; }; diff --git a/drivers/irqchip/irq-riscv-aplic-msi.c b/drivers/irqchip/irq-riscv-aplic-msi.c index 028444af48bd..f5020241e0ed 100644 --- a/drivers/irqchip/irq-riscv-aplic-msi.c +++ b/drivers/irqchip/irq-riscv-aplic-msi.c @@ -157,6 +157,7 @@ static const struct msi_domain_template aplic_msi_template = { int aplic_msi_setup(struct device *dev, void __iomem *regs) { const struct imsic_global_config *imsic_global; + struct irq_domain *msi_domain; struct aplic_priv *priv; struct aplic_msicfg *mc; phys_addr_t pa; @@ -239,8 +240,14 @@ int aplic_msi_setup(struct device *dev, void __iomem *regs) * IMSIC and the IMSIC MSI domains are created later through * the platform driver probing so we set it explicitly here. */ - if (is_of_node(dev->fwnode)) + if (is_of_node(dev->fwnode)) { of_msi_configure(dev, to_of_node(dev->fwnode)); + } else { + msi_domain = irq_find_matching_fwnode(imsic_acpi_get_fwnode(dev), + DOMAIN_BUS_PLATFORM_MSI); + if (msi_domain) + dev_set_msi_domain(dev, msi_domain); + } } if (!msi_create_device_irq_domain(dev, MSI_DEFAULT_DOMAIN, &aplic_msi_template, -- 2.40.1