Merge commit 'origin/master' into drm-gem
[profile/ivi/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 #ifdef I915_HAVE_BUFFER
71 #define I915_MAX_VALIDATE_BUFFERS 4096
72 struct drm_i915_validate_buffer;
73 #endif
74
75 typedef 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 } drm_i915_ring_buffer_t;
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 typedef 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 } drm_i915_vbl_swap_t;
102
103 typedef struct drm_i915_private {
104         struct drm_device *dev;
105
106         drm_local_map_t *sarea;
107         drm_local_map_t *mmio_map;
108
109         drm_i915_sarea_t *sarea_priv;
110         drm_i915_ring_buffer_t ring;
111
112         drm_dma_handle_t *status_page_dmah;
113         void *hw_status_page;
114         dma_addr_t dma_status_page;
115         uint32_t counter;
116         unsigned int status_gfx_addr;
117         drm_local_map_t hws_map;
118
119         unsigned int cpp;
120         int use_mi_batchbuffer_start;
121
122         wait_queue_head_t irq_queue;
123         atomic_t irq_received;
124         atomic_t irq_emitted;
125
126         int tex_lru_log_granularity;
127         int allow_batchbuffer;
128         struct mem_block *agp_heap;
129         unsigned int sr01, adpa, ppcr, dvob, dvoc, lvds;
130         int vblank_pipe;
131         DRM_SPINTYPE user_irq_lock;
132         int user_irq_refcount;
133         int fence_irq_on;
134         uint32_t irq_mask_reg;
135         int irq_enabled;
136
137 #ifdef I915_HAVE_FENCE
138         uint32_t flush_sequence;
139         uint32_t flush_flags;
140         uint32_t flush_pending;
141         uint32_t saved_flush_status;
142 #endif
143 #ifdef I915_HAVE_BUFFER
144         void *agp_iomap;
145         unsigned int max_validate_buffers;
146         struct mutex cmdbuf_mutex;
147         struct drm_i915_validate_buffer *val_bufs;
148 #endif
149
150         DRM_SPINTYPE swaps_lock;
151         drm_i915_vbl_swap_t vbl_swaps;
152         unsigned int swaps_pending;
153 #if defined(I915_HAVE_BUFFER)
154         /* DRI2 sarea */
155         struct drm_buffer_object *sarea_bo;
156         struct drm_bo_kmap_obj sarea_kmap;
157 #endif
158         /* Register state */
159         u8 saveLBB;
160         u32 saveDSPACNTR;
161         u32 saveDSPBCNTR;
162         u32 saveDSPARB;
163         u32 savePIPEACONF;
164         u32 savePIPEBCONF;
165         u32 savePIPEASRC;
166         u32 savePIPEBSRC;
167         u32 saveFPA0;
168         u32 saveFPA1;
169         u32 saveDPLL_A;
170         u32 saveDPLL_A_MD;
171         u32 saveHTOTAL_A;
172         u32 saveHBLANK_A;
173         u32 saveHSYNC_A;
174         u32 saveVTOTAL_A;
175         u32 saveVBLANK_A;
176         u32 saveVSYNC_A;
177         u32 saveBCLRPAT_A;
178         u32 savePIPEASTAT;
179         u32 saveDSPASTRIDE;
180         u32 saveDSPASIZE;
181         u32 saveDSPAPOS;
182         u32 saveDSPABASE;
183         u32 saveDSPASURF;
184         u32 saveDSPATILEOFF;
185         u32 savePFIT_PGM_RATIOS;
186         u32 saveBLC_PWM_CTL;
187         u32 saveBLC_PWM_CTL2;
188         u32 saveFPB0;
189         u32 saveFPB1;
190         u32 saveDPLL_B;
191         u32 saveDPLL_B_MD;
192         u32 saveHTOTAL_B;
193         u32 saveHBLANK_B;
194         u32 saveHSYNC_B;
195         u32 saveVTOTAL_B;
196         u32 saveVBLANK_B;
197         u32 saveVSYNC_B;
198         u32 saveBCLRPAT_B;
199         u32 savePIPEBSTAT;
200         u32 saveDSPBSTRIDE;
201         u32 saveDSPBSIZE;
202         u32 saveDSPBPOS;
203         u32 saveDSPBBASE;
204         u32 saveDSPBSURF;
205         u32 saveDSPBTILEOFF;
206         u32 saveVCLK_DIVISOR_VGA0;
207         u32 saveVCLK_DIVISOR_VGA1;
208         u32 saveVCLK_POST_DIV;
209         u32 saveVGACNTRL;
210         u32 saveADPA;
211         u32 saveLVDS;
212         u32 saveLVDSPP_ON;
213         u32 saveLVDSPP_OFF;
214         u32 saveDVOA;
215         u32 saveDVOB;
216         u32 saveDVOC;
217         u32 savePP_ON;
218         u32 savePP_OFF;
219         u32 savePP_CONTROL;
220         u32 savePP_CYCLE;
221         u32 savePFIT_CONTROL;
222         u32 save_palette_a[256];
223         u32 save_palette_b[256];
224         u32 saveFBC_CFB_BASE;
225         u32 saveFBC_LL_BASE;
226         u32 saveFBC_CONTROL;
227         u32 saveFBC_CONTROL2;
228         u32 saveIER;
229         u32 saveIIR;
230         u32 saveIMR;
231         u32 saveCACHE_MODE_0;
232         u32 saveD_STATE;
233         u32 saveDSPCLK_GATE_D;
234         u32 saveMI_ARB_STATE;
235         u32 saveSWF0[16];
236         u32 saveSWF1[16];
237         u32 saveSWF2[3];
238         u8 saveMSR;
239         u8 saveSR[8];
240         u8 saveGR[25];
241         u8 saveAR_INDEX;
242         u8 saveAR[21];
243         u8 saveDACMASK;
244         u8 saveDACDATA[256*3]; /* 256 3-byte colors */
245         u8 saveCR[37];
246
247         struct {
248                 struct drm_memrange gtt_space;
249
250                 /**
251                  * List of objects currently involved in rendering from the
252                  * ringbuffer.
253                  *
254                  * A reference is held on the buffer while on this list.
255                  */
256                 struct list_head active_list;
257
258                 /**
259                  * List of objects which are not in the ringbuffer but which
260                  * still have a write_domain which needs to be flushed before
261                  * unbinding.
262                  *
263                  * A reference is held on the buffer while on this list.
264                  */
265                 struct list_head flushing_list;
266
267                 /**
268                  * LRU list of objects which are not in the ringbuffer and
269                  * are ready to unbind, but are still in the GTT.
270                  *
271                  * A reference is not held on the buffer while on this list,
272                  * as merely being GTT-bound shouldn't prevent its being
273                  * freed, and we'll pull it off the list in the free path.
274                  */
275                 struct list_head inactive_list;
276
277                 /**
278                  * List of breadcrumbs associated with GPU requests currently
279                  * outstanding.
280                  */
281                 struct list_head request_list;
282
283                 uint32_t next_gem_seqno;
284         } mm;
285
286         struct work_struct user_interrupt_task;
287 } drm_i915_private_t;
288
289 enum intel_chip_family {
290         CHIP_I8XX = 0x01,
291         CHIP_I9XX = 0x02,
292         CHIP_I915 = 0x04,
293         CHIP_I965 = 0x08,
294 };
295
296 /** driver private structure attached to each drm_gem_object */
297 struct drm_i915_gem_object {
298         struct drm_gem_object *obj;
299
300         /** Current space allocated to this object in the GTT, if any. */
301         struct drm_memrange_node *gtt_space;
302
303         /** This object's place on the active/flushing/inactive lists */
304         struct list_head list;
305
306         /**
307          * This is set if the object is on the active or flushing lists
308          * (has pending rendering), and is not set if it's on inactive (ready
309          * to be unbound).
310          */
311         int active;
312
313         /** AGP memory structure for our GTT binding. */
314         DRM_AGP_MEM *agp_mem;
315
316         struct page **page_list;
317
318         /**
319          * Current offset of the object in GTT space.
320          *
321          * This is the same as gtt_space->start
322          */
323         uint32_t gtt_offset;
324
325         /** Boolean whether this object has a valid gtt offset. */
326         int gtt_bound;
327
328         /** How many users have pinned this object in GTT space */
329         int pin_count;
330
331         /** Breadcrumb of last rendering to the buffer. */
332         uint32_t last_rendering_seqno;
333 };
334
335 /**
336  * Request queue structure.
337  *
338  * The request queue allows us to note sequence numbers that have been emitted
339  * and may be associated with active buffers to be retired.
340  *
341  * By keeping this list, we can avoid having to do questionable
342  * sequence-number comparisons on buffer last_rendering_seqnos, and associate
343  * an emission time with seqnos for tracking how far ahead of the GPU we are.
344  */
345 struct drm_i915_gem_request {
346         /** GEM sequence number associated with this request. */
347         uint32_t seqno;
348
349         /** Time at which this request was emitted, in jiffies. */
350         unsigned long emitted_jiffies;
351
352         /** Cache domains that were flushed at the start of the request. */
353         uint32_t flush_domains;
354
355         struct list_head list;
356 };
357
358 extern struct drm_ioctl_desc i915_ioctls[];
359 extern int i915_max_ioctl;
360
361                                 /* i915_dma.c */
362 extern void i915_kernel_lost_context(struct drm_device * dev);
363 extern int i915_driver_load(struct drm_device *, unsigned long flags);
364 extern int i915_driver_unload(struct drm_device *);
365 extern void i915_driver_lastclose(struct drm_device * dev);
366 extern void i915_driver_preclose(struct drm_device *dev,
367                                  struct drm_file *file_priv);
368 extern int i915_driver_device_is_agp(struct drm_device * dev);
369 extern long i915_compat_ioctl(struct file *filp, unsigned int cmd,
370                               unsigned long arg);
371 extern void i915_emit_breadcrumb(struct drm_device *dev);
372 extern void i915_dispatch_flip(struct drm_device * dev, int pipes, int sync);
373 extern int i915_emit_mi_flush(struct drm_device *dev, uint32_t flush);
374 extern int i915_driver_firstopen(struct drm_device *dev);
375 extern int i915_dispatch_batchbuffer(struct drm_device * dev,
376                                      drm_i915_batchbuffer_t * batch);
377 extern int i915_quiescent(struct drm_device *dev);
378
379 int i915_emit_box(struct drm_device * dev,
380                   struct drm_clip_rect __user * boxes,
381                   int i, int DR1, int DR4);
382
383 /* i915_irq.c */
384 extern int i915_irq_emit(struct drm_device *dev, void *data,
385                          struct drm_file *file_priv);
386 extern int i915_irq_wait(struct drm_device *dev, void *data,
387                          struct drm_file *file_priv);
388
389 extern irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS);
390 extern void i915_driver_irq_preinstall(struct drm_device * dev);
391 extern int i915_driver_irq_postinstall(struct drm_device * dev);
392 extern void i915_driver_irq_uninstall(struct drm_device * dev);
393 extern int i915_vblank_pipe_set(struct drm_device *dev, void *data,
394                                 struct drm_file *file_priv);
395 extern int i915_vblank_pipe_get(struct drm_device *dev, void *data,
396                                 struct drm_file *file_priv);
397 extern int i915_emit_irq(struct drm_device * dev);
398 extern int i915_wait_irq(struct drm_device * dev, int irq_nr);
399 extern int i915_enable_vblank(struct drm_device *dev, int crtc);
400 extern void i915_disable_vblank(struct drm_device *dev, int crtc);
401 extern u32 i915_get_vblank_counter(struct drm_device *dev, int crtc);
402 extern int i915_vblank_swap(struct drm_device *dev, void *data,
403                             struct drm_file *file_priv);
404 extern void i915_user_irq_on(drm_i915_private_t *dev_priv);
405 extern void i915_user_irq_off(drm_i915_private_t *dev_priv);
406 extern void i915_user_interrupt_handler(struct work_struct *work);
407
408 /* i915_mem.c */
409 extern int i915_mem_alloc(struct drm_device *dev, void *data,
410                           struct drm_file *file_priv);
411 extern int i915_mem_free(struct drm_device *dev, void *data,
412                          struct drm_file *file_priv);
413 extern int i915_mem_init_heap(struct drm_device *dev, void *data,
414                               struct drm_file *file_priv);
415 extern int i915_mem_destroy_heap(struct drm_device *dev, void *data,
416                                  struct drm_file *file_priv);
417 extern void i915_mem_takedown(struct mem_block **heap);
418 extern void i915_mem_release(struct drm_device * dev,
419                              struct drm_file *file_priv,
420                              struct mem_block *heap);
421 #ifdef I915_HAVE_FENCE
422 /* i915_fence.c */
423 extern void i915_fence_handler(struct drm_device *dev);
424 extern void i915_invalidate_reported_sequence(struct drm_device *dev);
425
426 #endif
427
428 #ifdef I915_HAVE_BUFFER
429 /* i915_buffer.c */
430 extern struct drm_ttm_backend *i915_create_ttm_backend_entry(struct drm_device *dev);
431 extern int i915_fence_type(struct drm_buffer_object *bo, uint32_t *fclass,
432                            uint32_t *type);
433 extern int i915_invalidate_caches(struct drm_device *dev, uint64_t buffer_flags);
434 extern int i915_init_mem_type(struct drm_device *dev, uint32_t type,
435                                struct drm_mem_type_manager *man);
436 extern uint64_t i915_evict_flags(struct drm_buffer_object *bo);
437 extern int i915_move(struct drm_buffer_object *bo, int evict,
438                 int no_wait, struct drm_bo_mem_reg *new_mem);
439 void i915_flush_ttm(struct drm_ttm *ttm);
440 /* i915_execbuf.c */
441 int i915_execbuffer(struct drm_device *dev, void *data,
442                                    struct drm_file *file_priv);
443 /* i915_gem.c */
444 int i915_gem_init_ioctl(struct drm_device *dev, void *data,
445                         struct drm_file *file_priv);
446 int i915_gem_execbuffer(struct drm_device *dev, void *data,
447                         struct drm_file *file_priv);
448 int i915_gem_pin_ioctl(struct drm_device *dev, void *data,
449                        struct drm_file *file_priv);
450 int i915_gem_unpin_ioctl(struct drm_device *dev, void *data,
451                          struct drm_file *file_priv);
452 int i915_gem_busy_ioctl(struct drm_device *dev, void *data,
453                         struct drm_file *file_priv);
454 int i915_gem_init_object(struct drm_gem_object *obj);
455 void i915_gem_free_object(struct drm_gem_object *obj);
456 int i915_gem_set_domain(struct drm_gem_object *obj,
457                         struct drm_file *file_priv,
458                         uint32_t read_domains,
459                         uint32_t write_domain);
460 int i915_gem_flush_pwrite(struct drm_gem_object *obj,
461                           uint64_t offset, uint64_t size);
462 void i915_gem_lastclose(struct drm_device *dev);
463 void i915_gem_retire_requests(struct drm_device *dev);
464 #endif
465
466 #ifdef __linux__
467 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)
468 extern void intel_init_chipset_flush_compat(struct drm_device *dev);
469 extern void intel_fini_chipset_flush_compat(struct drm_device *dev);
470 #endif
471 #endif
472
473 #define I915_READ(reg)          DRM_READ32(dev_priv->mmio_map, (reg))
474 #define I915_WRITE(reg,val)     DRM_WRITE32(dev_priv->mmio_map, (reg), (val))
475 #define I915_READ16(reg)        DRM_READ16(dev_priv->mmio_map, (reg))
476 #define I915_WRITE16(reg,val)   DRM_WRITE16(dev_priv->mmio_map, (reg), (val))
477
478 #define I915_VERBOSE 0
479 #define I915_RING_VALIDATE 0
480
481 #define RING_LOCALS     unsigned int outring, ringmask, outcount; \
482                         volatile char *virt;
483
484 #if I915_RING_VALIDATE
485 void i915_ring_validate(struct drm_device *dev, const char *func, int line);
486 #define I915_RING_DO_VALIDATE(dev) i915_ring_validate(dev, __FUNCTION__, __LINE__)
487 #else
488 #define I915_RING_DO_VALIDATE(dev)
489 #endif
490
491 #define BEGIN_LP_RING(n) do {                           \
492         if (I915_VERBOSE)                               \
493                 DRM_DEBUG("BEGIN_LP_RING(%d)\n",        \
494                                  (n));                  \
495         I915_RING_DO_VALIDATE(dev);                     \
496         if (dev_priv->ring.space < (n)*4)                      \
497                 i915_wait_ring(dev, (n)*4, __FUNCTION__);      \
498         outcount = 0;                                   \
499         outring = dev_priv->ring.tail;                  \
500         ringmask = dev_priv->ring.tail_mask;            \
501         virt = dev_priv->ring.virtual_start;            \
502 } while (0)
503
504 #define OUT_RING(n) do {                                        \
505         if (I915_VERBOSE) DRM_DEBUG("   OUT_RING %x\n", (int)(n));      \
506         *(volatile unsigned int *)(virt + outring) = (n);               \
507         outcount++;                                             \
508         outring += 4;                                           \
509         outring &= ringmask;                                    \
510 } while (0)
511
512 #define ADVANCE_LP_RING() do {                                          \
513         if (I915_VERBOSE) DRM_DEBUG("ADVANCE_LP_RING %x\n", outring);   \
514         I915_RING_DO_VALIDATE(dev);                                     \
515         dev_priv->ring.tail = outring;                                  \
516         dev_priv->ring.space -= outcount * 4;                           \
517         I915_WRITE(LP_RING + RING_TAIL, outring);                       \
518 } while(0)
519
520 extern int i915_wait_ring(struct drm_device * dev, int n, const char *caller);
521
522 /* Extended config space */
523 #define LBB 0xf4
524
525 /* VGA stuff */
526
527 #define VGA_ST01_MDA 0x3ba
528 #define VGA_ST01_CGA 0x3da
529
530 #define VGA_MSR_WRITE 0x3c2
531 #define VGA_MSR_READ 0x3cc
532 #define   VGA_MSR_MEM_EN (1<<1)
533 #define   VGA_MSR_CGA_MODE (1<<0)
534
535 #define VGA_SR_INDEX 0x3c4
536 #define VGA_SR_DATA 0x3c5
537
538 #define VGA_AR_INDEX 0x3c0
539 #define   VGA_AR_VID_EN (1<<5)
540 #define VGA_AR_DATA_WRITE 0x3c0
541 #define VGA_AR_DATA_READ 0x3c1
542
543 #define VGA_GR_INDEX 0x3ce
544 #define VGA_GR_DATA 0x3cf
545 /* GR05 */
546 #define   VGA_GR_MEM_READ_MODE_SHIFT 3
547 #define     VGA_GR_MEM_READ_MODE_PLANE 1
548 /* GR06 */
549 #define   VGA_GR_MEM_MODE_MASK 0xc
550 #define   VGA_GR_MEM_MODE_SHIFT 2
551 #define   VGA_GR_MEM_A0000_AFFFF 0
552 #define   VGA_GR_MEM_A0000_BFFFF 1
553 #define   VGA_GR_MEM_B0000_B7FFF 2
554 #define   VGA_GR_MEM_B0000_BFFFF 3
555
556 #define VGA_DACMASK 0x3c6
557 #define VGA_DACRX 0x3c7
558 #define VGA_DACWX 0x3c8
559 #define VGA_DACDATA 0x3c9
560
561 #define VGA_CR_INDEX_MDA 0x3b4
562 #define VGA_CR_DATA_MDA 0x3b5
563 #define VGA_CR_INDEX_CGA 0x3d4
564 #define VGA_CR_DATA_CGA 0x3d5
565
566 #define GFX_OP_USER_INTERRUPT           ((0<<29)|(2<<23))
567 #define GFX_OP_BREAKPOINT_INTERRUPT     ((0<<29)|(1<<23))
568 #define CMD_REPORT_HEAD                 (7<<23)
569 #define CMD_STORE_DWORD_IMM             ((0x20<<23) | (0x1 << 22) | 0x1)
570 /**
571  * Stores a 32-bit integer to the status page at the dword index given.
572  */
573 #define CMD_STORE_DWORD_IDX             ((0x21<<23) | 0x1)
574 # define STORE_DWORD_INDEX_SHIFT                2
575
576 #define CMD_OP_BATCH_BUFFER  ((0x0<<29)|(0x30<<23)|0x1)
577
578 #define CMD_MI_FLUSH         (0x04 << 23)
579 #define MI_NO_WRITE_FLUSH    (1 << 2)
580 #define MI_READ_FLUSH        (1 << 0)
581 #define MI_EXE_FLUSH         (1 << 1)
582 #define MI_END_SCENE         (1 << 4) /* flush binner and incr scene count */
583 #define MI_SCENE_COUNT       (1 << 3) /* just increment scene count */
584
585 /* Packet to load a register value from the ring/batch command stream:
586  */
587 #define CMD_MI_LOAD_REGISTER_IMM        ((0x22 << 23)|0x1)
588
589 #define BB1_START_ADDR_MASK   (~0x7)
590 #define BB1_PROTECTED         (1<<0)
591 #define BB1_UNPROTECTED       (0<<0)
592 #define BB2_END_ADDR_MASK     (~0x7)
593
594 /* Framebuffer compression */
595 #define FBC_CFB_BASE            0x03200 /* 4k page aligned */
596 #define FBC_LL_BASE             0x03204 /* 4k page aligned */
597 #define FBC_CONTROL             0x03208
598 #define   FBC_CTL_EN            (1<<31)
599 #define   FBC_CTL_PERIODIC      (1<<30)
600 #define   FBC_CTL_INTERVAL_SHIFT (16)
601 #define   FBC_CTL_UNCOMPRESSIBLE (1<<14)
602 #define   FBC_CTL_STRIDE_SHIFT  (5)
603 #define   FBC_CTL_FENCENO       (1<<0)
604 #define FBC_COMMAND             0x0320c
605 #define   FBC_CMD_COMPRESS      (1<<0)
606 #define FBC_STATUS              0x03210
607 #define   FBC_STAT_COMPRESSING  (1<<31)
608 #define   FBC_STAT_COMPRESSED   (1<<30)
609 #define   FBC_STAT_MODIFIED     (1<<29)
610 #define   FBC_STAT_CURRENT_LINE (1<<0)
611 #define FBC_CONTROL2            0x03214
612 #define   FBC_CTL_FENCE_DBL     (0<<4)
613 #define   FBC_CTL_IDLE_IMM      (0<<2)
614 #define   FBC_CTL_IDLE_FULL     (1<<2)
615 #define   FBC_CTL_IDLE_LINE     (2<<2)
616 #define   FBC_CTL_IDLE_DEBUG    (3<<2)
617 #define   FBC_CTL_CPU_FENCE     (1<<1)
618 #define   FBC_CTL_PLANEA        (0<<0)
619 #define   FBC_CTL_PLANEB        (1<<0)
620 #define FBC_FENCE_OFF           0x0321b
621
622 #define FBC_LL_SIZE             (1536)
623 #define FBC_LL_PAD              (32)
624
625 /* Interrupt bits:
626  */
627 #define I915_PIPE_CONTROL_NOTIFY_INTERRUPT              (1<<18)
628 #define I915_DISPLAY_PORT_INTERRUPT                     (1<<17)
629 #define I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT      (1<<15)
630 #define I915_GMCH_THERMAL_SENSOR_EVENT_INTERRUPT        (1<<14)
631 #define I915_HWB_OOM_INTERRUPT                          (1<<13) /* binner out of memory */
632 #define I915_SYNC_STATUS_INTERRUPT                      (1<<12)
633 #define I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT     (1<<11)
634 #define I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT     (1<<10)
635 #define I915_OVERLAY_PLANE_FLIP_PENDING_INTERRUPT       (1<<9)
636 #define I915_DISPLAY_PLANE_C_FLIP_PENDING_INTERRUPT     (1<<8)
637 #define I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT            (1<<7)
638 #define I915_DISPLAY_PIPE_A_EVENT_INTERRUPT             (1<<6)
639 #define I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT            (1<<5)
640 #define I915_DISPLAY_PIPE_B_EVENT_INTERRUPT             (1<<4)
641 #define I915_DEBUG_INTERRUPT                            (1<<2)
642 #define I915_USER_INTERRUPT                             (1<<1)
643
644
645 #define I915REG_HWSTAM          0x02098
646 #define I915REG_INT_IDENTITY_R  0x020a4
647 #define I915REG_INT_MASK_R      0x020a8
648 #define I915REG_INT_ENABLE_R    0x020a0
649 #define I915REG_INSTPM          0x020c0
650 #define I965REG_ACTHD           0x02074
651 #define I915REG_ACTHD           0x020C8
652
653 #define PIPEADSL                0x70000
654 #define PIPEBDSL                0x71000
655
656 #define I915REG_PIPEASTAT       0x70024
657 #define I915REG_PIPEBSTAT       0x71024
658 /*
659  * The two pipe frame counter registers are not synchronized, so
660  * reading a stable value is somewhat tricky. The following code 
661  * should work:
662  *
663  *  do {
664  *    high1 = ((INREG(PIPEAFRAMEHIGH) & PIPE_FRAME_HIGH_MASK) >>
665  *             PIPE_FRAME_HIGH_SHIFT;
666  *    low1 =  ((INREG(PIPEAFRAMEPIXEL) & PIPE_FRAME_LOW_MASK) >>
667  *             PIPE_FRAME_LOW_SHIFT);
668  *    high2 = ((INREG(PIPEAFRAMEHIGH) & PIPE_FRAME_HIGH_MASK) >>
669  *             PIPE_FRAME_HIGH_SHIFT);
670  *  } while (high1 != high2);
671  *  frame = (high1 << 8) | low1;
672  */
673 #define PIPEAFRAMEHIGH          0x70040
674 #define PIPEBFRAMEHIGH          0x71040
675 #define PIPE_FRAME_HIGH_MASK    0x0000ffff
676 #define PIPE_FRAME_HIGH_SHIFT   0
677 #define PIPEAFRAMEPIXEL         0x70044
678 #define PIPEBFRAMEPIXEL         0x71044
679
680 #define PIPE_FRAME_LOW_MASK     0xff000000
681 #define PIPE_FRAME_LOW_SHIFT    24
682 /*
683  * Pixel within the current frame is counted in the PIPEAFRAMEPIXEL register
684  * and is 24 bits wide.
685  */
686 #define PIPE_PIXEL_MASK         0x00ffffff
687 #define PIPE_PIXEL_SHIFT        0
688
689 #define I915_FIFO_UNDERRUN_STATUS               (1UL<<31)
690 #define I915_CRC_ERROR_ENABLE                   (1UL<<29)
691 #define I915_CRC_DONE_ENABLE                    (1UL<<28)
692 #define I915_GMBUS_EVENT_ENABLE                 (1UL<<27)
693 #define I915_VSYNC_INTERRUPT_ENABLE             (1UL<<25)
694 #define I915_DISPLAY_LINE_COMPARE_ENABLE        (1UL<<24)
695 #define I915_DPST_EVENT_ENABLE                  (1UL<<23)
696 #define I915_LEGACY_BLC_EVENT_ENABLE            (1UL<<22)
697 #define I915_ODD_FIELD_INTERRUPT_ENABLE         (1UL<<21)
698 #define I915_EVEN_FIELD_INTERRUPT_ENABLE        (1UL<<20)
699 #define I915_START_VBLANK_INTERRUPT_ENABLE      (1UL<<18)       /* 965 or later */
700 #define I915_VBLANK_INTERRUPT_ENABLE            (1UL<<17)
701 #define I915_OVERLAY_UPDATED_ENABLE             (1UL<<16)
702 #define I915_CRC_ERROR_INTERRUPT_STATUS         (1UL<<13)
703 #define I915_CRC_DONE_INTERRUPT_STATUS          (1UL<<12)
704 #define I915_GMBUS_INTERRUPT_STATUS             (1UL<<11)
705 #define I915_VSYNC_INTERRUPT_STATUS             (1UL<<9)
706 #define I915_DISPLAY_LINE_COMPARE_STATUS        (1UL<<8)
707 #define I915_DPST_EVENT_STATUS                  (1UL<<7)
708 #define I915_LEGACY_BLC_EVENT_STATUS            (1UL<<6)
709 #define I915_ODD_FIELD_INTERRUPT_STATUS         (1UL<<5)
710 #define I915_EVEN_FIELD_INTERRUPT_STATUS        (1UL<<4)
711 #define I915_START_VBLANK_INTERRUPT_STATUS      (1UL<<2)        /* 965 or later */
712 #define I915_VBLANK_INTERRUPT_STATUS            (1UL<<1)
713 #define I915_OVERLAY_UPDATED_STATUS             (1UL<<0)
714
715 #define SRX_INDEX               0x3c4
716 #define SRX_DATA                0x3c5
717 #define SR01                    1
718 #define SR01_SCREEN_OFF         (1<<5)
719
720 #define PPCR                    0x61204
721 #define PPCR_ON                 (1<<0)
722
723 #define DVOB                    0x61140
724 #define DVOB_ON                 (1<<31)
725 #define DVOC                    0x61160
726 #define DVOC_ON                 (1<<31)
727 #define LVDS                    0x61180
728 #define LVDS_ON                 (1<<31)
729
730 #define ADPA                    0x61100
731 #define ADPA_DPMS_MASK          (~(3<<10))
732 #define ADPA_DPMS_ON            (0<<10)
733 #define ADPA_DPMS_SUSPEND       (1<<10)
734 #define ADPA_DPMS_STANDBY       (2<<10)
735 #define ADPA_DPMS_OFF           (3<<10)
736
737 #define NOPID                   0x2094
738 #define LP_RING                 0x2030
739 #define HP_RING                 0x2040
740 /* The binner has its own ring buffer:
741  */
742 #define HWB_RING                0x2400
743
744 #define RING_TAIL               0x00
745 #define TAIL_ADDR               0x001FFFF8
746 #define RING_HEAD               0x04
747 #define HEAD_WRAP_COUNT         0xFFE00000
748 #define HEAD_WRAP_ONE           0x00200000
749 #define HEAD_ADDR               0x001FFFFC
750 #define RING_START              0x08
751 #define START_ADDR              0xFFFFF000
752 #define RING_LEN                0x0C
753 #define RING_NR_PAGES           0x001FF000
754 #define RING_REPORT_MASK        0x00000006
755 #define RING_REPORT_64K         0x00000002
756 #define RING_REPORT_128K        0x00000004
757 #define RING_NO_REPORT          0x00000000
758 #define RING_VALID_MASK         0x00000001
759 #define RING_VALID              0x00000001
760 #define RING_INVALID            0x00000000
761
762 /* Instruction parser error reg:
763  */
764 #define IPEIR                   0x2088
765
766 /* Scratch pad debug 0 reg:
767  */
768 #define SCPD0                   0x209c
769
770 /* Error status reg:
771  */
772 #define ESR                     0x20b8
773
774 /* Secondary DMA fetch address debug reg:
775  */
776 #define DMA_FADD_S              0x20d4
777
778 /* Memory Interface Arbitration State
779  */
780 #define MI_ARB_STATE            0x20e4
781
782 /* Cache mode 0 reg.
783  *  - Manipulating render cache behaviour is central
784  *    to the concept of zone rendering, tuning this reg can help avoid
785  *    unnecessary render cache reads and even writes (for z/stencil)
786  *    at beginning and end of scene.
787  *
788  * - To change a bit, write to this reg with a mask bit set and the
789  * bit of interest either set or cleared.  EG: (BIT<<16) | BIT to set.
790  */
791 #define Cache_Mode_0            0x2120
792 #define CACHE_MODE_0            0x2120
793 #define CM0_MASK_SHIFT          16
794 #define CM0_IZ_OPT_DISABLE      (1<<6)
795 #define CM0_ZR_OPT_DISABLE      (1<<5)
796 #define CM0_DEPTH_EVICT_DISABLE (1<<4)
797 #define CM0_COLOR_EVICT_DISABLE (1<<3)
798 #define CM0_DEPTH_WRITE_DISABLE (1<<1)
799 #define CM0_RC_OP_FLUSH_DISABLE (1<<0)
800
801
802 /* Graphics flush control.  A CPU write flushes the GWB of all writes.
803  * The data is discarded.
804  */
805 #define GFX_FLSH_CNTL           0x2170
806
807 /* Binner control.  Defines the location of the bin pointer list:
808  */
809 #define BINCTL                  0x2420
810 #define BC_MASK                 (1 << 9)
811
812 /* Binned scene info.
813  */
814 #define BINSCENE                0x2428
815 #define BS_OP_LOAD              (1 << 8)
816 #define BS_MASK                 (1 << 22)
817
818 /* Bin command parser debug reg:
819  */
820 #define BCPD                    0x2480
821
822 /* Bin memory control debug reg:
823  */
824 #define BMCD                    0x2484
825
826 /* Bin data cache debug reg:
827  */
828 #define BDCD                    0x2488
829
830 /* Binner pointer cache debug reg:
831  */
832 #define BPCD                    0x248c
833
834 /* Binner scratch pad debug reg:
835  */
836 #define BINSKPD                 0x24f0
837
838 /* HWB scratch pad debug reg:
839  */
840 #define HWBSKPD                 0x24f4
841
842 /* Binner memory pool reg:
843  */
844 #define BMP_BUFFER              0x2430
845 #define BMP_PAGE_SIZE_4K        (0 << 10)
846 #define BMP_BUFFER_SIZE_SHIFT   1
847 #define BMP_ENABLE              (1 << 0)
848
849 /* Get/put memory from the binner memory pool:
850  */
851 #define BMP_GET                 0x2438
852 #define BMP_PUT                 0x2440
853 #define BMP_OFFSET_SHIFT        5
854
855 /* 3D state packets:
856  */
857 #define GFX_OP_RASTER_RULES    ((0x3<<29)|(0x7<<24))
858
859 #define GFX_OP_SCISSOR         ((0x3<<29)|(0x1c<<24)|(0x10<<19))
860 #define SC_UPDATE_SCISSOR       (0x1<<1)
861 #define SC_ENABLE_MASK          (0x1<<0)
862 #define SC_ENABLE               (0x1<<0)
863
864 #define GFX_OP_LOAD_INDIRECT   ((0x3<<29)|(0x1d<<24)|(0x7<<16))
865
866 #define GFX_OP_SCISSOR_INFO    ((0x3<<29)|(0x1d<<24)|(0x81<<16)|(0x1))
867 #define SCI_YMIN_MASK      (0xffff<<16)
868 #define SCI_XMIN_MASK      (0xffff<<0)
869 #define SCI_YMAX_MASK      (0xffff<<16)
870 #define SCI_XMAX_MASK      (0xffff<<0)
871
872 #define GFX_OP_SCISSOR_ENABLE    ((0x3<<29)|(0x1c<<24)|(0x10<<19))
873 #define GFX_OP_SCISSOR_RECT      ((0x3<<29)|(0x1d<<24)|(0x81<<16)|1)
874 #define GFX_OP_COLOR_FACTOR      ((0x3<<29)|(0x1d<<24)|(0x1<<16)|0x0)
875 #define GFX_OP_STIPPLE           ((0x3<<29)|(0x1d<<24)|(0x83<<16))
876 #define GFX_OP_MAP_INFO          ((0x3<<29)|(0x1d<<24)|0x4)
877 #define GFX_OP_DESTBUFFER_VARS   ((0x3<<29)|(0x1d<<24)|(0x85<<16)|0x0)
878 #define GFX_OP_DRAWRECT_INFO     ((0x3<<29)|(0x1d<<24)|(0x80<<16)|(0x3))
879
880 #define GFX_OP_DRAWRECT_INFO_I965  ((0x7900<<16)|0x2)
881
882 #define SRC_COPY_BLT_CMD                ((2<<29)|(0x43<<22)|4)
883 #define XY_SRC_COPY_BLT_CMD             ((2<<29)|(0x53<<22)|6)
884 #define XY_SRC_COPY_BLT_WRITE_ALPHA     (1<<21)
885 #define XY_SRC_COPY_BLT_WRITE_RGB       (1<<20)
886 #define XY_SRC_COPY_BLT_SRC_TILED       (1<<15)
887 #define XY_SRC_COPY_BLT_DST_TILED       (1<<11)
888
889
890 #define MI_BATCH_BUFFER         ((0x30<<23)|1)
891 #define MI_BATCH_BUFFER_START   (0x31<<23)
892 #define MI_BATCH_BUFFER_END     (0xA<<23)
893 #define MI_BATCH_NON_SECURE     (1)
894
895 #define MI_BATCH_NON_SECURE_I965 (1<<8)
896
897 #define MI_WAIT_FOR_EVENT       ((0x3<<23))
898 #define MI_WAIT_FOR_PLANE_B_FLIP      (1<<6)
899 #define MI_WAIT_FOR_PLANE_A_FLIP      (1<<2)
900 #define MI_WAIT_FOR_PLANE_A_SCANLINES (1<<1)
901
902 #define MI_LOAD_SCAN_LINES_INCL  ((0x12<<23))
903
904 #define CMD_OP_DISPLAYBUFFER_INFO ((0x0<<29)|(0x14<<23)|2)
905 #define ASYNC_FLIP                (1<<22)
906 #define DISPLAY_PLANE_A           (0<<20)
907 #define DISPLAY_PLANE_B           (1<<20)
908
909 /* Display regs */
910 #define DSPACNTR                0x70180
911 #define DSPBCNTR                0x71180
912 #define DISPPLANE_SEL_PIPE_MASK                 (1<<24)
913
914 /* Define the region of interest for the binner:
915  */
916 #define CMD_OP_BIN_CONTROL       ((0x3<<29)|(0x1d<<24)|(0x84<<16)|4)
917
918 #define CMD_OP_DESTBUFFER_INFO   ((0x3<<29)|(0x1d<<24)|(0x8e<<16)|1)
919
920 #define BREADCRUMB_BITS 31
921 #define BREADCRUMB_MASK ((1U << BREADCRUMB_BITS) - 1)
922
923 #define READ_BREADCRUMB(dev_priv)  (((volatile u32*)(dev_priv->hw_status_page))[5])
924
925 /**
926  * Reads a dword out of the status page, which is written to from the command
927  * queue by automatic updates, MI_REPORT_HEAD, MI_STORE_DATA_INDEX, or
928  * MI_STORE_DATA_IMM.
929  *
930  * The following dwords have a reserved meaning:
931  * 0: ISR copy, updated when an ISR bit not set in the HWSTAM changes.
932  * 4: ring 0 head pointer
933  * 5: ring 1 head pointer (915-class)
934  * 6: ring 2 head pointer (915-class)
935  *
936  * The area from dword 0x10 to 0x3ff is available for driver usage.
937  */
938 #define READ_HWSP(dev_priv, reg)  (((volatile u32*)(dev_priv->hw_status_page))[reg])
939 #define I915_GEM_HWS_INDEX              0x10
940
941 #define BLC_PWM_CTL             0x61254
942 #define BACKLIGHT_MODULATION_FREQ_SHIFT         (17)
943
944 #define BLC_PWM_CTL2            0x61250
945 /**
946  * This is the most significant 15 bits of the number of backlight cycles in a
947  * complete cycle of the modulated backlight control.
948  *
949  * The actual value is this field multiplied by two.
950  */
951 #define BACKLIGHT_MODULATION_FREQ_MASK          (0x7fff << 17)
952 #define BLM_LEGACY_MODE                         (1 << 16)
953 /**
954  * This is the number of cycles out of the backlight modulation cycle for which
955  * the backlight is on.
956  *
957  * This field must be no greater than the number of cycles in the complete
958  * backlight modulation cycle.
959  */
960 #define BACKLIGHT_DUTY_CYCLE_SHIFT              (0)
961 #define BACKLIGHT_DUTY_CYCLE_MASK               (0xffff)
962
963 #define I915_GCFGC                      0xf0
964 #define I915_LOW_FREQUENCY_ENABLE               (1 << 7)
965 #define I915_DISPLAY_CLOCK_190_200_MHZ          (0 << 4)
966 #define I915_DISPLAY_CLOCK_333_MHZ              (4 << 4)
967 #define I915_DISPLAY_CLOCK_MASK                 (7 << 4)
968
969 #define I855_HPLLCC                     0xc0
970 #define I855_CLOCK_CONTROL_MASK                 (3 << 0)
971 #define I855_CLOCK_133_200                      (0 << 0)
972 #define I855_CLOCK_100_200                      (1 << 0)
973 #define I855_CLOCK_100_133                      (2 << 0)
974 #define I855_CLOCK_166_250                      (3 << 0)
975
976 /* p317, 319
977  */
978 #define VCLK2_VCO_M        0x6008 /* treat as 16 bit? (includes msbs) */
979 #define VCLK2_VCO_N        0x600a
980 #define VCLK2_VCO_DIV_SEL  0x6012
981
982 #define VCLK_DIVISOR_VGA0   0x6000
983 #define VCLK_DIVISOR_VGA1   0x6004
984 #define VCLK_POST_DIV       0x6010
985 /** Selects a post divisor of 4 instead of 2. */
986 # define VGA1_PD_P2_DIV_4       (1 << 15)
987 /** Overrides the p2 post divisor field */
988 # define VGA1_PD_P1_DIV_2       (1 << 13)
989 # define VGA1_PD_P1_SHIFT       8
990 /** P1 value is 2 greater than this field */
991 # define VGA1_PD_P1_MASK        (0x1f << 8)
992 /** Selects a post divisor of 4 instead of 2. */
993 # define VGA0_PD_P2_DIV_4       (1 << 7)
994 /** Overrides the p2 post divisor field */
995 # define VGA0_PD_P1_DIV_2       (1 << 5)
996 # define VGA0_PD_P1_SHIFT       0
997 /** P1 value is 2 greater than this field */
998 # define VGA0_PD_P1_MASK        (0x1f << 0)
999
1000 /* PCI D state control register */
1001 #define D_STATE         0x6104
1002 #define DSPCLK_GATE_D   0x6200
1003
1004 /* I830 CRTC registers */
1005 #define HTOTAL_A        0x60000
1006 #define HBLANK_A        0x60004
1007 #define HSYNC_A         0x60008
1008 #define VTOTAL_A        0x6000c
1009 #define VBLANK_A        0x60010
1010 #define VSYNC_A         0x60014
1011 #define PIPEASRC        0x6001c
1012 #define BCLRPAT_A       0x60020
1013 #define VSYNCSHIFT_A    0x60028
1014
1015 #define HTOTAL_B        0x61000
1016 #define HBLANK_B        0x61004
1017 #define HSYNC_B         0x61008
1018 #define VTOTAL_B        0x6100c
1019 #define VBLANK_B        0x61010
1020 #define VSYNC_B         0x61014
1021 #define PIPEBSRC        0x6101c
1022 #define BCLRPAT_B       0x61020
1023 #define VSYNCSHIFT_B    0x61028
1024
1025 #define HACTIVE_MASK    0x00000fff
1026 #define VTOTAL_MASK     0x00001fff
1027 #define VTOTAL_SHIFT    16
1028 #define VACTIVE_MASK    0x00000fff
1029 #define VBLANK_END_MASK 0x00001fff
1030 #define VBLANK_END_SHIFT 16
1031 #define VBLANK_START_MASK 0x00001fff
1032
1033 #define PP_STATUS       0x61200
1034 # define PP_ON                                  (1 << 31)
1035 /**
1036  * Indicates that all dependencies of the panel are on:
1037  *
1038  * - PLL enabled
1039  * - pipe enabled
1040  * - LVDS/DVOB/DVOC on
1041  */
1042 # define PP_READY                               (1 << 30)
1043 # define PP_SEQUENCE_NONE                       (0 << 28)
1044 # define PP_SEQUENCE_ON                         (1 << 28)
1045 # define PP_SEQUENCE_OFF                        (2 << 28)
1046 # define PP_SEQUENCE_MASK                       0x30000000
1047 #define PP_CONTROL      0x61204
1048 # define POWER_TARGET_ON                        (1 << 0)
1049
1050 #define LVDSPP_ON       0x61208
1051 #define LVDSPP_OFF      0x6120c
1052 #define PP_CYCLE        0x61210
1053
1054 #define PFIT_CONTROL    0x61230
1055 # define PFIT_ENABLE                            (1 << 31)
1056 # define PFIT_PIPE_MASK                         (3 << 29)
1057 # define PFIT_PIPE_SHIFT                        29
1058 # define VERT_INTERP_DISABLE                    (0 << 10)
1059 # define VERT_INTERP_BILINEAR                   (1 << 10)
1060 # define VERT_INTERP_MASK                       (3 << 10)
1061 # define VERT_AUTO_SCALE                        (1 << 9)
1062 # define HORIZ_INTERP_DISABLE                   (0 << 6)
1063 # define HORIZ_INTERP_BILINEAR                  (1 << 6)
1064 # define HORIZ_INTERP_MASK                      (3 << 6)
1065 # define HORIZ_AUTO_SCALE                       (1 << 5)
1066 # define PANEL_8TO6_DITHER_ENABLE               (1 << 3)
1067
1068 #define PFIT_PGM_RATIOS 0x61234
1069 # define PFIT_VERT_SCALE_MASK                   0xfff00000
1070 # define PFIT_HORIZ_SCALE_MASK                  0x0000fff0
1071
1072 #define PFIT_AUTO_RATIOS        0x61238
1073
1074
1075 #define DPLL_A          0x06014
1076 #define DPLL_B          0x06018
1077 # define DPLL_VCO_ENABLE                        (1 << 31)
1078 # define DPLL_DVO_HIGH_SPEED                    (1 << 30)
1079 # define DPLL_SYNCLOCK_ENABLE                   (1 << 29)
1080 # define DPLL_VGA_MODE_DIS                      (1 << 28)
1081 # define DPLLB_MODE_DAC_SERIAL                  (1 << 26) /* i915 */
1082 # define DPLLB_MODE_LVDS                        (2 << 26) /* i915 */
1083 # define DPLL_MODE_MASK                         (3 << 26)
1084 # define DPLL_DAC_SERIAL_P2_CLOCK_DIV_10        (0 << 24) /* i915 */
1085 # define DPLL_DAC_SERIAL_P2_CLOCK_DIV_5         (1 << 24) /* i915 */
1086 # define DPLLB_LVDS_P2_CLOCK_DIV_14             (0 << 24) /* i915 */
1087 # define DPLLB_LVDS_P2_CLOCK_DIV_7              (1 << 24) /* i915 */
1088 # define DPLL_P2_CLOCK_DIV_MASK                 0x03000000 /* i915 */
1089 # define DPLL_FPA01_P1_POST_DIV_MASK            0x00ff0000 /* i915 */
1090 /**
1091  *  The i830 generation, in DAC/serial mode, defines p1 as two plus this
1092  * bitfield, or just 2 if PLL_P1_DIVIDE_BY_TWO is set.
1093  */
1094 # define DPLL_FPA01_P1_POST_DIV_MASK_I830       0x001f0000
1095 /**
1096  * The i830 generation, in LVDS mode, defines P1 as the bit number set within
1097  * this field (only one bit may be set).
1098  */
1099 # define DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS  0x003f0000
1100 # define DPLL_FPA01_P1_POST_DIV_SHIFT           16
1101 # define PLL_P2_DIVIDE_BY_4                     (1 << 23) /* i830, required in DVO non-gang */
1102 # define PLL_P1_DIVIDE_BY_TWO                   (1 << 21) /* i830 */
1103 # define PLL_REF_INPUT_DREFCLK                  (0 << 13)
1104 # define PLL_REF_INPUT_TVCLKINA                 (1 << 13) /* i830 */
1105 # define PLL_REF_INPUT_TVCLKINBC                (2 << 13) /* SDVO TVCLKIN */
1106 # define PLLB_REF_INPUT_SPREADSPECTRUMIN        (3 << 13)
1107 # define PLL_REF_INPUT_MASK                     (3 << 13)
1108 # define PLL_LOAD_PULSE_PHASE_SHIFT             9
1109 /*
1110  * Parallel to Serial Load Pulse phase selection.
1111  * Selects the phase for the 10X DPLL clock for the PCIe
1112  * digital display port. The range is 4 to 13; 10 or more
1113  * is just a flip delay. The default is 6
1114  */
1115 # define PLL_LOAD_PULSE_PHASE_MASK              (0xf << PLL_LOAD_PULSE_PHASE_SHIFT)
1116 # define DISPLAY_RATE_SELECT_FPA1               (1 << 8)
1117
1118 /**
1119  * SDVO multiplier for 945G/GM. Not used on 965.
1120  *
1121  * \sa DPLL_MD_UDI_MULTIPLIER_MASK
1122  */
1123 # define SDVO_MULTIPLIER_MASK                   0x000000ff
1124 # define SDVO_MULTIPLIER_SHIFT_HIRES            4
1125 # define SDVO_MULTIPLIER_SHIFT_VGA              0
1126
1127 /** @defgroup DPLL_MD
1128  * @{
1129  */
1130 /** Pipe A SDVO/UDI clock multiplier/divider register for G965. */
1131 #define DPLL_A_MD               0x0601c
1132 /** Pipe B SDVO/UDI clock multiplier/divider register for G965. */
1133 #define DPLL_B_MD               0x06020
1134 /**
1135  * UDI pixel divider, controlling how many pixels are stuffed into a packet.
1136  *
1137  * Value is pixels minus 1.  Must be set to 1 pixel for SDVO.
1138  */
1139 # define DPLL_MD_UDI_DIVIDER_MASK               0x3f000000
1140 # define DPLL_MD_UDI_DIVIDER_SHIFT              24
1141 /** UDI pixel divider for VGA, same as DPLL_MD_UDI_DIVIDER_MASK. */
1142 # define DPLL_MD_VGA_UDI_DIVIDER_MASK           0x003f0000
1143 # define DPLL_MD_VGA_UDI_DIVIDER_SHIFT          16
1144 /**
1145  * SDVO/UDI pixel multiplier.
1146  *
1147  * SDVO requires that the bus clock rate be between 1 and 2 Ghz, and the bus
1148  * clock rate is 10 times the DPLL clock.  At low resolution/refresh rate
1149  * modes, the bus rate would be below the limits, so SDVO allows for stuffing
1150  * dummy bytes in the datastream at an increased clock rate, with both sides of
1151  * the link knowing how many bytes are fill.
1152  *
1153  * So, for a mode with a dotclock of 65Mhz, we would want to double the clock
1154  * rate to 130Mhz to get a bus rate of 1.30Ghz.  The DPLL clock rate would be
1155  * set to 130Mhz, and the SDVO multiplier set to 2x in this register and
1156  * through an SDVO command.
1157  *
1158  * This register field has values of multiplication factor minus 1, with
1159  * a maximum multiplier of 5 for SDVO.
1160  */
1161 # define DPLL_MD_UDI_MULTIPLIER_MASK            0x00003f00
1162 # define DPLL_MD_UDI_MULTIPLIER_SHIFT           8
1163 /** SDVO/UDI pixel multiplier for VGA, same as DPLL_MD_UDI_MULTIPLIER_MASK.
1164  * This best be set to the default value (3) or the CRT won't work. No,
1165  * I don't entirely understand what this does...
1166  */
1167 # define DPLL_MD_VGA_UDI_MULTIPLIER_MASK        0x0000003f
1168 # define DPLL_MD_VGA_UDI_MULTIPLIER_SHIFT       0
1169 /** @} */
1170
1171 #define DPLL_TEST               0x606c
1172 # define DPLLB_TEST_SDVO_DIV_1                  (0 << 22)
1173 # define DPLLB_TEST_SDVO_DIV_2                  (1 << 22)
1174 # define DPLLB_TEST_SDVO_DIV_4                  (2 << 22)
1175 # define DPLLB_TEST_SDVO_DIV_MASK               (3 << 22)
1176 # define DPLLB_TEST_N_BYPASS                    (1 << 19)
1177 # define DPLLB_TEST_M_BYPASS                    (1 << 18)
1178 # define DPLLB_INPUT_BUFFER_ENABLE              (1 << 16)
1179 # define DPLLA_TEST_N_BYPASS                    (1 << 3)
1180 # define DPLLA_TEST_M_BYPASS                    (1 << 2)
1181 # define DPLLA_INPUT_BUFFER_ENABLE              (1 << 0)
1182
1183 #define ADPA                    0x61100
1184 #define ADPA_DAC_ENABLE         (1<<31)
1185 #define ADPA_DAC_DISABLE        0
1186 #define ADPA_PIPE_SELECT_MASK   (1<<30)
1187 #define ADPA_PIPE_A_SELECT      0
1188 #define ADPA_PIPE_B_SELECT      (1<<30)
1189 #define ADPA_USE_VGA_HVPOLARITY (1<<15)
1190 #define ADPA_SETS_HVPOLARITY    0
1191 #define ADPA_VSYNC_CNTL_DISABLE (1<<11)
1192 #define ADPA_VSYNC_CNTL_ENABLE  0
1193 #define ADPA_HSYNC_CNTL_DISABLE (1<<10)
1194 #define ADPA_HSYNC_CNTL_ENABLE  0
1195 #define ADPA_VSYNC_ACTIVE_HIGH  (1<<4)
1196 #define ADPA_VSYNC_ACTIVE_LOW   0
1197 #define ADPA_HSYNC_ACTIVE_HIGH  (1<<3)
1198 #define ADPA_HSYNC_ACTIVE_LOW   0
1199
1200 #define FPA0            0x06040
1201 #define FPA1            0x06044
1202 #define FPB0            0x06048
1203 #define FPB1            0x0604c
1204 # define FP_N_DIV_MASK                          0x003f0000
1205 # define FP_N_DIV_SHIFT                         16
1206 # define FP_M1_DIV_MASK                         0x00003f00
1207 # define FP_M1_DIV_SHIFT                        8
1208 # define FP_M2_DIV_MASK                         0x0000003f
1209 # define FP_M2_DIV_SHIFT                        0
1210
1211
1212 #define PORT_HOTPLUG_EN         0x61110
1213 # define SDVOB_HOTPLUG_INT_EN                   (1 << 26)
1214 # define SDVOC_HOTPLUG_INT_EN                   (1 << 25)
1215 # define TV_HOTPLUG_INT_EN                      (1 << 18)
1216 # define CRT_HOTPLUG_INT_EN                     (1 << 9)
1217 # define CRT_HOTPLUG_FORCE_DETECT               (1 << 3)
1218
1219 #define PORT_HOTPLUG_STAT       0x61114
1220 # define CRT_HOTPLUG_INT_STATUS                 (1 << 11)
1221 # define TV_HOTPLUG_INT_STATUS                  (1 << 10)
1222 # define CRT_HOTPLUG_MONITOR_MASK               (3 << 8)
1223 # define CRT_HOTPLUG_MONITOR_COLOR              (3 << 8)
1224 # define CRT_HOTPLUG_MONITOR_MONO               (2 << 8)
1225 # define CRT_HOTPLUG_MONITOR_NONE               (0 << 8)
1226 # define SDVOC_HOTPLUG_INT_STATUS               (1 << 7)
1227 # define SDVOB_HOTPLUG_INT_STATUS               (1 << 6)
1228
1229 #define SDVOB                   0x61140
1230 #define SDVOC                   0x61160
1231 #define SDVO_ENABLE                             (1 << 31)
1232 #define SDVO_PIPE_B_SELECT                      (1 << 30)
1233 #define SDVO_STALL_SELECT                       (1 << 29)
1234 #define SDVO_INTERRUPT_ENABLE                   (1 << 26)
1235 /**
1236  * 915G/GM SDVO pixel multiplier.
1237  *
1238  * Programmed value is multiplier - 1, up to 5x.
1239  *
1240  * \sa DPLL_MD_UDI_MULTIPLIER_MASK
1241  */
1242 #define SDVO_PORT_MULTIPLY_MASK                 (7 << 23)
1243 #define SDVO_PORT_MULTIPLY_SHIFT                23
1244 #define SDVO_PHASE_SELECT_MASK                  (15 << 19)
1245 #define SDVO_PHASE_SELECT_DEFAULT               (6 << 19)
1246 #define SDVO_CLOCK_OUTPUT_INVERT                (1 << 18)
1247 #define SDVOC_GANG_MODE                         (1 << 16)
1248 #define SDVO_BORDER_ENABLE                      (1 << 7)
1249 #define SDVOB_PCIE_CONCURRENCY                  (1 << 3)
1250 #define SDVO_DETECTED                           (1 << 2)
1251 /* Bits to be preserved when writing */
1252 #define SDVOB_PRESERVE_MASK                     ((1 << 17) | (1 << 16) | (1 << 14))
1253 #define SDVOC_PRESERVE_MASK                     (1 << 17)
1254
1255 /** @defgroup LVDS
1256  * @{
1257  */
1258 /**
1259  * This register controls the LVDS output enable, pipe selection, and data
1260  * format selection.
1261  *
1262  * All of the clock/data pairs are force powered down by power sequencing.
1263  */
1264 #define LVDS                    0x61180
1265 /**
1266  * Enables the LVDS port.  This bit must be set before DPLLs are enabled, as
1267  * the DPLL semantics change when the LVDS is assigned to that pipe.
1268  */
1269 # define LVDS_PORT_EN                   (1 << 31)
1270 /** Selects pipe B for LVDS data.  Must be set on pre-965. */
1271 # define LVDS_PIPEB_SELECT              (1 << 30)
1272
1273 /**
1274  * Enables the A0-A2 data pairs and CLKA, containing 18 bits of color data per
1275  * pixel.
1276  */
1277 # define LVDS_A0A2_CLKA_POWER_MASK      (3 << 8)
1278 # define LVDS_A0A2_CLKA_POWER_DOWN      (0 << 8)
1279 # define LVDS_A0A2_CLKA_POWER_UP        (3 << 8)
1280 /**
1281  * Controls the A3 data pair, which contains the additional LSBs for 24 bit
1282  * mode.  Only enabled if LVDS_A0A2_CLKA_POWER_UP also indicates it should be
1283  * on.
1284  */
1285 # define LVDS_A3_POWER_MASK             (3 << 6)
1286 # define LVDS_A3_POWER_DOWN             (0 << 6)
1287 # define LVDS_A3_POWER_UP               (3 << 6)
1288 /**
1289  * Controls the CLKB pair.  This should only be set when LVDS_B0B3_POWER_UP
1290  * is set.
1291  */
1292 # define LVDS_CLKB_POWER_MASK           (3 << 4)
1293 # define LVDS_CLKB_POWER_DOWN           (0 << 4)
1294 # define LVDS_CLKB_POWER_UP             (3 << 4)
1295
1296 /**
1297  * Controls the B0-B3 data pairs.  This must be set to match the DPLL p2
1298  * setting for whether we are in dual-channel mode.  The B3 pair will
1299  * additionally only be powered up when LVDS_A3_POWER_UP is set.
1300  */
1301 # define LVDS_B0B3_POWER_MASK           (3 << 2)
1302 # define LVDS_B0B3_POWER_DOWN           (0 << 2)
1303 # define LVDS_B0B3_POWER_UP             (3 << 2)
1304
1305 #define PIPEACONF 0x70008
1306 #define PIPEACONF_ENABLE        (1<<31)
1307 #define PIPEACONF_DISABLE       0
1308 #define PIPEACONF_DOUBLE_WIDE   (1<<30)
1309 #define I965_PIPECONF_ACTIVE    (1<<30)
1310 #define PIPEACONF_SINGLE_WIDE   0
1311 #define PIPEACONF_PIPE_UNLOCKED 0
1312 #define PIPEACONF_PIPE_LOCKED   (1<<25)
1313 #define PIPEACONF_PALETTE       0
1314 #define PIPEACONF_GAMMA         (1<<24)
1315 #define PIPECONF_FORCE_BORDER   (1<<25)
1316 #define PIPECONF_PROGRESSIVE    (0 << 21)
1317 #define PIPECONF_INTERLACE_W_FIELD_INDICATION   (6 << 21)
1318 #define PIPECONF_INTERLACE_FIELD_0_ONLY         (7 << 21)
1319
1320 #define DSPARB    0x70030
1321 #define DSPARB_CSTART_MASK      (0x7f << 7)
1322 #define DSPARB_CSTART_SHIFT     7
1323 #define DSPARB_BSTART_MASK      (0x7f)           
1324 #define DSPARB_BSTART_SHIFT     0
1325
1326 #define PIPEBCONF 0x71008
1327 #define PIPEBCONF_ENABLE        (1<<31)
1328 #define PIPEBCONF_DISABLE       0
1329 #define PIPEBCONF_DOUBLE_WIDE   (1<<30)
1330 #define PIPEBCONF_DISABLE       0
1331 #define PIPEBCONF_GAMMA         (1<<24)
1332 #define PIPEBCONF_PALETTE       0
1333
1334 #define PIPEBGCMAXRED           0x71010
1335 #define PIPEBGCMAXGREEN         0x71014
1336 #define PIPEBGCMAXBLUE          0x71018
1337 #define PIPEBSTAT               0x71024
1338 #define PIPEBFRAMEHIGH          0x71040
1339 #define PIPEBFRAMEPIXEL         0x71044
1340
1341 #define DSPACNTR                0x70180
1342 #define DSPBCNTR                0x71180
1343 #define DISPLAY_PLANE_ENABLE                    (1<<31)
1344 #define DISPLAY_PLANE_DISABLE                   0
1345 #define DISPPLANE_GAMMA_ENABLE                  (1<<30)
1346 #define DISPPLANE_GAMMA_DISABLE                 0
1347 #define DISPPLANE_PIXFORMAT_MASK                (0xf<<26)
1348 #define DISPPLANE_8BPP                          (0x2<<26)
1349 #define DISPPLANE_15_16BPP                      (0x4<<26)
1350 #define DISPPLANE_16BPP                         (0x5<<26)
1351 #define DISPPLANE_32BPP_NO_ALPHA                (0x6<<26)
1352 #define DISPPLANE_32BPP                         (0x7<<26)
1353 #define DISPPLANE_STEREO_ENABLE                 (1<<25)
1354 #define DISPPLANE_STEREO_DISABLE                0
1355 #define DISPPLANE_SEL_PIPE_MASK                 (1<<24)
1356 #define DISPPLANE_SEL_PIPE_A                    0
1357 #define DISPPLANE_SEL_PIPE_B                    (1<<24)
1358 #define DISPPLANE_SRC_KEY_ENABLE                (1<<22)
1359 #define DISPPLANE_SRC_KEY_DISABLE               0
1360 #define DISPPLANE_LINE_DOUBLE                   (1<<20)
1361 #define DISPPLANE_NO_LINE_DOUBLE                0
1362 #define DISPPLANE_STEREO_POLARITY_FIRST         0
1363 #define DISPPLANE_STEREO_POLARITY_SECOND        (1<<18)
1364 /* plane B only */
1365 #define DISPPLANE_ALPHA_TRANS_ENABLE            (1<<15)
1366 #define DISPPLANE_ALPHA_TRANS_DISABLE           0
1367 #define DISPPLANE_SPRITE_ABOVE_DISPLAYA         0
1368 #define DISPPLANE_SPRITE_ABOVE_OVERLAY          (1)
1369
1370 #define DSPABASE                0x70184
1371 #define DSPASTRIDE              0x70188
1372
1373 #define DSPBBASE                0x71184
1374 #define DSPBADDR                DSPBBASE
1375 #define DSPBSTRIDE              0x71188
1376
1377 #define DSPAKEYVAL              0x70194
1378 #define DSPAKEYMASK             0x70198
1379
1380 #define DSPAPOS                 0x7018C /* reserved */
1381 #define DSPASIZE                0x70190
1382 #define DSPBPOS                 0x7118C
1383 #define DSPBSIZE                0x71190
1384
1385 #define DSPASURF                0x7019C
1386 #define DSPATILEOFF             0x701A4
1387
1388 #define DSPBSURF                0x7119C
1389 #define DSPBTILEOFF             0x711A4
1390
1391 #define VGACNTRL                0x71400
1392 # define VGA_DISP_DISABLE                       (1 << 31)
1393 # define VGA_2X_MODE                            (1 << 30)
1394 # define VGA_PIPE_B_SELECT                      (1 << 29)
1395
1396 /*
1397  * Some BIOS scratch area registers.  The 845 (and 830?) store the amount
1398  * of video memory available to the BIOS in SWF1.
1399  */
1400
1401 #define SWF0                    0x71410
1402
1403 /*
1404  * 855 scratch registers.
1405  */
1406 #define SWF10                   0x70410
1407
1408 #define SWF30                   0x72414
1409
1410 /*
1411  * Overlay registers.  These are overlay registers accessed via MMIO.
1412  * Those loaded via the overlay register page are defined in i830_video.c.
1413  */
1414 #define OVADD                   0x30000
1415
1416 #define DOVSTA                  0x30008
1417 #define OC_BUF                  (0x3<<20)
1418
1419 #define OGAMC5                  0x30010
1420 #define OGAMC4                  0x30014
1421 #define OGAMC3                  0x30018
1422 #define OGAMC2                  0x3001c
1423 #define OGAMC1                  0x30020
1424 #define OGAMC0                  0x30024
1425 /*
1426  * Palette registers
1427  */
1428 #define PALETTE_A               0x0a000
1429 #define PALETTE_B               0x0a800
1430
1431 #define IS_I830(dev) ((dev)->pci_device == 0x3577)
1432 #define IS_845G(dev) ((dev)->pci_device == 0x2562)
1433 #define IS_I85X(dev) ((dev)->pci_device == 0x3582)
1434 #define IS_I855(dev) ((dev)->pci_device == 0x3582)
1435 #define IS_I865G(dev) ((dev)->pci_device == 0x2572)
1436
1437 #define IS_I915G(dev) ((dev)->pci_device == 0x2582 || (dev)->pci_device == 0x258a)
1438 #define IS_I915GM(dev) ((dev)->pci_device == 0x2592)
1439 #define IS_I945G(dev) ((dev)->pci_device == 0x2772)
1440 #define IS_I945GM(dev) ((dev)->pci_device == 0x27A2 ||\
1441                         (dev)->pci_device == 0x27AE)
1442 #define IS_I965G(dev) ((dev)->pci_device == 0x2972 || \
1443                        (dev)->pci_device == 0x2982 || \
1444                        (dev)->pci_device == 0x2992 || \
1445                        (dev)->pci_device == 0x29A2 || \
1446                        (dev)->pci_device == 0x2A02 || \
1447                        (dev)->pci_device == 0x2A12 || \
1448                        (dev)->pci_device == 0x2A42)
1449
1450 #define IS_I965GM(dev) ((dev)->pci_device == 0x2A02)
1451
1452 #define IS_IGD_GM(dev) ((dev)->pci_device == 0x2A42)
1453
1454 #define IS_G33(dev)    ((dev)->pci_device == 0x29C2 ||  \
1455                         (dev)->pci_device == 0x29B2 ||  \
1456                         (dev)->pci_device == 0x29D2)
1457
1458 #define IS_I9XX(dev) (IS_I915G(dev) || IS_I915GM(dev) || IS_I945G(dev) || \
1459                       IS_I945GM(dev) || IS_I965G(dev) || IS_G33(dev))
1460
1461 #define IS_MOBILE(dev) (IS_I830(dev) || IS_I85X(dev) || IS_I915GM(dev) || \
1462                         IS_I945GM(dev) || IS_I965GM(dev) || IS_IGD_GM(dev))
1463
1464 #define I915_NEED_GFX_HWS(dev) (IS_G33(dev) || IS_IGD_GM(dev))
1465
1466 #define PRIMARY_RINGBUFFER_SIZE         (128*1024)
1467
1468 #endif