- number of ports for the external hub can be configured with the device name

now. Valid values are 2 to 8 and the default is set to 4 ports (device name
  "hub" uses the default, "hub:7" enables 7 ports.
This commit is contained in:
Volker Ruppert 2009-03-12 20:24:56 +00:00
parent 87c4564a98
commit c0d9238170
4 changed files with 46 additions and 26 deletions

View File

@ -717,16 +717,22 @@ i440fxsupport: enabled=1
# USB_UHCI:
# This option controls the presence of the USB root hub which is a part
# of the i440FX PCI chipset. With the portX option you can connect devices
# to the hub (currently supported: 'mouse', 'tablet', 'keypad' and 'disk').
# to the hub (currently supported: 'mouse', 'tablet', 'keypad', 'disk' and
# 'hub').
# If you connect the mouse or tablet to one of the ports, Bochs forwards the
# mouse movement data to the USB device instead of the selected mouse type.
# When connecting the keypad to one of the ports, Bochs forwards the input of
# the numeric keypad to the USB device instead of the PS/2 keyboard.
# To connect a flat image as an USB hardisk you can use the 'disk' device with
# the path to the image separated with a colon (see below).
# The device name 'hub' connects an external hub with max. 8 ports (default: 4)
# to the root hub. To specify the number of ports you have to add the value
# separated with a colon. Connecting devices to the external hub ports is only
# available in the runtime configuration.
#=======================================================================
#usb_uhci: enabled=1
#usb_uhci: enabled=1, port1=mouse, port2=disk:usbdisk.img
#usb_uhci: enabled=1, port1=hub:7
#=======================================================================
# CMOSIMAGE:

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: usb_common.cc,v 1.7 2009-03-09 12:18:40 vruppert Exp $
// $Id: usb_common.cc,v 1.8 2009-03-12 20:24:56 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2009 Benjamin D Lunt (fys at frontiernet net)
@ -63,6 +63,7 @@
usbdev_type usb_init_device(const char *devname, logfunctions *hub, usb_device_c **device)
{
usbdev_type type = USB_DEV_TYPE_NONE;
int ports;
if (!strcmp(devname, "mouse")) {
type = USB_DEV_TYPE_MOUSE;
@ -89,9 +90,20 @@ usbdev_type usb_init_device(const char *devname, logfunctions *hub, usb_device_c
// hub->panic("USB device 'cdrom' needs a filename separated with a colon");
// return type;
// }
} else if (!strcmp(devname, "hub")) {
} else if (!strncmp(devname, "hub", 3)) {
type = USB_DEV_TYPE_HUB;
*device = new usb_hub_device_c();
ports = 4;
if (strlen(devname) > 3) {
if (devname[3] == ':') {
ports = atoi(&devname[4]);
if ((ports < 2) || (ports > 8)) {
hub->panic("USB device 'hub': invalid number of ports");
}
} else {
hub->panic("USB device 'hub' needs the port count separated with a colon");
}
}
*device = new usb_hub_device_c(ports);
} else {
hub->panic("unknown USB device: %s", devname);
return type;

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: usb_hub.cc,v 1.3 2009-03-09 14:44:06 vruppert Exp $
// $Id: usb_hub.cc,v 1.4 2009-03-12 20:24:56 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2009 Volker Ruppert
@ -231,7 +231,7 @@ static usb_hub_device_c *find_usb_hub(const char *name)
}
usb_hub_device_c::usb_hub_device_c()
usb_hub_device_c::usb_hub_device_c(Bit8u ports)
{
int i;
char pname[10];
@ -243,7 +243,8 @@ usb_hub_device_c::usb_hub_device_c()
strcpy(d.devname, "Bochs USB HUB");
d.connected = 1;
memset((void*)&hub, 0, sizeof(hub));
for(i = 0; i < USB_HUB_NUM_PORTS; i++) {
hub.n_ports = ports;
for(i = 0; i < hub.n_ports; i++) {
hub.usb_port[i].PortStatus = PORT_STAT_POWER;
hub.usb_port[i].PortChange = 0;
}
@ -254,10 +255,10 @@ usb_hub_device_c::usb_hub_device_c()
bx_list_c *usb_rt = (bx_list_c*)SIM->get_param(BXPN_MENU_RUNTIME_USB);
sprintf(pname, "exthub%d", ++hub_count);
sprintf(label, "External Hub #%d Configuration", hub_count);
hub.config = new bx_list_c(usb, pname, label, USB_HUB_NUM_PORTS);
hub.config = new bx_list_c(usb, pname, label, hub.n_ports);
hub.config->get_options()->set(bx_list_c::SHOW_PARENT | bx_list_c::USE_BOX_TITLE);
usb_rt->add(hub.config);
for(i = 0; i < USB_HUB_NUM_PORTS; i++) {
for(i = 0; i < hub.n_ports; i++) {
sprintf(pname, "port%d", i+1);
sprintf(label, "Port #%d device", i+1);
port = new bx_param_string_c(hub.config, pname, label, "", "", BX_PATHNAME_LEN);
@ -270,7 +271,7 @@ usb_hub_device_c::usb_hub_device_c()
usb_hub_device_c::~usb_hub_device_c(void)
{
for (int i=0; i<USB_HUB_NUM_PORTS; i++) {
for (int i=0; i<hub.n_ports; i++) {
remove_device(i);
}
bx_list_c *usb_rt = (bx_list_c*)SIM->get_param(BXPN_MENU_RUNTIME_USB);
@ -289,8 +290,8 @@ void usb_hub_device_c::register_state_specific(bx_list_c *parent)
char portnum[6];
bx_list_c *port;
hub.state = new bx_list_c(parent, "hub", "USB HUB Device State", USB_HUB_NUM_PORTS);
for (i=0; i<USB_HUB_NUM_PORTS; i++) {
hub.state = new bx_list_c(parent, "hub", "USB HUB Device State", hub.n_ports);
for (i=0; i<hub.n_ports; i++) {
sprintf(portnum, "port%d", i+1);
port = new bx_list_c(hub.state, portnum, 3);
new bx_shadow_num_c(port, "PortStatus", &hub.usb_port[i].PortStatus, BASE_HEX);
@ -302,7 +303,7 @@ void usb_hub_device_c::register_state_specific(bx_list_c *parent)
void usb_hub_device_c::after_restore_state()
{
for (int i=0; i<USB_HUB_NUM_PORTS; i++) {
for (int i=0; i<hub.n_ports; i++) {
if (hub.usb_port[i].device != NULL) {
hub.usb_port[i].device->after_restore_state();
}
@ -366,7 +367,7 @@ int usb_hub_device_c::handle_control(int request, int value, int index, int leng
/* status change endpoint size based on number
* of ports */
data[22] = (USB_HUB_NUM_PORTS + 1 + 7) / 8;
data[22] = (hub.n_ports + 1 + 7) / 8;
ret = sizeof(bx_hub_config_descriptor);
break;
@ -424,7 +425,7 @@ int usb_hub_device_c::handle_control(int request, int value, int index, int leng
break;
case GetPortStatus:
n = index - 1;
if (n >= USB_HUB_NUM_PORTS)
if (n >= hub.n_ports)
goto fail;
data[0] = (hub.usb_port[n].PortStatus & 0xff);
data[1] = (hub.usb_port[n].PortStatus >> 8);
@ -442,7 +443,7 @@ int usb_hub_device_c::handle_control(int request, int value, int index, int leng
break;
case SetPortFeature:
n = index - 1;
if (n >= USB_HUB_NUM_PORTS)
if (n >= hub.n_ports)
goto fail;
switch(value) {
case PORT_SUSPEND:
@ -465,7 +466,7 @@ int usb_hub_device_c::handle_control(int request, int value, int index, int leng
break;
case ClearPortFeature:
n = index - 1;
if (n >= USB_HUB_NUM_PORTS)
if (n >= hub.n_ports)
goto fail;
switch(value) {
case PORT_ENABLE:
@ -499,17 +500,17 @@ int usb_hub_device_c::handle_control(int request, int value, int index, int leng
unsigned int limit, var_hub_size = 0;
memcpy(data, bx_hub_hub_descriptor,
sizeof(bx_hub_hub_descriptor));
data[2] = USB_HUB_NUM_PORTS;
data[2] = hub.n_ports;
/* fill DeviceRemovable bits */
limit = ((USB_HUB_NUM_PORTS + 1 + 7) / 8) + 7;
limit = ((hub.n_ports + 1 + 7) / 8) + 7;
for (n = 7; n < limit; n++) {
data[n] = 0x00;
var_hub_size++;
}
/* fill PortPwrCtrlMask bits */
limit = limit + ((USB_HUB_NUM_PORTS + 7) / 8);
limit = limit + ((hub.n_ports + 7) / 8);
for (;n < limit; n++) {
data[n] = 0xff;
var_hub_size++;
@ -536,14 +537,14 @@ int usb_hub_device_c::handle_data(USBPacket *p)
if (p->devep == 1) {
unsigned int status;
int i, n;
n = (USB_HUB_NUM_PORTS + 1 + 7) / 8;
n = (hub.n_ports + 1 + 7) / 8;
if (p->len == 1) { /* FreeBSD workaround */
n = 1;
} else if (n > p->len) {
return USB_RET_BABBLE;
}
status = 0;
for(i = 0; i < USB_HUB_NUM_PORTS; i++) {
for(i = 0; i < hub.n_ports; i++) {
if (hub.usb_port[i].PortChange)
status |= (1 << (i + 1));
}
@ -573,7 +574,7 @@ int usb_hub_device_c::broadcast_packet(USBPacket *p)
int i, ret;
usb_device_c *dev;
for(i = 0; i < USB_HUB_NUM_PORTS; i++) {
for(i = 0; i < hub.n_ports; i++) {
dev = hub.usb_port[i].device;
if ((dev != NULL) && (hub.usb_port[i].PortStatus & PORT_STAT_ENABLE)) {
ret = dev->handle_packet(p);
@ -683,7 +684,7 @@ const char *usb_hub_device_c::hub_param_handler(bx_param_string_c *param, int se
hubnum = atoi(param->get_parent()->get_name()+6);
portnum = atoi(param->get_name()+4) - 1;
bx_bool empty = ((strlen(val) == 0) || (!strcmp(val, "none")));
if ((portnum >= 0) && (portnum < USB_HUB_NUM_PORTS)) {
if ((portnum >= 0) && (portnum < hub->hub.n_ports)) {
BX_INFO(("USB hub #%d, port #%d experimental device change", hubnum, portnum+1));
if (empty && (hub->hub.usb_port[portnum].PortStatus & PORT_STAT_CONNECTION)) {
if (hub->hub.usb_port[portnum].device != NULL) {

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: usb_hub.h,v 1.1 2009-03-07 16:57:17 vruppert Exp $
// $Id: usb_hub.h,v 1.2 2009-03-12 20:24:56 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2009 Volker Ruppert
@ -29,7 +29,7 @@
class usb_hub_device_c : public usb_device_c {
public:
usb_hub_device_c(void);
usb_hub_device_c(Bit8u ports);
virtual ~usb_hub_device_c(void);
virtual int handle_packet(USBPacket *p);
@ -42,6 +42,7 @@ public:
private:
struct {
Bit8u n_ports;
bx_list_c *config;
bx_list_c *state;
struct {