From patchwork Wed Oct 28 12:33:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 319325 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp45071ilc; Wed, 28 Oct 2020 18:22:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy3o3peqeoPbFKtr8iUhhfsKNHZpF3m9iM2l4Gyl6FZGk3Si8BpFGgxdSUVUk9vJQGxAY2o X-Received: by 2002:aa7:cfc1:: with SMTP id r1mr1742503edy.138.1603934545199; Wed, 28 Oct 2020 18:22:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603934545; cv=none; d=google.com; s=arc-20160816; b=i0/3PqatHQUPfPemau+ou1VHqYh69r0ajPmwfXPVZJMNgEVX/hRP6ZhrYjozEoeRsG fq2lEMuxh1eQjcdbtTuta2loyQ7N282KHZWqK3kdRrv+NkX5pKgix5ta1mAgxTn3SkpO MkoYZDqLEdykZjtAlaWUF0y8jdwKH5QYR9UPLwU6U46rNIOqeITlqSio7sP8mnnmsLoL T4t2rsaErbwnymReLM3dKCgCnsy8Xa7oEaGSWSgiXpTMHsEEZjUE8nxANx4rU+qtbg8n vMKHGXiJ2w7JEwbcKuSOW/ej3hPc7DzeSzzgjua8jpI8Zfie0O3IEzz2asY/BrgK/6ur oH8g== 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=wAHb5kadjJRL6mW5h4QqywjqmkGghAtBuSuyOdd/KKE=; b=yO//jjjpXu1YUqEMRREZ38j8op5j9YAo+6mYZbSQTZhxKIssrzfVsgu4W+/b/N3XqV /qvIqzZuDsDf6iCk07NrdgjYDqOTkzc0c6GW3xPuvHRa/c3w39wnE1Ux7Y0gLlU2cvL5 rsZN/mjQOXMm4QuaybRLdDc3hjhR6MslMs0C/9Blj+NbGt779PIaOy/F1FV7CCef3YPH dscS8Q3EKr0+wf4i2T7qQr/wm9letvpidlF9XsuHLLMOu/0B4PXRMK2e3a4NKOzuHxW8 SGdx51hJG9JjVQapSONLS/p7/KFycAJSgdZW6gW0L/3puj1D5RR45qCqwqjTGehkuS2/ FJuA== 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 yl23si849427ejb.441.2020.10.28.18.22.25 for ; Wed, 28 Oct 2020 18:22:25 -0700 (PDT) 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 S1729602AbgJ1WEx (ORCPT ); Wed, 28 Oct 2020 18:04:53 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:7075 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728221AbgJ1WCN (ORCPT ); Wed, 28 Oct 2020 18:02:13 -0400 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4CLp3v5KtTzLqWJ; Wed, 28 Oct 2020 20:36:59 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.487.0; Wed, 28 Oct 2020 20:36:47 +0800 From: John Garry To: , , , , CC: , , , , John Garry Subject: [PATCH v2 2/3] Driver core: platform: Add platform_get_irqs_affinity() Date: Wed, 28 Oct 2020 20:33:06 +0800 Message-ID: <1603888387-52499-3-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1603888387-52499-1-git-send-email-john.garry@huawei.com> References: <1603888387-52499-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 platform device driver is expected to hold all the IRQ numbers, as there is no point in holding these in the common platform_device structure. Signed-off-by: John Garry --- drivers/base/platform.c | 58 +++++++++++++++++++++++++++++++++ include/linux/platform_device.h | 5 +++ 2 files changed, 63 insertions(+) -- 2.26.2 diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 88aef93eb4dd..c110b35469d6 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -269,6 +269,64 @@ int platform_get_irq(struct platform_device *dev, unsigned int num) } EXPORT_SYMBOL_GPL(platform_get_irq); +/** + * platform_get_irqs_affinity - get all IRQs for a device using an affinity + * descriptor + * @dev: platform device pointer + * @affd: affinity descriptor, must be set + * @count: pointer to count of IRQS + * @irqs: pointer holder for IRQ numbers + * + * Gets a full set of IRQs for a platform device, and updates IRQ afffinty + * according to the passed affinity descriptor + * + * Return: 0 on success, negative error number on failure. + */ +int platform_get_irqs_affinity(struct platform_device *dev, + struct irq_affinity *affd, + unsigned int *count, + int **irqs) +{ + struct irq_affinity_desc *desc; + int i, *pirqs; + + if (!affd) + return -EPERM; + + *count = platform_irq_count(dev); + + if (*count <= affd->pre_vectors + affd->post_vectors) + return -EIO; + + pirqs = kcalloc(*count, sizeof(int), GFP_KERNEL); + if (!pirqs) + return -ENOMEM; + + for (i = 0; i < *count; i++) { + int irq = platform_get_irq(dev, i); + if (irq < 0) { + kfree(pirqs); + return irq; + } + pirqs[i] = irq; + } + + desc = irq_create_affinity_masks(*count, affd); + if (!desc) { + kfree(pirqs); + return -ENOMEM; + } + + for (i = 0; i < *count; i++) + irq_update_affinity_desc(pirqs[i], &desc[i]); + + kfree(desc); + *irqs = pirqs; + + return 0; +} +EXPORT_SYMBOL_GPL(platform_get_irqs_affinity); + /** * platform_irq_count - Count the number of IRQs a platform device uses * @dev: platform device diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h index 77a2aada106d..c3f4fc5a76b9 100644 --- a/include/linux/platform_device.h +++ b/include/linux/platform_device.h @@ -11,6 +11,7 @@ #define _PLATFORM_DEVICE_H_ #include +#include #define PLATFORM_DEVID_NONE (-1) #define PLATFORM_DEVID_AUTO (-2) @@ -70,6 +71,10 @@ 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 platform_get_irqs_affinity(struct platform_device *dev, + struct irq_affinity *affd, + unsigned int *count, + int **irqs); extern struct resource *platform_get_resource_byname(struct platform_device *, unsigned int, const char *);