I'm allocating a buffer in my driver using devm_kzalloc(.., .., GFP_KERNEL)
and then I register this buffer as a framebuffer driver so that it appears as a file under /dev/fb0
. I can then open this file and write to it. When I do it this way, everything works fine and my data arrives in the driver memory buffer.
我正在使用devm_kzalloc(.. ..)在驱动程序中分配缓冲区。,. .然后,我将这个缓冲区注册为framebuffer驱动程序,以使它在/dev/fb0下显示为一个文件。然后我可以打开这个文件并写入它。当我这样做时,一切都运行良好,我的数据到达驱动程序内存缓冲区。
However, if I then mmap
it in the user process like this: mmap(NULL, size, PROT_WRITE, MAP_SHARED, fd, 0)
, using the same file fd and try to write to the returned memory space, nothing gets written into the driver memory.
但是,如果我在用户进程中使用mmap(NULL, size, PROT_WRITE, MAP_SHARED, fd, 0),使用相同的文件fd并尝试将其写到返回的内存空间中,则不会写入驱动程序内存中。
Am I forgetting something here?
我是不是忘了什么东西?
1 个解决方案
#1
2
Got it! I was doing it all wrong. I had to setup the vm system to correctly handle mmap and this had to be done using fb_deferred_io (which I did not even have until I enabled some unrelated drivers which selected it). Then I had to use __get_free_pages instead of devm_kzmalloc() and one last detail was to use __pa(vmem) when assigning the screen buffer pointer for fbdev subsystem. Then it started working :-)
得到它!我做错了。我必须设置vm系统来正确地处理mmap,这必须使用fb_deferred red_io(直到我启用了一些不相关的驱动程序来选择它)来完成。然后我必须使用__get_free_pages而不是devm_kzmalloc(),最后一个细节是在为fbdev子系统分配屏幕缓冲区指针时使用__pa(vmem)。然后它开始工作:
#1
2
Got it! I was doing it all wrong. I had to setup the vm system to correctly handle mmap and this had to be done using fb_deferred_io (which I did not even have until I enabled some unrelated drivers which selected it). Then I had to use __get_free_pages instead of devm_kzmalloc() and one last detail was to use __pa(vmem) when assigning the screen buffer pointer for fbdev subsystem. Then it started working :-)
得到它!我做错了。我必须设置vm系统来正确地处理mmap,这必须使用fb_deferred red_io(直到我启用了一些不相关的驱动程序来选择它)来完成。然后我必须使用__get_free_pages而不是devm_kzmalloc(),最后一个细节是在为fbdev子系统分配屏幕缓冲区指针时使用__pa(vmem)。然后它开始工作: