blob: 35977bfb6999b90d85c5d445d7f713c513d401e5 [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
Shaohua Li21778322009-02-23 15:19:16 +080029#define PCI_DEVICE_ID_INTEL_IGDGM_HB 0xA010
30#define PCI_DEVICE_ID_INTEL_IGDGM_IG 0xA011
31#define PCI_DEVICE_ID_INTEL_IGDG_HB 0xA000
32#define PCI_DEVICE_ID_INTEL_IGDG_IG 0xA001
Wang Zhenyu874808c62007-06-06 11:16:25 +080033#define PCI_DEVICE_ID_INTEL_G33_HB 0x29C0
34#define PCI_DEVICE_ID_INTEL_G33_IG 0x29C2
35#define PCI_DEVICE_ID_INTEL_Q35_HB 0x29B0
36#define PCI_DEVICE_ID_INTEL_Q35_IG 0x29B2
37#define PCI_DEVICE_ID_INTEL_Q33_HB 0x29D0
38#define PCI_DEVICE_ID_INTEL_Q33_IG 0x29D2
Zhenyu Wang99d32bd2008-07-30 12:26:50 -070039#define PCI_DEVICE_ID_INTEL_GM45_HB 0x2A40
40#define PCI_DEVICE_ID_INTEL_GM45_IG 0x2A42
Zhenyu Wang25ce77a2008-06-19 14:17:58 +100041#define PCI_DEVICE_ID_INTEL_IGD_E_HB 0x2E00
42#define PCI_DEVICE_ID_INTEL_IGD_E_IG 0x2E02
43#define PCI_DEVICE_ID_INTEL_Q45_HB 0x2E10
44#define PCI_DEVICE_ID_INTEL_Q45_IG 0x2E12
45#define PCI_DEVICE_ID_INTEL_G45_HB 0x2E20
46#define PCI_DEVICE_ID_INTEL_G45_IG 0x2E22
Zhenyu Wanga50ccc62008-11-17 14:39:00 +080047#define PCI_DEVICE_ID_INTEL_G41_HB 0x2E30
48#define PCI_DEVICE_ID_INTEL_G41_IG 0x2E32
Zhenyu Wang32cb0552009-06-05 15:38:36 +080049#define PCI_DEVICE_ID_INTEL_IGDNG_D_HB 0x0040
50#define PCI_DEVICE_ID_INTEL_IGDNG_D_IG 0x0042
51#define PCI_DEVICE_ID_INTEL_IGDNG_M_HB 0x0044
52#define PCI_DEVICE_ID_INTEL_IGDNG_M_IG 0x0046
Eric Anholt65c25aa2006-09-06 11:57:18 -040053
Dave Airlief011ae72008-01-25 11:23:04 +100054/* cover 915 and 945 variants */
55#define IS_I915 (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_E7221_HB || \
56 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82915G_HB || \
57 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82915GM_HB || \
58 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82945G_HB || \
59 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82945GM_HB || \
60 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82945GME_HB)
61
Eric Anholt65c25aa2006-09-06 11:57:18 -040062#define IS_I965 (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82946GZ_HB || \
Dave Airlief011ae72008-01-25 11:23:04 +100063 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82G35_HB || \
64 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965Q_HB || \
65 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965G_HB || \
66 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965GM_HB || \
Eric Anholt82e14a62008-10-14 11:28:58 -070067 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965GME_HB)
Eric Anholt65c25aa2006-09-06 11:57:18 -040068
Wang Zhenyu874808c62007-06-06 11:16:25 +080069#define IS_G33 (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_G33_HB || \
70 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_Q35_HB || \
Shaohua Li21778322009-02-23 15:19:16 +080071 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_Q33_HB || \
72 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IGDGM_HB || \
73 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IGDG_HB)
74
75#define IS_IGD (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IGDGM_HB || \
76 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IGDG_HB)
Eric Anholt65c25aa2006-09-06 11:57:18 -040077
Zhenyu Wang25ce77a2008-06-19 14:17:58 +100078#define IS_G4X (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IGD_E_HB || \
79 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_Q45_HB || \
Eric Anholt82e14a62008-10-14 11:28:58 -070080 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_G45_HB || \
Zhenyu Wanga50ccc62008-11-17 14:39:00 +080081 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_GM45_HB || \
Zhenyu Wang32cb0552009-06-05 15:38:36 +080082 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_G41_HB || \
83 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IGDNG_D_HB || \
84 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IGDNG_M_HB)
Zhenyu Wang25ce77a2008-06-19 14:17:58 +100085
Thomas Hellstroma030ce42007-01-23 10:33:43 +010086extern int agp_memory_reserved;
87
88
Linus Torvalds1da177e2005-04-16 15:20:36 -070089/* Intel 815 register */
90#define INTEL_815_APCONT 0x51
91#define INTEL_815_ATTBASE_MASK ~0x1FFFFFFF
92
93/* Intel i820 registers */
94#define INTEL_I820_RDCR 0x51
95#define INTEL_I820_ERRSTS 0xc8
96
97/* Intel i840 registers */
98#define INTEL_I840_MCHCFG 0x50
99#define INTEL_I840_ERRSTS 0xc8
100
101/* Intel i850 registers */
102#define INTEL_I850_MCHCFG 0x50
103#define INTEL_I850_ERRSTS 0xc8
104
105/* intel 915G registers */
106#define I915_GMADDR 0x18
107#define I915_MMADDR 0x10
108#define I915_PTEADDR 0x1C
109#define I915_GMCH_GMS_STOLEN_48M (0x6 << 4)
110#define I915_GMCH_GMS_STOLEN_64M (0x7 << 4)
Zhenyu Wang25ce77a2008-06-19 14:17:58 +1000111#define G33_GMCH_GMS_STOLEN_128M (0x8 << 4)
112#define G33_GMCH_GMS_STOLEN_256M (0x9 << 4)
113#define INTEL_GMCH_GMS_STOLEN_96M (0xa << 4)
114#define INTEL_GMCH_GMS_STOLEN_160M (0xb << 4)
115#define INTEL_GMCH_GMS_STOLEN_224M (0xc << 4)
116#define INTEL_GMCH_GMS_STOLEN_352M (0xd << 4)
117
Dave Airlie6c00a612007-10-29 18:06:10 +1000118#define I915_IFPADDR 0x60
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
Eric Anholt65c25aa2006-09-06 11:57:18 -0400120/* Intel 965G registers */
121#define I965_MSAC 0x62
Dave Airlie6c00a612007-10-29 18:06:10 +1000122#define I965_IFPADDR 0x70
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
124/* Intel 7505 registers */
125#define INTEL_I7505_APSIZE 0x74
126#define INTEL_I7505_NCAPID 0x60
127#define INTEL_I7505_NISTAT 0x6c
128#define INTEL_I7505_ATTBASE 0x78
129#define INTEL_I7505_ERRSTS 0x42
130#define INTEL_I7505_AGPCTRL 0x70
131#define INTEL_I7505_MCHCFG 0x50
132
Dave Jonese5524f32007-02-22 18:41:28 -0500133static const struct aper_size_info_fixed intel_i810_sizes[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134{
135 {64, 16384, 4},
136 /* The 32M mode still requires a 64k gatt */
137 {32, 8192, 4}
138};
139
140#define AGP_DCACHE_MEMORY 1
141#define AGP_PHYS_MEMORY 2
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100142#define INTEL_AGP_CACHED_MEMORY 3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
144static struct gatt_mask intel_i810_masks[] =
145{
146 {.mask = I810_PTE_VALID, .type = 0},
147 {.mask = (I810_PTE_VALID | I810_PTE_LOCAL), .type = AGP_DCACHE_MEMORY},
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100148 {.mask = I810_PTE_VALID, .type = 0},
149 {.mask = I810_PTE_VALID | I830_PTE_SYSTEM_CACHED,
150 .type = INTEL_AGP_CACHED_MEMORY}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151};
152
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800153static struct _intel_private {
154 struct pci_dev *pcidev; /* device one */
155 u8 __iomem *registers;
156 u32 __iomem *gtt; /* I915G */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 int num_dcache_entries;
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800158 /* gtt_entries is the number of gtt entries that are already mapped
159 * to stolen memory. Stolen memory is larger than the memory mapped
160 * through gtt_entries, as it includes some reserved space for the BIOS
161 * popup and for the GTT.
162 */
163 int gtt_entries; /* i830+ */
Dave Airlie2162e6a2007-11-21 16:36:31 +1000164 union {
165 void __iomem *i9xx_flush_page;
166 void *i8xx_flush_page;
167 };
168 struct page *i8xx_page;
Dave Airlie6c00a612007-10-29 18:06:10 +1000169 struct resource ifp_resource;
Dave Airlie4d64dd92008-01-23 15:34:29 +1000170 int resource_valid;
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800171} intel_private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
173static int intel_i810_fetch_size(void)
174{
175 u32 smram_miscc;
176 struct aper_size_info_fixed *values;
177
178 pci_read_config_dword(agp_bridge->dev, I810_SMRAM_MISCC, &smram_miscc);
179 values = A_SIZE_FIX(agp_bridge->driver->aperture_sizes);
180
181 if ((smram_miscc & I810_GMS) == I810_GMS_DISABLE) {
Bjorn Helgaase3cf6952008-07-30 12:26:51 -0700182 dev_warn(&agp_bridge->dev->dev, "i810 is disabled\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 return 0;
184 }
185 if ((smram_miscc & I810_GFX_MEM_WIN_SIZE) == I810_GFX_MEM_WIN_32M) {
186 agp_bridge->previous_size =
187 agp_bridge->current_size = (void *) (values + 1);
188 agp_bridge->aperture_size_idx = 1;
189 return values[1].size;
190 } else {
191 agp_bridge->previous_size =
192 agp_bridge->current_size = (void *) (values);
193 agp_bridge->aperture_size_idx = 0;
194 return values[0].size;
195 }
196
197 return 0;
198}
199
200static int intel_i810_configure(void)
201{
202 struct aper_size_info_fixed *current_size;
203 u32 temp;
204 int i;
205
206 current_size = A_SIZE_FIX(agp_bridge->current_size);
207
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800208 if (!intel_private.registers) {
209 pci_read_config_dword(intel_private.pcidev, I810_MMADDR, &temp);
Dave Jonese4ac5e42007-02-04 17:37:42 -0500210 temp &= 0xfff80000;
211
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800212 intel_private.registers = ioremap(temp, 128 * 4096);
213 if (!intel_private.registers) {
Bjorn Helgaase3cf6952008-07-30 12:26:51 -0700214 dev_err(&intel_private.pcidev->dev,
215 "can't remap memory\n");
Dave Jonese4ac5e42007-02-04 17:37:42 -0500216 return -ENOMEM;
217 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 }
219
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800220 if ((readl(intel_private.registers+I810_DRAM_CTL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 & I810_DRAM_ROW_0) == I810_DRAM_ROW_0_SDRAM) {
222 /* This will need to be dynamically assigned */
Bjorn Helgaase3cf6952008-07-30 12:26:51 -0700223 dev_info(&intel_private.pcidev->dev,
224 "detected 4MB dedicated video ram\n");
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800225 intel_private.num_dcache_entries = 1024;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 }
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800227 pci_read_config_dword(intel_private.pcidev, I810_GMADDR, &temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800229 writel(agp_bridge->gatt_bus_addr | I810_PGETBL_ENABLED, intel_private.registers+I810_PGETBL_CTL);
230 readl(intel_private.registers+I810_PGETBL_CTL); /* PCI Posting. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
232 if (agp_bridge->driver->needs_scratch_page) {
233 for (i = 0; i < current_size->num_entries; i++) {
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800234 writel(agp_bridge->scratch_page, intel_private.registers+I810_PTE_BASE+(i*4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 }
Keith Packard44d49442008-10-14 17:18:45 -0700236 readl(intel_private.registers+I810_PTE_BASE+((i-1)*4)); /* PCI posting. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 }
238 global_cache_flush();
239 return 0;
240}
241
242static void intel_i810_cleanup(void)
243{
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800244 writel(0, intel_private.registers+I810_PGETBL_CTL);
245 readl(intel_private.registers); /* PCI Posting. */
246 iounmap(intel_private.registers);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247}
248
249static void intel_i810_tlbflush(struct agp_memory *mem)
250{
251 return;
252}
253
254static void intel_i810_agp_enable(struct agp_bridge_data *bridge, u32 mode)
255{
256 return;
257}
258
259/* Exists to support ARGB cursors */
Dave Airlie07613ba2009-06-12 14:11:41 +1000260static struct page *i8xx_alloc_pages(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261{
Dave Airlief011ae72008-01-25 11:23:04 +1000262 struct page *page;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
Linus Torvalds66c669b2006-11-22 14:55:29 -0800264 page = alloc_pages(GFP_KERNEL | GFP_DMA32, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 if (page == NULL)
266 return NULL;
267
Arjan van de Ven6d238cc2008-01-30 13:34:06 +0100268 if (set_pages_uc(page, 4) < 0) {
269 set_pages_wb(page, 4);
Jan Beulich89cf7cc2007-04-02 14:50:14 +0100270 __free_pages(page, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 return NULL;
272 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 get_page(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 atomic_inc(&agp_bridge->current_memory_agp);
Dave Airlie07613ba2009-06-12 14:11:41 +1000275 return page;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276}
277
Dave Airlie07613ba2009-06-12 14:11:41 +1000278static void i8xx_destroy_pages(struct page *page)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279{
Dave Airlie07613ba2009-06-12 14:11:41 +1000280 if (page == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 return;
282
Arjan van de Ven6d238cc2008-01-30 13:34:06 +0100283 set_pages_wb(page, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 put_page(page);
Jan Beulich89cf7cc2007-04-02 14:50:14 +0100285 __free_pages(page, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 atomic_dec(&agp_bridge->current_memory_agp);
287}
288
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100289static int intel_i830_type_to_mask_type(struct agp_bridge_data *bridge,
290 int type)
291{
292 if (type < AGP_USER_TYPES)
293 return type;
294 else if (type == AGP_USER_CACHED_MEMORY)
295 return INTEL_AGP_CACHED_MEMORY;
296 else
297 return 0;
298}
299
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300static int intel_i810_insert_entries(struct agp_memory *mem, off_t pg_start,
301 int type)
302{
303 int i, j, num_entries;
304 void *temp;
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100305 int ret = -EINVAL;
306 int mask_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +0100308 if (mem->page_count == 0)
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100309 goto out;
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +0100310
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 temp = agp_bridge->current_size;
312 num_entries = A_SIZE_FIX(temp)->num_entries;
313
Dave Jones6a92a4e2006-02-28 00:54:25 -0500314 if ((pg_start + mem->page_count) > num_entries)
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100315 goto out_err;
316
Dave Jones6a92a4e2006-02-28 00:54:25 -0500317
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 for (j = pg_start; j < (pg_start + mem->page_count); j++) {
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100319 if (!PGE_EMPTY(agp_bridge, readl(agp_bridge->gatt_table+j))) {
320 ret = -EBUSY;
321 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 }
324
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100325 if (type != mem->type)
326 goto out_err;
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +0100327
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100328 mask_type = agp_bridge->driver->agp_type_to_mask_type(agp_bridge, type);
329
330 switch (mask_type) {
331 case AGP_DCACHE_MEMORY:
332 if (!mem->is_flushed)
333 global_cache_flush();
334 for (i = pg_start; i < (pg_start + mem->page_count); i++) {
335 writel((i*4096)|I810_PTE_LOCAL|I810_PTE_VALID,
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800336 intel_private.registers+I810_PTE_BASE+(i*4));
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100337 }
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800338 readl(intel_private.registers+I810_PTE_BASE+((i-1)*4));
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100339 break;
340 case AGP_PHYS_MEMORY:
341 case AGP_NORMAL_MEMORY:
342 if (!mem->is_flushed)
343 global_cache_flush();
344 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
345 writel(agp_bridge->driver->mask_memory(agp_bridge,
Dave Airlie07613ba2009-06-12 14:11:41 +1000346 mem->pages[i],
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100347 mask_type),
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800348 intel_private.registers+I810_PTE_BASE+(j*4));
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100349 }
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800350 readl(intel_private.registers+I810_PTE_BASE+((j-1)*4));
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100351 break;
352 default:
353 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
356 agp_bridge->driver->tlb_flush(mem);
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100357out:
358 ret = 0;
359out_err:
Dave Airlie9516b032008-06-19 10:42:17 +1000360 mem->is_flushed = true;
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100361 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362}
363
364static int intel_i810_remove_entries(struct agp_memory *mem, off_t pg_start,
365 int type)
366{
367 int i;
368
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +0100369 if (mem->page_count == 0)
370 return 0;
371
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 for (i = pg_start; i < (mem->page_count + pg_start); i++) {
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800373 writel(agp_bridge->scratch_page, intel_private.registers+I810_PTE_BASE+(i*4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 }
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800375 readl(intel_private.registers+I810_PTE_BASE+((i-1)*4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 agp_bridge->driver->tlb_flush(mem);
378 return 0;
379}
380
381/*
382 * The i810/i830 requires a physical address to program its mouse
383 * pointer into hardware.
384 * However the Xserver still writes to it through the agp aperture.
385 */
386static struct agp_memory *alloc_agpphysmem_i8xx(size_t pg_count, int type)
387{
388 struct agp_memory *new;
Dave Airlie07613ba2009-06-12 14:11:41 +1000389 struct page *page;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 switch (pg_count) {
Dave Airlie07613ba2009-06-12 14:11:41 +1000392 case 1: page = agp_bridge->driver->agp_alloc_page(agp_bridge);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 break;
394 case 4:
395 /* kludge to get 4 physical pages for ARGB cursor */
Dave Airlie07613ba2009-06-12 14:11:41 +1000396 page = i8xx_alloc_pages();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 break;
398 default:
399 return NULL;
400 }
401
Dave Airlie07613ba2009-06-12 14:11:41 +1000402 if (page == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 return NULL;
404
405 new = agp_create_memory(pg_count);
406 if (new == NULL)
407 return NULL;
408
Dave Airlie07613ba2009-06-12 14:11:41 +1000409 new->pages[0] = page;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 if (pg_count == 4) {
411 /* kludge to get 4 physical pages for ARGB cursor */
Dave Airlie07613ba2009-06-12 14:11:41 +1000412 new->pages[1] = new->pages[0] + 1;
413 new->pages[2] = new->pages[1] + 1;
414 new->pages[3] = new->pages[2] + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 }
416 new->page_count = pg_count;
417 new->num_scratch_pages = pg_count;
418 new->type = AGP_PHYS_MEMORY;
Dave Airlie07613ba2009-06-12 14:11:41 +1000419 new->physical = page_to_phys(new->pages[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 return new;
421}
422
423static struct agp_memory *intel_i810_alloc_by_type(size_t pg_count, int type)
424{
425 struct agp_memory *new;
426
427 if (type == AGP_DCACHE_MEMORY) {
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800428 if (pg_count != intel_private.num_dcache_entries)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 return NULL;
430
431 new = agp_create_memory(1);
432 if (new == NULL)
433 return NULL;
434
435 new->type = AGP_DCACHE_MEMORY;
436 new->page_count = pg_count;
437 new->num_scratch_pages = 0;
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100438 agp_free_page_array(new);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 return new;
440 }
441 if (type == AGP_PHYS_MEMORY)
442 return alloc_agpphysmem_i8xx(pg_count, type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 return NULL;
444}
445
446static void intel_i810_free_by_type(struct agp_memory *curr)
447{
448 agp_free_key(curr->key);
Dave Jones6a92a4e2006-02-28 00:54:25 -0500449 if (curr->type == AGP_PHYS_MEMORY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 if (curr->page_count == 4)
Dave Airlie07613ba2009-06-12 14:11:41 +1000451 i8xx_destroy_pages(curr->pages[0]);
Alan Hourihane88d51962005-11-06 23:35:34 -0800452 else {
Dave Airlie07613ba2009-06-12 14:11:41 +1000453 agp_bridge->driver->agp_destroy_page(curr->pages[0],
Dave Airliea2721e92007-10-15 10:19:16 +1000454 AGP_PAGE_DESTROY_UNMAP);
Dave Airlie07613ba2009-06-12 14:11:41 +1000455 agp_bridge->driver->agp_destroy_page(curr->pages[0],
Dave Airliea2721e92007-10-15 10:19:16 +1000456 AGP_PAGE_DESTROY_FREE);
Alan Hourihane88d51962005-11-06 23:35:34 -0800457 }
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100458 agp_free_page_array(curr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 }
460 kfree(curr);
461}
462
463static unsigned long intel_i810_mask_memory(struct agp_bridge_data *bridge,
Dave Airlie07613ba2009-06-12 14:11:41 +1000464 struct page *page, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465{
Dave Airlie07613ba2009-06-12 14:11:41 +1000466 unsigned long addr = phys_to_gart(page_to_phys(page));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 /* Type checking must be done elsewhere */
468 return addr | bridge->driver->masks[type].mask;
469}
470
471static struct aper_size_info_fixed intel_i830_sizes[] =
472{
473 {128, 32768, 5},
474 /* The 64M mode still requires a 128k gatt */
475 {64, 16384, 5},
476 {256, 65536, 6},
Eric Anholt65c25aa2006-09-06 11:57:18 -0400477 {512, 131072, 7},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478};
479
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480static void intel_i830_init_gtt_entries(void)
481{
482 u16 gmch_ctrl;
483 int gtt_entries;
484 u8 rdct;
485 int local = 0;
486 static const int ddt[4] = { 0, 16, 32, 64 };
Eric Anholtc41e0de2006-12-19 12:57:24 -0800487 int size; /* reserved space (in kb) at the top of stolen memory */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
Dave Airlief011ae72008-01-25 11:23:04 +1000489 pci_read_config_word(agp_bridge->dev, I830_GMCH_CTRL, &gmch_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
Eric Anholtc41e0de2006-12-19 12:57:24 -0800491 if (IS_I965) {
492 u32 pgetbl_ctl;
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800493 pgetbl_ctl = readl(intel_private.registers+I810_PGETBL_CTL);
Eric Anholtc41e0de2006-12-19 12:57:24 -0800494
Eric Anholtc41e0de2006-12-19 12:57:24 -0800495 /* The 965 has a field telling us the size of the GTT,
496 * which may be larger than what is necessary to map the
497 * aperture.
498 */
499 switch (pgetbl_ctl & I965_PGETBL_SIZE_MASK) {
500 case I965_PGETBL_SIZE_128KB:
501 size = 128;
502 break;
503 case I965_PGETBL_SIZE_256KB:
504 size = 256;
505 break;
506 case I965_PGETBL_SIZE_512KB:
507 size = 512;
508 break;
Zhenyu Wang4e8b6e22008-01-23 14:54:37 +1000509 case I965_PGETBL_SIZE_1MB:
510 size = 1024;
511 break;
512 case I965_PGETBL_SIZE_2MB:
513 size = 2048;
514 break;
515 case I965_PGETBL_SIZE_1_5MB:
516 size = 1024 + 512;
517 break;
Eric Anholtc41e0de2006-12-19 12:57:24 -0800518 default:
Bjorn Helgaase3cf6952008-07-30 12:26:51 -0700519 dev_info(&intel_private.pcidev->dev,
520 "unknown page table size, assuming 512KB\n");
Eric Anholtc41e0de2006-12-19 12:57:24 -0800521 size = 512;
522 }
523 size += 4; /* add in BIOS popup space */
Shaohua Li21778322009-02-23 15:19:16 +0800524 } else if (IS_G33 && !IS_IGD) {
Wang Zhenyu874808c62007-06-06 11:16:25 +0800525 /* G33's GTT size defined in gmch_ctrl */
526 switch (gmch_ctrl & G33_PGETBL_SIZE_MASK) {
527 case G33_PGETBL_SIZE_1M:
528 size = 1024;
529 break;
530 case G33_PGETBL_SIZE_2M:
531 size = 2048;
532 break;
533 default:
Bjorn Helgaase3cf6952008-07-30 12:26:51 -0700534 dev_info(&agp_bridge->dev->dev,
535 "unknown page table size 0x%x, assuming 512KB\n",
Wang Zhenyu874808c62007-06-06 11:16:25 +0800536 (gmch_ctrl & G33_PGETBL_SIZE_MASK));
537 size = 512;
538 }
539 size += 4;
Shaohua Li21778322009-02-23 15:19:16 +0800540 } else if (IS_G4X || IS_IGD) {
Zhenyu Wang25ce77a2008-06-19 14:17:58 +1000541 /* On 4 series hardware, GTT stolen is separate from graphics
Eric Anholt82e14a62008-10-14 11:28:58 -0700542 * stolen, ignore it in stolen gtt entries counting. However,
543 * 4KB of the stolen memory doesn't get mapped to the GTT.
544 */
545 size = 4;
Eric Anholtc41e0de2006-12-19 12:57:24 -0800546 } else {
547 /* On previous hardware, the GTT size was just what was
548 * required to map the aperture.
549 */
550 size = agp_bridge->driver->fetch_size() + 4;
551 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552
553 if (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82830_HB ||
554 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82845G_HB) {
555 switch (gmch_ctrl & I830_GMCH_GMS_MASK) {
556 case I830_GMCH_GMS_STOLEN_512:
557 gtt_entries = KB(512) - KB(size);
558 break;
559 case I830_GMCH_GMS_STOLEN_1024:
560 gtt_entries = MB(1) - KB(size);
561 break;
562 case I830_GMCH_GMS_STOLEN_8192:
563 gtt_entries = MB(8) - KB(size);
564 break;
565 case I830_GMCH_GMS_LOCAL:
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800566 rdct = readb(intel_private.registers+I830_RDRAM_CHANNEL_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 gtt_entries = (I830_RDRAM_ND(rdct) + 1) *
568 MB(ddt[I830_RDRAM_DDT(rdct)]);
569 local = 1;
570 break;
571 default:
572 gtt_entries = 0;
573 break;
574 }
575 } else {
Dave Airliee67aa272007-09-18 22:46:35 -0700576 switch (gmch_ctrl & I855_GMCH_GMS_MASK) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 case I855_GMCH_GMS_STOLEN_1M:
578 gtt_entries = MB(1) - KB(size);
579 break;
580 case I855_GMCH_GMS_STOLEN_4M:
581 gtt_entries = MB(4) - KB(size);
582 break;
583 case I855_GMCH_GMS_STOLEN_8M:
584 gtt_entries = MB(8) - KB(size);
585 break;
586 case I855_GMCH_GMS_STOLEN_16M:
587 gtt_entries = MB(16) - KB(size);
588 break;
589 case I855_GMCH_GMS_STOLEN_32M:
590 gtt_entries = MB(32) - KB(size);
591 break;
592 case I915_GMCH_GMS_STOLEN_48M:
593 /* Check it's really I915G */
Zhenyu Wang25ce77a2008-06-19 14:17:58 +1000594 if (IS_I915 || IS_I965 || IS_G33 || IS_G4X)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 gtt_entries = MB(48) - KB(size);
596 else
597 gtt_entries = 0;
598 break;
599 case I915_GMCH_GMS_STOLEN_64M:
600 /* Check it's really I915G */
Zhenyu Wang25ce77a2008-06-19 14:17:58 +1000601 if (IS_I915 || IS_I965 || IS_G33 || IS_G4X)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 gtt_entries = MB(64) - KB(size);
603 else
604 gtt_entries = 0;
Wang Zhenyu874808c62007-06-06 11:16:25 +0800605 break;
606 case G33_GMCH_GMS_STOLEN_128M:
Zhenyu Wang25ce77a2008-06-19 14:17:58 +1000607 if (IS_G33 || IS_I965 || IS_G4X)
Wang Zhenyu874808c62007-06-06 11:16:25 +0800608 gtt_entries = MB(128) - KB(size);
609 else
610 gtt_entries = 0;
611 break;
612 case G33_GMCH_GMS_STOLEN_256M:
Zhenyu Wang25ce77a2008-06-19 14:17:58 +1000613 if (IS_G33 || IS_I965 || IS_G4X)
Wang Zhenyu874808c62007-06-06 11:16:25 +0800614 gtt_entries = MB(256) - KB(size);
615 else
616 gtt_entries = 0;
617 break;
Zhenyu Wang25ce77a2008-06-19 14:17:58 +1000618 case INTEL_GMCH_GMS_STOLEN_96M:
619 if (IS_I965 || IS_G4X)
620 gtt_entries = MB(96) - KB(size);
621 else
622 gtt_entries = 0;
623 break;
624 case INTEL_GMCH_GMS_STOLEN_160M:
625 if (IS_I965 || IS_G4X)
626 gtt_entries = MB(160) - KB(size);
627 else
628 gtt_entries = 0;
629 break;
630 case INTEL_GMCH_GMS_STOLEN_224M:
631 if (IS_I965 || IS_G4X)
632 gtt_entries = MB(224) - KB(size);
633 else
634 gtt_entries = 0;
635 break;
636 case INTEL_GMCH_GMS_STOLEN_352M:
637 if (IS_I965 || IS_G4X)
638 gtt_entries = MB(352) - KB(size);
639 else
640 gtt_entries = 0;
641 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 default:
643 gtt_entries = 0;
644 break;
645 }
646 }
Lubomir Rintel9c1e8a42009-03-10 12:55:54 -0700647 if (gtt_entries > 0) {
Bjorn Helgaase3cf6952008-07-30 12:26:51 -0700648 dev_info(&agp_bridge->dev->dev, "detected %dK %s memory\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 gtt_entries / KB(1), local ? "local" : "stolen");
Lubomir Rintel9c1e8a42009-03-10 12:55:54 -0700650 gtt_entries /= KB(4);
651 } else {
Bjorn Helgaase3cf6952008-07-30 12:26:51 -0700652 dev_info(&agp_bridge->dev->dev,
653 "no pre-allocated video memory detected\n");
Lubomir Rintel9c1e8a42009-03-10 12:55:54 -0700654 gtt_entries = 0;
655 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800657 intel_private.gtt_entries = gtt_entries;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658}
659
Dave Airlie2162e6a2007-11-21 16:36:31 +1000660static void intel_i830_fini_flush(void)
661{
662 kunmap(intel_private.i8xx_page);
663 intel_private.i8xx_flush_page = NULL;
664 unmap_page_from_agp(intel_private.i8xx_page);
Dave Airlie2162e6a2007-11-21 16:36:31 +1000665
666 __free_page(intel_private.i8xx_page);
Dave Airlie4d64dd92008-01-23 15:34:29 +1000667 intel_private.i8xx_page = NULL;
Dave Airlie2162e6a2007-11-21 16:36:31 +1000668}
669
670static void intel_i830_setup_flush(void)
671{
Dave Airlie4d64dd92008-01-23 15:34:29 +1000672 /* return if we've already set the flush mechanism up */
673 if (intel_private.i8xx_page)
674 return;
Dave Airlie2162e6a2007-11-21 16:36:31 +1000675
676 intel_private.i8xx_page = alloc_page(GFP_KERNEL | __GFP_ZERO | GFP_DMA32);
Dave Airlief011ae72008-01-25 11:23:04 +1000677 if (!intel_private.i8xx_page)
Dave Airlie2162e6a2007-11-21 16:36:31 +1000678 return;
Dave Airlie2162e6a2007-11-21 16:36:31 +1000679
680 /* make page uncached */
681 map_page_into_agp(intel_private.i8xx_page);
Dave Airlie2162e6a2007-11-21 16:36:31 +1000682
683 intel_private.i8xx_flush_page = kmap(intel_private.i8xx_page);
684 if (!intel_private.i8xx_flush_page)
685 intel_i830_fini_flush();
686}
687
688static void intel_i830_chipset_flush(struct agp_bridge_data *bridge)
689{
690 unsigned int *pg = intel_private.i8xx_flush_page;
691 int i;
692
Dave Airlief011ae72008-01-25 11:23:04 +1000693 for (i = 0; i < 256; i += 2)
Dave Airlie2162e6a2007-11-21 16:36:31 +1000694 *(pg + i) = i;
Dave Airlief011ae72008-01-25 11:23:04 +1000695
Dave Airlie2162e6a2007-11-21 16:36:31 +1000696 wmb();
697}
698
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699/* The intel i830 automatically initializes the agp aperture during POST.
700 * Use the memory already set aside for in the GTT.
701 */
702static int intel_i830_create_gatt_table(struct agp_bridge_data *bridge)
703{
704 int page_order;
705 struct aper_size_info_fixed *size;
706 int num_entries;
707 u32 temp;
708
709 size = agp_bridge->current_size;
710 page_order = size->page_order;
711 num_entries = size->num_entries;
712 agp_bridge->gatt_table_real = NULL;
713
Dave Airlief011ae72008-01-25 11:23:04 +1000714 pci_read_config_dword(intel_private.pcidev, I810_MMADDR, &temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 temp &= 0xfff80000;
716
Dave Airlief011ae72008-01-25 11:23:04 +1000717 intel_private.registers = ioremap(temp, 128 * 4096);
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800718 if (!intel_private.registers)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 return -ENOMEM;
720
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800721 temp = readl(intel_private.registers+I810_PGETBL_CTL) & 0xfffff000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 global_cache_flush(); /* FIXME: ?? */
723
724 /* we have to call this as early as possible after the MMIO base address is known */
725 intel_i830_init_gtt_entries();
726
727 agp_bridge->gatt_table = NULL;
728
729 agp_bridge->gatt_bus_addr = temp;
730
731 return 0;
732}
733
734/* Return the gatt table to a sane state. Use the top of stolen
735 * memory for the GTT.
736 */
737static int intel_i830_free_gatt_table(struct agp_bridge_data *bridge)
738{
739 return 0;
740}
741
742static int intel_i830_fetch_size(void)
743{
744 u16 gmch_ctrl;
745 struct aper_size_info_fixed *values;
746
747 values = A_SIZE_FIX(agp_bridge->driver->aperture_sizes);
748
749 if (agp_bridge->dev->device != PCI_DEVICE_ID_INTEL_82830_HB &&
750 agp_bridge->dev->device != PCI_DEVICE_ID_INTEL_82845G_HB) {
751 /* 855GM/852GM/865G has 128MB aperture size */
752 agp_bridge->previous_size = agp_bridge->current_size = (void *) values;
753 agp_bridge->aperture_size_idx = 0;
754 return values[0].size;
755 }
756
Dave Airlief011ae72008-01-25 11:23:04 +1000757 pci_read_config_word(agp_bridge->dev, I830_GMCH_CTRL, &gmch_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758
759 if ((gmch_ctrl & I830_GMCH_MEM_MASK) == I830_GMCH_MEM_128M) {
760 agp_bridge->previous_size = agp_bridge->current_size = (void *) values;
761 agp_bridge->aperture_size_idx = 0;
762 return values[0].size;
763 } else {
764 agp_bridge->previous_size = agp_bridge->current_size = (void *) (values + 1);
765 agp_bridge->aperture_size_idx = 1;
766 return values[1].size;
767 }
768
769 return 0;
770}
771
772static int intel_i830_configure(void)
773{
774 struct aper_size_info_fixed *current_size;
775 u32 temp;
776 u16 gmch_ctrl;
777 int i;
778
779 current_size = A_SIZE_FIX(agp_bridge->current_size);
780
Dave Airlief011ae72008-01-25 11:23:04 +1000781 pci_read_config_dword(intel_private.pcidev, I810_GMADDR, &temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
783
Dave Airlief011ae72008-01-25 11:23:04 +1000784 pci_read_config_word(agp_bridge->dev, I830_GMCH_CTRL, &gmch_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 gmch_ctrl |= I830_GMCH_ENABLED;
Dave Airlief011ae72008-01-25 11:23:04 +1000786 pci_write_config_word(agp_bridge->dev, I830_GMCH_CTRL, gmch_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800788 writel(agp_bridge->gatt_bus_addr|I810_PGETBL_ENABLED, intel_private.registers+I810_PGETBL_CTL);
789 readl(intel_private.registers+I810_PGETBL_CTL); /* PCI Posting. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790
791 if (agp_bridge->driver->needs_scratch_page) {
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800792 for (i = intel_private.gtt_entries; i < current_size->num_entries; i++) {
793 writel(agp_bridge->scratch_page, intel_private.registers+I810_PTE_BASE+(i*4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 }
Keith Packard44d49442008-10-14 17:18:45 -0700795 readl(intel_private.registers+I810_PTE_BASE+((i-1)*4)); /* PCI Posting. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 }
797
798 global_cache_flush();
Dave Airlie2162e6a2007-11-21 16:36:31 +1000799
800 intel_i830_setup_flush();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 return 0;
802}
803
804static void intel_i830_cleanup(void)
805{
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800806 iounmap(intel_private.registers);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807}
808
Dave Airlief011ae72008-01-25 11:23:04 +1000809static int intel_i830_insert_entries(struct agp_memory *mem, off_t pg_start,
810 int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811{
Dave Airlief011ae72008-01-25 11:23:04 +1000812 int i, j, num_entries;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 void *temp;
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100814 int ret = -EINVAL;
815 int mask_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +0100817 if (mem->page_count == 0)
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100818 goto out;
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +0100819
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 temp = agp_bridge->current_size;
821 num_entries = A_SIZE_FIX(temp)->num_entries;
822
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800823 if (pg_start < intel_private.gtt_entries) {
Bjorn Helgaase3cf6952008-07-30 12:26:51 -0700824 dev_printk(KERN_DEBUG, &intel_private.pcidev->dev,
825 "pg_start == 0x%.8lx, intel_private.gtt_entries == 0x%.8x\n",
826 pg_start, intel_private.gtt_entries);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827
Bjorn Helgaase3cf6952008-07-30 12:26:51 -0700828 dev_info(&intel_private.pcidev->dev,
829 "trying to insert into local/stolen memory\n");
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100830 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 }
832
833 if ((pg_start + mem->page_count) > num_entries)
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100834 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835
836 /* The i830 can't check the GTT for entries since its read only,
837 * depend on the caller to make the correct offset decisions.
838 */
839
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100840 if (type != mem->type)
841 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100843 mask_type = agp_bridge->driver->agp_type_to_mask_type(agp_bridge, type);
844
845 if (mask_type != 0 && mask_type != AGP_PHYS_MEMORY &&
846 mask_type != INTEL_AGP_CACHED_MEMORY)
847 goto out_err;
848
849 if (!mem->is_flushed)
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +0100850 global_cache_flush();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851
852 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
853 writel(agp_bridge->driver->mask_memory(agp_bridge,
Dave Airlie07613ba2009-06-12 14:11:41 +1000854 mem->pages[i], mask_type),
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800855 intel_private.registers+I810_PTE_BASE+(j*4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 }
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800857 readl(intel_private.registers+I810_PTE_BASE+((j-1)*4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 agp_bridge->driver->tlb_flush(mem);
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100859
860out:
861 ret = 0;
862out_err:
Dave Airlie9516b032008-06-19 10:42:17 +1000863 mem->is_flushed = true;
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100864 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865}
866
Dave Airlief011ae72008-01-25 11:23:04 +1000867static int intel_i830_remove_entries(struct agp_memory *mem, off_t pg_start,
868 int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869{
870 int i;
871
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +0100872 if (mem->page_count == 0)
873 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800875 if (pg_start < intel_private.gtt_entries) {
Bjorn Helgaase3cf6952008-07-30 12:26:51 -0700876 dev_info(&intel_private.pcidev->dev,
877 "trying to disable local/stolen memory\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 return -EINVAL;
879 }
880
881 for (i = pg_start; i < (mem->page_count + pg_start); i++) {
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800882 writel(agp_bridge->scratch_page, intel_private.registers+I810_PTE_BASE+(i*4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 }
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800884 readl(intel_private.registers+I810_PTE_BASE+((i-1)*4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 agp_bridge->driver->tlb_flush(mem);
887 return 0;
888}
889
Dave Airlief011ae72008-01-25 11:23:04 +1000890static struct agp_memory *intel_i830_alloc_by_type(size_t pg_count, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891{
892 if (type == AGP_PHYS_MEMORY)
893 return alloc_agpphysmem_i8xx(pg_count, type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 /* always return NULL for other allocation types for now */
895 return NULL;
896}
897
Dave Airlie6c00a612007-10-29 18:06:10 +1000898static int intel_alloc_chipset_flush_resource(void)
899{
900 int ret;
901 ret = pci_bus_alloc_resource(agp_bridge->dev->bus, &intel_private.ifp_resource, PAGE_SIZE,
902 PAGE_SIZE, PCIBIOS_MIN_MEM, 0,
903 pcibios_align_resource, agp_bridge->dev);
Dave Airlie6c00a612007-10-29 18:06:10 +1000904
Dave Airlie2162e6a2007-11-21 16:36:31 +1000905 return ret;
Dave Airlie6c00a612007-10-29 18:06:10 +1000906}
907
908static void intel_i915_setup_chipset_flush(void)
909{
910 int ret;
911 u32 temp;
912
913 pci_read_config_dword(agp_bridge->dev, I915_IFPADDR, &temp);
914 if (!(temp & 0x1)) {
915 intel_alloc_chipset_flush_resource();
Dave Airlie4d64dd92008-01-23 15:34:29 +1000916 intel_private.resource_valid = 1;
Dave Airlie6c00a612007-10-29 18:06:10 +1000917 pci_write_config_dword(agp_bridge->dev, I915_IFPADDR, (intel_private.ifp_resource.start & 0xffffffff) | 0x1);
918 } else {
919 temp &= ~1;
920
Dave Airlie4d64dd92008-01-23 15:34:29 +1000921 intel_private.resource_valid = 1;
Dave Airlie6c00a612007-10-29 18:06:10 +1000922 intel_private.ifp_resource.start = temp;
923 intel_private.ifp_resource.end = temp + PAGE_SIZE;
924 ret = request_resource(&iomem_resource, &intel_private.ifp_resource);
Dave Airlie4d64dd92008-01-23 15:34:29 +1000925 /* some BIOSes reserve this area in a pnp some don't */
926 if (ret)
927 intel_private.resource_valid = 0;
Dave Airlie6c00a612007-10-29 18:06:10 +1000928 }
929}
930
931static void intel_i965_g33_setup_chipset_flush(void)
932{
933 u32 temp_hi, temp_lo;
934 int ret;
935
936 pci_read_config_dword(agp_bridge->dev, I965_IFPADDR + 4, &temp_hi);
937 pci_read_config_dword(agp_bridge->dev, I965_IFPADDR, &temp_lo);
938
939 if (!(temp_lo & 0x1)) {
940
941 intel_alloc_chipset_flush_resource();
942
Dave Airlie4d64dd92008-01-23 15:34:29 +1000943 intel_private.resource_valid = 1;
Andrew Morton1fa4db72007-11-29 10:00:48 +1000944 pci_write_config_dword(agp_bridge->dev, I965_IFPADDR + 4,
945 upper_32_bits(intel_private.ifp_resource.start));
Dave Airlie6c00a612007-10-29 18:06:10 +1000946 pci_write_config_dword(agp_bridge->dev, I965_IFPADDR, (intel_private.ifp_resource.start & 0xffffffff) | 0x1);
Dave Airlie6c00a612007-10-29 18:06:10 +1000947 } else {
948 u64 l64;
Dave Airlief011ae72008-01-25 11:23:04 +1000949
Dave Airlie6c00a612007-10-29 18:06:10 +1000950 temp_lo &= ~0x1;
951 l64 = ((u64)temp_hi << 32) | temp_lo;
952
Dave Airlie4d64dd92008-01-23 15:34:29 +1000953 intel_private.resource_valid = 1;
Dave Airlie6c00a612007-10-29 18:06:10 +1000954 intel_private.ifp_resource.start = l64;
955 intel_private.ifp_resource.end = l64 + PAGE_SIZE;
956 ret = request_resource(&iomem_resource, &intel_private.ifp_resource);
Dave Airlie4d64dd92008-01-23 15:34:29 +1000957 /* some BIOSes reserve this area in a pnp some don't */
958 if (ret)
959 intel_private.resource_valid = 0;
Dave Airlie6c00a612007-10-29 18:06:10 +1000960 }
961}
962
Dave Airlie2162e6a2007-11-21 16:36:31 +1000963static void intel_i9xx_setup_flush(void)
964{
Dave Airlie4d64dd92008-01-23 15:34:29 +1000965 /* return if already configured */
966 if (intel_private.ifp_resource.start)
967 return;
Dave Airlie2162e6a2007-11-21 16:36:31 +1000968
Dave Airlie4d64dd92008-01-23 15:34:29 +1000969 /* setup a resource for this object */
Dave Airlie2162e6a2007-11-21 16:36:31 +1000970 intel_private.ifp_resource.name = "Intel Flush Page";
971 intel_private.ifp_resource.flags = IORESOURCE_MEM;
972
973 /* Setup chipset flush for 915 */
Zhenyu Wang7d15ddf2008-06-20 11:48:06 +1000974 if (IS_I965 || IS_G33 || IS_G4X) {
Dave Airlie2162e6a2007-11-21 16:36:31 +1000975 intel_i965_g33_setup_chipset_flush();
976 } else {
977 intel_i915_setup_chipset_flush();
978 }
979
980 if (intel_private.ifp_resource.start) {
981 intel_private.i9xx_flush_page = ioremap_nocache(intel_private.ifp_resource.start, PAGE_SIZE);
982 if (!intel_private.i9xx_flush_page)
Bjorn Helgaase3cf6952008-07-30 12:26:51 -0700983 dev_info(&intel_private.pcidev->dev, "can't ioremap flush page - no chipset flushing");
Dave Airlie2162e6a2007-11-21 16:36:31 +1000984 }
985}
986
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987static int intel_i915_configure(void)
988{
989 struct aper_size_info_fixed *current_size;
990 u32 temp;
991 u16 gmch_ctrl;
992 int i;
993
994 current_size = A_SIZE_FIX(agp_bridge->current_size);
995
Wang Zhenyuc4ca8812007-05-30 09:40:46 +0800996 pci_read_config_dword(intel_private.pcidev, I915_GMADDR, &temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997
998 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
999
Dave Airlief011ae72008-01-25 11:23:04 +10001000 pci_read_config_word(agp_bridge->dev, I830_GMCH_CTRL, &gmch_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 gmch_ctrl |= I830_GMCH_ENABLED;
Dave Airlief011ae72008-01-25 11:23:04 +10001002 pci_write_config_word(agp_bridge->dev, I830_GMCH_CTRL, gmch_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001004 writel(agp_bridge->gatt_bus_addr|I810_PGETBL_ENABLED, intel_private.registers+I810_PGETBL_CTL);
1005 readl(intel_private.registers+I810_PGETBL_CTL); /* PCI Posting. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006
1007 if (agp_bridge->driver->needs_scratch_page) {
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001008 for (i = intel_private.gtt_entries; i < current_size->num_entries; i++) {
1009 writel(agp_bridge->scratch_page, intel_private.gtt+i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 }
Keith Packard44d49442008-10-14 17:18:45 -07001011 readl(intel_private.gtt+i-1); /* PCI Posting. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 }
1013
1014 global_cache_flush();
Dave Airlie6c00a612007-10-29 18:06:10 +10001015
Dave Airlie2162e6a2007-11-21 16:36:31 +10001016 intel_i9xx_setup_flush();
Dave Airlief011ae72008-01-25 11:23:04 +10001017
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 return 0;
1019}
1020
1021static void intel_i915_cleanup(void)
1022{
Dave Airlie2162e6a2007-11-21 16:36:31 +10001023 if (intel_private.i9xx_flush_page)
1024 iounmap(intel_private.i9xx_flush_page);
Dave Airlie4d64dd92008-01-23 15:34:29 +10001025 if (intel_private.resource_valid)
1026 release_resource(&intel_private.ifp_resource);
1027 intel_private.ifp_resource.start = 0;
1028 intel_private.resource_valid = 0;
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001029 iounmap(intel_private.gtt);
1030 iounmap(intel_private.registers);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031}
1032
Dave Airlie6c00a612007-10-29 18:06:10 +10001033static void intel_i915_chipset_flush(struct agp_bridge_data *bridge)
1034{
Dave Airlie2162e6a2007-11-21 16:36:31 +10001035 if (intel_private.i9xx_flush_page)
1036 writel(1, intel_private.i9xx_flush_page);
Dave Airlie6c00a612007-10-29 18:06:10 +10001037}
1038
Dave Airlief011ae72008-01-25 11:23:04 +10001039static int intel_i915_insert_entries(struct agp_memory *mem, off_t pg_start,
1040 int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041{
Dave Airlief011ae72008-01-25 11:23:04 +10001042 int i, j, num_entries;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 void *temp;
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001044 int ret = -EINVAL;
1045 int mask_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +01001047 if (mem->page_count == 0)
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001048 goto out;
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +01001049
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 temp = agp_bridge->current_size;
1051 num_entries = A_SIZE_FIX(temp)->num_entries;
1052
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001053 if (pg_start < intel_private.gtt_entries) {
Bjorn Helgaase3cf6952008-07-30 12:26:51 -07001054 dev_printk(KERN_DEBUG, &intel_private.pcidev->dev,
1055 "pg_start == 0x%.8lx, intel_private.gtt_entries == 0x%.8x\n",
1056 pg_start, intel_private.gtt_entries);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057
Bjorn Helgaase3cf6952008-07-30 12:26:51 -07001058 dev_info(&intel_private.pcidev->dev,
1059 "trying to insert into local/stolen memory\n");
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001060 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 }
1062
1063 if ((pg_start + mem->page_count) > num_entries)
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001064 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001066 /* The i915 can't check the GTT for entries since its read only,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 * depend on the caller to make the correct offset decisions.
1068 */
1069
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001070 if (type != mem->type)
1071 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001073 mask_type = agp_bridge->driver->agp_type_to_mask_type(agp_bridge, type);
1074
1075 if (mask_type != 0 && mask_type != AGP_PHYS_MEMORY &&
1076 mask_type != INTEL_AGP_CACHED_MEMORY)
1077 goto out_err;
1078
1079 if (!mem->is_flushed)
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +01001080 global_cache_flush();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081
1082 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
1083 writel(agp_bridge->driver->mask_memory(agp_bridge,
Dave Airlie07613ba2009-06-12 14:11:41 +10001084 mem->pages[i], mask_type), intel_private.gtt+j);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 }
1086
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001087 readl(intel_private.gtt+j-1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 agp_bridge->driver->tlb_flush(mem);
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001089
1090 out:
1091 ret = 0;
1092 out_err:
Dave Airlie9516b032008-06-19 10:42:17 +10001093 mem->is_flushed = true;
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001094 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095}
1096
Dave Airlief011ae72008-01-25 11:23:04 +10001097static int intel_i915_remove_entries(struct agp_memory *mem, off_t pg_start,
1098 int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099{
1100 int i;
1101
Thomas Hellstrom5aa80c72006-12-20 16:33:41 +01001102 if (mem->page_count == 0)
1103 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001105 if (pg_start < intel_private.gtt_entries) {
Bjorn Helgaase3cf6952008-07-30 12:26:51 -07001106 dev_info(&intel_private.pcidev->dev,
1107 "trying to disable local/stolen memory\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 return -EINVAL;
1109 }
1110
Dave Airlief011ae72008-01-25 11:23:04 +10001111 for (i = pg_start; i < (mem->page_count + pg_start); i++)
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001112 writel(agp_bridge->scratch_page, intel_private.gtt+i);
Dave Airlief011ae72008-01-25 11:23:04 +10001113
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001114 readl(intel_private.gtt+i-1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 agp_bridge->driver->tlb_flush(mem);
1117 return 0;
1118}
1119
Eric Anholtc41e0de2006-12-19 12:57:24 -08001120/* Return the aperture size by just checking the resource length. The effect
1121 * described in the spec of the MSAC registers is just changing of the
1122 * resource size.
1123 */
1124static int intel_i9xx_fetch_size(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125{
Ahmed S. Darwish1eaf1222007-02-06 18:08:28 +02001126 int num_sizes = ARRAY_SIZE(intel_i830_sizes);
Eric Anholtc41e0de2006-12-19 12:57:24 -08001127 int aper_size; /* size in megabytes */
1128 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001130 aper_size = pci_resource_len(intel_private.pcidev, 2) / MB(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131
Eric Anholtc41e0de2006-12-19 12:57:24 -08001132 for (i = 0; i < num_sizes; i++) {
1133 if (aper_size == intel_i830_sizes[i].size) {
1134 agp_bridge->current_size = intel_i830_sizes + i;
1135 agp_bridge->previous_size = agp_bridge->current_size;
1136 return aper_size;
1137 }
1138 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139
Eric Anholtc41e0de2006-12-19 12:57:24 -08001140 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141}
1142
1143/* The intel i915 automatically initializes the agp aperture during POST.
1144 * Use the memory already set aside for in the GTT.
1145 */
1146static int intel_i915_create_gatt_table(struct agp_bridge_data *bridge)
1147{
1148 int page_order;
1149 struct aper_size_info_fixed *size;
1150 int num_entries;
1151 u32 temp, temp2;
Zhenyu Wang47406222007-09-11 15:23:58 -07001152 int gtt_map_size = 256 * 1024;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153
1154 size = agp_bridge->current_size;
1155 page_order = size->page_order;
1156 num_entries = size->num_entries;
1157 agp_bridge->gatt_table_real = NULL;
1158
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001159 pci_read_config_dword(intel_private.pcidev, I915_MMADDR, &temp);
Dave Airlief011ae72008-01-25 11:23:04 +10001160 pci_read_config_dword(intel_private.pcidev, I915_PTEADDR, &temp2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161
Zhenyu Wang47406222007-09-11 15:23:58 -07001162 if (IS_G33)
1163 gtt_map_size = 1024 * 1024; /* 1M on G33 */
1164 intel_private.gtt = ioremap(temp2, gtt_map_size);
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001165 if (!intel_private.gtt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 return -ENOMEM;
1167
1168 temp &= 0xfff80000;
1169
Dave Airlief011ae72008-01-25 11:23:04 +10001170 intel_private.registers = ioremap(temp, 128 * 4096);
Scott Thompson5bdbc7d2007-08-25 18:14:00 +10001171 if (!intel_private.registers) {
1172 iounmap(intel_private.gtt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 return -ENOMEM;
Scott Thompson5bdbc7d2007-08-25 18:14:00 +10001174 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08001176 temp = readl(intel_private.registers+I810_PGETBL_CTL) & 0xfffff000;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 global_cache_flush(); /* FIXME: ? */
1178
1179 /* we have to call this as early as possible after the MMIO base address is known */
1180 intel_i830_init_gtt_entries();
1181
1182 agp_bridge->gatt_table = NULL;
1183
1184 agp_bridge->gatt_bus_addr = temp;
1185
1186 return 0;
1187}
Linus Torvalds7d915a32006-11-22 09:37:54 -08001188
1189/*
1190 * The i965 supports 36-bit physical addresses, but to keep
1191 * the format of the GTT the same, the bits that don't fit
1192 * in a 32-bit word are shifted down to bits 4..7.
1193 *
1194 * Gcc is smart enough to notice that "(addr >> 28) & 0xf0"
1195 * is always zero on 32-bit architectures, so no need to make
1196 * this conditional.
1197 */
1198static unsigned long intel_i965_mask_memory(struct agp_bridge_data *bridge,
Dave Airlie07613ba2009-06-12 14:11:41 +10001199 struct page *page, int type)
Linus Torvalds7d915a32006-11-22 09:37:54 -08001200{
Dave Airlie07613ba2009-06-12 14:11:41 +10001201 unsigned long addr = phys_to_gart(page_to_phys(page));
Linus Torvalds7d915a32006-11-22 09:37:54 -08001202 /* Shift high bits down */
1203 addr |= (addr >> 28) & 0xf0;
1204
1205 /* Type checking must be done elsewhere */
1206 return addr | bridge->driver->masks[type].mask;
1207}
1208
Zhenyu Wang25ce77a2008-06-19 14:17:58 +10001209static void intel_i965_get_gtt_range(int *gtt_offset, int *gtt_size)
1210{
1211 switch (agp_bridge->dev->device) {
Zhenyu Wang99d32bd2008-07-30 12:26:50 -07001212 case PCI_DEVICE_ID_INTEL_GM45_HB:
Zhenyu Wang25ce77a2008-06-19 14:17:58 +10001213 case PCI_DEVICE_ID_INTEL_IGD_E_HB:
1214 case PCI_DEVICE_ID_INTEL_Q45_HB:
1215 case PCI_DEVICE_ID_INTEL_G45_HB:
Zhenyu Wanga50ccc62008-11-17 14:39:00 +08001216 case PCI_DEVICE_ID_INTEL_G41_HB:
Zhenyu Wang32cb0552009-06-05 15:38:36 +08001217 case PCI_DEVICE_ID_INTEL_IGDNG_D_HB:
1218 case PCI_DEVICE_ID_INTEL_IGDNG_M_HB:
Zhenyu Wang25ce77a2008-06-19 14:17:58 +10001219 *gtt_offset = *gtt_size = MB(2);
1220 break;
1221 default:
1222 *gtt_offset = *gtt_size = KB(512);
1223 }
1224}
1225
Eric Anholt65c25aa2006-09-06 11:57:18 -04001226/* The intel i965 automatically initializes the agp aperture during POST.
Eric Anholtc41e0de2006-12-19 12:57:24 -08001227 * Use the memory already set aside for in the GTT.
1228 */
Eric Anholt65c25aa2006-09-06 11:57:18 -04001229static int intel_i965_create_gatt_table(struct agp_bridge_data *bridge)
1230{
Dave Airlie62c96b92008-06-19 14:27:53 +10001231 int page_order;
1232 struct aper_size_info_fixed *size;
1233 int num_entries;
1234 u32 temp;
1235 int gtt_offset, gtt_size;
Eric Anholt65c25aa2006-09-06 11:57:18 -04001236
Dave Airlie62c96b92008-06-19 14:27:53 +10001237 size = agp_bridge->current_size;
1238 page_order = size->page_order;
1239 num_entries = size->num_entries;
1240 agp_bridge->gatt_table_real = NULL;
Eric Anholt65c25aa2006-09-06 11:57:18 -04001241
Dave Airlie62c96b92008-06-19 14:27:53 +10001242 pci_read_config_dword(intel_private.pcidev, I915_MMADDR, &temp);
Eric Anholt65c25aa2006-09-06 11:57:18 -04001243
Dave Airlie62c96b92008-06-19 14:27:53 +10001244 temp &= 0xfff00000;
Eric Anholt65c25aa2006-09-06 11:57:18 -04001245
Zhenyu Wang25ce77a2008-06-19 14:17:58 +10001246 intel_i965_get_gtt_range(&gtt_offset, &gtt_size);
Eric Anholt65c25aa2006-09-06 11:57:18 -04001247
Dave Airlie62c96b92008-06-19 14:27:53 +10001248 intel_private.gtt = ioremap((temp + gtt_offset) , gtt_size);
Eric Anholt65c25aa2006-09-06 11:57:18 -04001249
Dave Airlie62c96b92008-06-19 14:27:53 +10001250 if (!intel_private.gtt)
1251 return -ENOMEM;
Zhenyu Wang4e8b6e22008-01-23 14:54:37 +10001252
Dave Airlie62c96b92008-06-19 14:27:53 +10001253 intel_private.registers = ioremap(temp, 128 * 4096);
1254 if (!intel_private.registers) {
Scott Thompson5bdbc7d2007-08-25 18:14:00 +10001255 iounmap(intel_private.gtt);
1256 return -ENOMEM;
1257 }
Eric Anholt65c25aa2006-09-06 11:57:18 -04001258
Dave Airlie62c96b92008-06-19 14:27:53 +10001259 temp = readl(intel_private.registers+I810_PGETBL_CTL) & 0xfffff000;
1260 global_cache_flush(); /* FIXME: ? */
Eric Anholt65c25aa2006-09-06 11:57:18 -04001261
Dave Airlie62c96b92008-06-19 14:27:53 +10001262 /* we have to call this as early as possible after the MMIO base address is known */
1263 intel_i830_init_gtt_entries();
Eric Anholt65c25aa2006-09-06 11:57:18 -04001264
Dave Airlie62c96b92008-06-19 14:27:53 +10001265 agp_bridge->gatt_table = NULL;
Eric Anholt65c25aa2006-09-06 11:57:18 -04001266
Dave Airlie62c96b92008-06-19 14:27:53 +10001267 agp_bridge->gatt_bus_addr = temp;
Eric Anholt65c25aa2006-09-06 11:57:18 -04001268
Dave Airlie62c96b92008-06-19 14:27:53 +10001269 return 0;
Eric Anholt65c25aa2006-09-06 11:57:18 -04001270}
1271
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272
1273static int intel_fetch_size(void)
1274{
1275 int i;
1276 u16 temp;
1277 struct aper_size_info_16 *values;
1278
1279 pci_read_config_word(agp_bridge->dev, INTEL_APSIZE, &temp);
1280 values = A_SIZE_16(agp_bridge->driver->aperture_sizes);
1281
1282 for (i = 0; i < agp_bridge->driver->num_aperture_sizes; i++) {
1283 if (temp == values[i].size_value) {
1284 agp_bridge->previous_size = agp_bridge->current_size = (void *) (values + i);
1285 agp_bridge->aperture_size_idx = i;
1286 return values[i].size;
1287 }
1288 }
1289
1290 return 0;
1291}
1292
1293static int __intel_8xx_fetch_size(u8 temp)
1294{
1295 int i;
1296 struct aper_size_info_8 *values;
1297
1298 values = A_SIZE_8(agp_bridge->driver->aperture_sizes);
1299
1300 for (i = 0; i < agp_bridge->driver->num_aperture_sizes; i++) {
1301 if (temp == values[i].size_value) {
1302 agp_bridge->previous_size =
1303 agp_bridge->current_size = (void *) (values + i);
1304 agp_bridge->aperture_size_idx = i;
1305 return values[i].size;
1306 }
1307 }
1308 return 0;
1309}
1310
1311static int intel_8xx_fetch_size(void)
1312{
1313 u8 temp;
1314
1315 pci_read_config_byte(agp_bridge->dev, INTEL_APSIZE, &temp);
1316 return __intel_8xx_fetch_size(temp);
1317}
1318
1319static int intel_815_fetch_size(void)
1320{
1321 u8 temp;
1322
1323 /* Intel 815 chipsets have a _weird_ APSIZE register with only
1324 * one non-reserved bit, so mask the others out ... */
1325 pci_read_config_byte(agp_bridge->dev, INTEL_APSIZE, &temp);
1326 temp &= (1 << 3);
1327
1328 return __intel_8xx_fetch_size(temp);
1329}
1330
1331static void intel_tlbflush(struct agp_memory *mem)
1332{
1333 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x2200);
1334 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x2280);
1335}
1336
1337
1338static void intel_8xx_tlbflush(struct agp_memory *mem)
1339{
1340 u32 temp;
1341 pci_read_config_dword(agp_bridge->dev, INTEL_AGPCTRL, &temp);
1342 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, temp & ~(1 << 7));
1343 pci_read_config_dword(agp_bridge->dev, INTEL_AGPCTRL, &temp);
1344 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, temp | (1 << 7));
1345}
1346
1347
1348static void intel_cleanup(void)
1349{
1350 u16 temp;
1351 struct aper_size_info_16 *previous_size;
1352
1353 previous_size = A_SIZE_16(agp_bridge->previous_size);
1354 pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp);
1355 pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG, temp & ~(1 << 9));
1356 pci_write_config_word(agp_bridge->dev, INTEL_APSIZE, previous_size->size_value);
1357}
1358
1359
1360static void intel_8xx_cleanup(void)
1361{
1362 u16 temp;
1363 struct aper_size_info_8 *previous_size;
1364
1365 previous_size = A_SIZE_8(agp_bridge->previous_size);
1366 pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp);
1367 pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG, temp & ~(1 << 9));
1368 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, previous_size->size_value);
1369}
1370
1371
1372static int intel_configure(void)
1373{
1374 u32 temp;
1375 u16 temp2;
1376 struct aper_size_info_16 *current_size;
1377
1378 current_size = A_SIZE_16(agp_bridge->current_size);
1379
1380 /* aperture size */
1381 pci_write_config_word(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1382
1383 /* address to map to */
1384 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1385 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1386
1387 /* attbase - aperture base */
1388 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1389
1390 /* agpctrl */
1391 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x2280);
1392
1393 /* paccfg/nbxcfg */
1394 pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp2);
1395 pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG,
1396 (temp2 & ~(1 << 10)) | (1 << 9));
1397 /* clear any possible error conditions */
1398 pci_write_config_byte(agp_bridge->dev, INTEL_ERRSTS + 1, 7);
1399 return 0;
1400}
1401
1402static int intel_815_configure(void)
1403{
1404 u32 temp, addr;
1405 u8 temp2;
1406 struct aper_size_info_8 *current_size;
1407
1408 /* attbase - aperture base */
1409 /* the Intel 815 chipset spec. says that bits 29-31 in the
1410 * ATTBASE register are reserved -> try not to write them */
1411 if (agp_bridge->gatt_bus_addr & INTEL_815_ATTBASE_MASK) {
Bjorn Helgaase3cf6952008-07-30 12:26:51 -07001412 dev_emerg(&agp_bridge->dev->dev, "gatt bus addr too high");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 return -EINVAL;
1414 }
1415
1416 current_size = A_SIZE_8(agp_bridge->current_size);
1417
1418 /* aperture size */
1419 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE,
1420 current_size->size_value);
1421
1422 /* address to map to */
1423 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1424 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1425
1426 pci_read_config_dword(agp_bridge->dev, INTEL_ATTBASE, &addr);
1427 addr &= INTEL_815_ATTBASE_MASK;
1428 addr |= agp_bridge->gatt_bus_addr;
1429 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, addr);
1430
1431 /* agpctrl */
1432 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1433
1434 /* apcont */
1435 pci_read_config_byte(agp_bridge->dev, INTEL_815_APCONT, &temp2);
1436 pci_write_config_byte(agp_bridge->dev, INTEL_815_APCONT, temp2 | (1 << 1));
1437
1438 /* clear any possible error conditions */
1439 /* Oddness : this chipset seems to have no ERRSTS register ! */
1440 return 0;
1441}
1442
1443static void intel_820_tlbflush(struct agp_memory *mem)
1444{
1445 return;
1446}
1447
1448static void intel_820_cleanup(void)
1449{
1450 u8 temp;
1451 struct aper_size_info_8 *previous_size;
1452
1453 previous_size = A_SIZE_8(agp_bridge->previous_size);
1454 pci_read_config_byte(agp_bridge->dev, INTEL_I820_RDCR, &temp);
1455 pci_write_config_byte(agp_bridge->dev, INTEL_I820_RDCR,
1456 temp & ~(1 << 1));
1457 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE,
1458 previous_size->size_value);
1459}
1460
1461
1462static int intel_820_configure(void)
1463{
1464 u32 temp;
1465 u8 temp2;
1466 struct aper_size_info_8 *current_size;
1467
1468 current_size = A_SIZE_8(agp_bridge->current_size);
1469
1470 /* aperture size */
1471 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1472
1473 /* address to map to */
1474 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1475 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1476
1477 /* attbase - aperture base */
1478 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1479
1480 /* agpctrl */
1481 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1482
1483 /* global enable aperture access */
1484 /* This flag is not accessed through MCHCFG register as in */
1485 /* i850 chipset. */
1486 pci_read_config_byte(agp_bridge->dev, INTEL_I820_RDCR, &temp2);
1487 pci_write_config_byte(agp_bridge->dev, INTEL_I820_RDCR, temp2 | (1 << 1));
1488 /* clear any possible AGP-related error conditions */
1489 pci_write_config_word(agp_bridge->dev, INTEL_I820_ERRSTS, 0x001c);
1490 return 0;
1491}
1492
1493static int intel_840_configure(void)
1494{
1495 u32 temp;
1496 u16 temp2;
1497 struct aper_size_info_8 *current_size;
1498
1499 current_size = A_SIZE_8(agp_bridge->current_size);
1500
1501 /* aperture size */
1502 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1503
1504 /* address to map to */
1505 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1506 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1507
1508 /* attbase - aperture base */
1509 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1510
1511 /* agpctrl */
1512 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1513
1514 /* mcgcfg */
1515 pci_read_config_word(agp_bridge->dev, INTEL_I840_MCHCFG, &temp2);
1516 pci_write_config_word(agp_bridge->dev, INTEL_I840_MCHCFG, temp2 | (1 << 9));
1517 /* clear any possible error conditions */
1518 pci_write_config_word(agp_bridge->dev, INTEL_I840_ERRSTS, 0xc000);
1519 return 0;
1520}
1521
1522static int intel_845_configure(void)
1523{
1524 u32 temp;
1525 u8 temp2;
1526 struct aper_size_info_8 *current_size;
1527
1528 current_size = A_SIZE_8(agp_bridge->current_size);
1529
1530 /* aperture size */
1531 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1532
Matthew Garrettb0825482005-07-29 14:03:39 -07001533 if (agp_bridge->apbase_config != 0) {
1534 pci_write_config_dword(agp_bridge->dev, AGP_APBASE,
1535 agp_bridge->apbase_config);
1536 } else {
1537 /* address to map to */
1538 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1539 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1540 agp_bridge->apbase_config = temp;
1541 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542
1543 /* attbase - aperture base */
1544 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1545
1546 /* agpctrl */
1547 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1548
1549 /* agpm */
1550 pci_read_config_byte(agp_bridge->dev, INTEL_I845_AGPM, &temp2);
1551 pci_write_config_byte(agp_bridge->dev, INTEL_I845_AGPM, temp2 | (1 << 1));
1552 /* clear any possible error conditions */
1553 pci_write_config_word(agp_bridge->dev, INTEL_I845_ERRSTS, 0x001c);
Dave Airlie2162e6a2007-11-21 16:36:31 +10001554
1555 intel_i830_setup_flush();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556 return 0;
1557}
1558
1559static int intel_850_configure(void)
1560{
1561 u32 temp;
1562 u16 temp2;
1563 struct aper_size_info_8 *current_size;
1564
1565 current_size = A_SIZE_8(agp_bridge->current_size);
1566
1567 /* aperture size */
1568 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1569
1570 /* address to map to */
1571 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1572 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1573
1574 /* attbase - aperture base */
1575 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1576
1577 /* agpctrl */
1578 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1579
1580 /* mcgcfg */
1581 pci_read_config_word(agp_bridge->dev, INTEL_I850_MCHCFG, &temp2);
1582 pci_write_config_word(agp_bridge->dev, INTEL_I850_MCHCFG, temp2 | (1 << 9));
1583 /* clear any possible AGP-related error conditions */
1584 pci_write_config_word(agp_bridge->dev, INTEL_I850_ERRSTS, 0x001c);
1585 return 0;
1586}
1587
1588static int intel_860_configure(void)
1589{
1590 u32 temp;
1591 u16 temp2;
1592 struct aper_size_info_8 *current_size;
1593
1594 current_size = A_SIZE_8(agp_bridge->current_size);
1595
1596 /* aperture size */
1597 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1598
1599 /* address to map to */
1600 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1601 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1602
1603 /* attbase - aperture base */
1604 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1605
1606 /* agpctrl */
1607 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1608
1609 /* mcgcfg */
1610 pci_read_config_word(agp_bridge->dev, INTEL_I860_MCHCFG, &temp2);
1611 pci_write_config_word(agp_bridge->dev, INTEL_I860_MCHCFG, temp2 | (1 << 9));
1612 /* clear any possible AGP-related error conditions */
1613 pci_write_config_word(agp_bridge->dev, INTEL_I860_ERRSTS, 0xf700);
1614 return 0;
1615}
1616
1617static int intel_830mp_configure(void)
1618{
1619 u32 temp;
1620 u16 temp2;
1621 struct aper_size_info_8 *current_size;
1622
1623 current_size = A_SIZE_8(agp_bridge->current_size);
1624
1625 /* aperture size */
1626 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1627
1628 /* address to map to */
1629 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1630 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1631
1632 /* attbase - aperture base */
1633 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1634
1635 /* agpctrl */
1636 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1637
1638 /* gmch */
1639 pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp2);
1640 pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG, temp2 | (1 << 9));
1641 /* clear any possible AGP-related error conditions */
1642 pci_write_config_word(agp_bridge->dev, INTEL_I830_ERRSTS, 0x1c);
1643 return 0;
1644}
1645
1646static int intel_7505_configure(void)
1647{
1648 u32 temp;
1649 u16 temp2;
1650 struct aper_size_info_8 *current_size;
1651
1652 current_size = A_SIZE_8(agp_bridge->current_size);
1653
1654 /* aperture size */
1655 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1656
1657 /* address to map to */
1658 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1659 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1660
1661 /* attbase - aperture base */
1662 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1663
1664 /* agpctrl */
1665 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1666
1667 /* mchcfg */
1668 pci_read_config_word(agp_bridge->dev, INTEL_I7505_MCHCFG, &temp2);
1669 pci_write_config_word(agp_bridge->dev, INTEL_I7505_MCHCFG, temp2 | (1 << 9));
1670
1671 return 0;
1672}
1673
1674/* Setup function */
Dave Jonese5524f32007-02-22 18:41:28 -05001675static const struct gatt_mask intel_generic_masks[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676{
1677 {.mask = 0x00000017, .type = 0}
1678};
1679
Dave Jonese5524f32007-02-22 18:41:28 -05001680static const struct aper_size_info_8 intel_815_sizes[2] =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681{
1682 {64, 16384, 4, 0},
1683 {32, 8192, 3, 8},
1684};
1685
Dave Jonese5524f32007-02-22 18:41:28 -05001686static const struct aper_size_info_8 intel_8xx_sizes[7] =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687{
1688 {256, 65536, 6, 0},
1689 {128, 32768, 5, 32},
1690 {64, 16384, 4, 48},
1691 {32, 8192, 3, 56},
1692 {16, 4096, 2, 60},
1693 {8, 2048, 1, 62},
1694 {4, 1024, 0, 63}
1695};
1696
Dave Jonese5524f32007-02-22 18:41:28 -05001697static const struct aper_size_info_16 intel_generic_sizes[7] =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698{
1699 {256, 65536, 6, 0},
1700 {128, 32768, 5, 32},
1701 {64, 16384, 4, 48},
1702 {32, 8192, 3, 56},
1703 {16, 4096, 2, 60},
1704 {8, 2048, 1, 62},
1705 {4, 1024, 0, 63}
1706};
1707
Dave Jonese5524f32007-02-22 18:41:28 -05001708static const struct aper_size_info_8 intel_830mp_sizes[4] =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709{
1710 {256, 65536, 6, 0},
1711 {128, 32768, 5, 32},
1712 {64, 16384, 4, 48},
1713 {32, 8192, 3, 56}
1714};
1715
Dave Jonese5524f32007-02-22 18:41:28 -05001716static const struct agp_bridge_driver intel_generic_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717 .owner = THIS_MODULE,
1718 .aperture_sizes = intel_generic_sizes,
1719 .size_type = U16_APER_SIZE,
1720 .num_aperture_sizes = 7,
1721 .configure = intel_configure,
1722 .fetch_size = intel_fetch_size,
1723 .cleanup = intel_cleanup,
1724 .tlb_flush = intel_tlbflush,
1725 .mask_memory = agp_generic_mask_memory,
1726 .masks = intel_generic_masks,
1727 .agp_enable = agp_generic_enable,
1728 .cache_flush = global_cache_flush,
1729 .create_gatt_table = agp_generic_create_gatt_table,
1730 .free_gatt_table = agp_generic_free_gatt_table,
1731 .insert_memory = agp_generic_insert_memory,
1732 .remove_memory = agp_generic_remove_memory,
1733 .alloc_by_type = agp_generic_alloc_by_type,
1734 .free_by_type = agp_generic_free_by_type,
1735 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08001736 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08001738 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001739 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740};
1741
Dave Jonese5524f32007-02-22 18:41:28 -05001742static const struct agp_bridge_driver intel_810_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 .owner = THIS_MODULE,
1744 .aperture_sizes = intel_i810_sizes,
1745 .size_type = FIXED_APER_SIZE,
1746 .num_aperture_sizes = 2,
Joe Perchesc7258012008-03-26 14:10:02 -07001747 .needs_scratch_page = true,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748 .configure = intel_i810_configure,
1749 .fetch_size = intel_i810_fetch_size,
1750 .cleanup = intel_i810_cleanup,
1751 .tlb_flush = intel_i810_tlbflush,
1752 .mask_memory = intel_i810_mask_memory,
1753 .masks = intel_i810_masks,
1754 .agp_enable = intel_i810_agp_enable,
1755 .cache_flush = global_cache_flush,
1756 .create_gatt_table = agp_generic_create_gatt_table,
1757 .free_gatt_table = agp_generic_free_gatt_table,
1758 .insert_memory = intel_i810_insert_entries,
1759 .remove_memory = intel_i810_remove_entries,
1760 .alloc_by_type = intel_i810_alloc_by_type,
1761 .free_by_type = intel_i810_free_by_type,
1762 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08001763 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08001765 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001766 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767};
1768
Dave Jonese5524f32007-02-22 18:41:28 -05001769static const struct agp_bridge_driver intel_815_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 .owner = THIS_MODULE,
1771 .aperture_sizes = intel_815_sizes,
1772 .size_type = U8_APER_SIZE,
1773 .num_aperture_sizes = 2,
1774 .configure = intel_815_configure,
1775 .fetch_size = intel_815_fetch_size,
1776 .cleanup = intel_8xx_cleanup,
1777 .tlb_flush = intel_8xx_tlbflush,
1778 .mask_memory = agp_generic_mask_memory,
1779 .masks = intel_generic_masks,
1780 .agp_enable = agp_generic_enable,
1781 .cache_flush = global_cache_flush,
1782 .create_gatt_table = agp_generic_create_gatt_table,
1783 .free_gatt_table = agp_generic_free_gatt_table,
1784 .insert_memory = agp_generic_insert_memory,
1785 .remove_memory = agp_generic_remove_memory,
1786 .alloc_by_type = agp_generic_alloc_by_type,
1787 .free_by_type = agp_generic_free_by_type,
1788 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08001789 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08001791 .agp_destroy_pages = agp_generic_destroy_pages,
Dave Airlie62c96b92008-06-19 14:27:53 +10001792 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793};
1794
Dave Jonese5524f32007-02-22 18:41:28 -05001795static const struct agp_bridge_driver intel_830_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 .owner = THIS_MODULE,
1797 .aperture_sizes = intel_i830_sizes,
1798 .size_type = FIXED_APER_SIZE,
Dave Jonesc14635e2006-09-06 11:59:35 -04001799 .num_aperture_sizes = 4,
Joe Perchesc7258012008-03-26 14:10:02 -07001800 .needs_scratch_page = true,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801 .configure = intel_i830_configure,
1802 .fetch_size = intel_i830_fetch_size,
1803 .cleanup = intel_i830_cleanup,
1804 .tlb_flush = intel_i810_tlbflush,
1805 .mask_memory = intel_i810_mask_memory,
1806 .masks = intel_i810_masks,
1807 .agp_enable = intel_i810_agp_enable,
1808 .cache_flush = global_cache_flush,
1809 .create_gatt_table = intel_i830_create_gatt_table,
1810 .free_gatt_table = intel_i830_free_gatt_table,
1811 .insert_memory = intel_i830_insert_entries,
1812 .remove_memory = intel_i830_remove_entries,
1813 .alloc_by_type = intel_i830_alloc_by_type,
1814 .free_by_type = intel_i810_free_by_type,
1815 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08001816 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08001818 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001819 .agp_type_to_mask_type = intel_i830_type_to_mask_type,
Dave Airlie2162e6a2007-11-21 16:36:31 +10001820 .chipset_flush = intel_i830_chipset_flush,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821};
1822
Dave Jonese5524f32007-02-22 18:41:28 -05001823static const struct agp_bridge_driver intel_820_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824 .owner = THIS_MODULE,
1825 .aperture_sizes = intel_8xx_sizes,
1826 .size_type = U8_APER_SIZE,
1827 .num_aperture_sizes = 7,
1828 .configure = intel_820_configure,
1829 .fetch_size = intel_8xx_fetch_size,
1830 .cleanup = intel_820_cleanup,
1831 .tlb_flush = intel_820_tlbflush,
1832 .mask_memory = agp_generic_mask_memory,
1833 .masks = intel_generic_masks,
1834 .agp_enable = agp_generic_enable,
1835 .cache_flush = global_cache_flush,
1836 .create_gatt_table = agp_generic_create_gatt_table,
1837 .free_gatt_table = agp_generic_free_gatt_table,
1838 .insert_memory = agp_generic_insert_memory,
1839 .remove_memory = agp_generic_remove_memory,
1840 .alloc_by_type = agp_generic_alloc_by_type,
1841 .free_by_type = agp_generic_free_by_type,
1842 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08001843 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08001845 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001846 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847};
1848
Dave Jonese5524f32007-02-22 18:41:28 -05001849static const struct agp_bridge_driver intel_830mp_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 .owner = THIS_MODULE,
1851 .aperture_sizes = intel_830mp_sizes,
1852 .size_type = U8_APER_SIZE,
1853 .num_aperture_sizes = 4,
1854 .configure = intel_830mp_configure,
1855 .fetch_size = intel_8xx_fetch_size,
1856 .cleanup = intel_8xx_cleanup,
1857 .tlb_flush = intel_8xx_tlbflush,
1858 .mask_memory = agp_generic_mask_memory,
1859 .masks = intel_generic_masks,
1860 .agp_enable = agp_generic_enable,
1861 .cache_flush = global_cache_flush,
1862 .create_gatt_table = agp_generic_create_gatt_table,
1863 .free_gatt_table = agp_generic_free_gatt_table,
1864 .insert_memory = agp_generic_insert_memory,
1865 .remove_memory = agp_generic_remove_memory,
1866 .alloc_by_type = agp_generic_alloc_by_type,
1867 .free_by_type = agp_generic_free_by_type,
1868 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08001869 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08001871 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001872 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873};
1874
Dave Jonese5524f32007-02-22 18:41:28 -05001875static const struct agp_bridge_driver intel_840_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876 .owner = THIS_MODULE,
1877 .aperture_sizes = intel_8xx_sizes,
1878 .size_type = U8_APER_SIZE,
1879 .num_aperture_sizes = 7,
1880 .configure = intel_840_configure,
1881 .fetch_size = intel_8xx_fetch_size,
1882 .cleanup = intel_8xx_cleanup,
1883 .tlb_flush = intel_8xx_tlbflush,
1884 .mask_memory = agp_generic_mask_memory,
1885 .masks = intel_generic_masks,
1886 .agp_enable = agp_generic_enable,
1887 .cache_flush = global_cache_flush,
1888 .create_gatt_table = agp_generic_create_gatt_table,
1889 .free_gatt_table = agp_generic_free_gatt_table,
1890 .insert_memory = agp_generic_insert_memory,
1891 .remove_memory = agp_generic_remove_memory,
1892 .alloc_by_type = agp_generic_alloc_by_type,
1893 .free_by_type = agp_generic_free_by_type,
1894 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08001895 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08001897 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001898 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899};
1900
Dave Jonese5524f32007-02-22 18:41:28 -05001901static const struct agp_bridge_driver intel_845_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902 .owner = THIS_MODULE,
1903 .aperture_sizes = intel_8xx_sizes,
1904 .size_type = U8_APER_SIZE,
1905 .num_aperture_sizes = 7,
1906 .configure = intel_845_configure,
1907 .fetch_size = intel_8xx_fetch_size,
1908 .cleanup = intel_8xx_cleanup,
1909 .tlb_flush = intel_8xx_tlbflush,
1910 .mask_memory = agp_generic_mask_memory,
1911 .masks = intel_generic_masks,
1912 .agp_enable = agp_generic_enable,
1913 .cache_flush = global_cache_flush,
1914 .create_gatt_table = agp_generic_create_gatt_table,
1915 .free_gatt_table = agp_generic_free_gatt_table,
1916 .insert_memory = agp_generic_insert_memory,
1917 .remove_memory = agp_generic_remove_memory,
1918 .alloc_by_type = agp_generic_alloc_by_type,
1919 .free_by_type = agp_generic_free_by_type,
1920 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08001921 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08001923 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001924 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Dave Airlie2162e6a2007-11-21 16:36:31 +10001925 .chipset_flush = intel_i830_chipset_flush,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926};
1927
Dave Jonese5524f32007-02-22 18:41:28 -05001928static const struct agp_bridge_driver intel_850_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929 .owner = THIS_MODULE,
1930 .aperture_sizes = intel_8xx_sizes,
1931 .size_type = U8_APER_SIZE,
1932 .num_aperture_sizes = 7,
1933 .configure = intel_850_configure,
1934 .fetch_size = intel_8xx_fetch_size,
1935 .cleanup = intel_8xx_cleanup,
1936 .tlb_flush = intel_8xx_tlbflush,
1937 .mask_memory = agp_generic_mask_memory,
1938 .masks = intel_generic_masks,
1939 .agp_enable = agp_generic_enable,
1940 .cache_flush = global_cache_flush,
1941 .create_gatt_table = agp_generic_create_gatt_table,
1942 .free_gatt_table = agp_generic_free_gatt_table,
1943 .insert_memory = agp_generic_insert_memory,
1944 .remove_memory = agp_generic_remove_memory,
1945 .alloc_by_type = agp_generic_alloc_by_type,
1946 .free_by_type = agp_generic_free_by_type,
1947 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08001948 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08001950 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001951 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952};
1953
Dave Jonese5524f32007-02-22 18:41:28 -05001954static const struct agp_bridge_driver intel_860_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955 .owner = THIS_MODULE,
1956 .aperture_sizes = intel_8xx_sizes,
1957 .size_type = U8_APER_SIZE,
1958 .num_aperture_sizes = 7,
1959 .configure = intel_860_configure,
1960 .fetch_size = intel_8xx_fetch_size,
1961 .cleanup = intel_8xx_cleanup,
1962 .tlb_flush = intel_8xx_tlbflush,
1963 .mask_memory = agp_generic_mask_memory,
1964 .masks = intel_generic_masks,
1965 .agp_enable = agp_generic_enable,
1966 .cache_flush = global_cache_flush,
1967 .create_gatt_table = agp_generic_create_gatt_table,
1968 .free_gatt_table = agp_generic_free_gatt_table,
1969 .insert_memory = agp_generic_insert_memory,
1970 .remove_memory = agp_generic_remove_memory,
1971 .alloc_by_type = agp_generic_alloc_by_type,
1972 .free_by_type = agp_generic_free_by_type,
1973 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08001974 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08001976 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01001977 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978};
1979
Dave Jonese5524f32007-02-22 18:41:28 -05001980static const struct agp_bridge_driver intel_915_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981 .owner = THIS_MODULE,
1982 .aperture_sizes = intel_i830_sizes,
1983 .size_type = FIXED_APER_SIZE,
Dave Jonesc14635e2006-09-06 11:59:35 -04001984 .num_aperture_sizes = 4,
Joe Perchesc7258012008-03-26 14:10:02 -07001985 .needs_scratch_page = true,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986 .configure = intel_i915_configure,
Eric Anholtc41e0de2006-12-19 12:57:24 -08001987 .fetch_size = intel_i9xx_fetch_size,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988 .cleanup = intel_i915_cleanup,
1989 .tlb_flush = intel_i810_tlbflush,
1990 .mask_memory = intel_i810_mask_memory,
1991 .masks = intel_i810_masks,
1992 .agp_enable = intel_i810_agp_enable,
1993 .cache_flush = global_cache_flush,
1994 .create_gatt_table = intel_i915_create_gatt_table,
1995 .free_gatt_table = intel_i830_free_gatt_table,
1996 .insert_memory = intel_i915_insert_entries,
1997 .remove_memory = intel_i915_remove_entries,
1998 .alloc_by_type = intel_i830_alloc_by_type,
1999 .free_by_type = intel_i810_free_by_type,
2000 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08002001 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08002003 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01002004 .agp_type_to_mask_type = intel_i830_type_to_mask_type,
Dave Airlie6c00a612007-10-29 18:06:10 +10002005 .chipset_flush = intel_i915_chipset_flush,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006};
2007
Dave Jonese5524f32007-02-22 18:41:28 -05002008static const struct agp_bridge_driver intel_i965_driver = {
Dave Airlie62c96b92008-06-19 14:27:53 +10002009 .owner = THIS_MODULE,
2010 .aperture_sizes = intel_i830_sizes,
2011 .size_type = FIXED_APER_SIZE,
2012 .num_aperture_sizes = 4,
2013 .needs_scratch_page = true,
Dave Airlie0e480e52008-06-19 14:57:31 +10002014 .configure = intel_i915_configure,
2015 .fetch_size = intel_i9xx_fetch_size,
Dave Airlie62c96b92008-06-19 14:27:53 +10002016 .cleanup = intel_i915_cleanup,
2017 .tlb_flush = intel_i810_tlbflush,
2018 .mask_memory = intel_i965_mask_memory,
2019 .masks = intel_i810_masks,
2020 .agp_enable = intel_i810_agp_enable,
2021 .cache_flush = global_cache_flush,
2022 .create_gatt_table = intel_i965_create_gatt_table,
2023 .free_gatt_table = intel_i830_free_gatt_table,
2024 .insert_memory = intel_i915_insert_entries,
2025 .remove_memory = intel_i915_remove_entries,
2026 .alloc_by_type = intel_i830_alloc_by_type,
2027 .free_by_type = intel_i810_free_by_type,
2028 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08002029 .agp_alloc_pages = agp_generic_alloc_pages,
Dave Airlie62c96b92008-06-19 14:27:53 +10002030 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08002031 .agp_destroy_pages = agp_generic_destroy_pages,
Dave Airlie62c96b92008-06-19 14:27:53 +10002032 .agp_type_to_mask_type = intel_i830_type_to_mask_type,
Dave Airlie6c00a612007-10-29 18:06:10 +10002033 .chipset_flush = intel_i915_chipset_flush,
Eric Anholt65c25aa2006-09-06 11:57:18 -04002034};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035
Dave Jonese5524f32007-02-22 18:41:28 -05002036static const struct agp_bridge_driver intel_7505_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037 .owner = THIS_MODULE,
2038 .aperture_sizes = intel_8xx_sizes,
2039 .size_type = U8_APER_SIZE,
2040 .num_aperture_sizes = 7,
2041 .configure = intel_7505_configure,
2042 .fetch_size = intel_8xx_fetch_size,
2043 .cleanup = intel_8xx_cleanup,
2044 .tlb_flush = intel_8xx_tlbflush,
2045 .mask_memory = agp_generic_mask_memory,
2046 .masks = intel_generic_masks,
2047 .agp_enable = agp_generic_enable,
2048 .cache_flush = global_cache_flush,
2049 .create_gatt_table = agp_generic_create_gatt_table,
2050 .free_gatt_table = agp_generic_free_gatt_table,
2051 .insert_memory = agp_generic_insert_memory,
2052 .remove_memory = agp_generic_remove_memory,
2053 .alloc_by_type = agp_generic_alloc_by_type,
2054 .free_by_type = agp_generic_free_by_type,
2055 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08002056 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08002058 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +01002059 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060};
2061
Wang Zhenyu874808c62007-06-06 11:16:25 +08002062static const struct agp_bridge_driver intel_g33_driver = {
Dave Airlie62c96b92008-06-19 14:27:53 +10002063 .owner = THIS_MODULE,
2064 .aperture_sizes = intel_i830_sizes,
2065 .size_type = FIXED_APER_SIZE,
2066 .num_aperture_sizes = 4,
2067 .needs_scratch_page = true,
2068 .configure = intel_i915_configure,
2069 .fetch_size = intel_i9xx_fetch_size,
2070 .cleanup = intel_i915_cleanup,
2071 .tlb_flush = intel_i810_tlbflush,
2072 .mask_memory = intel_i965_mask_memory,
2073 .masks = intel_i810_masks,
2074 .agp_enable = intel_i810_agp_enable,
2075 .cache_flush = global_cache_flush,
2076 .create_gatt_table = intel_i915_create_gatt_table,
2077 .free_gatt_table = intel_i830_free_gatt_table,
2078 .insert_memory = intel_i915_insert_entries,
2079 .remove_memory = intel_i915_remove_entries,
2080 .alloc_by_type = intel_i830_alloc_by_type,
2081 .free_by_type = intel_i810_free_by_type,
2082 .agp_alloc_page = agp_generic_alloc_page,
Shaohua Li37acee12008-08-21 10:46:11 +08002083 .agp_alloc_pages = agp_generic_alloc_pages,
Dave Airlie62c96b92008-06-19 14:27:53 +10002084 .agp_destroy_page = agp_generic_destroy_page,
Shaohua Libd079282008-08-21 10:46:17 +08002085 .agp_destroy_pages = agp_generic_destroy_pages,
Dave Airlie62c96b92008-06-19 14:27:53 +10002086 .agp_type_to_mask_type = intel_i830_type_to_mask_type,
Dave Airlie6c00a612007-10-29 18:06:10 +10002087 .chipset_flush = intel_i915_chipset_flush,
Wang Zhenyu874808c62007-06-06 11:16:25 +08002088};
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002089
2090static int find_gmch(u16 device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091{
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002092 struct pci_dev *gmch_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002094 gmch_device = pci_get_device(PCI_VENDOR_ID_INTEL, device, NULL);
2095 if (gmch_device && PCI_FUNC(gmch_device->devfn) != 0) {
2096 gmch_device = pci_get_device(PCI_VENDOR_ID_INTEL,
Dave Airlief011ae72008-01-25 11:23:04 +10002097 device, gmch_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 }
2099
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002100 if (!gmch_device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 return 0;
2102
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002103 intel_private.pcidev = gmch_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104 return 1;
2105}
2106
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002107/* Table to describe Intel GMCH and AGP/PCIE GART drivers. At least one of
2108 * driver and gmch_driver must be non-null, and find_gmch will determine
2109 * which one should be used if a gmch_chip_id is present.
2110 */
2111static const struct intel_driver_description {
2112 unsigned int chip_id;
2113 unsigned int gmch_chip_id;
Wang Zhenyu88889852007-06-14 10:01:04 +08002114 unsigned int multi_gmch_chip; /* if we have more gfx chip type on this HB. */
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002115 char *name;
2116 const struct agp_bridge_driver *driver;
2117 const struct agp_bridge_driver *gmch_driver;
2118} intel_agp_chipsets[] = {
Wang Zhenyu88889852007-06-14 10:01:04 +08002119 { PCI_DEVICE_ID_INTEL_82443LX_0, 0, 0, "440LX", &intel_generic_driver, NULL },
2120 { PCI_DEVICE_ID_INTEL_82443BX_0, 0, 0, "440BX", &intel_generic_driver, NULL },
2121 { PCI_DEVICE_ID_INTEL_82443GX_0, 0, 0, "440GX", &intel_generic_driver, NULL },
2122 { PCI_DEVICE_ID_INTEL_82810_MC1, PCI_DEVICE_ID_INTEL_82810_IG1, 0, "i810",
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002123 NULL, &intel_810_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002124 { PCI_DEVICE_ID_INTEL_82810_MC3, PCI_DEVICE_ID_INTEL_82810_IG3, 0, "i810",
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002125 NULL, &intel_810_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002126 { PCI_DEVICE_ID_INTEL_82810E_MC, PCI_DEVICE_ID_INTEL_82810E_IG, 0, "i810",
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002127 NULL, &intel_810_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002128 { PCI_DEVICE_ID_INTEL_82815_MC, PCI_DEVICE_ID_INTEL_82815_CGC, 0, "i815",
2129 &intel_815_driver, &intel_810_driver },
2130 { PCI_DEVICE_ID_INTEL_82820_HB, 0, 0, "i820", &intel_820_driver, NULL },
2131 { PCI_DEVICE_ID_INTEL_82820_UP_HB, 0, 0, "i820", &intel_820_driver, NULL },
2132 { PCI_DEVICE_ID_INTEL_82830_HB, PCI_DEVICE_ID_INTEL_82830_CGC, 0, "830M",
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002133 &intel_830mp_driver, &intel_830_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002134 { PCI_DEVICE_ID_INTEL_82840_HB, 0, 0, "i840", &intel_840_driver, NULL },
2135 { PCI_DEVICE_ID_INTEL_82845_HB, 0, 0, "845G", &intel_845_driver, NULL },
2136 { PCI_DEVICE_ID_INTEL_82845G_HB, PCI_DEVICE_ID_INTEL_82845G_IG, 0, "830M",
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002137 &intel_845_driver, &intel_830_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002138 { PCI_DEVICE_ID_INTEL_82850_HB, 0, 0, "i850", &intel_850_driver, NULL },
Stefan Husemann347486b2009-04-13 14:40:10 -07002139 { PCI_DEVICE_ID_INTEL_82854_HB, PCI_DEVICE_ID_INTEL_82854_IG, 0, "854",
2140 &intel_845_driver, &intel_830_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002141 { PCI_DEVICE_ID_INTEL_82855PM_HB, 0, 0, "855PM", &intel_845_driver, NULL },
2142 { PCI_DEVICE_ID_INTEL_82855GM_HB, PCI_DEVICE_ID_INTEL_82855GM_IG, 0, "855GM",
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002143 &intel_845_driver, &intel_830_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002144 { PCI_DEVICE_ID_INTEL_82860_HB, 0, 0, "i860", &intel_860_driver, NULL },
2145 { PCI_DEVICE_ID_INTEL_82865_HB, PCI_DEVICE_ID_INTEL_82865_IG, 0, "865",
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002146 &intel_845_driver, &intel_830_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002147 { PCI_DEVICE_ID_INTEL_82875_HB, 0, 0, "i875", &intel_845_driver, NULL },
Carlos Martíne914a362008-01-24 10:34:09 +10002148 { PCI_DEVICE_ID_INTEL_E7221_HB, PCI_DEVICE_ID_INTEL_E7221_IG, 0, "E7221 (i915)",
2149 NULL, &intel_915_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002150 { PCI_DEVICE_ID_INTEL_82915G_HB, PCI_DEVICE_ID_INTEL_82915G_IG, 0, "915G",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002151 NULL, &intel_915_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002152 { PCI_DEVICE_ID_INTEL_82915GM_HB, PCI_DEVICE_ID_INTEL_82915GM_IG, 0, "915GM",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002153 NULL, &intel_915_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002154 { PCI_DEVICE_ID_INTEL_82945G_HB, PCI_DEVICE_ID_INTEL_82945G_IG, 0, "945G",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002155 NULL, &intel_915_driver },
Zhenyu Wangdde47872007-07-26 09:18:09 +08002156 { PCI_DEVICE_ID_INTEL_82945GM_HB, PCI_DEVICE_ID_INTEL_82945GM_IG, 0, "945GM",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002157 NULL, &intel_915_driver },
Zhenyu Wangdde47872007-07-26 09:18:09 +08002158 { PCI_DEVICE_ID_INTEL_82945GME_HB, PCI_DEVICE_ID_INTEL_82945GME_IG, 0, "945GME",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002159 NULL, &intel_915_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002160 { PCI_DEVICE_ID_INTEL_82946GZ_HB, PCI_DEVICE_ID_INTEL_82946GZ_IG, 0, "946GZ",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002161 NULL, &intel_i965_driver },
Zhenyu Wang9119f852008-01-23 15:49:26 +10002162 { PCI_DEVICE_ID_INTEL_82G35_HB, PCI_DEVICE_ID_INTEL_82G35_IG, 0, "G35",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002163 NULL, &intel_i965_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002164 { PCI_DEVICE_ID_INTEL_82965Q_HB, PCI_DEVICE_ID_INTEL_82965Q_IG, 0, "965Q",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002165 NULL, &intel_i965_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002166 { PCI_DEVICE_ID_INTEL_82965G_HB, PCI_DEVICE_ID_INTEL_82965G_IG, 0, "965G",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002167 NULL, &intel_i965_driver },
Zhenyu Wangdde47872007-07-26 09:18:09 +08002168 { PCI_DEVICE_ID_INTEL_82965GM_HB, PCI_DEVICE_ID_INTEL_82965GM_IG, 0, "965GM",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002169 NULL, &intel_i965_driver },
Zhenyu Wangdde47872007-07-26 09:18:09 +08002170 { PCI_DEVICE_ID_INTEL_82965GME_HB, PCI_DEVICE_ID_INTEL_82965GME_IG, 0, "965GME/GLE",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002171 NULL, &intel_i965_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002172 { PCI_DEVICE_ID_INTEL_7505_0, 0, 0, "E7505", &intel_7505_driver, NULL },
2173 { PCI_DEVICE_ID_INTEL_7205_0, 0, 0, "E7205", &intel_7505_driver, NULL },
2174 { PCI_DEVICE_ID_INTEL_G33_HB, PCI_DEVICE_ID_INTEL_G33_IG, 0, "G33",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002175 NULL, &intel_g33_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002176 { PCI_DEVICE_ID_INTEL_Q35_HB, PCI_DEVICE_ID_INTEL_Q35_IG, 0, "Q35",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002177 NULL, &intel_g33_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002178 { PCI_DEVICE_ID_INTEL_Q33_HB, PCI_DEVICE_ID_INTEL_Q33_IG, 0, "Q33",
Wang Zhenyu47d46372007-06-21 13:43:18 +08002179 NULL, &intel_g33_driver },
Shaohua Li21778322009-02-23 15:19:16 +08002180 { PCI_DEVICE_ID_INTEL_IGDGM_HB, PCI_DEVICE_ID_INTEL_IGDGM_IG, 0, "IGD",
2181 NULL, &intel_g33_driver },
2182 { PCI_DEVICE_ID_INTEL_IGDG_HB, PCI_DEVICE_ID_INTEL_IGDG_IG, 0, "IGD",
2183 NULL, &intel_g33_driver },
Zhenyu Wang99d32bd2008-07-30 12:26:50 -07002184 { PCI_DEVICE_ID_INTEL_GM45_HB, PCI_DEVICE_ID_INTEL_GM45_IG, 0,
Eric Anholtb854b2a2008-12-22 18:56:27 -08002185 "Mobile Intel® GM45 Express", NULL, &intel_i965_driver },
Zhenyu Wang25ce77a2008-06-19 14:17:58 +10002186 { PCI_DEVICE_ID_INTEL_IGD_E_HB, PCI_DEVICE_ID_INTEL_IGD_E_IG, 0,
2187 "Intel Integrated Graphics Device", NULL, &intel_i965_driver },
2188 { PCI_DEVICE_ID_INTEL_Q45_HB, PCI_DEVICE_ID_INTEL_Q45_IG, 0,
2189 "Q45/Q43", NULL, &intel_i965_driver },
2190 { PCI_DEVICE_ID_INTEL_G45_HB, PCI_DEVICE_ID_INTEL_G45_IG, 0,
2191 "G45/G43", NULL, &intel_i965_driver },
Zhenyu Wanga50ccc62008-11-17 14:39:00 +08002192 { PCI_DEVICE_ID_INTEL_G41_HB, PCI_DEVICE_ID_INTEL_G41_IG, 0,
2193 "G41", NULL, &intel_i965_driver },
Zhenyu Wang32cb0552009-06-05 15:38:36 +08002194 { PCI_DEVICE_ID_INTEL_IGDNG_D_HB, PCI_DEVICE_ID_INTEL_IGDNG_D_IG, 0,
2195 "IGDNG/D", NULL, &intel_i965_driver },
2196 { PCI_DEVICE_ID_INTEL_IGDNG_M_HB, PCI_DEVICE_ID_INTEL_IGDNG_M_IG, 0,
2197 "IGDNG/M", NULL, &intel_i965_driver },
Wang Zhenyu88889852007-06-14 10:01:04 +08002198 { 0, 0, 0, NULL, NULL, NULL }
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002199};
2200
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201static int __devinit agp_intel_probe(struct pci_dev *pdev,
2202 const struct pci_device_id *ent)
2203{
2204 struct agp_bridge_data *bridge;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205 u8 cap_ptr = 0;
2206 struct resource *r;
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002207 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208
2209 cap_ptr = pci_find_capability(pdev, PCI_CAP_ID_AGP);
2210
2211 bridge = agp_alloc_bridge();
2212 if (!bridge)
2213 return -ENOMEM;
2214
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002215 for (i = 0; intel_agp_chipsets[i].name != NULL; i++) {
2216 /* In case that multiple models of gfx chip may
2217 stand on same host bridge type, this can be
2218 sure we detect the right IGD. */
Wang Zhenyu88889852007-06-14 10:01:04 +08002219 if (pdev->device == intel_agp_chipsets[i].chip_id) {
2220 if ((intel_agp_chipsets[i].gmch_chip_id != 0) &&
2221 find_gmch(intel_agp_chipsets[i].gmch_chip_id)) {
2222 bridge->driver =
2223 intel_agp_chipsets[i].gmch_driver;
2224 break;
2225 } else if (intel_agp_chipsets[i].multi_gmch_chip) {
2226 continue;
2227 } else {
2228 bridge->driver = intel_agp_chipsets[i].driver;
2229 break;
2230 }
2231 }
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002232 }
2233
2234 if (intel_agp_chipsets[i].name == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235 if (cap_ptr)
Bjorn Helgaase3cf6952008-07-30 12:26:51 -07002236 dev_warn(&pdev->dev, "unsupported Intel chipset [%04x/%04x]\n",
2237 pdev->vendor, pdev->device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 agp_put_bridge(bridge);
2239 return -ENODEV;
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002240 }
2241
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002242 if (bridge->driver == NULL) {
Wang Zhenyu47d46372007-06-21 13:43:18 +08002243 /* bridge has no AGP and no IGD detected */
2244 if (cap_ptr)
Bjorn Helgaase3cf6952008-07-30 12:26:51 -07002245 dev_warn(&pdev->dev, "can't find bridge device (chip_id: %04x)\n",
2246 intel_agp_chipsets[i].gmch_chip_id);
Wang Zhenyu9614ece2007-05-30 09:45:58 +08002247 agp_put_bridge(bridge);
2248 return -ENODEV;
Dave Airlief011ae72008-01-25 11:23:04 +10002249 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250
2251 bridge->dev = pdev;
2252 bridge->capndx = cap_ptr;
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08002253 bridge->dev_private_data = &intel_private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254
Bjorn Helgaase3cf6952008-07-30 12:26:51 -07002255 dev_info(&pdev->dev, "Intel %s Chipset\n", intel_agp_chipsets[i].name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256
2257 /*
2258 * The following fixes the case where the BIOS has "forgotten" to
2259 * provide an address range for the GART.
2260 * 20030610 - hamish@zot.org
2261 */
2262 r = &pdev->resource[0];
2263 if (!r->start && r->end) {
Dave Jones6a92a4e2006-02-28 00:54:25 -05002264 if (pci_assign_resource(pdev, 0)) {
Bjorn Helgaase3cf6952008-07-30 12:26:51 -07002265 dev_err(&pdev->dev, "can't assign resource 0\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266 agp_put_bridge(bridge);
2267 return -ENODEV;
2268 }
2269 }
2270
2271 /*
2272 * If the device has not been properly setup, the following will catch
2273 * the problem and should stop the system from crashing.
2274 * 20030610 - hamish@zot.org
2275 */
2276 if (pci_enable_device(pdev)) {
Bjorn Helgaase3cf6952008-07-30 12:26:51 -07002277 dev_err(&pdev->dev, "can't enable PCI device\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278 agp_put_bridge(bridge);
2279 return -ENODEV;
2280 }
2281
2282 /* Fill in the mode register */
2283 if (cap_ptr) {
2284 pci_read_config_dword(pdev,
2285 bridge->capndx+PCI_AGP_STATUS,
2286 &bridge->mode);
2287 }
2288
2289 pci_set_drvdata(pdev, bridge);
2290 return agp_add_bridge(bridge);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291}
2292
2293static void __devexit agp_intel_remove(struct pci_dev *pdev)
2294{
2295 struct agp_bridge_data *bridge = pci_get_drvdata(pdev);
2296
2297 agp_remove_bridge(bridge);
2298
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08002299 if (intel_private.pcidev)
2300 pci_dev_put(intel_private.pcidev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301
2302 agp_put_bridge(bridge);
2303}
2304
Alexey Dobriyan85be7d62006-08-12 02:02:02 +04002305#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306static int agp_intel_resume(struct pci_dev *pdev)
2307{
2308 struct agp_bridge_data *bridge = pci_get_drvdata(pdev);
Keith Packarda8c84df2008-07-31 15:48:07 +10002309 int ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310
2311 pci_restore_state(pdev);
2312
Wang Zhenyu4b953202007-01-17 11:07:54 +08002313 /* We should restore our graphics device's config space,
2314 * as host bridge (00:00) resumes before graphics device (02:00),
2315 * then our access to its pci space can work right.
2316 */
Wang Zhenyuc4ca8812007-05-30 09:40:46 +08002317 if (intel_private.pcidev)
2318 pci_restore_state(intel_private.pcidev);
Wang Zhenyu4b953202007-01-17 11:07:54 +08002319
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320 if (bridge->driver == &intel_generic_driver)
2321 intel_configure();
2322 else if (bridge->driver == &intel_850_driver)
2323 intel_850_configure();
2324 else if (bridge->driver == &intel_845_driver)
2325 intel_845_configure();
2326 else if (bridge->driver == &intel_830mp_driver)
2327 intel_830mp_configure();
2328 else if (bridge->driver == &intel_915_driver)
2329 intel_i915_configure();
2330 else if (bridge->driver == &intel_830_driver)
2331 intel_i830_configure();
2332 else if (bridge->driver == &intel_810_driver)
2333 intel_i810_configure();
Dave Jones08da3f42006-09-10 21:09:26 -04002334 else if (bridge->driver == &intel_i965_driver)
2335 intel_i915_configure();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336
Keith Packarda8c84df2008-07-31 15:48:07 +10002337 ret_val = agp_rebind_memory();
2338 if (ret_val != 0)
2339 return ret_val;
2340
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341 return 0;
2342}
Alexey Dobriyan85be7d62006-08-12 02:02:02 +04002343#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344
2345static struct pci_device_id agp_intel_pci_table[] = {
2346#define ID(x) \
2347 { \
2348 .class = (PCI_CLASS_BRIDGE_HOST << 8), \
2349 .class_mask = ~0, \
2350 .vendor = PCI_VENDOR_ID_INTEL, \
2351 .device = x, \
2352 .subvendor = PCI_ANY_ID, \
2353 .subdevice = PCI_ANY_ID, \
2354 }
2355 ID(PCI_DEVICE_ID_INTEL_82443LX_0),
2356 ID(PCI_DEVICE_ID_INTEL_82443BX_0),
2357 ID(PCI_DEVICE_ID_INTEL_82443GX_0),
2358 ID(PCI_DEVICE_ID_INTEL_82810_MC1),
2359 ID(PCI_DEVICE_ID_INTEL_82810_MC3),
2360 ID(PCI_DEVICE_ID_INTEL_82810E_MC),
2361 ID(PCI_DEVICE_ID_INTEL_82815_MC),
2362 ID(PCI_DEVICE_ID_INTEL_82820_HB),
2363 ID(PCI_DEVICE_ID_INTEL_82820_UP_HB),
2364 ID(PCI_DEVICE_ID_INTEL_82830_HB),
2365 ID(PCI_DEVICE_ID_INTEL_82840_HB),
2366 ID(PCI_DEVICE_ID_INTEL_82845_HB),
2367 ID(PCI_DEVICE_ID_INTEL_82845G_HB),
2368 ID(PCI_DEVICE_ID_INTEL_82850_HB),
Stefan Husemann347486b2009-04-13 14:40:10 -07002369 ID(PCI_DEVICE_ID_INTEL_82854_HB),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370 ID(PCI_DEVICE_ID_INTEL_82855PM_HB),
2371 ID(PCI_DEVICE_ID_INTEL_82855GM_HB),
2372 ID(PCI_DEVICE_ID_INTEL_82860_HB),
2373 ID(PCI_DEVICE_ID_INTEL_82865_HB),
2374 ID(PCI_DEVICE_ID_INTEL_82875_HB),
2375 ID(PCI_DEVICE_ID_INTEL_7505_0),
2376 ID(PCI_DEVICE_ID_INTEL_7205_0),
Carlos Martíne914a362008-01-24 10:34:09 +10002377 ID(PCI_DEVICE_ID_INTEL_E7221_HB),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 ID(PCI_DEVICE_ID_INTEL_82915G_HB),
2379 ID(PCI_DEVICE_ID_INTEL_82915GM_HB),
Alan Hourihaned0de98f2005-05-31 19:50:49 +01002380 ID(PCI_DEVICE_ID_INTEL_82945G_HB),
Alan Hourihane3b0e8ea2006-01-19 14:08:40 +00002381 ID(PCI_DEVICE_ID_INTEL_82945GM_HB),
Zhenyu Wangdde47872007-07-26 09:18:09 +08002382 ID(PCI_DEVICE_ID_INTEL_82945GME_HB),
Shaohua Li21778322009-02-23 15:19:16 +08002383 ID(PCI_DEVICE_ID_INTEL_IGDGM_HB),
2384 ID(PCI_DEVICE_ID_INTEL_IGDG_HB),
Eric Anholt65c25aa2006-09-06 11:57:18 -04002385 ID(PCI_DEVICE_ID_INTEL_82946GZ_HB),
Zhenyu Wang9119f852008-01-23 15:49:26 +10002386 ID(PCI_DEVICE_ID_INTEL_82G35_HB),
Eric Anholt65c25aa2006-09-06 11:57:18 -04002387 ID(PCI_DEVICE_ID_INTEL_82965Q_HB),
2388 ID(PCI_DEVICE_ID_INTEL_82965G_HB),
Wang Zhenyu4598af32007-04-09 08:51:36 +08002389 ID(PCI_DEVICE_ID_INTEL_82965GM_HB),
Zhenyu Wangdde47872007-07-26 09:18:09 +08002390 ID(PCI_DEVICE_ID_INTEL_82965GME_HB),
Wang Zhenyu874808c62007-06-06 11:16:25 +08002391 ID(PCI_DEVICE_ID_INTEL_G33_HB),
2392 ID(PCI_DEVICE_ID_INTEL_Q35_HB),
2393 ID(PCI_DEVICE_ID_INTEL_Q33_HB),
Zhenyu Wang99d32bd2008-07-30 12:26:50 -07002394 ID(PCI_DEVICE_ID_INTEL_GM45_HB),
Zhenyu Wang25ce77a2008-06-19 14:17:58 +10002395 ID(PCI_DEVICE_ID_INTEL_IGD_E_HB),
2396 ID(PCI_DEVICE_ID_INTEL_Q45_HB),
2397 ID(PCI_DEVICE_ID_INTEL_G45_HB),
Zhenyu Wanga50ccc62008-11-17 14:39:00 +08002398 ID(PCI_DEVICE_ID_INTEL_G41_HB),
Zhenyu Wang32cb0552009-06-05 15:38:36 +08002399 ID(PCI_DEVICE_ID_INTEL_IGDNG_D_HB),
2400 ID(PCI_DEVICE_ID_INTEL_IGDNG_M_HB),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401 { }
2402};
2403
2404MODULE_DEVICE_TABLE(pci, agp_intel_pci_table);
2405
2406static struct pci_driver agp_intel_pci_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407 .name = "agpgart-intel",
2408 .id_table = agp_intel_pci_table,
2409 .probe = agp_intel_probe,
2410 .remove = __devexit_p(agp_intel_remove),
Alexey Dobriyan85be7d62006-08-12 02:02:02 +04002411#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412 .resume = agp_intel_resume,
Alexey Dobriyan85be7d62006-08-12 02:02:02 +04002413#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414};
2415
2416static int __init agp_intel_init(void)
2417{
2418 if (agp_off)
2419 return -EINVAL;
2420 return pci_register_driver(&agp_intel_pci_driver);
2421}
2422
2423static void __exit agp_intel_cleanup(void)
2424{
2425 pci_unregister_driver(&agp_intel_pci_driver);
2426}
2427
2428module_init(agp_intel_init);
2429module_exit(agp_intel_cleanup);
2430
Dave Jonesf4432c52008-10-20 13:31:45 -04002431MODULE_AUTHOR("Dave Jones <davej@redhat.com>");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432MODULE_LICENSE("GPL and additional rights");