From 130a1761463a73efe3b999b96a8c333a564b3425 Mon Sep 17 00:00:00 2001 From: Marcus Overhagen Date: Wed, 29 Mar 2006 21:07:19 +0000 Subject: [PATCH] implemented unpublishing of device and disconnecting (doesn't seem to work yet) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16923 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/add-ons/kernel/bus_managers/ps2/ps2_dev.c | 3 ++- src/add-ons/kernel/bus_managers/ps2/ps2_dev.h | 3 +++ .../kernel/bus_managers/ps2/ps2_keyboard.c | 15 +++++++++++++++ .../kernel/bus_managers/ps2/ps2_mouse.c | 18 +++++++++++++++++- 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/add-ons/kernel/bus_managers/ps2/ps2_dev.c b/src/add-ons/kernel/bus_managers/ps2/ps2_dev.c index 2e54efc120..3a4b254846 100644 --- a/src/add-ons/kernel/bus_managers/ps2/ps2_dev.c +++ b/src/add-ons/kernel/bus_managers/ps2/ps2_dev.c @@ -82,7 +82,8 @@ ps2_dev_unpublish(ps2_dev *dev) dev->active = false; - status = -1; + status = devfs_unpublish_device(dev->name, true); + dev->disconnect(dev); dprintf("ps2: devfs_unpublish_device %s, status = 0x%08lx\n", dev->name, status); } diff --git a/src/add-ons/kernel/bus_managers/ps2/ps2_dev.h b/src/add-ons/kernel/bus_managers/ps2/ps2_dev.h index da66ed4314..32c8e49f31 100644 --- a/src/add-ons/kernel/bus_managers/ps2/ps2_dev.h +++ b/src/add-ons/kernel/bus_managers/ps2/ps2_dev.h @@ -28,6 +28,9 @@ struct ps2_dev int result_buf_cnt; void * cookie; bigtime_t last_data; + +// functions + void (*disconnect)(ps2_dev *); }; #define PS2_DEVICE_COUNT 5 diff --git a/src/add-ons/kernel/bus_managers/ps2/ps2_keyboard.c b/src/add-ons/kernel/bus_managers/ps2/ps2_keyboard.c index 8a2f0c17dd..b82ca3cd0a 100644 --- a/src/add-ons/kernel/bus_managers/ps2/ps2_keyboard.c +++ b/src/add-ons/kernel/bus_managers/ps2/ps2_keyboard.c @@ -150,6 +150,11 @@ read_keyboard_packet(at_kbd_io *packet) status = acquire_sem_etc(sKeyboardSem, 1, B_CAN_INTERRUPT, 0); if (status < B_OK) return status; + + if (!ps2_device[PS2_DEVICE_KEYB].active) { + dprintf("ps2: read_keyboard_packet, Error device no longer active\n"); + return B_ERROR; + } if (packet_buffer_read(sKeyBuffer, (uint8 *)packet, sizeof(*packet)) == 0) { TRACE(("read_keyboard_packet(): error reading packet: %s\n", strerror(status))); @@ -161,6 +166,15 @@ read_keyboard_packet(at_kbd_io *packet) } +static void +ps2_keyboard_disconnect(ps2_dev *dev) +{ + // the keyboard might not be opened at this point + dprintf("ps2: ps2_keyboard_disconnect %s\n", dev->name); + if (sKeyboardOpenMask) + release_sem(sKeyboardSem); +} + // #pragma mark - @@ -235,6 +249,7 @@ keyboard_open(const char *name, uint32 flags, void **_cookie) atomic_or(&ps2_device[PS2_DEVICE_KEYB].flags, PS2_FLAG_ENABLED); *_cookie = NULL; + ps2_device[PS2_DEVICE_KEYB].disconnect = &ps2_keyboard_disconnect; dprintf("ps2: keyboard_open %s success\n", name); return B_OK; diff --git a/src/add-ons/kernel/bus_managers/ps2/ps2_mouse.c b/src/add-ons/kernel/bus_managers/ps2/ps2_mouse.c index 69ba1e5563..2df0005e11 100644 --- a/src/add-ons/kernel/bus_managers/ps2/ps2_mouse.c +++ b/src/add-ons/kernel/bus_managers/ps2/ps2_mouse.c @@ -185,6 +185,11 @@ mouse_read_event(mouse_cookie *cookie, mouse_movement *userMovement) if (status < B_OK) return status; + if (!cookie->dev->active) { + dprintf("ps2: mouse_read_event: Error device no longer active\n"); + return B_ERROR; + } + if (packet_buffer_read(cookie->mouse_buffer, packet, cookie->packet_size) != cookie->packet_size) { TRACE(("error copying buffer\n")); return B_ERROR; @@ -199,6 +204,16 @@ mouse_read_event(mouse_cookie *cookie, mouse_movement *userMovement) } +static void +ps2_mouse_disconnect(ps2_dev *dev) +{ + // the mouse device might not be opened at this point + dprintf("ps2: ps2_mouse_disconnect %s\n", dev->name); + if (dev->flags & PS2_FLAG_OPEN) + release_sem(((mouse_cookie *)dev->cookie)->mouse_sem); +} + + /** 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 @@ -325,6 +340,7 @@ mouse_open(const char *name, uint32 flags, void **_cookie) cookie->dev = dev; dev->cookie = cookie; + dev->disconnect = &ps2_mouse_disconnect; status = probe_mouse(cookie, &cookie->packet_size); if (status != B_OK) { @@ -377,7 +393,7 @@ mouse_close(void *_cookie) { mouse_cookie *cookie = _cookie; - TRACE(("mouse_close()\n")); + dprintf("ps2: mouse_close %s\n", cookie->dev->name); ps2_dev_command(cookie->dev, PS2_CMD_DISABLE, NULL, 0, NULL, 0);