From patchwork Thu Feb 22 09:39:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 13566955 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5D4B0C48BF8 for ; Thu, 22 Feb 2024 09:42:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ayflwD54li1DE3zcKajscFmzSKFurye99kOijIa7LTw=; b=xqCULiS99V9+1k 7Ih081oQQRFoKky3qogXPhG9th86rL3ZVG44J52jDcfPSdBj8kL86b2rxpBMFJq9BeLwCzvjlELUb LyPIC3nb0wTQt1g8BsSclra2hRQCNX8vyiB1dJG9xHPv+B0qjSsYrw4pnE9cLwgS0FveFXQ2vIqlz vI5Z+ov6oBKQdeA3BhAhFFdZJGQOr3+Ny1/74OSffvE9/Rvy4U1UmcPBh2CKmqPGvWikd+n+37BZp ZmEZIGkSGA68DJXzm+tScn2Q2n7OEBborWwGdMCFOAG1Rzqa29DaTcmEM308cjEabw3UZBpjl/y+I HwbRiKAqEcyky7xWi3bA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rd5ai-00000004J2G-3kdS; Thu, 22 Feb 2024 09:42:08 +0000 Received: from mail-oi1-x231.google.com ([2607:f8b0:4864:20::231]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rd5Zi-00000004IDL-0HoT for linux-arm-kernel@lists.infradead.org; Thu, 22 Feb 2024 09:41:08 +0000 Received: by mail-oi1-x231.google.com with SMTP id 5614622812f47-3c15b7b36bbso562977b6e.1 for ; Thu, 22 Feb 2024 01:41:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1708594865; x=1709199665; darn=lists.infradead.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=67myGQfWdG/NTMsWtbLvxenqOsS6MBirvNDOIPSERro=; b=NEldiQJU+eS/KsTYbjPBSQhKkJVJQTMNOFJCQlRDw1MdTcZYBrSw0E9XmF5CnzOJkf Ofaznnx4SYl6+5J/eMfKkFTsPoBcWjdisDF63MNfFIkU4tYJx95DuqZKirh0wajmq+4B pmg7nmB+6VMlvD09KRG9rrqg5aDIbNFNEQ5Es+bHMTpyeY4YJnPN4CoZ77TneEpX19vH N/i4L3fFcrCcTIeST3M3wQDoREn6EauCrx4kVEi8V329HYGGez562jJorumijwgeig7S 9ft2SRQHXskTTt2fnvAg+ZBwLAMoqiPHde3AFgBR5cWSyRqkrBmLmsksgrxAiatvB5rg 6DFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708594865; x=1709199665; 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=67myGQfWdG/NTMsWtbLvxenqOsS6MBirvNDOIPSERro=; b=rQlJQH1Fi6D6ac/ynw1F3BEng8/e2GLNptDoYdbpChcjw7wGYT3ODJVfss5A5nGOxE QkXURKGowPYsaHJxjxFZiTo9NXVWKACeJblOmzEOdw2QlXJa8wkWEingwr6ogipe/WdL p8xKLek3BfJ6gt337xvJpzLrwRC+zS0IQqQvGi7xDRlbGAHvr8Cha2udafRZlQfb4wl3 JB5ryoifql0c+68W1hE/OC+1KjmOC6CMI9iv6o0hDpae/47PPuoWwIYezhHPncLh4weB ugBDD3qtp3nWX1gbyjuVwYI/6/r22+YIH8X/1kqzp4gfW4g+Efd2TSnUhpLX5xGlFtZC Yn3w== X-Forwarded-Encrypted: i=1; AJvYcCWrv2hPdMK2wqwdtzfAxcYRdYTyxk4Ozm+4NxwRKcgOWfZYhwQbAZbqsgHBPBsMomMblFkszOp3nXppGKFFERSlSFi/y7IwY7RuD5jvfhpZeIlDtYk= X-Gm-Message-State: AOJu0YxCq8V7z3SF4DbMI1/E945/iKf72WcIJ9r8rdZZDJdzLlSr4Q6p 5mFMzz08WQAT1ltNexbUqb7liYp9kInXQB3d1nWJ2d9jbAHT47fXMdvV81pW8FY= X-Google-Smtp-Source: AGHT+IEWljpjWcYNh6FWyteZzNizntERHCcdcGk1xA11bQ1Y2eMKvSMWtR4dupwFnRtiGSJXRVaPQw== X-Received: by 2002:a05:6808:200a:b0:3c1:54c9:be7b with SMTP id q10-20020a056808200a00b003c154c9be7bmr14031502oiw.12.1708594865151; Thu, 22 Feb 2024 01:41:05 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([103.97.165.210]) by smtp.gmail.com with ESMTPSA id n15-20020a05680803af00b003c17c2b8d09sm130699oie.31.2024.02.22.01.40.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 01:41:04 -0800 (PST) From: Anup Patel To: Palmer Dabbelt , Paul Walmsley , Thomas Gleixner , Rob Herring , Krzysztof Kozlowski , Frank Rowand , Conor Dooley Cc: Marc Zyngier , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Atish Patra , Andrew Jones , Sunil V L , Saravana Kannan , Anup Patel , linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Anup Patel Subject: [PATCH v14 06/18] irqchip/sifive-plic: Parse number of irqs and contexts early in plic_probe Date: Thu, 22 Feb 2024 15:09:54 +0530 Message-Id: <20240222094006.1030709-7-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222094006.1030709-1-apatel@ventanamicro.com> References: <20240222094006.1030709-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240222_014106_237084_B34DAE58 X-CRM114-Status: GOOD ( 17.36 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The SiFive PLIC driver needs to know the number of irqs and contexts to complete initialization. Parse these details early in plic_probe() to avoid unnecessary memory allocations and register mappings if these details are not available. Signed-off-by: Anup Patel --- drivers/irqchip/irq-sifive-plic.c | 43 ++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c index f0df5d0cb76e..e6d23fde51ed 100644 --- a/drivers/irqchip/irq-sifive-plic.c +++ b/drivers/irqchip/irq-sifive-plic.c @@ -416,6 +416,34 @@ static const struct of_device_id plic_match[] = { {} }; +static int plic_parse_nr_irqs_and_contexts(struct platform_device *pdev, + u32 *nr_irqs, u32 *nr_contexts) +{ + 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; + + rc = of_property_read_u32(to_of_node(dev->fwnode), "riscv,ndev", nr_irqs); + if (rc) { + dev_err(dev, "riscv,ndev property not available\n"); + return rc; + } + + *nr_contexts = of_irq_count(to_of_node(dev->fwnode)); + if (WARN_ON(!(*nr_contexts))) { + dev_err(dev, "no PLIC context available\n"); + return -EINVAL; + } + + return 0; +} + static int plic_parse_context_parent(struct platform_device *pdev, u32 context, u32 *parent_hwirq, int *parent_cpu) { @@ -464,31 +492,26 @@ 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); + if (error) + return error; + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); if (!priv) return -ENOMEM; priv->dev = dev; priv->plic_quirks = plic_quirks; + priv->nr_irqs = nr_irqs; priv->regs = devm_platform_ioremap_resource(pdev, 0); if (WARN_ON(!priv->regs)) return -EIO; - of_property_read_u32(to_of_node(dev->fwnode), "riscv,ndev", &nr_irqs); - if (WARN_ON(!nr_irqs)) - return -EINVAL; - - priv->nr_irqs = nr_irqs; - priv->prio_save = devm_bitmap_zalloc(dev, nr_irqs, GFP_KERNEL); if (!priv->prio_save) return -ENOMEM; - nr_contexts = of_irq_count(to_of_node(dev->fwnode)); - if (WARN_ON(!nr_contexts)) - return -EINVAL; - for (i = 0; i < nr_contexts; i++) { error = plic_parse_context_parent(pdev, i, &parent_hwirq, &cpu); if (error) {