From patchwork Tue Oct 24 19:54:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Berger X-Patchwork-Id: 10025439 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id F11CF60375 for ; Tue, 24 Oct 2017 19:56:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E126828A67 for ; Tue, 24 Oct 2017 19:56:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D541828A6A; Tue, 24 Oct 2017 19:56:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 926EB28A67 for ; Tue, 24 Oct 2017 19:56:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=ZurfB9yXutAUspoahVGDjpRY7+L4GK2CUsV6qQV0FBE=; b=dk8qJYwuhb1N7UztIUzQqAOjTQ mYKq1zb//JONYQOOTOY2JUpe6rJVKVQcbqnAfkj7Ep1ZqSmiEkfd1wE67pvnYdSgJzBFAI3m0gCoG L2J9d+6XeYD9vL9kKkBvhdIle6BgCGvuRkigT6T7AX8sMOO9WeejfWmDndEKH/IDc6CDacxLhcgTx s9owjwSaO+Z5FPUqIaqmW6z7MWOzejbw/+I8LYYEUlCvyH+y+J88eZJehdsLkHP4JWk5xsQh2AeWU 980g/QFu6iFnMqMLod88XFr9Gd05vRkAAp1U5yZ3VsnZ6dabkC6oTwFbH5hHpi6SIGy0vnmvzLoZs fHWJOOnA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1e75Jj-0000bG-O1; Tue, 24 Oct 2017 19:56:51 +0000 Received: from mail-qt0-x242.google.com ([2607:f8b0:400d:c0d::242]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e75Iu-0008NM-Ba for linux-arm-kernel@lists.infradead.org; Tue, 24 Oct 2017 19:56:02 +0000 Received: by mail-qt0-x242.google.com with SMTP id z28so31990865qtz.13 for ; Tue, 24 Oct 2017 12:55:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=7VWinLwoAoUUmS6ZIplN92l1cvCl1oHNVFfppnUKYak=; b=naAPY5r513En97+jGp66TYUiyyboqx0X4kMjbiBRnLm/Y/KUYkrKIHHuCTAZtWP1zP qT5EdI/NNZj56mDC5mJgo+FTwHDKjtxbsNn/SL+xuR0f5vCA0xL6KAOBkNCobrdzxhV/ 7ubUrf4BE72TMM6GUjVbvKuVZ9BDKssvVGluqyy0+N+XyP2rENxEZo7pSvoAidjdpcyf h2WNGca+0Rr0rBz35J9OLf/YxJxvBJYLalaBIuF2SQ66sckGBCmz2qoOCzisEbEgLCDq iUIrofpFZTkFiPoIEh36o0WMLZI5mquN/fvEhff6SIevrqtOYtZdA6T2TchuTy1yvz+L sNCg== 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:in-reply-to :references; bh=7VWinLwoAoUUmS6ZIplN92l1cvCl1oHNVFfppnUKYak=; b=uHTr33Aeg0te5veemq5VTWRggZ5t4XKzMIrQNV47LYUVJrE4KyfGHQeeuDfRpWFiN/ B0KN21HfGM2mth4I7Ce5xcRaX39MlNVR3QMZHRiWDzWtJUQRBWpO+TJI9B3rOH9aR3Uw BnfglVpW0hm7NDge991aMDra11EfwSM1oCYHT96ZU04lw7u9+ZwV4Gm4Ya9RYexRa/dS t+/YkFEPZ7twR8WJIeymapXFUZFSPM1VLH9eSCms5XkOuNu+O62kidbuelakhOJDmbgt qxLedDuq2U1C8pF4wB0ZIWReMNDu+epFl4OGjxCibmOtohP/sigxjVcfMT2HdEH8VmEh gwVQ== X-Gm-Message-State: AMCzsaUnW7HUbbXW0waCmfWMeMzdSpb3aH5nAMPMzT/mOayMpHf2SuZj T8OAD5hXjHDkpI4ml9jH6Ns= X-Google-Smtp-Source: ABhQp+SiK4iBubqOM/h/ZFdX6mrtJiHAPdn7Vzv5Wd5PXwkg7ND+CDWVzBNv5BNjUn+uu71GGXmDNg== X-Received: by 10.237.53.92 with SMTP id b28mr28264849qte.280.1508874942428; Tue, 24 Oct 2017 12:55:42 -0700 (PDT) Received: from stb-bld-02.irv.broadcom.com ([192.19.255.250]) by smtp.gmail.com with ESMTPSA id s27sm794249qtj.3.2017.10.24.12.55.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Oct 2017 12:55:41 -0700 (PDT) From: Doug Berger To: Gregory Fong Subject: [PATCH v2 3/7] gpio: brcmstb: release the bgpio lock during irq handlers Date: Tue, 24 Oct 2017 12:54:47 -0700 Message-Id: <20171024195451.30535-4-opendmb@gmail.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171024195451.30535-1-opendmb@gmail.com> References: <20171024195451.30535-1-opendmb@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171024_125600_562962_2338D2D1 X-CRM114-Status: GOOD ( 12.76 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Florian Fainelli , Linus Walleij , linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, Doug Berger , bcm-kernel-feedback-list@broadcom.com, Brian Norris , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The basic memory-mapped GPIO controller lock must be released before calling the registered GPIO interrupt handlers to allow the interrupt handlers to access the hardware. Examples of why a GPIO interrupt handler might want to access the GPIO hardware include an interrupt that is configured to trigger on rising and falling edges that needs to read the current level of the input to know how to respond, or an interrupt that causes a change in a GPIO output in the same bank. If the lock is not released before enterring the handler the hardware accesses will deadlock when they attempt to grab the lock. Since the lock is only needed to protect the calculation of unmasked pending interrupts create a dedicated function to perform this and hide the complexity. Fixes: 19a7b6940b78 ("gpio: brcmstb: Add interrupt and wakeup source support") Signed-off-by: Doug Berger Reviewed-by: Florian Fainelli Acked-by: Gregory Fong --- drivers/gpio/gpio-brcmstb.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/drivers/gpio/gpio-brcmstb.c b/drivers/gpio/gpio-brcmstb.c index 2031b73e066c..fd8c0412f8af 100644 --- a/drivers/gpio/gpio-brcmstb.c +++ b/drivers/gpio/gpio-brcmstb.c @@ -63,6 +63,21 @@ brcmstb_gpio_gc_to_priv(struct gpio_chip *gc) return bank->parent_priv; } +static unsigned long +brcmstb_gpio_get_active_irqs(struct brcmstb_gpio_bank *bank) +{ + void __iomem *reg_base = bank->parent_priv->reg_base; + unsigned long status; + unsigned long flags; + + spin_lock_irqsave(&bank->gc.bgpio_lock, flags); + status = bank->gc.read_reg(reg_base + GIO_STAT(bank->id)) & + bank->gc.read_reg(reg_base + GIO_MASK(bank->id)); + spin_unlock_irqrestore(&bank->gc.bgpio_lock, flags); + + return status; +} + static void brcmstb_gpio_set_imask(struct brcmstb_gpio_bank *bank, unsigned int offset, bool enable) { @@ -204,11 +219,8 @@ static void brcmstb_gpio_irq_bank_handler(struct brcmstb_gpio_bank *bank) struct irq_domain *irq_domain = bank->gc.irqdomain; void __iomem *reg_base = priv->reg_base; unsigned long status; - unsigned long flags; - spin_lock_irqsave(&bank->gc.bgpio_lock, flags); - while ((status = bank->gc.read_reg(reg_base + GIO_STAT(bank->id)) & - bank->gc.read_reg(reg_base + GIO_MASK(bank->id)))) { + while ((status = brcmstb_gpio_get_active_irqs(bank))) { int bit; for_each_set_bit(bit, &status, 32) { @@ -223,7 +235,6 @@ static void brcmstb_gpio_irq_bank_handler(struct brcmstb_gpio_bank *bank) generic_handle_irq(irq_find_mapping(irq_domain, bit)); } } - spin_unlock_irqrestore(&bank->gc.bgpio_lock, flags); } /* Each UPG GIO block has one IRQ for all banks */