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)
27 return NULL; /* no translation */
30 * Get the page, inc the use count, and return it
32 page = virt_to_page(__va(pa));
35 *type = VM_FAULT_MINOR;
39 static struct aper_size_info_fixed alpha_core_agp_sizes[] =
41 { 0, 0, 0 }, /* filled in by alpha_core_agp_setup */
44 struct vm_operations_struct alpha_core_agp_vm_ops = {
45 .nopage = alpha_core_agp_vm_nopage,
49 static int alpha_core_agp_fetch_size(void)
51 return alpha_core_agp_sizes[0].size;
54 static int alpha_core_agp_configure(void)
56 alpha_agp_info *agp = agp_bridge->dev_private_data;
57 agp_bridge->gart_bus_addr = agp->aperture.bus_base;
61 static void alpha_core_agp_cleanup(void)
63 alpha_agp_info *agp = agp_bridge->dev_private_data;
65 agp->ops->cleanup(agp);
68 static void alpha_core_agp_tlbflush(struct agp_memory *mem)
70 alpha_agp_info *agp = agp_bridge->dev_private_data;
71 alpha_mv.mv_pci_tbi(agp->hose, 0, -1);
74 static void alpha_core_agp_enable(struct agp_bridge_data *bridge, u32 mode)
76 alpha_agp_info *agp = bridge->dev_private_data;
78 agp->mode.lw = agp_collect_device_status(bridge, mode,
81 agp->mode.bits.enable = 1;
82 agp->ops->configure(agp);
84 agp_device_command(agp->mode.lw, 0);
87 static int alpha_core_agp_insert_memory(struct agp_memory *mem, off_t pg_start,
90 alpha_agp_info *agp = agp_bridge->dev_private_data;
91 int num_entries, status;
94 temp = agp_bridge->current_size;
95 num_entries = A_SIZE_FIX(temp)->num_entries;
96 if ((pg_start + mem->page_count) > num_entries)
99 status = agp->ops->bind(agp, pg_start, mem);
101 alpha_core_agp_tlbflush(mem);
106 static int alpha_core_agp_remove_memory(struct agp_memory *mem, off_t pg_start,
109 alpha_agp_info *agp = agp_bridge->dev_private_data;
112 status = agp->ops->unbind(agp, pg_start, mem);
113 alpha_core_agp_tlbflush(mem);
117 static int alpha_core_agp_create_free_gatt_table(struct agp_bridge_data *a)
122 struct agp_bridge_driver alpha_core_agp_driver = {
123 .owner = THIS_MODULE,
124 .aperture_sizes = alpha_core_agp_sizes,
125 .num_aperture_sizes = 1,
126 .size_type = FIXED_APER_SIZE,
127 .cant_use_aperture = 1,
130 .fetch_size = alpha_core_agp_fetch_size,
131 .configure = alpha_core_agp_configure,
132 .agp_enable = alpha_core_agp_enable,
133 .cleanup = alpha_core_agp_cleanup,
134 .tlb_flush = alpha_core_agp_tlbflush,
135 .mask_memory = agp_generic_mask_memory,
136 .cache_flush = global_cache_flush,
137 .create_gatt_table = alpha_core_agp_create_free_gatt_table,
138 .free_gatt_table = alpha_core_agp_create_free_gatt_table,
139 .insert_memory = alpha_core_agp_insert_memory,
140 .remove_memory = alpha_core_agp_remove_memory,
141 .alloc_by_type = agp_generic_alloc_by_type,
142 .free_by_type = agp_generic_free_by_type,
143 .agp_alloc_page = agp_generic_alloc_page,
144 .agp_destroy_page = agp_generic_destroy_page,
147 struct agp_bridge_data *alpha_bridge;
150 alpha_core_agp_setup(void)
152 alpha_agp_info *agp = alpha_mv.agp_info();
153 struct pci_dev *pdev; /* faked */
154 struct aper_size_info_fixed *aper_size;
158 if (agp->ops->setup(agp))
162 * Build the aperture size descriptor
164 aper_size = alpha_core_agp_sizes;
165 aper_size->size = agp->aperture.size / (1024 * 1024);
166 aper_size->num_entries = agp->aperture.size / PAGE_SIZE;
167 aper_size->page_order = __ffs(aper_size->num_entries / 1024);
170 * Build a fake pci_dev struct
172 pdev = kmalloc(sizeof(struct pci_dev), GFP_KERNEL);
175 pdev->vendor = 0xffff;
176 pdev->device = 0xffff;
177 pdev->sysdata = agp->hose;
179 alpha_bridge = agp_alloc_bridge();
183 alpha_bridge->driver = &alpha_core_agp_driver;
184 alpha_bridge->vm_ops = &alpha_core_agp_vm_ops;
185 alpha_bridge->current_size = aper_size; /* only 1 size */
186 alpha_bridge->dev_private_data = agp;
187 alpha_bridge->dev = pdev;
188 alpha_bridge->mode = agp->capability.lw;
190 printk(KERN_INFO PFX "Detected AGP on hose %d\n", agp->hose->index);
191 return agp_add_bridge(alpha_bridge);
198 static int __init agp_alpha_core_init(void)
202 if (alpha_mv.agp_info)
203 return alpha_core_agp_setup();
207 static void __exit agp_alpha_core_cleanup(void)
209 agp_remove_bridge(alpha_bridge);
210 agp_put_bridge(alpha_bridge);
213 module_init(agp_alpha_core_init);
214 module_exit(agp_alpha_core_cleanup);
216 MODULE_AUTHOR("Jeff Wiedemeier <Jeff.Wiedemeier@hp.com>");
217 MODULE_LICENSE("GPL and additional rights");