10 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
12 #include <linux/export.h>
13 #include <linux/errno.h>
16 #include <linux/slab.h>
20 #include <linux/sched.h>
22 #include <linux/device.h>
66 enum { MAX_IORES_LEVEL = 5 };
68 static void *r_start(
struct seq_file *m, loff_t *pos)
74 for (p = p->
child; p && l < *pos; p = r_next(m, p, &l))
79 static void r_stop(
struct seq_file *m,
void *v)
85 static int r_show(
struct seq_file *m,
void *v)
89 int width = root->
end < 0x10000 ? 4 : 8;
92 for (depth = 0, p = r; depth < MAX_IORES_LEVEL; depth++, p = p->
parent)
93 if (p->parent == root)
97 width, (
unsigned long long) r->
start,
98 width, (
unsigned long long) r->
end,
120 static int iomem_open(
struct inode *inode,
struct file *file)
122 int res =
seq_open(file, &resource_op);
131 .
open = ioports_open,
144 static int __init ioresources_init(
void)
146 proc_create(
"ioports", 0,
NULL, &proc_ioports_operations);
147 proc_create(
"iomem", 0,
NULL, &proc_iomem_operations);
163 if (start < root->start)
170 if (!tmp || tmp->
start > end) {
177 if (tmp->
end < start)
183 static int __release_resource(
struct resource *old)
202 static void __release_child_resources(
struct resource *r)
215 __release_child_resources(tmp);
219 size = resource_size(tmp);
228 __release_child_resources(r);
244 conflict = __request_resource(root,
new);
261 return conflict ? -
EBUSY : 0;
275 retval = __release_resource(old);
282 #if !defined(CONFIG_ARCH_HAS_WALK_MEMORY)
288 static int find_next_system_ram(
struct resource *res,
char *
name)
306 if (p->
start > end) {
310 if ((p->
end >= start) && (p->
start < end))
330 void *
arg,
int (*
func)(
unsigned long,
unsigned long,
void *))
333 unsigned long pfn, end_pfn;
342 (find_next_system_ram(&res,
"System RAM") >= 0)) {
346 ret = (*func)(pfn, end_pfn - pfn,
arg);
357 static int __is_ram(
unsigned long pfn,
unsigned long nr_pages,
void *arg)
385 if (res->
start < min)
408 tmp.
flags =
new->flags;
414 if (
this && this->start == root->
start) {
415 tmp.
start = (
this == old) ? old->
start : this->end + 1;
416 this = this->sibling;
420 tmp.
end = (
this == old) ? this->end : this->start - 1;
427 resource_clip(&tmp, constraint->
min, constraint->
max);
436 size, constraint->
align);
437 alloc.end = alloc.start + size - 1;
438 if (resource_contains(&
avail, &alloc)) {
439 new->start = alloc.start;
440 new->end = alloc.end;
445 next:
if (!
this || this->end == root->
end)
449 tmp.
start = this->end + 1;
462 return __find_resource(root,
NULL,
new, size, constraint);
485 if ((err = __find_resource(root, old, &
new, newsize, constraint)))
488 if (resource_contains(&
new, old)) {
489 old->
start =
new.start;
499 if (resource_contains(old, &
new)) {
500 old->
start =
new.start;
503 __release_resource(old);
505 conflict = __request_resource(root, old);
539 alignf = simple_align_resource;
554 err = find_resource(root,
new, size, &constraint);
555 if (err >= 0 && __request_resource(root,
new))
576 if (res->
start == start)
592 for (;; parent =
first) {
593 first = __request_resource(parent,
new);
602 if ((first->
start > new->start) || (first->
end < new->end))
604 if ((first->
start == new->start) && (first->
end == new->end))
608 for (next = first; ; next = next->
sibling) {
610 if (next->
start < new->start || next->
end > new->end)
614 if (next->
sibling->start > new->end)
629 next = parent->
child;
655 conflict = __insert_resource(parent,
new);
672 return conflict ? -
EBUSY : 0;
692 conflict = __insert_resource(root,
new);
695 if (conflict == root)
699 if (conflict->
start < new->start)
700 new->start = conflict->
start;
701 if (conflict->
end > new->end)
702 new->end = conflict->
end;
704 printk(
"Expanded resource %s due to conflict with %s\n", new->name, conflict->
name);
730 if ((start < parent->start) || (end > parent->
end))
740 if (start <= tmp->end)
746 if ((tmp->
start < start) || (tmp->
end > end))
759 static void __init __reserve_region_with_split(
struct resource *root,
778 conflict = __request_resource(parent, res);
789 conflict->
end >= res->
end) {
799 if (conflict->
end < end) {
800 next_res = kzalloc(
sizeof(*next_res),
807 next_res->
start = conflict->
end + 1;
825 if (root->
start > start || root->
end < end) {
826 pr_err(
"requested range [0x%llx-0x%llx] not in root %pr\n",
827 (
unsigned long long)start, (
unsigned long long)end,
829 if (start > root->
end || end < root->start)
834 if (start < root->start)
836 pr_err(
"fixing request to [0x%llx-0x%llx]\n",
837 (
unsigned long long)start,
838 (
unsigned long long)end);
843 __reserve_region_with_split(root, start, end, name);
857 return resource_size(res);
890 const char *name,
int flags)
900 res->
end = start + n - 1;
909 conflict = __request_resource(parent, res);
912 if (conflict != parent) {
990 if (res->
start <= start && res->
end >= end) {
995 if (res->
start != start || res->
end != end)
1000 wake_up(&muxed_resource_wait);
1010 "<%016llx-%016llx>\n", (
unsigned long long)start,
1011 (
unsigned long long)end);
1024 static void devm_region_release(
struct device *
dev,
void *res)
1031 static int devm_region_match(
struct device *
dev,
void *res,
void *match_data)
1035 return this->parent == match->
parent &&
1036 this->start == match->start && this->
n == match->n;
1079 #define MAXRESERVE 4
1080 static int __init reserve_setup(
char *
str)
1083 static struct resource reserve[MAXRESERVE];
1086 unsigned int io_start, io_num;
1093 if (x < MAXRESERVE) {
1095 res->
name =
"reserved";
1096 res->
start = io_start;
1097 res->
end = io_start + io_num - 1;
1107 __setup(
"reserve=", reserve_setup);
1120 for (p = p->
child; p ; p = r_next(
NULL, p, &l)) {
1125 if (p->
start >= addr + size)
1142 "0x%llx 0x%llx 0x%llx 0x%llx %s\n",
1143 (
unsigned long long)addr,
1144 (
unsigned long long)(addr + size - 1),
1145 (
unsigned long long)p->
start,
1146 (
unsigned long long)p->
end,
1156 #ifdef CONFIG_STRICT_DEVMEM
1157 static int strict_iomem_checks = 1;
1159 static int strict_iomem_checks;
1173 if (!strict_iomem_checks)
1179 for (p = p->
child; p ; p = r_next(
NULL, p, &l)) {
1184 if (p->
start >= addr + size)
1199 static int __init strict_iomem(
char *
str)
1201 if (
strstr(str,
"relaxed"))
1202 strict_iomem_checks = 0;
1203 if (
strstr(str,
"strict"))
1204 strict_iomem_checks = 1;
1208 __setup(
"iomem=", strict_iomem);