fbcon.c 87 KB

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