fbcon.c 83 KB

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