intelfbdrv.c 41 KB

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