1 #ifndef _INTELFB_H
2 #define _INTELFB_H
3 
4 /* $DHD: intelfb/intelfb.h,v 1.38 2003/02/06 17:29:41 dawes Exp $ */
5 /* $TG$ */
6 
7 
8 /*** Version/name ***/
9 #define INTELFB_VERSION			"0.7.7"
10 #define INTELFB_MODULE_NAME		"intelfb"
11 #define SUPPORTED_CHIPSETS		"830M/845G/852GM/855GM/865G"
12 
13 
14 /*** Debug/feature defines ***/
15 
16 #ifndef DEBUG
17 #define DEBUG				0
18 #endif
19 
20 #ifndef VERBOSE
21 #define VERBOSE				1
22 #endif
23 
24 #ifndef REGDUMP
25 #define REGDUMP				0
26 #endif
27 
28 #ifndef DETECT_VGA_CLASS_ONLY
29 #define DETECT_VGA_CLASS_ONLY		1
30 #endif
31 
32 #ifndef FIXED_MODE
33 #define FIXED_MODE			0
34 #endif
35 
36 #ifndef ALLOCATE_FOR_PANNING
37 #define ALLOCATE_FOR_PANNING		0
38 #endif
39 
40 #ifndef BAILOUT_EARLY
41 #define BAILOUT_EARLY			0
42 #endif
43 
44 #ifndef TEST_MODE_TO_HW
45 #define TEST_MODE_TO_HW			0
46 #endif
47 
48 #ifndef USE_SYNC_PAGE
49 #define USE_SYNC_PAGE			1
50 #endif
51 
52 #ifndef MOBILE_HW_CURSOR
53 #define MOBILE_HW_CURSOR		0
54 #endif
55 
56 #ifndef PREFERRED_MODE
57 #define PREFERRED_MODE			"1024x768-16@60"
58 #endif
59 
60 /*** hw-related values ***/
61 
62 /* PCI ids for supported devices */
63 #define PCI_DEVICE_ID_INTEL_830M	0x3577
64 #define PCI_DEVICE_ID_INTEL_845G	0x2562
65 #define PCI_DEVICE_ID_INTEL_85XGM	0x3582
66 #define PCI_DEVICE_ID_INTEL_865G	0x2572
67 
68 /* Size of MMIO region */
69 #define INTEL_REG_SIZE			0x80000
70 
71 #define STRIDE_ALIGNMENT		16
72 
73 #define PAT_ROP_GXCOPY                  0xf0
74 #define PAT_ROP_GXXOR                   0x5a
75 
76 #define PALETTE_8_ENTRIES		256
77 
78 
79 /*** Macros ***/
80 
81 /* basic arithmetic */
82 #define KB(x)			((x) * 1024)
83 #define MB(x)			((x) * 1024 * 1024)
84 #define BtoKB(x)		((x) / 1024)
85 #define BtoMB(x)		((x) / 1024 / 1024)
86 
87 #define ROUND_UP_TO(x, y)	(((x) + (y) - 1) / (y) * (y))
88 #define ROUND_DOWN_TO(x, y)	((x) / (y) * (y))
89 #define ROUND_UP_TO_PAGE(x)	ROUND_UP_TO((x), PAGE_SIZE)
90 #define ROUND_DOWN_TO_PAGE(x)	ROUND_DOWN_TO((x), PAGE_SIZE)
91 
92 /* messages */
93 #define PFX			INTELFB_MODULE_NAME ": "
94 
95 #define ERR_MSG(fmt, args...)	printk(KERN_ERR PFX fmt, ## args)
96 #define WRN_MSG(fmt, args...)	printk(KERN_WARNING PFX fmt, ## args)
97 #define NOT_MSG(fmt, args...)	printk(KERN_NOTICE PFX fmt, ## args)
98 #define INF_MSG(fmt, args...)	printk(KERN_INFO PFX fmt, ## args)
99 #if DEBUG
100 #define DBG_MSG(fmt, args...)	printk(KERN_DEBUG PFX fmt, ## args)
101 #else
102 #define DBG_MSG(fmt, args...)	while (0) printk(fmt, ## args)
103 #endif
104 
105 /* get commonly used pointers */
106 #define GET_DINFO(info)		(struct intelfb_info *)(info)
107 #define GET_DISP(info, con)	((con) < 0) ? (info)->disp : &fb_display[con]
108 
109 /* module parameters */
110 #define INTELFB_INT_PARAM(name, default, desc)				\
111 	static int name = default;					\
112 	MODULE_PARM(name, "i");						\
113 	MODULE_PARM_DESC(name, desc);
114 
115 #define INTELFB_STR_PARAM(name, default, desc)				\
116 	static const char *name = default;				\
117 	MODULE_PARM(name, "s");						\
118 	MODULE_PARM_DESC(name, desc);
119 
120 /* misc macros */
121 #define TEXT_ACCEL(d, v)						\
122 	((d)->accel && (d)->ring_active &&				\
123 	 ((v)->accel_flags & FB_ACCELF_TEXT))
124 
125 #define USE_DRAWGLYPH(d)						\
126 	((d)->chipset == INTEL_865G)
127 
128 #define NOACCEL_CHIPSET(d)						\
129 	((d)->chipset != INTEL_865G)
130 
131 #ifndef LockPage
132 #define LockPage(page)		set_bit(PG_locked, &(page)->flags)
133 #endif
134 #ifndef UnlockPage
135 #define UnlockPage(page)	unlock_page(page)
136 #endif
137 
138 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
139 #define FB_SET_CMAP(a, b, c, d) fb_set_cmap(a, b, d)
140 #else
141 #define FB_SET_CMAP(a, b, c, d) fb_set_cmap(a, b, c, d)
142 #endif
143 
144 
145 /*** Driver paramters ***/
146 
147 #define RINGBUFFER_SIZE		KB(64)
148 #define HW_CURSOR_SIZE		KB(4)
149 
150 
151 /*** Data Types ***/
152 
153 /* supported chipsets */
154 enum intel_chips {
155 	INTEL_830M,
156 	INTEL_845G,
157 	INTEL_85XGM,
158 	INTEL_852GM,
159 	INTEL_852GME,
160 	INTEL_855GM,
161 	INTEL_855GME,
162 	INTEL_865G
163 };
164 
165 struct intelfb_hwstate {
166 	u32 vga0_divisor;
167 	u32 vga1_divisor;
168 	u32 vga_pd;
169 	u32 dpll_a;
170 	u32 dpll_b;
171 	u32 fpa0;
172 	u32 fpa1;
173 	u32 fpb0;
174 	u32 fpb1;
175 	u32 palette_a[PALETTE_8_ENTRIES];
176 	u32 palette_b[PALETTE_8_ENTRIES];
177 	u32 htotal_a;
178 	u32 hblank_a;
179 	u32 hsync_a;
180 	u32 vtotal_a;
181 	u32 vblank_a;
182 	u32 vsync_a;
183 	u32 src_size_a;
184 	u32 bclrpat_a;
185 	u32 htotal_b;
186 	u32 hblank_b;
187 	u32 hsync_b;
188 	u32 vtotal_b;
189 	u32 vblank_b;
190 	u32 vsync_b;
191 	u32 src_size_b;
192 	u32 bclrpat_b;
193 	u32 adpa;
194 	u32 dvoa;
195 	u32 dvob;
196 	u32 dvoc;
197 	u32 dvoa_srcdim;
198 	u32 dvob_srcdim;
199 	u32 dvoc_srcdim;
200 	u32 lvds;
201 	u32 pipe_a_conf;
202 	u32 pipe_b_conf;
203 	u32 disp_arb;
204 	u32 cursor_a_control;
205 	u32 cursor_b_control;
206 	u32 cursor_a_base;
207 	u32 cursor_b_base;
208 	u32 cursor_size;
209 	u32 disp_a_ctrl;
210 	u32 disp_b_ctrl;
211 	u32 disp_a_base;
212 	u32 disp_b_base;
213 	u32 cursor_a_palette[4];
214 	u32 cursor_b_palette[4];
215 	u32 disp_a_stride;
216 	u32 disp_b_stride;
217 	u32 vgacntrl;
218 	u32 add_id;
219 	u32 swf0x[7];
220 	u32 swf1x[7];
221 	u32 swf3x[3];
222 	u32 fence[8];
223 	u32 instpm;
224 	u32 mem_mode;
225 	u32 fw_blc_0;
226 	u32 fw_blc_1;
227 };
228 
229 struct intelfb_info {
230 	struct fb_info info;
231 
232 	const char *name;
233 
234 	u32 fb_base_phys;
235 	u32 mmio_base_phys;
236 
237 	u32 fb_base;
238 	u32 mmio_base;
239 
240 	u32 fb_offset;
241 
242 	struct pci_dev *pdev;
243 
244 	/* Ring buffer */
245 	u32 ring_base_phys;
246 	u32 ring_base;
247 	u32 ring_size;
248 	u32 ring_head;
249 	u32 ring_tail;
250 	u32 ring_tail_mask;
251 	u32 ring_space;
252 
253 	/* HW cursor */
254 	u32 cursor_base_phys;
255 	u32 cursor_offset;
256 	u32 cursor_base;
257 	u32 cursor_size;
258 	u32 cursor_page_virt;
259 	u32 cursor_base_real;
260 
261 #if USE_SYNC_PAGE
262 	/* 2D synchronisation */
263 	u32 syncpage_virt;
264 	u32 syncpage_phys;
265 #endif
266 
267 	struct display disp;
268 	int currcon;
269 	struct display *currcon_display;
270 
271 	struct { u8 red, green, blue, pad; } palette[256];
272 
273 	int pci_chipset;
274 	int chipset;
275 	int mobile;
276 
277 	int video_ram;
278 	int aperture_size;
279 	int stolen_size;
280 	int bpp, depth;
281 	u32 visual;
282 
283 	int xres, yres, pitch;
284 	int pixclock;
285 
286 	int pipe;
287 
288 	int accel;
289 	int hwcursor;
290 	int fixed_mode;
291 
292 	int ring_active;
293 
294 #if defined(FBCON_HAS_CFB16) || defined(FBCON_HAS_CFB32)
295 	union {
296 #if defined(FBCON_HAS_CFB16)
297 		u_int16_t cfb16[16];
298 #endif
299 #if defined(FBCON_HAS_CFB32)
300 		u_int32_t cfb32[16];
301 #endif
302 	} con_cmap;
303 #endif
304 
305 	int vc_mode;
306 
307 	struct intelfb_hwstate save_state;
308 
309 	int registered;
310 
311 	int initial_vga;
312 	struct fb_var_screeninfo initial_var;
313 	u32 initial_fb_base;
314 	u32 initial_video_ram;
315 	u32 initial_pitch;
316 
317 	struct {
318 		int type;
319 		int state;
320 		int on;
321 		int enabled;
322 		int blanked;
323 		int w, u, d;
324 		int x, y, redraw;
325 		unsigned long cursorimage;
326 		struct timer_list timer;
327 	} cursor;
328 	spinlock_t DAClock;
329 };
330 
331 
332 /*** Functions ***/
333 
334 /* intelfb.c */
335 extern int intelfb_var_to_depth(const struct fb_var_screeninfo *var);
336 extern void intelfb_create_cursor_shape(struct intelfb_info *dinfo,
337 					struct display *disp);
338 
339 /* intelfbhw.c */
340 
341 extern int intelfbhw_get_chipset(struct pci_dev *pdev, const char **name,
342 				 int *chipset, int *mobile);
343 extern int intelfbhw_get_memory(struct pci_dev *pdev, int *aperture_size,
344 				int *stolen_size);
345 extern const char *intelfbhw_check_non_crt(struct intelfb_info *dinfo);
346 extern int intelfbhw_validate_mode(struct intelfb_info *dinfo, int con,
347 				   struct fb_var_screeninfo *var);
348 extern int intelfbhw_pan_display(struct fb_var_screeninfo *var, int con,
349 				 struct fb_info *info);
350 extern void intelfbhw_do_blank(int blank, struct fb_info *info);
351 extern void intelfbhw_setcolreg(struct intelfb_info *dinfo, unsigned regno,
352 				unsigned red, unsigned green, unsigned blue,
353 				unsigned transp);
354 extern int intelfbhw_read_hw_state(struct intelfb_info *dinfo,
355 				   struct intelfb_hwstate *hw, int flag);
356 extern void intelfbhw_print_hw_state(struct intelfb_info *dinfo,
357 				     struct intelfb_hwstate *hw);
358 extern int intelfbhw_mode_to_hw(struct intelfb_info *dinfo,
359 				struct intelfb_hwstate *hw,
360 				struct fb_var_screeninfo *var);
361 extern int intelfbhw_program_mode(struct intelfb_info *dinfo,
362 				  const struct intelfb_hwstate *hw, int blank);
363 extern void intelfbhw_do_sync(struct intelfb_info *dinfo);
364 extern void intelfbhw_2d_stop(struct intelfb_info *dinfo);
365 extern void intelfbhw_2d_start(struct intelfb_info *dinfo);
366 extern void intelfbhw_do_fillrect(struct intelfb_info *dinfo, u32 x, u32 y,
367 				  u32 w, u32 h, u32 color, u32 pitch, u32 bpp,
368 				  u32 rop);
369 extern void intelfbhw_do_bitblt(struct intelfb_info *dinfo, u32 curx, u32 cury,
370 				u32 dstx, u32 dsty, u32 w, u32 h, u32 pitch,
371 				u32 bpp);
372 extern int intelfbhw_do_drawglyph(struct intelfb_info *dinfo, u32 fg, u32 bg,
373 				  u32 w, u32 h, u8* cdat, u32 x, u32 y,
374 				  u32 pitch, u32 bpp);
375 extern void intelfbhw_cursor_init(struct intelfb_info *dinfo);
376 extern void intelfbhw_cursor_hide(struct intelfb_info *dinfo);
377 extern void intelfbhw_cursor_show(struct intelfb_info *dinfo);
378 extern void intelfbhw_cursor_setpos(struct intelfb_info *dinfo, int x, int y);
379 extern void intelfbhw_cursor_setcolor(struct intelfb_info *dinfo, u32 bg,
380 				      u32 fg);
381 extern void intelfbhw_cursor_load(struct intelfb_info *dinfo,
382 				  struct display *disp);
383 
384 
385 #endif /* _INTELFB_H */
386