Re: The Ultra Sound Driver

Alessandro Rubini (rubini@pop.systemy.it)
Mon, 16 Feb 1998 09:41:39 +0100 (MET)


> If file was closed mmaped area can still exist,
> but I (probably wrong) free DMA buffer when file is closing (releasing).

Yes, this *is* wrong.

> My question is: Can I detect at which point application unmap memory
> area? Is there any callback for it or some like this?

There are the "virtual memory operations", that are meant just for that
purpose: give a driver some control over its memory mapped regions.

You can implement a usage count in virtual memory areas with code like
this one:

static struct vm_operations_struct simple_vm_ops = {
simple_vma_open,
simple_vma_close, /* no more fields */
};

void simple_vma_open(struct vm_area_struct * area)
{ MOD_INC_USE_COUNT; }

void simple_vma_close(struct vm_area_struct * area)
{ MOD_DEC_USE_COUNT; }

int simple_mmap(struct inode *inode, struct file *filp,
struct vm_area_struct *vma)
{
/* int remap_page_range(virt_add, phys_add, size, protection); */
if (remap_page_range(vma->vm_start, vma->vm_offset,
vma->vm_end-vma->vm_start, vma->vm_page_prot))
return -EAGAIN;
if (vma->vm_ops)
return -EINVAL; /* Hmm... shouldn't happen */
vma->vm_ops = &simple_vm_ops;
MOD_INC_USE_COUNT; /* open(vma) wasn't called this time */
vma->vm_inode = inode;
inode->i_count++;
return 0;
}

Best
/alessandro

--
    __ o       Tu vuo` fa` l'americano: sient'a me chi t'o fa fa`.
   _`\<,                                            (Renato Carosone)
__( )/( )__ alessandro.rubini@linux.it  +39-382-529554

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu