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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 705ca2b was aafed15, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 7 years ago

Declare malloc() etc in standard <stdlib.h> rather than <mm/slab.h>

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