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

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

kernel output devices now suport multiple instances (except ski and sgcn, which respect the same interface, but behave as singletons)
if more than one output device gets initialized, the output is cloned to all of them
get rid of arch_grab_console() and arch_release_console() (output devices can implement a generic "redraw" method, input devices respect the "silent" global variable)
related cleanups and modifications

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