1059b1c5bSMauro Carvalho Chehab.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later 2*f9b2e8aaSMauro Carvalho Chehab.. c:namespace:: DTV.dmx 354f38fcaSMauro Carvalho Chehab 454f38fcaSMauro Carvalho Chehab.. _dmx-mmap: 554f38fcaSMauro Carvalho Chehab 654f38fcaSMauro Carvalho Chehab***************** 754f38fcaSMauro Carvalho ChehabDigital TV mmap() 854f38fcaSMauro Carvalho Chehab***************** 954f38fcaSMauro Carvalho Chehab 1054f38fcaSMauro Carvalho ChehabName 1154f38fcaSMauro Carvalho Chehab==== 1254f38fcaSMauro Carvalho Chehab 1354f38fcaSMauro Carvalho Chehabdmx-mmap - Map device memory into application address space 1454f38fcaSMauro Carvalho Chehab 1554f38fcaSMauro Carvalho Chehab.. warning:: this API is still experimental 1654f38fcaSMauro Carvalho Chehab 1754f38fcaSMauro Carvalho ChehabSynopsis 1854f38fcaSMauro Carvalho Chehab======== 1954f38fcaSMauro Carvalho Chehab 2054f38fcaSMauro Carvalho Chehab.. code-block:: c 2154f38fcaSMauro Carvalho Chehab 2254f38fcaSMauro Carvalho Chehab #include <unistd.h> 2354f38fcaSMauro Carvalho Chehab #include <sys/mman.h> 2454f38fcaSMauro Carvalho Chehab 2554f38fcaSMauro Carvalho Chehab.. c:function:: void *mmap( void *start, size_t length, int prot, int flags, int fd, off_t offset ) 2654f38fcaSMauro Carvalho Chehab 2754f38fcaSMauro Carvalho ChehabArguments 2854f38fcaSMauro Carvalho Chehab========= 2954f38fcaSMauro Carvalho Chehab 3054f38fcaSMauro Carvalho Chehab``start`` 3154f38fcaSMauro Carvalho Chehab Map the buffer to this address in the application's address space. 3254f38fcaSMauro Carvalho Chehab When the ``MAP_FIXED`` flag is specified, ``start`` must be a 3354f38fcaSMauro Carvalho Chehab multiple of the pagesize and mmap will fail when the specified 3454f38fcaSMauro Carvalho Chehab address cannot be used. Use of this option is discouraged; 3554f38fcaSMauro Carvalho Chehab applications should just specify a ``NULL`` pointer here. 3654f38fcaSMauro Carvalho Chehab 3754f38fcaSMauro Carvalho Chehab``length`` 3854f38fcaSMauro Carvalho Chehab Length of the memory area to map. This must be a multiple of the 3954f38fcaSMauro Carvalho Chehab DVB packet length (188, on most drivers). 4054f38fcaSMauro Carvalho Chehab 4154f38fcaSMauro Carvalho Chehab``prot`` 4254f38fcaSMauro Carvalho Chehab The ``prot`` argument describes the desired memory protection. 4354f38fcaSMauro Carvalho Chehab Regardless of the device type and the direction of data exchange it 4454f38fcaSMauro Carvalho Chehab should be set to ``PROT_READ`` | ``PROT_WRITE``, permitting read 4554f38fcaSMauro Carvalho Chehab and write access to image buffers. Drivers should support at least 4654f38fcaSMauro Carvalho Chehab this combination of flags. 4754f38fcaSMauro Carvalho Chehab 4854f38fcaSMauro Carvalho Chehab``flags`` 4954f38fcaSMauro Carvalho Chehab The ``flags`` parameter specifies the type of the mapped object, 5054f38fcaSMauro Carvalho Chehab mapping options and whether modifications made to the mapped copy of 5154f38fcaSMauro Carvalho Chehab the page are private to the process or are to be shared with other 5254f38fcaSMauro Carvalho Chehab references. 5354f38fcaSMauro Carvalho Chehab 5454f38fcaSMauro Carvalho Chehab ``MAP_FIXED`` requests that the driver selects no other address than 5554f38fcaSMauro Carvalho Chehab the one specified. If the specified address cannot be used, 56*f9b2e8aaSMauro Carvalho Chehab :c:func:`mmap()` will fail. If ``MAP_FIXED`` is specified, 5754f38fcaSMauro Carvalho Chehab ``start`` must be a multiple of the pagesize. Use of this option is 5854f38fcaSMauro Carvalho Chehab discouraged. 5954f38fcaSMauro Carvalho Chehab 6054f38fcaSMauro Carvalho Chehab One of the ``MAP_SHARED`` or ``MAP_PRIVATE`` flags must be set. 6154f38fcaSMauro Carvalho Chehab ``MAP_SHARED`` allows applications to share the mapped memory with 6254f38fcaSMauro Carvalho Chehab other (e. g. child-) processes. 6354f38fcaSMauro Carvalho Chehab 6454f38fcaSMauro Carvalho Chehab .. note:: 6554f38fcaSMauro Carvalho Chehab 6654f38fcaSMauro Carvalho Chehab The Linux Digital TV applications should not set the 6754f38fcaSMauro Carvalho Chehab ``MAP_PRIVATE``, ``MAP_DENYWRITE``, ``MAP_EXECUTABLE`` or ``MAP_ANON`` 6854f38fcaSMauro Carvalho Chehab flags. 6954f38fcaSMauro Carvalho Chehab 7054f38fcaSMauro Carvalho Chehab``fd`` 71*f9b2e8aaSMauro Carvalho Chehab File descriptor returned by :c:func:`open()`. 7254f38fcaSMauro Carvalho Chehab 7354f38fcaSMauro Carvalho Chehab``offset`` 7454f38fcaSMauro Carvalho Chehab Offset of the buffer in device memory, as returned by 7554f38fcaSMauro Carvalho Chehab :ref:`DMX_QUERYBUF` ioctl. 7654f38fcaSMauro Carvalho Chehab 7754f38fcaSMauro Carvalho ChehabDescription 7854f38fcaSMauro Carvalho Chehab=========== 7954f38fcaSMauro Carvalho Chehab 80*f9b2e8aaSMauro Carvalho ChehabThe :c:func:`mmap()` function asks to map ``length`` bytes starting at 8154f38fcaSMauro Carvalho Chehab``offset`` in the memory of the device specified by ``fd`` into the 8254f38fcaSMauro Carvalho Chehabapplication address space, preferably at address ``start``. This latter 8354f38fcaSMauro Carvalho Chehabaddress is a hint only, and is usually specified as 0. 8454f38fcaSMauro Carvalho Chehab 8554f38fcaSMauro Carvalho ChehabSuitable length and offset parameters are queried with the 8654f38fcaSMauro Carvalho Chehab:ref:`DMX_QUERYBUF` ioctl. Buffers must be allocated with the 8754f38fcaSMauro Carvalho Chehab:ref:`DMX_REQBUFS` ioctl before they can be queried. 8854f38fcaSMauro Carvalho Chehab 89*f9b2e8aaSMauro Carvalho ChehabTo unmap buffers the :c:func:`munmap()` function is used. 9054f38fcaSMauro Carvalho Chehab 9154f38fcaSMauro Carvalho ChehabReturn Value 9254f38fcaSMauro Carvalho Chehab============ 9354f38fcaSMauro Carvalho Chehab 94*f9b2e8aaSMauro Carvalho ChehabOn success :c:func:`mmap()` returns a pointer to the mapped buffer. On 9554f38fcaSMauro Carvalho Chehaberror ``MAP_FAILED`` (-1) is returned, and the ``errno`` variable is set 9654f38fcaSMauro Carvalho Chehabappropriately. Possible error codes are: 9754f38fcaSMauro Carvalho Chehab 9854f38fcaSMauro Carvalho ChehabEBADF 9954f38fcaSMauro Carvalho Chehab ``fd`` is not a valid file descriptor. 10054f38fcaSMauro Carvalho Chehab 10154f38fcaSMauro Carvalho ChehabEACCES 10254f38fcaSMauro Carvalho Chehab ``fd`` is not open for reading and writing. 10354f38fcaSMauro Carvalho Chehab 10454f38fcaSMauro Carvalho ChehabEINVAL 10554f38fcaSMauro Carvalho Chehab The ``start`` or ``length`` or ``offset`` are not suitable. (E. g. 10654f38fcaSMauro Carvalho Chehab they are too large, or not aligned on a ``PAGESIZE`` boundary.) 10754f38fcaSMauro Carvalho Chehab 10854f38fcaSMauro Carvalho Chehab The ``flags`` or ``prot`` value is not supported. 10954f38fcaSMauro Carvalho Chehab 11054f38fcaSMauro Carvalho Chehab No buffers have been allocated with the 11154f38fcaSMauro Carvalho Chehab :ref:`DMX_REQBUFS` ioctl. 11254f38fcaSMauro Carvalho Chehab 11354f38fcaSMauro Carvalho ChehabENOMEM 11454f38fcaSMauro Carvalho Chehab Not enough physical or virtual memory was available to complete the 11554f38fcaSMauro Carvalho Chehab request. 116