sis-agp.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. /*
  2. * SiS AGPGART routines.
  3. */
  4. #include <linux/module.h>
  5. #include <linux/pci.h>
  6. #include <linux/init.h>
  7. #include <linux/agp_backend.h>
  8. #include <linux/delay.h>
  9. #include "agp.h"
  10. #define SIS_ATTBASE 0x90
  11. #define SIS_APSIZE 0x94
  12. #define SIS_TLBCNTRL 0x97
  13. #define SIS_TLBFLUSH 0x98
  14. #define PCI_DEVICE_ID_SI_662 0x0662
  15. #define PCI_DEVICE_ID_SI_671 0x0671
  16. static int __devinitdata agp_sis_force_delay = 0;
  17. static int __devinitdata agp_sis_agp_spec = -1;
  18. static int sis_fetch_size(void)
  19. {
  20. u8 temp_size;
  21. int i;
  22. struct aper_size_info_8 *values;
  23. pci_read_config_byte(agp_bridge->dev, SIS_APSIZE, &temp_size);
  24. values = A_SIZE_8(agp_bridge->driver->aperture_sizes);
  25. for (i = 0; i < agp_bridge->driver->num_aperture_sizes; i++) {
  26. if ((temp_size == values[i].size_value) ||
  27. ((temp_size & ~(0x07)) ==
  28. (values[i].size_value & ~(0x07)))) {
  29. agp_bridge->previous_size =
  30. agp_bridge->current_size = (void *) (values + i);
  31. agp_bridge->aperture_size_idx = i;
  32. return values[i].size;
  33. }
  34. }
  35. return 0;
  36. }
  37. static void sis_tlbflush(struct agp_memory *mem)
  38. {
  39. pci_write_config_byte(agp_bridge->dev, SIS_TLBFLUSH, 0x02);
  40. }
  41. static int sis_configure(void)
  42. {
  43. u32 temp;
  44. struct aper_size_info_8 *current_size;
  45. current_size = A_SIZE_8(agp_bridge->current_size);
  46. pci_write_config_byte(agp_bridge->dev, SIS_TLBCNTRL, 0x05);
  47. pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
  48. agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
  49. pci_write_config_dword(agp_bridge->dev, SIS_ATTBASE,
  50. agp_bridge->gatt_bus_addr);
  51. pci_write_config_byte(agp_bridge->dev, SIS_APSIZE,
  52. current_size->size_value);
  53. return 0;
  54. }
  55. static void sis_cleanup(void)
  56. {
  57. struct aper_size_info_8 *previous_size;
  58. previous_size = A_SIZE_8(agp_bridge->previous_size);
  59. pci_write_config_byte(agp_bridge->dev, SIS_APSIZE,
  60. (previous_size->size_value & ~(0x03)));
  61. }
  62. static void sis_delayed_enable(struct agp_bridge_data *bridge, u32 mode)
  63. {
  64. struct pci_dev *device = NULL;
  65. u32 command;
  66. int rate;
  67. dev_info(&agp_bridge->dev->dev, "AGP %d.%d bridge\n",
  68. agp_bridge->major_version, agp_bridge->minor_version);
  69. pci_read_config_dword(agp_bridge->dev, agp_bridge->capndx + PCI_AGP_STATUS, &command);
  70. command = agp_collect_device_status(bridge, mode, command);
  71. command |= AGPSTAT_AGP_ENABLE;
  72. rate = (command & 0x7) << 2;
  73. for_each_pci_dev(device) {
  74. u8 agp = pci_find_capability(device, PCI_CAP_ID_AGP);
  75. if (!agp)
  76. continue;
  77. dev_info(&agp_bridge->dev->dev, "putting AGP V3 device at %s into %dx mode\n",
  78. pci_name(device), rate);
  79. pci_write_config_dword(device, agp + PCI_AGP_COMMAND, command);
  80. /*
  81. * Weird: on some sis chipsets any rate change in the target
  82. * command register triggers a 5ms screwup during which the master
  83. * cannot be configured
  84. */
  85. if (device->device == bridge->dev->device) {
  86. dev_info(&agp_bridge->dev->dev, "SiS delay workaround: giving bridge time to recover\n");
  87. msleep(10);
  88. }
  89. }
  90. }
  91. static const struct aper_size_info_8 sis_generic_sizes[7] =
  92. {
  93. {256, 65536, 6, 99},
  94. {128, 32768, 5, 83},
  95. {64, 16384, 4, 67},
  96. {32, 8192, 3, 51},
  97. {16, 4096, 2, 35},
  98. {8, 2048, 1, 19},
  99. {4, 1024, 0, 3}
  100. };
  101. static struct agp_bridge_driver sis_driver = {
  102. .owner = THIS_MODULE,
  103. .aperture_sizes = sis_generic_sizes,
  104. .size_type = U8_APER_SIZE,
  105. .num_aperture_sizes = 7,
  106. .configure = sis_configure,
  107. .fetch_size = sis_fetch_size,
  108. .cleanup = sis_cleanup,
  109. .tlb_flush = sis_tlbflush,
  110. .mask_memory = agp_generic_mask_memory,
  111. .masks = NULL,
  112. .agp_enable = agp_generic_enable,
  113. .cache_flush = global_cache_flush,
  114. .create_gatt_table = agp_generic_create_gatt_table,
  115. .free_gatt_table = agp_generic_free_gatt_table,
  116. .insert_memory = agp_generic_insert_memory,
  117. .remove_memory = agp_generic_remove_memory,
  118. .alloc_by_type = agp_generic_alloc_by_type,
  119. .free_by_type = agp_generic_free_by_type,
  120. .agp_alloc_page = agp_generic_alloc_page,
  121. .agp_destroy_page = agp_generic_destroy_page,
  122. .agp_type_to_mask_type = agp_generic_type_to_mask_type,
  123. };
  124. // chipsets that require the 'delay hack'
  125. static int sis_broken_chipsets[] __devinitdata = {
  126. PCI_DEVICE_ID_SI_648,
  127. PCI_DEVICE_ID_SI_746,
  128. 0 // terminator
  129. };
  130. static void __devinit sis_get_driver(struct agp_bridge_data *bridge)
  131. {
  132. int i;
  133. for (i=0; sis_broken_chipsets[i]!=0; ++i)
  134. if (bridge->dev->device==sis_broken_chipsets[i])
  135. break;
  136. if (sis_broken_chipsets[i] || agp_sis_force_delay)
  137. sis_driver.agp_enable=sis_delayed_enable;
  138. // sis chipsets that indicate less than agp3.5
  139. // are not actually fully agp3 compliant
  140. if ((agp_bridge->major_version == 3 && agp_bridge->minor_version >= 5
  141. && agp_sis_agp_spec!=0) || agp_sis_agp_spec==1) {
  142. sis_driver.aperture_sizes = agp3_generic_sizes;
  143. sis_driver.size_type = U16_APER_SIZE;
  144. sis_driver.num_aperture_sizes = AGP_GENERIC_SIZES_ENTRIES;
  145. sis_driver.configure = agp3_generic_configure;
  146. sis_driver.fetch_size = agp3_generic_fetch_size;
  147. sis_driver.cleanup = agp3_generic_cleanup;
  148. sis_driver.tlb_flush = agp3_generic_tlbflush;
  149. }
  150. }
  151. static int __devinit agp_sis_probe(struct pci_dev *pdev,
  152. const struct pci_device_id *ent)
  153. {
  154. struct agp_bridge_data *bridge;
  155. u8 cap_ptr;
  156. cap_ptr = pci_find_capability(pdev, PCI_CAP_ID_AGP);
  157. if (!cap_ptr)
  158. return -ENODEV;
  159. dev_info(&pdev->dev, "SiS chipset [%04x/%04x]\n",
  160. pdev->vendor, pdev->device);
  161. bridge = agp_alloc_bridge();
  162. if (!bridge)
  163. return -ENOMEM;
  164. bridge->driver = &sis_driver;
  165. bridge->dev = pdev;
  166. bridge->capndx = cap_ptr;
  167. get_agp_version(bridge);
  168. /* Fill in the mode register */
  169. pci_read_config_dword(pdev, bridge->capndx+PCI_AGP_STATUS, &bridge->mode);
  170. sis_get_driver(bridge);
  171. pci_set_drvdata(pdev, bridge);
  172. return agp_add_bridge(bridge);
  173. }
  174. static void __devexit agp_sis_remove(struct pci_dev *pdev)
  175. {
  176. struct agp_bridge_data *bridge = pci_get_drvdata(pdev);
  177. agp_remove_bridge(bridge);
  178. agp_put_bridge(bridge);
  179. }
  180. #ifdef CONFIG_PM
  181. static int agp_sis_suspend(struct pci_dev *pdev, pm_message_t state)
  182. {
  183. pci_save_state(pdev);
  184. pci_set_power_state(pdev, pci_choose_state(pdev, state));
  185. return 0;
  186. }
  187. static int agp_sis_resume(struct pci_dev *pdev)
  188. {
  189. pci_set_power_state(pdev, PCI_D0);
  190. pci_restore_state(pdev);
  191. return sis_driver.configure();
  192. }
  193. #endif /* CONFIG_PM */
  194. static struct pci_device_id agp_sis_pci_table[] = {
  195. {
  196. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  197. .class_mask = ~0,
  198. .vendor = PCI_VENDOR_ID_SI,
  199. .device = PCI_DEVICE_ID_SI_5591_AGP,
  200. .subvendor = PCI_ANY_ID,
  201. .subdevice = PCI_ANY_ID,
  202. },
  203. {
  204. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  205. .class_mask = ~0,
  206. .vendor = PCI_VENDOR_ID_SI,
  207. .device = PCI_DEVICE_ID_SI_530,
  208. .subvendor = PCI_ANY_ID,
  209. .subdevice = PCI_ANY_ID,
  210. },
  211. {
  212. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  213. .class_mask = ~0,
  214. .vendor = PCI_VENDOR_ID_SI,
  215. .device = PCI_DEVICE_ID_SI_540,
  216. .subvendor = PCI_ANY_ID,
  217. .subdevice = PCI_ANY_ID,
  218. },
  219. {
  220. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  221. .class_mask = ~0,
  222. .vendor = PCI_VENDOR_ID_SI,
  223. .device = PCI_DEVICE_ID_SI_550,
  224. .subvendor = PCI_ANY_ID,
  225. .subdevice = PCI_ANY_ID,
  226. },
  227. {
  228. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  229. .class_mask = ~0,
  230. .vendor = PCI_VENDOR_ID_SI,
  231. .device = PCI_DEVICE_ID_SI_620,
  232. .subvendor = PCI_ANY_ID,
  233. .subdevice = PCI_ANY_ID,
  234. },
  235. {
  236. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  237. .class_mask = ~0,
  238. .vendor = PCI_VENDOR_ID_SI,
  239. .device = PCI_DEVICE_ID_SI_630,
  240. .subvendor = PCI_ANY_ID,
  241. .subdevice = PCI_ANY_ID,
  242. },
  243. {
  244. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  245. .class_mask = ~0,
  246. .vendor = PCI_VENDOR_ID_SI,
  247. .device = PCI_DEVICE_ID_SI_635,
  248. .subvendor = PCI_ANY_ID,
  249. .subdevice = PCI_ANY_ID,
  250. },
  251. {
  252. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  253. .class_mask = ~0,
  254. .vendor = PCI_VENDOR_ID_SI,
  255. .device = PCI_DEVICE_ID_SI_645,
  256. .subvendor = PCI_ANY_ID,
  257. .subdevice = PCI_ANY_ID,
  258. },
  259. {
  260. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  261. .class_mask = ~0,
  262. .vendor = PCI_VENDOR_ID_SI,
  263. .device = PCI_DEVICE_ID_SI_646,
  264. .subvendor = PCI_ANY_ID,
  265. .subdevice = PCI_ANY_ID,
  266. },
  267. {
  268. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  269. .class_mask = ~0,
  270. .vendor = PCI_VENDOR_ID_SI,
  271. .device = PCI_DEVICE_ID_SI_648,
  272. .subvendor = PCI_ANY_ID,
  273. .subdevice = PCI_ANY_ID,
  274. },
  275. {
  276. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  277. .class_mask = ~0,
  278. .vendor = PCI_VENDOR_ID_SI,
  279. .device = PCI_DEVICE_ID_SI_650,
  280. .subvendor = PCI_ANY_ID,
  281. .subdevice = PCI_ANY_ID,
  282. },
  283. {
  284. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  285. .class_mask = ~0,
  286. .vendor = PCI_VENDOR_ID_SI,
  287. .device = PCI_DEVICE_ID_SI_651,
  288. .subvendor = PCI_ANY_ID,
  289. .subdevice = PCI_ANY_ID,
  290. },
  291. {
  292. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  293. .class_mask = ~0,
  294. .vendor = PCI_VENDOR_ID_SI,
  295. .device = PCI_DEVICE_ID_SI_655,
  296. .subvendor = PCI_ANY_ID,
  297. .subdevice = PCI_ANY_ID,
  298. },
  299. {
  300. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  301. .class_mask = ~0,
  302. .vendor = PCI_VENDOR_ID_SI,
  303. .device = PCI_DEVICE_ID_SI_661,
  304. .subvendor = PCI_ANY_ID,
  305. .subdevice = PCI_ANY_ID,
  306. },
  307. {
  308. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  309. .class_mask = ~0,
  310. .vendor = PCI_VENDOR_ID_SI,
  311. .device = PCI_DEVICE_ID_SI_662,
  312. .subvendor = PCI_ANY_ID,
  313. .subdevice = PCI_ANY_ID,
  314. },
  315. {
  316. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  317. .class_mask = ~0,
  318. .vendor = PCI_VENDOR_ID_SI,
  319. .device = PCI_DEVICE_ID_SI_671,
  320. .subvendor = PCI_ANY_ID,
  321. .subdevice = PCI_ANY_ID,
  322. },
  323. {
  324. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  325. .class_mask = ~0,
  326. .vendor = PCI_VENDOR_ID_SI,
  327. .device = PCI_DEVICE_ID_SI_730,
  328. .subvendor = PCI_ANY_ID,
  329. .subdevice = PCI_ANY_ID,
  330. },
  331. {
  332. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  333. .class_mask = ~0,
  334. .vendor = PCI_VENDOR_ID_SI,
  335. .device = PCI_DEVICE_ID_SI_735,
  336. .subvendor = PCI_ANY_ID,
  337. .subdevice = PCI_ANY_ID,
  338. },
  339. {
  340. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  341. .class_mask = ~0,
  342. .vendor = PCI_VENDOR_ID_SI,
  343. .device = PCI_DEVICE_ID_SI_740,
  344. .subvendor = PCI_ANY_ID,
  345. .subdevice = PCI_ANY_ID,
  346. },
  347. {
  348. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  349. .class_mask = ~0,
  350. .vendor = PCI_VENDOR_ID_SI,
  351. .device = PCI_DEVICE_ID_SI_741,
  352. .subvendor = PCI_ANY_ID,
  353. .subdevice = PCI_ANY_ID,
  354. },
  355. {
  356. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  357. .class_mask = ~0,
  358. .vendor = PCI_VENDOR_ID_SI,
  359. .device = PCI_DEVICE_ID_SI_745,
  360. .subvendor = PCI_ANY_ID,
  361. .subdevice = PCI_ANY_ID,
  362. },
  363. {
  364. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  365. .class_mask = ~0,
  366. .vendor = PCI_VENDOR_ID_SI,
  367. .device = PCI_DEVICE_ID_SI_746,
  368. .subvendor = PCI_ANY_ID,
  369. .subdevice = PCI_ANY_ID,
  370. },
  371. {
  372. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  373. .class_mask = ~0,
  374. .vendor = PCI_VENDOR_ID_SI,
  375. .device = PCI_DEVICE_ID_SI_760,
  376. .subvendor = PCI_ANY_ID,
  377. .subdevice = PCI_ANY_ID,
  378. },
  379. { }
  380. };
  381. MODULE_DEVICE_TABLE(pci, agp_sis_pci_table);
  382. static struct pci_driver agp_sis_pci_driver = {
  383. .name = "agpgart-sis",
  384. .id_table = agp_sis_pci_table,
  385. .probe = agp_sis_probe,
  386. .remove = agp_sis_remove,
  387. #ifdef CONFIG_PM
  388. .suspend = agp_sis_suspend,
  389. .resume = agp_sis_resume,
  390. #endif
  391. };
  392. static int __init agp_sis_init(void)
  393. {
  394. if (agp_off)
  395. return -EINVAL;
  396. return pci_register_driver(&agp_sis_pci_driver);
  397. }
  398. static void __exit agp_sis_cleanup(void)
  399. {
  400. pci_unregister_driver(&agp_sis_pci_driver);
  401. }
  402. module_init(agp_sis_init);
  403. module_exit(agp_sis_cleanup);
  404. module_param(agp_sis_force_delay, bool, 0);
  405. MODULE_PARM_DESC(agp_sis_force_delay,"forces sis delay hack");
  406. module_param(agp_sis_agp_spec, int, 0);
  407. MODULE_PARM_DESC(agp_sis_agp_spec,"0=force sis init, 1=force generic agp3 init, default: autodetect");
  408. MODULE_LICENSE("GPL and additional rights");