blob: 8a713f1e965351ef91a2d885485ec5fe4e96c719 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Intel AGPGART routines.
3 */
4
Linus Torvalds1da177e2005-04-16 15:20:36 -07005#include <linux/module.h>
6#include <linux/pci.h>
7#include <linux/init.h>
Ahmed S. Darwish1eaf1222007-02-06 18:08:28 +02008#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <linux/pagemap.h>
10#include <linux/agp_backend.h>
Borislav Petkov48a719c2010-01-22 16:01:04 +010011#include <asm/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include "agp.h"
13
Zhenyu Wang17661682009-07-27 12:59:57 +010014/*
15 * If we have Intel graphics, we're not going to have anything other than
16 * an Intel IOMMU. So make the correct use of the PCI DMA API contingent
17 * on the Intel IOMMU support (CONFIG_DMAR).
18 * Only newer chipsets need to bother with this, of course.
19 */
20#ifdef CONFIG_DMAR
21#define USE_PCI_DMA_API 1
22#endif
23
Carlos Martíne914a362008-01-24 10:34:09 +100024#define PCI_DEVICE_ID_INTEL_E7221_HB 0x2588
25#define PCI_DEVICE_ID_INTEL_E7221_IG 0x258a
Eric Anholt65c25aa2006-09-06 11:57:18 -040026#define PCI_DEVICE_ID_INTEL_82946GZ_HB 0x2970
27#define PCI_DEVICE_ID_INTEL_82946GZ_IG 0x2972
Zhenyu Wang9119f852008-01-23 15:49:26 +100028#define PCI_DEVICE_ID_INTEL_82G35_HB 0x2980
29#define PCI_DEVICE_ID_INTEL_82G35_IG 0x2982
Eric Anholt65c25aa2006-09-06 11:57:18 -040030#define PCI_DEVICE_ID_INTEL_82965Q_HB 0x2990
31#define PCI_DEVICE_ID_INTEL_82965Q_IG 0x2992
32#define PCI_DEVICE_ID_INTEL_82965G_HB 0x29A0
33#define PCI_DEVICE_ID_INTEL_82965G_IG 0x29A2
Wang Zhenyu4598af32007-04-09 08:51:36 +080034#define PCI_DEVICE_ID_INTEL_82965GM_HB 0x2A00
35#define PCI_DEVICE_ID_INTEL_82965GM_IG 0x2A02
Zhenyu Wangdde47872007-07-26 09:18:09 +080036#define PCI_DEVICE_ID_INTEL_82965GME_HB 0x2A10
Wang Zhenyuc8eebfd2007-05-31 11:34:06 +080037#define PCI_DEVICE_ID_INTEL_82965GME_IG 0x2A12
Zhenyu Wangdde47872007-07-26 09:18:09 +080038#define PCI_DEVICE_ID_INTEL_82945GME_HB 0x27AC
Wang Zhenyudf80b142007-05-31 11:51:12 +080039#define PCI_DEVICE_ID_INTEL_82945GME_IG 0x27AE
Adam Jackson107f5172009-12-03 17:14:41 -050040#define PCI_DEVICE_ID_INTEL_PINEVIEW_M_HB 0xA010
41#define PCI_DEVICE_ID_INTEL_PINEVIEW_M_IG 0xA011
42#define PCI_DEVICE_ID_INTEL_PINEVIEW_HB 0xA000
43#define PCI_DEVICE_ID_INTEL_PINEVIEW_IG 0xA001
Wang Zhenyu874808c62007-06-06 11:16:25 +080044#define PCI_DEVICE_ID_INTEL_G33_HB 0x29C0
45#define PCI_DEVICE_ID_INTEL_G33_IG 0x29C2
46#define PCI_DEVICE_ID_INTEL_Q35_HB 0x29B0
47#define PCI_DEVICE_ID_INTEL_Q35_IG 0x29B2
48#define PCI_DEVICE_ID_INTEL_Q33_HB 0x29D0
49#define PCI_DEVICE_ID_INTEL_Q33_IG 0x29D2
Fabian Henze38d8a952009-09-08 00:59:58 +080050#define PCI_DEVICE_ID_INTEL_B43_HB 0x2E40
51#define PCI_DEVICE_ID_INTEL_B43_IG 0x2E42
Zhenyu Wang99d32bd2008-07-30 12:26:50 -070052#define PCI_DEVICE_ID_INTEL_GM45_HB 0x2A40
53#define PCI_DEVICE_ID_INTEL_GM45_IG 0x2A42
Adam Jackson107f5172009-12-03 17:14:41 -050054#define PCI_DEVICE_ID_INTEL_EAGLELAKE_HB 0x2E00
55#define PCI_DEVICE_ID_INTEL_EAGLELAKE_IG 0x2E02
Zhenyu Wang25ce77a2008-06-19 14:17:58 +100056#define PCI_DEVICE_ID_INTEL_Q45_HB 0x2E10
57#define PCI_DEVICE_ID_INTEL_Q45_IG 0x2E12
58#define PCI_DEVICE_ID_INTEL_G45_HB 0x2E20
59#define PCI_DEVICE_ID_INTEL_G45_IG 0x2E22
Zhenyu Wanga50ccc62008-11-17 14:39:00 +080060#define PCI_DEVICE_ID_INTEL_G41_HB 0x2E30
61#define PCI_DEVICE_ID_INTEL_G41_IG 0x2E32
Adam Jackson107f5172009-12-03 17:14:41 -050062#define PCI_DEVICE_ID_INTEL_IRONLAKE_D_HB 0x0040
63#define PCI_DEVICE_ID_INTEL_IRONLAKE_D_IG 0x0042
64#define PCI_DEVICE_ID_INTEL_IRONLAKE_M_HB 0x0044
65#define PCI_DEVICE_ID_INTEL_IRONLAKE_MA_HB 0x0062
Dave Airlie3ff99162009-12-08 14:03:47 +100066#define PCI_DEVICE_ID_INTEL_IRONLAKE_MC2_HB 0x006a
Adam Jackson107f5172009-12-03 17:14:41 -050067#define PCI_DEVICE_ID_INTEL_IRONLAKE_M_IG 0x0046
Eric Anholt65c25aa2006-09-06 11:57:18 -040068
Dave Airlief011ae72008-01-25 11:23:04 +100069/* cover 915 and 945 variants */
70#define IS_I915 (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_E7221_HB || \
71 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82915G_HB || \
72 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82915GM_HB || \
73 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82945G_HB || \
74 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82945GM_HB || \
75 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82945GME_HB)
76
Eric Anholt65c25aa2006-09-06 11:57:18 -040077#define IS_I965 (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82946GZ_HB || \
Dave Airlief011ae72008-01-25 11:23:04 +100078 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82G35_HB || \
79 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965Q_HB || \
80 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965G_HB || \
81 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965GM_HB || \
Eric Anholt82e14a62008-10-14 11:28:58 -070082 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965GME_HB)
Eric Anholt65c25aa2006-09-06 11:57:18 -040083
Wang Zhenyu874808c62007-06-06 11:16:25 +080084#define IS_G33 (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_G33_HB || \
85 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_Q35_HB || \
Shaohua Li21778322009-02-23 15:19:16 +080086 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_Q33_HB || \
Adam Jackson107f5172009-12-03 17:14:41 -050087 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_PINEVIEW_M_HB || \
88 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_PINEVIEW_HB)
Shaohua Li21778322009-02-23 15:19:16 +080089
Adam Jackson107f5172009-12-03 17:14:41 -050090#define IS_PINEVIEW (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_PINEVIEW_M_HB || \
91 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_PINEVIEW_HB)
Eric Anholt65c25aa2006-09-06 11:57:18 -040092
Adam Jackson107f5172009-12-03 17:14:41 -050093#define IS_G4X (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_EAGLELAKE_HB || \
Zhenyu Wang25ce77a2008-06-19 14:17:58 +100094 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_Q45_HB || \
Eric Anholt82e14a62008-10-14 11:28:58 -070095 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_G45_HB || \
Zhenyu Wanga50ccc62008-11-17 14:39:00 +080096 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_GM45_HB || \
Zhenyu Wang32cb0552009-06-05 15:38:36 +080097 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_G41_HB || \
Fabian Henze38d8a952009-09-08 00:59:58 +080098 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_B43_HB || \
Adam Jackson107f5172009-12-03 17:14:41 -050099 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IRONLAKE_D_HB || \
100 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IRONLAKE_M_HB || \
Dave Airlie3ff99162009-12-08 14:03:47 +1000101 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IRONLAKE_MA_HB || \
102 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IRONLAKE_MC2_HB)
Zhenyu Wang25ce77a2008-06-19 14:17:58 +1000103
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100104extern int agp_memory_reserved;
105
106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107/* Intel 815 register */
108#define INTEL_815_APCONT 0x51
109#define INTEL_815_ATTBASE_MASK ~0x1FFFFFFF
110
111/* Intel i820 registers */
112#define INTEL_I820_RDCR 0x51
113#define INTEL_I820_ERRSTS 0xc8
114
115/* Intel i840 registers */
116#define INTEL_I840_MCHCFG 0x50
117#define INTEL_I840_ERRSTS 0xc8
118
119/* Intel i850 registers */
120#define INTEL_I850_MCHCFG 0x50
121#define INTEL_I850_ERRSTS 0xc8
122
123/* intel 915G registers */
124#define I915_GMADDR 0x18
125#define I915_MMADDR 0x10
126#define I915_PTEADDR 0x1C
127#define I915_GMCH_GMS_STOLEN_48M (0x6 << 4)
128#define I915_GMCH_GMS_STOLEN_64M (0x7 << 4)
Zhenyu Wang25ce77a2008-06-19 14:17:58 +1000129#define G33_GMCH_GMS_STOLEN_128M (0x8 << 4)
130#define G33_GMCH_GMS_STOLEN_256M (0x9 << 4)
131#define INTEL_GMCH_GMS_STOLEN_96M (0xa << 4)
132#define INTEL_GMCH_GMS_STOLEN_160M (0xb << 4)
133#define INTEL_GMCH_GMS_STOLEN_224M (0xc << 4)
134#define INTEL_GMCH_GMS_STOLEN_352M (0xd << 4)
135
Dave Airlie6c00a612007-10-29 18:06:10 +1000136#define I915_IFPADDR 0x60
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
Eric Anholt65c25aa2006-09-06 11:57:18 -0400138/* Intel 965G registers */
139#define I965_MSAC 0x62
Dave Airlie6c00a612007-10-29 18:06:10 +1000140#define I965_IFPADDR 0x70
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
142/* Intel 7505 registers */
143#define INTEL_I7505_APSIZE 0x74
144#define INTEL_I7505_NCAPID 0x60
145#define INTEL_I7505_NISTAT 0x6c
146#define INTEL_I7505_ATTBASE 0x78
147#define INTEL_I7505_ERRSTS 0x42
148#define INTEL_I7505_AGPCTRL 0x70
149#define INTEL_I7505_MCHCFG 0x50
150
Dave Jonese5524f32007-02-22 18:41:28 -0500151static const struct aper_size_info_fixed intel_i810_sizes[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152{
153 {64, 16384, 4},
154 /* The 32M mode still requires a 64k gatt */
155 {32, 8192, 4}
156};
157
158#define AGP_DCACHE_MEMORY 1
159#define AGP_PHYS_MEMORY 2
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100160#define INTEL_AGP_CACHED_MEMORY 3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
162static struct gatt_mask intel_i810_masks[] =
163{
164 {.mask = I810_PTE_VALID, .type = 0},
165 {.mask = (I810_PTE_VALID | I810_PTE_LOCAL), .type = AGP_DCACHE_MEMORY},
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100166 {.mask = I810_PTE_VALID, .type = 0},
167 {.mask = I810_PTE_VALID | I830_PTE_SYSTEM_CACHED,
168 .type = INTEL_AGP_CACHED_MEMORY}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169};
170
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800171static struct _intel_private {
172 struct pci_dev *pcidev; /* device one */
173 u8 __iomem *registers;
174 u32 __iomem *gtt; /* I915G */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 int num_dcache_entries;
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800176 /* gtt_entries is the number of gtt entries that are already mapped
177 * to stolen memory. Stolen memory is larger than the memory mapped
178 * through gtt_entries, as it includes some reserved space for the BIOS
179 * popup and for the GTT.
180 */
181 int gtt_entries; /* i830+ */
David Woodhousefc619012009-12-02 11:00:05 +0000182 int gtt_total_size;
Dave Airlie2162e6a2007-11-21 16:36:31 +1000183 union {
184 void __iomem *i9xx_flush_page;
185 void *i8xx_flush_page;
186 };
187 struct page *i8xx_page;
Dave Airlie6c00a612007-10-29 18:06:10 +1000188 struct resource ifp_resource;
Dave Airlie4d64dd92008-01-23 15:34:29 +1000189 int resource_valid;
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800190} intel_private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
Zhenyu Wang17661682009-07-27 12:59:57 +0100192#ifdef USE_PCI_DMA_API
David Woodhousec2980d82009-07-29 08:39:26 +0100193static int intel_agp_map_page(struct page *page, dma_addr_t *ret)
Zhenyu Wang17661682009-07-27 12:59:57 +0100194{
David Woodhousec2980d82009-07-29 08:39:26 +0100195 *ret = pci_map_page(intel_private.pcidev, page, 0,
196 PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
Zhenyu Wang17661682009-07-27 12:59:57 +0100197 if (pci_dma_mapping_error(intel_private.pcidev, *ret))
198 return -EINVAL;
199 return 0;
200}
201
David Woodhousec2980d82009-07-29 08:39:26 +0100202static void intel_agp_unmap_page(struct page *page, dma_addr_t dma)
Zhenyu Wang17661682009-07-27 12:59:57 +0100203{
David Woodhousec2980d82009-07-29 08:39:26 +0100204 pci_unmap_page(intel_private.pcidev, dma,
205 PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
Zhenyu Wang17661682009-07-27 12:59:57 +0100206}
207
David Woodhouse91b8e302009-07-29 08:49:12 +0100208static void intel_agp_free_sglist(struct agp_memory *mem)
209{
David Woodhousef6927752009-07-29 09:28:45 +0100210 struct sg_table st;
David Woodhouse91b8e302009-07-29 08:49:12 +0100211
David Woodhousef6927752009-07-29 09:28:45 +0100212 st.sgl = mem->sg_list;
213 st.orig_nents = st.nents = mem->page_count;
214
215 sg_free_table(&st);
216
David Woodhouse91b8e302009-07-29 08:49:12 +0100217 mem->sg_list = NULL;
218 mem->num_sg = 0;
219}
220
Zhenyu Wang17661682009-07-27 12:59:57 +0100221static int intel_agp_map_memory(struct agp_memory *mem)
222{
David Woodhousef6927752009-07-29 09:28:45 +0100223 struct sg_table st;
Zhenyu Wang17661682009-07-27 12:59:57 +0100224 struct scatterlist *sg;
225 int i;
226
227 DBG("try mapping %lu pages\n", (unsigned long)mem->page_count);
228
David Woodhousef6927752009-07-29 09:28:45 +0100229 if (sg_alloc_table(&st, mem->page_count, GFP_KERNEL))
Zhenyu Wang17661682009-07-27 12:59:57 +0100230 return -ENOMEM;
Zhenyu Wang17661682009-07-27 12:59:57 +0100231
David Woodhousef6927752009-07-29 09:28:45 +0100232 mem->sg_list = sg = st.sgl;
233
Zhenyu Wang17661682009-07-27 12:59:57 +0100234 for (i = 0 ; i < mem->page_count; i++, sg = sg_next(sg))
235 sg_set_page(sg, mem->pages[i], PAGE_SIZE, 0);
236
237 mem->num_sg = pci_map_sg(intel_private.pcidev, mem->sg_list,
238 mem->page_count, PCI_DMA_BIDIRECTIONAL);
David Woodhouse91b8e302009-07-29 08:49:12 +0100239 if (unlikely(!mem->num_sg)) {
240 intel_agp_free_sglist(mem);
Zhenyu Wang17661682009-07-27 12:59:57 +0100241 return -ENOMEM;
242 }
243 return 0;
244}
245
246static void intel_agp_unmap_memory(struct agp_memory *mem)
247{
248 DBG("try unmapping %lu pages\n", (unsigned long)mem->page_count);
249
250 pci_unmap_sg(intel_private.pcidev, mem->sg_list,
251 mem->page_count, PCI_DMA_BIDIRECTIONAL);
David Woodhouse91b8e302009-07-29 08:49:12 +0100252 intel_agp_free_sglist(mem);
Zhenyu Wang17661682009-07-27 12:59:57 +0100253}
254
255static void intel_agp_insert_sg_entries(struct agp_memory *mem,
256 off_t pg_start, int mask_type)
257{
258 struct scatterlist *sg;
259 int i, j;
260
261 j = pg_start;
262
263 WARN_ON(!mem->num_sg);
264
265 if (mem->num_sg == mem->page_count) {
266 for_each_sg(mem->sg_list, sg, mem->page_count, i) {
267 writel(agp_bridge->driver->mask_memory(agp_bridge,
268 sg_dma_address(sg), mask_type),
269 intel_private.gtt+j);
270 j++;
271 }
272 } else {
273 /* sg may merge pages, but we have to seperate
274 * per-page addr for GTT */
275 unsigned int len, m;
276
277 for_each_sg(mem->sg_list, sg, mem->num_sg, i) {
278 len = sg_dma_len(sg) / PAGE_SIZE;
279 for (m = 0; m < len; m++) {
280 writel(agp_bridge->driver->mask_memory(agp_bridge,
281 sg_dma_address(sg) + m * PAGE_SIZE,
282 mask_type),
283 intel_private.gtt+j);
284 j++;
285 }
286 }
287 }
288 readl(intel_private.gtt+j-1);
289}
290
291#else
292
293static void intel_agp_insert_sg_entries(struct agp_memory *mem,
294 off_t pg_start, int mask_type)
295{
296 int i, j;
297
298 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
299 writel(agp_bridge->driver->mask_memory(agp_bridge,
David Woodhouse6a122352009-07-29 10:25:58 +0100300 page_to_phys(mem->pages[i]), mask_type),
Zhenyu Wang17661682009-07-27 12:59:57 +0100301 intel_private.gtt+j);
302 }
303
304 readl(intel_private.gtt+j-1);
305}
306
307#endif
308
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309static int intel_i810_fetch_size(void)
310{
311 u32 smram_miscc;
312 struct aper_size_info_fixed *values;
313
314 pci_read_config_dword(agp_bridge->dev, I810_SMRAM_MISCC, &smram_miscc);
315 values = A_SIZE_FIX(agp_bridge->driver->aperture_sizes);
316
317 if ((smram_miscc & I810_GMS) == I810_GMS_DISABLE) {
Bjorn Helgaase3cf6952008-07-30 12:26:51 -0700318 dev_warn(&agp_bridge->dev->dev, "i810 is disabled\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 return 0;
320 }
321 if ((smram_miscc & I810_GFX_MEM_WIN_SIZE) == I810_GFX_MEM_WIN_32M) {
322 agp_bridge->previous_size =
323 agp_bridge->current_size = (void *) (values + 1);
324 agp_bridge->aperture_size_idx = 1;
325 return values[1].size;
326 } else {
327 agp_bridge->previous_size =
328 agp_bridge->current_size = (void *) (values);
329 agp_bridge->aperture_size_idx = 0;
330 return values[0].size;
331 }
332
333 return 0;
334}
335
336static int intel_i810_configure(void)
337{
338 struct aper_size_info_fixed *current_size;
339 u32 temp;
340 int i;
341
342 current_size = A_SIZE_FIX(agp_bridge->current_size);
343
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800344 if (!intel_private.registers) {
345 pci_read_config_dword(intel_private.pcidev, I810_MMADDR, &temp);
Dave Jonese4ac5e42007-02-04 17:37:42 -0500346 temp &= 0xfff80000;
347
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800348 intel_private.registers = ioremap(temp, 128 * 4096);
349 if (!intel_private.registers) {
Bjorn Helgaase3cf6952008-07-30 12:26:51 -0700350 dev_err(&intel_private.pcidev->dev,
351 "can't remap memory\n");
Dave Jonese4ac5e42007-02-04 17:37:42 -0500352 return -ENOMEM;
353 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 }
355
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800356 if ((readl(intel_private.registers+I810_DRAM_CTL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 & I810_DRAM_ROW_0) == I810_DRAM_ROW_0_SDRAM) {
358 /* This will need to be dynamically assigned */
Bjorn Helgaase3cf6952008-07-30 12:26:51 -0700359 dev_info(&intel_private.pcidev->dev,
360 "detected 4MB dedicated video ram\n");
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800361 intel_private.num_dcache_entries = 1024;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 }
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800363 pci_read_config_dword(intel_private.pcidev, I810_GMADDR, &temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800365 writel(agp_bridge->gatt_bus_addr | I810_PGETBL_ENABLED, intel_private.registers+I810_PGETBL_CTL);
366 readl(intel_private.registers+I810_PGETBL_CTL); /* PCI Posting. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
368 if (agp_bridge->driver->needs_scratch_page) {
369 for (i = 0; i < current_size->num_entries; i++) {
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800370 writel(agp_bridge->scratch_page, intel_private.registers+I810_PTE_BASE+(i*4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 }
Keith Packard44d49442008-10-14 17:18:45 -0700372 readl(intel_private.registers+I810_PTE_BASE+((i-1)*4)); /* PCI posting. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 }
374 global_cache_flush();
375 return 0;
376}
377
378static void intel_i810_cleanup(void)
379{
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800380 writel(0, intel_private.registers+I810_PGETBL_CTL);
381 readl(intel_private.registers); /* PCI Posting. */
382 iounmap(intel_private.registers);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383}
384
385static void intel_i810_tlbflush(struct agp_memory *mem)
386{
387 return;
388}
389
390static void intel_i810_agp_enable(struct agp_bridge_data *bridge, u32 mode)
391{
392 return;
393}
394
395/* Exists to support ARGB cursors */
Dave Airlie07613ba2009-06-12 14:11:41 +1000396static struct page *i8xx_alloc_pages(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397{
Dave Airlief011ae72008-01-25 11:23:04 +1000398 struct page *page;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
Linus Torvalds66c669b2006-11-22 14:55:29 -0800400 page = alloc_pages(GFP_KERNEL | GFP_DMA32, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 if (page == NULL)
402 return NULL;
403
Arjan van de Ven6d238cc2008-01-30 13:34:06 +0100404 if (set_pages_uc(page, 4) < 0) {
405 set_pages_wb(page, 4);
Jan Beulich89cf7cc2007-04-02 14:50:14 +0100406 __free_pages(page, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 return NULL;
408 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 get_page(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 atomic_inc(&agp_bridge->current_memory_agp);
Dave Airlie07613ba2009-06-12 14:11:41 +1000411 return page;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412}
413
Dave Airlie07613ba2009-06-12 14:11:41 +1000414static void i8xx_destroy_pages(struct page *page)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415{
Dave Airlie07613ba2009-06-12 14:11:41 +1000416 if (page == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 return;
418
Arjan van de Ven6d238cc2008-01-30 13:34:06 +0100419 set_pages_wb(page, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 put_page(page);
Jan Beulich89cf7cc2007-04-02 14:50:14 +0100421 __free_pages(page, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 atomic_dec(&agp_bridge->current_memory_agp);
423}
424
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100425static int intel_i830_type_to_mask_type(struct agp_bridge_data *bridge,
426 int type)
427{
428 if (type < AGP_USER_TYPES)
429 return type;
430 else if (type == AGP_USER_CACHED_MEMORY)
431 return INTEL_AGP_CACHED_MEMORY;
432 else
433 return 0;
434}
435
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436static int intel_i810_insert_entries(struct agp_memory *mem, off_t pg_start,
437 int type)
438{
439 int i, j, num_entries;
440 void *temp;
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100441 int ret = -EINVAL;
442 int mask_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +0100444 if (mem->page_count == 0)
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100445 goto out;
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +0100446
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 temp = agp_bridge->current_size;
448 num_entries = A_SIZE_FIX(temp)->num_entries;
449
Dave Jones6a92a4e2006-02-28 00:54:25 -0500450 if ((pg_start + mem->page_count) > num_entries)
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100451 goto out_err;
452
Dave Jones6a92a4e2006-02-28 00:54:25 -0500453
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 for (j = pg_start; j < (pg_start + mem->page_count); j++) {
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100455 if (!PGE_EMPTY(agp_bridge, readl(agp_bridge->gatt_table+j))) {
456 ret = -EBUSY;
457 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 }
460
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100461 if (type != mem->type)
462 goto out_err;
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +0100463
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100464 mask_type = agp_bridge->driver->agp_type_to_mask_type(agp_bridge, type);
465
466 switch (mask_type) {
467 case AGP_DCACHE_MEMORY:
468 if (!mem->is_flushed)
469 global_cache_flush();
470 for (i = pg_start; i < (pg_start + mem->page_count); i++) {
471 writel((i*4096)|I810_PTE_LOCAL|I810_PTE_VALID,
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800472 intel_private.registers+I810_PTE_BASE+(i*4));
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100473 }
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800474 readl(intel_private.registers+I810_PTE_BASE+((i-1)*4));
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100475 break;
476 case AGP_PHYS_MEMORY:
477 case AGP_NORMAL_MEMORY:
478 if (!mem->is_flushed)
479 global_cache_flush();
480 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
481 writel(agp_bridge->driver->mask_memory(agp_bridge,
David Woodhouse6a122352009-07-29 10:25:58 +0100482 page_to_phys(mem->pages[i]), mask_type),
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800483 intel_private.registers+I810_PTE_BASE+(j*4));
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100484 }
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800485 readl(intel_private.registers+I810_PTE_BASE+((j-1)*4));
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100486 break;
487 default:
488 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
491 agp_bridge->driver->tlb_flush(mem);
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100492out:
493 ret = 0;
494out_err:
Dave Airlie9516b032008-06-19 10:42:17 +1000495 mem->is_flushed = true;
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100496 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497}
498
499static int intel_i810_remove_entries(struct agp_memory *mem, off_t pg_start,
500 int type)
501{
502 int i;
503
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +0100504 if (mem->page_count == 0)
505 return 0;
506
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 for (i = pg_start; i < (mem->page_count + pg_start); i++) {
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800508 writel(agp_bridge->scratch_page, intel_private.registers+I810_PTE_BASE+(i*4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 }
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800510 readl(intel_private.registers+I810_PTE_BASE+((i-1)*4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 agp_bridge->driver->tlb_flush(mem);
513 return 0;
514}
515
516/*
517 * The i810/i830 requires a physical address to program its mouse
518 * pointer into hardware.
519 * However the Xserver still writes to it through the agp aperture.
520 */
521static struct agp_memory *alloc_agpphysmem_i8xx(size_t pg_count, int type)
522{
523 struct agp_memory *new;
Dave Airlie07613ba2009-06-12 14:11:41 +1000524 struct page *page;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 switch (pg_count) {
Dave Airlie07613ba2009-06-12 14:11:41 +1000527 case 1: page = agp_bridge->driver->agp_alloc_page(agp_bridge);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 break;
529 case 4:
530 /* kludge to get 4 physical pages for ARGB cursor */
Dave Airlie07613ba2009-06-12 14:11:41 +1000531 page = i8xx_alloc_pages();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 break;
533 default:
534 return NULL;
535 }
536
Dave Airlie07613ba2009-06-12 14:11:41 +1000537 if (page == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 return NULL;
539
540 new = agp_create_memory(pg_count);
541 if (new == NULL)
542 return NULL;
543
Dave Airlie07613ba2009-06-12 14:11:41 +1000544 new->pages[0] = page;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 if (pg_count == 4) {
546 /* kludge to get 4 physical pages for ARGB cursor */
Dave Airlie07613ba2009-06-12 14:11:41 +1000547 new->pages[1] = new->pages[0] + 1;
548 new->pages[2] = new->pages[1] + 1;
549 new->pages[3] = new->pages[2] + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 }
551 new->page_count = pg_count;
552 new->num_scratch_pages = pg_count;
553 new->type = AGP_PHYS_MEMORY;
Dave Airlie07613ba2009-06-12 14:11:41 +1000554 new->physical = page_to_phys(new->pages[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 return new;
556}
557
558static struct agp_memory *intel_i810_alloc_by_type(size_t pg_count, int type)
559{
560 struct agp_memory *new;
561
562 if (type == AGP_DCACHE_MEMORY) {
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800563 if (pg_count != intel_private.num_dcache_entries)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 return NULL;
565
566 new = agp_create_memory(1);
567 if (new == NULL)
568 return NULL;
569
570 new->type = AGP_DCACHE_MEMORY;
571 new->page_count = pg_count;
572 new->num_scratch_pages = 0;
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100573 agp_free_page_array(new);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 return new;
575 }
576 if (type == AGP_PHYS_MEMORY)
577 return alloc_agpphysmem_i8xx(pg_count, type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 return NULL;
579}
580
581static void intel_i810_free_by_type(struct agp_memory *curr)
582{
583 agp_free_key(curr->key);
Dave Jones6a92a4e2006-02-28 00:54:25 -0500584 if (curr->type == AGP_PHYS_MEMORY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 if (curr->page_count == 4)
Dave Airlie07613ba2009-06-12 14:11:41 +1000586 i8xx_destroy_pages(curr->pages[0]);
Alan Hourihane88d51962005-11-06 23:35:34 -0800587 else {
Dave Airlie07613ba2009-06-12 14:11:41 +1000588 agp_bridge->driver->agp_destroy_page(curr->pages[0],
Dave Airliea2721e92007-10-15 10:19:16 +1000589 AGP_PAGE_DESTROY_UNMAP);
Dave Airlie07613ba2009-06-12 14:11:41 +1000590 agp_bridge->driver->agp_destroy_page(curr->pages[0],
Dave Airliea2721e92007-10-15 10:19:16 +1000591 AGP_PAGE_DESTROY_FREE);
Alan Hourihane88d51962005-11-06 23:35:34 -0800592 }
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100593 agp_free_page_array(curr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 }
595 kfree(curr);
596}
597
598static unsigned long intel_i810_mask_memory(struct agp_bridge_data *bridge,
David Woodhouse2a4ceb62009-07-27 10:27:29 +0100599 dma_addr_t addr, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600{
601 /* Type checking must be done elsewhere */
602 return addr | bridge->driver->masks[type].mask;
603}
604
605static struct aper_size_info_fixed intel_i830_sizes[] =
606{
607 {128, 32768, 5},
608 /* The 64M mode still requires a 128k gatt */
609 {64, 16384, 5},
610 {256, 65536, 6},
Eric Anholt65c25aa2006-09-06 11:57:18 -0400611 {512, 131072, 7},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612};
613
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614static void intel_i830_init_gtt_entries(void)
615{
616 u16 gmch_ctrl;
617 int gtt_entries;
618 u8 rdct;
619 int local = 0;
620 static const int ddt[4] = { 0, 16, 32, 64 };
Eric Anholtc41e0de2006-12-19 12:57:24 -0800621 int size; /* reserved space (in kb) at the top of stolen memory */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622
Dave Airlief011ae72008-01-25 11:23:04 +1000623 pci_read_config_word(agp_bridge->dev, I830_GMCH_CTRL, &gmch_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624
Eric Anholtc41e0de2006-12-19 12:57:24 -0800625 if (IS_I965) {
626 u32 pgetbl_ctl;
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800627 pgetbl_ctl = readl(intel_private.registers+I810_PGETBL_CTL);
Eric Anholtc41e0de2006-12-19 12:57:24 -0800628
Eric Anholtc41e0de2006-12-19 12:57:24 -0800629 /* The 965 has a field telling us the size of the GTT,
630 * which may be larger than what is necessary to map the
631 * aperture.
632 */
633 switch (pgetbl_ctl & I965_PGETBL_SIZE_MASK) {
634 case I965_PGETBL_SIZE_128KB:
635 size = 128;
636 break;
637 case I965_PGETBL_SIZE_256KB:
638 size = 256;
639 break;
640 case I965_PGETBL_SIZE_512KB:
641 size = 512;
642 break;
Zhenyu Wang4e8b6e22008-01-23 14:54:37 +1000643 case I965_PGETBL_SIZE_1MB:
644 size = 1024;
645 break;
646 case I965_PGETBL_SIZE_2MB:
647 size = 2048;
648 break;
649 case I965_PGETBL_SIZE_1_5MB:
650 size = 1024 + 512;
651 break;
Eric Anholtc41e0de2006-12-19 12:57:24 -0800652 default:
Bjorn Helgaase3cf6952008-07-30 12:26:51 -0700653 dev_info(&intel_private.pcidev->dev,
654 "unknown page table size, assuming 512KB\n");
Eric Anholtc41e0de2006-12-19 12:57:24 -0800655 size = 512;
656 }
657 size += 4; /* add in BIOS popup space */
Adam Jackson107f5172009-12-03 17:14:41 -0500658 } else if (IS_G33 && !IS_PINEVIEW) {
Wang Zhenyu874808c62007-06-06 11:16:25 +0800659 /* G33's GTT size defined in gmch_ctrl */
660 switch (gmch_ctrl & G33_PGETBL_SIZE_MASK) {
661 case G33_PGETBL_SIZE_1M:
662 size = 1024;
663 break;
664 case G33_PGETBL_SIZE_2M:
665 size = 2048;
666 break;
667 default:
Bjorn Helgaase3cf6952008-07-30 12:26:51 -0700668 dev_info(&agp_bridge->dev->dev,
669 "unknown page table size 0x%x, assuming 512KB\n",
Wang Zhenyu874808c62007-06-06 11:16:25 +0800670 (gmch_ctrl & G33_PGETBL_SIZE_MASK));
671 size = 512;
672 }
673 size += 4;
Adam Jackson107f5172009-12-03 17:14:41 -0500674 } else if (IS_G4X || IS_PINEVIEW) {
Zhenyu Wang25ce77a2008-06-19 14:17:58 +1000675 /* On 4 series hardware, GTT stolen is separate from graphics
Eric Anholt82e14a62008-10-14 11:28:58 -0700676 * stolen, ignore it in stolen gtt entries counting. However,
677 * 4KB of the stolen memory doesn't get mapped to the GTT.
678 */
679 size = 4;
Eric Anholtc41e0de2006-12-19 12:57:24 -0800680 } else {
681 /* On previous hardware, the GTT size was just what was
682 * required to map the aperture.
683 */
684 size = agp_bridge->driver->fetch_size() + 4;
685 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686
687 if (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82830_HB ||
688 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82845G_HB) {
689 switch (gmch_ctrl & I830_GMCH_GMS_MASK) {
690 case I830_GMCH_GMS_STOLEN_512:
691 gtt_entries = KB(512) - KB(size);
692 break;
693 case I830_GMCH_GMS_STOLEN_1024:
694 gtt_entries = MB(1) - KB(size);
695 break;
696 case I830_GMCH_GMS_STOLEN_8192:
697 gtt_entries = MB(8) - KB(size);
698 break;
699 case I830_GMCH_GMS_LOCAL:
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800700 rdct = readb(intel_private.registers+I830_RDRAM_CHANNEL_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 gtt_entries = (I830_RDRAM_ND(rdct) + 1) *
702 MB(ddt[I830_RDRAM_DDT(rdct)]);
703 local = 1;
704 break;
705 default:
706 gtt_entries = 0;
707 break;
708 }
709 } else {
Dave Airliee67aa272007-09-18 22:46:35 -0700710 switch (gmch_ctrl & I855_GMCH_GMS_MASK) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 case I855_GMCH_GMS_STOLEN_1M:
712 gtt_entries = MB(1) - KB(size);
713 break;
714 case I855_GMCH_GMS_STOLEN_4M:
715 gtt_entries = MB(4) - KB(size);
716 break;
717 case I855_GMCH_GMS_STOLEN_8M:
718 gtt_entries = MB(8) - KB(size);
719 break;
720 case I855_GMCH_GMS_STOLEN_16M:
721 gtt_entries = MB(16) - KB(size);
722 break;
723 case I855_GMCH_GMS_STOLEN_32M:
724 gtt_entries = MB(32) - KB(size);
725 break;
726 case I915_GMCH_GMS_STOLEN_48M:
727 /* Check it's really I915G */
Zhenyu Wang25ce77a2008-06-19 14:17:58 +1000728 if (IS_I915 || IS_I965 || IS_G33 || IS_G4X)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 gtt_entries = MB(48) - KB(size);
730 else
731 gtt_entries = 0;
732 break;
733 case I915_GMCH_GMS_STOLEN_64M:
734 /* Check it's really I915G */
Zhenyu Wang25ce77a2008-06-19 14:17:58 +1000735 if (IS_I915 || IS_I965 || IS_G33 || IS_G4X)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 gtt_entries = MB(64) - KB(size);
737 else
738 gtt_entries = 0;
Wang Zhenyu874808c62007-06-06 11:16:25 +0800739 break;
740 case G33_GMCH_GMS_STOLEN_128M:
Zhenyu Wang25ce77a2008-06-19 14:17:58 +1000741 if (IS_G33 || IS_I965 || IS_G4X)
Wang Zhenyu874808c62007-06-06 11:16:25 +0800742 gtt_entries = MB(128) - KB(size);
743 else
744 gtt_entries = 0;
745 break;
746 case G33_GMCH_GMS_STOLEN_256M:
Zhenyu Wang25ce77a2008-06-19 14:17:58 +1000747 if (IS_G33 || IS_I965 || IS_G4X)
Wang Zhenyu874808c62007-06-06 11:16:25 +0800748 gtt_entries = MB(256) - KB(size);
749 else
750 gtt_entries = 0;
751 break;
Zhenyu Wang25ce77a2008-06-19 14:17:58 +1000752 case INTEL_GMCH_GMS_STOLEN_96M:
753 if (IS_I965 || IS_G4X)
754 gtt_entries = MB(96) - KB(size);
755 else
756 gtt_entries = 0;
757 break;
758 case INTEL_GMCH_GMS_STOLEN_160M:
759 if (IS_I965 || IS_G4X)
760 gtt_entries = MB(160) - KB(size);
761 else
762 gtt_entries = 0;
763 break;
764 case INTEL_GMCH_GMS_STOLEN_224M:
765 if (IS_I965 || IS_G4X)
766 gtt_entries = MB(224) - KB(size);
767 else
768 gtt_entries = 0;
769 break;
770 case INTEL_GMCH_GMS_STOLEN_352M:
771 if (IS_I965 || IS_G4X)
772 gtt_entries = MB(352) - KB(size);
773 else
774 gtt_entries = 0;
775 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 default:
777 gtt_entries = 0;
778 break;
779 }
780 }
Lubomir Rintel9c1e8a42009-03-10 12:55:54 -0700781 if (gtt_entries > 0) {
Bjorn Helgaase3cf6952008-07-30 12:26:51 -0700782 dev_info(&agp_bridge->dev->dev, "detected %dK %s memory\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 gtt_entries / KB(1), local ? "local" : "stolen");
Lubomir Rintel9c1e8a42009-03-10 12:55:54 -0700784 gtt_entries /= KB(4);
785 } else {
Bjorn Helgaase3cf6952008-07-30 12:26:51 -0700786 dev_info(&agp_bridge->dev->dev,
787 "no pre-allocated video memory detected\n");
Lubomir Rintel9c1e8a42009-03-10 12:55:54 -0700788 gtt_entries = 0;
789 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800791 intel_private.gtt_entries = gtt_entries;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792}
793
Dave Airlie2162e6a2007-11-21 16:36:31 +1000794static void intel_i830_fini_flush(void)
795{
796 kunmap(intel_private.i8xx_page);
797 intel_private.i8xx_flush_page = NULL;
798 unmap_page_from_agp(intel_private.i8xx_page);
Dave Airlie2162e6a2007-11-21 16:36:31 +1000799
800 __free_page(intel_private.i8xx_page);
Dave Airlie4d64dd92008-01-23 15:34:29 +1000801 intel_private.i8xx_page = NULL;
Dave Airlie2162e6a2007-11-21 16:36:31 +1000802}
803
804static void intel_i830_setup_flush(void)
805{
Dave Airlie4d64dd92008-01-23 15:34:29 +1000806 /* return if we've already set the flush mechanism up */
807 if (intel_private.i8xx_page)
808 return;
Dave Airlie2162e6a2007-11-21 16:36:31 +1000809
810 intel_private.i8xx_page = alloc_page(GFP_KERNEL | __GFP_ZERO | GFP_DMA32);
Dave Airlief011ae72008-01-25 11:23:04 +1000811 if (!intel_private.i8xx_page)
Dave Airlie2162e6a2007-11-21 16:36:31 +1000812 return;
Dave Airlie2162e6a2007-11-21 16:36:31 +1000813
Dave Airlie2162e6a2007-11-21 16:36:31 +1000814 intel_private.i8xx_flush_page = kmap(intel_private.i8xx_page);
815 if (!intel_private.i8xx_flush_page)
816 intel_i830_fini_flush();
817}
818
Eric Anholte517a5e2009-09-10 17:48:48 -0700819/* The chipset_flush interface needs to get data that has already been
820 * flushed out of the CPU all the way out to main memory, because the GPU
821 * doesn't snoop those buffers.
822 *
823 * The 8xx series doesn't have the same lovely interface for flushing the
824 * chipset write buffers that the later chips do. According to the 865
825 * specs, it's 64 octwords, or 1KB. So, to get those previous things in
826 * that buffer out, we just fill 1KB and clflush it out, on the assumption
827 * that it'll push whatever was in there out. It appears to work.
828 */
Dave Airlie2162e6a2007-11-21 16:36:31 +1000829static void intel_i830_chipset_flush(struct agp_bridge_data *bridge)
830{
831 unsigned int *pg = intel_private.i8xx_flush_page;
Dave Airlie2162e6a2007-11-21 16:36:31 +1000832
Eric Anholte517a5e2009-09-10 17:48:48 -0700833 memset(pg, 0, 1024);
Dave Airlief011ae72008-01-25 11:23:04 +1000834
Borislav Petkov48a719c2010-01-22 16:01:04 +0100835 if (cpu_has_clflush)
Eric Anholte517a5e2009-09-10 17:48:48 -0700836 clflush_cache_range(pg, 1024);
Borislav Petkov48a719c2010-01-22 16:01:04 +0100837 else if (wbinvd_on_all_cpus() != 0)
838 printk(KERN_ERR "Timed out waiting for cache flush.\n");
Dave Airlie2162e6a2007-11-21 16:36:31 +1000839}
840
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841/* The intel i830 automatically initializes the agp aperture during POST.
842 * Use the memory already set aside for in the GTT.
843 */
844static int intel_i830_create_gatt_table(struct agp_bridge_data *bridge)
845{
846 int page_order;
847 struct aper_size_info_fixed *size;
848 int num_entries;
849 u32 temp;
850
851 size = agp_bridge->current_size;
852 page_order = size->page_order;
853 num_entries = size->num_entries;
854 agp_bridge->gatt_table_real = NULL;
855
Dave Airlief011ae72008-01-25 11:23:04 +1000856 pci_read_config_dword(intel_private.pcidev, I810_MMADDR, &temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 temp &= 0xfff80000;
858
Dave Airlief011ae72008-01-25 11:23:04 +1000859 intel_private.registers = ioremap(temp, 128 * 4096);
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800860 if (!intel_private.registers)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 return -ENOMEM;
862
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800863 temp = readl(intel_private.registers+I810_PGETBL_CTL) & 0xfffff000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 global_cache_flush(); /* FIXME: ?? */
865
866 /* we have to call this as early as possible after the MMIO base address is known */
867 intel_i830_init_gtt_entries();
868
869 agp_bridge->gatt_table = NULL;
870
871 agp_bridge->gatt_bus_addr = temp;
872
873 return 0;
874}
875
876/* Return the gatt table to a sane state. Use the top of stolen
877 * memory for the GTT.
878 */
879static int intel_i830_free_gatt_table(struct agp_bridge_data *bridge)
880{
881 return 0;
882}
883
884static int intel_i830_fetch_size(void)
885{
886 u16 gmch_ctrl;
887 struct aper_size_info_fixed *values;
888
889 values = A_SIZE_FIX(agp_bridge->driver->aperture_sizes);
890
891 if (agp_bridge->dev->device != PCI_DEVICE_ID_INTEL_82830_HB &&
892 agp_bridge->dev->device != PCI_DEVICE_ID_INTEL_82845G_HB) {
893 /* 855GM/852GM/865G has 128MB aperture size */
894 agp_bridge->previous_size = agp_bridge->current_size = (void *) values;
895 agp_bridge->aperture_size_idx = 0;
896 return values[0].size;
897 }
898
Dave Airlief011ae72008-01-25 11:23:04 +1000899 pci_read_config_word(agp_bridge->dev, I830_GMCH_CTRL, &gmch_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900
901 if ((gmch_ctrl & I830_GMCH_MEM_MASK) == I830_GMCH_MEM_128M) {
902 agp_bridge->previous_size = agp_bridge->current_size = (void *) values;
903 agp_bridge->aperture_size_idx = 0;
904 return values[0].size;
905 } else {
906 agp_bridge->previous_size = agp_bridge->current_size = (void *) (values + 1);
907 agp_bridge->aperture_size_idx = 1;
908 return values[1].size;
909 }
910
911 return 0;
912}
913
914static int intel_i830_configure(void)
915{
916 struct aper_size_info_fixed *current_size;
917 u32 temp;
918 u16 gmch_ctrl;
919 int i;
920
921 current_size = A_SIZE_FIX(agp_bridge->current_size);
922
Dave Airlief011ae72008-01-25 11:23:04 +1000923 pci_read_config_dword(intel_private.pcidev, I810_GMADDR, &temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
925
Dave Airlief011ae72008-01-25 11:23:04 +1000926 pci_read_config_word(agp_bridge->dev, I830_GMCH_CTRL, &gmch_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 gmch_ctrl |= I830_GMCH_ENABLED;
Dave Airlief011ae72008-01-25 11:23:04 +1000928 pci_write_config_word(agp_bridge->dev, I830_GMCH_CTRL, gmch_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800930 writel(agp_bridge->gatt_bus_addr|I810_PGETBL_ENABLED, intel_private.registers+I810_PGETBL_CTL);
931 readl(intel_private.registers+I810_PGETBL_CTL); /* PCI Posting. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932
933 if (agp_bridge->driver->needs_scratch_page) {
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800934 for (i = intel_private.gtt_entries; i < current_size->num_entries; i++) {
935 writel(agp_bridge->scratch_page, intel_private.registers+I810_PTE_BASE+(i*4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 }
Keith Packard44d49442008-10-14 17:18:45 -0700937 readl(intel_private.registers+I810_PTE_BASE+((i-1)*4)); /* PCI Posting. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 }
939
940 global_cache_flush();
Dave Airlie2162e6a2007-11-21 16:36:31 +1000941
942 intel_i830_setup_flush();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 return 0;
944}
945
946static void intel_i830_cleanup(void)
947{
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800948 iounmap(intel_private.registers);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949}
950
Dave Airlief011ae72008-01-25 11:23:04 +1000951static int intel_i830_insert_entries(struct agp_memory *mem, off_t pg_start,
952 int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953{
Dave Airlief011ae72008-01-25 11:23:04 +1000954 int i, j, num_entries;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 void *temp;
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100956 int ret = -EINVAL;
957 int mask_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +0100959 if (mem->page_count == 0)
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100960 goto out;
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +0100961
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 temp = agp_bridge->current_size;
963 num_entries = A_SIZE_FIX(temp)->num_entries;
964
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800965 if (pg_start < intel_private.gtt_entries) {
Bjorn Helgaase3cf6952008-07-30 12:26:51 -0700966 dev_printk(KERN_DEBUG, &intel_private.pcidev->dev,
967 "pg_start == 0x%.8lx, intel_private.gtt_entries == 0x%.8x\n",
968 pg_start, intel_private.gtt_entries);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969
Bjorn Helgaase3cf6952008-07-30 12:26:51 -0700970 dev_info(&intel_private.pcidev->dev,
971 "trying to insert into local/stolen memory\n");
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100972 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 }
974
975 if ((pg_start + mem->page_count) > num_entries)
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100976 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977
978 /* The i830 can't check the GTT for entries since its read only,
979 * depend on the caller to make the correct offset decisions.
980 */
981
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100982 if (type != mem->type)
983 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100985 mask_type = agp_bridge->driver->agp_type_to_mask_type(agp_bridge, type);
986
987 if (mask_type != 0 && mask_type != AGP_PHYS_MEMORY &&
988 mask_type != INTEL_AGP_CACHED_MEMORY)
989 goto out_err;
990
991 if (!mem->is_flushed)
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +0100992 global_cache_flush();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993
994 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
995 writel(agp_bridge->driver->mask_memory(agp_bridge,
David Woodhouse6a122352009-07-29 10:25:58 +0100996 page_to_phys(mem->pages[i]), mask_type),
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800997 intel_private.registers+I810_PTE_BASE+(j*4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 }
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800999 readl(intel_private.registers+I810_PTE_BASE+((j-1)*4));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 agp_bridge->driver->tlb_flush(mem);
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001001
1002out:
1003 ret = 0;
1004out_err:
Dave Airlie9516b032008-06-19 10:42:17 +10001005 mem->is_flushed = true;
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001006 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007}
1008
Dave Airlief011ae72008-01-25 11:23:04 +10001009static int intel_i830_remove_entries(struct agp_memory *mem, off_t pg_start,
1010 int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011{
1012 int i;
1013
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +01001014 if (mem->page_count == 0)
1015 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001017 if (pg_start < intel_private.gtt_entries) {
Bjorn Helgaase3cf6952008-07-30 12:26:51 -07001018 dev_info(&intel_private.pcidev->dev,
1019 "trying to disable local/stolen memory\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 return -EINVAL;
1021 }
1022
1023 for (i = pg_start; i < (mem->page_count + pg_start); i++) {
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001024 writel(agp_bridge->scratch_page, intel_private.registers+I810_PTE_BASE+(i*4));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 }
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001026 readl(intel_private.registers+I810_PTE_BASE+((i-1)*4));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 agp_bridge->driver->tlb_flush(mem);
1029 return 0;
1030}
1031
Dave Airlief011ae72008-01-25 11:23:04 +10001032static struct agp_memory *intel_i830_alloc_by_type(size_t pg_count, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033{
1034 if (type == AGP_PHYS_MEMORY)
1035 return alloc_agpphysmem_i8xx(pg_count, type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 /* always return NULL for other allocation types for now */
1037 return NULL;
1038}
1039
Dave Airlie6c00a612007-10-29 18:06:10 +10001040static int intel_alloc_chipset_flush_resource(void)
1041{
1042 int ret;
1043 ret = pci_bus_alloc_resource(agp_bridge->dev->bus, &intel_private.ifp_resource, PAGE_SIZE,
1044 PAGE_SIZE, PCIBIOS_MIN_MEM, 0,
1045 pcibios_align_resource, agp_bridge->dev);
Dave Airlie6c00a612007-10-29 18:06:10 +10001046
Dave Airlie2162e6a2007-11-21 16:36:31 +10001047 return ret;
Dave Airlie6c00a612007-10-29 18:06:10 +10001048}
1049
1050static void intel_i915_setup_chipset_flush(void)
1051{
1052 int ret;
1053 u32 temp;
1054
1055 pci_read_config_dword(agp_bridge->dev, I915_IFPADDR, &temp);
1056 if (!(temp & 0x1)) {
1057 intel_alloc_chipset_flush_resource();
Dave Airlie4d64dd92008-01-23 15:34:29 +10001058 intel_private.resource_valid = 1;
Dave Airlie6c00a612007-10-29 18:06:10 +10001059 pci_write_config_dword(agp_bridge->dev, I915_IFPADDR, (intel_private.ifp_resource.start & 0xffffffff) | 0x1);
1060 } else {
1061 temp &= ~1;
1062
Dave Airlie4d64dd92008-01-23 15:34:29 +10001063 intel_private.resource_valid = 1;
Dave Airlie6c00a612007-10-29 18:06:10 +10001064 intel_private.ifp_resource.start = temp;
1065 intel_private.ifp_resource.end = temp + PAGE_SIZE;
1066 ret = request_resource(&iomem_resource, &intel_private.ifp_resource);
Dave Airlie4d64dd92008-01-23 15:34:29 +10001067 /* some BIOSes reserve this area in a pnp some don't */
1068 if (ret)
1069 intel_private.resource_valid = 0;
Dave Airlie6c00a612007-10-29 18:06:10 +10001070 }
1071}
1072
1073static void intel_i965_g33_setup_chipset_flush(void)
1074{
1075 u32 temp_hi, temp_lo;
1076 int ret;
1077
1078 pci_read_config_dword(agp_bridge->dev, I965_IFPADDR + 4, &temp_hi);
1079 pci_read_config_dword(agp_bridge->dev, I965_IFPADDR, &temp_lo);
1080
1081 if (!(temp_lo & 0x1)) {
1082
1083 intel_alloc_chipset_flush_resource();
1084
Dave Airlie4d64dd92008-01-23 15:34:29 +10001085 intel_private.resource_valid = 1;
Andrew Morton1fa4db72007-11-29 10:00:48 +10001086 pci_write_config_dword(agp_bridge->dev, I965_IFPADDR + 4,
1087 upper_32_bits(intel_private.ifp_resource.start));
Dave Airlie6c00a612007-10-29 18:06:10 +10001088 pci_write_config_dword(agp_bridge->dev, I965_IFPADDR, (intel_private.ifp_resource.start & 0xffffffff) | 0x1);
Dave Airlie6c00a612007-10-29 18:06:10 +10001089 } else {
1090 u64 l64;
Dave Airlief011ae72008-01-25 11:23:04 +10001091
Dave Airlie6c00a612007-10-29 18:06:10 +10001092 temp_lo &= ~0x1;
1093 l64 = ((u64)temp_hi << 32) | temp_lo;
1094
Dave Airlie4d64dd92008-01-23 15:34:29 +10001095 intel_private.resource_valid = 1;
Dave Airlie6c00a612007-10-29 18:06:10 +10001096 intel_private.ifp_resource.start = l64;
1097 intel_private.ifp_resource.end = l64 + PAGE_SIZE;
1098 ret = request_resource(&iomem_resource, &intel_private.ifp_resource);
Dave Airlie4d64dd92008-01-23 15:34:29 +10001099 /* some BIOSes reserve this area in a pnp some don't */
1100 if (ret)
1101 intel_private.resource_valid = 0;
Dave Airlie6c00a612007-10-29 18:06:10 +10001102 }
1103}
1104
Dave Airlie2162e6a2007-11-21 16:36:31 +10001105static void intel_i9xx_setup_flush(void)
1106{
Dave Airlie4d64dd92008-01-23 15:34:29 +10001107 /* return if already configured */
1108 if (intel_private.ifp_resource.start)
1109 return;
Dave Airlie2162e6a2007-11-21 16:36:31 +10001110
Dave Airlie4d64dd92008-01-23 15:34:29 +10001111 /* setup a resource for this object */
Dave Airlie2162e6a2007-11-21 16:36:31 +10001112 intel_private.ifp_resource.name = "Intel Flush Page";
1113 intel_private.ifp_resource.flags = IORESOURCE_MEM;
1114
1115 /* Setup chipset flush for 915 */
Zhenyu Wang7d15ddf2008-06-20 11:48:06 +10001116 if (IS_I965 || IS_G33 || IS_G4X) {
Dave Airlie2162e6a2007-11-21 16:36:31 +10001117 intel_i965_g33_setup_chipset_flush();
1118 } else {
1119 intel_i915_setup_chipset_flush();
1120 }
1121
1122 if (intel_private.ifp_resource.start) {
1123 intel_private.i9xx_flush_page = ioremap_nocache(intel_private.ifp_resource.start, PAGE_SIZE);
1124 if (!intel_private.i9xx_flush_page)
Bjorn Helgaase3cf6952008-07-30 12:26:51 -07001125 dev_info(&intel_private.pcidev->dev, "can't ioremap flush page - no chipset flushing");
Dave Airlie2162e6a2007-11-21 16:36:31 +10001126 }
1127}
1128
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129static int intel_i915_configure(void)
1130{
1131 struct aper_size_info_fixed *current_size;
1132 u32 temp;
1133 u16 gmch_ctrl;
1134 int i;
1135
1136 current_size = A_SIZE_FIX(agp_bridge->current_size);
1137
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001138 pci_read_config_dword(intel_private.pcidev, I915_GMADDR, &temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139
1140 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1141
Dave Airlief011ae72008-01-25 11:23:04 +10001142 pci_read_config_word(agp_bridge->dev, I830_GMCH_CTRL, &gmch_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143 gmch_ctrl |= I830_GMCH_ENABLED;
Dave Airlief011ae72008-01-25 11:23:04 +10001144 pci_write_config_word(agp_bridge->dev, I830_GMCH_CTRL, gmch_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001146 writel(agp_bridge->gatt_bus_addr|I810_PGETBL_ENABLED, intel_private.registers+I810_PGETBL_CTL);
1147 readl(intel_private.registers+I810_PGETBL_CTL); /* PCI Posting. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148
1149 if (agp_bridge->driver->needs_scratch_page) {
David Woodhousefc619012009-12-02 11:00:05 +00001150 for (i = intel_private.gtt_entries; i < intel_private.gtt_total_size; i++) {
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001151 writel(agp_bridge->scratch_page, intel_private.gtt+i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 }
Keith Packard44d49442008-10-14 17:18:45 -07001153 readl(intel_private.gtt+i-1); /* PCI Posting. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 }
1155
1156 global_cache_flush();
Dave Airlie6c00a612007-10-29 18:06:10 +10001157
Dave Airlie2162e6a2007-11-21 16:36:31 +10001158 intel_i9xx_setup_flush();
Dave Airlief011ae72008-01-25 11:23:04 +10001159
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 return 0;
1161}
1162
1163static void intel_i915_cleanup(void)
1164{
Dave Airlie2162e6a2007-11-21 16:36:31 +10001165 if (intel_private.i9xx_flush_page)
1166 iounmap(intel_private.i9xx_flush_page);
Dave Airlie4d64dd92008-01-23 15:34:29 +10001167 if (intel_private.resource_valid)
1168 release_resource(&intel_private.ifp_resource);
1169 intel_private.ifp_resource.start = 0;
1170 intel_private.resource_valid = 0;
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001171 iounmap(intel_private.gtt);
1172 iounmap(intel_private.registers);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173}
1174
Dave Airlie6c00a612007-10-29 18:06:10 +10001175static void intel_i915_chipset_flush(struct agp_bridge_data *bridge)
1176{
Dave Airlie2162e6a2007-11-21 16:36:31 +10001177 if (intel_private.i9xx_flush_page)
1178 writel(1, intel_private.i9xx_flush_page);
Dave Airlie6c00a612007-10-29 18:06:10 +10001179}
1180
Dave Airlief011ae72008-01-25 11:23:04 +10001181static int intel_i915_insert_entries(struct agp_memory *mem, off_t pg_start,
1182 int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183{
Zhenyu Wang17661682009-07-27 12:59:57 +01001184 int num_entries;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 void *temp;
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001186 int ret = -EINVAL;
1187 int mask_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +01001189 if (mem->page_count == 0)
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001190 goto out;
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +01001191
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 temp = agp_bridge->current_size;
1193 num_entries = A_SIZE_FIX(temp)->num_entries;
1194
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001195 if (pg_start < intel_private.gtt_entries) {
Bjorn Helgaase3cf6952008-07-30 12:26:51 -07001196 dev_printk(KERN_DEBUG, &intel_private.pcidev->dev,
1197 "pg_start == 0x%.8lx, intel_private.gtt_entries == 0x%.8x\n",
1198 pg_start, intel_private.gtt_entries);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199
Bjorn Helgaase3cf6952008-07-30 12:26:51 -07001200 dev_info(&intel_private.pcidev->dev,
1201 "trying to insert into local/stolen memory\n");
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001202 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 }
1204
1205 if ((pg_start + mem->page_count) > num_entries)
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001206 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207
Zhenyu Wang17661682009-07-27 12:59:57 +01001208 /* The i915 can't check the GTT for entries since it's read only;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 * depend on the caller to make the correct offset decisions.
1210 */
1211
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001212 if (type != mem->type)
1213 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001215 mask_type = agp_bridge->driver->agp_type_to_mask_type(agp_bridge, type);
1216
1217 if (mask_type != 0 && mask_type != AGP_PHYS_MEMORY &&
1218 mask_type != INTEL_AGP_CACHED_MEMORY)
1219 goto out_err;
1220
1221 if (!mem->is_flushed)
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +01001222 global_cache_flush();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223
Zhenyu Wang17661682009-07-27 12:59:57 +01001224 intel_agp_insert_sg_entries(mem, pg_start, mask_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225 agp_bridge->driver->tlb_flush(mem);
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001226
1227 out:
1228 ret = 0;
1229 out_err:
Dave Airlie9516b032008-06-19 10:42:17 +10001230 mem->is_flushed = true;
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001231 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232}
1233
Dave Airlief011ae72008-01-25 11:23:04 +10001234static int intel_i915_remove_entries(struct agp_memory *mem, off_t pg_start,
1235 int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236{
1237 int i;
1238
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +01001239 if (mem->page_count == 0)
1240 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001242 if (pg_start < intel_private.gtt_entries) {
Bjorn Helgaase3cf6952008-07-30 12:26:51 -07001243 dev_info(&intel_private.pcidev->dev,
1244 "trying to disable local/stolen memory\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245 return -EINVAL;
1246 }
1247
Dave Airlief011ae72008-01-25 11:23:04 +10001248 for (i = pg_start; i < (mem->page_count + pg_start); i++)
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001249 writel(agp_bridge->scratch_page, intel_private.gtt+i);
Dave Airlief011ae72008-01-25 11:23:04 +10001250
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001251 readl(intel_private.gtt+i-1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 agp_bridge->driver->tlb_flush(mem);
1254 return 0;
1255}
1256
Eric Anholtc41e0de2006-12-19 12:57:24 -08001257/* Return the aperture size by just checking the resource length. The effect
1258 * described in the spec of the MSAC registers is just changing of the
1259 * resource size.
1260 */
1261static int intel_i9xx_fetch_size(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262{
Ahmed S. Darwish1eaf1222007-02-06 18:08:28 +02001263 int num_sizes = ARRAY_SIZE(intel_i830_sizes);
Eric Anholtc41e0de2006-12-19 12:57:24 -08001264 int aper_size; /* size in megabytes */
1265 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001267 aper_size = pci_resource_len(intel_private.pcidev, 2) / MB(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268
Eric Anholtc41e0de2006-12-19 12:57:24 -08001269 for (i = 0; i < num_sizes; i++) {
1270 if (aper_size == intel_i830_sizes[i].size) {
1271 agp_bridge->current_size = intel_i830_sizes + i;
1272 agp_bridge->previous_size = agp_bridge->current_size;
1273 return aper_size;
1274 }
1275 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276
Eric Anholtc41e0de2006-12-19 12:57:24 -08001277 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278}
1279
1280/* The intel i915 automatically initializes the agp aperture during POST.
1281 * Use the memory already set aside for in the GTT.
1282 */
1283static int intel_i915_create_gatt_table(struct agp_bridge_data *bridge)
1284{
1285 int page_order;
1286 struct aper_size_info_fixed *size;
1287 int num_entries;
1288 u32 temp, temp2;
Zhenyu Wang47406222007-09-11 15:23:58 -07001289 int gtt_map_size = 256 * 1024;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290
1291 size = agp_bridge->current_size;
1292 page_order = size->page_order;
1293 num_entries = size->num_entries;
1294 agp_bridge->gatt_table_real = NULL;
1295
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001296 pci_read_config_dword(intel_private.pcidev, I915_MMADDR, &temp);
Dave Airlief011ae72008-01-25 11:23:04 +10001297 pci_read_config_dword(intel_private.pcidev, I915_PTEADDR, &temp2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298
Zhenyu Wang47406222007-09-11 15:23:58 -07001299 if (IS_G33)
1300 gtt_map_size = 1024 * 1024; /* 1M on G33 */
1301 intel_private.gtt = ioremap(temp2, gtt_map_size);
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001302 if (!intel_private.gtt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 return -ENOMEM;
1304
David Woodhousefc619012009-12-02 11:00:05 +00001305 intel_private.gtt_total_size = gtt_map_size / 4;
1306
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 temp &= 0xfff80000;
1308
Dave Airlief011ae72008-01-25 11:23:04 +10001309 intel_private.registers = ioremap(temp, 128 * 4096);
Scott Thompson5bdbc7d2007-08-25 18:14:00 +10001310 if (!intel_private.registers) {
1311 iounmap(intel_private.gtt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 return -ENOMEM;
Scott Thompson5bdbc7d2007-08-25 18:14:00 +10001313 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001315 temp = readl(intel_private.registers+I810_PGETBL_CTL) & 0xfffff000;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316 global_cache_flush(); /* FIXME: ? */
1317
1318 /* we have to call this as early as possible after the MMIO base address is known */
1319 intel_i830_init_gtt_entries();
1320
1321 agp_bridge->gatt_table = NULL;
1322
1323 agp_bridge->gatt_bus_addr = temp;
1324
1325 return 0;
1326}
Linus Torvalds7d915a32006-11-22 09:37:54 -08001327
1328/*
1329 * The i965 supports 36-bit physical addresses, but to keep
1330 * the format of the GTT the same, the bits that don't fit
1331 * in a 32-bit word are shifted down to bits 4..7.
1332 *
1333 * Gcc is smart enough to notice that "(addr >> 28) & 0xf0"
1334 * is always zero on 32-bit architectures, so no need to make
1335 * this conditional.
1336 */
1337static unsigned long intel_i965_mask_memory(struct agp_bridge_data *bridge,
David Woodhouse2a4ceb62009-07-27 10:27:29 +01001338 dma_addr_t addr, int type)
Linus Torvalds7d915a32006-11-22 09:37:54 -08001339{
1340 /* Shift high bits down */
1341 addr |= (addr >> 28) & 0xf0;
1342
1343 /* Type checking must be done elsewhere */
1344 return addr | bridge->driver->masks[type].mask;
1345}
1346
Zhenyu Wang25ce77a2008-06-19 14:17:58 +10001347static void intel_i965_get_gtt_range(int *gtt_offset, int *gtt_size)
1348{
1349 switch (agp_bridge->dev->device) {
Zhenyu Wang99d32bd2008-07-30 12:26:50 -07001350 case PCI_DEVICE_ID_INTEL_GM45_HB:
Adam Jackson107f5172009-12-03 17:14:41 -05001351 case PCI_DEVICE_ID_INTEL_EAGLELAKE_HB:
Zhenyu Wang25ce77a2008-06-19 14:17:58 +10001352 case PCI_DEVICE_ID_INTEL_Q45_HB:
1353 case PCI_DEVICE_ID_INTEL_G45_HB:
Zhenyu Wanga50ccc62008-11-17 14:39:00 +08001354 case PCI_DEVICE_ID_INTEL_G41_HB:
Fabian Henze38d8a952009-09-08 00:59:58 +08001355 case PCI_DEVICE_ID_INTEL_B43_HB:
Adam Jackson107f5172009-12-03 17:14:41 -05001356 case PCI_DEVICE_ID_INTEL_IRONLAKE_D_HB:
1357 case PCI_DEVICE_ID_INTEL_IRONLAKE_M_HB:
1358 case PCI_DEVICE_ID_INTEL_IRONLAKE_MA_HB:
Dave Airlie3ff99162009-12-08 14:03:47 +10001359 case PCI_DEVICE_ID_INTEL_IRONLAKE_MC2_HB:
Zhenyu Wang25ce77a2008-06-19 14:17:58 +10001360 *gtt_offset = *gtt_size = MB(2);
1361 break;
1362 default:
1363 *gtt_offset = *gtt_size = KB(512);
1364 }
1365}
1366
Eric Anholt65c25aa2006-09-06 11:57:18 -04001367/* The intel i965 automatically initializes the agp aperture during POST.
Eric Anholtc41e0de2006-12-19 12:57:24 -08001368 * Use the memory already set aside for in the GTT.
1369 */
Eric Anholt65c25aa2006-09-06 11:57:18 -04001370static int intel_i965_create_gatt_table(struct agp_bridge_data *bridge)
1371{
Dave Airlie62c96b92008-06-19 14:27:53 +10001372 int page_order;
1373 struct aper_size_info_fixed *size;
1374 int num_entries;
1375 u32 temp;
1376 int gtt_offset, gtt_size;
Eric Anholt65c25aa2006-09-06 11:57:18 -04001377
Dave Airlie62c96b92008-06-19 14:27:53 +10001378 size = agp_bridge->current_size;
1379 page_order = size->page_order;
1380 num_entries = size->num_entries;
1381 agp_bridge->gatt_table_real = NULL;
Eric Anholt65c25aa2006-09-06 11:57:18 -04001382
Dave Airlie62c96b92008-06-19 14:27:53 +10001383 pci_read_config_dword(intel_private.pcidev, I915_MMADDR, &temp);
Eric Anholt65c25aa2006-09-06 11:57:18 -04001384
Dave Airlie62c96b92008-06-19 14:27:53 +10001385 temp &= 0xfff00000;
Eric Anholt65c25aa2006-09-06 11:57:18 -04001386
Zhenyu Wang25ce77a2008-06-19 14:17:58 +10001387 intel_i965_get_gtt_range(&gtt_offset, &gtt_size);
Eric Anholt65c25aa2006-09-06 11:57:18 -04001388
Dave Airlie62c96b92008-06-19 14:27:53 +10001389 intel_private.gtt = ioremap((temp + gtt_offset) , gtt_size);
Eric Anholt65c25aa2006-09-06 11:57:18 -04001390
Dave Airlie62c96b92008-06-19 14:27:53 +10001391 if (!intel_private.gtt)
1392 return -ENOMEM;
Zhenyu Wang4e8b6e22008-01-23 14:54:37 +10001393
David Woodhousefc619012009-12-02 11:00:05 +00001394 intel_private.gtt_total_size = gtt_size / 4;
1395
Dave Airlie62c96b92008-06-19 14:27:53 +10001396 intel_private.registers = ioremap(temp, 128 * 4096);
1397 if (!intel_private.registers) {
Scott Thompson5bdbc7d2007-08-25 18:14:00 +10001398 iounmap(intel_private.gtt);
1399 return -ENOMEM;
1400 }
Eric Anholt65c25aa2006-09-06 11:57:18 -04001401
Dave Airlie62c96b92008-06-19 14:27:53 +10001402 temp = readl(intel_private.registers+I810_PGETBL_CTL) & 0xfffff000;
1403 global_cache_flush(); /* FIXME: ? */
Eric Anholt65c25aa2006-09-06 11:57:18 -04001404
Dave Airlie62c96b92008-06-19 14:27:53 +10001405 /* we have to call this as early as possible after the MMIO base address is known */
1406 intel_i830_init_gtt_entries();
Eric Anholt65c25aa2006-09-06 11:57:18 -04001407
Dave Airlie62c96b92008-06-19 14:27:53 +10001408 agp_bridge->gatt_table = NULL;
Eric Anholt65c25aa2006-09-06 11:57:18 -04001409
Dave Airlie62c96b92008-06-19 14:27:53 +10001410 agp_bridge->gatt_bus_addr = temp;
Eric Anholt65c25aa2006-09-06 11:57:18 -04001411
Dave Airlie62c96b92008-06-19 14:27:53 +10001412 return 0;
Eric Anholt65c25aa2006-09-06 11:57:18 -04001413}
1414
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415
1416static int intel_fetch_size(void)
1417{
1418 int i;
1419 u16 temp;
1420 struct aper_size_info_16 *values;
1421
1422 pci_read_config_word(agp_bridge->dev, INTEL_APSIZE, &temp);
1423 values = A_SIZE_16(agp_bridge->driver->aperture_sizes);
1424
1425 for (i = 0; i < agp_bridge->driver->num_aperture_sizes; i++) {
1426 if (temp == values[i].size_value) {
1427 agp_bridge->previous_size = agp_bridge->current_size = (void *) (values + i);
1428 agp_bridge->aperture_size_idx = i;
1429 return values[i].size;
1430 }
1431 }
1432
1433 return 0;
1434}
1435
1436static int __intel_8xx_fetch_size(u8 temp)
1437{
1438 int i;
1439 struct aper_size_info_8 *values;
1440
1441 values = A_SIZE_8(agp_bridge->driver->aperture_sizes);
1442
1443 for (i = 0; i < agp_bridge->driver->num_aperture_sizes; i++) {
1444 if (temp == values[i].size_value) {
1445 agp_bridge->previous_size =
1446 agp_bridge->current_size = (void *) (values + i);
1447 agp_bridge->aperture_size_idx = i;
1448 return values[i].size;
1449 }
1450 }
1451 return 0;
1452}
1453
1454static int intel_8xx_fetch_size(void)
1455{
1456 u8 temp;
1457
1458 pci_read_config_byte(agp_bridge->dev, INTEL_APSIZE, &temp);
1459 return __intel_8xx_fetch_size(temp);
1460}
1461
1462static int intel_815_fetch_size(void)
1463{
1464 u8 temp;
1465
1466 /* Intel 815 chipsets have a _weird_ APSIZE register with only
1467 * one non-reserved bit, so mask the others out ... */
1468 pci_read_config_byte(agp_bridge->dev, INTEL_APSIZE, &temp);
1469 temp &= (1 << 3);
1470
1471 return __intel_8xx_fetch_size(temp);
1472}
1473
1474static void intel_tlbflush(struct agp_memory *mem)
1475{
1476 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x2200);
1477 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x2280);
1478}
1479
1480
1481static void intel_8xx_tlbflush(struct agp_memory *mem)
1482{
1483 u32 temp;
1484 pci_read_config_dword(agp_bridge->dev, INTEL_AGPCTRL, &temp);
1485 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, temp & ~(1 << 7));
1486 pci_read_config_dword(agp_bridge->dev, INTEL_AGPCTRL, &temp);
1487 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, temp | (1 << 7));
1488}
1489
1490
1491static void intel_cleanup(void)
1492{
1493 u16 temp;
1494 struct aper_size_info_16 *previous_size;
1495
1496 previous_size = A_SIZE_16(agp_bridge->previous_size);
1497 pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp);
1498 pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG, temp & ~(1 << 9));
1499 pci_write_config_word(agp_bridge->dev, INTEL_APSIZE, previous_size->size_value);
1500}
1501
1502
1503static void intel_8xx_cleanup(void)
1504{
1505 u16 temp;
1506 struct aper_size_info_8 *previous_size;
1507
1508 previous_size = A_SIZE_8(agp_bridge->previous_size);
1509 pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp);
1510 pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG, temp & ~(1 << 9));
1511 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, previous_size->size_value);
1512}
1513
1514
1515static int intel_configure(void)
1516{
1517 u32 temp;
1518 u16 temp2;
1519 struct aper_size_info_16 *current_size;
1520
1521 current_size = A_SIZE_16(agp_bridge->current_size);
1522
1523 /* aperture size */
1524 pci_write_config_word(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1525
1526 /* address to map to */
1527 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1528 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1529
1530 /* attbase - aperture base */
1531 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1532
1533 /* agpctrl */
1534 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x2280);
1535
1536 /* paccfg/nbxcfg */
1537 pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp2);
1538 pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG,
1539 (temp2 & ~(1 << 10)) | (1 << 9));
1540 /* clear any possible error conditions */
1541 pci_write_config_byte(agp_bridge->dev, INTEL_ERRSTS + 1, 7);
1542 return 0;
1543}
1544
1545static int intel_815_configure(void)
1546{
1547 u32 temp, addr;
1548 u8 temp2;
1549 struct aper_size_info_8 *current_size;
1550
1551 /* attbase - aperture base */
1552 /* the Intel 815 chipset spec. says that bits 29-31 in the
1553 * ATTBASE register are reserved -> try not to write them */
1554 if (agp_bridge->gatt_bus_addr & INTEL_815_ATTBASE_MASK) {
Bjorn Helgaase3cf6952008-07-30 12:26:51 -07001555 dev_emerg(&agp_bridge->dev->dev, "gatt bus addr too high");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556 return -EINVAL;
1557 }
1558
1559 current_size = A_SIZE_8(agp_bridge->current_size);
1560
1561 /* aperture size */
1562 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE,
1563 current_size->size_value);
1564
1565 /* address to map to */
1566 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1567 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1568
1569 pci_read_config_dword(agp_bridge->dev, INTEL_ATTBASE, &addr);
1570 addr &= INTEL_815_ATTBASE_MASK;
1571 addr |= agp_bridge->gatt_bus_addr;
1572 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, addr);
1573
1574 /* agpctrl */
1575 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1576
1577 /* apcont */
1578 pci_read_config_byte(agp_bridge->dev, INTEL_815_APCONT, &temp2);
1579 pci_write_config_byte(agp_bridge->dev, INTEL_815_APCONT, temp2 | (1 << 1));
1580
1581 /* clear any possible error conditions */
1582 /* Oddness : this chipset seems to have no ERRSTS register ! */
1583 return 0;
1584}
1585
1586static void intel_820_tlbflush(struct agp_memory *mem)
1587{
1588 return;
1589}
1590
1591static void intel_820_cleanup(void)
1592{
1593 u8 temp;
1594 struct aper_size_info_8 *previous_size;
1595
1596 previous_size = A_SIZE_8(agp_bridge->previous_size);
1597 pci_read_config_byte(agp_bridge->dev, INTEL_I820_RDCR, &temp);
1598 pci_write_config_byte(agp_bridge->dev, INTEL_I820_RDCR,
1599 temp & ~(1 << 1));
1600 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE,
1601 previous_size->size_value);
1602}
1603
1604
1605static int intel_820_configure(void)
1606{
1607 u32 temp;
1608 u8 temp2;
1609 struct aper_size_info_8 *current_size;
1610
1611 current_size = A_SIZE_8(agp_bridge->current_size);
1612
1613 /* aperture size */
1614 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1615
1616 /* address to map to */
1617 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1618 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1619
1620 /* attbase - aperture base */
1621 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1622
1623 /* agpctrl */
1624 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1625
1626 /* global enable aperture access */
1627 /* This flag is not accessed through MCHCFG register as in */
1628 /* i850 chipset. */
1629 pci_read_config_byte(agp_bridge->dev, INTEL_I820_RDCR, &temp2);
1630 pci_write_config_byte(agp_bridge->dev, INTEL_I820_RDCR, temp2 | (1 << 1));
1631 /* clear any possible AGP-related error conditions */
1632 pci_write_config_word(agp_bridge->dev, INTEL_I820_ERRSTS, 0x001c);
1633 return 0;
1634}
1635
1636static int intel_840_configure(void)
1637{
1638 u32 temp;
1639 u16 temp2;
1640 struct aper_size_info_8 *current_size;
1641
1642 current_size = A_SIZE_8(agp_bridge->current_size);
1643
1644 /* aperture size */
1645 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1646
1647 /* address to map to */
1648 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1649 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1650
1651 /* attbase - aperture base */
1652 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1653
1654 /* agpctrl */
1655 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1656
1657 /* mcgcfg */
1658 pci_read_config_word(agp_bridge->dev, INTEL_I840_MCHCFG, &temp2);
1659 pci_write_config_word(agp_bridge->dev, INTEL_I840_MCHCFG, temp2 | (1 << 9));
1660 /* clear any possible error conditions */
1661 pci_write_config_word(agp_bridge->dev, INTEL_I840_ERRSTS, 0xc000);
1662 return 0;
1663}
1664
1665static int intel_845_configure(void)
1666{
1667 u32 temp;
1668 u8 temp2;
1669 struct aper_size_info_8 *current_size;
1670
1671 current_size = A_SIZE_8(agp_bridge->current_size);
1672
1673 /* aperture size */
1674 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1675
Matthew Garrettb0825482005-07-29 14:03:39 -07001676 if (agp_bridge->apbase_config != 0) {
1677 pci_write_config_dword(agp_bridge->dev, AGP_APBASE,
1678 agp_bridge->apbase_config);
1679 } else {
1680 /* address to map to */
1681 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1682 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1683 agp_bridge->apbase_config = temp;
1684 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685
1686 /* attbase - aperture base */
1687 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1688
1689 /* agpctrl */
1690 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1691
1692 /* agpm */
1693 pci_read_config_byte(agp_bridge->dev, INTEL_I845_AGPM, &temp2);
1694 pci_write_config_byte(agp_bridge->dev, INTEL_I845_AGPM, temp2 | (1 << 1));
1695 /* clear any possible error conditions */
1696 pci_write_config_word(agp_bridge->dev, INTEL_I845_ERRSTS, 0x001c);
Dave Airlie2162e6a2007-11-21 16:36:31 +10001697
1698 intel_i830_setup_flush();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699 return 0;
1700}
1701
1702static int intel_850_configure(void)
1703{
1704 u32 temp;
1705 u16 temp2;
1706 struct aper_size_info_8 *current_size;
1707
1708 current_size = A_SIZE_8(agp_bridge->current_size);
1709
1710 /* aperture size */
1711 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1712
1713 /* address to map to */
1714 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1715 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1716
1717 /* attbase - aperture base */
1718 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1719
1720 /* agpctrl */
1721 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1722
1723 /* mcgcfg */
1724 pci_read_config_word(agp_bridge->dev, INTEL_I850_MCHCFG, &temp2);
1725 pci_write_config_word(agp_bridge->dev, INTEL_I850_MCHCFG, temp2 | (1 << 9));
1726 /* clear any possible AGP-related error conditions */
1727 pci_write_config_word(agp_bridge->dev, INTEL_I850_ERRSTS, 0x001c);
1728 return 0;
1729}
1730
1731static int intel_860_configure(void)
1732{
1733 u32 temp;
1734 u16 temp2;
1735 struct aper_size_info_8 *current_size;
1736
1737 current_size = A_SIZE_8(agp_bridge->current_size);
1738
1739 /* aperture size */
1740 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1741
1742 /* address to map to */
1743 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1744 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1745
1746 /* attbase - aperture base */
1747 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1748
1749 /* agpctrl */
1750 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1751
1752 /* mcgcfg */
1753 pci_read_config_word(agp_bridge->dev, INTEL_I860_MCHCFG, &temp2);
1754 pci_write_config_word(agp_bridge->dev, INTEL_I860_MCHCFG, temp2 | (1 << 9));
1755 /* clear any possible AGP-related error conditions */
1756 pci_write_config_word(agp_bridge->dev, INTEL_I860_ERRSTS, 0xf700);
1757 return 0;
1758}
1759
1760static int intel_830mp_configure(void)
1761{
1762 u32 temp;
1763 u16 temp2;
1764 struct aper_size_info_8 *current_size;
1765
1766 current_size = A_SIZE_8(agp_bridge->current_size);
1767
1768 /* aperture size */
1769 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1770
1771 /* address to map to */
1772 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1773 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1774
1775 /* attbase - aperture base */
1776 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1777
1778 /* agpctrl */
1779 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1780
1781 /* gmch */
1782 pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp2);
1783 pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG, temp2 | (1 << 9));
1784 /* clear any possible AGP-related error conditions */
1785 pci_write_config_word(agp_bridge->dev, INTEL_I830_ERRSTS, 0x1c);
1786 return 0;
1787}
1788
1789static int intel_7505_configure(void)
1790{
1791 u32 temp;
1792 u16 temp2;
1793 struct aper_size_info_8 *current_size;
1794
1795 current_size = A_SIZE_8(agp_bridge->current_size);
1796
1797 /* aperture size */
1798 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1799
1800 /* address to map to */
1801 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1802 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1803
1804 /* attbase - aperture base */
1805 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1806
1807 /* agpctrl */
1808 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1809
1810 /* mchcfg */
1811 pci_read_config_word(agp_bridge->dev, INTEL_I7505_MCHCFG, &temp2);
1812 pci_write_config_word(agp_bridge->dev, INTEL_I7505_MCHCFG, temp2 | (1 << 9));
1813
1814 return 0;
1815}
1816
1817/* Setup function */
Dave Jonese5524f32007-02-22 18:41:28 -05001818static const struct gatt_mask intel_generic_masks[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819{
1820 {.mask = 0x00000017, .type = 0}
1821};
1822
Dave Jonese5524f32007-02-22 18:41:28 -05001823static const struct aper_size_info_8 intel_815_sizes[2] =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824{
1825 {64, 16384, 4, 0},
1826 {32, 8192, 3, 8},
1827};
1828
Dave Jonese5524f32007-02-22 18:41:28 -05001829static const struct aper_size_info_8 intel_8xx_sizes[7] =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830{
1831 {256, 65536, 6, 0},
1832 {128, 32768, 5, 32},
1833 {64, 16384, 4, 48},
1834 {32, 8192, 3, 56},
1835 {16, 4096, 2, 60},
1836 {8, 2048, 1, 62},
1837 {4, 1024, 0, 63}
1838};
1839
Dave Jonese5524f32007-02-22 18:41:28 -05001840static const struct aper_size_info_16 intel_generic_sizes[7] =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841{
1842 {256, 65536, 6, 0},
1843 {128, 32768, 5, 32},
1844 {64, 16384, 4, 48},
1845 {32, 8192, 3, 56},
1846 {16, 4096, 2, 60},
1847 {8, 2048, 1, 62},
1848 {4, 1024, 0, 63}
1849};
1850
Dave Jonese5524f32007-02-22 18:41:28 -05001851static const struct aper_size_info_8 intel_830mp_sizes[4] =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852{
1853 {256, 65536, 6, 0},
1854 {128, 32768, 5, 32},
1855 {64, 16384, 4, 48},
1856 {32, 8192, 3, 56}
1857};
1858
Dave Jonese5524f32007-02-22 18:41:28 -05001859static const struct agp_bridge_driver intel_generic_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860 .owner = THIS_MODULE,
1861 .aperture_sizes = intel_generic_sizes,
1862 .size_type = U16_APER_SIZE,
1863 .num_aperture_sizes = 7,
1864 .configure = intel_configure,
1865 .fetch_size = intel_fetch_size,
1866 .cleanup = intel_cleanup,
1867 .tlb_flush = intel_tlbflush,
1868 .mask_memory = agp_generic_mask_memory,
1869 .masks = intel_generic_masks,
1870 .agp_enable = agp_generic_enable,
1871 .cache_flush = global_cache_flush,
1872 .create_gatt_table = agp_generic_create_gatt_table,
1873 .free_gatt_table = agp_generic_free_gatt_table,
1874 .insert_memory = agp_generic_insert_memory,
1875 .remove_memory = agp_generic_remove_memory,
1876 .alloc_by_type = agp_generic_alloc_by_type,
1877 .free_by_type = agp_generic_free_by_type,
1878 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08001879 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08001881 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001882 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883};
1884
Dave Jonese5524f32007-02-22 18:41:28 -05001885static const struct agp_bridge_driver intel_810_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886 .owner = THIS_MODULE,
1887 .aperture_sizes = intel_i810_sizes,
1888 .size_type = FIXED_APER_SIZE,
1889 .num_aperture_sizes = 2,
Joe Perchesc7258012008-03-26 14:10:02 -07001890 .needs_scratch_page = true,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 .configure = intel_i810_configure,
1892 .fetch_size = intel_i810_fetch_size,
1893 .cleanup = intel_i810_cleanup,
1894 .tlb_flush = intel_i810_tlbflush,
1895 .mask_memory = intel_i810_mask_memory,
1896 .masks = intel_i810_masks,
1897 .agp_enable = intel_i810_agp_enable,
1898 .cache_flush = global_cache_flush,
1899 .create_gatt_table = agp_generic_create_gatt_table,
1900 .free_gatt_table = agp_generic_free_gatt_table,
1901 .insert_memory = intel_i810_insert_entries,
1902 .remove_memory = intel_i810_remove_entries,
1903 .alloc_by_type = intel_i810_alloc_by_type,
1904 .free_by_type = intel_i810_free_by_type,
1905 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08001906 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08001908 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001909 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910};
1911
Dave Jonese5524f32007-02-22 18:41:28 -05001912static const struct agp_bridge_driver intel_815_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913 .owner = THIS_MODULE,
1914 .aperture_sizes = intel_815_sizes,
1915 .size_type = U8_APER_SIZE,
1916 .num_aperture_sizes = 2,
1917 .configure = intel_815_configure,
1918 .fetch_size = intel_815_fetch_size,
1919 .cleanup = intel_8xx_cleanup,
1920 .tlb_flush = intel_8xx_tlbflush,
1921 .mask_memory = agp_generic_mask_memory,
1922 .masks = intel_generic_masks,
1923 .agp_enable = agp_generic_enable,
1924 .cache_flush = global_cache_flush,
1925 .create_gatt_table = agp_generic_create_gatt_table,
1926 .free_gatt_table = agp_generic_free_gatt_table,
1927 .insert_memory = agp_generic_insert_memory,
1928 .remove_memory = agp_generic_remove_memory,
1929 .alloc_by_type = agp_generic_alloc_by_type,
1930 .free_by_type = agp_generic_free_by_type,
1931 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08001932 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08001934 .agp_destroy_pages = agp_generic_destroy_pages,
Dave Airlie62c96b92008-06-19 14:27:53 +10001935 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936};
1937
Dave Jonese5524f32007-02-22 18:41:28 -05001938static const struct agp_bridge_driver intel_830_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939 .owner = THIS_MODULE,
1940 .aperture_sizes = intel_i830_sizes,
1941 .size_type = FIXED_APER_SIZE,
Dave Jonesc14635e2006-09-06 11:59:35 -04001942 .num_aperture_sizes = 4,
Joe Perchesc7258012008-03-26 14:10:02 -07001943 .needs_scratch_page = true,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 .configure = intel_i830_configure,
1945 .fetch_size = intel_i830_fetch_size,
1946 .cleanup = intel_i830_cleanup,
1947 .tlb_flush = intel_i810_tlbflush,
1948 .mask_memory = intel_i810_mask_memory,
1949 .masks = intel_i810_masks,
1950 .agp_enable = intel_i810_agp_enable,
1951 .cache_flush = global_cache_flush,
1952 .create_gatt_table = intel_i830_create_gatt_table,
1953 .free_gatt_table = intel_i830_free_gatt_table,
1954 .insert_memory = intel_i830_insert_entries,
1955 .remove_memory = intel_i830_remove_entries,
1956 .alloc_by_type = intel_i830_alloc_by_type,
1957 .free_by_type = intel_i810_free_by_type,
1958 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08001959 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08001961 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001962 .agp_type_to_mask_type = intel_i830_type_to_mask_type,
Dave Airlie2162e6a2007-11-21 16:36:31 +10001963 .chipset_flush = intel_i830_chipset_flush,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964};
1965
Dave Jonese5524f32007-02-22 18:41:28 -05001966static const struct agp_bridge_driver intel_820_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967 .owner = THIS_MODULE,
1968 .aperture_sizes = intel_8xx_sizes,
1969 .size_type = U8_APER_SIZE,
1970 .num_aperture_sizes = 7,
1971 .configure = intel_820_configure,
1972 .fetch_size = intel_8xx_fetch_size,
1973 .cleanup = intel_820_cleanup,
1974 .tlb_flush = intel_820_tlbflush,
1975 .mask_memory = agp_generic_mask_memory,
1976 .masks = intel_generic_masks,
1977 .agp_enable = agp_generic_enable,
1978 .cache_flush = global_cache_flush,
1979 .create_gatt_table = agp_generic_create_gatt_table,
1980 .free_gatt_table = agp_generic_free_gatt_table,
1981 .insert_memory = agp_generic_insert_memory,
1982 .remove_memory = agp_generic_remove_memory,
1983 .alloc_by_type = agp_generic_alloc_by_type,
1984 .free_by_type = agp_generic_free_by_type,
1985 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08001986 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08001988 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001989 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990};
1991
Dave Jonese5524f32007-02-22 18:41:28 -05001992static const struct agp_bridge_driver intel_830mp_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993 .owner = THIS_MODULE,
1994 .aperture_sizes = intel_830mp_sizes,
1995 .size_type = U8_APER_SIZE,
1996 .num_aperture_sizes = 4,
1997 .configure = intel_830mp_configure,
1998 .fetch_size = intel_8xx_fetch_size,
1999 .cleanup = intel_8xx_cleanup,
2000 .tlb_flush = intel_8xx_tlbflush,
2001 .mask_memory = agp_generic_mask_memory,
2002 .masks = intel_generic_masks,
2003 .agp_enable = agp_generic_enable,
2004 .cache_flush = global_cache_flush,
2005 .create_gatt_table = agp_generic_create_gatt_table,
2006 .free_gatt_table = agp_generic_free_gatt_table,
2007 .insert_memory = agp_generic_insert_memory,
2008 .remove_memory = agp_generic_remove_memory,
2009 .alloc_by_type = agp_generic_alloc_by_type,
2010 .free_by_type = agp_generic_free_by_type,
2011 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08002012 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08002014 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01002015 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016};
2017
Dave Jonese5524f32007-02-22 18:41:28 -05002018static const struct agp_bridge_driver intel_840_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019 .owner = THIS_MODULE,
2020 .aperture_sizes = intel_8xx_sizes,
2021 .size_type = U8_APER_SIZE,
2022 .num_aperture_sizes = 7,
2023 .configure = intel_840_configure,
2024 .fetch_size = intel_8xx_fetch_size,
2025 .cleanup = intel_8xx_cleanup,
2026 .tlb_flush = intel_8xx_tlbflush,
2027 .mask_memory = agp_generic_mask_memory,
2028 .masks = intel_generic_masks,
2029 .agp_enable = agp_generic_enable,
2030 .cache_flush = global_cache_flush,
2031 .create_gatt_table = agp_generic_create_gatt_table,
2032 .free_gatt_table = agp_generic_free_gatt_table,
2033 .insert_memory = agp_generic_insert_memory,
2034 .remove_memory = agp_generic_remove_memory,
2035 .alloc_by_type = agp_generic_alloc_by_type,
2036 .free_by_type = agp_generic_free_by_type,
2037 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08002038 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08002040 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01002041 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042};
2043
Dave Jonese5524f32007-02-22 18:41:28 -05002044static const struct agp_bridge_driver intel_845_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045 .owner = THIS_MODULE,
2046 .aperture_sizes = intel_8xx_sizes,
2047 .size_type = U8_APER_SIZE,
2048 .num_aperture_sizes = 7,
2049 .configure = intel_845_configure,
2050 .fetch_size = intel_8xx_fetch_size,
2051 .cleanup = intel_8xx_cleanup,
2052 .tlb_flush = intel_8xx_tlbflush,
2053 .mask_memory = agp_generic_mask_memory,
2054 .masks = intel_generic_masks,
2055 .agp_enable = agp_generic_enable,
2056 .cache_flush = global_cache_flush,
2057 .create_gatt_table = agp_generic_create_gatt_table,
2058 .free_gatt_table = agp_generic_free_gatt_table,
2059 .insert_memory = agp_generic_insert_memory,
2060 .remove_memory = agp_generic_remove_memory,
2061 .alloc_by_type = agp_generic_alloc_by_type,
2062 .free_by_type = agp_generic_free_by_type,
2063 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08002064 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08002066 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01002067 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Dave Airlie2162e6a2007-11-21 16:36:31 +10002068 .chipset_flush = intel_i830_chipset_flush,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069};
2070
Dave Jonese5524f32007-02-22 18:41:28 -05002071static const struct agp_bridge_driver intel_850_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072 .owner = THIS_MODULE,
2073 .aperture_sizes = intel_8xx_sizes,
2074 .size_type = U8_APER_SIZE,
2075 .num_aperture_sizes = 7,
2076 .configure = intel_850_configure,
2077 .fetch_size = intel_8xx_fetch_size,
2078 .cleanup = intel_8xx_cleanup,
2079 .tlb_flush = intel_8xx_tlbflush,
2080 .mask_memory = agp_generic_mask_memory,
2081 .masks = intel_generic_masks,
2082 .agp_enable = agp_generic_enable,
2083 .cache_flush = global_cache_flush,
2084 .create_gatt_table = agp_generic_create_gatt_table,
2085 .free_gatt_table = agp_generic_free_gatt_table,
2086 .insert_memory = agp_generic_insert_memory,
2087 .remove_memory = agp_generic_remove_memory,
2088 .alloc_by_type = agp_generic_alloc_by_type,
2089 .free_by_type = agp_generic_free_by_type,
2090 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08002091 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08002093 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01002094 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095};
2096
Dave Jonese5524f32007-02-22 18:41:28 -05002097static const struct agp_bridge_driver intel_860_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 .owner = THIS_MODULE,
2099 .aperture_sizes = intel_8xx_sizes,
2100 .size_type = U8_APER_SIZE,
2101 .num_aperture_sizes = 7,
2102 .configure = intel_860_configure,
2103 .fetch_size = intel_8xx_fetch_size,
2104 .cleanup = intel_8xx_cleanup,
2105 .tlb_flush = intel_8xx_tlbflush,
2106 .mask_memory = agp_generic_mask_memory,
2107 .masks = intel_generic_masks,
2108 .agp_enable = agp_generic_enable,
2109 .cache_flush = global_cache_flush,
2110 .create_gatt_table = agp_generic_create_gatt_table,
2111 .free_gatt_table = agp_generic_free_gatt_table,
2112 .insert_memory = agp_generic_insert_memory,
2113 .remove_memory = agp_generic_remove_memory,
2114 .alloc_by_type = agp_generic_alloc_by_type,
2115 .free_by_type = agp_generic_free_by_type,
2116 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08002117 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08002119 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01002120 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121};
2122
Dave Jonese5524f32007-02-22 18:41:28 -05002123static const struct agp_bridge_driver intel_915_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124 .owner = THIS_MODULE,
2125 .aperture_sizes = intel_i830_sizes,
2126 .size_type = FIXED_APER_SIZE,
Dave Jonesc14635e2006-09-06 11:59:35 -04002127 .num_aperture_sizes = 4,
Joe Perchesc7258012008-03-26 14:10:02 -07002128 .needs_scratch_page = true,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129 .configure = intel_i915_configure,
Eric Anholtc41e0de2006-12-19 12:57:24 -08002130 .fetch_size = intel_i9xx_fetch_size,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131 .cleanup = intel_i915_cleanup,
2132 .tlb_flush = intel_i810_tlbflush,
2133 .mask_memory = intel_i810_mask_memory,
2134 .masks = intel_i810_masks,
2135 .agp_enable = intel_i810_agp_enable,
2136 .cache_flush = global_cache_flush,
2137 .create_gatt_table = intel_i915_create_gatt_table,
2138 .free_gatt_table = intel_i830_free_gatt_table,
2139 .insert_memory = intel_i915_insert_entries,
2140 .remove_memory = intel_i915_remove_entries,
2141 .alloc_by_type = intel_i830_alloc_by_type,
2142 .free_by_type = intel_i810_free_by_type,
2143 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08002144 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08002146 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01002147 .agp_type_to_mask_type = intel_i830_type_to_mask_type,
Dave Airlie6c00a612007-10-29 18:06:10 +10002148 .chipset_flush = intel_i915_chipset_flush,
Zhenyu Wang17661682009-07-27 12:59:57 +01002149#ifdef USE_PCI_DMA_API
2150 .agp_map_page = intel_agp_map_page,
2151 .agp_unmap_page = intel_agp_unmap_page,
2152 .agp_map_memory = intel_agp_map_memory,
2153 .agp_unmap_memory = intel_agp_unmap_memory,
2154#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155};
2156
Dave Jonese5524f32007-02-22 18:41:28 -05002157static const struct agp_bridge_driver intel_i965_driver = {
Dave Airlie62c96b92008-06-19 14:27:53 +10002158 .owner = THIS_MODULE,
2159 .aperture_sizes = intel_i830_sizes,
2160 .size_type = FIXED_APER_SIZE,
2161 .num_aperture_sizes = 4,
2162 .needs_scratch_page = true,
Dave Airlie0e480e52008-06-19 14:57:31 +10002163 .configure = intel_i915_configure,
2164 .fetch_size = intel_i9xx_fetch_size,
Dave Airlie62c96b92008-06-19 14:27:53 +10002165 .cleanup = intel_i915_cleanup,
2166 .tlb_flush = intel_i810_tlbflush,
2167 .mask_memory = intel_i965_mask_memory,
2168 .masks = intel_i810_masks,
2169 .agp_enable = intel_i810_agp_enable,
2170 .cache_flush = global_cache_flush,
2171 .create_gatt_table = intel_i965_create_gatt_table,
2172 .free_gatt_table = intel_i830_free_gatt_table,
2173 .insert_memory = intel_i915_insert_entries,
2174 .remove_memory = intel_i915_remove_entries,
2175 .alloc_by_type = intel_i830_alloc_by_type,
2176 .free_by_type = intel_i810_free_by_type,
2177 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08002178 .agp_alloc_pages = agp_generic_alloc_pages,
Dave Airlie62c96b92008-06-19 14:27:53 +10002179 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08002180 .agp_destroy_pages = agp_generic_destroy_pages,
Dave Airlie62c96b92008-06-19 14:27:53 +10002181 .agp_type_to_mask_type = intel_i830_type_to_mask_type,
Dave Airlie6c00a612007-10-29 18:06:10 +10002182 .chipset_flush = intel_i915_chipset_flush,
Zhenyu Wang17661682009-07-27 12:59:57 +01002183#ifdef USE_PCI_DMA_API
2184 .agp_map_page = intel_agp_map_page,
2185 .agp_unmap_page = intel_agp_unmap_page,
2186 .agp_map_memory = intel_agp_map_memory,
2187 .agp_unmap_memory = intel_agp_unmap_memory,
2188#endif
Eric Anholt65c25aa2006-09-06 11:57:18 -04002189};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190
Dave Jonese5524f32007-02-22 18:41:28 -05002191static const struct agp_bridge_driver intel_7505_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192 .owner = THIS_MODULE,
2193 .aperture_sizes = intel_8xx_sizes,
2194 .size_type = U8_APER_SIZE,
2195 .num_aperture_sizes = 7,
2196 .configure = intel_7505_configure,
2197 .fetch_size = intel_8xx_fetch_size,
2198 .cleanup = intel_8xx_cleanup,
2199 .tlb_flush = intel_8xx_tlbflush,
2200 .mask_memory = agp_generic_mask_memory,
2201 .masks = intel_generic_masks,
2202 .agp_enable = agp_generic_enable,
2203 .cache_flush = global_cache_flush,
2204 .create_gatt_table = agp_generic_create_gatt_table,
2205 .free_gatt_table = agp_generic_free_gatt_table,
2206 .insert_memory = agp_generic_insert_memory,
2207 .remove_memory = agp_generic_remove_memory,
2208 .alloc_by_type = agp_generic_alloc_by_type,
2209 .free_by_type = agp_generic_free_by_type,
2210 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08002211 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08002213 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01002214 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215};
2216
Wang Zhenyu874808c62007-06-06 11:16:25 +08002217static const struct agp_bridge_driver intel_g33_driver = {
Dave Airlie62c96b92008-06-19 14:27:53 +10002218 .owner = THIS_MODULE,
2219 .aperture_sizes = intel_i830_sizes,
2220 .size_type = FIXED_APER_SIZE,
2221 .num_aperture_sizes = 4,
2222 .needs_scratch_page = true,
2223 .configure = intel_i915_configure,
2224 .fetch_size = intel_i9xx_fetch_size,
2225 .cleanup = intel_i915_cleanup,
2226 .tlb_flush = intel_i810_tlbflush,
2227 .mask_memory = intel_i965_mask_memory,
2228 .masks = intel_i810_masks,
2229 .agp_enable = intel_i810_agp_enable,
2230 .cache_flush = global_cache_flush,
2231 .create_gatt_table = intel_i915_create_gatt_table,
2232 .free_gatt_table = intel_i830_free_gatt_table,
2233 .insert_memory = intel_i915_insert_entries,
2234 .remove_memory = intel_i915_remove_entries,
2235 .alloc_by_type = intel_i830_alloc_by_type,
2236 .free_by_type = intel_i810_free_by_type,
2237 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08002238 .agp_alloc_pages = agp_generic_alloc_pages,
Dave Airlie62c96b92008-06-19 14:27:53 +10002239 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08002240 .agp_destroy_pages = agp_generic_destroy_pages,
Dave Airlie62c96b92008-06-19 14:27:53 +10002241 .agp_type_to_mask_type = intel_i830_type_to_mask_type,
Dave Airlie6c00a612007-10-29 18:06:10 +10002242 .chipset_flush = intel_i915_chipset_flush,
Zhenyu Wang17661682009-07-27 12:59:57 +01002243#ifdef USE_PCI_DMA_API
2244 .agp_map_page = intel_agp_map_page,
2245 .agp_unmap_page = intel_agp_unmap_page,
2246 .agp_map_memory = intel_agp_map_memory,
2247 .agp_unmap_memory = intel_agp_unmap_memory,
2248#endif
Wang Zhenyu874808c62007-06-06 11:16:25 +08002249};
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002250
2251static int find_gmch(u16 device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252{
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002253 struct pci_dev *gmch_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002255 gmch_device = pci_get_device(PCI_VENDOR_ID_INTEL, device, NULL);
2256 if (gmch_device && PCI_FUNC(gmch_device->devfn) != 0) {
2257 gmch_device = pci_get_device(PCI_VENDOR_ID_INTEL,
Dave Airlief011ae72008-01-25 11:23:04 +10002258 device, gmch_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259 }
2260
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002261 if (!gmch_device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262 return 0;
2263
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002264 intel_private.pcidev = gmch_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265 return 1;
2266}
2267
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002268/* Table to describe Intel GMCH and AGP/PCIE GART drivers. At least one of
2269 * driver and gmch_driver must be non-null, and find_gmch will determine
2270 * which one should be used if a gmch_chip_id is present.
2271 */
2272static const struct intel_driver_description {
2273 unsigned int chip_id;
2274 unsigned int gmch_chip_id;
Wang Zhenyu88889852007-06-14 10:01:04 +08002275 unsigned int multi_gmch_chip; /* if we have more gfx chip type on this HB. */
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002276 char *name;
2277 const struct agp_bridge_driver *driver;
2278 const struct agp_bridge_driver *gmch_driver;
2279} intel_agp_chipsets[] = {
Wang Zhenyu88889852007-06-14 10:01:04 +08002280 { PCI_DEVICE_ID_INTEL_82443LX_0, 0, 0, "440LX", &intel_generic_driver, NULL },
2281 { PCI_DEVICE_ID_INTEL_82443BX_0, 0, 0, "440BX", &intel_generic_driver, NULL },
2282 { PCI_DEVICE_ID_INTEL_82443GX_0, 0, 0, "440GX", &intel_generic_driver, NULL },
2283 { PCI_DEVICE_ID_INTEL_82810_MC1, PCI_DEVICE_ID_INTEL_82810_IG1, 0, "i810",
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002284 NULL, &intel_810_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002285 { PCI_DEVICE_ID_INTEL_82810_MC3, PCI_DEVICE_ID_INTEL_82810_IG3, 0, "i810",
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002286 NULL, &intel_810_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002287 { PCI_DEVICE_ID_INTEL_82810E_MC, PCI_DEVICE_ID_INTEL_82810E_IG, 0, "i810",
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002288 NULL, &intel_810_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002289 { PCI_DEVICE_ID_INTEL_82815_MC, PCI_DEVICE_ID_INTEL_82815_CGC, 0, "i815",
2290 &intel_815_driver, &intel_810_driver },
2291 { PCI_DEVICE_ID_INTEL_82820_HB, 0, 0, "i820", &intel_820_driver, NULL },
2292 { PCI_DEVICE_ID_INTEL_82820_UP_HB, 0, 0, "i820", &intel_820_driver, NULL },
2293 { PCI_DEVICE_ID_INTEL_82830_HB, PCI_DEVICE_ID_INTEL_82830_CGC, 0, "830M",
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002294 &intel_830mp_driver, &intel_830_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002295 { PCI_DEVICE_ID_INTEL_82840_HB, 0, 0, "i840", &intel_840_driver, NULL },
2296 { PCI_DEVICE_ID_INTEL_82845_HB, 0, 0, "845G", &intel_845_driver, NULL },
2297 { PCI_DEVICE_ID_INTEL_82845G_HB, PCI_DEVICE_ID_INTEL_82845G_IG, 0, "830M",
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002298 &intel_845_driver, &intel_830_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002299 { PCI_DEVICE_ID_INTEL_82850_HB, 0, 0, "i850", &intel_850_driver, NULL },
Stefan Husemann347486b2009-04-13 14:40:10 -07002300 { PCI_DEVICE_ID_INTEL_82854_HB, PCI_DEVICE_ID_INTEL_82854_IG, 0, "854",
2301 &intel_845_driver, &intel_830_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002302 { PCI_DEVICE_ID_INTEL_82855PM_HB, 0, 0, "855PM", &intel_845_driver, NULL },
2303 { PCI_DEVICE_ID_INTEL_82855GM_HB, PCI_DEVICE_ID_INTEL_82855GM_IG, 0, "855GM",
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002304 &intel_845_driver, &intel_830_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002305 { PCI_DEVICE_ID_INTEL_82860_HB, 0, 0, "i860", &intel_860_driver, NULL },
2306 { PCI_DEVICE_ID_INTEL_82865_HB, PCI_DEVICE_ID_INTEL_82865_IG, 0, "865",
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002307 &intel_845_driver, &intel_830_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002308 { PCI_DEVICE_ID_INTEL_82875_HB, 0, 0, "i875", &intel_845_driver, NULL },
Carlos Martíne914a362008-01-24 10:34:09 +10002309 { PCI_DEVICE_ID_INTEL_E7221_HB, PCI_DEVICE_ID_INTEL_E7221_IG, 0, "E7221 (i915)",
2310 NULL, &intel_915_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002311 { PCI_DEVICE_ID_INTEL_82915G_HB, PCI_DEVICE_ID_INTEL_82915G_IG, 0, "915G",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002312 NULL, &intel_915_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002313 { PCI_DEVICE_ID_INTEL_82915GM_HB, PCI_DEVICE_ID_INTEL_82915GM_IG, 0, "915GM",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002314 NULL, &intel_915_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002315 { PCI_DEVICE_ID_INTEL_82945G_HB, PCI_DEVICE_ID_INTEL_82945G_IG, 0, "945G",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002316 NULL, &intel_915_driver },
Zhenyu Wangdde47872007-07-26 09:18:09 +08002317 { PCI_DEVICE_ID_INTEL_82945GM_HB, PCI_DEVICE_ID_INTEL_82945GM_IG, 0, "945GM",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002318 NULL, &intel_915_driver },
Zhenyu Wangdde47872007-07-26 09:18:09 +08002319 { PCI_DEVICE_ID_INTEL_82945GME_HB, PCI_DEVICE_ID_INTEL_82945GME_IG, 0, "945GME",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002320 NULL, &intel_915_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002321 { PCI_DEVICE_ID_INTEL_82946GZ_HB, PCI_DEVICE_ID_INTEL_82946GZ_IG, 0, "946GZ",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002322 NULL, &intel_i965_driver },
Zhenyu Wang9119f852008-01-23 15:49:26 +10002323 { PCI_DEVICE_ID_INTEL_82G35_HB, PCI_DEVICE_ID_INTEL_82G35_IG, 0, "G35",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002324 NULL, &intel_i965_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002325 { PCI_DEVICE_ID_INTEL_82965Q_HB, PCI_DEVICE_ID_INTEL_82965Q_IG, 0, "965Q",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002326 NULL, &intel_i965_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002327 { PCI_DEVICE_ID_INTEL_82965G_HB, PCI_DEVICE_ID_INTEL_82965G_IG, 0, "965G",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002328 NULL, &intel_i965_driver },
Zhenyu Wangdde47872007-07-26 09:18:09 +08002329 { PCI_DEVICE_ID_INTEL_82965GM_HB, PCI_DEVICE_ID_INTEL_82965GM_IG, 0, "965GM",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002330 NULL, &intel_i965_driver },
Zhenyu Wangdde47872007-07-26 09:18:09 +08002331 { PCI_DEVICE_ID_INTEL_82965GME_HB, PCI_DEVICE_ID_INTEL_82965GME_IG, 0, "965GME/GLE",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002332 NULL, &intel_i965_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002333 { PCI_DEVICE_ID_INTEL_7505_0, 0, 0, "E7505", &intel_7505_driver, NULL },
2334 { PCI_DEVICE_ID_INTEL_7205_0, 0, 0, "E7205", &intel_7505_driver, NULL },
2335 { PCI_DEVICE_ID_INTEL_G33_HB, PCI_DEVICE_ID_INTEL_G33_IG, 0, "G33",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002336 NULL, &intel_g33_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002337 { PCI_DEVICE_ID_INTEL_Q35_HB, PCI_DEVICE_ID_INTEL_Q35_IG, 0, "Q35",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002338 NULL, &intel_g33_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002339 { PCI_DEVICE_ID_INTEL_Q33_HB, PCI_DEVICE_ID_INTEL_Q33_IG, 0, "Q33",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002340 NULL, &intel_g33_driver },
Adam Jackson107f5172009-12-03 17:14:41 -05002341 { PCI_DEVICE_ID_INTEL_PINEVIEW_M_HB, PCI_DEVICE_ID_INTEL_PINEVIEW_M_IG, 0, "Pineview",
Shaohua Li21778322009-02-23 15:19:16 +08002342 NULL, &intel_g33_driver },
Adam Jackson107f5172009-12-03 17:14:41 -05002343 { PCI_DEVICE_ID_INTEL_PINEVIEW_HB, PCI_DEVICE_ID_INTEL_PINEVIEW_IG, 0, "Pineview",
Shaohua Li21778322009-02-23 15:19:16 +08002344 NULL, &intel_g33_driver },
Zhenyu Wang99d32bd2008-07-30 12:26:50 -07002345 { PCI_DEVICE_ID_INTEL_GM45_HB, PCI_DEVICE_ID_INTEL_GM45_IG, 0,
Adam Jackson107f5172009-12-03 17:14:41 -05002346 "GM45", NULL, &intel_i965_driver },
2347 { PCI_DEVICE_ID_INTEL_EAGLELAKE_HB, PCI_DEVICE_ID_INTEL_EAGLELAKE_IG, 0,
2348 "Eaglelake", NULL, &intel_i965_driver },
Zhenyu Wang25ce77a2008-06-19 14:17:58 +10002349 { PCI_DEVICE_ID_INTEL_Q45_HB, PCI_DEVICE_ID_INTEL_Q45_IG, 0,
2350 "Q45/Q43", NULL, &intel_i965_driver },
2351 { PCI_DEVICE_ID_INTEL_G45_HB, PCI_DEVICE_ID_INTEL_G45_IG, 0,
2352 "G45/G43", NULL, &intel_i965_driver },
Fabian Henze38d8a952009-09-08 00:59:58 +08002353 { PCI_DEVICE_ID_INTEL_B43_HB, PCI_DEVICE_ID_INTEL_B43_IG, 0,
2354 "B43", NULL, &intel_i965_driver },
Zhenyu Wanga50ccc62008-11-17 14:39:00 +08002355 { PCI_DEVICE_ID_INTEL_G41_HB, PCI_DEVICE_ID_INTEL_G41_IG, 0,
2356 "G41", NULL, &intel_i965_driver },
Adam Jackson107f5172009-12-03 17:14:41 -05002357 { PCI_DEVICE_ID_INTEL_IRONLAKE_D_HB, PCI_DEVICE_ID_INTEL_IRONLAKE_D_IG, 0,
2358 "Ironlake/D", NULL, &intel_i965_driver },
2359 { PCI_DEVICE_ID_INTEL_IRONLAKE_M_HB, PCI_DEVICE_ID_INTEL_IRONLAKE_M_IG, 0,
2360 "Ironlake/M", NULL, &intel_i965_driver },
2361 { PCI_DEVICE_ID_INTEL_IRONLAKE_MA_HB, PCI_DEVICE_ID_INTEL_IRONLAKE_M_IG, 0,
2362 "Ironlake/MA", NULL, &intel_i965_driver },
Dave Airlie3ff99162009-12-08 14:03:47 +10002363 { PCI_DEVICE_ID_INTEL_IRONLAKE_MC2_HB, PCI_DEVICE_ID_INTEL_IRONLAKE_M_IG, 0,
2364 "Ironlake/MC2", NULL, &intel_i965_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002365 { 0, 0, 0, NULL, NULL, NULL }
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002366};
2367
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368static int __devinit agp_intel_probe(struct pci_dev *pdev,
2369 const struct pci_device_id *ent)
2370{
2371 struct agp_bridge_data *bridge;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372 u8 cap_ptr = 0;
2373 struct resource *r;
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002374 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375
2376 cap_ptr = pci_find_capability(pdev, PCI_CAP_ID_AGP);
2377
2378 bridge = agp_alloc_bridge();
2379 if (!bridge)
2380 return -ENOMEM;
2381
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002382 for (i = 0; intel_agp_chipsets[i].name != NULL; i++) {
2383 /* In case that multiple models of gfx chip may
2384 stand on same host bridge type, this can be
2385 sure we detect the right IGD. */
Wang Zhenyu88889852007-06-14 10:01:04 +08002386 if (pdev->device == intel_agp_chipsets[i].chip_id) {
2387 if ((intel_agp_chipsets[i].gmch_chip_id != 0) &&
2388 find_gmch(intel_agp_chipsets[i].gmch_chip_id)) {
2389 bridge->driver =
2390 intel_agp_chipsets[i].gmch_driver;
2391 break;
2392 } else if (intel_agp_chipsets[i].multi_gmch_chip) {
2393 continue;
2394 } else {
2395 bridge->driver = intel_agp_chipsets[i].driver;
2396 break;
2397 }
2398 }
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002399 }
2400
2401 if (intel_agp_chipsets[i].name == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402 if (cap_ptr)
Bjorn Helgaase3cf6952008-07-30 12:26:51 -07002403 dev_warn(&pdev->dev, "unsupported Intel chipset [%04x/%04x]\n",
2404 pdev->vendor, pdev->device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405 agp_put_bridge(bridge);
2406 return -ENODEV;
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002407 }
2408
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002409 if (bridge->driver == NULL) {
Wang Zhenyu47d46372007-06-21 13:43:18 +08002410 /* bridge has no AGP and no IGD detected */
2411 if (cap_ptr)
Bjorn Helgaase3cf6952008-07-30 12:26:51 -07002412 dev_warn(&pdev->dev, "can't find bridge device (chip_id: %04x)\n",
2413 intel_agp_chipsets[i].gmch_chip_id);
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002414 agp_put_bridge(bridge);
2415 return -ENODEV;
Dave Airlief011ae72008-01-25 11:23:04 +10002416 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417
2418 bridge->dev = pdev;
2419 bridge->capndx = cap_ptr;
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08002420 bridge->dev_private_data = &intel_private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421
Bjorn Helgaase3cf6952008-07-30 12:26:51 -07002422 dev_info(&pdev->dev, "Intel %s Chipset\n", intel_agp_chipsets[i].name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423
2424 /*
2425 * The following fixes the case where the BIOS has "forgotten" to
2426 * provide an address range for the GART.
2427 * 20030610 - hamish@zot.org
2428 */
2429 r = &pdev->resource[0];
2430 if (!r->start && r->end) {
Dave Jones6a92a4e2006-02-28 00:54:25 -05002431 if (pci_assign_resource(pdev, 0)) {
Bjorn Helgaase3cf6952008-07-30 12:26:51 -07002432 dev_err(&pdev->dev, "can't assign resource 0\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433 agp_put_bridge(bridge);
2434 return -ENODEV;
2435 }
2436 }
2437
2438 /*
2439 * If the device has not been properly setup, the following will catch
2440 * the problem and should stop the system from crashing.
2441 * 20030610 - hamish@zot.org
2442 */
2443 if (pci_enable_device(pdev)) {
Bjorn Helgaase3cf6952008-07-30 12:26:51 -07002444 dev_err(&pdev->dev, "can't enable PCI device\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445 agp_put_bridge(bridge);
2446 return -ENODEV;
2447 }
2448
2449 /* Fill in the mode register */
2450 if (cap_ptr) {
2451 pci_read_config_dword(pdev,
2452 bridge->capndx+PCI_AGP_STATUS,
2453 &bridge->mode);
2454 }
2455
Zhenyu Wang9b974cc2010-01-05 11:25:06 +08002456 if (bridge->driver->mask_memory == intel_i965_mask_memory) {
David Woodhouseec402ba2009-11-18 10:22:46 +00002457 if (pci_set_dma_mask(intel_private.pcidev, DMA_BIT_MASK(36)))
2458 dev_err(&intel_private.pcidev->dev,
2459 "set gfx device dma mask 36bit failed!\n");
Zhenyu Wang9b974cc2010-01-05 11:25:06 +08002460 else
2461 pci_set_consistent_dma_mask(intel_private.pcidev,
2462 DMA_BIT_MASK(36));
2463 }
David Woodhouseec402ba2009-11-18 10:22:46 +00002464
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465 pci_set_drvdata(pdev, bridge);
2466 return agp_add_bridge(bridge);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467}
2468
2469static void __devexit agp_intel_remove(struct pci_dev *pdev)
2470{
2471 struct agp_bridge_data *bridge = pci_get_drvdata(pdev);
2472
2473 agp_remove_bridge(bridge);
2474
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08002475 if (intel_private.pcidev)
2476 pci_dev_put(intel_private.pcidev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477
2478 agp_put_bridge(bridge);
2479}
2480
Alexey Dobriyan85be7d62006-08-12 02:02:02 +04002481#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482static int agp_intel_resume(struct pci_dev *pdev)
2483{
2484 struct agp_bridge_data *bridge = pci_get_drvdata(pdev);
Keith Packarda8c84df2008-07-31 15:48:07 +10002485 int ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487 if (bridge->driver == &intel_generic_driver)
2488 intel_configure();
2489 else if (bridge->driver == &intel_850_driver)
2490 intel_850_configure();
2491 else if (bridge->driver == &intel_845_driver)
2492 intel_845_configure();
2493 else if (bridge->driver == &intel_830mp_driver)
2494 intel_830mp_configure();
2495 else if (bridge->driver == &intel_915_driver)
2496 intel_i915_configure();
2497 else if (bridge->driver == &intel_830_driver)
2498 intel_i830_configure();
2499 else if (bridge->driver == &intel_810_driver)
2500 intel_i810_configure();
Dave Jones08da3f42006-09-10 21:09:26 -04002501 else if (bridge->driver == &intel_i965_driver)
2502 intel_i915_configure();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503
Keith Packarda8c84df2008-07-31 15:48:07 +10002504 ret_val = agp_rebind_memory();
2505 if (ret_val != 0)
2506 return ret_val;
2507
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508 return 0;
2509}
Alexey Dobriyan85be7d62006-08-12 02:02:02 +04002510#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511
2512static struct pci_device_id agp_intel_pci_table[] = {
2513#define ID(x) \
2514 { \
2515 .class = (PCI_CLASS_BRIDGE_HOST << 8), \
2516 .class_mask = ~0, \
2517 .vendor = PCI_VENDOR_ID_INTEL, \
2518 .device = x, \
2519 .subvendor = PCI_ANY_ID, \
2520 .subdevice = PCI_ANY_ID, \
2521 }
2522 ID(PCI_DEVICE_ID_INTEL_82443LX_0),
2523 ID(PCI_DEVICE_ID_INTEL_82443BX_0),
2524 ID(PCI_DEVICE_ID_INTEL_82443GX_0),
2525 ID(PCI_DEVICE_ID_INTEL_82810_MC1),
2526 ID(PCI_DEVICE_ID_INTEL_82810_MC3),
2527 ID(PCI_DEVICE_ID_INTEL_82810E_MC),
2528 ID(PCI_DEVICE_ID_INTEL_82815_MC),
2529 ID(PCI_DEVICE_ID_INTEL_82820_HB),
2530 ID(PCI_DEVICE_ID_INTEL_82820_UP_HB),
2531 ID(PCI_DEVICE_ID_INTEL_82830_HB),
2532 ID(PCI_DEVICE_ID_INTEL_82840_HB),
2533 ID(PCI_DEVICE_ID_INTEL_82845_HB),
2534 ID(PCI_DEVICE_ID_INTEL_82845G_HB),
2535 ID(PCI_DEVICE_ID_INTEL_82850_HB),
Stefan Husemann347486b2009-04-13 14:40:10 -07002536 ID(PCI_DEVICE_ID_INTEL_82854_HB),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537 ID(PCI_DEVICE_ID_INTEL_82855PM_HB),
2538 ID(PCI_DEVICE_ID_INTEL_82855GM_HB),
2539 ID(PCI_DEVICE_ID_INTEL_82860_HB),
2540 ID(PCI_DEVICE_ID_INTEL_82865_HB),
2541 ID(PCI_DEVICE_ID_INTEL_82875_HB),
2542 ID(PCI_DEVICE_ID_INTEL_7505_0),
2543 ID(PCI_DEVICE_ID_INTEL_7205_0),
Carlos Martíne914a362008-01-24 10:34:09 +10002544 ID(PCI_DEVICE_ID_INTEL_E7221_HB),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545 ID(PCI_DEVICE_ID_INTEL_82915G_HB),
2546 ID(PCI_DEVICE_ID_INTEL_82915GM_HB),
Alan Hourihaned0de98f2005-05-31 19:50:49 +01002547 ID(PCI_DEVICE_ID_INTEL_82945G_HB),
Alan Hourihane3b0e8ea2006-01-19 14:08:40 +00002548 ID(PCI_DEVICE_ID_INTEL_82945GM_HB),
Zhenyu Wangdde47872007-07-26 09:18:09 +08002549 ID(PCI_DEVICE_ID_INTEL_82945GME_HB),
Adam Jackson107f5172009-12-03 17:14:41 -05002550 ID(PCI_DEVICE_ID_INTEL_PINEVIEW_M_HB),
2551 ID(PCI_DEVICE_ID_INTEL_PINEVIEW_HB),
Eric Anholt65c25aa2006-09-06 11:57:18 -04002552 ID(PCI_DEVICE_ID_INTEL_82946GZ_HB),
Zhenyu Wang9119f852008-01-23 15:49:26 +10002553 ID(PCI_DEVICE_ID_INTEL_82G35_HB),
Eric Anholt65c25aa2006-09-06 11:57:18 -04002554 ID(PCI_DEVICE_ID_INTEL_82965Q_HB),
2555 ID(PCI_DEVICE_ID_INTEL_82965G_HB),
Wang Zhenyu4598af32007-04-09 08:51:36 +08002556 ID(PCI_DEVICE_ID_INTEL_82965GM_HB),
Zhenyu Wangdde47872007-07-26 09:18:09 +08002557 ID(PCI_DEVICE_ID_INTEL_82965GME_HB),
Wang Zhenyu874808c62007-06-06 11:16:25 +08002558 ID(PCI_DEVICE_ID_INTEL_G33_HB),
2559 ID(PCI_DEVICE_ID_INTEL_Q35_HB),
2560 ID(PCI_DEVICE_ID_INTEL_Q33_HB),
Zhenyu Wang99d32bd2008-07-30 12:26:50 -07002561 ID(PCI_DEVICE_ID_INTEL_GM45_HB),
Adam Jackson107f5172009-12-03 17:14:41 -05002562 ID(PCI_DEVICE_ID_INTEL_EAGLELAKE_HB),
Zhenyu Wang25ce77a2008-06-19 14:17:58 +10002563 ID(PCI_DEVICE_ID_INTEL_Q45_HB),
2564 ID(PCI_DEVICE_ID_INTEL_G45_HB),
Zhenyu Wanga50ccc62008-11-17 14:39:00 +08002565 ID(PCI_DEVICE_ID_INTEL_G41_HB),
Fabian Henze38d8a952009-09-08 00:59:58 +08002566 ID(PCI_DEVICE_ID_INTEL_B43_HB),
Adam Jackson107f5172009-12-03 17:14:41 -05002567 ID(PCI_DEVICE_ID_INTEL_IRONLAKE_D_HB),
2568 ID(PCI_DEVICE_ID_INTEL_IRONLAKE_M_HB),
2569 ID(PCI_DEVICE_ID_INTEL_IRONLAKE_MA_HB),
Dave Airlie3ff99162009-12-08 14:03:47 +10002570 ID(PCI_DEVICE_ID_INTEL_IRONLAKE_MC2_HB),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571 { }
2572};
2573
2574MODULE_DEVICE_TABLE(pci, agp_intel_pci_table);
2575
2576static struct pci_driver agp_intel_pci_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 .name = "agpgart-intel",
2578 .id_table = agp_intel_pci_table,
2579 .probe = agp_intel_probe,
2580 .remove = __devexit_p(agp_intel_remove),
Alexey Dobriyan85be7d62006-08-12 02:02:02 +04002581#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582 .resume = agp_intel_resume,
Alexey Dobriyan85be7d62006-08-12 02:02:02 +04002583#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584};
2585
2586static int __init agp_intel_init(void)
2587{
2588 if (agp_off)
2589 return -EINVAL;
2590 return pci_register_driver(&agp_intel_pci_driver);
2591}
2592
2593static void __exit agp_intel_cleanup(void)
2594{
2595 pci_unregister_driver(&agp_intel_pci_driver);
2596}
2597
2598module_init(agp_intel_init);
2599module_exit(agp_intel_cleanup);
2600
Dave Jonesf4432c52008-10-20 13:31:45 -04002601MODULE_AUTHOR("Dave Jones <davej@redhat.com>");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602MODULE_LICENSE("GPL and additional rights");