Changeset 2270bef in mainline for kernel/arch/ia64/src/ski/ski.c


Ignore:
Timestamp:
2009-03-08T14:05:42Z (16 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b0b5628
Parents:
0af8bcd
Message:

Clean up ski handling in kernel.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/ia64/src/ski/ski.c

    r0af8bcd r2270bef  
    3636#include <console/console.h>
    3737#include <console/chardev.h>
    38 #include <arch/interrupt.h>
    3938#include <sysinfo/sysinfo.h>
    4039#include <arch/types.h>
    41 #include <ddi/device.h>
    42 #include <ddi/irq.h>
    43 #include <ipc/irq.h>
    4440#include <proc/thread.h>
    4541#include <synch/spinlock.h>
    4642#include <arch/asm.h>
    4743#include <arch/drivers/kbd.h>
     44#include <arch.h>
    4845
    49 #define SKI_KBD_INR  0
     46static chardev_t *skiout;
    5047
    51 static irq_t ski_kbd_irq;
    52 static devno_t ski_kbd_devno;
    53 
    54 chardev_t ski_console;
    55 chardev_t ski_uconsole;
     48static chardev_t ski_stdout;
    5649
    5750static bool kbd_disabled;
     
    8275}
    8376
     77static chardev_operations_t ski_ops = {
     78        .write = ski_putchar
     79};
     80
    8481/** Ask debug console if a key was pressed.
    8582 *
     
    108105}
    109106
    110 /**
    111  * This is a blocking wrapper for ski_getchar().
    112  * To be used when the kernel crashes.
    113  */
    114 static char ski_getchar_blocking(chardev_t *d)
    115 {
    116         int ch;
    117        
    118         while(!(ch = ski_getchar()));
    119        
    120         if (ch == '\r')
    121                 ch = '\n';
    122         return (char) ch;
    123 }
    124 
    125107/** Ask keyboard if a key was pressed. */
    126108static void poll_keyboard(void)
    127109{
    128110        char ch;
    129         static char last;
    130111        ipl_t ipl;
    131112       
     
    137118        }
    138119       
    139         spinlock_lock(&ski_kbd_irq.lock);
    140        
    141120        ch = ski_getchar();
    142121        if(ch == '\r')
    143122                ch = '\n';
    144         if (ch) {
    145                 if (ski_kbd_irq.notif_cfg.notify &&
    146                     ski_kbd_irq.notif_cfg.answerbox) {
    147                         chardev_push_character(&ski_uconsole, ch);
    148                         /* XXX: send notification to userspace */
    149                 } else {
    150                         chardev_push_character(&ski_console, ch);
    151                 }       
    152                 last = ch;
    153                 spinlock_unlock(&ski_kbd_irq.lock);
     123        if (ch && skiout) {
     124                chardev_push_character(skiout, ch);
    154125                interrupts_restore(ipl);
    155126                return;
    156127        }
    157128
    158         if (last) {
    159                 if (ski_kbd_irq.notif_cfg.notify &&
    160                     ski_kbd_irq.notif_cfg.answerbox) {
    161                         chardev_push_character(&ski_uconsole, 0);
    162                         /* XXX: send notification to userspace */
    163                 }
    164                 last = 0;
    165         }
    166 
    167         spinlock_unlock(&ski_kbd_irq.lock);
    168129        interrupts_restore(ipl);
    169130}
    170131
    171 /* Called from getc(). */
    172 static void ski_kbd_enable(chardev_t *d)
     132#define POLL_INTERVAL           10000           /* 10 ms */
     133
     134/** Kernel thread for polling keyboard. */
     135static void kkbdpoll(void *arg)
    173136{
    174         kbd_disabled = false;
     137        while (1) {
     138                if (!silent) {
     139                        poll_keyboard();
     140                }
     141                thread_usleep(POLL_INTERVAL);
     142        }
    175143}
    176 
    177 /* Called from getc(). */
    178 static void ski_kbd_disable(chardev_t *d)
    179 {
    180         kbd_disabled = true;
    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  */
    189 static irq_ownership_t ski_kbd_claim(irq_t *irq)
    190 {
    191         return IRQ_DECLINE;
    192 }
    193 
    194 static chardev_operations_t ski_ops = {
    195         .resume = ski_kbd_enable,
    196         .suspend = ski_kbd_disable,
    197         .write = ski_putchar,
    198         .read = ski_getchar_blocking
    199 };
    200144
    201145/** Initialize debug console
     
    204148 * to open debug console.
    205149 */
    206 void ski_init_console(void)
     150void ski_console_init(chardev_t *devout)
    207151{
    208152        asm volatile (
     
    214158        );
    215159
    216         chardev_initialize("ski_console", &ski_console, &ski_ops);
    217         chardev_initialize("ski_uconsole", &ski_uconsole, &ski_ops);
    218         stdin = &ski_console;
    219         stdout = &ski_console;
     160        skiout = devout;
     161        chardev_initialize("ski_stdout", &ski_stdout, &ski_ops);
     162        stdout = &ski_stdout;
    220163
    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);
     164        thread_t *t = thread_create(kkbdpoll, NULL, TASK, 0, "kkbdpoll", true);
     165        if (!t)
     166                panic("Cannot create kkbdpoll.");
     167        thread_ready(t);
    228168
    229169        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);
    232170        sysinfo_set_item_val("kbd.type", NULL, KBD_SKI);
    233171
     
    237175void ski_kbd_grab(void)
    238176{
    239         ipl_t ipl = interrupts_disable();
    240         spinlock_lock(&ski_kbd_irq.lock);
    241         ski_kbd_irq.notif_cfg.notify = false;
    242         spinlock_unlock(&ski_kbd_irq.lock);
    243         interrupts_restore(ipl);
     177        kbd_disabled = true;
    244178}
    245179
    246180void ski_kbd_release(void)
    247181{
    248         ipl_t ipl = interrupts_disable();
    249         spinlock_lock(&ski_kbd_irq.lock);
    250         if (ski_kbd_irq.notif_cfg.answerbox)
    251                 ski_kbd_irq.notif_cfg.notify = true;
    252         spinlock_unlock(&ski_kbd_irq.lock);
    253         interrupts_restore(ipl);
    254 }
    255 
    256 
    257 #define POLL_INTERVAL           50000           /* 50 ms */
    258 
    259 /** Kernel thread for polling keyboard. */
    260 void kkbdpoll(void *arg)
    261 {
    262         while (1) {
    263                 if (!silent) {
    264                         poll_keyboard();
    265                 }
    266                 thread_usleep(POLL_INTERVAL);
    267         }
     182        kbd_disabled = false;
    268183}
    269184
Note: See TracChangeset for help on using the changeset viewer.