Release 4.7 kernel/resource.c
/*
* linux/kernel/resource.c
*
* Copyright (C) 1999 Linus Torvalds
* Copyright (C) 1999 Martin Mares <mj@ucw.cz>
*
* Arbitrary resource management.
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/export.h>
#include <linux/errno.h>
#include <linux/ioport.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/spinlock.h>
#include <linux/fs.h>
#include <linux/proc_fs.h>
#include <linux/sched.h>
#include <linux/seq_file.h>
#include <linux/device.h>
#include <linux/pfn.h>
#include <linux/mm.h>
#include <linux/resource_ext.h>
#include <asm/io.h>
struct resource ioport_resource = {
.name = "PCI IO",
.start = 0,
.end = IO_SPACE_LIMIT,
.flags = IORESOURCE_IO,
};
EXPORT_SYMBOL(ioport_resource);
struct resource iomem_resource = {
.name = "PCI mem",
.start = 0,
.end = -1,
.flags = IORESOURCE_MEM,
};
EXPORT_SYMBOL(iomem_resource);
/* constraints to be met while allocating resources */
struct resource_constraint {
resource_size_t min, max, align;
resource_size_t (*alignf)(void *, const struct resource *,
resource_size_t, resource_size_t);
void *alignf_data;
};
static DEFINE_RWLOCK(resource_lock);
/*
* For memory hotplug, there is no way to free resource entries allocated
* by boot mem after the system is up. So for reusing the resource entry
* we need to remember the resource.
*/
static struct resource *bootmem_resource_free;
static DEFINE_SPINLOCK(bootmem_resource_lock);
static struct resource *next_resource(struct resource *p, bool sibling_only)
{
/* Caller wants to traverse through siblings only */
if (sibling_only)
return p->sibling;
if (p->child)
return p->child;
while (!p->sibling && p->parent)
p = p->parent;
return p->sibling;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
al viro | al viro | 30 | 50.85% | 1 | 20.00% |
vivek goyal | vivek goyal | 16 | 27.12% | 1 | 20.00% |
pre-git | pre-git | 12 | 20.34% | 2 | 40.00% |
randy dunlap | randy dunlap | 1 | 1.69% | 1 | 20.00% |
| Total | 59 | 100.00% | 5 | 100.00% |
static void *r_next(struct seq_file *m, void *v, loff_t *pos)
{
struct resource *p = v;
(*pos)++;
return (void *)next_resource(p, false);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
vivek goyal | vivek goyal | 45 | 100.00% | 1 | 100.00% |
| Total | 45 | 100.00% | 1 | 100.00% |
#ifdef CONFIG_PROC_FS
enum { MAX_IORES_LEVEL = 5 };
static void *r_start(struct seq_file *m, loff_t *pos)
__acquires
(resource_lock)
{
struct resource *p = m->private;
loff_t l = 0;
read_lock(&resource_lock);
for (p = p->child; p && l < *pos; p = r_next(m, p, &l))
;
return p;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
al viro | al viro | 54 | 76.06% | 1 | 20.00% |
pre-git | pre-git | 10 | 14.08% | 2 | 40.00% |
linus torvalds | linus torvalds | 4 | 5.63% | 1 | 20.00% |
randy dunlap | randy dunlap | 3 | 4.23% | 1 | 20.00% |
| Total | 71 | 100.00% | 5 | 100.00% |
static void r_stop(struct seq_file *m, void *v)
__releases
(resource_lock)
{
read_unlock(&resource_lock);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
al viro | al viro | 21 | 84.00% | 1 | 50.00% |
linus torvalds | linus torvalds | 4 | 16.00% | 1 | 50.00% |
| Total | 25 | 100.00% | 2 | 100.00% |
static int r_show(struct seq_file *m, void *v)
{
struct resource *root = m->private;
struct resource *r = v, *p;
unsigned long long start, end;
int width = root->end < 0x10000 ? 4 : 8;
int depth;
for (depth = 0, p = r; depth < MAX_IORES_LEVEL; depth++, p = p->parent)
if (p->parent == root)
break;
if (file_ns_capable(m->file, &init_user_ns, CAP_SYS_ADMIN)) {
start = r->start;
end = r->end;
} else {
start = end = 0;
}
seq_printf(m, "%*s%0*llx-%0*llx : %s\n",
depth * 2, "",
width, start,
width, end,
r->name ? r->name : "<BAD>");
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
al viro | al viro | 72 | 45.00% | 1 | 11.11% |
linus torvalds | linus torvalds | 44 | 27.50% | 1 | 11.11% |
randy dunlap | randy dunlap | 23 | 14.38% | 1 | 11.11% |
pre-git | pre-git | 20 | 12.50% | 5 | 55.56% |
greg kroah-hartman | greg kroah-hartman | 1 | 0.62% | 1 | 11.11% |
| Total | 160 | 100.00% | 9 | 100.00% |
static const struct seq_operations resource_op = {
.start = r_start,
.next = r_next,
.stop = r_stop,
.show = r_show,
};
static int ioports_open(struct inode *inode, struct file *file)
{
int res = seq_open(file, &resource_op);
if (!res) {
struct seq_file *m = file->private_data;
m->private = &ioport_resource;
}
return res;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
al viro | al viro | 37 | 69.81% | 1 | 33.33% |
randy dunlap | randy dunlap | 15 | 28.30% | 1 | 33.33% |
pre-git | pre-git | 1 | 1.89% | 1 | 33.33% |
| Total | 53 | 100.00% | 3 | 100.00% |
static int iomem_open(struct inode *inode, struct file *file)
{
int res = seq_open(file, &resource_op);
if (!res) {
struct seq_file *m = file->private_data;
m->private = &iomem_resource;
}
return res;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
al viro | al viro | 32 | 60.38% | 1 | 33.33% |
randy dunlap | randy dunlap | 19 | 35.85% | 1 | 33.33% |
pre-git | pre-git | 2 | 3.77% | 1 | 33.33% |
| Total | 53 | 100.00% | 3 | 100.00% |
static const struct file_operations proc_ioports_operations = {
.open = ioports_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release,
};
static const struct file_operations proc_iomem_operations = {
.open = iomem_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release,
};
static int __init ioresources_init(void)
{
proc_create("ioports", 0, NULL, &proc_ioports_operations);
proc_create("iomem", 0, NULL, &proc_iomem_operations);
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
randy dunlap | randy dunlap | 27 | 75.00% | 1 | 25.00% |
denis v. lunev | denis v. lunev | 6 | 16.67% | 1 | 25.00% |
pre-git | pre-git | 3 | 8.33% | 2 | 50.00% |
| Total | 36 | 100.00% | 4 | 100.00% |
__initcall(ioresources_init);
#endif /* CONFIG_PROC_FS */
static void free_resource(struct resource *res)
{
if (!res)
return;
if (!PageSlab(virt_to_head_page(res))) {
spin_lock(&bootmem_resource_lock);
res->sibling = bootmem_resource_free;
bootmem_resource_free = res;
spin_unlock(&bootmem_resource_lock);
} else {
kfree(res);
}
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
yasuaki ishimatsu | yasuaki ishimatsu | 60 | 100.00% | 1 | 100.00% |
| Total | 60 | 100.00% | 1 | 100.00% |
static struct resource *alloc_resource(gfp_t flags)
{
struct resource *res = NULL;
spin_lock(&bootmem_resource_lock);
if (bootmem_resource_free) {
res = bootmem_resource_free;
bootmem_resource_free = res->sibling;
}
spin_unlock(&bootmem_resource_lock);
if (res)
memset(res, 0, sizeof(struct resource));
else
res = kzalloc(sizeof(struct resource), flags);
return res;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
yasuaki ishimatsu | yasuaki ishimatsu | 80 | 100.00% | 1 | 100.00% |
| Total | 80 | 100.00% | 1 | 100.00% |
/* Return the conflict entry if you can't request it */
static struct resource * __request_resource(struct resource *root, struct resource *new)
{
resource_size_t start = new->start;
resource_size_t end = new->end;
struct resource *tmp, **p;
if (end < start)
return root;
if (start < root->start)
return root;
if (end > root->end)
return root;
p = &root->child;
for (;;) {
tmp = *p;
if (!tmp || tmp->start > end) {
new->sibling = tmp;
*p = new;
new->parent = root;
return NULL;
}
p = &tmp->sibling;
if (tmp->end < start)
continue;
return tmp;
}
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
pre-git | pre-git | 141 | 98.60% | 4 | 80.00% |
greg kroah-hartman | greg kroah-hartman | 2 | 1.40% | 1 | 20.00% |
| Total | 143 | 100.00% | 5 | 100.00% |
static int __release_resource(struct resource *old, bool release_child)
{
struct resource *tmp, **p, *chd;
p = &old->parent->child;
for (;;) {
tmp = *p;
if (!tmp)
break;
if (tmp == old) {
if (release_child || !(tmp->child)) {
*p = tmp->sibling;
} else {
for (chd = tmp->child;; chd = chd->sibling) {
chd->parent = tmp->parent;
if (!(chd->sibling))
break;
}
*p = tmp->child;
chd->sibling = tmp->sibling;
}
old->parent = NULL;
return 0;
}
p = &tmp->sibling;
}
return -EINVAL;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
pre-git | pre-git | 82 | 53.25% | 1 | 50.00% |
toshi kani | toshi kani | 72 | 46.75% | 1 | 50.00% |
| Total | 154 | 100.00% | 2 | 100.00% |
static void __release_child_resources(struct resource *r)
{
struct resource *tmp, *p;
resource_size_t size;
p = r->child;
r->child = NULL;
while (p) {
tmp = p;
p = p->sibling;
tmp->parent = NULL;
tmp->sibling = NULL;
__release_child_resources(tmp);
printk(KERN_DEBUG "release child resource %pR\n", tmp);
/* need to restore size, and keep flags */
size = resource_size(tmp);
tmp->start = 0;
tmp->end = size - 1;
}
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
yinghai lu | yinghai lu | 97 | 100.00% | 1 | 100.00% |
| Total | 97 | 100.00% | 1 | 100.00% |
void release_child_resources(struct resource *r)
{
write_lock(&resource_lock);
__release_child_resources(r);
write_unlock(&resource_lock);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
yinghai lu | yinghai lu | 27 | 100.00% | 1 | 100.00% |
| Total | 27 | 100.00% | 1 | 100.00% |
/**
* request_resource_conflict - request and reserve an I/O or memory resource
* @root: root resource descriptor
* @new: resource descriptor desired by caller
*
* Returns 0 for success, conflict resource on error.
*/
struct resource *request_resource_conflict(struct resource *root, struct resource *new)
{
struct resource *conflict;
write_lock(&resource_lock);
conflict = __request_resource(root, new);
write_unlock(&resource_lock);
return conflict;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
pre-git | pre-git | 40 | 86.96% | 1 | 50.00% |
bjorn helgaas | bjorn helgaas | 6 | 13.04% | 1 | 50.00% |
| Total | 46 | 100.00% | 2 | 100.00% |
/**
* request_resource - request and reserve an I/O or memory resource
* @root: root resource descriptor
* @new: resource descriptor desired by caller
*
* Returns 0 for success, negative error code on error.
*/
int request_resource(struct resource *root, struct resource *new)
{
struct resource *conflict;
conflict = request_resource_conflict(root, new);
return conflict ? -EBUSY : 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
bjorn helgaas | bjorn helgaas | 30 | 81.08% | 1 | 25.00% |
pre-git | pre-git | 7 | 18.92% | 3 | 75.00% |
| Total | 37 | 100.00% | 4 | 100.00% |
EXPORT_SYMBOL(request_resource);
/**
* release_resource - release a previously reserved resource
* @old: resource pointer
*/
int release_resource(struct resource *old)
{
int retval;
write_lock(&resource_lock);
retval = __release_resource(old, true);
write_unlock(&resource_lock);
return retval;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
pre-git | pre-git | 35 | 94.59% | 4 | 80.00% |
toshi kani | toshi kani | 2 | 5.41% | 1 | 20.00% |
| Total | 37 | 100.00% | 5 | 100.00% |
EXPORT_SYMBOL(release_resource);
/*
* Finds the lowest iomem resource existing within [res->start.res->end).
* The caller must specify res->start, res->end, res->flags, and optionally
* desc. If found, returns 0, res is overwritten, if not found, returns -1.
* This function walks the whole tree and not just first level children until
* and unless first_level_children_only is true.
*/
static int find_next_iomem_res(struct resource *res, unsigned long desc,
bool first_level_children_only)
{
resource_size_t start, end;
struct resource *p;
bool sibling_only = false;
BUG_ON(!res);
start = res->start;
end = res->end;
BUG_ON(start >= end);
if (first_level_children_only)
sibling_only = true;
read_lock(&resource_lock);
for (p = iomem_resource.child; p; p = next_resource(p, sibling_only)) {
if ((p->flags & res->flags) != res->flags)
continue;
if ((desc != IORES_DESC_NONE) && (desc != p->desc))
continue;
if (p->start > end) {
p = NULL;
break;
}
if ((p->end >= start) && (p->start < end))
break;
}
read_unlock(&resource_lock);
if (!p)
return -1;
/* copy data */
if (res->start < p->start)
res->start = p->start;
if (res->end > p->end)
res->end = p->end;
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
kamezawa hiroyuki | kamezawa hiroyuki | 163 | 75.46% | 5 | 55.56% |
toshi kani | toshi kani | 27 | 12.50% | 2 | 22.22% |
vivek goyal | vivek goyal | 26 | 12.04% | 2 | 22.22% |
| Total | 216 | 100.00% | 9 | 100.00% |
/*
* Walks through iomem resources and calls func() with matching resource
* ranges. This walks through whole tree and not just first level children.
* All the memory ranges which overlap start,end and also match flags and
* desc are valid candidates.
*
* @desc: I/O resource descriptor. Use IORES_DESC_NONE to skip @desc check.
* @flags: I/O resource flags
* @start: start addr
* @end: end addr
*
* NOTE: For a new descriptor search, define a new IORES_DESC in
* <linux/ioport.h> and set it in 'desc' of a target resource entry.
*/
int walk_iomem_res_desc(unsigned long desc, unsigned long flags, u64 start,
u64 end, void *arg, int (*func)(u64, u64, void *))
{
struct resource res;
u64 orig_end;
int ret = -1;
res.start = start;
res.end = end;
res.flags = flags;
orig_end = res.end;
while ((res.start < res.end) &&
(!find_next_iomem_res(&res, desc, false))) {
ret = (*func)(res.start, res.end, arg);
if (ret)
break;
res.start = res.end + 1;
res.end = orig_end;
}
return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
toshi kani | toshi kani | 94 | 65.73% | 1 | 50.00% |
vivek goyal | vivek goyal | 49 | 34.27% | 1 | 50.00% |
| Total | 143 | 100.00% | 2 | 100.00% |
/*
* This function calls the @func callback against all memory ranges of type
* System RAM which are marked as IORESOURCE_SYSTEM_RAM and IORESOUCE_BUSY.
* Now, this function is only for System RAM, it deals with full ranges and
* not PFNs. If resources are not PFN-aligned, dealing with PFNs can truncate
* ranges.
*/
int walk_system_ram_res(u64 start, u64 end, void *arg,
int (*func)(u64, u64, void *))
{
struct resource res;
u64 orig_end;
int ret = -1;
res.start = start;
res.end = end;
res.flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
orig_end = res.end;
while ((res.start < res.end) &&
(!find_next_iomem_res(&res, IORES_DESC_NONE, true))) {
ret = (*func)(res.start, res.end, arg);
if (ret)
break;
res.start = res.end + 1;
res.end = orig_end;
}
return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
vivek goyal | vivek goyal | 134 | 97.81% | 1 | 33.33% |
toshi kani | toshi kani | 3 | 2.19% | 2 | 66.67% |
| Total | 137 | 100.00% | 3 | 100.00% |
#if !defined(CONFIG_ARCH_HAS_WALK_MEMORY)
/*
* This function calls the @func callback against all memory ranges of type
* System RAM which are marked as IORESOURCE_SYSTEM_RAM and IORESOUCE_BUSY.
* It is to be used only for System RAM.
*/
int walk_system_ram_range(unsigned long start_pfn, unsigned long nr_pages,
void *arg, int (*func)(unsigned long, unsigned long, void *))
{
struct resource res;
unsigned long pfn, end_pfn;
u64 orig_end;
int ret = -1;
res.start = (u64) start_pfn << PAGE_SHIFT;
res.end = ((u64)(start_pfn + nr_pages) << PAGE_SHIFT) - 1;
res.flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
orig_end = res.end;
while ((res.start < res.end) &&
(find_next_iomem_res(&res, IORES_DESC_NONE, true) >= 0)) {
pfn = (res.start + PAGE_SIZE - 1) >> PAGE_SHIFT;
end_pfn = (res.end + 1) >> PAGE_SHIFT;
if (end_pfn > pfn)
ret = (*func)(pfn, end_pfn - pfn, arg);
if (ret)
break;
res.start = res.end + 1;
res.end = orig_end;
}
return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
kamezawa hiroyuki | kamezawa hiroyuki | 172 | 87.76% | 2 | 28.57% |
fengguang wu | fengguang wu | 17 | 8.67% | 1 | 14.29% |
toshi kani | toshi kani | 3 | 1.53% | 2 | 28.57% |
vivek goyal | vivek goyal | 2 | 1.02% | 1 | 14.29% |
yasunori goto | yasunori goto | 2 | 1.02% | 1 | 14.29% |
| Total | 196 | 100.00% | 7 | 100.00% |
#endif
static int __is_ram(unsigned long pfn, unsigned long nr_pages, void *arg)
{
return 1;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
fengguang wu | fengguang wu | 21 | 100.00% | 1 | 100.00% |
| Total | 21 | 100.00% | 1 | 100.00% |
/*
* This generic page_is_ram() returns true if specified address is
* registered as System RAM in iomem_resource list.
*/
int __weak page_is_ram(unsigned long pfn)
{
return walk_system_ram_range(pfn, 1, NULL, __is_ram) == 1;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
fengguang wu | fengguang wu | 21 | 87.50% | 1 | 50.00% |
andrew morton | andrew morton | 3 | 12.50% | 1 | 50.00% |
| Total | 24 | 100.00% | 2 | 100.00% |
EXPORT_SYMBOL_GPL(page_is_ram);
/**
* region_intersects() - determine intersection of region with known resources
* @start: region start address
* @size: size of region
* @flags: flags of resource (in iomem_resource)
* @desc: descriptor of resource (in iomem_resource) or IORES_DESC_NONE
*
* Check if the specified region partially overlaps or fully eclipses a
* resource identified by @flags and @desc (optional with IORES_DESC_NONE).
* Return REGION_DISJOINT if the region does not overlap @flags/@desc,
* return REGION_MIXED if the region overlaps @flags/@desc and another
* resource, and return REGION_INTERSECTS if the region overlaps @flags/@desc
* and no other defined resource. Note that REGION_INTERSECTS is also
* returned in the case when the specified region overlaps RAM and undefined
* memory holes.
*
* region_intersect() is used by memory remapping functions to ensure
* the user is not remapping RAM and is a vast speed up over walking
* through the resource table page by page.
*/
int region_intersects(resource_size_t start, size_t size, unsigned long flags,
unsigned long desc)
{
resource_size_t end = start + size - 1;
int type = 0; int other = 0;
struct resource *p;
read_lock(&resource_lock);
for (p = iomem_resource.child; p ; p = p->sibling) {
bool is_type = (((p->flags & flags) == flags) &&
((desc == IORES_DESC_NONE) ||
(desc == p->desc)));
if (start >= p->start && start <= p->end)
is_type ? type++ : other++;
if (end >= p->start && end <= p->end)
is_type ? type++ : other++;
if (p->start >= start && p->end <= end)
is_type ? type++ : other++;
}
read_unlock(&resource_lock);
if (other == 0)
return type ? REGION_INTERSECTS : REGION_DISJOINT;
if (type)
return REGION_MIXED;
return REGION_DISJOINT;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
dan williams | dan williams | 87 | 44.62% | 1 | 20.00% |
mike travis | mike travis | 76 | 38.97% | 1 | 20.00% |
toshi kani | toshi kani | 32 | 16.41% | 3 | 60.00% |
| Total | 195 | 100.00% | 5 | 100.00% |
EXPORT_SYMBOL_GPL(region_intersects);
void __weak arch_remove_reservations(struct resource *avail)
{
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
bjorn helgaas | bjorn helgaas | 10 | 100.00% | 1 | 100.00% |
| Total | 10 | 100.00% | 1 | 100.00% |
static resource_size_t simple_align_resource(void *data,
const struct resource *avail,
resource_size_t size,
resource_size_t align)
{
return avail->start;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
bjorn helgaas | bjorn helgaas | 27 | 100.00% | 1 | 100.00% |
| Total | 27 | 100.00% | 1 | 100.00% |
static void resource_clip(struct resource *res, resource_size_t min,
resource_size_t max)
{
if (res->start < min)
res->start = min;
if (res->end > max)
res->end = max;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
bjorn helgaas | bjorn helgaas | 45 | 100.00% | 1 | 100.00% |
| Total | 45 | 100.00% | 1 | 100.00% |
/*
* Find empty slot in the resource tree with the given range and
* alignment constraints
*/
static int __find_resource(struct resource *root, struct resource *old,
struct resource *new,
resource_size_t size,
struct resource_constraint *constraint)
{
struct resource *this = root->child;
struct resource tmp = *new, avail, alloc;
tmp.start = root->start;
/*
* Skip past an allocated resource that starts at 0, since the assignment
* of this->start - 1 to tmp->end below would cause an underflow.
*/
if (this && this->start == root->start) {
tmp.start = (this == old) ? old->start : this->end + 1;
this = this->sibling;
}
for(;;) {
if (this)
tmp.end = (this == old) ? this->end : this->start - 1;
else
tmp.end = root->end;
if (tmp.end < tmp.start)
goto next;
resource_clip(&tmp, constraint->min, constraint->max);
arch_remove_reservations(&tmp);
/* Check for overflow after ALIGN() */
avail.start = ALIGN(tmp.start, constraint->align);
avail.end = tmp.end;
avail.flags = new->flags & ~IORESOURCE_UNSET;
if (avail.start >= tmp.start) {
alloc.flags = avail.flags;
alloc.start = constraint->alignf(constraint->alignf_data, &avail,
size, constraint->align);
alloc.end = alloc.start + size - 1;
if (resource_contains(&avail, &alloc)) {
new->start = alloc.start;
new->end = alloc.end;
return 0;
}
}
next: if (!this || this->end == root->end)
break;
if (this != old)
tmp.start = this->end + 1;
this = this->sibling;
}
return -EBUSY;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
pre-git | pre-git | 119 | 35.63% | 3 | 15.79% |
bjorn helgaas | bjorn helgaas | 79 | 23.65% | 7 | 36.84% |
ram pai | ram pai | 71 | 21.26% | 2 | 10.53% |
dominik brodowski | dominik brodowski | 31 | 9.28% | 2 | 10.53% |
andrew morton | andrew morton | 24 | 7.19% | 1 | 5.26% |
nick wilson | nick wilson | 4 | 1.20% | 1 | 5.26% |
ivan kokshaysky | ivan kokshaysky | 3 | 0.90% | 1 | 5.26% |
lennert buytenhek | lennert buytenhek | 2 | 0.60% | 1 | 5.26% |
greg kroah-hartman | greg kroah-hartman | 1 | 0.30% | 1 | 5.26% |
| Total | 334 | 100.00% | 19 | 100.00% |
/*
* Find empty slot in the resource tree given range and alignment.
*/
static int find_resource(struct resource *root, struct resource *new,
resource_size_t size,
struct resource_constraint *constraint)
{
return __find_resource(root, NULL, new, size, constraint);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
ram pai | ram pai | 38 | 100.00% | 1 | 100.00% |
| Total | 38 | 100.00% | 1 | 100.00% |
/**
* reallocate_resource - allocate a slot in the resource tree given range & alignment.
* The resource will be relocated if the new size cannot be reallocated in the
* current location.
*
* @root: root resource descriptor
* @old: resource descriptor desired by caller
* @newsize: new size of the resource descriptor
* @constraint: the size and alignment constraints to be met.
*/
static int reallocate_resource(struct resource *root, struct resource *old,
resource_size_t newsize,
struct resource_constraint *constraint)
{
int err=0;
struct resource new = *old;
struct resource *conflict;
write_lock(&resource_lock);
if ((err = __find_resource(root, old, &new, newsize, constraint)))
goto out;
if (resource_contains(&new, old)) {
old->start = new.start;
old->end = new.end;
goto out;
}
if (old->child) {
err = -EBUSY;
goto out;
}
if (resource_contains(old, &new)) {
old->start = new.start;
old->end = new.end;
} else {
__release_resource(old, true);
*old = new;
conflict = __request_resource(root, old);
BUG_ON(conflict);
}
out:
write_unlock(&resource_lock);
return err;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
ram pai | ram pai | 182 | 98.38% | 1 | 33.33% |
toshi kani | toshi kani | 2 | 1.08% | 1 | 33.33% |
daeseok youn | daeseok youn | 1 | 0.54% | 1 | 33.33% |
| Total | 185 | 100.00% | 3 | 100.00% |
/**
* allocate_resource - allocate empty slot in the resource tree given range & alignment.
* The resource will be reallocated with a new size if it was already allocated
* @root: root resource descriptor
* @new: resource descriptor desired by caller
* @size: requested resource region size
* @min: minimum boundary to allocate
* @max: maximum boundary to allocate
* @align: alignment requested, in bytes
* @alignf: alignment function, optional, called if not NULL
* @alignf_data: arbitrary data to pass to the @alignf function
*/
int allocate_resource(struct resource *root, struct resource *new,
resource_size_t size, resource_size_t min,
resource_size_t max, resource_size_t align,
resource_size_t (*alignf)(void *,
const struct resource *,
resource_size_t,
resource_size_t),
void *alignf_data)
{
int err;
struct resource_constraint constraint;
if (!alignf)
alignf = simple_align_resource;
constraint.min = min;
constraint.max = max;
constraint.align = align;
constraint.alignf = alignf;
constraint.alignf_data = alignf_data;
if ( new->parent ) {
/* resource is already allocated, try reallocating with
the new constraints */
return reallocate_resource(root, new, size, &constraint);
}
write_lock(&resource_lock);
err = find_resource(root, new, size, &constraint);
if (err >= 0 && __request_resource(root, new))
err = -EBUSY;
write_unlock(&resource_lock);
return err;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
pre-git | pre-git | 89 | 53.94% | 3 | 33.33% |
ram pai | ram pai | 58 | 35.15% | 1 | 11.11% |
bjorn helgaas | bjorn helgaas | 9 | 5.45% | 1 | 11.11% |
greg kroah-hartman | greg kroah-hartman | 6 | 3.64% | 1 | 11.11% |
dominik brodowski | dominik brodowski | 2 | 1.21% | 2 | 22.22% |
ivan kokshaysky | ivan kokshaysky | 1 | 0.61% | 1 | 11.11% |
| Total | 165 | 100.00% | 9 | 100.00% |
EXPORT_SYMBOL(allocate_resource);
/**
* lookup_resource - find an existing resource by a resource start address
* @root: root resource descriptor
* @start: resource start address
*
* Returns a pointer to the resource if found, NULL otherwise
*/
struct resource *lookup_resource(struct resource *root, resource_size_t start)
{
struct resource *res;
read_lock(&resource_lock);
for (res = root->child; res; res = res->sibling) {
if (res->start == start)
break;
}
read_unlock(&resource_lock);
return res;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
geert uytterhoeven | geert uytterhoeven | 62 | 100.00% | 1 | 100.00% |
| Total | 62 | 100.00% | 1 | 100.00% |
/*
* Insert a resource into the resource tree. If successful, return NULL,
* otherwise return the conflicting resource (compare to __request_resource())
*/
static struct resource * __insert_resource(struct resource *parent, struct resource *new)
{
struct resource *first, *next;
for (;; parent = first) {
first = __request_resource(parent, new);
if (!first)
return first;
if (first == parent)
return first;
if (WARN_ON(first == new)) /* duplicated insertion */
return first;
if ((first->start > new->start) || (first->end < new->end))
break;
if ((first->start == new->start) && (first->end == new->end))
break;
}
for (next = first; ; next = next->sibling) {
/* Partial overlap? Bad, and unfixable */
if (next->start < new->start || next->end > new->end)
return next;
if (!next->sibling)
break;
if (next->sibling->start > new->end)
break;
}
new->parent = parent;
new->sibling = next->sibling;
new->child = first;
next->sibling = NULL;
for (next = first; next; next = next->sibling)
next->parent = new;
if (parent->child == first) {
parent->child = new;
} else {
next = parent->child;
while (next->sibling != first)
next = next->sibling;
next->sibling = new;
}
return NULL;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
benjamin herrenschmidt | benjamin herrenschmidt | 164 | 60.07% | 1 | 16.67% |
linus torvalds | linus torvalds | 56 | 20.51% | 2 | 33.33% |
matthew wilcox | matthew wilcox | 39 | 14.29% | 1 | 16.67% |
huang shijie | huang shijie | 13 | 4.76% | 1 | 16.67% |
andrew morton | andrew morton | 1 | 0.37% | 1 | 16.67% |
| Total | 273 | 100.00% | 6 | 100.00% |
/**
* insert_resource_conflict - Inserts resource in the resource tree
* @parent: parent of the new resource
* @new: new resource to insert
*
* Returns 0 on success, conflict resource if the resource can't be inserted.
*
* This function is equivalent to request_resource_conflict when no conflict
* happens. If a conflict happens, and the conflicting resources
* entirely fit within the range of the new resource, then the new
* resource is inserted and the conflicting resources become children of
* the new resource.
*
* This function is intended for producers of resources, such as FW modules
* and bus drivers.
*/
struct resource *insert_resource_conflict(struct resource *parent, struct resource *new)
{
struct resource *conflict;
write_lock(&resource_lock);
conflict = __insert_resource(parent, new);
write_unlock(&resource_lock);
return conflict;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
linus torvalds | linus torvalds | 33 | 71.74% | 1 | 33.33% |
benjamin herrenschmidt | benjamin herrenschmidt | 7 | 15.22% | 1 | 33.33% |
bjorn helgaas | bjorn helgaas | 6 | 13.04% | 1 | 33.33% |
| Total | 46 | 100.00% | 3 | 100.00% |
/**
* insert_resource - Inserts a resource in the resource tree
* @parent: parent of the new resource
* @new: new resource to insert
*
* Returns 0 on success, -EBUSY if the resource can't be inserted.
*
* This function is intended for producers of resources, such as FW modules
* and bus drivers.
*/
int insert_resource(struct resource *parent, struct resource *new)
{
struct resource *conflict;
conflict = insert_resource_conflict(parent, new);
return conflict ? -EBUSY : 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
bjorn helgaas | bjorn helgaas | 30 | 81.08% | 1 | 33.33% |
linus torvalds | linus torvalds | 5 | 13.51% | 1 | 33.33% |
benjamin herrenschmidt | benjamin herrenschmidt | 2 | 5.41% | 1 | 33.33% |
| Total | 37 | 100.00% | 3 | 100.00% |
EXPORT_SYMBOL_GPL(insert_resource);
/**
* insert_resource_expand_to_fit - Insert a resource into the resource tree
* @root: root resource descriptor
* @new: new resource to insert
*
* Insert a resource into the resource tree, possibly expanding it in order
* to make it encompass any conflicting resources.
*/
void insert_resource_expand_to_fit(struct resource *root, struct resource *new)
{
if (new->parent)
return;
write_lock(&resource_lock);
for (;;) {
struct resource *conflict;
conflict = __insert_resource(root, new);
if (!conflict)
break;
if (conflict == root)
break;
/* Ok, expand resource to cover the conflict, then try again .. */
if (conflict->start < new->start)
new->start = conflict->start;
if (conflict->end > new->end)
new->end = conflict->end;
printk("Expanded resource %s due to conflict with %s\n", new->name, conflict->name);
}
write_unlock(&resource_lock);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
linus torvalds | linus torvalds | 118 | 100.00% | 1 | 100.00% |
| Total | 118 | 100.00% | 1 | 100.00% |
/**
* remove_resource - Remove a resource in the resource tree
* @old: resource to remove
*
* Returns 0 on success, -EINVAL if the resource is not valid.
*
* This function removes a resource previously inserted by insert_resource()
* or insert_resource_conflict(), and moves the children (if any) up to
* where they were before. insert_resource() and insert_resource_conflict()
* insert a new resource, and move any conflicting resources down to the
* children of the new resource.
*
* insert_resource(), insert_resource_conflict() and remove_resource() are
* intended for producers of resources, such as FW modules and bus drivers.
*/
int remove_resource(struct resource *old)
{
int retval;
write_lock(&resource_lock);
retval = __release_resource(old, false);
write_unlock(&resource_lock);
return retval;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
toshi kani | toshi kani | 37 | 100.00% | 1 | 100.00% |
| Total | 37 | 100.00% | 1 | 100.00% |
EXPORT_SYMBOL_GPL(remove_resource);
static int __adjust_resource(struct resource *res, resource_size_t start,
resource_size_t size)
{
struct resource *tmp, *parent = res->parent;
resource_size_t end = start + size - 1;
int result = -EBUSY;
if (!parent)
goto skip;
if ((start < parent->start) || (end > parent->end))
goto out;
if (res->sibling && (res->sibling->start <= end))
goto out;
tmp = parent->child;
if (tmp != res) {
while (tmp->sibling != res)
tmp = tmp->sibling;
if (start <= tmp->end)
goto out;
}
skip:
for (tmp = res->child; tmp; tmp = tmp->sibling)
if ((tmp->start < start) || (tmp->end > end))
goto out;
res->start = start;
res->end = end;
result = 0;
out:
return result;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
matthew wilcox | matthew wilcox | 137 | 71.73% | 1 | 25.00% |
yinghai lu | yinghai lu | 45 | 23.56% | 1 | 25.00% |
toshi kani | toshi kani | 6 | 3.14% | 1 | 25.00% |
greg kroah-hartman | greg kroah-hartman | 3 | 1.57% | 1 | 25.00% |
| Total | 191 | 100.00% | 4 | 100.00% |
/**
* adjust_resource - modify a resource's start and size
* @res: resource to modify
* @start: new start value
* @size: new size
*
* Given an existing resource, change its start and size to match the
* arguments. Returns 0 on success, -EBUSY if it can't fit.
* Existing children of the resource are assumed to be immutable.
*/
int adjust_resource(struct resource *res, resource_size_t start,
resource_size_t size)
{
int result;
write_lock(&resource_lock);
result = __adjust_resource(res, start, size);
write_unlock(&resource_lock);
return result;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
toshi kani | toshi kani | 35 | 77.78% | 1 | 50.00% |
matthew wilcox | matthew wilcox | 10 | 22.22% | 1 | 50.00% |
| Total | 45 | 100.00% | 2 | 100.00% |
EXPORT_SYMBOL(adjust_resource);
static void __init __reserve_region_with_split(struct resource *root,
resource_size_t start, resource_size_t end,
const char *name)
{
struct resource *parent = root;
struct resource *conflict;
struct resource *res = alloc_resource(GFP_ATOMIC);
struct resource *next_res = NULL;
if (!res)
return;
res->name = name;
res->start = start;
res->end = end;
res->flags = IORESOURCE_BUSY;
res->desc = IORES_DESC_NONE;
while (1) {
conflict = __request_resource(parent, res);
if (!conflict) {
if (!next_res)
break;
res = next_res;
next_res = NULL;
continue;
}
/* conflict covered whole area */
if (conflict->start <= res->start &&
conflict->end >= res->end) {
free_resource(res);
WARN_ON(next_res);
break;
}
/* failed, split and try again */
if (conflict->start > res->start) {
end = res->end;
res->end = conflict->start - 1;
if (conflict->end < end) {
next_res = alloc_resource(GFP_ATOMIC);
if (!next_res) {
free_resource(res);
break;
}
next_res->name = name;
next_res->start = conflict->end + 1;
next_res->end = end;
next_res->flags = IORESOURCE_BUSY;
next_res->desc = IORES_DESC_NONE;
}
} else {
res->start = conflict->end + 1;
}
}
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
yinghai lu | yinghai lu | 132 | 50.19% | 1 | 16.67% |
t makphaibulchoke | t makphaibulchoke | 113 | 42.97% | 1 | 16.67% |
toshi kani | toshi kani | 12 | 4.56% | 1 | 16.67% |
yasuaki ishimatsu | yasuaki ishimatsu | 4 | 1.52% | 1 | 16.67% |
ingo molnar | ingo molnar | 1 | 0.38% | 1 | 16.67% |
linus torvalds | linus torvalds | 1 | 0.38% | 1 | 16.67% |
| Total | 263 | 100.00% | 6 | 100.00% |
void __init reserve_region_with_split(struct resource *root,
resource_size_t start, resource_size_t end,
const char *name)
{
int abort = 0;
write_lock(&resource_lock);
if (root->start > start || root->end < end) {
pr_err("requested range [0x%llx-0x%llx] not in root %pr\n",
(unsigned long long)start, (unsigned long long)end,
root);
if (start > root->end || end < root->start)
abort = 1;
else {
if (end > root->end)
end = root->end;
if (start < root->start)
start = root->start;
pr_err("fixing request to [0x%llx-0x%llx]\n",
(unsigned long long)start,
(unsigned long long)end);
}
dump_stack();
}
if (!abort)
__reserve_region_with_split(root, start, end, name);
write_unlock(&resource_lock);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
octavian purdila | octavian purdila | 118 | 72.39% | 1 | 33.33% |
yinghai lu | yinghai lu | 44 | 26.99% | 1 | 33.33% |
paul mundt | paul mundt | 1 | 0.61% | 1 | 33.33% |
| Total | 163 | 100.00% | 3 | 100.00% |
/**
* resource_alignment - calculate resource's alignment
* @res: resource pointer
*
* Returns alignment on success, 0 (invalid alignment) on failure.
*/
resource_size_t resource_alignment(struct resource *res)
{
switch (res->flags & (IORESOURCE_SIZEALIGN | IORESOURCE_STARTALIGN)) {
case IORESOURCE_SIZEALIGN:
return resource_size(res);
case IORESOURCE_STARTALIGN:
return res->start;
default:
return 0;
}
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
ivan kokshaysky | ivan kokshaysky | 42 | 93.33% | 1 | 50.00% |
magnus damm | magnus damm | 3 | 6.67% | 1 | 50.00% |
| Total | 45 | 100.00% | 2 | 100.00% |
/*
* This is compatibility stuff for IO resources.
*
* Note how this, unlike the above, knows about
* the IO flag meanings (busy etc).
*
* request_region creates a new busy region.
*
* release_region releases a matching busy region.
*/
static DECLARE_WAIT_QUEUE_HEAD(muxed_resource_wait);
/**
* __request_region - create a new busy resource region
* @parent: parent resource descriptor
* @start: resource start address
* @n: resource region size
* @name: reserving caller's ID string
* @flags: IO resource flags
*/
struct resource * __request_region(struct resource *parent,
resource_size_t start, resource_size_t n,
const char *name, int flags)
{
DECLARE_WAITQUEUE(wait, current);
struct resource *res = alloc_resource(GFP_KERNEL);
if (!res)
return NULL;
res->name = name;
res->start = start;
res->end = start + n - 1;
write_lock(&resource_lock);
for (;;) {
struct resource *conflict;
res->flags = resource_type(parent) | resource_ext_type(parent);
res->flags |= IORESOURCE_BUSY | flags;
res->desc = parent->desc;
conflict = __request_resource(parent, res);
if (!conflict)
break;
if (conflict != parent) {
if (!(conflict->flags & IORESOURCE_BUSY)) {
parent = conflict;
continue;
}
}
if (conflict->flags & flags & IORESOURCE_MUXED) {
add_wait_queue(&muxed_resource_wait, &wait);
write_unlock(&resource_lock);
set_current_state(TASK_UNINTERRUPTIBLE);
schedule();
remove_wait_queue(&muxed_resource_wait, &wait);
write_lock(&resource_lock);
continue;
}
/* Uhhuh, that didn't work out.. */
free_resource(res);
res = NULL;
break;
}
write_unlock(&resource_lock);
return res;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
pre-git | pre-git | 117 | 50.21% | 5 | 33.33% |
alan cox | alan cox | 58 | 24.89% | 1 | 6.67% |
toshi kani | toshi kani | 29 | 12.45% | 3 | 20.00% |
bjorn helgaas | bjorn helgaas | 10 | 4.29% | 2 | 13.33% |
arjan van de ven | arjan van de ven | 9 | 3.86% | 1 | 6.67% |
simon guinot | simon guinot | 6 | 2.58% | 1 | 6.67% |
yasuaki ishimatsu | yasuaki ishimatsu | 2 | 0.86% | 1 | 6.67% |
greg kroah-hartman | greg kroah-hartman | 2 | 0.86% | 1 | 6.67% |
| Total | 233 | 100.00% | 15 | 100.00% |
EXPORT_SYMBOL(__request_region);
/**
* __release_region - release a previously reserved resource region
* @parent: parent resource descriptor
* @start: resource start address
* @n: resource region size
*
* The described resource region must match a currently busy region.
*/
void __release_region(struct resource *parent, resource_size_t start,
resource_size_t n)
{
struct resource **p;
resource_size_t end;
p = &parent->child;
end = start + n - 1;
write_lock(&resource_lock);
for (;;) {
struct resource *res = *p;
if (!res)
break;
if (res->start <= start && res->end >= end) {
if (!(res->flags & IORESOURCE_BUSY)) {
p = &res->child;
continue;
}
if (res->start != start || res->end != end)
break;
*p = res->sibling;
write_unlock(&resource_lock);
if (res->flags & IORESOURCE_MUXED)
wake_up(&muxed_resource_wait);
free_resource(res);
return;
}
p = &res->sibling;
}
write_unlock(&resource_lock);
printk(KERN_WARNING "Trying to free nonexistent resource "
"<%016llx-%016llx>\n", (unsigned long long)start,
(unsigned long long)end);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
pre-git | pre-git | 137 | 73.66% | 4 | 40.00% |
andrew morton | andrew morton | 18 | 9.68% | 1 | 10.00% |
greg kroah-hartman | greg kroah-hartman | 15 | 8.06% | 2 | 20.00% |
alan cox | alan cox | 14 | 7.53% | 1 | 10.00% |
cory watson | cory watson | 1 | 0.54% | 1 | 10.00% |
yasuaki ishimatsu | yasuaki ishimatsu | 1 | 0.54% | 1 | 10.00% |
| Total | 186 | 100.00% | 10 | 100.00% |
EXPORT_SYMBOL(__release_region);
#ifdef CONFIG_MEMORY_HOTREMOVE
/**
* release_mem_region_adjustable - release a previously reserved memory region
* @parent: parent resource descriptor
* @start: resource start address
* @size: resource region size
*
* This interface is intended for memory hot-delete. The requested region
* is released from a currently busy memory resource. The requested region
* must either match exactly or fit into a single busy resource entry. In
* the latter case, the remaining resource is adjusted accordingly.
* Existing children of the busy memory resource must be immutable in the
* request.
*
* Note:
* - Additional release conditions, such as overlapping region, can be
* supported after they are confirmed as valid cases.
* - When a busy memory resource gets split into two entries, the code
* assumes that all children remain in the lower address entry for
* simplicity. Enhance this logic when necessary.
*/
int release_mem_region_adjustable(struct resource *parent,
resource_size_t start, resource_size_t size)
{
struct resource **p;
struct resource *res;
struct resource *new_res;
resource_size_t end;
int ret = -EINVAL;
end = start + size - 1;
if ((start < parent->start) || (end > parent->end))
return ret;
/* The alloc_resource() result gets checked later */
new_res = alloc_resource(GFP_KERNEL);
p = &parent->child;
write_lock(&resource_lock);
while ((res = *p)) {
if (res->start >= end)
break;
/* look for the next resource if it does not fit into */
if (res->start > start || res->end < end) {
p = &res->sibling;
continue;
}
if (!(res->flags & IORESOURCE_MEM))
break;
if (!(res->flags & IORESOURCE_BUSY)) {
p = &res->child;
continue;
}
/* found the target resource; let's adjust accordingly */
if (res->start == start && res->end == end) {
/* free the whole entry */
*p = res->sibling;
free_resource(res);
ret = 0;
} else if (res->start == start && res->end != end) {
/* adjust the start */
ret = __adjust_resource(res, end + 1,
res->end - end);
} else if (res->start != start && res->end == end) {
/* adjust the end */
ret = __adjust_resource(res, res->start,
start - res->start);
} else {
/* split into two entries */
if (!new_res) {
ret = -ENOMEM;
break;
}
new_res->name = res->name;
new_res->start = end + 1;
new_res->end = res->end;
new_res->flags = res->flags;
new_res->desc = res->desc;
new_res->parent = res->parent;
new_res->sibling = res->sibling;
new_res->child = NULL;
ret = __adjust_resource(res, res->start,
start - res->start);
if (ret)
break;
res->sibling = new_res;
new_res = NULL;
}
break;
}
write_unlock(&resource_lock);
free_resource(new_res);
return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
toshi kani | toshi kani | 395 | 99.00% | 2 | 66.67% |
yasuaki ishimatsu | yasuaki ishimatsu | 4 | 1.00% | 1 | 33.33% |
| Total | 399 | 100.00% | 3 | 100.00% |
#endif /* CONFIG_MEMORY_HOTREMOVE */
/*
* Managed region resource
*/
static void devm_resource_release(struct device *dev, void *ptr)
{
struct resource **r = ptr;
release_resource(*r);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
thierry reding | thierry reding | 29 | 100.00% | 1 | 100.00% |
| Total | 29 | 100.00% | 1 | 100.00% |
/**
* devm_request_resource() - request and reserve an I/O or memory resource
* @dev: device for which to request the resource
* @root: root of the resource tree from which to request the resource
* @new: descriptor of the resource to request
*
* This is a device-managed version of request_resource(). There is usually
* no need to release resources requested by this function explicitly since
* that will be taken care of when the device is unbound from its driver.
* If for some reason the resource needs to be released explicitly, because
* of ordering issues for example, drivers must call devm_release_resource()
* rather than the regular release_resource().
*
* When a conflict is detected between any existing resources and the newly
* requested resource, an error message will be printed.
*
* Returns 0 on success or a negative error code on failure.
*/
int devm_request_resource(struct device *dev, struct resource *root,
struct resource *new)
{
struct resource *conflict, **ptr;
ptr = devres_alloc(devm_resource_release, sizeof(*ptr), GFP_KERNEL);
if (!ptr)
return -ENOMEM;
*ptr = new;
conflict = request_resource_conflict(root, new);
if (conflict) {
dev_err(dev, "resource collision: %pR conflicts with %s %pR\n",
new, conflict->name, conflict);
devres_free(ptr);
return -EBUSY;
}
devres_add(dev, ptr);
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
thierry reding | thierry reding | 107 | 100.00% | 1 | 100.00% |
| Total | 107 | 100.00% | 1 | 100.00% |
EXPORT_SYMBOL(devm_request_resource);
static int devm_resource_match(struct device *dev, void *res, void *data)
{
struct resource **ptr = res;
return *ptr == data;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
thierry reding | thierry reding | 33 | 100.00% | 1 | 100.00% |
| Total | 33 | 100.00% | 1 | 100.00% |
/**
* devm_release_resource() - release a previously requested resource
* @dev: device for which to release the resource
* @new: descriptor of the resource to release
*
* Releases a resource previously requested using devm_request_resource().
*/
void devm_release_resource(struct device *dev, struct resource *new)
{
WARN_ON(devres_release(dev, devm_resource_release, devm_resource_match,
new));
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
thierry reding | thierry reding | 29 | 100.00% | 1 | 100.00% |
| Total | 29 | 100.00% | 1 | 100.00% |
EXPORT_SYMBOL(devm_release_resource);
struct region_devres {
struct resource *parent;
resource_size_t start;
resource_size_t n;
};
static void devm_region_release(struct device *dev, void *res)
{
struct region_devres *this = res;
__release_region(this->parent, this->start, this->n);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
tejun heo | tejun heo | 37 | 100.00% | 1 | 100.00% |
| Total | 37 | 100.00% | 1 | 100.00% |
static int devm_region_match(struct device *dev, void *res, void *match_data)
{
struct region_devres *this = res, *match = match_data;
return this->parent == match->parent &&
this->start == match->start && this->n == match->n;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
tejun heo | tejun heo | 56 | 100.00% | 1 | 100.00% |
| Total | 56 | 100.00% | 1 | 100.00% |
struct resource * __devm_request_region(struct device *dev,
struct resource *parent, resource_size_t start,
resource_size_t n, const char *name)
{
struct region_devres *dr = NULL;
struct resource *res;
dr = devres_alloc(devm_region_release, sizeof(struct region_devres),
GFP_KERNEL);
if (!dr)
return NULL;
dr->parent = parent;
dr->start = start;
dr->n = n;
res = __request_region(parent, start, n, name, 0);
if (res)
devres_add(dev, dr);
else
devres_free(dr);
return res;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
tejun heo | tejun heo | 114 | 98.28% | 1 | 50.00% |
arjan van de ven | arjan van de ven | 2 | 1.72% | 1 | 50.00% |
| Total | 116 | 100.00% | 2 | 100.00% |
EXPORT_SYMBOL(__devm_request_region);
void __devm_release_region(struct device *dev, struct resource *parent,
resource_size_t start, resource_size_t n)
{
struct region_devres match_data = { parent, start, n };
__release_region(parent, start, n);
WARN_ON(devres_destroy(dev, devm_region_release, devm_region_match,
&match_data));
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
tejun heo | tejun heo | 57 | 100.00% | 1 | 100.00% |
| Total | 57 | 100.00% | 1 | 100.00% |
EXPORT_SYMBOL(__devm_release_region);
/*
* Called from init/main.c to reserve IO ports.
*/
#define MAXRESERVE 4
static int __init reserve_setup(char *str)
{
static int reserved;
static struct resource reserve[MAXRESERVE];
for (;;) {
unsigned int io_start, io_num;
int x = reserved;
if (get_option (&str, &io_start) != 2)
break;
if (get_option (&str, &io_num) == 0)
break;
if (x < MAXRESERVE) {
struct resource *res = reserve + x;
res->name = "reserved";
res->start = io_start;
res->end = io_start + io_num - 1;
res->flags = IORESOURCE_BUSY;
res->desc = IORES_DESC_NONE;
res->child = NULL;
if (request_resource(res->start >= 0x10000 ? &iomem_resource : &ioport_resource, res) == 0)
reserved = x+1;
}
}
return 1;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
pre-git | pre-git | 133 | 85.26% | 7 | 70.00% |
linus torvalds | linus torvalds | 16 | 10.26% | 1 | 10.00% |
toshi kani | toshi kani | 6 | 3.85% | 1 | 10.00% |
rui zhang | rui zhang | 1 | 0.64% | 1 | 10.00% |
| Total | 156 | 100.00% | 10 | 100.00% |
__setup("reserve=", reserve_setup);
/*
* Check if the requested addr and size spans more than any slot in the
* iomem resource tree.
*/
int iomem_map_sanity_check(resource_size_t addr, unsigned long size)
{
struct resource *p = &iomem_resource;
int err = 0;
loff_t l;
read_lock(&resource_lock);
for (p = p->child; p ; p = r_next(NULL, p, &l)) {
/*
* We can probably skip the resources without
* IORESOURCE_IO attribute?
*/
if (p->start >= addr + size)
continue;
if (p->end < addr)
continue;
if (PFN_DOWN(p->start) <= PFN_DOWN(addr) &&
PFN_DOWN(p->end) >= PFN_DOWN(addr + size - 1))
continue;
/*
* if a resource is "BUSY", it's not a hardware resource
* but a driver mapping of such a resource; we don't want
* to warn for those; some drivers legitimately map only
* partial hardware resources. (example: vesafb)
*/
if (p->flags & IORESOURCE_BUSY)
continue;
printk(KERN_WARNING "resource sanity check: requesting [mem %#010llx-%#010llx], which spans more than %s %pR\n",
(unsigned long long)addr,
(unsigned long long)(addr + size - 1),
p->name, p);
err = -1;
break;
}
read_unlock(&resource_lock);
return err;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
suresh siddha | suresh siddha | 143 | 85.63% | 2 | 40.00% |
ingo molnar | ingo molnar | 12 | 7.19% | 1 | 20.00% |
arjan van de ven | arjan van de ven | 10 | 5.99% | 1 | 20.00% |
bjorn helgaas | bjorn helgaas | 2 | 1.20% | 1 | 20.00% |
| Total | 167 | 100.00% | 5 | 100.00% |
#ifdef CONFIG_STRICT_DEVMEM
static int strict_iomem_checks = 1;
#else
static int strict_iomem_checks;
#endif
/*
* check if an address is reserved in the iomem resource tree
* returns 1 if reserved, 0 if not reserved.
*/
int iomem_is_exclusive(u64 addr)
{
struct resource *p = &iomem_resource;
int err = 0;
loff_t l;
int size = PAGE_SIZE;
if (!strict_iomem_checks)
return 0;
addr = addr & PAGE_MASK;
read_lock(&resource_lock);
for (p = p->child; p ; p = r_next(NULL, p, &l)) {
/*
* We can probably skip the resources without
* IORESOURCE_IO attribute?
*/
if (p->start >= addr + size)
break;
if (p->end < addr)
continue;
/*
* A resource is exclusive if IORESOURCE_EXCLUSIVE is set
* or CONFIG_IO_STRICT_DEVMEM is enabled and the
* resource is busy.
*/
if ((p->flags & IORESOURCE_BUSY) == 0)
continue;
if (IS_ENABLED(CONFIG_IO_STRICT_DEVMEM)
|| p->flags & IORESOURCE_EXCLUSIVE) {
err = 1;
break;
}
}
read_unlock(&resource_lock);
return err;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
arjan van de ven | arjan van de ven | 123 | 89.78% | 1 | 50.00% |
dan williams | dan williams | 14 | 10.22% | 1 | 50.00% |
| Total | 137 | 100.00% | 2 | 100.00% |
struct resource_entry *resource_list_create_entry(struct resource *res,
size_t extra_size)
{
struct resource_entry *entry;
entry = kzalloc(sizeof(*entry) + extra_size, GFP_KERNEL);
if (entry) {
INIT_LIST_HEAD(&entry->node);
entry->res = res ? res : &entry->__res;
}
return entry;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
jiang liu | jiang liu | 65 | 100.00% | 1 | 100.00% |
| Total | 65 | 100.00% | 1 | 100.00% |
EXPORT_SYMBOL(resource_list_create_entry);
void resource_list_free(struct list_head *head)
{
struct resource_entry *entry, *tmp;
list_for_each_entry_safe(entry, tmp, head, node)
resource_list_destroy_entry(entry);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
jiang liu | jiang liu | 33 | 100.00% | 1 | 100.00% |
| Total | 33 | 100.00% | 1 | 100.00% |
EXPORT_SYMBOL(resource_list_free);
static int __init strict_iomem(char *str)
{
if (strstr(str, "relaxed"))
strict_iomem_checks = 0;
if (strstr(str, "strict"))
strict_iomem_checks = 1;
return 1;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
arjan van de ven | arjan van de ven | 40 | 100.00% | 1 | 100.00% |
| Total | 40 | 100.00% | 1 | 100.00% |
__setup("iomem=", strict_iomem);
Overall Contributors
| Person | Tokens | Prop | Commits | CommitProp |
pre-git | pre-git | 1004 | 15.36% | 19 | 15.57% |
toshi kani | toshi kani | 787 | 12.04% | 12 | 9.84% |
ram pai | ram pai | 388 | 5.94% | 2 | 1.64% |
yinghai lu | yinghai lu | 345 | 5.28% | 3 | 2.46% |
kamezawa hiroyuki | kamezawa hiroyuki | 337 | 5.16% | 5 | 4.10% |
tejun heo | tejun heo | 294 | 4.50% | 1 | 0.82% |
linus torvalds | linus torvalds | 283 | 4.33% | 7 | 5.74% |
vivek goyal | vivek goyal | 279 | 4.27% | 2 | 1.64% |
al viro | al viro | 274 | 4.19% | 1 | 0.82% |
bjorn helgaas | bjorn helgaas | 256 | 3.92% | 12 | 9.84% |
thierry reding | thierry reding | 210 | 3.21% | 1 | 0.82% |
arjan van de ven | arjan van de ven | 209 | 3.20% | 2 | 1.64% |
matthew wilcox | matthew wilcox | 186 | 2.85% | 2 | 1.64% |
benjamin herrenschmidt | benjamin herrenschmidt | 173 | 2.65% | 1 | 0.82% |
yasuaki ishimatsu | yasuaki ishimatsu | 167 | 2.56% | 1 | 0.82% |
randy dunlap | randy dunlap | 161 | 2.46% | 4 | 3.28% |
suresh siddha | suresh siddha | 147 | 2.25% | 2 | 1.64% |
octavian purdila | octavian purdila | 125 | 1.91% | 1 | 0.82% |
t makphaibulchoke | t makphaibulchoke | 113 | 1.73% | 1 | 0.82% |
jiang liu | jiang liu | 111 | 1.70% | 1 | 0.82% |
dan williams | dan williams | 101 | 1.55% | 2 | 1.64% |
alan cox | alan cox | 81 | 1.24% | 1 | 0.82% |
mike travis | mike travis | 76 | 1.16% | 1 | 0.82% |
geert uytterhoeven | geert uytterhoeven | 63 | 0.96% | 1 | 0.82% |
fengguang wu | fengguang wu | 59 | 0.90% | 2 | 1.64% |
ivan kokshaysky | ivan kokshaysky | 47 | 0.72% | 2 | 1.64% |
andrew morton | andrew morton | 46 | 0.70% | 4 | 3.28% |
arnaldo carvalho de melo | arnaldo carvalho de melo | 37 | 0.57% | 1 | 0.82% |
greg kroah-hartman | greg kroah-hartman | 34 | 0.52% | 3 | 2.46% |
dominik brodowski | dominik brodowski | 33 | 0.50% | 3 | 2.46% |
art haas | art haas | 26 | 0.40% | 1 | 0.82% |
ingo molnar | ingo molnar | 23 | 0.35% | 2 | 1.64% |
huang shijie | huang shijie | 13 | 0.20% | 1 | 0.82% |
simon guinot | simon guinot | 6 | 0.09% | 1 | 0.82% |
denis v. lunev | denis v. lunev | 6 | 0.09% | 1 | 0.82% |
americo wang | americo wang | 5 | 0.08% | 1 | 0.82% |
gong chen | gong chen | 5 | 0.08% | 1 | 0.82% |
nick wilson | nick wilson | 4 | 0.06% | 1 | 0.82% |
thomas gleixner | thomas gleixner | 4 | 0.06% | 1 | 0.82% |
helge deller | helge deller | 3 | 0.05% | 1 | 0.82% |
magnus damm | magnus damm | 3 | 0.05% | 1 | 0.82% |
lennert buytenhek | lennert buytenhek | 2 | 0.03% | 1 | 0.82% |
yasunori goto | yasunori goto | 2 | 0.03% | 1 | 0.82% |
adrian bunk | adrian bunk | 1 | 0.02% | 1 | 0.82% |
paul mundt | paul mundt | 1 | 0.02% | 1 | 0.82% |
jakub sitnicki | jakub sitnicki | 1 | 0.02% | 1 | 0.82% |
daeseok youn | daeseok youn | 1 | 0.02% | 1 | 0.82% |
paul gortmaker | paul gortmaker | 1 | 0.02% | 1 | 0.82% |
cory watson | cory watson | 1 | 0.02% | 1 | 0.82% |
rui zhang | rui zhang | 1 | 0.02% | 1 | 0.82% |
wei yang | wei yang | 1 | 0.02% | 1 | 0.82% |
| Total | 6536 | 100.00% | 122 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.