devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] kernel/resource: Add new flag IORESOURCE_SHARED
@ 2015-06-05 10:51 Ricardo Ribalda Delgado
  2015-06-05 10:51 ` [PATCH 2/2] of/platform: Mark all device tree resources as SHARED Ricardo Ribalda Delgado
       [not found] ` <1433501478-15164-1-git-send-email-ricardo.ribalda-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 2 replies; 10+ messages in thread
From: Ricardo Ribalda Delgado @ 2015-06-05 10:51 UTC (permalink / raw)
  To: Grant Likely, Rob Herring, Rob Herring, Andrew Morton,
	Bjorn Helgaas, Vivek Goyal, Jakub Sitnicki, Mike Travis,
	Jiang Liu, Thierry Reding, devicetree, linux-kernel, gregkh,
	Tejun Heo, Cliff Wickman
  Cc: Ricardo Ribalda Delgado

Some device tree platforms have not defined correctly their memory
resources (i.e. Overlapping or duplication of resources).
To avoid this issue we have historically avoided to add their resources to
the resource tree. This leads to code duplication and oops when trying to
unload dynamically a device tree (feature introduced recently).

This new flag tells the resource system that a resource can be shared by
multiple owners, so we can support device trees with problems at the
same time that we do not duplicate code or crash when unloading the
device tree.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
 include/linux/ioport.h | 1 +
 kernel/resource.c      | 6 ++++--
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/include/linux/ioport.h b/include/linux/ioport.h
index 388e3ae94f7a..f4d992381529 100644
--- a/include/linux/ioport.h
+++ b/include/linux/ioport.h
@@ -49,6 +49,7 @@ struct resource {
 #define IORESOURCE_WINDOW	0x00200000	/* forwarded by bridge */
 #define IORESOURCE_MUXED	0x00400000	/* Resource is software muxed */
 
+#define IORESOURCE_SHARED	0x04000000	/* Resource can be shared */
 #define IORESOURCE_EXCLUSIVE	0x08000000	/* Userland may not map this resource */
 #define IORESOURCE_DISABLED	0x10000000
 #define IORESOURCE_UNSET	0x20000000	/* No address assigned yet */
diff --git a/kernel/resource.c b/kernel/resource.c
index 90552aab5f2d..4a3626489b62 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -210,6 +210,7 @@ static struct resource * __request_resource(struct resource *root, struct resour
 	resource_size_t start = new->start;
 	resource_size_t end = new->end;
 	struct resource *tmp, **p;
+	bool root_shared = root && root->flags & IORESOURCE_SHARED;
 
 	if (end < start)
 		return root;
@@ -220,14 +221,15 @@ static struct resource * __request_resource(struct resource *root, struct resour
 	p = &root->child;
 	for (;;) {
 		tmp = *p;
-		if (!tmp || tmp->start > end) {
+		if (!tmp || tmp->start > end ||
+			(root_shared && tmp->start > start)) {
 			new->sibling = tmp;
 			*p = new;
 			new->parent = root;
 			return NULL;
 		}
 		p = &tmp->sibling;
-		if (tmp->end < start)
+		if (tmp->end < start || root_shared)
 			continue;
 		return tmp;
 	}
-- 
2.1.4

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

end of thread, other threads:[~2015-06-09 12:33 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-05 10:51 [PATCH 1/2] kernel/resource: Add new flag IORESOURCE_SHARED Ricardo Ribalda Delgado
2015-06-05 10:51 ` [PATCH 2/2] of/platform: Mark all device tree resources as SHARED Ricardo Ribalda Delgado
     [not found]   ` <1433501478-15164-2-git-send-email-ricardo.ribalda-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-06-05 16:45     ` Rob Herring
     [not found]       ` <CAL_JsqLOqpP4E5mG5t5RvaTs96jLC=umY2cUQEhyZiWJNOt1nQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-06-05 16:51         ` Ricardo Ribalda Delgado
     [not found]           ` <CAPybu_0s=9yTFH5jngh6=Zuz0iia0F1RU6AsLi-vcWNrF3-qYg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-06-07 14:01             ` Grant Likely
     [not found] ` <1433501478-15164-1-git-send-email-ricardo.ribalda-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-06-08 18:23   ` [PATCH 1/2] kernel/resource: Add new flag IORESOURCE_SHARED Grant Likely
     [not found]     ` <20150608182310.1F13FC406AA-WNowdnHR2B42iJbIjFUEsiwD8/FfD2ys@public.gmane.org>
2015-06-08 20:02       ` Ricardo Ribalda Delgado
     [not found]         ` <CAPybu_2-EZoMEkWR9BoRfzGBevxCp-sd+CiVK2DhRjLoy5Pfyg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-06-09 11:13           ` Grant Likely
2015-06-09 12:30             ` Ricardo Ribalda Delgado
     [not found]             ` <20150609111320.F299FC40580-WNowdnHR2B42iJbIjFUEsiwD8/FfD2ys@public.gmane.org>
2015-06-09 12:33               ` Ricardo Ribalda Delgado

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