fbcon.c 84 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475
  1. /*
  2. * linux/drivers/video/fbcon.c -- Low level frame buffer based console driver
  3. *
  4. * Copyright (C) 1995 Geert Uytterhoeven
  5. *
  6. *
  7. * This file is based on the original Amiga console driver (amicon.c):
  8. *
  9. * Copyright (C) 1993 Hamish Macdonald
  10. * Greg Harp
  11. * Copyright (C) 1994 David Carter [carter@compsci.bristol.ac.uk]
  12. *
  13. * with work by William Rucklidge (wjr@cs.cornell.edu)
  14. * Geert Uytterhoeven
  15. * Jes Sorensen (jds@kom.auc.dk)
  16. * Martin Apel
  17. *
  18. * and on the original Atari console driver (atacon.c):
  19. *
  20. * Copyright (C) 1993 Bjoern Brauel
  21. * Roman Hodek
  22. *
  23. * with work by Guenther Kelleter
  24. * Martin Schaller
  25. * Andreas Schwab
  26. *
  27. * Hardware cursor support added by Emmanuel Marty (core@ggi-project.org)
  28. * Smart redraw scrolling, arbitrary font width support, 512char font support
  29. * and software scrollback added by
  30. * Jakub Jelinek (jj@ultra.linux.cz)
  31. *
  32. * Random hacking by Martin Mares <mj@ucw.cz>
  33. *
  34. * 2001 - Documented with DocBook
  35. * - Brad Douglas <brad@neruo.com>
  36. *
  37. * The low level operations for the various display memory organizations are
  38. * now in separate source files.
  39. *
  40. * Currently the following organizations are supported:
  41. *
  42. * o afb Amiga bitplanes
  43. * o cfb{2,4,8,16,24,32} Packed pixels
  44. * o ilbm Amiga interleaved bitplanes
  45. * o iplan2p[248] Atari interleaved bitplanes
  46. * o mfb Monochrome
  47. * o vga VGA characters/attributes
  48. *
  49. * To do:
  50. *
  51. * - Implement 16 plane mode (iplan2p16)
  52. *
  53. *
  54. * This file is subject to the terms and conditions of the GNU General Public
  55. * License. See the file COPYING in the main directory of this archive for
  56. * more details.
  57. */
  58. #undef FBCONDEBUG
  59. #include <linux/module.h>
  60. #include <linux/types.h>
  61. #include <linux/fs.h>
  62. #include <linux/kernel.h>
  63. #include <linux/delay.h> /* MSch: for IRQ probe */
  64. #include <linux/console.h>
  65. #include <linux/string.h>
  66. #include <linux/kd.h>
  67. #include <linux/slab.h>
  68. #include <linux/fb.h>
  69. #include <linux/fbcon.h>
  70. #include <linux/vt_kern.h>
  71. #include <linux/selection.h>
  72. #include <linux/font.h>
  73. #include <linux/smp.h>
  74. #include <linux/init.h>
  75. #include <linux/interrupt.h>
  76. #include <linux/crc32.h> /* For counting font checksums */
  77. #include <asm/fb.h>
  78. #include <asm/irq.h>
  79. #include "fbcon.h"
  80. #ifdef FBCONDEBUG
  81. # define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __func__ , ## args)
  82. #else
  83. # define DPRINTK(fmt, args...)
  84. #endif
  85. enum {
  86. FBCON_LOGO_CANSHOW = -1, /* the logo can be shown */
  87. FBCON_LOGO_DRAW = -2, /* draw the logo to a console */
  88. FBCON_LOGO_DONTSHOW = -3 /* do not show the logo */
  89. };
  90. static struct display fb_display[MAX_NR_CONSOLES];
  91. static signed char con2fb_map[MAX_NR_CONSOLES];
  92. static signed char con2fb_map_boot[MAX_NR_CONSOLES];
  93. static int logo_lines;
  94. /* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
  95. enums. */
  96. static int logo_shown = FBCON_LOGO_CANSHOW;
  97. /* console mappings */
  98. static int first_fb_vc;
  99. static int last_fb_vc = MAX_NR_CONSOLES - 1;
  100. static int fbcon_is_default = 1;
  101. static int fbcon_has_exited;
  102. static int primary_device = -1;
  103. static int fbcon_has_console_bind;
  104. #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
  105. static int map_override;
  106. static inline void fbcon_map_override(void)
  107. {
  108. map_override = 1;
  109. }
  110. #else
  111. static inline void fbcon_map_override(void)
  112. {
  113. }
  114. #endif /* CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY */
  115. #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
  116. static bool deferred_takeover = true;
  117. #else
  118. #define deferred_takeover false
  119. #endif
  120. /* font data */
  121. static char fontname[40];
  122. /* current fb_info */
  123. static int info_idx = -1;
  124. /* console rotation */
  125. static int initial_rotation = -1;
  126. static int fbcon_has_sysfs;
  127. static int margin_color;
  128. static const struct consw fb_con;
  129. #define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
  130. static int fbcon_set_origin(struct vc_data *);
  131. static int fbcon_cursor_noblink;
  132. #define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
  133. /*
  134. * Interface used by the world
  135. */
  136. static const char *fbcon_startup(void);
  137. static void fbcon_init(struct vc_data *vc, int init);
  138. static void fbcon_deinit(struct vc_data *vc);
  139. static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
  140. int width);
  141. static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos);
  142. static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
  143. int count, int ypos, int xpos);
  144. static void fbcon_clear_margins(struct vc_data *vc, int bottom_only);
  145. static void fbcon_cursor(struct vc_data *vc, int mode);
  146. static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
  147. int height, int width);
  148. static int fbcon_switch(struct vc_data *vc);
  149. static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch);
  150. static void fbcon_set_palette(struct vc_data *vc, const unsigned char *table);
  151. /*
  152. * Internal routines
  153. */
  154. static __inline__ void ywrap_up(struct vc_data *vc, int count);
  155. static __inline__ void ywrap_down(struct vc_data *vc, int count);
  156. static __inline__ void ypan_up(struct vc_data *vc, int count);
  157. static __inline__ void ypan_down(struct vc_data *vc, int count);
  158. static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
  159. int dy, int dx, int height, int width, u_int y_break);
  160. static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
  161. int unit);
  162. static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
  163. int line, int count, int dy);
  164. static void fbcon_modechanged(struct fb_info *info);
  165. static void fbcon_set_all_vcs(struct fb_info *info);
  166. static void fbcon_start(void);
  167. static void fbcon_exit(void);
  168. static struct device *fbcon_device;
  169. #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
  170. static inline void fbcon_set_rotation(struct fb_info *info)
  171. {
  172. struct fbcon_ops *ops = info->fbcon_par;
  173. if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
  174. ops->p->con_rotate < 4)
  175. ops->rotate = ops->p->con_rotate;
  176. else
  177. ops->rotate = 0;
  178. }
  179. static void fbcon_rotate(struct fb_info *info, u32 rotate)
  180. {
  181. struct fbcon_ops *ops= info->fbcon_par;
  182. struct fb_info *fb_info;
  183. if (!ops || ops->currcon == -1)
  184. return;
  185. fb_info = registered_fb[con2fb_map[ops->currcon]];
  186. if (info == fb_info) {
  187. struct display *p = &fb_display[ops->currcon];
  188. if (rotate < 4)
  189. p->con_rotate = rotate;
  190. else
  191. p->con_rotate = 0;
  192. fbcon_modechanged(info);
  193. }
  194. }
  195. static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
  196. {
  197. struct fbcon_ops *ops = info->fbcon_par;
  198. struct vc_data *vc;
  199. struct display *p;
  200. int i;
  201. if (!ops || ops->currcon < 0 || rotate > 3)
  202. return;
  203. for (i = first_fb_vc; i <= last_fb_vc; i++) {
  204. vc = vc_cons[i].d;
  205. if (!vc || vc->vc_mode != KD_TEXT ||
  206. registered_fb[con2fb_map[i]] != info)
  207. continue;
  208. p = &fb_display[vc->vc_num];
  209. p->con_rotate = rotate;
  210. }
  211. fbcon_set_all_vcs(info);
  212. }
  213. #else
  214. static inline void fbcon_set_rotation(struct fb_info *info)
  215. {
  216. struct fbcon_ops *ops = info->fbcon_par;
  217. ops->rotate = FB_ROTATE_UR;
  218. }
  219. static void fbcon_rotate(struct fb_info *info, u32 rotate)
  220. {
  221. return;
  222. }
  223. static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
  224. {
  225. return;
  226. }
  227. #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
  228. static int fbcon_get_rotate(struct fb_info *info)
  229. {
  230. struct fbcon_ops *ops = info->fbcon_par;
  231. return (ops) ? ops->rotate : 0;
  232. }
  233. static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info)
  234. {
  235. struct fbcon_ops *ops = info->fbcon_par;
  236. return (info->state != FBINFO_STATE_RUNNING ||
  237. vc->vc_mode != KD_TEXT || ops->graphics) &&
  238. !vt_force_oops_output(vc);
  239. }
  240. static int get_color(struct vc_data *vc, struct fb_info *info,
  241. u16 c, int is_fg)
  242. {
  243. int depth = fb_get_color_depth(&info->var, &info->fix);
  244. int color = 0;
  245. if (console_blanked) {
  246. unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
  247. c = vc->vc_video_erase_char & charmask;
  248. }
  249. if (depth != 1)
  250. color = (is_fg) ? attr_fgcol((vc->vc_hi_font_mask) ? 9 : 8, c)
  251. : attr_bgcol((vc->vc_hi_font_mask) ? 13 : 12, c);
  252. switch (depth) {
  253. case 1:
  254. {
  255. int col = mono_col(info);
  256. /* 0 or 1 */
  257. int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0;
  258. int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col;
  259. if (console_blanked)
  260. fg = bg;
  261. color = (is_fg) ? fg : bg;
  262. break;
  263. }
  264. case 2:
  265. /*
  266. * Scale down 16-colors to 4 colors. Default 4-color palette
  267. * is grayscale. However, simply dividing the values by 4
  268. * will not work, as colors 1, 2 and 3 will be scaled-down
  269. * to zero rendering them invisible. So empirically convert
  270. * colors to a sane 4-level grayscale.
  271. */
  272. switch (color) {
  273. case 0:
  274. color = 0; /* black */
  275. break;
  276. case 1 ... 6:
  277. color = 2; /* white */
  278. break;
  279. case 7 ... 8:
  280. color = 1; /* gray */
  281. break;
  282. default:
  283. color = 3; /* intense white */
  284. break;
  285. }
  286. break;
  287. case 3:
  288. /*
  289. * Last 8 entries of default 16-color palette is a more intense
  290. * version of the first 8 (i.e., same chrominance, different
  291. * luminance).
  292. */
  293. color &= 7;
  294. break;
  295. }
  296. return color;
  297. }
  298. static void fb_flashcursor(struct work_struct *work)
  299. {
  300. struct fb_info *info = container_of(work, struct fb_info, queue);
  301. struct fbcon_ops *ops = info->fbcon_par;
  302. struct vc_data *vc = NULL;
  303. int c;
  304. int mode;
  305. int ret;
  306. /* FIXME: we should sort out the unbind locking instead */
  307. /* instead we just fail to flash the cursor if we can't get
  308. * the lock instead of blocking fbcon deinit */
  309. ret = console_trylock();
  310. if (ret == 0)
  311. return;
  312. if (ops && ops->currcon != -1)
  313. vc = vc_cons[ops->currcon].d;
  314. if (!vc || !con_is_visible(vc) ||
  315. registered_fb[con2fb_map[vc->vc_num]] != info ||
  316. vc->vc_deccm != 1) {
  317. console_unlock();
  318. return;
  319. }
  320. c = scr_readw((u16 *) vc->vc_pos);
  321. mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
  322. CM_ERASE : CM_DRAW;
  323. ops->cursor(vc, info, mode, get_color(vc, info, c, 1),
  324. get_color(vc, info, c, 0));
  325. console_unlock();
  326. }
  327. static void cursor_timer_handler(struct timer_list *t)
  328. {
  329. struct fbcon_ops *ops = from_timer(ops, t, cursor_timer);
  330. struct fb_info *info = ops->info;
  331. queue_work(system_power_efficient_wq, &info->queue);
  332. mod_timer(&ops->cursor_timer, jiffies + ops->cur_blink_jiffies);
  333. }
  334. static void fbcon_add_cursor_timer(struct fb_info *info)
  335. {
  336. struct fbcon_ops *ops = info->fbcon_par;
  337. if ((!info->queue.func || info->queue.func == fb_flashcursor) &&
  338. !(ops->flags & FBCON_FLAGS_CURSOR_TIMER) &&
  339. !fbcon_cursor_noblink) {
  340. if (!info->queue.func)
  341. INIT_WORK(&info->queue, fb_flashcursor);
  342. timer_setup(&ops->cursor_timer, cursor_timer_handler, 0);
  343. mod_timer(&ops->cursor_timer, jiffies + ops->cur_blink_jiffies);
  344. ops->flags |= FBCON_FLAGS_CURSOR_TIMER;
  345. }
  346. }
  347. static void fbcon_del_cursor_timer(struct fb_info *info)
  348. {
  349. struct fbcon_ops *ops = info->fbcon_par;
  350. if (info->queue.func == fb_flashcursor &&
  351. ops->flags & FBCON_FLAGS_CURSOR_TIMER) {
  352. del_timer_sync(&ops->cursor_timer);
  353. ops->flags &= ~FBCON_FLAGS_CURSOR_TIMER;
  354. }
  355. }
  356. #ifndef MODULE
  357. static int __init fb_console_setup(char *this_opt)
  358. {
  359. char *options;
  360. int i, j;
  361. if (!this_opt || !*this_opt)
  362. return 1;
  363. while ((options = strsep(&this_opt, ",")) != NULL) {
  364. if (!strncmp(options, "font:", 5)) {
  365. strlcpy(fontname, options + 5, sizeof(fontname));
  366. continue;
  367. }
  368. if (!strncmp(options, "scrollback:", 11)) {
  369. pr_warn("Ignoring scrollback size option\n");
  370. continue;
  371. }
  372. if (!strncmp(options, "map:", 4)) {
  373. options += 4;
  374. if (*options) {
  375. for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
  376. if (!options[j])
  377. j = 0;
  378. con2fb_map_boot[i] =
  379. (options[j++]-'0') % FB_MAX;
  380. }
  381. fbcon_map_override();
  382. }
  383. continue;
  384. }
  385. if (!strncmp(options, "vc:", 3)) {
  386. options += 3;
  387. if (*options)
  388. first_fb_vc = simple_strtoul(options, &options, 10) - 1;
  389. if (first_fb_vc < 0)
  390. first_fb_vc = 0;
  391. if (*options++ == '-')
  392. last_fb_vc = simple_strtoul(options, &options, 10) - 1;
  393. fbcon_is_default = 0;
  394. continue;
  395. }
  396. if (!strncmp(options, "rotate:", 7)) {
  397. options += 7;
  398. if (*options)
  399. initial_rotation = simple_strtoul(options, &options, 0);
  400. if (initial_rotation > 3)
  401. initial_rotation = 0;
  402. continue;
  403. }
  404. if (!strncmp(options, "margin:", 7)) {
  405. options += 7;
  406. if (*options)
  407. margin_color = simple_strtoul(options, &options, 0);
  408. continue;
  409. }
  410. #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
  411. if (!strcmp(options, "nodefer")) {
  412. deferred_takeover = false;
  413. continue;
  414. }
  415. #endif
  416. }
  417. return 1;
  418. }
  419. __setup("fbcon=", fb_console_setup);
  420. #endif
  421. static int search_fb_in_map(int idx)
  422. {
  423. int i, retval = 0;
  424. for (i = first_fb_vc; i <= last_fb_vc; i++) {
  425. if (con2fb_map[i] == idx)
  426. retval = 1;
  427. }
  428. return retval;
  429. }
  430. static int search_for_mapped_con(void)
  431. {
  432. int i, retval = 0;
  433. for (i = first_fb_vc; i <= last_fb_vc; i++) {
  434. if (con2fb_map[i] != -1)
  435. retval = 1;
  436. }
  437. return retval;
  438. }
  439. static int do_fbcon_takeover(int show_logo)
  440. {
  441. int err, i;
  442. if (!num_registered_fb)
  443. return -ENODEV;
  444. if (!show_logo)
  445. logo_shown = FBCON_LOGO_DONTSHOW;
  446. for (i = first_fb_vc; i <= last_fb_vc; i++)
  447. con2fb_map[i] = info_idx;
  448. err = do_take_over_console(&fb_con, first_fb_vc, last_fb_vc,
  449. fbcon_is_default);
  450. if (err) {
  451. for (i = first_fb_vc; i <= last_fb_vc; i++)
  452. con2fb_map[i] = -1;
  453. info_idx = -1;
  454. } else {
  455. fbcon_has_console_bind = 1;
  456. }
  457. return err;
  458. }
  459. #ifdef MODULE
  460. static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
  461. int cols, int rows, int new_cols, int new_rows)
  462. {
  463. logo_shown = FBCON_LOGO_DONTSHOW;
  464. }
  465. #else
  466. static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
  467. int cols, int rows, int new_cols, int new_rows)
  468. {
  469. /* Need to make room for the logo */
  470. struct fbcon_ops *ops = info->fbcon_par;
  471. int cnt, erase = vc->vc_video_erase_char, step;
  472. unsigned short *save = NULL, *r, *q;
  473. int logo_height;
  474. if (info->fbops->owner) {
  475. logo_shown = FBCON_LOGO_DONTSHOW;
  476. return;
  477. }
  478. /*
  479. * remove underline attribute from erase character
  480. * if black and white framebuffer.
  481. */
  482. if (fb_get_color_depth(&info->var, &info->fix) == 1)
  483. erase &= ~0x400;
  484. logo_height = fb_prepare_logo(info, ops->rotate);
  485. logo_lines = DIV_ROUND_UP(logo_height, vc->vc_font.height);
  486. q = (unsigned short *) (vc->vc_origin +
  487. vc->vc_size_row * rows);
  488. step = logo_lines * cols;
  489. for (r = q - logo_lines * cols; r < q; r++)
  490. if (scr_readw(r) != vc->vc_video_erase_char)
  491. break;
  492. if (r != q && new_rows >= rows + logo_lines) {
  493. save = kmalloc(array3_size(logo_lines, new_cols, 2),
  494. GFP_KERNEL);
  495. if (save) {
  496. int i = cols < new_cols ? cols : new_cols;
  497. scr_memsetw(save, erase, logo_lines * new_cols * 2);
  498. r = q - step;
  499. for (cnt = 0; cnt < logo_lines; cnt++, r += i)
  500. scr_memcpyw(save + cnt * new_cols, r, 2 * i);
  501. r = q;
  502. }
  503. }
  504. if (r == q) {
  505. /* We can scroll screen down */
  506. r = q - step - cols;
  507. for (cnt = rows - logo_lines; cnt > 0; cnt--) {
  508. scr_memcpyw(r + step, r, vc->vc_size_row);
  509. r -= cols;
  510. }
  511. if (!save) {
  512. int lines;
  513. if (vc->vc_y + logo_lines >= rows)
  514. lines = rows - vc->vc_y - 1;
  515. else
  516. lines = logo_lines;
  517. vc->vc_y += lines;
  518. vc->vc_pos += lines * vc->vc_size_row;
  519. }
  520. }
  521. scr_memsetw((unsigned short *) vc->vc_origin,
  522. erase,
  523. vc->vc_size_row * logo_lines);
  524. if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) {
  525. fbcon_clear_margins(vc, 0);
  526. update_screen(vc);
  527. }
  528. if (save) {
  529. q = (unsigned short *) (vc->vc_origin +
  530. vc->vc_size_row *
  531. rows);
  532. scr_memcpyw(q, save, logo_lines * new_cols * 2);
  533. vc->vc_y += logo_lines;
  534. vc->vc_pos += logo_lines * vc->vc_size_row;
  535. kfree(save);
  536. }
  537. if (logo_lines > vc->vc_bottom) {
  538. logo_shown = FBCON_LOGO_CANSHOW;
  539. printk(KERN_INFO
  540. "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
  541. } else if (logo_shown != FBCON_LOGO_DONTSHOW) {
  542. logo_shown = FBCON_LOGO_DRAW;
  543. vc->vc_top = logo_lines;
  544. }
  545. }
  546. #endif /* MODULE */
  547. #ifdef CONFIG_FB_TILEBLITTING
  548. static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
  549. {
  550. struct fbcon_ops *ops = info->fbcon_par;
  551. ops->p = &fb_display[vc->vc_num];
  552. if ((info->flags & FBINFO_MISC_TILEBLITTING))
  553. fbcon_set_tileops(vc, info);
  554. else {
  555. fbcon_set_rotation(info);
  556. fbcon_set_bitops(ops);
  557. }
  558. }
  559. static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
  560. {
  561. int err = 0;
  562. if (info->flags & FBINFO_MISC_TILEBLITTING &&
  563. info->tileops->fb_get_tilemax(info) < charcount)
  564. err = 1;
  565. return err;
  566. }
  567. #else
  568. static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
  569. {
  570. struct fbcon_ops *ops = info->fbcon_par;
  571. info->flags &= ~FBINFO_MISC_TILEBLITTING;
  572. ops->p = &fb_display[vc->vc_num];
  573. fbcon_set_rotation(info);
  574. fbcon_set_bitops(ops);
  575. }
  576. static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
  577. {
  578. return 0;
  579. }
  580. #endif /* CONFIG_MISC_TILEBLITTING */
  581. static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
  582. int unit, int oldidx)
  583. {
  584. struct fbcon_ops *ops = NULL;
  585. int err = 0;
  586. if (!try_module_get(info->fbops->owner))
  587. err = -ENODEV;
  588. if (!err && info->fbops->fb_open &&
  589. info->fbops->fb_open(info, 0))
  590. err = -ENODEV;
  591. if (!err) {
  592. ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
  593. if (!ops)
  594. err = -ENOMEM;
  595. }
  596. if (!err) {
  597. ops->cur_blink_jiffies = HZ / 5;
  598. ops->info = info;
  599. info->fbcon_par = ops;
  600. if (vc)
  601. set_blitting_type(vc, info);
  602. }
  603. if (err) {
  604. con2fb_map[unit] = oldidx;
  605. module_put(info->fbops->owner);
  606. }
  607. return err;
  608. }
  609. static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
  610. struct fb_info *newinfo, int unit,
  611. int oldidx, int found)
  612. {
  613. struct fbcon_ops *ops = oldinfo->fbcon_par;
  614. int err = 0, ret;
  615. if (oldinfo->fbops->fb_release &&
  616. oldinfo->fbops->fb_release(oldinfo, 0)) {
  617. con2fb_map[unit] = oldidx;
  618. if (!found && newinfo->fbops->fb_release)
  619. newinfo->fbops->fb_release(newinfo, 0);
  620. if (!found)
  621. module_put(newinfo->fbops->owner);
  622. err = -ENODEV;
  623. }
  624. if (!err) {
  625. fbcon_del_cursor_timer(oldinfo);
  626. kfree(ops->cursor_state.mask);
  627. kfree(ops->cursor_data);
  628. kfree(ops->cursor_src);
  629. kfree(ops->fontbuffer);
  630. kfree(oldinfo->fbcon_par);
  631. oldinfo->fbcon_par = NULL;
  632. module_put(oldinfo->fbops->owner);
  633. /*
  634. If oldinfo and newinfo are driving the same hardware,
  635. the fb_release() method of oldinfo may attempt to
  636. restore the hardware state. This will leave the
  637. newinfo in an undefined state. Thus, a call to
  638. fb_set_par() may be needed for the newinfo.
  639. */
  640. if (newinfo && newinfo->fbops->fb_set_par) {
  641. ret = newinfo->fbops->fb_set_par(newinfo);
  642. if (ret)
  643. printk(KERN_ERR "con2fb_release_oldinfo: "
  644. "detected unhandled fb_set_par error, "
  645. "error code %d\n", ret);
  646. }
  647. }
  648. return err;
  649. }
  650. static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
  651. int unit, int show_logo)
  652. {
  653. struct fbcon_ops *ops = info->fbcon_par;
  654. int ret;
  655. ops->currcon = fg_console;
  656. if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT)) {
  657. ret = info->fbops->fb_set_par(info);
  658. if (ret)
  659. printk(KERN_ERR "con2fb_init_display: detected "
  660. "unhandled fb_set_par error, "
  661. "error code %d\n", ret);
  662. }
  663. ops->flags |= FBCON_FLAGS_INIT;
  664. ops->graphics = 0;
  665. fbcon_set_disp(info, &info->var, unit);
  666. if (show_logo) {
  667. struct vc_data *fg_vc = vc_cons[fg_console].d;
  668. struct fb_info *fg_info =
  669. registered_fb[con2fb_map[fg_console]];
  670. fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
  671. fg_vc->vc_rows, fg_vc->vc_cols,
  672. fg_vc->vc_rows);
  673. }
  674. update_screen(vc_cons[fg_console].d);
  675. }
  676. /**
  677. * set_con2fb_map - map console to frame buffer device
  678. * @unit: virtual console number to map
  679. * @newidx: frame buffer index to map virtual console to
  680. * @user: user request
  681. *
  682. * Maps a virtual console @unit to a frame buffer device
  683. * @newidx.
  684. *
  685. * This should be called with the console lock held.
  686. */
  687. static int set_con2fb_map(int unit, int newidx, int user)
  688. {
  689. struct vc_data *vc = vc_cons[unit].d;
  690. int oldidx = con2fb_map[unit];
  691. struct fb_info *info = registered_fb[newidx];
  692. struct fb_info *oldinfo = NULL;
  693. int found, err = 0;
  694. WARN_CONSOLE_UNLOCKED();
  695. if (oldidx == newidx)
  696. return 0;
  697. if (!info)
  698. return -EINVAL;
  699. if (!search_for_mapped_con() || !con_is_bound(&fb_con)) {
  700. info_idx = newidx;
  701. return do_fbcon_takeover(0);
  702. }
  703. if (oldidx != -1)
  704. oldinfo = registered_fb[oldidx];
  705. found = search_fb_in_map(newidx);
  706. con2fb_map[unit] = newidx;
  707. if (!err && !found)
  708. err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
  709. /*
  710. * If old fb is not mapped to any of the consoles,
  711. * fbcon should release it.
  712. */
  713. if (!err && oldinfo && !search_fb_in_map(oldidx))
  714. err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
  715. found);
  716. if (!err) {
  717. int show_logo = (fg_console == 0 && !user &&
  718. logo_shown != FBCON_LOGO_DONTSHOW);
  719. if (!found)
  720. fbcon_add_cursor_timer(info);
  721. con2fb_map_boot[unit] = newidx;
  722. con2fb_init_display(vc, info, unit, show_logo);
  723. }
  724. if (!search_fb_in_map(info_idx))
  725. info_idx = newidx;
  726. return err;
  727. }
  728. /*
  729. * Low Level Operations
  730. */
  731. /* NOTE: fbcon cannot be __init: it may be called from do_take_over_console later */
  732. static int var_to_display(struct display *disp,
  733. struct fb_var_screeninfo *var,
  734. struct fb_info *info)
  735. {
  736. disp->xres_virtual = var->xres_virtual;
  737. disp->yres_virtual = var->yres_virtual;
  738. disp->bits_per_pixel = var->bits_per_pixel;
  739. disp->grayscale = var->grayscale;
  740. disp->nonstd = var->nonstd;
  741. disp->accel_flags = var->accel_flags;
  742. disp->height = var->height;
  743. disp->width = var->width;
  744. disp->red = var->red;
  745. disp->green = var->green;
  746. disp->blue = var->blue;
  747. disp->transp = var->transp;
  748. disp->rotate = var->rotate;
  749. disp->mode = fb_match_mode(var, &info->modelist);
  750. if (disp->mode == NULL)
  751. /* This should not happen */
  752. return -EINVAL;
  753. return 0;
  754. }
  755. static void display_to_var(struct fb_var_screeninfo *var,
  756. struct display *disp)
  757. {
  758. fb_videomode_to_var(var, disp->mode);
  759. var->xres_virtual = disp->xres_virtual;
  760. var->yres_virtual = disp->yres_virtual;
  761. var->bits_per_pixel = disp->bits_per_pixel;
  762. var->grayscale = disp->grayscale;
  763. var->nonstd = disp->nonstd;
  764. var->accel_flags = disp->accel_flags;
  765. var->height = disp->height;
  766. var->width = disp->width;
  767. var->red = disp->red;
  768. var->green = disp->green;
  769. var->blue = disp->blue;
  770. var->transp = disp->transp;
  771. var->rotate = disp->rotate;
  772. }
  773. static const char *fbcon_startup(void)
  774. {
  775. const char *display_desc = "frame buffer device";
  776. struct display *p = &fb_display[fg_console];
  777. struct vc_data *vc = vc_cons[fg_console].d;
  778. const struct font_desc *font = NULL;
  779. struct module *owner;
  780. struct fb_info *info = NULL;
  781. struct fbcon_ops *ops;
  782. int rows, cols;
  783. /*
  784. * If num_registered_fb is zero, this is a call for the dummy part.
  785. * The frame buffer devices weren't initialized yet.
  786. */
  787. if (!num_registered_fb || info_idx == -1)
  788. return display_desc;
  789. /*
  790. * Instead of blindly using registered_fb[0], we use info_idx, set by
  791. * fb_console_init();
  792. */
  793. info = registered_fb[info_idx];
  794. if (!info)
  795. return NULL;
  796. owner = info->fbops->owner;
  797. if (!try_module_get(owner))
  798. return NULL;
  799. if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
  800. module_put(owner);
  801. return NULL;
  802. }
  803. ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
  804. if (!ops) {
  805. module_put(owner);
  806. return NULL;
  807. }
  808. ops->currcon = -1;
  809. ops->graphics = 1;
  810. ops->cur_rotate = -1;
  811. ops->cur_blink_jiffies = HZ / 5;
  812. ops->info = info;
  813. info->fbcon_par = ops;
  814. p->con_rotate = initial_rotation;
  815. if (p->con_rotate == -1)
  816. p->con_rotate = info->fbcon_rotate_hint;
  817. if (p->con_rotate == -1)
  818. p->con_rotate = FB_ROTATE_UR;
  819. set_blitting_type(vc, info);
  820. /* Setup default font */
  821. if (!p->fontdata && !vc->vc_font.data) {
  822. if (!fontname[0] || !(font = find_font(fontname)))
  823. font = get_default_font(info->var.xres,
  824. info->var.yres,
  825. info->pixmap.blit_x,
  826. info->pixmap.blit_y);
  827. vc->vc_font.width = font->width;
  828. vc->vc_font.height = font->height;
  829. vc->vc_font.data = (void *)(p->fontdata = font->data);
  830. vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
  831. } else {
  832. p->fontdata = vc->vc_font.data;
  833. }
  834. cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
  835. rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
  836. cols /= vc->vc_font.width;
  837. rows /= vc->vc_font.height;
  838. vc_resize(vc, cols, rows);
  839. DPRINTK("mode: %s\n", info->fix.id);
  840. DPRINTK("visual: %d\n", info->fix.visual);
  841. DPRINTK("res: %dx%d-%d\n", info->var.xres,
  842. info->var.yres,
  843. info->var.bits_per_pixel);
  844. fbcon_add_cursor_timer(info);
  845. fbcon_has_exited = 0;
  846. return display_desc;
  847. }
  848. static void fbcon_init(struct vc_data *vc, int init)
  849. {
  850. struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
  851. struct fbcon_ops *ops;
  852. struct vc_data **default_mode = vc->vc_display_fg;
  853. struct vc_data *svc = *default_mode;
  854. struct display *t, *p = &fb_display[vc->vc_num];
  855. int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
  856. int cap, ret;
  857. if (info_idx == -1 || info == NULL)
  858. return;
  859. cap = info->flags;
  860. if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
  861. (info->fix.type == FB_TYPE_TEXT))
  862. logo = 0;
  863. if (var_to_display(p, &info->var, info))
  864. return;
  865. if (!info->fbcon_par)
  866. con2fb_acquire_newinfo(vc, info, vc->vc_num, -1);
  867. /* If we are not the first console on this
  868. fb, copy the font from that console */
  869. t = &fb_display[fg_console];
  870. if (!p->fontdata) {
  871. if (t->fontdata) {
  872. struct vc_data *fvc = vc_cons[fg_console].d;
  873. vc->vc_font.data = (void *)(p->fontdata =
  874. fvc->vc_font.data);
  875. vc->vc_font.width = fvc->vc_font.width;
  876. vc->vc_font.height = fvc->vc_font.height;
  877. p->userfont = t->userfont;
  878. if (p->userfont)
  879. REFCOUNT(p->fontdata)++;
  880. } else {
  881. const struct font_desc *font = NULL;
  882. if (!fontname[0] || !(font = find_font(fontname)))
  883. font = get_default_font(info->var.xres,
  884. info->var.yres,
  885. info->pixmap.blit_x,
  886. info->pixmap.blit_y);
  887. vc->vc_font.width = font->width;
  888. vc->vc_font.height = font->height;
  889. vc->vc_font.data = (void *)(p->fontdata = font->data);
  890. vc->vc_font.charcount = 256; /* FIXME Need to
  891. support more fonts */
  892. }
  893. }
  894. if (p->userfont)
  895. charcnt = FNTCHARCNT(p->fontdata);
  896. vc->vc_panic_force_write = !!(info->flags & FBINFO_CAN_FORCE_OUTPUT);
  897. vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
  898. vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
  899. if (charcnt == 256) {
  900. vc->vc_hi_font_mask = 0;
  901. } else {
  902. vc->vc_hi_font_mask = 0x100;
  903. if (vc->vc_can_do_color)
  904. vc->vc_complement_mask <<= 1;
  905. }
  906. if (!*svc->vc_uni_pagedir_loc)
  907. con_set_default_unimap(svc);
  908. if (!*vc->vc_uni_pagedir_loc)
  909. con_copy_unimap(vc, svc);
  910. ops = info->fbcon_par;
  911. ops->cur_blink_jiffies = msecs_to_jiffies(vc->vc_cur_blink_ms);
  912. p->con_rotate = initial_rotation;
  913. if (p->con_rotate == -1)
  914. p->con_rotate = info->fbcon_rotate_hint;
  915. if (p->con_rotate == -1)
  916. p->con_rotate = FB_ROTATE_UR;
  917. set_blitting_type(vc, info);
  918. cols = vc->vc_cols;
  919. rows = vc->vc_rows;
  920. new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
  921. new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
  922. new_cols /= vc->vc_font.width;
  923. new_rows /= vc->vc_font.height;
  924. /*
  925. * We must always set the mode. The mode of the previous console
  926. * driver could be in the same resolution but we are using different
  927. * hardware so we have to initialize the hardware.
  928. *
  929. * We need to do it in fbcon_init() to prevent screen corruption.
  930. */
  931. if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) {
  932. if (info->fbops->fb_set_par &&
  933. !(ops->flags & FBCON_FLAGS_INIT)) {
  934. ret = info->fbops->fb_set_par(info);
  935. if (ret)
  936. printk(KERN_ERR "fbcon_init: detected "
  937. "unhandled fb_set_par error, "
  938. "error code %d\n", ret);
  939. }
  940. ops->flags |= FBCON_FLAGS_INIT;
  941. }
  942. ops->graphics = 0;
  943. if ((cap & FBINFO_HWACCEL_COPYAREA) &&
  944. !(cap & FBINFO_HWACCEL_DISABLED))
  945. p->scrollmode = SCROLL_MOVE;
  946. else /* default to something safe */
  947. p->scrollmode = SCROLL_REDRAW;
  948. /*
  949. * ++guenther: console.c:vc_allocate() relies on initializing
  950. * vc_{cols,rows}, but we must not set those if we are only
  951. * resizing the console.
  952. */
  953. if (init) {
  954. vc->vc_cols = new_cols;
  955. vc->vc_rows = new_rows;
  956. } else
  957. vc_resize(vc, new_cols, new_rows);
  958. if (logo)
  959. fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
  960. if (ops->rotate_font && ops->rotate_font(info, vc)) {
  961. ops->rotate = FB_ROTATE_UR;
  962. set_blitting_type(vc, info);
  963. }
  964. ops->p = &fb_display[fg_console];
  965. }
  966. static void fbcon_free_font(struct display *p, bool freefont)
  967. {
  968. if (freefont && p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
  969. kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
  970. p->fontdata = NULL;
  971. p->userfont = 0;
  972. }
  973. static void set_vc_hi_font(struct vc_data *vc, bool set);
  974. static void fbcon_deinit(struct vc_data *vc)
  975. {
  976. struct display *p = &fb_display[vc->vc_num];
  977. struct fb_info *info;
  978. struct fbcon_ops *ops;
  979. int idx;
  980. bool free_font = true;
  981. idx = con2fb_map[vc->vc_num];
  982. if (idx == -1)
  983. goto finished;
  984. info = registered_fb[idx];
  985. if (!info)
  986. goto finished;
  987. if (info->flags & FBINFO_MISC_FIRMWARE)
  988. free_font = false;
  989. ops = info->fbcon_par;
  990. if (!ops)
  991. goto finished;
  992. if (con_is_visible(vc))
  993. fbcon_del_cursor_timer(info);
  994. ops->flags &= ~FBCON_FLAGS_INIT;
  995. finished:
  996. fbcon_free_font(p, free_font);
  997. if (free_font)
  998. vc->vc_font.data = NULL;
  999. if (vc->vc_hi_font_mask && vc->vc_screenbuf)
  1000. set_vc_hi_font(vc, false);
  1001. if (!con_is_bound(&fb_con))
  1002. fbcon_exit();
  1003. if (vc->vc_num == logo_shown)
  1004. logo_shown = FBCON_LOGO_CANSHOW;
  1005. return;
  1006. }
  1007. /* ====================================================================== */
  1008. /* fbcon_XXX routines - interface used by the world
  1009. *
  1010. * This system is now divided into two levels because of complications
  1011. * caused by hardware scrolling. Top level functions:
  1012. *
  1013. * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
  1014. *
  1015. * handles y values in range [0, scr_height-1] that correspond to real
  1016. * screen positions. y_wrap shift means that first line of bitmap may be
  1017. * anywhere on this display. These functions convert lineoffsets to
  1018. * bitmap offsets and deal with the wrap-around case by splitting blits.
  1019. *
  1020. * fbcon_bmove_physical_8() -- These functions fast implementations
  1021. * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
  1022. * fbcon_putc_physical_8() -- (font width != 8) may be added later
  1023. *
  1024. * WARNING:
  1025. *
  1026. * At the moment fbcon_putc() cannot blit across vertical wrap boundary
  1027. * Implies should only really hardware scroll in rows. Only reason for
  1028. * restriction is simplicity & efficiency at the moment.
  1029. */
  1030. static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
  1031. int width)
  1032. {
  1033. struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
  1034. struct fbcon_ops *ops = info->fbcon_par;
  1035. struct display *p = &fb_display[vc->vc_num];
  1036. u_int y_break;
  1037. if (fbcon_is_inactive(vc, info))
  1038. return;
  1039. if (!height || !width)
  1040. return;
  1041. if (sy < vc->vc_top && vc->vc_top == logo_lines) {
  1042. vc->vc_top = 0;
  1043. /*
  1044. * If the font dimensions are not an integral of the display
  1045. * dimensions then the ops->clear below won't end up clearing
  1046. * the margins. Call clear_margins here in case the logo
  1047. * bitmap stretched into the margin area.
  1048. */
  1049. fbcon_clear_margins(vc, 0);
  1050. }
  1051. /* Split blits that cross physical y_wrap boundary */
  1052. y_break = p->vrows - p->yscroll;
  1053. if (sy < y_break && sy + height - 1 >= y_break) {
  1054. u_int b = y_break - sy;
  1055. ops->clear(vc, info, real_y(p, sy), sx, b, width);
  1056. ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
  1057. width);
  1058. } else
  1059. ops->clear(vc, info, real_y(p, sy), sx, height, width);
  1060. }
  1061. static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
  1062. int count, int ypos, int xpos)
  1063. {
  1064. struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
  1065. struct display *p = &fb_display[vc->vc_num];
  1066. struct fbcon_ops *ops = info->fbcon_par;
  1067. if (!fbcon_is_inactive(vc, info))
  1068. ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
  1069. get_color(vc, info, scr_readw(s), 1),
  1070. get_color(vc, info, scr_readw(s), 0));
  1071. }
  1072. static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
  1073. {
  1074. unsigned short chr;
  1075. scr_writew(c, &chr);
  1076. fbcon_putcs(vc, &chr, 1, ypos, xpos);
  1077. }
  1078. static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
  1079. {
  1080. struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
  1081. struct fbcon_ops *ops = info->fbcon_par;
  1082. if (!fbcon_is_inactive(vc, info))
  1083. ops->clear_margins(vc, info, margin_color, bottom_only);
  1084. }
  1085. static void fbcon_cursor(struct vc_data *vc, int mode)
  1086. {
  1087. struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
  1088. struct fbcon_ops *ops = info->fbcon_par;
  1089. int c = scr_readw((u16 *) vc->vc_pos);
  1090. ops->cur_blink_jiffies = msecs_to_jiffies(vc->vc_cur_blink_ms);
  1091. if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1)
  1092. return;
  1093. if (vc->vc_cursor_type & 0x10)
  1094. fbcon_del_cursor_timer(info);
  1095. else
  1096. fbcon_add_cursor_timer(info);
  1097. ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
  1098. if (!ops->cursor)
  1099. return;
  1100. ops->cursor(vc, info, mode, get_color(vc, info, c, 1),
  1101. get_color(vc, info, c, 0));
  1102. }
  1103. static int scrollback_phys_max = 0;
  1104. static int scrollback_max = 0;
  1105. static int scrollback_current = 0;
  1106. static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
  1107. int unit)
  1108. {
  1109. struct display *p, *t;
  1110. struct vc_data **default_mode, *vc;
  1111. struct vc_data *svc;
  1112. struct fbcon_ops *ops = info->fbcon_par;
  1113. int rows, cols, charcnt = 256;
  1114. p = &fb_display[unit];
  1115. if (var_to_display(p, var, info))
  1116. return;
  1117. vc = vc_cons[unit].d;
  1118. if (!vc)
  1119. return;
  1120. default_mode = vc->vc_display_fg;
  1121. svc = *default_mode;
  1122. t = &fb_display[svc->vc_num];
  1123. if (!vc->vc_font.data) {
  1124. vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
  1125. vc->vc_font.width = (*default_mode)->vc_font.width;
  1126. vc->vc_font.height = (*default_mode)->vc_font.height;
  1127. p->userfont = t->userfont;
  1128. if (p->userfont)
  1129. REFCOUNT(p->fontdata)++;
  1130. }
  1131. if (p->userfont)
  1132. charcnt = FNTCHARCNT(p->fontdata);
  1133. var->activate = FB_ACTIVATE_NOW;
  1134. info->var.activate = var->activate;
  1135. var->yoffset = info->var.yoffset;
  1136. var->xoffset = info->var.xoffset;
  1137. fb_set_var(info, var);
  1138. ops->var = info->var;
  1139. vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
  1140. vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
  1141. if (charcnt == 256) {
  1142. vc->vc_hi_font_mask = 0;
  1143. } else {
  1144. vc->vc_hi_font_mask = 0x100;
  1145. if (vc->vc_can_do_color)
  1146. vc->vc_complement_mask <<= 1;
  1147. }
  1148. if (!*svc->vc_uni_pagedir_loc)
  1149. con_set_default_unimap(svc);
  1150. if (!*vc->vc_uni_pagedir_loc)
  1151. con_copy_unimap(vc, svc);
  1152. cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
  1153. rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
  1154. cols /= vc->vc_font.width;
  1155. rows /= vc->vc_font.height;
  1156. vc_resize(vc, cols, rows);
  1157. if (con_is_visible(vc)) {
  1158. update_screen(vc);
  1159. }
  1160. }
  1161. static __inline__ void ywrap_up(struct vc_data *vc, int count)
  1162. {
  1163. struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
  1164. struct fbcon_ops *ops = info->fbcon_par;
  1165. struct display *p = &fb_display[vc->vc_num];
  1166. p->yscroll += count;
  1167. if (p->yscroll >= p->vrows) /* Deal with wrap */
  1168. p->yscroll -= p->vrows;
  1169. ops->var.xoffset = 0;
  1170. ops->var.yoffset = p->yscroll * vc->vc_font.height;
  1171. ops->var.vmode |= FB_VMODE_YWRAP;
  1172. ops->update_start(info);
  1173. scrollback_max += count;
  1174. if (scrollback_max > scrollback_phys_max)
  1175. scrollback_max = scrollback_phys_max;
  1176. scrollback_current = 0;
  1177. }
  1178. static __inline__ void ywrap_down(struct vc_data *vc, int count)
  1179. {
  1180. struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
  1181. struct fbcon_ops *ops = info->fbcon_par;
  1182. struct display *p = &fb_display[vc->vc_num];
  1183. p->yscroll -= count;
  1184. if (p->yscroll < 0) /* Deal with wrap */
  1185. p->yscroll += p->vrows;
  1186. ops->var.xoffset = 0;
  1187. ops->var.yoffset = p->yscroll * vc->vc_font.height;
  1188. ops->var.vmode |= FB_VMODE_YWRAP;
  1189. ops->update_start(info);
  1190. scrollback_max -= count;
  1191. if (scrollback_max < 0)
  1192. scrollback_max = 0;
  1193. scrollback_current = 0;
  1194. }
  1195. static __inline__ void ypan_up(struct vc_data *vc, int count)
  1196. {
  1197. struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
  1198. struct display *p = &fb_display[vc->vc_num];
  1199. struct fbcon_ops *ops = info->fbcon_par;
  1200. p->yscroll += count;
  1201. if (p->yscroll > p->vrows - vc->vc_rows) {
  1202. ops->bmove(vc, info, p->vrows - vc->vc_rows,
  1203. 0, 0, 0, vc->vc_rows, vc->vc_cols);
  1204. p->yscroll -= p->vrows - vc->vc_rows;
  1205. }
  1206. ops->var.xoffset = 0;
  1207. ops->var.yoffset = p->yscroll * vc->vc_font.height;
  1208. ops->var.vmode &= ~FB_VMODE_YWRAP;
  1209. ops->update_start(info);
  1210. fbcon_clear_margins(vc, 1);
  1211. scrollback_max += count;
  1212. if (scrollback_max > scrollback_phys_max)
  1213. scrollback_max = scrollback_phys_max;
  1214. scrollback_current = 0;
  1215. }
  1216. static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
  1217. {
  1218. struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
  1219. struct fbcon_ops *ops = info->fbcon_par;
  1220. struct display *p = &fb_display[vc->vc_num];
  1221. p->yscroll += count;
  1222. if (p->yscroll > p->vrows - vc->vc_rows) {
  1223. p->yscroll -= p->vrows - vc->vc_rows;
  1224. fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
  1225. }
  1226. ops->var.xoffset = 0;
  1227. ops->var.yoffset = p->yscroll * vc->vc_font.height;
  1228. ops->var.vmode &= ~FB_VMODE_YWRAP;
  1229. ops->update_start(info);
  1230. fbcon_clear_margins(vc, 1);
  1231. scrollback_max += count;
  1232. if (scrollback_max > scrollback_phys_max)
  1233. scrollback_max = scrollback_phys_max;
  1234. scrollback_current = 0;
  1235. }
  1236. static __inline__ void ypan_down(struct vc_data *vc, int count)
  1237. {
  1238. struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
  1239. struct display *p = &fb_display[vc->vc_num];
  1240. struct fbcon_ops *ops = info->fbcon_par;
  1241. p->yscroll -= count;
  1242. if (p->yscroll < 0) {
  1243. ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
  1244. 0, vc->vc_rows, vc->vc_cols);
  1245. p->yscroll += p->vrows - vc->vc_rows;
  1246. }
  1247. ops->var.xoffset = 0;
  1248. ops->var.yoffset = p->yscroll * vc->vc_font.height;
  1249. ops->var.vmode &= ~FB_VMODE_YWRAP;
  1250. ops->update_start(info);
  1251. fbcon_clear_margins(vc, 1);
  1252. scrollback_max -= count;
  1253. if (scrollback_max < 0)
  1254. scrollback_max = 0;
  1255. scrollback_current = 0;
  1256. }
  1257. static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
  1258. {
  1259. struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
  1260. struct fbcon_ops *ops = info->fbcon_par;
  1261. struct display *p = &fb_display[vc->vc_num];
  1262. p->yscroll -= count;
  1263. if (p->yscroll < 0) {
  1264. p->yscroll += p->vrows - vc->vc_rows;
  1265. fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
  1266. }
  1267. ops->var.xoffset = 0;
  1268. ops->var.yoffset = p->yscroll * vc->vc_font.height;
  1269. ops->var.vmode &= ~FB_VMODE_YWRAP;
  1270. ops->update_start(info);
  1271. fbcon_clear_margins(vc, 1);
  1272. scrollback_max -= count;
  1273. if (scrollback_max < 0)
  1274. scrollback_max = 0;
  1275. scrollback_current = 0;
  1276. }
  1277. static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
  1278. int line, int count, int dy)
  1279. {
  1280. unsigned short *s = (unsigned short *)
  1281. (vc->vc_origin + vc->vc_size_row * line);
  1282. while (count--) {
  1283. unsigned short *start = s;
  1284. unsigned short *le = advance_row(s, 1);
  1285. unsigned short c;
  1286. int x = 0;
  1287. unsigned short attr = 1;
  1288. do {
  1289. c = scr_readw(s);
  1290. if (attr != (c & 0xff00)) {
  1291. attr = c & 0xff00;
  1292. if (s > start) {
  1293. fbcon_putcs(vc, start, s - start,
  1294. dy, x);
  1295. x += s - start;
  1296. start = s;
  1297. }
  1298. }
  1299. console_conditional_schedule();
  1300. s++;
  1301. } while (s < le);
  1302. if (s > start)
  1303. fbcon_putcs(vc, start, s - start, dy, x);
  1304. console_conditional_schedule();
  1305. dy++;
  1306. }
  1307. }
  1308. static void fbcon_redraw_blit(struct vc_data *vc, struct fb_info *info,
  1309. struct display *p, int line, int count, int ycount)
  1310. {
  1311. int offset = ycount * vc->vc_cols;
  1312. unsigned short *d = (unsigned short *)
  1313. (vc->vc_origin + vc->vc_size_row * line);
  1314. unsigned short *s = d + offset;
  1315. struct fbcon_ops *ops = info->fbcon_par;
  1316. while (count--) {
  1317. unsigned short *start = s;
  1318. unsigned short *le = advance_row(s, 1);
  1319. unsigned short c;
  1320. int x = 0;
  1321. do {
  1322. c = scr_readw(s);
  1323. if (c == scr_readw(d)) {
  1324. if (s > start) {
  1325. ops->bmove(vc, info, line + ycount, x,
  1326. line, x, 1, s-start);
  1327. x += s - start + 1;
  1328. start = s + 1;
  1329. } else {
  1330. x++;
  1331. start++;
  1332. }
  1333. }
  1334. scr_writew(c, d);
  1335. console_conditional_schedule();
  1336. s++;
  1337. d++;
  1338. } while (s < le);
  1339. if (s > start)
  1340. ops->bmove(vc, info, line + ycount, x, line, x, 1,
  1341. s-start);
  1342. console_conditional_schedule();
  1343. if (ycount > 0)
  1344. line++;
  1345. else {
  1346. line--;
  1347. /* NOTE: We subtract two lines from these pointers */
  1348. s -= vc->vc_size_row;
  1349. d -= vc->vc_size_row;
  1350. }
  1351. }
  1352. }
  1353. static void fbcon_redraw(struct vc_data *vc, struct display *p,
  1354. int line, int count, int offset)
  1355. {
  1356. unsigned short *d = (unsigned short *)
  1357. (vc->vc_origin + vc->vc_size_row * line);
  1358. unsigned short *s = d + offset;
  1359. while (count--) {
  1360. unsigned short *start = s;
  1361. unsigned short *le = advance_row(s, 1);
  1362. unsigned short c;
  1363. int x = 0;
  1364. unsigned short attr = 1;
  1365. do {
  1366. c = scr_readw(s);
  1367. if (attr != (c & 0xff00)) {
  1368. attr = c & 0xff00;
  1369. if (s > start) {
  1370. fbcon_putcs(vc, start, s - start,
  1371. line, x);
  1372. x += s - start;
  1373. start = s;
  1374. }
  1375. }
  1376. if (c == scr_readw(d)) {
  1377. if (s > start) {
  1378. fbcon_putcs(vc, start, s - start,
  1379. line, x);
  1380. x += s - start + 1;
  1381. start = s + 1;
  1382. } else {
  1383. x++;
  1384. start++;
  1385. }
  1386. }
  1387. scr_writew(c, d);
  1388. console_conditional_schedule();
  1389. s++;
  1390. d++;
  1391. } while (s < le);
  1392. if (s > start)
  1393. fbcon_putcs(vc, start, s - start, line, x);
  1394. console_conditional_schedule();
  1395. if (offset > 0)
  1396. line++;
  1397. else {
  1398. line--;
  1399. /* NOTE: We subtract two lines from these pointers */
  1400. s -= vc->vc_size_row;
  1401. d -= vc->vc_size_row;
  1402. }
  1403. }
  1404. }
  1405. static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b,
  1406. enum con_scroll dir, unsigned int count)
  1407. {
  1408. struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
  1409. struct display *p = &fb_display[vc->vc_num];
  1410. int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
  1411. if (fbcon_is_inactive(vc, info))
  1412. return true;
  1413. fbcon_cursor(vc, CM_ERASE);
  1414. /*
  1415. * ++Geert: Only use ywrap/ypan if the console is in text mode
  1416. * ++Andrew: Only use ypan on hardware text mode when scrolling the
  1417. * whole screen (prevents flicker).
  1418. */
  1419. switch (dir) {
  1420. case SM_UP:
  1421. if (count > vc->vc_rows) /* Maximum realistic size */
  1422. count = vc->vc_rows;
  1423. if (logo_shown >= 0)
  1424. goto redraw_up;
  1425. switch (p->scrollmode) {
  1426. case SCROLL_MOVE:
  1427. fbcon_redraw_blit(vc, info, p, t, b - t - count,
  1428. count);
  1429. fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
  1430. scr_memsetw((unsigned short *) (vc->vc_origin +
  1431. vc->vc_size_row *
  1432. (b - count)),
  1433. vc->vc_video_erase_char,
  1434. vc->vc_size_row * count);
  1435. return true;
  1436. break;
  1437. case SCROLL_WRAP_MOVE:
  1438. if (b - t - count > 3 * vc->vc_rows >> 2) {
  1439. if (t > 0)
  1440. fbcon_bmove(vc, 0, 0, count, 0, t,
  1441. vc->vc_cols);
  1442. ywrap_up(vc, count);
  1443. if (vc->vc_rows - b > 0)
  1444. fbcon_bmove(vc, b - count, 0, b, 0,
  1445. vc->vc_rows - b,
  1446. vc->vc_cols);
  1447. } else if (info->flags & FBINFO_READS_FAST)
  1448. fbcon_bmove(vc, t + count, 0, t, 0,
  1449. b - t - count, vc->vc_cols);
  1450. else
  1451. goto redraw_up;
  1452. fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
  1453. break;
  1454. case SCROLL_PAN_REDRAW:
  1455. if ((p->yscroll + count <=
  1456. 2 * (p->vrows - vc->vc_rows))
  1457. && ((!scroll_partial && (b - t == vc->vc_rows))
  1458. || (scroll_partial
  1459. && (b - t - count >
  1460. 3 * vc->vc_rows >> 2)))) {
  1461. if (t > 0)
  1462. fbcon_redraw_move(vc, p, 0, t, count);
  1463. ypan_up_redraw(vc, t, count);
  1464. if (vc->vc_rows - b > 0)
  1465. fbcon_redraw_move(vc, p, b,
  1466. vc->vc_rows - b, b);
  1467. } else
  1468. fbcon_redraw_move(vc, p, t + count, b - t - count, t);
  1469. fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
  1470. break;
  1471. case SCROLL_PAN_MOVE:
  1472. if ((p->yscroll + count <=
  1473. 2 * (p->vrows - vc->vc_rows))
  1474. && ((!scroll_partial && (b - t == vc->vc_rows))
  1475. || (scroll_partial
  1476. && (b - t - count >
  1477. 3 * vc->vc_rows >> 2)))) {
  1478. if (t > 0)
  1479. fbcon_bmove(vc, 0, 0, count, 0, t,
  1480. vc->vc_cols);
  1481. ypan_up(vc, count);
  1482. if (vc->vc_rows - b > 0)
  1483. fbcon_bmove(vc, b - count, 0, b, 0,
  1484. vc->vc_rows - b,
  1485. vc->vc_cols);
  1486. } else if (info->flags & FBINFO_READS_FAST)
  1487. fbcon_bmove(vc, t + count, 0, t, 0,
  1488. b - t - count, vc->vc_cols);
  1489. else
  1490. goto redraw_up;
  1491. fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
  1492. break;
  1493. case SCROLL_REDRAW:
  1494. redraw_up:
  1495. fbcon_redraw(vc, p, t, b - t - count,
  1496. count * vc->vc_cols);
  1497. fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
  1498. scr_memsetw((unsigned short *) (vc->vc_origin +
  1499. vc->vc_size_row *
  1500. (b - count)),
  1501. vc->vc_video_erase_char,
  1502. vc->vc_size_row * count);
  1503. return true;
  1504. }
  1505. break;
  1506. case SM_DOWN:
  1507. if (count > vc->vc_rows) /* Maximum realistic size */
  1508. count = vc->vc_rows;
  1509. if (logo_shown >= 0)
  1510. goto redraw_down;
  1511. switch (p->scrollmode) {
  1512. case SCROLL_MOVE:
  1513. fbcon_redraw_blit(vc, info, p, b - 1, b - t - count,
  1514. -count);
  1515. fbcon_clear(vc, t, 0, count, vc->vc_cols);
  1516. scr_memsetw((unsigned short *) (vc->vc_origin +
  1517. vc->vc_size_row *
  1518. t),
  1519. vc->vc_video_erase_char,
  1520. vc->vc_size_row * count);
  1521. return true;
  1522. break;
  1523. case SCROLL_WRAP_MOVE:
  1524. if (b - t - count > 3 * vc->vc_rows >> 2) {
  1525. if (vc->vc_rows - b > 0)
  1526. fbcon_bmove(vc, b, 0, b - count, 0,
  1527. vc->vc_rows - b,
  1528. vc->vc_cols);
  1529. ywrap_down(vc, count);
  1530. if (t > 0)
  1531. fbcon_bmove(vc, count, 0, 0, 0, t,
  1532. vc->vc_cols);
  1533. } else if (info->flags & FBINFO_READS_FAST)
  1534. fbcon_bmove(vc, t, 0, t + count, 0,
  1535. b - t - count, vc->vc_cols);
  1536. else
  1537. goto redraw_down;
  1538. fbcon_clear(vc, t, 0, count, vc->vc_cols);
  1539. break;
  1540. case SCROLL_PAN_MOVE:
  1541. if ((count - p->yscroll <= p->vrows - vc->vc_rows)
  1542. && ((!scroll_partial && (b - t == vc->vc_rows))
  1543. || (scroll_partial
  1544. && (b - t - count >
  1545. 3 * vc->vc_rows >> 2)))) {
  1546. if (vc->vc_rows - b > 0)
  1547. fbcon_bmove(vc, b, 0, b - count, 0,
  1548. vc->vc_rows - b,
  1549. vc->vc_cols);
  1550. ypan_down(vc, count);
  1551. if (t > 0)
  1552. fbcon_bmove(vc, count, 0, 0, 0, t,
  1553. vc->vc_cols);
  1554. } else if (info->flags & FBINFO_READS_FAST)
  1555. fbcon_bmove(vc, t, 0, t + count, 0,
  1556. b - t - count, vc->vc_cols);
  1557. else
  1558. goto redraw_down;
  1559. fbcon_clear(vc, t, 0, count, vc->vc_cols);
  1560. break;
  1561. case SCROLL_PAN_REDRAW:
  1562. if ((count - p->yscroll <= p->vrows - vc->vc_rows)
  1563. && ((!scroll_partial && (b - t == vc->vc_rows))
  1564. || (scroll_partial
  1565. && (b - t - count >
  1566. 3 * vc->vc_rows >> 2)))) {
  1567. if (vc->vc_rows - b > 0)
  1568. fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
  1569. b - count);
  1570. ypan_down_redraw(vc, t, count);
  1571. if (t > 0)
  1572. fbcon_redraw_move(vc, p, count, t, 0);
  1573. } else
  1574. fbcon_redraw_move(vc, p, t, b - t - count, t + count);
  1575. fbcon_clear(vc, t, 0, count, vc->vc_cols);
  1576. break;
  1577. case SCROLL_REDRAW:
  1578. redraw_down:
  1579. fbcon_redraw(vc, p, b - 1, b - t - count,
  1580. -count * vc->vc_cols);
  1581. fbcon_clear(vc, t, 0, count, vc->vc_cols);
  1582. scr_memsetw((unsigned short *) (vc->vc_origin +
  1583. vc->vc_size_row *
  1584. t),
  1585. vc->vc_video_erase_char,
  1586. vc->vc_size_row * count);
  1587. return true;
  1588. }
  1589. }
  1590. return false;
  1591. }
  1592. static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
  1593. int height, int width)
  1594. {
  1595. struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
  1596. struct display *p = &fb_display[vc->vc_num];
  1597. if (fbcon_is_inactive(vc, info))
  1598. return;
  1599. if (!width || !height)
  1600. return;
  1601. /* Split blits that cross physical y_wrap case.
  1602. * Pathological case involves 4 blits, better to use recursive
  1603. * code rather than unrolled case
  1604. *
  1605. * Recursive invocations don't need to erase the cursor over and
  1606. * over again, so we use fbcon_bmove_rec()
  1607. */
  1608. fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
  1609. p->vrows - p->yscroll);
  1610. }
  1611. static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
  1612. int dy, int dx, int height, int width, u_int y_break)
  1613. {
  1614. struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
  1615. struct fbcon_ops *ops = info->fbcon_par;
  1616. u_int b;
  1617. if (sy < y_break && sy + height > y_break) {
  1618. b = y_break - sy;
  1619. if (dy < sy) { /* Avoid trashing self */
  1620. fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
  1621. y_break);
  1622. fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
  1623. height - b, width, y_break);
  1624. } else {
  1625. fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
  1626. height - b, width, y_break);
  1627. fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
  1628. y_break);
  1629. }
  1630. return;
  1631. }
  1632. if (dy < y_break && dy + height > y_break) {
  1633. b = y_break - dy;
  1634. if (dy < sy) { /* Avoid trashing self */
  1635. fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
  1636. y_break);
  1637. fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
  1638. height - b, width, y_break);
  1639. } else {
  1640. fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
  1641. height - b, width, y_break);
  1642. fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
  1643. y_break);
  1644. }
  1645. return;
  1646. }
  1647. ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
  1648. height, width);
  1649. }
  1650. static void updatescrollmode(struct display *p,
  1651. struct fb_info *info,
  1652. struct vc_data *vc)
  1653. {
  1654. struct fbcon_ops *ops = info->fbcon_par;
  1655. int fh = vc->vc_font.height;
  1656. int cap = info->flags;
  1657. u16 t = 0;
  1658. int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
  1659. info->fix.xpanstep);
  1660. int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
  1661. int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
  1662. int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
  1663. info->var.xres_virtual);
  1664. int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
  1665. divides(ypan, vc->vc_font.height) && vyres > yres;
  1666. int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
  1667. divides(ywrap, vc->vc_font.height) &&
  1668. divides(vc->vc_font.height, vyres) &&
  1669. divides(vc->vc_font.height, yres);
  1670. int reading_fast = cap & FBINFO_READS_FAST;
  1671. int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
  1672. !(cap & FBINFO_HWACCEL_DISABLED);
  1673. int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
  1674. !(cap & FBINFO_HWACCEL_DISABLED);
  1675. p->vrows = vyres/fh;
  1676. if (yres > (fh * (vc->vc_rows + 1)))
  1677. p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
  1678. if ((yres % fh) && (vyres % fh < yres % fh))
  1679. p->vrows--;
  1680. if (good_wrap || good_pan) {
  1681. if (reading_fast || fast_copyarea)
  1682. p->scrollmode = good_wrap ?
  1683. SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
  1684. else
  1685. p->scrollmode = good_wrap ? SCROLL_REDRAW :
  1686. SCROLL_PAN_REDRAW;
  1687. } else {
  1688. if (reading_fast || (fast_copyarea && !fast_imageblit))
  1689. p->scrollmode = SCROLL_MOVE;
  1690. else
  1691. p->scrollmode = SCROLL_REDRAW;
  1692. }
  1693. }
  1694. #define PITCH(w) (((w) + 7) >> 3)
  1695. #define CALC_FONTSZ(h, p, c) ((h) * (p) * (c)) /* size = height * pitch * charcount */
  1696. static int fbcon_resize(struct vc_data *vc, unsigned int width,
  1697. unsigned int height, unsigned int user)
  1698. {
  1699. struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
  1700. struct fbcon_ops *ops = info->fbcon_par;
  1701. struct display *p = &fb_display[vc->vc_num];
  1702. struct fb_var_screeninfo var = info->var;
  1703. int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
  1704. if (p->userfont && FNTSIZE(vc->vc_font.data)) {
  1705. int size;
  1706. int pitch = PITCH(vc->vc_font.width);
  1707. /*
  1708. * If user font, ensure that a possible change to user font
  1709. * height or width will not allow a font data out-of-bounds access.
  1710. * NOTE: must use original charcount in calculation as font
  1711. * charcount can change and cannot be used to determine the
  1712. * font data allocated size.
  1713. */
  1714. if (pitch <= 0)
  1715. return -EINVAL;
  1716. size = CALC_FONTSZ(vc->vc_font.height, pitch, FNTCHARCNT(vc->vc_font.data));
  1717. if (size > FNTSIZE(vc->vc_font.data))
  1718. return -EINVAL;
  1719. }
  1720. virt_w = FBCON_SWAP(ops->rotate, width, height);
  1721. virt_h = FBCON_SWAP(ops->rotate, height, width);
  1722. virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
  1723. vc->vc_font.height);
  1724. virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
  1725. vc->vc_font.width);
  1726. var.xres = virt_w * virt_fw;
  1727. var.yres = virt_h * virt_fh;
  1728. x_diff = info->var.xres - var.xres;
  1729. y_diff = info->var.yres - var.yres;
  1730. if (x_diff < 0 || x_diff > virt_fw ||
  1731. y_diff < 0 || y_diff > virt_fh) {
  1732. const struct fb_videomode *mode;
  1733. DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
  1734. mode = fb_find_best_mode(&var, &info->modelist);
  1735. if (mode == NULL)
  1736. return -EINVAL;
  1737. display_to_var(&var, p);
  1738. fb_videomode_to_var(&var, mode);
  1739. if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
  1740. return -EINVAL;
  1741. DPRINTK("resize now %ix%i\n", var.xres, var.yres);
  1742. if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) {
  1743. var.activate = FB_ACTIVATE_NOW |
  1744. FB_ACTIVATE_FORCE;
  1745. fb_set_var(info, &var);
  1746. }
  1747. var_to_display(p, &info->var, info);
  1748. ops->var = info->var;
  1749. }
  1750. updatescrollmode(p, info, vc);
  1751. return 0;
  1752. }
  1753. static int fbcon_switch(struct vc_data *vc)
  1754. {
  1755. struct fb_info *info, *old_info = NULL;
  1756. struct fbcon_ops *ops;
  1757. struct display *p = &fb_display[vc->vc_num];
  1758. struct fb_var_screeninfo var;
  1759. int i, ret, prev_console, charcnt = 256;
  1760. info = registered_fb[con2fb_map[vc->vc_num]];
  1761. ops = info->fbcon_par;
  1762. if (logo_shown >= 0) {
  1763. struct vc_data *conp2 = vc_cons[logo_shown].d;
  1764. if (conp2->vc_top == logo_lines
  1765. && conp2->vc_bottom == conp2->vc_rows)
  1766. conp2->vc_top = 0;
  1767. logo_shown = FBCON_LOGO_CANSHOW;
  1768. }
  1769. prev_console = ops->currcon;
  1770. if (prev_console != -1)
  1771. old_info = registered_fb[con2fb_map[prev_console]];
  1772. /*
  1773. * FIXME: If we have multiple fbdev's loaded, we need to
  1774. * update all info->currcon. Perhaps, we can place this
  1775. * in a centralized structure, but this might break some
  1776. * drivers.
  1777. *
  1778. * info->currcon = vc->vc_num;
  1779. */
  1780. for_each_registered_fb(i) {
  1781. if (registered_fb[i]->fbcon_par) {
  1782. struct fbcon_ops *o = registered_fb[i]->fbcon_par;
  1783. o->currcon = vc->vc_num;
  1784. }
  1785. }
  1786. memset(&var, 0, sizeof(struct fb_var_screeninfo));
  1787. display_to_var(&var, p);
  1788. var.activate = FB_ACTIVATE_NOW;
  1789. /*
  1790. * make sure we don't unnecessarily trip the memcmp()
  1791. * in fb_set_var()
  1792. */
  1793. info->var.activate = var.activate;
  1794. var.vmode |= info->var.vmode & ~FB_VMODE_MASK;
  1795. fb_set_var(info, &var);
  1796. ops->var = info->var;
  1797. if (old_info != NULL && (old_info != info ||
  1798. info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
  1799. if (info->fbops->fb_set_par) {
  1800. ret = info->fbops->fb_set_par(info);
  1801. if (ret)
  1802. printk(KERN_ERR "fbcon_switch: detected "
  1803. "unhandled fb_set_par error, "
  1804. "error code %d\n", ret);
  1805. }
  1806. if (old_info != info)
  1807. fbcon_del_cursor_timer(old_info);
  1808. }
  1809. if (fbcon_is_inactive(vc, info) ||
  1810. ops->blank_state != FB_BLANK_UNBLANK)
  1811. fbcon_del_cursor_timer(info);
  1812. else
  1813. fbcon_add_cursor_timer(info);
  1814. set_blitting_type(vc, info);
  1815. ops->cursor_reset = 1;
  1816. if (ops->rotate_font && ops->rotate_font(info, vc)) {
  1817. ops->rotate = FB_ROTATE_UR;
  1818. set_blitting_type(vc, info);
  1819. }
  1820. vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
  1821. vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
  1822. if (p->userfont)
  1823. charcnt = FNTCHARCNT(vc->vc_font.data);
  1824. if (charcnt > 256)
  1825. vc->vc_complement_mask <<= 1;
  1826. updatescrollmode(p, info, vc);
  1827. switch (p->scrollmode) {
  1828. case SCROLL_WRAP_MOVE:
  1829. scrollback_phys_max = p->vrows - vc->vc_rows;
  1830. break;
  1831. case SCROLL_PAN_MOVE:
  1832. case SCROLL_PAN_REDRAW:
  1833. scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
  1834. if (scrollback_phys_max < 0)
  1835. scrollback_phys_max = 0;
  1836. break;
  1837. default:
  1838. scrollback_phys_max = 0;
  1839. break;
  1840. }
  1841. scrollback_max = 0;
  1842. scrollback_current = 0;
  1843. if (!fbcon_is_inactive(vc, info)) {
  1844. ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
  1845. ops->update_start(info);
  1846. }
  1847. fbcon_set_palette(vc, color_table);
  1848. fbcon_clear_margins(vc, 0);
  1849. if (logo_shown == FBCON_LOGO_DRAW) {
  1850. logo_shown = fg_console;
  1851. /* This is protected above by initmem_freed */
  1852. fb_show_logo(info, ops->rotate);
  1853. update_region(vc,
  1854. vc->vc_origin + vc->vc_size_row * vc->vc_top,
  1855. vc->vc_size_row * (vc->vc_bottom -
  1856. vc->vc_top) / 2);
  1857. return 0;
  1858. }
  1859. return 1;
  1860. }
  1861. static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
  1862. int blank)
  1863. {
  1864. struct fb_event event;
  1865. if (blank) {
  1866. unsigned short charmask = vc->vc_hi_font_mask ?
  1867. 0x1ff : 0xff;
  1868. unsigned short oldc;
  1869. oldc = vc->vc_video_erase_char;
  1870. vc->vc_video_erase_char &= charmask;
  1871. fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
  1872. vc->vc_video_erase_char = oldc;
  1873. }
  1874. if (!lock_fb_info(info))
  1875. return;
  1876. event.info = info;
  1877. event.data = &blank;
  1878. fb_notifier_call_chain(FB_EVENT_CONBLANK, &event);
  1879. unlock_fb_info(info);
  1880. }
  1881. static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
  1882. {
  1883. struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
  1884. struct fbcon_ops *ops = info->fbcon_par;
  1885. if (mode_switch) {
  1886. struct fb_var_screeninfo var = info->var;
  1887. ops->graphics = 1;
  1888. if (!blank) {
  1889. var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
  1890. fb_set_var(info, &var);
  1891. ops->graphics = 0;
  1892. ops->var = info->var;
  1893. }
  1894. }
  1895. if (!fbcon_is_inactive(vc, info)) {
  1896. if (ops->blank_state != blank) {
  1897. ops->blank_state = blank;
  1898. fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
  1899. ops->cursor_flash = (!blank);
  1900. if (!(info->flags & FBINFO_MISC_USEREVENT))
  1901. if (fb_blank(info, blank))
  1902. fbcon_generic_blank(vc, info, blank);
  1903. }
  1904. if (!blank)
  1905. update_screen(vc);
  1906. }
  1907. if (mode_switch || fbcon_is_inactive(vc, info) ||
  1908. ops->blank_state != FB_BLANK_UNBLANK)
  1909. fbcon_del_cursor_timer(info);
  1910. else
  1911. fbcon_add_cursor_timer(info);
  1912. return 0;
  1913. }
  1914. static int fbcon_debug_enter(struct vc_data *vc)
  1915. {
  1916. struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
  1917. struct fbcon_ops *ops = info->fbcon_par;
  1918. ops->save_graphics = ops->graphics;
  1919. ops->graphics = 0;
  1920. if (info->fbops->fb_debug_enter)
  1921. info->fbops->fb_debug_enter(info);
  1922. fbcon_set_palette(vc, color_table);
  1923. return 0;
  1924. }
  1925. static int fbcon_debug_leave(struct vc_data *vc)
  1926. {
  1927. struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
  1928. struct fbcon_ops *ops = info->fbcon_par;
  1929. ops->graphics = ops->save_graphics;
  1930. if (info->fbops->fb_debug_leave)
  1931. info->fbops->fb_debug_leave(info);
  1932. return 0;
  1933. }
  1934. static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
  1935. {
  1936. u8 *fontdata = vc->vc_font.data;
  1937. u8 *data = font->data;
  1938. int i, j;
  1939. font->width = vc->vc_font.width;
  1940. font->height = vc->vc_font.height;
  1941. font->charcount = vc->vc_hi_font_mask ? 512 : 256;
  1942. if (!font->data)
  1943. return 0;
  1944. if (font->width <= 8) {
  1945. j = vc->vc_font.height;
  1946. if (font->charcount * j > FNTSIZE(fontdata))
  1947. return -EINVAL;
  1948. for (i = 0; i < font->charcount; i++) {
  1949. memcpy(data, fontdata, j);
  1950. memset(data + j, 0, 32 - j);
  1951. data += 32;
  1952. fontdata += j;
  1953. }
  1954. } else if (font->width <= 16) {
  1955. j = vc->vc_font.height * 2;
  1956. if (font->charcount * j > FNTSIZE(fontdata))
  1957. return -EINVAL;
  1958. for (i = 0; i < font->charcount; i++) {
  1959. memcpy(data, fontdata, j);
  1960. memset(data + j, 0, 64 - j);
  1961. data += 64;
  1962. fontdata += j;
  1963. }
  1964. } else if (font->width <= 24) {
  1965. if (font->charcount * (vc->vc_font.height * sizeof(u32)) > FNTSIZE(fontdata))
  1966. return -EINVAL;
  1967. for (i = 0; i < font->charcount; i++) {
  1968. for (j = 0; j < vc->vc_font.height; j++) {
  1969. *data++ = fontdata[0];
  1970. *data++ = fontdata[1];
  1971. *data++ = fontdata[2];
  1972. fontdata += sizeof(u32);
  1973. }
  1974. memset(data, 0, 3 * (32 - j));
  1975. data += 3 * (32 - j);
  1976. }
  1977. } else {
  1978. j = vc->vc_font.height * 4;
  1979. if (font->charcount * j > FNTSIZE(fontdata))
  1980. return -EINVAL;
  1981. for (i = 0; i < font->charcount; i++) {
  1982. memcpy(data, fontdata, j);
  1983. memset(data + j, 0, 128 - j);
  1984. data += 128;
  1985. fontdata += j;
  1986. }
  1987. }
  1988. return 0;
  1989. }
  1990. /* set/clear vc_hi_font_mask and update vc attrs accordingly */
  1991. static void set_vc_hi_font(struct vc_data *vc, bool set)
  1992. {
  1993. if (!set) {
  1994. vc->vc_hi_font_mask = 0;
  1995. if (vc->vc_can_do_color) {
  1996. vc->vc_complement_mask >>= 1;
  1997. vc->vc_s_complement_mask >>= 1;
  1998. }
  1999. /* ++Edmund: reorder the attribute bits */
  2000. if (vc->vc_can_do_color) {
  2001. unsigned short *cp =
  2002. (unsigned short *) vc->vc_origin;
  2003. int count = vc->vc_screenbuf_size / 2;
  2004. unsigned short c;
  2005. for (; count > 0; count--, cp++) {
  2006. c = scr_readw(cp);
  2007. scr_writew(((c & 0xfe00) >> 1) |
  2008. (c & 0xff), cp);
  2009. }
  2010. c = vc->vc_video_erase_char;
  2011. vc->vc_video_erase_char =
  2012. ((c & 0xfe00) >> 1) | (c & 0xff);
  2013. vc->vc_attr >>= 1;
  2014. }
  2015. } else {
  2016. vc->vc_hi_font_mask = 0x100;
  2017. if (vc->vc_can_do_color) {
  2018. vc->vc_complement_mask <<= 1;
  2019. vc->vc_s_complement_mask <<= 1;
  2020. }
  2021. /* ++Edmund: reorder the attribute bits */
  2022. {
  2023. unsigned short *cp =
  2024. (unsigned short *) vc->vc_origin;
  2025. int count = vc->vc_screenbuf_size / 2;
  2026. unsigned short c;
  2027. for (; count > 0; count--, cp++) {
  2028. unsigned short newc;
  2029. c = scr_readw(cp);
  2030. if (vc->vc_can_do_color)
  2031. newc =
  2032. ((c & 0xff00) << 1) | (c &
  2033. 0xff);
  2034. else
  2035. newc = c & ~0x100;
  2036. scr_writew(newc, cp);
  2037. }
  2038. c = vc->vc_video_erase_char;
  2039. if (vc->vc_can_do_color) {
  2040. vc->vc_video_erase_char =
  2041. ((c & 0xff00) << 1) | (c & 0xff);
  2042. vc->vc_attr <<= 1;
  2043. } else
  2044. vc->vc_video_erase_char = c & ~0x100;
  2045. }
  2046. }
  2047. }
  2048. static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
  2049. const u8 * data, int userfont)
  2050. {
  2051. struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
  2052. struct fbcon_ops *ops = info->fbcon_par;
  2053. struct display *p = &fb_display[vc->vc_num];
  2054. int resize;
  2055. int cnt;
  2056. char *old_data = NULL;
  2057. resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
  2058. if (p->userfont)
  2059. old_data = vc->vc_font.data;
  2060. if (userfont)
  2061. cnt = FNTCHARCNT(data);
  2062. else
  2063. cnt = 256;
  2064. vc->vc_font.data = (void *)(p->fontdata = data);
  2065. if ((p->userfont = userfont))
  2066. REFCOUNT(data)++;
  2067. vc->vc_font.width = w;
  2068. vc->vc_font.height = h;
  2069. if (vc->vc_hi_font_mask && cnt == 256)
  2070. set_vc_hi_font(vc, false);
  2071. else if (!vc->vc_hi_font_mask && cnt == 512)
  2072. set_vc_hi_font(vc, true);
  2073. if (resize) {
  2074. int cols, rows;
  2075. cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
  2076. rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
  2077. cols /= w;
  2078. rows /= h;
  2079. vc_resize(vc, cols, rows);
  2080. } else if (con_is_visible(vc)
  2081. && vc->vc_mode == KD_TEXT) {
  2082. fbcon_clear_margins(vc, 0);
  2083. update_screen(vc);
  2084. }
  2085. if (old_data && (--REFCOUNT(old_data) == 0))
  2086. kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
  2087. return 0;
  2088. }
  2089. static int fbcon_copy_font(struct vc_data *vc, int con)
  2090. {
  2091. struct display *od = &fb_display[con];
  2092. struct console_font *f = &vc->vc_font;
  2093. if (od->fontdata == f->data)
  2094. return 0; /* already the same font... */
  2095. return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
  2096. }
  2097. /*
  2098. * User asked to set font; we are guaranteed that
  2099. * a) width and height are in range 1..32
  2100. * b) charcount does not exceed 512
  2101. * but lets not assume that, since someone might someday want to use larger
  2102. * fonts. And charcount of 512 is small for unicode support.
  2103. *
  2104. * However, user space gives the font in 32 rows , regardless of
  2105. * actual font height. So a new API is needed if support for larger fonts
  2106. * is ever implemented.
  2107. */
  2108. static int fbcon_set_font(struct vc_data *vc, struct console_font *font,
  2109. unsigned int flags)
  2110. {
  2111. struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
  2112. unsigned charcount = font->charcount;
  2113. int w = font->width;
  2114. int h = font->height;
  2115. int size;
  2116. int i, csum;
  2117. u8 *new_data, *data = font->data;
  2118. int pitch = PITCH(font->width);
  2119. /* Is there a reason why fbconsole couldn't handle any charcount >256?
  2120. * If not this check should be changed to charcount < 256 */
  2121. if (charcount != 256 && charcount != 512)
  2122. return -EINVAL;
  2123. /* Make sure drawing engine can handle the font */
  2124. if (!(info->pixmap.blit_x & (1 << (font->width - 1))) ||
  2125. !(info->pixmap.blit_y & (1 << (font->height - 1))))
  2126. return -EINVAL;
  2127. /* Make sure driver can handle the font length */
  2128. if (fbcon_invalid_charcount(info, charcount))
  2129. return -EINVAL;
  2130. size = CALC_FONTSZ(h, pitch, charcount);
  2131. new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
  2132. if (!new_data)
  2133. return -ENOMEM;
  2134. new_data += FONT_EXTRA_WORDS * sizeof(int);
  2135. FNTSIZE(new_data) = size;
  2136. FNTCHARCNT(new_data) = charcount;
  2137. REFCOUNT(new_data) = 0; /* usage counter */
  2138. for (i=0; i< charcount; i++) {
  2139. memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
  2140. }
  2141. /* Since linux has a nice crc32 function use it for counting font
  2142. * checksums. */
  2143. csum = crc32(0, new_data, size);
  2144. FNTSUM(new_data) = csum;
  2145. /* Check if the same font is on some other console already */
  2146. for (i = first_fb_vc; i <= last_fb_vc; i++) {
  2147. struct vc_data *tmp = vc_cons[i].d;
  2148. if (fb_display[i].userfont &&
  2149. fb_display[i].fontdata &&
  2150. FNTSUM(fb_display[i].fontdata) == csum &&
  2151. FNTSIZE(fb_display[i].fontdata) == size &&
  2152. tmp->vc_font.width == w &&
  2153. !memcmp(fb_display[i].fontdata, new_data, size)) {
  2154. kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
  2155. new_data = (u8 *)fb_display[i].fontdata;
  2156. break;
  2157. }
  2158. }
  2159. return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
  2160. }
  2161. static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
  2162. {
  2163. struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
  2164. const struct font_desc *f;
  2165. if (!name)
  2166. f = get_default_font(info->var.xres, info->var.yres,
  2167. info->pixmap.blit_x, info->pixmap.blit_y);
  2168. else if (!(f = find_font(name)))
  2169. return -ENOENT;
  2170. font->width = f->width;
  2171. font->height = f->height;
  2172. return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
  2173. }
  2174. static u16 palette_red[16];
  2175. static u16 palette_green[16];
  2176. static u16 palette_blue[16];
  2177. static struct fb_cmap palette_cmap = {
  2178. 0, 16, palette_red, palette_green, palette_blue, NULL
  2179. };
  2180. static void fbcon_set_palette(struct vc_data *vc, const unsigned char *table)
  2181. {
  2182. struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
  2183. int i, j, k, depth;
  2184. u8 val;
  2185. if (fbcon_is_inactive(vc, info))
  2186. return;
  2187. if (!con_is_visible(vc))
  2188. return;
  2189. depth = fb_get_color_depth(&info->var, &info->fix);
  2190. if (depth > 3) {
  2191. for (i = j = 0; i < 16; i++) {
  2192. k = table[i];
  2193. val = vc->vc_palette[j++];
  2194. palette_red[k] = (val << 8) | val;
  2195. val = vc->vc_palette[j++];
  2196. palette_green[k] = (val << 8) | val;
  2197. val = vc->vc_palette[j++];
  2198. palette_blue[k] = (val << 8) | val;
  2199. }
  2200. palette_cmap.len = 16;
  2201. palette_cmap.start = 0;
  2202. /*
  2203. * If framebuffer is capable of less than 16 colors,
  2204. * use default palette of fbcon.
  2205. */
  2206. } else
  2207. fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
  2208. fb_set_cmap(&palette_cmap, info);
  2209. }
  2210. static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
  2211. {
  2212. return (u16 *) (vc->vc_origin + offset);
  2213. }
  2214. static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
  2215. int *px, int *py)
  2216. {
  2217. unsigned long ret;
  2218. int x, y;
  2219. if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
  2220. unsigned long offset = (pos - vc->vc_origin) / 2;
  2221. x = offset % vc->vc_cols;
  2222. y = offset / vc->vc_cols;
  2223. ret = pos + (vc->vc_cols - x) * 2;
  2224. } else {
  2225. /* Should not happen */
  2226. x = y = 0;
  2227. ret = vc->vc_origin;
  2228. }
  2229. if (px)
  2230. *px = x;
  2231. if (py)
  2232. *py = y;
  2233. return ret;
  2234. }
  2235. /* As we might be inside of softback, we may work with non-contiguous buffer,
  2236. that's why we have to use a separate routine. */
  2237. static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
  2238. {
  2239. while (cnt--) {
  2240. u16 a = scr_readw(p);
  2241. if (!vc->vc_can_do_color)
  2242. a ^= 0x0800;
  2243. else if (vc->vc_hi_font_mask == 0x100)
  2244. a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
  2245. (((a) & 0x0e00) << 4);
  2246. else
  2247. a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
  2248. (((a) & 0x0700) << 4);
  2249. scr_writew(a, p++);
  2250. }
  2251. }
  2252. static int fbcon_set_origin(struct vc_data *vc)
  2253. {
  2254. return 0;
  2255. }
  2256. static void fbcon_suspended(struct fb_info *info)
  2257. {
  2258. struct vc_data *vc = NULL;
  2259. struct fbcon_ops *ops = info->fbcon_par;
  2260. if (!ops || ops->currcon < 0)
  2261. return;
  2262. vc = vc_cons[ops->currcon].d;
  2263. /* Clear cursor, restore saved data */
  2264. fbcon_cursor(vc, CM_ERASE);
  2265. }
  2266. static void fbcon_resumed(struct fb_info *info)
  2267. {
  2268. struct vc_data *vc;
  2269. struct fbcon_ops *ops = info->fbcon_par;
  2270. if (!ops || ops->currcon < 0)
  2271. return;
  2272. vc = vc_cons[ops->currcon].d;
  2273. update_screen(vc);
  2274. }
  2275. static void fbcon_modechanged(struct fb_info *info)
  2276. {
  2277. struct fbcon_ops *ops = info->fbcon_par;
  2278. struct vc_data *vc;
  2279. struct display *p;
  2280. int rows, cols;
  2281. if (!ops || ops->currcon < 0)
  2282. return;
  2283. vc = vc_cons[ops->currcon].d;
  2284. if (vc->vc_mode != KD_TEXT ||
  2285. registered_fb[con2fb_map[ops->currcon]] != info)
  2286. return;
  2287. p = &fb_display[vc->vc_num];
  2288. set_blitting_type(vc, info);
  2289. if (con_is_visible(vc)) {
  2290. var_to_display(p, &info->var, info);
  2291. cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
  2292. rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
  2293. cols /= vc->vc_font.width;
  2294. rows /= vc->vc_font.height;
  2295. vc_resize(vc, cols, rows);
  2296. updatescrollmode(p, info, vc);
  2297. scrollback_max = 0;
  2298. scrollback_current = 0;
  2299. if (!fbcon_is_inactive(vc, info)) {
  2300. ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
  2301. ops->update_start(info);
  2302. }
  2303. fbcon_set_palette(vc, color_table);
  2304. update_screen(vc);
  2305. }
  2306. }
  2307. static void fbcon_set_all_vcs(struct fb_info *info)
  2308. {
  2309. struct fbcon_ops *ops = info->fbcon_par;
  2310. struct vc_data *vc;
  2311. struct display *p;
  2312. int i, rows, cols, fg = -1;
  2313. if (!ops || ops->currcon < 0)
  2314. return;
  2315. for (i = first_fb_vc; i <= last_fb_vc; i++) {
  2316. vc = vc_cons[i].d;
  2317. if (!vc || vc->vc_mode != KD_TEXT ||
  2318. registered_fb[con2fb_map[i]] != info)
  2319. continue;
  2320. if (con_is_visible(vc)) {
  2321. fg = i;
  2322. continue;
  2323. }
  2324. p = &fb_display[vc->vc_num];
  2325. set_blitting_type(vc, info);
  2326. var_to_display(p, &info->var, info);
  2327. cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
  2328. rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
  2329. cols /= vc->vc_font.width;
  2330. rows /= vc->vc_font.height;
  2331. vc_resize(vc, cols, rows);
  2332. }
  2333. if (fg != -1)
  2334. fbcon_modechanged(info);
  2335. }
  2336. static int fbcon_mode_deleted(struct fb_info *info,
  2337. struct fb_videomode *mode)
  2338. {
  2339. struct fb_info *fb_info;
  2340. struct display *p;
  2341. int i, j, found = 0;
  2342. /* before deletion, ensure that mode is not in use */
  2343. for (i = first_fb_vc; i <= last_fb_vc; i++) {
  2344. j = con2fb_map[i];
  2345. if (j == -1)
  2346. continue;
  2347. fb_info = registered_fb[j];
  2348. if (fb_info != info)
  2349. continue;
  2350. p = &fb_display[i];
  2351. if (!p || !p->mode)
  2352. continue;
  2353. if (fb_mode_is_equal(p->mode, mode)) {
  2354. found = 1;
  2355. break;
  2356. }
  2357. }
  2358. return found;
  2359. }
  2360. #ifdef CONFIG_VT_HW_CONSOLE_BINDING
  2361. static int fbcon_unbind(void)
  2362. {
  2363. int ret;
  2364. ret = do_unbind_con_driver(&fb_con, first_fb_vc, last_fb_vc,
  2365. fbcon_is_default);
  2366. if (!ret)
  2367. fbcon_has_console_bind = 0;
  2368. return ret;
  2369. }
  2370. #else
  2371. static inline int fbcon_unbind(void)
  2372. {
  2373. return -EINVAL;
  2374. }
  2375. #endif /* CONFIG_VT_HW_CONSOLE_BINDING */
  2376. /* called with console_lock held */
  2377. static int fbcon_fb_unbind(int idx)
  2378. {
  2379. int i, new_idx = -1, ret = 0;
  2380. WARN_CONSOLE_UNLOCKED();
  2381. if (!fbcon_has_console_bind)
  2382. return 0;
  2383. for (i = first_fb_vc; i <= last_fb_vc; i++) {
  2384. if (con2fb_map[i] != idx &&
  2385. con2fb_map[i] != -1) {
  2386. new_idx = con2fb_map[i];
  2387. break;
  2388. }
  2389. }
  2390. if (new_idx != -1) {
  2391. for (i = first_fb_vc; i <= last_fb_vc; i++) {
  2392. if (con2fb_map[i] == idx)
  2393. set_con2fb_map(i, new_idx, 0);
  2394. }
  2395. } else {
  2396. struct fb_info *info = registered_fb[idx];
  2397. /* This is sort of like set_con2fb_map, except it maps
  2398. * the consoles to no device and then releases the
  2399. * oldinfo to free memory and cancel the cursor blink
  2400. * timer. I can imagine this just becoming part of
  2401. * set_con2fb_map where new_idx is -1
  2402. */
  2403. for (i = first_fb_vc; i <= last_fb_vc; i++) {
  2404. if (con2fb_map[i] == idx) {
  2405. con2fb_map[i] = -1;
  2406. if (!search_fb_in_map(idx)) {
  2407. ret = con2fb_release_oldinfo(vc_cons[i].d,
  2408. info, NULL, i,
  2409. idx, 0);
  2410. if (ret) {
  2411. con2fb_map[i] = idx;
  2412. return ret;
  2413. }
  2414. }
  2415. }
  2416. }
  2417. ret = fbcon_unbind();
  2418. }
  2419. return ret;
  2420. }
  2421. /* called with console_lock held */
  2422. static int fbcon_fb_unregistered(struct fb_info *info)
  2423. {
  2424. int i, idx;
  2425. WARN_CONSOLE_UNLOCKED();
  2426. if (deferred_takeover)
  2427. return 0;
  2428. idx = info->node;
  2429. for (i = first_fb_vc; i <= last_fb_vc; i++) {
  2430. if (con2fb_map[i] == idx)
  2431. con2fb_map[i] = -1;
  2432. }
  2433. if (idx == info_idx) {
  2434. info_idx = -1;
  2435. for_each_registered_fb(i) {
  2436. info_idx = i;
  2437. break;
  2438. }
  2439. }
  2440. if (info_idx != -1) {
  2441. for (i = first_fb_vc; i <= last_fb_vc; i++) {
  2442. if (con2fb_map[i] == -1)
  2443. con2fb_map[i] = info_idx;
  2444. }
  2445. }
  2446. if (primary_device == idx)
  2447. primary_device = -1;
  2448. if (!num_registered_fb)
  2449. do_unregister_con_driver(&fb_con);
  2450. return 0;
  2451. }
  2452. /* called with console_lock held */
  2453. static void fbcon_remap_all(int idx)
  2454. {
  2455. int i;
  2456. WARN_CONSOLE_UNLOCKED();
  2457. if (deferred_takeover) {
  2458. for (i = first_fb_vc; i <= last_fb_vc; i++)
  2459. con2fb_map_boot[i] = idx;
  2460. fbcon_map_override();
  2461. return;
  2462. }
  2463. for (i = first_fb_vc; i <= last_fb_vc; i++)
  2464. set_con2fb_map(i, idx, 0);
  2465. if (con_is_bound(&fb_con)) {
  2466. printk(KERN_INFO "fbcon: Remapping primary device, "
  2467. "fb%i, to tty %i-%i\n", idx,
  2468. first_fb_vc + 1, last_fb_vc + 1);
  2469. info_idx = idx;
  2470. }
  2471. }
  2472. #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
  2473. static void fbcon_select_primary(struct fb_info *info)
  2474. {
  2475. if (!map_override && primary_device == -1 &&
  2476. fb_is_primary_device(info)) {
  2477. int i;
  2478. printk(KERN_INFO "fbcon: %s (fb%i) is primary device\n",
  2479. info->fix.id, info->node);
  2480. primary_device = info->node;
  2481. for (i = first_fb_vc; i <= last_fb_vc; i++)
  2482. con2fb_map_boot[i] = primary_device;
  2483. if (con_is_bound(&fb_con)) {
  2484. printk(KERN_INFO "fbcon: Remapping primary device, "
  2485. "fb%i, to tty %i-%i\n", info->node,
  2486. first_fb_vc + 1, last_fb_vc + 1);
  2487. info_idx = primary_device;
  2488. }
  2489. }
  2490. }
  2491. #else
  2492. static inline void fbcon_select_primary(struct fb_info *info)
  2493. {
  2494. return;
  2495. }
  2496. #endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
  2497. /* called with console_lock held */
  2498. static int fbcon_fb_registered(struct fb_info *info)
  2499. {
  2500. int ret = 0, i, idx;
  2501. WARN_CONSOLE_UNLOCKED();
  2502. idx = info->node;
  2503. fbcon_select_primary(info);
  2504. if (deferred_takeover) {
  2505. pr_info("fbcon: Deferring console take-over\n");
  2506. return 0;
  2507. }
  2508. if (info_idx == -1) {
  2509. for (i = first_fb_vc; i <= last_fb_vc; i++) {
  2510. if (con2fb_map_boot[i] == idx) {
  2511. info_idx = idx;
  2512. break;
  2513. }
  2514. }
  2515. if (info_idx != -1)
  2516. ret = do_fbcon_takeover(1);
  2517. } else {
  2518. for (i = first_fb_vc; i <= last_fb_vc; i++) {
  2519. if (con2fb_map_boot[i] == idx)
  2520. set_con2fb_map(i, idx, 0);
  2521. }
  2522. }
  2523. return ret;
  2524. }
  2525. static void fbcon_fb_blanked(struct fb_info *info, int blank)
  2526. {
  2527. struct fbcon_ops *ops = info->fbcon_par;
  2528. struct vc_data *vc;
  2529. if (!ops || ops->currcon < 0)
  2530. return;
  2531. vc = vc_cons[ops->currcon].d;
  2532. if (vc->vc_mode != KD_TEXT ||
  2533. registered_fb[con2fb_map[ops->currcon]] != info)
  2534. return;
  2535. if (con_is_visible(vc)) {
  2536. if (blank)
  2537. do_blank_screen(0);
  2538. else
  2539. do_unblank_screen(0);
  2540. }
  2541. ops->blank_state = blank;
  2542. }
  2543. static void fbcon_new_modelist(struct fb_info *info)
  2544. {
  2545. int i;
  2546. struct vc_data *vc;
  2547. struct fb_var_screeninfo var;
  2548. const struct fb_videomode *mode;
  2549. for (i = first_fb_vc; i <= last_fb_vc; i++) {
  2550. if (registered_fb[con2fb_map[i]] != info)
  2551. continue;
  2552. if (!fb_display[i].mode)
  2553. continue;
  2554. vc = vc_cons[i].d;
  2555. display_to_var(&var, &fb_display[i]);
  2556. mode = fb_find_nearest_mode(fb_display[i].mode,
  2557. &info->modelist);
  2558. fb_videomode_to_var(&var, mode);
  2559. fbcon_set_disp(info, &var, vc->vc_num);
  2560. }
  2561. }
  2562. static void fbcon_get_requirement(struct fb_info *info,
  2563. struct fb_blit_caps *caps)
  2564. {
  2565. struct vc_data *vc;
  2566. struct display *p;
  2567. if (caps->flags) {
  2568. int i, charcnt;
  2569. for (i = first_fb_vc; i <= last_fb_vc; i++) {
  2570. vc = vc_cons[i].d;
  2571. if (vc && vc->vc_mode == KD_TEXT &&
  2572. info->node == con2fb_map[i]) {
  2573. p = &fb_display[i];
  2574. caps->x |= 1 << (vc->vc_font.width - 1);
  2575. caps->y |= 1 << (vc->vc_font.height - 1);
  2576. charcnt = (p->userfont) ?
  2577. FNTCHARCNT(p->fontdata) : 256;
  2578. if (caps->len < charcnt)
  2579. caps->len = charcnt;
  2580. }
  2581. }
  2582. } else {
  2583. vc = vc_cons[fg_console].d;
  2584. if (vc && vc->vc_mode == KD_TEXT &&
  2585. info->node == con2fb_map[fg_console]) {
  2586. p = &fb_display[fg_console];
  2587. caps->x = 1 << (vc->vc_font.width - 1);
  2588. caps->y = 1 << (vc->vc_font.height - 1);
  2589. caps->len = (p->userfont) ?
  2590. FNTCHARCNT(p->fontdata) : 256;
  2591. }
  2592. }
  2593. }
  2594. static int fbcon_event_notify(struct notifier_block *self,
  2595. unsigned long action, void *data)
  2596. {
  2597. struct fb_event *event = data;
  2598. struct fb_info *info = event->info;
  2599. struct fb_videomode *mode;
  2600. struct fb_con2fbmap *con2fb;
  2601. struct fb_blit_caps *caps;
  2602. int idx, ret = 0;
  2603. /*
  2604. * ignore all events except driver registration and deregistration
  2605. * if fbcon is not active
  2606. */
  2607. if (fbcon_has_exited && !(action == FB_EVENT_FB_REGISTERED ||
  2608. action == FB_EVENT_FB_UNREGISTERED))
  2609. goto done;
  2610. switch(action) {
  2611. case FB_EVENT_SUSPEND:
  2612. fbcon_suspended(info);
  2613. break;
  2614. case FB_EVENT_RESUME:
  2615. fbcon_resumed(info);
  2616. break;
  2617. case FB_EVENT_MODE_CHANGE:
  2618. fbcon_modechanged(info);
  2619. break;
  2620. case FB_EVENT_MODE_CHANGE_ALL:
  2621. fbcon_set_all_vcs(info);
  2622. break;
  2623. case FB_EVENT_MODE_DELETE:
  2624. mode = event->data;
  2625. ret = fbcon_mode_deleted(info, mode);
  2626. break;
  2627. case FB_EVENT_FB_UNBIND:
  2628. idx = info->node;
  2629. ret = fbcon_fb_unbind(idx);
  2630. break;
  2631. case FB_EVENT_FB_REGISTERED:
  2632. ret = fbcon_fb_registered(info);
  2633. break;
  2634. case FB_EVENT_FB_UNREGISTERED:
  2635. ret = fbcon_fb_unregistered(info);
  2636. break;
  2637. case FB_EVENT_SET_CONSOLE_MAP:
  2638. /* called with console lock held */
  2639. con2fb = event->data;
  2640. ret = set_con2fb_map(con2fb->console - 1,
  2641. con2fb->framebuffer, 1);
  2642. break;
  2643. case FB_EVENT_GET_CONSOLE_MAP:
  2644. con2fb = event->data;
  2645. con2fb->framebuffer = con2fb_map[con2fb->console - 1];
  2646. break;
  2647. case FB_EVENT_BLANK:
  2648. fbcon_fb_blanked(info, *(int *)event->data);
  2649. break;
  2650. case FB_EVENT_NEW_MODELIST:
  2651. fbcon_new_modelist(info);
  2652. break;
  2653. case FB_EVENT_GET_REQ:
  2654. caps = event->data;
  2655. fbcon_get_requirement(info, caps);
  2656. break;
  2657. case FB_EVENT_REMAP_ALL_CONSOLE:
  2658. idx = info->node;
  2659. fbcon_remap_all(idx);
  2660. break;
  2661. }
  2662. done:
  2663. return ret;
  2664. }
  2665. /*
  2666. * The console `switch' structure for the frame buffer based console
  2667. */
  2668. static const struct consw fb_con = {
  2669. .owner = THIS_MODULE,
  2670. .con_startup = fbcon_startup,
  2671. .con_init = fbcon_init,
  2672. .con_deinit = fbcon_deinit,
  2673. .con_clear = fbcon_clear,
  2674. .con_putc = fbcon_putc,
  2675. .con_putcs = fbcon_putcs,
  2676. .con_cursor = fbcon_cursor,
  2677. .con_scroll = fbcon_scroll,
  2678. .con_switch = fbcon_switch,
  2679. .con_blank = fbcon_blank,
  2680. .con_font_set = fbcon_set_font,
  2681. .con_font_get = fbcon_get_font,
  2682. .con_font_default = fbcon_set_def_font,
  2683. .con_font_copy = fbcon_copy_font,
  2684. .con_set_palette = fbcon_set_palette,
  2685. .con_set_origin = fbcon_set_origin,
  2686. .con_invert_region = fbcon_invert_region,
  2687. .con_screen_pos = fbcon_screen_pos,
  2688. .con_getxy = fbcon_getxy,
  2689. .con_resize = fbcon_resize,
  2690. .con_debug_enter = fbcon_debug_enter,
  2691. .con_debug_leave = fbcon_debug_leave,
  2692. };
  2693. static struct notifier_block fbcon_event_notifier = {
  2694. .notifier_call = fbcon_event_notify,
  2695. };
  2696. static ssize_t store_rotate(struct device *device,
  2697. struct device_attribute *attr, const char *buf,
  2698. size_t count)
  2699. {
  2700. struct fb_info *info;
  2701. int rotate, idx;
  2702. char **last = NULL;
  2703. if (fbcon_has_exited)
  2704. return count;
  2705. console_lock();
  2706. idx = con2fb_map[fg_console];
  2707. if (idx == -1 || registered_fb[idx] == NULL)
  2708. goto err;
  2709. info = registered_fb[idx];
  2710. rotate = simple_strtoul(buf, last, 0);
  2711. fbcon_rotate(info, rotate);
  2712. err:
  2713. console_unlock();
  2714. return count;
  2715. }
  2716. static ssize_t store_rotate_all(struct device *device,
  2717. struct device_attribute *attr,const char *buf,
  2718. size_t count)
  2719. {
  2720. struct fb_info *info;
  2721. int rotate, idx;
  2722. char **last = NULL;
  2723. if (fbcon_has_exited)
  2724. return count;
  2725. console_lock();
  2726. idx = con2fb_map[fg_console];
  2727. if (idx == -1 || registered_fb[idx] == NULL)
  2728. goto err;
  2729. info = registered_fb[idx];
  2730. rotate = simple_strtoul(buf, last, 0);
  2731. fbcon_rotate_all(info, rotate);
  2732. err:
  2733. console_unlock();
  2734. return count;
  2735. }
  2736. static ssize_t show_rotate(struct device *device,
  2737. struct device_attribute *attr,char *buf)
  2738. {
  2739. struct fb_info *info;
  2740. int rotate = 0, idx;
  2741. if (fbcon_has_exited)
  2742. return 0;
  2743. console_lock();
  2744. idx = con2fb_map[fg_console];
  2745. if (idx == -1 || registered_fb[idx] == NULL)
  2746. goto err;
  2747. info = registered_fb[idx];
  2748. rotate = fbcon_get_rotate(info);
  2749. err:
  2750. console_unlock();
  2751. return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
  2752. }
  2753. static ssize_t show_cursor_blink(struct device *device,
  2754. struct device_attribute *attr, char *buf)
  2755. {
  2756. struct fb_info *info;
  2757. struct fbcon_ops *ops;
  2758. int idx, blink = -1;
  2759. if (fbcon_has_exited)
  2760. return 0;
  2761. console_lock();
  2762. idx = con2fb_map[fg_console];
  2763. if (idx == -1 || registered_fb[idx] == NULL)
  2764. goto err;
  2765. info = registered_fb[idx];
  2766. ops = info->fbcon_par;
  2767. if (!ops)
  2768. goto err;
  2769. blink = (ops->flags & FBCON_FLAGS_CURSOR_TIMER) ? 1 : 0;
  2770. err:
  2771. console_unlock();
  2772. return snprintf(buf, PAGE_SIZE, "%d\n", blink);
  2773. }
  2774. static ssize_t store_cursor_blink(struct device *device,
  2775. struct device_attribute *attr,
  2776. const char *buf, size_t count)
  2777. {
  2778. struct fb_info *info;
  2779. int blink, idx;
  2780. char **last = NULL;
  2781. if (fbcon_has_exited)
  2782. return count;
  2783. console_lock();
  2784. idx = con2fb_map[fg_console];
  2785. if (idx == -1 || registered_fb[idx] == NULL)
  2786. goto err;
  2787. info = registered_fb[idx];
  2788. if (!info->fbcon_par)
  2789. goto err;
  2790. blink = simple_strtoul(buf, last, 0);
  2791. if (blink) {
  2792. fbcon_cursor_noblink = 0;
  2793. fbcon_add_cursor_timer(info);
  2794. } else {
  2795. fbcon_cursor_noblink = 1;
  2796. fbcon_del_cursor_timer(info);
  2797. }
  2798. err:
  2799. console_unlock();
  2800. return count;
  2801. }
  2802. static struct device_attribute device_attrs[] = {
  2803. __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
  2804. __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
  2805. __ATTR(cursor_blink, S_IRUGO|S_IWUSR, show_cursor_blink,
  2806. store_cursor_blink),
  2807. };
  2808. static int fbcon_init_device(void)
  2809. {
  2810. int i, error = 0;
  2811. fbcon_has_sysfs = 1;
  2812. for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
  2813. error = device_create_file(fbcon_device, &device_attrs[i]);
  2814. if (error)
  2815. break;
  2816. }
  2817. if (error) {
  2818. while (--i >= 0)
  2819. device_remove_file(fbcon_device, &device_attrs[i]);
  2820. fbcon_has_sysfs = 0;
  2821. }
  2822. return 0;
  2823. }
  2824. #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
  2825. static void fbcon_register_existing_fbs(struct work_struct *work)
  2826. {
  2827. int i;
  2828. console_lock();
  2829. for_each_registered_fb(i)
  2830. fbcon_fb_registered(registered_fb[i]);
  2831. console_unlock();
  2832. }
  2833. static struct notifier_block fbcon_output_nb;
  2834. static DECLARE_WORK(fbcon_deferred_takeover_work, fbcon_register_existing_fbs);
  2835. static int fbcon_output_notifier(struct notifier_block *nb,
  2836. unsigned long action, void *data)
  2837. {
  2838. WARN_CONSOLE_UNLOCKED();
  2839. pr_info("fbcon: Taking over console\n");
  2840. dummycon_unregister_output_notifier(&fbcon_output_nb);
  2841. deferred_takeover = false;
  2842. logo_shown = FBCON_LOGO_DONTSHOW;
  2843. /* We may get called in atomic context */
  2844. schedule_work(&fbcon_deferred_takeover_work);
  2845. return NOTIFY_OK;
  2846. }
  2847. #endif
  2848. static void fbcon_start(void)
  2849. {
  2850. WARN_CONSOLE_UNLOCKED();
  2851. #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
  2852. if (conswitchp != &dummy_con)
  2853. deferred_takeover = false;
  2854. if (deferred_takeover) {
  2855. fbcon_output_nb.notifier_call = fbcon_output_notifier;
  2856. dummycon_register_output_notifier(&fbcon_output_nb);
  2857. return;
  2858. }
  2859. #endif
  2860. if (num_registered_fb) {
  2861. int i;
  2862. for_each_registered_fb(i) {
  2863. info_idx = i;
  2864. break;
  2865. }
  2866. do_fbcon_takeover(0);
  2867. }
  2868. }
  2869. static void fbcon_exit(void)
  2870. {
  2871. struct fb_info *info;
  2872. int i, j, mapped;
  2873. if (fbcon_has_exited)
  2874. return;
  2875. #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
  2876. if (deferred_takeover) {
  2877. dummycon_unregister_output_notifier(&fbcon_output_nb);
  2878. deferred_takeover = false;
  2879. }
  2880. #endif
  2881. for_each_registered_fb(i) {
  2882. int pending = 0;
  2883. mapped = 0;
  2884. info = registered_fb[i];
  2885. if (info->queue.func)
  2886. pending = cancel_work_sync(&info->queue);
  2887. DPRINTK("fbcon: %s pending work\n", (pending ? "canceled" :
  2888. "no"));
  2889. for (j = first_fb_vc; j <= last_fb_vc; j++) {
  2890. if (con2fb_map[j] == i) {
  2891. mapped = 1;
  2892. break;
  2893. }
  2894. }
  2895. if (mapped) {
  2896. if (info->fbops->fb_release)
  2897. info->fbops->fb_release(info, 0);
  2898. module_put(info->fbops->owner);
  2899. if (info->fbcon_par) {
  2900. struct fbcon_ops *ops = info->fbcon_par;
  2901. fbcon_del_cursor_timer(info);
  2902. kfree(ops->cursor_src);
  2903. kfree(ops->cursor_state.mask);
  2904. kfree(info->fbcon_par);
  2905. info->fbcon_par = NULL;
  2906. }
  2907. if (info->queue.func == fb_flashcursor)
  2908. info->queue.func = NULL;
  2909. }
  2910. }
  2911. fbcon_has_exited = 1;
  2912. }
  2913. void __init fb_console_init(void)
  2914. {
  2915. int i;
  2916. console_lock();
  2917. fb_register_client(&fbcon_event_notifier);
  2918. fbcon_device = device_create(fb_class, NULL, MKDEV(0, 0), NULL,
  2919. "fbcon");
  2920. if (IS_ERR(fbcon_device)) {
  2921. printk(KERN_WARNING "Unable to create device "
  2922. "for fbcon; errno = %ld\n",
  2923. PTR_ERR(fbcon_device));
  2924. fbcon_device = NULL;
  2925. } else
  2926. fbcon_init_device();
  2927. for (i = 0; i < MAX_NR_CONSOLES; i++)
  2928. con2fb_map[i] = -1;
  2929. fbcon_start();
  2930. console_unlock();
  2931. }
  2932. #ifdef MODULE
  2933. static void __exit fbcon_deinit_device(void)
  2934. {
  2935. int i;
  2936. if (fbcon_has_sysfs) {
  2937. for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
  2938. device_remove_file(fbcon_device, &device_attrs[i]);
  2939. fbcon_has_sysfs = 0;
  2940. }
  2941. }
  2942. void __exit fb_console_exit(void)
  2943. {
  2944. console_lock();
  2945. fb_unregister_client(&fbcon_event_notifier);
  2946. fbcon_deinit_device();
  2947. device_destroy(fb_class, MKDEV(0, 0));
  2948. fbcon_exit();
  2949. do_unregister_con_driver(&fb_con);
  2950. console_unlock();
  2951. }
  2952. #endif