2017-06-09 114 views
0

我正在使用512M啓動時間分配內存的特定編碼器。我應該通過dts文件配置分配內存。物理內存分爲低和高爲下文DTS文件:使用dts配置分配啓動時間內存

/* 256MB at 0x0 */ 
    [email protected] { 
      device_type = "memory"; 
      reg = <0x0 0x00000000 0x0 0x10000000>; 
    }; 

    /* 2GB at 0x8010000000 */ 
    [email protected] { 
      device_type = "memory"; 
      reg = <0x80 0x10000000 0x0 0x80000000>; 
    }; 

現在我想從分配高端內存劃分出內存的啓動時間。我能想到創建一個DTS條目下面

encoder: [email protected] { 
    compatible = "xyz, abc"; 
    reg= <0x0 0x80000000 0x0 0x20000000>; 
} 

這裏編碼器@ xxxx是實際的設備條目,並且它已經下面一組寄存器區域:

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

所以加入後分隔內存條目看起來像這樣:

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

這項工作?我不確定驅動程序代碼是如何知道內存的起始地址和內存大小的? 任何人都可以請幫忙嗎?
謝謝。

回答

0

我已經實現了這一點,從我的設備的高端內存的下半部分創建彎曲的內存。要做到這一點,我修改了我的DTSI文件,以反映如下的巢內存映射:

/* 256MB at 0x0 - this is the low memory region*/ 
     [email protected] { 
       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*/ 
     [email protected] { 
       device_type = "memory"; 
       reg = <0x80 0x10000000 0x0 0x40000000>; 
     }; 



/* 1GB carved out for my device.*/ 
     my_device: [email protected] { 
       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*/