OSDN Git Service

i915: more version checks
[android-x86/external-libdrm.git] / shared-core / i915_drv.h
1 /* i915_drv.h -- Private header for the I915 driver -*- linux-c -*-
2  */
3 /*
4  *
5  * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
6  * All Rights Reserved.
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a
9  * copy of this software and associated documentation files (the
10  * "Software"), to deal in the Software without restriction, including
11  * without limitation the rights to use, copy, modify, merge, publish,
12  * distribute, sub license, and/or sell copies of the Software, and to
13  * permit persons to whom the Software is furnished to do so, subject to
14  * the following conditions:
15  *
16  * The above copyright notice and this permission notice (including the
17  * next paragraph) shall be included in all copies or substantial portions
18  * of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
23  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
24  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27  *
28  */
29
30 #ifndef _I915_DRV_H_
31 #define _I915_DRV_H_
32
33 /* General customization:
34  */
35
36 #define DRIVER_AUTHOR           "Tungsten Graphics, Inc."
37
38 #define DRIVER_NAME             "i915"
39 #define DRIVER_DESC             "Intel Graphics"
40 #define DRIVER_DATE             "20080312"
41
42 #if defined(__linux__)
43 #define I915_HAVE_FENCE
44 #define I915_HAVE_BUFFER
45 #endif
46
47 /* Interface history:
48  *
49  * 1.1: Original.
50  * 1.2: Add Power Management
51  * 1.3: Add vblank support
52  * 1.4: Fix cmdbuffer path, add heap destroy
53  * 1.5: Add vblank pipe configuration
54  * 1.6: - New ioctl for scheduling buffer swaps on vertical blank
55  *      - Support vertical blank on secondary display pipe
56  * 1.8: New ioctl for ARB_Occlusion_Query
57  * 1.9: Usable page flipping and triple buffering
58  * 1.10: Plane/pipe disentangling
59  * 1.11: TTM superioctl
60  * 1.12: TTM relocation optimization
61  */
62 #define DRIVER_MAJOR            1
63 #if defined(I915_HAVE_FENCE) && defined(I915_HAVE_BUFFER)
64 #define DRIVER_MINOR            13
65 #else
66 #define DRIVER_MINOR            6
67 #endif
68 #define DRIVER_PATCHLEVEL       0
69
70 enum pipe {
71     PIPE_A = 0,
72     PIPE_B,
73 };
74
75 #ifdef I915_HAVE_BUFFER
76 #define I915_MAX_VALIDATE_BUFFERS 4096
77 struct drm_i915_validate_buffer;
78 #endif
79
80 typedef struct _drm_i915_ring_buffer {
81         int tail_mask;
82         unsigned long Start;
83         unsigned long End;
84         unsigned long Size;
85         u8 *virtual_start;
86         int head;
87         int tail;
88         int space;
89         drm_local_map_t map;
90 } drm_i915_ring_buffer_t;
91
92 struct mem_block {
93         struct mem_block *next;
94         struct mem_block *prev;
95         int start;
96         int size;
97         struct drm_file *file_priv; /* NULL: free, -1: heap, other: real files */
98 };
99
100 typedef struct _drm_i915_vbl_swap {
101         struct list_head head;
102         drm_drawable_t drw_id;
103         unsigned int plane;
104         unsigned int sequence;
105         int flip;
106 } drm_i915_vbl_swap_t;
107
108 #ifdef __linux__
109 struct opregion_header;
110 struct opregion_acpi;
111 struct opregion_swsci;
112 struct opregion_asle;
113
114 struct intel_opregion {
115         struct opregion_header *header;
116         struct opregion_acpi *acpi;
117         struct opregion_swsci *swsci;
118         struct opregion_asle *asle;
119
120         int enabled;
121 };
122 #endif
123
124 typedef struct drm_i915_private {
125         drm_local_map_t *sarea;
126         drm_local_map_t *mmio_map;
127
128         drm_i915_sarea_t *sarea_priv;
129         drm_i915_ring_buffer_t ring;
130
131         drm_dma_handle_t *status_page_dmah;
132         void *hw_status_page;
133         dma_addr_t dma_status_page;
134         uint32_t counter;
135         unsigned int status_gfx_addr;
136         drm_local_map_t hws_map;
137
138         unsigned int cpp;
139         int use_mi_batchbuffer_start;
140
141         wait_queue_head_t irq_queue;
142         atomic_t irq_received;
143         atomic_t irq_emitted;
144
145         int tex_lru_log_granularity;
146         int allow_batchbuffer;
147         struct mem_block *agp_heap;
148         unsigned int sr01, adpa, ppcr, dvob, dvoc, lvds;
149         int vblank_pipe;
150         DRM_SPINTYPE user_irq_lock;
151         int user_irq_refcount;
152         int fence_irq_on;
153         uint32_t irq_enable_reg;
154         int irq_enabled;
155
156 #ifdef I915_HAVE_FENCE
157         uint32_t flush_sequence;
158         uint32_t flush_flags;
159         uint32_t flush_pending;
160         uint32_t saved_flush_status;
161 #endif
162 #ifdef I915_HAVE_BUFFER
163         void *agp_iomap;
164         unsigned int max_validate_buffers;
165         struct mutex cmdbuf_mutex;
166         struct drm_i915_validate_buffer *val_bufs;
167 #endif
168
169         DRM_SPINTYPE swaps_lock;
170         drm_i915_vbl_swap_t vbl_swaps;
171         unsigned int swaps_pending;
172 #if defined(I915_HAVE_BUFFER)
173         /* DRI2 sarea */
174         struct drm_buffer_object *sarea_bo;
175         struct drm_bo_kmap_obj sarea_kmap;
176 #endif
177
178 #ifdef __linux__
179         struct intel_opregion opregion;
180 #endif
181
182         /* Register state */
183         u8 saveLBB;
184         u32 saveDSPACNTR;
185         u32 saveDSPBCNTR;
186         u32 saveDSPARB;
187         u32 savePIPEACONF;
188         u32 savePIPEBCONF;
189         u32 savePIPEASRC;
190         u32 savePIPEBSRC;
191         u32 saveFPA0;
192         u32 saveFPA1;
193         u32 saveDPLL_A;
194         u32 saveDPLL_A_MD;
195         u32 saveHTOTAL_A;
196         u32 saveHBLANK_A;
197         u32 saveHSYNC_A;
198         u32 saveVTOTAL_A;
199         u32 saveVBLANK_A;
200         u32 saveVSYNC_A;
201         u32 saveBCLRPAT_A;
202         u32 savePIPEASTAT;
203         u32 saveDSPASTRIDE;
204         u32 saveDSPASIZE;
205         u32 saveDSPAPOS;
206         u32 saveDSPAADDR;
207         u32 saveDSPASURF;
208         u32 saveDSPATILEOFF;
209         u32 savePFIT_PGM_RATIOS;
210         u32 saveBLC_PWM_CTL;
211         u32 saveBLC_PWM_CTL2;
212         u32 saveFPB0;
213         u32 saveFPB1;
214         u32 saveDPLL_B;
215         u32 saveDPLL_B_MD;
216         u32 saveHTOTAL_B;
217         u32 saveHBLANK_B;
218         u32 saveHSYNC_B;
219         u32 saveVTOTAL_B;
220         u32 saveVBLANK_B;
221         u32 saveVSYNC_B;
222         u32 saveBCLRPAT_B;
223         u32 savePIPEBSTAT;
224         u32 saveDSPBSTRIDE;
225         u32 saveDSPBSIZE;
226         u32 saveDSPBPOS;
227         u32 saveDSPBADDR;
228         u32 saveDSPBSURF;
229         u32 saveDSPBTILEOFF;
230         u32 saveVGA0;
231         u32 saveVGA1;
232         u32 saveVGA_PD;
233         u32 saveVGACNTRL;
234         u32 saveADPA;
235         u32 saveLVDS;
236         u32 savePP_ON_DELAYS;
237         u32 savePP_OFF_DELAYS;
238         u32 saveDVOA;
239         u32 saveDVOB;
240         u32 saveDVOC;
241         u32 savePP_ON;
242         u32 savePP_OFF;
243         u32 savePP_CONTROL;
244         u32 savePP_DIVISOR;
245         u32 savePFIT_CONTROL;
246         u32 save_palette_a[256];
247         u32 save_palette_b[256];
248         u32 saveFBC_CFB_BASE;
249         u32 saveFBC_LL_BASE;
250         u32 saveFBC_CONTROL;
251         u32 saveFBC_CONTROL2;
252         u32 saveIER;
253         u32 saveIIR;
254         u32 saveIMR;
255         u32 saveCACHE_MODE_0;
256         u32 saveD_STATE;
257         u32 saveCG_2D_DIS;
258         u32 saveMI_ARB_STATE;
259         u32 saveSWF0[16];
260         u32 saveSWF1[16];
261         u32 saveSWF2[3];
262         u8 saveMSR;
263         u8 saveSR[8];
264         u8 saveGR[25];
265         u8 saveAR_INDEX;
266         u8 saveAR[21];
267         u8 saveDACMASK;
268         u8 saveDACDATA[256*3]; /* 256 3-byte colors */
269         u8 saveCR[37];
270 } drm_i915_private_t;
271
272 enum intel_chip_family {
273         CHIP_I8XX = 0x01,
274         CHIP_I9XX = 0x02,
275         CHIP_I915 = 0x04,
276         CHIP_I965 = 0x08,
277 };
278
279 extern struct drm_ioctl_desc i915_ioctls[];
280 extern int i915_max_ioctl;
281
282                                 /* i915_dma.c */
283 extern void i915_kernel_lost_context(struct drm_device * dev);
284 extern int i915_driver_load(struct drm_device *, unsigned long flags);
285 extern int i915_driver_unload(struct drm_device *);
286 extern void i915_driver_lastclose(struct drm_device * dev);
287 extern void i915_driver_preclose(struct drm_device *dev,
288                                  struct drm_file *file_priv);
289 extern int i915_driver_device_is_agp(struct drm_device * dev);
290 extern long i915_compat_ioctl(struct file *filp, unsigned int cmd,
291                               unsigned long arg);
292 extern void i915_emit_breadcrumb(struct drm_device *dev);
293 extern void i915_dispatch_flip(struct drm_device * dev, int pipes, int sync);
294 extern int i915_emit_mi_flush(struct drm_device *dev, uint32_t flush);
295 extern int i915_driver_firstopen(struct drm_device *dev);
296 extern int i915_dispatch_batchbuffer(struct drm_device * dev,
297                                      drm_i915_batchbuffer_t * batch);
298 extern int i915_quiescent(struct drm_device *dev);
299
300 /* i915_irq.c */
301 extern int i915_irq_emit(struct drm_device *dev, void *data,
302                          struct drm_file *file_priv);
303 extern int i915_irq_wait(struct drm_device *dev, void *data,
304                          struct drm_file *file_priv);
305
306 extern irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS);
307 extern void i915_driver_irq_preinstall(struct drm_device * dev);
308 extern int i915_driver_irq_postinstall(struct drm_device * dev);
309 extern void i915_driver_irq_uninstall(struct drm_device * dev);
310 extern void i915_enable_interrupt(struct drm_device *dev);
311 extern int i915_vblank_pipe_set(struct drm_device *dev, void *data,
312                                 struct drm_file *file_priv);
313 extern int i915_vblank_pipe_get(struct drm_device *dev, void *data,
314                                 struct drm_file *file_priv);
315 extern int i915_emit_irq(struct drm_device * dev);
316 extern int i915_enable_vblank(struct drm_device *dev, int crtc);
317 extern void i915_disable_vblank(struct drm_device *dev, int crtc);
318 extern u32 i915_get_vblank_counter(struct drm_device *dev, int crtc);
319 extern int i915_vblank_swap(struct drm_device *dev, void *data,
320                             struct drm_file *file_priv);
321 extern void i915_user_irq_on(drm_i915_private_t *dev_priv);
322 extern void i915_user_irq_off(drm_i915_private_t *dev_priv);
323
324 /* i915_mem.c */
325 extern int i915_mem_alloc(struct drm_device *dev, void *data,
326                           struct drm_file *file_priv);
327 extern int i915_mem_free(struct drm_device *dev, void *data,
328                          struct drm_file *file_priv);
329 extern int i915_mem_init_heap(struct drm_device *dev, void *data,
330                               struct drm_file *file_priv);
331 extern int i915_mem_destroy_heap(struct drm_device *dev, void *data,
332                                  struct drm_file *file_priv);
333 extern void i915_mem_takedown(struct mem_block **heap);
334 extern void i915_mem_release(struct drm_device * dev,
335                              struct drm_file *file_priv,
336                              struct mem_block *heap);
337
338 /* i915_suspend.c */
339 extern int i915_save_state(struct drm_device *dev);
340 extern int i915_restore_state(struct drm_device *dev);
341
342 #ifdef I915_HAVE_FENCE
343 /* i915_fence.c */
344 extern void i915_fence_handler(struct drm_device *dev);
345 extern void i915_invalidate_reported_sequence(struct drm_device *dev);
346
347 #endif
348
349 #ifdef I915_HAVE_BUFFER
350 /* i915_buffer.c */
351 extern struct drm_ttm_backend *i915_create_ttm_backend_entry(struct drm_device *dev);
352 extern int i915_fence_type(struct drm_buffer_object *bo, uint32_t *fclass,
353                            uint32_t *type);
354 extern int i915_invalidate_caches(struct drm_device *dev, uint64_t buffer_flags);
355 extern int i915_init_mem_type(struct drm_device *dev, uint32_t type,
356                                struct drm_mem_type_manager *man);
357 extern uint64_t i915_evict_flags(struct drm_buffer_object *bo);
358 extern int i915_move(struct drm_buffer_object *bo, int evict,
359                 int no_wait, struct drm_bo_mem_reg *new_mem);
360 void i915_flush_ttm(struct drm_ttm *ttm);
361 /* i915_execbuf.c */
362 int i915_execbuffer(struct drm_device *dev, void *data,
363                                    struct drm_file *file_priv);
364
365 #endif
366
367 #ifdef __linux__
368 /* i915_opregion.c */
369 extern int intel_opregion_init(struct drm_device *dev);
370 extern void intel_opregion_free(struct drm_device *dev);
371 extern void opregion_asle_intr(struct drm_device *dev);
372 extern void opregion_enable_asle(struct drm_device *dev);
373 #endif
374
375 #ifdef __linux__
376 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)
377 extern void intel_init_chipset_flush_compat(struct drm_device *dev);
378 extern void intel_fini_chipset_flush_compat(struct drm_device *dev);
379 #endif
380 #endif
381
382 #define I915_READ(reg)          DRM_READ32(dev_priv->mmio_map, (reg))
383 #define I915_WRITE(reg,val)     DRM_WRITE32(dev_priv->mmio_map, (reg), (val))
384 #define I915_READ16(reg)        DRM_READ16(dev_priv->mmio_map, (reg))
385 #define I915_WRITE16(reg,val)   DRM_WRITE16(dev_priv->mmio_map, (reg), (val))
386 #define I915_READ8(reg)         DRM_READ8(dev_priv->mmio_map, (reg))
387 #define I915_WRITE8(reg,val)    DRM_WRITE8(dev_priv->mmio_map, (reg), (val))
388
389 #if defined(__FreeBSD__)
390 typedef boolean_t bool;
391 #endif
392
393 #define I915_VERBOSE 0
394
395 #define PRIMARY_RINGBUFFER_SIZE         (128*1024)
396
397 #define RING_LOCALS     unsigned int outring, ringmask, outcount; \
398                         volatile char *virt;
399
400 #define BEGIN_LP_RING(n) do {                           \
401         if (I915_VERBOSE)                               \
402                 DRM_DEBUG("BEGIN_LP_RING(%d)\n",        \
403                                  (n));                  \
404         if (dev_priv->ring.space < (n)*4)                      \
405                 i915_wait_ring(dev, (n)*4, __FUNCTION__);      \
406         outcount = 0;                                   \
407         outring = dev_priv->ring.tail;                  \
408         ringmask = dev_priv->ring.tail_mask;            \
409         virt = dev_priv->ring.virtual_start;            \
410 } while (0)
411
412 #define OUT_RING(n) do {                                        \
413         if (I915_VERBOSE) DRM_DEBUG("   OUT_RING %x\n", (int)(n));      \
414         *(volatile unsigned int *)(virt + outring) = (n);               \
415         outcount++;                                             \
416         outring += 4;                                           \
417         outring &= ringmask;                                    \
418 } while (0)
419
420 #define ADVANCE_LP_RING() do {                                          \
421         if (I915_VERBOSE) DRM_DEBUG("ADVANCE_LP_RING %x\n", outring);   \
422         dev_priv->ring.tail = outring;                                  \
423         dev_priv->ring.space -= outcount * 4;                           \
424         I915_WRITE(PRB0_TAIL, outring);                 \
425 } while(0)
426
427 extern int i915_wait_ring(struct drm_device * dev, int n, const char *caller);
428
429 /*
430  * The Bridge device's PCI config space has information about the
431  * fb aperture size and the amount of pre-reserved memory.
432  */
433 #define INTEL_GMCH_CTRL         0x52
434 #define INTEL_GMCH_ENABLED      0x4
435 #define INTEL_GMCH_MEM_MASK     0x1
436 #define INTEL_GMCH_MEM_64M      0x1
437 #define INTEL_GMCH_MEM_128M     0
438
439 #define INTEL_855_GMCH_GMS_MASK         (0x7 << 4)
440 #define INTEL_855_GMCH_GMS_DISABLED     (0x0 << 4)
441 #define INTEL_855_GMCH_GMS_STOLEN_1M    (0x1 << 4)
442 #define INTEL_855_GMCH_GMS_STOLEN_4M    (0x2 << 4)
443 #define INTEL_855_GMCH_GMS_STOLEN_8M    (0x3 << 4)
444 #define INTEL_855_GMCH_GMS_STOLEN_16M   (0x4 << 4)
445 #define INTEL_855_GMCH_GMS_STOLEN_32M   (0x5 << 4)
446
447 #define INTEL_915G_GMCH_GMS_STOLEN_48M  (0x6 << 4)
448 #define INTEL_915G_GMCH_GMS_STOLEN_64M  (0x7 << 4)
449
450 /* PCI config space */
451
452 #define HPLLCC  0xc0 /* 855 only */
453 #define   GC_CLOCK_CONTROL_MASK         (3 << 0)
454 #define   GC_CLOCK_133_200              (0 << 0)
455 #define   GC_CLOCK_100_200              (1 << 0)
456 #define   GC_CLOCK_100_133              (2 << 0)
457 #define   GC_CLOCK_166_250              (3 << 0)
458 #define GCFGC   0xf0 /* 915+ only */
459 #define   GC_LOW_FREQUENCY_ENABLE       (1 << 7)
460 #define   GC_DISPLAY_CLOCK_190_200_MHZ  (0 << 4)
461 #define   GC_DISPLAY_CLOCK_333_MHZ      (4 << 4)
462 #define   GC_DISPLAY_CLOCK_MASK         (7 << 4)
463 #define LBB     0xf4
464
465 /* VGA stuff */
466
467 #define VGA_ST01_MDA 0x3ba
468 #define VGA_ST01_CGA 0x3da
469
470 #define VGA_MSR_WRITE 0x3c2
471 #define VGA_MSR_READ 0x3cc
472 #define   VGA_MSR_MEM_EN (1<<1)
473 #define   VGA_MSR_CGA_MODE (1<<0)
474
475 #define VGA_SR_INDEX 0x3c4
476 #define VGA_SR_DATA 0x3c5
477
478 #define VGA_AR_INDEX 0x3c0
479 #define   VGA_AR_VID_EN (1<<5)
480 #define VGA_AR_DATA_WRITE 0x3c0
481 #define VGA_AR_DATA_READ 0x3c1
482
483 #define VGA_GR_INDEX 0x3ce
484 #define VGA_GR_DATA 0x3cf
485 /* GR05 */
486 #define   VGA_GR_MEM_READ_MODE_SHIFT 3
487 #define     VGA_GR_MEM_READ_MODE_PLANE 1
488 /* GR06 */
489 #define   VGA_GR_MEM_MODE_MASK 0xc
490 #define   VGA_GR_MEM_MODE_SHIFT 2
491 #define   VGA_GR_MEM_A0000_AFFFF 0
492 #define   VGA_GR_MEM_A0000_BFFFF 1
493 #define   VGA_GR_MEM_B0000_B7FFF 2
494 #define   VGA_GR_MEM_B0000_BFFFF 3
495
496 #define VGA_DACMASK 0x3c6
497 #define VGA_DACRX 0x3c7
498 #define VGA_DACWX 0x3c8
499 #define VGA_DACDATA 0x3c9
500
501 #define VGA_CR_INDEX_MDA 0x3b4
502 #define VGA_CR_DATA_MDA 0x3b5
503 #define VGA_CR_INDEX_CGA 0x3d4
504 #define VGA_CR_DATA_CGA 0x3d5
505
506 /*
507  * Memory interface instructions used by the kernel
508  */
509 #define MI_INSTR(opcode, flags) (((opcode) << 23) | (flags))
510
511 #define MI_NOOP                 MI_INSTR(0, 0)
512 #define MI_USER_INTERRUPT       MI_INSTR(0x02, 0)
513 #define MI_WAIT_FOR_EVENT       MI_INSTR(0x03, 0)
514 #define   MI_WAIT_FOR_PLANE_B_FLIP      (1<<6)
515 #define   MI_WAIT_FOR_PLANE_A_FLIP      (1<<2)
516 #define   MI_WAIT_FOR_PLANE_A_SCANLINES (1<<1)
517 #define MI_FLUSH                MI_INSTR(0x04, 0)
518 #define   MI_READ_FLUSH         (1 << 0)
519 #define   MI_EXE_FLUSH          (1 << 1)
520 #define   MI_NO_WRITE_FLUSH     (1 << 2)
521 #define   MI_SCENE_COUNT        (1 << 3) /* just increment scene count */
522 #define   MI_END_SCENE          (1 << 4) /* flush binner and incr scene count */
523 #define MI_BATCH_BUFFER_END     MI_INSTR(0x0a, 0)
524 #define MI_REPORT_HEAD          MI_INSTR(0x07, 0)
525 #define MI_LOAD_SCAN_LINES_INCL MI_INSTR(0x12, 0)
526 #define MI_STORE_DWORD_IMM      MI_INSTR(0x20, 1)
527 #define   MI_MEM_VIRTUAL        (1 << 22) /* 965+ only */
528 #define MI_STORE_DWORD_INDEX    MI_INSTR(0x21, 1)
529 #define MI_LOAD_REGISTER_IMM    MI_INSTR(0x22, 1)
530 #define MI_BATCH_BUFFER         MI_INSTR(0x30, 1)
531 #define   MI_BATCH_NON_SECURE   (1)
532 #define   MI_BATCH_NON_SECURE_I965 (1<<8)
533 #define MI_BATCH_BUFFER_START   MI_INSTR(0x31, 0)
534
535 #define BREADCRUMB_BITS 31
536 #define BREADCRUMB_MASK ((1U << BREADCRUMB_BITS) - 1)
537
538 #define READ_BREADCRUMB(dev_priv)  (((volatile u32*)(dev_priv->hw_status_page))[5])
539
540 /**
541  * Reads a dword out of the status page, which is written to from the command
542  * queue by automatic updates, MI_REPORT_HEAD, MI_STORE_DATA_INDEX, or
543  * MI_STORE_DATA_IMM.
544  *
545  * The following dwords have a reserved meaning:
546  * 0: ISR copy, updated when an ISR bit not set in the HWSTAM changes.
547  * 4: ring 0 head pointer
548  * 5: ring 1 head pointer (915-class)
549  * 6: ring 2 head pointer (915-class)
550  *
551  * The area from dword 0x10 to 0x3ff is available for driver usage.
552  */
553 #define READ_HWSP(dev_priv, reg)  (((volatile u32*)(dev_priv->hw_status_page))[reg])
554 #define I915_GEM_HWS_INDEX              0x10
555
556 /*
557  * 3D instructions used by the kernel
558  */
559 #define GFX_INSTR(opcode, flags) ((0x3 << 29) | ((opcode) << 24) | (flags))
560
561 #define GFX_OP_RASTER_RULES    ((0x3<<29)|(0x7<<24))
562 #define GFX_OP_SCISSOR         ((0x3<<29)|(0x1c<<24)|(0x10<<19))
563 #define   SC_UPDATE_SCISSOR       (0x1<<1)
564 #define   SC_ENABLE_MASK          (0x1<<0)
565 #define   SC_ENABLE               (0x1<<0)
566 #define GFX_OP_LOAD_INDIRECT   ((0x3<<29)|(0x1d<<24)|(0x7<<16))
567 #define GFX_OP_SCISSOR_INFO    ((0x3<<29)|(0x1d<<24)|(0x81<<16)|(0x1))
568 #define   SCI_YMIN_MASK      (0xffff<<16)
569 #define   SCI_XMIN_MASK      (0xffff<<0)
570 #define   SCI_YMAX_MASK      (0xffff<<16)
571 #define   SCI_XMAX_MASK      (0xffff<<0)
572 #define GFX_OP_SCISSOR_ENABLE    ((0x3<<29)|(0x1c<<24)|(0x10<<19))
573 #define GFX_OP_SCISSOR_RECT      ((0x3<<29)|(0x1d<<24)|(0x81<<16)|1)
574 #define GFX_OP_COLOR_FACTOR      ((0x3<<29)|(0x1d<<24)|(0x1<<16)|0x0)
575 #define GFX_OP_STIPPLE           ((0x3<<29)|(0x1d<<24)|(0x83<<16))
576 #define GFX_OP_MAP_INFO          ((0x3<<29)|(0x1d<<24)|0x4)
577 #define GFX_OP_DESTBUFFER_VARS   ((0x3<<29)|(0x1d<<24)|(0x85<<16)|0x0)
578 #define GFX_OP_DRAWRECT_INFO     ((0x3<<29)|(0x1d<<24)|(0x80<<16)|(0x3))
579 #define GFX_OP_DRAWRECT_INFO_I965  ((0x7900<<16)|0x2)
580 #define SRC_COPY_BLT_CMD                ((2<<29)|(0x43<<22)|4)
581 #define XY_SRC_COPY_BLT_CMD             ((2<<29)|(0x53<<22)|6)
582 #define XY_MONO_SRC_COPY_IMM_BLT        ((2<<29)|(0x71<<22)|5)
583 #define XY_SRC_COPY_BLT_WRITE_ALPHA     (1<<21)
584 #define XY_SRC_COPY_BLT_WRITE_RGB       (1<<20)
585 #define   BLT_DEPTH_8                   (0<<24)
586 #define   BLT_DEPTH_16_565              (1<<24)
587 #define   BLT_DEPTH_16_1555             (2<<24)
588 #define   BLT_DEPTH_32                  (3<<24)
589 #define   BLT_ROP_GXCOPY                (0xcc<<16)
590 #define XY_SRC_COPY_BLT_SRC_TILED       (1<<15) /* 965+ only */
591 #define XY_SRC_COPY_BLT_DST_TILED       (1<<11) /* 965+ only */
592 #define CMD_OP_DISPLAYBUFFER_INFO ((0x0<<29)|(0x14<<23)|2)
593 #define   ASYNC_FLIP                (1<<22)
594 #define   DISPLAY_PLANE_A           (0<<20)
595 #define   DISPLAY_PLANE_B           (1<<20)
596
597 /*
598  * Instruction and interrupt control regs
599  */
600
601 #define PRB0_TAIL       0x02030
602 #define PRB0_HEAD       0x02034
603 #define PRB0_START      0x02038
604 #define PRB0_CTL        0x0203c
605 #define   TAIL_ADDR             0x001FFFF8
606 #define   HEAD_WRAP_COUNT       0xFFE00000
607 #define   HEAD_WRAP_ONE         0x00200000
608 #define   HEAD_ADDR             0x001FFFFC
609 #define   RING_NR_PAGES         0x001FF000
610 #define   RING_REPORT_MASK      0x00000006
611 #define   RING_REPORT_64K       0x00000002
612 #define   RING_REPORT_128K      0x00000004
613 #define   RING_NO_REPORT        0x00000000
614 #define   RING_VALID_MASK       0x00000001
615 #define   RING_VALID            0x00000001
616 #define   RING_INVALID          0x00000000
617 #define PRB1_TAIL       0x02040 /* 915+ only */
618 #define PRB1_HEAD       0x02044 /* 915+ only */
619 #define PRB1_START      0x02048 /* 915+ only */
620 #define PRB1_CTL        0x0204c /* 915+ only */
621 #define HWS_PGA         0x02080
622 #define IPEIR           0x02088
623 #define NOPID           0x02094
624 #define HWSTAM          0x02098
625 #define SCPD0           0x0209c /* 915+ only */
626 #define IER             0x020a0
627 #define IIR             0x020a4
628 #define IMR             0x020a8
629 #define ISR             0x020ac
630 #define   I915_PIPE_CONTROL_NOTIFY_INTERRUPT            (1<<18)
631 #define   I915_DISPLAY_PORT_INTERRUPT                   (1<<17)
632 #define   I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT    (1<<15)
633 #define   I915_GMCH_THERMAL_SENSOR_EVENT_INTERRUPT      (1<<14)
634 #define   I915_HWB_OOM_INTERRUPT                        (1<<13)
635 #define   I915_SYNC_STATUS_INTERRUPT                    (1<<12)
636 #define   I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT   (1<<11)
637 #define   I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT   (1<<10)
638 #define   I915_OVERLAY_PLANE_FLIP_PENDING_INTERRUPT     (1<<9)
639 #define   I915_DISPLAY_PLANE_C_FLIP_PENDING_INTERRUPT   (1<<8)
640 #define   I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT          (1<<7)
641 #define   I915_DISPLAY_PIPE_A_EVENT_INTERRUPT           (1<<6)
642 #define   I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT          (1<<5)
643 #define   I915_DISPLAY_PIPE_B_EVENT_INTERRUPT           (1<<4)
644 #define   I915_DEBUG_INTERRUPT                          (1<<2)
645 #define   I915_USER_INTERRUPT                           (1<<1)
646 #define   I915_ASLE_INTERRUPT                           (1<<0)
647 #define EIR             0x020b0
648 #define EMR             0x020b4
649 #define ESR             0x020b8
650 #define INSTPM          0x020c0
651 #define FW_BLC          0x020d8
652 #define FW_BLC_SELF     0x020e0 /* 915+ only */
653 #define MI_ARB_STATE    0x020e4 /* 915+ only */
654 #define CACHE_MODE_0    0x02120 /* 915+ only */
655 #define   CM0_MASK_SHIFT          16
656 #define   CM0_IZ_OPT_DISABLE      (1<<6)
657 #define   CM0_ZR_OPT_DISABLE      (1<<5)
658 #define   CM0_DEPTH_EVICT_DISABLE (1<<4)
659 #define   CM0_COLOR_EVICT_DISABLE (1<<3)
660 #define   CM0_DEPTH_WRITE_DISABLE (1<<1)
661 #define   CM0_RC_OP_FLUSH_DISABLE (1<<0)
662 #define GFX_FLSH_CNTL   0x02170 /* 915+ only */
663
664 /*
665  * Framebuffer compression (915+ only)
666  */
667
668 #define FBC_CFB_BASE            0x03200 /* 4k page aligned */
669 #define FBC_LL_BASE             0x03204 /* 4k page aligned */
670 #define FBC_CONTROL             0x03208
671 #define   FBC_CTL_EN            (1<<31)
672 #define   FBC_CTL_PERIODIC      (1<<30)
673 #define   FBC_CTL_INTERVAL_SHIFT (16)
674 #define   FBC_CTL_UNCOMPRESSIBLE (1<<14)
675 #define   FBC_CTL_STRIDE_SHIFT  (5)
676 #define   FBC_CTL_FENCENO       (1<<0)
677 #define FBC_COMMAND             0x0320c
678 #define   FBC_CMD_COMPRESS      (1<<0)
679 #define FBC_STATUS              0x03210
680 #define   FBC_STAT_COMPRESSING  (1<<31)
681 #define   FBC_STAT_COMPRESSED   (1<<30)
682 #define   FBC_STAT_MODIFIED     (1<<29)
683 #define   FBC_STAT_CURRENT_LINE (1<<0)
684 #define FBC_CONTROL2            0x03214
685 #define   FBC_CTL_FENCE_DBL     (0<<4)
686 #define   FBC_CTL_IDLE_IMM      (0<<2)
687 #define   FBC_CTL_IDLE_FULL     (1<<2)
688 #define   FBC_CTL_IDLE_LINE     (2<<2)
689 #define   FBC_CTL_IDLE_DEBUG    (3<<2)
690 #define   FBC_CTL_CPU_FENCE     (1<<1)
691 #define   FBC_CTL_PLANEA        (0<<0)
692 #define   FBC_CTL_PLANEB        (1<<0)
693 #define FBC_FENCE_OFF           0x0321b
694
695 #define FBC_LL_SIZE             (1536)
696
697 /*
698  * GPIO regs
699  */
700
701 #define GPIOA                   0x5010
702 #define GPIOB                   0x5014
703 #define GPIOC                   0x5018
704 #define GPIOD                   0x501c
705 #define GPIOE                   0x5020
706 #define GPIOF                   0x5024
707 #define GPIOG                   0x5028
708 #define GPIOH                   0x502c
709 # define GPIO_CLOCK_DIR_MASK            (1 << 0)
710 # define GPIO_CLOCK_DIR_IN              (0 << 1)
711 # define GPIO_CLOCK_DIR_OUT             (1 << 1)
712 # define GPIO_CLOCK_VAL_MASK            (1 << 2)
713 # define GPIO_CLOCK_VAL_OUT             (1 << 3)
714 # define GPIO_CLOCK_VAL_IN              (1 << 4)
715 # define GPIO_CLOCK_PULLUP_DISABLE      (1 << 5)
716 # define GPIO_DATA_DIR_MASK             (1 << 8)
717 # define GPIO_DATA_DIR_IN               (0 << 9)
718 # define GPIO_DATA_DIR_OUT              (1 << 9)
719 # define GPIO_DATA_VAL_MASK             (1 << 10)
720 # define GPIO_DATA_VAL_OUT              (1 << 11)
721 # define GPIO_DATA_VAL_IN               (1 << 12)
722 # define GPIO_DATA_PULLUP_DISABLE       (1 << 13)
723
724 /*
725  * Clock control & power management
726  */
727
728 #define VGA0    0x6000
729 #define VGA1    0x6004
730 #define VGA_PD  0x6010
731 #define   VGA0_PD_P2_DIV_4      (1 << 7)
732 #define   VGA0_PD_P1_DIV_2      (1 << 5)
733 #define   VGA0_PD_P1_SHIFT      0
734 #define   VGA0_PD_P1_MASK       (0x1f << 0)
735 #define   VGA1_PD_P2_DIV_4      (1 << 15)
736 #define   VGA1_PD_P1_DIV_2      (1 << 13)
737 #define   VGA1_PD_P1_SHIFT      8
738 #define   VGA1_PD_P1_MASK       (0x1f << 8)
739 #define DPLL_A  0x06014
740 #define DPLL_B  0x06018
741 #define   DPLL_VCO_ENABLE               (1 << 31)
742 #define   DPLL_DVO_HIGH_SPEED           (1 << 30)
743 #define   DPLL_SYNCLOCK_ENABLE          (1 << 29)
744 #define   DPLL_VGA_MODE_DIS             (1 << 28)
745 #define   DPLLB_MODE_DAC_SERIAL         (1 << 26) /* i915 */
746 #define   DPLLB_MODE_LVDS               (2 << 26) /* i915 */
747 #define   DPLL_MODE_MASK                (3 << 26)
748 #define   DPLL_DAC_SERIAL_P2_CLOCK_DIV_10 (0 << 24) /* i915 */
749 #define   DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 (1 << 24) /* i915 */
750 #define   DPLLB_LVDS_P2_CLOCK_DIV_14    (0 << 24) /* i915 */
751 #define   DPLLB_LVDS_P2_CLOCK_DIV_7     (1 << 24) /* i915 */
752 #define   DPLL_P2_CLOCK_DIV_MASK        0x03000000 /* i915 */
753 #define   DPLL_FPA01_P1_POST_DIV_MASK   0x00ff0000 /* i915 */
754
755 #define I915_FIFO_UNDERRUN_STATUS               (1UL<<31)
756 #define I915_CRC_ERROR_ENABLE                   (1UL<<29)
757 #define I915_CRC_DONE_ENABLE                    (1UL<<28)
758 #define I915_GMBUS_EVENT_ENABLE                 (1UL<<27)
759 #define I915_VSYNC_INTERRUPT_ENABLE             (1UL<<25)
760 #define I915_DISPLAY_LINE_COMPARE_ENABLE        (1UL<<24)
761 #define I915_DPST_EVENT_ENABLE                  (1UL<<23)
762 #define I915_LEGACY_BLC_EVENT_ENABLE            (1UL<<22)
763 #define I915_ODD_FIELD_INTERRUPT_ENABLE         (1UL<<21)
764 #define I915_EVEN_FIELD_INTERRUPT_ENABLE        (1UL<<20)
765 #define I915_START_VBLANK_INTERRUPT_ENABLE      (1UL<<18)       /* 965 or later */
766 #define I915_VBLANK_INTERRUPT_ENABLE            (1UL<<17)
767 #define I915_OVERLAY_UPDATED_ENABLE             (1UL<<16)
768 #define I915_CRC_ERROR_INTERRUPT_STATUS         (1UL<<13)
769 #define I915_CRC_DONE_INTERRUPT_STATUS          (1UL<<12)
770 #define I915_GMBUS_INTERRUPT_STATUS             (1UL<<11)
771 #define I915_VSYNC_INTERRUPT_STATUS             (1UL<<9)
772 #define I915_DISPLAY_LINE_COMPARE_STATUS        (1UL<<8)
773 #define I915_DPST_EVENT_STATUS                  (1UL<<7)
774 #define I915_LEGACY_BLC_EVENT_STATUS            (1UL<<6)
775 #define I915_ODD_FIELD_INTERRUPT_STATUS         (1UL<<5)
776 #define I915_EVEN_FIELD_INTERRUPT_STATUS        (1UL<<4)
777 #define I915_START_VBLANK_INTERRUPT_STATUS      (1UL<<2)        /* 965 or later */
778 #define I915_VBLANK_INTERRUPT_STATUS            (1UL<<1)
779 #define I915_OVERLAY_UPDATED_STATUS             (1UL<<0)
780
781 #define SRX_INDEX               0x3c4
782 #define SRX_DATA                0x3c5
783 #define SR01                    1
784 #define SR01_SCREEN_OFF         (1<<5)
785
786 #define PPCR                    0x61204
787 #define PPCR_ON                 (1<<0)
788
789 #define DVOB                    0x61140
790 #define DVOB_ON                 (1<<31)
791 #define DVOC                    0x61160
792 #define DVOC_ON                 (1<<31)
793 #define LVDS                    0x61180
794 #define LVDS_ON                 (1<<31)
795
796 #define ADPA                    0x61100
797 #define ADPA_DPMS_MASK          (~(3<<10))
798 #define ADPA_DPMS_ON            (0<<10)
799 #define ADPA_DPMS_SUSPEND       (1<<10)
800 #define ADPA_DPMS_STANDBY       (2<<10)
801 #define ADPA_DPMS_OFF           (3<<10)
802
803 #define RING_TAIL               0x00
804 #define TAIL_ADDR               0x001FFFF8
805 #define RING_HEAD               0x04
806 #define HEAD_WRAP_COUNT         0xFFE00000
807 #define HEAD_WRAP_ONE           0x00200000
808 #define HEAD_ADDR               0x001FFFFC
809 #define RING_START              0x08
810 #define START_ADDR              0xFFFFF000
811 #define RING_LEN                0x0C
812 #define RING_NR_PAGES           0x001FF000
813 #define RING_REPORT_MASK        0x00000006
814 #define RING_REPORT_64K         0x00000002
815 #define RING_REPORT_128K        0x00000004
816 #define RING_NO_REPORT          0x00000000
817 #define RING_VALID_MASK         0x00000001
818 #define RING_VALID              0x00000001
819 #define RING_INVALID            0x00000000
820
821 /* Scratch pad debug 0 reg:
822  */
823 #define   DPLL_FPA01_P1_POST_DIV_MASK_I830      0x001f0000
824 /*
825  * The i830 generation, in LVDS mode, defines P1 as the bit number set within
826  * this field (only one bit may be set).
827  */
828 #define   DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS 0x003f0000
829 #define   DPLL_FPA01_P1_POST_DIV_SHIFT  16
830 /* i830, required in DVO non-gang */
831 #define   PLL_P2_DIVIDE_BY_4            (1 << 23)
832 #define   PLL_P1_DIVIDE_BY_TWO          (1 << 21) /* i830 */
833 #define   PLL_REF_INPUT_DREFCLK         (0 << 13)
834 #define   PLL_REF_INPUT_TVCLKINA        (1 << 13) /* i830 */
835 #define   PLL_REF_INPUT_TVCLKINBC       (2 << 13) /* SDVO TVCLKIN */
836 #define   PLLB_REF_INPUT_SPREADSPECTRUMIN (3 << 13)
837 #define   PLL_REF_INPUT_MASK            (3 << 13)
838 #define   PLL_LOAD_PULSE_PHASE_SHIFT            9
839 /*
840  * Parallel to Serial Load Pulse phase selection.
841  * Selects the phase for the 10X DPLL clock for the PCIe
842  * digital display port. The range is 4 to 13; 10 or more
843  * is just a flip delay. The default is 6
844  */
845 #define   PLL_LOAD_PULSE_PHASE_MASK             (0xf << PLL_LOAD_PULSE_PHASE_SHIFT)
846 #define   DISPLAY_RATE_SELECT_FPA1              (1 << 8)
847 /*
848  * SDVO multiplier for 945G/GM. Not used on 965.
849  */
850 #define   SDVO_MULTIPLIER_MASK                  0x000000ff
851 #define   SDVO_MULTIPLIER_SHIFT_HIRES           4
852 #define   SDVO_MULTIPLIER_SHIFT_VGA             0
853 #define DPLL_A_MD 0x0601c /* 965+ only */
854 /*
855  * UDI pixel divider, controlling how many pixels are stuffed into a packet.
856  *
857  * Value is pixels minus 1.  Must be set to 1 pixel for SDVO.
858  */
859 #define   DPLL_MD_UDI_DIVIDER_MASK              0x3f000000
860 #define   DPLL_MD_UDI_DIVIDER_SHIFT             24
861 /* UDI pixel divider for VGA, same as DPLL_MD_UDI_DIVIDER_MASK. */
862 #define   DPLL_MD_VGA_UDI_DIVIDER_MASK          0x003f0000
863 #define   DPLL_MD_VGA_UDI_DIVIDER_SHIFT         16
864 /*
865  * SDVO/UDI pixel multiplier.
866  *
867  * SDVO requires that the bus clock rate be between 1 and 2 Ghz, and the bus
868  * clock rate is 10 times the DPLL clock.  At low resolution/refresh rate
869  * modes, the bus rate would be below the limits, so SDVO allows for stuffing
870  * dummy bytes in the datastream at an increased clock rate, with both sides of
871  * the link knowing how many bytes are fill.
872  *
873  * So, for a mode with a dotclock of 65Mhz, we would want to double the clock
874  * rate to 130Mhz to get a bus rate of 1.30Ghz.  The DPLL clock rate would be
875  * set to 130Mhz, and the SDVO multiplier set to 2x in this register and
876  * through an SDVO command.
877  *
878  * This register field has values of multiplication factor minus 1, with
879  * a maximum multiplier of 5 for SDVO.
880  */
881 #define   DPLL_MD_UDI_MULTIPLIER_MASK           0x00003f00
882 #define   DPLL_MD_UDI_MULTIPLIER_SHIFT          8
883 /*
884  * SDVO/UDI pixel multiplier for VGA, same as DPLL_MD_UDI_MULTIPLIER_MASK.
885  * This best be set to the default value (3) or the CRT won't work. No,
886  * I don't entirely understand what this does...
887  */
888 #define   DPLL_MD_VGA_UDI_MULTIPLIER_MASK       0x0000003f
889 #define   DPLL_MD_VGA_UDI_MULTIPLIER_SHIFT      0
890 #define DPLL_B_MD 0x06020 /* 965+ only */
891 #define FPA0    0x06040
892 #define FPA1    0x06044
893 #define FPB0    0x06048
894 #define FPB1    0x0604c
895 #define   FP_N_DIV_MASK         0x003f0000
896 #define   FP_N_DIV_SHIFT                16
897 #define   FP_M1_DIV_MASK        0x00003f00
898 #define   FP_M1_DIV_SHIFT                8
899 #define   FP_M2_DIV_MASK        0x0000003f
900 #define   FP_M2_DIV_SHIFT                0
901 #define DPLL_TEST       0x606c
902 #define   DPLLB_TEST_SDVO_DIV_1         (0 << 22)
903 #define   DPLLB_TEST_SDVO_DIV_2         (1 << 22)
904 #define   DPLLB_TEST_SDVO_DIV_4         (2 << 22)
905 #define   DPLLB_TEST_SDVO_DIV_MASK      (3 << 22)
906 #define   DPLLB_TEST_N_BYPASS           (1 << 19)
907 #define   DPLLB_TEST_M_BYPASS           (1 << 18)
908 #define   DPLLB_INPUT_BUFFER_ENABLE     (1 << 16)
909 #define   DPLLA_TEST_N_BYPASS           (1 << 3)
910 #define   DPLLA_TEST_M_BYPASS           (1 << 2)
911 #define   DPLLA_INPUT_BUFFER_ENABLE     (1 << 0)
912 #define D_STATE         0x6104
913 #define CG_2D_DIS       0x6200
914 #define CG_3D_DIS       0x6204
915
916 /*
917  * Palette regs
918  */
919
920 #define PALETTE_A               0x0a000
921 #define PALETTE_B               0x0a800
922
923 /*
924  * Overlay regs
925  */
926
927 #define OVADD                   0x30000
928 #define DOVSTA                  0x30008
929 #define OC_BUF                  (0x3<<20)
930 #define OGAMC5                  0x30010
931 #define OGAMC4                  0x30014
932 #define OGAMC3                  0x30018
933 #define OGAMC2                  0x3001c
934 #define OGAMC1                  0x30020
935 #define OGAMC0                  0x30024
936
937 /*
938  * Display engine regs
939  */
940
941 /* Pipe A timing regs */
942 #define HTOTAL_A        0x60000
943 #define HBLANK_A        0x60004
944 #define HSYNC_A         0x60008
945 #define VTOTAL_A        0x6000c
946 #define VBLANK_A        0x60010
947 #define VSYNC_A         0x60014
948 #define PIPEASRC        0x6001c
949 #define BCLRPAT_A       0x60020
950
951 /* Pipe B timing regs */
952 #define HTOTAL_B        0x61000
953 #define HBLANK_B        0x61004
954 #define HSYNC_B         0x61008
955 #define VTOTAL_B        0x6100c
956 #define VBLANK_B        0x61010
957 #define VSYNC_B         0x61014
958 #define PIPEBSRC        0x6101c
959 #define BCLRPAT_B       0x61020
960
961 /* VGA port control */
962 #define ADPA                    0x61100
963 #define   ADPA_DAC_ENABLE       (1<<31)
964 #define   ADPA_DAC_DISABLE      0
965 #define   ADPA_PIPE_SELECT_MASK (1<<30)
966 #define   ADPA_PIPE_A_SELECT    0
967 #define   ADPA_PIPE_B_SELECT    (1<<30)
968 #define   ADPA_USE_VGA_HVPOLARITY (1<<15)
969 #define   ADPA_SETS_HVPOLARITY  0
970 #define   ADPA_VSYNC_CNTL_DISABLE (1<<11)
971 #define   ADPA_VSYNC_CNTL_ENABLE 0
972 #define   ADPA_HSYNC_CNTL_DISABLE (1<<10)
973 #define   ADPA_HSYNC_CNTL_ENABLE 0
974 #define   ADPA_VSYNC_ACTIVE_HIGH (1<<4)
975 #define   ADPA_VSYNC_ACTIVE_LOW 0
976 #define   ADPA_HSYNC_ACTIVE_HIGH (1<<3)
977 #define   ADPA_HSYNC_ACTIVE_LOW 0
978 #define   ADPA_DPMS_MASK        (~(3<<10))
979 #define   ADPA_DPMS_ON          (0<<10)
980 #define   ADPA_DPMS_SUSPEND     (1<<10)
981 #define   ADPA_DPMS_STANDBY     (2<<10)
982 #define   ADPA_DPMS_OFF         (3<<10)
983
984 /* Hotplug control (945+ only) */
985 #define PORT_HOTPLUG_EN         0x61110
986 #define   SDVOB_HOTPLUG_INT_EN                  (1 << 26)
987 #define   SDVOC_HOTPLUG_INT_EN                  (1 << 25)
988 #define   TV_HOTPLUG_INT_EN                     (1 << 18)
989 #define   CRT_HOTPLUG_INT_EN                    (1 << 9)
990 #define   CRT_HOTPLUG_FORCE_DETECT              (1 << 3)
991
992 #define PORT_HOTPLUG_STAT       0x61114
993 #define   CRT_HOTPLUG_INT_STATUS                (1 << 11)
994 #define   TV_HOTPLUG_INT_STATUS                 (1 << 10)
995 #define   CRT_HOTPLUG_MONITOR_MASK              (3 << 8)
996 #define   CRT_HOTPLUG_MONITOR_COLOR             (3 << 8)
997 #define   CRT_HOTPLUG_MONITOR_MONO              (2 << 8)
998 #define   CRT_HOTPLUG_MONITOR_NONE              (0 << 8)
999 #define   SDVOC_HOTPLUG_INT_STATUS              (1 << 7)
1000 #define   SDVOB_HOTPLUG_INT_STATUS              (1 << 6)
1001
1002 /* SDVO port control */
1003 #define SDVOB                   0x61140
1004 #define SDVOC                   0x61160
1005 #define   SDVO_ENABLE           (1 << 31)
1006 #define   SDVO_PIPE_B_SELECT    (1 << 30)
1007 #define   SDVO_STALL_SELECT     (1 << 29)
1008 #define   SDVO_INTERRUPT_ENABLE (1 << 26)
1009 /**
1010  * 915G/GM SDVO pixel multiplier.
1011  *
1012  * Programmed value is multiplier - 1, up to 5x.
1013  *
1014  * \sa DPLL_MD_UDI_MULTIPLIER_MASK
1015  */
1016 #define   SDVO_PORT_MULTIPLY_MASK       (7 << 23)
1017 #define   SDVO_PORT_MULTIPLY_SHIFT              23
1018 #define   SDVO_PHASE_SELECT_MASK        (15 << 19)
1019 #define   SDVO_PHASE_SELECT_DEFAULT     (6 << 19)
1020 #define   SDVO_CLOCK_OUTPUT_INVERT      (1 << 18)
1021 #define   SDVOC_GANG_MODE               (1 << 16)
1022 #define   SDVO_BORDER_ENABLE            (1 << 7)
1023 #define   SDVOB_PCIE_CONCURRENCY        (1 << 3)
1024 #define   SDVO_DETECTED                 (1 << 2)
1025 /* Bits to be preserved when writing */
1026 #define   SDVOB_PRESERVE_MASK ((1 << 17) | (1 << 16) | (1 << 14) | (1 << 26))
1027 #define   SDVOC_PRESERVE_MASK ((1 << 17) | (1 << 26))
1028
1029 /* DVO port control */
1030 #define DVOA                    0x61120
1031 #define DVOB                    0x61140
1032 #define DVOC                    0x61160
1033 #define   DVO_ENABLE                    (1 << 31)
1034 #define   DVO_PIPE_B_SELECT             (1 << 30)
1035 #define   DVO_PIPE_STALL_UNUSED         (0 << 28)
1036 #define   DVO_PIPE_STALL                (1 << 28)
1037 #define   DVO_PIPE_STALL_TV             (2 << 28)
1038 #define   DVO_PIPE_STALL_MASK           (3 << 28)
1039 #define   DVO_USE_VGA_SYNC              (1 << 15)
1040 #define   DVO_DATA_ORDER_I740           (0 << 14)
1041 #define   DVO_DATA_ORDER_FP             (1 << 14)
1042 #define   DVO_VSYNC_DISABLE             (1 << 11)
1043 #define   DVO_HSYNC_DISABLE             (1 << 10)
1044 #define   DVO_VSYNC_TRISTATE            (1 << 9)
1045 #define   DVO_HSYNC_TRISTATE            (1 << 8)
1046 #define   DVO_BORDER_ENABLE             (1 << 7)
1047 #define   DVO_DATA_ORDER_GBRG           (1 << 6)
1048 #define   DVO_DATA_ORDER_RGGB           (0 << 6)
1049 #define   DVO_DATA_ORDER_GBRG_ERRATA    (0 << 6)
1050 #define   DVO_DATA_ORDER_RGGB_ERRATA    (1 << 6)
1051 #define   DVO_VSYNC_ACTIVE_HIGH         (1 << 4)
1052 #define   DVO_HSYNC_ACTIVE_HIGH         (1 << 3)
1053 #define   DVO_BLANK_ACTIVE_HIGH         (1 << 2)
1054 #define   DVO_OUTPUT_CSTATE_PIXELS      (1 << 1)        /* SDG only */
1055 #define   DVO_OUTPUT_SOURCE_SIZE_PIXELS (1 << 0)        /* SDG only */
1056 #define   DVO_PRESERVE_MASK             (0x7<<24)
1057 #define DVOA_SRCDIM             0x61124
1058 #define DVOB_SRCDIM             0x61144
1059 #define DVOC_SRCDIM             0x61164
1060 #define   DVO_SRCDIM_HORIZONTAL_SHIFT   12
1061 #define   DVO_SRCDIM_VERTICAL_SHIFT     0
1062
1063 /* LVDS port control */
1064 #define LVDS                    0x61180
1065 /*
1066  * Enables the LVDS port.  This bit must be set before DPLLs are enabled, as
1067  * the DPLL semantics change when the LVDS is assigned to that pipe.
1068  */
1069 #define   LVDS_PORT_EN                  (1 << 31)
1070 /* Selects pipe B for LVDS data.  Must be set on pre-965. */
1071 #define   LVDS_PIPEB_SELECT             (1 << 30)
1072 /*
1073  * Enables the A0-A2 data pairs and CLKA, containing 18 bits of color data per
1074  * pixel.
1075  */
1076 #define   LVDS_A0A2_CLKA_POWER_MASK     (3 << 8)
1077 #define   LVDS_A0A2_CLKA_POWER_DOWN     (0 << 8)
1078 #define   LVDS_A0A2_CLKA_POWER_UP       (3 << 8)
1079 /*
1080  * Controls the A3 data pair, which contains the additional LSBs for 24 bit
1081  * mode.  Only enabled if LVDS_A0A2_CLKA_POWER_UP also indicates it should be
1082  * on.
1083  */
1084 #define   LVDS_A3_POWER_MASK            (3 << 6)
1085 #define   LVDS_A3_POWER_DOWN            (0 << 6)
1086 #define   LVDS_A3_POWER_UP              (3 << 6)
1087 /*
1088  * Controls the CLKB pair.  This should only be set when LVDS_B0B3_POWER_UP
1089  * is set.
1090  */
1091 #define   LVDS_CLKB_POWER_MASK          (3 << 4)
1092 #define   LVDS_CLKB_POWER_DOWN          (0 << 4)
1093 #define   LVDS_CLKB_POWER_UP            (3 << 4)
1094 /*
1095  * Controls the B0-B3 data pairs.  This must be set to match the DPLL p2
1096  * setting for whether we are in dual-channel mode.  The B3 pair will
1097  * additionally only be powered up when LVDS_A3_POWER_UP is set.
1098  */
1099 #define   LVDS_B0B3_POWER_MASK          (3 << 2)
1100 #define   LVDS_B0B3_POWER_DOWN          (0 << 2)
1101 #define   LVDS_B0B3_POWER_UP            (3 << 2)
1102
1103 /* Panel power sequencing */
1104 #define PP_STATUS       0x61200
1105 #define   PP_ON         (1 << 31)
1106 /*
1107  * Indicates that all dependencies of the panel are on:
1108  *
1109  * - PLL enabled
1110  * - pipe enabled
1111  * - LVDS/DVOB/DVOC on
1112  */
1113 #define   PP_READY              (1 << 30)
1114 #define   PP_SEQUENCE_NONE      (0 << 28)
1115 #define   PP_SEQUENCE_ON        (1 << 28)
1116 #define   PP_SEQUENCE_OFF       (2 << 28)
1117 #define   PP_SEQUENCE_MASK      0x30000000
1118 #define PP_CONTROL      0x61204
1119 #define   POWER_TARGET_ON       (1 << 0)
1120 #define PP_ON_DELAYS    0x61208
1121 #define PP_OFF_DELAYS   0x6120c
1122 #define PP_DIVISOR      0x61210
1123
1124 /* Panel fitting */
1125 #define PFIT_CONTROL    0x61230
1126 #define   PFIT_ENABLE           (1 << 31)
1127 #define   PFIT_PIPE_MASK        (3 << 29)
1128 #define   PFIT_PIPE_SHIFT       29
1129 #define   VERT_INTERP_DISABLE   (0 << 10)
1130 #define   VERT_INTERP_BILINEAR  (1 << 10)
1131 #define   VERT_INTERP_MASK      (3 << 10)
1132 #define   VERT_AUTO_SCALE       (1 << 9)
1133 #define   HORIZ_INTERP_DISABLE  (0 << 6)
1134 #define   HORIZ_INTERP_BILINEAR (1 << 6)
1135 #define   HORIZ_INTERP_MASK     (3 << 6)
1136 #define   HORIZ_AUTO_SCALE      (1 << 5)
1137 #define   PANEL_8TO6_DITHER_ENABLE (1 << 3)
1138 #define PFIT_PGM_RATIOS 0x61234
1139 #define   PFIT_VERT_SCALE_MASK                  0xfff00000
1140 #define   PFIT_HORIZ_SCALE_MASK                 0x0000fff0
1141 #define PFIT_AUTO_RATIOS 0x61238
1142
1143 /* Backlight control */
1144 #define BLC_PWM_CTL             0x61254
1145 #define   BACKLIGHT_MODULATION_FREQ_SHIFT               (17)
1146 #define BLC_PWM_CTL2            0x61250 /* 965+ only */
1147 /*
1148  * This is the most significant 15 bits of the number of backlight cycles in a
1149  * complete cycle of the modulated backlight control.
1150  *
1151  * The actual value is this field multiplied by two.
1152  */
1153 #define   BACKLIGHT_MODULATION_FREQ_MASK                (0x7fff << 17)
1154 #define   BLM_LEGACY_MODE                               (1 << 16)
1155 /*
1156  * This is the number of cycles out of the backlight modulation cycle for which
1157  * the backlight is on.
1158  *
1159  * This field must be no greater than the number of cycles in the complete
1160  * backlight modulation cycle.
1161  */
1162 #define   BACKLIGHT_DUTY_CYCLE_SHIFT            (0)
1163 #define   BACKLIGHT_DUTY_CYCLE_MASK             (0xffff)
1164
1165 /* TV port control */
1166 #define TV_CTL                  0x68000
1167 /** Enables the TV encoder */
1168 # define TV_ENC_ENABLE                  (1 << 31)
1169 /** Sources the TV encoder input from pipe B instead of A. */
1170 # define TV_ENC_PIPEB_SELECT            (1 << 30)
1171 /** Outputs composite video (DAC A only) */
1172 # define TV_ENC_OUTPUT_COMPOSITE        (0 << 28)
1173 /** Outputs SVideo video (DAC B/C) */
1174 # define TV_ENC_OUTPUT_SVIDEO           (1 << 28)
1175 /** Outputs Component video (DAC A/B/C) */
1176 # define TV_ENC_OUTPUT_COMPONENT        (2 << 28)
1177 /** Outputs Composite and SVideo (DAC A/B/C) */
1178 # define TV_ENC_OUTPUT_SVIDEO_COMPOSITE (3 << 28)
1179 # define TV_TRILEVEL_SYNC               (1 << 21)
1180 /** Enables slow sync generation (945GM only) */
1181 # define TV_SLOW_SYNC                   (1 << 20)
1182 /** Selects 4x oversampling for 480i and 576p */
1183 # define TV_OVERSAMPLE_4X               (0 << 18)
1184 /** Selects 2x oversampling for 720p and 1080i */
1185 # define TV_OVERSAMPLE_2X               (1 << 18)
1186 /** Selects no oversampling for 1080p */
1187 # define TV_OVERSAMPLE_NONE             (2 << 18)
1188 /** Selects 8x oversampling */
1189 # define TV_OVERSAMPLE_8X               (3 << 18)
1190 /** Selects progressive mode rather than interlaced */
1191 # define TV_PROGRESSIVE                 (1 << 17)
1192 /** Sets the colorburst to PAL mode.  Required for non-M PAL modes. */
1193 # define TV_PAL_BURST                   (1 << 16)
1194 /** Field for setting delay of Y compared to C */
1195 # define TV_YC_SKEW_MASK                (7 << 12)
1196 /** Enables a fix for 480p/576p standard definition modes on the 915GM only */
1197 # define TV_ENC_SDP_FIX                 (1 << 11)
1198 /**
1199  * Enables a fix for the 915GM only.
1200  *
1201  * Not sure what it does.
1202  */
1203 # define TV_ENC_C0_FIX                  (1 << 10)
1204 /** Bits that must be preserved by software */
1205 # define TV_CTL_SAVE                    ((3 << 8) | (3 << 6))
1206 # define TV_FUSE_STATE_MASK             (3 << 4)
1207 /** Read-only state that reports all features enabled */
1208 # define TV_FUSE_STATE_ENABLED          (0 << 4)
1209 /** Read-only state that reports that Macrovision is disabled in hardware*/
1210 # define TV_FUSE_STATE_NO_MACROVISION   (1 << 4)
1211 /** Read-only state that reports that TV-out is disabled in hardware. */
1212 # define TV_FUSE_STATE_DISABLED         (2 << 4)
1213 /** Normal operation */
1214 # define TV_TEST_MODE_NORMAL            (0 << 0)
1215 /** Encoder test pattern 1 - combo pattern */
1216 # define TV_TEST_MODE_PATTERN_1         (1 << 0)
1217 /** Encoder test pattern 2 - full screen vertical 75% color bars */
1218 # define TV_TEST_MODE_PATTERN_2         (2 << 0)
1219 /** Encoder test pattern 3 - full screen horizontal 75% color bars */
1220 # define TV_TEST_MODE_PATTERN_3         (3 << 0)
1221 /** Encoder test pattern 4 - random noise */
1222 # define TV_TEST_MODE_PATTERN_4         (4 << 0)
1223 /** Encoder test pattern 5 - linear color ramps */
1224 # define TV_TEST_MODE_PATTERN_5         (5 << 0)
1225 /**
1226  * This test mode forces the DACs to 50% of full output.
1227  *
1228  * This is used for load detection in combination with TVDAC_SENSE_MASK
1229  */
1230 # define TV_TEST_MODE_MONITOR_DETECT    (7 << 0)
1231 # define TV_TEST_MODE_MASK              (7 << 0)
1232
1233 #define TV_DAC                  0x68004
1234 /**
1235  * Reports that DAC state change logic has reported change (RO).
1236  *
1237  * This gets cleared when TV_DAC_STATE_EN is cleared
1238 */
1239 # define TVDAC_STATE_CHG                (1 << 31)
1240 # define TVDAC_SENSE_MASK               (7 << 28)
1241 /** Reports that DAC A voltage is above the detect threshold */
1242 # define TVDAC_A_SENSE                  (1 << 30)
1243 /** Reports that DAC B voltage is above the detect threshold */
1244 # define TVDAC_B_SENSE                  (1 << 29)
1245 /** Reports that DAC C voltage is above the detect threshold */
1246 # define TVDAC_C_SENSE                  (1 << 28)
1247 /**
1248  * Enables DAC state detection logic, for load-based TV detection.
1249  *
1250  * The PLL of the chosen pipe (in TV_CTL) must be running, and the encoder set
1251  * to off, for load detection to work.
1252  */
1253 # define TVDAC_STATE_CHG_EN             (1 << 27)
1254 /** Sets the DAC A sense value to high */
1255 # define TVDAC_A_SENSE_CTL              (1 << 26)
1256 /** Sets the DAC B sense value to high */
1257 # define TVDAC_B_SENSE_CTL              (1 << 25)
1258 /** Sets the DAC C sense value to high */
1259 # define TVDAC_C_SENSE_CTL              (1 << 24)
1260 /** Overrides the ENC_ENABLE and DAC voltage levels */
1261 # define DAC_CTL_OVERRIDE               (1 << 7)
1262 /** Sets the slew rate.  Must be preserved in software */
1263 # define ENC_TVDAC_SLEW_FAST            (1 << 6)
1264 # define DAC_A_1_3_V                    (0 << 4)
1265 # define DAC_A_1_1_V                    (1 << 4)
1266 # define DAC_A_0_7_V                    (2 << 4)
1267 # define DAC_A_OFF                      (3 << 4)
1268 # define DAC_B_1_3_V                    (0 << 2)
1269 # define DAC_B_1_1_V                    (1 << 2)
1270 # define DAC_B_0_7_V                    (2 << 2)
1271 # define DAC_B_OFF                      (3 << 2)
1272 # define DAC_C_1_3_V                    (0 << 0)
1273 # define DAC_C_1_1_V                    (1 << 0)
1274 # define DAC_C_0_7_V                    (2 << 0)
1275 # define DAC_C_OFF                      (3 << 0)
1276
1277 /**
1278  * CSC coefficients are stored in a floating point format with 9 bits of
1279  * mantissa and 2 or 3 bits of exponent.  The exponent is represented as 2**-n,
1280  * where 2-bit exponents are unsigned n, and 3-bit exponents are signed n with
1281  * -1 (0x3) being the only legal negative value.
1282  */
1283 #define TV_CSC_Y                0x68010
1284 # define TV_RY_MASK                     0x07ff0000
1285 # define TV_RY_SHIFT                    16
1286 # define TV_GY_MASK                     0x00000fff
1287 # define TV_GY_SHIFT                    0
1288
1289 #define TV_CSC_Y2               0x68014
1290 # define TV_BY_MASK                     0x07ff0000
1291 # define TV_BY_SHIFT                    16
1292 /**
1293  * Y attenuation for component video.
1294  *
1295  * Stored in 1.9 fixed point.
1296  */
1297 # define TV_AY_MASK                     0x000003ff
1298 # define TV_AY_SHIFT                    0
1299
1300 #define TV_CSC_U                0x68018
1301 # define TV_RU_MASK                     0x07ff0000
1302 # define TV_RU_SHIFT                    16
1303 # define TV_GU_MASK                     0x000007ff
1304 # define TV_GU_SHIFT                    0
1305
1306 #define TV_CSC_U2               0x6801c
1307 # define TV_BU_MASK                     0x07ff0000
1308 # define TV_BU_SHIFT                    16
1309 /**
1310  * U attenuation for component video.
1311  *
1312  * Stored in 1.9 fixed point.
1313  */
1314 # define TV_AU_MASK                     0x000003ff
1315 # define TV_AU_SHIFT                    0
1316
1317 #define TV_CSC_V                0x68020
1318 # define TV_RV_MASK                     0x0fff0000
1319 # define TV_RV_SHIFT                    16
1320 # define TV_GV_MASK                     0x000007ff
1321 # define TV_GV_SHIFT                    0
1322
1323 #define TV_CSC_V2               0x68024
1324 # define TV_BV_MASK                     0x07ff0000
1325 # define TV_BV_SHIFT                    16
1326 /**
1327  * V attenuation for component video.
1328  *
1329  * Stored in 1.9 fixed point.
1330  */
1331 # define TV_AV_MASK                     0x000007ff
1332 # define TV_AV_SHIFT                    0
1333
1334 #define TV_CLR_KNOBS            0x68028
1335 /** 2s-complement brightness adjustment */
1336 # define TV_BRIGHTNESS_MASK             0xff000000
1337 # define TV_BRIGHTNESS_SHIFT            24
1338 /** Contrast adjustment, as a 2.6 unsigned floating point number */
1339 # define TV_CONTRAST_MASK               0x00ff0000
1340 # define TV_CONTRAST_SHIFT              16
1341 /** Saturation adjustment, as a 2.6 unsigned floating point number */
1342 # define TV_SATURATION_MASK             0x0000ff00
1343 # define TV_SATURATION_SHIFT            8
1344 /** Hue adjustment, as an integer phase angle in degrees */
1345 # define TV_HUE_MASK                    0x000000ff
1346 # define TV_HUE_SHIFT                   0
1347
1348 #define TV_CLR_LEVEL            0x6802c
1349 /** Controls the DAC level for black */
1350 # define TV_BLACK_LEVEL_MASK            0x01ff0000
1351 # define TV_BLACK_LEVEL_SHIFT           16
1352 /** Controls the DAC level for blanking */
1353 # define TV_BLANK_LEVEL_MASK            0x000001ff
1354 # define TV_BLANK_LEVEL_SHIFT           0
1355
1356 #define TV_H_CTL_1              0x68030
1357 /** Number of pixels in the hsync. */
1358 # define TV_HSYNC_END_MASK              0x1fff0000
1359 # define TV_HSYNC_END_SHIFT             16
1360 /** Total number of pixels minus one in the line (display and blanking). */
1361 # define TV_HTOTAL_MASK                 0x00001fff
1362 # define TV_HTOTAL_SHIFT                0
1363
1364 #define TV_H_CTL_2              0x68034
1365 /** Enables the colorburst (needed for non-component color) */
1366 # define TV_BURST_ENA                   (1 << 31)
1367 /** Offset of the colorburst from the start of hsync, in pixels minus one. */
1368 # define TV_HBURST_START_SHIFT          16
1369 # define TV_HBURST_START_MASK           0x1fff0000
1370 /** Length of the colorburst */
1371 # define TV_HBURST_LEN_SHIFT            0
1372 # define TV_HBURST_LEN_MASK             0x0001fff
1373
1374 #define TV_H_CTL_3              0x68038
1375 /** End of hblank, measured in pixels minus one from start of hsync */
1376 # define TV_HBLANK_END_SHIFT            16
1377 # define TV_HBLANK_END_MASK             0x1fff0000
1378 /** Start of hblank, measured in pixels minus one from start of hsync */
1379 # define TV_HBLANK_START_SHIFT          0
1380 # define TV_HBLANK_START_MASK           0x0001fff
1381
1382 #define TV_V_CTL_1              0x6803c
1383 /** XXX */
1384 # define TV_NBR_END_SHIFT               16
1385 # define TV_NBR_END_MASK                0x07ff0000
1386 /** XXX */
1387 # define TV_VI_END_F1_SHIFT             8
1388 # define TV_VI_END_F1_MASK              0x00003f00
1389 /** XXX */
1390 # define TV_VI_END_F2_SHIFT             0
1391 # define TV_VI_END_F2_MASK              0x0000003f
1392
1393 #define TV_V_CTL_2              0x68040
1394 /** Length of vsync, in half lines */
1395 # define TV_VSYNC_LEN_MASK              0x07ff0000
1396 # define TV_VSYNC_LEN_SHIFT             16
1397 /** Offset of the start of vsync in field 1, measured in one less than the
1398  * number of half lines.
1399  */
1400 # define TV_VSYNC_START_F1_MASK         0x00007f00
1401 # define TV_VSYNC_START_F1_SHIFT        8
1402 /**
1403  * Offset of the start of vsync in field 2, measured in one less than the
1404  * number of half lines.
1405  */
1406 # define TV_VSYNC_START_F2_MASK         0x0000007f
1407 # define TV_VSYNC_START_F2_SHIFT        0
1408
1409 #define TV_V_CTL_3              0x68044
1410 /** Enables generation of the equalization signal */
1411 # define TV_EQUAL_ENA                   (1 << 31)
1412 /** Length of vsync, in half lines */
1413 # define TV_VEQ_LEN_MASK                0x007f0000
1414 # define TV_VEQ_LEN_SHIFT               16
1415 /** Offset of the start of equalization in field 1, measured in one less than
1416  * the number of half lines.
1417  */
1418 # define TV_VEQ_START_F1_MASK           0x0007f00
1419 # define TV_VEQ_START_F1_SHIFT          8
1420 /**
1421  * Offset of the start of equalization in field 2, measured in one less than
1422  * the number of half lines.
1423  */
1424 # define TV_VEQ_START_F2_MASK           0x000007f
1425 # define TV_VEQ_START_F2_SHIFT          0
1426
1427 #define TV_V_CTL_4              0x68048
1428 /**
1429  * Offset to start of vertical colorburst, measured in one less than the
1430  * number of lines from vertical start.
1431  */
1432 # define TV_VBURST_START_F1_MASK        0x003f0000
1433 # define TV_VBURST_START_F1_SHIFT       16
1434 /**
1435  * Offset to the end of vertical colorburst, measured in one less than the
1436  * number of lines from the start of NBR.
1437  */
1438 # define TV_VBURST_END_F1_MASK          0x000000ff
1439 # define TV_VBURST_END_F1_SHIFT         0
1440
1441 #define TV_V_CTL_5              0x6804c
1442 /**
1443  * Offset to start of vertical colorburst, measured in one less than the
1444  * number of lines from vertical start.
1445  */
1446 # define TV_VBURST_START_F2_MASK        0x003f0000
1447 # define TV_VBURST_START_F2_SHIFT       16
1448 /**
1449  * Offset to the end of vertical colorburst, measured in one less than the
1450  * number of lines from the start of NBR.
1451  */
1452 # define TV_VBURST_END_F2_MASK          0x000000ff
1453 # define TV_VBURST_END_F2_SHIFT         0
1454
1455 #define TV_V_CTL_6              0x68050
1456 /**
1457  * Offset to start of vertical colorburst, measured in one less than the
1458  * number of lines from vertical start.
1459  */
1460 # define TV_VBURST_START_F3_MASK        0x003f0000
1461 # define TV_VBURST_START_F3_SHIFT       16
1462 /**
1463  * Offset to the end of vertical colorburst, measured in one less than the
1464  * number of lines from the start of NBR.
1465  */
1466 # define TV_VBURST_END_F3_MASK          0x000000ff
1467 # define TV_VBURST_END_F3_SHIFT         0
1468
1469 #define TV_V_CTL_7              0x68054
1470 /**
1471  * Offset to start of vertical colorburst, measured in one less than the
1472  * number of lines from vertical start.
1473  */
1474 # define TV_VBURST_START_F4_MASK        0x003f0000
1475 # define TV_VBURST_START_F4_SHIFT       16
1476 /**
1477  * Offset to the end of vertical colorburst, measured in one less than the
1478  * number of lines from the start of NBR.
1479  */
1480 # define TV_VBURST_END_F4_MASK          0x000000ff
1481 # define TV_VBURST_END_F4_SHIFT         0
1482
1483 #define TV_SC_CTL_1             0x68060
1484 /** Turns on the first subcarrier phase generation DDA */
1485 # define TV_SC_DDA1_EN                  (1 << 31)
1486 /** Turns on the first subcarrier phase generation DDA */
1487 # define TV_SC_DDA2_EN                  (1 << 30)
1488 /** Turns on the first subcarrier phase generation DDA */
1489 # define TV_SC_DDA3_EN                  (1 << 29)
1490 /** Sets the subcarrier DDA to reset frequency every other field */
1491 # define TV_SC_RESET_EVERY_2            (0 << 24)
1492 /** Sets the subcarrier DDA to reset frequency every fourth field */
1493 # define TV_SC_RESET_EVERY_4            (1 << 24)
1494 /** Sets the subcarrier DDA to reset frequency every eighth field */
1495 # define TV_SC_RESET_EVERY_8            (2 << 24)
1496 /** Sets the subcarrier DDA to never reset the frequency */
1497 # define TV_SC_RESET_NEVER              (3 << 24)
1498 /** Sets the peak amplitude of the colorburst.*/
1499 # define TV_BURST_LEVEL_MASK            0x00ff0000
1500 # define TV_BURST_LEVEL_SHIFT           16
1501 /** Sets the increment of the first subcarrier phase generation DDA */
1502 # define TV_SCDDA1_INC_MASK             0x00000fff
1503 # define TV_SCDDA1_INC_SHIFT            0
1504
1505 #define TV_SC_CTL_2             0x68064
1506 /** Sets the rollover for the second subcarrier phase generation DDA */
1507 # define TV_SCDDA2_SIZE_MASK            0x7fff0000
1508 # define TV_SCDDA2_SIZE_SHIFT           16
1509 /** Sets the increent of the second subcarrier phase generation DDA */
1510 # define TV_SCDDA2_INC_MASK             0x00007fff
1511 # define TV_SCDDA2_INC_SHIFT            0
1512
1513 #define TV_SC_CTL_3             0x68068
1514 /** Sets the rollover for the third subcarrier phase generation DDA */
1515 # define TV_SCDDA3_SIZE_MASK            0x7fff0000
1516 # define TV_SCDDA3_SIZE_SHIFT           16
1517 /** Sets the increent of the third subcarrier phase generation DDA */
1518 # define TV_SCDDA3_INC_MASK             0x00007fff
1519 # define TV_SCDDA3_INC_SHIFT            0
1520
1521 #define TV_WIN_POS              0x68070
1522 /** X coordinate of the display from the start of horizontal active */
1523 # define TV_XPOS_MASK                   0x1fff0000
1524 # define TV_XPOS_SHIFT                  16
1525 /** Y coordinate of the display from the start of vertical active (NBR) */
1526 # define TV_YPOS_MASK                   0x00000fff
1527 # define TV_YPOS_SHIFT                  0
1528
1529 #define TV_WIN_SIZE             0x68074
1530 /** Horizontal size of the display window, measured in pixels*/
1531 # define TV_XSIZE_MASK                  0x1fff0000
1532 # define TV_XSIZE_SHIFT                 16
1533 /**
1534  * Vertical size of the display window, measured in pixels.
1535  *
1536  * Must be even for interlaced modes.
1537  */
1538 # define TV_YSIZE_MASK                  0x00000fff
1539 # define TV_YSIZE_SHIFT                 0
1540
1541 #define TV_FILTER_CTL_1         0x68080
1542 /**
1543  * Enables automatic scaling calculation.
1544  *
1545  * If set, the rest of the registers are ignored, and the calculated values can
1546  * be read back from the register.
1547  */
1548 # define TV_AUTO_SCALE                  (1 << 31)
1549 /**
1550  * Disables the vertical filter.
1551  *
1552  * This is required on modes more than 1024 pixels wide */
1553 # define TV_V_FILTER_BYPASS             (1 << 29)
1554 /** Enables adaptive vertical filtering */
1555 # define TV_VADAPT                      (1 << 28)
1556 # define TV_VADAPT_MODE_MASK            (3 << 26)
1557 /** Selects the least adaptive vertical filtering mode */
1558 # define TV_VADAPT_MODE_LEAST           (0 << 26)
1559 /** Selects the moderately adaptive vertical filtering mode */
1560 # define TV_VADAPT_MODE_MODERATE        (1 << 26)
1561 /** Selects the most adaptive vertical filtering mode */
1562 # define TV_VADAPT_MODE_MOST            (3 << 26)
1563 /**
1564  * Sets the horizontal scaling factor.
1565  *
1566  * This should be the fractional part of the horizontal scaling factor divided
1567  * by the oversampling rate.  TV_HSCALE should be less than 1, and set to:
1568  *
1569  * (src width - 1) / ((oversample * dest width) - 1)
1570  */
1571 # define TV_HSCALE_FRAC_MASK            0x00003fff
1572 # define TV_HSCALE_FRAC_SHIFT           0
1573
1574 #define TV_FILTER_CTL_2         0x68084
1575 /**
1576  * Sets the integer part of the 3.15 fixed-point vertical scaling factor.
1577  *
1578  * TV_VSCALE should be (src height - 1) / ((interlace * dest height) - 1)
1579  */
1580 # define TV_VSCALE_INT_MASK             0x00038000
1581 # define TV_VSCALE_INT_SHIFT            15
1582 /**
1583  * Sets the fractional part of the 3.15 fixed-point vertical scaling factor.
1584  *
1585  * \sa TV_VSCALE_INT_MASK
1586  */
1587 # define TV_VSCALE_FRAC_MASK            0x00007fff
1588 # define TV_VSCALE_FRAC_SHIFT           0
1589
1590 #define TV_FILTER_CTL_3         0x68088
1591 /**
1592  * Sets the integer part of the 3.15 fixed-point vertical scaling factor.
1593  *
1594  * TV_VSCALE should be (src height - 1) / (1/4 * (dest height - 1))
1595  *
1596  * For progressive modes, TV_VSCALE_IP_INT should be set to zeroes.
1597  */
1598 # define TV_VSCALE_IP_INT_MASK          0x00038000
1599 # define TV_VSCALE_IP_INT_SHIFT         15
1600 /**
1601  * Sets the fractional part of the 3.15 fixed-point vertical scaling factor.
1602  *
1603  * For progressive modes, TV_VSCALE_IP_INT should be set to zeroes.
1604  *
1605  * \sa TV_VSCALE_IP_INT_MASK
1606  */
1607 # define TV_VSCALE_IP_FRAC_MASK         0x00007fff
1608 # define TV_VSCALE_IP_FRAC_SHIFT                0
1609
1610 #define TV_CC_CONTROL           0x68090
1611 # define TV_CC_ENABLE                   (1 << 31)
1612 /**
1613  * Specifies which field to send the CC data in.
1614  *
1615  * CC data is usually sent in field 0.
1616  */
1617 # define TV_CC_FID_MASK                 (1 << 27)
1618 # define TV_CC_FID_SHIFT                27
1619 /** Sets the horizontal position of the CC data.  Usually 135. */
1620 # define TV_CC_HOFF_MASK                0x03ff0000
1621 # define TV_CC_HOFF_SHIFT               16
1622 /** Sets the vertical position of the CC data.  Usually 21 */
1623 # define TV_CC_LINE_MASK                0x0000003f
1624 # define TV_CC_LINE_SHIFT               0
1625
1626 #define TV_CC_DATA              0x68094
1627 # define TV_CC_RDY                      (1 << 31)
1628 /** Second word of CC data to be transmitted. */
1629 # define TV_CC_DATA_2_MASK              0x007f0000
1630 # define TV_CC_DATA_2_SHIFT             16
1631 /** First word of CC data to be transmitted. */
1632 # define TV_CC_DATA_1_MASK              0x0000007f
1633 # define TV_CC_DATA_1_SHIFT             0
1634
1635 #define TV_H_LUMA_0             0x68100
1636 #define TV_H_LUMA_59            0x681ec
1637 #define TV_H_CHROMA_0           0x68200
1638 #define TV_H_CHROMA_59          0x682ec
1639 #define TV_V_LUMA_0             0x68300
1640 #define TV_V_LUMA_42            0x683a8
1641 #define TV_V_CHROMA_0           0x68400
1642 #define TV_V_CHROMA_42          0x684a8
1643
1644 /* Display & cursor control */
1645
1646 /* Pipe A */
1647 #define PIPEADSL                0x70000
1648 #define PIPEACONF                0x70008
1649 #define   PIPEACONF_ENABLE      (1<<31)
1650 #define   PIPEACONF_DISABLE     0
1651 #define   PIPEACONF_DOUBLE_WIDE (1<<30)
1652 #define   I965_PIPECONF_ACTIVE  (1<<30)
1653 #define   PIPEACONF_SINGLE_WIDE 0
1654 #define   PIPEACONF_PIPE_UNLOCKED 0
1655 #define   PIPEACONF_PIPE_LOCKED (1<<25)
1656 #define   PIPEACONF_PALETTE     0
1657 #define   PIPEACONF_GAMMA               (1<<24)
1658 #define   PIPECONF_FORCE_BORDER (1<<25)
1659 #define   PIPECONF_PROGRESSIVE  (0 << 21)
1660 #define   PIPECONF_INTERLACE_W_FIELD_INDICATION (6 << 21)
1661 #define   PIPECONF_INTERLACE_FIELD_0_ONLY               (7 << 21)
1662 #define PIPEASTAT               0x70024
1663 #define   PIPE_FIFO_UNDERRUN_STATUS             (1UL<<31)
1664 #define   PIPE_CRC_ERROR_ENABLE                 (1UL<<29)
1665 #define   PIPE_CRC_DONE_ENABLE                  (1UL<<28)
1666 #define   PIPE_GMBUS_EVENT_ENABLE               (1UL<<27)
1667 #define   PIPE_HOTPLUG_INTERRUPT_ENABLE         (1UL<<26)
1668 #define   PIPE_VSYNC_INTERRUPT_ENABLE           (1UL<<25)
1669 #define   PIPE_DISPLAY_LINE_COMPARE_ENABLE      (1UL<<24)
1670 #define   PIPE_DPST_EVENT_ENABLE                (1UL<<23)
1671 #define   PIPE_LEGACY_BLC_EVENT_ENABLE          (1UL<<22)
1672 #define   PIPE_ODD_FIELD_INTERRUPT_ENABLE       (1UL<<21)
1673 #define   PIPE_EVEN_FIELD_INTERRUPT_ENABLE      (1UL<<20)
1674 #define   PIPE_HOTPLUG_TV_INTERRUPT_ENABLE      (1UL<<18) /* pre-965 */
1675 #define   PIPE_START_VBLANK_INTERRUPT_ENABLE    (1UL<<18) /* 965 or later */
1676 #define   PIPE_VBLANK_INTERRUPT_ENABLE          (1UL<<17)
1677 #define   PIPE_OVERLAY_UPDATED_ENABLE           (1UL<<16)
1678 #define   PIPE_CRC_ERROR_INTERRUPT_STATUS       (1UL<<13)
1679 #define   PIPE_CRC_DONE_INTERRUPT_STATUS        (1UL<<12)
1680 #define   PIPE_GMBUS_INTERRUPT_STATUS           (1UL<<11)
1681 #define   PIPE_HOTPLUG_INTERRUPT_STATUS         (1UL<<10)
1682 #define   PIPE_VSYNC_INTERRUPT_STATUS           (1UL<<9)
1683 #define   PIPE_DISPLAY_LINE_COMPARE_STATUS      (1UL<<8)
1684 #define   PIPE_DPST_EVENT_STATUS                (1UL<<7)
1685 #define   PIPE_LEGACY_BLC_EVENT_STATUS          (1UL<<6)
1686 #define   PIPE_ODD_FIELD_INTERRUPT_STATUS       (1UL<<5)
1687 #define   PIPE_EVEN_FIELD_INTERRUPT_STATUS      (1UL<<4)
1688 #define   PIPE_HOTPLUG_TV_INTERRUPT_STATUS      (1UL<<2) /* pre-965 */
1689 #define   PIPE_START_VBLANK_INTERRUPT_STATUS    (1UL<<2) /* 965 or later */
1690 #define   PIPE_VBLANK_INTERRUPT_STATUS          (1UL<<1)
1691 #define   PIPE_OVERLAY_UPDATED_STATUS           (1UL<<0)
1692
1693 #define DSPARB                  0x70030
1694 #define   DSPARB_CSTART_MASK    (0x7f << 7)
1695 #define   DSPARB_CSTART_SHIFT   7
1696 #define   DSPARB_BSTART_MASK    (0x7f)           
1697 #define   DSPARB_BSTART_SHIFT   0
1698 /*
1699  * The two pipe frame counter registers are not synchronized, so
1700  * reading a stable value is somewhat tricky. The following code 
1701  * should work:
1702  *
1703  *  do {
1704  *    high1 = ((INREG(PIPEAFRAMEHIGH) & PIPE_FRAME_HIGH_MASK) >>
1705  *             PIPE_FRAME_HIGH_SHIFT;
1706  *    low1 =  ((INREG(PIPEAFRAMEPIXEL) & PIPE_FRAME_LOW_MASK) >>
1707  *             PIPE_FRAME_LOW_SHIFT);
1708  *    high2 = ((INREG(PIPEAFRAMEHIGH) & PIPE_FRAME_HIGH_MASK) >>
1709  *             PIPE_FRAME_HIGH_SHIFT);
1710  *  } while (high1 != high2);
1711  *  frame = (high1 << 8) | low1;
1712  */
1713 #define PIPEAFRAMEHIGH          0x70040
1714 #define   PIPE_FRAME_HIGH_MASK    0x0000ffff
1715 #define   PIPE_FRAME_HIGH_SHIFT   0
1716 #define PIPEAFRAMEPIXEL         0x70044
1717 #define   PIPE_FRAME_LOW_MASK     0xff000000
1718 #define   PIPE_FRAME_LOW_SHIFT    24
1719 #define   PIPE_PIXEL_MASK         0x00ffffff
1720 #define   PIPE_PIXEL_SHIFT        0
1721
1722 /* Cursor A & B regs */
1723 #define CURACNTR                0x70080
1724 #define   CURSOR_MODE_DISABLE   0x00
1725 #define   CURSOR_MODE_64_32B_AX 0x07
1726 #define   CURSOR_MODE_64_ARGB_AX ((1 << 5) | CURSOR_MODE_64_32B_AX)
1727 #define   MCURSOR_GAMMA_ENABLE  (1 << 26)
1728 #define CURABASE                0x70084
1729 #define CURAPOS                 0x70088
1730 #define   CURSOR_POS_MASK       0x007FF
1731 #define   CURSOR_POS_SIGN       0x8000
1732 #define   CURSOR_X_SHIFT        0
1733 #define   CURSOR_Y_SHIFT        16
1734 #define CURBCNTR                0x700c0
1735 #define CURBBASE                0x700c4
1736 #define CURBPOS                 0x700c8
1737
1738 /* Display A control */
1739 #define DSPACNTR                0x70180
1740 #define   DISPLAY_PLANE_ENABLE                  (1<<31)
1741 #define   DISPLAY_PLANE_DISABLE                 0
1742 #define   DISPPLANE_GAMMA_ENABLE                (1<<30)
1743 #define   DISPPLANE_GAMMA_DISABLE               0
1744 #define   DISPPLANE_PIXFORMAT_MASK              (0xf<<26)
1745 #define   DISPPLANE_8BPP                        (0x2<<26)
1746 #define   DISPPLANE_15_16BPP                    (0x4<<26)
1747 #define   DISPPLANE_16BPP                       (0x5<<26)
1748 #define   DISPPLANE_32BPP_NO_ALPHA              (0x6<<26)
1749 #define   DISPPLANE_32BPP                       (0x7<<26)
1750 #define   DISPPLANE_STEREO_ENABLE               (1<<25)
1751 #define   DISPPLANE_STEREO_DISABLE              0
1752 #define   DISPPLANE_SEL_PIPE_MASK               (1<<24)
1753 #define   DISPPLANE_SEL_PIPE_A                  0
1754 #define   DISPPLANE_SEL_PIPE_B                  (1<<24)
1755 #define   DISPPLANE_SRC_KEY_ENABLE              (1<<22)
1756 #define   DISPPLANE_SRC_KEY_DISABLE             0
1757 #define   DISPPLANE_LINE_DOUBLE                 (1<<20)
1758 #define   DISPPLANE_NO_LINE_DOUBLE              0
1759 #define   DISPPLANE_STEREO_POLARITY_FIRST       0
1760 #define   DISPPLANE_STEREO_POLARITY_SECOND      (1<<18)
1761 #define DSPAADDR                0x70184
1762 #define DSPASTRIDE              0x70188
1763 #define DSPAPOS                 0x7018C /* reserved */
1764 #define DSPASIZE                0x70190
1765 #define DSPASURF                0x7019C /* 965+ only */
1766 #define DSPATILEOFF             0x701A4 /* 965+ only */
1767
1768 /* VBIOS flags */
1769 #define SWF00                   0x71410
1770 #define SWF01                   0x71414
1771 #define SWF02                   0x71418
1772 #define SWF03                   0x7141c
1773 #define SWF04                   0x71420
1774 #define SWF05                   0x71424
1775 #define SWF06                   0x71428
1776 #define SWF10                   0x70410
1777 #define SWF11                   0x70414
1778 #define SWF14                   0x71420
1779 #define SWF30                   0x72414
1780 #define SWF31                   0x72418
1781 #define SWF32                   0x7241c
1782
1783 /* Pipe B */
1784 #define PIPEBDSL                0x71000
1785 #define PIPEBCONF               0x71008
1786 #define PIPEBSTAT               0x71024
1787 #define PIPEBFRAMEHIGH          0x71040
1788 #define PIPEBFRAMEPIXEL         0x71044
1789
1790 /* Display B control */
1791 #define DSPBCNTR                0x71180
1792 #define   DISPPLANE_ALPHA_TRANS_ENABLE          (1<<15)
1793 #define   DISPPLANE_ALPHA_TRANS_DISABLE         0
1794 #define   DISPPLANE_SPRITE_ABOVE_DISPLAY        0
1795 #define   DISPPLANE_SPRITE_ABOVE_OVERLAY        (1)
1796 #define DSPBADDR                0x71184
1797 #define DSPBSTRIDE              0x71188
1798 #define DSPBPOS                 0x7118C
1799 #define DSPBSIZE                0x71190
1800 #define DSPBSURF                0x7119C
1801 #define DSPBTILEOFF             0x711A4
1802
1803 /* VBIOS regs */
1804 #define VGACNTRL                0x71400
1805 # define VGA_DISP_DISABLE                       (1 << 31)
1806 # define VGA_2X_MODE                            (1 << 30)
1807 # define VGA_PIPE_B_SELECT                      (1 << 29)
1808
1809 /* Chipset type macros */
1810
1811 #define IS_I830(dev) ((dev)->pci_device == 0x3577)
1812 #define IS_845G(dev) ((dev)->pci_device == 0x2562)
1813 #define IS_I85X(dev) ((dev)->pci_device == 0x3582)
1814 #define IS_I855(dev) ((dev)->pci_device == 0x3582)
1815 #define IS_I865G(dev) ((dev)->pci_device == 0x2572)
1816
1817 #define IS_I915G(dev) ((dev)->pci_device == 0x2582 || (dev)->pci_device == 0x258a)
1818 #define IS_I915GM(dev) ((dev)->pci_device == 0x2592)
1819 #define IS_I945G(dev) ((dev)->pci_device == 0x2772)
1820 #define IS_I945GM(dev) ((dev)->pci_device == 0x27A2 ||\
1821                         (dev)->pci_device == 0x27AE)
1822 #define IS_I965G(dev) ((dev)->pci_device == 0x2972 || \
1823                        (dev)->pci_device == 0x2982 || \
1824                        (dev)->pci_device == 0x2992 || \
1825                        (dev)->pci_device == 0x29A2 || \
1826                        (dev)->pci_device == 0x2A02 || \
1827                        (dev)->pci_device == 0x2A12 || \
1828                        (dev)->pci_device == 0x2A42 || \
1829                        (dev)->pci_device == 0x2E02 || \
1830                        (dev)->pci_device == 0x2E12 || \
1831                        (dev)->pci_device == 0x2E22)
1832
1833 #define IS_I965GM(dev) ((dev)->pci_device == 0x2A02)
1834
1835 #define IS_GM45(dev) ((dev)->pci_device == 0x2A42)
1836
1837 #define IS_G4X(dev) ((dev)->pci_device == 0x2E02 || \
1838                      (dev)->pci_device == 0x2E12 || \
1839                      (dev)->pci_device == 0x2E22)
1840
1841 #define IS_G33(dev)    ((dev)->pci_device == 0x29C2 ||  \
1842                         (dev)->pci_device == 0x29B2 ||  \
1843                         (dev)->pci_device == 0x29D2)
1844
1845 #define IS_I9XX(dev) (IS_I915G(dev) || IS_I915GM(dev) || IS_I945G(dev) || \
1846                       IS_I945GM(dev) || IS_I965G(dev) || IS_G33(dev))
1847
1848 #define IS_MOBILE(dev) (IS_I830(dev) || IS_I85X(dev) || IS_I915GM(dev) || \
1849                         IS_I945GM(dev) || IS_I965GM(dev) || IS_GM45(dev))
1850
1851 #define I915_NEED_GFX_HWS(dev) (IS_G33(dev) || IS_GM45(dev) || IS_G4X(dev))
1852
1853 #endif