Subversion Repositories HelenOS-historic

Rev

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

Rev 1625 Rev 1628
Line 27... Line 27...
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/console.h>
31
#include <console/console.h>
-
 
32
#include <console/chardev.h>
32
#include <arch/drivers/pic.h>
33
#include <arch/drivers/pic.h>
33
#include <sysinfo/sysinfo.h>
34
#include <sysinfo/sysinfo.h>
34
#include <interrupt.h>
35
#include <interrupt.h>
35
#include <stdarg.h>
36
#include <stdarg.h>
36
 
37
 
37
#define PACKET_ADB  0x00
38
#define PACKET_ADB  0x00
38
#define PACKET_CUDA 0x01
39
#define PACKET_CUDA 0x01
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)
Line 64... Line 64...
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
void send_packet(const __u8 kind, index_t count, ...);
70
{
-
 
71
    index_t i;
-
 
72
    va_list va;
-
 
73
   
-
 
74
    switch (kind) {
-
 
75
        case PACKET_NULL:
-
 
76
            break;
-
 
77
        default:
-
 
78
            cuda[B] = cuda[B] | TIP;
-
 
79
            cuda[ACR] = cuda[ACR] | SR_OUT;
-
 
80
            cuda[SR] = kind;
-
 
81
            cuda[B] = cuda[B] & ~TIP;
-
 
82
           
-
 
83
            va_start(va, count);
-
 
84
           
-
 
85
            for (i = 0; i < count; i++) {
-
 
86
                cuda[ACR] = cuda[ACR] | SR_OUT;
-
 
87
                cuda[SR] = va_arg(va, int);
-
 
88
                cuda[B] = cuda[B] | TACK;
-
 
89
            }
-
 
90
           
-
 
91
            va_end(va);
-
 
92
           
-
 
93
            cuda[B] = cuda[B] | TIP;
-
 
94
    }
-
 
95
}
-
 
96
 
70
 
97
 
71
 
98
static void receive_packet(__u8 *kind, index_t count, __u8 data[])
72
static void receive_packet(__u8 *kind, index_t count, __u8 data[])
99
{
73
{
100
    cuda[B] = cuda[B] & ~TIP;
74
    cuda[B] = cuda[B] & ~TIP;
Line 127... Line 101...
127
    ch = 0;
101
    ch = 0;
128
    return ch;
102
    return ch;
129
}
103
}
130
 
104
 
131
 
105
 
132
chardev_t kbrd;
106
static chardev_t kbrd;
133
static chardev_operations_t ops = {
107
static chardev_operations_t ops = {
134
    .suspend = cuda_suspend,
108
    .suspend = cuda_suspend,
135
    .resume = cuda_resume,
109
    .resume = cuda_resume,
136
    .read = key_read
110
    .read = key_read
137
};
111
};
138
 
112
 
139
 
113
 
140
static void cuda_irq(int n, istate_t *istate)
114
__u8 cuda_get_scancode(void)
141
{
115
{
142
    __u8 kind;
116
    __u8 kind;
143
    __u8 data[4];
117
    __u8 data[4];
144
   
118
   
145
    receive_packet(&kind, 4, data);
119
    receive_packet(&kind, 4, data);
146
   
120
   
147
    if ((kind == PACKET_ADB) && (data[0] == 0x40) && (data[1] == 0x2c)) {
121
    if ((kind == PACKET_ADB) && (data[0] == 0x40) && (data[1] == 0x2c))
148
        __u8 key = data[2];
122
        return data[2];
149
       
123
   
-
 
124
    return 0;
-
 
125
}
-
 
126
 
-
 
127
 
150
        if ((key & 0x80) != 0x80)
128
static void cuda_irq(int n, istate_t *istate)
-
 
129
{
151
            chardev_push_character(&kbrd, lchars[key & 0x7f]);
130
    __u8 scancode = cuda_get_scancode();
152
    }
131
   
-
 
132
    if ((scancode != 0) && ((scancode & 0x80) != 0x80))
-
 
133
        chardev_push_character(&kbrd, lchars[scancode & 0x7f]);
153
}
134
}
154
 
135
 
155
 
136
 
156
void cuda_init(__address base, size_t size)
137
void cuda_init(__address base, size_t size)
157
{
138
{
Line 166... Line 147...
166
    sysinfo_set_item_val("cuda", NULL, true);
147
    sysinfo_set_item_val("cuda", NULL, true);
167
    sysinfo_set_item_val("cuda.irq", NULL, CUDA_IRQ);
148
    sysinfo_set_item_val("cuda.irq", NULL, CUDA_IRQ);
168
}
149
}
169
 
150
 
170
 
151
 
-
 
152
void send_packet(const __u8 kind, index_t count, ...)
-
 
153
{
-
 
154
    index_t i;
-
 
155
    va_list va;
-
 
156
   
-
 
157
    cuda[B] = cuda[B] | TIP;
-
 
158
    cuda[ACR] = cuda[ACR] | SR_OUT;
-
 
159
    cuda[SR] = kind;
-
 
160
    cuda[B] = cuda[B] & ~TIP;
-
 
161
   
-
 
162
    va_start(va, count);
-
 
163
   
-
 
164
    for (i = 0; i < count; i++) {
-
 
165
        cuda[ACR] = cuda[ACR] | SR_OUT;
-
 
166
        cuda[SR] = va_arg(va, int);
-
 
167
        cuda[B] = cuda[B] | TACK;
-
 
168
    }
-
 
169
   
-
 
170
    va_end(va);
-
 
171
   
-
 
172
    cuda[B] = cuda[B] | TIP;
-
 
173
}
-
 
174
 
-
 
175
 
171
void cpu_halt(void) {
176
void cpu_halt(void) {
172
#ifdef CONFIG_POWEROFF
177
#ifdef CONFIG_POWEROFF
173
    send_packet(PACKET_CUDA, 1, CUDA_POWERDOWN);
178
    send_packet(PACKET_CUDA, 1, CUDA_POWERDOWN);
174
#else
-
 
175
    send_packet(PACKET_NULL, 0);
-
 
176
#endif
179
#endif
177
    asm volatile (
180
    asm volatile (
178
        "b 0\n"
181
        "b 0\n"
179
    );
182
    );
180
}
183
}