sisusb_con.c 35 KB

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