From patchwork Tue Mar 28 12:21:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanjun Guo X-Patchwork-Id: 96165 Delivered-To: patch@linaro.org Received: by 10.182.246.10 with SMTP id xs10csp296851obc; Tue, 28 Mar 2017 05:22:55 -0700 (PDT) X-Received: by 10.84.232.67 with SMTP id f3mr35420973pln.42.1490703775503; Tue, 28 Mar 2017 05:22:55 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v3si4081553plb.128.2017.03.28.05.22.55; Tue, 28 Mar 2017 05:22:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751986AbdC1MWx (ORCPT + 18 others); Tue, 28 Mar 2017 08:22:53 -0400 Received: from mail-pg0-f42.google.com ([74.125.83.42]:34525 "EHLO mail-pg0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751599AbdC1MWu (ORCPT ); Tue, 28 Mar 2017 08:22:50 -0400 Received: by mail-pg0-f42.google.com with SMTP id 21so71255005pgg.1 for ; Tue, 28 Mar 2017 05:21:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=7ETTl5IkaobVvEjznInhCY5J/9jnQ1hagJW8sJu/JNY=; b=TXGg4FK6GP0Ev7b5U6Hpl6wnS7wjGYok2TN0tuhmF4zk+jvSBUsWAEd/uCtyIodzOv AqeWPu5jABdQ7ddRwPXRIajNnAlNUiEpGiSg5AEO1kW72EcT75XB4qnouou2ogkQ4qbD 5TviH5ZfXvvAzjlFgDFQTaEQB8uJuhUKuu8TU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=7ETTl5IkaobVvEjznInhCY5J/9jnQ1hagJW8sJu/JNY=; b=J11Sl2fEvQpuOTvqiD0Uk8QmTwbx29goRJJ776tUiXBqJ373jq/oLzBj2t5TQKilft CndMMAkxezN6ycDek5A5w3haWetC1qJp+q64Xr/FNi1KUMNg1EGt7mc/Y05zLaYiSnxH mzZT6REBtM/7bW8XMtBw4j3KgKCUkt2WxYhtpFDRtZQ7HPRR6WlnX7qZWD9IR2NYHGJT ZzxPhZHGGhaK5W1cvjUxKlGs4t+RrVWpTMt1MPYkeoTIf4HnYbgFj0RLJzbYb2cJFqWe +rNldfyCDhh4d0w3EmQkFy3icMv6FzyGj5QB5g8V7TDUg2x+Zk5QQFGbnNEUErP0KHWW dcqw== X-Gm-Message-State: AFeK/H0+jEEyUvFVp+hKnHMiWWOhHXpGjH6igE1zvczDqbhPJgoDLGZ+li/YSbkyInM++gm9 X-Received: by 10.98.32.72 with SMTP id g69mr2147375pfg.64.1490703717368; Tue, 28 Mar 2017 05:21:57 -0700 (PDT) Received: from localhost ([104.237.91.145]) by smtp.googlemail.com with ESMTPSA id f3sm7297642pga.34.2017.03.28.05.21.55 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 28 Mar 2017 05:21:56 -0700 (PDT) From: Hanjun Guo To: Marc Zyngier , "Rafael J. Wysocki" , Lorenzo Pieralisi Cc: linux-acpi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linuxarm@huawei.com, Thomas Gleixner , Kefeng Wang , huxinwei@huawei.com, yimin@huawei.com, Hanjun Guo , MaJun , Al Stone , Darren Hart Subject: [Update][PATCH v9.1 15/15] irqchip: mbigen: Add ACPI support Date: Tue, 28 Mar 2017 20:21:05 +0800 Message-Id: <1490703665-4932-1-git-send-email-hanjun.guo@linaro.org> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With the preparation of platform msi support and interrupt producer in commit d44fa3d46079 ("ACPI: Add support for ResourceSource/IRQ domain mapping"), we can add mbigen ACPI support now. Now that the major framework changes are ready, we just need to add the ACPI probe code which creates the irqdomain for devices connecting to it. In order to create the irqdomain, we need to know the number of hw irqs as input which is provided by mbigen. In DT case, we are using "num-pins" property to describe it, and we will take advantage of that too using _DSD in ACPI as there is no standard way of describe it in ACPI way, also according to the _DSD rule described in Documentation/acpi/DSD-properties-rules.txt, it doesn't break the rules. The DSDT is represented as below: For mbigen, Device(MBI0) { Name(_HID, "HISI0152") Name(_UID, Zero) Name(_CRS, ResourceTemplate() { Memory32Fixed(ReadWrite, 0xa0080000, 0x10000) }) Name(_DSD, Package () { ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"), Package () { Package () {"num-pins", 378} } }) } For devices, Device(SAS0) { Name(_HID, "HISIxxxx") Name(_UID, Zero) Name(_CRS, ResourceTemplate() { Memory32Fixed(ReadWrite, 0xb0030000, 0x10000) Interrupt(ResourceConsumer,..., "\_SB.MBI0") {12, ...} }) } So for the devices connected to the mbigen, as we clearly say that it refers to a specific interrupt controller (mbigen), we can get the virq from mbigen's irqdomain once it's created successfully. Signed-off-by: Hanjun Guo Signed-off-by: MaJun Cc: Al Stone Cc: Darren Hart Cc: Lorenzo Pieralisi Cc: Marc Zyngier --- drivers/irqchip/irq-mbigen.c | 75 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 3 deletions(-) -- 1.9.1 Tested-by: MaJun Tested-by: Wei Xu Reviewed-by: Al Stone diff --git a/drivers/irqchip/irq-mbigen.c b/drivers/irqchip/irq-mbigen.c index 3756408..061cdb8 100644 --- a/drivers/irqchip/irq-mbigen.c +++ b/drivers/irqchip/irq-mbigen.c @@ -16,6 +16,7 @@ * along with this program. If not, see . */ +#include #include #include #include @@ -180,7 +181,7 @@ static int mbigen_domain_translate(struct irq_domain *d, unsigned long *hwirq, unsigned int *type) { - if (is_of_node(fwspec->fwnode)) { + if (is_of_node(fwspec->fwnode) || is_acpi_device_node(fwspec->fwnode)) { if (fwspec->param_count != 2) return -EINVAL; @@ -271,6 +272,58 @@ static int mbigen_of_create_domain(struct platform_device *pdev, return 0; } +#ifdef CONFIG_ACPI +static int mbigen_acpi_create_domain(struct platform_device *pdev, + struct mbigen_device *mgn_chip) +{ + struct irq_domain *domain; + u32 num_pins = 0; + int ret; + + /* + * "num-pins" is the total number of interrupt pins implemented in + * this mbigen instance, and mbigen is an interrupt controller + * connected to ITS converting wired interrupts into MSI, so we + * use "num-pins" to alloc MSI vectors which are needed by client + * devices connected to it. + * + * Here is the DSDT device node used for mbigen in firmware: + * Device(MBI0) { + * Name(_HID, "HISI0152") + * Name(_UID, Zero) + * Name(_CRS, ResourceTemplate() { + * Memory32Fixed(ReadWrite, 0xa0080000, 0x10000) + * }) + * + * Name(_DSD, Package () { + * ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"), + * Package () { + * Package () {"num-pins", 378} + * } + * }) + * } + */ + ret = device_property_read_u32(&pdev->dev, "num-pins", &num_pins); + if (ret || num_pins == 0) + return -EINVAL; + + domain = platform_msi_create_device_domain(&pdev->dev, num_pins, + mbigen_write_msg, + &mbigen_domain_ops, + mgn_chip); + if (!domain) + return -ENOMEM; + + return 0; +} +#else +static inline int mbigen_acpi_create_domain(struct platform_device *pdev, + struct mbigen_device *mgn_chip) +{ + return -ENODEV; +} +#endif + static int mbigen_device_probe(struct platform_device *pdev) { struct mbigen_device *mgn_chip; @@ -289,9 +342,18 @@ static int mbigen_device_probe(struct platform_device *pdev) if (IS_ERR(mgn_chip->base)) return PTR_ERR(mgn_chip->base); - err = mbigen_of_create_domain(pdev, mgn_chip); - if (err) + if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node) + err = mbigen_of_create_domain(pdev, mgn_chip); + else if (ACPI_COMPANION(&pdev->dev)) + err = mbigen_acpi_create_domain(pdev, mgn_chip); + else + err = -EINVAL; + + if (err) { + dev_err(&pdev->dev, "Failed to create mbi-gen@%p irqdomain", + mgn_chip->base); return err; + } platform_set_drvdata(pdev, mgn_chip); return 0; @@ -303,10 +365,17 @@ static int mbigen_device_probe(struct platform_device *pdev) }; MODULE_DEVICE_TABLE(of, mbigen_of_match); +static const struct acpi_device_id mbigen_acpi_match[] = { + { "HISI0152", 0 }, + {} +}; +MODULE_DEVICE_TABLE(acpi, mbigen_acpi_match); + static struct platform_driver mbigen_platform_driver = { .driver = { .name = "Hisilicon MBIGEN-V2", .of_match_table = mbigen_of_match, + .acpi_match_table = ACPI_PTR(mbigen_acpi_match), }, .probe = mbigen_device_probe, };