fbcon.c 70 KB

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