From patchwork Fri Oct 28 20:48:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Agustin Vega-Frias X-Patchwork-Id: 9402657 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 0E61C601C0 for ; Fri, 28 Oct 2016 20:50:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F25B92A8A2 for ; Fri, 28 Oct 2016 20:50:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E6AD22A8BA; Fri, 28 Oct 2016 20:50:27 +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.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 967F82A8A2 for ; Fri, 28 Oct 2016 20:50:27 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1c0E5Q-0007gF-FD; Fri, 28 Oct 2016 20:49:12 +0000 Received: from smtp.codeaurora.org ([198.145.29.96]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1c0E56-0007cz-6K for linux-arm-kernel@lists.infradead.org; Fri, 28 Oct 2016 20:48:53 +0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 17099616B3; Fri, 28 Oct 2016 20:48:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1477687713; bh=68J26mkQPCIFxTchtHC0ndW6PtryK5oXBQ6wKZeQjiI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WLFoW9CmdeFh/oz9wvEo+mcLXS2QFF2MV7mXYra7DduRWAsIbHMll3ovIw6BR6pNN wo2Xj+QhYS2H9CAiWbcq1riSgCAyZUO3oVdMfAtLtCBfruODjueRS9MinW4vlh3TqL H09IKysPZBUTCdwDXUcV5VfMMUCk9bxsLuj/ajFs= Received: from midgar.qualcomm.com (global_nat1_iad_fw.qualcomm.com [129.46.232.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: agustinv@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 68BC9616A4; Fri, 28 Oct 2016 20:48:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1477687712; bh=68J26mkQPCIFxTchtHC0ndW6PtryK5oXBQ6wKZeQjiI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kF/22JmxMtioKO3L+OsZAdy93MCzO8jjWSPnI8TM3g2fcVJzn4nr9hIjyitDWBx3o 6cWJMnYWWaoyCBHnWoxPPhs0FkybtuOhaZjHvPGdwRjTaZqIioABs2eg5rlbswXFcz RLxqdL1l5Pg3cH+g/++XSxrYNnWTs18ycsm6KVfM= DMARC-Filter: OpenDMARC Filter v1.3.1 smtp.codeaurora.org 68BC9616A4 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=pass smtp.mailfrom=agustinv@codeaurora.org From: Agustin Vega-Frias To: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, rjw@rjwysocki.net, lenb@kernel.org, tglx@linutronix.de, jason@lakedaemon.net, marc.zyngier@arm.com Subject: [PATCH V6 1/3] ACPI: Retry IRQ conversion if it failed previously Date: Fri, 28 Oct 2016 16:48:14 -0400 Message-Id: <1477687696-1509-2-git-send-email-agustinv@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1477687696-1509-1-git-send-email-agustinv@codeaurora.org> References: <1477687696-1509-1-git-send-email-agustinv@codeaurora.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161028_134852_332326_4C488C5A X-CRM114-Status: GOOD ( 17.04 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: harba@codeaurora.org, mlangsdo@redhat.com, graeme.gregory@linaro.org, jcm@redhat.com, timur@codeaurora.org, agross@codeaurora.org, guohanjun@huawei.com, astone@redhat.com, cov@codeaurora.org, msalter@redhat.com, Agustin Vega-Frias , ahs3@redhat.com, charles.garcia-tobin@arm.com 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 This allows probe deferral to work properly when a dependent device fails to get a valid IRQ because the IRQ domain was not registered at the time the resources were added to the platform_device. Signed-off-by: Agustin Vega-Frias --- drivers/acpi/resource.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ drivers/base/platform.c | 9 +++++++- include/linux/acpi.h | 7 ++++++ 3 files changed, 74 insertions(+), 1 deletion(-) diff --git a/drivers/acpi/resource.c b/drivers/acpi/resource.c index 56241eb..4beda15 100644 --- a/drivers/acpi/resource.c +++ b/drivers/acpi/resource.c @@ -664,3 +664,62 @@ int acpi_dev_filter_resource_type(struct acpi_resource *ares, return (type & types) ? 0 : 1; } EXPORT_SYMBOL_GPL(acpi_dev_filter_resource_type); + +struct acpi_irq_get_ctx { + unsigned int index; + struct resource *res; +}; + +static acpi_status acpi_irq_get_cb(struct acpi_resource *ares, void *context) +{ + struct acpi_irq_get_ctx *ctx = context; + struct acpi_resource_irq *irq; + struct acpi_resource_extended_irq *ext_irq; + + switch (ares->type) { + case ACPI_RESOURCE_TYPE_IRQ: + irq = &ares->data.irq; + if (ctx->index < irq->interrupt_count) { + acpi_dev_resource_interrupt(ares, ctx->index, ctx->res); + return AE_CTRL_TERMINATE; + } + ctx->index -= irq->interrupt_count; + break; + case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: + ext_irq = &ares->data.extended_irq; + if (ctx->index < ext_irq->interrupt_count) { + acpi_dev_resource_interrupt(ares, ctx->index, ctx->res); + return AE_CTRL_TERMINATE; + } + ctx->index -= ext_irq->interrupt_count; + break; + } + + return AE_OK; +} + +/** + * acpi_irq_get - Look for the ACPI IRQ resource with the given index and + * use it to initialize the given Linux IRQ resource. + * @handle ACPI device handle + * @index ACPI IRQ resource index to lookup + * @res Linux IRQ resource to initialize + * + * Return: 0 on success + * -EINVAL if an error occurs + * -EPROBE_DEFER if the IRQ lookup/conversion failed + */ +int acpi_irq_get(acpi_handle handle, unsigned int index, struct resource *res) +{ + struct acpi_irq_get_ctx ctx = { index, res }; + acpi_status status; + + status = acpi_walk_resources(handle, METHOD_NAME__CRS, + acpi_irq_get_cb, &ctx); + if (ACPI_FAILURE(status)) + return -EINVAL; + if (res->flags & IORESOURCE_DISABLED) + return -EPROBE_DEFER; + return 0; +} +EXPORT_SYMBOL_GPL(acpi_irq_get); diff --git a/drivers/base/platform.c b/drivers/base/platform.c index c4af003..61423d2 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -102,6 +102,14 @@ int platform_get_irq(struct platform_device *dev, unsigned int num) } r = platform_get_resource(dev, IORESOURCE_IRQ, num); + if (r && r->flags & IORESOURCE_DISABLED && ACPI_COMPANION(&dev->dev)) { + int ret; + + ret = acpi_irq_get(ACPI_HANDLE(&dev->dev), num, r); + if (ret) + return ret; + } + /* * The resources may pass trigger flags to the irqs that need * to be set up. It so happens that the trigger flags for @@ -1450,4 +1458,3 @@ void __init early_platform_cleanup(void) memset(&pd->dev.devres_head, 0, sizeof(pd->dev.devres_head)); } } - diff --git a/include/linux/acpi.h b/include/linux/acpi.h index ddbeda6..40213c4 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -405,6 +405,7 @@ bool acpi_dev_resource_ext_address_space(struct acpi_resource *ares, unsigned int acpi_dev_get_irq_type(int triggering, int polarity); bool acpi_dev_resource_interrupt(struct acpi_resource *ares, int index, struct resource *res); +int acpi_irq_get(acpi_handle handle, unsigned int index, struct resource *res); void acpi_dev_free_resource_list(struct list_head *list); int acpi_dev_get_resources(struct acpi_device *adev, struct list_head *list, @@ -762,6 +763,12 @@ static inline int acpi_reconfig_notifier_unregister(struct notifier_block *nb) return -EINVAL; } +static inline int acpi_irq_get(acpi_handle handle, unsigned int index, + struct resource *res) +{ + return -EINVAL; +} + #endif /* !CONFIG_ACPI */ #ifdef CONFIG_ACPI_HOTPLUG_IOAPIC