xref: /titanic_44/usr/src/uts/common/sys/agp/agpdefs.h (revision 18c2aff776a775d34a4c9893a4c72e0434d68e36)
1 /*
2  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 #ifndef _SYS_AGPDEFS_H
7 #define	_SYS_AGPDEFS_H
8 
9 #pragma ident	"%Z%%M%	%I%	%E% SMI"
10 
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14 
15 /*
16  * This AGP memory type is required by some hadrware like i810 video
17  * card, which need physical contiguous pages to setup hardware cursor.
18  * Usually, several tens of kilo bytes are needed in this case.
19  * We use DDI DMA interfaces to allocate such memory in agpgart driver,
20  * and it can not be exported to user applications directly by calling mmap
21  * on agpgart driver. The typical usage scenario is as the following:
22  * Firstly, Xserver get the memory physical address by calling AGPIOC_ALLOCATE
23  * on agpgart driver. Secondly, Xserver use the physical address to mmap
24  * the memory to Xserver space area by xsvc driver.
25  *
26  */
27 #define	AGP_PHYSICAL		2	/* Only used for i810, HW curosr */
28 
29 #ifdef _KERNEL
30 
31 /* AGP space units */
32 #define	AGP_PAGE_SHIFT			12
33 #define	AGP_PAGE_SIZE			(1 << AGP_PAGE_SHIFT)
34 #define	AGP_PAGE_OFFSET			(AGP_PAGE_SIZE - 1)
35 #define	AGP_MB2PAGES(x)			((x) << 8)
36 #define	AGP_PAGES2BYTES(x)		((x) << AGP_PAGE_SHIFT)
37 #define	AGP_BYTES2PAGES(x)		((x) >> AGP_PAGE_SHIFT)
38 #define	AGP_PAGES2KB(x)			((x) << 2)
39 #define	AGP_ALIGNED(offset)		(((offset) & AGP_PAGE_OFFSET) == 0)
40 
41 /* stand pci register offset */
42 #define	PCI_CONF_CAP_MASK		0x10
43 #define	PCI_CONF_CAPID_MASK		0xff
44 #define	PCI_CONF_NCAPID_MASK		0xff00
45 
46 #define	INTEL_VENDOR_ID			0x8086
47 #define	AMD_VENDOR_ID			0x1022
48 #define	VENDOR_ID_MASK			0xffff
49 
50 /* macros for device types */
51 #define	DEVICE_IS_I810		11 /* intel i810 series video card */
52 #define	DEVICE_IS_I830		12 /* intel i830, i845, i855 series */
53 #define	DEVICE_IS_AGP		21 /* external AGP video card */
54 #define	CHIP_IS_INTEL		10 /* intel agp bridge */
55 #define	CHIP_IS_AMD		20 /* amd agp bridge */
56 
57 /* AGP bridge device id */
58 #define	AMD_BR_8151			0x74541022
59 #define	INTEL_BR_810			0x71208086
60 #define	INTEL_BR_810DC			0x71228086
61 #define	INTEL_BR_810E			0x71248086
62 #define	INTEL_BR_815			0x11308086 /* include 815G/EG/P/EP */
63 #define	INTEL_BR_830M			0x35758086
64 #define	INTEL_BR_845			0x25608086 /* include 845G/P */
65 #define	INTEL_BR_855GM			0x35808086 /* include 852GM/PM */
66 #define	INTEL_BR_855PM			0x33408086
67 #define	INTEL_BR_865			0x25708086
68 #define	INTEL_BR_910			0x25808086
69 #define	INTEL_BR_910M			0x25908086
70 
71 /* AGP common register offset in pci configuration space */
72 #define	AGP_CONF_MISC			0x51 /* one byte */
73 #define	AGP_CONF_CAPPTR			0x34
74 #define	AGP_CONF_APERBASE		0x10
75 #define	AGP_CONF_STATUS			0x04 /* CAP + 0x4 */
76 #define	AGP_CONF_COMMAND		0x08 /* CAP + 0x8 */
77 
78 /* AGP target register and mask defines */
79 #define	AGP_CONF_CONTROL		0x10 /* CAP + 0x10 */
80 #define	AGP_TARGET_BAR1			1
81 #define	AGP_32_APERBASE_MASK		0xffc00000 /* 4M aligned */
82 #define	AGP_64_APERBASE_MASK		0xffffc00000LL /* 4M aligned */
83 #define	AGP_CONF_APERSIZE		0x14 /* CAP + 0x14 */
84 #define	AGP_CONF_ATTBASE		0x18 /* CAP + 0x18 */
85 #define	AGP_ATTBASE_MASK		0xfffff000
86 #define	AGPCTRL_GTLBEN			(0x1 << 7)
87 #define	AGP_APER_TYPE_MASK		0x4
88 #define	AGP_APER_SIZE_MASK		0xf00
89 #define	AGP_APER_128M_MASK		0x3f
90 #define	AGP_APER_4G_MASK		0xf00
91 #define	AGP_APER_4M			0x3f
92 #define	AGP_APER_8M			0x3e
93 #define	AGP_APER_16M			0x3c
94 #define	AGP_APER_32M			0x38
95 #define	AGP_APER_64M			0x30
96 #define	AGP_APER_128M			0x20
97 #define	AGP_APER_256M			0xf00
98 #define	AGP_APER_512M			0xe00
99 #define	AGP_APER_1024M			0xc00
100 #define	AGP_APER_2048M			0x800
101 #define	AGP_APER_4G			0x000
102 #define	AGP_MISC_APEN			0x2
103 
104 /* AGP gart table definition */
105 #define	AGP_ENTRY_VALID			0x1
106 
107 /* AGP term definitions */
108 #define	AGP_CAP_ID			0x2
109 #define	AGP_CAP_OFF_DEF			0xa0
110 
111 /* Intel integrated video card, chipset id */
112 #define	INTEL_IGD_810			0x71218086
113 #define	INTEL_IGD_810DC			0x71238086
114 #define	INTEL_IGD_810E			0x71258086
115 #define	INTEL_IGD_815			0x11328086
116 #define	INTEL_IGD_830M			0x35778086
117 #define	INTEL_IGD_845G			0x25628086
118 #define	INTEL_IGD_855GM			0x35828086
119 #define	INTEL_IGD_865G			0x25728086
120 #define	INTEL_IGD_910			0x25828086
121 #define	INTEL_IGD_910M			0x25928086
122 #define	I8XX_CONF_GMADR			0x10 /* offset in PCI config space */
123 #define	I915_CONF_GMADR			0x18 /* offset in PCI config space */
124 #define	I8XX_CONF_GC			0x52 /* offset in PCI config space */
125 
126 /* Intel integrated video card graphics mode mask */
127 #define	I8XX_GC_MODE_MASK		0x70
128 #define	I8XX_GC_MODE0			0x00
129 #define	I8XX_GC_MODE1			0x10
130 #define	I8XX_GC_MODE2			0x20
131 #define	I8XX_GC_MODE3			0x30
132 #define	I8XX_GC_MODE4			0x40
133 #define	I8XX_GC_MODE5			0x50
134 
135 /* Intel integrated video card GTT definition */
136 #define	GTT_PAGE_SHIFT			12
137 #define	GTT_PAGE_SIZE			(1 << GTT_PAGE_SHIFT)
138 #define	GTT_PAGE_OFFSET			(GTT_PAGE_SIZE - 1)
139 #define	GTT_PTE_MASK			(~GTT_PAGE_OFFSET)
140 #define	GTT_PTE_VALID			0x1
141 #define	GTT_TABLE_VALID			0x1
142 #define	GTT_BASE_MASK			0xfffff000
143 #define	GTT_MB_TO_PAGES(m)		((m) << 8)
144 #define	GTT_POINTER_MASK		0xffffffff
145 
146 /* Intel i810 register offset */
147 #define	I810_POINTER_MASK		0x3fffffff
148 #define	I810_CONF_SMRAM			0x70 /* offset in PCI config space */
149 #define	I810_GMS_MASK			0xc0 /* smram register mask */
150 /*
151  *	GART and GTT entry format table
152  *
153  * 		AMD64 GART entry
154  * 	from bios and kernel develop guide for amd64
155  *	 -----------------------------
156  * 	Bits		Description	|
157  * 	0		valid		|
158  * 	1		coherent	|
159  * 	3:2		reserved	|
160  * 	11:4		physaddr[39:32]	|
161  * 	31:12	physaddr[31:12]	|
162  * 	-----------------------------
163  *		Intel GTT entry
164  * 	Intel video programming manual
165  * 	-----------------------------
166  * 	Bits		descrition	|
167  * 	0		valid		|
168  * 	2:1		memory type	|
169  * 	29:12		PhysAddr[29:12]	|
170  * 	31:30		reserved	|
171  * 	-----------------------------
172  *		AGP entry
173  * 	from AGP protocol 3.0
174  * 	-----------------------------
175  * 	Bits		descrition	|
176  * 	0		valid		|
177  * 	1		coherent	|
178  * 	3:2		reserved	|
179  * 	11:4		PhysAddr[39:32]	|
180  * 	31:12	PhysAddr[31:12]		|
181  * 	63:32	PhysAddr[71:40]		|
182  *	 -----------------------------
183  */
184 
185 /*
186  *	gart and gtt table base register format
187  *
188  *  		AMD64 register format
189  * 	from bios and kernel develop guide for AMD64
190  * 	---------------------------------------------
191  * 	Bits			Description		|
192  * 	3:0			reserved		|
193  * 	31:4			physical addr 39:12	|
194  * 	----------------------------------------------
195  * 		INTEL AGPGART table base register format
196  * 	from AGP protocol 3.0 p142, only support 32 bits
197  * 	---------------------------------------------
198  * 	Bits			Description		|
199  * 	11:0			reserved		|
200  * 	31:12		physical addr 31:12		|
201  * 	63:32		physical addr 63:32		|
202  * 	---------------------------------------------
203  * 		INTEL i810 GTT table base register format
204  * 	_____________________________________________
205  * 	Bits			Description		|
206  * 	0			GTT table enable bit	|
207  * 	11:1			reserved		|
208  * 	31:12			physical addr 31:12	|
209  * 	---------------------------------------------
210  */
211 
212 /* Intel agp bridge specific */
213 #define	AGP_INTEL_POINTER_MASK		0xffffffff
214 
215 /* Amd64 cpu gart device reigster offset */
216 #define	AMD64_APERTURE_CONTROL		0x90
217 #define	AMD64_APERTURE_BASE		0x94
218 #define	AMD64_GART_CACHE_CTL		0x9c
219 #define	AMD64_GART_BASE			0x98
220 
221 /* Amd64 cpu gart bits */
222 #define	AMD64_APERBASE_SHIFT		25
223 #define	AMD64_APERBASE_MASK		0x00007fff
224 #define	AMD64_GARTBASE_SHIFT		8
225 #define	AMD64_GARTBASE_MASK		0xfffffff0
226 #define	AMD64_POINTER_MASK		0xffffffffff
227 #define	AMD64_INVALID_CACHE		0x1
228 #define	AMD64_GART_SHIFT		12
229 #define	AMD64_RESERVE_SHIFT		4
230 #define	AMD64_APERSIZE_MASK		0xe
231 #define	AMD64_GARTEN			0x1
232 #define	AMD64_DISGARTCPU		0x10
233 #define	AMD64_DISGARTIO			0x20
234 #define	AMD64_ENTRY_VALID		0x1
235 
236 /* Other common routines */
237 #define	MB2BYTES(m)		((m) << 20)
238 #define	BYTES2MB(m)		((m) >> 20)
239 #define	GIGA_MASK		0xC0000000
240 #define	UI32_MASK		0xffffffffU
241 #define	MAXAPERMEGAS		0x1000 /* Aper size no more than 4G */
242 
243 #endif /* _KERNEL */
244 
245 #ifdef __cplusplus
246 }
247 #endif
248 
249 #endif /* _SYS_AGPDEFS_H */
250