From patchwork Tue Oct 27 12:10:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 319048 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp1512123ilc; Tue, 27 Oct 2020 05:14:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwEDM8d5fFjkXTbXAyFMcVJNGXXC6Jhi0/Ly0LRNTUBRwn5IBQe4JW1CrFUCQt1EIIlD3jw X-Received: by 2002:a17:906:6a07:: with SMTP id o7mr2048949ejr.454.1603800873355; Tue, 27 Oct 2020 05:14:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603800873; cv=none; d=google.com; s=arc-20160816; b=LUp5Xxg86CXwA5w3tMFjozqDyDKlSShViZe/6bIfJ5975I9WH9kdSmXL0oOYlwHZUu dkmmm1SmckT5k9WnZ/YQhPKWEJpcNReJAgIQofQ73wOxDKvCjmzYmVdQVGyDI5cf5YTq D9VdOoG4TARPAasHrioPgAEbM43Cu4/wbGugFDaMMwVHH50xegIAXwEinjrFGQZv3hv8 EFP9gx82FRxw5fUCFDotyMGfzNUt+pfo6d+J61lwSxRX7QuIcuXVGS/AMTnId/HEQRYE UwAw8mLSLrSJIHo+aqpmOzim+2NPr9ddkFEvPHIIoM3PcYiJOJnQYyvZIHSZzBt2HsPl HKHQ== 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=DhZT6hIxujgBSH+e25ek2pSe2YCpntPOL4kB2QvLPtEgd3RWqHCaGWW1yCkz18OsZd JhTQWbpoz1VOAfnGFBoocAixdf4Tytr8TJbk4RIKa8kbFBdnCxH1yKeavuvmaYEi2E0r uc/zAfel8DAjXRhJy9X0BWFCEhMDbFFwVlLlHBvuBjfal46yoho5o9QzVR+8/MsAHAjn SsRSR49UjIGlxCvpsNIE9eIErdYxmYNuBpdtLqOb8UUiCa1RUL126t1RlqoIa5fxqbKJ qnBc4zY9OouH3mXmirJUc5jZ4SCMZ5/ynGhr/7ItVxJCckE8g/CEd//faMOw2qgU28fS jI2Q== 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 h22si749788edj.40.2020.10.27.05.14.33 for ; Tue, 27 Oct 2020 05:14:33 -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 S1750756AbgJ0MOQ (ORCPT ); Tue, 27 Oct 2020 08:14:16 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:6404 "EHLO szxga07-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750748AbgJ0MOP (ORCPT ); Tue, 27 Oct 2020 08:14:15 -0400 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4CL9cB04t6z6yB1; Tue, 27 Oct 2020 20:14:18 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.487.0; Tue, 27 Oct 2020 20:14:05 +0800 From: John Garry To: , , , , CC: , , , , John Garry Subject: [PATCH 2/3] Driver core: platform: Add platform_get_irqs_affinity() Date: Tue, 27 Oct 2020 20:10:23 +0800 Message-ID: <1603800624-180488-3-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1603800624-180488-1-git-send-email-john.garry@huawei.com> References: <1603800624-180488-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 Reported-by: kernel test robot 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 *);