【问题标题】:Allocating boot time memory using dts configuration使用 dts 配置分配启动时内存
【发布时间】:2017-11-11 09:40:41
【问题描述】:

我正在使用一个特定的编码器,它使用 512M 启动时间分配的内存。我应该通过 dts 文件配置来分配内存。物理内存在dts文件中分为低位和高位:

    /* 256MB at 0x0 */
    memory@0 {
            device_type = "memory";
            reg =  <0x0 0x00000000 0x0 0x10000000>;
    };

    /* 2GB at 0x8010000000 */
    memory@8000000000 {
            device_type = "memory";
            reg =  <0x80 0x10000000 0x0 0x80000000>;
    };

现在我想分配启动时间从高内存中挖出的内存。我可以考虑如下创建一个 dts 条目

encoder: encoder@0xxxxxxxxx {
    compatible = "xyz, abc";
    reg=    <0x0 0x80000000 0x0 0x20000000>;
}  

这里的encoder@xxxx是实际的设备入口,它已经有一组寄存器区域如下:

    encoder: encoder@0xxxxxxxxx{
        compatible = "xyz, abc";
        #address-cells = <1>;
        #size-cells = <1>;
        reg = <0x0 0xxxxxxxxxx 0x0 0x1234>;
        status = "disabled";
    };

所以在添加雕刻内存后,条目将如下所示:

    encoder: encoder@0xxxxxxxxx{
        compatible = "xyz, abc";
        #address-cells = <1>;
        #size-cells = <1>;
        reg = <0x0 0xxxxxxxxxx 0x0 0x1234>;
        reg=  <0x0 0x80000000 0x0 0x20000000>;
        status = "disabled";
    };

这行得通吗?我不确定驱动程序代码如何知道雕刻内存的起始地址及其大小? 有人可以帮忙吗?
谢谢。

【问题讨论】:

    标签: memory kernel driver dts


    【解决方案1】:

    我通过从我的设备的高内存的下部创建弯曲内存来实现这一点。为此,我修改了我的 dtsi 文件以反映新的内存映射,如下所示:

    /* 256MB at 0x0 - this is the low memory region*/
            memory@0 {
                    device_type = "memory";
                    reg =  <0x0 0x00000000 0x0 0x10000000>;
            };
    
            /* 1GB at 0x8010000000 - high memory region, this used to be 2GB earlier. I curved out to 1GB and allocated 1GB to my device*/
            memory@8000000000 {
                    device_type = "memory";
                    reg =  <0x80 0x10000000 0x0 0x40000000>;
            };
    
    
    
    /* 1GB carved out for my device.*/
            my_device: mydevice@8050000000 {
                    compatible = "xxx,xxx-yyy";
                    reg = <0x00 0x20810000 0x0 0x010000>,
                          **<0x80 0x50000000 0x0 0x40000000>;**
                    interrupts = <GIC_SHARED xx IRQ_TYPE_LEVEL_HIGH>;
                    status = "disabled";
            };
    

    1GB 的分配有点过多,我已将其修改为 256MB,但这并不重要。

    然后在驱动程序中我重试了内存详细信息,如下所示:

    struct resource *res;
    res = platform_get_resource(pdev, IORESOURCE_MEM, 0); /*this is to get hold of the the registers of my device*/
    
    res = platform_get_resource(pdev, IORESOURCE_MEM, 1); /* this is the device memory for my device which had been set aside in the dtsi file above.*/
    
    For using the memories retrieve as above use the below:
    
    res->start /* start address of the memory region */
    res->end - res->start + 1 /* this is to calculate the size of the memory*/
    devm_ioremap_resource(&pdev->dev, res); /* this will give the mapped kernel virtual address for the memory bank*/
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-06
      • 2018-01-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多