PCI子系统之-resource插入算法

来源:互联网 发布:丁红玉的淘宝店 编辑:程序博客网 时间:2024/06/07 13:46
/*
 * 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;

}

==============================

struct resource {
    resource_size_t start;
    resource_size_t end;
    const char *name;
    unsigned long flags;
    struct resource *parent, *sibling, *child;
};


http://blog.chinaunix.net/uid/10678279/cid-138364-list-1.html


原创粉丝点击