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
This commit is contained in:
Marcus Overhagen 2006-03-29 21:07:19 +00:00
parent 4c000f8856
commit 130a176146
4 changed files with 37 additions and 2 deletions

View File

@ -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);
}

View File

@ -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

View File

@ -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;

View File

@ -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);