linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* mmap enrty point in a driver
@ 2002-10-08 16:27 swayampakulaa, sudhindra
  0 siblings, 0 replies; only message in thread
From: swayampakulaa, sudhindra @ 2002-10-08 16:27 UTC (permalink / raw)
  To: lkml, linux-mm

Iam trying to understand the mmap entry point for a driver.
This is how the mmap() is implemented 


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

Can you help me in understanding what exactly is the mmap() doing here and
if its doing it right.


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-10-08 16:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-08 16:27 mmap enrty point in a driver swayampakulaa, sudhindra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).