sisusb_con.c 36 KB

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