Use do_mmap() in Linux device driver
The device we work at now need to have a user space virtual memory address, we try to use do_mmap() as below:
*uvaddr = (void *)do开发者_运维问答_mmap(0, 0, size, PROT_READ|PROT_WRITE, MAP_ANONYMOUS, 0);
But we got following error
Unable to handle kernel paging request for data at ad8
Is it okay to use "do_mmap()" in a device driver? If not, any correct way to do it?
It's possible that do_mmap
is succeeding, but uvaddr
does not point to a valid location to store the result. To check this for sure, do something like:
void *mmap_result;
printk(KERN_DEBUG "uvaddr = %p", uvaddr);
mmap_result = (void *)do_mmap(0, 0, size, PROT_READ|PROT_WRITE, MAP_ANONYMOUS, 0);
printk(KERN_DEBUG "mmap_result = %p", mmap_result);
*uvaddr = mmap_result;
This should tell you for certain which is failing: the call to do_mmap
or the assignment to *uvaddr
.
精彩评论