hvsi.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314
  1. /*
  2. * Copyright (C) 2004 Hollis Blanchard <hollisb@us.ibm.com>, IBM
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. */
  18. /* Host Virtual Serial Interface (HVSI) is a protocol between the hosted OS
  19. * and the service processor on IBM pSeries servers. On these servers, there
  20. * are no serial ports under the OS's control, and sometimes there is no other
  21. * console available either. However, the service processor has two standard
  22. * serial ports, so this over-complicated protocol allows the OS to control
  23. * those ports by proxy.
  24. *
  25. * Besides data, the procotol supports the reading/writing of the serial
  26. * port's DTR line, and the reading of the CD line. This is to allow the OS to
  27. * control a modem attached to the service processor's serial port. Note that
  28. * the OS cannot change the speed of the port through this protocol.
  29. */
  30. #undef DEBUG
  31. #include <linux/console.h>
  32. #include <linux/ctype.h>
  33. #include <linux/delay.h>
  34. #include <linux/init.h>
  35. #include <linux/interrupt.h>
  36. #include <linux/module.h>
  37. #include <linux/major.h>
  38. #include <linux/kernel.h>
  39. #include <linux/spinlock.h>
  40. #include <linux/sysrq.h>
  41. #include <linux/tty.h>
  42. #include <linux/tty_flip.h>
  43. #include <asm/hvcall.h>
  44. #include <asm/hvconsole.h>
  45. #include <asm/prom.h>
  46. #include <asm/uaccess.h>
  47. #include <asm/vio.h>
  48. #include <asm/param.h>
  49. #define HVSI_MAJOR 229
  50. #define HVSI_MINOR 128
  51. #define MAX_NR_HVSI_CONSOLES 4
  52. #define HVSI_TIMEOUT (5*HZ)
  53. #define HVSI_VERSION 1
  54. #define HVSI_MAX_PACKET 256
  55. #define HVSI_MAX_READ 16
  56. #define HVSI_MAX_OUTGOING_DATA 12
  57. #define N_OUTBUF 12
  58. /*
  59. * we pass data via two 8-byte registers, so we would like our char arrays
  60. * properly aligned for those loads.
  61. */
  62. #define __ALIGNED__ __attribute__((__aligned__(sizeof(long))))
  63. struct hvsi_struct {
  64. struct delayed_work writer;
  65. struct work_struct handshaker;
  66. wait_queue_head_t emptyq; /* woken when outbuf is emptied */
  67. wait_queue_head_t stateq; /* woken when HVSI state changes */
  68. spinlock_t lock;
  69. int index;
  70. struct tty_struct *tty;
  71. int count;
  72. uint8_t throttle_buf[128];
  73. uint8_t outbuf[N_OUTBUF]; /* to implement write_room and chars_in_buffer */
  74. /* inbuf is for packet reassembly. leave a little room for leftovers. */
  75. uint8_t inbuf[HVSI_MAX_PACKET + HVSI_MAX_READ];
  76. uint8_t *inbuf_end;
  77. int n_throttle;
  78. int n_outbuf;
  79. uint32_t vtermno;
  80. uint32_t virq;
  81. atomic_t seqno; /* HVSI packet sequence number */
  82. uint16_t mctrl;
  83. uint8_t state; /* HVSI protocol state */
  84. uint8_t flags;
  85. #ifdef CONFIG_MAGIC_SYSRQ
  86. uint8_t sysrq;
  87. #endif /* CONFIG_MAGIC_SYSRQ */
  88. };
  89. static struct hvsi_struct hvsi_ports[MAX_NR_HVSI_CONSOLES];
  90. static struct tty_driver *hvsi_driver;
  91. static int hvsi_count;
  92. static int (*hvsi_wait)(struct hvsi_struct *hp, int state);
  93. enum HVSI_PROTOCOL_STATE {
  94. HVSI_CLOSED,
  95. HVSI_WAIT_FOR_VER_RESPONSE,
  96. HVSI_WAIT_FOR_VER_QUERY,
  97. HVSI_OPEN,
  98. HVSI_WAIT_FOR_MCTRL_RESPONSE,
  99. HVSI_FSP_DIED,
  100. };
  101. #define HVSI_CONSOLE 0x1
  102. #define VS_DATA_PACKET_HEADER 0xff
  103. #define VS_CONTROL_PACKET_HEADER 0xfe
  104. #define VS_QUERY_PACKET_HEADER 0xfd
  105. #define VS_QUERY_RESPONSE_PACKET_HEADER 0xfc
  106. /* control verbs */
  107. #define VSV_SET_MODEM_CTL 1 /* to service processor only */
  108. #define VSV_MODEM_CTL_UPDATE 2 /* from service processor only */
  109. #define VSV_CLOSE_PROTOCOL 3
  110. /* query verbs */
  111. #define VSV_SEND_VERSION_NUMBER 1
  112. #define VSV_SEND_MODEM_CTL_STATUS 2
  113. /* yes, these masks are not consecutive. */
  114. #define HVSI_TSDTR 0x01
  115. #define HVSI_TSCD 0x20
  116. struct hvsi_header {
  117. uint8_t type;
  118. uint8_t len;
  119. uint16_t seqno;
  120. } __attribute__((packed));
  121. struct hvsi_data {
  122. uint8_t type;
  123. uint8_t len;
  124. uint16_t seqno;
  125. uint8_t data[HVSI_MAX_OUTGOING_DATA];
  126. } __attribute__((packed));
  127. struct hvsi_control {
  128. uint8_t type;
  129. uint8_t len;
  130. uint16_t seqno;
  131. uint16_t verb;
  132. /* optional depending on verb: */
  133. uint32_t word;
  134. uint32_t mask;
  135. } __attribute__((packed));
  136. struct hvsi_query {
  137. uint8_t type;
  138. uint8_t len;
  139. uint16_t seqno;
  140. uint16_t verb;
  141. } __attribute__((packed));
  142. struct hvsi_query_response {
  143. uint8_t type;
  144. uint8_t len;
  145. uint16_t seqno;
  146. uint16_t verb;
  147. uint16_t query_seqno;
  148. union {
  149. uint8_t version;
  150. uint32_t mctrl_word;
  151. } u;
  152. } __attribute__((packed));
  153. static inline int is_console(struct hvsi_struct *hp)
  154. {
  155. return hp->flags & HVSI_CONSOLE;
  156. }
  157. static inline int is_open(struct hvsi_struct *hp)
  158. {
  159. /* if we're waiting for an mctrl then we're already open */
  160. return (hp->state == HVSI_OPEN)
  161. || (hp->state == HVSI_WAIT_FOR_MCTRL_RESPONSE);
  162. }
  163. static inline void print_state(struct hvsi_struct *hp)
  164. {
  165. #ifdef DEBUG
  166. static const char *state_names[] = {
  167. "HVSI_CLOSED",
  168. "HVSI_WAIT_FOR_VER_RESPONSE",
  169. "HVSI_WAIT_FOR_VER_QUERY",
  170. "HVSI_OPEN",
  171. "HVSI_WAIT_FOR_MCTRL_RESPONSE",
  172. "HVSI_FSP_DIED",
  173. };
  174. const char *name = (hp->state < ARRAY_SIZE(state_names))
  175. ? state_names[hp->state] : "UNKNOWN";
  176. pr_debug("hvsi%i: state = %s\n", hp->index, name);
  177. #endif /* DEBUG */
  178. }
  179. static inline void __set_state(struct hvsi_struct *hp, int state)
  180. {
  181. hp->state = state;
  182. print_state(hp);
  183. wake_up_all(&hp->stateq);
  184. }
  185. static inline void set_state(struct hvsi_struct *hp, int state)
  186. {
  187. unsigned long flags;
  188. spin_lock_irqsave(&hp->lock, flags);
  189. __set_state(hp, state);
  190. spin_unlock_irqrestore(&hp->lock, flags);
  191. }
  192. static inline int len_packet(const uint8_t *packet)
  193. {
  194. return (int)((struct hvsi_header *)packet)->len;
  195. }
  196. static inline int is_header(const uint8_t *packet)
  197. {
  198. struct hvsi_header *header = (struct hvsi_header *)packet;
  199. return header->type >= VS_QUERY_RESPONSE_PACKET_HEADER;
  200. }
  201. static inline int got_packet(const struct hvsi_struct *hp, uint8_t *packet)
  202. {
  203. if (hp->inbuf_end < packet + sizeof(struct hvsi_header))
  204. return 0; /* don't even have the packet header */
  205. if (hp->inbuf_end < (packet + len_packet(packet)))
  206. return 0; /* don't have the rest of the packet */
  207. return 1;
  208. }
  209. /* shift remaining bytes in packetbuf down */
  210. static void compact_inbuf(struct hvsi_struct *hp, uint8_t *read_to)
  211. {
  212. int remaining = (int)(hp->inbuf_end - read_to);
  213. pr_debug("%s: %i chars remain\n", __func__, remaining);
  214. if (read_to != hp->inbuf)
  215. memmove(hp->inbuf, read_to, remaining);
  216. hp->inbuf_end = hp->inbuf + remaining;
  217. }
  218. #ifdef DEBUG
  219. #define dbg_dump_packet(packet) dump_packet(packet)
  220. #define dbg_dump_hex(data, len) dump_hex(data, len)
  221. #else
  222. #define dbg_dump_packet(packet) do { } while (0)
  223. #define dbg_dump_hex(data, len) do { } while (0)
  224. #endif
  225. static void dump_hex(const uint8_t *data, int len)
  226. {
  227. int i;
  228. printk(" ");
  229. for (i=0; i < len; i++)
  230. printk("%.2x", data[i]);
  231. printk("\n ");
  232. for (i=0; i < len; i++) {
  233. if (isprint(data[i]))
  234. printk("%c", data[i]);
  235. else
  236. printk(".");
  237. }
  238. printk("\n");
  239. }
  240. static void dump_packet(uint8_t *packet)
  241. {
  242. struct hvsi_header *header = (struct hvsi_header *)packet;
  243. printk("type 0x%x, len %i, seqno %i:\n", header->type, header->len,
  244. header->seqno);
  245. dump_hex(packet, header->len);
  246. }
  247. static int hvsi_read(struct hvsi_struct *hp, char *buf, int count)
  248. {
  249. unsigned long got;
  250. got = hvc_get_chars(hp->vtermno, buf, count);
  251. return got;
  252. }
  253. static void hvsi_recv_control(struct hvsi_struct *hp, uint8_t *packet,
  254. struct tty_struct **to_hangup, struct hvsi_struct **to_handshake)
  255. {
  256. struct hvsi_control *header = (struct hvsi_control *)packet;
  257. switch (header->verb) {
  258. case VSV_MODEM_CTL_UPDATE:
  259. if ((header->word & HVSI_TSCD) == 0) {
  260. /* CD went away; no more connection */
  261. pr_debug("hvsi%i: CD dropped\n", hp->index);
  262. hp->mctrl &= TIOCM_CD;
  263. /* If userland hasn't done an open(2) yet, hp->tty is NULL. */
  264. if (hp->tty && !(hp->tty->flags & CLOCAL))
  265. *to_hangup = hp->tty;
  266. }
  267. break;
  268. case VSV_CLOSE_PROTOCOL:
  269. pr_debug("hvsi%i: service processor came back\n", hp->index);
  270. if (hp->state != HVSI_CLOSED) {
  271. *to_handshake = hp;
  272. }
  273. break;
  274. default:
  275. printk(KERN_WARNING "hvsi%i: unknown HVSI control packet: ",
  276. hp->index);
  277. dump_packet(packet);
  278. break;
  279. }
  280. }
  281. static void hvsi_recv_response(struct hvsi_struct *hp, uint8_t *packet)
  282. {
  283. struct hvsi_query_response *resp = (struct hvsi_query_response *)packet;
  284. switch (hp->state) {
  285. case HVSI_WAIT_FOR_VER_RESPONSE:
  286. __set_state(hp, HVSI_WAIT_FOR_VER_QUERY);
  287. break;
  288. case HVSI_WAIT_FOR_MCTRL_RESPONSE:
  289. hp->mctrl = 0;
  290. if (resp->u.mctrl_word & HVSI_TSDTR)
  291. hp->mctrl |= TIOCM_DTR;
  292. if (resp->u.mctrl_word & HVSI_TSCD)
  293. hp->mctrl |= TIOCM_CD;
  294. __set_state(hp, HVSI_OPEN);
  295. break;
  296. default:
  297. printk(KERN_ERR "hvsi%i: unexpected query response: ", hp->index);
  298. dump_packet(packet);
  299. break;
  300. }
  301. }
  302. /* respond to service processor's version query */
  303. static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
  304. {
  305. struct hvsi_query_response packet __ALIGNED__;
  306. int wrote;
  307. packet.type = VS_QUERY_RESPONSE_PACKET_HEADER;
  308. packet.len = sizeof(struct hvsi_query_response);
  309. packet.seqno = atomic_inc_return(&hp->seqno);
  310. packet.verb = VSV_SEND_VERSION_NUMBER;
  311. packet.u.version = HVSI_VERSION;
  312. packet.query_seqno = query_seqno+1;
  313. pr_debug("%s: sending %i bytes\n", __func__, packet.len);
  314. dbg_dump_hex((uint8_t*)&packet, packet.len);
  315. wrote = hvc_put_chars(hp->vtermno, (char *)&packet, packet.len);
  316. if (wrote != packet.len) {
  317. printk(KERN_ERR "hvsi%i: couldn't send query response!\n",
  318. hp->index);
  319. return -EIO;
  320. }
  321. return 0;
  322. }
  323. static void hvsi_recv_query(struct hvsi_struct *hp, uint8_t *packet)
  324. {
  325. struct hvsi_query *query = (struct hvsi_query *)packet;
  326. switch (hp->state) {
  327. case HVSI_WAIT_FOR_VER_QUERY:
  328. hvsi_version_respond(hp, query->seqno);
  329. __set_state(hp, HVSI_OPEN);
  330. break;
  331. default:
  332. printk(KERN_ERR "hvsi%i: unexpected query: ", hp->index);
  333. dump_packet(packet);
  334. break;
  335. }
  336. }
  337. static void hvsi_insert_chars(struct hvsi_struct *hp, const char *buf, int len)
  338. {
  339. int i;
  340. for (i=0; i < len; i++) {
  341. char c = buf[i];
  342. #ifdef CONFIG_MAGIC_SYSRQ
  343. if (c == '\0') {
  344. hp->sysrq = 1;
  345. continue;
  346. } else if (hp->sysrq) {
  347. handle_sysrq(c);
  348. hp->sysrq = 0;
  349. continue;
  350. }
  351. #endif /* CONFIG_MAGIC_SYSRQ */
  352. tty_insert_flip_char(hp->tty, c, 0);
  353. }
  354. }
  355. /*
  356. * We could get 252 bytes of data at once here. But the tty layer only
  357. * throttles us at TTY_THRESHOLD_THROTTLE (128) bytes, so we could overflow
  358. * it. Accordingly we won't send more than 128 bytes at a time to the flip
  359. * buffer, which will give the tty buffer a chance to throttle us. Should the
  360. * value of TTY_THRESHOLD_THROTTLE change in n_tty.c, this code should be
  361. * revisited.
  362. */
  363. #define TTY_THRESHOLD_THROTTLE 128
  364. static struct tty_struct *hvsi_recv_data(struct hvsi_struct *hp,
  365. const uint8_t *packet)
  366. {
  367. const struct hvsi_header *header = (const struct hvsi_header *)packet;
  368. const uint8_t *data = packet + sizeof(struct hvsi_header);
  369. int datalen = header->len - sizeof(struct hvsi_header);
  370. int overflow = datalen - TTY_THRESHOLD_THROTTLE;
  371. pr_debug("queueing %i chars '%.*s'\n", datalen, datalen, data);
  372. if (datalen == 0)
  373. return NULL;
  374. if (overflow > 0) {
  375. pr_debug("%s: got >TTY_THRESHOLD_THROTTLE bytes\n", __func__);
  376. datalen = TTY_THRESHOLD_THROTTLE;
  377. }
  378. hvsi_insert_chars(hp, data, datalen);
  379. if (overflow > 0) {
  380. /*
  381. * we still have more data to deliver, so we need to save off the
  382. * overflow and send it later
  383. */
  384. pr_debug("%s: deferring overflow\n", __func__);
  385. memcpy(hp->throttle_buf, data + TTY_THRESHOLD_THROTTLE, overflow);
  386. hp->n_throttle = overflow;
  387. }
  388. return hp->tty;
  389. }
  390. /*
  391. * Returns true/false indicating data successfully read from hypervisor.
  392. * Used both to get packets for tty connections and to advance the state
  393. * machine during console handshaking (in which case tty = NULL and we ignore
  394. * incoming data).
  395. */
  396. static int hvsi_load_chunk(struct hvsi_struct *hp, struct tty_struct **flip,
  397. struct tty_struct **hangup, struct hvsi_struct **handshake)
  398. {
  399. uint8_t *packet = hp->inbuf;
  400. int chunklen;
  401. *flip = NULL;
  402. *hangup = NULL;
  403. *handshake = NULL;
  404. chunklen = hvsi_read(hp, hp->inbuf_end, HVSI_MAX_READ);
  405. if (chunklen == 0) {
  406. pr_debug("%s: 0-length read\n", __func__);
  407. return 0;
  408. }
  409. pr_debug("%s: got %i bytes\n", __func__, chunklen);
  410. dbg_dump_hex(hp->inbuf_end, chunklen);
  411. hp->inbuf_end += chunklen;
  412. /* handle all completed packets */
  413. while ((packet < hp->inbuf_end) && got_packet(hp, packet)) {
  414. struct hvsi_header *header = (struct hvsi_header *)packet;
  415. if (!is_header(packet)) {
  416. printk(KERN_ERR "hvsi%i: got malformed packet\n", hp->index);
  417. /* skip bytes until we find a header or run out of data */
  418. while ((packet < hp->inbuf_end) && (!is_header(packet)))
  419. packet++;
  420. continue;
  421. }
  422. pr_debug("%s: handling %i-byte packet\n", __func__,
  423. len_packet(packet));
  424. dbg_dump_packet(packet);
  425. switch (header->type) {
  426. case VS_DATA_PACKET_HEADER:
  427. if (!is_open(hp))
  428. break;
  429. if (hp->tty == NULL)
  430. break; /* no tty buffer to put data in */
  431. *flip = hvsi_recv_data(hp, packet);
  432. break;
  433. case VS_CONTROL_PACKET_HEADER:
  434. hvsi_recv_control(hp, packet, hangup, handshake);
  435. break;
  436. case VS_QUERY_RESPONSE_PACKET_HEADER:
  437. hvsi_recv_response(hp, packet);
  438. break;
  439. case VS_QUERY_PACKET_HEADER:
  440. hvsi_recv_query(hp, packet);
  441. break;
  442. default:
  443. printk(KERN_ERR "hvsi%i: unknown HVSI packet type 0x%x\n",
  444. hp->index, header->type);
  445. dump_packet(packet);
  446. break;
  447. }
  448. packet += len_packet(packet);
  449. if (*hangup || *handshake) {
  450. pr_debug("%s: hangup or handshake\n", __func__);
  451. /*
  452. * we need to send the hangup now before receiving any more data.
  453. * If we get "data, hangup, data", we can't deliver the second
  454. * data before the hangup.
  455. */
  456. break;
  457. }
  458. }
  459. compact_inbuf(hp, packet);
  460. return 1;
  461. }
  462. static void hvsi_send_overflow(struct hvsi_struct *hp)
  463. {
  464. pr_debug("%s: delivering %i bytes overflow\n", __func__,
  465. hp->n_throttle);
  466. hvsi_insert_chars(hp, hp->throttle_buf, hp->n_throttle);
  467. hp->n_throttle = 0;
  468. }
  469. /*
  470. * must get all pending data because we only get an irq on empty->non-empty
  471. * transition
  472. */
  473. static irqreturn_t hvsi_interrupt(int irq, void *arg)
  474. {
  475. struct hvsi_struct *hp = (struct hvsi_struct *)arg;
  476. struct tty_struct *flip;
  477. struct tty_struct *hangup;
  478. struct hvsi_struct *handshake;
  479. unsigned long flags;
  480. int again = 1;
  481. pr_debug("%s\n", __func__);
  482. while (again) {
  483. spin_lock_irqsave(&hp->lock, flags);
  484. again = hvsi_load_chunk(hp, &flip, &hangup, &handshake);
  485. spin_unlock_irqrestore(&hp->lock, flags);
  486. /*
  487. * we have to call tty_flip_buffer_push() and tty_hangup() outside our
  488. * spinlock. But we also have to keep going until we've read all the
  489. * available data.
  490. */
  491. if (flip) {
  492. /* there was data put in the tty flip buffer */
  493. tty_flip_buffer_push(flip);
  494. flip = NULL;
  495. }
  496. if (hangup) {
  497. tty_hangup(hangup);
  498. }
  499. if (handshake) {
  500. pr_debug("hvsi%i: attempting re-handshake\n", handshake->index);
  501. schedule_work(&handshake->handshaker);
  502. }
  503. }
  504. spin_lock_irqsave(&hp->lock, flags);
  505. if (hp->tty && hp->n_throttle
  506. && (!test_bit(TTY_THROTTLED, &hp->tty->flags))) {
  507. /* we weren't hung up and we weren't throttled, so we can deliver the
  508. * rest now */
  509. flip = hp->tty;
  510. hvsi_send_overflow(hp);
  511. }
  512. spin_unlock_irqrestore(&hp->lock, flags);
  513. if (flip) {
  514. tty_flip_buffer_push(flip);
  515. }
  516. return IRQ_HANDLED;
  517. }
  518. /* for boot console, before the irq handler is running */
  519. static int __init poll_for_state(struct hvsi_struct *hp, int state)
  520. {
  521. unsigned long end_jiffies = jiffies + HVSI_TIMEOUT;
  522. for (;;) {
  523. hvsi_interrupt(hp->virq, (void *)hp); /* get pending data */
  524. if (hp->state == state)
  525. return 0;
  526. mdelay(5);
  527. if (time_after(jiffies, end_jiffies))
  528. return -EIO;
  529. }
  530. }
  531. /* wait for irq handler to change our state */
  532. static int wait_for_state(struct hvsi_struct *hp, int state)
  533. {
  534. int ret = 0;
  535. if (!wait_event_timeout(hp->stateq, (hp->state == state), HVSI_TIMEOUT))
  536. ret = -EIO;
  537. return ret;
  538. }
  539. static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
  540. {
  541. struct hvsi_query packet __ALIGNED__;
  542. int wrote;
  543. packet.type = VS_QUERY_PACKET_HEADER;
  544. packet.len = sizeof(struct hvsi_query);
  545. packet.seqno = atomic_inc_return(&hp->seqno);
  546. packet.verb = verb;
  547. pr_debug("%s: sending %i bytes\n", __func__, packet.len);
  548. dbg_dump_hex((uint8_t*)&packet, packet.len);
  549. wrote = hvc_put_chars(hp->vtermno, (char *)&packet, packet.len);
  550. if (wrote != packet.len) {
  551. printk(KERN_ERR "hvsi%i: couldn't send query (%i)!\n", hp->index,
  552. wrote);
  553. return -EIO;
  554. }
  555. return 0;
  556. }
  557. static int hvsi_get_mctrl(struct hvsi_struct *hp)
  558. {
  559. int ret;
  560. set_state(hp, HVSI_WAIT_FOR_MCTRL_RESPONSE);
  561. hvsi_query(hp, VSV_SEND_MODEM_CTL_STATUS);
  562. ret = hvsi_wait(hp, HVSI_OPEN);
  563. if (ret < 0) {
  564. printk(KERN_ERR "hvsi%i: didn't get modem flags\n", hp->index);
  565. set_state(hp, HVSI_OPEN);
  566. return ret;
  567. }
  568. pr_debug("%s: mctrl 0x%x\n", __func__, hp->mctrl);
  569. return 0;
  570. }
  571. /* note that we can only set DTR */
  572. static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
  573. {
  574. struct hvsi_control packet __ALIGNED__;
  575. int wrote;
  576. packet.type = VS_CONTROL_PACKET_HEADER,
  577. packet.seqno = atomic_inc_return(&hp->seqno);
  578. packet.len = sizeof(struct hvsi_control);
  579. packet.verb = VSV_SET_MODEM_CTL;
  580. packet.mask = HVSI_TSDTR;
  581. if (mctrl & TIOCM_DTR)
  582. packet.word = HVSI_TSDTR;
  583. pr_debug("%s: sending %i bytes\n", __func__, packet.len);
  584. dbg_dump_hex((uint8_t*)&packet, packet.len);
  585. wrote = hvc_put_chars(hp->vtermno, (char *)&packet, packet.len);
  586. if (wrote != packet.len) {
  587. printk(KERN_ERR "hvsi%i: couldn't set DTR!\n", hp->index);
  588. return -EIO;
  589. }
  590. return 0;
  591. }
  592. static void hvsi_drain_input(struct hvsi_struct *hp)
  593. {
  594. uint8_t buf[HVSI_MAX_READ] __ALIGNED__;
  595. unsigned long end_jiffies = jiffies + HVSI_TIMEOUT;
  596. while (time_before(end_jiffies, jiffies))
  597. if (0 == hvsi_read(hp, buf, HVSI_MAX_READ))
  598. break;
  599. }
  600. static int hvsi_handshake(struct hvsi_struct *hp)
  601. {
  602. int ret;
  603. /*
  604. * We could have a CLOSE or other data waiting for us before we even try
  605. * to open; try to throw it all away so we don't get confused. (CLOSE
  606. * is the first message sent up the pipe when the FSP comes online. We
  607. * need to distinguish between "it came up a while ago and we're the first
  608. * user" and "it was just reset before it saw our handshake packet".)
  609. */
  610. hvsi_drain_input(hp);
  611. set_state(hp, HVSI_WAIT_FOR_VER_RESPONSE);
  612. ret = hvsi_query(hp, VSV_SEND_VERSION_NUMBER);
  613. if (ret < 0) {
  614. printk(KERN_ERR "hvsi%i: couldn't send version query\n", hp->index);
  615. return ret;
  616. }
  617. ret = hvsi_wait(hp, HVSI_OPEN);
  618. if (ret < 0)
  619. return ret;
  620. return 0;
  621. }
  622. static void hvsi_handshaker(struct work_struct *work)
  623. {
  624. struct hvsi_struct *hp =
  625. container_of(work, struct hvsi_struct, handshaker);
  626. if (hvsi_handshake(hp) >= 0)
  627. return;
  628. printk(KERN_ERR "hvsi%i: re-handshaking failed\n", hp->index);
  629. if (is_console(hp)) {
  630. /*
  631. * ttys will re-attempt the handshake via hvsi_open, but
  632. * the console will not.
  633. */
  634. printk(KERN_ERR "hvsi%i: lost console!\n", hp->index);
  635. }
  636. }
  637. static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
  638. {
  639. struct hvsi_data packet __ALIGNED__;
  640. int ret;
  641. BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
  642. packet.type = VS_DATA_PACKET_HEADER;
  643. packet.seqno = atomic_inc_return(&hp->seqno);
  644. packet.len = count + sizeof(struct hvsi_header);
  645. memcpy(&packet.data, buf, count);
  646. ret = hvc_put_chars(hp->vtermno, (char *)&packet, packet.len);
  647. if (ret == packet.len) {
  648. /* return the number of chars written, not the packet length */
  649. return count;
  650. }
  651. return ret; /* return any errors */
  652. }
  653. static void hvsi_close_protocol(struct hvsi_struct *hp)
  654. {
  655. struct hvsi_control packet __ALIGNED__;
  656. packet.type = VS_CONTROL_PACKET_HEADER;
  657. packet.seqno = atomic_inc_return(&hp->seqno);
  658. packet.len = 6;
  659. packet.verb = VSV_CLOSE_PROTOCOL;
  660. pr_debug("%s: sending %i bytes\n", __func__, packet.len);
  661. dbg_dump_hex((uint8_t*)&packet, packet.len);
  662. hvc_put_chars(hp->vtermno, (char *)&packet, packet.len);
  663. }
  664. static int hvsi_open(struct tty_struct *tty, struct file *filp)
  665. {
  666. struct hvsi_struct *hp;
  667. unsigned long flags;
  668. int line = tty->index;
  669. int ret;
  670. pr_debug("%s\n", __func__);
  671. if (line < 0 || line >= hvsi_count)
  672. return -ENODEV;
  673. hp = &hvsi_ports[line];
  674. tty->driver_data = hp;
  675. mb();
  676. if (hp->state == HVSI_FSP_DIED)
  677. return -EIO;
  678. spin_lock_irqsave(&hp->lock, flags);
  679. hp->tty = tty;
  680. hp->count++;
  681. atomic_set(&hp->seqno, 0);
  682. h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
  683. spin_unlock_irqrestore(&hp->lock, flags);
  684. if (is_console(hp))
  685. return 0; /* this has already been handshaked as the console */
  686. ret = hvsi_handshake(hp);
  687. if (ret < 0) {
  688. printk(KERN_ERR "%s: HVSI handshaking failed\n", tty->name);
  689. return ret;
  690. }
  691. ret = hvsi_get_mctrl(hp);
  692. if (ret < 0) {
  693. printk(KERN_ERR "%s: couldn't get initial modem flags\n", tty->name);
  694. return ret;
  695. }
  696. ret = hvsi_set_mctrl(hp, hp->mctrl | TIOCM_DTR);
  697. if (ret < 0) {
  698. printk(KERN_ERR "%s: couldn't set DTR\n", tty->name);
  699. return ret;
  700. }
  701. return 0;
  702. }
  703. /* wait for hvsi_write_worker to empty hp->outbuf */
  704. static void hvsi_flush_output(struct hvsi_struct *hp)
  705. {
  706. wait_event_timeout(hp->emptyq, (hp->n_outbuf <= 0), HVSI_TIMEOUT);
  707. /* 'writer' could still be pending if it didn't see n_outbuf = 0 yet */
  708. cancel_delayed_work_sync(&hp->writer);
  709. flush_work_sync(&hp->handshaker);
  710. /*
  711. * it's also possible that our timeout expired and hvsi_write_worker
  712. * didn't manage to push outbuf. poof.
  713. */
  714. hp->n_outbuf = 0;
  715. }
  716. static void hvsi_close(struct tty_struct *tty, struct file *filp)
  717. {
  718. struct hvsi_struct *hp = tty->driver_data;
  719. unsigned long flags;
  720. pr_debug("%s\n", __func__);
  721. if (tty_hung_up_p(filp))
  722. return;
  723. spin_lock_irqsave(&hp->lock, flags);
  724. if (--hp->count == 0) {
  725. hp->tty = NULL;
  726. hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
  727. /* only close down connection if it is not the console */
  728. if (!is_console(hp)) {
  729. h_vio_signal(hp->vtermno, VIO_IRQ_DISABLE); /* no more irqs */
  730. __set_state(hp, HVSI_CLOSED);
  731. /*
  732. * any data delivered to the tty layer after this will be
  733. * discarded (except for XON/XOFF)
  734. */
  735. tty->closing = 1;
  736. spin_unlock_irqrestore(&hp->lock, flags);
  737. /* let any existing irq handlers finish. no more will start. */
  738. synchronize_irq(hp->virq);
  739. /* hvsi_write_worker will re-schedule until outbuf is empty. */
  740. hvsi_flush_output(hp);
  741. /* tell FSP to stop sending data */
  742. hvsi_close_protocol(hp);
  743. /*
  744. * drain anything FSP is still in the middle of sending, and let
  745. * hvsi_handshake drain the rest on the next open.
  746. */
  747. hvsi_drain_input(hp);
  748. spin_lock_irqsave(&hp->lock, flags);
  749. }
  750. } else if (hp->count < 0)
  751. printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
  752. hp - hvsi_ports, hp->count);
  753. spin_unlock_irqrestore(&hp->lock, flags);
  754. }
  755. static void hvsi_hangup(struct tty_struct *tty)
  756. {
  757. struct hvsi_struct *hp = tty->driver_data;
  758. unsigned long flags;
  759. pr_debug("%s\n", __func__);
  760. spin_lock_irqsave(&hp->lock, flags);
  761. hp->count = 0;
  762. hp->n_outbuf = 0;
  763. hp->tty = NULL;
  764. spin_unlock_irqrestore(&hp->lock, flags);
  765. }
  766. /* called with hp->lock held */
  767. static void hvsi_push(struct hvsi_struct *hp)
  768. {
  769. int n;
  770. if (hp->n_outbuf <= 0)
  771. return;
  772. n = hvsi_put_chars(hp, hp->outbuf, hp->n_outbuf);
  773. if (n > 0) {
  774. /* success */
  775. pr_debug("%s: wrote %i chars\n", __func__, n);
  776. hp->n_outbuf = 0;
  777. } else if (n == -EIO) {
  778. __set_state(hp, HVSI_FSP_DIED);
  779. printk(KERN_ERR "hvsi%i: service processor died\n", hp->index);
  780. }
  781. }
  782. /* hvsi_write_worker will keep rescheduling itself until outbuf is empty */
  783. static void hvsi_write_worker(struct work_struct *work)
  784. {
  785. struct hvsi_struct *hp =
  786. container_of(work, struct hvsi_struct, writer.work);
  787. unsigned long flags;
  788. #ifdef DEBUG
  789. static long start_j = 0;
  790. if (start_j == 0)
  791. start_j = jiffies;
  792. #endif /* DEBUG */
  793. spin_lock_irqsave(&hp->lock, flags);
  794. pr_debug("%s: %i chars in buffer\n", __func__, hp->n_outbuf);
  795. if (!is_open(hp)) {
  796. /*
  797. * We could have a non-open connection if the service processor died
  798. * while we were busily scheduling ourselves. In that case, it could
  799. * be minutes before the service processor comes back, so only try
  800. * again once a second.
  801. */
  802. schedule_delayed_work(&hp->writer, HZ);
  803. goto out;
  804. }
  805. hvsi_push(hp);
  806. if (hp->n_outbuf > 0)
  807. schedule_delayed_work(&hp->writer, 10);
  808. else {
  809. #ifdef DEBUG
  810. pr_debug("%s: outbuf emptied after %li jiffies\n", __func__,
  811. jiffies - start_j);
  812. start_j = 0;
  813. #endif /* DEBUG */
  814. wake_up_all(&hp->emptyq);
  815. tty_wakeup(hp->tty);
  816. }
  817. out:
  818. spin_unlock_irqrestore(&hp->lock, flags);
  819. }
  820. static int hvsi_write_room(struct tty_struct *tty)
  821. {
  822. struct hvsi_struct *hp = tty->driver_data;
  823. return N_OUTBUF - hp->n_outbuf;
  824. }
  825. static int hvsi_chars_in_buffer(struct tty_struct *tty)
  826. {
  827. struct hvsi_struct *hp = tty->driver_data;
  828. return hp->n_outbuf;
  829. }
  830. static int hvsi_write(struct tty_struct *tty,
  831. const unsigned char *buf, int count)
  832. {
  833. struct hvsi_struct *hp = tty->driver_data;
  834. const char *source = buf;
  835. unsigned long flags;
  836. int total = 0;
  837. int origcount = count;
  838. spin_lock_irqsave(&hp->lock, flags);
  839. pr_debug("%s: %i chars in buffer\n", __func__, hp->n_outbuf);
  840. if (!is_open(hp)) {
  841. /* we're either closing or not yet open; don't accept data */
  842. pr_debug("%s: not open\n", __func__);
  843. goto out;
  844. }
  845. /*
  846. * when the hypervisor buffer (16K) fills, data will stay in hp->outbuf
  847. * and hvsi_write_worker will be scheduled. subsequent hvsi_write() calls
  848. * will see there is no room in outbuf and return.
  849. */
  850. while ((count > 0) && (hvsi_write_room(hp->tty) > 0)) {
  851. int chunksize = min(count, hvsi_write_room(hp->tty));
  852. BUG_ON(hp->n_outbuf < 0);
  853. memcpy(hp->outbuf + hp->n_outbuf, source, chunksize);
  854. hp->n_outbuf += chunksize;
  855. total += chunksize;
  856. source += chunksize;
  857. count -= chunksize;
  858. hvsi_push(hp);
  859. }
  860. if (hp->n_outbuf > 0) {
  861. /*
  862. * we weren't able to write it all to the hypervisor.
  863. * schedule another push attempt.
  864. */
  865. schedule_delayed_work(&hp->writer, 10);
  866. }
  867. out:
  868. spin_unlock_irqrestore(&hp->lock, flags);
  869. if (total != origcount)
  870. pr_debug("%s: wanted %i, only wrote %i\n", __func__, origcount,
  871. total);
  872. return total;
  873. }
  874. /*
  875. * I have never seen throttle or unthrottle called, so this little throttle
  876. * buffering scheme may or may not work.
  877. */
  878. static void hvsi_throttle(struct tty_struct *tty)
  879. {
  880. struct hvsi_struct *hp = tty->driver_data;
  881. pr_debug("%s\n", __func__);
  882. h_vio_signal(hp->vtermno, VIO_IRQ_DISABLE);
  883. }
  884. static void hvsi_unthrottle(struct tty_struct *tty)
  885. {
  886. struct hvsi_struct *hp = tty->driver_data;
  887. unsigned long flags;
  888. int shouldflip = 0;
  889. pr_debug("%s\n", __func__);
  890. spin_lock_irqsave(&hp->lock, flags);
  891. if (hp->n_throttle) {
  892. hvsi_send_overflow(hp);
  893. shouldflip = 1;
  894. }
  895. spin_unlock_irqrestore(&hp->lock, flags);
  896. if (shouldflip)
  897. tty_flip_buffer_push(hp->tty);
  898. h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
  899. }
  900. static int hvsi_tiocmget(struct tty_struct *tty, struct file *file)
  901. {
  902. struct hvsi_struct *hp = tty->driver_data;
  903. hvsi_get_mctrl(hp);
  904. return hp->mctrl;
  905. }
  906. static int hvsi_tiocmset(struct tty_struct *tty, struct file *file,
  907. unsigned int set, unsigned int clear)
  908. {
  909. struct hvsi_struct *hp = tty->driver_data;
  910. unsigned long flags;
  911. uint16_t new_mctrl;
  912. /* we can only alter DTR */
  913. clear &= TIOCM_DTR;
  914. set &= TIOCM_DTR;
  915. spin_lock_irqsave(&hp->lock, flags);
  916. new_mctrl = (hp->mctrl & ~clear) | set;
  917. if (hp->mctrl != new_mctrl) {
  918. hvsi_set_mctrl(hp, new_mctrl);
  919. hp->mctrl = new_mctrl;
  920. }
  921. spin_unlock_irqrestore(&hp->lock, flags);
  922. return 0;
  923. }
  924. static const struct tty_operations hvsi_ops = {
  925. .open = hvsi_open,
  926. .close = hvsi_close,
  927. .write = hvsi_write,
  928. .hangup = hvsi_hangup,
  929. .write_room = hvsi_write_room,
  930. .chars_in_buffer = hvsi_chars_in_buffer,
  931. .throttle = hvsi_throttle,
  932. .unthrottle = hvsi_unthrottle,
  933. .tiocmget = hvsi_tiocmget,
  934. .tiocmset = hvsi_tiocmset,
  935. };
  936. static int __init hvsi_init(void)
  937. {
  938. int i;
  939. hvsi_driver = alloc_tty_driver(hvsi_count);
  940. if (!hvsi_driver)
  941. return -ENOMEM;
  942. hvsi_driver->owner = THIS_MODULE;
  943. hvsi_driver->driver_name = "hvsi";
  944. hvsi_driver->name = "hvsi";
  945. hvsi_driver->major = HVSI_MAJOR;
  946. hvsi_driver->minor_start = HVSI_MINOR;
  947. hvsi_driver->type = TTY_DRIVER_TYPE_SYSTEM;
  948. hvsi_driver->init_termios = tty_std_termios;
  949. hvsi_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL;
  950. hvsi_driver->init_termios.c_ispeed = 9600;
  951. hvsi_driver->init_termios.c_ospeed = 9600;
  952. hvsi_driver->flags = TTY_DRIVER_REAL_RAW;
  953. tty_set_operations(hvsi_driver, &hvsi_ops);
  954. for (i=0; i < hvsi_count; i++) {
  955. struct hvsi_struct *hp = &hvsi_ports[i];
  956. int ret = 1;
  957. ret = request_irq(hp->virq, hvsi_interrupt, IRQF_DISABLED, "hvsi", hp);
  958. if (ret)
  959. printk(KERN_ERR "HVSI: couldn't reserve irq 0x%x (error %i)\n",
  960. hp->virq, ret);
  961. }
  962. hvsi_wait = wait_for_state; /* irqs active now */
  963. if (tty_register_driver(hvsi_driver))
  964. panic("Couldn't register hvsi console driver\n");
  965. printk(KERN_DEBUG "HVSI: registered %i devices\n", hvsi_count);
  966. return 0;
  967. }
  968. device_initcall(hvsi_init);
  969. /***** console (not tty) code: *****/
  970. static void hvsi_console_print(struct console *console, const char *buf,
  971. unsigned int count)
  972. {
  973. struct hvsi_struct *hp = &hvsi_ports[console->index];
  974. char c[HVSI_MAX_OUTGOING_DATA] __ALIGNED__;
  975. unsigned int i = 0, n = 0;
  976. int ret, donecr = 0;
  977. mb();
  978. if (!is_open(hp))
  979. return;
  980. /*
  981. * ugh, we have to translate LF -> CRLF ourselves, in place.
  982. * copied from hvc_console.c:
  983. */
  984. while (count > 0 || i > 0) {
  985. if (count > 0 && i < sizeof(c)) {
  986. if (buf[n] == '\n' && !donecr) {
  987. c[i++] = '\r';
  988. donecr = 1;
  989. } else {
  990. c[i++] = buf[n++];
  991. donecr = 0;
  992. --count;
  993. }
  994. } else {
  995. ret = hvsi_put_chars(hp, c, i);
  996. if (ret < 0)
  997. i = 0;
  998. i -= ret;
  999. }
  1000. }
  1001. }
  1002. static struct tty_driver *hvsi_console_device(struct console *console,
  1003. int *index)
  1004. {
  1005. *index = console->index;
  1006. return hvsi_driver;
  1007. }
  1008. static int __init hvsi_console_setup(struct console *console, char *options)
  1009. {
  1010. struct hvsi_struct *hp;
  1011. int ret;
  1012. if (console->index < 0 || console->index >= hvsi_count)
  1013. return -1;
  1014. hp = &hvsi_ports[console->index];
  1015. /* give the FSP a chance to change the baud rate when we re-open */
  1016. hvsi_close_protocol(hp);
  1017. ret = hvsi_handshake(hp);
  1018. if (ret < 0)
  1019. return ret;
  1020. ret = hvsi_get_mctrl(hp);
  1021. if (ret < 0)
  1022. return ret;
  1023. ret = hvsi_set_mctrl(hp, hp->mctrl | TIOCM_DTR);
  1024. if (ret < 0)
  1025. return ret;
  1026. hp->flags |= HVSI_CONSOLE;
  1027. return 0;
  1028. }
  1029. static struct console hvsi_console = {
  1030. .name = "hvsi",
  1031. .write = hvsi_console_print,
  1032. .device = hvsi_console_device,
  1033. .setup = hvsi_console_setup,
  1034. .flags = CON_PRINTBUFFER,
  1035. .index = -1,
  1036. };
  1037. static int __init hvsi_console_init(void)
  1038. {
  1039. struct device_node *vty;
  1040. hvsi_wait = poll_for_state; /* no irqs yet; must poll */
  1041. /* search device tree for vty nodes */
  1042. for (vty = of_find_compatible_node(NULL, "serial", "hvterm-protocol");
  1043. vty != NULL;
  1044. vty = of_find_compatible_node(vty, "serial", "hvterm-protocol")) {
  1045. struct hvsi_struct *hp;
  1046. const uint32_t *vtermno, *irq;
  1047. vtermno = of_get_property(vty, "reg", NULL);
  1048. irq = of_get_property(vty, "interrupts", NULL);
  1049. if (!vtermno || !irq)
  1050. continue;
  1051. if (hvsi_count >= MAX_NR_HVSI_CONSOLES) {
  1052. of_node_put(vty);
  1053. break;
  1054. }
  1055. hp = &hvsi_ports[hvsi_count];
  1056. INIT_DELAYED_WORK(&hp->writer, hvsi_write_worker);
  1057. INIT_WORK(&hp->handshaker, hvsi_handshaker);
  1058. init_waitqueue_head(&hp->emptyq);
  1059. init_waitqueue_head(&hp->stateq);
  1060. spin_lock_init(&hp->lock);
  1061. hp->index = hvsi_count;
  1062. hp->inbuf_end = hp->inbuf;
  1063. hp->state = HVSI_CLOSED;
  1064. hp->vtermno = *vtermno;
  1065. hp->virq = irq_create_mapping(NULL, irq[0]);
  1066. if (hp->virq == NO_IRQ) {
  1067. printk(KERN_ERR "%s: couldn't create irq mapping for 0x%x\n",
  1068. __func__, irq[0]);
  1069. continue;
  1070. }
  1071. hvsi_count++;
  1072. }
  1073. if (hvsi_count)
  1074. register_console(&hvsi_console);
  1075. return 0;
  1076. }
  1077. console_initcall(hvsi_console_init);