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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 3061bc1 was 63e27ef, checked in by Jiri Svoboda <jiri@…>, 8 years ago

ASSERT → assert

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