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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 3193c05 was 3193c05, checked in by Jakub Jermar <jakub@…>, 15 years ago

Fix fb detection for Ski.

  • Property mode set to 100644
File size: 5.2 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
59static void ski_putchar(outdev_t *, const wchar_t, bool);
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 if (silent)
[6095342]102 return;
[a71c158]103
104 int count = POLL_LIMIT;
105
[66b430e]106 while (count > 0) {
[a71c158]107 wchar_t ch = ski_getchar();
108
[66b430e]109 if (ch == '\0')
110 break;
[a71c158]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;
121
122 while (true) {
123 if (!silent)
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 * @param silent Whether the output should be silenced.
185 *
186 */
187static void ski_putchar(outdev_t *dev, const wchar_t ch, bool silent)
188{
189 if (!silent) {
190 if (ascii_check(ch)) {
191 if (ch == '\n')
192 ski_do_putchar('\r');
193
194 ski_do_putchar(ch);
195 } else
196 ski_do_putchar(U_SPECIAL);
197 }
198}
199
200outdev_t *skiout_init(void)
201{
202 ski_init();
203 if (!instance)
204 return NULL;
205
206 outdev_t *skidev = malloc(sizeof(outdev_t), FRAME_ATOMIC);
207 if (!skidev)
208 return NULL;
[c2417bc]209
[a71c158]210 outdev_initialize("skidev", skidev, &skidev_ops);
211 skidev->data = instance;
212
213 if (!fb_exported) {
214 /*
215 * This is the necessary evil until the userspace driver is entirely
216 * self-sufficient.
217 */
[3193c05]218 sysinfo_set_item_val("fb.kind", NULL, 6);
[a71c158]219
220 fb_exported = true;
221 }
222
223 return skidev;
224}
225
226ski_instance_t *skiin_init(void)
227{
228 ski_init();
[c2417bc]229 return instance;
[c640876]230}
[6095342]231
[c2417bc]232void skiin_wire(ski_instance_t *instance, indev_t *srlnin)
[c640876]233{
[c2417bc]234 ASSERT(instance);
235 ASSERT(srlnin);
236
237 instance->srlnin = srlnin;
238 thread_ready(instance->thread);
239
[de57e060]240 sysinfo_set_item_val("kbd", NULL, true);
[323a5aaf]241 sysinfo_set_item_val("kbd.type", NULL, KBD_SKI);
[de57e060]242}
243
[06e1e95]244/** @}
[b45c443]245 */
Note: See TracBrowser for help on using the repository browser.