intelfbdrv.c 43 KB

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