fbmem.c 35 KB

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