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