[lkml]   [2003]   [May]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
    SubjectHow to DMA data from a pci device to a user buffer directly
    Hello, All.

    In my device driver, I want to DMA image data from a PCI device (a frame
    grabber) to a user buffer directly. Right now I am stuck at how to convert a
    user virtual address to a physical address that can be used by the DMA

    Here is my sequence:
    1) User allocates an image buffer,
    2) User passes the pointer (pUserVirtualAddr) of that buffer to the driver
    through an ioctl call,
    3) Driver calls alloc_kiovec(1, &iobuf);
    4) Driver calls map_user_kiobuf(WRITE, iobuf, (ULONG)pUserVirtualAddr,
    I believe map_user_kiobuf() is executed successfully, for the following
    1) map_user_kiobuf() returns 0,
    2) For imageBufferSize = 640*160, iobuf->nr_pages = 26. Because
    pUserVirtualAddr is not page-aligned, 26 is correct.
    3) iobuf->offset is equal to (ULONG)pUserVirtualAddr & 0xFFF, which is also
    What is strange to me is that iobuf->maplist[idx]->virtual = 0 for idx =

    One driver developer suggested that I do the following to get the physical
    address for the first page:
    physAddr = virt_to_bus(page_address(iobuf->maplist[0])) + iobuf->offset;
    Because page_address() is "#define page_address(page) ((page)->virtual)" and
    "virtual" is equal to 0, this approach will not work for me.

    Another suggested that I add this to my code:
    #define page_to_bus(page) \
    (ULONG)(((page) - mem_map) << PAGE_SHIFT),
    and get the physical address for the first page this way:
    physAddr = page_to_bus(iobuf->maplist[0])+iobuf->offset;
    Because it is not clear to me what exactly is "mem_map", I am not sure how
    "maplist" of type "struct page*", is subtracted by "mem_map" of type
    In my test, I have:
    1) maplist[0] = 0xC114ECEC;
    2) mem_map = 0xC1000010.
    Ignore the offset, what the physical address should be?

    My development environment:
    1) OS: RedHat 7.2 (2.4.7-10)
    2) GCC: 3.2.1
    3) PC: P-III single processor w/ 128Mbytes of memory,
    4) BUS: PCI,
    5) My DMA controller has unlimited scatter-gather capability.

    By the way, I have tested the rest of my code by DMA the image data to a
    kernel buffer allocated using kmalloc() first, then do a memcpy() to copy
    the image data to a user buffer. This alternative seems to work fine.

    All suggestions and comments are greatly appreciated.

    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to
    More majordomo info at
    Please read the FAQ at

     \ /
      Last update: 2005-03-22 13:35    [W:2.402 / U:0.004 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site