blob: aa8f3a39a7044d74fe1652d62ef077fc470b024b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#include <linux/module.h>
2#include <linux/pci.h>
3#include <linux/init.h>
4#include <linux/agp_backend.h>
5#include <linux/mm.h>
6#include <linux/slab.h>
7
8#include <asm/machvec.h>
9#include <asm/agp_backend.h>
10#include "../../../arch/alpha/kernel/pci_impl.h"
11
12#include "agp.h"
13
14static struct page *alpha_core_agp_vm_nopage(struct vm_area_struct *vma,
15 unsigned long address,
16 int *type)
17{
18 alpha_agp_info *agp = agp_bridge->dev_private_data;
19 dma_addr_t dma_addr;
20 unsigned long pa;
21 struct page *page;
22
23 dma_addr = address - vma->vm_start + agp->aperture.bus_base;
24 pa = agp->ops->translate(agp, dma_addr);
25
Dave Jones6a92a4e2006-02-28 00:54:25 -050026 if (pa == (unsigned long)-EINVAL)
27 return NULL; /* no translation */
28
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 /*
30 * Get the page, inc the use count, and return it
31 */
32 page = virt_to_page(__va(pa));
33 get_page(page);
34 if (type)
35 *type = VM_FAULT_MINOR;
36 return page;
37}
38
39static struct aper_size_info_fixed alpha_core_agp_sizes[] =
40{
41 { 0, 0, 0 }, /* filled in by alpha_core_agp_setup */
42};
43
44struct vm_operations_struct alpha_core_agp_vm_ops = {
45 .nopage = alpha_core_agp_vm_nopage,
46};
47
48
Linus Torvalds1da177e2005-04-16 15:20:36 -070049static int alpha_core_agp_fetch_size(void)
50{
51 return alpha_core_agp_sizes[0].size;
52}
53
54static int alpha_core_agp_configure(void)
55{
56 alpha_agp_info *agp = agp_bridge->dev_private_data;
57 agp_bridge->gart_bus_addr = agp->aperture.bus_base;
58 return 0;
59}
60
61static void alpha_core_agp_cleanup(void)
62{
63 alpha_agp_info *agp = agp_bridge->dev_private_data;
64
65 agp->ops->cleanup(agp);
66}
67
68static void alpha_core_agp_tlbflush(struct agp_memory *mem)
69{
70 alpha_agp_info *agp = agp_bridge->dev_private_data;
71 alpha_mv.mv_pci_tbi(agp->hose, 0, -1);
72}
73
74static void alpha_core_agp_enable(struct agp_bridge_data *bridge, u32 mode)
75{
76 alpha_agp_info *agp = bridge->dev_private_data;
77
78 agp->mode.lw = agp_collect_device_status(bridge, mode,
79 agp->capability.lw);
80
81 agp->mode.bits.enable = 1;
82 agp->ops->configure(agp);
83
84 agp_device_command(agp->mode.lw, 0);
85}
86
Dave Jones6a92a4e2006-02-28 00:54:25 -050087static int alpha_core_agp_insert_memory(struct agp_memory *mem, off_t pg_start,
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 int type)
89{
90 alpha_agp_info *agp = agp_bridge->dev_private_data;
91 int num_entries, status;
92 void *temp;
93
Thomas Hellstroma030ce42007-01-23 10:33:43 +010094 if (type >= AGP_USER_TYPES || mem->type >= AGP_USER_TYPES)
95 return -EINVAL;
96
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 temp = agp_bridge->current_size;
98 num_entries = A_SIZE_FIX(temp)->num_entries;
Dave Jones6a92a4e2006-02-28 00:54:25 -050099 if ((pg_start + mem->page_count) > num_entries)
100 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
102 status = agp->ops->bind(agp, pg_start, mem);
103 mb();
104 alpha_core_agp_tlbflush(mem);
105
106 return status;
107}
108
Dave Jones6a92a4e2006-02-28 00:54:25 -0500109static int alpha_core_agp_remove_memory(struct agp_memory *mem, off_t pg_start,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 int type)
111{
112 alpha_agp_info *agp = agp_bridge->dev_private_data;
113 int status;
114
115 status = agp->ops->unbind(agp, pg_start, mem);
116 alpha_core_agp_tlbflush(mem);
117 return status;
118}
119
Andrew Morton81c24662006-06-01 20:19:36 -0700120static int alpha_core_agp_create_free_gatt_table(struct agp_bridge_data *a)
121{
122 return 0;
123}
124
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125struct agp_bridge_driver alpha_core_agp_driver = {
126 .owner = THIS_MODULE,
127 .aperture_sizes = alpha_core_agp_sizes,
128 .num_aperture_sizes = 1,
129 .size_type = FIXED_APER_SIZE,
130 .cant_use_aperture = 1,
131 .masks = NULL,
Dave Jones6a92a4e2006-02-28 00:54:25 -0500132
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 .fetch_size = alpha_core_agp_fetch_size,
134 .configure = alpha_core_agp_configure,
135 .agp_enable = alpha_core_agp_enable,
136 .cleanup = alpha_core_agp_cleanup,
137 .tlb_flush = alpha_core_agp_tlbflush,
138 .mask_memory = agp_generic_mask_memory,
139 .cache_flush = global_cache_flush,
Andrew Morton81c24662006-06-01 20:19:36 -0700140 .create_gatt_table = alpha_core_agp_create_free_gatt_table,
141 .free_gatt_table = alpha_core_agp_create_free_gatt_table,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 .insert_memory = alpha_core_agp_insert_memory,
143 .remove_memory = alpha_core_agp_remove_memory,
144 .alloc_by_type = agp_generic_alloc_by_type,
145 .free_by_type = agp_generic_free_by_type,
146 .agp_alloc_page = agp_generic_alloc_page,
147 .agp_destroy_page = agp_generic_destroy_page,
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100148 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149};
150
151struct agp_bridge_data *alpha_bridge;
152
153int __init
154alpha_core_agp_setup(void)
155{
156 alpha_agp_info *agp = alpha_mv.agp_info();
157 struct pci_dev *pdev; /* faked */
158 struct aper_size_info_fixed *aper_size;
159
160 if (!agp)
161 return -ENODEV;
162 if (agp->ops->setup(agp))
163 return -ENODEV;
164
165 /*
166 * Build the aperture size descriptor
167 */
168 aper_size = alpha_core_agp_sizes;
169 aper_size->size = agp->aperture.size / (1024 * 1024);
170 aper_size->num_entries = agp->aperture.size / PAGE_SIZE;
171 aper_size->page_order = __ffs(aper_size->num_entries / 1024);
172
173 /*
174 * Build a fake pci_dev struct
175 */
Michael Ellermanbab41e92007-04-05 17:19:09 +1000176 pdev = alloc_pci_dev();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 if (!pdev)
178 return -ENOMEM;
179 pdev->vendor = 0xffff;
180 pdev->device = 0xffff;
181 pdev->sysdata = agp->hose;
182
183 alpha_bridge = agp_alloc_bridge();
184 if (!alpha_bridge)
185 goto fail;
186
187 alpha_bridge->driver = &alpha_core_agp_driver;
188 alpha_bridge->vm_ops = &alpha_core_agp_vm_ops;
189 alpha_bridge->current_size = aper_size; /* only 1 size */
190 alpha_bridge->dev_private_data = agp;
191 alpha_bridge->dev = pdev;
192 alpha_bridge->mode = agp->capability.lw;
193
194 printk(KERN_INFO PFX "Detected AGP on hose %d\n", agp->hose->index);
195 return agp_add_bridge(alpha_bridge);
196
197 fail:
198 kfree(pdev);
199 return -ENOMEM;
200}
201
202static int __init agp_alpha_core_init(void)
203{
204 if (agp_off)
205 return -EINVAL;
206 if (alpha_mv.agp_info)
207 return alpha_core_agp_setup();
208 return -ENODEV;
209}
210
211static void __exit agp_alpha_core_cleanup(void)
212{
213 agp_remove_bridge(alpha_bridge);
214 agp_put_bridge(alpha_bridge);
215}
216
217module_init(agp_alpha_core_init);
218module_exit(agp_alpha_core_cleanup);
219
220MODULE_AUTHOR("Jeff Wiedemeier <Jeff.Wiedemeier@hp.com>");
221MODULE_LICENSE("GPL and additional rights");