]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - kernel/resource.c
tick/sched: Annotate lockless access to last_jiffies_update
[mirror_ubuntu-bionic-kernel.git] / kernel / resource.c
1 /*
2 * linux/kernel/resource.c
3 *
4 * Copyright (C) 1999 Linus Torvalds
5 * Copyright (C) 1999 Martin Mares <mj@ucw.cz>
6 *
7 * Arbitrary resource management.
8 */
9
10 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
11
12 #include <linux/export.h>
13 #include <linux/errno.h>
14 #include <linux/ioport.h>
15 #include <linux/init.h>
16 #include <linux/slab.h>
17 #include <linux/spinlock.h>
18 #include <linux/fs.h>
19 #include <linux/proc_fs.h>
20 #include <linux/sched.h>
21 #include <linux/seq_file.h>
22 #include <linux/device.h>
23 #include <linux/pfn.h>
24 #include <linux/mm.h>
25 #include <linux/resource_ext.h>
26 #include <asm/io.h>
27
28
29 struct resource ioport_resource = {
30 .name = "PCI IO",
31 .start = 0,
32 .end = IO_SPACE_LIMIT,
33 .flags = IORESOURCE_IO,
34 };
35 EXPORT_SYMBOL(ioport_resource);
36
37 struct resource iomem_resource = {
38 .name = "PCI mem",
39 .start = 0,
40 .end = -1,
41 .flags = IORESOURCE_MEM,
42 };
43 EXPORT_SYMBOL(iomem_resource);
44
45 /* constraints to be met while allocating resources */
46 struct resource_constraint {
47 resource_size_t min, max, align;
48 resource_size_t (*alignf)(void *, const struct resource *,
49 resource_size_t, resource_size_t);
50 void *alignf_data;
51 };
52
53 static DEFINE_RWLOCK(resource_lock);
54
55 /*
56 * For memory hotplug, there is no way to free resource entries allocated
57 * by boot mem after the system is up. So for reusing the resource entry
58 * we need to remember the resource.
59 */
60 static struct resource *bootmem_resource_free;
61 static DEFINE_SPINLOCK(bootmem_resource_lock);
62
63 static struct resource *next_resource(struct resource *p, bool sibling_only)
64 {
65 /* Caller wants to traverse through siblings only */
66 if (sibling_only)
67 return p->sibling;
68
69 if (p->child)
70 return p->child;
71 while (!p->sibling && p->parent)
72 p = p->parent;
73 return p->sibling;
74 }
75
76 static void *r_next(struct seq_file *m, void *v, loff_t *pos)
77 {
78 struct resource *p = v;
79 (*pos)++;
80 return (void *)next_resource(p, false);
81 }
82
83 #ifdef CONFIG_PROC_FS
84
85 enum { MAX_IORES_LEVEL = 5 };
86
87 static void *r_start(struct seq_file *m, loff_t *pos)
88 __acquires(resource_lock)
89 {
90 struct resource *p = m->private;
91 loff_t l = 0;
92 read_lock(&resource_lock);
93 for (p = p->child; p && l < *pos; p = r_next(m, p, &l))
94 ;
95 return p;
96 }
97
98 static void r_stop(struct seq_file *m, void *v)
99 __releases(resource_lock)
100 {
101 read_unlock(&resource_lock);
102 }
103
104 static int r_show(struct seq_file *m, void *v)
105 {
106 struct resource *root = m->private;
107 struct resource *r = v, *p;
108 unsigned long long start, end;
109 int width = root->end < 0x10000 ? 4 : 8;
110 int depth;
111
112 for (depth = 0, p = r; depth < MAX_IORES_LEVEL; depth++, p = p->parent)
113 if (p->parent == root)
114 break;
115
116 if (file_ns_capable(m->file, &init_user_ns, CAP_SYS_ADMIN)) {
117 start = r->start;
118 end = r->end;
119 } else {
120 start = end = 0;
121 }
122
123 seq_printf(m, "%*s%0*llx-%0*llx : %s\n",
124 depth * 2, "",
125 width, start,
126 width, end,
127 r->name ? r->name : "<BAD>");
128 return 0;
129 }
130
131 static const struct seq_operations resource_op = {
132 .start = r_start,
133 .next = r_next,
134 .stop = r_stop,
135 .show = r_show,
136 };
137
138 static int ioports_open(struct inode *inode, struct file *file)
139 {
140 int res = seq_open(file, &resource_op);
141 if (!res) {
142 struct seq_file *m = file->private_data;
143 m->private = &ioport_resource;
144 }
145 return res;
146 }
147
148 static int iomem_open(struct inode *inode, struct file *file)
149 {
150 int res = seq_open(file, &resource_op);
151 if (!res) {
152 struct seq_file *m = file->private_data;
153 m->private = &iomem_resource;
154 }
155 return res;
156 }
157
158 static const struct file_operations proc_ioports_operations = {
159 .open = ioports_open,
160 .read = seq_read,
161 .llseek = seq_lseek,
162 .release = seq_release,
163 };
164
165 static const struct file_operations proc_iomem_operations = {
166 .open = iomem_open,
167 .read = seq_read,
168 .llseek = seq_lseek,
169 .release = seq_release,
170 };
171
172 static int __init ioresources_init(void)
173 {
174 proc_create("ioports", 0, NULL, &proc_ioports_operations);
175 proc_create("iomem", 0, NULL, &proc_iomem_operations);
176 return 0;
177 }
178 __initcall(ioresources_init);
179
180 #endif /* CONFIG_PROC_FS */
181
182 static void free_resource(struct resource *res)
183 {
184 if (!res)
185 return;
186
187 if (!PageSlab(virt_to_head_page(res))) {
188 spin_lock(&bootmem_resource_lock);
189 res->sibling = bootmem_resource_free;
190 bootmem_resource_free = res;
191 spin_unlock(&bootmem_resource_lock);
192 } else {
193 kfree(res);
194 }
195 }
196
197 static struct resource *alloc_resource(gfp_t flags)
198 {
199 struct resource *res = NULL;
200
201 spin_lock(&bootmem_resource_lock);
202 if (bootmem_resource_free) {
203 res = bootmem_resource_free;
204 bootmem_resource_free = res->sibling;
205 }
206 spin_unlock(&bootmem_resource_lock);
207
208 if (res)
209 memset(res, 0, sizeof(struct resource));
210 else
211 res = kzalloc(sizeof(struct resource), flags);
212
213 return res;
214 }
215
216 /* Return the conflict entry if you can't request it */
217 static struct resource * __request_resource(struct resource *root, struct resource *new)
218 {
219 resource_size_t start = new->start;
220 resource_size_t end = new->end;
221 struct resource *tmp, **p;
222
223 if (end < start)
224 return root;
225 if (start < root->start)
226 return root;
227 if (end > root->end)
228 return root;
229 p = &root->child;
230 for (;;) {
231 tmp = *p;
232 if (!tmp || tmp->start > end) {
233 new->sibling = tmp;
234 *p = new;
235 new->parent = root;
236 return NULL;
237 }
238 p = &tmp->sibling;
239 if (tmp->end < start)
240 continue;
241 return tmp;
242 }
243 }
244
245 static int __release_resource(struct resource *old, bool release_child)
246 {
247 struct resource *tmp, **p, *chd;
248
249 p = &old->parent->child;
250 for (;;) {
251 tmp = *p;
252 if (!tmp)
253 break;
254 if (tmp == old) {
255 if (release_child || !(tmp->child)) {
256 *p = tmp->sibling;
257 } else {
258 for (chd = tmp->child;; chd = chd->sibling) {
259 chd->parent = tmp->parent;
260 if (!(chd->sibling))
261 break;
262 }
263 *p = tmp->child;
264 chd->sibling = tmp->sibling;
265 }
266 old->parent = NULL;
267 return 0;
268 }
269 p = &tmp->sibling;
270 }
271 return -EINVAL;
272 }
273
274 static void __release_child_resources(struct resource *r)
275 {
276 struct resource *tmp, *p;
277 resource_size_t size;
278
279 p = r->child;
280 r->child = NULL;
281 while (p) {
282 tmp = p;
283 p = p->sibling;
284
285 tmp->parent = NULL;
286 tmp->sibling = NULL;
287 __release_child_resources(tmp);
288
289 printk(KERN_DEBUG "release child resource %pR\n", tmp);
290 /* need to restore size, and keep flags */
291 size = resource_size(tmp);
292 tmp->start = 0;
293 tmp->end = size - 1;
294 }
295 }
296
297 void release_child_resources(struct resource *r)
298 {
299 write_lock(&resource_lock);
300 __release_child_resources(r);
301 write_unlock(&resource_lock);
302 }
303
304 /**
305 * request_resource_conflict - request and reserve an I/O or memory resource
306 * @root: root resource descriptor
307 * @new: resource descriptor desired by caller
308 *
309 * Returns 0 for success, conflict resource on error.
310 */
311 struct resource *request_resource_conflict(struct resource *root, struct resource *new)
312 {
313 struct resource *conflict;
314
315 write_lock(&resource_lock);
316 conflict = __request_resource(root, new);
317 write_unlock(&resource_lock);
318 return conflict;
319 }
320
321 /**
322 * request_resource - request and reserve an I/O or memory resource
323 * @root: root resource descriptor
324 * @new: resource descriptor desired by caller
325 *
326 * Returns 0 for success, negative error code on error.
327 */
328 int request_resource(struct resource *root, struct resource *new)
329 {
330 struct resource *conflict;
331
332 conflict = request_resource_conflict(root, new);
333 return conflict ? -EBUSY : 0;
334 }
335
336 EXPORT_SYMBOL(request_resource);
337
338 /**
339 * release_resource - release a previously reserved resource
340 * @old: resource pointer
341 */
342 int release_resource(struct resource *old)
343 {
344 int retval;
345
346 write_lock(&resource_lock);
347 retval = __release_resource(old, true);
348 write_unlock(&resource_lock);
349 return retval;
350 }
351
352 EXPORT_SYMBOL(release_resource);
353
354 /**
355 * Finds the lowest iomem resource that covers part of [start..end]. The
356 * caller must specify start, end, flags, and desc (which may be
357 * IORES_DESC_NONE).
358 *
359 * If a resource is found, returns 0 and *res is overwritten with the part
360 * of the resource that's within [start..end]; if none is found, returns
361 * -ENODEV. Returns -EINVAL for invalid parameters.
362 *
363 * This function walks the whole tree and not just first level children
364 * unless @first_level_children_only is true.
365 */
366 static int find_next_iomem_res(resource_size_t start, resource_size_t end,
367 unsigned long flags, unsigned long desc,
368 bool first_level_children_only,
369 struct resource *res)
370 {
371 struct resource *p;
372 bool sibling_only = false;
373
374 BUG_ON(!res);
375 BUG_ON(start >= end);
376
377 if (first_level_children_only)
378 sibling_only = true;
379
380 read_lock(&resource_lock);
381
382 for (p = iomem_resource.child; p; p = next_resource(p, sibling_only)) {
383 if ((p->flags & flags) != flags)
384 continue;
385 if ((desc != IORES_DESC_NONE) && (desc != p->desc))
386 continue;
387 if (p->start > end) {
388 p = NULL;
389 break;
390 }
391 if ((p->end >= start) && (p->start <= end))
392 break;
393 }
394
395 if (p) {
396 /* copy data */
397 res->start = max(start, p->start);
398 res->end = min(end, p->end);
399 res->flags = p->flags;
400 res->desc = p->desc;
401 }
402
403 read_unlock(&resource_lock);
404 return p ? 0 : -ENODEV;
405 }
406
407 static int __walk_iomem_res_desc(resource_size_t start, resource_size_t end,
408 unsigned long flags, unsigned long desc,
409 bool first_level_children_only, void *arg,
410 int (*func)(struct resource *, void *))
411 {
412 struct resource res;
413 int ret = -1;
414
415 while (start < end &&
416 !find_next_iomem_res(start, end, flags, desc,
417 first_level_children_only, &res)) {
418 ret = (*func)(&res, arg);
419 if (ret)
420 break;
421
422 start = res.end + 1;
423 }
424
425 return ret;
426 }
427
428 /*
429 * Walks through iomem resources and calls func() with matching resource
430 * ranges. This walks through whole tree and not just first level children.
431 * All the memory ranges which overlap start,end and also match flags and
432 * desc are valid candidates.
433 *
434 * @desc: I/O resource descriptor. Use IORES_DESC_NONE to skip @desc check.
435 * @flags: I/O resource flags
436 * @start: start addr
437 * @end: end addr
438 *
439 * NOTE: For a new descriptor search, define a new IORES_DESC in
440 * <linux/ioport.h> and set it in 'desc' of a target resource entry.
441 */
442 int walk_iomem_res_desc(unsigned long desc, unsigned long flags, u64 start,
443 u64 end, void *arg, int (*func)(struct resource *, void *))
444 {
445 return __walk_iomem_res_desc(start, end, flags, desc, false, arg, func);
446 }
447
448 /*
449 * This function calls the @func callback against all memory ranges of type
450 * System RAM which are marked as IORESOURCE_SYSTEM_RAM and IORESOUCE_BUSY.
451 * Now, this function is only for System RAM, it deals with full ranges and
452 * not PFNs. If resources are not PFN-aligned, dealing with PFNs can truncate
453 * ranges.
454 */
455 int walk_system_ram_res(u64 start, u64 end, void *arg,
456 int (*func)(struct resource *, void *))
457 {
458 unsigned long flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
459
460 return __walk_iomem_res_desc(start, end, flags, IORES_DESC_NONE, true,
461 arg, func);
462 }
463
464 /*
465 * This function calls the @func callback against all memory ranges, which
466 * are ranges marked as IORESOURCE_MEM and IORESOUCE_BUSY.
467 */
468 int walk_mem_res(u64 start, u64 end, void *arg,
469 int (*func)(struct resource *, void *))
470 {
471 unsigned long flags = IORESOURCE_MEM | IORESOURCE_BUSY;
472
473 return __walk_iomem_res_desc(start, end, flags, IORES_DESC_NONE, true,
474 arg, func);
475 }
476
477 #if !defined(CONFIG_ARCH_HAS_WALK_MEMORY)
478
479 /*
480 * This function calls the @func callback against all memory ranges of type
481 * System RAM which are marked as IORESOURCE_SYSTEM_RAM and IORESOUCE_BUSY.
482 * It is to be used only for System RAM.
483 */
484 int walk_system_ram_range(unsigned long start_pfn, unsigned long nr_pages,
485 void *arg, int (*func)(unsigned long, unsigned long, void *))
486 {
487 resource_size_t start, end;
488 unsigned long flags;
489 struct resource res;
490 unsigned long pfn, end_pfn;
491 int ret = -1;
492
493 start = (u64) start_pfn << PAGE_SHIFT;
494 end = ((u64)(start_pfn + nr_pages) << PAGE_SHIFT) - 1;
495 flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
496 while (start < end &&
497 !find_next_iomem_res(start, end, flags, IORES_DESC_NONE,
498 true, &res)) {
499 pfn = (res.start + PAGE_SIZE - 1) >> PAGE_SHIFT;
500 end_pfn = (res.end + 1) >> PAGE_SHIFT;
501 if (end_pfn > pfn)
502 ret = (*func)(pfn, end_pfn - pfn, arg);
503 if (ret)
504 break;
505 start = res.end + 1;
506 }
507 return ret;
508 }
509
510 #endif
511
512 static int __is_ram(unsigned long pfn, unsigned long nr_pages, void *arg)
513 {
514 return 1;
515 }
516
517 /*
518 * This generic page_is_ram() returns true if specified address is
519 * registered as System RAM in iomem_resource list.
520 */
521 int __weak page_is_ram(unsigned long pfn)
522 {
523 return walk_system_ram_range(pfn, 1, NULL, __is_ram) == 1;
524 }
525 EXPORT_SYMBOL_GPL(page_is_ram);
526
527 /**
528 * region_intersects() - determine intersection of region with known resources
529 * @start: region start address
530 * @size: size of region
531 * @flags: flags of resource (in iomem_resource)
532 * @desc: descriptor of resource (in iomem_resource) or IORES_DESC_NONE
533 *
534 * Check if the specified region partially overlaps or fully eclipses a
535 * resource identified by @flags and @desc (optional with IORES_DESC_NONE).
536 * Return REGION_DISJOINT if the region does not overlap @flags/@desc,
537 * return REGION_MIXED if the region overlaps @flags/@desc and another
538 * resource, and return REGION_INTERSECTS if the region overlaps @flags/@desc
539 * and no other defined resource. Note that REGION_INTERSECTS is also
540 * returned in the case when the specified region overlaps RAM and undefined
541 * memory holes.
542 *
543 * region_intersect() is used by memory remapping functions to ensure
544 * the user is not remapping RAM and is a vast speed up over walking
545 * through the resource table page by page.
546 */
547 int region_intersects(resource_size_t start, size_t size, unsigned long flags,
548 unsigned long desc)
549 {
550 resource_size_t end = start + size - 1;
551 int type = 0; int other = 0;
552 struct resource *p;
553
554 read_lock(&resource_lock);
555 for (p = iomem_resource.child; p ; p = p->sibling) {
556 bool is_type = (((p->flags & flags) == flags) &&
557 ((desc == IORES_DESC_NONE) ||
558 (desc == p->desc)));
559
560 if (start >= p->start && start <= p->end)
561 is_type ? type++ : other++;
562 if (end >= p->start && end <= p->end)
563 is_type ? type++ : other++;
564 if (p->start >= start && p->end <= end)
565 is_type ? type++ : other++;
566 }
567 read_unlock(&resource_lock);
568
569 if (other == 0)
570 return type ? REGION_INTERSECTS : REGION_DISJOINT;
571
572 if (type)
573 return REGION_MIXED;
574
575 return REGION_DISJOINT;
576 }
577 EXPORT_SYMBOL_GPL(region_intersects);
578
579 void __weak arch_remove_reservations(struct resource *avail)
580 {
581 }
582
583 static resource_size_t simple_align_resource(void *data,
584 const struct resource *avail,
585 resource_size_t size,
586 resource_size_t align)
587 {
588 return avail->start;
589 }
590
591 static void resource_clip(struct resource *res, resource_size_t min,
592 resource_size_t max)
593 {
594 if (res->start < min)
595 res->start = min;
596 if (res->end > max)
597 res->end = max;
598 }
599
600 /*
601 * Find empty slot in the resource tree with the given range and
602 * alignment constraints
603 */
604 static int __find_resource(struct resource *root, struct resource *old,
605 struct resource *new,
606 resource_size_t size,
607 struct resource_constraint *constraint)
608 {
609 struct resource *this = root->child;
610 struct resource tmp = *new, avail, alloc;
611
612 tmp.start = root->start;
613 /*
614 * Skip past an allocated resource that starts at 0, since the assignment
615 * of this->start - 1 to tmp->end below would cause an underflow.
616 */
617 if (this && this->start == root->start) {
618 tmp.start = (this == old) ? old->start : this->end + 1;
619 this = this->sibling;
620 }
621 for(;;) {
622 if (this)
623 tmp.end = (this == old) ? this->end : this->start - 1;
624 else
625 tmp.end = root->end;
626
627 if (tmp.end < tmp.start)
628 goto next;
629
630 resource_clip(&tmp, constraint->min, constraint->max);
631 arch_remove_reservations(&tmp);
632
633 /* Check for overflow after ALIGN() */
634 avail.start = ALIGN(tmp.start, constraint->align);
635 avail.end = tmp.end;
636 avail.flags = new->flags & ~IORESOURCE_UNSET;
637 if (avail.start >= tmp.start) {
638 alloc.flags = avail.flags;
639 alloc.start = constraint->alignf(constraint->alignf_data, &avail,
640 size, constraint->align);
641 alloc.end = alloc.start + size - 1;
642 if (alloc.start <= alloc.end &&
643 resource_contains(&avail, &alloc)) {
644 new->start = alloc.start;
645 new->end = alloc.end;
646 return 0;
647 }
648 }
649
650 next: if (!this || this->end == root->end)
651 break;
652
653 if (this != old)
654 tmp.start = this->end + 1;
655 this = this->sibling;
656 }
657 return -EBUSY;
658 }
659
660 /*
661 * Find empty slot in the resource tree given range and alignment.
662 */
663 static int find_resource(struct resource *root, struct resource *new,
664 resource_size_t size,
665 struct resource_constraint *constraint)
666 {
667 return __find_resource(root, NULL, new, size, constraint);
668 }
669
670 /**
671 * reallocate_resource - allocate a slot in the resource tree given range & alignment.
672 * The resource will be relocated if the new size cannot be reallocated in the
673 * current location.
674 *
675 * @root: root resource descriptor
676 * @old: resource descriptor desired by caller
677 * @newsize: new size of the resource descriptor
678 * @constraint: the size and alignment constraints to be met.
679 */
680 static int reallocate_resource(struct resource *root, struct resource *old,
681 resource_size_t newsize,
682 struct resource_constraint *constraint)
683 {
684 int err=0;
685 struct resource new = *old;
686 struct resource *conflict;
687
688 write_lock(&resource_lock);
689
690 if ((err = __find_resource(root, old, &new, newsize, constraint)))
691 goto out;
692
693 if (resource_contains(&new, old)) {
694 old->start = new.start;
695 old->end = new.end;
696 goto out;
697 }
698
699 if (old->child) {
700 err = -EBUSY;
701 goto out;
702 }
703
704 if (resource_contains(old, &new)) {
705 old->start = new.start;
706 old->end = new.end;
707 } else {
708 __release_resource(old, true);
709 *old = new;
710 conflict = __request_resource(root, old);
711 BUG_ON(conflict);
712 }
713 out:
714 write_unlock(&resource_lock);
715 return err;
716 }
717
718
719 /**
720 * allocate_resource - allocate empty slot in the resource tree given range & alignment.
721 * The resource will be reallocated with a new size if it was already allocated
722 * @root: root resource descriptor
723 * @new: resource descriptor desired by caller
724 * @size: requested resource region size
725 * @min: minimum boundary to allocate
726 * @max: maximum boundary to allocate
727 * @align: alignment requested, in bytes
728 * @alignf: alignment function, optional, called if not NULL
729 * @alignf_data: arbitrary data to pass to the @alignf function
730 */
731 int allocate_resource(struct resource *root, struct resource *new,
732 resource_size_t size, resource_size_t min,
733 resource_size_t max, resource_size_t align,
734 resource_size_t (*alignf)(void *,
735 const struct resource *,
736 resource_size_t,
737 resource_size_t),
738 void *alignf_data)
739 {
740 int err;
741 struct resource_constraint constraint;
742
743 if (!alignf)
744 alignf = simple_align_resource;
745
746 constraint.min = min;
747 constraint.max = max;
748 constraint.align = align;
749 constraint.alignf = alignf;
750 constraint.alignf_data = alignf_data;
751
752 if ( new->parent ) {
753 /* resource is already allocated, try reallocating with
754 the new constraints */
755 return reallocate_resource(root, new, size, &constraint);
756 }
757
758 write_lock(&resource_lock);
759 err = find_resource(root, new, size, &constraint);
760 if (err >= 0 && __request_resource(root, new))
761 err = -EBUSY;
762 write_unlock(&resource_lock);
763 return err;
764 }
765
766 EXPORT_SYMBOL(allocate_resource);
767
768 /**
769 * lookup_resource - find an existing resource by a resource start address
770 * @root: root resource descriptor
771 * @start: resource start address
772 *
773 * Returns a pointer to the resource if found, NULL otherwise
774 */
775 struct resource *lookup_resource(struct resource *root, resource_size_t start)
776 {
777 struct resource *res;
778
779 read_lock(&resource_lock);
780 for (res = root->child; res; res = res->sibling) {
781 if (res->start == start)
782 break;
783 }
784 read_unlock(&resource_lock);
785
786 return res;
787 }
788
789 /*
790 * Insert a resource into the resource tree. If successful, return NULL,
791 * otherwise return the conflicting resource (compare to __request_resource())
792 */
793 static struct resource * __insert_resource(struct resource *parent, struct resource *new)
794 {
795 struct resource *first, *next;
796
797 for (;; parent = first) {
798 first = __request_resource(parent, new);
799 if (!first)
800 return first;
801
802 if (first == parent)
803 return first;
804 if (WARN_ON(first == new)) /* duplicated insertion */
805 return first;
806
807 if ((first->start > new->start) || (first->end < new->end))
808 break;
809 if ((first->start == new->start) && (first->end == new->end))
810 break;
811 }
812
813 for (next = first; ; next = next->sibling) {
814 /* Partial overlap? Bad, and unfixable */
815 if (next->start < new->start || next->end > new->end)
816 return next;
817 if (!next->sibling)
818 break;
819 if (next->sibling->start > new->end)
820 break;
821 }
822
823 new->parent = parent;
824 new->sibling = next->sibling;
825 new->child = first;
826
827 next->sibling = NULL;
828 for (next = first; next; next = next->sibling)
829 next->parent = new;
830
831 if (parent->child == first) {
832 parent->child = new;
833 } else {
834 next = parent->child;
835 while (next->sibling != first)
836 next = next->sibling;
837 next->sibling = new;
838 }
839 return NULL;
840 }
841
842 /**
843 * insert_resource_conflict - Inserts resource in the resource tree
844 * @parent: parent of the new resource
845 * @new: new resource to insert
846 *
847 * Returns 0 on success, conflict resource if the resource can't be inserted.
848 *
849 * This function is equivalent to request_resource_conflict when no conflict
850 * happens. If a conflict happens, and the conflicting resources
851 * entirely fit within the range of the new resource, then the new
852 * resource is inserted and the conflicting resources become children of
853 * the new resource.
854 *
855 * This function is intended for producers of resources, such as FW modules
856 * and bus drivers.
857 */
858 struct resource *insert_resource_conflict(struct resource *parent, struct resource *new)
859 {
860 struct resource *conflict;
861
862 write_lock(&resource_lock);
863 conflict = __insert_resource(parent, new);
864 write_unlock(&resource_lock);
865 return conflict;
866 }
867
868 /**
869 * insert_resource - Inserts a resource in the resource tree
870 * @parent: parent of the new resource
871 * @new: new resource to insert
872 *
873 * Returns 0 on success, -EBUSY if the resource can't be inserted.
874 *
875 * This function is intended for producers of resources, such as FW modules
876 * and bus drivers.
877 */
878 int insert_resource(struct resource *parent, struct resource *new)
879 {
880 struct resource *conflict;
881
882 conflict = insert_resource_conflict(parent, new);
883 return conflict ? -EBUSY : 0;
884 }
885 EXPORT_SYMBOL_GPL(insert_resource);
886
887 /**
888 * insert_resource_expand_to_fit - Insert a resource into the resource tree
889 * @root: root resource descriptor
890 * @new: new resource to insert
891 *
892 * Insert a resource into the resource tree, possibly expanding it in order
893 * to make it encompass any conflicting resources.
894 */
895 void insert_resource_expand_to_fit(struct resource *root, struct resource *new)
896 {
897 if (new->parent)
898 return;
899
900 write_lock(&resource_lock);
901 for (;;) {
902 struct resource *conflict;
903
904 conflict = __insert_resource(root, new);
905 if (!conflict)
906 break;
907 if (conflict == root)
908 break;
909
910 /* Ok, expand resource to cover the conflict, then try again .. */
911 if (conflict->start < new->start)
912 new->start = conflict->start;
913 if (conflict->end > new->end)
914 new->end = conflict->end;
915
916 printk("Expanded resource %s due to conflict with %s\n", new->name, conflict->name);
917 }
918 write_unlock(&resource_lock);
919 }
920
921 /**
922 * remove_resource - Remove a resource in the resource tree
923 * @old: resource to remove
924 *
925 * Returns 0 on success, -EINVAL if the resource is not valid.
926 *
927 * This function removes a resource previously inserted by insert_resource()
928 * or insert_resource_conflict(), and moves the children (if any) up to
929 * where they were before. insert_resource() and insert_resource_conflict()
930 * insert a new resource, and move any conflicting resources down to the
931 * children of the new resource.
932 *
933 * insert_resource(), insert_resource_conflict() and remove_resource() are
934 * intended for producers of resources, such as FW modules and bus drivers.
935 */
936 int remove_resource(struct resource *old)
937 {
938 int retval;
939
940 write_lock(&resource_lock);
941 retval = __release_resource(old, false);
942 write_unlock(&resource_lock);
943 return retval;
944 }
945 EXPORT_SYMBOL_GPL(remove_resource);
946
947 static int __adjust_resource(struct resource *res, resource_size_t start,
948 resource_size_t size)
949 {
950 struct resource *tmp, *parent = res->parent;
951 resource_size_t end = start + size - 1;
952 int result = -EBUSY;
953
954 if (!parent)
955 goto skip;
956
957 if ((start < parent->start) || (end > parent->end))
958 goto out;
959
960 if (res->sibling && (res->sibling->start <= end))
961 goto out;
962
963 tmp = parent->child;
964 if (tmp != res) {
965 while (tmp->sibling != res)
966 tmp = tmp->sibling;
967 if (start <= tmp->end)
968 goto out;
969 }
970
971 skip:
972 for (tmp = res->child; tmp; tmp = tmp->sibling)
973 if ((tmp->start < start) || (tmp->end > end))
974 goto out;
975
976 res->start = start;
977 res->end = end;
978 result = 0;
979
980 out:
981 return result;
982 }
983
984 /**
985 * adjust_resource - modify a resource's start and size
986 * @res: resource to modify
987 * @start: new start value
988 * @size: new size
989 *
990 * Given an existing resource, change its start and size to match the
991 * arguments. Returns 0 on success, -EBUSY if it can't fit.
992 * Existing children of the resource are assumed to be immutable.
993 */
994 int adjust_resource(struct resource *res, resource_size_t start,
995 resource_size_t size)
996 {
997 int result;
998
999 write_lock(&resource_lock);
1000 result = __adjust_resource(res, start, size);
1001 write_unlock(&resource_lock);
1002 return result;
1003 }
1004 EXPORT_SYMBOL(adjust_resource);
1005
1006 static void __init __reserve_region_with_split(struct resource *root,
1007 resource_size_t start, resource_size_t end,
1008 const char *name)
1009 {
1010 struct resource *parent = root;
1011 struct resource *conflict;
1012 struct resource *res = alloc_resource(GFP_ATOMIC);
1013 struct resource *next_res = NULL;
1014
1015 if (!res)
1016 return;
1017
1018 res->name = name;
1019 res->start = start;
1020 res->end = end;
1021 res->flags = IORESOURCE_BUSY;
1022 res->desc = IORES_DESC_NONE;
1023
1024 while (1) {
1025
1026 conflict = __request_resource(parent, res);
1027 if (!conflict) {
1028 if (!next_res)
1029 break;
1030 res = next_res;
1031 next_res = NULL;
1032 continue;
1033 }
1034
1035 /* conflict covered whole area */
1036 if (conflict->start <= res->start &&
1037 conflict->end >= res->end) {
1038 free_resource(res);
1039 WARN_ON(next_res);
1040 break;
1041 }
1042
1043 /* failed, split and try again */
1044 if (conflict->start > res->start) {
1045 end = res->end;
1046 res->end = conflict->start - 1;
1047 if (conflict->end < end) {
1048 next_res = alloc_resource(GFP_ATOMIC);
1049 if (!next_res) {
1050 free_resource(res);
1051 break;
1052 }
1053 next_res->name = name;
1054 next_res->start = conflict->end + 1;
1055 next_res->end = end;
1056 next_res->flags = IORESOURCE_BUSY;
1057 next_res->desc = IORES_DESC_NONE;
1058 }
1059 } else {
1060 res->start = conflict->end + 1;
1061 }
1062 }
1063
1064 }
1065
1066 void __init reserve_region_with_split(struct resource *root,
1067 resource_size_t start, resource_size_t end,
1068 const char *name)
1069 {
1070 int abort = 0;
1071
1072 write_lock(&resource_lock);
1073 if (root->start > start || root->end < end) {
1074 pr_err("requested range [0x%llx-0x%llx] not in root %pr\n",
1075 (unsigned long long)start, (unsigned long long)end,
1076 root);
1077 if (start > root->end || end < root->start)
1078 abort = 1;
1079 else {
1080 if (end > root->end)
1081 end = root->end;
1082 if (start < root->start)
1083 start = root->start;
1084 pr_err("fixing request to [0x%llx-0x%llx]\n",
1085 (unsigned long long)start,
1086 (unsigned long long)end);
1087 }
1088 dump_stack();
1089 }
1090 if (!abort)
1091 __reserve_region_with_split(root, start, end, name);
1092 write_unlock(&resource_lock);
1093 }
1094
1095 /**
1096 * resource_alignment - calculate resource's alignment
1097 * @res: resource pointer
1098 *
1099 * Returns alignment on success, 0 (invalid alignment) on failure.
1100 */
1101 resource_size_t resource_alignment(struct resource *res)
1102 {
1103 switch (res->flags & (IORESOURCE_SIZEALIGN | IORESOURCE_STARTALIGN)) {
1104 case IORESOURCE_SIZEALIGN:
1105 return resource_size(res);
1106 case IORESOURCE_STARTALIGN:
1107 return res->start;
1108 default:
1109 return 0;
1110 }
1111 }
1112
1113 /*
1114 * This is compatibility stuff for IO resources.
1115 *
1116 * Note how this, unlike the above, knows about
1117 * the IO flag meanings (busy etc).
1118 *
1119 * request_region creates a new busy region.
1120 *
1121 * release_region releases a matching busy region.
1122 */
1123
1124 static DECLARE_WAIT_QUEUE_HEAD(muxed_resource_wait);
1125
1126 /**
1127 * __request_region - create a new busy resource region
1128 * @parent: parent resource descriptor
1129 * @start: resource start address
1130 * @n: resource region size
1131 * @name: reserving caller's ID string
1132 * @flags: IO resource flags
1133 */
1134 struct resource * __request_region(struct resource *parent,
1135 resource_size_t start, resource_size_t n,
1136 const char *name, int flags)
1137 {
1138 DECLARE_WAITQUEUE(wait, current);
1139 struct resource *res = alloc_resource(GFP_KERNEL);
1140
1141 if (!res)
1142 return NULL;
1143
1144 res->name = name;
1145 res->start = start;
1146 res->end = start + n - 1;
1147
1148 write_lock(&resource_lock);
1149
1150 for (;;) {
1151 struct resource *conflict;
1152
1153 res->flags = resource_type(parent) | resource_ext_type(parent);
1154 res->flags |= IORESOURCE_BUSY | flags;
1155 res->desc = parent->desc;
1156
1157 conflict = __request_resource(parent, res);
1158 if (!conflict)
1159 break;
1160 if (conflict != parent) {
1161 if (!(conflict->flags & IORESOURCE_BUSY)) {
1162 parent = conflict;
1163 continue;
1164 }
1165 }
1166 if (conflict->flags & flags & IORESOURCE_MUXED) {
1167 add_wait_queue(&muxed_resource_wait, &wait);
1168 write_unlock(&resource_lock);
1169 set_current_state(TASK_UNINTERRUPTIBLE);
1170 schedule();
1171 remove_wait_queue(&muxed_resource_wait, &wait);
1172 write_lock(&resource_lock);
1173 continue;
1174 }
1175 /* Uhhuh, that didn't work out.. */
1176 free_resource(res);
1177 res = NULL;
1178 break;
1179 }
1180 write_unlock(&resource_lock);
1181 return res;
1182 }
1183 EXPORT_SYMBOL(__request_region);
1184
1185 /**
1186 * __release_region - release a previously reserved resource region
1187 * @parent: parent resource descriptor
1188 * @start: resource start address
1189 * @n: resource region size
1190 *
1191 * The described resource region must match a currently busy region.
1192 */
1193 void __release_region(struct resource *parent, resource_size_t start,
1194 resource_size_t n)
1195 {
1196 struct resource **p;
1197 resource_size_t end;
1198
1199 p = &parent->child;
1200 end = start + n - 1;
1201
1202 write_lock(&resource_lock);
1203
1204 for (;;) {
1205 struct resource *res = *p;
1206
1207 if (!res)
1208 break;
1209 if (res->start <= start && res->end >= end) {
1210 if (!(res->flags & IORESOURCE_BUSY)) {
1211 p = &res->child;
1212 continue;
1213 }
1214 if (res->start != start || res->end != end)
1215 break;
1216 *p = res->sibling;
1217 write_unlock(&resource_lock);
1218 if (res->flags & IORESOURCE_MUXED)
1219 wake_up(&muxed_resource_wait);
1220 free_resource(res);
1221 return;
1222 }
1223 p = &res->sibling;
1224 }
1225
1226 write_unlock(&resource_lock);
1227
1228 printk(KERN_WARNING "Trying to free nonexistent resource "
1229 "<%016llx-%016llx>\n", (unsigned long long)start,
1230 (unsigned long long)end);
1231 }
1232 EXPORT_SYMBOL(__release_region);
1233
1234 #ifdef CONFIG_MEMORY_HOTREMOVE
1235 /**
1236 * release_mem_region_adjustable - release a previously reserved memory region
1237 * @parent: parent resource descriptor
1238 * @start: resource start address
1239 * @size: resource region size
1240 *
1241 * This interface is intended for memory hot-delete. The requested region
1242 * is released from a currently busy memory resource. The requested region
1243 * must either match exactly or fit into a single busy resource entry. In
1244 * the latter case, the remaining resource is adjusted accordingly.
1245 * Existing children of the busy memory resource must be immutable in the
1246 * request.
1247 *
1248 * Note:
1249 * - Additional release conditions, such as overlapping region, can be
1250 * supported after they are confirmed as valid cases.
1251 * - When a busy memory resource gets split into two entries, the code
1252 * assumes that all children remain in the lower address entry for
1253 * simplicity. Enhance this logic when necessary.
1254 */
1255 int release_mem_region_adjustable(struct resource *parent,
1256 resource_size_t start, resource_size_t size)
1257 {
1258 struct resource **p;
1259 struct resource *res;
1260 struct resource *new_res;
1261 resource_size_t end;
1262 int ret = -EINVAL;
1263
1264 end = start + size - 1;
1265 if ((start < parent->start) || (end > parent->end))
1266 return ret;
1267
1268 /* The alloc_resource() result gets checked later */
1269 new_res = alloc_resource(GFP_KERNEL);
1270
1271 p = &parent->child;
1272 write_lock(&resource_lock);
1273
1274 while ((res = *p)) {
1275 if (res->start >= end)
1276 break;
1277
1278 /* look for the next resource if it does not fit into */
1279 if (res->start > start || res->end < end) {
1280 p = &res->sibling;
1281 continue;
1282 }
1283
1284 if (!(res->flags & IORESOURCE_MEM))
1285 break;
1286
1287 if (!(res->flags & IORESOURCE_BUSY)) {
1288 p = &res->child;
1289 continue;
1290 }
1291
1292 /* found the target resource; let's adjust accordingly */
1293 if (res->start == start && res->end == end) {
1294 /* free the whole entry */
1295 *p = res->sibling;
1296 free_resource(res);
1297 ret = 0;
1298 } else if (res->start == start && res->end != end) {
1299 /* adjust the start */
1300 ret = __adjust_resource(res, end + 1,
1301 res->end - end);
1302 } else if (res->start != start && res->end == end) {
1303 /* adjust the end */
1304 ret = __adjust_resource(res, res->start,
1305 start - res->start);
1306 } else {
1307 /* split into two entries */
1308 if (!new_res) {
1309 ret = -ENOMEM;
1310 break;
1311 }
1312 new_res->name = res->name;
1313 new_res->start = end + 1;
1314 new_res->end = res->end;
1315 new_res->flags = res->flags;
1316 new_res->desc = res->desc;
1317 new_res->parent = res->parent;
1318 new_res->sibling = res->sibling;
1319 new_res->child = NULL;
1320
1321 ret = __adjust_resource(res, res->start,
1322 start - res->start);
1323 if (ret)
1324 break;
1325 res->sibling = new_res;
1326 new_res = NULL;
1327 }
1328
1329 break;
1330 }
1331
1332 write_unlock(&resource_lock);
1333 free_resource(new_res);
1334 return ret;
1335 }
1336 #endif /* CONFIG_MEMORY_HOTREMOVE */
1337
1338 /*
1339 * Managed region resource
1340 */
1341 static void devm_resource_release(struct device *dev, void *ptr)
1342 {
1343 struct resource **r = ptr;
1344
1345 release_resource(*r);
1346 }
1347
1348 /**
1349 * devm_request_resource() - request and reserve an I/O or memory resource
1350 * @dev: device for which to request the resource
1351 * @root: root of the resource tree from which to request the resource
1352 * @new: descriptor of the resource to request
1353 *
1354 * This is a device-managed version of request_resource(). There is usually
1355 * no need to release resources requested by this function explicitly since
1356 * that will be taken care of when the device is unbound from its driver.
1357 * If for some reason the resource needs to be released explicitly, because
1358 * of ordering issues for example, drivers must call devm_release_resource()
1359 * rather than the regular release_resource().
1360 *
1361 * When a conflict is detected between any existing resources and the newly
1362 * requested resource, an error message will be printed.
1363 *
1364 * Returns 0 on success or a negative error code on failure.
1365 */
1366 int devm_request_resource(struct device *dev, struct resource *root,
1367 struct resource *new)
1368 {
1369 struct resource *conflict, **ptr;
1370
1371 ptr = devres_alloc(devm_resource_release, sizeof(*ptr), GFP_KERNEL);
1372 if (!ptr)
1373 return -ENOMEM;
1374
1375 *ptr = new;
1376
1377 conflict = request_resource_conflict(root, new);
1378 if (conflict) {
1379 dev_err(dev, "resource collision: %pR conflicts with %s %pR\n",
1380 new, conflict->name, conflict);
1381 devres_free(ptr);
1382 return -EBUSY;
1383 }
1384
1385 devres_add(dev, ptr);
1386 return 0;
1387 }
1388 EXPORT_SYMBOL(devm_request_resource);
1389
1390 static int devm_resource_match(struct device *dev, void *res, void *data)
1391 {
1392 struct resource **ptr = res;
1393
1394 return *ptr == data;
1395 }
1396
1397 /**
1398 * devm_release_resource() - release a previously requested resource
1399 * @dev: device for which to release the resource
1400 * @new: descriptor of the resource to release
1401 *
1402 * Releases a resource previously requested using devm_request_resource().
1403 */
1404 void devm_release_resource(struct device *dev, struct resource *new)
1405 {
1406 WARN_ON(devres_release(dev, devm_resource_release, devm_resource_match,
1407 new));
1408 }
1409 EXPORT_SYMBOL(devm_release_resource);
1410
1411 struct region_devres {
1412 struct resource *parent;
1413 resource_size_t start;
1414 resource_size_t n;
1415 };
1416
1417 static void devm_region_release(struct device *dev, void *res)
1418 {
1419 struct region_devres *this = res;
1420
1421 __release_region(this->parent, this->start, this->n);
1422 }
1423
1424 static int devm_region_match(struct device *dev, void *res, void *match_data)
1425 {
1426 struct region_devres *this = res, *match = match_data;
1427
1428 return this->parent == match->parent &&
1429 this->start == match->start && this->n == match->n;
1430 }
1431
1432 struct resource * __devm_request_region(struct device *dev,
1433 struct resource *parent, resource_size_t start,
1434 resource_size_t n, const char *name)
1435 {
1436 struct region_devres *dr = NULL;
1437 struct resource *res;
1438
1439 dr = devres_alloc(devm_region_release, sizeof(struct region_devres),
1440 GFP_KERNEL);
1441 if (!dr)
1442 return NULL;
1443
1444 dr->parent = parent;
1445 dr->start = start;
1446 dr->n = n;
1447
1448 res = __request_region(parent, start, n, name, 0);
1449 if (res)
1450 devres_add(dev, dr);
1451 else
1452 devres_free(dr);
1453
1454 return res;
1455 }
1456 EXPORT_SYMBOL(__devm_request_region);
1457
1458 void __devm_release_region(struct device *dev, struct resource *parent,
1459 resource_size_t start, resource_size_t n)
1460 {
1461 struct region_devres match_data = { parent, start, n };
1462
1463 __release_region(parent, start, n);
1464 WARN_ON(devres_destroy(dev, devm_region_release, devm_region_match,
1465 &match_data));
1466 }
1467 EXPORT_SYMBOL(__devm_release_region);
1468
1469 /*
1470 * Called from init/main.c to reserve IO ports.
1471 */
1472 #define MAXRESERVE 4
1473 static int __init reserve_setup(char *str)
1474 {
1475 static int reserved;
1476 static struct resource reserve[MAXRESERVE];
1477
1478 for (;;) {
1479 unsigned int io_start, io_num;
1480 int x = reserved;
1481
1482 if (get_option (&str, &io_start) != 2)
1483 break;
1484 if (get_option (&str, &io_num) == 0)
1485 break;
1486 if (x < MAXRESERVE) {
1487 struct resource *res = reserve + x;
1488 res->name = "reserved";
1489 res->start = io_start;
1490 res->end = io_start + io_num - 1;
1491 res->flags = IORESOURCE_BUSY;
1492 res->desc = IORES_DESC_NONE;
1493 res->child = NULL;
1494 if (request_resource(res->start >= 0x10000 ? &iomem_resource : &ioport_resource, res) == 0)
1495 reserved = x+1;
1496 }
1497 }
1498 return 1;
1499 }
1500
1501 __setup("reserve=", reserve_setup);
1502
1503 /*
1504 * Check if the requested addr and size spans more than any slot in the
1505 * iomem resource tree.
1506 */
1507 int iomem_map_sanity_check(resource_size_t addr, unsigned long size)
1508 {
1509 struct resource *p = &iomem_resource;
1510 int err = 0;
1511 loff_t l;
1512
1513 read_lock(&resource_lock);
1514 for (p = p->child; p ; p = r_next(NULL, p, &l)) {
1515 /*
1516 * We can probably skip the resources without
1517 * IORESOURCE_IO attribute?
1518 */
1519 if (p->start >= addr + size)
1520 continue;
1521 if (p->end < addr)
1522 continue;
1523 if (PFN_DOWN(p->start) <= PFN_DOWN(addr) &&
1524 PFN_DOWN(p->end) >= PFN_DOWN(addr + size - 1))
1525 continue;
1526 /*
1527 * if a resource is "BUSY", it's not a hardware resource
1528 * but a driver mapping of such a resource; we don't want
1529 * to warn for those; some drivers legitimately map only
1530 * partial hardware resources. (example: vesafb)
1531 */
1532 if (p->flags & IORESOURCE_BUSY)
1533 continue;
1534
1535 printk(KERN_WARNING "resource sanity check: requesting [mem %#010llx-%#010llx], which spans more than %s %pR\n",
1536 (unsigned long long)addr,
1537 (unsigned long long)(addr + size - 1),
1538 p->name, p);
1539 err = -1;
1540 break;
1541 }
1542 read_unlock(&resource_lock);
1543
1544 return err;
1545 }
1546
1547 #ifdef CONFIG_STRICT_DEVMEM
1548 static int strict_iomem_checks = 1;
1549 #else
1550 static int strict_iomem_checks;
1551 #endif
1552
1553 /*
1554 * check if an address is reserved in the iomem resource tree
1555 * returns 1 if reserved, 0 if not reserved.
1556 */
1557 int iomem_is_exclusive(u64 addr)
1558 {
1559 struct resource *p = &iomem_resource;
1560 int err = 0;
1561 loff_t l;
1562 int size = PAGE_SIZE;
1563
1564 if (!strict_iomem_checks)
1565 return 0;
1566
1567 addr = addr & PAGE_MASK;
1568
1569 read_lock(&resource_lock);
1570 for (p = p->child; p ; p = r_next(NULL, p, &l)) {
1571 /*
1572 * We can probably skip the resources without
1573 * IORESOURCE_IO attribute?
1574 */
1575 if (p->start >= addr + size)
1576 break;
1577 if (p->end < addr)
1578 continue;
1579 /*
1580 * A resource is exclusive if IORESOURCE_EXCLUSIVE is set
1581 * or CONFIG_IO_STRICT_DEVMEM is enabled and the
1582 * resource is busy.
1583 */
1584 if ((p->flags & IORESOURCE_BUSY) == 0)
1585 continue;
1586 if (IS_ENABLED(CONFIG_IO_STRICT_DEVMEM)
1587 || p->flags & IORESOURCE_EXCLUSIVE) {
1588 err = 1;
1589 break;
1590 }
1591 }
1592 read_unlock(&resource_lock);
1593
1594 return err;
1595 }
1596
1597 struct resource_entry *resource_list_create_entry(struct resource *res,
1598 size_t extra_size)
1599 {
1600 struct resource_entry *entry;
1601
1602 entry = kzalloc(sizeof(*entry) + extra_size, GFP_KERNEL);
1603 if (entry) {
1604 INIT_LIST_HEAD(&entry->node);
1605 entry->res = res ? res : &entry->__res;
1606 }
1607
1608 return entry;
1609 }
1610 EXPORT_SYMBOL(resource_list_create_entry);
1611
1612 void resource_list_free(struct list_head *head)
1613 {
1614 struct resource_entry *entry, *tmp;
1615
1616 list_for_each_entry_safe(entry, tmp, head, node)
1617 resource_list_destroy_entry(entry);
1618 }
1619 EXPORT_SYMBOL(resource_list_free);
1620
1621 static int __init strict_iomem(char *str)
1622 {
1623 if (strstr(str, "relaxed"))
1624 strict_iomem_checks = 0;
1625 if (strstr(str, "strict"))
1626 strict_iomem_checks = 1;
1627 return 1;
1628 }
1629
1630 __setup("iomem=", strict_iomem);