Libdrm function headers. Some renaming.
[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  * List macros heavily inspired by the Linux kernel
36  * list handling. No list looping yet.
37  */
38
39 typedef struct _drmMMListHead
40 {
41     struct _drmMMListHead *prev;
42     struct _drmMMListHead *next;
43 } drmMMListHead;
44
45 #define DRMINITLISTHEAD(__item)                \
46   do{                                          \
47     (__item)->prev = (__item);                 \
48     (__item)->next = (__item);                 \
49   } while (0)
50
51 #define DRMLISTADD(__item, __list)                      \
52   do {                                          \
53     (__item)->prev = (__list);                  \
54     (__item)->next = (__list)->next;            \
55     (__list)->next->prev = (__item);            \
56     (__list)->next = (__item);                  \
57   } while (0)
58
59 #define DRMLISTADDTAIL(__item, __list)          \
60   do {                                          \
61     (__item)->next = (__list);                  \
62     (__item)->prev = (__list)->prev;            \
63     (__list)->prev->next = (__item);            \
64     (__list)->prev = (__item);                  \
65   } while(0)
66
67 #define DRMLISTDEL(__item)                      \
68   do {                                          \
69     (__item)->prev->next = (__item)->next;      \
70     (__item)->next->prev = (__item)->prev;      \
71   } while(0)
72
73 #define DRMLISTDELINIT(__item)                  \
74   do {                                          \
75     (__item)->prev->next = (__item)->next;      \
76     (__item)->next->prev = (__item)->prev;      \
77     (__item)->next = (__item);                  \
78     (__item)->prev = (__item);                  \
79   } while(0)
80
81 #define DRMLISTENTRY(__type, __item, __field)   \
82     ((__type *)(((char *) (__item)) - offsetof(__type, __field)))
83
84
85 typedef struct _drmBO{
86     drm_bo_type_t type;
87     unsigned handle;
88     drm_handle_t mapHandle;
89     unsigned flags;
90     unsigned mask;
91     unsigned mapFlags;
92     unsigned long size;
93     unsigned long offset;
94     unsigned long start;
95     unsigned replyFlags;
96     unsigned fenceFlags;
97     void *virtual;
98     void *mapVirtual;
99     int mapCount;
100     drmTTM *ttm;
101 } drmBO;
102
103
104 typedef struct _drmBONode {
105     drmMMListHead head;
106     drmBO *buf;
107     drm_bo_arg_t bo_arg;
108     unsigned long arg0;
109     unsigned long arg1;
110 } drmBONode;
111
112 typedef struct _drmBOList {
113     unsigned numTarget;
114     unsigned numCurrent;
115     unsigned numOnList;
116     drmMMListHead list;
117     drmMMListHead free;
118 } drmBOList;
119
120
121 /*
122  * TTM functions.
123  */
124
125 extern int drmTTMCreate(int fd, drmTTM *ttm, unsigned long size, 
126                         unsigned flags);
127 extern int drmTTMDestroy(int fd, const drmTTM *ttm);
128 extern int drmTTMReference(int fd, unsigned handle, drmTTM *ttm);
129 extern int drmTTMUnreference(int fd, const drmTTM *ttm);
130 extern drm_handle_t drmTTMMapHandle(int fd, const drmTTM *ttm);
131
132 /*
133  * Buffer object list functions.
134  */
135
136 extern void drmBOFreeList(drmBOList *list);
137 extern int drmBOResetList(drmBOList *list);
138 extern void *drmBOListIterator(drmBOList *list);
139 extern void *drmBOListNext(drmBOList *list, void *iterator);
140 extern drmBO *drmBOListBuf(void *iterator);
141 extern int drmBOCreateList(int numTarget, drmBOList *list);
142
143 /*
144  * Buffer object functions.
145  */
146
147 extern int drmBOCreate(int fd, drmTTM *ttm, unsigned long start, unsigned long size,
148                               void *user_buffer, drm_bo_type_t type, unsigned mask,
149                 unsigned hint, drmBO *buf);
150 extern int drmBODestroy(int fd, drmBO *buf);
151 extern int drmBOReference(int fd, unsigned handle, drmBO *buf);
152 extern int drmBOUnReference(int fd, drmBO *buf);
153 extern int drmBOMap(int fd, drmBO *buf, unsigned mapFlags, unsigned mapHint,
154                     void **address);
155 extern int drmBOUnmap(int fd, drmBO *buf);
156 extern int drmBOValidate(int fd, drmBO *buf, unsigned flags, unsigned mask, 
157                          unsigned hint);
158 extern int drmBOFence(int fd, drmBO *buf, unsigned flags, unsigned fenceHandle);
159 extern int drmBOInfo(int fd, drmBO *buf);
160 extern int drmBufBusy(int fd, drmBO *buf, int *busy);
161
162
163 extern int drmAddValidateItem(drmBOList *list, drmBO *buf, unsigned flags, 
164                        unsigned mask,
165                        int *newItem);
166 extern int drmBOValidateList(int fd, drmBOList *list);
167 extern int drmBOFenceList(int fd, drmBOList *list, unsigned fenceHandle);
168
169
170 /*
171  * Initialization functions.
172  */
173
174 extern int drmMMInit(int fd, unsigned long vramPOffset, unsigned long vramPSize,
175                      unsigned long ttPOffset, unsigned long ttPSize);
176 extern int drmMMTakedown(int fd);
177
178
179 #endif