blob: 4d932c46725dda950a4b2cd197e1923fca18ab50 [file] [log] [blame]
Dave Airlie414c4532012-04-17 15:01:25 +01001/*
2 * Copyright 2010 Matt Turner.
3 * Copyright 2012 Red Hat
4 *
5 * This file is subject to the terms and conditions of the GNU General
6 * Public License version 2. See the file COPYING in the main
7 * directory of this archive for more details.
8 *
9 * Authors: Matthew Garrett
10 * Matt Turner
11 * Dave Airlie
12 */
13#ifndef __MGAG200_DRV_H__
14#define __MGAG200_DRV_H__
15
16#include <video/vga.h>
17
David Howells760285e2012-10-02 18:01:07 +010018#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>
Dave Airlie414c4532012-04-17 15:01:25 +010024
25#include <linux/i2c.h>
26#include <linux/i2c-algo-bit.h>
27
28#include "mgag200_reg.h"
29
30#define DRIVER_AUTHOR "Matthew Garrett"
31
32#define DRIVER_NAME "mgag200"
33#define DRIVER_DESC "MGA G200 SE"
34#define DRIVER_DATE "20110418"
35
36#define DRIVER_MAJOR 1
37#define DRIVER_MINOR 0
38#define DRIVER_PATCHLEVEL 0
39
40#define MGAG200FB_CONN_LIMIT 1
41
42#define RREG8(reg) ioread8(((void __iomem *)mdev->rmmio) + (reg))
43#define WREG8(reg, v) iowrite8(v, ((void __iomem *)mdev->rmmio) + (reg))
44#define RREG32(reg) ioread32(((void __iomem *)mdev->rmmio) + (reg))
45#define WREG32(reg, v) iowrite32(v, ((void __iomem *)mdev->rmmio) + (reg))
46
47#define ATTR_INDEX 0x1fc0
48#define ATTR_DATA 0x1fc1
49
50#define WREG_ATTR(reg, v) \
51 do { \
52 RREG8(0x1fda); \
53 WREG8(ATTR_INDEX, reg); \
54 WREG8(ATTR_DATA, v); \
55 } while (0) \
56
57#define WREG_SEQ(reg, v) \
58 do { \
59 WREG8(MGAREG_SEQ_INDEX, reg); \
60 WREG8(MGAREG_SEQ_DATA, v); \
61 } while (0) \
62
63#define WREG_CRT(reg, v) \
64 do { \
65 WREG8(MGAREG_CRTC_INDEX, reg); \
66 WREG8(MGAREG_CRTC_DATA, v); \
67 } while (0) \
68
69
70#define WREG_ECRT(reg, v) \
71 do { \
72 WREG8(MGAREG_CRTCEXT_INDEX, reg); \
73 WREG8(MGAREG_CRTCEXT_DATA, v); \
74 } while (0) \
75
76#define GFX_INDEX 0x1fce
77#define GFX_DATA 0x1fcf
78
79#define WREG_GFX(reg, v) \
80 do { \
81 WREG8(GFX_INDEX, reg); \
82 WREG8(GFX_DATA, v); \
83 } while (0) \
84
85#define DAC_INDEX 0x3c00
86#define DAC_DATA 0x3c0a
87
88#define WREG_DAC(reg, v) \
89 do { \
90 WREG8(DAC_INDEX, reg); \
91 WREG8(DAC_DATA, v); \
92 } while (0) \
93
94#define MGA_MISC_OUT 0x1fc2
95#define MGA_MISC_IN 0x1fcc
96
97#define MGAG200_MAX_FB_HEIGHT 4096
98#define MGAG200_MAX_FB_WIDTH 4096
99
100#define MATROX_DPMS_CLEARED (-1)
101
102#define to_mga_crtc(x) container_of(x, struct mga_crtc, base)
103#define to_mga_encoder(x) container_of(x, struct mga_encoder, base)
104#define to_mga_connector(x) container_of(x, struct mga_connector, base)
105#define to_mga_framebuffer(x) container_of(x, struct mga_framebuffer, base)
106
107struct mga_framebuffer {
108 struct drm_framebuffer base;
109 struct drm_gem_object *obj;
110};
111
112struct mga_fbdev {
113 struct drm_fb_helper helper;
114 struct mga_framebuffer mfb;
Dave Airlie414c4532012-04-17 15:01:25 +0100115 void *sysram;
116 int size;
117 struct ttm_bo_kmap_obj mapping;
118};
119
120struct mga_crtc {
121 struct drm_crtc base;
122 u8 lut_r[256], lut_g[256], lut_b[256];
123 int last_dpms;
124 bool enabled;
125};
126
127struct mga_mode_info {
128 bool mode_config_initialized;
129 struct mga_crtc *crtc;
130};
131
132struct mga_encoder {
133 struct drm_encoder base;
134 int last_dpms;
135};
136
137
138struct mga_i2c_chan {
139 struct i2c_adapter adapter;
140 struct drm_device *dev;
141 struct i2c_algo_bit_data bit;
142 int data, clock;
143};
144
145struct mga_connector {
146 struct drm_connector base;
147 struct mga_i2c_chan *i2c;
148};
149
150
151struct mga_mc {
152 resource_size_t vram_size;
153 resource_size_t vram_base;
154 resource_size_t vram_window;
155};
156
157enum mga_type {
158 G200_SE_A,
159 G200_SE_B,
160 G200_WB,
161 G200_EV,
162 G200_EH,
163 G200_ER,
164};
165
166#define IS_G200_SE(mdev) (mdev->type == G200_SE_A || mdev->type == G200_SE_B)
167
168struct mga_device {
169 struct drm_device *dev;
170 unsigned long flags;
171
172 resource_size_t rmmio_base;
173 resource_size_t rmmio_size;
174 void __iomem *rmmio;
175
176 drm_local_map_t *framebuffer;
177
178 struct mga_mc mc;
179 struct mga_mode_info mode_info;
180
181 struct mga_fbdev *mfbdev;
182
183 bool suspended;
184 int num_crtc;
185 enum mga_type type;
186 int has_sdram;
187 struct drm_display_mode mode;
188
189 int bpp_shifts[4];
190
191 int fb_mtrr;
192
193 struct {
194 struct drm_global_reference mem_global_ref;
195 struct ttm_bo_global_ref bo_global_ref;
196 struct ttm_bo_device bdev;
Dave Airlie414c4532012-04-17 15:01:25 +0100197 } ttm;
198
199 u32 reg_1e24; /* SE model number */
200};
201
202
203struct mgag200_bo {
204 struct ttm_buffer_object bo;
205 struct ttm_placement placement;
206 struct ttm_bo_kmap_obj kmap;
207 struct drm_gem_object gem;
208 u32 placements[3];
209 int pin_count;
210};
211#define gem_to_mga_bo(gobj) container_of((gobj), struct mgag200_bo, gem)
212
213static inline struct mgag200_bo *
214mgag200_bo(struct ttm_buffer_object *bo)
215{
216 return container_of(bo, struct mgag200_bo, bo);
217}
218 /* mga_crtc.c */
219void mga_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
220 u16 blue, int regno);
221void mga_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green,
222 u16 *blue, int regno);
223
224 /* mgag200_mode.c */
225int mgag200_modeset_init(struct mga_device *mdev);
226void mgag200_modeset_fini(struct mga_device *mdev);
227
228 /* mga_fbdev.c */
229int mgag200_fbdev_init(struct mga_device *mdev);
230void mgag200_fbdev_fini(struct mga_device *mdev);
231
232 /* mgag200_main.c */
233int mgag200_framebuffer_init(struct drm_device *dev,
234 struct mga_framebuffer *mfb,
235 struct drm_mode_fb_cmd2 *mode_cmd,
236 struct drm_gem_object *obj);
237
238
239int mgag200_driver_load(struct drm_device *dev, unsigned long flags);
240int mgag200_driver_unload(struct drm_device *dev);
241int mgag200_gem_create(struct drm_device *dev,
242 u32 size, bool iskernel,
243 struct drm_gem_object **obj);
244int mgag200_gem_init_object(struct drm_gem_object *obj);
245int mgag200_dumb_create(struct drm_file *file,
246 struct drm_device *dev,
247 struct drm_mode_create_dumb *args);
248int mgag200_dumb_destroy(struct drm_file *file,
249 struct drm_device *dev,
250 uint32_t handle);
251void mgag200_gem_free_object(struct drm_gem_object *obj);
252int
253mgag200_dumb_mmap_offset(struct drm_file *file,
254 struct drm_device *dev,
255 uint32_t handle,
256 uint64_t *offset);
257 /* mga_i2c.c */
258struct mga_i2c_chan *mgag200_i2c_create(struct drm_device *dev);
259void mgag200_i2c_destroy(struct mga_i2c_chan *i2c);
260
261#define DRM_FILE_PAGE_OFFSET (0x100000000ULL >> PAGE_SHIFT)
262void mgag200_ttm_placement(struct mgag200_bo *bo, int domain);
263
264int mgag200_bo_reserve(struct mgag200_bo *bo, bool no_wait);
265void mgag200_bo_unreserve(struct mgag200_bo *bo);
266int mgag200_bo_create(struct drm_device *dev, int size, int align,
267 uint32_t flags, struct mgag200_bo **pastbo);
268int mgag200_mm_init(struct mga_device *mdev);
269void mgag200_mm_fini(struct mga_device *mdev);
270int mgag200_mmap(struct file *filp, struct vm_area_struct *vma);
271int mgag200_bo_pin(struct mgag200_bo *bo, u32 pl_flag, u64 *gpu_addr);
272int mgag200_bo_unpin(struct mgag200_bo *bo);
273int mgag200_bo_push_sysram(struct mgag200_bo *bo);
274#endif /* __MGAG200_DRV_H__ */