fbmem.c 40 KB

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