int mmapdrv_mmap(struct file *file, struct vm_area_struct *vma) { unsigned long offset = vma->vm_pgoff< unsigned long size = vma->vm_end - vma->vm_start;
if ( size > mem_size*1024*1024 ) { printk("size too big\n"); return(-ENXIO); }
offset = offset + mem_start*1024*1024;
/* we do not want to have this area swapped out, lock it */ vma->vm_flags |= VM_LOCKED; if ( remap_page_range(vma->vm_start,offset,size,PAGE_SHARED)) { printk("remap page range failed\n"); return -ENXIO; }
return(0); }
使用LDD2源码里面自带的工具mapper测试结果如下:
[root@localhost modprg]# insmod mmap_ioremap.mod mmap device major = 254 high memory physical address 0x100M reserve_virt_addr = 0xc7038000