intelfbdrv.c 43 KB

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