dmx-mmap.rst 3.4 KB

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