2020-10-28 18:05:06

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH v1 1/5] driver core: platform: Introduce platform_get_mem_or_io_resource()

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 <[email protected]>
Cc: Eric Auger <[email protected]>
Cc: Alex Williamson <[email protected]>
Cc: Cornelia Huck <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: Peng Hao <[email protected]>
Cc: Arnd Bergmann <[email protected]>
---
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);
--
2.28.0


2020-10-28 18:05:13

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH v1 2/5] vfio: platform: Switch to use platform_get_mem_or_io_resource()

Switch to use new platform_get_mem_or_io_resource() instead of
home grown analogue.

Cc: Eric Auger <[email protected]>
Cc: Alex Williamson <[email protected]>
Cc: Cornelia Huck <[email protected]>
Cc: [email protected]
Signed-off-by: Andy Shevchenko <[email protected]>
---
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)
--
2.28.0

2020-10-28 18:05:42

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH v1 3/5] usb: host: sl811: Switch to use platform_get_mem_or_io_resource()

Switch to use new platform_get_mem_or_io_resource() instead of
home grown analogue.

Note, the code has been moved upper in the function to allow farther cleanups,
such as resource sanity check.

Cc: [email protected]
Signed-off-by: Andy Shevchenko <[email protected]>
---
drivers/usb/host/sl811-hcd.c | 20 +++++++++-----------
1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c
index adaf4063690a..7e0d6f686231 100644
--- a/drivers/usb/host/sl811-hcd.c
+++ b/drivers/usb/host/sl811-hcd.c
@@ -1614,12 +1614,18 @@ sl811h_probe(struct platform_device *dev)
void __iomem *addr_reg;
void __iomem *data_reg;
int retval;
- u8 tmp, ioaddr = 0;
+ u8 tmp, ioaddr;
unsigned long irqflags;

if (usb_disabled())
return -ENODEV;

+ /* the chip may be wired for either kind of addressing */
+ addr = platform_get_mem_or_io_resource(dev, 0);
+ data = platform_get_mem_or_io_resource(dev, 1);
+ if (!addr || !data || resource_type(addr) != resource_type(data))
+ return -ENODEV;
+
/* basic sanity checks first. board-specific init logic should
* have initialized these three resources and probably board
* specific platform_data. we don't probe for IRQs, and do only
@@ -1632,16 +1638,8 @@ sl811h_probe(struct platform_device *dev)
irq = ires->start;
irqflags = ires->flags & IRQF_TRIGGER_MASK;

- /* the chip may be wired for either kind of addressing */
- addr = platform_get_resource(dev, IORESOURCE_MEM, 0);
- data = platform_get_resource(dev, IORESOURCE_MEM, 1);
- retval = -EBUSY;
- if (!addr || !data) {
- addr = platform_get_resource(dev, IORESOURCE_IO, 0);
- data = platform_get_resource(dev, IORESOURCE_IO, 1);
- if (!addr || !data)
- return -ENODEV;
- ioaddr = 1;
+ ioaddr = resource_type(addr) == IORESOURCE_IO;
+ if (ioaddr) {
/*
* NOTE: 64-bit resource->start is getting truncated
* to avoid compiler warning, assuming that ->start
--
2.28.0

2020-10-28 18:07:43

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH v1 5/5] misc: pvpanic: Replace OF headers by mod_devicetable.h

There is no use for OF headers in the driver, but mod_devicetable.h
must be included. Update driver accordingly.

Cc: Peng Hao <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Signed-off-by: Andy Shevchenko <[email protected]>
---
drivers/misc/pvpanic.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/misc/pvpanic.c b/drivers/misc/pvpanic.c
index 103a09ed651d..a45e70c5b6b9 100644
--- a/drivers/misc/pvpanic.c
+++ b/drivers/misc/pvpanic.c
@@ -11,11 +11,11 @@
#include <linux/io.h>
#include <linux/kernel.h>
#include <linux/kexec.h>
+#include <linux/mod_devicetable.h>
#include <linux/module.h>
-#include <linux/of.h>
-#include <linux/of_address.h>
#include <linux/platform_device.h>
#include <linux/types.h>
+
#include <uapi/misc/pvpanic.h>

static void __iomem *base;
--
2.28.0

2020-12-03 12:59:09

by Eric Auger

[permalink] [raw]
Subject: Re: [PATCH v1 2/5] vfio: platform: Switch to use platform_get_mem_or_io_resource()

Hi Andy,

On 10/27/20 6:58 PM, Andy Shevchenko wrote:
> Switch to use new platform_get_mem_or_io_resource() instead of
> home grown analogue.
>
> Cc: Eric Auger <[email protected]>
> Cc: Alex Williamson <[email protected]>
> Cc: Cornelia Huck <[email protected]>
> Cc: [email protected]
> Signed-off-by: Andy Shevchenko <[email protected]>
Acked-by: Eric Auger <[email protected]>

Thanks

Eric
> ---
> 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)
>

2020-12-03 13:10:14

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v1 2/5] vfio: platform: Switch to use platform_get_mem_or_io_resource()

On Thu, Dec 03, 2020 at 01:54:38PM +0100, Auger Eric wrote:
> Hi Andy,
>
> On 10/27/20 6:58 PM, Andy Shevchenko wrote:
> > Switch to use new platform_get_mem_or_io_resource() instead of
> > home grown analogue.
> >
> > Cc: Eric Auger <[email protected]>
> > Cc: Alex Williamson <[email protected]>
> > Cc: Cornelia Huck <[email protected]>
> > Cc: [email protected]
> > Signed-off-by: Andy Shevchenko <[email protected]>
> Acked-by: Eric Auger <[email protected]>

Thanks!

Greg, do I need to do anything else with this series?

--
With Best Regards,
Andy Shevchenko


2020-12-03 13:25:52

by Cornelia Huck

[permalink] [raw]
Subject: Re: [PATCH v1 1/5] driver core: platform: Introduce platform_get_mem_or_io_resource()

On Tue, 27 Oct 2020 19:58:02 +0200
Andy Shevchenko <[email protected]> wrote:

> 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 <[email protected]>
> Cc: Eric Auger <[email protected]>
> Cc: Alex Williamson <[email protected]>
> Cc: Cornelia Huck <[email protected]>
> Cc: [email protected]
> Cc: [email protected]
> Cc: Peng Hao <[email protected]>
> Cc: Arnd Bergmann <[email protected]>
> ---
> 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,

Minor nit: If I would want to break up the long line, I'd use

static inline struct resource *
platform_get_mem_or_io_resource(...)

> + 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);

Reviewed-by: Cornelia Huck <[email protected]>

2020-12-03 13:28:41

by Cornelia Huck

[permalink] [raw]
Subject: Re: [PATCH v1 2/5] vfio: platform: Switch to use platform_get_mem_or_io_resource()

On Tue, 27 Oct 2020 19:58:03 +0200
Andy Shevchenko <[email protected]> wrote:

> Switch to use new platform_get_mem_or_io_resource() instead of
> home grown analogue.
>
> Cc: Eric Auger <[email protected]>
> Cc: Alex Williamson <[email protected]>
> Cc: Cornelia Huck <[email protected]>
> Cc: [email protected]
> Signed-off-by: Andy Shevchenko <[email protected]>
> ---
> drivers/vfio/platform/vfio_platform.c | 13 +------------
> 1 file changed, 1 insertion(+), 12 deletions(-)

Reviewed-by: Cornelia Huck <[email protected]>

2020-12-03 18:09:44

by Alex Williamson

[permalink] [raw]
Subject: Re: [PATCH v1 2/5] vfio: platform: Switch to use platform_get_mem_or_io_resource()

On Tue, 27 Oct 2020 19:58:03 +0200
Andy Shevchenko <[email protected]> wrote:

> Switch to use new platform_get_mem_or_io_resource() instead of
> home grown analogue.
>
> Cc: Eric Auger <[email protected]>
> Cc: Alex Williamson <[email protected]>
> Cc: Cornelia Huck <[email protected]>
> Cc: [email protected]
> Signed-off-by: Andy Shevchenko <[email protected]>
> ---
> drivers/vfio/platform/vfio_platform.c | 13 +------------
> 1 file changed, 1 insertion(+), 12 deletions(-)

Acked-by: Alex Williamson <[email protected]>

2020-12-09 16:51:17

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v1 2/5] vfio: platform: Switch to use platform_get_mem_or_io_resource()

On Wed, Dec 09, 2020 at 03:47:06PM +0100, Greg Kroah-Hartman wrote:
> On Thu, Dec 03, 2020 at 03:07:19PM +0200, Andy Shevchenko wrote:
> > On Thu, Dec 03, 2020 at 01:54:38PM +0100, Auger Eric wrote:
> > > On 10/27/20 6:58 PM, Andy Shevchenko wrote:
> > > > Switch to use new platform_get_mem_or_io_resource() instead of
> > > > home grown analogue.
> > > >
> > > > Cc: Eric Auger <[email protected]>
> > > > Cc: Alex Williamson <[email protected]>
> > > > Cc: Cornelia Huck <[email protected]>
> > > > Cc: [email protected]
> > > > Signed-off-by: Andy Shevchenko <[email protected]>
> > > Acked-by: Eric Auger <[email protected]>
> >
> > Thanks!
> >
> > Greg, do I need to do anything else with this series?
>
> Have them taken by the vfio maintainers? I'm not that person :)

But it can't be done with a first patch that provides a new API.
The rest seems under your realm, if I didn't miss anything.
Btw, VFIO agreed on the change (as per given tags).

--
With Best Regards,
Andy Shevchenko


2020-12-09 16:57:14

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH v1 2/5] vfio: platform: Switch to use platform_get_mem_or_io_resource()

On Wed, Dec 09, 2020 at 06:48:16PM +0200, Andy Shevchenko wrote:
> On Wed, Dec 09, 2020 at 03:47:06PM +0100, Greg Kroah-Hartman wrote:
> > On Thu, Dec 03, 2020 at 03:07:19PM +0200, Andy Shevchenko wrote:
> > > On Thu, Dec 03, 2020 at 01:54:38PM +0100, Auger Eric wrote:
> > > > On 10/27/20 6:58 PM, Andy Shevchenko wrote:
> > > > > Switch to use new platform_get_mem_or_io_resource() instead of
> > > > > home grown analogue.
> > > > >
> > > > > Cc: Eric Auger <[email protected]>
> > > > > Cc: Alex Williamson <[email protected]>
> > > > > Cc: Cornelia Huck <[email protected]>
> > > > > Cc: [email protected]
> > > > > Signed-off-by: Andy Shevchenko <[email protected]>
> > > > Acked-by: Eric Auger <[email protected]>
> > >
> > > Thanks!
> > >
> > > Greg, do I need to do anything else with this series?
> >
> > Have them taken by the vfio maintainers? I'm not that person :)
>
> But it can't be done with a first patch that provides a new API.
> The rest seems under your realm, if I didn't miss anything.
> Btw, VFIO agreed on the change (as per given tags).

Ok, can you resend all of these, with the vfio tags added, so I know to
take them all?

thanks,

greg k-h

2020-12-09 18:25:53

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v1 2/5] vfio: platform: Switch to use platform_get_mem_or_io_resource()

On Wed, Dec 09, 2020 at 05:53:45PM +0100, Greg Kroah-Hartman wrote:
> On Wed, Dec 09, 2020 at 06:48:16PM +0200, Andy Shevchenko wrote:
> > On Wed, Dec 09, 2020 at 03:47:06PM +0100, Greg Kroah-Hartman wrote:
> > > On Thu, Dec 03, 2020 at 03:07:19PM +0200, Andy Shevchenko wrote:
> > > > On Thu, Dec 03, 2020 at 01:54:38PM +0100, Auger Eric wrote:

...

> > > > Greg, do I need to do anything else with this series?

> > > Have them taken by the vfio maintainers? I'm not that person :)

> > But it can't be done with a first patch that provides a new API.
> > The rest seems under your realm, if I didn't miss anything.
> > Btw, VFIO agreed on the change (as per given tags).

> Ok, can you resend all of these, with the vfio tags added, so I know to
> take them all?

Sure. Will do soon.

--
With Best Regards,
Andy Shevchenko


2020-12-10 01:43:19

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH v1 2/5] vfio: platform: Switch to use platform_get_mem_or_io_resource()

On Thu, Dec 03, 2020 at 03:07:19PM +0200, Andy Shevchenko wrote:
> On Thu, Dec 03, 2020 at 01:54:38PM +0100, Auger Eric wrote:
> > Hi Andy,
> >
> > On 10/27/20 6:58 PM, Andy Shevchenko wrote:
> > > Switch to use new platform_get_mem_or_io_resource() instead of
> > > home grown analogue.
> > >
> > > Cc: Eric Auger <[email protected]>
> > > Cc: Alex Williamson <[email protected]>
> > > Cc: Cornelia Huck <[email protected]>
> > > Cc: [email protected]
> > > Signed-off-by: Andy Shevchenko <[email protected]>
> > Acked-by: Eric Auger <[email protected]>
>
> Thanks!
>
> Greg, do I need to do anything else with this series?

Have them taken by the vfio maintainers? I'm not that person :)