1 #include <linux/module.h>
3 #include <linux/init.h>
4 #include <linux/agp_backend.h>
6 #include <linux/slab.h>
8 #include <asm/machvec.h>
9 #include <asm/agp_backend.h>
10 #include "../../../arch/alpha/kernel/pci_impl.h"
14 static struct page
*alpha_core_agp_vm_nopage(struct vm_area_struct
*vma
,
15 unsigned long address
,
18 alpha_agp_info
*agp
= agp_bridge
->dev_private_data
;
23 dma_addr
= address
- vma
->vm_start
+ agp
->aperture
.bus_base
;
24 pa
= agp
->ops
->translate(agp
, dma_addr
);
26 if (pa
== (unsigned long)-EINVAL
) return NULL
; /* no translation */
29 * Get the page, inc the use count, and return it
31 page
= virt_to_page(__va(pa
));
34 *type
= VM_FAULT_MINOR
;
38 static struct aper_size_info_fixed alpha_core_agp_sizes
[] =
40 { 0, 0, 0 }, /* filled in by alpha_core_agp_setup */
43 struct vm_operations_struct alpha_core_agp_vm_ops
= {
44 .nopage
= alpha_core_agp_vm_nopage
,
48 static int alpha_core_agp_nop(void)
50 /* just return success */
54 static int alpha_core_agp_fetch_size(void)
56 return alpha_core_agp_sizes
[0].size
;
59 static int alpha_core_agp_configure(void)
61 alpha_agp_info
*agp
= agp_bridge
->dev_private_data
;
62 agp_bridge
->gart_bus_addr
= agp
->aperture
.bus_base
;
66 static void alpha_core_agp_cleanup(void)
68 alpha_agp_info
*agp
= agp_bridge
->dev_private_data
;
70 agp
->ops
->cleanup(agp
);
73 static void alpha_core_agp_tlbflush(struct agp_memory
*mem
)
75 alpha_agp_info
*agp
= agp_bridge
->dev_private_data
;
76 alpha_mv
.mv_pci_tbi(agp
->hose
, 0, -1);
79 static void alpha_core_agp_enable(struct agp_bridge_data
*bridge
, u32 mode
)
81 alpha_agp_info
*agp
= bridge
->dev_private_data
;
83 agp
->mode
.lw
= agp_collect_device_status(bridge
, mode
,
86 agp
->mode
.bits
.enable
= 1;
87 agp
->ops
->configure(agp
);
89 agp_device_command(agp
->mode
.lw
, 0);
92 static int alpha_core_agp_insert_memory(struct agp_memory
*mem
, off_t pg_start
,
95 alpha_agp_info
*agp
= agp_bridge
->dev_private_data
;
96 int num_entries
, status
;
99 temp
= agp_bridge
->current_size
;
100 num_entries
= A_SIZE_FIX(temp
)->num_entries
;
101 if ((pg_start
+ mem
->page_count
) > num_entries
) return -EINVAL
;
103 status
= agp
->ops
->bind(agp
, pg_start
, mem
);
105 alpha_core_agp_tlbflush(mem
);
110 static int alpha_core_agp_remove_memory(struct agp_memory
*mem
, off_t pg_start
,
113 alpha_agp_info
*agp
= agp_bridge
->dev_private_data
;
116 status
= agp
->ops
->unbind(agp
, pg_start
, mem
);
117 alpha_core_agp_tlbflush(mem
);
121 struct agp_bridge_driver alpha_core_agp_driver
= {
122 .owner
= THIS_MODULE
,
123 .aperture_sizes
= alpha_core_agp_sizes
,
124 .num_aperture_sizes
= 1,
125 .size_type
= FIXED_APER_SIZE
,
126 .cant_use_aperture
= 1,
129 .fetch_size
= alpha_core_agp_fetch_size
,
130 .configure
= alpha_core_agp_configure
,
131 .agp_enable
= alpha_core_agp_enable
,
132 .cleanup
= alpha_core_agp_cleanup
,
133 .tlb_flush
= alpha_core_agp_tlbflush
,
134 .mask_memory
= agp_generic_mask_memory
,
135 .cache_flush
= global_cache_flush
,
136 .create_gatt_table
= alpha_core_agp_nop
,
137 .free_gatt_table
= alpha_core_agp_nop
,
138 .insert_memory
= alpha_core_agp_insert_memory
,
139 .remove_memory
= alpha_core_agp_remove_memory
,
140 .alloc_by_type
= agp_generic_alloc_by_type
,
141 .free_by_type
= agp_generic_free_by_type
,
142 .agp_alloc_page
= agp_generic_alloc_page
,
143 .agp_destroy_page
= agp_generic_destroy_page
,
146 struct agp_bridge_data
*alpha_bridge
;
149 alpha_core_agp_setup(void)
151 alpha_agp_info
*agp
= alpha_mv
.agp_info();
152 struct pci_dev
*pdev
; /* faked */
153 struct aper_size_info_fixed
*aper_size
;
157 if (agp
->ops
->setup(agp
))
161 * Build the aperture size descriptor
163 aper_size
= alpha_core_agp_sizes
;
164 aper_size
->size
= agp
->aperture
.size
/ (1024 * 1024);
165 aper_size
->num_entries
= agp
->aperture
.size
/ PAGE_SIZE
;
166 aper_size
->page_order
= __ffs(aper_size
->num_entries
/ 1024);
169 * Build a fake pci_dev struct
171 pdev
= kmalloc(sizeof(struct pci_dev
), GFP_KERNEL
);
174 pdev
->vendor
= 0xffff;
175 pdev
->device
= 0xffff;
176 pdev
->sysdata
= agp
->hose
;
178 alpha_bridge
= agp_alloc_bridge();
182 alpha_bridge
->driver
= &alpha_core_agp_driver
;
183 alpha_bridge
->vm_ops
= &alpha_core_agp_vm_ops
;
184 alpha_bridge
->current_size
= aper_size
; /* only 1 size */
185 alpha_bridge
->dev_private_data
= agp
;
186 alpha_bridge
->dev
= pdev
;
187 alpha_bridge
->mode
= agp
->capability
.lw
;
189 printk(KERN_INFO PFX
"Detected AGP on hose %d\n", agp
->hose
->index
);
190 return agp_add_bridge(alpha_bridge
);
197 static int __init
agp_alpha_core_init(void)
201 if (alpha_mv
.agp_info
)
202 return alpha_core_agp_setup();
206 static void __exit
agp_alpha_core_cleanup(void)
208 agp_remove_bridge(alpha_bridge
);
209 agp_put_bridge(alpha_bridge
);
212 module_init(agp_alpha_core_init
);
213 module_exit(agp_alpha_core_cleanup
);
215 MODULE_AUTHOR("Jeff Wiedemeier <Jeff.Wiedemeier@hp.com>");
216 MODULE_LICENSE("GPL and additional rights");