intelfbdrv.c 41 KB

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