1 /* SPDX-License-Identifier: MIT */
2 /* Copyright (c) 2012-2020 NVIDIA Corporation */
4 #ifndef _UAPI_TEGRA_DRM_H_
5 #define _UAPI_TEGRA_DRM_H_
9 #if defined(__cplusplus)
13 /* Tegra DRM legacy UAPI. Only enabled with STAGING */
15 #define DRM_TEGRA_GEM_CREATE_TILED (1 << 0)
16 #define DRM_TEGRA_GEM_CREATE_BOTTOM_UP (1 << 1)
19 * struct drm_tegra_gem_create - parameters for the GEM object creation IOCTL
21 struct drm_tegra_gem_create {
25 * The size, in bytes, of the buffer object to be created.
32 * A bitmask of flags that influence the creation of GEM objects:
34 * DRM_TEGRA_GEM_CREATE_TILED
35 * Use the 16x16 tiling format for this buffer.
37 * DRM_TEGRA_GEM_CREATE_BOTTOM_UP
38 * The buffer has a bottom-up layout.
45 * The handle of the created GEM object. Set by the kernel upon
46 * successful completion of the IOCTL.
52 * struct drm_tegra_gem_mmap - parameters for the GEM mmap IOCTL
54 struct drm_tegra_gem_mmap {
58 * Handle of the GEM object to obtain an mmap offset for.
65 * Structure padding that may be used in the future. Must be 0.
72 * The mmap offset for the given GEM object. Set by the kernel upon
73 * successful completion of the IOCTL.
79 * struct drm_tegra_syncpt_read - parameters for the read syncpoint IOCTL
81 struct drm_tegra_syncpt_read {
85 * ID of the syncpoint to read the current value from.
92 * The current syncpoint value. Set by the kernel upon successful
93 * completion of the IOCTL.
99 * struct drm_tegra_syncpt_incr - parameters for the increment syncpoint IOCTL
101 struct drm_tegra_syncpt_incr {
105 * ID of the syncpoint to increment.
112 * Structure padding that may be used in the future. Must be 0.
118 * struct drm_tegra_syncpt_wait - parameters for the wait syncpoint IOCTL
120 struct drm_tegra_syncpt_wait {
124 * ID of the syncpoint to wait on.
131 * Threshold value for which to wait.
138 * Timeout, in milliseconds, to wait.
145 * The new syncpoint value after the wait. Set by the kernel upon
146 * successful completion of the IOCTL.
151 #define DRM_TEGRA_NO_TIMEOUT (0xffffffff)
154 * struct drm_tegra_open_channel - parameters for the open channel IOCTL
156 struct drm_tegra_open_channel {
160 * The client ID for this channel.
167 * Structure padding that may be used in the future. Must be 0.
174 * The application context of this channel. Set by the kernel upon
175 * successful completion of the IOCTL. This context needs to be passed
176 * to the DRM_TEGRA_CHANNEL_CLOSE or the DRM_TEGRA_SUBMIT IOCTLs.
182 * struct drm_tegra_close_channel - parameters for the close channel IOCTL
184 struct drm_tegra_close_channel {
188 * The application context of this channel. This is obtained from the
189 * DRM_TEGRA_OPEN_CHANNEL IOCTL.
195 * struct drm_tegra_get_syncpt - parameters for the get syncpoint IOCTL
197 struct drm_tegra_get_syncpt {
201 * The application context identifying the channel for which to obtain
209 * Index of the client syncpoint for which to obtain the ID.
216 * The ID of the given syncpoint. Set by the kernel upon successful
217 * completion of the IOCTL.
223 * struct drm_tegra_get_syncpt_base - parameters for the get wait base IOCTL
225 struct drm_tegra_get_syncpt_base {
229 * The application context identifying for which channel to obtain the
237 * ID of the syncpoint for which to obtain the wait base.
244 * The ID of the wait base corresponding to the client syncpoint. Set
245 * by the kernel upon successful completion of the IOCTL.
251 * struct drm_tegra_syncpt - syncpoint increment operation
253 struct drm_tegra_syncpt {
257 * ID of the syncpoint to operate on.
264 * Number of increments to perform for the syncpoint.
270 * struct drm_tegra_cmdbuf - structure describing a command buffer
272 struct drm_tegra_cmdbuf {
276 * Handle to a GEM object containing the command buffer.
283 * Offset, in bytes, into the GEM object identified by @handle at
284 * which the command buffer starts.
291 * Number of 32-bit words in this command buffer.
298 * Structure padding that may be used in the future. Must be 0.
304 * struct drm_tegra_reloc - GEM object relocation structure
306 struct drm_tegra_reloc {
311 * Handle to the GEM object containing the command buffer for
312 * which to perform this GEM object relocation.
319 * Offset, in bytes, into the command buffer at which to
320 * insert the relocated address.
328 * Handle to the GEM object to be relocated.
335 * Offset, in bytes, into the target GEM object at which the
336 * relocated data starts.
344 * The number of bits by which to shift relocated addresses.
351 * Structure padding that may be used in the future. Must be 0.
357 * struct drm_tegra_waitchk - wait check structure
359 struct drm_tegra_waitchk {
363 * Handle to the GEM object containing a command stream on which to
364 * perform the wait check.
371 * Offset, in bytes, of the location in the command stream to perform
379 * ID of the syncpoint to wait check.
386 * Threshold value for which to check.
392 * struct drm_tegra_submit - job submission structure
394 struct drm_tegra_submit {
398 * The application context identifying the channel to use for the
399 * execution of this job.
406 * The number of syncpoints operated on by this job. This defines the
407 * length of the array pointed to by @syncpts.
414 * The number of command buffers to execute as part of this job. This
415 * defines the length of the array pointed to by @cmdbufs.
422 * The number of relocations to perform before executing this job.
423 * This defines the length of the array pointed to by @relocs.
430 * The number of wait checks to perform as part of this job. This
431 * defines the length of the array pointed to by @waitchks.
438 * Bitmask of valid wait checks.
445 * Timeout, in milliseconds, before this job is cancelled.
452 * A pointer to an array of &struct drm_tegra_syncpt structures that
453 * specify the syncpoint operations performed as part of this job.
454 * The number of elements in the array must be equal to the value
455 * given by @num_syncpts.
462 * A pointer to an array of &struct drm_tegra_cmdbuf structures that
463 * define the command buffers to execute as part of this job. The
464 * number of elements in the array must be equal to the value given
472 * A pointer to an array of &struct drm_tegra_reloc structures that
473 * specify the relocations that need to be performed before executing
474 * this job. The number of elements in the array must be equal to the
475 * value given by @num_relocs.
482 * A pointer to an array of &struct drm_tegra_waitchk structures that
483 * specify the wait checks to be performed while executing this job.
484 * The number of elements in the array must be equal to the value
485 * given by @num_waitchks.
492 * The threshold of the syncpoint associated with this job after it
493 * has been completed. Set by the kernel upon successful completion of
494 * the IOCTL. This can be used with the DRM_TEGRA_SYNCPT_WAIT IOCTL to
495 * wait for this job to be finished.
502 * This field is reserved for future use. Must be 0.
507 #define DRM_TEGRA_GEM_TILING_MODE_PITCH 0
508 #define DRM_TEGRA_GEM_TILING_MODE_TILED 1
509 #define DRM_TEGRA_GEM_TILING_MODE_BLOCK 2
512 * struct drm_tegra_gem_set_tiling - parameters for the set tiling IOCTL
514 struct drm_tegra_gem_set_tiling {
518 * Handle to the GEM object for which to set the tiling parameters.
525 * The tiling mode to set. Must be one of:
527 * DRM_TEGRA_GEM_TILING_MODE_PITCH
528 * pitch linear format
530 * DRM_TEGRA_GEM_TILING_MODE_TILED
531 * 16x16 tiling format
533 * DRM_TEGRA_GEM_TILING_MODE_BLOCK
534 * 16Bx2 tiling format
541 * The value to set for the tiling mode parameter.
548 * Structure padding that may be used in the future. Must be 0.
554 * struct drm_tegra_gem_get_tiling - parameters for the get tiling IOCTL
556 struct drm_tegra_gem_get_tiling {
560 * Handle to the GEM object for which to query the tiling parameters.
567 * The tiling mode currently associated with the GEM object. Set by
568 * the kernel upon successful completion of the IOCTL.
575 * The tiling mode parameter currently associated with the GEM object.
576 * Set by the kernel upon successful completion of the IOCTL.
583 * Structure padding that may be used in the future. Must be 0.
588 #define DRM_TEGRA_GEM_BOTTOM_UP (1 << 0)
589 #define DRM_TEGRA_GEM_FLAGS (DRM_TEGRA_GEM_BOTTOM_UP)
592 * struct drm_tegra_gem_set_flags - parameters for the set flags IOCTL
594 struct drm_tegra_gem_set_flags {
598 * Handle to the GEM object for which to set the flags.
605 * The flags to set for the GEM object.
611 * struct drm_tegra_gem_get_flags - parameters for the get flags IOCTL
613 struct drm_tegra_gem_get_flags {
617 * Handle to the GEM object for which to query the flags.
624 * The flags currently associated with the GEM object. Set by the
625 * kernel upon successful completion of the IOCTL.
630 #define DRM_TEGRA_GEM_CREATE 0x00
631 #define DRM_TEGRA_GEM_MMAP 0x01
632 #define DRM_TEGRA_SYNCPT_READ 0x02
633 #define DRM_TEGRA_SYNCPT_INCR 0x03
634 #define DRM_TEGRA_SYNCPT_WAIT 0x04
635 #define DRM_TEGRA_OPEN_CHANNEL 0x05
636 #define DRM_TEGRA_CLOSE_CHANNEL 0x06
637 #define DRM_TEGRA_GET_SYNCPT 0x07
638 #define DRM_TEGRA_SUBMIT 0x08
639 #define DRM_TEGRA_GET_SYNCPT_BASE 0x09
640 #define DRM_TEGRA_GEM_SET_TILING 0x0a
641 #define DRM_TEGRA_GEM_GET_TILING 0x0b
642 #define DRM_TEGRA_GEM_SET_FLAGS 0x0c
643 #define DRM_TEGRA_GEM_GET_FLAGS 0x0d
645 #define DRM_IOCTL_TEGRA_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_GEM_CREATE, struct drm_tegra_gem_create)
646 #define DRM_IOCTL_TEGRA_GEM_MMAP DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_GEM_MMAP, struct drm_tegra_gem_mmap)
647 #define DRM_IOCTL_TEGRA_SYNCPT_READ DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_SYNCPT_READ, struct drm_tegra_syncpt_read)
648 #define DRM_IOCTL_TEGRA_SYNCPT_INCR DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_SYNCPT_INCR, struct drm_tegra_syncpt_incr)
649 #define DRM_IOCTL_TEGRA_SYNCPT_WAIT DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_SYNCPT_WAIT, struct drm_tegra_syncpt_wait)
650 #define DRM_IOCTL_TEGRA_OPEN_CHANNEL DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_OPEN_CHANNEL, struct drm_tegra_open_channel)
651 #define DRM_IOCTL_TEGRA_CLOSE_CHANNEL DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_CLOSE_CHANNEL, struct drm_tegra_close_channel)
652 #define DRM_IOCTL_TEGRA_GET_SYNCPT DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_GET_SYNCPT, struct drm_tegra_get_syncpt)
653 #define DRM_IOCTL_TEGRA_SUBMIT DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_SUBMIT, struct drm_tegra_submit)
654 #define DRM_IOCTL_TEGRA_GET_SYNCPT_BASE DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_GET_SYNCPT_BASE, struct drm_tegra_get_syncpt_base)
655 #define DRM_IOCTL_TEGRA_GEM_SET_TILING DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_GEM_SET_TILING, struct drm_tegra_gem_set_tiling)
656 #define DRM_IOCTL_TEGRA_GEM_GET_TILING DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_GEM_GET_TILING, struct drm_tegra_gem_get_tiling)
657 #define DRM_IOCTL_TEGRA_GEM_SET_FLAGS DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_GEM_SET_FLAGS, struct drm_tegra_gem_set_flags)
658 #define DRM_IOCTL_TEGRA_GEM_GET_FLAGS DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_GEM_GET_FLAGS, struct drm_tegra_gem_get_flags)
660 /* New Tegra DRM UAPI */
663 * Reported by the driver in the `capabilities` field.
665 * DRM_TEGRA_CHANNEL_CAP_CACHE_COHERENT: If set, the engine is cache coherent
666 * with regard to the system memory.
668 #define DRM_TEGRA_CHANNEL_CAP_CACHE_COHERENT (1 << 0)
670 struct drm_tegra_channel_open {
672 * @host1x_class: [in]
674 * Host1x class of the engine that will be programmed using this
689 * Opaque identifier corresponding to the opened channel.
696 * Version of the engine hardware. This can be used by userspace
697 * to determine how the engine needs to be programmed.
702 * @capabilities: [out]
704 * Flags describing the hardware capabilities.
710 struct drm_tegra_channel_close {
714 * Identifier of the channel to close.
721 * Mapping flags that can be used to influence how the mapping is created.
723 * DRM_TEGRA_CHANNEL_MAP_READ: create mapping that allows HW read access
724 * DRM_TEGRA_CHANNEL_MAP_WRITE: create mapping that allows HW write access
726 #define DRM_TEGRA_CHANNEL_MAP_READ (1 << 0)
727 #define DRM_TEGRA_CHANNEL_MAP_WRITE (1 << 1)
728 #define DRM_TEGRA_CHANNEL_MAP_READ_WRITE (DRM_TEGRA_CHANNEL_MAP_READ | \
729 DRM_TEGRA_CHANNEL_MAP_WRITE)
731 struct drm_tegra_channel_map {
735 * Identifier of the channel to which make memory available for.
742 * GEM handle of the memory to map.
756 * Identifier corresponding to the mapping, to be used for
757 * relocations or unmapping later.
762 struct drm_tegra_channel_unmap {
766 * Channel identifier of the channel to unmap memory from.
773 * Mapping identifier of the memory mapping to unmap.
781 * Specify that bit 39 of the patched-in address should be set to switch
782 * swizzling between Tegra and non-Tegra sector layout on systems that store
783 * surfaces in system memory in non-Tegra sector layout.
785 #define DRM_TEGRA_SUBMIT_RELOC_SECTOR_LAYOUT (1 << 0)
787 struct drm_tegra_submit_buf {
791 * Identifier of the mapping to use in the submission.
803 * Information for relocation patching.
807 * @target_offset: [in]
809 * Offset from the start of the mapping of the data whose
810 * address is to be patched into the gather.
815 * @gather_offset_words: [in]
817 * Offset in words from the start of the gather data to
818 * where the address should be patched into.
820 __u32 gather_offset_words;
825 * Number of bits the address should be shifted right before
833 * Execute `words` words of Host1x opcodes specified in the `gather_data_ptr`
834 * buffer. Each GATHER_UPTR command uses successive words from the buffer.
836 #define DRM_TEGRA_SUBMIT_CMD_GATHER_UPTR 0
838 * Wait for a syncpoint to reach a value before continuing with further
841 #define DRM_TEGRA_SUBMIT_CMD_WAIT_SYNCPT 1
843 * Wait for a syncpoint to reach a value before continuing with further
844 * commands. The threshold is calculated relative to the start of the job.
846 #define DRM_TEGRA_SUBMIT_CMD_WAIT_SYNCPT_RELATIVE 2
848 struct drm_tegra_submit_cmd_gather_uptr {
853 struct drm_tegra_submit_cmd_wait_syncpt {
859 struct drm_tegra_submit_cmd {
863 * Command type to execute. One of the DRM_TEGRA_SUBMIT_CMD*
876 struct drm_tegra_submit_cmd_gather_uptr gather_uptr;
877 struct drm_tegra_submit_cmd_wait_syncpt wait_syncpt;
882 struct drm_tegra_submit_syncpt {
886 * ID of the syncpoint that the job will increment.
900 * Number of times the job will increment this syncpoint.
907 * Value the syncpoint will have once the job has completed all
908 * its specified syncpoint increments.
910 * Note that the kernel may increment the syncpoint before or after
911 * the job. These increments are not reflected in this field.
913 * If the job hangs or times out, not all of the increments may
919 struct drm_tegra_channel_submit {
923 * Identifier of the channel to submit this job to.
930 * Number of elements in the `bufs_ptr` array.
937 * Number of elements in the `cmds_ptr` array.
942 * @gather_data_words: [in]
944 * Number of 32-bit words in the `gather_data_ptr` array.
946 __u32 gather_data_words;
951 * Pointer to an array of drm_tegra_submit_buf structures.
958 * Pointer to an array of drm_tegra_submit_cmd structures.
963 * @gather_data_ptr: [in]
965 * Pointer to an array of Host1x opcodes to be used by GATHER_UPTR
968 __u64 gather_data_ptr;
973 * Handle for DRM syncobj that will be waited before submission.
981 * Handle for DRM syncobj that will have its fence replaced with
982 * the job's completion fence. Ignored if zero.
987 * @syncpt_incr: [in,out]
989 * Information about the syncpoint the job will increment.
991 struct drm_tegra_submit_syncpt syncpt;
994 struct drm_tegra_syncpoint_allocate {
998 * ID of allocated syncpoint.
1004 struct drm_tegra_syncpoint_free {
1008 * ID of syncpoint to free.
1014 struct drm_tegra_syncpoint_wait {
1018 * Absolute timestamp at which the wait will time out.
1025 * ID of syncpoint to wait on.
1032 * Threshold to wait for.
1039 * Value of the syncpoint upon wait completion.
1046 #define DRM_IOCTL_TEGRA_CHANNEL_OPEN DRM_IOWR(DRM_COMMAND_BASE + 0x10, struct drm_tegra_channel_open)
1047 #define DRM_IOCTL_TEGRA_CHANNEL_CLOSE DRM_IOWR(DRM_COMMAND_BASE + 0x11, struct drm_tegra_channel_close)
1048 #define DRM_IOCTL_TEGRA_CHANNEL_MAP DRM_IOWR(DRM_COMMAND_BASE + 0x12, struct drm_tegra_channel_map)
1049 #define DRM_IOCTL_TEGRA_CHANNEL_UNMAP DRM_IOWR(DRM_COMMAND_BASE + 0x13, struct drm_tegra_channel_unmap)
1050 #define DRM_IOCTL_TEGRA_CHANNEL_SUBMIT DRM_IOWR(DRM_COMMAND_BASE + 0x14, struct drm_tegra_channel_submit)
1052 #define DRM_IOCTL_TEGRA_SYNCPOINT_ALLOCATE DRM_IOWR(DRM_COMMAND_BASE + 0x20, struct drm_tegra_syncpoint_allocate)
1053 #define DRM_IOCTL_TEGRA_SYNCPOINT_FREE DRM_IOWR(DRM_COMMAND_BASE + 0x21, struct drm_tegra_syncpoint_free)
1054 #define DRM_IOCTL_TEGRA_SYNCPOINT_WAIT DRM_IOWR(DRM_COMMAND_BASE + 0x22, struct drm_tegra_syncpoint_wait)
1056 #if defined(__cplusplus)