Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp154565pxb; Tue, 24 Aug 2021 23:18:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz5XSBFA1be9r+Xcsz4fdT+8Gp3nNozq8oh9LLlW5v4QKPnYa9rYxrilzHhVC3VuyDiyYSz X-Received: by 2002:a50:ff06:: with SMTP id a6mr11051645edu.220.1629872298811; Tue, 24 Aug 2021 23:18:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629872298; cv=none; d=google.com; s=arc-20160816; b=QcdC7Nu7KNEhNxQumkzRf+r9z0VcrndJ+Dkii04Z4Y+fyt5Cyve0fzr+o3B4iWw0bV Bjq/PO6fm9EGfsjtV88hBpGxy8RHbk/otG0V4s1iFh3mM5a/dvjmEODjnH5zCTnpus1r uYobaPW/WDAmyP5NG7sUh08Jq3h59NM0tYJn+nNZ5HzG0c3h8aZtA62ZhyoI9fCckMTm M6NuL6jRz3eTtYmWbA0oaAtp5z4NJMLEwnhjdngghUOGprjbLHBYgoqWPTezZQwG7uwj mOo8iuvqskVE75DwZo+IY+hTMX4wU6v0/1U3Wn6eRsjESi9MA2XLKUWBzxkoFz80/3vx LVFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=UMN0JyfzZCpJYNgBgy1H/CWh3Ra3hDDKDYwdIXmYcMQ=; b=rbidNEPQefUMUMewEacHMYdG6MAuS4rn7ajyNnVXTrtfOgYihbTZtOfwTptXJ3vHlT GR/+MlpXg2R2RDszwU23ygFNHPUB1byw4Lu0y3ulAA393boQXDcAn6ncg4GsjJyVgzDE KeOE1koW23C6I0cI/n+6gIC1oonmzw+XGQoKwXM4cMDb7DBsZipCxUtdlMfwwFZShJkr aKQkGl/rkiKU1vljBWbggP8jF8nB2DfHjhOAkwo0ynKd+8gWv7d+I3+BxoVI+EqVlQCw k8TAinoD+zbRGOmJYZltavi+J6lqf/ocoZx8Syl1PGhGv5BV9Ir774p+Ru/0tVp6awjg FhcQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qw26si8599608ejc.258.2021.08.24.23.17.56; Tue, 24 Aug 2021 23:18:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238835AbhHYGOd (ORCPT + 99 others); Wed, 25 Aug 2021 02:14:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:47122 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238833AbhHYGOd (ORCPT ); Wed, 25 Aug 2021 02:14:33 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0D6E961181; Wed, 25 Aug 2021 06:13:45 +0000 (UTC) From: Huacai Chen To: Thomas Gleixner , Marc Zyngier Cc: linux-kernel@vger.kernel.org, Xuefeng Li , Huacai Chen , Jiaxun Yang , Huacai Chen Subject: [PATCH V3 04/10] irqchip/loongson-pch-msi: Add ACPI init support Date: Wed, 25 Aug 2021 14:11:46 +0800 Message-Id: <20210825061152.3396398-5-chenhuacai@loongson.cn> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210825061152.3396398-1-chenhuacai@loongson.cn> References: <20210825061152.3396398-1-chenhuacai@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We are preparing to add new Loongson (based on LoongArch, not MIPS) support. LoongArch use ACPI other than DT as its boot protocol, so add ACPI init support. Signed-off-by: Huacai Chen --- drivers/irqchip/irq-loongson-pch-msi.c | 126 ++++++++++++++++--------- 1 file changed, 84 insertions(+), 42 deletions(-) diff --git a/drivers/irqchip/irq-loongson-pch-msi.c b/drivers/irqchip/irq-loongson-pch-msi.c index 32562b7e681b..1ecb15f8745b 100644 --- a/drivers/irqchip/irq-loongson-pch-msi.c +++ b/drivers/irqchip/irq-loongson-pch-msi.c @@ -21,6 +21,7 @@ struct pch_msi_data { u32 irq_first; /* The vector number that MSIs starts */ u32 num_irqs; /* The number of vectors for MSIs */ unsigned long *msi_map; + struct fwnode_handle *domain_handle; }; static void pch_msi_mask_msi_irq(struct irq_data *d) @@ -154,12 +155,14 @@ static const struct irq_domain_ops pch_msi_middle_domain_ops = { }; static int pch_msi_init_domains(struct pch_msi_data *priv, - struct device_node *node, - struct irq_domain *parent) + struct irq_domain *parent, + struct fwnode_handle *domain_handle) { struct irq_domain *middle_domain, *msi_domain; - middle_domain = irq_domain_create_linear(of_node_to_fwnode(node), + priv->domain_handle = domain_handle; + + middle_domain = irq_domain_create_linear(priv->domain_handle, priv->num_irqs, &pch_msi_middle_domain_ops, priv); @@ -171,7 +174,7 @@ static int pch_msi_init_domains(struct pch_msi_data *priv, middle_domain->parent = parent; irq_domain_update_bus_token(middle_domain, DOMAIN_BUS_NEXUS); - msi_domain = pci_msi_create_irq_domain(of_node_to_fwnode(node), + msi_domain = pci_msi_create_irq_domain(priv->domain_handle, &pch_msi_domain_info, middle_domain); if (!msi_domain) { @@ -183,19 +186,11 @@ static int pch_msi_init_domains(struct pch_msi_data *priv, return 0; } -static int pch_msi_init(struct device_node *node, - struct device_node *parent) +static int pch_msi_init(phys_addr_t msg_address, int irq_base, int irq_count, + struct irq_domain *parent_domain, struct fwnode_handle *domain_handle) { - struct pch_msi_data *priv; - struct irq_domain *parent_domain; - struct resource res; int ret; - - parent_domain = irq_find_host(parent); - if (!parent_domain) { - pr_err("Failed to find the parent domain\n"); - return -ENXIO; - } + struct pch_msi_data *priv; priv = kzalloc(sizeof(*priv), GFP_KERNEL); if (!priv) @@ -203,38 +198,18 @@ static int pch_msi_init(struct device_node *node, mutex_init(&priv->msi_map_lock); - ret = of_address_to_resource(node, 0, &res); - if (ret) { - pr_err("Failed to allocate resource\n"); - goto err_priv; - } - - priv->doorbell = res.start; - - if (of_property_read_u32(node, "loongson,msi-base-vec", - &priv->irq_first)) { - pr_err("Unable to parse MSI vec base\n"); - ret = -EINVAL; - goto err_priv; - } - - if (of_property_read_u32(node, "loongson,msi-num-vecs", - &priv->num_irqs)) { - pr_err("Unable to parse MSI vec number\n"); - ret = -EINVAL; - goto err_priv; - } + priv->doorbell = msg_address; + priv->irq_first = irq_base; + priv->num_irqs = irq_count; priv->msi_map = bitmap_zalloc(priv->num_irqs, GFP_KERNEL); - if (!priv->msi_map) { - ret = -ENOMEM; + if (!priv->msi_map) goto err_priv; - } pr_debug("Registering %d MSIs, starting at %d\n", priv->num_irqs, priv->irq_first); - ret = pch_msi_init_domains(priv, node, parent_domain); + ret = pch_msi_init_domains(priv, parent_domain, domain_handle); if (ret) goto err_map; @@ -244,7 +219,74 @@ static int pch_msi_init(struct device_node *node, kfree(priv->msi_map); err_priv: kfree(priv); - return ret; + + return -EINVAL; +} + +#ifdef CONFIG_OF + +int pch_msi_of_init(struct device_node *node, struct device_node *parent) +{ + int err; + int irq_base, irq_count; + struct resource res; + struct irq_domain *parent_domain; + + parent_domain = irq_find_host(parent); + if (!parent_domain) { + pr_err("Failed to find the parent domain\n"); + return -ENXIO; + } + + if (of_address_to_resource(node, 0, &res)) { + pr_err("Failed to allocate resource\n"); + return -EINVAL; + } + + if (of_property_read_u32(node, "loongson,msi-base-vec", &irq_base)) { + pr_err("Unable to parse MSI vec base\n"); + return -EINVAL; + } + + if (of_property_read_u32(node, "loongson,msi-num-vecs", &irq_count)) { + pr_err("Unable to parse MSI vec number\n"); + return -EINVAL; + } + + err = pch_msi_init(res.start, irq_base, irq_count, parent_domain, of_node_to_fwnode(node)); + if (err < 0) + return err; + + return 0; +} + +IRQCHIP_DECLARE(pch_msi, "loongson,pch-msi-1.0", pch_msi_of_init); + +#endif + +#ifdef CONFIG_ACPI + +struct fwnode_handle *pch_msi_acpi_init(struct fwnode_handle *parent, + struct acpi_madt_msi_pic *acpi_pchmsi) +{ + int ret; + struct irq_domain *parent_domain; + struct fwnode_handle *domain_handle; + + parent_domain = irq_find_matching_fwnode(parent, DOMAIN_BUS_ANY); + if (!parent_domain) { + pr_err("Failed to find the parent domain\n"); + return NULL; + } + + domain_handle = irq_domain_alloc_fwnode((phys_addr_t *)acpi_pchmsi); + + ret = pch_msi_init(acpi_pchmsi->msg_address, acpi_pchmsi->start, + acpi_pchmsi->count, parent_domain, domain_handle); + if (ret < 0) + return NULL; + + return domain_handle; } -IRQCHIP_DECLARE(pch_msi, "loongson,pch-msi-1.0", pch_msi_init); +#endif -- 2.27.0