2 * Intel AGPGART routines.
6 * Intel(R) 855GM/852GM and 865G support added by David Dawes
7 * <dawes@tungstengraphics.com>.
9 * Intel(R) 915G support added by Alan Hourihane
10 * <alanh@tungstengraphics.com>.
13 #include <linux/module.h>
14 #include <linux/pci.h>
15 #include <linux/init.h>
16 #include <linux/pagemap.h>
17 #include <linux/agp_backend.h>
20 /* Intel 815 register */
21 #define INTEL_815_APCONT 0x51
22 #define INTEL_815_ATTBASE_MASK ~0x1FFFFFFF
24 /* Intel i820 registers */
25 #define INTEL_I820_RDCR 0x51
26 #define INTEL_I820_ERRSTS 0xc8
28 /* Intel i840 registers */
29 #define INTEL_I840_MCHCFG 0x50
30 #define INTEL_I840_ERRSTS 0xc8
32 /* Intel i850 registers */
33 #define INTEL_I850_MCHCFG 0x50
34 #define INTEL_I850_ERRSTS 0xc8
36 /* intel 915G registers */
37 #define I915_GMADDR 0x18
38 #define I915_MMADDR 0x10
39 #define I915_PTEADDR 0x1C
40 #define I915_GMCH_GMS_STOLEN_48M (0x6 << 4)
41 #define I915_GMCH_GMS_STOLEN_64M (0x7 << 4)
44 /* Intel 7505 registers */
45 #define INTEL_I7505_APSIZE 0x74
46 #define INTEL_I7505_NCAPID 0x60
47 #define INTEL_I7505_NISTAT 0x6c
48 #define INTEL_I7505_ATTBASE 0x78
49 #define INTEL_I7505_ERRSTS 0x42
50 #define INTEL_I7505_AGPCTRL 0x70
51 #define INTEL_I7505_MCHCFG 0x50
53 static struct aper_size_info_fixed intel_i810_sizes[] =
56 /* The 32M mode still requires a 64k gatt */
60 #define AGP_DCACHE_MEMORY 1
61 #define AGP_PHYS_MEMORY 2
63 static struct gatt_mask intel_i810_masks[] =
65 {.mask = I810_PTE_VALID, .type = 0},
66 {.mask = (I810_PTE_VALID | I810_PTE_LOCAL), .type = AGP_DCACHE_MEMORY},
67 {.mask = I810_PTE_VALID, .type = 0}
70 static struct _intel_i810_private {
71 struct pci_dev *i810_dev; /* device one */
72 volatile u8 __iomem *registers;
73 int num_dcache_entries;
76 static int intel_i810_fetch_size(void)
79 struct aper_size_info_fixed *values;
81 pci_read_config_dword(agp_bridge->dev, I810_SMRAM_MISCC, &smram_miscc);
82 values = A_SIZE_FIX(agp_bridge->driver->aperture_sizes);
84 if ((smram_miscc & I810_GMS) == I810_GMS_DISABLE) {
85 printk(KERN_WARNING PFX "i810 is disabled\n");
88 if ((smram_miscc & I810_GFX_MEM_WIN_SIZE) == I810_GFX_MEM_WIN_32M) {
89 agp_bridge->previous_size =
90 agp_bridge->current_size = (void *) (values + 1);
91 agp_bridge->aperture_size_idx = 1;
92 return values[1].size;
94 agp_bridge->previous_size =
95 agp_bridge->current_size = (void *) (values);
96 agp_bridge->aperture_size_idx = 0;
97 return values[0].size;
103 static int intel_i810_configure(void)
105 struct aper_size_info_fixed *current_size;
109 current_size = A_SIZE_FIX(agp_bridge->current_size);
111 pci_read_config_dword(intel_i810_private.i810_dev, I810_MMADDR, &temp);
114 intel_i810_private.registers = ioremap(temp, 128 * 4096);
115 if (!intel_i810_private.registers) {
116 printk(KERN_ERR PFX "Unable to remap memory.\n");
120 if ((INREG32(intel_i810_private.registers, I810_DRAM_CTL)
121 & I810_DRAM_ROW_0) == I810_DRAM_ROW_0_SDRAM) {
122 /* This will need to be dynamically assigned */
123 printk(KERN_INFO PFX "detected 4MB dedicated video ram.\n");
124 intel_i810_private.num_dcache_entries = 1024;
126 pci_read_config_dword(intel_i810_private.i810_dev, I810_GMADDR, &temp);
127 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
128 OUTREG32(intel_i810_private.registers, I810_PGETBL_CTL,
129 agp_bridge->gatt_bus_addr | I810_PGETBL_ENABLED);
130 global_cache_flush();
132 if (agp_bridge->driver->needs_scratch_page) {
133 for (i = 0; i < current_size->num_entries; i++) {
134 OUTREG32(intel_i810_private.registers,
135 I810_PTE_BASE + (i * 4),
136 agp_bridge->scratch_page);
142 static void intel_i810_cleanup(void)
144 OUTREG32(intel_i810_private.registers, I810_PGETBL_CTL, 0);
145 iounmap(intel_i810_private.registers);
148 static void intel_i810_tlbflush(struct agp_memory *mem)
153 static void intel_i810_agp_enable(u32 mode)
158 /* Exists to support ARGB cursors */
159 static void *i8xx_alloc_pages(void)
163 page = alloc_pages(GFP_KERNEL, 2);
167 if (change_page_attr(page, 4, PAGE_KERNEL_NOCACHE) < 0) {
173 atomic_inc(&agp_bridge->current_memory_agp);
174 return page_address(page);
177 static void i8xx_destroy_pages(void *addr)
184 page = virt_to_page(addr);
185 change_page_attr(page, 4, PAGE_KERNEL);
188 free_pages((unsigned long)addr, 2);
189 atomic_dec(&agp_bridge->current_memory_agp);
192 static int intel_i810_insert_entries(struct agp_memory *mem, off_t pg_start,
195 int i, j, num_entries;
198 temp = agp_bridge->current_size;
199 num_entries = A_SIZE_FIX(temp)->num_entries;
201 if ((pg_start + mem->page_count) > num_entries) {
204 for (j = pg_start; j < (pg_start + mem->page_count); j++) {
205 if (!PGE_EMPTY(agp_bridge, readl(agp_bridge->gatt_table+j)))
209 if (type != 0 || mem->type != 0) {
210 if ((type == AGP_DCACHE_MEMORY) && (mem->type == AGP_DCACHE_MEMORY)) {
212 global_cache_flush();
213 for (i = pg_start; i < (pg_start + mem->page_count); i++) {
214 OUTREG32(intel_i810_private.registers,
215 I810_PTE_BASE + (i * 4),
216 (i * 4096) | I810_PTE_LOCAL |
219 global_cache_flush();
220 agp_bridge->driver->tlb_flush(mem);
223 if((type == AGP_PHYS_MEMORY) && (mem->type == AGP_PHYS_MEMORY))
229 global_cache_flush();
230 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
231 OUTREG32(intel_i810_private.registers,
232 I810_PTE_BASE + (j * 4),
233 agp_bridge->driver->mask_memory(mem->memory[i], mem->type));
235 global_cache_flush();
237 agp_bridge->driver->tlb_flush(mem);
241 static int intel_i810_remove_entries(struct agp_memory *mem, off_t pg_start,
246 for (i = pg_start; i < (mem->page_count + pg_start); i++) {
247 OUTREG32(intel_i810_private.registers,
248 I810_PTE_BASE + (i * 4),
249 agp_bridge->scratch_page);
252 global_cache_flush();
253 agp_bridge->driver->tlb_flush(mem);
258 * The i810/i830 requires a physical address to program its mouse
259 * pointer into hardware.
260 * However the Xserver still writes to it through the agp aperture.
262 static struct agp_memory *alloc_agpphysmem_i8xx(size_t pg_count, int type)
264 struct agp_memory *new;
267 if (pg_count != 1 && pg_count != 4)
271 case 1: addr = agp_bridge->driver->agp_alloc_page();
274 /* kludge to get 4 physical pages for ARGB cursor */
275 addr = i8xx_alloc_pages();
284 new = agp_create_memory(pg_count);
288 new->memory[0] = virt_to_phys(addr);
290 /* kludge to get 4 physical pages for ARGB cursor */
291 new->memory[1] = new->memory[0] + PAGE_SIZE;
292 new->memory[2] = new->memory[1] + PAGE_SIZE;
293 new->memory[3] = new->memory[2] + PAGE_SIZE;
295 new->page_count = pg_count;
296 new->num_scratch_pages = pg_count;
297 new->type = AGP_PHYS_MEMORY;
298 new->physical = new->memory[0];
302 static struct agp_memory *intel_i810_alloc_by_type(size_t pg_count, int type)
304 struct agp_memory *new;
306 if (type == AGP_DCACHE_MEMORY) {
307 if (pg_count != intel_i810_private.num_dcache_entries)
310 new = agp_create_memory(1);
314 new->type = AGP_DCACHE_MEMORY;
315 new->page_count = pg_count;
316 new->num_scratch_pages = 0;
320 if (type == AGP_PHYS_MEMORY)
321 return(alloc_agpphysmem_i8xx(pg_count, type));
326 static void intel_i810_free_by_type(struct agp_memory *curr)
328 agp_free_key(curr->key);
329 if(curr->type == AGP_PHYS_MEMORY) {
330 if (curr->page_count == 4)
331 i8xx_destroy_pages(phys_to_virt(curr->memory[0]));
333 agp_bridge->driver->agp_destroy_page(
334 phys_to_virt(curr->memory[0]));
340 static unsigned long intel_i810_mask_memory(unsigned long addr, int type)
342 /* Type checking must be done elsewhere */
343 return addr | agp_bridge->driver->masks[type].mask;
346 static struct aper_size_info_fixed intel_i830_sizes[] =
349 /* The 64M mode still requires a 128k gatt */
354 static struct _intel_i830_private {
355 struct pci_dev *i830_dev; /* device one */
356 volatile u8 __iomem *registers;
357 volatile u32 __iomem *gtt; /* I915G */
359 } intel_i830_private;
361 static void intel_i830_init_gtt_entries(void)
367 static const int ddt[4] = { 0, 16, 32, 64 };
370 pci_read_config_word(agp_bridge->dev,I830_GMCH_CTRL,&gmch_ctrl);
372 /* We obtain the size of the GTT, which is also stored (for some
373 * reason) at the top of stolen memory. Then we add 4KB to that
374 * for the video BIOS popup, which is also stored in there. */
375 size = agp_bridge->driver->fetch_size() + 4;
377 if (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82830_HB ||
378 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82845G_HB) {
379 switch (gmch_ctrl & I830_GMCH_GMS_MASK) {
380 case I830_GMCH_GMS_STOLEN_512:
381 gtt_entries = KB(512) - KB(size);
383 case I830_GMCH_GMS_STOLEN_1024:
384 gtt_entries = MB(1) - KB(size);
386 case I830_GMCH_GMS_STOLEN_8192:
387 gtt_entries = MB(8) - KB(size);
389 case I830_GMCH_GMS_LOCAL:
390 rdct = INREG8(intel_i830_private.registers,
391 I830_RDRAM_CHANNEL_TYPE);
392 gtt_entries = (I830_RDRAM_ND(rdct) + 1) *
393 MB(ddt[I830_RDRAM_DDT(rdct)]);
401 switch (gmch_ctrl & I830_GMCH_GMS_MASK) {
402 case I855_GMCH_GMS_STOLEN_1M:
403 gtt_entries = MB(1) - KB(size);
405 case I855_GMCH_GMS_STOLEN_4M:
406 gtt_entries = MB(4) - KB(size);
408 case I855_GMCH_GMS_STOLEN_8M:
409 gtt_entries = MB(8) - KB(size);
411 case I855_GMCH_GMS_STOLEN_16M:
412 gtt_entries = MB(16) - KB(size);
414 case I855_GMCH_GMS_STOLEN_32M:
415 gtt_entries = MB(32) - KB(size);
417 case I915_GMCH_GMS_STOLEN_48M:
418 /* Check it's really I915G */
419 if (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82915G_HB)
420 gtt_entries = MB(48) - KB(size);
424 case I915_GMCH_GMS_STOLEN_64M:
425 /* Check it's really I915G */
426 if (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82915G_HB)
427 gtt_entries = MB(64) - KB(size);
436 printk(KERN_INFO PFX "Detected %dK %s memory.\n",
437 gtt_entries / KB(1), local ? "local" : "stolen");
440 "No pre-allocated video memory detected.\n");
441 gtt_entries /= KB(4);
443 intel_i830_private.gtt_entries = gtt_entries;
446 /* The intel i830 automatically initializes the agp aperture during POST.
447 * Use the memory already set aside for in the GTT.
449 static int intel_i830_create_gatt_table(void)
452 struct aper_size_info_fixed *size;
456 size = agp_bridge->current_size;
457 page_order = size->page_order;
458 num_entries = size->num_entries;
459 agp_bridge->gatt_table_real = NULL;
461 pci_read_config_dword(intel_i830_private.i830_dev,I810_MMADDR,&temp);
464 intel_i830_private.registers = ioremap(temp,128 * 4096);
465 if (!intel_i830_private.registers)
468 temp = INREG32(intel_i830_private.registers,I810_PGETBL_CTL) & 0xfffff000;
469 global_cache_flush();
471 /* we have to call this as early as possible after the MMIO base address is known */
472 intel_i830_init_gtt_entries();
474 agp_bridge->gatt_table = NULL;
476 agp_bridge->gatt_bus_addr = temp;
481 /* Return the gatt table to a sane state. Use the top of stolen
482 * memory for the GTT.
484 static int intel_i830_free_gatt_table(void)
489 static int intel_i830_fetch_size(void)
492 struct aper_size_info_fixed *values;
494 values = A_SIZE_FIX(agp_bridge->driver->aperture_sizes);
496 if (agp_bridge->dev->device != PCI_DEVICE_ID_INTEL_82830_HB &&
497 agp_bridge->dev->device != PCI_DEVICE_ID_INTEL_82845G_HB) {
498 /* 855GM/852GM/865G has 128MB aperture size */
499 agp_bridge->previous_size = agp_bridge->current_size = (void *) values;
500 agp_bridge->aperture_size_idx = 0;
501 return(values[0].size);
504 pci_read_config_word(agp_bridge->dev,I830_GMCH_CTRL,&gmch_ctrl);
506 if ((gmch_ctrl & I830_GMCH_MEM_MASK) == I830_GMCH_MEM_128M) {
507 agp_bridge->previous_size = agp_bridge->current_size = (void *) values;
508 agp_bridge->aperture_size_idx = 0;
509 return(values[0].size);
511 agp_bridge->previous_size = agp_bridge->current_size = (void *) (values + 1);
512 agp_bridge->aperture_size_idx = 1;
513 return(values[1].size);
519 static int intel_i830_configure(void)
521 struct aper_size_info_fixed *current_size;
526 current_size = A_SIZE_FIX(agp_bridge->current_size);
528 pci_read_config_dword(intel_i830_private.i830_dev,I810_GMADDR,&temp);
529 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
531 pci_read_config_word(agp_bridge->dev,I830_GMCH_CTRL,&gmch_ctrl);
532 gmch_ctrl |= I830_GMCH_ENABLED;
533 pci_write_config_word(agp_bridge->dev,I830_GMCH_CTRL,gmch_ctrl);
535 OUTREG32(intel_i830_private.registers,I810_PGETBL_CTL,agp_bridge->gatt_bus_addr | I810_PGETBL_ENABLED);
536 global_cache_flush();
538 if (agp_bridge->driver->needs_scratch_page)
539 for (i = intel_i830_private.gtt_entries; i < current_size->num_entries; i++)
540 OUTREG32(intel_i830_private.registers,I810_PTE_BASE + (i * 4),agp_bridge->scratch_page);
545 static void intel_i830_cleanup(void)
547 iounmap(intel_i830_private.registers);
550 static int intel_i830_insert_entries(struct agp_memory *mem,off_t pg_start,
556 temp = agp_bridge->current_size;
557 num_entries = A_SIZE_FIX(temp)->num_entries;
559 if (pg_start < intel_i830_private.gtt_entries) {
560 printk (KERN_DEBUG PFX "pg_start == 0x%.8lx,intel_i830_private.gtt_entries == 0x%.8x\n",
561 pg_start,intel_i830_private.gtt_entries);
563 printk (KERN_INFO PFX "Trying to insert into local/stolen memory\n");
567 if ((pg_start + mem->page_count) > num_entries)
570 /* The i830 can't check the GTT for entries since its read only,
571 * depend on the caller to make the correct offset decisions.
574 if ((type != 0 && type != AGP_PHYS_MEMORY) ||
575 (mem->type != 0 && mem->type != AGP_PHYS_MEMORY))
578 global_cache_flush();
580 for (i = 0, j = pg_start; i < mem->page_count; i++, j++)
581 OUTREG32(intel_i830_private.registers,I810_PTE_BASE + (j * 4),
582 agp_bridge->driver->mask_memory(mem->memory[i], mem->type));
584 global_cache_flush();
586 agp_bridge->driver->tlb_flush(mem);
591 static int intel_i830_remove_entries(struct agp_memory *mem,off_t pg_start,
596 global_cache_flush();
598 if (pg_start < intel_i830_private.gtt_entries) {
599 printk (KERN_INFO PFX "Trying to disable local/stolen memory\n");
603 for (i = pg_start; i < (mem->page_count + pg_start); i++)
604 OUTREG32(intel_i830_private.registers,I810_PTE_BASE + (i * 4),agp_bridge->scratch_page);
606 global_cache_flush();
608 agp_bridge->driver->tlb_flush(mem);
613 static struct agp_memory *intel_i830_alloc_by_type(size_t pg_count,int type)
615 if (type == AGP_PHYS_MEMORY)
616 return(alloc_agpphysmem_i8xx(pg_count, type));
618 /* always return NULL for other allocation types for now */
622 static int intel_i915_configure(void)
624 struct aper_size_info_fixed *current_size;
629 current_size = A_SIZE_FIX(agp_bridge->current_size);
631 pci_read_config_dword(intel_i830_private.i830_dev, I915_GMADDR, &temp);
633 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
635 pci_read_config_word(agp_bridge->dev,I830_GMCH_CTRL,&gmch_ctrl);
636 gmch_ctrl |= I830_GMCH_ENABLED;
637 pci_write_config_word(agp_bridge->dev,I830_GMCH_CTRL,gmch_ctrl);
639 OUTREG32(intel_i830_private.registers,I810_PGETBL_CTL,agp_bridge->gatt_bus_addr | I810_PGETBL_ENABLED);
640 global_cache_flush();
642 if (agp_bridge->driver->needs_scratch_page) {
643 for (i = intel_i830_private.gtt_entries; i < current_size->num_entries; i++)
644 OUTREG32(intel_i830_private.gtt, i, agp_bridge->scratch_page);
650 static void intel_i915_cleanup(void)
652 iounmap(intel_i830_private.gtt);
653 iounmap(intel_i830_private.registers);
656 static int intel_i915_insert_entries(struct agp_memory *mem,off_t pg_start,
662 temp = agp_bridge->current_size;
663 num_entries = A_SIZE_FIX(temp)->num_entries;
665 if (pg_start < intel_i830_private.gtt_entries) {
666 printk (KERN_DEBUG PFX "pg_start == 0x%.8lx,intel_i830_private.gtt_entries == 0x%.8x\n",
667 pg_start,intel_i830_private.gtt_entries);
669 printk (KERN_INFO PFX "Trying to insert into local/stolen memory\n");
673 if ((pg_start + mem->page_count) > num_entries)
676 /* The i830 can't check the GTT for entries since its read only,
677 * depend on the caller to make the correct offset decisions.
680 if ((type != 0 && type != AGP_PHYS_MEMORY) ||
681 (mem->type != 0 && mem->type != AGP_PHYS_MEMORY))
684 global_cache_flush();
686 for (i = 0, j = pg_start; i < mem->page_count; i++, j++)
687 OUTREG32(intel_i830_private.gtt, j, agp_bridge->driver->mask_memory(mem->memory[i], mem->type));
689 global_cache_flush();
691 agp_bridge->driver->tlb_flush(mem);
696 static int intel_i915_remove_entries(struct agp_memory *mem,off_t pg_start,
701 global_cache_flush();
703 if (pg_start < intel_i830_private.gtt_entries) {
704 printk (KERN_INFO PFX "Trying to disable local/stolen memory\n");
708 for (i = pg_start; i < (mem->page_count + pg_start); i++)
709 OUTREG32(intel_i830_private.gtt, i, agp_bridge->scratch_page);
711 global_cache_flush();
713 agp_bridge->driver->tlb_flush(mem);
718 static int intel_i915_fetch_size(void)
720 struct aper_size_info_fixed *values;
721 u32 temp, offset = 0;
723 #define I915_256MB_ADDRESS_MASK (1<<27)
725 values = A_SIZE_FIX(agp_bridge->driver->aperture_sizes);
727 pci_read_config_dword(intel_i830_private.i830_dev, I915_GMADDR, &temp);
728 if (temp & I915_256MB_ADDRESS_MASK)
729 offset = 0; /* 128MB aperture */
731 offset = 2; /* 256MB aperture */
732 agp_bridge->previous_size = agp_bridge->current_size = (void *)(values + offset);
733 return(values[offset].size);
736 /* The intel i915 automatically initializes the agp aperture during POST.
737 * Use the memory already set aside for in the GTT.
739 static int intel_i915_create_gatt_table(void)
742 struct aper_size_info_fixed *size;
746 size = agp_bridge->current_size;
747 page_order = size->page_order;
748 num_entries = size->num_entries;
749 agp_bridge->gatt_table_real = NULL;
751 pci_read_config_dword(intel_i830_private.i830_dev, I915_MMADDR, &temp);
752 pci_read_config_dword(intel_i830_private.i830_dev, I915_PTEADDR,&temp2);
754 intel_i830_private.gtt = ioremap(temp2, 256 * 1024);
755 if (!intel_i830_private.gtt)
760 intel_i830_private.registers = ioremap(temp,128 * 4096);
761 if (!intel_i830_private.registers)
764 temp = INREG32(intel_i830_private.registers,I810_PGETBL_CTL) & 0xfffff000;
765 global_cache_flush();
767 /* we have to call this as early as possible after the MMIO base address is known */
768 intel_i830_init_gtt_entries();
770 agp_bridge->gatt_table = NULL;
772 agp_bridge->gatt_bus_addr = temp;
777 static int intel_fetch_size(void)
781 struct aper_size_info_16 *values;
783 pci_read_config_word(agp_bridge->dev, INTEL_APSIZE, &temp);
784 values = A_SIZE_16(agp_bridge->driver->aperture_sizes);
786 for (i = 0; i < agp_bridge->driver->num_aperture_sizes; i++) {
787 if (temp == values[i].size_value) {
788 agp_bridge->previous_size = agp_bridge->current_size = (void *) (values + i);
789 agp_bridge->aperture_size_idx = i;
790 return values[i].size;
797 static int __intel_8xx_fetch_size(u8 temp)
800 struct aper_size_info_8 *values;
802 values = A_SIZE_8(agp_bridge->driver->aperture_sizes);
804 for (i = 0; i < agp_bridge->driver->num_aperture_sizes; i++) {
805 if (temp == values[i].size_value) {
806 agp_bridge->previous_size =
807 agp_bridge->current_size = (void *) (values + i);
808 agp_bridge->aperture_size_idx = i;
809 return values[i].size;
815 static int intel_8xx_fetch_size(void)
819 pci_read_config_byte(agp_bridge->dev, INTEL_APSIZE, &temp);
820 return __intel_8xx_fetch_size(temp);
823 static int intel_815_fetch_size(void)
827 /* Intel 815 chipsets have a _weird_ APSIZE register with only
828 * one non-reserved bit, so mask the others out ... */
829 pci_read_config_byte(agp_bridge->dev, INTEL_APSIZE, &temp);
832 return __intel_8xx_fetch_size(temp);
835 static void intel_tlbflush(struct agp_memory *mem)
837 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x2200);
838 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x2280);
842 static void intel_8xx_tlbflush(struct agp_memory *mem)
845 pci_read_config_dword(agp_bridge->dev, INTEL_AGPCTRL, &temp);
846 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, temp & ~(1 << 7));
847 pci_read_config_dword(agp_bridge->dev, INTEL_AGPCTRL, &temp);
848 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, temp | (1 << 7));
852 static void intel_cleanup(void)
855 struct aper_size_info_16 *previous_size;
857 previous_size = A_SIZE_16(agp_bridge->previous_size);
858 pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp);
859 pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG, temp & ~(1 << 9));
860 pci_write_config_word(agp_bridge->dev, INTEL_APSIZE, previous_size->size_value);
864 static void intel_8xx_cleanup(void)
867 struct aper_size_info_8 *previous_size;
869 previous_size = A_SIZE_8(agp_bridge->previous_size);
870 pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp);
871 pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG, temp & ~(1 << 9));
872 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, previous_size->size_value);
876 static int intel_configure(void)
880 struct aper_size_info_16 *current_size;
882 current_size = A_SIZE_16(agp_bridge->current_size);
885 pci_write_config_word(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
887 /* address to map to */
888 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
889 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
891 /* attbase - aperture base */
892 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
895 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x2280);
898 pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp2);
899 pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG,
900 (temp2 & ~(1 << 10)) | (1 << 9));
901 /* clear any possible error conditions */
902 pci_write_config_byte(agp_bridge->dev, INTEL_ERRSTS + 1, 7);
906 static int intel_815_configure(void)
910 struct aper_size_info_8 *current_size;
912 /* attbase - aperture base */
913 /* the Intel 815 chipset spec. says that bits 29-31 in the
914 * ATTBASE register are reserved -> try not to write them */
915 if (agp_bridge->gatt_bus_addr & INTEL_815_ATTBASE_MASK) {
916 printk (KERN_EMERG PFX "gatt bus addr too high");
920 current_size = A_SIZE_8(agp_bridge->current_size);
923 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE,
924 current_size->size_value);
926 /* address to map to */
927 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
928 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
930 pci_read_config_dword(agp_bridge->dev, INTEL_ATTBASE, &addr);
931 addr &= INTEL_815_ATTBASE_MASK;
932 addr |= agp_bridge->gatt_bus_addr;
933 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, addr);
936 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
939 pci_read_config_byte(agp_bridge->dev, INTEL_815_APCONT, &temp2);
940 pci_write_config_byte(agp_bridge->dev, INTEL_815_APCONT, temp2 | (1 << 1));
942 /* clear any possible error conditions */
943 /* Oddness : this chipset seems to have no ERRSTS register ! */
947 static void intel_820_tlbflush(struct agp_memory *mem)
952 static void intel_820_cleanup(void)
955 struct aper_size_info_8 *previous_size;
957 previous_size = A_SIZE_8(agp_bridge->previous_size);
958 pci_read_config_byte(agp_bridge->dev, INTEL_I820_RDCR, &temp);
959 pci_write_config_byte(agp_bridge->dev, INTEL_I820_RDCR,
961 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE,
962 previous_size->size_value);
966 static int intel_820_configure(void)
970 struct aper_size_info_8 *current_size;
972 current_size = A_SIZE_8(agp_bridge->current_size);
975 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
977 /* address to map to */
978 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
979 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
981 /* attbase - aperture base */
982 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
985 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
987 /* global enable aperture access */
988 /* This flag is not accessed through MCHCFG register as in */
990 pci_read_config_byte(agp_bridge->dev, INTEL_I820_RDCR, &temp2);
991 pci_write_config_byte(agp_bridge->dev, INTEL_I820_RDCR, temp2 | (1 << 1));
992 /* clear any possible AGP-related error conditions */
993 pci_write_config_word(agp_bridge->dev, INTEL_I820_ERRSTS, 0x001c);
997 static int intel_840_configure(void)
1001 struct aper_size_info_8 *current_size;
1003 current_size = A_SIZE_8(agp_bridge->current_size);
1006 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1008 /* address to map to */
1009 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1010 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1012 /* attbase - aperture base */
1013 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1016 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1019 pci_read_config_word(agp_bridge->dev, INTEL_I840_MCHCFG, &temp2);
1020 pci_write_config_word(agp_bridge->dev, INTEL_I840_MCHCFG, temp2 | (1 << 9));
1021 /* clear any possible error conditions */
1022 pci_write_config_word(agp_bridge->dev, INTEL_I840_ERRSTS, 0xc000);
1026 static int intel_845_configure(void)
1030 struct aper_size_info_8 *current_size;
1032 current_size = A_SIZE_8(agp_bridge->current_size);
1035 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1037 /* address to map to */
1038 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1039 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1041 /* attbase - aperture base */
1042 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1045 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1048 pci_read_config_byte(agp_bridge->dev, INTEL_I845_AGPM, &temp2);
1049 pci_write_config_byte(agp_bridge->dev, INTEL_I845_AGPM, temp2 | (1 << 1));
1050 /* clear any possible error conditions */
1051 pci_write_config_word(agp_bridge->dev, INTEL_I845_ERRSTS, 0x001c);
1055 static int intel_850_configure(void)
1059 struct aper_size_info_8 *current_size;
1061 current_size = A_SIZE_8(agp_bridge->current_size);
1064 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1066 /* address to map to */
1067 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1068 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1070 /* attbase - aperture base */
1071 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1074 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1077 pci_read_config_word(agp_bridge->dev, INTEL_I850_MCHCFG, &temp2);
1078 pci_write_config_word(agp_bridge->dev, INTEL_I850_MCHCFG, temp2 | (1 << 9));
1079 /* clear any possible AGP-related error conditions */
1080 pci_write_config_word(agp_bridge->dev, INTEL_I850_ERRSTS, 0x001c);
1084 static int intel_860_configure(void)
1088 struct aper_size_info_8 *current_size;
1090 current_size = A_SIZE_8(agp_bridge->current_size);
1093 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1095 /* address to map to */
1096 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1097 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1099 /* attbase - aperture base */
1100 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1103 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1106 pci_read_config_word(agp_bridge->dev, INTEL_I860_MCHCFG, &temp2);
1107 pci_write_config_word(agp_bridge->dev, INTEL_I860_MCHCFG, temp2 | (1 << 9));
1108 /* clear any possible AGP-related error conditions */
1109 pci_write_config_word(agp_bridge->dev, INTEL_I860_ERRSTS, 0xf700);
1113 static int intel_830mp_configure(void)
1117 struct aper_size_info_8 *current_size;
1119 current_size = A_SIZE_8(agp_bridge->current_size);
1122 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1124 /* address to map to */
1125 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1126 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1128 /* attbase - aperture base */
1129 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1132 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1135 pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp2);
1136 pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG, temp2 | (1 << 9));
1137 /* clear any possible AGP-related error conditions */
1138 pci_write_config_word(agp_bridge->dev, INTEL_I830_ERRSTS, 0x1c);
1142 static int intel_7505_configure(void)
1146 struct aper_size_info_8 *current_size;
1148 current_size = A_SIZE_8(agp_bridge->current_size);
1151 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1153 /* address to map to */
1154 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1155 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1157 /* attbase - aperture base */
1158 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1161 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1164 pci_read_config_word(agp_bridge->dev, INTEL_I7505_MCHCFG, &temp2);
1165 pci_write_config_word(agp_bridge->dev, INTEL_I7505_MCHCFG, temp2 | (1 << 9));
1170 /* Setup function */
1171 static struct gatt_mask intel_generic_masks[] =
1173 {.mask = 0x00000017, .type = 0}
1176 static struct aper_size_info_8 intel_815_sizes[2] =
1182 static struct aper_size_info_8 intel_8xx_sizes[7] =
1185 {128, 32768, 5, 32},
1193 static struct aper_size_info_16 intel_generic_sizes[7] =
1196 {128, 32768, 5, 32},
1204 static struct aper_size_info_8 intel_830mp_sizes[4] =
1207 {128, 32768, 5, 32},
1212 static struct agp_bridge_driver intel_generic_driver = {
1213 .owner = THIS_MODULE,
1214 .aperture_sizes = intel_generic_sizes,
1215 .size_type = U16_APER_SIZE,
1216 .num_aperture_sizes = 7,
1217 .configure = intel_configure,
1218 .fetch_size = intel_fetch_size,
1219 .cleanup = intel_cleanup,
1220 .tlb_flush = intel_tlbflush,
1221 .mask_memory = agp_generic_mask_memory,
1222 .masks = intel_generic_masks,
1223 .agp_enable = agp_generic_enable,
1224 .cache_flush = global_cache_flush,
1225 .create_gatt_table = agp_generic_create_gatt_table,
1226 .free_gatt_table = agp_generic_free_gatt_table,
1227 .insert_memory = agp_generic_insert_memory,
1228 .remove_memory = agp_generic_remove_memory,
1229 .alloc_by_type = agp_generic_alloc_by_type,
1230 .free_by_type = agp_generic_free_by_type,
1231 .agp_alloc_page = agp_generic_alloc_page,
1232 .agp_destroy_page = agp_generic_destroy_page,
1235 static struct agp_bridge_driver intel_810_driver = {
1236 .owner = THIS_MODULE,
1237 .aperture_sizes = intel_i810_sizes,
1238 .size_type = FIXED_APER_SIZE,
1239 .num_aperture_sizes = 2,
1240 .needs_scratch_page = TRUE,
1241 .configure = intel_i810_configure,
1242 .fetch_size = intel_i810_fetch_size,
1243 .cleanup = intel_i810_cleanup,
1244 .tlb_flush = intel_i810_tlbflush,
1245 .mask_memory = intel_i810_mask_memory,
1246 .masks = intel_i810_masks,
1247 .agp_enable = intel_i810_agp_enable,
1248 .cache_flush = global_cache_flush,
1249 .create_gatt_table = agp_generic_create_gatt_table,
1250 .free_gatt_table = agp_generic_free_gatt_table,
1251 .insert_memory = intel_i810_insert_entries,
1252 .remove_memory = intel_i810_remove_entries,
1253 .alloc_by_type = intel_i810_alloc_by_type,
1254 .free_by_type = intel_i810_free_by_type,
1255 .agp_alloc_page = agp_generic_alloc_page,
1256 .agp_destroy_page = agp_generic_destroy_page,
1259 static struct agp_bridge_driver intel_815_driver = {
1260 .owner = THIS_MODULE,
1261 .aperture_sizes = intel_815_sizes,
1262 .size_type = U8_APER_SIZE,
1263 .num_aperture_sizes = 2,
1264 .configure = intel_815_configure,
1265 .fetch_size = intel_815_fetch_size,
1266 .cleanup = intel_8xx_cleanup,
1267 .tlb_flush = intel_8xx_tlbflush,
1268 .mask_memory = agp_generic_mask_memory,
1269 .masks = intel_generic_masks,
1270 .agp_enable = agp_generic_enable,
1271 .cache_flush = global_cache_flush,
1272 .create_gatt_table = agp_generic_create_gatt_table,
1273 .free_gatt_table = agp_generic_free_gatt_table,
1274 .insert_memory = agp_generic_insert_memory,
1275 .remove_memory = agp_generic_remove_memory,
1276 .alloc_by_type = agp_generic_alloc_by_type,
1277 .free_by_type = agp_generic_free_by_type,
1278 .agp_alloc_page = agp_generic_alloc_page,
1279 .agp_destroy_page = agp_generic_destroy_page,
1282 static struct agp_bridge_driver intel_830_driver = {
1283 .owner = THIS_MODULE,
1284 .aperture_sizes = intel_i830_sizes,
1285 .size_type = FIXED_APER_SIZE,
1286 .num_aperture_sizes = 3,
1287 .needs_scratch_page = TRUE,
1288 .configure = intel_i830_configure,
1289 .fetch_size = intel_i830_fetch_size,
1290 .cleanup = intel_i830_cleanup,
1291 .tlb_flush = intel_i810_tlbflush,
1292 .mask_memory = intel_i810_mask_memory,
1293 .masks = intel_i810_masks,
1294 .agp_enable = intel_i810_agp_enable,
1295 .cache_flush = global_cache_flush,
1296 .create_gatt_table = intel_i830_create_gatt_table,
1297 .free_gatt_table = intel_i830_free_gatt_table,
1298 .insert_memory = intel_i830_insert_entries,
1299 .remove_memory = intel_i830_remove_entries,
1300 .alloc_by_type = intel_i830_alloc_by_type,
1301 .free_by_type = intel_i810_free_by_type,
1302 .agp_alloc_page = agp_generic_alloc_page,
1303 .agp_destroy_page = agp_generic_destroy_page,
1306 static struct agp_bridge_driver intel_820_driver = {
1307 .owner = THIS_MODULE,
1308 .aperture_sizes = intel_8xx_sizes,
1309 .size_type = U8_APER_SIZE,
1310 .num_aperture_sizes = 7,
1311 .configure = intel_820_configure,
1312 .fetch_size = intel_8xx_fetch_size,
1313 .cleanup = intel_820_cleanup,
1314 .tlb_flush = intel_820_tlbflush,
1315 .mask_memory = agp_generic_mask_memory,
1316 .masks = intel_generic_masks,
1317 .agp_enable = agp_generic_enable,
1318 .cache_flush = global_cache_flush,
1319 .create_gatt_table = agp_generic_create_gatt_table,
1320 .free_gatt_table = agp_generic_free_gatt_table,
1321 .insert_memory = agp_generic_insert_memory,
1322 .remove_memory = agp_generic_remove_memory,
1323 .alloc_by_type = agp_generic_alloc_by_type,
1324 .free_by_type = agp_generic_free_by_type,
1325 .agp_alloc_page = agp_generic_alloc_page,
1326 .agp_destroy_page = agp_generic_destroy_page,
1329 static struct agp_bridge_driver intel_830mp_driver = {
1330 .owner = THIS_MODULE,
1331 .aperture_sizes = intel_830mp_sizes,
1332 .size_type = U8_APER_SIZE,
1333 .num_aperture_sizes = 4,
1334 .configure = intel_830mp_configure,
1335 .fetch_size = intel_8xx_fetch_size,
1336 .cleanup = intel_8xx_cleanup,
1337 .tlb_flush = intel_8xx_tlbflush,
1338 .mask_memory = agp_generic_mask_memory,
1339 .masks = intel_generic_masks,
1340 .agp_enable = agp_generic_enable,
1341 .cache_flush = global_cache_flush,
1342 .create_gatt_table = agp_generic_create_gatt_table,
1343 .free_gatt_table = agp_generic_free_gatt_table,
1344 .insert_memory = agp_generic_insert_memory,
1345 .remove_memory = agp_generic_remove_memory,
1346 .alloc_by_type = agp_generic_alloc_by_type,
1347 .free_by_type = agp_generic_free_by_type,
1348 .agp_alloc_page = agp_generic_alloc_page,
1349 .agp_destroy_page = agp_generic_destroy_page,
1352 static struct agp_bridge_driver intel_840_driver = {
1353 .owner = THIS_MODULE,
1354 .aperture_sizes = intel_8xx_sizes,
1355 .size_type = U8_APER_SIZE,
1356 .num_aperture_sizes = 7,
1357 .configure = intel_840_configure,
1358 .fetch_size = intel_8xx_fetch_size,
1359 .cleanup = intel_8xx_cleanup,
1360 .tlb_flush = intel_8xx_tlbflush,
1361 .mask_memory = agp_generic_mask_memory,
1362 .masks = intel_generic_masks,
1363 .agp_enable = agp_generic_enable,
1364 .cache_flush = global_cache_flush,
1365 .create_gatt_table = agp_generic_create_gatt_table,
1366 .free_gatt_table = agp_generic_free_gatt_table,
1367 .insert_memory = agp_generic_insert_memory,
1368 .remove_memory = agp_generic_remove_memory,
1369 .alloc_by_type = agp_generic_alloc_by_type,
1370 .free_by_type = agp_generic_free_by_type,
1371 .agp_alloc_page = agp_generic_alloc_page,
1372 .agp_destroy_page = agp_generic_destroy_page,
1375 static struct agp_bridge_driver intel_845_driver = {
1376 .owner = THIS_MODULE,
1377 .aperture_sizes = intel_8xx_sizes,
1378 .size_type = U8_APER_SIZE,
1379 .num_aperture_sizes = 7,
1380 .configure = intel_845_configure,
1381 .fetch_size = intel_8xx_fetch_size,
1382 .cleanup = intel_8xx_cleanup,
1383 .tlb_flush = intel_8xx_tlbflush,
1384 .mask_memory = agp_generic_mask_memory,
1385 .masks = intel_generic_masks,
1386 .agp_enable = agp_generic_enable,
1387 .cache_flush = global_cache_flush,
1388 .create_gatt_table = agp_generic_create_gatt_table,
1389 .free_gatt_table = agp_generic_free_gatt_table,
1390 .insert_memory = agp_generic_insert_memory,
1391 .remove_memory = agp_generic_remove_memory,
1392 .alloc_by_type = agp_generic_alloc_by_type,
1393 .free_by_type = agp_generic_free_by_type,
1394 .agp_alloc_page = agp_generic_alloc_page,
1395 .agp_destroy_page = agp_generic_destroy_page,
1398 static struct agp_bridge_driver intel_850_driver = {
1399 .owner = THIS_MODULE,
1400 .aperture_sizes = intel_8xx_sizes,
1401 .size_type = U8_APER_SIZE,
1402 .num_aperture_sizes = 7,
1403 .configure = intel_850_configure,
1404 .fetch_size = intel_8xx_fetch_size,
1405 .cleanup = intel_8xx_cleanup,
1406 .tlb_flush = intel_8xx_tlbflush,
1407 .mask_memory = agp_generic_mask_memory,
1408 .masks = intel_generic_masks,
1409 .agp_enable = agp_generic_enable,
1410 .cache_flush = global_cache_flush,
1411 .create_gatt_table = agp_generic_create_gatt_table,
1412 .free_gatt_table = agp_generic_free_gatt_table,
1413 .insert_memory = agp_generic_insert_memory,
1414 .remove_memory = agp_generic_remove_memory,
1415 .alloc_by_type = agp_generic_alloc_by_type,
1416 .free_by_type = agp_generic_free_by_type,
1417 .agp_alloc_page = agp_generic_alloc_page,
1418 .agp_destroy_page = agp_generic_destroy_page,
1421 static struct agp_bridge_driver intel_860_driver = {
1422 .owner = THIS_MODULE,
1423 .aperture_sizes = intel_8xx_sizes,
1424 .size_type = U8_APER_SIZE,
1425 .num_aperture_sizes = 7,
1426 .configure = intel_860_configure,
1427 .fetch_size = intel_8xx_fetch_size,
1428 .cleanup = intel_8xx_cleanup,
1429 .tlb_flush = intel_8xx_tlbflush,
1430 .mask_memory = agp_generic_mask_memory,
1431 .masks = intel_generic_masks,
1432 .agp_enable = agp_generic_enable,
1433 .cache_flush = global_cache_flush,
1434 .create_gatt_table = agp_generic_create_gatt_table,
1435 .free_gatt_table = agp_generic_free_gatt_table,
1436 .insert_memory = agp_generic_insert_memory,
1437 .remove_memory = agp_generic_remove_memory,
1438 .alloc_by_type = agp_generic_alloc_by_type,
1439 .free_by_type = agp_generic_free_by_type,
1440 .agp_alloc_page = agp_generic_alloc_page,
1441 .agp_destroy_page = agp_generic_destroy_page,
1444 static struct agp_bridge_driver intel_915_driver = {
1445 .owner = THIS_MODULE,
1446 .aperture_sizes = intel_i830_sizes,
1447 .size_type = FIXED_APER_SIZE,
1448 .num_aperture_sizes = 3,
1449 .needs_scratch_page = TRUE,
1450 .configure = intel_i915_configure,
1451 .fetch_size = intel_i915_fetch_size,
1452 .cleanup = intel_i915_cleanup,
1453 .tlb_flush = intel_i810_tlbflush,
1454 .mask_memory = intel_i810_mask_memory,
1455 .masks = intel_i810_masks,
1456 .agp_enable = intel_i810_agp_enable,
1457 .cache_flush = global_cache_flush,
1458 .create_gatt_table = intel_i915_create_gatt_table,
1459 .free_gatt_table = intel_i830_free_gatt_table,
1460 .insert_memory = intel_i915_insert_entries,
1461 .remove_memory = intel_i915_remove_entries,
1462 .alloc_by_type = intel_i830_alloc_by_type,
1463 .free_by_type = intel_i810_free_by_type,
1464 .agp_alloc_page = agp_generic_alloc_page,
1465 .agp_destroy_page = agp_generic_destroy_page,
1469 static struct agp_bridge_driver intel_7505_driver = {
1470 .owner = THIS_MODULE,
1471 .aperture_sizes = intel_8xx_sizes,
1472 .size_type = U8_APER_SIZE,
1473 .num_aperture_sizes = 7,
1474 .configure = intel_7505_configure,
1475 .fetch_size = intel_8xx_fetch_size,
1476 .cleanup = intel_8xx_cleanup,
1477 .tlb_flush = intel_8xx_tlbflush,
1478 .mask_memory = agp_generic_mask_memory,
1479 .masks = intel_generic_masks,
1480 .agp_enable = agp_generic_enable,
1481 .cache_flush = global_cache_flush,
1482 .create_gatt_table = agp_generic_create_gatt_table,
1483 .free_gatt_table = agp_generic_free_gatt_table,
1484 .insert_memory = agp_generic_insert_memory,
1485 .remove_memory = agp_generic_remove_memory,
1486 .alloc_by_type = agp_generic_alloc_by_type,
1487 .free_by_type = agp_generic_free_by_type,
1488 .agp_alloc_page = agp_generic_alloc_page,
1489 .agp_destroy_page = agp_generic_destroy_page,
1492 static int find_i810(u16 device)
1494 struct pci_dev *i810_dev;
1496 i810_dev = pci_find_device(PCI_VENDOR_ID_INTEL, device, NULL);
1499 intel_i810_private.i810_dev = i810_dev;
1503 static int find_i830(u16 device)
1505 struct pci_dev *i830_dev;
1507 i830_dev = pci_find_device(PCI_VENDOR_ID_INTEL, device, NULL);
1508 if (i830_dev && PCI_FUNC(i830_dev->devfn) != 0) {
1509 i830_dev = pci_find_device(PCI_VENDOR_ID_INTEL,
1516 intel_i830_private.i830_dev = i830_dev;
1520 static int __devinit agp_intel_probe(struct pci_dev *pdev,
1521 const struct pci_device_id *ent)
1523 struct agp_bridge_data *bridge;
1524 char *name = "(unknown)";
1528 cap_ptr = pci_find_capability(pdev, PCI_CAP_ID_AGP);
1530 bridge = agp_alloc_bridge();
1534 switch (pdev->device) {
1535 case PCI_DEVICE_ID_INTEL_82443LX_0:
1536 bridge->driver = &intel_generic_driver;
1539 case PCI_DEVICE_ID_INTEL_82443BX_0:
1540 bridge->driver = &intel_generic_driver;
1543 case PCI_DEVICE_ID_INTEL_82443GX_0:
1544 bridge->driver = &intel_generic_driver;
1547 case PCI_DEVICE_ID_INTEL_82810_MC1:
1549 if (!find_i810(PCI_DEVICE_ID_INTEL_82810_IG1))
1551 bridge->driver = &intel_810_driver;
1553 case PCI_DEVICE_ID_INTEL_82810_MC3:
1554 name = "i810 DC100";
1555 if (!find_i810(PCI_DEVICE_ID_INTEL_82810_IG3))
1557 bridge->driver = &intel_810_driver;
1559 case PCI_DEVICE_ID_INTEL_82810E_MC:
1561 if (!find_i810(PCI_DEVICE_ID_INTEL_82810E_IG))
1563 bridge->driver = &intel_810_driver;
1565 case PCI_DEVICE_ID_INTEL_82815_MC:
1567 * The i815 can operate either as an i810 style
1568 * integrated device, or as an AGP4X motherboard.
1570 if (find_i810(PCI_DEVICE_ID_INTEL_82815_CGC))
1571 bridge->driver = &intel_810_driver;
1573 bridge->driver = &intel_815_driver;
1576 case PCI_DEVICE_ID_INTEL_82820_HB:
1577 case PCI_DEVICE_ID_INTEL_82820_UP_HB:
1578 bridge->driver = &intel_820_driver;
1581 case PCI_DEVICE_ID_INTEL_82830_HB:
1582 if (find_i830(PCI_DEVICE_ID_INTEL_82830_CGC)) {
1583 bridge->driver = &intel_830_driver;
1585 bridge->driver = &intel_830mp_driver;
1589 case PCI_DEVICE_ID_INTEL_82840_HB:
1590 bridge->driver = &intel_840_driver;
1593 case PCI_DEVICE_ID_INTEL_82845_HB:
1594 bridge->driver = &intel_845_driver;
1597 case PCI_DEVICE_ID_INTEL_82845G_HB:
1598 if (find_i830(PCI_DEVICE_ID_INTEL_82845G_IG)) {
1599 bridge->driver = &intel_830_driver;
1601 bridge->driver = &intel_845_driver;
1605 case PCI_DEVICE_ID_INTEL_82850_HB:
1606 bridge->driver = &intel_850_driver;
1609 case PCI_DEVICE_ID_INTEL_82855PM_HB:
1610 bridge->driver = &intel_845_driver;
1613 case PCI_DEVICE_ID_INTEL_82855GM_HB:
1614 if (find_i830(PCI_DEVICE_ID_INTEL_82855GM_IG)) {
1615 bridge->driver = &intel_830_driver;
1618 bridge->driver = &intel_845_driver;
1622 case PCI_DEVICE_ID_INTEL_82860_HB:
1623 bridge->driver = &intel_860_driver;
1626 case PCI_DEVICE_ID_INTEL_82865_HB:
1627 if (find_i830(PCI_DEVICE_ID_INTEL_82865_IG)) {
1628 bridge->driver = &intel_830_driver;
1630 bridge->driver = &intel_845_driver;
1634 case PCI_DEVICE_ID_INTEL_82875_HB:
1635 bridge->driver = &intel_845_driver;
1638 case PCI_DEVICE_ID_INTEL_82915G_HB:
1639 if (find_i830(PCI_DEVICE_ID_INTEL_82915G_IG)) {
1640 bridge->driver = &intel_915_driver;
1642 bridge->driver = &intel_845_driver;
1646 case PCI_DEVICE_ID_INTEL_7505_0:
1647 bridge->driver = &intel_7505_driver;
1650 case PCI_DEVICE_ID_INTEL_7205_0:
1651 bridge->driver = &intel_7505_driver;
1656 printk(KERN_WARNING PFX "Unsupported Intel chipset (device id: %04x)\n",
1658 agp_put_bridge(bridge);
1663 bridge->capndx = cap_ptr;
1665 if (bridge->driver == &intel_810_driver)
1666 bridge->dev_private_data = &intel_i810_private;
1667 else if (bridge->driver == &intel_830_driver)
1668 bridge->dev_private_data = &intel_i830_private;
1670 printk(KERN_INFO PFX "Detected an Intel %s Chipset.\n", name);
1673 * The following fixes the case where the BIOS has "forgotten" to
1674 * provide an address range for the GART.
1675 * 20030610 - hamish@zot.org
1677 r = &pdev->resource[0];
1678 if (!r->start && r->end) {
1679 if(pci_assign_resource(pdev, 0)) {
1680 printk(KERN_ERR PFX "could not assign resource 0\n");
1681 agp_put_bridge(bridge);
1687 * If the device has not been properly setup, the following will catch
1688 * the problem and should stop the system from crashing.
1689 * 20030610 - hamish@zot.org
1691 if (pci_enable_device(pdev)) {
1692 printk(KERN_ERR PFX "Unable to Enable PCI device\n");
1693 agp_put_bridge(bridge);
1697 /* Fill in the mode register */
1699 pci_read_config_dword(pdev,
1700 bridge->capndx+PCI_AGP_STATUS,
1704 pci_set_drvdata(pdev, bridge);
1705 return agp_add_bridge(bridge);
1708 printk(KERN_ERR PFX "Detected an Intel %s chipset, "
1709 "but could not find the secondary device.\n", name);
1710 agp_put_bridge(bridge);
1714 static void __devexit agp_intel_remove(struct pci_dev *pdev)
1716 struct agp_bridge_data *bridge = pci_get_drvdata(pdev);
1718 agp_remove_bridge(bridge);
1719 agp_put_bridge(bridge);
1722 static int agp_intel_resume(struct pci_dev *pdev)
1724 struct agp_bridge_data *bridge = pci_get_drvdata(pdev);
1726 pci_restore_state(pdev, pdev->saved_config_space);
1728 if (bridge->driver == &intel_generic_driver)
1730 else if (bridge->driver == &intel_845_driver)
1731 intel_845_configure();
1732 else if (bridge->driver == &intel_830mp_driver)
1733 intel_830mp_configure();
1734 else if (bridge->driver == &intel_915_driver)
1735 intel_i915_configure();
1740 static struct pci_device_id agp_intel_pci_table[] = {
1743 .class = (PCI_CLASS_BRIDGE_HOST << 8), \
1745 .vendor = PCI_VENDOR_ID_INTEL, \
1747 .subvendor = PCI_ANY_ID, \
1748 .subdevice = PCI_ANY_ID, \
1750 ID(PCI_DEVICE_ID_INTEL_82443LX_0),
1751 ID(PCI_DEVICE_ID_INTEL_82443BX_0),
1752 ID(PCI_DEVICE_ID_INTEL_82443GX_0),
1753 ID(PCI_DEVICE_ID_INTEL_82810_MC1),
1754 ID(PCI_DEVICE_ID_INTEL_82810_MC3),
1755 ID(PCI_DEVICE_ID_INTEL_82810E_MC),
1756 ID(PCI_DEVICE_ID_INTEL_82815_MC),
1757 ID(PCI_DEVICE_ID_INTEL_82820_HB),
1758 ID(PCI_DEVICE_ID_INTEL_82820_UP_HB),
1759 ID(PCI_DEVICE_ID_INTEL_82830_HB),
1760 ID(PCI_DEVICE_ID_INTEL_82840_HB),
1761 ID(PCI_DEVICE_ID_INTEL_82845_HB),
1762 ID(PCI_DEVICE_ID_INTEL_82845G_HB),
1763 ID(PCI_DEVICE_ID_INTEL_82850_HB),
1764 ID(PCI_DEVICE_ID_INTEL_82855PM_HB),
1765 ID(PCI_DEVICE_ID_INTEL_82855GM_HB),
1766 ID(PCI_DEVICE_ID_INTEL_82860_HB),
1767 ID(PCI_DEVICE_ID_INTEL_82865_HB),
1768 ID(PCI_DEVICE_ID_INTEL_82875_HB),
1769 ID(PCI_DEVICE_ID_INTEL_7505_0),
1770 ID(PCI_DEVICE_ID_INTEL_7205_0),
1771 ID(PCI_DEVICE_ID_INTEL_82915G_HB),
1775 MODULE_DEVICE_TABLE(pci, agp_intel_pci_table);
1777 static struct pci_driver agp_intel_pci_driver = {
1778 .name = "agpgart-intel",
1779 .id_table = agp_intel_pci_table,
1780 .probe = agp_intel_probe,
1781 .remove = __devexit_p(agp_intel_remove),
1782 .resume = agp_intel_resume,
1785 /* intel_agp_init() must not be declared static for explicit
1786 early initialization to work (ie i810fb) */
1787 int __init agp_intel_init(void)
1789 static int agp_initialised=0;
1791 if (agp_initialised == 1)
1795 return pci_module_init(&agp_intel_pci_driver);
1798 static void __exit agp_intel_cleanup(void)
1800 pci_unregister_driver(&agp_intel_pci_driver);
1803 module_init(agp_intel_init);
1804 module_exit(agp_intel_cleanup);
1806 MODULE_AUTHOR("Dave Jones <davej@codemonkey.org.uk>");
1807 MODULE_LICENSE("GPL and additional rights");