我正在使用一个使用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>;
}
这里编码器@ 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";
};
这会有用吗?我不确定驱动程序代码如何知道已雕刻的内存的起始地址和大小? 有人可以帮忙吗? 谢谢。
答案 0 :(得分:0)
我通过从我的设备的高内存下部创建内存来实现这一点。为此,我修改了我的dtsi文件,以反映下面的mew内存映射:
/* 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*/