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