lkdp-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [LKDP] mmap driver entry point


From: Ankit
Subject: Re: [LKDP] mmap driver entry point
Date: Tue, 8 Oct 2002 11:32:35 -0700 (PDT)

Hi,
i see what you mean...
but iam using this driver to fetch me some memory in
my user space application by calling mmap with the
file descriptor got by opening the device file for
this driver.
mmap(0, length, flags, flags, fd, offset)

and the mmap entry point in the driver is implemented
as below:

In the implementation, it tries to write an index into
the first four bytes, which i use to store in my
internal structures( to later reference it through the
index), before zeroing out the buffer. But the index
is always -1.

himem_buf_allocated = 0;

int xxx_mmap(struct file *filp,
                  struct vm_area_struct *vma)
{
  unsigned long size;
  char * virt_addr;
  int           index;

  size = vma->vm_end - vma->vm_start;
  if ((size % PAGE_SIZE) != 0){
    size = (size / PAGE_SIZE) * PAGE_SIZE + PAGE_SIZE;
  }

  /* himem_buf_size is 0x80000000 */
  if (size + himem_buf_allocated >= himem_buf_size){
    
    return -ENOMEM;
  }
  
  /* himem_buf is calculated as high_memory -
PAGE_OFFSET */
  umem_addr = himem_buf + himem_buf_allocated;
  if (umem_addr == 0){
    return -ENOMEM;
  }
  himem_buf_allocated += size;
  

  virt_addr = ioremap((unsigned long)umem_addr,
PAGE_SIZE);  
  if (virt_addr == 0){
    return -ENOMEM;
  }
  /* write the index into the first 4 bytes */
  writel(index, (uint32_t *)virt_addr);

    /* the values of index and *(virt_addr) do not 
       match.   *(virt_addr) is always -1 .
       Is something wrong here    */
    dbg_printf(0,"index is %d, *(virt_addr) is %d\n",
index,(int)readl(virt_addr));
  iounmap(virt_addr);

   

  remap_page_range(vma->vm_start, (ulong)umem_addr, 
                   vma->vm_end - vma->vm_start, vma->vm_page_prot);

  return 0;
}

I dont understand the part where its getting the
physical address to map.
whats the high_memory and whats the page_offset.
Can you help me in understanding what exactly is the
mmap() doing here and
if its doing it right.

Thank you

--- Abhishek Nayani <address@hidden> wrote:
> Hi,
> 
> On Tue, 08 Oct 2002, Ankit wrote:
> 
> > Iam trying to understand the mmap entry point for
> a
> > driver.
> > This is how the mmap() is implemented 
> > 
> 
>       mmap() is usually used to map a file from some
> secondary 
> storage into RAM. So the drivers (usually fs code)
> implement the mmap()
> function (which is specific to the filesystem) which
> is called by the 
> generic do_mmap() routine. 
> 
>                                       bye,
>                                               Abhi.
>       
>
--------------------------------------------------------------------------
> "I can only show you the door, you have to walk
> through it..." - Morpheus
>
--------------------------------------------------------------------------
> Home Page: http://www.abhi.tk
> -----BEGIN GEEK CODE
>
BLOCK------------------------------------------------
> GCS d+ s:- a-- C+++ UL P+ L+++ E- W++ N+ o K- w---
> O-- M- V- PS PE Y PGP 
> t+ 5 X+ R- tv+ b+++ DI+ D G e++ h! !r y- 
> ------END GEEK CODE
>
BLOCK-------------------------------------------------
> 
> 
> _______________________________________________
> Lkdp-discuss mailing list
> address@hidden
>
http://mail.freesoftware.fsf.org/mailman/listinfo/lkdp-discuss


__________________________________________________
Do you Yahoo!?
Faith Hill - Exclusive Performances, Videos & More
http://faith.yahoo.com




reply via email to

[Prev in Thread] Current Thread [Next in Thread]