Does the kernel driver implementing mmap () create a character device?

I am trying to write a kernel driver to manage some memory blocks of physically contiguous and DMAable memory (I use kmalloc() , since these are only DMA threads). To enable some functionality in user space, this memory must be mmap() ed with its own implementation of mmap() . I use Linux device drivers and bad examples that appear on Google as the main source of information.

My mmap() (calling it my_mmap() now) should be registered in the kernel. This is the only valid way to do this using struct file_operations , but this requires creating a personal device and a physical location for it. I do not want to do this. I just want to create a virtual address for a user application to access memory buffers and not create files for mapping memory buffers. Is it possible?

I found that frame buffers also have an equivalent structure with mmap() implementation, but that would be too heavy. This adds more unknowns.

As I understand it, my_mmap() can do the hard work and use remap_pfn_range() while I'm fine with lost flexibility. Otherwise, I would have to implement local nopages() and register it with struct vm_operations_struct . Is it correct?

+4
source share
1 answer

The mmap() operation is a request from user space to map some source in its virtual address space. The way a user-space program identifies a source of interest is to provide a file descriptor (which is actually only a resource descriptor known to the kernel).

This means that you must make your device representable as a file descriptor so that the user-space program can tell the kernel of interest (and the kernel knows how to call the mmap() implementation) - registering a character device is a typical way to do this. Note that frame buffer devices are also accessible through character devices.

You do not need to perform other operations with character devices, such as read() and write() , if that does not make sense for your device. A character device is simply the way in which userpace can open a kernel-controlled descriptor.

+6
source

All Articles