2014-06-08 10:51:01 +04:00
|
|
|
/* vim: tabstop=4 shiftwidth=4 noexpandtab
|
|
|
|
*/
|
2014-06-08 10:29:17 +04:00
|
|
|
/* This file is part of ToaruOS and is released under the terms
|
|
|
|
* of the NCSA / University of Illinois License - see LICENSE.md
|
|
|
|
* Copyright (C) 2011-2014 Kevin Lange
|
2011-12-11 03:34:10 +04:00
|
|
|
*
|
2011-03-26 03:54:48 +03:00
|
|
|
* Low-level keyboard interrupt driver.
|
|
|
|
*
|
2012-01-25 23:50:30 +04:00
|
|
|
* Creates a device file (keyboard_pipe) that can be read
|
|
|
|
* to retreive keyboard events.
|
|
|
|
*
|
2011-03-26 03:54:48 +03:00
|
|
|
*/
|
|
|
|
|
2011-01-16 21:45:51 +03:00
|
|
|
#include <system.h>
|
2011-12-15 05:06:11 +04:00
|
|
|
#include <logging.h>
|
2012-01-25 10:19:52 +04:00
|
|
|
#include <fs.h>
|
|
|
|
#include <pipe.h>
|
|
|
|
#include <process.h>
|
2011-01-16 21:45:51 +03:00
|
|
|
|
2014-03-17 02:13:27 +04:00
|
|
|
#include <module.h>
|
|
|
|
|
2011-10-23 04:32:03 +04:00
|
|
|
#define KEY_DEVICE 0x60
|
|
|
|
#define KEY_PENDING 0x64
|
|
|
|
|
2011-10-31 10:18:44 +04:00
|
|
|
#define KEYBOARD_NOTICES 0
|
2012-02-05 08:29:46 +04:00
|
|
|
#define KEYBOARD_IRQ 1
|
2011-10-31 10:18:44 +04:00
|
|
|
|
2014-03-17 02:13:27 +04:00
|
|
|
static fs_node_t * keyboard_pipe;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add a character to the device buffer.
|
|
|
|
*/
|
|
|
|
static void putch(unsigned char c) {
|
|
|
|
uint8_t buf[2];
|
|
|
|
buf[0] = c;
|
|
|
|
buf[1] = '\0';
|
|
|
|
write_fs(keyboard_pipe, 0, 1, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait on the keyboard.
|
|
|
|
*/
|
|
|
|
static void keyboard_wait(void) {
|
|
|
|
while(inportb(KEY_PENDING) & 2);
|
|
|
|
}
|
2011-01-22 06:48:17 +03:00
|
|
|
|
2014-03-17 02:13:27 +04:00
|
|
|
static void keyboard_handler(struct regs *r) {
|
2011-01-16 21:45:51 +03:00
|
|
|
unsigned char scancode;
|
2011-10-31 10:30:48 +04:00
|
|
|
keyboard_wait();
|
2011-10-23 04:32:03 +04:00
|
|
|
scancode = inportb(KEY_DEVICE);
|
2012-02-05 08:29:46 +04:00
|
|
|
irq_ack(KEYBOARD_IRQ);
|
2011-10-31 10:48:03 +04:00
|
|
|
|
2012-10-15 06:53:16 +04:00
|
|
|
putch(scancode);
|
2011-01-16 21:45:51 +03:00
|
|
|
}
|
|
|
|
|
2012-01-25 23:50:30 +04:00
|
|
|
/*
|
|
|
|
* Install the keyboard driver and initialize the
|
|
|
|
* pipe device for userspace.
|
|
|
|
*/
|
2014-03-17 02:13:27 +04:00
|
|
|
static int keyboard_install(void) {
|
2012-12-08 06:33:07 +04:00
|
|
|
debug_print(NOTICE, "Initializing PS/2 keyboard driver");
|
2012-01-25 23:50:30 +04:00
|
|
|
|
|
|
|
/* Create a device pipe */
|
2012-01-25 10:19:52 +04:00
|
|
|
keyboard_pipe = make_pipe(128);
|
2012-02-17 00:31:40 +04:00
|
|
|
current_process->fds->entries[0] = keyboard_pipe;
|
2012-01-25 10:19:52 +04:00
|
|
|
|
2014-03-17 08:50:04 +04:00
|
|
|
keyboard_pipe->flags = FS_CHARDEVICE;
|
|
|
|
|
2014-03-17 02:13:27 +04:00
|
|
|
vfs_mount("/dev/kbd", keyboard_pipe);
|
|
|
|
|
2012-01-25 23:50:30 +04:00
|
|
|
/* Install the interrupt handler */
|
2012-02-05 08:29:46 +04:00
|
|
|
irq_install_handler(KEYBOARD_IRQ, keyboard_handler);
|
2014-03-17 02:13:27 +04:00
|
|
|
|
|
|
|
return 0;
|
2011-01-16 21:45:51 +03:00
|
|
|
}
|
|
|
|
|
2014-03-17 02:13:27 +04:00
|
|
|
static void keyboard_reset_ps2(void) {
|
2012-12-01 07:32:38 +04:00
|
|
|
uint8_t tmp = inportb(0x61);
|
|
|
|
outportb(0x61, tmp | 0x80);
|
|
|
|
outportb(0x61, tmp & 0x7F);
|
|
|
|
inportb(KEY_DEVICE);
|
|
|
|
}
|
|
|
|
|
2014-03-17 02:13:27 +04:00
|
|
|
static int keyboard_uninstall(void) {
|
|
|
|
/* TODO */
|
|
|
|
return 0;
|
2011-04-05 03:51:55 +04:00
|
|
|
}
|
|
|
|
|
2014-03-17 02:13:27 +04:00
|
|
|
MODULE_DEF(ps2kbd, keyboard_install, keyboard_uninstall);
|