Linux内核:CMA&设备树

时间:2015-02-26 23:47:27

标签: linux kernel kernel-module device-tree

我尝试使用配置了DT的CMA(Contiguous Memory Allocator)。但是如何从模块中访问分配的内存区域?

这是DT部分:

reserved-memory {
    #address-cells = <1>;
    #size-cells = <1>;
    ranges;

    dsp_reserved: dsp@83400000 {
        reg = <0x83400000 0x400000>;
        no-map;
    };
};

c64_dsp {
    compatible = "c64-dsp";
    interrupt-parent = <&intc>;
    interrupts = <26>;
    memory-region = <&dsp_reserved>;
};

如何在自己的驱动程序中获取保留的内存区域“dsp_reserved”?该区域是否已由“dma_alloc_coherent”请求?是否有类似“platform_get_irq”的函数?

感谢您的帮助, 斯文

1 个答案:

答案 0 :(得分:1)

我找到了一个解决方案(在probe()函数中调用):

memory = of_parse_phandle(dev->of_node, "memory-region", 0);
if (!memory) {
    return -ENODEV;
}

addr = of_translate_address(memory,
             of_get_address(memory, 0, &memory_size, NULL));

virt_addr = phys_to_virt(addr);