Rev 3853 | Rev 3880 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3853 | Rev 3854 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2005 Jakub Jermar |
2 | * Copyright (c) 2005 Jakub Jermar |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup ia64 |
29 | /** @addtogroup ia64 |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | /** @file |
32 | /** @file |
33 | */ |
33 | */ |
34 | 34 | ||
35 | #include <arch/ski/ski.h> |
35 | #include <arch/ski/ski.h> |
36 | #include <console/console.h> |
36 | #include <console/console.h> |
37 | #include <console/chardev.h> |
37 | #include <console/chardev.h> |
38 | #include <arch/interrupt.h> |
38 | #include <arch/interrupt.h> |
39 | #include <sysinfo/sysinfo.h> |
39 | #include <sysinfo/sysinfo.h> |
40 | #include <arch/types.h> |
40 | #include <arch/types.h> |
41 | #include <ddi/device.h> |
41 | #include <ddi/device.h> |
42 | #include <ddi/irq.h> |
42 | #include <ddi/irq.h> |
43 | #include <ipc/irq.h> |
43 | #include <ipc/irq.h> |
44 | #include <proc/thread.h> |
44 | #include <proc/thread.h> |
45 | #include <synch/spinlock.h> |
45 | #include <synch/spinlock.h> |
46 | #include <arch/asm.h> |
46 | #include <arch/asm.h> |
47 | #include <arch/drivers/kbd.h> |
47 | #include <arch/drivers/kbd.h> |
48 | 48 | ||
49 | #define SKI_KBD_INR 0 |
49 | #define SKI_KBD_INR 0 |
50 | 50 | ||
51 | static irq_t ski_kbd_irq; |
51 | static irq_t ski_kbd_irq; |
52 | static devno_t ski_kbd_devno; |
52 | static devno_t ski_kbd_devno; |
53 | 53 | ||
54 | chardev_t ski_console; |
54 | chardev_t ski_console; |
55 | chardev_t ski_uconsole; |
55 | chardev_t ski_uconsole; |
56 | 56 | ||
57 | static bool kbd_disabled; |
57 | static bool kbd_disabled; |
58 | 58 | ||
59 | /** Display character on debug console |
59 | /** Display character on debug console |
60 | * |
60 | * |
61 | * Use SSC (Simulator System Call) to |
61 | * Use SSC (Simulator System Call) to |
62 | * display character on debug console. |
62 | * display character on debug console. |
63 | * |
63 | * |
64 | * @param d Character device. |
64 | * @param d Character device. |
65 | * @param ch Character to be printed. |
65 | * @param ch Character to be printed. |
66 | */ |
66 | */ |
67 | static void ski_putchar(chardev_t *d, const char ch, bool silent) |
67 | static void ski_putchar(chardev_t *d, const char ch, bool silent) |
68 | { |
68 | { |
69 | if (!silent) { |
69 | if (!silent) { |
70 | asm volatile ( |
70 | asm volatile ( |
71 | "mov r15 = %0\n" |
71 | "mov r15 = %0\n" |
72 | "mov r32 = %1\n" /* r32 is in0 */ |
72 | "mov r32 = %1\n" /* r32 is in0 */ |
73 | "break 0x80000\n" /* modifies r8 */ |
73 | "break 0x80000\n" /* modifies r8 */ |
74 | : |
74 | : |
75 | : "i" (SKI_PUTCHAR), "r" (ch) |
75 | : "i" (SKI_PUTCHAR), "r" (ch) |
76 | : "r15", "in0", "r8" |
76 | : "r15", "in0", "r8" |
77 | ); |
77 | ); |
78 | 78 | ||
79 | if (ch == '\n') |
79 | if (ch == '\n') |
80 | ski_putchar(d, '\r', silent); |
80 | ski_putchar(d, '\r', false); |
81 | } |
81 | } |
82 | } |
82 | } |
83 | 83 | ||
84 | /** Ask debug console if a key was pressed. |
84 | /** Ask debug console if a key was pressed. |
85 | * |
85 | * |
86 | * Use SSC (Simulator System Call) to |
86 | * Use SSC (Simulator System Call) to |
87 | * get character from debug console. |
87 | * get character from debug console. |
88 | * |
88 | * |
89 | * This call is non-blocking. |
89 | * This call is non-blocking. |
90 | * |
90 | * |
91 | * @return ASCII code of pressed key or 0 if no key pressed. |
91 | * @return ASCII code of pressed key or 0 if no key pressed. |
92 | */ |
92 | */ |
93 | static int32_t ski_getchar(void) |
93 | static int32_t ski_getchar(void) |
94 | { |
94 | { |
95 | uint64_t ch; |
95 | uint64_t ch; |
96 | 96 | ||
97 | asm volatile ( |
97 | asm volatile ( |
98 | "mov r15 = %1\n" |
98 | "mov r15 = %1\n" |
99 | "break 0x80000;;\n" /* modifies r8 */ |
99 | "break 0x80000;;\n" /* modifies r8 */ |
100 | "mov %0 = r8;;\n" |
100 | "mov %0 = r8;;\n" |
101 | 101 | ||
102 | : "=r" (ch) |
102 | : "=r" (ch) |
103 | : "i" (SKI_GETCHAR) |
103 | : "i" (SKI_GETCHAR) |
104 | : "r15", "r8" |
104 | : "r15", "r8" |
105 | ); |
105 | ); |
106 | 106 | ||
107 | return (int32_t) ch; |
107 | return (int32_t) ch; |
108 | } |
108 | } |
109 | 109 | ||
110 | /** |
110 | /** |
111 | * This is a blocking wrapper for ski_getchar(). |
111 | * This is a blocking wrapper for ski_getchar(). |
112 | * To be used when the kernel crashes. |
112 | * To be used when the kernel crashes. |
113 | */ |
113 | */ |
114 | static char ski_getchar_blocking(chardev_t *d) |
114 | static char ski_getchar_blocking(chardev_t *d) |
115 | { |
115 | { |
116 | int ch; |
116 | int ch; |
117 | 117 | ||
118 | while(!(ch = ski_getchar())) |
118 | while(!(ch = ski_getchar())) |
119 | ; |
119 | ; |
120 | if (ch == '\r') |
120 | if (ch == '\r') |
121 | ch = '\n'; |
121 | ch = '\n'; |
122 | return (char) ch; |
122 | return (char) ch; |
123 | } |
123 | } |
124 | 124 | ||
125 | /** Ask keyboard if a key was pressed. */ |
125 | /** Ask keyboard if a key was pressed. */ |
126 | static void poll_keyboard(void) |
126 | static void poll_keyboard(void) |
127 | { |
127 | { |
128 | char ch; |
128 | char ch; |
129 | static char last; |
129 | static char last; |
130 | ipl_t ipl; |
130 | ipl_t ipl; |
131 | 131 | ||
132 | ipl = interrupts_disable(); |
132 | ipl = interrupts_disable(); |
133 | 133 | ||
134 | if (kbd_disabled) { |
134 | if (kbd_disabled) { |
135 | interrupts_restore(ipl); |
135 | interrupts_restore(ipl); |
136 | return; |
136 | return; |
137 | } |
137 | } |
138 | 138 | ||
139 | spinlock_lock(&ski_kbd_irq.lock); |
139 | spinlock_lock(&ski_kbd_irq.lock); |
140 | 140 | ||
141 | ch = ski_getchar(); |
141 | ch = ski_getchar(); |
142 | if(ch == '\r') |
142 | if(ch == '\r') |
143 | ch = '\n'; |
143 | ch = '\n'; |
144 | if (ch) { |
144 | if (ch) { |
145 | if (ski_kbd_irq.notif_cfg.notify && |
145 | if (ski_kbd_irq.notif_cfg.notify && |
146 | ski_kbd_irq.notif_cfg.answerbox) { |
146 | ski_kbd_irq.notif_cfg.answerbox) { |
147 | chardev_push_character(&ski_uconsole, ch); |
147 | chardev_push_character(&ski_uconsole, ch); |
148 | ipc_irq_send_notif(&ski_kbd_irq); |
148 | ipc_irq_send_notif(&ski_kbd_irq); |
149 | } else { |
149 | } else { |
150 | chardev_push_character(&ski_console, ch); |
150 | chardev_push_character(&ski_console, ch); |
151 | } |
151 | } |
152 | last = ch; |
152 | last = ch; |
153 | spinlock_unlock(&ski_kbd_irq.lock); |
153 | spinlock_unlock(&ski_kbd_irq.lock); |
154 | interrupts_restore(ipl); |
154 | interrupts_restore(ipl); |
155 | return; |
155 | return; |
156 | } |
156 | } |
157 | 157 | ||
158 | if (last) { |
158 | if (last) { |
159 | if (ski_kbd_irq.notif_cfg.notify && |
159 | if (ski_kbd_irq.notif_cfg.notify && |
160 | ski_kbd_irq.notif_cfg.answerbox) { |
160 | ski_kbd_irq.notif_cfg.answerbox) { |
161 | chardev_push_character(&ski_uconsole, 0); |
161 | chardev_push_character(&ski_uconsole, 0); |
162 | ipc_irq_send_notif(&ski_kbd_irq); |
162 | ipc_irq_send_notif(&ski_kbd_irq); |
163 | } |
163 | } |
164 | last = 0; |
164 | last = 0; |
165 | } |
165 | } |
166 | 166 | ||
167 | spinlock_unlock(&ski_kbd_irq.lock); |
167 | spinlock_unlock(&ski_kbd_irq.lock); |
168 | interrupts_restore(ipl); |
168 | interrupts_restore(ipl); |
169 | } |
169 | } |
170 | 170 | ||
171 | /* Called from getc(). */ |
171 | /* Called from getc(). */ |
172 | static void ski_kbd_enable(chardev_t *d) |
172 | static void ski_kbd_enable(chardev_t *d) |
173 | { |
173 | { |
174 | kbd_disabled = false; |
174 | kbd_disabled = false; |
175 | } |
175 | } |
176 | 176 | ||
177 | /* Called from getc(). */ |
177 | /* Called from getc(). */ |
178 | static void ski_kbd_disable(chardev_t *d) |
178 | static void ski_kbd_disable(chardev_t *d) |
179 | { |
179 | { |
180 | kbd_disabled = true; |
180 | kbd_disabled = true; |
181 | } |
181 | } |
182 | 182 | ||
183 | /** Decline to service hardware IRQ. |
183 | /** Decline to service hardware IRQ. |
184 | * |
184 | * |
185 | * This is only a virtual IRQ, so always decline. |
185 | * This is only a virtual IRQ, so always decline. |
186 | * |
186 | * |
187 | * @return Always IRQ_DECLINE. |
187 | * @return Always IRQ_DECLINE. |
188 | */ |
188 | */ |
189 | static irq_ownership_t ski_kbd_claim(void) |
189 | static irq_ownership_t ski_kbd_claim(void) |
190 | { |
190 | { |
191 | return IRQ_DECLINE; |
191 | return IRQ_DECLINE; |
192 | } |
192 | } |
193 | 193 | ||
194 | static chardev_operations_t ski_ops = { |
194 | static chardev_operations_t ski_ops = { |
195 | .resume = ski_kbd_enable, |
195 | .resume = ski_kbd_enable, |
196 | .suspend = ski_kbd_disable, |
196 | .suspend = ski_kbd_disable, |
197 | .write = ski_putchar, |
197 | .write = ski_putchar, |
198 | .read = ski_getchar_blocking |
198 | .read = ski_getchar_blocking |
199 | }; |
199 | }; |
200 | 200 | ||
201 | /** Initialize debug console |
201 | /** Initialize debug console |
202 | * |
202 | * |
203 | * Issue SSC (Simulator System Call) to |
203 | * Issue SSC (Simulator System Call) to |
204 | * to open debug console. |
204 | * to open debug console. |
205 | */ |
205 | */ |
206 | void ski_init_console(void) |
206 | void ski_init_console(void) |
207 | { |
207 | { |
208 | asm volatile ( |
208 | asm volatile ( |
209 | "mov r15 = %0\n" |
209 | "mov r15 = %0\n" |
210 | "break 0x80000\n" |
210 | "break 0x80000\n" |
211 | : |
211 | : |
212 | : "i" (SKI_INIT_CONSOLE) |
212 | : "i" (SKI_INIT_CONSOLE) |
213 | : "r15", "r8" |
213 | : "r15", "r8" |
214 | ); |
214 | ); |
215 | 215 | ||
216 | chardev_initialize("ski_console", &ski_console, &ski_ops); |
216 | chardev_initialize("ski_console", &ski_console, &ski_ops); |
217 | chardev_initialize("ski_uconsole", &ski_uconsole, &ski_ops); |
217 | chardev_initialize("ski_uconsole", &ski_uconsole, &ski_ops); |
218 | stdin = &ski_console; |
218 | stdin = &ski_console; |
219 | stdout = &ski_console; |
219 | stdout = &ski_console; |
220 | 220 | ||
221 | ski_kbd_devno = device_assign_devno(); |
221 | ski_kbd_devno = device_assign_devno(); |
222 | 222 | ||
223 | irq_initialize(&ski_kbd_irq); |
223 | irq_initialize(&ski_kbd_irq); |
224 | ski_kbd_irq.inr = SKI_KBD_INR; |
224 | ski_kbd_irq.inr = SKI_KBD_INR; |
225 | ski_kbd_irq.devno = ski_kbd_devno; |
225 | ski_kbd_irq.devno = ski_kbd_devno; |
226 | ski_kbd_irq.claim = ski_kbd_claim; |
226 | ski_kbd_irq.claim = ski_kbd_claim; |
227 | irq_register(&ski_kbd_irq); |
227 | irq_register(&ski_kbd_irq); |
228 | 228 | ||
229 | sysinfo_set_item_val("kbd", NULL, true); |
229 | sysinfo_set_item_val("kbd", NULL, true); |
230 | sysinfo_set_item_val("kbd.inr", NULL, SKI_KBD_INR); |
230 | sysinfo_set_item_val("kbd.inr", NULL, SKI_KBD_INR); |
231 | sysinfo_set_item_val("kbd.devno", NULL, ski_kbd_devno); |
231 | sysinfo_set_item_val("kbd.devno", NULL, ski_kbd_devno); |
232 | sysinfo_set_item_val("kbd.type", NULL, KBD_SKI); |
232 | sysinfo_set_item_val("kbd.type", NULL, KBD_SKI); |
233 | 233 | ||
234 | sysinfo_set_item_val("fb", NULL, false); |
234 | sysinfo_set_item_val("fb", NULL, false); |
235 | } |
235 | } |
236 | 236 | ||
237 | void ski_kbd_grab(void) |
237 | void ski_kbd_grab(void) |
238 | { |
238 | { |
239 | ipl_t ipl = interrupts_disable(); |
239 | ipl_t ipl = interrupts_disable(); |
240 | spinlock_lock(&ski_kbd_irq.lock); |
240 | spinlock_lock(&ski_kbd_irq.lock); |
241 | ski_kbd_irq.notif_cfg.notify = false; |
241 | ski_kbd_irq.notif_cfg.notify = false; |
242 | spinlock_unlock(&ski_kbd_irq.lock); |
242 | spinlock_unlock(&ski_kbd_irq.lock); |
243 | interrupts_restore(ipl); |
243 | interrupts_restore(ipl); |
244 | } |
244 | } |
245 | 245 | ||
246 | void ski_kbd_release(void) |
246 | void ski_kbd_release(void) |
247 | { |
247 | { |
248 | ipl_t ipl = interrupts_disable(); |
248 | ipl_t ipl = interrupts_disable(); |
249 | spinlock_lock(&ski_kbd_irq.lock); |
249 | spinlock_lock(&ski_kbd_irq.lock); |
250 | if (ski_kbd_irq.notif_cfg.answerbox) |
250 | if (ski_kbd_irq.notif_cfg.answerbox) |
251 | ski_kbd_irq.notif_cfg.notify = true; |
251 | ski_kbd_irq.notif_cfg.notify = true; |
252 | spinlock_unlock(&ski_kbd_irq.lock); |
252 | spinlock_unlock(&ski_kbd_irq.lock); |
253 | interrupts_restore(ipl); |
253 | interrupts_restore(ipl); |
254 | } |
254 | } |
255 | 255 | ||
256 | 256 | ||
257 | #define POLL_INTERVAL 50000 /* 50 ms */ |
257 | #define POLL_INTERVAL 50000 /* 50 ms */ |
258 | 258 | ||
259 | /** Kernel thread for polling keyboard. */ |
259 | /** Kernel thread for polling keyboard. */ |
260 | void kkbdpoll(void *arg) |
260 | void kkbdpoll(void *arg) |
261 | { |
261 | { |
262 | while (1) { |
262 | while (1) { |
263 | poll_keyboard(); |
263 | poll_keyboard(); |
264 | thread_usleep(POLL_INTERVAL); |
264 | thread_usleep(POLL_INTERVAL); |
265 | } |
265 | } |
266 | } |
266 | } |
267 | 267 | ||
268 | /** @} |
268 | /** @} |
269 | */ |
269 | */ |
270 | 270 |