Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp432619lqm; Wed, 1 May 2024 05:26:51 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUARauz2Uwj6mxLzACoHwnDMC92ikzXiRNeWxZPTT4OQoFlGt29cvlV4KoQxdoLs9mT+SjKkaTxwSenlMmr+CSn31ScrTraPXrOMCYHFQ== X-Google-Smtp-Source: AGHT+IG30HrOZXAdIaiukJjnSlyR3HS5DsNQTxveUIen/awt49uk87T1nHcxbHGBvwd1Ahtxg4qP X-Received: by 2002:a05:6a20:7351:b0:1af:51d1:eab6 with SMTP id v17-20020a056a20735100b001af51d1eab6mr2484448pzc.45.1714566411177; Wed, 01 May 2024 05:26:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714566411; cv=pass; d=google.com; s=arc-20160816; b=XRQSoQyD7JVdf2n0ycOINzqGWM614bMGAXnXQiznZACgkGJ978eNtC3m9Z1v6+N8Bs LnjiMS5qXEkUqv17V7q3TjbBXRzB3/7T0rBnOAf+mAYMJuYeIkCg328R6KF9d8YzQQif tCa8Ebd7+10kP96klJBT/azFABS1UtSp9FklIE4Qo8KK2witDB9Hdaz9WQO6eTGpeck3 b5N3WM67BOdgaPNZf24zcIgxapYyTZTeT6tG0vfIvOH8LS3EaDjOv29pCQhAX7kHe6dz XrFGum1VCkFyovJfyMJRXYVLUrb0DhSssplN8RI+/0dBDLiTS0cvdl5HLzOiF8QKDMkM vVFQ== 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=sCs3yrmzFwEswQj2N8wV0vpYdlRUqd+77n2ry9m3784=; fh=oTGrn71T8UaEOYHlkO6jhJ4WJs7/7xO5ekHg6c2bcL8=; b=nMkMXq+1wLUxNMl9sXkSBltwlvwe4t/eifWerz7MEjFzeU7ArecXYfTF8JpmQQvVXE BGVUOpwaY+q+bjwkgHIm+5gAJgoApq1sgy83ymoYtGFawtU7xWcHCsyfzV9wJ1RK1N89 bJx41l953MRFukIMroKjcrUtSzMdI4hM6fk1TydRQ5rEtkooPmC88N88Vv07jPfP1lja 7ObfrhJkYNDJHOLG28NVG0fQ1MnlClW2ab0VkrEOsU2C7Yd134GZo1bgRdLxeMonj9JX CQ4n73YmjyoNPIxg/kBhUcyAOyATS+tW7pf21l+VX+K5Wef1gXNdqivt3OToWeYuVqKU YBsA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=DRcpgpEN; arc=pass (i=1 spf=pass spfdomain=ventanamicro.com dkim=pass dkdomain=ventanamicro.com); spf=pass (google.com: domain of linux-kernel+bounces-165232-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-165232-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 ge3-20020a056a00838300b006ecdea272c2si23807091pfb.189.2024.05.01.05.26.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 May 2024 05:26:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-165232-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=DRcpgpEN; arc=pass (i=1 spf=pass spfdomain=ventanamicro.com dkim=pass dkdomain=ventanamicro.com); spf=pass (google.com: domain of linux-kernel+bounces-165232-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-165232-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 8BA27B23CB3 for ; Wed, 1 May 2024 12:23:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E3BEF12FF7D; Wed, 1 May 2024 12:20:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="DRcpgpEN" Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 6147E128385 for ; Wed, 1 May 2024 12:20:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714566009; cv=none; b=uQ3p36LjipItSyyLeJefmviVZHZ06PzQ5RWTYN3yHqDPO8OFklQUXkBJVoiMxFbqPYOdLGti6GzIC6+UrZYFiT8cxZXhsxxQOtHFTm27p0geSkk2STHdEbZcRTpaWxUR8k7V8qBBJ5hK3RP/BSobEx657pPnMHNmE8uCfAmPe+E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714566009; c=relaxed/simple; bh=m6TSaqDnA4vNxdsvAdEsFy7ZWBxeRMhznnW8/gHp2ag=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ayBNBOgvPUNirGvzWSFBnObG3QsWQsodN0VWzCnMvBFZyEXbs4/fyC7ykS2WN/7OnW30OmevsvprLO8xLg3ZLdvkirevWkifzCU1XBNvAB83nVmsDMLEsQ+o+QP1JVcplWuN40CDePhoiz6GrxVp31zK9LXQ9kHgnJ1o4vKGbG0= 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=DRcpgpEN; arc=none smtp.client-ip=209.85.214.180 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-f180.google.com with SMTP id d9443c01a7336-1e9ffd3f96eso54548385ad.3 for ; Wed, 01 May 2024 05:20:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1714566008; x=1715170808; 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=sCs3yrmzFwEswQj2N8wV0vpYdlRUqd+77n2ry9m3784=; b=DRcpgpEN5mKVeJmcdK8mPgOLT4hftb/Sm7Y/6UQqNMwV6Mh190Gg4ytwn3Zdplw7qb yRU9SovhmqWpTv2qflFvir3UuYu3yXRI4RohidsXIuYKzOuhdPTB2RZrQGghhF5YD29U 6L7YWRP1WJciPA30b6Rf+4c8NOcNcogx+aWJlYBAF+0GABai7bY2O+MLRSTnQbke+RSW I+IenjwArZLcyjIKn+Lqz6lirH0p/+8o3ZxTM15KGVDY+mKHnJUwyQqiUs0KOEgFTV4A R8zTLRHFLZmZ05UxnjquD4t10MjgdD1+97R4QJFHQPmfEJZ9PpOP+j72nQdXB97V0tLG rlNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714566008; x=1715170808; 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=sCs3yrmzFwEswQj2N8wV0vpYdlRUqd+77n2ry9m3784=; b=S0OpRi3hlhcMcBktONyApOXpMo/p4pEOcUh8Rj2UgjVOuiKabrolgg09H/DHiQqRLh AxaCoqdCid1S6lumn4qaPtPSBT2jlJo1rlWIdEAAzcGQXGBVmr8xA3cZzMhMSeRvaEL2 YSaxRjUjLbk63p8T/2skj72vxXfT1aMi31BOjncRhmRYBXNNJdHVZDCVFds77ef7NKLe Y5xUu4NVPNyZdlUz0GNim8Ljo3MOtmPbM8MZaSdgqOG42wdR+ZEwMr5BbJmMcq4/uUvU cuhV9oIpmAK0WYmmAwRFQxg9zym0Akr5AOwSi059heHEv1xLsv70GMYClphSMsKCgNdm y/4w== X-Forwarded-Encrypted: i=1; AJvYcCVYPrPkCGlp3kwEbLAs3tF5eKYKSYrpz6no4BFvEV6broF9q48POMlj5oCvdvFLhkKUz+vT2NZ0p7sbGLbsmDJVjWNKrFNA9bi4KDRe X-Gm-Message-State: AOJu0YwWA0kUEdJSrKbpfCLz3GjG+LlGYAeafeoL1K3CwYhvTIaBtew2 s7sclIpNIJnmqT1YBsEhix4ss0JZ7gn2W/z1tbDzzPYc+4L0lRwUJQwuLC26vFQ= X-Received: by 2002:a17:903:2303:b0:1eb:7172:673b with SMTP id d3-20020a170903230300b001eb7172673bmr2574288plh.16.1714566007835; Wed, 01 May 2024 05:20:07 -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.20.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 May 2024 05:20:07 -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 16/17] irqchip/sifive-plic: Add ACPI support Date: Wed, 1 May 2024 17:47:41 +0530 Message-Id: <20240501121742.1215792-17-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: 8bit Add ACPI support in PLIC driver. Use the mapping created early during boot to get details about the PLIC. Signed-off-by: Sunil V L Co-developed-by: Haibo Xu Signed-off-by: Haibo Xu --- drivers/irqchip/irq-sifive-plic.c | 89 +++++++++++++++++++++++-------- 1 file changed, 68 insertions(+), 21 deletions(-) diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c index 8fb183ced1e7..b6b04b5923c2 100644 --- a/drivers/irqchip/irq-sifive-plic.c +++ b/drivers/irqchip/irq-sifive-plic.c @@ -3,6 +3,7 @@ * Copyright (C) 2017 SiFive * Copyright (C) 2018 Christoph Hellwig */ +#include #include #include #include @@ -70,6 +71,8 @@ struct plic_priv { unsigned long plic_quirks; unsigned int nr_irqs; unsigned long *prio_save; + u32 gsi_base; + int id; }; struct plic_handler { @@ -324,6 +327,10 @@ static int plic_irq_domain_translate(struct irq_domain *d, { struct plic_priv *priv = d->host_data; + /* For DT, gsi_base is always zero. */ + if (fwspec->param[0] >= priv->gsi_base) + fwspec->param[0] = fwspec->param[0] - priv->gsi_base; + if (test_bit(PLIC_QUIRK_EDGE_INTERRUPT, &priv->plic_quirks)) return irq_domain_translate_twocell(d, fwspec, hwirq, type); @@ -424,18 +431,32 @@ static const struct of_device_id plic_match[] = { {} }; +#ifdef CONFIG_ACPI + +static const struct acpi_device_id plic_acpi_match[] = { + { "RSCV0001", 0 }, + {} +}; +MODULE_DEVICE_TABLE(acpi, plic_acpi_match); + +#endif static int plic_parse_nr_irqs_and_contexts(struct platform_device *pdev, - u32 *nr_irqs, u32 *nr_contexts) + u32 *nr_irqs, u32 *nr_contexts, + u32 *gsi_base, u32 *id) { struct device *dev = &pdev->dev; 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)) { + riscv_acpi_get_gsi_info(dev->fwnode, gsi_base, id, nr_irqs, NULL); + acpi_get_plic_nr_contexts(*id, nr_contexts); + if (WARN_ON(!*nr_contexts)) { + dev_err(dev, "no PLIC context available\n"); + return -EINVAL; + } + + return 0; + } rc = of_property_read_u32(to_of_node(dev->fwnode), "riscv,ndev", nr_irqs); if (rc) { @@ -449,23 +470,29 @@ static int plic_parse_nr_irqs_and_contexts(struct platform_device *pdev, return -EINVAL; } + *gsi_base = 0; + *id = 0; + return 0; } static int plic_parse_context_parent(struct platform_device *pdev, u32 context, - u32 *parent_hwirq, int *parent_cpu) + u32 *parent_hwirq, int *parent_cpu, u32 id) { struct device *dev = &pdev->dev; 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)) { + rc = acpi_get_ext_intc_parent_hartid(id, context, &hartid); + if (rc) + return rc; + + *parent_cpu = riscv_hartid_to_cpuid(hartid); + *parent_hwirq = RV_IRQ_EXT; + return 0; + } rc = of_irq_parse_one(to_of_node(dev->fwnode), context, &parent); if (rc) @@ -490,7 +517,9 @@ static int plic_probe(struct platform_device *pdev) struct irq_domain *domain; struct plic_priv *priv; irq_hw_number_t hwirq; + int id, context_id; bool cpuhp_setup; + u32 gsi_base; if (is_of_node(dev->fwnode)) { const struct of_device_id *id; @@ -500,7 +529,7 @@ static int plic_probe(struct platform_device *pdev) plic_quirks = (unsigned long)id->data; } - error = plic_parse_nr_irqs_and_contexts(pdev, &nr_irqs, &nr_contexts); + error = plic_parse_nr_irqs_and_contexts(pdev, &nr_irqs, &nr_contexts, &gsi_base, &id); if (error) return error; @@ -511,6 +540,8 @@ static int plic_probe(struct platform_device *pdev) priv->dev = dev; priv->plic_quirks = plic_quirks; priv->nr_irqs = nr_irqs; + priv->gsi_base = gsi_base; + priv->id = id; priv->regs = devm_platform_ioremap_resource(pdev, 0); if (WARN_ON(!priv->regs)) @@ -521,12 +552,22 @@ static int plic_probe(struct platform_device *pdev) return -ENOMEM; for (i = 0; i < nr_contexts; i++) { - error = plic_parse_context_parent(pdev, i, &parent_hwirq, &cpu); + error = plic_parse_context_parent(pdev, i, &parent_hwirq, &cpu, priv->id); if (error) { dev_warn(dev, "hwirq for context%d not found\n", i); continue; } + if (is_of_node(dev->fwnode)) { + context_id = i; + } else { + error = acpi_get_plic_context(priv->id, i, &context_id); + if (error) { + dev_warn(dev, "invalid context id for context%d\n", i); + continue; + } + } + /* * Skip contexts other than external interrupts for our * privilege level. @@ -572,10 +613,10 @@ static int plic_probe(struct platform_device *pdev) cpumask_set_cpu(cpu, &priv->lmask); handler->present = true; handler->hart_base = priv->regs + CONTEXT_BASE + - i * CONTEXT_SIZE; + context_id * CONTEXT_SIZE; raw_spin_lock_init(&handler->enable_lock); handler->enable_base = priv->regs + CONTEXT_ENABLE_BASE + - i * CONTEXT_ENABLE_SIZE; + context_id * CONTEXT_ENABLE_SIZE; handler->priv = priv; handler->enable_save = devm_kcalloc(dev, DIV_ROUND_UP(nr_irqs, 32), @@ -591,8 +632,8 @@ static int plic_probe(struct platform_device *pdev) nr_handlers++; } - priv->irqdomain = irq_domain_add_linear(to_of_node(dev->fwnode), nr_irqs + 1, - &plic_irqdomain_ops, priv); + priv->irqdomain = irq_domain_create_linear(dev->fwnode, nr_irqs + 1, + &plic_irqdomain_ops, priv); if (WARN_ON(!priv->irqdomain)) goto fail_cleanup_contexts; @@ -619,13 +660,18 @@ static int plic_probe(struct platform_device *pdev) } } +#ifdef CONFIG_ACPI + if (!acpi_disabled) + acpi_dev_clear_dependencies(ACPI_COMPANION(dev)); +#endif + dev_info(dev, "mapped %d interrupts with %d handlers for %d contexts.\n", nr_irqs, nr_handlers, nr_contexts); return 0; fail_cleanup_contexts: for (i = 0; i < nr_contexts; i++) { - if (plic_parse_context_parent(pdev, i, &parent_hwirq, &cpu)) + if (plic_parse_context_parent(pdev, i, &parent_hwirq, &cpu, priv->id)) continue; if (parent_hwirq != RV_IRQ_EXT || cpu < 0) continue; @@ -644,6 +690,7 @@ static struct platform_driver plic_driver = { .driver = { .name = "riscv-plic", .of_match_table = plic_match, + .acpi_match_table = ACPI_PTR(plic_acpi_match), }, .probe = plic_probe, }; -- 2.40.1