fbcon.c 89 KB

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