blob: 2a3f886365808241e329222772d28dfadf87da62 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/module.h>
11#include <linux/sched.h>
12#include <linux/errno.h>
13#include <linux/ioport.h>
14#include <linux/init.h>
15#include <linux/slab.h>
16#include <linux/spinlock.h>
17#include <linux/fs.h>
18#include <linux/proc_fs.h>
19#include <linux/seq_file.h>
Tejun Heo9ac78492007-01-20 16:00:26 +090020#include <linux/device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <asm/io.h>
22
23
24struct resource ioport_resource = {
25 .name = "PCI IO",
Greg Kroah-Hartman6550e072006-06-12 17:11:31 -070026 .start = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 .end = IO_SPACE_LIMIT,
28 .flags = IORESOURCE_IO,
29};
Linus Torvalds1da177e2005-04-16 15:20:36 -070030EXPORT_SYMBOL(ioport_resource);
31
32struct resource iomem_resource = {
33 .name = "PCI mem",
Greg Kroah-Hartman6550e072006-06-12 17:11:31 -070034 .start = 0,
35 .end = -1,
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 .flags = IORESOURCE_MEM,
37};
Linus Torvalds1da177e2005-04-16 15:20:36 -070038EXPORT_SYMBOL(iomem_resource);
39
40static DEFINE_RWLOCK(resource_lock);
41
42#ifdef CONFIG_PROC_FS
43
44enum { MAX_IORES_LEVEL = 5 };
45
46static void *r_next(struct seq_file *m, void *v, loff_t *pos)
47{
48 struct resource *p = v;
49 (*pos)++;
50 if (p->child)
51 return p->child;
52 while (!p->sibling && p->parent)
53 p = p->parent;
54 return p->sibling;
55}
56
57static void *r_start(struct seq_file *m, loff_t *pos)
58 __acquires(resource_lock)
59{
60 struct resource *p = m->private;
61 loff_t l = 0;
62 read_lock(&resource_lock);
63 for (p = p->child; p && l < *pos; p = r_next(m, p, &l))
64 ;
65 return p;
66}
67
68static void r_stop(struct seq_file *m, void *v)
69 __releases(resource_lock)
70{
71 read_unlock(&resource_lock);
72}
73
74static int r_show(struct seq_file *m, void *v)
75{
76 struct resource *root = m->private;
77 struct resource *r = v, *p;
78 int width = root->end < 0x10000 ? 4 : 8;
79 int depth;
80
81 for (depth = 0, p = r; depth < MAX_IORES_LEVEL; depth++, p = p->parent)
82 if (p->parent == root)
83 break;
Greg Kroah-Hartman685143ac2006-06-12 15:18:31 -070084 seq_printf(m, "%*s%0*llx-%0*llx : %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 depth * 2, "",
Greg Kroah-Hartman685143ac2006-06-12 15:18:31 -070086 width, (unsigned long long) r->start,
87 width, (unsigned long long) r->end,
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 r->name ? r->name : "<BAD>");
89 return 0;
90}
91
Helge Deller15ad7cd2006-12-06 20:40:36 -080092static const struct seq_operations resource_op = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 .start = r_start,
94 .next = r_next,
95 .stop = r_stop,
96 .show = r_show,
97};
98
99static int ioports_open(struct inode *inode, struct file *file)
100{
101 int res = seq_open(file, &resource_op);
102 if (!res) {
103 struct seq_file *m = file->private_data;
104 m->private = &ioport_resource;
105 }
106 return res;
107}
108
109static int iomem_open(struct inode *inode, struct file *file)
110{
111 int res = seq_open(file, &resource_op);
112 if (!res) {
113 struct seq_file *m = file->private_data;
114 m->private = &iomem_resource;
115 }
116 return res;
117}
118
Helge Deller15ad7cd2006-12-06 20:40:36 -0800119static const struct file_operations proc_ioports_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 .open = ioports_open,
121 .read = seq_read,
122 .llseek = seq_lseek,
123 .release = seq_release,
124};
125
Helge Deller15ad7cd2006-12-06 20:40:36 -0800126static const struct file_operations proc_iomem_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 .open = iomem_open,
128 .read = seq_read,
129 .llseek = seq_lseek,
130 .release = seq_release,
131};
132
133static int __init ioresources_init(void)
134{
135 struct proc_dir_entry *entry;
136
137 entry = create_proc_entry("ioports", 0, NULL);
138 if (entry)
139 entry->proc_fops = &proc_ioports_operations;
140 entry = create_proc_entry("iomem", 0, NULL);
141 if (entry)
142 entry->proc_fops = &proc_iomem_operations;
143 return 0;
144}
145__initcall(ioresources_init);
146
147#endif /* CONFIG_PROC_FS */
148
149/* Return the conflict entry if you can't request it */
150static struct resource * __request_resource(struct resource *root, struct resource *new)
151{
Greg Kroah-Hartmand75fc8b2006-06-12 16:09:23 -0700152 resource_size_t start = new->start;
153 resource_size_t end = new->end;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 struct resource *tmp, **p;
155
156 if (end < start)
157 return root;
158 if (start < root->start)
159 return root;
160 if (end > root->end)
161 return root;
162 p = &root->child;
163 for (;;) {
164 tmp = *p;
165 if (!tmp || tmp->start > end) {
166 new->sibling = tmp;
167 *p = new;
168 new->parent = root;
169 return NULL;
170 }
171 p = &tmp->sibling;
172 if (tmp->end < start)
173 continue;
174 return tmp;
175 }
176}
177
178static int __release_resource(struct resource *old)
179{
180 struct resource *tmp, **p;
181
182 p = &old->parent->child;
183 for (;;) {
184 tmp = *p;
185 if (!tmp)
186 break;
187 if (tmp == old) {
188 *p = tmp->sibling;
189 old->parent = NULL;
190 return 0;
191 }
192 p = &tmp->sibling;
193 }
194 return -EINVAL;
195}
196
Randy Dunlape1ca66d2006-10-03 01:13:51 -0700197/**
198 * request_resource - request and reserve an I/O or memory resource
199 * @root: root resource descriptor
200 * @new: resource descriptor desired by caller
201 *
202 * Returns 0 for success, negative error code on error.
203 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204int request_resource(struct resource *root, struct resource *new)
205{
206 struct resource *conflict;
207
208 write_lock(&resource_lock);
209 conflict = __request_resource(root, new);
210 write_unlock(&resource_lock);
211 return conflict ? -EBUSY : 0;
212}
213
214EXPORT_SYMBOL(request_resource);
215
Randy Dunlape1ca66d2006-10-03 01:13:51 -0700216/**
217 * ____request_resource - reserve a resource, with resource conflict returned
218 * @root: root resource descriptor
219 * @new: resource descriptor desired by caller
220 *
221 * Returns:
222 * On success, NULL is returned.
223 * On error, a pointer to the conflicting resource is returned.
224 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225struct resource *____request_resource(struct resource *root, struct resource *new)
226{
227 struct resource *conflict;
228
229 write_lock(&resource_lock);
230 conflict = __request_resource(root, new);
231 write_unlock(&resource_lock);
232 return conflict;
233}
234
235EXPORT_SYMBOL(____request_resource);
236
Randy Dunlape1ca66d2006-10-03 01:13:51 -0700237/**
238 * release_resource - release a previously reserved resource
239 * @old: resource pointer
240 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241int release_resource(struct resource *old)
242{
243 int retval;
244
245 write_lock(&resource_lock);
246 retval = __release_resource(old);
247 write_unlock(&resource_lock);
248 return retval;
249}
250
251EXPORT_SYMBOL(release_resource);
252
KAMEZAWA Hiroyuki2842f112006-06-27 02:53:36 -0700253#ifdef CONFIG_MEMORY_HOTPLUG
254/*
255 * Finds the lowest memory reosurce exists within [res->start.res->end)
256 * the caller must specify res->start, res->end, res->flags.
257 * If found, returns 0, res is overwritten, if not found, returns -1.
258 */
259int find_next_system_ram(struct resource *res)
260{
261 resource_size_t start, end;
262 struct resource *p;
263
264 BUG_ON(!res);
265
266 start = res->start;
267 end = res->end;
KAMEZAWA Hiroyuki58c1b5b2006-08-05 12:15:01 -0700268 BUG_ON(start >= end);
KAMEZAWA Hiroyuki2842f112006-06-27 02:53:36 -0700269
270 read_lock(&resource_lock);
271 for (p = iomem_resource.child; p ; p = p->sibling) {
272 /* system ram is just marked as IORESOURCE_MEM */
273 if (p->flags != res->flags)
274 continue;
275 if (p->start > end) {
276 p = NULL;
277 break;
278 }
KAMEZAWA Hiroyuki58c1b5b2006-08-05 12:15:01 -0700279 if ((p->end >= start) && (p->start < end))
KAMEZAWA Hiroyuki2842f112006-06-27 02:53:36 -0700280 break;
281 }
282 read_unlock(&resource_lock);
283 if (!p)
284 return -1;
285 /* copy data */
KAMEZAWA Hiroyuki0f04ab52006-08-05 12:14:59 -0700286 if (res->start < p->start)
287 res->start = p->start;
288 if (res->end > p->end)
289 res->end = p->end;
KAMEZAWA Hiroyuki2842f112006-06-27 02:53:36 -0700290 return 0;
291}
292#endif
293
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294/*
295 * Find empty slot in the resource tree given range and alignment.
296 */
297static int find_resource(struct resource *root, struct resource *new,
Greg Kroah-Hartmand75fc8b2006-06-12 16:09:23 -0700298 resource_size_t size, resource_size_t min,
299 resource_size_t max, resource_size_t align,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 void (*alignf)(void *, struct resource *,
Greg Kroah-Hartmand75fc8b2006-06-12 16:09:23 -0700301 resource_size_t, resource_size_t),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 void *alignf_data)
303{
304 struct resource *this = root->child;
305
306 new->start = root->start;
307 /*
308 * Skip past an allocated resource that starts at 0, since the assignment
309 * of this->start - 1 to new->end below would cause an underflow.
310 */
311 if (this && this->start == 0) {
312 new->start = this->end + 1;
313 this = this->sibling;
314 }
315 for(;;) {
316 if (this)
317 new->end = this->start - 1;
318 else
319 new->end = root->end;
320 if (new->start < min)
321 new->start = min;
322 if (new->end > max)
323 new->end = max;
Nick Wilson8c0e33c2005-06-25 14:59:00 -0700324 new->start = ALIGN(new->start, align);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 if (alignf)
326 alignf(alignf_data, new, size, align);
Lennert Buytenhekb52402c2005-04-16 15:25:58 -0700327 if (new->start < new->end && new->end - new->start >= size - 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 new->end = new->start + size - 1;
329 return 0;
330 }
331 if (!this)
332 break;
333 new->start = this->end + 1;
334 this = this->sibling;
335 }
336 return -EBUSY;
337}
338
Randy Dunlape1ca66d2006-10-03 01:13:51 -0700339/**
340 * allocate_resource - allocate empty slot in the resource tree given range & alignment
341 * @root: root resource descriptor
342 * @new: resource descriptor desired by caller
343 * @size: requested resource region size
344 * @min: minimum size to allocate
345 * @max: maximum size to allocate
346 * @align: alignment requested, in bytes
347 * @alignf: alignment function, optional, called if not NULL
348 * @alignf_data: arbitrary data to pass to the @alignf function
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 */
350int allocate_resource(struct resource *root, struct resource *new,
Greg Kroah-Hartmand75fc8b2006-06-12 16:09:23 -0700351 resource_size_t size, resource_size_t min,
352 resource_size_t max, resource_size_t align,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 void (*alignf)(void *, struct resource *,
Greg Kroah-Hartmand75fc8b2006-06-12 16:09:23 -0700354 resource_size_t, resource_size_t),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 void *alignf_data)
356{
357 int err;
358
359 write_lock(&resource_lock);
360 err = find_resource(root, new, size, min, max, align, alignf, alignf_data);
361 if (err >= 0 && __request_resource(root, new))
362 err = -EBUSY;
363 write_unlock(&resource_lock);
364 return err;
365}
366
367EXPORT_SYMBOL(allocate_resource);
368
369/**
370 * insert_resource - Inserts a resource in the resource tree
371 * @parent: parent of the new resource
372 * @new: new resource to insert
373 *
374 * Returns 0 on success, -EBUSY if the resource can't be inserted.
375 *
Matthew Wilcoxd33b6fb2006-06-30 02:31:24 -0700376 * This function is equivalent to request_resource when no conflict
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 * happens. If a conflict happens, and the conflicting resources
378 * entirely fit within the range of the new resource, then the new
Matthew Wilcoxd33b6fb2006-06-30 02:31:24 -0700379 * resource is inserted and the conflicting resources become children of
380 * the new resource.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 */
382int insert_resource(struct resource *parent, struct resource *new)
383{
384 int result;
385 struct resource *first, *next;
386
387 write_lock(&resource_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
Matthew Wilcoxd33b6fb2006-06-30 02:31:24 -0700389 for (;; parent = first) {
390 result = 0;
391 first = __request_resource(parent, new);
392 if (!first)
393 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
Matthew Wilcoxd33b6fb2006-06-30 02:31:24 -0700395 result = -EBUSY;
396 if (first == parent)
397 goto out;
398
399 if ((first->start > new->start) || (first->end < new->end))
400 break;
401 if ((first->start == new->start) && (first->end == new->end))
402 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 }
404
405 for (next = first; ; next = next->sibling) {
406 /* Partial overlap? Bad, and unfixable */
407 if (next->start < new->start || next->end > new->end)
408 goto out;
409 if (!next->sibling)
410 break;
411 if (next->sibling->start > new->end)
412 break;
413 }
414
415 result = 0;
416
417 new->parent = parent;
418 new->sibling = next->sibling;
419 new->child = first;
420
421 next->sibling = NULL;
422 for (next = first; next; next = next->sibling)
423 next->parent = new;
424
425 if (parent->child == first) {
426 parent->child = new;
427 } else {
428 next = parent->child;
429 while (next->sibling != first)
430 next = next->sibling;
431 next->sibling = new;
432 }
433
434 out:
435 write_unlock(&resource_lock);
436 return result;
437}
438
Randy Dunlape1ca66d2006-10-03 01:13:51 -0700439/**
440 * adjust_resource - modify a resource's start and size
441 * @res: resource to modify
442 * @start: new start value
443 * @size: new size
444 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 * Given an existing resource, change its start and size to match the
Randy Dunlape1ca66d2006-10-03 01:13:51 -0700446 * arguments. Returns 0 on success, -EBUSY if it can't fit.
447 * Existing children of the resource are assumed to be immutable.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 */
Greg Kroah-Hartmand75fc8b2006-06-12 16:09:23 -0700449int adjust_resource(struct resource *res, resource_size_t start, resource_size_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450{
451 struct resource *tmp, *parent = res->parent;
Greg Kroah-Hartmand75fc8b2006-06-12 16:09:23 -0700452 resource_size_t end = start + size - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 int result = -EBUSY;
454
455 write_lock(&resource_lock);
456
457 if ((start < parent->start) || (end > parent->end))
458 goto out;
459
460 for (tmp = res->child; tmp; tmp = tmp->sibling) {
461 if ((tmp->start < start) || (tmp->end > end))
462 goto out;
463 }
464
465 if (res->sibling && (res->sibling->start <= end))
466 goto out;
467
468 tmp = parent->child;
469 if (tmp != res) {
470 while (tmp->sibling != res)
471 tmp = tmp->sibling;
472 if (start <= tmp->end)
473 goto out;
474 }
475
476 res->start = start;
477 res->end = end;
478 result = 0;
479
480 out:
481 write_unlock(&resource_lock);
482 return result;
483}
484
485EXPORT_SYMBOL(adjust_resource);
486
487/*
488 * This is compatibility stuff for IO resources.
489 *
490 * Note how this, unlike the above, knows about
491 * the IO flag meanings (busy etc).
492 *
Randy Dunlape1ca66d2006-10-03 01:13:51 -0700493 * request_region creates a new busy region.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 *
Randy Dunlape1ca66d2006-10-03 01:13:51 -0700495 * check_region returns non-zero if the area is already busy.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 *
Randy Dunlape1ca66d2006-10-03 01:13:51 -0700497 * release_region releases a matching busy region.
498 */
499
500/**
501 * __request_region - create a new busy resource region
502 * @parent: parent resource descriptor
503 * @start: resource start address
504 * @n: resource region size
505 * @name: reserving caller's ID string
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 */
Greg Kroah-Hartmand75fc8b2006-06-12 16:09:23 -0700507struct resource * __request_region(struct resource *parent,
508 resource_size_t start, resource_size_t n,
509 const char *name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510{
Pekka J Enbergdd392712005-09-06 15:18:31 -0700511 struct resource *res = kzalloc(sizeof(*res), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512
513 if (res) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 res->name = name;
515 res->start = start;
516 res->end = start + n - 1;
517 res->flags = IORESOURCE_BUSY;
518
519 write_lock(&resource_lock);
520
521 for (;;) {
522 struct resource *conflict;
523
524 conflict = __request_resource(parent, res);
525 if (!conflict)
526 break;
527 if (conflict != parent) {
528 parent = conflict;
529 if (!(conflict->flags & IORESOURCE_BUSY))
530 continue;
531 }
532
533 /* Uhhuh, that didn't work out.. */
534 kfree(res);
535 res = NULL;
536 break;
537 }
538 write_unlock(&resource_lock);
539 }
540 return res;
541}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542EXPORT_SYMBOL(__request_region);
543
Randy Dunlape1ca66d2006-10-03 01:13:51 -0700544/**
545 * __check_region - check if a resource region is busy or free
546 * @parent: parent resource descriptor
547 * @start: resource start address
548 * @n: resource region size
549 *
550 * Returns 0 if the region is free at the moment it is checked,
551 * returns %-EBUSY if the region is busy.
552 *
553 * NOTE:
554 * This function is deprecated because its use is racy.
555 * Even if it returns 0, a subsequent call to request_region()
556 * may fail because another driver etc. just allocated the region.
557 * Do NOT use it. It will be removed from the kernel.
558 */
Greg Kroah-Hartmand75fc8b2006-06-12 16:09:23 -0700559int __check_region(struct resource *parent, resource_size_t start,
560 resource_size_t n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561{
562 struct resource * res;
563
564 res = __request_region(parent, start, n, "check-region");
565 if (!res)
566 return -EBUSY;
567
568 release_resource(res);
569 kfree(res);
570 return 0;
571}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572EXPORT_SYMBOL(__check_region);
573
Randy Dunlape1ca66d2006-10-03 01:13:51 -0700574/**
575 * __release_region - release a previously reserved resource region
576 * @parent: parent resource descriptor
577 * @start: resource start address
578 * @n: resource region size
579 *
580 * The described resource region must match a currently busy region.
581 */
Greg Kroah-Hartmand75fc8b2006-06-12 16:09:23 -0700582void __release_region(struct resource *parent, resource_size_t start,
583 resource_size_t n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584{
585 struct resource **p;
Greg Kroah-Hartmand75fc8b2006-06-12 16:09:23 -0700586 resource_size_t end;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587
588 p = &parent->child;
589 end = start + n - 1;
590
591 write_lock(&resource_lock);
592
593 for (;;) {
594 struct resource *res = *p;
595
596 if (!res)
597 break;
598 if (res->start <= start && res->end >= end) {
599 if (!(res->flags & IORESOURCE_BUSY)) {
600 p = &res->child;
601 continue;
602 }
603 if (res->start != start || res->end != end)
604 break;
605 *p = res->sibling;
606 write_unlock(&resource_lock);
607 kfree(res);
608 return;
609 }
610 p = &res->sibling;
611 }
612
613 write_unlock(&resource_lock);
614
Greg Kroah-Hartman685143ac2006-06-12 15:18:31 -0700615 printk(KERN_WARNING "Trying to free nonexistent resource "
616 "<%016llx-%016llx>\n", (unsigned long long)start,
617 (unsigned long long)end);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619EXPORT_SYMBOL(__release_region);
620
621/*
Tejun Heo9ac78492007-01-20 16:00:26 +0900622 * Managed region resource
623 */
624struct region_devres {
625 struct resource *parent;
626 resource_size_t start;
627 resource_size_t n;
628};
629
630static void devm_region_release(struct device *dev, void *res)
631{
632 struct region_devres *this = res;
633
634 __release_region(this->parent, this->start, this->n);
635}
636
637static int devm_region_match(struct device *dev, void *res, void *match_data)
638{
639 struct region_devres *this = res, *match = match_data;
640
641 return this->parent == match->parent &&
642 this->start == match->start && this->n == match->n;
643}
644
645struct resource * __devm_request_region(struct device *dev,
646 struct resource *parent, resource_size_t start,
647 resource_size_t n, const char *name)
648{
649 struct region_devres *dr = NULL;
650 struct resource *res;
651
652 dr = devres_alloc(devm_region_release, sizeof(struct region_devres),
653 GFP_KERNEL);
654 if (!dr)
655 return NULL;
656
657 dr->parent = parent;
658 dr->start = start;
659 dr->n = n;
660
661 res = __request_region(parent, start, n, name);
662 if (res)
663 devres_add(dev, dr);
664 else
665 devres_free(dr);
666
667 return res;
668}
669EXPORT_SYMBOL(__devm_request_region);
670
671void __devm_release_region(struct device *dev, struct resource *parent,
672 resource_size_t start, resource_size_t n)
673{
674 struct region_devres match_data = { parent, start, n };
675
676 __release_region(parent, start, n);
677 WARN_ON(devres_destroy(dev, devm_region_release, devm_region_match,
678 &match_data));
679}
680EXPORT_SYMBOL(__devm_release_region);
681
682/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 * Called from init/main.c to reserve IO ports.
684 */
685#define MAXRESERVE 4
686static int __init reserve_setup(char *str)
687{
688 static int reserved;
689 static struct resource reserve[MAXRESERVE];
690
691 for (;;) {
692 int io_start, io_num;
693 int x = reserved;
694
695 if (get_option (&str, &io_start) != 2)
696 break;
697 if (get_option (&str, &io_num) == 0)
698 break;
699 if (x < MAXRESERVE) {
700 struct resource *res = reserve + x;
701 res->name = "reserved";
702 res->start = io_start;
703 res->end = io_start + io_num - 1;
704 res->flags = IORESOURCE_BUSY;
705 res->child = NULL;
706 if (request_resource(res->start >= 0x10000 ? &iomem_resource : &ioport_resource, res) == 0)
707 reserved = x+1;
708 }
709 }
710 return 1;
711}
712
713__setup("reserve=", reserve_setup);