fbcon.c 81 KB

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