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

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

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

  • 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
[c8bf88d]29/** @addtogroup 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>
[de57e060]47
[66b430e]48enum {
49 /** Interval between polling in microseconds */
[a71c158]50 POLL_INTERVAL = 10000, /* 0.01 s */
[a35b458]51
[66b430e]52 /** Max. number of characters to pull out at a time */
[a71c158]53 POLL_LIMIT = 30,
[a35b458]54
[a71c158]55 SKI_INIT_CONSOLE = 20,
56 SKI_GETCHAR = 21,
57 SKI_PUTCHAR = 31
[66b430e]58};
[c2417bc]59
[b366a6f4]60static void ski_putchar(outdev_t *, const wchar_t);
[c2417bc]61
[a71c158]62static outdev_operations_t skidev_ops = {
63 .write = ski_putchar,
[7ddc2c7]64 .redraw = NULL,
65 .scroll_up = NULL,
66 .scroll_down = NULL
[c2417bc]67};
68
[a71c158]69static ski_instance_t *instance = NULL;
[2270bef]70
[880de6e]71/** Ask debug console if a key was pressed.
[a8c48241]72 *
73 * Use SSC (Simulator System Call) to
74 * get character from debug console.
[880de6e]75 *
76 * This call is non-blocking.
77 *
78 * @return ASCII code of pressed key or 0 if no key pressed.
[c2417bc]79 *
[a8c48241]80 */
[c2417bc]81static wchar_t ski_getchar(void)
[a8c48241]82{
[7f1c620]83 uint64_t ch;
[a35b458]84
[e7b7be3f]85 asm volatile (
[de57e060]86 "mov r15 = %1\n"
[c2417bc]87 "break 0x80000;;\n" /* modifies r8 */
88 "mov %0 = r8;;\n"
[a35b458]89
[5bb20ec]90 : "=r" (ch)
91 : "i" (SKI_GETCHAR)
[de57e060]92 : "r15", "r8"
[a8c48241]93 );
[a35b458]94
[c2417bc]95 return (wchar_t) ch;
[a8c48241]96}
[6095342]97
[66b430e]98/** Ask keyboard if a key was pressed.
99 *
100 * If so, it will repeat and pull up to POLL_LIMIT characters.
101 */
[c2417bc]102static void poll_keyboard(ski_instance_t *instance)
[6095342]103{
[a71c158]104 int count = POLL_LIMIT;
[a35b458]105
[66b430e]106 while (count > 0) {
[a71c158]107 wchar_t ch = ski_getchar();
[a35b458]108
[66b430e]109 if (ch == '\0')
110 break;
[a35b458]111
[c2417bc]112 indev_push_character(instance->srlnin, ch);
[66b430e]113 --count;
114 }
[6095342]115}
116
[2270bef]117/** Kernel thread for polling keyboard. */
[c2417bc]118static void kskipoll(void *arg)
[de57e060]119{
[c2417bc]120 ski_instance_t *instance = (ski_instance_t *) arg;
[a35b458]121
[c2417bc]122 while (true) {
[b366a6f4]123 // TODO FIXME:
124 // This currently breaks the kernel console
125 // before we get the override from uspace.
126 if (console_override)
[c2417bc]127 poll_keyboard(instance);
[a35b458]128
[2270bef]129 thread_usleep(POLL_INTERVAL);
130 }
[6095342]131}
132
[a71c158]133/** Initialize debug console
134 *
135 * Issue SSC (Simulator System Call) to
136 * to open debug console.
137 *
138 */
139static void ski_init(void)
[6095342]140{
[a71c158]141 if (instance)
142 return;
[a35b458]143
[a71c158]144 asm volatile (
145 "mov r15 = %0\n"
146 "break 0x80000\n"
147 :
148 : "i" (SKI_INIT_CONSOLE)
149 : "r15", "r8"
150 );
[a35b458]151
[a71c158]152 instance = malloc(sizeof(ski_instance_t), FRAME_ATOMIC);
[a35b458]153
[c2417bc]154 if (instance) {
[6eef3c4]155 instance->thread = thread_create(kskipoll, instance, TASK,
156 THREAD_FLAG_UNCOUNTED, "kskipoll");
[a35b458]157
[c2417bc]158 if (!instance->thread) {
159 free(instance);
[a71c158]160 instance = NULL;
161 return;
[c2417bc]162 }
[a35b458]163
[c2417bc]164 instance->srlnin = NULL;
165 }
[a71c158]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 */
[b366a6f4]189static void ski_putchar(outdev_t *dev, const wchar_t ch)
[a71c158]190{
[b366a6f4]191 // TODO FIXME:
192 // This currently breaks the kernel console
193 // before we get the override from uspace.
194 if (console_override) {
[a71c158]195 if (ascii_check(ch)) {
196 if (ch == '\n')
197 ski_do_putchar('\r');
[a35b458]198
[a71c158]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;
[a35b458]210
[a71c158]211 outdev_t *skidev = malloc(sizeof(outdev_t), FRAME_ATOMIC);
212 if (!skidev)
213 return NULL;
[a35b458]214
[a71c158]215 outdev_initialize("skidev", skidev, &skidev_ops);
216 skidev->data = instance;
[a35b458]217
[a71c158]218 if (!fb_exported) {
219 /*
[b366a6f4]220 * This is the necessary evil until
221 * the userspace driver is entirely
[a71c158]222 * self-sufficient.
223 */
[3a5506a]224 sysinfo_set_item_val("fb", NULL, true);
[3193c05]225 sysinfo_set_item_val("fb.kind", NULL, 6);
[a35b458]226
[a71c158]227 fb_exported = true;
228 }
[a35b458]229
[a71c158]230 return skidev;
231}
232
233ski_instance_t *skiin_init(void)
234{
235 ski_init();
[c2417bc]236 return instance;
[c640876]237}
[6095342]238
[c2417bc]239void skiin_wire(ski_instance_t *instance, indev_t *srlnin)
[c640876]240{
[63e27ef]241 assert(instance);
242 assert(srlnin);
[a35b458]243
[c2417bc]244 instance->srlnin = srlnin;
245 thread_ready(instance->thread);
[a35b458]246
[de57e060]247 sysinfo_set_item_val("kbd", NULL, true);
[323a5aaf]248 sysinfo_set_item_val("kbd.type", NULL, KBD_SKI);
[de57e060]249}
250
[06e1e95]251/** @}
[b45c443]252 */
Note: See TracBrowser for help on using the repository browser.