📄 uninorth-agp.c
字号:
static int agp_uninorth_resume(struct pci_dev *pdev){ struct agp_bridge_data *bridge; u32 command; bridge = agp_find_bridge(pdev); if (bridge == NULL) return -ENODEV; command = (u32)bridge->dev_private_data; bridge->dev_private_data = NULL; if (!(command & PCI_AGP_COMMAND_AGP)) return 0; uninorth_agp_enable(bridge, command); return 0;}#endif /* CONFIG_PM */static int uninorth_create_gatt_table(struct agp_bridge_data *bridge){ char *table; char *table_end; int size; int page_order; int num_entries; int i; void *temp; struct page *page; /* We can't handle 2 level gatt's */ if (bridge->driver->size_type == LVL2_APER_SIZE) return -EINVAL; table = NULL; i = bridge->aperture_size_idx; temp = bridge->current_size; size = page_order = num_entries = 0; do { size = A_SIZE_32(temp)->size; page_order = A_SIZE_32(temp)->page_order; num_entries = A_SIZE_32(temp)->num_entries; table = (char *) __get_free_pages(GFP_KERNEL, page_order); if (table == NULL) { i++; bridge->current_size = A_IDX32(bridge); } else { bridge->aperture_size_idx = i; } } while (!table && (i < bridge->driver->num_aperture_sizes)); if (table == NULL) return -ENOMEM; table_end = table + ((PAGE_SIZE * (1 << page_order)) - 1); for (page = virt_to_page(table); page <= virt_to_page(table_end); page++) SetPageReserved(page); bridge->gatt_table_real = (u32 *) table; bridge->gatt_table = (u32 *)table; bridge->gatt_bus_addr = virt_to_gart(table); for (i = 0; i < num_entries; i++) bridge->gatt_table[i] = 0; flush_dcache_range((unsigned long)table, (unsigned long)table_end); return 0;}static int uninorth_free_gatt_table(struct agp_bridge_data *bridge){ int page_order; char *table, *table_end; void *temp; struct page *page; temp = bridge->current_size; page_order = A_SIZE_32(temp)->page_order; /* Do not worry about freeing memory, because if this is * called, then all agp memory is deallocated and removed * from the table. */ table = (char *) bridge->gatt_table_real; table_end = table + ((PAGE_SIZE * (1 << page_order)) - 1); for (page = virt_to_page(table); page <= virt_to_page(table_end); page++) ClearPageReserved(page); free_pages((unsigned long) bridge->gatt_table_real, page_order); return 0;}void null_cache_flush(void){ mb();}/* Setup function */static struct aper_size_info_32 uninorth_sizes[7] ={#if 0 /* Not sure uninorth supports that high aperture sizes */ {256, 65536, 6, 64}, {128, 32768, 5, 32}, {64, 16384, 4, 16},#endif {32, 8192, 3, 8}, {16, 4096, 2, 4}, {8, 2048, 1, 2}, {4, 1024, 0, 1}};/* * Not sure that u3 supports that high aperture sizes but it * would strange if it did not :) */static struct aper_size_info_32 u3_sizes[8] ={ {512, 131072, 7, 128}, {256, 65536, 6, 64}, {128, 32768, 5, 32}, {64, 16384, 4, 16}, {32, 8192, 3, 8}, {16, 4096, 2, 4}, {8, 2048, 1, 2}, {4, 1024, 0, 1}};struct agp_bridge_driver uninorth_agp_driver = { .owner = THIS_MODULE, .aperture_sizes = (void *)uninorth_sizes, .size_type = U32_APER_SIZE, .num_aperture_sizes = 4, .configure = uninorth_configure, .fetch_size = uninorth_fetch_size, .cleanup = uninorth_cleanup, .tlb_flush = uninorth_tlbflush, .mask_memory = agp_generic_mask_memory, .masks = NULL, .cache_flush = null_cache_flush, .agp_enable = uninorth_agp_enable, .create_gatt_table = uninorth_create_gatt_table, .free_gatt_table = uninorth_free_gatt_table, .insert_memory = uninorth_insert_memory, .remove_memory = agp_generic_remove_memory, .alloc_by_type = agp_generic_alloc_by_type, .free_by_type = agp_generic_free_by_type, .agp_alloc_page = agp_generic_alloc_page, .agp_destroy_page = agp_generic_destroy_page, .cant_use_aperture = 1,};struct agp_bridge_driver u3_agp_driver = { .owner = THIS_MODULE, .aperture_sizes = (void *)u3_sizes, .size_type = U32_APER_SIZE, .num_aperture_sizes = 8, .configure = uninorth_configure, .fetch_size = uninorth_fetch_size, .cleanup = uninorth_cleanup, .tlb_flush = uninorth_tlbflush, .mask_memory = agp_generic_mask_memory, .masks = NULL, .cache_flush = null_cache_flush, .agp_enable = uninorth_agp_enable, .create_gatt_table = uninorth_create_gatt_table, .free_gatt_table = uninorth_free_gatt_table, .insert_memory = u3_insert_memory, .remove_memory = u3_remove_memory, .alloc_by_type = agp_generic_alloc_by_type, .free_by_type = agp_generic_free_by_type, .agp_alloc_page = agp_generic_alloc_page, .agp_destroy_page = agp_generic_destroy_page, .cant_use_aperture = 1, .needs_scratch_page = 1,};static struct agp_device_ids uninorth_agp_device_ids[] __devinitdata = { { .device_id = PCI_DEVICE_ID_APPLE_UNI_N_AGP, .chipset_name = "UniNorth", }, { .device_id = PCI_DEVICE_ID_APPLE_UNI_N_AGP_P, .chipset_name = "UniNorth/Pangea", }, { .device_id = PCI_DEVICE_ID_APPLE_UNI_N_AGP15, .chipset_name = "UniNorth 1.5", }, { .device_id = PCI_DEVICE_ID_APPLE_UNI_N_AGP2, .chipset_name = "UniNorth 2", }, { .device_id = PCI_DEVICE_ID_APPLE_U3_AGP, .chipset_name = "U3", }, { .device_id = PCI_DEVICE_ID_APPLE_U3L_AGP, .chipset_name = "U3L", }, { .device_id = PCI_DEVICE_ID_APPLE_U3H_AGP, .chipset_name = "U3H", }, { .device_id = PCI_DEVICE_ID_APPLE_IPID2_AGP, .chipset_name = "UniNorth/Intrepid2", },};static int __devinit agp_uninorth_probe(struct pci_dev *pdev, const struct pci_device_id *ent){ struct agp_device_ids *devs = uninorth_agp_device_ids; struct agp_bridge_data *bridge; struct device_node *uninorth_node; u8 cap_ptr; int j; cap_ptr = pci_find_capability(pdev, PCI_CAP_ID_AGP); if (cap_ptr == 0) return -ENODEV; /* probe for known chipsets */ for (j = 0; devs[j].chipset_name != NULL; ++j) { if (pdev->device == devs[j].device_id) { printk(KERN_INFO PFX "Detected Apple %s chipset\n", devs[j].chipset_name); goto found; } } printk(KERN_ERR PFX "Unsupported Apple chipset (device id: %04x).\n", pdev->device); return -ENODEV; found: /* Set revision to 0 if we could not read it. */ uninorth_rev = 0; is_u3 = 0; /* Locate core99 Uni-N */ uninorth_node = of_find_node_by_name(NULL, "uni-n"); /* Locate G5 u3 */ if (uninorth_node == NULL) { is_u3 = 1; uninorth_node = of_find_node_by_name(NULL, "u3"); } if (uninorth_node) { int *revprop = (int *) get_property(uninorth_node, "device-rev", NULL); if (revprop != NULL) uninorth_rev = *revprop & 0x3f; of_node_put(uninorth_node); }#ifdef CONFIG_PM /* Inform platform of our suspend/resume caps */ pmac_register_agp_pm(pdev, agp_uninorth_suspend, agp_uninorth_resume);#endif /* Allocate & setup our driver */ bridge = agp_alloc_bridge(); if (!bridge) return -ENOMEM; if (is_u3) bridge->driver = &u3_agp_driver; else bridge->driver = &uninorth_agp_driver; bridge->dev = pdev; bridge->capndx = cap_ptr; bridge->flags = AGP_ERRATA_FASTWRITES; /* Fill in the mode register */ pci_read_config_dword(pdev, cap_ptr+PCI_AGP_STATUS, &bridge->mode); pci_set_drvdata(pdev, bridge); return agp_add_bridge(bridge);}static void __devexit agp_uninorth_remove(struct pci_dev *pdev){ struct agp_bridge_data *bridge = pci_get_drvdata(pdev);#ifdef CONFIG_PM /* Inform platform of our suspend/resume caps */ pmac_register_agp_pm(pdev, NULL, NULL);#endif agp_remove_bridge(bridge); agp_put_bridge(bridge);}static struct pci_device_id agp_uninorth_pci_table[] = { { .class = (PCI_CLASS_BRIDGE_HOST << 8), .class_mask = ~0, .vendor = PCI_VENDOR_ID_APPLE, .device = PCI_ANY_ID, .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID, }, { }};MODULE_DEVICE_TABLE(pci, agp_uninorth_pci_table);static struct pci_driver agp_uninorth_pci_driver = { .name = "agpgart-uninorth", .id_table = agp_uninorth_pci_table, .probe = agp_uninorth_probe, .remove = agp_uninorth_remove,};static int __init agp_uninorth_init(void){ if (agp_off) return -EINVAL; return pci_register_driver(&agp_uninorth_pci_driver);}static void __exit agp_uninorth_cleanup(void){ pci_unregister_driver(&agp_uninorth_pci_driver);}module_init(agp_uninorth_init);module_exit(agp_uninorth_cleanup);MODULE_AUTHOR("Ben Herrenschmidt & Paul Mackerras");MODULE_LICENSE("GPL");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -