dmx-mmap.rst 3.4 KB

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