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