sisusb_con.c 35 KB

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