blob: 290a1cf6392580b1e7dfcdbb71ff35e742cd2726 [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
Zhenyu Wang9119f852008-01-23 15:49:26 +100017#define PCI_DEVICE_ID_INTEL_82G35_HB 0x2980
18#define PCI_DEVICE_ID_INTEL_82G35_IG 0x2982
Eric Anholt65c25aa2006-09-06 11:57:18 -040019#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
Zhenyu Wang4e8b6e22008-01-23 14:54:37 +100035#define PCI_DEVICE_ID_INTEL_IGD_HB 0x2A40
36#define PCI_DEVICE_ID_INTEL_IGD_IG 0x2A42
Zhenyu Wang25ce77a2008-06-19 14:17:58 +100037#define PCI_DEVICE_ID_INTEL_IGD_E_HB 0x2E00
38#define PCI_DEVICE_ID_INTEL_IGD_E_IG 0x2E02
39#define PCI_DEVICE_ID_INTEL_Q45_HB 0x2E10
40#define PCI_DEVICE_ID_INTEL_Q45_IG 0x2E12
41#define PCI_DEVICE_ID_INTEL_G45_HB 0x2E20
42#define PCI_DEVICE_ID_INTEL_G45_IG 0x2E22
Eric Anholt65c25aa2006-09-06 11:57:18 -040043
Dave Airlief011ae72008-01-25 11:23:04 +100044/* cover 915 and 945 variants */
45#define IS_I915 (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_E7221_HB || \
46 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82915G_HB || \
47 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82915GM_HB || \
48 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82945G_HB || \
49 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82945GM_HB || \
50 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82945GME_HB)
51
Eric Anholt65c25aa2006-09-06 11:57:18 -040052#define IS_I965 (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82946GZ_HB || \
Dave Airlief011ae72008-01-25 11:23:04 +100053 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82G35_HB || \
54 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965Q_HB || \
55 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965G_HB || \
56 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965GM_HB || \
Zhenyu Wang4e8b6e22008-01-23 14:54:37 +100057 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965GME_HB || \
58 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IGD_HB)
Eric Anholt65c25aa2006-09-06 11:57:18 -040059
Wang Zhenyu874808c62007-06-06 11:16:25 +080060#define IS_G33 (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_G33_HB || \
61 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_Q35_HB || \
62 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_Q33_HB)
Eric Anholt65c25aa2006-09-06 11:57:18 -040063
Zhenyu Wang25ce77a2008-06-19 14:17:58 +100064#define IS_G4X (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IGD_E_HB || \
65 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_Q45_HB || \
66 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_G45_HB)
67
Thomas Hellstroma030ce42007-01-23 10:33:43 +010068extern int agp_memory_reserved;
69
70
Linus Torvalds1da177e2005-04-16 15:20:36 -070071/* Intel 815 register */
72#define INTEL_815_APCONT 0x51
73#define INTEL_815_ATTBASE_MASK ~0x1FFFFFFF
74
75/* Intel i820 registers */
76#define INTEL_I820_RDCR 0x51
77#define INTEL_I820_ERRSTS 0xc8
78
79/* Intel i840 registers */
80#define INTEL_I840_MCHCFG 0x50
81#define INTEL_I840_ERRSTS 0xc8
82
83/* Intel i850 registers */
84#define INTEL_I850_MCHCFG 0x50
85#define INTEL_I850_ERRSTS 0xc8
86
87/* intel 915G registers */
88#define I915_GMADDR 0x18
89#define I915_MMADDR 0x10
90#define I915_PTEADDR 0x1C
91#define I915_GMCH_GMS_STOLEN_48M (0x6 << 4)
92#define I915_GMCH_GMS_STOLEN_64M (0x7 << 4)
Zhenyu Wang25ce77a2008-06-19 14:17:58 +100093#define G33_GMCH_GMS_STOLEN_128M (0x8 << 4)
94#define G33_GMCH_GMS_STOLEN_256M (0x9 << 4)
95#define INTEL_GMCH_GMS_STOLEN_96M (0xa << 4)
96#define INTEL_GMCH_GMS_STOLEN_160M (0xb << 4)
97#define INTEL_GMCH_GMS_STOLEN_224M (0xc << 4)
98#define INTEL_GMCH_GMS_STOLEN_352M (0xd << 4)
99
Dave Airlie6c00a612007-10-29 18:06:10 +1000100#define I915_IFPADDR 0x60
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Eric Anholt65c25aa2006-09-06 11:57:18 -0400102/* Intel 965G registers */
103#define I965_MSAC 0x62
Dave Airlie6c00a612007-10-29 18:06:10 +1000104#define I965_IFPADDR 0x70
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
106/* Intel 7505 registers */
107#define INTEL_I7505_APSIZE 0x74
108#define INTEL_I7505_NCAPID 0x60
109#define INTEL_I7505_NISTAT 0x6c
110#define INTEL_I7505_ATTBASE 0x78
111#define INTEL_I7505_ERRSTS 0x42
112#define INTEL_I7505_AGPCTRL 0x70
113#define INTEL_I7505_MCHCFG 0x50
114
Dave Jonese5524f32007-02-22 18:41:28 -0500115static const struct aper_size_info_fixed intel_i810_sizes[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116{
117 {64, 16384, 4},
118 /* The 32M mode still requires a 64k gatt */
119 {32, 8192, 4}
120};
121
122#define AGP_DCACHE_MEMORY 1
123#define AGP_PHYS_MEMORY 2
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100124#define INTEL_AGP_CACHED_MEMORY 3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
126static struct gatt_mask intel_i810_masks[] =
127{
128 {.mask = I810_PTE_VALID, .type = 0},
129 {.mask = (I810_PTE_VALID | I810_PTE_LOCAL), .type = AGP_DCACHE_MEMORY},
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100130 {.mask = I810_PTE_VALID, .type = 0},
131 {.mask = I810_PTE_VALID | I830_PTE_SYSTEM_CACHED,
132 .type = INTEL_AGP_CACHED_MEMORY}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133};
134
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800135static struct _intel_private {
136 struct pci_dev *pcidev; /* device one */
137 u8 __iomem *registers;
138 u32 __iomem *gtt; /* I915G */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 int num_dcache_entries;
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800140 /* gtt_entries is the number of gtt entries that are already mapped
141 * to stolen memory. Stolen memory is larger than the memory mapped
142 * through gtt_entries, as it includes some reserved space for the BIOS
143 * popup and for the GTT.
144 */
145 int gtt_entries; /* i830+ */
Dave Airlie2162e6a2007-11-21 16:36:31 +1000146 union {
147 void __iomem *i9xx_flush_page;
148 void *i8xx_flush_page;
149 };
150 struct page *i8xx_page;
Dave Airlie6c00a612007-10-29 18:06:10 +1000151 struct resource ifp_resource;
Dave Airlie4d64dd92008-01-23 15:34:29 +1000152 int resource_valid;
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800153} intel_private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
155static int intel_i810_fetch_size(void)
156{
157 u32 smram_miscc;
158 struct aper_size_info_fixed *values;
159
160 pci_read_config_dword(agp_bridge->dev, I810_SMRAM_MISCC, &smram_miscc);
161 values = A_SIZE_FIX(agp_bridge->driver->aperture_sizes);
162
163 if ((smram_miscc & I810_GMS) == I810_GMS_DISABLE) {
164 printk(KERN_WARNING PFX "i810 is disabled\n");
165 return 0;
166 }
167 if ((smram_miscc & I810_GFX_MEM_WIN_SIZE) == I810_GFX_MEM_WIN_32M) {
168 agp_bridge->previous_size =
169 agp_bridge->current_size = (void *) (values + 1);
170 agp_bridge->aperture_size_idx = 1;
171 return values[1].size;
172 } else {
173 agp_bridge->previous_size =
174 agp_bridge->current_size = (void *) (values);
175 agp_bridge->aperture_size_idx = 0;
176 return values[0].size;
177 }
178
179 return 0;
180}
181
182static int intel_i810_configure(void)
183{
184 struct aper_size_info_fixed *current_size;
185 u32 temp;
186 int i;
187
188 current_size = A_SIZE_FIX(agp_bridge->current_size);
189
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800190 if (!intel_private.registers) {
191 pci_read_config_dword(intel_private.pcidev, I810_MMADDR, &temp);
Dave Jonese4ac5e42007-02-04 17:37:42 -0500192 temp &= 0xfff80000;
193
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800194 intel_private.registers = ioremap(temp, 128 * 4096);
195 if (!intel_private.registers) {
Dave Jonese4ac5e42007-02-04 17:37:42 -0500196 printk(KERN_ERR PFX "Unable to remap memory.\n");
197 return -ENOMEM;
198 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 }
200
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800201 if ((readl(intel_private.registers+I810_DRAM_CTL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 & I810_DRAM_ROW_0) == I810_DRAM_ROW_0_SDRAM) {
203 /* This will need to be dynamically assigned */
204 printk(KERN_INFO PFX "detected 4MB dedicated video ram.\n");
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800205 intel_private.num_dcache_entries = 1024;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 }
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800207 pci_read_config_dword(intel_private.pcidev, I810_GMADDR, &temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800209 writel(agp_bridge->gatt_bus_addr | I810_PGETBL_ENABLED, intel_private.registers+I810_PGETBL_CTL);
210 readl(intel_private.registers+I810_PGETBL_CTL); /* PCI Posting. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
212 if (agp_bridge->driver->needs_scratch_page) {
213 for (i = 0; i < current_size->num_entries; i++) {
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800214 writel(agp_bridge->scratch_page, intel_private.registers+I810_PTE_BASE+(i*4));
215 readl(intel_private.registers+I810_PTE_BASE+(i*4)); /* PCI posting. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 }
217 }
218 global_cache_flush();
219 return 0;
220}
221
222static void intel_i810_cleanup(void)
223{
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800224 writel(0, intel_private.registers+I810_PGETBL_CTL);
225 readl(intel_private.registers); /* PCI Posting. */
226 iounmap(intel_private.registers);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227}
228
229static void intel_i810_tlbflush(struct agp_memory *mem)
230{
231 return;
232}
233
234static void intel_i810_agp_enable(struct agp_bridge_data *bridge, u32 mode)
235{
236 return;
237}
238
239/* Exists to support ARGB cursors */
240static void *i8xx_alloc_pages(void)
241{
Dave Airlief011ae72008-01-25 11:23:04 +1000242 struct page *page;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
Linus Torvalds66c669b2006-11-22 14:55:29 -0800244 page = alloc_pages(GFP_KERNEL | GFP_DMA32, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 if (page == NULL)
246 return NULL;
247
Arjan van de Ven6d238cc2008-01-30 13:34:06 +0100248 if (set_pages_uc(page, 4) < 0) {
249 set_pages_wb(page, 4);
Jan Beulich89cf7cc2007-04-02 14:50:14 +0100250 __free_pages(page, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 return NULL;
252 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 get_page(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 atomic_inc(&agp_bridge->current_memory_agp);
255 return page_address(page);
256}
257
258static void i8xx_destroy_pages(void *addr)
259{
260 struct page *page;
261
262 if (addr == NULL)
263 return;
264
265 page = virt_to_page(addr);
Arjan van de Ven6d238cc2008-01-30 13:34:06 +0100266 set_pages_wb(page, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 put_page(page);
Jan Beulich89cf7cc2007-04-02 14:50:14 +0100268 __free_pages(page, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 atomic_dec(&agp_bridge->current_memory_agp);
270}
271
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100272static int intel_i830_type_to_mask_type(struct agp_bridge_data *bridge,
273 int type)
274{
275 if (type < AGP_USER_TYPES)
276 return type;
277 else if (type == AGP_USER_CACHED_MEMORY)
278 return INTEL_AGP_CACHED_MEMORY;
279 else
280 return 0;
281}
282
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283static int intel_i810_insert_entries(struct agp_memory *mem, off_t pg_start,
284 int type)
285{
286 int i, j, num_entries;
287 void *temp;
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100288 int ret = -EINVAL;
289 int mask_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +0100291 if (mem->page_count == 0)
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100292 goto out;
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +0100293
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 temp = agp_bridge->current_size;
295 num_entries = A_SIZE_FIX(temp)->num_entries;
296
Dave Jones6a92a4e2006-02-28 00:54:25 -0500297 if ((pg_start + mem->page_count) > num_entries)
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100298 goto out_err;
299
Dave Jones6a92a4e2006-02-28 00:54:25 -0500300
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 for (j = pg_start; j < (pg_start + mem->page_count); j++) {
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100302 if (!PGE_EMPTY(agp_bridge, readl(agp_bridge->gatt_table+j))) {
303 ret = -EBUSY;
304 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 }
307
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100308 if (type != mem->type)
309 goto out_err;
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +0100310
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100311 mask_type = agp_bridge->driver->agp_type_to_mask_type(agp_bridge, type);
312
313 switch (mask_type) {
314 case AGP_DCACHE_MEMORY:
315 if (!mem->is_flushed)
316 global_cache_flush();
317 for (i = pg_start; i < (pg_start + mem->page_count); i++) {
318 writel((i*4096)|I810_PTE_LOCAL|I810_PTE_VALID,
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800319 intel_private.registers+I810_PTE_BASE+(i*4));
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100320 }
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800321 readl(intel_private.registers+I810_PTE_BASE+((i-1)*4));
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100322 break;
323 case AGP_PHYS_MEMORY:
324 case AGP_NORMAL_MEMORY:
325 if (!mem->is_flushed)
326 global_cache_flush();
327 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
328 writel(agp_bridge->driver->mask_memory(agp_bridge,
329 mem->memory[i],
330 mask_type),
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800331 intel_private.registers+I810_PTE_BASE+(j*4));
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100332 }
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800333 readl(intel_private.registers+I810_PTE_BASE+((j-1)*4));
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100334 break;
335 default:
336 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
339 agp_bridge->driver->tlb_flush(mem);
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100340out:
341 ret = 0;
342out_err:
Dave Airlie9516b032008-06-19 10:42:17 +1000343 mem->is_flushed = true;
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100344 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345}
346
347static int intel_i810_remove_entries(struct agp_memory *mem, off_t pg_start,
348 int type)
349{
350 int i;
351
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +0100352 if (mem->page_count == 0)
353 return 0;
354
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 for (i = pg_start; i < (mem->page_count + pg_start); i++) {
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800356 writel(agp_bridge->scratch_page, intel_private.registers+I810_PTE_BASE+(i*4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 }
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800358 readl(intel_private.registers+I810_PTE_BASE+((i-1)*4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 agp_bridge->driver->tlb_flush(mem);
361 return 0;
362}
363
364/*
365 * The i810/i830 requires a physical address to program its mouse
366 * pointer into hardware.
367 * However the Xserver still writes to it through the agp aperture.
368 */
369static struct agp_memory *alloc_agpphysmem_i8xx(size_t pg_count, int type)
370{
371 struct agp_memory *new;
372 void *addr;
373
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 switch (pg_count) {
375 case 1: addr = agp_bridge->driver->agp_alloc_page(agp_bridge);
376 break;
377 case 4:
378 /* kludge to get 4 physical pages for ARGB cursor */
379 addr = i8xx_alloc_pages();
380 break;
381 default:
382 return NULL;
383 }
384
385 if (addr == NULL)
386 return NULL;
387
388 new = agp_create_memory(pg_count);
389 if (new == NULL)
390 return NULL;
391
Keir Fraser07eee782005-03-30 13:17:04 -0800392 new->memory[0] = virt_to_gart(addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 if (pg_count == 4) {
394 /* kludge to get 4 physical pages for ARGB cursor */
395 new->memory[1] = new->memory[0] + PAGE_SIZE;
396 new->memory[2] = new->memory[1] + PAGE_SIZE;
397 new->memory[3] = new->memory[2] + PAGE_SIZE;
398 }
399 new->page_count = pg_count;
400 new->num_scratch_pages = pg_count;
401 new->type = AGP_PHYS_MEMORY;
402 new->physical = new->memory[0];
403 return new;
404}
405
406static struct agp_memory *intel_i810_alloc_by_type(size_t pg_count, int type)
407{
408 struct agp_memory *new;
409
410 if (type == AGP_DCACHE_MEMORY) {
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800411 if (pg_count != intel_private.num_dcache_entries)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 return NULL;
413
414 new = agp_create_memory(1);
415 if (new == NULL)
416 return NULL;
417
418 new->type = AGP_DCACHE_MEMORY;
419 new->page_count = pg_count;
420 new->num_scratch_pages = 0;
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100421 agp_free_page_array(new);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 return new;
423 }
424 if (type == AGP_PHYS_MEMORY)
425 return alloc_agpphysmem_i8xx(pg_count, type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 return NULL;
427}
428
429static void intel_i810_free_by_type(struct agp_memory *curr)
430{
431 agp_free_key(curr->key);
Dave Jones6a92a4e2006-02-28 00:54:25 -0500432 if (curr->type == AGP_PHYS_MEMORY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 if (curr->page_count == 4)
Keir Fraser07eee782005-03-30 13:17:04 -0800434 i8xx_destroy_pages(gart_to_virt(curr->memory[0]));
Alan Hourihane88d51962005-11-06 23:35:34 -0800435 else {
Jan Beulichda503fa2008-06-18 09:28:00 +0100436 void *va = gart_to_virt(curr->memory[0]);
437
438 agp_bridge->driver->agp_destroy_page(va,
Dave Airliea2721e92007-10-15 10:19:16 +1000439 AGP_PAGE_DESTROY_UNMAP);
Jan Beulichda503fa2008-06-18 09:28:00 +0100440 agp_bridge->driver->agp_destroy_page(va,
Dave Airliea2721e92007-10-15 10:19:16 +1000441 AGP_PAGE_DESTROY_FREE);
Alan Hourihane88d51962005-11-06 23:35:34 -0800442 }
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100443 agp_free_page_array(curr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 }
445 kfree(curr);
446}
447
448static unsigned long intel_i810_mask_memory(struct agp_bridge_data *bridge,
449 unsigned long addr, int type)
450{
451 /* Type checking must be done elsewhere */
452 return addr | bridge->driver->masks[type].mask;
453}
454
455static struct aper_size_info_fixed intel_i830_sizes[] =
456{
457 {128, 32768, 5},
458 /* The 64M mode still requires a 128k gatt */
459 {64, 16384, 5},
460 {256, 65536, 6},
Eric Anholt65c25aa2006-09-06 11:57:18 -0400461 {512, 131072, 7},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462};
463
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464static void intel_i830_init_gtt_entries(void)
465{
466 u16 gmch_ctrl;
467 int gtt_entries;
468 u8 rdct;
469 int local = 0;
470 static const int ddt[4] = { 0, 16, 32, 64 };
Eric Anholtc41e0de2006-12-19 12:57:24 -0800471 int size; /* reserved space (in kb) at the top of stolen memory */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472
Dave Airlief011ae72008-01-25 11:23:04 +1000473 pci_read_config_word(agp_bridge->dev, I830_GMCH_CTRL, &gmch_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474
Eric Anholtc41e0de2006-12-19 12:57:24 -0800475 if (IS_I965) {
476 u32 pgetbl_ctl;
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800477 pgetbl_ctl = readl(intel_private.registers+I810_PGETBL_CTL);
Eric Anholtc41e0de2006-12-19 12:57:24 -0800478
Eric Anholtc41e0de2006-12-19 12:57:24 -0800479 /* The 965 has a field telling us the size of the GTT,
480 * which may be larger than what is necessary to map the
481 * aperture.
482 */
483 switch (pgetbl_ctl & I965_PGETBL_SIZE_MASK) {
484 case I965_PGETBL_SIZE_128KB:
485 size = 128;
486 break;
487 case I965_PGETBL_SIZE_256KB:
488 size = 256;
489 break;
490 case I965_PGETBL_SIZE_512KB:
491 size = 512;
492 break;
Zhenyu Wang4e8b6e22008-01-23 14:54:37 +1000493 case I965_PGETBL_SIZE_1MB:
494 size = 1024;
495 break;
496 case I965_PGETBL_SIZE_2MB:
497 size = 2048;
498 break;
499 case I965_PGETBL_SIZE_1_5MB:
500 size = 1024 + 512;
501 break;
Eric Anholtc41e0de2006-12-19 12:57:24 -0800502 default:
503 printk(KERN_INFO PFX "Unknown page table size, "
504 "assuming 512KB\n");
505 size = 512;
506 }
507 size += 4; /* add in BIOS popup space */
Wang Zhenyu874808c62007-06-06 11:16:25 +0800508 } else if (IS_G33) {
509 /* G33's GTT size defined in gmch_ctrl */
510 switch (gmch_ctrl & G33_PGETBL_SIZE_MASK) {
511 case G33_PGETBL_SIZE_1M:
512 size = 1024;
513 break;
514 case G33_PGETBL_SIZE_2M:
515 size = 2048;
516 break;
517 default:
518 printk(KERN_INFO PFX "Unknown page table size 0x%x, "
519 "assuming 512KB\n",
520 (gmch_ctrl & G33_PGETBL_SIZE_MASK));
521 size = 512;
522 }
523 size += 4;
Zhenyu Wang25ce77a2008-06-19 14:17:58 +1000524 } else if (IS_G4X) {
525 /* On 4 series hardware, GTT stolen is separate from graphics
526 * stolen, ignore it in stolen gtt entries counting */
527 size = 0;
Eric Anholtc41e0de2006-12-19 12:57:24 -0800528 } else {
529 /* On previous hardware, the GTT size was just what was
530 * required to map the aperture.
531 */
532 size = agp_bridge->driver->fetch_size() + 4;
533 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534
535 if (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82830_HB ||
536 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82845G_HB) {
537 switch (gmch_ctrl & I830_GMCH_GMS_MASK) {
538 case I830_GMCH_GMS_STOLEN_512:
539 gtt_entries = KB(512) - KB(size);
540 break;
541 case I830_GMCH_GMS_STOLEN_1024:
542 gtt_entries = MB(1) - KB(size);
543 break;
544 case I830_GMCH_GMS_STOLEN_8192:
545 gtt_entries = MB(8) - KB(size);
546 break;
547 case I830_GMCH_GMS_LOCAL:
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800548 rdct = readb(intel_private.registers+I830_RDRAM_CHANNEL_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 gtt_entries = (I830_RDRAM_ND(rdct) + 1) *
550 MB(ddt[I830_RDRAM_DDT(rdct)]);
551 local = 1;
552 break;
553 default:
554 gtt_entries = 0;
555 break;
556 }
557 } else {
Dave Airliee67aa272007-09-18 22:46:35 -0700558 switch (gmch_ctrl & I855_GMCH_GMS_MASK) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 case I855_GMCH_GMS_STOLEN_1M:
560 gtt_entries = MB(1) - KB(size);
561 break;
562 case I855_GMCH_GMS_STOLEN_4M:
563 gtt_entries = MB(4) - KB(size);
564 break;
565 case I855_GMCH_GMS_STOLEN_8M:
566 gtt_entries = MB(8) - KB(size);
567 break;
568 case I855_GMCH_GMS_STOLEN_16M:
569 gtt_entries = MB(16) - KB(size);
570 break;
571 case I855_GMCH_GMS_STOLEN_32M:
572 gtt_entries = MB(32) - KB(size);
573 break;
574 case I915_GMCH_GMS_STOLEN_48M:
575 /* Check it's really I915G */
Zhenyu Wang25ce77a2008-06-19 14:17:58 +1000576 if (IS_I915 || IS_I965 || IS_G33 || IS_G4X)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 gtt_entries = MB(48) - KB(size);
578 else
579 gtt_entries = 0;
580 break;
581 case I915_GMCH_GMS_STOLEN_64M:
582 /* Check it's really I915G */
Zhenyu Wang25ce77a2008-06-19 14:17:58 +1000583 if (IS_I915 || IS_I965 || IS_G33 || IS_G4X)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 gtt_entries = MB(64) - KB(size);
585 else
586 gtt_entries = 0;
Wang Zhenyu874808c62007-06-06 11:16:25 +0800587 break;
588 case G33_GMCH_GMS_STOLEN_128M:
Zhenyu Wang25ce77a2008-06-19 14:17:58 +1000589 if (IS_G33 || IS_I965 || IS_G4X)
Wang Zhenyu874808c62007-06-06 11:16:25 +0800590 gtt_entries = MB(128) - KB(size);
591 else
592 gtt_entries = 0;
593 break;
594 case G33_GMCH_GMS_STOLEN_256M:
Zhenyu Wang25ce77a2008-06-19 14:17:58 +1000595 if (IS_G33 || IS_I965 || IS_G4X)
Wang Zhenyu874808c62007-06-06 11:16:25 +0800596 gtt_entries = MB(256) - KB(size);
597 else
598 gtt_entries = 0;
599 break;
Zhenyu Wang25ce77a2008-06-19 14:17:58 +1000600 case INTEL_GMCH_GMS_STOLEN_96M:
601 if (IS_I965 || IS_G4X)
602 gtt_entries = MB(96) - KB(size);
603 else
604 gtt_entries = 0;
605 break;
606 case INTEL_GMCH_GMS_STOLEN_160M:
607 if (IS_I965 || IS_G4X)
608 gtt_entries = MB(160) - KB(size);
609 else
610 gtt_entries = 0;
611 break;
612 case INTEL_GMCH_GMS_STOLEN_224M:
613 if (IS_I965 || IS_G4X)
614 gtt_entries = MB(224) - KB(size);
615 else
616 gtt_entries = 0;
617 break;
618 case INTEL_GMCH_GMS_STOLEN_352M:
619 if (IS_I965 || IS_G4X)
620 gtt_entries = MB(352) - KB(size);
621 else
622 gtt_entries = 0;
623 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 default:
625 gtt_entries = 0;
626 break;
627 }
628 }
629 if (gtt_entries > 0)
630 printk(KERN_INFO PFX "Detected %dK %s memory.\n",
631 gtt_entries / KB(1), local ? "local" : "stolen");
632 else
633 printk(KERN_INFO PFX
634 "No pre-allocated video memory detected.\n");
635 gtt_entries /= KB(4);
636
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800637 intel_private.gtt_entries = gtt_entries;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638}
639
Dave Airlie2162e6a2007-11-21 16:36:31 +1000640static void intel_i830_fini_flush(void)
641{
642 kunmap(intel_private.i8xx_page);
643 intel_private.i8xx_flush_page = NULL;
644 unmap_page_from_agp(intel_private.i8xx_page);
Dave Airlie2162e6a2007-11-21 16:36:31 +1000645
646 __free_page(intel_private.i8xx_page);
Dave Airlie4d64dd92008-01-23 15:34:29 +1000647 intel_private.i8xx_page = NULL;
Dave Airlie2162e6a2007-11-21 16:36:31 +1000648}
649
650static void intel_i830_setup_flush(void)
651{
Dave Airlie4d64dd92008-01-23 15:34:29 +1000652 /* return if we've already set the flush mechanism up */
653 if (intel_private.i8xx_page)
654 return;
Dave Airlie2162e6a2007-11-21 16:36:31 +1000655
656 intel_private.i8xx_page = alloc_page(GFP_KERNEL | __GFP_ZERO | GFP_DMA32);
Dave Airlief011ae72008-01-25 11:23:04 +1000657 if (!intel_private.i8xx_page)
Dave Airlie2162e6a2007-11-21 16:36:31 +1000658 return;
Dave Airlie2162e6a2007-11-21 16:36:31 +1000659
660 /* make page uncached */
661 map_page_into_agp(intel_private.i8xx_page);
Dave Airlie2162e6a2007-11-21 16:36:31 +1000662
663 intel_private.i8xx_flush_page = kmap(intel_private.i8xx_page);
664 if (!intel_private.i8xx_flush_page)
665 intel_i830_fini_flush();
666}
667
668static void intel_i830_chipset_flush(struct agp_bridge_data *bridge)
669{
670 unsigned int *pg = intel_private.i8xx_flush_page;
671 int i;
672
Dave Airlief011ae72008-01-25 11:23:04 +1000673 for (i = 0; i < 256; i += 2)
Dave Airlie2162e6a2007-11-21 16:36:31 +1000674 *(pg + i) = i;
Dave Airlief011ae72008-01-25 11:23:04 +1000675
Dave Airlie2162e6a2007-11-21 16:36:31 +1000676 wmb();
677}
678
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679/* The intel i830 automatically initializes the agp aperture during POST.
680 * Use the memory already set aside for in the GTT.
681 */
682static int intel_i830_create_gatt_table(struct agp_bridge_data *bridge)
683{
684 int page_order;
685 struct aper_size_info_fixed *size;
686 int num_entries;
687 u32 temp;
688
689 size = agp_bridge->current_size;
690 page_order = size->page_order;
691 num_entries = size->num_entries;
692 agp_bridge->gatt_table_real = NULL;
693
Dave Airlief011ae72008-01-25 11:23:04 +1000694 pci_read_config_dword(intel_private.pcidev, I810_MMADDR, &temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 temp &= 0xfff80000;
696
Dave Airlief011ae72008-01-25 11:23:04 +1000697 intel_private.registers = ioremap(temp, 128 * 4096);
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800698 if (!intel_private.registers)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 return -ENOMEM;
700
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800701 temp = readl(intel_private.registers+I810_PGETBL_CTL) & 0xfffff000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 global_cache_flush(); /* FIXME: ?? */
703
704 /* we have to call this as early as possible after the MMIO base address is known */
705 intel_i830_init_gtt_entries();
706
707 agp_bridge->gatt_table = NULL;
708
709 agp_bridge->gatt_bus_addr = temp;
710
711 return 0;
712}
713
714/* Return the gatt table to a sane state. Use the top of stolen
715 * memory for the GTT.
716 */
717static int intel_i830_free_gatt_table(struct agp_bridge_data *bridge)
718{
719 return 0;
720}
721
722static int intel_i830_fetch_size(void)
723{
724 u16 gmch_ctrl;
725 struct aper_size_info_fixed *values;
726
727 values = A_SIZE_FIX(agp_bridge->driver->aperture_sizes);
728
729 if (agp_bridge->dev->device != PCI_DEVICE_ID_INTEL_82830_HB &&
730 agp_bridge->dev->device != PCI_DEVICE_ID_INTEL_82845G_HB) {
731 /* 855GM/852GM/865G has 128MB aperture size */
732 agp_bridge->previous_size = agp_bridge->current_size = (void *) values;
733 agp_bridge->aperture_size_idx = 0;
734 return values[0].size;
735 }
736
Dave Airlief011ae72008-01-25 11:23:04 +1000737 pci_read_config_word(agp_bridge->dev, I830_GMCH_CTRL, &gmch_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738
739 if ((gmch_ctrl & I830_GMCH_MEM_MASK) == I830_GMCH_MEM_128M) {
740 agp_bridge->previous_size = agp_bridge->current_size = (void *) values;
741 agp_bridge->aperture_size_idx = 0;
742 return values[0].size;
743 } else {
744 agp_bridge->previous_size = agp_bridge->current_size = (void *) (values + 1);
745 agp_bridge->aperture_size_idx = 1;
746 return values[1].size;
747 }
748
749 return 0;
750}
751
752static int intel_i830_configure(void)
753{
754 struct aper_size_info_fixed *current_size;
755 u32 temp;
756 u16 gmch_ctrl;
757 int i;
758
759 current_size = A_SIZE_FIX(agp_bridge->current_size);
760
Dave Airlief011ae72008-01-25 11:23:04 +1000761 pci_read_config_dword(intel_private.pcidev, I810_GMADDR, &temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
763
Dave Airlief011ae72008-01-25 11:23:04 +1000764 pci_read_config_word(agp_bridge->dev, I830_GMCH_CTRL, &gmch_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 gmch_ctrl |= I830_GMCH_ENABLED;
Dave Airlief011ae72008-01-25 11:23:04 +1000766 pci_write_config_word(agp_bridge->dev, I830_GMCH_CTRL, gmch_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800768 writel(agp_bridge->gatt_bus_addr|I810_PGETBL_ENABLED, intel_private.registers+I810_PGETBL_CTL);
769 readl(intel_private.registers+I810_PGETBL_CTL); /* PCI Posting. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770
771 if (agp_bridge->driver->needs_scratch_page) {
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800772 for (i = intel_private.gtt_entries; i < current_size->num_entries; i++) {
773 writel(agp_bridge->scratch_page, intel_private.registers+I810_PTE_BASE+(i*4));
774 readl(intel_private.registers+I810_PTE_BASE+(i*4)); /* PCI Posting. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 }
776 }
777
778 global_cache_flush();
Dave Airlie2162e6a2007-11-21 16:36:31 +1000779
780 intel_i830_setup_flush();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 return 0;
782}
783
784static void intel_i830_cleanup(void)
785{
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800786 iounmap(intel_private.registers);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787}
788
Dave Airlief011ae72008-01-25 11:23:04 +1000789static int intel_i830_insert_entries(struct agp_memory *mem, off_t pg_start,
790 int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791{
Dave Airlief011ae72008-01-25 11:23:04 +1000792 int i, j, num_entries;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 void *temp;
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100794 int ret = -EINVAL;
795 int mask_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +0100797 if (mem->page_count == 0)
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100798 goto out;
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +0100799
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 temp = agp_bridge->current_size;
801 num_entries = A_SIZE_FIX(temp)->num_entries;
802
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800803 if (pg_start < intel_private.gtt_entries) {
Dave Airlief011ae72008-01-25 11:23:04 +1000804 printk(KERN_DEBUG PFX "pg_start == 0x%.8lx,intel_private.gtt_entries == 0x%.8x\n",
805 pg_start, intel_private.gtt_entries);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806
Dave Airlief011ae72008-01-25 11:23:04 +1000807 printk(KERN_INFO PFX "Trying to insert into local/stolen memory\n");
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100808 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 }
810
811 if ((pg_start + mem->page_count) > num_entries)
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100812 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813
814 /* The i830 can't check the GTT for entries since its read only,
815 * depend on the caller to make the correct offset decisions.
816 */
817
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100818 if (type != mem->type)
819 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100821 mask_type = agp_bridge->driver->agp_type_to_mask_type(agp_bridge, type);
822
823 if (mask_type != 0 && mask_type != AGP_PHYS_MEMORY &&
824 mask_type != INTEL_AGP_CACHED_MEMORY)
825 goto out_err;
826
827 if (!mem->is_flushed)
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +0100828 global_cache_flush();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829
830 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
831 writel(agp_bridge->driver->mask_memory(agp_bridge,
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100832 mem->memory[i], mask_type),
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800833 intel_private.registers+I810_PTE_BASE+(j*4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 }
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800835 readl(intel_private.registers+I810_PTE_BASE+((j-1)*4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 agp_bridge->driver->tlb_flush(mem);
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100837
838out:
839 ret = 0;
840out_err:
Dave Airlie9516b032008-06-19 10:42:17 +1000841 mem->is_flushed = true;
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100842 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843}
844
Dave Airlief011ae72008-01-25 11:23:04 +1000845static int intel_i830_remove_entries(struct agp_memory *mem, off_t pg_start,
846 int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847{
848 int i;
849
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +0100850 if (mem->page_count == 0)
851 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800853 if (pg_start < intel_private.gtt_entries) {
Dave Airlief011ae72008-01-25 11:23:04 +1000854 printk(KERN_INFO PFX "Trying to disable local/stolen memory\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 return -EINVAL;
856 }
857
858 for (i = pg_start; i < (mem->page_count + pg_start); i++) {
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800859 writel(agp_bridge->scratch_page, intel_private.registers+I810_PTE_BASE+(i*4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 }
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800861 readl(intel_private.registers+I810_PTE_BASE+((i-1)*4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 agp_bridge->driver->tlb_flush(mem);
864 return 0;
865}
866
Dave Airlief011ae72008-01-25 11:23:04 +1000867static struct agp_memory *intel_i830_alloc_by_type(size_t pg_count, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868{
869 if (type == AGP_PHYS_MEMORY)
870 return alloc_agpphysmem_i8xx(pg_count, type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 /* always return NULL for other allocation types for now */
872 return NULL;
873}
874
Dave Airlie6c00a612007-10-29 18:06:10 +1000875static int intel_alloc_chipset_flush_resource(void)
876{
877 int ret;
878 ret = pci_bus_alloc_resource(agp_bridge->dev->bus, &intel_private.ifp_resource, PAGE_SIZE,
879 PAGE_SIZE, PCIBIOS_MIN_MEM, 0,
880 pcibios_align_resource, agp_bridge->dev);
Dave Airlie6c00a612007-10-29 18:06:10 +1000881
Dave Airlie2162e6a2007-11-21 16:36:31 +1000882 return ret;
Dave Airlie6c00a612007-10-29 18:06:10 +1000883}
884
885static void intel_i915_setup_chipset_flush(void)
886{
887 int ret;
888 u32 temp;
889
890 pci_read_config_dword(agp_bridge->dev, I915_IFPADDR, &temp);
891 if (!(temp & 0x1)) {
892 intel_alloc_chipset_flush_resource();
Dave Airlie4d64dd92008-01-23 15:34:29 +1000893 intel_private.resource_valid = 1;
Dave Airlie6c00a612007-10-29 18:06:10 +1000894 pci_write_config_dword(agp_bridge->dev, I915_IFPADDR, (intel_private.ifp_resource.start & 0xffffffff) | 0x1);
895 } else {
896 temp &= ~1;
897
Dave Airlie4d64dd92008-01-23 15:34:29 +1000898 intel_private.resource_valid = 1;
Dave Airlie6c00a612007-10-29 18:06:10 +1000899 intel_private.ifp_resource.start = temp;
900 intel_private.ifp_resource.end = temp + PAGE_SIZE;
901 ret = request_resource(&iomem_resource, &intel_private.ifp_resource);
Dave Airlie4d64dd92008-01-23 15:34:29 +1000902 /* some BIOSes reserve this area in a pnp some don't */
903 if (ret)
904 intel_private.resource_valid = 0;
Dave Airlie6c00a612007-10-29 18:06:10 +1000905 }
906}
907
908static void intel_i965_g33_setup_chipset_flush(void)
909{
910 u32 temp_hi, temp_lo;
911 int ret;
912
913 pci_read_config_dword(agp_bridge->dev, I965_IFPADDR + 4, &temp_hi);
914 pci_read_config_dword(agp_bridge->dev, I965_IFPADDR, &temp_lo);
915
916 if (!(temp_lo & 0x1)) {
917
918 intel_alloc_chipset_flush_resource();
919
Dave Airlie4d64dd92008-01-23 15:34:29 +1000920 intel_private.resource_valid = 1;
Andrew Morton1fa4db72007-11-29 10:00:48 +1000921 pci_write_config_dword(agp_bridge->dev, I965_IFPADDR + 4,
922 upper_32_bits(intel_private.ifp_resource.start));
Dave Airlie6c00a612007-10-29 18:06:10 +1000923 pci_write_config_dword(agp_bridge->dev, I965_IFPADDR, (intel_private.ifp_resource.start & 0xffffffff) | 0x1);
Dave Airlie6c00a612007-10-29 18:06:10 +1000924 } else {
925 u64 l64;
Dave Airlief011ae72008-01-25 11:23:04 +1000926
Dave Airlie6c00a612007-10-29 18:06:10 +1000927 temp_lo &= ~0x1;
928 l64 = ((u64)temp_hi << 32) | temp_lo;
929
Dave Airlie4d64dd92008-01-23 15:34:29 +1000930 intel_private.resource_valid = 1;
Dave Airlie6c00a612007-10-29 18:06:10 +1000931 intel_private.ifp_resource.start = l64;
932 intel_private.ifp_resource.end = l64 + PAGE_SIZE;
933 ret = request_resource(&iomem_resource, &intel_private.ifp_resource);
Dave Airlie4d64dd92008-01-23 15:34:29 +1000934 /* some BIOSes reserve this area in a pnp some don't */
935 if (ret)
936 intel_private.resource_valid = 0;
Dave Airlie6c00a612007-10-29 18:06:10 +1000937 }
938}
939
Dave Airlie2162e6a2007-11-21 16:36:31 +1000940static void intel_i9xx_setup_flush(void)
941{
Dave Airlie4d64dd92008-01-23 15:34:29 +1000942 /* return if already configured */
943 if (intel_private.ifp_resource.start)
944 return;
Dave Airlie2162e6a2007-11-21 16:36:31 +1000945
Dave Airlie4d64dd92008-01-23 15:34:29 +1000946 /* setup a resource for this object */
Dave Airlie2162e6a2007-11-21 16:36:31 +1000947 intel_private.ifp_resource.name = "Intel Flush Page";
948 intel_private.ifp_resource.flags = IORESOURCE_MEM;
949
950 /* Setup chipset flush for 915 */
Zhenyu Wang7d15ddf2008-06-20 11:48:06 +1000951 if (IS_I965 || IS_G33 || IS_G4X) {
Dave Airlie2162e6a2007-11-21 16:36:31 +1000952 intel_i965_g33_setup_chipset_flush();
953 } else {
954 intel_i915_setup_chipset_flush();
955 }
956
957 if (intel_private.ifp_resource.start) {
958 intel_private.i9xx_flush_page = ioremap_nocache(intel_private.ifp_resource.start, PAGE_SIZE);
959 if (!intel_private.i9xx_flush_page)
Dave Airlief011ae72008-01-25 11:23:04 +1000960 printk(KERN_INFO "unable to ioremap flush page - no chipset flushing");
Dave Airlie2162e6a2007-11-21 16:36:31 +1000961 }
962}
963
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964static int intel_i915_configure(void)
965{
966 struct aper_size_info_fixed *current_size;
967 u32 temp;
968 u16 gmch_ctrl;
969 int i;
970
971 current_size = A_SIZE_FIX(agp_bridge->current_size);
972
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800973 pci_read_config_dword(intel_private.pcidev, I915_GMADDR, &temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974
975 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
976
Dave Airlief011ae72008-01-25 11:23:04 +1000977 pci_read_config_word(agp_bridge->dev, I830_GMCH_CTRL, &gmch_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 gmch_ctrl |= I830_GMCH_ENABLED;
Dave Airlief011ae72008-01-25 11:23:04 +1000979 pci_write_config_word(agp_bridge->dev, I830_GMCH_CTRL, gmch_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800981 writel(agp_bridge->gatt_bus_addr|I810_PGETBL_ENABLED, intel_private.registers+I810_PGETBL_CTL);
982 readl(intel_private.registers+I810_PGETBL_CTL); /* PCI Posting. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983
984 if (agp_bridge->driver->needs_scratch_page) {
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800985 for (i = intel_private.gtt_entries; i < current_size->num_entries; i++) {
986 writel(agp_bridge->scratch_page, intel_private.gtt+i);
987 readl(intel_private.gtt+i); /* PCI Posting. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 }
989 }
990
991 global_cache_flush();
Dave Airlie6c00a612007-10-29 18:06:10 +1000992
Dave Airlie2162e6a2007-11-21 16:36:31 +1000993 intel_i9xx_setup_flush();
Dave Airlief011ae72008-01-25 11:23:04 +1000994
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 return 0;
996}
997
998static void intel_i915_cleanup(void)
999{
Dave Airlie2162e6a2007-11-21 16:36:31 +10001000 if (intel_private.i9xx_flush_page)
1001 iounmap(intel_private.i9xx_flush_page);
Dave Airlie4d64dd92008-01-23 15:34:29 +10001002 if (intel_private.resource_valid)
1003 release_resource(&intel_private.ifp_resource);
1004 intel_private.ifp_resource.start = 0;
1005 intel_private.resource_valid = 0;
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001006 iounmap(intel_private.gtt);
1007 iounmap(intel_private.registers);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008}
1009
Dave Airlie6c00a612007-10-29 18:06:10 +10001010static void intel_i915_chipset_flush(struct agp_bridge_data *bridge)
1011{
Dave Airlie2162e6a2007-11-21 16:36:31 +10001012 if (intel_private.i9xx_flush_page)
1013 writel(1, intel_private.i9xx_flush_page);
Dave Airlie6c00a612007-10-29 18:06:10 +10001014}
1015
Dave Airlief011ae72008-01-25 11:23:04 +10001016static int intel_i915_insert_entries(struct agp_memory *mem, off_t pg_start,
1017 int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018{
Dave Airlief011ae72008-01-25 11:23:04 +10001019 int i, j, num_entries;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 void *temp;
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001021 int ret = -EINVAL;
1022 int mask_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +01001024 if (mem->page_count == 0)
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001025 goto out;
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +01001026
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 temp = agp_bridge->current_size;
1028 num_entries = A_SIZE_FIX(temp)->num_entries;
1029
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001030 if (pg_start < intel_private.gtt_entries) {
Dave Airlief011ae72008-01-25 11:23:04 +10001031 printk(KERN_DEBUG PFX "pg_start == 0x%.8lx,intel_private.gtt_entries == 0x%.8x\n",
1032 pg_start, intel_private.gtt_entries);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033
Dave Airlief011ae72008-01-25 11:23:04 +10001034 printk(KERN_INFO PFX "Trying to insert into local/stolen memory\n");
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001035 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 }
1037
1038 if ((pg_start + mem->page_count) > num_entries)
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001039 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001041 /* The i915 can't check the GTT for entries since its read only,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 * depend on the caller to make the correct offset decisions.
1043 */
1044
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001045 if (type != mem->type)
1046 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001048 mask_type = agp_bridge->driver->agp_type_to_mask_type(agp_bridge, type);
1049
1050 if (mask_type != 0 && mask_type != AGP_PHYS_MEMORY &&
1051 mask_type != INTEL_AGP_CACHED_MEMORY)
1052 goto out_err;
1053
1054 if (!mem->is_flushed)
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +01001055 global_cache_flush();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056
1057 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
1058 writel(agp_bridge->driver->mask_memory(agp_bridge,
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001059 mem->memory[i], mask_type), intel_private.gtt+j);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 }
1061
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001062 readl(intel_private.gtt+j-1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 agp_bridge->driver->tlb_flush(mem);
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001064
1065 out:
1066 ret = 0;
1067 out_err:
Dave Airlie9516b032008-06-19 10:42:17 +10001068 mem->is_flushed = true;
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001069 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070}
1071
Dave Airlief011ae72008-01-25 11:23:04 +10001072static int intel_i915_remove_entries(struct agp_memory *mem, off_t pg_start,
1073 int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074{
1075 int i;
1076
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +01001077 if (mem->page_count == 0)
1078 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001080 if (pg_start < intel_private.gtt_entries) {
Dave Airlief011ae72008-01-25 11:23:04 +10001081 printk(KERN_INFO PFX "Trying to disable local/stolen memory\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 return -EINVAL;
1083 }
1084
Dave Airlief011ae72008-01-25 11:23:04 +10001085 for (i = pg_start; i < (mem->page_count + pg_start); i++)
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001086 writel(agp_bridge->scratch_page, intel_private.gtt+i);
Dave Airlief011ae72008-01-25 11:23:04 +10001087
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001088 readl(intel_private.gtt+i-1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 agp_bridge->driver->tlb_flush(mem);
1091 return 0;
1092}
1093
Eric Anholtc41e0de2006-12-19 12:57:24 -08001094/* Return the aperture size by just checking the resource length. The effect
1095 * described in the spec of the MSAC registers is just changing of the
1096 * resource size.
1097 */
1098static int intel_i9xx_fetch_size(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099{
Ahmed S. Darwish1eaf1222007-02-06 18:08:28 +02001100 int num_sizes = ARRAY_SIZE(intel_i830_sizes);
Eric Anholtc41e0de2006-12-19 12:57:24 -08001101 int aper_size; /* size in megabytes */
1102 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001104 aper_size = pci_resource_len(intel_private.pcidev, 2) / MB(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105
Eric Anholtc41e0de2006-12-19 12:57:24 -08001106 for (i = 0; i < num_sizes; i++) {
1107 if (aper_size == intel_i830_sizes[i].size) {
1108 agp_bridge->current_size = intel_i830_sizes + i;
1109 agp_bridge->previous_size = agp_bridge->current_size;
1110 return aper_size;
1111 }
1112 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113
Eric Anholtc41e0de2006-12-19 12:57:24 -08001114 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115}
1116
1117/* The intel i915 automatically initializes the agp aperture during POST.
1118 * Use the memory already set aside for in the GTT.
1119 */
1120static int intel_i915_create_gatt_table(struct agp_bridge_data *bridge)
1121{
1122 int page_order;
1123 struct aper_size_info_fixed *size;
1124 int num_entries;
1125 u32 temp, temp2;
Zhenyu Wang47406222007-09-11 15:23:58 -07001126 int gtt_map_size = 256 * 1024;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127
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);
Dave Airlief011ae72008-01-25 11:23:04 +10001134 pci_read_config_dword(intel_private.pcidev, I915_PTEADDR, &temp2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135
Zhenyu Wang47406222007-09-11 15:23:58 -07001136 if (IS_G33)
1137 gtt_map_size = 1024 * 1024; /* 1M on G33 */
1138 intel_private.gtt = ioremap(temp2, gtt_map_size);
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001139 if (!intel_private.gtt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 return -ENOMEM;
1141
1142 temp &= 0xfff80000;
1143
Dave Airlief011ae72008-01-25 11:23:04 +10001144 intel_private.registers = ioremap(temp, 128 * 4096);
Scott Thompson5bdbc7d2007-08-25 18:14:00 +10001145 if (!intel_private.registers) {
1146 iounmap(intel_private.gtt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 return -ENOMEM;
Scott Thompson5bdbc7d2007-08-25 18:14:00 +10001148 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001150 temp = readl(intel_private.registers+I810_PGETBL_CTL) & 0xfffff000;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151 global_cache_flush(); /* FIXME: ? */
1152
1153 /* we have to call this as early as possible after the MMIO base address is known */
1154 intel_i830_init_gtt_entries();
1155
1156 agp_bridge->gatt_table = NULL;
1157
1158 agp_bridge->gatt_bus_addr = temp;
1159
1160 return 0;
1161}
Linus Torvalds7d915a32006-11-22 09:37:54 -08001162
1163/*
1164 * The i965 supports 36-bit physical addresses, but to keep
1165 * the format of the GTT the same, the bits that don't fit
1166 * in a 32-bit word are shifted down to bits 4..7.
1167 *
1168 * Gcc is smart enough to notice that "(addr >> 28) & 0xf0"
1169 * is always zero on 32-bit architectures, so no need to make
1170 * this conditional.
1171 */
1172static unsigned long intel_i965_mask_memory(struct agp_bridge_data *bridge,
1173 unsigned long addr, int type)
1174{
1175 /* Shift high bits down */
1176 addr |= (addr >> 28) & 0xf0;
1177
1178 /* Type checking must be done elsewhere */
1179 return addr | bridge->driver->masks[type].mask;
1180}
1181
Zhenyu Wang25ce77a2008-06-19 14:17:58 +10001182static void intel_i965_get_gtt_range(int *gtt_offset, int *gtt_size)
1183{
1184 switch (agp_bridge->dev->device) {
1185 case PCI_DEVICE_ID_INTEL_IGD_HB:
1186 case PCI_DEVICE_ID_INTEL_IGD_E_HB:
1187 case PCI_DEVICE_ID_INTEL_Q45_HB:
1188 case PCI_DEVICE_ID_INTEL_G45_HB:
1189 *gtt_offset = *gtt_size = MB(2);
1190 break;
1191 default:
1192 *gtt_offset = *gtt_size = KB(512);
1193 }
1194}
1195
Eric Anholt65c25aa2006-09-06 11:57:18 -04001196/* The intel i965 automatically initializes the agp aperture during POST.
Eric Anholtc41e0de2006-12-19 12:57:24 -08001197 * Use the memory already set aside for in the GTT.
1198 */
Eric Anholt65c25aa2006-09-06 11:57:18 -04001199static int intel_i965_create_gatt_table(struct agp_bridge_data *bridge)
1200{
Dave Airlie62c96b92008-06-19 14:27:53 +10001201 int page_order;
1202 struct aper_size_info_fixed *size;
1203 int num_entries;
1204 u32 temp;
1205 int gtt_offset, gtt_size;
Eric Anholt65c25aa2006-09-06 11:57:18 -04001206
Dave Airlie62c96b92008-06-19 14:27:53 +10001207 size = agp_bridge->current_size;
1208 page_order = size->page_order;
1209 num_entries = size->num_entries;
1210 agp_bridge->gatt_table_real = NULL;
Eric Anholt65c25aa2006-09-06 11:57:18 -04001211
Dave Airlie62c96b92008-06-19 14:27:53 +10001212 pci_read_config_dword(intel_private.pcidev, I915_MMADDR, &temp);
Eric Anholt65c25aa2006-09-06 11:57:18 -04001213
Dave Airlie62c96b92008-06-19 14:27:53 +10001214 temp &= 0xfff00000;
Eric Anholt65c25aa2006-09-06 11:57:18 -04001215
Zhenyu Wang25ce77a2008-06-19 14:17:58 +10001216 intel_i965_get_gtt_range(&gtt_offset, &gtt_size);
Eric Anholt65c25aa2006-09-06 11:57:18 -04001217
Dave Airlie62c96b92008-06-19 14:27:53 +10001218 intel_private.gtt = ioremap((temp + gtt_offset) , gtt_size);
Eric Anholt65c25aa2006-09-06 11:57:18 -04001219
Dave Airlie62c96b92008-06-19 14:27:53 +10001220 if (!intel_private.gtt)
1221 return -ENOMEM;
Zhenyu Wang4e8b6e22008-01-23 14:54:37 +10001222
Dave Airlie62c96b92008-06-19 14:27:53 +10001223 intel_private.registers = ioremap(temp, 128 * 4096);
1224 if (!intel_private.registers) {
Scott Thompson5bdbc7d2007-08-25 18:14:00 +10001225 iounmap(intel_private.gtt);
1226 return -ENOMEM;
1227 }
Eric Anholt65c25aa2006-09-06 11:57:18 -04001228
Dave Airlie62c96b92008-06-19 14:27:53 +10001229 temp = readl(intel_private.registers+I810_PGETBL_CTL) & 0xfffff000;
1230 global_cache_flush(); /* FIXME: ? */
Eric Anholt65c25aa2006-09-06 11:57:18 -04001231
Dave Airlie62c96b92008-06-19 14:27:53 +10001232 /* we have to call this as early as possible after the MMIO base address is known */
1233 intel_i830_init_gtt_entries();
Eric Anholt65c25aa2006-09-06 11:57:18 -04001234
Dave Airlie62c96b92008-06-19 14:27:53 +10001235 agp_bridge->gatt_table = NULL;
Eric Anholt65c25aa2006-09-06 11:57:18 -04001236
Dave Airlie62c96b92008-06-19 14:27:53 +10001237 agp_bridge->gatt_bus_addr = temp;
Eric Anholt65c25aa2006-09-06 11:57:18 -04001238
Dave Airlie62c96b92008-06-19 14:27:53 +10001239 return 0;
Eric Anholt65c25aa2006-09-06 11:57:18 -04001240}
1241
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242
1243static int intel_fetch_size(void)
1244{
1245 int i;
1246 u16 temp;
1247 struct aper_size_info_16 *values;
1248
1249 pci_read_config_word(agp_bridge->dev, INTEL_APSIZE, &temp);
1250 values = A_SIZE_16(agp_bridge->driver->aperture_sizes);
1251
1252 for (i = 0; i < agp_bridge->driver->num_aperture_sizes; i++) {
1253 if (temp == values[i].size_value) {
1254 agp_bridge->previous_size = agp_bridge->current_size = (void *) (values + i);
1255 agp_bridge->aperture_size_idx = i;
1256 return values[i].size;
1257 }
1258 }
1259
1260 return 0;
1261}
1262
1263static int __intel_8xx_fetch_size(u8 temp)
1264{
1265 int i;
1266 struct aper_size_info_8 *values;
1267
1268 values = A_SIZE_8(agp_bridge->driver->aperture_sizes);
1269
1270 for (i = 0; i < agp_bridge->driver->num_aperture_sizes; i++) {
1271 if (temp == values[i].size_value) {
1272 agp_bridge->previous_size =
1273 agp_bridge->current_size = (void *) (values + i);
1274 agp_bridge->aperture_size_idx = i;
1275 return values[i].size;
1276 }
1277 }
1278 return 0;
1279}
1280
1281static int intel_8xx_fetch_size(void)
1282{
1283 u8 temp;
1284
1285 pci_read_config_byte(agp_bridge->dev, INTEL_APSIZE, &temp);
1286 return __intel_8xx_fetch_size(temp);
1287}
1288
1289static int intel_815_fetch_size(void)
1290{
1291 u8 temp;
1292
1293 /* Intel 815 chipsets have a _weird_ APSIZE register with only
1294 * one non-reserved bit, so mask the others out ... */
1295 pci_read_config_byte(agp_bridge->dev, INTEL_APSIZE, &temp);
1296 temp &= (1 << 3);
1297
1298 return __intel_8xx_fetch_size(temp);
1299}
1300
1301static void intel_tlbflush(struct agp_memory *mem)
1302{
1303 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x2200);
1304 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x2280);
1305}
1306
1307
1308static void intel_8xx_tlbflush(struct agp_memory *mem)
1309{
1310 u32 temp;
1311 pci_read_config_dword(agp_bridge->dev, INTEL_AGPCTRL, &temp);
1312 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, temp & ~(1 << 7));
1313 pci_read_config_dword(agp_bridge->dev, INTEL_AGPCTRL, &temp);
1314 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, temp | (1 << 7));
1315}
1316
1317
1318static void intel_cleanup(void)
1319{
1320 u16 temp;
1321 struct aper_size_info_16 *previous_size;
1322
1323 previous_size = A_SIZE_16(agp_bridge->previous_size);
1324 pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp);
1325 pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG, temp & ~(1 << 9));
1326 pci_write_config_word(agp_bridge->dev, INTEL_APSIZE, previous_size->size_value);
1327}
1328
1329
1330static void intel_8xx_cleanup(void)
1331{
1332 u16 temp;
1333 struct aper_size_info_8 *previous_size;
1334
1335 previous_size = A_SIZE_8(agp_bridge->previous_size);
1336 pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp);
1337 pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG, temp & ~(1 << 9));
1338 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, previous_size->size_value);
1339}
1340
1341
1342static int intel_configure(void)
1343{
1344 u32 temp;
1345 u16 temp2;
1346 struct aper_size_info_16 *current_size;
1347
1348 current_size = A_SIZE_16(agp_bridge->current_size);
1349
1350 /* aperture size */
1351 pci_write_config_word(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1352
1353 /* address to map to */
1354 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1355 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1356
1357 /* attbase - aperture base */
1358 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1359
1360 /* agpctrl */
1361 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x2280);
1362
1363 /* paccfg/nbxcfg */
1364 pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp2);
1365 pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG,
1366 (temp2 & ~(1 << 10)) | (1 << 9));
1367 /* clear any possible error conditions */
1368 pci_write_config_byte(agp_bridge->dev, INTEL_ERRSTS + 1, 7);
1369 return 0;
1370}
1371
1372static int intel_815_configure(void)
1373{
1374 u32 temp, addr;
1375 u8 temp2;
1376 struct aper_size_info_8 *current_size;
1377
1378 /* attbase - aperture base */
1379 /* the Intel 815 chipset spec. says that bits 29-31 in the
1380 * ATTBASE register are reserved -> try not to write them */
1381 if (agp_bridge->gatt_bus_addr & INTEL_815_ATTBASE_MASK) {
Dave Airlief011ae72008-01-25 11:23:04 +10001382 printk(KERN_EMERG PFX "gatt bus addr too high");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 return -EINVAL;
1384 }
1385
1386 current_size = A_SIZE_8(agp_bridge->current_size);
1387
1388 /* aperture size */
1389 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE,
1390 current_size->size_value);
1391
1392 /* address to map to */
1393 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1394 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1395
1396 pci_read_config_dword(agp_bridge->dev, INTEL_ATTBASE, &addr);
1397 addr &= INTEL_815_ATTBASE_MASK;
1398 addr |= agp_bridge->gatt_bus_addr;
1399 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, addr);
1400
1401 /* agpctrl */
1402 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1403
1404 /* apcont */
1405 pci_read_config_byte(agp_bridge->dev, INTEL_815_APCONT, &temp2);
1406 pci_write_config_byte(agp_bridge->dev, INTEL_815_APCONT, temp2 | (1 << 1));
1407
1408 /* clear any possible error conditions */
1409 /* Oddness : this chipset seems to have no ERRSTS register ! */
1410 return 0;
1411}
1412
1413static void intel_820_tlbflush(struct agp_memory *mem)
1414{
1415 return;
1416}
1417
1418static void intel_820_cleanup(void)
1419{
1420 u8 temp;
1421 struct aper_size_info_8 *previous_size;
1422
1423 previous_size = A_SIZE_8(agp_bridge->previous_size);
1424 pci_read_config_byte(agp_bridge->dev, INTEL_I820_RDCR, &temp);
1425 pci_write_config_byte(agp_bridge->dev, INTEL_I820_RDCR,
1426 temp & ~(1 << 1));
1427 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE,
1428 previous_size->size_value);
1429}
1430
1431
1432static int intel_820_configure(void)
1433{
1434 u32 temp;
1435 u8 temp2;
1436 struct aper_size_info_8 *current_size;
1437
1438 current_size = A_SIZE_8(agp_bridge->current_size);
1439
1440 /* aperture size */
1441 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1442
1443 /* address to map to */
1444 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1445 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1446
1447 /* attbase - aperture base */
1448 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1449
1450 /* agpctrl */
1451 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1452
1453 /* global enable aperture access */
1454 /* This flag is not accessed through MCHCFG register as in */
1455 /* i850 chipset. */
1456 pci_read_config_byte(agp_bridge->dev, INTEL_I820_RDCR, &temp2);
1457 pci_write_config_byte(agp_bridge->dev, INTEL_I820_RDCR, temp2 | (1 << 1));
1458 /* clear any possible AGP-related error conditions */
1459 pci_write_config_word(agp_bridge->dev, INTEL_I820_ERRSTS, 0x001c);
1460 return 0;
1461}
1462
1463static int intel_840_configure(void)
1464{
1465 u32 temp;
1466 u16 temp2;
1467 struct aper_size_info_8 *current_size;
1468
1469 current_size = A_SIZE_8(agp_bridge->current_size);
1470
1471 /* aperture size */
1472 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1473
1474 /* address to map to */
1475 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1476 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1477
1478 /* attbase - aperture base */
1479 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1480
1481 /* agpctrl */
1482 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1483
1484 /* mcgcfg */
1485 pci_read_config_word(agp_bridge->dev, INTEL_I840_MCHCFG, &temp2);
1486 pci_write_config_word(agp_bridge->dev, INTEL_I840_MCHCFG, temp2 | (1 << 9));
1487 /* clear any possible error conditions */
1488 pci_write_config_word(agp_bridge->dev, INTEL_I840_ERRSTS, 0xc000);
1489 return 0;
1490}
1491
1492static int intel_845_configure(void)
1493{
1494 u32 temp;
1495 u8 temp2;
1496 struct aper_size_info_8 *current_size;
1497
1498 current_size = A_SIZE_8(agp_bridge->current_size);
1499
1500 /* aperture size */
1501 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1502
Matthew Garrettb0825482005-07-29 14:03:39 -07001503 if (agp_bridge->apbase_config != 0) {
1504 pci_write_config_dword(agp_bridge->dev, AGP_APBASE,
1505 agp_bridge->apbase_config);
1506 } else {
1507 /* address to map to */
1508 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1509 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1510 agp_bridge->apbase_config = temp;
1511 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512
1513 /* attbase - aperture base */
1514 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1515
1516 /* agpctrl */
1517 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1518
1519 /* agpm */
1520 pci_read_config_byte(agp_bridge->dev, INTEL_I845_AGPM, &temp2);
1521 pci_write_config_byte(agp_bridge->dev, INTEL_I845_AGPM, temp2 | (1 << 1));
1522 /* clear any possible error conditions */
1523 pci_write_config_word(agp_bridge->dev, INTEL_I845_ERRSTS, 0x001c);
Dave Airlie2162e6a2007-11-21 16:36:31 +10001524
1525 intel_i830_setup_flush();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 return 0;
1527}
1528
1529static int intel_850_configure(void)
1530{
1531 u32 temp;
1532 u16 temp2;
1533 struct aper_size_info_8 *current_size;
1534
1535 current_size = A_SIZE_8(agp_bridge->current_size);
1536
1537 /* aperture size */
1538 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1539
1540 /* address to map to */
1541 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1542 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1543
1544 /* attbase - aperture base */
1545 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1546
1547 /* agpctrl */
1548 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1549
1550 /* mcgcfg */
1551 pci_read_config_word(agp_bridge->dev, INTEL_I850_MCHCFG, &temp2);
1552 pci_write_config_word(agp_bridge->dev, INTEL_I850_MCHCFG, temp2 | (1 << 9));
1553 /* clear any possible AGP-related error conditions */
1554 pci_write_config_word(agp_bridge->dev, INTEL_I850_ERRSTS, 0x001c);
1555 return 0;
1556}
1557
1558static int intel_860_configure(void)
1559{
1560 u32 temp;
1561 u16 temp2;
1562 struct aper_size_info_8 *current_size;
1563
1564 current_size = A_SIZE_8(agp_bridge->current_size);
1565
1566 /* aperture size */
1567 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1568
1569 /* address to map to */
1570 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1571 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1572
1573 /* attbase - aperture base */
1574 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1575
1576 /* agpctrl */
1577 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1578
1579 /* mcgcfg */
1580 pci_read_config_word(agp_bridge->dev, INTEL_I860_MCHCFG, &temp2);
1581 pci_write_config_word(agp_bridge->dev, INTEL_I860_MCHCFG, temp2 | (1 << 9));
1582 /* clear any possible AGP-related error conditions */
1583 pci_write_config_word(agp_bridge->dev, INTEL_I860_ERRSTS, 0xf700);
1584 return 0;
1585}
1586
1587static int intel_830mp_configure(void)
1588{
1589 u32 temp;
1590 u16 temp2;
1591 struct aper_size_info_8 *current_size;
1592
1593 current_size = A_SIZE_8(agp_bridge->current_size);
1594
1595 /* aperture size */
1596 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1597
1598 /* address to map to */
1599 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1600 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1601
1602 /* attbase - aperture base */
1603 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1604
1605 /* agpctrl */
1606 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1607
1608 /* gmch */
1609 pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp2);
1610 pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG, temp2 | (1 << 9));
1611 /* clear any possible AGP-related error conditions */
1612 pci_write_config_word(agp_bridge->dev, INTEL_I830_ERRSTS, 0x1c);
1613 return 0;
1614}
1615
1616static int intel_7505_configure(void)
1617{
1618 u32 temp;
1619 u16 temp2;
1620 struct aper_size_info_8 *current_size;
1621
1622 current_size = A_SIZE_8(agp_bridge->current_size);
1623
1624 /* aperture size */
1625 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1626
1627 /* address to map to */
1628 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1629 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1630
1631 /* attbase - aperture base */
1632 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1633
1634 /* agpctrl */
1635 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1636
1637 /* mchcfg */
1638 pci_read_config_word(agp_bridge->dev, INTEL_I7505_MCHCFG, &temp2);
1639 pci_write_config_word(agp_bridge->dev, INTEL_I7505_MCHCFG, temp2 | (1 << 9));
1640
1641 return 0;
1642}
1643
1644/* Setup function */
Dave Jonese5524f32007-02-22 18:41:28 -05001645static const struct gatt_mask intel_generic_masks[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646{
1647 {.mask = 0x00000017, .type = 0}
1648};
1649
Dave Jonese5524f32007-02-22 18:41:28 -05001650static const struct aper_size_info_8 intel_815_sizes[2] =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651{
1652 {64, 16384, 4, 0},
1653 {32, 8192, 3, 8},
1654};
1655
Dave Jonese5524f32007-02-22 18:41:28 -05001656static const struct aper_size_info_8 intel_8xx_sizes[7] =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657{
1658 {256, 65536, 6, 0},
1659 {128, 32768, 5, 32},
1660 {64, 16384, 4, 48},
1661 {32, 8192, 3, 56},
1662 {16, 4096, 2, 60},
1663 {8, 2048, 1, 62},
1664 {4, 1024, 0, 63}
1665};
1666
Dave Jonese5524f32007-02-22 18:41:28 -05001667static const struct aper_size_info_16 intel_generic_sizes[7] =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668{
1669 {256, 65536, 6, 0},
1670 {128, 32768, 5, 32},
1671 {64, 16384, 4, 48},
1672 {32, 8192, 3, 56},
1673 {16, 4096, 2, 60},
1674 {8, 2048, 1, 62},
1675 {4, 1024, 0, 63}
1676};
1677
Dave Jonese5524f32007-02-22 18:41:28 -05001678static const struct aper_size_info_8 intel_830mp_sizes[4] =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679{
1680 {256, 65536, 6, 0},
1681 {128, 32768, 5, 32},
1682 {64, 16384, 4, 48},
1683 {32, 8192, 3, 56}
1684};
1685
Dave Jonese5524f32007-02-22 18:41:28 -05001686static const struct agp_bridge_driver intel_generic_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687 .owner = THIS_MODULE,
1688 .aperture_sizes = intel_generic_sizes,
1689 .size_type = U16_APER_SIZE,
1690 .num_aperture_sizes = 7,
1691 .configure = intel_configure,
1692 .fetch_size = intel_fetch_size,
1693 .cleanup = intel_cleanup,
1694 .tlb_flush = intel_tlbflush,
1695 .mask_memory = agp_generic_mask_memory,
1696 .masks = intel_generic_masks,
1697 .agp_enable = agp_generic_enable,
1698 .cache_flush = global_cache_flush,
1699 .create_gatt_table = agp_generic_create_gatt_table,
1700 .free_gatt_table = agp_generic_free_gatt_table,
1701 .insert_memory = agp_generic_insert_memory,
1702 .remove_memory = agp_generic_remove_memory,
1703 .alloc_by_type = agp_generic_alloc_by_type,
1704 .free_by_type = agp_generic_free_by_type,
1705 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08001706 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08001708 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001709 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710};
1711
Dave Jonese5524f32007-02-22 18:41:28 -05001712static const struct agp_bridge_driver intel_810_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713 .owner = THIS_MODULE,
1714 .aperture_sizes = intel_i810_sizes,
1715 .size_type = FIXED_APER_SIZE,
1716 .num_aperture_sizes = 2,
Joe Perchesc7258012008-03-26 14:10:02 -07001717 .needs_scratch_page = true,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718 .configure = intel_i810_configure,
1719 .fetch_size = intel_i810_fetch_size,
1720 .cleanup = intel_i810_cleanup,
1721 .tlb_flush = intel_i810_tlbflush,
1722 .mask_memory = intel_i810_mask_memory,
1723 .masks = intel_i810_masks,
1724 .agp_enable = intel_i810_agp_enable,
1725 .cache_flush = global_cache_flush,
1726 .create_gatt_table = agp_generic_create_gatt_table,
1727 .free_gatt_table = agp_generic_free_gatt_table,
1728 .insert_memory = intel_i810_insert_entries,
1729 .remove_memory = intel_i810_remove_entries,
1730 .alloc_by_type = intel_i810_alloc_by_type,
1731 .free_by_type = intel_i810_free_by_type,
1732 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08001733 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08001735 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001736 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737};
1738
Dave Jonese5524f32007-02-22 18:41:28 -05001739static const struct agp_bridge_driver intel_815_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740 .owner = THIS_MODULE,
1741 .aperture_sizes = intel_815_sizes,
1742 .size_type = U8_APER_SIZE,
1743 .num_aperture_sizes = 2,
1744 .configure = intel_815_configure,
1745 .fetch_size = intel_815_fetch_size,
1746 .cleanup = intel_8xx_cleanup,
1747 .tlb_flush = intel_8xx_tlbflush,
1748 .mask_memory = agp_generic_mask_memory,
1749 .masks = intel_generic_masks,
1750 .agp_enable = agp_generic_enable,
1751 .cache_flush = global_cache_flush,
1752 .create_gatt_table = agp_generic_create_gatt_table,
1753 .free_gatt_table = agp_generic_free_gatt_table,
1754 .insert_memory = agp_generic_insert_memory,
1755 .remove_memory = agp_generic_remove_memory,
1756 .alloc_by_type = agp_generic_alloc_by_type,
1757 .free_by_type = agp_generic_free_by_type,
1758 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08001759 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08001761 .agp_destroy_pages = agp_generic_destroy_pages,
Dave Airlie62c96b92008-06-19 14:27:53 +10001762 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763};
1764
Dave Jonese5524f32007-02-22 18:41:28 -05001765static const struct agp_bridge_driver intel_830_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 .owner = THIS_MODULE,
1767 .aperture_sizes = intel_i830_sizes,
1768 .size_type = FIXED_APER_SIZE,
Dave Jonesc14635e2006-09-06 11:59:35 -04001769 .num_aperture_sizes = 4,
Joe Perchesc7258012008-03-26 14:10:02 -07001770 .needs_scratch_page = true,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771 .configure = intel_i830_configure,
1772 .fetch_size = intel_i830_fetch_size,
1773 .cleanup = intel_i830_cleanup,
1774 .tlb_flush = intel_i810_tlbflush,
1775 .mask_memory = intel_i810_mask_memory,
1776 .masks = intel_i810_masks,
1777 .agp_enable = intel_i810_agp_enable,
1778 .cache_flush = global_cache_flush,
1779 .create_gatt_table = intel_i830_create_gatt_table,
1780 .free_gatt_table = intel_i830_free_gatt_table,
1781 .insert_memory = intel_i830_insert_entries,
1782 .remove_memory = intel_i830_remove_entries,
1783 .alloc_by_type = intel_i830_alloc_by_type,
1784 .free_by_type = intel_i810_free_by_type,
1785 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08001786 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08001788 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001789 .agp_type_to_mask_type = intel_i830_type_to_mask_type,
Dave Airlie2162e6a2007-11-21 16:36:31 +10001790 .chipset_flush = intel_i830_chipset_flush,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791};
1792
Dave Jonese5524f32007-02-22 18:41:28 -05001793static const struct agp_bridge_driver intel_820_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 .owner = THIS_MODULE,
1795 .aperture_sizes = intel_8xx_sizes,
1796 .size_type = U8_APER_SIZE,
1797 .num_aperture_sizes = 7,
1798 .configure = intel_820_configure,
1799 .fetch_size = intel_8xx_fetch_size,
1800 .cleanup = intel_820_cleanup,
1801 .tlb_flush = intel_820_tlbflush,
1802 .mask_memory = agp_generic_mask_memory,
1803 .masks = intel_generic_masks,
1804 .agp_enable = agp_generic_enable,
1805 .cache_flush = global_cache_flush,
1806 .create_gatt_table = agp_generic_create_gatt_table,
1807 .free_gatt_table = agp_generic_free_gatt_table,
1808 .insert_memory = agp_generic_insert_memory,
1809 .remove_memory = agp_generic_remove_memory,
1810 .alloc_by_type = agp_generic_alloc_by_type,
1811 .free_by_type = agp_generic_free_by_type,
1812 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08001813 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08001815 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001816 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817};
1818
Dave Jonese5524f32007-02-22 18:41:28 -05001819static const struct agp_bridge_driver intel_830mp_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820 .owner = THIS_MODULE,
1821 .aperture_sizes = intel_830mp_sizes,
1822 .size_type = U8_APER_SIZE,
1823 .num_aperture_sizes = 4,
1824 .configure = intel_830mp_configure,
1825 .fetch_size = intel_8xx_fetch_size,
1826 .cleanup = intel_8xx_cleanup,
1827 .tlb_flush = intel_8xx_tlbflush,
1828 .mask_memory = agp_generic_mask_memory,
1829 .masks = intel_generic_masks,
1830 .agp_enable = agp_generic_enable,
1831 .cache_flush = global_cache_flush,
1832 .create_gatt_table = agp_generic_create_gatt_table,
1833 .free_gatt_table = agp_generic_free_gatt_table,
1834 .insert_memory = agp_generic_insert_memory,
1835 .remove_memory = agp_generic_remove_memory,
1836 .alloc_by_type = agp_generic_alloc_by_type,
1837 .free_by_type = agp_generic_free_by_type,
1838 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08001839 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08001841 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001842 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843};
1844
Dave Jonese5524f32007-02-22 18:41:28 -05001845static const struct agp_bridge_driver intel_840_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846 .owner = THIS_MODULE,
1847 .aperture_sizes = intel_8xx_sizes,
1848 .size_type = U8_APER_SIZE,
1849 .num_aperture_sizes = 7,
1850 .configure = intel_840_configure,
1851 .fetch_size = intel_8xx_fetch_size,
1852 .cleanup = intel_8xx_cleanup,
1853 .tlb_flush = intel_8xx_tlbflush,
1854 .mask_memory = agp_generic_mask_memory,
1855 .masks = intel_generic_masks,
1856 .agp_enable = agp_generic_enable,
1857 .cache_flush = global_cache_flush,
1858 .create_gatt_table = agp_generic_create_gatt_table,
1859 .free_gatt_table = agp_generic_free_gatt_table,
1860 .insert_memory = agp_generic_insert_memory,
1861 .remove_memory = agp_generic_remove_memory,
1862 .alloc_by_type = agp_generic_alloc_by_type,
1863 .free_by_type = agp_generic_free_by_type,
1864 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08001865 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08001867 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001868 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869};
1870
Dave Jonese5524f32007-02-22 18:41:28 -05001871static const struct agp_bridge_driver intel_845_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872 .owner = THIS_MODULE,
1873 .aperture_sizes = intel_8xx_sizes,
1874 .size_type = U8_APER_SIZE,
1875 .num_aperture_sizes = 7,
1876 .configure = intel_845_configure,
1877 .fetch_size = intel_8xx_fetch_size,
1878 .cleanup = intel_8xx_cleanup,
1879 .tlb_flush = intel_8xx_tlbflush,
1880 .mask_memory = agp_generic_mask_memory,
1881 .masks = intel_generic_masks,
1882 .agp_enable = agp_generic_enable,
1883 .cache_flush = global_cache_flush,
1884 .create_gatt_table = agp_generic_create_gatt_table,
1885 .free_gatt_table = agp_generic_free_gatt_table,
1886 .insert_memory = agp_generic_insert_memory,
1887 .remove_memory = agp_generic_remove_memory,
1888 .alloc_by_type = agp_generic_alloc_by_type,
1889 .free_by_type = agp_generic_free_by_type,
1890 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08001891 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08001893 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001894 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Dave Airlie2162e6a2007-11-21 16:36:31 +10001895 .chipset_flush = intel_i830_chipset_flush,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896};
1897
Dave Jonese5524f32007-02-22 18:41:28 -05001898static const struct agp_bridge_driver intel_850_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899 .owner = THIS_MODULE,
1900 .aperture_sizes = intel_8xx_sizes,
1901 .size_type = U8_APER_SIZE,
1902 .num_aperture_sizes = 7,
1903 .configure = intel_850_configure,
1904 .fetch_size = intel_8xx_fetch_size,
1905 .cleanup = intel_8xx_cleanup,
1906 .tlb_flush = intel_8xx_tlbflush,
1907 .mask_memory = agp_generic_mask_memory,
1908 .masks = intel_generic_masks,
1909 .agp_enable = agp_generic_enable,
1910 .cache_flush = global_cache_flush,
1911 .create_gatt_table = agp_generic_create_gatt_table,
1912 .free_gatt_table = agp_generic_free_gatt_table,
1913 .insert_memory = agp_generic_insert_memory,
1914 .remove_memory = agp_generic_remove_memory,
1915 .alloc_by_type = agp_generic_alloc_by_type,
1916 .free_by_type = agp_generic_free_by_type,
1917 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08001918 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08001920 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001921 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922};
1923
Dave Jonese5524f32007-02-22 18:41:28 -05001924static const struct agp_bridge_driver intel_860_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925 .owner = THIS_MODULE,
1926 .aperture_sizes = intel_8xx_sizes,
1927 .size_type = U8_APER_SIZE,
1928 .num_aperture_sizes = 7,
1929 .configure = intel_860_configure,
1930 .fetch_size = intel_8xx_fetch_size,
1931 .cleanup = intel_8xx_cleanup,
1932 .tlb_flush = intel_8xx_tlbflush,
1933 .mask_memory = agp_generic_mask_memory,
1934 .masks = intel_generic_masks,
1935 .agp_enable = agp_generic_enable,
1936 .cache_flush = global_cache_flush,
1937 .create_gatt_table = agp_generic_create_gatt_table,
1938 .free_gatt_table = agp_generic_free_gatt_table,
1939 .insert_memory = agp_generic_insert_memory,
1940 .remove_memory = agp_generic_remove_memory,
1941 .alloc_by_type = agp_generic_alloc_by_type,
1942 .free_by_type = agp_generic_free_by_type,
1943 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08001944 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08001946 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001947 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948};
1949
Dave Jonese5524f32007-02-22 18:41:28 -05001950static const struct agp_bridge_driver intel_915_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 .owner = THIS_MODULE,
1952 .aperture_sizes = intel_i830_sizes,
1953 .size_type = FIXED_APER_SIZE,
Dave Jonesc14635e2006-09-06 11:59:35 -04001954 .num_aperture_sizes = 4,
Joe Perchesc7258012008-03-26 14:10:02 -07001955 .needs_scratch_page = true,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956 .configure = intel_i915_configure,
Eric Anholtc41e0de2006-12-19 12:57:24 -08001957 .fetch_size = intel_i9xx_fetch_size,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958 .cleanup = intel_i915_cleanup,
1959 .tlb_flush = intel_i810_tlbflush,
1960 .mask_memory = intel_i810_mask_memory,
1961 .masks = intel_i810_masks,
1962 .agp_enable = intel_i810_agp_enable,
1963 .cache_flush = global_cache_flush,
1964 .create_gatt_table = intel_i915_create_gatt_table,
1965 .free_gatt_table = intel_i830_free_gatt_table,
1966 .insert_memory = intel_i915_insert_entries,
1967 .remove_memory = intel_i915_remove_entries,
1968 .alloc_by_type = intel_i830_alloc_by_type,
1969 .free_by_type = intel_i810_free_by_type,
1970 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08001971 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08001973 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001974 .agp_type_to_mask_type = intel_i830_type_to_mask_type,
Dave Airlie6c00a612007-10-29 18:06:10 +10001975 .chipset_flush = intel_i915_chipset_flush,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976};
1977
Dave Jonese5524f32007-02-22 18:41:28 -05001978static const struct agp_bridge_driver intel_i965_driver = {
Dave Airlie62c96b92008-06-19 14:27:53 +10001979 .owner = THIS_MODULE,
1980 .aperture_sizes = intel_i830_sizes,
1981 .size_type = FIXED_APER_SIZE,
1982 .num_aperture_sizes = 4,
1983 .needs_scratch_page = true,
Dave Airlie0e480e52008-06-19 14:57:31 +10001984 .configure = intel_i915_configure,
1985 .fetch_size = intel_i9xx_fetch_size,
Dave Airlie62c96b92008-06-19 14:27:53 +10001986 .cleanup = intel_i915_cleanup,
1987 .tlb_flush = intel_i810_tlbflush,
1988 .mask_memory = intel_i965_mask_memory,
1989 .masks = intel_i810_masks,
1990 .agp_enable = intel_i810_agp_enable,
1991 .cache_flush = global_cache_flush,
1992 .create_gatt_table = intel_i965_create_gatt_table,
1993 .free_gatt_table = intel_i830_free_gatt_table,
1994 .insert_memory = intel_i915_insert_entries,
1995 .remove_memory = intel_i915_remove_entries,
1996 .alloc_by_type = intel_i830_alloc_by_type,
1997 .free_by_type = intel_i810_free_by_type,
1998 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08001999 .agp_alloc_pages = agp_generic_alloc_pages,
Dave Airlie62c96b92008-06-19 14:27:53 +10002000 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08002001 .agp_destroy_pages = agp_generic_destroy_pages,
Dave Airlie62c96b92008-06-19 14:27:53 +10002002 .agp_type_to_mask_type = intel_i830_type_to_mask_type,
Dave Airlie6c00a612007-10-29 18:06:10 +10002003 .chipset_flush = intel_i915_chipset_flush,
Eric Anholt65c25aa2006-09-06 11:57:18 -04002004};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005
Dave Jonese5524f32007-02-22 18:41:28 -05002006static const struct agp_bridge_driver intel_7505_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002007 .owner = THIS_MODULE,
2008 .aperture_sizes = intel_8xx_sizes,
2009 .size_type = U8_APER_SIZE,
2010 .num_aperture_sizes = 7,
2011 .configure = intel_7505_configure,
2012 .fetch_size = intel_8xx_fetch_size,
2013 .cleanup = intel_8xx_cleanup,
2014 .tlb_flush = intel_8xx_tlbflush,
2015 .mask_memory = agp_generic_mask_memory,
2016 .masks = intel_generic_masks,
2017 .agp_enable = agp_generic_enable,
2018 .cache_flush = global_cache_flush,
2019 .create_gatt_table = agp_generic_create_gatt_table,
2020 .free_gatt_table = agp_generic_free_gatt_table,
2021 .insert_memory = agp_generic_insert_memory,
2022 .remove_memory = agp_generic_remove_memory,
2023 .alloc_by_type = agp_generic_alloc_by_type,
2024 .free_by_type = agp_generic_free_by_type,
2025 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08002026 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08002028 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01002029 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030};
2031
Wang Zhenyu874808c62007-06-06 11:16:25 +08002032static const struct agp_bridge_driver intel_g33_driver = {
Dave Airlie62c96b92008-06-19 14:27:53 +10002033 .owner = THIS_MODULE,
2034 .aperture_sizes = intel_i830_sizes,
2035 .size_type = FIXED_APER_SIZE,
2036 .num_aperture_sizes = 4,
2037 .needs_scratch_page = true,
2038 .configure = intel_i915_configure,
2039 .fetch_size = intel_i9xx_fetch_size,
2040 .cleanup = intel_i915_cleanup,
2041 .tlb_flush = intel_i810_tlbflush,
2042 .mask_memory = intel_i965_mask_memory,
2043 .masks = intel_i810_masks,
2044 .agp_enable = intel_i810_agp_enable,
2045 .cache_flush = global_cache_flush,
2046 .create_gatt_table = intel_i915_create_gatt_table,
2047 .free_gatt_table = intel_i830_free_gatt_table,
2048 .insert_memory = intel_i915_insert_entries,
2049 .remove_memory = intel_i915_remove_entries,
2050 .alloc_by_type = intel_i830_alloc_by_type,
2051 .free_by_type = intel_i810_free_by_type,
2052 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08002053 .agp_alloc_pages = agp_generic_alloc_pages,
Dave Airlie62c96b92008-06-19 14:27:53 +10002054 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08002055 .agp_destroy_pages = agp_generic_destroy_pages,
Dave Airlie62c96b92008-06-19 14:27:53 +10002056 .agp_type_to_mask_type = intel_i830_type_to_mask_type,
Dave Airlie6c00a612007-10-29 18:06:10 +10002057 .chipset_flush = intel_i915_chipset_flush,
Wang Zhenyu874808c62007-06-06 11:16:25 +08002058};
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002059
2060static int find_gmch(u16 device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061{
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002062 struct pci_dev *gmch_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002064 gmch_device = pci_get_device(PCI_VENDOR_ID_INTEL, device, NULL);
2065 if (gmch_device && PCI_FUNC(gmch_device->devfn) != 0) {
2066 gmch_device = pci_get_device(PCI_VENDOR_ID_INTEL,
Dave Airlief011ae72008-01-25 11:23:04 +10002067 device, gmch_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068 }
2069
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002070 if (!gmch_device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071 return 0;
2072
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002073 intel_private.pcidev = gmch_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074 return 1;
2075}
2076
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002077/* Table to describe Intel GMCH and AGP/PCIE GART drivers. At least one of
2078 * driver and gmch_driver must be non-null, and find_gmch will determine
2079 * which one should be used if a gmch_chip_id is present.
2080 */
2081static const struct intel_driver_description {
2082 unsigned int chip_id;
2083 unsigned int gmch_chip_id;
Wang Zhenyu88889852007-06-14 10:01:04 +08002084 unsigned int multi_gmch_chip; /* if we have more gfx chip type on this HB. */
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002085 char *name;
2086 const struct agp_bridge_driver *driver;
2087 const struct agp_bridge_driver *gmch_driver;
2088} intel_agp_chipsets[] = {
Wang Zhenyu88889852007-06-14 10:01:04 +08002089 { PCI_DEVICE_ID_INTEL_82443LX_0, 0, 0, "440LX", &intel_generic_driver, NULL },
2090 { PCI_DEVICE_ID_INTEL_82443BX_0, 0, 0, "440BX", &intel_generic_driver, NULL },
2091 { PCI_DEVICE_ID_INTEL_82443GX_0, 0, 0, "440GX", &intel_generic_driver, NULL },
2092 { PCI_DEVICE_ID_INTEL_82810_MC1, PCI_DEVICE_ID_INTEL_82810_IG1, 0, "i810",
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002093 NULL, &intel_810_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002094 { PCI_DEVICE_ID_INTEL_82810_MC3, PCI_DEVICE_ID_INTEL_82810_IG3, 0, "i810",
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002095 NULL, &intel_810_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002096 { PCI_DEVICE_ID_INTEL_82810E_MC, PCI_DEVICE_ID_INTEL_82810E_IG, 0, "i810",
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002097 NULL, &intel_810_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002098 { PCI_DEVICE_ID_INTEL_82815_MC, PCI_DEVICE_ID_INTEL_82815_CGC, 0, "i815",
2099 &intel_815_driver, &intel_810_driver },
2100 { PCI_DEVICE_ID_INTEL_82820_HB, 0, 0, "i820", &intel_820_driver, NULL },
2101 { PCI_DEVICE_ID_INTEL_82820_UP_HB, 0, 0, "i820", &intel_820_driver, NULL },
2102 { PCI_DEVICE_ID_INTEL_82830_HB, PCI_DEVICE_ID_INTEL_82830_CGC, 0, "830M",
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002103 &intel_830mp_driver, &intel_830_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002104 { PCI_DEVICE_ID_INTEL_82840_HB, 0, 0, "i840", &intel_840_driver, NULL },
2105 { PCI_DEVICE_ID_INTEL_82845_HB, 0, 0, "845G", &intel_845_driver, NULL },
2106 { PCI_DEVICE_ID_INTEL_82845G_HB, PCI_DEVICE_ID_INTEL_82845G_IG, 0, "830M",
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002107 &intel_845_driver, &intel_830_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002108 { PCI_DEVICE_ID_INTEL_82850_HB, 0, 0, "i850", &intel_850_driver, NULL },
2109 { PCI_DEVICE_ID_INTEL_82855PM_HB, 0, 0, "855PM", &intel_845_driver, NULL },
2110 { PCI_DEVICE_ID_INTEL_82855GM_HB, PCI_DEVICE_ID_INTEL_82855GM_IG, 0, "855GM",
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002111 &intel_845_driver, &intel_830_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002112 { PCI_DEVICE_ID_INTEL_82860_HB, 0, 0, "i860", &intel_860_driver, NULL },
2113 { PCI_DEVICE_ID_INTEL_82865_HB, PCI_DEVICE_ID_INTEL_82865_IG, 0, "865",
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002114 &intel_845_driver, &intel_830_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002115 { PCI_DEVICE_ID_INTEL_82875_HB, 0, 0, "i875", &intel_845_driver, NULL },
Carlos Martíne914a362008-01-24 10:34:09 +10002116 { PCI_DEVICE_ID_INTEL_E7221_HB, PCI_DEVICE_ID_INTEL_E7221_IG, 0, "E7221 (i915)",
2117 NULL, &intel_915_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002118 { PCI_DEVICE_ID_INTEL_82915G_HB, PCI_DEVICE_ID_INTEL_82915G_IG, 0, "915G",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002119 NULL, &intel_915_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002120 { PCI_DEVICE_ID_INTEL_82915GM_HB, PCI_DEVICE_ID_INTEL_82915GM_IG, 0, "915GM",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002121 NULL, &intel_915_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002122 { PCI_DEVICE_ID_INTEL_82945G_HB, PCI_DEVICE_ID_INTEL_82945G_IG, 0, "945G",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002123 NULL, &intel_915_driver },
Zhenyu Wangdde47872007-07-26 09:18:09 +08002124 { PCI_DEVICE_ID_INTEL_82945GM_HB, PCI_DEVICE_ID_INTEL_82945GM_IG, 0, "945GM",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002125 NULL, &intel_915_driver },
Zhenyu Wangdde47872007-07-26 09:18:09 +08002126 { PCI_DEVICE_ID_INTEL_82945GME_HB, PCI_DEVICE_ID_INTEL_82945GME_IG, 0, "945GME",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002127 NULL, &intel_915_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002128 { PCI_DEVICE_ID_INTEL_82946GZ_HB, PCI_DEVICE_ID_INTEL_82946GZ_IG, 0, "946GZ",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002129 NULL, &intel_i965_driver },
Zhenyu Wang9119f852008-01-23 15:49:26 +10002130 { PCI_DEVICE_ID_INTEL_82G35_HB, PCI_DEVICE_ID_INTEL_82G35_IG, 0, "G35",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002131 NULL, &intel_i965_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002132 { PCI_DEVICE_ID_INTEL_82965Q_HB, PCI_DEVICE_ID_INTEL_82965Q_IG, 0, "965Q",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002133 NULL, &intel_i965_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002134 { PCI_DEVICE_ID_INTEL_82965G_HB, PCI_DEVICE_ID_INTEL_82965G_IG, 0, "965G",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002135 NULL, &intel_i965_driver },
Zhenyu Wangdde47872007-07-26 09:18:09 +08002136 { PCI_DEVICE_ID_INTEL_82965GM_HB, PCI_DEVICE_ID_INTEL_82965GM_IG, 0, "965GM",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002137 NULL, &intel_i965_driver },
Zhenyu Wangdde47872007-07-26 09:18:09 +08002138 { PCI_DEVICE_ID_INTEL_82965GME_HB, PCI_DEVICE_ID_INTEL_82965GME_IG, 0, "965GME/GLE",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002139 NULL, &intel_i965_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002140 { PCI_DEVICE_ID_INTEL_7505_0, 0, 0, "E7505", &intel_7505_driver, NULL },
2141 { PCI_DEVICE_ID_INTEL_7205_0, 0, 0, "E7205", &intel_7505_driver, NULL },
2142 { PCI_DEVICE_ID_INTEL_G33_HB, PCI_DEVICE_ID_INTEL_G33_IG, 0, "G33",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002143 NULL, &intel_g33_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002144 { PCI_DEVICE_ID_INTEL_Q35_HB, PCI_DEVICE_ID_INTEL_Q35_IG, 0, "Q35",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002145 NULL, &intel_g33_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002146 { PCI_DEVICE_ID_INTEL_Q33_HB, PCI_DEVICE_ID_INTEL_Q33_IG, 0, "Q33",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002147 NULL, &intel_g33_driver },
Zhenyu Wang4e8b6e22008-01-23 14:54:37 +10002148 { PCI_DEVICE_ID_INTEL_IGD_HB, PCI_DEVICE_ID_INTEL_IGD_IG, 0,
2149 "Intel Integrated Graphics Device", NULL, &intel_i965_driver },
Zhenyu Wang25ce77a2008-06-19 14:17:58 +10002150 { PCI_DEVICE_ID_INTEL_IGD_E_HB, PCI_DEVICE_ID_INTEL_IGD_E_IG, 0,
2151 "Intel Integrated Graphics Device", NULL, &intel_i965_driver },
2152 { PCI_DEVICE_ID_INTEL_Q45_HB, PCI_DEVICE_ID_INTEL_Q45_IG, 0,
2153 "Q45/Q43", NULL, &intel_i965_driver },
2154 { PCI_DEVICE_ID_INTEL_G45_HB, PCI_DEVICE_ID_INTEL_G45_IG, 0,
2155 "G45/G43", NULL, &intel_i965_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002156 { 0, 0, 0, NULL, NULL, NULL }
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002157};
2158
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159static int __devinit agp_intel_probe(struct pci_dev *pdev,
2160 const struct pci_device_id *ent)
2161{
2162 struct agp_bridge_data *bridge;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163 u8 cap_ptr = 0;
2164 struct resource *r;
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002165 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166
2167 cap_ptr = pci_find_capability(pdev, PCI_CAP_ID_AGP);
2168
2169 bridge = agp_alloc_bridge();
2170 if (!bridge)
2171 return -ENOMEM;
2172
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002173 for (i = 0; intel_agp_chipsets[i].name != NULL; i++) {
2174 /* In case that multiple models of gfx chip may
2175 stand on same host bridge type, this can be
2176 sure we detect the right IGD. */
Wang Zhenyu88889852007-06-14 10:01:04 +08002177 if (pdev->device == intel_agp_chipsets[i].chip_id) {
2178 if ((intel_agp_chipsets[i].gmch_chip_id != 0) &&
2179 find_gmch(intel_agp_chipsets[i].gmch_chip_id)) {
2180 bridge->driver =
2181 intel_agp_chipsets[i].gmch_driver;
2182 break;
2183 } else if (intel_agp_chipsets[i].multi_gmch_chip) {
2184 continue;
2185 } else {
2186 bridge->driver = intel_agp_chipsets[i].driver;
2187 break;
2188 }
2189 }
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002190 }
2191
2192 if (intel_agp_chipsets[i].name == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 if (cap_ptr)
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002194 printk(KERN_WARNING PFX "Unsupported Intel chipset"
Dave Airlief011ae72008-01-25 11:23:04 +10002195 "(device id: %04x)\n", pdev->device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196 agp_put_bridge(bridge);
2197 return -ENODEV;
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002198 }
2199
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002200 if (bridge->driver == NULL) {
Wang Zhenyu47d46372007-06-21 13:43:18 +08002201 /* bridge has no AGP and no IGD detected */
2202 if (cap_ptr)
2203 printk(KERN_WARNING PFX "Failed to find bridge device "
2204 "(chip_id: %04x)\n",
2205 intel_agp_chipsets[i].gmch_chip_id);
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002206 agp_put_bridge(bridge);
2207 return -ENODEV;
Dave Airlief011ae72008-01-25 11:23:04 +10002208 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209
2210 bridge->dev = pdev;
2211 bridge->capndx = cap_ptr;
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08002212 bridge->dev_private_data = &intel_private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002214 printk(KERN_INFO PFX "Detected an Intel %s Chipset.\n",
2215 intel_agp_chipsets[i].name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216
2217 /*
2218 * The following fixes the case where the BIOS has "forgotten" to
2219 * provide an address range for the GART.
2220 * 20030610 - hamish@zot.org
2221 */
2222 r = &pdev->resource[0];
2223 if (!r->start && r->end) {
Dave Jones6a92a4e2006-02-28 00:54:25 -05002224 if (pci_assign_resource(pdev, 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225 printk(KERN_ERR PFX "could not assign resource 0\n");
2226 agp_put_bridge(bridge);
2227 return -ENODEV;
2228 }
2229 }
2230
2231 /*
2232 * If the device has not been properly setup, the following will catch
2233 * the problem and should stop the system from crashing.
2234 * 20030610 - hamish@zot.org
2235 */
2236 if (pci_enable_device(pdev)) {
2237 printk(KERN_ERR PFX "Unable to Enable PCI device\n");
2238 agp_put_bridge(bridge);
2239 return -ENODEV;
2240 }
2241
2242 /* Fill in the mode register */
2243 if (cap_ptr) {
2244 pci_read_config_dword(pdev,
2245 bridge->capndx+PCI_AGP_STATUS,
2246 &bridge->mode);
2247 }
2248
2249 pci_set_drvdata(pdev, bridge);
2250 return agp_add_bridge(bridge);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251}
2252
2253static void __devexit agp_intel_remove(struct pci_dev *pdev)
2254{
2255 struct agp_bridge_data *bridge = pci_get_drvdata(pdev);
2256
2257 agp_remove_bridge(bridge);
2258
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08002259 if (intel_private.pcidev)
2260 pci_dev_put(intel_private.pcidev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261
2262 agp_put_bridge(bridge);
2263}
2264
Alexey Dobriyan85be7d62006-08-12 02:02:02 +04002265#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266static int agp_intel_resume(struct pci_dev *pdev)
2267{
2268 struct agp_bridge_data *bridge = pci_get_drvdata(pdev);
2269
2270 pci_restore_state(pdev);
2271
Wang Zhenyu4b953202007-01-17 11:07:54 +08002272 /* We should restore our graphics device's config space,
2273 * as host bridge (00:00) resumes before graphics device (02:00),
2274 * then our access to its pci space can work right.
2275 */
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08002276 if (intel_private.pcidev)
2277 pci_restore_state(intel_private.pcidev);
Wang Zhenyu4b953202007-01-17 11:07:54 +08002278
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279 if (bridge->driver == &intel_generic_driver)
2280 intel_configure();
2281 else if (bridge->driver == &intel_850_driver)
2282 intel_850_configure();
2283 else if (bridge->driver == &intel_845_driver)
2284 intel_845_configure();
2285 else if (bridge->driver == &intel_830mp_driver)
2286 intel_830mp_configure();
2287 else if (bridge->driver == &intel_915_driver)
2288 intel_i915_configure();
2289 else if (bridge->driver == &intel_830_driver)
2290 intel_i830_configure();
2291 else if (bridge->driver == &intel_810_driver)
2292 intel_i810_configure();
Dave Jones08da3f42006-09-10 21:09:26 -04002293 else if (bridge->driver == &intel_i965_driver)
2294 intel_i915_configure();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295
2296 return 0;
2297}
Alexey Dobriyan85be7d62006-08-12 02:02:02 +04002298#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299
2300static struct pci_device_id agp_intel_pci_table[] = {
2301#define ID(x) \
2302 { \
2303 .class = (PCI_CLASS_BRIDGE_HOST << 8), \
2304 .class_mask = ~0, \
2305 .vendor = PCI_VENDOR_ID_INTEL, \
2306 .device = x, \
2307 .subvendor = PCI_ANY_ID, \
2308 .subdevice = PCI_ANY_ID, \
2309 }
2310 ID(PCI_DEVICE_ID_INTEL_82443LX_0),
2311 ID(PCI_DEVICE_ID_INTEL_82443BX_0),
2312 ID(PCI_DEVICE_ID_INTEL_82443GX_0),
2313 ID(PCI_DEVICE_ID_INTEL_82810_MC1),
2314 ID(PCI_DEVICE_ID_INTEL_82810_MC3),
2315 ID(PCI_DEVICE_ID_INTEL_82810E_MC),
2316 ID(PCI_DEVICE_ID_INTEL_82815_MC),
2317 ID(PCI_DEVICE_ID_INTEL_82820_HB),
2318 ID(PCI_DEVICE_ID_INTEL_82820_UP_HB),
2319 ID(PCI_DEVICE_ID_INTEL_82830_HB),
2320 ID(PCI_DEVICE_ID_INTEL_82840_HB),
2321 ID(PCI_DEVICE_ID_INTEL_82845_HB),
2322 ID(PCI_DEVICE_ID_INTEL_82845G_HB),
2323 ID(PCI_DEVICE_ID_INTEL_82850_HB),
2324 ID(PCI_DEVICE_ID_INTEL_82855PM_HB),
2325 ID(PCI_DEVICE_ID_INTEL_82855GM_HB),
2326 ID(PCI_DEVICE_ID_INTEL_82860_HB),
2327 ID(PCI_DEVICE_ID_INTEL_82865_HB),
2328 ID(PCI_DEVICE_ID_INTEL_82875_HB),
2329 ID(PCI_DEVICE_ID_INTEL_7505_0),
2330 ID(PCI_DEVICE_ID_INTEL_7205_0),
Carlos Martíne914a362008-01-24 10:34:09 +10002331 ID(PCI_DEVICE_ID_INTEL_E7221_HB),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 ID(PCI_DEVICE_ID_INTEL_82915G_HB),
2333 ID(PCI_DEVICE_ID_INTEL_82915GM_HB),
Alan Hourihaned0de98f2005-05-31 19:50:49 +01002334 ID(PCI_DEVICE_ID_INTEL_82945G_HB),
Alan Hourihane3b0e8ea2006-01-19 14:08:40 +00002335 ID(PCI_DEVICE_ID_INTEL_82945GM_HB),
Zhenyu Wangdde47872007-07-26 09:18:09 +08002336 ID(PCI_DEVICE_ID_INTEL_82945GME_HB),
Eric Anholt65c25aa2006-09-06 11:57:18 -04002337 ID(PCI_DEVICE_ID_INTEL_82946GZ_HB),
Zhenyu Wang9119f852008-01-23 15:49:26 +10002338 ID(PCI_DEVICE_ID_INTEL_82G35_HB),
Eric Anholt65c25aa2006-09-06 11:57:18 -04002339 ID(PCI_DEVICE_ID_INTEL_82965Q_HB),
2340 ID(PCI_DEVICE_ID_INTEL_82965G_HB),
Wang Zhenyu4598af32007-04-09 08:51:36 +08002341 ID(PCI_DEVICE_ID_INTEL_82965GM_HB),
Zhenyu Wangdde47872007-07-26 09:18:09 +08002342 ID(PCI_DEVICE_ID_INTEL_82965GME_HB),
Wang Zhenyu874808c62007-06-06 11:16:25 +08002343 ID(PCI_DEVICE_ID_INTEL_G33_HB),
2344 ID(PCI_DEVICE_ID_INTEL_Q35_HB),
2345 ID(PCI_DEVICE_ID_INTEL_Q33_HB),
Zhenyu Wang4e8b6e22008-01-23 14:54:37 +10002346 ID(PCI_DEVICE_ID_INTEL_IGD_HB),
Zhenyu Wang25ce77a2008-06-19 14:17:58 +10002347 ID(PCI_DEVICE_ID_INTEL_IGD_E_HB),
2348 ID(PCI_DEVICE_ID_INTEL_Q45_HB),
2349 ID(PCI_DEVICE_ID_INTEL_G45_HB),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350 { }
2351};
2352
2353MODULE_DEVICE_TABLE(pci, agp_intel_pci_table);
2354
2355static struct pci_driver agp_intel_pci_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 .name = "agpgart-intel",
2357 .id_table = agp_intel_pci_table,
2358 .probe = agp_intel_probe,
2359 .remove = __devexit_p(agp_intel_remove),
Alexey Dobriyan85be7d62006-08-12 02:02:02 +04002360#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 .resume = agp_intel_resume,
Alexey Dobriyan85be7d62006-08-12 02:02:02 +04002362#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363};
2364
2365static int __init agp_intel_init(void)
2366{
2367 if (agp_off)
2368 return -EINVAL;
2369 return pci_register_driver(&agp_intel_pci_driver);
2370}
2371
2372static void __exit agp_intel_cleanup(void)
2373{
2374 pci_unregister_driver(&agp_intel_pci_driver);
2375}
2376
2377module_init(agp_intel_init);
2378module_exit(agp_intel_cleanup);
2379
2380MODULE_AUTHOR("Dave Jones <davej@codemonkey.org.uk>");
2381MODULE_LICENSE("GPL and additional rights");