Subversion Repositories HelenOS

Rev

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

Rev 4344 Rev 4346
Line 33... Line 33...
33
 */
33
 */
34
 
34
 
35
#include <arch/ski/ski.h>
35
#include <arch/ski/ski.h>
36
#include <console/console.h>
36
#include <console/console.h>
37
#include <console/chardev.h>
37
#include <console/chardev.h>
38
#include <arch/interrupt.h>
-
 
39
#include <sysinfo/sysinfo.h>
38
#include <sysinfo/sysinfo.h>
40
#include <arch/types.h>
39
#include <arch/types.h>
41
#include <ddi/device.h>
-
 
42
#include <ddi/irq.h>
-
 
43
#include <ipc/irq.h>
-
 
44
#include <proc/thread.h>
40
#include <proc/thread.h>
45
#include <synch/spinlock.h>
41
#include <synch/spinlock.h>
46
#include <arch/asm.h>
42
#include <arch/asm.h>
47
#include <arch/drivers/kbd.h>
43
#include <arch/drivers/kbd.h>
-
 
44
#include <arch.h>
48
 
45
 
49
#define SKI_KBD_INR  0
-
 
50
 
-
 
51
static irq_t ski_kbd_irq;
46
static indev_t skiin;       /**< Ski input device. */
52
static devno_t ski_kbd_devno;
47
static outdev_t skiout;     /**< Ski output device. */
53
 
-
 
54
chardev_t ski_console;
-
 
55
chardev_t ski_uconsole;
-
 
56
 
48
 
57
static bool kbd_disabled;
49
static bool kbd_disabled;
58
 
50
 
59
/** Display character on debug console
51
/** Display character on debug console
60
 *
52
 *
Line 62... Line 54...
62
 * display character on debug console.
54
 * display character on debug console.
63
 *
55
 *
64
 * @param d Character device.
56
 * @param d Character device.
65
 * @param ch Character to be printed.
57
 * @param ch Character to be printed.
66
 */
58
 */
67
static void ski_putchar(chardev_t *d, const char ch, bool silent)
59
static void ski_putchar(outdev_t *d, const char ch, bool silent)
68
{
60
{
69
    if (!silent) {
61
    if (!silent) {
70
        asm volatile (
62
        asm volatile (
71
            "mov r15 = %0\n"
63
            "mov r15 = %0\n"
72
            "mov r32 = %1\n"   /* r32 is in0 */
64
            "mov r32 = %1\n"   /* r32 is in0 */
Line 79... Line 71...
79
        if (ch == '\n')
71
        if (ch == '\n')
80
            ski_putchar(d, '\r', false);
72
            ski_putchar(d, '\r', false);
81
    }
73
    }
82
}
74
}
83
 
75
 
-
 
76
static indev_operations_t skiin_ops = {
-
 
77
    .poll = NULL
-
 
78
};
-
 
79
 
-
 
80
static outdev_operations_t skiout_ops = {
-
 
81
    .write = ski_putchar
-
 
82
};
-
 
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
87
 * get character from debug console.
87
 * get character from debug console.
88
 *
88
 *
Line 105... Line 105...
105
    );
105
    );
106
 
106
 
107
    return (int32_t) ch;
107
    return (int32_t) ch;
108
}
108
}
109
 
109
 
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
 
-
 
125
/** Ask keyboard if a key was pressed. */
110
/** Ask keyboard if a key was pressed. */
126
static void poll_keyboard(void)
111
static void poll_keyboard(void)
127
{
112
{
128
    char ch;
113
    char ch;
129
    static char last;
-
 
130
    ipl_t ipl;
-
 
131
   
-
 
132
    ipl = interrupts_disable();
-
 
133
   
114
   
134
    if (kbd_disabled) {
115
    if (kbd_disabled)
135
        interrupts_restore(ipl);
-
 
136
        return;
116
        return;
137
    }
-
 
138
   
-
 
139
    spinlock_lock(&ski_kbd_irq.lock);
-
 
140
   
-
 
141
    ch = ski_getchar();
117
    ch = ski_getchar();
142
    if(ch == '\r')
118
    if(ch == '\r')
143
        ch = '\n';
119
        ch = '\n';
144
    if (ch) {
120
    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);
121
        indev_push_character(&skiin, ch);
151
        }  
-
 
152
        last = ch;
-
 
153
        spinlock_unlock(&ski_kbd_irq.lock);
-
 
154
        interrupts_restore(ipl);
-
 
155
        return;
122
        return;
156
    }
123
    }
157
 
-
 
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);
-
 
168
    interrupts_restore(ipl);
-
 
169
}
124
}
170
 
125
 
171
/* Called from getc(). */
-
 
172
static void ski_kbd_enable(chardev_t *d)
126
#define POLL_INTERVAL           10000           /* 10 ms */
173
{
-
 
174
    kbd_disabled = false;
-
 
175
}
-
 
176
 
127
 
177
/* Called from getc(). */
128
/** Kernel thread for polling keyboard. */
178
static void ski_kbd_disable(chardev_t *d)
129
static void kkbdpoll(void *arg)
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
{
130
{
-
 
131
    while (1) {
-
 
132
        if (!silent) {
-
 
133
            poll_keyboard();
-
 
134
        }
191
    return IRQ_DECLINE;
135
        thread_usleep(POLL_INTERVAL);
-
 
136
    }
192
}
137
}
193
 
138
 
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
};
-
 
200
 
-
 
201
/** Initialize debug console
139
/** Initialize debug console
202
 *
140
 *
203
 * Issue SSC (Simulator System Call) to
141
 * Issue SSC (Simulator System Call) to
204
 * to open debug console.
142
 * to open debug console.
205
 */
143
 */
206
void ski_init_console(void)
144
static void ski_init(void)
207
{
145
{
-
 
146
    static bool initialized;
-
 
147
 
-
 
148
    if (initialized)
-
 
149
        return;
-
 
150
   
208
    asm volatile (
151
    asm volatile (
209
        "mov r15 = %0\n"
152
        "mov r15 = %0\n"
210
        "break 0x80000\n"
153
        "break 0x80000\n"
211
        :
154
        :
212
        : "i" (SKI_INIT_CONSOLE)
155
        : "i" (SKI_INIT_CONSOLE)
213
        : "r15", "r8"
156
        : "r15", "r8"
214
    );
157
    );
-
 
158
   
-
 
159
    initialized = true;
-
 
160
}
215
 
161
 
216
    chardev_initialize("ski_console", &ski_console, &ski_ops);
-
 
217
    chardev_initialize("ski_uconsole", &ski_uconsole, &ski_ops);
-
 
218
    stdin = &ski_console;
162
indev_t *skiin_init(void)
-
 
163
{
219
    stdout = &ski_console;
164
    ski_init();
220
 
165
 
221
    ski_kbd_devno = device_assign_devno();
166
    indev_initialize("skiin", &skiin, &skiin_ops);
222
   
-
 
223
    irq_initialize(&ski_kbd_irq);
167
    thread_t *t = thread_create(kkbdpoll, NULL, TASK, 0, "kkbdpoll", true);
224
    ski_kbd_irq.inr = SKI_KBD_INR;
168
    if (t)
225
    ski_kbd_irq.devno = ski_kbd_devno;
169
        thread_ready(t);
226
    ski_kbd_irq.claim = ski_kbd_claim;
170
    else
227
    irq_register(&ski_kbd_irq);
171
        return NULL;
228
 
172
 
229
    sysinfo_set_item_val("kbd", NULL, true);
173
    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);
-
 
232
    sysinfo_set_item_val("kbd.type", NULL, KBD_SKI);
174
    sysinfo_set_item_val("kbd.type", NULL, KBD_SKI);
233
 
175
 
234
    sysinfo_set_item_val("fb", NULL, false);
176
    return &skiin;
235
}
177
}
236
 
178
 
-
 
179
 
237
void ski_kbd_grab(void)
180
void skiout_init(void)
238
{
181
{
239
    ipl_t ipl = interrupts_disable();
182
    ski_init();
-
 
183
 
240
    spinlock_lock(&ski_kbd_irq.lock);
184
    outdev_initialize("skiout", &skiout, &skiout_ops);
241
    ski_kbd_irq.notif_cfg.notify = false;
185
    stdout = &skiout;
-
 
186
 
242
    spinlock_unlock(&ski_kbd_irq.lock);
187
    sysinfo_set_item_val("fb", NULL, false);
243
    interrupts_restore(ipl);
-
 
244
}
188
}
245
 
189
 
246
void ski_kbd_release(void)
190
void ski_kbd_grab(void)
247
{
191
{
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;
192
    kbd_disabled = true;
252
    spinlock_unlock(&ski_kbd_irq.lock);
-
 
253
    interrupts_restore(ipl);
-
 
254
}
193
}
255
 
194
 
256
 
-
 
257
#define POLL_INTERVAL       50000       /* 50 ms */
-
 
258
 
-
 
259
/** Kernel thread for polling keyboard. */
-
 
260
void kkbdpoll(void *arg)
195
void ski_kbd_release(void)
261
{
196
{
262
    while (1) {
-
 
263
        poll_keyboard();
197
    kbd_disabled = false;
264
        thread_usleep(POLL_INTERVAL);
-
 
265
    }
-
 
266
}
198
}
267
 
199
 
268
/** @}
200
/** @}
269
 */
201
 */