From patchwork Tue Oct 27 17:58:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 11861257 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=-12.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, 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 38B29C55178 for ; Tue, 27 Oct 2020 17:59:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D6D5C21556 for ; Tue, 27 Oct 2020 17:59:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1823657AbgJ0R7Z (ORCPT ); Tue, 27 Oct 2020 13:59:25 -0400 Received: from mga03.intel.com ([134.134.136.65]:34126 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1823203AbgJ0R6L (ORCPT ); Tue, 27 Oct 2020 13:58:11 -0400 IronPort-SDR: fW7T60hx1U28IPgMbQ/ufL/NsJsLrDr8h6qOpKkB5QSrnKFjB6eeDphAXriX73rCczz297b1SU KEzTXfMmJZLg== X-IronPort-AV: E=McAfee;i="6000,8403,9787"; a="168230686" X-IronPort-AV: E=Sophos;i="5.77,424,1596524400"; d="scan'208";a="168230686" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Oct 2020 10:58:10 -0700 IronPort-SDR: pVBI96o6WMqJ6mq5a8oXe8bATKbSaxP/VCM1wYfH+mNa36hNrOtpMcv+1HKUfbt7UIprRLPVTs BcddLyFjzpHQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,424,1596524400"; d="scan'208";a="303841822" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga008.fm.intel.com with ESMTP; 27 Oct 2020 10:58:07 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id E4DE0179; Tue, 27 Oct 2020 19:58:06 +0200 (EET) From: Andy Shevchenko To: Greg Kroah-Hartman , linux-kernel@vger.kernel.org Cc: Andy Shevchenko , Eric Auger , Alex Williamson , Cornelia Huck , kvm@vger.kernel.org, linux-usb@vger.kernel.org, Peng Hao , Arnd Bergmann Subject: [PATCH v1 1/5] driver core: platform: Introduce platform_get_mem_or_io_resource() Date: Tue, 27 Oct 2020 19:58:02 +0200 Message-Id: <20201027175806.20305-1-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org There are at least few existing users of the proposed API which retrieves either MEM or IO resource from platform device. Make it common to utilize in the existing and new users. Signed-off-by: Andy Shevchenko Cc: Eric Auger Cc: Alex Williamson Cc: Cornelia Huck Cc: kvm@vger.kernel.org Cc: linux-usb@vger.kernel.org Cc: Peng Hao Cc: Arnd Bergmann Reviewed-by: Cornelia Huck --- include/linux/platform_device.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h index 77a2aada106d..eb8d74744e29 100644 --- a/include/linux/platform_device.h +++ b/include/linux/platform_device.h @@ -52,6 +52,19 @@ extern struct device platform_bus; extern struct resource *platform_get_resource(struct platform_device *, unsigned int, unsigned int); +static inline +struct resource *platform_get_mem_or_io_resource(struct platform_device *pdev, + unsigned int num) +{ + struct resource *res; + + res = platform_get_resource(pdev, IORESOURCE_MEM, num); + if (res) + return res; + + return platform_get_resource(pdev, IORESOURCE_IO, num); +} + extern struct device * platform_find_device_by_driver(struct device *start, const struct device_driver *drv); From patchwork Tue Oct 27 17:58:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 11861255 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=-12.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, 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 6CE10C4363A for ; Tue, 27 Oct 2020 17:59:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1C35121556 for ; Tue, 27 Oct 2020 17:59:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1823242AbgJ0R62 (ORCPT ); Tue, 27 Oct 2020 13:58:28 -0400 Received: from mga18.intel.com ([134.134.136.126]:41011 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1823232AbgJ0R60 (ORCPT ); Tue, 27 Oct 2020 13:58:26 -0400 IronPort-SDR: tv2AXyGcjbo/W0fJDYrKQ7Lr7vZE3BmcLCFCroxm09vtSWEnjU4SThl4cmeHo09jtWN4l16te1 JhvbcIJfzCxA== X-IronPort-AV: E=McAfee;i="6000,8403,9787"; a="155910868" X-IronPort-AV: E=Sophos;i="5.77,424,1596524400"; d="scan'208";a="155910868" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Oct 2020 10:58:09 -0700 IronPort-SDR: FVTLGKaPm2nU8nQKKMMyNr0H3IvtVTsE/+UA5+5KS0SCJgBb4qe1dEnGuDqICwUTjJ1SuENcSU Nm6bSf3gOqzw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,424,1596524400"; d="scan'208";a="323036172" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga006.jf.intel.com with ESMTP; 27 Oct 2020 10:58:07 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 00436178; Tue, 27 Oct 2020 19:58:06 +0200 (EET) From: Andy Shevchenko To: Greg Kroah-Hartman , linux-kernel@vger.kernel.org Cc: Andy Shevchenko , Eric Auger , Alex Williamson , Cornelia Huck , kvm@vger.kernel.org Subject: [PATCH v1 2/5] vfio: platform: Switch to use platform_get_mem_or_io_resource() Date: Tue, 27 Oct 2020 19:58:03 +0200 Message-Id: <20201027175806.20305-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201027175806.20305-1-andriy.shevchenko@linux.intel.com> References: <20201027175806.20305-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Switch to use new platform_get_mem_or_io_resource() instead of home grown analogue. Cc: Eric Auger Cc: Alex Williamson Cc: Cornelia Huck Cc: kvm@vger.kernel.org Signed-off-by: Andy Shevchenko Acked-by: Eric Auger Reviewed-by: Cornelia Huck Acked-by: Alex Williamson --- drivers/vfio/platform/vfio_platform.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/drivers/vfio/platform/vfio_platform.c b/drivers/vfio/platform/vfio_platform.c index 1e2769010089..84afafb6941b 100644 --- a/drivers/vfio/platform/vfio_platform.c +++ b/drivers/vfio/platform/vfio_platform.c @@ -25,19 +25,8 @@ static struct resource *get_platform_resource(struct vfio_platform_device *vdev, int num) { struct platform_device *dev = (struct platform_device *) vdev->opaque; - int i; - for (i = 0; i < dev->num_resources; i++) { - struct resource *r = &dev->resource[i]; - - if (resource_type(r) & (IORESOURCE_MEM|IORESOURCE_IO)) { - if (!num) - return r; - - num--; - } - } - return NULL; + return platform_get_mem_or_io_resource(dev, num); } static int get_platform_irq(struct vfio_platform_device *vdev, int i)