diff --git a/bochs/bochs.h b/bochs/bochs.h index 576fbbbc0..4b00c9753 100644 --- a/bochs/bochs.h +++ b/bochs/bochs.h @@ -477,10 +477,6 @@ extern bx_bool bx_gui_sighandler; #define BX_N_OPTRAM_IMAGES 4 #define BX_N_SERIAL_PORTS 4 #define BX_N_PARALLEL_PORTS 2 -#define BX_N_USB_UHCI_PORTS 2 -#define BX_N_USB_OHCI_PORTS 2 -#define BX_N_USB_XHCI_PORTS 4 -#define BX_N_USB_HUB_PORTS 8 #define BX_N_PCI_SLOTS 5 #define BX_N_USER_PLUGINS 8 diff --git a/bochs/iodev/usb/usb_common.cc b/bochs/iodev/usb/usb_common.cc index b9452e94a..bea06dcf0 100644 --- a/bochs/iodev/usb/usb_common.cc +++ b/bochs/iodev/usb/usb_common.cc @@ -113,7 +113,7 @@ int bx_usb_devctl_c::init_device(bx_list_c *portconf, logfunctions *hub, void ** if (dnlen > 3) { if (devname[3] == ':') { ports = atoi(&devname[4]); - if ((ports < 2) || (ports > BX_N_USB_HUB_PORTS)) { + if ((ports < 2) || (ports > USB_HUB_PORTS)) { hub->panic("USB device 'hub': invalid number of ports"); } } else { diff --git a/bochs/iodev/usb/usb_hub.h b/bochs/iodev/usb/usb_hub.h index 1e4e3b4aa..898f02fc7 100644 --- a/bochs/iodev/usb/usb_hub.h +++ b/bochs/iodev/usb/usb_hub.h @@ -30,7 +30,7 @@ #define BX_IODEV_USB_HUB_H -// max. number of ports defined in bochs.h +#define USB_HUB_PORTS 8 class usb_hub_device_c : public usb_device_c { public: @@ -58,7 +58,7 @@ private: Bit16u PortStatus; Bit16u PortChange; - } usb_port[BX_N_USB_HUB_PORTS]; + } usb_port[USB_HUB_PORTS]; Bit16u device_change; } hub; diff --git a/bochs/iodev/usb/usb_ohci.cc b/bochs/iodev/usb/usb_ohci.cc index 01dd627de..6dda34d59 100644 --- a/bochs/iodev/usb/usb_ohci.cc +++ b/bochs/iodev/usb/usb_ohci.cc @@ -81,11 +81,11 @@ Bit32s usb_ohci_options_parser(const char *context, int num_params, char *params if (!strncmp(params[i], "enabled=", 8)) { SIM->get_param_bool(BXPN_OHCI_ENABLED)->set(atol(¶ms[i][8])); } else if (!strncmp(params[i], "port", 4)) { - if (SIM->parse_usb_port_params(context, 0, params[i], BX_N_USB_OHCI_PORTS, base) < 0) { + if (SIM->parse_usb_port_params(context, 0, params[i], USB_OHCI_PORTS, base) < 0) { return -1; } } else if (!strncmp(params[i], "options", 7)) { - if (SIM->parse_usb_port_params(context, 1, params[i], BX_N_USB_OHCI_PORTS, base) < 0) { + if (SIM->parse_usb_port_params(context, 1, params[i], USB_OHCI_PORTS, base) < 0) { return -1; } } else { @@ -101,7 +101,7 @@ Bit32s usb_ohci_options_parser(const char *context, int num_params, char *params Bit32s usb_ohci_options_save(FILE *fp) { bx_list_c *base = (bx_list_c*) SIM->get_param(BXPN_USB_OHCI); - SIM->write_usb_options(fp, BX_N_USB_OHCI_PORTS, base); + SIM->write_usb_options(fp, USB_OHCI_PORTS, base); return 0; } @@ -112,7 +112,7 @@ int CDECL libusb_ohci_LTX_plugin_init(plugin_t *plugin, plugintype_t type, int a theUSB_OHCI = new bx_usb_ohci_c(); BX_REGISTER_DEVICE_DEVMODEL(plugin, type, theUSB_OHCI, BX_PLUGIN_USB_OHCI); // add new configuration parameter for the config interface - SIM->init_usb_options("OHCI", "ohci", BX_N_USB_OHCI_PORTS); + SIM->init_usb_options("OHCI", "ohci", USB_OHCI_PORTS); // register add-on option for bochsrc and command line SIM->register_addon_option("usb_ohci", usb_ohci_options_parser, usb_ohci_options_save); return 0; // Success @@ -145,7 +145,7 @@ bx_usb_ohci_c::~bx_usb_ohci_c() if (BX_OHCI_THIS device_buffer != NULL) delete [] BX_OHCI_THIS device_buffer; - for (int i=0; iget_param_string(pname, SIM->get_param(BXPN_USB_OHCI))->set_handler(NULL); remove_device(i); @@ -197,7 +197,7 @@ void bx_usb_ohci_c::init(void) bx_list_c *usb_rt = (bx_list_c*)SIM->get_param(BXPN_MENU_RUNTIME_USB); bx_list_c *ohci_rt = new bx_list_c(usb_rt, "ohci", "OHCI Runtime Options"); ohci_rt->set_options(ohci_rt->SHOW_PARENT); - for (i=0; iget_param(pname, ohci); ohci_rt->add(port); @@ -345,10 +345,10 @@ void bx_usb_ohci_c::reset_hc() BX_OHCI_THIS hub.op_regs.HcRhDescriptorA.dt = 0; BX_OHCI_THIS hub.op_regs.HcRhDescriptorA.nps = 0; BX_OHCI_THIS hub.op_regs.HcRhDescriptorA.psm = 1; - BX_OHCI_THIS hub.op_regs.HcRhDescriptorA.ndp = BX_N_USB_OHCI_PORTS; + BX_OHCI_THIS hub.op_regs.HcRhDescriptorA.ndp = USB_OHCI_PORTS; // HcRhDescriptorB - BX_OHCI_THIS hub.op_regs.HcRhDescriptorB.ppcm = ((1 << BX_N_USB_OHCI_PORTS) - 1) << 1; + BX_OHCI_THIS hub.op_regs.HcRhDescriptorB.ppcm = ((1 << USB_OHCI_PORTS) - 1) << 1; BX_OHCI_THIS hub.op_regs.HcRhDescriptorB.dr = 0x0000; // HcRhStatus @@ -362,7 +362,7 @@ void bx_usb_ohci_c::reset_hc() BX_OHCI_THIS hub.op_regs.HcRhStatus.lps = 0; // HcRhPortStatus[x] - for (i=0; iafter_restore_state(); } @@ -680,17 +680,17 @@ bx_bool bx_usb_ohci_c::read_handler(bx_phy_address addr, unsigned len, void *dat break; case 0x60: // HcRhPortStatus[3] -#if (BX_N_USB_OHCI_PORTS < 4) +#if (USB_OHCI_PORTS < 4) val = 0; break; #endif case 0x5C: // HcRhPortStatus[2] -#if (BX_N_USB_OHCI_PORTS < 3) +#if (USB_OHCI_PORTS < 3) val = 0; break; #endif case 0x58: // HcRhPortStatus[1] -#if (BX_N_USB_OHCI_PORTS < 2) +#if (USB_OHCI_PORTS < 2) val = 0; break; #endif @@ -787,7 +787,7 @@ bx_bool bx_usb_ohci_c::write_handler(bx_phy_address addr, unsigned len, void *da BX_OHCI_THIS hub.op_regs.HcCommandStatus.hcr = 1; BX_OHCI_THIS reset_hc(); BX_OHCI_THIS hub.op_regs.HcControl.hcfs = 3; // suspend state - for (unsigned i=0; ihandle_packet(p); @@ -1408,7 +1408,7 @@ void bx_usb_ohci_c::runtime_config(void) char pname[6]; usbdev_type type = USB_DEV_TYPE_NONE; - for (i = 0; i < BX_N_USB_OHCI_PORTS; i++) { + for (i = 0; i < USB_OHCI_PORTS; i++) { // device change support if ((BX_OHCI_THIS hub.device_change & (1 << i)) != 0) { if (!BX_OHCI_THIS hub.usb_port[i].HcRhPortStatus.ccs) { @@ -1566,7 +1566,7 @@ const char *bx_usb_ohci_c::usb_param_handler(bx_param_string_c *param, int set, if (set) { portnum = atoi((param->get_parent())->get_name()+4) - 1; bx_bool empty = ((strlen(val) == 0) || (!strcmp(val, "none"))); - if ((portnum >= 0) && (portnum < BX_N_USB_OHCI_PORTS)) { + if ((portnum >= 0) && (portnum < USB_OHCI_PORTS)) { if (empty && BX_OHCI_THIS hub.usb_port[portnum].HcRhPortStatus.ccs) { BX_OHCI_THIS hub.device_change |= (1 << portnum); } else if (!empty && !BX_OHCI_THIS hub.usb_port[portnum].HcRhPortStatus.ccs) { diff --git a/bochs/iodev/usb/usb_ohci.h b/bochs/iodev/usb/usb_ohci.h index 07a740e00..1a8209d77 100644 --- a/bochs/iodev/usb/usb_ohci.h +++ b/bochs/iodev/usb/usb_ohci.h @@ -31,7 +31,7 @@ # define BX_OHCI_THIS_PTR this #endif -// number of ports defined in bochs.h +#define USB_OHCI_PORTS 2 #define OHCI_INTR_SO (1<<0) // Scheduling overrun #define OHCI_INTR_WD (1<<1) // HcDoneHead writeback @@ -228,7 +228,7 @@ typedef struct { bx_bool pes; // 1 bit PortEnableStatus = 0b RW RW bx_bool ccs; // 1 bit CurrentConnectStatus = 0b RW RW } HcRhPortStatus; - } usb_port[BX_N_USB_OHCI_PORTS]; + } usb_port[USB_OHCI_PORTS]; Bit8u devfunc; unsigned ohci_done_count; diff --git a/bochs/iodev/usb/usb_uhci.cc b/bochs/iodev/usb/usb_uhci.cc index 76bdd5cfc..7ca71e272 100644 --- a/bochs/iodev/usb/usb_uhci.cc +++ b/bochs/iodev/usb/usb_uhci.cc @@ -68,11 +68,11 @@ Bit32s usb_uhci_options_parser(const char *context, int num_params, char *params if (!strncmp(params[i], "enabled=", 8)) { SIM->get_param_bool(BXPN_UHCI_ENABLED)->set(atol(¶ms[i][8])); } else if (!strncmp(params[i], "port", 4)) { - if (SIM->parse_usb_port_params(context, 0, params[i], BX_N_USB_UHCI_PORTS, base) < 0) { + if (SIM->parse_usb_port_params(context, 0, params[i], USB_UHCI_PORTS, base) < 0) { return -1; } } else if (!strncmp(params[i], "options", 7)) { - if (SIM->parse_usb_port_params(context, 1, params[i], BX_N_USB_UHCI_PORTS, base) < 0) { + if (SIM->parse_usb_port_params(context, 1, params[i], USB_UHCI_PORTS, base) < 0) { return -1; } } else { @@ -88,7 +88,7 @@ Bit32s usb_uhci_options_parser(const char *context, int num_params, char *params Bit32s usb_uhci_options_save(FILE *fp) { bx_list_c *base = (bx_list_c*) SIM->get_param(BXPN_USB_UHCI); - SIM->write_usb_options(fp, BX_N_USB_UHCI_PORTS, base); + SIM->write_usb_options(fp, USB_UHCI_PORTS, base); return 0; } @@ -99,7 +99,7 @@ int CDECL libusb_uhci_LTX_plugin_init(plugin_t *plugin, plugintype_t type, int a theUSB_UHCI = new bx_usb_uhci_c(); BX_REGISTER_DEVICE_DEVMODEL(plugin, type, theUSB_UHCI, BX_PLUGIN_USB_UHCI); // add new configuration parameter for the config interface - SIM->init_usb_options("UHCI", "uhci", BX_N_USB_UHCI_PORTS); + SIM->init_usb_options("UHCI", "uhci", USB_UHCI_PORTS); // register add-on option for bochsrc and command line SIM->register_addon_option("usb_uhci", usb_uhci_options_parser, usb_uhci_options_save); return 0; // Success @@ -132,7 +132,7 @@ bx_usb_uhci_c::~bx_usb_uhci_c() if (BX_UHCI_THIS device_buffer != NULL) delete [] BX_UHCI_THIS device_buffer; - for (int i=0; iget_param_string(pname, SIM->get_param(BXPN_USB_UHCI))->set_handler(NULL); remove_device(i); @@ -185,7 +185,7 @@ void bx_usb_uhci_c::init(void) bx_list_c *usb_rt = (bx_list_c*)SIM->get_param(BXPN_MENU_RUNTIME_USB); bx_list_c *uhci_rt = new bx_list_c(usb_rt, "uhci", "UHCI Runtime Options"); uhci_rt->set_options(uhci_rt->SHOW_PARENT); - for (i=0; iget_param(pname, uhci); uhci_rt->add(port); @@ -255,7 +255,7 @@ void bx_usb_uhci_c::reset(unsigned type) BX_UHCI_THIS hub.usb_frame_num.frame_num = 0x0000; BX_UHCI_THIS hub.usb_frame_base.frame_base = 0x00000000; BX_UHCI_THIS hub.usb_sof.sof_timing = 0x40; - for (j=0; jafter_restore_state(); } @@ -469,7 +469,7 @@ Bit32u bx_usb_uhci_c::read(Bit32u address, unsigned io_len) case 0x12: // port #2 case 0x13: port = (offset & 0x0F) >> 1; - if (port < BX_N_USB_UHCI_PORTS) { + if (port < USB_UHCI_PORTS) { val = BX_UHCI_THIS hub.usb_port[port].suspend << 12 | 1 << 10 // some Root Hubs have bit 10 set ????? | BX_UHCI_THIS hub.usb_port[port].reset << 9 @@ -536,7 +536,7 @@ void bx_usb_uhci_c::write(Bit32u address, Bit32u value, unsigned io_len) // HCRESET if (BX_UHCI_THIS hub.usb_command.host_reset) { BX_UHCI_THIS reset(0); - for (unsigned i=0; i> 1; - if ((port < BX_N_USB_UHCI_PORTS) && (io_len == 2)) { + if ((port < USB_UHCI_PORTS) && (io_len == 2)) { // If the ports reset bit is set, don't allow any writes unless the new write will clear the reset bit if (BX_UHCI_THIS hub.usb_port[port].reset & (value & (1<<9))) break; @@ -716,7 +716,7 @@ void bx_usb_uhci_c::usb_timer(void) // If the "global reset" bit was set by software if (BX_UHCI_THIS global_reset) { - for (i=0; ihandle_packet(p); @@ -1008,7 +1008,7 @@ void bx_usb_uhci_c::runtime_config(void) char pname[6]; usbdev_type type = USB_DEV_TYPE_NONE; - for (i = 0; i < BX_N_USB_UHCI_PORTS; i++) { + for (i = 0; i < USB_UHCI_PORTS; i++) { // device change support if ((BX_UHCI_THIS hub.device_change & (1 << i)) != 0) { if (!BX_UHCI_THIS hub.usb_port[i].status) { @@ -1190,7 +1190,7 @@ const char *bx_usb_uhci_c::usb_param_handler(bx_param_string_c *param, int set, if (set) { portnum = atoi((param->get_parent())->get_name()+4) - 1; bx_bool empty = ((strlen(val) == 0) || (!strcmp(val, "none"))); - if ((portnum >= 0) && (portnum < BX_N_USB_UHCI_PORTS)) { + if ((portnum >= 0) && (portnum < USB_UHCI_PORTS)) { if (empty && BX_UHCI_THIS hub.usb_port[portnum].status) { BX_UHCI_THIS hub.device_change |= (1 << portnum); } else if (!empty && !BX_UHCI_THIS hub.usb_port[portnum].status) { diff --git a/bochs/iodev/usb/usb_uhci.h b/bochs/iodev/usb/usb_uhci.h index ed5bf6bce..1cc5a4e02 100644 --- a/bochs/iodev/usb/usb_uhci.h +++ b/bochs/iodev/usb/usb_uhci.h @@ -30,7 +30,7 @@ # define BX_UHCI_THIS_PTR this #endif -// defined in bochs.h: UHCI supports 2 ports per root hub +#define USB_UHCI_PORTS 2 typedef struct { int timer_index; @@ -154,7 +154,7 @@ typedef struct { bx_bool enabled; bx_bool connect_changed; bx_bool status; - } usb_port[BX_N_USB_UHCI_PORTS]; + } usb_port[USB_UHCI_PORTS]; Bit8u devfunc; diff --git a/bochs/iodev/usb/usb_xhci.h b/bochs/iodev/usb/usb_xhci.h index ec2e4dc42..21fe61d81 100644 --- a/bochs/iodev/usb/usb_xhci.h +++ b/bochs/iodev/usb/usb_xhci.h @@ -147,13 +147,7 @@ // ie.: Each physical port (socket) has two defined port register sets. One for USB3, one for USB2 // Only one port type may be used at a time. Port0 or Port1, not both. If Port0 is used, then // Port1 must be vacant. -#ifndef BX_N_USB_XHCI_PORTS - #error "BX_N_USB_XHCI_PORTS was not defined in bochs.h" -#else - #if (BX_N_USB_XHCI_PORTS < USB_XHCI_PORTS) - #error "BX_N_USB_XHCI_PORTS is less than USB_XHCI_PORTS." - #endif -#endif +#define BX_N_USB_XHCI_PORTS 4 // xHCI speed values #define SPEED_FULL 1