fbmem.c 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984
  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/kernel.h>
  18. #include <linux/major.h>
  19. #include <linux/slab.h>
  20. #include <linux/mm.h>
  21. #include <linux/mman.h>
  22. #include <linux/vt.h>
  23. #include <linux/init.h>
  24. #include <linux/linux_logo.h>
  25. #include <linux/proc_fs.h>
  26. #include <linux/seq_file.h>
  27. #include <linux/console.h>
  28. #include <linux/kmod.h>
  29. #include <linux/err.h>
  30. #include <linux/device.h>
  31. #include <linux/efi.h>
  32. #include <linux/fb.h>
  33. #include <linux/fbcon.h>
  34. #include <linux/mem_encrypt.h>
  35. #include <asm/fb.h>
  36. /*
  37. * Frame buffer device initialization and setup routines
  38. */
  39. #define FBPIXMAPSIZE (1024 * 8)
  40. static DEFINE_MUTEX(registration_lock);
  41. struct fb_info *registered_fb[FB_MAX] __read_mostly;
  42. EXPORT_SYMBOL(registered_fb);
  43. int num_registered_fb __read_mostly;
  44. EXPORT_SYMBOL(num_registered_fb);
  45. static struct fb_info *get_fb_info(unsigned int idx)
  46. {
  47. struct fb_info *fb_info;
  48. if (idx >= FB_MAX)
  49. return ERR_PTR(-ENODEV);
  50. mutex_lock(&registration_lock);
  51. fb_info = registered_fb[idx];
  52. if (fb_info)
  53. atomic_inc(&fb_info->count);
  54. mutex_unlock(&registration_lock);
  55. return fb_info;
  56. }
  57. static void put_fb_info(struct fb_info *fb_info)
  58. {
  59. if (!atomic_dec_and_test(&fb_info->count))
  60. return;
  61. if (fb_info->fbops->fb_destroy)
  62. fb_info->fbops->fb_destroy(fb_info);
  63. }
  64. int lock_fb_info(struct fb_info *info)
  65. {
  66. mutex_lock(&info->lock);
  67. if (!info->fbops) {
  68. mutex_unlock(&info->lock);
  69. return 0;
  70. }
  71. return 1;
  72. }
  73. EXPORT_SYMBOL(lock_fb_info);
  74. /*
  75. * Helpers
  76. */
  77. int fb_get_color_depth(struct fb_var_screeninfo *var,
  78. struct fb_fix_screeninfo *fix)
  79. {
  80. int depth = 0;
  81. if (fix->visual == FB_VISUAL_MONO01 ||
  82. fix->visual == FB_VISUAL_MONO10)
  83. depth = 1;
  84. else {
  85. if (var->green.length == var->blue.length &&
  86. var->green.length == var->red.length &&
  87. var->green.offset == var->blue.offset &&
  88. var->green.offset == var->red.offset)
  89. depth = var->green.length;
  90. else
  91. depth = var->green.length + var->red.length +
  92. var->blue.length;
  93. }
  94. return depth;
  95. }
  96. EXPORT_SYMBOL(fb_get_color_depth);
  97. /*
  98. * Data padding functions.
  99. */
  100. void fb_pad_aligned_buffer(u8 *dst, u32 d_pitch, u8 *src, u32 s_pitch, u32 height)
  101. {
  102. __fb_pad_aligned_buffer(dst, d_pitch, src, s_pitch, height);
  103. }
  104. EXPORT_SYMBOL(fb_pad_aligned_buffer);
  105. void fb_pad_unaligned_buffer(u8 *dst, u32 d_pitch, u8 *src, u32 idx, u32 height,
  106. u32 shift_high, u32 shift_low, u32 mod)
  107. {
  108. u8 mask = (u8) (0xfff << shift_high), tmp;
  109. int i, j;
  110. for (i = height; i--; ) {
  111. for (j = 0; j < idx; j++) {
  112. tmp = dst[j];
  113. tmp &= mask;
  114. tmp |= *src >> shift_low;
  115. dst[j] = tmp;
  116. tmp = *src << shift_high;
  117. dst[j+1] = tmp;
  118. src++;
  119. }
  120. tmp = dst[idx];
  121. tmp &= mask;
  122. tmp |= *src >> shift_low;
  123. dst[idx] = tmp;
  124. if (shift_high < mod) {
  125. tmp = *src << shift_high;
  126. dst[idx+1] = tmp;
  127. }
  128. src++;
  129. dst += d_pitch;
  130. }
  131. }
  132. EXPORT_SYMBOL(fb_pad_unaligned_buffer);
  133. /*
  134. * we need to lock this section since fb_cursor
  135. * may use fb_imageblit()
  136. */
  137. char* fb_get_buffer_offset(struct fb_info *info, struct fb_pixmap *buf, u32 size)
  138. {
  139. u32 align = buf->buf_align - 1, offset;
  140. char *addr = buf->addr;
  141. /* If IO mapped, we need to sync before access, no sharing of
  142. * the pixmap is done
  143. */
  144. if (buf->flags & FB_PIXMAP_IO) {
  145. if (info->fbops->fb_sync && (buf->flags & FB_PIXMAP_SYNC))
  146. info->fbops->fb_sync(info);
  147. return addr;
  148. }
  149. /* See if we fit in the remaining pixmap space */
  150. offset = buf->offset + align;
  151. offset &= ~align;
  152. if (offset + size > buf->size) {
  153. /* We do not fit. In order to be able to re-use the buffer,
  154. * we must ensure no asynchronous DMA'ing or whatever operation
  155. * is in progress, we sync for that.
  156. */
  157. if (info->fbops->fb_sync && (buf->flags & FB_PIXMAP_SYNC))
  158. info->fbops->fb_sync(info);
  159. offset = 0;
  160. }
  161. buf->offset = offset + size;
  162. addr += offset;
  163. return addr;
  164. }
  165. EXPORT_SYMBOL(fb_get_buffer_offset);
  166. #ifdef CONFIG_LOGO
  167. static inline unsigned safe_shift(unsigned d, int n)
  168. {
  169. return n < 0 ? d >> -n : d << n;
  170. }
  171. static void fb_set_logocmap(struct fb_info *info,
  172. const struct linux_logo *logo)
  173. {
  174. struct fb_cmap palette_cmap;
  175. u16 palette_green[16];
  176. u16 palette_blue[16];
  177. u16 palette_red[16];
  178. int i, j, n;
  179. const unsigned char *clut = logo->clut;
  180. palette_cmap.start = 0;
  181. palette_cmap.len = 16;
  182. palette_cmap.red = palette_red;
  183. palette_cmap.green = palette_green;
  184. palette_cmap.blue = palette_blue;
  185. palette_cmap.transp = NULL;
  186. for (i = 0; i < logo->clutsize; i += n) {
  187. n = logo->clutsize - i;
  188. /* palette_cmap provides space for only 16 colors at once */
  189. if (n > 16)
  190. n = 16;
  191. palette_cmap.start = 32 + i;
  192. palette_cmap.len = n;
  193. for (j = 0; j < n; ++j) {
  194. palette_cmap.red[j] = clut[0] << 8 | clut[0];
  195. palette_cmap.green[j] = clut[1] << 8 | clut[1];
  196. palette_cmap.blue[j] = clut[2] << 8 | clut[2];
  197. clut += 3;
  198. }
  199. fb_set_cmap(&palette_cmap, info);
  200. }
  201. }
  202. static void fb_set_logo_truepalette(struct fb_info *info,
  203. const struct linux_logo *logo,
  204. u32 *palette)
  205. {
  206. static const unsigned char mask[] = { 0,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff };
  207. unsigned char redmask, greenmask, bluemask;
  208. int redshift, greenshift, blueshift;
  209. int i;
  210. const unsigned char *clut = logo->clut;
  211. /*
  212. * We have to create a temporary palette since console palette is only
  213. * 16 colors long.
  214. */
  215. /* Bug: Doesn't obey msb_right ... (who needs that?) */
  216. redmask = mask[info->var.red.length < 8 ? info->var.red.length : 8];
  217. greenmask = mask[info->var.green.length < 8 ? info->var.green.length : 8];
  218. bluemask = mask[info->var.blue.length < 8 ? info->var.blue.length : 8];
  219. redshift = info->var.red.offset - (8 - info->var.red.length);
  220. greenshift = info->var.green.offset - (8 - info->var.green.length);
  221. blueshift = info->var.blue.offset - (8 - info->var.blue.length);
  222. for ( i = 0; i < logo->clutsize; i++) {
  223. palette[i+32] = (safe_shift((clut[0] & redmask), redshift) |
  224. safe_shift((clut[1] & greenmask), greenshift) |
  225. safe_shift((clut[2] & bluemask), blueshift));
  226. clut += 3;
  227. }
  228. }
  229. static void fb_set_logo_directpalette(struct fb_info *info,
  230. const struct linux_logo *logo,
  231. u32 *palette)
  232. {
  233. int redshift, greenshift, blueshift;
  234. int i;
  235. redshift = info->var.red.offset;
  236. greenshift = info->var.green.offset;
  237. blueshift = info->var.blue.offset;
  238. for (i = 32; i < 32 + logo->clutsize; i++)
  239. palette[i] = i << redshift | i << greenshift | i << blueshift;
  240. }
  241. static void fb_set_logo(struct fb_info *info,
  242. const struct linux_logo *logo, u8 *dst,
  243. int depth)
  244. {
  245. int i, j, k;
  246. const u8 *src = logo->data;
  247. u8 xor = (info->fix.visual == FB_VISUAL_MONO01) ? 0xff : 0;
  248. u8 fg = 1, d;
  249. switch (fb_get_color_depth(&info->var, &info->fix)) {
  250. case 1:
  251. fg = 1;
  252. break;
  253. case 2:
  254. fg = 3;
  255. break;
  256. default:
  257. fg = 7;
  258. break;
  259. }
  260. if (info->fix.visual == FB_VISUAL_MONO01 ||
  261. info->fix.visual == FB_VISUAL_MONO10)
  262. fg = ~((u8) (0xfff << info->var.green.length));
  263. switch (depth) {
  264. case 4:
  265. for (i = 0; i < logo->height; i++)
  266. for (j = 0; j < logo->width; src++) {
  267. *dst++ = *src >> 4;
  268. j++;
  269. if (j < logo->width) {
  270. *dst++ = *src & 0x0f;
  271. j++;
  272. }
  273. }
  274. break;
  275. case 1:
  276. for (i = 0; i < logo->height; i++) {
  277. for (j = 0; j < logo->width; src++) {
  278. d = *src ^ xor;
  279. for (k = 7; k >= 0 && j < logo->width; k--) {
  280. *dst++ = ((d >> k) & 1) ? fg : 0;
  281. j++;
  282. }
  283. }
  284. }
  285. break;
  286. }
  287. }
  288. /*
  289. * Three (3) kinds of logo maps exist. linux_logo_clut224 (>16 colors),
  290. * linux_logo_vga16 (16 colors) and linux_logo_mono (2 colors). Depending on
  291. * the visual format and color depth of the framebuffer, the DAC, the
  292. * pseudo_palette, and the logo data will be adjusted accordingly.
  293. *
  294. * Case 1 - linux_logo_clut224:
  295. * Color exceeds the number of console colors (16), thus we set the hardware DAC
  296. * using fb_set_cmap() appropriately. The "needs_cmapreset" flag will be set.
  297. *
  298. * For visuals that require color info from the pseudo_palette, we also construct
  299. * one for temporary use. The "needs_directpalette" or "needs_truepalette" flags
  300. * will be set.
  301. *
  302. * Case 2 - linux_logo_vga16:
  303. * The number of colors just matches the console colors, thus there is no need
  304. * to set the DAC or the pseudo_palette. However, the bitmap is packed, ie,
  305. * each byte contains color information for two pixels (upper and lower nibble).
  306. * To be consistent with fb_imageblit() usage, we therefore separate the two
  307. * nibbles into separate bytes. The "depth" flag will be set to 4.
  308. *
  309. * Case 3 - linux_logo_mono:
  310. * This is similar with Case 2. Each byte contains information for 8 pixels.
  311. * We isolate each bit and expand each into a byte. The "depth" flag will
  312. * be set to 1.
  313. */
  314. static struct logo_data {
  315. int depth;
  316. int needs_directpalette;
  317. int needs_truepalette;
  318. int needs_cmapreset;
  319. const struct linux_logo *logo;
  320. } fb_logo __read_mostly;
  321. static void fb_rotate_logo_ud(const u8 *in, u8 *out, u32 width, u32 height)
  322. {
  323. u32 size = width * height, i;
  324. out += size - 1;
  325. for (i = size; i--; )
  326. *out-- = *in++;
  327. }
  328. static void fb_rotate_logo_cw(const u8 *in, u8 *out, u32 width, u32 height)
  329. {
  330. int i, j, h = height - 1;
  331. for (i = 0; i < height; i++)
  332. for (j = 0; j < width; j++)
  333. out[height * j + h - i] = *in++;
  334. }
  335. static void fb_rotate_logo_ccw(const u8 *in, u8 *out, u32 width, u32 height)
  336. {
  337. int i, j, w = width - 1;
  338. for (i = 0; i < height; i++)
  339. for (j = 0; j < width; j++)
  340. out[height * (w - j) + i] = *in++;
  341. }
  342. static void fb_rotate_logo(struct fb_info *info, u8 *dst,
  343. struct fb_image *image, int rotate)
  344. {
  345. u32 tmp;
  346. if (rotate == FB_ROTATE_UD) {
  347. fb_rotate_logo_ud(image->data, dst, image->width,
  348. image->height);
  349. image->dx = info->var.xres - image->width - image->dx;
  350. image->dy = info->var.yres - image->height - image->dy;
  351. } else if (rotate == FB_ROTATE_CW) {
  352. fb_rotate_logo_cw(image->data, dst, image->width,
  353. image->height);
  354. tmp = image->width;
  355. image->width = image->height;
  356. image->height = tmp;
  357. tmp = image->dy;
  358. image->dy = image->dx;
  359. image->dx = info->var.xres - image->width - tmp;
  360. } else if (rotate == FB_ROTATE_CCW) {
  361. fb_rotate_logo_ccw(image->data, dst, image->width,
  362. image->height);
  363. tmp = image->width;
  364. image->width = image->height;
  365. image->height = tmp;
  366. tmp = image->dx;
  367. image->dx = image->dy;
  368. image->dy = info->var.yres - image->height - tmp;
  369. }
  370. image->data = dst;
  371. }
  372. static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
  373. int rotate, unsigned int num)
  374. {
  375. unsigned int x;
  376. if (image->width > info->var.xres || image->height > info->var.yres)
  377. return;
  378. if (rotate == FB_ROTATE_UR) {
  379. for (x = 0;
  380. x < num && image->dx + image->width <= info->var.xres;
  381. x++) {
  382. info->fbops->fb_imageblit(info, image);
  383. image->dx += image->width + 8;
  384. }
  385. } else if (rotate == FB_ROTATE_UD) {
  386. u32 dx = image->dx;
  387. for (x = 0; x < num && image->dx <= dx; x++) {
  388. info->fbops->fb_imageblit(info, image);
  389. image->dx -= image->width + 8;
  390. }
  391. } else if (rotate == FB_ROTATE_CW) {
  392. for (x = 0;
  393. x < num && image->dy + image->height <= info->var.yres;
  394. x++) {
  395. info->fbops->fb_imageblit(info, image);
  396. image->dy += image->height + 8;
  397. }
  398. } else if (rotate == FB_ROTATE_CCW) {
  399. u32 dy = image->dy;
  400. for (x = 0; x < num && image->dy <= dy; x++) {
  401. info->fbops->fb_imageblit(info, image);
  402. image->dy -= image->height + 8;
  403. }
  404. }
  405. }
  406. static int fb_show_logo_line(struct fb_info *info, int rotate,
  407. const struct linux_logo *logo, int y,
  408. unsigned int n)
  409. {
  410. u32 *palette = NULL, *saved_pseudo_palette = NULL;
  411. unsigned char *logo_new = NULL, *logo_rotate = NULL;
  412. struct fb_image image;
  413. /* Return if the frame buffer is not mapped or suspended */
  414. if (logo == NULL || info->state != FBINFO_STATE_RUNNING ||
  415. info->fbops->owner)
  416. return 0;
  417. image.depth = 8;
  418. image.data = logo->data;
  419. if (fb_logo.needs_cmapreset)
  420. fb_set_logocmap(info, logo);
  421. if (fb_logo.needs_truepalette ||
  422. fb_logo.needs_directpalette) {
  423. palette = kmalloc(256 * 4, GFP_KERNEL);
  424. if (palette == NULL)
  425. return 0;
  426. if (fb_logo.needs_truepalette)
  427. fb_set_logo_truepalette(info, logo, palette);
  428. else
  429. fb_set_logo_directpalette(info, logo, palette);
  430. saved_pseudo_palette = info->pseudo_palette;
  431. info->pseudo_palette = palette;
  432. }
  433. if (fb_logo.depth <= 4) {
  434. logo_new = kmalloc_array(logo->width, logo->height,
  435. GFP_KERNEL);
  436. if (logo_new == NULL) {
  437. kfree(palette);
  438. if (saved_pseudo_palette)
  439. info->pseudo_palette = saved_pseudo_palette;
  440. return 0;
  441. }
  442. image.data = logo_new;
  443. fb_set_logo(info, logo, logo_new, fb_logo.depth);
  444. }
  445. image.dx = 0;
  446. image.dy = y;
  447. image.width = logo->width;
  448. image.height = logo->height;
  449. if (rotate) {
  450. logo_rotate = kmalloc_array(logo->width, logo->height,
  451. GFP_KERNEL);
  452. if (logo_rotate)
  453. fb_rotate_logo(info, logo_rotate, &image, rotate);
  454. }
  455. fb_do_show_logo(info, &image, rotate, n);
  456. kfree(palette);
  457. if (saved_pseudo_palette != NULL)
  458. info->pseudo_palette = saved_pseudo_palette;
  459. kfree(logo_new);
  460. kfree(logo_rotate);
  461. return logo->height;
  462. }
  463. #ifdef CONFIG_FB_LOGO_EXTRA
  464. #define FB_LOGO_EX_NUM_MAX 10
  465. static struct logo_data_extra {
  466. const struct linux_logo *logo;
  467. unsigned int n;
  468. } fb_logo_ex[FB_LOGO_EX_NUM_MAX];
  469. static unsigned int fb_logo_ex_num;
  470. void fb_append_extra_logo(const struct linux_logo *logo, unsigned int n)
  471. {
  472. if (!n || fb_logo_ex_num == FB_LOGO_EX_NUM_MAX)
  473. return;
  474. fb_logo_ex[fb_logo_ex_num].logo = logo;
  475. fb_logo_ex[fb_logo_ex_num].n = n;
  476. fb_logo_ex_num++;
  477. }
  478. static int fb_prepare_extra_logos(struct fb_info *info, unsigned int height,
  479. unsigned int yres)
  480. {
  481. unsigned int i;
  482. /* FIXME: logo_ex supports only truecolor fb. */
  483. if (info->fix.visual != FB_VISUAL_TRUECOLOR)
  484. fb_logo_ex_num = 0;
  485. for (i = 0; i < fb_logo_ex_num; i++) {
  486. if (fb_logo_ex[i].logo->type != fb_logo.logo->type) {
  487. fb_logo_ex[i].logo = NULL;
  488. continue;
  489. }
  490. height += fb_logo_ex[i].logo->height;
  491. if (height > yres) {
  492. height -= fb_logo_ex[i].logo->height;
  493. fb_logo_ex_num = i;
  494. break;
  495. }
  496. }
  497. return height;
  498. }
  499. static int fb_show_extra_logos(struct fb_info *info, int y, int rotate)
  500. {
  501. unsigned int i;
  502. for (i = 0; i < fb_logo_ex_num; i++)
  503. y += fb_show_logo_line(info, rotate,
  504. fb_logo_ex[i].logo, y, fb_logo_ex[i].n);
  505. return y;
  506. }
  507. #else /* !CONFIG_FB_LOGO_EXTRA */
  508. static inline int fb_prepare_extra_logos(struct fb_info *info,
  509. unsigned int height,
  510. unsigned int yres)
  511. {
  512. return height;
  513. }
  514. static inline int fb_show_extra_logos(struct fb_info *info, int y, int rotate)
  515. {
  516. return y;
  517. }
  518. #endif /* CONFIG_FB_LOGO_EXTRA */
  519. int fb_prepare_logo(struct fb_info *info, int rotate)
  520. {
  521. int depth = fb_get_color_depth(&info->var, &info->fix);
  522. unsigned int yres;
  523. memset(&fb_logo, 0, sizeof(struct logo_data));
  524. if (info->flags & FBINFO_MISC_TILEBLITTING ||
  525. info->fbops->owner)
  526. return 0;
  527. if (info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
  528. depth = info->var.blue.length;
  529. if (info->var.red.length < depth)
  530. depth = info->var.red.length;
  531. if (info->var.green.length < depth)
  532. depth = info->var.green.length;
  533. }
  534. if (info->fix.visual == FB_VISUAL_STATIC_PSEUDOCOLOR && depth > 4) {
  535. /* assume console colormap */
  536. depth = 4;
  537. }
  538. /* Return if no suitable logo was found */
  539. fb_logo.logo = fb_find_logo(depth);
  540. if (!fb_logo.logo) {
  541. return 0;
  542. }
  543. if (rotate == FB_ROTATE_UR || rotate == FB_ROTATE_UD)
  544. yres = info->var.yres;
  545. else
  546. yres = info->var.xres;
  547. if (fb_logo.logo->height > yres) {
  548. fb_logo.logo = NULL;
  549. return 0;
  550. }
  551. /* What depth we asked for might be different from what we get */
  552. if (fb_logo.logo->type == LINUX_LOGO_CLUT224)
  553. fb_logo.depth = 8;
  554. else if (fb_logo.logo->type == LINUX_LOGO_VGA16)
  555. fb_logo.depth = 4;
  556. else
  557. fb_logo.depth = 1;
  558. if (fb_logo.depth > 4 && depth > 4) {
  559. switch (info->fix.visual) {
  560. case FB_VISUAL_TRUECOLOR:
  561. fb_logo.needs_truepalette = 1;
  562. break;
  563. case FB_VISUAL_DIRECTCOLOR:
  564. fb_logo.needs_directpalette = 1;
  565. fb_logo.needs_cmapreset = 1;
  566. break;
  567. case FB_VISUAL_PSEUDOCOLOR:
  568. fb_logo.needs_cmapreset = 1;
  569. break;
  570. }
  571. }
  572. return fb_prepare_extra_logos(info, fb_logo.logo->height, yres);
  573. }
  574. int fb_show_logo(struct fb_info *info, int rotate)
  575. {
  576. int y;
  577. y = fb_show_logo_line(info, rotate, fb_logo.logo, 0,
  578. num_online_cpus());
  579. y = fb_show_extra_logos(info, y, rotate);
  580. return y;
  581. }
  582. #else
  583. int fb_prepare_logo(struct fb_info *info, int rotate) { return 0; }
  584. int fb_show_logo(struct fb_info *info, int rotate) { return 0; }
  585. #endif /* CONFIG_LOGO */
  586. EXPORT_SYMBOL(fb_prepare_logo);
  587. EXPORT_SYMBOL(fb_show_logo);
  588. static void *fb_seq_start(struct seq_file *m, loff_t *pos)
  589. {
  590. mutex_lock(&registration_lock);
  591. return (*pos < FB_MAX) ? pos : NULL;
  592. }
  593. static void *fb_seq_next(struct seq_file *m, void *v, loff_t *pos)
  594. {
  595. (*pos)++;
  596. return (*pos < FB_MAX) ? pos : NULL;
  597. }
  598. static void fb_seq_stop(struct seq_file *m, void *v)
  599. {
  600. mutex_unlock(&registration_lock);
  601. }
  602. static int fb_seq_show(struct seq_file *m, void *v)
  603. {
  604. int i = *(loff_t *)v;
  605. struct fb_info *fi = registered_fb[i];
  606. if (fi)
  607. seq_printf(m, "%d %s\n", fi->node, fi->fix.id);
  608. return 0;
  609. }
  610. static const struct seq_operations proc_fb_seq_ops = {
  611. .start = fb_seq_start,
  612. .next = fb_seq_next,
  613. .stop = fb_seq_stop,
  614. .show = fb_seq_show,
  615. };
  616. /*
  617. * We hold a reference to the fb_info in file->private_data,
  618. * but if the current registered fb has changed, we don't
  619. * actually want to use it.
  620. *
  621. * So look up the fb_info using the inode minor number,
  622. * and just verify it against the reference we have.
  623. */
  624. static struct fb_info *file_fb_info(struct file *file)
  625. {
  626. struct inode *inode = file_inode(file);
  627. int fbidx = iminor(inode);
  628. struct fb_info *info = registered_fb[fbidx];
  629. if (info != file->private_data)
  630. info = NULL;
  631. return info;
  632. }
  633. static ssize_t
  634. fb_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
  635. {
  636. unsigned long p = *ppos;
  637. struct fb_info *info = file_fb_info(file);
  638. u8 *buffer, *dst;
  639. u8 __iomem *src;
  640. int c, cnt = 0, err = 0;
  641. unsigned long total_size;
  642. if (!info || ! info->screen_base)
  643. return -ENODEV;
  644. if (info->state != FBINFO_STATE_RUNNING)
  645. return -EPERM;
  646. if (info->fbops->fb_read)
  647. return info->fbops->fb_read(info, buf, count, ppos);
  648. total_size = info->screen_size;
  649. if (total_size == 0)
  650. total_size = info->fix.smem_len;
  651. if (p >= total_size)
  652. return 0;
  653. if (count >= total_size)
  654. count = total_size;
  655. if (count + p > total_size)
  656. count = total_size - p;
  657. buffer = kmalloc((count > PAGE_SIZE) ? PAGE_SIZE : count,
  658. GFP_KERNEL);
  659. if (!buffer)
  660. return -ENOMEM;
  661. src = (u8 __iomem *) (info->screen_base + p);
  662. if (info->fbops->fb_sync)
  663. info->fbops->fb_sync(info);
  664. while (count) {
  665. c = (count > PAGE_SIZE) ? PAGE_SIZE : count;
  666. dst = buffer;
  667. fb_memcpy_fromfb(dst, src, c);
  668. dst += c;
  669. src += c;
  670. if (copy_to_user(buf, buffer, c)) {
  671. err = -EFAULT;
  672. break;
  673. }
  674. *ppos += c;
  675. buf += c;
  676. cnt += c;
  677. count -= c;
  678. }
  679. kfree(buffer);
  680. return (err) ? err : cnt;
  681. }
  682. static ssize_t
  683. fb_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
  684. {
  685. unsigned long p = *ppos;
  686. struct fb_info *info = file_fb_info(file);
  687. u8 *buffer, *src;
  688. u8 __iomem *dst;
  689. int c, cnt = 0, err = 0;
  690. unsigned long total_size;
  691. if (!info || !info->screen_base)
  692. return -ENODEV;
  693. if (info->state != FBINFO_STATE_RUNNING)
  694. return -EPERM;
  695. if (info->fbops->fb_write)
  696. return info->fbops->fb_write(info, buf, count, ppos);
  697. total_size = info->screen_size;
  698. if (total_size == 0)
  699. total_size = info->fix.smem_len;
  700. if (p > total_size)
  701. return -EFBIG;
  702. if (count > total_size) {
  703. err = -EFBIG;
  704. count = total_size;
  705. }
  706. if (count + p > total_size) {
  707. if (!err)
  708. err = -ENOSPC;
  709. count = total_size - p;
  710. }
  711. buffer = kmalloc((count > PAGE_SIZE) ? PAGE_SIZE : count,
  712. GFP_KERNEL);
  713. if (!buffer)
  714. return -ENOMEM;
  715. dst = (u8 __iomem *) (info->screen_base + p);
  716. if (info->fbops->fb_sync)
  717. info->fbops->fb_sync(info);
  718. while (count) {
  719. c = (count > PAGE_SIZE) ? PAGE_SIZE : count;
  720. src = buffer;
  721. if (copy_from_user(src, buf, c)) {
  722. err = -EFAULT;
  723. break;
  724. }
  725. fb_memcpy_tofb(dst, src, c);
  726. dst += c;
  727. src += c;
  728. *ppos += c;
  729. buf += c;
  730. cnt += c;
  731. count -= c;
  732. }
  733. kfree(buffer);
  734. return (cnt) ? cnt : err;
  735. }
  736. int
  737. fb_pan_display(struct fb_info *info, struct fb_var_screeninfo *var)
  738. {
  739. struct fb_fix_screeninfo *fix = &info->fix;
  740. unsigned int yres = info->var.yres;
  741. int err = 0;
  742. if (var->yoffset > 0) {
  743. if (var->vmode & FB_VMODE_YWRAP) {
  744. if (!fix->ywrapstep || (var->yoffset % fix->ywrapstep))
  745. err = -EINVAL;
  746. else
  747. yres = 0;
  748. } else if (!fix->ypanstep || (var->yoffset % fix->ypanstep))
  749. err = -EINVAL;
  750. }
  751. if (var->xoffset > 0 && (!fix->xpanstep ||
  752. (var->xoffset % fix->xpanstep)))
  753. err = -EINVAL;
  754. if (err || !info->fbops->fb_pan_display ||
  755. var->yoffset > info->var.yres_virtual - yres ||
  756. var->xoffset > info->var.xres_virtual - info->var.xres)
  757. return -EINVAL;
  758. if ((err = info->fbops->fb_pan_display(var, info)))
  759. return err;
  760. info->var.xoffset = var->xoffset;
  761. info->var.yoffset = var->yoffset;
  762. if (var->vmode & FB_VMODE_YWRAP)
  763. info->var.vmode |= FB_VMODE_YWRAP;
  764. else
  765. info->var.vmode &= ~FB_VMODE_YWRAP;
  766. return 0;
  767. }
  768. EXPORT_SYMBOL(fb_pan_display);
  769. static int fb_check_caps(struct fb_info *info, struct fb_var_screeninfo *var,
  770. u32 activate)
  771. {
  772. struct fb_event event;
  773. struct fb_blit_caps caps, fbcaps;
  774. int err = 0;
  775. memset(&caps, 0, sizeof(caps));
  776. memset(&fbcaps, 0, sizeof(fbcaps));
  777. caps.flags = (activate & FB_ACTIVATE_ALL) ? 1 : 0;
  778. event.info = info;
  779. event.data = &caps;
  780. fb_notifier_call_chain(FB_EVENT_GET_REQ, &event);
  781. info->fbops->fb_get_caps(info, &fbcaps, var);
  782. if (((fbcaps.x ^ caps.x) & caps.x) ||
  783. ((fbcaps.y ^ caps.y) & caps.y) ||
  784. (fbcaps.len < caps.len))
  785. err = -EINVAL;
  786. return err;
  787. }
  788. int
  789. fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var)
  790. {
  791. int flags = info->flags;
  792. int ret = 0;
  793. if (var->activate & FB_ACTIVATE_INV_MODE) {
  794. struct fb_videomode mode1, mode2;
  795. fb_var_to_videomode(&mode1, var);
  796. fb_var_to_videomode(&mode2, &info->var);
  797. /* make sure we don't delete the videomode of current var */
  798. ret = fb_mode_is_equal(&mode1, &mode2);
  799. if (!ret) {
  800. struct fb_event event;
  801. event.info = info;
  802. event.data = &mode1;
  803. ret = fb_notifier_call_chain(FB_EVENT_MODE_DELETE, &event);
  804. }
  805. if (!ret)
  806. fb_delete_videomode(&mode1, &info->modelist);
  807. ret = (ret) ? -EINVAL : 0;
  808. goto done;
  809. }
  810. if ((var->activate & FB_ACTIVATE_FORCE) ||
  811. memcmp(&info->var, var, sizeof(struct fb_var_screeninfo))) {
  812. u32 activate = var->activate;
  813. /* When using FOURCC mode, make sure the red, green, blue and
  814. * transp fields are set to 0.
  815. */
  816. if ((info->fix.capabilities & FB_CAP_FOURCC) &&
  817. var->grayscale > 1) {
  818. if (var->red.offset || var->green.offset ||
  819. var->blue.offset || var->transp.offset ||
  820. var->red.length || var->green.length ||
  821. var->blue.length || var->transp.length ||
  822. var->red.msb_right || var->green.msb_right ||
  823. var->blue.msb_right || var->transp.msb_right)
  824. return -EINVAL;
  825. }
  826. if (!info->fbops->fb_check_var) {
  827. *var = info->var;
  828. goto done;
  829. }
  830. ret = info->fbops->fb_check_var(var, info);
  831. if (ret)
  832. goto done;
  833. if ((var->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW) {
  834. struct fb_var_screeninfo old_var;
  835. struct fb_videomode mode;
  836. if (info->fbops->fb_get_caps) {
  837. ret = fb_check_caps(info, var, activate);
  838. if (ret)
  839. goto done;
  840. }
  841. old_var = info->var;
  842. info->var = *var;
  843. if (info->fbops->fb_set_par) {
  844. ret = info->fbops->fb_set_par(info);
  845. if (ret) {
  846. info->var = old_var;
  847. printk(KERN_WARNING "detected "
  848. "fb_set_par error, "
  849. "error code: %d\n", ret);
  850. goto done;
  851. }
  852. }
  853. fb_pan_display(info, &info->var);
  854. fb_set_cmap(&info->cmap, info);
  855. fb_var_to_videomode(&mode, &info->var);
  856. if (info->modelist.prev && info->modelist.next &&
  857. !list_empty(&info->modelist))
  858. ret = fb_add_videomode(&mode, &info->modelist);
  859. if (!ret && (flags & FBINFO_MISC_USEREVENT)) {
  860. struct fb_event event;
  861. int evnt = (activate & FB_ACTIVATE_ALL) ?
  862. FB_EVENT_MODE_CHANGE_ALL :
  863. FB_EVENT_MODE_CHANGE;
  864. info->flags &= ~FBINFO_MISC_USEREVENT;
  865. event.info = info;
  866. event.data = &mode;
  867. fb_notifier_call_chain(evnt, &event);
  868. }
  869. }
  870. }
  871. done:
  872. return ret;
  873. }
  874. EXPORT_SYMBOL(fb_set_var);
  875. int
  876. fb_blank(struct fb_info *info, int blank)
  877. {
  878. struct fb_event event;
  879. int ret = -EINVAL, early_ret;
  880. if (blank > FB_BLANK_POWERDOWN)
  881. blank = FB_BLANK_POWERDOWN;
  882. event.info = info;
  883. event.data = &blank;
  884. early_ret = fb_notifier_call_chain(FB_EARLY_EVENT_BLANK, &event);
  885. if (info->fbops->fb_blank)
  886. ret = info->fbops->fb_blank(blank, info);
  887. if (!ret)
  888. fb_notifier_call_chain(FB_EVENT_BLANK, &event);
  889. else {
  890. /*
  891. * if fb_blank is failed then revert effects of
  892. * the early blank event.
  893. */
  894. if (!early_ret)
  895. fb_notifier_call_chain(FB_R_EARLY_EVENT_BLANK, &event);
  896. }
  897. return ret;
  898. }
  899. EXPORT_SYMBOL(fb_blank);
  900. static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
  901. unsigned long arg)
  902. {
  903. struct fb_ops *fb;
  904. struct fb_var_screeninfo var;
  905. struct fb_fix_screeninfo fix;
  906. struct fb_con2fbmap con2fb;
  907. struct fb_cmap cmap_from;
  908. struct fb_cmap_user cmap;
  909. struct fb_event event;
  910. void __user *argp = (void __user *)arg;
  911. long ret = 0;
  912. switch (cmd) {
  913. case FBIOGET_VSCREENINFO:
  914. if (!lock_fb_info(info))
  915. return -ENODEV;
  916. var = info->var;
  917. unlock_fb_info(info);
  918. ret = copy_to_user(argp, &var, sizeof(var)) ? -EFAULT : 0;
  919. break;
  920. case FBIOPUT_VSCREENINFO:
  921. if (copy_from_user(&var, argp, sizeof(var)))
  922. return -EFAULT;
  923. console_lock();
  924. if (!lock_fb_info(info)) {
  925. console_unlock();
  926. return -ENODEV;
  927. }
  928. info->flags |= FBINFO_MISC_USEREVENT;
  929. ret = fb_set_var(info, &var);
  930. info->flags &= ~FBINFO_MISC_USEREVENT;
  931. unlock_fb_info(info);
  932. console_unlock();
  933. if (!ret && copy_to_user(argp, &var, sizeof(var)))
  934. ret = -EFAULT;
  935. break;
  936. case FBIOGET_FSCREENINFO:
  937. if (!lock_fb_info(info))
  938. return -ENODEV;
  939. memcpy(&fix, &info->fix, sizeof(fix));
  940. unlock_fb_info(info);
  941. ret = copy_to_user(argp, &fix, sizeof(fix)) ? -EFAULT : 0;
  942. break;
  943. case FBIOPUTCMAP:
  944. if (copy_from_user(&cmap, argp, sizeof(cmap)))
  945. return -EFAULT;
  946. ret = fb_set_user_cmap(&cmap, info);
  947. break;
  948. case FBIOGETCMAP:
  949. if (copy_from_user(&cmap, argp, sizeof(cmap)))
  950. return -EFAULT;
  951. if (!lock_fb_info(info))
  952. return -ENODEV;
  953. cmap_from = info->cmap;
  954. unlock_fb_info(info);
  955. ret = fb_cmap_to_user(&cmap_from, &cmap);
  956. break;
  957. case FBIOPAN_DISPLAY:
  958. if (copy_from_user(&var, argp, sizeof(var)))
  959. return -EFAULT;
  960. console_lock();
  961. if (!lock_fb_info(info)) {
  962. console_unlock();
  963. return -ENODEV;
  964. }
  965. ret = fb_pan_display(info, &var);
  966. unlock_fb_info(info);
  967. console_unlock();
  968. if (ret == 0 && copy_to_user(argp, &var, sizeof(var)))
  969. return -EFAULT;
  970. break;
  971. case FBIO_CURSOR:
  972. ret = -EINVAL;
  973. break;
  974. case FBIOGET_CON2FBMAP:
  975. if (copy_from_user(&con2fb, argp, sizeof(con2fb)))
  976. return -EFAULT;
  977. if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
  978. return -EINVAL;
  979. con2fb.framebuffer = -1;
  980. event.data = &con2fb;
  981. if (!lock_fb_info(info))
  982. return -ENODEV;
  983. event.info = info;
  984. fb_notifier_call_chain(FB_EVENT_GET_CONSOLE_MAP, &event);
  985. unlock_fb_info(info);
  986. ret = copy_to_user(argp, &con2fb, sizeof(con2fb)) ? -EFAULT : 0;
  987. break;
  988. case FBIOPUT_CON2FBMAP:
  989. if (copy_from_user(&con2fb, argp, sizeof(con2fb)))
  990. return -EFAULT;
  991. if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
  992. return -EINVAL;
  993. if (con2fb.framebuffer >= FB_MAX)
  994. return -EINVAL;
  995. if (!registered_fb[con2fb.framebuffer])
  996. request_module("fb%d", con2fb.framebuffer);
  997. if (!registered_fb[con2fb.framebuffer]) {
  998. ret = -EINVAL;
  999. break;
  1000. }
  1001. event.data = &con2fb;
  1002. console_lock();
  1003. if (!lock_fb_info(info)) {
  1004. console_unlock();
  1005. return -ENODEV;
  1006. }
  1007. event.info = info;
  1008. ret = fb_notifier_call_chain(FB_EVENT_SET_CONSOLE_MAP, &event);
  1009. unlock_fb_info(info);
  1010. console_unlock();
  1011. break;
  1012. case FBIOBLANK:
  1013. console_lock();
  1014. if (!lock_fb_info(info)) {
  1015. console_unlock();
  1016. return -ENODEV;
  1017. }
  1018. info->flags |= FBINFO_MISC_USEREVENT;
  1019. ret = fb_blank(info, arg);
  1020. info->flags &= ~FBINFO_MISC_USEREVENT;
  1021. unlock_fb_info(info);
  1022. console_unlock();
  1023. break;
  1024. default:
  1025. if (!lock_fb_info(info))
  1026. return -ENODEV;
  1027. fb = info->fbops;
  1028. if (fb->fb_ioctl)
  1029. ret = fb->fb_ioctl(info, cmd, arg);
  1030. else
  1031. ret = -ENOTTY;
  1032. unlock_fb_info(info);
  1033. }
  1034. return ret;
  1035. }
  1036. static long fb_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  1037. {
  1038. struct fb_info *info = file_fb_info(file);
  1039. if (!info)
  1040. return -ENODEV;
  1041. return do_fb_ioctl(info, cmd, arg);
  1042. }
  1043. #ifdef CONFIG_COMPAT
  1044. struct fb_fix_screeninfo32 {
  1045. char id[16];
  1046. compat_caddr_t smem_start;
  1047. u32 smem_len;
  1048. u32 type;
  1049. u32 type_aux;
  1050. u32 visual;
  1051. u16 xpanstep;
  1052. u16 ypanstep;
  1053. u16 ywrapstep;
  1054. u32 line_length;
  1055. compat_caddr_t mmio_start;
  1056. u32 mmio_len;
  1057. u32 accel;
  1058. u16 reserved[3];
  1059. };
  1060. struct fb_cmap32 {
  1061. u32 start;
  1062. u32 len;
  1063. compat_caddr_t red;
  1064. compat_caddr_t green;
  1065. compat_caddr_t blue;
  1066. compat_caddr_t transp;
  1067. };
  1068. static int fb_getput_cmap(struct fb_info *info, unsigned int cmd,
  1069. unsigned long arg)
  1070. {
  1071. struct fb_cmap_user __user *cmap;
  1072. struct fb_cmap32 __user *cmap32;
  1073. __u32 data;
  1074. int err;
  1075. cmap = compat_alloc_user_space(sizeof(*cmap));
  1076. cmap32 = compat_ptr(arg);
  1077. if (copy_in_user(&cmap->start, &cmap32->start, 2 * sizeof(__u32)))
  1078. return -EFAULT;
  1079. if (get_user(data, &cmap32->red) ||
  1080. put_user(compat_ptr(data), &cmap->red) ||
  1081. get_user(data, &cmap32->green) ||
  1082. put_user(compat_ptr(data), &cmap->green) ||
  1083. get_user(data, &cmap32->blue) ||
  1084. put_user(compat_ptr(data), &cmap->blue) ||
  1085. get_user(data, &cmap32->transp) ||
  1086. put_user(compat_ptr(data), &cmap->transp))
  1087. return -EFAULT;
  1088. err = do_fb_ioctl(info, cmd, (unsigned long) cmap);
  1089. if (!err) {
  1090. if (copy_in_user(&cmap32->start,
  1091. &cmap->start,
  1092. 2 * sizeof(__u32)))
  1093. err = -EFAULT;
  1094. }
  1095. return err;
  1096. }
  1097. static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
  1098. struct fb_fix_screeninfo32 __user *fix32)
  1099. {
  1100. __u32 data;
  1101. int err;
  1102. err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
  1103. data = (__u32) (unsigned long) fix->smem_start;
  1104. err |= put_user(data, &fix32->smem_start);
  1105. err |= put_user(fix->smem_len, &fix32->smem_len);
  1106. err |= put_user(fix->type, &fix32->type);
  1107. err |= put_user(fix->type_aux, &fix32->type_aux);
  1108. err |= put_user(fix->visual, &fix32->visual);
  1109. err |= put_user(fix->xpanstep, &fix32->xpanstep);
  1110. err |= put_user(fix->ypanstep, &fix32->ypanstep);
  1111. err |= put_user(fix->ywrapstep, &fix32->ywrapstep);
  1112. err |= put_user(fix->line_length, &fix32->line_length);
  1113. data = (__u32) (unsigned long) fix->mmio_start;
  1114. err |= put_user(data, &fix32->mmio_start);
  1115. err |= put_user(fix->mmio_len, &fix32->mmio_len);
  1116. err |= put_user(fix->accel, &fix32->accel);
  1117. err |= copy_to_user(fix32->reserved, fix->reserved,
  1118. sizeof(fix->reserved));
  1119. if (err)
  1120. return -EFAULT;
  1121. return 0;
  1122. }
  1123. static int fb_get_fscreeninfo(struct fb_info *info, unsigned int cmd,
  1124. unsigned long arg)
  1125. {
  1126. struct fb_fix_screeninfo fix;
  1127. if (!lock_fb_info(info))
  1128. return -ENODEV;
  1129. fix = info->fix;
  1130. unlock_fb_info(info);
  1131. return do_fscreeninfo_to_user(&fix, compat_ptr(arg));
  1132. }
  1133. static long fb_compat_ioctl(struct file *file, unsigned int cmd,
  1134. unsigned long arg)
  1135. {
  1136. struct fb_info *info = file_fb_info(file);
  1137. struct fb_ops *fb;
  1138. long ret = -ENOIOCTLCMD;
  1139. if (!info)
  1140. return -ENODEV;
  1141. fb = info->fbops;
  1142. switch(cmd) {
  1143. case FBIOGET_VSCREENINFO:
  1144. case FBIOPUT_VSCREENINFO:
  1145. case FBIOPAN_DISPLAY:
  1146. case FBIOGET_CON2FBMAP:
  1147. case FBIOPUT_CON2FBMAP:
  1148. arg = (unsigned long) compat_ptr(arg);
  1149. /* fall through */
  1150. case FBIOBLANK:
  1151. ret = do_fb_ioctl(info, cmd, arg);
  1152. break;
  1153. case FBIOGET_FSCREENINFO:
  1154. ret = fb_get_fscreeninfo(info, cmd, arg);
  1155. break;
  1156. case FBIOGETCMAP:
  1157. case FBIOPUTCMAP:
  1158. ret = fb_getput_cmap(info, cmd, arg);
  1159. break;
  1160. default:
  1161. if (fb->fb_compat_ioctl)
  1162. ret = fb->fb_compat_ioctl(info, cmd, arg);
  1163. break;
  1164. }
  1165. return ret;
  1166. }
  1167. #endif
  1168. static int
  1169. fb_mmap(struct file *file, struct vm_area_struct * vma)
  1170. {
  1171. struct fb_info *info = file_fb_info(file);
  1172. struct fb_ops *fb;
  1173. unsigned long mmio_pgoff;
  1174. unsigned long start;
  1175. u32 len;
  1176. if (!info)
  1177. return -ENODEV;
  1178. fb = info->fbops;
  1179. if (!fb)
  1180. return -ENODEV;
  1181. mutex_lock(&info->mm_lock);
  1182. if (fb->fb_mmap) {
  1183. int res;
  1184. /*
  1185. * The framebuffer needs to be accessed decrypted, be sure
  1186. * SME protection is removed ahead of the call
  1187. */
  1188. vma->vm_page_prot = pgprot_decrypted(vma->vm_page_prot);
  1189. res = fb->fb_mmap(info, vma);
  1190. mutex_unlock(&info->mm_lock);
  1191. return res;
  1192. }
  1193. /*
  1194. * Ugh. This can be either the frame buffer mapping, or
  1195. * if pgoff points past it, the mmio mapping.
  1196. */
  1197. start = info->fix.smem_start;
  1198. len = info->fix.smem_len;
  1199. mmio_pgoff = PAGE_ALIGN((start & ~PAGE_MASK) + len) >> PAGE_SHIFT;
  1200. if (vma->vm_pgoff >= mmio_pgoff) {
  1201. if (info->var.accel_flags) {
  1202. mutex_unlock(&info->mm_lock);
  1203. return -EINVAL;
  1204. }
  1205. vma->vm_pgoff -= mmio_pgoff;
  1206. start = info->fix.mmio_start;
  1207. len = info->fix.mmio_len;
  1208. }
  1209. mutex_unlock(&info->mm_lock);
  1210. vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
  1211. /*
  1212. * The framebuffer needs to be accessed decrypted, be sure
  1213. * SME protection is removed
  1214. */
  1215. vma->vm_page_prot = pgprot_decrypted(vma->vm_page_prot);
  1216. fb_pgprotect(file, vma, start);
  1217. return vm_iomap_memory(vma, start, len);
  1218. }
  1219. static int
  1220. fb_open(struct inode *inode, struct file *file)
  1221. __acquires(&info->lock)
  1222. __releases(&info->lock)
  1223. {
  1224. int fbidx = iminor(inode);
  1225. struct fb_info *info;
  1226. int res = 0;
  1227. info = get_fb_info(fbidx);
  1228. if (!info) {
  1229. request_module("fb%d", fbidx);
  1230. info = get_fb_info(fbidx);
  1231. if (!info)
  1232. return -ENODEV;
  1233. }
  1234. if (IS_ERR(info))
  1235. return PTR_ERR(info);
  1236. mutex_lock(&info->lock);
  1237. if (!try_module_get(info->fbops->owner)) {
  1238. res = -ENODEV;
  1239. goto out;
  1240. }
  1241. file->private_data = info;
  1242. if (info->fbops->fb_open) {
  1243. res = info->fbops->fb_open(info,1);
  1244. if (res)
  1245. module_put(info->fbops->owner);
  1246. }
  1247. #ifdef CONFIG_FB_DEFERRED_IO
  1248. if (info->fbdefio)
  1249. fb_deferred_io_open(info, inode, file);
  1250. #endif
  1251. out:
  1252. mutex_unlock(&info->lock);
  1253. if (res)
  1254. put_fb_info(info);
  1255. return res;
  1256. }
  1257. static int
  1258. fb_release(struct inode *inode, struct file *file)
  1259. __acquires(&info->lock)
  1260. __releases(&info->lock)
  1261. {
  1262. struct fb_info * const info = file->private_data;
  1263. mutex_lock(&info->lock);
  1264. if (info->fbops->fb_release)
  1265. info->fbops->fb_release(info,1);
  1266. module_put(info->fbops->owner);
  1267. mutex_unlock(&info->lock);
  1268. put_fb_info(info);
  1269. return 0;
  1270. }
  1271. #if defined(CONFIG_FB_PROVIDE_GET_FB_UNMAPPED_AREA) && !defined(CONFIG_MMU)
  1272. unsigned long get_fb_unmapped_area(struct file *filp,
  1273. unsigned long addr, unsigned long len,
  1274. unsigned long pgoff, unsigned long flags)
  1275. {
  1276. struct fb_info * const info = filp->private_data;
  1277. unsigned long fb_size = PAGE_ALIGN(info->fix.smem_len);
  1278. if (pgoff > fb_size || len > fb_size - pgoff)
  1279. return -EINVAL;
  1280. return (unsigned long)info->screen_base + pgoff;
  1281. }
  1282. #endif
  1283. static const struct file_operations fb_fops = {
  1284. .owner = THIS_MODULE,
  1285. .read = fb_read,
  1286. .write = fb_write,
  1287. .unlocked_ioctl = fb_ioctl,
  1288. #ifdef CONFIG_COMPAT
  1289. .compat_ioctl = fb_compat_ioctl,
  1290. #endif
  1291. .mmap = fb_mmap,
  1292. .open = fb_open,
  1293. .release = fb_release,
  1294. #if defined(HAVE_ARCH_FB_UNMAPPED_AREA) || \
  1295. (defined(CONFIG_FB_PROVIDE_GET_FB_UNMAPPED_AREA) && \
  1296. !defined(CONFIG_MMU))
  1297. .get_unmapped_area = get_fb_unmapped_area,
  1298. #endif
  1299. #ifdef CONFIG_FB_DEFERRED_IO
  1300. .fsync = fb_deferred_io_fsync,
  1301. #endif
  1302. .llseek = default_llseek,
  1303. };
  1304. struct class *fb_class;
  1305. EXPORT_SYMBOL(fb_class);
  1306. static int fb_check_foreignness(struct fb_info *fi)
  1307. {
  1308. const bool foreign_endian = fi->flags & FBINFO_FOREIGN_ENDIAN;
  1309. fi->flags &= ~FBINFO_FOREIGN_ENDIAN;
  1310. #ifdef __BIG_ENDIAN
  1311. fi->flags |= foreign_endian ? 0 : FBINFO_BE_MATH;
  1312. #else
  1313. fi->flags |= foreign_endian ? FBINFO_BE_MATH : 0;
  1314. #endif /* __BIG_ENDIAN */
  1315. if (fi->flags & FBINFO_BE_MATH && !fb_be_math(fi)) {
  1316. pr_err("%s: enable CONFIG_FB_BIG_ENDIAN to "
  1317. "support this framebuffer\n", fi->fix.id);
  1318. return -ENOSYS;
  1319. } else if (!(fi->flags & FBINFO_BE_MATH) && fb_be_math(fi)) {
  1320. pr_err("%s: enable CONFIG_FB_LITTLE_ENDIAN to "
  1321. "support this framebuffer\n", fi->fix.id);
  1322. return -ENOSYS;
  1323. }
  1324. return 0;
  1325. }
  1326. static bool apertures_overlap(struct aperture *gen, struct aperture *hw)
  1327. {
  1328. /* is the generic aperture base the same as the HW one */
  1329. if (gen->base == hw->base)
  1330. return true;
  1331. /* is the generic aperture base inside the hw base->hw base+size */
  1332. if (gen->base > hw->base && gen->base < hw->base + hw->size)
  1333. return true;
  1334. return false;
  1335. }
  1336. static bool fb_do_apertures_overlap(struct apertures_struct *gena,
  1337. struct apertures_struct *hwa)
  1338. {
  1339. int i, j;
  1340. if (!hwa || !gena)
  1341. return false;
  1342. for (i = 0; i < hwa->count; ++i) {
  1343. struct aperture *h = &hwa->ranges[i];
  1344. for (j = 0; j < gena->count; ++j) {
  1345. struct aperture *g = &gena->ranges[j];
  1346. printk(KERN_DEBUG "checking generic (%llx %llx) vs hw (%llx %llx)\n",
  1347. (unsigned long long)g->base,
  1348. (unsigned long long)g->size,
  1349. (unsigned long long)h->base,
  1350. (unsigned long long)h->size);
  1351. if (apertures_overlap(g, h))
  1352. return true;
  1353. }
  1354. }
  1355. return false;
  1356. }
  1357. static int do_unregister_framebuffer(struct fb_info *fb_info);
  1358. #define VGA_FB_PHYS 0xA0000
  1359. static int do_remove_conflicting_framebuffers(struct apertures_struct *a,
  1360. const char *name, bool primary)
  1361. {
  1362. int i, ret;
  1363. /* check all firmware fbs and kick off if the base addr overlaps */
  1364. for_each_registered_fb(i) {
  1365. struct apertures_struct *gen_aper;
  1366. if (!(registered_fb[i]->flags & FBINFO_MISC_FIRMWARE))
  1367. continue;
  1368. gen_aper = registered_fb[i]->apertures;
  1369. if (fb_do_apertures_overlap(gen_aper, a) ||
  1370. (primary && gen_aper && gen_aper->count &&
  1371. gen_aper->ranges[0].base == VGA_FB_PHYS)) {
  1372. printk(KERN_INFO "fb: switching to %s from %s\n",
  1373. name, registered_fb[i]->fix.id);
  1374. ret = do_unregister_framebuffer(registered_fb[i]);
  1375. if (ret)
  1376. return ret;
  1377. }
  1378. }
  1379. return 0;
  1380. }
  1381. static bool lockless_register_fb;
  1382. module_param_named_unsafe(lockless_register_fb, lockless_register_fb, bool, 0400);
  1383. MODULE_PARM_DESC(lockless_register_fb,
  1384. "Lockless framebuffer registration for debugging [default=off]");
  1385. static int do_register_framebuffer(struct fb_info *fb_info)
  1386. {
  1387. int i, ret;
  1388. struct fb_event event;
  1389. struct fb_videomode mode;
  1390. if (fb_check_foreignness(fb_info))
  1391. return -ENOSYS;
  1392. ret = do_remove_conflicting_framebuffers(fb_info->apertures,
  1393. fb_info->fix.id,
  1394. fb_is_primary_device(fb_info));
  1395. if (ret)
  1396. return ret;
  1397. if (num_registered_fb == FB_MAX)
  1398. return -ENXIO;
  1399. num_registered_fb++;
  1400. for (i = 0 ; i < FB_MAX; i++)
  1401. if (!registered_fb[i])
  1402. break;
  1403. fb_info->node = i;
  1404. atomic_set(&fb_info->count, 1);
  1405. mutex_init(&fb_info->lock);
  1406. mutex_init(&fb_info->mm_lock);
  1407. fb_info->dev = device_create(fb_class, fb_info->device,
  1408. MKDEV(FB_MAJOR, i), NULL, "fb%d", i);
  1409. if (IS_ERR(fb_info->dev)) {
  1410. /* Not fatal */
  1411. printk(KERN_WARNING "Unable to create device for framebuffer %d; errno = %ld\n", i, PTR_ERR(fb_info->dev));
  1412. fb_info->dev = NULL;
  1413. } else
  1414. fb_init_device(fb_info);
  1415. if (fb_info->pixmap.addr == NULL) {
  1416. fb_info->pixmap.addr = kmalloc(FBPIXMAPSIZE, GFP_KERNEL);
  1417. if (fb_info->pixmap.addr) {
  1418. fb_info->pixmap.size = FBPIXMAPSIZE;
  1419. fb_info->pixmap.buf_align = 1;
  1420. fb_info->pixmap.scan_align = 1;
  1421. fb_info->pixmap.access_align = 32;
  1422. fb_info->pixmap.flags = FB_PIXMAP_DEFAULT;
  1423. }
  1424. }
  1425. fb_info->pixmap.offset = 0;
  1426. if (!fb_info->pixmap.blit_x)
  1427. fb_info->pixmap.blit_x = ~(u32)0;
  1428. if (!fb_info->pixmap.blit_y)
  1429. fb_info->pixmap.blit_y = ~(u32)0;
  1430. if (!fb_info->modelist.prev || !fb_info->modelist.next)
  1431. INIT_LIST_HEAD(&fb_info->modelist);
  1432. if (fb_info->skip_vt_switch)
  1433. pm_vt_switch_required(fb_info->dev, false);
  1434. else
  1435. pm_vt_switch_required(fb_info->dev, true);
  1436. fb_var_to_videomode(&mode, &fb_info->var);
  1437. fb_add_videomode(&mode, &fb_info->modelist);
  1438. registered_fb[i] = fb_info;
  1439. event.info = fb_info;
  1440. if (!lockless_register_fb)
  1441. console_lock();
  1442. else
  1443. atomic_inc(&ignore_console_lock_warning);
  1444. if (!lock_fb_info(fb_info)) {
  1445. ret = -ENODEV;
  1446. goto unlock_console;
  1447. }
  1448. ret = 0;
  1449. fb_notifier_call_chain(FB_EVENT_FB_REGISTERED, &event);
  1450. unlock_fb_info(fb_info);
  1451. unlock_console:
  1452. if (!lockless_register_fb)
  1453. console_unlock();
  1454. else
  1455. atomic_dec(&ignore_console_lock_warning);
  1456. return ret;
  1457. }
  1458. static int unbind_console(struct fb_info *fb_info)
  1459. {
  1460. struct fb_event event;
  1461. int ret;
  1462. int i = fb_info->node;
  1463. if (i < 0 || i >= FB_MAX || registered_fb[i] != fb_info)
  1464. return -EINVAL;
  1465. console_lock();
  1466. if (!lock_fb_info(fb_info)) {
  1467. console_unlock();
  1468. return -ENODEV;
  1469. }
  1470. event.info = fb_info;
  1471. ret = fb_notifier_call_chain(FB_EVENT_FB_UNBIND, &event);
  1472. unlock_fb_info(fb_info);
  1473. console_unlock();
  1474. return ret;
  1475. }
  1476. static int __unlink_framebuffer(struct fb_info *fb_info);
  1477. static int do_unregister_framebuffer(struct fb_info *fb_info)
  1478. {
  1479. struct fb_event event;
  1480. int ret;
  1481. ret = unbind_console(fb_info);
  1482. if (ret)
  1483. return -EINVAL;
  1484. pm_vt_switch_unregister(fb_info->dev);
  1485. __unlink_framebuffer(fb_info);
  1486. if (fb_info->pixmap.addr &&
  1487. (fb_info->pixmap.flags & FB_PIXMAP_DEFAULT))
  1488. kfree(fb_info->pixmap.addr);
  1489. fb_destroy_modelist(&fb_info->modelist);
  1490. registered_fb[fb_info->node] = NULL;
  1491. num_registered_fb--;
  1492. fb_cleanup_device(fb_info);
  1493. event.info = fb_info;
  1494. console_lock();
  1495. fb_notifier_call_chain(FB_EVENT_FB_UNREGISTERED, &event);
  1496. console_unlock();
  1497. /* this may free fb info */
  1498. put_fb_info(fb_info);
  1499. return 0;
  1500. }
  1501. static int __unlink_framebuffer(struct fb_info *fb_info)
  1502. {
  1503. int i;
  1504. i = fb_info->node;
  1505. if (i < 0 || i >= FB_MAX || registered_fb[i] != fb_info)
  1506. return -EINVAL;
  1507. if (fb_info->dev) {
  1508. device_destroy(fb_class, MKDEV(FB_MAJOR, i));
  1509. fb_info->dev = NULL;
  1510. }
  1511. return 0;
  1512. }
  1513. int unlink_framebuffer(struct fb_info *fb_info)
  1514. {
  1515. int ret;
  1516. ret = __unlink_framebuffer(fb_info);
  1517. if (ret)
  1518. return ret;
  1519. unbind_console(fb_info);
  1520. return 0;
  1521. }
  1522. EXPORT_SYMBOL(unlink_framebuffer);
  1523. int remove_conflicting_framebuffers(struct apertures_struct *a,
  1524. const char *name, bool primary)
  1525. {
  1526. int ret;
  1527. mutex_lock(&registration_lock);
  1528. ret = do_remove_conflicting_framebuffers(a, name, primary);
  1529. mutex_unlock(&registration_lock);
  1530. return ret;
  1531. }
  1532. EXPORT_SYMBOL(remove_conflicting_framebuffers);
  1533. /**
  1534. * register_framebuffer - registers a frame buffer device
  1535. * @fb_info: frame buffer info structure
  1536. *
  1537. * Registers a frame buffer device @fb_info.
  1538. *
  1539. * Returns negative errno on error, or zero for success.
  1540. *
  1541. */
  1542. int
  1543. register_framebuffer(struct fb_info *fb_info)
  1544. {
  1545. int ret;
  1546. mutex_lock(&registration_lock);
  1547. ret = do_register_framebuffer(fb_info);
  1548. mutex_unlock(&registration_lock);
  1549. return ret;
  1550. }
  1551. EXPORT_SYMBOL(register_framebuffer);
  1552. /**
  1553. * unregister_framebuffer - releases a frame buffer device
  1554. * @fb_info: frame buffer info structure
  1555. *
  1556. * Unregisters a frame buffer device @fb_info.
  1557. *
  1558. * Returns negative errno on error, or zero for success.
  1559. *
  1560. * This function will also notify the framebuffer console
  1561. * to release the driver.
  1562. *
  1563. * This is meant to be called within a driver's module_exit()
  1564. * function. If this is called outside module_exit(), ensure
  1565. * that the driver implements fb_open() and fb_release() to
  1566. * check that no processes are using the device.
  1567. */
  1568. int
  1569. unregister_framebuffer(struct fb_info *fb_info)
  1570. {
  1571. int ret;
  1572. mutex_lock(&registration_lock);
  1573. ret = do_unregister_framebuffer(fb_info);
  1574. mutex_unlock(&registration_lock);
  1575. return ret;
  1576. }
  1577. EXPORT_SYMBOL(unregister_framebuffer);
  1578. /**
  1579. * fb_set_suspend - low level driver signals suspend
  1580. * @info: framebuffer affected
  1581. * @state: 0 = resuming, !=0 = suspending
  1582. *
  1583. * This is meant to be used by low level drivers to
  1584. * signal suspend/resume to the core & clients.
  1585. * It must be called with the console semaphore held
  1586. */
  1587. void fb_set_suspend(struct fb_info *info, int state)
  1588. {
  1589. struct fb_event event;
  1590. event.info = info;
  1591. if (state) {
  1592. fb_notifier_call_chain(FB_EVENT_SUSPEND, &event);
  1593. info->state = FBINFO_STATE_SUSPENDED;
  1594. } else {
  1595. info->state = FBINFO_STATE_RUNNING;
  1596. fb_notifier_call_chain(FB_EVENT_RESUME, &event);
  1597. }
  1598. }
  1599. EXPORT_SYMBOL(fb_set_suspend);
  1600. /**
  1601. * fbmem_init - init frame buffer subsystem
  1602. *
  1603. * Initialize the frame buffer subsystem.
  1604. *
  1605. * NOTE: This function is _only_ to be called by drivers/char/mem.c.
  1606. *
  1607. */
  1608. static int __init
  1609. fbmem_init(void)
  1610. {
  1611. int ret;
  1612. if (!proc_create_seq("fb", 0, NULL, &proc_fb_seq_ops))
  1613. return -ENOMEM;
  1614. ret = register_chrdev(FB_MAJOR, "fb", &fb_fops);
  1615. if (ret) {
  1616. printk("unable to get major %d for fb devs\n", FB_MAJOR);
  1617. goto err_chrdev;
  1618. }
  1619. fb_class = class_create(THIS_MODULE, "graphics");
  1620. if (IS_ERR(fb_class)) {
  1621. ret = PTR_ERR(fb_class);
  1622. pr_warn("Unable to create fb class; errno = %d\n", ret);
  1623. fb_class = NULL;
  1624. goto err_class;
  1625. }
  1626. fb_console_init();
  1627. return 0;
  1628. err_class:
  1629. unregister_chrdev(FB_MAJOR, "fb");
  1630. err_chrdev:
  1631. remove_proc_entry("fb", NULL);
  1632. return ret;
  1633. }
  1634. #ifdef MODULE
  1635. module_init(fbmem_init);
  1636. static void __exit
  1637. fbmem_exit(void)
  1638. {
  1639. fb_console_exit();
  1640. remove_proc_entry("fb", NULL);
  1641. class_destroy(fb_class);
  1642. unregister_chrdev(FB_MAJOR, "fb");
  1643. }
  1644. module_exit(fbmem_exit);
  1645. MODULE_LICENSE("GPL");
  1646. MODULE_DESCRIPTION("Framebuffer base");
  1647. #else
  1648. subsys_initcall(fbmem_init);
  1649. #endif
  1650. int fb_new_modelist(struct fb_info *info)
  1651. {
  1652. struct fb_event event;
  1653. struct fb_var_screeninfo var = info->var;
  1654. struct list_head *pos, *n;
  1655. struct fb_modelist *modelist;
  1656. struct fb_videomode *m, mode;
  1657. int err = 1;
  1658. list_for_each_safe(pos, n, &info->modelist) {
  1659. modelist = list_entry(pos, struct fb_modelist, list);
  1660. m = &modelist->mode;
  1661. fb_videomode_to_var(&var, m);
  1662. var.activate = FB_ACTIVATE_TEST;
  1663. err = fb_set_var(info, &var);
  1664. fb_var_to_videomode(&mode, &var);
  1665. if (err || !fb_mode_is_equal(m, &mode)) {
  1666. list_del(pos);
  1667. kfree(pos);
  1668. }
  1669. }
  1670. err = 1;
  1671. if (!list_empty(&info->modelist)) {
  1672. event.info = info;
  1673. err = fb_notifier_call_chain(FB_EVENT_NEW_MODELIST, &event);
  1674. }
  1675. return err;
  1676. }
  1677. MODULE_LICENSE("GPL");