intelfbdrv.c 43 KB

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