sisusb_con.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564
  1. /*
  2. * sisusb - usb kernel driver for SiS315(E) based USB2VGA dongles
  3. *
  4. * VGA text mode console part
  5. *
  6. * Copyright (C) 2005 by Thomas Winischhofer, Vienna, Austria
  7. *
  8. * If distributed as part of the Linux kernel, this code is licensed under the
  9. * terms of the GPL v2.
  10. *
  11. * Otherwise, the following license terms apply:
  12. *
  13. * * Redistribution and use in source and binary forms, with or without
  14. * * modification, are permitted provided that the following conditions
  15. * * are met:
  16. * * 1) Redistributions of source code must retain the above copyright
  17. * * notice, this list of conditions and the following disclaimer.
  18. * * 2) Redistributions in binary form must reproduce the above copyright
  19. * * notice, this list of conditions and the following disclaimer in the
  20. * * documentation and/or other materials provided with the distribution.
  21. * * 3) The name of the author may not be used to endorse or promote products
  22. * * derived from this software without specific psisusbr written permission.
  23. * *
  24. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESSED OR
  25. * * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  26. * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  27. * * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  28. * * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  29. * * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  30. * * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  31. * * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  32. * * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  33. * * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. * Author: Thomas Winischhofer <thomas@winischhofer.net>
  36. *
  37. * Portions based on vgacon.c which are
  38. * Created 28 Sep 1997 by Geert Uytterhoeven
  39. * Rewritten by Martin Mares <mj@ucw.cz>, July 1998
  40. * based on code Copyright (C) 1991, 1992 Linus Torvalds
  41. * 1995 Jay Estabrook
  42. *
  43. * A note on using in_atomic() in here: We can't handle console
  44. * calls from non-schedulable context due to our USB-dependend
  45. * nature. For now, this driver just ignores any calls if it
  46. * detects this state.
  47. *
  48. */
  49. #include <linux/mutex.h>
  50. #include <linux/module.h>
  51. #include <linux/kernel.h>
  52. #include <linux/signal.h>
  53. #include <linux/fs.h>
  54. #include <linux/usb.h>
  55. #include <linux/tty.h>
  56. #include <linux/console.h>
  57. #include <linux/string.h>
  58. #include <linux/kd.h>
  59. #include <linux/init.h>
  60. #include <linux/slab.h>
  61. #include <linux/vt_kern.h>
  62. #include <linux/selection.h>
  63. #include <linux/spinlock.h>
  64. #include <linux/kref.h>
  65. #include <linux/ioport.h>
  66. #include <linux/interrupt.h>
  67. #include <linux/vmalloc.h>
  68. #include "sisusb.h"
  69. #include "sisusb_init.h"
  70. #ifdef INCL_SISUSB_CON
  71. #define sisusbcon_writew(val, addr) (*(addr) = (val))
  72. #define sisusbcon_readw(addr) (*(addr))
  73. #define sisusbcon_memmovew(d, s, c) memmove(d, s, c)
  74. #define sisusbcon_memcpyw(d, s, c) memcpy(d, s, c)
  75. /* vc_data -> sisusb conversion table */
  76. static struct sisusb_usb_data *mysisusbs[MAX_NR_CONSOLES];
  77. /* Forward declaration */
  78. static const struct consw sisusb_con;
  79. static inline void
  80. sisusbcon_memsetw(u16 *s, u16 c, unsigned int count)
  81. {
  82. count /= 2;
  83. while (count--)
  84. sisusbcon_writew(c, s++);
  85. }
  86. static inline void
  87. sisusb_initialize(struct sisusb_usb_data *sisusb)
  88. {
  89. /* Reset cursor and start address */
  90. if (sisusb_setidxreg(sisusb, SISCR, 0x0c, 0x00))
  91. return;
  92. if (sisusb_setidxreg(sisusb, SISCR, 0x0d, 0x00))
  93. return;
  94. if (sisusb_setidxreg(sisusb, SISCR, 0x0e, 0x00))
  95. return;
  96. sisusb_setidxreg(sisusb, SISCR, 0x0f, 0x00);
  97. }
  98. static inline void
  99. sisusbcon_set_start_address(struct sisusb_usb_data *sisusb, struct vc_data *c)
  100. {
  101. sisusb->cur_start_addr = (c->vc_visible_origin - sisusb->scrbuf) / 2;
  102. sisusb_setidxreg(sisusb, SISCR, 0x0c, (sisusb->cur_start_addr >> 8));
  103. sisusb_setidxreg(sisusb, SISCR, 0x0d, (sisusb->cur_start_addr & 0xff));
  104. }
  105. void
  106. sisusb_set_cursor(struct sisusb_usb_data *sisusb, unsigned int location)
  107. {
  108. if (sisusb->sisusb_cursor_loc == location)
  109. return;
  110. sisusb->sisusb_cursor_loc = location;
  111. /* Hardware bug: Text cursor appears twice or not at all
  112. * at some positions. Work around it with the cursor skew
  113. * bits.
  114. */
  115. if ((location & 0x0007) == 0x0007) {
  116. sisusb->bad_cursor_pos = 1;
  117. location--;
  118. if (sisusb_setidxregandor(sisusb, SISCR, 0x0b, 0x1f, 0x20))
  119. return;
  120. } else if (sisusb->bad_cursor_pos) {
  121. if (sisusb_setidxregand(sisusb, SISCR, 0x0b, 0x1f))
  122. return;
  123. sisusb->bad_cursor_pos = 0;
  124. }
  125. if (sisusb_setidxreg(sisusb, SISCR, 0x0e, (location >> 8)))
  126. return;
  127. sisusb_setidxreg(sisusb, SISCR, 0x0f, (location & 0xff));
  128. }
  129. static inline struct sisusb_usb_data *
  130. sisusb_get_sisusb(unsigned short console)
  131. {
  132. return mysisusbs[console];
  133. }
  134. static inline int
  135. sisusb_sisusb_valid(struct sisusb_usb_data *sisusb)
  136. {
  137. if (!sisusb->present || !sisusb->ready || !sisusb->sisusb_dev)
  138. return 0;
  139. return 1;
  140. }
  141. static struct sisusb_usb_data *
  142. sisusb_get_sisusb_lock_and_check(unsigned short console)
  143. {
  144. struct sisusb_usb_data *sisusb;
  145. /* We can't handle console calls in non-schedulable
  146. * context due to our locks and the USB transport.
  147. * So we simply ignore them. This should only affect
  148. * some calls to printk.
  149. */
  150. if (in_atomic())
  151. return NULL;
  152. if (!(sisusb = sisusb_get_sisusb(console)))
  153. return NULL;
  154. mutex_lock(&sisusb->lock);
  155. if (!sisusb_sisusb_valid(sisusb) ||
  156. !sisusb->havethisconsole[console]) {
  157. mutex_unlock(&sisusb->lock);
  158. return NULL;
  159. }
  160. return sisusb;
  161. }
  162. static int
  163. sisusb_is_inactive(struct vc_data *c, struct sisusb_usb_data *sisusb)
  164. {
  165. if (sisusb->is_gfx ||
  166. sisusb->textmodedestroyed ||
  167. c->vc_mode != KD_TEXT)
  168. return 1;
  169. return 0;
  170. }
  171. /* con_startup console interface routine */
  172. static const char *
  173. sisusbcon_startup(void)
  174. {
  175. return "SISUSBCON";
  176. }
  177. /* con_init console interface routine */
  178. static void
  179. sisusbcon_init(struct vc_data *c, int init)
  180. {
  181. struct sisusb_usb_data *sisusb;
  182. int cols, rows;
  183. /* This is called by take_over_console(),
  184. * ie by us/under our control. It is
  185. * only called after text mode and fonts
  186. * are set up/restored.
  187. */
  188. if (!(sisusb = sisusb_get_sisusb(c->vc_num)))
  189. return;
  190. mutex_lock(&sisusb->lock);
  191. if (!sisusb_sisusb_valid(sisusb)) {
  192. mutex_unlock(&sisusb->lock);
  193. return;
  194. }
  195. c->vc_can_do_color = 1;
  196. c->vc_complement_mask = 0x7700;
  197. c->vc_hi_font_mask = sisusb->current_font_512 ? 0x0800 : 0;
  198. sisusb->haveconsole = 1;
  199. sisusb->havethisconsole[c->vc_num] = 1;
  200. /* We only support 640x400 */
  201. c->vc_scan_lines = 400;
  202. c->vc_font.height = sisusb->current_font_height;
  203. /* We only support width = 8 */
  204. cols = 80;
  205. rows = c->vc_scan_lines / c->vc_font.height;
  206. /* Increment usage count for our sisusb.
  207. * Doing so saves us from upping/downing
  208. * the disconnect semaphore; we can't
  209. * lose our sisusb until this is undone
  210. * in con_deinit. For all other console
  211. * interface functions, it suffices to
  212. * use sisusb->lock and do a quick check
  213. * of sisusb for device disconnection.
  214. */
  215. kref_get(&sisusb->kref);
  216. if (!*c->vc_uni_pagedir_loc)
  217. con_set_default_unimap(c);
  218. mutex_unlock(&sisusb->lock);
  219. if (init) {
  220. c->vc_cols = cols;
  221. c->vc_rows = rows;
  222. } else
  223. vc_resize(c, cols, rows);
  224. }
  225. /* con_deinit console interface routine */
  226. static void
  227. sisusbcon_deinit(struct vc_data *c)
  228. {
  229. struct sisusb_usb_data *sisusb;
  230. int i;
  231. /* This is called by take_over_console()
  232. * and others, ie not under our control.
  233. */
  234. if (!(sisusb = sisusb_get_sisusb(c->vc_num)))
  235. return;
  236. mutex_lock(&sisusb->lock);
  237. /* Clear ourselves in mysisusbs */
  238. mysisusbs[c->vc_num] = NULL;
  239. sisusb->havethisconsole[c->vc_num] = 0;
  240. /* Free our font buffer if all consoles are gone */
  241. if (sisusb->font_backup) {
  242. for(i = 0; i < MAX_NR_CONSOLES; i++) {
  243. if (sisusb->havethisconsole[c->vc_num])
  244. break;
  245. }
  246. if (i == MAX_NR_CONSOLES) {
  247. vfree(sisusb->font_backup);
  248. sisusb->font_backup = NULL;
  249. }
  250. }
  251. mutex_unlock(&sisusb->lock);
  252. /* decrement the usage count on our sisusb */
  253. kref_put(&sisusb->kref, sisusb_delete);
  254. }
  255. /* interface routine */
  256. static u8
  257. sisusbcon_build_attr(struct vc_data *c, u8 color, u8 intensity,
  258. u8 blink, u8 underline, u8 reverse, u8 unused)
  259. {
  260. u8 attr = color;
  261. if (underline)
  262. attr = (attr & 0xf0) | c->vc_ulcolor;
  263. else if (intensity == 0)
  264. attr = (attr & 0xf0) | c->vc_halfcolor;
  265. if (reverse)
  266. attr = ((attr) & 0x88) |
  267. ((((attr) >> 4) |
  268. ((attr) << 4)) & 0x77);
  269. if (blink)
  270. attr ^= 0x80;
  271. if (intensity == 2)
  272. attr ^= 0x08;
  273. return attr;
  274. }
  275. /* Interface routine */
  276. static void
  277. sisusbcon_invert_region(struct vc_data *vc, u16 *p, int count)
  278. {
  279. /* Invert a region. This is called with a pointer
  280. * to the console's internal screen buffer. So we
  281. * simply do the inversion there and rely on
  282. * a call to putc(s) to update the real screen.
  283. */
  284. while (count--) {
  285. u16 a = sisusbcon_readw(p);
  286. a = ((a) & 0x88ff) |
  287. (((a) & 0x7000) >> 4) |
  288. (((a) & 0x0700) << 4);
  289. sisusbcon_writew(a, p++);
  290. }
  291. }
  292. #define SISUSB_VADDR(x,y) \
  293. ((u16 *)c->vc_origin + \
  294. (y) * sisusb->sisusb_num_columns + \
  295. (x))
  296. #define SISUSB_HADDR(x,y) \
  297. ((u16 *)(sisusb->vrambase + (c->vc_origin - sisusb->scrbuf)) + \
  298. (y) * sisusb->sisusb_num_columns + \
  299. (x))
  300. /* Interface routine */
  301. static void
  302. sisusbcon_putc(struct vc_data *c, int ch, int y, int x)
  303. {
  304. struct sisusb_usb_data *sisusb;
  305. ssize_t written;
  306. if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
  307. return;
  308. /* sisusb->lock is down */
  309. if (sisusb_is_inactive(c, sisusb)) {
  310. mutex_unlock(&sisusb->lock);
  311. return;
  312. }
  313. sisusb_copy_memory(sisusb, (char *)SISUSB_VADDR(x, y),
  314. (long)SISUSB_HADDR(x, y), 2, &written);
  315. mutex_unlock(&sisusb->lock);
  316. }
  317. /* Interface routine */
  318. static void
  319. sisusbcon_putcs(struct vc_data *c, const unsigned short *s,
  320. int count, int y, int x)
  321. {
  322. struct sisusb_usb_data *sisusb;
  323. ssize_t written;
  324. u16 *dest;
  325. int i;
  326. if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
  327. return;
  328. /* sisusb->lock is down */
  329. /* Need to put the characters into the buffer ourselves,
  330. * because the vt does this AFTER calling us.
  331. */
  332. dest = SISUSB_VADDR(x, y);
  333. for (i = count; i > 0; i--)
  334. sisusbcon_writew(sisusbcon_readw(s++), dest++);
  335. if (sisusb_is_inactive(c, sisusb)) {
  336. mutex_unlock(&sisusb->lock);
  337. return;
  338. }
  339. sisusb_copy_memory(sisusb, (char *)SISUSB_VADDR(x, y),
  340. (long)SISUSB_HADDR(x, y), count * 2, &written);
  341. mutex_unlock(&sisusb->lock);
  342. }
  343. /* Interface routine */
  344. static void
  345. sisusbcon_clear(struct vc_data *c, int y, int x, int height, int width)
  346. {
  347. struct sisusb_usb_data *sisusb;
  348. u16 eattr = c->vc_video_erase_char;
  349. ssize_t written;
  350. int i, length, cols;
  351. u16 *dest;
  352. if (width <= 0 || height <= 0)
  353. return;
  354. if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
  355. return;
  356. /* sisusb->lock is down */
  357. /* Need to clear buffer ourselves, because the vt does
  358. * this AFTER calling us.
  359. */
  360. dest = SISUSB_VADDR(x, y);
  361. cols = sisusb->sisusb_num_columns;
  362. if (width > cols)
  363. width = cols;
  364. if (x == 0 && width >= c->vc_cols) {
  365. sisusbcon_memsetw(dest, eattr, height * cols * 2);
  366. } else {
  367. for (i = height; i > 0; i--, dest += cols)
  368. sisusbcon_memsetw(dest, eattr, width * 2);
  369. }
  370. if (sisusb_is_inactive(c, sisusb)) {
  371. mutex_unlock(&sisusb->lock);
  372. return;
  373. }
  374. length = ((height * cols) - x - (cols - width - x)) * 2;
  375. sisusb_copy_memory(sisusb, (unsigned char *)SISUSB_VADDR(x, y),
  376. (long)SISUSB_HADDR(x, y), length, &written);
  377. mutex_unlock(&sisusb->lock);
  378. }
  379. /* Interface routine */
  380. static void
  381. sisusbcon_bmove(struct vc_data *c, int sy, int sx,
  382. int dy, int dx, int height, int width)
  383. {
  384. struct sisusb_usb_data *sisusb;
  385. ssize_t written;
  386. int cols, length;
  387. if (width <= 0 || height <= 0)
  388. return;
  389. if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
  390. return;
  391. /* sisusb->lock is down */
  392. cols = sisusb->sisusb_num_columns;
  393. if (sisusb_is_inactive(c, sisusb)) {
  394. mutex_unlock(&sisusb->lock);
  395. return;
  396. }
  397. length = ((height * cols) - dx - (cols - width - dx)) * 2;
  398. sisusb_copy_memory(sisusb, (unsigned char *)SISUSB_VADDR(dx, dy),
  399. (long)SISUSB_HADDR(dx, dy), length, &written);
  400. mutex_unlock(&sisusb->lock);
  401. }
  402. /* interface routine */
  403. static int
  404. sisusbcon_switch(struct vc_data *c)
  405. {
  406. struct sisusb_usb_data *sisusb;
  407. ssize_t written;
  408. int length;
  409. /* Returnvalue 0 means we have fully restored screen,
  410. * and vt doesn't need to call do_update_region().
  411. * Returnvalue != 0 naturally means the opposite.
  412. */
  413. if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
  414. return 0;
  415. /* sisusb->lock is down */
  416. /* Don't write to screen if in gfx mode */
  417. if (sisusb_is_inactive(c, sisusb)) {
  418. mutex_unlock(&sisusb->lock);
  419. return 0;
  420. }
  421. /* That really should not happen. It would mean we are
  422. * being called while the vc is using its private buffer
  423. * as origin.
  424. */
  425. if (c->vc_origin == (unsigned long)c->vc_screenbuf) {
  426. mutex_unlock(&sisusb->lock);
  427. dev_dbg(&sisusb->sisusb_dev->dev, "ASSERT ORIGIN != SCREENBUF!\n");
  428. return 0;
  429. }
  430. /* Check that we don't copy too much */
  431. length = min((int)c->vc_screenbuf_size,
  432. (int)(sisusb->scrbuf + sisusb->scrbuf_size - c->vc_origin));
  433. /* Restore the screen contents */
  434. sisusbcon_memcpyw((u16 *)c->vc_origin, (u16 *)c->vc_screenbuf,
  435. length);
  436. sisusb_copy_memory(sisusb, (unsigned char *)c->vc_origin,
  437. (long)SISUSB_HADDR(0, 0),
  438. length, &written);
  439. mutex_unlock(&sisusb->lock);
  440. return 0;
  441. }
  442. /* interface routine */
  443. static void
  444. sisusbcon_save_screen(struct vc_data *c)
  445. {
  446. struct sisusb_usb_data *sisusb;
  447. int length;
  448. /* Save the current screen contents to vc's private
  449. * buffer.
  450. */
  451. if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
  452. return;
  453. /* sisusb->lock is down */
  454. if (sisusb_is_inactive(c, sisusb)) {
  455. mutex_unlock(&sisusb->lock);
  456. return;
  457. }
  458. /* Check that we don't copy too much */
  459. length = min((int)c->vc_screenbuf_size,
  460. (int)(sisusb->scrbuf + sisusb->scrbuf_size - c->vc_origin));
  461. /* Save the screen contents to vc's private buffer */
  462. sisusbcon_memcpyw((u16 *)c->vc_screenbuf, (u16 *)c->vc_origin,
  463. length);
  464. mutex_unlock(&sisusb->lock);
  465. }
  466. /* interface routine */
  467. static int
  468. sisusbcon_set_palette(struct vc_data *c, unsigned char *table)
  469. {
  470. struct sisusb_usb_data *sisusb;
  471. int i, j;
  472. /* Return value not used by vt */
  473. if (!CON_IS_VISIBLE(c))
  474. return -EINVAL;
  475. if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
  476. return -EINVAL;
  477. /* sisusb->lock is down */
  478. if (sisusb_is_inactive(c, sisusb)) {
  479. mutex_unlock(&sisusb->lock);
  480. return -EINVAL;
  481. }
  482. for (i = j = 0; i < 16; i++) {
  483. if (sisusb_setreg(sisusb, SISCOLIDX, table[i]))
  484. break;
  485. if (sisusb_setreg(sisusb, SISCOLDATA, c->vc_palette[j++] >> 2))
  486. break;
  487. if (sisusb_setreg(sisusb, SISCOLDATA, c->vc_palette[j++] >> 2))
  488. break;
  489. if (sisusb_setreg(sisusb, SISCOLDATA, c->vc_palette[j++] >> 2))
  490. break;
  491. }
  492. mutex_unlock(&sisusb->lock);
  493. return 0;
  494. }
  495. /* interface routine */
  496. static int
  497. sisusbcon_blank(struct vc_data *c, int blank, int mode_switch)
  498. {
  499. struct sisusb_usb_data *sisusb;
  500. u8 sr1, cr17, pmreg, cr63;
  501. ssize_t written;
  502. int ret = 0;
  503. if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
  504. return 0;
  505. /* sisusb->lock is down */
  506. if (mode_switch)
  507. sisusb->is_gfx = blank ? 1 : 0;
  508. if (sisusb_is_inactive(c, sisusb)) {
  509. mutex_unlock(&sisusb->lock);
  510. return 0;
  511. }
  512. switch (blank) {
  513. case 1: /* Normal blanking: Clear screen */
  514. case -1:
  515. sisusbcon_memsetw((u16 *)c->vc_origin,
  516. c->vc_video_erase_char,
  517. c->vc_screenbuf_size);
  518. sisusb_copy_memory(sisusb,
  519. (unsigned char *)c->vc_origin,
  520. (u32)(sisusb->vrambase +
  521. (c->vc_origin - sisusb->scrbuf)),
  522. c->vc_screenbuf_size, &written);
  523. sisusb->con_blanked = 1;
  524. ret = 1;
  525. break;
  526. default: /* VESA blanking */
  527. switch (blank) {
  528. case 0: /* Unblank */
  529. sr1 = 0x00;
  530. cr17 = 0x80;
  531. pmreg = 0x00;
  532. cr63 = 0x00;
  533. ret = 1;
  534. sisusb->con_blanked = 0;
  535. break;
  536. case VESA_VSYNC_SUSPEND + 1:
  537. sr1 = 0x20;
  538. cr17 = 0x80;
  539. pmreg = 0x80;
  540. cr63 = 0x40;
  541. break;
  542. case VESA_HSYNC_SUSPEND + 1:
  543. sr1 = 0x20;
  544. cr17 = 0x80;
  545. pmreg = 0x40;
  546. cr63 = 0x40;
  547. break;
  548. case VESA_POWERDOWN + 1:
  549. sr1 = 0x20;
  550. cr17 = 0x00;
  551. pmreg = 0xc0;
  552. cr63 = 0x40;
  553. break;
  554. default:
  555. mutex_unlock(&sisusb->lock);
  556. return -EINVAL;
  557. }
  558. sisusb_setidxregandor(sisusb, SISSR, 0x01, ~0x20, sr1);
  559. sisusb_setidxregandor(sisusb, SISCR, 0x17, 0x7f, cr17);
  560. sisusb_setidxregandor(sisusb, SISSR, 0x1f, 0x3f, pmreg);
  561. sisusb_setidxregandor(sisusb, SISCR, 0x63, 0xbf, cr63);
  562. }
  563. mutex_unlock(&sisusb->lock);
  564. return ret;
  565. }
  566. /* interface routine */
  567. static int
  568. sisusbcon_scrolldelta(struct vc_data *c, int lines)
  569. {
  570. struct sisusb_usb_data *sisusb;
  571. int margin = c->vc_size_row * 4;
  572. int ul, we, p, st;
  573. /* The return value does not seem to be used */
  574. if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
  575. return 0;
  576. /* sisusb->lock is down */
  577. if (sisusb_is_inactive(c, sisusb)) {
  578. mutex_unlock(&sisusb->lock);
  579. return 0;
  580. }
  581. if (!lines) /* Turn scrollback off */
  582. c->vc_visible_origin = c->vc_origin;
  583. else {
  584. if (sisusb->con_rolled_over >
  585. (c->vc_scr_end - sisusb->scrbuf) + margin) {
  586. ul = c->vc_scr_end - sisusb->scrbuf;
  587. we = sisusb->con_rolled_over + c->vc_size_row;
  588. } else {
  589. ul = 0;
  590. we = sisusb->scrbuf_size;
  591. }
  592. p = (c->vc_visible_origin - sisusb->scrbuf - ul + we) % we +
  593. lines * c->vc_size_row;
  594. st = (c->vc_origin - sisusb->scrbuf - ul + we) % we;
  595. if (st < 2 * margin)
  596. margin = 0;
  597. if (p < margin)
  598. p = 0;
  599. if (p > st - margin)
  600. p = st;
  601. c->vc_visible_origin = sisusb->scrbuf + (p + ul) % we;
  602. }
  603. sisusbcon_set_start_address(sisusb, c);
  604. mutex_unlock(&sisusb->lock);
  605. return 1;
  606. }
  607. /* Interface routine */
  608. static void
  609. sisusbcon_cursor(struct vc_data *c, int mode)
  610. {
  611. struct sisusb_usb_data *sisusb;
  612. int from, to, baseline;
  613. if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
  614. return;
  615. /* sisusb->lock is down */
  616. if (sisusb_is_inactive(c, sisusb)) {
  617. mutex_unlock(&sisusb->lock);
  618. return;
  619. }
  620. if (c->vc_origin != c->vc_visible_origin) {
  621. c->vc_visible_origin = c->vc_origin;
  622. sisusbcon_set_start_address(sisusb, c);
  623. }
  624. if (mode == CM_ERASE) {
  625. sisusb_setidxregor(sisusb, SISCR, 0x0a, 0x20);
  626. sisusb->sisusb_cursor_size_to = -1;
  627. mutex_unlock(&sisusb->lock);
  628. return;
  629. }
  630. sisusb_set_cursor(sisusb, (c->vc_pos - sisusb->scrbuf) / 2);
  631. baseline = c->vc_font.height - (c->vc_font.height < 10 ? 1 : 2);
  632. switch (c->vc_cursor_type & 0x0f) {
  633. case CUR_BLOCK: from = 1;
  634. to = c->vc_font.height;
  635. break;
  636. case CUR_TWO_THIRDS: from = c->vc_font.height / 3;
  637. to = baseline;
  638. break;
  639. case CUR_LOWER_HALF: from = c->vc_font.height / 2;
  640. to = baseline;
  641. break;
  642. case CUR_LOWER_THIRD: from = (c->vc_font.height * 2) / 3;
  643. to = baseline;
  644. break;
  645. case CUR_NONE: from = 31;
  646. to = 30;
  647. break;
  648. default:
  649. case CUR_UNDERLINE: from = baseline - 1;
  650. to = baseline;
  651. break;
  652. }
  653. if (sisusb->sisusb_cursor_size_from != from ||
  654. sisusb->sisusb_cursor_size_to != to) {
  655. sisusb_setidxreg(sisusb, SISCR, 0x0a, from);
  656. sisusb_setidxregandor(sisusb, SISCR, 0x0b, 0xe0, to);
  657. sisusb->sisusb_cursor_size_from = from;
  658. sisusb->sisusb_cursor_size_to = to;
  659. }
  660. mutex_unlock(&sisusb->lock);
  661. }
  662. static int
  663. sisusbcon_scroll_area(struct vc_data *c, struct sisusb_usb_data *sisusb,
  664. int t, int b, int dir, int lines)
  665. {
  666. int cols = sisusb->sisusb_num_columns;
  667. int length = ((b - t) * cols) * 2;
  668. u16 eattr = c->vc_video_erase_char;
  669. ssize_t written;
  670. /* sisusb->lock is down */
  671. /* Scroll an area which does not match the
  672. * visible screen's dimensions. This needs
  673. * to be done separately, as it does not
  674. * use hardware panning.
  675. */
  676. switch (dir) {
  677. case SM_UP:
  678. sisusbcon_memmovew(SISUSB_VADDR(0, t),
  679. SISUSB_VADDR(0, t + lines),
  680. (b - t - lines) * cols * 2);
  681. sisusbcon_memsetw(SISUSB_VADDR(0, b - lines), eattr,
  682. lines * cols * 2);
  683. break;
  684. case SM_DOWN:
  685. sisusbcon_memmovew(SISUSB_VADDR(0, t + lines),
  686. SISUSB_VADDR(0, t),
  687. (b - t - lines) * cols * 2);
  688. sisusbcon_memsetw(SISUSB_VADDR(0, t), eattr,
  689. lines * cols * 2);
  690. break;
  691. }
  692. sisusb_copy_memory(sisusb, (char *)SISUSB_VADDR(0, t),
  693. (long)SISUSB_HADDR(0, t), length, &written);
  694. mutex_unlock(&sisusb->lock);
  695. return 1;
  696. }
  697. /* Interface routine */
  698. static int
  699. sisusbcon_scroll(struct vc_data *c, int t, int b, int dir, int lines)
  700. {
  701. struct sisusb_usb_data *sisusb;
  702. u16 eattr = c->vc_video_erase_char;
  703. ssize_t written;
  704. int copyall = 0;
  705. unsigned long oldorigin;
  706. unsigned int delta = lines * c->vc_size_row;
  707. u32 originoffset;
  708. /* Returning != 0 means we have done the scrolling successfully.
  709. * Returning 0 makes vt do the scrolling on its own.
  710. * Note that con_scroll is only called if the console is
  711. * visible. In that case, the origin should be our buffer,
  712. * not the vt's private one.
  713. */
  714. if (!lines)
  715. return 1;
  716. if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
  717. return 0;
  718. /* sisusb->lock is down */
  719. if (sisusb_is_inactive(c, sisusb)) {
  720. mutex_unlock(&sisusb->lock);
  721. return 0;
  722. }
  723. /* Special case */
  724. if (t || b != c->vc_rows)
  725. return sisusbcon_scroll_area(c, sisusb, t, b, dir, lines);
  726. if (c->vc_origin != c->vc_visible_origin) {
  727. c->vc_visible_origin = c->vc_origin;
  728. sisusbcon_set_start_address(sisusb, c);
  729. }
  730. /* limit amount to maximum realistic size */
  731. if (lines > c->vc_rows)
  732. lines = c->vc_rows;
  733. oldorigin = c->vc_origin;
  734. switch (dir) {
  735. case SM_UP:
  736. if (c->vc_scr_end + delta >=
  737. sisusb->scrbuf + sisusb->scrbuf_size) {
  738. sisusbcon_memcpyw((u16 *)sisusb->scrbuf,
  739. (u16 *)(oldorigin + delta),
  740. c->vc_screenbuf_size - delta);
  741. c->vc_origin = sisusb->scrbuf;
  742. sisusb->con_rolled_over = oldorigin - sisusb->scrbuf;
  743. copyall = 1;
  744. } else
  745. c->vc_origin += delta;
  746. sisusbcon_memsetw(
  747. (u16 *)(c->vc_origin + c->vc_screenbuf_size - delta),
  748. eattr, delta);
  749. break;
  750. case SM_DOWN:
  751. if (oldorigin - delta < sisusb->scrbuf) {
  752. sisusbcon_memmovew((u16 *)(sisusb->scrbuf +
  753. sisusb->scrbuf_size -
  754. c->vc_screenbuf_size +
  755. delta),
  756. (u16 *)oldorigin,
  757. c->vc_screenbuf_size - delta);
  758. c->vc_origin = sisusb->scrbuf +
  759. sisusb->scrbuf_size -
  760. c->vc_screenbuf_size;
  761. sisusb->con_rolled_over = 0;
  762. copyall = 1;
  763. } else
  764. c->vc_origin -= delta;
  765. c->vc_scr_end = c->vc_origin + c->vc_screenbuf_size;
  766. scr_memsetw((u16 *)(c->vc_origin), eattr, delta);
  767. break;
  768. }
  769. originoffset = (u32)(c->vc_origin - sisusb->scrbuf);
  770. if (copyall)
  771. sisusb_copy_memory(sisusb,
  772. (char *)c->vc_origin,
  773. (u32)(sisusb->vrambase + originoffset),
  774. c->vc_screenbuf_size, &written);
  775. else if (dir == SM_UP)
  776. sisusb_copy_memory(sisusb,
  777. (char *)c->vc_origin + c->vc_screenbuf_size - delta,
  778. (u32)sisusb->vrambase + originoffset +
  779. c->vc_screenbuf_size - delta,
  780. delta, &written);
  781. else
  782. sisusb_copy_memory(sisusb,
  783. (char *)c->vc_origin,
  784. (u32)(sisusb->vrambase + originoffset),
  785. delta, &written);
  786. c->vc_scr_end = c->vc_origin + c->vc_screenbuf_size;
  787. c->vc_visible_origin = c->vc_origin;
  788. sisusbcon_set_start_address(sisusb, c);
  789. c->vc_pos = c->vc_pos - oldorigin + c->vc_origin;
  790. mutex_unlock(&sisusb->lock);
  791. return 1;
  792. }
  793. /* Interface routine */
  794. static int
  795. sisusbcon_set_origin(struct vc_data *c)
  796. {
  797. struct sisusb_usb_data *sisusb;
  798. /* Returning != 0 means we were successful.
  799. * Returning 0 will vt make to use its own
  800. * screenbuffer as the origin.
  801. */
  802. if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
  803. return 0;
  804. /* sisusb->lock is down */
  805. if (sisusb_is_inactive(c, sisusb) || sisusb->con_blanked) {
  806. mutex_unlock(&sisusb->lock);
  807. return 0;
  808. }
  809. c->vc_origin = c->vc_visible_origin = sisusb->scrbuf;
  810. sisusbcon_set_start_address(sisusb, c);
  811. sisusb->con_rolled_over = 0;
  812. mutex_unlock(&sisusb->lock);
  813. return 1;
  814. }
  815. /* Interface routine */
  816. static int
  817. sisusbcon_resize(struct vc_data *c, unsigned int newcols, unsigned int newrows)
  818. {
  819. struct sisusb_usb_data *sisusb;
  820. int fh;
  821. if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
  822. return -ENODEV;
  823. fh = sisusb->current_font_height;
  824. mutex_unlock(&sisusb->lock);
  825. /* We are quite unflexible as regards resizing. The vt code
  826. * handles sizes where the line length isn't equal the pitch
  827. * quite badly. As regards the rows, our panning tricks only
  828. * work well if the number of rows equals the visible number
  829. * of rows.
  830. */
  831. if (newcols != 80 || c->vc_scan_lines / fh != newrows)
  832. return -EINVAL;
  833. return 0;
  834. }
  835. int
  836. sisusbcon_do_font_op(struct sisusb_usb_data *sisusb, int set, int slot,
  837. u8 *arg, int cmapsz, int ch512, int dorecalc,
  838. struct vc_data *c, int fh, int uplock)
  839. {
  840. int font_select = 0x00, i, err = 0;
  841. u32 offset = 0;
  842. u8 dummy;
  843. /* sisusb->lock is down */
  844. /*
  845. * The default font is kept in slot 0.
  846. * A user font is loaded in slot 2 (256 ch)
  847. * or 2+3 (512 ch).
  848. */
  849. if ((slot != 0 && slot != 2) || !fh) {
  850. if (uplock)
  851. mutex_unlock(&sisusb->lock);
  852. return -EINVAL;
  853. }
  854. if (set)
  855. sisusb->font_slot = slot;
  856. /* Default font is always 256 */
  857. if (slot == 0)
  858. ch512 = 0;
  859. else
  860. offset = 4 * cmapsz;
  861. font_select = (slot == 0) ? 0x00 : (ch512 ? 0x0e : 0x0a);
  862. err |= sisusb_setidxreg(sisusb, SISSR, 0x00, 0x01); /* Reset */
  863. err |= sisusb_setidxreg(sisusb, SISSR, 0x02, 0x04); /* Write to plane 2 */
  864. err |= sisusb_setidxreg(sisusb, SISSR, 0x04, 0x07); /* Memory mode a0-bf */
  865. err |= sisusb_setidxreg(sisusb, SISSR, 0x00, 0x03); /* Reset */
  866. if (err)
  867. goto font_op_error;
  868. err |= sisusb_setidxreg(sisusb, SISGR, 0x04, 0x03); /* Select plane read 2 */
  869. err |= sisusb_setidxreg(sisusb, SISGR, 0x05, 0x00); /* Disable odd/even */
  870. err |= sisusb_setidxreg(sisusb, SISGR, 0x06, 0x00); /* Address range a0-bf */
  871. if (err)
  872. goto font_op_error;
  873. if (arg) {
  874. if (set)
  875. for (i = 0; i < cmapsz; i++) {
  876. err |= sisusb_writeb(sisusb,
  877. sisusb->vrambase + offset + i,
  878. arg[i]);
  879. if (err)
  880. break;
  881. }
  882. else
  883. for (i = 0; i < cmapsz; i++) {
  884. err |= sisusb_readb(sisusb,
  885. sisusb->vrambase + offset + i,
  886. &arg[i]);
  887. if (err)
  888. break;
  889. }
  890. /*
  891. * In 512-character mode, the character map is not contiguous if
  892. * we want to remain EGA compatible -- which we do
  893. */
  894. if (ch512) {
  895. if (set)
  896. for (i = 0; i < cmapsz; i++) {
  897. err |= sisusb_writeb(sisusb,
  898. sisusb->vrambase + offset +
  899. (2 * cmapsz) + i,
  900. arg[cmapsz + i]);
  901. if (err)
  902. break;
  903. }
  904. else
  905. for (i = 0; i < cmapsz; i++) {
  906. err |= sisusb_readb(sisusb,
  907. sisusb->vrambase + offset +
  908. (2 * cmapsz) + i,
  909. &arg[cmapsz + i]);
  910. if (err)
  911. break;
  912. }
  913. }
  914. }
  915. if (err)
  916. goto font_op_error;
  917. err |= sisusb_setidxreg(sisusb, SISSR, 0x00, 0x01); /* Reset */
  918. err |= sisusb_setidxreg(sisusb, SISSR, 0x02, 0x03); /* Write to planes 0+1 */
  919. err |= sisusb_setidxreg(sisusb, SISSR, 0x04, 0x03); /* Memory mode a0-bf */
  920. if (set)
  921. sisusb_setidxreg(sisusb, SISSR, 0x03, font_select);
  922. err |= sisusb_setidxreg(sisusb, SISSR, 0x00, 0x03); /* Reset end */
  923. if (err)
  924. goto font_op_error;
  925. err |= sisusb_setidxreg(sisusb, SISGR, 0x04, 0x00); /* Select plane read 0 */
  926. err |= sisusb_setidxreg(sisusb, SISGR, 0x05, 0x10); /* Enable odd/even */
  927. err |= sisusb_setidxreg(sisusb, SISGR, 0x06, 0x06); /* Address range b8-bf */
  928. if (err)
  929. goto font_op_error;
  930. if ((set) && (ch512 != sisusb->current_font_512)) {
  931. /* Font is shared among all our consoles.
  932. * And so is the hi_font_mask.
  933. */
  934. for (i = 0; i < MAX_NR_CONSOLES; i++) {
  935. struct vc_data *c = vc_cons[i].d;
  936. if (c && c->vc_sw == &sisusb_con)
  937. c->vc_hi_font_mask = ch512 ? 0x0800 : 0;
  938. }
  939. sisusb->current_font_512 = ch512;
  940. /* color plane enable register:
  941. 256-char: enable intensity bit
  942. 512-char: disable intensity bit */
  943. sisusb_getreg(sisusb, SISINPSTAT, &dummy);
  944. sisusb_setreg(sisusb, SISAR, 0x12);
  945. sisusb_setreg(sisusb, SISAR, ch512 ? 0x07 : 0x0f);
  946. sisusb_getreg(sisusb, SISINPSTAT, &dummy);
  947. sisusb_setreg(sisusb, SISAR, 0x20);
  948. sisusb_getreg(sisusb, SISINPSTAT, &dummy);
  949. }
  950. if (dorecalc) {
  951. /*
  952. * Adjust the screen to fit a font of a certain height
  953. */
  954. unsigned char ovr, vde, fsr;
  955. int rows = 0, maxscan = 0;
  956. if (c) {
  957. /* Number of video rows */
  958. rows = c->vc_scan_lines / fh;
  959. /* Scan lines to actually display-1 */
  960. maxscan = rows * fh - 1;
  961. /*printk(KERN_DEBUG "sisusb recalc rows %d maxscan %d fh %d sl %d\n",
  962. rows, maxscan, fh, c->vc_scan_lines);*/
  963. sisusb_getidxreg(sisusb, SISCR, 0x07, &ovr);
  964. vde = maxscan & 0xff;
  965. ovr = (ovr & 0xbd) |
  966. ((maxscan & 0x100) >> 7) |
  967. ((maxscan & 0x200) >> 3);
  968. sisusb_setidxreg(sisusb, SISCR, 0x07, ovr);
  969. sisusb_setidxreg(sisusb, SISCR, 0x12, vde);
  970. }
  971. sisusb_getidxreg(sisusb, SISCR, 0x09, &fsr);
  972. fsr = (fsr & 0xe0) | (fh - 1);
  973. sisusb_setidxreg(sisusb, SISCR, 0x09, fsr);
  974. sisusb->current_font_height = fh;
  975. sisusb->sisusb_cursor_size_from = -1;
  976. sisusb->sisusb_cursor_size_to = -1;
  977. }
  978. if (uplock)
  979. mutex_unlock(&sisusb->lock);
  980. if (dorecalc && c) {
  981. int i, rows = c->vc_scan_lines / fh;
  982. /* Now adjust our consoles' size */
  983. for (i = 0; i < MAX_NR_CONSOLES; i++) {
  984. struct vc_data *vc = vc_cons[i].d;
  985. if (vc && vc->vc_sw == &sisusb_con) {
  986. if (CON_IS_VISIBLE(vc)) {
  987. vc->vc_sw->con_cursor(vc, CM_DRAW);
  988. }
  989. vc->vc_font.height = fh;
  990. vc_resize(vc, 0, rows);
  991. }
  992. }
  993. }
  994. return 0;
  995. font_op_error:
  996. if (uplock)
  997. mutex_unlock(&sisusb->lock);
  998. return -EIO;
  999. }
  1000. /* Interface routine */
  1001. static int
  1002. sisusbcon_font_set(struct vc_data *c, struct console_font *font,
  1003. unsigned flags)
  1004. {
  1005. struct sisusb_usb_data *sisusb;
  1006. unsigned charcount = font->charcount;
  1007. if (font->width != 8 || (charcount != 256 && charcount != 512))
  1008. return -EINVAL;
  1009. if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
  1010. return -ENODEV;
  1011. /* sisusb->lock is down */
  1012. /* Save the user-provided font into a buffer. This
  1013. * is used for restoring text mode after quitting
  1014. * from X and for the con_getfont routine.
  1015. */
  1016. if (sisusb->font_backup) {
  1017. if (sisusb->font_backup_size < charcount) {
  1018. vfree(sisusb->font_backup);
  1019. sisusb->font_backup = NULL;
  1020. }
  1021. }
  1022. if (!sisusb->font_backup)
  1023. sisusb->font_backup = vmalloc(charcount * 32);
  1024. if (sisusb->font_backup) {
  1025. memcpy(sisusb->font_backup, font->data, charcount * 32);
  1026. sisusb->font_backup_size = charcount;
  1027. sisusb->font_backup_height = font->height;
  1028. sisusb->font_backup_512 = (charcount == 512) ? 1 : 0;
  1029. }
  1030. /* do_font_op ups sisusb->lock */
  1031. return sisusbcon_do_font_op(sisusb, 1, 2, font->data,
  1032. 8192, (charcount == 512),
  1033. (!(flags & KD_FONT_FLAG_DONT_RECALC)) ? 1 : 0,
  1034. c, font->height, 1);
  1035. }
  1036. /* Interface routine */
  1037. static int
  1038. sisusbcon_font_get(struct vc_data *c, struct console_font *font)
  1039. {
  1040. struct sisusb_usb_data *sisusb;
  1041. if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
  1042. return -ENODEV;
  1043. /* sisusb->lock is down */
  1044. font->width = 8;
  1045. font->height = c->vc_font.height;
  1046. font->charcount = 256;
  1047. if (!font->data) {
  1048. mutex_unlock(&sisusb->lock);
  1049. return 0;
  1050. }
  1051. if (!sisusb->font_backup) {
  1052. mutex_unlock(&sisusb->lock);
  1053. return -ENODEV;
  1054. }
  1055. /* Copy 256 chars only, like vgacon */
  1056. memcpy(font->data, sisusb->font_backup, 256 * 32);
  1057. mutex_unlock(&sisusb->lock);
  1058. return 0;
  1059. }
  1060. /*
  1061. * The console `switch' structure for the sisusb console
  1062. */
  1063. static const struct consw sisusb_con = {
  1064. .owner = THIS_MODULE,
  1065. .con_startup = sisusbcon_startup,
  1066. .con_init = sisusbcon_init,
  1067. .con_deinit = sisusbcon_deinit,
  1068. .con_clear = sisusbcon_clear,
  1069. .con_putc = sisusbcon_putc,
  1070. .con_putcs = sisusbcon_putcs,
  1071. .con_cursor = sisusbcon_cursor,
  1072. .con_scroll = sisusbcon_scroll,
  1073. .con_bmove = sisusbcon_bmove,
  1074. .con_switch = sisusbcon_switch,
  1075. .con_blank = sisusbcon_blank,
  1076. .con_font_set = sisusbcon_font_set,
  1077. .con_font_get = sisusbcon_font_get,
  1078. .con_set_palette = sisusbcon_set_palette,
  1079. .con_scrolldelta = sisusbcon_scrolldelta,
  1080. .con_build_attr = sisusbcon_build_attr,
  1081. .con_invert_region = sisusbcon_invert_region,
  1082. .con_set_origin = sisusbcon_set_origin,
  1083. .con_save_screen = sisusbcon_save_screen,
  1084. .con_resize = sisusbcon_resize,
  1085. };
  1086. /* Our very own dummy console driver */
  1087. static const char *sisusbdummycon_startup(void)
  1088. {
  1089. return "SISUSBVGADUMMY";
  1090. }
  1091. static void sisusbdummycon_init(struct vc_data *vc, int init)
  1092. {
  1093. vc->vc_can_do_color = 1;
  1094. if (init) {
  1095. vc->vc_cols = 80;
  1096. vc->vc_rows = 25;
  1097. } else
  1098. vc_resize(vc, 80, 25);
  1099. }
  1100. static int sisusbdummycon_dummy(void)
  1101. {
  1102. return 0;
  1103. }
  1104. #define SISUSBCONDUMMY (void *)sisusbdummycon_dummy
  1105. static const struct consw sisusb_dummy_con = {
  1106. .owner = THIS_MODULE,
  1107. .con_startup = sisusbdummycon_startup,
  1108. .con_init = sisusbdummycon_init,
  1109. .con_deinit = SISUSBCONDUMMY,
  1110. .con_clear = SISUSBCONDUMMY,
  1111. .con_putc = SISUSBCONDUMMY,
  1112. .con_putcs = SISUSBCONDUMMY,
  1113. .con_cursor = SISUSBCONDUMMY,
  1114. .con_scroll = SISUSBCONDUMMY,
  1115. .con_bmove = SISUSBCONDUMMY,
  1116. .con_switch = SISUSBCONDUMMY,
  1117. .con_blank = SISUSBCONDUMMY,
  1118. .con_font_set = SISUSBCONDUMMY,
  1119. .con_font_get = SISUSBCONDUMMY,
  1120. .con_font_default = SISUSBCONDUMMY,
  1121. .con_font_copy = SISUSBCONDUMMY,
  1122. .con_set_palette = SISUSBCONDUMMY,
  1123. .con_scrolldelta = SISUSBCONDUMMY,
  1124. };
  1125. int
  1126. sisusb_console_init(struct sisusb_usb_data *sisusb, int first, int last)
  1127. {
  1128. int i, ret;
  1129. mutex_lock(&sisusb->lock);
  1130. /* Erm.. that should not happen */
  1131. if (sisusb->haveconsole || !sisusb->SiS_Pr) {
  1132. mutex_unlock(&sisusb->lock);
  1133. return 1;
  1134. }
  1135. sisusb->con_first = first;
  1136. sisusb->con_last = last;
  1137. if (first > last ||
  1138. first > MAX_NR_CONSOLES ||
  1139. last > MAX_NR_CONSOLES) {
  1140. mutex_unlock(&sisusb->lock);
  1141. return 1;
  1142. }
  1143. /* If gfxcore not initialized or no consoles given, quit graciously */
  1144. if (!sisusb->gfxinit || first < 1 || last < 1) {
  1145. mutex_unlock(&sisusb->lock);
  1146. return 0;
  1147. }
  1148. sisusb->sisusb_cursor_loc = -1;
  1149. sisusb->sisusb_cursor_size_from = -1;
  1150. sisusb->sisusb_cursor_size_to = -1;
  1151. /* Set up text mode (and upload default font) */
  1152. if (sisusb_reset_text_mode(sisusb, 1)) {
  1153. mutex_unlock(&sisusb->lock);
  1154. dev_err(&sisusb->sisusb_dev->dev, "Failed to set up text mode\n");
  1155. return 1;
  1156. }
  1157. /* Initialize some gfx registers */
  1158. sisusb_initialize(sisusb);
  1159. for (i = first - 1; i <= last - 1; i++) {
  1160. /* Save sisusb for our interface routines */
  1161. mysisusbs[i] = sisusb;
  1162. }
  1163. /* Initial console setup */
  1164. sisusb->sisusb_num_columns = 80;
  1165. /* Use a 32K buffer (matches b8000-bffff area) */
  1166. sisusb->scrbuf_size = 32 * 1024;
  1167. /* Allocate screen buffer */
  1168. if (!(sisusb->scrbuf = (unsigned long)vmalloc(sisusb->scrbuf_size))) {
  1169. mutex_unlock(&sisusb->lock);
  1170. dev_err(&sisusb->sisusb_dev->dev, "Failed to allocate screen buffer\n");
  1171. return 1;
  1172. }
  1173. mutex_unlock(&sisusb->lock);
  1174. /* Now grab the desired console(s) */
  1175. ret = take_over_console(&sisusb_con, first - 1, last - 1, 0);
  1176. if (!ret)
  1177. sisusb->haveconsole = 1;
  1178. else {
  1179. for (i = first - 1; i <= last - 1; i++)
  1180. mysisusbs[i] = NULL;
  1181. }
  1182. return ret;
  1183. }
  1184. void
  1185. sisusb_console_exit(struct sisusb_usb_data *sisusb)
  1186. {
  1187. int i;
  1188. /* This is called if the device is disconnected
  1189. * and while disconnect and lock semaphores
  1190. * are up. This should be save because we
  1191. * can't lose our sisusb any other way but by
  1192. * disconnection (and hence, the disconnect
  1193. * sema is for protecting all other access
  1194. * functions from disconnection, not the
  1195. * other way round).
  1196. */
  1197. /* Now what do we do in case of disconnection:
  1198. * One alternative would be to simply call
  1199. * give_up_console(). Nah, not a good idea.
  1200. * give_up_console() is obviously buggy as it
  1201. * only discards the consw pointer from the
  1202. * driver_map, but doesn't adapt vc->vc_sw
  1203. * of the affected consoles. Hence, the next
  1204. * call to any of the console functions will
  1205. * eventually take a trip to oops county.
  1206. * Also, give_up_console for some reason
  1207. * doesn't decrement our module refcount.
  1208. * Instead, we switch our consoles to a private
  1209. * dummy console. This, of course, keeps our
  1210. * refcount up as well, but it works perfectly.
  1211. */
  1212. if (sisusb->haveconsole) {
  1213. for (i = 0; i < MAX_NR_CONSOLES; i++)
  1214. if (sisusb->havethisconsole[i])
  1215. take_over_console(&sisusb_dummy_con, i, i, 0);
  1216. /* At this point, con_deinit for all our
  1217. * consoles is executed by take_over_console().
  1218. */
  1219. sisusb->haveconsole = 0;
  1220. }
  1221. vfree((void *)sisusb->scrbuf);
  1222. sisusb->scrbuf = 0;
  1223. vfree(sisusb->font_backup);
  1224. sisusb->font_backup = NULL;
  1225. }
  1226. void __init sisusb_init_concode(void)
  1227. {
  1228. int i;
  1229. for (i = 0; i < MAX_NR_CONSOLES; i++)
  1230. mysisusbs[i] = NULL;
  1231. }
  1232. #endif /* INCL_CON */