All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/5] driver core: platform: Introduce platform_get_mem_or_io()
@ 2020-12-09 20:36 Andy Shevchenko
  2020-12-09 20:36 ` [PATCH v2 2/5] vfio: platform: Switch to use platform_get_mem_or_io() Andy Shevchenko
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Andy Shevchenko @ 2020-12-09 20:36 UTC (permalink / raw)
  To: Greg Kroah-Hartman, linux-kernel
  Cc: Andy Shevchenko, Eric Auger, Alex Williamson, kvm, linux-usb,
	Peng Hao, Arnd Bergmann, Cornelia Huck

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.

Cc: Eric Auger <eric.auger@redhat.com>
Cc: Alex Williamson <alex.williamson@redhat.com>
Cc: kvm@vger.kernel.org
Cc: linux-usb@vger.kernel.org
Cc: Peng Hao <peng.hao2@zte.com.cn>
Cc: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
---
v2: moved to C-file and renamed for the sake of consistency with the rest
    platform code

 drivers/base/platform.c         | 15 +++++++++++++++
 include/linux/platform_device.h |  3 +++
 2 files changed, 18 insertions(+)

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 88aef93eb4dd..af0c37f720e6 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -63,6 +63,21 @@ struct resource *platform_get_resource(struct platform_device *dev,
 }
 EXPORT_SYMBOL_GPL(platform_get_resource);
 
+struct resource *platform_get_mem_or_io(struct platform_device *dev,
+					unsigned int num)
+{
+	u32 i;
+
+	for (i = 0; i < dev->num_resources; i++) {
+		struct resource *r = &dev->resource[i];
+
+		if ((resource_type(r) & (IORESOURCE_MEM|IORESOURCE_IO)) && num-- == 0)
+			return r;
+	}
+	return NULL;
+}
+EXPORT_SYMBOL_GPL(platform_get_mem_or_io);
+
 #ifdef CONFIG_HAS_IOMEM
 /**
  * devm_platform_get_and_ioremap_resource - call devm_ioremap_resource() for a
diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
index 77a2aada106d..ee6a9f10c2c7 100644
--- a/include/linux/platform_device.h
+++ b/include/linux/platform_device.h
@@ -52,6 +52,9 @@ extern struct device platform_bus;
 
 extern struct resource *platform_get_resource(struct platform_device *,
 					      unsigned int, unsigned int);
+extern struct resource *platform_get_mem_or_io(struct platform_device *,
+					       unsigned int);
+
 extern struct device *
 platform_find_device_by_driver(struct device *start,
 			       const struct device_driver *drv);
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-12-09 20:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-09 20:36 [PATCH v2 1/5] driver core: platform: Introduce platform_get_mem_or_io() Andy Shevchenko
2020-12-09 20:36 ` [PATCH v2 2/5] vfio: platform: Switch to use platform_get_mem_or_io() Andy Shevchenko
2020-12-09 20:36 ` [PATCH v2 3/5] usb: host: sl811: " Andy Shevchenko
2020-12-09 20:36 ` [PATCH v2 4/5] misc: pvpanic: Combine ACPI and platform drivers Andy Shevchenko
2020-12-09 20:36 ` [PATCH v2 5/5] misc: pvpanic: Replace OF headers by mod_devicetable.h Andy Shevchenko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.