blob: 75a9786a77e6307711a74bcde8f4dd7fee8fcae0 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Schmielau4e57b682005-10-30 15:03:48 -08009#include <linux/string.h>
10#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/agp_backend.h>
12#include <asm/agp.h>
13#include "agp.h"
14
Bjorn Helgaasd68c5a22014-01-06 15:21:16 -070015#define ATI_GART_MMBASE_BAR 1
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#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 Jonese5524f32007-02-22 18:41:28 -050027static const struct aper_size_info_lvl2 ati_generic_sizes[7] =
Linus Torvalds1da177e2005-04-16 15:20:36 -070028{
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
38static struct gatt_mask ati_generic_masks[] =
39{
40 { .mask = 1, .type = 0}
41};
42
43
Dave Jones87a17f32007-01-28 17:41:37 -050044struct ati_page_map {
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 unsigned long *real;
46 unsigned long __iomem *remapped;
Dave Jones87a17f32007-01-28 17:41:37 -050047};
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
49static struct _ati_generic_private {
50 volatile u8 __iomem *registers;
Dave Jones87a17f32007-01-28 17:41:37 -050051 struct ati_page_map **gatt_pages;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 int num_tables;
53} ati_generic_private;
54
Dave Jones87a17f32007-01-28 17:41:37 -050055static int ati_create_page_map(struct ati_page_map *page_map)
Linus Torvalds1da177e2005-04-16 15:20:36 -070056{
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 Airlie44a207f2008-02-20 10:37:08 +100063 set_memory_uc((unsigned long)page_map->real, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 err = map_page_into_agp(virt_to_page(page_map->real));
Arjan van dev Venfcea4242008-02-06 05:16:00 +010065 page_map->remapped = page_map->real;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
Dave Jones6a92a4e2006-02-28 00:54:25 -050067 for (i = 0; i < PAGE_SIZE / sizeof(unsigned long); i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 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 Jones87a17f32007-01-28 17:41:37 -050076static void ati_free_page_map(struct ati_page_map *page_map)
Linus Torvalds1da177e2005-04-16 15:20:36 -070077{
78 unmap_page_from_agp(virt_to_page(page_map->real));
Dave Airlie44a207f2008-02-20 10:37:08 +100079 set_memory_wb((unsigned long)page_map->real, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 free_page((unsigned long) page_map->real);
81}
82
83
84static void ati_free_gatt_pages(void)
85{
86 int i;
Dave Jones87a17f32007-01-28 17:41:37 -050087 struct ati_page_map **tables;
88 struct ati_page_map *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
90 tables = ati_generic_private.gatt_pages;
Dave Jones6a92a4e2006-02-28 00:54:25 -050091 for (i = 0; i < ati_generic_private.num_tables; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 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
103static int ati_create_gatt_pages(int nr_tables)
104{
Dave Jones87a17f32007-01-28 17:41:37 -0500105 struct ati_page_map **tables;
106 struct ati_page_map *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 int retval = 0;
108 int i;
109
Dave Jones87a17f32007-01-28 17:41:37 -0500110 tables = kzalloc((nr_tables + 1) * sizeof(struct ati_page_map *),GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 if (tables == NULL)
112 return -ENOMEM;
113
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 for (i = 0; i < nr_tables; i++) {
Dave Jones87a17f32007-01-28 17:41:37 -0500115 entry = kzalloc(sizeof(struct ati_page_map), GFP_KERNEL);
Jesper Juhl190644e2007-07-21 17:39:11 +0200116 tables[i] = entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 if (entry == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 retval = -ENOMEM;
119 break;
120 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 retval = ati_create_page_map(entry);
Dave Jones7707ea32007-01-28 17:50:17 -0500122 if (retval != 0)
123 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 }
Jesper Juhl190644e2007-07-21 17:39:11 +0200125 ati_generic_private.num_tables = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 ati_generic_private.gatt_pages = tables;
127
Dave Jones89d17b92006-06-20 00:39:19 -0400128 if (retval != 0)
129 ati_free_gatt_pages();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
131 return retval;
132}
133
134static 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
144static 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
170static 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
176static 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
197static int ati_configure(void)
198{
Bjorn Helgaasd68c5a22014-01-06 15:21:16 -0700199 phys_addr_t reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 u32 temp;
201
202 /* Get the memory mapped registers */
Bjorn Helgaasd68c5a22014-01-06 15:21:16 -0700203 reg = pci_resource_start(agp_bridge->dev, ATI_GART_MMBASE_BAR);
204 ati_generic_private.registers = (volatile u8 __iomem *) ioremap(reg, 4096);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
Scott Thompson5bdbc7d2007-08-25 18:14:00 +1000206 if (!ati_generic_private.registers)
207 return -ENOMEM;
208
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 if (is_r200())
Dave Jones89d17b92006-06-20 00:39:19 -0400210 pci_write_config_dword(agp_bridge->dev, ATI_RS100_IG_AGPMODE, 0x20000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 else
212 pci_write_config_dword(agp_bridge->dev, ATI_RS300_IG_AGPMODE, 0x20000);
213
Bjorn Helgaase501b3d2014-01-03 18:26:58 -0700214 /* address to map to */
Dave Jones89d17b92006-06-20 00:39:19 -0400215 /*
Bjorn Helgaase501b3d2014-01-03 18:26:58 -0700216 agp_bridge.gart_bus_addr = pci_bus_address(agp_bridge.dev,
217 AGP_APERTURE_BAR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 printk(KERN_INFO PFX "IGP320 gart_bus_addr: %x\n", agp_bridge.gart_bus_addr);
Dave Jones89d17b92006-06-20 00:39:19 -0400219 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 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 */
Bjorn Helgaas167b1f02014-01-06 16:15:31 -0700224 pci_read_config_dword(agp_bridge->dev, PCI_COMMAND, &temp);
225 pci_write_config_dword(agp_bridge->dev, PCI_COMMAND, temp | (1<<14));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226
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.org5dda4982006-01-03 23:00:59 -0800235#ifdef CONFIG_PM
akpm@osdl.org5dda4982006-01-03 23:00:59 -0800236static int agp_ati_suspend(struct pci_dev *dev, pm_message_t state)
237{
238 pci_save_state(dev);
Yijing Wang43355502013-06-27 20:52:36 +0800239 pci_set_power_state(dev, PCI_D3hot);
akpm@osdl.org5dda4982006-01-03 23:00:59 -0800240
241 return 0;
242}
Dave Jonesa4aec262006-06-20 00:42:04 -0400243
244static int agp_ati_resume(struct pci_dev *dev)
245{
Yijing Wang43355502013-06-27 20:52:36 +0800246 pci_set_power_state(dev, PCI_D0);
Dave Jonesa4aec262006-06-20 00:42:04 -0400247 pci_restore_state(dev);
248
249 return ati_configure();
250}
akpm@osdl.org5dda4982006-01-03 23:00:59 -0800251#endif
252
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253/*
Andreas Mohrd6e05ed2006-06-26 18:35:02 +0200254 *Since we don't need contiguous memory we just try
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 * 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
266static 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;
Dave Airliea95fe462009-06-19 10:52:57 +1000272 int mask_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
274 num_entries = A_SIZE_LVL2(agp_bridge->current_size)->num_entries;
275
Dave Airliea95fe462009-06-19 10:52:57 +1000276 mask_type = agp_generic_type_to_mask_type(mem->bridge, type);
277 if (mask_type != 0 || type != mem->type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 return -EINVAL;
279
Dave Airliea95fe462009-06-19 10:52:57 +1000280 if (mem->page_count == 0)
281 return 0;
282
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 if ((pg_start + mem->page_count) > num_entries)
284 return -EINVAL;
285
286 j = pg_start;
287 while (j < (pg_start + mem->page_count)) {
288 addr = (j * PAGE_SIZE) + agp_bridge->gart_bus_addr;
289 cur_gatt = GET_GATT(addr);
290 if (!PGE_EMPTY(agp_bridge,readl(cur_gatt+GET_GATT_OFF(addr))))
291 return -EBUSY;
292 j++;
293 }
294
Joe Perchesc7258012008-03-26 14:10:02 -0700295 if (!mem->is_flushed) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 /*CACHE_FLUSH(); */
297 global_cache_flush();
Joe Perchesc7258012008-03-26 14:10:02 -0700298 mem->is_flushed = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 }
300
301 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
302 addr = (j * PAGE_SIZE) + agp_bridge->gart_bus_addr;
303 cur_gatt = GET_GATT(addr);
Dave Airlie07613ba2009-06-12 14:11:41 +1000304 writel(agp_bridge->driver->mask_memory(agp_bridge,
David Woodhouse6a122352009-07-29 10:25:58 +0100305 page_to_phys(mem->pages[i]),
David Woodhouse2a4ceb62009-07-27 10:27:29 +0100306 mem->type),
Dave Airlie07613ba2009-06-12 14:11:41 +1000307 cur_gatt+GET_GATT_OFF(addr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 }
Dave Airliea95fe462009-06-19 10:52:57 +1000309 readl(GET_GATT(agp_bridge->gart_bus_addr)); /* PCI posting */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 agp_bridge->driver->tlb_flush(mem);
311 return 0;
312}
313
314static int ati_remove_memory(struct agp_memory * mem, off_t pg_start,
315 int type)
316{
317 int i;
318 unsigned long __iomem *cur_gatt;
319 unsigned long addr;
Dave Airliea95fe462009-06-19 10:52:57 +1000320 int mask_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
Dave Airliea95fe462009-06-19 10:52:57 +1000322 mask_type = agp_generic_type_to_mask_type(mem->bridge, type);
323 if (mask_type != 0 || type != mem->type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 return -EINVAL;
Dave Jones89d17b92006-06-20 00:39:19 -0400325
Dave Airliea95fe462009-06-19 10:52:57 +1000326 if (mem->page_count == 0)
327 return 0;
328
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 for (i = pg_start; i < (mem->page_count + pg_start); i++) {
330 addr = (i * PAGE_SIZE) + agp_bridge->gart_bus_addr;
331 cur_gatt = GET_GATT(addr);
332 writel(agp_bridge->scratch_page, cur_gatt+GET_GATT_OFF(addr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 }
334
Dave Airliea95fe462009-06-19 10:52:57 +1000335 readl(GET_GATT(agp_bridge->gart_bus_addr)); /* PCI posting */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 agp_bridge->driver->tlb_flush(mem);
337 return 0;
338}
339
340static int ati_create_gatt_table(struct agp_bridge_data *bridge)
341{
342 struct aper_size_info_lvl2 *value;
Dave Jones87a17f32007-01-28 17:41:37 -0500343 struct ati_page_map page_dir;
Jerome Glisse61cf0592010-04-20 17:43:34 +0200344 unsigned long __iomem *cur_gatt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 unsigned long addr;
346 int retval;
347 u32 temp;
348 int i;
349 struct aper_size_info_lvl2 *current_size;
350
351 value = A_SIZE_LVL2(agp_bridge->current_size);
352 retval = ati_create_page_map(&page_dir);
353 if (retval != 0)
354 return retval;
355
356 retval = ati_create_gatt_pages(value->num_entries / 1024);
357 if (retval != 0) {
358 ati_free_page_map(&page_dir);
359 return retval;
360 }
361
362 agp_bridge->gatt_table_real = (u32 *)page_dir.real;
363 agp_bridge->gatt_table = (u32 __iomem *) page_dir.remapped;
David Woodhouse6a122352009-07-29 10:25:58 +0100364 agp_bridge->gatt_bus_addr = virt_to_phys(page_dir.real);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365
366 /* Write out the size register */
367 current_size = A_SIZE_LVL2(agp_bridge->current_size);
368
369 if (is_r200()) {
370 pci_read_config_dword(agp_bridge->dev, ATI_RS100_APSIZE, &temp);
371 temp = (((temp & ~(0x0000000e)) | current_size->size_value)
372 | 0x00000001);
373 pci_write_config_dword(agp_bridge->dev, ATI_RS100_APSIZE, temp);
374 pci_read_config_dword(agp_bridge->dev, ATI_RS100_APSIZE, &temp);
375 } else {
376 pci_read_config_dword(agp_bridge->dev, ATI_RS300_APSIZE, &temp);
377 temp = (((temp & ~(0x0000000e)) | current_size->size_value)
378 | 0x00000001);
379 pci_write_config_dword(agp_bridge->dev, ATI_RS300_APSIZE, temp);
380 pci_read_config_dword(agp_bridge->dev, ATI_RS300_APSIZE, &temp);
381 }
382
383 /*
384 * Get the address for the gart region.
385 * This is a bus address even on the alpha, b/c its
386 * used to program the agp master not the cpu
387 */
Bjorn Helgaase501b3d2014-01-03 18:26:58 -0700388 addr = pci_bus_address(agp_bridge->dev, AGP_APERTURE_BAR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 agp_bridge->gart_bus_addr = addr;
390
391 /* Calculate the agp offset */
Dave Jones6a92a4e2006-02-28 00:54:25 -0500392 for (i = 0; i < value->num_entries / 1024; i++, addr += 0x00400000) {
David Woodhouse6a122352009-07-29 10:25:58 +0100393 writel(virt_to_phys(ati_generic_private.gatt_pages[i]->real) | 1,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 page_dir.remapped+GET_PAGE_DIR_OFF(addr));
395 readl(page_dir.remapped+GET_PAGE_DIR_OFF(addr)); /* PCI Posting. */
396 }
397
Jerome Glisse61cf0592010-04-20 17:43:34 +0200398 for (i = 0; i < value->num_entries; i++) {
399 addr = (i * PAGE_SIZE) + agp_bridge->gart_bus_addr;
400 cur_gatt = GET_GATT(addr);
401 writel(agp_bridge->scratch_page, cur_gatt+GET_GATT_OFF(addr));
402 }
403
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 return 0;
405}
406
407static int ati_free_gatt_table(struct agp_bridge_data *bridge)
408{
Dave Jones87a17f32007-01-28 17:41:37 -0500409 struct ati_page_map page_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
411 page_dir.real = (unsigned long *)agp_bridge->gatt_table_real;
412 page_dir.remapped = (unsigned long __iomem *)agp_bridge->gatt_table;
413
414 ati_free_gatt_pages();
415 ati_free_page_map(&page_dir);
416 return 0;
417}
418
Dave Jonese5524f32007-02-22 18:41:28 -0500419static const struct agp_bridge_driver ati_generic_bridge = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 .owner = THIS_MODULE,
421 .aperture_sizes = ati_generic_sizes,
422 .size_type = LVL2_APER_SIZE,
423 .num_aperture_sizes = 7,
Jerome Glisse61cf0592010-04-20 17:43:34 +0200424 .needs_scratch_page = true,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 .configure = ati_configure,
426 .fetch_size = ati_fetch_size,
427 .cleanup = ati_cleanup,
428 .tlb_flush = ati_tlbflush,
429 .mask_memory = agp_generic_mask_memory,
430 .masks = ati_generic_masks,
431 .agp_enable = agp_generic_enable,
432 .cache_flush = global_cache_flush,
433 .create_gatt_table = ati_create_gatt_table,
434 .free_gatt_table = ati_free_gatt_table,
435 .insert_memory = ati_insert_memory,
436 .remove_memory = ati_remove_memory,
437 .alloc_by_type = agp_generic_alloc_by_type,
438 .free_by_type = agp_generic_free_by_type,
439 .agp_alloc_page = agp_generic_alloc_page,
Rene Herman5f310b62008-08-21 19:15:46 +0200440 .agp_alloc_pages = agp_generic_alloc_pages,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 .agp_destroy_page = agp_generic_destroy_page,
Rene Herman5f310b62008-08-21 19:15:46 +0200442 .agp_destroy_pages = agp_generic_destroy_pages,
Thomas Hellstroma030ce42007-01-23 10:33:43 +0100443 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444};
445
446
Bill Pemberton0bbed202012-11-19 13:24:36 -0500447static struct agp_device_ids ati_agp_device_ids[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448{
449 {
450 .device_id = PCI_DEVICE_ID_ATI_RS100,
451 .chipset_name = "IGP320/M",
452 },
453 {
454 .device_id = PCI_DEVICE_ID_ATI_RS200,
455 .chipset_name = "IGP330/340/345/350/M",
456 },
457 {
458 .device_id = PCI_DEVICE_ID_ATI_RS200_B,
459 .chipset_name = "IGP345M",
460 },
461 {
462 .device_id = PCI_DEVICE_ID_ATI_RS250,
463 .chipset_name = "IGP7000/M",
464 },
465 {
466 .device_id = PCI_DEVICE_ID_ATI_RS300_100,
467 .chipset_name = "IGP9100/M",
468 },
469 {
470 .device_id = PCI_DEVICE_ID_ATI_RS300_133,
471 .chipset_name = "IGP9100/M",
472 },
473 {
474 .device_id = PCI_DEVICE_ID_ATI_RS300_166,
475 .chipset_name = "IGP9100/M",
476 },
477 {
478 .device_id = PCI_DEVICE_ID_ATI_RS300_200,
479 .chipset_name = "IGP9100/M",
480 },
Dave Jones9d1ef8a2006-03-01 14:23:14 -0500481 {
Amit Kucheriadf0bcab2008-06-12 15:21:26 -0700482 .device_id = PCI_DEVICE_ID_ATI_RS350_133,
483 .chipset_name = "IGP9000/M",
484 },
485 {
Dave Jones9d1ef8a2006-03-01 14:23:14 -0500486 .device_id = PCI_DEVICE_ID_ATI_RS350_200,
487 .chipset_name = "IGP9100/M",
488 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 { }, /* dummy final entry, always present */
490};
491
Greg Kroah-Hartmanbcd29822012-12-21 15:12:08 -0800492static int agp_ati_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493{
494 struct agp_device_ids *devs = ati_agp_device_ids;
495 struct agp_bridge_data *bridge;
496 u8 cap_ptr;
497 int j;
498
499 cap_ptr = pci_find_capability(pdev, PCI_CAP_ID_AGP);
500 if (!cap_ptr)
501 return -ENODEV;
502
503 /* probe for known chipsets */
504 for (j = 0; devs[j].chipset_name; j++) {
505 if (pdev->device == devs[j].device_id)
506 goto found;
507 }
508
Bjorn Helgaase3cf6952008-07-30 12:26:51 -0700509 dev_err(&pdev->dev, "unsupported Ati chipset [%04x/%04x])\n",
510 pdev->vendor, pdev->device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 return -ENODEV;
512
513found:
514 bridge = agp_alloc_bridge();
515 if (!bridge)
516 return -ENOMEM;
517
518 bridge->dev = pdev;
519 bridge->capndx = cap_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520
Dave Jones89d17b92006-06-20 00:39:19 -0400521 bridge->driver = &ati_generic_bridge;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522
Bjorn Helgaase3cf6952008-07-30 12:26:51 -0700523 dev_info(&pdev->dev, "Ati %s chipset\n", devs[j].chipset_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524
525 /* Fill in the mode register */
526 pci_read_config_dword(pdev,
527 bridge->capndx+PCI_AGP_STATUS,
528 &bridge->mode);
529
530 pci_set_drvdata(pdev, bridge);
531 return agp_add_bridge(bridge);
532}
533
Bill Pemberton39af33f2012-11-19 13:26:26 -0500534static void agp_ati_remove(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535{
536 struct agp_bridge_data *bridge = pci_get_drvdata(pdev);
537
538 agp_remove_bridge(bridge);
539 agp_put_bridge(bridge);
540}
541
542static struct pci_device_id agp_ati_pci_table[] = {
543 {
544 .class = (PCI_CLASS_BRIDGE_HOST << 8),
545 .class_mask = ~0,
546 .vendor = PCI_VENDOR_ID_ATI,
547 .device = PCI_ANY_ID,
548 .subvendor = PCI_ANY_ID,
549 .subdevice = PCI_ANY_ID,
550 },
551 { }
552};
553
554MODULE_DEVICE_TABLE(pci, agp_ati_pci_table);
555
556static struct pci_driver agp_ati_pci_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 .name = "agpgart-ati",
558 .id_table = agp_ati_pci_table,
559 .probe = agp_ati_probe,
560 .remove = agp_ati_remove,
akpm@osdl.org5dda4982006-01-03 23:00:59 -0800561#ifdef CONFIG_PM
akpm@osdl.org5dda4982006-01-03 23:00:59 -0800562 .suspend = agp_ati_suspend,
Dave Jonesa4aec262006-06-20 00:42:04 -0400563 .resume = agp_ati_resume,
akpm@osdl.org5dda4982006-01-03 23:00:59 -0800564#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565};
566
567static int __init agp_ati_init(void)
568{
569 if (agp_off)
570 return -EINVAL;
571 return pci_register_driver(&agp_ati_pci_driver);
572}
573
574static void __exit agp_ati_cleanup(void)
575{
576 pci_unregister_driver(&agp_ati_pci_driver);
577}
578
579module_init(agp_ati_init);
580module_exit(agp_ati_cleanup);
581
Dave Jonesbd8136d2014-12-19 11:23:50 -0500582MODULE_AUTHOR("Dave Jones");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583MODULE_LICENSE("GPL and additional rights");
584