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 int alpha_core_agp_vm_fault(struct vm_area_struct
*vma
,
17 alpha_agp_info
*agp
= agp_bridge
->dev_private_data
;
22 dma_addr
= (unsigned long)vmf
->virtual_address
- vma
->vm_start
23 + agp
->aperture
.bus_base
;
24 pa
= agp
->ops
->translate(agp
, dma_addr
);
26 if (pa
== (unsigned long)-EINVAL
)
27 return VM_FAULT_SIGBUS
; /* no translation */
30 * Get the page, inc the use count, and return it
32 page
= virt_to_page(__va(pa
));
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 .fault
= alpha_core_agp_vm_fault
,
48 static int alpha_core_agp_fetch_size(void)
50 return alpha_core_agp_sizes
[0].size
;
53 static int alpha_core_agp_configure(void)
55 alpha_agp_info
*agp
= agp_bridge
->dev_private_data
;
56 agp_bridge
->gart_bus_addr
= agp
->aperture
.bus_base
;
60 static void alpha_core_agp_cleanup(void)
62 alpha_agp_info
*agp
= agp_bridge
->dev_private_data
;
64 agp
->ops
->cleanup(agp
);
67 static void alpha_core_agp_tlbflush(struct agp_memory
*mem
)
69 alpha_agp_info
*agp
= agp_bridge
->dev_private_data
;
70 alpha_mv
.mv_pci_tbi(agp
->hose
, 0, -1);
73 static void alpha_core_agp_enable(struct agp_bridge_data
*bridge
, u32 mode
)
75 alpha_agp_info
*agp
= bridge
->dev_private_data
;
77 agp
->mode
.lw
= agp_collect_device_status(bridge
, mode
,
80 agp
->mode
.bits
.enable
= 1;
81 agp
->ops
->configure(agp
);
83 agp_device_command(agp
->mode
.lw
, false);
86 static int alpha_core_agp_insert_memory(struct agp_memory
*mem
, off_t pg_start
,
89 alpha_agp_info
*agp
= agp_bridge
->dev_private_data
;
90 int num_entries
, status
;
93 if (type
>= AGP_USER_TYPES
|| mem
->type
>= AGP_USER_TYPES
)
96 temp
= agp_bridge
->current_size
;
97 num_entries
= A_SIZE_FIX(temp
)->num_entries
;
98 if ((pg_start
+ mem
->page_count
) > num_entries
)
101 status
= agp
->ops
->bind(agp
, pg_start
, mem
);
103 alpha_core_agp_tlbflush(mem
);
108 static int alpha_core_agp_remove_memory(struct agp_memory
*mem
, off_t pg_start
,
111 alpha_agp_info
*agp
= agp_bridge
->dev_private_data
;
114 status
= agp
->ops
->unbind(agp
, pg_start
, mem
);
115 alpha_core_agp_tlbflush(mem
);
119 static int alpha_core_agp_create_free_gatt_table(struct agp_bridge_data
*a
)
124 struct agp_bridge_driver alpha_core_agp_driver
= {
125 .owner
= THIS_MODULE
,
126 .aperture_sizes
= alpha_core_agp_sizes
,
127 .num_aperture_sizes
= 1,
128 .size_type
= FIXED_APER_SIZE
,
129 .cant_use_aperture
= true,
132 .fetch_size
= alpha_core_agp_fetch_size
,
133 .configure
= alpha_core_agp_configure
,
134 .agp_enable
= alpha_core_agp_enable
,
135 .cleanup
= alpha_core_agp_cleanup
,
136 .tlb_flush
= alpha_core_agp_tlbflush
,
137 .mask_memory
= agp_generic_mask_memory
,
138 .cache_flush
= global_cache_flush
,
139 .create_gatt_table
= alpha_core_agp_create_free_gatt_table
,
140 .free_gatt_table
= alpha_core_agp_create_free_gatt_table
,
141 .insert_memory
= alpha_core_agp_insert_memory
,
142 .remove_memory
= alpha_core_agp_remove_memory
,
143 .alloc_by_type
= agp_generic_alloc_by_type
,
144 .free_by_type
= agp_generic_free_by_type
,
145 .agp_alloc_page
= agp_generic_alloc_page
,
146 .agp_destroy_page
= agp_generic_destroy_page
,
147 .agp_type_to_mask_type
= agp_generic_type_to_mask_type
,
150 struct agp_bridge_data
*alpha_bridge
;
153 alpha_core_agp_setup(void)
155 alpha_agp_info
*agp
= alpha_mv
.agp_info();
156 struct pci_dev
*pdev
; /* faked */
157 struct aper_size_info_fixed
*aper_size
;
161 if (agp
->ops
->setup(agp
))
165 * Build the aperture size descriptor
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);
173 * Build a fake pci_dev struct
175 pdev
= alloc_pci_dev();
178 pdev
->vendor
= 0xffff;
179 pdev
->device
= 0xffff;
180 pdev
->sysdata
= agp
->hose
;
182 alpha_bridge
= agp_alloc_bridge();
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
;
193 printk(KERN_INFO PFX
"Detected AGP on hose %d\n", agp
->hose
->index
);
194 return agp_add_bridge(alpha_bridge
);
201 static int __init
agp_alpha_core_init(void)
205 if (alpha_mv
.agp_info
)
206 return alpha_core_agp_setup();
210 static void __exit
agp_alpha_core_cleanup(void)
212 agp_remove_bridge(alpha_bridge
);
213 agp_put_bridge(alpha_bridge
);
216 module_init(agp_alpha_core_init
);
217 module_exit(agp_alpha_core_cleanup
);
219 MODULE_AUTHOR("Jeff Wiedemeier <Jeff.Wiedemeier@hp.com>");
220 MODULE_LICENSE("GPL and additional rights");