Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/doc: Clarify PRIME documentation

PRIME fds aren't actually GEM fds but are (like the modeset API)
independent of the underlying buffer manager, as long as that one uses
uint32_t as handles. So move that entire section out of the GEM
section and reword it a bit to clarify which parts of PRIME are
generic, and which are the mandatory pieces for GEM drivers to
correctly implement the GEM lifetime rules. The rewording mostly
consists of not mixing up GEM, PRIME and DRM.

I've considered adding some blurbs to the GEM object lifetime section
about interactions with dma-bufs, but then dropped that. As long as
drivers use the right helpers they should have this all implemented
correctly and hence can be regarded as an implementation detail of the
PRIME/GEM helpers. So no need to confuse driver writers with those
tricky interactions.

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>

+74 -51
+74 -51
Documentation/DocBook/drm.tmpl
··· 697 697 respectively. The conversion is handled by the DRM core without any 698 698 driver-specific support. 699 699 </para> 700 - <para> 701 - Similar to global names, GEM file descriptors are also used to share GEM 702 - objects across processes. They offer additional security: as file 703 - descriptors must be explicitly sent over UNIX domain sockets to be shared 704 - between applications, they can't be guessed like the globally unique GEM 705 - names. 706 - </para> 707 - <para> 708 - Drivers that support GEM file descriptors, also known as the DRM PRIME 709 - API, must set the DRIVER_PRIME bit in the struct 710 - <structname>drm_driver</structname> 711 - <structfield>driver_features</structfield> field, and implement the 712 - <methodname>prime_handle_to_fd</methodname> and 713 - <methodname>prime_fd_to_handle</methodname> operations. 714 - </para> 715 - <para> 716 - <synopsis>int (*prime_handle_to_fd)(struct drm_device *dev, 717 - struct drm_file *file_priv, uint32_t handle, 718 - uint32_t flags, int *prime_fd); 719 - int (*prime_fd_to_handle)(struct drm_device *dev, 720 - struct drm_file *file_priv, int prime_fd, 721 - uint32_t *handle);</synopsis> 722 - Those two operations convert a handle to a PRIME file descriptor and 723 - vice versa. Drivers must use the kernel dma-buf buffer sharing framework 724 - to manage the PRIME file descriptors. 725 - </para> 726 - <para> 727 - While non-GEM drivers must implement the operations themselves, GEM 728 - drivers must use the <function>drm_gem_prime_handle_to_fd</function> 729 - and <function>drm_gem_prime_fd_to_handle</function> helper functions. 730 - Those helpers rely on the driver 731 - <methodname>gem_prime_export</methodname> and 732 - <methodname>gem_prime_import</methodname> operations to create a dma-buf 733 - instance from a GEM object (dma-buf exporter role) and to create a GEM 734 - object from a dma-buf instance (dma-buf importer role). 735 - </para> 736 - <para> 737 - <synopsis>struct dma_buf * (*gem_prime_export)(struct drm_device *dev, 738 - struct drm_gem_object *obj, 739 - int flags); 740 - struct drm_gem_object * (*gem_prime_import)(struct drm_device *dev, 741 - struct dma_buf *dma_buf);</synopsis> 742 - These two operations are mandatory for GEM drivers that support DRM 743 - PRIME. 744 - </para> 745 - <sect4> 746 - <title>DRM PRIME Helper Functions Reference</title> 747 - !Pdrivers/gpu/drm/drm_prime.c PRIME Helpers 748 - </sect4> 700 + <para> 701 + GEM also supports buffer sharing with dma-buf file descriptors through 702 + PRIME. GEM-based drivers must use the provided helpers functions to 703 + implement the exporting and importing correctly. See <xref linkend="drm-prime-support" />. 704 + Since sharing file descriptors is inherently more secure than the 705 + easily guessable and global GEM names it is the preferred buffer 706 + sharing mechanism. Sharing buffers through GEM names is only supported 707 + for legacy userspace. Furthermore PRIME also allows cross-device 708 + buffer sharing since it is based on dma-bufs. 709 + </para> 749 710 </sect3> 750 711 <sect3 id="drm-gem-objects-mapping"> 751 712 <title>GEM Objects Mapping</title> ··· 829 868 abstracted from the client in libdrm. 830 869 </para> 831 870 </sect3> 832 - <sect2> 871 + <sect3> 833 872 <title>GEM Function Reference</title> 834 873 !Edrivers/gpu/drm/drm_gem.c 835 - </sect2> 874 + </sect3> 836 875 </sect2> 837 876 <sect2> 838 877 <title>VMA Offset Manager</title> 839 878 !Pdrivers/gpu/drm/drm_vma_manager.c vma offset manager 840 879 !Edrivers/gpu/drm/drm_vma_manager.c 841 880 !Iinclude/drm/drm_vma_manager.h 881 + </sect2> 882 + <sect2 id="drm-prime-support"> 883 + <title>PRIME Buffer Sharing</title> 884 + <para> 885 + PRIME is the cross device buffer sharing framework in drm, originally 886 + created for the OPTIMUS range of multi-gpu platforms. To userspace 887 + PRIME buffers are dma-buf based file descriptors. 888 + </para> 889 + <sect3> 890 + <title>Overview and Driver Interface</title> 891 + <para> 892 + Similar to GEM global names, PRIME file descriptors are 893 + also used to share buffer objects across processes. They offer 894 + additional security: as file descriptors must be explicitly sent over 895 + UNIX domain sockets to be shared between applications, they can't be 896 + guessed like the globally unique GEM names. 897 + </para> 898 + <para> 899 + Drivers that support the PRIME 900 + API must set the DRIVER_PRIME bit in the struct 901 + <structname>drm_driver</structname> 902 + <structfield>driver_features</structfield> field, and implement the 903 + <methodname>prime_handle_to_fd</methodname> and 904 + <methodname>prime_fd_to_handle</methodname> operations. 905 + </para> 906 + <para> 907 + <synopsis>int (*prime_handle_to_fd)(struct drm_device *dev, 908 + struct drm_file *file_priv, uint32_t handle, 909 + uint32_t flags, int *prime_fd); 910 + int (*prime_fd_to_handle)(struct drm_device *dev, 911 + struct drm_file *file_priv, int prime_fd, 912 + uint32_t *handle);</synopsis> 913 + Those two operations convert a handle to a PRIME file descriptor and 914 + vice versa. Drivers must use the kernel dma-buf buffer sharing framework 915 + to manage the PRIME file descriptors. Similar to the mode setting 916 + API PRIME is agnostic to the underlying buffer object manager, as 917 + long as handles are 32bit unsinged integers. 918 + </para> 919 + <para> 920 + While non-GEM drivers must implement the operations themselves, GEM 921 + drivers must use the <function>drm_gem_prime_handle_to_fd</function> 922 + and <function>drm_gem_prime_fd_to_handle</function> helper functions. 923 + Those helpers rely on the driver 924 + <methodname>gem_prime_export</methodname> and 925 + <methodname>gem_prime_import</methodname> operations to create a dma-buf 926 + instance from a GEM object (dma-buf exporter role) and to create a GEM 927 + object from a dma-buf instance (dma-buf importer role). 928 + </para> 929 + <para> 930 + <synopsis>struct dma_buf * (*gem_prime_export)(struct drm_device *dev, 931 + struct drm_gem_object *obj, 932 + int flags); 933 + struct drm_gem_object * (*gem_prime_import)(struct drm_device *dev, 934 + struct dma_buf *dma_buf);</synopsis> 935 + These two operations are mandatory for GEM drivers that support 936 + PRIME. 937 + </para> 938 + </sect3> 939 + <sect3> 940 + <title>PRIME Helper Functions Reference</title> 941 + !Pdrivers/gpu/drm/drm_prime.c PRIME Helpers 942 + </sect3> 842 943 </sect2> 843 944 </sect1> 844 945