Cannot allocate a DMA buffer in kernel module

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Cannot allocate a DMA buffer in kernel module

1,161 次查看
quentinchang
Contributor II

Hi Sir,

I try to allocate a buffer in my kernel module but it failed.

Below is my testing kernel module codes.

---------------------------------------------------------

    void           __iomem *dma_vbase = NULL;

    unsigned long  dma_pbase = 0, size = 0x2000000;

    unsigned long  pbase = 0;

    pbase = isa_virt_to_bus(high_memory);

    dma_pbase = pbase;

    dma_vbase = ioremap_nocache(dma_pbase, size);

    if (dma_vbase != NULL) {

        pr_info("dma_vbase: %p\n", dma_vbase);

        iounmap(dma_vbase);

    }

    pr_info("--> dma_vbase: %p, dma_pbase: %lx, allocated size: %lx\n", dma_vbase, dma_pbase, (unsigned long)size);

---------------------------------------------------------

Output:

------------[ cut here ]------------

WARNING: CPU: 0 PID: 638 at arch/arm/mm/ioremap.c:301 __arm_ioremap_pfn_caller+0x184/0x1a8()

Modules linked in: linux_kernel_bde(PO+)

CPU: 0 PID: 638 Comm: insmod Tainted: P           O 3.14.52-1.1.0_ga #4

[<80015788>] (unwind_backtrace) from [<80011858>] (show_stack+0x10/0x14)

[<80011858>] (show_stack) from [<80765d38>] (dump_stack+0x7c/0xbc)

[<80765d38>] (dump_stack) from [<80032f60>] (warn_slowpath_common+0x70/0x8c)

[<80032f60>] (warn_slowpath_common) from [<80033018>] (warn_slowpath_null+0x1c/0x24)

[<80033018>] (warn_slowpath_null) from [<8001b504>] (__arm_ioremap_pfn_caller+0x184/0x1a8)

[<8001b504>] (__arm_ioremap_pfn_caller) from [<8001b574>] (__arm_ioremap_caller+0x4c/0x54)

[<8001b574>] (__arm_ioremap_caller) from [<7f001b60>] (_alloc_mpool+0x50/0x11c [linux_kernel_bde])

unwind: Index not found 7f001b60

---[ end trace 11aa9be18d33025f ]---

--> dma_vbase:   (null), dma_pbase: 7f800000, allocated size: 2000000

The function __arm_ioremap_pfn_caller() returns NULL.

I am not familiar to i.MX6 CPU.

Does any one can provide a way to allocate a DMA buffer in kernel module ?

Thank you very much!

标签 (1)
0 项奖励
回复
4 回复数

867 次查看
igorpadykov
NXP Employee
NXP Employee

Hi quentin

one can try to set sufficient memory in cma (defined in imx_v7_defconfig),

also is board have sufficient free memory (>32MB as requests your code)

Best regards

igor

-----------------------------------------------------------------------------------------------------------------------

Note: If this post answers your question, please click the Correct Answer button. Thank you!

-----------------------------------------------------------------------------------------------------------------------

0 项奖励
回复

867 次查看
quentinchang
Contributor II

Hi Igor,

Thanks for your reply.

I think cma is configured in kernel defconfig.

---------------------------------------------------------

CONFIG_CMA_SIZE_MBYTES=320

CONFIG_CMA_SIZE_SEL_MBYTES=y

----------------------------------------------------------------------

I found the function __arm_ioremap_pfn_caller() return NULL in below code block.

/*
* Don't allow RAM to be mapped - this causes problems with ARMv6+
*/
if (WARN_ON(pfn_valid(pfn)))
return NULL;

Do you have any suggestion to this problem ?

Thank you very much.

Best regards,

Quentin

0 项奖励
回复

867 次查看
igorpadykov
NXP Employee
NXP Employee

Hi quentin

please post this on kernel.org mail list

Best regards

igor

0 项奖励
回复

867 次查看
quentinchang
Contributor II

Hi Igor,

Got it. Thank you!

Best regards,

Quentin

0 项奖励
回复