From patchwork Wed Dec 2 10:36:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 335977 Delivered-To: patch@linaro.org Received: by 2002:a17:906:4755:0:0:0:0 with SMTP id j21csp811463ejs; Wed, 2 Dec 2020 02:43:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJwssQy2weJLrC/h2qMoJYzKGQii9MRCQF8OYAXXJqztB3A46vh7d1QcH88rFhpus5rPDHSc X-Received: by 2002:a17:906:e81:: with SMTP id p1mr1698125ejf.494.1606905805645; Wed, 02 Dec 2020 02:43:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606905805; cv=none; d=google.com; s=arc-20160816; b=ztg/nCLwR9lFRVBS1Ph1y5Y+rxV7CPecLY5AnEkTkkue5sJApbsnBrx+JT1pAn9ZhY nJLeJ55A1XpaOJwP9u8xLAc2jZPycFvQ2OIwyYpovNjxn6mG7d5KBs/nPM3J/qtAwhiQ 1r7Mo7phh16282ZDVsaICoguM40BEDQbwUQq0vrChOXUSMFE3wEgiweEvcUtuDvn7gOv YIHlGolx73nprGy1RJ3CarKbqbC/8gc/oSkBP9BOFNSWwIPkd5qmRQLN6A4KUCcK3MwT yBeFiA4L+EVhabeSCUBlZ5dl4WxnMWZlvdF/fZTfS30yj99vfues/ZtD/hBoaElGG6dU ersg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=rJFmTDj7CdH9RCccqRLIe1lG/ZriBEbO4XhB9OmsKIQ=; b=D25vQM+DVmDoEb4zDTEeiHAC/AD+KqRksWWto1U58PgA/EqFtDdCOGuKedEXoAAL40 RNCzbcZKALNSxa2ZsQFjcoEjzoymy0mzMpCDTSOWyUOhgmmkyAXfIXwd6bpMJdWwanp4 SBJZYH6KShVjXI86xJ9jzJEKaKz4NXoX6WB8RygAXvs8wc6bSETYWyWjnTZwxnX+3UUi /e4s7k2Fq27IythxBLa3PufNSUtABj6SeprZ54nHVj1ZpnHDWV6UPtGwyCMezeATcWBp LspAPO95YM1hggNeQjvoXlkgjgumDzQcskNszbYzddV1q81PKZy7ol4/DAAC5Yd+ixLG VvPA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a15si811195eds.424.2020.12.02.02.43.25 for ; Wed, 02 Dec 2020 02:43:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388664AbgLBKll (ORCPT ); Wed, 2 Dec 2020 05:41:41 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:8494 "EHLO szxga06-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388621AbgLBKlk (ORCPT ); Wed, 2 Dec 2020 05:41:40 -0500 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4CmFqS6P6rzhlmG; Wed, 2 Dec 2020 18:40:36 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.487.0; Wed, 2 Dec 2020 18:40:47 +0800 From: John Garry To: , , , , , , CC: , , , , , "John Garry" Subject: [PATCH v5 1/5] genirq/affinity: Add irq_update_affinity_desc() Date: Wed, 2 Dec 2020 18:36:53 +0800 Message-ID: <1606905417-183214-2-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1606905417-183214-1-git-send-email-john.garry@huawei.com> References: <1606905417-183214-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Add a function to allow the affinity of an interrupt be switched to managed, such that interrupts allocated for platform devices may be managed. This new interface has certain limitations, and attempts to use it in the following circumstances will fail: - For when the kernel is configured for generic IRQ reservation mode (in config GENERIC_IRQ_RESERVATION_MODE). The reason being that it could conflict with managed vs. non-managed interrupt accounting. - The interrupt is already started, which should not be the case during init - The interrupt is already configured as managed, which means double init Suggested-by: Thomas Gleixner Signed-off-by: John Garry --- include/linux/interrupt.h | 8 +++++ kernel/irq/manage.c | 70 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) -- 2.26.2 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h index ee8299eb1f52..870b3251e174 100644 --- a/include/linux/interrupt.h +++ b/include/linux/interrupt.h @@ -352,6 +352,8 @@ extern int irq_can_set_affinity(unsigned int irq); extern int irq_select_affinity(unsigned int irq); extern int irq_set_affinity_hint(unsigned int irq, const struct cpumask *m); +extern int irq_update_affinity_desc(unsigned int irq, + struct irq_affinity_desc *affinity); extern int irq_set_affinity_notifier(unsigned int irq, struct irq_affinity_notify *notify); @@ -387,6 +389,12 @@ static inline int irq_set_affinity_hint(unsigned int irq, return -EINVAL; } +static inline int irq_update_affinity_desc(unsigned int irq, + struct irq_affinity_desc *affinity) +{ + return -EINVAL; +} + static inline int irq_set_affinity_notifier(unsigned int irq, struct irq_affinity_notify *notify) { diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c index c460e0496006..c826ba4141fe 100644 --- a/kernel/irq/manage.c +++ b/kernel/irq/manage.c @@ -371,6 +371,76 @@ int irq_set_affinity_locked(struct irq_data *data, const struct cpumask *mask, return ret; } +/** + * irq_update_affinity_desc - Update affinity management for an interrupt + * @irq: The interrupt number to update + * @affinity: Pointer to the affinity descriptor + * + * This interface can be used to configure the affinity management of + * interrupts which have been allocated already. + * + * There are certain limitations on when it may be used - attempts to use it + * for when the kernel is configured for generic IRQ reservation mode (in + * config GENERIC_IRQ_RESERVATION_MODE) will fail, as it may conflict with + * managed/non-managed interrupt accounting. In addition, attempts to use it on + * an interrupt which is already started or which has already been configured + * as managed will also fail, as these mean invalid init state or double init. + */ +int irq_update_affinity_desc(unsigned int irq, + struct irq_affinity_desc *affinity) +{ + struct irq_desc *desc; + unsigned long flags; + bool activated; + int ret = 0; + + /* + * Supporting this with the reservation scheme used by x86 needs + * some more thought. Fail it for now. + */ + if (IS_ENABLED(CONFIG_GENERIC_IRQ_RESERVATION_MODE)) + return -EOPNOTSUPP; + + desc = irq_get_desc_buslock(irq, &flags, 0); + if (!desc) + return -EINVAL; + + /* Requires the interrupt to be shut down */ + if (irqd_is_started(&desc->irq_data)) { + ret = -EBUSY; + goto out_unlock; + } + + /* Interrupts which are already managed cannot be modified */ + if (irqd_affinity_is_managed(&desc->irq_data)) { + ret = -EBUSY; + goto out_unlock; + } + + /* + * Deactivate the interrupt. That's required to undo + * anything an earlier activation has established. + */ + activated = irqd_is_activated(&desc->irq_data); + if (activated) + irq_domain_deactivate_irq(&desc->irq_data); + + if (affinity->is_managed) { + irqd_set(&desc->irq_data, IRQD_AFFINITY_MANAGED); + irqd_set(&desc->irq_data, IRQD_MANAGED_SHUTDOWN); + } + + cpumask_copy(desc->irq_common_data.affinity, &affinity->mask); + + /* Restore the activation state */ + if (activated) + irq_domain_activate_irq(&desc->irq_data, false); + +out_unlock: + irq_put_desc_busunlock(desc, flags); + return ret; +} + int __irq_set_affinity(unsigned int irq, const struct cpumask *mask, bool force) { struct irq_desc *desc = irq_to_desc(irq); From patchwork Wed Dec 2 10:36:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 336434 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8260AC83013 for ; Wed, 2 Dec 2020 10:41:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 457592222C for ; Wed, 2 Dec 2020 10:41:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388676AbgLBKlm (ORCPT ); Wed, 2 Dec 2020 05:41:42 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:8490 "EHLO szxga06-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388620AbgLBKll (ORCPT ); Wed, 2 Dec 2020 05:41:41 -0500 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4CmFqS54jczhlkn; Wed, 2 Dec 2020 18:40:36 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.487.0; Wed, 2 Dec 2020 18:40:48 +0800 From: John Garry To: , , , , , , CC: , , , , , "John Garry" Subject: [PATCH v5 2/5] resource: Add irqresource_disabled() Date: Wed, 2 Dec 2020 18:36:54 +0800 Message-ID: <1606905417-183214-3-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1606905417-183214-1-git-send-email-john.garry@huawei.com> References: <1606905417-183214-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Add a common function to set the fields for a irq resource to disabled, which mimics what is done in acpi_dev_irqresource_disabled(), with a view to replace that function. Signed-off-by: John Garry Reviewed-by: Rafael J. Wysocki --- include/linux/ioport.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/linux/ioport.h b/include/linux/ioport.h index 5135d4b86cd6..f9bf374f9633 100644 --- a/include/linux/ioport.h +++ b/include/linux/ioport.h @@ -307,6 +307,13 @@ struct resource *devm_request_free_mem_region(struct device *dev, struct resource *request_free_mem_region(struct resource *base, unsigned long size, const char *name); +static inline void irqresource_disabled(struct resource *res, u32 irq) +{ + res->start = irq; + res->end = irq; + res->flags = IORESOURCE_IRQ | IORESOURCE_DISABLED | IORESOURCE_UNSET; +} + #ifdef CONFIG_IO_STRICT_DEVMEM void revoke_devmem(struct resource *res); #else From patchwork Wed Dec 2 10:36:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 335975 Delivered-To: patch@linaro.org Received: by 2002:a17:906:4755:0:0:0:0 with SMTP id j21csp811442ejs; Wed, 2 Dec 2020 02:43:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJxhAqoC2NJX2c9uUCFqAwaz6zo5GCHKkYfYELPVSEug+ISUXq9ytnaYfc5y/IUD9xkot4cu X-Received: by 2002:a17:906:7f13:: with SMTP id d19mr1766212ejr.54.1606905803743; Wed, 02 Dec 2020 02:43:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606905803; cv=none; d=google.com; s=arc-20160816; b=G/jZY5AXeLv2rLjh9NA2rz2g2nPCW31i4EP5EaGXlqcdiLTjBLTEZLo8vV1BWmZDwl zPOsb+RgeR2nr/bcI4pv2/JnTLvz986xr2v7am9HVikqTfU14f7bYRGIHUl6N7Z22yCS rwb5Cz2ClSmKTF+r5nGSaKstZHe6pVj5cH/ObxoY31YDnFPNX5mWqemX/URN5+mZtZhP hBaKJaGHrrS/d+bvheNdqiRHjjtiPXPIswPY8vvSTwdTdBNVPTaV1JuGp2E/n0Qxnyy6 Xsd/bCt/v8aJeyenomd9XuUKyYXg7iejohi/j25AftoDUrsLVGabKlxF/0K7K089OZOZ lDSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=8k3W5qHbi0eOemYajOZuNTFsUG5+Arc1xJ2YhI9qaNA=; b=cKnayg0DWCRL6XaIleXIi3/G/cnIOgN+klEy+skadhPTD8aR5/xoecOvDyp05Nx8Ka +4oQPrBejb73b5JJDOH+1gy0RP6VC0SoxGxWEGGeuEJTpkCZc0Fyfi30mf34bn8a6UBj 54zKSswmmWbtSRGtrOkA7hn0kxYTUCWiPYC0cvGpuKDVM5u8hrQ8LWD05fA6YTE+cV3m P6pOiakYl9K82X7XgE78HvkXRFkwNY+7/B3KVkbQgxSbaFPm08FD61w6UikTvlQ7gvB/ S02nTg0DGPPtHRUcSnrOgJad/y2BmzqBlZSijzlv0RtevB6IC8jwgaXVIydKtF8E+m8D jzZQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a15si811195eds.424.2020.12.02.02.43.23 for ; Wed, 02 Dec 2020 02:43:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388695AbgLBKlo (ORCPT ); Wed, 2 Dec 2020 05:41:44 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:8492 "EHLO szxga06-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388626AbgLBKln (ORCPT ); Wed, 2 Dec 2020 05:41:43 -0500 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4CmFqS5MfwzhllH; Wed, 2 Dec 2020 18:40:36 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.487.0; Wed, 2 Dec 2020 18:40:48 +0800 From: John Garry To: , , , , , , CC: , , , , , "John Garry" Subject: [PATCH v5 3/5] ACPI: Drop acpi_dev_irqresource_disabled() Date: Wed, 2 Dec 2020 18:36:55 +0800 Message-ID: <1606905417-183214-4-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1606905417-183214-1-git-send-email-john.garry@huawei.com> References: <1606905417-183214-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The functionality of acpi_dev_irqresource_disabled() is same as in common irqresource_disabled(), so drop acpi_dev_irqresource_disabled() in favour of that function. Signed-off-by: John Garry Acked-by: Rafael J. Wysocki --- drivers/acpi/resource.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) -- 2.26.2 diff --git a/drivers/acpi/resource.c b/drivers/acpi/resource.c index ad04824ca3ba..58203193417e 100644 --- a/drivers/acpi/resource.c +++ b/drivers/acpi/resource.c @@ -380,13 +380,6 @@ unsigned int acpi_dev_get_irq_type(int triggering, int polarity) } EXPORT_SYMBOL_GPL(acpi_dev_get_irq_type); -static void acpi_dev_irqresource_disabled(struct resource *res, u32 gsi) -{ - res->start = gsi; - res->end = gsi; - res->flags = IORESOURCE_IRQ | IORESOURCE_DISABLED | IORESOURCE_UNSET; -} - static void acpi_dev_get_irqresource(struct resource *res, u32 gsi, u8 triggering, u8 polarity, u8 shareable, bool legacy) @@ -394,7 +387,7 @@ static void acpi_dev_get_irqresource(struct resource *res, u32 gsi, int irq, p, t; if (!valid_IRQ(gsi)) { - acpi_dev_irqresource_disabled(res, gsi); + irqresource_disabled(res, gsi); return; } @@ -426,7 +419,7 @@ static void acpi_dev_get_irqresource(struct resource *res, u32 gsi, res->start = irq; res->end = irq; } else { - acpi_dev_irqresource_disabled(res, gsi); + irqresource_disabled(res, gsi); } } @@ -463,7 +456,7 @@ bool acpi_dev_resource_interrupt(struct acpi_resource *ares, int index, */ irq = &ares->data.irq; if (index >= irq->interrupt_count) { - acpi_dev_irqresource_disabled(res, 0); + irqresource_disabled(res, 0); return false; } acpi_dev_get_irqresource(res, irq->interrupts[index], @@ -473,7 +466,7 @@ bool acpi_dev_resource_interrupt(struct acpi_resource *ares, int index, case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: ext_irq = &ares->data.extended_irq; if (index >= ext_irq->interrupt_count) { - acpi_dev_irqresource_disabled(res, 0); + irqresource_disabled(res, 0); return false; } if (is_gsi(ext_irq)) @@ -481,7 +474,7 @@ bool acpi_dev_resource_interrupt(struct acpi_resource *ares, int index, ext_irq->triggering, ext_irq->polarity, ext_irq->shareable, false); else - acpi_dev_irqresource_disabled(res, 0); + irqresource_disabled(res, 0); break; default: res->flags = 0; From patchwork Wed Dec 2 10:36:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 335978 Delivered-To: patch@linaro.org Received: by 2002:a17:906:4755:0:0:0:0 with SMTP id j21csp811482ejs; Wed, 2 Dec 2020 02:43:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJyuxVvlcvTrm4SigJZGCBjJsx+N7VIMvErCKZf1iL3ZqTSxwflhUragqAn5qe1QLpTtUAog X-Received: by 2002:a50:ff05:: with SMTP id a5mr1924144edu.43.1606905807193; Wed, 02 Dec 2020 02:43:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606905807; cv=none; d=google.com; s=arc-20160816; b=RqcI1rQ2g005nd8eiMO62jfsTPr8sxWNJ6G5IAtISTLa5MHuMMsSdrCnrZPs2o53xo twWrO/KEFMBD9QhJUmU5Peh1QDA0pkl8VfBEZjLUbDAWcT9EujU8i/bZNzrElZQNamX+ 52JIZxDn66biFWnpSoi0cYmpjW+Vk+opRO6X/DXTtItD3c6RqZvF6QZ/cBBzflb+F/Rt Wxd49V8lyu7y4KGhq1+WDnNQxBx4br6GqHvkWImgEfAE1bwivVcebojhU1rwSbxZXdgw xTxrDQKCNnTQmTJVeZkI3J24glAWTZDXylofOVFfc3M3cBJBh1X3YNj9m+RpupOn1YW1 bzig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=xYj4h0OmjvyWQZZ5vUB8iTt90cE2T4W7TtJdqH1+RuY=; b=xIWMYxU0++3WqYVnPklOs8rUH2DLI/0I9HO/y//w4NU62WEywNmIfZmW8wi9aqV+lh 7mSPE/a65meMUm7P2Gvm0nLml6cIpue34OkPfkFhF3nJFMFXG3HmWN1hfGvFNNEsL+Lk TxgJXugOn+SdXkXHzUQkI5FAKiRnM2xh6txoqZrg629zbRh6xxp9zflyXmP3ndTs5RU1 iMT+XHJ5qIBIItZayi9TR12ax48UOcUFSLHi8Ahc5D5pIoDY3xfmCBPN2W1kfR3ipfE1 q7E1EVB3hynEngEm0QumIL8b5Rg3Jy0MfDgYNkRJdtcoE3iW2Nz60E+M0ADDnrHOntnT mD7A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a15si811195eds.424.2020.12.02.02.43.27 for ; Wed, 02 Dec 2020 02:43:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388721AbgLBKl4 (ORCPT ); Wed, 2 Dec 2020 05:41:56 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:8493 "EHLO szxga06-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388619AbgLBKlk (ORCPT ); Wed, 2 Dec 2020 05:41:40 -0500 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4CmFqS633fzhllW; Wed, 2 Dec 2020 18:40:36 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.487.0; Wed, 2 Dec 2020 18:40:49 +0800 From: John Garry To: , , , , , , CC: , , , , , "John Garry" Subject: [PATCH v5 4/5] Driver core: platform: Add devm_platform_get_irqs_affinity() Date: Wed, 2 Dec 2020 18:36:56 +0800 Message-ID: <1606905417-183214-5-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1606905417-183214-1-git-send-email-john.garry@huawei.com> References: <1606905417-183214-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Drivers for multi-queue platform devices may also want managed interrupts for handling HW queue completion interrupts, so add support. The function accepts an affinity descriptor pointer, which covers all IRQs expected for the device. The function is devm class as the only current in-tree user will also use devm method for requesting the interrupts; as such, the function is made as devm as it can ensure ordering of freeing the irq and disposing of the mapping. Signed-off-by: John Garry --- drivers/base/platform.c | 121 ++++++++++++++++++++++++++++++++ include/linux/platform_device.h | 6 ++ 2 files changed, 127 insertions(+) -- 2.26.2 Acked-by: Marc Zyngier diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 88aef93eb4dd..ea8add164b89 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -15,6 +15,8 @@ #include #include #include +#include +#include #include #include #include @@ -289,6 +291,125 @@ int platform_irq_count(struct platform_device *dev) } EXPORT_SYMBOL_GPL(platform_irq_count); +struct irq_affinity_devres { + unsigned int count; + unsigned int irq[]; +}; + +static void platform_disable_acpi_irq(struct platform_device *pdev, int index) +{ + struct resource *r; + + r = platform_get_resource(pdev, IORESOURCE_IRQ, index); + if (r) + irqresource_disabled(r, 0); +} + +static void devm_platform_get_irqs_affinity_release(struct device *dev, + void *res) +{ + struct irq_affinity_devres *ptr = res; + int i; + + for (i = 0; i < ptr->count; i++) { + irq_dispose_mapping(ptr->irq[i]); + + if (has_acpi_companion(dev)) + platform_disable_acpi_irq(to_platform_device(dev), i); + } +} + +/** + * devm_platform_get_irqs_affinity - devm method to get a set of IRQs for a + * device using an interrupt affinity descriptor + * @dev: platform device pointer + * @affd: affinity descriptor + * @minvec: minimum count of interrupt vectors + * @maxvec: maximum count of interrupt vectors + * @irqs: pointer holder for IRQ numbers + * + * Gets a set of IRQs for a platform device, and updates IRQ afffinty according + * to the passed affinity descriptor + * + * Return: Number of vectors on success, negative error number on failure. + */ +int devm_platform_get_irqs_affinity(struct platform_device *dev, + struct irq_affinity *affd, + unsigned int minvec, + unsigned int maxvec, + int **irqs) +{ + struct irq_affinity_devres *ptr; + struct irq_affinity_desc *desc; + size_t size; + int i, ret, nvec; + + if (!affd) + return -EPERM; + + if (maxvec < minvec) + return -ERANGE; + + nvec = platform_irq_count(dev); + + if (nvec < minvec) + return -ENOSPC; + + nvec = irq_calc_affinity_vectors(minvec, nvec, affd); + if (nvec < minvec) + return -ENOSPC; + + if (nvec > maxvec) + nvec = maxvec; + + size = sizeof(*ptr) + sizeof(unsigned int) * nvec; + ptr = devres_alloc(devm_platform_get_irqs_affinity_release, size, + GFP_KERNEL); + if (!ptr) + return -ENOMEM; + + ptr->count = nvec; + + for (i = 0; i < nvec; i++) { + int irq = platform_get_irq(dev, i); + if (irq < 0) { + ret = irq; + goto err_free_devres; + } + ptr->irq[i] = irq; + } + + desc = irq_create_affinity_masks(nvec, affd); + if (!desc) { + ret = -ENOMEM; + goto err_free_devres; + } + + for (i = 0; i < nvec; i++) { + ret = irq_update_affinity_desc(ptr->irq[i], &desc[i]); + if (ret) { + dev_err(&dev->dev, "failed to update irq%d affinity descriptor (%d)\n", + ptr->irq[i], ret); + goto err_free_desc; + } + } + + devres_add(&dev->dev, ptr); + + kfree(desc); + + *irqs = ptr->irq; + + return nvec; + +err_free_desc: + kfree(desc); +err_free_devres: + devres_free(ptr); + return ret; +} +EXPORT_SYMBOL_GPL(devm_platform_get_irqs_affinity); + /** * platform_get_resource_byname - get a resource for a device by name * @dev: platform device diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h index 77a2aada106d..4d75633e6735 100644 --- a/include/linux/platform_device.h +++ b/include/linux/platform_device.h @@ -15,6 +15,7 @@ #define PLATFORM_DEVID_NONE (-1) #define PLATFORM_DEVID_AUTO (-2) +struct irq_affinity; struct mfd_cell; struct property_entry; struct platform_device_id; @@ -70,6 +71,11 @@ devm_platform_ioremap_resource_byname(struct platform_device *pdev, extern int platform_get_irq(struct platform_device *, unsigned int); extern int platform_get_irq_optional(struct platform_device *, unsigned int); extern int platform_irq_count(struct platform_device *); +extern int devm_platform_get_irqs_affinity(struct platform_device *dev, + struct irq_affinity *affd, + unsigned int minvec, + unsigned int maxvec, + int **irqs); extern struct resource *platform_get_resource_byname(struct platform_device *, unsigned int, const char *);