mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] adjust_resource()
@ 2003-12-18 14:14 Matthew Wilcox
  0 siblings, 0 replies; only message in thread
From: Matthew Wilcox @ 2003-12-18 14:14 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: Russell King, linux-kernel


Hi Linus.

I need something along these lines to cope with some devices on PA-RISC
and Russell also needs something like it for PCMCIA.  What do you think?

diff -urpNX dontdiff linus-2.6/include/linux/ioport.h parisc-2.6/include/linux/ioport.h
--- linus-2.6/include/linux/ioport.h	Thu Dec 18 06:10:09 2003
+++ parisc-2.6/include/linux/ioport.h	Thu Dec 18 05:48:57 2003
@@ -99,6 +99,8 @@ extern int allocate_resource(struct reso
 			     void (*alignf)(void *, struct resource *,
 					    unsigned long, unsigned long),
 			     void *alignf_data);
+int adjust_resource(struct resource *res, unsigned long start,
+		    unsigned long size);
 
 /* Convenience shorthand with allocation */
 #define request_region(start,n,name)	__request_region(&ioport_resource, (start), (n), (name))
diff -urpNX dontdiff linus-2.6/kernel/resource.c parisc-2.6/kernel/resource.c
--- linus-2.6/kernel/resource.c	Thu Dec 18 06:10:10 2003
+++ parisc-2.6/kernel/resource.c	Thu Dec 18 05:48:59 2003
@@ -359,6 +361,49 @@ int insert_resource(struct resource *par
 }
 
 EXPORT_SYMBOL(insert_resource);
+
+/*
+ * Given an existing resource, change its start and size to match the
+ * arguments.  Returns -EBUSY if it can't fit.  Existing children of
+ * the resource are assumed to be immutable.
+ */
+int adjust_resource(struct resource *res, unsigned long start, unsigned long size)
+{
+	struct resource *tmp, *parent = res->parent;
+	unsigned long end = start + size - 1;
+	int result = -EBUSY;
+
+	write_lock(&resource_lock);
+
+	if ((start < parent->start) || (end > parent->end))
+		goto out;
+
+	for (tmp = res->child; tmp; tmp = tmp->sibling) {
+		if ((tmp->start < start) || (tmp->end > end))
+			goto out;
+	}
+
+	if (res->sibling && (res->sibling->start <= end))
+		goto out;
+
+	tmp = parent->child;
+	if (tmp != res) {
+		while (tmp->sibling != res)
+			tmp = tmp->sibling;
+		if (start <= tmp->end)
+			goto out;
+	}
+
+	res->start = start;
+	res->end = end;
+	result = 0;
+
+ out:
+	write_unlock(&resource_lock);
+	return result;
+}
+
+EXPORT_SYMBOL(adjust_resource);
 
 /*
  * This is compatibility stuff for IO resources.

-- 
"Next the statesmen will invent cheap lies, putting the blame upon 
the nation that is attacked, and every man will be glad of those
conscience-soothing falsities, and will diligently study them, and refuse
to examine any refutations of them; and thus he will by and by convince 
himself that the war is just, and will thank God for the better sleep 
he enjoys after this process of grotesque self-deception." -- Mark Twain

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-12-18 14:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-18 14:14 [PATCH] adjust_resource() Matthew Wilcox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®