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