Subversion Repositories HelenOS

Rev

Rev 3022 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3022 Rev 4055
Line 42... Line 42...
42
#include <ddi/irq.h>
42
#include <ddi/irq.h>
43
#include <ipc/irq.h>
43
#include <ipc/irq.h>
44
#include <proc/thread.h>
44
#include <proc/thread.h>
45
#include <synch/spinlock.h>
45
#include <synch/spinlock.h>
46
#include <arch/asm.h>
46
#include <arch/asm.h>
-
 
47
#include <arch/drivers/kbd.h>
47
 
48
 
48
#define SKI_KBD_INR 0
49
#define SKI_KBD_INR  0
49
 
50
 
50
static irq_t ski_kbd_irq;
51
static irq_t ski_kbd_irq;
51
static devno_t ski_kbd_devno;
52
static devno_t ski_kbd_devno;
52
 
53
 
53
chardev_t ski_console;
54
chardev_t ski_console;
54
chardev_t ski_uconsole;
55
chardev_t ski_uconsole;
55
 
56
 
56
static bool kbd_disabled;
57
static bool kbd_disabled;
57
 
58
 
58
static void ski_putchar(chardev_t *d, const char ch);
-
 
59
static int32_t ski_getchar(void);
-
 
60
 
-
 
61
/** Display character on debug console
59
/** Display character on debug console
62
 *
60
 *
63
 * Use SSC (Simulator System Call) to
61
 * Use SSC (Simulator System Call) to
64
 * display character on debug console.
62
 * display character on debug console.
65
 *
63
 *
66
 * @param d Character device.
64
 * @param d Character device.
67
 * @param ch Character to be printed.
65
 * @param ch Character to be printed.
68
 */
66
 */
69
void ski_putchar(chardev_t *d, const char ch)
67
static void ski_putchar(chardev_t *d, const char ch, bool silent)
70
{
68
{
-
 
69
    if (!silent) {
71
    asm volatile (
70
        asm volatile (
72
        "mov r15 = %0\n"
71
            "mov r15 = %0\n"
73
        "mov r32 = %1\n"    /* r32 is in0 */
72
            "mov r32 = %1\n"   /* r32 is in0 */
74
        "break 0x80000\n"   /* modifies r8 */
73
            "break 0x80000\n"  /* modifies r8 */
75
        :
74
            :
76
        : "i" (SKI_PUTCHAR), "r" (ch)
75
            : "i" (SKI_PUTCHAR), "r" (ch)
77
        : "r15", "in0", "r8"
76
            : "r15", "in0", "r8"
78
    );
77
        );
79
   
78
       
80
    if (ch == '\n')
79
        if (ch == '\n')
81
        ski_putchar(d, '\r');
80
            ski_putchar(d, '\r', false);
-
 
81
    }
82
}
82
}
83
 
83
 
84
/** Ask debug console if a key was pressed.
84
/** Ask debug console if a key was pressed.
85
 *
85
 *
86
 * Use SSC (Simulator System Call) to
86
 * Use SSC (Simulator System Call) to
Line 88... Line 88...
88
 *
88
 *
89
 * This call is non-blocking.
89
 * This call is non-blocking.
90
 *
90
 *
91
 * @return ASCII code of pressed key or 0 if no key pressed.
91
 * @return ASCII code of pressed key or 0 if no key pressed.
92
 */
92
 */
93
int32_t ski_getchar(void)
93
static int32_t ski_getchar(void)
94
{
94
{
95
    uint64_t ch;
95
    uint64_t ch;
96
   
96
   
97
    asm volatile (
97
    asm volatile (
98
        "mov r15 = %1\n"
98
        "mov r15 = %1\n"
Line 112... Line 112...
112
 * To be used when the kernel crashes.
112
 * To be used when the kernel crashes.
113
 */
113
 */
114
static char ski_getchar_blocking(chardev_t *d)
114
static char ski_getchar_blocking(chardev_t *d)
115
{
115
{
116
    int ch;
116
    int ch;
117
 
117
   
118
    while(!(ch = ski_getchar()))
118
    while(!(ch = ski_getchar()));
119
        ;
119
   
120
    if(ch == '\r')
120
    if (ch == '\r')
121
        ch = '\n';
121
        ch = '\n';
122
    return (char) ch;
122
    return (char) ch;
123
}
123
}
124
 
124
 
125
/** Ask keyboard if a key was pressed. */
125
/** Ask keyboard if a key was pressed. */
126
static void poll_keyboard(void)
126
static void poll_keyboard(void)
127
{
127
{
128
    char ch;
128
    char ch;
129
    static char last;
129
    static char last;
130
    ipl_t ipl;
130
    ipl_t ipl;
131
 
131
   
132
    ipl = interrupts_disable();
132
    ipl = interrupts_disable();
133
 
133
   
134
    if (kbd_disabled) {
134
    if (kbd_disabled) {
135
        interrupts_restore(ipl);
135
        interrupts_restore(ipl);
136
        return;
136
        return;
137
    }
137
    }
138
       
138
   
139
    spinlock_lock(&ski_kbd_irq.lock);
139
    spinlock_lock(&ski_kbd_irq.lock);
140
 
140
   
141
    ch = ski_getchar();
141
    ch = ski_getchar();
142
    if(ch == '\r')
142
    if(ch == '\r')
143
        ch = '\n';
143
        ch = '\n';
144
    if (ch) {
144
    if (ch) {
-
 
145
        if (ski_kbd_irq.notif_cfg.notify &&
145
        if (ski_kbd_irq.notif_cfg.notify && ski_kbd_irq.notif_cfg.answerbox) {
146
            ski_kbd_irq.notif_cfg.answerbox) {
146
            chardev_push_character(&ski_uconsole, ch);
147
            chardev_push_character(&ski_uconsole, ch);
147
            ipc_irq_send_notif(&ski_kbd_irq);
148
            /* XXX: send notification to userspace */
148
        } else {
149
        } else {
149
            chardev_push_character(&ski_console, ch);
150
            chardev_push_character(&ski_console, ch);
150
        }  
151
        }  
151
        last = ch;
152
        last = ch;
152
        spinlock_unlock(&ski_kbd_irq.lock);
153
        spinlock_unlock(&ski_kbd_irq.lock);
153
        interrupts_restore(ipl);
154
        interrupts_restore(ipl);
154
        return;
155
        return;
155
    }
156
    }
156
 
157
 
157
    if (last) {
158
    if (last) {
-
 
159
        if (ski_kbd_irq.notif_cfg.notify &&
158
        if (ski_kbd_irq.notif_cfg.notify && ski_kbd_irq.notif_cfg.answerbox) {
160
            ski_kbd_irq.notif_cfg.answerbox) {
159
            chardev_push_character(&ski_uconsole, 0);
161
            chardev_push_character(&ski_uconsole, 0);
160
            ipc_irq_send_notif(&ski_kbd_irq);
162
            /* XXX: send notification to userspace */
161
        }
163
        }
162
        last = 0;
164
        last = 0;
163
    }
165
    }
164
 
166
 
165
    spinlock_unlock(&ski_kbd_irq.lock);
167
    spinlock_unlock(&ski_kbd_irq.lock);
Line 173... Line 175...
173
}
175
}
174
 
176
 
175
/* Called from getc(). */
177
/* Called from getc(). */
176
static void ski_kbd_disable(chardev_t *d)
178
static void ski_kbd_disable(chardev_t *d)
177
{
179
{
178
    kbd_disabled = true;   
180
    kbd_disabled = true;
179
}
181
}
180
 
182
 
181
/** Decline to service hardware IRQ.
183
/** Decline to service hardware IRQ.
182
 *
184
 *
183
 * This is only a virtual IRQ, so always decline.
185
 * This is only a virtual IRQ, so always decline.
184
 *
186
 *
185
 * @return Always IRQ_DECLINE.
187
 * @return Always IRQ_DECLINE.
186
 */
188
 */
187
static irq_ownership_t ski_kbd_claim(void)
189
static irq_ownership_t ski_kbd_claim(irq_t *irq)
188
{
190
{
189
    return IRQ_DECLINE;
191
    return IRQ_DECLINE;
190
}
192
}
191
 
193
 
192
static chardev_operations_t ski_ops = {
194
static chardev_operations_t ski_ops = {
Line 225... Line 227...
225
    irq_register(&ski_kbd_irq);
227
    irq_register(&ski_kbd_irq);
226
 
228
 
227
    sysinfo_set_item_val("kbd", NULL, true);
229
    sysinfo_set_item_val("kbd", NULL, true);
228
    sysinfo_set_item_val("kbd.inr", NULL, SKI_KBD_INR);
230
    sysinfo_set_item_val("kbd.inr", NULL, SKI_KBD_INR);
229
    sysinfo_set_item_val("kbd.devno", NULL, ski_kbd_devno);
231
    sysinfo_set_item_val("kbd.devno", NULL, ski_kbd_devno);
-
 
232
    sysinfo_set_item_val("kbd.type", NULL, KBD_SKI);
-
 
233
 
-
 
234
    sysinfo_set_item_val("fb", NULL, false);
230
}
235
}
231
 
236
 
232
void ski_kbd_grab(void)
237
void ski_kbd_grab(void)
233
{
238
{
234
    ipl_t ipl = interrupts_disable();
239
    ipl_t ipl = interrupts_disable();
Line 253... Line 258...
253
 
258
 
254
/** Kernel thread for polling keyboard. */
259
/** Kernel thread for polling keyboard. */
255
void kkbdpoll(void *arg)
260
void kkbdpoll(void *arg)
256
{
261
{
257
    while (1) {
262
    while (1) {
-
 
263
        if (!silent) {
258
        poll_keyboard();
264
            poll_keyboard();
-
 
265
        }
259
        thread_usleep(POLL_INTERVAL);
266
        thread_usleep(POLL_INTERVAL);
260
    }
267
    }
261
}
268
}
262
 
269
 
263
/** @}
270
/** @}