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 #define PCI_DEVICE_ID_SI_662 0x0662
18 #define PCI_DEVICE_ID_SI_671 0x0671
20 static int __devinitdata agp_sis_force_delay
= 0;
21 static int __devinitdata agp_sis_agp_spec
= -1;
23 static int sis_fetch_size(void)
27 struct aper_size_info_8
*values
;
29 pci_read_config_byte(agp_bridge
->dev
, SIS_APSIZE
, &temp_size
);
30 values
= A_SIZE_8(agp_bridge
->driver
->aperture_sizes
);
31 for (i
= 0; i
< agp_bridge
->driver
->num_aperture_sizes
; i
++) {
32 if ((temp_size
== values
[i
].size_value
) ||
33 ((temp_size
& ~(0x07)) ==
34 (values
[i
].size_value
& ~(0x07)))) {
35 agp_bridge
->previous_size
=
36 agp_bridge
->current_size
= (void *) (values
+ i
);
38 agp_bridge
->aperture_size_idx
= i
;
39 return values
[i
].size
;
46 static void sis_tlbflush(struct agp_memory
*mem
)
48 pci_write_config_byte(agp_bridge
->dev
, SIS_TLBFLUSH
, 0x02);
51 static int sis_configure(void)
54 struct aper_size_info_8
*current_size
;
56 current_size
= A_SIZE_8(agp_bridge
->current_size
);
57 pci_write_config_byte(agp_bridge
->dev
, SIS_TLBCNTRL
, 0x05);
58 pci_read_config_dword(agp_bridge
->dev
, AGP_APBASE
, &temp
);
59 agp_bridge
->gart_bus_addr
= (temp
& PCI_BASE_ADDRESS_MEM_MASK
);
60 pci_write_config_dword(agp_bridge
->dev
, SIS_ATTBASE
,
61 agp_bridge
->gatt_bus_addr
);
62 pci_write_config_byte(agp_bridge
->dev
, SIS_APSIZE
,
63 current_size
->size_value
);
67 static void sis_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
, SIS_APSIZE
,
73 (previous_size
->size_value
& ~(0x03)));
76 static void sis_delayed_enable(struct agp_bridge_data
*bridge
, u32 mode
)
78 struct pci_dev
*device
= NULL
;
82 printk(KERN_INFO PFX
"Found an AGP %d.%d compliant device at %s.\n",
83 agp_bridge
->major_version
,
84 agp_bridge
->minor_version
,
85 pci_name(agp_bridge
->dev
));
87 pci_read_config_dword(agp_bridge
->dev
, agp_bridge
->capndx
+ PCI_AGP_STATUS
, &command
);
88 command
= agp_collect_device_status(bridge
, mode
, command
);
89 command
|= AGPSTAT_AGP_ENABLE
;
90 rate
= (command
& 0x7) << 2;
92 for_each_pci_dev(device
) {
93 u8 agp
= pci_find_capability(device
, PCI_CAP_ID_AGP
);
97 printk(KERN_INFO PFX
"Putting AGP V3 device at %s into %dx mode\n",
98 pci_name(device
), rate
);
100 pci_write_config_dword(device
, agp
+ PCI_AGP_COMMAND
, command
);
103 * Weird: on some sis chipsets any rate change in the target
104 * command register triggers a 5ms screwup during which the master
105 * cannot be configured
107 if (device
->device
== bridge
->dev
->device
) {
108 printk(KERN_INFO PFX
"SiS delay workaround: giving bridge time to recover.\n");
114 static const struct aper_size_info_8 sis_generic_sizes
[7] =
125 static struct agp_bridge_driver sis_driver
= {
126 .owner
= THIS_MODULE
,
127 .aperture_sizes
= sis_generic_sizes
,
128 .size_type
= U8_APER_SIZE
,
129 .num_aperture_sizes
= 7,
130 .configure
= sis_configure
,
131 .fetch_size
= sis_fetch_size
,
132 .cleanup
= sis_cleanup
,
133 .tlb_flush
= sis_tlbflush
,
134 .mask_memory
= agp_generic_mask_memory
,
136 .agp_enable
= agp_generic_enable
,
137 .cache_flush
= global_cache_flush
,
138 .create_gatt_table
= agp_generic_create_gatt_table
,
139 .free_gatt_table
= agp_generic_free_gatt_table
,
140 .insert_memory
= agp_generic_insert_memory
,
141 .remove_memory
= agp_generic_remove_memory
,
142 .alloc_by_type
= agp_generic_alloc_by_type
,
143 .free_by_type
= agp_generic_free_by_type
,
144 .agp_alloc_page
= agp_generic_alloc_page
,
145 .agp_destroy_page
= agp_generic_destroy_page
,
146 .agp_type_to_mask_type
= agp_generic_type_to_mask_type
,
149 // chipsets that require the 'delay hack'
150 static int sis_broken_chipsets
[] __devinitdata
= {
151 PCI_DEVICE_ID_SI_648
,
152 PCI_DEVICE_ID_SI_746
,
156 static void __devinit
sis_get_driver(struct agp_bridge_data
*bridge
)
160 for (i
=0; sis_broken_chipsets
[i
]!=0; ++i
)
161 if (bridge
->dev
->device
==sis_broken_chipsets
[i
])
164 if (sis_broken_chipsets
[i
] || agp_sis_force_delay
)
165 sis_driver
.agp_enable
=sis_delayed_enable
;
167 // sis chipsets that indicate less than agp3.5
168 // are not actually fully agp3 compliant
169 if ((agp_bridge
->major_version
== 3 && agp_bridge
->minor_version
>= 5
170 && agp_sis_agp_spec
!=0) || agp_sis_agp_spec
==1) {
171 sis_driver
.aperture_sizes
= agp3_generic_sizes
;
172 sis_driver
.size_type
= U16_APER_SIZE
;
173 sis_driver
.num_aperture_sizes
= AGP_GENERIC_SIZES_ENTRIES
;
174 sis_driver
.configure
= agp3_generic_configure
;
175 sis_driver
.fetch_size
= agp3_generic_fetch_size
;
176 sis_driver
.cleanup
= agp3_generic_cleanup
;
177 sis_driver
.tlb_flush
= agp3_generic_tlbflush
;
182 static int __devinit
agp_sis_probe(struct pci_dev
*pdev
,
183 const struct pci_device_id
*ent
)
185 struct agp_bridge_data
*bridge
;
188 cap_ptr
= pci_find_capability(pdev
, PCI_CAP_ID_AGP
);
193 printk(KERN_INFO PFX
"Detected SiS chipset - id:%i\n", pdev
->device
);
194 bridge
= agp_alloc_bridge();
198 bridge
->driver
= &sis_driver
;
200 bridge
->capndx
= cap_ptr
;
202 get_agp_version(bridge
);
204 /* Fill in the mode register */
205 pci_read_config_dword(pdev
, bridge
->capndx
+PCI_AGP_STATUS
, &bridge
->mode
);
206 sis_get_driver(bridge
);
208 pci_set_drvdata(pdev
, bridge
);
209 return agp_add_bridge(bridge
);
212 static void __devexit
agp_sis_remove(struct pci_dev
*pdev
)
214 struct agp_bridge_data
*bridge
= pci_get_drvdata(pdev
);
216 agp_remove_bridge(bridge
);
217 agp_put_bridge(bridge
);
222 static int agp_sis_suspend(struct pci_dev
*pdev
, pm_message_t state
)
224 pci_save_state(pdev
);
225 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
230 static int agp_sis_resume(struct pci_dev
*pdev
)
232 pci_set_power_state(pdev
, PCI_D0
);
233 pci_restore_state(pdev
);
235 return sis_driver
.configure();
238 #endif /* CONFIG_PM */
240 static struct pci_device_id agp_sis_pci_table
[] = {
242 .class = (PCI_CLASS_BRIDGE_HOST
<< 8),
244 .vendor
= PCI_VENDOR_ID_SI
,
245 .device
= PCI_DEVICE_ID_SI_5591_AGP
,
246 .subvendor
= PCI_ANY_ID
,
247 .subdevice
= PCI_ANY_ID
,
250 .class = (PCI_CLASS_BRIDGE_HOST
<< 8),
252 .vendor
= PCI_VENDOR_ID_SI
,
253 .device
= PCI_DEVICE_ID_SI_530
,
254 .subvendor
= PCI_ANY_ID
,
255 .subdevice
= PCI_ANY_ID
,
258 .class = (PCI_CLASS_BRIDGE_HOST
<< 8),
260 .vendor
= PCI_VENDOR_ID_SI
,
261 .device
= PCI_DEVICE_ID_SI_540
,
262 .subvendor
= PCI_ANY_ID
,
263 .subdevice
= PCI_ANY_ID
,
266 .class = (PCI_CLASS_BRIDGE_HOST
<< 8),
268 .vendor
= PCI_VENDOR_ID_SI
,
269 .device
= PCI_DEVICE_ID_SI_550
,
270 .subvendor
= PCI_ANY_ID
,
271 .subdevice
= PCI_ANY_ID
,
274 .class = (PCI_CLASS_BRIDGE_HOST
<< 8),
276 .vendor
= PCI_VENDOR_ID_SI
,
277 .device
= PCI_DEVICE_ID_SI_620
,
278 .subvendor
= PCI_ANY_ID
,
279 .subdevice
= PCI_ANY_ID
,
282 .class = (PCI_CLASS_BRIDGE_HOST
<< 8),
284 .vendor
= PCI_VENDOR_ID_SI
,
285 .device
= PCI_DEVICE_ID_SI_630
,
286 .subvendor
= PCI_ANY_ID
,
287 .subdevice
= PCI_ANY_ID
,
290 .class = (PCI_CLASS_BRIDGE_HOST
<< 8),
292 .vendor
= PCI_VENDOR_ID_SI
,
293 .device
= PCI_DEVICE_ID_SI_635
,
294 .subvendor
= PCI_ANY_ID
,
295 .subdevice
= PCI_ANY_ID
,
298 .class = (PCI_CLASS_BRIDGE_HOST
<< 8),
300 .vendor
= PCI_VENDOR_ID_SI
,
301 .device
= PCI_DEVICE_ID_SI_645
,
302 .subvendor
= PCI_ANY_ID
,
303 .subdevice
= PCI_ANY_ID
,
306 .class = (PCI_CLASS_BRIDGE_HOST
<< 8),
308 .vendor
= PCI_VENDOR_ID_SI
,
309 .device
= PCI_DEVICE_ID_SI_646
,
310 .subvendor
= PCI_ANY_ID
,
311 .subdevice
= PCI_ANY_ID
,
314 .class = (PCI_CLASS_BRIDGE_HOST
<< 8),
316 .vendor
= PCI_VENDOR_ID_SI
,
317 .device
= PCI_DEVICE_ID_SI_648
,
318 .subvendor
= PCI_ANY_ID
,
319 .subdevice
= PCI_ANY_ID
,
322 .class = (PCI_CLASS_BRIDGE_HOST
<< 8),
324 .vendor
= PCI_VENDOR_ID_SI
,
325 .device
= PCI_DEVICE_ID_SI_650
,
326 .subvendor
= PCI_ANY_ID
,
327 .subdevice
= PCI_ANY_ID
,
330 .class = (PCI_CLASS_BRIDGE_HOST
<< 8),
332 .vendor
= PCI_VENDOR_ID_SI
,
333 .device
= PCI_DEVICE_ID_SI_651
,
334 .subvendor
= PCI_ANY_ID
,
335 .subdevice
= PCI_ANY_ID
,
338 .class = (PCI_CLASS_BRIDGE_HOST
<< 8),
340 .vendor
= PCI_VENDOR_ID_SI
,
341 .device
= PCI_DEVICE_ID_SI_655
,
342 .subvendor
= PCI_ANY_ID
,
343 .subdevice
= PCI_ANY_ID
,
346 .class = (PCI_CLASS_BRIDGE_HOST
<< 8),
348 .vendor
= PCI_VENDOR_ID_SI
,
349 .device
= PCI_DEVICE_ID_SI_661
,
350 .subvendor
= PCI_ANY_ID
,
351 .subdevice
= PCI_ANY_ID
,
354 .class = (PCI_CLASS_BRIDGE_HOST
<< 8),
356 .vendor
= PCI_VENDOR_ID_SI
,
357 .device
= PCI_DEVICE_ID_SI_662
,
358 .subvendor
= PCI_ANY_ID
,
359 .subdevice
= PCI_ANY_ID
,
362 .class = (PCI_CLASS_BRIDGE_HOST
<< 8),
364 .vendor
= PCI_VENDOR_ID_SI
,
365 .device
= PCI_DEVICE_ID_SI_671
,
366 .subvendor
= PCI_ANY_ID
,
367 .subdevice
= PCI_ANY_ID
,
370 .class = (PCI_CLASS_BRIDGE_HOST
<< 8),
372 .vendor
= PCI_VENDOR_ID_SI
,
373 .device
= PCI_DEVICE_ID_SI_730
,
374 .subvendor
= PCI_ANY_ID
,
375 .subdevice
= PCI_ANY_ID
,
378 .class = (PCI_CLASS_BRIDGE_HOST
<< 8),
380 .vendor
= PCI_VENDOR_ID_SI
,
381 .device
= PCI_DEVICE_ID_SI_735
,
382 .subvendor
= PCI_ANY_ID
,
383 .subdevice
= PCI_ANY_ID
,
386 .class = (PCI_CLASS_BRIDGE_HOST
<< 8),
388 .vendor
= PCI_VENDOR_ID_SI
,
389 .device
= PCI_DEVICE_ID_SI_740
,
390 .subvendor
= PCI_ANY_ID
,
391 .subdevice
= PCI_ANY_ID
,
394 .class = (PCI_CLASS_BRIDGE_HOST
<< 8),
396 .vendor
= PCI_VENDOR_ID_SI
,
397 .device
= PCI_DEVICE_ID_SI_741
,
398 .subvendor
= PCI_ANY_ID
,
399 .subdevice
= PCI_ANY_ID
,
402 .class = (PCI_CLASS_BRIDGE_HOST
<< 8),
404 .vendor
= PCI_VENDOR_ID_SI
,
405 .device
= PCI_DEVICE_ID_SI_745
,
406 .subvendor
= PCI_ANY_ID
,
407 .subdevice
= PCI_ANY_ID
,
410 .class = (PCI_CLASS_BRIDGE_HOST
<< 8),
412 .vendor
= PCI_VENDOR_ID_SI
,
413 .device
= PCI_DEVICE_ID_SI_746
,
414 .subvendor
= PCI_ANY_ID
,
415 .subdevice
= PCI_ANY_ID
,
418 .class = (PCI_CLASS_BRIDGE_HOST
<< 8),
420 .vendor
= PCI_VENDOR_ID_SI
,
421 .device
= PCI_DEVICE_ID_SI_760
,
422 .subvendor
= PCI_ANY_ID
,
423 .subdevice
= PCI_ANY_ID
,
428 MODULE_DEVICE_TABLE(pci
, agp_sis_pci_table
);
430 static struct pci_driver agp_sis_pci_driver
= {
431 .name
= "agpgart-sis",
432 .id_table
= agp_sis_pci_table
,
433 .probe
= agp_sis_probe
,
434 .remove
= agp_sis_remove
,
436 .suspend
= agp_sis_suspend
,
437 .resume
= agp_sis_resume
,
441 static int __init
agp_sis_init(void)
445 return pci_register_driver(&agp_sis_pci_driver
);
448 static void __exit
agp_sis_cleanup(void)
450 pci_unregister_driver(&agp_sis_pci_driver
);
453 module_init(agp_sis_init
);
454 module_exit(agp_sis_cleanup
);
456 module_param(agp_sis_force_delay
, bool, 0);
457 MODULE_PARM_DESC(agp_sis_force_delay
,"forces sis delay hack");
458 module_param(agp_sis_agp_spec
, int, 0);
459 MODULE_PARM_DESC(agp_sis_agp_spec
,"0=force sis init, 1=force generic agp3 init, default: autodetect");
460 MODULE_LICENSE("GPL and additional rights");