2 * Intel AGPGART routines.
5 #include <linux/module.h>
7 #include <linux/init.h>
8 #include <linux/kernel.h>
9 #include <linux/pagemap.h>
10 #include <linux/agp_backend.h>
13 #define PCI_DEVICE_ID_INTEL_E7221_HB 0x2588
14 #define PCI_DEVICE_ID_INTEL_E7221_IG 0x258a
15 #define PCI_DEVICE_ID_INTEL_82946GZ_HB 0x2970
16 #define PCI_DEVICE_ID_INTEL_82946GZ_IG 0x2972
17 #define PCI_DEVICE_ID_INTEL_82G35_HB 0x2980
18 #define PCI_DEVICE_ID_INTEL_82G35_IG 0x2982
19 #define PCI_DEVICE_ID_INTEL_82965Q_HB 0x2990
20 #define PCI_DEVICE_ID_INTEL_82965Q_IG 0x2992
21 #define PCI_DEVICE_ID_INTEL_82965G_HB 0x29A0
22 #define PCI_DEVICE_ID_INTEL_82965G_IG 0x29A2
23 #define PCI_DEVICE_ID_INTEL_82965GM_HB 0x2A00
24 #define PCI_DEVICE_ID_INTEL_82965GM_IG 0x2A02
25 #define PCI_DEVICE_ID_INTEL_82965GME_HB 0x2A10
26 #define PCI_DEVICE_ID_INTEL_82965GME_IG 0x2A12
27 #define PCI_DEVICE_ID_INTEL_82945GME_HB 0x27AC
28 #define PCI_DEVICE_ID_INTEL_82945GME_IG 0x27AE
29 #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
33 #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
39 #define PCI_DEVICE_ID_INTEL_GM45_HB 0x2A40
40 #define PCI_DEVICE_ID_INTEL_GM45_IG 0x2A42
41 #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
47 #define PCI_DEVICE_ID_INTEL_G41_HB 0x2E30
48 #define PCI_DEVICE_ID_INTEL_G41_IG 0x2E32
49 #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
54 /* 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)
62 #define IS_I965 (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82946GZ_HB || \
63 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 || \
67 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965GME_HB)
69 #define IS_G33 (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_G33_HB || \
70 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_Q35_HB || \
71 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)
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)
78 #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 || \
80 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_G45_HB || \
81 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_GM45_HB || \
82 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)
86 extern int agp_memory_reserved;
89 /* Intel 815 register */
90 #define INTEL_815_APCONT 0x51
91 #define INTEL_815_ATTBASE_MASK ~0x1FFFFFFF
93 /* Intel i820 registers */
94 #define INTEL_I820_RDCR 0x51
95 #define INTEL_I820_ERRSTS 0xc8
97 /* Intel i840 registers */
98 #define INTEL_I840_MCHCFG 0x50
99 #define INTEL_I840_ERRSTS 0xc8
101 /* Intel i850 registers */
102 #define INTEL_I850_MCHCFG 0x50
103 #define INTEL_I850_ERRSTS 0xc8
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)
111 #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)
118 #define I915_IFPADDR 0x60
120 /* Intel 965G registers */
121 #define I965_MSAC 0x62
122 #define I965_IFPADDR 0x70
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
133 static const struct aper_size_info_fixed intel_i810_sizes[] =
136 /* The 32M mode still requires a 64k gatt */
140 #define AGP_DCACHE_MEMORY 1
141 #define AGP_PHYS_MEMORY 2
142 #define INTEL_AGP_CACHED_MEMORY 3
144 static struct gatt_mask intel_i810_masks[] =
146 {.mask = I810_PTE_VALID, .type = 0},
147 {.mask = (I810_PTE_VALID | I810_PTE_LOCAL), .type = AGP_DCACHE_MEMORY},
148 {.mask = I810_PTE_VALID, .type = 0},
149 {.mask = I810_PTE_VALID | I830_PTE_SYSTEM_CACHED,
150 .type = INTEL_AGP_CACHED_MEMORY}
153 static struct _intel_private {
154 struct pci_dev *pcidev; /* device one */
155 u8 __iomem *registers;
156 u32 __iomem *gtt; /* I915G */
157 int num_dcache_entries;
158 /* 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.
163 int gtt_entries; /* i830+ */
165 void __iomem *i9xx_flush_page;
166 void *i8xx_flush_page;
168 struct page *i8xx_page;
169 struct resource ifp_resource;
173 static int intel_i810_fetch_size(void)
176 struct aper_size_info_fixed *values;
178 pci_read_config_dword(agp_bridge->dev, I810_SMRAM_MISCC, &smram_miscc);
179 values = A_SIZE_FIX(agp_bridge->driver->aperture_sizes);
181 if ((smram_miscc & I810_GMS) == I810_GMS_DISABLE) {
182 dev_warn(&agp_bridge->dev->dev, "i810 is disabled\n");
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;
191 agp_bridge->previous_size =
192 agp_bridge->current_size = (void *) (values);
193 agp_bridge->aperture_size_idx = 0;
194 return values[0].size;
200 static int intel_i810_configure(void)
202 struct aper_size_info_fixed *current_size;
206 current_size = A_SIZE_FIX(agp_bridge->current_size);
208 if (!intel_private.registers) {
209 pci_read_config_dword(intel_private.pcidev, I810_MMADDR, &temp);
212 intel_private.registers = ioremap(temp, 128 * 4096);
213 if (!intel_private.registers) {
214 dev_err(&intel_private.pcidev->dev,
215 "can't remap memory\n");
220 if ((readl(intel_private.registers+I810_DRAM_CTL)
221 & I810_DRAM_ROW_0) == I810_DRAM_ROW_0_SDRAM) {
222 /* This will need to be dynamically assigned */
223 dev_info(&intel_private.pcidev->dev,
224 "detected 4MB dedicated video ram\n");
225 intel_private.num_dcache_entries = 1024;
227 pci_read_config_dword(intel_private.pcidev, I810_GMADDR, &temp);
228 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
229 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. */
232 if (agp_bridge->driver->needs_scratch_page) {
233 for (i = 0; i < current_size->num_entries; i++) {
234 writel(agp_bridge->scratch_page, intel_private.registers+I810_PTE_BASE+(i*4));
236 readl(intel_private.registers+I810_PTE_BASE+((i-1)*4)); /* PCI posting. */
238 global_cache_flush();
242 static void intel_i810_cleanup(void)
244 writel(0, intel_private.registers+I810_PGETBL_CTL);
245 readl(intel_private.registers); /* PCI Posting. */
246 iounmap(intel_private.registers);
249 static void intel_i810_tlbflush(struct agp_memory *mem)
254 static void intel_i810_agp_enable(struct agp_bridge_data *bridge, u32 mode)
259 /* Exists to support ARGB cursors */
260 static void *i8xx_alloc_pages(void)
264 page = alloc_pages(GFP_KERNEL | GFP_DMA32, 2);
268 if (set_pages_uc(page, 4) < 0) {
269 set_pages_wb(page, 4);
270 __free_pages(page, 2);
274 atomic_inc(&agp_bridge->current_memory_agp);
275 return page_address(page);
278 static void i8xx_destroy_pages(void *addr)
285 page = virt_to_page(addr);
286 set_pages_wb(page, 4);
288 __free_pages(page, 2);
289 atomic_dec(&agp_bridge->current_memory_agp);
292 static int intel_i830_type_to_mask_type(struct agp_bridge_data *bridge,
295 if (type < AGP_USER_TYPES)
297 else if (type == AGP_USER_CACHED_MEMORY)
298 return INTEL_AGP_CACHED_MEMORY;
303 static int intel_i810_insert_entries(struct agp_memory *mem, off_t pg_start,
306 int i, j, num_entries;
311 if (mem->page_count == 0)
314 temp = agp_bridge->current_size;
315 num_entries = A_SIZE_FIX(temp)->num_entries;
317 if ((pg_start + mem->page_count) > num_entries)
321 for (j = pg_start; j < (pg_start + mem->page_count); j++) {
322 if (!PGE_EMPTY(agp_bridge, readl(agp_bridge->gatt_table+j))) {
328 if (type != mem->type)
331 mask_type = agp_bridge->driver->agp_type_to_mask_type(agp_bridge, type);
334 case AGP_DCACHE_MEMORY:
335 if (!mem->is_flushed)
336 global_cache_flush();
337 for (i = pg_start; i < (pg_start + mem->page_count); i++) {
338 writel((i*4096)|I810_PTE_LOCAL|I810_PTE_VALID,
339 intel_private.registers+I810_PTE_BASE+(i*4));
341 readl(intel_private.registers+I810_PTE_BASE+((i-1)*4));
343 case AGP_PHYS_MEMORY:
344 case AGP_NORMAL_MEMORY:
345 if (!mem->is_flushed)
346 global_cache_flush();
347 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
348 writel(agp_bridge->driver->mask_memory(agp_bridge,
351 intel_private.registers+I810_PTE_BASE+(j*4));
353 readl(intel_private.registers+I810_PTE_BASE+((j-1)*4));
359 agp_bridge->driver->tlb_flush(mem);
363 mem->is_flushed = true;
367 static int intel_i810_remove_entries(struct agp_memory *mem, off_t pg_start,
372 if (mem->page_count == 0)
375 for (i = pg_start; i < (mem->page_count + pg_start); i++) {
376 writel(agp_bridge->scratch_page, intel_private.registers+I810_PTE_BASE+(i*4));
378 readl(intel_private.registers+I810_PTE_BASE+((i-1)*4));
380 agp_bridge->driver->tlb_flush(mem);
385 * The i810/i830 requires a physical address to program its mouse
386 * pointer into hardware.
387 * However the Xserver still writes to it through the agp aperture.
389 static struct agp_memory *alloc_agpphysmem_i8xx(size_t pg_count, int type)
391 struct agp_memory *new;
395 case 1: addr = agp_bridge->driver->agp_alloc_page(agp_bridge);
398 /* kludge to get 4 physical pages for ARGB cursor */
399 addr = i8xx_alloc_pages();
408 new = agp_create_memory(pg_count);
412 new->memory[0] = virt_to_gart(addr);
414 /* kludge to get 4 physical pages for ARGB cursor */
415 new->memory[1] = new->memory[0] + PAGE_SIZE;
416 new->memory[2] = new->memory[1] + PAGE_SIZE;
417 new->memory[3] = new->memory[2] + PAGE_SIZE;
419 new->page_count = pg_count;
420 new->num_scratch_pages = pg_count;
421 new->type = AGP_PHYS_MEMORY;
422 new->physical = new->memory[0];
426 static struct agp_memory *intel_i810_alloc_by_type(size_t pg_count, int type)
428 struct agp_memory *new;
430 if (type == AGP_DCACHE_MEMORY) {
431 if (pg_count != intel_private.num_dcache_entries)
434 new = agp_create_memory(1);
438 new->type = AGP_DCACHE_MEMORY;
439 new->page_count = pg_count;
440 new->num_scratch_pages = 0;
441 agp_free_page_array(new);
444 if (type == AGP_PHYS_MEMORY)
445 return alloc_agpphysmem_i8xx(pg_count, type);
449 static void intel_i810_free_by_type(struct agp_memory *curr)
451 agp_free_key(curr->key);
452 if (curr->type == AGP_PHYS_MEMORY) {
453 if (curr->page_count == 4)
454 i8xx_destroy_pages(gart_to_virt(curr->memory[0]));
456 void *va = gart_to_virt(curr->memory[0]);
458 agp_bridge->driver->agp_destroy_page(va,
459 AGP_PAGE_DESTROY_UNMAP);
460 agp_bridge->driver->agp_destroy_page(va,
461 AGP_PAGE_DESTROY_FREE);
463 agp_free_page_array(curr);
468 static unsigned long intel_i810_mask_memory(struct agp_bridge_data *bridge,
469 unsigned long addr, int type)
471 /* Type checking must be done elsewhere */
472 return addr | bridge->driver->masks[type].mask;
475 static struct aper_size_info_fixed intel_i830_sizes[] =
478 /* The 64M mode still requires a 128k gatt */
484 static void intel_i830_init_gtt_entries(void)
490 static const int ddt[4] = { 0, 16, 32, 64 };
491 int size; /* reserved space (in kb) at the top of stolen memory */
493 pci_read_config_word(agp_bridge->dev, I830_GMCH_CTRL, &gmch_ctrl);
497 pgetbl_ctl = readl(intel_private.registers+I810_PGETBL_CTL);
499 /* The 965 has a field telling us the size of the GTT,
500 * which may be larger than what is necessary to map the
503 switch (pgetbl_ctl & I965_PGETBL_SIZE_MASK) {
504 case I965_PGETBL_SIZE_128KB:
507 case I965_PGETBL_SIZE_256KB:
510 case I965_PGETBL_SIZE_512KB:
513 case I965_PGETBL_SIZE_1MB:
516 case I965_PGETBL_SIZE_2MB:
519 case I965_PGETBL_SIZE_1_5MB:
523 dev_info(&intel_private.pcidev->dev,
524 "unknown page table size, assuming 512KB\n");
527 size += 4; /* add in BIOS popup space */
528 } else if (IS_G33 && !IS_IGD) {
529 /* G33's GTT size defined in gmch_ctrl */
530 switch (gmch_ctrl & G33_PGETBL_SIZE_MASK) {
531 case G33_PGETBL_SIZE_1M:
534 case G33_PGETBL_SIZE_2M:
538 dev_info(&agp_bridge->dev->dev,
539 "unknown page table size 0x%x, assuming 512KB\n",
540 (gmch_ctrl & G33_PGETBL_SIZE_MASK));
544 } else if (IS_G4X || IS_IGD) {
545 /* On 4 series hardware, GTT stolen is separate from graphics
546 * stolen, ignore it in stolen gtt entries counting. However,
547 * 4KB of the stolen memory doesn't get mapped to the GTT.
551 /* On previous hardware, the GTT size was just what was
552 * required to map the aperture.
554 size = agp_bridge->driver->fetch_size() + 4;
557 if (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82830_HB ||
558 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82845G_HB) {
559 switch (gmch_ctrl & I830_GMCH_GMS_MASK) {
560 case I830_GMCH_GMS_STOLEN_512:
561 gtt_entries = KB(512) - KB(size);
563 case I830_GMCH_GMS_STOLEN_1024:
564 gtt_entries = MB(1) - KB(size);
566 case I830_GMCH_GMS_STOLEN_8192:
567 gtt_entries = MB(8) - KB(size);
569 case I830_GMCH_GMS_LOCAL:
570 rdct = readb(intel_private.registers+I830_RDRAM_CHANNEL_TYPE);
571 gtt_entries = (I830_RDRAM_ND(rdct) + 1) *
572 MB(ddt[I830_RDRAM_DDT(rdct)]);
580 switch (gmch_ctrl & I855_GMCH_GMS_MASK) {
581 case I855_GMCH_GMS_STOLEN_1M:
582 gtt_entries = MB(1) - KB(size);
584 case I855_GMCH_GMS_STOLEN_4M:
585 gtt_entries = MB(4) - KB(size);
587 case I855_GMCH_GMS_STOLEN_8M:
588 gtt_entries = MB(8) - KB(size);
590 case I855_GMCH_GMS_STOLEN_16M:
591 gtt_entries = MB(16) - KB(size);
593 case I855_GMCH_GMS_STOLEN_32M:
594 gtt_entries = MB(32) - KB(size);
596 case I915_GMCH_GMS_STOLEN_48M:
597 /* Check it's really I915G */
598 if (IS_I915 || IS_I965 || IS_G33 || IS_G4X)
599 gtt_entries = MB(48) - KB(size);
603 case I915_GMCH_GMS_STOLEN_64M:
604 /* Check it's really I915G */
605 if (IS_I915 || IS_I965 || IS_G33 || IS_G4X)
606 gtt_entries = MB(64) - KB(size);
610 case G33_GMCH_GMS_STOLEN_128M:
611 if (IS_G33 || IS_I965 || IS_G4X)
612 gtt_entries = MB(128) - KB(size);
616 case G33_GMCH_GMS_STOLEN_256M:
617 if (IS_G33 || IS_I965 || IS_G4X)
618 gtt_entries = MB(256) - KB(size);
622 case INTEL_GMCH_GMS_STOLEN_96M:
623 if (IS_I965 || IS_G4X)
624 gtt_entries = MB(96) - KB(size);
628 case INTEL_GMCH_GMS_STOLEN_160M:
629 if (IS_I965 || IS_G4X)
630 gtt_entries = MB(160) - KB(size);
634 case INTEL_GMCH_GMS_STOLEN_224M:
635 if (IS_I965 || IS_G4X)
636 gtt_entries = MB(224) - KB(size);
640 case INTEL_GMCH_GMS_STOLEN_352M:
641 if (IS_I965 || IS_G4X)
642 gtt_entries = MB(352) - KB(size);
651 if (gtt_entries > 0) {
652 dev_info(&agp_bridge->dev->dev, "detected %dK %s memory\n",
653 gtt_entries / KB(1), local ? "local" : "stolen");
654 gtt_entries /= KB(4);
656 dev_info(&agp_bridge->dev->dev,
657 "no pre-allocated video memory detected\n");
661 intel_private.gtt_entries = gtt_entries;
664 static void intel_i830_fini_flush(void)
666 kunmap(intel_private.i8xx_page);
667 intel_private.i8xx_flush_page = NULL;
668 unmap_page_from_agp(intel_private.i8xx_page);
670 __free_page(intel_private.i8xx_page);
671 intel_private.i8xx_page = NULL;
674 static void intel_i830_setup_flush(void)
676 /* return if we've already set the flush mechanism up */
677 if (intel_private.i8xx_page)
680 intel_private.i8xx_page = alloc_page(GFP_KERNEL | __GFP_ZERO | GFP_DMA32);
681 if (!intel_private.i8xx_page)
684 /* make page uncached */
685 map_page_into_agp(intel_private.i8xx_page);
687 intel_private.i8xx_flush_page = kmap(intel_private.i8xx_page);
688 if (!intel_private.i8xx_flush_page)
689 intel_i830_fini_flush();
692 static void intel_i830_chipset_flush(struct agp_bridge_data *bridge)
694 unsigned int *pg = intel_private.i8xx_flush_page;
697 for (i = 0; i < 256; i += 2)
703 /* The intel i830 automatically initializes the agp aperture during POST.
704 * Use the memory already set aside for in the GTT.
706 static int intel_i830_create_gatt_table(struct agp_bridge_data *bridge)
709 struct aper_size_info_fixed *size;
713 size = agp_bridge->current_size;
714 page_order = size->page_order;
715 num_entries = size->num_entries;
716 agp_bridge->gatt_table_real = NULL;
718 pci_read_config_dword(intel_private.pcidev, I810_MMADDR, &temp);
721 intel_private.registers = ioremap(temp, 128 * 4096);
722 if (!intel_private.registers)
725 temp = readl(intel_private.registers+I810_PGETBL_CTL) & 0xfffff000;
726 global_cache_flush(); /* FIXME: ?? */
728 /* we have to call this as early as possible after the MMIO base address is known */
729 intel_i830_init_gtt_entries();
731 agp_bridge->gatt_table = NULL;
733 agp_bridge->gatt_bus_addr = temp;
738 /* Return the gatt table to a sane state. Use the top of stolen
739 * memory for the GTT.
741 static int intel_i830_free_gatt_table(struct agp_bridge_data *bridge)
746 static int intel_i830_fetch_size(void)
749 struct aper_size_info_fixed *values;
751 values = A_SIZE_FIX(agp_bridge->driver->aperture_sizes);
753 if (agp_bridge->dev->device != PCI_DEVICE_ID_INTEL_82830_HB &&
754 agp_bridge->dev->device != PCI_DEVICE_ID_INTEL_82845G_HB) {
755 /* 855GM/852GM/865G has 128MB aperture size */
756 agp_bridge->previous_size = agp_bridge->current_size = (void *) values;
757 agp_bridge->aperture_size_idx = 0;
758 return values[0].size;
761 pci_read_config_word(agp_bridge->dev, I830_GMCH_CTRL, &gmch_ctrl);
763 if ((gmch_ctrl & I830_GMCH_MEM_MASK) == I830_GMCH_MEM_128M) {
764 agp_bridge->previous_size = agp_bridge->current_size = (void *) values;
765 agp_bridge->aperture_size_idx = 0;
766 return values[0].size;
768 agp_bridge->previous_size = agp_bridge->current_size = (void *) (values + 1);
769 agp_bridge->aperture_size_idx = 1;
770 return values[1].size;
776 static int intel_i830_configure(void)
778 struct aper_size_info_fixed *current_size;
783 current_size = A_SIZE_FIX(agp_bridge->current_size);
785 pci_read_config_dword(intel_private.pcidev, I810_GMADDR, &temp);
786 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
788 pci_read_config_word(agp_bridge->dev, I830_GMCH_CTRL, &gmch_ctrl);
789 gmch_ctrl |= I830_GMCH_ENABLED;
790 pci_write_config_word(agp_bridge->dev, I830_GMCH_CTRL, gmch_ctrl);
792 writel(agp_bridge->gatt_bus_addr|I810_PGETBL_ENABLED, intel_private.registers+I810_PGETBL_CTL);
793 readl(intel_private.registers+I810_PGETBL_CTL); /* PCI Posting. */
795 if (agp_bridge->driver->needs_scratch_page) {
796 for (i = intel_private.gtt_entries; i < current_size->num_entries; i++) {
797 writel(agp_bridge->scratch_page, intel_private.registers+I810_PTE_BASE+(i*4));
799 readl(intel_private.registers+I810_PTE_BASE+((i-1)*4)); /* PCI Posting. */
802 global_cache_flush();
804 intel_i830_setup_flush();
808 static void intel_i830_cleanup(void)
810 iounmap(intel_private.registers);
813 static int intel_i830_insert_entries(struct agp_memory *mem, off_t pg_start,
816 int i, j, num_entries;
821 if (mem->page_count == 0)
824 temp = agp_bridge->current_size;
825 num_entries = A_SIZE_FIX(temp)->num_entries;
827 if (pg_start < intel_private.gtt_entries) {
828 dev_printk(KERN_DEBUG, &intel_private.pcidev->dev,
829 "pg_start == 0x%.8lx, intel_private.gtt_entries == 0x%.8x\n",
830 pg_start, intel_private.gtt_entries);
832 dev_info(&intel_private.pcidev->dev,
833 "trying to insert into local/stolen memory\n");
837 if ((pg_start + mem->page_count) > num_entries)
840 /* The i830 can't check the GTT for entries since its read only,
841 * depend on the caller to make the correct offset decisions.
844 if (type != mem->type)
847 mask_type = agp_bridge->driver->agp_type_to_mask_type(agp_bridge, type);
849 if (mask_type != 0 && mask_type != AGP_PHYS_MEMORY &&
850 mask_type != INTEL_AGP_CACHED_MEMORY)
853 if (!mem->is_flushed)
854 global_cache_flush();
856 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
857 writel(agp_bridge->driver->mask_memory(agp_bridge,
858 mem->memory[i], mask_type),
859 intel_private.registers+I810_PTE_BASE+(j*4));
861 readl(intel_private.registers+I810_PTE_BASE+((j-1)*4));
862 agp_bridge->driver->tlb_flush(mem);
867 mem->is_flushed = true;
871 static int intel_i830_remove_entries(struct agp_memory *mem, off_t pg_start,
876 if (mem->page_count == 0)
879 if (pg_start < intel_private.gtt_entries) {
880 dev_info(&intel_private.pcidev->dev,
881 "trying to disable local/stolen memory\n");
885 for (i = pg_start; i < (mem->page_count + pg_start); i++) {
886 writel(agp_bridge->scratch_page, intel_private.registers+I810_PTE_BASE+(i*4));
888 readl(intel_private.registers+I810_PTE_BASE+((i-1)*4));
890 agp_bridge->driver->tlb_flush(mem);
894 static struct agp_memory *intel_i830_alloc_by_type(size_t pg_count, int type)
896 if (type == AGP_PHYS_MEMORY)
897 return alloc_agpphysmem_i8xx(pg_count, type);
898 /* always return NULL for other allocation types for now */
902 static int intel_alloc_chipset_flush_resource(void)
905 ret = pci_bus_alloc_resource(agp_bridge->dev->bus, &intel_private.ifp_resource, PAGE_SIZE,
906 PAGE_SIZE, PCIBIOS_MIN_MEM, 0,
907 pcibios_align_resource, agp_bridge->dev);
912 static void intel_i915_setup_chipset_flush(void)
917 pci_read_config_dword(agp_bridge->dev, I915_IFPADDR, &temp);
919 intel_alloc_chipset_flush_resource();
920 intel_private.resource_valid = 1;
921 pci_write_config_dword(agp_bridge->dev, I915_IFPADDR, (intel_private.ifp_resource.start & 0xffffffff) | 0x1);
925 intel_private.resource_valid = 1;
926 intel_private.ifp_resource.start = temp;
927 intel_private.ifp_resource.end = temp + PAGE_SIZE;
928 ret = request_resource(&iomem_resource, &intel_private.ifp_resource);
929 /* some BIOSes reserve this area in a pnp some don't */
931 intel_private.resource_valid = 0;
935 static void intel_i965_g33_setup_chipset_flush(void)
937 u32 temp_hi, temp_lo;
940 pci_read_config_dword(agp_bridge->dev, I965_IFPADDR + 4, &temp_hi);
941 pci_read_config_dword(agp_bridge->dev, I965_IFPADDR, &temp_lo);
943 if (!(temp_lo & 0x1)) {
945 intel_alloc_chipset_flush_resource();
947 intel_private.resource_valid = 1;
948 pci_write_config_dword(agp_bridge->dev, I965_IFPADDR + 4,
949 upper_32_bits(intel_private.ifp_resource.start));
950 pci_write_config_dword(agp_bridge->dev, I965_IFPADDR, (intel_private.ifp_resource.start & 0xffffffff) | 0x1);
955 l64 = ((u64)temp_hi << 32) | temp_lo;
957 intel_private.resource_valid = 1;
958 intel_private.ifp_resource.start = l64;
959 intel_private.ifp_resource.end = l64 + PAGE_SIZE;
960 ret = request_resource(&iomem_resource, &intel_private.ifp_resource);
961 /* some BIOSes reserve this area in a pnp some don't */
963 intel_private.resource_valid = 0;
967 static void intel_i9xx_setup_flush(void)
969 /* return if already configured */
970 if (intel_private.ifp_resource.start)
973 /* setup a resource for this object */
974 intel_private.ifp_resource.name = "Intel Flush Page";
975 intel_private.ifp_resource.flags = IORESOURCE_MEM;
977 /* Setup chipset flush for 915 */
978 if (IS_I965 || IS_G33 || IS_G4X) {
979 intel_i965_g33_setup_chipset_flush();
981 intel_i915_setup_chipset_flush();
984 if (intel_private.ifp_resource.start) {
985 intel_private.i9xx_flush_page = ioremap_nocache(intel_private.ifp_resource.start, PAGE_SIZE);
986 if (!intel_private.i9xx_flush_page)
987 dev_info(&intel_private.pcidev->dev, "can't ioremap flush page - no chipset flushing");
991 static int intel_i915_configure(void)
993 struct aper_size_info_fixed *current_size;
998 current_size = A_SIZE_FIX(agp_bridge->current_size);
1000 pci_read_config_dword(intel_private.pcidev, I915_GMADDR, &temp);
1002 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1004 pci_read_config_word(agp_bridge->dev, I830_GMCH_CTRL, &gmch_ctrl);
1005 gmch_ctrl |= I830_GMCH_ENABLED;
1006 pci_write_config_word(agp_bridge->dev, I830_GMCH_CTRL, gmch_ctrl);
1008 writel(agp_bridge->gatt_bus_addr|I810_PGETBL_ENABLED, intel_private.registers+I810_PGETBL_CTL);
1009 readl(intel_private.registers+I810_PGETBL_CTL); /* PCI Posting. */
1011 if (agp_bridge->driver->needs_scratch_page) {
1012 for (i = intel_private.gtt_entries; i < current_size->num_entries; i++) {
1013 writel(agp_bridge->scratch_page, intel_private.gtt+i);
1015 readl(intel_private.gtt+i-1); /* PCI Posting. */
1018 global_cache_flush();
1020 intel_i9xx_setup_flush();
1025 static void intel_i915_cleanup(void)
1027 if (intel_private.i9xx_flush_page)
1028 iounmap(intel_private.i9xx_flush_page);
1029 if (intel_private.resource_valid)
1030 release_resource(&intel_private.ifp_resource);
1031 intel_private.ifp_resource.start = 0;
1032 intel_private.resource_valid = 0;
1033 iounmap(intel_private.gtt);
1034 iounmap(intel_private.registers);
1037 static void intel_i915_chipset_flush(struct agp_bridge_data *bridge)
1039 if (intel_private.i9xx_flush_page)
1040 writel(1, intel_private.i9xx_flush_page);
1043 static int intel_i915_insert_entries(struct agp_memory *mem, off_t pg_start,
1046 int i, j, num_entries;
1051 if (mem->page_count == 0)
1054 temp = agp_bridge->current_size;
1055 num_entries = A_SIZE_FIX(temp)->num_entries;
1057 if (pg_start < intel_private.gtt_entries) {
1058 dev_printk(KERN_DEBUG, &intel_private.pcidev->dev,
1059 "pg_start == 0x%.8lx, intel_private.gtt_entries == 0x%.8x\n",
1060 pg_start, intel_private.gtt_entries);
1062 dev_info(&intel_private.pcidev->dev,
1063 "trying to insert into local/stolen memory\n");
1067 if ((pg_start + mem->page_count) > num_entries)
1070 /* The i915 can't check the GTT for entries since its read only,
1071 * depend on the caller to make the correct offset decisions.
1074 if (type != mem->type)
1077 mask_type = agp_bridge->driver->agp_type_to_mask_type(agp_bridge, type);
1079 if (mask_type != 0 && mask_type != AGP_PHYS_MEMORY &&
1080 mask_type != INTEL_AGP_CACHED_MEMORY)
1083 if (!mem->is_flushed)
1084 global_cache_flush();
1086 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
1087 writel(agp_bridge->driver->mask_memory(agp_bridge,
1088 mem->memory[i], mask_type), intel_private.gtt+j);
1091 readl(intel_private.gtt+j-1);
1092 agp_bridge->driver->tlb_flush(mem);
1097 mem->is_flushed = true;
1101 static int intel_i915_remove_entries(struct agp_memory *mem, off_t pg_start,
1106 if (mem->page_count == 0)
1109 if (pg_start < intel_private.gtt_entries) {
1110 dev_info(&intel_private.pcidev->dev,
1111 "trying to disable local/stolen memory\n");
1115 for (i = pg_start; i < (mem->page_count + pg_start); i++)
1116 writel(agp_bridge->scratch_page, intel_private.gtt+i);
1118 readl(intel_private.gtt+i-1);
1120 agp_bridge->driver->tlb_flush(mem);
1124 /* Return the aperture size by just checking the resource length. The effect
1125 * described in the spec of the MSAC registers is just changing of the
1128 static int intel_i9xx_fetch_size(void)
1130 int num_sizes = ARRAY_SIZE(intel_i830_sizes);
1131 int aper_size; /* size in megabytes */
1134 aper_size = pci_resource_len(intel_private.pcidev, 2) / MB(1);
1136 for (i = 0; i < num_sizes; i++) {
1137 if (aper_size == intel_i830_sizes[i].size) {
1138 agp_bridge->current_size = intel_i830_sizes + i;
1139 agp_bridge->previous_size = agp_bridge->current_size;
1147 /* The intel i915 automatically initializes the agp aperture during POST.
1148 * Use the memory already set aside for in the GTT.
1150 static int intel_i915_create_gatt_table(struct agp_bridge_data *bridge)
1153 struct aper_size_info_fixed *size;
1156 int gtt_map_size = 256 * 1024;
1158 size = agp_bridge->current_size;
1159 page_order = size->page_order;
1160 num_entries = size->num_entries;
1161 agp_bridge->gatt_table_real = NULL;
1163 pci_read_config_dword(intel_private.pcidev, I915_MMADDR, &temp);
1164 pci_read_config_dword(intel_private.pcidev, I915_PTEADDR, &temp2);
1167 gtt_map_size = 1024 * 1024; /* 1M on G33 */
1168 intel_private.gtt = ioremap(temp2, gtt_map_size);
1169 if (!intel_private.gtt)
1174 intel_private.registers = ioremap(temp, 128 * 4096);
1175 if (!intel_private.registers) {
1176 iounmap(intel_private.gtt);
1180 temp = readl(intel_private.registers+I810_PGETBL_CTL) & 0xfffff000;
1181 global_cache_flush(); /* FIXME: ? */
1183 /* we have to call this as early as possible after the MMIO base address is known */
1184 intel_i830_init_gtt_entries();
1186 agp_bridge->gatt_table = NULL;
1188 agp_bridge->gatt_bus_addr = temp;
1194 * The i965 supports 36-bit physical addresses, but to keep
1195 * the format of the GTT the same, the bits that don't fit
1196 * in a 32-bit word are shifted down to bits 4..7.
1198 * Gcc is smart enough to notice that "(addr >> 28) & 0xf0"
1199 * is always zero on 32-bit architectures, so no need to make
1202 static unsigned long intel_i965_mask_memory(struct agp_bridge_data *bridge,
1203 unsigned long addr, int type)
1205 /* Shift high bits down */
1206 addr |= (addr >> 28) & 0xf0;
1208 /* Type checking must be done elsewhere */
1209 return addr | bridge->driver->masks[type].mask;
1212 static void intel_i965_get_gtt_range(int *gtt_offset, int *gtt_size)
1214 switch (agp_bridge->dev->device) {
1215 case PCI_DEVICE_ID_INTEL_GM45_HB:
1216 case PCI_DEVICE_ID_INTEL_IGD_E_HB:
1217 case PCI_DEVICE_ID_INTEL_Q45_HB:
1218 case PCI_DEVICE_ID_INTEL_G45_HB:
1219 case PCI_DEVICE_ID_INTEL_G41_HB:
1220 case PCI_DEVICE_ID_INTEL_IGDNG_D_HB:
1221 case PCI_DEVICE_ID_INTEL_IGDNG_M_HB:
1222 *gtt_offset = *gtt_size = MB(2);
1225 *gtt_offset = *gtt_size = KB(512);
1229 /* The intel i965 automatically initializes the agp aperture during POST.
1230 * Use the memory already set aside for in the GTT.
1232 static int intel_i965_create_gatt_table(struct agp_bridge_data *bridge)
1235 struct aper_size_info_fixed *size;
1238 int gtt_offset, gtt_size;
1240 size = agp_bridge->current_size;
1241 page_order = size->page_order;
1242 num_entries = size->num_entries;
1243 agp_bridge->gatt_table_real = NULL;
1245 pci_read_config_dword(intel_private.pcidev, I915_MMADDR, &temp);
1249 intel_i965_get_gtt_range(>t_offset, >t_size);
1251 intel_private.gtt = ioremap((temp + gtt_offset) , gtt_size);
1253 if (!intel_private.gtt)
1256 intel_private.registers = ioremap(temp, 128 * 4096);
1257 if (!intel_private.registers) {
1258 iounmap(intel_private.gtt);
1262 temp = readl(intel_private.registers+I810_PGETBL_CTL) & 0xfffff000;
1263 global_cache_flush(); /* FIXME: ? */
1265 /* we have to call this as early as possible after the MMIO base address is known */
1266 intel_i830_init_gtt_entries();
1268 agp_bridge->gatt_table = NULL;
1270 agp_bridge->gatt_bus_addr = temp;
1276 static int intel_fetch_size(void)
1280 struct aper_size_info_16 *values;
1282 pci_read_config_word(agp_bridge->dev, INTEL_APSIZE, &temp);
1283 values = A_SIZE_16(agp_bridge->driver->aperture_sizes);
1285 for (i = 0; i < agp_bridge->driver->num_aperture_sizes; i++) {
1286 if (temp == values[i].size_value) {
1287 agp_bridge->previous_size = agp_bridge->current_size = (void *) (values + i);
1288 agp_bridge->aperture_size_idx = i;
1289 return values[i].size;
1296 static int __intel_8xx_fetch_size(u8 temp)
1299 struct aper_size_info_8 *values;
1301 values = A_SIZE_8(agp_bridge->driver->aperture_sizes);
1303 for (i = 0; i < agp_bridge->driver->num_aperture_sizes; i++) {
1304 if (temp == values[i].size_value) {
1305 agp_bridge->previous_size =
1306 agp_bridge->current_size = (void *) (values + i);
1307 agp_bridge->aperture_size_idx = i;
1308 return values[i].size;
1314 static int intel_8xx_fetch_size(void)
1318 pci_read_config_byte(agp_bridge->dev, INTEL_APSIZE, &temp);
1319 return __intel_8xx_fetch_size(temp);
1322 static int intel_815_fetch_size(void)
1326 /* Intel 815 chipsets have a _weird_ APSIZE register with only
1327 * one non-reserved bit, so mask the others out ... */
1328 pci_read_config_byte(agp_bridge->dev, INTEL_APSIZE, &temp);
1331 return __intel_8xx_fetch_size(temp);
1334 static void intel_tlbflush(struct agp_memory *mem)
1336 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x2200);
1337 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x2280);
1341 static void intel_8xx_tlbflush(struct agp_memory *mem)
1344 pci_read_config_dword(agp_bridge->dev, INTEL_AGPCTRL, &temp);
1345 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, temp & ~(1 << 7));
1346 pci_read_config_dword(agp_bridge->dev, INTEL_AGPCTRL, &temp);
1347 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, temp | (1 << 7));
1351 static void intel_cleanup(void)
1354 struct aper_size_info_16 *previous_size;
1356 previous_size = A_SIZE_16(agp_bridge->previous_size);
1357 pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp);
1358 pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG, temp & ~(1 << 9));
1359 pci_write_config_word(agp_bridge->dev, INTEL_APSIZE, previous_size->size_value);
1363 static void intel_8xx_cleanup(void)
1366 struct aper_size_info_8 *previous_size;
1368 previous_size = A_SIZE_8(agp_bridge->previous_size);
1369 pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp);
1370 pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG, temp & ~(1 << 9));
1371 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, previous_size->size_value);
1375 static int intel_configure(void)
1379 struct aper_size_info_16 *current_size;
1381 current_size = A_SIZE_16(agp_bridge->current_size);
1384 pci_write_config_word(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1386 /* address to map to */
1387 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1388 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1390 /* attbase - aperture base */
1391 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1394 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x2280);
1397 pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp2);
1398 pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG,
1399 (temp2 & ~(1 << 10)) | (1 << 9));
1400 /* clear any possible error conditions */
1401 pci_write_config_byte(agp_bridge->dev, INTEL_ERRSTS + 1, 7);
1405 static int intel_815_configure(void)
1409 struct aper_size_info_8 *current_size;
1411 /* attbase - aperture base */
1412 /* the Intel 815 chipset spec. says that bits 29-31 in the
1413 * ATTBASE register are reserved -> try not to write them */
1414 if (agp_bridge->gatt_bus_addr & INTEL_815_ATTBASE_MASK) {
1415 dev_emerg(&agp_bridge->dev->dev, "gatt bus addr too high");
1419 current_size = A_SIZE_8(agp_bridge->current_size);
1422 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE,
1423 current_size->size_value);
1425 /* address to map to */
1426 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1427 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1429 pci_read_config_dword(agp_bridge->dev, INTEL_ATTBASE, &addr);
1430 addr &= INTEL_815_ATTBASE_MASK;
1431 addr |= agp_bridge->gatt_bus_addr;
1432 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, addr);
1435 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1438 pci_read_config_byte(agp_bridge->dev, INTEL_815_APCONT, &temp2);
1439 pci_write_config_byte(agp_bridge->dev, INTEL_815_APCONT, temp2 | (1 << 1));
1441 /* clear any possible error conditions */
1442 /* Oddness : this chipset seems to have no ERRSTS register ! */
1446 static void intel_820_tlbflush(struct agp_memory *mem)
1451 static void intel_820_cleanup(void)
1454 struct aper_size_info_8 *previous_size;
1456 previous_size = A_SIZE_8(agp_bridge->previous_size);
1457 pci_read_config_byte(agp_bridge->dev, INTEL_I820_RDCR, &temp);
1458 pci_write_config_byte(agp_bridge->dev, INTEL_I820_RDCR,
1460 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE,
1461 previous_size->size_value);
1465 static int intel_820_configure(void)
1469 struct aper_size_info_8 *current_size;
1471 current_size = A_SIZE_8(agp_bridge->current_size);
1474 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1476 /* address to map to */
1477 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1478 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1480 /* attbase - aperture base */
1481 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1484 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1486 /* global enable aperture access */
1487 /* This flag is not accessed through MCHCFG register as in */
1489 pci_read_config_byte(agp_bridge->dev, INTEL_I820_RDCR, &temp2);
1490 pci_write_config_byte(agp_bridge->dev, INTEL_I820_RDCR, temp2 | (1 << 1));
1491 /* clear any possible AGP-related error conditions */
1492 pci_write_config_word(agp_bridge->dev, INTEL_I820_ERRSTS, 0x001c);
1496 static int intel_840_configure(void)
1500 struct aper_size_info_8 *current_size;
1502 current_size = A_SIZE_8(agp_bridge->current_size);
1505 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1507 /* address to map to */
1508 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1509 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1511 /* attbase - aperture base */
1512 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1515 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1518 pci_read_config_word(agp_bridge->dev, INTEL_I840_MCHCFG, &temp2);
1519 pci_write_config_word(agp_bridge->dev, INTEL_I840_MCHCFG, temp2 | (1 << 9));
1520 /* clear any possible error conditions */
1521 pci_write_config_word(agp_bridge->dev, INTEL_I840_ERRSTS, 0xc000);
1525 static int intel_845_configure(void)
1529 struct aper_size_info_8 *current_size;
1531 current_size = A_SIZE_8(agp_bridge->current_size);
1534 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1536 if (agp_bridge->apbase_config != 0) {
1537 pci_write_config_dword(agp_bridge->dev, AGP_APBASE,
1538 agp_bridge->apbase_config);
1540 /* address to map to */
1541 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1542 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1543 agp_bridge->apbase_config = temp;
1546 /* attbase - aperture base */
1547 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1550 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1553 pci_read_config_byte(agp_bridge->dev, INTEL_I845_AGPM, &temp2);
1554 pci_write_config_byte(agp_bridge->dev, INTEL_I845_AGPM, temp2 | (1 << 1));
1555 /* clear any possible error conditions */
1556 pci_write_config_word(agp_bridge->dev, INTEL_I845_ERRSTS, 0x001c);
1558 intel_i830_setup_flush();
1562 static int intel_850_configure(void)
1566 struct aper_size_info_8 *current_size;
1568 current_size = A_SIZE_8(agp_bridge->current_size);
1571 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1573 /* address to map to */
1574 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1575 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1577 /* attbase - aperture base */
1578 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1581 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1584 pci_read_config_word(agp_bridge->dev, INTEL_I850_MCHCFG, &temp2);
1585 pci_write_config_word(agp_bridge->dev, INTEL_I850_MCHCFG, temp2 | (1 << 9));
1586 /* clear any possible AGP-related error conditions */
1587 pci_write_config_word(agp_bridge->dev, INTEL_I850_ERRSTS, 0x001c);
1591 static int intel_860_configure(void)
1595 struct aper_size_info_8 *current_size;
1597 current_size = A_SIZE_8(agp_bridge->current_size);
1600 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1602 /* address to map to */
1603 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1604 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1606 /* attbase - aperture base */
1607 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1610 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1613 pci_read_config_word(agp_bridge->dev, INTEL_I860_MCHCFG, &temp2);
1614 pci_write_config_word(agp_bridge->dev, INTEL_I860_MCHCFG, temp2 | (1 << 9));
1615 /* clear any possible AGP-related error conditions */
1616 pci_write_config_word(agp_bridge->dev, INTEL_I860_ERRSTS, 0xf700);
1620 static int intel_830mp_configure(void)
1624 struct aper_size_info_8 *current_size;
1626 current_size = A_SIZE_8(agp_bridge->current_size);
1629 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1631 /* address to map to */
1632 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1633 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1635 /* attbase - aperture base */
1636 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1639 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1642 pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp2);
1643 pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG, temp2 | (1 << 9));
1644 /* clear any possible AGP-related error conditions */
1645 pci_write_config_word(agp_bridge->dev, INTEL_I830_ERRSTS, 0x1c);
1649 static int intel_7505_configure(void)
1653 struct aper_size_info_8 *current_size;
1655 current_size = A_SIZE_8(agp_bridge->current_size);
1658 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1660 /* address to map to */
1661 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1662 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1664 /* attbase - aperture base */
1665 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1668 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1671 pci_read_config_word(agp_bridge->dev, INTEL_I7505_MCHCFG, &temp2);
1672 pci_write_config_word(agp_bridge->dev, INTEL_I7505_MCHCFG, temp2 | (1 << 9));
1677 /* Setup function */
1678 static const struct gatt_mask intel_generic_masks[] =
1680 {.mask = 0x00000017, .type = 0}
1683 static const struct aper_size_info_8 intel_815_sizes[2] =
1689 static const struct aper_size_info_8 intel_8xx_sizes[7] =
1692 {128, 32768, 5, 32},
1700 static const struct aper_size_info_16 intel_generic_sizes[7] =
1703 {128, 32768, 5, 32},
1711 static const struct aper_size_info_8 intel_830mp_sizes[4] =
1714 {128, 32768, 5, 32},
1719 static const struct agp_bridge_driver intel_generic_driver = {
1720 .owner = THIS_MODULE,
1721 .aperture_sizes = intel_generic_sizes,
1722 .size_type = U16_APER_SIZE,
1723 .num_aperture_sizes = 7,
1724 .configure = intel_configure,
1725 .fetch_size = intel_fetch_size,
1726 .cleanup = intel_cleanup,
1727 .tlb_flush = intel_tlbflush,
1728 .mask_memory = agp_generic_mask_memory,
1729 .masks = intel_generic_masks,
1730 .agp_enable = agp_generic_enable,
1731 .cache_flush = global_cache_flush,
1732 .create_gatt_table = agp_generic_create_gatt_table,
1733 .free_gatt_table = agp_generic_free_gatt_table,
1734 .insert_memory = agp_generic_insert_memory,
1735 .remove_memory = agp_generic_remove_memory,
1736 .alloc_by_type = agp_generic_alloc_by_type,
1737 .free_by_type = agp_generic_free_by_type,
1738 .agp_alloc_page = agp_generic_alloc_page,
1739 .agp_alloc_pages = agp_generic_alloc_pages,
1740 .agp_destroy_page = agp_generic_destroy_page,
1741 .agp_destroy_pages = agp_generic_destroy_pages,
1742 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
1745 static const struct agp_bridge_driver intel_810_driver = {
1746 .owner = THIS_MODULE,
1747 .aperture_sizes = intel_i810_sizes,
1748 .size_type = FIXED_APER_SIZE,
1749 .num_aperture_sizes = 2,
1750 .needs_scratch_page = true,
1751 .configure = intel_i810_configure,
1752 .fetch_size = intel_i810_fetch_size,
1753 .cleanup = intel_i810_cleanup,
1754 .tlb_flush = intel_i810_tlbflush,
1755 .mask_memory = intel_i810_mask_memory,
1756 .masks = intel_i810_masks,
1757 .agp_enable = intel_i810_agp_enable,
1758 .cache_flush = global_cache_flush,
1759 .create_gatt_table = agp_generic_create_gatt_table,
1760 .free_gatt_table = agp_generic_free_gatt_table,
1761 .insert_memory = intel_i810_insert_entries,
1762 .remove_memory = intel_i810_remove_entries,
1763 .alloc_by_type = intel_i810_alloc_by_type,
1764 .free_by_type = intel_i810_free_by_type,
1765 .agp_alloc_page = agp_generic_alloc_page,
1766 .agp_alloc_pages = agp_generic_alloc_pages,
1767 .agp_destroy_page = agp_generic_destroy_page,
1768 .agp_destroy_pages = agp_generic_destroy_pages,
1769 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
1772 static const struct agp_bridge_driver intel_815_driver = {
1773 .owner = THIS_MODULE,
1774 .aperture_sizes = intel_815_sizes,
1775 .size_type = U8_APER_SIZE,
1776 .num_aperture_sizes = 2,
1777 .configure = intel_815_configure,
1778 .fetch_size = intel_815_fetch_size,
1779 .cleanup = intel_8xx_cleanup,
1780 .tlb_flush = intel_8xx_tlbflush,
1781 .mask_memory = agp_generic_mask_memory,
1782 .masks = intel_generic_masks,
1783 .agp_enable = agp_generic_enable,
1784 .cache_flush = global_cache_flush,
1785 .create_gatt_table = agp_generic_create_gatt_table,
1786 .free_gatt_table = agp_generic_free_gatt_table,
1787 .insert_memory = agp_generic_insert_memory,
1788 .remove_memory = agp_generic_remove_memory,
1789 .alloc_by_type = agp_generic_alloc_by_type,
1790 .free_by_type = agp_generic_free_by_type,
1791 .agp_alloc_page = agp_generic_alloc_page,
1792 .agp_alloc_pages = agp_generic_alloc_pages,
1793 .agp_destroy_page = agp_generic_destroy_page,
1794 .agp_destroy_pages = agp_generic_destroy_pages,
1795 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
1798 static const struct agp_bridge_driver intel_830_driver = {
1799 .owner = THIS_MODULE,
1800 .aperture_sizes = intel_i830_sizes,
1801 .size_type = FIXED_APER_SIZE,
1802 .num_aperture_sizes = 4,
1803 .needs_scratch_page = true,
1804 .configure = intel_i830_configure,
1805 .fetch_size = intel_i830_fetch_size,
1806 .cleanup = intel_i830_cleanup,
1807 .tlb_flush = intel_i810_tlbflush,
1808 .mask_memory = intel_i810_mask_memory,
1809 .masks = intel_i810_masks,
1810 .agp_enable = intel_i810_agp_enable,
1811 .cache_flush = global_cache_flush,
1812 .create_gatt_table = intel_i830_create_gatt_table,
1813 .free_gatt_table = intel_i830_free_gatt_table,
1814 .insert_memory = intel_i830_insert_entries,
1815 .remove_memory = intel_i830_remove_entries,
1816 .alloc_by_type = intel_i830_alloc_by_type,
1817 .free_by_type = intel_i810_free_by_type,
1818 .agp_alloc_page = agp_generic_alloc_page,
1819 .agp_alloc_pages = agp_generic_alloc_pages,
1820 .agp_destroy_page = agp_generic_destroy_page,
1821 .agp_destroy_pages = agp_generic_destroy_pages,
1822 .agp_type_to_mask_type = intel_i830_type_to_mask_type,
1823 .chipset_flush = intel_i830_chipset_flush,
1826 static const struct agp_bridge_driver intel_820_driver = {
1827 .owner = THIS_MODULE,
1828 .aperture_sizes = intel_8xx_sizes,
1829 .size_type = U8_APER_SIZE,
1830 .num_aperture_sizes = 7,
1831 .configure = intel_820_configure,
1832 .fetch_size = intel_8xx_fetch_size,
1833 .cleanup = intel_820_cleanup,
1834 .tlb_flush = intel_820_tlbflush,
1835 .mask_memory = agp_generic_mask_memory,
1836 .masks = intel_generic_masks,
1837 .agp_enable = agp_generic_enable,
1838 .cache_flush = global_cache_flush,
1839 .create_gatt_table = agp_generic_create_gatt_table,
1840 .free_gatt_table = agp_generic_free_gatt_table,
1841 .insert_memory = agp_generic_insert_memory,
1842 .remove_memory = agp_generic_remove_memory,
1843 .alloc_by_type = agp_generic_alloc_by_type,
1844 .free_by_type = agp_generic_free_by_type,
1845 .agp_alloc_page = agp_generic_alloc_page,
1846 .agp_alloc_pages = agp_generic_alloc_pages,
1847 .agp_destroy_page = agp_generic_destroy_page,
1848 .agp_destroy_pages = agp_generic_destroy_pages,
1849 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
1852 static const struct agp_bridge_driver intel_830mp_driver = {
1853 .owner = THIS_MODULE,
1854 .aperture_sizes = intel_830mp_sizes,
1855 .size_type = U8_APER_SIZE,
1856 .num_aperture_sizes = 4,
1857 .configure = intel_830mp_configure,
1858 .fetch_size = intel_8xx_fetch_size,
1859 .cleanup = intel_8xx_cleanup,
1860 .tlb_flush = intel_8xx_tlbflush,
1861 .mask_memory = agp_generic_mask_memory,
1862 .masks = intel_generic_masks,
1863 .agp_enable = agp_generic_enable,
1864 .cache_flush = global_cache_flush,
1865 .create_gatt_table = agp_generic_create_gatt_table,
1866 .free_gatt_table = agp_generic_free_gatt_table,
1867 .insert_memory = agp_generic_insert_memory,
1868 .remove_memory = agp_generic_remove_memory,
1869 .alloc_by_type = agp_generic_alloc_by_type,
1870 .free_by_type = agp_generic_free_by_type,
1871 .agp_alloc_page = agp_generic_alloc_page,
1872 .agp_alloc_pages = agp_generic_alloc_pages,
1873 .agp_destroy_page = agp_generic_destroy_page,
1874 .agp_destroy_pages = agp_generic_destroy_pages,
1875 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
1878 static const struct agp_bridge_driver intel_840_driver = {
1879 .owner = THIS_MODULE,
1880 .aperture_sizes = intel_8xx_sizes,
1881 .size_type = U8_APER_SIZE,
1882 .num_aperture_sizes = 7,
1883 .configure = intel_840_configure,
1884 .fetch_size = intel_8xx_fetch_size,
1885 .cleanup = intel_8xx_cleanup,
1886 .tlb_flush = intel_8xx_tlbflush,
1887 .mask_memory = agp_generic_mask_memory,
1888 .masks = intel_generic_masks,
1889 .agp_enable = agp_generic_enable,
1890 .cache_flush = global_cache_flush,
1891 .create_gatt_table = agp_generic_create_gatt_table,
1892 .free_gatt_table = agp_generic_free_gatt_table,
1893 .insert_memory = agp_generic_insert_memory,
1894 .remove_memory = agp_generic_remove_memory,
1895 .alloc_by_type = agp_generic_alloc_by_type,
1896 .free_by_type = agp_generic_free_by_type,
1897 .agp_alloc_page = agp_generic_alloc_page,
1898 .agp_alloc_pages = agp_generic_alloc_pages,
1899 .agp_destroy_page = agp_generic_destroy_page,
1900 .agp_destroy_pages = agp_generic_destroy_pages,
1901 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
1904 static const struct agp_bridge_driver intel_845_driver = {
1905 .owner = THIS_MODULE,
1906 .aperture_sizes = intel_8xx_sizes,
1907 .size_type = U8_APER_SIZE,
1908 .num_aperture_sizes = 7,
1909 .configure = intel_845_configure,
1910 .fetch_size = intel_8xx_fetch_size,
1911 .cleanup = intel_8xx_cleanup,
1912 .tlb_flush = intel_8xx_tlbflush,
1913 .mask_memory = agp_generic_mask_memory,
1914 .masks = intel_generic_masks,
1915 .agp_enable = agp_generic_enable,
1916 .cache_flush = global_cache_flush,
1917 .create_gatt_table = agp_generic_create_gatt_table,
1918 .free_gatt_table = agp_generic_free_gatt_table,
1919 .insert_memory = agp_generic_insert_memory,
1920 .remove_memory = agp_generic_remove_memory,
1921 .alloc_by_type = agp_generic_alloc_by_type,
1922 .free_by_type = agp_generic_free_by_type,
1923 .agp_alloc_page = agp_generic_alloc_page,
1924 .agp_alloc_pages = agp_generic_alloc_pages,
1925 .agp_destroy_page = agp_generic_destroy_page,
1926 .agp_destroy_pages = agp_generic_destroy_pages,
1927 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
1928 .chipset_flush = intel_i830_chipset_flush,
1931 static const struct agp_bridge_driver intel_850_driver = {
1932 .owner = THIS_MODULE,
1933 .aperture_sizes = intel_8xx_sizes,
1934 .size_type = U8_APER_SIZE,
1935 .num_aperture_sizes = 7,
1936 .configure = intel_850_configure,
1937 .fetch_size = intel_8xx_fetch_size,
1938 .cleanup = intel_8xx_cleanup,
1939 .tlb_flush = intel_8xx_tlbflush,
1940 .mask_memory = agp_generic_mask_memory,
1941 .masks = intel_generic_masks,
1942 .agp_enable = agp_generic_enable,
1943 .cache_flush = global_cache_flush,
1944 .create_gatt_table = agp_generic_create_gatt_table,
1945 .free_gatt_table = agp_generic_free_gatt_table,
1946 .insert_memory = agp_generic_insert_memory,
1947 .remove_memory = agp_generic_remove_memory,
1948 .alloc_by_type = agp_generic_alloc_by_type,
1949 .free_by_type = agp_generic_free_by_type,
1950 .agp_alloc_page = agp_generic_alloc_page,
1951 .agp_alloc_pages = agp_generic_alloc_pages,
1952 .agp_destroy_page = agp_generic_destroy_page,
1953 .agp_destroy_pages = agp_generic_destroy_pages,
1954 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
1957 static const struct agp_bridge_driver intel_860_driver = {
1958 .owner = THIS_MODULE,
1959 .aperture_sizes = intel_8xx_sizes,
1960 .size_type = U8_APER_SIZE,
1961 .num_aperture_sizes = 7,
1962 .configure = intel_860_configure,
1963 .fetch_size = intel_8xx_fetch_size,
1964 .cleanup = intel_8xx_cleanup,
1965 .tlb_flush = intel_8xx_tlbflush,
1966 .mask_memory = agp_generic_mask_memory,
1967 .masks = intel_generic_masks,
1968 .agp_enable = agp_generic_enable,
1969 .cache_flush = global_cache_flush,
1970 .create_gatt_table = agp_generic_create_gatt_table,
1971 .free_gatt_table = agp_generic_free_gatt_table,
1972 .insert_memory = agp_generic_insert_memory,
1973 .remove_memory = agp_generic_remove_memory,
1974 .alloc_by_type = agp_generic_alloc_by_type,
1975 .free_by_type = agp_generic_free_by_type,
1976 .agp_alloc_page = agp_generic_alloc_page,
1977 .agp_alloc_pages = agp_generic_alloc_pages,
1978 .agp_destroy_page = agp_generic_destroy_page,
1979 .agp_destroy_pages = agp_generic_destroy_pages,
1980 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
1983 static const struct agp_bridge_driver intel_915_driver = {
1984 .owner = THIS_MODULE,
1985 .aperture_sizes = intel_i830_sizes,
1986 .size_type = FIXED_APER_SIZE,
1987 .num_aperture_sizes = 4,
1988 .needs_scratch_page = true,
1989 .configure = intel_i915_configure,
1990 .fetch_size = intel_i9xx_fetch_size,
1991 .cleanup = intel_i915_cleanup,
1992 .tlb_flush = intel_i810_tlbflush,
1993 .mask_memory = intel_i810_mask_memory,
1994 .masks = intel_i810_masks,
1995 .agp_enable = intel_i810_agp_enable,
1996 .cache_flush = global_cache_flush,
1997 .create_gatt_table = intel_i915_create_gatt_table,
1998 .free_gatt_table = intel_i830_free_gatt_table,
1999 .insert_memory = intel_i915_insert_entries,
2000 .remove_memory = intel_i915_remove_entries,
2001 .alloc_by_type = intel_i830_alloc_by_type,
2002 .free_by_type = intel_i810_free_by_type,
2003 .agp_alloc_page = agp_generic_alloc_page,
2004 .agp_alloc_pages = agp_generic_alloc_pages,
2005 .agp_destroy_page = agp_generic_destroy_page,
2006 .agp_destroy_pages = agp_generic_destroy_pages,
2007 .agp_type_to_mask_type = intel_i830_type_to_mask_type,
2008 .chipset_flush = intel_i915_chipset_flush,
2011 static const struct agp_bridge_driver intel_i965_driver = {
2012 .owner = THIS_MODULE,
2013 .aperture_sizes = intel_i830_sizes,
2014 .size_type = FIXED_APER_SIZE,
2015 .num_aperture_sizes = 4,
2016 .needs_scratch_page = true,
2017 .configure = intel_i915_configure,
2018 .fetch_size = intel_i9xx_fetch_size,
2019 .cleanup = intel_i915_cleanup,
2020 .tlb_flush = intel_i810_tlbflush,
2021 .mask_memory = intel_i965_mask_memory,
2022 .masks = intel_i810_masks,
2023 .agp_enable = intel_i810_agp_enable,
2024 .cache_flush = global_cache_flush,
2025 .create_gatt_table = intel_i965_create_gatt_table,
2026 .free_gatt_table = intel_i830_free_gatt_table,
2027 .insert_memory = intel_i915_insert_entries,
2028 .remove_memory = intel_i915_remove_entries,
2029 .alloc_by_type = intel_i830_alloc_by_type,
2030 .free_by_type = intel_i810_free_by_type,
2031 .agp_alloc_page = agp_generic_alloc_page,
2032 .agp_alloc_pages = agp_generic_alloc_pages,
2033 .agp_destroy_page = agp_generic_destroy_page,
2034 .agp_destroy_pages = agp_generic_destroy_pages,
2035 .agp_type_to_mask_type = intel_i830_type_to_mask_type,
2036 .chipset_flush = intel_i915_chipset_flush,
2039 static const struct agp_bridge_driver intel_7505_driver = {
2040 .owner = THIS_MODULE,
2041 .aperture_sizes = intel_8xx_sizes,
2042 .size_type = U8_APER_SIZE,
2043 .num_aperture_sizes = 7,
2044 .configure = intel_7505_configure,
2045 .fetch_size = intel_8xx_fetch_size,
2046 .cleanup = intel_8xx_cleanup,
2047 .tlb_flush = intel_8xx_tlbflush,
2048 .mask_memory = agp_generic_mask_memory,
2049 .masks = intel_generic_masks,
2050 .agp_enable = agp_generic_enable,
2051 .cache_flush = global_cache_flush,
2052 .create_gatt_table = agp_generic_create_gatt_table,
2053 .free_gatt_table = agp_generic_free_gatt_table,
2054 .insert_memory = agp_generic_insert_memory,
2055 .remove_memory = agp_generic_remove_memory,
2056 .alloc_by_type = agp_generic_alloc_by_type,
2057 .free_by_type = agp_generic_free_by_type,
2058 .agp_alloc_page = agp_generic_alloc_page,
2059 .agp_alloc_pages = agp_generic_alloc_pages,
2060 .agp_destroy_page = agp_generic_destroy_page,
2061 .agp_destroy_pages = agp_generic_destroy_pages,
2062 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
2065 static const struct agp_bridge_driver intel_g33_driver = {
2066 .owner = THIS_MODULE,
2067 .aperture_sizes = intel_i830_sizes,
2068 .size_type = FIXED_APER_SIZE,
2069 .num_aperture_sizes = 4,
2070 .needs_scratch_page = true,
2071 .configure = intel_i915_configure,
2072 .fetch_size = intel_i9xx_fetch_size,
2073 .cleanup = intel_i915_cleanup,
2074 .tlb_flush = intel_i810_tlbflush,
2075 .mask_memory = intel_i965_mask_memory,
2076 .masks = intel_i810_masks,
2077 .agp_enable = intel_i810_agp_enable,
2078 .cache_flush = global_cache_flush,
2079 .create_gatt_table = intel_i915_create_gatt_table,
2080 .free_gatt_table = intel_i830_free_gatt_table,
2081 .insert_memory = intel_i915_insert_entries,
2082 .remove_memory = intel_i915_remove_entries,
2083 .alloc_by_type = intel_i830_alloc_by_type,
2084 .free_by_type = intel_i810_free_by_type,
2085 .agp_alloc_page = agp_generic_alloc_page,
2086 .agp_alloc_pages = agp_generic_alloc_pages,
2087 .agp_destroy_page = agp_generic_destroy_page,
2088 .agp_destroy_pages = agp_generic_destroy_pages,
2089 .agp_type_to_mask_type = intel_i830_type_to_mask_type,
2090 .chipset_flush = intel_i915_chipset_flush,
2093 static int find_gmch(u16 device)
2095 struct pci_dev *gmch_device;
2097 gmch_device = pci_get_device(PCI_VENDOR_ID_INTEL, device, NULL);
2098 if (gmch_device && PCI_FUNC(gmch_device->devfn) != 0) {
2099 gmch_device = pci_get_device(PCI_VENDOR_ID_INTEL,
2100 device, gmch_device);
2106 intel_private.pcidev = gmch_device;
2110 /* Table to describe Intel GMCH and AGP/PCIE GART drivers. At least one of
2111 * driver and gmch_driver must be non-null, and find_gmch will determine
2112 * which one should be used if a gmch_chip_id is present.
2114 static const struct intel_driver_description {
2115 unsigned int chip_id;
2116 unsigned int gmch_chip_id;
2117 unsigned int multi_gmch_chip; /* if we have more gfx chip type on this HB. */
2119 const struct agp_bridge_driver *driver;
2120 const struct agp_bridge_driver *gmch_driver;
2121 } intel_agp_chipsets[] = {
2122 { PCI_DEVICE_ID_INTEL_82443LX_0, 0, 0, "440LX", &intel_generic_driver, NULL },
2123 { PCI_DEVICE_ID_INTEL_82443BX_0, 0, 0, "440BX", &intel_generic_driver, NULL },
2124 { PCI_DEVICE_ID_INTEL_82443GX_0, 0, 0, "440GX", &intel_generic_driver, NULL },
2125 { PCI_DEVICE_ID_INTEL_82810_MC1, PCI_DEVICE_ID_INTEL_82810_IG1, 0, "i810",
2126 NULL, &intel_810_driver },
2127 { PCI_DEVICE_ID_INTEL_82810_MC3, PCI_DEVICE_ID_INTEL_82810_IG3, 0, "i810",
2128 NULL, &intel_810_driver },
2129 { PCI_DEVICE_ID_INTEL_82810E_MC, PCI_DEVICE_ID_INTEL_82810E_IG, 0, "i810",
2130 NULL, &intel_810_driver },
2131 { PCI_DEVICE_ID_INTEL_82815_MC, PCI_DEVICE_ID_INTEL_82815_CGC, 0, "i815",
2132 &intel_815_driver, &intel_810_driver },
2133 { PCI_DEVICE_ID_INTEL_82820_HB, 0, 0, "i820", &intel_820_driver, NULL },
2134 { PCI_DEVICE_ID_INTEL_82820_UP_HB, 0, 0, "i820", &intel_820_driver, NULL },
2135 { PCI_DEVICE_ID_INTEL_82830_HB, PCI_DEVICE_ID_INTEL_82830_CGC, 0, "830M",
2136 &intel_830mp_driver, &intel_830_driver },
2137 { PCI_DEVICE_ID_INTEL_82840_HB, 0, 0, "i840", &intel_840_driver, NULL },
2138 { PCI_DEVICE_ID_INTEL_82845_HB, 0, 0, "845G", &intel_845_driver, NULL },
2139 { PCI_DEVICE_ID_INTEL_82845G_HB, PCI_DEVICE_ID_INTEL_82845G_IG, 0, "830M",
2140 &intel_845_driver, &intel_830_driver },
2141 { PCI_DEVICE_ID_INTEL_82850_HB, 0, 0, "i850", &intel_850_driver, NULL },
2142 { PCI_DEVICE_ID_INTEL_82854_HB, PCI_DEVICE_ID_INTEL_82854_IG, 0, "854",
2143 &intel_845_driver, &intel_830_driver },
2144 { PCI_DEVICE_ID_INTEL_82855PM_HB, 0, 0, "855PM", &intel_845_driver, NULL },
2145 { PCI_DEVICE_ID_INTEL_82855GM_HB, PCI_DEVICE_ID_INTEL_82855GM_IG, 0, "855GM",
2146 &intel_845_driver, &intel_830_driver },
2147 { PCI_DEVICE_ID_INTEL_82860_HB, 0, 0, "i860", &intel_860_driver, NULL },
2148 { PCI_DEVICE_ID_INTEL_82865_HB, PCI_DEVICE_ID_INTEL_82865_IG, 0, "865",
2149 &intel_845_driver, &intel_830_driver },
2150 { PCI_DEVICE_ID_INTEL_82875_HB, 0, 0, "i875", &intel_845_driver, NULL },
2151 { PCI_DEVICE_ID_INTEL_E7221_HB, PCI_DEVICE_ID_INTEL_E7221_IG, 0, "E7221 (i915)",
2152 NULL, &intel_915_driver },
2153 { PCI_DEVICE_ID_INTEL_82915G_HB, PCI_DEVICE_ID_INTEL_82915G_IG, 0, "915G",
2154 NULL, &intel_915_driver },
2155 { PCI_DEVICE_ID_INTEL_82915GM_HB, PCI_DEVICE_ID_INTEL_82915GM_IG, 0, "915GM",
2156 NULL, &intel_915_driver },
2157 { PCI_DEVICE_ID_INTEL_82945G_HB, PCI_DEVICE_ID_INTEL_82945G_IG, 0, "945G",
2158 NULL, &intel_915_driver },
2159 { PCI_DEVICE_ID_INTEL_82945GM_HB, PCI_DEVICE_ID_INTEL_82945GM_IG, 0, "945GM",
2160 NULL, &intel_915_driver },
2161 { PCI_DEVICE_ID_INTEL_82945GME_HB, PCI_DEVICE_ID_INTEL_82945GME_IG, 0, "945GME",
2162 NULL, &intel_915_driver },
2163 { PCI_DEVICE_ID_INTEL_82946GZ_HB, PCI_DEVICE_ID_INTEL_82946GZ_IG, 0, "946GZ",
2164 NULL, &intel_i965_driver },
2165 { PCI_DEVICE_ID_INTEL_82G35_HB, PCI_DEVICE_ID_INTEL_82G35_IG, 0, "G35",
2166 NULL, &intel_i965_driver },
2167 { PCI_DEVICE_ID_INTEL_82965Q_HB, PCI_DEVICE_ID_INTEL_82965Q_IG, 0, "965Q",
2168 NULL, &intel_i965_driver },
2169 { PCI_DEVICE_ID_INTEL_82965G_HB, PCI_DEVICE_ID_INTEL_82965G_IG, 0, "965G",
2170 NULL, &intel_i965_driver },
2171 { PCI_DEVICE_ID_INTEL_82965GM_HB, PCI_DEVICE_ID_INTEL_82965GM_IG, 0, "965GM",
2172 NULL, &intel_i965_driver },
2173 { PCI_DEVICE_ID_INTEL_82965GME_HB, PCI_DEVICE_ID_INTEL_82965GME_IG, 0, "965GME/GLE",
2174 NULL, &intel_i965_driver },
2175 { PCI_DEVICE_ID_INTEL_7505_0, 0, 0, "E7505", &intel_7505_driver, NULL },
2176 { PCI_DEVICE_ID_INTEL_7205_0, 0, 0, "E7205", &intel_7505_driver, NULL },
2177 { PCI_DEVICE_ID_INTEL_G33_HB, PCI_DEVICE_ID_INTEL_G33_IG, 0, "G33",
2178 NULL, &intel_g33_driver },
2179 { PCI_DEVICE_ID_INTEL_Q35_HB, PCI_DEVICE_ID_INTEL_Q35_IG, 0, "Q35",
2180 NULL, &intel_g33_driver },
2181 { PCI_DEVICE_ID_INTEL_Q33_HB, PCI_DEVICE_ID_INTEL_Q33_IG, 0, "Q33",
2182 NULL, &intel_g33_driver },
2183 { PCI_DEVICE_ID_INTEL_IGDGM_HB, PCI_DEVICE_ID_INTEL_IGDGM_IG, 0, "IGD",
2184 NULL, &intel_g33_driver },
2185 { PCI_DEVICE_ID_INTEL_IGDG_HB, PCI_DEVICE_ID_INTEL_IGDG_IG, 0, "IGD",
2186 NULL, &intel_g33_driver },
2187 { PCI_DEVICE_ID_INTEL_GM45_HB, PCI_DEVICE_ID_INTEL_GM45_IG, 0,
2188 "Mobile IntelĀ® GM45 Express", NULL, &intel_i965_driver },
2189 { PCI_DEVICE_ID_INTEL_IGD_E_HB, PCI_DEVICE_ID_INTEL_IGD_E_IG, 0,
2190 "Intel Integrated Graphics Device", NULL, &intel_i965_driver },
2191 { PCI_DEVICE_ID_INTEL_Q45_HB, PCI_DEVICE_ID_INTEL_Q45_IG, 0,
2192 "Q45/Q43", NULL, &intel_i965_driver },
2193 { PCI_DEVICE_ID_INTEL_G45_HB, PCI_DEVICE_ID_INTEL_G45_IG, 0,
2194 "G45/G43", NULL, &intel_i965_driver },
2195 { PCI_DEVICE_ID_INTEL_G41_HB, PCI_DEVICE_ID_INTEL_G41_IG, 0,
2196 "G41", NULL, &intel_i965_driver },
2197 { PCI_DEVICE_ID_INTEL_IGDNG_D_HB, PCI_DEVICE_ID_INTEL_IGDNG_D_IG, 0,
2198 "IGDNG/D", NULL, &intel_i965_driver },
2199 { PCI_DEVICE_ID_INTEL_IGDNG_M_HB, PCI_DEVICE_ID_INTEL_IGDNG_M_IG, 0,
2200 "IGDNG/M", NULL, &intel_i965_driver },
2201 { 0, 0, 0, NULL, NULL, NULL }
2204 static int __devinit agp_intel_probe(struct pci_dev *pdev,
2205 const struct pci_device_id *ent)
2207 struct agp_bridge_data *bridge;
2212 cap_ptr = pci_find_capability(pdev, PCI_CAP_ID_AGP);
2214 bridge = agp_alloc_bridge();
2218 for (i = 0; intel_agp_chipsets[i].name != NULL; i++) {
2219 /* In case that multiple models of gfx chip may
2220 stand on same host bridge type, this can be
2221 sure we detect the right IGD. */
2222 if (pdev->device == intel_agp_chipsets[i].chip_id) {
2223 if ((intel_agp_chipsets[i].gmch_chip_id != 0) &&
2224 find_gmch(intel_agp_chipsets[i].gmch_chip_id)) {
2226 intel_agp_chipsets[i].gmch_driver;
2228 } else if (intel_agp_chipsets[i].multi_gmch_chip) {
2231 bridge->driver = intel_agp_chipsets[i].driver;
2237 if (intel_agp_chipsets[i].name == NULL) {
2239 dev_warn(&pdev->dev, "unsupported Intel chipset [%04x/%04x]\n",
2240 pdev->vendor, pdev->device);
2241 agp_put_bridge(bridge);
2245 if (bridge->driver == NULL) {
2246 /* bridge has no AGP and no IGD detected */
2248 dev_warn(&pdev->dev, "can't find bridge device (chip_id: %04x)\n",
2249 intel_agp_chipsets[i].gmch_chip_id);
2250 agp_put_bridge(bridge);
2255 bridge->capndx = cap_ptr;
2256 bridge->dev_private_data = &intel_private;
2258 dev_info(&pdev->dev, "Intel %s Chipset\n", intel_agp_chipsets[i].name);
2261 * The following fixes the case where the BIOS has "forgotten" to
2262 * provide an address range for the GART.
2263 * 20030610 - hamish@zot.org
2265 r = &pdev->resource[0];
2266 if (!r->start && r->end) {
2267 if (pci_assign_resource(pdev, 0)) {
2268 dev_err(&pdev->dev, "can't assign resource 0\n");
2269 agp_put_bridge(bridge);
2275 * If the device has not been properly setup, the following will catch
2276 * the problem and should stop the system from crashing.
2277 * 20030610 - hamish@zot.org
2279 if (pci_enable_device(pdev)) {
2280 dev_err(&pdev->dev, "can't enable PCI device\n");
2281 agp_put_bridge(bridge);
2285 /* Fill in the mode register */
2287 pci_read_config_dword(pdev,
2288 bridge->capndx+PCI_AGP_STATUS,
2292 pci_set_drvdata(pdev, bridge);
2293 return agp_add_bridge(bridge);
2296 static void __devexit agp_intel_remove(struct pci_dev *pdev)
2298 struct agp_bridge_data *bridge = pci_get_drvdata(pdev);
2300 agp_remove_bridge(bridge);
2302 if (intel_private.pcidev)
2303 pci_dev_put(intel_private.pcidev);
2305 agp_put_bridge(bridge);
2309 static int agp_intel_resume(struct pci_dev *pdev)
2311 struct agp_bridge_data *bridge = pci_get_drvdata(pdev);
2314 pci_restore_state(pdev);
2316 /* We should restore our graphics device's config space,
2317 * as host bridge (00:00) resumes before graphics device (02:00),
2318 * then our access to its pci space can work right.
2320 if (intel_private.pcidev)
2321 pci_restore_state(intel_private.pcidev);
2323 if (bridge->driver == &intel_generic_driver)
2325 else if (bridge->driver == &intel_850_driver)
2326 intel_850_configure();
2327 else if (bridge->driver == &intel_845_driver)
2328 intel_845_configure();
2329 else if (bridge->driver == &intel_830mp_driver)
2330 intel_830mp_configure();
2331 else if (bridge->driver == &intel_915_driver)
2332 intel_i915_configure();
2333 else if (bridge->driver == &intel_830_driver)
2334 intel_i830_configure();
2335 else if (bridge->driver == &intel_810_driver)
2336 intel_i810_configure();
2337 else if (bridge->driver == &intel_i965_driver)
2338 intel_i915_configure();
2340 ret_val = agp_rebind_memory();
2348 static struct pci_device_id agp_intel_pci_table[] = {
2351 .class = (PCI_CLASS_BRIDGE_HOST << 8), \
2353 .vendor = PCI_VENDOR_ID_INTEL, \
2355 .subvendor = PCI_ANY_ID, \
2356 .subdevice = PCI_ANY_ID, \
2358 ID(PCI_DEVICE_ID_INTEL_82443LX_0),
2359 ID(PCI_DEVICE_ID_INTEL_82443BX_0),
2360 ID(PCI_DEVICE_ID_INTEL_82443GX_0),
2361 ID(PCI_DEVICE_ID_INTEL_82810_MC1),
2362 ID(PCI_DEVICE_ID_INTEL_82810_MC3),
2363 ID(PCI_DEVICE_ID_INTEL_82810E_MC),
2364 ID(PCI_DEVICE_ID_INTEL_82815_MC),
2365 ID(PCI_DEVICE_ID_INTEL_82820_HB),
2366 ID(PCI_DEVICE_ID_INTEL_82820_UP_HB),
2367 ID(PCI_DEVICE_ID_INTEL_82830_HB),
2368 ID(PCI_DEVICE_ID_INTEL_82840_HB),
2369 ID(PCI_DEVICE_ID_INTEL_82845_HB),
2370 ID(PCI_DEVICE_ID_INTEL_82845G_HB),
2371 ID(PCI_DEVICE_ID_INTEL_82850_HB),
2372 ID(PCI_DEVICE_ID_INTEL_82854_HB),
2373 ID(PCI_DEVICE_ID_INTEL_82855PM_HB),
2374 ID(PCI_DEVICE_ID_INTEL_82855GM_HB),
2375 ID(PCI_DEVICE_ID_INTEL_82860_HB),
2376 ID(PCI_DEVICE_ID_INTEL_82865_HB),
2377 ID(PCI_DEVICE_ID_INTEL_82875_HB),
2378 ID(PCI_DEVICE_ID_INTEL_7505_0),
2379 ID(PCI_DEVICE_ID_INTEL_7205_0),
2380 ID(PCI_DEVICE_ID_INTEL_E7221_HB),
2381 ID(PCI_DEVICE_ID_INTEL_82915G_HB),
2382 ID(PCI_DEVICE_ID_INTEL_82915GM_HB),
2383 ID(PCI_DEVICE_ID_INTEL_82945G_HB),
2384 ID(PCI_DEVICE_ID_INTEL_82945GM_HB),
2385 ID(PCI_DEVICE_ID_INTEL_82945GME_HB),
2386 ID(PCI_DEVICE_ID_INTEL_IGDGM_HB),
2387 ID(PCI_DEVICE_ID_INTEL_IGDG_HB),
2388 ID(PCI_DEVICE_ID_INTEL_82946GZ_HB),
2389 ID(PCI_DEVICE_ID_INTEL_82G35_HB),
2390 ID(PCI_DEVICE_ID_INTEL_82965Q_HB),
2391 ID(PCI_DEVICE_ID_INTEL_82965G_HB),
2392 ID(PCI_DEVICE_ID_INTEL_82965GM_HB),
2393 ID(PCI_DEVICE_ID_INTEL_82965GME_HB),
2394 ID(PCI_DEVICE_ID_INTEL_G33_HB),
2395 ID(PCI_DEVICE_ID_INTEL_Q35_HB),
2396 ID(PCI_DEVICE_ID_INTEL_Q33_HB),
2397 ID(PCI_DEVICE_ID_INTEL_GM45_HB),
2398 ID(PCI_DEVICE_ID_INTEL_IGD_E_HB),
2399 ID(PCI_DEVICE_ID_INTEL_Q45_HB),
2400 ID(PCI_DEVICE_ID_INTEL_G45_HB),
2401 ID(PCI_DEVICE_ID_INTEL_G41_HB),
2402 ID(PCI_DEVICE_ID_INTEL_IGDNG_D_HB),
2403 ID(PCI_DEVICE_ID_INTEL_IGDNG_M_HB),
2407 MODULE_DEVICE_TABLE(pci, agp_intel_pci_table);
2409 static struct pci_driver agp_intel_pci_driver = {
2410 .name = "agpgart-intel",
2411 .id_table = agp_intel_pci_table,
2412 .probe = agp_intel_probe,
2413 .remove = __devexit_p(agp_intel_remove),
2415 .resume = agp_intel_resume,
2419 static int __init agp_intel_init(void)
2423 return pci_register_driver(&agp_intel_pci_driver);
2426 static void __exit agp_intel_cleanup(void)
2428 pci_unregister_driver(&agp_intel_pci_driver);
2431 module_init(agp_intel_init);
2432 module_exit(agp_intel_cleanup);
2434 MODULE_AUTHOR("Dave Jones <davej@redhat.com>");
2435 MODULE_LICENSE("GPL and additional rights");