fbmem.c 39 KB

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