intelfbdrv.c 43 KB

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