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