Import of XFree86 3.9.17
[platform/upstream/libdrm.git] / linux / drm.h
1 /* drm.h -- Header for Direct Rendering Manager -*- linux-c -*-
2  * Created: Mon Jan  4 10:05:05 1999 by faith@precisioninsight.com
3  * Revised: Mon Dec  6 17:11:19 1999 by faith@precisioninsight.com
4  *
5  * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
6  * All rights reserved.
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a
9  * copy of this software and associated documentation files (the "Software"),
10  * to deal in the Software without restriction, including without limitation
11  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12  * and/or sell copies of the Software, and to permit persons to whom the
13  * Software is furnished to do so, subject to the following conditions:
14  * 
15  * The above copyright notice and this permission notice (including the next
16  * paragraph) shall be included in all copies or substantial portions of the
17  * Software.
18  * 
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
22  * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25  * DEALINGS IN THE SOFTWARE.
26  * 
27  * $PI: xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/drm.h,v 1.46 1999/08/20 20:00:53 faith Exp $
28  * $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/drm.h,v 1.2 1999/12/14 01:33:56 robin Exp $
29  *
30  * Acknowledgements:
31  * Dec 1999, Richard Henderson <rth@twiddle.net>, move to generic cmpxchg.
32  *
33  */
34
35 #ifndef _DRM_H_
36 #define _DRM_H_
37
38 #include <asm/ioctl.h>          /* For _IO* macros */
39
40 #define DRM_PROC_DEVICES "/proc/devices"
41 #define DRM_PROC_MISC    "/proc/misc"
42 #define DRM_PROC_DRM     "/proc/drm"
43 #define DRM_DEV_DRM      "/dev/drm"
44 #define DRM_DEV_MODE     (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)
45 #define DRM_DEV_UID      0
46 #define DRM_DEV_GID      0
47
48
49 #define DRM_NAME        "drm"     /* Name in kernel, /dev, and /proc        */
50 #define DRM_MIN_ORDER   5         /* At least 2^5 bytes = 32 bytes          */
51 #define DRM_MAX_ORDER   22        /* Up to 2^22 bytes = 4MB                 */
52 #define DRM_RAM_PERCENT 10        /* How much system ram can we lock?       */
53
54 #define _DRM_LOCK_HELD  0x80000000 /* Hardware lock is held                 */
55 #define _DRM_LOCK_CONT  0x40000000 /* Hardware lock is contended            */
56 #define _DRM_LOCK_IS_HELD(lock)    ((lock) & _DRM_LOCK_HELD)
57 #define _DRM_LOCK_IS_CONT(lock)    ((lock) & _DRM_LOCK_CONT)
58 #define _DRM_LOCKING_CONTEXT(lock) ((lock) & ~(_DRM_LOCK_HELD|_DRM_LOCK_CONT))
59
60 typedef unsigned long drm_handle_t;
61 typedef unsigned int  drm_context_t;
62 typedef unsigned int  drm_drawable_t;
63 typedef unsigned int  drm_magic_t;
64
65
66 typedef struct drm_version {
67         int    version_major;     /* Major version                          */
68         int    version_minor;     /* Minor version                          */
69         int    version_patchlevel;/* Patch level                            */
70         size_t name_len;          /* Length of name buffer                  */
71         char   *name;             /* Name of driver                         */
72         size_t date_len;          /* Length of date buffer                  */
73         char   *date;             /* User-space buffer to hold date         */
74         size_t desc_len;          /* Length of desc buffer                  */
75         char   *desc;             /* User-space buffer to hold desc         */
76 } drm_version_t;
77
78 typedef struct drm_unique {
79         size_t unique_len;        /* Length of unique                       */
80         char   *unique;           /* Unique name for driver instantiation   */
81 } drm_unique_t;
82
83 typedef struct drm_list {
84         int              count;   /* Length of user-space structures        */
85         drm_version_t    *version;
86 } drm_list_t;
87
88 typedef struct drm_block {
89         int              unused;
90 } drm_block_t;
91
92 typedef struct drm_control {
93         enum {
94                 DRM_ADD_COMMAND,
95                 DRM_RM_COMMAND,
96                 DRM_INST_HANDLER,
97                 DRM_UNINST_HANDLER
98         }                func;
99         int              irq;
100 } drm_control_t;
101
102 typedef enum drm_map_type {
103         _DRM_FRAME_BUFFER = 0,    /* WC (no caching), no core dump          */
104         _DRM_REGISTERS    = 1,    /* no caching, no core dump               */
105         _DRM_SHM          = 2     /* shared, cached                         */
106 } drm_map_type_t;
107
108 typedef enum drm_map_flags {
109         _DRM_RESTRICTED      = 0x01, /* Cannot be mapped to user-virtual    */
110         _DRM_READ_ONLY       = 0x02,
111         _DRM_LOCKED          = 0x04, /* shared, cached, locked              */
112         _DRM_KERNEL          = 0x08, /* kernel requires access              */
113         _DRM_WRITE_COMBINING = 0x10, /* use write-combining if available    */
114         _DRM_CONTAINS_LOCK   = 0x20  /* SHM page that contains lock         */
115 } drm_map_flags_t;
116
117 typedef struct drm_map {
118         unsigned long   offset;  /* Requested physical address (0 for SAREA)*/
119         unsigned long   size;    /* Requested physical size (bytes)         */
120         drm_map_type_t  type;    /* Type of memory to map                   */
121         drm_map_flags_t flags;   /* Flags                                   */
122         void            *handle; /* User-space: "Handle" to pass to mmap    */
123                                  /* Kernel-space: kernel-virtual address    */
124         int             mtrr;    /* MTRR slot used                          */
125                                  /* Private data                            */
126 } drm_map_t;
127
128 typedef enum drm_lock_flags {
129         _DRM_LOCK_READY      = 0x01, /* Wait until hardware is ready for DMA */
130         _DRM_LOCK_QUIESCENT  = 0x02, /* Wait until hardware quiescent        */
131         _DRM_LOCK_FLUSH      = 0x04, /* Flush this context's DMA queue first */
132         _DRM_LOCK_FLUSH_ALL  = 0x08, /* Flush all DMA queues first           */
133                                 /* These *HALT* flags aren't supported yet
134                                    -- they will be used to support the
135                                    full-screen DGA-like mode. */
136         _DRM_HALT_ALL_QUEUES = 0x10, /* Halt all current and future queues   */
137         _DRM_HALT_CUR_QUEUES = 0x20  /* Halt all current queues              */
138 } drm_lock_flags_t;
139
140 typedef struct drm_lock {
141         int              context;
142         drm_lock_flags_t flags;
143 } drm_lock_t;
144
145 typedef enum drm_dma_flags {          /* These values *MUST* match xf86drm.h */
146                                       /* Flags for DMA buffer dispatch       */
147         _DRM_DMA_BLOCK        = 0x01, /* Block until buffer dispatched.
148                                          Note, the buffer may not yet have
149                                          been processed by the hardware --
150                                          getting a hardware lock with the
151                                          hardware quiescent will ensure
152                                          that the buffer has been
153                                          processed.                          */
154         _DRM_DMA_WHILE_LOCKED = 0x02, /* Dispatch while lock held            */
155         _DRM_DMA_PRIORITY     = 0x04, /* High priority dispatch              */
156
157                                       /* Flags for DMA buffer request        */
158         _DRM_DMA_WAIT         = 0x10, /* Wait for free buffers               */
159         _DRM_DMA_SMALLER_OK   = 0x20, /* Smaller-than-requested buffers ok   */
160         _DRM_DMA_LARGER_OK    = 0x40  /* Larger-than-requested buffers ok    */
161 } drm_dma_flags_t;
162
163 typedef struct drm_buf_desc {
164         int           count;     /* Number of buffers of this size           */
165         int           size;      /* Size in bytes                            */
166         int           low_mark;  /* Low water mark                           */
167         int           high_mark; /* High water mark                          */
168         enum {
169                 DRM_PAGE_ALIGN = 0x01  /* Align on page boundaries for DMA   */
170         }             flags;
171 } drm_buf_desc_t;
172
173 typedef struct drm_buf_info {
174         int            count;   /* Entries in list                           */
175         drm_buf_desc_t *list;
176 } drm_buf_info_t;
177
178 typedef struct drm_buf_free {
179         int            count;
180         int            *list;
181 } drm_buf_free_t;
182
183 typedef struct drm_buf_pub {
184         int               idx;         /* Index into master buflist          */
185         int               total;       /* Buffer size                        */
186         int               used;        /* Amount of buffer in use (for DMA)  */
187         void              *address;    /* Address of buffer                  */
188 } drm_buf_pub_t;
189
190 typedef struct drm_buf_map {
191         int           count;    /* Length of buflist                        */
192         void          *virtual; /* Mmaped area in user-virtual              */
193         drm_buf_pub_t *list;    /* Buffer information                       */
194 } drm_buf_map_t;
195
196 typedef struct drm_dma {
197                                 /* Indices here refer to the offset into
198                                    buflist in drm_buf_get_t.  */
199         int             context;          /* Context handle                 */
200         int             send_count;       /* Number of buffers to send      */
201         int             *send_indices;    /* List of handles to buffers     */
202         int             *send_sizes;      /* Lengths of data to send        */
203         drm_dma_flags_t flags;            /* Flags                          */
204         int             request_count;    /* Number of buffers requested    */
205         int             request_size;     /* Desired size for buffers       */
206         int             *request_indices; /* Buffer information             */
207         int             *request_sizes;
208         int             granted_count;    /* Number of buffers granted      */
209 } drm_dma_t;
210
211 typedef enum {
212         _DRM_CONTEXT_PRESERVED = 0x01,
213         _DRM_CONTEXT_2DONLY    = 0x02
214 } drm_ctx_flags_t;
215
216 typedef struct drm_ctx {
217         drm_context_t   handle;
218         drm_ctx_flags_t flags;
219 } drm_ctx_t;
220
221 typedef struct drm_ctx_res {
222         int             count;
223         drm_ctx_t       *contexts;
224 } drm_ctx_res_t;
225
226 typedef struct drm_draw {
227         drm_drawable_t  handle;
228 } drm_draw_t;
229
230 typedef struct drm_auth {
231         drm_magic_t     magic;
232 } drm_auth_t;
233
234 typedef struct drm_irq_busid {
235         int irq;
236         int busnum;
237         int devnum;
238         int funcnum;
239 } drm_irq_busid_t;
240
241 #define DRM_IOCTL_BASE       'd'
242 #define DRM_IOCTL_NR(n)      _IOC_NR(n)
243 #define DRM_IO(nr)           _IO(DRM_IOCTL_BASE,nr)
244 #define DRM_IOR(nr,size)     _IOR(DRM_IOCTL_BASE,nr,size)
245 #define DRM_IOW(nr,size)     _IOW(DRM_IOCTL_BASE,nr,size)
246 #define DRM_IOWR(nr,size)    _IOWR(DRM_IOCTL_BASE,nr,size)
247
248
249 #define DRM_IOCTL_VERSION    DRM_IOWR(0x00, drm_version_t)
250 #define DRM_IOCTL_GET_UNIQUE DRM_IOWR(0x01, drm_unique_t)
251 #define DRM_IOCTL_GET_MAGIC  DRM_IOW( 0x02, drm_auth_t)
252 #define DRM_IOCTL_IRQ_BUSID  DRM_IOWR(0x03, drm_irq_busid_t)
253
254 #define DRM_IOCTL_SET_UNIQUE DRM_IOW( 0x10, drm_unique_t)
255 #define DRM_IOCTL_AUTH_MAGIC DRM_IOW( 0x11, drm_auth_t)
256 #define DRM_IOCTL_BLOCK      DRM_IOWR(0x12, drm_block_t)
257 #define DRM_IOCTL_UNBLOCK    DRM_IOWR(0x13, drm_block_t)
258 #define DRM_IOCTL_CONTROL    DRM_IOW( 0x14, drm_control_t)
259 #define DRM_IOCTL_ADD_MAP    DRM_IOWR(0x15, drm_map_t)
260 #define DRM_IOCTL_ADD_BUFS   DRM_IOWR(0x16, drm_buf_desc_t)
261 #define DRM_IOCTL_MARK_BUFS  DRM_IOW( 0x17, drm_buf_desc_t)
262 #define DRM_IOCTL_INFO_BUFS  DRM_IOWR(0x18, drm_buf_info_t)
263 #define DRM_IOCTL_MAP_BUFS   DRM_IOWR(0x19, drm_buf_map_t)
264 #define DRM_IOCTL_FREE_BUFS  DRM_IOW( 0x1a, drm_buf_free_t)
265
266 #define DRM_IOCTL_ADD_CTX    DRM_IOWR(0x20, drm_ctx_t)
267 #define DRM_IOCTL_RM_CTX     DRM_IOWR(0x21, drm_ctx_t)
268 #define DRM_IOCTL_MOD_CTX    DRM_IOW( 0x22, drm_ctx_t)
269 #define DRM_IOCTL_GET_CTX    DRM_IOWR(0x23, drm_ctx_t)
270 #define DRM_IOCTL_SWITCH_CTX DRM_IOW( 0x24, drm_ctx_t)
271 #define DRM_IOCTL_NEW_CTX    DRM_IOW( 0x25, drm_ctx_t)
272 #define DRM_IOCTL_RES_CTX    DRM_IOWR(0x26, drm_ctx_res_t)
273 #define DRM_IOCTL_ADD_DRAW   DRM_IOWR(0x27, drm_draw_t)
274 #define DRM_IOCTL_RM_DRAW    DRM_IOWR(0x28, drm_draw_t)
275 #define DRM_IOCTL_DMA        DRM_IOWR(0x29, drm_dma_t)
276 #define DRM_IOCTL_LOCK       DRM_IOW( 0x2a, drm_lock_t)
277 #define DRM_IOCTL_UNLOCK     DRM_IOW( 0x2b, drm_lock_t)
278 #define DRM_IOCTL_FINISH     DRM_IOW( 0x2c, drm_lock_t)
279
280 #endif