intel-agp.c 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353
  1. /*
  2. * Intel AGPGART routines.
  3. */
  4. #include <linux/module.h>
  5. #include <linux/pci.h>
  6. #include <linux/init.h>
  7. #include <linux/kernel.h>
  8. #include <linux/pagemap.h>
  9. #include <linux/agp_backend.h>
  10. #include "agp.h"
  11. #define PCI_DEVICE_ID_INTEL_E7221_HB 0x2588
  12. #define PCI_DEVICE_ID_INTEL_E7221_IG 0x258a
  13. #define PCI_DEVICE_ID_INTEL_82946GZ_HB 0x2970
  14. #define PCI_DEVICE_ID_INTEL_82946GZ_IG 0x2972
  15. #define PCI_DEVICE_ID_INTEL_82G35_HB 0x2980
  16. #define PCI_DEVICE_ID_INTEL_82G35_IG 0x2982
  17. #define PCI_DEVICE_ID_INTEL_82965Q_HB 0x2990
  18. #define PCI_DEVICE_ID_INTEL_82965Q_IG 0x2992
  19. #define PCI_DEVICE_ID_INTEL_82965G_HB 0x29A0
  20. #define PCI_DEVICE_ID_INTEL_82965G_IG 0x29A2
  21. #define PCI_DEVICE_ID_INTEL_82965GM_HB 0x2A00
  22. #define PCI_DEVICE_ID_INTEL_82965GM_IG 0x2A02
  23. #define PCI_DEVICE_ID_INTEL_82965GME_HB 0x2A10
  24. #define PCI_DEVICE_ID_INTEL_82965GME_IG 0x2A12
  25. #define PCI_DEVICE_ID_INTEL_82945GME_HB 0x27AC
  26. #define PCI_DEVICE_ID_INTEL_82945GME_IG 0x27AE
  27. #define PCI_DEVICE_ID_INTEL_G33_HB 0x29C0
  28. #define PCI_DEVICE_ID_INTEL_G33_IG 0x29C2
  29. #define PCI_DEVICE_ID_INTEL_Q35_HB 0x29B0
  30. #define PCI_DEVICE_ID_INTEL_Q35_IG 0x29B2
  31. #define PCI_DEVICE_ID_INTEL_Q33_HB 0x29D0
  32. #define PCI_DEVICE_ID_INTEL_Q33_IG 0x29D2
  33. #define PCI_DEVICE_ID_INTEL_IGD_HB 0x2A40
  34. #define PCI_DEVICE_ID_INTEL_IGD_IG 0x2A42
  35. #define PCI_DEVICE_ID_INTEL_IGD_E_HB 0x2E00
  36. #define PCI_DEVICE_ID_INTEL_IGD_E_IG 0x2E02
  37. #define PCI_DEVICE_ID_INTEL_Q45_HB 0x2E10
  38. #define PCI_DEVICE_ID_INTEL_Q45_IG 0x2E12
  39. #define PCI_DEVICE_ID_INTEL_G45_HB 0x2E20
  40. #define PCI_DEVICE_ID_INTEL_G45_IG 0x2E22
  41. /* cover 915 and 945 variants */
  42. #define IS_I915 (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_E7221_HB || \
  43. agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82915G_HB || \
  44. agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82915GM_HB || \
  45. agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82945G_HB || \
  46. agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82945GM_HB || \
  47. agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82945GME_HB)
  48. #define IS_I965 (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82946GZ_HB || \
  49. agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82G35_HB || \
  50. agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965Q_HB || \
  51. agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965G_HB || \
  52. agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965GM_HB || \
  53. agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965GME_HB || \
  54. agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IGD_HB)
  55. #define IS_G33 (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_G33_HB || \
  56. agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_Q35_HB || \
  57. agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_Q33_HB)
  58. #define IS_G4X (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IGD_E_HB || \
  59. agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_Q45_HB || \
  60. agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_G45_HB)
  61. extern int agp_memory_reserved;
  62. /* Intel 815 register */
  63. #define INTEL_815_APCONT 0x51
  64. #define INTEL_815_ATTBASE_MASK ~0x1FFFFFFF
  65. /* Intel i820 registers */
  66. #define INTEL_I820_RDCR 0x51
  67. #define INTEL_I820_ERRSTS 0xc8
  68. /* Intel i840 registers */
  69. #define INTEL_I840_MCHCFG 0x50
  70. #define INTEL_I840_ERRSTS 0xc8
  71. /* Intel i850 registers */
  72. #define INTEL_I850_MCHCFG 0x50
  73. #define INTEL_I850_ERRSTS 0xc8
  74. /* intel 915G registers */
  75. #define I915_GMADDR 0x18
  76. #define I915_MMADDR 0x10
  77. #define I915_PTEADDR 0x1C
  78. #define I915_GMCH_GMS_STOLEN_48M (0x6 << 4)
  79. #define I915_GMCH_GMS_STOLEN_64M (0x7 << 4)
  80. #define G33_GMCH_GMS_STOLEN_128M (0x8 << 4)
  81. #define G33_GMCH_GMS_STOLEN_256M (0x9 << 4)
  82. #define INTEL_GMCH_GMS_STOLEN_96M (0xa << 4)
  83. #define INTEL_GMCH_GMS_STOLEN_160M (0xb << 4)
  84. #define INTEL_GMCH_GMS_STOLEN_224M (0xc << 4)
  85. #define INTEL_GMCH_GMS_STOLEN_352M (0xd << 4)
  86. #define I915_IFPADDR 0x60
  87. /* Intel 965G registers */
  88. #define I965_MSAC 0x62
  89. #define I965_IFPADDR 0x70
  90. /* Intel 7505 registers */
  91. #define INTEL_I7505_APSIZE 0x74
  92. #define INTEL_I7505_NCAPID 0x60
  93. #define INTEL_I7505_NISTAT 0x6c
  94. #define INTEL_I7505_ATTBASE 0x78
  95. #define INTEL_I7505_ERRSTS 0x42
  96. #define INTEL_I7505_AGPCTRL 0x70
  97. #define INTEL_I7505_MCHCFG 0x50
  98. static const struct aper_size_info_fixed intel_i810_sizes[] =
  99. {
  100. {64, 16384, 4},
  101. /* The 32M mode still requires a 64k gatt */
  102. {32, 8192, 4}
  103. };
  104. #define AGP_DCACHE_MEMORY 1
  105. #define AGP_PHYS_MEMORY 2
  106. #define INTEL_AGP_CACHED_MEMORY 3
  107. static struct gatt_mask intel_i810_masks[] =
  108. {
  109. {.mask = I810_PTE_VALID, .type = 0},
  110. {.mask = (I810_PTE_VALID | I810_PTE_LOCAL), .type = AGP_DCACHE_MEMORY},
  111. {.mask = I810_PTE_VALID, .type = 0},
  112. {.mask = I810_PTE_VALID | I830_PTE_SYSTEM_CACHED,
  113. .type = INTEL_AGP_CACHED_MEMORY}
  114. };
  115. static struct _intel_private {
  116. struct pci_dev *pcidev; /* device one */
  117. u8 __iomem *registers;
  118. u32 __iomem *gtt; /* I915G */
  119. int num_dcache_entries;
  120. /* gtt_entries is the number of gtt entries that are already mapped
  121. * to stolen memory. Stolen memory is larger than the memory mapped
  122. * through gtt_entries, as it includes some reserved space for the BIOS
  123. * popup and for the GTT.
  124. */
  125. int gtt_entries; /* i830+ */
  126. union {
  127. void __iomem *i9xx_flush_page;
  128. void *i8xx_flush_page;
  129. };
  130. struct page *i8xx_page;
  131. struct resource ifp_resource;
  132. int resource_valid;
  133. } intel_private;
  134. static int intel_i810_fetch_size(void)
  135. {
  136. u32 smram_miscc;
  137. struct aper_size_info_fixed *values;
  138. pci_read_config_dword(agp_bridge->dev, I810_SMRAM_MISCC, &smram_miscc);
  139. values = A_SIZE_FIX(agp_bridge->driver->aperture_sizes);
  140. if ((smram_miscc & I810_GMS) == I810_GMS_DISABLE) {
  141. printk(KERN_WARNING PFX "i810 is disabled\n");
  142. return 0;
  143. }
  144. if ((smram_miscc & I810_GFX_MEM_WIN_SIZE) == I810_GFX_MEM_WIN_32M) {
  145. agp_bridge->previous_size =
  146. agp_bridge->current_size = (void *) (values + 1);
  147. agp_bridge->aperture_size_idx = 1;
  148. return values[1].size;
  149. } else {
  150. agp_bridge->previous_size =
  151. agp_bridge->current_size = (void *) (values);
  152. agp_bridge->aperture_size_idx = 0;
  153. return values[0].size;
  154. }
  155. return 0;
  156. }
  157. static int intel_i810_configure(void)
  158. {
  159. struct aper_size_info_fixed *current_size;
  160. u32 temp;
  161. int i;
  162. current_size = A_SIZE_FIX(agp_bridge->current_size);
  163. if (!intel_private.registers) {
  164. pci_read_config_dword(intel_private.pcidev, I810_MMADDR, &temp);
  165. temp &= 0xfff80000;
  166. intel_private.registers = ioremap(temp, 128 * 4096);
  167. if (!intel_private.registers) {
  168. printk(KERN_ERR PFX "Unable to remap memory.\n");
  169. return -ENOMEM;
  170. }
  171. }
  172. if ((readl(intel_private.registers+I810_DRAM_CTL)
  173. & I810_DRAM_ROW_0) == I810_DRAM_ROW_0_SDRAM) {
  174. /* This will need to be dynamically assigned */
  175. printk(KERN_INFO PFX "detected 4MB dedicated video ram.\n");
  176. intel_private.num_dcache_entries = 1024;
  177. }
  178. pci_read_config_dword(intel_private.pcidev, I810_GMADDR, &temp);
  179. agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
  180. writel(agp_bridge->gatt_bus_addr | I810_PGETBL_ENABLED, intel_private.registers+I810_PGETBL_CTL);
  181. readl(intel_private.registers+I810_PGETBL_CTL); /* PCI Posting. */
  182. if (agp_bridge->driver->needs_scratch_page) {
  183. for (i = 0; i < current_size->num_entries; i++) {
  184. writel(agp_bridge->scratch_page, intel_private.registers+I810_PTE_BASE+(i*4));
  185. readl(intel_private.registers+I810_PTE_BASE+(i*4)); /* PCI posting. */
  186. }
  187. }
  188. global_cache_flush();
  189. return 0;
  190. }
  191. static void intel_i810_cleanup(void)
  192. {
  193. writel(0, intel_private.registers+I810_PGETBL_CTL);
  194. readl(intel_private.registers); /* PCI Posting. */
  195. iounmap(intel_private.registers);
  196. }
  197. static void intel_i810_tlbflush(struct agp_memory *mem)
  198. {
  199. return;
  200. }
  201. static void intel_i810_agp_enable(struct agp_bridge_data *bridge, u32 mode)
  202. {
  203. return;
  204. }
  205. /* Exists to support ARGB cursors */
  206. static void *i8xx_alloc_pages(void)
  207. {
  208. struct page *page;
  209. page = alloc_pages(GFP_KERNEL | GFP_DMA32, 2);
  210. if (page == NULL)
  211. return NULL;
  212. if (set_pages_uc(page, 4) < 0) {
  213. set_pages_wb(page, 4);
  214. __free_pages(page, 2);
  215. return NULL;
  216. }
  217. get_page(page);
  218. atomic_inc(&agp_bridge->current_memory_agp);
  219. return page_address(page);
  220. }
  221. static void i8xx_destroy_pages(void *addr)
  222. {
  223. struct page *page;
  224. if (addr == NULL)
  225. return;
  226. page = virt_to_page(addr);
  227. set_pages_wb(page, 4);
  228. put_page(page);
  229. __free_pages(page, 2);
  230. atomic_dec(&agp_bridge->current_memory_agp);
  231. }
  232. static int intel_i830_type_to_mask_type(struct agp_bridge_data *bridge,
  233. int type)
  234. {
  235. if (type < AGP_USER_TYPES)
  236. return type;
  237. else if (type == AGP_USER_CACHED_MEMORY)
  238. return INTEL_AGP_CACHED_MEMORY;
  239. else
  240. return 0;
  241. }
  242. static int intel_i810_insert_entries(struct agp_memory *mem, off_t pg_start,
  243. int type)
  244. {
  245. int i, j, num_entries;
  246. void *temp;
  247. int ret = -EINVAL;
  248. int mask_type;
  249. if (mem->page_count == 0)
  250. goto out;
  251. temp = agp_bridge->current_size;
  252. num_entries = A_SIZE_FIX(temp)->num_entries;
  253. if ((pg_start + mem->page_count) > num_entries)
  254. goto out_err;
  255. for (j = pg_start; j < (pg_start + mem->page_count); j++) {
  256. if (!PGE_EMPTY(agp_bridge, readl(agp_bridge->gatt_table+j))) {
  257. ret = -EBUSY;
  258. goto out_err;
  259. }
  260. }
  261. if (type != mem->type)
  262. goto out_err;
  263. mask_type = agp_bridge->driver->agp_type_to_mask_type(agp_bridge, type);
  264. switch (mask_type) {
  265. case AGP_DCACHE_MEMORY:
  266. if (!mem->is_flushed)
  267. global_cache_flush();
  268. for (i = pg_start; i < (pg_start + mem->page_count); i++) {
  269. writel((i*4096)|I810_PTE_LOCAL|I810_PTE_VALID,
  270. intel_private.registers+I810_PTE_BASE+(i*4));
  271. }
  272. readl(intel_private.registers+I810_PTE_BASE+((i-1)*4));
  273. break;
  274. case AGP_PHYS_MEMORY:
  275. case AGP_NORMAL_MEMORY:
  276. if (!mem->is_flushed)
  277. global_cache_flush();
  278. for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
  279. writel(agp_bridge->driver->mask_memory(agp_bridge,
  280. mem->memory[i],
  281. mask_type),
  282. intel_private.registers+I810_PTE_BASE+(j*4));
  283. }
  284. readl(intel_private.registers+I810_PTE_BASE+((j-1)*4));
  285. break;
  286. default:
  287. goto out_err;
  288. }
  289. agp_bridge->driver->tlb_flush(mem);
  290. out:
  291. ret = 0;
  292. out_err:
  293. mem->is_flushed = true;
  294. return ret;
  295. }
  296. static int intel_i810_remove_entries(struct agp_memory *mem, off_t pg_start,
  297. int type)
  298. {
  299. int i;
  300. if (mem->page_count == 0)
  301. return 0;
  302. for (i = pg_start; i < (mem->page_count + pg_start); i++) {
  303. writel(agp_bridge->scratch_page, intel_private.registers+I810_PTE_BASE+(i*4));
  304. }
  305. readl(intel_private.registers+I810_PTE_BASE+((i-1)*4));
  306. agp_bridge->driver->tlb_flush(mem);
  307. return 0;
  308. }
  309. /*
  310. * The i810/i830 requires a physical address to program its mouse
  311. * pointer into hardware.
  312. * However the Xserver still writes to it through the agp aperture.
  313. */
  314. static struct agp_memory *alloc_agpphysmem_i8xx(size_t pg_count, int type)
  315. {
  316. struct agp_memory *new;
  317. void *addr;
  318. switch (pg_count) {
  319. case 1: addr = agp_bridge->driver->agp_alloc_page(agp_bridge);
  320. break;
  321. case 4:
  322. /* kludge to get 4 physical pages for ARGB cursor */
  323. addr = i8xx_alloc_pages();
  324. break;
  325. default:
  326. return NULL;
  327. }
  328. if (addr == NULL)
  329. return NULL;
  330. new = agp_create_memory(pg_count);
  331. if (new == NULL)
  332. return NULL;
  333. new->memory[0] = virt_to_gart(addr);
  334. if (pg_count == 4) {
  335. /* kludge to get 4 physical pages for ARGB cursor */
  336. new->memory[1] = new->memory[0] + PAGE_SIZE;
  337. new->memory[2] = new->memory[1] + PAGE_SIZE;
  338. new->memory[3] = new->memory[2] + PAGE_SIZE;
  339. }
  340. new->page_count = pg_count;
  341. new->num_scratch_pages = pg_count;
  342. new->type = AGP_PHYS_MEMORY;
  343. new->physical = new->memory[0];
  344. return new;
  345. }
  346. static struct agp_memory *intel_i810_alloc_by_type(size_t pg_count, int type)
  347. {
  348. struct agp_memory *new;
  349. if (type == AGP_DCACHE_MEMORY) {
  350. if (pg_count != intel_private.num_dcache_entries)
  351. return NULL;
  352. new = agp_create_memory(1);
  353. if (new == NULL)
  354. return NULL;
  355. new->type = AGP_DCACHE_MEMORY;
  356. new->page_count = pg_count;
  357. new->num_scratch_pages = 0;
  358. agp_free_page_array(new);
  359. return new;
  360. }
  361. if (type == AGP_PHYS_MEMORY)
  362. return alloc_agpphysmem_i8xx(pg_count, type);
  363. return NULL;
  364. }
  365. static void intel_i810_free_by_type(struct agp_memory *curr)
  366. {
  367. agp_free_key(curr->key);
  368. if (curr->type == AGP_PHYS_MEMORY) {
  369. if (curr->page_count == 4)
  370. i8xx_destroy_pages(gart_to_virt(curr->memory[0]));
  371. else {
  372. void *va = gart_to_virt(curr->memory[0]);
  373. agp_bridge->driver->agp_destroy_page(va,
  374. AGP_PAGE_DESTROY_UNMAP);
  375. agp_bridge->driver->agp_destroy_page(va,
  376. AGP_PAGE_DESTROY_FREE);
  377. }
  378. agp_free_page_array(curr);
  379. }
  380. kfree(curr);
  381. }
  382. static unsigned long intel_i810_mask_memory(struct agp_bridge_data *bridge,
  383. unsigned long addr, int type)
  384. {
  385. /* Type checking must be done elsewhere */
  386. return addr | bridge->driver->masks[type].mask;
  387. }
  388. static struct aper_size_info_fixed intel_i830_sizes[] =
  389. {
  390. {128, 32768, 5},
  391. /* The 64M mode still requires a 128k gatt */
  392. {64, 16384, 5},
  393. {256, 65536, 6},
  394. {512, 131072, 7},
  395. };
  396. static void intel_i830_init_gtt_entries(void)
  397. {
  398. u16 gmch_ctrl;
  399. int gtt_entries;
  400. u8 rdct;
  401. int local = 0;
  402. static const int ddt[4] = { 0, 16, 32, 64 };
  403. int size; /* reserved space (in kb) at the top of stolen memory */
  404. pci_read_config_word(agp_bridge->dev, I830_GMCH_CTRL, &gmch_ctrl);
  405. if (IS_I965) {
  406. u32 pgetbl_ctl;
  407. pgetbl_ctl = readl(intel_private.registers+I810_PGETBL_CTL);
  408. /* The 965 has a field telling us the size of the GTT,
  409. * which may be larger than what is necessary to map the
  410. * aperture.
  411. */
  412. switch (pgetbl_ctl & I965_PGETBL_SIZE_MASK) {
  413. case I965_PGETBL_SIZE_128KB:
  414. size = 128;
  415. break;
  416. case I965_PGETBL_SIZE_256KB:
  417. size = 256;
  418. break;
  419. case I965_PGETBL_SIZE_512KB:
  420. size = 512;
  421. break;
  422. case I965_PGETBL_SIZE_1MB:
  423. size = 1024;
  424. break;
  425. case I965_PGETBL_SIZE_2MB:
  426. size = 2048;
  427. break;
  428. case I965_PGETBL_SIZE_1_5MB:
  429. size = 1024 + 512;
  430. break;
  431. default:
  432. printk(KERN_INFO PFX "Unknown page table size, "
  433. "assuming 512KB\n");
  434. size = 512;
  435. }
  436. size += 4; /* add in BIOS popup space */
  437. } else if (IS_G33) {
  438. /* G33's GTT size defined in gmch_ctrl */
  439. switch (gmch_ctrl & G33_PGETBL_SIZE_MASK) {
  440. case G33_PGETBL_SIZE_1M:
  441. size = 1024;
  442. break;
  443. case G33_PGETBL_SIZE_2M:
  444. size = 2048;
  445. break;
  446. default:
  447. printk(KERN_INFO PFX "Unknown page table size 0x%x, "
  448. "assuming 512KB\n",
  449. (gmch_ctrl & G33_PGETBL_SIZE_MASK));
  450. size = 512;
  451. }
  452. size += 4;
  453. } else if (IS_G4X) {
  454. /* On 4 series hardware, GTT stolen is separate from graphics
  455. * stolen, ignore it in stolen gtt entries counting */
  456. size = 0;
  457. } else {
  458. /* On previous hardware, the GTT size was just what was
  459. * required to map the aperture.
  460. */
  461. size = agp_bridge->driver->fetch_size() + 4;
  462. }
  463. if (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82830_HB ||
  464. agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82845G_HB) {
  465. switch (gmch_ctrl & I830_GMCH_GMS_MASK) {
  466. case I830_GMCH_GMS_STOLEN_512:
  467. gtt_entries = KB(512) - KB(size);
  468. break;
  469. case I830_GMCH_GMS_STOLEN_1024:
  470. gtt_entries = MB(1) - KB(size);
  471. break;
  472. case I830_GMCH_GMS_STOLEN_8192:
  473. gtt_entries = MB(8) - KB(size);
  474. break;
  475. case I830_GMCH_GMS_LOCAL:
  476. rdct = readb(intel_private.registers+I830_RDRAM_CHANNEL_TYPE);
  477. gtt_entries = (I830_RDRAM_ND(rdct) + 1) *
  478. MB(ddt[I830_RDRAM_DDT(rdct)]);
  479. local = 1;
  480. break;
  481. default:
  482. gtt_entries = 0;
  483. break;
  484. }
  485. } else {
  486. switch (gmch_ctrl & I855_GMCH_GMS_MASK) {
  487. case I855_GMCH_GMS_STOLEN_1M:
  488. gtt_entries = MB(1) - KB(size);
  489. break;
  490. case I855_GMCH_GMS_STOLEN_4M:
  491. gtt_entries = MB(4) - KB(size);
  492. break;
  493. case I855_GMCH_GMS_STOLEN_8M:
  494. gtt_entries = MB(8) - KB(size);
  495. break;
  496. case I855_GMCH_GMS_STOLEN_16M:
  497. gtt_entries = MB(16) - KB(size);
  498. break;
  499. case I855_GMCH_GMS_STOLEN_32M:
  500. gtt_entries = MB(32) - KB(size);
  501. break;
  502. case I915_GMCH_GMS_STOLEN_48M:
  503. /* Check it's really I915G */
  504. if (IS_I915 || IS_I965 || IS_G33 || IS_G4X)
  505. gtt_entries = MB(48) - KB(size);
  506. else
  507. gtt_entries = 0;
  508. break;
  509. case I915_GMCH_GMS_STOLEN_64M:
  510. /* Check it's really I915G */
  511. if (IS_I915 || IS_I965 || IS_G33 || IS_G4X)
  512. gtt_entries = MB(64) - KB(size);
  513. else
  514. gtt_entries = 0;
  515. break;
  516. case G33_GMCH_GMS_STOLEN_128M:
  517. if (IS_G33 || IS_I965 || IS_G4X)
  518. gtt_entries = MB(128) - KB(size);
  519. else
  520. gtt_entries = 0;
  521. break;
  522. case G33_GMCH_GMS_STOLEN_256M:
  523. if (IS_G33 || IS_I965 || IS_G4X)
  524. gtt_entries = MB(256) - KB(size);
  525. else
  526. gtt_entries = 0;
  527. break;
  528. case INTEL_GMCH_GMS_STOLEN_96M:
  529. if (IS_I965 || IS_G4X)
  530. gtt_entries = MB(96) - KB(size);
  531. else
  532. gtt_entries = 0;
  533. break;
  534. case INTEL_GMCH_GMS_STOLEN_160M:
  535. if (IS_I965 || IS_G4X)
  536. gtt_entries = MB(160) - KB(size);
  537. else
  538. gtt_entries = 0;
  539. break;
  540. case INTEL_GMCH_GMS_STOLEN_224M:
  541. if (IS_I965 || IS_G4X)
  542. gtt_entries = MB(224) - KB(size);
  543. else
  544. gtt_entries = 0;
  545. break;
  546. case INTEL_GMCH_GMS_STOLEN_352M:
  547. if (IS_I965 || IS_G4X)
  548. gtt_entries = MB(352) - KB(size);
  549. else
  550. gtt_entries = 0;
  551. break;
  552. default:
  553. gtt_entries = 0;
  554. break;
  555. }
  556. }
  557. if (gtt_entries > 0)
  558. printk(KERN_INFO PFX "Detected %dK %s memory.\n",
  559. gtt_entries / KB(1), local ? "local" : "stolen");
  560. else
  561. printk(KERN_INFO PFX
  562. "No pre-allocated video memory detected.\n");
  563. gtt_entries /= KB(4);
  564. intel_private.gtt_entries = gtt_entries;
  565. }
  566. static void intel_i830_fini_flush(void)
  567. {
  568. kunmap(intel_private.i8xx_page);
  569. intel_private.i8xx_flush_page = NULL;
  570. unmap_page_from_agp(intel_private.i8xx_page);
  571. __free_page(intel_private.i8xx_page);
  572. intel_private.i8xx_page = NULL;
  573. }
  574. static void intel_i830_setup_flush(void)
  575. {
  576. /* return if we've already set the flush mechanism up */
  577. if (intel_private.i8xx_page)
  578. return;
  579. intel_private.i8xx_page = alloc_page(GFP_KERNEL | __GFP_ZERO | GFP_DMA32);
  580. if (!intel_private.i8xx_page)
  581. return;
  582. /* make page uncached */
  583. map_page_into_agp(intel_private.i8xx_page);
  584. intel_private.i8xx_flush_page = kmap(intel_private.i8xx_page);
  585. if (!intel_private.i8xx_flush_page)
  586. intel_i830_fini_flush();
  587. }
  588. static void intel_i830_chipset_flush(struct agp_bridge_data *bridge)
  589. {
  590. unsigned int *pg = intel_private.i8xx_flush_page;
  591. int i;
  592. for (i = 0; i < 256; i += 2)
  593. *(pg + i) = i;
  594. wmb();
  595. }
  596. /* The intel i830 automatically initializes the agp aperture during POST.
  597. * Use the memory already set aside for in the GTT.
  598. */
  599. static int intel_i830_create_gatt_table(struct agp_bridge_data *bridge)
  600. {
  601. int page_order;
  602. struct aper_size_info_fixed *size;
  603. int num_entries;
  604. u32 temp;
  605. size = agp_bridge->current_size;
  606. page_order = size->page_order;
  607. num_entries = size->num_entries;
  608. agp_bridge->gatt_table_real = NULL;
  609. pci_read_config_dword(intel_private.pcidev, I810_MMADDR, &temp);
  610. temp &= 0xfff80000;
  611. intel_private.registers = ioremap(temp, 128 * 4096);
  612. if (!intel_private.registers)
  613. return -ENOMEM;
  614. temp = readl(intel_private.registers+I810_PGETBL_CTL) & 0xfffff000;
  615. global_cache_flush(); /* FIXME: ?? */
  616. /* we have to call this as early as possible after the MMIO base address is known */
  617. intel_i830_init_gtt_entries();
  618. agp_bridge->gatt_table = NULL;
  619. agp_bridge->gatt_bus_addr = temp;
  620. return 0;
  621. }
  622. /* Return the gatt table to a sane state. Use the top of stolen
  623. * memory for the GTT.
  624. */
  625. static int intel_i830_free_gatt_table(struct agp_bridge_data *bridge)
  626. {
  627. return 0;
  628. }
  629. static int intel_i830_fetch_size(void)
  630. {
  631. u16 gmch_ctrl;
  632. struct aper_size_info_fixed *values;
  633. values = A_SIZE_FIX(agp_bridge->driver->aperture_sizes);
  634. if (agp_bridge->dev->device != PCI_DEVICE_ID_INTEL_82830_HB &&
  635. agp_bridge->dev->device != PCI_DEVICE_ID_INTEL_82845G_HB) {
  636. /* 855GM/852GM/865G has 128MB aperture size */
  637. agp_bridge->previous_size = agp_bridge->current_size = (void *) values;
  638. agp_bridge->aperture_size_idx = 0;
  639. return values[0].size;
  640. }
  641. pci_read_config_word(agp_bridge->dev, I830_GMCH_CTRL, &gmch_ctrl);
  642. if ((gmch_ctrl & I830_GMCH_MEM_MASK) == I830_GMCH_MEM_128M) {
  643. agp_bridge->previous_size = agp_bridge->current_size = (void *) values;
  644. agp_bridge->aperture_size_idx = 0;
  645. return values[0].size;
  646. } else {
  647. agp_bridge->previous_size = agp_bridge->current_size = (void *) (values + 1);
  648. agp_bridge->aperture_size_idx = 1;
  649. return values[1].size;
  650. }
  651. return 0;
  652. }
  653. static int intel_i830_configure(void)
  654. {
  655. struct aper_size_info_fixed *current_size;
  656. u32 temp;
  657. u16 gmch_ctrl;
  658. int i;
  659. current_size = A_SIZE_FIX(agp_bridge->current_size);
  660. pci_read_config_dword(intel_private.pcidev, I810_GMADDR, &temp);
  661. agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
  662. pci_read_config_word(agp_bridge->dev, I830_GMCH_CTRL, &gmch_ctrl);
  663. gmch_ctrl |= I830_GMCH_ENABLED;
  664. pci_write_config_word(agp_bridge->dev, I830_GMCH_CTRL, gmch_ctrl);
  665. writel(agp_bridge->gatt_bus_addr|I810_PGETBL_ENABLED, intel_private.registers+I810_PGETBL_CTL);
  666. readl(intel_private.registers+I810_PGETBL_CTL); /* PCI Posting. */
  667. if (agp_bridge->driver->needs_scratch_page) {
  668. for (i = intel_private.gtt_entries; i < current_size->num_entries; i++) {
  669. writel(agp_bridge->scratch_page, intel_private.registers+I810_PTE_BASE+(i*4));
  670. readl(intel_private.registers+I810_PTE_BASE+(i*4)); /* PCI Posting. */
  671. }
  672. }
  673. global_cache_flush();
  674. intel_i830_setup_flush();
  675. return 0;
  676. }
  677. static void intel_i830_cleanup(void)
  678. {
  679. iounmap(intel_private.registers);
  680. }
  681. static int intel_i830_insert_entries(struct agp_memory *mem, off_t pg_start,
  682. int type)
  683. {
  684. int i, j, num_entries;
  685. void *temp;
  686. int ret = -EINVAL;
  687. int mask_type;
  688. if (mem->page_count == 0)
  689. goto out;
  690. temp = agp_bridge->current_size;
  691. num_entries = A_SIZE_FIX(temp)->num_entries;
  692. if (pg_start < intel_private.gtt_entries) {
  693. printk(KERN_DEBUG PFX "pg_start == 0x%.8lx,intel_private.gtt_entries == 0x%.8x\n",
  694. pg_start, intel_private.gtt_entries);
  695. printk(KERN_INFO PFX "Trying to insert into local/stolen memory\n");
  696. goto out_err;
  697. }
  698. if ((pg_start + mem->page_count) > num_entries)
  699. goto out_err;
  700. /* The i830 can't check the GTT for entries since its read only,
  701. * depend on the caller to make the correct offset decisions.
  702. */
  703. if (type != mem->type)
  704. goto out_err;
  705. mask_type = agp_bridge->driver->agp_type_to_mask_type(agp_bridge, type);
  706. if (mask_type != 0 && mask_type != AGP_PHYS_MEMORY &&
  707. mask_type != INTEL_AGP_CACHED_MEMORY)
  708. goto out_err;
  709. if (!mem->is_flushed)
  710. global_cache_flush();
  711. for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
  712. writel(agp_bridge->driver->mask_memory(agp_bridge,
  713. mem->memory[i], mask_type),
  714. intel_private.registers+I810_PTE_BASE+(j*4));
  715. }
  716. readl(intel_private.registers+I810_PTE_BASE+((j-1)*4));
  717. agp_bridge->driver->tlb_flush(mem);
  718. out:
  719. ret = 0;
  720. out_err:
  721. mem->is_flushed = true;
  722. return ret;
  723. }
  724. static int intel_i830_remove_entries(struct agp_memory *mem, off_t pg_start,
  725. int type)
  726. {
  727. int i;
  728. if (mem->page_count == 0)
  729. return 0;
  730. if (pg_start < intel_private.gtt_entries) {
  731. printk(KERN_INFO PFX "Trying to disable local/stolen memory\n");
  732. return -EINVAL;
  733. }
  734. for (i = pg_start; i < (mem->page_count + pg_start); i++) {
  735. writel(agp_bridge->scratch_page, intel_private.registers+I810_PTE_BASE+(i*4));
  736. }
  737. readl(intel_private.registers+I810_PTE_BASE+((i-1)*4));
  738. agp_bridge->driver->tlb_flush(mem);
  739. return 0;
  740. }
  741. static struct agp_memory *intel_i830_alloc_by_type(size_t pg_count, int type)
  742. {
  743. if (type == AGP_PHYS_MEMORY)
  744. return alloc_agpphysmem_i8xx(pg_count, type);
  745. /* always return NULL for other allocation types for now */
  746. return NULL;
  747. }
  748. static int intel_alloc_chipset_flush_resource(void)
  749. {
  750. int ret;
  751. ret = pci_bus_alloc_resource(agp_bridge->dev->bus, &intel_private.ifp_resource, PAGE_SIZE,
  752. PAGE_SIZE, PCIBIOS_MIN_MEM, 0,
  753. pcibios_align_resource, agp_bridge->dev);
  754. return ret;
  755. }
  756. static void intel_i915_setup_chipset_flush(void)
  757. {
  758. int ret;
  759. u32 temp;
  760. pci_read_config_dword(agp_bridge->dev, I915_IFPADDR, &temp);
  761. if (!(temp & 0x1)) {
  762. intel_alloc_chipset_flush_resource();
  763. intel_private.resource_valid = 1;
  764. pci_write_config_dword(agp_bridge->dev, I915_IFPADDR, (intel_private.ifp_resource.start & 0xffffffff) | 0x1);
  765. } else {
  766. temp &= ~1;
  767. intel_private.resource_valid = 1;
  768. intel_private.ifp_resource.start = temp;
  769. intel_private.ifp_resource.end = temp + PAGE_SIZE;
  770. ret = request_resource(&iomem_resource, &intel_private.ifp_resource);
  771. /* some BIOSes reserve this area in a pnp some don't */
  772. if (ret)
  773. intel_private.resource_valid = 0;
  774. }
  775. }
  776. static void intel_i965_g33_setup_chipset_flush(void)
  777. {
  778. u32 temp_hi, temp_lo;
  779. int ret;
  780. pci_read_config_dword(agp_bridge->dev, I965_IFPADDR + 4, &temp_hi);
  781. pci_read_config_dword(agp_bridge->dev, I965_IFPADDR, &temp_lo);
  782. if (!(temp_lo & 0x1)) {
  783. intel_alloc_chipset_flush_resource();
  784. intel_private.resource_valid = 1;
  785. pci_write_config_dword(agp_bridge->dev, I965_IFPADDR + 4,
  786. upper_32_bits(intel_private.ifp_resource.start));
  787. pci_write_config_dword(agp_bridge->dev, I965_IFPADDR, (intel_private.ifp_resource.start & 0xffffffff) | 0x1);
  788. } else {
  789. u64 l64;
  790. temp_lo &= ~0x1;
  791. l64 = ((u64)temp_hi << 32) | temp_lo;
  792. intel_private.resource_valid = 1;
  793. intel_private.ifp_resource.start = l64;
  794. intel_private.ifp_resource.end = l64 + PAGE_SIZE;
  795. ret = request_resource(&iomem_resource, &intel_private.ifp_resource);
  796. /* some BIOSes reserve this area in a pnp some don't */
  797. if (ret)
  798. intel_private.resource_valid = 0;
  799. }
  800. }
  801. static void intel_i9xx_setup_flush(void)
  802. {
  803. /* return if already configured */
  804. if (intel_private.ifp_resource.start)
  805. return;
  806. /* setup a resource for this object */
  807. intel_private.ifp_resource.name = "Intel Flush Page";
  808. intel_private.ifp_resource.flags = IORESOURCE_MEM;
  809. /* Setup chipset flush for 915 */
  810. if (IS_I965 || IS_G33 || IS_G4X) {
  811. intel_i965_g33_setup_chipset_flush();
  812. } else {
  813. intel_i915_setup_chipset_flush();
  814. }
  815. if (intel_private.ifp_resource.start) {
  816. intel_private.i9xx_flush_page = ioremap_nocache(intel_private.ifp_resource.start, PAGE_SIZE);
  817. if (!intel_private.i9xx_flush_page)
  818. printk(KERN_INFO "unable to ioremap flush page - no chipset flushing");
  819. }
  820. }
  821. static int intel_i915_configure(void)
  822. {
  823. struct aper_size_info_fixed *current_size;
  824. u32 temp;
  825. u16 gmch_ctrl;
  826. int i;
  827. current_size = A_SIZE_FIX(agp_bridge->current_size);
  828. pci_read_config_dword(intel_private.pcidev, I915_GMADDR, &temp);
  829. agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
  830. pci_read_config_word(agp_bridge->dev, I830_GMCH_CTRL, &gmch_ctrl);
  831. gmch_ctrl |= I830_GMCH_ENABLED;
  832. pci_write_config_word(agp_bridge->dev, I830_GMCH_CTRL, gmch_ctrl);
  833. writel(agp_bridge->gatt_bus_addr|I810_PGETBL_ENABLED, intel_private.registers+I810_PGETBL_CTL);
  834. readl(intel_private.registers+I810_PGETBL_CTL); /* PCI Posting. */
  835. if (agp_bridge->driver->needs_scratch_page) {
  836. for (i = intel_private.gtt_entries; i < current_size->num_entries; i++) {
  837. writel(agp_bridge->scratch_page, intel_private.gtt+i);
  838. readl(intel_private.gtt+i); /* PCI Posting. */
  839. }
  840. }
  841. global_cache_flush();
  842. intel_i9xx_setup_flush();
  843. return 0;
  844. }
  845. static void intel_i915_cleanup(void)
  846. {
  847. if (intel_private.i9xx_flush_page)
  848. iounmap(intel_private.i9xx_flush_page);
  849. if (intel_private.resource_valid)
  850. release_resource(&intel_private.ifp_resource);
  851. intel_private.ifp_resource.start = 0;
  852. intel_private.resource_valid = 0;
  853. iounmap(intel_private.gtt);
  854. iounmap(intel_private.registers);
  855. }
  856. static void intel_i915_chipset_flush(struct agp_bridge_data *bridge)
  857. {
  858. if (intel_private.i9xx_flush_page)
  859. writel(1, intel_private.i9xx_flush_page);
  860. }
  861. static int intel_i915_insert_entries(struct agp_memory *mem, off_t pg_start,
  862. int type)
  863. {
  864. int i, j, num_entries;
  865. void *temp;
  866. int ret = -EINVAL;
  867. int mask_type;
  868. if (mem->page_count == 0)
  869. goto out;
  870. temp = agp_bridge->current_size;
  871. num_entries = A_SIZE_FIX(temp)->num_entries;
  872. if (pg_start < intel_private.gtt_entries) {
  873. printk(KERN_DEBUG PFX "pg_start == 0x%.8lx,intel_private.gtt_entries == 0x%.8x\n",
  874. pg_start, intel_private.gtt_entries);
  875. printk(KERN_INFO PFX "Trying to insert into local/stolen memory\n");
  876. goto out_err;
  877. }
  878. if ((pg_start + mem->page_count) > num_entries)
  879. goto out_err;
  880. /* The i915 can't check the GTT for entries since its read only,
  881. * depend on the caller to make the correct offset decisions.
  882. */
  883. if (type != mem->type)
  884. goto out_err;
  885. mask_type = agp_bridge->driver->agp_type_to_mask_type(agp_bridge, type);
  886. if (mask_type != 0 && mask_type != AGP_PHYS_MEMORY &&
  887. mask_type != INTEL_AGP_CACHED_MEMORY)
  888. goto out_err;
  889. if (!mem->is_flushed)
  890. global_cache_flush();
  891. for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
  892. writel(agp_bridge->driver->mask_memory(agp_bridge,
  893. mem->memory[i], mask_type), intel_private.gtt+j);
  894. }
  895. readl(intel_private.gtt+j-1);
  896. agp_bridge->driver->tlb_flush(mem);
  897. out:
  898. ret = 0;
  899. out_err:
  900. mem->is_flushed = true;
  901. return ret;
  902. }
  903. static int intel_i915_remove_entries(struct agp_memory *mem, off_t pg_start,
  904. int type)
  905. {
  906. int i;
  907. if (mem->page_count == 0)
  908. return 0;
  909. if (pg_start < intel_private.gtt_entries) {
  910. printk(KERN_INFO PFX "Trying to disable local/stolen memory\n");
  911. return -EINVAL;
  912. }
  913. for (i = pg_start; i < (mem->page_count + pg_start); i++)
  914. writel(agp_bridge->scratch_page, intel_private.gtt+i);
  915. readl(intel_private.gtt+i-1);
  916. agp_bridge->driver->tlb_flush(mem);
  917. return 0;
  918. }
  919. /* Return the aperture size by just checking the resource length. The effect
  920. * described in the spec of the MSAC registers is just changing of the
  921. * resource size.
  922. */
  923. static int intel_i9xx_fetch_size(void)
  924. {
  925. int num_sizes = ARRAY_SIZE(intel_i830_sizes);
  926. int aper_size; /* size in megabytes */
  927. int i;
  928. aper_size = pci_resource_len(intel_private.pcidev, 2) / MB(1);
  929. for (i = 0; i < num_sizes; i++) {
  930. if (aper_size == intel_i830_sizes[i].size) {
  931. agp_bridge->current_size = intel_i830_sizes + i;
  932. agp_bridge->previous_size = agp_bridge->current_size;
  933. return aper_size;
  934. }
  935. }
  936. return 0;
  937. }
  938. /* The intel i915 automatically initializes the agp aperture during POST.
  939. * Use the memory already set aside for in the GTT.
  940. */
  941. static int intel_i915_create_gatt_table(struct agp_bridge_data *bridge)
  942. {
  943. int page_order;
  944. struct aper_size_info_fixed *size;
  945. int num_entries;
  946. u32 temp, temp2;
  947. int gtt_map_size = 256 * 1024;
  948. size = agp_bridge->current_size;
  949. page_order = size->page_order;
  950. num_entries = size->num_entries;
  951. agp_bridge->gatt_table_real = NULL;
  952. pci_read_config_dword(intel_private.pcidev, I915_MMADDR, &temp);
  953. pci_read_config_dword(intel_private.pcidev, I915_PTEADDR, &temp2);
  954. if (IS_G33)
  955. gtt_map_size = 1024 * 1024; /* 1M on G33 */
  956. intel_private.gtt = ioremap(temp2, gtt_map_size);
  957. if (!intel_private.gtt)
  958. return -ENOMEM;
  959. temp &= 0xfff80000;
  960. intel_private.registers = ioremap(temp, 128 * 4096);
  961. if (!intel_private.registers) {
  962. iounmap(intel_private.gtt);
  963. return -ENOMEM;
  964. }
  965. temp = readl(intel_private.registers+I810_PGETBL_CTL) & 0xfffff000;
  966. global_cache_flush(); /* FIXME: ? */
  967. /* we have to call this as early as possible after the MMIO base address is known */
  968. intel_i830_init_gtt_entries();
  969. agp_bridge->gatt_table = NULL;
  970. agp_bridge->gatt_bus_addr = temp;
  971. return 0;
  972. }
  973. /*
  974. * The i965 supports 36-bit physical addresses, but to keep
  975. * the format of the GTT the same, the bits that don't fit
  976. * in a 32-bit word are shifted down to bits 4..7.
  977. *
  978. * Gcc is smart enough to notice that "(addr >> 28) & 0xf0"
  979. * is always zero on 32-bit architectures, so no need to make
  980. * this conditional.
  981. */
  982. static unsigned long intel_i965_mask_memory(struct agp_bridge_data *bridge,
  983. unsigned long addr, int type)
  984. {
  985. /* Shift high bits down */
  986. addr |= (addr >> 28) & 0xf0;
  987. /* Type checking must be done elsewhere */
  988. return addr | bridge->driver->masks[type].mask;
  989. }
  990. static void intel_i965_get_gtt_range(int *gtt_offset, int *gtt_size)
  991. {
  992. switch (agp_bridge->dev->device) {
  993. case PCI_DEVICE_ID_INTEL_IGD_HB:
  994. case PCI_DEVICE_ID_INTEL_IGD_E_HB:
  995. case PCI_DEVICE_ID_INTEL_Q45_HB:
  996. case PCI_DEVICE_ID_INTEL_G45_HB:
  997. *gtt_offset = *gtt_size = MB(2);
  998. break;
  999. default:
  1000. *gtt_offset = *gtt_size = KB(512);
  1001. }
  1002. }
  1003. /* The intel i965 automatically initializes the agp aperture during POST.
  1004. * Use the memory already set aside for in the GTT.
  1005. */
  1006. static int intel_i965_create_gatt_table(struct agp_bridge_data *bridge)
  1007. {
  1008. int page_order;
  1009. struct aper_size_info_fixed *size;
  1010. int num_entries;
  1011. u32 temp;
  1012. int gtt_offset, gtt_size;
  1013. size = agp_bridge->current_size;
  1014. page_order = size->page_order;
  1015. num_entries = size->num_entries;
  1016. agp_bridge->gatt_table_real = NULL;
  1017. pci_read_config_dword(intel_private.pcidev, I915_MMADDR, &temp);
  1018. temp &= 0xfff00000;
  1019. intel_i965_get_gtt_range(&gtt_offset, &gtt_size);
  1020. intel_private.gtt = ioremap((temp + gtt_offset) , gtt_size);
  1021. if (!intel_private.gtt)
  1022. return -ENOMEM;
  1023. intel_private.registers = ioremap(temp, 128 * 4096);
  1024. if (!intel_private.registers) {
  1025. iounmap(intel_private.gtt);
  1026. return -ENOMEM;
  1027. }
  1028. temp = readl(intel_private.registers+I810_PGETBL_CTL) & 0xfffff000;
  1029. global_cache_flush(); /* FIXME: ? */
  1030. /* we have to call this as early as possible after the MMIO base address is known */
  1031. intel_i830_init_gtt_entries();
  1032. agp_bridge->gatt_table = NULL;
  1033. agp_bridge->gatt_bus_addr = temp;
  1034. return 0;
  1035. }
  1036. static int intel_fetch_size(void)
  1037. {
  1038. int i;
  1039. u16 temp;
  1040. struct aper_size_info_16 *values;
  1041. pci_read_config_word(agp_bridge->dev, INTEL_APSIZE, &temp);
  1042. values = A_SIZE_16(agp_bridge->driver->aperture_sizes);
  1043. for (i = 0; i < agp_bridge->driver->num_aperture_sizes; i++) {
  1044. if (temp == values[i].size_value) {
  1045. agp_bridge->previous_size = agp_bridge->current_size = (void *) (values + i);
  1046. agp_bridge->aperture_size_idx = i;
  1047. return values[i].size;
  1048. }
  1049. }
  1050. return 0;
  1051. }
  1052. static int __intel_8xx_fetch_size(u8 temp)
  1053. {
  1054. int i;
  1055. struct aper_size_info_8 *values;
  1056. values = A_SIZE_8(agp_bridge->driver->aperture_sizes);
  1057. for (i = 0; i < agp_bridge->driver->num_aperture_sizes; i++) {
  1058. if (temp == values[i].size_value) {
  1059. agp_bridge->previous_size =
  1060. agp_bridge->current_size = (void *) (values + i);
  1061. agp_bridge->aperture_size_idx = i;
  1062. return values[i].size;
  1063. }
  1064. }
  1065. return 0;
  1066. }
  1067. static int intel_8xx_fetch_size(void)
  1068. {
  1069. u8 temp;
  1070. pci_read_config_byte(agp_bridge->dev, INTEL_APSIZE, &temp);
  1071. return __intel_8xx_fetch_size(temp);
  1072. }
  1073. static int intel_815_fetch_size(void)
  1074. {
  1075. u8 temp;
  1076. /* Intel 815 chipsets have a _weird_ APSIZE register with only
  1077. * one non-reserved bit, so mask the others out ... */
  1078. pci_read_config_byte(agp_bridge->dev, INTEL_APSIZE, &temp);
  1079. temp &= (1 << 3);
  1080. return __intel_8xx_fetch_size(temp);
  1081. }
  1082. static void intel_tlbflush(struct agp_memory *mem)
  1083. {
  1084. pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x2200);
  1085. pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x2280);
  1086. }
  1087. static void intel_8xx_tlbflush(struct agp_memory *mem)
  1088. {
  1089. u32 temp;
  1090. pci_read_config_dword(agp_bridge->dev, INTEL_AGPCTRL, &temp);
  1091. pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, temp & ~(1 << 7));
  1092. pci_read_config_dword(agp_bridge->dev, INTEL_AGPCTRL, &temp);
  1093. pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, temp | (1 << 7));
  1094. }
  1095. static void intel_cleanup(void)
  1096. {
  1097. u16 temp;
  1098. struct aper_size_info_16 *previous_size;
  1099. previous_size = A_SIZE_16(agp_bridge->previous_size);
  1100. pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp);
  1101. pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG, temp & ~(1 << 9));
  1102. pci_write_config_word(agp_bridge->dev, INTEL_APSIZE, previous_size->size_value);
  1103. }
  1104. static void intel_8xx_cleanup(void)
  1105. {
  1106. u16 temp;
  1107. struct aper_size_info_8 *previous_size;
  1108. previous_size = A_SIZE_8(agp_bridge->previous_size);
  1109. pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp);
  1110. pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG, temp & ~(1 << 9));
  1111. pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, previous_size->size_value);
  1112. }
  1113. static int intel_configure(void)
  1114. {
  1115. u32 temp;
  1116. u16 temp2;
  1117. struct aper_size_info_16 *current_size;
  1118. current_size = A_SIZE_16(agp_bridge->current_size);
  1119. /* aperture size */
  1120. pci_write_config_word(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
  1121. /* address to map to */
  1122. pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
  1123. agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
  1124. /* attbase - aperture base */
  1125. pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
  1126. /* agpctrl */
  1127. pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x2280);
  1128. /* paccfg/nbxcfg */
  1129. pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp2);
  1130. pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG,
  1131. (temp2 & ~(1 << 10)) | (1 << 9));
  1132. /* clear any possible error conditions */
  1133. pci_write_config_byte(agp_bridge->dev, INTEL_ERRSTS + 1, 7);
  1134. return 0;
  1135. }
  1136. static int intel_815_configure(void)
  1137. {
  1138. u32 temp, addr;
  1139. u8 temp2;
  1140. struct aper_size_info_8 *current_size;
  1141. /* attbase - aperture base */
  1142. /* the Intel 815 chipset spec. says that bits 29-31 in the
  1143. * ATTBASE register are reserved -> try not to write them */
  1144. if (agp_bridge->gatt_bus_addr & INTEL_815_ATTBASE_MASK) {
  1145. printk(KERN_EMERG PFX "gatt bus addr too high");
  1146. return -EINVAL;
  1147. }
  1148. current_size = A_SIZE_8(agp_bridge->current_size);
  1149. /* aperture size */
  1150. pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE,
  1151. current_size->size_value);
  1152. /* address to map to */
  1153. pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
  1154. agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
  1155. pci_read_config_dword(agp_bridge->dev, INTEL_ATTBASE, &addr);
  1156. addr &= INTEL_815_ATTBASE_MASK;
  1157. addr |= agp_bridge->gatt_bus_addr;
  1158. pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, addr);
  1159. /* agpctrl */
  1160. pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
  1161. /* apcont */
  1162. pci_read_config_byte(agp_bridge->dev, INTEL_815_APCONT, &temp2);
  1163. pci_write_config_byte(agp_bridge->dev, INTEL_815_APCONT, temp2 | (1 << 1));
  1164. /* clear any possible error conditions */
  1165. /* Oddness : this chipset seems to have no ERRSTS register ! */
  1166. return 0;
  1167. }
  1168. static void intel_820_tlbflush(struct agp_memory *mem)
  1169. {
  1170. return;
  1171. }
  1172. static void intel_820_cleanup(void)
  1173. {
  1174. u8 temp;
  1175. struct aper_size_info_8 *previous_size;
  1176. previous_size = A_SIZE_8(agp_bridge->previous_size);
  1177. pci_read_config_byte(agp_bridge->dev, INTEL_I820_RDCR, &temp);
  1178. pci_write_config_byte(agp_bridge->dev, INTEL_I820_RDCR,
  1179. temp & ~(1 << 1));
  1180. pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE,
  1181. previous_size->size_value);
  1182. }
  1183. static int intel_820_configure(void)
  1184. {
  1185. u32 temp;
  1186. u8 temp2;
  1187. struct aper_size_info_8 *current_size;
  1188. current_size = A_SIZE_8(agp_bridge->current_size);
  1189. /* aperture size */
  1190. pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
  1191. /* address to map to */
  1192. pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
  1193. agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
  1194. /* attbase - aperture base */
  1195. pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
  1196. /* agpctrl */
  1197. pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
  1198. /* global enable aperture access */
  1199. /* This flag is not accessed through MCHCFG register as in */
  1200. /* i850 chipset. */
  1201. pci_read_config_byte(agp_bridge->dev, INTEL_I820_RDCR, &temp2);
  1202. pci_write_config_byte(agp_bridge->dev, INTEL_I820_RDCR, temp2 | (1 << 1));
  1203. /* clear any possible AGP-related error conditions */
  1204. pci_write_config_word(agp_bridge->dev, INTEL_I820_ERRSTS, 0x001c);
  1205. return 0;
  1206. }
  1207. static int intel_840_configure(void)
  1208. {
  1209. u32 temp;
  1210. u16 temp2;
  1211. struct aper_size_info_8 *current_size;
  1212. current_size = A_SIZE_8(agp_bridge->current_size);
  1213. /* aperture size */
  1214. pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
  1215. /* address to map to */
  1216. pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
  1217. agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
  1218. /* attbase - aperture base */
  1219. pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
  1220. /* agpctrl */
  1221. pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
  1222. /* mcgcfg */
  1223. pci_read_config_word(agp_bridge->dev, INTEL_I840_MCHCFG, &temp2);
  1224. pci_write_config_word(agp_bridge->dev, INTEL_I840_MCHCFG, temp2 | (1 << 9));
  1225. /* clear any possible error conditions */
  1226. pci_write_config_word(agp_bridge->dev, INTEL_I840_ERRSTS, 0xc000);
  1227. return 0;
  1228. }
  1229. static int intel_845_configure(void)
  1230. {
  1231. u32 temp;
  1232. u8 temp2;
  1233. struct aper_size_info_8 *current_size;
  1234. current_size = A_SIZE_8(agp_bridge->current_size);
  1235. /* aperture size */
  1236. pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
  1237. if (agp_bridge->apbase_config != 0) {
  1238. pci_write_config_dword(agp_bridge->dev, AGP_APBASE,
  1239. agp_bridge->apbase_config);
  1240. } else {
  1241. /* address to map to */
  1242. pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
  1243. agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
  1244. agp_bridge->apbase_config = temp;
  1245. }
  1246. /* attbase - aperture base */
  1247. pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
  1248. /* agpctrl */
  1249. pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
  1250. /* agpm */
  1251. pci_read_config_byte(agp_bridge->dev, INTEL_I845_AGPM, &temp2);
  1252. pci_write_config_byte(agp_bridge->dev, INTEL_I845_AGPM, temp2 | (1 << 1));
  1253. /* clear any possible error conditions */
  1254. pci_write_config_word(agp_bridge->dev, INTEL_I845_ERRSTS, 0x001c);
  1255. intel_i830_setup_flush();
  1256. return 0;
  1257. }
  1258. static int intel_850_configure(void)
  1259. {
  1260. u32 temp;
  1261. u16 temp2;
  1262. struct aper_size_info_8 *current_size;
  1263. current_size = A_SIZE_8(agp_bridge->current_size);
  1264. /* aperture size */
  1265. pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
  1266. /* address to map to */
  1267. pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
  1268. agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
  1269. /* attbase - aperture base */
  1270. pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
  1271. /* agpctrl */
  1272. pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
  1273. /* mcgcfg */
  1274. pci_read_config_word(agp_bridge->dev, INTEL_I850_MCHCFG, &temp2);
  1275. pci_write_config_word(agp_bridge->dev, INTEL_I850_MCHCFG, temp2 | (1 << 9));
  1276. /* clear any possible AGP-related error conditions */
  1277. pci_write_config_word(agp_bridge->dev, INTEL_I850_ERRSTS, 0x001c);
  1278. return 0;
  1279. }
  1280. static int intel_860_configure(void)
  1281. {
  1282. u32 temp;
  1283. u16 temp2;
  1284. struct aper_size_info_8 *current_size;
  1285. current_size = A_SIZE_8(agp_bridge->current_size);
  1286. /* aperture size */
  1287. pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
  1288. /* address to map to */
  1289. pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
  1290. agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
  1291. /* attbase - aperture base */
  1292. pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
  1293. /* agpctrl */
  1294. pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
  1295. /* mcgcfg */
  1296. pci_read_config_word(agp_bridge->dev, INTEL_I860_MCHCFG, &temp2);
  1297. pci_write_config_word(agp_bridge->dev, INTEL_I860_MCHCFG, temp2 | (1 << 9));
  1298. /* clear any possible AGP-related error conditions */
  1299. pci_write_config_word(agp_bridge->dev, INTEL_I860_ERRSTS, 0xf700);
  1300. return 0;
  1301. }
  1302. static int intel_830mp_configure(void)
  1303. {
  1304. u32 temp;
  1305. u16 temp2;
  1306. struct aper_size_info_8 *current_size;
  1307. current_size = A_SIZE_8(agp_bridge->current_size);
  1308. /* aperture size */
  1309. pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
  1310. /* address to map to */
  1311. pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
  1312. agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
  1313. /* attbase - aperture base */
  1314. pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
  1315. /* agpctrl */
  1316. pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
  1317. /* gmch */
  1318. pci_read_config_word(agp_bridge->dev, INTEL_NBXCFG, &temp2);
  1319. pci_write_config_word(agp_bridge->dev, INTEL_NBXCFG, temp2 | (1 << 9));
  1320. /* clear any possible AGP-related error conditions */
  1321. pci_write_config_word(agp_bridge->dev, INTEL_I830_ERRSTS, 0x1c);
  1322. return 0;
  1323. }
  1324. static int intel_7505_configure(void)
  1325. {
  1326. u32 temp;
  1327. u16 temp2;
  1328. struct aper_size_info_8 *current_size;
  1329. current_size = A_SIZE_8(agp_bridge->current_size);
  1330. /* aperture size */
  1331. pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
  1332. /* address to map to */
  1333. pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
  1334. agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
  1335. /* attbase - aperture base */
  1336. pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
  1337. /* agpctrl */
  1338. pci_write_config_dword(agp_bridge->dev, INTEL_AGPCTRL, 0x0000);
  1339. /* mchcfg */
  1340. pci_read_config_word(agp_bridge->dev, INTEL_I7505_MCHCFG, &temp2);
  1341. pci_write_config_word(agp_bridge->dev, INTEL_I7505_MCHCFG, temp2 | (1 << 9));
  1342. return 0;
  1343. }
  1344. /* Setup function */
  1345. static const struct gatt_mask intel_generic_masks[] =
  1346. {
  1347. {.mask = 0x00000017, .type = 0}
  1348. };
  1349. static const struct aper_size_info_8 intel_815_sizes[2] =
  1350. {
  1351. {64, 16384, 4, 0},
  1352. {32, 8192, 3, 8},
  1353. };
  1354. static const struct aper_size_info_8 intel_8xx_sizes[7] =
  1355. {
  1356. {256, 65536, 6, 0},
  1357. {128, 32768, 5, 32},
  1358. {64, 16384, 4, 48},
  1359. {32, 8192, 3, 56},
  1360. {16, 4096, 2, 60},
  1361. {8, 2048, 1, 62},
  1362. {4, 1024, 0, 63}
  1363. };
  1364. static const struct aper_size_info_16 intel_generic_sizes[7] =
  1365. {
  1366. {256, 65536, 6, 0},
  1367. {128, 32768, 5, 32},
  1368. {64, 16384, 4, 48},
  1369. {32, 8192, 3, 56},
  1370. {16, 4096, 2, 60},
  1371. {8, 2048, 1, 62},
  1372. {4, 1024, 0, 63}
  1373. };
  1374. static const struct aper_size_info_8 intel_830mp_sizes[4] =
  1375. {
  1376. {256, 65536, 6, 0},
  1377. {128, 32768, 5, 32},
  1378. {64, 16384, 4, 48},
  1379. {32, 8192, 3, 56}
  1380. };
  1381. static const struct agp_bridge_driver intel_generic_driver = {
  1382. .owner = THIS_MODULE,
  1383. .aperture_sizes = intel_generic_sizes,
  1384. .size_type = U16_APER_SIZE,
  1385. .num_aperture_sizes = 7,
  1386. .configure = intel_configure,
  1387. .fetch_size = intel_fetch_size,
  1388. .cleanup = intel_cleanup,
  1389. .tlb_flush = intel_tlbflush,
  1390. .mask_memory = agp_generic_mask_memory,
  1391. .masks = intel_generic_masks,
  1392. .agp_enable = agp_generic_enable,
  1393. .cache_flush = global_cache_flush,
  1394. .create_gatt_table = agp_generic_create_gatt_table,
  1395. .free_gatt_table = agp_generic_free_gatt_table,
  1396. .insert_memory = agp_generic_insert_memory,
  1397. .remove_memory = agp_generic_remove_memory,
  1398. .alloc_by_type = agp_generic_alloc_by_type,
  1399. .free_by_type = agp_generic_free_by_type,
  1400. .agp_alloc_page = agp_generic_alloc_page,
  1401. .agp_destroy_page = agp_generic_destroy_page,
  1402. .agp_type_to_mask_type = agp_generic_type_to_mask_type,
  1403. };
  1404. static const struct agp_bridge_driver intel_810_driver = {
  1405. .owner = THIS_MODULE,
  1406. .aperture_sizes = intel_i810_sizes,
  1407. .size_type = FIXED_APER_SIZE,
  1408. .num_aperture_sizes = 2,
  1409. .needs_scratch_page = true,
  1410. .configure = intel_i810_configure,
  1411. .fetch_size = intel_i810_fetch_size,
  1412. .cleanup = intel_i810_cleanup,
  1413. .tlb_flush = intel_i810_tlbflush,
  1414. .mask_memory = intel_i810_mask_memory,
  1415. .masks = intel_i810_masks,
  1416. .agp_enable = intel_i810_agp_enable,
  1417. .cache_flush = global_cache_flush,
  1418. .create_gatt_table = agp_generic_create_gatt_table,
  1419. .free_gatt_table = agp_generic_free_gatt_table,
  1420. .insert_memory = intel_i810_insert_entries,
  1421. .remove_memory = intel_i810_remove_entries,
  1422. .alloc_by_type = intel_i810_alloc_by_type,
  1423. .free_by_type = intel_i810_free_by_type,
  1424. .agp_alloc_page = agp_generic_alloc_page,
  1425. .agp_destroy_page = agp_generic_destroy_page,
  1426. .agp_type_to_mask_type = agp_generic_type_to_mask_type,
  1427. };
  1428. static const struct agp_bridge_driver intel_815_driver = {
  1429. .owner = THIS_MODULE,
  1430. .aperture_sizes = intel_815_sizes,
  1431. .size_type = U8_APER_SIZE,
  1432. .num_aperture_sizes = 2,
  1433. .configure = intel_815_configure,
  1434. .fetch_size = intel_815_fetch_size,
  1435. .cleanup = intel_8xx_cleanup,
  1436. .tlb_flush = intel_8xx_tlbflush,
  1437. .mask_memory = agp_generic_mask_memory,
  1438. .masks = intel_generic_masks,
  1439. .agp_enable = agp_generic_enable,
  1440. .cache_flush = global_cache_flush,
  1441. .create_gatt_table = agp_generic_create_gatt_table,
  1442. .free_gatt_table = agp_generic_free_gatt_table,
  1443. .insert_memory = agp_generic_insert_memory,
  1444. .remove_memory = agp_generic_remove_memory,
  1445. .alloc_by_type = agp_generic_alloc_by_type,
  1446. .free_by_type = agp_generic_free_by_type,
  1447. .agp_alloc_page = agp_generic_alloc_page,
  1448. .agp_destroy_page = agp_generic_destroy_page,
  1449. .agp_type_to_mask_type = agp_generic_type_to_mask_type,
  1450. };
  1451. static const struct agp_bridge_driver intel_830_driver = {
  1452. .owner = THIS_MODULE,
  1453. .aperture_sizes = intel_i830_sizes,
  1454. .size_type = FIXED_APER_SIZE,
  1455. .num_aperture_sizes = 4,
  1456. .needs_scratch_page = true,
  1457. .configure = intel_i830_configure,
  1458. .fetch_size = intel_i830_fetch_size,
  1459. .cleanup = intel_i830_cleanup,
  1460. .tlb_flush = intel_i810_tlbflush,
  1461. .mask_memory = intel_i810_mask_memory,
  1462. .masks = intel_i810_masks,
  1463. .agp_enable = intel_i810_agp_enable,
  1464. .cache_flush = global_cache_flush,
  1465. .create_gatt_table = intel_i830_create_gatt_table,
  1466. .free_gatt_table = intel_i830_free_gatt_table,
  1467. .insert_memory = intel_i830_insert_entries,
  1468. .remove_memory = intel_i830_remove_entries,
  1469. .alloc_by_type = intel_i830_alloc_by_type,
  1470. .free_by_type = intel_i810_free_by_type,
  1471. .agp_alloc_page = agp_generic_alloc_page,
  1472. .agp_destroy_page = agp_generic_destroy_page,
  1473. .agp_type_to_mask_type = intel_i830_type_to_mask_type,
  1474. .chipset_flush = intel_i830_chipset_flush,
  1475. };
  1476. static const struct agp_bridge_driver intel_820_driver = {
  1477. .owner = THIS_MODULE,
  1478. .aperture_sizes = intel_8xx_sizes,
  1479. .size_type = U8_APER_SIZE,
  1480. .num_aperture_sizes = 7,
  1481. .configure = intel_820_configure,
  1482. .fetch_size = intel_8xx_fetch_size,
  1483. .cleanup = intel_820_cleanup,
  1484. .tlb_flush = intel_820_tlbflush,
  1485. .mask_memory = agp_generic_mask_memory,
  1486. .masks = intel_generic_masks,
  1487. .agp_enable = agp_generic_enable,
  1488. .cache_flush = global_cache_flush,
  1489. .create_gatt_table = agp_generic_create_gatt_table,
  1490. .free_gatt_table = agp_generic_free_gatt_table,
  1491. .insert_memory = agp_generic_insert_memory,
  1492. .remove_memory = agp_generic_remove_memory,
  1493. .alloc_by_type = agp_generic_alloc_by_type,
  1494. .free_by_type = agp_generic_free_by_type,
  1495. .agp_alloc_page = agp_generic_alloc_page,
  1496. .agp_destroy_page = agp_generic_destroy_page,
  1497. .agp_type_to_mask_type = agp_generic_type_to_mask_type,
  1498. };
  1499. static const struct agp_bridge_driver intel_830mp_driver = {
  1500. .owner = THIS_MODULE,
  1501. .aperture_sizes = intel_830mp_sizes,
  1502. .size_type = U8_APER_SIZE,
  1503. .num_aperture_sizes = 4,
  1504. .configure = intel_830mp_configure,
  1505. .fetch_size = intel_8xx_fetch_size,
  1506. .cleanup = intel_8xx_cleanup,
  1507. .tlb_flush = intel_8xx_tlbflush,
  1508. .mask_memory = agp_generic_mask_memory,
  1509. .masks = intel_generic_masks,
  1510. .agp_enable = agp_generic_enable,
  1511. .cache_flush = global_cache_flush,
  1512. .create_gatt_table = agp_generic_create_gatt_table,
  1513. .free_gatt_table = agp_generic_free_gatt_table,
  1514. .insert_memory = agp_generic_insert_memory,
  1515. .remove_memory = agp_generic_remove_memory,
  1516. .alloc_by_type = agp_generic_alloc_by_type,
  1517. .free_by_type = agp_generic_free_by_type,
  1518. .agp_alloc_page = agp_generic_alloc_page,
  1519. .agp_destroy_page = agp_generic_destroy_page,
  1520. .agp_type_to_mask_type = agp_generic_type_to_mask_type,
  1521. };
  1522. static const struct agp_bridge_driver intel_840_driver = {
  1523. .owner = THIS_MODULE,
  1524. .aperture_sizes = intel_8xx_sizes,
  1525. .size_type = U8_APER_SIZE,
  1526. .num_aperture_sizes = 7,
  1527. .configure = intel_840_configure,
  1528. .fetch_size = intel_8xx_fetch_size,
  1529. .cleanup = intel_8xx_cleanup,
  1530. .tlb_flush = intel_8xx_tlbflush,
  1531. .mask_memory = agp_generic_mask_memory,
  1532. .masks = intel_generic_masks,
  1533. .agp_enable = agp_generic_enable,
  1534. .cache_flush = global_cache_flush,
  1535. .create_gatt_table = agp_generic_create_gatt_table,
  1536. .free_gatt_table = agp_generic_free_gatt_table,
  1537. .insert_memory = agp_generic_insert_memory,
  1538. .remove_memory = agp_generic_remove_memory,
  1539. .alloc_by_type = agp_generic_alloc_by_type,
  1540. .free_by_type = agp_generic_free_by_type,
  1541. .agp_alloc_page = agp_generic_alloc_page,
  1542. .agp_destroy_page = agp_generic_destroy_page,
  1543. .agp_type_to_mask_type = agp_generic_type_to_mask_type,
  1544. };
  1545. static const struct agp_bridge_driver intel_845_driver = {
  1546. .owner = THIS_MODULE,
  1547. .aperture_sizes = intel_8xx_sizes,
  1548. .size_type = U8_APER_SIZE,
  1549. .num_aperture_sizes = 7,
  1550. .configure = intel_845_configure,
  1551. .fetch_size = intel_8xx_fetch_size,
  1552. .cleanup = intel_8xx_cleanup,
  1553. .tlb_flush = intel_8xx_tlbflush,
  1554. .mask_memory = agp_generic_mask_memory,
  1555. .masks = intel_generic_masks,
  1556. .agp_enable = agp_generic_enable,
  1557. .cache_flush = global_cache_flush,
  1558. .create_gatt_table = agp_generic_create_gatt_table,
  1559. .free_gatt_table = agp_generic_free_gatt_table,
  1560. .insert_memory = agp_generic_insert_memory,
  1561. .remove_memory = agp_generic_remove_memory,
  1562. .alloc_by_type = agp_generic_alloc_by_type,
  1563. .free_by_type = agp_generic_free_by_type,
  1564. .agp_alloc_page = agp_generic_alloc_page,
  1565. .agp_destroy_page = agp_generic_destroy_page,
  1566. .agp_type_to_mask_type = agp_generic_type_to_mask_type,
  1567. .chipset_flush = intel_i830_chipset_flush,
  1568. };
  1569. static const struct agp_bridge_driver intel_850_driver = {
  1570. .owner = THIS_MODULE,
  1571. .aperture_sizes = intel_8xx_sizes,
  1572. .size_type = U8_APER_SIZE,
  1573. .num_aperture_sizes = 7,
  1574. .configure = intel_850_configure,
  1575. .fetch_size = intel_8xx_fetch_size,
  1576. .cleanup = intel_8xx_cleanup,
  1577. .tlb_flush = intel_8xx_tlbflush,
  1578. .mask_memory = agp_generic_mask_memory,
  1579. .masks = intel_generic_masks,
  1580. .agp_enable = agp_generic_enable,
  1581. .cache_flush = global_cache_flush,
  1582. .create_gatt_table = agp_generic_create_gatt_table,
  1583. .free_gatt_table = agp_generic_free_gatt_table,
  1584. .insert_memory = agp_generic_insert_memory,
  1585. .remove_memory = agp_generic_remove_memory,
  1586. .alloc_by_type = agp_generic_alloc_by_type,
  1587. .free_by_type = agp_generic_free_by_type,
  1588. .agp_alloc_page = agp_generic_alloc_page,
  1589. .agp_destroy_page = agp_generic_destroy_page,
  1590. .agp_type_to_mask_type = agp_generic_type_to_mask_type,
  1591. };
  1592. static const struct agp_bridge_driver intel_860_driver = {
  1593. .owner = THIS_MODULE,
  1594. .aperture_sizes = intel_8xx_sizes,
  1595. .size_type = U8_APER_SIZE,
  1596. .num_aperture_sizes = 7,
  1597. .configure = intel_860_configure,
  1598. .fetch_size = intel_8xx_fetch_size,
  1599. .cleanup = intel_8xx_cleanup,
  1600. .tlb_flush = intel_8xx_tlbflush,
  1601. .mask_memory = agp_generic_mask_memory,
  1602. .masks = intel_generic_masks,
  1603. .agp_enable = agp_generic_enable,
  1604. .cache_flush = global_cache_flush,
  1605. .create_gatt_table = agp_generic_create_gatt_table,
  1606. .free_gatt_table = agp_generic_free_gatt_table,
  1607. .insert_memory = agp_generic_insert_memory,
  1608. .remove_memory = agp_generic_remove_memory,
  1609. .alloc_by_type = agp_generic_alloc_by_type,
  1610. .free_by_type = agp_generic_free_by_type,
  1611. .agp_alloc_page = agp_generic_alloc_page,
  1612. .agp_destroy_page = agp_generic_destroy_page,
  1613. .agp_type_to_mask_type = agp_generic_type_to_mask_type,
  1614. };
  1615. static const struct agp_bridge_driver intel_915_driver = {
  1616. .owner = THIS_MODULE,
  1617. .aperture_sizes = intel_i830_sizes,
  1618. .size_type = FIXED_APER_SIZE,
  1619. .num_aperture_sizes = 4,
  1620. .needs_scratch_page = true,
  1621. .configure = intel_i915_configure,
  1622. .fetch_size = intel_i9xx_fetch_size,
  1623. .cleanup = intel_i915_cleanup,
  1624. .tlb_flush = intel_i810_tlbflush,
  1625. .mask_memory = intel_i810_mask_memory,
  1626. .masks = intel_i810_masks,
  1627. .agp_enable = intel_i810_agp_enable,
  1628. .cache_flush = global_cache_flush,
  1629. .create_gatt_table = intel_i915_create_gatt_table,
  1630. .free_gatt_table = intel_i830_free_gatt_table,
  1631. .insert_memory = intel_i915_insert_entries,
  1632. .remove_memory = intel_i915_remove_entries,
  1633. .alloc_by_type = intel_i830_alloc_by_type,
  1634. .free_by_type = intel_i810_free_by_type,
  1635. .agp_alloc_page = agp_generic_alloc_page,
  1636. .agp_destroy_page = agp_generic_destroy_page,
  1637. .agp_type_to_mask_type = intel_i830_type_to_mask_type,
  1638. .chipset_flush = intel_i915_chipset_flush,
  1639. };
  1640. static const struct agp_bridge_driver intel_i965_driver = {
  1641. .owner = THIS_MODULE,
  1642. .aperture_sizes = intel_i830_sizes,
  1643. .size_type = FIXED_APER_SIZE,
  1644. .num_aperture_sizes = 4,
  1645. .needs_scratch_page = true,
  1646. .configure = intel_i915_configure,
  1647. .fetch_size = intel_i9xx_fetch_size,
  1648. .cleanup = intel_i915_cleanup,
  1649. .tlb_flush = intel_i810_tlbflush,
  1650. .mask_memory = intel_i965_mask_memory,
  1651. .masks = intel_i810_masks,
  1652. .agp_enable = intel_i810_agp_enable,
  1653. .cache_flush = global_cache_flush,
  1654. .create_gatt_table = intel_i965_create_gatt_table,
  1655. .free_gatt_table = intel_i830_free_gatt_table,
  1656. .insert_memory = intel_i915_insert_entries,
  1657. .remove_memory = intel_i915_remove_entries,
  1658. .alloc_by_type = intel_i830_alloc_by_type,
  1659. .free_by_type = intel_i810_free_by_type,
  1660. .agp_alloc_page = agp_generic_alloc_page,
  1661. .agp_destroy_page = agp_generic_destroy_page,
  1662. .agp_type_to_mask_type = intel_i830_type_to_mask_type,
  1663. .chipset_flush = intel_i915_chipset_flush,
  1664. };
  1665. static const struct agp_bridge_driver intel_7505_driver = {
  1666. .owner = THIS_MODULE,
  1667. .aperture_sizes = intel_8xx_sizes,
  1668. .size_type = U8_APER_SIZE,
  1669. .num_aperture_sizes = 7,
  1670. .configure = intel_7505_configure,
  1671. .fetch_size = intel_8xx_fetch_size,
  1672. .cleanup = intel_8xx_cleanup,
  1673. .tlb_flush = intel_8xx_tlbflush,
  1674. .mask_memory = agp_generic_mask_memory,
  1675. .masks = intel_generic_masks,
  1676. .agp_enable = agp_generic_enable,
  1677. .cache_flush = global_cache_flush,
  1678. .create_gatt_table = agp_generic_create_gatt_table,
  1679. .free_gatt_table = agp_generic_free_gatt_table,
  1680. .insert_memory = agp_generic_insert_memory,
  1681. .remove_memory = agp_generic_remove_memory,
  1682. .alloc_by_type = agp_generic_alloc_by_type,
  1683. .free_by_type = agp_generic_free_by_type,
  1684. .agp_alloc_page = agp_generic_alloc_page,
  1685. .agp_destroy_page = agp_generic_destroy_page,
  1686. .agp_type_to_mask_type = agp_generic_type_to_mask_type,
  1687. };
  1688. static const struct agp_bridge_driver intel_g33_driver = {
  1689. .owner = THIS_MODULE,
  1690. .aperture_sizes = intel_i830_sizes,
  1691. .size_type = FIXED_APER_SIZE,
  1692. .num_aperture_sizes = 4,
  1693. .needs_scratch_page = true,
  1694. .configure = intel_i915_configure,
  1695. .fetch_size = intel_i9xx_fetch_size,
  1696. .cleanup = intel_i915_cleanup,
  1697. .tlb_flush = intel_i810_tlbflush,
  1698. .mask_memory = intel_i965_mask_memory,
  1699. .masks = intel_i810_masks,
  1700. .agp_enable = intel_i810_agp_enable,
  1701. .cache_flush = global_cache_flush,
  1702. .create_gatt_table = intel_i915_create_gatt_table,
  1703. .free_gatt_table = intel_i830_free_gatt_table,
  1704. .insert_memory = intel_i915_insert_entries,
  1705. .remove_memory = intel_i915_remove_entries,
  1706. .alloc_by_type = intel_i830_alloc_by_type,
  1707. .free_by_type = intel_i810_free_by_type,
  1708. .agp_alloc_page = agp_generic_alloc_page,
  1709. .agp_destroy_page = agp_generic_destroy_page,
  1710. .agp_type_to_mask_type = intel_i830_type_to_mask_type,
  1711. .chipset_flush = intel_i915_chipset_flush,
  1712. };
  1713. static int find_gmch(u16 device)
  1714. {
  1715. struct pci_dev *gmch_device;
  1716. gmch_device = pci_get_device(PCI_VENDOR_ID_INTEL, device, NULL);
  1717. if (gmch_device && PCI_FUNC(gmch_device->devfn) != 0) {
  1718. gmch_device = pci_get_device(PCI_VENDOR_ID_INTEL,
  1719. device, gmch_device);
  1720. }
  1721. if (!gmch_device)
  1722. return 0;
  1723. intel_private.pcidev = gmch_device;
  1724. return 1;
  1725. }
  1726. /* Table to describe Intel GMCH and AGP/PCIE GART drivers. At least one of
  1727. * driver and gmch_driver must be non-null, and find_gmch will determine
  1728. * which one should be used if a gmch_chip_id is present.
  1729. */
  1730. static const struct intel_driver_description {
  1731. unsigned int chip_id;
  1732. unsigned int gmch_chip_id;
  1733. unsigned int multi_gmch_chip; /* if we have more gfx chip type on this HB. */
  1734. char *name;
  1735. const struct agp_bridge_driver *driver;
  1736. const struct agp_bridge_driver *gmch_driver;
  1737. } intel_agp_chipsets[] = {
  1738. { PCI_DEVICE_ID_INTEL_82443LX_0, 0, 0, "440LX", &intel_generic_driver, NULL },
  1739. { PCI_DEVICE_ID_INTEL_82443BX_0, 0, 0, "440BX", &intel_generic_driver, NULL },
  1740. { PCI_DEVICE_ID_INTEL_82443GX_0, 0, 0, "440GX", &intel_generic_driver, NULL },
  1741. { PCI_DEVICE_ID_INTEL_82810_MC1, PCI_DEVICE_ID_INTEL_82810_IG1, 0, "i810",
  1742. NULL, &intel_810_driver },
  1743. { PCI_DEVICE_ID_INTEL_82810_MC3, PCI_DEVICE_ID_INTEL_82810_IG3, 0, "i810",
  1744. NULL, &intel_810_driver },
  1745. { PCI_DEVICE_ID_INTEL_82810E_MC, PCI_DEVICE_ID_INTEL_82810E_IG, 0, "i810",
  1746. NULL, &intel_810_driver },
  1747. { PCI_DEVICE_ID_INTEL_82815_MC, PCI_DEVICE_ID_INTEL_82815_CGC, 0, "i815",
  1748. &intel_815_driver, &intel_810_driver },
  1749. { PCI_DEVICE_ID_INTEL_82820_HB, 0, 0, "i820", &intel_820_driver, NULL },
  1750. { PCI_DEVICE_ID_INTEL_82820_UP_HB, 0, 0, "i820", &intel_820_driver, NULL },
  1751. { PCI_DEVICE_ID_INTEL_82830_HB, PCI_DEVICE_ID_INTEL_82830_CGC, 0, "830M",
  1752. &intel_830mp_driver, &intel_830_driver },
  1753. { PCI_DEVICE_ID_INTEL_82840_HB, 0, 0, "i840", &intel_840_driver, NULL },
  1754. { PCI_DEVICE_ID_INTEL_82845_HB, 0, 0, "845G", &intel_845_driver, NULL },
  1755. { PCI_DEVICE_ID_INTEL_82845G_HB, PCI_DEVICE_ID_INTEL_82845G_IG, 0, "830M",
  1756. &intel_845_driver, &intel_830_driver },
  1757. { PCI_DEVICE_ID_INTEL_82850_HB, 0, 0, "i850", &intel_850_driver, NULL },
  1758. { PCI_DEVICE_ID_INTEL_82855PM_HB, 0, 0, "855PM", &intel_845_driver, NULL },
  1759. { PCI_DEVICE_ID_INTEL_82855GM_HB, PCI_DEVICE_ID_INTEL_82855GM_IG, 0, "855GM",
  1760. &intel_845_driver, &intel_830_driver },
  1761. { PCI_DEVICE_ID_INTEL_82860_HB, 0, 0, "i860", &intel_860_driver, NULL },
  1762. { PCI_DEVICE_ID_INTEL_82865_HB, PCI_DEVICE_ID_INTEL_82865_IG, 0, "865",
  1763. &intel_845_driver, &intel_830_driver },
  1764. { PCI_DEVICE_ID_INTEL_82875_HB, 0, 0, "i875", &intel_845_driver, NULL },
  1765. { PCI_DEVICE_ID_INTEL_E7221_HB, PCI_DEVICE_ID_INTEL_E7221_IG, 0, "E7221 (i915)",
  1766. NULL, &intel_915_driver },
  1767. { PCI_DEVICE_ID_INTEL_82915G_HB, PCI_DEVICE_ID_INTEL_82915G_IG, 0, "915G",
  1768. NULL, &intel_915_driver },
  1769. { PCI_DEVICE_ID_INTEL_82915GM_HB, PCI_DEVICE_ID_INTEL_82915GM_IG, 0, "915GM",
  1770. NULL, &intel_915_driver },
  1771. { PCI_DEVICE_ID_INTEL_82945G_HB, PCI_DEVICE_ID_INTEL_82945G_IG, 0, "945G",
  1772. NULL, &intel_915_driver },
  1773. { PCI_DEVICE_ID_INTEL_82945GM_HB, PCI_DEVICE_ID_INTEL_82945GM_IG, 0, "945GM",
  1774. NULL, &intel_915_driver },
  1775. { PCI_DEVICE_ID_INTEL_82945GME_HB, PCI_DEVICE_ID_INTEL_82945GME_IG, 0, "945GME",
  1776. NULL, &intel_915_driver },
  1777. { PCI_DEVICE_ID_INTEL_82946GZ_HB, PCI_DEVICE_ID_INTEL_82946GZ_IG, 0, "946GZ",
  1778. NULL, &intel_i965_driver },
  1779. { PCI_DEVICE_ID_INTEL_82G35_HB, PCI_DEVICE_ID_INTEL_82G35_IG, 0, "G35",
  1780. NULL, &intel_i965_driver },
  1781. { PCI_DEVICE_ID_INTEL_82965Q_HB, PCI_DEVICE_ID_INTEL_82965Q_IG, 0, "965Q",
  1782. NULL, &intel_i965_driver },
  1783. { PCI_DEVICE_ID_INTEL_82965G_HB, PCI_DEVICE_ID_INTEL_82965G_IG, 0, "965G",
  1784. NULL, &intel_i965_driver },
  1785. { PCI_DEVICE_ID_INTEL_82965GM_HB, PCI_DEVICE_ID_INTEL_82965GM_IG, 0, "965GM",
  1786. NULL, &intel_i965_driver },
  1787. { PCI_DEVICE_ID_INTEL_82965GME_HB, PCI_DEVICE_ID_INTEL_82965GME_IG, 0, "965GME/GLE",
  1788. NULL, &intel_i965_driver },
  1789. { PCI_DEVICE_ID_INTEL_7505_0, 0, 0, "E7505", &intel_7505_driver, NULL },
  1790. { PCI_DEVICE_ID_INTEL_7205_0, 0, 0, "E7205", &intel_7505_driver, NULL },
  1791. { PCI_DEVICE_ID_INTEL_G33_HB, PCI_DEVICE_ID_INTEL_G33_IG, 0, "G33",
  1792. NULL, &intel_g33_driver },
  1793. { PCI_DEVICE_ID_INTEL_Q35_HB, PCI_DEVICE_ID_INTEL_Q35_IG, 0, "Q35",
  1794. NULL, &intel_g33_driver },
  1795. { PCI_DEVICE_ID_INTEL_Q33_HB, PCI_DEVICE_ID_INTEL_Q33_IG, 0, "Q33",
  1796. NULL, &intel_g33_driver },
  1797. { PCI_DEVICE_ID_INTEL_IGD_HB, PCI_DEVICE_ID_INTEL_IGD_IG, 0,
  1798. "Intel Integrated Graphics Device", NULL, &intel_i965_driver },
  1799. { PCI_DEVICE_ID_INTEL_IGD_E_HB, PCI_DEVICE_ID_INTEL_IGD_E_IG, 0,
  1800. "Intel Integrated Graphics Device", NULL, &intel_i965_driver },
  1801. { PCI_DEVICE_ID_INTEL_Q45_HB, PCI_DEVICE_ID_INTEL_Q45_IG, 0,
  1802. "Q45/Q43", NULL, &intel_i965_driver },
  1803. { PCI_DEVICE_ID_INTEL_G45_HB, PCI_DEVICE_ID_INTEL_G45_IG, 0,
  1804. "G45/G43", NULL, &intel_i965_driver },
  1805. { 0, 0, 0, NULL, NULL, NULL }
  1806. };
  1807. static int __devinit agp_intel_probe(struct pci_dev *pdev,
  1808. const struct pci_device_id *ent)
  1809. {
  1810. struct agp_bridge_data *bridge;
  1811. u8 cap_ptr = 0;
  1812. struct resource *r;
  1813. int i;
  1814. cap_ptr = pci_find_capability(pdev, PCI_CAP_ID_AGP);
  1815. bridge = agp_alloc_bridge();
  1816. if (!bridge)
  1817. return -ENOMEM;
  1818. for (i = 0; intel_agp_chipsets[i].name != NULL; i++) {
  1819. /* In case that multiple models of gfx chip may
  1820. stand on same host bridge type, this can be
  1821. sure we detect the right IGD. */
  1822. if (pdev->device == intel_agp_chipsets[i].chip_id) {
  1823. if ((intel_agp_chipsets[i].gmch_chip_id != 0) &&
  1824. find_gmch(intel_agp_chipsets[i].gmch_chip_id)) {
  1825. bridge->driver =
  1826. intel_agp_chipsets[i].gmch_driver;
  1827. break;
  1828. } else if (intel_agp_chipsets[i].multi_gmch_chip) {
  1829. continue;
  1830. } else {
  1831. bridge->driver = intel_agp_chipsets[i].driver;
  1832. break;
  1833. }
  1834. }
  1835. }
  1836. if (intel_agp_chipsets[i].name == NULL) {
  1837. if (cap_ptr)
  1838. printk(KERN_WARNING PFX "Unsupported Intel chipset"
  1839. "(device id: %04x)\n", pdev->device);
  1840. agp_put_bridge(bridge);
  1841. return -ENODEV;
  1842. }
  1843. if (bridge->driver == NULL) {
  1844. /* bridge has no AGP and no IGD detected */
  1845. if (cap_ptr)
  1846. printk(KERN_WARNING PFX "Failed to find bridge device "
  1847. "(chip_id: %04x)\n",
  1848. intel_agp_chipsets[i].gmch_chip_id);
  1849. agp_put_bridge(bridge);
  1850. return -ENODEV;
  1851. }
  1852. bridge->dev = pdev;
  1853. bridge->capndx = cap_ptr;
  1854. bridge->dev_private_data = &intel_private;
  1855. printk(KERN_INFO PFX "Detected an Intel %s Chipset.\n",
  1856. intel_agp_chipsets[i].name);
  1857. /*
  1858. * The following fixes the case where the BIOS has "forgotten" to
  1859. * provide an address range for the GART.
  1860. * 20030610 - hamish@zot.org
  1861. */
  1862. r = &pdev->resource[0];
  1863. if (!r->start && r->end) {
  1864. if (pci_assign_resource(pdev, 0)) {
  1865. printk(KERN_ERR PFX "could not assign resource 0\n");
  1866. agp_put_bridge(bridge);
  1867. return -ENODEV;
  1868. }
  1869. }
  1870. /*
  1871. * If the device has not been properly setup, the following will catch
  1872. * the problem and should stop the system from crashing.
  1873. * 20030610 - hamish@zot.org
  1874. */
  1875. if (pci_enable_device(pdev)) {
  1876. printk(KERN_ERR PFX "Unable to Enable PCI device\n");
  1877. agp_put_bridge(bridge);
  1878. return -ENODEV;
  1879. }
  1880. /* Fill in the mode register */
  1881. if (cap_ptr) {
  1882. pci_read_config_dword(pdev,
  1883. bridge->capndx+PCI_AGP_STATUS,
  1884. &bridge->mode);
  1885. }
  1886. pci_set_drvdata(pdev, bridge);
  1887. return agp_add_bridge(bridge);
  1888. }
  1889. static void __devexit agp_intel_remove(struct pci_dev *pdev)
  1890. {
  1891. struct agp_bridge_data *bridge = pci_get_drvdata(pdev);
  1892. agp_remove_bridge(bridge);
  1893. if (intel_private.pcidev)
  1894. pci_dev_put(intel_private.pcidev);
  1895. agp_put_bridge(bridge);
  1896. }
  1897. #ifdef CONFIG_PM
  1898. static int agp_intel_resume(struct pci_dev *pdev)
  1899. {
  1900. struct agp_bridge_data *bridge = pci_get_drvdata(pdev);
  1901. pci_restore_state(pdev);
  1902. /* We should restore our graphics device's config space,
  1903. * as host bridge (00:00) resumes before graphics device (02:00),
  1904. * then our access to its pci space can work right.
  1905. */
  1906. if (intel_private.pcidev)
  1907. pci_restore_state(intel_private.pcidev);
  1908. if (bridge->driver == &intel_generic_driver)
  1909. intel_configure();
  1910. else if (bridge->driver == &intel_850_driver)
  1911. intel_850_configure();
  1912. else if (bridge->driver == &intel_845_driver)
  1913. intel_845_configure();
  1914. else if (bridge->driver == &intel_830mp_driver)
  1915. intel_830mp_configure();
  1916. else if (bridge->driver == &intel_915_driver)
  1917. intel_i915_configure();
  1918. else if (bridge->driver == &intel_830_driver)
  1919. intel_i830_configure();
  1920. else if (bridge->driver == &intel_810_driver)
  1921. intel_i810_configure();
  1922. else if (bridge->driver == &intel_i965_driver)
  1923. intel_i915_configure();
  1924. return 0;
  1925. }
  1926. #endif
  1927. static struct pci_device_id agp_intel_pci_table[] = {
  1928. #define ID(x) \
  1929. { \
  1930. .class = (PCI_CLASS_BRIDGE_HOST << 8), \
  1931. .class_mask = ~0, \
  1932. .vendor = PCI_VENDOR_ID_INTEL, \
  1933. .device = x, \
  1934. .subvendor = PCI_ANY_ID, \
  1935. .subdevice = PCI_ANY_ID, \
  1936. }
  1937. ID(PCI_DEVICE_ID_INTEL_82443LX_0),
  1938. ID(PCI_DEVICE_ID_INTEL_82443BX_0),
  1939. ID(PCI_DEVICE_ID_INTEL_82443GX_0),
  1940. ID(PCI_DEVICE_ID_INTEL_82810_MC1),
  1941. ID(PCI_DEVICE_ID_INTEL_82810_MC3),
  1942. ID(PCI_DEVICE_ID_INTEL_82810E_MC),
  1943. ID(PCI_DEVICE_ID_INTEL_82815_MC),
  1944. ID(PCI_DEVICE_ID_INTEL_82820_HB),
  1945. ID(PCI_DEVICE_ID_INTEL_82820_UP_HB),
  1946. ID(PCI_DEVICE_ID_INTEL_82830_HB),
  1947. ID(PCI_DEVICE_ID_INTEL_82840_HB),
  1948. ID(PCI_DEVICE_ID_INTEL_82845_HB),
  1949. ID(PCI_DEVICE_ID_INTEL_82845G_HB),
  1950. ID(PCI_DEVICE_ID_INTEL_82850_HB),
  1951. ID(PCI_DEVICE_ID_INTEL_82855PM_HB),
  1952. ID(PCI_DEVICE_ID_INTEL_82855GM_HB),
  1953. ID(PCI_DEVICE_ID_INTEL_82860_HB),
  1954. ID(PCI_DEVICE_ID_INTEL_82865_HB),
  1955. ID(PCI_DEVICE_ID_INTEL_82875_HB),
  1956. ID(PCI_DEVICE_ID_INTEL_7505_0),
  1957. ID(PCI_DEVICE_ID_INTEL_7205_0),
  1958. ID(PCI_DEVICE_ID_INTEL_E7221_HB),
  1959. ID(PCI_DEVICE_ID_INTEL_82915G_HB),
  1960. ID(PCI_DEVICE_ID_INTEL_82915GM_HB),
  1961. ID(PCI_DEVICE_ID_INTEL_82945G_HB),
  1962. ID(PCI_DEVICE_ID_INTEL_82945GM_HB),
  1963. ID(PCI_DEVICE_ID_INTEL_82945GME_HB),
  1964. ID(PCI_DEVICE_ID_INTEL_82946GZ_HB),
  1965. ID(PCI_DEVICE_ID_INTEL_82G35_HB),
  1966. ID(PCI_DEVICE_ID_INTEL_82965Q_HB),
  1967. ID(PCI_DEVICE_ID_INTEL_82965G_HB),
  1968. ID(PCI_DEVICE_ID_INTEL_82965GM_HB),
  1969. ID(PCI_DEVICE_ID_INTEL_82965GME_HB),
  1970. ID(PCI_DEVICE_ID_INTEL_G33_HB),
  1971. ID(PCI_DEVICE_ID_INTEL_Q35_HB),
  1972. ID(PCI_DEVICE_ID_INTEL_Q33_HB),
  1973. ID(PCI_DEVICE_ID_INTEL_IGD_HB),
  1974. ID(PCI_DEVICE_ID_INTEL_IGD_E_HB),
  1975. ID(PCI_DEVICE_ID_INTEL_Q45_HB),
  1976. ID(PCI_DEVICE_ID_INTEL_G45_HB),
  1977. { }
  1978. };
  1979. MODULE_DEVICE_TABLE(pci, agp_intel_pci_table);
  1980. static struct pci_driver agp_intel_pci_driver = {
  1981. .name = "agpgart-intel",
  1982. .id_table = agp_intel_pci_table,
  1983. .probe = agp_intel_probe,
  1984. .remove = __devexit_p(agp_intel_remove),
  1985. #ifdef CONFIG_PM
  1986. .resume = agp_intel_resume,
  1987. #endif
  1988. };
  1989. static int __init agp_intel_init(void)
  1990. {
  1991. if (agp_off)
  1992. return -EINVAL;
  1993. return pci_register_driver(&agp_intel_pci_driver);
  1994. }
  1995. static void __exit agp_intel_cleanup(void)
  1996. {
  1997. pci_unregister_driver(&agp_intel_pci_driver);
  1998. }
  1999. module_init(agp_intel_init);
  2000. module_exit(agp_intel_cleanup);
  2001. MODULE_AUTHOR("Dave Jones <davej@codemonkey.org.uk>");
  2002. MODULE_LICENSE("GPL and additional rights");