AnsweredAssumed Answered

Cannot allocate a DMA buffer in kernel module

Question asked by quentin chang on Jun 10, 2016
Latest reply on Jun 13, 2016 by quentin chang

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);



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




------------[ 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!