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 **************************************************************************/
36 * Note on multithreaded applications using this interface.
37 * Libdrm is not threadsafe, so common buffer, TTM, and fence objects need to
38 * be protected using an external mutex.
40 * Note: Don't protect the following functions, as it may lead to deadlocks:
42 * The kernel is synchronizing and refcounting buffer maps.
43 * User space only needs to refcount object usage within the same application.
48 * List macros heavily inspired by the Linux kernel
49 * list handling. No list looping yet.
52 typedef struct _drmMMListHead
54 struct _drmMMListHead *prev;
55 struct _drmMMListHead *next;
58 #define DRMINITLISTHEAD(__item) \
60 (__item)->prev = (__item); \
61 (__item)->next = (__item); \
64 #define DRMLISTADD(__item, __list) \
66 (__item)->prev = (__list); \
67 (__item)->next = (__list)->next; \
68 (__list)->next->prev = (__item); \
69 (__list)->next = (__item); \
72 #define DRMLISTADDTAIL(__item, __list) \
74 (__item)->next = (__list); \
75 (__item)->prev = (__list)->prev; \
76 (__list)->prev->next = (__item); \
77 (__list)->prev = (__item); \
80 #define DRMLISTDEL(__item) \
82 (__item)->prev->next = (__item)->next; \
83 (__item)->next->prev = (__item)->prev; \
86 #define DRMLISTDELINIT(__item) \
88 (__item)->prev->next = (__item)->next; \
89 (__item)->next->prev = (__item)->prev; \
90 (__item)->next = (__item); \
91 (__item)->prev = (__item); \
94 #define DRMLISTENTRY(__type, __item, __field) \
95 ((__type *)(((char *) (__item)) - offsetof(__type, __field)))
97 #define DRMLISTEMPTY(__item) ((__item)->next == (__item))
99 #define DRMLISTFOREACHSAFE(__item, __temp, __list) \
100 for ((__item) = (__list)->next, (__temp) = (__item)->next; \
101 (__item) != (__list); \
102 (__item) = (__temp), (__temp) = (__item)->next)
104 #define DRMLISTFOREACHSAFEREVERSE(__item, __temp, __list) \
105 for ((__item) = (__list)->prev, (__temp) = (__item)->prev; \
106 (__item) != (__list); \
107 (__item) = (__temp), (__temp) = (__item)->prev)
109 typedef struct _drmFence
117 unsigned pad[4]; /* for future expansion */
120 typedef struct _drmBO
125 uint64_t proposedFlags;
128 unsigned long offset;
132 unsigned pageAlignment;
134 unsigned hwTileStride;
135 unsigned desiredTileStride;
139 unsigned pad[8]; /* for future expansion */
146 extern int drmFenceCreate(int fd, unsigned flags, int fence_class,
147 unsigned type, drmFence *fence);
148 extern int drmFenceReference(int fd, unsigned handle, drmFence *fence);
149 extern int drmFenceUnreference(int fd, const drmFence *fence);
150 extern int drmFenceFlush(int fd, drmFence *fence, unsigned flush_type);
151 extern int drmFenceSignaled(int fd, drmFence *fence,
152 unsigned fenceType, int *signaled);
153 extern int drmFenceWait(int fd, unsigned flags, drmFence *fence,
154 unsigned flush_type);
155 extern int drmFenceEmit(int fd, unsigned flags, drmFence *fence,
157 extern int drmFenceBuffers(int fd, unsigned flags, uint32_t fence_class, drmFence *fence);
161 * Buffer object functions.
164 extern int drmBOCreate(int fd, unsigned long size,
165 unsigned pageAlignment, void *user_buffer,
166 uint64_t mask, unsigned hint, drmBO *buf);
167 extern int drmBOReference(int fd, unsigned handle, drmBO *buf);
168 extern int drmBOUnreference(int fd, drmBO *buf);
169 extern int drmBOMap(int fd, drmBO *buf, unsigned mapFlags, unsigned mapHint,
171 extern int drmBOUnmap(int fd, drmBO *buf);
172 extern int drmBOFence(int fd, drmBO *buf, unsigned flags, unsigned fenceHandle);
173 extern int drmBOInfo(int fd, drmBO *buf);
174 extern int drmBOBusy(int fd, drmBO *buf, int *busy);
176 extern int drmBOWaitIdle(int fd, drmBO *buf, unsigned hint);
179 * Initialization functions.
182 extern int drmMMInit(int fd, unsigned long pOffset, unsigned long pSize,
184 extern int drmMMTakedown(int fd, unsigned memType);
185 extern int drmMMLock(int fd, unsigned memType, int lockBM, int ignoreNoEvict);
186 extern int drmMMUnlock(int fd, unsigned memType, int unlockBM);
187 extern int drmMMInfo(int fd, unsigned memType, uint64_t *size);
188 extern int drmBOSetStatus(int fd, drmBO *buf,
189 uint64_t flags, uint64_t mask,
191 unsigned int desired_tile_stride,
192 unsigned int tile_info);
193 extern int drmBOVersion(int fd, unsigned int *major,
195 unsigned int *patchlevel);