blob: 53fe633df1e8d9c1187e862b6a305a1905bbc2bb [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
Dave Jiang11bac802017-02-24 14:56:41 -080014static int alpha_core_agp_vm_fault(struct vm_fault *vmf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070015{
16 alpha_agp_info *agp = agp_bridge->dev_private_data;
17 dma_addr_t dma_addr;
18 unsigned long pa;
19 struct page *page;
20
Dave Jiang11bac802017-02-24 14:56:41 -080021 dma_addr = vmf->address - vmf->vma->vm_start + agp->aperture.bus_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 pa = agp->ops->translate(agp, dma_addr);
23
Dave Jones6a92a4e2006-02-28 00:54:25 -050024 if (pa == (unsigned long)-EINVAL)
Nick Piggin6d6f8d52008-02-04 22:30:04 -080025 return VM_FAULT_SIGBUS; /* no translation */
Dave Jones6a92a4e2006-02-28 00:54:25 -050026
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 /*
28 * Get the page, inc the use count, and return it
29 */
30 page = virt_to_page(__va(pa));
31 get_page(page);
Nick Piggin6d6f8d52008-02-04 22:30:04 -080032 vmf->page = page;
33 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034}
35
36static struct aper_size_info_fixed alpha_core_agp_sizes[] =
37{
38 { 0, 0, 0 }, /* filled in by alpha_core_agp_setup */
39};
40
Alexey Dobriyanf0f37e22009-09-27 22:29:37 +040041static const struct vm_operations_struct alpha_core_agp_vm_ops = {
Nick Piggin6d6f8d52008-02-04 22:30:04 -080042 .fault = alpha_core_agp_vm_fault,
Linus Torvalds1da177e2005-04-16 15:20:36 -070043};
44
45
Linus Torvalds1da177e2005-04-16 15:20:36 -070046static int alpha_core_agp_fetch_size(void)
47{
48 return alpha_core_agp_sizes[0].size;
49}
50
51static int alpha_core_agp_configure(void)
52{
53 alpha_agp_info *agp = agp_bridge->dev_private_data;
54 agp_bridge->gart_bus_addr = agp->aperture.bus_base;
55 return 0;
56}
57
58static void alpha_core_agp_cleanup(void)
59{
60 alpha_agp_info *agp = agp_bridge->dev_private_data;
61
62 agp->ops->cleanup(agp);
63}
64
65static void alpha_core_agp_tlbflush(struct agp_memory *mem)
66{
67 alpha_agp_info *agp = agp_bridge->dev_private_data;
68 alpha_mv.mv_pci_tbi(agp->hose, 0, -1);
69}
70
71static void alpha_core_agp_enable(struct agp_bridge_data *bridge, u32 mode)
72{
73 alpha_agp_info *agp = bridge->dev_private_data;
74
75 agp->mode.lw = agp_collect_device_status(bridge, mode,
76 agp->capability.lw);
77
78 agp->mode.bits.enable = 1;
79 agp->ops->configure(agp);
80
Joe Perchesc7258012008-03-26 14:10:02 -070081 agp_device_command(agp->mode.lw, false);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082}
83
Dave Jones6a92a4e2006-02-28 00:54:25 -050084static int alpha_core_agp_insert_memory(struct agp_memory *mem, off_t pg_start,
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 int type)
86{
87 alpha_agp_info *agp = agp_bridge->dev_private_data;
88 int num_entries, status;
89 void *temp;
90
Thomas Hellstroma030ce42007-01-23 10:33:43 +010091 if (type >= AGP_USER_TYPES || mem->type >= AGP_USER_TYPES)
92 return -EINVAL;
93
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 temp = agp_bridge->current_size;
95 num_entries = A_SIZE_FIX(temp)->num_entries;
Dave Jones6a92a4e2006-02-28 00:54:25 -050096 if ((pg_start + mem->page_count) > num_entries)
97 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
99 status = agp->ops->bind(agp, pg_start, mem);
100 mb();
101 alpha_core_agp_tlbflush(mem);
102
103 return status;
104}
105
Dave Jones6a92a4e2006-02-28 00:54:25 -0500106static int alpha_core_agp_remove_memory(struct agp_memory *mem, off_t pg_start,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 int type)
108{
109 alpha_agp_info *agp = agp_bridge->dev_private_data;
110 int status;
111
112 status = agp->ops->unbind(agp, pg_start, mem);
113 alpha_core_agp_tlbflush(mem);
114 return status;
115}
116
Andrew Morton81c24662006-06-01 20:19:36 -0700117static int alpha_core_agp_create_free_gatt_table(struct agp_bridge_data *a)
118{
119 return 0;
120}
121
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122struct 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,
Joe Perchesc7258012008-03-26 14:10:02 -0700127 .cant_use_aperture = true,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 .masks = NULL,
Dave Jones6a92a4e2006-02-28 00:54:25 -0500129
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 .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,
Andrew Morton81c24662006-06-01 20:19:36 -0700137 .create_gatt_table = alpha_core_agp_create_free_gatt_table,
138 .free_gatt_table = alpha_core_agp_create_free_gatt_table,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 .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,
Rene Herman5f310b62008-08-21 19:15:46 +0200144 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 .agp_destroy_page = agp_generic_destroy_page,
Rene Herman5f310b62008-08-21 19:15:46 +0200146 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100147 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148};
149
150struct agp_bridge_data *alpha_bridge;
151
152int __init
153alpha_core_agp_setup(void)
154{
155 alpha_agp_info *agp = alpha_mv.agp_info();
156 struct pci_dev *pdev; /* faked */
157 struct aper_size_info_fixed *aper_size;
158
159 if (!agp)
160 return -ENODEV;
161 if (agp->ops->setup(agp))
162 return -ENODEV;
163
164 /*
165 * Build the aperture size descriptor
166 */
167 aper_size = alpha_core_agp_sizes;
168 aper_size->size = agp->aperture.size / (1024 * 1024);
169 aper_size->num_entries = agp->aperture.size / PAGE_SIZE;
170 aper_size->page_order = __ffs(aper_size->num_entries / 1024);
171
172 /*
173 * Build a fake pci_dev struct
174 */
Gu Zheng8b1fce02013-05-25 21:48:31 +0800175 pdev = pci_alloc_dev(NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 if (!pdev)
177 return -ENOMEM;
178 pdev->vendor = 0xffff;
179 pdev->device = 0xffff;
180 pdev->sysdata = agp->hose;
181
182 alpha_bridge = agp_alloc_bridge();
183 if (!alpha_bridge)
184 goto fail;
185
186 alpha_bridge->driver = &alpha_core_agp_driver;
187 alpha_bridge->vm_ops = &alpha_core_agp_vm_ops;
188 alpha_bridge->current_size = aper_size; /* only 1 size */
189 alpha_bridge->dev_private_data = agp;
190 alpha_bridge->dev = pdev;
191 alpha_bridge->mode = agp->capability.lw;
192
193 printk(KERN_INFO PFX "Detected AGP on hose %d\n", agp->hose->index);
194 return agp_add_bridge(alpha_bridge);
195
196 fail:
197 kfree(pdev);
198 return -ENOMEM;
199}
200
201static int __init agp_alpha_core_init(void)
202{
203 if (agp_off)
204 return -EINVAL;
205 if (alpha_mv.agp_info)
206 return alpha_core_agp_setup();
207 return -ENODEV;
208}
209
210static void __exit agp_alpha_core_cleanup(void)
211{
212 agp_remove_bridge(alpha_bridge);
213 agp_put_bridge(alpha_bridge);
214}
215
216module_init(agp_alpha_core_init);
217module_exit(agp_alpha_core_cleanup);
218
219MODULE_AUTHOR("Jeff Wiedemeier <Jeff.Wiedemeier@hp.com>");
220MODULE_LICENSE("GPL and additional rights");