Skip to contentSkip to conversation

Query about UIO

DISCUSSION bill 3 participants 4 messages Jul 7, 2011 – Jul 8, 2011 1 message not in the archive

lore
Share & tools
lore

bill

author
#0 lore raw

Hi, Greg

I've been reading the UIO code, one place puzzled me a lot. May I ask one question about it?

-------------------------------------------------------------------------------
drivers/uio/uio.c
static int uio_find_mem_index(struct vm_area_struct *vma)

{
    int mi;
    struct uio_device *idev = vma->vm_private_data;

    for (mi = 0; mi < MAX_UIO_MAPS; mi++) {
        if (idev->info->mem[mi].size == 0)
            return -1;
        if (vma->vm_pgoff == mi)
            return mi;
    }
    return -1;
}

I don't get it why use vma->vm_pgoff as the index for struct uio_mem mem[MAX_UIO_MAPS], Suppose there are twohardware memory space, if user intends to map the 2nd mem, then the last parameter of mmap should be 1,

mapaddr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED,

               fd, 1);

Is my understanding correct?

thanks

bill

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20110707/88272eab/attachment.html

#1 lore raw
Quoted 21 lines · bill

Hi, Greg

I've been reading the UIO code, one place puzzled me a lot. May I ask one question about it?

-------------------------------------------------------------------------------
drivers/uio/uio.c
static int uio_find_mem_index(struct vm_area_struct *vma)

{
    int mi;
    struct uio_device *idev = vma->vm_private_data;

    for (mi = 0; mi < MAX_UIO_MAPS; mi++) {
        if (idev->info->mem[mi].size == 0)
            return -1;
        if (vma->vm_pgoff == mi)
            return mi;
    }
    return -1;
}
Quoted 8 lines

I don't get it why use vma->vm_pgoff as the index for struct uio_mem mem[MAX_UIO_MAPS], Suppose there are twohardware memory space, if user intends to map the 2nd mem, then the last parameter of mmap should be 1,

mapaddr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED,

               fd, 1);

Is my understanding correct?

I really don't know, sorry.

But Hans should know, Hans?

#2 lore raw
In reply to bill
Quoted 21 lines · bill

Hi, Greg

I've been reading the UIO code, one place puzzled me a lot. May I ask one question about it?

-------------------------------------------------------------------------------
drivers/uio/uio.c
static int uio_find_mem_index(struct vm_area_struct *vma) {
??? int mi;
??? struct uio_device *idev = vma->vm_private_data;

??? for (mi = 0; mi < MAX_UIO_MAPS; mi++) {
??? ??? if (idev->info->mem[mi].size == 0)
??? ??? ??? return -1;
??? ??? if (vma->vm_pgoff == mi)
??? ??? ??? return mi;
??? }
??? return -1;
}

Quoted 9 lines

I don't get it why use vma->vm_pgoff as the index for struct uio_mem mem[MAX_UIO_MAPS],
Suppose there are twohardware memory space, if user intends to map the 2nd mem, then
the last parameter of mmap should be 1,

mapaddr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, ??? ??? ?????? fd, 1);

the offset need in page units, vm_pgoff is the offset in page. to map nth mem, you need to do (n-1)<<PAGE_SHIFT(n-1* page size specific to arch). in mmap call, ultimately in the kernel vm_pgoff = offset >>PAGE_SHIFT which is index into uio_mem array.

thanks,
thayumanavar s.

A message that is not in the archive (sent off-list or not yet received): 20110707183745.GA4860@local

author
#4 lore raw
Quoted 37 lines · At 2011-07-08 02:37:46?"Hans J. Koch" <[email protected]> wrote:
Quoted 22 lines · Greg KH
Quoted 21 lines · bill

Hi, Greg

I've been reading the UIO code, one place puzzled me a lot. May I ask one question about it?

-------------------------------------------------------------------------------
drivers/uio/uio.c
static int uio_find_mem_index(struct vm_area_struct *vma)

{
    int mi;
    struct uio_device *idev = vma->vm_private_data;

    for (mi = 0; mi < MAX_UIO_MAPS; mi++) {
        if (idev->info->mem[mi].size == 0)
            return -1;
        if (vma->vm_pgoff == mi)
            return mi;
    }
    return -1;
}
Quoted 8 lines
Quoted 8 lines

I don't get it why use vma->vm_pgoff as the index for struct uio_mem mem[MAX_UIO_MAPS], Suppose there are twohardware memory space, if user intends to map the 2nd mem, then the last parameter of mmap should be 1,

mapaddr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED,

               fd, 1);

Is my understanding correct?

No, it isn't. The last parameter of mmap is divided by PAGE_SIZE before it reaches the UIO core. Therefore, it has to be set to n * getpagesize(). This is explained in the docs under Documentation/DocBook/. Use "make htmldocs" to generate HTML documentation. A faster way is to do

Quoted 8 lines

dblatex Documentation/DocBook/uio-howto.tmpl

This generates a PDF with the UIO documentation, provided you have a working LaTeX system, and have dblatex installed.

Thanks,
Hans

Thanks for your explanation.
So vma->vm_pgoff is not used as its original meanings, that's the point puzzled me. Now it's clear:)

Quoted 6 lines
Quoted 6 lines

I really don't know, sorry.

But Hans should know, Hans?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20110708/d30d1d3a/attachment.html