2 * Copyright 2012 Red Hat
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.
8 * Authors: Matthew Garrett
11 #ifndef __CIRRUS_DRV_H__
12 #define __CIRRUS_DRV_H__
14 #include <video/vga.h>
16 #include <drm/drm_encoder.h>
17 #include <drm/drm_fb_helper.h>
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>
25 #include <drm/drm_gem.h>
27 #define DRIVER_AUTHOR "Matthew Garrett"
29 #define DRIVER_NAME "cirrus"
30 #define DRIVER_DESC "qemu Cirrus emulation"
31 #define DRIVER_DATE "20110418"
33 #define DRIVER_MAJOR 1
34 #define DRIVER_MINOR 0
35 #define DRIVER_PATCHLEVEL 0
37 #define CIRRUSFB_CONN_LIMIT 1
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))
47 #define WREG_SEQ(reg, v) \
49 WREG8(SEQ_INDEX, reg); \
53 #define CRT_INDEX 0x14
56 #define WREG_CRT(reg, v) \
58 WREG8(CRT_INDEX, reg); \
65 #define WREG_GFX(reg, v) \
67 WREG8(GFX_INDEX, reg); \
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
76 #define VGA_DAC_MASK 0x6
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); \
88 #define CIRRUS_MAX_FB_HEIGHT 4096
89 #define CIRRUS_MAX_FB_WIDTH 4096
91 #define CIRRUS_DPMS_CLEARED (-1)
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)
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;
110 struct cirrus_encoder {
111 struct drm_encoder base;
115 struct cirrus_connector {
116 struct drm_connector base;
120 resource_size_t vram_size;
121 resource_size_t vram_base;
124 struct cirrus_device {
125 struct drm_device *dev;
128 resource_size_t rmmio_base;
129 resource_size_t rmmio_size;
133 struct cirrus_mode_info mode_info;
139 struct drm_global_reference mem_global_ref;
140 struct ttm_bo_global_ref bo_global_ref;
141 struct ttm_bo_device bdev;
147 struct cirrus_fbdev {
148 struct drm_fb_helper helper;
149 struct drm_framebuffer gfb;
152 int x1, y1, x2, y2; /* dirty rect */
153 spinlock_t dirty_lock;
157 struct ttm_buffer_object bo;
158 struct ttm_placement placement;
159 struct ttm_bo_kmap_obj kmap;
160 struct drm_gem_object gem;
161 struct ttm_place placements[3];
164 #define gem_to_cirrus_bo(gobj) container_of((gobj), struct cirrus_bo, gem)
166 static inline struct cirrus_bo *
167 cirrus_bo(struct ttm_buffer_object *bo)
169 return container_of(bo, struct cirrus_bo, bo);
173 #define to_cirrus_obj(x) container_of(x, struct cirrus_gem_object, base)
174 #define DRM_FILE_PAGE_OFFSET (0x100000000ULL >> PAGE_SHIFT)
177 int cirrus_device_init(struct cirrus_device *cdev,
178 struct drm_device *ddev,
179 struct pci_dev *pdev,
181 void cirrus_device_fini(struct cirrus_device *cdev);
182 void cirrus_gem_free_object(struct drm_gem_object *obj);
183 int cirrus_dumb_mmap_offset(struct drm_file *file,
184 struct drm_device *dev,
187 int cirrus_gem_create(struct drm_device *dev,
188 u32 size, bool iskernel,
189 struct drm_gem_object **obj);
190 int cirrus_dumb_create(struct drm_file *file,
191 struct drm_device *dev,
192 struct drm_mode_create_dumb *args);
194 int cirrus_framebuffer_init(struct drm_device *dev,
195 struct drm_framebuffer *gfb,
196 const struct drm_mode_fb_cmd2 *mode_cmd,
197 struct drm_gem_object *obj);
199 bool cirrus_check_framebuffer(struct cirrus_device *cdev, int width, int height,
202 /* cirrus_display.c */
203 int cirrus_modeset_init(struct cirrus_device *cdev);
204 void cirrus_modeset_fini(struct cirrus_device *cdev);
207 int cirrus_fbdev_init(struct cirrus_device *cdev);
208 void cirrus_fbdev_fini(struct cirrus_device *cdev);
213 void cirrus_driver_irq_preinstall(struct drm_device *dev);
214 int cirrus_driver_irq_postinstall(struct drm_device *dev);
215 void cirrus_driver_irq_uninstall(struct drm_device *dev);
216 irqreturn_t cirrus_driver_irq_handler(int irq, void *arg);
219 int cirrus_driver_load(struct drm_device *dev, unsigned long flags);
220 void cirrus_driver_unload(struct drm_device *dev);
221 extern struct drm_ioctl_desc cirrus_ioctls[];
222 extern int cirrus_max_ioctl;
224 int cirrus_mm_init(struct cirrus_device *cirrus);
225 void cirrus_mm_fini(struct cirrus_device *cirrus);
226 void cirrus_ttm_placement(struct cirrus_bo *bo, int domain);
227 int cirrus_bo_create(struct drm_device *dev, int size, int align,
228 uint32_t flags, struct cirrus_bo **pcirrusbo);
229 int cirrus_mmap(struct file *filp, struct vm_area_struct *vma);
231 static inline int cirrus_bo_reserve(struct cirrus_bo *bo, bool no_wait)
235 ret = ttm_bo_reserve(&bo->bo, true, no_wait, NULL);
237 if (ret != -ERESTARTSYS && ret != -EBUSY)
238 DRM_ERROR("reserve failed %p\n", bo);
244 static inline void cirrus_bo_unreserve(struct cirrus_bo *bo)
246 ttm_bo_unreserve(&bo->bo);
249 int cirrus_bo_push_sysram(struct cirrus_bo *bo);
250 int cirrus_bo_pin(struct cirrus_bo *bo, u32 pl_flag, u64 *gpu_addr);
252 extern int cirrus_bpp;
254 #endif /* __CIRRUS_DRV_H__ */