Mercurial > hvf > hvf-old
annotate cp/drivers/console.c @ 618:535aec703236
cp: define a FIXME macro that leaves a sclp message
There are far too many fixmes in the code. Sadly, the compiler simply
discards them. This usually isn't an issue until one accidentally hits a
"weird" bug which just turns out to be an unhandled (but documented) case in
another part of the code. Using a macro instead of a comment will let the
compiler string-ify the text, and then at runtime use SCLP to print it out.
This will immediatelly point at problem areas. So, keep an eye on SCLP from
now on :)
Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author | Josef 'Jeff' Sipek <jeffpc@josefsipek.net> |
---|---|
date | Tue, 13 Dec 2011 22:20:50 -0500 |
parents | 6b1f2cc66681 |
children |
rev | line source |
---|---|
417
bd6f5cdfac97
Happy New Year! - Add copyright notices
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
415
diff
changeset
|
1 /* |
581
fe0910111769
cp: replace crusty console line buffering mechanism with a spoolfile
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
543
diff
changeset
|
2 * (C) Copyright 2007-2011 Josef 'Jeff' Sipek <jeffpc@josefsipek.net> |
417
bd6f5cdfac97
Happy New Year! - Add copyright notices
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
415
diff
changeset
|
3 * |
bd6f5cdfac97
Happy New Year! - Add copyright notices
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
415
diff
changeset
|
4 * This file is released under the GPLv2. See the COPYING file for more |
bd6f5cdfac97
Happy New Year! - Add copyright notices
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
415
diff
changeset
|
5 * details. |
bd6f5cdfac97
Happy New Year! - Add copyright notices
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
415
diff
changeset
|
6 */ |
bd6f5cdfac97
Happy New Year! - Add copyright notices
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
415
diff
changeset
|
7 |
415 | 8 #include <console.h> |
9 #include <slab.h> | |
10 #include <sched.h> | |
11 #include <directory.h> | |
12 #include <vsprintf.h> | |
581
fe0910111769
cp: replace crusty console line buffering mechanism with a spoolfile
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
543
diff
changeset
|
13 #include <spool.h> |
fe0910111769
cp: replace crusty console line buffering mechanism with a spoolfile
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
543
diff
changeset
|
14 #include <buddy.h> |
415 | 15 |
16 /* | |
17 * List of all consoles on the system | |
18 */ | |
19 static LIST_HEAD(consoles); | |
20 static spinlock_t consoles_lock = SPIN_LOCK_UNLOCKED; | |
21 | |
22 static void do_issue_read(struct console *con, struct io_op *ioop, struct ccw *ccws) | |
23 { | |
581
fe0910111769
cp: replace crusty console line buffering mechanism with a spoolfile
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
543
diff
changeset
|
24 int ret; |
415 | 25 |
26 atomic_dec(&con->dev->attention); | |
27 | |
581
fe0910111769
cp: replace crusty console line buffering mechanism with a spoolfile
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
543
diff
changeset
|
28 /* clear the buffer to allow strlen on the result */ |
fe0910111769
cp: replace crusty console line buffering mechanism with a spoolfile
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
543
diff
changeset
|
29 memset(con->bigbuf, 0, CONSOLE_LINE_LEN+1); |
415 | 30 |
581
fe0910111769
cp: replace crusty console line buffering mechanism with a spoolfile
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
543
diff
changeset
|
31 ccws[0].addr = ADDR31(con->bigbuf); |
fe0910111769
cp: replace crusty console line buffering mechanism with a spoolfile
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
543
diff
changeset
|
32 ccws[0].count = CONSOLE_LINE_LEN; |
415 | 33 ccws[0].cmd = 0x0a; |
34 ccws[0].flags = CCW_FLAG_SLI; | |
35 | |
36 memset(&ioop->orb, 0, sizeof(struct orb)); | |
37 ioop->orb.lpm = 0xff; | |
38 ioop->orb.addr = ADDR31(ccws); | |
39 ioop->orb.f = 1; | |
40 | |
581
fe0910111769
cp: replace crusty console line buffering mechanism with a spoolfile
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
543
diff
changeset
|
41 ioop->handler = NULL; |
415 | 42 ioop->dtor = NULL; |
43 | |
44 submit_io(con->dev, ioop, CAN_SLEEP); | |
581
fe0910111769
cp: replace crusty console line buffering mechanism with a spoolfile
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
543
diff
changeset
|
45 |
fe0910111769
cp: replace crusty console line buffering mechanism with a spoolfile
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
543
diff
changeset
|
46 ret = spool_append_rec(con->rlines, con->bigbuf, |
582
5aced27e0f39
cp: fix signedness warning
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
581
diff
changeset
|
47 strnlen((char*)con->bigbuf, CONSOLE_LINE_LEN)); |
581
fe0910111769
cp: replace crusty console line buffering mechanism with a spoolfile
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
543
diff
changeset
|
48 BUG_ON(ret); |
415 | 49 } |
50 | |
51 /** | |
52 * console_flusher - iterates over a console's buffers and initiates the IO | |
53 */ | |
54 static int console_flusher(void *data) | |
55 { | |
56 struct console *con = data; | |
581
fe0910111769
cp: replace crusty console line buffering mechanism with a spoolfile
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
543
diff
changeset
|
57 u8 *buf; |
fe0910111769
cp: replace crusty console line buffering mechanism with a spoolfile
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
543
diff
changeset
|
58 u16 len; |
fe0910111769
cp: replace crusty console line buffering mechanism with a spoolfile
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
543
diff
changeset
|
59 u16 left; |
415 | 60 |
61 /* needed for the IO */ | |
62 struct io_op ioop; | |
581
fe0910111769
cp: replace crusty console line buffering mechanism with a spoolfile
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
543
diff
changeset
|
63 struct ccw ccws[PAGE_SIZE/CONSOLE_LINE_LEN]; |
fe0910111769
cp: replace crusty console line buffering mechanism with a spoolfile
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
543
diff
changeset
|
64 int i; |
415 | 65 |
66 for(;;) { | |
618
535aec703236
cp: define a FIXME macro that leaves a sclp message
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
592
diff
changeset
|
67 FIXME("this should be a sub-unless-zero"); |
415 | 68 if (atomic_read(&con->dev->attention)) |
69 do_issue_read(con, &ioop, ccws); | |
70 | |
581
fe0910111769
cp: replace crusty console line buffering mechanism with a spoolfile
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
543
diff
changeset
|
71 buf = con->bigbuf; |
fe0910111769
cp: replace crusty console line buffering mechanism with a spoolfile
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
543
diff
changeset
|
72 left = PAGE_SIZE; |
fe0910111769
cp: replace crusty console line buffering mechanism with a spoolfile
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
543
diff
changeset
|
73 |
fe0910111769
cp: replace crusty console line buffering mechanism with a spoolfile
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
543
diff
changeset
|
74 for(i=0; left >= CONSOLE_LINE_LEN; i++) { |
fe0910111769
cp: replace crusty console line buffering mechanism with a spoolfile
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
543
diff
changeset
|
75 len = CONSOLE_LINE_LEN; |
fe0910111769
cp: replace crusty console line buffering mechanism with a spoolfile
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
543
diff
changeset
|
76 if (spool_grab_rec(con->wlines, buf, &len)) |
fe0910111769
cp: replace crusty console line buffering mechanism with a spoolfile
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
543
diff
changeset
|
77 break; |
415 | 78 |
581
fe0910111769
cp: replace crusty console line buffering mechanism with a spoolfile
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
543
diff
changeset
|
79 ccws[i].addr = ADDR31(buf); |
fe0910111769
cp: replace crusty console line buffering mechanism with a spoolfile
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
543
diff
changeset
|
80 ccws[i].count = len; |
fe0910111769
cp: replace crusty console line buffering mechanism with a spoolfile
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
543
diff
changeset
|
81 ccws[i].cmd = 0x01; /* write */ |
fe0910111769
cp: replace crusty console line buffering mechanism with a spoolfile
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
543
diff
changeset
|
82 ccws[i].flags = CCW_FLAG_CC | CCW_FLAG_SLI; |
415 | 83 |
581
fe0910111769
cp: replace crusty console line buffering mechanism with a spoolfile
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
543
diff
changeset
|
84 left -= len; |
fe0910111769
cp: replace crusty console line buffering mechanism with a spoolfile
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
543
diff
changeset
|
85 buf += len; |
415 | 86 } |
87 | |
581
fe0910111769
cp: replace crusty console line buffering mechanism with a spoolfile
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
543
diff
changeset
|
88 if (!i) { |
415 | 89 schedule(); |
90 continue; | |
91 } | |
92 | |
581
fe0910111769
cp: replace crusty console line buffering mechanism with a spoolfile
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
543
diff
changeset
|
93 ccws[i-1].flags &= ~CCW_FLAG_CC; |
415 | 94 |
95 /* | |
96 * Now, set up the ORB and CCW | |
97 */ | |
98 memset(&ioop.orb, 0, sizeof(struct orb)); | |
99 ioop.orb.lpm = 0xff; | |
100 ioop.orb.addr = ADDR31(ccws); | |
101 ioop.orb.f = 1; /* format 1 CCW */ | |
102 | |
103 /* | |
104 * Set up the operation handler pointers, and start the IO | |
105 */ | |
106 ioop.handler = NULL; | |
107 ioop.dtor = NULL; | |
108 | |
109 submit_io(con->dev, &ioop, CAN_SLEEP); | |
110 } | |
111 | |
112 return 0; | |
113 } | |
114 | |
115 static void print_splash(struct console *con) | |
116 { | |
543
37c1f0f94441
cp/nucleus: move the splash onto the ipl volume
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
501
diff
changeset
|
117 struct logo_rec *rec; |
37c1f0f94441
cp/nucleus: move the splash onto the ipl volume
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
501
diff
changeset
|
118 struct logo *logo; |
37c1f0f94441
cp/nucleus: move the splash onto the ipl volume
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
501
diff
changeset
|
119 |
37c1f0f94441
cp/nucleus: move the splash onto the ipl volume
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
501
diff
changeset
|
120 list_for_each_entry(logo, &sysconf.logos, list) { |
37c1f0f94441
cp/nucleus: move the splash onto the ipl volume
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
501
diff
changeset
|
121 if (con->dev->type != logo->devtype) |
37c1f0f94441
cp/nucleus: move the splash onto the ipl volume
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
501
diff
changeset
|
122 continue; |
415 | 123 |
618
535aec703236
cp: define a FIXME macro that leaves a sclp message
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
592
diff
changeset
|
124 FIXME("check the connection type"); |
543
37c1f0f94441
cp/nucleus: move the splash onto the ipl volume
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
501
diff
changeset
|
125 |
37c1f0f94441
cp/nucleus: move the splash onto the ipl volume
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
501
diff
changeset
|
126 list_for_each_entry(rec, &logo->lines, list) |
37c1f0f94441
cp/nucleus: move the splash onto the ipl volume
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
501
diff
changeset
|
127 con_printf(con, "%*.*s\n", CONFIG_LRECL, |
37c1f0f94441
cp/nucleus: move the splash onto the ipl volume
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
501
diff
changeset
|
128 CONFIG_LRECL, (char*) rec->data); |
37c1f0f94441
cp/nucleus: move the splash onto the ipl volume
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
501
diff
changeset
|
129 break; |
37c1f0f94441
cp/nucleus: move the splash onto the ipl volume
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
501
diff
changeset
|
130 } |
415 | 131 |
132 con_printf(con, "HVF VERSION " VERSION "\n\n"); | |
133 } | |
134 | |
135 struct console* start_oper_console(void) | |
136 { | |
137 struct device *dev; | |
138 | |
139 /* | |
140 * We only start the operator console | |
141 */ | |
142 | |
501
f9fe2cddf9e0
cp: use the operator console dev num & userid from the config file
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
417
diff
changeset
|
143 dev = find_device_by_ccuu(sysconf.oper_con); |
415 | 144 BUG_ON(IS_ERR(dev)); |
145 | |
146 return console_enable(dev); | |
147 } | |
148 | |
149 void* console_enable(struct device *dev) | |
150 { | |
151 char name[TASK_NAME_LEN+1]; | |
152 struct console *con; | |
153 | |
154 con = find_console(dev); | |
155 if (!IS_ERR(con)) | |
156 return con; | |
157 | |
158 if (register_console(dev)) | |
159 return ERR_PTR(-ENOMEM); | |
160 | |
161 /* try again, this time, we should always find it! */ | |
162 con = find_console(dev); | |
163 if (IS_ERR(con)) | |
164 return con; | |
165 | |
166 atomic_inc(&con->dev->in_use); | |
167 | |
168 snprintf(name, TASK_NAME_LEN, "%05X-conflsh", con->dev->sch); | |
169 | |
170 create_task(name, console_flusher, con); | |
171 | |
172 print_splash(con); | |
173 | |
174 return con; | |
175 } | |
176 | |
177 int con_read_pending(struct console *con) | |
178 { | |
581
fe0910111769
cp: replace crusty console line buffering mechanism with a spoolfile
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
543
diff
changeset
|
179 return spool_nrecs(con->rlines); |
415 | 180 } |
181 | |
182 int con_read(struct console *con, u8 *buf, int size) | |
183 { | |
581
fe0910111769
cp: replace crusty console line buffering mechanism with a spoolfile
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
543
diff
changeset
|
184 u16 len = size; |
415 | 185 |
581
fe0910111769
cp: replace crusty console line buffering mechanism with a spoolfile
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
543
diff
changeset
|
186 if (spool_grab_rec(con->rlines, buf, &len)) |
fe0910111769
cp: replace crusty console line buffering mechanism with a spoolfile
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
543
diff
changeset
|
187 return -1; |
415 | 188 |
189 return len; | |
190 } | |
191 | |
192 int con_write(struct console *con, u8 *buf, int len) | |
193 { | |
581
fe0910111769
cp: replace crusty console line buffering mechanism with a spoolfile
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
543
diff
changeset
|
194 if (spool_append_rec(con->wlines, buf, len)) |
fe0910111769
cp: replace crusty console line buffering mechanism with a spoolfile
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
543
diff
changeset
|
195 return 0; |
415 | 196 |
581
fe0910111769
cp: replace crusty console line buffering mechanism with a spoolfile
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
543
diff
changeset
|
197 return len; |
415 | 198 } |
199 | |
200 void for_each_console(void (*f)(struct console *con)) | |
201 { | |
202 struct console *con; | |
203 | |
204 if (!f) | |
205 return; | |
206 | |
207 spin_lock(&consoles_lock); | |
208 list_for_each_entry(con, &consoles, consoles) | |
209 f(con); | |
210 spin_unlock(&consoles_lock); | |
211 } | |
212 | |
213 struct console* find_console(struct device *dev) | |
214 { | |
215 struct console *con; | |
216 | |
217 if (!dev) | |
218 return ERR_PTR(-ENOENT); | |
219 | |
220 spin_lock(&consoles_lock); | |
221 list_for_each_entry(con, &consoles, consoles) { | |
222 if (con->dev == dev) | |
223 goto found; | |
224 } | |
225 con = ERR_PTR(-ENOENT); | |
226 found: | |
227 spin_unlock(&consoles_lock); | |
228 return con; | |
229 } |