linux-acpi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/6] resource: introduce union(), intersection() API
@ 2020-10-30 17:25 Andy Shevchenko
  2020-10-30 17:25 ` [PATCH v3 1/6] resource: Simplify region_intersects() by reducing conditionals Andy Shevchenko
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Andy Shevchenko @ 2020-10-30 17:25 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, linux-acpi; +Cc: Andy Shevchenko

Some users may want to use resource library to manage their own resources,
besides existing users that open code union() and intersection()
implementations.

Provide a generic API for wider use.

Changelog v3:
- rebased on top of v5.10-rc1
- dropped upstreamed dependencies
- added Rb tag to the last patch (Mika)

Andy Shevchenko (6):
  resource: Simplify region_intersects() by reducing conditionals
  resource: Group resource_overlaps() with other inline helpers
  resource: Introduce resource_union() for overlapping resources
  resource: Introduce resource_intersection() for overlapping resources
  PCI/ACPI: Replace open coded variant of resource_union()
  ACPI: watchdog: Replace open coded variant of resource_union()

 drivers/acpi/acpi_watchdog.c |  6 +-----
 drivers/acpi/pci_root.c      |  4 +---
 include/linux/ioport.h       | 34 +++++++++++++++++++++++++++-------
 kernel/resource.c            | 10 +++++-----
 4 files changed, 34 insertions(+), 20 deletions(-)

-- 
2.28.0


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

* [PATCH v3 1/6] resource: Simplify region_intersects() by reducing conditionals
  2020-10-30 17:25 [PATCH v3 0/6] resource: introduce union(), intersection() API Andy Shevchenko
@ 2020-10-30 17:25 ` Andy Shevchenko
  2020-10-30 17:25 ` [PATCH v3 2/6] resource: Group resource_overlaps() with other inline helpers Andy Shevchenko
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2020-10-30 17:25 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, linux-acpi; +Cc: Andy Shevchenko

Now we have for 'other' and 'type' variables

other	type	return
  0	  0	REGION_DISJOINT
  0	  x	REGION_INTERSECTS
  x	  0	REGION_DISJOINT
  x	  x	REGION_MIXED

Obviously it's easier to check 'type' for 0 first instead of
currently checked 'other'.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 kernel/resource.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/kernel/resource.c b/kernel/resource.c
index 3ae2f56cc79d..82df80417489 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -557,13 +557,13 @@ int region_intersects(resource_size_t start, size_t size, unsigned long flags,
 	}
 	read_unlock(&resource_lock);
 
-	if (other == 0)
-		return type ? REGION_INTERSECTS : REGION_DISJOINT;
+	if (type == 0)
+		return REGION_DISJOINT;
 
-	if (type)
-		return REGION_MIXED;
+	if (other == 0)
+		return REGION_INTERSECTS;
 
-	return REGION_DISJOINT;
+	return REGION_MIXED;
 }
 EXPORT_SYMBOL_GPL(region_intersects);
 
-- 
2.28.0


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

* [PATCH v3 2/6] resource: Group resource_overlaps() with other inline helpers
  2020-10-30 17:25 [PATCH v3 0/6] resource: introduce union(), intersection() API Andy Shevchenko
  2020-10-30 17:25 ` [PATCH v3 1/6] resource: Simplify region_intersects() by reducing conditionals Andy Shevchenko
@ 2020-10-30 17:25 ` Andy Shevchenko
  2020-10-30 17:25 ` [PATCH v3 3/6] resource: Introduce resource_union() for overlapping resources Andy Shevchenko
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2020-10-30 17:25 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, linux-acpi; +Cc: Andy Shevchenko

For better maintenance group resource_overlaps() with other inline helpers.
While at it, drop extra parentheses.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 include/linux/ioport.h | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/include/linux/ioport.h b/include/linux/ioport.h
index 5135d4b86cd6..df4581107536 100644
--- a/include/linux/ioport.h
+++ b/include/linux/ioport.h
@@ -229,6 +229,11 @@ static inline bool resource_contains(struct resource *r1, struct resource *r2)
 	return r1->start <= r2->start && r1->end >= r2->end;
 }
 
+/* True if any part of r1 overlaps r2 */
+static inline bool resource_overlaps(struct resource *r1, struct resource *r2)
+{
+       return r1->start <= r2->end && r1->end >= r2->start;
+}
 
 /* Convenience shorthand with allocation */
 #define request_region(start,n,name)		__request_region(&ioport_resource, (start), (n), (name), 0)
@@ -296,12 +301,6 @@ extern int
 walk_iomem_res_desc(unsigned long desc, unsigned long flags, u64 start, u64 end,
 		    void *arg, int (*func)(struct resource *, void *));
 
-/* True if any part of r1 overlaps r2 */
-static inline bool resource_overlaps(struct resource *r1, struct resource *r2)
-{
-       return (r1->start <= r2->end && r1->end >= r2->start);
-}
-
 struct resource *devm_request_free_mem_region(struct device *dev,
 		struct resource *base, unsigned long size);
 struct resource *request_free_mem_region(struct resource *base,
-- 
2.28.0


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

* [PATCH v3 3/6] resource: Introduce resource_union() for overlapping resources
  2020-10-30 17:25 [PATCH v3 0/6] resource: introduce union(), intersection() API Andy Shevchenko
  2020-10-30 17:25 ` [PATCH v3 1/6] resource: Simplify region_intersects() by reducing conditionals Andy Shevchenko
  2020-10-30 17:25 ` [PATCH v3 2/6] resource: Group resource_overlaps() with other inline helpers Andy Shevchenko
@ 2020-10-30 17:25 ` Andy Shevchenko
  2020-10-30 17:25 ` [PATCH v3 4/6] resource: Introduce resource_intersection() " Andy Shevchenko
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2020-10-30 17:25 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, linux-acpi
  Cc: Andy Shevchenko, Mika Westerberg, Kuppuswamy Sathyanarayanan,
	Bjorn Helgaas, linux-pci

Some already present users may utilize resource_union() helper.
Provide it for them and for wider use in the future.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: linux-pci@vger.kernel.org
---
 include/linux/ioport.h | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/include/linux/ioport.h b/include/linux/ioport.h
index df4581107536..40320eb5bc0e 100644
--- a/include/linux/ioport.h
+++ b/include/linux/ioport.h
@@ -10,9 +10,10 @@
 #define _LINUX_IOPORT_H
 
 #ifndef __ASSEMBLY__
+#include <linux/bits.h>
 #include <linux/compiler.h>
+#include <linux/minmax.h>
 #include <linux/types.h>
-#include <linux/bits.h>
 /*
  * Resources are tree-like, allowing
  * nesting etc..
@@ -235,6 +236,16 @@ static inline bool resource_overlaps(struct resource *r1, struct resource *r2)
        return r1->start <= r2->end && r1->end >= r2->start;
 }
 
+static inline bool
+resource_union(struct resource *r1, struct resource *r2, struct resource *r)
+{
+	if (!resource_overlaps(r1, r2))
+		return false;
+	r->start = min(r1->start, r2->start);
+	r->end = max(r1->end, r2->end);
+	return true;
+}
+
 /* Convenience shorthand with allocation */
 #define request_region(start,n,name)		__request_region(&ioport_resource, (start), (n), (name), 0)
 #define request_muxed_region(start,n,name)	__request_region(&ioport_resource, (start), (n), (name), IORESOURCE_MUXED)
-- 
2.28.0


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

* [PATCH v3 4/6] resource: Introduce resource_intersection() for overlapping resources
  2020-10-30 17:25 [PATCH v3 0/6] resource: introduce union(), intersection() API Andy Shevchenko
                   ` (2 preceding siblings ...)
  2020-10-30 17:25 ` [PATCH v3 3/6] resource: Introduce resource_union() for overlapping resources Andy Shevchenko
@ 2020-10-30 17:25 ` Andy Shevchenko
  2020-10-30 17:25 ` [PATCH v3 5/6] PCI/ACPI: Replace open coded variant of resource_union() Andy Shevchenko
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2020-10-30 17:25 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, linux-acpi; +Cc: Andy Shevchenko

There will be at least one user that can utilize new helper.
Provide the helper for future user and for wider use.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 include/linux/ioport.h | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/include/linux/ioport.h b/include/linux/ioport.h
index 40320eb5bc0e..ece1a8db309c 100644
--- a/include/linux/ioport.h
+++ b/include/linux/ioport.h
@@ -236,6 +236,16 @@ static inline bool resource_overlaps(struct resource *r1, struct resource *r2)
        return r1->start <= r2->end && r1->end >= r2->start;
 }
 
+static inline bool
+resource_intersection(struct resource *r1, struct resource *r2, struct resource *r)
+{
+	if (!resource_overlaps(r1, r2))
+		return false;
+	r->start = max(r1->start, r2->start);
+	r->end = min(r1->end, r2->end);
+	return true;
+}
+
 static inline bool
 resource_union(struct resource *r1, struct resource *r2, struct resource *r)
 {
-- 
2.28.0


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

* [PATCH v3 5/6] PCI/ACPI: Replace open coded variant of resource_union()
  2020-10-30 17:25 [PATCH v3 0/6] resource: introduce union(), intersection() API Andy Shevchenko
                   ` (3 preceding siblings ...)
  2020-10-30 17:25 ` [PATCH v3 4/6] resource: Introduce resource_intersection() " Andy Shevchenko
@ 2020-10-30 17:25 ` Andy Shevchenko
  2020-10-30 17:25 ` [PATCH v3 6/6] ACPI: watchdog: " Andy Shevchenko
  2020-11-02 19:29 ` [PATCH v3 0/6] resource: introduce union(), intersection() API Rafael J. Wysocki
  6 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2020-10-30 17:25 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, linux-acpi
  Cc: Andy Shevchenko, Kuppuswamy Sathyanarayanan, Bjorn Helgaas,
	linux-pci, Rafael J . Wysocki

Since we have resource_union() helper, let's utilize it here.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: linux-pci@vger.kernel.org
Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/acpi/pci_root.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c
index c12b5fb3e8fb..0bf072cef6cf 100644
--- a/drivers/acpi/pci_root.c
+++ b/drivers/acpi/pci_root.c
@@ -722,9 +722,7 @@ static void acpi_pci_root_validate_resources(struct device *dev,
 			 * our resources no longer match the ACPI _CRS, but
 			 * the kernel resource tree doesn't allow overlaps.
 			 */
-			if (resource_overlaps(res1, res2)) {
-				res2->start = min(res1->start, res2->start);
-				res2->end = max(res1->end, res2->end);
+			if (resource_union(res1, res2, res2)) {
 				dev_info(dev, "host bridge window expanded to %pR; %pR ignored\n",
 					 res2, res1);
 				free = true;
-- 
2.28.0


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

* [PATCH v3 6/6] ACPI: watchdog: Replace open coded variant of resource_union()
  2020-10-30 17:25 [PATCH v3 0/6] resource: introduce union(), intersection() API Andy Shevchenko
                   ` (4 preceding siblings ...)
  2020-10-30 17:25 ` [PATCH v3 5/6] PCI/ACPI: Replace open coded variant of resource_union() Andy Shevchenko
@ 2020-10-30 17:25 ` Andy Shevchenko
  2020-11-02 19:29 ` [PATCH v3 0/6] resource: introduce union(), intersection() API Rafael J. Wysocki
  6 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2020-10-30 17:25 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, linux-acpi
  Cc: Andy Shevchenko, Mika Westerberg, Rafael J . Wysocki

Since we have resource_union() helper, let's utilize it here.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/acpi/acpi_watchdog.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/acpi/acpi_watchdog.c b/drivers/acpi/acpi_watchdog.c
index 5c1e9ea43123..ca28183f4d13 100644
--- a/drivers/acpi/acpi_watchdog.c
+++ b/drivers/acpi/acpi_watchdog.c
@@ -151,11 +151,7 @@ void __init acpi_watchdog_init(void)
 		found = false;
 		resource_list_for_each_entry(rentry, &resource_list) {
 			if (rentry->res->flags == res.flags &&
-			    resource_overlaps(rentry->res, &res)) {
-				if (res.start < rentry->res->start)
-					rentry->res->start = res.start;
-				if (res.end > rentry->res->end)
-					rentry->res->end = res.end;
+			    resource_union(rentry->res, &res, rentry->res)) {
 				found = true;
 				break;
 			}
-- 
2.28.0


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

* Re: [PATCH v3 0/6] resource: introduce union(), intersection() API
  2020-10-30 17:25 [PATCH v3 0/6] resource: introduce union(), intersection() API Andy Shevchenko
                   ` (5 preceding siblings ...)
  2020-10-30 17:25 ` [PATCH v3 6/6] ACPI: watchdog: " Andy Shevchenko
@ 2020-11-02 19:29 ` Rafael J. Wysocki
  6 siblings, 0 replies; 8+ messages in thread
From: Rafael J. Wysocki @ 2020-11-02 19:29 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: Rafael J. Wysocki, Len Brown, ACPI Devel Maling List

On Fri, Oct 30, 2020 at 6:26 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> Some users may want to use resource library to manage their own resources,
> besides existing users that open code union() and intersection()
> implementations.
>
> Provide a generic API for wider use.
>
> Changelog v3:
> - rebased on top of v5.10-rc1
> - dropped upstreamed dependencies
> - added Rb tag to the last patch (Mika)
>
> Andy Shevchenko (6):
>   resource: Simplify region_intersects() by reducing conditionals
>   resource: Group resource_overlaps() with other inline helpers
>   resource: Introduce resource_union() for overlapping resources
>   resource: Introduce resource_intersection() for overlapping resources

Feel free to add

Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

to the four patches above (and I've already ACKed the remaining two).

If you want me to pick up the series, it would be good to resend it
with CCs to linux-kernel and Greg KH.

Thanks!

>   PCI/ACPI: Replace open coded variant of resource_union()
>   ACPI: watchdog: Replace open coded variant of resource_union()
>
>  drivers/acpi/acpi_watchdog.c |  6 +-----
>  drivers/acpi/pci_root.c      |  4 +---
>  include/linux/ioport.h       | 34 +++++++++++++++++++++++++++-------
>  kernel/resource.c            | 10 +++++-----
>  4 files changed, 34 insertions(+), 20 deletions(-)
>
> --

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

end of thread, other threads:[~2020-11-02 19:29 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-30 17:25 [PATCH v3 0/6] resource: introduce union(), intersection() API Andy Shevchenko
2020-10-30 17:25 ` [PATCH v3 1/6] resource: Simplify region_intersects() by reducing conditionals Andy Shevchenko
2020-10-30 17:25 ` [PATCH v3 2/6] resource: Group resource_overlaps() with other inline helpers Andy Shevchenko
2020-10-30 17:25 ` [PATCH v3 3/6] resource: Introduce resource_union() for overlapping resources Andy Shevchenko
2020-10-30 17:25 ` [PATCH v3 4/6] resource: Introduce resource_intersection() " Andy Shevchenko
2020-10-30 17:25 ` [PATCH v3 5/6] PCI/ACPI: Replace open coded variant of resource_union() Andy Shevchenko
2020-10-30 17:25 ` [PATCH v3 6/6] ACPI: watchdog: " Andy Shevchenko
2020-11-02 19:29 ` [PATCH v3 0/6] resource: introduce union(), intersection() API Rafael J. Wysocki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).