我需要保留大约 3 或 4 个内存区域供单个设备驱动程序使用。
我遵循了 Xilinx 的指南。适用于单个内存区域。
设备树如下所示:
reserved-memory {
#address-cells = <2>;
#size-cells = <2>;
ranges;
reserved_m1: buffer1@60000000 {
compatible = "shared-dma-pool";
no-map;
reg = <0x0 0x60000000 0x0 0x00400000>;
};
reserved_m2: buffer2@80000000 {
compatible = "shared-dma-pool";
no-map;
reg = <0x0 0x80000000 0x0 0x00400000>;
};
};
my_driver@0 {
compatible = "dummy,my_driver";
status = "okay";
memory-region = <&reserved_m1>, <&reserved_m2>;
};
以及“my_driver”中的我的探测功能
static int my_driver_probe(struct platform_device *pdev)
{
...
rc = of_reserved_mem_device_init(&pdev->dev);
debug = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
v_addr = dma_alloc_coherent(&pdev->dev, MY_MEM_SIZE, &paddr, GFP_KERNEL);
printk("Allocated coherent memory Size: %d MB, vaddr: 0x%0llX paddr: 0x%0llX\n", MY_MEM_SIZE / 1024 / 1024, (u64)v_addr, (u32)paddr);
...
使用上述探测方法,我只能分配第一个
reserved-memory
区域。
如何正确分配每个区域?
of_reserved_mem_device_init()
是一个包装函数,它以索引 0 调用 of_reserved_mem_device_init_by_idx()
。以索引 1 调用它以获取第二个保留内存区域。