Improved ps2_dev_command(), it now properly handles ACK and NACK, and thus is much faster.
Small cleanup git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16029 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -44,7 +44,6 @@ device_hooks sMouseDeviceHooks = {
|
|||||||
|
|
||||||
|
|
||||||
isa_module_info *gIsa = NULL;
|
isa_module_info *gIsa = NULL;
|
||||||
sem_id gDeviceOpenSemaphore;
|
|
||||||
|
|
||||||
static sem_id sKbcSem;
|
static sem_id sKbcSem;
|
||||||
static int32 sIgnoreInterrupts = 0;
|
static int32 sIgnoreInterrupts = 0;
|
||||||
@@ -244,10 +243,6 @@ ps2_init_driver(void)
|
|||||||
|
|
||||||
sKbcSem = create_sem(1, "ps/2 keyb ctrl");
|
sKbcSem = create_sem(1, "ps/2 keyb ctrl");
|
||||||
|
|
||||||
gDeviceOpenSemaphore = create_sem(1, "ps/2 open");
|
|
||||||
if (gDeviceOpenSemaphore < B_OK)
|
|
||||||
goto err_2;
|
|
||||||
|
|
||||||
status = ps2_dev_init();
|
status = ps2_dev_init();
|
||||||
|
|
||||||
status = ps2_service_init();
|
status = ps2_service_init();
|
||||||
@@ -340,7 +335,6 @@ err_4:
|
|||||||
err_3:
|
err_3:
|
||||||
ps2_service_exit();
|
ps2_service_exit();
|
||||||
ps2_dev_exit();
|
ps2_dev_exit();
|
||||||
delete_sem(gDeviceOpenSemaphore);
|
|
||||||
delete_sem(sKbcSem);
|
delete_sem(sKbcSem);
|
||||||
err_2:
|
err_2:
|
||||||
put_module(B_ISA_MODULE_NAME);
|
put_module(B_ISA_MODULE_NAME);
|
||||||
@@ -358,7 +352,6 @@ ps2_uninit_driver(void)
|
|||||||
remove_io_interrupt_handler(INT_PS2_KEYBOARD, &ps2_interrupt, NULL);
|
remove_io_interrupt_handler(INT_PS2_KEYBOARD, &ps2_interrupt, NULL);
|
||||||
ps2_service_exit();
|
ps2_service_exit();
|
||||||
ps2_dev_exit();
|
ps2_dev_exit();
|
||||||
delete_sem(gDeviceOpenSemaphore);
|
|
||||||
delete_sem(sKbcSem);
|
delete_sem(sKbcSem);
|
||||||
put_module(B_ISA_MODULE_NAME);
|
put_module(B_ISA_MODULE_NAME);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,6 @@
|
|||||||
|
|
||||||
// global variables
|
// global variables
|
||||||
extern isa_module_info *gIsa;
|
extern isa_module_info *gIsa;
|
||||||
extern sem_id gDeviceOpenSemaphore;
|
|
||||||
|
|
||||||
extern device_hooks sKeyboardDeviceHooks;
|
extern device_hooks sKeyboardDeviceHooks;
|
||||||
extern device_hooks sMouseDeviceHooks;
|
extern device_hooks sMouseDeviceHooks;
|
||||||
|
|||||||
@@ -12,9 +12,7 @@
|
|||||||
#include "ps2_dev.h"
|
#include "ps2_dev.h"
|
||||||
#include "ps2_service.h"
|
#include "ps2_service.h"
|
||||||
|
|
||||||
#define PS2_DEV_COUNT 5
|
ps2_dev ps2_device[PS2_DEVICE_COUNT] =
|
||||||
|
|
||||||
ps2_dev ps2_device[PS2_DEV_COUNT] =
|
|
||||||
{
|
{
|
||||||
{ .name = "input/mouse/ps2/0", .active = false, .idx = 0, .result_sem = -1 },
|
{ .name = "input/mouse/ps2/0", .active = false, .idx = 0, .result_sem = -1 },
|
||||||
{ .name = "input/mouse/ps2/1", .active = false, .idx = 1, .result_sem = -1 },
|
{ .name = "input/mouse/ps2/1", .active = false, .idx = 1, .result_sem = -1 },
|
||||||
@@ -28,7 +26,7 @@ status_t
|
|||||||
ps2_dev_init(void)
|
ps2_dev_init(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < PS2_DEV_COUNT; i++) {
|
for (i = 0; i < PS2_DEVICE_COUNT; i++) {
|
||||||
ps2_dev *dev = &ps2_device[i];
|
ps2_dev *dev = &ps2_device[i];
|
||||||
dev->result_sem = create_sem(0, "ps2 result");
|
dev->result_sem = create_sem(0, "ps2 result");
|
||||||
if (dev->result_sem < 0)
|
if (dev->result_sem < 0)
|
||||||
@@ -45,7 +43,7 @@ void
|
|||||||
ps2_dev_exit(void)
|
ps2_dev_exit(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < PS2_DEV_COUNT; i++) {
|
for (i = 0; i < PS2_DEVICE_COUNT; i++) {
|
||||||
ps2_dev *dev = &ps2_device[i];
|
ps2_dev *dev = &ps2_device[i];
|
||||||
if (dev->result_sem >= 0) {
|
if (dev->result_sem >= 0) {
|
||||||
delete_sem(dev->result_sem);
|
delete_sem(dev->result_sem);
|
||||||
@@ -96,6 +94,8 @@ ps2_dev_handle_int(ps2_dev *dev, uint8 data)
|
|||||||
if (flags & PS2_FLAG_CMD) {
|
if (flags & PS2_FLAG_CMD) {
|
||||||
if ((flags & (PS2_FLAG_ACK | PS2_FLAG_NACK)) == 0) {
|
if ((flags & (PS2_FLAG_ACK | PS2_FLAG_NACK)) == 0) {
|
||||||
atomic_or(&dev->flags, data == 0xfa ? PS2_FLAG_ACK : PS2_FLAG_NACK);
|
atomic_or(&dev->flags, data == 0xfa ? PS2_FLAG_ACK : PS2_FLAG_NACK);
|
||||||
|
release_sem_etc(dev->result_sem, 1, B_DO_NOT_RESCHEDULE);
|
||||||
|
return B_INVOKE_SCHEDULER;
|
||||||
} else if (dev->result_buf_cnt) {
|
} else if (dev->result_buf_cnt) {
|
||||||
dev->result_buf[dev->result_buf_idx] = data;
|
dev->result_buf[dev->result_buf_idx] = data;
|
||||||
dev->result_buf_idx++;
|
dev->result_buf_idx++;
|
||||||
@@ -133,6 +133,7 @@ status_t
|
|||||||
ps2_dev_command(ps2_dev *dev, uint8 cmd, const uint8 *out, int out_count, uint8 *in, int in_count)
|
ps2_dev_command(ps2_dev *dev, uint8 cmd, const uint8 *out, int out_count, uint8 *in, int in_count)
|
||||||
{
|
{
|
||||||
status_t res = B_OK;
|
status_t res = B_OK;
|
||||||
|
bigtime_t start;
|
||||||
int i, count;
|
int i, count;
|
||||||
|
|
||||||
dprintf("ps2_dev_command %02x, %d out, in %d, dev %s\n", cmd, out_count, in_count, dev->name);
|
dprintf("ps2_dev_command %02x, %d out, in %d, dev %s\n", cmd, out_count, in_count, dev->name);
|
||||||
@@ -143,6 +144,8 @@ ps2_dev_command(ps2_dev *dev, uint8 cmd, const uint8 *out, int out_count, uint8
|
|||||||
dev->result_buf_cnt = in_count;
|
dev->result_buf_cnt = in_count;
|
||||||
dev->result_buf_idx = 0;
|
dev->result_buf_idx = 0;
|
||||||
dev->result_buf = in;
|
dev->result_buf = in;
|
||||||
|
|
||||||
|
start = system_time();
|
||||||
|
|
||||||
for (i = -1; res == B_OK && i < out_count; i++) {
|
for (i = -1; res == B_OK && i < out_count; i++) {
|
||||||
|
|
||||||
@@ -162,6 +165,14 @@ ps2_dev_command(ps2_dev *dev, uint8 cmd, const uint8 *out, int out_count, uint8
|
|||||||
ps2_write_data(i == -1 ? cmd : out[i]);
|
ps2_write_data(i == -1 ? cmd : out[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dprintf("ps2_dev_command send-time %Ld\n", system_time() - start);
|
||||||
|
|
||||||
|
|
||||||
|
start = system_time();
|
||||||
|
res = acquire_sem_etc(dev->result_sem, 1, B_RELATIVE_TIMEOUT, 4000000);
|
||||||
|
dprintf("ps2_dev_command wait for ack res %08x, wait-time %Ld\n", res, system_time() - start);
|
||||||
|
|
||||||
|
|
||||||
if (dev->flags & PS2_FLAG_ACK) {
|
if (dev->flags & PS2_FLAG_ACK) {
|
||||||
dprintf("ps2_dev_command got ACK\n");
|
dprintf("ps2_dev_command got ACK\n");
|
||||||
@@ -179,13 +190,15 @@ ps2_dev_command(ps2_dev *dev, uint8 cmd, const uint8 *out, int out_count, uint8
|
|||||||
|
|
||||||
if (in_count != 0) {
|
if (in_count != 0) {
|
||||||
dprintf("ps2_dev_command waiting for result\n");
|
dprintf("ps2_dev_command waiting for result\n");
|
||||||
|
|
||||||
|
start = system_time();
|
||||||
|
|
||||||
res = acquire_sem_etc(dev->result_sem, 1, B_RELATIVE_TIMEOUT, 4000000);
|
res = acquire_sem_etc(dev->result_sem, 1, B_RELATIVE_TIMEOUT, 4000000);
|
||||||
|
|
||||||
count = in_count - dev->result_buf_cnt;
|
count = in_count - dev->result_buf_cnt;
|
||||||
dev->result_buf_cnt = 0;
|
dev->result_buf_cnt = 0;
|
||||||
|
|
||||||
dprintf("ps2_dev_command res %08x, in %d\n", res, count);
|
dprintf("ps2_dev_command res %08x, in %d, wait-time %Ld\n", res, count, system_time() - start);
|
||||||
|
|
||||||
for (i = 0; i < count; i++)
|
for (i = 0; i < count; i++)
|
||||||
dprintf("ps2_dev_command data %02x\n", in[i]);
|
dprintf("ps2_dev_command data %02x\n", in[i]);
|
||||||
|
|||||||
@@ -29,7 +29,9 @@ struct ps2_dev
|
|||||||
void * cookie;
|
void * cookie;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern ps2_dev ps2_device[5];
|
#define PS2_DEVICE_COUNT 5
|
||||||
|
|
||||||
|
extern ps2_dev ps2_device[PS2_DEVICE_COUNT];
|
||||||
|
|
||||||
#define PS2_DEVICE_MOUSE 0
|
#define PS2_DEVICE_MOUSE 0
|
||||||
#define PS2_DEVICE_KEYB 4
|
#define PS2_DEVICE_KEYB 4
|
||||||
|
|||||||
@@ -211,8 +211,6 @@ keyboard_open(const char *name, uint32 flags, void **_cookie)
|
|||||||
if (atomic_or(&sKeyboardOpenMask, 1) != 0)
|
if (atomic_or(&sKeyboardOpenMask, 1) != 0)
|
||||||
return B_BUSY;
|
return B_BUSY;
|
||||||
|
|
||||||
acquire_sem(gDeviceOpenSemaphore);
|
|
||||||
|
|
||||||
sKeyboardSem = create_sem(0, "keyboard_sem");
|
sKeyboardSem = create_sem(0, "keyboard_sem");
|
||||||
if (sKeyboardSem < 0) {
|
if (sKeyboardSem < 0) {
|
||||||
status = sKeyboardSem;
|
status = sKeyboardSem;
|
||||||
@@ -227,8 +225,6 @@ keyboard_open(const char *name, uint32 flags, void **_cookie)
|
|||||||
|
|
||||||
atomic_or(&ps2_device[PS2_DEVICE_KEYB].flags, PS2_FLAG_ENABLED);
|
atomic_or(&ps2_device[PS2_DEVICE_KEYB].flags, PS2_FLAG_ENABLED);
|
||||||
|
|
||||||
release_sem(gDeviceOpenSemaphore);
|
|
||||||
|
|
||||||
*_cookie = NULL;
|
*_cookie = NULL;
|
||||||
|
|
||||||
TRACE(("keyboard_open(): done.\n"));
|
TRACE(("keyboard_open(): done.\n"));
|
||||||
@@ -241,7 +237,6 @@ err3:
|
|||||||
err2:
|
err2:
|
||||||
err1:
|
err1:
|
||||||
atomic_and(&sKeyboardOpenMask, 0);
|
atomic_and(&sKeyboardOpenMask, 0);
|
||||||
release_sem(gDeviceOpenSemaphore);
|
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -323,7 +323,7 @@ mouse_open(const char *name, uint32 flags, void **_cookie)
|
|||||||
|
|
||||||
TRACE(("mouse_open() %s\n", name));
|
TRACE(("mouse_open() %s\n", name));
|
||||||
|
|
||||||
for (dev = NULL, i = 0; i < 5; i++) {
|
for (dev = NULL, i = 0; i < PS2_DEVICE_COUNT; i++) {
|
||||||
if (0 == strcmp(ps2_device[i].name, name)) {
|
if (0 == strcmp(ps2_device[i].name, name)) {
|
||||||
dev = &ps2_device[i];
|
dev = &ps2_device[i];
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user