intelfbdrv.c 41 KB

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