sis-agp.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  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 bool agp_sis_force_delay = 0;
  17. static int 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. struct aper_size_info_8 *current_size;
  44. current_size = A_SIZE_8(agp_bridge->current_size);
  45. pci_write_config_byte(agp_bridge->dev, SIS_TLBCNTRL, 0x05);
  46. agp_bridge->gart_bus_addr = pci_bus_address(agp_bridge->dev,
  47. AGP_APERTURE_BAR);
  48. pci_write_config_dword(agp_bridge->dev, SIS_ATTBASE,
  49. agp_bridge->gatt_bus_addr);
  50. pci_write_config_byte(agp_bridge->dev, SIS_APSIZE,
  51. current_size->size_value);
  52. return 0;
  53. }
  54. static void sis_cleanup(void)
  55. {
  56. struct aper_size_info_8 *previous_size;
  57. previous_size = A_SIZE_8(agp_bridge->previous_size);
  58. pci_write_config_byte(agp_bridge->dev, SIS_APSIZE,
  59. (previous_size->size_value & ~(0x03)));
  60. }
  61. static void sis_delayed_enable(struct agp_bridge_data *bridge, u32 mode)
  62. {
  63. struct pci_dev *device = NULL;
  64. u32 command;
  65. int rate;
  66. dev_info(&agp_bridge->dev->dev, "AGP %d.%d bridge\n",
  67. agp_bridge->major_version, agp_bridge->minor_version);
  68. pci_read_config_dword(agp_bridge->dev, agp_bridge->capndx + PCI_AGP_STATUS, &command);
  69. command = agp_collect_device_status(bridge, mode, command);
  70. command |= AGPSTAT_AGP_ENABLE;
  71. rate = (command & 0x7) << 2;
  72. for_each_pci_dev(device) {
  73. u8 agp = pci_find_capability(device, PCI_CAP_ID_AGP);
  74. if (!agp)
  75. continue;
  76. dev_info(&agp_bridge->dev->dev, "putting AGP V3 device at %s into %dx mode\n",
  77. pci_name(device), rate);
  78. pci_write_config_dword(device, agp + PCI_AGP_COMMAND, command);
  79. /*
  80. * Weird: on some sis chipsets any rate change in the target
  81. * command register triggers a 5ms screwup during which the master
  82. * cannot be configured
  83. */
  84. if (device->device == bridge->dev->device) {
  85. dev_info(&agp_bridge->dev->dev, "SiS delay workaround: giving bridge time to recover\n");
  86. msleep(10);
  87. }
  88. }
  89. }
  90. static const struct aper_size_info_8 sis_generic_sizes[7] =
  91. {
  92. {256, 65536, 6, 99},
  93. {128, 32768, 5, 83},
  94. {64, 16384, 4, 67},
  95. {32, 8192, 3, 51},
  96. {16, 4096, 2, 35},
  97. {8, 2048, 1, 19},
  98. {4, 1024, 0, 3}
  99. };
  100. static struct agp_bridge_driver sis_driver = {
  101. .owner = THIS_MODULE,
  102. .aperture_sizes = sis_generic_sizes,
  103. .size_type = U8_APER_SIZE,
  104. .num_aperture_sizes = 7,
  105. .needs_scratch_page = true,
  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_alloc_pages = agp_generic_alloc_pages,
  122. .agp_destroy_page = agp_generic_destroy_page,
  123. .agp_destroy_pages = agp_generic_destroy_pages,
  124. .agp_type_to_mask_type = agp_generic_type_to_mask_type,
  125. };
  126. // chipsets that require the 'delay hack'
  127. static int sis_broken_chipsets[] = {
  128. PCI_DEVICE_ID_SI_648,
  129. PCI_DEVICE_ID_SI_746,
  130. 0 // terminator
  131. };
  132. static void sis_get_driver(struct agp_bridge_data *bridge)
  133. {
  134. int i;
  135. for (i=0; sis_broken_chipsets[i]!=0; ++i)
  136. if (bridge->dev->device==sis_broken_chipsets[i])
  137. break;
  138. if (sis_broken_chipsets[i] || agp_sis_force_delay)
  139. sis_driver.agp_enable=sis_delayed_enable;
  140. // sis chipsets that indicate less than agp3.5
  141. // are not actually fully agp3 compliant
  142. if ((agp_bridge->major_version == 3 && agp_bridge->minor_version >= 5
  143. && agp_sis_agp_spec!=0) || agp_sis_agp_spec==1) {
  144. sis_driver.aperture_sizes = agp3_generic_sizes;
  145. sis_driver.size_type = U16_APER_SIZE;
  146. sis_driver.num_aperture_sizes = AGP_GENERIC_SIZES_ENTRIES;
  147. sis_driver.configure = agp3_generic_configure;
  148. sis_driver.fetch_size = agp3_generic_fetch_size;
  149. sis_driver.cleanup = agp3_generic_cleanup;
  150. sis_driver.tlb_flush = agp3_generic_tlbflush;
  151. }
  152. }
  153. static int agp_sis_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  154. {
  155. struct agp_bridge_data *bridge;
  156. u8 cap_ptr;
  157. cap_ptr = pci_find_capability(pdev, PCI_CAP_ID_AGP);
  158. if (!cap_ptr)
  159. return -ENODEV;
  160. dev_info(&pdev->dev, "SiS chipset [%04x/%04x]\n",
  161. pdev->vendor, pdev->device);
  162. bridge = agp_alloc_bridge();
  163. if (!bridge)
  164. return -ENOMEM;
  165. bridge->driver = &sis_driver;
  166. bridge->dev = pdev;
  167. bridge->capndx = cap_ptr;
  168. get_agp_version(bridge);
  169. /* Fill in the mode register */
  170. pci_read_config_dword(pdev, bridge->capndx+PCI_AGP_STATUS, &bridge->mode);
  171. sis_get_driver(bridge);
  172. pci_set_drvdata(pdev, bridge);
  173. return agp_add_bridge(bridge);
  174. }
  175. static void agp_sis_remove(struct pci_dev *pdev)
  176. {
  177. struct agp_bridge_data *bridge = pci_get_drvdata(pdev);
  178. agp_remove_bridge(bridge);
  179. agp_put_bridge(bridge);
  180. }
  181. static int agp_sis_resume(__attribute__((unused)) struct device *dev)
  182. {
  183. return sis_driver.configure();
  184. }
  185. static const struct pci_device_id agp_sis_pci_table[] = {
  186. {
  187. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  188. .class_mask = ~0,
  189. .vendor = PCI_VENDOR_ID_SI,
  190. .device = PCI_DEVICE_ID_SI_5591,
  191. .subvendor = PCI_ANY_ID,
  192. .subdevice = PCI_ANY_ID,
  193. },
  194. {
  195. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  196. .class_mask = ~0,
  197. .vendor = PCI_VENDOR_ID_SI,
  198. .device = PCI_DEVICE_ID_SI_530,
  199. .subvendor = PCI_ANY_ID,
  200. .subdevice = PCI_ANY_ID,
  201. },
  202. {
  203. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  204. .class_mask = ~0,
  205. .vendor = PCI_VENDOR_ID_SI,
  206. .device = PCI_DEVICE_ID_SI_540,
  207. .subvendor = PCI_ANY_ID,
  208. .subdevice = PCI_ANY_ID,
  209. },
  210. {
  211. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  212. .class_mask = ~0,
  213. .vendor = PCI_VENDOR_ID_SI,
  214. .device = PCI_DEVICE_ID_SI_550,
  215. .subvendor = PCI_ANY_ID,
  216. .subdevice = PCI_ANY_ID,
  217. },
  218. {
  219. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  220. .class_mask = ~0,
  221. .vendor = PCI_VENDOR_ID_SI,
  222. .device = PCI_DEVICE_ID_SI_620,
  223. .subvendor = PCI_ANY_ID,
  224. .subdevice = PCI_ANY_ID,
  225. },
  226. {
  227. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  228. .class_mask = ~0,
  229. .vendor = PCI_VENDOR_ID_SI,
  230. .device = PCI_DEVICE_ID_SI_630,
  231. .subvendor = PCI_ANY_ID,
  232. .subdevice = PCI_ANY_ID,
  233. },
  234. {
  235. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  236. .class_mask = ~0,
  237. .vendor = PCI_VENDOR_ID_SI,
  238. .device = PCI_DEVICE_ID_SI_635,
  239. .subvendor = PCI_ANY_ID,
  240. .subdevice = PCI_ANY_ID,
  241. },
  242. {
  243. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  244. .class_mask = ~0,
  245. .vendor = PCI_VENDOR_ID_SI,
  246. .device = PCI_DEVICE_ID_SI_645,
  247. .subvendor = PCI_ANY_ID,
  248. .subdevice = PCI_ANY_ID,
  249. },
  250. {
  251. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  252. .class_mask = ~0,
  253. .vendor = PCI_VENDOR_ID_SI,
  254. .device = PCI_DEVICE_ID_SI_646,
  255. .subvendor = PCI_ANY_ID,
  256. .subdevice = PCI_ANY_ID,
  257. },
  258. {
  259. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  260. .class_mask = ~0,
  261. .vendor = PCI_VENDOR_ID_SI,
  262. .device = PCI_DEVICE_ID_SI_648,
  263. .subvendor = PCI_ANY_ID,
  264. .subdevice = PCI_ANY_ID,
  265. },
  266. {
  267. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  268. .class_mask = ~0,
  269. .vendor = PCI_VENDOR_ID_SI,
  270. .device = PCI_DEVICE_ID_SI_650,
  271. .subvendor = PCI_ANY_ID,
  272. .subdevice = PCI_ANY_ID,
  273. },
  274. {
  275. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  276. .class_mask = ~0,
  277. .vendor = PCI_VENDOR_ID_SI,
  278. .device = PCI_DEVICE_ID_SI_651,
  279. .subvendor = PCI_ANY_ID,
  280. .subdevice = PCI_ANY_ID,
  281. },
  282. {
  283. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  284. .class_mask = ~0,
  285. .vendor = PCI_VENDOR_ID_SI,
  286. .device = PCI_DEVICE_ID_SI_655,
  287. .subvendor = PCI_ANY_ID,
  288. .subdevice = PCI_ANY_ID,
  289. },
  290. {
  291. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  292. .class_mask = ~0,
  293. .vendor = PCI_VENDOR_ID_SI,
  294. .device = PCI_DEVICE_ID_SI_661,
  295. .subvendor = PCI_ANY_ID,
  296. .subdevice = PCI_ANY_ID,
  297. },
  298. {
  299. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  300. .class_mask = ~0,
  301. .vendor = PCI_VENDOR_ID_SI,
  302. .device = PCI_DEVICE_ID_SI_662,
  303. .subvendor = PCI_ANY_ID,
  304. .subdevice = PCI_ANY_ID,
  305. },
  306. {
  307. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  308. .class_mask = ~0,
  309. .vendor = PCI_VENDOR_ID_SI,
  310. .device = PCI_DEVICE_ID_SI_671,
  311. .subvendor = PCI_ANY_ID,
  312. .subdevice = PCI_ANY_ID,
  313. },
  314. {
  315. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  316. .class_mask = ~0,
  317. .vendor = PCI_VENDOR_ID_SI,
  318. .device = PCI_DEVICE_ID_SI_730,
  319. .subvendor = PCI_ANY_ID,
  320. .subdevice = PCI_ANY_ID,
  321. },
  322. {
  323. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  324. .class_mask = ~0,
  325. .vendor = PCI_VENDOR_ID_SI,
  326. .device = PCI_DEVICE_ID_SI_735,
  327. .subvendor = PCI_ANY_ID,
  328. .subdevice = PCI_ANY_ID,
  329. },
  330. {
  331. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  332. .class_mask = ~0,
  333. .vendor = PCI_VENDOR_ID_SI,
  334. .device = PCI_DEVICE_ID_SI_740,
  335. .subvendor = PCI_ANY_ID,
  336. .subdevice = PCI_ANY_ID,
  337. },
  338. {
  339. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  340. .class_mask = ~0,
  341. .vendor = PCI_VENDOR_ID_SI,
  342. .device = PCI_DEVICE_ID_SI_741,
  343. .subvendor = PCI_ANY_ID,
  344. .subdevice = PCI_ANY_ID,
  345. },
  346. {
  347. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  348. .class_mask = ~0,
  349. .vendor = PCI_VENDOR_ID_SI,
  350. .device = PCI_DEVICE_ID_SI_745,
  351. .subvendor = PCI_ANY_ID,
  352. .subdevice = PCI_ANY_ID,
  353. },
  354. {
  355. .class = (PCI_CLASS_BRIDGE_HOST << 8),
  356. .class_mask = ~0,
  357. .vendor = PCI_VENDOR_ID_SI,
  358. .device = PCI_DEVICE_ID_SI_746,
  359. .subvendor = PCI_ANY_ID,
  360. .subdevice = PCI_ANY_ID,
  361. },
  362. { }
  363. };
  364. MODULE_DEVICE_TABLE(pci, agp_sis_pci_table);
  365. static DEFINE_SIMPLE_DEV_PM_OPS(agp_sis_pm_ops, NULL, agp_sis_resume);
  366. static struct pci_driver agp_sis_pci_driver = {
  367. .name = "agpgart-sis",
  368. .id_table = agp_sis_pci_table,
  369. .probe = agp_sis_probe,
  370. .remove = agp_sis_remove,
  371. .driver.pm = &agp_sis_pm_ops,
  372. };
  373. static int __init agp_sis_init(void)
  374. {
  375. if (agp_off)
  376. return -EINVAL;
  377. return pci_register_driver(&agp_sis_pci_driver);
  378. }
  379. static void __exit agp_sis_cleanup(void)
  380. {
  381. pci_unregister_driver(&agp_sis_pci_driver);
  382. }
  383. module_init(agp_sis_init);
  384. module_exit(agp_sis_cleanup);
  385. module_param(agp_sis_force_delay, bool, 0);
  386. MODULE_PARM_DESC(agp_sis_force_delay,"forces sis delay hack");
  387. module_param(agp_sis_agp_spec, int, 0);
  388. MODULE_PARM_DESC(agp_sis_agp_spec,"0=force sis init, 1=force generic agp3 init, default: autodetect");
  389. MODULE_DESCRIPTION("SiS AGPGART routines");
  390. MODULE_LICENSE("GPL and additional rights");