1 /**************************************************************************
3 * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND. USA.
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:
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.
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
27 **************************************************************************/
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.
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.
47 * List macros heavily inspired by the Linux kernel
48 * list handling. No list looping yet.
51 typedef struct _drmMMListHead
53 struct _drmMMListHead *prev;
54 struct _drmMMListHead *next;
57 #define DRMINITLISTHEAD(__item) \
59 (__item)->prev = (__item); \
60 (__item)->next = (__item); \
63 #define DRMLISTADD(__item, __list) \
65 (__item)->prev = (__list); \
66 (__item)->next = (__list)->next; \
67 (__list)->next->prev = (__item); \
68 (__list)->next = (__item); \
71 #define DRMLISTADDTAIL(__item, __list) \
73 (__item)->next = (__list); \
74 (__item)->prev = (__list)->prev; \
75 (__list)->prev->next = (__item); \
76 (__list)->prev = (__item); \
79 #define DRMLISTDEL(__item) \
81 (__item)->prev->next = (__item)->next; \
82 (__item)->next->prev = (__item)->prev; \
85 #define DRMLISTDELINIT(__item) \
87 (__item)->prev->next = (__item)->next; \
88 (__item)->next->prev = (__item)->prev; \
89 (__item)->next = (__item); \
90 (__item)->prev = (__item); \
93 #define DRMLISTENTRY(__type, __item, __field) \
94 ((__type *)(((char *) (__item)) - offsetof(__type, __field)))
96 typedef struct _drmFence
104 unsigned pad[4]; /* for future expansion */
107 typedef struct _drmBO
115 unsigned long offset;
119 unsigned pageAlignment;
121 unsigned hwTileStride;
122 unsigned desiredTileStride;
126 unsigned pad[8]; /* for future expansion */
129 typedef struct _drmBONode
133 struct drm_bo_op_arg bo_arg;
138 typedef struct _drmBOList {
151 extern int drmFenceCreate(int fd, unsigned flags, int fence_class,
152 unsigned type, 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,
163 extern int drmFenceBuffers(int fd, unsigned flags, uint32_t fence_class, drmFence *fence);
167 * Buffer object list functions.
170 extern void drmBOFreeList(drmBOList *list);
171 extern int drmBOResetList(drmBOList *list);
172 extern void *drmBOListIterator(drmBOList *list);
173 extern void *drmBOListNext(drmBOList *list, void *iterator);
174 extern drmBO *drmBOListBuf(void *iterator);
175 extern int drmBOCreateList(int numTarget, drmBOList *list);
178 * Buffer object functions.
181 extern int drmBOCreate(int fd, unsigned long size,
182 unsigned pageAlignment, void *user_buffer,
183 uint64_t mask, unsigned hint, drmBO *buf);
184 extern int drmBODestroy(int fd, drmBO *buf);
185 extern int drmBOReference(int fd, unsigned handle, drmBO *buf);
186 extern int drmBOUnReference(int fd, drmBO *buf);
187 extern int drmBOMap(int fd, drmBO *buf, unsigned mapFlags, unsigned mapHint,
189 extern int drmBOUnmap(int fd, drmBO *buf);
190 extern int drmBOValidate(int fd, drmBO *buf, uint32_t fence_class, uint64_t flags,
191 uint64_t mask, unsigned hint);
193 extern int drmBOFence(int fd, drmBO *buf, unsigned flags, unsigned fenceHandle);
194 extern int drmBOInfo(int fd, drmBO *buf);
195 extern int drmBOBusy(int fd, drmBO *buf, int *busy);
197 extern int drmAddValidateItem(drmBOList *list, drmBO *buf, unsigned flags,
200 extern int drmBOValidateList(int fd, drmBOList *list);
201 extern int drmBOFenceList(int fd, drmBOList *list, unsigned fenceHandle);
202 extern int drmBOWaitIdle(int fd, drmBO *buf, unsigned hint);
203 int drmBOSetPin(int fd, drmBO *buf, int pin);
206 * Initialization functions.
209 extern int drmMMInit(int fd, unsigned long pOffset, unsigned long pSize,
211 extern int drmMMTakedown(int fd, unsigned memType);
212 extern int drmMMLock(int fd, unsigned memType);
213 extern int drmMMUnlock(int fd, unsigned memType);