Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp1572386lqp; Mon, 15 Apr 2024 10:07:32 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXwIvXwKRa1ClDyAuXsp16GZL5u5Z3Rj6kJS+kOuRvpYIin09z98pC1JyYwBVn0PEaYwv5/xBcEKRNyMv8oQRuEFBV1cbNtzcJP1fxqdw== X-Google-Smtp-Source: AGHT+IEdGQ6afS4F1UkItiG0jhNmzu3Dov7cZXYaNzuL8d6vL8o0GZVsFCa0RNO90bPiy2TGBhAH X-Received: by 2002:a05:6102:d93:b0:47b:6053:c204 with SMTP id d19-20020a0561020d9300b0047b6053c204mr9926306vst.23.1713200851741; Mon, 15 Apr 2024 10:07:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713200851; cv=pass; d=google.com; s=arc-20160816; b=Hl+WWfLBHP1vehsiY5UKcwlA88egejwzSDEpaZmnxun9HHlXeOqmYSxdCIMZ8OkZYt uKqlBv94QZ6UpcRW0DVmAVtiYDPNpdoFtLxTu/S8bp1/KKa+rydLbccYdfOkutk6pq1k kc4KQRvQfq0Q1GOMj/KTAjg/0J1D00CVbLtzKvvHZ3OiNVzAY6dtkeO7/WXalPdo3CSp Q7M05ynG0jNPOaRvYUHAcRwL3uQ6Vd6/0IEnhor5LXdj3Rj3kjUWMzQsIuWxsd9rgFg8 GK+EuLu7uAKCne/u7qi32sR4OMwpx4rTDnSyHAySaX3qfQsAfUmQsQbCR/ttkvIRDJmo 3Bgw== 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=H3zPkz1xxC1CxVIHCuATW1be05yVqY6yZ3K4WTU3dxk=; fh=MUx1zoWu8EGTAa32QYPbrz+NtvKSiM1lK4DBpSsJzGQ=; b=wRJZwmjnbWyPFgBemcIxXliDY1zC3XsMBiasYIBdpziSpU5wieWRUTgTJtY27euSlq RzL4dtrcLXESSXqX230Wh12auJSPHmAojRQoDxKp3MDQql6baoEDcssRUroRfZIZUkBS 95sTEYnFaUwOAKJVGjSjewtK7QqdMXhwkMVm4MOkjvEejAj8IQH8K6sfyKY6XiG5gQNa J4fhSJE2eZIPMoPsekEVtmhXHtLFIizm+5+pwVyHkU2i7In5s9w6s44CvrztSwYr3YQJ lGZ3JSpSzipBeaRJs2PNMRp21BYt2bFIYHxsPl1EmxuioQ8bOs/JrPJQFaDdJLTAJSGK 3ZCg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=IgooehBq; arc=pass (i=1 spf=pass spfdomain=ventanamicro.com dkim=pass dkdomain=ventanamicro.com); spf=pass (google.com: domain of linux-kernel+bounces-145618-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-145618-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id s8-20020a056102370800b0047a3fd40a7dsi1428349vst.658.2024.04.15.10.07.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 10:07:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-145618-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=IgooehBq; arc=pass (i=1 spf=pass spfdomain=ventanamicro.com dkim=pass dkdomain=ventanamicro.com); spf=pass (google.com: domain of linux-kernel+bounces-145618-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-145618-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id E609D1C21AFD for ; Mon, 15 Apr 2024 17:06:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3E0B9129E70; Mon, 15 Apr 2024 17:03:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="IgooehBq" 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 22E221292EB for ; Mon, 15 Apr 2024 17:03:12 +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=1713200594; cv=none; b=XaNsyk2vu1f5Cu0TVP1XNfXWabihQea5VtwZ3QyH7SkHiDvR/hrBhoArjZCJeWqF65Sryc/q0Rw7g3BVeb9mjR0/JY0jc2j7OstPaCDE+1aCMkSsDBWMxFyhvNYhirV8B7ASRXUTo9vz5Knpb6OxDCPMNuj3hMuqXLmwtx2Rrf8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713200594; c=relaxed/simple; bh=zR9YW/ONlpnGtOqbpcoPrl61EIaXzrcgrwGTwL9VCus=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=llmviXVJkxWskLfPWGo4FCDThH6HAsoEyRtssPoHVoVw2rKWhnUJjERtbH3WHY2/SkNfk22MSeVe1WXLUHx1ya/7b/mIRl9eDt4UfVR5N4zCjSmkcQed+vqmhzHdCP/f0PUO4dQw1tJxTYPKE9jWjoLBkaXOei7RLFpquND4cCs= 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=IgooehBq; 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-6ecec796323so3656203b3a.3 for ; Mon, 15 Apr 2024 10:03:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1713200591; x=1713805391; 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=H3zPkz1xxC1CxVIHCuATW1be05yVqY6yZ3K4WTU3dxk=; b=IgooehBqroOJM4xvchZpEqVIwtA0s50OfUSv+hCaFzpIRgUMKKtUTkUPj2R8TB85tq sNfi6lAPHEnVBXoPkvtllsgSP+AQxqJA3z3yA0MU7/8zXx6TQCdVgM5kv7jsycTqiO8o pbyyb7piCnymz7qCMrSziTjyyPTiEezUxL8aZakFHUXpG+jeKHmXYZYAdbZFeywzZ8BZ 8rV9a22O0/HOil8o+jJwskmhMPPHvUhwVAG1Z+db2UD4DloUFkK7h9p9eges/xIqkqEh G1dicWCNQS9FltNHLW7R37kNbntR30lcXTQAB+43Zg08NFzGWpuNun3/aaaJzga4JFN9 H39A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713200591; x=1713805391; 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=H3zPkz1xxC1CxVIHCuATW1be05yVqY6yZ3K4WTU3dxk=; b=gjo1WVDAypEUW9PgH7TQO4D6974pDUAwaowDhzz58PZ/LayPuOuSezGWOI0bwLeO5q Iar7X5cteRqs84no9AjqrjOhDkeNKjhLYUTSxphWDFb4cZyfBWZO8viXrgWDIgfEb23e fZm2YY3r57LVHjAf5lgeLjYkTXyrdvFJGxm8qzrZNQLBqWcFziPSnv57OcJ+OoHevJLt vbJswcE3dPmWhV1bNx67Yg0rT+qz5D8+e57vQ3u4C90p6Fe+sJsf8Of0QpST+1RjkBvt /i8m+63K6dUoGNcyHABU5tETxvYeedYrTmun1SU9hOErnOdOAAO93sC8jHtpbd8wgMM/ aWuw== X-Forwarded-Encrypted: i=1; AJvYcCUJ4/CV/3OOcIkJJjiGOQdAS66KWQg8fOJ0i/8FyoOqcayLJzN7gBk742CY4EKH1omAfcSYkbGVNXI2Ya7CNEksqmOhBKf0/prKWef0 X-Gm-Message-State: AOJu0Yycnh4V4qiMAIXW0QaLHIw8oH2nw+VbksWMV8qy3aqD6tMa1ZNW 9NRb0Z9kFgxDTnEN3KcnZn0WBd1PJivohS5tVPSFjXrLfCPysUG50QQMPVR8tlI= X-Received: by 2002:a05:6a20:8420:b0:1a7:ab39:4356 with SMTP id c32-20020a056a20842000b001a7ab394356mr14647289pzd.10.1713200591065; Mon, 15 Apr 2024 10:03:11 -0700 (PDT) Received: from sunil-pc.Dlink ([106.51.187.230]) by smtp.gmail.com with ESMTPSA id 1-20020a056a00072100b006ed045e3a70sm7433158pfm.25.2024.04.15.10.03.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 10:03:10 -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 , Haibo1 Xu , Conor Dooley , Andrew Jones , Atish Kumar Patra , Andrei Warkentin , Marc Zyngier , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Sunil V L Subject: [RFC PATCH v4 16/20] irqchip: riscv-aplic: Add ACPI support Date: Mon, 15 Apr 2024 22:31:09 +0530 Message-Id: <20240415170113.662318-17-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240415170113.662318-1-sunilvl@ventanamicro.com> References: <20240415170113.662318-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. It used the namespace device to probe and MADT to get other details required. 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 | 20 ++++--- drivers/irqchip/irq-riscv-aplic-main.c | 70 ++++++++++++++++-------- drivers/irqchip/irq-riscv-aplic-main.h | 1 + drivers/irqchip/irq-riscv-aplic-msi.c | 9 ++- 4 files changed, 67 insertions(+), 33 deletions(-) diff --git a/drivers/irqchip/irq-riscv-aplic-direct.c b/drivers/irqchip/irq-riscv-aplic-direct.c index 06bace9b7497..ccf08e617e5a 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 @@ -192,17 +193,20 @@ 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; 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)) { + rc = acpi_get_ext_intc_parent_hartid(priv->id, index, parent_hartid); + if (rc) + return rc; + + *parent_hwirq = RV_IRQ_EXT; + return 0; + } rc = of_irq_parse_one(to_of_node(dev->fwnode), index, &parent); if (rc) @@ -240,7 +244,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; - } - - /* - * 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++; + 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++; + } + } 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