Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/* -*- linux-c -*-
*
* drivers/char/viocons.c
*
* iSeries Virtual Terminal
*
* Authors: Dave Boutcher <boutcher@us.ibm.com>
* Ryan Arnold <ryanarn@us.ibm.com>
* Colin Devilbiss <devilbis@us.ibm.com>
* Stephen Rothwell <sfr@au1.ibm.com>
*
* (C) Copyright 2000, 2001, 2002, 2003, 2004 IBM Corporation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) anyu later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <linux/config.h>
#include <linux/version.h>
#include <linux/kernel.h>
#include <linux/proc_fs.h>
#include <linux/errno.h>
#include <linux/vmalloc.h>
#include <linux/mm.h>
#include <linux/console.h>
#include <linux/module.h>
#include <asm/uaccess.h>
#include <linux/init.h>
#include <linux/wait.h>
#include <linux/spinlock.h>
#include <asm/ioctls.h>
#include <linux/kd.h>
#include <linux/tty.h>
#include <linux/tty_flip.h>
#include <linux/sysrq.h>
#include <asm/iSeries/vio.h>
#include <asm/iSeries/HvLpEvent.h>
#include <asm/iSeries/HvCallEvent.h>
#include <asm/iSeries/HvLpConfig.h>
#include <asm/iSeries/HvCall.h>
#ifdef CONFIG_VT
#error You must turn off CONFIG_VT to use CONFIG_VIOCONS
#endif
#define VIOTTY_MAGIC (0x0DCB)
#define VTTY_PORTS 10
#define VIOCONS_KERN_WARN KERN_WARNING "viocons: "
#define VIOCONS_KERN_INFO KERN_INFO "viocons: "
static DEFINE_SPINLOCK(consolelock);
static DEFINE_SPINLOCK(consoleloglock);
#ifdef CONFIG_MAGIC_SYSRQ
static int vio_sysrq_pressed;
extern int sysrq_enabled;
#endif
/*
* The structure of the events that flow between us and OS/400. You can't
* mess with this unless the OS/400 side changes too
*/
struct viocharlpevent {
struct HvLpEvent event;
u32 reserved;
u16 version;
u16 subtype_result_code;
u8 virtual_device;
u8 len;
u8 data[VIOCHAR_MAX_DATA];
};
#define VIOCHAR_WINDOW 10
#define VIOCHAR_HIGHWATERMARK 3
enum viocharsubtype {
viocharopen = 0x0001,
viocharclose = 0x0002,
viochardata = 0x0003,
viocharack = 0x0004,
viocharconfig = 0x0005
};
enum viochar_rc {
viochar_rc_ebusy = 1
};
#define VIOCHAR_NUM_BUF 16
/*
* Our port information. We store a pointer to one entry in the
* tty_driver_data
*/
static struct port_info {
int magic;
struct tty_struct *tty;
HvLpIndex lp;
u8 vcons;
u64 seq; /* sequence number of last HV send */
u64 ack; /* last ack from HV */
/*
* When we get writes faster than we can send it to the partition,
* buffer the data here. Note that used is a bit map of used buffers.
* It had better have enough bits to hold VIOCHAR_NUM_BUF the bitops assume
* it is a multiple of unsigned long
*/
unsigned long used;
u8 *buffer[VIOCHAR_NUM_BUF];
int bufferBytes[VIOCHAR_NUM_BUF];
int curbuf;
int bufferOverflow;
int overflowMessage;
} port_info[VTTY_PORTS];
#define viochar_is_console(pi) ((pi) == &port_info[0])
#define viochar_port(pi) ((pi) - &port_info[0])
static void initDataEvent(struct viocharlpevent *viochar, HvLpIndex lp);
static struct tty_driver *viotty_driver;
void hvlog(char *fmt, ...)
{
int i;
unsigned long flags;
va_list args;
static char buf[256];
spin_lock_irqsave(&consoleloglock, flags);
va_start(args, fmt);
i = vscnprintf(buf, sizeof(buf) - 1, fmt, args);
va_end(args);
buf[i++] = '\r';
HvCall_writeLogBuffer(buf, i);
spin_unlock_irqrestore(&consoleloglock, flags);
}
void hvlogOutput(const char *buf, int count)
{
unsigned long flags;
int begin;
int index;
static const char cr = '\r';
begin = 0;
spin_lock_irqsave(&consoleloglock, flags);
for (index = 0; index < count; index++) {
if (buf[index] == '\n') {
/*
* Start right after the last '\n' or at the zeroth
* array position and output the number of characters
* including the newline.
*/
HvCall_writeLogBuffer(&buf[begin], index - begin + 1);
begin = index + 1;
HvCall_writeLogBuffer(&cr, 1);
}
}
if ((index - begin) > 0)
HvCall_writeLogBuffer(&buf[begin], index - begin);
spin_unlock_irqrestore(&consoleloglock, flags);
}
/*
* Make sure we're pointing to a valid port_info structure. Shamelessly
* plagerized from serial.c
*/
static inline int viotty_paranoia_check(struct port_info *pi,
char *name, const char *routine)
{
static const char *bad_pi_addr = VIOCONS_KERN_WARN
"warning: bad address for port_info struct (%s) in %s\n";
static const char *badmagic = VIOCONS_KERN_WARN
"warning: bad magic number for port_info struct (%s) in %s\n";
if ((pi < &port_info[0]) || (viochar_port(pi) > VTTY_PORTS)) {
printk(bad_pi_addr, name, routine);
return 1;
}
if (pi->magic != VIOTTY_MAGIC) {
printk(badmagic, name, routine);
return 1;
}
return 0;
}
/*
Loading
Loading full blame...