GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / drivers / char / agp / via-agp.c
blob1cdb8b1f535b6c06d77f250c03147dba31feb486
1 /*
2 * VIA AGPGART routines.
3 */
5 #include <linux/types.h>
6 #include <linux/module.h>
7 #include <linux/pci.h>
8 #include <linux/init.h>
9 #include <linux/agp_backend.h>
10 #include "agp.h"
12 static const struct pci_device_id agp_via_pci_table[];
14 #define VIA_GARTCTRL 0x80
15 #define VIA_APSIZE 0x84
16 #define VIA_ATTBASE 0x88
18 #define VIA_AGP3_GARTCTRL 0x90
19 #define VIA_AGP3_APSIZE 0x94
20 #define VIA_AGP3_ATTBASE 0x98
21 #define VIA_AGPSEL 0xfd
23 static int via_fetch_size(void)
25 int i;
26 u8 temp;
27 struct aper_size_info_8 *values;
29 values = A_SIZE_8(agp_bridge->driver->aperture_sizes);
30 pci_read_config_byte(agp_bridge->dev, VIA_APSIZE, &temp);
31 for (i = 0; i < agp_bridge->driver->num_aperture_sizes; i++) {
32 if (temp == values[i].size_value) {
33 agp_bridge->previous_size =
34 agp_bridge->current_size = (void *) (values + i);
35 agp_bridge->aperture_size_idx = i;
36 return values[i].size;
39 printk(KERN_ERR PFX "Unknown aperture size from AGP bridge (0x%x)\n", temp);
40 return 0;
44 static int via_configure(void)
46 u32 temp;
47 struct aper_size_info_8 *current_size;
49 current_size = A_SIZE_8(agp_bridge->current_size);
50 /* aperture size */
51 pci_write_config_byte(agp_bridge->dev, VIA_APSIZE,
52 current_size->size_value);
53 /* address to map too */
54 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
55 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
57 /* GART control register */
58 pci_write_config_dword(agp_bridge->dev, VIA_GARTCTRL, 0x0000000f);
60 /* attbase - aperture GATT base */
61 pci_write_config_dword(agp_bridge->dev, VIA_ATTBASE,
62 (agp_bridge->gatt_bus_addr & 0xfffff000) | 3);
63 return 0;
67 static void via_cleanup(void)
69 struct aper_size_info_8 *previous_size;
71 previous_size = A_SIZE_8(agp_bridge->previous_size);
72 pci_write_config_byte(agp_bridge->dev, VIA_APSIZE,
73 previous_size->size_value);
74 /* Do not disable by writing 0 to VIA_ATTBASE, it screws things up
75 * during reinitialization.
80 static void via_tlbflush(struct agp_memory *mem)
82 u32 temp;
84 pci_read_config_dword(agp_bridge->dev, VIA_GARTCTRL, &temp);
85 temp |= (1<<7);
86 pci_write_config_dword(agp_bridge->dev, VIA_GARTCTRL, temp);
87 temp &= ~(1<<7);
88 pci_write_config_dword(agp_bridge->dev, VIA_GARTCTRL, temp);
92 static const struct aper_size_info_8 via_generic_sizes[9] =
94 {256, 65536, 6, 0},
95 {128, 32768, 5, 128},
96 {64, 16384, 4, 192},
97 {32, 8192, 3, 224},
98 {16, 4096, 2, 240},
99 {8, 2048, 1, 248},
100 {4, 1024, 0, 252},
101 {2, 512, 0, 254},
102 {1, 256, 0, 255}
106 static int via_fetch_size_agp3(void)
108 int i;
109 u16 temp;
110 struct aper_size_info_16 *values;
112 values = A_SIZE_16(agp_bridge->driver->aperture_sizes);
113 pci_read_config_word(agp_bridge->dev, VIA_AGP3_APSIZE, &temp);
114 temp &= 0xfff;
116 for (i = 0; i < agp_bridge->driver->num_aperture_sizes; i++) {
117 if (temp == values[i].size_value) {
118 agp_bridge->previous_size =
119 agp_bridge->current_size = (void *) (values + i);
120 agp_bridge->aperture_size_idx = i;
121 return values[i].size;
124 return 0;
128 static int via_configure_agp3(void)
130 u32 temp;
131 struct aper_size_info_16 *current_size;
133 current_size = A_SIZE_16(agp_bridge->current_size);
135 /* address to map too */
136 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
137 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
139 /* attbase - aperture GATT base */
140 pci_write_config_dword(agp_bridge->dev, VIA_AGP3_ATTBASE,
141 agp_bridge->gatt_bus_addr & 0xfffff000);
143 /* 1. Enable GTLB in RX90<7>, all AGP aperture access needs to fetch
144 * translation table first.
145 * 2. Enable AGP aperture in RX91<0>. This bit controls the enabling of the
146 * graphics AGP aperture for the AGP3.0 port.
148 pci_read_config_dword(agp_bridge->dev, VIA_AGP3_GARTCTRL, &temp);
149 pci_write_config_dword(agp_bridge->dev, VIA_AGP3_GARTCTRL, temp | (3<<7));
150 return 0;
154 static void via_cleanup_agp3(void)
156 struct aper_size_info_16 *previous_size;
158 previous_size = A_SIZE_16(agp_bridge->previous_size);
159 pci_write_config_byte(agp_bridge->dev, VIA_APSIZE, previous_size->size_value);
163 static void via_tlbflush_agp3(struct agp_memory *mem)
165 u32 temp;
167 pci_read_config_dword(agp_bridge->dev, VIA_AGP3_GARTCTRL, &temp);
168 pci_write_config_dword(agp_bridge->dev, VIA_AGP3_GARTCTRL, temp & ~(1<<7));
169 pci_write_config_dword(agp_bridge->dev, VIA_AGP3_GARTCTRL, temp);
173 static const struct agp_bridge_driver via_agp3_driver = {
174 .owner = THIS_MODULE,
175 .aperture_sizes = agp3_generic_sizes,
176 .size_type = U8_APER_SIZE,
177 .num_aperture_sizes = 10,
178 .needs_scratch_page = true,
179 .configure = via_configure_agp3,
180 .fetch_size = via_fetch_size_agp3,
181 .cleanup = via_cleanup_agp3,
182 .tlb_flush = via_tlbflush_agp3,
183 .mask_memory = agp_generic_mask_memory,
184 .masks = NULL,
185 .agp_enable = agp_generic_enable,
186 .cache_flush = global_cache_flush,
187 .create_gatt_table = agp_generic_create_gatt_table,
188 .free_gatt_table = agp_generic_free_gatt_table,
189 .insert_memory = agp_generic_insert_memory,
190 .remove_memory = agp_generic_remove_memory,
191 .alloc_by_type = agp_generic_alloc_by_type,
192 .free_by_type = agp_generic_free_by_type,
193 .agp_alloc_page = agp_generic_alloc_page,
194 .agp_alloc_pages = agp_generic_alloc_pages,
195 .agp_destroy_page = agp_generic_destroy_page,
196 .agp_destroy_pages = agp_generic_destroy_pages,
197 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
200 static const struct agp_bridge_driver via_driver = {
201 .owner = THIS_MODULE,
202 .aperture_sizes = via_generic_sizes,
203 .size_type = U8_APER_SIZE,
204 .num_aperture_sizes = 9,
205 .needs_scratch_page = true,
206 .configure = via_configure,
207 .fetch_size = via_fetch_size,
208 .cleanup = via_cleanup,
209 .tlb_flush = via_tlbflush,
210 .mask_memory = agp_generic_mask_memory,
211 .masks = NULL,
212 .agp_enable = agp_generic_enable,
213 .cache_flush = global_cache_flush,
214 .create_gatt_table = agp_generic_create_gatt_table,
215 .free_gatt_table = agp_generic_free_gatt_table,
216 .insert_memory = agp_generic_insert_memory,
217 .remove_memory = agp_generic_remove_memory,
218 .alloc_by_type = agp_generic_alloc_by_type,
219 .free_by_type = agp_generic_free_by_type,
220 .agp_alloc_page = agp_generic_alloc_page,
221 .agp_alloc_pages = agp_generic_alloc_pages,
222 .agp_destroy_page = agp_generic_destroy_page,
223 .agp_destroy_pages = agp_generic_destroy_pages,
224 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
227 static struct agp_device_ids via_agp_device_ids[] __devinitdata =
230 .device_id = PCI_DEVICE_ID_VIA_82C597_0,
231 .chipset_name = "Apollo VP3",
235 .device_id = PCI_DEVICE_ID_VIA_82C598_0,
236 .chipset_name = "Apollo MVP3",
240 .device_id = PCI_DEVICE_ID_VIA_8501_0,
241 .chipset_name = "Apollo MVP4",
244 /* VT8601 */
246 .device_id = PCI_DEVICE_ID_VIA_8601_0,
247 .chipset_name = "Apollo ProMedia/PLE133Ta",
250 /* VT82C693A / VT28C694T */
252 .device_id = PCI_DEVICE_ID_VIA_82C691_0,
253 .chipset_name = "Apollo Pro 133",
257 .device_id = PCI_DEVICE_ID_VIA_8371_0,
258 .chipset_name = "KX133",
261 /* VT8633 */
263 .device_id = PCI_DEVICE_ID_VIA_8633_0,
264 .chipset_name = "Pro 266",
268 .device_id = PCI_DEVICE_ID_VIA_XN266,
269 .chipset_name = "Apollo Pro266",
272 /* VT8361 */
274 .device_id = PCI_DEVICE_ID_VIA_8361,
275 .chipset_name = "KLE133",
278 /* VT8365 / VT8362 */
280 .device_id = PCI_DEVICE_ID_VIA_8363_0,
281 .chipset_name = "Twister-K/KT133x/KM133",
284 /* VT8753A */
286 .device_id = PCI_DEVICE_ID_VIA_8753_0,
287 .chipset_name = "P4X266",
290 /* VT8366 */
292 .device_id = PCI_DEVICE_ID_VIA_8367_0,
293 .chipset_name = "KT266/KY266x/KT333",
296 /* VT8633 (for CuMine/ Celeron) */
298 .device_id = PCI_DEVICE_ID_VIA_8653_0,
299 .chipset_name = "Pro266T",
302 /* KM266 / PM266 */
304 .device_id = PCI_DEVICE_ID_VIA_XM266,
305 .chipset_name = "PM266/KM266",
308 /* CLE266 */
310 .device_id = PCI_DEVICE_ID_VIA_862X_0,
311 .chipset_name = "CLE266",
315 .device_id = PCI_DEVICE_ID_VIA_8377_0,
316 .chipset_name = "KT400/KT400A/KT600",
319 /* VT8604 / VT8605 / VT8603
320 * (Apollo Pro133A chipset with S3 Savage4) */
322 .device_id = PCI_DEVICE_ID_VIA_8605_0,
323 .chipset_name = "ProSavage PM133/PL133/PN133"
326 /* P4M266x/P4N266 */
328 .device_id = PCI_DEVICE_ID_VIA_8703_51_0,
329 .chipset_name = "P4M266x/P4N266",
332 /* VT8754 */
334 .device_id = PCI_DEVICE_ID_VIA_8754C_0,
335 .chipset_name = "PT800",
338 /* P4X600 */
340 .device_id = PCI_DEVICE_ID_VIA_8763_0,
341 .chipset_name = "P4X600"
344 /* KM400 */
346 .device_id = PCI_DEVICE_ID_VIA_8378_0,
347 .chipset_name = "KM400/KM400A",
350 /* PT880 */
352 .device_id = PCI_DEVICE_ID_VIA_PT880,
353 .chipset_name = "PT880",
356 /* PT880 Ultra */
358 .device_id = PCI_DEVICE_ID_VIA_PT880ULTRA,
359 .chipset_name = "PT880 Ultra",
362 /* PT890 */
364 .device_id = PCI_DEVICE_ID_VIA_8783_0,
365 .chipset_name = "PT890",
368 /* PM800/PN800/PM880/PN880 */
370 .device_id = PCI_DEVICE_ID_VIA_PX8X0_0,
371 .chipset_name = "PM800/PN800/PM880/PN880",
373 /* KT880 */
375 .device_id = PCI_DEVICE_ID_VIA_3269_0,
376 .chipset_name = "KT880",
378 /* KTxxx/Px8xx */
380 .device_id = PCI_DEVICE_ID_VIA_83_87XX_1,
381 .chipset_name = "VT83xx/VT87xx/KTxxx/Px8xx",
383 /* P4M800 */
385 .device_id = PCI_DEVICE_ID_VIA_3296_0,
386 .chipset_name = "P4M800",
388 /* P4M800CE */
390 .device_id = PCI_DEVICE_ID_VIA_P4M800CE,
391 .chipset_name = "VT3314",
393 /* VT3324 / CX700 */
395 .device_id = PCI_DEVICE_ID_VIA_VT3324,
396 .chipset_name = "CX700",
398 /* VT3336 - this is a chipset for AMD Athlon/K8 CPU. Due to K8's unique
399 * architecture, the AGP resource and behavior are different from
400 * the traditional AGP which resides only in chipset. AGP is used
401 * by 3D driver which wasn't available for the VT3336 and VT3364
402 * generation until now. Unfortunately, by testing, VT3364 works
403 * but VT3336 doesn't. - explaination from via, just leave this as
404 * as a placeholder to avoid future patches adding it back in.
406 /* P4M890 */
408 .device_id = PCI_DEVICE_ID_VIA_P4M890,
409 .chipset_name = "P4M890",
411 /* P4M900 */
413 .device_id = PCI_DEVICE_ID_VIA_VT3364,
414 .chipset_name = "P4M900",
416 { }, /* dummy final entry, always present */
421 * VIA's AGP3 chipsets do magick to put the AGP bridge compliant
422 * with the same standards version as the graphics card.
424 static void check_via_agp3 (struct agp_bridge_data *bridge)
426 u8 reg;
428 pci_read_config_byte(bridge->dev, VIA_AGPSEL, &reg);
429 /* Check AGP 2.0 compatibility mode. */
430 if ((reg & (1<<1))==0)
431 bridge->driver = &via_agp3_driver;
435 static int __devinit agp_via_probe(struct pci_dev *pdev,
436 const struct pci_device_id *ent)
438 struct agp_device_ids *devs = via_agp_device_ids;
439 struct agp_bridge_data *bridge;
440 int j = 0;
441 u8 cap_ptr;
443 cap_ptr = pci_find_capability(pdev, PCI_CAP_ID_AGP);
444 if (!cap_ptr)
445 return -ENODEV;
447 j = ent - agp_via_pci_table;
448 printk (KERN_INFO PFX "Detected VIA %s chipset\n", devs[j].chipset_name);
450 bridge = agp_alloc_bridge();
451 if (!bridge)
452 return -ENOMEM;
454 bridge->dev = pdev;
455 bridge->capndx = cap_ptr;
456 bridge->driver = &via_driver;
459 * Garg, there are KT400s with KT266 IDs.
461 if (pdev->device == PCI_DEVICE_ID_VIA_8367_0) {
462 /* Is there a KT400 subsystem ? */
463 if (pdev->subsystem_device == PCI_DEVICE_ID_VIA_8377_0) {
464 printk(KERN_INFO PFX "Found KT400 in disguise as a KT266.\n");
465 check_via_agp3(bridge);
469 /* If this is an AGP3 bridge, check which mode its in and adjust. */
470 get_agp_version(bridge);
471 if (bridge->major_version >= 3)
472 check_via_agp3(bridge);
474 /* Fill in the mode register */
475 pci_read_config_dword(pdev,
476 bridge->capndx+PCI_AGP_STATUS, &bridge->mode);
478 pci_set_drvdata(pdev, bridge);
479 return agp_add_bridge(bridge);
482 static void __devexit agp_via_remove(struct pci_dev *pdev)
484 struct agp_bridge_data *bridge = pci_get_drvdata(pdev);
486 agp_remove_bridge(bridge);
487 agp_put_bridge(bridge);
490 #ifdef CONFIG_PM
492 static int agp_via_suspend(struct pci_dev *pdev, pm_message_t state)
494 pci_save_state (pdev);
495 pci_set_power_state (pdev, PCI_D3hot);
497 return 0;
500 static int agp_via_resume(struct pci_dev *pdev)
502 struct agp_bridge_data *bridge = pci_get_drvdata(pdev);
504 pci_set_power_state (pdev, PCI_D0);
505 pci_restore_state(pdev);
507 if (bridge->driver == &via_agp3_driver)
508 return via_configure_agp3();
509 else if (bridge->driver == &via_driver)
510 return via_configure();
512 return 0;
515 #endif /* CONFIG_PM */
517 /* must be the same order as name table above */
518 static const struct pci_device_id agp_via_pci_table[] = {
519 #define ID(x) \
521 .class = (PCI_CLASS_BRIDGE_HOST << 8), \
522 .class_mask = ~0, \
523 .vendor = PCI_VENDOR_ID_VIA, \
524 .device = x, \
525 .subvendor = PCI_ANY_ID, \
526 .subdevice = PCI_ANY_ID, \
528 ID(PCI_DEVICE_ID_VIA_82C597_0),
529 ID(PCI_DEVICE_ID_VIA_82C598_0),
530 ID(PCI_DEVICE_ID_VIA_8501_0),
531 ID(PCI_DEVICE_ID_VIA_8601_0),
532 ID(PCI_DEVICE_ID_VIA_82C691_0),
533 ID(PCI_DEVICE_ID_VIA_8371_0),
534 ID(PCI_DEVICE_ID_VIA_8633_0),
535 ID(PCI_DEVICE_ID_VIA_XN266),
536 ID(PCI_DEVICE_ID_VIA_8361),
537 ID(PCI_DEVICE_ID_VIA_8363_0),
538 ID(PCI_DEVICE_ID_VIA_8753_0),
539 ID(PCI_DEVICE_ID_VIA_8367_0),
540 ID(PCI_DEVICE_ID_VIA_8653_0),
541 ID(PCI_DEVICE_ID_VIA_XM266),
542 ID(PCI_DEVICE_ID_VIA_862X_0),
543 ID(PCI_DEVICE_ID_VIA_8377_0),
544 ID(PCI_DEVICE_ID_VIA_8605_0),
545 ID(PCI_DEVICE_ID_VIA_8703_51_0),
546 ID(PCI_DEVICE_ID_VIA_8754C_0),
547 ID(PCI_DEVICE_ID_VIA_8763_0),
548 ID(PCI_DEVICE_ID_VIA_8378_0),
549 ID(PCI_DEVICE_ID_VIA_PT880),
550 ID(PCI_DEVICE_ID_VIA_PT880ULTRA),
551 ID(PCI_DEVICE_ID_VIA_8783_0),
552 ID(PCI_DEVICE_ID_VIA_PX8X0_0),
553 ID(PCI_DEVICE_ID_VIA_3269_0),
554 ID(PCI_DEVICE_ID_VIA_83_87XX_1),
555 ID(PCI_DEVICE_ID_VIA_3296_0),
556 ID(PCI_DEVICE_ID_VIA_P4M800CE),
557 ID(PCI_DEVICE_ID_VIA_VT3324),
558 ID(PCI_DEVICE_ID_VIA_P4M890),
559 ID(PCI_DEVICE_ID_VIA_VT3364),
563 MODULE_DEVICE_TABLE(pci, agp_via_pci_table);
566 static struct pci_driver agp_via_pci_driver = {
567 .name = "agpgart-via",
568 .id_table = agp_via_pci_table,
569 .probe = agp_via_probe,
570 .remove = agp_via_remove,
571 #ifdef CONFIG_PM
572 .suspend = agp_via_suspend,
573 .resume = agp_via_resume,
574 #endif
578 static int __init agp_via_init(void)
580 if (agp_off)
581 return -EINVAL;
582 return pci_register_driver(&agp_via_pci_driver);
585 static void __exit agp_via_cleanup(void)
587 pci_unregister_driver(&agp_via_pci_driver);
590 module_init(agp_via_init);
591 module_exit(agp_via_cleanup);
593 MODULE_LICENSE("GPL");
594 MODULE_AUTHOR("Dave Jones <davej@redhat.com>");