2 * Intel AGPGART routines.
6 * Intel(R) 855GM/852GM and 865G support added by David Dawes
7 * <dawes@tungstengraphics.com>.
9 * Intel(R) 915G/915GM 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 ((readl(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 writel(agp_bridge->gatt_bus_addr | I810_PGETBL_ENABLED, intel_i810_private.registers+I810_PGETBL_CTL);
129 readl(intel_i810_private.registers+I810_PGETBL_CTL); /* PCI Posting. */
131 if (agp_bridge->driver->needs_scratch_page) {
132 for (i = 0; i < current_size->num_entries; i++) {
133 writel(agp_bridge->scratch_page, intel_i810_private.registers+I810_PTE_BASE+(i*4));
134 readl(intel_i810_private.registers+I810_PTE_BASE+(i*4)); /* PCI posting. */
137 global_cache_flush();
141 static void intel_i810_cleanup(void)
143 writel(0, intel_i810_private.registers+I810_PGETBL_CTL);
144 readl(intel_i810_private.registers); /* PCI Posting. */
145 iounmap(intel_i810_private.registers);
148 static void intel_i810_tlbflush(struct agp_memory *mem)
153 static void intel_i810_agp_enable(struct agp_bridge_data *bridge, 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) {
175 atomic_inc(&agp_bridge->current_memory_agp);
176 return page_address(page);
179 static void i8xx_destroy_pages(void *addr)
186 page = virt_to_page(addr);
187 change_page_attr(page, 4, PAGE_KERNEL);
191 free_pages((unsigned long)addr, 2);
192 atomic_dec(&agp_bridge->current_memory_agp);
195 static int intel_i810_insert_entries(struct agp_memory *mem, off_t pg_start,
198 int i, j, num_entries;
201 temp = agp_bridge->current_size;
202 num_entries = A_SIZE_FIX(temp)->num_entries;
204 if ((pg_start + mem->page_count) > num_entries) {
207 for (j = pg_start; j < (pg_start + mem->page_count); j++) {
208 if (!PGE_EMPTY(agp_bridge, readl(agp_bridge->gatt_table+j)))
212 if (type != 0 || mem->type != 0) {
213 if ((type == AGP_DCACHE_MEMORY) && (mem->type == AGP_DCACHE_MEMORY)) {
215 global_cache_flush();
216 for (i = pg_start; i < (pg_start + mem->page_count); i++) {
217 writel((i*4096)|I810_PTE_LOCAL|I810_PTE_VALID, intel_i810_private.registers+I810_PTE_BASE+(i*4));
218 readl(intel_i810_private.registers+I810_PTE_BASE+(i*4)); /* PCI Posting. */
220 global_cache_flush();
221 agp_bridge->driver->tlb_flush(mem);
224 if((type == AGP_PHYS_MEMORY) && (mem->type == AGP_PHYS_MEMORY))
230 global_cache_flush();
231 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
232 writel(agp_bridge->driver->mask_memory(agp_bridge,
233 mem->memory[i], mem->type),
234 intel_i810_private.registers+I810_PTE_BASE+(j*4));
235 readl(intel_i810_private.registers+I810_PTE_BASE+(j*4)); /* PCI Posting. */
237 global_cache_flush();
239 agp_bridge->driver->tlb_flush(mem);
243 static int intel_i810_remove_entries(struct agp_memory *mem, off_t pg_start,
248 for (i = pg_start; i < (mem->page_count + pg_start); i++) {
249 writel(agp_bridge->scratch_page, intel_i810_private.registers+I810_PTE_BASE+(i*4));
250 readl(intel_i810_private.registers+I810_PTE_BASE+(i*4)); /* PCI Posting. */
253 global_cache_flush();
254 agp_bridge->driver->tlb_flush(mem);
259 * The i810/i830 requires a physical address to program its mouse
260 * pointer into hardware.
261 * However the Xserver still writes to it through the agp aperture.
263 static struct agp_memory *alloc_agpphysmem_i8xx(size_t pg_count, int type)
265 struct agp_memory *new;
268 if (pg_count != 1 && pg_count != 4)
272 case 1: addr = agp_bridge->driver->agp_alloc_page(agp_bridge);
275 /* kludge to get 4 physical pages for ARGB cursor */
276 addr = i8xx_alloc_pages();
285 new = agp_create_memory(pg_count);
289 new->memory[0] = virt_to_gart(addr);
291 /* kludge to get 4 physical pages for ARGB cursor */
292 new->memory[1] = new->memory[0] + PAGE_SIZE;
293 new->memory[2] = new->memory[1] + PAGE_SIZE;
294 new->memory[3] = new->memory[2] + PAGE_SIZE;
296 new->page_count = pg_count;
297 new->num_scratch_pages = pg_count;
298 new->type = AGP_PHYS_MEMORY;
299 new->physical = new->memory[0];
303 static struct agp_memory *intel_i810_alloc_by_type(size_t pg_count, int type)
305 struct agp_memory *new;
307 if (type == AGP_DCACHE_MEMORY) {
308 if (pg_count != intel_i810_private.num_dcache_entries)
311 new = agp_create_memory(1);
315 new->type = AGP_DCACHE_MEMORY;
316 new->page_count = pg_count;
317 new->num_scratch_pages = 0;
321 if (type == AGP_PHYS_MEMORY)
322 return alloc_agpphysmem_i8xx(pg_count, type);
327 static void intel_i810_free_by_type(struct agp_memory *curr)
329 agp_free_key(curr->key);
330 if(curr->type == AGP_PHYS_MEMORY) {
331 if (curr->page_count == 4)
332 i8xx_destroy_pages(gart_to_virt(curr->memory[0]));
334 agp_bridge->driver->agp_destroy_page(
335 gart_to_virt(curr->memory[0]));
341 static unsigned long intel_i810_mask_memory(struct agp_bridge_data *bridge,
342 unsigned long addr, int type)
344 /* Type checking must be done elsewhere */
345 return addr | bridge->driver->masks[type].mask;
348 static struct aper_size_info_fixed intel_i830_sizes[] =
351 /* The 64M mode still requires a 128k gatt */
356 static struct _intel_i830_private {
357 struct pci_dev *i830_dev; /* device one */
358 volatile u8 __iomem *registers;
359 volatile u32 __iomem *gtt; /* I915G */
361 } intel_i830_private;
363 static void intel_i830_init_gtt_entries(void)
369 static const int ddt[4] = { 0, 16, 32, 64 };
372 pci_read_config_word(agp_bridge->dev,I830_GMCH_CTRL,&gmch_ctrl);
374 /* We obtain the size of the GTT, which is also stored (for some
375 * reason) at the top of stolen memory. Then we add 4KB to that
376 * for the video BIOS popup, which is also stored in there. */
377 size = agp_bridge->driver->fetch_size() + 4;
379 if (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82830_HB ||
380 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82845G_HB) {
381 switch (gmch_ctrl & I830_GMCH_GMS_MASK) {
382 case I830_GMCH_GMS_STOLEN_512:
383 gtt_entries = KB(512) - KB(size);
385 case I830_GMCH_GMS_STOLEN_1024:
386 gtt_entries = MB(1) - KB(size);
388 case I830_GMCH_GMS_STOLEN_8192:
389 gtt_entries = MB(8) - KB(size);
391 case I830_GMCH_GMS_LOCAL:
392 rdct = readb(intel_i830_private.registers+I830_RDRAM_CHANNEL_TYPE);
393 gtt_entries = (I830_RDRAM_ND(rdct) + 1) *
394 MB(ddt[I830_RDRAM_DDT(rdct)]);
402 switch (gmch_ctrl & I830_GMCH_GMS_MASK) {
403 case I855_GMCH_GMS_STOLEN_1M:
404 gtt_entries = MB(1) - KB(size);
406 case I855_GMCH_GMS_STOLEN_4M:
407 gtt_entries = MB(4) - KB(size);
409 case I855_GMCH_GMS_STOLEN_8M:
410 gtt_entries = MB(8) - KB(size);
412 case I855_GMCH_GMS_STOLEN_16M:
413 gtt_entries = MB(16) - KB(size);
415 case I855_GMCH_GMS_STOLEN_32M:
416 gtt_entries = MB(32) - KB(size);
418 case I915_GMCH_GMS_STOLEN_48M:
419 /* Check it's really I915G */
420 if (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82915G_HB ||
421 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82915GM_HB ||
422 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82945G_HB)
423 gtt_entries = MB(48) - KB(size);
427 case I915_GMCH_GMS_STOLEN_64M:
428 /* Check it's really I915G */
429 if (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82915G_HB ||
430 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82915GM_HB ||
431 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82945G_HB)
432 gtt_entries = MB(64) - KB(size);
441 printk(KERN_INFO PFX "Detected %dK %s memory.\n",
442 gtt_entries / KB(1), local ? "local" : "stolen");
445 "No pre-allocated video memory detected.\n");
446 gtt_entries /= KB(4);
448 intel_i830_private.gtt_entries = gtt_entries;
451 /* The intel i830 automatically initializes the agp aperture during POST.
452 * Use the memory already set aside for in the GTT.
454 static int intel_i830_create_gatt_table(struct agp_bridge_data *bridge)
457 struct aper_size_info_fixed *size;
461 size = agp_bridge->current_size;
462 page_order = size->page_order;
463 num_entries = size->num_entries;
464 agp_bridge->gatt_table_real = NULL;
466 pci_read_config_dword(intel_i830_private.i830_dev,I810_MMADDR,&temp);
469 intel_i830_private.registers = ioremap(temp,128 * 4096);
470 if (!intel_i830_private.registers)
473 temp = readl(intel_i830_private.registers+I810_PGETBL_CTL) & 0xfffff000;
474 global_cache_flush(); /* FIXME: ?? */
476 /* we have to call this as early as possible after the MMIO base address is known */
477 intel_i830_init_gtt_entries();
479 agp_bridge->gatt_table = NULL;
481 agp_bridge->gatt_bus_addr = temp;
486 /* Return the gatt table to a sane state. Use the top of stolen
487 * memory for the GTT.
489 static int intel_i830_free_gatt_table(struct agp_bridge_data *bridge)
494 static int intel_i830_fetch_size(void)
497 struct aper_size_info_fixed *values;
499 values = A_SIZE_FIX(agp_bridge->driver->aperture_sizes);
501 if (agp_bridge->dev->device != PCI_DEVICE_ID_INTEL_82830_HB &&
502 agp_bridge->dev->device != PCI_DEVICE_ID_INTEL_82845G_HB) {
503 /* 855GM/852GM/865G has 128MB aperture size */
504 agp_bridge->previous_size = agp_bridge->current_size = (void *) values;
505 agp_bridge->aperture_size_idx = 0;
506 return values[0].size;
509 pci_read_config_word(agp_bridge->dev,I830_GMCH_CTRL,&gmch_ctrl);
511 if ((gmch_ctrl & I830_GMCH_MEM_MASK) == I830_GMCH_MEM_128M) {
512 agp_bridge->previous_size = agp_bridge->current_size = (void *) values;
513 agp_bridge->aperture_size_idx = 0;
514 return values[0].size;
516 agp_bridge->previous_size = agp_bridge->current_size = (void *) (values + 1);
517 agp_bridge->aperture_size_idx = 1;
518 return values[1].size;
524 static int intel_i830_configure(void)
526 struct aper_size_info_fixed *current_size;
531 current_size = A_SIZE_FIX(agp_bridge->current_size);
533 pci_read_config_dword(intel_i830_private.i830_dev,I810_GMADDR,&temp);
534 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
536 pci_read_config_word(agp_bridge->dev,I830_GMCH_CTRL,&gmch_ctrl);
537 gmch_ctrl |= I830_GMCH_ENABLED;
538 pci_write_config_word(agp_bridge->dev,I830_GMCH_CTRL,gmch_ctrl);
540 writel(agp_bridge->gatt_bus_addr|I810_PGETBL_ENABLED, intel_i830_private.registers+I810_PGETBL_CTL);
541 readl(intel_i830_private.registers+I810_PGETBL_CTL); /* PCI Posting. */
543 if (agp_bridge->driver->needs_scratch_page) {
544 for (i = intel_i830_private.gtt_entries; i < current_size->num_entries; i++) {
545 writel(agp_bridge->scratch_page, intel_i830_private.registers+I810_PTE_BASE+(i*4));
546 readl(intel_i830_private.registers+I810_PTE_BASE+(i*4)); /* PCI Posting. */
550 global_cache_flush();
554 static void intel_i830_cleanup(void)
556 iounmap(intel_i830_private.registers);
559 static int intel_i830_insert_entries(struct agp_memory *mem,off_t pg_start, int type)
564 temp = agp_bridge->current_size;
565 num_entries = A_SIZE_FIX(temp)->num_entries;
567 if (pg_start < intel_i830_private.gtt_entries) {
568 printk (KERN_DEBUG PFX "pg_start == 0x%.8lx,intel_i830_private.gtt_entries == 0x%.8x\n",
569 pg_start,intel_i830_private.gtt_entries);
571 printk (KERN_INFO PFX "Trying to insert into local/stolen memory\n");
575 if ((pg_start + mem->page_count) > num_entries)
578 /* The i830 can't check the GTT for entries since its read only,
579 * depend on the caller to make the correct offset decisions.
582 if ((type != 0 && type != AGP_PHYS_MEMORY) ||
583 (mem->type != 0 && mem->type != AGP_PHYS_MEMORY))
586 global_cache_flush(); /* FIXME: Necessary ?*/
588 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
589 writel(agp_bridge->driver->mask_memory(agp_bridge,
590 mem->memory[i], mem->type),
591 intel_i830_private.registers+I810_PTE_BASE+(j*4));
592 readl(intel_i830_private.registers+I810_PTE_BASE+(j*4)); /* PCI Posting. */
595 global_cache_flush();
596 agp_bridge->driver->tlb_flush(mem);
600 static int intel_i830_remove_entries(struct agp_memory *mem,off_t pg_start,
605 global_cache_flush();
607 if (pg_start < intel_i830_private.gtt_entries) {
608 printk (KERN_INFO PFX "Trying to disable local/stolen memory\n");
612 for (i = pg_start; i < (mem->page_count + pg_start); i++) {
613 writel(agp_bridge->scratch_page, intel_i830_private.registers+I810_PTE_BASE+(i*4));
614 readl(intel_i830_private.registers+I810_PTE_BASE+(i*4)); /* PCI Posting. */
617 global_cache_flush();
618 agp_bridge->driver->tlb_flush(mem);
622 static struct agp_memory *intel_i830_alloc_by_type(size_t pg_count,int type)
624 if (type == AGP_PHYS_MEMORY)
625 return alloc_agpphysmem_i8xx(pg_count, type);
627 /* always return NULL for other allocation types for now */
631 static int intel_i915_configure(void)
633 struct aper_size_info_fixed *current_size;
638 current_size = A_SIZE_FIX(agp_bridge->current_size);
640 pci_read_config_dword(intel_i830_private.i830_dev, I915_GMADDR, &temp);
642 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
644 pci_read_config_word(agp_bridge->dev,I830_GMCH_CTRL,&gmch_ctrl);
645 gmch_ctrl |= I830_GMCH_ENABLED;
646 pci_write_config_word(agp_bridge->dev,I830_GMCH_CTRL,gmch_ctrl);
648 writel(agp_bridge->gatt_bus_addr|I810_PGETBL_ENABLED, intel_i830_private.registers+I810_PGETBL_CTL);
649 readl(intel_i830_private.registers+I810_PGETBL_CTL); /* PCI Posting. */
651 if (agp_bridge->driver->needs_scratch_page) {
652 for (i = intel_i830_private.gtt_entries; i < current_size->num_entries; i++) {
653 writel(agp_bridge->scratch_page, intel_i830_private.gtt+i);
654 readl(intel_i830_private.gtt+i); /* PCI Posting. */
658 global_cache_flush();
662 static void intel_i915_cleanup(void)
664 iounmap(intel_i830_private.gtt);
665 iounmap(intel_i830_private.registers);
668 static int intel_i915_insert_entries(struct agp_memory *mem,off_t pg_start,
674 temp = agp_bridge->current_size;
675 num_entries = A_SIZE_FIX(temp)->num_entries;
677 if (pg_start < intel_i830_private.gtt_entries) {
678 printk (KERN_DEBUG PFX "pg_start == 0x%.8lx,intel_i830_private.gtt_entries == 0x%.8x\n",
679 pg_start,intel_i830_private.gtt_entries);
681 printk (KERN_INFO PFX "Trying to insert into local/stolen memory\n");
685 if ((pg_start + mem->page_count) > num_entries)
688 /* The i830 can't check the GTT for entries since its read only,
689 * depend on the caller to make the correct offset decisions.
692 if ((type != 0 && type != AGP_PHYS_MEMORY) ||
693 (mem->type != 0 && mem->type != AGP_PHYS_MEMORY))
696 global_cache_flush();
698 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
699 writel(agp_bridge->driver->mask_memory(agp_bridge,
700 mem->memory[i], mem->type), intel_i830_private.gtt+j);
701 readl(intel_i830_private.gtt+j); /* PCI Posting. */
704 global_cache_flush();
705 agp_bridge->driver->tlb_flush(mem);
709 static int intel_i915_remove_entries(struct agp_memory *mem,off_t pg_start,
714 global_cache_flush();
716 if (pg_start < intel_i830_private.gtt_entries) {
717 printk (KERN_INFO PFX "Trying to disable local/stolen memory\n");
721 for (i = pg_start; i < (mem->page_count + pg_start); i++) {
722 writel(agp_bridge->scratch_page, intel_i830_private.gtt+i);
723 readl(intel_i830_private.gtt+i);
726 global_cache_flush();
727 agp_bridge->driver->tlb_flush(mem);
731 static int intel_i915_fetch_size(void)
733 struct aper_size_info_fixed *values;
734 u32 temp, offset = 0;
736 #define I915_256MB_ADDRESS_MASK (1<<27)
738 values = A_SIZE_FIX(agp_bridge->driver->aperture_sizes);
740 pci_read_config_dword(intel_i830_private.i830_dev, I915_GMADDR, &temp);
741 if (temp & I915_256MB_ADDRESS_MASK)
742 offset = 0; /* 128MB aperture */
744 offset = 2; /* 256MB aperture */
745 agp_bridge->previous_size = agp_bridge->current_size = (void *)(values + offset);
746 return values[offset].size;
749 /* The intel i915 automatically initializes the agp aperture during POST.
750 * Use the memory already set aside for in the GTT.
752 static int intel_i915_create_gatt_table(struct agp_bridge_data *bridge)
755 struct aper_size_info_fixed *size;
759 size = agp_bridge->current_size;
760 page_order = size->page_order;
761 num_entries = size->num_entries;
762 agp_bridge->gatt_table_real = NULL;
764 pci_read_config_dword(intel_i830_private.i830_dev, I915_MMADDR, &temp);
765 pci_read_config_dword(intel_i830_private.i830_dev, I915_PTEADDR,&temp2);
767 intel_i830_private.gtt = ioremap(temp2, 256 * 1024);
768 if (!intel_i830_private.gtt)
773 intel_i830_private.registers = ioremap(temp,128 * 4096);
774 if (!intel_i830_private.registers)
777 temp = readl(intel_i830_private.registers+I810_PGETBL_CTL) & 0xfffff000;
778 global_cache_flush(); /* FIXME: ? */
780 /* we have to call this as early as possible after the MMIO base address is known */
781 intel_i830_init_gtt_entries();
783 agp_bridge->gatt_table = NULL;
785 agp_bridge->gatt_bus_addr = temp;
790 static int intel_fetch_size(void)
794 struct aper_size_info_16 *values;
796 pci_read_config_word(agp_bridge->dev, INTEL_APSIZE, &temp);
797 values = A_SIZE_16(agp_bridge->driver->aperture_sizes);
799 for (i = 0; i < agp_bridge->driver->num_aperture_sizes; i++) {
800 if (temp == values[i].size_value) {
801 agp_bridge->previous_size = agp_bridge->current_size = (void *) (values + i);
802 agp_bridge->aperture_size_idx = i;
803 return values[i].size;
810 static int __intel_8xx_fetch_size(u8 temp)
813 struct aper_size_info_8 *values;
815 values = A_SIZE_8(agp_bridge->driver->aperture_sizes);
817 for (i = 0; i < agp_bridge->driver->num_aperture_sizes; i++) {
818 if (temp == values[i].size_value) {
819 agp_bridge->previous_size =
820 agp_bridge->current_size = (void *) (values + i);
821 agp_bridge->aperture_size_idx = i;
822 return values[i].size;
828 static int intel_8xx_fetch_size(void)
832 pci_read_config_byte(agp_bridge->dev, INTEL_APSIZE, &temp);
833 return __intel_8xx_fetch_size(temp);
836 static int intel_815_fetch_size(void)
840 /* Intel 815 chipsets have a _weird_ APSIZE register with only
841 * one non-reserved bit, so mask the others out ... */
842 pci_read_config_byte(agp_bridge->dev, INTEL_APSIZE, &temp);
845 return __intel_8xx_fetch_size(temp);
848 static void intel_tlbflush(struct agp_memory *mem)
850 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x2200);
851 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x2280);
855 static void intel_8xx_tlbflush(struct agp_memory *mem)
858 pci_read_config_dword(agp_bridge->dev, INTEL_AGPCTRL, &temp);
859 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, temp & ~(1 << 7));
860 pci_read_config_dword(agp_bridge->dev, INTEL_AGPCTRL, &temp);
861 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, temp | (1 << 7));
865 static void intel_cleanup(void)
868 struct aper_size_info_16 *previous_size;
870 previous_size = A_SIZE_16(agp_bridge->previous_size);
871 pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp);
872 pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG, temp & ~(1 << 9));
873 pci_write_config_word(agp_bridge->dev, INTEL_APSIZE, previous_size->size_value);
877 static void intel_8xx_cleanup(void)
880 struct aper_size_info_8 *previous_size;
882 previous_size = A_SIZE_8(agp_bridge->previous_size);
883 pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp);
884 pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG, temp & ~(1 << 9));
885 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, previous_size->size_value);
889 static int intel_configure(void)
893 struct aper_size_info_16 *current_size;
895 current_size = A_SIZE_16(agp_bridge->current_size);
898 pci_write_config_word(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
900 /* address to map to */
901 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
902 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
904 /* attbase - aperture base */
905 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
908 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x2280);
911 pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp2);
912 pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG,
913 (temp2 & ~(1 << 10)) | (1 << 9));
914 /* clear any possible error conditions */
915 pci_write_config_byte(agp_bridge->dev, INTEL_ERRSTS + 1, 7);
919 static int intel_815_configure(void)
923 struct aper_size_info_8 *current_size;
925 /* attbase - aperture base */
926 /* the Intel 815 chipset spec. says that bits 29-31 in the
927 * ATTBASE register are reserved -> try not to write them */
928 if (agp_bridge->gatt_bus_addr & INTEL_815_ATTBASE_MASK) {
929 printk (KERN_EMERG PFX "gatt bus addr too high");
933 current_size = A_SIZE_8(agp_bridge->current_size);
936 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE,
937 current_size->size_value);
939 /* address to map to */
940 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
941 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
943 pci_read_config_dword(agp_bridge->dev, INTEL_ATTBASE, &addr);
944 addr &= INTEL_815_ATTBASE_MASK;
945 addr |= agp_bridge->gatt_bus_addr;
946 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, addr);
949 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
952 pci_read_config_byte(agp_bridge->dev, INTEL_815_APCONT, &temp2);
953 pci_write_config_byte(agp_bridge->dev, INTEL_815_APCONT, temp2 | (1 << 1));
955 /* clear any possible error conditions */
956 /* Oddness : this chipset seems to have no ERRSTS register ! */
960 static void intel_820_tlbflush(struct agp_memory *mem)
965 static void intel_820_cleanup(void)
968 struct aper_size_info_8 *previous_size;
970 previous_size = A_SIZE_8(agp_bridge->previous_size);
971 pci_read_config_byte(agp_bridge->dev, INTEL_I820_RDCR, &temp);
972 pci_write_config_byte(agp_bridge->dev, INTEL_I820_RDCR,
974 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE,
975 previous_size->size_value);
979 static int intel_820_configure(void)
983 struct aper_size_info_8 *current_size;
985 current_size = A_SIZE_8(agp_bridge->current_size);
988 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
990 /* address to map to */
991 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
992 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
994 /* attbase - aperture base */
995 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
998 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1000 /* global enable aperture access */
1001 /* This flag is not accessed through MCHCFG register as in */
1003 pci_read_config_byte(agp_bridge->dev, INTEL_I820_RDCR, &temp2);
1004 pci_write_config_byte(agp_bridge->dev, INTEL_I820_RDCR, temp2 | (1 << 1));
1005 /* clear any possible AGP-related error conditions */
1006 pci_write_config_word(agp_bridge->dev, INTEL_I820_ERRSTS, 0x001c);
1010 static int intel_840_configure(void)
1014 struct aper_size_info_8 *current_size;
1016 current_size = A_SIZE_8(agp_bridge->current_size);
1019 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1021 /* address to map to */
1022 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1023 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1025 /* attbase - aperture base */
1026 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1029 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1032 pci_read_config_word(agp_bridge->dev, INTEL_I840_MCHCFG, &temp2);
1033 pci_write_config_word(agp_bridge->dev, INTEL_I840_MCHCFG, temp2 | (1 << 9));
1034 /* clear any possible error conditions */
1035 pci_write_config_word(agp_bridge->dev, INTEL_I840_ERRSTS, 0xc000);
1039 static int intel_845_configure(void)
1043 struct aper_size_info_8 *current_size;
1045 current_size = A_SIZE_8(agp_bridge->current_size);
1048 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1050 /* address to map to */
1051 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1052 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1054 /* attbase - aperture base */
1055 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1058 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1061 pci_read_config_byte(agp_bridge->dev, INTEL_I845_AGPM, &temp2);
1062 pci_write_config_byte(agp_bridge->dev, INTEL_I845_AGPM, temp2 | (1 << 1));
1063 /* clear any possible error conditions */
1064 pci_write_config_word(agp_bridge->dev, INTEL_I845_ERRSTS, 0x001c);
1068 static int intel_850_configure(void)
1072 struct aper_size_info_8 *current_size;
1074 current_size = A_SIZE_8(agp_bridge->current_size);
1077 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1079 /* address to map to */
1080 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1081 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1083 /* attbase - aperture base */
1084 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1087 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1090 pci_read_config_word(agp_bridge->dev, INTEL_I850_MCHCFG, &temp2);
1091 pci_write_config_word(agp_bridge->dev, INTEL_I850_MCHCFG, temp2 | (1 << 9));
1092 /* clear any possible AGP-related error conditions */
1093 pci_write_config_word(agp_bridge->dev, INTEL_I850_ERRSTS, 0x001c);
1097 static int intel_860_configure(void)
1101 struct aper_size_info_8 *current_size;
1103 current_size = A_SIZE_8(agp_bridge->current_size);
1106 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1108 /* address to map to */
1109 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1110 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1112 /* attbase - aperture base */
1113 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1116 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1119 pci_read_config_word(agp_bridge->dev, INTEL_I860_MCHCFG, &temp2);
1120 pci_write_config_word(agp_bridge->dev, INTEL_I860_MCHCFG, temp2 | (1 << 9));
1121 /* clear any possible AGP-related error conditions */
1122 pci_write_config_word(agp_bridge->dev, INTEL_I860_ERRSTS, 0xf700);
1126 static int intel_830mp_configure(void)
1130 struct aper_size_info_8 *current_size;
1132 current_size = A_SIZE_8(agp_bridge->current_size);
1135 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1137 /* address to map to */
1138 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1139 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1141 /* attbase - aperture base */
1142 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1145 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1148 pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp2);
1149 pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG, temp2 | (1 << 9));
1150 /* clear any possible AGP-related error conditions */
1151 pci_write_config_word(agp_bridge->dev, INTEL_I830_ERRSTS, 0x1c);
1155 static int intel_7505_configure(void)
1159 struct aper_size_info_8 *current_size;
1161 current_size = A_SIZE_8(agp_bridge->current_size);
1164 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1166 /* address to map to */
1167 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1168 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1170 /* attbase - aperture base */
1171 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
1174 pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
1177 pci_read_config_word(agp_bridge->dev, INTEL_I7505_MCHCFG, &temp2);
1178 pci_write_config_word(agp_bridge->dev, INTEL_I7505_MCHCFG, temp2 | (1 << 9));
1183 /* Setup function */
1184 static struct gatt_mask intel_generic_masks[] =
1186 {.mask = 0x00000017, .type = 0}
1189 static struct aper_size_info_8 intel_815_sizes[2] =
1195 static struct aper_size_info_8 intel_8xx_sizes[7] =
1198 {128, 32768, 5, 32},
1206 static struct aper_size_info_16 intel_generic_sizes[7] =
1209 {128, 32768, 5, 32},
1217 static struct aper_size_info_8 intel_830mp_sizes[4] =
1220 {128, 32768, 5, 32},
1225 static struct agp_bridge_driver intel_generic_driver = {
1226 .owner = THIS_MODULE,
1227 .aperture_sizes = intel_generic_sizes,
1228 .size_type = U16_APER_SIZE,
1229 .num_aperture_sizes = 7,
1230 .configure = intel_configure,
1231 .fetch_size = intel_fetch_size,
1232 .cleanup = intel_cleanup,
1233 .tlb_flush = intel_tlbflush,
1234 .mask_memory = agp_generic_mask_memory,
1235 .masks = intel_generic_masks,
1236 .agp_enable = agp_generic_enable,
1237 .cache_flush = global_cache_flush,
1238 .create_gatt_table = agp_generic_create_gatt_table,
1239 .free_gatt_table = agp_generic_free_gatt_table,
1240 .insert_memory = agp_generic_insert_memory,
1241 .remove_memory = agp_generic_remove_memory,
1242 .alloc_by_type = agp_generic_alloc_by_type,
1243 .free_by_type = agp_generic_free_by_type,
1244 .agp_alloc_page = agp_generic_alloc_page,
1245 .agp_destroy_page = agp_generic_destroy_page,
1248 static struct agp_bridge_driver intel_810_driver = {
1249 .owner = THIS_MODULE,
1250 .aperture_sizes = intel_i810_sizes,
1251 .size_type = FIXED_APER_SIZE,
1252 .num_aperture_sizes = 2,
1253 .needs_scratch_page = TRUE,
1254 .configure = intel_i810_configure,
1255 .fetch_size = intel_i810_fetch_size,
1256 .cleanup = intel_i810_cleanup,
1257 .tlb_flush = intel_i810_tlbflush,
1258 .mask_memory = intel_i810_mask_memory,
1259 .masks = intel_i810_masks,
1260 .agp_enable = intel_i810_agp_enable,
1261 .cache_flush = global_cache_flush,
1262 .create_gatt_table = agp_generic_create_gatt_table,
1263 .free_gatt_table = agp_generic_free_gatt_table,
1264 .insert_memory = intel_i810_insert_entries,
1265 .remove_memory = intel_i810_remove_entries,
1266 .alloc_by_type = intel_i810_alloc_by_type,
1267 .free_by_type = intel_i810_free_by_type,
1268 .agp_alloc_page = agp_generic_alloc_page,
1269 .agp_destroy_page = agp_generic_destroy_page,
1272 static struct agp_bridge_driver intel_815_driver = {
1273 .owner = THIS_MODULE,
1274 .aperture_sizes = intel_815_sizes,
1275 .size_type = U8_APER_SIZE,
1276 .num_aperture_sizes = 2,
1277 .configure = intel_815_configure,
1278 .fetch_size = intel_815_fetch_size,
1279 .cleanup = intel_8xx_cleanup,
1280 .tlb_flush = intel_8xx_tlbflush,
1281 .mask_memory = agp_generic_mask_memory,
1282 .masks = intel_generic_masks,
1283 .agp_enable = agp_generic_enable,
1284 .cache_flush = global_cache_flush,
1285 .create_gatt_table = agp_generic_create_gatt_table,
1286 .free_gatt_table = agp_generic_free_gatt_table,
1287 .insert_memory = agp_generic_insert_memory,
1288 .remove_memory = agp_generic_remove_memory,
1289 .alloc_by_type = agp_generic_alloc_by_type,
1290 .free_by_type = agp_generic_free_by_type,
1291 .agp_alloc_page = agp_generic_alloc_page,
1292 .agp_destroy_page = agp_generic_destroy_page,
1295 static struct agp_bridge_driver intel_830_driver = {
1296 .owner = THIS_MODULE,
1297 .aperture_sizes = intel_i830_sizes,
1298 .size_type = FIXED_APER_SIZE,
1299 .num_aperture_sizes = 3,
1300 .needs_scratch_page = TRUE,
1301 .configure = intel_i830_configure,
1302 .fetch_size = intel_i830_fetch_size,
1303 .cleanup = intel_i830_cleanup,
1304 .tlb_flush = intel_i810_tlbflush,
1305 .mask_memory = intel_i810_mask_memory,
1306 .masks = intel_i810_masks,
1307 .agp_enable = intel_i810_agp_enable,
1308 .cache_flush = global_cache_flush,
1309 .create_gatt_table = intel_i830_create_gatt_table,
1310 .free_gatt_table = intel_i830_free_gatt_table,
1311 .insert_memory = intel_i830_insert_entries,
1312 .remove_memory = intel_i830_remove_entries,
1313 .alloc_by_type = intel_i830_alloc_by_type,
1314 .free_by_type = intel_i810_free_by_type,
1315 .agp_alloc_page = agp_generic_alloc_page,
1316 .agp_destroy_page = agp_generic_destroy_page,
1319 static struct agp_bridge_driver intel_820_driver = {
1320 .owner = THIS_MODULE,
1321 .aperture_sizes = intel_8xx_sizes,
1322 .size_type = U8_APER_SIZE,
1323 .num_aperture_sizes = 7,
1324 .configure = intel_820_configure,
1325 .fetch_size = intel_8xx_fetch_size,
1326 .cleanup = intel_820_cleanup,
1327 .tlb_flush = intel_820_tlbflush,
1328 .mask_memory = agp_generic_mask_memory,
1329 .masks = intel_generic_masks,
1330 .agp_enable = agp_generic_enable,
1331 .cache_flush = global_cache_flush,
1332 .create_gatt_table = agp_generic_create_gatt_table,
1333 .free_gatt_table = agp_generic_free_gatt_table,
1334 .insert_memory = agp_generic_insert_memory,
1335 .remove_memory = agp_generic_remove_memory,
1336 .alloc_by_type = agp_generic_alloc_by_type,
1337 .free_by_type = agp_generic_free_by_type,
1338 .agp_alloc_page = agp_generic_alloc_page,
1339 .agp_destroy_page = agp_generic_destroy_page,
1342 static struct agp_bridge_driver intel_830mp_driver = {
1343 .owner = THIS_MODULE,
1344 .aperture_sizes = intel_830mp_sizes,
1345 .size_type = U8_APER_SIZE,
1346 .num_aperture_sizes = 4,
1347 .configure = intel_830mp_configure,
1348 .fetch_size = intel_8xx_fetch_size,
1349 .cleanup = intel_8xx_cleanup,
1350 .tlb_flush = intel_8xx_tlbflush,
1351 .mask_memory = agp_generic_mask_memory,
1352 .masks = intel_generic_masks,
1353 .agp_enable = agp_generic_enable,
1354 .cache_flush = global_cache_flush,
1355 .create_gatt_table = agp_generic_create_gatt_table,
1356 .free_gatt_table = agp_generic_free_gatt_table,
1357 .insert_memory = agp_generic_insert_memory,
1358 .remove_memory = agp_generic_remove_memory,
1359 .alloc_by_type = agp_generic_alloc_by_type,
1360 .free_by_type = agp_generic_free_by_type,
1361 .agp_alloc_page = agp_generic_alloc_page,
1362 .agp_destroy_page = agp_generic_destroy_page,
1365 static struct agp_bridge_driver intel_840_driver = {
1366 .owner = THIS_MODULE,
1367 .aperture_sizes = intel_8xx_sizes,
1368 .size_type = U8_APER_SIZE,
1369 .num_aperture_sizes = 7,
1370 .configure = intel_840_configure,
1371 .fetch_size = intel_8xx_fetch_size,
1372 .cleanup = intel_8xx_cleanup,
1373 .tlb_flush = intel_8xx_tlbflush,
1374 .mask_memory = agp_generic_mask_memory,
1375 .masks = intel_generic_masks,
1376 .agp_enable = agp_generic_enable,
1377 .cache_flush = global_cache_flush,
1378 .create_gatt_table = agp_generic_create_gatt_table,
1379 .free_gatt_table = agp_generic_free_gatt_table,
1380 .insert_memory = agp_generic_insert_memory,
1381 .remove_memory = agp_generic_remove_memory,
1382 .alloc_by_type = agp_generic_alloc_by_type,
1383 .free_by_type = agp_generic_free_by_type,
1384 .agp_alloc_page = agp_generic_alloc_page,
1385 .agp_destroy_page = agp_generic_destroy_page,
1388 static struct agp_bridge_driver intel_845_driver = {
1389 .owner = THIS_MODULE,
1390 .aperture_sizes = intel_8xx_sizes,
1391 .size_type = U8_APER_SIZE,
1392 .num_aperture_sizes = 7,
1393 .configure = intel_845_configure,
1394 .fetch_size = intel_8xx_fetch_size,
1395 .cleanup = intel_8xx_cleanup,
1396 .tlb_flush = intel_8xx_tlbflush,
1397 .mask_memory = agp_generic_mask_memory,
1398 .masks = intel_generic_masks,
1399 .agp_enable = agp_generic_enable,
1400 .cache_flush = global_cache_flush,
1401 .create_gatt_table = agp_generic_create_gatt_table,
1402 .free_gatt_table = agp_generic_free_gatt_table,
1403 .insert_memory = agp_generic_insert_memory,
1404 .remove_memory = agp_generic_remove_memory,
1405 .alloc_by_type = agp_generic_alloc_by_type,
1406 .free_by_type = agp_generic_free_by_type,
1407 .agp_alloc_page = agp_generic_alloc_page,
1408 .agp_destroy_page = agp_generic_destroy_page,
1411 static struct agp_bridge_driver intel_850_driver = {
1412 .owner = THIS_MODULE,
1413 .aperture_sizes = intel_8xx_sizes,
1414 .size_type = U8_APER_SIZE,
1415 .num_aperture_sizes = 7,
1416 .configure = intel_850_configure,
1417 .fetch_size = intel_8xx_fetch_size,
1418 .cleanup = intel_8xx_cleanup,
1419 .tlb_flush = intel_8xx_tlbflush,
1420 .mask_memory = agp_generic_mask_memory,
1421 .masks = intel_generic_masks,
1422 .agp_enable = agp_generic_enable,
1423 .cache_flush = global_cache_flush,
1424 .create_gatt_table = agp_generic_create_gatt_table,
1425 .free_gatt_table = agp_generic_free_gatt_table,
1426 .insert_memory = agp_generic_insert_memory,
1427 .remove_memory = agp_generic_remove_memory,
1428 .alloc_by_type = agp_generic_alloc_by_type,
1429 .free_by_type = agp_generic_free_by_type,
1430 .agp_alloc_page = agp_generic_alloc_page,
1431 .agp_destroy_page = agp_generic_destroy_page,
1434 static struct agp_bridge_driver intel_860_driver = {
1435 .owner = THIS_MODULE,
1436 .aperture_sizes = intel_8xx_sizes,
1437 .size_type = U8_APER_SIZE,
1438 .num_aperture_sizes = 7,
1439 .configure = intel_860_configure,
1440 .fetch_size = intel_8xx_fetch_size,
1441 .cleanup = intel_8xx_cleanup,
1442 .tlb_flush = intel_8xx_tlbflush,
1443 .mask_memory = agp_generic_mask_memory,
1444 .masks = intel_generic_masks,
1445 .agp_enable = agp_generic_enable,
1446 .cache_flush = global_cache_flush,
1447 .create_gatt_table = agp_generic_create_gatt_table,
1448 .free_gatt_table = agp_generic_free_gatt_table,
1449 .insert_memory = agp_generic_insert_memory,
1450 .remove_memory = agp_generic_remove_memory,
1451 .alloc_by_type = agp_generic_alloc_by_type,
1452 .free_by_type = agp_generic_free_by_type,
1453 .agp_alloc_page = agp_generic_alloc_page,
1454 .agp_destroy_page = agp_generic_destroy_page,
1457 static struct agp_bridge_driver intel_915_driver = {
1458 .owner = THIS_MODULE,
1459 .aperture_sizes = intel_i830_sizes,
1460 .size_type = FIXED_APER_SIZE,
1461 .num_aperture_sizes = 3,
1462 .needs_scratch_page = TRUE,
1463 .configure = intel_i915_configure,
1464 .fetch_size = intel_i915_fetch_size,
1465 .cleanup = intel_i915_cleanup,
1466 .tlb_flush = intel_i810_tlbflush,
1467 .mask_memory = intel_i810_mask_memory,
1468 .masks = intel_i810_masks,
1469 .agp_enable = intel_i810_agp_enable,
1470 .cache_flush = global_cache_flush,
1471 .create_gatt_table = intel_i915_create_gatt_table,
1472 .free_gatt_table = intel_i830_free_gatt_table,
1473 .insert_memory = intel_i915_insert_entries,
1474 .remove_memory = intel_i915_remove_entries,
1475 .alloc_by_type = intel_i830_alloc_by_type,
1476 .free_by_type = intel_i810_free_by_type,
1477 .agp_alloc_page = agp_generic_alloc_page,
1478 .agp_destroy_page = agp_generic_destroy_page,
1482 static struct agp_bridge_driver intel_7505_driver = {
1483 .owner = THIS_MODULE,
1484 .aperture_sizes = intel_8xx_sizes,
1485 .size_type = U8_APER_SIZE,
1486 .num_aperture_sizes = 7,
1487 .configure = intel_7505_configure,
1488 .fetch_size = intel_8xx_fetch_size,
1489 .cleanup = intel_8xx_cleanup,
1490 .tlb_flush = intel_8xx_tlbflush,
1491 .mask_memory = agp_generic_mask_memory,
1492 .masks = intel_generic_masks,
1493 .agp_enable = agp_generic_enable,
1494 .cache_flush = global_cache_flush,
1495 .create_gatt_table = agp_generic_create_gatt_table,
1496 .free_gatt_table = agp_generic_free_gatt_table,
1497 .insert_memory = agp_generic_insert_memory,
1498 .remove_memory = agp_generic_remove_memory,
1499 .alloc_by_type = agp_generic_alloc_by_type,
1500 .free_by_type = agp_generic_free_by_type,
1501 .agp_alloc_page = agp_generic_alloc_page,
1502 .agp_destroy_page = agp_generic_destroy_page,
1505 static int find_i810(u16 device)
1507 struct pci_dev *i810_dev;
1509 i810_dev = pci_get_device(PCI_VENDOR_ID_INTEL, device, NULL);
1512 intel_i810_private.i810_dev = i810_dev;
1516 static int find_i830(u16 device)
1518 struct pci_dev *i830_dev;
1520 i830_dev = pci_get_device(PCI_VENDOR_ID_INTEL, device, NULL);
1521 if (i830_dev && PCI_FUNC(i830_dev->devfn) != 0) {
1522 i830_dev = pci_get_device(PCI_VENDOR_ID_INTEL,
1529 intel_i830_private.i830_dev = i830_dev;
1533 static int __devinit agp_intel_probe(struct pci_dev *pdev,
1534 const struct pci_device_id *ent)
1536 struct agp_bridge_data *bridge;
1537 char *name = "(unknown)";
1541 cap_ptr = pci_find_capability(pdev, PCI_CAP_ID_AGP);
1543 bridge = agp_alloc_bridge();
1547 switch (pdev->device) {
1548 case PCI_DEVICE_ID_INTEL_82443LX_0:
1549 bridge->driver = &intel_generic_driver;
1552 case PCI_DEVICE_ID_INTEL_82443BX_0:
1553 bridge->driver = &intel_generic_driver;
1556 case PCI_DEVICE_ID_INTEL_82443GX_0:
1557 bridge->driver = &intel_generic_driver;
1560 case PCI_DEVICE_ID_INTEL_82810_MC1:
1562 if (!find_i810(PCI_DEVICE_ID_INTEL_82810_IG1))
1564 bridge->driver = &intel_810_driver;
1566 case PCI_DEVICE_ID_INTEL_82810_MC3:
1567 name = "i810 DC100";
1568 if (!find_i810(PCI_DEVICE_ID_INTEL_82810_IG3))
1570 bridge->driver = &intel_810_driver;
1572 case PCI_DEVICE_ID_INTEL_82810E_MC:
1574 if (!find_i810(PCI_DEVICE_ID_INTEL_82810E_IG))
1576 bridge->driver = &intel_810_driver;
1578 case PCI_DEVICE_ID_INTEL_82815_MC:
1580 * The i815 can operate either as an i810 style
1581 * integrated device, or as an AGP4X motherboard.
1583 if (find_i810(PCI_DEVICE_ID_INTEL_82815_CGC))
1584 bridge->driver = &intel_810_driver;
1586 bridge->driver = &intel_815_driver;
1589 case PCI_DEVICE_ID_INTEL_82820_HB:
1590 case PCI_DEVICE_ID_INTEL_82820_UP_HB:
1591 bridge->driver = &intel_820_driver;
1594 case PCI_DEVICE_ID_INTEL_82830_HB:
1595 if (find_i830(PCI_DEVICE_ID_INTEL_82830_CGC)) {
1596 bridge->driver = &intel_830_driver;
1598 bridge->driver = &intel_830mp_driver;
1602 case PCI_DEVICE_ID_INTEL_82840_HB:
1603 bridge->driver = &intel_840_driver;
1606 case PCI_DEVICE_ID_INTEL_82845_HB:
1607 bridge->driver = &intel_845_driver;
1610 case PCI_DEVICE_ID_INTEL_82845G_HB:
1611 if (find_i830(PCI_DEVICE_ID_INTEL_82845G_IG)) {
1612 bridge->driver = &intel_830_driver;
1614 bridge->driver = &intel_845_driver;
1618 case PCI_DEVICE_ID_INTEL_82850_HB:
1619 bridge->driver = &intel_850_driver;
1622 case PCI_DEVICE_ID_INTEL_82855PM_HB:
1623 bridge->driver = &intel_845_driver;
1626 case PCI_DEVICE_ID_INTEL_82855GM_HB:
1627 if (find_i830(PCI_DEVICE_ID_INTEL_82855GM_IG)) {
1628 bridge->driver = &intel_830_driver;
1631 bridge->driver = &intel_845_driver;
1635 case PCI_DEVICE_ID_INTEL_82860_HB:
1636 bridge->driver = &intel_860_driver;
1639 case PCI_DEVICE_ID_INTEL_82865_HB:
1640 if (find_i830(PCI_DEVICE_ID_INTEL_82865_IG)) {
1641 bridge->driver = &intel_830_driver;
1643 bridge->driver = &intel_845_driver;
1647 case PCI_DEVICE_ID_INTEL_82875_HB:
1648 bridge->driver = &intel_845_driver;
1651 case PCI_DEVICE_ID_INTEL_82915G_HB:
1652 if (find_i830(PCI_DEVICE_ID_INTEL_82915G_IG)) {
1653 bridge->driver = &intel_915_driver;
1655 bridge->driver = &intel_845_driver;
1659 case PCI_DEVICE_ID_INTEL_82915GM_HB:
1660 if (find_i830(PCI_DEVICE_ID_INTEL_82915GM_IG)) {
1661 bridge->driver = &intel_915_driver;
1663 bridge->driver = &intel_845_driver;
1667 case PCI_DEVICE_ID_INTEL_82945G_HB:
1668 if (find_i830(PCI_DEVICE_ID_INTEL_82945G_IG)) {
1669 bridge->driver = &intel_915_driver;
1671 bridge->driver = &intel_845_driver;
1675 case PCI_DEVICE_ID_INTEL_7505_0:
1676 bridge->driver = &intel_7505_driver;
1679 case PCI_DEVICE_ID_INTEL_7205_0:
1680 bridge->driver = &intel_7505_driver;
1685 printk(KERN_WARNING PFX "Unsupported Intel chipset (device id: %04x)\n",
1687 agp_put_bridge(bridge);
1692 bridge->capndx = cap_ptr;
1694 if (bridge->driver == &intel_810_driver)
1695 bridge->dev_private_data = &intel_i810_private;
1696 else if (bridge->driver == &intel_830_driver)
1697 bridge->dev_private_data = &intel_i830_private;
1699 printk(KERN_INFO PFX "Detected an Intel %s Chipset.\n", name);
1702 * The following fixes the case where the BIOS has "forgotten" to
1703 * provide an address range for the GART.
1704 * 20030610 - hamish@zot.org
1706 r = &pdev->resource[0];
1707 if (!r->start && r->end) {
1708 if(pci_assign_resource(pdev, 0)) {
1709 printk(KERN_ERR PFX "could not assign resource 0\n");
1710 agp_put_bridge(bridge);
1716 * If the device has not been properly setup, the following will catch
1717 * the problem and should stop the system from crashing.
1718 * 20030610 - hamish@zot.org
1720 if (pci_enable_device(pdev)) {
1721 printk(KERN_ERR PFX "Unable to Enable PCI device\n");
1722 agp_put_bridge(bridge);
1726 /* Fill in the mode register */
1728 pci_read_config_dword(pdev,
1729 bridge->capndx+PCI_AGP_STATUS,
1733 pci_set_drvdata(pdev, bridge);
1734 return agp_add_bridge(bridge);
1737 printk(KERN_ERR PFX "Detected an Intel %s chipset, "
1738 "but could not find the secondary device.\n", name);
1739 agp_put_bridge(bridge);
1743 static void __devexit agp_intel_remove(struct pci_dev *pdev)
1745 struct agp_bridge_data *bridge = pci_get_drvdata(pdev);
1747 agp_remove_bridge(bridge);
1749 if (intel_i810_private.i810_dev)
1750 pci_dev_put(intel_i810_private.i810_dev);
1751 if (intel_i830_private.i830_dev)
1752 pci_dev_put(intel_i830_private.i830_dev);
1754 agp_put_bridge(bridge);
1757 static int agp_intel_resume(struct pci_dev *pdev)
1759 struct agp_bridge_data *bridge = pci_get_drvdata(pdev);
1761 pci_restore_state(pdev);
1763 if (bridge->driver == &intel_generic_driver)
1765 else if (bridge->driver == &intel_850_driver)
1766 intel_850_configure();
1767 else if (bridge->driver == &intel_845_driver)
1768 intel_845_configure();
1769 else if (bridge->driver == &intel_830mp_driver)
1770 intel_830mp_configure();
1771 else if (bridge->driver == &intel_915_driver)
1772 intel_i915_configure();
1773 else if (bridge->driver == &intel_830_driver)
1774 intel_i830_configure();
1775 else if (bridge->driver == &intel_810_driver)
1776 intel_i810_configure();
1781 static struct pci_device_id agp_intel_pci_table[] = {
1784 .class = (PCI_CLASS_BRIDGE_HOST << 8), \
1786 .vendor = PCI_VENDOR_ID_INTEL, \
1788 .subvendor = PCI_ANY_ID, \
1789 .subdevice = PCI_ANY_ID, \
1791 ID(PCI_DEVICE_ID_INTEL_82443LX_0),
1792 ID(PCI_DEVICE_ID_INTEL_82443BX_0),
1793 ID(PCI_DEVICE_ID_INTEL_82443GX_0),
1794 ID(PCI_DEVICE_ID_INTEL_82810_MC1),
1795 ID(PCI_DEVICE_ID_INTEL_82810_MC3),
1796 ID(PCI_DEVICE_ID_INTEL_82810E_MC),
1797 ID(PCI_DEVICE_ID_INTEL_82815_MC),
1798 ID(PCI_DEVICE_ID_INTEL_82820_HB),
1799 ID(PCI_DEVICE_ID_INTEL_82820_UP_HB),
1800 ID(PCI_DEVICE_ID_INTEL_82830_HB),
1801 ID(PCI_DEVICE_ID_INTEL_82840_HB),
1802 ID(PCI_DEVICE_ID_INTEL_82845_HB),
1803 ID(PCI_DEVICE_ID_INTEL_82845G_HB),
1804 ID(PCI_DEVICE_ID_INTEL_82850_HB),
1805 ID(PCI_DEVICE_ID_INTEL_82855PM_HB),
1806 ID(PCI_DEVICE_ID_INTEL_82855GM_HB),
1807 ID(PCI_DEVICE_ID_INTEL_82860_HB),
1808 ID(PCI_DEVICE_ID_INTEL_82865_HB),
1809 ID(PCI_DEVICE_ID_INTEL_82875_HB),
1810 ID(PCI_DEVICE_ID_INTEL_7505_0),
1811 ID(PCI_DEVICE_ID_INTEL_7205_0),
1812 ID(PCI_DEVICE_ID_INTEL_82915G_HB),
1813 ID(PCI_DEVICE_ID_INTEL_82915GM_HB),
1814 ID(PCI_DEVICE_ID_INTEL_82945G_HB),
1818 MODULE_DEVICE_TABLE(pci, agp_intel_pci_table);
1820 static struct pci_driver agp_intel_pci_driver = {
1821 .name = "agpgart-intel",
1822 .id_table = agp_intel_pci_table,
1823 .probe = agp_intel_probe,
1824 .remove = __devexit_p(agp_intel_remove),
1825 .resume = agp_intel_resume,
1828 static int __init agp_intel_init(void)
1832 return pci_register_driver(&agp_intel_pci_driver);
1835 static void __exit agp_intel_cleanup(void)
1837 pci_unregister_driver(&agp_intel_pci_driver);
1840 module_init(agp_intel_init);
1841 module_exit(agp_intel_cleanup);
1843 MODULE_AUTHOR("Dave Jones <davej@codemonkey.org.uk>");
1844 MODULE_LICENSE("GPL and additional rights");