fbcon.c 74 KB

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