Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp981986ioo; Thu, 26 May 2022 21:30:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTegsQucNHqA8NI3WEn06xRU8aJDXL+nQ9uL5Ns3BCaLBwrwXHgnpqSAwAr5DjiT+3ja3t X-Received: by 2002:a05:6a00:e8e:b0:518:287c:ce82 with SMTP id bo14-20020a056a000e8e00b00518287cce82mr41603946pfb.4.1653625809109; Thu, 26 May 2022 21:30:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653625809; cv=none; d=google.com; s=arc-20160816; b=GSzmCwqTjzRXHwhb3LrHuzAO0RDPFQgVyrIgt7GKjtCRJb9I1AzXPCoz9DXHWUP0Eg LGr9lwuwK5OG0OvFhCgP6OogCZ755fAgTrPJ+X+qw+8id6MDL80B3FJ/f1icpHAyu+pV JE4xm1h6uooqkEPXNi1EoAni/wzygU/TjE57yb+xELQkzTA10aEZxGeGWgH7CTCWXcfr u/22jHSv9BNpVQpyfWKrZ+yoWs2q9/N8klspgRvS69S9693x51et+GcJDAjZniprh8jJ Fv/UjsJo1ou5nw/ZOOBHjU21Uo+jKA7ZDAjADOHk/XSwnNZqKkaA7lpYEgtyr+ltsb6y ZCJA== 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 :user-agent:references:in-reply-to:subject:cc:to:from:message-id :date:dkim-signature; bh=Yrj2Nh7jyKnFnjCL0oE0GeNXVfeiSv5nOIn21/bmNOA=; b=axmUL9XIlfnshtrT+eL20JWWD/4NuYnoSV/6HmfDBdc1h8R9YddgP/Hksvcyd+gVmi 8H0X38iqchHKxTI44rQMi7PYPpeGpoguGT8rMvK/8QftrhinEVyDJ1h3XX5AGY39BTRl lYnrop845F9BfsleJyBcItU0Y5AiwJc5we97ZLOhabgqCnex+kg43m0s1GFhuIELLeim 42/cUgTQAFrbxa8vzu5iRDR9v0I9g+L9zZZ94BYv2nsIkcGCTxZRePZxB5xKV0jX5+fb 1oqTafBVPg6dQpqAiCbt3n19ogCYgqeoUwUMaBxdN8e13w7rYEbr8Q56DLTUAhqdn1Hm sXiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sw9p0cDw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w7-20020a63a747000000b003aba3e87b30si4827392pgo.155.2022.05.26.21.29.55; Thu, 26 May 2022 21:30:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sw9p0cDw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S1346295AbiEZGyM (ORCPT + 99 others); Thu, 26 May 2022 02:54:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346296AbiEZGyL (ORCPT ); Thu, 26 May 2022 02:54:11 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B74872E3E for ; Wed, 25 May 2022 23:54:08 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 8F162B81ECC for ; Thu, 26 May 2022 06:54:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4BC4EC385A9; Thu, 26 May 2022 06:54:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1653548045; bh=v8SvQPQ97nFV5d3lLq/BEczJQQiolsIIT/VHCP9PfFk=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=sw9p0cDwBjfb68NgDGb8yPDJPc9J91TELIIAqwntVcsWr8+vHQ0JzI3dBxs2DRmiq 6xaGCLFSMxbkns4We5NRNCgPHkjC2ExYXdY2lLthEp1g5g+ojmCItPDlCSLpZZjwUU c3DYeqkbfqpyfizawGrQzvcBigVlzrrG9ziitpi4qtrfqaMZjGSAgpLL9t7rjZqZqL jCeCGWupcQPjkbDqauQj3mv8oGs02nfm+ofULrzL5qDx+21otL9MXJh80QP4HCrVE6 +Uc3Jj0AMpXMSNtVLZq12t0YYPLu/tAQFjLlPe+BzMEH/z7Q0cgpmigwYZxsv/n8IS 6uu9mVhrpy/6A== Received: from athedsl-4490923.home.otenet.gr ([94.71.82.179] helo=wait-a-minute.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nu7Ni-00DmwU-JY; Thu, 26 May 2022 07:54:02 +0100 Date: Thu, 26 May 2022 07:54:01 +0100 Message-ID: <87ee0gn5rq.wl-maz@kernel.org> From: Marc Zyngier To: richard clark Cc: Robin Murphy , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: Question about SPIs' interrupt trigger type restrictions In-Reply-To: References: <35f95ba3-8a7b-7918-0f9d-e14274a5ffe9@arm.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 94.71.82.179 X-SA-Exim-Rcpt-To: richard.xnu.clark@gmail.com, robin.murphy@arm.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 26 May 2022 04:44:41 +0100, richard clark wrote: >=20 > On Thu, May 26, 2022 at 3:14 AM Robin Murphy wrote: > > > > On 2022-05-25 11:01, richard clark wrote: > > > Hi Marc, > > > > > > For below code snippet about SPI interrupt trigger type: > > > > > > static int gic_set_type(struct irq_data *d, unsigned int type) > > > { > > > ... > > > /* SPIs have restrictions on the supported types */ > > > if ((range =3D=3D SPI_RANGE || range =3D=3D ESPI_RANGE) && > > > type !=3D IRQ_TYPE_LEVEL_HIGH && type !=3D IRQ_TYPE_EDGE= _RISING) > > > return -EINVAL; > > > ... > > > } > > > > > > We have a device at hand whose interrupt type is SPI, Falling edge > > > will trigger the interrupt. But the request_irq(50, handler, > > > IRQ_TYPE_EDGE_FALLING, ...) will return -EINVAL. > > > > > > The question is, why must the SPI interrupt use IRQ_TYPE_EDGE_RISING > > > instead of IRQ_TYPE_EDGE_FALLING? > > > > Because that's what the GIC architecture[1] says. From section 1.2.1 > > "Interrupt Types": > > > > "An interrupt that is edge-triggered has the following property: > > =E2=80=A2 It is asserted on detection of a rising edge of an in= terrupt signal >=20 > This rising edge detection is not true, it's also asserted by > falling edge, just like the GICD_ICFGR register says: Changing the > interrupt configuration between level-sensitive and *edge-triggered > (in either direction)* at a time when there is a pending interrupt > ..., Let me finish the sentence for you: ... will leave the interrupt in an UNKNOWN pending state. and the direction here is about the configuration bit, not the edge direction. > which has been confirmed by GIC-500 on my platform. =46rom the GIC500 r1p1 TRM, page 2-8: SPIs are generated either by wire inputs or by writes to the AXI4 slave programming interface. The GIC-500 can support up to 960 SPIs corresponding to the external spi[991:32] signal. The number of SPIs available depends on the implemented configuration. The permitted values are 32-960, in steps of 32. The first SPI has an ID number of 32. You can configure whether each SPI is triggered on a rising edge or is active-HIGH level-sensitive. So I have no idea what you are talking about, but you definitely have the wrong end of the stick. Both the architecture and the implementations are aligned with what the GIC drivers do. If your system behaves differently, this is because something is inverting the signal, which is extremely common. Just describe this in your device tree, or lie to the kernel, whichever way you want. >=20 > > and then, regardless of the state of the signal, remains asserted until > > the interrupt is acknowledged by software." > > > > External signals with the wrong polarity may need external logic to >=20 > IMO, it's not wrong polarity for a device to interrupt the processor > with a falling edge, it's normal. Actually, the GIC supports > edge-trigger type: > '0b10 Corresponding interrupt is edge-triggered', the > IRQ_TYPE_EDGE_RISING check in gic_set_type(...) is just a sanity check > from this point of view. No, this is an architectural requirement, and the driver caters for the architecture (and only that). > I would more like to have below changes applied: >=20 > --- a/linux/drivers/irqchip/irq-gic-v3.c > +++ b/linux/drivers/irqchip/irq-gic-v3.c >=20 > @@ -560,8 +560,7 @@ static int gic_set_type(struct irq_data *d, > unsigned int type) > return type !=3D IRQ_TYPE_EDGE_RISING ? -EINVAL : 0; > /* SPIs have restrictions on the supported types */ > - if ((range =3D=3D SPI_RANGE || range =3D=3D ESPI_RANGE) && > - type !=3D IRQ_TYPE_LEVEL_HIGH && type !=3D IRQ_TYPE_EDGE_RISI= NG) > + if ((range =3D=3D SPI_RANGE || range =3D=3D ESPI_RANGE) && !(type= & 0xf)) > return -EINVAL; >=20 Not under my watch. Thanks, M. --=20 Without deviation from the norm, progress is not possible.