Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * ATi AGPGART routines. |
| 3 | */ |
| 4 | |
| 5 | #include <linux/types.h> |
| 6 | #include <linux/module.h> |
| 7 | #include <linux/pci.h> |
| 8 | #include <linux/init.h> |
Tim Schmielau | 4e57b68 | 2005-10-30 15:03:48 -0800 | [diff] [blame] | 9 | #include <linux/string.h> |
| 10 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/agp_backend.h> |
| 12 | #include <asm/agp.h> |
| 13 | #include "agp.h" |
| 14 | |
| 15 | #define ATI_GART_MMBASE_ADDR 0x14 |
| 16 | #define ATI_RS100_APSIZE 0xac |
| 17 | #define ATI_RS100_IG_AGPMODE 0xb0 |
| 18 | #define ATI_RS300_APSIZE 0xf8 |
| 19 | #define ATI_RS300_IG_AGPMODE 0xfc |
| 20 | #define ATI_GART_FEATURE_ID 0x00 |
| 21 | #define ATI_GART_BASE 0x04 |
| 22 | #define ATI_GART_CACHE_SZBASE 0x08 |
| 23 | #define ATI_GART_CACHE_CNTRL 0x0c |
| 24 | #define ATI_GART_CACHE_ENTRY_CNTRL 0x10 |
| 25 | |
| 26 | |
Dave Jones | e5524f3 | 2007-02-22 18:41:28 -0500 | [diff] [blame] | 27 | static const struct aper_size_info_lvl2 ati_generic_sizes[7] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | { |
| 29 | {2048, 524288, 0x0000000c}, |
| 30 | {1024, 262144, 0x0000000a}, |
| 31 | {512, 131072, 0x00000008}, |
| 32 | {256, 65536, 0x00000006}, |
| 33 | {128, 32768, 0x00000004}, |
| 34 | {64, 16384, 0x00000002}, |
| 35 | {32, 8192, 0x00000000} |
| 36 | }; |
| 37 | |
| 38 | static struct gatt_mask ati_generic_masks[] = |
| 39 | { |
| 40 | { .mask = 1, .type = 0} |
| 41 | }; |
| 42 | |
| 43 | |
Dave Jones | 87a17f3 | 2007-01-28 17:41:37 -0500 | [diff] [blame] | 44 | struct ati_page_map { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | unsigned long *real; |
| 46 | unsigned long __iomem *remapped; |
Dave Jones | 87a17f3 | 2007-01-28 17:41:37 -0500 | [diff] [blame] | 47 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
| 49 | static struct _ati_generic_private { |
| 50 | volatile u8 __iomem *registers; |
Dave Jones | 87a17f3 | 2007-01-28 17:41:37 -0500 | [diff] [blame] | 51 | struct ati_page_map **gatt_pages; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | int num_tables; |
| 53 | } ati_generic_private; |
| 54 | |
Dave Jones | 87a17f3 | 2007-01-28 17:41:37 -0500 | [diff] [blame] | 55 | static int ati_create_page_map(struct ati_page_map *page_map) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | { |
| 57 | int i, err = 0; |
| 58 | |
| 59 | page_map->real = (unsigned long *) __get_free_page(GFP_KERNEL); |
| 60 | if (page_map->real == NULL) |
| 61 | return -ENOMEM; |
| 62 | |
Dave Airlie | 44a207f | 2008-02-20 10:37:08 +1000 | [diff] [blame^] | 63 | set_memory_uc((unsigned long)page_map->real, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | err = map_page_into_agp(virt_to_page(page_map->real)); |
Arjan van dev Ven | fcea424 | 2008-02-06 05:16:00 +0100 | [diff] [blame] | 65 | page_map->remapped = page_map->real; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
Dave Jones | 6a92a4e | 2006-02-28 00:54:25 -0500 | [diff] [blame] | 67 | for (i = 0; i < PAGE_SIZE / sizeof(unsigned long); i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | writel(agp_bridge->scratch_page, page_map->remapped+i); |
| 69 | readl(page_map->remapped+i); /* PCI Posting. */ |
| 70 | } |
| 71 | |
| 72 | return 0; |
| 73 | } |
| 74 | |
| 75 | |
Dave Jones | 87a17f3 | 2007-01-28 17:41:37 -0500 | [diff] [blame] | 76 | static void ati_free_page_map(struct ati_page_map *page_map) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | { |
| 78 | unmap_page_from_agp(virt_to_page(page_map->real)); |
Dave Airlie | 44a207f | 2008-02-20 10:37:08 +1000 | [diff] [blame^] | 79 | set_memory_wb((unsigned long)page_map->real, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | free_page((unsigned long) page_map->real); |
| 81 | } |
| 82 | |
| 83 | |
| 84 | static void ati_free_gatt_pages(void) |
| 85 | { |
| 86 | int i; |
Dave Jones | 87a17f3 | 2007-01-28 17:41:37 -0500 | [diff] [blame] | 87 | struct ati_page_map **tables; |
| 88 | struct ati_page_map *entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
| 90 | tables = ati_generic_private.gatt_pages; |
Dave Jones | 6a92a4e | 2006-02-28 00:54:25 -0500 | [diff] [blame] | 91 | for (i = 0; i < ati_generic_private.num_tables; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | entry = tables[i]; |
| 93 | if (entry != NULL) { |
| 94 | if (entry->real != NULL) |
| 95 | ati_free_page_map(entry); |
| 96 | kfree(entry); |
| 97 | } |
| 98 | } |
| 99 | kfree(tables); |
| 100 | } |
| 101 | |
| 102 | |
| 103 | static int ati_create_gatt_pages(int nr_tables) |
| 104 | { |
Dave Jones | 87a17f3 | 2007-01-28 17:41:37 -0500 | [diff] [blame] | 105 | struct ati_page_map **tables; |
| 106 | struct ati_page_map *entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | int retval = 0; |
| 108 | int i; |
| 109 | |
Dave Jones | 87a17f3 | 2007-01-28 17:41:37 -0500 | [diff] [blame] | 110 | tables = kzalloc((nr_tables + 1) * sizeof(struct ati_page_map *),GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | if (tables == NULL) |
| 112 | return -ENOMEM; |
| 113 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | for (i = 0; i < nr_tables; i++) { |
Dave Jones | 87a17f3 | 2007-01-28 17:41:37 -0500 | [diff] [blame] | 115 | entry = kzalloc(sizeof(struct ati_page_map), GFP_KERNEL); |
Jesper Juhl | 190644e | 2007-07-21 17:39:11 +0200 | [diff] [blame] | 116 | tables[i] = entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | if (entry == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | retval = -ENOMEM; |
| 119 | break; |
| 120 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | retval = ati_create_page_map(entry); |
Dave Jones | 7707ea3 | 2007-01-28 17:50:17 -0500 | [diff] [blame] | 122 | if (retval != 0) |
| 123 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | } |
Jesper Juhl | 190644e | 2007-07-21 17:39:11 +0200 | [diff] [blame] | 125 | ati_generic_private.num_tables = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | ati_generic_private.gatt_pages = tables; |
| 127 | |
Dave Jones | 89d17b9 | 2006-06-20 00:39:19 -0400 | [diff] [blame] | 128 | if (retval != 0) |
| 129 | ati_free_gatt_pages(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
| 131 | return retval; |
| 132 | } |
| 133 | |
| 134 | static int is_r200(void) |
| 135 | { |
| 136 | if ((agp_bridge->dev->device == PCI_DEVICE_ID_ATI_RS100) || |
| 137 | (agp_bridge->dev->device == PCI_DEVICE_ID_ATI_RS200) || |
| 138 | (agp_bridge->dev->device == PCI_DEVICE_ID_ATI_RS200_B) || |
| 139 | (agp_bridge->dev->device == PCI_DEVICE_ID_ATI_RS250)) |
| 140 | return 1; |
| 141 | return 0; |
| 142 | } |
| 143 | |
| 144 | static int ati_fetch_size(void) |
| 145 | { |
| 146 | int i; |
| 147 | u32 temp; |
| 148 | struct aper_size_info_lvl2 *values; |
| 149 | |
| 150 | if (is_r200()) |
| 151 | pci_read_config_dword(agp_bridge->dev, ATI_RS100_APSIZE, &temp); |
| 152 | else |
| 153 | pci_read_config_dword(agp_bridge->dev, ATI_RS300_APSIZE, &temp); |
| 154 | |
| 155 | temp = (temp & 0x0000000e); |
| 156 | values = A_SIZE_LVL2(agp_bridge->driver->aperture_sizes); |
| 157 | for (i = 0; i < agp_bridge->driver->num_aperture_sizes; i++) { |
| 158 | if (temp == values[i].size_value) { |
| 159 | agp_bridge->previous_size = |
| 160 | agp_bridge->current_size = (void *) (values + i); |
| 161 | |
| 162 | agp_bridge->aperture_size_idx = i; |
| 163 | return values[i].size; |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | return 0; |
| 168 | } |
| 169 | |
| 170 | static void ati_tlbflush(struct agp_memory * mem) |
| 171 | { |
| 172 | writel(1, ati_generic_private.registers+ATI_GART_CACHE_CNTRL); |
| 173 | readl(ati_generic_private.registers+ATI_GART_CACHE_CNTRL); /* PCI Posting. */ |
| 174 | } |
| 175 | |
| 176 | static void ati_cleanup(void) |
| 177 | { |
| 178 | struct aper_size_info_lvl2 *previous_size; |
| 179 | u32 temp; |
| 180 | |
| 181 | previous_size = A_SIZE_LVL2(agp_bridge->previous_size); |
| 182 | |
| 183 | /* Write back the previous size and disable gart translation */ |
| 184 | if (is_r200()) { |
| 185 | pci_read_config_dword(agp_bridge->dev, ATI_RS100_APSIZE, &temp); |
| 186 | temp = ((temp & ~(0x0000000f)) | previous_size->size_value); |
| 187 | pci_write_config_dword(agp_bridge->dev, ATI_RS100_APSIZE, temp); |
| 188 | } else { |
| 189 | pci_read_config_dword(agp_bridge->dev, ATI_RS300_APSIZE, &temp); |
| 190 | temp = ((temp & ~(0x0000000f)) | previous_size->size_value); |
| 191 | pci_write_config_dword(agp_bridge->dev, ATI_RS300_APSIZE, temp); |
| 192 | } |
| 193 | iounmap((volatile u8 __iomem *)ati_generic_private.registers); |
| 194 | } |
| 195 | |
| 196 | |
| 197 | static int ati_configure(void) |
| 198 | { |
| 199 | u32 temp; |
| 200 | |
| 201 | /* Get the memory mapped registers */ |
| 202 | pci_read_config_dword(agp_bridge->dev, ATI_GART_MMBASE_ADDR, &temp); |
| 203 | temp = (temp & 0xfffff000); |
| 204 | ati_generic_private.registers = (volatile u8 __iomem *) ioremap(temp, 4096); |
| 205 | |
Scott Thompson | 5bdbc7d | 2007-08-25 18:14:00 +1000 | [diff] [blame] | 206 | if (!ati_generic_private.registers) |
| 207 | return -ENOMEM; |
| 208 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | if (is_r200()) |
Dave Jones | 89d17b9 | 2006-06-20 00:39:19 -0400 | [diff] [blame] | 210 | pci_write_config_dword(agp_bridge->dev, ATI_RS100_IG_AGPMODE, 0x20000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | else |
| 212 | pci_write_config_dword(agp_bridge->dev, ATI_RS300_IG_AGPMODE, 0x20000); |
| 213 | |
| 214 | /* address to map too */ |
Dave Jones | 89d17b9 | 2006-06-20 00:39:19 -0400 | [diff] [blame] | 215 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | pci_read_config_dword(agp_bridge.dev, AGP_APBASE, &temp); |
| 217 | agp_bridge.gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK); |
| 218 | printk(KERN_INFO PFX "IGP320 gart_bus_addr: %x\n", agp_bridge.gart_bus_addr); |
Dave Jones | 89d17b9 | 2006-06-20 00:39:19 -0400 | [diff] [blame] | 219 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | writel(0x60000, ati_generic_private.registers+ATI_GART_FEATURE_ID); |
| 221 | readl(ati_generic_private.registers+ATI_GART_FEATURE_ID); /* PCI Posting.*/ |
| 222 | |
| 223 | /* SIGNALED_SYSTEM_ERROR @ NB_STATUS */ |
| 224 | pci_read_config_dword(agp_bridge->dev, 4, &temp); |
| 225 | pci_write_config_dword(agp_bridge->dev, 4, temp | (1<<14)); |
| 226 | |
| 227 | /* Write out the address of the gatt table */ |
| 228 | writel(agp_bridge->gatt_bus_addr, ati_generic_private.registers+ATI_GART_BASE); |
| 229 | readl(ati_generic_private.registers+ATI_GART_BASE); /* PCI Posting. */ |
| 230 | |
| 231 | return 0; |
| 232 | } |
| 233 | |
| 234 | |
akpm@osdl.org | 5dda498 | 2006-01-03 23:00:59 -0800 | [diff] [blame] | 235 | #ifdef CONFIG_PM |
akpm@osdl.org | 5dda498 | 2006-01-03 23:00:59 -0800 | [diff] [blame] | 236 | static int agp_ati_suspend(struct pci_dev *dev, pm_message_t state) |
| 237 | { |
| 238 | pci_save_state(dev); |
Dave Jones | b3818ed | 2006-06-21 13:10:26 -0400 | [diff] [blame] | 239 | pci_set_power_state(dev, 3); |
akpm@osdl.org | 5dda498 | 2006-01-03 23:00:59 -0800 | [diff] [blame] | 240 | |
| 241 | return 0; |
| 242 | } |
Dave Jones | a4aec26 | 2006-06-20 00:42:04 -0400 | [diff] [blame] | 243 | |
| 244 | static int agp_ati_resume(struct pci_dev *dev) |
| 245 | { |
Dave Jones | b3818ed | 2006-06-21 13:10:26 -0400 | [diff] [blame] | 246 | pci_set_power_state(dev, 0); |
Dave Jones | a4aec26 | 2006-06-20 00:42:04 -0400 | [diff] [blame] | 247 | pci_restore_state(dev); |
| 248 | |
| 249 | return ati_configure(); |
| 250 | } |
akpm@osdl.org | 5dda498 | 2006-01-03 23:00:59 -0800 | [diff] [blame] | 251 | #endif |
| 252 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | /* |
Andreas Mohr | d6e05ed | 2006-06-26 18:35:02 +0200 | [diff] [blame] | 254 | *Since we don't need contiguous memory we just try |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | * to get the gatt table once |
| 256 | */ |
| 257 | |
| 258 | #define GET_PAGE_DIR_OFF(addr) (addr >> 22) |
| 259 | #define GET_PAGE_DIR_IDX(addr) (GET_PAGE_DIR_OFF(addr) - \ |
| 260 | GET_PAGE_DIR_OFF(agp_bridge->gart_bus_addr)) |
| 261 | #define GET_GATT_OFF(addr) ((addr & 0x003ff000) >> 12) |
| 262 | #undef GET_GATT |
| 263 | #define GET_GATT(addr) (ati_generic_private.gatt_pages[\ |
| 264 | GET_PAGE_DIR_IDX(addr)]->remapped) |
| 265 | |
| 266 | static int ati_insert_memory(struct agp_memory * mem, |
| 267 | off_t pg_start, int type) |
| 268 | { |
| 269 | int i, j, num_entries; |
| 270 | unsigned long __iomem *cur_gatt; |
| 271 | unsigned long addr; |
| 272 | |
| 273 | num_entries = A_SIZE_LVL2(agp_bridge->current_size)->num_entries; |
| 274 | |
| 275 | if (type != 0 || mem->type != 0) |
| 276 | return -EINVAL; |
| 277 | |
| 278 | if ((pg_start + mem->page_count) > num_entries) |
| 279 | return -EINVAL; |
| 280 | |
| 281 | j = pg_start; |
| 282 | while (j < (pg_start + mem->page_count)) { |
| 283 | addr = (j * PAGE_SIZE) + agp_bridge->gart_bus_addr; |
| 284 | cur_gatt = GET_GATT(addr); |
| 285 | if (!PGE_EMPTY(agp_bridge,readl(cur_gatt+GET_GATT_OFF(addr)))) |
| 286 | return -EBUSY; |
| 287 | j++; |
| 288 | } |
| 289 | |
| 290 | if (mem->is_flushed == FALSE) { |
| 291 | /*CACHE_FLUSH(); */ |
| 292 | global_cache_flush(); |
| 293 | mem->is_flushed = TRUE; |
| 294 | } |
| 295 | |
| 296 | for (i = 0, j = pg_start; i < mem->page_count; i++, j++) { |
| 297 | addr = (j * PAGE_SIZE) + agp_bridge->gart_bus_addr; |
| 298 | cur_gatt = GET_GATT(addr); |
| 299 | writel(agp_bridge->driver->mask_memory(agp_bridge, |
| 300 | mem->memory[i], mem->type), cur_gatt+GET_GATT_OFF(addr)); |
| 301 | readl(cur_gatt+GET_GATT_OFF(addr)); /* PCI Posting. */ |
| 302 | } |
| 303 | agp_bridge->driver->tlb_flush(mem); |
| 304 | return 0; |
| 305 | } |
| 306 | |
| 307 | static int ati_remove_memory(struct agp_memory * mem, off_t pg_start, |
| 308 | int type) |
| 309 | { |
| 310 | int i; |
| 311 | unsigned long __iomem *cur_gatt; |
| 312 | unsigned long addr; |
| 313 | |
Dave Jones | 89d17b9 | 2006-06-20 00:39:19 -0400 | [diff] [blame] | 314 | if (type != 0 || mem->type != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | return -EINVAL; |
Dave Jones | 89d17b9 | 2006-06-20 00:39:19 -0400 | [diff] [blame] | 316 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | for (i = pg_start; i < (mem->page_count + pg_start); i++) { |
| 318 | addr = (i * PAGE_SIZE) + agp_bridge->gart_bus_addr; |
| 319 | cur_gatt = GET_GATT(addr); |
| 320 | writel(agp_bridge->scratch_page, cur_gatt+GET_GATT_OFF(addr)); |
| 321 | readl(cur_gatt+GET_GATT_OFF(addr)); /* PCI Posting. */ |
| 322 | } |
| 323 | |
| 324 | agp_bridge->driver->tlb_flush(mem); |
| 325 | return 0; |
| 326 | } |
| 327 | |
| 328 | static int ati_create_gatt_table(struct agp_bridge_data *bridge) |
| 329 | { |
| 330 | struct aper_size_info_lvl2 *value; |
Dave Jones | 87a17f3 | 2007-01-28 17:41:37 -0500 | [diff] [blame] | 331 | struct ati_page_map page_dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | unsigned long addr; |
| 333 | int retval; |
| 334 | u32 temp; |
| 335 | int i; |
| 336 | struct aper_size_info_lvl2 *current_size; |
| 337 | |
| 338 | value = A_SIZE_LVL2(agp_bridge->current_size); |
| 339 | retval = ati_create_page_map(&page_dir); |
| 340 | if (retval != 0) |
| 341 | return retval; |
| 342 | |
| 343 | retval = ati_create_gatt_pages(value->num_entries / 1024); |
| 344 | if (retval != 0) { |
| 345 | ati_free_page_map(&page_dir); |
| 346 | return retval; |
| 347 | } |
| 348 | |
| 349 | agp_bridge->gatt_table_real = (u32 *)page_dir.real; |
| 350 | agp_bridge->gatt_table = (u32 __iomem *) page_dir.remapped; |
Keir Fraser | 07eee78 | 2005-03-30 13:17:04 -0800 | [diff] [blame] | 351 | agp_bridge->gatt_bus_addr = virt_to_gart(page_dir.real); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | |
| 353 | /* Write out the size register */ |
| 354 | current_size = A_SIZE_LVL2(agp_bridge->current_size); |
| 355 | |
| 356 | if (is_r200()) { |
| 357 | pci_read_config_dword(agp_bridge->dev, ATI_RS100_APSIZE, &temp); |
| 358 | temp = (((temp & ~(0x0000000e)) | current_size->size_value) |
| 359 | | 0x00000001); |
| 360 | pci_write_config_dword(agp_bridge->dev, ATI_RS100_APSIZE, temp); |
| 361 | pci_read_config_dword(agp_bridge->dev, ATI_RS100_APSIZE, &temp); |
| 362 | } else { |
| 363 | pci_read_config_dword(agp_bridge->dev, ATI_RS300_APSIZE, &temp); |
| 364 | temp = (((temp & ~(0x0000000e)) | current_size->size_value) |
| 365 | | 0x00000001); |
| 366 | pci_write_config_dword(agp_bridge->dev, ATI_RS300_APSIZE, temp); |
| 367 | pci_read_config_dword(agp_bridge->dev, ATI_RS300_APSIZE, &temp); |
| 368 | } |
| 369 | |
| 370 | /* |
| 371 | * Get the address for the gart region. |
| 372 | * This is a bus address even on the alpha, b/c its |
| 373 | * used to program the agp master not the cpu |
| 374 | */ |
| 375 | pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp); |
| 376 | addr = (temp & PCI_BASE_ADDRESS_MEM_MASK); |
| 377 | agp_bridge->gart_bus_addr = addr; |
| 378 | |
| 379 | /* Calculate the agp offset */ |
Dave Jones | 6a92a4e | 2006-02-28 00:54:25 -0500 | [diff] [blame] | 380 | for (i = 0; i < value->num_entries / 1024; i++, addr += 0x00400000) { |
Keir Fraser | 07eee78 | 2005-03-30 13:17:04 -0800 | [diff] [blame] | 381 | writel(virt_to_gart(ati_generic_private.gatt_pages[i]->real) | 1, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | page_dir.remapped+GET_PAGE_DIR_OFF(addr)); |
| 383 | readl(page_dir.remapped+GET_PAGE_DIR_OFF(addr)); /* PCI Posting. */ |
| 384 | } |
| 385 | |
| 386 | return 0; |
| 387 | } |
| 388 | |
| 389 | static int ati_free_gatt_table(struct agp_bridge_data *bridge) |
| 390 | { |
Dave Jones | 87a17f3 | 2007-01-28 17:41:37 -0500 | [diff] [blame] | 391 | struct ati_page_map page_dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | |
| 393 | page_dir.real = (unsigned long *)agp_bridge->gatt_table_real; |
| 394 | page_dir.remapped = (unsigned long __iomem *)agp_bridge->gatt_table; |
| 395 | |
| 396 | ati_free_gatt_pages(); |
| 397 | ati_free_page_map(&page_dir); |
| 398 | return 0; |
| 399 | } |
| 400 | |
Dave Jones | e5524f3 | 2007-02-22 18:41:28 -0500 | [diff] [blame] | 401 | static const struct agp_bridge_driver ati_generic_bridge = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | .owner = THIS_MODULE, |
| 403 | .aperture_sizes = ati_generic_sizes, |
| 404 | .size_type = LVL2_APER_SIZE, |
| 405 | .num_aperture_sizes = 7, |
| 406 | .configure = ati_configure, |
| 407 | .fetch_size = ati_fetch_size, |
| 408 | .cleanup = ati_cleanup, |
| 409 | .tlb_flush = ati_tlbflush, |
| 410 | .mask_memory = agp_generic_mask_memory, |
| 411 | .masks = ati_generic_masks, |
| 412 | .agp_enable = agp_generic_enable, |
| 413 | .cache_flush = global_cache_flush, |
| 414 | .create_gatt_table = ati_create_gatt_table, |
| 415 | .free_gatt_table = ati_free_gatt_table, |
| 416 | .insert_memory = ati_insert_memory, |
| 417 | .remove_memory = ati_remove_memory, |
| 418 | .alloc_by_type = agp_generic_alloc_by_type, |
| 419 | .free_by_type = agp_generic_free_by_type, |
| 420 | .agp_alloc_page = agp_generic_alloc_page, |
| 421 | .agp_destroy_page = agp_generic_destroy_page, |
Thomas Hellstrom | a030ce4 | 2007-01-23 10:33:43 +0100 | [diff] [blame] | 422 | .agp_type_to_mask_type = agp_generic_type_to_mask_type, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | }; |
| 424 | |
| 425 | |
| 426 | static struct agp_device_ids ati_agp_device_ids[] __devinitdata = |
| 427 | { |
| 428 | { |
| 429 | .device_id = PCI_DEVICE_ID_ATI_RS100, |
| 430 | .chipset_name = "IGP320/M", |
| 431 | }, |
| 432 | { |
| 433 | .device_id = PCI_DEVICE_ID_ATI_RS200, |
| 434 | .chipset_name = "IGP330/340/345/350/M", |
| 435 | }, |
| 436 | { |
| 437 | .device_id = PCI_DEVICE_ID_ATI_RS200_B, |
| 438 | .chipset_name = "IGP345M", |
| 439 | }, |
| 440 | { |
| 441 | .device_id = PCI_DEVICE_ID_ATI_RS250, |
| 442 | .chipset_name = "IGP7000/M", |
| 443 | }, |
| 444 | { |
| 445 | .device_id = PCI_DEVICE_ID_ATI_RS300_100, |
| 446 | .chipset_name = "IGP9100/M", |
| 447 | }, |
| 448 | { |
| 449 | .device_id = PCI_DEVICE_ID_ATI_RS300_133, |
| 450 | .chipset_name = "IGP9100/M", |
| 451 | }, |
| 452 | { |
| 453 | .device_id = PCI_DEVICE_ID_ATI_RS300_166, |
| 454 | .chipset_name = "IGP9100/M", |
| 455 | }, |
| 456 | { |
| 457 | .device_id = PCI_DEVICE_ID_ATI_RS300_200, |
| 458 | .chipset_name = "IGP9100/M", |
| 459 | }, |
Dave Jones | 9d1ef8a | 2006-03-01 14:23:14 -0500 | [diff] [blame] | 460 | { |
| 461 | .device_id = PCI_DEVICE_ID_ATI_RS350_200, |
| 462 | .chipset_name = "IGP9100/M", |
| 463 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | { }, /* dummy final entry, always present */ |
| 465 | }; |
| 466 | |
| 467 | static int __devinit agp_ati_probe(struct pci_dev *pdev, |
| 468 | const struct pci_device_id *ent) |
| 469 | { |
| 470 | struct agp_device_ids *devs = ati_agp_device_ids; |
| 471 | struct agp_bridge_data *bridge; |
| 472 | u8 cap_ptr; |
| 473 | int j; |
| 474 | |
| 475 | cap_ptr = pci_find_capability(pdev, PCI_CAP_ID_AGP); |
| 476 | if (!cap_ptr) |
| 477 | return -ENODEV; |
| 478 | |
| 479 | /* probe for known chipsets */ |
| 480 | for (j = 0; devs[j].chipset_name; j++) { |
| 481 | if (pdev->device == devs[j].device_id) |
| 482 | goto found; |
| 483 | } |
| 484 | |
| 485 | printk(KERN_ERR PFX |
| 486 | "Unsupported Ati chipset (device id: %04x)\n", pdev->device); |
| 487 | return -ENODEV; |
| 488 | |
| 489 | found: |
| 490 | bridge = agp_alloc_bridge(); |
| 491 | if (!bridge) |
| 492 | return -ENOMEM; |
| 493 | |
| 494 | bridge->dev = pdev; |
| 495 | bridge->capndx = cap_ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | |
Dave Jones | 89d17b9 | 2006-06-20 00:39:19 -0400 | [diff] [blame] | 497 | bridge->driver = &ati_generic_bridge; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | |
| 499 | printk(KERN_INFO PFX "Detected Ati %s chipset\n", |
| 500 | devs[j].chipset_name); |
| 501 | |
| 502 | /* Fill in the mode register */ |
| 503 | pci_read_config_dword(pdev, |
| 504 | bridge->capndx+PCI_AGP_STATUS, |
| 505 | &bridge->mode); |
| 506 | |
| 507 | pci_set_drvdata(pdev, bridge); |
| 508 | return agp_add_bridge(bridge); |
| 509 | } |
| 510 | |
| 511 | static void __devexit agp_ati_remove(struct pci_dev *pdev) |
| 512 | { |
| 513 | struct agp_bridge_data *bridge = pci_get_drvdata(pdev); |
| 514 | |
| 515 | agp_remove_bridge(bridge); |
| 516 | agp_put_bridge(bridge); |
| 517 | } |
| 518 | |
| 519 | static struct pci_device_id agp_ati_pci_table[] = { |
| 520 | { |
| 521 | .class = (PCI_CLASS_BRIDGE_HOST << 8), |
| 522 | .class_mask = ~0, |
| 523 | .vendor = PCI_VENDOR_ID_ATI, |
| 524 | .device = PCI_ANY_ID, |
| 525 | .subvendor = PCI_ANY_ID, |
| 526 | .subdevice = PCI_ANY_ID, |
| 527 | }, |
| 528 | { } |
| 529 | }; |
| 530 | |
| 531 | MODULE_DEVICE_TABLE(pci, agp_ati_pci_table); |
| 532 | |
| 533 | static struct pci_driver agp_ati_pci_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | .name = "agpgart-ati", |
| 535 | .id_table = agp_ati_pci_table, |
| 536 | .probe = agp_ati_probe, |
| 537 | .remove = agp_ati_remove, |
akpm@osdl.org | 5dda498 | 2006-01-03 23:00:59 -0800 | [diff] [blame] | 538 | #ifdef CONFIG_PM |
akpm@osdl.org | 5dda498 | 2006-01-03 23:00:59 -0800 | [diff] [blame] | 539 | .suspend = agp_ati_suspend, |
Dave Jones | a4aec26 | 2006-06-20 00:42:04 -0400 | [diff] [blame] | 540 | .resume = agp_ati_resume, |
akpm@osdl.org | 5dda498 | 2006-01-03 23:00:59 -0800 | [diff] [blame] | 541 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | }; |
| 543 | |
| 544 | static int __init agp_ati_init(void) |
| 545 | { |
| 546 | if (agp_off) |
| 547 | return -EINVAL; |
| 548 | return pci_register_driver(&agp_ati_pci_driver); |
| 549 | } |
| 550 | |
| 551 | static void __exit agp_ati_cleanup(void) |
| 552 | { |
| 553 | pci_unregister_driver(&agp_ati_pci_driver); |
| 554 | } |
| 555 | |
| 556 | module_init(agp_ati_init); |
| 557 | module_exit(agp_ati_cleanup); |
| 558 | |
| 559 | MODULE_AUTHOR("Dave Jones <davej@codemonkey.org.uk>"); |
| 560 | MODULE_LICENSE("GPL and additional rights"); |
| 561 | |