Rev 3386 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3386 | Rev 4153 | ||
---|---|---|---|
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 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 <ipc/irq.h> |
- | |
37 | #include <arch/asm.h> |
36 | #include <arch/asm.h> |
38 | #include <console/console.h> |
37 | #include <console/console.h> |
39 | #include <console/chardev.h> |
38 | #include <console/chardev.h> |
40 | #include <arch/drivers/pic.h> |
39 | #include <arch/drivers/pic.h> |
41 | #include <sysinfo/sysinfo.h> |
40 | #include <sysinfo/sysinfo.h> |
42 | #include <interrupt.h> |
41 | #include <interrupt.h> |
43 | #include <stdarg.h> |
42 | #include <stdarg.h> |
- | 43 | #include <ddi/device.h> |
|
44 | 44 | ||
45 | #define CUDA_IRQ 10 |
45 | #define CUDA_IRQ 10 |
46 | #define SPECIAL '?' |
46 | #define SPECIAL '?' |
47 | 47 | ||
48 | #define PACKET_ADB 0x00 |
48 | #define PACKET_ADB 0x00 |
Line 203... | Line 203... | ||
203 | 203 | ||
204 | cuda[B] = cuda[B] | TIP; |
204 | cuda[B] = cuda[B] | TIP; |
205 | } |
205 | } |
206 | 206 | ||
207 | 207 | ||
208 | /* Called from getc(). */ |
- | |
209 | static void cuda_resume(chardev_t *d) |
- | |
210 | { |
- | |
211 | } |
- | |
212 | - | ||
213 | - | ||
214 | /* Called from getc(). */ |
- | |
215 | static void cuda_suspend(chardev_t *d) |
- | |
216 | { |
- | |
217 | } |
- | |
218 | - | ||
219 | - | ||
220 | static char key_read(chardev_t *d) |
- | |
221 | { |
- | |
222 | char ch; |
- | |
223 | - | ||
224 | ch = 0; |
- | |
225 | return ch; |
- | |
226 | } |
- | |
227 | - | ||
228 | - | ||
229 | static chardev_t kbrd; |
208 | static indev_t kbrd; |
230 | static chardev_operations_t ops = { |
209 | static indev_operations_t ops = { |
231 | .suspend = cuda_suspend, |
- | |
232 | .resume = cuda_resume, |
- | |
233 | .read = key_read |
210 | .poll = NULL |
234 | }; |
211 | }; |
235 | 212 | ||
236 | 213 | ||
237 | int cuda_get_scancode(void) |
214 | int cuda_get_scancode(void) |
238 | { |
215 | { |
- | 216 | if (cuda) { |
|
239 | uint8_t kind; |
217 | uint8_t kind; |
240 | uint8_t data[4]; |
218 | uint8_t data[4]; |
241 | 219 | ||
242 | receive_packet(&kind, 4, data); |
220 | receive_packet(&kind, 4, data); |
243 | 221 | ||
244 | if ((kind == PACKET_ADB) && (data[0] == 0x40) && (data[1] == 0x2c)) |
222 | if ((kind == PACKET_ADB) && (data[0] == 0x40) && (data[1] == 0x2c)) |
245 | return data[2]; |
223 | return data[2]; |
- | 224 | } |
|
246 | 225 | ||
247 | return -1; |
226 | return -1; |
248 | } |
227 | } |
249 | 228 | ||
250 | static void cuda_irq_handler(irq_t *irq, void *arg, ...) |
229 | static void cuda_irq_handler(irq_t *irq) |
251 | { |
230 | { |
252 | if ((irq->notif_cfg.notify) && (irq->notif_cfg.answerbox)) |
- | |
253 | ipc_irq_send_notif(irq); |
- | |
254 | else { |
- | |
255 | int scan_code = cuda_get_scancode(); |
231 | int scan_code = cuda_get_scancode(); |
256 | 232 | ||
257 | if (scan_code != -1) { |
233 | if (scan_code != -1) { |
258 | uint8_t scancode = (uint8_t) scan_code; |
234 | uint8_t scancode = (uint8_t) scan_code; |
259 | if ((scancode & 0x80) != 0x80) |
235 | if ((scancode & 0x80) != 0x80) |
260 | chardev_push_character(&kbrd, lchars[scancode & 0x7f]); |
236 | indev_push_character(&kbrd, lchars[scancode & 0x7f]); |
261 | } |
- | |
262 | } |
237 | } |
263 | } |
238 | } |
264 | 239 | ||
265 | static irq_ownership_t cuda_claim(void) |
240 | static irq_ownership_t cuda_claim(irq_t *irq) |
266 | { |
241 | { |
267 | return IRQ_ACCEPT; |
242 | return IRQ_ACCEPT; |
268 | } |
243 | } |
269 | 244 | ||
270 | - | ||
271 | /** Initialize keyboard and service interrupts using kernel routine */ |
- | |
272 | void cuda_grab(void) |
- | |
273 | { |
- | |
274 | ipl_t ipl = interrupts_disable(); |
- | |
275 | spinlock_lock(&cuda_irq.lock); |
- | |
276 | cuda_irq.notif_cfg.notify = false; |
- | |
277 | spinlock_unlock(&cuda_irq.lock); |
- | |
278 | interrupts_restore(ipl); |
- | |
279 | } |
- | |
280 | - | ||
281 | - | ||
282 | /** Resume the former interrupt vector */ |
- | |
283 | void cuda_release(void) |
- | |
284 | { |
- | |
285 | ipl_t ipl = interrupts_disable(); |
- | |
286 | spinlock_lock(&cuda_irq.lock); |
- | |
287 | if (cuda_irq.notif_cfg.answerbox) |
- | |
288 | cuda_irq.notif_cfg.notify = true; |
- | |
289 | spinlock_unlock(&cuda_irq.unlock); |
- | |
290 | interrupts_restore(ipl); |
- | |
291 | } |
- | |
292 | - | ||
293 | - | ||
294 | void cuda_init(devno_t devno, uintptr_t base, size_t size) |
245 | void cuda_init(uintptr_t base, size_t size) |
295 | { |
246 | { |
296 | cuda = (uint8_t *) hw_map(base, size); |
247 | cuda = (uint8_t *) hw_map(base, size); |
297 | 248 | ||
298 | chardev_initialize("cuda_kbd", &kbrd, &ops); |
249 | indev_initialize("cuda_kbd", &kbrd, &ops); |
299 | stdin = &kbrd; |
250 | stdin = &kbrd; |
300 | 251 | ||
301 | irq_initialize(&cuda_irq); |
252 | irq_initialize(&cuda_irq); |
302 | cuda_irq.devno = devno; |
253 | cuda_irq.devno = device_assign_devno(); |
303 | cuda_irq.inr = CUDA_IRQ; |
254 | cuda_irq.inr = CUDA_IRQ; |
304 | cuda_irq.claim = cuda_claim; |
255 | cuda_irq.claim = cuda_claim; |
305 | cuda_irq.handler = cuda_irq_handler; |
256 | cuda_irq.handler = cuda_irq_handler; |
306 | irq_register(&cuda_irq); |
257 | irq_register(&cuda_irq); |
307 | 258 | ||
308 | pic_enable_interrupt(CUDA_IRQ); |
259 | pic_enable_interrupt(CUDA_IRQ); |
309 | 260 | ||
310 | sysinfo_set_item_val("kbd", NULL, true); |
261 | sysinfo_set_item_val("kbd", NULL, true); |
311 | sysinfo_set_item_val("kbd.devno", NULL, devno); |
- | |
312 | sysinfo_set_item_val("kbd.inr", NULL, CUDA_IRQ); |
262 | sysinfo_set_item_val("kbd.inr", NULL, CUDA_IRQ); |
313 | sysinfo_set_item_val("kbd.address.virtual", NULL, base); |
263 | sysinfo_set_item_val("kbd.address.virtual", NULL, base); |
314 | } |
264 | } |
315 | 265 | ||
316 | 266 | ||
Line 343... | Line 293... | ||
343 | "b 0\n" |
293 | "b 0\n" |
344 | ); |
294 | ); |
345 | } |
295 | } |
346 | 296 | ||
347 | void arch_reboot(void) { |
297 | void arch_reboot(void) { |
- | 298 | if (cuda) |
|
348 | send_packet(PACKET_CUDA, 1, CUDA_RESET); |
299 | send_packet(PACKET_CUDA, 1, CUDA_RESET); |
- | 300 | ||
349 | asm volatile ( |
301 | asm volatile ( |
350 | "b 0\n" |
302 | "b 0\n" |
351 | ); |
303 | ); |
352 | } |
304 | } |
353 | 305 |