i915: Make sure extensions that require TTM actually work.
[mesa.git] / src / mesa / drivers / dri / i915 / server / intel.h
1 #ifndef _INTEL_H_
2 #define _INTEL_H_
3
4 #include "xf86drm.h" /* drm_handle_t, etc */
5
6 /* Intel */
7 #ifndef PCI_CHIP_I810
8 #define PCI_CHIP_I810 0x7121
9 #define PCI_CHIP_I810_DC100 0x7123
10 #define PCI_CHIP_I810_E 0x7125
11 #define PCI_CHIP_I815 0x1132
12 #define PCI_CHIP_I810_BRIDGE 0x7120
13 #define PCI_CHIP_I810_DC100_BRIDGE 0x7122
14 #define PCI_CHIP_I810_E_BRIDGE 0x7124
15 #define PCI_CHIP_I815_BRIDGE 0x1130
16 #endif
17
18 #define PCI_CHIP_845_G 0x2562
19 #define PCI_CHIP_I830_M 0x3577
20
21 #ifndef PCI_CHIP_I855_GM
22 #define PCI_CHIP_I855_GM 0x3582
23 #define PCI_CHIP_I855_GM_BRIDGE 0x3580
24 #endif
25
26 #ifndef PCI_CHIP_I865_G
27 #define PCI_CHIP_I865_G 0x2572
28 #define PCI_CHIP_I865_G_BRIDGE 0x2570
29 #endif
30
31 #ifndef PCI_CHIP_I915_G
32 #define PCI_CHIP_I915_G 0x2582
33 #define PCI_CHIP_I915_G_BRIDGE 0x2580
34 #endif
35
36 #ifndef PCI_CHIP_I915_GM
37 #define PCI_CHIP_I915_GM 0x2592
38 #define PCI_CHIP_I915_GM_BRIDGE 0x2590
39 #endif
40
41 #ifndef PCI_CHIP_E7221_G
42 #define PCI_CHIP_E7221_G 0x258A
43 /* Same as I915_G_BRIDGE */
44 #define PCI_CHIP_E7221_G_BRIDGE 0x2580
45 #endif
46
47 #ifndef PCI_CHIP_I945_G
48 #define PCI_CHIP_I945_G 0x2772
49 #define PCI_CHIP_I945_G_BRIDGE 0x2770
50 #endif
51
52 #ifndef PCI_CHIP_I945_GM
53 #define PCI_CHIP_I945_GM 0x27A2
54 #define PCI_CHIP_I945_GM_BRIDGE 0x27A0
55 #endif
56
57 #define IS_I810(pI810) (pI810->Chipset == PCI_CHIP_I810 || \
58 pI810->Chipset == PCI_CHIP_I810_DC100 || \
59 pI810->Chipset == PCI_CHIP_I810_E)
60 #define IS_I815(pI810) (pI810->Chipset == PCI_CHIP_I815)
61 #define IS_I830(pI810) (pI810->Chipset == PCI_CHIP_I830_M)
62 #define IS_845G(pI810) (pI810->Chipset == PCI_CHIP_845_G)
63 #define IS_I85X(pI810) (pI810->Chipset == PCI_CHIP_I855_GM)
64 #define IS_I852(pI810) (pI810->Chipset == PCI_CHIP_I855_GM && (pI810->variant == I852_GM || pI810->variant == I852_GME))
65 #define IS_I855(pI810) (pI810->Chipset == PCI_CHIP_I855_GM && (pI810->variant == I855_GM || pI810->variant == I855_GME))
66 #define IS_I865G(pI810) (pI810->Chipset == PCI_CHIP_I865_G)
67
68 #define IS_I915G(pI810) (pI810->Chipset == PCI_CHIP_I915_G || pI810->Chipset == PCI_CHIP_E7221_G)
69 #define IS_I915GM(pI810) (pI810->Chipset == PCI_CHIP_I915_GM)
70 #define IS_I945G(pI810) (pI810->Chipset == PCI_CHIP_I945_G)
71 #define IS_I945GM(pI810) (pI810->Chipset == PCI_CHIP_I945_GM)
72 #define IS_I9XX(pI810) (IS_I915G(pI810) || IS_I915GM(pI810) || IS_I945G(pI810) || IS_I945GM(pI810))
73
74 #define IS_MOBILE(pI810) (IS_I830(pI810) || IS_I85X(pI810) || IS_I915GM(pI810) || IS_I945GM(pI810))
75
76 #define I830_GMCH_CTRL 0x52
77
78 #define I830_GMCH_MEM_MASK 0x1
79 #define I830_GMCH_MEM_64M 0x1
80 #define I830_GMCH_MEM_128M 0
81
82 #define I830_GMCH_GMS_MASK 0x70
83 #define I830_GMCH_GMS_DISABLED 0x00
84 #define I830_GMCH_GMS_LOCAL 0x10
85 #define I830_GMCH_GMS_STOLEN_512 0x20
86 #define I830_GMCH_GMS_STOLEN_1024 0x30
87 #define I830_GMCH_GMS_STOLEN_8192 0x40
88
89 #define I855_GMCH_GMS_MASK (0x7 << 4)
90 #define I855_GMCH_GMS_DISABLED 0x00
91 #define I855_GMCH_GMS_STOLEN_1M (0x1 << 4)
92 #define I855_GMCH_GMS_STOLEN_4M (0x2 << 4)
93 #define I855_GMCH_GMS_STOLEN_8M (0x3 << 4)
94 #define I855_GMCH_GMS_STOLEN_16M (0x4 << 4)
95 #define I855_GMCH_GMS_STOLEN_32M (0x5 << 4)
96 #define I915G_GMCH_GMS_STOLEN_48M (0x6 << 4)
97 #define I915G_GMCH_GMS_STOLEN_64M (0x7 << 4)
98
99 typedef unsigned char Bool;
100 #define TRUE 1
101 #define FALSE 0
102
103 #define PIPE_NONE 0<<0
104 #define PIPE_CRT 1<<0
105 #define PIPE_TV 1<<1
106 #define PIPE_DFP 1<<2
107 #define PIPE_LFP 1<<3
108 #define PIPE_CRT2 1<<4
109 #define PIPE_TV2 1<<5
110 #define PIPE_DFP2 1<<6
111 #define PIPE_LFP2 1<<7
112
113 typedef struct _I830MemPool *I830MemPoolPtr;
114 typedef struct _I830MemRange *I830MemRangePtr;
115 typedef struct _I830MemRange {
116 long Start;
117 long End;
118 long Size;
119 unsigned long Physical;
120 unsigned long Offset; /* Offset of AGP-allocated portion */
121 unsigned long Alignment;
122 drm_handle_t Key;
123 unsigned long Pitch; // add pitch
124 I830MemPoolPtr Pool;
125 } I830MemRange;
126
127 typedef struct _I830MemPool {
128 I830MemRange Total;
129 I830MemRange Free;
130 I830MemRange Fixed;
131 I830MemRange Allocated;
132 } I830MemPool;
133
134 typedef struct {
135 int tail_mask;
136 I830MemRange mem;
137 unsigned char *virtual_start;
138 int head;
139 int tail;
140 int space;
141 } I830RingBuffer;
142
143 typedef struct _I830Rec {
144 unsigned char *MMIOBase;
145 unsigned char *FbBase;
146 int cpp;
147 uint32_t aper_size;
148 unsigned int bios_version;
149
150 /* These are set in PreInit and never changed. */
151 long FbMapSize;
152 long TotalVideoRam;
153 I830MemRange StolenMemory; /* pre-allocated memory */
154 long BIOSMemorySize; /* min stolen pool size */
155 int BIOSMemSizeLoc;
156
157 /* These change according to what has been allocated. */
158 long FreeMemory;
159 I830MemRange MemoryAperture;
160 I830MemPool StolenPool;
161 long allocatedMemory;
162
163 /* Regions allocated either from the above pools, or from agpgart. */
164 /* for single and dual head configurations */
165 I830MemRange FrontBuffer;
166 I830MemRange FrontBuffer2;
167 I830MemRange Scratch;
168 I830MemRange Scratch2;
169
170 I830RingBuffer *LpRing;
171
172 I830MemRange BackBuffer;
173 I830MemRange DepthBuffer;
174 I830MemRange TexMem;
175 int TexGranularity;
176 I830MemRange ContextMem;
177 int drmMinor;
178 Bool have3DWindows;
179
180 Bool NeedRingBufferLow;
181 Bool allowPageFlip;
182 Bool disableTiling;
183
184 int Chipset;
185 unsigned long LinearAddr;
186 unsigned long MMIOAddr;
187
188 drmSize registerSize; /**< \brief MMIO register map size */
189 drm_handle_t registerHandle; /**< \brief MMIO register map handle */
190 // IOADDRESS ioBase;
191 int irq; /**< \brief IRQ number */
192 int GttBound;
193
194 drm_handle_t ring_map;
195 unsigned int Fence[8];
196
197 } I830Rec;
198
199 /*
200 * 12288 is set as the maximum, chosen because it is enough for
201 * 1920x1440@32bpp with a 2048 pixel line pitch with some to spare.
202 */
203 #define I830_MAXIMUM_VBIOS_MEM 12288
204 #define I830_DEFAULT_VIDEOMEM_2D (MB(32) / 1024)
205 #define I830_DEFAULT_VIDEOMEM_3D (MB(64) / 1024)
206
207 /* Flags for memory allocation function */
208 #define FROM_ANYWHERE 0x00000000
209 #define FROM_POOL_ONLY 0x00000001
210 #define FROM_NEW_ONLY 0x00000002
211 #define FROM_MASK 0x0000000f
212
213 #define ALLOCATE_AT_TOP 0x00000010
214 #define ALLOCATE_AT_BOTTOM 0x00000020
215 #define FORCE_GAPS 0x00000040
216
217 #define NEED_PHYSICAL_ADDR 0x00000100
218 #define ALIGN_BOTH_ENDS 0x00000200
219 #define FORCE_LOW 0x00000400
220
221 #define ALLOC_NO_TILING 0x00001000
222 #define ALLOC_INITIAL 0x00002000
223
224 #define ALLOCATE_DRY_RUN 0x80000000
225
226 /* Chipset registers for VIDEO BIOS memory RW access */
227 #define _855_DRAM_RW_CONTROL 0x58
228 #define _845_DRAM_RW_CONTROL 0x90
229 #define DRAM_WRITE 0x33330000
230
231 #define KB(x) ((x) * 1024)
232 #define MB(x) ((x) * KB(1024))
233
234 #define GTT_PAGE_SIZE KB(4)
235 #define ROUND_TO(x, y) (((x) + (y) - 1) / (y) * (y))
236 #define ROUND_DOWN_TO(x, y) ((x) / (y) * (y))
237 #define ROUND_TO_PAGE(x) ROUND_TO((x), GTT_PAGE_SIZE)
238 #define ROUND_TO_MB(x) ROUND_TO((x), MB(1))
239 #define PRIMARY_RINGBUFFER_SIZE KB(128)
240
241
242 /* Ring buffer registers, p277, overview p19
243 */
244 #define LP_RING 0x2030
245 #define HP_RING 0x2040
246
247 #define RING_TAIL 0x00
248 #define TAIL_ADDR 0x000FFFF8
249 #define I830_TAIL_MASK 0x001FFFF8
250
251 #define RING_HEAD 0x04
252 #define HEAD_WRAP_COUNT 0xFFE00000
253 #define HEAD_WRAP_ONE 0x00200000
254 #define HEAD_ADDR 0x001FFFFC
255 #define I830_HEAD_MASK 0x001FFFFC
256
257 #define RING_START 0x08
258 #define START_ADDR 0x03FFFFF8
259 #define I830_RING_START_MASK 0xFFFFF000
260
261 #define RING_LEN 0x0C
262 #define RING_NR_PAGES 0x001FF000
263 #define I830_RING_NR_PAGES 0x001FF000
264 #define RING_REPORT_MASK 0x00000006
265 #define RING_REPORT_64K 0x00000002
266 #define RING_REPORT_128K 0x00000004
267 #define RING_NO_REPORT 0x00000000
268 #define RING_VALID_MASK 0x00000001
269 #define RING_VALID 0x00000001
270 #define RING_INVALID 0x00000000
271
272
273 /* Fence/Tiling ranges [0..7]
274 */
275 #define FENCE 0x2000
276 #define FENCE_NR 8
277
278 #define I915G_FENCE_START_MASK 0x0ff00000
279
280 #define I830_FENCE_START_MASK 0x07f80000
281
282 #define FENCE_START_MASK 0x03F80000
283 #define FENCE_X_MAJOR 0x00000000
284 #define FENCE_Y_MAJOR 0x00001000
285 #define FENCE_SIZE_MASK 0x00000700
286 #define FENCE_SIZE_512K 0x00000000
287 #define FENCE_SIZE_1M 0x00000100
288 #define FENCE_SIZE_2M 0x00000200
289 #define FENCE_SIZE_4M 0x00000300
290 #define FENCE_SIZE_8M 0x00000400
291 #define FENCE_SIZE_16M 0x00000500
292 #define FENCE_SIZE_32M 0x00000600
293 #define FENCE_SIZE_64M 0x00000700
294 #define I915G_FENCE_SIZE_1M 0x00000000
295 #define I915G_FENCE_SIZE_2M 0x00000100
296 #define I915G_FENCE_SIZE_4M 0x00000200
297 #define I915G_FENCE_SIZE_8M 0x00000300
298 #define I915G_FENCE_SIZE_16M 0x00000400
299 #define I915G_FENCE_SIZE_32M 0x00000500
300 #define I915G_FENCE_SIZE_64M 0x00000600
301 #define I915G_FENCE_SIZE_128M 0x00000700
302 #define FENCE_PITCH_1 0x00000000
303 #define FENCE_PITCH_2 0x00000010
304 #define FENCE_PITCH_4 0x00000020
305 #define FENCE_PITCH_8 0x00000030
306 #define FENCE_PITCH_16 0x00000040
307 #define FENCE_PITCH_32 0x00000050
308 #define FENCE_PITCH_64 0x00000060
309 #define FENCE_VALID 0x00000001
310
311 #include <mmio.h>
312
313 # define MMIO_IN8(base, offset) \
314 *(volatile unsigned char *)(((unsigned char*)(base)) + (offset))
315 # define MMIO_IN32(base, offset) \
316 read_MMIO_LE32(base, offset)
317 # define MMIO_OUT8(base, offset, val) \
318 *(volatile unsigned char *)(((unsigned char*)(base)) + (offset)) = (val)
319 # define MMIO_OUT32(base, offset, val) \
320 *(volatile unsigned int *)(void *)(((unsigned char*)(base)) + (offset)) = CPU_TO_LE32(val)
321
322
323 /* Memory mapped register access macros */
324 #define INREG8(addr) MMIO_IN8(MMIO, addr)
325 #define INREG(addr) MMIO_IN32(MMIO, addr)
326 #define OUTREG8(addr, val) MMIO_OUT8(MMIO, addr, val)
327 #define OUTREG(addr, val) MMIO_OUT32(MMIO, addr, val)
328
329 #define DSPABASE 0x70184
330
331 #endif