info->fix.smem_start
---- 如果是从kmalloc或者get_free_pages()分配的,这样的内存是不能用remap_pfn_range()映射出去的,要对每个页面调用SetPageReserved()标记为“保留”才可以,virt_to_phys()函数只能得到其物理地址,remap_pfn_range()中的第三个参数是要求是物理页面的帧号,即pfn,所以phys还要>>page_shift。
---- 如果是通过vmalloc分配得到的,也和上面一样,但是需要用vmalloc_to_pfn。
通过kmalloc, get_free_pages,vmalloc分配的物理内存页面,最好不要用remap_pfn_page方法,最后使用VMA的nopage方法。
对于设备内存,最好调用pgprot_nocached(vma->vm_page_prot)后传给remap_pfn_range,防止处理器缓存。
最好是使用fb_mmap()。
static int xxx_mmap(struct file *file, struct vm_area_struct *vma)
{
// TODO: allocate the raw frame buffer if necessary
unsigned long page, pos;
unsigned long start = vma-> vm_start;
unsigned long size = vma-> vm_end-vma-> vm_start;
struct private *cam = file-> private_data;
DBG( "enter zoran_mmap/n ");
if (!cam)
return -ENODEV;
/* We let mmap allocate as much as it wants because Linux was adding 2048 bytes
* to the size the application requested for mmap and it was screwing apps up.
*/
//memcpy(cam-> framebuf, "this is a test ",14);
pos = (unsigned long)cam-> framebuf;
while (size > 0) {
page = vmalloc_to_pfn((void *)pos);
if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED))
return -EAGAIN;
start += PAGE_SIZE;
pos += PAGE_SIZE;
if (size > PAGE_SIZE)
size -= PAGE_SIZE;
else
size = 0;
}
DBG( "mmap success ");
cam-> mmapped = 1;
return 0;
}
---- 如果是从kmalloc或者get_free_pages()分配的,这样的内存是不能用remap_pfn_range()映射出去的,要对每个页面调用SetPageReserved()标记为“保留”才可以,virt_to_phys()函数只能得到其物理地址,remap_pfn_range()中的第三个参数是要求是物理页面的帧号,即pfn,所以phys还要>>page_shift。
---- 如果是通过vmalloc分配得到的,也和上面一样,但是需要用vmalloc_to_pfn。
通过kmalloc, get_free_pages,vmalloc分配的物理内存页面,最好不要用remap_pfn_page方法,最后使用VMA的nopage方法。
对于设备内存,最好调用pgprot_nocached(vma->vm_page_prot)后传给remap_pfn_range,防止处理器缓存。
最好是使用fb_mmap()。
static int xxx_mmap(struct file *file, struct vm_area_struct *vma)
{
// TODO: allocate the raw frame buffer if necessary
unsigned long page, pos;
unsigned long start = vma-> vm_start;
unsigned long size = vma-> vm_end-vma-> vm_start;
struct private *cam = file-> private_data;
DBG( "enter zoran_mmap/n ");
if (!cam)
return -ENODEV;
/* We let mmap allocate as much as it wants because Linux was adding 2048 bytes
* to the size the application requested for mmap and it was screwing apps up.
*/
//memcpy(cam-> framebuf, "this is a test ",14);
pos = (unsigned long)cam-> framebuf;
while (size > 0) {
page = vmalloc_to_pfn((void *)pos);
if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED))
return -EAGAIN;
start += PAGE_SIZE;
pos += PAGE_SIZE;
if (size > PAGE_SIZE)
size -= PAGE_SIZE;
else
size = 0;
}
DBG( "mmap success ");
cam-> mmapped = 1;
return 0;
}
