intelfbdrv.c 41 KB

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