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

Last change on this file was e9bc927, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 3 months ago

Update forgotten serial implementations

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