zoukankan      html  css  js  c++  java
  • request_resource

    1.全局变量

    resource结构体定义如下,指针parent、sibling、child用于构建树状结构。

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

    用到的全局变量

    /arch/arm/kernel/setup.c/
    static struct resource mem_res[] = {
        {
            .name = "Video RAM",
            .start = 0,
            .end = 0,
            .flags = IORESOURCE_MEM
        },
        {
            .name = "Kernel text",
            .start = 0,
            .end = 0,
            .flags = IORESOURCE_MEM
        },
        {
            .name = "Kernel data",
            .start = 0,
            .end = 0,
            .flags = IORESOURCE_MEM
        }
    };
    
    #define video_ram   mem_res[0]
    #define kernel_code mem_res[1]
    #define kernel_data mem_res[2]

    2.request_resource()

    int request_resource(struct resource *root, struct resource *new)
        -->__request_resource(root, new);//按地址升序排列
    /* 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;
        }
    }
  • 相关阅读:
    IDEA 工具使用报错总结
    Struts2 值栈总结(ValueStack)
    hibernate 中映射关系配置
    Java 注解之总结
    ssh_整合总结
    Ajax 请求之_请求类型详解
    C++的重载赋值运算符
    vector容器使用reserve预留空间
    C++中的内存分配
    C++ const修饰指针
  • 原文地址:https://www.cnblogs.com/yangjiguang/p/9490389.html
Copyright © 2011-2022 走看看