aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Rothwell <sfr@canb.auug.org.au>2006-07-13 04:51:22 -0400
committerStephen Rothwell <sfr@canb.auug.org.au>2006-07-13 04:51:22 -0400
commit8bff05b052db7a4cfaaf0eee7f8145600548e9c9 (patch)
treefe637e3ba17b1453d039b8fdd7d9339fad674f4a
parent3da27289a8ecc688fc62c0961dfe89d392370480 (diff)
[POWERPC] iseries: A new iSeries console
This driver uses the hvc_console.c infrastructure that is used by the pSeries virtual and RTAS consoles. This will allow us to make viocons.c obsolete and is another step along the way to a combined kernel (as viocons could not coexist with CONFIG_VT). Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
-rw-r--r--arch/powerpc/platforms/iseries/Kconfig8
-rw-r--r--arch/powerpc/platforms/iseries/dt.c3
-rw-r--r--drivers/char/Kconfig7
-rw-r--r--drivers/char/Makefile1
-rw-r--r--drivers/char/hvc_iseries.c593
-rw-r--r--drivers/char/viocons.c31
-rw-r--r--include/asm-powerpc/iseries/vio.h28
7 files changed, 638 insertions, 33 deletions
diff --git a/arch/powerpc/platforms/iseries/Kconfig b/arch/powerpc/platforms/iseries/Kconfig
index 3d957a30c8c..887b68804e6 100644
--- a/arch/powerpc/platforms/iseries/Kconfig
+++ b/arch/powerpc/platforms/iseries/Kconfig
@@ -3,13 +3,17 @@ menu "iSeries device drivers"
3 depends on PPC_ISERIES 3 depends on PPC_ISERIES
4 4
5config VIOCONS 5config VIOCONS
6 tristate "iSeries Virtual Console Support" 6 tristate "iSeries Virtual Console Support (Obsolete)"
7 help
8 This is the old virtual console driver for legacy iSeries.
9 You should use the iSeries Hypervisor Virtual Console
10 support instead.
7 11
8config VIODASD 12config VIODASD
9 tristate "iSeries Virtual I/O disk support" 13 tristate "iSeries Virtual I/O disk support"
10 help 14 help
11 If you are running on an iSeries system and you want to use 15 If you are running on an iSeries system and you want to use
12 virtual disks created and managed by OS/400, say Y. 16 virtual disks created and managed by OS/400, say Y.
13 17
14config VIOCD 18config VIOCD
15 tristate "iSeries Virtual I/O CD support" 19 tristate "iSeries Virtual I/O CD support"
diff --git a/arch/powerpc/platforms/iseries/dt.c b/arch/powerpc/platforms/iseries/dt.c
index d194140c1eb..894b534669d 100644
--- a/arch/powerpc/platforms/iseries/dt.c
+++ b/arch/powerpc/platforms/iseries/dt.c
@@ -298,7 +298,8 @@ static void __init dt_vdevices(struct iseries_flat_dt *dt)
298 dt_prop_u32(dt, "#address-cells", 1); 298 dt_prop_u32(dt, "#address-cells", 1);
299 dt_prop_u32(dt, "#size-cells", 0); 299 dt_prop_u32(dt, "#size-cells", 0);
300 300
301 dt_do_vdevice(dt, "vty", reg, -1, device_type_serial, NULL, 1); 301 dt_do_vdevice(dt, "vty", reg, -1, device_type_serial,
302 "IBM,iSeries-vty", 1);
302 reg++; 303 reg++;
303 304
304 dt_do_vdevice(dt, "v-scsi", reg, -1, device_type_vscsi, 305 dt_do_vdevice(dt, "v-scsi", reg, -1, device_type_vscsi,
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index 11de59ff422..a7ef542afbc 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -610,6 +610,13 @@ config HVC_CONSOLE
610 console. This driver allows each pSeries partition to have a console 610 console. This driver allows each pSeries partition to have a console
611 which is accessed via the HMC. 611 which is accessed via the HMC.
612 612
613config HVC_ISERIES
614 bool "iSeries Hypervisor Virtual Console support"
615 depends on PPC_ISERIES && !VIOCONS
616 select HVC_DRIVER
617 help
618 iSeries machines support a hypervisor virtual console.
619
613config HVC_RTAS 620config HVC_RTAS
614 bool "IBM RTAS Console support" 621 bool "IBM RTAS Console support"
615 depends on PPC_RTAS 622 depends on PPC_RTAS
diff --git a/drivers/char/Makefile b/drivers/char/Makefile
index 7a7ee572127..8c6dfc62152 100644
--- a/drivers/char/Makefile
+++ b/drivers/char/Makefile
@@ -42,6 +42,7 @@ obj-$(CONFIG_AMIGA_BUILTIN_SERIAL) += amiserial.o
42obj-$(CONFIG_SX) += sx.o generic_serial.o 42obj-$(CONFIG_SX) += sx.o generic_serial.o
43obj-$(CONFIG_RIO) += rio/ generic_serial.o 43obj-$(CONFIG_RIO) += rio/ generic_serial.o
44obj-$(CONFIG_HVC_CONSOLE) += hvc_vio.o hvsi.o 44obj-$(CONFIG_HVC_CONSOLE) += hvc_vio.o hvsi.o
45obj-$(CONFIG_HVC_ISERIES) += hvc_iseries.o
45obj-$(CONFIG_HVC_RTAS) += hvc_rtas.o 46obj-$(CONFIG_HVC_RTAS) += hvc_rtas.o
46obj-$(CONFIG_HVC_DRIVER) += hvc_console.o 47obj-$(CONFIG_HVC_DRIVER) += hvc_console.o
47obj-$(CONFIG_RAW_DRIVER) += raw.o 48obj-$(CONFIG_RAW_DRIVER) += raw.o
diff --git a/drivers/char/hvc_iseries.c b/drivers/char/hvc_iseries.c
new file mode 100644
index 00000000000..256afc8e583
--- /dev/null
+++ b/drivers/char/hvc_iseries.c
@@ -0,0 +1,593 @@
1/*
2 * iSeries vio driver interface to hvc_console.c
3 *
4 * This code is based heavily on hvc_vio.c and viocons.c
5 *
6 * Copyright (C) 2006 Stephen Rothwell, IBM Corporation
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22#include <stdarg.h>
23#include <linux/types.h>
24#include <linux/init.h>
25#include <linux/kernel.h>
26#include <linux/spinlock.h>
27#include <linux/console.h>
28
29#include <asm/hvconsole.h>
30#include <asm/vio.h>
31#include <asm/prom.h>
32#include <asm/iseries/vio.h>
33#include <asm/iseries/hv_call.h>
34#include <asm/iseries/hv_lp_config.h>
35#include <asm/iseries/hv_lp_event.h>
36
37#include "hvc_console.h"
38
39#define VTTY_PORTS 10
40
41static DEFINE_SPINLOCK(consolelock);
42static DEFINE_SPINLOCK(consoleloglock);
43
44static const char hvc_driver_name[] = "hvc_console";
45
46#define IN_BUF_SIZE 200
47
48/*
49 * Our port information.
50 */
51static struct port_info {
52 HvLpIndex lp;
53 u64 seq; /* sequence number of last HV send */
54 u64 ack; /* last ack from HV */
55 struct hvc_struct *hp;
56 int in_start;
57 int in_end;
58 unsigned char in_buf[IN_BUF_SIZE];
59} port_info[VTTY_PORTS] = {
60 [ 0 ... VTTY_PORTS - 1 ] = {
61 .lp = HvLpIndexInvalid
62 }
63};
64
65#define viochar_is_console(pi) ((pi) == &port_info[0])
66
67static struct vio_device_id hvc_driver_table[] __devinitdata = {
68 {"serial", "IBM,iSeries-vty"},
69 { "", "" }
70};
71MODULE_DEVICE_TABLE(vio, hvc_driver_table);
72
73static void hvlog(char *fmt, ...)
74{
75 int i;
76 unsigned long flags;
77 va_list args;
78 static char buf[256];
79
80 spin_lock_irqsave(&consoleloglock, flags);
81 va_start(args, fmt);
82 i = vscnprintf(buf, sizeof(buf) - 1, fmt, args);
83 va_end(args);
84 buf[i++] = '\r';
85 HvCall_writeLogBuffer(buf, i);
86 spin_unlock_irqrestore(&consoleloglock, flags);
87}
88
89/*
90 * Initialize the common fields in a charLpEvent
91 */
92static void init_data_event(struct viocharlpevent *viochar, HvLpIndex lp)
93{
94 struct HvLpEvent *hev = &viochar->event;
95
96 memset(viochar, 0, sizeof(struct viocharlpevent));
97
98 hev->flags = HV_LP_EVENT_VALID | HV_LP_EVENT_DEFERRED_ACK |
99 HV_LP_EVENT_INT;
100 hev->xType = HvLpEvent_Type_VirtualIo;
101 hev->xSubtype = viomajorsubtype_chario | viochardata;
102 hev->xSourceLp = HvLpConfig_getLpIndex();
103 hev->xTargetLp = lp;
104 hev->xSizeMinus1 = sizeof(struct viocharlpevent);
105 hev->xSourceInstanceId = viopath_sourceinst(lp);
106 hev->xTargetInstanceId = viopath_targetinst(lp);
107}
108
109static int get_chars(uint32_t vtermno, char *buf, int count)
110{
111 struct port_info *pi;
112 int n = 0;
113 unsigned long flags;
114
115 if (vtermno >= VTTY_PORTS)
116 return -EINVAL;
117 if (count == 0)
118 return 0;
119
120 pi = &port_info[vtermno];
121 spin_lock_irqsave(&consolelock, flags);
122
123 if (pi->in_end == 0)
124 goto done;
125
126 n = pi->in_end - pi->in_start;
127 if (n > count)
128 n = count;
129 memcpy(buf, &pi->in_buf[pi->in_start], n);
130 pi->in_start += n;
131 if (pi->in_start == pi->in_end) {
132 pi->in_start = 0;
133 pi->in_end = 0;
134 }
135done:
136 spin_unlock_irqrestore(&consolelock, flags);
137 return n;
138}
139
140static int put_chars(uint32_t vtermno, const char *buf, int count)
141{
142 struct viocharlpevent *viochar;
143 struct port_info *pi;
144 HvLpEvent_Rc hvrc;
145 unsigned long flags;
146 int sent = 0;
147
148 if (vtermno >= VTTY_PORTS)
149 return -EINVAL;
150
151 pi = &port_info[vtermno];
152
153 spin_lock_irqsave(&consolelock, flags);
154
155 if (viochar_is_console(pi) && !viopath_isactive(pi->lp)) {
156 spin_lock_irqsave(&consoleloglock, flags);
157 HvCall_writeLogBuffer(buf, count);
158 spin_unlock_irqrestore(&consoleloglock, flags);
159 sent = count;
160 goto done;
161 }
162
163 viochar = vio_get_event_buffer(viomajorsubtype_chario);
164 if (viochar == NULL) {
165 hvlog("\n\rviocons: Can't get viochar buffer.");
166 goto done;
167 }
168
169 while ((count > 0) && ((pi->seq - pi->ack) < VIOCHAR_WINDOW)) {
170 int len;
171
172 len = (count > VIOCHAR_MAX_DATA) ? VIOCHAR_MAX_DATA : count;
173
174 if (viochar_is_console(pi)) {
175 spin_lock_irqsave(&consoleloglock, flags);
176 HvCall_writeLogBuffer(buf, len);
177 spin_unlock_irqrestore(&consoleloglock, flags);
178 }
179
180 init_data_event(viochar, pi->lp);
181
182 viochar->len = len;
183 viochar->event.xCorrelationToken = pi->seq++;
184 viochar->event.xSizeMinus1 =
185 offsetof(struct viocharlpevent, data) + len;
186
187 memcpy(viochar->data, buf, len);
188
189 hvrc = HvCallEvent_signalLpEvent(&viochar->event);
190 if (hvrc)
191 hvlog("\n\rerror sending event! return code %d\n\r",
192 (int)hvrc);
193 sent += len;
194 count -= len;
195 buf += len;
196 }
197
198 vio_free_event_buffer(viomajorsubtype_chario, viochar);
199done:
200 spin_unlock_irqrestore(&consolelock, flags);
201 return sent;
202}
203
204static struct hv_ops hvc_get_put_ops = {
205 .get_chars = get_chars,
206 .put_chars = put_chars,
207};
208
209static int __devinit hvc_vio_probe(struct vio_dev *vdev,
210 const struct vio_device_id *id)
211{
212 struct hvc_struct *hp;
213 struct port_info *pi;
214
215 /* probed with invalid parameters. */
216 if (!vdev || !id)
217 return -EPERM;
218
219 if (vdev->unit_address >= VTTY_PORTS)
220 return -ENODEV;
221
222 pi = &port_info[vdev->unit_address];
223
224 hp = hvc_alloc(vdev->unit_address, vdev->irq, &hvc_get_put_ops);
225 if (IS_ERR(hp))
226 return PTR_ERR(hp);
227 pi->hp = hp;
228 dev_set_drvdata(&vdev->dev, pi);
229
230 return 0;
231}
232
233static int __devexit hvc_vio_remove(struct vio_dev *vdev)
234{
235 struct port_info *pi = dev_get_drvdata(&vdev->dev);
236 struct hvc_struct *hp = pi->hp;
237
238 return hvc_remove(hp);
239}
240
241static struct vio_driver hvc_vio_driver = {
242 .id_table = hvc_driver_table,
243 .probe = hvc_vio_probe,
244 .remove = hvc_vio_remove,
245 .driver = {
246 .name = hvc_driver_name,
247 .owner = THIS_MODULE,
248 }
249};
250
251static void hvc_open_event(struct HvLpEvent *event)
252{
253 unsigned long flags;
254 struct viocharlpevent *cevent = (struct viocharlpevent *)event;
255 u8 port = cevent->virtual_device;
256 struct port_info *pi;
257 int reject = 0;
258
259 if (hvlpevent_is_ack(event)) {
260 if (port >= VTTY_PORTS)
261 return;
262
263 spin_lock_irqsave(&consolelock, flags);
264
265 pi = &port_info[port];
266 if (event->xRc == HvLpEvent_Rc_Good) {
267 pi->seq = pi->ack = 0;
268 /*
269 * This line allows connections from the primary
270 * partition but once one is connected from the
271 * primary partition nothing short of a reboot
272 * of linux will allow access from the hosting
273 * partition again without a required iSeries fix.
274 */
275 pi->lp = event->xTargetLp;
276 }
277
278 spin_unlock_irqrestore(&consolelock, flags);
279 if (event->xRc != HvLpEvent_Rc_Good)
280 printk(KERN_WARNING
281 "hvc: handle_open_event: event->xRc == (%d).\n",
282 event->xRc);
283
284 if (event->xCorrelationToken != 0) {
285 atomic_t *aptr= (atomic_t *)event->xCorrelationToken;
286 atomic_set(aptr, 1);
287 } else
288 printk(KERN_WARNING
289 "hvc: weird...got open ack without atomic\n");
290 return;
291 }
292
293 /* This had better require an ack, otherwise complain */
294 if (!hvlpevent_need_ack(event)) {
295 printk(KERN_WARNING "hvc: viocharopen without ack bit!\n");
296 return;
297 }
298
299 spin_lock_irqsave(&consolelock, flags);
300
301 /* Make sure this is a good virtual tty */
302 if (port >= VTTY_PORTS) {
303 event->xRc = HvLpEvent_Rc_SubtypeError;
304 cevent->subtype_result_code = viorc_openRejected;
305 /*
306 * Flag state here since we can't printk while holding
307 * the consolelock spinlock.
308 */
309 reject = 1;
310 } else {
311 pi = &port_info[port];
312 if ((pi->lp != HvLpIndexInvalid) &&
313 (pi->lp != event->xSourceLp)) {
314 /*
315 * If this is tty is already connected to a different
316 * partition, fail.
317 */
318 event->xRc = HvLpEvent_Rc_SubtypeError;
319 cevent->subtype_result_code = viorc_openRejected;
320 reject = 2;
321 } else {
322 pi->lp = event->xSourceLp;
323 event->xRc = HvLpEvent_Rc_Good;
324 cevent->subtype_result_code = viorc_good;
325 pi->seq = pi->ack = 0;
326 }
327 }
328
329 spin_unlock_irqrestore(&consolelock, flags);
330
331 if (reject == 1)
332 printk(KERN_WARNING "hvc: open rejected: bad virtual tty.\n");
333 else if (reject == 2)
334 printk(KERN_WARNING "hvc: open rejected: console in exclusive "
335 "use by another partition.\n");
336
337 /* Return the acknowledgement */
338 HvCallEvent_ackLpEvent(event);
339}
340
341/*
342 * Handle a close charLpEvent. This should ONLY be an Interrupt because the
343 * virtual console should never actually issue a close event to the hypervisor
344 * because the virtual console never goes away. A close event coming from the
345 * hypervisor simply means that there are no client consoles connected to the
346 * virtual console.
347 */
348static void hvc_close_event(struct HvLpEvent *event)
349{
350 unsigned long flags;
351 struct viocharlpevent *cevent = (struct viocharlpevent *)event;
352 u8 port = cevent->virtual_device;
353
354 if (!hvlpevent_is_int(event)) {
355 printk(KERN_WARNING
356 "hvc: got unexpected close acknowlegement\n");
357 return;
358 }
359
360 if (port >= VTTY_PORTS) {
361 printk(KERN_WARNING
362 "hvc: close message from invalid virtual device.\n");
363 return;
364 }
365
366 /* For closes, just mark the console partition invalid */
367 spin_lock_irqsave(&consolelock, flags);
368
369 if (port_info[port].lp == event->xSourceLp)
370 port_info[port].lp = HvLpIndexInvalid;
371
372 spin_unlock_irqrestore(&consolelock, flags);
373}
374
375static void hvc_data_event(struct HvLpEvent *event)
376{
377 unsigned long flags;
378 struct viocharlpevent *cevent = (struct viocharlpevent *)event;
379 struct port_info *pi;
380 int n;
381 u8 port = cevent->virtual_device;
382
383 if (port >= VTTY_PORTS) {
384 printk(KERN_WARNING "hvc: data on invalid virtual device %d\n",
385 port);
386 return;
387 }
388 if (cevent->len == 0)
389 return;
390
391 /*
392 * Change 05/01/2003 - Ryan Arnold: If a partition other than
393 * the current exclusive partition tries to send us data
394 * events then just drop them on the floor because we don't
395 * want his stinking data. He isn't authorized to receive
396 * data because he wasn't the first one to get the console,
397 * therefore he shouldn't be allowed to send data either.
398 * This will work without an iSeries fix.
399 */
400 pi = &port_info[port];
401 if (pi->lp != event->xSourceLp)
402 return;
403
404 spin_lock_irqsave(&consolelock, flags);
405
406 n = IN_BUF_SIZE - pi->in_end;
407 if (n > cevent->len)
408 n = cevent->len;
409 if (n > 0) {
410 memcpy(&pi->in_buf[pi->in_end], cevent->data, n);
411 pi->in_end += n;
412 }
413 spin_unlock_irqrestore(&consolelock, flags);
414 if (n == 0)
415 printk(KERN_WARNING "hvc: input buffer overflow\n");
416}
417
418static void hvc_ack_event(struct HvLpEvent *event)
419{
420 struct viocharlpevent *cevent = (struct viocharlpevent *)event;
421 unsigned long flags;
422 u8 port = cevent->virtual_device;
423
424 if (port >= VTTY_PORTS) {
425 printk(KERN_WARNING "hvc: data on invalid virtual device\n");
426 return;
427 }
428
429 spin_lock_irqsave(&consolelock, flags);
430 port_info[port].ack = event->xCorrelationToken;
431 spin_unlock_irqrestore(&consolelock, flags);
432}
433
434static void hvc_config_event(struct HvLpEvent *event)
435{
436 struct viocharlpevent *cevent = (struct viocharlpevent *)event;
437
438 if (cevent->data[0] == 0x01)
439 printk(KERN_INFO "hvc: window resized to %d: %d: %d: %d\n",
440 cevent->data[1], cevent->data[2],
441 cevent->data[3], cevent->data[4]);
442 else
443 printk(KERN_WARNING "hvc: unknown config event\n");
444}
445
446static void hvc_handle_event(struct HvLpEvent *event)
447{
448 int charminor;
449
450 if (event == NULL)
451 return;
452
453 charminor = event->xSubtype & VIOMINOR_SUBTYPE_MASK;
454 switch (charminor) {
455 case viocharopen:
456 hvc_open_event(event);
457 break;
458 case viocharclose:
459 hvc_close_event(event);
460 break;
461 case viochardata:
462 hvc_data_event(event);
463 break;
464 case viocharack:
465 hvc_ack_event(event);
466 break;
467 case viocharconfig:
468 hvc_config_event(event);
469 break;
470 default:
471 if (hvlpevent_is_int(event) && hvlpevent_need_ack(event)) {
472 event->xRc = HvLpEvent_Rc_InvalidSubtype;
473 HvCallEvent_ackLpEvent(event);
474 }
475 }
476}
477
478static int send_open(HvLpIndex remoteLp, void *sem)
479{
480 return HvCallEvent_signalLpEventFast(remoteLp,
481 HvLpEvent_Type_VirtualIo,
482 viomajorsubtype_chario | viocharopen,
483 HvLpEvent_AckInd_DoAck, HvLpEvent_AckType_ImmediateAck,
484 viopath_sourceinst(remoteLp),
485 viopath_targetinst(remoteLp),
486 (u64)(unsigned long)sem, VIOVERSION << 16,
487 0, 0, 0, 0);
488}
489
490static int hvc_vio_init(void)
491{
492 atomic_t wait_flag;
493 int rc;
494
495 /* +2 for fudge */
496 rc = viopath_open(HvLpConfig_getPrimaryLpIndex(),
497 viomajorsubtype_chario, VIOCHAR_WINDOW + 2);
498 if (rc)
499 printk(KERN_WARNING "hvc: error opening to primary %d\n", rc);
500
501 if (viopath_hostLp == HvLpIndexInvalid)
502 vio_set_hostlp();
503
504 /*
505 * And if the primary is not the same as the hosting LP, open to the
506 * hosting lp
507 */
508 if ((viopath_hostLp != HvLpIndexInvalid) &&
509 (viopath_hostLp != HvLpConfig_getPrimaryLpIndex())) {
510 printk(KERN_INFO "hvc: open path to hosting (%d)\n",
511 viopath_hostLp);
512 rc = viopath_open(viopath_hostLp, viomajorsubtype_chario,
513 VIOCHAR_WINDOW + 2); /* +2 for fudge */
514 if (rc)
515 printk(KERN_WARNING
516 "error opening to partition %d: %d\n",
517 viopath_hostLp, rc);
518 }
519
520 if (vio_setHandler(viomajorsubtype_chario, hvc_handle_event) < 0)
521 printk(KERN_WARNING
522 "hvc: error seting handler for console events!\n");
523
524 /*
525 * First, try to open the console to the hosting lp.
526 * Wait on a semaphore for the response.
527 */
528 atomic_set(&wait_flag, 0);
529 if ((viopath_isactive(viopath_hostLp)) &&
530 (send_open(viopath_hostLp, &wait_flag) == 0)) {
531 printk(KERN_INFO "hvc: hosting partition %d\n", viopath_hostLp);
532 while (atomic_read(&wait_flag) == 0)
533 mb();
534 atomic_set(&wait_flag, 0);
535 }
536
537 /*
538 * If we don't have an active console, try the primary
539 */
540 if ((!viopath_isactive(port_info[0].lp)) &&
541 (viopath_isactive(HvLpConfig_getPrimaryLpIndex())) &&
542 (send_open(HvLpConfig_getPrimaryLpIndex(), &wait_flag) == 0)) {
543 printk(KERN_INFO "hvc: opening console to primary partition\n");
544 while (atomic_read(&wait_flag) == 0)
545 mb();
546 }
547
548 /* Register as a vio device to receive callbacks */
549 rc = vio_register_driver(&hvc_vio_driver);
550
551 return rc;
552}
553module_init(hvc_vio_init); /* after drivers/char/hvc_console.c */
554
555static void hvc_vio_exit(void)
556{
557 vio_unregister_driver(&hvc_vio_driver);
558}
559module_exit(hvc_vio_exit);
560
561/* the device tree order defines our numbering */
562static int hvc_find_vtys(void)
563{
564 struct device_node *vty;
565 int num_found = 0;
566
567 for (vty = of_find_node_by_name(NULL, "vty"); vty != NULL;
568 vty = of_find_node_by_name(vty, "vty")) {
569 uint32_t *vtermno;
570
571 /* We have statically defined space for only a certain number
572 * of console adapters.
573 */
574 if ((num_found >= MAX_NR_HVC_CONSOLES) ||
575 (num_found >= VTTY_PORTS))
576 break;
577
578 vtermno = (uint32_t *)get_property(vty, "reg", NULL);
579 if (!vtermno)
580 continue;
581
582 if (!device_is_compatible(vty, "IBM,iSeries-vty"))
583 continue;
584
585 if (num_found == 0)
586 add_preferred_console("hvc", 0, NULL);
587 hvc_instantiate(*vtermno, num_found, &hvc_get_put_ops);
588 ++num_found;
589 }
590
591 return num_found;
592}
593console_initcall(hvc_find_vtys);
diff --git a/drivers/char/viocons.c b/drivers/char/viocons.c
index 766f7864c6c..f3efeaf2826 100644
--- a/drivers/char/viocons.c
+++ b/drivers/char/viocons.c
@@ -43,7 +43,6 @@
43#include <linux/sysrq.h> 43#include <linux/sysrq.h>
44 44
45#include <asm/iseries/vio.h> 45#include <asm/iseries/vio.h>
46
47#include <asm/iseries/hv_lp_event.h> 46#include <asm/iseries/hv_lp_event.h>
48#include <asm/iseries/hv_call_event.h> 47#include <asm/iseries/hv_call_event.h>
49#include <asm/iseries/hv_lp_config.h> 48#include <asm/iseries/hv_lp_config.h>
@@ -67,35 +66,6 @@ static int vio_sysrq_pressed;
67extern int sysrq_enabled; 66extern int sysrq_enabled;
68#endif 67#endif
69 68
70/*
71 * The structure of the events that flow between us and OS/400. You can't
72 * mess with this unless the OS/400 side changes too
73 */
74struct viocharlpevent {
75 struct HvLpEvent event;
76 u32 reserved;
77 u16 version;
78 u16 subtype_result_code;
79 u8 virtual_device;
80 u8 len;
81 u8 data[VIOCHAR_MAX_DATA];
82};
83
84#define VIOCHAR_WINDOW 10
85#define VIOCHAR_HIGHWATERMARK 3
86
87enum viocharsubtype {
88 viocharopen = 0x0001,
89 viocharclose = 0x0002,
90 viochardata = 0x0003,
91 viocharack = 0x0004,
92 viocharconfig = 0x0005
93};
94
95enum viochar_rc {
96 viochar_rc_ebusy = 1
97};
98
99#define VIOCHAR_NUM_BUF 16 69#define VIOCHAR_NUM_BUF 16
100 70
101/* 71/*
@@ -1183,6 +1153,7 @@ static int __init viocons_init(void)
1183 port_info[i].magic = VIOTTY_MAGIC; 1153 port_info[i].magic = VIOTTY_MAGIC;
1184 } 1154 }
1185 HvCall_setLogBufferFormatAndCodepage(HvCall_LogBuffer_ASCII, 437); 1155 HvCall_setLogBufferFormatAndCodepage(HvCall_LogBuffer_ASCII, 437);
1156 add_preferred_console("viocons", 0, NULL);
1186 register_console(&viocons_early); 1157 register_console(&viocons_early);
1187 return 0; 1158 return 0;
1188} 1159}
diff --git a/include/asm-powerpc/iseries/vio.h b/include/asm-powerpc/iseries/vio.h
index 72a97d37aac..7a95d296abd 100644
--- a/include/asm-powerpc/iseries/vio.h
+++ b/include/asm-powerpc/iseries/vio.h
@@ -122,6 +122,34 @@ enum viorc {
122 viorc_openRejected = 0x0301 122 viorc_openRejected = 0x0301
123}; 123};
124 124
125/*
126 * The structure of the events that flow between us and OS/400 for chario
127 * events. You can't mess with this unless the OS/400 side changes too.
128 */
129struct viocharlpevent {
130 struct HvLpEvent event;
131 u32 reserved;
132 u16 version;
133 u16 subtype_result_code;
134 u8 virtual_device;
135 u8 len;
136 u8 data[VIOCHAR_MAX_DATA];
137};
138
139#define VIOCHAR_WINDOW 10
140
141enum viocharsubtype {
142 viocharopen = 0x0001,
143 viocharclose = 0x0002,
144 viochardata = 0x0003,
145 viocharack = 0x0004,
146 viocharconfig = 0x0005
147};
148
149enum viochar_rc {
150 viochar_rc_ebusy = 1
151};
152
125struct device; 153struct device;
126 154
127extern struct device *iSeries_vio_dev; 155extern struct device *iSeries_vio_dev;