intelfbdrv.c 41 KB

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