blob: 8e61a05304858636b3619cbd61c2743de590d2fb [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>
11#include "agp.h"
12
Carlos Martíne914a362008-01-24 10:34:09 +100013#define PCI_DEVICE_ID_INTEL_E7221_HB 0x2588
14#define PCI_DEVICE_ID_INTEL_E7221_IG 0x258a
Eric Anholt65c25aa2006-09-06 11:57:18 -040015#define PCI_DEVICE_ID_INTEL_82946GZ_HB 0x2970
16#define PCI_DEVICE_ID_INTEL_82946GZ_IG 0x2972
17#define PCI_DEVICE_ID_INTEL_82965G_1_HB 0x2980
18#define PCI_DEVICE_ID_INTEL_82965G_1_IG 0x2982
19#define PCI_DEVICE_ID_INTEL_82965Q_HB 0x2990
20#define PCI_DEVICE_ID_INTEL_82965Q_IG 0x2992
21#define PCI_DEVICE_ID_INTEL_82965G_HB 0x29A0
22#define PCI_DEVICE_ID_INTEL_82965G_IG 0x29A2
Wang Zhenyu4598af32007-04-09 08:51:36 +080023#define PCI_DEVICE_ID_INTEL_82965GM_HB 0x2A00
24#define PCI_DEVICE_ID_INTEL_82965GM_IG 0x2A02
Zhenyu Wangdde47872007-07-26 09:18:09 +080025#define PCI_DEVICE_ID_INTEL_82965GME_HB 0x2A10
Wang Zhenyuc8eebfd2007-05-31 11:34:06 +080026#define PCI_DEVICE_ID_INTEL_82965GME_IG 0x2A12
Zhenyu Wangdde47872007-07-26 09:18:09 +080027#define PCI_DEVICE_ID_INTEL_82945GME_HB 0x27AC
Wang Zhenyudf80b142007-05-31 11:51:12 +080028#define PCI_DEVICE_ID_INTEL_82945GME_IG 0x27AE
Wang Zhenyu874808c62007-06-06 11:16:25 +080029#define PCI_DEVICE_ID_INTEL_G33_HB 0x29C0
30#define PCI_DEVICE_ID_INTEL_G33_IG 0x29C2
31#define PCI_DEVICE_ID_INTEL_Q35_HB 0x29B0
32#define PCI_DEVICE_ID_INTEL_Q35_IG 0x29B2
33#define PCI_DEVICE_ID_INTEL_Q33_HB 0x29D0
34#define PCI_DEVICE_ID_INTEL_Q33_IG 0x29D2
Eric Anholt65c25aa2006-09-06 11:57:18 -040035
36#define IS_I965 (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82946GZ_HB || \
37 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965G_1_HB || \
38 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965Q_HB || \
Wang Zhenyu4598af32007-04-09 08:51:36 +080039 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965G_HB || \
Zhenyu Wangdde47872007-07-26 09:18:09 +080040 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965GM_HB || \
41 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965GME_HB)
Eric Anholt65c25aa2006-09-06 11:57:18 -040042
Wang Zhenyu874808c62007-06-06 11:16:25 +080043#define IS_G33 (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_G33_HB || \
44 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_Q35_HB || \
45 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_Q33_HB)
Eric Anholt65c25aa2006-09-06 11:57:18 -040046
Thomas Hellstroma030ce42007-01-23 10:33:43 +010047extern int agp_memory_reserved;
48
49
Linus Torvalds1da177e2005-04-16 15:20:36 -070050/* Intel 815 register */
51#define INTEL_815_APCONT 0x51
52#define INTEL_815_ATTBASE_MASK ~0x1FFFFFFF
53
54/* Intel i820 registers */
55#define INTEL_I820_RDCR 0x51
56#define INTEL_I820_ERRSTS 0xc8
57
58/* Intel i840 registers */
59#define INTEL_I840_MCHCFG 0x50
60#define INTEL_I840_ERRSTS 0xc8
61
62/* Intel i850 registers */
63#define INTEL_I850_MCHCFG 0x50
64#define INTEL_I850_ERRSTS 0xc8
65
66/* intel 915G registers */
67#define I915_GMADDR 0x18
68#define I915_MMADDR 0x10
69#define I915_PTEADDR 0x1C
70#define I915_GMCH_GMS_STOLEN_48M (0x6 << 4)
71#define I915_GMCH_GMS_STOLEN_64M (0x7 << 4)
Wang Zhenyu874808c62007-06-06 11:16:25 +080072#define G33_GMCH_GMS_STOLEN_128M (0x8 << 4)
73#define G33_GMCH_GMS_STOLEN_256M (0x9 << 4)
Dave Airlie6c00a612007-10-29 18:06:10 +100074#define I915_IFPADDR 0x60
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
Eric Anholt65c25aa2006-09-06 11:57:18 -040076/* Intel 965G registers */
77#define I965_MSAC 0x62
Dave Airlie6c00a612007-10-29 18:06:10 +100078#define I965_IFPADDR 0x70
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
80/* Intel 7505 registers */
81#define INTEL_I7505_APSIZE 0x74
82#define INTEL_I7505_NCAPID 0x60
83#define INTEL_I7505_NISTAT 0x6c
84#define INTEL_I7505_ATTBASE 0x78
85#define INTEL_I7505_ERRSTS 0x42
86#define INTEL_I7505_AGPCTRL 0x70
87#define INTEL_I7505_MCHCFG 0x50
88
Dave Jonese5524f32007-02-22 18:41:28 -050089static const struct aper_size_info_fixed intel_i810_sizes[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -070090{
91 {64, 16384, 4},
92 /* The 32M mode still requires a 64k gatt */
93 {32, 8192, 4}
94};
95
96#define AGP_DCACHE_MEMORY 1
97#define AGP_PHYS_MEMORY 2
Thomas Hellstroma030ce42007-01-23 10:33:43 +010098#define INTEL_AGP_CACHED_MEMORY 3
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
100static struct gatt_mask intel_i810_masks[] =
101{
102 {.mask = I810_PTE_VALID, .type = 0},
103 {.mask = (I810_PTE_VALID | I810_PTE_LOCAL), .type = AGP_DCACHE_MEMORY},
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100104 {.mask = I810_PTE_VALID, .type = 0},
105 {.mask = I810_PTE_VALID | I830_PTE_SYSTEM_CACHED,
106 .type = INTEL_AGP_CACHED_MEMORY}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107};
108
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800109static struct _intel_private {
110 struct pci_dev *pcidev; /* device one */
111 u8 __iomem *registers;
112 u32 __iomem *gtt; /* I915G */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 int num_dcache_entries;
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800114 /* gtt_entries is the number of gtt entries that are already mapped
115 * to stolen memory. Stolen memory is larger than the memory mapped
116 * through gtt_entries, as it includes some reserved space for the BIOS
117 * popup and for the GTT.
118 */
119 int gtt_entries; /* i830+ */
Dave Airlie2162e6a2007-11-21 16:36:31 +1000120 union {
121 void __iomem *i9xx_flush_page;
122 void *i8xx_flush_page;
123 };
124 struct page *i8xx_page;
Dave Airlie6c00a612007-10-29 18:06:10 +1000125 struct resource ifp_resource;
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800126} intel_private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
128static int intel_i810_fetch_size(void)
129{
130 u32 smram_miscc;
131 struct aper_size_info_fixed *values;
132
133 pci_read_config_dword(agp_bridge->dev, I810_SMRAM_MISCC, &smram_miscc);
134 values = A_SIZE_FIX(agp_bridge->driver->aperture_sizes);
135
136 if ((smram_miscc & I810_GMS) == I810_GMS_DISABLE) {
137 printk(KERN_WARNING PFX "i810 is disabled\n");
138 return 0;
139 }
140 if ((smram_miscc & I810_GFX_MEM_WIN_SIZE) == I810_GFX_MEM_WIN_32M) {
141 agp_bridge->previous_size =
142 agp_bridge->current_size = (void *) (values + 1);
143 agp_bridge->aperture_size_idx = 1;
144 return values[1].size;
145 } else {
146 agp_bridge->previous_size =
147 agp_bridge->current_size = (void *) (values);
148 agp_bridge->aperture_size_idx = 0;
149 return values[0].size;
150 }
151
152 return 0;
153}
154
155static int intel_i810_configure(void)
156{
157 struct aper_size_info_fixed *current_size;
158 u32 temp;
159 int i;
160
161 current_size = A_SIZE_FIX(agp_bridge->current_size);
162
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800163 if (!intel_private.registers) {
164 pci_read_config_dword(intel_private.pcidev, I810_MMADDR, &temp);
Dave Jonese4ac5e42007-02-04 17:37:42 -0500165 temp &= 0xfff80000;
166
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800167 intel_private.registers = ioremap(temp, 128 * 4096);
168 if (!intel_private.registers) {
Dave Jonese4ac5e42007-02-04 17:37:42 -0500169 printk(KERN_ERR PFX "Unable to remap memory.\n");
170 return -ENOMEM;
171 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 }
173
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800174 if ((readl(intel_private.registers+I810_DRAM_CTL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 & I810_DRAM_ROW_0) == I810_DRAM_ROW_0_SDRAM) {
176 /* This will need to be dynamically assigned */
177 printk(KERN_INFO PFX "detected 4MB dedicated video ram.\n");
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800178 intel_private.num_dcache_entries = 1024;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 }
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800180 pci_read_config_dword(intel_private.pcidev, I810_GMADDR, &temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800182 writel(agp_bridge->gatt_bus_addr | I810_PGETBL_ENABLED, intel_private.registers+I810_PGETBL_CTL);
183 readl(intel_private.registers+I810_PGETBL_CTL); /* PCI Posting. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
185 if (agp_bridge->driver->needs_scratch_page) {
186 for (i = 0; i < current_size->num_entries; i++) {
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800187 writel(agp_bridge->scratch_page, intel_private.registers+I810_PTE_BASE+(i*4));
188 readl(intel_private.registers+I810_PTE_BASE+(i*4)); /* PCI posting. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 }
190 }
191 global_cache_flush();
192 return 0;
193}
194
195static void intel_i810_cleanup(void)
196{
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800197 writel(0, intel_private.registers+I810_PGETBL_CTL);
198 readl(intel_private.registers); /* PCI Posting. */
199 iounmap(intel_private.registers);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200}
201
202static void intel_i810_tlbflush(struct agp_memory *mem)
203{
204 return;
205}
206
207static void intel_i810_agp_enable(struct agp_bridge_data *bridge, u32 mode)
208{
209 return;
210}
211
212/* Exists to support ARGB cursors */
213static void *i8xx_alloc_pages(void)
214{
215 struct page * page;
216
Linus Torvalds66c669b2006-11-22 14:55:29 -0800217 page = alloc_pages(GFP_KERNEL | GFP_DMA32, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 if (page == NULL)
219 return NULL;
220
Arjan van de Ven6d238cc2008-01-30 13:34:06 +0100221 if (set_pages_uc(page, 4) < 0) {
222 set_pages_wb(page, 4);
Jan Beulich89cf7cc2007-04-02 14:50:14 +0100223 __free_pages(page, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 return NULL;
225 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 get_page(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 atomic_inc(&agp_bridge->current_memory_agp);
228 return page_address(page);
229}
230
231static void i8xx_destroy_pages(void *addr)
232{
233 struct page *page;
234
235 if (addr == NULL)
236 return;
237
238 page = virt_to_page(addr);
Arjan van de Ven6d238cc2008-01-30 13:34:06 +0100239 set_pages_wb(page, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 put_page(page);
Jan Beulich89cf7cc2007-04-02 14:50:14 +0100241 __free_pages(page, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 atomic_dec(&agp_bridge->current_memory_agp);
243}
244
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100245static int intel_i830_type_to_mask_type(struct agp_bridge_data *bridge,
246 int type)
247{
248 if (type < AGP_USER_TYPES)
249 return type;
250 else if (type == AGP_USER_CACHED_MEMORY)
251 return INTEL_AGP_CACHED_MEMORY;
252 else
253 return 0;
254}
255
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256static int intel_i810_insert_entries(struct agp_memory *mem, off_t pg_start,
257 int type)
258{
259 int i, j, num_entries;
260 void *temp;
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100261 int ret = -EINVAL;
262 int mask_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +0100264 if (mem->page_count == 0)
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100265 goto out;
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +0100266
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 temp = agp_bridge->current_size;
268 num_entries = A_SIZE_FIX(temp)->num_entries;
269
Dave Jones6a92a4e2006-02-28 00:54:25 -0500270 if ((pg_start + mem->page_count) > num_entries)
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100271 goto out_err;
272
Dave Jones6a92a4e2006-02-28 00:54:25 -0500273
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 for (j = pg_start; j < (pg_start + mem->page_count); j++) {
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100275 if (!PGE_EMPTY(agp_bridge, readl(agp_bridge->gatt_table+j))) {
276 ret = -EBUSY;
277 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 }
280
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100281 if (type != mem->type)
282 goto out_err;
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +0100283
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100284 mask_type = agp_bridge->driver->agp_type_to_mask_type(agp_bridge, type);
285
286 switch (mask_type) {
287 case AGP_DCACHE_MEMORY:
288 if (!mem->is_flushed)
289 global_cache_flush();
290 for (i = pg_start; i < (pg_start + mem->page_count); i++) {
291 writel((i*4096)|I810_PTE_LOCAL|I810_PTE_VALID,
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800292 intel_private.registers+I810_PTE_BASE+(i*4));
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100293 }
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800294 readl(intel_private.registers+I810_PTE_BASE+((i-1)*4));
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100295 break;
296 case AGP_PHYS_MEMORY:
297 case AGP_NORMAL_MEMORY:
298 if (!mem->is_flushed)
299 global_cache_flush();
300 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
301 writel(agp_bridge->driver->mask_memory(agp_bridge,
302 mem->memory[i],
303 mask_type),
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800304 intel_private.registers+I810_PTE_BASE+(j*4));
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100305 }
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800306 readl(intel_private.registers+I810_PTE_BASE+((j-1)*4));
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100307 break;
308 default:
309 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311
312 agp_bridge->driver->tlb_flush(mem);
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100313out:
314 ret = 0;
315out_err:
316 mem->is_flushed = 1;
317 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318}
319
320static int intel_i810_remove_entries(struct agp_memory *mem, off_t pg_start,
321 int type)
322{
323 int i;
324
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +0100325 if (mem->page_count == 0)
326 return 0;
327
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 for (i = pg_start; i < (mem->page_count + pg_start); i++) {
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800329 writel(agp_bridge->scratch_page, intel_private.registers+I810_PTE_BASE+(i*4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 }
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800331 readl(intel_private.registers+I810_PTE_BASE+((i-1)*4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 agp_bridge->driver->tlb_flush(mem);
334 return 0;
335}
336
337/*
338 * The i810/i830 requires a physical address to program its mouse
339 * pointer into hardware.
340 * However the Xserver still writes to it through the agp aperture.
341 */
342static struct agp_memory *alloc_agpphysmem_i8xx(size_t pg_count, int type)
343{
344 struct agp_memory *new;
345 void *addr;
346
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 switch (pg_count) {
348 case 1: addr = agp_bridge->driver->agp_alloc_page(agp_bridge);
349 break;
350 case 4:
351 /* kludge to get 4 physical pages for ARGB cursor */
352 addr = i8xx_alloc_pages();
353 break;
354 default:
355 return NULL;
356 }
357
358 if (addr == NULL)
359 return NULL;
360
361 new = agp_create_memory(pg_count);
362 if (new == NULL)
363 return NULL;
364
Keir Fraser07eee782005-03-30 13:17:04 -0800365 new->memory[0] = virt_to_gart(addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 if (pg_count == 4) {
367 /* kludge to get 4 physical pages for ARGB cursor */
368 new->memory[1] = new->memory[0] + PAGE_SIZE;
369 new->memory[2] = new->memory[1] + PAGE_SIZE;
370 new->memory[3] = new->memory[2] + PAGE_SIZE;
371 }
372 new->page_count = pg_count;
373 new->num_scratch_pages = pg_count;
374 new->type = AGP_PHYS_MEMORY;
375 new->physical = new->memory[0];
376 return new;
377}
378
379static struct agp_memory *intel_i810_alloc_by_type(size_t pg_count, int type)
380{
381 struct agp_memory *new;
382
383 if (type == AGP_DCACHE_MEMORY) {
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800384 if (pg_count != intel_private.num_dcache_entries)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 return NULL;
386
387 new = agp_create_memory(1);
388 if (new == NULL)
389 return NULL;
390
391 new->type = AGP_DCACHE_MEMORY;
392 new->page_count = pg_count;
393 new->num_scratch_pages = 0;
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100394 agp_free_page_array(new);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 return new;
396 }
397 if (type == AGP_PHYS_MEMORY)
398 return alloc_agpphysmem_i8xx(pg_count, type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 return NULL;
400}
401
402static void intel_i810_free_by_type(struct agp_memory *curr)
403{
404 agp_free_key(curr->key);
Dave Jones6a92a4e2006-02-28 00:54:25 -0500405 if (curr->type == AGP_PHYS_MEMORY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 if (curr->page_count == 4)
Keir Fraser07eee782005-03-30 13:17:04 -0800407 i8xx_destroy_pages(gart_to_virt(curr->memory[0]));
Alan Hourihane88d51962005-11-06 23:35:34 -0800408 else {
Dave Airliea2721e92007-10-15 10:19:16 +1000409 agp_bridge->driver->agp_destroy_page(gart_to_virt(curr->memory[0]),
410 AGP_PAGE_DESTROY_UNMAP);
Dave Airliea2721e92007-10-15 10:19:16 +1000411 agp_bridge->driver->agp_destroy_page(gart_to_virt(curr->memory[0]),
412 AGP_PAGE_DESTROY_FREE);
Alan Hourihane88d51962005-11-06 23:35:34 -0800413 }
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100414 agp_free_page_array(curr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 }
416 kfree(curr);
417}
418
419static unsigned long intel_i810_mask_memory(struct agp_bridge_data *bridge,
420 unsigned long addr, int type)
421{
422 /* Type checking must be done elsewhere */
423 return addr | bridge->driver->masks[type].mask;
424}
425
426static struct aper_size_info_fixed intel_i830_sizes[] =
427{
428 {128, 32768, 5},
429 /* The 64M mode still requires a 128k gatt */
430 {64, 16384, 5},
431 {256, 65536, 6},
Eric Anholt65c25aa2006-09-06 11:57:18 -0400432 {512, 131072, 7},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433};
434
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435static void intel_i830_init_gtt_entries(void)
436{
437 u16 gmch_ctrl;
438 int gtt_entries;
439 u8 rdct;
440 int local = 0;
441 static const int ddt[4] = { 0, 16, 32, 64 };
Eric Anholtc41e0de2006-12-19 12:57:24 -0800442 int size; /* reserved space (in kb) at the top of stolen memory */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443
444 pci_read_config_word(agp_bridge->dev,I830_GMCH_CTRL,&gmch_ctrl);
445
Eric Anholtc41e0de2006-12-19 12:57:24 -0800446 if (IS_I965) {
447 u32 pgetbl_ctl;
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800448 pgetbl_ctl = readl(intel_private.registers+I810_PGETBL_CTL);
Eric Anholtc41e0de2006-12-19 12:57:24 -0800449
Eric Anholtc41e0de2006-12-19 12:57:24 -0800450 /* The 965 has a field telling us the size of the GTT,
451 * which may be larger than what is necessary to map the
452 * aperture.
453 */
454 switch (pgetbl_ctl & I965_PGETBL_SIZE_MASK) {
455 case I965_PGETBL_SIZE_128KB:
456 size = 128;
457 break;
458 case I965_PGETBL_SIZE_256KB:
459 size = 256;
460 break;
461 case I965_PGETBL_SIZE_512KB:
462 size = 512;
463 break;
464 default:
465 printk(KERN_INFO PFX "Unknown page table size, "
466 "assuming 512KB\n");
467 size = 512;
468 }
469 size += 4; /* add in BIOS popup space */
Wang Zhenyu874808c62007-06-06 11:16:25 +0800470 } else if (IS_G33) {
471 /* G33's GTT size defined in gmch_ctrl */
472 switch (gmch_ctrl & G33_PGETBL_SIZE_MASK) {
473 case G33_PGETBL_SIZE_1M:
474 size = 1024;
475 break;
476 case G33_PGETBL_SIZE_2M:
477 size = 2048;
478 break;
479 default:
480 printk(KERN_INFO PFX "Unknown page table size 0x%x, "
481 "assuming 512KB\n",
482 (gmch_ctrl & G33_PGETBL_SIZE_MASK));
483 size = 512;
484 }
485 size += 4;
Eric Anholtc41e0de2006-12-19 12:57:24 -0800486 } else {
487 /* On previous hardware, the GTT size was just what was
488 * required to map the aperture.
489 */
490 size = agp_bridge->driver->fetch_size() + 4;
491 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
493 if (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82830_HB ||
494 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82845G_HB) {
495 switch (gmch_ctrl & I830_GMCH_GMS_MASK) {
496 case I830_GMCH_GMS_STOLEN_512:
497 gtt_entries = KB(512) - KB(size);
498 break;
499 case I830_GMCH_GMS_STOLEN_1024:
500 gtt_entries = MB(1) - KB(size);
501 break;
502 case I830_GMCH_GMS_STOLEN_8192:
503 gtt_entries = MB(8) - KB(size);
504 break;
505 case I830_GMCH_GMS_LOCAL:
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800506 rdct = readb(intel_private.registers+I830_RDRAM_CHANNEL_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 gtt_entries = (I830_RDRAM_ND(rdct) + 1) *
508 MB(ddt[I830_RDRAM_DDT(rdct)]);
509 local = 1;
510 break;
511 default:
512 gtt_entries = 0;
513 break;
514 }
515 } else {
Dave Airliee67aa272007-09-18 22:46:35 -0700516 switch (gmch_ctrl & I855_GMCH_GMS_MASK) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 case I855_GMCH_GMS_STOLEN_1M:
518 gtt_entries = MB(1) - KB(size);
519 break;
520 case I855_GMCH_GMS_STOLEN_4M:
521 gtt_entries = MB(4) - KB(size);
522 break;
523 case I855_GMCH_GMS_STOLEN_8M:
524 gtt_entries = MB(8) - KB(size);
525 break;
526 case I855_GMCH_GMS_STOLEN_16M:
527 gtt_entries = MB(16) - KB(size);
528 break;
529 case I855_GMCH_GMS_STOLEN_32M:
530 gtt_entries = MB(32) - KB(size);
531 break;
532 case I915_GMCH_GMS_STOLEN_48M:
533 /* Check it's really I915G */
Carlos Martíne914a362008-01-24 10:34:09 +1000534 if (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_E7221_HB ||
535 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82915G_HB ||
Alan Hourihaned0de98f2005-05-31 19:50:49 +0100536 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82915GM_HB ||
Alan Hourihane3b0e8ea2006-01-19 14:08:40 +0000537 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82945G_HB ||
Wang Zhenyu874808c62007-06-06 11:16:25 +0800538 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82945GM_HB ||
Zhenyu Wangdde47872007-07-26 09:18:09 +0800539 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82945GME_HB ||
Wang Zhenyu874808c62007-06-06 11:16:25 +0800540 IS_I965 || IS_G33)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 gtt_entries = MB(48) - KB(size);
542 else
543 gtt_entries = 0;
544 break;
545 case I915_GMCH_GMS_STOLEN_64M:
546 /* Check it's really I915G */
Carlos Martíne914a362008-01-24 10:34:09 +1000547 if (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_E7221_HB ||
548 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82915G_HB ||
Alan Hourihaned0de98f2005-05-31 19:50:49 +0100549 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82915GM_HB ||
Alan Hourihane3b0e8ea2006-01-19 14:08:40 +0000550 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82945G_HB ||
Wang Zhenyu874808c62007-06-06 11:16:25 +0800551 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82945GM_HB ||
Zhenyu Wangdde47872007-07-26 09:18:09 +0800552 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82945GME_HB ||
Wang Zhenyu874808c62007-06-06 11:16:25 +0800553 IS_I965 || IS_G33)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 gtt_entries = MB(64) - KB(size);
555 else
556 gtt_entries = 0;
Wang Zhenyu874808c62007-06-06 11:16:25 +0800557 break;
558 case G33_GMCH_GMS_STOLEN_128M:
559 if (IS_G33)
560 gtt_entries = MB(128) - KB(size);
561 else
562 gtt_entries = 0;
563 break;
564 case G33_GMCH_GMS_STOLEN_256M:
565 if (IS_G33)
566 gtt_entries = MB(256) - KB(size);
567 else
568 gtt_entries = 0;
569 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 default:
571 gtt_entries = 0;
572 break;
573 }
574 }
575 if (gtt_entries > 0)
576 printk(KERN_INFO PFX "Detected %dK %s memory.\n",
577 gtt_entries / KB(1), local ? "local" : "stolen");
578 else
579 printk(KERN_INFO PFX
580 "No pre-allocated video memory detected.\n");
581 gtt_entries /= KB(4);
582
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800583 intel_private.gtt_entries = gtt_entries;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584}
585
Dave Airlie2162e6a2007-11-21 16:36:31 +1000586static void intel_i830_fini_flush(void)
587{
588 kunmap(intel_private.i8xx_page);
589 intel_private.i8xx_flush_page = NULL;
590 unmap_page_from_agp(intel_private.i8xx_page);
591 flush_agp_mappings();
592
593 __free_page(intel_private.i8xx_page);
594}
595
596static void intel_i830_setup_flush(void)
597{
598
599 intel_private.i8xx_page = alloc_page(GFP_KERNEL | __GFP_ZERO | GFP_DMA32);
600 if (!intel_private.i8xx_page) {
601 return;
602 }
603
604 /* make page uncached */
605 map_page_into_agp(intel_private.i8xx_page);
606 flush_agp_mappings();
607
608 intel_private.i8xx_flush_page = kmap(intel_private.i8xx_page);
609 if (!intel_private.i8xx_flush_page)
610 intel_i830_fini_flush();
611}
612
613static void intel_i830_chipset_flush(struct agp_bridge_data *bridge)
614{
615 unsigned int *pg = intel_private.i8xx_flush_page;
616 int i;
617
618 for (i = 0; i < 256; i+=2)
619 *(pg + i) = i;
620
621 wmb();
622}
623
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624/* The intel i830 automatically initializes the agp aperture during POST.
625 * Use the memory already set aside for in the GTT.
626 */
627static int intel_i830_create_gatt_table(struct agp_bridge_data *bridge)
628{
629 int page_order;
630 struct aper_size_info_fixed *size;
631 int num_entries;
632 u32 temp;
633
634 size = agp_bridge->current_size;
635 page_order = size->page_order;
636 num_entries = size->num_entries;
637 agp_bridge->gatt_table_real = NULL;
638
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800639 pci_read_config_dword(intel_private.pcidev,I810_MMADDR,&temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 temp &= 0xfff80000;
641
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800642 intel_private.registers = ioremap(temp,128 * 4096);
643 if (!intel_private.registers)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 return -ENOMEM;
645
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800646 temp = readl(intel_private.registers+I810_PGETBL_CTL) & 0xfffff000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 global_cache_flush(); /* FIXME: ?? */
648
649 /* we have to call this as early as possible after the MMIO base address is known */
650 intel_i830_init_gtt_entries();
651
652 agp_bridge->gatt_table = NULL;
653
654 agp_bridge->gatt_bus_addr = temp;
655
656 return 0;
657}
658
659/* Return the gatt table to a sane state. Use the top of stolen
660 * memory for the GTT.
661 */
662static int intel_i830_free_gatt_table(struct agp_bridge_data *bridge)
663{
664 return 0;
665}
666
667static int intel_i830_fetch_size(void)
668{
669 u16 gmch_ctrl;
670 struct aper_size_info_fixed *values;
671
672 values = A_SIZE_FIX(agp_bridge->driver->aperture_sizes);
673
674 if (agp_bridge->dev->device != PCI_DEVICE_ID_INTEL_82830_HB &&
675 agp_bridge->dev->device != PCI_DEVICE_ID_INTEL_82845G_HB) {
676 /* 855GM/852GM/865G has 128MB aperture size */
677 agp_bridge->previous_size = agp_bridge->current_size = (void *) values;
678 agp_bridge->aperture_size_idx = 0;
679 return values[0].size;
680 }
681
682 pci_read_config_word(agp_bridge->dev,I830_GMCH_CTRL,&gmch_ctrl);
683
684 if ((gmch_ctrl & I830_GMCH_MEM_MASK) == I830_GMCH_MEM_128M) {
685 agp_bridge->previous_size = agp_bridge->current_size = (void *) values;
686 agp_bridge->aperture_size_idx = 0;
687 return values[0].size;
688 } else {
689 agp_bridge->previous_size = agp_bridge->current_size = (void *) (values + 1);
690 agp_bridge->aperture_size_idx = 1;
691 return values[1].size;
692 }
693
694 return 0;
695}
696
697static int intel_i830_configure(void)
698{
699 struct aper_size_info_fixed *current_size;
700 u32 temp;
701 u16 gmch_ctrl;
702 int i;
703
704 current_size = A_SIZE_FIX(agp_bridge->current_size);
705
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800706 pci_read_config_dword(intel_private.pcidev,I810_GMADDR,&temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
708
709 pci_read_config_word(agp_bridge->dev,I830_GMCH_CTRL,&gmch_ctrl);
710 gmch_ctrl |= I830_GMCH_ENABLED;
711 pci_write_config_word(agp_bridge->dev,I830_GMCH_CTRL,gmch_ctrl);
712
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800713 writel(agp_bridge->gatt_bus_addr|I810_PGETBL_ENABLED, intel_private.registers+I810_PGETBL_CTL);
714 readl(intel_private.registers+I810_PGETBL_CTL); /* PCI Posting. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
716 if (agp_bridge->driver->needs_scratch_page) {
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800717 for (i = intel_private.gtt_entries; i < current_size->num_entries; i++) {
718 writel(agp_bridge->scratch_page, intel_private.registers+I810_PTE_BASE+(i*4));
719 readl(intel_private.registers+I810_PTE_BASE+(i*4)); /* PCI Posting. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 }
721 }
722
723 global_cache_flush();
Dave Airlie2162e6a2007-11-21 16:36:31 +1000724
725 intel_i830_setup_flush();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 return 0;
727}
728
729static void intel_i830_cleanup(void)
730{
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800731 iounmap(intel_private.registers);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732}
733
734static int intel_i830_insert_entries(struct agp_memory *mem,off_t pg_start, int type)
735{
736 int i,j,num_entries;
737 void *temp;
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100738 int ret = -EINVAL;
739 int mask_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +0100741 if (mem->page_count == 0)
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100742 goto out;
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +0100743
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 temp = agp_bridge->current_size;
745 num_entries = A_SIZE_FIX(temp)->num_entries;
746
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800747 if (pg_start < intel_private.gtt_entries) {
748 printk (KERN_DEBUG PFX "pg_start == 0x%.8lx,intel_private.gtt_entries == 0x%.8x\n",
749 pg_start,intel_private.gtt_entries);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750
751 printk (KERN_INFO PFX "Trying to insert into local/stolen memory\n");
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100752 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 }
754
755 if ((pg_start + mem->page_count) > num_entries)
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100756 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757
758 /* The i830 can't check the GTT for entries since its read only,
759 * depend on the caller to make the correct offset decisions.
760 */
761
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100762 if (type != mem->type)
763 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100765 mask_type = agp_bridge->driver->agp_type_to_mask_type(agp_bridge, type);
766
767 if (mask_type != 0 && mask_type != AGP_PHYS_MEMORY &&
768 mask_type != INTEL_AGP_CACHED_MEMORY)
769 goto out_err;
770
771 if (!mem->is_flushed)
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +0100772 global_cache_flush();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773
774 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
775 writel(agp_bridge->driver->mask_memory(agp_bridge,
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100776 mem->memory[i], mask_type),
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800777 intel_private.registers+I810_PTE_BASE+(j*4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 }
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800779 readl(intel_private.registers+I810_PTE_BASE+((j-1)*4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 agp_bridge->driver->tlb_flush(mem);
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100781
782out:
783 ret = 0;
784out_err:
785 mem->is_flushed = 1;
786 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787}
788
789static int intel_i830_remove_entries(struct agp_memory *mem,off_t pg_start,
790 int type)
791{
792 int i;
793
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +0100794 if (mem->page_count == 0)
795 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800797 if (pg_start < intel_private.gtt_entries) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 printk (KERN_INFO PFX "Trying to disable local/stolen memory\n");
799 return -EINVAL;
800 }
801
802 for (i = pg_start; i < (mem->page_count + pg_start); i++) {
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800803 writel(agp_bridge->scratch_page, intel_private.registers+I810_PTE_BASE+(i*4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 }
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800805 readl(intel_private.registers+I810_PTE_BASE+((i-1)*4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 agp_bridge->driver->tlb_flush(mem);
808 return 0;
809}
810
811static struct agp_memory *intel_i830_alloc_by_type(size_t pg_count,int type)
812{
813 if (type == AGP_PHYS_MEMORY)
814 return alloc_agpphysmem_i8xx(pg_count, type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 /* always return NULL for other allocation types for now */
816 return NULL;
817}
818
Dave Airlie6c00a612007-10-29 18:06:10 +1000819static int intel_alloc_chipset_flush_resource(void)
820{
821 int ret;
822 ret = pci_bus_alloc_resource(agp_bridge->dev->bus, &intel_private.ifp_resource, PAGE_SIZE,
823 PAGE_SIZE, PCIBIOS_MIN_MEM, 0,
824 pcibios_align_resource, agp_bridge->dev);
Dave Airlie6c00a612007-10-29 18:06:10 +1000825
Dave Airlie2162e6a2007-11-21 16:36:31 +1000826 return ret;
Dave Airlie6c00a612007-10-29 18:06:10 +1000827}
828
829static void intel_i915_setup_chipset_flush(void)
830{
831 int ret;
832 u32 temp;
833
834 pci_read_config_dword(agp_bridge->dev, I915_IFPADDR, &temp);
835 if (!(temp & 0x1)) {
836 intel_alloc_chipset_flush_resource();
837
838 pci_write_config_dword(agp_bridge->dev, I915_IFPADDR, (intel_private.ifp_resource.start & 0xffffffff) | 0x1);
839 } else {
840 temp &= ~1;
841
842 intel_private.ifp_resource.start = temp;
843 intel_private.ifp_resource.end = temp + PAGE_SIZE;
844 ret = request_resource(&iomem_resource, &intel_private.ifp_resource);
845 if (ret) {
846 intel_private.ifp_resource.start = 0;
847 printk("Failed inserting resource into tree\n");
848 }
849 }
850}
851
852static void intel_i965_g33_setup_chipset_flush(void)
853{
854 u32 temp_hi, temp_lo;
855 int ret;
856
857 pci_read_config_dword(agp_bridge->dev, I965_IFPADDR + 4, &temp_hi);
858 pci_read_config_dword(agp_bridge->dev, I965_IFPADDR, &temp_lo);
859
860 if (!(temp_lo & 0x1)) {
861
862 intel_alloc_chipset_flush_resource();
863
Andrew Morton1fa4db72007-11-29 10:00:48 +1000864 pci_write_config_dword(agp_bridge->dev, I965_IFPADDR + 4,
865 upper_32_bits(intel_private.ifp_resource.start));
Dave Airlie6c00a612007-10-29 18:06:10 +1000866 pci_write_config_dword(agp_bridge->dev, I965_IFPADDR, (intel_private.ifp_resource.start & 0xffffffff) | 0x1);
Dave Airlie6c00a612007-10-29 18:06:10 +1000867 } else {
868 u64 l64;
869
870 temp_lo &= ~0x1;
871 l64 = ((u64)temp_hi << 32) | temp_lo;
872
873 intel_private.ifp_resource.start = l64;
874 intel_private.ifp_resource.end = l64 + PAGE_SIZE;
875 ret = request_resource(&iomem_resource, &intel_private.ifp_resource);
876 if (!ret) {
Dave Airlie2162e6a2007-11-21 16:36:31 +1000877 printk("Failed inserting resource into tree - continuing\n");
Dave Airlie6c00a612007-10-29 18:06:10 +1000878 }
879 }
880}
881
Dave Airlie2162e6a2007-11-21 16:36:31 +1000882static void intel_i9xx_setup_flush(void)
883{
884 /* setup a resource for this object */
885 memset(&intel_private.ifp_resource, 0, sizeof(intel_private.ifp_resource));
886
887 intel_private.ifp_resource.name = "Intel Flush Page";
888 intel_private.ifp_resource.flags = IORESOURCE_MEM;
889
890 /* Setup chipset flush for 915 */
891 if (IS_I965 || IS_G33) {
892 intel_i965_g33_setup_chipset_flush();
893 } else {
894 intel_i915_setup_chipset_flush();
895 }
896
897 if (intel_private.ifp_resource.start) {
898 intel_private.i9xx_flush_page = ioremap_nocache(intel_private.ifp_resource.start, PAGE_SIZE);
899 if (!intel_private.i9xx_flush_page)
900 printk("unable to ioremap flush page - no chipset flushing");
901 }
902}
903
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904static int intel_i915_configure(void)
905{
906 struct aper_size_info_fixed *current_size;
907 u32 temp;
908 u16 gmch_ctrl;
909 int i;
910
911 current_size = A_SIZE_FIX(agp_bridge->current_size);
912
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800913 pci_read_config_dword(intel_private.pcidev, I915_GMADDR, &temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914
915 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
916
917 pci_read_config_word(agp_bridge->dev,I830_GMCH_CTRL,&gmch_ctrl);
918 gmch_ctrl |= I830_GMCH_ENABLED;
919 pci_write_config_word(agp_bridge->dev,I830_GMCH_CTRL,gmch_ctrl);
920
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800921 writel(agp_bridge->gatt_bus_addr|I810_PGETBL_ENABLED, intel_private.registers+I810_PGETBL_CTL);
922 readl(intel_private.registers+I810_PGETBL_CTL); /* PCI Posting. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923
924 if (agp_bridge->driver->needs_scratch_page) {
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800925 for (i = intel_private.gtt_entries; i < current_size->num_entries; i++) {
926 writel(agp_bridge->scratch_page, intel_private.gtt+i);
927 readl(intel_private.gtt+i); /* PCI Posting. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 }
929 }
930
931 global_cache_flush();
Dave Airlie6c00a612007-10-29 18:06:10 +1000932
Dave Airlie2162e6a2007-11-21 16:36:31 +1000933 intel_i9xx_setup_flush();
Dave Airlie6c00a612007-10-29 18:06:10 +1000934
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 return 0;
936}
937
938static void intel_i915_cleanup(void)
939{
Dave Airlie2162e6a2007-11-21 16:36:31 +1000940 if (intel_private.i9xx_flush_page)
941 iounmap(intel_private.i9xx_flush_page);
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800942 iounmap(intel_private.gtt);
943 iounmap(intel_private.registers);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944}
945
Dave Airlie6c00a612007-10-29 18:06:10 +1000946static void intel_i915_chipset_flush(struct agp_bridge_data *bridge)
947{
Dave Airlie2162e6a2007-11-21 16:36:31 +1000948 if (intel_private.i9xx_flush_page)
949 writel(1, intel_private.i9xx_flush_page);
Dave Airlie6c00a612007-10-29 18:06:10 +1000950}
951
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952static int intel_i915_insert_entries(struct agp_memory *mem,off_t pg_start,
953 int type)
954{
955 int i,j,num_entries;
956 void *temp;
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100957 int ret = -EINVAL;
958 int mask_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +0100960 if (mem->page_count == 0)
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100961 goto out;
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +0100962
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 temp = agp_bridge->current_size;
964 num_entries = A_SIZE_FIX(temp)->num_entries;
965
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800966 if (pg_start < intel_private.gtt_entries) {
967 printk (KERN_DEBUG PFX "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
970 printk (KERN_INFO PFX "Trying to insert into local/stolen memory\n");
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100971 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 }
973
974 if ((pg_start + mem->page_count) > num_entries)
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100975 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100977 /* The i915 can't check the GTT for entries since its read only,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 * depend on the caller to make the correct offset decisions.
979 */
980
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100981 if (type != mem->type)
982 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100984 mask_type = agp_bridge->driver->agp_type_to_mask_type(agp_bridge, type);
985
986 if (mask_type != 0 && mask_type != AGP_PHYS_MEMORY &&
987 mask_type != INTEL_AGP_CACHED_MEMORY)
988 goto out_err;
989
990 if (!mem->is_flushed)
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +0100991 global_cache_flush();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992
993 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
994 writel(agp_bridge->driver->mask_memory(agp_bridge,
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800995 mem->memory[i], mask_type), intel_private.gtt+j);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 }
997
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800998 readl(intel_private.gtt+j-1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 agp_bridge->driver->tlb_flush(mem);
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001000
1001 out:
1002 ret = 0;
1003 out_err:
1004 mem->is_flushed = 1;
1005 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006}
1007
1008static int intel_i915_remove_entries(struct agp_memory *mem,off_t pg_start,
1009 int type)
1010{
1011 int i;
1012
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +01001013 if (mem->page_count == 0)
1014 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001016 if (pg_start < intel_private.gtt_entries) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 printk (KERN_INFO PFX "Trying to disable local/stolen memory\n");
1018 return -EINVAL;
1019 }
1020
1021 for (i = pg_start; i < (mem->page_count + pg_start); i++) {
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001022 writel(agp_bridge->scratch_page, intel_private.gtt+i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 }
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001024 readl(intel_private.gtt+i-1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 agp_bridge->driver->tlb_flush(mem);
1027 return 0;
1028}
1029
Eric Anholtc41e0de2006-12-19 12:57:24 -08001030/* Return the aperture size by just checking the resource length. The effect
1031 * described in the spec of the MSAC registers is just changing of the
1032 * resource size.
1033 */
1034static int intel_i9xx_fetch_size(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035{
Ahmed S. Darwish1eaf1222007-02-06 18:08:28 +02001036 int num_sizes = ARRAY_SIZE(intel_i830_sizes);
Eric Anholtc41e0de2006-12-19 12:57:24 -08001037 int aper_size; /* size in megabytes */
1038 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001040 aper_size = pci_resource_len(intel_private.pcidev, 2) / MB(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041
Eric Anholtc41e0de2006-12-19 12:57:24 -08001042 for (i = 0; i < num_sizes; i++) {
1043 if (aper_size == intel_i830_sizes[i].size) {
1044 agp_bridge->current_size = intel_i830_sizes + i;
1045 agp_bridge->previous_size = agp_bridge->current_size;
1046 return aper_size;
1047 }
1048 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049
Eric Anholtc41e0de2006-12-19 12:57:24 -08001050 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051}
1052
1053/* The intel i915 automatically initializes the agp aperture during POST.
1054 * Use the memory already set aside for in the GTT.
1055 */
1056static int intel_i915_create_gatt_table(struct agp_bridge_data *bridge)
1057{
1058 int page_order;
1059 struct aper_size_info_fixed *size;
1060 int num_entries;
1061 u32 temp, temp2;
Zhenyu Wang47406222007-09-11 15:23:58 -07001062 int gtt_map_size = 256 * 1024;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063
1064 size = agp_bridge->current_size;
1065 page_order = size->page_order;
1066 num_entries = size->num_entries;
1067 agp_bridge->gatt_table_real = NULL;
1068
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001069 pci_read_config_dword(intel_private.pcidev, I915_MMADDR, &temp);
1070 pci_read_config_dword(intel_private.pcidev, I915_PTEADDR,&temp2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071
Zhenyu Wang47406222007-09-11 15:23:58 -07001072 if (IS_G33)
1073 gtt_map_size = 1024 * 1024; /* 1M on G33 */
1074 intel_private.gtt = ioremap(temp2, gtt_map_size);
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001075 if (!intel_private.gtt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 return -ENOMEM;
1077
1078 temp &= 0xfff80000;
1079
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001080 intel_private.registers = ioremap(temp,128 * 4096);
Scott Thompson5bdbc7d2007-08-25 18:14:00 +10001081 if (!intel_private.registers) {
1082 iounmap(intel_private.gtt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 return -ENOMEM;
Scott Thompson5bdbc7d2007-08-25 18:14:00 +10001084 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001086 temp = readl(intel_private.registers+I810_PGETBL_CTL) & 0xfffff000;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 global_cache_flush(); /* FIXME: ? */
1088
1089 /* we have to call this as early as possible after the MMIO base address is known */
1090 intel_i830_init_gtt_entries();
1091
1092 agp_bridge->gatt_table = NULL;
1093
1094 agp_bridge->gatt_bus_addr = temp;
1095
1096 return 0;
1097}
Linus Torvalds7d915a32006-11-22 09:37:54 -08001098
1099/*
1100 * The i965 supports 36-bit physical addresses, but to keep
1101 * the format of the GTT the same, the bits that don't fit
1102 * in a 32-bit word are shifted down to bits 4..7.
1103 *
1104 * Gcc is smart enough to notice that "(addr >> 28) & 0xf0"
1105 * is always zero on 32-bit architectures, so no need to make
1106 * this conditional.
1107 */
1108static unsigned long intel_i965_mask_memory(struct agp_bridge_data *bridge,
1109 unsigned long addr, int type)
1110{
1111 /* Shift high bits down */
1112 addr |= (addr >> 28) & 0xf0;
1113
1114 /* Type checking must be done elsewhere */
1115 return addr | bridge->driver->masks[type].mask;
1116}
1117
Eric Anholt65c25aa2006-09-06 11:57:18 -04001118/* The intel i965 automatically initializes the agp aperture during POST.
Eric Anholtc41e0de2006-12-19 12:57:24 -08001119 * Use the memory already set aside for in the GTT.
1120 */
Eric Anholt65c25aa2006-09-06 11:57:18 -04001121static int intel_i965_create_gatt_table(struct agp_bridge_data *bridge)
1122{
1123 int page_order;
1124 struct aper_size_info_fixed *size;
1125 int num_entries;
1126 u32 temp;
1127
1128 size = agp_bridge->current_size;
1129 page_order = size->page_order;
1130 num_entries = size->num_entries;
1131 agp_bridge->gatt_table_real = NULL;
1132
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001133 pci_read_config_dword(intel_private.pcidev, I915_MMADDR, &temp);
Eric Anholt65c25aa2006-09-06 11:57:18 -04001134
1135 temp &= 0xfff00000;
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001136 intel_private.gtt = ioremap((temp + (512 * 1024)) , 512 * 1024);
Eric Anholt65c25aa2006-09-06 11:57:18 -04001137
Scott Thompson5bdbc7d2007-08-25 18:14:00 +10001138 if (!intel_private.gtt)
1139 return -ENOMEM;
Eric Anholt65c25aa2006-09-06 11:57:18 -04001140
1141
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001142 intel_private.registers = ioremap(temp,128 * 4096);
Scott Thompson5bdbc7d2007-08-25 18:14:00 +10001143 if (!intel_private.registers) {
1144 iounmap(intel_private.gtt);
1145 return -ENOMEM;
1146 }
Eric Anholt65c25aa2006-09-06 11:57:18 -04001147
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001148 temp = readl(intel_private.registers+I810_PGETBL_CTL) & 0xfffff000;
Eric Anholt65c25aa2006-09-06 11:57:18 -04001149 global_cache_flush(); /* FIXME: ? */
1150
1151 /* we have to call this as early as possible after the MMIO base address is known */
1152 intel_i830_init_gtt_entries();
1153
1154 agp_bridge->gatt_table = NULL;
1155
1156 agp_bridge->gatt_bus_addr = temp;
1157
1158 return 0;
1159}
1160
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161
1162static int intel_fetch_size(void)
1163{
1164 int i;
1165 u16 temp;
1166 struct aper_size_info_16 *values;
1167
1168 pci_read_config_word(agp_bridge->dev, INTEL_APSIZE, &temp);
1169 values = A_SIZE_16(agp_bridge->driver->aperture_sizes);
1170
1171 for (i = 0; i < agp_bridge->driver->num_aperture_sizes; i++) {
1172 if (temp == values[i].size_value) {
1173 agp_bridge->previous_size = agp_bridge->current_size = (void *) (values + i);
1174 agp_bridge->aperture_size_idx = i;
1175 return values[i].size;
1176 }
1177 }
1178
1179 return 0;
1180}
1181
1182static int __intel_8xx_fetch_size(u8 temp)
1183{
1184 int i;
1185 struct aper_size_info_8 *values;
1186
1187 values = A_SIZE_8(agp_bridge->driver->aperture_sizes);
1188
1189 for (i = 0; i < agp_bridge->driver->num_aperture_sizes; i++) {
1190 if (temp == values[i].size_value) {
1191 agp_bridge->previous_size =
1192 agp_bridge->current_size = (void *) (values + i);
1193 agp_bridge->aperture_size_idx = i;
1194 return values[i].size;
1195 }
1196 }
1197 return 0;
1198}
1199
1200static int intel_8xx_fetch_size(void)
1201{
1202 u8 temp;
1203
1204 pci_read_config_byte(agp_bridge->dev, INTEL_APSIZE, &temp);
1205 return __intel_8xx_fetch_size(temp);
1206}
1207
1208static int intel_815_fetch_size(void)
1209{
1210 u8 temp;
1211
1212 /* Intel 815 chipsets have a _weird_ APSIZE register with only
1213 * one non-reserved bit, so mask the others out ... */
1214 pci_read_config_byte(agp_bridge->dev, INTEL_APSIZE, &temp);
1215 temp &= (1 << 3);
1216
1217 return __intel_8xx_fetch_size(temp);
1218}
1219
1220static void intel_tlbflush(struct agp_memory *mem)
1221{
1222 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x2200);
1223 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x2280);
1224}
1225
1226
1227static void intel_8xx_tlbflush(struct agp_memory *mem)
1228{
1229 u32 temp;
1230 pci_read_config_dword(agp_bridge->dev, INTEL_AGPCTRL, &temp);
1231 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, temp & ~(1 << 7));
1232 pci_read_config_dword(agp_bridge->dev, INTEL_AGPCTRL, &temp);
1233 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, temp | (1 << 7));
1234}
1235
1236
1237static void intel_cleanup(void)
1238{
1239 u16 temp;
1240 struct aper_size_info_16 *previous_size;
1241
1242 previous_size = A_SIZE_16(agp_bridge->previous_size);
1243 pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp);
1244 pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG, temp & ~(1 << 9));
1245 pci_write_config_word(agp_bridge->dev, INTEL_APSIZE, previous_size->size_value);
1246}
1247
1248
1249static void intel_8xx_cleanup(void)
1250{
1251 u16 temp;
1252 struct aper_size_info_8 *previous_size;
1253
1254 previous_size = A_SIZE_8(agp_bridge->previous_size);
1255 pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp);
1256 pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG, temp & ~(1 << 9));
1257 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, previous_size->size_value);
1258}
1259
1260
1261static int intel_configure(void)
1262{
1263 u32 temp;
1264 u16 temp2;
1265 struct aper_size_info_16 *current_size;
1266
1267 current_size = A_SIZE_16(agp_bridge->current_size);
1268
1269 /* aperture size */
1270 pci_write_config_word(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1271
1272 /* address to map to */
1273 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1274 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1275
1276 /* attbase - aperture base */
1277 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1278
1279 /* agpctrl */
1280 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x2280);
1281
1282 /* paccfg/nbxcfg */
1283 pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp2);
1284 pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG,
1285 (temp2 & ~(1 << 10)) | (1 << 9));
1286 /* clear any possible error conditions */
1287 pci_write_config_byte(agp_bridge->dev, INTEL_ERRSTS + 1, 7);
1288 return 0;
1289}
1290
1291static int intel_815_configure(void)
1292{
1293 u32 temp, addr;
1294 u8 temp2;
1295 struct aper_size_info_8 *current_size;
1296
1297 /* attbase - aperture base */
1298 /* the Intel 815 chipset spec. says that bits 29-31 in the
1299 * ATTBASE register are reserved -> try not to write them */
1300 if (agp_bridge->gatt_bus_addr & INTEL_815_ATTBASE_MASK) {
1301 printk (KERN_EMERG PFX "gatt bus addr too high");
1302 return -EINVAL;
1303 }
1304
1305 current_size = A_SIZE_8(agp_bridge->current_size);
1306
1307 /* aperture size */
1308 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE,
1309 current_size->size_value);
1310
1311 /* address to map to */
1312 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1313 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1314
1315 pci_read_config_dword(agp_bridge->dev, INTEL_ATTBASE, &addr);
1316 addr &= INTEL_815_ATTBASE_MASK;
1317 addr |= agp_bridge->gatt_bus_addr;
1318 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, addr);
1319
1320 /* agpctrl */
1321 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1322
1323 /* apcont */
1324 pci_read_config_byte(agp_bridge->dev, INTEL_815_APCONT, &temp2);
1325 pci_write_config_byte(agp_bridge->dev, INTEL_815_APCONT, temp2 | (1 << 1));
1326
1327 /* clear any possible error conditions */
1328 /* Oddness : this chipset seems to have no ERRSTS register ! */
1329 return 0;
1330}
1331
1332static void intel_820_tlbflush(struct agp_memory *mem)
1333{
1334 return;
1335}
1336
1337static void intel_820_cleanup(void)
1338{
1339 u8 temp;
1340 struct aper_size_info_8 *previous_size;
1341
1342 previous_size = A_SIZE_8(agp_bridge->previous_size);
1343 pci_read_config_byte(agp_bridge->dev, INTEL_I820_RDCR, &temp);
1344 pci_write_config_byte(agp_bridge->dev, INTEL_I820_RDCR,
1345 temp & ~(1 << 1));
1346 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE,
1347 previous_size->size_value);
1348}
1349
1350
1351static int intel_820_configure(void)
1352{
1353 u32 temp;
1354 u8 temp2;
1355 struct aper_size_info_8 *current_size;
1356
1357 current_size = A_SIZE_8(agp_bridge->current_size);
1358
1359 /* aperture size */
1360 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1361
1362 /* address to map to */
1363 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1364 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1365
1366 /* attbase - aperture base */
1367 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1368
1369 /* agpctrl */
1370 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1371
1372 /* global enable aperture access */
1373 /* This flag is not accessed through MCHCFG register as in */
1374 /* i850 chipset. */
1375 pci_read_config_byte(agp_bridge->dev, INTEL_I820_RDCR, &temp2);
1376 pci_write_config_byte(agp_bridge->dev, INTEL_I820_RDCR, temp2 | (1 << 1));
1377 /* clear any possible AGP-related error conditions */
1378 pci_write_config_word(agp_bridge->dev, INTEL_I820_ERRSTS, 0x001c);
1379 return 0;
1380}
1381
1382static int intel_840_configure(void)
1383{
1384 u32 temp;
1385 u16 temp2;
1386 struct aper_size_info_8 *current_size;
1387
1388 current_size = A_SIZE_8(agp_bridge->current_size);
1389
1390 /* aperture size */
1391 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1392
1393 /* address to map to */
1394 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1395 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1396
1397 /* attbase - aperture base */
1398 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1399
1400 /* agpctrl */
1401 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1402
1403 /* mcgcfg */
1404 pci_read_config_word(agp_bridge->dev, INTEL_I840_MCHCFG, &temp2);
1405 pci_write_config_word(agp_bridge->dev, INTEL_I840_MCHCFG, temp2 | (1 << 9));
1406 /* clear any possible error conditions */
1407 pci_write_config_word(agp_bridge->dev, INTEL_I840_ERRSTS, 0xc000);
1408 return 0;
1409}
1410
1411static int intel_845_configure(void)
1412{
1413 u32 temp;
1414 u8 temp2;
1415 struct aper_size_info_8 *current_size;
1416
1417 current_size = A_SIZE_8(agp_bridge->current_size);
1418
1419 /* aperture size */
1420 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1421
Matthew Garrettb0825482005-07-29 14:03:39 -07001422 if (agp_bridge->apbase_config != 0) {
1423 pci_write_config_dword(agp_bridge->dev, AGP_APBASE,
1424 agp_bridge->apbase_config);
1425 } else {
1426 /* address to map to */
1427 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1428 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1429 agp_bridge->apbase_config = temp;
1430 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431
1432 /* attbase - aperture base */
1433 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1434
1435 /* agpctrl */
1436 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1437
1438 /* agpm */
1439 pci_read_config_byte(agp_bridge->dev, INTEL_I845_AGPM, &temp2);
1440 pci_write_config_byte(agp_bridge->dev, INTEL_I845_AGPM, temp2 | (1 << 1));
1441 /* clear any possible error conditions */
1442 pci_write_config_word(agp_bridge->dev, INTEL_I845_ERRSTS, 0x001c);
Dave Airlie2162e6a2007-11-21 16:36:31 +10001443
1444 intel_i830_setup_flush();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 return 0;
1446}
1447
1448static int intel_850_configure(void)
1449{
1450 u32 temp;
1451 u16 temp2;
1452 struct aper_size_info_8 *current_size;
1453
1454 current_size = A_SIZE_8(agp_bridge->current_size);
1455
1456 /* aperture size */
1457 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1458
1459 /* address to map to */
1460 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1461 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1462
1463 /* attbase - aperture base */
1464 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1465
1466 /* agpctrl */
1467 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1468
1469 /* mcgcfg */
1470 pci_read_config_word(agp_bridge->dev, INTEL_I850_MCHCFG, &temp2);
1471 pci_write_config_word(agp_bridge->dev, INTEL_I850_MCHCFG, temp2 | (1 << 9));
1472 /* clear any possible AGP-related error conditions */
1473 pci_write_config_word(agp_bridge->dev, INTEL_I850_ERRSTS, 0x001c);
1474 return 0;
1475}
1476
1477static int intel_860_configure(void)
1478{
1479 u32 temp;
1480 u16 temp2;
1481 struct aper_size_info_8 *current_size;
1482
1483 current_size = A_SIZE_8(agp_bridge->current_size);
1484
1485 /* aperture size */
1486 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1487
1488 /* address to map to */
1489 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1490 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1491
1492 /* attbase - aperture base */
1493 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1494
1495 /* agpctrl */
1496 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1497
1498 /* mcgcfg */
1499 pci_read_config_word(agp_bridge->dev, INTEL_I860_MCHCFG, &temp2);
1500 pci_write_config_word(agp_bridge->dev, INTEL_I860_MCHCFG, temp2 | (1 << 9));
1501 /* clear any possible AGP-related error conditions */
1502 pci_write_config_word(agp_bridge->dev, INTEL_I860_ERRSTS, 0xf700);
1503 return 0;
1504}
1505
1506static int intel_830mp_configure(void)
1507{
1508 u32 temp;
1509 u16 temp2;
1510 struct aper_size_info_8 *current_size;
1511
1512 current_size = A_SIZE_8(agp_bridge->current_size);
1513
1514 /* aperture size */
1515 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1516
1517 /* address to map to */
1518 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1519 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1520
1521 /* attbase - aperture base */
1522 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1523
1524 /* agpctrl */
1525 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1526
1527 /* gmch */
1528 pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp2);
1529 pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG, temp2 | (1 << 9));
1530 /* clear any possible AGP-related error conditions */
1531 pci_write_config_word(agp_bridge->dev, INTEL_I830_ERRSTS, 0x1c);
1532 return 0;
1533}
1534
1535static int intel_7505_configure(void)
1536{
1537 u32 temp;
1538 u16 temp2;
1539 struct aper_size_info_8 *current_size;
1540
1541 current_size = A_SIZE_8(agp_bridge->current_size);
1542
1543 /* aperture size */
1544 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1545
1546 /* address to map to */
1547 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1548 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1549
1550 /* attbase - aperture base */
1551 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1552
1553 /* agpctrl */
1554 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1555
1556 /* mchcfg */
1557 pci_read_config_word(agp_bridge->dev, INTEL_I7505_MCHCFG, &temp2);
1558 pci_write_config_word(agp_bridge->dev, INTEL_I7505_MCHCFG, temp2 | (1 << 9));
1559
1560 return 0;
1561}
1562
1563/* Setup function */
Dave Jonese5524f32007-02-22 18:41:28 -05001564static const struct gatt_mask intel_generic_masks[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565{
1566 {.mask = 0x00000017, .type = 0}
1567};
1568
Dave Jonese5524f32007-02-22 18:41:28 -05001569static const struct aper_size_info_8 intel_815_sizes[2] =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570{
1571 {64, 16384, 4, 0},
1572 {32, 8192, 3, 8},
1573};
1574
Dave Jonese5524f32007-02-22 18:41:28 -05001575static const struct aper_size_info_8 intel_8xx_sizes[7] =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576{
1577 {256, 65536, 6, 0},
1578 {128, 32768, 5, 32},
1579 {64, 16384, 4, 48},
1580 {32, 8192, 3, 56},
1581 {16, 4096, 2, 60},
1582 {8, 2048, 1, 62},
1583 {4, 1024, 0, 63}
1584};
1585
Dave Jonese5524f32007-02-22 18:41:28 -05001586static const struct aper_size_info_16 intel_generic_sizes[7] =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587{
1588 {256, 65536, 6, 0},
1589 {128, 32768, 5, 32},
1590 {64, 16384, 4, 48},
1591 {32, 8192, 3, 56},
1592 {16, 4096, 2, 60},
1593 {8, 2048, 1, 62},
1594 {4, 1024, 0, 63}
1595};
1596
Dave Jonese5524f32007-02-22 18:41:28 -05001597static const struct aper_size_info_8 intel_830mp_sizes[4] =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598{
1599 {256, 65536, 6, 0},
1600 {128, 32768, 5, 32},
1601 {64, 16384, 4, 48},
1602 {32, 8192, 3, 56}
1603};
1604
Dave Jonese5524f32007-02-22 18:41:28 -05001605static const struct agp_bridge_driver intel_generic_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606 .owner = THIS_MODULE,
1607 .aperture_sizes = intel_generic_sizes,
1608 .size_type = U16_APER_SIZE,
1609 .num_aperture_sizes = 7,
1610 .configure = intel_configure,
1611 .fetch_size = intel_fetch_size,
1612 .cleanup = intel_cleanup,
1613 .tlb_flush = intel_tlbflush,
1614 .mask_memory = agp_generic_mask_memory,
1615 .masks = intel_generic_masks,
1616 .agp_enable = agp_generic_enable,
1617 .cache_flush = global_cache_flush,
1618 .create_gatt_table = agp_generic_create_gatt_table,
1619 .free_gatt_table = agp_generic_free_gatt_table,
1620 .insert_memory = agp_generic_insert_memory,
1621 .remove_memory = agp_generic_remove_memory,
1622 .alloc_by_type = agp_generic_alloc_by_type,
1623 .free_by_type = agp_generic_free_by_type,
1624 .agp_alloc_page = agp_generic_alloc_page,
1625 .agp_destroy_page = agp_generic_destroy_page,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001626 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627};
1628
Dave Jonese5524f32007-02-22 18:41:28 -05001629static const struct agp_bridge_driver intel_810_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630 .owner = THIS_MODULE,
1631 .aperture_sizes = intel_i810_sizes,
1632 .size_type = FIXED_APER_SIZE,
1633 .num_aperture_sizes = 2,
1634 .needs_scratch_page = TRUE,
1635 .configure = intel_i810_configure,
1636 .fetch_size = intel_i810_fetch_size,
1637 .cleanup = intel_i810_cleanup,
1638 .tlb_flush = intel_i810_tlbflush,
1639 .mask_memory = intel_i810_mask_memory,
1640 .masks = intel_i810_masks,
1641 .agp_enable = intel_i810_agp_enable,
1642 .cache_flush = global_cache_flush,
1643 .create_gatt_table = agp_generic_create_gatt_table,
1644 .free_gatt_table = agp_generic_free_gatt_table,
1645 .insert_memory = intel_i810_insert_entries,
1646 .remove_memory = intel_i810_remove_entries,
1647 .alloc_by_type = intel_i810_alloc_by_type,
1648 .free_by_type = intel_i810_free_by_type,
1649 .agp_alloc_page = agp_generic_alloc_page,
1650 .agp_destroy_page = agp_generic_destroy_page,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001651 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652};
1653
Dave Jonese5524f32007-02-22 18:41:28 -05001654static const struct agp_bridge_driver intel_815_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655 .owner = THIS_MODULE,
1656 .aperture_sizes = intel_815_sizes,
1657 .size_type = U8_APER_SIZE,
1658 .num_aperture_sizes = 2,
1659 .configure = intel_815_configure,
1660 .fetch_size = intel_815_fetch_size,
1661 .cleanup = intel_8xx_cleanup,
1662 .tlb_flush = intel_8xx_tlbflush,
1663 .mask_memory = agp_generic_mask_memory,
1664 .masks = intel_generic_masks,
1665 .agp_enable = agp_generic_enable,
1666 .cache_flush = global_cache_flush,
1667 .create_gatt_table = agp_generic_create_gatt_table,
1668 .free_gatt_table = agp_generic_free_gatt_table,
1669 .insert_memory = agp_generic_insert_memory,
1670 .remove_memory = agp_generic_remove_memory,
1671 .alloc_by_type = agp_generic_alloc_by_type,
1672 .free_by_type = agp_generic_free_by_type,
1673 .agp_alloc_page = agp_generic_alloc_page,
1674 .agp_destroy_page = agp_generic_destroy_page,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001675 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676};
1677
Dave Jonese5524f32007-02-22 18:41:28 -05001678static const struct agp_bridge_driver intel_830_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 .owner = THIS_MODULE,
1680 .aperture_sizes = intel_i830_sizes,
1681 .size_type = FIXED_APER_SIZE,
Dave Jonesc14635e2006-09-06 11:59:35 -04001682 .num_aperture_sizes = 4,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683 .needs_scratch_page = TRUE,
1684 .configure = intel_i830_configure,
1685 .fetch_size = intel_i830_fetch_size,
1686 .cleanup = intel_i830_cleanup,
1687 .tlb_flush = intel_i810_tlbflush,
1688 .mask_memory = intel_i810_mask_memory,
1689 .masks = intel_i810_masks,
1690 .agp_enable = intel_i810_agp_enable,
1691 .cache_flush = global_cache_flush,
1692 .create_gatt_table = intel_i830_create_gatt_table,
1693 .free_gatt_table = intel_i830_free_gatt_table,
1694 .insert_memory = intel_i830_insert_entries,
1695 .remove_memory = intel_i830_remove_entries,
1696 .alloc_by_type = intel_i830_alloc_by_type,
1697 .free_by_type = intel_i810_free_by_type,
1698 .agp_alloc_page = agp_generic_alloc_page,
1699 .agp_destroy_page = agp_generic_destroy_page,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001700 .agp_type_to_mask_type = intel_i830_type_to_mask_type,
Dave Airlie2162e6a2007-11-21 16:36:31 +10001701 .chipset_flush = intel_i830_chipset_flush,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702};
1703
Dave Jonese5524f32007-02-22 18:41:28 -05001704static const struct agp_bridge_driver intel_820_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705 .owner = THIS_MODULE,
1706 .aperture_sizes = intel_8xx_sizes,
1707 .size_type = U8_APER_SIZE,
1708 .num_aperture_sizes = 7,
1709 .configure = intel_820_configure,
1710 .fetch_size = intel_8xx_fetch_size,
1711 .cleanup = intel_820_cleanup,
1712 .tlb_flush = intel_820_tlbflush,
1713 .mask_memory = agp_generic_mask_memory,
1714 .masks = intel_generic_masks,
1715 .agp_enable = agp_generic_enable,
1716 .cache_flush = global_cache_flush,
1717 .create_gatt_table = agp_generic_create_gatt_table,
1718 .free_gatt_table = agp_generic_free_gatt_table,
1719 .insert_memory = agp_generic_insert_memory,
1720 .remove_memory = agp_generic_remove_memory,
1721 .alloc_by_type = agp_generic_alloc_by_type,
1722 .free_by_type = agp_generic_free_by_type,
1723 .agp_alloc_page = agp_generic_alloc_page,
1724 .agp_destroy_page = agp_generic_destroy_page,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001725 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726};
1727
Dave Jonese5524f32007-02-22 18:41:28 -05001728static const struct agp_bridge_driver intel_830mp_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729 .owner = THIS_MODULE,
1730 .aperture_sizes = intel_830mp_sizes,
1731 .size_type = U8_APER_SIZE,
1732 .num_aperture_sizes = 4,
1733 .configure = intel_830mp_configure,
1734 .fetch_size = intel_8xx_fetch_size,
1735 .cleanup = intel_8xx_cleanup,
1736 .tlb_flush = intel_8xx_tlbflush,
1737 .mask_memory = agp_generic_mask_memory,
1738 .masks = intel_generic_masks,
1739 .agp_enable = agp_generic_enable,
1740 .cache_flush = global_cache_flush,
1741 .create_gatt_table = agp_generic_create_gatt_table,
1742 .free_gatt_table = agp_generic_free_gatt_table,
1743 .insert_memory = agp_generic_insert_memory,
1744 .remove_memory = agp_generic_remove_memory,
1745 .alloc_by_type = agp_generic_alloc_by_type,
1746 .free_by_type = agp_generic_free_by_type,
1747 .agp_alloc_page = agp_generic_alloc_page,
1748 .agp_destroy_page = agp_generic_destroy_page,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001749 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750};
1751
Dave Jonese5524f32007-02-22 18:41:28 -05001752static const struct agp_bridge_driver intel_840_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753 .owner = THIS_MODULE,
1754 .aperture_sizes = intel_8xx_sizes,
1755 .size_type = U8_APER_SIZE,
1756 .num_aperture_sizes = 7,
1757 .configure = intel_840_configure,
1758 .fetch_size = intel_8xx_fetch_size,
1759 .cleanup = intel_8xx_cleanup,
1760 .tlb_flush = intel_8xx_tlbflush,
1761 .mask_memory = agp_generic_mask_memory,
1762 .masks = intel_generic_masks,
1763 .agp_enable = agp_generic_enable,
1764 .cache_flush = global_cache_flush,
1765 .create_gatt_table = agp_generic_create_gatt_table,
1766 .free_gatt_table = agp_generic_free_gatt_table,
1767 .insert_memory = agp_generic_insert_memory,
1768 .remove_memory = agp_generic_remove_memory,
1769 .alloc_by_type = agp_generic_alloc_by_type,
1770 .free_by_type = agp_generic_free_by_type,
1771 .agp_alloc_page = agp_generic_alloc_page,
1772 .agp_destroy_page = agp_generic_destroy_page,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001773 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774};
1775
Dave Jonese5524f32007-02-22 18:41:28 -05001776static const struct agp_bridge_driver intel_845_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 .owner = THIS_MODULE,
1778 .aperture_sizes = intel_8xx_sizes,
1779 .size_type = U8_APER_SIZE,
1780 .num_aperture_sizes = 7,
1781 .configure = intel_845_configure,
1782 .fetch_size = intel_8xx_fetch_size,
1783 .cleanup = intel_8xx_cleanup,
1784 .tlb_flush = intel_8xx_tlbflush,
1785 .mask_memory = agp_generic_mask_memory,
1786 .masks = intel_generic_masks,
1787 .agp_enable = agp_generic_enable,
1788 .cache_flush = global_cache_flush,
1789 .create_gatt_table = agp_generic_create_gatt_table,
1790 .free_gatt_table = agp_generic_free_gatt_table,
1791 .insert_memory = agp_generic_insert_memory,
1792 .remove_memory = agp_generic_remove_memory,
1793 .alloc_by_type = agp_generic_alloc_by_type,
1794 .free_by_type = agp_generic_free_by_type,
1795 .agp_alloc_page = agp_generic_alloc_page,
1796 .agp_destroy_page = agp_generic_destroy_page,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001797 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Dave Airlie2162e6a2007-11-21 16:36:31 +10001798 .chipset_flush = intel_i830_chipset_flush,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799};
1800
Dave Jonese5524f32007-02-22 18:41:28 -05001801static const struct agp_bridge_driver intel_850_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802 .owner = THIS_MODULE,
1803 .aperture_sizes = intel_8xx_sizes,
1804 .size_type = U8_APER_SIZE,
1805 .num_aperture_sizes = 7,
1806 .configure = intel_850_configure,
1807 .fetch_size = intel_8xx_fetch_size,
1808 .cleanup = intel_8xx_cleanup,
1809 .tlb_flush = intel_8xx_tlbflush,
1810 .mask_memory = agp_generic_mask_memory,
1811 .masks = intel_generic_masks,
1812 .agp_enable = agp_generic_enable,
1813 .cache_flush = global_cache_flush,
1814 .create_gatt_table = agp_generic_create_gatt_table,
1815 .free_gatt_table = agp_generic_free_gatt_table,
1816 .insert_memory = agp_generic_insert_memory,
1817 .remove_memory = agp_generic_remove_memory,
1818 .alloc_by_type = agp_generic_alloc_by_type,
1819 .free_by_type = agp_generic_free_by_type,
1820 .agp_alloc_page = agp_generic_alloc_page,
1821 .agp_destroy_page = agp_generic_destroy_page,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001822 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823};
1824
Dave Jonese5524f32007-02-22 18:41:28 -05001825static const struct agp_bridge_driver intel_860_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826 .owner = THIS_MODULE,
1827 .aperture_sizes = intel_8xx_sizes,
1828 .size_type = U8_APER_SIZE,
1829 .num_aperture_sizes = 7,
1830 .configure = intel_860_configure,
1831 .fetch_size = intel_8xx_fetch_size,
1832 .cleanup = intel_8xx_cleanup,
1833 .tlb_flush = intel_8xx_tlbflush,
1834 .mask_memory = agp_generic_mask_memory,
1835 .masks = intel_generic_masks,
1836 .agp_enable = agp_generic_enable,
1837 .cache_flush = global_cache_flush,
1838 .create_gatt_table = agp_generic_create_gatt_table,
1839 .free_gatt_table = agp_generic_free_gatt_table,
1840 .insert_memory = agp_generic_insert_memory,
1841 .remove_memory = agp_generic_remove_memory,
1842 .alloc_by_type = agp_generic_alloc_by_type,
1843 .free_by_type = agp_generic_free_by_type,
1844 .agp_alloc_page = agp_generic_alloc_page,
1845 .agp_destroy_page = agp_generic_destroy_page,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001846 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847};
1848
Dave Jonese5524f32007-02-22 18:41:28 -05001849static const struct agp_bridge_driver intel_915_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 .owner = THIS_MODULE,
1851 .aperture_sizes = intel_i830_sizes,
1852 .size_type = FIXED_APER_SIZE,
Dave Jonesc14635e2006-09-06 11:59:35 -04001853 .num_aperture_sizes = 4,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854 .needs_scratch_page = TRUE,
1855 .configure = intel_i915_configure,
Eric Anholtc41e0de2006-12-19 12:57:24 -08001856 .fetch_size = intel_i9xx_fetch_size,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857 .cleanup = intel_i915_cleanup,
1858 .tlb_flush = intel_i810_tlbflush,
1859 .mask_memory = intel_i810_mask_memory,
1860 .masks = intel_i810_masks,
1861 .agp_enable = intel_i810_agp_enable,
1862 .cache_flush = global_cache_flush,
1863 .create_gatt_table = intel_i915_create_gatt_table,
1864 .free_gatt_table = intel_i830_free_gatt_table,
1865 .insert_memory = intel_i915_insert_entries,
1866 .remove_memory = intel_i915_remove_entries,
1867 .alloc_by_type = intel_i830_alloc_by_type,
1868 .free_by_type = intel_i810_free_by_type,
1869 .agp_alloc_page = agp_generic_alloc_page,
1870 .agp_destroy_page = agp_generic_destroy_page,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001871 .agp_type_to_mask_type = intel_i830_type_to_mask_type,
Dave Airlie6c00a612007-10-29 18:06:10 +10001872 .chipset_flush = intel_i915_chipset_flush,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873};
1874
Dave Jonese5524f32007-02-22 18:41:28 -05001875static const struct agp_bridge_driver intel_i965_driver = {
Eric Anholt65c25aa2006-09-06 11:57:18 -04001876 .owner = THIS_MODULE,
1877 .aperture_sizes = intel_i830_sizes,
1878 .size_type = FIXED_APER_SIZE,
1879 .num_aperture_sizes = 4,
1880 .needs_scratch_page = TRUE,
1881 .configure = intel_i915_configure,
Eric Anholtc41e0de2006-12-19 12:57:24 -08001882 .fetch_size = intel_i9xx_fetch_size,
Eric Anholt65c25aa2006-09-06 11:57:18 -04001883 .cleanup = intel_i915_cleanup,
1884 .tlb_flush = intel_i810_tlbflush,
Linus Torvalds7d915a32006-11-22 09:37:54 -08001885 .mask_memory = intel_i965_mask_memory,
Eric Anholt65c25aa2006-09-06 11:57:18 -04001886 .masks = intel_i810_masks,
1887 .agp_enable = intel_i810_agp_enable,
1888 .cache_flush = global_cache_flush,
1889 .create_gatt_table = intel_i965_create_gatt_table,
1890 .free_gatt_table = intel_i830_free_gatt_table,
1891 .insert_memory = intel_i915_insert_entries,
1892 .remove_memory = intel_i915_remove_entries,
1893 .alloc_by_type = intel_i830_alloc_by_type,
1894 .free_by_type = intel_i810_free_by_type,
1895 .agp_alloc_page = agp_generic_alloc_page,
1896 .agp_destroy_page = agp_generic_destroy_page,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001897 .agp_type_to_mask_type = intel_i830_type_to_mask_type,
Dave Airlie6c00a612007-10-29 18:06:10 +10001898 .chipset_flush = intel_i915_chipset_flush,
Eric Anholt65c25aa2006-09-06 11:57:18 -04001899};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900
Dave Jonese5524f32007-02-22 18:41:28 -05001901static const struct agp_bridge_driver intel_7505_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902 .owner = THIS_MODULE,
1903 .aperture_sizes = intel_8xx_sizes,
1904 .size_type = U8_APER_SIZE,
1905 .num_aperture_sizes = 7,
1906 .configure = intel_7505_configure,
1907 .fetch_size = intel_8xx_fetch_size,
1908 .cleanup = intel_8xx_cleanup,
1909 .tlb_flush = intel_8xx_tlbflush,
1910 .mask_memory = agp_generic_mask_memory,
1911 .masks = intel_generic_masks,
1912 .agp_enable = agp_generic_enable,
1913 .cache_flush = global_cache_flush,
1914 .create_gatt_table = agp_generic_create_gatt_table,
1915 .free_gatt_table = agp_generic_free_gatt_table,
1916 .insert_memory = agp_generic_insert_memory,
1917 .remove_memory = agp_generic_remove_memory,
1918 .alloc_by_type = agp_generic_alloc_by_type,
1919 .free_by_type = agp_generic_free_by_type,
1920 .agp_alloc_page = agp_generic_alloc_page,
1921 .agp_destroy_page = agp_generic_destroy_page,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001922 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923};
1924
Wang Zhenyu874808c62007-06-06 11:16:25 +08001925static const struct agp_bridge_driver intel_g33_driver = {
1926 .owner = THIS_MODULE,
1927 .aperture_sizes = intel_i830_sizes,
1928 .size_type = FIXED_APER_SIZE,
1929 .num_aperture_sizes = 4,
1930 .needs_scratch_page = TRUE,
1931 .configure = intel_i915_configure,
1932 .fetch_size = intel_i9xx_fetch_size,
1933 .cleanup = intel_i915_cleanup,
1934 .tlb_flush = intel_i810_tlbflush,
1935 .mask_memory = intel_i965_mask_memory,
1936 .masks = intel_i810_masks,
1937 .agp_enable = intel_i810_agp_enable,
1938 .cache_flush = global_cache_flush,
1939 .create_gatt_table = intel_i915_create_gatt_table,
1940 .free_gatt_table = intel_i830_free_gatt_table,
1941 .insert_memory = intel_i915_insert_entries,
1942 .remove_memory = intel_i915_remove_entries,
1943 .alloc_by_type = intel_i830_alloc_by_type,
1944 .free_by_type = intel_i810_free_by_type,
1945 .agp_alloc_page = agp_generic_alloc_page,
1946 .agp_destroy_page = agp_generic_destroy_page,
1947 .agp_type_to_mask_type = intel_i830_type_to_mask_type,
Dave Airlie6c00a612007-10-29 18:06:10 +10001948 .chipset_flush = intel_i915_chipset_flush,
Wang Zhenyu874808c62007-06-06 11:16:25 +08001949};
Wang Zhenyu9614ece2007-05-30 09:45:58 +08001950
1951static int find_gmch(u16 device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952{
Wang Zhenyu9614ece2007-05-30 09:45:58 +08001953 struct pci_dev *gmch_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954
Wang Zhenyu9614ece2007-05-30 09:45:58 +08001955 gmch_device = pci_get_device(PCI_VENDOR_ID_INTEL, device, NULL);
1956 if (gmch_device && PCI_FUNC(gmch_device->devfn) != 0) {
1957 gmch_device = pci_get_device(PCI_VENDOR_ID_INTEL,
1958 device, gmch_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959 }
1960
Wang Zhenyu9614ece2007-05-30 09:45:58 +08001961 if (!gmch_device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962 return 0;
1963
Wang Zhenyu9614ece2007-05-30 09:45:58 +08001964 intel_private.pcidev = gmch_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965 return 1;
1966}
1967
Wang Zhenyu9614ece2007-05-30 09:45:58 +08001968/* Table to describe Intel GMCH and AGP/PCIE GART drivers. At least one of
1969 * driver and gmch_driver must be non-null, and find_gmch will determine
1970 * which one should be used if a gmch_chip_id is present.
1971 */
1972static const struct intel_driver_description {
1973 unsigned int chip_id;
1974 unsigned int gmch_chip_id;
Wang Zhenyu88889852007-06-14 10:01:04 +08001975 unsigned int multi_gmch_chip; /* if we have more gfx chip type on this HB. */
Wang Zhenyu9614ece2007-05-30 09:45:58 +08001976 char *name;
1977 const struct agp_bridge_driver *driver;
1978 const struct agp_bridge_driver *gmch_driver;
1979} intel_agp_chipsets[] = {
Wang Zhenyu88889852007-06-14 10:01:04 +08001980 { PCI_DEVICE_ID_INTEL_82443LX_0, 0, 0, "440LX", &intel_generic_driver, NULL },
1981 { PCI_DEVICE_ID_INTEL_82443BX_0, 0, 0, "440BX", &intel_generic_driver, NULL },
1982 { PCI_DEVICE_ID_INTEL_82443GX_0, 0, 0, "440GX", &intel_generic_driver, NULL },
1983 { PCI_DEVICE_ID_INTEL_82810_MC1, PCI_DEVICE_ID_INTEL_82810_IG1, 0, "i810",
Wang Zhenyu9614ece2007-05-30 09:45:58 +08001984 NULL, &intel_810_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08001985 { PCI_DEVICE_ID_INTEL_82810_MC3, PCI_DEVICE_ID_INTEL_82810_IG3, 0, "i810",
Wang Zhenyu9614ece2007-05-30 09:45:58 +08001986 NULL, &intel_810_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08001987 { PCI_DEVICE_ID_INTEL_82810E_MC, PCI_DEVICE_ID_INTEL_82810E_IG, 0, "i810",
Wang Zhenyu9614ece2007-05-30 09:45:58 +08001988 NULL, &intel_810_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08001989 { PCI_DEVICE_ID_INTEL_82815_MC, PCI_DEVICE_ID_INTEL_82815_CGC, 0, "i815",
1990 &intel_815_driver, &intel_810_driver },
1991 { PCI_DEVICE_ID_INTEL_82820_HB, 0, 0, "i820", &intel_820_driver, NULL },
1992 { PCI_DEVICE_ID_INTEL_82820_UP_HB, 0, 0, "i820", &intel_820_driver, NULL },
1993 { PCI_DEVICE_ID_INTEL_82830_HB, PCI_DEVICE_ID_INTEL_82830_CGC, 0, "830M",
Wang Zhenyu9614ece2007-05-30 09:45:58 +08001994 &intel_830mp_driver, &intel_830_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08001995 { PCI_DEVICE_ID_INTEL_82840_HB, 0, 0, "i840", &intel_840_driver, NULL },
1996 { PCI_DEVICE_ID_INTEL_82845_HB, 0, 0, "845G", &intel_845_driver, NULL },
1997 { PCI_DEVICE_ID_INTEL_82845G_HB, PCI_DEVICE_ID_INTEL_82845G_IG, 0, "830M",
Wang Zhenyu9614ece2007-05-30 09:45:58 +08001998 &intel_845_driver, &intel_830_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08001999 { PCI_DEVICE_ID_INTEL_82850_HB, 0, 0, "i850", &intel_850_driver, NULL },
2000 { PCI_DEVICE_ID_INTEL_82855PM_HB, 0, 0, "855PM", &intel_845_driver, NULL },
2001 { PCI_DEVICE_ID_INTEL_82855GM_HB, PCI_DEVICE_ID_INTEL_82855GM_IG, 0, "855GM",
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002002 &intel_845_driver, &intel_830_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002003 { PCI_DEVICE_ID_INTEL_82860_HB, 0, 0, "i860", &intel_860_driver, NULL },
2004 { PCI_DEVICE_ID_INTEL_82865_HB, PCI_DEVICE_ID_INTEL_82865_IG, 0, "865",
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002005 &intel_845_driver, &intel_830_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002006 { PCI_DEVICE_ID_INTEL_82875_HB, 0, 0, "i875", &intel_845_driver, NULL },
Carlos Martíne914a362008-01-24 10:34:09 +10002007 { PCI_DEVICE_ID_INTEL_E7221_HB, PCI_DEVICE_ID_INTEL_E7221_IG, 0, "E7221 (i915)",
2008 NULL, &intel_915_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002009 { PCI_DEVICE_ID_INTEL_82915G_HB, PCI_DEVICE_ID_INTEL_82915G_IG, 0, "915G",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002010 NULL, &intel_915_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002011 { PCI_DEVICE_ID_INTEL_82915GM_HB, PCI_DEVICE_ID_INTEL_82915GM_IG, 0, "915GM",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002012 NULL, &intel_915_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002013 { PCI_DEVICE_ID_INTEL_82945G_HB, PCI_DEVICE_ID_INTEL_82945G_IG, 0, "945G",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002014 NULL, &intel_915_driver },
Zhenyu Wangdde47872007-07-26 09:18:09 +08002015 { PCI_DEVICE_ID_INTEL_82945GM_HB, PCI_DEVICE_ID_INTEL_82945GM_IG, 0, "945GM",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002016 NULL, &intel_915_driver },
Zhenyu Wangdde47872007-07-26 09:18:09 +08002017 { PCI_DEVICE_ID_INTEL_82945GME_HB, PCI_DEVICE_ID_INTEL_82945GME_IG, 0, "945GME",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002018 NULL, &intel_915_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002019 { PCI_DEVICE_ID_INTEL_82946GZ_HB, PCI_DEVICE_ID_INTEL_82946GZ_IG, 0, "946GZ",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002020 NULL, &intel_i965_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002021 { PCI_DEVICE_ID_INTEL_82965G_1_HB, PCI_DEVICE_ID_INTEL_82965G_1_IG, 0, "965G",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002022 NULL, &intel_i965_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002023 { PCI_DEVICE_ID_INTEL_82965Q_HB, PCI_DEVICE_ID_INTEL_82965Q_IG, 0, "965Q",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002024 NULL, &intel_i965_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002025 { PCI_DEVICE_ID_INTEL_82965G_HB, PCI_DEVICE_ID_INTEL_82965G_IG, 0, "965G",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002026 NULL, &intel_i965_driver },
Zhenyu Wangdde47872007-07-26 09:18:09 +08002027 { PCI_DEVICE_ID_INTEL_82965GM_HB, PCI_DEVICE_ID_INTEL_82965GM_IG, 0, "965GM",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002028 NULL, &intel_i965_driver },
Zhenyu Wangdde47872007-07-26 09:18:09 +08002029 { PCI_DEVICE_ID_INTEL_82965GME_HB, PCI_DEVICE_ID_INTEL_82965GME_IG, 0, "965GME/GLE",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002030 NULL, &intel_i965_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002031 { PCI_DEVICE_ID_INTEL_7505_0, 0, 0, "E7505", &intel_7505_driver, NULL },
2032 { PCI_DEVICE_ID_INTEL_7205_0, 0, 0, "E7205", &intel_7505_driver, NULL },
2033 { PCI_DEVICE_ID_INTEL_G33_HB, PCI_DEVICE_ID_INTEL_G33_IG, 0, "G33",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002034 NULL, &intel_g33_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002035 { PCI_DEVICE_ID_INTEL_Q35_HB, PCI_DEVICE_ID_INTEL_Q35_IG, 0, "Q35",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002036 NULL, &intel_g33_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002037 { PCI_DEVICE_ID_INTEL_Q33_HB, PCI_DEVICE_ID_INTEL_Q33_IG, 0, "Q33",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002038 NULL, &intel_g33_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002039 { 0, 0, 0, NULL, NULL, NULL }
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002040};
2041
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042static int __devinit agp_intel_probe(struct pci_dev *pdev,
2043 const struct pci_device_id *ent)
2044{
2045 struct agp_bridge_data *bridge;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046 u8 cap_ptr = 0;
2047 struct resource *r;
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002048 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049
2050 cap_ptr = pci_find_capability(pdev, PCI_CAP_ID_AGP);
2051
2052 bridge = agp_alloc_bridge();
2053 if (!bridge)
2054 return -ENOMEM;
2055
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002056 for (i = 0; intel_agp_chipsets[i].name != NULL; i++) {
2057 /* In case that multiple models of gfx chip may
2058 stand on same host bridge type, this can be
2059 sure we detect the right IGD. */
Wang Zhenyu88889852007-06-14 10:01:04 +08002060 if (pdev->device == intel_agp_chipsets[i].chip_id) {
2061 if ((intel_agp_chipsets[i].gmch_chip_id != 0) &&
2062 find_gmch(intel_agp_chipsets[i].gmch_chip_id)) {
2063 bridge->driver =
2064 intel_agp_chipsets[i].gmch_driver;
2065 break;
2066 } else if (intel_agp_chipsets[i].multi_gmch_chip) {
2067 continue;
2068 } else {
2069 bridge->driver = intel_agp_chipsets[i].driver;
2070 break;
2071 }
2072 }
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002073 }
2074
2075 if (intel_agp_chipsets[i].name == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076 if (cap_ptr)
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002077 printk(KERN_WARNING PFX "Unsupported Intel chipset"
2078 "(device id: %04x)\n", pdev->device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 agp_put_bridge(bridge);
2080 return -ENODEV;
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002081 }
2082
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002083 if (bridge->driver == NULL) {
Wang Zhenyu47d46372007-06-21 13:43:18 +08002084 /* bridge has no AGP and no IGD detected */
2085 if (cap_ptr)
2086 printk(KERN_WARNING PFX "Failed to find bridge device "
2087 "(chip_id: %04x)\n",
2088 intel_agp_chipsets[i].gmch_chip_id);
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002089 agp_put_bridge(bridge);
2090 return -ENODEV;
2091 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092
2093 bridge->dev = pdev;
2094 bridge->capndx = cap_ptr;
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08002095 bridge->dev_private_data = &intel_private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002097 printk(KERN_INFO PFX "Detected an Intel %s Chipset.\n",
2098 intel_agp_chipsets[i].name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099
2100 /*
2101 * The following fixes the case where the BIOS has "forgotten" to
2102 * provide an address range for the GART.
2103 * 20030610 - hamish@zot.org
2104 */
2105 r = &pdev->resource[0];
2106 if (!r->start && r->end) {
Dave Jones6a92a4e2006-02-28 00:54:25 -05002107 if (pci_assign_resource(pdev, 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108 printk(KERN_ERR PFX "could not assign resource 0\n");
2109 agp_put_bridge(bridge);
2110 return -ENODEV;
2111 }
2112 }
2113
2114 /*
2115 * If the device has not been properly setup, the following will catch
2116 * the problem and should stop the system from crashing.
2117 * 20030610 - hamish@zot.org
2118 */
2119 if (pci_enable_device(pdev)) {
2120 printk(KERN_ERR PFX "Unable to Enable PCI device\n");
2121 agp_put_bridge(bridge);
2122 return -ENODEV;
2123 }
2124
2125 /* Fill in the mode register */
2126 if (cap_ptr) {
2127 pci_read_config_dword(pdev,
2128 bridge->capndx+PCI_AGP_STATUS,
2129 &bridge->mode);
2130 }
2131
2132 pci_set_drvdata(pdev, bridge);
2133 return agp_add_bridge(bridge);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134}
2135
2136static void __devexit agp_intel_remove(struct pci_dev *pdev)
2137{
2138 struct agp_bridge_data *bridge = pci_get_drvdata(pdev);
2139
2140 agp_remove_bridge(bridge);
2141
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08002142 if (intel_private.pcidev)
2143 pci_dev_put(intel_private.pcidev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144
2145 agp_put_bridge(bridge);
2146}
2147
Alexey Dobriyan85be7d62006-08-12 02:02:02 +04002148#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149static int agp_intel_resume(struct pci_dev *pdev)
2150{
2151 struct agp_bridge_data *bridge = pci_get_drvdata(pdev);
2152
2153 pci_restore_state(pdev);
2154
Wang Zhenyu4b953202007-01-17 11:07:54 +08002155 /* We should restore our graphics device's config space,
2156 * as host bridge (00:00) resumes before graphics device (02:00),
2157 * then our access to its pci space can work right.
2158 */
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08002159 if (intel_private.pcidev)
2160 pci_restore_state(intel_private.pcidev);
Wang Zhenyu4b953202007-01-17 11:07:54 +08002161
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162 if (bridge->driver == &intel_generic_driver)
2163 intel_configure();
2164 else if (bridge->driver == &intel_850_driver)
2165 intel_850_configure();
2166 else if (bridge->driver == &intel_845_driver)
2167 intel_845_configure();
2168 else if (bridge->driver == &intel_830mp_driver)
2169 intel_830mp_configure();
2170 else if (bridge->driver == &intel_915_driver)
2171 intel_i915_configure();
2172 else if (bridge->driver == &intel_830_driver)
2173 intel_i830_configure();
2174 else if (bridge->driver == &intel_810_driver)
2175 intel_i810_configure();
Dave Jones08da3f42006-09-10 21:09:26 -04002176 else if (bridge->driver == &intel_i965_driver)
2177 intel_i915_configure();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178
2179 return 0;
2180}
Alexey Dobriyan85be7d62006-08-12 02:02:02 +04002181#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182
2183static struct pci_device_id agp_intel_pci_table[] = {
2184#define ID(x) \
2185 { \
2186 .class = (PCI_CLASS_BRIDGE_HOST << 8), \
2187 .class_mask = ~0, \
2188 .vendor = PCI_VENDOR_ID_INTEL, \
2189 .device = x, \
2190 .subvendor = PCI_ANY_ID, \
2191 .subdevice = PCI_ANY_ID, \
2192 }
2193 ID(PCI_DEVICE_ID_INTEL_82443LX_0),
2194 ID(PCI_DEVICE_ID_INTEL_82443BX_0),
2195 ID(PCI_DEVICE_ID_INTEL_82443GX_0),
2196 ID(PCI_DEVICE_ID_INTEL_82810_MC1),
2197 ID(PCI_DEVICE_ID_INTEL_82810_MC3),
2198 ID(PCI_DEVICE_ID_INTEL_82810E_MC),
2199 ID(PCI_DEVICE_ID_INTEL_82815_MC),
2200 ID(PCI_DEVICE_ID_INTEL_82820_HB),
2201 ID(PCI_DEVICE_ID_INTEL_82820_UP_HB),
2202 ID(PCI_DEVICE_ID_INTEL_82830_HB),
2203 ID(PCI_DEVICE_ID_INTEL_82840_HB),
2204 ID(PCI_DEVICE_ID_INTEL_82845_HB),
2205 ID(PCI_DEVICE_ID_INTEL_82845G_HB),
2206 ID(PCI_DEVICE_ID_INTEL_82850_HB),
2207 ID(PCI_DEVICE_ID_INTEL_82855PM_HB),
2208 ID(PCI_DEVICE_ID_INTEL_82855GM_HB),
2209 ID(PCI_DEVICE_ID_INTEL_82860_HB),
2210 ID(PCI_DEVICE_ID_INTEL_82865_HB),
2211 ID(PCI_DEVICE_ID_INTEL_82875_HB),
2212 ID(PCI_DEVICE_ID_INTEL_7505_0),
2213 ID(PCI_DEVICE_ID_INTEL_7205_0),
Carlos Martíne914a362008-01-24 10:34:09 +10002214 ID(PCI_DEVICE_ID_INTEL_E7221_HB),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215 ID(PCI_DEVICE_ID_INTEL_82915G_HB),
2216 ID(PCI_DEVICE_ID_INTEL_82915GM_HB),
Alan Hourihaned0de98f2005-05-31 19:50:49 +01002217 ID(PCI_DEVICE_ID_INTEL_82945G_HB),
Alan Hourihane3b0e8ea2006-01-19 14:08:40 +00002218 ID(PCI_DEVICE_ID_INTEL_82945GM_HB),
Zhenyu Wangdde47872007-07-26 09:18:09 +08002219 ID(PCI_DEVICE_ID_INTEL_82945GME_HB),
Eric Anholt65c25aa2006-09-06 11:57:18 -04002220 ID(PCI_DEVICE_ID_INTEL_82946GZ_HB),
2221 ID(PCI_DEVICE_ID_INTEL_82965G_1_HB),
2222 ID(PCI_DEVICE_ID_INTEL_82965Q_HB),
2223 ID(PCI_DEVICE_ID_INTEL_82965G_HB),
Wang Zhenyu4598af32007-04-09 08:51:36 +08002224 ID(PCI_DEVICE_ID_INTEL_82965GM_HB),
Zhenyu Wangdde47872007-07-26 09:18:09 +08002225 ID(PCI_DEVICE_ID_INTEL_82965GME_HB),
Wang Zhenyu874808c62007-06-06 11:16:25 +08002226 ID(PCI_DEVICE_ID_INTEL_G33_HB),
2227 ID(PCI_DEVICE_ID_INTEL_Q35_HB),
2228 ID(PCI_DEVICE_ID_INTEL_Q33_HB),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229 { }
2230};
2231
2232MODULE_DEVICE_TABLE(pci, agp_intel_pci_table);
2233
2234static struct pci_driver agp_intel_pci_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235 .name = "agpgart-intel",
2236 .id_table = agp_intel_pci_table,
2237 .probe = agp_intel_probe,
2238 .remove = __devexit_p(agp_intel_remove),
Alexey Dobriyan85be7d62006-08-12 02:02:02 +04002239#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 .resume = agp_intel_resume,
Alexey Dobriyan85be7d62006-08-12 02:02:02 +04002241#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242};
2243
2244static int __init agp_intel_init(void)
2245{
2246 if (agp_off)
2247 return -EINVAL;
2248 return pci_register_driver(&agp_intel_pci_driver);
2249}
2250
2251static void __exit agp_intel_cleanup(void)
2252{
2253 pci_unregister_driver(&agp_intel_pci_driver);
2254}
2255
2256module_init(agp_intel_init);
2257module_exit(agp_intel_cleanup);
2258
2259MODULE_AUTHOR("Dave Jones <davej@codemonkey.org.uk>");
2260MODULE_LICENSE("GPL and additional rights");