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