2 * SiS AGPGART routines.
5 #include <linux/module.h>
7 #include <linux/init.h>
8 #include <linux/agp_backend.h>
9 #include <linux/delay.h>
12 #define SIS_ATTBASE 0x90
13 #define SIS_APSIZE 0x94
14 #define SIS_TLBCNTRL 0x97
15 #define SIS_TLBFLUSH 0x98
17 static int __devinitdata agp_sis_force_delay = 0;
18 static int __devinitdata agp_sis_agp_spec = -1;
20 static int sis_fetch_size(void)
24 struct aper_size_info_8 *values;
26 pci_read_config_byte(agp_bridge->dev, SIS_APSIZE, &temp_size);
27 values = A_SIZE_8(agp_bridge->driver->aperture_sizes);
28 for (i = 0; i < agp_bridge->driver->num_aperture_sizes; i++) {
29 if ((temp_size == values[i].size_value) ||
30 ((temp_size & ~(0x03)) ==
31 (values[i].size_value & ~(0x03)))) {
32 agp_bridge->previous_size =
33 agp_bridge->current_size = (void *) (values + i);
35 agp_bridge->aperture_size_idx = i;
36 return values[i].size;
43 static void sis_tlbflush(struct agp_memory *mem)
45 pci_write_config_byte(agp_bridge->dev, SIS_TLBFLUSH, 0x02);
48 static int sis_configure(void)
51 struct aper_size_info_8 *current_size;
53 current_size = A_SIZE_8(agp_bridge->current_size);
54 pci_write_config_byte(agp_bridge->dev, SIS_TLBCNTRL, 0x05);
55 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
56 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
57 pci_write_config_dword(agp_bridge->dev, SIS_ATTBASE,
58 agp_bridge->gatt_bus_addr);
59 pci_write_config_byte(agp_bridge->dev, SIS_APSIZE,
60 current_size->size_value);
64 static void sis_cleanup(void)
66 struct aper_size_info_8 *previous_size;
68 previous_size = A_SIZE_8(agp_bridge->previous_size);
69 pci_write_config_byte(agp_bridge->dev, SIS_APSIZE,
70 (previous_size->size_value & ~(0x03)));
73 static void sis_delayed_enable(struct agp_bridge_data *bridge, u32 mode)
75 struct pci_dev *device = NULL;
79 printk(KERN_INFO PFX "Found an AGP %d.%d compliant device at %s.\n",
80 agp_bridge->major_version,
81 agp_bridge->minor_version,
82 pci_name(agp_bridge->dev));
84 pci_read_config_dword(agp_bridge->dev, agp_bridge->capndx + PCI_AGP_STATUS, &command);
85 command = agp_collect_device_status(bridge, mode, command);
86 command |= AGPSTAT_AGP_ENABLE;
87 rate = (command & 0x7) << 2;
89 for_each_pci_dev(device) {
90 u8 agp = pci_find_capability(device, PCI_CAP_ID_AGP);
94 printk(KERN_INFO PFX "Putting AGP V3 device at %s into %dx mode\n",
95 pci_name(device), rate);
97 pci_write_config_dword(device, agp + PCI_AGP_COMMAND, command);
100 * Weird: on some sis chipsets any rate change in the target
101 * command register triggers a 5ms screwup during which the master
102 * cannot be configured
104 if (device->device == bridge->dev->device) {
105 printk(KERN_INFO PFX "SiS delay workaround: giving bridge time to recover.\n");
111 static struct aper_size_info_8 sis_generic_sizes[7] =
122 static struct agp_bridge_driver sis_driver = {
123 .owner = THIS_MODULE,
124 .aperture_sizes = sis_generic_sizes,
125 .size_type = U8_APER_SIZE,
126 .num_aperture_sizes = 7,
127 .configure = sis_configure,
128 .fetch_size = sis_fetch_size,
129 .cleanup = sis_cleanup,
130 .tlb_flush = sis_tlbflush,
131 .mask_memory = agp_generic_mask_memory,
133 .agp_enable = agp_generic_enable,
134 .cache_flush = global_cache_flush,
135 .create_gatt_table = agp_generic_create_gatt_table,
136 .free_gatt_table = agp_generic_free_gatt_table,
137 .insert_memory = agp_generic_insert_memory,
138 .remove_memory = agp_generic_remove_memory,
139 .alloc_by_type = agp_generic_alloc_by_type,
140 .free_by_type = agp_generic_free_by_type,
141 .agp_alloc_page = agp_generic_alloc_page,
142 .agp_destroy_page = agp_generic_destroy_page,
143 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
146 static struct agp_device_ids sis_agp_device_ids[] __devinitdata =
149 .device_id = PCI_DEVICE_ID_SI_5591_AGP,
150 .chipset_name = "5591",
153 .device_id = PCI_DEVICE_ID_SI_530,
154 .chipset_name = "530",
157 .device_id = PCI_DEVICE_ID_SI_540,
158 .chipset_name = "540",
161 .device_id = PCI_DEVICE_ID_SI_550,
162 .chipset_name = "550",
165 .device_id = PCI_DEVICE_ID_SI_620,
166 .chipset_name = "620",
169 .device_id = PCI_DEVICE_ID_SI_630,
170 .chipset_name = "630",
173 .device_id = PCI_DEVICE_ID_SI_635,
174 .chipset_name = "635",
177 .device_id = PCI_DEVICE_ID_SI_645,
178 .chipset_name = "645",
181 .device_id = PCI_DEVICE_ID_SI_646,
182 .chipset_name = "646",
185 .device_id = PCI_DEVICE_ID_SI_648,
186 .chipset_name = "648",
189 .device_id = PCI_DEVICE_ID_SI_650,
190 .chipset_name = "650",
193 .device_id = PCI_DEVICE_ID_SI_651,
194 .chipset_name = "651",
197 .device_id = PCI_DEVICE_ID_SI_655,
198 .chipset_name = "655",
201 .device_id = PCI_DEVICE_ID_SI_661,
202 .chipset_name = "661",
205 .device_id = PCI_DEVICE_ID_SI_730,
206 .chipset_name = "730",
209 .device_id = PCI_DEVICE_ID_SI_735,
210 .chipset_name = "735",
213 .device_id = PCI_DEVICE_ID_SI_740,
214 .chipset_name = "740",
217 .device_id = PCI_DEVICE_ID_SI_741,
218 .chipset_name = "741",
221 .device_id = PCI_DEVICE_ID_SI_745,
222 .chipset_name = "745",
225 .device_id = PCI_DEVICE_ID_SI_746,
226 .chipset_name = "746",
229 .device_id = PCI_DEVICE_ID_SI_760,
230 .chipset_name = "760",
232 { }, /* dummy final entry, always present */
236 // chipsets that require the 'delay hack'
237 static int sis_broken_chipsets[] __devinitdata = {
238 PCI_DEVICE_ID_SI_648,
239 PCI_DEVICE_ID_SI_746,
243 static void __devinit sis_get_driver(struct agp_bridge_data *bridge)
247 for (i=0; sis_broken_chipsets[i]!=0; ++i)
248 if (bridge->dev->device==sis_broken_chipsets[i])
251 if (sis_broken_chipsets[i] || agp_sis_force_delay)
252 sis_driver.agp_enable=sis_delayed_enable;
254 // sis chipsets that indicate less than agp3.5
255 // are not actually fully agp3 compliant
256 if ((agp_bridge->major_version == 3 && agp_bridge->minor_version >= 5
257 && agp_sis_agp_spec!=0) || agp_sis_agp_spec==1) {
258 sis_driver.aperture_sizes = agp3_generic_sizes;
259 sis_driver.size_type = U16_APER_SIZE;
260 sis_driver.num_aperture_sizes = AGP_GENERIC_SIZES_ENTRIES;
261 sis_driver.configure = agp3_generic_configure;
262 sis_driver.fetch_size = agp3_generic_fetch_size;
263 sis_driver.cleanup = agp3_generic_cleanup;
264 sis_driver.tlb_flush = agp3_generic_tlbflush;
269 static int __devinit agp_sis_probe(struct pci_dev *pdev,
270 const struct pci_device_id *ent)
272 struct agp_device_ids *devs = sis_agp_device_ids;
273 struct agp_bridge_data *bridge;
277 cap_ptr = pci_find_capability(pdev, PCI_CAP_ID_AGP);
281 /* probe for known chipsets */
282 for (j = 0; devs[j].chipset_name; j++) {
283 if (pdev->device == devs[j].device_id) {
284 printk(KERN_INFO PFX "Detected SiS %s chipset\n",
285 devs[j].chipset_name);
290 printk(KERN_ERR PFX "Unsupported SiS chipset (device id: %04x)\n",
295 bridge = agp_alloc_bridge();
299 bridge->driver = &sis_driver;
301 bridge->capndx = cap_ptr;
303 get_agp_version(bridge);
305 /* Fill in the mode register */
306 pci_read_config_dword(pdev, bridge->capndx+PCI_AGP_STATUS, &bridge->mode);
307 sis_get_driver(bridge);
309 pci_set_drvdata(pdev, bridge);
310 return agp_add_bridge(bridge);
313 static void __devexit agp_sis_remove(struct pci_dev *pdev)
315 struct agp_bridge_data *bridge = pci_get_drvdata(pdev);
317 agp_remove_bridge(bridge);
318 agp_put_bridge(bridge);
321 static struct pci_device_id agp_sis_pci_table[] = {
323 .class = (PCI_CLASS_BRIDGE_HOST << 8),
325 .vendor = PCI_VENDOR_ID_SI,
326 .device = PCI_ANY_ID,
327 .subvendor = PCI_ANY_ID,
328 .subdevice = PCI_ANY_ID,
333 MODULE_DEVICE_TABLE(pci, agp_sis_pci_table);
335 static struct pci_driver agp_sis_pci_driver = {
336 .name = "agpgart-sis",
337 .id_table = agp_sis_pci_table,
338 .probe = agp_sis_probe,
339 .remove = agp_sis_remove,
342 static int __init agp_sis_init(void)
346 return pci_register_driver(&agp_sis_pci_driver);
349 static void __exit agp_sis_cleanup(void)
351 pci_unregister_driver(&agp_sis_pci_driver);
354 module_init(agp_sis_init);
355 module_exit(agp_sis_cleanup);
357 module_param(agp_sis_force_delay, bool, 0);
358 MODULE_PARM_DESC(agp_sis_force_delay,"forces sis delay hack");
359 module_param(agp_sis_agp_spec, int, 0);
360 MODULE_PARM_DESC(agp_sis_agp_spec,"0=force sis init, 1=force generic agp3 init, default: autodetect");
361 MODULE_LICENSE("GPL and additional rights");