Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp606665pxa; Wed, 19 Aug 2020 09:54:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwpsO0P3ZqOxI8BGUgN93qHmwENTYRPpWlwK/vrjHBpzoDH24HXhJxbzeA1PX8QORY7Whla X-Received: by 2002:a17:906:d209:: with SMTP id w9mr25516850ejz.93.1597856043750; Wed, 19 Aug 2020 09:54:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597856043; cv=none; d=google.com; s=arc-20160816; b=FjQR9kDY39WOl3uucfNTVzmI0tYcXpQ5rG2fjlqxLGnDgwmNA5BSMEQjVtuGxgg3nm 8lAJn+BbZ2OnCcOGb2BdXi50T077qCrCfggpwlQl0iFJ2fpPtEd9wIru6XmKw7o4QMFe 3gYkTechw3FPZOHJI7jy2Qky52wxo2pGYP/e2H/O7IChPtQPNem1nluatTZjyo5+xAuy 08paKMizwZxU48IBlAm0Oo4Q0xeMDv0MzPYyOlfxK7Z6Qt4FMxevBLaUsDaZMj52aPdS rC4afs1Udk9RFDzEkO1JJmIiixu2Gd4NSF+85Je4VLhrJV0HzimYk4GLqI/mqlXNj4Ze Gi+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Lu1L8Np4Sb1znwysVOMYeFd9PeezWxo0K5RLTh1iwF8=; b=ks+KFHJkQ9RSYxsLZ4GRUwfHXHscW7iTp0mbNkzg+H7zzgyPC16cWYeFOjLFZMCyEK 8FSu/VdneewTPcEvCm3ZAnx6ldUXSMCBcBzpU35iFuWc0Ssv93WPeSfq36KxuFdrveBv +bk6LVCnAMVRS3vP0iD+4a9fVqyMZUi6EipSlRShi87hinhegimek1J/I8RXaZlPdfYZ ebyqDUGsO8RQkNLbgZnQfPWN1qxq1oL+lj3/0MQSdi9cDghnk51pe4xc08HJtqc/snz4 RbJbwLwjCDx8nI1ayvIYnMyIHmSPBkRKiBJbcX+SWk1UTg7qckcgRAjOUGXaDoRJpZnh elTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mELPK41e; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d6si15948903ejy.409.2020.08.19.09.53.37; Wed, 19 Aug 2020 09:54:03 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mELPK41e; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726923AbgHSQwR (ORCPT + 99 others); Wed, 19 Aug 2020 12:52:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726211AbgHSQwO (ORCPT ); Wed, 19 Aug 2020 12:52:14 -0400 Received: from mail-ej1-x643.google.com (mail-ej1-x643.google.com [IPv6:2a00:1450:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04A7DC061757; Wed, 19 Aug 2020 09:52:14 -0700 (PDT) Received: by mail-ej1-x643.google.com with SMTP id bo3so27077206ejb.11; Wed, 19 Aug 2020 09:52:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=Lu1L8Np4Sb1znwysVOMYeFd9PeezWxo0K5RLTh1iwF8=; b=mELPK41eNWYV7XCpw+RnLESHqhS/nSXA6SruNKm9XqHomDbZgcdomg5q5FIYFGSOgF 57r/JqBVViqLKlIIsg4KLyBe+8DjxUn/C3Pxdj8RqwGLc09S8EnZ1QG4OsN8REr6N3cA M9xwDj9I+1WK7OWfJLVMDuugstPh+OdMFKN5xF+M1U3BL7npqHGqOFaoEGxTJIZextjX h51o68qT+7dEgZdmXXYLzP5h3cBRwnRkk2j8Moh/pdNLYDtvuLyYHGt0dZNXEibMbOHh bf/bOUyNZb6D6Ws0NgvGv5DJ63UXWsa8GHq2DiTJysjxkCsWRM8wgyxzQehSY1O1zaar i2ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=Lu1L8Np4Sb1znwysVOMYeFd9PeezWxo0K5RLTh1iwF8=; b=A2C3Q7SxF3ICTNUq71Iac5guKEhha+0uNvvuaH6BYGhoaAehluLisIpGCHKUoUpNMF 6VFhUiLIuYKPIfSstzWOfGKShc3FLgP6UtIFlgwLwgHSnGfomdRLnoaj3VO9zjumwb8i 8OnRW9hOj0P7igfK0Fktaspt04W47xb7TDlw1TSF1lVlnvw6PC5mG1Zm+mpJh2aIYKjx CMVSGZtOU40Van43oiDqSCiar99yauynPioVIzCc74touCYArrqIQViEdHIx+za7ltnl TBpB3X9yxuqxt3LOvEDK9DN7mx07jUC0X8X8Hd52vVLesQpgCZdMyv76MDGFfsR/wRlQ Ykdw== X-Gm-Message-State: AOAM530YzW0HLHyuihCyZeCxS2biwNA0vjVD0BKU80PS+jazTJxgYU+P 5ry7/K07xIDPtYTPnyvSOSw= X-Received: by 2002:a17:906:f8c3:: with SMTP id lh3mr26531749ejb.263.1597855932552; Wed, 19 Aug 2020 09:52:12 -0700 (PDT) Received: from BV030612LT ([188.24.144.238]) by smtp.gmail.com with ESMTPSA id u6sm19416937ejf.98.2020.08.19.09.52.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Aug 2020 09:52:12 -0700 (PDT) Date: Wed, 19 Aug 2020 19:52:09 +0300 From: Cristian Ciocaltea To: Marc Zyngier Cc: Thomas Gleixner , Jason Cooper , Rob Herring , Andreas =?iso-8859-1?Q?F=E4rber?= , Manivannan Sadhasivam , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-actions@lists.infradead.org, Saravanan Sekar Subject: Re: [PATCH v4 2/3] irqchip: Add Actions Semi Owl SIRQ controller Message-ID: <20200819165209.GA2137769@BV030612LT> References: <8e43fe6c6246bfd5347dc21b6f5c3f50@kernel.org> <20200818174241.GA2020288@BV030612LT> <87lfibn0ie.wl-maz@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <87lfibn0ie.wl-maz@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 18, 2020 at 09:48:41PM +0100, Marc Zyngier wrote: > On Tue, 18 Aug 2020 18:42:41 +0100, > Cristian Ciocaltea wrote: > > > > Hi Marc, > > > > Thanks for your quick and detailed review! > > > > On Mon, Aug 17, 2020 at 02:52:06PM +0100, Marc Zyngier wrote: > > > On 2020-08-16 12:33, Cristian Ciocaltea wrote: > > > > This controller appears on Actions Semi Owl family SoC's S500, S700 and > > > > S900 and provides support for 3 external interrupt controllers through > > > > > > Is that really 3 interrupt controllers? Or merely 3 interrupt lines? > > > > This is mostly a leftover statement from the previous patch revision. > > I will change it to something like: > > > > "This interrupt controller is found in the Actions Semi Owl SoCs (S500, > > S700 and S900) and provides support for handling up to 3 external > > interrupt lines." > > Looks good. > > > > > > > dedicated SIRQ pins. > > > > > > > > Each line can be independently configured as interrupt and triggers > > > > on either of the edges (raising or falling) or either of the levels > > > > (high or low). Each line can also be masked independently. > > > > > > > > This is based on the patch series submitted by Parthiban Nallathambi: > > > > https://lore.kernel.org/lkml/20181126100356.2840578-1-pn@denx.de/ > > > > > > > > Signed-off-by: Parthiban Nallathambi > > > > Signed-off-by: Saravanan Sekar > > > > [cristi: optimized DT, various fixes/cleanups/improvements] > > > > Signed-off-by: Cristian Ciocaltea > > > > --- > > > > drivers/irqchip/Makefile | 1 + > > > > drivers/irqchip/irq-owl-sirq.c | 318 +++++++++++++++++++++++++++++++++ > > > > 2 files changed, 319 insertions(+) > > > > create mode 100644 drivers/irqchip/irq-owl-sirq.c > > > > > > > > diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile > > > > index 133f9c45744a..b8eb5b8b766d 100644 > > > > --- a/drivers/irqchip/Makefile > > > > +++ b/drivers/irqchip/Makefile > > > > @@ -7,6 +7,7 @@ obj-$(CONFIG_ATH79) += irq-ath79-cpu.o > > > > obj-$(CONFIG_ATH79) += irq-ath79-misc.o > > > > obj-$(CONFIG_ARCH_BCM2835) += irq-bcm2835.o > > > > obj-$(CONFIG_ARCH_BCM2835) += irq-bcm2836.o > > > > +obj-$(CONFIG_ARCH_ACTIONS) += irq-owl-sirq.o > > > > obj-$(CONFIG_DAVINCI_AINTC) += irq-davinci-aintc.o > > > > obj-$(CONFIG_DAVINCI_CP_INTC) += irq-davinci-cp-intc.o > > > > obj-$(CONFIG_EXYNOS_IRQ_COMBINER) += exynos-combiner.o > > > > diff --git a/drivers/irqchip/irq-owl-sirq.c > > > > b/drivers/irqchip/irq-owl-sirq.c > > > > new file mode 100644 > > > > index 000000000000..29b7ffc40ac7 > > > > --- /dev/null > > > > +++ b/drivers/irqchip/irq-owl-sirq.c > > > > @@ -0,0 +1,318 @@ > > > > +// SPDX-License-Identifier: GPL-2.0+ > > > > +/* > > > > + * Actions Semi Owl SoCs SIRQ interrupt controller driver > > > > + * > > > > + * Copyright (C) 2014 Actions Semi Inc. > > > > + * David Liu > > > > + * > > > > + * Author: Parthiban Nallathambi > > > > + * Author: Saravanan Sekar > > > > + * Author: Cristian Ciocaltea > > > > + */ > > > > + > > > > +#include > > > > +#include > > > > +#include > > > > +#include > > > > + > > > > +#define NUM_SIRQ 3 > > > > + > > > > +#define INTC_EXTCTL_PENDING BIT(0) > > > > +#define INTC_EXTCTL_CLK_SEL BIT(4) > > > > +#define INTC_EXTCTL_EN BIT(5) > > > > +#define INTC_EXTCTL_TYPE_MASK GENMASK(7, 6) > > > > +#define INTC_EXTCTL_TYPE_HIGH 0 > > > > +#define INTC_EXTCTL_TYPE_LOW BIT(6) > > > > +#define INTC_EXTCTL_TYPE_RISING BIT(7) > > > > +#define INTC_EXTCTL_TYPE_FALLING (BIT(6) | BIT(7)) > > > > + > > > > +/* S900 SIRQ1 & SIRQ2 control register offsets, relative to SIRQ0 */ > > > > +#define INTC_EXTCTL1 0x0328 > > > > +#define INTC_EXTCTL2 0x032c > > > > + > > > > +struct owl_sirq_params { > > > > + /* INTC_EXTCTL reg shared for all three SIRQ lines */ > > > > + bool reg_shared; > > > > + /* INTC_EXTCTL reg offsets relative to controller base address */ > > > > + u16 reg_offset[NUM_SIRQ]; > > > > +}; > > > > + > > > > +struct owl_sirq_chip_data { > > > > + const struct owl_sirq_params *params; > > > > + void __iomem *base; > > > > + raw_spinlock_t lock; > > > > + u32 ext_irqs[NUM_SIRQ]; > > > > + u8 trigger; > > > > > > Nit: Please align data structure members vertically: > > > > > > struct owl_sirq_chip_data { > > > const struct owl_sirq_params *params; > > > void __iomem *base; > > > raw_spinlock_t lock; > > > u32 ext_irqs[NUM_SIRQ]; > > > u8 trigger; > > > }; > > > > Done. > > > > > > +}; > > > > + > > > > +/* S500 and S700 SoCs */ > > > > +static const struct owl_sirq_params owl_sirq_s500_params = { > > > > + .reg_shared = true, > > > > + .reg_offset = { 0, 0, 0 }, > > > > +}; > > > > + > > > > +/* S900 SoC */ > > > > +static const struct owl_sirq_params owl_sirq_s900_params = { > > > > + .reg_shared = false, > > > > + .reg_offset = { 0, INTC_EXTCTL1, INTC_EXTCTL2 }, > > > > > > 0 *is* an offset, right? Why doesn't it have a name too? > > > > Right, I updated the defines section: > > > > /* S900 SIRQ control register offsets, relative to controller base address */ > > #define INTC_EXTCTL0 0x0000 > > #define INTC_EXTCTL1 0x0328 > > [...] > > > > The controller base address points to SIRQ0 control register, so this > > offset is always 0, but I totally agree we should have a name for it. > > > > > > +}; > > > > + > > > > +static u32 owl_sirq_read_extctl(struct owl_sirq_chip_data *data, u32 > > > > index) > > > > +{ > > > > + u32 val; > > > > + > > > > + val = readl_relaxed(data->base + data->params->reg_offset[index]); > > > > + if (data->params->reg_shared) > > > > + val = (val >> (2 - index) * 8) & 0xff; > > > > > > base = (2 - index) * 8; > > > val = FIELD_GET(GENMASK(base + 7, base), val); > > > > Unfortunately the context doesn't allow using FIELD_GET: > > > > ./include/linux/compiler.h:392:38: error: call to ‘__compiletime_assert_159’ > > declared with attribute error: FIELD_GET: mask is not constant > > Bah. Turning the whole thing into compile-time values would actually > be more readable, so how about this: > > diff --git a/drivers/irqchip/irq-owl-sirq.c b/drivers/irqchip/irq-owl-sirq.c > index 29b7ffc40ac7..b771acbda7d5 100644 > --- a/drivers/irqchip/irq-owl-sirq.c > +++ b/drivers/irqchip/irq-owl-sirq.c > @@ -57,13 +57,39 @@ static const struct owl_sirq_params owl_sirq_s900_params = { > .reg_offset = { 0, INTC_EXTCTL1, INTC_EXTCTL2 }, > }; > > +static u32 owl_field_get(u32 val, int index) > +{ > + switch(index) { > + case 0: > + return FIELD_GET(GENMASK(23, 16), val); > + case 1: > + return FIELD_GET(GENMASK(15, 8), val); > + case 2: > + default: > + return FIELD_GET(GENMASK(7, 0), val); > + } > +} > + > +static u32 owl_field_prep(u32 val, int index) > +{ > + switch(index) { > + case 0: > + return FIELD_PREP(GENMASK(23, 16), val); > + case 1: > + return FIELD_PREP(GENMASK(15, 8), val); > + case 2: > + default: > + return FIELD_PREP(GENMASK(7, 0), val); > + } > +} > + > static u32 owl_sirq_read_extctl(struct owl_sirq_chip_data *data, u32 index) > { > u32 val; > > val = readl_relaxed(data->base + data->params->reg_offset[index]); > if (data->params->reg_shared) > - val = (val >> (2 - index) * 8) & 0xff; > + val = owl_field_get(val, index); > > return val; > } > @@ -75,9 +101,8 @@ static void owl_sirq_write_extctl(struct owl_sirq_chip_data *data, > > if (data->params->reg_shared) { > val = readl_relaxed(data->base + data->params->reg_offset[index]); > - val &= ~(0xff << (2 - index) * 8); > - extctl &= 0xff; > - extctl = (extctl << (2 - index) * 8) | val; > + val &= ~owl_field_prep(0xff, index); > + extctl = owl_field_prep(extctl, index) | val; > } > > writel_relaxed(extctl, data->base + data->params->reg_offset[index]); > > Yes, this is a bit more code, but it *is* readable. Bonus points if > you add proper defines for the masks. That's great, thanks a lot! I have submitted a new revision: https://lore.kernel.org/lkml/cover.1597852360.git.cristian.ciocaltea@gmail.com/ Regards, Cristi > > > > > > + > > > > + return val; > > > > +} > > > > + > > > > +static void owl_sirq_write_extctl(struct owl_sirq_chip_data *data, > > > > + u32 extctl, u32 index) > > > > +{ > > > > + u32 val; > > > > + > > > > + if (data->params->reg_shared) { > > > > + val = readl_relaxed(data->base + data->params->reg_offset[index]); > > > > + val &= ~(0xff << (2 - index) * 8); > > > > + extctl &= 0xff; > > > > + extctl = (extctl << (2 - index) * 8) | val; > > > > > > Please make use of FIELD_PREP, FIELD_GET and GENMASK. > > > > I'm not sure how to deal with the mask constness restriction, except > > using static defines and if/else statements, which is not quite > > elegant. > > See above. > > > > > > > + } > > > > + > > > > + writel_relaxed(extctl, data->base + data->params->reg_offset[index]); > > > > +} > > > > + > > > > +static void owl_sirq_clear_set_extctl(struct owl_sirq_chip_data *d, > > > > + u32 clear, u32 set, u32 index) > > > > +{ > > > > + unsigned long flags; > > > > + u32 val; > > > > + > > > > + raw_spin_lock_irqsave(&d->lock, flags); > > > > + val = owl_sirq_read_extctl(d, index); > > > > + val &= ~clear; > > > > + val |= set; > > > > + owl_sirq_write_extctl(d, val, index); > > > > + raw_spin_unlock_irqrestore(&d->lock, flags); > > > > +} > > > > + > > > > +static void owl_sirq_eoi(struct irq_data *data) > > > > +{ > > > > + struct owl_sirq_chip_data *chip_data = > > > > irq_data_get_irq_chip_data(data); > > > > + > > > > + /* > > > > + * Software must clear external interrupt pending, when interrupt type > > > > + * is edge triggered, so we need per SIRQ based clearing. > > > > + */ > > > > + if (chip_data->trigger & (1 << data->hwirq)) > > > > > > BIT(d->hwirq) > > > > > > But it also begs the question: we already have all the trigger information > > > in the irqdesc. Why do you need some additional bookkeeping? > > > > That's another leftover from the original work. Thanks for pointing > > this out, I missed it. I dropped the redundant handling of the IRQ > > trigger information and just replaced this with: > > > > if (!irqd_is_level_type(data)) > > Yup. > > > > > > > + owl_sirq_clear_set_extctl(chip_data, 0, INTC_EXTCTL_PENDING, > > > > + data->hwirq); > > > > + > > > > + irq_chip_eoi_parent(data); > > > > +} > > > > + > > > > +static void owl_sirq_mask(struct irq_data *data) > > > > +{ > > > > + struct owl_sirq_chip_data *chip_data = > > > > irq_data_get_irq_chip_data(data); > > > > + > > > > + owl_sirq_clear_set_extctl(chip_data, INTC_EXTCTL_EN, 0, data->hwirq); > > > > + irq_chip_mask_parent(data); > > > > +} > > > > + > > > > +static void owl_sirq_unmask(struct irq_data *data) > > > > +{ > > > > + struct owl_sirq_chip_data *chip_data = > > > > irq_data_get_irq_chip_data(data); > > > > + > > > > + owl_sirq_clear_set_extctl(chip_data, 0, INTC_EXTCTL_EN, data->hwirq); > > > > + irq_chip_unmask_parent(data); > > > > +} > > > > + > > > > +/* > > > > + * GIC does not handle falling edge or active low, hence SIRQ shall be > > > > + * programmed to convert falling edge to rising edge signal and active > > > > + * low to active high signal. > > > > + */ > > > > +static int owl_sirq_set_type(struct irq_data *data, unsigned int type) > > > > +{ > > > > + struct owl_sirq_chip_data *chip_data = > > > > irq_data_get_irq_chip_data(data); > > > > + u32 sirq_type; > > > > + > > > > + switch (type) { > > > > + case IRQ_TYPE_LEVEL_LOW: > > > > + sirq_type = INTC_EXTCTL_TYPE_LOW; > > > > + chip_data->trigger &= ~(1 << data->hwirq); > > > > + type = IRQ_TYPE_LEVEL_HIGH; > > > > + break; > > > > + case IRQ_TYPE_LEVEL_HIGH: > > > > + sirq_type = INTC_EXTCTL_TYPE_HIGH; > > > > + chip_data->trigger &= ~(1 << data->hwirq); > > > > + break; > > > > + case IRQ_TYPE_EDGE_FALLING: > > > > + sirq_type = INTC_EXTCTL_TYPE_FALLING; > > > > + chip_data->trigger |= 1 << data->hwirq; > > > > + type = IRQ_TYPE_EDGE_RISING; > > > > + break; > > > > + case IRQ_TYPE_EDGE_RISING: > > > > + sirq_type = INTC_EXTCTL_TYPE_RISING; > > > > + chip_data->trigger |= 1 << data->hwirq; > > > > + break; > > > > + default: > > > > + WARN_ON(1); > > > > > > No need for this WARN_ON(), the core kernel is loud enough. > > > > Done. > > > > > > + return -EINVAL; > > > > + } > > > > + > > > > + owl_sirq_clear_set_extctl(chip_data, INTC_EXTCTL_TYPE_MASK, sirq_type, > > > > + data->hwirq); > > > > + > > > > + return irq_chip_set_type_parent(data, type); > > > > +} > > > > + > > > > +static struct irq_chip owl_sirq_chip = { > > > > + .name = "owl-sirq", > > > > + .irq_mask = owl_sirq_mask, > > > > + .irq_unmask = owl_sirq_unmask, > > > > + .irq_eoi = owl_sirq_eoi, > > > > + .irq_set_type = owl_sirq_set_type, > > > > + .irq_retrigger = irq_chip_retrigger_hierarchy, > > > > > > How about irq_set_affinity? Or does it only exist on UP systems? > > > > I have just added: > > > > #ifdef CONFIG_SMP > > .irq_set_affinity = irq_chip_set_affinity_parent, > > #endif > > Looks OK. > > Cheers, > > M. > > -- > Without deviation from the norm, progress is not possible.