fbcon.c 87 KB

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