intel-agp.c 28 KB

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