Subversion Repositories HelenOS-historic

Rev

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

Rev 1619 Rev 1625
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
#include <arch/drivers/cuda.h>
29
#include <arch/drivers/cuda.h>
30
#include <arch/asm.h>
30
#include <arch/asm.h>
31
#include <console/chardev.h>
-
 
32
#include <console/console.h>
31
#include <console/console.h>
33
#include <arch/drivers/pic.h>
32
#include <arch/drivers/pic.h>
-
 
33
#include <sysinfo/sysinfo.h>
34
#include <interrupt.h>
34
#include <interrupt.h>
35
#include <stdarg.h>
35
#include <stdarg.h>
36
 
36
 
37
#define PACKET_ADB  0x00
37
#define PACKET_ADB  0x00
38
#define PACKET_CUDA 0x01
38
#define PACKET_CUDA 0x01
39
#define PACKET_NULL 0xff
39
#define PACKET_NULL 0xff
40
 
40
 
41
#define CUDA_POWERDOWN 0x0a
41
#define CUDA_POWERDOWN 0x0a
42
 
42
 
43
#define RS 0x200
43
#define RS 0x200
44
#define B (0 * RS)
44
#define B (0 * RS)
45
#define A (1 * RS)
45
#define A (1 * RS)
46
#define SR (10 * RS)
46
#define SR (10 * RS)
47
#define ACR (11 * RS)
47
#define ACR (11 * RS)
48
 
48
 
49
#define SR_OUT 0x10
49
#define SR_OUT 0x10
50
#define TACK 0x10
50
#define TACK 0x10
51
#define TIP 0x20
51
#define TIP 0x20
52
 
52
 
53
 
53
 
54
static volatile __u8 *cuda = NULL;
54
static volatile __u8 *cuda = NULL;
55
 
55
 
56
 
56
 
57
static char lchars[0x80] = {
57
static char lchars[0x80] = {
58
    'a',  's',  'd',  'f',  'h',  'g',  'z',  'x',  'c',  'v',    0,  'b',  'q',  'w',  'e',  'r',
58
    'a',  's',  'd',  'f',  'h',  'g',  'z',  'x',  'c',  'v',    0,  'b',  'q',  'w',  'e',  'r',
59
    'y',  't',  '1',  '2',  '3',  '4',  '6',  '5',  '=',  '9',  '7',  '-',  '8',  '0',  ']',  'o',
59
    'y',  't',  '1',  '2',  '3',  '4',  '6',  '5',  '=',  '9',  '7',  '-',  '8',  '0',  ']',  'o',
60
    'u',  '[',  'i',  'p',   13,  'l',  'j', '\'',  'k',  ';', '\\',  ',',  '/',  'n',  'm',  '.',
60
    'u',  '[',  'i',  'p',   13,  'l',  'j', '\'',  'k',  ';', '\\',  ',',  '/',  'n',  'm',  '.',
61
      9,   32,  '`',    8,    0,   27,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
61
      9,   32,  '`',    8,    0,   27,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
62
      0,  '.',    0,  '*',    0,  '+',    0,    0,    0,    0,    0,  '/',   13,    0,  '-',    0,
62
      0,  '.',    0,  '*',    0,  '+',    0,    0,    0,    0,    0,  '/',   13,    0,  '-',    0,
63
      0,    0,  '0',  '1',  '2',  '3',  '4',  '5',  '6',  '7',    0,  '8',  '9',    0,    0,    0,
63
      0,    0,  '0',  '1',  '2',  '3',  '4',  '5',  '6',  '7',    0,  '8',  '9',    0,    0,    0,
64
      0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
64
      0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
65
      0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0
65
      0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0
66
};
66
};
67
 
67
 
68
 
68
 
69
static void send_packet(const __u8 kind, index_t count, ...)
69
static void send_packet(const __u8 kind, index_t count, ...)
70
{
70
{
71
    index_t i;
71
    index_t i;
72
    va_list va;
72
    va_list va;
73
   
73
   
74
    switch (kind) {
74
    switch (kind) {
75
        case PACKET_NULL:
75
        case PACKET_NULL:
76
            break;
76
            break;
77
        default:
77
        default:
78
            cuda[B] = cuda[B] | TIP;
78
            cuda[B] = cuda[B] | TIP;
79
            cuda[ACR] = cuda[ACR] | SR_OUT;
79
            cuda[ACR] = cuda[ACR] | SR_OUT;
80
            cuda[SR] = kind;
80
            cuda[SR] = kind;
81
            cuda[B] = cuda[B] & ~TIP;
81
            cuda[B] = cuda[B] & ~TIP;
82
           
82
           
83
            va_start(va, count);
83
            va_start(va, count);
84
           
84
           
85
            for (i = 0; i < count; i++) {
85
            for (i = 0; i < count; i++) {
86
                cuda[ACR] = cuda[ACR] | SR_OUT;
86
                cuda[ACR] = cuda[ACR] | SR_OUT;
87
                cuda[SR] = va_arg(va, int);
87
                cuda[SR] = va_arg(va, int);
88
                cuda[B] = cuda[B] | TACK;
88
                cuda[B] = cuda[B] | TACK;
89
            }
89
            }
90
           
90
           
91
            va_end(va);
91
            va_end(va);
92
           
92
           
93
            cuda[B] = cuda[B] | TIP;
93
            cuda[B] = cuda[B] | TIP;
94
    }
94
    }
95
}
95
}
96
 
96
 
97
 
97
 
98
static void receive_packet(__u8 *kind, index_t count, __u8 data[])
98
static void receive_packet(__u8 *kind, index_t count, __u8 data[])
99
{
99
{
100
    cuda[B] = cuda[B] & ~TIP;
100
    cuda[B] = cuda[B] & ~TIP;
101
    *kind = cuda[SR];
101
    *kind = cuda[SR];
102
   
102
   
103
    index_t i;
103
    index_t i;
104
    for (i = 0; i < count; i++)
104
    for (i = 0; i < count; i++)
105
        data[i] = cuda[SR];
105
        data[i] = cuda[SR];
106
   
106
   
107
    cuda[B] = cuda[B] | TIP;
107
    cuda[B] = cuda[B] | TIP;
108
}
108
}
109
 
109
 
110
 
110
 
111
/* Called from getc(). */
111
/* Called from getc(). */
112
static void cuda_resume(chardev_t *d)
112
static void cuda_resume(chardev_t *d)
113
{
113
{
114
}
114
}
115
 
115
 
116
 
116
 
117
/* Called from getc(). */
117
/* Called from getc(). */
118
static void cuda_suspend(chardev_t *d)
118
static void cuda_suspend(chardev_t *d)
119
{
119
{
120
}
120
}
121
 
121
 
122
 
122
 
123
static char key_read(chardev_t *d)
123
static char key_read(chardev_t *d)
124
{
124
{
125
    char ch;
125
    char ch;
126
   
126
   
127
    ch = 0;
127
    ch = 0;
128
    return ch;
128
    return ch;
129
}
129
}
130
 
130
 
131
 
131
 
132
static chardev_t kbrd;
132
chardev_t kbrd;
133
static chardev_operations_t ops = {
133
static chardev_operations_t ops = {
134
    .suspend = cuda_suspend,
134
    .suspend = cuda_suspend,
135
    .resume = cuda_resume,
135
    .resume = cuda_resume,
136
    .read = key_read
136
    .read = key_read
137
};
137
};
138
 
138
 
139
 
139
 
140
static void cuda_irq(int n, istate_t *istate)
140
static void cuda_irq(int n, istate_t *istate)
141
{
141
{
142
    __u8 kind;
142
    __u8 kind;
143
    __u8 data[4];
143
    __u8 data[4];
144
   
144
   
145
    receive_packet(&kind, 4, data);
145
    receive_packet(&kind, 4, data);
146
   
146
   
147
    if ((kind == PACKET_ADB) && (data[0] == 0x40) && (data[1] == 0x2c)) {
147
    if ((kind == PACKET_ADB) && (data[0] == 0x40) && (data[1] == 0x2c)) {
148
        __u8 key = data[2];
148
        __u8 key = data[2];
149
       
149
       
150
        if ((key & 0x80) != 0x80)
150
        if ((key & 0x80) != 0x80)
151
            chardev_push_character(&kbrd, lchars[key & 0x7f]);
151
            chardev_push_character(&kbrd, lchars[key & 0x7f]);
152
    }
152
    }
153
}
153
}
154
 
154
 
155
 
155
 
156
void cuda_init(__address base, size_t size)
156
void cuda_init(__address base, size_t size)
157
{
157
{
158
    cuda = (__u8 *) hw_map(base, size);
158
    cuda = (__u8 *) hw_map(base, size);
159
   
159
   
160
    int_register(CUDA_IRQ, "cuda", cuda_irq);
160
    int_register(CUDA_IRQ, "cuda", cuda_irq);
161
    pic_enable_interrupt(CUDA_IRQ);
161
    pic_enable_interrupt(CUDA_IRQ);
162
   
162
   
163
    chardev_initialize("cuda_kbd", &kbrd, &ops);
163
    chardev_initialize("cuda_kbd", &kbrd, &ops);
164
    stdin = &kbrd;
164
    stdin = &kbrd;
-
 
165
   
-
 
166
    sysinfo_set_item_val("cuda", NULL, true);
-
 
167
    sysinfo_set_item_val("cuda.irq", NULL, CUDA_IRQ);
165
}
168
}
166
 
169
 
167
 
170
 
168
void cpu_halt(void) {
171
void cpu_halt(void) {
169
#ifdef CONFIG_POWEROFF
172
#ifdef CONFIG_POWEROFF
170
    send_packet(PACKET_CUDA, 1, CUDA_POWERDOWN);
173
    send_packet(PACKET_CUDA, 1, CUDA_POWERDOWN);
171
#else
174
#else
172
    send_packet(PACKET_NULL, 0);
175
    send_packet(PACKET_NULL, 0);
173
#endif
176
#endif
174
    asm volatile (
177
    asm volatile (
175
        "b 0\n"
178
        "b 0\n"
176
    );
179
    );
177
}
180
}
178
 
181