/*1* Copyright 2005 Stephane Marchesin.2* All Rights Reserved.3*4* Permission is hereby granted, free of charge, to any person obtaining a5* copy of this software and associated documentation files (the "Software"),6* to deal in the Software without restriction, including without limitation7* the rights to use, copy, modify, merge, publish, distribute, sublicense,8* and/or sell copies of the Software, and to permit persons to whom the9* Software is furnished to do so, subject to the following conditions:10*11* The above copyright notice and this permission notice (including the next12* paragraph) shall be included in all copies or substantial portions of the13* Software.14*15* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL18* VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR19* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,20* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR21* OTHER DEALINGS IN THE SOFTWARE.22*/2324#ifndef __NOUVEAU_DRM_H__25#define __NOUVEAU_DRM_H__2627#define DRM_NOUVEAU_EVENT_NVIF 0x800000002829#include "drm.h"3031#if defined(__cplusplus)32extern "C" {33#endif3435#define NOUVEAU_GETPARAM_PCI_VENDOR 336#define NOUVEAU_GETPARAM_PCI_DEVICE 437#define NOUVEAU_GETPARAM_BUS_TYPE 538#define NOUVEAU_GETPARAM_FB_SIZE 839#define NOUVEAU_GETPARAM_AGP_SIZE 940#define NOUVEAU_GETPARAM_CHIPSET_ID 1141#define NOUVEAU_GETPARAM_VM_VRAM_BASE 1242#define NOUVEAU_GETPARAM_GRAPH_UNITS 1343#define NOUVEAU_GETPARAM_PTIMER_TIME 1444#define NOUVEAU_GETPARAM_HAS_BO_USAGE 1545#define NOUVEAU_GETPARAM_HAS_PAGEFLIP 164647/*48* NOUVEAU_GETPARAM_EXEC_PUSH_MAX - query max pushes through getparam49*50* Query the maximum amount of IBs that can be pushed through a single51* &drm_nouveau_exec structure and hence a single &DRM_IOCTL_NOUVEAU_EXEC52* ioctl().53*/54#define NOUVEAU_GETPARAM_EXEC_PUSH_MAX 175556/*57* NOUVEAU_GETPARAM_VRAM_BAR_SIZE - query bar size58*59* Query the VRAM BAR size.60*/61#define NOUVEAU_GETPARAM_VRAM_BAR_SIZE 186263/*64* NOUVEAU_GETPARAM_VRAM_USED65*66* Get remaining VRAM size.67*/68#define NOUVEAU_GETPARAM_VRAM_USED 196970/*71* NOUVEAU_GETPARAM_HAS_VMA_TILEMODE72*73* Query whether tile mode and PTE kind are accepted with VM allocs or not.74*/75#define NOUVEAU_GETPARAM_HAS_VMA_TILEMODE 207677struct drm_nouveau_getparam {78__u64 param;79__u64 value;80};8182/*83* Those are used to support selecting the main engine used on Kepler.84* This goes into drm_nouveau_channel_alloc::tt_ctxdma_handle85*/86#define NOUVEAU_FIFO_ENGINE_GR 0x0187#define NOUVEAU_FIFO_ENGINE_VP 0x0288#define NOUVEAU_FIFO_ENGINE_PPP 0x0489#define NOUVEAU_FIFO_ENGINE_BSP 0x0890#define NOUVEAU_FIFO_ENGINE_CE 0x309192struct drm_nouveau_channel_alloc {93__u32 fb_ctxdma_handle;94__u32 tt_ctxdma_handle;9596__s32 channel;97__u32 pushbuf_domains;9899/* Notifier memory */100__u32 notifier_handle;101102/* DRM-enforced subchannel assignments */103struct {104__u32 handle;105__u32 grclass;106} subchan[8];107__u32 nr_subchan;108};109110struct drm_nouveau_channel_free {111__s32 channel;112};113114struct drm_nouveau_notifierobj_alloc {115__u32 channel;116__u32 handle;117__u32 size;118__u32 offset;119};120121struct drm_nouveau_gpuobj_free {122__s32 channel;123__u32 handle;124};125126#define NOUVEAU_GEM_DOMAIN_CPU (1 << 0)127#define NOUVEAU_GEM_DOMAIN_VRAM (1 << 1)128#define NOUVEAU_GEM_DOMAIN_GART (1 << 2)129#define NOUVEAU_GEM_DOMAIN_MAPPABLE (1 << 3)130#define NOUVEAU_GEM_DOMAIN_COHERENT (1 << 4)131/* The BO will never be shared via import or export. */132#define NOUVEAU_GEM_DOMAIN_NO_SHARE (1 << 5)133134#define NOUVEAU_GEM_TILE_COMP 0x00030000 /* nv50-only */135#define NOUVEAU_GEM_TILE_LAYOUT_MASK 0x0000ff00136#define NOUVEAU_GEM_TILE_16BPP 0x00000001137#define NOUVEAU_GEM_TILE_32BPP 0x00000002138#define NOUVEAU_GEM_TILE_ZETA 0x00000004139#define NOUVEAU_GEM_TILE_NONCONTIG 0x00000008140141struct drm_nouveau_gem_info {142__u32 handle;143__u32 domain;144__u64 size;145__u64 offset;146__u64 map_handle;147__u32 tile_mode;148__u32 tile_flags;149};150151struct drm_nouveau_gem_new {152struct drm_nouveau_gem_info info;153__u32 channel_hint;154__u32 align;155};156157#define NOUVEAU_GEM_MAX_BUFFERS 1024158struct drm_nouveau_gem_pushbuf_bo_presumed {159__u32 valid;160__u32 domain;161__u64 offset;162};163164struct drm_nouveau_gem_pushbuf_bo {165__u64 user_priv;166__u32 handle;167__u32 read_domains;168__u32 write_domains;169__u32 valid_domains;170struct drm_nouveau_gem_pushbuf_bo_presumed presumed;171};172173#define NOUVEAU_GEM_RELOC_LOW (1 << 0)174#define NOUVEAU_GEM_RELOC_HIGH (1 << 1)175#define NOUVEAU_GEM_RELOC_OR (1 << 2)176#define NOUVEAU_GEM_MAX_RELOCS 1024177struct drm_nouveau_gem_pushbuf_reloc {178__u32 reloc_bo_index;179__u32 reloc_bo_offset;180__u32 bo_index;181__u32 flags;182__u32 data;183__u32 vor;184__u32 tor;185};186187#define NOUVEAU_GEM_MAX_PUSH 512188struct drm_nouveau_gem_pushbuf_push {189__u32 bo_index;190__u32 pad;191__u64 offset;192__u64 length;193#define NOUVEAU_GEM_PUSHBUF_NO_PREFETCH (1 << 23)194};195196struct drm_nouveau_gem_pushbuf {197__u32 channel;198__u32 nr_buffers;199__u64 buffers;200__u32 nr_relocs;201__u32 nr_push;202__u64 relocs;203__u64 push;204__u32 suffix0;205__u32 suffix1;206#define NOUVEAU_GEM_PUSHBUF_SYNC (1ULL << 0)207__u64 vram_available;208__u64 gart_available;209};210211#define NOUVEAU_GEM_CPU_PREP_NOWAIT 0x00000001212#define NOUVEAU_GEM_CPU_PREP_WRITE 0x00000004213struct drm_nouveau_gem_cpu_prep {214__u32 handle;215__u32 flags;216};217218struct drm_nouveau_gem_cpu_fini {219__u32 handle;220};221222/**223* struct drm_nouveau_sync - sync object224*225* This structure serves as synchronization mechanism for (potentially)226* asynchronous operations such as EXEC or VM_BIND.227*/228struct drm_nouveau_sync {229/**230* @flags: the flags for a sync object231*232* The first 8 bits are used to determine the type of the sync object.233*/234__u32 flags;235#define DRM_NOUVEAU_SYNC_SYNCOBJ 0x0236#define DRM_NOUVEAU_SYNC_TIMELINE_SYNCOBJ 0x1237#define DRM_NOUVEAU_SYNC_TYPE_MASK 0xf238/**239* @handle: the handle of the sync object240*/241__u32 handle;242/**243* @timeline_value:244*245* The timeline point of the sync object in case the syncobj is of246* type DRM_NOUVEAU_SYNC_TIMELINE_SYNCOBJ.247*/248__u64 timeline_value;249};250251/**252* struct drm_nouveau_vm_init - GPU VA space init structure253*254* Used to initialize the GPU's VA space for a user client, telling the kernel255* which portion of the VA space is managed by the UMD and kernel respectively.256*257* For the UMD to use the VM_BIND uAPI, this must be called before any BOs or258* channels are created; if called afterwards DRM_IOCTL_NOUVEAU_VM_INIT fails259* with -ENOSYS.260*/261struct drm_nouveau_vm_init {262/**263* @kernel_managed_addr: start address of the kernel managed VA space264* region265*/266__u64 kernel_managed_addr;267/**268* @kernel_managed_size: size of the kernel managed VA space region in269* bytes270*/271__u64 kernel_managed_size;272};273274/**275* struct drm_nouveau_vm_bind_op - VM_BIND operation276*277* This structure represents a single VM_BIND operation. UMDs should pass278* an array of this structure via struct drm_nouveau_vm_bind's &op_ptr field.279*/280struct drm_nouveau_vm_bind_op {281/**282* @op: the operation type283*284* Supported values:285*286* %DRM_NOUVEAU_VM_BIND_OP_MAP - Map a GEM object to the GPU's VA287* space. Optionally, the &DRM_NOUVEAU_VM_BIND_SPARSE flag can be288* passed to instruct the kernel to create sparse mappings for the289* given range.290*291* %DRM_NOUVEAU_VM_BIND_OP_UNMAP - Unmap an existing mapping in the292* GPU's VA space. If the region the mapping is located in is a293* sparse region, new sparse mappings are created where the unmapped294* (memory backed) mapping was mapped previously. To remove a sparse295* region the &DRM_NOUVEAU_VM_BIND_SPARSE must be set.296*/297__u32 op;298#define DRM_NOUVEAU_VM_BIND_OP_MAP 0x0299#define DRM_NOUVEAU_VM_BIND_OP_UNMAP 0x1300/**301* @flags: the flags for a &drm_nouveau_vm_bind_op302*303* Supported values:304*305* %DRM_NOUVEAU_VM_BIND_SPARSE - Indicates that an allocated VA306* space region should be sparse.307*/308__u32 flags;309#define DRM_NOUVEAU_VM_BIND_SPARSE (1 << 8)310/**311* @handle: the handle of the DRM GEM object to map312*/313__u32 handle;314/**315* @pad: 32 bit padding, should be 0316*/317__u32 pad;318/**319* @addr:320*321* the address the VA space region or (memory backed) mapping should be mapped to322*/323__u64 addr;324/**325* @bo_offset: the offset within the BO backing the mapping326*/327__u64 bo_offset;328/**329* @range: the size of the requested mapping in bytes330*/331__u64 range;332};333334/**335* struct drm_nouveau_vm_bind - structure for DRM_IOCTL_NOUVEAU_VM_BIND336*/337struct drm_nouveau_vm_bind {338/**339* @op_count: the number of &drm_nouveau_vm_bind_op340*/341__u32 op_count;342/**343* @flags: the flags for a &drm_nouveau_vm_bind ioctl344*345* Supported values:346*347* %DRM_NOUVEAU_VM_BIND_RUN_ASYNC - Indicates that the given VM_BIND348* operation should be executed asynchronously by the kernel.349*350* If this flag is not supplied the kernel executes the associated351* operations synchronously and doesn't accept any &drm_nouveau_sync352* objects.353*/354__u32 flags;355#define DRM_NOUVEAU_VM_BIND_RUN_ASYNC 0x1356/**357* @wait_count: the number of wait &drm_nouveau_syncs358*/359__u32 wait_count;360/**361* @sig_count: the number of &drm_nouveau_syncs to signal when finished362*/363__u32 sig_count;364/**365* @wait_ptr: pointer to &drm_nouveau_syncs to wait for366*/367__u64 wait_ptr;368/**369* @sig_ptr: pointer to &drm_nouveau_syncs to signal when finished370*/371__u64 sig_ptr;372/**373* @op_ptr: pointer to the &drm_nouveau_vm_bind_ops to execute374*/375__u64 op_ptr;376};377378/**379* struct drm_nouveau_exec_push - EXEC push operation380*381* This structure represents a single EXEC push operation. UMDs should pass an382* array of this structure via struct drm_nouveau_exec's &push_ptr field.383*/384struct drm_nouveau_exec_push {385/**386* @va: the virtual address of the push buffer mapping387*/388__u64 va;389/**390* @va_len: the length of the push buffer mapping391*/392__u32 va_len;393/**394* @flags: the flags for this push buffer mapping395*/396__u32 flags;397#define DRM_NOUVEAU_EXEC_PUSH_NO_PREFETCH 0x1398};399400/**401* struct drm_nouveau_exec - structure for DRM_IOCTL_NOUVEAU_EXEC402*/403struct drm_nouveau_exec {404/**405* @channel: the channel to execute the push buffer in406*/407__u32 channel;408/**409* @push_count: the number of &drm_nouveau_exec_push ops410*/411__u32 push_count;412/**413* @wait_count: the number of wait &drm_nouveau_syncs414*/415__u32 wait_count;416/**417* @sig_count: the number of &drm_nouveau_syncs to signal when finished418*/419__u32 sig_count;420/**421* @wait_ptr: pointer to &drm_nouveau_syncs to wait for422*/423__u64 wait_ptr;424/**425* @sig_ptr: pointer to &drm_nouveau_syncs to signal when finished426*/427__u64 sig_ptr;428/**429* @push_ptr: pointer to &drm_nouveau_exec_push ops430*/431__u64 push_ptr;432};433434#define DRM_NOUVEAU_GETPARAM 0x00435#define DRM_NOUVEAU_SETPARAM 0x01 /* deprecated */436#define DRM_NOUVEAU_CHANNEL_ALLOC 0x02437#define DRM_NOUVEAU_CHANNEL_FREE 0x03438#define DRM_NOUVEAU_GROBJ_ALLOC 0x04 /* deprecated */439#define DRM_NOUVEAU_NOTIFIEROBJ_ALLOC 0x05 /* deprecated */440#define DRM_NOUVEAU_GPUOBJ_FREE 0x06 /* deprecated */441#define DRM_NOUVEAU_NVIF 0x07442#define DRM_NOUVEAU_SVM_INIT 0x08443#define DRM_NOUVEAU_SVM_BIND 0x09444#define DRM_NOUVEAU_VM_INIT 0x10445#define DRM_NOUVEAU_VM_BIND 0x11446#define DRM_NOUVEAU_EXEC 0x12447#define DRM_NOUVEAU_GEM_NEW 0x40448#define DRM_NOUVEAU_GEM_PUSHBUF 0x41449#define DRM_NOUVEAU_GEM_CPU_PREP 0x42450#define DRM_NOUVEAU_GEM_CPU_FINI 0x43451#define DRM_NOUVEAU_GEM_INFO 0x44452453struct drm_nouveau_svm_init {454__u64 unmanaged_addr;455__u64 unmanaged_size;456};457458struct drm_nouveau_svm_bind {459__u64 header;460__u64 va_start;461__u64 va_end;462__u64 npages;463__u64 stride;464__u64 result;465__u64 reserved0;466__u64 reserved1;467};468469#define NOUVEAU_SVM_BIND_COMMAND_SHIFT 0470#define NOUVEAU_SVM_BIND_COMMAND_BITS 8471#define NOUVEAU_SVM_BIND_COMMAND_MASK ((1 << 8) - 1)472#define NOUVEAU_SVM_BIND_PRIORITY_SHIFT 8473#define NOUVEAU_SVM_BIND_PRIORITY_BITS 8474#define NOUVEAU_SVM_BIND_PRIORITY_MASK ((1 << 8) - 1)475#define NOUVEAU_SVM_BIND_TARGET_SHIFT 16476#define NOUVEAU_SVM_BIND_TARGET_BITS 32477#define NOUVEAU_SVM_BIND_TARGET_MASK 0xffffffff478479/*480* Below is use to validate ioctl argument, userspace can also use it to make481* sure that no bit are set beyond known fields for a given kernel version.482*/483#define NOUVEAU_SVM_BIND_VALID_BITS 48484#define NOUVEAU_SVM_BIND_VALID_MASK ((1ULL << NOUVEAU_SVM_BIND_VALID_BITS) - 1)485486487/*488* NOUVEAU_BIND_COMMAND__MIGRATE: synchronous migrate to target memory.489* result: number of page successfuly migrate to the target memory.490*/491#define NOUVEAU_SVM_BIND_COMMAND__MIGRATE 0492493/*494* NOUVEAU_SVM_BIND_HEADER_TARGET__GPU_VRAM: target the GPU VRAM memory.495*/496#define NOUVEAU_SVM_BIND_TARGET__GPU_VRAM (1UL << 31)497498499#define DRM_IOCTL_NOUVEAU_GETPARAM DRM_IOWR(DRM_COMMAND_BASE + DRM_NOUVEAU_GETPARAM, struct drm_nouveau_getparam)500#define DRM_IOCTL_NOUVEAU_CHANNEL_ALLOC DRM_IOWR(DRM_COMMAND_BASE + DRM_NOUVEAU_CHANNEL_ALLOC, struct drm_nouveau_channel_alloc)501#define DRM_IOCTL_NOUVEAU_CHANNEL_FREE DRM_IOW (DRM_COMMAND_BASE + DRM_NOUVEAU_CHANNEL_FREE, struct drm_nouveau_channel_free)502503#define DRM_IOCTL_NOUVEAU_SVM_INIT DRM_IOWR(DRM_COMMAND_BASE + DRM_NOUVEAU_SVM_INIT, struct drm_nouveau_svm_init)504#define DRM_IOCTL_NOUVEAU_SVM_BIND DRM_IOWR(DRM_COMMAND_BASE + DRM_NOUVEAU_SVM_BIND, struct drm_nouveau_svm_bind)505506#define DRM_IOCTL_NOUVEAU_GEM_NEW DRM_IOWR(DRM_COMMAND_BASE + DRM_NOUVEAU_GEM_NEW, struct drm_nouveau_gem_new)507#define DRM_IOCTL_NOUVEAU_GEM_PUSHBUF DRM_IOWR(DRM_COMMAND_BASE + DRM_NOUVEAU_GEM_PUSHBUF, struct drm_nouveau_gem_pushbuf)508#define DRM_IOCTL_NOUVEAU_GEM_CPU_PREP DRM_IOW (DRM_COMMAND_BASE + DRM_NOUVEAU_GEM_CPU_PREP, struct drm_nouveau_gem_cpu_prep)509#define DRM_IOCTL_NOUVEAU_GEM_CPU_FINI DRM_IOW (DRM_COMMAND_BASE + DRM_NOUVEAU_GEM_CPU_FINI, struct drm_nouveau_gem_cpu_fini)510#define DRM_IOCTL_NOUVEAU_GEM_INFO DRM_IOWR(DRM_COMMAND_BASE + DRM_NOUVEAU_GEM_INFO, struct drm_nouveau_gem_info)511512#define DRM_IOCTL_NOUVEAU_VM_INIT DRM_IOWR(DRM_COMMAND_BASE + DRM_NOUVEAU_VM_INIT, struct drm_nouveau_vm_init)513#define DRM_IOCTL_NOUVEAU_VM_BIND DRM_IOWR(DRM_COMMAND_BASE + DRM_NOUVEAU_VM_BIND, struct drm_nouveau_vm_bind)514#define DRM_IOCTL_NOUVEAU_EXEC DRM_IOWR(DRM_COMMAND_BASE + DRM_NOUVEAU_EXEC, struct drm_nouveau_exec)515#if defined(__cplusplus)516}517#endif518519#endif /* __NOUVEAU_DRM_H__ */520521522