ba1bee8490283ab16030a262b69015a068f379ca
[cascardo/linux.git] / drivers / gpu / drm / exynos / exynos_drm_drv.h
1 /* exynos_drm_drv.h
2  *
3  * Copyright (c) 2011 Samsung Electronics Co., Ltd.
4  * Authors:
5  *      Inki Dae <inki.dae@samsung.com>
6  *      Joonyoung Shim <jy0922.shim@samsung.com>
7  *      Seung-Woo Kim <sw0312.kim@samsung.com>
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a
10  * copy of this software and associated documentation files (the "Software"),
11  * to deal in the Software without restriction, including without limitation
12  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13  * and/or sell copies of the Software, and to permit persons to whom the
14  * Software is furnished to do so, subject to the following conditions:
15  *
16  * The above copyright notice and this permission notice (including the next
17  * paragraph) shall be included in all copies or substantial portions of the
18  * Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
23  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
24  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26  * OTHER DEALINGS IN THE SOFTWARE.
27  */
28
29 #ifndef _EXYNOS_DRM_DRV_H_
30 #define _EXYNOS_DRM_DRV_H_
31
32 #include <linux/kref.h>
33 #include <linux/module.h>
34 #include "drmP.h"
35 #include "drm.h"
36 #include "drm_crtc.h"
37
38 #ifdef CONFIG_EXYNOS_IOMMU
39 #include <mach/sysmmu.h>
40 #include <linux/of_platform.h>
41 #endif
42
43 #ifdef CONFIG_DMA_SHARED_BUFFER_USES_KDS
44 #include "linux/kds.h"
45 #include <linux/dma-buf.h>
46 #endif
47
48 #define MAX_CRTC        3
49 #define MAX_PLANE       5
50 #define MAX_FB_BUFFER   4
51 #define DEFAULT_ZPOS    -1
52
53 struct drm_device;
54 struct exynos_drm_overlay;
55 struct drm_connector;
56 struct exynos_drm_gem_object;
57 struct exynos_drm_display;
58
59 extern unsigned int drm_vblank_offdelay;
60
61 /*
62  * Exynos drm common overlay structure.
63  *
64  * @fb_x: offset x on a framebuffer to be displayed.
65  *      - the unit is screen coordinates.
66  * @fb_y: offset y on a framebuffer to be displayed.
67  *      - the unit is screen coordinates.
68  * @fb_width: width of a framebuffer.
69  * @fb_height: height of a framebuffer.
70  * @fb_pitch: pitch of a framebuffer.
71  * @crtc_x: offset x on hardware screen.
72  * @crtc_y: offset y on hardware screen.
73  * @crtc_width: window width to be displayed (hardware screen).
74  * @crtc_height: window height to be displayed (hardware screen).
75  * @mode_width: width of screen mode.
76  * @mode_height: height of screen mode.
77  * @refresh: refresh rate.
78  * @scan_flag: interlace or progressive way.
79  *      (it could be DRM_MODE_FLAG_*)
80  * @bpp: pixel size.(in bit)
81  * @pixel_format: fourcc pixel format of this overlay
82  * @dma_addr: array of bus(accessed by dma) address to the memory region
83  *            allocated for a overlay.
84  * @vaddr: array of virtual memory addresss to this overlay.
85  * @zpos: order of overlay layer(z position).
86  * @default_win: a window to be enabled.
87  * @color_key: color key on or off.
88  * @index_color: if using color key feature then this value would be used
89  *                      as index color.
90  * @local_path: in case of lcd type, local path mode on or off.
91  * @transparency: transparency on or off.
92  * @activated: activated or not.
93  *
94  * this structure is common to exynos SoC and its contents would be copied
95  * to hardware specific overlay info.
96  */
97 struct exynos_drm_overlay {
98         unsigned int fb_x;
99         unsigned int fb_y;
100         unsigned int fb_width;
101         unsigned int fb_height;
102         unsigned int fb_pitch;
103         unsigned int crtc_x;
104         unsigned int crtc_y;
105         unsigned int crtc_width;
106         unsigned int crtc_height;
107         unsigned int crtc_htotal;
108         unsigned int crtc_hsync_len;
109         unsigned int crtc_vtotal;
110         unsigned int crtc_vsync_len;
111         unsigned int mode_width;
112         unsigned int mode_height;
113         unsigned int refresh;
114         unsigned int scan_flag;
115         unsigned int bpp;
116         uint32_t pixel_format;
117         dma_addr_t dma_addr[MAX_FB_BUFFER];
118         void __iomem *vaddr[MAX_FB_BUFFER];
119         int zpos;
120
121         bool default_win;
122         bool color_key;
123         unsigned int index_color;
124         bool local_path;
125         bool transparency;
126         bool activated;
127 };
128
129 /*
130  * Exynos drm private structure.
131  */
132 struct exynos_drm_private {
133         struct drm_fb_helper *fb_helper;
134
135         wait_queue_head_t wait_vsync_queue;
136
137         /*
138          * created crtc object would be contained at this array and
139          * this array is used to be aware of which crtc did it request vblank.
140          */
141         struct drm_crtc *crtc[MAX_CRTC];
142
143 #ifdef CONFIG_DMA_SHARED_BUFFER_USES_KDS
144         struct kds_callback kds_cb;
145 #endif
146 #ifdef CONFIG_DRM_EXYNOS_DEBUG
147         struct {
148                 atomic_t object_memory;
149                 atomic_t object_count;
150         } mm;
151 #endif
152 };
153
154 /*
155  * Exynos drm sub driver structure.
156  *
157  * @list: sub driver has its own list object to register to exynos drm driver.
158  * @dev: pointer to device object for subdrv device driver.
159  * @drm_dev: pointer to drm_device and this pointer would be set
160  *      when sub driver calls exynos_drm_subdrv_register().
161  * @display: A pointer to the display structure for this sub driver
162  * @probe: this callback would be called by exynos drm driver after
163  *      subdrv is registered to it.
164  * @remove: this callback is used to release resources created
165  *      by probe callback.
166  * @open: this would be called with drm device file open.
167  * @close: this would be called with drm device file close.
168  * @encoder: encoder object owned by this sub driver.
169  * @connector: connector object owned by this sub driver.
170  */
171 struct exynos_drm_subdrv {
172         struct list_head list;
173         struct device *dev;
174         struct drm_device *drm_dev;
175         struct exynos_drm_display *display;
176
177         int (*probe)(struct drm_device *drm_dev,
178                         struct exynos_drm_subdrv *subdrv);
179         void (*remove)(struct drm_device *dev);
180         int (*open)(struct drm_device *drm_dev, struct device *dev,
181                         struct drm_file *file);
182         void (*close)(struct drm_device *drm_dev, struct device *dev,
183                         struct drm_file *file);
184
185         struct drm_encoder *encoder;
186         struct drm_connector *connector;
187 };
188
189 /*
190  * this function calls a probe callback registered to sub driver list and
191  * create its own encoder and connector and then set drm_device object
192  * to global one.
193  */
194 int exynos_drm_device_register(struct drm_device *dev);
195 /*
196  * this function calls a remove callback registered to sub driver list and
197  * destroy its own encoder and connetor.
198  */
199 int exynos_drm_device_unregister(struct drm_device *dev);
200
201 /*
202  * this function would be called by sub drivers such as display controller
203  * or hdmi driver to register this sub driver object to exynos drm driver
204  * and when a sub driver is registered to exynos drm driver a probe callback
205  * of the sub driver is called and creates its own encoder and connector.
206  */
207 int exynos_drm_subdrv_register(struct exynos_drm_subdrv *drm_subdrv);
208
209 /* this function removes subdrv list from exynos drm driver */
210 int exynos_drm_subdrv_unregister(struct exynos_drm_subdrv *drm_subdrv);
211
212 void exynos_fimd_dp_attach(struct device *dev);
213
214 int exynos_drm_subdrv_open(struct drm_device *dev, struct drm_file *file);
215 void exynos_drm_subdrv_close(struct drm_device *dev, struct drm_file *file);
216
217 void exynos_drm_encoder_dpms(struct drm_encoder *encoder, int mode);
218 int exynos_drm_encoder_get_dpms(struct drm_encoder *encoder);
219
220 /*
221  * exynos specific framebuffer structure.
222  *
223  * @release_work: for the worker destroying the fb after it's done being used
224  * @fb: drm framebuffer obejct.
225  * @exynos_gem_obj: array of exynos specific gem object containing a gem object.
226  */
227 struct exynos_drm_fb {
228         struct kref                     refcount;
229         struct work_struct              release_work;
230         struct drm_framebuffer          fb;
231         struct exynos_drm_gem_obj       *exynos_gem_obj[MAX_FB_BUFFER];
232 #ifdef CONFIG_DMA_SHARED_BUFFER_USES_KDS
233         struct drm_crtc                 *crtc;
234         struct kds_resource_set         *kds_res_set;
235         struct dma_buf                  *dma_buf;
236 #endif
237 };
238
239 void exynos_drm_fb_release(struct kref *kref);
240
241 static inline void exynos_drm_fb_get(struct exynos_drm_fb *exynos_fb)
242 {
243         kref_get(&exynos_fb->refcount);
244 }
245
246 static inline void exynos_drm_fb_put(struct exynos_drm_fb *exynos_fb)
247 {
248         kref_put(&exynos_fb->refcount, exynos_drm_fb_release);
249 }
250
251 /*
252  * Exynos specific crtc structure.
253  *
254  * @drm_crtc: crtc object.
255  * @overlay: contain information common to display controller and hdmi and
256  *      contents of this overlay object would be copied to sub driver size.
257  * @current_fb: current fb that is being scanned out
258  * @pending_fb: fb that will start scanout on next flip
259  * @event: vblank event that is currently queued for flip
260  * @pipe: a crtc index created at load() with a new crtc object creation
261  *      and the crtc object would be set to private->crtc array
262  *      to get a crtc object corresponding to this pipe from private->crtc
263  *      array when irq interrupt occured. the reason of using this pipe is that
264  *      drm framework doesn't support multiple irq yet.
265  *      we can refer to the crtc to current hardware interrupt occured through
266  *      this pipe value.
267  * @dpms: store the crtc dpms value
268  * @flip_pending: there is a flip pending that we need to process next vblank
269  */
270 struct exynos_drm_crtc {
271         struct drm_crtc                 drm_crtc;
272         struct exynos_drm_overlay       overlay;
273         struct drm_framebuffer          *current_fb;
274         struct drm_framebuffer          *pending_fb;
275 #ifdef CONFIG_DMA_SHARED_BUFFER_USES_KDS
276         struct drm_pending_vblank_event *event;
277         struct kds_resource_set         *current_kds;
278         struct kds_resource_set         *pending_kds;
279         struct kds_resource_set         *future_kds;
280         struct kds_resource_set         *future_kds_extra;
281 #endif
282         unsigned int                    pipe;
283         unsigned int                    dpms;
284         unsigned int                    flip_in_flight;
285         atomic_t                        flip_pending;
286 };
287
288 #define to_exynos_fb(x) container_of(x, struct exynos_drm_fb, fb)
289 #define to_exynos_crtc(x)       container_of(x, struct exynos_drm_crtc,\
290                                 drm_crtc)
291
292 extern struct platform_driver fimd_driver;
293 extern struct platform_driver hdmi_driver;
294 extern struct platform_driver dp_driver;
295 extern struct platform_driver mixer_driver;
296 extern struct platform_driver exynos_drm_common_hdmi_driver;
297 extern struct platform_driver vidi_driver;
298 #ifdef CONFIG_EXYNOS_IOMMU
299 extern struct dma_iommu_mapping *exynos_drm_common_mapping;
300 #endif
301
302 /* exynos_drm_debugfs.c */
303 int exynos_drm_debugfs_init(struct drm_minor *minor);
304 void exynos_drm_debugfs_cleanup(struct drm_minor *minor);
305
306 #endif