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

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

automatic kernel console lockout

  • kernel automatically relinquishes the access to the kernel console when the uspace maps the respective physical memory area
  • kernel output before uspace initialization is currently broken on Ski (no physical memory area), but this is pending further unification
  • kernel console devices are now independent (there is no system-wide "silent" variable), thus on multiple devices the kernel console and uspace output might be usable at the same time
  • Property mode set to 100644
File size: 5.4 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,
63 .redraw = NULL
[c2417bc]64};
65
[a71c158]66static ski_instance_t *instance = NULL;
[2270bef]67
[880de6e]68/** Ask debug console if a key was pressed.
[a8c48241]69 *
70 * Use SSC (Simulator System Call) to
71 * get character from debug console.
[880de6e]72 *
73 * This call is non-blocking.
74 *
75 * @return ASCII code of pressed key or 0 if no key pressed.
[c2417bc]76 *
[a8c48241]77 */
[c2417bc]78static wchar_t ski_getchar(void)
[a8c48241]79{
[7f1c620]80 uint64_t ch;
[a8c48241]81
[e7b7be3f]82 asm volatile (
[de57e060]83 "mov r15 = %1\n"
[c2417bc]84 "break 0x80000;;\n" /* modifies r8 */
85 "mov %0 = r8;;\n"
86
[5bb20ec]87 : "=r" (ch)
88 : "i" (SKI_GETCHAR)
[de57e060]89 : "r15", "r8"
[a8c48241]90 );
[c2417bc]91
92 return (wchar_t) ch;
[a8c48241]93}
[6095342]94
[66b430e]95/** Ask keyboard if a key was pressed.
96 *
97 * If so, it will repeat and pull up to POLL_LIMIT characters.
98 */
[c2417bc]99static void poll_keyboard(ski_instance_t *instance)
[6095342]100{
[a71c158]101 int count = POLL_LIMIT;
102
[66b430e]103 while (count > 0) {
[a71c158]104 wchar_t ch = ski_getchar();
105
[66b430e]106 if (ch == '\0')
107 break;
[a71c158]108
[c2417bc]109 indev_push_character(instance->srlnin, ch);
[66b430e]110 --count;
111 }
[6095342]112}
113
[2270bef]114/** Kernel thread for polling keyboard. */
[c2417bc]115static void kskipoll(void *arg)
[de57e060]116{
[c2417bc]117 ski_instance_t *instance = (ski_instance_t *) arg;
118
119 while (true) {
[b366a6f4]120 // TODO FIXME:
121 // This currently breaks the kernel console
122 // before we get the override from uspace.
123 if (console_override)
[c2417bc]124 poll_keyboard(instance);
125
[2270bef]126 thread_usleep(POLL_INTERVAL);
127 }
[6095342]128}
129
[a71c158]130/** Initialize debug console
131 *
132 * Issue SSC (Simulator System Call) to
133 * to open debug console.
134 *
135 */
136static void ski_init(void)
[6095342]137{
[a71c158]138 if (instance)
139 return;
[c640876]140
[a71c158]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);
[c640876]150
[c2417bc]151 if (instance) {
[253d3d0]152 instance->thread = thread_create(kskipoll, instance, TASK, 0,
153 "kskipoll", true);
[c2417bc]154
155 if (!instance->thread) {
156 free(instance);
[a71c158]157 instance = NULL;
158 return;
[c2417bc]159 }
160
161 instance->srlnin = NULL;
162 }
[a71c158]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 */
[b366a6f4]186static void ski_putchar(outdev_t *dev, const wchar_t ch)
[a71c158]187{
[b366a6f4]188 // TODO FIXME:
189 // This currently breaks the kernel console
190 // before we get the override from uspace.
191 if (console_override) {
[a71c158]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;
[c2417bc]211
[a71c158]212 outdev_initialize("skidev", skidev, &skidev_ops);
213 skidev->data = instance;
214
215 if (!fb_exported) {
216 /*
[b366a6f4]217 * This is the necessary evil until
218 * the userspace driver is entirely
[a71c158]219 * self-sufficient.
220 */
[3193c05]221 sysinfo_set_item_val("fb.kind", NULL, 6);
[a71c158]222
223 fb_exported = true;
224 }
225
226 return skidev;
227}
228
229ski_instance_t *skiin_init(void)
230{
231 ski_init();
[c2417bc]232 return instance;
[c640876]233}
[6095342]234
[c2417bc]235void skiin_wire(ski_instance_t *instance, indev_t *srlnin)
[c640876]236{
[c2417bc]237 ASSERT(instance);
238 ASSERT(srlnin);
239
240 instance->srlnin = srlnin;
241 thread_ready(instance->thread);
242
[de57e060]243 sysinfo_set_item_val("kbd", NULL, true);
[323a5aaf]244 sysinfo_set_item_val("kbd.type", NULL, KBD_SKI);
[de57e060]245}
246
[06e1e95]247/** @}
[b45c443]248 */
Note: See TracBrowser for help on using the repository browser.