intelfbdrv.c 43 KB

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