fbcon.c 80 KB

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