Buffer object mapping and mapping synchronization for multiple clients.
[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 hint;
92     unsigned mapFlags;
93     unsigned long size;
94     unsigned long offset;
95     unsigned long start;
96     void *virtual;
97     void *mapVirtual;
98     int mapCount;
99     drmTTM *ttm;
100 } drmBO;
101
102
103 typedef struct _drmBONode {
104     drmMMListHead head;
105     drmBO *buf;
106     drm_bo_arg_t bo_arg;
107 } drmBONode;
108
109 typedef struct _drmBOList {
110     unsigned numTarget;
111     unsigned numCurrent;
112     unsigned numOnList;
113     drmMMListHead list;
114     drmMMListHead free;
115 } drmBOList;
116
117 extern int drmBOCreate(int fd, drmTTM *ttm, unsigned long start, unsigned long size,
118                               void *user_buffer, drm_bo_type_t type, unsigned mask,
119                 unsigned hint, drmBO *buf);
120 extern int drmBODestroy(int fd, drmBO *buf);
121 extern int drmBOReference(int fd, unsigned handle, drmBO *buf);
122 extern int drmBOUnReference(int fd, drmBO *buf);
123
124
125 #endif