intelfbdrv.c 42 KB

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