Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp736479pxu; Wed, 6 Jan 2021 03:03:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJy648DlDwpfmM4Ogg3HZ3jyCbEJqkBi+/g/OWWLwGxhRure6PO1tsLklE3ZONevhYJ/tiwk X-Received: by 2002:a17:906:3404:: with SMTP id c4mr2586216ejb.86.1609931036827; Wed, 06 Jan 2021 03:03:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609931036; cv=none; d=google.com; s=arc-20160816; b=Nd4VtKoU9f9/6XhGzTbo+/zXUWAIGFPbrW5VI95nqnZX18S85LxVgOwL5T3kD6tdsS xcvfJLi+nkDAPTqOLDpr3DUdEAGqtA6XrbR3EImsOKHvg9s4vbrD5g0zmxJOdkmyww+k Tx7312ftejQWT3Y7hv40hSFTX7KOiB4d0m1AiRjRkGbneKfnr/QVTSlglpViuz9sax77 vwgOJMRbdzXi/QvbnxnifuThtipvMMvrfu/ealhEDQkaQB411rXQmHfznAjTE9VFPXij 2ArJG0WTWPdPbE3ONOsSh3EzGJS3UNI0I/0/sqdoS5GjQJ7xlJbH+efp/nwg+SSYJW9D gWaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:user-agent:references:in-reply-to :subject:cc:to:from:date:content-transfer-encoding:mime-version; bh=j7ugc7ilizbJr1jmkY6EMydfqp+x4xB15fo6H15jk9o=; b=hoc3xct2CMEuZp26Lnt6c4eQMsB5aCv/a81z+1wWQHjVmjeI+kWVv+6NVKWIVIqnP3 VrWg064VLqVZKOzglJZLk0L77I57P2O4H8IenwAML4fakdbxlGM0o5GnVbzdpBqgS6MG VOoinieK5RtElmyKfN6Z++G/f8ZOjFc8vWFIQ6NsZocGhgRtt6OcUFQrKOuce18/zmx1 bK+g6JN/Lsp7dYmFSnlZ0C53KNjxKYaxgv2JaOgC/gYbyCNd2V4O15v5WuN57zPbGZaD tkeMMdwkkUF/c2LGc06Zz70w7dU++f7mgfP1jLj/PxMEcw1EC8SDLH8IgTwj2pyVz2gf q6pg== 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c23si748191ejx.330.2021.01.06.03.03.31; Wed, 06 Jan 2021 03:03:56 -0800 (PST) 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726712AbhAFLAK (ORCPT + 99 others); Wed, 6 Jan 2021 06:00:10 -0500 Received: from mail.kernel.org ([198.145.29.99]:36670 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726433AbhAFLAJ (ORCPT ); Wed, 6 Jan 2021 06:00:09 -0500 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2B16222C9F; Wed, 6 Jan 2021 10:59:28 +0000 (UTC) Received: from disco-boy.misterjones.org ([51.254.78.96] helo=www.loen.fr) by disco-boy.misterjones.org with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94) (envelope-from ) id 1kx6XG-005cMk-0h; Wed, 06 Jan 2021 10:59:26 +0000 MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Wed, 06 Jan 2021 10:59:25 +0000 From: Marc Zyngier To: "Chia-Wei, Wang" Cc: robh+dt@kernel.org, joel@jms.id.au, andrew@aj.id.au, tglx@linutronix.de, p.zabel@pengutronix.de, linux-aspeed@lists.ozlabs.org, openbmc@lists.ozlabs.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, BMC-SW@aspeedtech.com Subject: Re: [PATCH 4/6] irqchip/aspeed: Add Aspeed eSPI interrupt controller In-Reply-To: <20210106055939.19386-5-chiawei_wang@aspeedtech.com> References: <20210106055939.19386-1-chiawei_wang@aspeedtech.com> <20210106055939.19386-5-chiawei_wang@aspeedtech.com> User-Agent: Roundcube Webmail/1.4.9 Message-ID: <123bc25c72b3b17c0c4154d8bd8ce3b0@kernel.org> X-Sender: maz@kernel.org X-SA-Exim-Connect-IP: 51.254.78.96 X-SA-Exim-Rcpt-To: chiawei_wang@aspeedtech.com, robh+dt@kernel.org, joel@jms.id.au, andrew@aj.id.au, tglx@linutronix.de, p.zabel@pengutronix.de, linux-aspeed@lists.ozlabs.org, openbmc@lists.ozlabs.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, BMC-SW@aspeedtech.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021-01-06 05:59, Chia-Wei, Wang wrote: > The eSPI interrupt controller acts as a SW IRQ number > decoder to correctly control/dispatch interrupts of > the eSPI peripheral, virtual wire, out-of-band, and > flash channels. > > Signed-off-by: Chia-Wei, Wang > --- > drivers/irqchip/Makefile | 2 +- > drivers/irqchip/irq-aspeed-espi-ic.c | 251 ++++++++++++++++++++++++ > include/soc/aspeed/espi.h | 279 +++++++++++++++++++++++++++ > 3 files changed, 531 insertions(+), 1 deletion(-) > create mode 100644 drivers/irqchip/irq-aspeed-espi-ic.c > create mode 100644 include/soc/aspeed/espi.h > > diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile > index 0ac93bfaec61..56da4a3123f8 100644 > --- a/drivers/irqchip/Makefile > +++ b/drivers/irqchip/Makefile > @@ -86,7 +86,7 @@ obj-$(CONFIG_MVEBU_PIC) += irq-mvebu-pic.o > obj-$(CONFIG_MVEBU_SEI) += irq-mvebu-sei.o > obj-$(CONFIG_LS_EXTIRQ) += irq-ls-extirq.o > obj-$(CONFIG_LS_SCFG_MSI) += irq-ls-scfg-msi.o > -obj-$(CONFIG_ARCH_ASPEED) += irq-aspeed-vic.o irq-aspeed-i2c-ic.o > irq-aspeed-scu-ic.o > +obj-$(CONFIG_ARCH_ASPEED) += irq-aspeed-vic.o irq-aspeed-i2c-ic.o > irq-aspeed-scu-ic.o irq-aspeed-espi-ic.o > obj-$(CONFIG_STM32_EXTI) += irq-stm32-exti.o > obj-$(CONFIG_QCOM_IRQ_COMBINER) += qcom-irq-combiner.o > obj-$(CONFIG_IRQ_UNIPHIER_AIDET) += irq-uniphier-aidet.o > diff --git a/drivers/irqchip/irq-aspeed-espi-ic.c > b/drivers/irqchip/irq-aspeed-espi-ic.c > new file mode 100644 > index 000000000000..8a5cc8fe3f0c > --- /dev/null > +++ b/drivers/irqchip/irq-aspeed-espi-ic.c > @@ -0,0 +1,251 @@ > +// SPDX-License-Identifier: GPL-2.0-or-later > +/* > + * Copyright (c) 2020 Aspeed Technology Inc. > + */ > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include > +#include > + > +#define DEVICE_NAME "aspeed-espi-ic" > +#define IRQCHIP_NAME "eSPI-IC" > + > +#define ESPI_IC_IRQ_NUM 7 > + > +struct aspeed_espi_ic { > + struct regmap *map; > + int irq; > + int gpio_irq; > + struct irq_domain *irq_domain; > +}; > + > +static void aspeed_espi_ic_gpio_isr(struct irq_desc *desc) > +{ > + unsigned int irq; > + struct aspeed_espi_ic *espi_ic = irq_desc_get_handler_data(desc); > + struct irq_chip *chip = irq_desc_get_chip(desc); > + > + chained_irq_enter(chip, desc); > + > + irq = irq_find_mapping(espi_ic->irq_domain, > + ASPEED_ESPI_IC_CTRL_RESET); > + generic_handle_irq(irq); > + > + irq = irq_find_mapping(espi_ic->irq_domain, > + ASPEED_ESPI_IC_CHAN_RESET); > + generic_handle_irq(irq); So for each mux interrupt, you generate two endpoints interrupt, without even checking whether they are pending? That's no good. > + > + chained_irq_exit(chip, desc); > +} > + > +static void aspeed_espi_ic_isr(struct irq_desc *desc) > +{ > + unsigned int sts; > + unsigned int irq; > + struct aspeed_espi_ic *espi_ic = irq_desc_get_handler_data(desc); > + struct irq_chip *chip = irq_desc_get_chip(desc); > + > + chained_irq_enter(chip, desc); > + > + regmap_read(espi_ic->map, ESPI_INT_STS, &sts); > + > + if (sts & ESPI_INT_STS_PERIF_BITS) { > + irq = irq_find_mapping(espi_ic->irq_domain, > + ASPEED_ESPI_IC_PERIF_EVENT); > + generic_handle_irq(irq); > + } > + > + if (sts & ESPI_INT_STS_VW_BITS) { > + irq = irq_find_mapping(espi_ic->irq_domain, > + ASPEED_ESPI_IC_VW_EVENT); > + generic_handle_irq(irq); > + } > + > + if (sts & ESPI_INT_STS_OOB_BITS) { > + irq = irq_find_mapping(espi_ic->irq_domain, > + ASPEED_ESPI_IC_OOB_EVENT); > + generic_handle_irq(irq); > + } > + > + if (sts & ESPI_INT_STS_FLASH_BITS) { > + irq = irq_find_mapping(espi_ic->irq_domain, > + ASPEED_ESPI_IC_FLASH_EVENT); > + generic_handle_irq(irq); > + } > + > + if (sts & ESPI_INT_STS_HW_RST_DEASSERT) { > + irq = irq_find_mapping(espi_ic->irq_domain, > + ASPEED_ESPI_IC_CTRL_EVENT); > + generic_handle_irq(irq); > + } This is horrible. Why can't you just use fls() in a loop? > + > + chained_irq_exit(chip, desc); > +} > + > +static void aspeed_espi_ic_irq_disable(struct irq_data *data) > +{ > + struct aspeed_espi_ic *espi_ic = irq_data_get_irq_chip_data(data); > + > + switch (data->hwirq) { > + case ASPEED_ESPI_IC_CTRL_EVENT: > + regmap_update_bits(espi_ic->map, ESPI_INT_EN, > + ESPI_INT_EN_HW_RST_DEASSERT, > + 0); > + break; > + case ASPEED_ESPI_IC_PERIF_EVENT: > + regmap_update_bits(espi_ic->map, ESPI_INT_EN, > + ESPI_INT_EN_PERIF_BITS, 0); > + break; > + case ASPEED_ESPI_IC_VW_EVENT: > + regmap_update_bits(espi_ic->map, ESPI_INT_EN, > + ESPI_INT_EN_VW_BITS, 0); > + break; > + case ASPEED_ESPI_IC_OOB_EVENT: > + regmap_update_bits(espi_ic->map, ESPI_INT_EN, > + ESPI_INT_EN_OOB_BITS, 0); > + break; > + case ASPEED_ESPI_IC_FLASH_EVENT: > + regmap_update_bits(espi_ic->map, ESPI_INT_EN, > + ESPI_INT_EN_FLASH_BITS, 0); > + break; > + } Most of these are masking multiple events at once, which makes me think that it really doesn't belong here... > +} > + > +static void aspeed_espi_ic_irq_enable(struct irq_data *data) > +{ > + struct aspeed_espi_ic *espi_ic = irq_data_get_irq_chip_data(data); > + > + switch (data->hwirq) { > + case ASPEED_ESPI_IC_CTRL_EVENT: > + regmap_update_bits(espi_ic->map, ESPI_INT_EN, > + ESPI_INT_EN_HW_RST_DEASSERT, > + ESPI_INT_EN_HW_RST_DEASSERT); > + break; > + case ASPEED_ESPI_IC_PERIF_EVENT: > + regmap_update_bits(espi_ic->map, ESPI_INT_EN, > + ESPI_INT_EN_PERIF_BITS, > + ESPI_INT_EN_PERIF_BITS); > + break; > + case ASPEED_ESPI_IC_VW_EVENT: > + regmap_update_bits(espi_ic->map, ESPI_INT_EN, > + ESPI_INT_EN_VW_BITS, > + ESPI_INT_EN_VW_BITS); > + break; > + case ASPEED_ESPI_IC_OOB_EVENT: > + regmap_update_bits(espi_ic->map, ESPI_INT_EN, > + ESPI_INT_EN_OOB_BITS, > + ESPI_INT_EN_OOB_BITS); > + break; > + case ASPEED_ESPI_IC_FLASH_EVENT: > + regmap_update_bits(espi_ic->map, ESPI_INT_EN, > + ESPI_INT_EN_FLASH_BITS, > + ESPI_INT_EN_FLASH_BITS); > + break; > + } > +} > + > +static struct irq_chip aspeed_espi_ic_chip = { > + .name = IRQCHIP_NAME, > + .irq_enable = aspeed_espi_ic_irq_enable, > + .irq_disable = aspeed_espi_ic_irq_disable, > +}; > + > +static int aspeed_espi_ic_map(struct irq_domain *domain, unsigned int > irq, > + irq_hw_number_t hwirq) > +{ > + irq_set_chip_and_handler(irq, &aspeed_espi_ic_chip, > handle_simple_irq); > + irq_set_chip_data(irq, domain->host_data); > + > + return 0; > +} > + > +static const struct irq_domain_ops aspeed_espi_ic_domain_ops = { > + .map = aspeed_espi_ic_map, > +}; > + > +static int aspeed_espi_ic_probe(struct platform_device *pdev) > +{ > + struct device *dev; > + struct aspeed_espi_ic *espi_ic; > + > + dev = &pdev->dev; > + > + espi_ic = devm_kzalloc(dev, sizeof(*espi_ic), GFP_KERNEL); > + if (!espi_ic) > + return -ENOMEM; > + > + espi_ic->map = syscon_node_to_regmap(dev->parent->of_node); > + if (IS_ERR(espi_ic->map)) { > + dev_err(dev, "cannot get regmap\n"); > + return -ENODEV; > + } > + > + espi_ic->irq = platform_get_irq(pdev, 0); > + if (espi_ic->irq < 0) > + return espi_ic->irq; > + > + espi_ic->gpio_irq = platform_get_irq(pdev, 1); > + if (espi_ic->gpio_irq < 0) > + return espi_ic->gpio_irq; > + > + espi_ic->irq_domain = irq_domain_add_linear(dev->of_node, > ESPI_IC_IRQ_NUM, > + &aspeed_espi_ic_domain_ops, > + espi_ic); > + if (!espi_ic->irq_domain) { > + dev_err(dev, "cannot to add irq domain\n"); > + return -ENOMEM; > + } > + > + irq_set_chained_handler_and_data(espi_ic->irq, > + aspeed_espi_ic_isr, > + espi_ic); > + > + irq_set_chained_handler_and_data(espi_ic->gpio_irq, > + aspeed_espi_ic_gpio_isr, > + espi_ic); > + > + dev_set_drvdata(dev, espi_ic); > + > + dev_info(dev, "eSPI IRQ controller initialized\n"); > + > + return 0; > +} > + > +static int aspeed_espi_ic_remove(struct platform_device *pdev) > +{ > + struct aspeed_espi_ic *espi_ic = platform_get_drvdata(pdev); > + > + irq_domain_remove(espi_ic->irq_domain); > + return 0; > +} > + > +static const struct of_device_id aspeed_espi_ic_of_matches[] = { > + { .compatible = "aspeed,ast2600-espi-ic" }, > + { }, > +}; > + > +static struct platform_driver aspeed_espi_ic_driver = { > + .driver = { > + .name = DEVICE_NAME, > + .of_match_table = aspeed_espi_ic_of_matches, > + }, > + .probe = aspeed_espi_ic_probe, > + .remove = aspeed_espi_ic_remove, > +}; > + > +module_platform_driver(aspeed_espi_ic_driver); > + > +MODULE_AUTHOR("Chia-Wei Wang "); > +MODULE_AUTHOR("Ryan Chen "); > +MODULE_DESCRIPTION("Aspeed eSPI interrupt controller"); > +MODULE_LICENSE("GPL v2"); > diff --git a/include/soc/aspeed/espi.h b/include/soc/aspeed/espi.h > new file mode 100644 > index 000000000000..c9a4f51737ee > --- /dev/null > +++ b/include/soc/aspeed/espi.h > @@ -0,0 +1,279 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > +/* > + * Copyright (c) 2020 Aspeed Technology Inc. > + * Author: Chia-Wei Wang > + */ > +#ifndef _ASPEED_ESPI_H_ > +#define _ASPEED_ESPI_H_ [...] If nothing else uses the data here, move it to the irqchip driver. M. -- Jazz is not dead. It just smells funny...