Skip to content

Commit e623218

Browse files
Yanteng Siacmel
authored andcommitted
tools headers UAPI: Sync the drm/drm.h with the kernel sources
Picking the changes from: 6068771 ("drm: document DRM_IOCTL_PRIME_HANDLE_TO_FD and PRIME_FD_TO_HANDLE") 61a55f8 ("drm: document expectations for GETFB2 handles") 158350a ("drm: document DRM_IOCTL_GEM_CLOSE") Silencing these perf build warnings: Warning: Kernel ABI header at 'tools/include/uapi/drm/drm.h' differs from latest version at 'include/uapi/drm/drm.h' diff -u tools/include/uapi/drm/drm.h include/uapi/drm/drm.h No changes in tooling as these are just C comment documentation changes. Signed-off-by: Yanteng Si <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Ian Rogers <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/7552c61660bf079f2979fdcbcef8e921255f877a.1683712945.git.siyanteng@loongson.cn Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 5d1ac59 commit e623218

File tree

1 file changed

+55
-2
lines changed
  • tools/include/uapi/drm

1 file changed

+55
-2
lines changed

tools/include/uapi/drm/drm.h

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,19 @@ extern "C" {
972972
#define DRM_IOCTL_GET_STATS DRM_IOR( 0x06, struct drm_stats)
973973
#define DRM_IOCTL_SET_VERSION DRM_IOWR(0x07, struct drm_set_version)
974974
#define DRM_IOCTL_MODESET_CTL DRM_IOW(0x08, struct drm_modeset_ctl)
975+
/**
976+
* DRM_IOCTL_GEM_CLOSE - Close a GEM handle.
977+
*
978+
* GEM handles are not reference-counted by the kernel. User-space is
979+
* responsible for managing their lifetime. For example, if user-space imports
980+
* the same memory object twice on the same DRM file description, the same GEM
981+
* handle is returned by both imports, and user-space needs to ensure
982+
* &DRM_IOCTL_GEM_CLOSE is performed once only. The same situation can happen
983+
* when a memory object is allocated, then exported and imported again on the
984+
* same DRM file description. The &DRM_IOCTL_MODE_GETFB2 IOCTL is an exception
985+
* and always returns fresh new GEM handles even if an existing GEM handle
986+
* already refers to the same memory object before the IOCTL is performed.
987+
*/
975988
#define DRM_IOCTL_GEM_CLOSE DRM_IOW (0x09, struct drm_gem_close)
976989
#define DRM_IOCTL_GEM_FLINK DRM_IOWR(0x0a, struct drm_gem_flink)
977990
#define DRM_IOCTL_GEM_OPEN DRM_IOWR(0x0b, struct drm_gem_open)
@@ -1012,7 +1025,37 @@ extern "C" {
10121025
#define DRM_IOCTL_UNLOCK DRM_IOW( 0x2b, struct drm_lock)
10131026
#define DRM_IOCTL_FINISH DRM_IOW( 0x2c, struct drm_lock)
10141027

1028+
/**
1029+
* DRM_IOCTL_PRIME_HANDLE_TO_FD - Convert a GEM handle to a DMA-BUF FD.
1030+
*
1031+
* User-space sets &drm_prime_handle.handle with the GEM handle to export and
1032+
* &drm_prime_handle.flags, and gets back a DMA-BUF file descriptor in
1033+
* &drm_prime_handle.fd.
1034+
*
1035+
* The export can fail for any driver-specific reason, e.g. because export is
1036+
* not supported for this specific GEM handle (but might be for others).
1037+
*
1038+
* Support for exporting DMA-BUFs is advertised via &DRM_PRIME_CAP_EXPORT.
1039+
*/
10151040
#define DRM_IOCTL_PRIME_HANDLE_TO_FD DRM_IOWR(0x2d, struct drm_prime_handle)
1041+
/**
1042+
* DRM_IOCTL_PRIME_FD_TO_HANDLE - Convert a DMA-BUF FD to a GEM handle.
1043+
*
1044+
* User-space sets &drm_prime_handle.fd with a DMA-BUF file descriptor to
1045+
* import, and gets back a GEM handle in &drm_prime_handle.handle.
1046+
* &drm_prime_handle.flags is unused.
1047+
*
1048+
* If an existing GEM handle refers to the memory object backing the DMA-BUF,
1049+
* that GEM handle is returned. Therefore user-space which needs to handle
1050+
* arbitrary DMA-BUFs must have a user-space lookup data structure to manually
1051+
* reference-count duplicated GEM handles. For more information see
1052+
* &DRM_IOCTL_GEM_CLOSE.
1053+
*
1054+
* The import can fail for any driver-specific reason, e.g. because import is
1055+
* only supported for DMA-BUFs allocated on this DRM device.
1056+
*
1057+
* Support for importing DMA-BUFs is advertised via &DRM_PRIME_CAP_IMPORT.
1058+
*/
10161059
#define DRM_IOCTL_PRIME_FD_TO_HANDLE DRM_IOWR(0x2e, struct drm_prime_handle)
10171060

10181061
#define DRM_IOCTL_AGP_ACQUIRE DRM_IO( 0x30)
@@ -1104,15 +1147,25 @@ extern "C" {
11041147
* struct as the output.
11051148
*
11061149
* If the client is DRM master or has &CAP_SYS_ADMIN, &drm_mode_fb_cmd2.handles
1107-
* will be filled with GEM buffer handles. Planes are valid until one has a
1108-
* zero handle -- this can be used to compute the number of planes.
1150+
* will be filled with GEM buffer handles. Fresh new GEM handles are always
1151+
* returned, even if another GEM handle referring to the same memory object
1152+
* already exists on the DRM file description. The caller is responsible for
1153+
* removing the new handles, e.g. via the &DRM_IOCTL_GEM_CLOSE IOCTL. The same
1154+
* new handle will be returned for multiple planes in case they use the same
1155+
* memory object. Planes are valid until one has a zero handle -- this can be
1156+
* used to compute the number of planes.
11091157
*
11101158
* Otherwise, &drm_mode_fb_cmd2.handles will be zeroed and planes are valid
11111159
* until one has a zero &drm_mode_fb_cmd2.pitches.
11121160
*
11131161
* If the framebuffer has a format modifier, &DRM_MODE_FB_MODIFIERS will be set
11141162
* in &drm_mode_fb_cmd2.flags and &drm_mode_fb_cmd2.modifier will contain the
11151163
* modifier. Otherwise, user-space must ignore &drm_mode_fb_cmd2.modifier.
1164+
*
1165+
* To obtain DMA-BUF FDs for each plane without leaking GEM handles, user-space
1166+
* can export each handle via &DRM_IOCTL_PRIME_HANDLE_TO_FD, then immediately
1167+
* close each unique handle via &DRM_IOCTL_GEM_CLOSE, making sure to not
1168+
* double-close handles which are specified multiple times in the array.
11161169
*/
11171170
#define DRM_IOCTL_MODE_GETFB2 DRM_IOWR(0xCE, struct drm_mode_fb_cmd2)
11181171

0 commit comments

Comments
 (0)