intelfbdrv.c 41 KB

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