intelfbdrv.c 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592
  1. /*
  2. * intelfb
  3. *
  4. * Linux framebuffer driver for Intel(R) 830M/845G/852GM/855GM/865G/915G/915GM
  5. * integrated graphics chips.
  6. *
  7. * Copyright © 2002, 2003 David Dawes <dawes@xfree86.org>
  8. * 2004 Sylvain Meyer
  9. *
  10. * This driver consists of two parts. The first part (intelfbdrv.c) provides
  11. * the basic fbdev interfaces, is derived in part from the radeonfb and
  12. * vesafb drivers, and is covered by the GPL. The second part (intelfbhw.c)
  13. * provides the code to program the hardware. Most of it is derived from
  14. * the i810/i830 XFree86 driver. The HW-specific code is covered here
  15. * under a dual license (GPL and MIT/XFree86 license).
  16. *
  17. * Author: David Dawes
  18. *
  19. */
  20. /* $DHD: intelfb/intelfbdrv.c,v 1.20 2003/06/27 15:17:40 dawes Exp $ */
  21. /*
  22. * Changes:
  23. * 01/2003 - Initial driver (0.1.0), no mode switching, no acceleration.
  24. * This initial version is a basic core that works a lot like
  25. * the vesafb driver. It must be built-in to the kernel,
  26. * and the initial video mode must be set with vga=XXX at
  27. * boot time. (David Dawes)
  28. *
  29. * 01/2003 - Version 0.2.0: Mode switching added, colormap support
  30. * implemented, Y panning, and soft screen blanking implemented.
  31. * No acceleration yet. (David Dawes)
  32. *
  33. * 01/2003 - Version 0.3.0: fbcon acceleration support added. Module
  34. * option handling added. (David Dawes)
  35. *
  36. * 01/2003 - Version 0.4.0: fbcon HW cursor support added. (David Dawes)
  37. *
  38. * 01/2003 - Version 0.4.1: Add auto-generation of built-in modes.
  39. * (David Dawes)
  40. *
  41. * 02/2003 - Version 0.4.2: Add check for active non-CRT devices, and
  42. * mode validation checks. (David Dawes)
  43. *
  44. * 02/2003 - Version 0.4.3: Check when the VC is in graphics mode so that
  45. * acceleration is disabled while an XFree86 server is running.
  46. * (David Dawes)
  47. *
  48. * 02/2003 - Version 0.4.4: Monitor DPMS support. (David Dawes)
  49. *
  50. * 02/2003 - Version 0.4.5: Basic XFree86 + fbdev working. (David Dawes)
  51. *
  52. * 02/2003 - Version 0.5.0: Modify to work with the 2.5.32 kernel as well
  53. * as 2.4.x kernels. (David Dawes)
  54. *
  55. * 02/2003 - Version 0.6.0: Split out HW-specifics into a separate file.
  56. * (David Dawes)
  57. *
  58. * 02/2003 - Version 0.7.0: Test on 852GM/855GM. Acceleration and HW
  59. * cursor are disabled on this platform. (David Dawes)
  60. *
  61. * 02/2003 - Version 0.7.1: Test on 845G. Acceleration is disabled
  62. * on this platform. (David Dawes)
  63. *
  64. * 02/2003 - Version 0.7.2: Test on 830M. Acceleration and HW
  65. * cursor are disabled on this platform. (David Dawes)
  66. *
  67. * 02/2003 - Version 0.7.3: Fix 8-bit modes for mobile platforms
  68. * (David Dawes)
  69. *
  70. * 02/2003 - Version 0.7.4: Add checks for FB and FBCON_HAS_CFB* configured
  71. * in the kernel, and add mode bpp verification and default
  72. * bpp selection based on which FBCON_HAS_CFB* are configured.
  73. * (David Dawes)
  74. *
  75. * 02/2003 - Version 0.7.5: Add basic package/install scripts based on the
  76. * DRI packaging scripts. (David Dawes)
  77. *
  78. * 04/2003 - Version 0.7.6: Fix typo that affects builds with SMP-enabled
  79. * kernels. (David Dawes, reported by Anupam).
  80. *
  81. * 06/2003 - Version 0.7.7:
  82. * Fix Makefile.kernel build problem (Tsutomu Yasuda).
  83. * Fix mis-placed #endif (2.4.21 kernel).
  84. *
  85. * 09/2004 - Version 0.9.0 - by Sylvain Meyer
  86. * Port to linux 2.6 kernel fbdev
  87. * Fix HW accel and HW cursor on i845G
  88. * Use of agpgart for fb memory reservation
  89. * Add mtrr support
  90. *
  91. * 10/2004 - Version 0.9.1
  92. * Use module_param instead of old MODULE_PARM
  93. * Some cleanup
  94. *
  95. * 11/2004 - Version 0.9.2
  96. * Add vram option to reserve more memory than stolen by BIOS
  97. * Fix intelfbhw_pan_display typo
  98. * Add __initdata annotations
  99. *
  100. * TODO:
  101. *
  102. *
  103. * Wish List:
  104. *
  105. *
  106. */
  107. #include <linux/config.h>
  108. #include <linux/module.h>
  109. #include <linux/kernel.h>
  110. #include <linux/errno.h>
  111. #include <linux/string.h>
  112. #include <linux/mm.h>
  113. #include <linux/tty.h>
  114. #include <linux/slab.h>
  115. #include <linux/delay.h>
  116. #include <linux/fb.h>
  117. #include <linux/ioport.h>
  118. #include <linux/init.h>
  119. #include <linux/pci.h>
  120. #include <linux/vmalloc.h>
  121. #include <linux/pagemap.h>
  122. #include <asm/io.h>
  123. #ifdef CONFIG_MTRR
  124. #include <asm/mtrr.h>
  125. #endif
  126. #include "intelfb.h"
  127. #include "intelfbhw.h"
  128. static void __devinit get_initial_mode(struct intelfb_info *dinfo);
  129. static void update_dinfo(struct intelfb_info *dinfo,
  130. struct fb_var_screeninfo *var);
  131. static int intelfb_check_var(struct fb_var_screeninfo *var,
  132. struct fb_info *info);
  133. static int intelfb_set_par(struct fb_info *info);
  134. static int intelfb_setcolreg(unsigned regno, unsigned red, unsigned green,
  135. unsigned blue, unsigned transp,
  136. struct fb_info *info);
  137. static int intelfb_blank(int blank, struct fb_info *info);
  138. static int intelfb_pan_display(struct fb_var_screeninfo *var,
  139. struct fb_info *info);
  140. static void intelfb_fillrect(struct fb_info *info,
  141. const struct fb_fillrect *rect);
  142. static void intelfb_copyarea(struct fb_info *info,
  143. const struct fb_copyarea *region);
  144. static void intelfb_imageblit(struct fb_info *info,
  145. const struct fb_image *image);
  146. static int intelfb_cursor(struct fb_info *info,
  147. struct fb_cursor *cursor);
  148. static int intelfb_sync(struct fb_info *info);
  149. static int intelfb_ioctl(struct fb_info *info,
  150. unsigned int cmd, unsigned long arg);
  151. static int __devinit intelfb_pci_register(struct pci_dev *pdev,
  152. const struct pci_device_id *ent);
  153. static void __devexit intelfb_pci_unregister(struct pci_dev *pdev);
  154. static int __devinit intelfb_set_fbinfo(struct intelfb_info *dinfo);
  155. /*
  156. * Limiting the class to PCI_CLASS_DISPLAY_VGA prevents function 1 of the
  157. * mobile chipsets from being registered.
  158. */
  159. #if DETECT_VGA_CLASS_ONLY
  160. #define INTELFB_CLASS_MASK ~0 << 8
  161. #else
  162. #define INTELFB_CLASS_MASK 0
  163. #endif
  164. static struct pci_device_id intelfb_pci_table[] __devinitdata = {
  165. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_830M, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_830M },
  166. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_845G, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_845G },
  167. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_85XGM, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_85XGM },
  168. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_865G, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_865G },
  169. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_915G, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_915G },
  170. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_915GM, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_915GM },
  171. { 0, }
  172. };
  173. /* Global data */
  174. static int num_registered = 0;
  175. /* fb ops */
  176. static struct fb_ops intel_fb_ops = {
  177. .owner = THIS_MODULE,
  178. .fb_check_var = intelfb_check_var,
  179. .fb_set_par = intelfb_set_par,
  180. .fb_setcolreg = intelfb_setcolreg,
  181. .fb_blank = intelfb_blank,
  182. .fb_pan_display = intelfb_pan_display,
  183. .fb_fillrect = intelfb_fillrect,
  184. .fb_copyarea = intelfb_copyarea,
  185. .fb_imageblit = intelfb_imageblit,
  186. .fb_cursor = intelfb_cursor,
  187. .fb_sync = intelfb_sync,
  188. .fb_ioctl = intelfb_ioctl
  189. };
  190. /* PCI driver module table */
  191. static struct pci_driver intelfb_driver = {
  192. .name = "intelfb",
  193. .id_table = intelfb_pci_table,
  194. .probe = intelfb_pci_register,
  195. .remove = __devexit_p(intelfb_pci_unregister)
  196. };
  197. /* Module description/parameters */
  198. MODULE_AUTHOR("David Dawes <dawes@tungstengraphics.com>, "
  199. "Sylvain Meyer <sylvain.meyer@worldonline.fr>");
  200. MODULE_DESCRIPTION(
  201. "Framebuffer driver for Intel(R) " SUPPORTED_CHIPSETS " chipsets");
  202. MODULE_LICENSE("Dual BSD/GPL");
  203. MODULE_DEVICE_TABLE(pci, intelfb_pci_table);
  204. static int accel = 1;
  205. static int vram = 4;
  206. static int hwcursor = 0;
  207. static int mtrr = 1;
  208. static int fixed = 0;
  209. static int noinit = 0;
  210. static int noregister = 0;
  211. static int probeonly = 0;
  212. static int idonly = 0;
  213. static int bailearly = 0;
  214. static int voffset = 48;
  215. static char *mode = NULL;
  216. module_param(accel, bool, S_IRUGO);
  217. MODULE_PARM_DESC(accel, "Enable hardware acceleration");
  218. module_param(vram, int, S_IRUGO);
  219. MODULE_PARM_DESC(vram, "System RAM to allocate to framebuffer in MiB");
  220. module_param(voffset, int, S_IRUGO);
  221. MODULE_PARM_DESC(voffset, "Offset of framebuffer in MiB");
  222. module_param(hwcursor, bool, S_IRUGO);
  223. MODULE_PARM_DESC(hwcursor, "Enable HW cursor");
  224. module_param(mtrr, bool, S_IRUGO);
  225. MODULE_PARM_DESC(mtrr, "Enable MTRR support");
  226. module_param(fixed, bool, S_IRUGO);
  227. MODULE_PARM_DESC(fixed, "Disable mode switching");
  228. module_param(noinit, bool, 0);
  229. MODULE_PARM_DESC(noinit, "Don't initialise graphics mode when loading");
  230. module_param(noregister, bool, 0);
  231. MODULE_PARM_DESC(noregister, "Don't register, just probe and exit (debug)");
  232. module_param(probeonly, bool, 0);
  233. MODULE_PARM_DESC(probeonly, "Do a minimal probe (debug)");
  234. module_param(idonly, bool, 0);
  235. MODULE_PARM_DESC(idonly, "Just identify without doing anything else (debug)");
  236. module_param(bailearly, bool, 0);
  237. MODULE_PARM_DESC(bailearly, "Bail out early, depending on value (debug)");
  238. module_param(mode, charp, S_IRUGO);
  239. MODULE_PARM_DESC(mode,
  240. "Initial video mode \"<xres>x<yres>[-<depth>][@<refresh>]\"");
  241. #ifndef MODULE
  242. #define OPT_EQUAL(opt, name) (!strncmp(opt, name, strlen(name)))
  243. #define OPT_INTVAL(opt, name) simple_strtoul(opt + strlen(name), NULL, 0)
  244. #define OPT_STRVAL(opt, name) (opt + strlen(name))
  245. static __inline__ char *
  246. get_opt_string(const char *this_opt, const char *name)
  247. {
  248. const char *p;
  249. int i;
  250. char *ret;
  251. p = OPT_STRVAL(this_opt, name);
  252. i = 0;
  253. while (p[i] && p[i] != ' ' && p[i] != ',')
  254. i++;
  255. ret = kmalloc(i + 1, GFP_KERNEL);
  256. if (ret) {
  257. strncpy(ret, p, i);
  258. ret[i] = '\0';
  259. }
  260. return ret;
  261. }
  262. static __inline__ int
  263. get_opt_int(const char *this_opt, const char *name, int *ret)
  264. {
  265. if (!ret)
  266. return 0;
  267. if (!OPT_EQUAL(this_opt, name))
  268. return 0;
  269. *ret = OPT_INTVAL(this_opt, name);
  270. return 1;
  271. }
  272. static __inline__ int
  273. get_opt_bool(const char *this_opt, const char *name, int *ret)
  274. {
  275. if (!ret)
  276. return 0;
  277. if (OPT_EQUAL(this_opt, name)) {
  278. if (this_opt[strlen(name)] == '=')
  279. *ret = simple_strtoul(this_opt + strlen(name) + 1,
  280. NULL, 0);
  281. else
  282. *ret = 1;
  283. } else {
  284. if (OPT_EQUAL(this_opt, "no") && OPT_EQUAL(this_opt + 2, name))
  285. *ret = 0;
  286. else
  287. return 0;
  288. }
  289. return 1;
  290. }
  291. static int __init
  292. intelfb_setup(char *options)
  293. {
  294. char *this_opt;
  295. DBG_MSG("intelfb_setup\n");
  296. if (!options || !*options) {
  297. DBG_MSG("no options\n");
  298. return 0;
  299. } else
  300. DBG_MSG("options: %s\n", options);
  301. /*
  302. * These are the built-in options analogous to the module parameters
  303. * defined above.
  304. *
  305. * The syntax is:
  306. *
  307. * video=intelfb:[mode][,<param>=<val>] ...
  308. *
  309. * e.g.,
  310. *
  311. * video=intelfb:1024x768-16@75,accel=0
  312. */
  313. while ((this_opt = strsep(&options, ","))) {
  314. if (!*this_opt)
  315. continue;
  316. if (get_opt_bool(this_opt, "accel", &accel))
  317. ;
  318. else if (get_opt_int(this_opt, "vram", &vram))
  319. ;
  320. else if (get_opt_bool(this_opt, "hwcursor", &hwcursor))
  321. ;
  322. else if (get_opt_bool(this_opt, "mtrr", &mtrr))
  323. ;
  324. else if (get_opt_bool(this_opt, "fixed", &fixed))
  325. ;
  326. else if (get_opt_bool(this_opt, "init", &noinit))
  327. noinit = !noinit;
  328. else if (OPT_EQUAL(this_opt, "mode="))
  329. mode = get_opt_string(this_opt, "mode=");
  330. else
  331. mode = this_opt;
  332. }
  333. return 0;
  334. }
  335. #endif
  336. static int __init
  337. intelfb_init(void)
  338. {
  339. #ifndef MODULE
  340. char *option = NULL;
  341. #endif
  342. DBG_MSG("intelfb_init\n");
  343. INF_MSG("Framebuffer driver for "
  344. "Intel(R) " SUPPORTED_CHIPSETS " chipsets\n");
  345. INF_MSG("Version " INTELFB_VERSION "\n");
  346. if (idonly)
  347. return -ENODEV;
  348. #ifndef MODULE
  349. if (fb_get_options("intelfb", &option))
  350. return -ENODEV;
  351. intelfb_setup(option);
  352. #endif
  353. return pci_register_driver(&intelfb_driver);
  354. }
  355. static void __exit
  356. intelfb_exit(void)
  357. {
  358. DBG_MSG("intelfb_exit\n");
  359. pci_unregister_driver(&intelfb_driver);
  360. }
  361. module_init(intelfb_init);
  362. module_exit(intelfb_exit);
  363. /***************************************************************
  364. * mtrr support functions *
  365. ***************************************************************/
  366. #ifdef CONFIG_MTRR
  367. static inline void __devinit set_mtrr(struct intelfb_info *dinfo)
  368. {
  369. dinfo->mtrr_reg = mtrr_add(dinfo->aperture.physical,
  370. dinfo->aperture.size, MTRR_TYPE_WRCOMB, 1);
  371. if (dinfo->mtrr_reg < 0) {
  372. ERR_MSG("unable to set MTRR\n");
  373. return;
  374. }
  375. dinfo->has_mtrr = 1;
  376. }
  377. static inline void unset_mtrr(struct intelfb_info *dinfo)
  378. {
  379. if (dinfo->has_mtrr)
  380. mtrr_del(dinfo->mtrr_reg, dinfo->aperture.physical,
  381. dinfo->aperture.size);
  382. }
  383. #else
  384. #define set_mtrr(x) WRN_MSG("MTRR is disabled in the kernel\n")
  385. #define unset_mtrr(x) do { } while (0)
  386. #endif /* CONFIG_MTRR */
  387. /***************************************************************
  388. * driver init / cleanup *
  389. ***************************************************************/
  390. static void
  391. cleanup(struct intelfb_info *dinfo)
  392. {
  393. DBG_MSG("cleanup\n");
  394. if (!dinfo)
  395. return;
  396. fb_dealloc_cmap(&dinfo->info->cmap);
  397. kfree(dinfo->info->pixmap.addr);
  398. if (dinfo->registered)
  399. unregister_framebuffer(dinfo->info);
  400. unset_mtrr(dinfo);
  401. if (dinfo->fbmem_gart && dinfo->gtt_fb_mem) {
  402. agp_unbind_memory(dinfo->gtt_fb_mem);
  403. agp_free_memory(dinfo->gtt_fb_mem);
  404. }
  405. if (dinfo->gtt_cursor_mem) {
  406. agp_unbind_memory(dinfo->gtt_cursor_mem);
  407. agp_free_memory(dinfo->gtt_cursor_mem);
  408. }
  409. if (dinfo->gtt_ring_mem) {
  410. agp_unbind_memory(dinfo->gtt_ring_mem);
  411. agp_free_memory(dinfo->gtt_ring_mem);
  412. }
  413. if (dinfo->mmio_base)
  414. iounmap((void __iomem *)dinfo->mmio_base);
  415. if (dinfo->aperture.virtual)
  416. iounmap((void __iomem *)dinfo->aperture.virtual);
  417. if (dinfo->flag & INTELFB_MMIO_ACQUIRED)
  418. release_mem_region(dinfo->mmio_base_phys, INTEL_REG_SIZE);
  419. if (dinfo->flag & INTELFB_FB_ACQUIRED)
  420. release_mem_region(dinfo->aperture.physical,
  421. dinfo->aperture.size);
  422. framebuffer_release(dinfo->info);
  423. }
  424. #define bailout(dinfo) do { \
  425. DBG_MSG("bailout\n"); \
  426. cleanup(dinfo); \
  427. INF_MSG("Not going to register framebuffer, exiting...\n"); \
  428. return -ENODEV; \
  429. } while (0)
  430. static int __devinit
  431. intelfb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent)
  432. {
  433. struct fb_info *info;
  434. struct intelfb_info *dinfo;
  435. int i, err, dvo;
  436. int aperture_size, stolen_size;
  437. struct agp_kern_info gtt_info;
  438. int agp_memtype;
  439. const char *s;
  440. struct agp_bridge_data *bridge;
  441. int aperture_bar = 0;
  442. int mmio_bar = 1;
  443. int offset;
  444. DBG_MSG("intelfb_pci_register\n");
  445. num_registered++;
  446. if (num_registered != 1) {
  447. ERR_MSG("Attempted to register %d devices "
  448. "(should be only 1).\n", num_registered);
  449. return -ENODEV;
  450. }
  451. info = framebuffer_alloc(sizeof(struct intelfb_info), &pdev->dev);
  452. if (!info) {
  453. ERR_MSG("Could not allocate memory for intelfb_info.\n");
  454. return -ENODEV;
  455. }
  456. if (fb_alloc_cmap(&info->cmap, 256, 1) < 0) {
  457. ERR_MSG("Could not allocate cmap for intelfb_info.\n");
  458. goto err_out_cmap;
  459. return -ENODEV;
  460. }
  461. dinfo = info->par;
  462. dinfo->info = info;
  463. dinfo->fbops = &intel_fb_ops;
  464. dinfo->pdev = pdev;
  465. /* Reserve pixmap space. */
  466. info->pixmap.addr = kmalloc(64 * 1024, GFP_KERNEL);
  467. if (info->pixmap.addr == NULL) {
  468. ERR_MSG("Cannot reserve pixmap memory.\n");
  469. goto err_out_pixmap;
  470. }
  471. memset(info->pixmap.addr, 0, 64 * 1024);
  472. /* set early this option because it could be changed by tv encoder
  473. driver */
  474. dinfo->fixed_mode = fixed;
  475. /* Enable device. */
  476. if ((err = pci_enable_device(pdev))) {
  477. ERR_MSG("Cannot enable device.\n");
  478. cleanup(dinfo);
  479. return -ENODEV;
  480. }
  481. /* Set base addresses. */
  482. if ((ent->device == PCI_DEVICE_ID_INTEL_915G) ||
  483. (ent->device == PCI_DEVICE_ID_INTEL_915GM)) {
  484. aperture_bar = 2;
  485. mmio_bar = 0;
  486. /* Disable HW cursor on 915G/M (not implemented yet) */
  487. hwcursor = 0;
  488. }
  489. dinfo->aperture.physical = pci_resource_start(pdev, aperture_bar);
  490. dinfo->aperture.size = pci_resource_len(pdev, aperture_bar);
  491. dinfo->mmio_base_phys = pci_resource_start(pdev, mmio_bar);
  492. DBG_MSG("fb aperture: 0x%llx/0x%llx, MMIO region: 0x%llx/0x%llx\n",
  493. (unsigned long long)pci_resource_start(pdev, aperture_bar),
  494. (unsigned long long)pci_resource_len(pdev, aperture_bar),
  495. (unsigned long long)pci_resource_start(pdev, mmio_bar),
  496. (unsigned long long)pci_resource_len(pdev, mmio_bar));
  497. /* Reserve the fb and MMIO regions */
  498. if (!request_mem_region(dinfo->aperture.physical, dinfo->aperture.size,
  499. INTELFB_MODULE_NAME)) {
  500. ERR_MSG("Cannot reserve FB region.\n");
  501. cleanup(dinfo);
  502. return -ENODEV;
  503. }
  504. dinfo->flag |= INTELFB_FB_ACQUIRED;
  505. if (!request_mem_region(dinfo->mmio_base_phys,
  506. INTEL_REG_SIZE,
  507. INTELFB_MODULE_NAME)) {
  508. ERR_MSG("Cannot reserve MMIO region.\n");
  509. cleanup(dinfo);
  510. return -ENODEV;
  511. }
  512. dinfo->flag |= INTELFB_MMIO_ACQUIRED;
  513. /* Get the chipset info. */
  514. dinfo->pci_chipset = pdev->device;
  515. if (intelfbhw_get_chipset(pdev, dinfo)) {
  516. cleanup(dinfo);
  517. return -ENODEV;
  518. }
  519. if (intelfbhw_get_memory(pdev, &aperture_size,&stolen_size)) {
  520. cleanup(dinfo);
  521. return -ENODEV;
  522. }
  523. INF_MSG("%02x:%02x.%d: %s, aperture size %dMB, "
  524. "stolen memory %dkB\n",
  525. pdev->bus->number, PCI_SLOT(pdev->devfn),
  526. PCI_FUNC(pdev->devfn), dinfo->name,
  527. BtoMB(aperture_size), BtoKB(stolen_size));
  528. /* Set these from the options. */
  529. dinfo->accel = accel;
  530. dinfo->hwcursor = hwcursor;
  531. if (NOACCEL_CHIPSET(dinfo) && dinfo->accel == 1) {
  532. INF_MSG("Acceleration is not supported for the %s chipset.\n",
  533. dinfo->name);
  534. dinfo->accel = 0;
  535. }
  536. /* Framebuffer parameters - Use all the stolen memory if >= vram */
  537. if (ROUND_UP_TO_PAGE(stolen_size) >= MB(vram)) {
  538. dinfo->fb.size = ROUND_UP_TO_PAGE(stolen_size);
  539. dinfo->fbmem_gart = 0;
  540. } else {
  541. dinfo->fb.size = MB(vram);
  542. dinfo->fbmem_gart = 1;
  543. }
  544. /* Allocate space for the ring buffer and HW cursor if enabled. */
  545. if (dinfo->accel) {
  546. dinfo->ring.size = RINGBUFFER_SIZE;
  547. dinfo->ring_tail_mask = dinfo->ring.size - 1;
  548. }
  549. if (dinfo->hwcursor) {
  550. dinfo->cursor.size = HW_CURSOR_SIZE;
  551. }
  552. /* Use agpgart to manage the GATT */
  553. if (!(bridge = agp_backend_acquire(pdev))) {
  554. ERR_MSG("cannot acquire agp\n");
  555. cleanup(dinfo);
  556. return -ENODEV;
  557. }
  558. /* get the current gatt info */
  559. if (agp_copy_info(bridge, &gtt_info)) {
  560. ERR_MSG("cannot get agp info\n");
  561. agp_backend_release(bridge);
  562. cleanup(dinfo);
  563. return -ENODEV;
  564. }
  565. if (MB(voffset) < stolen_size)
  566. offset = (stolen_size >> 12);
  567. else
  568. offset = ROUND_UP_TO_PAGE(MB(voffset))/GTT_PAGE_SIZE;
  569. /* set the mem offsets - set them after the already used pages */
  570. if (dinfo->accel) {
  571. dinfo->ring.offset = offset + gtt_info.current_memory;
  572. }
  573. if (dinfo->hwcursor) {
  574. dinfo->cursor.offset = offset +
  575. + gtt_info.current_memory + (dinfo->ring.size >> 12);
  576. }
  577. if (dinfo->fbmem_gart) {
  578. dinfo->fb.offset = offset +
  579. + gtt_info.current_memory + (dinfo->ring.size >> 12)
  580. + (dinfo->cursor.size >> 12);
  581. }
  582. /* Allocate memories (which aren't stolen) */
  583. /* Map the fb and MMIO regions */
  584. /* ioremap only up to the end of used aperture */
  585. dinfo->aperture.virtual = (u8 __iomem *)ioremap_nocache
  586. (dinfo->aperture.physical, ((offset + dinfo->fb.offset) << 12)
  587. + dinfo->fb.size);
  588. if (!dinfo->aperture.virtual) {
  589. ERR_MSG("Cannot remap FB region.\n");
  590. cleanup(dinfo);
  591. return -ENODEV;
  592. }
  593. dinfo->mmio_base =
  594. (u8 __iomem *)ioremap_nocache(dinfo->mmio_base_phys,
  595. INTEL_REG_SIZE);
  596. if (!dinfo->mmio_base) {
  597. ERR_MSG("Cannot remap MMIO region.\n");
  598. cleanup(dinfo);
  599. return -ENODEV;
  600. }
  601. if (dinfo->accel) {
  602. if (!(dinfo->gtt_ring_mem =
  603. agp_allocate_memory(bridge, dinfo->ring.size >> 12,
  604. AGP_NORMAL_MEMORY))) {
  605. ERR_MSG("cannot allocate ring buffer memory\n");
  606. agp_backend_release(bridge);
  607. cleanup(dinfo);
  608. return -ENOMEM;
  609. }
  610. if (agp_bind_memory(dinfo->gtt_ring_mem,
  611. dinfo->ring.offset)) {
  612. ERR_MSG("cannot bind ring buffer memory\n");
  613. agp_backend_release(bridge);
  614. cleanup(dinfo);
  615. return -EBUSY;
  616. }
  617. dinfo->ring.physical = dinfo->aperture.physical
  618. + (dinfo->ring.offset << 12);
  619. dinfo->ring.virtual = dinfo->aperture.virtual
  620. + (dinfo->ring.offset << 12);
  621. dinfo->ring_head = dinfo->ring.virtual;
  622. }
  623. if (dinfo->hwcursor) {
  624. agp_memtype = dinfo->mobile ? AGP_PHYSICAL_MEMORY
  625. : AGP_NORMAL_MEMORY;
  626. if (!(dinfo->gtt_cursor_mem =
  627. agp_allocate_memory(bridge, dinfo->cursor.size >> 12,
  628. agp_memtype))) {
  629. ERR_MSG("cannot allocate cursor memory\n");
  630. agp_backend_release(bridge);
  631. cleanup(dinfo);
  632. return -ENOMEM;
  633. }
  634. if (agp_bind_memory(dinfo->gtt_cursor_mem,
  635. dinfo->cursor.offset)) {
  636. ERR_MSG("cannot bind cursor memory\n");
  637. agp_backend_release(bridge);
  638. cleanup(dinfo);
  639. return -EBUSY;
  640. }
  641. if (dinfo->mobile)
  642. dinfo->cursor.physical
  643. = dinfo->gtt_cursor_mem->physical;
  644. else
  645. dinfo->cursor.physical = dinfo->aperture.physical
  646. + (dinfo->cursor.offset << 12);
  647. dinfo->cursor.virtual = dinfo->aperture.virtual
  648. + (dinfo->cursor.offset << 12);
  649. }
  650. if (dinfo->fbmem_gart) {
  651. if (!(dinfo->gtt_fb_mem =
  652. agp_allocate_memory(bridge, dinfo->fb.size >> 12,
  653. AGP_NORMAL_MEMORY))) {
  654. WRN_MSG("cannot allocate framebuffer memory - use "
  655. "the stolen one\n");
  656. dinfo->fbmem_gart = 0;
  657. }
  658. if (agp_bind_memory(dinfo->gtt_fb_mem,
  659. dinfo->fb.offset)) {
  660. WRN_MSG("cannot bind framebuffer memory - use "
  661. "the stolen one\n");
  662. dinfo->fbmem_gart = 0;
  663. }
  664. }
  665. /* update framebuffer memory parameters */
  666. if (!dinfo->fbmem_gart)
  667. dinfo->fb.offset = 0; /* starts at offset 0 */
  668. dinfo->fb.physical = dinfo->aperture.physical
  669. + (dinfo->fb.offset << 12);
  670. dinfo->fb.virtual = dinfo->aperture.virtual + (dinfo->fb.offset << 12);
  671. dinfo->fb_start = dinfo->fb.offset << 12;
  672. /* release agpgart */
  673. agp_backend_release(bridge);
  674. if (mtrr)
  675. set_mtrr(dinfo);
  676. DBG_MSG("fb: 0x%x(+ 0x%x)/0x%x (0x%x)\n",
  677. dinfo->fb.physical, dinfo->fb.offset, dinfo->fb.size,
  678. (u32 __iomem ) dinfo->fb.virtual);
  679. DBG_MSG("MMIO: 0x%x/0x%x (0x%x)\n",
  680. dinfo->mmio_base_phys, INTEL_REG_SIZE,
  681. (u32 __iomem) dinfo->mmio_base);
  682. DBG_MSG("ring buffer: 0x%x/0x%x (0x%x)\n",
  683. dinfo->ring.physical, dinfo->ring.size,
  684. (u32 __iomem ) dinfo->ring.virtual);
  685. DBG_MSG("HW cursor: 0x%x/0x%x (0x%x) (offset 0x%x) (phys 0x%x)\n",
  686. dinfo->cursor.physical, dinfo->cursor.size,
  687. (u32 __iomem ) dinfo->cursor.virtual, dinfo->cursor.offset,
  688. dinfo->cursor.physical);
  689. DBG_MSG("options: vram = %d, accel = %d, hwcursor = %d, fixed = %d, "
  690. "noinit = %d\n", vram, accel, hwcursor, fixed, noinit);
  691. DBG_MSG("options: mode = \"%s\"\n", mode ? mode : "");
  692. if (probeonly)
  693. bailout(dinfo);
  694. /*
  695. * Check if the LVDS port or any DVO ports are enabled. If so,
  696. * don't allow mode switching
  697. */
  698. dvo = intelfbhw_check_non_crt(dinfo);
  699. if (dvo) {
  700. dinfo->fixed_mode = 1;
  701. WRN_MSG("Non-CRT device is enabled ( ");
  702. i = 0;
  703. while (dvo) {
  704. if (dvo & 1) {
  705. s = intelfbhw_dvo_to_string(1 << i);
  706. if (s)
  707. printk("%s ", s);
  708. }
  709. dvo >>= 1;
  710. ++i;
  711. }
  712. printk("). Disabling mode switching.\n");
  713. }
  714. if (bailearly == 1)
  715. bailout(dinfo);
  716. if (FIXED_MODE(dinfo) && ORIG_VIDEO_ISVGA != VIDEO_TYPE_VLFB) {
  717. ERR_MSG("Video mode must be programmed at boot time.\n");
  718. cleanup(dinfo);
  719. return -ENODEV;
  720. }
  721. if (bailearly == 2)
  722. bailout(dinfo);
  723. /* Initialise dinfo and related data. */
  724. /* If an initial mode was programmed at boot time, get its details. */
  725. if (ORIG_VIDEO_ISVGA == VIDEO_TYPE_VLFB)
  726. get_initial_mode(dinfo);
  727. if (bailearly == 3)
  728. bailout(dinfo);
  729. if (FIXED_MODE(dinfo)) {
  730. /* remap fb address */
  731. update_dinfo(dinfo, &dinfo->initial_var);
  732. }
  733. if (bailearly == 4)
  734. bailout(dinfo);
  735. if (intelfb_set_fbinfo(dinfo)) {
  736. cleanup(dinfo);
  737. return -ENODEV;
  738. }
  739. if (bailearly == 5)
  740. bailout(dinfo);
  741. if (bailearly == 6)
  742. bailout(dinfo);
  743. pci_set_drvdata(pdev, dinfo);
  744. /* Save the initial register state. */
  745. i = intelfbhw_read_hw_state(dinfo, &dinfo->save_state,
  746. bailearly > 6 ? bailearly - 6 : 0);
  747. if (i != 0) {
  748. DBG_MSG("intelfbhw_read_hw_state returned %d\n", i);
  749. bailout(dinfo);
  750. }
  751. intelfbhw_print_hw_state(dinfo, &dinfo->save_state);
  752. if (bailearly == 18)
  753. bailout(dinfo);
  754. /* Cursor initialisation */
  755. if (dinfo->hwcursor) {
  756. intelfbhw_cursor_init(dinfo);
  757. intelfbhw_cursor_reset(dinfo);
  758. }
  759. if (bailearly == 19)
  760. bailout(dinfo);
  761. /* 2d acceleration init */
  762. if (dinfo->accel)
  763. intelfbhw_2d_start(dinfo);
  764. if (bailearly == 20)
  765. bailout(dinfo);
  766. if (noregister)
  767. bailout(dinfo);
  768. if (register_framebuffer(dinfo->info) < 0) {
  769. ERR_MSG("Cannot register framebuffer.\n");
  770. cleanup(dinfo);
  771. return -ENODEV;
  772. }
  773. dinfo->registered = 1;
  774. return 0;
  775. err_out_pixmap:
  776. fb_dealloc_cmap(&info->cmap);
  777. err_out_cmap:
  778. framebuffer_release(info);
  779. return -ENODEV;
  780. }
  781. static void __devexit
  782. intelfb_pci_unregister(struct pci_dev *pdev)
  783. {
  784. struct intelfb_info *dinfo = pci_get_drvdata(pdev);
  785. DBG_MSG("intelfb_pci_unregister\n");
  786. if (!dinfo)
  787. return;
  788. cleanup(dinfo);
  789. pci_set_drvdata(pdev, NULL);
  790. }
  791. /***************************************************************
  792. * helper functions *
  793. ***************************************************************/
  794. int __inline__
  795. intelfb_var_to_depth(const struct fb_var_screeninfo *var)
  796. {
  797. DBG_MSG("intelfb_var_to_depth: bpp: %d, green.length is %d\n",
  798. var->bits_per_pixel, var->green.length);
  799. switch (var->bits_per_pixel) {
  800. case 16:
  801. return (var->green.length == 6) ? 16 : 15;
  802. case 32:
  803. return 24;
  804. default:
  805. return var->bits_per_pixel;
  806. }
  807. }
  808. static __inline__ int
  809. var_to_refresh(const struct fb_var_screeninfo *var)
  810. {
  811. int xtot = var->xres + var->left_margin + var->right_margin +
  812. var->hsync_len;
  813. int ytot = var->yres + var->upper_margin + var->lower_margin +
  814. var->vsync_len;
  815. return (1000000000 / var->pixclock * 1000 + 500) / xtot / ytot;
  816. }
  817. /***************************************************************
  818. * Various intialisation functions *
  819. ***************************************************************/
  820. static void __devinit
  821. get_initial_mode(struct intelfb_info *dinfo)
  822. {
  823. struct fb_var_screeninfo *var;
  824. int xtot, ytot;
  825. DBG_MSG("get_initial_mode\n");
  826. dinfo->initial_vga = 1;
  827. dinfo->initial_fb_base = screen_info.lfb_base;
  828. dinfo->initial_video_ram = screen_info.lfb_size * KB(64);
  829. dinfo->initial_pitch = screen_info.lfb_linelength;
  830. var = &dinfo->initial_var;
  831. memset(var, 0, sizeof(*var));
  832. var->xres = screen_info.lfb_width;
  833. var->yres = screen_info.lfb_height;
  834. var->bits_per_pixel = screen_info.lfb_depth;
  835. switch (screen_info.lfb_depth) {
  836. case 15:
  837. var->bits_per_pixel = 16;
  838. break;
  839. case 24:
  840. var->bits_per_pixel = 32;
  841. break;
  842. }
  843. DBG_MSG("Initial info: FB is 0x%x/0x%x (%d kByte)\n",
  844. dinfo->initial_fb_base, dinfo->initial_video_ram,
  845. BtoKB(dinfo->initial_video_ram));
  846. DBG_MSG("Initial info: mode is %dx%d-%d (%d)\n",
  847. var->xres, var->yres, var->bits_per_pixel,
  848. dinfo->initial_pitch);
  849. /* Dummy timing values (assume 60Hz) */
  850. var->left_margin = (var->xres / 8) & 0xf8;
  851. var->right_margin = 32;
  852. var->upper_margin = 16;
  853. var->lower_margin = 4;
  854. var->hsync_len = (var->xres / 8) & 0xf8;
  855. var->vsync_len = 4;
  856. xtot = var->xres + var->left_margin +
  857. var->right_margin + var->hsync_len;
  858. ytot = var->yres + var->upper_margin +
  859. var->lower_margin + var->vsync_len;
  860. var->pixclock = 10000000 / xtot * 1000 / ytot * 100 / 60;
  861. var->height = -1;
  862. var->width = -1;
  863. if (var->bits_per_pixel > 8) {
  864. var->red.offset = screen_info.red_pos;
  865. var->red.length = screen_info.red_size;
  866. var->green.offset = screen_info.green_pos;
  867. var->green.length = screen_info.green_size;
  868. var->blue.offset = screen_info.blue_pos;
  869. var->blue.length = screen_info.blue_size;
  870. var->transp.offset = screen_info.rsvd_pos;
  871. var->transp.length = screen_info.rsvd_size;
  872. } else {
  873. var->red.length = 8;
  874. var->green.length = 8;
  875. var->blue.length = 8;
  876. }
  877. }
  878. static int __devinit
  879. intelfb_init_var(struct intelfb_info *dinfo)
  880. {
  881. struct fb_var_screeninfo *var;
  882. int msrc = 0;
  883. DBG_MSG("intelfb_init_var\n");
  884. var = &dinfo->info->var;
  885. if (FIXED_MODE(dinfo)) {
  886. memcpy(var, &dinfo->initial_var,
  887. sizeof(struct fb_var_screeninfo));
  888. msrc = 5;
  889. } else {
  890. if (mode) {
  891. msrc = fb_find_mode(var, dinfo->info, mode,
  892. vesa_modes, VESA_MODEDB_SIZE,
  893. NULL, 0);
  894. if (msrc)
  895. msrc |= 8;
  896. }
  897. if (!msrc) {
  898. msrc = fb_find_mode(var, dinfo->info, PREFERRED_MODE,
  899. vesa_modes, VESA_MODEDB_SIZE,
  900. NULL, 0);
  901. }
  902. }
  903. if (!msrc) {
  904. ERR_MSG("Cannot find a suitable video mode.\n");
  905. return 1;
  906. }
  907. INF_MSG("Initial video mode is %dx%d-%d@%d.\n", var->xres, var->yres,
  908. var->bits_per_pixel, var_to_refresh(var));
  909. DBG_MSG("Initial video mode is from %d.\n", msrc);
  910. #if ALLOCATE_FOR_PANNING
  911. /* Allow use of half of the video ram for panning */
  912. var->xres_virtual = var->xres;
  913. var->yres_virtual =
  914. dinfo->fb.size / 2 / (var->bits_per_pixel * var->xres);
  915. if (var->yres_virtual < var->yres)
  916. var->yres_virtual = var->yres;
  917. #else
  918. var->yres_virtual = var->yres;
  919. #endif
  920. if (dinfo->accel)
  921. var->accel_flags |= FB_ACCELF_TEXT;
  922. else
  923. var->accel_flags &= ~FB_ACCELF_TEXT;
  924. return 0;
  925. }
  926. static int __devinit
  927. intelfb_set_fbinfo(struct intelfb_info *dinfo)
  928. {
  929. struct fb_info *info = dinfo->info;
  930. DBG_MSG("intelfb_set_fbinfo\n");
  931. info->flags = FBINFO_FLAG_DEFAULT;
  932. info->fbops = &intel_fb_ops;
  933. info->pseudo_palette = dinfo->pseudo_palette;
  934. info->pixmap.size = 64*1024;
  935. info->pixmap.buf_align = 8;
  936. info->pixmap.access_align = 32;
  937. info->pixmap.flags = FB_PIXMAP_SYSTEM;
  938. if (intelfb_init_var(dinfo))
  939. return 1;
  940. info->pixmap.scan_align = 1;
  941. strcpy(info->fix.id, dinfo->name);
  942. info->fix.smem_start = dinfo->fb.physical;
  943. info->fix.smem_len = dinfo->fb.size;
  944. info->fix.type = FB_TYPE_PACKED_PIXELS;
  945. info->fix.type_aux = 0;
  946. info->fix.xpanstep = 8;
  947. info->fix.ypanstep = 1;
  948. info->fix.ywrapstep = 0;
  949. info->fix.mmio_start = dinfo->mmio_base_phys;
  950. info->fix.mmio_len = INTEL_REG_SIZE;
  951. info->fix.accel = FB_ACCEL_I830;
  952. update_dinfo(dinfo, &info->var);
  953. return 0;
  954. }
  955. /* Update dinfo to match the active video mode. */
  956. static void
  957. update_dinfo(struct intelfb_info *dinfo, struct fb_var_screeninfo *var)
  958. {
  959. DBG_MSG("update_dinfo\n");
  960. dinfo->bpp = var->bits_per_pixel;
  961. dinfo->depth = intelfb_var_to_depth(var);
  962. dinfo->xres = var->xres;
  963. dinfo->yres = var->xres;
  964. dinfo->pixclock = var->pixclock;
  965. dinfo->info->fix.visual = dinfo->visual;
  966. dinfo->info->fix.line_length = dinfo->pitch;
  967. switch (dinfo->bpp) {
  968. case 8:
  969. dinfo->visual = FB_VISUAL_PSEUDOCOLOR;
  970. dinfo->pitch = var->xres_virtual;
  971. break;
  972. case 16:
  973. dinfo->visual = FB_VISUAL_TRUECOLOR;
  974. dinfo->pitch = var->xres_virtual * 2;
  975. break;
  976. case 32:
  977. dinfo->visual = FB_VISUAL_TRUECOLOR;
  978. dinfo->pitch = var->xres_virtual * 4;
  979. break;
  980. }
  981. /* Make sure the line length is a aligned correctly. */
  982. dinfo->pitch = ROUND_UP_TO(dinfo->pitch, STRIDE_ALIGNMENT);
  983. if (FIXED_MODE(dinfo))
  984. dinfo->pitch = dinfo->initial_pitch;
  985. dinfo->info->screen_base = (char __iomem *)dinfo->fb.virtual;
  986. dinfo->info->fix.line_length = dinfo->pitch;
  987. dinfo->info->fix.visual = dinfo->visual;
  988. }
  989. /* fbops functions */
  990. /***************************************************************
  991. * fbdev interface *
  992. ***************************************************************/
  993. static int
  994. intelfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  995. {
  996. int change_var = 0;
  997. struct fb_var_screeninfo v;
  998. struct intelfb_info *dinfo;
  999. static int first = 1;
  1000. DBG_MSG("intelfb_check_var: accel_flags is %d\n", var->accel_flags);
  1001. dinfo = GET_DINFO(info);
  1002. if (intelfbhw_validate_mode(dinfo, var) != 0)
  1003. return -EINVAL;
  1004. v = *var;
  1005. /* Check for a supported bpp. */
  1006. if (v.bits_per_pixel <= 8) {
  1007. v.bits_per_pixel = 8;
  1008. } else if (v.bits_per_pixel <= 16) {
  1009. if (v.bits_per_pixel == 16)
  1010. v.green.length = 6;
  1011. v.bits_per_pixel = 16;
  1012. } else if (v.bits_per_pixel <= 32) {
  1013. v.bits_per_pixel = 32;
  1014. } else
  1015. return -EINVAL;
  1016. change_var = ((info->var.xres != var->xres) ||
  1017. (info->var.yres != var->yres) ||
  1018. (info->var.xres_virtual != var->xres_virtual) ||
  1019. (info->var.yres_virtual != var->yres_virtual) ||
  1020. (info->var.bits_per_pixel != var->bits_per_pixel) ||
  1021. memcmp(&info->var.red, &var->red, sizeof(var->red)) ||
  1022. memcmp(&info->var.green, &var->green,
  1023. sizeof(var->green)) ||
  1024. memcmp(&info->var.blue, &var->blue, sizeof(var->blue)));
  1025. if (FIXED_MODE(dinfo) &&
  1026. (change_var ||
  1027. var->yres_virtual > dinfo->initial_var.yres_virtual ||
  1028. var->yres_virtual < dinfo->initial_var.yres ||
  1029. var->xoffset || var->nonstd)) {
  1030. if (first) {
  1031. ERR_MSG("Changing the video mode is not supported.\n");
  1032. first = 0;
  1033. }
  1034. return -EINVAL;
  1035. }
  1036. switch (intelfb_var_to_depth(&v)) {
  1037. case 8:
  1038. v.red.offset = v.green.offset = v.blue.offset = 0;
  1039. v.red.length = v.green.length = v.blue.length = 8;
  1040. v.transp.offset = v.transp.length = 0;
  1041. break;
  1042. case 15:
  1043. v.red.offset = 10;
  1044. v.green.offset = 5;
  1045. v.blue.offset = 0;
  1046. v.red.length = v.green.length = v.blue.length = 5;
  1047. v.transp.offset = v.transp.length = 0;
  1048. break;
  1049. case 16:
  1050. v.red.offset = 11;
  1051. v.green.offset = 5;
  1052. v.blue.offset = 0;
  1053. v.red.length = 5;
  1054. v.green.length = 6;
  1055. v.blue.length = 5;
  1056. v.transp.offset = v.transp.length = 0;
  1057. break;
  1058. case 24:
  1059. v.red.offset = 16;
  1060. v.green.offset = 8;
  1061. v.blue.offset = 0;
  1062. v.red.length = v.green.length = v.blue.length = 8;
  1063. v.transp.offset = v.transp.length = 0;
  1064. break;
  1065. case 32:
  1066. v.red.offset = 16;
  1067. v.green.offset = 8;
  1068. v.blue.offset = 0;
  1069. v.red.length = v.green.length = v.blue.length = 8;
  1070. v.transp.offset = 24;
  1071. v.transp.length = 8;
  1072. break;
  1073. }
  1074. if (v.xoffset < 0)
  1075. v.xoffset = 0;
  1076. if (v.yoffset < 0)
  1077. v.yoffset = 0;
  1078. if (v.xoffset > v.xres_virtual - v.xres)
  1079. v.xoffset = v.xres_virtual - v.xres;
  1080. if (v.yoffset > v.yres_virtual - v.yres)
  1081. v.yoffset = v.yres_virtual - v.yres;
  1082. v.red.msb_right = v.green.msb_right = v.blue.msb_right =
  1083. v.transp.msb_right = 0;
  1084. *var = v;
  1085. return 0;
  1086. }
  1087. static int
  1088. intelfb_set_par(struct fb_info *info)
  1089. {
  1090. struct intelfb_hwstate *hw;
  1091. struct intelfb_info *dinfo = GET_DINFO(info);
  1092. if (FIXED_MODE(dinfo)) {
  1093. ERR_MSG("Changing the video mode is not supported.\n");
  1094. return -EINVAL;
  1095. }
  1096. hw = kmalloc(sizeof(*hw), GFP_ATOMIC);
  1097. if (!hw)
  1098. return -ENOMEM;
  1099. DBG_MSG("intelfb_set_par (%dx%d-%d)\n", info->var.xres,
  1100. info->var.yres, info->var.bits_per_pixel);
  1101. intelfb_blank(FB_BLANK_POWERDOWN, info);
  1102. if (ACCEL(dinfo, info))
  1103. intelfbhw_2d_stop(dinfo);
  1104. memcpy(hw, &dinfo->save_state, sizeof(*hw));
  1105. if (intelfbhw_mode_to_hw(dinfo, hw, &info->var))
  1106. goto invalid_mode;
  1107. if (intelfbhw_program_mode(dinfo, hw, 0))
  1108. goto invalid_mode;
  1109. #if REGDUMP > 0
  1110. intelfbhw_read_hw_state(dinfo, hw, 0);
  1111. intelfbhw_print_hw_state(dinfo, hw);
  1112. #endif
  1113. update_dinfo(dinfo, &info->var);
  1114. if (ACCEL(dinfo, info))
  1115. intelfbhw_2d_start(dinfo);
  1116. intelfb_pan_display(&info->var, info);
  1117. intelfb_blank(FB_BLANK_UNBLANK, info);
  1118. if (ACCEL(dinfo, info)) {
  1119. info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
  1120. FBINFO_HWACCEL_COPYAREA | FBINFO_HWACCEL_FILLRECT |
  1121. FBINFO_HWACCEL_IMAGEBLIT;
  1122. } else {
  1123. info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
  1124. }
  1125. kfree(hw);
  1126. return 0;
  1127. invalid_mode:
  1128. kfree(hw);
  1129. return -EINVAL;
  1130. }
  1131. static int
  1132. intelfb_setcolreg(unsigned regno, unsigned red, unsigned green,
  1133. unsigned blue, unsigned transp, struct fb_info *info)
  1134. {
  1135. struct intelfb_info *dinfo = GET_DINFO(info);
  1136. #if VERBOSE > 0
  1137. DBG_MSG("intelfb_setcolreg: regno %d, depth %d\n", regno, dinfo->depth);
  1138. #endif
  1139. if (regno > 255)
  1140. return 1;
  1141. if (dinfo->depth == 8) {
  1142. red >>= 8;
  1143. green >>= 8;
  1144. blue >>= 8;
  1145. intelfbhw_setcolreg(dinfo, regno, red, green, blue,
  1146. transp);
  1147. }
  1148. if (regno < 16) {
  1149. switch (dinfo->depth) {
  1150. case 15:
  1151. dinfo->pseudo_palette[regno] = ((red & 0xf800) >> 1) |
  1152. ((green & 0xf800) >> 6) |
  1153. ((blue & 0xf800) >> 11);
  1154. break;
  1155. case 16:
  1156. dinfo->pseudo_palette[regno] = (red & 0xf800) |
  1157. ((green & 0xfc00) >> 5) |
  1158. ((blue & 0xf800) >> 11);
  1159. break;
  1160. case 24:
  1161. dinfo->pseudo_palette[regno] = ((red & 0xff00) << 8) |
  1162. (green & 0xff00) |
  1163. ((blue & 0xff00) >> 8);
  1164. break;
  1165. }
  1166. }
  1167. return 0;
  1168. }
  1169. static int
  1170. intelfb_blank(int blank, struct fb_info *info)
  1171. {
  1172. intelfbhw_do_blank(blank, info);
  1173. return 0;
  1174. }
  1175. static int
  1176. intelfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
  1177. {
  1178. intelfbhw_pan_display(var, info);
  1179. return 0;
  1180. }
  1181. /* When/if we have our own ioctls. */
  1182. static int
  1183. intelfb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
  1184. {
  1185. int retval = 0;
  1186. return retval;
  1187. }
  1188. static void
  1189. intelfb_fillrect (struct fb_info *info, const struct fb_fillrect *rect)
  1190. {
  1191. struct intelfb_info *dinfo = GET_DINFO(info);
  1192. u32 rop, color;
  1193. #if VERBOSE > 0
  1194. DBG_MSG("intelfb_fillrect\n");
  1195. #endif
  1196. if (!ACCEL(dinfo, info) || dinfo->depth == 4)
  1197. return cfb_fillrect(info, rect);
  1198. if (rect->rop == ROP_COPY)
  1199. rop = PAT_ROP_GXCOPY;
  1200. else // ROP_XOR
  1201. rop = PAT_ROP_GXXOR;
  1202. if (dinfo->depth != 8)
  1203. color = dinfo->pseudo_palette[rect->color];
  1204. else
  1205. color = rect->color;
  1206. intelfbhw_do_fillrect(dinfo, rect->dx, rect->dy,
  1207. rect->width, rect->height, color,
  1208. dinfo->pitch, info->var.bits_per_pixel,
  1209. rop);
  1210. }
  1211. static void
  1212. intelfb_copyarea(struct fb_info *info, const struct fb_copyarea *region)
  1213. {
  1214. struct intelfb_info *dinfo = GET_DINFO(info);
  1215. #if VERBOSE > 0
  1216. DBG_MSG("intelfb_copyarea\n");
  1217. #endif
  1218. if (!ACCEL(dinfo, info) || dinfo->depth == 4)
  1219. return cfb_copyarea(info, region);
  1220. intelfbhw_do_bitblt(dinfo, region->sx, region->sy, region->dx,
  1221. region->dy, region->width, region->height,
  1222. dinfo->pitch, info->var.bits_per_pixel);
  1223. }
  1224. static void
  1225. intelfb_imageblit(struct fb_info *info, const struct fb_image *image)
  1226. {
  1227. struct intelfb_info *dinfo = GET_DINFO(info);
  1228. u32 fgcolor, bgcolor;
  1229. #if VERBOSE > 0
  1230. DBG_MSG("intelfb_imageblit\n");
  1231. #endif
  1232. if (!ACCEL(dinfo, info) || dinfo->depth == 4
  1233. || image->depth != 1)
  1234. return cfb_imageblit(info, image);
  1235. if (dinfo->depth != 8) {
  1236. fgcolor = dinfo->pseudo_palette[image->fg_color];
  1237. bgcolor = dinfo->pseudo_palette[image->bg_color];
  1238. } else {
  1239. fgcolor = image->fg_color;
  1240. bgcolor = image->bg_color;
  1241. }
  1242. if (!intelfbhw_do_drawglyph(dinfo, fgcolor, bgcolor, image->width,
  1243. image->height, image->data,
  1244. image->dx, image->dy,
  1245. dinfo->pitch, info->var.bits_per_pixel))
  1246. return cfb_imageblit(info, image);
  1247. }
  1248. static int
  1249. intelfb_cursor(struct fb_info *info, struct fb_cursor *cursor)
  1250. {
  1251. struct intelfb_info *dinfo = GET_DINFO(info);
  1252. #if VERBOSE > 0
  1253. DBG_MSG("intelfb_cursor\n");
  1254. #endif
  1255. if (!dinfo->hwcursor)
  1256. return -ENODEV;
  1257. intelfbhw_cursor_hide(dinfo);
  1258. /* If XFree killed the cursor - restore it */
  1259. if (INREG(CURSOR_A_BASEADDR) != dinfo->cursor.offset << 12) {
  1260. u32 fg, bg;
  1261. DBG_MSG("the cursor was killed - restore it !!\n");
  1262. DBG_MSG("size %d, %d pos %d, %d\n",
  1263. cursor->image.width, cursor->image.height,
  1264. cursor->image.dx, cursor->image.dy);
  1265. intelfbhw_cursor_init(dinfo);
  1266. intelfbhw_cursor_reset(dinfo);
  1267. intelfbhw_cursor_setpos(dinfo, cursor->image.dx,
  1268. cursor->image.dy);
  1269. if (dinfo->depth != 8) {
  1270. fg =dinfo->pseudo_palette[cursor->image.fg_color];
  1271. bg =dinfo->pseudo_palette[cursor->image.bg_color];
  1272. } else {
  1273. fg = cursor->image.fg_color;
  1274. bg = cursor->image.bg_color;
  1275. }
  1276. intelfbhw_cursor_setcolor(dinfo, bg, fg);
  1277. intelfbhw_cursor_load(dinfo, cursor->image.width,
  1278. cursor->image.height,
  1279. dinfo->cursor_src);
  1280. if (cursor->enable)
  1281. intelfbhw_cursor_show(dinfo);
  1282. return 0;
  1283. }
  1284. if (cursor->set & FB_CUR_SETPOS) {
  1285. u32 dx, dy;
  1286. dx = cursor->image.dx - info->var.xoffset;
  1287. dy = cursor->image.dy - info->var.yoffset;
  1288. intelfbhw_cursor_setpos(dinfo, dx, dy);
  1289. }
  1290. if (cursor->set & FB_CUR_SETSIZE) {
  1291. if (cursor->image.width > 64 || cursor->image.height > 64)
  1292. return -ENXIO;
  1293. intelfbhw_cursor_reset(dinfo);
  1294. }
  1295. if (cursor->set & FB_CUR_SETCMAP) {
  1296. u32 fg, bg;
  1297. if (dinfo->depth != 8) {
  1298. fg = dinfo->pseudo_palette[cursor->image.fg_color];
  1299. bg = dinfo->pseudo_palette[cursor->image.bg_color];
  1300. } else {
  1301. fg = cursor->image.fg_color;
  1302. bg = cursor->image.bg_color;
  1303. }
  1304. intelfbhw_cursor_setcolor(dinfo, bg, fg);
  1305. }
  1306. if (cursor->set & (FB_CUR_SETSHAPE | FB_CUR_SETIMAGE)) {
  1307. u32 s_pitch = (ROUND_UP_TO(cursor->image.width, 8) / 8);
  1308. u32 size = s_pitch * cursor->image.height;
  1309. u8 *dat = (u8 *) cursor->image.data;
  1310. u8 *msk = (u8 *) cursor->mask;
  1311. u8 src[64];
  1312. u32 i;
  1313. if (cursor->image.depth != 1)
  1314. return -ENXIO;
  1315. switch (cursor->rop) {
  1316. case ROP_XOR:
  1317. for (i = 0; i < size; i++)
  1318. src[i] = dat[i] ^ msk[i];
  1319. break;
  1320. case ROP_COPY:
  1321. default:
  1322. for (i = 0; i < size; i++)
  1323. src[i] = dat[i] & msk[i];
  1324. break;
  1325. }
  1326. /* save the bitmap to restore it when XFree will
  1327. make the cursor dirty */
  1328. memcpy(dinfo->cursor_src, src, size);
  1329. intelfbhw_cursor_load(dinfo, cursor->image.width,
  1330. cursor->image.height, src);
  1331. }
  1332. if (cursor->enable)
  1333. intelfbhw_cursor_show(dinfo);
  1334. return 0;
  1335. }
  1336. static int
  1337. intelfb_sync(struct fb_info *info)
  1338. {
  1339. struct intelfb_info *dinfo = GET_DINFO(info);
  1340. #if VERBOSE > 0
  1341. DBG_MSG("intelfb_sync\n");
  1342. #endif
  1343. if (dinfo->ring_lockup)
  1344. return 0;
  1345. intelfbhw_do_sync(dinfo);
  1346. return 0;
  1347. }