设备树中ranges属性理解[通俗易懂]

设备树中ranges属性理解[通俗易懂]作者彭东林pengdonglin137@163.com文章来源http://www.cnblogs.com/pengdonglin137/p/7401049.html正文一、设备树下面是我们将要实验的设备树的例子:/{#address-cells=<1>;#size-cells=<1&g…

大家好,又见面了,我是你们的朋友全栈君。

作者

彭东林
pengdonglin137@163.com

文章来源

http://www.cnblogs.com/pengdonglin137/p/7401049.html

正文

一、设备树
  • 下面是我们将要实验的设备树的例子:
/ {
    #address-cells = <1>;
    #size-cells = <1>;

    demo_level0 {
        compatible = "simple-bus";
        ranges = <0x0 0x3000000 0x3000>;
        #address-cells = <1>;
        #size-cells = <1>;

        range@0 {
            compatible = "range";
            reg = <0x100 0x200>;
            reg-names = "range0";
        };

        range@1 {
            compatible = "range";
            reg = <0x300 0x200>;
            reg-names = "range1";
        };

        range@2 {
            compatible = "range";
            reg = <0x600 0x200>;
            reg-names = "range2";
        };

        demo_level1 {
            compatible = "simple-bus";
            ranges = <0x0 0x1000 0x1000>;
            #address-cells = <1>;
            #size-cells = <1>;

            range@3 {
                compatible = "range";
                reg = <0x100 0x200>;
                reg-names = "range3";
            };

            demo_level1-1 {
                compatible = "simple-bus";
                ranges = <0x0 0x300 0x500>;
                #address-cells = <1>;
                #size-cells = <1>;

                range@4 {
                    compatible = "range";
                    reg = <0x100 0x200>;
                    reg-names = "range4";
                };

                range@5 {
                    compatible = "range";
                    reg = <0x300 0x100>;
                    reg-names = "range5";
                };

                demo_level1-1-1 {
                    compatible = "simple-bus";
                    ranges = <0x0 0x400 0x100>;
                    #address-cells = <1>;
                    #size-cells = <1>;

                    range@6 {
                        compatible = "range";
                        reg = <0x50 0x30>;
                        reg-names = "range6";
                    };

                    demo_level1-1-1-1 {
                        compatible = "simple-bus";
                        ranges = <0x0 0x20 0x20>;
                        #address-cells = <1>;
                        #size-cells = <1>;

                        range@7 {
                            compatible = "range";
                            reg = <0x10 0x10>;
                            reg-names = "range7";
                        };

                        range@8 {
                            compatible = "range";
                            reg = <0x0 0x10>;
                            reg-names = "range8";
                        };
                    };
                };
            };

            range@9 {
                compatible = "range";
                reg = <0x800 0x50>;
                reg-names = "range9";
            };

            demo_level1-2 {
                compatible = "simple-bus";
                ranges = <0x0 0x900 0x100>;
                #address-cells = <1>;
                #size-cells = <1>;

                range@10 {
                    compatible = "range";
                    reg = <0x0 0x50>;
                    reg-names = "range10";
                };

                demo_level1-2-1 {
                    compatible = "simple-bus";
                    ranges;
                    #address-cells = <1>;
                    #size-cells = <1>;

                    range@11 {
                        compatible = "range";
                        reg = <0x50 0x30>;
                        reg-names = "range11";
                    };
                };
            };
        };

        demo_level2 {
            compatible = "simple-bus";
            ranges;
            #address-cells = <1>;
            #size-cells = <1>;

            range@12 {
                compatible = "range";
                reg = <0x2000 0x1000>;
                reg-names = "range12";
            };
        };
    }
};
二、驱动
  • 下面是一个简单的驱动,功能很简单,只是在probe函数中将memory资源的start和(end+1)打印出来.
demo_range.c:

#include <linux/init.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/of.h>

static int demo_range_probe(struct platform_device *pdev)
{
    struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);

    printk(KERN_INFO "%s start: 0x%x, end: 0x%x\n",
        res->name, res->start, res->end + 1);

    return 0;
}

static int demo_range_remove(struct platform_device *pdev)
{
    return 0;
}

static const struct of_device_id demo_range_of_match[]  = {
    { .compatible = "range"},
    {},
};

static struct platform_driver demo_range_driver = {
    .driver = {
        .name = "demo_range",
        .owner = THIS_MODULE,
        .of_match_table = demo_range_of_match,
    },
    .probe = demo_range_probe,
    .remove = demo_range_remove,
};
module_platform_driver(demo_range_driver);

MODULE_LICENSE("GPL v2");
  • 在驱动中会获得memory资源,然后将start和(end+1)打印出来,之所以这里用(end+1),仅仅是为了便于理解下面的kernel log。
三、验证
  • 编译驱动,然后加载,可以看到下面的打印信息:
[root@vexpress mnt]# insmod demo_range.ko 
[ 382.940402] range0 start: 0x3000100, end: 0x3000300
[ 382.940697] range1 start: 0x3000300, end: 0x3000500
[ 382.941448] range2 start: 0x3000600, end: 0x3000800
[ 382.941657] range3 start: 0x3001100, end: 0x3001300
[ 382.941855] range4 start: 0x3001400, end: 0x3001600
[ 382.942057] range5 start: 0x3001600, end: 0x3001700
[ 382.942262] range6 start: 0x3001750, end: 0x3001780
[ 382.942470] range7 start: 0x3001730, end: 0x3001740
[ 382.942684] range8 start: 0x3001720, end: 0x3001730
[ 382.949796] range9 start: 0x3001800, end: 0x3001850
[ 382.950023] range10 start: 0x3001900, end: 0x3001950
[ 382.950603] range11 start: 0x3001950, end: 0x3001980
[ 382.950805] range12 start: 0x3002000, end: 0x3003000
总结:
  • 1、ranges属性值的格式
四、示意图
  • 对照上面的log理解下面的框图
    image
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/151116.html原文链接:https://javaforall.net

赞 (0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 架构方案(16) 常见分布式文件存储介绍、选型比较、以及架构设计

    架构方案(16) 常见分布式文件存储介绍、选型比较、以及架构设计数据正成为世界上最有价值的资源,分布式文件存储是应对数据爆炸的最好解决方案,那就会涉及到分布式文件存储方案、选型、架构设计等。分布式文件存储的来源在这个数据爆炸的时代,产生的数据量不断地在攀升,从GB,TB,PB,ZB.挖掘其中数据的价值也是企业在不断地追求的终极目标。但是要想对海量的数据进行挖掘,首先要考虑的就是海量数据的存储问题,比如Tb量级的数据。谈到数据的存储,则不得不说的是磁盘…

    2022年5月1日
  • 到底如何区分什么是架构,框架,模式和平台_整体架构是什么意思

    到底如何区分什么是架构,框架,模式和平台_整体架构是什么意思区分什么是架构、框架、模式和平台,一直都感觉这几个词过于抽象和模糊,今天大家来说说到底什么是架构、框架、模式和平台?收集了的一些来自网上各自的定义和区分如下:来自冬眠的蛤蟆概念:设计模式<框架<架构<平台,从复用角度讲,设计模式是代码级复用、框架是模块级复用、架构是系统级复用、平台是企业应用级复用。

    2022年10月18日
  • XRDP与VNC的关系

    XRDP与VNC的关系

    2022年2月3日
  • 模板语法[通俗易懂]

    什么是模板模板语法分类模板语法之变量语法为{{}}:在Django模板中遍历复杂数据结构的关键是句点字符.(也就是点)views.pytemplate/index.html注意

    2022年3月29日
  • 那些错过的人和事,已成回忆

    哪些曾经没有做的事情,你现在还想做吗?你现在还能做吗?最近的一些梦,让我思考哪些我当时有机会做,但是最后没有做的事情!现在回忆起来,略有遗憾,也在感慨时间的力量,推着我一直向前,我已经不再是过去的那个我了。我记得小的时候,那会上小学,在学校外面的有个老奶奶开的小卖铺,那个小卖铺里面是用木头搭建的房子,屋顶上面用的是茅草铺的。小卖铺里面卖着一种一毛钱一片的辣条(片),本来这种辣条(片…

    2022年2月27日

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号