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

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

simplify configuration
introduce arch_construct_function and inb/outb (sometimes empty) on all platforms
various code cleanup

  • Property mode set to 100644
File size: 6.0 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
[06e1e95]29/** @addtogroup ia64
[b45c443]30 * @{
31 */
32/** @file
33 */
34
[244f284]35#include <arch/ski/ski.h>
[6095342]36#include <console/console.h>
37#include <console/chardev.h>
[d0c5901]38#include <arch/interrupt.h>
39#include <sysinfo/sysinfo.h>
[de57e060]40#include <arch/types.h>
41#include <ddi/device.h>
42#include <ddi/irq.h>
43#include <ipc/irq.h>
[f0450658]44#include <proc/thread.h>
[de57e060]45#include <synch/spinlock.h>
46#include <arch/asm.h>
[50b3d30]47#include <arch/drivers/kbd.h>
[de57e060]48
[6da1013f]49#define SKI_KBD_INR 0
[de57e060]50
51static irq_t ski_kbd_irq;
52static devno_t ski_kbd_devno;
[244f284]53
[d0c5901]54chardev_t ski_console;
55chardev_t ski_uconsole;
[de57e060]56
57static bool kbd_disabled;
[244f284]58
[eb43679]59/** Display character on debug console
60 *
61 * Use SSC (Simulator System Call) to
62 * display character on debug console.
63 *
[72f5866d]64 * @param d Character device.
65 * @param ch Character to be printed.
[eb43679]66 */
[516ff92]67static void ski_putchar(chardev_t *d, const char ch, bool silent)
[244f284]68{
[516ff92]69 if (!silent) {
70 asm volatile (
71 "mov r15 = %0\n"
72 "mov r32 = %1\n" /* r32 is in0 */
73 "break 0x80000\n" /* modifies r8 */
74 :
75 : "i" (SKI_PUTCHAR), "r" (ch)
76 : "r15", "in0", "r8"
77 );
78
79 if (ch == '\n')
[108a60f9]80 ski_putchar(d, '\r', false);
[516ff92]81 }
[244f284]82}
[a8c48241]83
[880de6e]84/** Ask debug console if a key was pressed.
[a8c48241]85 *
86 * Use SSC (Simulator System Call) to
87 * get character from debug console.
[880de6e]88 *
89 * This call is non-blocking.
90 *
91 * @return ASCII code of pressed key or 0 if no key pressed.
[a8c48241]92 */
[516ff92]93static int32_t ski_getchar(void)
[a8c48241]94{
[7f1c620]95 uint64_t ch;
[a8c48241]96
[e7b7be3f]97 asm volatile (
[de57e060]98 "mov r15 = %1\n"
[a8c48241]99 "break 0x80000;;\n" /* modifies r8 */
[de57e060]100 "mov %0 = r8;;\n"
[a8c48241]101
[5bb20ec]102 : "=r" (ch)
103 : "i" (SKI_GETCHAR)
[de57e060]104 : "r15", "r8"
[a8c48241]105 );
106
[7f1c620]107 return (int32_t) ch;
[a8c48241]108}
[6095342]109
[4a2b52f]110/**
[481c520]111 * This is a blocking wrapper for ski_getchar().
112 * To be used when the kernel crashes.
113 */
[4a2b52f]114static char ski_getchar_blocking(chardev_t *d)
115{
[481c520]116 int ch;
[6da1013f]117
118 while(!(ch = ski_getchar()));
119
[666773c]120 if (ch == '\r')
[481c520]121 ch = '\n';
[4a2b52f]122 return (char) ch;
123}
124
[6095342]125/** Ask keyboard if a key was pressed. */
[f0450658]126static void poll_keyboard(void)
[6095342]127{
128 char ch;
[8adafa0]129 static char last;
[de57e060]130 ipl_t ipl;
[6da1013f]131
[de57e060]132 ipl = interrupts_disable();
[6da1013f]133
[de57e060]134 if (kbd_disabled) {
135 interrupts_restore(ipl);
[6095342]136 return;
[de57e060]137 }
[6da1013f]138
[de57e060]139 spinlock_lock(&ski_kbd_irq.lock);
[6da1013f]140
[6095342]141 ch = ski_getchar();
142 if(ch == '\r')
143 ch = '\n';
[de57e060]144 if (ch) {
[666773c]145 if (ski_kbd_irq.notif_cfg.notify &&
146 ski_kbd_irq.notif_cfg.answerbox) {
[d0c5901]147 chardev_push_character(&ski_uconsole, ch);
[de57e060]148 ipc_irq_send_notif(&ski_kbd_irq);
149 } else {
[d0c5901]150 chardev_push_character(&ski_console, ch);
[8adafa0]151 }
[de57e060]152 last = ch;
153 spinlock_unlock(&ski_kbd_irq.lock);
154 interrupts_restore(ipl);
[8adafa0]155 return;
[de57e060]156 }
[d0c5901]157
[de57e060]158 if (last) {
[666773c]159 if (ski_kbd_irq.notif_cfg.notify &&
160 ski_kbd_irq.notif_cfg.answerbox) {
[8adafa0]161 chardev_push_character(&ski_uconsole, 0);
[de57e060]162 ipc_irq_send_notif(&ski_kbd_irq);
[8adafa0]163 }
[de57e060]164 last = 0;
165 }
[8adafa0]166
[de57e060]167 spinlock_unlock(&ski_kbd_irq.lock);
168 interrupts_restore(ipl);
[6095342]169}
170
171/* Called from getc(). */
[de57e060]172static void ski_kbd_enable(chardev_t *d)
[6095342]173{
[de57e060]174 kbd_disabled = false;
[6095342]175}
176
177/* Called from getc(). */
[de57e060]178static void ski_kbd_disable(chardev_t *d)
[6095342]179{
[6da1013f]180 kbd_disabled = true;
[de57e060]181}
182
183/** Decline to service hardware IRQ.
184 *
185 * This is only a virtual IRQ, so always decline.
186 *
187 * @return Always IRQ_DECLINE.
188 */
189static irq_ownership_t ski_kbd_claim(void)
190{
191 return IRQ_DECLINE;
[6095342]192}
193
194static chardev_operations_t ski_ops = {
[de57e060]195 .resume = ski_kbd_enable,
196 .suspend = ski_kbd_disable,
[4a2b52f]197 .write = ski_putchar,
198 .read = ski_getchar_blocking
[6095342]199};
200
201/** Initialize debug console
202 *
203 * Issue SSC (Simulator System Call) to
204 * to open debug console.
205 */
206void ski_init_console(void)
207{
[e7b7be3f]208 asm volatile (
[de57e060]209 "mov r15 = %0\n"
[6095342]210 "break 0x80000\n"
211 :
212 : "i" (SKI_INIT_CONSOLE)
213 : "r15", "r8"
214 );
215
216 chardev_initialize("ski_console", &ski_console, &ski_ops);
[d0c5901]217 chardev_initialize("ski_uconsole", &ski_uconsole, &ski_ops);
[6095342]218 stdin = &ski_console;
219 stdout = &ski_console;
[d0c5901]220
[de57e060]221 ski_kbd_devno = device_assign_devno();
222
223 irq_initialize(&ski_kbd_irq);
224 ski_kbd_irq.inr = SKI_KBD_INR;
225 ski_kbd_irq.devno = ski_kbd_devno;
226 ski_kbd_irq.claim = ski_kbd_claim;
227 irq_register(&ski_kbd_irq);
228
229 sysinfo_set_item_val("kbd", NULL, true);
230 sysinfo_set_item_val("kbd.inr", NULL, SKI_KBD_INR);
231 sysinfo_set_item_val("kbd.devno", NULL, ski_kbd_devno);
[323a5aaf]232 sysinfo_set_item_val("kbd.type", NULL, KBD_SKI);
[36251c6]233
234 sysinfo_set_item_val("fb", NULL, false);
[de57e060]235}
236
237void ski_kbd_grab(void)
238{
[3dea17f]239 ipl_t ipl = interrupts_disable();
240 spinlock_lock(&ski_kbd_irq.lock);
[de57e060]241 ski_kbd_irq.notif_cfg.notify = false;
[3dea17f]242 spinlock_unlock(&ski_kbd_irq.lock);
243 interrupts_restore(ipl);
[de57e060]244}
245
246void ski_kbd_release(void)
247{
[3dea17f]248 ipl_t ipl = interrupts_disable();
249 spinlock_lock(&ski_kbd_irq.lock);
[de57e060]250 if (ski_kbd_irq.notif_cfg.answerbox)
251 ski_kbd_irq.notif_cfg.notify = true;
[3dea17f]252 spinlock_unlock(&ski_kbd_irq.lock);
253 interrupts_restore(ipl);
[6095342]254}
[b45c443]255
[f0450658]256
257#define POLL_INTERVAL 50000 /* 50 ms */
258
259/** Kernel thread for polling keyboard. */
260void kkbdpoll(void *arg)
261{
262 while (1) {
263 poll_keyboard();
264 thread_usleep(POLL_INTERVAL);
265 }
266}
267
[06e1e95]268/** @}
[b45c443]269 */
Note: See TracBrowser for help on using the repository browser.