OSDN Git Service

radeon: fix tiling config for family older than 06xx
[android-x86/external-drm_gralloc.git] / gralloc_drm_priv.h
1 /*
2  * Copyright (C) 2010-2011 Chia-I Wu <olvaffe@gmail.com>
3  * Copyright (C) 2010-2011 LunarG Inc.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included
13  * in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  */
23
24 #ifndef _GRALLOC_DRM_PRIV_H_
25 #define _GRALLOC_DRM_PRIV_H_
26
27 #include <pthread.h>
28 #include <xf86drm.h>
29 #include <xf86drmMode.h>
30
31 #include "gralloc_drm_handle.h"
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 /* how a bo is posted */
38 enum drm_swap_mode {
39         DRM_SWAP_NOOP,
40         DRM_SWAP_FLIP,
41         DRM_SWAP_COPY,
42         DRM_SWAP_SETCRTC,
43 };
44
45 enum hdmi_output_mode {
46         HDMI_CLONED,
47         HDMI_EXTENDED,
48 };
49
50 struct gralloc_drm_plane_t {
51         drmModePlane *drm_plane;
52
53         /* plane has been set to display a layer */
54         uint32_t active;
55
56         /* handle to display */
57         buffer_handle_t handle;
58
59         /* identifier set by hwc */
60         uint32_t id;
61
62         /* position, crop and scale */
63         uint32_t src_x;
64         uint32_t src_y;
65         uint32_t src_w;
66         uint32_t src_h;
67         uint32_t dst_x;
68         uint32_t dst_y;
69         uint32_t dst_w;
70         uint32_t dst_h;
71
72         /* previous buffer, for refcounting */
73         struct gralloc_drm_bo_t *prev;
74 };
75
76 struct gralloc_drm_output
77 {
78         uint32_t crtc_id;
79         uint32_t connector_id;
80         uint32_t pipe;
81         drmModeModeInfo mode;
82         int xdpi, ydpi;
83         int fb_format;
84         int bpp;
85         uint32_t active;
86
87         /* 'private fb' for this output */
88         struct gralloc_drm_bo_t *bo;
89 };
90
91 struct gralloc_drm_t {
92         /* initialized by gralloc_drm_create */
93         int fd;
94         struct gralloc_drm_drv_t *drv;
95
96         /* initialized by gralloc_drm_init_kms */
97         drmModeResPtr resources;
98         struct gralloc_drm_output primary;
99         struct gralloc_drm_output hdmi;
100         enum hdmi_output_mode hdmi_mode;
101
102         /* hdmi hotplug */
103         pthread_mutex_t hdmi_mutex;
104         pthread_t hdmi_hotplug_thread;
105
106 #ifdef DRM_MODE_FEATURE_DIRTYFB
107         drmModeClip clip;
108 #endif
109
110         /* initialized by drv->init_kms_features */
111         enum drm_swap_mode swap_mode;
112         int swap_interval;
113         int mode_quirk_vmwgfx;
114         int mode_sync_flip; /* page flip should block */
115         int vblank_secondary;
116
117         drmEventContext evctx;
118
119         int first_post;
120         struct gralloc_drm_bo_t *current_front, *next_front;
121         int waiting_flip;
122         unsigned int last_swap;
123
124         /* plane support */
125         drmModePlaneResPtr plane_resources;
126         struct gralloc_drm_plane_t *planes;
127 };
128
129 struct drm_module_t {
130         gralloc_module_t base;
131
132         /* HWC plane API */
133         int (*hwc_reserve_plane) (struct gralloc_drm_t *mod,
134                 buffer_handle_t handle, uint32_t id,
135                 uint32_t dst_x, uint32_t dst_y, uint32_t dst_w, uint32_t dst_h,
136                 uint32_t src_x, uint32_t src_y, uint32_t src_w, uint32_t src_h);
137         void (*hwc_disable_planes) (struct gralloc_drm_t *mod);
138         int (*hwc_set_plane_handle) (struct gralloc_drm_t *mod,
139                 uint32_t id, buffer_handle_t handle);
140
141         pthread_mutex_t mutex;
142         struct gralloc_drm_t *drm;
143 };
144
145 struct gralloc_drm_drv_t {
146         /* destroy the driver */
147         void (*destroy)(struct gralloc_drm_drv_t *drv);
148
149         /* initialize KMS features */
150         void (*init_kms_features)(struct gralloc_drm_drv_t *drv,
151                                   struct gralloc_drm_t *drm);
152
153         /* allocate or import a bo */
154         struct gralloc_drm_bo_t *(*alloc)(struct gralloc_drm_drv_t *drv,
155                                           struct gralloc_drm_handle_t *handle);
156
157         /* free a bo */
158         void (*free)(struct gralloc_drm_drv_t *drv,
159                      struct gralloc_drm_bo_t *bo);
160
161         /* map a bo for CPU access */
162         int (*map)(struct gralloc_drm_drv_t *drv,
163                    struct gralloc_drm_bo_t *bo,
164                    int x, int y, int w, int h, int enable_write, void **addr);
165
166         /* unmap a bo */
167         void (*unmap)(struct gralloc_drm_drv_t *drv,
168                       struct gralloc_drm_bo_t *bo);
169
170         /* blit between two bo's, used for DRM_SWAP_COPY and general blitting */
171         void (*blit)(struct gralloc_drm_drv_t *drv,
172                      struct gralloc_drm_bo_t *dst,
173                      struct gralloc_drm_bo_t *src,
174                      uint16_t dst_x1, uint16_t dst_y1,
175                      uint16_t dst_x2, uint16_t dst_y2,
176                      uint16_t src_x1, uint16_t src_y1,
177                      uint16_t src_x2, uint16_t src_y2);
178
179         /* query component offsets, strides and handles for a format */
180         void (*resolve_format)(struct gralloc_drm_drv_t *drv,
181                      struct gralloc_drm_bo_t *bo,
182                      uint32_t *pitches, uint32_t *offsets, uint32_t *handles);
183 };
184
185 struct gralloc_drm_bo_t {
186         struct gralloc_drm_t *drm;
187         struct gralloc_drm_handle_t *handle;
188
189         int imported;  /* the handle is from a remote proces when true */
190         int fb_handle; /* the GEM handle of the bo */
191         int fb_id;     /* the fb id */
192
193         int lock_count;
194         int locked_for;
195
196         unsigned int refcount;
197 };
198
199 struct gralloc_drm_drv_t *gralloc_drm_drv_create_for_pipe(int fd, const char *name);
200 struct gralloc_drm_drv_t *gralloc_drm_drv_create_for_intel(int fd);
201 struct gralloc_drm_drv_t *gralloc_drm_drv_create_for_radeon(int fd);
202 struct gralloc_drm_drv_t *gralloc_drm_drv_create_for_nouveau(int fd);
203
204 #ifdef __cplusplus
205 }
206 #endif
207 #endif /* _GRALLOC_DRM_PRIV_H_ */