fbcon.c 87 KB

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