More verbose error reporting in some cases.
[profile/ivi/libdrm.git] / libdrm / xf86mm.h
1 /**************************************************************************
2  * 
3  * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND. USA.
4  * All Rights Reserved.
5  * 
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sub license, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  * 
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
17  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, 
18  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 
19  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 
20  * USE OR OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * The above copyright notice and this permission notice (including the
23  * next paragraph) shall be included in all copies or substantial portions
24  * of the Software.
25  * 
26  * 
27  **************************************************************************/
28
29 #ifndef _XF86MM_H_
30 #define _XF86MM_H_
31 #include <stddef.h>
32 #include "drm.h"
33
34 /*
35  * Note on multithreaded applications using this interface.
36  * Libdrm is not threadsafe, so common buffer, TTM, and fence objects need to
37  * be protected using an external mutex.
38  *
39  * Note: Don't protect the following functions, as it may lead to deadlocks:
40  * drmBOUnmap(), drmFenceBuffers().
41  * The kernel is synchronizing and refcounting buffer maps. 
42  * User space only needs to refcount object usage within the same application.
43  */
44
45
46 /*
47  * List macros heavily inspired by the Linux kernel
48  * list handling. No list looping yet.
49  */
50
51 typedef struct _drmMMListHead
52 {
53     struct _drmMMListHead *prev;
54     struct _drmMMListHead *next;
55 } drmMMListHead;
56
57 #define DRMINITLISTHEAD(__item)                \
58   do{                                          \
59     (__item)->prev = (__item);                 \
60     (__item)->next = (__item);                 \
61   } while (0)
62
63 #define DRMLISTADD(__item, __list)                      \
64   do {                                          \
65     (__item)->prev = (__list);                  \
66     (__item)->next = (__list)->next;            \
67     (__list)->next->prev = (__item);            \
68     (__list)->next = (__item);                  \
69   } while (0)
70
71 #define DRMLISTADDTAIL(__item, __list)          \
72   do {                                          \
73     (__item)->next = (__list);                  \
74     (__item)->prev = (__list)->prev;            \
75     (__list)->prev->next = (__item);            \
76     (__list)->prev = (__item);                  \
77   } while(0)
78
79 #define DRMLISTDEL(__item)                      \
80   do {                                          \
81     (__item)->prev->next = (__item)->next;      \
82     (__item)->next->prev = (__item)->prev;      \
83   } while(0)
84
85 #define DRMLISTDELINIT(__item)                  \
86   do {                                          \
87     (__item)->prev->next = (__item)->next;      \
88     (__item)->next->prev = (__item)->prev;      \
89     (__item)->next = (__item);                  \
90     (__item)->prev = (__item);                  \
91   } while(0)
92
93 #define DRMLISTENTRY(__type, __item, __field)   \
94     ((__type *)(((char *) (__item)) - offsetof(__type, __field)))
95
96 typedef struct _drmFence{
97         unsigned handle;
98         int class;
99         unsigned type; 
100         unsigned flags;
101         unsigned signaled;
102 } drmFence;
103
104 typedef struct _drmTTM{
105         unsigned handle;
106         drm_handle_t user_token;
107         unsigned flags;
108         unsigned long size;
109         void *virtual;
110         int mapCount;
111 } drmTTM;
112
113 typedef struct _drmBO{
114     drm_bo_type_t type;
115     unsigned handle;
116     drm_handle_t mapHandle;
117     unsigned flags;
118     unsigned mask;
119     unsigned mapFlags;
120     unsigned long size;
121     unsigned long offset;
122     unsigned long start;
123     unsigned replyFlags;
124     unsigned fenceFlags;
125     void *virtual;
126     void *mapVirtual;
127     int mapCount;
128     drmTTM *ttm;
129 } drmBO;
130
131
132 typedef struct _drmBONode {
133     drmMMListHead head;
134     drmBO *buf;
135     drm_bo_arg_t bo_arg;
136     unsigned long arg0;
137     unsigned long arg1;
138 } drmBONode;
139
140 typedef struct _drmBOList {
141     unsigned numTarget;
142     unsigned numCurrent;
143     unsigned numOnList;
144     drmMMListHead list;
145     drmMMListHead free;
146 } drmBOList;
147
148 /* Fencing */
149
150 extern int           drmFenceCreate(int fd, unsigned flags, int class,
151                                     unsigned type, 
152                                     drmFence *fence);
153 extern int           drmFenceDestroy(int fd, const drmFence *fence);
154 extern int           drmFenceReference(int fd, unsigned handle, drmFence *fence);
155 extern int           drmFenceUnreference(int fd, const drmFence *fence);
156 extern int           drmFenceFlush(int fd, drmFence *fence, unsigned flush_type);
157 extern int           drmFenceSignaled(int fd, drmFence *fence, 
158                                       unsigned fenceType, int *signaled);
159 extern int           drmFenceWait(int fd, unsigned flags, drmFence *fence, 
160                                   unsigned flush_type);
161 extern int           drmFenceEmit(int fd, unsigned flags, drmFence *fence, 
162                                   unsigned emit_type);
163 extern int           drmFenceBuffers(int fd, unsigned flags, drmFence *fence);
164
165
166 /*
167  * TTM functions.
168  */
169
170 extern int drmTTMCreate(int fd, drmTTM *ttm, unsigned long size, 
171                         unsigned flags);
172 extern int drmTTMDestroy(int fd, const drmTTM *ttm);
173 extern int drmTTMReference(int fd, unsigned handle, drmTTM *ttm);
174 extern int drmTTMUnreference(int fd, const drmTTM *ttm);
175 extern drm_handle_t drmTTMMapHandle(int fd, const drmTTM *ttm);
176
177 /*
178  * Buffer object list functions.
179  */
180
181 extern void drmBOFreeList(drmBOList *list);
182 extern int drmBOResetList(drmBOList *list);
183 extern void *drmBOListIterator(drmBOList *list);
184 extern void *drmBOListNext(drmBOList *list, void *iterator);
185 extern drmBO *drmBOListBuf(void *iterator);
186 extern int drmBOCreateList(int numTarget, drmBOList *list);
187
188 /*
189  * Buffer object functions.
190  */
191
192 extern int drmBOCreate(int fd, drmTTM *ttm, unsigned long start, unsigned long size,
193                               void *user_buffer, drm_bo_type_t type, unsigned mask,
194                 unsigned hint, drmBO *buf);
195 extern int drmBODestroy(int fd, drmBO *buf);
196 extern int drmBOReference(int fd, unsigned handle, drmBO *buf);
197 extern int drmBOUnReference(int fd, drmBO *buf);
198 extern int drmBOMap(int fd, drmBO *buf, unsigned mapFlags, unsigned mapHint,
199                     void **address);
200 extern int drmBOUnmap(int fd, drmBO *buf);
201 extern int drmBOValidate(int fd, drmBO *buf, unsigned flags, unsigned mask, 
202                          unsigned hint);
203 extern int drmBOFence(int fd, drmBO *buf, unsigned flags, unsigned fenceHandle);
204 extern int drmBOInfo(int fd, drmBO *buf);
205 extern int drmBOBusy(int fd, drmBO *buf, int *busy);
206
207
208 extern int drmAddValidateItem(drmBOList *list, drmBO *buf, unsigned flags, 
209                        unsigned mask,
210                        int *newItem);
211 extern int drmBOValidateList(int fd, drmBOList *list);
212 extern int drmBOFenceList(int fd, drmBOList *list, unsigned fenceHandle);
213 extern int drmBOWaitIdle(int fd, drmBO *buf, unsigned hint);
214
215 /*
216  * Initialization functions.
217  */
218
219 extern int drmMMInit(int fd, unsigned long vramPOffset, unsigned long vramPSize,
220                      unsigned long ttPOffset, unsigned long ttPSize,
221                      unsigned long max_locked_size);
222 extern int drmMMTakedown(int fd);
223
224
225 #endif