Rev 4223 | Rev 4610 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4223 | Rev 4311 | ||
---|---|---|---|
Line 24... | Line 24... | ||
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 genarch |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | /** @file |
32 | /** @file |
33 | */ |
33 | */ |
34 | 34 | ||
35 | #include <arch/drivers/cuda.h> |
35 | #include <genarch/drivers/via-cuda/cuda.h> |
36 | #include <arch/asm.h> |
- | |
37 | #include <console/console.h> |
- | |
38 | #include <console/chardev.h> |
36 | #include <console/chardev.h> |
39 | #include <arch/drivers/pic.h> |
- | |
40 | #include <sysinfo/sysinfo.h> |
37 | #include <ddi/irq.h> |
41 | #include <interrupt.h> |
38 | #include <arch/asm.h> |
42 | #include <stdarg.h> |
39 | #include <mm/slab.h> |
43 | #include <ddi/device.h> |
40 | #include <ddi/device.h> |
44 | #include <string.h> |
- | |
45 | - | ||
46 | #define CUDA_IRQ 10 |
- | |
47 | - | ||
48 | #define PACKET_ADB 0x00 |
- | |
49 | #define PACKET_CUDA 0x01 |
- | |
50 | - | ||
51 | #define CUDA_POWERDOWN 0x0a |
- | |
52 | #define CUDA_RESET 0x11 |
- | |
53 | - | ||
54 | #define RS 0x200 |
- | |
55 | #define B (0 * RS) |
- | |
56 | #define A (1 * RS) |
- | |
57 | #define SR (10 * RS) |
- | |
58 | #define ACR (11 * RS) |
- | |
59 | - | ||
60 | #define SR_OUT 0x10 |
- | |
61 | #define TACK 0x10 |
- | |
62 | #define TIP 0x20 |
- | |
63 | - | ||
64 | #define SCANCODES 128 |
- | |
65 | - | ||
66 | static volatile uint8_t *cuda = NULL; |
- | |
67 | static irq_t cuda_irq; /**< Cuda's IRQ. */ |
- | |
68 | - | ||
69 | static wchar_t lchars[SCANCODES] = { |
- | |
70 | 'a', 's', 'd', 'f', 'h', 'g', 'z', 'x', 'c', 'v', |
- | |
71 | U_SPECIAL, |
- | |
72 | 'b', 'q', 'w', 'e', 'r', 'y', 't', '1', '2', '3', '4', '6', '5', |
- | |
73 | '=', '9', '7', '-', '8', '0', ']', 'o', 'u', '[', 'i', 'p', |
- | |
74 | '\n', /* Enter */ |
- | |
75 | 'l', 'j', '\'', 'k', ';', '\\', ',', '/', 'n', 'm', '.', |
- | |
76 | '\t', /* Tab */ |
- | |
77 | ' ', '`', |
- | |
78 | '\b', /* Backspace */ |
- | |
79 | U_SPECIAL, |
- | |
80 | U_ESCAPE, /* Escape */ |
- | |
81 | U_SPECIAL, /* Ctrl */ |
- | |
82 | U_SPECIAL, /* Alt */ |
- | |
83 | U_SPECIAL, /* Shift */ |
- | |
84 | U_SPECIAL, /* CapsLock */ |
- | |
85 | U_SPECIAL, /* Right Alt */ |
- | |
86 | U_LEFT_ARROW, /* Left */ |
- | |
87 | U_RIGHT_ARROW, /* Right */ |
- | |
88 | U_DOWN_ARROW, /* Down */ |
- | |
89 | U_UP_ARROW, /* Up */ |
- | |
90 | U_SPECIAL, |
- | |
91 | U_SPECIAL, |
- | |
92 | '.', /* Keypad . */ |
- | |
93 | U_SPECIAL, |
- | |
94 | '*', /* Keypad * */ |
- | |
95 | U_SPECIAL, |
- | |
96 | '+', /* Keypad + */ |
- | |
97 | U_SPECIAL, |
- | |
98 | U_SPECIAL, /* NumLock */ |
- | |
99 | U_SPECIAL, |
- | |
100 | U_SPECIAL, |
- | |
101 | U_SPECIAL, |
- | |
102 | '/', /* Keypad / */ |
- | |
103 | '\n', /* Keypad Enter */ |
- | |
104 | U_SPECIAL, |
- | |
105 | '-', /* Keypad - */ |
- | |
106 | U_SPECIAL, |
- | |
107 | U_SPECIAL, |
- | |
108 | U_SPECIAL, |
- | |
109 | '0', /* Keypad 0 */ |
- | |
110 | '1', /* Keypad 1 */ |
- | |
111 | '2', /* Keypad 2 */ |
- | |
112 | '3', /* Keypad 3 */ |
- | |
113 | '4', /* Keypad 4 */ |
- | |
114 | '5', /* Keypad 5 */ |
- | |
115 | '6', /* Keypad 6 */ |
- | |
116 | '7', /* Keypad 7 */ |
- | |
117 | U_SPECIAL, |
- | |
118 | '8', /* Keypad 8 */ |
- | |
119 | '9', /* Keypad 9 */ |
- | |
120 | U_SPECIAL, |
- | |
121 | U_SPECIAL, |
- | |
122 | U_SPECIAL, |
- | |
123 | U_SPECIAL, /* F5 */ |
- | |
124 | U_SPECIAL, /* F6 */ |
- | |
125 | U_SPECIAL, /* F7 */ |
- | |
126 | U_SPECIAL, /* F3 */ |
- | |
127 | U_SPECIAL, /* F8 */ |
- | |
128 | U_SPECIAL, /* F9 */ |
- | |
129 | U_SPECIAL, |
- | |
130 | U_SPECIAL, /* F11 */ |
- | |
131 | U_SPECIAL, |
- | |
132 | U_SPECIAL, /* F13 */ |
- | |
133 | U_SPECIAL, |
- | |
134 | U_SPECIAL, /* ScrollLock */ |
- | |
135 | U_SPECIAL, |
- | |
136 | U_SPECIAL, /* F10 */ |
- | |
137 | U_SPECIAL, |
- | |
138 | U_SPECIAL, /* F12 */ |
- | |
139 | U_SPECIAL, |
- | |
140 | U_SPECIAL, /* Pause */ |
- | |
141 | U_SPECIAL, /* Insert */ |
- | |
142 | U_HOME_ARROW, /* Home */ |
- | |
143 | U_PAGE_UP, /* Page Up */ |
- | |
144 | U_DELETE, /* Delete */ |
- | |
145 | U_SPECIAL, /* F4 */ |
- | |
146 | U_END_ARROW, /* End */ |
- | |
147 | U_SPECIAL, /* F2 */ |
- | |
148 | U_PAGE_DOWN, /* Page Down */ |
- | |
149 | U_SPECIAL /* F1 */ |
- | |
150 | }; |
- | |
151 | - | ||
152 | static void receive_packet(uint8_t *kind, index_t count, uint8_t data[]) |
- | |
153 | { |
- | |
154 | cuda[B] = cuda[B] & ~TIP; |
- | |
155 | *kind = cuda[SR]; |
- | |
156 | - | ||
157 | index_t i; |
- | |
158 | for (i = 0; i < count; i++) |
- | |
159 | data[i] = cuda[SR]; |
- | |
160 | - | ||
161 | cuda[B] = cuda[B] | TIP; |
- | |
162 | } |
- | |
163 | - | ||
164 | static indev_t kbrd; |
- | |
165 | static indev_operations_t ops = { |
- | |
166 | .poll = NULL |
- | |
167 | }; |
- | |
168 | - | ||
169 | int cuda_get_scancode(void) |
- | |
170 | { |
- | |
171 | if (cuda) { |
- | |
172 | uint8_t kind; |
- | |
173 | uint8_t data[4]; |
- | |
174 | - | ||
175 | receive_packet(&kind, 4, data); |
- | |
176 | - | ||
177 | if ((kind == PACKET_ADB) && (data[0] == 0x40) && (data[1] == 0x2c)) |
- | |
178 | return data[2]; |
- | |
179 | } |
- | |
180 | - | ||
181 | return -1; |
- | |
182 | } |
- | |
183 | - | ||
184 | static void cuda_irq_handler(irq_t *irq) |
- | |
185 | { |
- | |
186 | int scan_code = cuda_get_scancode(); |
- | |
187 | - | ||
188 | if (scan_code != -1) { |
- | |
189 | uint8_t scancode = (uint8_t) scan_code; |
- | |
190 | if ((scancode & 0x80) != 0x80) |
- | |
191 | indev_push_character(&kbrd, lchars[scancode & 0x7f]); |
- | |
192 | } |
- | |
193 | } |
- | |
194 | 41 | ||
195 | static irq_ownership_t cuda_claim(irq_t *irq) |
42 | static irq_ownership_t cuda_claim(irq_t *irq) |
196 | { |
43 | { |
197 | return IRQ_ACCEPT; |
44 | return IRQ_DECLINE; |
198 | } |
45 | } |
199 | 46 | ||
200 | void cuda_init(uintptr_t base, size_t size) |
47 | static void cuda_irq_handler(irq_t *irq) |
201 | { |
48 | { |
202 | cuda = (uint8_t *) hw_map(base, size); |
- | |
203 | - | ||
204 | indev_initialize("cuda_kbd", &kbrd, &ops); |
- | |
205 | stdin = &kbrd; |
- | |
206 | - | ||
207 | irq_initialize(&cuda_irq); |
- | |
208 | cuda_irq.devno = device_assign_devno(); |
- | |
209 | cuda_irq.inr = CUDA_IRQ; |
- | |
210 | cuda_irq.claim = cuda_claim; |
- | |
211 | cuda_irq.handler = cuda_irq_handler; |
- | |
212 | irq_register(&cuda_irq); |
- | |
213 | - | ||
214 | pic_enable_interrupt(CUDA_IRQ); |
- | |
215 | - | ||
216 | sysinfo_set_item_val("kbd", NULL, true); |
- | |
217 | sysinfo_set_item_val("kbd.inr", NULL, CUDA_IRQ); |
- | |
218 | sysinfo_set_item_val("kbd.address.virtual", NULL, base); |
- | |
219 | } |
49 | } |
220 | 50 | ||
221 | static void send_packet(const uint8_t kind, count_t count, ...) |
51 | cuda_instance_t *cuda_init(cuda_t *dev, inr_t inr, cir_t cir, void *cir_arg) |
222 | { |
52 | { |
223 | index_t i; |
- | |
224 | va_list va; |
53 | cuda_instance_t *instance |
225 | - | ||
226 | cuda[B] = cuda[B] | TIP; |
54 | = malloc(sizeof(cuda_instance_t), FRAME_ATOMIC); |
227 | cuda[ACR] = cuda[ACR] | SR_OUT; |
55 | if (instance) { |
228 | cuda[SR] = kind; |
56 | instance->cuda = dev; |
229 | cuda[B] = cuda[B] & ~TIP; |
57 | instance->kbrdin = NULL; |
230 | 58 | ||
- | 59 | irq_initialize(&instance->irq); |
|
- | 60 | instance->irq.devno = device_assign_devno(); |
|
231 | va_start(va, count); |
61 | instance->irq.inr = inr; |
232 | - | ||
233 | for (i = 0; i < count; i++) { |
62 | instance->irq.claim = cuda_claim; |
234 | cuda[ACR] = cuda[ACR] | SR_OUT; |
63 | instance->irq.handler = cuda_irq_handler; |
235 | cuda[SR] = va_arg(va, int); |
64 | instance->irq.instance = instance; |
236 | cuda[B] = cuda[B] | TACK; |
65 | instance->irq.cir = cir; |
- | 66 | instance->irq.cir_arg = cir_arg; |
|
237 | } |
67 | } |
238 | 68 | ||
239 | va_end(va); |
69 | return instance; |
240 | - | ||
241 | cuda[B] = cuda[B] | TIP; |
- | |
242 | } |
70 | } |
243 | 71 | ||
244 | void cpu_halt(void) { |
72 | void cuda_wire(cuda_instance_t *instance, indev_t *kbrdin) |
245 | asm volatile ( |
- | |
246 | "b 0\n" |
- | |
247 | ); |
73 | { |
248 | } |
74 | } |
249 | 75 | ||
250 | void arch_reboot(void) { |
- | |
251 | if (cuda) |
- | |
252 | send_packet(PACKET_CUDA, 1, CUDA_RESET); |
- | |
253 | - | ||
254 | asm volatile ( |
- | |
255 | "b 0\n" |
- | |
256 | ); |
- | |
257 | } |
- | |
258 | 76 | ||
259 | /** @} |
77 | /** @} |
260 | */ |
78 | */ |