source: mainline/kernel/arch/ia64/src/drivers/ski.c@ 35b8bfe

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 35b8bfe was 7ddc2c7, checked in by Martin Decky <martin@…>, 12 years ago

add support for framebuffer history paging (using Page Up and Page Down keys), inspiration taken from the code by Sebastian Köln
add support for input device out-of-band signalling

  • Property mode set to 100644
File size: 5.5 KB
RevLine 
[244f284]1/*
[df4ed85]2 * Copyright (c) 2005 Jakub Jermar
[244f284]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
[c8bf88d]29/** @addtogroup ia64
[b45c443]30 * @{
31 */
32/** @file
33 */
34
[c2417bc]35#include <arch/drivers/ski.h>
[6095342]36#include <console/console.h>
37#include <console/chardev.h>
[d0c5901]38#include <sysinfo/sysinfo.h>
[d99c1d2]39#include <typedefs.h>
[f0450658]40#include <proc/thread.h>
[de57e060]41#include <synch/spinlock.h>
42#include <arch/asm.h>
[50b3d30]43#include <arch/drivers/kbd.h>
[19f857a]44#include <str.h>
[2270bef]45#include <arch.h>
[de57e060]46
[66b430e]47enum {
48 /** Interval between polling in microseconds */
[a71c158]49 POLL_INTERVAL = 10000, /* 0.01 s */
50
[66b430e]51 /** Max. number of characters to pull out at a time */
[a71c158]52 POLL_LIMIT = 30,
53
54 SKI_INIT_CONSOLE = 20,
55 SKI_GETCHAR = 21,
56 SKI_PUTCHAR = 31
[66b430e]57};
[c2417bc]58
[b366a6f4]59static void ski_putchar(outdev_t *, const wchar_t);
[c2417bc]60
[a71c158]61static outdev_operations_t skidev_ops = {
62 .write = ski_putchar,
[7ddc2c7]63 .redraw = NULL,
64 .scroll_up = NULL,
65 .scroll_down = NULL
[c2417bc]66};
67
[a71c158]68static ski_instance_t *instance = NULL;
[2270bef]69
[880de6e]70/** Ask debug console if a key was pressed.
[a8c48241]71 *
72 * Use SSC (Simulator System Call) to
73 * get character from debug console.
[880de6e]74 *
75 * This call is non-blocking.
76 *
77 * @return ASCII code of pressed key or 0 if no key pressed.
[c2417bc]78 *
[a8c48241]79 */
[c2417bc]80static wchar_t ski_getchar(void)
[a8c48241]81{
[7f1c620]82 uint64_t ch;
[a8c48241]83
[e7b7be3f]84 asm volatile (
[de57e060]85 "mov r15 = %1\n"
[c2417bc]86 "break 0x80000;;\n" /* modifies r8 */
87 "mov %0 = r8;;\n"
88
[5bb20ec]89 : "=r" (ch)
90 : "i" (SKI_GETCHAR)
[de57e060]91 : "r15", "r8"
[a8c48241]92 );
[c2417bc]93
94 return (wchar_t) ch;
[a8c48241]95}
[6095342]96
[66b430e]97/** Ask keyboard if a key was pressed.
98 *
99 * If so, it will repeat and pull up to POLL_LIMIT characters.
100 */
[c2417bc]101static void poll_keyboard(ski_instance_t *instance)
[6095342]102{
[a71c158]103 int count = POLL_LIMIT;
104
[66b430e]105 while (count > 0) {
[a71c158]106 wchar_t ch = ski_getchar();
107
[66b430e]108 if (ch == '\0')
109 break;
[a71c158]110
[c2417bc]111 indev_push_character(instance->srlnin, ch);
[66b430e]112 --count;
113 }
[6095342]114}
115
[2270bef]116/** Kernel thread for polling keyboard. */
[c2417bc]117static void kskipoll(void *arg)
[de57e060]118{
[c2417bc]119 ski_instance_t *instance = (ski_instance_t *) arg;
120
121 while (true) {
[b366a6f4]122 // TODO FIXME:
123 // This currently breaks the kernel console
124 // before we get the override from uspace.
125 if (console_override)
[c2417bc]126 poll_keyboard(instance);
127
[2270bef]128 thread_usleep(POLL_INTERVAL);
129 }
[6095342]130}
131
[a71c158]132/** Initialize debug console
133 *
134 * Issue SSC (Simulator System Call) to
135 * to open debug console.
136 *
137 */
138static void ski_init(void)
[6095342]139{
[a71c158]140 if (instance)
141 return;
[c640876]142
[a71c158]143 asm volatile (
144 "mov r15 = %0\n"
145 "break 0x80000\n"
146 :
147 : "i" (SKI_INIT_CONSOLE)
148 : "r15", "r8"
149 );
150
151 instance = malloc(sizeof(ski_instance_t), FRAME_ATOMIC);
[c640876]152
[c2417bc]153 if (instance) {
[6eef3c4]154 instance->thread = thread_create(kskipoll, instance, TASK,
155 THREAD_FLAG_UNCOUNTED, "kskipoll");
[c2417bc]156
157 if (!instance->thread) {
158 free(instance);
[a71c158]159 instance = NULL;
160 return;
[c2417bc]161 }
162
163 instance->srlnin = NULL;
164 }
[a71c158]165}
166
167static void ski_do_putchar(const wchar_t ch)
168{
169 asm volatile (
170 "mov r15 = %[cmd]\n"
171 "mov r32 = %[ch]\n" /* r32 is in0 */
172 "break 0x80000\n" /* modifies r8 */
173 :
174 : [cmd] "i" (SKI_PUTCHAR), [ch] "r" (ch)
175 : "r15", "in0", "r8"
176 );
177}
178
179/** Display character on debug console
180 *
181 * Use SSC (Simulator System Call) to
182 * display character on debug console.
183 *
184 * @param dev Character device.
185 * @param ch Character to be printed.
186 *
187 */
[b366a6f4]188static void ski_putchar(outdev_t *dev, const wchar_t ch)
[a71c158]189{
[b366a6f4]190 // TODO FIXME:
191 // This currently breaks the kernel console
192 // before we get the override from uspace.
193 if (console_override) {
[a71c158]194 if (ascii_check(ch)) {
195 if (ch == '\n')
196 ski_do_putchar('\r');
197
198 ski_do_putchar(ch);
199 } else
200 ski_do_putchar(U_SPECIAL);
201 }
202}
203
204outdev_t *skiout_init(void)
205{
206 ski_init();
207 if (!instance)
208 return NULL;
209
210 outdev_t *skidev = malloc(sizeof(outdev_t), FRAME_ATOMIC);
211 if (!skidev)
212 return NULL;
[c2417bc]213
[a71c158]214 outdev_initialize("skidev", skidev, &skidev_ops);
215 skidev->data = instance;
216
217 if (!fb_exported) {
218 /*
[b366a6f4]219 * This is the necessary evil until
220 * the userspace driver is entirely
[a71c158]221 * self-sufficient.
222 */
[3a5506a]223 sysinfo_set_item_val("fb", NULL, true);
[3193c05]224 sysinfo_set_item_val("fb.kind", NULL, 6);
[a71c158]225
226 fb_exported = true;
227 }
228
229 return skidev;
230}
231
232ski_instance_t *skiin_init(void)
233{
234 ski_init();
[c2417bc]235 return instance;
[c640876]236}
[6095342]237
[c2417bc]238void skiin_wire(ski_instance_t *instance, indev_t *srlnin)
[c640876]239{
[c2417bc]240 ASSERT(instance);
241 ASSERT(srlnin);
242
243 instance->srlnin = srlnin;
244 thread_ready(instance->thread);
245
[de57e060]246 sysinfo_set_item_val("kbd", NULL, true);
[323a5aaf]247 sysinfo_set_item_val("kbd.type", NULL, KBD_SKI);
[de57e060]248}
249
[06e1e95]250/** @}
[b45c443]251 */
Note: See TracBrowser for help on using the repository browser.