- added register/unregister methods for removable mouse devices and updated

usb_hid code to use them
- removed mouse handling from the USB host controller code
- TODO: add similar code for keyboard devices
This commit is contained in:
Volker Ruppert 2009-03-02 21:21:16 +00:00
parent 7f9717dd10
commit 3c21d494cb
9 changed files with 71 additions and 106 deletions

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: devices.cc,v 1.141 2009-02-23 18:38:25 vruppert Exp $
// $Id: devices.cc,v 1.142 2009-03-02 21:21:16 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2002 MandrakeSoft S.A.
@ -120,7 +120,7 @@ void bx_devices_c::init(BX_MEM_C *newmem)
const char *plugname;
#endif
BX_DEBUG(("Init $Id: devices.cc,v 1.141 2009-02-23 18:38:25 vruppert Exp $"));
BX_DEBUG(("Init $Id: devices.cc,v 1.142 2009-03-02 21:21:16 vruppert Exp $"));
mem = newmem;
/* set builtin default handlers, will be overwritten by the real default handler */
@ -153,6 +153,9 @@ void bx_devices_c::init(BX_MEM_C *newmem)
}
// common mouse settings
bx_mouse_dev = NULL;
bx_mouse_enq = NULL;
bx_mouse_enabled_changed = NULL;
mouse_captured = SIM->get_param_bool(BXPN_MOUSE_ENABLED)->get();
mouse_type = SIM->get_param_enum(BXPN_MOUSE_TYPE)->get();
@ -1060,42 +1063,48 @@ bx_bool bx_devices_c::is_usb_uhci_enabled(void)
}
// common mouse device handlers
void bx_devices_c::register_removable_mouse(void *dev, bx_mouse_enq_t mouse_enq,
bx_mouse_enabled_changed_t mouse_enabled_changed)
{
if (bx_mouse_dev == NULL) {
bx_mouse_dev = dev;
bx_mouse_enq = mouse_enq;
bx_mouse_enabled_changed = mouse_enabled_changed;
}
}
void bx_devices_c::unregister_removable_mouse(void *dev)
{
if (dev == bx_mouse_dev) {
bx_mouse_dev = NULL;
bx_mouse_enq = NULL;
bx_mouse_enabled_changed = NULL;
}
}
void bx_devices_c::mouse_enabled_changed(bx_bool enabled)
{
mouse_captured = enabled;
#if BX_SUPPORT_USB_UHCI
if (pluginUSB_UHCI->usb_mouse_enabled_changed(enabled)) {
if (bx_mouse_dev != NULL) {
bx_mouse_enabled_changed(bx_mouse_dev, enabled);
return;
}
#endif
#if BX_SUPPORT_USB_OHCI
if (pluginUSB_OHCI->usb_mouse_enabled_changed(enabled)) {
return;
}
#endif
pluginKeyboard->mouse_enabled_changed(enabled);
}
void bx_devices_c::mouse_motion(int delta_x, int delta_y, int delta_z, unsigned button_state)
{
// If mouse events are disabled on the GUI headerbar, don't
// generate any mouse data
if (!mouse_captured)
return;
// if an usb mouse is connected, redirect mouse data to the usb device
#if BX_SUPPORT_USB_UHCI
if (pluginUSB_UHCI->usb_mouse_enq(delta_x, delta_y, delta_z, button_state)) {
// if a removable mouse is connected, redirect mouse data to the device
if (bx_mouse_dev != NULL) {
bx_mouse_enq(bx_mouse_dev, delta_x, delta_y, delta_z, button_state);
return;
}
#endif
#if BX_SUPPORT_USB_OHCI
if (pluginUSB_OHCI->usb_mouse_enq(delta_x, delta_y, delta_z, button_state)) {
return;
}
#endif
// if type == serial, redirect mouse data to the serial device
if ((mouse_type == BX_MOUSE_TYPE_SERIAL) ||

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: iodev.h,v 1.111 2009-02-23 18:38:25 vruppert Exp $
// $Id: iodev.h,v 1.112 2009-03-02 21:21:16 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2002 MandrakeSoft S.A.
@ -48,6 +48,9 @@ class bx_g2h_c;
typedef Bit32u (*bx_read_handler_t)(void *, Bit32u, unsigned);
typedef void (*bx_write_handler_t)(void *, Bit32u, Bit32u, unsigned);
typedef void (*bx_mouse_enq_t)(void *, int, int, int, unsigned);
typedef void (*bx_mouse_enabled_changed_t)(void *, bx_bool);
#if BX_USE_DEV_SMF
# define BX_DEV_SMF static
# define BX_DEV_THIS bx_devices.
@ -332,12 +335,6 @@ public:
#if BX_SUPPORT_PCIUSB
class BOCHSAPI bx_pci_usb_stub_c : public bx_devmodel_c, public bx_pci_device_stub_c {
public:
virtual bx_bool usb_mouse_enq(int delta_x, int delta_y, int delta_z, unsigned button_state) {
return 0;
}
virtual bx_bool usb_mouse_enabled_changed(bx_bool enabled) {
return 0;
}
virtual bx_bool usb_key_enq(Bit8u *scan_code) {
return 0;
}
@ -424,6 +421,8 @@ public:
bx_bool unregister_irq(unsigned irq, const char *name);
Bit32u inp(Bit16u addr, unsigned io_len) BX_CPP_AttrRegparmN(2);
void outp(Bit16u addr, Bit32u value, unsigned io_len) BX_CPP_AttrRegparmN(3);
void register_removable_mouse(void *dev, bx_mouse_enq_t mouse_enq, bx_mouse_enabled_changed_t mouse_enabled_changed);
void unregister_removable_mouse(void *dev);
void mouse_enabled_changed(bx_bool enabled);
void mouse_motion(int delta_x, int delta_y, int delta_z, unsigned button_state);
@ -538,6 +537,9 @@ private:
bx_bool mouse_captured; // host mouse capture enabled
Bit8u mouse_type;
void *bx_mouse_dev;
bx_mouse_enq_t bx_mouse_enq;
bx_mouse_enabled_changed_t bx_mouse_enabled_changed;
int timer_handle;

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: usb_hid.cc,v 1.14 2009-02-14 10:06:20 vruppert Exp $
// $Id: usb_hid.cc,v 1.15 2009-03-02 21:21:16 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2009 Volker Ruppert
@ -360,8 +360,10 @@ usb_hid_device_c::usb_hid_device_c(usbdev_type type)
d.speed = USB_SPEED_LOW;
if (d.type == USB_DEV_TYPE_MOUSE) {
strcpy(d.devname, "USB Mouse");
DEV_register_removable_mouse((void*)this, mouse_enq_static, mouse_enabled_changed);
} else if (d.type == USB_DEV_TYPE_TABLET) {
strcpy(d.devname, "USB Tablet");
DEV_register_removable_mouse((void*)this, mouse_enq_static, mouse_enabled_changed);
} else if (d.type == USB_DEV_TYPE_KEYPAD) {
strcpy(d.devname, "USB/PS2 Keypad");
}
@ -373,6 +375,10 @@ usb_hid_device_c::usb_hid_device_c(usbdev_type type)
usb_hid_device_c::~usb_hid_device_c(void)
{
if ((d.type == USB_DEV_TYPE_MOUSE) ||
(d.type == USB_DEV_TYPE_TABLET)) {
DEV_unregister_removable_mouse((void*)this);
}
}
void usb_hid_device_c::register_state_specific(bx_list_c *parent)
@ -659,6 +665,16 @@ int usb_hid_device_c::mouse_poll(Bit8u *buf, int len)
return l;
}
void usb_hid_device_c::mouse_enabled_changed(void *dev, bx_bool enabled)
{
if (enabled) ((usb_hid_device_c*)dev)->handle_reset();
}
void usb_hid_device_c::mouse_enq_static(void *dev, int delta_x, int delta_y, int delta_z, unsigned button_state)
{
((usb_hid_device_c*)dev)->mouse_enq(delta_x, delta_y, delta_z, button_state);
}
void usb_hid_device_c::mouse_enq(int delta_x, int delta_y, int delta_z, unsigned button_state)
{
if (d.type == USB_DEV_TYPE_MOUSE) {

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: usb_hid.h,v 1.9 2009-02-08 09:05:52 vruppert Exp $
// $Id: usb_hid.h,v 1.10 2009-03-02 21:21:16 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2009 Volker Ruppert
@ -34,11 +34,7 @@ public:
virtual int handle_control(int request, int value, int index, int length, Bit8u *data);
virtual int handle_data(USBPacket *p);
virtual void register_state_specific(bx_list_c *parent);
void mouse_enq(int delta_x, int delta_y, int delta_z, unsigned button_state);
bx_bool key_enq(Bit8u *scan_code);
protected:
int mouse_poll(Bit8u *buf, int len);
int keypad_poll(Bit8u *buf, int len);
private:
struct {
@ -52,6 +48,12 @@ private:
Bit8u saved_key[8];
Bit8u key_pad_packet[8];
} s;
static void mouse_enabled_changed(void *dev, bx_bool enabled);
static void mouse_enq_static(void *dev, int delta_x, int delta_y, int delta_z, unsigned button_state);
void mouse_enq(int delta_x, int delta_y, int delta_z, unsigned button_state);
int mouse_poll(Bit8u *buf, int len);
int keypad_poll(Bit8u *buf, int len);
};
#endif

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: usb_ohci.cc,v 1.12 2009-03-01 19:29:36 vruppert Exp $
// $Id: usb_ohci.cc,v 1.13 2009-03-02 21:21:16 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2009 Benjamin D Lunt (fys at frontiernet net)
@ -152,7 +152,6 @@ void bx_usb_ohci_c::init(void)
for (i=0; i<USB_NUM_PORTS; i++) {
BX_OHCI_THIS hub.usb_port[i].device = NULL;
}
BX_OHCI_THIS mousedev = NULL;
BX_OHCI_THIS keybdev = NULL;
//HACK: Turn on debug messages from the start
@ -465,15 +464,9 @@ void bx_usb_ohci_c::init_device(Bit8u port, const char *devname)
if (!strcmp(devname, "mouse")) {
type = USB_DEV_TYPE_MOUSE;
BX_OHCI_THIS hub.usb_port[port].device = new usb_hid_device_c(type);
if (BX_OHCI_THIS mousedev == NULL) {
BX_OHCI_THIS mousedev = (usb_hid_device_c*)BX_OHCI_THIS hub.usb_port[port].device;
}
} else if (!strcmp(devname, "tablet")) {
type = USB_DEV_TYPE_TABLET;
BX_OHCI_THIS hub.usb_port[port].device = new usb_hid_device_c(type);
if (BX_OHCI_THIS mousedev == NULL) {
BX_OHCI_THIS mousedev = (usb_hid_device_c*)BX_OHCI_THIS hub.usb_port[port].device;
}
} else if (!strcmp(devname, "keypad")) {
type = USB_DEV_TYPE_KEYPAD;
BX_OHCI_THIS hub.usb_port[port].device = new usb_hid_device_c(type);
@ -505,12 +498,7 @@ void bx_usb_ohci_c::remove_device(Bit8u port)
if (BX_OHCI_THIS hub.usb_port[port].device != NULL) {
type = BX_OHCI_THIS hub.usb_port[port].device->get_type();
if ((type == USB_DEV_TYPE_MOUSE) ||
(type == USB_DEV_TYPE_TABLET)) {
if (BX_OHCI_THIS hub.usb_port[port].device == BX_OHCI_THIS mousedev) {
BX_OHCI_THIS mousedev = NULL;
}
} else if (type == USB_DEV_TYPE_KEYPAD) {
if (type == USB_DEV_TYPE_KEYPAD) {
if (BX_OHCI_THIS hub.usb_port[port].device == BX_OHCI_THIS keybdev) {
BX_OHCI_THIS keybdev = NULL;
}
@ -1479,15 +1467,6 @@ void bx_usb_ohci_c::pci_write_handler(Bit8u address, Bit32u value, unsigned io_l
BX_DEBUG(("USB OHCI write register 0x%02x value 0x%s", address, szTmp));
}
bx_bool bx_usb_ohci_c::usb_mouse_enabled_changed(bx_bool enabled)
{
if (BX_OHCI_THIS mousedev != NULL) {
if (enabled) mousedev->handle_reset();
return 1;
}
return 0;
}
void bx_usb_ohci_c::usb_set_connect_status(Bit8u port, int type, bx_bool connected)
{
usb_device_c *device = BX_OHCI_THIS hub.usb_port[port].device;
@ -1522,15 +1501,6 @@ void bx_usb_ohci_c::usb_set_connect_status(Bit8u port, int type, bx_bool connect
}
}
bx_bool bx_usb_ohci_c::usb_mouse_enq(int delta_x, int delta_y, int delta_z, unsigned button_state)
{
if (BX_OHCI_THIS mousedev != NULL) {
mousedev->mouse_enq(delta_x, delta_y, delta_z, button_state);
return 1;
}
return 0;
}
bx_bool bx_usb_ohci_c::usb_key_enq(Bit8u *scan_code)
{
if (BX_OHCI_THIS keybdev != NULL) {

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: usb_ohci.h,v 1.8 2009-03-01 19:29:36 vruppert Exp $
// $Id: usb_ohci.h,v 1.9 2009-03-02 21:21:16 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2009 Benjamin D Lunt (fys at frontiernet net)
@ -253,8 +253,6 @@ public:
virtual ~bx_usb_ohci_c();
virtual void init(void);
virtual void reset(unsigned);
virtual bx_bool usb_mouse_enq(int delta_x, int delta_y, int delta_z, unsigned button_state);
virtual bx_bool usb_mouse_enabled_changed(bx_bool enable);
virtual bx_bool usb_key_enq(Bit8u *scan_code);
virtual void register_state(void);
virtual void after_restore_state(void);
@ -269,7 +267,6 @@ private:
bx_usb_ohci_t hub;
Bit8u *device_buffer;
usb_hid_device_c *mousedev;
usb_hid_device_c *keybdev;
USBPacket usb_packet;

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: usb_uhci.cc,v 1.10 2009-03-01 19:29:36 vruppert Exp $
// $Id: usb_uhci.cc,v 1.11 2009-03-02 21:21:16 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2009 Benjamin D Lunt (fys at frontiernet net)
@ -116,7 +116,6 @@ void bx_usb_uhci_c::init(void)
for (i=0; i<USB_NUM_PORTS; i++) {
BX_UHCI_THIS hub.usb_port[i].device = NULL;
}
BX_UHCI_THIS mousedev = NULL;
BX_UHCI_THIS keybdev = NULL;
//HACK: Turn on debug messages from the start
@ -295,15 +294,9 @@ void bx_usb_uhci_c::init_device(Bit8u port, const char *devname)
if (!strcmp(devname, "mouse")) {
type = USB_DEV_TYPE_MOUSE;
BX_UHCI_THIS hub.usb_port[port].device = new usb_hid_device_c(type);
if (BX_UHCI_THIS mousedev == NULL) {
BX_UHCI_THIS mousedev = (usb_hid_device_c*)BX_UHCI_THIS hub.usb_port[port].device;
}
} else if (!strcmp(devname, "tablet")) {
type = USB_DEV_TYPE_TABLET;
BX_UHCI_THIS hub.usb_port[port].device = new usb_hid_device_c(type);
if (BX_UHCI_THIS mousedev == NULL) {
BX_UHCI_THIS mousedev = (usb_hid_device_c*)BX_UHCI_THIS hub.usb_port[port].device;
}
} else if (!strcmp(devname, "keypad")) {
type = USB_DEV_TYPE_KEYPAD;
BX_UHCI_THIS hub.usb_port[port].device = new usb_hid_device_c(type);
@ -335,12 +328,7 @@ void bx_usb_uhci_c::remove_device(Bit8u port)
if (BX_UHCI_THIS hub.usb_port[port].device != NULL) {
type = BX_UHCI_THIS hub.usb_port[port].device->get_type();
if ((type == USB_DEV_TYPE_MOUSE) ||
(type == USB_DEV_TYPE_TABLET)) {
if (BX_UHCI_THIS hub.usb_port[port].device == BX_UHCI_THIS mousedev) {
BX_UHCI_THIS mousedev = NULL;
}
} else if (type == USB_DEV_TYPE_KEYPAD) {
if (type == USB_DEV_TYPE_KEYPAD) {
if (BX_UHCI_THIS hub.usb_port[port].device == BX_UHCI_THIS keybdev) {
BX_UHCI_THIS keybdev = NULL;
}
@ -1080,15 +1068,6 @@ void bx_usb_uhci_c::pci_write_handler(Bit8u address, Bit32u value, unsigned io_l
BX_DEBUG(("USB UHCI write register 0x%02x value 0x%s", address, szTmp));
}
bx_bool bx_usb_uhci_c::usb_mouse_enabled_changed(bx_bool enabled)
{
if (BX_UHCI_THIS mousedev != NULL) {
if (enabled) mousedev->handle_reset();
return 1;
}
return 0;
}
void bx_usb_uhci_c::usb_set_connect_status(Bit8u port, int type, bx_bool connected)
{
usb_device_c *device = BX_UHCI_THIS hub.usb_port[port].device;
@ -1141,15 +1120,6 @@ void bx_usb_uhci_c::usb_set_connect_status(Bit8u port, int type, bx_bool connect
}
}
bx_bool bx_usb_uhci_c::usb_mouse_enq(int delta_x, int delta_y, int delta_z, unsigned button_state)
{
if (BX_UHCI_THIS mousedev != NULL) {
mousedev->mouse_enq(delta_x, delta_y, delta_z, button_state);
return 1;
}
return 0;
}
bx_bool bx_usb_uhci_c::usb_key_enq(Bit8u *scan_code)
{
if (BX_UHCI_THIS keybdev != NULL) {

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: usb_uhci.h,v 1.6 2009-03-01 19:29:36 vruppert Exp $
// $Id: usb_uhci.h,v 1.7 2009-03-02 21:21:16 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2009 Benjamin D Lunt (fys at frontiernet net)
@ -187,8 +187,6 @@ public:
virtual ~bx_usb_uhci_c();
virtual void init(void);
virtual void reset(unsigned);
virtual bx_bool usb_mouse_enq(int delta_x, int delta_y, int delta_z, unsigned button_state);
virtual bx_bool usb_mouse_enabled_changed(bx_bool enabled);
virtual bx_bool usb_key_enq(Bit8u *scan_code);
virtual void register_state(void);
virtual void after_restore_state(void);
@ -204,7 +202,6 @@ private:
bx_bool busy;
Bit8u *device_buffer;
usb_hid_device_c *mousedev;
usb_hid_device_c *keybdev;
USBPacket usb_packet;

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: plugin.h,v 1.75 2009-02-23 18:38:25 vruppert Exp $
// $Id: plugin.h,v 1.76 2009-03-02 21:21:16 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2009 The Bochs Project
@ -124,6 +124,8 @@ extern "C" {
#define DEV_mouse_enabled_changed(en) (bx_devices.mouse_enabled_changed(en))
#define DEV_mouse_motion(dx, dy, state) (bx_devices.mouse_motion(dx, dy, 0, state))
#define DEV_mouse_motion_ext(dx, dy, dz, state) (bx_devices.mouse_motion(dx, dy, dz, state))
#define DEV_register_removable_mouse(a,b,c) (bx_devices.register_removable_mouse(a,b,c))
#define DEV_unregister_removable_mouse(a) (bx_devices.unregister_removable_mouse(a))
///////// I/O APIC macros
#define DEV_ioapic_present() (bx_devices.pluginIOAPIC != &bx_devices.stubIOAPIC)