intelfbdrv.c 43 KB

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