sisusb_con.c 36 KB

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