1.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later 2 3.. _dmx-mmap: 4 5***************** 6Digital TV mmap() 7***************** 8 9Name 10==== 11 12dmx-mmap - Map device memory into application address space 13 14.. warning:: this API is still experimental 15 16Synopsis 17======== 18 19.. code-block:: c 20 21 #include <unistd.h> 22 #include <sys/mman.h> 23 24 25.. c:function:: void *mmap( void *start, size_t length, int prot, int flags, int fd, off_t offset ) 26 :name: dmx-mmap 27 28Arguments 29========= 30 31``start`` 32 Map the buffer to this address in the application's address space. 33 When the ``MAP_FIXED`` flag is specified, ``start`` must be a 34 multiple of the pagesize and mmap will fail when the specified 35 address cannot be used. Use of this option is discouraged; 36 applications should just specify a ``NULL`` pointer here. 37 38``length`` 39 Length of the memory area to map. This must be a multiple of the 40 DVB packet length (188, on most drivers). 41 42``prot`` 43 The ``prot`` argument describes the desired memory protection. 44 Regardless of the device type and the direction of data exchange it 45 should be set to ``PROT_READ`` | ``PROT_WRITE``, permitting read 46 and write access to image buffers. Drivers should support at least 47 this combination of flags. 48 49``flags`` 50 The ``flags`` parameter specifies the type of the mapped object, 51 mapping options and whether modifications made to the mapped copy of 52 the page are private to the process or are to be shared with other 53 references. 54 55 ``MAP_FIXED`` requests that the driver selects no other address than 56 the one specified. If the specified address cannot be used, 57 :ref:`mmap() <dmx-mmap>` will fail. If ``MAP_FIXED`` is specified, 58 ``start`` must be a multiple of the pagesize. Use of this option is 59 discouraged. 60 61 One of the ``MAP_SHARED`` or ``MAP_PRIVATE`` flags must be set. 62 ``MAP_SHARED`` allows applications to share the mapped memory with 63 other (e. g. child-) processes. 64 65 .. note:: 66 67 The Linux Digital TV applications should not set the 68 ``MAP_PRIVATE``, ``MAP_DENYWRITE``, ``MAP_EXECUTABLE`` or ``MAP_ANON`` 69 flags. 70 71``fd`` 72 File descriptor returned by :ref:`open() <dmx_fopen>`. 73 74``offset`` 75 Offset of the buffer in device memory, as returned by 76 :ref:`DMX_QUERYBUF` ioctl. 77 78 79Description 80=========== 81 82The :ref:`mmap() <dmx-mmap>` function asks to map ``length`` bytes starting at 83``offset`` in the memory of the device specified by ``fd`` into the 84application address space, preferably at address ``start``. This latter 85address is a hint only, and is usually specified as 0. 86 87Suitable length and offset parameters are queried with the 88:ref:`DMX_QUERYBUF` ioctl. Buffers must be allocated with the 89:ref:`DMX_REQBUFS` ioctl before they can be queried. 90 91To unmap buffers the :ref:`munmap() <dmx-munmap>` function is used. 92 93 94Return Value 95============ 96 97On success :ref:`mmap() <dmx-mmap>` returns a pointer to the mapped buffer. On 98error ``MAP_FAILED`` (-1) is returned, and the ``errno`` variable is set 99appropriately. Possible error codes are: 100 101EBADF 102 ``fd`` is not a valid file descriptor. 103 104EACCES 105 ``fd`` is not open for reading and writing. 106 107EINVAL 108 The ``start`` or ``length`` or ``offset`` are not suitable. (E. g. 109 they are too large, or not aligned on a ``PAGESIZE`` boundary.) 110 111 The ``flags`` or ``prot`` value is not supported. 112 113 No buffers have been allocated with the 114 :ref:`DMX_REQBUFS` ioctl. 115 116ENOMEM 117 Not enough physical or virtual memory was available to complete the 118 request. 119