intel-agp.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937
  1. /*
  2. * Intel AGPGART routines.
  3. */
  4. #include <linux/module.h>
  5. #include <linux/pci.h>
  6. #include <linux/slab.h>
  7. #include <linux/init.h>
  8. #include <linux/kernel.h>
  9. #include <linux/pagemap.h>
  10. #include <linux/agp_backend.h>
  11. #include <asm/smp.h>
  12. #include "agp.h"
  13. #include "intel-agp.h"
  14. #include <drm/intel-gtt.h>
  15. int intel_agp_enabled;
  16. EXPORT_SYMBOL(intel_agp_enabled);
  17. static int intel_fetch_size(void)
  18. {
  19. int i;
  20. u16 temp;
  21. struct aper_size_info_16 *values;
  22. pci_read_config_word(agp_bridge->dev, INTEL_APSIZE, &temp);
  23. values = A_SIZE_16(agp_bridge->driver->aperture_sizes);
  24. for (i = 0; i < agp_bridge->driver->num_aperture_sizes; i++) {
  25. if (temp == values[i].size_value) {
  26. agp_bridge->previous_size = agp_bridge->current_size = (void *) (values + i);
  27. agp_bridge->aperture_size_idx = i;
  28. return values[i].size;
  29. }
  30. }
  31. return 0;
  32. }
  33. static int __intel_8xx_fetch_size(u8 temp)
  34. {
  35. int i;
  36. struct aper_size_info_8 *values;
  37. values = A_SIZE_8(agp_bridge->driver->aperture_sizes);
  38. for (i = 0; i < agp_bridge->driver->num_aperture_sizes; i++) {
  39. if (temp == values[i].size_value) {
  40. agp_bridge->previous_size =
  41. agp_bridge->current_size = (void *) (values + i);
  42. agp_bridge->aperture_size_idx = i;
  43. return values[i].size;
  44. }
  45. }
  46. return 0;
  47. }
  48. static int intel_8xx_fetch_size(void)
  49. {
  50. u8 temp;
  51. pci_read_config_byte(agp_bridge->dev, INTEL_APSIZE, &temp);
  52. return __intel_8xx_fetch_size(temp);
  53. }
  54. static int intel_815_fetch_size(void)
  55. {
  56. u8 temp;
  57. /* Intel 815 chipsets have a _weird_ APSIZE register with only
  58. * one non-reserved bit, so mask the others out ... */
  59. pci_read_config_byte(agp_bridge->dev, INTEL_APSIZE, &temp);
  60. temp &= (1 << 3);
  61. return __intel_8xx_fetch_size(temp);
  62. }
  63. static void intel_tlbflush(struct agp_memory *mem)
  64. {
  65. pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x2200);
  66. pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x2280);
  67. }
  68. static void intel_8xx_tlbflush(struct agp_memory *mem)
  69. {
  70. u32 temp;
  71. pci_read_config_dword(agp_bridge->dev, INTEL_AGPCTRL, &temp);
  72. pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, temp & ~(1 << 7));
  73. pci_read_config_dword(agp_bridge->dev, INTEL_AGPCTRL, &temp);
  74. pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, temp | (1 << 7));
  75. }
  76. static void intel_cleanup(void)
  77. {
  78. u16 temp;
  79. struct aper_size_info_16 *previous_size;
  80. previous_size = A_SIZE_16(agp_bridge->previous_size);
  81. pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp);
  82. pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG, temp & ~(1 << 9));
  83. pci_write_config_word(agp_bridge->dev, INTEL_APSIZE, previous_size->size_value);
  84. }
  85. static void intel_8xx_cleanup(void)
  86. {
  87. u16 temp;
  88. struct aper_size_info_8 *previous_size;
  89. previous_size = A_SIZE_8(agp_bridge->previous_size);
  90. pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp);
  91. pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG, temp & ~(1 << 9));
  92. pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, previous_size->size_value);
  93. }
  94. static int intel_configure(void)
  95. {
  96. u32 temp;
  97. u16 temp2;
  98. struct aper_size_info_16 *current_size;
  99. current_size = A_SIZE_16(agp_bridge->current_size);
  100. /* aperture size */
  101. pci_write_config_word(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
  102. /* address to map to */
  103. pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
  104. agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
  105. /* attbase - aperture base */
  106. pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
  107. /* agpctrl */
  108. pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x2280);
  109. /* paccfg/nbxcfg */
  110. pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp2);
  111. pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG,
  112. (temp2 & ~(1 << 10)) | (1 << 9));
  113. /* clear any possible error conditions */
  114. pci_write_config_byte(agp_bridge->dev, INTEL_ERRSTS + 1, 7);
  115. return 0;
  116. }
  117. static int intel_815_configure(void)
  118. {
  119. u32 temp, addr;
  120. u8 temp2;
  121. struct aper_size_info_8 *current_size;
  122. /* attbase - aperture base */
  123. /* the Intel 815 chipset spec. says that bits 29-31 in the
  124. * ATTBASE register are reserved -> try not to write them */
  125. if (agp_bridge->gatt_bus_addr & INTEL_815_ATTBASE_MASK) {
  126. dev_emerg(&agp_bridge->dev->dev, "gatt bus addr too high");
  127. return -EINVAL;
  128. }
  129. current_size = A_SIZE_8(agp_bridge->current_size);
  130. /* aperture size */
  131. pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE,
  132. current_size->size_value);
  133. /* address to map to */
  134. pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
  135. agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
  136. pci_read_config_dword(agp_bridge->dev, INTEL_ATTBASE, &addr);
  137. addr &= INTEL_815_ATTBASE_MASK;
  138. addr |= agp_bridge->gatt_bus_addr;
  139. pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, addr);
  140. /* agpctrl */
  141. pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
  142. /* apcont */
  143. pci_read_config_byte(agp_bridge->dev, INTEL_815_APCONT, &temp2);
  144. pci_write_config_byte(agp_bridge->dev, INTEL_815_APCONT, temp2 | (1 << 1));
  145. /* clear any possible error conditions */
  146. /* Oddness : this chipset seems to have no ERRSTS register ! */
  147. return 0;
  148. }
  149. static void intel_820_tlbflush(struct agp_memory *mem)
  150. {
  151. return;
  152. }
  153. static void intel_820_cleanup(void)
  154. {
  155. u8 temp;
  156. struct aper_size_info_8 *previous_size;
  157. previous_size = A_SIZE_8(agp_bridge->previous_size);
  158. pci_read_config_byte(agp_bridge->dev, INTEL_I820_RDCR, &temp);
  159. pci_write_config_byte(agp_bridge->dev, INTEL_I820_RDCR,
  160. temp & ~(1 << 1));
  161. pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE,
  162. previous_size->size_value);
  163. }
  164. static int intel_820_configure(void)
  165. {
  166. u32 temp;
  167. u8 temp2;
  168. struct aper_size_info_8 *current_size;
  169. current_size = A_SIZE_8(agp_bridge->current_size);
  170. /* aperture size */
  171. pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
  172. /* address to map to */
  173. pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
  174. agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
  175. /* attbase - aperture base */
  176. pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
  177. /* agpctrl */
  178. pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
  179. /* global enable aperture access */
  180. /* This flag is not accessed through MCHCFG register as in */
  181. /* i850 chipset. */
  182. pci_read_config_byte(agp_bridge->dev, INTEL_I820_RDCR, &temp2);
  183. pci_write_config_byte(agp_bridge->dev, INTEL_I820_RDCR, temp2 | (1 << 1));
  184. /* clear any possible AGP-related error conditions */
  185. pci_write_config_word(agp_bridge->dev, INTEL_I820_ERRSTS, 0x001c);
  186. return 0;
  187. }
  188. static int intel_840_configure(void)
  189. {
  190. u32 temp;
  191. u16 temp2;
  192. struct aper_size_info_8 *current_size;
  193. current_size = A_SIZE_8(agp_bridge->current_size);
  194. /* aperture size */
  195. pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
  196. /* address to map to */
  197. pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
  198. agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
  199. /* attbase - aperture base */
  200. pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
  201. /* agpctrl */
  202. pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
  203. /* mcgcfg */
  204. pci_read_config_word(agp_bridge->dev, INTEL_I840_MCHCFG, &temp2);
  205. pci_write_config_word(agp_bridge->dev, INTEL_I840_MCHCFG, temp2 | (1 << 9));
  206. /* clear any possible error conditions */
  207. pci_write_config_word(agp_bridge->dev, INTEL_I840_ERRSTS, 0xc000);
  208. return 0;
  209. }
  210. static int intel_845_configure(void)
  211. {
  212. u32 temp;
  213. u8 temp2;
  214. struct aper_size_info_8 *current_size;
  215. current_size = A_SIZE_8(agp_bridge->current_size);
  216. /* aperture size */
  217. pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
  218. if (agp_bridge->apbase_config != 0) {
  219. pci_write_config_dword(agp_bridge->dev, AGP_APBASE,
  220. agp_bridge->apbase_config);
  221. } else {
  222. /* address to map to */
  223. pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
  224. agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
  225. agp_bridge->apbase_config = temp;
  226. }
  227. /* attbase - aperture base */
  228. pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
  229. /* agpctrl */
  230. pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
  231. /* agpm */
  232. pci_read_config_byte(agp_bridge->dev, INTEL_I845_AGPM, &temp2);
  233. pci_write_config_byte(agp_bridge->dev, INTEL_I845_AGPM, temp2 | (1 << 1));
  234. /* clear any possible error conditions */
  235. pci_write_config_word(agp_bridge->dev, INTEL_I845_ERRSTS, 0x001c);
  236. return 0;
  237. }
  238. static int intel_850_configure(void)
  239. {
  240. u32 temp;
  241. u16 temp2;
  242. struct aper_size_info_8 *current_size;
  243. current_size = A_SIZE_8(agp_bridge->current_size);
  244. /* aperture size */
  245. pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
  246. /* address to map to */
  247. pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
  248. agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
  249. /* attbase - aperture base */
  250. pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
  251. /* agpctrl */
  252. pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
  253. /* mcgcfg */
  254. pci_read_config_word(agp_bridge->dev, INTEL_I850_MCHCFG, &temp2);
  255. pci_write_config_word(agp_bridge->dev, INTEL_I850_MCHCFG, temp2 | (1 << 9));
  256. /* clear any possible AGP-related error conditions */
  257. pci_write_config_word(agp_bridge->dev, INTEL_I850_ERRSTS, 0x001c);
  258. return 0;
  259. }
  260. static int intel_860_configure(void)
  261. {
  262. u32 temp;
  263. u16 temp2;
  264. struct aper_size_info_8 *current_size;
  265. current_size = A_SIZE_8(agp_bridge->current_size);
  266. /* aperture size */
  267. pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
  268. /* address to map to */
  269. pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
  270. agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
  271. /* attbase - aperture base */
  272. pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
  273. /* agpctrl */
  274. pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
  275. /* mcgcfg */
  276. pci_read_config_word(agp_bridge->dev, INTEL_I860_MCHCFG, &temp2);
  277. pci_write_config_word(agp_bridge->dev, INTEL_I860_MCHCFG, temp2 | (1 << 9));
  278. /* clear any possible AGP-related error conditions */
  279. pci_write_config_word(agp_bridge->dev, INTEL_I860_ERRSTS, 0xf700);
  280. return 0;
  281. }
  282. static int intel_830mp_configure(void)
  283. {
  284. u32 temp;
  285. u16 temp2;
  286. struct aper_size_info_8 *current_size;
  287. current_size = A_SIZE_8(agp_bridge->current_size);
  288. /* aperture size */
  289. pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
  290. /* address to map to */
  291. pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
  292. agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
  293. /* attbase - aperture base */
  294. pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
  295. /* agpctrl */
  296. pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
  297. /* gmch */
  298. pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp2);
  299. pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG, temp2 | (1 << 9));
  300. /* clear any possible AGP-related error conditions */
  301. pci_write_config_word(agp_bridge->dev, INTEL_I830_ERRSTS, 0x1c);
  302. return 0;
  303. }
  304. static int intel_7505_configure(void)
  305. {
  306. u32 temp;
  307. u16 temp2;
  308. struct aper_size_info_8 *current_size;
  309. current_size = A_SIZE_8(agp_bridge->current_size);
  310. /* aperture size */
  311. pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
  312. /* address to map to */
  313. pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
  314. agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
  315. /* attbase - aperture base */
  316. pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
  317. /* agpctrl */
  318. pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
  319. /* mchcfg */
  320. pci_read_config_word(agp_bridge->dev, INTEL_I7505_MCHCFG, &temp2);
  321. pci_write_config_word(agp_bridge->dev, INTEL_I7505_MCHCFG, temp2 | (1 << 9));
  322. return 0;
  323. }
  324. /* Setup function */
  325. static const struct gatt_mask intel_generic_masks[] =
  326. {
  327. {.mask = 0x00000017, .type = 0}
  328. };
  329. static const struct aper_size_info_8 intel_815_sizes[2] =
  330. {
  331. {64, 16384, 4, 0},
  332. {32, 8192, 3, 8},
  333. };
  334. static const struct aper_size_info_8 intel_8xx_sizes[7] =
  335. {
  336. {256, 65536, 6, 0},
  337. {128, 32768, 5, 32},
  338. {64, 16384, 4, 48},
  339. {32, 8192, 3, 56},
  340. {16, 4096, 2, 60},
  341. {8, 2048, 1, 62},
  342. {4, 1024, 0, 63}
  343. };
  344. static const struct aper_size_info_16 intel_generic_sizes[7] =
  345. {
  346. {256, 65536, 6, 0},
  347. {128, 32768, 5, 32},
  348. {64, 16384, 4, 48},
  349. {32, 8192, 3, 56},
  350. {16, 4096, 2, 60},
  351. {8, 2048, 1, 62},
  352. {4, 1024, 0, 63}
  353. };
  354. static const struct aper_size_info_8 intel_830mp_sizes[4] =
  355. {
  356. {256, 65536, 6, 0},
  357. {128, 32768, 5, 32},
  358. {64, 16384, 4, 48},
  359. {32, 8192, 3, 56}
  360. };
  361. static const struct agp_bridge_driver intel_generic_driver = {
  362. .owner = THIS_MODULE,
  363. .aperture_sizes = intel_generic_sizes,
  364. .size_type = U16_APER_SIZE,
  365. .num_aperture_sizes = 7,
  366. .needs_scratch_page = true,
  367. .configure = intel_configure,
  368. .fetch_size = intel_fetch_size,
  369. .cleanup = intel_cleanup,
  370. .tlb_flush = intel_tlbflush,
  371. .mask_memory = agp_generic_mask_memory,
  372. .masks = intel_generic_masks,
  373. .agp_enable = agp_generic_enable,
  374. .cache_flush = global_cache_flush,
  375. .create_gatt_table = agp_generic_create_gatt_table,
  376. .free_gatt_table = agp_generic_free_gatt_table,
  377. .insert_memory = agp_generic_insert_memory,
  378. .remove_memory = agp_generic_remove_memory,
  379. .alloc_by_type = agp_generic_alloc_by_type,
  380. .free_by_type = agp_generic_free_by_type,
  381. .agp_alloc_page = agp_generic_alloc_page,
  382. .agp_alloc_pages = agp_generic_alloc_pages,
  383. .agp_destroy_page = agp_generic_destroy_page,
  384. .agp_destroy_pages = agp_generic_destroy_pages,
  385. .agp_type_to_mask_type = agp_generic_type_to_mask_type,
  386. };
  387. static const struct agp_bridge_driver intel_815_driver = {
  388. .owner = THIS_MODULE,
  389. .aperture_sizes = intel_815_sizes,
  390. .size_type = U8_APER_SIZE,
  391. .num_aperture_sizes = 2,
  392. .needs_scratch_page = true,
  393. .configure = intel_815_configure,
  394. .fetch_size = intel_815_fetch_size,
  395. .cleanup = intel_8xx_cleanup,
  396. .tlb_flush = intel_8xx_tlbflush,
  397. .mask_memory = agp_generic_mask_memory,
  398. .masks = intel_generic_masks,
  399. .agp_enable = agp_generic_enable,
  400. .cache_flush = global_cache_flush,
  401. .create_gatt_table = agp_generic_create_gatt_table,
  402. .free_gatt_table = agp_generic_free_gatt_table,
  403. .insert_memory = agp_generic_insert_memory,
  404. .remove_memory = agp_generic_remove_memory,
  405. .alloc_by_type = agp_generic_alloc_by_type,
  406. .free_by_type = agp_generic_free_by_type,
  407. .agp_alloc_page = agp_generic_alloc_page,
  408. .agp_alloc_pages = agp_generic_alloc_pages,
  409. .agp_destroy_page = agp_generic_destroy_page,
  410. .agp_destroy_pages = agp_generic_destroy_pages,
  411. .agp_type_to_mask_type = agp_generic_type_to_mask_type,
  412. };
  413. static const struct agp_bridge_driver intel_820_driver = {
  414. .owner = THIS_MODULE,
  415. .aperture_sizes = intel_8xx_sizes,
  416. .size_type = U8_APER_SIZE,
  417. .num_aperture_sizes = 7,
  418. .needs_scratch_page = true,
  419. .configure = intel_820_configure,
  420. .fetch_size = intel_8xx_fetch_size,
  421. .cleanup = intel_820_cleanup,
  422. .tlb_flush = intel_820_tlbflush,
  423. .mask_memory = agp_generic_mask_memory,
  424. .masks = intel_generic_masks,
  425. .agp_enable = agp_generic_enable,
  426. .cache_flush = global_cache_flush,
  427. .create_gatt_table = agp_generic_create_gatt_table,
  428. .free_gatt_table = agp_generic_free_gatt_table,
  429. .insert_memory = agp_generic_insert_memory,
  430. .remove_memory = agp_generic_remove_memory,
  431. .alloc_by_type = agp_generic_alloc_by_type,
  432. .free_by_type = agp_generic_free_by_type,
  433. .agp_alloc_page = agp_generic_alloc_page,
  434. .agp_alloc_pages = agp_generic_alloc_pages,
  435. .agp_destroy_page = agp_generic_destroy_page,
  436. .agp_destroy_pages = agp_generic_destroy_pages,
  437. .agp_type_to_mask_type = agp_generic_type_to_mask_type,
  438. };
  439. static const struct agp_bridge_driver intel_830mp_driver = {
  440. .owner = THIS_MODULE,
  441. .aperture_sizes = intel_830mp_sizes,
  442. .size_type = U8_APER_SIZE,
  443. .num_aperture_sizes = 4,
  444. .needs_scratch_page = true,
  445. .configure = intel_830mp_configure,
  446. .fetch_size = intel_8xx_fetch_size,
  447. .cleanup = intel_8xx_cleanup,
  448. .tlb_flush = intel_8xx_tlbflush,
  449. .mask_memory = agp_generic_mask_memory,
  450. .masks = intel_generic_masks,
  451. .agp_enable = agp_generic_enable,
  452. .cache_flush = global_cache_flush,
  453. .create_gatt_table = agp_generic_create_gatt_table,
  454. .free_gatt_table = agp_generic_free_gatt_table,
  455. .insert_memory = agp_generic_insert_memory,
  456. .remove_memory = agp_generic_remove_memory,
  457. .alloc_by_type = agp_generic_alloc_by_type,
  458. .free_by_type = agp_generic_free_by_type,
  459. .agp_alloc_page = agp_generic_alloc_page,
  460. .agp_alloc_pages = agp_generic_alloc_pages,
  461. .agp_destroy_page = agp_generic_destroy_page,
  462. .agp_destroy_pages = agp_generic_destroy_pages,
  463. .agp_type_to_mask_type = agp_generic_type_to_mask_type,
  464. };
  465. static const struct agp_bridge_driver intel_840_driver = {
  466. .owner = THIS_MODULE,
  467. .aperture_sizes = intel_8xx_sizes,
  468. .size_type = U8_APER_SIZE,
  469. .num_aperture_sizes = 7,
  470. .needs_scratch_page = true,
  471. .configure = intel_840_configure,
  472. .fetch_size = intel_8xx_fetch_size,
  473. .cleanup = intel_8xx_cleanup,
  474. .tlb_flush = intel_8xx_tlbflush,
  475. .mask_memory = agp_generic_mask_memory,
  476. .masks = intel_generic_masks,
  477. .agp_enable = agp_generic_enable,
  478. .cache_flush = global_cache_flush,
  479. .create_gatt_table = agp_generic_create_gatt_table,
  480. .free_gatt_table = agp_generic_free_gatt_table,
  481. .insert_memory = agp_generic_insert_memory,
  482. .remove_memory = agp_generic_remove_memory,
  483. .alloc_by_type = agp_generic_alloc_by_type,
  484. .free_by_type = agp_generic_free_by_type,
  485. .agp_alloc_page = agp_generic_alloc_page,
  486. .agp_alloc_pages = agp_generic_alloc_pages,
  487. .agp_destroy_page = agp_generic_destroy_page,
  488. .agp_destroy_pages = agp_generic_destroy_pages,
  489. .agp_type_to_mask_type = agp_generic_type_to_mask_type,
  490. };
  491. static const struct agp_bridge_driver intel_845_driver = {
  492. .owner = THIS_MODULE,
  493. .aperture_sizes = intel_8xx_sizes,
  494. .size_type = U8_APER_SIZE,
  495. .num_aperture_sizes = 7,
  496. .needs_scratch_page = true,
  497. .configure = intel_845_configure,
  498. .fetch_size = intel_8xx_fetch_size,
  499. .cleanup = intel_8xx_cleanup,
  500. .tlb_flush = intel_8xx_tlbflush,
  501. .mask_memory = agp_generic_mask_memory,
  502. .masks = intel_generic_masks,
  503. .agp_enable = agp_generic_enable,
  504. .cache_flush = global_cache_flush,
  505. .create_gatt_table = agp_generic_create_gatt_table,
  506. .free_gatt_table = agp_generic_free_gatt_table,
  507. .insert_memory = agp_generic_insert_memory,
  508. .remove_memory = agp_generic_remove_memory,
  509. .alloc_by_type = agp_generic_alloc_by_type,
  510. .free_by_type = agp_generic_free_by_type,
  511. .agp_alloc_page = agp_generic_alloc_page,
  512. .agp_alloc_pages = agp_generic_alloc_pages,
  513. .agp_destroy_page = agp_generic_destroy_page,
  514. .agp_destroy_pages = agp_generic_destroy_pages,
  515. .agp_type_to_mask_type = agp_generic_type_to_mask_type,
  516. };
  517. static const struct agp_bridge_driver intel_850_driver = {
  518. .owner = THIS_MODULE,
  519. .aperture_sizes = intel_8xx_sizes,
  520. .size_type = U8_APER_SIZE,
  521. .num_aperture_sizes = 7,
  522. .needs_scratch_page = true,
  523. .configure = intel_850_configure,
  524. .fetch_size = intel_8xx_fetch_size,
  525. .cleanup = intel_8xx_cleanup,
  526. .tlb_flush = intel_8xx_tlbflush,
  527. .mask_memory = agp_generic_mask_memory,
  528. .masks = intel_generic_masks,
  529. .agp_enable = agp_generic_enable,
  530. .cache_flush = global_cache_flush,
  531. .create_gatt_table = agp_generic_create_gatt_table,
  532. .free_gatt_table = agp_generic_free_gatt_table,
  533. .insert_memory = agp_generic_insert_memory,
  534. .remove_memory = agp_generic_remove_memory,
  535. .alloc_by_type = agp_generic_alloc_by_type,
  536. .free_by_type = agp_generic_free_by_type,
  537. .agp_alloc_page = agp_generic_alloc_page,
  538. .agp_alloc_pages = agp_generic_alloc_pages,
  539. .agp_destroy_page = agp_generic_destroy_page,
  540. .agp_destroy_pages = agp_generic_destroy_pages,
  541. .agp_type_to_mask_type = agp_generic_type_to_mask_type,
  542. };
  543. static const struct agp_bridge_driver intel_860_driver = {
  544. .owner = THIS_MODULE,
  545. .aperture_sizes = intel_8xx_sizes,
  546. .size_type = U8_APER_SIZE,
  547. .num_aperture_sizes = 7,
  548. .needs_scratch_page = true,
  549. .configure = intel_860_configure,
  550. .fetch_size = intel_8xx_fetch_size,
  551. .cleanup = intel_8xx_cleanup,
  552. .tlb_flush = intel_8xx_tlbflush,
  553. .mask_memory = agp_generic_mask_memory,
  554. .masks = intel_generic_masks,
  555. .agp_enable = agp_generic_enable,
  556. .cache_flush = global_cache_flush,
  557. .create_gatt_table = agp_generic_create_gatt_table,
  558. .free_gatt_table = agp_generic_free_gatt_table,
  559. .insert_memory = agp_generic_insert_memory,
  560. .remove_memory = agp_generic_remove_memory,
  561. .alloc_by_type = agp_generic_alloc_by_type,
  562. .free_by_type = agp_generic_free_by_type,
  563. .agp_alloc_page = agp_generic_alloc_page,
  564. .agp_alloc_pages = agp_generic_alloc_pages,
  565. .agp_destroy_page = agp_generic_destroy_page,
  566. .agp_destroy_pages = agp_generic_destroy_pages,
  567. .agp_type_to_mask_type = agp_generic_type_to_mask_type,
  568. };
  569. static const struct agp_bridge_driver intel_7505_driver = {
  570. .owner = THIS_MODULE,
  571. .aperture_sizes = intel_8xx_sizes,
  572. .size_type = U8_APER_SIZE,
  573. .num_aperture_sizes = 7,
  574. .needs_scratch_page = true,
  575. .configure = intel_7505_configure,
  576. .fetch_size = intel_8xx_fetch_size,
  577. .cleanup = intel_8xx_cleanup,
  578. .tlb_flush = intel_8xx_tlbflush,
  579. .mask_memory = agp_generic_mask_memory,
  580. .masks = intel_generic_masks,
  581. .agp_enable = agp_generic_enable,
  582. .cache_flush = global_cache_flush,
  583. .create_gatt_table = agp_generic_create_gatt_table,
  584. .free_gatt_table = agp_generic_free_gatt_table,
  585. .insert_memory = agp_generic_insert_memory,
  586. .remove_memory = agp_generic_remove_memory,
  587. .alloc_by_type = agp_generic_alloc_by_type,
  588. .free_by_type = agp_generic_free_by_type,
  589. .agp_alloc_page = agp_generic_alloc_page,
  590. .agp_alloc_pages = agp_generic_alloc_pages,
  591. .agp_destroy_page = agp_generic_destroy_page,
  592. .agp_destroy_pages = agp_generic_destroy_pages,
  593. .agp_type_to_mask_type = agp_generic_type_to_mask_type,
  594. };
  595. /* Table to describe Intel GMCH and AGP/PCIE GART drivers. At least one of
  596. * driver and gmch_driver must be non-null, and find_gmch will determine
  597. * which one should be used if a gmch_chip_id is present.
  598. */
  599. static const struct intel_agp_driver_description {
  600. unsigned int chip_id;
  601. char *name;
  602. const struct agp_bridge_driver *driver;
  603. } intel_agp_chipsets[] = {
  604. { PCI_DEVICE_ID_INTEL_82443LX_0, "440LX", &intel_generic_driver },
  605. { PCI_DEVICE_ID_INTEL_82443BX_0, "440BX", &intel_generic_driver },
  606. { PCI_DEVICE_ID_INTEL_82443GX_0, "440GX", &intel_generic_driver },
  607. { PCI_DEVICE_ID_INTEL_82815_MC, "i815", &intel_815_driver },
  608. { PCI_DEVICE_ID_INTEL_82820_HB, "i820", &intel_820_driver },
  609. { PCI_DEVICE_ID_INTEL_82820_UP_HB, "i820", &intel_820_driver },
  610. { PCI_DEVICE_ID_INTEL_82830_HB, "830M", &intel_830mp_driver },
  611. { PCI_DEVICE_ID_INTEL_82840_HB, "i840", &intel_840_driver },
  612. { PCI_DEVICE_ID_INTEL_82845_HB, "i845", &intel_845_driver },
  613. { PCI_DEVICE_ID_INTEL_82845G_HB, "845G", &intel_845_driver },
  614. { PCI_DEVICE_ID_INTEL_82850_HB, "i850", &intel_850_driver },
  615. { PCI_DEVICE_ID_INTEL_82854_HB, "854", &intel_845_driver },
  616. { PCI_DEVICE_ID_INTEL_82855PM_HB, "855PM", &intel_845_driver },
  617. { PCI_DEVICE_ID_INTEL_82855GM_HB, "855GM", &intel_845_driver },
  618. { PCI_DEVICE_ID_INTEL_82860_HB, "i860", &intel_860_driver },
  619. { PCI_DEVICE_ID_INTEL_82865_HB, "865", &intel_845_driver },
  620. { PCI_DEVICE_ID_INTEL_82875_HB, "i875", &intel_845_driver },
  621. { PCI_DEVICE_ID_INTEL_7505_0, "E7505", &intel_7505_driver },
  622. { PCI_DEVICE_ID_INTEL_7205_0, "E7205", &intel_7505_driver },
  623. { 0, NULL, NULL }
  624. };
  625. static int agp_intel_probe(struct pci_dev *pdev,
  626. const struct pci_device_id *ent)
  627. {
  628. struct agp_bridge_data *bridge;
  629. u8 cap_ptr = 0;
  630. struct resource *r;
  631. int i, err;
  632. cap_ptr = pci_find_capability(pdev, PCI_CAP_ID_AGP);
  633. bridge = agp_alloc_bridge();
  634. if (!bridge)
  635. return -ENOMEM;
  636. bridge->capndx = cap_ptr;
  637. if (intel_gmch_probe(pdev, NULL, bridge))
  638. goto found_gmch;
  639. for (i = 0; intel_agp_chipsets[i].name != NULL; i++) {
  640. /* In case that multiple models of gfx chip may
  641. stand on same host bridge type, this can be
  642. sure we detect the right IGD. */
  643. if (pdev->device == intel_agp_chipsets[i].chip_id) {
  644. bridge->driver = intel_agp_chipsets[i].driver;
  645. break;
  646. }
  647. }
  648. if (!bridge->driver) {
  649. if (cap_ptr)
  650. dev_warn(&pdev->dev, "unsupported Intel chipset [%04x/%04x]\n",
  651. pdev->vendor, pdev->device);
  652. agp_put_bridge(bridge);
  653. return -ENODEV;
  654. }
  655. bridge->dev = pdev;
  656. bridge->dev_private_data = NULL;
  657. dev_info(&pdev->dev, "Intel %s Chipset\n", intel_agp_chipsets[i].name);
  658. /*
  659. * The following fixes the case where the BIOS has "forgotten" to
  660. * provide an address range for the GART.
  661. * 20030610 - hamish@zot.org
  662. * This happens before pci_enable_device() intentionally;
  663. * calling pci_enable_device() before assigning the resource
  664. * will result in the GART being disabled on machines with such
  665. * BIOSs (the GART ends up with a BAR starting at 0, which
  666. * conflicts a lot of other devices).
  667. */
  668. r = &pdev->resource[0];
  669. if (!r->start && r->end) {
  670. if (pci_assign_resource(pdev, 0)) {
  671. dev_err(&pdev->dev, "can't assign resource 0\n");
  672. agp_put_bridge(bridge);
  673. return -ENODEV;
  674. }
  675. }
  676. /*
  677. * If the device has not been properly setup, the following will catch
  678. * the problem and should stop the system from crashing.
  679. * 20030610 - hamish@zot.org
  680. */
  681. if (pci_enable_device(pdev)) {
  682. dev_err(&pdev->dev, "can't enable PCI device\n");
  683. agp_put_bridge(bridge);
  684. return -ENODEV;
  685. }
  686. /* Fill in the mode register */
  687. if (cap_ptr) {
  688. pci_read_config_dword(pdev,
  689. bridge->capndx+PCI_AGP_STATUS,
  690. &bridge->mode);
  691. }
  692. found_gmch:
  693. pci_set_drvdata(pdev, bridge);
  694. err = agp_add_bridge(bridge);
  695. if (!err)
  696. intel_agp_enabled = 1;
  697. return err;
  698. }
  699. static void agp_intel_remove(struct pci_dev *pdev)
  700. {
  701. struct agp_bridge_data *bridge = pci_get_drvdata(pdev);
  702. agp_remove_bridge(bridge);
  703. intel_gmch_remove();
  704. agp_put_bridge(bridge);
  705. }
  706. #ifdef CONFIG_PM
  707. static int agp_intel_resume(struct pci_dev *pdev)
  708. {
  709. struct agp_bridge_data *bridge = pci_get_drvdata(pdev);
  710. bridge->driver->configure();
  711. return 0;
  712. }
  713. #endif
  714. static struct pci_device_id agp_intel_pci_table[] = {
  715. #define ID(x) \
  716. { \
  717. .class = (PCI_CLASS_BRIDGE_HOST << 8), \
  718. .class_mask = ~0, \
  719. .vendor = PCI_VENDOR_ID_INTEL, \
  720. .device = x, \
  721. .subvendor = PCI_ANY_ID, \
  722. .subdevice = PCI_ANY_ID, \
  723. }
  724. ID(PCI_DEVICE_ID_INTEL_82441), /* for HAS2 support */
  725. ID(PCI_DEVICE_ID_INTEL_82443LX_0),
  726. ID(PCI_DEVICE_ID_INTEL_82443BX_0),
  727. ID(PCI_DEVICE_ID_INTEL_82443GX_0),
  728. ID(PCI_DEVICE_ID_INTEL_82810_MC1),
  729. ID(PCI_DEVICE_ID_INTEL_82810_MC3),
  730. ID(PCI_DEVICE_ID_INTEL_82810E_MC),
  731. ID(PCI_DEVICE_ID_INTEL_82815_MC),
  732. ID(PCI_DEVICE_ID_INTEL_82820_HB),
  733. ID(PCI_DEVICE_ID_INTEL_82820_UP_HB),
  734. ID(PCI_DEVICE_ID_INTEL_82830_HB),
  735. ID(PCI_DEVICE_ID_INTEL_82840_HB),
  736. ID(PCI_DEVICE_ID_INTEL_82845_HB),
  737. ID(PCI_DEVICE_ID_INTEL_82845G_HB),
  738. ID(PCI_DEVICE_ID_INTEL_82850_HB),
  739. ID(PCI_DEVICE_ID_INTEL_82854_HB),
  740. ID(PCI_DEVICE_ID_INTEL_82855PM_HB),
  741. ID(PCI_DEVICE_ID_INTEL_82855GM_HB),
  742. ID(PCI_DEVICE_ID_INTEL_82860_HB),
  743. ID(PCI_DEVICE_ID_INTEL_82865_HB),
  744. ID(PCI_DEVICE_ID_INTEL_82875_HB),
  745. ID(PCI_DEVICE_ID_INTEL_7505_0),
  746. ID(PCI_DEVICE_ID_INTEL_7205_0),
  747. ID(PCI_DEVICE_ID_INTEL_E7221_HB),
  748. ID(PCI_DEVICE_ID_INTEL_82915G_HB),
  749. ID(PCI_DEVICE_ID_INTEL_82915GM_HB),
  750. ID(PCI_DEVICE_ID_INTEL_82945G_HB),
  751. ID(PCI_DEVICE_ID_INTEL_82945GM_HB),
  752. ID(PCI_DEVICE_ID_INTEL_82945GME_HB),
  753. ID(PCI_DEVICE_ID_INTEL_PINEVIEW_M_HB),
  754. ID(PCI_DEVICE_ID_INTEL_PINEVIEW_HB),
  755. ID(PCI_DEVICE_ID_INTEL_82946GZ_HB),
  756. ID(PCI_DEVICE_ID_INTEL_82G35_HB),
  757. ID(PCI_DEVICE_ID_INTEL_82965Q_HB),
  758. ID(PCI_DEVICE_ID_INTEL_82965G_HB),
  759. ID(PCI_DEVICE_ID_INTEL_82965GM_HB),
  760. ID(PCI_DEVICE_ID_INTEL_82965GME_HB),
  761. ID(PCI_DEVICE_ID_INTEL_G33_HB),
  762. ID(PCI_DEVICE_ID_INTEL_Q35_HB),
  763. ID(PCI_DEVICE_ID_INTEL_Q33_HB),
  764. ID(PCI_DEVICE_ID_INTEL_GM45_HB),
  765. ID(PCI_DEVICE_ID_INTEL_EAGLELAKE_HB),
  766. ID(PCI_DEVICE_ID_INTEL_Q45_HB),
  767. ID(PCI_DEVICE_ID_INTEL_G45_HB),
  768. ID(PCI_DEVICE_ID_INTEL_G41_HB),
  769. ID(PCI_DEVICE_ID_INTEL_B43_HB),
  770. ID(PCI_DEVICE_ID_INTEL_B43_1_HB),
  771. ID(PCI_DEVICE_ID_INTEL_IRONLAKE_D_HB),
  772. ID(PCI_DEVICE_ID_INTEL_IRONLAKE_D2_HB),
  773. ID(PCI_DEVICE_ID_INTEL_IRONLAKE_M_HB),
  774. ID(PCI_DEVICE_ID_INTEL_IRONLAKE_MA_HB),
  775. ID(PCI_DEVICE_ID_INTEL_IRONLAKE_MC2_HB),
  776. { }
  777. };
  778. MODULE_DEVICE_TABLE(pci, agp_intel_pci_table);
  779. static struct pci_driver agp_intel_pci_driver = {
  780. .name = "agpgart-intel",
  781. .id_table = agp_intel_pci_table,
  782. .probe = agp_intel_probe,
  783. .remove = agp_intel_remove,
  784. #ifdef CONFIG_PM
  785. .resume = agp_intel_resume,
  786. #endif
  787. };
  788. static int __init agp_intel_init(void)
  789. {
  790. if (agp_off)
  791. return -EINVAL;
  792. return pci_register_driver(&agp_intel_pci_driver);
  793. }
  794. static void __exit agp_intel_cleanup(void)
  795. {
  796. pci_unregister_driver(&agp_intel_pci_driver);
  797. }
  798. module_init(agp_intel_init);
  799. module_exit(agp_intel_cleanup);
  800. MODULE_AUTHOR("Dave Jones <davej@redhat.com>");
  801. MODULE_LICENSE("GPL and additional rights");