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_phys(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(phys_to_virt(curr
->memory
[0]));
334 agp_bridge
->driver
->agp_destroy_page(
335 phys_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 gtt_entries
= MB(48) - KB(size
);
426 case I915_GMCH_GMS_STOLEN_64M
:
427 /* Check it's really I915G */
428 if (agp_bridge
->dev
->device
== PCI_DEVICE_ID_INTEL_82915G_HB
||
429 agp_bridge
->dev
->device
== PCI_DEVICE_ID_INTEL_82915GM_HB
)
430 gtt_entries
= MB(64) - KB(size
);
439 printk(KERN_INFO PFX
"Detected %dK %s memory.\n",
440 gtt_entries
/ KB(1), local
? "local" : "stolen");
443 "No pre-allocated video memory detected.\n");
444 gtt_entries
/= KB(4);
446 intel_i830_private
.gtt_entries
= gtt_entries
;
449 /* The intel i830 automatically initializes the agp aperture during POST.
450 * Use the memory already set aside for in the GTT.
452 static int intel_i830_create_gatt_table(struct agp_bridge_data
*bridge
)
455 struct aper_size_info_fixed
*size
;
459 size
= agp_bridge
->current_size
;
460 page_order
= size
->page_order
;
461 num_entries
= size
->num_entries
;
462 agp_bridge
->gatt_table_real
= NULL
;
464 pci_read_config_dword(intel_i830_private
.i830_dev
,I810_MMADDR
,&temp
);
467 intel_i830_private
.registers
= ioremap(temp
,128 * 4096);
468 if (!intel_i830_private
.registers
)
471 temp
= readl(intel_i830_private
.registers
+I810_PGETBL_CTL
) & 0xfffff000;
472 global_cache_flush(); /* FIXME: ?? */
474 /* we have to call this as early as possible after the MMIO base address is known */
475 intel_i830_init_gtt_entries();
477 agp_bridge
->gatt_table
= NULL
;
479 agp_bridge
->gatt_bus_addr
= temp
;
484 /* Return the gatt table to a sane state. Use the top of stolen
485 * memory for the GTT.
487 static int intel_i830_free_gatt_table(struct agp_bridge_data
*bridge
)
492 static int intel_i830_fetch_size(void)
495 struct aper_size_info_fixed
*values
;
497 values
= A_SIZE_FIX(agp_bridge
->driver
->aperture_sizes
);
499 if (agp_bridge
->dev
->device
!= PCI_DEVICE_ID_INTEL_82830_HB
&&
500 agp_bridge
->dev
->device
!= PCI_DEVICE_ID_INTEL_82845G_HB
) {
501 /* 855GM/852GM/865G has 128MB aperture size */
502 agp_bridge
->previous_size
= agp_bridge
->current_size
= (void *) values
;
503 agp_bridge
->aperture_size_idx
= 0;
504 return values
[0].size
;
507 pci_read_config_word(agp_bridge
->dev
,I830_GMCH_CTRL
,&gmch_ctrl
);
509 if ((gmch_ctrl
& I830_GMCH_MEM_MASK
) == I830_GMCH_MEM_128M
) {
510 agp_bridge
->previous_size
= agp_bridge
->current_size
= (void *) values
;
511 agp_bridge
->aperture_size_idx
= 0;
512 return values
[0].size
;
514 agp_bridge
->previous_size
= agp_bridge
->current_size
= (void *) (values
+ 1);
515 agp_bridge
->aperture_size_idx
= 1;
516 return values
[1].size
;
522 static int intel_i830_configure(void)
524 struct aper_size_info_fixed
*current_size
;
529 current_size
= A_SIZE_FIX(agp_bridge
->current_size
);
531 pci_read_config_dword(intel_i830_private
.i830_dev
,I810_GMADDR
,&temp
);
532 agp_bridge
->gart_bus_addr
= (temp
& PCI_BASE_ADDRESS_MEM_MASK
);
534 pci_read_config_word(agp_bridge
->dev
,I830_GMCH_CTRL
,&gmch_ctrl
);
535 gmch_ctrl
|= I830_GMCH_ENABLED
;
536 pci_write_config_word(agp_bridge
->dev
,I830_GMCH_CTRL
,gmch_ctrl
);
538 writel(agp_bridge
->gatt_bus_addr
|I810_PGETBL_ENABLED
, intel_i830_private
.registers
+I810_PGETBL_CTL
);
539 readl(intel_i830_private
.registers
+I810_PGETBL_CTL
); /* PCI Posting. */
541 if (agp_bridge
->driver
->needs_scratch_page
) {
542 for (i
= intel_i830_private
.gtt_entries
; i
< current_size
->num_entries
; i
++) {
543 writel(agp_bridge
->scratch_page
, intel_i830_private
.registers
+I810_PTE_BASE
+(i
*4));
544 readl(intel_i830_private
.registers
+I810_PTE_BASE
+(i
*4)); /* PCI Posting. */
548 global_cache_flush();
552 static void intel_i830_cleanup(void)
554 iounmap(intel_i830_private
.registers
);
557 static int intel_i830_insert_entries(struct agp_memory
*mem
,off_t pg_start
, int type
)
562 temp
= agp_bridge
->current_size
;
563 num_entries
= A_SIZE_FIX(temp
)->num_entries
;
565 if (pg_start
< intel_i830_private
.gtt_entries
) {
566 printk (KERN_DEBUG PFX
"pg_start == 0x%.8lx,intel_i830_private.gtt_entries == 0x%.8x\n",
567 pg_start
,intel_i830_private
.gtt_entries
);
569 printk (KERN_INFO PFX
"Trying to insert into local/stolen memory\n");
573 if ((pg_start
+ mem
->page_count
) > num_entries
)
576 /* The i830 can't check the GTT for entries since its read only,
577 * depend on the caller to make the correct offset decisions.
580 if ((type
!= 0 && type
!= AGP_PHYS_MEMORY
) ||
581 (mem
->type
!= 0 && mem
->type
!= AGP_PHYS_MEMORY
))
584 global_cache_flush(); /* FIXME: Necessary ?*/
586 for (i
= 0, j
= pg_start
; i
< mem
->page_count
; i
++, j
++) {
587 writel(agp_bridge
->driver
->mask_memory(agp_bridge
,
588 mem
->memory
[i
], mem
->type
),
589 intel_i830_private
.registers
+I810_PTE_BASE
+(j
*4));
590 readl(intel_i830_private
.registers
+I810_PTE_BASE
+(j
*4)); /* PCI Posting. */
593 global_cache_flush();
594 agp_bridge
->driver
->tlb_flush(mem
);
598 static int intel_i830_remove_entries(struct agp_memory
*mem
,off_t pg_start
,
603 global_cache_flush();
605 if (pg_start
< intel_i830_private
.gtt_entries
) {
606 printk (KERN_INFO PFX
"Trying to disable local/stolen memory\n");
610 for (i
= pg_start
; i
< (mem
->page_count
+ pg_start
); i
++) {
611 writel(agp_bridge
->scratch_page
, intel_i830_private
.registers
+I810_PTE_BASE
+(i
*4));
612 readl(intel_i830_private
.registers
+I810_PTE_BASE
+(i
*4)); /* PCI Posting. */
615 global_cache_flush();
616 agp_bridge
->driver
->tlb_flush(mem
);
620 static struct agp_memory
*intel_i830_alloc_by_type(size_t pg_count
,int type
)
622 if (type
== AGP_PHYS_MEMORY
)
623 return alloc_agpphysmem_i8xx(pg_count
, type
);
625 /* always return NULL for other allocation types for now */
629 static int intel_i915_configure(void)
631 struct aper_size_info_fixed
*current_size
;
636 current_size
= A_SIZE_FIX(agp_bridge
->current_size
);
638 pci_read_config_dword(intel_i830_private
.i830_dev
, I915_GMADDR
, &temp
);
640 agp_bridge
->gart_bus_addr
= (temp
& PCI_BASE_ADDRESS_MEM_MASK
);
642 pci_read_config_word(agp_bridge
->dev
,I830_GMCH_CTRL
,&gmch_ctrl
);
643 gmch_ctrl
|= I830_GMCH_ENABLED
;
644 pci_write_config_word(agp_bridge
->dev
,I830_GMCH_CTRL
,gmch_ctrl
);
646 writel(agp_bridge
->gatt_bus_addr
|I810_PGETBL_ENABLED
, intel_i830_private
.registers
+I810_PGETBL_CTL
);
647 readl(intel_i830_private
.registers
+I810_PGETBL_CTL
); /* PCI Posting. */
649 if (agp_bridge
->driver
->needs_scratch_page
) {
650 for (i
= intel_i830_private
.gtt_entries
; i
< current_size
->num_entries
; i
++) {
651 writel(agp_bridge
->scratch_page
, intel_i830_private
.gtt
+i
);
652 readl(intel_i830_private
.gtt
+i
); /* PCI Posting. */
656 global_cache_flush();
660 static void intel_i915_cleanup(void)
662 iounmap(intel_i830_private
.gtt
);
663 iounmap(intel_i830_private
.registers
);
666 static int intel_i915_insert_entries(struct agp_memory
*mem
,off_t pg_start
,
672 temp
= agp_bridge
->current_size
;
673 num_entries
= A_SIZE_FIX(temp
)->num_entries
;
675 if (pg_start
< intel_i830_private
.gtt_entries
) {
676 printk (KERN_DEBUG PFX
"pg_start == 0x%.8lx,intel_i830_private.gtt_entries == 0x%.8x\n",
677 pg_start
,intel_i830_private
.gtt_entries
);
679 printk (KERN_INFO PFX
"Trying to insert into local/stolen memory\n");
683 if ((pg_start
+ mem
->page_count
) > num_entries
)
686 /* The i830 can't check the GTT for entries since its read only,
687 * depend on the caller to make the correct offset decisions.
690 if ((type
!= 0 && type
!= AGP_PHYS_MEMORY
) ||
691 (mem
->type
!= 0 && mem
->type
!= AGP_PHYS_MEMORY
))
694 global_cache_flush();
696 for (i
= 0, j
= pg_start
; i
< mem
->page_count
; i
++, j
++) {
697 writel(agp_bridge
->driver
->mask_memory(agp_bridge
,
698 mem
->memory
[i
], mem
->type
), intel_i830_private
.gtt
+j
);
699 readl(intel_i830_private
.gtt
+j
); /* PCI Posting. */
702 global_cache_flush();
703 agp_bridge
->driver
->tlb_flush(mem
);
707 static int intel_i915_remove_entries(struct agp_memory
*mem
,off_t pg_start
,
712 global_cache_flush();
714 if (pg_start
< intel_i830_private
.gtt_entries
) {
715 printk (KERN_INFO PFX
"Trying to disable local/stolen memory\n");
719 for (i
= pg_start
; i
< (mem
->page_count
+ pg_start
); i
++) {
720 writel(agp_bridge
->scratch_page
, intel_i830_private
.gtt
+i
);
721 readl(intel_i830_private
.gtt
+i
);
724 global_cache_flush();
725 agp_bridge
->driver
->tlb_flush(mem
);
729 static int intel_i915_fetch_size(void)
731 struct aper_size_info_fixed
*values
;
732 u32 temp
, offset
= 0;
734 #define I915_256MB_ADDRESS_MASK (1<<27)
736 values
= A_SIZE_FIX(agp_bridge
->driver
->aperture_sizes
);
738 pci_read_config_dword(intel_i830_private
.i830_dev
, I915_GMADDR
, &temp
);
739 if (temp
& I915_256MB_ADDRESS_MASK
)
740 offset
= 0; /* 128MB aperture */
742 offset
= 2; /* 256MB aperture */
743 agp_bridge
->previous_size
= agp_bridge
->current_size
= (void *)(values
+ offset
);
744 return values
[offset
].size
;
747 /* The intel i915 automatically initializes the agp aperture during POST.
748 * Use the memory already set aside for in the GTT.
750 static int intel_i915_create_gatt_table(struct agp_bridge_data
*bridge
)
753 struct aper_size_info_fixed
*size
;
757 size
= agp_bridge
->current_size
;
758 page_order
= size
->page_order
;
759 num_entries
= size
->num_entries
;
760 agp_bridge
->gatt_table_real
= NULL
;
762 pci_read_config_dword(intel_i830_private
.i830_dev
, I915_MMADDR
, &temp
);
763 pci_read_config_dword(intel_i830_private
.i830_dev
, I915_PTEADDR
,&temp2
);
765 intel_i830_private
.gtt
= ioremap(temp2
, 256 * 1024);
766 if (!intel_i830_private
.gtt
)
771 intel_i830_private
.registers
= ioremap(temp
,128 * 4096);
772 if (!intel_i830_private
.registers
)
775 temp
= readl(intel_i830_private
.registers
+I810_PGETBL_CTL
) & 0xfffff000;
776 global_cache_flush(); /* FIXME: ? */
778 /* we have to call this as early as possible after the MMIO base address is known */
779 intel_i830_init_gtt_entries();
781 agp_bridge
->gatt_table
= NULL
;
783 agp_bridge
->gatt_bus_addr
= temp
;
788 static int intel_fetch_size(void)
792 struct aper_size_info_16
*values
;
794 pci_read_config_word(agp_bridge
->dev
, INTEL_APSIZE
, &temp
);
795 values
= A_SIZE_16(agp_bridge
->driver
->aperture_sizes
);
797 for (i
= 0; i
< agp_bridge
->driver
->num_aperture_sizes
; i
++) {
798 if (temp
== values
[i
].size_value
) {
799 agp_bridge
->previous_size
= agp_bridge
->current_size
= (void *) (values
+ i
);
800 agp_bridge
->aperture_size_idx
= i
;
801 return values
[i
].size
;
808 static int __intel_8xx_fetch_size(u8 temp
)
811 struct aper_size_info_8
*values
;
813 values
= A_SIZE_8(agp_bridge
->driver
->aperture_sizes
);
815 for (i
= 0; i
< agp_bridge
->driver
->num_aperture_sizes
; i
++) {
816 if (temp
== values
[i
].size_value
) {
817 agp_bridge
->previous_size
=
818 agp_bridge
->current_size
= (void *) (values
+ i
);
819 agp_bridge
->aperture_size_idx
= i
;
820 return values
[i
].size
;
826 static int intel_8xx_fetch_size(void)
830 pci_read_config_byte(agp_bridge
->dev
, INTEL_APSIZE
, &temp
);
831 return __intel_8xx_fetch_size(temp
);
834 static int intel_815_fetch_size(void)
838 /* Intel 815 chipsets have a _weird_ APSIZE register with only
839 * one non-reserved bit, so mask the others out ... */
840 pci_read_config_byte(agp_bridge
->dev
, INTEL_APSIZE
, &temp
);
843 return __intel_8xx_fetch_size(temp
);
846 static void intel_tlbflush(struct agp_memory
*mem
)
848 pci_write_config_dword(agp_bridge
->dev
, INTEL_AGPCTRL
, 0x2200);
849 pci_write_config_dword(agp_bridge
->dev
, INTEL_AGPCTRL
, 0x2280);
853 static void intel_8xx_tlbflush(struct agp_memory
*mem
)
856 pci_read_config_dword(agp_bridge
->dev
, INTEL_AGPCTRL
, &temp
);
857 pci_write_config_dword(agp_bridge
->dev
, INTEL_AGPCTRL
, temp
& ~(1 << 7));
858 pci_read_config_dword(agp_bridge
->dev
, INTEL_AGPCTRL
, &temp
);
859 pci_write_config_dword(agp_bridge
->dev
, INTEL_AGPCTRL
, temp
| (1 << 7));
863 static void intel_cleanup(void)
866 struct aper_size_info_16
*previous_size
;
868 previous_size
= A_SIZE_16(agp_bridge
->previous_size
);
869 pci_read_config_word(agp_bridge
->dev
, INTEL_NBXCFG
, &temp
);
870 pci_write_config_word(agp_bridge
->dev
, INTEL_NBXCFG
, temp
& ~(1 << 9));
871 pci_write_config_word(agp_bridge
->dev
, INTEL_APSIZE
, previous_size
->size_value
);
875 static void intel_8xx_cleanup(void)
878 struct aper_size_info_8
*previous_size
;
880 previous_size
= A_SIZE_8(agp_bridge
->previous_size
);
881 pci_read_config_word(agp_bridge
->dev
, INTEL_NBXCFG
, &temp
);
882 pci_write_config_word(agp_bridge
->dev
, INTEL_NBXCFG
, temp
& ~(1 << 9));
883 pci_write_config_byte(agp_bridge
->dev
, INTEL_APSIZE
, previous_size
->size_value
);
887 static int intel_configure(void)
891 struct aper_size_info_16
*current_size
;
893 current_size
= A_SIZE_16(agp_bridge
->current_size
);
896 pci_write_config_word(agp_bridge
->dev
, INTEL_APSIZE
, current_size
->size_value
);
898 /* address to map to */
899 pci_read_config_dword(agp_bridge
->dev
, AGP_APBASE
, &temp
);
900 agp_bridge
->gart_bus_addr
= (temp
& PCI_BASE_ADDRESS_MEM_MASK
);
902 /* attbase - aperture base */
903 pci_write_config_dword(agp_bridge
->dev
, INTEL_ATTBASE
, agp_bridge
->gatt_bus_addr
);
906 pci_write_config_dword(agp_bridge
->dev
, INTEL_AGPCTRL
, 0x2280);
909 pci_read_config_word(agp_bridge
->dev
, INTEL_NBXCFG
, &temp2
);
910 pci_write_config_word(agp_bridge
->dev
, INTEL_NBXCFG
,
911 (temp2
& ~(1 << 10)) | (1 << 9));
912 /* clear any possible error conditions */
913 pci_write_config_byte(agp_bridge
->dev
, INTEL_ERRSTS
+ 1, 7);
917 static int intel_815_configure(void)
921 struct aper_size_info_8
*current_size
;
923 /* attbase - aperture base */
924 /* the Intel 815 chipset spec. says that bits 29-31 in the
925 * ATTBASE register are reserved -> try not to write them */
926 if (agp_bridge
->gatt_bus_addr
& INTEL_815_ATTBASE_MASK
) {
927 printk (KERN_EMERG PFX
"gatt bus addr too high");
931 current_size
= A_SIZE_8(agp_bridge
->current_size
);
934 pci_write_config_byte(agp_bridge
->dev
, INTEL_APSIZE
,
935 current_size
->size_value
);
937 /* address to map to */
938 pci_read_config_dword(agp_bridge
->dev
, AGP_APBASE
, &temp
);
939 agp_bridge
->gart_bus_addr
= (temp
& PCI_BASE_ADDRESS_MEM_MASK
);
941 pci_read_config_dword(agp_bridge
->dev
, INTEL_ATTBASE
, &addr
);
942 addr
&= INTEL_815_ATTBASE_MASK
;
943 addr
|= agp_bridge
->gatt_bus_addr
;
944 pci_write_config_dword(agp_bridge
->dev
, INTEL_ATTBASE
, addr
);
947 pci_write_config_dword(agp_bridge
->dev
, INTEL_AGPCTRL
, 0x0000);
950 pci_read_config_byte(agp_bridge
->dev
, INTEL_815_APCONT
, &temp2
);
951 pci_write_config_byte(agp_bridge
->dev
, INTEL_815_APCONT
, temp2
| (1 << 1));
953 /* clear any possible error conditions */
954 /* Oddness : this chipset seems to have no ERRSTS register ! */
958 static void intel_820_tlbflush(struct agp_memory
*mem
)
963 static void intel_820_cleanup(void)
966 struct aper_size_info_8
*previous_size
;
968 previous_size
= A_SIZE_8(agp_bridge
->previous_size
);
969 pci_read_config_byte(agp_bridge
->dev
, INTEL_I820_RDCR
, &temp
);
970 pci_write_config_byte(agp_bridge
->dev
, INTEL_I820_RDCR
,
972 pci_write_config_byte(agp_bridge
->dev
, INTEL_APSIZE
,
973 previous_size
->size_value
);
977 static int intel_820_configure(void)
981 struct aper_size_info_8
*current_size
;
983 current_size
= A_SIZE_8(agp_bridge
->current_size
);
986 pci_write_config_byte(agp_bridge
->dev
, INTEL_APSIZE
, current_size
->size_value
);
988 /* address to map to */
989 pci_read_config_dword(agp_bridge
->dev
, AGP_APBASE
, &temp
);
990 agp_bridge
->gart_bus_addr
= (temp
& PCI_BASE_ADDRESS_MEM_MASK
);
992 /* attbase - aperture base */
993 pci_write_config_dword(agp_bridge
->dev
, INTEL_ATTBASE
, agp_bridge
->gatt_bus_addr
);
996 pci_write_config_dword(agp_bridge
->dev
, INTEL_AGPCTRL
, 0x0000);
998 /* global enable aperture access */
999 /* This flag is not accessed through MCHCFG register as in */
1001 pci_read_config_byte(agp_bridge
->dev
, INTEL_I820_RDCR
, &temp2
);
1002 pci_write_config_byte(agp_bridge
->dev
, INTEL_I820_RDCR
, temp2
| (1 << 1));
1003 /* clear any possible AGP-related error conditions */
1004 pci_write_config_word(agp_bridge
->dev
, INTEL_I820_ERRSTS
, 0x001c);
1008 static int intel_840_configure(void)
1012 struct aper_size_info_8
*current_size
;
1014 current_size
= A_SIZE_8(agp_bridge
->current_size
);
1017 pci_write_config_byte(agp_bridge
->dev
, INTEL_APSIZE
, current_size
->size_value
);
1019 /* address to map to */
1020 pci_read_config_dword(agp_bridge
->dev
, AGP_APBASE
, &temp
);
1021 agp_bridge
->gart_bus_addr
= (temp
& PCI_BASE_ADDRESS_MEM_MASK
);
1023 /* attbase - aperture base */
1024 pci_write_config_dword(agp_bridge
->dev
, INTEL_ATTBASE
, agp_bridge
->gatt_bus_addr
);
1027 pci_write_config_dword(agp_bridge
->dev
, INTEL_AGPCTRL
, 0x0000);
1030 pci_read_config_word(agp_bridge
->dev
, INTEL_I840_MCHCFG
, &temp2
);
1031 pci_write_config_word(agp_bridge
->dev
, INTEL_I840_MCHCFG
, temp2
| (1 << 9));
1032 /* clear any possible error conditions */
1033 pci_write_config_word(agp_bridge
->dev
, INTEL_I840_ERRSTS
, 0xc000);
1037 static int intel_845_configure(void)
1041 struct aper_size_info_8
*current_size
;
1043 current_size
= A_SIZE_8(agp_bridge
->current_size
);
1046 pci_write_config_byte(agp_bridge
->dev
, INTEL_APSIZE
, current_size
->size_value
);
1048 /* address to map to */
1049 pci_read_config_dword(agp_bridge
->dev
, AGP_APBASE
, &temp
);
1050 agp_bridge
->gart_bus_addr
= (temp
& PCI_BASE_ADDRESS_MEM_MASK
);
1052 /* attbase - aperture base */
1053 pci_write_config_dword(agp_bridge
->dev
, INTEL_ATTBASE
, agp_bridge
->gatt_bus_addr
);
1056 pci_write_config_dword(agp_bridge
->dev
, INTEL_AGPCTRL
, 0x0000);
1059 pci_read_config_byte(agp_bridge
->dev
, INTEL_I845_AGPM
, &temp2
);
1060 pci_write_config_byte(agp_bridge
->dev
, INTEL_I845_AGPM
, temp2
| (1 << 1));
1061 /* clear any possible error conditions */
1062 pci_write_config_word(agp_bridge
->dev
, INTEL_I845_ERRSTS
, 0x001c);
1066 static int intel_850_configure(void)
1070 struct aper_size_info_8
*current_size
;
1072 current_size
= A_SIZE_8(agp_bridge
->current_size
);
1075 pci_write_config_byte(agp_bridge
->dev
, INTEL_APSIZE
, current_size
->size_value
);
1077 /* address to map to */
1078 pci_read_config_dword(agp_bridge
->dev
, AGP_APBASE
, &temp
);
1079 agp_bridge
->gart_bus_addr
= (temp
& PCI_BASE_ADDRESS_MEM_MASK
);
1081 /* attbase - aperture base */
1082 pci_write_config_dword(agp_bridge
->dev
, INTEL_ATTBASE
, agp_bridge
->gatt_bus_addr
);
1085 pci_write_config_dword(agp_bridge
->dev
, INTEL_AGPCTRL
, 0x0000);
1088 pci_read_config_word(agp_bridge
->dev
, INTEL_I850_MCHCFG
, &temp2
);
1089 pci_write_config_word(agp_bridge
->dev
, INTEL_I850_MCHCFG
, temp2
| (1 << 9));
1090 /* clear any possible AGP-related error conditions */
1091 pci_write_config_word(agp_bridge
->dev
, INTEL_I850_ERRSTS
, 0x001c);
1095 static int intel_860_configure(void)
1099 struct aper_size_info_8
*current_size
;
1101 current_size
= A_SIZE_8(agp_bridge
->current_size
);
1104 pci_write_config_byte(agp_bridge
->dev
, INTEL_APSIZE
, current_size
->size_value
);
1106 /* address to map to */
1107 pci_read_config_dword(agp_bridge
->dev
, AGP_APBASE
, &temp
);
1108 agp_bridge
->gart_bus_addr
= (temp
& PCI_BASE_ADDRESS_MEM_MASK
);
1110 /* attbase - aperture base */
1111 pci_write_config_dword(agp_bridge
->dev
, INTEL_ATTBASE
, agp_bridge
->gatt_bus_addr
);
1114 pci_write_config_dword(agp_bridge
->dev
, INTEL_AGPCTRL
, 0x0000);
1117 pci_read_config_word(agp_bridge
->dev
, INTEL_I860_MCHCFG
, &temp2
);
1118 pci_write_config_word(agp_bridge
->dev
, INTEL_I860_MCHCFG
, temp2
| (1 << 9));
1119 /* clear any possible AGP-related error conditions */
1120 pci_write_config_word(agp_bridge
->dev
, INTEL_I860_ERRSTS
, 0xf700);
1124 static int intel_830mp_configure(void)
1128 struct aper_size_info_8
*current_size
;
1130 current_size
= A_SIZE_8(agp_bridge
->current_size
);
1133 pci_write_config_byte(agp_bridge
->dev
, INTEL_APSIZE
, current_size
->size_value
);
1135 /* address to map to */
1136 pci_read_config_dword(agp_bridge
->dev
, AGP_APBASE
, &temp
);
1137 agp_bridge
->gart_bus_addr
= (temp
& PCI_BASE_ADDRESS_MEM_MASK
);
1139 /* attbase - aperture base */
1140 pci_write_config_dword(agp_bridge
->dev
, INTEL_ATTBASE
, agp_bridge
->gatt_bus_addr
);
1143 pci_write_config_dword(agp_bridge
->dev
, INTEL_AGPCTRL
, 0x0000);
1146 pci_read_config_word(agp_bridge
->dev
, INTEL_NBXCFG
, &temp2
);
1147 pci_write_config_word(agp_bridge
->dev
, INTEL_NBXCFG
, temp2
| (1 << 9));
1148 /* clear any possible AGP-related error conditions */
1149 pci_write_config_word(agp_bridge
->dev
, INTEL_I830_ERRSTS
, 0x1c);
1153 static int intel_7505_configure(void)
1157 struct aper_size_info_8
*current_size
;
1159 current_size
= A_SIZE_8(agp_bridge
->current_size
);
1162 pci_write_config_byte(agp_bridge
->dev
, INTEL_APSIZE
, current_size
->size_value
);
1164 /* address to map to */
1165 pci_read_config_dword(agp_bridge
->dev
, AGP_APBASE
, &temp
);
1166 agp_bridge
->gart_bus_addr
= (temp
& PCI_BASE_ADDRESS_MEM_MASK
);
1168 /* attbase - aperture base */
1169 pci_write_config_dword(agp_bridge
->dev
, INTEL_ATTBASE
, agp_bridge
->gatt_bus_addr
);
1172 pci_write_config_dword(agp_bridge
->dev
, INTEL_AGPCTRL
, 0x0000);
1175 pci_read_config_word(agp_bridge
->dev
, INTEL_I7505_MCHCFG
, &temp2
);
1176 pci_write_config_word(agp_bridge
->dev
, INTEL_I7505_MCHCFG
, temp2
| (1 << 9));
1181 /* Setup function */
1182 static struct gatt_mask intel_generic_masks
[] =
1184 {.mask
= 0x00000017, .type
= 0}
1187 static struct aper_size_info_8 intel_815_sizes
[2] =
1193 static struct aper_size_info_8 intel_8xx_sizes
[7] =
1196 {128, 32768, 5, 32},
1204 static struct aper_size_info_16 intel_generic_sizes
[7] =
1207 {128, 32768, 5, 32},
1215 static struct aper_size_info_8 intel_830mp_sizes
[4] =
1218 {128, 32768, 5, 32},
1223 static struct agp_bridge_driver intel_generic_driver
= {
1224 .owner
= THIS_MODULE
,
1225 .aperture_sizes
= intel_generic_sizes
,
1226 .size_type
= U16_APER_SIZE
,
1227 .num_aperture_sizes
= 7,
1228 .configure
= intel_configure
,
1229 .fetch_size
= intel_fetch_size
,
1230 .cleanup
= intel_cleanup
,
1231 .tlb_flush
= intel_tlbflush
,
1232 .mask_memory
= agp_generic_mask_memory
,
1233 .masks
= intel_generic_masks
,
1234 .agp_enable
= agp_generic_enable
,
1235 .cache_flush
= global_cache_flush
,
1236 .create_gatt_table
= agp_generic_create_gatt_table
,
1237 .free_gatt_table
= agp_generic_free_gatt_table
,
1238 .insert_memory
= agp_generic_insert_memory
,
1239 .remove_memory
= agp_generic_remove_memory
,
1240 .alloc_by_type
= agp_generic_alloc_by_type
,
1241 .free_by_type
= agp_generic_free_by_type
,
1242 .agp_alloc_page
= agp_generic_alloc_page
,
1243 .agp_destroy_page
= agp_generic_destroy_page
,
1246 static struct agp_bridge_driver intel_810_driver
= {
1247 .owner
= THIS_MODULE
,
1248 .aperture_sizes
= intel_i810_sizes
,
1249 .size_type
= FIXED_APER_SIZE
,
1250 .num_aperture_sizes
= 2,
1251 .needs_scratch_page
= TRUE
,
1252 .configure
= intel_i810_configure
,
1253 .fetch_size
= intel_i810_fetch_size
,
1254 .cleanup
= intel_i810_cleanup
,
1255 .tlb_flush
= intel_i810_tlbflush
,
1256 .mask_memory
= intel_i810_mask_memory
,
1257 .masks
= intel_i810_masks
,
1258 .agp_enable
= intel_i810_agp_enable
,
1259 .cache_flush
= global_cache_flush
,
1260 .create_gatt_table
= agp_generic_create_gatt_table
,
1261 .free_gatt_table
= agp_generic_free_gatt_table
,
1262 .insert_memory
= intel_i810_insert_entries
,
1263 .remove_memory
= intel_i810_remove_entries
,
1264 .alloc_by_type
= intel_i810_alloc_by_type
,
1265 .free_by_type
= intel_i810_free_by_type
,
1266 .agp_alloc_page
= agp_generic_alloc_page
,
1267 .agp_destroy_page
= agp_generic_destroy_page
,
1270 static struct agp_bridge_driver intel_815_driver
= {
1271 .owner
= THIS_MODULE
,
1272 .aperture_sizes
= intel_815_sizes
,
1273 .size_type
= U8_APER_SIZE
,
1274 .num_aperture_sizes
= 2,
1275 .configure
= intel_815_configure
,
1276 .fetch_size
= intel_815_fetch_size
,
1277 .cleanup
= intel_8xx_cleanup
,
1278 .tlb_flush
= intel_8xx_tlbflush
,
1279 .mask_memory
= agp_generic_mask_memory
,
1280 .masks
= intel_generic_masks
,
1281 .agp_enable
= agp_generic_enable
,
1282 .cache_flush
= global_cache_flush
,
1283 .create_gatt_table
= agp_generic_create_gatt_table
,
1284 .free_gatt_table
= agp_generic_free_gatt_table
,
1285 .insert_memory
= agp_generic_insert_memory
,
1286 .remove_memory
= agp_generic_remove_memory
,
1287 .alloc_by_type
= agp_generic_alloc_by_type
,
1288 .free_by_type
= agp_generic_free_by_type
,
1289 .agp_alloc_page
= agp_generic_alloc_page
,
1290 .agp_destroy_page
= agp_generic_destroy_page
,
1293 static struct agp_bridge_driver intel_830_driver
= {
1294 .owner
= THIS_MODULE
,
1295 .aperture_sizes
= intel_i830_sizes
,
1296 .size_type
= FIXED_APER_SIZE
,
1297 .num_aperture_sizes
= 3,
1298 .needs_scratch_page
= TRUE
,
1299 .configure
= intel_i830_configure
,
1300 .fetch_size
= intel_i830_fetch_size
,
1301 .cleanup
= intel_i830_cleanup
,
1302 .tlb_flush
= intel_i810_tlbflush
,
1303 .mask_memory
= intel_i810_mask_memory
,
1304 .masks
= intel_i810_masks
,
1305 .agp_enable
= intel_i810_agp_enable
,
1306 .cache_flush
= global_cache_flush
,
1307 .create_gatt_table
= intel_i830_create_gatt_table
,
1308 .free_gatt_table
= intel_i830_free_gatt_table
,
1309 .insert_memory
= intel_i830_insert_entries
,
1310 .remove_memory
= intel_i830_remove_entries
,
1311 .alloc_by_type
= intel_i830_alloc_by_type
,
1312 .free_by_type
= intel_i810_free_by_type
,
1313 .agp_alloc_page
= agp_generic_alloc_page
,
1314 .agp_destroy_page
= agp_generic_destroy_page
,
1317 static struct agp_bridge_driver intel_820_driver
= {
1318 .owner
= THIS_MODULE
,
1319 .aperture_sizes
= intel_8xx_sizes
,
1320 .size_type
= U8_APER_SIZE
,
1321 .num_aperture_sizes
= 7,
1322 .configure
= intel_820_configure
,
1323 .fetch_size
= intel_8xx_fetch_size
,
1324 .cleanup
= intel_820_cleanup
,
1325 .tlb_flush
= intel_820_tlbflush
,
1326 .mask_memory
= agp_generic_mask_memory
,
1327 .masks
= intel_generic_masks
,
1328 .agp_enable
= agp_generic_enable
,
1329 .cache_flush
= global_cache_flush
,
1330 .create_gatt_table
= agp_generic_create_gatt_table
,
1331 .free_gatt_table
= agp_generic_free_gatt_table
,
1332 .insert_memory
= agp_generic_insert_memory
,
1333 .remove_memory
= agp_generic_remove_memory
,
1334 .alloc_by_type
= agp_generic_alloc_by_type
,
1335 .free_by_type
= agp_generic_free_by_type
,
1336 .agp_alloc_page
= agp_generic_alloc_page
,
1337 .agp_destroy_page
= agp_generic_destroy_page
,
1340 static struct agp_bridge_driver intel_830mp_driver
= {
1341 .owner
= THIS_MODULE
,
1342 .aperture_sizes
= intel_830mp_sizes
,
1343 .size_type
= U8_APER_SIZE
,
1344 .num_aperture_sizes
= 4,
1345 .configure
= intel_830mp_configure
,
1346 .fetch_size
= intel_8xx_fetch_size
,
1347 .cleanup
= intel_8xx_cleanup
,
1348 .tlb_flush
= intel_8xx_tlbflush
,
1349 .mask_memory
= agp_generic_mask_memory
,
1350 .masks
= intel_generic_masks
,
1351 .agp_enable
= agp_generic_enable
,
1352 .cache_flush
= global_cache_flush
,
1353 .create_gatt_table
= agp_generic_create_gatt_table
,
1354 .free_gatt_table
= agp_generic_free_gatt_table
,
1355 .insert_memory
= agp_generic_insert_memory
,
1356 .remove_memory
= agp_generic_remove_memory
,
1357 .alloc_by_type
= agp_generic_alloc_by_type
,
1358 .free_by_type
= agp_generic_free_by_type
,
1359 .agp_alloc_page
= agp_generic_alloc_page
,
1360 .agp_destroy_page
= agp_generic_destroy_page
,
1363 static struct agp_bridge_driver intel_840_driver
= {
1364 .owner
= THIS_MODULE
,
1365 .aperture_sizes
= intel_8xx_sizes
,
1366 .size_type
= U8_APER_SIZE
,
1367 .num_aperture_sizes
= 7,
1368 .configure
= intel_840_configure
,
1369 .fetch_size
= intel_8xx_fetch_size
,
1370 .cleanup
= intel_8xx_cleanup
,
1371 .tlb_flush
= intel_8xx_tlbflush
,
1372 .mask_memory
= agp_generic_mask_memory
,
1373 .masks
= intel_generic_masks
,
1374 .agp_enable
= agp_generic_enable
,
1375 .cache_flush
= global_cache_flush
,
1376 .create_gatt_table
= agp_generic_create_gatt_table
,
1377 .free_gatt_table
= agp_generic_free_gatt_table
,
1378 .insert_memory
= agp_generic_insert_memory
,
1379 .remove_memory
= agp_generic_remove_memory
,
1380 .alloc_by_type
= agp_generic_alloc_by_type
,
1381 .free_by_type
= agp_generic_free_by_type
,
1382 .agp_alloc_page
= agp_generic_alloc_page
,
1383 .agp_destroy_page
= agp_generic_destroy_page
,
1386 static struct agp_bridge_driver intel_845_driver
= {
1387 .owner
= THIS_MODULE
,
1388 .aperture_sizes
= intel_8xx_sizes
,
1389 .size_type
= U8_APER_SIZE
,
1390 .num_aperture_sizes
= 7,
1391 .configure
= intel_845_configure
,
1392 .fetch_size
= intel_8xx_fetch_size
,
1393 .cleanup
= intel_8xx_cleanup
,
1394 .tlb_flush
= intel_8xx_tlbflush
,
1395 .mask_memory
= agp_generic_mask_memory
,
1396 .masks
= intel_generic_masks
,
1397 .agp_enable
= agp_generic_enable
,
1398 .cache_flush
= global_cache_flush
,
1399 .create_gatt_table
= agp_generic_create_gatt_table
,
1400 .free_gatt_table
= agp_generic_free_gatt_table
,
1401 .insert_memory
= agp_generic_insert_memory
,
1402 .remove_memory
= agp_generic_remove_memory
,
1403 .alloc_by_type
= agp_generic_alloc_by_type
,
1404 .free_by_type
= agp_generic_free_by_type
,
1405 .agp_alloc_page
= agp_generic_alloc_page
,
1406 .agp_destroy_page
= agp_generic_destroy_page
,
1409 static struct agp_bridge_driver intel_850_driver
= {
1410 .owner
= THIS_MODULE
,
1411 .aperture_sizes
= intel_8xx_sizes
,
1412 .size_type
= U8_APER_SIZE
,
1413 .num_aperture_sizes
= 7,
1414 .configure
= intel_850_configure
,
1415 .fetch_size
= intel_8xx_fetch_size
,
1416 .cleanup
= intel_8xx_cleanup
,
1417 .tlb_flush
= intel_8xx_tlbflush
,
1418 .mask_memory
= agp_generic_mask_memory
,
1419 .masks
= intel_generic_masks
,
1420 .agp_enable
= agp_generic_enable
,
1421 .cache_flush
= global_cache_flush
,
1422 .create_gatt_table
= agp_generic_create_gatt_table
,
1423 .free_gatt_table
= agp_generic_free_gatt_table
,
1424 .insert_memory
= agp_generic_insert_memory
,
1425 .remove_memory
= agp_generic_remove_memory
,
1426 .alloc_by_type
= agp_generic_alloc_by_type
,
1427 .free_by_type
= agp_generic_free_by_type
,
1428 .agp_alloc_page
= agp_generic_alloc_page
,
1429 .agp_destroy_page
= agp_generic_destroy_page
,
1432 static struct agp_bridge_driver intel_860_driver
= {
1433 .owner
= THIS_MODULE
,
1434 .aperture_sizes
= intel_8xx_sizes
,
1435 .size_type
= U8_APER_SIZE
,
1436 .num_aperture_sizes
= 7,
1437 .configure
= intel_860_configure
,
1438 .fetch_size
= intel_8xx_fetch_size
,
1439 .cleanup
= intel_8xx_cleanup
,
1440 .tlb_flush
= intel_8xx_tlbflush
,
1441 .mask_memory
= agp_generic_mask_memory
,
1442 .masks
= intel_generic_masks
,
1443 .agp_enable
= agp_generic_enable
,
1444 .cache_flush
= global_cache_flush
,
1445 .create_gatt_table
= agp_generic_create_gatt_table
,
1446 .free_gatt_table
= agp_generic_free_gatt_table
,
1447 .insert_memory
= agp_generic_insert_memory
,
1448 .remove_memory
= agp_generic_remove_memory
,
1449 .alloc_by_type
= agp_generic_alloc_by_type
,
1450 .free_by_type
= agp_generic_free_by_type
,
1451 .agp_alloc_page
= agp_generic_alloc_page
,
1452 .agp_destroy_page
= agp_generic_destroy_page
,
1455 static struct agp_bridge_driver intel_915_driver
= {
1456 .owner
= THIS_MODULE
,
1457 .aperture_sizes
= intel_i830_sizes
,
1458 .size_type
= FIXED_APER_SIZE
,
1459 .num_aperture_sizes
= 3,
1460 .needs_scratch_page
= TRUE
,
1461 .configure
= intel_i915_configure
,
1462 .fetch_size
= intel_i915_fetch_size
,
1463 .cleanup
= intel_i915_cleanup
,
1464 .tlb_flush
= intel_i810_tlbflush
,
1465 .mask_memory
= intel_i810_mask_memory
,
1466 .masks
= intel_i810_masks
,
1467 .agp_enable
= intel_i810_agp_enable
,
1468 .cache_flush
= global_cache_flush
,
1469 .create_gatt_table
= intel_i915_create_gatt_table
,
1470 .free_gatt_table
= intel_i830_free_gatt_table
,
1471 .insert_memory
= intel_i915_insert_entries
,
1472 .remove_memory
= intel_i915_remove_entries
,
1473 .alloc_by_type
= intel_i830_alloc_by_type
,
1474 .free_by_type
= intel_i810_free_by_type
,
1475 .agp_alloc_page
= agp_generic_alloc_page
,
1476 .agp_destroy_page
= agp_generic_destroy_page
,
1480 static struct agp_bridge_driver intel_7505_driver
= {
1481 .owner
= THIS_MODULE
,
1482 .aperture_sizes
= intel_8xx_sizes
,
1483 .size_type
= U8_APER_SIZE
,
1484 .num_aperture_sizes
= 7,
1485 .configure
= intel_7505_configure
,
1486 .fetch_size
= intel_8xx_fetch_size
,
1487 .cleanup
= intel_8xx_cleanup
,
1488 .tlb_flush
= intel_8xx_tlbflush
,
1489 .mask_memory
= agp_generic_mask_memory
,
1490 .masks
= intel_generic_masks
,
1491 .agp_enable
= agp_generic_enable
,
1492 .cache_flush
= global_cache_flush
,
1493 .create_gatt_table
= agp_generic_create_gatt_table
,
1494 .free_gatt_table
= agp_generic_free_gatt_table
,
1495 .insert_memory
= agp_generic_insert_memory
,
1496 .remove_memory
= agp_generic_remove_memory
,
1497 .alloc_by_type
= agp_generic_alloc_by_type
,
1498 .free_by_type
= agp_generic_free_by_type
,
1499 .agp_alloc_page
= agp_generic_alloc_page
,
1500 .agp_destroy_page
= agp_generic_destroy_page
,
1503 static int find_i810(u16 device
)
1505 struct pci_dev
*i810_dev
;
1507 i810_dev
= pci_get_device(PCI_VENDOR_ID_INTEL
, device
, NULL
);
1510 intel_i810_private
.i810_dev
= i810_dev
;
1514 static int find_i830(u16 device
)
1516 struct pci_dev
*i830_dev
;
1518 i830_dev
= pci_get_device(PCI_VENDOR_ID_INTEL
, device
, NULL
);
1519 if (i830_dev
&& PCI_FUNC(i830_dev
->devfn
) != 0) {
1520 i830_dev
= pci_get_device(PCI_VENDOR_ID_INTEL
,
1527 intel_i830_private
.i830_dev
= i830_dev
;
1531 static int __devinit
agp_intel_probe(struct pci_dev
*pdev
,
1532 const struct pci_device_id
*ent
)
1534 struct agp_bridge_data
*bridge
;
1535 char *name
= "(unknown)";
1539 cap_ptr
= pci_find_capability(pdev
, PCI_CAP_ID_AGP
);
1541 bridge
= agp_alloc_bridge();
1545 switch (pdev
->device
) {
1546 case PCI_DEVICE_ID_INTEL_82443LX_0
:
1547 bridge
->driver
= &intel_generic_driver
;
1550 case PCI_DEVICE_ID_INTEL_82443BX_0
:
1551 bridge
->driver
= &intel_generic_driver
;
1554 case PCI_DEVICE_ID_INTEL_82443GX_0
:
1555 bridge
->driver
= &intel_generic_driver
;
1558 case PCI_DEVICE_ID_INTEL_82810_MC1
:
1560 if (!find_i810(PCI_DEVICE_ID_INTEL_82810_IG1
))
1562 bridge
->driver
= &intel_810_driver
;
1564 case PCI_DEVICE_ID_INTEL_82810_MC3
:
1565 name
= "i810 DC100";
1566 if (!find_i810(PCI_DEVICE_ID_INTEL_82810_IG3
))
1568 bridge
->driver
= &intel_810_driver
;
1570 case PCI_DEVICE_ID_INTEL_82810E_MC
:
1572 if (!find_i810(PCI_DEVICE_ID_INTEL_82810E_IG
))
1574 bridge
->driver
= &intel_810_driver
;
1576 case PCI_DEVICE_ID_INTEL_82815_MC
:
1578 * The i815 can operate either as an i810 style
1579 * integrated device, or as an AGP4X motherboard.
1581 if (find_i810(PCI_DEVICE_ID_INTEL_82815_CGC
))
1582 bridge
->driver
= &intel_810_driver
;
1584 bridge
->driver
= &intel_815_driver
;
1587 case PCI_DEVICE_ID_INTEL_82820_HB
:
1588 case PCI_DEVICE_ID_INTEL_82820_UP_HB
:
1589 bridge
->driver
= &intel_820_driver
;
1592 case PCI_DEVICE_ID_INTEL_82830_HB
:
1593 if (find_i830(PCI_DEVICE_ID_INTEL_82830_CGC
)) {
1594 bridge
->driver
= &intel_830_driver
;
1596 bridge
->driver
= &intel_830mp_driver
;
1600 case PCI_DEVICE_ID_INTEL_82840_HB
:
1601 bridge
->driver
= &intel_840_driver
;
1604 case PCI_DEVICE_ID_INTEL_82845_HB
:
1605 bridge
->driver
= &intel_845_driver
;
1608 case PCI_DEVICE_ID_INTEL_82845G_HB
:
1609 if (find_i830(PCI_DEVICE_ID_INTEL_82845G_IG
)) {
1610 bridge
->driver
= &intel_830_driver
;
1612 bridge
->driver
= &intel_845_driver
;
1616 case PCI_DEVICE_ID_INTEL_82850_HB
:
1617 bridge
->driver
= &intel_850_driver
;
1620 case PCI_DEVICE_ID_INTEL_82855PM_HB
:
1621 bridge
->driver
= &intel_845_driver
;
1624 case PCI_DEVICE_ID_INTEL_82855GM_HB
:
1625 if (find_i830(PCI_DEVICE_ID_INTEL_82855GM_IG
)) {
1626 bridge
->driver
= &intel_830_driver
;
1629 bridge
->driver
= &intel_845_driver
;
1633 case PCI_DEVICE_ID_INTEL_82860_HB
:
1634 bridge
->driver
= &intel_860_driver
;
1637 case PCI_DEVICE_ID_INTEL_82865_HB
:
1638 if (find_i830(PCI_DEVICE_ID_INTEL_82865_IG
)) {
1639 bridge
->driver
= &intel_830_driver
;
1641 bridge
->driver
= &intel_845_driver
;
1645 case PCI_DEVICE_ID_INTEL_82875_HB
:
1646 bridge
->driver
= &intel_845_driver
;
1649 case PCI_DEVICE_ID_INTEL_82915G_HB
:
1650 if (find_i830(PCI_DEVICE_ID_INTEL_82915G_IG
)) {
1651 bridge
->driver
= &intel_915_driver
;
1653 bridge
->driver
= &intel_845_driver
;
1657 case PCI_DEVICE_ID_INTEL_82915GM_HB
:
1658 if (find_i830(PCI_DEVICE_ID_INTEL_82915GM_IG
)) {
1659 bridge
->driver
= &intel_915_driver
;
1661 bridge
->driver
= &intel_845_driver
;
1665 case PCI_DEVICE_ID_INTEL_7505_0
:
1666 bridge
->driver
= &intel_7505_driver
;
1669 case PCI_DEVICE_ID_INTEL_7205_0
:
1670 bridge
->driver
= &intel_7505_driver
;
1675 printk(KERN_WARNING PFX
"Unsupported Intel chipset (device id: %04x)\n",
1677 agp_put_bridge(bridge
);
1682 bridge
->capndx
= cap_ptr
;
1684 if (bridge
->driver
== &intel_810_driver
)
1685 bridge
->dev_private_data
= &intel_i810_private
;
1686 else if (bridge
->driver
== &intel_830_driver
)
1687 bridge
->dev_private_data
= &intel_i830_private
;
1689 printk(KERN_INFO PFX
"Detected an Intel %s Chipset.\n", name
);
1692 * The following fixes the case where the BIOS has "forgotten" to
1693 * provide an address range for the GART.
1694 * 20030610 - hamish@zot.org
1696 r
= &pdev
->resource
[0];
1697 if (!r
->start
&& r
->end
) {
1698 if(pci_assign_resource(pdev
, 0)) {
1699 printk(KERN_ERR PFX
"could not assign resource 0\n");
1700 agp_put_bridge(bridge
);
1706 * If the device has not been properly setup, the following will catch
1707 * the problem and should stop the system from crashing.
1708 * 20030610 - hamish@zot.org
1710 if (pci_enable_device(pdev
)) {
1711 printk(KERN_ERR PFX
"Unable to Enable PCI device\n");
1712 agp_put_bridge(bridge
);
1716 /* Fill in the mode register */
1718 pci_read_config_dword(pdev
,
1719 bridge
->capndx
+PCI_AGP_STATUS
,
1723 pci_set_drvdata(pdev
, bridge
);
1724 return agp_add_bridge(bridge
);
1727 printk(KERN_ERR PFX
"Detected an Intel %s chipset, "
1728 "but could not find the secondary device.\n", name
);
1729 agp_put_bridge(bridge
);
1733 static void __devexit
agp_intel_remove(struct pci_dev
*pdev
)
1735 struct agp_bridge_data
*bridge
= pci_get_drvdata(pdev
);
1737 agp_remove_bridge(bridge
);
1739 if (intel_i810_private
.i810_dev
)
1740 pci_dev_put(intel_i810_private
.i810_dev
);
1741 if (intel_i830_private
.i830_dev
)
1742 pci_dev_put(intel_i830_private
.i830_dev
);
1744 agp_put_bridge(bridge
);
1747 static int agp_intel_resume(struct pci_dev
*pdev
)
1749 struct agp_bridge_data
*bridge
= pci_get_drvdata(pdev
);
1751 pci_restore_state(pdev
);
1753 if (bridge
->driver
== &intel_generic_driver
)
1755 else if (bridge
->driver
== &intel_850_driver
)
1756 intel_850_configure();
1757 else if (bridge
->driver
== &intel_845_driver
)
1758 intel_845_configure();
1759 else if (bridge
->driver
== &intel_830mp_driver
)
1760 intel_830mp_configure();
1761 else if (bridge
->driver
== &intel_915_driver
)
1762 intel_i915_configure();
1763 else if (bridge
->driver
== &intel_830_driver
)
1764 intel_i830_configure();
1765 else if (bridge
->driver
== &intel_810_driver
)
1766 intel_i810_configure();
1771 static struct pci_device_id agp_intel_pci_table
[] = {
1774 .class = (PCI_CLASS_BRIDGE_HOST << 8), \
1776 .vendor = PCI_VENDOR_ID_INTEL, \
1778 .subvendor = PCI_ANY_ID, \
1779 .subdevice = PCI_ANY_ID, \
1781 ID(PCI_DEVICE_ID_INTEL_82443LX_0
),
1782 ID(PCI_DEVICE_ID_INTEL_82443BX_0
),
1783 ID(PCI_DEVICE_ID_INTEL_82443GX_0
),
1784 ID(PCI_DEVICE_ID_INTEL_82810_MC1
),
1785 ID(PCI_DEVICE_ID_INTEL_82810_MC3
),
1786 ID(PCI_DEVICE_ID_INTEL_82810E_MC
),
1787 ID(PCI_DEVICE_ID_INTEL_82815_MC
),
1788 ID(PCI_DEVICE_ID_INTEL_82820_HB
),
1789 ID(PCI_DEVICE_ID_INTEL_82820_UP_HB
),
1790 ID(PCI_DEVICE_ID_INTEL_82830_HB
),
1791 ID(PCI_DEVICE_ID_INTEL_82840_HB
),
1792 ID(PCI_DEVICE_ID_INTEL_82845_HB
),
1793 ID(PCI_DEVICE_ID_INTEL_82845G_HB
),
1794 ID(PCI_DEVICE_ID_INTEL_82850_HB
),
1795 ID(PCI_DEVICE_ID_INTEL_82855PM_HB
),
1796 ID(PCI_DEVICE_ID_INTEL_82855GM_HB
),
1797 ID(PCI_DEVICE_ID_INTEL_82860_HB
),
1798 ID(PCI_DEVICE_ID_INTEL_82865_HB
),
1799 ID(PCI_DEVICE_ID_INTEL_82875_HB
),
1800 ID(PCI_DEVICE_ID_INTEL_7505_0
),
1801 ID(PCI_DEVICE_ID_INTEL_7205_0
),
1802 ID(PCI_DEVICE_ID_INTEL_82915G_HB
),
1803 ID(PCI_DEVICE_ID_INTEL_82915GM_HB
),
1807 MODULE_DEVICE_TABLE(pci
, agp_intel_pci_table
);
1809 static struct pci_driver agp_intel_pci_driver
= {
1810 .name
= "agpgart-intel",
1811 .id_table
= agp_intel_pci_table
,
1812 .probe
= agp_intel_probe
,
1813 .remove
= __devexit_p(agp_intel_remove
),
1814 .resume
= agp_intel_resume
,
1817 static int __init
agp_intel_init(void)
1821 return pci_register_driver(&agp_intel_pci_driver
);
1824 static void __exit
agp_intel_cleanup(void)
1826 pci_unregister_driver(&agp_intel_pci_driver
);
1829 module_init(agp_intel_init
);
1830 module_exit(agp_intel_cleanup
);
1832 MODULE_AUTHOR("Dave Jones <davej@codemonkey.org.uk>");
1833 MODULE_LICENSE("GPL and additional rights");