Remove the need for the hardware lock in the buffer manager.
[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 {
98     unsigned handle;
99     int fence_class;
100     unsigned type; 
101     unsigned flags;
102     unsigned signaled;
103     uint32_t sequence;
104     unsigned pad[4]; /* for future expansion */
105 } drmFence;
106
107 typedef struct _drmBO
108 {
109     unsigned handle;
110     uint64_t mapHandle;
111     uint64_t flags;
112     uint64_t mask;
113     unsigned mapFlags;
114     unsigned long size;
115     unsigned long offset;
116     unsigned long start;
117     unsigned replyFlags;
118     unsigned fenceFlags;
119     unsigned pageAlignment;
120     unsigned tileInfo;
121     unsigned hwTileStride;
122     unsigned desiredTileStride;
123     void *virtual;
124     void *mapVirtual;
125     int mapCount;
126     unsigned pad[8];     /* for future expansion */
127 } drmBO;
128
129 /*
130  * Fence functions.
131  */
132
133 extern int drmFenceCreate(int fd, unsigned flags, int fence_class,
134                           unsigned type, drmFence *fence);
135 extern int drmFenceReference(int fd, unsigned handle, drmFence *fence);
136 extern int drmFenceUnreference(int fd, const drmFence *fence);
137 extern int drmFenceFlush(int fd, drmFence *fence, unsigned flush_type);
138 extern int drmFenceSignaled(int fd, drmFence *fence, 
139                             unsigned fenceType, int *signaled);
140 extern int drmFenceWait(int fd, unsigned flags, drmFence *fence, 
141                         unsigned flush_type);
142 extern int drmFenceEmit(int fd, unsigned flags, drmFence *fence, 
143                         unsigned emit_type);
144 extern int drmFenceBuffers(int fd, unsigned flags, uint32_t fence_class, drmFence *fence);
145
146
147 /*
148  * Buffer object functions.
149  */
150
151 extern int drmBOCreate(int fd, unsigned long size,
152                        unsigned pageAlignment, void *user_buffer,
153                        uint64_t mask, unsigned hint, drmBO *buf);
154 extern int drmBOReference(int fd, unsigned handle, drmBO *buf);
155 extern int drmBOUnreference(int fd, drmBO *buf);
156 extern int drmBOMap(int fd, drmBO *buf, unsigned mapFlags, unsigned mapHint,
157                     void **address);
158 extern int drmBOUnmap(int fd, drmBO *buf);
159 extern int drmBOValidate(int fd, drmBO *buf, uint32_t fence_class, uint64_t flags,
160                          uint64_t mask, unsigned hint);
161
162 extern int drmBOFence(int fd, drmBO *buf, unsigned flags, unsigned fenceHandle);
163 extern int drmBOInfo(int fd, drmBO *buf);
164 extern int drmBOBusy(int fd, drmBO *buf, int *busy);
165
166 extern int drmBOWaitIdle(int fd, drmBO *buf, unsigned hint);
167
168 /*
169  * Initialization functions.
170  */
171
172 extern int drmMMInit(int fd, unsigned long pOffset, unsigned long pSize,
173                      unsigned memType);
174 extern int drmMMTakedown(int fd, unsigned memType);
175 extern int drmMMLock(int fd, unsigned memType, int lockBM, int ignoreNoEvict);
176 extern int drmMMUnlock(int fd, unsigned memType, int unlockBM);
177
178
179 #endif