intelfbdrv.c 43 KB

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