Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2434829ioo; Sat, 28 May 2022 13:34:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzXYmr4TLEAiY5v02esikFdZjTvg8rQhxLMvDoyOz71YtnwubS/SRfAYQz+siIeCI7pG9Kf X-Received: by 2002:a05:6a00:2353:b0:518:96b7:ceb8 with SMTP id j19-20020a056a00235300b0051896b7ceb8mr33641647pfj.5.1653770077261; Sat, 28 May 2022 13:34:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653770077; cv=none; d=google.com; s=arc-20160816; b=BBcjWnHSyf3IAYWCv7xYwdI76vO8xJ+WQblacU8x+HpBcokFbJnSu5nsBSlP+5wREt fSv7JP976e7lsEvfAXlKOxcyDaqgUN5wuxmQz4XVuzsMD6usanZlmeFXkw1dwA2TVw8L +glZu9NR+oTOdLMrfyvCM6jDEfNUiF2loey9KZJu78Nt+7d6o6m26UNRRqd/a7gmOS5p Pq7LK2XYN5pPWHhIn7hohA1qzi/pBjGsKOG1avqBGmUPqdUqMRL2pr1QwjWekDjAhvga rflIQpbx5bz+cK0gBQRrulK912irImFxl8oMjdsuwxSGK8jsxx9GZrkvvC/fjFYvtw0I nR4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=V+5NYjifJjaEFme5WSfgc2ZxDCMHPSnFq4GwSE5vrbk=; b=oD+BmvAzLDDF0UUeNJSMgvnYhi2RNEboR3FR+C/PxdPFRie4gWhwNVMydl8kb0klpG v7ySK6chHqY5h55C1hSZxQowVZq86z5kdaeW2dHOQ5QsyTN01/gYXNEvkHrcpFX1VRdY jpcDMmnyhZepi5D19RIcZ0VycHRIVblJ4n8u+lrw6PCwywkbiqd3IKlZbxmmAOl0mThP w5S71SJ+fjEt9HNip6Lm7dFVVssGmrgzlvq9w3tZKIfrO38oNqTvuou37nSRGZDqh27O UzI00dBbHXHNaqnIZHKV9D/MWsMnap6pqnhhwhKFIe8q/Ih+t0UjDsvNWb/dbBTgoSEm 0dMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=TEbDHnWU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id y2-20020aa78f22000000b0050e0d9b0e4dsi7429859pfr.166.2022.05.28.13.34.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 May 2022 13:34:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=TEbDHnWU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 51B5719FB33; Sat, 28 May 2022 12:35:59 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345243AbiEZMJs (ORCPT + 99 others); Thu, 26 May 2022 08:09:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236076AbiEZMJp (ORCPT ); Thu, 26 May 2022 08:09:45 -0400 Received: from mail-yw1-x1134.google.com (mail-yw1-x1134.google.com [IPv6:2607:f8b0:4864:20::1134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CE21D02BB for ; Thu, 26 May 2022 05:09:44 -0700 (PDT) Received: by mail-yw1-x1134.google.com with SMTP id 00721157ae682-300312ba5e2so13615507b3.0 for ; Thu, 26 May 2022 05:09:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=V+5NYjifJjaEFme5WSfgc2ZxDCMHPSnFq4GwSE5vrbk=; b=TEbDHnWUybKO42XRLvFS6qnfUnR8icXKuSfXryV0lcrntszBNaCAn1g2BXHpoa0tI+ tOhO3rMBFoQ2CVK4J3e3h+ADLCCmWq5OzJKkFjqsWIkdaXVwagk8OhrODFr/u4Dja9Vr XXbiQalm5jCbkSioIF/P6CPYBzsjffwD8zclPVCqg0cwwO4u7Nb0DJa8lDUy2lXbnQmO FN3/jlozAYCjOBoCIrKGdNT4rLsleK1jzG1QUfzZJZrODIMBGF0UlL5m1EgBS0FhCYQ0 qKAGB6463+J9e4/xdEwq/mmN4fNfnH5p3kvanYoRop9FUOfmZMwWS9ZBj5HJgRctpV2L 6jDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=V+5NYjifJjaEFme5WSfgc2ZxDCMHPSnFq4GwSE5vrbk=; b=o4PMhJQR7EQDn9TUKT6LD5D7lPySw5cPGWd3Nehy2sMeJhd7WK+FzITDLpqJQgHWEm 3EgcbhPxq0U7Ik0mU39zVGISnkFWtUpWt91+zGq9phydEplqQ2nm4DpWZh4ORiyFphgV OjqVZBBfkCKG5kpCy2ZOSt6HNSvTfcvRpJ3JmiKFCDPauW2mpxyOVSxgnQ2IceAMEIeP jN6gvSBXBNubnlKkdHikgp/QFBDBCe2HdVDNOSQz00fey0dqRRuvVS0sAvYzVqn/q2bJ yvNvhl6elHX15bVuOYDfI0GSg6O6d06VIrwqElrYG/J1bBpLBCG+q+u/dlzRKNz48b0S pSKw== X-Gm-Message-State: AOAM533p2m7vdB8Dj72lvkYfT9ha4QTo0HmV94GyqTf8IrPkBS9C5JG1 CoSU3qKtTvt6JuDv6SfUrjLp8rvXAcsPI6W3eepbBYDm8n020g== X-Received: by 2002:a81:1951:0:b0:300:4a0f:13be with SMTP id 78-20020a811951000000b003004a0f13bemr8601677ywz.133.1653566983589; Thu, 26 May 2022 05:09:43 -0700 (PDT) MIME-Version: 1.0 References: <35f95ba3-8a7b-7918-0f9d-e14274a5ffe9@arm.com> <87ee0gn5rq.wl-maz@kernel.org> In-Reply-To: <87ee0gn5rq.wl-maz@kernel.org> From: richard clark Date: Thu, 26 May 2022 20:09:32 +0800 Message-ID: Subject: Re: Question about SPIs' interrupt trigger type restrictions To: Marc Zyngier Cc: Robin Murphy , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, s32@nxp.com, leoyang.li@nxp.com, catalin-dan.udma@nxp.com, bogdan.hamciuc@nxp.com, bogdan.folea@nxp.com, ciprianmarian.costea@nxp.com, radu-nicolae.pirea@nxp.com, ghennadi.procopciuc@nxp.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 CC'ing some nxp guys for the S32G274A SOC... On Thu, May 26, 2022 at 2:54 PM Marc Zyngier wrote: > > On Thu, 26 May 2022 04:44:41 +0100, > richard clark wrote: > > > > On Thu, May 26, 2022 at 3:14 AM Robin Murphy wro= te: > > > > > > 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_ED= GE_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_RISIN= G > > > > 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 = interrupt signal > > > > 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. > Context sensitive(register-update leaves UNKNOWN pending) and > > and the direction here is about the configuration bit, not the edge > direction. with this(configuration bit: either level-sensitive or edge-triggered), but it doesn't matter. > > > which has been confirmed by GIC-500 on my platform. > > From 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. What I am talking about is - The SPI is triggered on a rising edge only, while the falling edge is not as the document says. But I've observed the falling edge does trigger the SPI interrupt on my platform (the SOC is NXP S32G274A, an external wakeup signal with high to low transition to wake up the SOC - 'Wakeup/Interrupt Rising-Edge Event Enable Register (WIREER)' and 'Wakeup/Interrupt Falling-Edge Event Enable Register (WIFEER)', WIFEER set 1 and WIREER set 0 works). I don't know why the GIC has such a behavior and what the subtle rationale is behind this, so just mark this as a record... Thanks > > 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. > > > > > > and then, regardless of the state of the signal, remains asserted unt= il > > > the interrupt is acknowledged by software." > > > > > > External signals with the wrong polarity may need external logic to > > > > 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: > > > > --- a/linux/drivers/irqchip/irq-gic-v3.c > > +++ b/linux/drivers/irqchip/irq-gic-v3.c > > > > @@ -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_RI= SING) > > + if ((range =3D=3D SPI_RANGE || range =3D=3D ESPI_RANGE) && !(ty= pe & 0xf)) > > return -EINVAL; > > > > Not under my watch. > > Thanks, > > M. > > -- > Without deviation from the norm, progress is not possible.