fbmem.c 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832
  1. /*
  2. * linux/drivers/video/fbmem.c
  3. *
  4. * Copyright (C) 1994 Martin Schaller
  5. *
  6. * 2001 - Documented with DocBook
  7. * - Brad Douglas <brad@neruo.com>
  8. *
  9. * This file is subject to the terms and conditions of the GNU General Public
  10. * License. See the file COPYING in the main directory of this archive
  11. * for more details.
  12. */
  13. #include <linux/module.h>
  14. #include <linux/compat.h>
  15. #include <linux/types.h>
  16. #include <linux/errno.h>
  17. #include <linux/smp_lock.h>
  18. #include <linux/kernel.h>
  19. #include <linux/major.h>
  20. #include <linux/slab.h>
  21. #include <linux/mm.h>
  22. #include <linux/mman.h>
  23. #include <linux/vt.h>
  24. #include <linux/init.h>
  25. #include <linux/linux_logo.h>
  26. #include <linux/proc_fs.h>
  27. #include <linux/seq_file.h>
  28. #include <linux/console.h>
  29. #include <linux/kmod.h>
  30. #include <linux/err.h>
  31. #include <linux/device.h>
  32. #include <linux/efi.h>
  33. #include <linux/fb.h>
  34. #include <asm/fb.h>
  35. /*
  36. * Frame buffer device initialization and setup routines
  37. */
  38. #define FBPIXMAPSIZE (1024 * 8)
  39. struct fb_info *registered_fb[FB_MAX] __read_mostly;
  40. int num_registered_fb __read_mostly;
  41. int lock_fb_info(struct fb_info *info)
  42. {
  43. mutex_lock(&info->lock);
  44. if (!info->fbops) {
  45. mutex_unlock(&info->lock);
  46. return 0;
  47. }
  48. return 1;
  49. }
  50. EXPORT_SYMBOL(lock_fb_info);
  51. /*
  52. * Helpers
  53. */
  54. int fb_get_color_depth(struct fb_var_screeninfo *var,
  55. struct fb_fix_screeninfo *fix)
  56. {
  57. int depth = 0;
  58. if (fix->visual == FB_VISUAL_MONO01 ||
  59. fix->visual == FB_VISUAL_MONO10)
  60. depth = 1;
  61. else {
  62. if (var->green.length == var->blue.length &&
  63. var->green.length == var->red.length &&
  64. var->green.offset == var->blue.offset &&
  65. var->green.offset == var->red.offset)
  66. depth = var->green.length;
  67. else
  68. depth = var->green.length + var->red.length +
  69. var->blue.length;
  70. }
  71. return depth;
  72. }
  73. EXPORT_SYMBOL(fb_get_color_depth);
  74. /*
  75. * Data padding functions.
  76. */
  77. void fb_pad_aligned_buffer(u8 *dst, u32 d_pitch, u8 *src, u32 s_pitch, u32 height)
  78. {
  79. __fb_pad_aligned_buffer(dst, d_pitch, src, s_pitch, height);
  80. }
  81. EXPORT_SYMBOL(fb_pad_aligned_buffer);
  82. void fb_pad_unaligned_buffer(u8 *dst, u32 d_pitch, u8 *src, u32 idx, u32 height,
  83. u32 shift_high, u32 shift_low, u32 mod)
  84. {
  85. u8 mask = (u8) (0xfff << shift_high), tmp;
  86. int i, j;
  87. for (i = height; i--; ) {
  88. for (j = 0; j < idx; j++) {
  89. tmp = dst[j];
  90. tmp &= mask;
  91. tmp |= *src >> shift_low;
  92. dst[j] = tmp;
  93. tmp = *src << shift_high;
  94. dst[j+1] = tmp;
  95. src++;
  96. }
  97. tmp = dst[idx];
  98. tmp &= mask;
  99. tmp |= *src >> shift_low;
  100. dst[idx] = tmp;
  101. if (shift_high < mod) {
  102. tmp = *src << shift_high;
  103. dst[idx+1] = tmp;
  104. }
  105. src++;
  106. dst += d_pitch;
  107. }
  108. }
  109. EXPORT_SYMBOL(fb_pad_unaligned_buffer);
  110. /*
  111. * we need to lock this section since fb_cursor
  112. * may use fb_imageblit()
  113. */
  114. char* fb_get_buffer_offset(struct fb_info *info, struct fb_pixmap *buf, u32 size)
  115. {
  116. u32 align = buf->buf_align - 1, offset;
  117. char *addr = buf->addr;
  118. /* If IO mapped, we need to sync before access, no sharing of
  119. * the pixmap is done
  120. */
  121. if (buf->flags & FB_PIXMAP_IO) {
  122. if (info->fbops->fb_sync && (buf->flags & FB_PIXMAP_SYNC))
  123. info->fbops->fb_sync(info);
  124. return addr;
  125. }
  126. /* See if we fit in the remaining pixmap space */
  127. offset = buf->offset + align;
  128. offset &= ~align;
  129. if (offset + size > buf->size) {
  130. /* We do not fit. In order to be able to re-use the buffer,
  131. * we must ensure no asynchronous DMA'ing or whatever operation
  132. * is in progress, we sync for that.
  133. */
  134. if (info->fbops->fb_sync && (buf->flags & FB_PIXMAP_SYNC))
  135. info->fbops->fb_sync(info);
  136. offset = 0;
  137. }
  138. buf->offset = offset + size;
  139. addr += offset;
  140. return addr;
  141. }
  142. #ifdef CONFIG_LOGO
  143. static inline unsigned safe_shift(unsigned d, int n)
  144. {
  145. return n < 0 ? d >> -n : d << n;
  146. }
  147. static void fb_set_logocmap(struct fb_info *info,
  148. const struct linux_logo *logo)
  149. {
  150. struct fb_cmap palette_cmap;
  151. u16 palette_green[16];
  152. u16 palette_blue[16];
  153. u16 palette_red[16];
  154. int i, j, n;
  155. const unsigned char *clut = logo->clut;
  156. palette_cmap.start = 0;
  157. palette_cmap.len = 16;
  158. palette_cmap.red = palette_red;
  159. palette_cmap.green = palette_green;
  160. palette_cmap.blue = palette_blue;
  161. palette_cmap.transp = NULL;
  162. for (i = 0; i < logo->clutsize; i += n) {
  163. n = logo->clutsize - i;
  164. /* palette_cmap provides space for only 16 colors at once */
  165. if (n > 16)
  166. n = 16;
  167. palette_cmap.start = 32 + i;
  168. palette_cmap.len = n;
  169. for (j = 0; j < n; ++j) {
  170. palette_cmap.red[j] = clut[0] << 8 | clut[0];
  171. palette_cmap.green[j] = clut[1] << 8 | clut[1];
  172. palette_cmap.blue[j] = clut[2] << 8 | clut[2];
  173. clut += 3;
  174. }
  175. fb_set_cmap(&palette_cmap, info);
  176. }
  177. }
  178. static void fb_set_logo_truepalette(struct fb_info *info,
  179. const struct linux_logo *logo,
  180. u32 *palette)
  181. {
  182. static const unsigned char mask[] = { 0,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff };
  183. unsigned char redmask, greenmask, bluemask;
  184. int redshift, greenshift, blueshift;
  185. int i;
  186. const unsigned char *clut = logo->clut;
  187. /*
  188. * We have to create a temporary palette since console palette is only
  189. * 16 colors long.
  190. */
  191. /* Bug: Doesn't obey msb_right ... (who needs that?) */
  192. redmask = mask[info->var.red.length < 8 ? info->var.red.length : 8];
  193. greenmask = mask[info->var.green.length < 8 ? info->var.green.length : 8];
  194. bluemask = mask[info->var.blue.length < 8 ? info->var.blue.length : 8];
  195. redshift = info->var.red.offset - (8 - info->var.red.length);
  196. greenshift = info->var.green.offset - (8 - info->var.green.length);
  197. blueshift = info->var.blue.offset - (8 - info->var.blue.length);
  198. for ( i = 0; i < logo->clutsize; i++) {
  199. palette[i+32] = (safe_shift((clut[0] & redmask), redshift) |
  200. safe_shift((clut[1] & greenmask), greenshift) |
  201. safe_shift((clut[2] & bluemask), blueshift));
  202. clut += 3;
  203. }
  204. }
  205. static void fb_set_logo_directpalette(struct fb_info *info,
  206. const struct linux_logo *logo,
  207. u32 *palette)
  208. {
  209. int redshift, greenshift, blueshift;
  210. int i;
  211. redshift = info->var.red.offset;
  212. greenshift = info->var.green.offset;
  213. blueshift = info->var.blue.offset;
  214. for (i = 32; i < 32 + logo->clutsize; i++)
  215. palette[i] = i << redshift | i << greenshift | i << blueshift;
  216. }
  217. static void fb_set_logo(struct fb_info *info,
  218. const struct linux_logo *logo, u8 *dst,
  219. int depth)
  220. {
  221. int i, j, k;
  222. const u8 *src = logo->data;
  223. u8 xor = (info->fix.visual == FB_VISUAL_MONO01) ? 0xff : 0;
  224. u8 fg = 1, d;
  225. switch (fb_get_color_depth(&info->var, &info->fix)) {
  226. case 1:
  227. fg = 1;
  228. break;
  229. case 2:
  230. fg = 3;
  231. break;
  232. default:
  233. fg = 7;
  234. break;
  235. }
  236. if (info->fix.visual == FB_VISUAL_MONO01 ||
  237. info->fix.visual == FB_VISUAL_MONO10)
  238. fg = ~((u8) (0xfff << info->var.green.length));
  239. switch (depth) {
  240. case 4:
  241. for (i = 0; i < logo->height; i++)
  242. for (j = 0; j < logo->width; src++) {
  243. *dst++ = *src >> 4;
  244. j++;
  245. if (j < logo->width) {
  246. *dst++ = *src & 0x0f;
  247. j++;
  248. }
  249. }
  250. break;
  251. case 1:
  252. for (i = 0; i < logo->height; i++) {
  253. for (j = 0; j < logo->width; src++) {
  254. d = *src ^ xor;
  255. for (k = 7; k >= 0; k--) {
  256. *dst++ = ((d >> k) & 1) ? fg : 0;
  257. j++;
  258. }
  259. }
  260. }
  261. break;
  262. }
  263. }
  264. /*
  265. * Three (3) kinds of logo maps exist. linux_logo_clut224 (>16 colors),
  266. * linux_logo_vga16 (16 colors) and linux_logo_mono (2 colors). Depending on
  267. * the visual format and color depth of the framebuffer, the DAC, the
  268. * pseudo_palette, and the logo data will be adjusted accordingly.
  269. *
  270. * Case 1 - linux_logo_clut224:
  271. * Color exceeds the number of console colors (16), thus we set the hardware DAC
  272. * using fb_set_cmap() appropriately. The "needs_cmapreset" flag will be set.
  273. *
  274. * For visuals that require color info from the pseudo_palette, we also construct
  275. * one for temporary use. The "needs_directpalette" or "needs_truepalette" flags
  276. * will be set.
  277. *
  278. * Case 2 - linux_logo_vga16:
  279. * The number of colors just matches the console colors, thus there is no need
  280. * to set the DAC or the pseudo_palette. However, the bitmap is packed, ie,
  281. * each byte contains color information for two pixels (upper and lower nibble).
  282. * To be consistent with fb_imageblit() usage, we therefore separate the two
  283. * nibbles into separate bytes. The "depth" flag will be set to 4.
  284. *
  285. * Case 3 - linux_logo_mono:
  286. * This is similar with Case 2. Each byte contains information for 8 pixels.
  287. * We isolate each bit and expand each into a byte. The "depth" flag will
  288. * be set to 1.
  289. */
  290. static struct logo_data {
  291. int depth;
  292. int needs_directpalette;
  293. int needs_truepalette;
  294. int needs_cmapreset;
  295. const struct linux_logo *logo;
  296. } fb_logo __read_mostly;
  297. static void fb_rotate_logo_ud(const u8 *in, u8 *out, u32 width, u32 height)
  298. {
  299. u32 size = width * height, i;
  300. out += size - 1;
  301. for (i = size; i--; )
  302. *out-- = *in++;
  303. }
  304. static void fb_rotate_logo_cw(const u8 *in, u8 *out, u32 width, u32 height)
  305. {
  306. int i, j, h = height - 1;
  307. for (i = 0; i < height; i++)
  308. for (j = 0; j < width; j++)
  309. out[height * j + h - i] = *in++;
  310. }
  311. static void fb_rotate_logo_ccw(const u8 *in, u8 *out, u32 width, u32 height)
  312. {
  313. int i, j, w = width - 1;
  314. for (i = 0; i < height; i++)
  315. for (j = 0; j < width; j++)
  316. out[height * (w - j) + i] = *in++;
  317. }
  318. static void fb_rotate_logo(struct fb_info *info, u8 *dst,
  319. struct fb_image *image, int rotate)
  320. {
  321. u32 tmp;
  322. if (rotate == FB_ROTATE_UD) {
  323. fb_rotate_logo_ud(image->data, dst, image->width,
  324. image->height);
  325. image->dx = info->var.xres - image->width - image->dx;
  326. image->dy = info->var.yres - image->height - image->dy;
  327. } else if (rotate == FB_ROTATE_CW) {
  328. fb_rotate_logo_cw(image->data, dst, image->width,
  329. image->height);
  330. tmp = image->width;
  331. image->width = image->height;
  332. image->height = tmp;
  333. tmp = image->dy;
  334. image->dy = image->dx;
  335. image->dx = info->var.xres - image->width - tmp;
  336. } else if (rotate == FB_ROTATE_CCW) {
  337. fb_rotate_logo_ccw(image->data, dst, image->width,
  338. image->height);
  339. tmp = image->width;
  340. image->width = image->height;
  341. image->height = tmp;
  342. tmp = image->dx;
  343. image->dx = image->dy;
  344. image->dy = info->var.yres - image->height - tmp;
  345. }
  346. image->data = dst;
  347. }
  348. static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
  349. int rotate, unsigned int num)
  350. {
  351. unsigned int x;
  352. if (rotate == FB_ROTATE_UR) {
  353. for (x = 0;
  354. x < num && image->dx + image->width <= info->var.xres;
  355. x++) {
  356. info->fbops->fb_imageblit(info, image);
  357. image->dx += image->width + 8;
  358. }
  359. } else if (rotate == FB_ROTATE_UD) {
  360. for (x = 0; x < num && image->dx >= 0; x++) {
  361. info->fbops->fb_imageblit(info, image);
  362. image->dx -= image->width + 8;
  363. }
  364. } else if (rotate == FB_ROTATE_CW) {
  365. for (x = 0;
  366. x < num && image->dy + image->height <= info->var.yres;
  367. x++) {
  368. info->fbops->fb_imageblit(info, image);
  369. image->dy += image->height + 8;
  370. }
  371. } else if (rotate == FB_ROTATE_CCW) {
  372. for (x = 0; x < num && image->dy >= 0; x++) {
  373. info->fbops->fb_imageblit(info, image);
  374. image->dy -= image->height + 8;
  375. }
  376. }
  377. }
  378. static int fb_show_logo_line(struct fb_info *info, int rotate,
  379. const struct linux_logo *logo, int y,
  380. unsigned int n)
  381. {
  382. u32 *palette = NULL, *saved_pseudo_palette = NULL;
  383. unsigned char *logo_new = NULL, *logo_rotate = NULL;
  384. struct fb_image image;
  385. /* Return if the frame buffer is not mapped or suspended */
  386. if (logo == NULL || info->state != FBINFO_STATE_RUNNING ||
  387. info->flags & FBINFO_MODULE)
  388. return 0;
  389. image.depth = 8;
  390. image.data = logo->data;
  391. if (fb_logo.needs_cmapreset)
  392. fb_set_logocmap(info, logo);
  393. if (fb_logo.needs_truepalette ||
  394. fb_logo.needs_directpalette) {
  395. palette = kmalloc(256 * 4, GFP_KERNEL);
  396. if (palette == NULL)
  397. return 0;
  398. if (fb_logo.needs_truepalette)
  399. fb_set_logo_truepalette(info, logo, palette);
  400. else
  401. fb_set_logo_directpalette(info, logo, palette);
  402. saved_pseudo_palette = info->pseudo_palette;
  403. info->pseudo_palette = palette;
  404. }
  405. if (fb_logo.depth <= 4) {
  406. logo_new = kmalloc(logo->width * logo->height, GFP_KERNEL);
  407. if (logo_new == NULL) {
  408. kfree(palette);
  409. if (saved_pseudo_palette)
  410. info->pseudo_palette = saved_pseudo_palette;
  411. return 0;
  412. }
  413. image.data = logo_new;
  414. fb_set_logo(info, logo, logo_new, fb_logo.depth);
  415. }
  416. image.dx = 0;
  417. image.dy = y;
  418. image.width = logo->width;
  419. image.height = logo->height;
  420. if (rotate) {
  421. logo_rotate = kmalloc(logo->width *
  422. logo->height, GFP_KERNEL);
  423. if (logo_rotate)
  424. fb_rotate_logo(info, logo_rotate, &image, rotate);
  425. }
  426. fb_do_show_logo(info, &image, rotate, n);
  427. kfree(palette);
  428. if (saved_pseudo_palette != NULL)
  429. info->pseudo_palette = saved_pseudo_palette;
  430. kfree(logo_new);
  431. kfree(logo_rotate);
  432. return logo->height;
  433. }
  434. #ifdef CONFIG_FB_LOGO_EXTRA
  435. #define FB_LOGO_EX_NUM_MAX 10
  436. static struct logo_data_extra {
  437. const struct linux_logo *logo;
  438. unsigned int n;
  439. } fb_logo_ex[FB_LOGO_EX_NUM_MAX];
  440. static unsigned int fb_logo_ex_num;
  441. void fb_append_extra_logo(const struct linux_logo *logo, unsigned int n)
  442. {
  443. if (!n || fb_logo_ex_num == FB_LOGO_EX_NUM_MAX)
  444. return;
  445. fb_logo_ex[fb_logo_ex_num].logo = logo;
  446. fb_logo_ex[fb_logo_ex_num].n = n;
  447. fb_logo_ex_num++;
  448. }
  449. static int fb_prepare_extra_logos(struct fb_info *info, unsigned int height,
  450. unsigned int yres)
  451. {
  452. unsigned int i;
  453. /* FIXME: logo_ex supports only truecolor fb. */
  454. if (info->fix.visual != FB_VISUAL_TRUECOLOR)
  455. fb_logo_ex_num = 0;
  456. for (i = 0; i < fb_logo_ex_num; i++) {
  457. if (fb_logo_ex[i].logo->type != fb_logo.logo->type) {
  458. fb_logo_ex[i].logo = NULL;
  459. continue;
  460. }
  461. height += fb_logo_ex[i].logo->height;
  462. if (height > yres) {
  463. height -= fb_logo_ex[i].logo->height;
  464. fb_logo_ex_num = i;
  465. break;
  466. }
  467. }
  468. return height;
  469. }
  470. static int fb_show_extra_logos(struct fb_info *info, int y, int rotate)
  471. {
  472. unsigned int i;
  473. for (i = 0; i < fb_logo_ex_num; i++)
  474. y += fb_show_logo_line(info, rotate,
  475. fb_logo_ex[i].logo, y, fb_logo_ex[i].n);
  476. return y;
  477. }
  478. #else /* !CONFIG_FB_LOGO_EXTRA */
  479. static inline int fb_prepare_extra_logos(struct fb_info *info,
  480. unsigned int height,
  481. unsigned int yres)
  482. {
  483. return height;
  484. }
  485. static inline int fb_show_extra_logos(struct fb_info *info, int y, int rotate)
  486. {
  487. return y;
  488. }
  489. #endif /* CONFIG_FB_LOGO_EXTRA */
  490. int fb_prepare_logo(struct fb_info *info, int rotate)
  491. {
  492. int depth = fb_get_color_depth(&info->var, &info->fix);
  493. unsigned int yres;
  494. memset(&fb_logo, 0, sizeof(struct logo_data));
  495. if (info->flags & FBINFO_MISC_TILEBLITTING ||
  496. info->flags & FBINFO_MODULE)
  497. return 0;
  498. if (info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
  499. depth = info->var.blue.length;
  500. if (info->var.red.length < depth)
  501. depth = info->var.red.length;
  502. if (info->var.green.length < depth)
  503. depth = info->var.green.length;
  504. }
  505. if (info->fix.visual == FB_VISUAL_STATIC_PSEUDOCOLOR && depth > 4) {
  506. /* assume console colormap */
  507. depth = 4;
  508. }
  509. /* Return if no suitable logo was found */
  510. fb_logo.logo = fb_find_logo(depth);
  511. if (!fb_logo.logo) {
  512. return 0;
  513. }
  514. if (rotate == FB_ROTATE_UR || rotate == FB_ROTATE_UD)
  515. yres = info->var.yres;
  516. else
  517. yres = info->var.xres;
  518. if (fb_logo.logo->height > yres) {
  519. fb_logo.logo = NULL;
  520. return 0;
  521. }
  522. /* What depth we asked for might be different from what we get */
  523. if (fb_logo.logo->type == LINUX_LOGO_CLUT224)
  524. fb_logo.depth = 8;
  525. else if (fb_logo.logo->type == LINUX_LOGO_VGA16)
  526. fb_logo.depth = 4;
  527. else
  528. fb_logo.depth = 1;
  529. if (fb_logo.depth > 4 && depth > 4) {
  530. switch (info->fix.visual) {
  531. case FB_VISUAL_TRUECOLOR:
  532. fb_logo.needs_truepalette = 1;
  533. break;
  534. case FB_VISUAL_DIRECTCOLOR:
  535. fb_logo.needs_directpalette = 1;
  536. fb_logo.needs_cmapreset = 1;
  537. break;
  538. case FB_VISUAL_PSEUDOCOLOR:
  539. fb_logo.needs_cmapreset = 1;
  540. break;
  541. }
  542. }
  543. return fb_prepare_extra_logos(info, fb_logo.logo->height, yres);
  544. }
  545. int fb_show_logo(struct fb_info *info, int rotate)
  546. {
  547. int y;
  548. y = fb_show_logo_line(info, rotate, fb_logo.logo, 0,
  549. num_online_cpus());
  550. y = fb_show_extra_logos(info, y, rotate);
  551. return y;
  552. }
  553. #else
  554. int fb_prepare_logo(struct fb_info *info, int rotate) { return 0; }
  555. int fb_show_logo(struct fb_info *info, int rotate) { return 0; }
  556. #endif /* CONFIG_LOGO */
  557. static void *fb_seq_start(struct seq_file *m, loff_t *pos)
  558. {
  559. return (*pos < FB_MAX) ? pos : NULL;
  560. }
  561. static void *fb_seq_next(struct seq_file *m, void *v, loff_t *pos)
  562. {
  563. (*pos)++;
  564. return (*pos < FB_MAX) ? pos : NULL;
  565. }
  566. static void fb_seq_stop(struct seq_file *m, void *v)
  567. {
  568. }
  569. static int fb_seq_show(struct seq_file *m, void *v)
  570. {
  571. int i = *(loff_t *)v;
  572. struct fb_info *fi = registered_fb[i];
  573. if (fi)
  574. seq_printf(m, "%d %s\n", fi->node, fi->fix.id);
  575. return 0;
  576. }
  577. static const struct seq_operations proc_fb_seq_ops = {
  578. .start = fb_seq_start,
  579. .next = fb_seq_next,
  580. .stop = fb_seq_stop,
  581. .show = fb_seq_show,
  582. };
  583. static int proc_fb_open(struct inode *inode, struct file *file)
  584. {
  585. return seq_open(file, &proc_fb_seq_ops);
  586. }
  587. static const struct file_operations fb_proc_fops = {
  588. .owner = THIS_MODULE,
  589. .open = proc_fb_open,
  590. .read = seq_read,
  591. .llseek = seq_lseek,
  592. .release = seq_release,
  593. };
  594. static ssize_t
  595. fb_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
  596. {
  597. unsigned long p = *ppos;
  598. struct inode *inode = file->f_path.dentry->d_inode;
  599. int fbidx = iminor(inode);
  600. struct fb_info *info = registered_fb[fbidx];
  601. u32 *buffer, *dst;
  602. u32 __iomem *src;
  603. int c, i, cnt = 0, err = 0;
  604. unsigned long total_size;
  605. if (!info || ! info->screen_base)
  606. return -ENODEV;
  607. if (info->state != FBINFO_STATE_RUNNING)
  608. return -EPERM;
  609. if (info->fbops->fb_read)
  610. return info->fbops->fb_read(info, buf, count, ppos);
  611. total_size = info->screen_size;
  612. if (total_size == 0)
  613. total_size = info->fix.smem_len;
  614. if (p >= total_size)
  615. return 0;
  616. if (count >= total_size)
  617. count = total_size;
  618. if (count + p > total_size)
  619. count = total_size - p;
  620. buffer = kmalloc((count > PAGE_SIZE) ? PAGE_SIZE : count,
  621. GFP_KERNEL);
  622. if (!buffer)
  623. return -ENOMEM;
  624. src = (u32 __iomem *) (info->screen_base + p);
  625. if (info->fbops->fb_sync)
  626. info->fbops->fb_sync(info);
  627. while (count) {
  628. c = (count > PAGE_SIZE) ? PAGE_SIZE : count;
  629. dst = buffer;
  630. for (i = c >> 2; i--; )
  631. *dst++ = fb_readl(src++);
  632. if (c & 3) {
  633. u8 *dst8 = (u8 *) dst;
  634. u8 __iomem *src8 = (u8 __iomem *) src;
  635. for (i = c & 3; i--;)
  636. *dst8++ = fb_readb(src8++);
  637. src = (u32 __iomem *) src8;
  638. }
  639. if (copy_to_user(buf, buffer, c)) {
  640. err = -EFAULT;
  641. break;
  642. }
  643. *ppos += c;
  644. buf += c;
  645. cnt += c;
  646. count -= c;
  647. }
  648. kfree(buffer);
  649. return (err) ? err : cnt;
  650. }
  651. static ssize_t
  652. fb_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
  653. {
  654. unsigned long p = *ppos;
  655. struct inode *inode = file->f_path.dentry->d_inode;
  656. int fbidx = iminor(inode);
  657. struct fb_info *info = registered_fb[fbidx];
  658. u32 *buffer, *src;
  659. u32 __iomem *dst;
  660. int c, i, cnt = 0, err = 0;
  661. unsigned long total_size;
  662. if (!info || !info->screen_base)
  663. return -ENODEV;
  664. if (info->state != FBINFO_STATE_RUNNING)
  665. return -EPERM;
  666. if (info->fbops->fb_write)
  667. return info->fbops->fb_write(info, buf, count, ppos);
  668. total_size = info->screen_size;
  669. if (total_size == 0)
  670. total_size = info->fix.smem_len;
  671. if (p > total_size)
  672. return -EFBIG;
  673. if (count > total_size) {
  674. err = -EFBIG;
  675. count = total_size;
  676. }
  677. if (count + p > total_size) {
  678. if (!err)
  679. err = -ENOSPC;
  680. count = total_size - p;
  681. }
  682. buffer = kmalloc((count > PAGE_SIZE) ? PAGE_SIZE : count,
  683. GFP_KERNEL);
  684. if (!buffer)
  685. return -ENOMEM;
  686. dst = (u32 __iomem *) (info->screen_base + p);
  687. if (info->fbops->fb_sync)
  688. info->fbops->fb_sync(info);
  689. while (count) {
  690. c = (count > PAGE_SIZE) ? PAGE_SIZE : count;
  691. src = buffer;
  692. if (copy_from_user(src, buf, c)) {
  693. err = -EFAULT;
  694. break;
  695. }
  696. for (i = c >> 2; i--; )
  697. fb_writel(*src++, dst++);
  698. if (c & 3) {
  699. u8 *src8 = (u8 *) src;
  700. u8 __iomem *dst8 = (u8 __iomem *) dst;
  701. for (i = c & 3; i--; )
  702. fb_writeb(*src8++, dst8++);
  703. dst = (u32 __iomem *) dst8;
  704. }
  705. *ppos += c;
  706. buf += c;
  707. cnt += c;
  708. count -= c;
  709. }
  710. kfree(buffer);
  711. return (cnt) ? cnt : err;
  712. }
  713. int
  714. fb_pan_display(struct fb_info *info, struct fb_var_screeninfo *var)
  715. {
  716. struct fb_fix_screeninfo *fix = &info->fix;
  717. unsigned int yres = info->var.yres;
  718. int err = 0;
  719. if (var->yoffset > 0) {
  720. if (var->vmode & FB_VMODE_YWRAP) {
  721. if (!fix->ywrapstep || (var->yoffset % fix->ywrapstep))
  722. err = -EINVAL;
  723. else
  724. yres = 0;
  725. } else if (!fix->ypanstep || (var->yoffset % fix->ypanstep))
  726. err = -EINVAL;
  727. }
  728. if (var->xoffset > 0 && (!fix->xpanstep ||
  729. (var->xoffset % fix->xpanstep)))
  730. err = -EINVAL;
  731. if (err || !info->fbops->fb_pan_display ||
  732. var->yoffset + yres > info->var.yres_virtual ||
  733. var->xoffset + info->var.xres > info->var.xres_virtual)
  734. return -EINVAL;
  735. if ((err = info->fbops->fb_pan_display(var, info)))
  736. return err;
  737. info->var.xoffset = var->xoffset;
  738. info->var.yoffset = var->yoffset;
  739. if (var->vmode & FB_VMODE_YWRAP)
  740. info->var.vmode |= FB_VMODE_YWRAP;
  741. else
  742. info->var.vmode &= ~FB_VMODE_YWRAP;
  743. return 0;
  744. }
  745. static int fb_check_caps(struct fb_info *info, struct fb_var_screeninfo *var,
  746. u32 activate)
  747. {
  748. struct fb_event event;
  749. struct fb_blit_caps caps, fbcaps;
  750. int err = 0;
  751. memset(&caps, 0, sizeof(caps));
  752. memset(&fbcaps, 0, sizeof(fbcaps));
  753. caps.flags = (activate & FB_ACTIVATE_ALL) ? 1 : 0;
  754. event.info = info;
  755. event.data = &caps;
  756. fb_notifier_call_chain(FB_EVENT_GET_REQ, &event);
  757. info->fbops->fb_get_caps(info, &fbcaps, var);
  758. if (((fbcaps.x ^ caps.x) & caps.x) ||
  759. ((fbcaps.y ^ caps.y) & caps.y) ||
  760. (fbcaps.len < caps.len))
  761. err = -EINVAL;
  762. return err;
  763. }
  764. int
  765. fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var)
  766. {
  767. int flags = info->flags;
  768. int ret = 0;
  769. if (var->activate & FB_ACTIVATE_INV_MODE) {
  770. struct fb_videomode mode1, mode2;
  771. fb_var_to_videomode(&mode1, var);
  772. fb_var_to_videomode(&mode2, &info->var);
  773. /* make sure we don't delete the videomode of current var */
  774. ret = fb_mode_is_equal(&mode1, &mode2);
  775. if (!ret) {
  776. struct fb_event event;
  777. event.info = info;
  778. event.data = &mode1;
  779. ret = fb_notifier_call_chain(FB_EVENT_MODE_DELETE, &event);
  780. }
  781. if (!ret)
  782. fb_delete_videomode(&mode1, &info->modelist);
  783. ret = (ret) ? -EINVAL : 0;
  784. goto done;
  785. }
  786. if ((var->activate & FB_ACTIVATE_FORCE) ||
  787. memcmp(&info->var, var, sizeof(struct fb_var_screeninfo))) {
  788. u32 activate = var->activate;
  789. if (!info->fbops->fb_check_var) {
  790. *var = info->var;
  791. goto done;
  792. }
  793. ret = info->fbops->fb_check_var(var, info);
  794. if (ret)
  795. goto done;
  796. if ((var->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW) {
  797. struct fb_videomode mode;
  798. if (info->fbops->fb_get_caps) {
  799. ret = fb_check_caps(info, var, activate);
  800. if (ret)
  801. goto done;
  802. }
  803. info->var = *var;
  804. if (info->fbops->fb_set_par)
  805. info->fbops->fb_set_par(info);
  806. fb_pan_display(info, &info->var);
  807. fb_set_cmap(&info->cmap, info);
  808. fb_var_to_videomode(&mode, &info->var);
  809. if (info->modelist.prev && info->modelist.next &&
  810. !list_empty(&info->modelist))
  811. ret = fb_add_videomode(&mode, &info->modelist);
  812. if (!ret && (flags & FBINFO_MISC_USEREVENT)) {
  813. struct fb_event event;
  814. int evnt = (activate & FB_ACTIVATE_ALL) ?
  815. FB_EVENT_MODE_CHANGE_ALL :
  816. FB_EVENT_MODE_CHANGE;
  817. info->flags &= ~FBINFO_MISC_USEREVENT;
  818. event.info = info;
  819. event.data = &mode;
  820. fb_notifier_call_chain(evnt, &event);
  821. }
  822. }
  823. }
  824. done:
  825. return ret;
  826. }
  827. int
  828. fb_blank(struct fb_info *info, int blank)
  829. {
  830. int ret = -EINVAL;
  831. if (blank > FB_BLANK_POWERDOWN)
  832. blank = FB_BLANK_POWERDOWN;
  833. if (info->fbops->fb_blank)
  834. ret = info->fbops->fb_blank(blank, info);
  835. if (!ret) {
  836. struct fb_event event;
  837. event.info = info;
  838. event.data = &blank;
  839. fb_notifier_call_chain(FB_EVENT_BLANK, &event);
  840. }
  841. return ret;
  842. }
  843. static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
  844. unsigned long arg)
  845. {
  846. struct fb_ops *fb;
  847. struct fb_var_screeninfo var;
  848. struct fb_fix_screeninfo fix;
  849. struct fb_con2fbmap con2fb;
  850. struct fb_cmap cmap_from;
  851. struct fb_cmap_user cmap;
  852. struct fb_event event;
  853. void __user *argp = (void __user *)arg;
  854. long ret = 0;
  855. switch (cmd) {
  856. case FBIOGET_VSCREENINFO:
  857. if (!lock_fb_info(info))
  858. return -ENODEV;
  859. var = info->var;
  860. unlock_fb_info(info);
  861. ret = copy_to_user(argp, &var, sizeof(var)) ? -EFAULT : 0;
  862. break;
  863. case FBIOPUT_VSCREENINFO:
  864. if (copy_from_user(&var, argp, sizeof(var)))
  865. return -EFAULT;
  866. if (!lock_fb_info(info))
  867. return -ENODEV;
  868. acquire_console_sem();
  869. info->flags |= FBINFO_MISC_USEREVENT;
  870. ret = fb_set_var(info, &var);
  871. info->flags &= ~FBINFO_MISC_USEREVENT;
  872. release_console_sem();
  873. unlock_fb_info(info);
  874. if (!ret && copy_to_user(argp, &var, sizeof(var)))
  875. ret = -EFAULT;
  876. break;
  877. case FBIOGET_FSCREENINFO:
  878. if (!lock_fb_info(info))
  879. return -ENODEV;
  880. fix = info->fix;
  881. unlock_fb_info(info);
  882. ret = copy_to_user(argp, &fix, sizeof(fix)) ? -EFAULT : 0;
  883. break;
  884. case FBIOPUTCMAP:
  885. if (copy_from_user(&cmap, argp, sizeof(cmap)))
  886. return -EFAULT;
  887. ret = fb_set_user_cmap(&cmap, info);
  888. break;
  889. case FBIOGETCMAP:
  890. if (copy_from_user(&cmap, argp, sizeof(cmap)))
  891. return -EFAULT;
  892. if (!lock_fb_info(info))
  893. return -ENODEV;
  894. cmap_from = info->cmap;
  895. unlock_fb_info(info);
  896. ret = fb_cmap_to_user(&cmap_from, &cmap);
  897. break;
  898. case FBIOPAN_DISPLAY:
  899. if (copy_from_user(&var, argp, sizeof(var)))
  900. return -EFAULT;
  901. if (!lock_fb_info(info))
  902. return -ENODEV;
  903. acquire_console_sem();
  904. ret = fb_pan_display(info, &var);
  905. release_console_sem();
  906. unlock_fb_info(info);
  907. if (ret == 0 && copy_to_user(argp, &var, sizeof(var)))
  908. return -EFAULT;
  909. break;
  910. case FBIO_CURSOR:
  911. ret = -EINVAL;
  912. break;
  913. case FBIOGET_CON2FBMAP:
  914. if (copy_from_user(&con2fb, argp, sizeof(con2fb)))
  915. return -EFAULT;
  916. if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
  917. return -EINVAL;
  918. con2fb.framebuffer = -1;
  919. event.data = &con2fb;
  920. if (!lock_fb_info(info))
  921. return -ENODEV;
  922. event.info = info;
  923. fb_notifier_call_chain(FB_EVENT_GET_CONSOLE_MAP, &event);
  924. unlock_fb_info(info);
  925. ret = copy_to_user(argp, &con2fb, sizeof(con2fb)) ? -EFAULT : 0;
  926. break;
  927. case FBIOPUT_CON2FBMAP:
  928. if (copy_from_user(&con2fb, argp, sizeof(con2fb)))
  929. return -EFAULT;
  930. if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
  931. return -EINVAL;
  932. if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
  933. return -EINVAL;
  934. if (!registered_fb[con2fb.framebuffer])
  935. request_module("fb%d", con2fb.framebuffer);
  936. if (!registered_fb[con2fb.framebuffer]) {
  937. ret = -EINVAL;
  938. break;
  939. }
  940. event.data = &con2fb;
  941. if (!lock_fb_info(info))
  942. return -ENODEV;
  943. event.info = info;
  944. ret = fb_notifier_call_chain(FB_EVENT_SET_CONSOLE_MAP, &event);
  945. unlock_fb_info(info);
  946. break;
  947. case FBIOBLANK:
  948. if (!lock_fb_info(info))
  949. return -ENODEV;
  950. acquire_console_sem();
  951. info->flags |= FBINFO_MISC_USEREVENT;
  952. ret = fb_blank(info, arg);
  953. info->flags &= ~FBINFO_MISC_USEREVENT;
  954. release_console_sem();
  955. unlock_fb_info(info);
  956. break;
  957. default:
  958. if (!lock_fb_info(info))
  959. return -ENODEV;
  960. fb = info->fbops;
  961. if (fb->fb_ioctl)
  962. ret = fb->fb_ioctl(info, cmd, arg);
  963. else
  964. ret = -ENOTTY;
  965. unlock_fb_info(info);
  966. }
  967. return ret;
  968. }
  969. static long fb_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  970. {
  971. struct inode *inode = file->f_path.dentry->d_inode;
  972. int fbidx = iminor(inode);
  973. struct fb_info *info = registered_fb[fbidx];
  974. return do_fb_ioctl(info, cmd, arg);
  975. }
  976. #ifdef CONFIG_COMPAT
  977. struct fb_fix_screeninfo32 {
  978. char id[16];
  979. compat_caddr_t smem_start;
  980. u32 smem_len;
  981. u32 type;
  982. u32 type_aux;
  983. u32 visual;
  984. u16 xpanstep;
  985. u16 ypanstep;
  986. u16 ywrapstep;
  987. u32 line_length;
  988. compat_caddr_t mmio_start;
  989. u32 mmio_len;
  990. u32 accel;
  991. u16 reserved[3];
  992. };
  993. struct fb_cmap32 {
  994. u32 start;
  995. u32 len;
  996. compat_caddr_t red;
  997. compat_caddr_t green;
  998. compat_caddr_t blue;
  999. compat_caddr_t transp;
  1000. };
  1001. static int fb_getput_cmap(struct fb_info *info, unsigned int cmd,
  1002. unsigned long arg)
  1003. {
  1004. struct fb_cmap_user __user *cmap;
  1005. struct fb_cmap32 __user *cmap32;
  1006. __u32 data;
  1007. int err;
  1008. cmap = compat_alloc_user_space(sizeof(*cmap));
  1009. cmap32 = compat_ptr(arg);
  1010. if (copy_in_user(&cmap->start, &cmap32->start, 2 * sizeof(__u32)))
  1011. return -EFAULT;
  1012. if (get_user(data, &cmap32->red) ||
  1013. put_user(compat_ptr(data), &cmap->red) ||
  1014. get_user(data, &cmap32->green) ||
  1015. put_user(compat_ptr(data), &cmap->green) ||
  1016. get_user(data, &cmap32->blue) ||
  1017. put_user(compat_ptr(data), &cmap->blue) ||
  1018. get_user(data, &cmap32->transp) ||
  1019. put_user(compat_ptr(data), &cmap->transp))
  1020. return -EFAULT;
  1021. err = do_fb_ioctl(info, cmd, (unsigned long) cmap);
  1022. if (!err) {
  1023. if (copy_in_user(&cmap32->start,
  1024. &cmap->start,
  1025. 2 * sizeof(__u32)))
  1026. err = -EFAULT;
  1027. }
  1028. return err;
  1029. }
  1030. static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
  1031. struct fb_fix_screeninfo32 __user *fix32)
  1032. {
  1033. __u32 data;
  1034. int err;
  1035. err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
  1036. data = (__u32) (unsigned long) fix->smem_start;
  1037. err |= put_user(data, &fix32->smem_start);
  1038. err |= put_user(fix->smem_len, &fix32->smem_len);
  1039. err |= put_user(fix->type, &fix32->type);
  1040. err |= put_user(fix->type_aux, &fix32->type_aux);
  1041. err |= put_user(fix->visual, &fix32->visual);
  1042. err |= put_user(fix->xpanstep, &fix32->xpanstep);
  1043. err |= put_user(fix->ypanstep, &fix32->ypanstep);
  1044. err |= put_user(fix->ywrapstep, &fix32->ywrapstep);
  1045. err |= put_user(fix->line_length, &fix32->line_length);
  1046. data = (__u32) (unsigned long) fix->mmio_start;
  1047. err |= put_user(data, &fix32->mmio_start);
  1048. err |= put_user(fix->mmio_len, &fix32->mmio_len);
  1049. err |= put_user(fix->accel, &fix32->accel);
  1050. err |= copy_to_user(fix32->reserved, fix->reserved,
  1051. sizeof(fix->reserved));
  1052. return err;
  1053. }
  1054. static int fb_get_fscreeninfo(struct fb_info *info, unsigned int cmd,
  1055. unsigned long arg)
  1056. {
  1057. mm_segment_t old_fs;
  1058. struct fb_fix_screeninfo fix;
  1059. struct fb_fix_screeninfo32 __user *fix32;
  1060. int err;
  1061. fix32 = compat_ptr(arg);
  1062. old_fs = get_fs();
  1063. set_fs(KERNEL_DS);
  1064. err = do_fb_ioctl(info, cmd, (unsigned long) &fix);
  1065. set_fs(old_fs);
  1066. if (!err)
  1067. err = do_fscreeninfo_to_user(&fix, fix32);
  1068. return err;
  1069. }
  1070. static long fb_compat_ioctl(struct file *file, unsigned int cmd,
  1071. unsigned long arg)
  1072. {
  1073. struct inode *inode = file->f_path.dentry->d_inode;
  1074. int fbidx = iminor(inode);
  1075. struct fb_info *info = registered_fb[fbidx];
  1076. struct fb_ops *fb = info->fbops;
  1077. long ret = -ENOIOCTLCMD;
  1078. switch(cmd) {
  1079. case FBIOGET_VSCREENINFO:
  1080. case FBIOPUT_VSCREENINFO:
  1081. case FBIOPAN_DISPLAY:
  1082. case FBIOGET_CON2FBMAP:
  1083. case FBIOPUT_CON2FBMAP:
  1084. arg = (unsigned long) compat_ptr(arg);
  1085. case FBIOBLANK:
  1086. ret = do_fb_ioctl(info, cmd, arg);
  1087. break;
  1088. case FBIOGET_FSCREENINFO:
  1089. ret = fb_get_fscreeninfo(info, cmd, arg);
  1090. break;
  1091. case FBIOGETCMAP:
  1092. case FBIOPUTCMAP:
  1093. ret = fb_getput_cmap(info, cmd, arg);
  1094. break;
  1095. default:
  1096. if (fb->fb_compat_ioctl)
  1097. ret = fb->fb_compat_ioctl(info, cmd, arg);
  1098. break;
  1099. }
  1100. return ret;
  1101. }
  1102. #endif
  1103. static int
  1104. fb_mmap(struct file *file, struct vm_area_struct * vma)
  1105. __acquires(&info->lock)
  1106. __releases(&info->lock)
  1107. {
  1108. int fbidx = iminor(file->f_path.dentry->d_inode);
  1109. struct fb_info *info = registered_fb[fbidx];
  1110. struct fb_ops *fb = info->fbops;
  1111. unsigned long off;
  1112. unsigned long start;
  1113. u32 len;
  1114. if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT))
  1115. return -EINVAL;
  1116. off = vma->vm_pgoff << PAGE_SHIFT;
  1117. if (!fb)
  1118. return -ENODEV;
  1119. if (fb->fb_mmap) {
  1120. int res;
  1121. mutex_lock(&info->lock);
  1122. res = fb->fb_mmap(info, vma);
  1123. mutex_unlock(&info->lock);
  1124. return res;
  1125. }
  1126. mutex_lock(&info->lock);
  1127. /* frame buffer memory */
  1128. start = info->fix.smem_start;
  1129. len = PAGE_ALIGN((start & ~PAGE_MASK) + info->fix.smem_len);
  1130. if (off >= len) {
  1131. /* memory mapped io */
  1132. off -= len;
  1133. if (info->var.accel_flags) {
  1134. mutex_unlock(&info->lock);
  1135. return -EINVAL;
  1136. }
  1137. start = info->fix.mmio_start;
  1138. len = PAGE_ALIGN((start & ~PAGE_MASK) + info->fix.mmio_len);
  1139. }
  1140. mutex_unlock(&info->lock);
  1141. start &= PAGE_MASK;
  1142. if ((vma->vm_end - vma->vm_start + off) > len)
  1143. return -EINVAL;
  1144. off += start;
  1145. vma->vm_pgoff = off >> PAGE_SHIFT;
  1146. /* This is an IO map - tell maydump to skip this VMA */
  1147. vma->vm_flags |= VM_IO | VM_RESERVED;
  1148. fb_pgprotect(file, vma, off);
  1149. if (io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT,
  1150. vma->vm_end - vma->vm_start, vma->vm_page_prot))
  1151. return -EAGAIN;
  1152. return 0;
  1153. }
  1154. static int
  1155. fb_open(struct inode *inode, struct file *file)
  1156. __acquires(&info->lock)
  1157. __releases(&info->lock)
  1158. {
  1159. int fbidx = iminor(inode);
  1160. struct fb_info *info;
  1161. int res = 0;
  1162. if (fbidx >= FB_MAX)
  1163. return -ENODEV;
  1164. info = registered_fb[fbidx];
  1165. if (!info)
  1166. request_module("fb%d", fbidx);
  1167. info = registered_fb[fbidx];
  1168. if (!info)
  1169. return -ENODEV;
  1170. mutex_lock(&info->lock);
  1171. if (!try_module_get(info->fbops->owner)) {
  1172. res = -ENODEV;
  1173. goto out;
  1174. }
  1175. file->private_data = info;
  1176. if (info->fbops->fb_open) {
  1177. res = info->fbops->fb_open(info,1);
  1178. if (res)
  1179. module_put(info->fbops->owner);
  1180. }
  1181. #ifdef CONFIG_FB_DEFERRED_IO
  1182. if (info->fbdefio)
  1183. fb_deferred_io_open(info, inode, file);
  1184. #endif
  1185. out:
  1186. mutex_unlock(&info->lock);
  1187. return res;
  1188. }
  1189. static int
  1190. fb_release(struct inode *inode, struct file *file)
  1191. __acquires(&info->lock)
  1192. __releases(&info->lock)
  1193. {
  1194. struct fb_info * const info = file->private_data;
  1195. mutex_lock(&info->lock);
  1196. if (info->fbops->fb_release)
  1197. info->fbops->fb_release(info,1);
  1198. module_put(info->fbops->owner);
  1199. mutex_unlock(&info->lock);
  1200. return 0;
  1201. }
  1202. static const struct file_operations fb_fops = {
  1203. .owner = THIS_MODULE,
  1204. .read = fb_read,
  1205. .write = fb_write,
  1206. .unlocked_ioctl = fb_ioctl,
  1207. #ifdef CONFIG_COMPAT
  1208. .compat_ioctl = fb_compat_ioctl,
  1209. #endif
  1210. .mmap = fb_mmap,
  1211. .open = fb_open,
  1212. .release = fb_release,
  1213. #ifdef HAVE_ARCH_FB_UNMAPPED_AREA
  1214. .get_unmapped_area = get_fb_unmapped_area,
  1215. #endif
  1216. #ifdef CONFIG_FB_DEFERRED_IO
  1217. .fsync = fb_deferred_io_fsync,
  1218. #endif
  1219. };
  1220. struct class *fb_class;
  1221. EXPORT_SYMBOL(fb_class);
  1222. static int fb_check_foreignness(struct fb_info *fi)
  1223. {
  1224. const bool foreign_endian = fi->flags & FBINFO_FOREIGN_ENDIAN;
  1225. fi->flags &= ~FBINFO_FOREIGN_ENDIAN;
  1226. #ifdef __BIG_ENDIAN
  1227. fi->flags |= foreign_endian ? 0 : FBINFO_BE_MATH;
  1228. #else
  1229. fi->flags |= foreign_endian ? FBINFO_BE_MATH : 0;
  1230. #endif /* __BIG_ENDIAN */
  1231. if (fi->flags & FBINFO_BE_MATH && !fb_be_math(fi)) {
  1232. pr_err("%s: enable CONFIG_FB_BIG_ENDIAN to "
  1233. "support this framebuffer\n", fi->fix.id);
  1234. return -ENOSYS;
  1235. } else if (!(fi->flags & FBINFO_BE_MATH) && fb_be_math(fi)) {
  1236. pr_err("%s: enable CONFIG_FB_LITTLE_ENDIAN to "
  1237. "support this framebuffer\n", fi->fix.id);
  1238. return -ENOSYS;
  1239. }
  1240. return 0;
  1241. }
  1242. static bool fb_do_apertures_overlap(struct fb_info *gen, struct fb_info *hw)
  1243. {
  1244. /* is the generic aperture base the same as the HW one */
  1245. if (gen->aperture_base == hw->aperture_base)
  1246. return true;
  1247. /* is the generic aperture base inside the hw base->hw base+size */
  1248. if (gen->aperture_base > hw->aperture_base && gen->aperture_base <= hw->aperture_base + hw->aperture_size)
  1249. return true;
  1250. return false;
  1251. }
  1252. /**
  1253. * register_framebuffer - registers a frame buffer device
  1254. * @fb_info: frame buffer info structure
  1255. *
  1256. * Registers a frame buffer device @fb_info.
  1257. *
  1258. * Returns negative errno on error, or zero for success.
  1259. *
  1260. */
  1261. int
  1262. register_framebuffer(struct fb_info *fb_info)
  1263. {
  1264. int i;
  1265. struct fb_event event;
  1266. struct fb_videomode mode;
  1267. if (num_registered_fb == FB_MAX)
  1268. return -ENXIO;
  1269. if (fb_check_foreignness(fb_info))
  1270. return -ENOSYS;
  1271. /* check all firmware fbs and kick off if the base addr overlaps */
  1272. for (i = 0 ; i < FB_MAX; i++) {
  1273. if (!registered_fb[i])
  1274. continue;
  1275. if (registered_fb[i]->flags & FBINFO_MISC_FIRMWARE) {
  1276. if (fb_do_apertures_overlap(registered_fb[i], fb_info)) {
  1277. printk(KERN_ERR "fb: conflicting fb hw usage "
  1278. "%s vs %s - removing generic driver\n",
  1279. fb_info->fix.id,
  1280. registered_fb[i]->fix.id);
  1281. unregister_framebuffer(registered_fb[i]);
  1282. break;
  1283. }
  1284. }
  1285. }
  1286. num_registered_fb++;
  1287. for (i = 0 ; i < FB_MAX; i++)
  1288. if (!registered_fb[i])
  1289. break;
  1290. fb_info->node = i;
  1291. mutex_init(&fb_info->lock);
  1292. fb_info->dev = device_create(fb_class, fb_info->device,
  1293. MKDEV(FB_MAJOR, i), NULL, "fb%d", i);
  1294. if (IS_ERR(fb_info->dev)) {
  1295. /* Not fatal */
  1296. printk(KERN_WARNING "Unable to create device for framebuffer %d; errno = %ld\n", i, PTR_ERR(fb_info->dev));
  1297. fb_info->dev = NULL;
  1298. } else
  1299. fb_init_device(fb_info);
  1300. if (fb_info->pixmap.addr == NULL) {
  1301. fb_info->pixmap.addr = kmalloc(FBPIXMAPSIZE, GFP_KERNEL);
  1302. if (fb_info->pixmap.addr) {
  1303. fb_info->pixmap.size = FBPIXMAPSIZE;
  1304. fb_info->pixmap.buf_align = 1;
  1305. fb_info->pixmap.scan_align = 1;
  1306. fb_info->pixmap.access_align = 32;
  1307. fb_info->pixmap.flags = FB_PIXMAP_DEFAULT;
  1308. }
  1309. }
  1310. fb_info->pixmap.offset = 0;
  1311. if (!fb_info->pixmap.blit_x)
  1312. fb_info->pixmap.blit_x = ~(u32)0;
  1313. if (!fb_info->pixmap.blit_y)
  1314. fb_info->pixmap.blit_y = ~(u32)0;
  1315. if (!fb_info->modelist.prev || !fb_info->modelist.next)
  1316. INIT_LIST_HEAD(&fb_info->modelist);
  1317. fb_var_to_videomode(&mode, &fb_info->var);
  1318. fb_add_videomode(&mode, &fb_info->modelist);
  1319. registered_fb[i] = fb_info;
  1320. event.info = fb_info;
  1321. if (!lock_fb_info(fb_info))
  1322. return -ENODEV;
  1323. fb_notifier_call_chain(FB_EVENT_FB_REGISTERED, &event);
  1324. unlock_fb_info(fb_info);
  1325. return 0;
  1326. }
  1327. /**
  1328. * unregister_framebuffer - releases a frame buffer device
  1329. * @fb_info: frame buffer info structure
  1330. *
  1331. * Unregisters a frame buffer device @fb_info.
  1332. *
  1333. * Returns negative errno on error, or zero for success.
  1334. *
  1335. * This function will also notify the framebuffer console
  1336. * to release the driver.
  1337. *
  1338. * This is meant to be called within a driver's module_exit()
  1339. * function. If this is called outside module_exit(), ensure
  1340. * that the driver implements fb_open() and fb_release() to
  1341. * check that no processes are using the device.
  1342. */
  1343. int
  1344. unregister_framebuffer(struct fb_info *fb_info)
  1345. {
  1346. struct fb_event event;
  1347. int i, ret = 0;
  1348. i = fb_info->node;
  1349. if (!registered_fb[i]) {
  1350. ret = -EINVAL;
  1351. goto done;
  1352. }
  1353. if (!lock_fb_info(fb_info))
  1354. return -ENODEV;
  1355. event.info = fb_info;
  1356. ret = fb_notifier_call_chain(FB_EVENT_FB_UNBIND, &event);
  1357. unlock_fb_info(fb_info);
  1358. if (ret) {
  1359. ret = -EINVAL;
  1360. goto done;
  1361. }
  1362. if (fb_info->pixmap.addr &&
  1363. (fb_info->pixmap.flags & FB_PIXMAP_DEFAULT))
  1364. kfree(fb_info->pixmap.addr);
  1365. fb_destroy_modelist(&fb_info->modelist);
  1366. registered_fb[i]=NULL;
  1367. num_registered_fb--;
  1368. fb_cleanup_device(fb_info);
  1369. device_destroy(fb_class, MKDEV(FB_MAJOR, i));
  1370. event.info = fb_info;
  1371. fb_notifier_call_chain(FB_EVENT_FB_UNREGISTERED, &event);
  1372. /* this may free fb info */
  1373. if (fb_info->fbops->fb_destroy)
  1374. fb_info->fbops->fb_destroy(fb_info);
  1375. done:
  1376. return ret;
  1377. }
  1378. /**
  1379. * fb_set_suspend - low level driver signals suspend
  1380. * @info: framebuffer affected
  1381. * @state: 0 = resuming, !=0 = suspending
  1382. *
  1383. * This is meant to be used by low level drivers to
  1384. * signal suspend/resume to the core & clients.
  1385. * It must be called with the console semaphore held
  1386. */
  1387. void fb_set_suspend(struct fb_info *info, int state)
  1388. {
  1389. struct fb_event event;
  1390. if (!lock_fb_info(info))
  1391. return;
  1392. event.info = info;
  1393. if (state) {
  1394. fb_notifier_call_chain(FB_EVENT_SUSPEND, &event);
  1395. info->state = FBINFO_STATE_SUSPENDED;
  1396. } else {
  1397. info->state = FBINFO_STATE_RUNNING;
  1398. fb_notifier_call_chain(FB_EVENT_RESUME, &event);
  1399. }
  1400. unlock_fb_info(info);
  1401. }
  1402. /**
  1403. * fbmem_init - init frame buffer subsystem
  1404. *
  1405. * Initialize the frame buffer subsystem.
  1406. *
  1407. * NOTE: This function is _only_ to be called by drivers/char/mem.c.
  1408. *
  1409. */
  1410. static int __init
  1411. fbmem_init(void)
  1412. {
  1413. proc_create("fb", 0, NULL, &fb_proc_fops);
  1414. if (register_chrdev(FB_MAJOR,"fb",&fb_fops))
  1415. printk("unable to get major %d for fb devs\n", FB_MAJOR);
  1416. fb_class = class_create(THIS_MODULE, "graphics");
  1417. if (IS_ERR(fb_class)) {
  1418. printk(KERN_WARNING "Unable to create fb class; errno = %ld\n", PTR_ERR(fb_class));
  1419. fb_class = NULL;
  1420. }
  1421. return 0;
  1422. }
  1423. #ifdef MODULE
  1424. module_init(fbmem_init);
  1425. static void __exit
  1426. fbmem_exit(void)
  1427. {
  1428. remove_proc_entry("fb", NULL);
  1429. class_destroy(fb_class);
  1430. unregister_chrdev(FB_MAJOR, "fb");
  1431. }
  1432. module_exit(fbmem_exit);
  1433. MODULE_LICENSE("GPL");
  1434. MODULE_DESCRIPTION("Framebuffer base");
  1435. #else
  1436. subsys_initcall(fbmem_init);
  1437. #endif
  1438. int fb_new_modelist(struct fb_info *info)
  1439. {
  1440. struct fb_event event;
  1441. struct fb_var_screeninfo var = info->var;
  1442. struct list_head *pos, *n;
  1443. struct fb_modelist *modelist;
  1444. struct fb_videomode *m, mode;
  1445. int err = 1;
  1446. list_for_each_safe(pos, n, &info->modelist) {
  1447. modelist = list_entry(pos, struct fb_modelist, list);
  1448. m = &modelist->mode;
  1449. fb_videomode_to_var(&var, m);
  1450. var.activate = FB_ACTIVATE_TEST;
  1451. err = fb_set_var(info, &var);
  1452. fb_var_to_videomode(&mode, &var);
  1453. if (err || !fb_mode_is_equal(m, &mode)) {
  1454. list_del(pos);
  1455. kfree(pos);
  1456. }
  1457. }
  1458. err = 1;
  1459. if (!list_empty(&info->modelist)) {
  1460. if (!lock_fb_info(info))
  1461. return -ENODEV;
  1462. event.info = info;
  1463. err = fb_notifier_call_chain(FB_EVENT_NEW_MODELIST, &event);
  1464. unlock_fb_info(info);
  1465. }
  1466. return err;
  1467. }
  1468. static char *video_options[FB_MAX] __read_mostly;
  1469. static int ofonly __read_mostly;
  1470. /**
  1471. * fb_get_options - get kernel boot parameters
  1472. * @name: framebuffer name as it would appear in
  1473. * the boot parameter line
  1474. * (video=<name>:<options>)
  1475. * @option: the option will be stored here
  1476. *
  1477. * NOTE: Needed to maintain backwards compatibility
  1478. */
  1479. int fb_get_options(char *name, char **option)
  1480. {
  1481. char *opt, *options = NULL;
  1482. int opt_len, retval = 0;
  1483. int name_len = strlen(name), i;
  1484. if (name_len && ofonly && strncmp(name, "offb", 4))
  1485. retval = 1;
  1486. if (name_len && !retval) {
  1487. for (i = 0; i < FB_MAX; i++) {
  1488. if (video_options[i] == NULL)
  1489. continue;
  1490. opt_len = strlen(video_options[i]);
  1491. if (!opt_len)
  1492. continue;
  1493. opt = video_options[i];
  1494. if (!strncmp(name, opt, name_len) &&
  1495. opt[name_len] == ':')
  1496. options = opt + name_len + 1;
  1497. }
  1498. }
  1499. if (options && !strncmp(options, "off", 3))
  1500. retval = 1;
  1501. if (option)
  1502. *option = options;
  1503. return retval;
  1504. }
  1505. #ifndef MODULE
  1506. /**
  1507. * video_setup - process command line options
  1508. * @options: string of options
  1509. *
  1510. * Process command line options for frame buffer subsystem.
  1511. *
  1512. * NOTE: This function is a __setup and __init function.
  1513. * It only stores the options. Drivers have to call
  1514. * fb_get_options() as necessary.
  1515. *
  1516. * Returns zero.
  1517. *
  1518. */
  1519. static int __init video_setup(char *options)
  1520. {
  1521. int i, global = 0;
  1522. if (!options || !*options)
  1523. global = 1;
  1524. if (!global && !strncmp(options, "ofonly", 6)) {
  1525. ofonly = 1;
  1526. global = 1;
  1527. }
  1528. if (!global && !strstr(options, "fb:")) {
  1529. fb_mode_option = options;
  1530. global = 1;
  1531. }
  1532. if (!global) {
  1533. for (i = 0; i < FB_MAX; i++) {
  1534. if (video_options[i] == NULL) {
  1535. video_options[i] = options;
  1536. break;
  1537. }
  1538. }
  1539. }
  1540. return 1;
  1541. }
  1542. __setup("video=", video_setup);
  1543. #endif
  1544. /*
  1545. * Visible symbols for modules
  1546. */
  1547. EXPORT_SYMBOL(register_framebuffer);
  1548. EXPORT_SYMBOL(unregister_framebuffer);
  1549. EXPORT_SYMBOL(num_registered_fb);
  1550. EXPORT_SYMBOL(registered_fb);
  1551. EXPORT_SYMBOL(fb_show_logo);
  1552. EXPORT_SYMBOL(fb_set_var);
  1553. EXPORT_SYMBOL(fb_blank);
  1554. EXPORT_SYMBOL(fb_pan_display);
  1555. EXPORT_SYMBOL(fb_get_buffer_offset);
  1556. EXPORT_SYMBOL(fb_set_suspend);
  1557. EXPORT_SYMBOL(fb_get_options);
  1558. MODULE_LICENSE("GPL");