Subversion Repositories HelenOS

Rev

Rev 1787 | Rev 1932 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1787 Rev 1928
1
/*
1
/*
2
 * Copyright (C) 2006 Martin Decky
2
 * Copyright (C) 2006 Martin Decky
3
 * All rights reserved.
3
 * All rights reserved.
4
 *
4
 *
5
 * Redistribution and use in source and binary forms, with or without
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
6
 * modification, are permitted provided that the following conditions
7
 * are met:
7
 * are met:
8
 *
8
 *
9
 * - Redistributions of source code must retain the above copyright
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
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
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.
15
 *   derived from this software without specific prior written permission.
16
 *
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
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
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
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
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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
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.
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
27
 */
28
 
28
 
29
/** @addtogroup ppc32  
29
/** @addtogroup ppc32  
30
 * @{
30
 * @{
31
 */
31
 */
32
/** @file
32
/** @file
33
 */
33
 */
34
 
34
 
35
#include <arch/drivers/cuda.h>
35
#include <arch/drivers/cuda.h>
-
 
36
#include <ddi/irq.h>
36
#include <arch/asm.h>
37
#include <arch/asm.h>
37
#include <console/console.h>
38
#include <console/console.h>
38
#include <console/chardev.h>
39
#include <console/chardev.h>
39
#include <arch/drivers/pic.h>
40
#include <arch/drivers/pic.h>
40
#include <sysinfo/sysinfo.h>
41
#include <sysinfo/sysinfo.h>
41
#include <interrupt.h>
42
#include <interrupt.h>
42
#include <stdarg.h>
43
#include <stdarg.h>
43
 
44
 
-
 
45
#define CUDA_IRQ 10
44
#define SPECIAL     '?'
46
#define SPECIAL     '?'
45
 
47
 
46
#define PACKET_ADB  0x00
48
#define PACKET_ADB  0x00
47
#define PACKET_CUDA 0x01
49
#define PACKET_CUDA 0x01
48
 
50
 
49
#define CUDA_POWERDOWN 0x0a
51
#define CUDA_POWERDOWN 0x0a
50
 
52
 
51
#define RS 0x200
53
#define RS 0x200
52
#define B (0 * RS)
54
#define B (0 * RS)
53
#define A (1 * RS)
55
#define A (1 * RS)
54
#define SR (10 * RS)
56
#define SR (10 * RS)
55
#define ACR (11 * RS)
57
#define ACR (11 * RS)
56
 
58
 
57
#define SR_OUT 0x10
59
#define SR_OUT 0x10
58
#define TACK 0x10
60
#define TACK 0x10
59
#define TIP 0x20
61
#define TIP 0x20
60
 
62
 
61
 
63
 
62
static volatile uint8_t *cuda = NULL;
64
static volatile uint8_t *cuda = NULL;
-
 
65
static irq_t cuda_irq;      /**< Cuda's IRQ. */
-
 
66
 
63
static iroutine vector;
67
static ipc_notif_cfg_t saved_notif_cfg;
64
 
68
 
65
 
69
 
66
static char lchars[0x80] = {
70
static char lchars[0x80] = {
67
    'a',
71
    'a',
68
    's',
72
    's',
69
    'd',
73
    'd',
70
    'f',
74
    'f',
71
    'h',
75
    'h',
72
    'g',
76
    'g',
73
    'z',
77
    'z',
74
    'x',
78
    'x',
75
    'c',
79
    'c',
76
    'v',
80
    'v',
77
    SPECIAL,
81
    SPECIAL,
78
    'b',
82
    'b',
79
    'q',
83
    'q',
80
    'w',
84
    'w',
81
    'e',
85
    'e',
82
    'r',
86
    'r',
83
    'y',
87
    'y',
84
    't',
88
    't',
85
    '1',
89
    '1',
86
    '2',
90
    '2',
87
    '3',
91
    '3',
88
    '4',
92
    '4',
89
    '6',
93
    '6',
90
    '5',
94
    '5',
91
    '=',
95
    '=',
92
    '9',
96
    '9',
93
    '7',
97
    '7',
94
    '-',
98
    '-',
95
    '8',
99
    '8',
96
    '0',
100
    '0',
97
    ']',
101
    ']',
98
    'o',
102
    'o',
99
    'u',
103
    'u',
100
    '[',
104
    '[',
101
    'i',
105
    'i',
102
    'p',
106
    'p',
103
    '\n',    /* Enter */
107
    '\n',    /* Enter */
104
    'l',
108
    'l',
105
    'j',
109
    'j',
106
    '\'',
110
    '\'',
107
    'k',
111
    'k',
108
    ';',
112
    ';',
109
    '\\',
113
    '\\',
110
    ',',
114
    ',',
111
    '/',
115
    '/',
112
    'n',
116
    'n',
113
    'm',
117
    'm',
114
    '.',
118
    '.',
115
    '\t',    /* Tab */
119
    '\t',    /* Tab */
116
    ' ',
120
    ' ',
117
    '`',
121
    '`',
118
    '\b',    /* Backspace */
122
    '\b',    /* Backspace */
119
    SPECIAL,
123
    SPECIAL,
120
    SPECIAL, /* Escape */
124
    SPECIAL, /* Escape */
121
    SPECIAL, /* Ctrl */
125
    SPECIAL, /* Ctrl */
122
    SPECIAL, /* Alt */
126
    SPECIAL, /* Alt */
123
    SPECIAL, /* Shift */
127
    SPECIAL, /* Shift */
124
    SPECIAL, /* Caps-Lock */
128
    SPECIAL, /* Caps-Lock */
125
    SPECIAL, /* RAlt */
129
    SPECIAL, /* RAlt */
126
    SPECIAL, /* Left */
130
    SPECIAL, /* Left */
127
    SPECIAL, /* Right */
131
    SPECIAL, /* Right */
128
    SPECIAL, /* Down */
132
    SPECIAL, /* Down */
129
    SPECIAL, /* Up */
133
    SPECIAL, /* Up */
130
    SPECIAL,
134
    SPECIAL,
131
    SPECIAL,
135
    SPECIAL,
132
    '.',     /* Keypad . */
136
    '.',     /* Keypad . */
133
    SPECIAL,
137
    SPECIAL,
134
    '*',     /* Keypad * */
138
    '*',     /* Keypad * */
135
    SPECIAL,
139
    SPECIAL,
136
    '+',     /* Keypad + */
140
    '+',     /* Keypad + */
137
    SPECIAL,
141
    SPECIAL,
138
    SPECIAL, /* NumLock */
142
    SPECIAL, /* NumLock */
139
    SPECIAL,
143
    SPECIAL,
140
    SPECIAL,
144
    SPECIAL,
141
    SPECIAL,
145
    SPECIAL,
142
    '/',     /* Keypad / */
146
    '/',     /* Keypad / */
143
    '\n',    /* Keypad Enter */
147
    '\n',    /* Keypad Enter */
144
    SPECIAL,
148
    SPECIAL,
145
    '-',     /* Keypad - */
149
    '-',     /* Keypad - */
146
    SPECIAL,
150
    SPECIAL,
147
    SPECIAL,
151
    SPECIAL,
148
    SPECIAL,
152
    SPECIAL,
149
    '0',     /* Keypad 0 */
153
    '0',     /* Keypad 0 */
150
    '1',     /* Keypad 1 */
154
    '1',     /* Keypad 1 */
151
    '2',     /* Keypad 2 */
155
    '2',     /* Keypad 2 */
152
    '3',     /* Keypad 3 */
156
    '3',     /* Keypad 3 */
153
    '4',     /* Keypad 4 */
157
    '4',     /* Keypad 4 */
154
    '5',     /* Keypad 5 */
158
    '5',     /* Keypad 5 */
155
    '6',     /* Keypad 6 */
159
    '6',     /* Keypad 6 */
156
    '7',     /* Keypad 7 */
160
    '7',     /* Keypad 7 */
157
    SPECIAL,
161
    SPECIAL,
158
    '8',     /* Keypad 8 */
162
    '8',     /* Keypad 8 */
159
    '9',     /* Keypad 9 */
163
    '9',     /* Keypad 9 */
160
    SPECIAL,
164
    SPECIAL,
161
    SPECIAL,
165
    SPECIAL,
162
    SPECIAL,
166
    SPECIAL,
163
    SPECIAL, /* F5 */
167
    SPECIAL, /* F5 */
164
    SPECIAL, /* F6 */
168
    SPECIAL, /* F6 */
165
    SPECIAL, /* F7 */
169
    SPECIAL, /* F7 */
166
    SPECIAL, /* F3 */
170
    SPECIAL, /* F3 */
167
    SPECIAL, /* F8 */
171
    SPECIAL, /* F8 */
168
    SPECIAL, /* F9 */
172
    SPECIAL, /* F9 */
169
    SPECIAL,
173
    SPECIAL,
170
    SPECIAL, /* F11 */
174
    SPECIAL, /* F11 */
171
    SPECIAL,
175
    SPECIAL,
172
    SPECIAL, /* F13 */
176
    SPECIAL, /* F13 */
173
    SPECIAL,
177
    SPECIAL,
174
    SPECIAL, /* ScrollLock */
178
    SPECIAL, /* ScrollLock */
175
    SPECIAL,
179
    SPECIAL,
176
    SPECIAL, /* F10 */
180
    SPECIAL, /* F10 */
177
    SPECIAL,
181
    SPECIAL,
178
    SPECIAL, /* F12 */
182
    SPECIAL, /* F12 */
179
    SPECIAL,
183
    SPECIAL,
180
    SPECIAL, /* Pause */
184
    SPECIAL, /* Pause */
181
    SPECIAL, /* Insert */
185
    SPECIAL, /* Insert */
182
    SPECIAL, /* Home */
186
    SPECIAL, /* Home */
183
    SPECIAL, /* PageUp */
187
    SPECIAL, /* PageUp */
184
    SPECIAL, /* Delete */
188
    SPECIAL, /* Delete */
185
    SPECIAL, /* F4 */
189
    SPECIAL, /* F4 */
186
    SPECIAL, /* End */
190
    SPECIAL, /* End */
187
    SPECIAL, /* F2 */
191
    SPECIAL, /* F2 */
188
    SPECIAL, /* PageDown */
192
    SPECIAL, /* PageDown */
189
    SPECIAL  /* F1 */
193
    SPECIAL  /* F1 */
190
};
194
};
191
 
195
 
192
 
196
 
193
void send_packet(const uint8_t kind, index_t count, ...);
197
void send_packet(const uint8_t kind, index_t count, ...);
194
 
198
 
195
 
199
 
196
static void receive_packet(uint8_t *kind, index_t count, uint8_t data[])
200
static void receive_packet(uint8_t *kind, index_t count, uint8_t data[])
197
{
201
{
198
    cuda[B] = cuda[B] & ~TIP;
202
    cuda[B] = cuda[B] & ~TIP;
199
    *kind = cuda[SR];
203
    *kind = cuda[SR];
200
   
204
   
201
    index_t i;
205
    index_t i;
202
    for (i = 0; i < count; i++)
206
    for (i = 0; i < count; i++)
203
        data[i] = cuda[SR];
207
        data[i] = cuda[SR];
204
   
208
   
205
    cuda[B] = cuda[B] | TIP;
209
    cuda[B] = cuda[B] | TIP;
206
}
210
}
207
 
211
 
208
 
212
 
209
/* Called from getc(). */
213
/* Called from getc(). */
210
static void cuda_resume(chardev_t *d)
214
static void cuda_resume(chardev_t *d)
211
{
215
{
212
}
216
}
213
 
217
 
214
 
218
 
215
/* Called from getc(). */
219
/* Called from getc(). */
216
static void cuda_suspend(chardev_t *d)
220
static void cuda_suspend(chardev_t *d)
217
{
221
{
218
}
222
}
219
 
223
 
220
 
224
 
221
static char key_read(chardev_t *d)
225
static char key_read(chardev_t *d)
222
{
226
{
223
    char ch;
227
    char ch;
224
   
228
   
225
    ch = 0;
229
    ch = 0;
226
    return ch;
230
    return ch;
227
}
231
}
228
 
232
 
229
 
233
 
230
static chardev_t kbrd;
234
static chardev_t kbrd;
231
static chardev_operations_t ops = {
235
static chardev_operations_t ops = {
232
    .suspend = cuda_suspend,
236
    .suspend = cuda_suspend,
233
    .resume = cuda_resume,
237
    .resume = cuda_resume,
234
    .read = key_read
238
    .read = key_read
235
};
239
};
236
 
240
 
237
 
241
 
238
int cuda_get_scancode(void)
242
int cuda_get_scancode(void)
239
{
243
{
240
    uint8_t kind;
244
    uint8_t kind;
241
    uint8_t data[4];
245
    uint8_t data[4];
242
   
246
   
243
    receive_packet(&kind, 4, data);
247
    receive_packet(&kind, 4, data);
244
   
248
   
245
    if ((kind == PACKET_ADB) && (data[0] == 0x40) && (data[1] == 0x2c))
249
    if ((kind == PACKET_ADB) && (data[0] == 0x40) && (data[1] == 0x2c))
246
        return data[2];
250
        return data[2];
247
   
251
   
248
    return -1;
252
    return -1;
249
}
253
}
250
 
254
 
251
static void cuda_irq(int n, istate_t *istate)
255
static void cuda_irq_handler(irq_t *irq, void *arg, ...)
252
{
256
{
-
 
257
    if (irq->notif_cfg.answerbox)
-
 
258
        ipc_irq_send_notif(irq);
-
 
259
    else {
253
    int scan_code = cuda_get_scancode();
260
        int scan_code = cuda_get_scancode();
254
   
261
       
255
    if (scan_code != -1) {
262
        if (scan_code != -1) {
256
        uint8_t scancode = (uint8_t) scan_code;
263
            uint8_t scancode = (uint8_t) scan_code;
257
        if ((scancode & 0x80) != 0x80)
264
            if ((scancode & 0x80) != 0x80)
258
            chardev_push_character(&kbrd, lchars[scancode & 0x7f]);
265
                chardev_push_character(&kbrd, lchars[scancode & 0x7f]);
-
 
266
        }
259
    }
267
    }
260
}
268
}
261
 
269
 
-
 
270
static irq_ownership_t cuda_claim(void)
-
 
271
{
-
 
272
    return IRQ_ACCEPT;
-
 
273
}
-
 
274
 
262
 
275
 
263
/** Initialize keyboard and service interrupts using kernel routine */
276
/** Initialize keyboard and service interrupts using kernel routine */
264
void cuda_grab(void)
277
void cuda_grab(void)
265
{
278
{
-
 
279
    if (cuda_irq.notif_cfg.answerbox) {
266
    vector = int_register(CUDA_IRQ, "cuda", cuda_irq);
280
        saved_notif_cfg = cuda_irq.notif_cfg;
-
 
281
        cuda_irq.notif_cfg.answerbox = NULL;
-
 
282
        cuda_irq.notif_cfg.code = NULL;
-
 
283
        cuda_irq.notif_cfg.method = 0;
-
 
284
        cuda_irq.notif_cfg.counter = 0;
-
 
285
    }
267
}
286
}
268
 
287
 
269
 
288
 
270
/** Resume the former interrupt vector */
289
/** Resume the former interrupt vector */
271
void cuda_release(void)
290
void cuda_release(void)
272
{
291
{
273
    if (vector)
292
    if (saved_notif_cfg.answerbox)
274
        int_register(CUDA_IRQ, "user_interrupt", vector);
293
        cuda_irq.notif_cfg = saved_notif_cfg;
275
}
294
}
276
 
295
 
277
 
296
 
278
void cuda_init(uintptr_t base, size_t size)
297
void cuda_init(devno_t devno, uintptr_t base, size_t size)
279
{
298
{
280
    cuda = (uint8_t *) hw_map(base, size);
299
    cuda = (uint8_t *) hw_map(base, size); 
281
   
-
 
282
    int_register(CUDA_IRQ, "cuda", cuda_irq);
-
 
283
    pic_enable_interrupt(CUDA_IRQ);
-
 
284
   
300
   
285
    chardev_initialize("cuda_kbd", &kbrd, &ops);
301
    chardev_initialize("cuda_kbd", &kbrd, &ops);
286
    stdin = &kbrd;
302
    stdin = &kbrd;
287
   
303
   
-
 
304
    irq_initialize(&cuda_irq);
-
 
305
    cuda_irq.devno = devno;
-
 
306
    cuda_irq.inr = CUDA_IRQ;
-
 
307
    cuda_irq.claim = cuda_claim;
-
 
308
    cuda_irq.handler = cuda_irq_handler;
-
 
309
    irq_register(&cuda_irq);
-
 
310
   
-
 
311
    pic_enable_interrupt(CUDA_IRQ);
-
 
312
 
288
    sysinfo_set_item_val("cuda", NULL, true);
313
    sysinfo_set_item_val("kbd", NULL, true);
-
 
314
    sysinfo_set_item_val("kbd.devno", NULL, devno);
289
    sysinfo_set_item_val("cuda.irq", NULL, CUDA_IRQ);
315
    sysinfo_set_item_val("kbd.inr", NULL, CUDA_IRQ);
-
 
316
    sysinfo_set_item_val("kbd.address.virtual", NULL, base);
-
 
317
 
-
 
318
    cuda_grab();
290
}
319
}
291
 
320
 
292
 
321
 
293
void send_packet(const uint8_t kind, index_t count, ...)
322
void send_packet(const uint8_t kind, index_t count, ...)
294
{
323
{
295
    index_t i;
324
    index_t i;
296
    va_list va;
325
    va_list va;
297
   
326
   
298
    cuda[B] = cuda[B] | TIP;
327
    cuda[B] = cuda[B] | TIP;
299
    cuda[ACR] = cuda[ACR] | SR_OUT;
328
    cuda[ACR] = cuda[ACR] | SR_OUT;
300
    cuda[SR] = kind;
329
    cuda[SR] = kind;
301
    cuda[B] = cuda[B] & ~TIP;
330
    cuda[B] = cuda[B] & ~TIP;
302
   
331
   
303
    va_start(va, count);
332
    va_start(va, count);
304
   
333
   
305
    for (i = 0; i < count; i++) {
334
    for (i = 0; i < count; i++) {
306
        cuda[ACR] = cuda[ACR] | SR_OUT;
335
        cuda[ACR] = cuda[ACR] | SR_OUT;
307
        cuda[SR] = va_arg(va, int);
336
        cuda[SR] = va_arg(va, int);
308
        cuda[B] = cuda[B] | TACK;
337
        cuda[B] = cuda[B] | TACK;
309
    }
338
    }
310
   
339
   
311
    va_end(va);
340
    va_end(va);
312
   
341
   
313
    cuda[B] = cuda[B] | TIP;
342
    cuda[B] = cuda[B] | TIP;
314
}
343
}
315
 
344
 
316
 
345
 
317
void cpu_halt(void) {
346
void cpu_halt(void) {
318
#ifdef CONFIG_POWEROFF
347
#ifdef CONFIG_POWEROFF
319
    send_packet(PACKET_CUDA, 1, CUDA_POWERDOWN);
348
    send_packet(PACKET_CUDA, 1, CUDA_POWERDOWN);
320
#endif
349
#endif
321
    asm volatile (
350
    asm volatile (
322
        "b 0\n"
351
        "b 0\n"
323
    );
352
    );
324
}
353
}
325
 
354
 
326
/** @}
355
/** @}
327
 */
356
 */
328
 
357