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

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

cleanup thread_create() and thread_t structure

  • remove 'flag' bitfield from thread_t, use individual boolean flags (can be optimized later on by adding : 1)
  • use an enum for call flags, add THREAD_FLAG_NONE
  • remove the 'uncounted' argument in favour of a call flag
  • introduce thread_wire() to setup wired threads
  • Property mode set to 100644
File size: 5.4 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 <typedefs.h>
40#include <proc/thread.h>
41#include <synch/spinlock.h>
42#include <arch/asm.h>
43#include <arch/drivers/kbd.h>
44#include <str.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);
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 int count = POLL_LIMIT;
102
103 while (count > 0) {
104 wchar_t ch = ski_getchar();
105
106 if (ch == '\0')
107 break;
108
109 indev_push_character(instance->srlnin, ch);
110 --count;
111 }
112}
113
114/** Kernel thread for polling keyboard. */
115static void kskipoll(void *arg)
116{
117 ski_instance_t *instance = (ski_instance_t *) arg;
118
119 while (true) {
120 // TODO FIXME:
121 // This currently breaks the kernel console
122 // before we get the override from uspace.
123 if (console_override)
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,
153 THREAD_FLAG_UNCOUNTED, "kskipoll");
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 *
185 */
186static void ski_putchar(outdev_t *dev, const wchar_t ch)
187{
188 // TODO FIXME:
189 // This currently breaks the kernel console
190 // before we get the override from uspace.
191 if (console_override) {
192 if (ascii_check(ch)) {
193 if (ch == '\n')
194 ski_do_putchar('\r');
195
196 ski_do_putchar(ch);
197 } else
198 ski_do_putchar(U_SPECIAL);
199 }
200}
201
202outdev_t *skiout_init(void)
203{
204 ski_init();
205 if (!instance)
206 return NULL;
207
208 outdev_t *skidev = malloc(sizeof(outdev_t), FRAME_ATOMIC);
209 if (!skidev)
210 return NULL;
211
212 outdev_initialize("skidev", skidev, &skidev_ops);
213 skidev->data = instance;
214
215 if (!fb_exported) {
216 /*
217 * This is the necessary evil until
218 * the userspace driver is entirely
219 * self-sufficient.
220 */
221 sysinfo_set_item_val("fb", NULL, true);
222 sysinfo_set_item_val("fb.kind", NULL, 6);
223
224 fb_exported = true;
225 }
226
227 return skidev;
228}
229
230ski_instance_t *skiin_init(void)
231{
232 ski_init();
233 return instance;
234}
235
236void skiin_wire(ski_instance_t *instance, indev_t *srlnin)
237{
238 ASSERT(instance);
239 ASSERT(srlnin);
240
241 instance->srlnin = srlnin;
242 thread_ready(instance->thread);
243
244 sysinfo_set_item_val("kbd", NULL, true);
245 sysinfo_set_item_val("kbd.type", NULL, KBD_SKI);
246}
247
248/** @}
249 */
Note: See TracBrowser for help on using the repository browser.