intel_extreme.h revision e2e5daf2
1/*
2 * Copyright 2006-2015, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 *		Axel D��rfler, axeld@pinc-software.de
7 *		Alexander von Gluck, kallisti5@unixzen.com
8 */
9#ifndef INTEL_EXTREME_H
10#define INTEL_EXTREME_H
11
12
13#include "lock.h"
14
15#include <Accelerant.h>
16#include <Drivers.h>
17#include <PCI.h>
18
19#include <edid.h>
20
21
22#define VENDOR_ID_INTEL			0x8086
23
24#define INTEL_FAMILY_MASK	0x00ff0000
25#define INTEL_GROUP_MASK	0x00fffff0
26#define INTEL_MODEL_MASK	0x00ffffff
27// families
28#define INTEL_FAMILY_7xx	0x00010000	// First Gen
29#define INTEL_FAMILY_8xx	0x00020000	// Second Gen
30#define INTEL_FAMILY_9xx	0x00040000	// Third Gen +
31#define INTEL_FAMILY_SER5	0x00080000	// Intel5 Series
32#define INTEL_FAMILY_POVR	0x00100000	// PowerVR (uugh)
33#define INTEL_FAMILY_SOC0	0x00200000  // Atom SOC
34// groups
35#define INTEL_GROUP_83x		(INTEL_FAMILY_8xx  | 0x0010)
36#define INTEL_GROUP_85x		(INTEL_FAMILY_8xx  | 0x0020)
37#define INTEL_GROUP_91x		(INTEL_FAMILY_9xx  | 0x0010)
38#define INTEL_GROUP_94x		(INTEL_FAMILY_9xx  | 0x0020)
39#define INTEL_GROUP_96x		(INTEL_FAMILY_9xx  | 0x0040)
40#define INTEL_GROUP_Gxx		(INTEL_FAMILY_9xx  | 0x0080)
41#define INTEL_GROUP_G4x		(INTEL_FAMILY_9xx  | 0x0100)
42#define INTEL_GROUP_IGD		(INTEL_FAMILY_9xx  | 0x0200)
43#define INTEL_GROUP_ILK		(INTEL_FAMILY_SER5 | 0x0010)  // IronLake
44#define INTEL_GROUP_SNB		(INTEL_FAMILY_SER5 | 0x0020)  // SandyBridge
45#define INTEL_GROUP_IVB		(INTEL_FAMILY_SER5 | 0x0040)  // IvyBridge
46#define INTEL_GROUP_HAS		(INTEL_FAMILY_SER5 | 0x0080)  // Haswell
47#define INTEL_GROUP_SLT		(INTEL_FAMILY_POVR | 0x0010)  // Saltwell
48#define INTEL_GROUP_FSM		(INTEL_FAMILY_POVR | 0x0020)  // Fu.Silvermont
49#define INTEL_GROUP_SLV		(INTEL_FAMILY_SOC0 | 0x0010)  // Silvermont
50#define INTEL_GROUP_AIR		(INTEL_FAMILY_SOC0 | 0x0020)  // Airmont
51#define INTEL_GROUP_GOL		(INTEL_FAMILY_SOC0 | 0x0040)  // Goldmont
52// models
53#define INTEL_TYPE_SERVER	0x0004
54#define INTEL_TYPE_MOBILE	0x0008
55#define INTEL_MODEL_915		(INTEL_GROUP_91x)
56#define INTEL_MODEL_915M	(INTEL_GROUP_91x | INTEL_TYPE_MOBILE)
57#define INTEL_MODEL_945		(INTEL_GROUP_94x)
58#define INTEL_MODEL_945M	(INTEL_GROUP_94x | INTEL_TYPE_MOBILE)
59#define INTEL_MODEL_965		(INTEL_GROUP_96x)
60#define INTEL_MODEL_965M	(INTEL_GROUP_96x | INTEL_TYPE_MOBILE)
61#define INTEL_MODEL_G33		(INTEL_GROUP_Gxx)
62#define INTEL_MODEL_G45		(INTEL_GROUP_G4x)
63#define INTEL_MODEL_GM45	(INTEL_GROUP_G4x | INTEL_TYPE_MOBILE)
64#define INTEL_MODEL_IGDG	(INTEL_GROUP_IGD)
65#define INTEL_MODEL_IGDGM	(INTEL_GROUP_IGD | INTEL_TYPE_MOBILE)
66#define INTEL_MODEL_ILKG	(INTEL_GROUP_ILK)
67#define INTEL_MODEL_ILKGM	(INTEL_GROUP_ILK | INTEL_TYPE_MOBILE)
68#define INTEL_MODEL_SNBG	(INTEL_GROUP_SNB)
69#define INTEL_MODEL_SNBGM	(INTEL_GROUP_SNB | INTEL_TYPE_MOBILE)
70#define INTEL_MODEL_SNBGS	(INTEL_GROUP_SNB | INTEL_TYPE_SERVER)
71#define INTEL_MODEL_IVBG	(INTEL_GROUP_IVB)
72#define INTEL_MODEL_IVBGM	(INTEL_GROUP_IVB | INTEL_TYPE_MOBILE)
73#define INTEL_MODEL_IVBGS	(INTEL_GROUP_IVB | INTEL_TYPE_SERVER)
74#define INTEL_MODEL_HAS		(INTEL_GROUP_HAS)
75#define INTEL_MODEL_HASM	(INTEL_GROUP_HAS | INTEL_TYPE_MOBILE)
76#define INTEL_MODEL_VLV		(INTEL_GROUP_SLV)
77#define INTEL_MODEL_VLVM	(INTEL_GROUP_SLV | INTEL_TYPE_MOBILE)
78
79// ValleyView MMIO offset
80#define VLV_DISPLAY_BASE		0x180000
81
82#define DEVICE_NAME				"intel_extreme"
83#define INTEL_ACCELERANT_NAME	"intel_extreme.accelerant"
84
85// We encode the register block into the value and extract/translate it when
86// actually accessing.
87#define REGISTER_BLOCK_COUNT				6
88#define REGISTER_BLOCK_SHIFT				24
89#define REGISTER_BLOCK_MASK					0xff000000
90#define REGISTER_REGISTER_MASK				0x00ffffff
91#define REGISTER_BLOCK(x) ((x & REGISTER_BLOCK_MASK) >> REGISTER_BLOCK_SHIFT)
92#define REGISTER_REGISTER(x) (x & REGISTER_REGISTER_MASK)
93
94#define REGS_FLAT							(0 << REGISTER_BLOCK_SHIFT)
95#define REGS_NORTH_SHARED					(1 << REGISTER_BLOCK_SHIFT)
96#define REGS_NORTH_PIPE_AND_PORT			(2 << REGISTER_BLOCK_SHIFT)
97#define REGS_NORTH_PLANE_CONTROL			(3 << REGISTER_BLOCK_SHIFT)
98#define REGS_SOUTH_SHARED					(4 << REGISTER_BLOCK_SHIFT)
99#define REGS_SOUTH_TRANSCODER_PORT			(5 << REGISTER_BLOCK_SHIFT)
100
101// register blocks for (G)MCH/ICH based platforms
102#define MCH_SHARED_REGISTER_BASE						0x00000
103#define MCH_PIPE_AND_PORT_REGISTER_BASE					0x60000
104#define MCH_PLANE_CONTROL_REGISTER_BASE					0x70000
105#define ICH_SHARED_REGISTER_BASE						0x00000
106#define ICH_PORT_REGISTER_BASE							0x60000
107
108// PCH - Platform Control Hub - Some hardware moves from a MCH/ICH based
109// setup to a PCH based one, that means anything that used to communicate via
110// (G)MCH registers needs to use different ones on PCH based platforms
111// (Ironlake, SandyBridge, IvyBridge, Some Haswell).
112#define PCH_NORTH_SHARED_REGISTER_BASE					0x40000
113#define PCH_NORTH_PIPE_AND_PORT_REGISTER_BASE			0x60000
114#define PCH_NORTH_PLANE_CONTROL_REGISTER_BASE			0x70000
115#define PCH_SOUTH_SHARED_REGISTER_BASE					0xc0000
116#define PCH_SOUTH_TRANSCODER_AND_PORT_REGISTER_BASE		0xe0000
117
118
119struct DeviceType {
120	uint32			type;
121
122	DeviceType(int t)
123	{
124		type = t;
125	}
126
127	DeviceType& operator=(int t)
128	{
129		type = t;
130		return *this;
131	}
132
133	bool InFamily(uint32 family) const
134	{
135		return (type & INTEL_FAMILY_MASK) == family;
136	}
137
138	bool InGroup(uint32 group) const
139	{
140		return (type & INTEL_GROUP_MASK) == group;
141	}
142
143	bool IsModel(uint32 model) const
144	{
145		return (type & INTEL_MODEL_MASK) == model;
146	}
147
148	bool IsMobile() const
149	{
150		return (type & INTEL_MODEL_MASK) == INTEL_TYPE_MOBILE;
151	}
152
153	bool SupportsHDMI() const
154	{
155		return InGroup(INTEL_GROUP_G4x) || InFamily(INTEL_FAMILY_SER5)
156			|| InFamily(INTEL_FAMILY_SOC0);
157	}
158
159	bool HasPlatformControlHub() const
160	{
161		return InFamily(INTEL_FAMILY_SER5);
162	}
163
164	int Generation() const
165	{
166		if (InFamily(INTEL_FAMILY_7xx))
167			return 1;
168		if (InFamily(INTEL_FAMILY_8xx))
169			return 2;
170		if (InGroup(INTEL_GROUP_91x) || InGroup(INTEL_GROUP_94x)
171				|| IsModel(INTEL_MODEL_G33))
172			return 3;
173		if (InFamily(INTEL_FAMILY_9xx))
174			return 4;
175		if (InGroup(INTEL_GROUP_ILK))
176			return 5;
177		if (InGroup(INTEL_GROUP_SNB))
178			return 6;
179		if (InFamily(INTEL_FAMILY_SER5) || InGroup(INTEL_GROUP_SLV))
180			return 7;
181
182		// TODO: Groups below here might need some tweaking
183		if (InGroup(INTEL_GROUP_AIR) || InGroup(INTEL_GROUP_GOL))
184			return 8;
185
186		// TODO: SkyLake, Broxton is gen 9
187
188		// Generation 0 means somethins is wrong :-)
189		return 0;
190	}
191};
192
193// info about PLL on graphics card
194struct pll_info {
195	uint32			reference_frequency;
196	uint32			max_frequency;
197	uint32			min_frequency;
198	uint32			divisor_register;
199};
200
201struct ring_buffer {
202	struct lock		lock;
203	uint32			register_base;
204	uint32			offset;
205	uint32			size;
206	uint32			position;
207	uint32			space_left;
208	uint8*			base;
209};
210
211struct overlay_registers;
212
213struct intel_shared_info {
214	area_id			mode_list_area;		// area containing display mode list
215	uint32			mode_count;
216
217	display_mode	current_mode;
218	uint32			bytes_per_row;
219	uint32			bits_per_pixel;
220	uint32			dpms_mode;
221
222	area_id			registers_area;			// area of memory mapped registers
223	uint32			register_blocks[REGISTER_BLOCK_COUNT];
224
225	uint8*			status_page;
226	phys_addr_t		physical_status_page;
227	uint8*			graphics_memory;
228	phys_addr_t		physical_graphics_memory;
229	uint32			graphics_memory_size;
230
231	addr_t			frame_buffer;
232	uint32			frame_buffer_offset;
233
234	bool			got_vbt;
235	bool			single_head_locked;
236
237	struct lock		accelerant_lock;
238	struct lock		engine_lock;
239
240	ring_buffer		primary_ring_buffer;
241
242	int32			overlay_channel_used;
243	bool			overlay_active;
244	uintptr_t		overlay_token;
245	phys_addr_t		physical_overlay_registers;
246	uint32			overlay_offset;
247
248	bool			hardware_cursor_enabled;
249	sem_id			vblank_sem;
250
251	uint8*			cursor_memory;
252	phys_addr_t		physical_cursor_memory;
253	uint32			cursor_buffer_offset;
254	uint32			cursor_format;
255	bool			cursor_visible;
256	uint16			cursor_hot_x;
257	uint16			cursor_hot_y;
258
259	DeviceType		device_type;
260	char			device_identifier[32];
261	struct pll_info	pll_info;
262
263	edid1_info		vesa_edid_info;
264	bool			has_vesa_edid_info;
265};
266
267//----------------- ioctl() interface ----------------
268
269// magic code for ioctls
270#define INTEL_PRIVATE_DATA_MAGIC		'itic'
271
272// list ioctls
273enum {
274	INTEL_GET_PRIVATE_DATA = B_DEVICE_OP_CODES_END + 1,
275
276	INTEL_GET_DEVICE_NAME,
277	INTEL_ALLOCATE_GRAPHICS_MEMORY,
278	INTEL_FREE_GRAPHICS_MEMORY
279};
280
281// retrieve the area_id of the kernel/accelerant shared info
282struct intel_get_private_data {
283	uint32	magic;				// magic number
284	area_id	shared_info_area;
285};
286
287// allocate graphics memory
288struct intel_allocate_graphics_memory {
289	uint32	magic;
290	uint32	size;
291	uint32	alignment;
292	uint32	flags;
293	addr_t	buffer_base;
294};
295
296// free graphics memory
297struct intel_free_graphics_memory {
298	uint32 	magic;
299	addr_t	buffer_base;
300};
301
302//----------------------------------------------------------
303// Register definitions, taken from X driver
304
305// PCI bridge memory management
306#define INTEL_GRAPHICS_MEMORY_CONTROL	0x52
307	// GGC - (G)MCH Graphics Control Register
308#define MEMORY_CONTROL_ENABLED			0x0004
309#define MEMORY_MASK						0x0001
310#define STOLEN_MEMORY_MASK				0x00f0
311#define i965_GTT_MASK					0x000e
312#define G33_GTT_MASK					0x0300
313#define G4X_GTT_MASK					0x0f00	// GGMS (GSM Memory Size) mask
314
315// models i830 and up
316#define i830_LOCAL_MEMORY_ONLY			0x10
317#define i830_STOLEN_512K				0x20
318#define i830_STOLEN_1M					0x30
319#define i830_STOLEN_8M					0x40
320#define i830_FRAME_BUFFER_64M			0x01
321#define i830_FRAME_BUFFER_128M			0x00
322
323// models i855 and up
324#define i855_STOLEN_MEMORY_1M			0x10
325#define i855_STOLEN_MEMORY_4M			0x20
326#define i855_STOLEN_MEMORY_8M			0x30
327#define i855_STOLEN_MEMORY_16M			0x40
328#define i855_STOLEN_MEMORY_32M			0x50
329#define i855_STOLEN_MEMORY_48M			0x60
330#define i855_STOLEN_MEMORY_64M			0x70
331#define i855_STOLEN_MEMORY_128M			0x80
332#define i855_STOLEN_MEMORY_256M			0x90
333
334#define G4X_STOLEN_MEMORY_96MB			0xa0	// GMS - Graphics Mode Select
335#define G4X_STOLEN_MEMORY_160MB			0xb0
336#define G4X_STOLEN_MEMORY_224MB			0xc0
337#define G4X_STOLEN_MEMORY_352MB			0xd0
338
339// SandyBridge (SNB)
340#define SNB_GRAPHICS_MEMORY_CONTROL		0x50
341
342#define SNB_STOLEN_MEMORY_MASK			0xf8
343#define SNB_STOLEN_MEMORY_32MB			(1 << 3)
344#define SNB_STOLEN_MEMORY_64MB			(2 << 3)
345#define SNB_STOLEN_MEMORY_96MB			(3 << 3)
346#define SNB_STOLEN_MEMORY_128MB			(4 << 3)
347#define SNB_STOLEN_MEMORY_160MB			(5 << 3)
348#define SNB_STOLEN_MEMORY_192MB			(6 << 3)
349#define SNB_STOLEN_MEMORY_224MB			(7 << 3)
350#define SNB_STOLEN_MEMORY_256MB			(8 << 3)
351#define SNB_STOLEN_MEMORY_288MB			(9 << 3)
352#define SNB_STOLEN_MEMORY_320MB			(10 << 3)
353#define SNB_STOLEN_MEMORY_352MB			(11 << 3)
354#define SNB_STOLEN_MEMORY_384MB			(12 << 3)
355#define SNB_STOLEN_MEMORY_416MB			(13 << 3)
356#define SNB_STOLEN_MEMORY_448MB			(14 << 3)
357#define SNB_STOLEN_MEMORY_480MB			(15 << 3)
358#define SNB_STOLEN_MEMORY_512MB			(16 << 3)
359
360#define SNB_GTT_SIZE_MASK				(3 << 8)
361#define SNB_GTT_SIZE_NONE				(0 << 8)
362#define SNB_GTT_SIZE_1MB				(1 << 8)
363#define SNB_GTT_SIZE_2MB				(2 << 8)
364
365// graphics page translation table
366#define INTEL_PAGE_TABLE_CONTROL		0x02020
367#define PAGE_TABLE_ENABLED				0x00000001
368#define INTEL_PAGE_TABLE_ERROR			0x02024
369#define INTEL_HARDWARE_STATUS_PAGE		0x02080
370#define i915_GTT_BASE					0x1c
371#define i830_GTT_BASE					0x10000	// (- 0x2ffff)
372#define i830_GTT_SIZE					0x20000
373#define i965_GTT_BASE					0x80000	// (- 0xfffff)
374#define i965_GTT_SIZE					0x80000
375#define i965_GTT_128K					(2 << 1)
376#define i965_GTT_256K					(1 << 1)
377#define i965_GTT_512K					(0 << 1)
378#define G33_GTT_1M						(1 << 8)
379#define G33_GTT_2M						(2 << 8)
380#define G4X_GTT_NONE					0x000	// GGMS - GSM Memory Size
381#define G4X_GTT_1M_NO_IVT				0x100	// no Intel Virtualization Tech.
382#define G4X_GTT_2M_NO_IVT				0x300
383#define G4X_GTT_2M_IVT					0x900	// with Intel Virt. Tech.
384#define G4X_GTT_3M_IVT					0xa00
385#define G4X_GTT_4M_IVT					0xb00
386
387
388#define GTT_ENTRY_VALID					0x01
389#define GTT_ENTRY_LOCAL_MEMORY			0x02
390#define GTT_PAGE_SHIFT					12
391
392
393// ring buffer
394#define INTEL_PRIMARY_RING_BUFFER		0x02030
395#define INTEL_SECONDARY_RING_BUFFER_0	0x02100
396#define INTEL_SECONDARY_RING_BUFFER_1	0x02110
397// offsets for the ring buffer base registers above
398#define RING_BUFFER_TAIL				0x0
399#define RING_BUFFER_HEAD				0x4
400#define RING_BUFFER_START				0x8
401#define RING_BUFFER_CONTROL				0xc
402#define INTEL_RING_BUFFER_SIZE_MASK		0x001ff000
403#define INTEL_RING_BUFFER_HEAD_MASK		0x001ffffc
404#define INTEL_RING_BUFFER_ENABLED		1
405
406// interrupts
407#define INTEL_INTERRUPT_ENABLED			0x020a0
408#define INTEL_INTERRUPT_IDENTITY		0x020a4
409#define INTEL_INTERRUPT_MASK			0x020a8
410#define INTEL_INTERRUPT_STATUS			0x020ac
411#define INTERRUPT_VBLANK_PIPEA			(1 << 7)
412#define INTERRUPT_VBLANK_PIPEB			(1 << 5)
413
414// PCH interrupts
415#define PCH_INTERRUPT_STATUS			0x44000
416#define PCH_INTERRUPT_MASK				0x44004
417#define PCH_INTERRUPT_IDENTITY			0x44008
418#define PCH_INTERRUPT_ENABLED			0x4400c
419#define PCH_INTERRUPT_VBLANK_PIPEA		(1 << 0)
420#define PCH_INTERRUPT_VBLANK_PIPEB		(1 << 5)
421#define PCH_INTERRUPT_VBLANK_PIPEC		(1 << 10)
422
423#define PCH_INTERRUPT_VBLANK_PIPEA_SNB		(1 << 7)
424#define PCH_INTERRUPT_VBLANK_PIPEB_SNB		(1 << 15)
425
426// display ports
427#define DISPLAY_MONITOR_PORT_ENABLED	(1UL << 31)
428#define DISPLAY_MONITOR_PIPE_B			(1UL << 30)
429#define DISPLAY_MONITOR_VGA_POLARITY	(1UL << 15)
430#define DISPLAY_MONITOR_MODE_MASK		(3UL << 10)
431#define DISPLAY_MONITOR_ON				0
432#define DISPLAY_MONITOR_SUSPEND			(1UL << 10)
433#define DISPLAY_MONITOR_STAND_BY		(2UL << 10)
434#define DISPLAY_MONITOR_OFF				(3UL << 10)
435#define DISPLAY_MONITOR_POLARITY_MASK	(3UL << 3)
436#define DISPLAY_MONITOR_POSITIVE_HSYNC	(1UL << 3)
437#define DISPLAY_MONITOR_POSITIVE_VSYNC	(2UL << 3)
438#define LVDS_POST2_RATE_SLOW			14 // PLL Divisors
439#define LVDS_POST2_RATE_FAST			7
440#define LVDS_CLKB_POWER_MASK			(3 << 4)
441#define LVDS_CLKB_POWER_UP				(3 << 4)
442#define LVDS_PORT_EN					(1 << 31)
443#define LVDS_A0A2_CLKA_POWER_UP			(3 << 8)
444#define LVDS_PIPEB_SELECT				(1 << 30)
445#define LVDS_B0B3PAIRS_POWER_UP			(3 << 2)
446#define LVDS_PLL_MODE_LVDS				(2 << 26)
447#define LVDS_18BIT_DITHER				(1 << 25)
448
449// PLL flags
450#define DISPLAY_PLL_ENABLED				(1UL << 31)
451#define DISPLAY_PLL_2X_CLOCK			(1UL << 30)
452#define DISPLAY_PLL_SYNC_LOCK_ENABLED	(1UL << 29)
453#define DISPLAY_PLL_NO_VGA_CONTROL		(1UL << 28)
454#define DISPLAY_PLL_MODE_ANALOG			(1UL << 26)
455#define DISPLAY_PLL_DIVIDE_HIGH			(1UL << 24)
456#define DISPLAY_PLL_DIVIDE_4X			(1UL << 23)
457#define DISPLAY_PLL_POST1_DIVIDE_2		(1UL << 21)
458#define DISPLAY_PLL_POST1_DIVISOR_MASK	0x001f0000
459#define DISPLAY_PLL_9xx_POST1_DIVISOR_MASK	0x00ff0000
460#define DISPLAY_PLL_IGD_POST1_DIVISOR_MASK  0x00ff8000
461#define DISPLAY_PLL_POST1_DIVISOR_SHIFT	16
462#define DISPLAY_PLL_IGD_POST1_DIVISOR_SHIFT	15
463#define DISPLAY_PLL_DIVISOR_1			(1UL << 8)
464#define DISPLAY_PLL_N_DIVISOR_MASK		0x001f0000
465#define DISPLAY_PLL_IGD_N_DIVISOR_MASK	0x00ff0000
466#define DISPLAY_PLL_M1_DIVISOR_MASK		0x00001f00
467#define DISPLAY_PLL_M2_DIVISOR_MASK		0x0000001f
468#define DISPLAY_PLL_IGD_M2_DIVISOR_MASK	0x000000ff
469#define DISPLAY_PLL_N_DIVISOR_SHIFT		16
470#define DISPLAY_PLL_M1_DIVISOR_SHIFT	8
471#define DISPLAY_PLL_M2_DIVISOR_SHIFT	0
472#define DISPLAY_PLL_PULSE_PHASE_SHIFT	9
473
474// display
475#define INTEL_DISPLAY_A_HTOTAL			(0x0000 | REGS_SOUTH_TRANSCODER_PORT)
476#define INTEL_DISPLAY_A_HBLANK			(0x0004 | REGS_SOUTH_TRANSCODER_PORT)
477#define INTEL_DISPLAY_A_HSYNC			(0x0008 | REGS_SOUTH_TRANSCODER_PORT)
478#define INTEL_DISPLAY_A_VTOTAL			(0x000c | REGS_SOUTH_TRANSCODER_PORT)
479#define INTEL_DISPLAY_A_VBLANK			(0x0010 | REGS_SOUTH_TRANSCODER_PORT)
480#define INTEL_DISPLAY_A_VSYNC			(0x0014 | REGS_SOUTH_TRANSCODER_PORT)
481#define INTEL_DISPLAY_B_HTOTAL			(0x1000 | REGS_SOUTH_TRANSCODER_PORT)
482#define INTEL_DISPLAY_B_HBLANK			(0x1004 | REGS_SOUTH_TRANSCODER_PORT)
483#define INTEL_DISPLAY_B_HSYNC			(0x1008 | REGS_SOUTH_TRANSCODER_PORT)
484#define INTEL_DISPLAY_B_VTOTAL			(0x100c | REGS_SOUTH_TRANSCODER_PORT)
485#define INTEL_DISPLAY_B_VBLANK			(0x1010 | REGS_SOUTH_TRANSCODER_PORT)
486#define INTEL_DISPLAY_B_VSYNC			(0x1014 | REGS_SOUTH_TRANSCODER_PORT)
487
488#define INTEL_DISPLAY_A_IMAGE_SIZE		(0x001c | REGS_NORTH_PIPE_AND_PORT)
489#define INTEL_DISPLAY_B_IMAGE_SIZE		(0x101c | REGS_NORTH_PIPE_AND_PORT)
490
491#define INTEL_ANALOG_PORT				(0x1100 | REGS_SOUTH_TRANSCODER_PORT)
492#define INTEL_DIGITAL_PORT_A			(0x1120 | REGS_SOUTH_TRANSCODER_PORT)
493#define INTEL_DIGITAL_PORT_B			(0x1140 | REGS_SOUTH_TRANSCODER_PORT)
494#define INTEL_DIGITAL_PORT_C			(0x1160 | REGS_SOUTH_TRANSCODER_PORT)
495#define INTEL_DIGITAL_LVDS_PORT			(0x1180 | REGS_SOUTH_TRANSCODER_PORT)
496
497#define INTEL_HDMI_PORT_B				(0x1140 | REGS_SOUTH_TRANSCODER_PORT)
498#define INTEL_HDMI_PORT_C				(0x1160 | REGS_SOUTH_TRANSCODER_PORT)
499
500#define PCH_HDMI_PORT_B					(0x1140 | REGS_SOUTH_TRANSCODER_PORT)
501#define PCH_HDMI_PORT_C					(0x1150 | REGS_SOUTH_TRANSCODER_PORT)
502#define PCH_HDMI_PORT_D					(0x1160 | REGS_SOUTH_TRANSCODER_PORT)
503
504#define GEN4_HDMI_PORT_B				(0x1140 | REGS_NORTH_PIPE_AND_PORT)
505#define GEN4_HDMI_PORT_C				(0x1160 | REGS_NORTH_PIPE_AND_PORT)
506#define CHV_HDMI_PORT_D					(0x116C | REGS_NORTH_PIPE_AND_PORT)
507
508#define INTEL_DISPLAY_PORT_A			(0x4000 | REGS_NORTH_PIPE_AND_PORT)
509#define INTEL_DISPLAY_PORT_B			(0x4100 | REGS_NORTH_PIPE_AND_PORT)
510#define INTEL_DISPLAY_PORT_C			(0x4200 | REGS_NORTH_PIPE_AND_PORT)
511#define INTEL_DISPLAY_PORT_D			(0x4300 | REGS_NORTH_PIPE_AND_PORT)
512
513// valid for both DVI/HDMI and DisplayPort
514#define PORT_DETECTED					(1 << 2)
515
516// planes
517#define INTEL_PIPE_BASE_REGISTER		(0x0000 | REGS_NORTH_PLANE_CONTROL)
518#define INTEL_PIPE_ENABLED				(1UL << 31)
519#define INTEL_PIPE_CONTROL				0x0008
520#define INTEL_PIPE_STATUS				0x0024
521#define INTEL_PIPE_OFFSET				0x1000
522#define INTEL_DISPLAY_A_PIPE_CONTROL	(0x0008	| REGS_NORTH_PLANE_CONTROL)
523#define INTEL_DISPLAY_B_PIPE_CONTROL	(0x1008 | REGS_NORTH_PLANE_CONTROL)
524#define INTEL_DISPLAY_A_PIPE_STATUS		(0x0024 | REGS_NORTH_PLANE_CONTROL)
525#define INTEL_DISPLAY_B_PIPE_STATUS		(0x1024 | REGS_NORTH_PLANE_CONTROL)
526
527#define DISPLAY_PIPE_VBLANK_ENABLED		(1UL << 17)
528#define DISPLAY_PIPE_VBLANK_STATUS		(1UL << 1)
529
530#define INTEL_DISPLAY_A_CONTROL			(0x0180 | REGS_NORTH_PLANE_CONTROL)
531#define INTEL_DISPLAY_A_BASE			(0x0184 | REGS_NORTH_PLANE_CONTROL)
532#define INTEL_DISPLAY_A_BYTES_PER_ROW	(0x0188 | REGS_NORTH_PLANE_CONTROL)
533#define INTEL_DISPLAY_A_POS				(0x018c | REGS_NORTH_PLANE_CONTROL)
534	// reserved on A
535#define INTEL_DISPLAY_A_PIPE_SIZE		(0x0190 | REGS_NORTH_PLANE_CONTROL)
536#define INTEL_DISPLAY_A_SURFACE			(0x019c | REGS_NORTH_PLANE_CONTROL)
537	// i965 and up only
538
539#define INTEL_DISPLAY_B_CONTROL			(0x1180 | REGS_NORTH_PLANE_CONTROL)
540#define INTEL_DISPLAY_B_BASE			(0x1184 | REGS_NORTH_PLANE_CONTROL)
541#define INTEL_DISPLAY_B_BYTES_PER_ROW	(0x1188 | REGS_NORTH_PLANE_CONTROL)
542#define INTEL_DISPLAY_B_POS				(0x118c | REGS_NORTH_PLANE_CONTROL)
543#define INTEL_DISPLAY_B_PIPE_SIZE		(0x1190 | REGS_NORTH_PLANE_CONTROL)
544#define INTEL_DISPLAY_B_SURFACE			(0x119c | REGS_NORTH_PLANE_CONTROL)
545	// i965 and up only
546
547#define DISPLAY_CONTROL_ENABLED			(1UL << 31)
548#define DISPLAY_CONTROL_GAMMA			(1UL << 30)
549#define DISPLAY_CONTROL_COLOR_MASK		(0x0fUL << 26)
550#define DISPLAY_CONTROL_CMAP8			(2UL << 26)
551#define DISPLAY_CONTROL_RGB15			(4UL << 26)
552#define DISPLAY_CONTROL_RGB16			(5UL << 26)
553#define DISPLAY_CONTROL_RGB32			(6UL << 26)
554
555// cursors
556#define INTEL_CURSOR_CONTROL			(0x0080 | REGS_NORTH_PLANE_CONTROL)
557#define INTEL_CURSOR_BASE				(0x0084 | REGS_NORTH_PLANE_CONTROL)
558#define INTEL_CURSOR_POSITION			(0x0088 | REGS_NORTH_PLANE_CONTROL)
559#define INTEL_CURSOR_PALETTE			(0x0090 | REGS_NORTH_PLANE_CONTROL)
560	// (- 0x009f)
561#define INTEL_CURSOR_SIZE				(0x00a0 | REGS_NORTH_PLANE_CONTROL)
562#define CURSOR_ENABLED					(1UL << 31)
563#define CURSOR_FORMAT_2_COLORS			(0UL << 24)
564#define CURSOR_FORMAT_3_COLORS			(1UL << 24)
565#define CURSOR_FORMAT_4_COLORS			(2UL << 24)
566#define CURSOR_FORMAT_ARGB				(4UL << 24)
567#define CURSOR_FORMAT_XRGB				(5UL << 24)
568#define CURSOR_POSITION_NEGATIVE		0x8000
569#define CURSOR_POSITION_MASK			0x3fff
570
571// palette registers
572#define INTEL_DISPLAY_A_PALETTE			(0xa000 | REGS_NORTH_SHARED)
573#define INTEL_DISPLAY_B_PALETTE			(0xa800 | REGS_NORTH_SHARED)
574
575// PLL registers
576#define INTEL_DISPLAY_A_PLL				(0x6014 | REGS_SOUTH_SHARED)
577#define INTEL_DISPLAY_B_PLL				(0x6018 | REGS_SOUTH_SHARED)
578#define CHV_DISPLAY_C_PLL				(0x6030 | REGS_SOUTH_SHARED)
579
580#define INTEL_DISPLAY_A_PLL_MULTIPLIER_DIVISOR	(INTEL_DISPLAY_A_PLL + 0x8)
581#define INTEL_DISPLAY_B_PLL_MULTIPLIER_DIVISOR	(INTEL_DISPLAY_B_PLL + 0x8)
582#define CHV_DISPLAY_C_PLL_MULTIPLIER_DIVISOR	(CHV_DISPLAY_C_PLL + 0xc)
583
584#define INTEL_DISPLAY_A_PLL_DIVISOR_0	(0x6040 | REGS_SOUTH_SHARED)
585#define INTEL_DISPLAY_A_PLL_DIVISOR_1	(0x6044 | REGS_SOUTH_SHARED)
586#define INTEL_DISPLAY_B_PLL_DIVISOR_0	(0x6048 | REGS_SOUTH_SHARED)
587#define INTEL_DISPLAY_B_PLL_DIVISOR_1	(0x604c | REGS_SOUTH_SHARED)
588
589// i2c
590#define INTEL_I2C_IO_A					(0x5010 | REGS_SOUTH_SHARED)
591#define INTEL_I2C_IO_B					(0x5014 | REGS_SOUTH_SHARED)
592#define INTEL_I2C_IO_C					(0x5018 | REGS_SOUTH_SHARED)
593#define INTEL_I2C_IO_D					(0x501c | REGS_SOUTH_SHARED)
594#define INTEL_I2C_IO_E					(0x5020 | REGS_SOUTH_SHARED)
595#define INTEL_I2C_IO_F					(0x5024 | REGS_SOUTH_SHARED)
596#define INTEL_I2C_IO_G					(0x5028 | REGS_SOUTH_SHARED)
597#define INTEL_I2C_IO_H					(0x502c | REGS_SOUTH_SHARED)
598
599#define I2C_CLOCK_DIRECTION_MASK		(1 << 0)
600#define I2C_CLOCK_DIRECTION_OUT			(1 << 1)
601#define I2C_CLOCK_VALUE_MASK			(1 << 2)
602#define I2C_CLOCK_VALUE_OUT				(1 << 3)
603#define I2C_CLOCK_VALUE_IN				(1 << 4)
604#define I2C_DATA_DIRECTION_MASK			(1 << 8)
605#define I2C_DATA_DIRECTION_OUT			(1 << 9)
606#define I2C_DATA_VALUE_MASK				(1 << 10)
607#define I2C_DATA_VALUE_OUT				(1 << 11)
608#define I2C_DATA_VALUE_IN				(1 << 12)
609#define I2C_RESERVED					((1 << 13) | (1 << 5))
610
611// TODO: on IronLake this is in the north shared block at 0x41000
612#define INTEL_VGA_DISPLAY_CONTROL		(0x1400 | REGS_NORTH_PLANE_CONTROL)
613#define VGA_DISPLAY_DISABLED			(1UL << 31)
614
615// LVDS panel
616#define INTEL_PANEL_STATUS				0x61200
617#define PANEL_STATUS_POWER_ON			(1UL << 31)
618#define INTEL_PANEL_CONTROL				0x61204
619#define PANEL_CONTROL_POWER_TARGET_ON	(1UL << 0)
620#define INTEL_PANEL_FIT_CONTROL			0x61230
621#define INTEL_PANEL_FIT_RATIOS			0x61234
622
623// LVDS on IronLake and up
624#define PCH_PANEL_CONTROL				0xc7200
625#define PCH_PANEL_STATUS				0xc7204
626#define PANEL_REGISTER_UNLOCK			(0xabcd << 16)
627#define PCH_LVDS_DETECTED				(1 << 1)
628
629// ring buffer commands
630
631#define COMMAND_NOOP					0x00
632#define COMMAND_WAIT_FOR_EVENT			(0x03 << 23)
633#define COMMAND_WAIT_FOR_OVERLAY_FLIP	(1 << 16)
634
635#define COMMAND_FLUSH					(0x04 << 23)
636
637// overlay flip
638#define COMMAND_OVERLAY_FLIP			(0x11 << 23)
639#define COMMAND_OVERLAY_CONTINUE		(0 << 21)
640#define COMMAND_OVERLAY_ON				(1 << 21)
641#define COMMAND_OVERLAY_OFF				(2 << 21)
642#define OVERLAY_UPDATE_COEFFICIENTS		0x1
643
644// 2D acceleration
645#define XY_COMMAND_SOURCE_BLIT			0x54c00006
646#define XY_COMMAND_COLOR_BLIT			0x54000004
647#define XY_COMMAND_SETUP_MONO_PATTERN	0x44400007
648#define XY_COMMAND_SCANLINE_BLIT		0x49400001
649#define COMMAND_COLOR_BLIT				0x50000003
650#define COMMAND_BLIT_RGBA				0x00300000
651
652#define COMMAND_MODE_SOLID_PATTERN		0x80
653#define COMMAND_MODE_CMAP8				0x00
654#define COMMAND_MODE_RGB15				0x02
655#define COMMAND_MODE_RGB16				0x01
656#define COMMAND_MODE_RGB32				0x03
657
658// overlay
659#define INTEL_OVERLAY_UPDATE			0x30000
660#define INTEL_OVERLAY_TEST				0x30004
661#define INTEL_OVERLAY_STATUS			0x30008
662#define INTEL_OVERLAY_EXTENDED_STATUS	0x3000c
663#define INTEL_OVERLAY_GAMMA_5			0x30010
664#define INTEL_OVERLAY_GAMMA_4			0x30014
665#define INTEL_OVERLAY_GAMMA_3			0x30018
666#define INTEL_OVERLAY_GAMMA_2			0x3001c
667#define INTEL_OVERLAY_GAMMA_1			0x30020
668#define INTEL_OVERLAY_GAMMA_0			0x30024
669
670// FDI - Flexible Display Interface, the interface between the (CPU-internal)
671// GPU and the PCH display outputs. Proprietary interface, based on DisplayPort
672// though, so similar link training and all...
673// There's an FDI transmitter (TX) on the CPU and an FDI receiver (RX) on the
674// PCH for each display pipe.
675// FDI receiver A is hooked up to transcoder A, FDI receiver B is hooked up to
676// transcoder B, so we have the same mapping as with the display pipes.
677#define PCH_FDI_RX_BASE_REGISTER		0xf0000
678#define PCH_FDI_RX_PIPE_OFFSET			0x01000
679
680#define PCH_FDI_RX_CONTROL				0x0c
681#define FDI_RX_CLOCK_MASK				(1 << 4)
682#define FDI_RX_CLOCK_RAW				(0 << 4)
683#define FDI_RX_CLOCK_PCD				(1 << 4)
684
685#define PCH_FDI_RX_TRANS_UNIT_SIZE_1	0x30
686#define PCH_FDI_RX_TRANS_UNIT_SIZE_2	0x38
687#define FDI_RX_TRANS_UNIT_SIZE(x)		((x - 1) << 25)
688#define FDI_RX_TRANS_UNIT_MASK			0x7e000000
689	// Transfer unit size 1 is the primary and fixed transfer unit size,
690	// TU size 2 is the lower power state transfer unit size when using dynamic
691	// refresh rates (we don't do that though).
692
693// CPU Panel Fitters - These are for IronLake and up and are the CPU internal
694// panel fitters.
695#define PCH_PANEL_FITTER_BASE_REGISTER	0x68000
696#define PCH_PANEL_FITTER_PIPE_OFFSET	0x00800
697
698#define PCH_PANEL_FITTER_WINDOW_POS		0x70
699#define PCH_PANEL_FITTER_WINDOW_SIZE	0x74
700#define PCH_PANEL_FITTER_CONTROL		0x80
701#define PCH_PANEL_FITTER_V_SCALE		0x84
702#define PCH_PANEL_FITTER_H_SCALE		0x90
703
704#define PANEL_FITTER_ENABLED			(1 << 31)
705#define PANEL_FITTER_FILTER_MASK		(3 << 23)
706
707struct overlay_scale {
708	uint32 _reserved0 : 3;
709	uint32 horizontal_scale_fraction : 12;
710	uint32 _reserved1 : 1;
711	uint32 horizontal_downscale_factor : 3;
712	uint32 _reserved2 : 1;
713	uint32 vertical_scale_fraction : 12;
714};
715
716#define OVERLAY_FORMAT_RGB15			0x2
717#define OVERLAY_FORMAT_RGB16			0x3
718#define OVERLAY_FORMAT_RGB32			0x1
719#define OVERLAY_FORMAT_YCbCr422			0x8
720#define OVERLAY_FORMAT_YCbCr411			0x9
721#define OVERLAY_FORMAT_YCbCr420			0xc
722
723#define OVERLAY_MIRROR_NORMAL			0x0
724#define OVERLAY_MIRROR_HORIZONTAL		0x1
725#define OVERLAY_MIRROR_VERTICAL			0x2
726
727// The real overlay registers are written to using an update buffer
728
729struct overlay_registers {
730	uint32 buffer_rgb0;
731	uint32 buffer_rgb1;
732	uint32 buffer_u0;
733	uint32 buffer_v0;
734	uint32 buffer_u1;
735	uint32 buffer_v1;
736	// (0x18) OSTRIDE - overlay stride
737	uint16 stride_rgb;
738	uint16 stride_uv;
739	// (0x1c) YRGB_VPH - Y/RGB vertical phase
740	uint16 vertical_phase0_rgb;
741	uint16 vertical_phase1_rgb;
742	// (0x20) UV_VPH - UV vertical phase
743	uint16 vertical_phase0_uv;
744	uint16 vertical_phase1_uv;
745	// (0x24) HORZ_PH - horizontal phase
746	uint16 horizontal_phase_rgb;
747	uint16 horizontal_phase_uv;
748	// (0x28) INIT_PHS - initial phase shift
749	uint32 initial_vertical_phase0_shift_rgb0 : 4;
750	uint32 initial_vertical_phase1_shift_rgb0 : 4;
751	uint32 initial_horizontal_phase_shift_rgb0 : 4;
752	uint32 initial_vertical_phase0_shift_uv : 4;
753	uint32 initial_vertical_phase1_shift_uv : 4;
754	uint32 initial_horizontal_phase_shift_uv : 4;
755	uint32 _reserved0 : 8;
756	// (0x2c) DWINPOS - destination window position
757	uint16 window_left;
758	uint16 window_top;
759	// (0x30) DWINSZ - destination window size
760	uint16 window_width;
761	uint16 window_height;
762	// (0x34) SWIDTH - source width
763	uint16 source_width_rgb;
764	uint16 source_width_uv;
765	// (0x38) SWITDHSW - source width in 8 byte steps
766	uint16 source_bytes_per_row_rgb;
767	uint16 source_bytes_per_row_uv;
768	uint16 source_height_rgb;
769	uint16 source_height_uv;
770	overlay_scale scale_rgb;
771	overlay_scale scale_uv;
772	// (0x48) OCLRC0 - overlay color correction 0
773	uint32 brightness_correction : 8;		// signed, -128 to 127
774	uint32 _reserved1 : 10;
775	uint32 contrast_correction : 9;			// fixed point: 3.6 bits
776	uint32 _reserved2 : 5;
777	// (0x4c) OCLRC1 - overlay color correction 1
778	uint32 saturation_cos_correction : 10;	// fixed point: 3.7 bits
779	uint32 _reserved3 : 6;
780	uint32 saturation_sin_correction : 11;	// signed fixed point: 3.7 bits
781	uint32 _reserved4 : 5;
782	// (0x50) DCLRKV - destination color key value
783	uint32 color_key_blue : 8;
784	uint32 color_key_green : 8;
785	uint32 color_key_red : 8;
786	uint32 _reserved5 : 8;
787	// (0x54) DCLRKM - destination color key mask
788	uint32 color_key_mask_blue : 8;
789	uint32 color_key_mask_green : 8;
790	uint32 color_key_mask_red : 8;
791	uint32 _reserved6 : 7;
792	uint32 color_key_enabled : 1;
793	// (0x58) SCHRKVH - source chroma key high value
794	uint32 source_chroma_key_high_red : 8;
795	uint32 source_chroma_key_high_blue : 8;
796	uint32 source_chroma_key_high_green : 8;
797	uint32 _reserved7 : 8;
798	// (0x5c) SCHRKVL - source chroma key low value
799	uint32 source_chroma_key_low_red : 8;
800	uint32 source_chroma_key_low_blue : 8;
801	uint32 source_chroma_key_low_green : 8;
802	uint32 _reserved8 : 8;
803	// (0x60) SCHRKEN - source chroma key enable
804	uint32 _reserved9 : 24;
805	uint32 source_chroma_key_red_enabled : 1;
806	uint32 source_chroma_key_blue_enabled : 1;
807	uint32 source_chroma_key_green_enabled : 1;
808	uint32 _reserved10 : 5;
809	// (0x64) OCONFIG - overlay configuration
810	uint32 _reserved11 : 3;
811	uint32 color_control_output_mode : 1;
812	uint32 yuv_to_rgb_bypass : 1;
813	uint32 _reserved12 : 11;
814	uint32 gamma2_enabled : 1;
815	uint32 _reserved13 : 1;
816	uint32 select_pipe : 1;
817	uint32 slot_time : 8;
818	uint32 _reserved14 : 5;
819	// (0x68) OCOMD - overlay command
820	uint32 overlay_enabled : 1;
821	uint32 active_field : 1;
822	uint32 active_buffer : 2;
823	uint32 test_mode : 1;
824	uint32 buffer_field_mode : 1;
825	uint32 _reserved15 : 1;
826	uint32 tv_flip_field_enabled : 1;
827	uint32 _reserved16 : 1;
828	uint32 tv_flip_field_parity : 1;
829	uint32 source_format : 4;
830	uint32 ycbcr422_order : 2;
831	uint32 _reserved18 : 1;
832	uint32 mirroring_mode : 2;
833	uint32 _reserved19 : 13;
834
835	uint32 _reserved20;
836
837	uint32 start_0y;
838	uint32 start_1y;
839	uint32 start_0u;
840	uint32 start_0v;
841	uint32 start_1u;
842	uint32 start_1v;
843	uint32 _reserved21[6];
844#if 0
845	// (0x70) AWINPOS - alpha blend window position
846	uint32 awinpos;
847	// (0x74) AWINSZ - alpha blend window size
848	uint32 awinsz;
849
850	uint32 _reserved21[10];
851#endif
852
853	// (0xa0) FASTHSCALE - fast horizontal downscale (strangely enough,
854	// the next two registers switch the usual Y/RGB vs. UV order)
855	uint16 horizontal_scale_uv;
856	uint16 horizontal_scale_rgb;
857	// (0xa4) UVSCALEV - vertical downscale
858	uint16 vertical_scale_uv;
859	uint16 vertical_scale_rgb;
860
861	uint32 _reserved22[86];
862
863	// (0x200) polyphase filter coefficients
864	uint16 vertical_coefficients_rgb[128];
865	uint16 horizontal_coefficients_rgb[128];
866
867	uint32	_reserved23[64];
868
869	// (0x500)
870	uint16 vertical_coefficients_uv[128];
871	uint16 horizontal_coefficients_uv[128];
872};
873
874// i965 overlay support is currently realized using its 3D hardware
875#define INTEL_i965_OVERLAY_STATE_SIZE	36864
876#define INTEL_i965_3D_CONTEXT_SIZE		32768
877
878inline bool
879intel_uses_physical_overlay(intel_shared_info &info)
880{
881	return !info.device_type.InGroup(INTEL_GROUP_Gxx);
882}
883
884
885struct hardware_status {
886	uint32	interrupt_status_register;
887	uint32	_reserved0[3];
888	void*	primary_ring_head_storage;
889	uint32	_reserved1[3];
890	void*	secondary_ring_0_head_storage;
891	void*	secondary_ring_1_head_storage;
892	uint32	_reserved2[2];
893	void*	binning_head_storage;
894	uint32	_reserved3[3];
895	uint32	store[1008];
896};
897
898#endif	/* INTEL_EXTREME_H */
899