Mastering Linux Device Driver Development by John Madieu

Mastering Linux Device Driver Development by John Madieu

Author:John Madieu
Language: eng
Format: epub
Publisher: Packt Publishing Pvt Ltd
Published: 2021-01-22T00:00:00+00:00


read should contain operations needed to implement the read() system call. Most of the time, the videobuf2-V4L2 helper vb2_fop_read is enough.

write is not needed in our case as it is for an OUTPUT type device. However, using vb2_fop_write here does the job.

unlocked_ioctl must be set to video_ioctl2 if you use v4l2_ioctl_ops. The next section explains this in detail. This V4L2 core helper is a wrapper around __video_do_ioctl(), which handles the real logic, and which routes each ioctl to the appropriate callback in vdev->ioctl_ops, which is where individual ioctl handlers are defined.

mmap should contain operations needed to implement the mmap() system call. Most of the time, the videobuf2-V4L2 helper vb2_fop_mmap is enough, unless additional elements are required prior to performing mapping. Video buffers in the kernel (allocated in response to the VIDIOC_REQBUFS ioctl) have to be mapped individually prior to being accessed in the user space. This is the purpose of this .mmap callback, which just has to map one, and only one, video buffer to the user space. Information needed to map a buffer to a user space is queried to the kernel using the VIDIOC_QUERYBUF ioctl. Given the vma parameter, you can grab a pointer to the corresponding video buffer as follows:struct vb2_queue *q = container_of_myqueue_wrapper();

unsigned long off = vma->vm_pgoff << PAGE_SHIFT;

struct vb2_buffer *vb;

unsigned int buffer = 0, plane = 0;

for (i = 0; i < q->num_buffers; i++) {

struct vb2_buffer *buf = q->bufs[i];

/* The below assume we are on a single-planar system,

* else we would have loop over each plane

*/

if (buf->planes[0].m.offset == off)

break;

return i;

}

videobuf_queue_unlock(myqueue);



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.