intelfbdrv.c 44 KB

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