diff --git a/build/jam/HaikuImage b/build/jam/HaikuImage index 63d628edd5..9a8436e83d 100644 --- a/build/jam/HaikuImage +++ b/build/jam/HaikuImage @@ -244,7 +244,7 @@ AddNewDriversToHaikuImage power : $(X86_ONLY)acpi_battery ; AddNewDriversToHaikuImage power : $(X86_ONLY)acpi_embedded_controller ; # legacy drivers -AddDriversToHaikuImage : console dprintf $(X86_ONLY)keyboard null +AddDriversToHaikuImage : console dprintf null random tty zero ; AddDriversToHaikuImage audio hmulti : $(SYSTEM_ADD_ONS_DRIVERS_AUDIO) ; AddDriversToHaikuImage audio old : $(SYSTEM_ADD_ONS_DRIVERS_AUDIO_OLD) ; diff --git a/src/add-ons/kernel/drivers/Jamfile b/src/add-ons/kernel/drivers/Jamfile index 37346ef84d..241c5bebb9 100644 --- a/src/add-ons/kernel/drivers/Jamfile +++ b/src/add-ons/kernel/drivers/Jamfile @@ -1,6 +1,5 @@ SubDir HAIKU_TOP src add-ons kernel drivers ; -SubInclude HAIKU_TOP src add-ons kernel drivers arch ; SubInclude HAIKU_TOP src add-ons kernel drivers bluetooth ; SubInclude HAIKU_TOP src add-ons kernel drivers bus ; SubInclude HAIKU_TOP src add-ons kernel drivers audio ; diff --git a/src/add-ons/kernel/drivers/arch/Jamfile b/src/add-ons/kernel/drivers/arch/Jamfile deleted file mode 100644 index 61a61207d0..0000000000 --- a/src/add-ons/kernel/drivers/arch/Jamfile +++ /dev/null @@ -1,3 +0,0 @@ -SubDir HAIKU_TOP src add-ons kernel drivers arch ; - -SubInclude HAIKU_TOP src add-ons kernel drivers arch $(TARGET_ARCH) ; diff --git a/src/add-ons/kernel/drivers/arch/m68k/Jamfile b/src/add-ons/kernel/drivers/arch/m68k/Jamfile deleted file mode 100644 index 0a837bcfe5..0000000000 --- a/src/add-ons/kernel/drivers/arch/m68k/Jamfile +++ /dev/null @@ -1,4 +0,0 @@ -SubDir HAIKU_TOP src add-ons kernel drivers arch m68k ; - -#SubInclude HAIKU_TOP src add-ons kernel drivers arch x86 keyboard ; -#SubInclude HAIKU_TOP src add-ons kernel drivers arch x86 ps2mouse ; diff --git a/src/add-ons/kernel/drivers/arch/ppc/Jamfile b/src/add-ons/kernel/drivers/arch/ppc/Jamfile deleted file mode 100644 index 5fe8fa3f0f..0000000000 --- a/src/add-ons/kernel/drivers/arch/ppc/Jamfile +++ /dev/null @@ -1,4 +0,0 @@ -SubDir HAIKU_TOP src add-ons kernel drivers arch ppc ; - -#SubInclude HAIKU_TOP src add-ons kernel drivers arch x86 keyboard ; -#SubInclude HAIKU_TOP src add-ons kernel drivers arch x86 ps2mouse ; diff --git a/src/add-ons/kernel/drivers/arch/x86/Jamfile b/src/add-ons/kernel/drivers/arch/x86/Jamfile deleted file mode 100644 index 86b0e0aeae..0000000000 --- a/src/add-ons/kernel/drivers/arch/x86/Jamfile +++ /dev/null @@ -1,4 +0,0 @@ -SubDir HAIKU_TOP src add-ons kernel drivers arch x86 ; - -SubInclude HAIKU_TOP src add-ons kernel drivers arch x86 keyboard ; -SubInclude HAIKU_TOP src add-ons kernel drivers arch x86 ps2mouse ; diff --git a/src/add-ons/kernel/drivers/arch/x86/keyboard/Jamfile b/src/add-ons/kernel/drivers/arch/x86/keyboard/Jamfile deleted file mode 100644 index 231c79e71f..0000000000 --- a/src/add-ons/kernel/drivers/arch/x86/keyboard/Jamfile +++ /dev/null @@ -1,24 +0,0 @@ -SubDir HAIKU_TOP src add-ons kernel drivers arch x86 keyboard ; - -UsePrivateHeaders input ; - -if $(COMPILE_FOR_R5) { - SubDirCcFlags -DCOMPILE_FOR_R5 ; -} - -KernelObjects - keyboard.c - : - -fno-pic - ; - -KernelLd keyboard : - <$(SOURCE_GRIST)>keyboard.o - kernel.so - : - $(HAIKU_TOP)/src/system/ldscripts/$(TARGET_ARCH)/add-on.ld - : - -Bdynamic -shared - : - ; - diff --git a/src/add-ons/kernel/drivers/arch/x86/keyboard/keyboard.c b/src/add-ons/kernel/drivers/arch/x86/keyboard/keyboard.c deleted file mode 100644 index 4654ac5294..0000000000 --- a/src/add-ons/kernel/drivers/arch/x86/keyboard/keyboard.c +++ /dev/null @@ -1,453 +0,0 @@ -/* - * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. - * Distributed under the terms of the NewOS License. - */ - - -#include -#include -#include -#include -#include - -#include -#include - -#define DEVICE_NAME "keyboard" - -#define TRACE_KEYBOARD 0 -#if TRACE_KEYBOARD -# define TRACE(x) dprintf x -#else -# define TRACE(x) ; -#endif - - -enum keycodes { - ESCAPE = 1, - - LSHIFT = 42, - RSHIFT = 54, - CAPS_LOCK = 58, - NUM_LOCK = 69, - SCR_LOCK = 70, - SYS_REQ = 55, - LCONTROL = 29, - RCONTROL = 29, // dunno what it really is - - CURSOR_LEFT = 75, - CURSOR_RIGHT = 77, - CURSOR_UP = 72, - CURSOR_DOWN = 80, - - HOME = 71, - END = 79, - - F1 = 0x3b, - F2, F3, F4, F5, F6, - F7, F8, F9, F10, - - F11 = 87, - F12 = 88, -}; - -#define LED_SCROLL 1 -#define LED_NUM 2 -#define LED_CAPS 4 - -int32 api_version = B_CUR_DRIVER_API_VERSION; - -static bool shift, sControl; -static int leds; -static sem_id keyboard_sem; -static mutex keyboard_read_mutex; -static char keyboard_buf[1024]; -static unsigned int head, tail; -static isa_module_info *gISA; -static int32 sOpenCount = 0; - - -// begins with HOME, end with CURSOR_DOWN -static const char sControlKeys[] = {'@', 'A', 0, 0, 'D', 0, 'C', 0, '[', 'B'}; - -// stolen from nujeffos -const char unshifted_keymap[128] = { - 0, 27, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', 8, '\t', - 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', 0, 'a', 's', - 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`', 0, '\\', 'z', 'x', 'c', 'v', - 'b', 'n', 'm', ',', '.', '/', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - '\\', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -}; - -const char shifted_keymap[128] = { - 0, 27, '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', 8, '\t', - 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', '\n', 0, 'A', 'S', - 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '"', '~', 0, '|', 'Z', 'X', 'C', 'V', - 'B', 'N', 'M', '<', '>', '?', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -}; - -const char caps_keymap[128] = { - 0, 27, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', 8, '\t', - 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '[', ']', '\n', 0, 'A', 'S', - 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', '\'', '`', 0, '\\', 'Z', 'X', 'C', 'V', - 'B', 'N', 'M', '<', '>', '?', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - '\\', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -}; - - -static void -wait_for_output(void) -{ - while (gISA->read_io_8(0x64) & 0x2) - ; -} - - -static void -set_leds(void) -{ - wait_for_output(); - gISA->write_io_8(0x60, 0xed); - wait_for_output(); - gISA->write_io_8(0x60, leds); -} - - -static void -insert_in_buf(char c) -{ - unsigned int temp_tail = tail; - - // see if the next char will collide with the head - temp_tail++; - temp_tail %= sizeof(keyboard_buf); - if (temp_tail == head) { - // buffer overflow, ditch this char - return; - } - keyboard_buf[tail] = c; - tail = temp_tail; - release_sem_etc(keyboard_sem, 1, B_DO_NOT_RESCHEDULE); -} - - -static int32 -handle_keyboard_interrupt(void *data) -{ - unsigned char key; - int32 retval = B_HANDLED_INTERRUPT; - - key = gISA->read_io_8(0x60); - TRACE(("handle_keyboard_interrupt: key = 0x%x\n", key)); - - if (key & 0x80) { - // key up - if (key == LSHIFT + 0x80 || key == RSHIFT + 0x80) - shift = false; - if (key == LCONTROL + 0x80 || key == RCONTROL + 0x80) - sControl = false; - - return B_HANDLED_INTERRUPT; - } - - switch (key) { - case LSHIFT: - case RSHIFT: - shift = true; - break; - case LCONTROL: - //case RCONTROL: - sControl = true; - break; - case CAPS_LOCK: - if (leds & LED_CAPS) - leds &= ~LED_CAPS; - else - leds |= LED_CAPS; - set_leds(); - break; - case SCR_LOCK: - if (leds & LED_SCROLL) { - leds &= ~LED_SCROLL; - //set_dprintf_enabled(false); - } else { - leds |= LED_SCROLL; - //set_dprintf_enabled(true); - } - set_leds(); - break; - case NUM_LOCK: - if (leds & LED_NUM) - leds &= ~LED_NUM; - else - leds |= LED_NUM; - set_leds(); - break; - - /* the following code has two possibilities because of issues - * with BeBochs & BeOS (all special keys don't map to anything - * useful, and SYS_REQ does a screen dump in BeOS). - * ToDo: remove these key functions some day... - */ - case F12: - case SYS_REQ: - panic("Keyboard Requested Halt\n"); - break; -#if 0 - case F11: - dbg_set_serial_debug(dbg_get_serial_debug() ? false : true); - break; -#endif - - case HOME: - case END: - case CURSOR_DOWN: - case CURSOR_UP: - case CURSOR_LEFT: - case CURSOR_RIGHT: - insert_in_buf(0x1b); - insert_in_buf('['); - insert_in_buf(sControlKeys[key - HOME]); - retval = B_INVOKE_SCHEDULER; - break; - - default: { - char ascii; - - if (shift || sControl) - ascii = shifted_keymap[key]; - else { - if (leds & LED_CAPS) - ascii = caps_keymap[key]; - else - ascii = unshifted_keymap[key]; - } - - if (sControl && ascii >= 64 && ascii < 96) - ascii -= 0100; - - TRACE(("ascii = 0x%x, '%c'\n", ascii, ascii)); - - if (ascii != 0) { - insert_in_buf(ascii); - retval = B_INVOKE_SCHEDULER; - } else - TRACE(("keyboard: unknown scan-code 0x%x\n", key)); - } - } - - return retval; -} - - -// #pragma mark - device hooks - - -static status_t -keyboard_open(const char *name, uint32 flags, void **cookie) -{ - if (atomic_add(&sOpenCount, 1) != 0) { - *cookie = NULL; - return B_OK; - } - - keyboard_sem = create_sem(0, "keyboard_sem"); - if (keyboard_sem < 0) - panic("could not create keyboard sem!\n"); - - mutex_init(&keyboard_read_mutex, "keyboard_read_mutex"); - - shift = false; - sControl = false; - leds = 0; - - // have the scroll lock reflect the state of serial debugging -#if 0 - if (dbg_get_serial_debug()) - leds |= LED_SCROLL; -#endif - set_leds(); - - head = tail = 0; - - install_io_interrupt_handler(0x01, &handle_keyboard_interrupt, NULL, 0); - - *cookie = NULL; - return B_OK; -} - - -static status_t -keyboard_close(void *cookie) -{ - if (atomic_add(&sOpenCount, -1) != 1) - return B_OK; - - remove_io_interrupt_handler(0x01, &handle_keyboard_interrupt, NULL); - - delete_sem(keyboard_sem); - mutex_destroy(&keyboard_read_mutex); - - return B_OK; -} - - -static status_t -keyboard_freecookie(void *cookie) -{ - return B_OK; -} - - -static status_t -keyboard_read(void *cookie, off_t pos, void *buffer, size_t *_length) -{ - unsigned int savedTail; - size_t length = *_length; - size_t copiedBytes = 0; - int status; - - if (length < 0) { - *_length = 0; - return B_OK; - } - - if (length > sizeof(keyboard_buf) - 1) - length = sizeof(keyboard_buf) - 1; - -retry: - // block here until data is ready - status = acquire_sem_etc(keyboard_sem, 1, B_CAN_INTERRUPT, 0); - if (status == B_INTERRUPTED) { - *_length = 0; - return B_OK; - } - if (status < B_OK) - return status; - - // critical section - mutex_lock(&keyboard_read_mutex); - - savedTail = tail; - if (head == savedTail) { - // buffer queue is empty - mutex_unlock(&keyboard_read_mutex); - goto retry; - } else { - size_t copyLength; - - // copy out of the buffer - if (head < savedTail) - copyLength = min(length, savedTail - head); - else - copyLength = min(length, sizeof(keyboard_buf) - head); - memcpy(buffer, &keyboard_buf[head], copyLength); - copiedBytes = copyLength; - - head = (head + copyLength) % sizeof(keyboard_buf); - if (head == 0 && savedTail > 0 && copiedBytes < length) { - // we wrapped around and have more bytes to read - // copy the first part of the buffer - copyLength = min(savedTail, length - copiedBytes); - memcpy((uint8 *)buffer + length, keyboard_buf, copyLength); - copiedBytes += copyLength; - head = copyLength; - } - } - if (head != savedTail) { - // we did not empty the keyboard queue - release_sem_etc(keyboard_sem, 1, B_DO_NOT_RESCHEDULE); - } - - mutex_unlock(&keyboard_read_mutex); - - *_length = copiedBytes; - return B_OK; -} - - -static status_t -keyboard_write(void *cookie, off_t pos, const void *buf, size_t *len) -{ - return EROFS; -} - - -static status_t -keyboard_ioctl(void *cookie, uint32 op, void *buf, size_t len) -{ - return EINVAL; -} - - -device_hooks keyboard_hooks = { - &keyboard_open, - &keyboard_close, - &keyboard_freecookie, - &keyboard_ioctl, - &keyboard_read, - &keyboard_write, - NULL, - NULL, - NULL, - NULL -}; - - -// #pragma mark - driver hooks - - -status_t -init_hardware(void) -{ - return B_OK; -} - - -const char ** -publish_devices(void) -{ - static const char *devices[] = { - DEVICE_NAME, - NULL - }; - - return devices; -} - - -device_hooks * -find_device(const char *name) -{ - if (!strcmp(name, DEVICE_NAME)) - return &keyboard_hooks; - - return NULL; -} - - -status_t -init_driver(void) -{ - if (get_module(B_ISA_MODULE_NAME, (module_info **)&gISA) < B_OK) - return B_ENTRY_NOT_FOUND; - - return B_OK; -} - - -void -uninit_driver(void) -{ - put_module(B_ISA_MODULE_NAME); -} diff --git a/src/add-ons/kernel/drivers/arch/x86/ps2mouse/Jamfile b/src/add-ons/kernel/drivers/arch/x86/ps2mouse/Jamfile deleted file mode 100644 index d398b0c1cc..0000000000 --- a/src/add-ons/kernel/drivers/arch/x86/ps2mouse/Jamfile +++ /dev/null @@ -1,42 +0,0 @@ -SubDir HAIKU_TOP src add-ons kernel drivers arch x86 ps2mouse ; - -SetSubDirSupportedPlatformsBeOSCompatible ; - -UsePrivateHeaders input kernel ; - -KernelObjects - ps2mouse.c - : - -fno-pic - ; - -KernelLd ps2mouse : - <$(SOURCE_GRIST)>ps2mouse.o - kernel.so - : - $(HAIKU_TOP)/src/system/ldscripts/$(TARGET_ARCH)/add-on.ld - : - -Bdynamic -shared - : - ; - -if $(COMPILE_FOR_R5) { -SubDirCcFlags -DCOMPILE_FOR_R5 ; - -KernelAddon ps2mouse : - ps2mouse.c -; - -#Package haiku-inputkit-cvs -# : -# ps2mouse -# : -# boot home config add-ons kernel drivers bin ; - -#Package haiku-inputkit-cvs -# : -# ps2mouse -# : -# boot home config add-ons kernel drivers dev input ; - -} diff --git a/src/add-ons/kernel/drivers/arch/x86/ps2mouse/ps2mouse.c b/src/add-ons/kernel/drivers/arch/x86/ps2mouse/ps2mouse.c deleted file mode 100644 index 637c17664f..0000000000 --- a/src/add-ons/kernel/drivers/arch/x86/ps2mouse/ps2mouse.c +++ /dev/null @@ -1,650 +0,0 @@ -/* - * Copyright 2001-2004 Haiku, Inc. - * ps2mouse.c: - * PS/2 mouse device driver - * Authors (in chronological order): - * Elad Lahav (elad@eldarshany.com) - * Stefano Ceccherini (burton666@libero.it) - */ - -/* - * A PS/2 mouse is connected to the IBM 8042 controller, and gets its - * name from the IBM PS/2 personal computer, which was the first to - * use this device. All resources are shared between the keyboard, and - * the mouse, referred to as the "Auxiliary Device". - * I/O: - * ~~~ - * The controller has 3 I/O registers: - * 1. Status (input), mapped to port 64h - * 2. Control (output), mapped to port 64h - * 3. Data (input/output), mapped to port 60h - * Data: - * ~~~~ - * A packet read from the mouse data port is composed of - * three bytes: - * byte 0: status byte, where - * - bit 0: Y overflow (1 = true) - * - bit 1: X overflow (1 = true) - * - bit 2: MSB of Y offset - * - bit 3: MSB of X offset - * - bit 4: Syncronization bit (always 1) - * - bit 5: Middle button (1 = down) - * - bit 6: Right button (1 = down) - * - bit 7: Left button (1 = down) - * byte 1: X position change, since last probed (-127 to +127) - * byte 2: Y position change, since last probed (-127 to +127) - * - * Intellimouse mice send a four byte packet, where the first three - * bytes are the same as standard mice, and the last one reports the - * Z position, which is, usually, the wheel movement. - * - * Interrupts: - * ~~~~~~~~~~ - * The PS/2 mouse device is connected to interrupt 12, which means that - * it uses the second interrupt controller (handles INT8 to INT15). In - * order for this interrupt to be enabled, both the 5th interrupt of - * the second controller AND the 3rd interrupt of the first controller - * (cascade mode) should be unmasked. - * This is all done inside install_io_interrupt_handler(), no need to - * worry about it anymore - * The controller uses 3 consecutive interrupts to inform the computer - * that it has new data. On the first the data register holds the status - * byte, on the second the X offset, and on the 3rd the Y offset. - */ - -#include -#include -#include -#include - -#include - -#include - -#include "ps2mouse.h" - -#define DEVICE_NAME "input/mouse/ps2/0" - -#if DEBUG - #define TRACE(x) dprintf x -#else - #define TRACE(x) -#endif - - -#ifdef COMPILE_FOR_R5 - #include "cbuf_adapter.h" -#else - #include -#endif - - -int32 api_version = B_CUR_DRIVER_API_VERSION; - -static isa_module_info *sIsa = NULL; - -static sem_id sMouseSem; -static int32 sSync; -static cbuf *sMouseChain; -static int32 sOpenMask; - -static bigtime_t sLastClickTime; -static bigtime_t sClickSpeed; -static int32 sClickCount; -static int sButtonsState; - -static uint32 sPacketSize; - -///////////////////////////////////////////////////////////////////////// -// ps2 protocol stuff - -/** Wait until the control port is ready to be written. This requires that - * the "Input buffer full" and "Output buffer full" bits will both be set - * to 0. Returns true if the control port is ready to be written, false - * if 10ms have passed since the function has been called, and the control - * port is still busy. - */ - -static bool -wait_write_ctrl() -{ - int8 read; - int32 tries = 100; - TRACE(("wait_write_ctrl()\n")); - do { - read = sIsa->read_io_8(PS2_PORT_CTRL); - spin(100); - } while ((read & (PS2_IBUF_FULL | PS2_OBUF_FULL)) && tries-- > 0); - - return tries > 0; -} - - -/** Wait until the data port is ready to be written. This requires that - * the "Input buffer full" bit will be set to 0. - */ - -static bool -wait_write_data() -{ - int8 read; - int32 tries = 100; - TRACE(("wait_write_data()\n")); - do { - read = sIsa->read_io_8(PS2_PORT_CTRL); - spin(100); - } while ((read & PS2_IBUF_FULL) && tries-- > 0); - - return tries > 0; -} - - -/** Wait until the data port can be read from. This requires that the - * "Output buffer full" bit will be set to 1. - */ - -static bool -wait_read_data() -{ - int8 read; - int32 tries = 100; - TRACE(("wait_read_data()\n")); - do { - read = sIsa->read_io_8(PS2_PORT_CTRL); - spin(100); - } while (!(read & PS2_OBUF_FULL) && tries-- > 0); - - return tries > 0; -} - -/** Get the ps2 command byte. - */ - -static int8 -get_command_byte() -{ - int8 read = 0; - - TRACE(("set_command_byte()\n")); - if (wait_write_ctrl()) { - sIsa->write_io_8(PS2_PORT_CTRL, PS2_CTRL_READ_CMD); - if (wait_read_data()) - read = sIsa->read_io_8(PS2_PORT_DATA); - } - - return read; -} - - -/** Set the ps2 command byte. - * Parameters: - * unsigned char, byte to write - */ - -static void -set_command_byte(unsigned char cmd) -{ - TRACE(("set_command_byte()\n")); - if (wait_write_ctrl()) { - sIsa->write_io_8(PS2_PORT_CTRL, PS2_CTRL_WRITE_CMD); - if (wait_write_data()) - sIsa->write_io_8(PS2_PORT_DATA, cmd); - } -} - - -/** Reads a single byte from the data port. - * Return value: - * unsigned char, byte read - */ - -static uint8 -read_data_byte() -{ - TRACE(("read_data_byte()\n")); - if (wait_read_data()) { - TRACE(("read_data_byte(): ok\n")); - return sIsa->read_io_8(PS2_PORT_DATA); - } - - TRACE(("read_data_byte(): timeout\n")); - - return PS2_ERROR; -} - - -/** Writes a byte to the mouse device. Uses the control port to indicate - * that the byte is sent to the auxiliary device (mouse), instead of the - * keyboard. - * Parameters: - * unsigned char, byte to write - */ - -static void -write_aux_byte(unsigned char cmd) -{ - TRACE(("write_aux_byte()\n")); - if (wait_write_ctrl()) { - sIsa->write_io_8(PS2_PORT_CTRL, PS2_CTRL_WRITE_AUX); - - if (wait_write_data()) - sIsa->write_io_8(PS2_PORT_DATA, cmd); - } -} - - - -///////////////////////////////////////////////////////////////////////// -// mouse functions - -/* -static status_t -ps2_reset_mouse() -{ - int8 read; - - TRACE(("ps2_reset_mouse()\n")); - - write_aux_byte(PS2_CMD_RESET_MOUSE); - read = read_data_byte(); - - TRACE(("reset mouse: %2x\n", read)); - return B_OK; -} -*/ - - -/** Enables or disables mouse reporting for the ps2 port. - */ - -static status_t -ps2_enable_mouse(bool enable) -{ - int32 tries = 2; - uint8 read; - - do { - write_aux_byte(enable ? PS2_CMD_ENABLE_MOUSE : PS2_CMD_DISABLE_MOUSE); - read = read_data_byte(); - if (read == PS2_RES_ACK) - break; - spin(100); - } while (read == PS2_RES_RESEND && tries-- > 0); - - if (read != PS2_RES_ACK) - return B_ERROR; - - return B_OK; -} - - -/** Set sampling rate of the ps2 port. - */ - -static status_t -ps2_set_sample_rate(uint32 rate) -{ - status_t status = B_ERROR; - - write_aux_byte(PS2_CMD_SET_SAMPLE_RATE); - if (read_data_byte() == PS2_RES_ACK) { - write_aux_byte(rate); - if (read_data_byte() == PS2_RES_ACK) - status = B_OK; - } - - return status; -} - - -/** Converts a packet received by the mouse to a "movement". - */ - -static void -ps2_packet_to_movement(uint8 packet[], mouse_movement *pos) -{ - int buttons = packet[0] & 7; - int xDelta = ((packet[0] & 0x10) ? 0xFFFFFF00 : 0) | packet[1]; - int yDelta = ((packet[0] & 0x20) ? 0xFFFFFF00 : 0) | packet[2]; - bigtime_t currentTime = system_time(); - int8 wheel_ydelta = 0; - int8 wheel_xdelta = 0; - - if (buttons != 0) { - if (sButtonsState == 0) { - if (sLastClickTime + sClickSpeed > currentTime) - sClickCount++; - else - sClickCount = 1; - } - } - - sLastClickTime = currentTime; - sButtonsState = buttons; - - if (sPacketSize == PS2_PACKET_INTELLIMOUSE) { - switch (packet[3] & 0x0F) { - case 0x01: wheel_ydelta = +1; break; // wheel 1 down - case 0x0F: wheel_ydelta = -1; break; // wheel 1 up - case 0x02: wheel_xdelta = +1; break; // wheel 2 down - case 0x0E: wheel_xdelta = -1; break; // wheel 2 up - } - } - - if (pos) { - pos->xdelta = xDelta; - pos->ydelta = yDelta; - pos->buttons = buttons; - pos->clicks = sClickCount; - pos->modifiers = 0; - pos->timestamp = currentTime; - pos->wheel_ydelta = (int)wheel_ydelta; - pos->wheel_xdelta = (int)wheel_xdelta; - } -} - - -/** Read a mouse event from the mouse events chain buffer. - */ -static status_t -ps2_mouse_read(mouse_movement *pos) -{ - status_t status; - uint8 packet[PS2_MAX_PACKET_SIZE]; - - TRACE(("ps2_mouse_read()\n")); - status = acquire_sem_etc(sMouseSem, 1, B_CAN_INTERRUPT, 0); - if (status < B_OK) - return status; - - status = cbuf_memcpy_from_chain(packet, sMouseChain, 0, sPacketSize); - if (status < B_OK) { - TRACE(("error copying buffer\n")); - return status; - } - - ps2_packet_to_movement(packet, pos); - - return B_OK; -} - - -///////////////////////////////////////////////////////////////////////// -// interrupt - - -/** Interrupt handler for the mouse device. Called whenever the I/O - * controller generates an interrupt for the PS/2 mouse. Reads mouse - * information from the data port, and stores it, so it can be accessed - * by read() operations. The full data is obtained using 3 consecutive - * calls to the handler, each holds a different byte on the data port. - */ -static int32 -handle_mouse_interrupt(void* data) -{ - int8 read; - TRACE(("mouse interrupt occurred!!!\n")); - - read = sIsa->read_io_8(PS2_PORT_CTRL); - - if (read < 0) { - TRACE(("Interrupt was not generated by the ps2 mouse\n")); - return B_UNHANDLED_INTERRUPT; - } - - read = read_data_byte(); - cbuf_memcpy_to_chain(sMouseChain, 0, &read, sizeof(read)); - - if (sSync == 0 && !(read & 8)) { - TRACE(("mouse resynched, bad data\n")); - return B_HANDLED_INTERRUPT; - } - - if (++sSync == sPacketSize) { - TRACE(("mouse synched\n")); - sSync = 0; - release_sem_etc(sMouseSem, 1, B_DO_NOT_RESCHEDULE); - - return B_INVOKE_SCHEDULER; - } - - return B_HANDLED_INTERRUPT; -} - - -///////////////////////////////////////////////////////////////////////// -// file operations - - -static status_t -mouse_open(const char *name, uint32 flags, void **cookie) -{ - status_t status; - int8 commandByte; - - TRACE(("mouse_open()\n")); - - if (atomic_or(&sOpenMask, 1) != 0) - return B_BUSY; - - *cookie = NULL; - - commandByte = get_command_byte(); - commandByte |= PS2_BITS_AUX_INTERRUPT; - commandByte &= ~PS2_BITS_MOUSE_DISABLED; - set_command_byte(commandByte); - - status = ps2_enable_mouse(true); - if (status < B_OK) { - TRACE(("mouse_open(): cannot enable PS/2 mouse\n")); - return B_ERROR; - } - - TRACE(("mouse_open(): mouse succesfully enabled\n")); - - // register interrupt handler - status = install_io_interrupt_handler(INT_PS2_MOUSE, handle_mouse_interrupt, NULL, 0); - - return status; -} - - -static status_t -mouse_close(void * cookie) -{ - TRACE(("mouse_close()\n")); - ps2_enable_mouse(false); - - remove_io_interrupt_handler(INT_PS2_MOUSE, handle_mouse_interrupt, NULL); - - atomic_and(&sOpenMask, 0); - - return B_OK; -} - - -static status_t -mouse_freecookie(void * cookie) -{ - return B_OK; -} - - -static status_t -mouse_read(void *cookie, off_t pos, void *buf, size_t *len) -{ - *len = 0; - return EROFS; -} - - -static status_t -mouse_write(void * cookie, off_t pos, const void *buf, size_t *len) -{ - *len = 0; - return EROFS; -} - - -static status_t -mouse_ioctl(void *cookie, uint32 op, void *buf, size_t len) -{ - mouse_movement *pos = (mouse_movement *)buf; - switch (op) { - case MS_NUM_EVENTS: - { - int32 count; - TRACE(("MS_NUM_EVENTS\n")); - get_sem_count(sMouseSem, &count); - return count; - } - case MS_READ: - TRACE(("MS_READ\n")); - return ps2_mouse_read(pos); - case MS_SET_TYPE: - TRACE(("MS_SET_TYPE not implemented\n")); - return EINVAL; - case MS_SET_MAP: - TRACE(("MS_SET_MAP (set mouse mapping) not implemented\n")); - return EINVAL; - case MS_GET_ACCEL: - TRACE(("MS_GET_ACCEL (get mouse acceleration) not implemented\n")); - return EINVAL; - case MS_SET_ACCEL: - TRACE(("MS_SET_ACCEL (set mouse acceleration) not implemented\n")); - return EINVAL; - case MS_SET_CLICKSPEED: - TRACE(("MS_SETCLICK (set click speed)\n")); - sClickSpeed = *(bigtime_t *)buf; - return B_OK; - default: - TRACE(("unknown opcode: %ld\n", op)); - return EINVAL; - } -} - - -/* - * function structure used for file-op registration - */ -device_hooks ps2_mouse_hooks = { - &mouse_open, - &mouse_close, - &mouse_freecookie, - &mouse_ioctl, - &mouse_read, - &mouse_write, - NULL, - NULL, - NULL, - NULL -}; - - -///////////////////////////////////////////////////////////////////////// -// initialization - - -status_t -init_hardware() -{ - return B_OK; -} - - -const char ** -publish_devices(void) -{ - static const char *devices[] = { - DEVICE_NAME, - NULL - }; - - return devices; -} - - -device_hooks * -find_device(const char *name) -{ - if (!strcmp(name, DEVICE_NAME)) - return &ps2_mouse_hooks; - - return NULL; -} - - -status_t -init_driver() -{ - status_t status; - uint8 deviceId; - - status = get_module(B_ISA_MODULE_NAME, (module_info **)&sIsa); - if (status < B_OK) { - TRACE(("Failed getting isa module: %s\n", strerror(status))); - return status; - } - - // get device id - write_aux_byte(PS2_CMD_GET_DEVICE_ID); - if (read_data_byte() == PS2_RES_ACK) - deviceId = read_data_byte(); - - TRACE(("init_driver: device id: %2x\n", deviceId)); - if (deviceId == 0) { - // try to switch to intellimouse mode - ps2_set_sample_rate(200); - ps2_set_sample_rate(100); - ps2_set_sample_rate(80); - } - - // get device id, again - write_aux_byte(PS2_CMD_GET_DEVICE_ID); - if (read_data_byte() == PS2_RES_ACK) - deviceId = read_data_byte(); - - if (deviceId == PS2_DEV_ID_STANDARD) { - sPacketSize = PS2_PACKET_STANDARD; - TRACE(("Standard ps2 mouse found\n")); - } else if (deviceId == PS2_DEV_ID_INTELLIMOUSE) { - sPacketSize = PS2_PACKET_INTELLIMOUSE; - TRACE(("Extended ps2 mouse found\n")); - } else { - TRACE(("No mouse found\n")); - put_module(B_ISA_MODULE_NAME); - return B_ERROR; // Something's wrong. Better quit - } - - sMouseChain = cbuf_get_chain(MOUSE_HISTORY_SIZE); - if (sMouseChain == NULL) { - TRACE(("can't allocate cbuf chain\n")); - put_module(B_ISA_MODULE_NAME); - return B_ERROR; - } - - // create the mouse semaphore, used for synchronization between - // the interrupt handler and the read operation - sMouseSem = create_sem(0, "ps2_mouse_sem"); - if (sMouseSem < 0) { - TRACE(("failed creating PS/2 mouse semaphore!\n")); - cbuf_free_chain(sMouseChain); - put_module(B_ISA_MODULE_NAME); - return sMouseSem; - } - - set_sem_owner(sMouseSem, B_SYSTEM_TEAM); - - sOpenMask = 0; - - return B_OK; -} - - -void -uninit_driver() -{ - cbuf_free_chain(sMouseChain); - delete_sem(sMouseSem); - put_module(B_ISA_MODULE_NAME); -} diff --git a/src/add-ons/kernel/drivers/arch/x86/ps2mouse/ps2mouse.h b/src/add-ons/kernel/drivers/arch/x86/ps2mouse/ps2mouse.h deleted file mode 100644 index 42c416e2b6..0000000000 --- a/src/add-ons/kernel/drivers/arch/x86/ps2mouse/ps2mouse.h +++ /dev/null @@ -1,110 +0,0 @@ -/* - * ps2mouse.c: - * PS/2 mouse device driver for NewOS and OpenBeOS. - * Author: Elad Lahav (elad@eldarshany.com) - * Created: 21.12.2001 - * Modified: 11.1.2002 - */ - -/* - * A PS/2 mouse is connected to the IBM 8042 controller, and gets its - * name from the IBM PS/2 personal computer, which was the first to - * use this device. All resources are shared between the keyboard, and - * the mouse, referred to as the "Auxiliary Device". - * I/O: - * ~~~ - * The controller has 3 I/O registers: - * 1. Status (input), mapped to port 64h - * 2. Control (output), mapped to port 64h - * 3. Data (input/output), mapped to port 60h - * Data: - * ~~~~ - * Since a mouse is an input only device, data can only be read, and - * not written. A packet read from the mouse data port is composed of - * three bytes: - * byte 0: status byte, where - * - bit 0: Y overflow (1 = true) - * - bit 1: X overflow (1 = true) - * - bit 2: MSB of Y offset - * - bit 3: MSB of X offset - * - bit 4: Syncronization bit (always 1) - * - bit 5: Middle button (1 = down) - * - bit 6: Right button (1 = down) - * - bit 7: Left button (1 = down) - * byte 1: X position change, since last probed (-127 to +127) - * byte 2: Y position change, since last probed (-127 to +127) - * Interrupts: - * ~~~~~~~~~~ - * The PS/2 mouse device is connected to interrupt 12, which means that - * it uses the second interrupt controller (handles INT8 to INT15). In - * order for this interrupt to be enabled, both the 5th interrupt of - * the second controller AND the 3rd interrupt of the first controller - * (cascade mode) should be unmasked. - * The controller uses 3 consecutive interrupts to inform the computer - * that it has new data. On the first the data register holds the status - * byte, on the second the X offset, and on the 3rd the Y offset. - */ - -#ifndef _KERNEL_ARCH_x86_PS2MOUSE_H -#define _KERNEL_ARCH_x86_PS2MOUSE_H - -#include - -///////////////////////////////////////////////////////////////////////// -// definitions - -// I/O addresses -#define PS2_PORT_DATA 0x60 -#define PS2_PORT_CTRL 0x64 - -// data port bits -#define PS2_OBUF_FULL 0x01 -#define PS2_IBUF_FULL 0x02 -#define PS2_MOUSE_OBUF_FULL 0x20 -#define PS2_TIMEOUT 0x40 - -// control words -#define PS2_CTRL_READ_CMD 0x20 -#define PS2_CTRL_WRITE_CMD 0x60 -#define PS2_CTRL_WRITE_AUX 0xD4 -#define PS2_CTRL_MOUSE_DISABLE 0xA7 -#define PS2_CTRL_MOUSE_ENABLE 0xA8 -#define PS2_CTRL_MOUSE_TEST 0xA9 - -// command bytes -#define PS2_CMD_DEV_INIT 0x43 - -// command bits -#define PS2_BITS_AUX_INTERRUPT 0x02 -#define PS2_BITS_MOUSE_DISABLED 0x20 - -// data words -#define PS2_CMD_TEST_PASSED 0xAA -#define PS2_CMD_GET_DEVICE_ID 0xF2 -#define PS2_CMD_SET_SAMPLE_RATE 0xF3 -#define PS2_CMD_ENABLE_MOUSE 0xF4 -#define PS2_CMD_DISABLE_MOUSE 0xF5 -#define PS2_CMD_RESET_MOUSE 0xFF - -// reply codes -#define PS2_RES_TEST_PASSED 0x55 -#define PS2_RES_ACK 0xFA -#define PS2_RES_RESEND 0xFE -#define PS2_ERROR 0xFC - -// interrupts -#define INT_PS2_MOUSE 0x0C - -// other stuff -#define MOUSE_HISTORY_SIZE 256 - -// mouse device IDs -#define PS2_DEV_ID_STANDARD 0 -#define PS2_DEV_ID_INTELLIMOUSE 3 - -// packet sizes -#define PS2_PACKET_STANDARD 3 -#define PS2_PACKET_INTELLIMOUSE 4 -#define PS2_MAX_PACKET_SIZE 4 // Should be equal to the biggest packet size - -#endif /* _KERNEL_ARCH_x86_PS2MOUSE_H */