fbcon.c 86 KB

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