intelfbdrv.c 44 KB

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