fbmem.c 33 KB

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