drm/exynos: Refactor manager/display/overlay
[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/module.h>
33 #include "drmP.h"
34 #include "drm.h"
35 #include "drm_crtc.h"
36
37 #ifdef CONFIG_EXYNOS_IOMMU
38 #include <mach/sysmmu.h>
39 #include <linux/of_platform.h>
40 #endif
41
42 #ifdef CONFIG_DMA_SHARED_BUFFER_USES_KDS
43 #include "linux/kds.h"
44 #include <linux/dma-buf.h>
45 #endif
46
47 #define MAX_CRTC        3
48 #define MAX_PLANE       5
49 #define MAX_FB_BUFFER   4
50 #define DEFAULT_ZPOS    -1
51
52 struct drm_device;
53 struct exynos_drm_overlay;
54 struct drm_connector;
55 struct exynos_drm_gem_object;
56 struct exynos_drm_display;
57
58 extern unsigned int drm_vblank_offdelay;
59
60 /*
61  * Exynos drm common overlay structure.
62  *
63  * @fb_x: offset x on a framebuffer to be displayed.
64  *      - the unit is screen coordinates.
65  * @fb_y: offset y on a framebuffer to be displayed.
66  *      - the unit is screen coordinates.
67  * @fb_width: width of a framebuffer.
68  * @fb_height: height of a framebuffer.
69  * @fb_pitch: pitch of a framebuffer.
70  * @crtc_x: offset x on hardware screen.
71  * @crtc_y: offset y on hardware screen.
72  * @crtc_width: window width to be displayed (hardware screen).
73  * @crtc_height: window height to be displayed (hardware screen).
74  * @mode_width: width of screen mode.
75  * @mode_height: height of screen mode.
76  * @refresh: refresh rate.
77  * @scan_flag: interlace or progressive way.
78  *      (it could be DRM_MODE_FLAG_*)
79  * @bpp: pixel size.(in bit)
80  * @pixel_format: fourcc pixel format of this overlay
81  * @dma_addr: array of bus(accessed by dma) address to the memory region
82  *            allocated for a overlay.
83  * @vaddr: array of virtual memory addresss to this overlay.
84  * @zpos: order of overlay layer(z position).
85  * @default_win: a window to be enabled.
86  * @color_key: color key on or off.
87  * @index_color: if using color key feature then this value would be used
88  *                      as index color.
89  * @local_path: in case of lcd type, local path mode on or off.
90  * @transparency: transparency on or off.
91  * @activated: activated or not.
92  *
93  * this structure is common to exynos SoC and its contents would be copied
94  * to hardware specific overlay info.
95  */
96 struct exynos_drm_overlay {
97         unsigned int fb_x;
98         unsigned int fb_y;
99         unsigned int fb_width;
100         unsigned int fb_height;
101         unsigned int fb_pitch;
102         unsigned int crtc_x;
103         unsigned int crtc_y;
104         unsigned int crtc_width;
105         unsigned int crtc_height;
106         unsigned int mode_width;
107         unsigned int mode_height;
108         unsigned int refresh;
109         unsigned int scan_flag;
110         unsigned int bpp;
111         uint32_t pixel_format;
112         dma_addr_t dma_addr[MAX_FB_BUFFER];
113         void __iomem *vaddr[MAX_FB_BUFFER];
114         int zpos;
115
116         bool default_win;
117         bool color_key;
118         unsigned int index_color;
119         bool local_path;
120         bool transparency;
121         bool activated;
122 };
123
124 /*
125  * Exynos drm private structure.
126  */
127 struct exynos_drm_private {
128         struct drm_fb_helper *fb_helper;
129
130         /*
131          * wait_vsync_event is set to zero by crtc whenever a VSYNC interrupt
132          * is received. After setting wait_vsync_event to 0, wait_vsync_queue
133          * is woken up.
134          */
135         wait_queue_head_t wait_vsync_queue;
136         atomic_t wait_vsync_event;
137
138         /*
139          * created crtc object would be contained at this array and
140          * this array is used to be aware of which crtc did it request vblank.
141          */
142         struct drm_crtc *crtc[MAX_CRTC];
143
144 #ifdef CONFIG_DMA_SHARED_BUFFER_USES_KDS
145         struct kds_callback kds_cb;
146         struct kds_callback kds_cb_rm_fb;
147 #endif
148 };
149
150 /*
151  * Exynos drm sub driver structure.
152  *
153  * @list: sub driver has its own list object to register to exynos drm driver.
154  * @dev: pointer to device object for subdrv device driver.
155  * @drm_dev: pointer to drm_device and this pointer would be set
156  *      when sub driver calls exynos_drm_subdrv_register().
157  * @display: A pointer to the display structure for this sub driver
158  * @probe: this callback would be called by exynos drm driver after
159  *      subdrv is registered to it.
160  * @remove: this callback is used to release resources created
161  *      by probe callback.
162  * @open: this would be called with drm device file open.
163  * @close: this would be called with drm device file close.
164  * @encoder: encoder object owned by this sub driver.
165  * @connector: connector object owned by this sub driver.
166  */
167 struct exynos_drm_subdrv {
168         struct list_head list;
169         struct device *dev;
170         struct drm_device *drm_dev;
171         struct exynos_drm_display *display;
172
173         int (*probe)(struct drm_device *drm_dev,
174                         struct exynos_drm_subdrv *subdrv);
175         void (*remove)(struct drm_device *dev);
176         int (*open)(struct drm_device *drm_dev, struct device *dev,
177                         struct drm_file *file);
178         void (*close)(struct drm_device *drm_dev, struct device *dev,
179                         struct drm_file *file);
180
181         struct drm_encoder *encoder;
182         struct drm_connector *connector;
183 };
184
185 /*
186  * this function calls a probe callback registered to sub driver list and
187  * create its own encoder and connector and then set drm_device object
188  * to global one.
189  */
190 int exynos_drm_device_register(struct drm_device *dev);
191 /*
192  * this function calls a remove callback registered to sub driver list and
193  * destroy its own encoder and connetor.
194  */
195 int exynos_drm_device_unregister(struct drm_device *dev);
196
197 /*
198  * this function would be called by sub drivers such as display controller
199  * or hdmi driver to register this sub driver object to exynos drm driver
200  * and when a sub driver is registered to exynos drm driver a probe callback
201  * of the sub driver is called and creates its own encoder and connector.
202  */
203 int exynos_drm_subdrv_register(struct exynos_drm_subdrv *drm_subdrv);
204
205 /* this function removes subdrv list from exynos drm driver */
206 int exynos_drm_subdrv_unregister(struct exynos_drm_subdrv *drm_subdrv);
207
208 void exynos_fimd_dp_attach(struct device *dev);
209
210 int exynos_drm_subdrv_open(struct drm_device *dev, struct drm_file *file);
211 void exynos_drm_subdrv_close(struct drm_device *dev, struct drm_file *file);
212
213 /*
214  * exynos specific framebuffer structure.
215  *
216  * @fb: drm framebuffer obejct.
217  * @exynos_gem_obj: array of exynos specific gem object containing a gem object.
218  */
219 struct exynos_drm_fb {
220         struct drm_framebuffer          fb;
221         struct exynos_drm_gem_obj       *exynos_gem_obj[MAX_FB_BUFFER];
222 #ifdef CONFIG_DMA_SHARED_BUFFER_USES_KDS
223         struct drm_crtc                 *crtc;
224         struct kds_resource_set         *kds_res_set;
225         struct kds_resource_set         *kds_res_set_rm_fb;
226         struct dma_buf                  *dma_buf;
227 #endif
228 };
229
230 /*
231  * Exynos specific crtc structure.
232  *
233  * @drm_crtc: crtc object.
234  * @overlay: contain information common to display controller and hdmi and
235  *      contents of this overlay object would be copied to sub driver size.
236  * @event: vblank event that is currently queued for flip
237  * @pipe: a crtc index created at load() with a new crtc object creation
238  *      and the crtc object would be set to private->crtc array
239  *      to get a crtc object corresponding to this pipe from private->crtc
240  *      array when irq interrupt occured. the reason of using this pipe is that
241  *      drm framework doesn't support multiple irq yet.
242  *      we can refer to the crtc to current hardware interrupt occured through
243  *      this pipe value.
244  * @dpms: store the crtc dpms value
245  * @flip_pending: there is a flip pending that we need to process next vblank
246  */
247 struct exynos_drm_crtc {
248         struct drm_crtc                 drm_crtc;
249         struct exynos_drm_overlay       overlay;
250 #ifdef CONFIG_DMA_SHARED_BUFFER_USES_KDS
251         struct drm_pending_vblank_event *event;
252         struct kds_resource_set         *current_kds;
253         struct kds_resource_set         *pending_kds;
254         struct kds_resource_set         *future_kds;
255         struct kds_resource_set         *future_kds_extra;
256 #endif
257         unsigned int                    pipe;
258         unsigned int                    dpms;
259         unsigned int                    flip_in_flight;
260         atomic_t                        flip_pending;
261 };
262
263 #define to_exynos_fb(x) container_of(x, struct exynos_drm_fb, fb)
264 #define to_exynos_crtc(x)       container_of(x, struct exynos_drm_crtc,\
265                                 drm_crtc)
266
267 extern struct platform_driver fimd_driver;
268 extern struct platform_driver hdmi_driver;
269 extern struct platform_driver dp_driver;
270 extern struct platform_driver mixer_driver;
271 extern struct platform_driver exynos_drm_common_hdmi_driver;
272 extern struct platform_driver vidi_driver;
273 #ifdef CONFIG_EXYNOS_IOMMU
274 extern struct dma_iommu_mapping *exynos_drm_common_mapping;
275 #endif
276 #endif