18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later 28c2ecf20Sopenharmony_ci.. c:namespace:: DTV.dmx 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ci.. _dmx-mmap: 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci***************** 78c2ecf20Sopenharmony_ciDigital TV mmap() 88c2ecf20Sopenharmony_ci***************** 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ciName 118c2ecf20Sopenharmony_ci==== 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_cidmx-mmap - Map device memory into application address space 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci.. warning:: this API is still experimental 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ciSynopsis 188c2ecf20Sopenharmony_ci======== 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci.. code-block:: c 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci #include <unistd.h> 238c2ecf20Sopenharmony_ci #include <sys/mman.h> 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci.. c:function:: void *mmap( void *start, size_t length, int prot, int flags, int fd, off_t offset ) 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ciArguments 288c2ecf20Sopenharmony_ci========= 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci``start`` 318c2ecf20Sopenharmony_ci Map the buffer to this address in the application's address space. 328c2ecf20Sopenharmony_ci When the ``MAP_FIXED`` flag is specified, ``start`` must be a 338c2ecf20Sopenharmony_ci multiple of the pagesize and mmap will fail when the specified 348c2ecf20Sopenharmony_ci address cannot be used. Use of this option is discouraged; 358c2ecf20Sopenharmony_ci applications should just specify a ``NULL`` pointer here. 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci``length`` 388c2ecf20Sopenharmony_ci Length of the memory area to map. This must be a multiple of the 398c2ecf20Sopenharmony_ci DVB packet length (188, on most drivers). 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci``prot`` 428c2ecf20Sopenharmony_ci The ``prot`` argument describes the desired memory protection. 438c2ecf20Sopenharmony_ci Regardless of the device type and the direction of data exchange it 448c2ecf20Sopenharmony_ci should be set to ``PROT_READ`` | ``PROT_WRITE``, permitting read 458c2ecf20Sopenharmony_ci and write access to image buffers. Drivers should support at least 468c2ecf20Sopenharmony_ci this combination of flags. 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci``flags`` 498c2ecf20Sopenharmony_ci The ``flags`` parameter specifies the type of the mapped object, 508c2ecf20Sopenharmony_ci mapping options and whether modifications made to the mapped copy of 518c2ecf20Sopenharmony_ci the page are private to the process or are to be shared with other 528c2ecf20Sopenharmony_ci references. 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci ``MAP_FIXED`` requests that the driver selects no other address than 558c2ecf20Sopenharmony_ci the one specified. If the specified address cannot be used, 568c2ecf20Sopenharmony_ci :c:func:`mmap()` will fail. If ``MAP_FIXED`` is specified, 578c2ecf20Sopenharmony_ci ``start`` must be a multiple of the pagesize. Use of this option is 588c2ecf20Sopenharmony_ci discouraged. 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci One of the ``MAP_SHARED`` or ``MAP_PRIVATE`` flags must be set. 618c2ecf20Sopenharmony_ci ``MAP_SHARED`` allows applications to share the mapped memory with 628c2ecf20Sopenharmony_ci other (e. g. child-) processes. 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci .. note:: 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci The Linux Digital TV applications should not set the 678c2ecf20Sopenharmony_ci ``MAP_PRIVATE``, ``MAP_DENYWRITE``, ``MAP_EXECUTABLE`` or ``MAP_ANON`` 688c2ecf20Sopenharmony_ci flags. 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci``fd`` 718c2ecf20Sopenharmony_ci File descriptor returned by :c:func:`open()`. 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci``offset`` 748c2ecf20Sopenharmony_ci Offset of the buffer in device memory, as returned by 758c2ecf20Sopenharmony_ci :ref:`DMX_QUERYBUF` ioctl. 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ciDescription 788c2ecf20Sopenharmony_ci=========== 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ciThe :c:func:`mmap()` function asks to map ``length`` bytes starting at 818c2ecf20Sopenharmony_ci``offset`` in the memory of the device specified by ``fd`` into the 828c2ecf20Sopenharmony_ciapplication address space, preferably at address ``start``. This latter 838c2ecf20Sopenharmony_ciaddress is a hint only, and is usually specified as 0. 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ciSuitable length and offset parameters are queried with the 868c2ecf20Sopenharmony_ci:ref:`DMX_QUERYBUF` ioctl. Buffers must be allocated with the 878c2ecf20Sopenharmony_ci:ref:`DMX_REQBUFS` ioctl before they can be queried. 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ciTo unmap buffers the :c:func:`munmap()` function is used. 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ciReturn Value 928c2ecf20Sopenharmony_ci============ 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ciOn success :c:func:`mmap()` returns a pointer to the mapped buffer. On 958c2ecf20Sopenharmony_cierror ``MAP_FAILED`` (-1) is returned, and the ``errno`` variable is set 968c2ecf20Sopenharmony_ciappropriately. Possible error codes are: 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ciEBADF 998c2ecf20Sopenharmony_ci ``fd`` is not a valid file descriptor. 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ciEACCES 1028c2ecf20Sopenharmony_ci ``fd`` is not open for reading and writing. 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ciEINVAL 1058c2ecf20Sopenharmony_ci The ``start`` or ``length`` or ``offset`` are not suitable. (E. g. 1068c2ecf20Sopenharmony_ci they are too large, or not aligned on a ``PAGESIZE`` boundary.) 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ci The ``flags`` or ``prot`` value is not supported. 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ci No buffers have been allocated with the 1118c2ecf20Sopenharmony_ci :ref:`DMX_REQBUFS` ioctl. 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ciENOMEM 1148c2ecf20Sopenharmony_ci Not enough physical or virtual memory was available to complete the 1158c2ecf20Sopenharmony_ci request. 116