Find the answer to your Linux question:
Results 1 to 8 of 8
I have read a few short discussions on implemented memory mapping in a driver but I am still puzzled. What I want to do is have a piece of memory ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2005
    Posts
    6

    Driver MMAP support for direct access from User space


    I have read a few short discussions on implemented memory mapping in a driver but I am still puzzled. What I want to do is have a piece of memory in the driver that is updated when an IRQ comes in and then the user process, which memory maps that driver's memory, polls it for "real time" response.

    Is this a correct understanding, I allocate memory in the module that address is used as the physical address when I call remap_page_range? Oh the Kernel is 2.6. Why I am asking this is the discussions also mention the address in kernel space is logical not physical.

    Thanks,

  2. #2
    Linux Guru lakerdonald's Avatar
    Join Date
    Jun 2004
    Location
    St. Petersburg, FL
    Posts
    5,035
    What kind of information would you like to be placed in this memory region after receiving an interrupt? Just the fact that you've gotten interrupted or what?

  3. #3
    Just Joined!
    Join Date
    Apr 2005
    Posts
    6

    shared memory

    I am just looking to put in the driver memory that an interrupt has occurred and the user process polls that memory instead of the other methods for faster response.

    Thanks,

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Guru lakerdonald's Avatar
    Join Date
    Jun 2004
    Location
    St. Petersburg, FL
    Posts
    5,035
    Just write an interrupt handler function that does the following:
    1. Handles whatever needs to be handled for the particular interrupt
    2. If you want a running count, increase whatever stats variable you have
    3. Awake any reading user processes

    Then change the read() method for your device to sleep until data has arrived.

  6. #5
    Just Joined!
    Join Date
    Apr 2005
    Posts
    6

    deterministic behavior

    I need deterministic behavior so to do that the user program is tied to one CPU.

    Thanks,

  7. #6
    Linux Guru lakerdonald's Avatar
    Join Date
    Jun 2004
    Location
    St. Petersburg, FL
    Posts
    5,035
    can you give me some more context as to the overall scope of this driver?

  8. #7
    Just Joined!
    Join Date
    Apr 2005
    Posts
    6

    Goal for Interrupt Handler and an attempt that does not work

    What is trying to be done is when a ISR is called a variable is set. A user level process memory maps that driver/module's variable and polls it to check for an interrupt occurrence. This is an attempt to get the fastest response as possible to an IRQ assertion in User space.

    I added these lines in the module:
    static int Airtiger2Driver_mmap(struct file* pFile, struct vm_area_struct* pVma)
    {
    static const char* function = NAME "_ioctl";
    ENTER("(%p,%p)",pFile,pVma);

    int status;
    unsigned long offset = pVma->vm_pgoff << PAGE_SHIFT;

    status = remap_page_range(pVma,
    (unsigned long)pBuffer + offset, // from start
    (unsigned long)pBuffer + PAGE_SIZE + offset, // to end
    PAGE_SIZE,
    PAGE_SHARED);
    if (status != 0)
    return (-EAGAIN);
    return SUCCESS;
    }
    ...
    static int Airtiger2DriverInit(void)
    {
    ...
    pBuffer = kmalloc(PAGE_SIZE,GFP_KERNEL);
    pBuffer[0] = 0x000000AA;
    pBuffer[1] = 0x000000BB;
    pBuffer[2] = 0x000000CC;
    pBuffer[3] = 0x00000123;
    ...

    and this in the user level code to test it:
    // open driver
    int fDriver;
    fDriver = open(DRIVER, 0);
    if (fDriver < 0) {
    printf("Can't open device file: %s\n", DRIVER);
    goto byebyeWithError;
    }

    // memory map
    UINT32* pBuffer;
    pBuffer = (UINT32*)mmap(0,PAGE_SIZE,PROT_READ,MAP_SHARED,fDr iver,0);
    printf("pBuffer @ %p\n",pBuffer);
    printf("[0]=%08x [1]=%08x [2]=%08x [3]=%08x\n",
    pBuffer[0], pBuffer[1], pBuffer[2], pBuffer[3]);
    munmap(0,PAGE_SIZE);

    and this is the output:
    pBuffer @ 0x2a9556c000
    [0]=00000000 [1]=00000000 [2]=00000000 [3]=00000000

    Thanks,

  9. #8
    Linux Guru lakerdonald's Avatar
    Join Date
    Jun 2004
    Location
    St. Petersburg, FL
    Posts
    5,035
    Seriously, I think a better way to do this is to implement a read/open/whatever method that sleeps, and have the interrupt handler wake it up. This eliminates the need to mmap() anything.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •