fbmem.c 37 KB

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