Merge branch 'drm-next-5.2' of git://people.freedesktop.org/~agd5f/linux into drm...
[linux-2.6-microblaze.git] / drivers / gpu / drm / cirrus / cirrus_drv.h
1 /*
2  * Copyright 2012 Red Hat
3  *
4  * This file is subject to the terms and conditions of the GNU General
5  * Public License version 2. See the file COPYING in the main
6  * directory of this archive for more details.
7  *
8  * Authors: Matthew Garrett
9  *          Dave Airlie
10  */
11 #ifndef __CIRRUS_DRV_H__
12 #define __CIRRUS_DRV_H__
13
14 #include <video/vga.h>
15
16 #include <drm/drm_encoder.h>
17 #include <drm/drm_fb_helper.h>
18
19 #include <drm/ttm/ttm_bo_api.h>
20 #include <drm/ttm/ttm_bo_driver.h>
21 #include <drm/ttm/ttm_placement.h>
22 #include <drm/ttm/ttm_memory.h>
23 #include <drm/ttm/ttm_module.h>
24
25 #include <drm/drm_gem.h>
26
27 #define DRIVER_AUTHOR           "Matthew Garrett"
28
29 #define DRIVER_NAME             "cirrus"
30 #define DRIVER_DESC             "qemu Cirrus emulation"
31 #define DRIVER_DATE             "20110418"
32
33 #define DRIVER_MAJOR            1
34 #define DRIVER_MINOR            0
35 #define DRIVER_PATCHLEVEL       0
36
37 #define CIRRUSFB_CONN_LIMIT 1
38
39 #define RREG8(reg) ioread8(((void __iomem *)cdev->rmmio) + (reg))
40 #define WREG8(reg, v) iowrite8(v, ((void __iomem *)cdev->rmmio) + (reg))
41 #define RREG32(reg) ioread32(((void __iomem *)cdev->rmmio) + (reg))
42 #define WREG32(reg, v) iowrite32(v, ((void __iomem *)cdev->rmmio) + (reg))
43
44 #define SEQ_INDEX 4
45 #define SEQ_DATA 5
46
47 #define WREG_SEQ(reg, v)                                        \
48         do {                                                    \
49                 WREG8(SEQ_INDEX, reg);                          \
50                 WREG8(SEQ_DATA, v);                             \
51         } while (0)                                             \
52
53 #define CRT_INDEX 0x14
54 #define CRT_DATA 0x15
55
56 #define WREG_CRT(reg, v)                                        \
57         do {                                                    \
58                 WREG8(CRT_INDEX, reg);                          \
59                 WREG8(CRT_DATA, v);                             \
60         } while (0)                                             \
61
62 #define GFX_INDEX 0xe
63 #define GFX_DATA 0xf
64
65 #define WREG_GFX(reg, v)                                        \
66         do {                                                    \
67                 WREG8(GFX_INDEX, reg);                          \
68                 WREG8(GFX_DATA, v);                             \
69         } while (0)                                             \
70
71 /*
72  * Cirrus has a "hidden" DAC register that can be accessed by writing to
73  * the pixel mask register to reset the state, then reading from the register
74  * four times. The next write will then pass to the DAC
75  */
76 #define VGA_DAC_MASK 0x6
77
78 #define WREG_HDR(v)                                             \
79         do {                                                    \
80                 RREG8(VGA_DAC_MASK);                                    \
81                 RREG8(VGA_DAC_MASK);                                    \
82                 RREG8(VGA_DAC_MASK);                                    \
83                 RREG8(VGA_DAC_MASK);                                    \
84                 WREG8(VGA_DAC_MASK, v);                                 \
85         } while (0)                                             \
86
87
88 #define CIRRUS_MAX_FB_HEIGHT 4096
89 #define CIRRUS_MAX_FB_WIDTH 4096
90
91 #define CIRRUS_DPMS_CLEARED (-1)
92
93 #define to_cirrus_crtc(x) container_of(x, struct cirrus_crtc, base)
94 #define to_cirrus_encoder(x) container_of(x, struct cirrus_encoder, base)
95
96 struct cirrus_crtc {
97         struct drm_crtc                 base;
98         int                             last_dpms;
99         bool                            enabled;
100 };
101
102 struct cirrus_fbdev;
103 struct cirrus_mode_info {
104         bool                            mode_config_initialized;
105         struct cirrus_crtc              *crtc;
106         /* pointer to fbdev info structure */
107         struct cirrus_fbdev             *gfbdev;
108 };
109
110 struct cirrus_encoder {
111         struct drm_encoder              base;
112         int                             last_dpms;
113 };
114
115 struct cirrus_connector {
116         struct drm_connector            base;
117 };
118
119 struct cirrus_mc {
120         resource_size_t                 vram_size;
121         resource_size_t                 vram_base;
122 };
123
124 struct cirrus_device {
125         struct drm_device               *dev;
126         unsigned long                   flags;
127
128         resource_size_t                 rmmio_base;
129         resource_size_t                 rmmio_size;
130         void __iomem                    *rmmio;
131
132         struct cirrus_mc                        mc;
133         struct cirrus_mode_info         mode_info;
134
135         int                             num_crtc;
136         int fb_mtrr;
137
138         struct {
139                 struct ttm_bo_device bdev;
140         } ttm;
141         bool mm_inited;
142 };
143
144
145 struct cirrus_fbdev {
146         struct drm_fb_helper helper; /* must be first */
147         struct drm_framebuffer *gfb;
148         void *sysram;
149         int size;
150         int x1, y1, x2, y2; /* dirty rect */
151         spinlock_t dirty_lock;
152 };
153
154 struct cirrus_bo {
155         struct ttm_buffer_object bo;
156         struct ttm_placement placement;
157         struct ttm_bo_kmap_obj kmap;
158         struct drm_gem_object gem;
159         struct ttm_place placements[3];
160         int pin_count;
161 };
162 #define gem_to_cirrus_bo(gobj) container_of((gobj), struct cirrus_bo, gem)
163
164 static inline struct cirrus_bo *
165 cirrus_bo(struct ttm_buffer_object *bo)
166 {
167         return container_of(bo, struct cirrus_bo, bo);
168 }
169
170
171 #define to_cirrus_obj(x) container_of(x, struct cirrus_gem_object, base)
172
173                                 /* cirrus_main.c */
174 int cirrus_device_init(struct cirrus_device *cdev,
175                       struct drm_device *ddev,
176                       struct pci_dev *pdev,
177                       uint32_t flags);
178 void cirrus_device_fini(struct cirrus_device *cdev);
179 void cirrus_gem_free_object(struct drm_gem_object *obj);
180 int cirrus_dumb_mmap_offset(struct drm_file *file,
181                             struct drm_device *dev,
182                             uint32_t handle,
183                             uint64_t *offset);
184 int cirrus_gem_create(struct drm_device *dev,
185                    u32 size, bool iskernel,
186                       struct drm_gem_object **obj);
187 int cirrus_dumb_create(struct drm_file *file,
188                     struct drm_device *dev,
189                        struct drm_mode_create_dumb *args);
190
191 int cirrus_framebuffer_init(struct drm_device *dev,
192                             struct drm_framebuffer *gfb,
193                             const struct drm_mode_fb_cmd2 *mode_cmd,
194                             struct drm_gem_object *obj);
195
196 bool cirrus_check_framebuffer(struct cirrus_device *cdev, int width, int height,
197                               int bpp, int pitch);
198
199                                 /* cirrus_display.c */
200 int cirrus_modeset_init(struct cirrus_device *cdev);
201 void cirrus_modeset_fini(struct cirrus_device *cdev);
202
203                                 /* cirrus_fbdev.c */
204 int cirrus_fbdev_init(struct cirrus_device *cdev);
205 void cirrus_fbdev_fini(struct cirrus_device *cdev);
206
207
208
209                                 /* cirrus_irq.c */
210 void cirrus_driver_irq_preinstall(struct drm_device *dev);
211 int cirrus_driver_irq_postinstall(struct drm_device *dev);
212 void cirrus_driver_irq_uninstall(struct drm_device *dev);
213 irqreturn_t cirrus_driver_irq_handler(int irq, void *arg);
214
215                                 /* cirrus_kms.c */
216 int cirrus_driver_load(struct drm_device *dev, unsigned long flags);
217 void cirrus_driver_unload(struct drm_device *dev);
218 extern struct drm_ioctl_desc cirrus_ioctls[];
219 extern int cirrus_max_ioctl;
220
221 int cirrus_mm_init(struct cirrus_device *cirrus);
222 void cirrus_mm_fini(struct cirrus_device *cirrus);
223 void cirrus_ttm_placement(struct cirrus_bo *bo, int domain);
224 int cirrus_bo_create(struct drm_device *dev, int size, int align,
225                      uint32_t flags, struct cirrus_bo **pcirrusbo);
226 int cirrus_mmap(struct file *filp, struct vm_area_struct *vma);
227
228 static inline int cirrus_bo_reserve(struct cirrus_bo *bo, bool no_wait)
229 {
230         int ret;
231
232         ret = ttm_bo_reserve(&bo->bo, true, no_wait, NULL);
233         if (ret) {
234                 if (ret != -ERESTARTSYS && ret != -EBUSY)
235                         DRM_ERROR("reserve failed %p\n", bo);
236                 return ret;
237         }
238         return 0;
239 }
240
241 static inline void cirrus_bo_unreserve(struct cirrus_bo *bo)
242 {
243         ttm_bo_unreserve(&bo->bo);
244 }
245
246 int cirrus_bo_push_sysram(struct cirrus_bo *bo);
247 int cirrus_bo_pin(struct cirrus_bo *bo, u32 pl_flag, u64 *gpu_addr);
248
249 extern int cirrus_bpp;
250
251 #endif                          /* __CIRRUS_DRV_H__ */