PageRenderTime 58ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/video/intelfb/intelfbdrv.c

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