fbmem.c 39 KB

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