fbcon.c 76 KB

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